evalution 2.0.4 → 2.0.5

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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/angular-html-CU67Zn6k.js","assets/html-GMplVEZG.js","assets/javascript-wDzz0qaB.js","assets/css-DPfMkruS.js","assets/angular-ts-BwZT4LLn.js","assets/scss-OYdSNvt2.js","assets/apl-dKokRX4l.js","assets/xml-sdJ4AIDG.js","assets/java-CylS5w8V.js","assets/json-Cp-IABpG.js","assets/astro-CbQHKStN.js","assets/typescript-BPQ3VLAy.js","assets/postcss-CXtECtnM.js","assets/tsx-COt5Ahok.js","assets/blade-D4QpJJKB.js","assets/html-derivative-BFtXZ54Q.js","assets/sql-BLtJtn59.js","assets/bsl-BO_Y6i37.js","assets/sdbl-DVxCFoDh.js","assets/cairo-KRGpt6FW.js","assets/python-B6aJPvgy.js","assets/cobol-nwyudZeR.js","assets/coffee-Ch7k5sss.js","assets/cpp-CofmeUqb.js","assets/regexp-CDVJQ6XC.js","assets/glsl-DplSGwfg.js","assets/c-BIGW1oBm.js","assets/crystal-tKQVLTB8.js","assets/shellscript-Yzrsuije.js","assets/edge-BkV0erSs.js","assets/elixir-CDX3lj18.js","assets/elm-DbKCFpqz.js","assets/erb-B12qg9BL.js","assets/ruby-Dw2BHqvy.js","assets/haml-B8DHNrY2.js","assets/graphql-ChdNCCLP.js","assets/jsx-g9-lgVsj.js","assets/lua-BaeVxFsk.js","assets/yaml-Buea-lGh.js","assets/erlang-DsQrWhSR.js","assets/markdown-Cvjx9yec.js","assets/fortran-fixed-form-CkoXwp7k.js","assets/fortran-free-form-BxgE0vQu.js","assets/fsharp-CXgrBDvD.js","assets/gdresource-BOOCDP_w.js","assets/gdshader-DkwncUOv.js","assets/gdscript-C5YyOfLZ.js","assets/git-commit-F4YmCXRG.js","assets/diff-D97Zzqfu.js","assets/git-rebase-r7XF79zn.js","assets/glimmer-js-Rg0-pVw9.js","assets/glimmer-ts-U6CK756n.js","assets/hack-CaT9iCJl.js","assets/handlebars-BL8al0AC.js","assets/http-jrhK8wxY.js","assets/hurl-irOxFIW8.js","assets/csv-fuZLfV_i.js","assets/hxml-Bvhsp5Yf.js","assets/haxe-CzTSHFRz.js","assets/jinja-4LBKfQ-Z.js","assets/jison-wvAkD_A8.js","assets/julia-CxzCAyBv.js","assets/r-Dspwwk_N.js","assets/just-Cw27pwNe.js","assets/perl-C0TMdlhV.js","assets/latex-CWtU0Tv5.js","assets/tex-idrVyKtj.js","assets/liquid-DYVedYrR.js","assets/marko-CnJfTvn9.js","assets/less-B1dDrJ26.js","assets/mdc-BMNejdWA.js","assets/nextflow-Zz6hmt5N.js","assets/nextflow-groovy-BeH2EWoN.js","assets/nginx-BpAMiNFr.js","assets/nim-CVrawwO9.js","assets/php-Dhbhpdrm.js","assets/pug-CGlum2m_.js","assets/qml-3beO22l8.js","assets/razor-Uh8Bk_45.js","assets/csharp-COcwbKMJ.js","assets/rst-BrH8l1NY.js","assets/cmake-D1j8_8rp.js","assets/sas-cz2c8ADy.js","assets/shaderlab-Dg9Lc6iA.js","assets/hlsl-D3lLCCz7.js","assets/shellsession-BADoaaVG.js","assets/soy-Brmx7dQM.js","assets/sparql-rVzFXLq3.js","assets/turtle-BsS91CYL.js","assets/stata-BH5u7GGu.js","assets/surrealql-Bq5Q-fJD.js","assets/svelte-C_ipcX3V.js","assets/templ-P3uqSqPl.js","assets/go-CxLEBnE3.js","assets/ts-tags-zn1MmPIZ.js","assets/twig-DNn4PbVi.js","assets/vue-DN_0RTcg.js","assets/vue-html-AaS7Mt5G.js","assets/vue-vine-CQOfvN7w.js","assets/stylus-BEDo0Tqx.js","assets/xsl-CtQFsRM5.js","assets/DatasetView-B1KoSX7p.js","assets/DatasetView-BcYR5beY.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/angular-html-CU67Zn6k.js","assets/html-GMplVEZG.js","assets/javascript-wDzz0qaB.js","assets/css-DPfMkruS.js","assets/angular-ts-BwZT4LLn.js","assets/scss-OYdSNvt2.js","assets/apl-dKokRX4l.js","assets/xml-sdJ4AIDG.js","assets/java-CylS5w8V.js","assets/json-Cp-IABpG.js","assets/astro-CbQHKStN.js","assets/typescript-BPQ3VLAy.js","assets/postcss-CXtECtnM.js","assets/tsx-COt5Ahok.js","assets/blade-D4QpJJKB.js","assets/html-derivative-BFtXZ54Q.js","assets/sql-BLtJtn59.js","assets/bsl-BO_Y6i37.js","assets/sdbl-DVxCFoDh.js","assets/cairo-KRGpt6FW.js","assets/python-B6aJPvgy.js","assets/cobol-nwyudZeR.js","assets/coffee-Ch7k5sss.js","assets/cpp-CofmeUqb.js","assets/regexp-CDVJQ6XC.js","assets/glsl-DplSGwfg.js","assets/c-BIGW1oBm.js","assets/crystal-tKQVLTB8.js","assets/shellscript-Yzrsuije.js","assets/edge-BkV0erSs.js","assets/elixir-CDX3lj18.js","assets/elm-DbKCFpqz.js","assets/erb-B12qg9BL.js","assets/ruby-Dw2BHqvy.js","assets/haml-B8DHNrY2.js","assets/graphql-ChdNCCLP.js","assets/jsx-g9-lgVsj.js","assets/lua-BaeVxFsk.js","assets/yaml-Buea-lGh.js","assets/erlang-DsQrWhSR.js","assets/markdown-Cvjx9yec.js","assets/fortran-fixed-form-CkoXwp7k.js","assets/fortran-free-form-BxgE0vQu.js","assets/fsharp-CXgrBDvD.js","assets/gdresource-BOOCDP_w.js","assets/gdshader-DkwncUOv.js","assets/gdscript-C5YyOfLZ.js","assets/git-commit-F4YmCXRG.js","assets/diff-D97Zzqfu.js","assets/git-rebase-r7XF79zn.js","assets/glimmer-js-Rg0-pVw9.js","assets/glimmer-ts-U6CK756n.js","assets/hack-CaT9iCJl.js","assets/handlebars-BL8al0AC.js","assets/http-jrhK8wxY.js","assets/hurl-irOxFIW8.js","assets/csv-fuZLfV_i.js","assets/hxml-Bvhsp5Yf.js","assets/haxe-CzTSHFRz.js","assets/jinja-4LBKfQ-Z.js","assets/jison-wvAkD_A8.js","assets/julia-CxzCAyBv.js","assets/r-Dspwwk_N.js","assets/just-Cw27pwNe.js","assets/perl-C0TMdlhV.js","assets/latex-CWtU0Tv5.js","assets/tex-idrVyKtj.js","assets/liquid-DYVedYrR.js","assets/marko-CnJfTvn9.js","assets/less-B1dDrJ26.js","assets/mdc-BMNejdWA.js","assets/nextflow-Zz6hmt5N.js","assets/nextflow-groovy-BeH2EWoN.js","assets/nginx-BpAMiNFr.js","assets/nim-CVrawwO9.js","assets/php-Dhbhpdrm.js","assets/pug-CGlum2m_.js","assets/qml-3beO22l8.js","assets/razor-Uh8Bk_45.js","assets/csharp-COcwbKMJ.js","assets/rst-BrH8l1NY.js","assets/cmake-D1j8_8rp.js","assets/sas-cz2c8ADy.js","assets/shaderlab-Dg9Lc6iA.js","assets/hlsl-D3lLCCz7.js","assets/shellsession-BADoaaVG.js","assets/soy-Brmx7dQM.js","assets/sparql-rVzFXLq3.js","assets/turtle-BsS91CYL.js","assets/stata-BH5u7GGu.js","assets/surrealql-Bq5Q-fJD.js","assets/svelte-C_ipcX3V.js","assets/templ-P3uqSqPl.js","assets/go-CxLEBnE3.js","assets/ts-tags-zn1MmPIZ.js","assets/twig-DNn4PbVi.js","assets/vue-DN_0RTcg.js","assets/vue-html-AaS7Mt5G.js","assets/vue-vine-CQOfvN7w.js","assets/stylus-BEDo0Tqx.js","assets/xsl-CtQFsRM5.js","assets/DatasetView-dWZOCEO1.js","assets/DatasetView-BcYR5beY.css"])))=>i.map(i=>d[i]);
2
2
  var Fj=Object.defineProperty;var Uj=Object.getPrototypeOf;var Vj=Reflect.get;var W6=e=>{throw TypeError(e)};var qj=(e,t,r)=>t in e?Fj(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var J=(e,t,r)=>qj(e,typeof t!="symbol"?t+"":t,r),J1=(e,t,r)=>t.has(e)||W6("Cannot "+r);var wn=(e,t,r)=>(J1(e,t,"read from private field"),r?r.call(e):t.get(e)),Io=(e,t,r)=>t.has(e)?W6("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),Ui=(e,t,r,n)=>(J1(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),eg=(e,t,r)=>(J1(e,t,"access private method"),r);var Y6=(e,t,r)=>Vj(Uj(e),r,t);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const a of s.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function r(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function n(i){if(i.ep)return;i.ep=!0;const s=r(i);fetch(i.href,s)}})();var lm=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function wy(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var wk={exports:{}},Bp={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -50,7 +50,7 @@ Error generating stack: `+n.message+`
50
50
  `).replace(hz,"")}function u9(e,t){return t=ix(t),ix(e)===t}function Lt(e,t,r,n,i,s){switch(r){case"children":typeof n=="string"?t==="body"||t==="textarea"&&n===""||Vu(e,n):(typeof n=="number"||typeof n=="bigint")&&t!=="body"&&Vu(e,""+n);break;case"className":R0(e,"class",n);break;case"tabIndex":R0(e,"tabindex",n);break;case"dir":case"role":case"viewBox":case"width":case"height":R0(e,r,n);break;case"style":aC(e,n,s);break;case"data":if(t!=="object"){R0(e,"data",n);break}case"src":case"href":if(n===""&&(t!=="a"||r!=="href")){e.removeAttribute(r);break}if(n==null||typeof n=="function"||typeof n=="symbol"||typeof n=="boolean"){e.removeAttribute(r);break}n=Cf(""+n),e.setAttribute(r,n);break;case"action":case"formAction":if(typeof n=="function"){e.setAttribute(r,"javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')");break}else typeof s=="function"&&(r==="formAction"?(t!=="input"&&Lt(e,t,"name",i.name,i,null),Lt(e,t,"formEncType",i.formEncType,i,null),Lt(e,t,"formMethod",i.formMethod,i,null),Lt(e,t,"formTarget",i.formTarget,i,null)):(Lt(e,t,"encType",i.encType,i,null),Lt(e,t,"method",i.method,i,null),Lt(e,t,"target",i.target,i,null)));if(n==null||typeof n=="symbol"||typeof n=="boolean"){e.removeAttribute(r);break}n=Cf(""+n),e.setAttribute(r,n);break;case"onClick":n!=null&&(e.onclick=ea);break;case"onScroll":n!=null&&gt("scroll",e);break;case"onScrollEnd":n!=null&&gt("scrollend",e);break;case"dangerouslySetInnerHTML":if(n!=null){if(typeof n!="object"||!("__html"in n))throw Error(se(61));if(r=n.__html,r!=null){if(i.children!=null)throw Error(se(60));e.innerHTML=r}}break;case"multiple":e.multiple=n&&typeof n!="function"&&typeof n!="symbol";break;case"muted":e.muted=n&&typeof n!="function"&&typeof n!="symbol";break;case"suppressContentEditableWarning":case"suppressHydrationWarning":case"defaultValue":case"defaultChecked":case"innerHTML":case"ref":break;case"autoFocus":break;case"xlinkHref":if(n==null||typeof n=="function"||typeof n=="boolean"||typeof n=="symbol"){e.removeAttribute("xlink:href");break}r=Cf(""+n),e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r);break;case"contentEditable":case"spellCheck":case"draggable":case"value":case"autoReverse":case"externalResourcesRequired":case"focusable":case"preserveAlpha":n!=null&&typeof n!="function"&&typeof n!="symbol"?e.setAttribute(r,""+n):e.removeAttribute(r);break;case"inert":case"allowFullScreen":case"async":case"autoPlay":case"controls":case"default":case"defer":case"disabled":case"disablePictureInPicture":case"disableRemotePlayback":case"formNoValidate":case"hidden":case"loop":case"noModule":case"noValidate":case"open":case"playsInline":case"readOnly":case"required":case"reversed":case"scoped":case"seamless":case"itemScope":n&&typeof n!="function"&&typeof n!="symbol"?e.setAttribute(r,""):e.removeAttribute(r);break;case"capture":case"download":n===!0?e.setAttribute(r,""):n!==!1&&n!=null&&typeof n!="function"&&typeof n!="symbol"?e.setAttribute(r,n):e.removeAttribute(r);break;case"cols":case"rows":case"size":case"span":n!=null&&typeof n!="function"&&typeof n!="symbol"&&!isNaN(n)&&1<=n?e.setAttribute(r,n):e.removeAttribute(r);break;case"rowSpan":case"start":n==null||typeof n=="function"||typeof n=="symbol"||isNaN(n)?e.removeAttribute(r):e.setAttribute(r,n);break;case"popover":gt("beforetoggle",e),gt("toggle",e),kf(e,"popover",n);break;case"xlinkActuate":Bs(e,"http://www.w3.org/1999/xlink","xlink:actuate",n);break;case"xlinkArcrole":Bs(e,"http://www.w3.org/1999/xlink","xlink:arcrole",n);break;case"xlinkRole":Bs(e,"http://www.w3.org/1999/xlink","xlink:role",n);break;case"xlinkShow":Bs(e,"http://www.w3.org/1999/xlink","xlink:show",n);break;case"xlinkTitle":Bs(e,"http://www.w3.org/1999/xlink","xlink:title",n);break;case"xlinkType":Bs(e,"http://www.w3.org/1999/xlink","xlink:type",n);break;case"xmlBase":Bs(e,"http://www.w3.org/XML/1998/namespace","xml:base",n);break;case"xmlLang":Bs(e,"http://www.w3.org/XML/1998/namespace","xml:lang",n);break;case"xmlSpace":Bs(e,"http://www.w3.org/XML/1998/namespace","xml:space",n);break;case"is":kf(e,"is",n);break;case"innerText":case"textContent":break;default:(!(2<r.length)||r[0]!=="o"&&r[0]!=="O"||r[1]!=="n"&&r[1]!=="N")&&(r=zB.get(r)||r,kf(e,r,n))}}function Xb(e,t,r,n,i,s){switch(r){case"style":aC(e,n,s);break;case"dangerouslySetInnerHTML":if(n!=null){if(typeof n!="object"||!("__html"in n))throw Error(se(61));if(r=n.__html,r!=null){if(i.children!=null)throw Error(se(60));e.innerHTML=r}}break;case"children":typeof n=="string"?Vu(e,n):(typeof n=="number"||typeof n=="bigint")&&Vu(e,""+n);break;case"onScroll":n!=null&&gt("scroll",e);break;case"onScrollEnd":n!=null&&gt("scrollend",e);break;case"onClick":n!=null&&(e.onclick=ea);break;case"suppressContentEditableWarning":case"suppressHydrationWarning":case"innerHTML":case"ref":break;case"innerText":case"textContent":break;default:if(!eC.hasOwnProperty(r))e:{if(r[0]==="o"&&r[1]==="n"&&(i=r.endsWith("Capture"),t=r.slice(2,i?r.length-7:void 0),s=e[Kn]||null,s=s!=null?s[r]:null,typeof s=="function"&&e.removeEventListener(t,s,i),typeof n=="function")){typeof s!="function"&&s!==null&&(r in e?e[r]=null:e.hasAttribute(r)&&e.removeAttribute(r)),e.addEventListener(t,n,i);break e}r in e?e[r]=n:n===!0?e.setAttribute(r,""):kf(e,r,n)}}}function on(e,t,r){switch(t){case"div":case"span":case"svg":case"path":case"a":case"g":case"p":case"li":break;case"img":gt("error",e),gt("load",e);var n=!1,i=!1,s;for(s in r)if(r.hasOwnProperty(s)){var a=r[s];if(a!=null)switch(s){case"src":n=!0;break;case"srcSet":i=!0;break;case"children":case"dangerouslySetInnerHTML":throw Error(se(137,t));default:Lt(e,t,s,a,r,null)}}i&&Lt(e,t,"srcSet",r.srcSet,r,null),n&&Lt(e,t,"src",r.src,r,null);return;case"input":gt("invalid",e);var o=s=a=i=null,l=null,u=null;for(n in r)if(r.hasOwnProperty(n)){var c=r[n];if(c!=null)switch(n){case"name":i=c;break;case"type":a=c;break;case"checked":l=c;break;case"defaultChecked":u=c;break;case"value":s=c;break;case"defaultValue":o=c;break;case"children":case"dangerouslySetInnerHTML":if(c!=null)throw Error(se(137,t));break;default:Lt(e,t,n,c,r,null)}}nC(e,s,o,l,u,a,i,!1);return;case"select":gt("invalid",e),n=a=s=null;for(i in r)if(r.hasOwnProperty(i)&&(o=r[i],o!=null))switch(i){case"value":s=o;break;case"defaultValue":a=o;break;case"multiple":n=o;default:Lt(e,t,i,o,r,null)}t=s,r=a,e.multiple=!!n,t!=null?Ru(e,!!n,t,!1):r!=null&&Ru(e,!!n,r,!0);return;case"textarea":gt("invalid",e),s=i=n=null;for(a in r)if(r.hasOwnProperty(a)&&(o=r[a],o!=null))switch(a){case"value":n=o;break;case"defaultValue":i=o;break;case"children":s=o;break;case"dangerouslySetInnerHTML":if(o!=null)throw Error(se(91));break;default:Lt(e,t,a,o,r,null)}sC(e,n,i,s);return;case"option":for(l in r)if(r.hasOwnProperty(l)&&(n=r[l],n!=null))switch(l){case"selected":e.selected=n&&typeof n!="function"&&typeof n!="symbol";break;default:Lt(e,t,l,n,r,null)}return;case"dialog":gt("beforetoggle",e),gt("toggle",e),gt("cancel",e),gt("close",e);break;case"iframe":case"object":gt("load",e);break;case"video":case"audio":for(n=0;n<hd.length;n++)gt(hd[n],e);break;case"image":gt("error",e),gt("load",e);break;case"details":gt("toggle",e);break;case"embed":case"source":case"link":gt("error",e),gt("load",e);case"area":case"base":case"br":case"col":case"hr":case"keygen":case"meta":case"param":case"track":case"wbr":case"menuitem":for(u in r)if(r.hasOwnProperty(u)&&(n=r[u],n!=null))switch(u){case"children":case"dangerouslySetInnerHTML":throw Error(se(137,t));default:Lt(e,t,u,n,r,null)}return;default:if(My(t)){for(c in r)r.hasOwnProperty(c)&&(n=r[c],n!==void 0&&Xb(e,t,c,n,r,void 0));return}}for(o in r)r.hasOwnProperty(o)&&(n=r[o],n!=null&&Lt(e,t,o,n,r,null))}function dz(e,t,r,n){switch(t){case"div":case"span":case"svg":case"path":case"a":case"g":case"p":case"li":break;case"input":var i=null,s=null,a=null,o=null,l=null,u=null,c=null;for(f in r){var d=r[f];if(r.hasOwnProperty(f)&&d!=null)switch(f){case"checked":break;case"value":break;case"defaultValue":l=d;default:n.hasOwnProperty(f)||Lt(e,t,f,null,n,d)}}for(var m in n){var f=n[m];if(d=r[m],n.hasOwnProperty(m)&&(f!=null||d!=null))switch(m){case"type":s=f;break;case"name":i=f;break;case"checked":u=f;break;case"defaultChecked":c=f;break;case"value":a=f;break;case"defaultValue":o=f;break;case"children":case"dangerouslySetInnerHTML":if(f!=null)throw Error(se(137,t));break;default:f!==d&&Lt(e,t,m,f,n,d)}}xb(e,a,o,l,u,c,s,i);return;case"select":f=a=o=m=null;for(s in r)if(l=r[s],r.hasOwnProperty(s)&&l!=null)switch(s){case"value":break;case"multiple":f=l;default:n.hasOwnProperty(s)||Lt(e,t,s,null,n,l)}for(i in n)if(s=n[i],l=r[i],n.hasOwnProperty(i)&&(s!=null||l!=null))switch(i){case"value":m=s;break;case"defaultValue":o=s;break;case"multiple":a=s;default:s!==l&&Lt(e,t,i,s,n,l)}t=o,r=a,n=f,m!=null?Ru(e,!!r,m,!1):!!n!=!!r&&(t!=null?Ru(e,!!r,t,!0):Ru(e,!!r,r?[]:"",!1));return;case"textarea":f=m=null;for(o in r)if(i=r[o],r.hasOwnProperty(o)&&i!=null&&!n.hasOwnProperty(o))switch(o){case"value":break;case"children":break;default:Lt(e,t,o,null,n,i)}for(a in n)if(i=n[a],s=r[a],n.hasOwnProperty(a)&&(i!=null||s!=null))switch(a){case"value":m=i;break;case"defaultValue":f=i;break;case"children":break;case"dangerouslySetInnerHTML":if(i!=null)throw Error(se(91));break;default:i!==s&&Lt(e,t,a,i,n,s)}iC(e,m,f);return;case"option":for(var p in r)if(m=r[p],r.hasOwnProperty(p)&&m!=null&&!n.hasOwnProperty(p))switch(p){case"selected":e.selected=!1;break;default:Lt(e,t,p,null,n,m)}for(l in n)if(m=n[l],f=r[l],n.hasOwnProperty(l)&&m!==f&&(m!=null||f!=null))switch(l){case"selected":e.selected=m&&typeof m!="function"&&typeof m!="symbol";break;default:Lt(e,t,l,m,n,f)}return;case"img":case"link":case"area":case"base":case"br":case"col":case"embed":case"hr":case"keygen":case"meta":case"param":case"source":case"track":case"wbr":case"menuitem":for(var g in r)m=r[g],r.hasOwnProperty(g)&&m!=null&&!n.hasOwnProperty(g)&&Lt(e,t,g,null,n,m);for(u in n)if(m=n[u],f=r[u],n.hasOwnProperty(u)&&m!==f&&(m!=null||f!=null))switch(u){case"children":case"dangerouslySetInnerHTML":if(m!=null)throw Error(se(137,t));break;default:Lt(e,t,u,m,n,f)}return;default:if(My(t)){for(var y in r)m=r[y],r.hasOwnProperty(y)&&m!==void 0&&!n.hasOwnProperty(y)&&Xb(e,t,y,void 0,n,m);for(c in n)m=n[c],f=r[c],!n.hasOwnProperty(c)||m===f||m===void 0&&f===void 0||Xb(e,t,c,m,n,f);return}}for(var b in r)m=r[b],r.hasOwnProperty(b)&&m!=null&&!n.hasOwnProperty(b)&&Lt(e,t,b,null,n,m);for(d in n)m=n[d],f=r[d],!n.hasOwnProperty(d)||m===f||m==null&&f==null||Lt(e,t,d,m,n,f)}function sx(e){switch(e){case"css":case"script":case"font":case"img":case"image":case"input":case"link":return!0;default:return!1}}function fz(){if(typeof performance.getEntriesByType=="function"){for(var e=0,t=0,r=performance.getEntriesByType("resource"),n=0;n<r.length;n++){var i=r[n],s=i.transferSize,a=i.initiatorType,o=i.duration;if(s&&o&&sx(a)){for(a=0,o=i.responseEnd,n+=1;n<r.length;n++){var l=r[n],u=l.startTime;if(u>o)break;var c=l.transferSize,d=l.initiatorType;c&&sx(d)&&(l=l.responseEnd,a+=c*(l<o?1:(o-u)/(l-u)))}if(--n,t+=8*(s+a)/(i.duration/1e3),e++,10<e)break}}if(0<e)return t/e/1e6}return navigator.connection&&(e=navigator.connection.downlink,typeof e=="number")?e:5}var Qb=null,Zb=null;function Im(e){return e.nodeType===9?e:e.ownerDocument}function ax(e){switch(e){case"http://www.w3.org/2000/svg":return 1;case"http://www.w3.org/1998/Math/MathML":return 2;default:return 0}}function c9(e,t){if(e===0)switch(t){case"svg":return 1;case"math":return 2;default:return 0}return e===1&&t==="foreignObject"?0:e}function Jb(e,t){return e==="textarea"||e==="noscript"||typeof t.children=="string"||typeof t.children=="number"||typeof t.children=="bigint"||typeof t.dangerouslySetInnerHTML=="object"&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var jg=null;function mz(){var e=window.event;return e&&e.type==="popstate"?e===jg?!1:(jg=e,!0):(jg=null,!1)}var h9=typeof setTimeout=="function"?setTimeout:void 0,pz=typeof clearTimeout=="function"?clearTimeout:void 0,ox=typeof Promise=="function"?Promise:void 0,gz=typeof queueMicrotask=="function"?queueMicrotask:typeof ox<"u"?function(e){return ox.resolve(null).then(e).catch(bz)}:h9;function bz(e){setTimeout(function(){throw e})}function Ao(e){return e==="head"}function lx(e,t){var r=t,n=0;do{var i=r.nextSibling;if(e.removeChild(r),i&&i.nodeType===8)if(r=i.data,r==="/$"||r==="/&"){if(n===0){e.removeChild(i),Zu(t);return}n--}else if(r==="$"||r==="$?"||r==="$~"||r==="$!"||r==="&")n++;else if(r==="html")$h(e.ownerDocument.documentElement);else if(r==="head"){r=e.ownerDocument.head,$h(r);for(var s=r.firstChild;s;){var a=s.nextSibling,o=s.nodeName;s[Fd]||o==="SCRIPT"||o==="STYLE"||o==="LINK"&&s.rel.toLowerCase()==="stylesheet"||r.removeChild(s),s=a}}else r==="body"&&$h(e.ownerDocument.body);r=i}while(r);Zu(t)}function ux(e,t){var r=e;e=0;do{var n=r.nextSibling;if(r.nodeType===1?t?(r._stashedDisplay=r.style.display,r.style.display="none"):(r.style.display=r._stashedDisplay||"",r.getAttribute("style")===""&&r.removeAttribute("style")):r.nodeType===3&&(t?(r._stashedText=r.nodeValue,r.nodeValue=""):r.nodeValue=r._stashedText||""),n&&n.nodeType===8)if(r=n.data,r==="/$"){if(e===0)break;e--}else r!=="$"&&r!=="$?"&&r!=="$~"&&r!=="$!"||e++;r=n}while(r)}function e_(e){var t=e.firstChild;for(t&&t.nodeType===10&&(t=t.nextSibling);t;){var r=t;switch(t=t.nextSibling,r.nodeName){case"HTML":case"HEAD":case"BODY":e_(r),Oy(r);continue;case"SCRIPT":case"STYLE":continue;case"LINK":if(r.rel.toLowerCase()==="stylesheet")continue}e.removeChild(r)}}function _z(e,t,r,n){for(;e.nodeType===1;){var i=r;if(e.nodeName.toLowerCase()!==t.toLowerCase()){if(!n&&(e.nodeName!=="INPUT"||e.type!=="hidden"))break}else if(n){if(!e[Fd])switch(t){case"meta":if(!e.hasAttribute("itemprop"))break;return e;case"link":if(s=e.getAttribute("rel"),s==="stylesheet"&&e.hasAttribute("data-precedence"))break;if(s!==i.rel||e.getAttribute("href")!==(i.href==null||i.href===""?null:i.href)||e.getAttribute("crossorigin")!==(i.crossOrigin==null?null:i.crossOrigin)||e.getAttribute("title")!==(i.title==null?null:i.title))break;return e;case"style":if(e.hasAttribute("data-precedence"))break;return e;case"script":if(s=e.getAttribute("src"),(s!==(i.src==null?null:i.src)||e.getAttribute("type")!==(i.type==null?null:i.type)||e.getAttribute("crossorigin")!==(i.crossOrigin==null?null:i.crossOrigin))&&s&&e.hasAttribute("async")&&!e.hasAttribute("itemprop"))break;return e;default:return e}}else if(t==="input"&&e.type==="hidden"){var s=i.name==null?null:""+i.name;if(i.type==="hidden"&&e.getAttribute("name")===s)return e}else return e;if(e=ji(e.nextSibling),e===null)break}return null}function vz(e,t,r){if(t==="")return null;for(;e.nodeType!==3;)if((e.nodeType!==1||e.nodeName!=="INPUT"||e.type!=="hidden")&&!r||(e=ji(e.nextSibling),e===null))return null;return e}function d9(e,t){for(;e.nodeType!==8;)if((e.nodeType!==1||e.nodeName!=="INPUT"||e.type!=="hidden")&&!t||(e=ji(e.nextSibling),e===null))return null;return e}function t_(e){return e.data==="$?"||e.data==="$~"}function r_(e){return e.data==="$!"||e.data==="$?"&&e.ownerDocument.readyState!=="loading"}function yz(e,t){var r=e.ownerDocument;if(e.data==="$~")e._reactRetry=t;else if(e.data!=="$?"||r.readyState!=="loading")t();else{var n=function(){t(),r.removeEventListener("DOMContentLoaded",n)};r.addEventListener("DOMContentLoaded",n),e._reactRetry=n}}function ji(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t==="$"||t==="$!"||t==="$?"||t==="$~"||t==="&"||t==="F!"||t==="F")break;if(t==="/$"||t==="/&")return null}}return e}var n_=null;function cx(e){e=e.nextSibling;for(var t=0;e;){if(e.nodeType===8){var r=e.data;if(r==="/$"||r==="/&"){if(t===0)return ji(e.nextSibling);t--}else r!=="$"&&r!=="$!"&&r!=="$?"&&r!=="$~"&&r!=="&"||t++}e=e.nextSibling}return null}function hx(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var r=e.data;if(r==="$"||r==="$!"||r==="$?"||r==="$~"||r==="&"){if(t===0)return e;t--}else r!=="/$"&&r!=="/&"||t++}e=e.previousSibling}return null}function f9(e,t,r){switch(t=Im(r),e){case"html":if(e=t.documentElement,!e)throw Error(se(452));return e;case"head":if(e=t.head,!e)throw Error(se(453));return e;case"body":if(e=t.body,!e)throw Error(se(454));return e;default:throw Error(se(451))}}function $h(e){for(var t=e.attributes;t.length;)e.removeAttributeNode(t[0]);Oy(e)}var Pi=new Map,dx=new Set;function Dm(e){return typeof e.getRootNode=="function"?e.getRootNode():e.nodeType===9?e:e.ownerDocument}var ba=kt.d;kt.d={f:xz,r:Sz,D:wz,C:Ez,L:kz,m:Cz,X:Az,S:Tz,M:Nz};function xz(){var e=ba.f(),t=Zp();return e||t}function Sz(e){var t=hc(e);t!==null&&t.tag===5&&t.type==="form"?aT(t):ba.r(e)}var pc=typeof document>"u"?null:document;function m9(e,t,r){var n=pc;if(n&&typeof t=="string"&&t){var i=Ni(t);i='link[rel="'+e+'"][href="'+i+'"]',typeof r=="string"&&(i+='[crossorigin="'+r+'"]'),dx.has(i)||(dx.add(i),e={rel:e,crossOrigin:r,href:t},n.querySelector(i)===null&&(t=n.createElement("link"),on(t,"link",e),Wr(t),n.head.appendChild(t)))}}function wz(e){ba.D(e),m9("dns-prefetch",e,null)}function Ez(e,t){ba.C(e,t),m9("preconnect",e,t)}function kz(e,t,r){ba.L(e,t,r);var n=pc;if(n&&e&&t){var i='link[rel="preload"][as="'+Ni(t)+'"]';t==="image"&&r&&r.imageSrcSet?(i+='[imagesrcset="'+Ni(r.imageSrcSet)+'"]',typeof r.imageSizes=="string"&&(i+='[imagesizes="'+Ni(r.imageSizes)+'"]')):i+='[href="'+Ni(e)+'"]';var s=i;switch(t){case"style":s=Qu(e);break;case"script":s=gc(e)}Pi.has(s)||(e=qt({rel:"preload",href:t==="image"&&r&&r.imageSrcSet?void 0:e,as:t},r),Pi.set(s,e),n.querySelector(i)!==null||t==="style"&&n.querySelector(Yd(s))||t==="script"&&n.querySelector(Kd(s))||(t=n.createElement("link"),on(t,"link",e),Wr(t),n.head.appendChild(t)))}}function Cz(e,t){ba.m(e,t);var r=pc;if(r&&e){var n=t&&typeof t.as=="string"?t.as:"script",i='link[rel="modulepreload"][as="'+Ni(n)+'"][href="'+Ni(e)+'"]',s=i;switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":s=gc(e)}if(!Pi.has(s)&&(e=qt({rel:"modulepreload",href:e},t),Pi.set(s,e),r.querySelector(i)===null)){switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(r.querySelector(Kd(s)))return}n=r.createElement("link"),on(n,"link",e),Wr(n),r.head.appendChild(n)}}}function Tz(e,t,r){ba.S(e,t,r);var n=pc;if(n&&e){var i=Nu(n).hoistableStyles,s=Qu(e);t=t||"default";var a=i.get(s);if(!a){var o={loading:0,preload:null};if(a=n.querySelector(Yd(s)))o.loading=5;else{e=qt({rel:"stylesheet",href:e,"data-precedence":t},r),(r=Pi.get(s))&&v4(e,r);var l=a=n.createElement("link");Wr(l),on(l,"link",e),l._p=new Promise(function(u,c){l.onload=u,l.onerror=c}),l.addEventListener("load",function(){o.loading|=1}),l.addEventListener("error",function(){o.loading|=2}),o.loading|=4,jf(a,t,n)}a={type:"stylesheet",instance:a,count:1,state:o},i.set(s,a)}}}function Az(e,t){ba.X(e,t);var r=pc;if(r&&e){var n=Nu(r).hoistableScripts,i=gc(e),s=n.get(i);s||(s=r.querySelector(Kd(i)),s||(e=qt({src:e,async:!0},t),(t=Pi.get(i))&&y4(e,t),s=r.createElement("script"),Wr(s),on(s,"link",e),r.head.appendChild(s)),s={type:"script",instance:s,count:1,state:null},n.set(i,s))}}function Nz(e,t){ba.M(e,t);var r=pc;if(r&&e){var n=Nu(r).hoistableScripts,i=gc(e),s=n.get(i);s||(s=r.querySelector(Kd(i)),s||(e=qt({src:e,async:!0,type:"module"},t),(t=Pi.get(i))&&y4(e,t),s=r.createElement("script"),Wr(s),on(s,"link",e),r.head.appendChild(s)),s={type:"script",instance:s,count:1,state:null},n.set(i,s))}}function fx(e,t,r,n){var i=(i=no.current)?Dm(i):null;if(!i)throw Error(se(446));switch(e){case"meta":case"title":return null;case"style":return typeof r.precedence=="string"&&typeof r.href=="string"?(t=Qu(r.href),r=Nu(i).hoistableStyles,n=r.get(t),n||(n={type:"style",instance:null,count:0,state:null},r.set(t,n)),n):{type:"void",instance:null,count:0,state:null};case"link":if(r.rel==="stylesheet"&&typeof r.href=="string"&&typeof r.precedence=="string"){e=Qu(r.href);var s=Nu(i).hoistableStyles,a=s.get(e);if(a||(i=i.ownerDocument||i,a={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},s.set(e,a),(s=i.querySelector(Yd(e)))&&!s._p&&(a.instance=s,a.state.loading=5),Pi.has(e)||(r={rel:"preload",as:"style",href:r.href,crossOrigin:r.crossOrigin,integrity:r.integrity,media:r.media,hrefLang:r.hrefLang,referrerPolicy:r.referrerPolicy},Pi.set(e,r),s||Rz(i,e,r,a.state))),t&&n===null)throw Error(se(528,""));return a}if(t&&n!==null)throw Error(se(529,""));return null;case"script":return t=r.async,r=r.src,typeof r=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=gc(r),r=Nu(i).hoistableScripts,n=r.get(t),n||(n={type:"script",instance:null,count:0,state:null},r.set(t,n)),n):{type:"void",instance:null,count:0,state:null};default:throw Error(se(444,e))}}function Qu(e){return'href="'+Ni(e)+'"'}function Yd(e){return'link[rel="stylesheet"]['+e+"]"}function p9(e){return qt({},e,{"data-precedence":e.precedence,precedence:null})}function Rz(e,t,r,n){e.querySelector('link[rel="preload"][as="style"]['+t+"]")?n.loading=1:(t=e.createElement("link"),n.preload=t,t.addEventListener("load",function(){return n.loading|=1}),t.addEventListener("error",function(){return n.loading|=2}),on(t,"link",r),Wr(t),e.head.appendChild(t))}function gc(e){return'[src="'+Ni(e)+'"]'}function Kd(e){return"script[async]"+e}function mx(e,t,r){if(t.count++,t.instance===null)switch(t.type){case"style":var n=e.querySelector('style[data-href~="'+Ni(r.href)+'"]');if(n)return t.instance=n,Wr(n),n;var i=qt({},r,{"data-href":r.href,"data-precedence":r.precedence,href:null,precedence:null});return n=(e.ownerDocument||e).createElement("style"),Wr(n),on(n,"style",i),jf(n,r.precedence,e),t.instance=n;case"stylesheet":i=Qu(r.href);var s=e.querySelector(Yd(i));if(s)return t.state.loading|=4,t.instance=s,Wr(s),s;n=p9(r),(i=Pi.get(i))&&v4(n,i),s=(e.ownerDocument||e).createElement("link"),Wr(s);var a=s;return a._p=new Promise(function(o,l){a.onload=o,a.onerror=l}),on(s,"link",n),t.state.loading|=4,jf(s,r.precedence,e),t.instance=s;case"script":return s=gc(r.src),(i=e.querySelector(Kd(s)))?(t.instance=i,Wr(i),i):(n=r,(i=Pi.get(s))&&(n=qt({},r),y4(n,i)),e=e.ownerDocument||e,i=e.createElement("script"),Wr(i),on(i,"link",n),e.head.appendChild(i),t.instance=i);case"void":return null;default:throw Error(se(443,t.type))}else t.type==="stylesheet"&&!(t.state.loading&4)&&(n=t.instance,t.state.loading|=4,jf(n,r.precedence,e));return t.instance}function jf(e,t,r){for(var n=r.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),i=n.length?n[n.length-1]:null,s=i,a=0;a<n.length;a++){var o=n[a];if(o.dataset.precedence===t)s=o;else if(s!==i)break}s?s.parentNode.insertBefore(e,s.nextSibling):(t=r.nodeType===9?r.head:r,t.insertBefore(e,t.firstChild))}function v4(e,t){e.crossOrigin==null&&(e.crossOrigin=t.crossOrigin),e.referrerPolicy==null&&(e.referrerPolicy=t.referrerPolicy),e.title==null&&(e.title=t.title)}function y4(e,t){e.crossOrigin==null&&(e.crossOrigin=t.crossOrigin),e.referrerPolicy==null&&(e.referrerPolicy=t.referrerPolicy),e.integrity==null&&(e.integrity=t.integrity)}var Bf=null;function px(e,t,r){if(Bf===null){var n=new Map,i=Bf=new Map;i.set(r,n)}else i=Bf,n=i.get(r),n||(n=new Map,i.set(r,n));if(n.has(e))return n;for(n.set(e,null),r=r.getElementsByTagName(e),i=0;i<r.length;i++){var s=r[i];if(!(s[Fd]||s[tn]||e==="link"&&s.getAttribute("rel")==="stylesheet")&&s.namespaceURI!=="http://www.w3.org/2000/svg"){var a=s.getAttribute(t)||"";a=e+a;var o=n.get(a);o?o.push(s):n.set(a,[s])}}return n}function gx(e,t,r){e=e.ownerDocument||e,e.head.insertBefore(r,t==="title"?e.querySelector("head > title"):null)}function Lz(e,t,r){if(r===1||t.itemProp!=null)return!1;switch(e){case"meta":case"title":return!0;case"style":if(typeof t.precedence!="string"||typeof t.href!="string"||t.href==="")break;return!0;case"link":if(typeof t.rel!="string"||typeof t.href!="string"||t.href===""||t.onLoad||t.onError)break;switch(t.rel){case"stylesheet":return e=t.disabled,typeof t.precedence=="string"&&e==null;default:return!0}case"script":if(t.async&&typeof t.async!="function"&&typeof t.async!="symbol"&&!t.onLoad&&!t.onError&&t.src&&typeof t.src=="string")return!0}return!1}function g9(e){return!(e.type==="stylesheet"&&!(e.state.loading&3))}function Iz(e,t,r,n){if(r.type==="stylesheet"&&(typeof n.media!="string"||matchMedia(n.media).matches!==!1)&&!(r.state.loading&4)){if(r.instance===null){var i=Qu(n.href),s=t.querySelector(Yd(i));if(s){t=s._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(e.count++,e=Om.bind(e),t.then(e,e)),r.state.loading|=4,r.instance=s,Wr(s);return}s=t.ownerDocument||t,n=p9(n),(i=Pi.get(i))&&v4(n,i),s=s.createElement("link"),Wr(s);var a=s;a._p=new Promise(function(o,l){a.onload=o,a.onerror=l}),on(s,"link",n),r.instance=s}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(r,t),(t=r.state.preload)&&!(r.state.loading&3)&&(e.count++,r=Om.bind(e),t.addEventListener("load",r),t.addEventListener("error",r))}}var Bg=0;function Dz(e,t){return e.stylesheets&&e.count===0&&Pf(e,e.stylesheets),0<e.count||0<e.imgCount?function(r){var n=setTimeout(function(){if(e.stylesheets&&Pf(e,e.stylesheets),e.unsuspend){var s=e.unsuspend;e.unsuspend=null,s()}},6e4+t);0<e.imgBytes&&Bg===0&&(Bg=62500*fz());var i=setTimeout(function(){if(e.waitingForImages=!1,e.count===0&&(e.stylesheets&&Pf(e,e.stylesheets),e.unsuspend)){var s=e.unsuspend;e.unsuspend=null,s()}},(e.imgBytes>Bg?50:800)+t);return e.unsuspend=r,function(){e.unsuspend=null,clearTimeout(n),clearTimeout(i)}}:null}function Om(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Pf(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var Mm=null;function Pf(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,Mm=new Map,t.forEach(Oz,e),Mm=null,Om.call(e))}function Oz(e,t){if(!(t.state.loading&4)){var r=Mm.get(e);if(r)var n=r.get(null);else{r=new Map,Mm.set(e,r);for(var i=e.querySelectorAll("link[data-precedence],style[data-precedence]"),s=0;s<i.length;s++){var a=i[s];(a.nodeName==="LINK"||a.getAttribute("media")!=="not all")&&(r.set(a.dataset.precedence,a),n=a)}n&&r.set(null,n)}i=t.instance,a=i.getAttribute("data-precedence"),s=r.get(a)||n,s===n&&r.set(null,i),r.set(a,i),this.count++,n=Om.bind(this),i.addEventListener("load",n),i.addEventListener("error",n),s?s.parentNode.insertBefore(i,s.nextSibling):(e=e.nodeType===9?e.head:e,e.insertBefore(i,e.firstChild)),t.state.loading|=4}}var fd={$$typeof:Js,Provider:null,Consumer:null,_currentValue:sl,_currentValue2:sl,_threadCount:0};function Mz(e,t,r,n,i,s,a,o,l){this.tag=1,this.containerInfo=e,this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.next=this.pendingContext=this.context=this.cancelPendingCommit=null,this.callbackPriority=0,this.expirationTimes=ag(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ag(0),this.hiddenUpdates=ag(null),this.identifierPrefix=n,this.onUncaughtError=i,this.onCaughtError=s,this.onRecoverableError=a,this.pooledCache=null,this.pooledCacheLanes=0,this.formState=l,this.incompleteTransitions=new Map}function b9(e,t,r,n,i,s,a,o,l,u,c,d){return e=new Mz(e,t,r,a,l,u,c,d,o),t=1,s===!0&&(t|=24),s=ii(3,null,null,t),e.current=s,s.stateNode=e,t=Gy(),t.refCount++,e.pooledCache=t,t.refCount++,s.memoizedState={element:n,isDehydrated:r,cache:t},Ky(s),e}function _9(e){return e?(e=yu,e):yu}function v9(e,t,r,n,i,s){i=_9(i),n.context===null?n.context=i:n.pendingContext=i,n=so(t),n.payload={element:r},s=s===void 0?null:s,s!==null&&(n.callback=s),r=ao(e,n,t),r!==null&&(Yn(r,e,t),Ih(r,e,t))}function bx(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var r=e.retryLane;e.retryLane=r!==0&&r<t?r:t}}function x4(e,t){bx(e,t),(e=e.alternate)&&bx(e,t)}function y9(e){if(e.tag===13||e.tag===31){var t=Ml(e,67108864);t!==null&&Yn(t,e,67108864),x4(e,67108864)}}function _x(e){if(e.tag===13||e.tag===31){var t=ui();t=Iy(t);var r=Ml(e,t);r!==null&&Yn(r,e,t),x4(e,t)}}var jm=!0;function jz(e,t,r,n){var i=Ye.T;Ye.T=null;var s=kt.p;try{kt.p=2,S4(e,t,r,n)}finally{kt.p=s,Ye.T=i}}function Bz(e,t,r,n){var i=Ye.T;Ye.T=null;var s=kt.p;try{kt.p=8,S4(e,t,r,n)}finally{kt.p=s,Ye.T=i}}function S4(e,t,r,n){if(jm){var i=i_(n);if(i===null)Mg(e,t,n,Bm,r),vx(e,n);else if(zz(i,e,t,r,n))n.stopPropagation();else if(vx(e,n),t&4&&-1<Pz.indexOf(e)){for(;i!==null;){var s=hc(i);if(s!==null)switch(s.tag){case 3:if(s=s.stateNode,s.current.memoizedState.isDehydrated){var a=Uo(s.pendingLanes);if(a!==0){var o=s;for(o.pendingLanes|=2,o.entangledLanes|=2;a;){var l=1<<31-li(a);o.entanglements[1]|=l,a&=~l}Ns(s),!(wt&6)&&(Cm=ai()+500,Wd(0))}}break;case 31:case 13:o=Ml(s,2),o!==null&&Yn(o,s,2),Zp(),x4(s,2)}if(s=i_(n),s===null&&Mg(e,t,n,Bm,r),s===i)break;i=s}i!==null&&n.stopPropagation()}else Mg(e,t,n,null,r)}}function i_(e){return e=jy(e),w4(e)}var Bm=null;function w4(e){if(Bm=null,e=mu(e),e!==null){var t=Pd(e);if(t===null)e=null;else{var r=t.tag;if(r===13){if(e=$k(t),e!==null)return e;e=null}else if(r===31){if(e=Hk(t),e!==null)return e;e=null}else if(r===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null)}}return Bm=e,null}function x9(e){switch(e){case"beforetoggle":case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"toggle":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 2;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 8;case"message":switch(wB()){case qk:return 2;case Gk:return 8;case dm:case EB:return 32;case Wk:return 268435456;default:return 32}default:return 32}}var s_=!1,uo=null,co=null,ho=null,md=new Map,pd=new Map,Va=[],Pz="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset".split(" ");function vx(e,t){switch(e){case"focusin":case"focusout":uo=null;break;case"dragenter":case"dragleave":co=null;break;case"mouseover":case"mouseout":ho=null;break;case"pointerover":case"pointerout":md.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":pd.delete(t.pointerId)}}function Gc(e,t,r,n,i,s){return e===null||e.nativeEvent!==s?(e={blockedOn:t,domEventName:r,eventSystemFlags:n,nativeEvent:s,targetContainers:[i]},t!==null&&(t=hc(t),t!==null&&y9(t)),e):(e.eventSystemFlags|=n,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function zz(e,t,r,n,i){switch(t){case"focusin":return uo=Gc(uo,e,t,r,n,i),!0;case"dragenter":return co=Gc(co,e,t,r,n,i),!0;case"mouseover":return ho=Gc(ho,e,t,r,n,i),!0;case"pointerover":var s=i.pointerId;return md.set(s,Gc(md.get(s)||null,e,t,r,n,i)),!0;case"gotpointercapture":return s=i.pointerId,pd.set(s,Gc(pd.get(s)||null,e,t,r,n,i)),!0}return!1}function S9(e){var t=mu(e.target);if(t!==null){var r=Pd(t);if(r!==null){if(t=r.tag,t===13){if(t=$k(r),t!==null){e.blockedOn=t,n5(e.priority,function(){_x(r)});return}}else if(t===31){if(t=Hk(r),t!==null){e.blockedOn=t,n5(e.priority,function(){_x(r)});return}}else if(t===3&&r.stateNode.current.memoizedState.isDehydrated){e.blockedOn=r.tag===3?r.stateNode.containerInfo:null;return}}}e.blockedOn=null}function zf(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var r=i_(e.nativeEvent);if(r===null){r=e.nativeEvent;var n=new r.constructor(r.type,r);wb=n,r.target.dispatchEvent(n),wb=null}else return t=hc(r),t!==null&&y9(t),e.blockedOn=r,!1;t.shift()}return!0}function yx(e,t,r){zf(e)&&r.delete(t)}function $z(){s_=!1,uo!==null&&zf(uo)&&(uo=null),co!==null&&zf(co)&&(co=null),ho!==null&&zf(ho)&&(ho=null),md.forEach(yx),pd.forEach(yx)}function P0(e,t){e.blockedOn===t&&(e.blockedOn=null,s_||(s_=!0,Dr.unstable_scheduleCallback(Dr.unstable_NormalPriority,$z)))}var z0=null;function xx(e){z0!==e&&(z0=e,Dr.unstable_scheduleCallback(Dr.unstable_NormalPriority,function(){z0===e&&(z0=null);for(var t=0;t<e.length;t+=3){var r=e[t],n=e[t+1],i=e[t+2];if(typeof n!="function"){if(w4(n||r)===null)continue;break}var s=hc(r);s!==null&&(e.splice(t,3),t-=3,zb(s,{pending:!0,data:i,method:r.method,action:n},n,i))}}))}function Zu(e){function t(l){return P0(l,e)}uo!==null&&P0(uo,e),co!==null&&P0(co,e),ho!==null&&P0(ho,e),md.forEach(t),pd.forEach(t);for(var r=0;r<Va.length;r++){var n=Va[r];n.blockedOn===e&&(n.blockedOn=null)}for(;0<Va.length&&(r=Va[0],r.blockedOn===null);)S9(r),r.blockedOn===null&&Va.shift();if(r=(e.ownerDocument||e).$$reactFormReplay,r!=null)for(n=0;n<r.length;n+=3){var i=r[n],s=r[n+1],a=i[Kn]||null;if(typeof s=="function")a||xx(r);else if(a){var o=null;if(s&&s.hasAttribute("formAction")){if(i=s,a=s[Kn]||null)o=a.formAction;else if(w4(i)!==null)continue}else o=a.action;typeof o=="function"?r[n+1]=o:(r.splice(n,3),n-=3),xx(r)}}}function w9(){function e(s){s.canIntercept&&s.info==="react-transition"&&s.intercept({handler:function(){return new Promise(function(a){return i=a})},focusReset:"manual",scroll:"manual"})}function t(){i!==null&&(i(),i=null),n||setTimeout(r,20)}function r(){if(!n&&!navigation.transition){var s=navigation.currentEntry;s&&s.url!=null&&navigation.navigate(s.url,{state:s.getState(),info:"react-transition",history:"replace"})}}if(typeof navigation=="object"){var n=!1,i=null;return navigation.addEventListener("navigate",e),navigation.addEventListener("navigatesuccess",t),navigation.addEventListener("navigateerror",t),setTimeout(r,100),function(){n=!0,navigation.removeEventListener("navigate",e),navigation.removeEventListener("navigatesuccess",t),navigation.removeEventListener("navigateerror",t),i!==null&&(i(),i=null)}}}function E4(e){this._internalRoot=e}t1.prototype.render=E4.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(se(409));var r=t.current,n=ui();v9(r,n,e,t,null,null)};t1.prototype.unmount=E4.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;v9(e.current,2,null,e,null,null),Zp(),t[cc]=null}};function t1(e){this._internalRoot=e}t1.prototype.unstable_scheduleHydration=function(e){if(e){var t=Zk();e={blockedOn:null,target:e,priority:t};for(var r=0;r<Va.length&&t!==0&&t<Va[r].priority;r++);Va.splice(r,0,e),r===0&&S9(e)}};var Sx=Pk.version;if(Sx!=="19.2.7")throw Error(se(527,Sx,"19.2.7"));kt.findDOMNode=function(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(se(188)):(e=Object.keys(e).join(","),Error(se(268,e)));return e=gB(t),e=e!==null?Fk(e):null,e=e===null?null:e.stateNode,e};var Hz={bundleType:0,version:"19.2.7",rendererPackageName:"react-dom",currentDispatcherRef:Ye,reconcilerVersion:"19.2.7"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var $0=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!$0.isDisabled&&$0.supportsFiber)try{zd=$0.inject(Hz),oi=$0}catch{}}Pp.createRoot=function(e,t){if(!zk(e))throw Error(se(299));var r=!1,n="",i=mT,s=pT,a=gT;return t!=null&&(t.unstable_strictMode===!0&&(r=!0),t.identifierPrefix!==void 0&&(n=t.identifierPrefix),t.onUncaughtError!==void 0&&(i=t.onUncaughtError),t.onCaughtError!==void 0&&(s=t.onCaughtError),t.onRecoverableError!==void 0&&(a=t.onRecoverableError)),t=b9(e,1,!1,null,null,r,n,null,i,s,a,w9),e[cc]=t.current,_4(e),new E4(t)};Pp.hydrateRoot=function(e,t,r){if(!zk(e))throw Error(se(299));var n=!1,i="",s=mT,a=pT,o=gT,l=null;return r!=null&&(r.unstable_strictMode===!0&&(n=!0),r.identifierPrefix!==void 0&&(i=r.identifierPrefix),r.onUncaughtError!==void 0&&(s=r.onUncaughtError),r.onCaughtError!==void 0&&(a=r.onCaughtError),r.onRecoverableError!==void 0&&(o=r.onRecoverableError),r.formState!==void 0&&(l=r.formState)),t=b9(e,1,!0,t,r??null,n,i,l,s,a,o,w9),t.context=_9(null),r=t.current,n=ui(),n=Iy(n),i=so(n),i.callback=null,ao(r,i,n),r=n,t.current.lanes=r,Hd(t,r),Ns(t),e[cc]=t.current,_4(e),new t1(t)};Pp.version="19.2.7";function E9(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(E9)}catch(e){console.error(e)}}E9(),Ik.exports=Pp;var Fz=Ik.exports;const Uz="modulepreload",Vz=function(e){return"/"+e},wx={},O=function(t,r,n){let i=Promise.resolve();if(r&&r.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),o=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));i=Promise.allSettled(r.map(l=>{if(l=Vz(l),l in wx)return;wx[l]=!0;const u=l.endsWith(".css"),c=u?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${c}`))return;const d=document.createElement("link");if(d.rel=u?"stylesheet":Uz,u||(d.as="script"),d.crossOrigin="",d.href=l,o&&d.setAttribute("nonce",o),document.head.appendChild(d),u)return new Promise((m,f)=>{d.addEventListener("load",m),d.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${l}`)))})}))}function s(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return i.then(a=>{for(const o of a||[])o.status==="rejected"&&s(o.reason);return t().catch(s)})};function Ss(e){var t;return`${e.name}\0${((t=e.type)==null?void 0:t.syntax)??""}`}function k9(e){const{valueSpan:t,fullSpan:r,...n}=e;return n}function Hh(e,t){return!!e&&!!t&&e.id===t.id&&e.providerId===t.providerId}const qz=["string","number","boolean"];function Gz(e){return qz.includes(e)}function k4(e){const t=new Set,r=[];for(const n of e){const i=Ss(n);t.has(i)||(t.add(i),r.push({def:k9(n)}))}return r}function C9(e){return k4([...e.functionParameters,...e.executeParameters??[]])}const Wz=["name","status","model","effort","environment","annotations","checks","version","variation"],Yz=["startTime","spanCount","duration","totalTokens","cost"];function T9(e){return Wz.includes(e)}function Kz(e){return Yz.includes(e)}function Wc(e){const t=e[0];return e.every(r=>r===t)?t:void 0}function Ex(e){const t=e.filter(r=>r!==void 0);return t.length>0?t.reduce((r,n)=>r+n,0):void 0}function Xz(e){const t=e.filter(n=>n!==void 0);if(t.length===0)return;const r={pass:0,fail:0,error:0,skipped:0,scored:0};for(const n of t)for(const i of Object.keys(r))r[i]+=n[i];return r}function Qz(e){const t=e.some(c=>c.status==="running"),r=Ex(e.map(c=>c.totalTokens)),n=Ex(e.map(c=>c.cost)),i=Xz(e.map(c=>c.checkCounts)),s=Wc(e.map(c=>c.model)),a=Wc(e.map(c=>c.effort)),o=Wc(e.map(c=>c.environment)),l=Wc(e.map(c=>c.promptVersion)),u=Wc(e.map(c=>c.promptVariation));return{startTime:Math.min(...e.map(c=>c.startTime)),...!t&&{endTime:Math.max(...e.map(c=>c.endTime??c.startTime))},status:t?"running":e.some(c=>c.status==="error")?"error":"ok",spanCount:e.reduce((c,d)=>c+d.spanCount,0),...r!==void 0&&{totalTokens:r},...n!==void 0&&{cost:n},...i&&{checkCounts:i},...s!==void 0&&{model:s},...a!==void 0&&{effort:a},...o!==void 0&&{environment:o},...l!==void 0&&{promptVersion:l},...u!==void 0&&{promptVariation:u},annotationCounts:{issue:e.reduce((c,d)=>c+d.annotationCounts.issue,0),good:e.reduce((c,d)=>c+d.annotationCounts.good,0),note:e.reduce((c,d)=>c+d.annotationCounts.note,0)}}}function Zz(e){var r,n;const t=(r=e.search)==null?void 0:r.trim();return{...t&&{q:t},...((n=e.filters)==null?void 0:n.length)&&{filters:JSON.stringify(e.filters)},...e.groupBy&&{groupBy:e.groupBy.column,...e.groupBy.resolution&&{resolution:e.groupBy.resolution}},...e.timeZone&&{tz:e.timeZone}}}const Jz="evalution.check";function A9(e){var t;return((t=e.attributes)==null?void 0:t[Jz])!==void 0}function r1(e){return Array.isArray(e==null?void 0:e.input)?e.input:void 0}function N9(e){const t=e==null?void 0:e.output;return typeof t=="string"?[{role:"assistant",content:t}]:Array.isArray(t)&&t.length>0&&t.every(r=>r&&typeof r=="object"&&typeof r.role=="string"&&(typeof r.content=="string"||Array.isArray(r.content)))?t:void 0}const e$="playground",Eu=new Map,t$=2e3;function R9(e,t,r){return`${e}:${t}:${r}`}function C4(e,t,r){const n=R9(e,t,r),i=Eu.get(n);Eu.set(n,{remaining:((i==null?void 0:i.remaining)??0)+1,expiresAt:Date.now()+t$})}function r$(e,t,r){const n=R9(e,t,r),i=Eu.get(n);return i?i.expiresAt<Date.now()?(Eu.delete(n),!1):(i.remaining<=1?Eu.delete(n):Eu.set(n,{remaining:i.remaining-1,expiresAt:i.expiresAt}),!0):!1}function n$(e){return e.some(t=>typeof t!="string")?{kind:"template",value:e}:{kind:"primitive",value:e.join("")}}function L9(e){return e.map(I9)}function I9(e){const t={name:e.name};return e.type.kind==="object"&&e.type.properties.length>0&&(t.children=e.type.properties.map(I9)),t}const Xl=/[A-Za-z_$][A-Za-z0-9_$]*/y;function i$(e){const t=e.trim();if(t==="")return null;Xl.lastIndex=0;const r=Xl.exec(t);if((r==null?void 0:r.index)!==0)return null;const n=[r[0]];let i=Xl.lastIndex;for(;i<t.length;)if(t[i]==="."){Xl.lastIndex=i+1;const s=Xl.exec(t);if(!s||s.index!==i+1)return null;n.push(s[0]),i=Xl.lastIndex}else if(t[i]==="["){const s=t[i+1];if(s!=='"'&&s!=="'")return null;let a=i+2,o="";for(;a<t.length&&t[a]!==s;)o+=t[a],a++;if(a>=t.length||t[a+1]!=="]")return null;n.push(o),i=a+2}else return null;return n}function s$(e,t){let r=t,n=null;for(const i of e){if(n=r.find(s=>s.name===i)??null,!n)return null;r=n.children??[]}return n}function a$(e,t){const r=/[A-Za-z0-9_$]*$/.exec(e)[0];let n=e.slice(0,e.length-r.length);const i=/(\.|\[\s*['"]?)\s*$/.exec(n);i&&(n=n.slice(0,n.length-i[0].length));let s;if(n.trim()==="")s=t;else{const l=i$(n),u=l?s$(l,t):null;s=(u==null?void 0:u.children)??[]}const a=r.toLowerCase();return{candidates:s.filter(l=>l.name.toLowerCase().startsWith(a)),fragment:r}}function D9(e){const t=[],r=(n,i)=>{for(const s of n){const a=[...i,s.name];t.push(a),s.children&&r(s.children,a)}};return r(e,[]),t}function ma(e){return e.displayValue!==void 0?e.displayValue:ju(e)}function ju(e){switch(e.kind){case"primitive":return e.value===null?"null":e.value===void 0?"undefined":typeof e.value=="string"?JSON.stringify(e.value):String(e.value);case"template":{let t="";for(const r of e.value)typeof r=="string"?t+=r.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${"):t+="${"+r.expr+"}";return"`"+t+"`"}case"functionCall":{const t=e.args.map(ju).join(", ");return`${e.callee}(${t})`}case"lambda":return`(${e.parameters.join(", ")}) => ${e.body}`;case"object":{const t=Object.entries(e.properties);return t.length===0?"{}":`{ ${t.map(([n,i])=>i.kind==="reference"&&i.path.length===1&&i.path[0]===n&&T4(n)?n:`${l$(n)}: ${ju(i)}`).join(", ")} }`}case"reference":return gd(e.path);case"array":case"tuple":return`[${e.elements.map(ju).join(", ")}]`;case"raw":return e.sourceText}}const o$=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function T4(e){return o$.test(e)}function l$(e){return T4(e)?e:JSON.stringify(e)}function gd(e){return e.map((t,r)=>r===0?t:T4(t)?`.${t}`:`[${JSON.stringify(t)}]`).join("")}const O9=w.createContext(void 0);function u$(){return w.useContext(O9)}function A4(e){if(e.kind!=="union")return null;const t=e.types.findIndex(r=>r.kind!=="constant");return t===-1?null:{members:e.types,defaultIndex:t}}function c$(e,t){switch(e.kind){case"object":case"record":return t.kind==="object";case"array":return t.kind==="array";case"tuple":return t.kind==="tuple"||t.kind==="array";case"function":return t.kind==="lambda"||t.kind==="functionCall";case"primitive":return t.kind==="template"?e.syntax!=="number"&&e.syntax!=="boolean":t.kind!=="primitive"?!1:e.syntax==="number"?typeof t.value=="number":e.syntax==="boolean"?typeof t.value=="boolean":typeof t.value=="string";default:return!1}}function h$(e,t){if(!t)return e.defaultIndex;if(t.kind==="primitive"){const n=e.members.findIndex(i=>i.kind==="constant"&&i.value===t.value);if(n!==-1)return n}const r=e.members.findIndex(n=>n.kind!=="constant"&&c$(n,t));return r===-1?e.defaultIndex:r}function N4(e){return e.kind==="union"&&e.types.every(t=>t.kind==="constant")||A4(e)||e.kind==="function"?!1:e.kind==="object"||e.kind==="record"||e.kind==="union"||e.kind==="array"||e.kind==="tuple"}function nn(e){switch(e.kind){case"primitive":{const t=e.base??e.syntax;return t==="number"?{kind:"primitive",value:0}:t==="boolean"?{kind:"primitive",value:!1}:t==="string"?{kind:"primitive",value:""}:{kind:"primitive",value:null}}case"constant":return{kind:"primitive",value:e.value};case"array":return{kind:"array",elements:[]};case"tuple":return{kind:"array",elements:e.elements.map(t=>nn(t.type))};case"object":return{kind:"object",properties:Object.fromEntries(e.properties.filter(t=>!t.optional).map(t=>[t.name,t.defaultValue??nn(t.type)]))};case"record":return{kind:"object",properties:{}};case"union":{const t=e.types.find(n=>n.kind==="primitive"&&(n.base??n.syntax)==="string");if(t)return nn(t);const r=e.types.find(n=>n.kind==="constant"&&(n.value===null||n.value===void 0));return r?nn(r):e.types.length>0?nn(e.types[0]):{kind:"primitive",value:null}}case"function":case"opaque":return{kind:"primitive",value:void 0}}}function M9(e,t){return Object.hasOwn(e,t)}function $f(e,t){if(e===void 0||t===void 0)return e===t;switch(t.kind){case"primitive":return e.kind==="primitive"&&e.value===t.value;case"template":return e.kind==="template"&&e.value.length===t.value.length&&e.value.every((r,n)=>{const i=t.value[n];return typeof r=="string"||typeof i=="string"?r===i:r.expr===i.expr});case"functionCall":return e.kind==="functionCall"&&e.callee===t.callee&&e.args.length===t.args.length&&e.args.every((r,n)=>$f(r,t.args[n]));case"lambda":return e.kind==="lambda"&&e.parameters.join(",")===t.parameters.join(",")&&e.body===t.body;case"object":{if(e.kind!=="object")return!1;const r=Object.keys(e.properties),n=Object.keys(t.properties);return r.length===n.length&&r.every(i=>M9(t.properties,i)&&$f(e.properties[i],t.properties[i]))}case"array":case"tuple":return(e.kind==="array"||e.kind==="tuple")&&e.elements.length===t.elements.length&&e.elements.every((r,n)=>$f(r,t.elements[n]));case"reference":return e.kind==="reference"&&e.path.join("\0")===t.path.join("\0");case"raw":return e.kind==="raw"&&e.sourceText===t.sourceText}}function a_(e,t){var r;if(t)for(const[n,i]of e.entries())for(const[s,a]of i.groups.entries()){const o=(r=a.presets)==null?void 0:r.find(l=>$f(t,l.value));if(o)return{catalogIndex:n,groupIndex:s,preset:o}}}function R4(e,t){var r;if((t==null?void 0:t.kind)==="functionCall"){for(const[n,i]of e.entries())for(const[s,a]of i.groups.entries())if(((r=a.factory)==null?void 0:r.def.name)===t.callee)return{catalogIndex:n,groupIndex:s,factory:a.factory}}}function j9(e,t){if(e.literal)return e.literal===!0?{...t,catalogs:void 0}:{...e.literal,name:e.literal.name||t.name,interpolatables:t.interpolatables}}function Pm(e,t){if(t.kind==="reference")return!0;switch(e.kind){case"constant":return t.kind==="primitive"&&t.value===e.value;case"primitive":{const r=e.base??e.syntax;return t.kind==="template"?r==="string":t.kind!=="primitive"?r!=="string"&&r!=="number"&&r!=="boolean":r==="string"||r==="number"||r==="boolean"?typeof t.value===r:!0}case"union":return e.types.some(r=>Pm(r,t));case"object":{if(t.kind!=="object")return!1;const r=new Set(e.properties.map(i=>i.name));return Object.keys(t.properties).every(i=>r.has(i))&&e.properties.every(i=>M9(t.properties,i.name)?Pm(i.type,t.properties[i.name]):i.optional)}case"record":return t.kind==="object";case"array":case"tuple":return t.kind==="array"||t.kind==="tuple";case"function":return t.kind==="lambda"||t.kind==="functionCall";case"opaque":return t.kind==="raw"||t.kind==="functionCall"}}function kx(e,t,r){const n=a_(e,r);if(n)return n.catalogIndex;const i=R4(e,r);if(i)return i.catalogIndex;if(r){const s=e.findIndex(a=>{const o=j9(a,t);return o&&Pm(o.type,r)});if(s>=0)return s}return 0}function d$(e){return e.def.type.kind==="function"?e.def.type.parameters:[]}function n1(e){const t=d$(e);let r=0;return t.forEach((n,i)=>{n.optional||(r=i+1)}),r===0&&t.length>0&&(r=1),{kind:"functionCall",callee:e.def.name,args:t.slice(0,r).map(n=>n.defaultValue??nn(n.type)),binding:e.binding}}const f$={kind:"primitive",value:void 0};function m$(e,t,r,n){const i=[...e.args];for(let s=i.length;s<r;s++){const a=t[s];i[s]=!a||a.optional?f$:a.defaultValue??nn(a.type)}for(i[r]=n;i.length>0;){const s=i.length-1,a=t[s],o=i[s];if(a!=null&&a.optional&&o.kind==="primitive"&&o.value===void 0)i.pop();else break}return{...e,args:i}}function B9(e){if(e.kind!=="union")return null;const t=e.types.filter(n=>n.kind==="object");if(t.length!==e.types.length||t.length<2)return null;const r=t[0].properties;for(const n of r)if(t.every(s=>{const a=s.properties.find(o=>o.name===n.name);return a&&a.type.kind==="constant"})){const s=t.map(a=>({discriminatorValue:a.properties.find(l=>l.name===n.name).type.value,properties:a.properties.filter(l=>l.name!==n.name)}));return{discriminator:n.name,cases:s}}return null}function p$(e){return e.kind==="primitive"&&(e.base??e.syntax)==="string"}function g$(e){if(e.kind!=="union")return null;const t=[];let r=!1;for(const n of e.types)if(n.kind==="constant"&&typeof n.value=="string")t.push(n.value);else if(p$(n))r=!0;else return null;return r&&t.length>0?{suggestions:t}:null}function b$(e,t,r=50){const n=t.trim().toLowerCase();if(!n)return e.slice(0,r);const i=[],s=[];for(const a of e){const o=a.toLowerCase().indexOf(n);o===0?i.push(a):o>0&&s.push(a)}return[...i,...s].slice(0,r)}const qe={border:"var(--proppy-border, #e2e2e6)",buttonBg:"var(--proppy-button-bg, #f5f5f5)",buttonColor:"var(--proppy-button-color, inherit)",inputBg:"var(--proppy-input-bg, #fff)",inputColor:"var(--proppy-input-color, inherit)",textPrimary:"var(--proppy-text-primary, inherit)",textMuted:"var(--proppy-text-muted, #999)",textSecondary:"var(--proppy-text-secondary, #666)",dangerBg:"var(--proppy-danger-bg, none)",dangerBorder:"var(--proppy-danger-border, #fcc)",dangerColor:"var(--proppy-danger-color, #dc2626)",menuBg:"var(--proppy-menu-bg, #fff)",menuColor:"var(--proppy-menu-color, inherit)",menuActiveBg:"var(--proppy-menu-active-bg, #eef)"},Es={sm:5,md:7},Mn={width:"100%",padding:"5px 8px",background:qe.inputBg,color:qe.inputColor,border:`1px solid ${qe.border}`,borderRadius:Es.sm,fontSize:12.5,fontFamily:"inherit",boxSizing:"border-box"},L4={padding:"3px 8px",background:qe.buttonBg,color:qe.buttonColor,border:`1px solid ${qe.border}`,borderRadius:Es.sm,fontSize:11,fontFamily:"inherit",cursor:"pointer"},zm={alignSelf:"flex-start",padding:"2px 0",border:"none",background:"none",color:qe.textSecondary,fontSize:12,fontFamily:"inherit",cursor:"pointer"},I4={background:qe.dangerBg,border:"none",borderRadius:Es.sm,cursor:"pointer",color:qe.dangerColor,fontSize:17,lineHeight:1,padding:"2px 4px",fontFamily:"inherit"},bc={display:"flex",flexDirection:"column",gap:10,paddingLeft:12,borderLeft:`2px solid ${qe.border}`},_$={fontSize:12,fontWeight:500,color:qe.textPrimary},xo='ui-monospace, "SF Mono", Menlo, monospace',v$={fontWeight:400,fontFamily:xo,fontSize:11,color:qe.textMuted,marginLeft:6,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},y$={fontSize:11,color:qe.textSecondary,marginTop:2,marginBottom:4,lineHeight:1.4},x$=16;function S$({element:e,value:t,onChange:r,plugins:n,path:i=[],disabled:s}){const a=(t==null?void 0:t.kind)==="array"?t.elements:[],o=()=>{r({kind:"array",elements:[...a,e.defaultValue??nn(e.type)]})},l=d=>{r({kind:"array",elements:a.filter((m,f)=>f!==d)})},u=(d,m)=>{const f=[...a];f[d]=m,r({kind:"array",elements:f})},c=N4(e.type)?x$:0;return h.jsxs("div",{style:bc,children:[h.jsxs("div",{style:{fontSize:11,color:qe.textSecondary},children:[a.length," item",a.length!==1?"s":""]}),a.map((d,m)=>h.jsxs("div",{style:{display:"flex",gap:6,alignItems:"flex-start"},children:[h.jsx("div",{style:{flex:1,minWidth:0},children:h.jsx(Ir,{propDef:e,value:d,onChange:f=>u(m,f),plugins:n,path:[...i,String(m)],disabled:s})}),h.jsx("button",{type:"button",onClick:()=>l(m),"aria-label":`Remove item ${m+1}`,disabled:s,style:{...I4,marginTop:c},children:"×"})]},m)),h.jsx("button",{type:"button",onClick:o,disabled:s,style:zm,children:"+ Add item"})]})}function w$(e,t){var r;if((t==null?void 0:t.kind)==="primitive"&&typeof t.value=="boolean")return t.value;if(((r=e.defaultValue)==null?void 0:r.kind)==="primitive"&&typeof e.defaultValue.value=="boolean")return e.defaultValue.value}function E$({value:e,onChange:t,propDef:r,className:n,disabled:i}){const s=w$(r,e);return h.jsxs("select",{value:s===void 0?"":s?"true":"false",onChange:a=>t({kind:"primitive",value:a.target.value==="true"}),className:n,disabled:i,style:n?void 0:Mn,children:[s===void 0&&h.jsx("option",{value:"",children:"-- Select --"}),h.jsx("option",{value:"true",children:"true"}),h.jsx("option",{value:"false",children:"false"})]})}function _c(e){if(e.defaultValue)return`Default: ${ju(e.defaultValue)}`}function k$({value:e,onChange:t,propDef:r,unionInfo:n,className:i,disabled:s}){const a=(e==null?void 0:e.kind)==="primitive"&&typeof e.value=="string"?e.value:"",[o,l]=w.useState(!1),[u,c]=w.useState(0),d=w.useId(),m=w.useRef(null),[f,p]=w.useState(null),g=o?b$(n.suggestions,a):[],y=g.length===1&&g[0]===a?[]:g,b=y.length>0;w.useEffect(()=>{if(!b)return;const x=()=>{var T;const E=(T=m.current)==null?void 0:T.getBoundingClientRect();E&&p({left:E.left,top:E.bottom+2,width:E.width})};return x(),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),()=>{window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},[b]);const v=x=>{t({kind:"primitive",value:x}),l(!1)};return h.jsxs("div",{style:{position:"relative"},children:[h.jsx("input",{ref:m,type:"text",role:"combobox","aria-expanded":y.length>0,"aria-controls":d,"aria-autocomplete":"list",value:a,placeholder:_c(r),readOnly:s,className:i,"data-proppy-editor":"combobox",onChange:x=>{t({kind:"primitive",value:x.target.value}),l(!0),c(0)},onFocus:()=>!s&&l(!0),onBlur:()=>l(!1),onKeyDown:x=>{s||(x.key==="ArrowDown"?(x.preventDefault(),l(!0),c(E=>y.length?(E+1)%y.length:0)):x.key==="ArrowUp"?(x.preventDefault(),c(E=>y.length?(E-1+y.length)%y.length:0)):x.key==="Enter"&&y.length>0?(x.preventDefault(),v(y[Math.min(u,y.length-1)])):x.key==="Escape"&&l(!1))},style:i?void 0:Mn}),y.length>0&&h.jsx("div",{id:d,role:"listbox",style:{position:"fixed",left:(f==null?void 0:f.left)??0,top:(f==null?void 0:f.top)??0,width:f==null?void 0:f.width,visibility:f?void 0:"hidden",boxSizing:"border-box",zIndex:1e4,margin:0,padding:4,maxHeight:240,overflowY:"auto",background:qe.menuBg,color:qe.menuColor,border:`1px solid ${qe.border}`,borderRadius:Es.md,boxShadow:"0 4px 16px rgba(0,0,0,0.16)",fontSize:12.5},children:y.map((x,E)=>h.jsx("div",{role:"option",tabIndex:-1,"aria-selected":E===u,onMouseDown:T=>{T.preventDefault(),v(x)},onMouseEnter:()=>c(E),style:{padding:"4px 8px",borderRadius:4,cursor:"pointer",background:E===u?qe.menuActiveBg:"transparent"},children:x},x))})]})}function C$(e){return e.kind!=="union"?[]:e.types.filter(t=>t.kind==="constant").map(t=>t.value)}function T$(e,t,r){const n=(r==null?void 0:r.kind)==="primitive"?r:t.defaultValue;if((n==null?void 0:n.kind)!=="primitive")return;const i=e.indexOf(n.value);return i===-1?void 0:i}function A$({value:e,onChange:t,propDef:r,className:n,disabled:i}){const s=C$(r.type),a=T$(s,r,e);return h.jsxs("select",{value:a===void 0?"":String(a),onChange:o=>t({kind:"primitive",value:s[Number(o.target.value)]}),className:n,disabled:i,style:n?void 0:Mn,children:[a===void 0&&h.jsx("option",{value:"",children:"-- Select --"}),s.map((o,l)=>h.jsx("option",{value:String(l),children:String(o)},l))]})}function N$({value:e,onChange:t,propDef:r,disabled:n}){const i=(e==null?void 0:e.kind)==="primitive"&&typeof e.value=="string"?e.value:"";return h.jsx("input",{type:"datetime-local",value:i,onChange:s=>t({kind:"primitive",value:s.target.value}),placeholder:_c(r),readOnly:n,style:Mn})}const P9=42;function bd(e,t=P9){const r=e.replace(/\s+/g," ").trim();return r.length<=t?r:r.slice(0,t-1).trimEnd()+"…"}function R$(e){switch(e.kind){case"object":{const t=e.properties.length;return t===0?"{}":`${t} field${t===1?"":"s"}`}case"array":return`${bd(e.element.type.syntax,28)}[]`;case"tuple":return`tuple(${e.elements.length}${e.rest?"+":""})`;case"record":return`{ [key]: ${bd(e.value.type.syntax,28)} }`;default:return null}}function i1({name:e,type:t,optional:r,description:n,actions:i,children:s,defaultCollapsed:a}){const o=N4(t),[l,u]=w.useState(!!a&&o),c=R$(t),d=c??bd(t.syntax),m=c||t.syntax.length>P9?t.syntax:void 0,f=h.jsxs(h.Fragment,{children:[o&&h.jsx("span",{"aria-hidden":"true",style:{flex:"0 0 auto",fontSize:14,fontWeight:700,color:qe.textMuted,lineHeight:1,transform:l?"rotate(-90deg)":"none",transition:"transform .1s ease"},children:"▾"}),h.jsxs("span",{style:{..._$,flex:"0 0 auto"},children:[e,r?"":" *"]}),h.jsx("span",{style:{...v$,flex:"1 1 auto"},title:m,children:d})]});return h.jsxs("div",{children:[h.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:6},children:[o?h.jsx("button",{type:"button",onClick:()=>u(p=>!p),"aria-expanded":!l,"aria-label":l?`Expand ${e||"item"}`:`Collapse ${e||"item"}`,style:{display:"flex",alignItems:"baseline",gap:6,minWidth:0,flex:"1 1 auto",border:"none",background:"none",padding:"4px 0",margin:"-4px 0",font:"inherit",textAlign:"left",cursor:"pointer"},children:f}):h.jsx("span",{style:{display:"flex",alignItems:"baseline",gap:6,minWidth:0},children:f}),i]}),n&&!l&&h.jsx("div",{style:y$,children:n}),h.jsx("div",{hidden:l,children:s})]})}function L$(e,t,r){const n=r[t];if((n==null?void 0:n.kind)!=="primitive")return;const i=e.findIndex(s=>s.discriminatorValue===n.value);return i===-1?void 0:i}function I$({discriminatedUnionInfo:e,value:t,onChange:r,plugins:n,path:i=[],disabled:s}){const a=w.useId(),{discriminator:o,cases:l}=e,u=(t==null?void 0:t.kind)==="object"?t.properties:{},c=L$(l,o,u),d=c===void 0?void 0:l[c],m=p=>{const{discriminatorValue:g}=l[p];r({kind:"object",properties:{[o]:{kind:"primitive",value:g}}})},f=(p,g)=>{const y={...u,[p]:g};r({kind:"object",properties:y})};return h.jsxs("div",{style:bc,children:[h.jsxs("div",{children:[h.jsxs("label",{htmlFor:a,style:{display:"block",fontSize:12,marginBottom:4,fontWeight:500,color:qe.textPrimary},children:[o," *"]}),h.jsxs("select",{id:a,value:c===void 0?"":String(c),onChange:p=>m(Number(p.target.value)),style:Mn,disabled:s,children:[c===void 0&&h.jsx("option",{value:"",children:"-- Select --"}),l.map((p,g)=>h.jsx("option",{value:String(g),children:String(p.discriminatorValue)},g))]})]}),d==null?void 0:d.properties.map(p=>h.jsx(i1,{name:p.name,type:p.type,optional:p.optional,description:p.description,children:h.jsx(Ir,{propDef:p,value:u[p.name],onChange:g=>f(p.name,g),plugins:n,path:[...i,p.name],disabled:s})},p.name))]})}function D$({value:e,onChange:t,propDef:r,disabled:n}){const i=r.type.kind==="function"?r.type.parameters:[],s=i.map(l=>`${l.name}${l.optional?"?":""}: ${l.type.syntax}`).join(", "),a=(e==null?void 0:e.kind)==="lambda"?e.body:"",o=_c(r)||"Enter function body (without braces)";return h.jsxs("div",{children:[h.jsxs("div",{style:{fontSize:11,fontFamily:xo,color:qe.textSecondary,marginBottom:4,padding:"4px 8px",background:qe.buttonBg,borderRadius:Es.sm,border:`1px solid ${qe.border}`},children:["(",s,") =>"]}),h.jsx("textarea",{value:a,onChange:l=>t({kind:"lambda",parameters:i.map(u=>u.name),body:l.target.value}),placeholder:o,readOnly:n,style:{...Mn,padding:"6px 8px",borderRadius:Es.md,fontFamily:xo,minHeight:60,resize:"vertical"}})]})}function O$({value:e,onChange:t,propDef:r,className:n,disabled:i}){const s=e?ju(e):"";return h.jsx("textarea",{value:s,onChange:a=>t({kind:"raw",sourceText:a.target.value}),placeholder:_c(r),className:n,"data-proppy-editor":"json-fallback",readOnly:i,style:n?void 0:{...Mn,fontSize:11,fontFamily:xo,minHeight:40,resize:"vertical"}})}function M$({value:e,onChange:t,propDef:r,className:n,disabled:i}){const s=(e==null?void 0:e.kind)==="primitive"&&typeof e.value=="number"?e.value:"";return h.jsx("input",{type:"number",value:s??"",onChange:a=>{const o=a.target.value;o===""&&r.optional?t({kind:"primitive",value:void 0}):t({kind:"primitive",value:o===""?0:Number(o)})},placeholder:_c(r),className:n,readOnly:i,style:n?void 0:Mn})}function j$({properties:e,value:t,onChange:r,plugins:n,path:i=[],disabled:s}){const a=(t==null?void 0:t.kind)==="object"?{...t.properties}:{},o=(u,c)=>{const d={...a,[u]:c};r({kind:"object",properties:d})},l=e.length>1;return h.jsx("div",{style:bc,children:e.map(u=>h.jsx(i1,{name:u.name,type:u.type,optional:u.optional,description:u.description,defaultCollapsed:l,children:h.jsx(Ir,{propDef:u,value:a[u.name],onChange:c=>o(u.name,c),plugins:n,path:[...i,u.name],disabled:s})},u.name))})}function B$(e){return h.jsx("div",{"data-proppy-editor":"opaque",style:{padding:"8px 10px",border:`1px dashed ${qe.border}`,borderRadius:Es.sm,fontSize:11,color:qe.textMuted},children:"No value editor for this type."})}function z9(e,t,r){if(t===r||!(t in e))return{...e};const n={};for(const[i,s]of Object.entries(e))n[i===t?r:i]=s;return n}function $9(e,t,r){return r===""?"Key can't be empty":r!==t&&Object.hasOwn(e,r)?"Key already exists":null}function Cx(e,t="key"){if(!Object.hasOwn(e,t))return t;for(let r=2;;r++){const n=`${t}${r}`;if(!Object.hasOwn(e,n))return n}}function H9(e){return(e==null?void 0:e.kind)==="tuple"||(e==null?void 0:e.kind)==="array"?e.elements:[]}function F9(e,t){return e>=t}function P$({entryKey:e,properties:t,onRename:r,disabled:n}){const[i,s]=w.useState(e);w.useEffect(()=>s(e),[e]);const a=$9(t,e,i),o=()=>{a?s(e):i!==e&&r(i)};return h.jsx("input",{type:"text",value:i,"aria-label":"Key","aria-invalid":!!a,title:a??void 0,readOnly:n,"data-proppy-editor":"record-key",onChange:l=>s(l.target.value),onBlur:o,onKeyDown:l=>{l.key==="Enter"?(l.preventDefault(),o()):l.key==="Escape"&&s(e)},style:{...Mn,fontFamily:xo,fontWeight:500,borderColor:a?qe.dangerBorder:qe.border}})}function U9(e){return(e.catalogs??[]).flatMap(t=>t.groups.flatMap(r=>r.factory?[{label:r.label,factory:r.factory}]:[]))}function V9({value:e,current:t,onChange:r,plugins:n,path:i=[],disabled:s}){const a=(t==null?void 0:t.kind)==="object"?t.properties:{},o=Object.entries(a),l=p=>r({kind:"object",properties:p}),u=()=>{const p=Cx(a);l({...a,[p]:e.defaultValue??nn(e.type)})},c=U9(e),d=p=>{var y;const g=(y=c.find(b=>b.factory.def.name===p))==null?void 0:y.factory;g&&l({...a,[Cx(a,g.def.name)]:n1(g)})},m=p=>{const g={...a};delete g[p],l(g)},f=N4(e.type);return h.jsxs("div",{style:bc,"data-proppy-editor":"record",children:[o.map(([p,g],y)=>h.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[h.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[h.jsx(P$,{entryKey:p,properties:a,onRename:b=>l(z9(a,p,b)),disabled:s}),h.jsx("button",{type:"button",onClick:()=>m(p),"aria-label":`Remove ${p}`,disabled:s,style:I4,children:"×"})]}),h.jsx("div",{style:f?void 0:{paddingLeft:8},children:h.jsx(Ir,{propDef:{...e,name:p},value:g,onChange:b=>l({...a,[p]:b}),plugins:n,path:[...i,p],disabled:s})})]},y)),c.length>0?h.jsxs("select",{value:"",disabled:s,"aria-label":"Add entry","data-proppy-editor":"record-add",onChange:p=>d(p.target.value),style:zm,children:[h.jsx("option",{value:"",children:"+ Add entry…"}),c.map(({label:p,factory:g})=>h.jsx("option",{value:g.def.name,children:p},g.def.name))]}):h.jsx("button",{type:"button",onClick:u,disabled:s,"data-proppy-editor":"record-add",style:zm,children:"+ Add entry"})]})}function z$({path:e}){return h.jsx("span",{className:"te-token","data-proppy-editor":"reference",style:{fontFamily:xo,fontSize:12,padding:"1px 6px",borderRadius:Es.sm,background:qe.menuActiveBg,whiteSpace:"nowrap"},children:"${"+gd(e)+"}"})}function $$({path:e,interpolatables:t,onChange:r,onClear:n,disabled:i}){const s=D9(t),a=e.join(".");return h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[h.jsx(z$,{path:e}),s.length>0&&h.jsxs("select",{"aria-label":"Parameter",value:a,disabled:i,onChange:o=>r({kind:"reference",path:o.target.value.split(".")}),style:{...Mn,width:"auto",flex:"0 1 auto"},children:[!s.some(o=>o.join(".")===a)&&h.jsx("option",{value:a,children:gd(e)}),s.map(o=>h.jsx("option",{value:o.join("."),children:gd(o)},o.join(".")))]}),h.jsx("button",{type:"button",onClick:n,disabled:i,style:L4,title:"Use a value instead",children:"Use value"})]})}function q9({interpolatables:e,onChange:t,disabled:r}){const n=D9(e);return n.length===0?null:h.jsxs("select",{"aria-label":"Use parameter",value:"",disabled:r,"data-proppy-editor":"parameter-menu",onChange:i=>i.target.value&&t({kind:"reference",path:i.target.value.split(".")}),style:{...L4,alignSelf:"flex-start"},children:[h.jsx("option",{value:"",children:"${…}"}),n.map(i=>h.jsx("option",{value:i.join("."),children:gd(i)},i.join(".")))]})}function H$({value:e,onChange:t,propDef:r,className:n,disabled:i}){const s=(e==null?void 0:e.kind)==="primitive"&&typeof e.value=="string"?e.value:"";return h.jsx("textarea",{value:s,onChange:a=>t({kind:"primitive",value:a.target.value}),placeholder:_c(r),className:n,rows:1,readOnly:i,style:n?void 0:{...Mn,resize:"vertical"}})}class F${constructor(){J(this,"segments",[""])}appendString(t){const r=this.segments[this.segments.length-1];return typeof r=="string"?this.segments[this.segments.length-1]=r+t:this.segments.push(t),this}appendToken(t){return this.segments.push({expr:t}),this.segments.push(""),this}appendSegments(t){for(const r of t)typeof r=="string"?this.appendString(r):this.appendToken(r.expr);return this}build(){return this.segments}}function G9(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Pg(e,t){if(!e)return"";const r=G9(e).replace(/\n/g,"<br>");return t?`<span class="te-code">${r}</span>`:r}const U$="";function V$(e){let t="";for(const s of e)t+=typeof s=="string"?s:U$;const r=Array.from(t.matchAll(/`[^`\n]+`/g),s=>[s.index,s.index+s[0].length]);let n="",i=0;for(const s of e){if(typeof s!="string"){const l="${"+s.expr+"}";n+=`<span class="te-token">${G9(l)}</span>`,i+=1;continue}const a=i+s.length;let o=i;for(const[l,u]of r){if(u<=o||l>=a)continue;l>o&&(n+=Pg(t.slice(o,l),!1));const c=Math.min(u,a);n+=Pg(t.slice(Math.max(l,o),c),!0),o=c}n+=Pg(t.slice(o,a),!1),i=a}return n}function Tx(e){const t=new F$;function r(n){if(n.nodeType===Node.TEXT_NODE)t.appendString(n.textContent??"");else if(n instanceof HTMLElement)if(n.classList.contains("te-token")){const i=n.textContent??"",s=i.match(/^(.*)\$\{(.+)\}(.*)$/s);if(s){const[,a,o,l]=s;a&&t.appendString(a),t.appendToken(o),l&&t.appendString(l)}else t.appendString(i)}else if(n.tagName==="BR")t.appendString(`
51
51
  `);else if(n.tagName==="DIV"||n.tagName==="P"){for(const i of Array.from(n.childNodes))r(i);t.appendString(`
52
52
  `)}else for(const i of Array.from(n.childNodes))r(i)}for(const n of Array.from(e.childNodes))r(n);return t.build()}function q$(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const n=e[r],i=t[r];if(typeof n=="string"||typeof i=="string"){if(n!==i)return!1}else if(n.expr!==i.expr)return!1}return!0}function G$(e){return e===void 0?[""]:e.kind==="template"?e.value:e.kind==="primitive"&&typeof e.value=="string"?[e.value]:[{expr:ma(e)}]}function W$(e){var a;const t=window.getSelection();if(!t||t.rangeCount===0)return null;const r=t.getRangeAt(0);if(!e.contains(r.startContainer))return null;let n=0;const i=document.createTreeWalker(e,NodeFilter.SHOW_ALL);let s=i.nextNode();for(;s;){if(s===r.startContainer)return s.nodeType===Node.TEXT_NODE?n+r.startOffset:n;s.nodeType===Node.TEXT_NODE?n+=((a=s.textContent)==null?void 0:a.length)??0:s instanceof HTMLElement&&s.tagName==="BR"&&(n+=1),s=i.nextNode()}return n}function Y$(e,t){var o;if(t===null)return;const r=window.getSelection();if(!r)return;let n=t;const i=document.createTreeWalker(e,NodeFilter.SHOW_ALL);let s=i.nextNode();for(;s;){if(s.nodeType===Node.TEXT_NODE){const l=((o=s.textContent)==null?void 0:o.length)??0;if(n<=l){const u=document.createRange();u.setStart(s,n),u.collapse(!0),r.removeAllRanges(),r.addRange(u);return}n-=l}else if(s instanceof HTMLElement&&s.tagName==="BR"){if(n<=1){const l=s.parentNode;if(!l)return;const u=Array.from(l.childNodes).indexOf(s),c=document.createRange();c.setStart(l,u+1),c.collapse(!0),r.removeAllRanges(),r.addRange(c);return}n-=1}s=i.nextNode()}const a=document.createRange();a.selectNodeContents(e),a.collapse(!1),r.removeAllRanges(),r.addRange(a)}function zg(e,t,r){var a;let n=0;const i=document.createTreeWalker(e,NodeFilter.SHOW_ALL);let s=i.nextNode();for(;s;){if(s===t)return n+(s.nodeType===Node.TEXT_NODE?r:0);s.nodeType===Node.TEXT_NODE?n+=((a=s.textContent)==null?void 0:a.length)??0:s instanceof HTMLElement&&s.tagName==="BR"&&(n+=1),s=i.nextNode()}return n}function Yc(e){const t=window.getSelection();if(!t||t.rangeCount===0)return null;const r=t.getRangeAt(0);if(!r.collapsed)return null;const n=r.startContainer;if(n.nodeType!==Node.TEXT_NODE||!e.contains(n))return null;let i=n;for(;i&&i!==e;){if(i instanceof HTMLElement&&i.classList.contains("te-token"))return null;i=i.parentNode}const s=n.textContent??"",a=r.startOffset,o=s.slice(0,a),l=o.lastIndexOf("${");if(l===-1||o.slice(l+2).includes("}"))return null;const u=s.slice(a),c=u.indexOf("}"),d=u.indexOf("${");return c!==-1&&(d===-1||c<d)?null:{node:n,dollarOffset:l,caret:a,activeExpr:o.slice(l+2)}}function K$(e){const t=window.getSelection();if(t!=null&&t.rangeCount){const n=t.getRangeAt(0),i=n.getClientRects(),s=i.length?i[0]:n.getBoundingClientRect();if(s&&(s.left||s.top||s.bottom))return{left:s.left,top:s.top,bottom:s.bottom}}const r=e.getBoundingClientRect();return{left:r.left,top:r.top,bottom:r.bottom}}const X$=new Set(["ArrowUp","ArrowDown","Enter","Tab","Escape"]);function Q$(e,t){return e.length!==t.length?!1:e.every((r,n)=>{const i=t[n];return r.kind!==i.kind?!1:r.kind==="identifier"&&i.kind==="identifier"?r.node.name===i.node.name:!0})}function D4({value:e,onChange:t,propDef:r,className:n,placeholder:i,disabled:s,onBlur:a}){const o=r.interpolatables??[],l=G$(e),u=w.useRef(null),c=w.useRef(l),d=w.useRef(!1),m=w.useRef(null),[f,p]=w.useState(null),g=(B,j)=>{if(!u.current)return;const G=j?W$(u.current):null,W=V$(B);u.current.innerHTML!==W&&(u.current.innerHTML=W,j&&Y$(u.current,G))};w.useLayoutEffect(()=>{g(l,!1)},[]),w.useEffect(()=>{!q$(l,c.current)&&u.current&&(c.current=l,g(l,!0))},[l]);const y=B=>{c.current=B,t(n$(B))},b=()=>{const B=u.current;if(!B)return;const j=Yc(B);if(!j){m.current=null,d.current=!1,p(null);return}const G=zg(B,j.node,j.dollarOffset);if(m.current===G){p(null);return}m.current=null;const{candidates:W,fragment:Y}=a$(j.activeExpr,o),V=W.length?[...W.map(P=>({kind:"identifier",node:P})),{kind:"insert-literal"}]:[{kind:"insert-token"},{kind:"insert-literal"}],X=K$(B);p(P=>{const re=P&&Q$(P.items,V)?Math.min(P.index,V.length-1):0;return{items:V,index:re,fragmentLen:Y.length,left:X.left,top:X.bottom}})},v=(B,j="")=>{const G=u.current,W=Yc(G);if(!W)return;if(B.trim()===""){document.execCommand("insertText",!1,"}"+j),d.current=!1,m.current=null,p(null);return}const Y=document.createRange();Y.setStart(W.node,W.dollarOffset),Y.setEnd(W.node,W.caret),Y.deleteContents();const V=document.createElement("span");V.className="te-token",V.textContent="${"+B+"}",Y.insertNode(V);const X=window.getSelection(),P=document.createRange();if(j){const re=document.createTextNode(j);V.parentNode.insertBefore(re,V.nextSibling),P.setStart(re,j.length)}else P.setStartAfter(V);P.collapse(!0),X&&(X.removeAllRanges(),X.addRange(P)),y(Tx(G)),d.current=!1,m.current=null,p(null)},x=(B="")=>{const j=u.current;if(!j)return!1;const G=Yc(j);return!G||G.activeExpr.trim()===""||m.current===zg(j,G.node,G.dollarOffset)?!1:(v(G.activeExpr,B),!0)},E=(B,j,G)=>{const W=window.getSelection();if(W!=null&&W.rangeCount){const Y=W.getRangeAt(0),V=document.createRange();V.setStart(Y.startContainer,Math.max(0,Y.startOffset-j)),V.setEnd(Y.startContainer,Y.startOffset),W.removeAllRanges(),W.addRange(V)}document.execCommand("insertText",!1,B.name),m.current=null,G?x():d.current=!0},T=(B,j,G)=>{if(B.kind==="identifier")E(B.node,j,G);else if(B.kind==="insert-token"){const W=Yc(u.current);v((W==null?void 0:W.activeExpr)??"")}else{const W=u.current,Y=Yc(W);m.current=Y?zg(W,Y.node,Y.dollarOffset):null,d.current=!1,p(null)}},C=()=>{const B=Tx(u.current);g(B,!0),y(B),b()},L=B=>{B.preventDefault(),document.execCommand("insertText",!1,B.clipboardData.getData("text/plain"))},A=B=>{const j=B.key.length===1&&!B.ctrlKey&&!B.metaKey&&!B.altKey;if(f){const G=f.items.length;if(B.key==="ArrowDown"){B.preventDefault(),p({...f,index:(f.index+1)%G});return}if(B.key==="ArrowUp"){B.preventDefault(),p({...f,index:(f.index-1+G)%G});return}if(B.key==="Escape"){B.preventDefault(),p(null);return}if(B.key==="Enter"){B.preventDefault(),T(f.items[f.index],f.fragmentLen,!0);return}if(B.key==="Tab"){B.preventDefault(),T(f.items[f.index],f.fragmentLen,!1);return}}if(B.key==="}"){x()&&B.preventDefault();return}if(B.key===" "&&d.current&&x(" ")){B.preventDefault();return}if(B.key==="Enter"){B.preventDefault(),x()||document.execCommand("insertText",!1,`
53
- `);return}j&&(d.current=!1)},z=B=>{X$.has(B.key)||b()},I=()=>{p(null),d.current=!1,a==null||a()};return h.jsxs(h.Fragment,{children:[h.jsx("div",{ref:u,contentEditable:!s,suppressContentEditableWarning:!0,className:n,"data-placeholder":i,onInput:C,onPaste:L,onKeyDown:A,onKeyUp:z,onMouseUp:b,onBlur:I,style:n?void 0:{...Mn,minHeight:24,outline:"none",whiteSpace:"pre-wrap",wordBreak:"break-word"}}),f&&h.jsx("ul",{className:"te-suggest",style:{position:"fixed",left:f.left,top:f.top+4,zIndex:9999,margin:0,padding:4,listStyle:"none",minWidth:160,maxHeight:240,overflowY:"auto",background:qe.menuBg,color:qe.menuColor,border:`1px solid ${qe.border}`,borderRadius:Es.md,boxShadow:"0 4px 16px rgba(0,0,0,0.16)",fontSize:13},children:f.items.map((B,j)=>{var Y;const G=B.kind!=="identifier",W=B.kind==="identifier"?B.node.name+((Y=B.node.children)!=null&&Y.length?" ›":""):B.kind==="insert-token"?"Insert token":"Insert as literal text";return h.jsx("li",{className:"te-suggest-item"+(j===f.index?" active":"")+(G?" te-suggest-action":""),onMouseDown:V=>{var P;V.preventDefault();const X=!(B.kind==="identifier"&&((P=B.node.children)!=null&&P.length));T(B,f.fragmentLen,X)},onMouseEnter:()=>p(V=>V&&{...V,index:j}),style:{padding:"4px 8px",borderRadius:4,cursor:"pointer",fontStyle:G?"italic":"normal",borderTop:G&&j>0&&f.items[j-1].kind==="identifier"?`1px solid ${qe.border}`:void 0,background:j===f.index?qe.menuActiveBg:"transparent"},children:W},B.kind==="identifier"?B.node.name:B.kind)})})]})}function Z$({elements:e,rest:t,value:r,onChange:n,plugins:i,path:s=[],disabled:a}){const o=H9(r),l=(r==null?void 0:r.kind)==="tuple"?"tuple":"array",u=m=>n({kind:l,elements:m}),c=(m,f)=>{const p=[...o];for(let g=p.length;g<m;g++){const y=e[g]??t;p[g]=y?nn(y.type):{kind:"primitive",value:null}}p[m]=f,u(p)},d=t?Math.max(o.length,e.length):e.length;return h.jsxs("div",{style:bc,children:[Array.from({length:d},(m,f)=>{const p=e[f]??t,g=f<e.length?p.name||`[${f}]`:`[${f}]`,y=!!t&&F9(f,e.length);return h.jsx(i1,{name:g,type:p.type,optional:p.optional,description:p.description,actions:y&&h.jsx("button",{type:"button",onClick:()=>u(o.filter((b,v)=>v!==f)),"aria-label":`Remove item ${f+1}`,disabled:a,style:I4,children:"×"}),children:h.jsx(Ir,{propDef:{...p,name:g},value:o[f],onChange:b=>c(f,b),plugins:i,path:[...s,String(f)],disabled:a})},f)}),t&&h.jsx("button",{type:"button",onClick:()=>c(d,t.defaultValue??nn(t.type)),disabled:a,style:zm,children:"+ Add item"})]})}function J$({propDef:e,unionInfo:t,value:r,onChange:n,plugins:i,className:s,path:a,disabled:o}){const{members:l}=t,[u,c]=w.useState(null),d=u??h$(t,r),m=l[d],[f,p]=w.useState({}),g=y=>{const b=Number(y);p(x=>({...x,[d]:r})),c(b);const v=l[b];n(v.kind==="constant"?{kind:"primitive",value:v.value}:f[b]??{kind:"primitive",value:void 0})};return h.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.jsx("select",{value:String(d),onChange:y=>g(y.target.value),className:s,style:s?void 0:Mn,disabled:o,children:l.map((y,b)=>h.jsx("option",{value:String(b),children:y.syntax},b))}),m.kind!=="constant"&&h.jsx(Ir,{propDef:{...e,type:m},value:r,onChange:n,plugins:i,className:s,path:a,disabled:o})]})}const W9=w.createContext(void 0);function Y9(){return w.useContext(W9)}function ku(e){if(e.kind==="primitive")return e.base??e.syntax}const eH=[];function Ir(e){const t=Y9(),r=e.propDef.interpolatables,n=r??t,i=n===r?e.propDef:{...e.propDef,interpolatables:n},s=h.jsx(rH,{...e,propDef:i});return r&&r!==t?h.jsx(W9.Provider,{value:r,children:s}):s}function tH(e){switch(e.kind){case"object":case"record":case"array":case"tuple":case"opaque":return!0;case"union":return!e.types.every(t=>t.kind==="constant")&&!e.types.some(t=>ku(t)==="string");case"primitive":return!["string","number","boolean"].includes(ku(e)??"")&&e.syntax!=="Date";default:return!1}}function rH(e){var o;const{value:t,onChange:r,propDef:n,disabled:i}=e,s=n.interpolatables;if((t==null?void 0:t.kind)==="reference")return h.jsx($$,{path:t.path,interpolatables:s??[],onChange:r,onClear:()=>r(n.defaultValue??nn(n.type)),disabled:i});const a=h.jsx(nH,{...e});return!(s!=null&&s.length)||(o=n.catalogs)!=null&&o.length||!tH(n.type)?a:h.jsxs("div",{style:{display:"flex",gap:6,alignItems:"flex-start"},children:[h.jsx("div",{style:{flex:1,minWidth:0},children:a}),h.jsx(q9,{interpolatables:s,onChange:r,disabled:i})]})}function nH({value:e,onChange:t,propDef:r,plugins:n,className:i,path:s=eH,disabled:a}){var d,m;const{type:o}=r;if(n){for(const f of n)if(f.match(o,s)){const p=f.component;return h.jsx(p,{propDef:r,value:e,onChange:t,path:s,disabled:a})}}if((d=r.catalogs)!=null&&d.length)return h.jsx(sH,{propDef:r,value:e,onChange:t,plugins:n,className:i,path:s,disabled:a});if((e==null?void 0:e.kind)==="template"||ku(o)==="string"&&((m=r.interpolatables)!=null&&m.length))return h.jsx(D4,{propDef:r,value:e,onChange:t,className:i,disabled:a});if(o.kind==="function")return h.jsx(D$,{propDef:r,value:e,onChange:t,disabled:a});if(o.kind==="array")return h.jsx(S$,{element:o.element,value:e,onChange:t,plugins:n,path:s,disabled:a});if(o.kind==="tuple")return h.jsx(Z$,{elements:o.elements,rest:o.rest,value:e,onChange:t,plugins:n,path:s,disabled:a});if(o.kind==="record")return h.jsx(V9,{value:o.value,current:e,onChange:t,plugins:n,path:s,disabled:a});const l=g$(o);if(l)return h.jsx(k$,{propDef:r,unionInfo:l,value:e,onChange:t,className:i,disabled:a});const u=B9(o);if(u)return h.jsx(I$,{discriminatedUnionInfo:u,value:e,onChange:t,plugins:n,path:s,disabled:a});if(o.kind==="union"&&o.types.every(f=>f.kind==="constant"))return h.jsx(A$,{propDef:r,value:e,onChange:t,className:i,disabled:a});const c=A4(o);return c?h.jsx(J$,{propDef:r,unionInfo:c,value:e,onChange:t,plugins:n,className:i,path:s,disabled:a}):o.syntax==="Date"?h.jsx(N$,{propDef:r,value:e,onChange:t,disabled:a}):ku(o)==="string"?h.jsx(H$,{propDef:r,value:e,onChange:t,className:i,disabled:a}):ku(o)==="number"?h.jsx(M$,{propDef:r,value:e,onChange:t,className:i,disabled:a}):ku(o)==="boolean"?h.jsx(E$,{propDef:r,value:e,onChange:t,className:i,disabled:a}):o.kind==="opaque"?h.jsx(B$,{propDef:r,value:e,onChange:t,className:i,path:s}):o.kind==="object"&&o.properties.length>0?h.jsx(j$,{properties:o.properties,value:e,onChange:t,plugins:n,path:s,disabled:a}):h.jsx(O$,{propDef:r,value:e,onChange:t,className:i,disabled:a})}function K9({value:e,def:t,onChange:r,plugins:n,path:i=[],disabled:s}){const a=t.type.kind==="function"?t.type.parameters:[];return h.jsxs("div",{"data-proppy-editor":"function-call",children:[h.jsxs("div",{style:{fontFamily:xo,fontSize:11,color:qe.textSecondary},children:[e.callee,"("]}),h.jsx("div",{style:bc,children:a.map((o,l)=>h.jsx(i1,{name:o.name,type:o.type,optional:o.optional,description:o.description,children:h.jsx(Ir,{propDef:o,value:e.args[l],onChange:u=>r(m$(e,a,l,u)),plugins:n,path:[...i,o.name],disabled:s})},l))}),h.jsx("div",{style:{fontFamily:xo,fontSize:11,color:qe.textSecondary},children:")"})]})}function Ax(e){return e.kind==="primitive"&&typeof e.value=="string"&&e.displayValue===void 0?e.value:ma(e)}function iH(e){return e.some(t=>t.literal||t.groups.some(r=>{var n;return(n=r.presets)==null?void 0:n.length}))}function sH(e){const t=e.propDef.catalogs??[];return iH(t)?h.jsx(oH,{...e,catalogs:t}):h.jsx(aH,{...e,catalogs:t})}function aH({propDef:e,catalogs:t,value:r,onChange:n,plugins:i,className:s,path:a,disabled:o}){const l={...e,catalogs:void 0},u=t.flatMap(m=>m.groups.flatMap(f=>f.factory?[{group:f,factory:f.factory}]:[])),c=R4(t,r),d=h.jsxs("select",{value:"",disabled:o,"aria-label":"Kind",className:s?"proppy-catalog-kind":void 0,style:s?void 0:{...Mn,width:"auto",alignSelf:"flex-start"},onChange:m=>{const f=u.find(p=>p.factory.def.name===m.target.value);f&&n(n1(f.factory))},children:[h.jsx("option",{value:"",children:"Choose…"}),u.map(({group:m,factory:f})=>h.jsx("option",{value:f.def.name,children:m.label},f.def.name))]});return c&&(r==null?void 0:r.kind)==="functionCall"?h.jsx("div",{"data-proppy-editor":"catalog",className:s,style:{display:"flex",flexDirection:"column",gap:4},children:h.jsx(K9,{value:r,def:c.factory.def,onChange:n,plugins:i,path:a,disabled:o})}):r?h.jsx(Ir,{propDef:l,value:r,onChange:n,plugins:i,path:a,disabled:o}):h.jsx("div",{"data-proppy-editor":"catalog",className:s,children:d})}function oH({propDef:e,catalogs:t,value:r,onChange:n,plugins:i,className:s,path:a,disabled:o}){var X;const l=u$(),[u,c]=w.useState(!1),[d,m]=w.useState(()=>kx(t,e,r)),f=w.useRef(null),p=w.useRef(null),[g,y]=w.useState(null),b=!s,v=P=>b?void 0:`proppy-catalog-${P}`,x=r?JSON.stringify(r):"";w.useEffect(()=>{u||m(kx(t,e,r))},[x]),w.useEffect(()=>{if(!u)return;const P=()=>{var R;const re=(R=p.current)==null?void 0:R.getBoundingClientRect();re&&y({left:re.left,top:re.bottom+2,minWidth:re.width})};return P(),window.addEventListener("resize",P),window.addEventListener("scroll",P,!0),()=>{window.removeEventListener("resize",P),window.removeEventListener("scroll",P,!0)}},[u]),w.useEffect(()=>{if(!u)return;const P=R=>{var de;(de=f.current)!=null&&de.contains(R.target)||c(!1)},re=R=>{R.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",P),document.addEventListener("keydown",re),()=>{document.removeEventListener("mousedown",P),document.removeEventListener("keydown",re)}},[u]);const E=a_(t,r),T=E?void 0:R4(t,r),C=E!==void 0?t[E.catalogIndex].groups[E.groupIndex].icon:T!==void 0?t[T.catalogIndex].groups[T.groupIndex].icon:void 0,L=r?ma(r):void 0,A=!r&&e.defaultValue?e.defaultValue:void 0,z=A&&(((X=a_(t,A))==null?void 0:X.preset.label)??Ax(A)),I=(E==null?void 0:E.preset.label)??(r&&Ax(r))??z,B=!r&&!A,j=(P,re=!0)=>{n(P),re&&c(!1)},G=t[Math.min(d,t.length-1)],W=j9(G,e),Y=W&&r&&!E&&!T&&Pm(W.type,r)?r:void 0,V=P=>b?P:void 0;return h.jsxs("div",{ref:f,"data-proppy-editor":"catalog",className:s,style:{position:"relative"},children:[h.jsxs("button",{ref:p,type:"button",className:v("trigger"),disabled:o,"aria-haspopup":"listbox","aria-expanded":u,title:L,onClick:()=>c(P=>!P),style:V({...Mn,display:"flex",alignItems:"center",gap:6,textAlign:"left",cursor:o?"default":"pointer"}),children:[l==null?void 0:l(C,18),h.jsxs("span",{className:v("label")&&`${v("label")}${B?" placeholder":""}`,style:V({flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:B?qe.textMuted:void 0}),children:[I??"Select…",A&&h.jsxs("span",{className:v("label-annotation"),style:V({color:qe.textMuted}),children:[" ","(default)"]})]}),E&&L&&h.jsx("span",{className:v("source"),style:V({fontSize:11,color:qe.textMuted}),children:L}),h.jsx("span",{"aria-hidden":!0,className:v("chevron"),style:V({color:qe.textMuted}),children:"▾"})]}),u&&h.jsxs("div",{className:v("menu"),role:"listbox",style:{position:"fixed",left:(g==null?void 0:g.left)??0,top:(g==null?void 0:g.top)??0,minWidth:g==null?void 0:g.minWidth,zIndex:9999,visibility:g?void 0:"hidden",...V({maxHeight:420,overflowY:"auto",padding:4,background:qe.menuBg,color:qe.menuColor,border:`1px solid ${qe.border}`,borderRadius:Es.md,boxShadow:"0 4px 16px rgba(0,0,0,0.16)",fontSize:12.5})},children:[t.length>1&&h.jsx("div",{className:v("modes"),style:V({display:"flex",gap:4,padding:4}),children:t.map((P,re)=>h.jsx("button",{type:"button",className:v("mode")&&`${v("mode")}${re===d?" active":""}`,"aria-pressed":re===d,title:P.description,onClick:()=>m(re),style:V({...L4,flex:1,background:re===d?qe.menuActiveBg:qe.buttonBg}),children:P.label},re))}),G.groups.map((P,re)=>{const R=P.presets??[];return R.length===0&&!P.factory?null:h.jsxs("div",{className:v("group"),style:V({padding:"4px 0"}),children:[h.jsxs("div",{className:v("group-header"),style:V({display:"flex",alignItems:"center",gap:6,padding:"2px 8px",fontSize:11,fontWeight:600,color:qe.textSecondary}),children:[l==null?void 0:l(P.icon,14),h.jsx("span",{children:P.label})]}),R.map((de,Te)=>{const H=(E==null?void 0:E.catalogIndex)===d&&E.groupIndex===re&&E.preset===de;return h.jsxs("button",{type:"button",role:"option","aria-selected":H,className:v("option")&&`${v("option")}${H?" selected":""}`,onClick:()=>j(de.value),style:V({display:"flex",width:"100%",gap:8,padding:"4px 8px",border:"none",borderRadius:4,background:H?qe.menuActiveBg:"transparent",color:"inherit",font:"inherit",textAlign:"left",cursor:"pointer"}),children:[h.jsx("span",{"aria-hidden":!0,className:v("check"),style:V({width:12}),children:H?"✓":""}),h.jsx("span",{className:v("option-label"),style:V({flex:1}),children:de.label}),h.jsx("span",{className:v("option-source"),style:V({fontSize:11,color:qe.textMuted}),children:ma(de.value)})]},Te)}),P.factory&&h.jsxs("button",{type:"button",className:v("custom"),onClick:()=>j(n1(P.factory)),style:V({display:"block",width:"100%",padding:"4px 8px 4px 28px",border:"none",borderRadius:4,background:(T==null?void 0:T.catalogIndex)===d&&T.groupIndex===re?qe.menuActiveBg:"transparent",color:qe.textSecondary,font:"inherit",fontStyle:"italic",textAlign:"left",cursor:"pointer"}),children:["Custom ",P.factory.def.name,"(…)"]})]},re)}),W&&h.jsx("div",{className:v("literal"),style:V({padding:8,borderTop:`1px solid ${qe.border}`}),children:h.jsx(Ir,{propDef:W,value:Y,onChange:P=>j(P,!1),plugins:i,path:a,disabled:o})})]}),T&&(r==null?void 0:r.kind)==="functionCall"&&h.jsx("div",{style:V({marginTop:4}),className:v("call"),children:h.jsx(K9,{value:r,def:T.factory.def,onChange:n,plugins:i,path:a,disabled:o})})]})}function lH(e,t,r){if(r===e.has(t))return e;const n=new Set(e);return r?n.add(t):n.delete(t),n}function X9(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Hf(e,t){return e||(console.warn(`[evalution] Missing providerId for ${t}; prompt linking may not work.`),"")}function Q9(e){if(e.kind==="primitive")return e.syntax==="number"?{kind:"primitive",value:0}:e.syntax==="boolean"?{kind:"primitive",value:!1}:{kind:"primitive",value:""};if(e.kind==="array")return{kind:"array",elements:[]};if(e.kind==="union"){const t=A4(e);if(t)return Q9(t.members[t.defaultIndex]);const r=e.types.find(n=>n.kind==="constant");if(r&&r.kind==="constant")return{kind:"primitive",value:r.value}}return{kind:"primitive",value:void 0}}function vc(e,t,r){return`/api/prompts/${e.providerId}/${X9(e.id)}/${t}${Z9(r)}`}function Z9(e){return e!=null&&e.variation?`?variation=${encodeURIComponent(e.variation)}`:e!=null&&e.version?`?version=${encodeURIComponent(e.version)}`:""}async function ze(e){if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t.error??`Request failed: ${e.status}`)}}async function uH(){const e=await fetch("/api/setup-tasks");return await ze(e),e.json()}async function cH(e,t){const r=await fetch(`/api/setup-tasks/${encodeURIComponent(e)}/steps/${encodeURIComponent(t)}/execute`,{method:"POST"});return await ze(r),r.json()}async function hH(){const e=await fetch("/api/sync",{method:"POST"});await ze(e)}async function dH(){const e=await fetch("/api/sync");return await ze(e),(await e.json()).adopting}async function fH(){const e=await fetch("/api/agents");return await ze(e),e.json()}async function mH(e,t){const r=await fetch(`/api/agents/${encodeURIComponent(e)}/command`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({context:t})});return await ze(r),(await r.json()).command}async function pH(){const e=await fetch("/api/providers");return await ze(e),e.json()}async function Nx(e,t){const r=await fetch(`/api/providers/${e}/add-prompt`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});await ze(r);const n=await r.json();return n&&"id"in n&&C4("add",e,n.id),n}async function gH(){const e=await fetch("/api/prompts");return await ze(e),e.json()}async function bH(e,t){const r=await fetch(`/api/providers/${e}/model-definition?style=${t}`);return await ze(r),r.json()}async function _H(e){const t=await fetch(`/api/providers/${e}/model-parameters`);return await ze(t),t.json()}async function vH(e,t){const r=e.id.lastIndexOf("#"),n=r>=0?`${e.id.slice(0,r+1)}${t}`:e.id;e.providerId&&C4("change",e.providerId,n);const i=await fetch(vc(e,"rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({newName:t})});return await ze(i),i.json()}async function yH(e,t,r){const n=await fetch(`/api/prompts/${e}/${X9(t)}${Z9(r)}`);return await ze(n),n.json()}async function xH(e,t,r){e.providerId&&C4("change",e.providerId,e.id);const n=await fetch(vc(e,"update",r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return await ze(n),n.json()}async function SH(e,t,r){const n=await fetch(vc(e,"execute",r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return await ze(n),n.json()}async function wH(e,{limit:t,before:r}={}){const n=new URLSearchParams;t&&n.set("limit",String(t)),r&&n.set("before",r);const i=n.size?`?${n}`:"",s=await fetch(vc(e,"versions")+i);return await ze(s),s.json()}async function EH(e){const t=await fetch(vc(e,"variations"));return await ze(t),t.json()}function O4(e,t,r=""){return`/api/variations/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r}`}async function Xd(e,t,r,n){const i=await fetch(O4(e,t,`/${r}`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n??{})});return await ze(i),i.status===204?void 0:i.json()}function kH(e,t){return Xd(e,t,"save")}function CH(e,t){return Xd(e,t,"discard")}function TH(e,t,r={}){return Xd(e,t,"open-on-head",r)}async function AH(e,t,r={}){const n=await fetch(vc(e,"open-on-head",{version:t}),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return await ze(n),n.json()}function NH(e,t,r){return Xd(e,t,"resolve",{choices:r})}async function RH(e,t,r){const n=await fetch(O4(e,t,"/name"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r})});return await ze(n),n.json()}function LH(e,t,r,n){return Xd(e,t,"rename",{from:r,to:n})}async function IH(e,t){for(const r of t.names){const n=await fetch(O4(e,t.id,`/name/${encodeURIComponent(r)}`),{method:"DELETE"});await ze(n)}}async function DH(e){if(e.length===0)return{};const t=await fetch(`/api/variations?ids=${e.map(encodeURIComponent).join(",")}`);return await ze(t),t.json()}function J9(e){const t=new URLSearchParams(Zz(e));return t.size>0?`?${t}`:""}async function OH(e){const t=await fetch(`/api/traces/groups${J9(e)}`);return await ze(t),t.json()}async function MH(e){const t=await fetch(`/api/traces${J9(e??{})}`);return await ze(t),t.json()}async function jH(e,t){const r=await fetch(`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:"DELETE"});await ze(r)}async function BH(e,t,{signal:r,timeoutMs:n=1e4,intervalMs:i=150}={}){const s=`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,a=Date.now()+n;for(;;){const o=await fetch(s,{signal:r});if(o.ok)return o.json();(o.status!==404||Date.now()>=a)&&await ze(o),await PH(i,r)}}function PH(e,t){return new Promise((r,n)=>{if(t!=null&&t.aborted){n(new DOMException("Aborted","AbortError"));return}const i=setTimeout(r,e);t==null||t.addEventListener("abort",()=>{clearTimeout(i),n(new DOMException("Aborted","AbortError"))},{once:!0})})}function zH(e,t,r){const n=`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}/events`,i=new EventSource(n);return i.onmessage=s=>{try{const a=JSON.parse(s.data);a!=null&&a.type&&a.type!=="connected"&&r(a)}catch{}},()=>i.close()}function M4(e,t,r=""){return`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}/annotations${r}`}async function $H(e,t){const r=await fetch(M4(e,t));return await ze(r),r.json()}async function HH(e,t,r){const n=await fetch(M4(e,t),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return await ze(n),n.json()}async function FH(e,t,r){const n=await fetch(M4(e,t,`/${encodeURIComponent(r)}`),{method:"DELETE"});await ze(n)}function Qn(e,t,r=""){const n=`/api/datasets/${encodeURIComponent(e)}`;return t?`${n}/${encodeURIComponent(t)}${r}`:n}async function eA(){const e=await fetch("/api/datasets");return await ze(e),e.json()}async function F_e(e,t){const r=await fetch(Qn(e,t));return await ze(r),r.json()}async function U_e(e,t,r,n){const i=await fetch(Qn(e,t,`/rows?offset=${r}&limit=${n}`));return await ze(i),i.json()}async function tA(e,t){const r=await fetch(Qn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return await ze(r),r.json()}async function UH(e){const[t]=await rA();if(!t)throw new Error("No dataset provider is configured");const r=await tA(t.id,{name:e,fields:[]});return{providerId:t.id,id:r.id,name:r.name,rowCount:0,fields:r.fields,updatedAt:r.updatedAt}}async function V_e(e,t,r){const n=await fetch(Qn(e,t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r})});return await ze(n),n.json()}async function q_e(e,t){const r=await fetch(Qn(e,t),{method:"DELETE"});await ze(r)}async function VH(e,t,r){const n=await fetch(Qn(e,t,"/rows"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rows:r})});return await ze(n),n.json()}async function G_e(e,t,r){const n=await fetch(Qn(e,t,"/rows"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:r})});await ze(n)}async function W_e(e,t,r){const n=await fetch(Qn(e,t,"/fields"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return await ze(n),n.json()}async function Y_e(e,t,r,n){const i=await fetch(Qn(e,t,`/fields/${encodeURIComponent(r)}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n})});return await ze(i),i.json()}async function K_e(e,t,r){const n=await fetch(Qn(e,t,`/fields/${encodeURIComponent(r)}`),{method:"DELETE"});await ze(n)}async function X_e(e,t,r){const n=await fetch(Qn(e,t,"/paths"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r})});return await ze(n),n.json()}async function Q_e(e,t,r,n){const i=await fetch(Qn(e,t,"/columns"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({columns:r,rowLabel:n})});return await ze(i),i.json()}async function Z_e(e,t,r){const n=await fetch(Qn(e,t,`/rows/${encodeURIComponent(r)}`),{method:"DELETE"});await ze(n)}async function J_e(e,t,r){const n=await fetch(Qn(e,t,"/rows"),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({rowIds:r})});await ze(n);const{deleted:i}=await n.json();return i}async function rA(){const e=await fetch("/api/dataset-providers");return await ze(e),e.json()}function yc(e,t,r=""){const n=`/api/evals/${encodeURIComponent(e)}`;return t?`${n}/${encodeURIComponent(t)}${r}`:n}function j4(e,t,r=""){return`/api/eval-runs/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r}`}class qH extends Error{constructor(r,n){super(r);J(this,"problems");this.problems=n}}async function GH(){const e=await fetch("/api/eval-providers");return await ze(e),e.json()}async function WH(){const e=await fetch("/api/evals");return await ze(e),e.json()}async function eve(e,t){const r=await fetch(yc(e,t));return await ze(r),r.json()}async function YH(e,t){var i;const r=t??((i=(await GH())[0])==null?void 0:i.id);if(!r)throw new Error("No eval provider is configured");const n=await fetch(yc(r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return await ze(n),{...await n.json(),providerId:r}}async function tve(e,t,r){const n=await fetch(yc(e,t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return await ze(n),n.json()}async function rve(e,t){const r=await fetch(yc(e,t),{method:"DELETE"});await ze(r)}async function nve(e,t,r={}){const n=await fetch(yc(e,t,"/runs"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok){const i=await n.json().catch(()=>({}));throw Array.isArray(i.problems)?new qH(i.error,i.problems):new Error(i.error??`Request failed: ${n.status}`)}return n.json()}async function ive(e,t){const r=await fetch(yc(e,t,"/runs"));return await ze(r),r.json()}async function sve(e,t){const r=await fetch(j4(e,t));return await ze(r),r.json()}async function ave(e,t){const r=await fetch(j4(e,t,"/cancel"),{method:"POST"});await ze(r)}async function ove(e,t){const r=await fetch(j4(e,t),{method:"DELETE"});await ze(r)}async function lve(){const e=await fetch("/api/checks");return await ze(e),e.json()}async function KH(e,t){const r=await fetch(`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}/check-results`);return await ze(r),r.json()}async function XH(e,t){const r=await fetch(`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}/eval-run`);return await ze(r),await r.json()??void 0}async function uve(e){const t=await fetch(`/api/prompt-providers/${encodeURIComponent(e)}/head`);return await ze(t),t.json()}async function QH(){const e=await fetch("/api/views");return await ze(e),e.json()}function ZH({onClose:e,onCreated:t}){const[r,n]=w.useState({type:"loading"}),[i,s]=w.useState({}),[a,o]=w.useState(null);w.useEffect(()=>{pH().then(c=>{const d=c.filter(m=>m.hasAddPrompt);d.length===0?o("No providers support adding prompts"):d.length===1?l(d[0].id):n({type:"pick-provider",providers:d})}).catch(c=>o(c.message))},[]);async function l(c){n({type:"loading"}),o(null);try{const d=await Nx(c,{});if("fields"in d){const m={};for(const f of d.fields)f.defaultValue&&(m[f.name]=f.defaultValue);s(m),n({type:"form",providerId:c,context:d})}else t(d)}catch(d){o(d.message)}}async function u(c){if(c.preventDefault(),r.type!=="form")return;o(null),n({type:"submitting"});const d={};for(const[m,f]of Object.entries(i))f&&(d[m]=f);if(d.directory!==void 0&&d.fileName){const m=d.directory==="."?"":d.directory+"/";d.metadata={relativeFilePath:m+d.fileName},delete d.directory,delete d.fileName}try{const m=await Nx(r.providerId,d);if("fields"in m){const f={};for(const p of m.fields)p.defaultValue&&(f[p.name]=p.defaultValue);s({...f,...i}),n({type:"form",providerId:r.providerId,context:m})}else t(m)}catch(m){o(m.message),n({type:"form",providerId:r.providerId,context:r.context})}}return h.jsx("div",{className:"dialog-backdrop",onClick:e,children:h.jsxs("div",{className:"dialog",onClick:c=>c.stopPropagation(),children:[h.jsxs("div",{className:"dialog-header",children:[h.jsx("h3",{children:"New Prompt"}),h.jsx("button",{type:"button",className:"dialog-close",onClick:e,children:"×"})]}),h.jsxs("div",{className:"dialog-body",children:[a&&h.jsx("div",{className:"dialog-error",children:a}),r.type==="loading"&&h.jsx("div",{className:"dialog-status",children:"Loading..."}),r.type==="submitting"&&h.jsx("div",{className:"dialog-status",children:"Creating..."}),r.type==="pick-provider"&&h.jsx("div",{className:"dialog-providers",children:r.providers.map(c=>h.jsxs("button",{type:"button",className:"dialog-provider-btn",onClick:()=>l(c.id),children:[c.icon&&h.jsx("span",{className:"dialog-provider-icon",dangerouslySetInnerHTML:{__html:c.icon}}),h.jsxs("div",{children:[h.jsx("div",{className:"dialog-provider-name",children:c.displayName??c.id}),c.description&&h.jsx("div",{className:"dialog-provider-desc",children:c.description})]})]},c.id))}),r.type==="form"&&h.jsxs("form",{onSubmit:u,children:[r.context.fields.map(c=>{var d;return h.jsxs("div",{className:"dialog-field",children:[h.jsx("label",{htmlFor:`field-${c.name}`,children:c.label}),c.type==="select"?h.jsx("select",{id:`field-${c.name}`,value:i[c.name]??"",onChange:m=>s(f=>({...f,[c.name]:m.target.value})),required:c.required,children:(d=c.options)==null?void 0:d.map(m=>h.jsx("option",{value:m.value,children:m.label},m.value))}):h.jsx("input",{id:`field-${c.name}`,type:"text",value:i[c.name]??"",onChange:m=>s(f=>({...f,[c.name]:m.target.value})),placeholder:c.placeholder,required:c.required})]},c.name)}),h.jsxs("div",{className:"dialog-actions",children:[h.jsx("button",{type:"button",className:"dialog-btn-cancel",onClick:e,children:"Cancel"}),h.jsx("button",{type:"submit",className:"dialog-btn-create",children:"Create"})]})]})]})]})})}function JH(e,t){return e.key===t?{key:t,dir:e.dir==="asc"?"desc":"asc"}:{key:t,dir:"desc"}}function Rx(e,t,r){const n=r==="asc"?1:-1;return[...e].sort((i,s)=>{const a=t(i),o=t(s);return a===void 0?o===void 0?0:1:o===void 0?-1:typeof a=="string"||typeof o=="string"?String(a).localeCompare(String(o))*n:(a-o)*n})}const eF=120,tF=24,rF=340,nF=480;function B4(e){const t=e.reduce((r,n)=>r+n,eF)+tF;return Math.min(nF,Math.max(rF,t))}function Lx(e){const t=e&&typeof e=="object"?e:{},r=i=>typeof i=="number"&&Number.isFinite(i)&&i>0?i:void 0,n=Array.isArray(t.widths)?t.widths:[];return{current:t.current===1?1:0,widths:[r(n[0]),r(n[1])]}}function iF(e,t,r){const n=e.current===0?1:0,i=[...e.widths];return i[e.current]=t,{memory:{current:n,widths:i},width:i[n]??r}}function Qd(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),h.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),h.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),h.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]})}function nA(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"4",y1:"6",x2:"14",y2:"6"}),h.jsx("line",{x1:"8",y1:"12",x2:"20",y2:"12"}),h.jsx("line",{x1:"6",y1:"18",x2:"16",y2:"18"})]})}function s1(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"12",cy:"13",r:"8"}),h.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),h.jsx("line",{x1:"12",y1:"13",x2:"15",y2:"15"}),h.jsx("line",{x1:"9",y1:"2",x2:"15",y2:"2"}),h.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"5"})]})}function a1(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),h.jsx("polyline",{points:"14 2 14 8 20 8"}),h.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),h.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),h.jsx("line",{x1:"10",y1:"9",x2:"8",y2:"9"})]})}function Zd(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),h.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function cve(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),h.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function Ix(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("polyline",{points:"3 6 5 6 21 6"}),h.jsx("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),h.jsx("path",{d:"M10 11v6M14 11v6"}),h.jsx("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})}function sF(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"4",y1:"6",x2:"14",y2:"6"}),h.jsx("line",{x1:"8",y1:"12",x2:"20",y2:"12"}),h.jsx("line",{x1:"6",y1:"18",x2:"16",y2:"18"})]})}function aF(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("polyline",{points:"8.5 0.5 12 3.5 15.5 0.5"}),h.jsx("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),h.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"}),h.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18"}),h.jsx("polyline",{points:"8.5 23.5 12 20.5 15.5 23.5"})]})}function oF(){return h.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:h.jsx("path",{d:"M14.7 6.3a4 4 0 0 0-5.6 4.6L2 18l4 4 7.1-7.1a4 4 0 0 0 4.6-5.6l-2.8 2.8-3-3Z"})})}function P4({open:e}){return h.jsx("svg",{className:`chevron-icon${e?" chevron-icon-open":""}`,width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:h.jsx("polyline",{points:"9 18 15 12 9 6"})})}function lF(){return h.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:h.jsx("polyline",{points:"6 9 12 15 18 9"})})}function uF(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M2.5 5.5A1.5 1.5 0 0 1 4 4h10a1.5 1.5 0 0 1 1.5 1.5v6A1.5 1.5 0 0 1 14 13H8.5l-3 3v-3H4a1.5 1.5 0 0 1-1.5-1.5Z"}),h.jsx("path",{d:"M19.5 9.5H20A1.5 1.5 0 0 1 21.5 11v4A1.5 1.5 0 0 1 20 16.5v3l-3-3h-3"})]})}function z4(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("polyline",{points:"7 3 3 7 7 11"}),h.jsx("line",{x1:"3",y1:"7",x2:"17",y2:"7"}),h.jsx("polyline",{points:"17 13 21 17 17 21"}),h.jsx("line",{x1:"21",y1:"17",x2:"7",y2:"17"})]})}function $4(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"12",cy:"12",r:"9"}),h.jsx("path",{d:"M15 9.5c0-1.1-1.34-2-3-2s-3 .9-3 2 1.34 2 3 2 3 .9 3 2-1.34 2-3 2-3-.9-3-2"}),h.jsx("line",{x1:"12",y1:"6",x2:"12",y2:"18"})]})}function H4(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1.5"}),h.jsx("line",{x1:"9",y1:"2",x2:"9",y2:"6"}),h.jsx("line",{x1:"15",y1:"2",x2:"15",y2:"6"}),h.jsx("line",{x1:"9",y1:"18",x2:"9",y2:"22"}),h.jsx("line",{x1:"15",y1:"18",x2:"15",y2:"22"}),h.jsx("line",{x1:"2",y1:"9",x2:"6",y2:"9"}),h.jsx("line",{x1:"2",y1:"15",x2:"6",y2:"15"}),h.jsx("line",{x1:"18",y1:"9",x2:"22",y2:"9"}),h.jsx("line",{x1:"18",y1:"15",x2:"22",y2:"15"})]})}function iA(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M3.5 17a9 9 0 1 1 17 0"}),h.jsx("line",{x1:"12",y1:"15",x2:"16.5",y2:"9"}),h.jsx("circle",{cx:"12",cy:"15",r:"1"})]})}function cF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M3 3h9l9 9-9 9-9-9V3z"}),h.jsx("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"})]})}function hF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M5 21V4"}),h.jsx("path",{d:"M5 4h12l-2.5 4 2.5 4H5"})]})}function dF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("polygon",{points:"8 2 16 2 22 8 22 16 16 22 8 22 2 16 2 8"}),h.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function fF(){return h.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:h.jsx("path",{d:"M7 18a4.5 4.5 0 0 1-.6-8.96A6 6 0 0 1 18 10a4 4 0 0 1-.5 8Z"})})}function mF(){return h.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[h.jsx("circle",{cx:"5",cy:"12",r:"2.2"}),h.jsx("circle",{cx:"12",cy:"12",r:"2.2"}),h.jsx("circle",{cx:"19",cy:"12",r:"2.2"})]})}function Jd({size:e=11}){return h.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("ellipse",{cx:"12",cy:"5",rx:"8",ry:"3"}),h.jsx("path",{d:"M4 5v14c0 1.66 3.58 3 8 3s8-1.34 8-3V5"}),h.jsx("path",{d:"M4 12c0 1.66 3.58 3 8 3s8-1.34 8-3"})]})}function pF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"12",cy:"12",r:"4"}),h.jsx("line",{x1:"2",y1:"12",x2:"8",y2:"12"}),h.jsx("line",{x1:"16",y1:"12",x2:"22",y2:"12"})]})}function gF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"12",cy:"12",r:"9"}),h.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),h.jsx("path",{d:"M12 3a14 14 0 0 1 0 18a14 14 0 0 1 0-18"})]})}function bF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"6",cy:"6",r:"2.5"}),h.jsx("circle",{cx:"6",cy:"18",r:"2.5"}),h.jsx("circle",{cx:"18",cy:"8",r:"2.5"}),h.jsx("line",{x1:"6",y1:"8.5",x2:"6",y2:"15.5"}),h.jsx("path",{d:"M18 10.5c0 4-6 3.5-11 6"})]})}function o1({size:e=11}){return h.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"3"}),h.jsx("polyline",{points:"8 12.5 11 15.5 16.5 9"})]})}function _F(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),h.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),h.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function hve({filled:e=!1}){return h.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:e?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M3 3h9l9 9-9 9-9-9V3z"}),h.jsx("circle",{cx:"8",cy:"8",r:"1",fill:e?"var(--dropdown-bg, #fff)":"currentColor",stroke:"none"})]})}function dve(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),h.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function vF(){return h.jsxs("svg",{width:"10",height:"16",viewBox:"0 0 10 16",fill:"currentColor","aria-hidden":!0,children:[h.jsx("circle",{cx:"3",cy:"3",r:"1.3"}),h.jsx("circle",{cx:"7",cy:"3",r:"1.3"}),h.jsx("circle",{cx:"3",cy:"8",r:"1.3"}),h.jsx("circle",{cx:"7",cy:"8",r:"1.3"}),h.jsx("circle",{cx:"3",cy:"13",r:"1.3"}),h.jsx("circle",{cx:"7",cy:"13",r:"1.3"})]})}function Dx(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71"}),h.jsx("path",{d:"M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71"})]})}function yF(){return h.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:h.jsx("polygon",{points:"22 3 2 3 10 12.5 10 19 14 21 14 12.5 22 3"})})}function xF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),h.jsx("line",{x1:"9",y1:"12",x2:"21",y2:"12"}),h.jsx("line",{x1:"9",y1:"18",x2:"21",y2:"18"})]})}function sA(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 11 11",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("circle",{cx:"4.5",cy:"4.5",r:"3"}),h.jsx("line",{x1:"7",y1:"7",x2:"9.5",y2:"9.5"})]})}function Ox({label:e,icon:t,sortKey:r,sort:n,onSort:i,className:s,width:a}){const o=n.key===r;return h.jsx("th",{className:s,style:a!==void 0?{width:a}:void 0,"aria-sort":o?n.dir==="asc"?"ascending":"descending":"none",children:h.jsxs("button",{type:"button",className:`trace-table-sort-btn${o?" trace-table-sort-btn-active":""}`,onClick:()=>i(r),title:`Sort by ${e}`,children:[t??e,h.jsx("span",{className:"trace-table-sort-arrow","aria-hidden":!0,children:o?n.dir==="asc"?"▲":"▼":""})]})})}function Mx(e,t,r){let n=e;return t.key===r&&(n+=` ${e}-selected`),t.count!==void 0&&(n+=` ${e}-group`),t.placeholder&&(n+=` ${e}-loading`),t.child&&(n+=` ${e}-child`),n}function jx({row:e,itemName:t,itemMarker:r}){if(e.placeholder)return h.jsx("span",{className:"trace-list-name",children:"Loading…"});const n=e.count!==void 0;return h.jsxs(h.Fragment,{children:[n&&h.jsx("span",{className:"trace-list-chevron",children:h.jsx(P4,{open:!!e.open})}),r==null?void 0:r(e.item),h.jsx("span",{className:"trace-list-name",children:t(e.item)}),n&&h.jsx("span",{className:"trace-list-group-count",children:e.count})]})}function SF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"2",y1:"7",x2:"18",y2:"7"}),h.jsx("polyline",{points:"14 3 18 7 14 11"}),h.jsx("line",{x1:"22",y1:"17",x2:"6",y2:"17"}),h.jsx("polyline",{points:"10 13 6 17 10 21"})]})}function wF(e){try{return Lx(JSON.parse(localStorage.getItem(e)??"null"))}catch{return Lx(null)}}function F4({sidebarWidth:e,onResizeSidebar:t,tableWidth:r,storageKey:n}){const i=`table-mode:${n}`,[s,a]=w.useState(()=>wF(i)),o=()=>{const l=iF(s,e,r);a(l.memory);try{localStorage.setItem(i,JSON.stringify(l.memory))}catch{}t(l.width)};return h.jsx("button",{type:"button",className:"tree-toolbar-btn",title:"Toggle table view",onClick:o,children:h.jsx(SF,{})})}function U4({title:e,headerActions:t,toolbar:r,loading:n,error:i,empty:s,items:a,columns:o,cardColumnCount:l=3,itemKey:u,itemName:c,itemTitle:d=c,itemMarker:m,itemChildren:f,itemGroupCount:p,onExpandGroup:g,selectedKey:y,onSelect:b,defaultSort:v}){const[x,E]=w.useState(v),[T,C]=w.useState(new Set),L=P=>C(re=>{const R=new Set(re);return R.delete(P)||R.add(P),R}),[A,z]=w.useState(y);if(y!==A){z(y);const P=a.find(R=>{var de;return(de=f==null?void 0:f(R))==null?void 0:de.some(Te=>u(Te)===y)}),re=P&&u(P);re!==void 0&&!T.has(re)&&C(R=>new Set(R).add(re))}w.useEffect(()=>{if(g)for(const P of a)T.has(u(P))&&(p==null?void 0:p(P))!==void 0&&!(f!=null&&f(P))&&g(P)});const I=h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"section-panel-header",children:[h.jsx("span",{children:e}),t&&h.jsx("div",{className:"section-panel-header-actions",children:t})]}),r]});if(n||i||a.length===0)return h.jsxs(h.Fragment,{children:[I,h.jsx("div",{className:"section-panel-body",children:n?h.jsx("div",{className:"tree-status",children:"Loading..."}):i?h.jsxs("div",{className:"tree-status tree-error",children:["Error: ",i]}):h.jsx("div",{className:"tree-empty-state",children:s})})]});const B=o.find(P=>P.key===x.key),j=P=>x.key==="name"?Rx(P,c,x.dir):B!=null&&B.sortValue?Rx(P,B.sortValue,x.dir):P,G=j(a).flatMap(P=>{const re=u(P),R=f==null?void 0:f(P),de=(p==null?void 0:p(P))??(R==null?void 0:R.length);if(de===void 0)return[{item:P,key:re}];const Te=T.has(re),H={item:P,key:re,count:de,children:R,open:Te};return Te?R?[H,...j(R).map(Oe=>({item:Oe,key:u(Oe),child:!0}))]:[H,{item:P,key:`${re}:loading`,child:!0,placeholder:!0}]:[H]}),W=P=>{P.placeholder||(P.count!==void 0?L(P.key):b(P.item))},Y=P=>P.placeholder?void 0:d(P.item),V=o.slice(0,l),X=P=>E(re=>JH(re,P));return h.jsxs(h.Fragment,{children:[I,h.jsxs("div",{className:"section-panel-body trace-list",children:[h.jsx("div",{className:"trace-list-cards",children:G.map(P=>{const{item:re}=P;return h.jsxs("div",{className:Mx("trace-list-row",P,y),onClick:()=>W(P),title:Y(P),...P.count!==void 0&&{role:"button","aria-expanded":P.open},children:[h.jsx("div",{className:"trace-list-row-top",children:h.jsx(jx,{row:P,itemName:c,itemMarker:m})}),h.jsx("div",{className:"trace-list-row-meta",children:(P.placeholder?[]:V).map(R=>{const de=(R.card??R.cell)(re);return de===null?null:h.jsxs("span",{className:"trace-list-meta-item",children:[R.icon,de]},R.key)})})]},P.key)})}),h.jsxs("table",{className:"trace-table",children:[h.jsx("thead",{children:h.jsxs("tr",{children:[h.jsx(Ox,{label:"Name",sortKey:"name",sort:x,onSort:X,className:"trace-table-name-th"}),o.map(P=>{const re=`trace-table-th trace-table-col-${P.key}`;return P.sortValue?h.jsx(Ox,{label:P.label,icon:P.icon,sortKey:P.key,sort:x,onSort:X,className:re,width:P.width},P.key):h.jsx("th",{className:re,style:{width:P.width},title:P.label,children:P.icon},P.key)})]})}),h.jsx("tbody",{children:G.map(P=>{const{item:re}=P;return h.jsxs("tr",{className:Mx("trace-table-row",P,y),onClick:()=>W(P),title:Y(P),"aria-expanded":P.count!==void 0?P.open:void 0,children:[h.jsx("td",{children:h.jsx("div",{className:"trace-table-name-cell",children:h.jsx(jx,{row:P,itemName:c,itemMarker:m})})}),o.map(R=>h.jsx("td",{className:`trace-table-col-${R.key}`,children:!P.placeholder&&R.cell(re)},R.key))]},P.key)})})]})]})]})}function V4({label:e=!0}){return h.jsxs("span",{className:"syncing-indicator",role:"status","aria-label":e?void 0:"Syncing",title:"Starting to sync with Evalution Cloud. Changes made now are saved once it's done — keep evalution running until then.",children:[h.jsx("span",{className:"syncing-indicator-ring","aria-hidden":"true"}),e&&"Syncing"]})}function Sl(e){return e<1?"<1ms":e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(2)}s`}function o_(e){return new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}function ks(e){return new Date(e).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:"numeric",minute:"2-digit"})}function EF(e){return e.status??(e.endTime===void 0?"running":void 0)}function kF(e){switch(e){case"ok":return"✓";case"error":return"✕";case"running":return"●";default:return"?"}}function Bu(e){return e.toLocaleString()}function fo(e){return e<1e-4?"<$0.0001":e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}const Oo=8;function Fi({open:e,onClose:t,matchTriggerWidth:r=!0,extraContains:n}){const i=w.useRef(null),s=w.useRef(null),[a,o]=w.useState({position:"fixed"}),l=w.useCallback(()=>{var f;if(!i.current)return;const u=i.current.getBoundingClientRect();let c=u.left,d=u.bottom+4;if(r){o({position:"fixed",top:d,left:c,width:u.width,zIndex:9999});return}const m=(f=s.current)==null?void 0:f.getBoundingClientRect();if(m&&(c+m.width>window.innerWidth-Oo&&(c=Math.max(Oo,u.right-m.width)),c=Math.min(c,window.innerWidth-Oo-m.width),c=Math.max(Oo,c),d+m.height>window.innerHeight-Oo)){const p=u.top-4-m.height;d=p>=Oo?p:Oo}o({position:"fixed",top:d,left:c,zIndex:9999})},[r]);return w.useLayoutEffect(()=>{if(!e)return;l();const u=m=>{var p,g;const f=m.target;(p=i.current)!=null&&p.contains(f)||(g=s.current)!=null&&g.contains(f)||n!=null&&n(f)||t()},c=m=>{m.key==="Escape"&&t()};document.addEventListener("pointerdown",u),document.addEventListener("keydown",c),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l);let d;return s.current&&typeof ResizeObserver<"u"&&(d=new ResizeObserver(l),d.observe(s.current)),()=>{d==null||d.disconnect(),document.removeEventListener("pointerdown",u),document.removeEventListener("keydown",c),window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[e,l]),{triggerRef:i,popoverRef:s,style:a}}function Za(e){return`${e.providerId}:${e.id}`}function CF({onCreated:e}){const[t,r]=w.useState(!1),[n,i]=w.useState(""),[s,a]=w.useState(!1),[o,l]=w.useState(null),u=w.useRef(!1),c=w.useCallback(()=>{r(!1),i("")},[]),d=w.useCallback(()=>{u.current||c()},[c]),m=()=>{l(null),r(!0)},{triggerRef:f,popoverRef:p,style:g}=Fi({open:t,onClose:d,matchTriggerWidth:!1}),y=async()=>{const b=n.trim();if(b){u.current=!0,a(!0);try{const v=await UH(b);c(),e(v)}catch(v){l(v.message)}finally{u.current=!1,a(!1)}}};return h.jsxs(h.Fragment,{children:[h.jsx("button",{ref:f,type:"button",className:`tree-toolbar-btn${t?" tree-toolbar-btn-active":""}`,title:"New dataset…","aria-label":"New dataset",onClick:()=>t?d():m(),children:h.jsx(Zd,{})}),t&&cn.createPortal(h.jsxs("div",{className:"add-to-dataset-menu",ref:p,style:g,children:[h.jsxs("form",{className:"add-to-dataset-new",onSubmit:b=>{b.preventDefault(),y()},children:[h.jsx("input",{autoFocus:!0,className:"add-to-dataset-name",placeholder:"Dataset name","aria-label":"New dataset name",value:n,onChange:b=>i(b.target.value),disabled:s}),h.jsx("button",{type:"submit",className:"add-to-dataset-create",disabled:s||!n.trim(),children:"Create"})]}),o&&h.jsx("div",{className:"add-to-dataset-error",children:o})]}),document.body)]})}function TF({datasets:e,loading:t,error:r,selectedKey:n,onSelect:i,promptName:s,sidebarWidth:a,onResizeSidebar:o,syncing:l}){const u=d=>d.prompt&&s(d.prompt),c=[{key:"rowCount",label:"Rows",icon:h.jsx(Jd,{}),width:48,cell:d=>d.error?h.jsx("span",{className:"dataset-list-error",children:"error"}):d.rowCount,card:d=>d.error?h.jsx("span",{className:"dataset-list-error",children:"can't be opened"}):`${d.rowCount} row${d.rowCount===1?"":"s"}`,sortValue:d=>d.error?void 0:d.rowCount},{key:"prompt",label:"Prompt",icon:h.jsx(a1,{}),width:110,cell:d=>u(d)||"—",card:d=>u(d)||null,sortValue:d=>u(d)||void 0},{key:"updatedAt",label:"Updated",icon:h.jsx(Qd,{}),width:100,cell:d=>d.updatedAt>0?ks(d.updatedAt):"—",card:d=>d.updatedAt>0?ks(d.updatedAt):null,sortValue:d=>d.updatedAt}];return h.jsx(U4,{title:"Datasets",headerActions:h.jsxs(h.Fragment,{children:[h.jsx(F4,{sidebarWidth:a,onResizeSidebar:o,tableWidth:B4(c.map(d=>d.width)),storageKey:"datasets"}),h.jsx(CF,{onCreated:i})]}),loading:t,error:r,empty:h.jsxs(h.Fragment,{children:[h.jsx("p",{children:"No datasets yet."}),h.jsx("p",{className:"trace-list-hint",children:"Start one by hand with “+” above, or use “Add to dataset” in a prompt's execute panel or on a trace."})]}),items:e,columns:c,itemKey:Za,itemName:d=>d.name,itemTitle:d=>d.error??d.name,itemMarker:d=>l!=null&&l.has(Za(d))?h.jsx(V4,{label:!1}):null,selectedKey:n,onSelect:i,defaultSort:{key:"updatedAt",dir:"desc"}})}function aA(){return{pass:0,fail:0,error:0,skipped:0,scored:0}}function Bx(e,t){if(e.length===0)return;const r=[...e].sort((i,s)=>i-s),n=Math.max(1,Math.ceil(t*r.length));return r[n-1]}function l_(e){const t=e.pass+e.fail;return t===0?void 0:e.pass/t}function fve(e,t,r){const n=e.rows.filter(o=>o.armId===t),i=e.checks.filter(o=>o.armId===t),s=n.flatMap(o=>o.costUsd===void 0?[]:[o.costUsd]),a=n.flatMap(o=>o.durationMs===void 0?[]:[o.durationMs]);return{armId:t,checks:r.map(o=>{const l=aA(),u=[];for(const c of i)c.checkId===o&&(l[c.outcome]++,c.score!==void 0&&u.push(c.score));return{checkId:o,counts:l,...l_(l)!==void 0&&{passRate:l_(l)},...u.length>0&&{meanScore:u.reduce((c,d)=>c+d,0)/u.length}}}),rowErrors:n.filter(o=>o.status!=="ok").length,...s.length>0&&{totalCost:s.reduce((o,l)=>o+l,0)},...a.length>0&&{p50Duration:Bx(a,.5),p95Duration:Bx(a,.95)}}}function oA(e,t,r){return`${e}:${t}:${r}`}function AF(e){return new Map(e.map(t=>[oA(t.armId,t.rowId,t.checkId),t]))}function mve(e){const t=new Map;for(const r of e.rows){let n=t.get(r.rowId);n||(n={rowId:r.rowId,rowIndex:r.rowIndex,arms:new Map},t.set(r.rowId,n)),n.arms.set(r.armId,r)}return[...t.values()].sort((r,n)=>r.rowIndex-n.rowIndex)}const NF={pass:"✓",fail:"✗",error:"!",skipped:"–",scored:""},Px=new Set(["pass"]);function pve(e,t){var s,a;const r=new Map(t.arms.map(o=>[o.label,o.id])),n=AF(t.results.checks),i=[];for(const o of e.results.checks){const l=(s=e.arms.find(d=>d.id===o.armId))==null?void 0:s.label,u=l&&r.get(l);if(!u)continue;const c=(a=n.get(oA(u,o.rowId,o.checkId)))==null?void 0:a.outcome;c===void 0||c===o.outcome||i.push({rowId:o.rowId,armId:o.armId,checkId:o.checkId,before:c,after:o.outcome,regressed:Px.has(c)&&!Px.has(o.outcome)})}return i.sort((o,l)=>Number(l.regressed)-Number(o.regressed))}function zx(e){return e===void 0?"—":`${Math.round(e*100)}%`}function gve(e,t){const r=`the run from ${ks(e)}`;return t?`Cancel and delete ${r}, with its results?`:`Delete ${r} and its results?`}function bve(e){return structuredClone({name:`${e.name} copy`,prompt:e.prompt,dataset:e.dataset,inputs:e.inputs,checks:e.checks})}function lA(e){return`${e.providerId}:${e.id}`}function $g(e){return e.lastRun&&l_(e.lastRun.counts)}function RF({evals:e,loading:t,error:r,selectedKey:n,onSelect:i,onNew:s,promptName:a,sidebarWidth:o,onResizeSidebar:l,syncing:u=!1}){const c=[{key:"passRate",label:"Last run",icon:h.jsx(o1,{}),width:64,cell:d=>{var m;return((m=d.lastRun)==null?void 0:m.status)==="running"?`${d.lastRun.done}/${d.lastRun.total}`:zx($g(d))},card:d=>d.lastRun?d.lastRun.status==="running"?`running ${d.lastRun.done}/${d.lastRun.total}`:`${zx($g(d))} passing`:"never run",sortValue:$g},{key:"prompt",label:"Prompt",icon:h.jsx(a1,{}),width:110,cell:d=>a(d.prompt)||"—",card:d=>a(d.prompt)||null,sortValue:d=>a(d.prompt)||void 0},{key:"updatedAt",label:"Updated",icon:h.jsx(Qd,{}),width:100,cell:d=>ks(d.updatedAt),card:d=>ks(d.updatedAt),sortValue:d=>d.updatedAt}];return h.jsx(U4,{title:"Evals",headerActions:h.jsxs(h.Fragment,{children:[u&&h.jsx(V4,{}),h.jsx(F4,{sidebarWidth:o,onResizeSidebar:l,tableWidth:B4(c.map(d=>d.width)),storageKey:"evals"}),h.jsx("button",{type:"button",className:"tree-toolbar-btn",title:"New eval…","aria-label":"New eval",onClick:s,children:h.jsx(Zd,{})})]}),loading:t,error:r,empty:h.jsxs(h.Fragment,{children:[h.jsx("p",{children:"No evals yet."}),h.jsx("p",{className:"trace-list-hint",children:"An eval runs a prompt over a dataset and checks each result. Start one with “+” above, or with “New eval…” on a dataset."})]}),items:e,columns:c,itemKey:lA,itemName:d=>d.name,selectedKey:n,onSelect:i,defaultSort:{key:"updatedAt",dir:"desc"}})}const uA=new Set,cA=(e,t)=>JSON.stringify([e,t]);function LF(e,t){uA.add(cA(e,t))}function _ve(e,t){return uA.delete(cA(e,t))}function hA(e,t){if(t)return e.find(r=>r.globalId!==void 0&&r.globalId===t.id)??e.find(r=>r.id===t.id&&(t.providerId===void 0||r.providerId===t.providerId))}function IF({prompts:e,datasets:t,seed:r,onClose:n,onCreated:i}){const s=T=>`${T.providerId}:${T.id}`,a=r.dataset&&t.find(T=>T.providerId===r.dataset.providerId&&T.id===r.dataset.id),o=hA(e,r.prompt??(a==null?void 0:a.prompt)),[l,u]=w.useState(o&&a?`${o.name} on ${a.name}`:""),[c,d]=w.useState(o?s(o):""),[m,f]=w.useState(a?Za(a):""),[p,g]=w.useState(!1),[y,b]=w.useState(null),v=e.find(T=>s(T)===c),x=t.find(T=>Za(T)===m),E=async T=>{if(T.preventDefault(),!(!(v!=null&&v.providerId)||!x||!l.trim())){g(!0),b(null);try{const C=await YH({name:l.trim(),prompt:{id:v.globalId??v.id,providerId:v.providerId},dataset:{providerId:x.providerId,id:x.id},inputs:{functionInputs:{},executeInputs:{}},checks:[]});LF(C.providerId,C.id),i(C)}catch(C){b(C.message),g(!1)}}};return h.jsx("div",{className:"dialog-backdrop",onMouseDown:T=>T.target===T.currentTarget&&n(),children:h.jsxs("form",{className:"dialog",onSubmit:E,children:[h.jsxs("div",{className:"dialog-header",children:[h.jsx("h3",{children:"New eval"}),h.jsx("button",{type:"button",className:"dialog-close",onClick:n,"aria-label":"Close",children:"×"})]}),h.jsxs("div",{className:"dialog-body",children:[y&&h.jsx("div",{className:"dialog-error",children:y}),h.jsxs("div",{className:"dialog-field",children:[h.jsx("label",{htmlFor:"new-eval-name",children:"Name"}),h.jsx("input",{id:"new-eval-name",autoFocus:!0,"data-1p-ignore":!0,value:l,placeholder:"Plans the right tasks",onChange:T=>u(T.target.value)})]}),h.jsxs("div",{className:"dialog-field",children:[h.jsx("label",{htmlFor:"new-eval-prompt",children:"Prompt"}),h.jsxs("select",{id:"new-eval-prompt",value:c,onChange:T=>d(T.target.value),children:[h.jsx("option",{value:"",children:"Choose a prompt…"}),e.map(T=>h.jsx("option",{value:s(T),children:T.name},s(T)))]})]}),h.jsxs("div",{className:"dialog-field",children:[h.jsx("label",{htmlFor:"new-eval-dataset",children:"Dataset"}),h.jsxs("select",{id:"new-eval-dataset",value:m,onChange:T=>f(T.target.value),children:[h.jsx("option",{value:"",children:"Choose a dataset…"}),t.map(T=>h.jsx("option",{value:Za(T),children:T.name},Za(T)))]})]}),h.jsxs("div",{className:"dialog-actions",children:[h.jsx("button",{type:"button",className:"dialog-btn-cancel",onClick:n,children:"Cancel"}),h.jsx("button",{type:"submit",className:"dialog-btn-create",disabled:p||!v||!x||!l.trim(),children:"Create"})]})]})]})})}function dA(e){return/^[A-Za-z_][A-Za-z0-9_-]*$/.test(e)}function DF(e){return Object.fromEntries(Object.entries(e).map(([t,{receipt:r,...n}])=>[t,n]))}function vve(e){return e.kind==="primitive"&&(e.value===void 0||e.value===null||e.value==="")?null:{kind:"value",value:e}}function yve(e){if(e.kind!=="primitive")return;const t=e.base??e.syntax;return Gz(t)?t:void 0}const OF=4;function wl(e,t="",r=0){const n=[];for(const i of e){const s=t?`${t}.${i.name}`:i.name;n.push({path:s,name:i.name,type:i.type}),i.type.kind==="object"&&r+1<OF&&n.push(...wl(i.type.properties,s,r+1))}return n}function Fh(e,t){return e==="execute"?`execute:${t}`:t}function u_(e){return"instance"in e?`resource '${e.instance}'`:Fh(e.half,e.path)}const MF=new Set(Object.keys({value:!0,object:!0,input:!0,instance:!0,dataset:!0}));function c_(e){switch(e.kind){case"instance":return[e.name];case"object":return Object.values(e.properties).flatMap(c_);default:return[]}}function fA(e,t){const r=[],n=(i,s)=>{switch(i.kind){case"object":for(const[a,o]of Object.entries(i.properties))n(o,"instance"in s?s:{half:s.half,path:`${s.path}.${a}`});break;case"input":r.push({at:s,target:{half:i.half,path:i.path}});break;case"instance":r.push({at:s,target:{instance:i.name}});break;default:MF.has(i.kind)||t==null||t.push({at:s,kind:i.kind});break}};for(const[i,s]of Object.entries(e.functionInputs))n(s,{half:"function",path:i});for(const[i,s]of Object.entries(e.executeInputs))n(s,{half:"execute",path:i});for(const[i,s]of Object.entries(e.resources??{}))for(const a of Object.values(s.args??{}))n(a,{instance:i});return r}function jF(e,t){return"instance"in e||"instance"in t?"instance"in e&&"instance"in t&&e.instance===t.instance:e.half===t.half&&mA(e.path,t.path)}function mA(e,t){return e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`)}function pA(e){const t=fA(e),r=t.map(a=>t.filter(o=>jF(o.at,a.target))),n=new Map,i=[],s=a=>{const o=n.get(a);if(o!=="done"){if(o==="visiting")return[...i.slice(i.indexOf(a)),a].map(u=>u_(u.at));n.set(a,"visiting"),i.push(a);for(const l of r[t.indexOf(a)]){const u=s(l);if(u)return u}i.pop(),n.set(a,"done")}};for(const a of t){const o=s(a);if(o)return o}}function gA(e){return{function:new Set(wl(e.functionParameters).map(t=>t.path)),execute:new Set(wl(e.executeParameters??[]).map(t=>t.path))}}function BF(e,t,r={}){const n=gA(t),i=e.resources??{},s=[],a=[],o=fA(e,a),l=c=>"instance"in c?u_(c):`'${u_(c)}'`;for(const{at:c,kind:d}of a)s.push(d==="resource"?`${l(c)} uses an inline 'resource' input, which is no longer supported: declare the resource in 'resources' and reference it with { kind: "instance" }`:`${l(c)} has an input of unknown kind '${d}'`);for(const c of o){const d=l(c.at);"instance"in c.target?!r.undeclaredInstances&&!Object.hasOwn(i,c.target.instance)&&s.push(`${d} names resource '${c.target.instance}', which this run doesn't declare`):n[c.target.half].has(c.target.path)||s.push(`${d} names input '${Fh(c.target.half,c.target.path)}', which the prompt doesn't have`)}const u=pA(e);return u&&s.push(`Input cycle: ${u.join(" → ")}`),s}function $m(e){return Array.isArray(e)?{kind:"array",elements:e.map($m)}:e!==null&&typeof e=="object"?{kind:"object",properties:Object.fromEntries(Object.entries(e).map(([t,r])=>[t,$m(r)]))}:{kind:"primitive",value:e}}function Hm(e){return!e||e.kind==="value"&&e.value.kind==="primitive"&&e.value.value===void 0}function h_(e){const t=e;return t&&typeof t.name=="string"&&t.type?t:void 0}function PF(e,t){const r=[];for(const n of e.functionParameters){const i=t.functionInputs[n.name];Hm(i)||r.push({def:n,input:i})}for(const n of e.executeParameters??[]){const i=t.executeInputs[n.name];Hm(i)||r.push({def:n,input:i})}return r}function bA(e,t){var n;const r=[];if(e.functionInputs||e.executeInputs){(e.functionInputs??[]).forEach((s,a)=>{var u;const o=s,l=h_((u=e.parameterDefinitions)==null?void 0:u[a])??(t==null?void 0:t.functionParameters[a]);l&&!Hm(o)&&r.push({def:l,input:o})});const i=(e.executeParameterDefinitions??[]).map(h_).filter(s=>!!s);for(const[s,a]of Object.entries(e.executeInputs??{})){const o=a,l=i.find(u=>u.name===s)??((n=t==null?void 0:t.executeParameters)==null?void 0:n.find(u=>u.name===s));l&&!Hm(o)&&r.push({def:l,input:o})}return r}return e.functionParameters&&t&&e.functionParameters.forEach((i,s)=>{const a=t.functionParameters[s];!a||i===void 0||a.type.kind==="opaque"||r.push({def:a,input:{kind:"value",value:$m(i)}})}),r}function xve(e,t){return e.fields.flatMap(r=>{const n=t.cells[r.id];return n?[{def:r.def,input:n}]:[]})}function _A(e){return!!(e&&(e.functionInputs||e.executeInputs||e.functionParameters))}function vA(e,t){const r=new Map(t.map(a=>[Ss(a.def),a])),n={},i=[];let s=0;for(const{def:a,input:o}of e){const l=r.get(Ss(a));if(!l){i.push({name:a.name,reason:"no-match"});continue}l.id in n||(n[l.id]=o,s++)}return{cells:n,matched:s,skipped:i}}function yA(e){return e&&Object.keys(e).length>0?DF(e):void 0}function zF(e,t,r){var u,c;const n=new Set((((u=t.inputSources)==null?void 0:u.resources)??[]).map(d=>d.uri)),i={},s=new Set;for(const[d,m]of Object.entries(yA(r)??{}))n.has(m.uri)?i[d]=m:s.add(d);for(let d=s.size>0;d;){d=!1;for(const[m,f]of Object.entries(i))Object.values(f.args??{}).some(g=>c_(g).some(y=>s.has(y)))&&(delete i[m],s.add(m),d=!0)}const a={},o={},l=[];for(const{def:d,input:m}of e){const f=Ss(d),p=t.functionParameters.find(y=>Ss(y)===f),g=(c=t.executeParameters)==null?void 0:c.find(y=>Ss(y)===f);if(!p&&!g){l.push({name:d.name,reason:"no-match"});continue}if(c_(m).some(y=>s.has(y))){l.push({name:d.name,reason:"resource-out-of-scope"});continue}p&&(a[p.name]=m),g&&(o[g.name]=m)}return{functionInputs:a,executeInputs:o,...Object.keys(i).length>0&&{resources:i},skipped:l}}function $F(e){return k4(e.map(t=>t.def))}function HF(e,t,r){const n=[...e.parameterDefinitions??[],...e.executeParameterDefinitions??[]].map(h_).filter(i=>!!i);return n.length>0?k4(n):t?C9(t):$F(r)}function FF(e,t){return vA(e,t).matched}function Sve(e,t){const r=new Set([...t.functionParameters,...t.executeParameters??[]].map(Ss));return e.filter(n=>!n.added&&!r.has(Ss(n.def)))}function wve(e,t){const r=new Map([...t.functionParameters,...t.executeParameters??[]].map(s=>[Ss(s),s]));let n=!1;const i=e.map(s=>{const a=!s.added&&r.get(Ss(s.def));if(!a)return s;const o=k9(a);return JSON.stringify(o)===JSON.stringify(s.def)?s:(n=!0,{...s,def:o})});return n?i:e}let UF=0;function VF(e,t,r,n){const{functionInputs:i,executeInputs:s,skipped:a,...o}=zF(e,t,n);return{functionInputs:i,executeInputs:s,...o.resources&&{resources:o.resources},from:r,skipped:a,nonce:Date.now()*1e3+UF++%1e3}}function xA(e){return e.kind!=="raw"&&!(e.kind==="functionCall"&&!e.binding)}function cl(e,t){return e&&(t===void 0||xA(t))}function zi(e){return e.replace(/^var_/,"").slice(0,7)}function SA(e,t,r){function n(){try{const a=localStorage.getItem(e);return a===null?t:r(a)}catch{return t}}let i=n();const s=new Set;return{get:()=>i,set(a){i=a;try{localStorage.setItem(e,String(a))}catch{}for(const o of s)o()},subscribe(a){return s.add(a),()=>s.delete(a)}}}const wA=SA("evalution.autosave",!1,e=>e==="true");function q4(e){return[w.useSyncExternalStore(e.subscribe,e.get),e.set]}function qF(){const e=new Set;return{get size(){return e.size},track(t){e.add(t);const r=()=>e.delete(t);return t.then(r,r),t},async settled(){for(;e.size>0;)await Promise.allSettled(e)}}}const GF="l.evalut.io",e0=e=>`https://${GF}/s/${e}`,WF=e0("setup"),YF=e0("config"),KF=e0("prompts"),EA=e0("agent-request"),XF=e0("sdk-request"),QF=`<!-- SPDX-License-Identifier: AGPL-3.0-only -->
53
+ `);return}j&&(d.current=!1)},z=B=>{X$.has(B.key)||b()},I=()=>{p(null),d.current=!1,a==null||a()};return h.jsxs(h.Fragment,{children:[h.jsx("div",{ref:u,contentEditable:!s,suppressContentEditableWarning:!0,className:n,"data-placeholder":i,onInput:C,onPaste:L,onKeyDown:A,onKeyUp:z,onMouseUp:b,onBlur:I,style:n?void 0:{...Mn,minHeight:24,outline:"none",whiteSpace:"pre-wrap",wordBreak:"break-word"}}),f&&h.jsx("ul",{className:"te-suggest",style:{position:"fixed",left:f.left,top:f.top+4,zIndex:9999,margin:0,padding:4,listStyle:"none",minWidth:160,maxHeight:240,overflowY:"auto",background:qe.menuBg,color:qe.menuColor,border:`1px solid ${qe.border}`,borderRadius:Es.md,boxShadow:"0 4px 16px rgba(0,0,0,0.16)",fontSize:13},children:f.items.map((B,j)=>{var Y;const G=B.kind!=="identifier",W=B.kind==="identifier"?B.node.name+((Y=B.node.children)!=null&&Y.length?" ›":""):B.kind==="insert-token"?"Insert token":"Insert as literal text";return h.jsx("li",{className:"te-suggest-item"+(j===f.index?" active":"")+(G?" te-suggest-action":""),onMouseDown:V=>{var P;V.preventDefault();const X=!(B.kind==="identifier"&&((P=B.node.children)!=null&&P.length));T(B,f.fragmentLen,X)},onMouseEnter:()=>p(V=>V&&{...V,index:j}),style:{padding:"4px 8px",borderRadius:4,cursor:"pointer",fontStyle:G?"italic":"normal",borderTop:G&&j>0&&f.items[j-1].kind==="identifier"?`1px solid ${qe.border}`:void 0,background:j===f.index?qe.menuActiveBg:"transparent"},children:W},B.kind==="identifier"?B.node.name:B.kind)})})]})}function Z$({elements:e,rest:t,value:r,onChange:n,plugins:i,path:s=[],disabled:a}){const o=H9(r),l=(r==null?void 0:r.kind)==="tuple"?"tuple":"array",u=m=>n({kind:l,elements:m}),c=(m,f)=>{const p=[...o];for(let g=p.length;g<m;g++){const y=e[g]??t;p[g]=y?nn(y.type):{kind:"primitive",value:null}}p[m]=f,u(p)},d=t?Math.max(o.length,e.length):e.length;return h.jsxs("div",{style:bc,children:[Array.from({length:d},(m,f)=>{const p=e[f]??t,g=f<e.length?p.name||`[${f}]`:`[${f}]`,y=!!t&&F9(f,e.length);return h.jsx(i1,{name:g,type:p.type,optional:p.optional,description:p.description,actions:y&&h.jsx("button",{type:"button",onClick:()=>u(o.filter((b,v)=>v!==f)),"aria-label":`Remove item ${f+1}`,disabled:a,style:I4,children:"×"}),children:h.jsx(Ir,{propDef:{...p,name:g},value:o[f],onChange:b=>c(f,b),plugins:i,path:[...s,String(f)],disabled:a})},f)}),t&&h.jsx("button",{type:"button",onClick:()=>c(d,t.defaultValue??nn(t.type)),disabled:a,style:zm,children:"+ Add item"})]})}function J$({propDef:e,unionInfo:t,value:r,onChange:n,plugins:i,className:s,path:a,disabled:o}){const{members:l}=t,[u,c]=w.useState(null),d=u??h$(t,r),m=l[d],[f,p]=w.useState({}),g=y=>{const b=Number(y);p(x=>({...x,[d]:r})),c(b);const v=l[b];n(v.kind==="constant"?{kind:"primitive",value:v.value}:f[b]??{kind:"primitive",value:void 0})};return h.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.jsx("select",{value:String(d),onChange:y=>g(y.target.value),className:s,style:s?void 0:Mn,disabled:o,children:l.map((y,b)=>h.jsx("option",{value:String(b),children:y.syntax},b))}),m.kind!=="constant"&&h.jsx(Ir,{propDef:{...e,type:m},value:r,onChange:n,plugins:i,className:s,path:a,disabled:o})]})}const W9=w.createContext(void 0);function Y9(){return w.useContext(W9)}function ku(e){if(e.kind==="primitive")return e.base??e.syntax}const eH=[];function Ir(e){const t=Y9(),r=e.propDef.interpolatables,n=r??t,i=n===r?e.propDef:{...e.propDef,interpolatables:n},s=h.jsx(rH,{...e,propDef:i});return r&&r!==t?h.jsx(W9.Provider,{value:r,children:s}):s}function tH(e){switch(e.kind){case"object":case"record":case"array":case"tuple":case"opaque":return!0;case"union":return!e.types.every(t=>t.kind==="constant")&&!e.types.some(t=>ku(t)==="string");case"primitive":return!["string","number","boolean"].includes(ku(e)??"")&&e.syntax!=="Date";default:return!1}}function rH(e){var o;const{value:t,onChange:r,propDef:n,disabled:i}=e,s=n.interpolatables;if((t==null?void 0:t.kind)==="reference")return h.jsx($$,{path:t.path,interpolatables:s??[],onChange:r,onClear:()=>r(n.defaultValue??nn(n.type)),disabled:i});const a=h.jsx(nH,{...e});return!(s!=null&&s.length)||(o=n.catalogs)!=null&&o.length||!tH(n.type)?a:h.jsxs("div",{style:{display:"flex",gap:6,alignItems:"flex-start"},children:[h.jsx("div",{style:{flex:1,minWidth:0},children:a}),h.jsx(q9,{interpolatables:s,onChange:r,disabled:i})]})}function nH({value:e,onChange:t,propDef:r,plugins:n,className:i,path:s=eH,disabled:a}){var d,m;const{type:o}=r;if(n){for(const f of n)if(f.match(o,s)){const p=f.component;return h.jsx(p,{propDef:r,value:e,onChange:t,path:s,disabled:a})}}if((d=r.catalogs)!=null&&d.length)return h.jsx(sH,{propDef:r,value:e,onChange:t,plugins:n,className:i,path:s,disabled:a});if((e==null?void 0:e.kind)==="template"||ku(o)==="string"&&((m=r.interpolatables)!=null&&m.length))return h.jsx(D4,{propDef:r,value:e,onChange:t,className:i,disabled:a});if(o.kind==="function")return h.jsx(D$,{propDef:r,value:e,onChange:t,disabled:a});if(o.kind==="array")return h.jsx(S$,{element:o.element,value:e,onChange:t,plugins:n,path:s,disabled:a});if(o.kind==="tuple")return h.jsx(Z$,{elements:o.elements,rest:o.rest,value:e,onChange:t,plugins:n,path:s,disabled:a});if(o.kind==="record")return h.jsx(V9,{value:o.value,current:e,onChange:t,plugins:n,path:s,disabled:a});const l=g$(o);if(l)return h.jsx(k$,{propDef:r,unionInfo:l,value:e,onChange:t,className:i,disabled:a});const u=B9(o);if(u)return h.jsx(I$,{discriminatedUnionInfo:u,value:e,onChange:t,plugins:n,path:s,disabled:a});if(o.kind==="union"&&o.types.every(f=>f.kind==="constant"))return h.jsx(A$,{propDef:r,value:e,onChange:t,className:i,disabled:a});const c=A4(o);return c?h.jsx(J$,{propDef:r,unionInfo:c,value:e,onChange:t,plugins:n,className:i,path:s,disabled:a}):o.syntax==="Date"?h.jsx(N$,{propDef:r,value:e,onChange:t,disabled:a}):ku(o)==="string"?h.jsx(H$,{propDef:r,value:e,onChange:t,className:i,disabled:a}):ku(o)==="number"?h.jsx(M$,{propDef:r,value:e,onChange:t,className:i,disabled:a}):ku(o)==="boolean"?h.jsx(E$,{propDef:r,value:e,onChange:t,className:i,disabled:a}):o.kind==="opaque"?h.jsx(B$,{propDef:r,value:e,onChange:t,className:i,path:s}):o.kind==="object"&&o.properties.length>0?h.jsx(j$,{properties:o.properties,value:e,onChange:t,plugins:n,path:s,disabled:a}):h.jsx(O$,{propDef:r,value:e,onChange:t,className:i,disabled:a})}function K9({value:e,def:t,onChange:r,plugins:n,path:i=[],disabled:s}){const a=t.type.kind==="function"?t.type.parameters:[];return h.jsxs("div",{"data-proppy-editor":"function-call",children:[h.jsxs("div",{style:{fontFamily:xo,fontSize:11,color:qe.textSecondary},children:[e.callee,"("]}),h.jsx("div",{style:bc,children:a.map((o,l)=>h.jsx(i1,{name:o.name,type:o.type,optional:o.optional,description:o.description,children:h.jsx(Ir,{propDef:o,value:e.args[l],onChange:u=>r(m$(e,a,l,u)),plugins:n,path:[...i,o.name],disabled:s})},l))}),h.jsx("div",{style:{fontFamily:xo,fontSize:11,color:qe.textSecondary},children:")"})]})}function Ax(e){return e.kind==="primitive"&&typeof e.value=="string"&&e.displayValue===void 0?e.value:ma(e)}function iH(e){return e.some(t=>t.literal||t.groups.some(r=>{var n;return(n=r.presets)==null?void 0:n.length}))}function sH(e){const t=e.propDef.catalogs??[];return iH(t)?h.jsx(oH,{...e,catalogs:t}):h.jsx(aH,{...e,catalogs:t})}function aH({propDef:e,catalogs:t,value:r,onChange:n,plugins:i,className:s,path:a,disabled:o}){const l={...e,catalogs:void 0},u=t.flatMap(m=>m.groups.flatMap(f=>f.factory?[{group:f,factory:f.factory}]:[])),c=R4(t,r),d=h.jsxs("select",{value:"",disabled:o,"aria-label":"Kind",className:s?"proppy-catalog-kind":void 0,style:s?void 0:{...Mn,width:"auto",alignSelf:"flex-start"},onChange:m=>{const f=u.find(p=>p.factory.def.name===m.target.value);f&&n(n1(f.factory))},children:[h.jsx("option",{value:"",children:"Choose…"}),u.map(({group:m,factory:f})=>h.jsx("option",{value:f.def.name,children:m.label},f.def.name))]});return c&&(r==null?void 0:r.kind)==="functionCall"?h.jsx("div",{"data-proppy-editor":"catalog",className:s,style:{display:"flex",flexDirection:"column",gap:4},children:h.jsx(K9,{value:r,def:c.factory.def,onChange:n,plugins:i,path:a,disabled:o})}):r?h.jsx(Ir,{propDef:l,value:r,onChange:n,plugins:i,path:a,disabled:o}):h.jsx("div",{"data-proppy-editor":"catalog",className:s,children:d})}function oH({propDef:e,catalogs:t,value:r,onChange:n,plugins:i,className:s,path:a,disabled:o}){var X;const l=u$(),[u,c]=w.useState(!1),[d,m]=w.useState(()=>kx(t,e,r)),f=w.useRef(null),p=w.useRef(null),[g,y]=w.useState(null),b=!s,v=P=>b?void 0:`proppy-catalog-${P}`,x=r?JSON.stringify(r):"";w.useEffect(()=>{u||m(kx(t,e,r))},[x]),w.useEffect(()=>{if(!u)return;const P=()=>{var R;const re=(R=p.current)==null?void 0:R.getBoundingClientRect();re&&y({left:re.left,top:re.bottom+2,minWidth:re.width})};return P(),window.addEventListener("resize",P),window.addEventListener("scroll",P,!0),()=>{window.removeEventListener("resize",P),window.removeEventListener("scroll",P,!0)}},[u]),w.useEffect(()=>{if(!u)return;const P=R=>{var de;(de=f.current)!=null&&de.contains(R.target)||c(!1)},re=R=>{R.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",P),document.addEventListener("keydown",re),()=>{document.removeEventListener("mousedown",P),document.removeEventListener("keydown",re)}},[u]);const E=a_(t,r),T=E?void 0:R4(t,r),C=E!==void 0?t[E.catalogIndex].groups[E.groupIndex].icon:T!==void 0?t[T.catalogIndex].groups[T.groupIndex].icon:void 0,L=r?ma(r):void 0,A=!r&&e.defaultValue?e.defaultValue:void 0,z=A&&(((X=a_(t,A))==null?void 0:X.preset.label)??Ax(A)),I=(E==null?void 0:E.preset.label)??(r&&Ax(r))??z,B=!r&&!A,j=(P,re=!0)=>{n(P),re&&c(!1)},G=t[Math.min(d,t.length-1)],W=j9(G,e),Y=W&&r&&!E&&!T&&Pm(W.type,r)?r:void 0,V=P=>b?P:void 0;return h.jsxs("div",{ref:f,"data-proppy-editor":"catalog",className:s,style:{position:"relative"},children:[h.jsxs("button",{ref:p,type:"button",className:v("trigger"),disabled:o,"aria-haspopup":"listbox","aria-expanded":u,title:L,onClick:()=>c(P=>!P),style:V({...Mn,display:"flex",alignItems:"center",gap:6,textAlign:"left",cursor:o?"default":"pointer"}),children:[l==null?void 0:l(C,18),h.jsxs("span",{className:v("label")&&`${v("label")}${B?" placeholder":""}`,style:V({flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:B?qe.textMuted:void 0}),children:[I??"Select…",A&&h.jsxs("span",{className:v("label-annotation"),style:V({color:qe.textMuted}),children:[" ","(default)"]})]}),E&&L&&h.jsx("span",{className:v("source"),style:V({fontSize:11,color:qe.textMuted}),children:L}),h.jsx("span",{"aria-hidden":!0,className:v("chevron"),style:V({color:qe.textMuted}),children:"▾"})]}),u&&h.jsxs("div",{className:v("menu"),role:"listbox",style:{position:"fixed",left:(g==null?void 0:g.left)??0,top:(g==null?void 0:g.top)??0,minWidth:g==null?void 0:g.minWidth,zIndex:9999,visibility:g?void 0:"hidden",...V({maxHeight:420,overflowY:"auto",padding:4,background:qe.menuBg,color:qe.menuColor,border:`1px solid ${qe.border}`,borderRadius:Es.md,boxShadow:"0 4px 16px rgba(0,0,0,0.16)",fontSize:12.5})},children:[t.length>1&&h.jsx("div",{className:v("modes"),style:V({display:"flex",gap:4,padding:4}),children:t.map((P,re)=>h.jsx("button",{type:"button",className:v("mode")&&`${v("mode")}${re===d?" active":""}`,"aria-pressed":re===d,title:P.description,onClick:()=>m(re),style:V({...L4,flex:1,background:re===d?qe.menuActiveBg:qe.buttonBg}),children:P.label},re))}),G.groups.map((P,re)=>{const R=P.presets??[];return R.length===0&&!P.factory?null:h.jsxs("div",{className:v("group"),style:V({padding:"4px 0"}),children:[h.jsxs("div",{className:v("group-header"),style:V({display:"flex",alignItems:"center",gap:6,padding:"2px 8px",fontSize:11,fontWeight:600,color:qe.textSecondary}),children:[l==null?void 0:l(P.icon,14),h.jsx("span",{children:P.label})]}),R.map((de,Te)=>{const H=(E==null?void 0:E.catalogIndex)===d&&E.groupIndex===re&&E.preset===de;return h.jsxs("button",{type:"button",role:"option","aria-selected":H,className:v("option")&&`${v("option")}${H?" selected":""}`,onClick:()=>j(de.value),style:V({display:"flex",width:"100%",gap:8,padding:"4px 8px",border:"none",borderRadius:4,background:H?qe.menuActiveBg:"transparent",color:"inherit",font:"inherit",textAlign:"left",cursor:"pointer"}),children:[h.jsx("span",{"aria-hidden":!0,className:v("check"),style:V({width:12}),children:H?"✓":""}),h.jsx("span",{className:v("option-label"),style:V({flex:1}),children:de.label}),h.jsx("span",{className:v("option-source"),style:V({fontSize:11,color:qe.textMuted}),children:ma(de.value)})]},Te)}),P.factory&&h.jsxs("button",{type:"button",className:v("custom"),onClick:()=>j(n1(P.factory)),style:V({display:"block",width:"100%",padding:"4px 8px 4px 28px",border:"none",borderRadius:4,background:(T==null?void 0:T.catalogIndex)===d&&T.groupIndex===re?qe.menuActiveBg:"transparent",color:qe.textSecondary,font:"inherit",fontStyle:"italic",textAlign:"left",cursor:"pointer"}),children:["Custom ",P.factory.def.name,"(…)"]})]},re)}),W&&h.jsx("div",{className:v("literal"),style:V({padding:8,borderTop:`1px solid ${qe.border}`}),children:h.jsx(Ir,{propDef:W,value:Y,onChange:P=>j(P,!1),plugins:i,path:a,disabled:o})})]}),T&&(r==null?void 0:r.kind)==="functionCall"&&h.jsx("div",{style:V({marginTop:4}),className:v("call"),children:h.jsx(K9,{value:r,def:T.factory.def,onChange:n,plugins:i,path:a,disabled:o})})]})}function lH(e,t,r){if(r===e.has(t))return e;const n=new Set(e);return r?n.add(t):n.delete(t),n}function X9(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Hf(e,t){return e||(console.warn(`[evalution] Missing providerId for ${t}; prompt linking may not work.`),"")}function Q9(e){if(e.kind==="primitive")return e.syntax==="number"?{kind:"primitive",value:0}:e.syntax==="boolean"?{kind:"primitive",value:!1}:{kind:"primitive",value:""};if(e.kind==="array")return{kind:"array",elements:[]};if(e.kind==="union"){const t=A4(e);if(t)return Q9(t.members[t.defaultIndex]);const r=e.types.find(n=>n.kind==="constant");if(r&&r.kind==="constant")return{kind:"primitive",value:r.value}}return{kind:"primitive",value:void 0}}function vc(e,t,r){return`/api/prompts/${e.providerId}/${X9(e.id)}/${t}${Z9(r)}`}function Z9(e){return e!=null&&e.variation?`?variation=${encodeURIComponent(e.variation)}`:e!=null&&e.version?`?version=${encodeURIComponent(e.version)}`:""}async function ze(e){if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t.error??`Request failed: ${e.status}`)}}async function uH(){const e=await fetch("/api/setup-tasks");return await ze(e),e.json()}async function cH(e,t){const r=await fetch(`/api/setup-tasks/${encodeURIComponent(e)}/steps/${encodeURIComponent(t)}/execute`,{method:"POST"});return await ze(r),r.json()}async function hH(){const e=await fetch("/api/sync",{method:"POST"});await ze(e)}async function dH(){const e=await fetch("/api/sync");return await ze(e),(await e.json()).adopting}async function fH(){const e=await fetch("/api/agents");return await ze(e),e.json()}async function mH(e,t){const r=await fetch(`/api/agents/${encodeURIComponent(e)}/command`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({context:t})});return await ze(r),(await r.json()).command}async function pH(){const e=await fetch("/api/providers");return await ze(e),e.json()}async function Nx(e,t){const r=await fetch(`/api/providers/${e}/add-prompt`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});await ze(r);const n=await r.json();return n&&"id"in n&&C4("add",e,n.id),n}async function gH(){const e=await fetch("/api/prompts");return await ze(e),e.json()}async function bH(e,t){const r=await fetch(`/api/providers/${e}/model-definition?style=${t}`);return await ze(r),r.json()}async function _H(e){const t=await fetch(`/api/providers/${e}/model-parameters`);return await ze(t),t.json()}async function vH(e,t){const r=e.id.lastIndexOf("#"),n=r>=0?`${e.id.slice(0,r+1)}${t}`:e.id;e.providerId&&C4("change",e.providerId,n);const i=await fetch(vc(e,"rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({newName:t})});return await ze(i),i.json()}async function yH(e,t,r){const n=await fetch(`/api/prompts/${e}/${X9(t)}${Z9(r)}`);return await ze(n),n.json()}async function xH(e,t,r){e.providerId&&C4("change",e.providerId,e.id);const n=await fetch(vc(e,"update",r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return await ze(n),n.json()}async function SH(e,t,r){const n=await fetch(vc(e,"execute",r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return await ze(n),n.json()}async function wH(e,{limit:t,before:r}={}){const n=new URLSearchParams;t&&n.set("limit",String(t)),r&&n.set("before",r);const i=n.size?`?${n}`:"",s=await fetch(vc(e,"versions")+i);return await ze(s),s.json()}async function EH(e){const t=await fetch(vc(e,"variations"));return await ze(t),t.json()}function O4(e,t,r=""){return`/api/variations/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r}`}async function Xd(e,t,r,n){const i=await fetch(O4(e,t,`/${r}`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n??{})});return await ze(i),i.status===204?void 0:i.json()}function kH(e,t){return Xd(e,t,"save")}function CH(e,t){return Xd(e,t,"discard")}function TH(e,t,r={}){return Xd(e,t,"open-on-head",r)}async function AH(e,t,r={}){const n=await fetch(vc(e,"open-on-head",{version:t}),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return await ze(n),n.json()}function NH(e,t,r){return Xd(e,t,"resolve",{choices:r})}async function RH(e,t,r){const n=await fetch(O4(e,t,"/name"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r})});return await ze(n),n.json()}function LH(e,t,r,n){return Xd(e,t,"rename",{from:r,to:n})}async function IH(e,t){for(const r of t.names){const n=await fetch(O4(e,t.id,`/name/${encodeURIComponent(r)}`),{method:"DELETE"});await ze(n)}}async function DH(e){if(e.length===0)return{};const t=await fetch(`/api/variations?ids=${e.map(encodeURIComponent).join(",")}`);return await ze(t),t.json()}function J9(e){const t=new URLSearchParams(Zz(e));return t.size>0?`?${t}`:""}async function OH(e){const t=await fetch(`/api/traces/groups${J9(e)}`);return await ze(t),t.json()}async function MH(e){const t=await fetch(`/api/traces${J9(e??{})}`);return await ze(t),t.json()}async function jH(e,t){const r=await fetch(`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:"DELETE"});await ze(r)}async function BH(e,t,{signal:r,timeoutMs:n=1e4,intervalMs:i=150}={}){const s=`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,a=Date.now()+n;for(;;){const o=await fetch(s,{signal:r});if(o.ok)return o.json();(o.status!==404||Date.now()>=a)&&await ze(o),await PH(i,r)}}function PH(e,t){return new Promise((r,n)=>{if(t!=null&&t.aborted){n(new DOMException("Aborted","AbortError"));return}const i=setTimeout(r,e);t==null||t.addEventListener("abort",()=>{clearTimeout(i),n(new DOMException("Aborted","AbortError"))},{once:!0})})}function zH(e,t,r){const n=`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}/events`,i=new EventSource(n);return i.onmessage=s=>{try{const a=JSON.parse(s.data);a!=null&&a.type&&a.type!=="connected"&&r(a)}catch{}},()=>i.close()}function M4(e,t,r=""){return`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}/annotations${r}`}async function $H(e,t){const r=await fetch(M4(e,t));return await ze(r),r.json()}async function HH(e,t,r){const n=await fetch(M4(e,t),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return await ze(n),n.json()}async function FH(e,t,r){const n=await fetch(M4(e,t,`/${encodeURIComponent(r)}`),{method:"DELETE"});await ze(n)}function Qn(e,t,r=""){const n=`/api/datasets/${encodeURIComponent(e)}`;return t?`${n}/${encodeURIComponent(t)}${r}`:n}async function eA(){const e=await fetch("/api/datasets");return await ze(e),e.json()}async function U_e(e,t){const r=await fetch(Qn(e,t));return await ze(r),r.json()}async function V_e(e,t,r,n){const i=await fetch(Qn(e,t,`/rows?offset=${r}&limit=${n}`));return await ze(i),i.json()}async function tA(e,t){const r=await fetch(Qn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return await ze(r),r.json()}async function UH(e){const[t]=await rA();if(!t)throw new Error("No dataset provider is configured");const r=await tA(t.id,{name:e,fields:[]});return{providerId:t.id,id:r.id,name:r.name,rowCount:0,fields:r.fields,updatedAt:r.updatedAt}}async function q_e(e,t,r){const n=await fetch(Qn(e,t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r})});return await ze(n),n.json()}async function G_e(e,t){const r=await fetch(Qn(e,t),{method:"DELETE"});await ze(r)}async function VH(e,t,r){const n=await fetch(Qn(e,t,"/rows"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rows:r})});return await ze(n),n.json()}async function W_e(e,t,r){const n=await fetch(Qn(e,t,"/rows"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:r})});await ze(n)}async function Y_e(e,t,r){const n=await fetch(Qn(e,t,"/fields"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return await ze(n),n.json()}async function K_e(e,t,r,n){const i=await fetch(Qn(e,t,`/fields/${encodeURIComponent(r)}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n})});return await ze(i),i.json()}async function X_e(e,t,r){const n=await fetch(Qn(e,t,`/fields/${encodeURIComponent(r)}`),{method:"DELETE"});await ze(n)}async function Q_e(e,t,r){const n=await fetch(Qn(e,t,"/paths"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r})});return await ze(n),n.json()}async function Z_e(e,t,r,n){const i=await fetch(Qn(e,t,"/columns"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({columns:r,rowLabel:n})});return await ze(i),i.json()}async function J_e(e,t,r){const n=await fetch(Qn(e,t,`/rows/${encodeURIComponent(r)}`),{method:"DELETE"});await ze(n)}async function eve(e,t,r){const n=await fetch(Qn(e,t,"/rows"),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({rowIds:r})});await ze(n);const{deleted:i}=await n.json();return i}async function rA(){const e=await fetch("/api/dataset-providers");return await ze(e),e.json()}function yc(e,t,r=""){const n=`/api/evals/${encodeURIComponent(e)}`;return t?`${n}/${encodeURIComponent(t)}${r}`:n}function j4(e,t,r=""){return`/api/eval-runs/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r}`}class qH extends Error{constructor(r,n){super(r);J(this,"problems");this.problems=n}}async function GH(){const e=await fetch("/api/eval-providers");return await ze(e),e.json()}async function WH(){const e=await fetch("/api/evals");return await ze(e),e.json()}async function tve(e,t){const r=await fetch(yc(e,t));return await ze(r),r.json()}async function YH(e,t){var i;const r=t??((i=(await GH())[0])==null?void 0:i.id);if(!r)throw new Error("No eval provider is configured");const n=await fetch(yc(r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return await ze(n),{...await n.json(),providerId:r}}async function rve(e,t,r){const n=await fetch(yc(e,t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return await ze(n),n.json()}async function nve(e,t){const r=await fetch(yc(e,t),{method:"DELETE"});await ze(r)}async function ive(e,t,r={}){const n=await fetch(yc(e,t,"/runs"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok){const i=await n.json().catch(()=>({}));throw Array.isArray(i.problems)?new qH(i.error,i.problems):new Error(i.error??`Request failed: ${n.status}`)}return n.json()}async function sve(e,t){const r=await fetch(yc(e,t,"/runs"));return await ze(r),r.json()}async function ave(e,t){const r=await fetch(j4(e,t));return await ze(r),r.json()}async function ove(e,t){const r=await fetch(j4(e,t,"/cancel"),{method:"POST"});await ze(r)}async function lve(e,t){const r=await fetch(j4(e,t),{method:"DELETE"});await ze(r)}async function uve(){const e=await fetch("/api/checks");return await ze(e),e.json()}async function KH(e,t){const r=await fetch(`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}/check-results`);return await ze(r),r.json()}async function XH(e,t){const r=await fetch(`/api/traces/${encodeURIComponent(e)}/${encodeURIComponent(t)}/eval-run`);return await ze(r),await r.json()??void 0}async function cve(e){const t=await fetch(`/api/prompt-providers/${encodeURIComponent(e)}/head`);return await ze(t),t.json()}async function QH(){const e=await fetch("/api/views");return await ze(e),e.json()}function ZH({onClose:e,onCreated:t}){const[r,n]=w.useState({type:"loading"}),[i,s]=w.useState({}),[a,o]=w.useState(null);w.useEffect(()=>{pH().then(c=>{const d=c.filter(m=>m.hasAddPrompt);d.length===0?o("No providers support adding prompts"):d.length===1?l(d[0].id):n({type:"pick-provider",providers:d})}).catch(c=>o(c.message))},[]);async function l(c){n({type:"loading"}),o(null);try{const d=await Nx(c,{});if("fields"in d){const m={};for(const f of d.fields)f.defaultValue&&(m[f.name]=f.defaultValue);s(m),n({type:"form",providerId:c,context:d})}else t(d)}catch(d){o(d.message)}}async function u(c){if(c.preventDefault(),r.type!=="form")return;o(null),n({type:"submitting"});const d={};for(const[m,f]of Object.entries(i))f&&(d[m]=f);if(d.directory!==void 0&&d.fileName){const m=d.directory==="."?"":d.directory+"/";d.metadata={relativeFilePath:m+d.fileName},delete d.directory,delete d.fileName}try{const m=await Nx(r.providerId,d);if("fields"in m){const f={};for(const p of m.fields)p.defaultValue&&(f[p.name]=p.defaultValue);s({...f,...i}),n({type:"form",providerId:r.providerId,context:m})}else t(m)}catch(m){o(m.message),n({type:"form",providerId:r.providerId,context:r.context})}}return h.jsx("div",{className:"dialog-backdrop",onClick:e,children:h.jsxs("div",{className:"dialog",onClick:c=>c.stopPropagation(),children:[h.jsxs("div",{className:"dialog-header",children:[h.jsx("h3",{children:"New Prompt"}),h.jsx("button",{type:"button",className:"dialog-close",onClick:e,children:"×"})]}),h.jsxs("div",{className:"dialog-body",children:[a&&h.jsx("div",{className:"dialog-error",children:a}),r.type==="loading"&&h.jsx("div",{className:"dialog-status",children:"Loading..."}),r.type==="submitting"&&h.jsx("div",{className:"dialog-status",children:"Creating..."}),r.type==="pick-provider"&&h.jsx("div",{className:"dialog-providers",children:r.providers.map(c=>h.jsxs("button",{type:"button",className:"dialog-provider-btn",onClick:()=>l(c.id),children:[c.icon&&h.jsx("span",{className:"dialog-provider-icon",dangerouslySetInnerHTML:{__html:c.icon}}),h.jsxs("div",{children:[h.jsx("div",{className:"dialog-provider-name",children:c.displayName??c.id}),c.description&&h.jsx("div",{className:"dialog-provider-desc",children:c.description})]})]},c.id))}),r.type==="form"&&h.jsxs("form",{onSubmit:u,children:[r.context.fields.map(c=>{var d;return h.jsxs("div",{className:"dialog-field",children:[h.jsx("label",{htmlFor:`field-${c.name}`,children:c.label}),c.type==="select"?h.jsx("select",{id:`field-${c.name}`,value:i[c.name]??"",onChange:m=>s(f=>({...f,[c.name]:m.target.value})),required:c.required,children:(d=c.options)==null?void 0:d.map(m=>h.jsx("option",{value:m.value,children:m.label},m.value))}):h.jsx("input",{id:`field-${c.name}`,type:"text",value:i[c.name]??"",onChange:m=>s(f=>({...f,[c.name]:m.target.value})),placeholder:c.placeholder,required:c.required})]},c.name)}),h.jsxs("div",{className:"dialog-actions",children:[h.jsx("button",{type:"button",className:"dialog-btn-cancel",onClick:e,children:"Cancel"}),h.jsx("button",{type:"submit",className:"dialog-btn-create",children:"Create"})]})]})]})]})})}function JH(e,t){return e.key===t?{key:t,dir:e.dir==="asc"?"desc":"asc"}:{key:t,dir:"desc"}}function Rx(e,t,r){const n=r==="asc"?1:-1;return[...e].sort((i,s)=>{const a=t(i),o=t(s);return a===void 0?o===void 0?0:1:o===void 0?-1:typeof a=="string"||typeof o=="string"?String(a).localeCompare(String(o))*n:(a-o)*n})}const eF=120,tF=24,rF=340,nF=480;function B4(e){const t=e.reduce((r,n)=>r+n,eF)+tF;return Math.min(nF,Math.max(rF,t))}function Lx(e){const t=e&&typeof e=="object"?e:{},r=i=>typeof i=="number"&&Number.isFinite(i)&&i>0?i:void 0,n=Array.isArray(t.widths)?t.widths:[];return{current:t.current===1?1:0,widths:[r(n[0]),r(n[1])]}}function iF(e,t,r){const n=e.current===0?1:0,i=[...e.widths];return i[e.current]=t,{memory:{current:n,widths:i},width:i[n]??r}}function Qd(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),h.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),h.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),h.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]})}function nA(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"4",y1:"6",x2:"14",y2:"6"}),h.jsx("line",{x1:"8",y1:"12",x2:"20",y2:"12"}),h.jsx("line",{x1:"6",y1:"18",x2:"16",y2:"18"})]})}function s1(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"12",cy:"13",r:"8"}),h.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),h.jsx("line",{x1:"12",y1:"13",x2:"15",y2:"15"}),h.jsx("line",{x1:"9",y1:"2",x2:"15",y2:"2"}),h.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"5"})]})}function a1(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),h.jsx("polyline",{points:"14 2 14 8 20 8"}),h.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),h.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),h.jsx("line",{x1:"10",y1:"9",x2:"8",y2:"9"})]})}function Zd(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),h.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function hve(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),h.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function Ix(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("polyline",{points:"3 6 5 6 21 6"}),h.jsx("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),h.jsx("path",{d:"M10 11v6M14 11v6"}),h.jsx("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})}function sF(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"4",y1:"6",x2:"14",y2:"6"}),h.jsx("line",{x1:"8",y1:"12",x2:"20",y2:"12"}),h.jsx("line",{x1:"6",y1:"18",x2:"16",y2:"18"})]})}function aF(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("polyline",{points:"8.5 0.5 12 3.5 15.5 0.5"}),h.jsx("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),h.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"}),h.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18"}),h.jsx("polyline",{points:"8.5 23.5 12 20.5 15.5 23.5"})]})}function oF(){return h.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:h.jsx("path",{d:"M14.7 6.3a4 4 0 0 0-5.6 4.6L2 18l4 4 7.1-7.1a4 4 0 0 0 4.6-5.6l-2.8 2.8-3-3Z"})})}function P4({open:e}){return h.jsx("svg",{className:`chevron-icon${e?" chevron-icon-open":""}`,width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:h.jsx("polyline",{points:"9 18 15 12 9 6"})})}function lF(){return h.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:h.jsx("polyline",{points:"6 9 12 15 18 9"})})}function uF(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M2.5 5.5A1.5 1.5 0 0 1 4 4h10a1.5 1.5 0 0 1 1.5 1.5v6A1.5 1.5 0 0 1 14 13H8.5l-3 3v-3H4a1.5 1.5 0 0 1-1.5-1.5Z"}),h.jsx("path",{d:"M19.5 9.5H20A1.5 1.5 0 0 1 21.5 11v4A1.5 1.5 0 0 1 20 16.5v3l-3-3h-3"})]})}function z4(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("polyline",{points:"7 3 3 7 7 11"}),h.jsx("line",{x1:"3",y1:"7",x2:"17",y2:"7"}),h.jsx("polyline",{points:"17 13 21 17 17 21"}),h.jsx("line",{x1:"21",y1:"17",x2:"7",y2:"17"})]})}function $4(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"12",cy:"12",r:"9"}),h.jsx("path",{d:"M15 9.5c0-1.1-1.34-2-3-2s-3 .9-3 2 1.34 2 3 2 3 .9 3 2-1.34 2-3 2-3-.9-3-2"}),h.jsx("line",{x1:"12",y1:"6",x2:"12",y2:"18"})]})}function H4(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1.5"}),h.jsx("line",{x1:"9",y1:"2",x2:"9",y2:"6"}),h.jsx("line",{x1:"15",y1:"2",x2:"15",y2:"6"}),h.jsx("line",{x1:"9",y1:"18",x2:"9",y2:"22"}),h.jsx("line",{x1:"15",y1:"18",x2:"15",y2:"22"}),h.jsx("line",{x1:"2",y1:"9",x2:"6",y2:"9"}),h.jsx("line",{x1:"2",y1:"15",x2:"6",y2:"15"}),h.jsx("line",{x1:"18",y1:"9",x2:"22",y2:"9"}),h.jsx("line",{x1:"18",y1:"15",x2:"22",y2:"15"})]})}function iA(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M3.5 17a9 9 0 1 1 17 0"}),h.jsx("line",{x1:"12",y1:"15",x2:"16.5",y2:"9"}),h.jsx("circle",{cx:"12",cy:"15",r:"1"})]})}function cF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M3 3h9l9 9-9 9-9-9V3z"}),h.jsx("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"})]})}function hF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M5 21V4"}),h.jsx("path",{d:"M5 4h12l-2.5 4 2.5 4H5"})]})}function dF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("polygon",{points:"8 2 16 2 22 8 22 16 16 22 8 22 2 16 2 8"}),h.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function fF(){return h.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:h.jsx("path",{d:"M7 18a4.5 4.5 0 0 1-.6-8.96A6 6 0 0 1 18 10a4 4 0 0 1-.5 8Z"})})}function mF(){return h.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[h.jsx("circle",{cx:"5",cy:"12",r:"2.2"}),h.jsx("circle",{cx:"12",cy:"12",r:"2.2"}),h.jsx("circle",{cx:"19",cy:"12",r:"2.2"})]})}function Jd({size:e=11}){return h.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("ellipse",{cx:"12",cy:"5",rx:"8",ry:"3"}),h.jsx("path",{d:"M4 5v14c0 1.66 3.58 3 8 3s8-1.34 8-3V5"}),h.jsx("path",{d:"M4 12c0 1.66 3.58 3 8 3s8-1.34 8-3"})]})}function pF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"12",cy:"12",r:"4"}),h.jsx("line",{x1:"2",y1:"12",x2:"8",y2:"12"}),h.jsx("line",{x1:"16",y1:"12",x2:"22",y2:"12"})]})}function gF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"12",cy:"12",r:"9"}),h.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),h.jsx("path",{d:"M12 3a14 14 0 0 1 0 18a14 14 0 0 1 0-18"})]})}function bF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("circle",{cx:"6",cy:"6",r:"2.5"}),h.jsx("circle",{cx:"6",cy:"18",r:"2.5"}),h.jsx("circle",{cx:"18",cy:"8",r:"2.5"}),h.jsx("line",{x1:"6",y1:"8.5",x2:"6",y2:"15.5"}),h.jsx("path",{d:"M18 10.5c0 4-6 3.5-11 6"})]})}function o1({size:e=11}){return h.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"3"}),h.jsx("polyline",{points:"8 12.5 11 15.5 16.5 9"})]})}function _F(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),h.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),h.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function dve({filled:e=!1}){return h.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:e?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M3 3h9l9 9-9 9-9-9V3z"}),h.jsx("circle",{cx:"8",cy:"8",r:"1",fill:e?"var(--dropdown-bg, #fff)":"currentColor",stroke:"none"})]})}function fve(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),h.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function vF(){return h.jsxs("svg",{width:"10",height:"16",viewBox:"0 0 10 16",fill:"currentColor","aria-hidden":!0,children:[h.jsx("circle",{cx:"3",cy:"3",r:"1.3"}),h.jsx("circle",{cx:"7",cy:"3",r:"1.3"}),h.jsx("circle",{cx:"3",cy:"8",r:"1.3"}),h.jsx("circle",{cx:"7",cy:"8",r:"1.3"}),h.jsx("circle",{cx:"3",cy:"13",r:"1.3"}),h.jsx("circle",{cx:"7",cy:"13",r:"1.3"})]})}function Dx(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("path",{d:"M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71"}),h.jsx("path",{d:"M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71"})]})}function yF(){return h.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:h.jsx("polygon",{points:"22 3 2 3 10 12.5 10 19 14 21 14 12.5 22 3"})})}function xF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),h.jsx("line",{x1:"9",y1:"12",x2:"21",y2:"12"}),h.jsx("line",{x1:"9",y1:"18",x2:"21",y2:"18"})]})}function sA(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 11 11",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("circle",{cx:"4.5",cy:"4.5",r:"3"}),h.jsx("line",{x1:"7",y1:"7",x2:"9.5",y2:"9.5"})]})}function Ox({label:e,icon:t,sortKey:r,sort:n,onSort:i,className:s,width:a}){const o=n.key===r;return h.jsx("th",{className:s,style:a!==void 0?{width:a}:void 0,"aria-sort":o?n.dir==="asc"?"ascending":"descending":"none",children:h.jsxs("button",{type:"button",className:`trace-table-sort-btn${o?" trace-table-sort-btn-active":""}`,onClick:()=>i(r),title:`Sort by ${e}`,children:[t??e,h.jsx("span",{className:"trace-table-sort-arrow","aria-hidden":!0,children:o?n.dir==="asc"?"▲":"▼":""})]})})}function Mx(e,t,r){let n=e;return t.key===r&&(n+=` ${e}-selected`),t.count!==void 0&&(n+=` ${e}-group`),t.placeholder&&(n+=` ${e}-loading`),t.child&&(n+=` ${e}-child`),n}function jx({row:e,itemName:t,itemMarker:r}){if(e.placeholder)return h.jsx("span",{className:"trace-list-name",children:"Loading…"});const n=e.count!==void 0;return h.jsxs(h.Fragment,{children:[n&&h.jsx("span",{className:"trace-list-chevron",children:h.jsx(P4,{open:!!e.open})}),r==null?void 0:r(e.item),h.jsx("span",{className:"trace-list-name",children:t(e.item)}),n&&h.jsx("span",{className:"trace-list-group-count",children:e.count})]})}function SF(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[h.jsx("line",{x1:"2",y1:"7",x2:"18",y2:"7"}),h.jsx("polyline",{points:"14 3 18 7 14 11"}),h.jsx("line",{x1:"22",y1:"17",x2:"6",y2:"17"}),h.jsx("polyline",{points:"10 13 6 17 10 21"})]})}function wF(e){try{return Lx(JSON.parse(localStorage.getItem(e)??"null"))}catch{return Lx(null)}}function F4({sidebarWidth:e,onResizeSidebar:t,tableWidth:r,storageKey:n}){const i=`table-mode:${n}`,[s,a]=w.useState(()=>wF(i)),o=()=>{const l=iF(s,e,r);a(l.memory);try{localStorage.setItem(i,JSON.stringify(l.memory))}catch{}t(l.width)};return h.jsx("button",{type:"button",className:"tree-toolbar-btn",title:"Toggle table view",onClick:o,children:h.jsx(SF,{})})}function U4({title:e,headerActions:t,toolbar:r,loading:n,error:i,empty:s,items:a,columns:o,cardColumnCount:l=3,itemKey:u,itemName:c,itemTitle:d=c,itemMarker:m,itemChildren:f,itemGroupCount:p,onExpandGroup:g,selectedKey:y,onSelect:b,defaultSort:v}){const[x,E]=w.useState(v),[T,C]=w.useState(new Set),L=P=>C(re=>{const R=new Set(re);return R.delete(P)||R.add(P),R}),[A,z]=w.useState(y);if(y!==A){z(y);const P=a.find(R=>{var de;return(de=f==null?void 0:f(R))==null?void 0:de.some(Te=>u(Te)===y)}),re=P&&u(P);re!==void 0&&!T.has(re)&&C(R=>new Set(R).add(re))}w.useEffect(()=>{if(g)for(const P of a)T.has(u(P))&&(p==null?void 0:p(P))!==void 0&&!(f!=null&&f(P))&&g(P)});const I=h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"section-panel-header",children:[h.jsx("span",{children:e}),t&&h.jsx("div",{className:"section-panel-header-actions",children:t})]}),r]});if(n||i||a.length===0)return h.jsxs(h.Fragment,{children:[I,h.jsx("div",{className:"section-panel-body",children:n?h.jsx("div",{className:"tree-status",children:"Loading..."}):i?h.jsxs("div",{className:"tree-status tree-error",children:["Error: ",i]}):h.jsx("div",{className:"tree-empty-state",children:s})})]});const B=o.find(P=>P.key===x.key),j=P=>x.key==="name"?Rx(P,c,x.dir):B!=null&&B.sortValue?Rx(P,B.sortValue,x.dir):P,G=j(a).flatMap(P=>{const re=u(P),R=f==null?void 0:f(P),de=(p==null?void 0:p(P))??(R==null?void 0:R.length);if(de===void 0)return[{item:P,key:re}];const Te=T.has(re),H={item:P,key:re,count:de,children:R,open:Te};return Te?R?[H,...j(R).map(Oe=>({item:Oe,key:u(Oe),child:!0}))]:[H,{item:P,key:`${re}:loading`,child:!0,placeholder:!0}]:[H]}),W=P=>{P.placeholder||(P.count!==void 0?L(P.key):b(P.item))},Y=P=>P.placeholder?void 0:d(P.item),V=o.slice(0,l),X=P=>E(re=>JH(re,P));return h.jsxs(h.Fragment,{children:[I,h.jsxs("div",{className:"section-panel-body trace-list",children:[h.jsx("div",{className:"trace-list-cards",children:G.map(P=>{const{item:re}=P;return h.jsxs("div",{className:Mx("trace-list-row",P,y),onClick:()=>W(P),title:Y(P),...P.count!==void 0&&{role:"button","aria-expanded":P.open},children:[h.jsx("div",{className:"trace-list-row-top",children:h.jsx(jx,{row:P,itemName:c,itemMarker:m})}),h.jsx("div",{className:"trace-list-row-meta",children:(P.placeholder?[]:V).map(R=>{const de=(R.card??R.cell)(re);return de===null?null:h.jsxs("span",{className:"trace-list-meta-item",children:[R.icon,de]},R.key)})})]},P.key)})}),h.jsxs("table",{className:"trace-table",children:[h.jsx("thead",{children:h.jsxs("tr",{children:[h.jsx(Ox,{label:"Name",sortKey:"name",sort:x,onSort:X,className:"trace-table-name-th"}),o.map(P=>{const re=`trace-table-th trace-table-col-${P.key}`;return P.sortValue?h.jsx(Ox,{label:P.label,icon:P.icon,sortKey:P.key,sort:x,onSort:X,className:re,width:P.width},P.key):h.jsx("th",{className:re,style:{width:P.width},title:P.label,children:P.icon},P.key)})]})}),h.jsx("tbody",{children:G.map(P=>{const{item:re}=P;return h.jsxs("tr",{className:Mx("trace-table-row",P,y),onClick:()=>W(P),title:Y(P),"aria-expanded":P.count!==void 0?P.open:void 0,children:[h.jsx("td",{children:h.jsx("div",{className:"trace-table-name-cell",children:h.jsx(jx,{row:P,itemName:c,itemMarker:m})})}),o.map(R=>h.jsx("td",{className:`trace-table-col-${R.key}`,children:!P.placeholder&&R.cell(re)},R.key))]},P.key)})})]})]})]})}function V4({label:e=!0}){return h.jsxs("span",{className:"syncing-indicator",role:"status","aria-label":e?void 0:"Syncing",title:"Starting to sync with Evalution Cloud. Changes made now are saved once it's done — keep evalution running until then.",children:[h.jsx("span",{className:"syncing-indicator-ring","aria-hidden":"true"}),e&&"Syncing"]})}function Sl(e){return e<1?"<1ms":e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(2)}s`}function o_(e){return new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}function ks(e){return new Date(e).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:"numeric",minute:"2-digit"})}function EF(e){return e.status??(e.endTime===void 0?"running":void 0)}function kF(e){switch(e){case"ok":return"✓";case"error":return"✕";case"running":return"●";default:return"?"}}function Bu(e){return e.toLocaleString()}function fo(e){return e<1e-4?"<$0.0001":e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}const Oo=8;function Fi({open:e,onClose:t,matchTriggerWidth:r=!0,extraContains:n}){const i=w.useRef(null),s=w.useRef(null),[a,o]=w.useState({position:"fixed"}),l=w.useCallback(()=>{var f;if(!i.current)return;const u=i.current.getBoundingClientRect();let c=u.left,d=u.bottom+4;if(r){o({position:"fixed",top:d,left:c,width:u.width,zIndex:9999});return}const m=(f=s.current)==null?void 0:f.getBoundingClientRect();if(m&&(c+m.width>window.innerWidth-Oo&&(c=Math.max(Oo,u.right-m.width)),c=Math.min(c,window.innerWidth-Oo-m.width),c=Math.max(Oo,c),d+m.height>window.innerHeight-Oo)){const p=u.top-4-m.height;d=p>=Oo?p:Oo}o({position:"fixed",top:d,left:c,zIndex:9999})},[r]);return w.useLayoutEffect(()=>{if(!e)return;l();const u=m=>{var p,g;const f=m.target;(p=i.current)!=null&&p.contains(f)||(g=s.current)!=null&&g.contains(f)||n!=null&&n(f)||t()},c=m=>{m.key==="Escape"&&t()};document.addEventListener("pointerdown",u),document.addEventListener("keydown",c),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l);let d;return s.current&&typeof ResizeObserver<"u"&&(d=new ResizeObserver(l),d.observe(s.current)),()=>{d==null||d.disconnect(),document.removeEventListener("pointerdown",u),document.removeEventListener("keydown",c),window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[e,l]),{triggerRef:i,popoverRef:s,style:a}}function Za(e){return`${e.providerId}:${e.id}`}function CF({onCreated:e}){const[t,r]=w.useState(!1),[n,i]=w.useState(""),[s,a]=w.useState(!1),[o,l]=w.useState(null),u=w.useRef(!1),c=w.useCallback(()=>{r(!1),i("")},[]),d=w.useCallback(()=>{u.current||c()},[c]),m=()=>{l(null),r(!0)},{triggerRef:f,popoverRef:p,style:g}=Fi({open:t,onClose:d,matchTriggerWidth:!1}),y=async()=>{const b=n.trim();if(b){u.current=!0,a(!0);try{const v=await UH(b);c(),e(v)}catch(v){l(v.message)}finally{u.current=!1,a(!1)}}};return h.jsxs(h.Fragment,{children:[h.jsx("button",{ref:f,type:"button",className:`tree-toolbar-btn${t?" tree-toolbar-btn-active":""}`,title:"New dataset…","aria-label":"New dataset",onClick:()=>t?d():m(),children:h.jsx(Zd,{})}),t&&cn.createPortal(h.jsxs("div",{className:"add-to-dataset-menu",ref:p,style:g,children:[h.jsxs("form",{className:"add-to-dataset-new",onSubmit:b=>{b.preventDefault(),y()},children:[h.jsx("input",{autoFocus:!0,className:"add-to-dataset-name",placeholder:"Dataset name","aria-label":"New dataset name",value:n,onChange:b=>i(b.target.value),disabled:s}),h.jsx("button",{type:"submit",className:"add-to-dataset-create",disabled:s||!n.trim(),children:"Create"})]}),o&&h.jsx("div",{className:"add-to-dataset-error",children:o})]}),document.body)]})}function TF({datasets:e,loading:t,error:r,selectedKey:n,onSelect:i,promptName:s,sidebarWidth:a,onResizeSidebar:o,syncing:l}){const u=d=>d.prompt&&s(d.prompt),c=[{key:"rowCount",label:"Rows",icon:h.jsx(Jd,{}),width:48,cell:d=>d.error?h.jsx("span",{className:"dataset-list-error",children:"error"}):d.rowCount,card:d=>d.error?h.jsx("span",{className:"dataset-list-error",children:"can't be opened"}):`${d.rowCount} row${d.rowCount===1?"":"s"}`,sortValue:d=>d.error?void 0:d.rowCount},{key:"prompt",label:"Prompt",icon:h.jsx(a1,{}),width:110,cell:d=>u(d)||"—",card:d=>u(d)||null,sortValue:d=>u(d)||void 0},{key:"updatedAt",label:"Updated",icon:h.jsx(Qd,{}),width:100,cell:d=>d.updatedAt>0?ks(d.updatedAt):"—",card:d=>d.updatedAt>0?ks(d.updatedAt):null,sortValue:d=>d.updatedAt}];return h.jsx(U4,{title:"Datasets",headerActions:h.jsxs(h.Fragment,{children:[h.jsx(F4,{sidebarWidth:a,onResizeSidebar:o,tableWidth:B4(c.map(d=>d.width)),storageKey:"datasets"}),h.jsx(CF,{onCreated:i})]}),loading:t,error:r,empty:h.jsxs(h.Fragment,{children:[h.jsx("p",{children:"No datasets yet."}),h.jsx("p",{className:"trace-list-hint",children:"Start one by hand with “+” above, or use “Add to dataset” in a prompt's execute panel or on a trace."})]}),items:e,columns:c,itemKey:Za,itemName:d=>d.name,itemTitle:d=>d.error??d.name,itemMarker:d=>l!=null&&l.has(Za(d))?h.jsx(V4,{label:!1}):null,selectedKey:n,onSelect:i,defaultSort:{key:"updatedAt",dir:"desc"}})}function aA(){return{pass:0,fail:0,error:0,skipped:0,scored:0}}function Bx(e,t){if(e.length===0)return;const r=[...e].sort((i,s)=>i-s),n=Math.max(1,Math.ceil(t*r.length));return r[n-1]}function l_(e){const t=e.pass+e.fail;return t===0?void 0:e.pass/t}function mve(e,t,r){const n=e.rows.filter(o=>o.armId===t),i=e.checks.filter(o=>o.armId===t),s=n.flatMap(o=>o.costUsd===void 0?[]:[o.costUsd]),a=n.flatMap(o=>o.durationMs===void 0?[]:[o.durationMs]);return{armId:t,checks:r.map(o=>{const l=aA(),u=[];for(const c of i)c.checkId===o&&(l[c.outcome]++,c.score!==void 0&&u.push(c.score));return{checkId:o,counts:l,...l_(l)!==void 0&&{passRate:l_(l)},...u.length>0&&{meanScore:u.reduce((c,d)=>c+d,0)/u.length}}}),rowErrors:n.filter(o=>o.status!=="ok").length,...s.length>0&&{totalCost:s.reduce((o,l)=>o+l,0)},...a.length>0&&{p50Duration:Bx(a,.5),p95Duration:Bx(a,.95)}}}function oA(e,t,r){return`${e}:${t}:${r}`}function AF(e){return new Map(e.map(t=>[oA(t.armId,t.rowId,t.checkId),t]))}function pve(e){const t=new Map;for(const r of e.rows){let n=t.get(r.rowId);n||(n={rowId:r.rowId,rowIndex:r.rowIndex,arms:new Map},t.set(r.rowId,n)),n.arms.set(r.armId,r)}return[...t.values()].sort((r,n)=>r.rowIndex-n.rowIndex)}const NF={pass:"✓",fail:"✗",error:"!",skipped:"–",scored:""},Px=new Set(["pass"]);function gve(e,t){var s,a;const r=new Map(t.arms.map(o=>[o.label,o.id])),n=AF(t.results.checks),i=[];for(const o of e.results.checks){const l=(s=e.arms.find(d=>d.id===o.armId))==null?void 0:s.label,u=l&&r.get(l);if(!u)continue;const c=(a=n.get(oA(u,o.rowId,o.checkId)))==null?void 0:a.outcome;c===void 0||c===o.outcome||i.push({rowId:o.rowId,armId:o.armId,checkId:o.checkId,before:c,after:o.outcome,regressed:Px.has(c)&&!Px.has(o.outcome)})}return i.sort((o,l)=>Number(l.regressed)-Number(o.regressed))}function zx(e){return e===void 0?"—":`${Math.round(e*100)}%`}function bve(e,t){const r=`the run from ${ks(e)}`;return t?`Cancel and delete ${r}, with its results?`:`Delete ${r} and its results?`}function _ve(e){return structuredClone({name:`${e.name} copy`,prompt:e.prompt,dataset:e.dataset,inputs:e.inputs,checks:e.checks})}function lA(e){return`${e.providerId}:${e.id}`}function $g(e){return e.lastRun&&l_(e.lastRun.counts)}function RF({evals:e,loading:t,error:r,selectedKey:n,onSelect:i,onNew:s,promptName:a,sidebarWidth:o,onResizeSidebar:l,syncing:u=!1}){const c=[{key:"passRate",label:"Last run",icon:h.jsx(o1,{}),width:64,cell:d=>{var m;return((m=d.lastRun)==null?void 0:m.status)==="running"?`${d.lastRun.done}/${d.lastRun.total}`:zx($g(d))},card:d=>d.lastRun?d.lastRun.status==="running"?`running ${d.lastRun.done}/${d.lastRun.total}`:`${zx($g(d))} passing`:"never run",sortValue:$g},{key:"prompt",label:"Prompt",icon:h.jsx(a1,{}),width:110,cell:d=>a(d.prompt)||"—",card:d=>a(d.prompt)||null,sortValue:d=>a(d.prompt)||void 0},{key:"updatedAt",label:"Updated",icon:h.jsx(Qd,{}),width:100,cell:d=>ks(d.updatedAt),card:d=>ks(d.updatedAt),sortValue:d=>d.updatedAt}];return h.jsx(U4,{title:"Evals",headerActions:h.jsxs(h.Fragment,{children:[u&&h.jsx(V4,{}),h.jsx(F4,{sidebarWidth:o,onResizeSidebar:l,tableWidth:B4(c.map(d=>d.width)),storageKey:"evals"}),h.jsx("button",{type:"button",className:"tree-toolbar-btn",title:"New eval…","aria-label":"New eval",onClick:s,children:h.jsx(Zd,{})})]}),loading:t,error:r,empty:h.jsxs(h.Fragment,{children:[h.jsx("p",{children:"No evals yet."}),h.jsx("p",{className:"trace-list-hint",children:"An eval runs a prompt over a dataset and checks each result. Start one with “+” above, or with “New eval…” on a dataset."})]}),items:e,columns:c,itemKey:lA,itemName:d=>d.name,selectedKey:n,onSelect:i,defaultSort:{key:"updatedAt",dir:"desc"}})}const uA=new Set,cA=(e,t)=>JSON.stringify([e,t]);function LF(e,t){uA.add(cA(e,t))}function vve(e,t){return uA.delete(cA(e,t))}function hA(e,t){if(t)return e.find(r=>r.globalId!==void 0&&r.globalId===t.id)??e.find(r=>r.id===t.id&&(t.providerId===void 0||r.providerId===t.providerId))}function IF({prompts:e,datasets:t,seed:r,onClose:n,onCreated:i}){const s=T=>`${T.providerId}:${T.id}`,a=r.dataset&&t.find(T=>T.providerId===r.dataset.providerId&&T.id===r.dataset.id),o=hA(e,r.prompt??(a==null?void 0:a.prompt)),[l,u]=w.useState(o&&a?`${o.name} on ${a.name}`:""),[c,d]=w.useState(o?s(o):""),[m,f]=w.useState(a?Za(a):""),[p,g]=w.useState(!1),[y,b]=w.useState(null),v=e.find(T=>s(T)===c),x=t.find(T=>Za(T)===m),E=async T=>{if(T.preventDefault(),!(!(v!=null&&v.providerId)||!x||!l.trim())){g(!0),b(null);try{const C=await YH({name:l.trim(),prompt:{id:v.globalId??v.id,providerId:v.providerId},dataset:{providerId:x.providerId,id:x.id},inputs:{functionInputs:{},executeInputs:{}},checks:[]});LF(C.providerId,C.id),i(C)}catch(C){b(C.message),g(!1)}}};return h.jsx("div",{className:"dialog-backdrop",onMouseDown:T=>T.target===T.currentTarget&&n(),children:h.jsxs("form",{className:"dialog",onSubmit:E,children:[h.jsxs("div",{className:"dialog-header",children:[h.jsx("h3",{children:"New eval"}),h.jsx("button",{type:"button",className:"dialog-close",onClick:n,"aria-label":"Close",children:"×"})]}),h.jsxs("div",{className:"dialog-body",children:[y&&h.jsx("div",{className:"dialog-error",children:y}),h.jsxs("div",{className:"dialog-field",children:[h.jsx("label",{htmlFor:"new-eval-name",children:"Name"}),h.jsx("input",{id:"new-eval-name",autoFocus:!0,"data-1p-ignore":!0,value:l,placeholder:"Plans the right tasks",onChange:T=>u(T.target.value)})]}),h.jsxs("div",{className:"dialog-field",children:[h.jsx("label",{htmlFor:"new-eval-prompt",children:"Prompt"}),h.jsxs("select",{id:"new-eval-prompt",value:c,onChange:T=>d(T.target.value),children:[h.jsx("option",{value:"",children:"Choose a prompt…"}),e.map(T=>h.jsx("option",{value:s(T),children:T.name},s(T)))]})]}),h.jsxs("div",{className:"dialog-field",children:[h.jsx("label",{htmlFor:"new-eval-dataset",children:"Dataset"}),h.jsxs("select",{id:"new-eval-dataset",value:m,onChange:T=>f(T.target.value),children:[h.jsx("option",{value:"",children:"Choose a dataset…"}),t.map(T=>h.jsx("option",{value:Za(T),children:T.name},Za(T)))]})]}),h.jsxs("div",{className:"dialog-actions",children:[h.jsx("button",{type:"button",className:"dialog-btn-cancel",onClick:n,children:"Cancel"}),h.jsx("button",{type:"submit",className:"dialog-btn-create",disabled:p||!v||!x||!l.trim(),children:"Create"})]})]})]})})}function dA(e){return/^[A-Za-z_][A-Za-z0-9_-]*$/.test(e)}function DF(e){return Object.fromEntries(Object.entries(e).map(([t,{receipt:r,...n}])=>[t,n]))}function yve(e){return e.kind==="primitive"&&(e.value===void 0||e.value===null||e.value==="")?null:{kind:"value",value:e}}function xve(e){if(e.kind!=="primitive")return;const t=e.base??e.syntax;return Gz(t)?t:void 0}const OF=4;function wl(e,t="",r=0){const n=[];for(const i of e){const s=t?`${t}.${i.name}`:i.name;n.push({path:s,name:i.name,type:i.type}),i.type.kind==="object"&&r+1<OF&&n.push(...wl(i.type.properties,s,r+1))}return n}function Fh(e,t){return e==="execute"?`execute:${t}`:t}function u_(e){return"instance"in e?`resource '${e.instance}'`:Fh(e.half,e.path)}const MF=new Set(Object.keys({value:!0,object:!0,input:!0,instance:!0,dataset:!0}));function c_(e){switch(e.kind){case"instance":return[e.name];case"object":return Object.values(e.properties).flatMap(c_);default:return[]}}function fA(e,t){const r=[],n=(i,s)=>{switch(i.kind){case"object":for(const[a,o]of Object.entries(i.properties))n(o,"instance"in s?s:{half:s.half,path:`${s.path}.${a}`});break;case"input":r.push({at:s,target:{half:i.half,path:i.path}});break;case"instance":r.push({at:s,target:{instance:i.name}});break;default:MF.has(i.kind)||t==null||t.push({at:s,kind:i.kind});break}};for(const[i,s]of Object.entries(e.functionInputs))n(s,{half:"function",path:i});for(const[i,s]of Object.entries(e.executeInputs))n(s,{half:"execute",path:i});for(const[i,s]of Object.entries(e.resources??{}))for(const a of Object.values(s.args??{}))n(a,{instance:i});return r}function jF(e,t){return"instance"in e||"instance"in t?"instance"in e&&"instance"in t&&e.instance===t.instance:e.half===t.half&&mA(e.path,t.path)}function mA(e,t){return e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`)}function pA(e){const t=fA(e),r=t.map(a=>t.filter(o=>jF(o.at,a.target))),n=new Map,i=[],s=a=>{const o=n.get(a);if(o!=="done"){if(o==="visiting")return[...i.slice(i.indexOf(a)),a].map(u=>u_(u.at));n.set(a,"visiting"),i.push(a);for(const l of r[t.indexOf(a)]){const u=s(l);if(u)return u}i.pop(),n.set(a,"done")}};for(const a of t){const o=s(a);if(o)return o}}function gA(e){return{function:new Set(wl(e.functionParameters).map(t=>t.path)),execute:new Set(wl(e.executeParameters??[]).map(t=>t.path))}}function BF(e,t,r={}){const n=gA(t),i=e.resources??{},s=[],a=[],o=fA(e,a),l=c=>"instance"in c?u_(c):`'${u_(c)}'`;for(const{at:c,kind:d}of a)s.push(d==="resource"?`${l(c)} uses an inline 'resource' input, which is no longer supported: declare the resource in 'resources' and reference it with { kind: "instance" }`:`${l(c)} has an input of unknown kind '${d}'`);for(const c of o){const d=l(c.at);"instance"in c.target?!r.undeclaredInstances&&!Object.hasOwn(i,c.target.instance)&&s.push(`${d} names resource '${c.target.instance}', which this run doesn't declare`):n[c.target.half].has(c.target.path)||s.push(`${d} names input '${Fh(c.target.half,c.target.path)}', which the prompt doesn't have`)}const u=pA(e);return u&&s.push(`Input cycle: ${u.join(" → ")}`),s}function $m(e){return Array.isArray(e)?{kind:"array",elements:e.map($m)}:e!==null&&typeof e=="object"?{kind:"object",properties:Object.fromEntries(Object.entries(e).map(([t,r])=>[t,$m(r)]))}:{kind:"primitive",value:e}}function Hm(e){return!e||e.kind==="value"&&e.value.kind==="primitive"&&e.value.value===void 0}function h_(e){const t=e;return t&&typeof t.name=="string"&&t.type?t:void 0}function PF(e,t){const r=[];for(const n of e.functionParameters){const i=t.functionInputs[n.name];Hm(i)||r.push({def:n,input:i})}for(const n of e.executeParameters??[]){const i=t.executeInputs[n.name];Hm(i)||r.push({def:n,input:i})}return r}function bA(e,t){var n;const r=[];if(e.functionInputs||e.executeInputs){(e.functionInputs??[]).forEach((s,a)=>{var u;const o=s,l=h_((u=e.parameterDefinitions)==null?void 0:u[a])??(t==null?void 0:t.functionParameters[a]);l&&!Hm(o)&&r.push({def:l,input:o})});const i=(e.executeParameterDefinitions??[]).map(h_).filter(s=>!!s);for(const[s,a]of Object.entries(e.executeInputs??{})){const o=a,l=i.find(u=>u.name===s)??((n=t==null?void 0:t.executeParameters)==null?void 0:n.find(u=>u.name===s));l&&!Hm(o)&&r.push({def:l,input:o})}return r}return e.functionParameters&&t&&e.functionParameters.forEach((i,s)=>{const a=t.functionParameters[s];!a||i===void 0||a.type.kind==="opaque"||r.push({def:a,input:{kind:"value",value:$m(i)}})}),r}function Sve(e,t){return e.fields.flatMap(r=>{const n=t.cells[r.id];return n?[{def:r.def,input:n}]:[]})}function _A(e){return!!(e&&(e.functionInputs||e.executeInputs||e.functionParameters))}function vA(e,t){const r=new Map(t.map(a=>[Ss(a.def),a])),n={},i=[];let s=0;for(const{def:a,input:o}of e){const l=r.get(Ss(a));if(!l){i.push({name:a.name,reason:"no-match"});continue}l.id in n||(n[l.id]=o,s++)}return{cells:n,matched:s,skipped:i}}function yA(e){return e&&Object.keys(e).length>0?DF(e):void 0}function zF(e,t,r){var u,c;const n=new Set((((u=t.inputSources)==null?void 0:u.resources)??[]).map(d=>d.uri)),i={},s=new Set;for(const[d,m]of Object.entries(yA(r)??{}))n.has(m.uri)?i[d]=m:s.add(d);for(let d=s.size>0;d;){d=!1;for(const[m,f]of Object.entries(i))Object.values(f.args??{}).some(g=>c_(g).some(y=>s.has(y)))&&(delete i[m],s.add(m),d=!0)}const a={},o={},l=[];for(const{def:d,input:m}of e){const f=Ss(d),p=t.functionParameters.find(y=>Ss(y)===f),g=(c=t.executeParameters)==null?void 0:c.find(y=>Ss(y)===f);if(!p&&!g){l.push({name:d.name,reason:"no-match"});continue}if(c_(m).some(y=>s.has(y))){l.push({name:d.name,reason:"resource-out-of-scope"});continue}p&&(a[p.name]=m),g&&(o[g.name]=m)}return{functionInputs:a,executeInputs:o,...Object.keys(i).length>0&&{resources:i},skipped:l}}function $F(e){return k4(e.map(t=>t.def))}function HF(e,t,r){const n=[...e.parameterDefinitions??[],...e.executeParameterDefinitions??[]].map(h_).filter(i=>!!i);return n.length>0?k4(n):t?C9(t):$F(r)}function FF(e,t){return vA(e,t).matched}function wve(e,t){const r=new Set([...t.functionParameters,...t.executeParameters??[]].map(Ss));return e.filter(n=>!n.added&&!r.has(Ss(n.def)))}function Eve(e,t){const r=new Map([...t.functionParameters,...t.executeParameters??[]].map(s=>[Ss(s),s]));let n=!1;const i=e.map(s=>{const a=!s.added&&r.get(Ss(s.def));if(!a)return s;const o=k9(a);return JSON.stringify(o)===JSON.stringify(s.def)?s:(n=!0,{...s,def:o})});return n?i:e}let UF=0;function VF(e,t,r,n){const{functionInputs:i,executeInputs:s,skipped:a,...o}=zF(e,t,n);return{functionInputs:i,executeInputs:s,...o.resources&&{resources:o.resources},from:r,skipped:a,nonce:Date.now()*1e3+UF++%1e3}}function xA(e){return e.kind!=="raw"&&!(e.kind==="functionCall"&&!e.binding)}function cl(e,t){return e&&(t===void 0||xA(t))}function zi(e){return e.replace(/^var_/,"").slice(0,7)}function SA(e,t,r){function n(){try{const a=localStorage.getItem(e);return a===null?t:r(a)}catch{return t}}let i=n();const s=new Set;return{get:()=>i,set(a){i=a;try{localStorage.setItem(e,String(a))}catch{}for(const o of s)o()},subscribe(a){return s.add(a),()=>s.delete(a)}}}const wA=SA("evalution.autosave",!1,e=>e==="true");function q4(e){return[w.useSyncExternalStore(e.subscribe,e.get),e.set]}function qF(){const e=new Set;return{get size(){return e.size},track(t){e.add(t);const r=()=>e.delete(t);return t.then(r,r),t},async settled(){for(;e.size>0;)await Promise.allSettled(e)}}}const GF="l.evalut.io",e0=e=>`https://${GF}/s/${e}`,WF=e0("setup"),YF=e0("config"),KF=e0("prompts"),EA=e0("agent-request"),XF=e0("sdk-request"),QF=`<!-- SPDX-License-Identifier: AGPL-3.0-only -->
54
54
  <!-- Copyright (c) 2026 Alexander Corrado -->
55
55
 
56
56
  <svg width="1em" height="1em" stroke-linejoin="round" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
@@ -81,7 +81,7 @@ Error generating stack: `+n.message+`
81
81
  <path class="vercel-triangle" d="M50 28 76 72 24 72Z"/>
82
82
  </svg>
83
83
  `;function H0({icon:e,size:t}){return h.jsx("span",{style:{display:"inline-flex",width:t,height:t,fontSize:t},dangerouslySetInnerHTML:{__html:e}})}function tU({provider:e,size:t}){const r=(e==null?void 0:e.charAt(0).toUpperCase())??"";return h.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",children:[h.jsx("circle",{cx:"12",cy:"12",r:"11",fill:"#888"}),h.jsx("text",{x:"12",y:"16.5",textAnchor:"middle",fill:"white",fontSize:"13",fontWeight:"600",fontFamily:"system-ui, sans-serif",children:r})]})}const rU={OpenAI:({size:e})=>h.jsx(H0,{icon:JF,size:e}),Anthropic:({size:e})=>h.jsx(H0,{icon:QF,size:e}),Google:({size:e})=>h.jsx(H0,{icon:ZF,size:e}),vercel:({size:e})=>h.jsx(H0,{icon:eU,size:e})};function Fm({provider:e,size:t=24}){const r=e?rU[e]:void 0;return r?h.jsx(r,{size:t}):h.jsx(tU,{provider:e,size:t})}function kA({agents:e,onAsk:t}){const[r,n]=w.useState(!1),i=()=>n(!1),{triggerRef:s,popoverRef:a,style:o}=Fi({open:r,onClose:i,matchTriggerWidth:!1});return e.length===0?null:h.jsxs(h.Fragment,{children:[h.jsxs("button",{type:"button",ref:s,className:"trace-view-prompt-btn ask-agent-btn",onClick:()=>n(l=>!l),"aria-haspopup":"menu","aria-expanded":r,title:"Open a coding agent in a terminal, told what you're viewing",children:[h.jsx(nU,{}),"Ask AI",h.jsx(lF,{})]}),r&&cn.createPortal(h.jsxs("div",{className:"trace-header-menu",ref:a,style:o,role:"menu",children:[h.jsx(CA,{agents:e,onAsk:l=>{i(),t(l)},labelPrefix:""}),h.jsx("hr",{className:"ask-agent-menu-divider"}),h.jsxs("a",{role:"menuitem",className:"trace-header-menu-item",href:EA,target:"_blank",rel:"noopener",onClick:i,children:[h.jsx("span",{className:"trace-header-menu-item-icon"}),h.jsx("span",{className:"trace-header-menu-item-label",children:"Other"})]})]}),document.body)]})}function CA({agents:e,onAsk:t,labelPrefix:r="Ask "}){return e.map(n=>h.jsxs("button",{type:"button",role:"menuitem",className:"trace-header-menu-item",disabled:!!n.disabledReason,title:n.disabledReason,onClick:()=>t(n),children:[h.jsx("span",{className:"trace-header-menu-item-icon",children:h.jsx(Fm,{provider:n.icon,size:14})}),h.jsxs("span",{className:"trace-header-menu-item-label",children:[r,n.label]}),n.disabledReason&&h.jsx("span",{className:"ask-agent-item-status",children:"Not found"})]},n.id))}function nU(){return h.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[h.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z"}),h.jsx("path",{d:"M19 15l.8 2.2L22 18l-2.2.8L19 21l-.8-2.2L16 18l2.2-.8z"})]})}function $x(e){return e.scrollHeight-e.scrollTop-e.clientHeight>1}function iU({header:e,editor:t,panel:r,loading:n}){return h.jsxs("div",{className:"pg-playground-wrapper",children:[e,h.jsxs("div",{className:"pg-content"+(n?" pg-content--loading":""),"aria-busy":n,children:[h.jsx("div",{className:"pg-editor-col",children:t}),h.jsx("div",{className:"pg-exec-col",children:r})]})]})}function sU({title:e,actions:t,children:r,error:n,onDismissError:i,footer:s,notice:a}){const o=w.useRef(null),[l,u]=w.useState(!1);return w.useEffect(()=>{const c=o.current;if(!c)return;const d=()=>u($x(c));return c.addEventListener("scroll",d,{passive:!0}),()=>c.removeEventListener("scroll",d)},[]),w.useEffect(()=>{o.current&&u($x(o.current))}),h.jsxs("div",{className:"pg-exec-inner",children:[h.jsxs("div",{className:"pg-exec-header",children:[h.jsx("span",{className:"pg-exec-title",children:e}),t]}),a&&h.jsx("div",{className:"pg-exec-notice",children:a}),h.jsxs("div",{className:"pg-exec-main",children:[h.jsx("div",{className:"pg-exec-body",ref:o,children:r}),h.jsxs("div",{className:"pg-exec-footer",children:[n&&h.jsxs("div",{className:"pg-exec-error pg-exec-error-run"+(l?" pg-exec-error-run-shadow":""),children:[n,i&&h.jsx("button",{type:"button",className:"pg-dismiss",onClick:i,children:"×"})]}),s]})]})]})}function aU(e,t){if(e.style!==t.style)return e;let r;const n=()=>r??(r={...e});if("model"in t){const i=n();t.model==null?delete i.model:i.model=t.model}if(e.style==="chat"&&t.style==="chat"){if("system"in t){const i=n();t.system==null?delete i.system:i.system=t.system}if("messages"in t){const i=n();i.messages=t.messages??[]}}else if(e.style==="questions"&&t.style==="questions"){if("state"in t){const i=n();i.state={...e.state,value:t.state??void 0}}if("questions"in t){const i=n();i.questions={...e.questions,value:t.questions??void 0}}}return r??e}function Hg(e){return JSON.stringify(e)??"undefined"}function _d(e,t=0,r){const[n,i]=w.useState(e),s=Hg(e),a=w.useRef(s),o=w.useRef(s),l=w.useRef(!1);w.useEffect(()=>{const c=Hg(e);if(c!==a.current){if(r!=null&&r.current){c===o.current&&(a.current=c,l.current=!1);return}if(l.current){c===o.current&&(a.current=c,l.current=!1);return}c!==a.current&&(a.current=c,o.current=c,i(e))}},[e,t,r]);const u=w.useCallback(c=>{const d=Hg(c);o.current=d,l.current=d!==a.current,i(c)},[]);return[n,u]}const Um=250,oU=(e,t)=>h.jsx(Fm,{provider:e,size:t});function TA({definition:e,value:t,editable:r,onChange:n}){const[i,s]=w.useState(),a=w.useRef(void 0),o=u=>{s(u),clearTimeout(a.current),a.current=setTimeout(()=>{n(u),s(void 0)},Um)},l=i??t;return e?h.jsx(O9.Provider,{value:oU,children:h.jsx("div",{className:"pg-model-row",children:h.jsx(Ir,{propDef:e,value:l,onChange:o,className:"pg-catalog",disabled:!r})})}):h.jsx("div",{className:"pg-catalog pg-model-row-pending",children:h.jsx("span",{className:`proppy-catalog-label${l?"":" placeholder"}`,children:l?ma(l):"Select a model…"})})}function lU({size:e=12}){return h.jsx("svg",{width:e,height:e,viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,pointerEvents:"none",color:"#9ca3af"},children:h.jsx("path",{d:"M2.5 4.5L6 8L9.5 4.5"})})}function uU({toolCalls:e,onChange:t}){return h.jsxs("div",{className:"pg-tool-calls",children:[e.map((r,n)=>h.jsxs("div",{className:"pg-tool-call",children:[h.jsxs("div",{className:"pg-tool-call-header",children:[h.jsx("span",{className:"pg-tool-call-label",children:"Tool call"}),h.jsx("button",{type:"button",className:"pg-delete-msg",onClick:()=>t(e.filter((i,s)=>s!==n)),title:"Remove tool call",children:"×"})]}),h.jsxs("div",{className:"pg-tool-call-fields",children:[h.jsx("input",{className:"pg-tool-name-input",placeholder:"function_name",value:r.toolName,onChange:i=>t(e.map((s,a)=>a===n?{...s,toolName:i.target.value}:s))}),h.jsx("input",{className:"pg-tool-args-input",placeholder:'{ "key": "value" }',value:r.args,onChange:i=>t(e.map((s,a)=>a===n?{...s,args:i.target.value}:s))})]})]},n)),h.jsx("button",{type:"button",className:"pg-add-tool-call-btn",onClick:()=>t([...e,{toolName:"",args:""}]),children:"+ Tool Call"})]})}const Hx={system:"System message",user:"User",assistant:"AI",tool:"Tool Result"},cU={name:"_template",type:{kind:"primitive",syntax:"string"},optional:!1};function hU({content:e,editable:t,propDef:r,syncVersion:n,syncPausedRef:i,onChange:s}){const[a,o]=_d(e,n,i),l=w.useRef(s);l.current=s;const u=w.useCallback(c=>{o(c),l.current(c)},[o]);return h.jsxs("div",{className:"pg-panel-card",children:[h.jsx("div",{className:"pg-msg-header",children:h.jsx("span",{className:"pg-role-label",children:"System message"})}),t?h.jsx(D4,{propDef:r,value:a,onChange:u,className:"token-editor",placeholder:"System message…"}):h.jsx("div",{className:`pg-msg-content${e===void 0?" pg-placeholder":""}`,"data-readonly":"true",children:e!==void 0?ma(e):"System message…"})]})}const dU=w.memo(hU,(e,t)=>t.syncPausedRef.current&&e.editable===t.editable&&e.propDef===t.propDef&&e.syncPausedRef===t.syncPausedRef);function fU({msg:e,messageIndex:t,editable:r,propDef:n,onChange:i,onDelete:s}){const[a,o]=_d(e.content),l=w.useRef(e),u=w.useRef(i);l.current=e,u.current=i;const c=w.useCallback(m=>{o(m),u.current({...l.current,content:m})},[o]),d=cl(r,e.content);return h.jsxs("div",{className:"pg-panel-card","data-message-index":t,children:[h.jsxs("div",{className:"pg-msg-header",children:[h.jsxs("div",{className:"pg-role-wrapper",children:[h.jsx("span",{className:"pg-role-label",children:Hx[e.role]??e.role}),h.jsx(lU,{size:10}),h.jsx("select",{className:"pg-role-select",value:e.role,disabled:!r,onChange:m=>i({...e,role:m.target.value}),children:Object.entries(Hx).map(([m,f])=>h.jsx("option",{value:m,children:f},m))})]}),r&&h.jsx("button",{type:"button",className:"pg-delete-msg",onClick:s,title:"Delete",children:"×"})]}),d?h.jsx(D4,{propDef:n,value:a,onChange:c,className:"token-editor"}):h.jsx("div",{className:"pg-msg-content","data-readonly":"true",children:ma(e.content)}),r&&e.role==="assistant"&&h.jsx(uU,{toolCalls:e.toolCalls??[],onChange:m=>i({...e,toolCalls:m})})]})}function mU({propDef:e,value:t,editable:r,onDelete:n,onChange:i}){const[s,a]=w.useState(!1),o=e.description?e.description.split(`
84
- `):[],l=o.length>1;return h.jsxs("div",{className:"pg-panel-card",children:[h.jsxs("div",{className:"pg-msg-header",style:{alignItems:"flex-start"},children:[h.jsxs("div",{style:{flex:1,minWidth:0},children:[h.jsx("span",{className:"pg-role-label",children:e.name}),o.length>0&&h.jsxs("div",{className:"pg-param-description",children:[s?e.description:o[0],l&&h.jsx("button",{type:"button",className:"pg-desc-toggle",onClick:()=>a(u=>!u),children:s?"less":"more"})]})]}),r&&h.jsx("button",{type:"button",className:"pg-delete-msg",onClick:n,title:"Remove parameter",children:"×"})]}),h.jsx("div",{className:"pg-param-input-inline",children:h.jsx(Ir,{propDef:e,value:t,onChange:i,className:"pg-param-input",disabled:!cl(r,t)})})]})}function pU({prompt:e,modelParameters:t,addableParams:r,onUpdate:n,onClose:i}){const s=e.modelParametersEditable!==!1;return h.jsx("div",{className:"pg-modal-backdrop",onClick:i,children:h.jsxs("div",{className:"pg-modal",onClick:a=>a.stopPropagation(),children:[h.jsxs("div",{className:"pg-modal-header",children:[h.jsx("span",{className:"pg-modal-title",children:"Model settings"}),h.jsx("button",{type:"button",className:"pg-delete-msg",onClick:i,title:"Close",children:"×"})]}),h.jsx("div",{className:"pg-modal-body",children:e.modelParameters.length===0?h.jsx("div",{className:"pg-modal-empty",children:"No settings configured."}):e.modelParameters.map(a=>{const o=t.find(l=>l.name===a.def.name);return o?h.jsx(mU,{propDef:o,value:a.value,editable:s,onDelete:()=>n({modelParameters:{[a.def.name]:null}}),onChange:l=>n({modelParameters:{[a.def.name]:l}})},a.def.name):h.jsxs("div",{className:"pg-panel-card",children:[h.jsxs("div",{className:"pg-msg-header",children:[h.jsx("span",{className:"pg-role-label",children:a.def.name}),s&&a.value&&xA(a.value)&&h.jsx("button",{type:"button",className:"pg-delete-msg",onClick:()=>n({modelParameters:{[a.def.name]:null}}),title:"Remove",children:"×"})]}),h.jsx("div",{className:"pg-msg-content",style:{fontSize:13,color:"#9ca3af"},children:a.value!==void 0?ma(a.value):""})]},a.def.name)})}),s&&r.length>0&&h.jsx("div",{className:"pg-modal-footer",children:h.jsxs("div",{className:"pg-pill-btn pg-add-param-btn",children:["+ Add setting",h.jsxs("select",{className:"pg-model-overlay-select",value:"",onChange:a=>{if(!a.target.value)return;const o=r.find(l=>l.name===a.target.value);o&&n({modelParameters:{[o.name]:o.defaultValue??Q9(o.type)}})},children:[h.jsx("option",{value:"",children:"Choose…"}),r.map(a=>h.jsx("option",{value:a.name,children:a.name},a.name))]})]})})]})})}function gU({prompt:e,onUpdate:t,modelDefinition:r}){const n=w.useRef(!1),i=w.useRef(null),s=w.useRef(null),[a,o]=w.useState(0),[l,u]=_d(e.messages),[c,d]=w.useState([]),[m,f]=w.useState(!1),p=()=>{n.current=!0},g=A=>{A.currentTarget.contains(A.relatedTarget)||(n.current=!1,o(z=>z+1))};w.useEffect(()=>{e.providerId&&_H(e.providerId).then(d).catch(()=>{})},[e.providerId]);const y=w.useRef(null),b=w.useRef(null),v=A=>{u(A),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>t({messages:A}),Um)},x=A=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>t({system:A}),Um)},E=()=>{var B;const A=l[l.length-1];let z="user";(A==null?void 0:A.role)==="user"?z="assistant":(A==null?void 0:A.role)==="assistant"&&((B=A.toolCalls)!=null&&B.length)&&(z="tool");const I=[...l,{role:z,content:{kind:"primitive",value:""}}];s.current=I.length-1,u(I),y.current&&clearTimeout(y.current),t({messages:I})};w.useLayoutEffect(()=>{var z,I;const A=s.current;A===null||A>=l.length||(s.current=null,(I=(z=i.current)==null?void 0:z.querySelector(`[data-message-index="${A}"] .token-editor`))==null||I.focus())},[l.length]);const T=new Set(e.modelParameters.map(A=>A.def.name)),C=r?c.filter(A=>!T.has(A.name)):[],L=w.useMemo(()=>({...cU,interpolatables:L9(e.functionParameters)}),[e.functionParameters]);return h.jsxs("div",{className:"pg-editor",children:[m&&h.jsx(pU,{prompt:e,modelParameters:c,addableParams:C,onUpdate:t,onClose:()=>f(!1)}),h.jsx("div",{className:"pg-panel",children:h.jsxs("div",{className:"pg-panel-model-row",children:[h.jsx(TA,{definition:r,value:e.model,editable:cl(e.modelEditable,e.model),onChange:A=>t({model:A})}),h.jsxs("div",{className:"pg-panel-model-row-actions",children:[h.jsx("button",{type:"button",className:"pg-pill-btn",onClick:()=>f(!0),children:"Settings"}),h.jsx("button",{type:"button",className:"pg-pill-btn",disabled:!0,children:"Tools"}),h.jsxs("button",{type:"button",className:"pg-pill-btn",children:["Output type: Text",h.jsx("span",{"aria-hidden":!0,className:"pg-pill-chevron",children:"▾"})]})]})]})}),h.jsxs("div",{className:"pg-panel",children:[h.jsxs("div",{ref:i,className:"pg-panel-body",onFocus:p,onBlur:g,children:[h.jsx(dU,{content:e.system,editable:cl(e.systemEditable,e.system),propDef:L,syncVersion:a,syncPausedRef:n,onChange:x}),l.map((A,z)=>h.jsx(fU,{msg:A,messageIndex:z,editable:e.messagesEditable,propDef:L,onChange:I=>v(l.map((B,j)=>j===z?I:B)),onDelete:()=>v(l.filter((I,B)=>B!==z))},z))]}),h.jsx("div",{className:"pg-panel-footer",children:h.jsx("button",{type:"button",className:"pg-add-msg-btn",onClick:E,disabled:!e.messagesEditable,children:"+ Add message"})})]})]})}function bU({value:e,validate:t,className:r,label:n,title:i,readOnly:s,onCommit:a}){const[o,l]=w.useState(null),u=o===null?null:t==null?void 0:t(o),c=()=>{o!==null&&!u&&o!==e&&a(o),l(null)};return h.jsx("input",{"data-1p-ignore":!0,className:r,"aria-label":n,"aria-invalid":!!u,title:u??i,value:o??e,readOnly:s,spellCheck:!1,onChange:d=>l(d.target.value),onBlur:c,onKeyDown:d=>{d.key==="Enter"?(d.preventDefault(),c()):d.key==="Escape"&&l(null)}})}function vd(e){if(e.kind!=="union")return;const t=e.types.find(s=>s.kind==="primitive"&&(s.base??s.syntax)==="string"),r=e.types.filter(s=>s.kind==="record"||s.kind==="array"),n=e.types.filter(s=>s!==t&&!r.includes(s)&&!(s.kind==="constant"&&s.value===null));if(!t||r.length===0||n.length>0)return;const i=e.types.some(s=>s.kind==="constant"&&s.value===null);return{text:t,structured:r,nullable:i}}const Fx={kind:"primitive",value:null};function Fg(e){return(e==null?void 0:e.kind)==="primitive"&&e.value===null}function _U(e){var t;return e.kind==="record"&&!!((t=vd(e.value.type))!=null&&t.nullable)}function Ux(e){return e===void 0||e.kind==="template"||e.kind==="reference"||e.kind==="primitive"&&(typeof e.value=="string"||e.value==null)}function Vx(e,t){if(e.kind==="tuple"){const{elements:r,rest:n}=e;return!n||r.length<2||![...r,n].every(i=>!!vd(i.type))?void 0:{fixed:r,rest:n,min:r.length}}if(e.kind==="array"&&t[t.length-1]==="criteria"&&vd(e.element.type))return{fixed:[],rest:e.element,min:2}}function vU(){const e=[];function t({propDef:s,value:a,onChange:o,path:l,disabled:u}){const c=vd(s.type),d=Y9(),m=(l==null?void 0:l.join("/"))??"",[f,p]=w.useState({slot:m,structured:!Ux(a)}),g=f.slot===m?f.structured:!Ux(a),y=c.structured.length===1?c.structured[0]:{kind:"union",syntax:c.structured.map(I=>I.syntax).join(" | "),types:c.structured},b=g?y:c.text,v=Fg(a)?void 0:a,x=c.nullable&&Fg(a),[E,T]=w.useState(!1),C=w.useRef(null);w.useEffect(()=>{var I,B;E&&((B=(I=C.current)==null?void 0:I.querySelector('[contenteditable="true"], input, textarea'))==null||B.focus())},[E]);const{defaultValue:L,...A}=s,z=Fg(L)?A:s;return h.jsxs("div",{className:"pg-entry",ref:C,onBlur:I=>{I.currentTarget.contains(I.relatedTarget)||T(!1)},children:[x&&!E?h.jsx("button",{type:"button",className:"pg-entry-none",title:"None (null). Click to write one.",disabled:u,onClick:()=>T(!0),children:"None"}):h.jsx(Ir,{propDef:{...z,type:b},value:g?a:v,onChange:o,plugins:e,path:l,disabled:u,className:g?void 0:"token-editor pg-entry-text"}),(l==null?void 0:l.length)===1&&(d!=null&&d.length)?h.jsx(q9,{interpolatables:d,onChange:o,disabled:u}):null,h.jsx("button",{type:"button",className:"pg-entry-toggle",disabled:u,onClick:()=>{p({slot:m,structured:!g}),o(nn(g?c.text:y))},children:g?"Text":"JSON"}),c.nullable&&!x&&h.jsx("button",{type:"button",className:"pg-entry-set-null",title:"Set to null",disabled:u,onClick:()=>{p({slot:m,structured:!1}),T(!1),o(Fx)},children:"None"})]})}function r({propDef:s,value:a,onChange:o,path:l,disabled:u}){return s.type.kind!=="record"?null:h.jsx(V9,{value:{...s.type.value,defaultValue:Fx},current:a,onChange:o,plugins:e,path:l,disabled:u})}function n({propDef:s,value:a,onChange:o,path:l=[],disabled:u}){const c=Vx(s.type,l);if(!c)return null;const{fixed:d,rest:m,min:f}=c,p=H9(a),g=Math.max(p.length,f),y=x=>({...d[x]??m,name:`Level ${x}`}),b=x=>d.length>0?F9(x,d.length):x<p.length&&p.length>f,v=x=>o({kind:"array",elements:x});return h.jsxs("ol",{className:"pg-score-levels",start:0,children:[Array.from({length:g},(x,E)=>h.jsxs("li",{className:"pg-score-level",children:[h.jsx("span",{className:"pg-score-level-number",children:E}),h.jsx("div",{className:"pg-score-level-editor",children:h.jsx(Ir,{propDef:y(E),value:p[E],onChange:T=>{const C=[...p];for(let L=C.length;L<E;L++)C[L]=nn(y(L).type);C[E]=T,v(C)},plugins:e,path:[...l,String(E)],disabled:u})}),b(E)?h.jsx("button",{type:"button",className:"pg-delete-msg",title:"Remove level",disabled:u,onClick:()=>v(p.filter((T,C)=>C!==E)),children:"×"}):h.jsx("span",{className:"pg-delete-msg pg-delete-msg-spacer","aria-hidden":"true",children:"×"})]},E)),h.jsx("button",{type:"button",className:"pg-add-level-btn",disabled:u,onClick:()=>{const x=[...p];for(let E=x.length;E<g;E++)x[E]=nn(y(E).type);v([...x,nn(m.type)])},children:"+ Add level"})]})}function i({propDef:s,value:a,onChange:o,path:l=[],disabled:u}){if(s.type.kind!=="object")return null;const c=(a==null?void 0:a.kind)==="object"?a.properties:{};return h.jsx("div",{className:"pg-noul-criteria",children:s.type.properties.map(d=>h.jsxs("div",{className:"pg-noul-outcome",children:[h.jsxs("span",{className:"pg-noul-outcome-label",children:[h.jsx("strong",{children:d.name==="true"?"Yes":"No"})," means"]}),h.jsx(Ir,{propDef:d,value:c[d.name],onChange:m=>o({kind:"object",properties:{...c,[d.name]:m}}),plugins:e,path:[...l,d.name],disabled:u})]},d.name))})}return e.push({match:s=>!!vd(s),component:t},{match:_U,component:r},{match:(s,a)=>!!Vx(s,a),component:n},{match:(s,a)=>s.kind==="object"&&a[a.length-1]==="criteria"&&s.properties.length===2&&s.properties.every(o=>o.name==="true"||o.name==="false"),component:i}),e}function yU(e){return e===void 0?{}:e.kind==="object"?e.properties:void 0}function xU(e){return e.type.kind==="record"?e.type.value:void 0}function SU(e){const t=new Set(Object.keys(e));for(let r=Object.keys(e).length+1;;r++){const n=`question_${r}`;if(!t.has(n))return n}}const wU=e=>e.charAt(0).toUpperCase()+e.slice(1);function EU(e){const t=U9(e);if(t.length>0)return t.map(({label:n,factory:i})=>({key:i.def.name,label:n,create:()=>n1(i)}));const r=B9(e.type);return r?r.cases.map(n=>({key:String(n.discriminatorValue),label:wU(String(n.discriminatorValue)),create:()=>({kind:"object",properties:{[r.discriminator]:{kind:"primitive",value:n.discriminatorValue},...Object.fromEntries(n.properties.filter(i=>!i.optional).map(i=>[i.name,i.defaultValue??nn(i.type)]))}})})):[]}function kU(e,t){const r=SU(e);return{id:r,questions:{...e,[r]:t.create()}}}function CU(e,t,r){return z9(e,t,r)}function qx({value:e}){return h.jsx("div",{className:"pg-msg-content","data-readonly":"true",children:e===void 0?"":ma(e)})}function TU({id:e,questions:t,disabled:r,onRename:n}){return h.jsx(bU,{className:"pg-question-id",label:"Question id",title:"Identifies this question's answer",value:e,validate:i=>$9(t,e,i),readOnly:r,onCommit:n})}function AU({prompt:e,onUpdate:t,modelDefinition:r}){const n=w.useRef(!1),[i,s]=w.useState(0),[a,o]=_d(e.state.value,i,n),[l,u]=_d(e.questions.value,i,n),c=w.useMemo(vU,[]),d=w.useRef(null),m=w.useRef(null),f=w.useMemo(()=>L9(e.functionParameters),[e.functionParameters]),p=w.useRef({}),g=(A,z)=>{clearTimeout(p.current[A]),p.current[A]=setTimeout(()=>t({[A]:z}),Um)},y=()=>{n.current=!0},b=A=>{A.currentTarget.contains(A.relatedTarget)||(n.current=!1,s(z=>z+1))},v=w.useMemo(()=>({...e.state.def,interpolatables:f}),[e.state.def,f]),x=w.useMemo(()=>{const A=xU(e.questions.def);return A&&{...A,interpolatables:f}},[e.questions.def,f]),E=yU(l),T=cl(e.questionsEditable,l),C=w.useMemo(()=>x?EU(x):[],[x]),L=(A,z=!1)=>{const I={kind:"object",properties:A};u(I),z?(clearTimeout(p.current.questions),t({questions:I})):g("questions",I)};return w.useEffect(()=>{var z,I;const A=m.current;A!==null&&(m.current=null,(I=(z=d.current)==null?void 0:z.querySelector(`[data-question-index="${A}"] [contenteditable="true"], [data-question-index="${A}"] textarea, [data-question-index="${A}"] input:not(.pg-question-id)`))==null||I.focus())}),h.jsxs("div",{className:"pg-editor pg-questions-editor",children:[h.jsx("div",{className:"pg-panel",children:h.jsx("div",{className:"pg-panel-model-row",children:h.jsx(TA,{definition:r,value:e.model,editable:cl(e.modelEditable,e.model),onChange:A=>t({model:A})})})}),h.jsxs("div",{className:"pg-panel",onFocus:y,onBlur:b,children:[h.jsxs("div",{className:"pg-panel-card pg-state-card",children:[h.jsxs("div",{className:"pg-msg-header",children:[h.jsx("span",{className:"pg-role-label",children:"State"}),h.jsx("span",{className:"pg-card-hint",title:"What the questions are about",children:"?"})]}),cl(e.stateEditable,a)?h.jsx(Ir,{propDef:v,value:a,onChange:A=>{o(A),g("state",A)},plugins:c,path:["state"]}):h.jsx(qx,{value:a})]}),h.jsx("div",{className:"pg-msg-header",children:h.jsx("span",{className:"pg-role-label",children:"Questions"})}),h.jsx("div",{className:"pg-questions",ref:d,children:T&&x&&E?Object.entries(E).map(([A,z],I)=>h.jsxs("div",{className:"pg-panel-card pg-question-card","data-question-index":I,children:[h.jsxs("div",{className:"pg-msg-header",children:[h.jsx(TU,{id:A,questions:E,disabled:!1,onRename:B=>L(CU(E,A,B),!0)}),h.jsx("button",{type:"button",className:"pg-delete-msg",title:"Delete question",onClick:()=>{const B={...E};delete B[A],L(B,!0)},children:"×"})]}),h.jsx(Ir,{propDef:{...x,name:A},value:z,onChange:B=>L({...E,[A]:B}),plugins:c,path:["questions",A]})]},I)):h.jsx("div",{className:"pg-panel-card",children:h.jsx(qx,{value:l})})}),T&&x&&E&&C.length>0&&h.jsx("div",{className:"pg-panel-footer",children:h.jsxs("div",{className:"pg-add-msg-btn pg-add-question",children:["+ Add question",h.jsxs("select",{"aria-label":"Add question",className:"pg-model-overlay-select",value:"",onChange:A=>{const z=C.find(B=>B.key===A.target.value);if(!z)return;const I=kU(E,z);m.current=Object.keys(I.questions).length-1,L(I.questions,!0)},children:[h.jsx("option",{value:"",children:"Choose…"}),C.map(({key:A,label:z})=>h.jsx("option",{value:A,children:z},A))]})]})})]})]})}function NU({prompt:e,onUpdate:t,modelDefinition:r}){const n=w.useCallback(s=>t({...s,style:"questions"}),[t]),i=w.useCallback(s=>t({...s,style:"chat"}),[t]);switch(e.style){case"chat":return h.jsx(gU,{prompt:e,onUpdate:i,modelDefinition:r});case"questions":return h.jsx(AU,{prompt:e,onUpdate:n,modelDefinition:r})}}const RU=w.memo(NU);function AA(e){var n;const t=w.useRef(null),r=JSON.stringify(e)??"";return((n=t.current)==null?void 0:n.json)!==r&&(t.current={value:e,json:r}),t.current.value}function LU(e){return e instanceof Element&&!!e.closest(".add-to-dataset-menu")}const IU=6e3;function DU(e){return e.length===0?"":` · skipped ${[...new Set(e.map(r=>r.name))].join(", ")} (no matching field)`}function d_({inputs:e,resources:t,newDatasetFields:r,prompt:n,source:i,disabled:s,className:a,children:o,onOpenDataset:l}){const[u,c]=w.useState(!1),[d,m]=w.useState(null),[f,p]=w.useState(null),[g,y]=w.useState(null),[b,v]=w.useState(!1),[x,E]=w.useState(""),[T,C]=w.useState(!1),[L,A]=w.useState(null),z=w.useRef(null),I=w.useCallback(()=>{c(!1),v(!1),E("")},[]),{triggerRef:B,popoverRef:j,style:G}=Fi({open:u,onClose:I,matchTriggerWidth:!1});w.useEffect(()=>{if(!u)return;let R=!1;return y(null),Promise.all([eA(),rA()]).then(([de,Te])=>{var H;R||(m(de),p(((H=Te[0])==null?void 0:H.id)??null))}).catch(de=>!R&&y(de.message)),()=>{R=!0}},[u]),w.useEffect(()=>{var R;b&&((R=z.current)==null||R.focus())},[b]),w.useEffect(()=>{if(!(L!=null&&L.ok))return;const R=setTimeout(()=>A(null),IU);return()=>clearTimeout(R)},[L]);const W=async(R,de)=>{const{cells:Te,skipped:H}=vA(e,de),Oe=yA(t);await VH(R.providerId,R.id,[{cells:Te,source:i,...Oe&&{resources:Oe}}]);const Pe=DU(H);A({ok:!0,message:`Added to ${R.name}${Pe}`,dataset:{providerId:R.providerId,id:R.id,name:R.name},skipped:Pe})},Y=async R=>{C(!0);try{await R(),I()}catch(de){A({ok:!1,message:de.message}),I()}finally{C(!1)}},V=()=>Y(async()=>{const R=x.trim();if(!R||!f)return;const de=await tA(f,{name:R,fields:r,...n&&{prompt:n.link}});await W({...de,providerId:f},de.fields)}),X=[...d??[]].sort((R,de)=>{const Te=Hh(R.prompt,n==null?void 0:n.openable),H=Hh(de.prompt,n==null?void 0:n.openable);return Te===H?0:Te?-1:1}),P=u&&cn.createPortal(h.jsxs("div",{className:"add-to-dataset-menu",ref:j,style:G,role:"menu",children:[g&&h.jsx("div",{className:"add-to-dataset-error",children:g}),!d&&!g&&h.jsx("div",{className:"add-to-dataset-empty",children:"Loading…"}),X.map(R=>{const de=R.error?0:FF(e,R.fields),Te=Hh(R.prompt,n==null?void 0:n.openable);return h.jsxs("button",{type:"button",role:"menuitem",className:"add-to-dataset-item",disabled:T||de===0,onClick:()=>Y(()=>W(R,R.fields)),title:R.error??void 0,children:[h.jsxs("span",{className:"add-to-dataset-item-name",children:[R.name,Te&&h.jsx("span",{className:"add-to-dataset-linked",children:"linked"})]}),h.jsx("span",{className:"add-to-dataset-item-meta",children:R.error?"can't be opened":de===0?"no matching fields":`${de} of ${e.length} field${e.length===1?"":"s"}`})]},`${R.providerId}:${R.id}`)}),d&&X.length>0&&h.jsx("div",{className:"add-to-dataset-divider"}),b?h.jsxs("form",{className:"add-to-dataset-new",onSubmit:R=>{R.preventDefault(),V()},children:[h.jsx("input",{ref:z,className:"add-to-dataset-name",placeholder:"Dataset name","aria-label":"New dataset name",value:x,onChange:R=>E(R.target.value),disabled:T}),h.jsx("button",{type:"submit",className:"add-to-dataset-create",disabled:T||!x.trim()||!f,children:"Create"})]}):h.jsx("button",{type:"button",role:"menuitem",className:"add-to-dataset-item add-to-dataset-item-new",onClick:()=>v(!0),disabled:T||!!d&&!f,children:h.jsx("span",{className:"add-to-dataset-item-name",children:"New dataset…"})})]}),document.body),re=L==null?void 0:L.dataset;return h.jsxs("span",{className:"add-to-dataset",children:[L&&h.jsxs("span",{className:`add-to-dataset-outcome${L.ok?"":" add-to-dataset-outcome-error"}`,role:"status",title:L.message,children:[re&&l?h.jsxs("span",{children:["Added to"," ",h.jsxs("button",{type:"button",className:"add-to-dataset-link",onClick:R=>{R.stopPropagation(),l(re)},children:[re.name," ↗"]}),L.skipped]}):L.message,h.jsx("button",{type:"button",className:"pg-dismiss","aria-label":"Dismiss",onClick:()=>A(null),children:"×"})]}),h.jsx("button",{type:"button",ref:B,className:a??"add-to-dataset-btn",onClick:()=>{A(null),c(R=>!R)},disabled:s,"aria-haspopup":"menu","aria-expanded":u,title:"Add these inputs to a dataset",children:o??h.jsxs(h.Fragment,{children:[h.jsx(Jd,{}),"Add to dataset"]})}),P]})}function NA(e){switch(e.kind){case"dataset":return[e.field];case"object":return Object.values(e.properties).flatMap(NA);default:return[]}}function RA(e){switch(e.kind){case"input":return[e];case"object":return Object.values(e.properties).flatMap(RA);default:return[]}}function Vm(e,t,r=i=>i,n=""){const i=[];for(const s of e){const a=n?`${n}.${s.name}`:s.name,o=t[s.name],l=o&&r(o);if(!l){s.optional||i.push(a);continue}l.kind==="object"&&s.type.kind==="object"&&i.push(...Vm(s.type.properties,l.properties,r,a))}return i}function Eve(e,t,r){var c;const n=[],{prompt:i,fields:s}=r,a=s&&new Set(s.map(d=>d.id)),o=(d,m)=>{if(a)for(const f of NA(d))a.has(f)||n.push(`${m} is bound to a column that no longer exists`)},l=[["function",e.functionInputs,i==null?void 0:i.functionParameters],["execute",e.executeInputs,(i==null?void 0:i.executeParameters)??[]]];for(const[d,m,f]of l){for(const[p,g]of Object.entries(m)){const y=`Input '${Fh(d,p)}'`;if(f&&!f.some(b=>b.name===p)){n.push(`${y} is bound, but the prompt no longer has it`);continue}o(g,y)}if(f)for(const p of Vm(f,m))n.push(`Input '${Fh(d,p)}' is required but unbound`)}for(const[d,m]of Object.entries(e.resources??{}))for(const[f,p]of Object.entries(m.args??{}))o(p,`Resource '${d}': '${f}'`);i&&n.push(...BF(e,i,{undeclaredInstances:!0}));const u=i&&gA(i);for(const d of t){const m=(c=r.checks)==null?void 0:c.find(p=>p.uri===d.uri),f=`Check '${d.label??(m==null?void 0:m.label)??d.uri}'`;if(r.checks&&!m){n.push(`${f} no longer exists`);continue}if(m!=null&&m.error){n.push(`${f} can't load: ${m.error}`);continue}for(const[p,g]of Object.entries(d.args)){const y=`${f}: '${p}'`;if(o(g,y),!!u)for(const b of RA(g))u[b.half].has(b.path)||n.push(`${y} names input '${Fh(b.half,b.path)}', which the prompt doesn't have`)}if(m)for(const p of Vm(m.parameters,d.args))n.push(`${f}: '${p}' is required but unbound`)}return n}const f_="@@column/",m_="@@input/",qm="@@instance/",LA="@@new-column",Gx="Dataset columns",OU="Prompt inputs",Wx="Resources in this run",G4="New";function W4(e){return`${f_}${e}`}function Y4(e,t){return`${m_}${e}/${t}`}function oa(e,t){return t===void 0?`${qm}${e}`:`${qm}${e}/${t}`}function Bl(e){if(!e.startsWith(qm))return;const t=e.slice(qm.length),r=t.indexOf("/");return r<0?{name:t}:{name:t.slice(0,r),output:t.slice(r+1)}}function K4(e){return e.startsWith("@@")}function p_(e){if(e.startsWith(f_))return{kind:"dataset",field:e.slice(f_.length)};if(e.startsWith(m_)){const r=e.slice(m_.length),n=r.indexOf("/"),i=r.slice(0,n);return i!=="function"&&i!=="execute"?void 0:{kind:"input",half:i,path:r.slice(n+1)}}const t=Bl(e);if(t)return{kind:"instance",...t}}function MU(e){if(e.kind==="dataset")return W4(e.field);if(e.kind==="input")return Y4(e.half,e.path);if(e.kind==="instance")return oa(e.name,e.output)}function jU(e,t){return e==="execute"?`execute.${t}`:t}function yd(e,t){return e.syntax===t.syntax?!0:e.kind==="union"?e.types.every(r=>yd(r,t)):t.kind==="union"?t.types.some(r=>yd(e,r)):e.kind==="primitive"&&t.kind==="primitive"&&e.base===t.base}function BU(e,t,r,n){const[i,...s]=r.split("."),a=(l,u)=>{if(u.length===0)return n;const[c,...d]=u,m=(l==null?void 0:l.kind)==="object"?{...l.properties}:{};return m[c]=a(m[c],d),{kind:"object",properties:m}},o=t==="function"?"functionInputs":"executeInputs";return{...e,[o]:{...e[o],[i]:a(e[o][i],s)}}}function X4(e){return[...wl(e.functionParameters).map(t=>({half:"function",path:t.path,type:t.type})),...wl(e.executeParameters??[]).map(t=>({half:"execute",path:t.path,type:t.type}))]}function IA(e,t,r){return[...e.map(n=>({uri:W4(n.id),label:n.def.name,scope:"run",group:[Gx]})),...r?[{uri:LA,label:r,scope:"run",group:[Gx]}]:[],...t.map(n=>({uri:Y4(n.half,n.path),label:`= ${jU(n.half,n.path)}`,scope:"run",group:[OU]}))]}function PU(e,t){var o,l;const r=X4(t),n=t.fields??[],i=(u,c)=>{const d=[];for(const m of n)(t.offerMismatches||yd(m.def.type,u))&&d.push(W4(m.id));for(const m of r)if(!(c&&m.half===c.half&&mA(m.path,c.path))&&!(!t.offerMismatches&&!yd(m.type,u))){if(c){const f={kind:"input",half:m.half,path:m.path},p=BU(t.bindings,c.half,c.path,f);if(pA(p))continue}d.push(Y4(m.half,m.path))}return d},s=(u,c)=>{const d={...c};for(const m of r.filter(f=>f.half===u)){const f=i(m.type,m);t.newColumn&&f.push(LA),f.length>0&&(d[m.path]=[...d[m.path]??[],...f])}return d},a={...e==null?void 0:e.resourceSlots};for(const u of(e==null?void 0:e.resources)??[]){if(!((o=u.parameters)!=null&&o.length))continue;const c={...(l=e==null?void 0:e.resourceSlots)==null?void 0:l[u.uri]};for(const d of wl(u.parameters)){const m=i(d.type);m.length>0&&(c[d.path]=[...c[d.path]??[],...m])}a[u.uri]=c}return{resources:[...(e==null?void 0:e.resources)??[],...IA(n,r,t.newColumn?"+ New column from this slot":void 0)],functionSlots:s("function",e==null?void 0:e.functionSlots),executeSlots:s("execute",e==null?void 0:e.executeSlots),resourceSlots:a}}function kve(e,t){const r=X4(t),n=IA(t.fields??[],r,"+ New column from this parameter"),i=n.map(s=>s.uri);return{resources:n,functionSlots:Object.fromEntries(wl(e).map(s=>[s.path,i])),executeSlots:{}}}function zU(e,t,r){var a,o,l;const n=p_(e);if(!n)return;let i,s="";if(n.kind==="dataset")i=(o=(a=r.fields)==null?void 0:a.find(u=>u.id===n.field))==null?void 0:o.def.type,s=i?"column from dataset":"column no longer exists";else if(n.kind==="input"){const{half:u,path:c}=n;i=(l=X4(r).find(d=>d.half===u&&d.path===c))==null?void 0:l.type,s=i?"same value as that input":"input no longer exists"}return i&&!yd(i,t)?{note:s,warning:`${i.syntax} into ${t.syntax}`}:{note:s}}function $U(e,t){const r=Object.entries(t);if(r.length===0)return[...e];const n=new Map(e.map(a=>[a.uri,a])),i=new Map;for(const a of e)a.parent&&i.set(a.parent,[...i.get(a.parent)??[],a]);return[...r.flatMap(([a,{uri:o}])=>{const l=n.get(o),u=(l==null?void 0:l.scope)??"run";return[{uri:oa(a),label:a,scope:u,group:[Wx],...(l==null?void 0:l.value)!==void 0&&{value:l.value}},...(i.get(o)??[]).map(c=>({uri:oa(a,c.uri.slice(o.length+1)),label:c.label,scope:u,group:[Wx],parent:oa(a),...c.value!==void 0&&{value:c.value}}))]}),...e.map(a=>K4(a.uri)?a:{...a,group:[G4,...a.group??[]]})]}function HU(e,t,r){const n=Object.entries(r);if(n.length===0)return{...e};const i=new Map(t.flatMap(s=>s.parent?[[s.uri,s.parent]]:[]));return Object.fromEntries(Object.entries(e??{}).map(([s,a])=>{const o=[];for(const[l,{uri:u}]of n)for(const c of a)c===u?o.push(oa(l)):i.get(c)===u&&o.push(oa(l,c.slice(u.length+1)));return[s,[...o,...a]]}))}function FU(e,t){const r=(e==null?void 0:e.resources)??[],n=i=>HU(i,r,t);return{resources:$U(r,t),functionSlots:n(e==null?void 0:e.functionSlots),executeSlots:n(e==null?void 0:e.executeSlots),...(e==null?void 0:e.resourceSlots)&&{resourceSlots:Object.fromEntries(Object.entries(e.resourceSlots).map(([i,s])=>[i,n(s)]))}}}function UU(e,t,r,n={}){const i=Bl(e);if(!i)return;const s=t[i.name],a=i.output===void 0?i.name:`${i.name}.${i.output}`;if(!s)return n.rowsMayDeclare?{label:a,note:"not declared here: each row must declare it"}:{label:a,note:"resource no longer in this run",missing:!0};const o=r.get(s.uri);return{label:a,note:(o==null?void 0:o.label)??s.uri}}function Q4(e){return`pg-exec-params:${e.globalId??e.id}`}function Cve(e){try{const t=localStorage.getItem(Q4(e)),r=t?JSON.parse(t):void 0;return r&&typeof r=="object"?r:void 0}catch{return}}const hl="";function Gi(e){if(!e)return;const t=e.resources??{},r=t[hl];if(r)return p_(r);const n=Object.entries(t).flatMap(([s,a])=>{if(s===hl)return[];const o=p_(a);return o?[[s,o]]:[]});if(n.length===0)return e.value?{kind:"value",value:e.value}:void 0;let i=e.value?{kind:"value",value:e.value}:{kind:"object",properties:{}};for(const[s,a]of n)i=DA(i,s.split("."),a);return i}function DA(e,t,r){if(t.length===0)return r;const[n,...i]=t,s={...VU(e)};return s[n]=DA(s[n]??{kind:"object",properties:{}},i,r),{kind:"object",properties:s}}function VU(e){return e.kind==="object"?e.properties:e.kind==="value"&&e.value.kind==="object"?Object.fromEntries(Object.entries(e.value.properties).map(([t,r])=>[t,{kind:"value",value:r}])):{}}function dl(e){if(!e)return{};const t={};let r;const n=(s,a)=>{switch(s.kind){case"value":a===hl?r=s.value:i(a,s.value);break;case"object":for(const[o,l]of Object.entries(s.properties))n(l,a===hl?o:`${a}.${o}`);break;case"dataset":case"input":case"instance":t[a]=MU(s);break}},i=(s,a)=>{const o=s.split(".");(r==null?void 0:r.kind)!=="object"&&(r={kind:"object",properties:{}});let l=r;for(const u of o.slice(0,-1)){const c=l.properties[u];(c==null?void 0:c.kind)!=="object"&&(l.properties[u]={kind:"object",properties:{}}),l=l.properties[u]}l.properties[o[o.length-1]]=a};return n(e,hl),{...r?{value:r}:{},...Object.keys(t).length>0?{resources:t}:{}}}function Yx(e,t,r){const[n]=t?Vm([e],{[e.name]:t}):[e.name];if(n===void 0)return;let i=e;for(const s of n.split(".").slice(1)){if(i.type.kind!=="object")break;i=i.type.properties.find(a=>a.name===s)??i}return i.type.kind!=="opaque"?`Parameter '${n}' is required`:r?`Parameter '${n}' needs a resource — pick one from its dropdown`:`Parameter '${n}' is a ${i.type.syntax}, which can't be typed in. Export a resource() from a *.playground.ts beside the prompt, or from .evalution/playground/, to supply one.`}function qU(e){if(e.type.kind!=="object")return;const t=e.type.properties.filter(r=>r.type.kind==="object");return t.length>=2?t:void 0}function Kx(e){const t=qU(e)??[],r=new Map;for(const n of t)if(n.type.kind==="object")for(const i of n.type.properties){const s=`${i.name}\0${i.type.syntax}`,a=r.get(s);a?(a.members.push(n.name),a.optional=a.optional&&i.optional):r.set(s,{name:i.name,type:i.type,optional:i.optional,members:[n.name]})}return[...r.values()]}function Xx(e){return e.some(t=>t.members.length>=2)}function GU(e){return new Set(e.flatMap(t=>t.members)).size}function WU(e,t){if(e){if(e.kind==="object")return e.properties[t];if(e.kind==="value"&&e.value.kind==="object"){const r=e.value.properties[t];return r?{kind:"value",value:r}:void 0}}}function OA(e,t){return t.reduce((r,n)=>WU(r,n),e)}function Z4(e,t){if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||!e||!t||Array.isArray(e)!==Array.isArray(t))return!1;const r=Object.keys(e),n=Object.keys(t);return r.length!==n.length?!1:r.every(i=>Z4(e[i],t[i]))}function MA(e,t){const r={};for(const n of e){const i=n.members.map(l=>OA(t,[l,n.name])),s=i.filter(l=>l!==void 0);if(s.length===0){r[n.name]={};continue}if(s.length<i.length)return null;const[a,...o]=s;if(!o.every(l=>Z4(l,a)))return null;r[n.name]=dl(a)}return{fields:r}}function g_(e,t){const r={},n={};for(const i of e){const a=i.members.map(c=>[c,OA(t,[c,i.name])]).filter(c=>c[1]!==void 0);if(a.length===0){r[i.name]={};continue}const[[,o],...l]=a,u=l.filter(([,c])=>!Z4(c,o)).map(([c])=>c);u.length>0&&(n[i.name]=u),r[i.name]=dl(o)}return{selection:{fields:r},overwritten:n}}function YU(e,t){if(MA(e,t)!==null)return;const{selection:r,overwritten:n}=g_(e,t);return{input:b_(e,r),overwritten:n}}function b_(e,t){const r={};for(const i of e){const s=Gi(t.fields[i.name]);if(s)for(const a of i.members)r[a]??(r[a]={}),r[a][i.name]=s}const n={};for(const[i,s]of Object.entries(r))n[i]={kind:"object",properties:s};return Object.keys(n).length>0?{kind:"object",properties:n}:void 0}function KU(e,t,r,n){return r||(t&&MA(e,t)===null?"expanded":n??"expanded")}function XU(e){return"__group"in e}function QU(e,t){const r=t instanceof Set?t:new Set(t),n=new Map;for(const o of e){if(o.parent===void 0)continue;const l=n.get(o.parent);l?l.push(o):n.set(o.parent,[o])}const i=[];for(const o of e){if(o.parent!==void 0)continue;const l=ZU(o,n.get(o.uri)??[],r);l&&i.push({group:o.group??[],node:l})}const s=JU(i),[a]=s;return s.length===1&&a.kind==="group"&&a.label===G4?a.children??[]:s}function Ff(e,...t){return[...e,...t].join(" / ")}function jA(e,t){return`${e} → ${t}`}function ZU(e,t,r){const n=e.group??[],i=Ff(n,e.label),s=r.has(e.uri),a=t.filter(u=>r.has(u.uri)),o=u=>({kind:"output",uri:u.uri,label:u.label,breadcrumb:Ff(n,e.label,u.label)});if(!s){if(a.length===0)return null;if(a.length===1){const u=a[0];return{kind:"output",uri:u.uri,label:jA(e.label,u.label),breadcrumb:Ff(n,e.label,u.label)}}return{kind:"resource",label:e.label,breadcrumb:i,children:a.map(o)}}if(a.length===0)return{kind:"resource",uri:e.uri,label:e.label,breadcrumb:i};const l={kind:"resource",uri:e.uri,label:e.label,breadcrumb:i};return{kind:"resource",uri:e.uri,label:e.label,breadcrumb:i,children:[l,...a.map(o)]}}function JU(e){const t=[],r=new Map;for(const{group:n,node:i}of e){let s=t,a="";const o=[];for(const l of n){a=a?`${a}/${l}`:l,o.push(l);let u=r.get(a);u||(u={__group:!0,label:l,breadcrumb:Ff(o),children:[]},r.set(a,u),s.push(u)),s=u.children}s.push(i)}return BA(t)}function BA(e){const t=[];for(const r of e){if(!XU(r)){t.push(r);continue}const n=BA(r.children);n.length!==0&&(n.length===1&&r.label!==G4?t.push(n[0]):t.push({kind:"group",label:r.label,breadcrumb:r.breadcrumb,children:n}))}return t}function eV(e){const t=[],r=n=>{for(const i of n)i.uri!==void 0&&t.push(i),i.children&&r(i.children)};return r(e),t}const tV=8,Qx='[role="menuitem"]',Ug=8;function PA({resources:e,matching:t,chosen:r,stale:n,editable:i,label:s,onChoose:a,triggerLabel:o}){const[l,u]=w.useState(!1),[c,d]=w.useState(""),m=()=>{u(!1),d("")},f=C=>{a(C),m()},{triggerRef:p,popoverRef:g,style:y}=Fi({open:l,onClose:m,matchTriggerWidth:!1,extraContains:C=>{var L;return!!((L=C.closest)!=null&&L.call(C,".pg-source-menu-flyout"))}}),b=w.useMemo(()=>QU(e,t.map(C=>C.uri)),[e,t]),v=w.useMemo(()=>eV(b),[b]),x=v.length>=tV,E=x&&c.trim()?v.filter(C=>C.breadcrumb.toLowerCase().includes(c.trim().toLowerCase())):void 0,T=o?void 0:i?"custom":r?void 0:"placeholder";return h.jsxs("div",{className:"pg-source-picker",children:[h.jsx("button",{ref:p,type:"button",className:o?"pg-resources-add":"pg-slot-source-wrap","aria-haspopup":"menu","aria-expanded":l,"aria-label":o?void 0:`Source for ${s}`,title:o?void 0:"Pick a resource",onClick:()=>u(C=>!C),children:o??h.jsx("span",{className:"pg-slot-source-icon","aria-hidden":"true",children:"⋯"})}),l&&cn.createPortal(h.jsxs("div",{ref:g,className:"pg-source-menu-root",style:y,children:[x&&h.jsx("input",{type:"text",className:"pg-source-menu-filter",placeholder:"Filter…",value:c,onChange:C=>d(C.target.value),autoFocus:!0}),E?h.jsx(rV,{nodes:E,chosen:r,onChoose:f}):h.jsx(zA,{nodes:b,chosen:r,headerKind:T,stale:n,onChoose:f,depth:0,autoFocusFirst:!x})]}),document.body)]})}function rV({nodes:e,chosen:t,onChoose:r}){return h.jsxs("div",{className:"pg-source-menu",role:"menu",children:[e.length===0&&h.jsx("div",{className:"pg-source-menu-empty",children:"No matches"}),e.map(n=>h.jsxs("button",{type:"button",role:"menuitem",className:"pg-source-menu-item"+(n.uri===t?" selected":""),title:n.breadcrumb,onClick:()=>r(n.uri),children:[h.jsx("span",{className:"pg-source-menu-check",children:n.uri===t?"✓":""}),h.jsx("span",{className:"pg-source-menu-label",children:n.label}),h.jsx("span",{className:"pg-source-menu-breadcrumb",children:n.breadcrumb})]},n.uri))]})}function zA({nodes:e,chosen:t,headerKind:r,stale:n,onChoose:i,depth:s,onLeaveLevel:a,autoFocusFirst:o}){const[l,u]=w.useState(null),c=w.useRef(null);w.useEffect(()=>{var f,p;o&&((p=(f=c.current)==null?void 0:f.querySelector(Qx))==null||p.focus())},[]);const d=f=>{var v;const p=c.current;if(!p)return;const g=Array.from(p.querySelectorAll(Qx));if(g.length===0)return;const y=g.indexOf(document.activeElement),b=y<0?0:(y+f+g.length)%g.length;(v=g[b])==null||v.focus()},m=f=>{if(l===null)switch(f.key){case"ArrowDown":f.preventDefault(),d(1);break;case"ArrowUp":f.preventDefault(),d(-1);break;case"ArrowLeft":s>0&&(f.preventDefault(),a==null||a());break;case"Escape":s>0&&(f.preventDefault(),f.stopPropagation(),a==null||a());break}};return h.jsxs("div",{className:"pg-source-menu",role:"menu",ref:c,onKeyDown:m,children:[r==="custom"&&h.jsx(Zx,{label:"Custom",selected:!t,onClick:()=>i(null)}),r==="placeholder"&&h.jsx("div",{className:"pg-source-menu-placeholder",children:"Pick a resource…"}),e.length===0&&!r&&!n&&h.jsx("div",{className:"pg-source-menu-empty",children:"No sources available"}),e.map((f,p)=>h.jsx(nV,{node:f,chosen:t,open:l===p,onOpen:()=>u(p),onClose:()=>u(null),onChoose:i,depth:s},f.uri??`group-${p}-${f.label}`)),n&&h.jsx(Zx,{label:`${n} (unavailable)`,selected:!0,muted:!0,onClick:()=>i(n)})]})}function Zx({label:e,selected:t,muted:r,onClick:n}){return h.jsxs("button",{type:"button",role:"menuitem",className:"pg-source-menu-item"+(t?" selected":"")+(r?" muted":""),onClick:n,children:[h.jsx("span",{className:"pg-source-menu-check",children:t?"✓":""}),h.jsx("span",{className:"pg-source-menu-label",children:e})]})}function nV({node:e,chosen:t,open:r,onOpen:n,onClose:i,onChoose:s,depth:a}){const o=w.useRef(null),l=w.useRef(null),[u,c]=w.useState({}),d=!!e.children&&e.children.length>0,m=!!e.uri&&e.uri===t,f=()=>{var b;if(!d)return;const y=(b=o.current)==null?void 0:b.getBoundingClientRect();if(y){const v=y.right+220>window.innerWidth;c({position:"fixed",top:y.top,maxHeight:window.innerHeight-2*Ug,overflowY:"auto",...v?{right:window.innerWidth-y.left}:{left:y.right},zIndex:1e4+a})}n()};w.useLayoutEffect(()=>{const y=l.current,b=u.top;if(!r||!y||typeof b!="number")return;const v=Math.max(Ug,Math.min(b,window.innerHeight-Ug-y.getBoundingClientRect().height));v!==b&&c({...u,top:v})},[r,u]);const p=()=>{d?f():e.uri&&s(e.uri)},g=y=>{y.key==="ArrowRight"&&d?(y.preventDefault(),f()):y.key==="Enter"&&(y.preventDefault(),p())};return h.jsxs("div",{className:"pg-source-menu-row-wrap",onMouseEnter:d?f:void 0,children:[h.jsxs("button",{ref:o,type:"button",role:"menuitem",className:"pg-source-menu-item"+(m?" selected":""),title:e.breadcrumb,"aria-haspopup":d?"menu":void 0,"aria-expanded":d?r:void 0,onClick:p,onKeyDown:g,children:[h.jsx("span",{className:"pg-source-menu-check",children:m?"✓":""}),h.jsx("span",{className:"pg-source-menu-label",children:e.label}),d&&h.jsx("span",{className:"pg-source-menu-caret","aria-hidden":"true",children:"▸"})]}),d&&r&&cn.createPortal(h.jsx("div",{ref:l,className:"pg-source-menu-flyout",style:u,children:h.jsx(zA,{nodes:e.children,chosen:t,onChoose:s,depth:a+1,autoFocusFirst:!0,onLeaveLevel:()=>{var y;i(),(y=o.current)==null||y.focus()}})}),document.body)]})}function Jx(e,t){if(!e.parent)return e.label;const r=t.get(e.parent);return r?jA(r.label,e.label):e.label}function iV(){}function eS({propDef:e,resources:t,matching:r,chosen:n,onChoose:i,context:s,children:a}){var f;const o=e.type.kind!=="opaque",l=n?r.find(p=>p.uri===n):void 0,u=n&&K4(n)?((f=s==null?void 0:s.describePseudo)==null?void 0:f.call(s,n,e.type))??{note:""}:void 0,c=n&&!l&&!(u!=null&&u.label)?n:void 0,d=w.useMemo(()=>new Map(t.map(p=>[p.uri,p])),[t]);if(r.length===0&&!c&&!u&&o)return h.jsx(h.Fragment,{children:a});const m=u?u.label??(l?Jx(l,d):void 0):void 0;return h.jsxs("div",{className:"pg-slot",children:[h.jsx("div",{className:"pg-slot-body",children:o&&(l==null?void 0:l.value)!==void 0?h.jsx("div",{className:"pg-slot-preview",title:l.uri,children:h.jsx(Ir,{propDef:e,value:$m(l.value),onChange:iV,disabled:!0})}):u&&m!==void 0?h.jsxs("span",{className:"pg-slot-chip pg-slot-chip-pseudo"+(u.warning||u.missing?" pg-slot-chip-warning":""),title:u.warning?`Type mismatch: ${u.warning}`:void 0,children:[u.onOpen?h.jsxs("button",{type:"button",className:"pg-slot-instance-link",title:"Show this resource",onClick:u.onOpen,children:["◆ ",m]}):m,(u.warning||u.note)&&h.jsx("em",{className:"pg-slot-chip-note",children:u.warning?`⚠ ${u.warning}`:u.note})]}):l?h.jsxs("span",{className:"pg-slot-chip",title:l.uri,children:[Jx(l,d),h.jsx("em",{className:"pg-slot-chip-note",children:l.scope==="server"?"created once per server":"created for each run"})]}):c?h.jsx("div",{className:"pg-slot-hint",children:h.jsx("span",{children:"Resource no longer available"})}):o?a:h.jsxs("div",{className:"pg-slot-hint",children:[h.jsx("span",{children:"No editor for this type"}),h.jsx("a",{className:"pg-slot-hint-help",href:"https://example.com/docs/opaque-types",target:"_blank",rel:"noreferrer","aria-label":"Learn more about opaque types",children:"?"})]})}),(r.length>0||c||u)&&h.jsx(PA,{resources:t,matching:r,chosen:n,stale:c,editable:o,label:e.name,onChoose:i})]})}function J4({propDef:e,selection:t,onChange:r,resources:n,slots:i,context:s}){var f;const a=w.useMemo(()=>new Map(n.map(p=>[p.uri,p])),[n]),o=w.useRef(t);o.current=t;const l=w.useRef(r);l.current=r;const u=w.useRef(s);u.current=s;const c=w.useCallback((p,g)=>{var E;const y=o.current,b={...y.resources??{}},v=(E=u.current)==null?void 0:E.adopt,x=g&&!K4(g)&&v?v(g):g;x?b[p]=x:delete b[p],l.current({...y,resources:b})},[]),d=w.useMemo(()=>{const p=new Set(Object.keys(i).filter(y=>y!==e.name));return[{match:(y,b)=>y.kind==="opaque"||p.has($A(e.name,b)),component:y=>{var E;const b=sV(y.path),v=y.path,x=d.map(T=>({...T,match:(C,L)=>L!==v&&T.match(C,L)}));return h.jsx(eS,{propDef:y.propDef,resources:n,matching:tS(i,e.name,y.path,a),chosen:(E=o.current.resources)==null?void 0:E[b],onChoose:T=>c(b,T),context:u.current,children:h.jsx(Ir,{propDef:y.propDef,value:y.value,onChange:y.onChange,plugins:x,path:y.path})})}}]},[i,e.name,a,c,n]),m=tS(i,e.name,[e.name],a);return h.jsx(eS,{propDef:e,resources:n,matching:m,chosen:(f=t.resources)==null?void 0:f[hl],onChoose:p=>c(hl,p),context:s,children:h.jsx(Ir,{propDef:e,value:t.value,onChange:p=>r({...t,value:p}),plugins:d,path:[e.name]})})}function $A(e,t){return(t??[e]).join(".")}function sV(e){return(e??[]).slice(1).join(".")}function tS(e,t,r,n){return(e[$A(t,r)]??[]).map(s=>n.get(s)).filter(s=>!!s&&!s.error)}function aV(e){return((e==null?void 0:e.resources)??[]).filter(t=>!!t.error)}function oV({propDef:e,groups:t,selection:r,onChange:n,resources:i,slots:s,overwritten:a,context:o}){const l=GU(t);return h.jsx(h.Fragment,{children:t.map(u=>{const c={name:u.name,type:u.type,optional:u.optional},d=uV(s,e.name,u),m=(a==null?void 0:a[u.name])??[];return h.jsxs("div",{className:"pg-exec-param pg-combined-row",children:[h.jsxs("div",{className:"pg-exec-param-label",children:[h.jsxs("span",{className:"pg-exec-param-name",children:[u.name,u.optional?"":" *"]}),h.jsx("span",{className:"pg-exec-param-type",title:u.type.syntax,children:bd(u.type.syntax,60)}),h.jsx("span",{className:"pg-combined-members",children:lV(u,l)})]}),m.length>0&&h.jsxs("div",{className:"pg-combined-note",children:["Overwrote ",m.join(", ")]}),d.length>0&&h.jsxs("div",{className:"pg-combined-note",children:[d.length===1?"A matching resource is":`${d.length} matching resources are`," ","pinned to only some members and isn't offered here."]}),h.jsx(J4,{propDef:c,selection:r.fields[u.name]??{},onChange:f=>n({fields:{...r.fields,[u.name]:f}}),resources:i,slots:cV(s,e.name,u),context:o})]},u.name)})})}function lV(e,t){return e.members.length===t?`all ${t}`:e.members.join(", ")}function HA(e,t,r){const n=r.members.map(a=>new Set(e[`${t}.${a}.${r.name}`]??[])),[i,...s]=n;return i?[...i].filter(a=>s.every(o=>o.has(a))):[]}function uV(e,t,r){const n=new Set(r.members.flatMap(s=>e[`${t}.${s}.${r.name}`]??[])),i=new Set(HA(e,t,r));return[...n].filter(s=>!i.has(s))}function cV(e,t,r){const n=r.members[0],i=`${t}.${n}.`,s=`${i}${r.name}`,a={};for(const[o,l]of Object.entries(e))(o===s||o.startsWith(`${s}.`))&&(a[o.slice(i.length)]=l);return a[r.name]=HA(e,t,r),a}function hV(e){const t=Object.entries(e);if(t.length!==0)return Object.fromEntries(t.map(([r,{uri:n,args:i}])=>{const s=Object.fromEntries(Object.entries(i).flatMap(([a,o])=>{const l=Gi(o);return l?[[a,l]]:[]}));return[r,Object.keys(s).length>0?{uri:n,args:s}:{uri:n}]}))}function FA(e){if(!e||typeof e!="object")return{};const t={};for(const[r,n]of Object.entries(e))!n||typeof n.uri!="string"||(t[r]={uri:n.uri,args:Object.fromEntries(Object.entries(n.args??{}).map(([i,s])=>[i,dl(s)]))});return t}function UA(e,t){const r=new Set(t);let i=(e.slice(e.lastIndexOf("#")+1).split(".")[0]??"").replace(/[^A-Za-z0-9_-]/g,"_");if(dA(i)||(i=`r_${i}`),!r.has(i))return i;for(let s=2;;s++)if(!r.has(`${i}${s}`))return`${i}${s}`}function VA(e,t){const r=UA(t,Object.keys(e));return{instances:{...e,[r]:{uri:t,args:{}}},name:r}}function dV(e,t,r){var o;const n=r.get(t),i=(n==null?void 0:n.parent)??t,s=n!=null&&n.parent?t.slice(n.parent.length+1):void 0;if(((o=r.get(i))==null?void 0:o.scope)==="server"){const l=Object.entries(e).find(([,u])=>u.uri===i);if(l)return{instances:e,uri:oa(l[0],s)}}const a=VA(e,i);return{instances:a.instances,uri:oa(a.name,s)}}function fV(e,t,r){if(!e.resources)return e;let n=!1;const i={};for(const[s,a]of Object.entries(e.resources)){const o=Bl(a);if((o==null?void 0:o.name)!==t){i[s]=a;continue}n=!0,r!==null&&(i[s]=oa(r,o.output))}return n?Object.keys(i).length>0?{...e,resources:i}:(({resources:s,...a})=>a)(e):e}function Gm(e,t,r){let n=!1;const i={};for(const[s,a]of Object.entries(e)){const o=fV(a,t,r);o!==a&&(n=!0),i[s]=o}return n?i:e}function mV(e,t,r){if(t===r)return e;const n=qA(r,e,t);if(n)throw new Error(n);return Object.fromEntries(Object.entries(e).map(([i,s])=>[i===t?r:i,{...s,args:Gm(s.args,t,r)}]))}function qA(e,t,r){if(!dA(e))return"Use letters, digits, '_' and '-', not starting with a digit or '-'.";if(e!==r&&Object.hasOwn(t,e))return`There's already a resource named '${e}'.`}function pV(e,t){return Object.fromEntries(Object.entries(e).filter(([r])=>r!==t).map(([r,n])=>[r,{...n,args:Gm(n.args,t,null)}]))}function gV(e,t){const r=e[t];if(!r)return{instances:e,name:t};const n=UA(t.replace(/\d+$/,"")||t,Object.keys(e)),i={};for(const[s,a]of Object.entries(e))i[s]=a,s===t&&(i[n]={uri:r.uri,args:structuredClone(r.args)});return{instances:i,name:n}}function rS(e,t,r){return Object.entries((e==null?void 0:e.resources)??{}).flatMap(([n,i])=>{var s;return((s=Bl(i))==null?void 0:s.name)===t?[n===""?r:`${r}.${n}`]:[]})}function bV(e,t,r){const n=[];for(const{prefix:i,selections:s}of r)for(const[a,o]of Object.entries(s))n.push(...rS(o,e,i?`${i}.${a}`:a));for(const[i,s]of Object.entries(t))if(i!==e)for(const[a,o]of Object.entries(s.args))n.push(...rS(o,e,`${i}.${a}`));return n}function _V(e){const t=new Set;for(const r of Object.values(e.args))for(const n of Object.values(r.resources??{})){const i=Bl(n);i&&t.add(i.name)}return t}function vV(e,t){const r=new Set([t]);let n=!0;for(;n;){n=!1;for(const[i,s]of Object.entries(e))r.has(i)||[..._V(s)].some(a=>r.has(a))&&(r.add(i),n=!0)}return r}function yV(e,t){const r=new Map;for(const[s,a]of Object.entries(e))r.set(a.uri,[...r.get(a.uri)??[],s]);const n=new Map,i=(s,a,o)=>{var l,u;for(const c of Object.values(((l=t.get(s))==null?void 0:l.dependencies)??{})){const d=r.get(c)??[];if(d.length===1)continue;let m=n.get(c);m||(m={uri:c,usedBy:[],...d.length>1&&{ambiguous:d}},n.set(c,m)),m.usedBy.includes(a)||m.usedBy.push(a),d.length===0&&!o.has(c)&&i(c,((u=t.get(c))==null?void 0:u.label)??c,new Set([...o,c]))}};for(const[s,a]of Object.entries(e))i(a.uri,s,new Set([a.uri]));return[...n.values()]}const xV=1200;function SV(e,t){e.scrollIntoView({behavior:"smooth",block:t}),e.classList.remove("pg-row-highlight"),e.offsetWidth,e.classList.add("pg-row-highlight"),window.setTimeout(()=>e.classList.remove("pg-row-highlight"),xV)}function GA(e){const t=document.querySelector(`[data-instance-card="${CSS.escape(e)}"]`);t&&SV(t,"center")}function wV({instances:e,onChange:t,sources:r,catalog:n,referencedBy:i,context:s}){const a=w.useMemo(()=>new Map(n.map(f=>[f.uri,f])),[n]),o=Object.entries(e),l=yV(e,a),u=n.filter(f=>!f.parent&&!f.error&&!((f.scope==="server"||f.value!==void 0)&&o.some(([,p])=>p.uri===f.uri))),c=w.useRef(null);w.useEffect(()=>{const f=c.current;f===null||!Object.hasOwn(e,f)||(c.current=null,GA(f))},[e]);const d=f=>{c.current=f.name,t(f.instances)},m=f=>{f&&d(VA(e,f))};return h.jsxs("section",{className:"pg-resources","aria-label":"Resources",children:[h.jsxs("div",{className:"pg-resources-header",children:[h.jsx("span",{className:"pg-resources-title",children:"Resources"}),u.length>0&&h.jsx(PA,{resources:n,matching:u,chosen:void 0,stale:void 0,editable:!1,label:"Resources",triggerLabel:"+ Add resource",onChoose:m})]}),o.map(([f,p])=>h.jsx(kV,{name:f,instances:e,resource:a.get(p.uri),onChange:t,onDuplicate:()=>d(gV(e,f)),sources:r,referencedBy:i(f),context:s},f)),l.map(f=>{const p=a.get(f.uri);return h.jsxs("div",{className:"pg-resource-card pg-resource-dependency",children:[h.jsxs("div",{className:"pg-resource-head",children:[h.jsxs("span",{className:"pg-resource-name",children:["◆ ",(p==null?void 0:p.label)??f.uri]}),h.jsxs("span",{className:"pg-resource-meta",children:[WA(p)," · dependency"]}),!f.ambiguous&&h.jsx("button",{type:"button",className:"pg-resource-action","aria-label":`Add ${(p==null?void 0:p.label)??f.uri} to the run explicitly`,title:"Add to the run explicitly (to set arguments or a name)",onClick:()=>m(f.uri),children:h.jsx(Zd,{})})]}),h.jsx("div",{className:"pg-resource-refs"+(f.ambiguous?" pg-resource-refs-warning":""),children:f.ambiguous?`⚠ ${f.usedBy.join(", ")} can't tell which to use: ${f.ambiguous.join(", ")}`:`implicit instance for ${f.usedBy.join(", ")}`})]},f.uri)})]})}function WA(e){return(e==null?void 0:e.scope)==="server"?"shared":"per run"}function EV(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[h.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),h.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function kV({name:e,instances:t,resource:r,onChange:n,onDuplicate:i,sources:s,referencedBy:a,context:o}){var L;const l=t[e],[u,c]=w.useState(null),[d,m]=w.useState(!1),f=()=>m(!1),{triggerRef:p,popoverRef:g,style:y}=Fi({open:d,onClose:f,matchTriggerWidth:!1}),b=u===null?void 0:qA(u,t,e),v=()=>{u!==null&&(!b&&u!==e&&n(mV(t,e,u),{kind:"rename",from:e,to:u}),c(null))},x=()=>{a.length>0&&!window.confirm(`Remove '${e}'? ${a.join(", ")} will be cleared.`)||n(pV(t,e),{kind:"remove",name:e})},E=vV(t,e),T=Object.fromEntries(Object.entries(((L=s.resourceSlots)==null?void 0:L[l.uri])??{}).map(([A,z])=>[A,z.filter(I=>{const B=Bl(I);return!B||!E.has(B.name)})])),C=(r==null?void 0:r.parameters)??[];return h.jsxs("div",{className:"pg-resource-card","data-instance-card":e,children:[h.jsxs("div",{className:"pg-resource-head",children:[u===null?h.jsxs("button",{type:"button",className:"pg-resource-name pg-resource-rename",title:"Rename",onClick:()=>c(e),children:["◆ ",e," ",h.jsx("span",{"aria-hidden":"true",children:"✎"})]}):h.jsx("input",{className:"pg-resource-name-input","aria-label":`Name for ${e}`,"aria-invalid":!!b,title:b,value:u,autoFocus:!0,onChange:A=>c(A.target.value),onBlur:v,onKeyDown:A=>{A.key==="Enter"&&v(),A.key==="Escape"&&c(null)}}),h.jsxs("span",{className:"pg-resource-meta",title:l.uri,children:[r?r.label:"Resource no longer available",r&&` · ${WA(r)}`]}),h.jsxs("span",{className:"pg-resource-actions",children:[h.jsx("button",{type:"button",ref:p,className:"pg-resource-action pg-resource-menu-trigger","aria-label":`Actions for ${e}`,"aria-haspopup":"menu","aria-expanded":d,title:"Actions",onClick:()=>m(A=>!A),children:h.jsx(EV,{})}),d&&cn.createPortal(h.jsxs("div",{className:"trace-header-menu",ref:g,style:y,role:"menu",children:[(r==null?void 0:r.scope)!=="server"&&h.jsx("button",{type:"button",role:"menuitem",className:"trace-header-menu-item",onClick:()=>{f(),i()},children:h.jsx("span",{className:"trace-header-menu-item-label",children:"Duplicate"})}),h.jsx("button",{type:"button",role:"menuitem",className:"trace-header-menu-item","aria-label":`Remove ${e}`,onClick:()=>{f(),x()},children:h.jsx("span",{className:"trace-header-menu-item-label",children:"Remove"})})]}),document.body)]})]}),b&&h.jsx("div",{className:"pg-resource-refs-warning",children:b}),h.jsx("div",{className:"pg-resource-refs",children:a.length>0?`→ ${a.join(", ")}`:"not bound to a slot: runs for its side effects"}),C.length>0&&h.jsx("div",{className:"pg-args-form",children:C.map(A=>h.jsxs("div",{className:"pg-args-row",children:[h.jsx("span",{className:"pg-args-name",children:A.name}),A.description&&h.jsx("div",{className:"pg-exec-param-desc",children:A.description}),h.jsx(J4,{propDef:A,selection:l.args[A.name]??{},onChange:z=>n(I=>{const B=I[e];return B?{...I,[e]:{...B,args:{...B.args,[A.name]:z}}}:I}),resources:s.resources,slots:T,context:o})]},A.name))})]})}function CV({instances:e,catalogByUri:t,adopt:r,describeOther:n,rowsMayDeclare:i}){return{adopt:r,describePseudo:(s,a)=>{const o=UU(s,e,t,{rowsMayDeclare:i});if(!o)return n==null?void 0:n(s,a);const l=Bl(s),u=Object.hasOwn(e,l.name);return{...o,...u&&{onOpen:()=>GA(l.name)}}}}}function TV(e,t,r){const[n,i]=w.useState(e),s=w.useRef(n),a=w.useRef(t);a.current=t;const o=w.useRef(r);o.current=r;const l=w.useCallback(c=>{var m;const d=typeof c=="function"?c(s.current):c;d!==s.current&&(s.current=d,i(d),(m=o.current)==null||m.call(o,d))},[]),u=w.useCallback(c=>{const d=dV(s.current,c,a.current);return l(d.instances),d.uri},[l]);return{instances:n,setInstances:l,adopt:u}}const nS=new Set;function AV({name:e,reason:t}){return h.jsxs(h.Fragment,{children:[h.jsx("code",{children:e}),t==="resource-out-of-scope"?" uses a resource this prompt can't see":" has no matching parameter"]})}const NV=[],RV=[];function iS(e,t){return Object.fromEntries(e.flatMap(r=>{const n=Gi(t[r.name]);return n?[[r.name,n]]:[]}))}function Wm(e={}){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,dl(r)]))}function LV(e){var r,n;const t={fn:{},exec:{},layout:{fn:{},exec:{}},instances:{}};try{const i=localStorage.getItem(Q4(e));if(!i)return t;const s=JSON.parse(i);return!s||typeof s!="object"?t:{fn:Wm(s.functionInputs),exec:Wm(s.executeInputs),layout:{fn:((r=s.layout)==null?void 0:r.functionSlots)??{},exec:((n=s.layout)==null?void 0:n.executeSlots)??{}},instances:FA(s.resources)}}catch{return t}}function F0(e,t,r,n){const i={...e[t]};return n===void 0?delete i[r]:i[r]=n,{...e,[t]:i}}function IV({prompt:e,promptRef:t,runDisabledReason:r,onExecuted:n,fill:i,onOpenFillSource:s,onOpenDataset:a}){var Pe;const o=w.useState(()=>LV(e))[0],[l,u]=w.useState(o.fn),[c,d]=w.useState(o.exec),[m,f]=w.useState(o.layout),[p,g]=w.useState({fn:{},exec:{}}),[y,b]=w.useState(!1),[v,x]=w.useState(null),[E,T]=w.useState(null),C=e.executeParameters??NV,L=aV(e.inputSources),A=((Pe=e.inputSources)==null?void 0:Pe.resources)??RV,z=w.useMemo(()=>new Map(A.map(ee=>[ee.uri,ee])),[A]),{instances:I,setInstances:B,adopt:j}=TV(o.instances,z),G=w.useMemo(()=>{const ee=hV(I);return{functionInputs:iS(e.functionParameters,l),executeInputs:iS(C,c),...ee&&{resources:ee}}},[e.functionParameters,C,l,c,I]),W=AA(PU(FU(e.inputSources,I),{functionParameters:e.functionParameters,executeParameters:C,bindings:G}));w.useEffect(()=>{try{localStorage.setItem(Q4(e),JSON.stringify({functionInputs:G.functionInputs,executeInputs:G.executeInputs,...G.resources&&{resources:G.resources},layout:{functionSlots:m.fn,executeSlots:m.exec}}))}catch{}},[G,m]);const Y=ee=>(oe,Be)=>{const we=ee==="fn"?{...l,[oe]:Be}:l,_e=ee==="exec"?{...c,[oe]:Be}:c;u(we),d(_e)},V=(ee,oe)=>{if(B(ee),!oe)return;const[Be,we]=oe.kind==="rename"?[oe.from,oe.to]:[oe.name,null];u(_e=>Gm(_e,Be,we)),d(_e=>Gm(_e,Be,we))},X=CV({instances:I,catalogByUri:z,adopt:j,describeOther:(ee,oe)=>zU(ee,oe,{functionParameters:e.functionParameters,executeParameters:C})}),P=(ee,oe,Be)=>{var je,Ke,Le;const we=ee==="fn"?l:c,_e=(Le=ee==="fn"?(je=e.inputLayout)==null?void 0:je.functionSlots:(Ke=e.inputLayout)==null?void 0:Ke.executeSlots)==null?void 0:Le[oe.name];return KU(Be,Gi(we[oe.name]),m[ee][oe.name],_e)};w.useEffect(()=>{const ee=(we,_e,je)=>{let Ke=je;for(const Le of _e){const it=Kx(Le);if(!Xx(it)||P(we,Le,it)!=="combined")continue;const zt=YU(it,Gi(je[Le.name]));zt&&(Ke={...Ke,[Le.name]:dl(zt.input)},g(ot=>F0(ot,we,Le.name,zt.overwritten)))}return Ke},oe=ee("fn",e.functionParameters,l),Be=ee("exec",C,c);oe!==l&&u(oe),Be!==c&&d(Be)},[l,c,m,e]);const re=(ee,oe,Be,we)=>{let _e=l,je=c;if(we==="combined"){const Le=Gi((ee==="fn"?_e:je)[oe.name]),{selection:it,overwritten:zt}=g_(Be,Le),ot=dl(b_(Be,it));ee==="fn"?_e={..._e,[oe.name]:ot}:je={...je,[oe.name]:ot},u(_e),d(je),g(Br=>F0(Br,ee,oe.name,zt))}else g(Ke=>F0(Ke,ee,oe.name,void 0));f(F0(m,ee,oe.name,we))},R=({requireAll:ee})=>{const oe={};for(const we of e.functionParameters){const _e=Gi(l[we.name]);_e&&(oe[we.name]=_e);const je=ee&&(_e||!we.optional&&we.defaultValue===void 0)&&Yx(we,_e,!!e.inputSources);if(je)return x(je),null}const Be={};for(const we of C){const _e=Gi(c[we.name]);_e&&(Be[we.name]=_e);const je=ee&&(_e||!we.optional)&&Yx(we,_e,!!e.inputSources);if(je)return x(je),null}return{functionInputs:oe,executeInputs:Be,...G.resources&&{resources:G.resources}}},de=()=>{const ee=R({requireAll:!0});return ee?{functionInputs:e.functionParameters.map(Be=>ee.functionInputs[Be.name]??(Be.defaultValue?{kind:"value",value:Be.defaultValue}:{kind:"value",value:{kind:"primitive",value:void 0}})),executeInputs:ee.executeInputs,...ee.resources&&{resources:ee.resources}}:null};w.useEffect(()=>{if(!i||nS.has(i.nonce))return;nS.add(i.nonce);const ee=[...e.functionParameters.filter(oe=>!(oe.name in i.functionInputs)&&Gi(l[oe.name])).map(oe=>oe.name),...C.filter(oe=>!(oe.name in i.executeInputs)&&Gi(c[oe.name])).map(oe=>oe.name)];if(u({...l,...Wm(i.functionInputs)}),d({...c,...Wm(i.executeInputs)}),i.resources){const oe=FA(i.resources);B(Be=>({...Be,...oe}))}T({from:i.from,kept:ee,skipped:i.skipped})},[i==null?void 0:i.nonce]);const Te=PF(e,R({requireAll:!1})??{functionInputs:{},executeInputs:{}}),H=async()=>{x(null);const ee=de();if(ee){b(!0);try{const oe=await SH(e,ee,t);n==null||n({...oe,label:e.name})}catch(oe){x(oe.message)}finally{b(!1)}}},Oe=(ee,oe,Be,we)=>ee.map(_e=>{const je=Kx(_e),Ke=Xx(je),Le=Ke?P(we,_e,je):"expanded";return h.jsxs("div",{className:"pg-exec-param",children:[h.jsxs("div",{className:"pg-exec-param-label",children:[h.jsxs("span",{className:"pg-exec-param-name",children:[_e.name,_e.optional?"":" *"]}),h.jsx("span",{className:"pg-exec-param-type",title:_e.type.syntax,children:bd(_e.type.syntax,60)})]}),_e.description&&h.jsx("div",{className:"pg-exec-param-desc",children:_e.description}),Ke&&h.jsx("div",{className:"pg-combined-toggle",children:h.jsx("div",{className:"pg-layout-tabs",role:"tablist","aria-label":`Layout for ${_e.name}`,children:["expanded","combined"].map(it=>h.jsx("button",{type:"button",role:"tab","aria-selected":Le===it,className:`pg-layout-tab${Le===it?" pg-layout-tab-active":""}`,onClick:()=>re(we,_e,je,it),children:it==="expanded"?"Expanded":"Combined"},it))})}),Le==="combined"?h.jsx(oV,{propDef:_e,groups:je,selection:g_(je,Gi(oe[_e.name])).selection,onChange:it=>Y(we)(_e.name,dl(b_(je,it))),resources:(W==null?void 0:W.resources)??[],slots:Be,overwritten:p[we][_e.name],context:X}):h.jsx(J4,{propDef:_e,selection:oe[_e.name]??{},onChange:it=>Y(we)(_e.name,it),resources:(W==null?void 0:W.resources)??[],slots:Be,context:X})]},_e.name)});return h.jsxs(sU,{title:"Execute",actions:e.providerId&&h.jsx(d_,{inputs:Te,resources:G.resources,newDatasetFields:C9(e),prompt:{link:{id:e.globalId??e.id,providerId:e.providerId},openable:{id:e.id,providerId:e.providerId}},source:{kind:"playground",promptId:e.id,providerId:e.providerId},disabled:Te.length===0,onOpenDataset:a}),error:v,onDismissError:()=>x(null),footer:h.jsx("button",{type:"button",className:"pg-run-btn",onClick:H,disabled:y||!!r,title:r,children:y?"…":"▶ Run"}),children:[E&&h.jsxs("div",{className:"pg-exec-fill-notice",role:"status",children:[h.jsxs("span",{children:["Filled from"," ",s?h.jsxs("button",{type:"button",className:"pg-exec-fill-link",onClick:ee=>{ee.stopPropagation(),s(E.from)},title:E.from.description,children:[E.from.type," ↗"]}):E.from.type,E.kept.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("br",{}),"Not filled: ",E.kept.map((ee,oe)=>h.jsxs("span",{children:[oe>0&&", ",h.jsx("code",{children:ee})]},ee))]})]}),E.skipped.map(ee=>h.jsx("span",{className:"pg-exec-fill-skipped",children:AV(ee)},ee.name)),h.jsx("button",{type:"button",className:"pg-dismiss","aria-label":"Dismiss",onClick:()=>T(null),children:"×"})]}),Oe(e.functionParameters,l,(W==null?void 0:W.functionSlots)??{},"fn"),C.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"pg-exec-section"}),Oe(C,c,(W==null?void 0:W.executeSlots)??{},"exec")]}),(A.length>0||Object.keys(I).length>0)&&h.jsx(wV,{instances:I,onChange:V,sources:W,catalog:A,referencedBy:ee=>bV(ee,I,[{selections:l},{selections:c}]),context:X}),L.map(ee=>h.jsxs("div",{className:"pg-exec-error",children:["Playground module ",h.jsx("code",{children:ee.uri})," failed to load: ",ee.error]},ee.uri))]})}const DV=2e3;function sS(e){return e.split(/(\s+)/).filter(t=>t!=="")}function OV(e,t){const r=sS(e),n=sS(t);let i=0;for(;i<r.length&&i<n.length&&r[i]===n[i];)i++;let s=r.length,a=n.length;for(;s>i&&a>i&&r[s-1]===n[a-1];)s--,a--;const o=[],l=(u,c)=>{if(!c)return;const d=o.at(-1);(d==null?void 0:d.type)===u?d.text+=c:o.push({type:u,text:c})};l("same",r.slice(0,i).join(""));for(const u of MV(r.slice(i,s),n.slice(i,a)))l(u.type,u.text);return l("same",r.slice(s).join("")),o}function MV(e,t){const r=e.length,n=t.length;if(r===0||n===0)return[...r?[{type:"del",text:e.join("")}]:[],...n?[{type:"add",text:t.join("")}]:[]];const i=Math.min(r+n,DV),s=i+1;let a=new Int32Array(2*i+3);const o=[];let l=!1;for(let m=0;m<=i&&!l;m++){o.push(a.slice());const f=a.slice();for(let p=-m;p<=m;p+=2){let g=p===-m||p!==m&&a[s+p-1]<a[s+p+1]?a[s+p+1]:a[s+p-1]+1,y=g-p;for(;g<r&&y<n&&e[g]===t[y];)g++,y++;if(f[s+p]=g,g>=r&&y>=n){l=!0;break}}a=f}if(!l)return[{type:"del",text:e.join("")},{type:"add",text:t.join("")}];const u=[];let c=r,d=n;for(let m=o.length-1;m>=0;m--){const f=o[m],p=c-d,g=p===-m||p!==m&&f[s+p-1]<f[s+p+1]?p+1:p-1,y=f[s+g],b=y-g;for(;c>y&&d>b;)u.push({type:"same",text:e[--c]}),d--;if(m===0)break;c===y?u.push({type:"add",text:t[--d]}):u.push({type:"del",text:e[--c]})}return u.reverse()}function xc(e){return e.names.length>0?e.names[0]:e.wip?"unsaved edits":`variation ${zi(e.id)}`}function Uf(e){return!e||e.version===void 0&&e.variation===void 0}function jV(e,t){if(!Uf(t))return t;if(e.wipId)return{promptId:e.id,variation:e.wipId}}function BV(e){var t;return!!((t=e.variation)!=null&&t.wip)&&!!e.variation.onHead}function PV(e,t){const{variation:r,version:n,dirty:i,wipId:s,...a}=t;return{...e,...a,ref:{promptId:e.id},atHead:!0,dirty:void 0,wipId:void 0}}function zV(e){var n,i;const t=e.variation,r=e.version?zi(e.version.id):void 0;if(t!=null&&t.wip)return`${t.onHead?"Working tree":r??"Old version"} · ● unsaved`;if(t){const s=xc(t);return e.atHead===!1&&r?`${s} · on ${r}`:s}return(n=e.ref)!=null&&n.version&&r?(i=e.version)!=null&&i.message?`${r} · ${e.version.message}`:r:e.dirty?"Working tree · ● unsaved":"Working tree"}function $V(e){return e.variation?xc(e.variation):e.version?zi(e.version.id):"this version"}function YA(e){return!!e.variation&&!e.variation.wip}function HV(e){const t={modelEditable:!1,modelParametersEditable:!1};return e.style==="chat"?{...e,...t,systemEditable:!1,messagesEditable:!1}:{...e,...t,stateEditable:!1,questionsEditable:!1}}function FV(e){const t=YA(e),r=e.atHead===!1;if(t&&r)return"Saved variations are read-only, and run only on the working tree.";if(t)return"Saved variations are read-only.";if(r)return"Running is only available on the working tree."}function UV(e){var t;if((t=e.variation)!=null&&t.pending)return"Resolve the conflicts before running.";if(e.atHead===!1)return"Running is only available on the working tree."}function aS(e){return e==null?"":Array.isArray(e)?e.map(t=>t&&typeof t=="object"&&"role"in t?`${t.role}: ${Vf(t.content)}`:Vf(t)).join(`
84
+ `):[],l=o.length>1;return h.jsxs("div",{className:"pg-panel-card",children:[h.jsxs("div",{className:"pg-msg-header",style:{alignItems:"flex-start"},children:[h.jsxs("div",{style:{flex:1,minWidth:0},children:[h.jsx("span",{className:"pg-role-label",children:e.name}),o.length>0&&h.jsxs("div",{className:"pg-param-description",children:[s?e.description:o[0],l&&h.jsx("button",{type:"button",className:"pg-desc-toggle",onClick:()=>a(u=>!u),children:s?"less":"more"})]})]}),r&&h.jsx("button",{type:"button",className:"pg-delete-msg",onClick:n,title:"Remove parameter",children:"×"})]}),h.jsx("div",{className:"pg-param-input-inline",children:h.jsx(Ir,{propDef:e,value:t,onChange:i,className:"pg-param-input",disabled:!cl(r,t)})})]})}function pU({prompt:e,modelParameters:t,addableParams:r,onUpdate:n,onClose:i}){const s=e.modelParametersEditable!==!1;return h.jsx("div",{className:"pg-modal-backdrop",onClick:i,children:h.jsxs("div",{className:"pg-modal",onClick:a=>a.stopPropagation(),children:[h.jsxs("div",{className:"pg-modal-header",children:[h.jsx("span",{className:"pg-modal-title",children:"Model settings"}),h.jsx("button",{type:"button",className:"pg-delete-msg",onClick:i,title:"Close",children:"×"})]}),h.jsx("div",{className:"pg-modal-body",children:e.modelParameters.length===0?h.jsx("div",{className:"pg-modal-empty",children:"No settings configured."}):e.modelParameters.map(a=>{const o=t.find(l=>l.name===a.def.name);return o?h.jsx(mU,{propDef:o,value:a.value,editable:s,onDelete:()=>n({modelParameters:{[a.def.name]:null}}),onChange:l=>n({modelParameters:{[a.def.name]:l}})},a.def.name):h.jsxs("div",{className:"pg-panel-card",children:[h.jsxs("div",{className:"pg-msg-header",children:[h.jsx("span",{className:"pg-role-label",children:a.def.name}),s&&a.value&&xA(a.value)&&h.jsx("button",{type:"button",className:"pg-delete-msg",onClick:()=>n({modelParameters:{[a.def.name]:null}}),title:"Remove",children:"×"})]}),h.jsx("div",{className:"pg-msg-content",style:{fontSize:13,color:"#9ca3af"},children:a.value!==void 0?ma(a.value):""})]},a.def.name)})}),s&&r.length>0&&h.jsx("div",{className:"pg-modal-footer",children:h.jsxs("div",{className:"pg-pill-btn pg-add-param-btn",children:["+ Add setting",h.jsxs("select",{className:"pg-model-overlay-select",value:"",onChange:a=>{if(!a.target.value)return;const o=r.find(l=>l.name===a.target.value);o&&n({modelParameters:{[o.name]:o.defaultValue??Q9(o.type)}})},children:[h.jsx("option",{value:"",children:"Choose…"}),r.map(a=>h.jsx("option",{value:a.name,children:a.name},a.name))]})]})})]})})}function gU({prompt:e,onUpdate:t,modelDefinition:r}){const n=w.useRef(!1),i=w.useRef(null),s=w.useRef(null),[a,o]=w.useState(0),[l,u]=_d(e.messages),[c,d]=w.useState([]),[m,f]=w.useState(!1),p=()=>{n.current=!0},g=A=>{A.currentTarget.contains(A.relatedTarget)||(n.current=!1,o(z=>z+1))};w.useEffect(()=>{e.providerId&&_H(e.providerId).then(d).catch(()=>{})},[e.providerId]);const y=w.useRef(null),b=w.useRef(null),v=A=>{u(A),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>t({messages:A}),Um)},x=A=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>t({system:A}),Um)},E=()=>{var B;const A=l[l.length-1];let z="user";(A==null?void 0:A.role)==="user"?z="assistant":(A==null?void 0:A.role)==="assistant"&&((B=A.toolCalls)!=null&&B.length)&&(z="tool");const I=[...l,{role:z,content:{kind:"primitive",value:""}}];s.current=I.length-1,u(I),y.current&&clearTimeout(y.current),t({messages:I})};w.useLayoutEffect(()=>{var z,I;const A=s.current;A===null||A>=l.length||(s.current=null,(I=(z=i.current)==null?void 0:z.querySelector(`[data-message-index="${A}"] .token-editor`))==null||I.focus())},[l.length]);const T=new Set(e.modelParameters.map(A=>A.def.name)),C=r?c.filter(A=>!T.has(A.name)):[],L=w.useMemo(()=>({...cU,interpolatables:L9(e.functionParameters)}),[e.functionParameters]);return h.jsxs("div",{className:"pg-editor",children:[m&&h.jsx(pU,{prompt:e,modelParameters:c,addableParams:C,onUpdate:t,onClose:()=>f(!1)}),h.jsx("div",{className:"pg-panel",children:h.jsxs("div",{className:"pg-panel-model-row",children:[h.jsx(TA,{definition:r,value:e.model,editable:cl(e.modelEditable,e.model),onChange:A=>t({model:A})}),h.jsxs("div",{className:"pg-panel-model-row-actions",children:[h.jsx("button",{type:"button",className:"pg-pill-btn",onClick:()=>f(!0),children:"Settings"}),h.jsx("button",{type:"button",className:"pg-pill-btn",disabled:!0,children:"Tools"}),h.jsxs("button",{type:"button",className:"pg-pill-btn",children:["Output type: Text",h.jsx("span",{"aria-hidden":!0,className:"pg-pill-chevron",children:"▾"})]})]})]})}),h.jsxs("div",{className:"pg-panel",children:[h.jsxs("div",{ref:i,className:"pg-panel-body",onFocus:p,onBlur:g,children:[h.jsx(dU,{content:e.system,editable:cl(e.systemEditable,e.system),propDef:L,syncVersion:a,syncPausedRef:n,onChange:x}),l.map((A,z)=>h.jsx(fU,{msg:A,messageIndex:z,editable:e.messagesEditable,propDef:L,onChange:I=>v(l.map((B,j)=>j===z?I:B)),onDelete:()=>v(l.filter((I,B)=>B!==z))},z))]}),h.jsx("div",{className:"pg-panel-footer",children:h.jsx("button",{type:"button",className:"pg-add-msg-btn",onClick:E,disabled:!e.messagesEditable,children:"+ Add message"})})]})]})}function bU({value:e,validate:t,className:r,label:n,title:i,readOnly:s,onCommit:a}){const[o,l]=w.useState(null),u=o===null?null:t==null?void 0:t(o),c=()=>{o!==null&&!u&&o!==e&&a(o),l(null)};return h.jsx("input",{"data-1p-ignore":!0,className:r,"aria-label":n,"aria-invalid":!!u,title:u??i,value:o??e,readOnly:s,spellCheck:!1,onChange:d=>l(d.target.value),onBlur:c,onKeyDown:d=>{d.key==="Enter"?(d.preventDefault(),c()):d.key==="Escape"&&l(null)}})}function vd(e){if(e.kind!=="union")return;const t=e.types.find(s=>s.kind==="primitive"&&(s.base??s.syntax)==="string"),r=e.types.filter(s=>s.kind==="record"||s.kind==="array"),n=e.types.filter(s=>s!==t&&!r.includes(s)&&!(s.kind==="constant"&&s.value===null));if(!t||r.length===0||n.length>0)return;const i=e.types.some(s=>s.kind==="constant"&&s.value===null);return{text:t,structured:r,nullable:i}}const Fx={kind:"primitive",value:null};function Fg(e){return(e==null?void 0:e.kind)==="primitive"&&e.value===null}function _U(e){var t;return e.kind==="record"&&!!((t=vd(e.value.type))!=null&&t.nullable)}function Ux(e){return e===void 0||e.kind==="template"||e.kind==="reference"||e.kind==="primitive"&&(typeof e.value=="string"||e.value==null)}function Vx(e,t){if(e.kind==="tuple"){const{elements:r,rest:n}=e;return!n||r.length<2||![...r,n].every(i=>!!vd(i.type))?void 0:{fixed:r,rest:n,min:r.length}}if(e.kind==="array"&&t[t.length-1]==="criteria"&&vd(e.element.type))return{fixed:[],rest:e.element,min:2}}function vU(){const e=[];function t({propDef:s,value:a,onChange:o,path:l,disabled:u}){const c=vd(s.type),d=Y9(),m=(l==null?void 0:l.join("/"))??"",[f,p]=w.useState({slot:m,structured:!Ux(a)}),g=f.slot===m?f.structured:!Ux(a),y=c.structured.length===1?c.structured[0]:{kind:"union",syntax:c.structured.map(I=>I.syntax).join(" | "),types:c.structured},b=g?y:c.text,v=Fg(a)?void 0:a,x=c.nullable&&Fg(a),[E,T]=w.useState(!1),C=w.useRef(null);w.useEffect(()=>{var I,B;E&&((B=(I=C.current)==null?void 0:I.querySelector('[contenteditable="true"], input, textarea'))==null||B.focus())},[E]);const{defaultValue:L,...A}=s,z=Fg(L)?A:s;return h.jsxs("div",{className:"pg-entry",ref:C,onBlur:I=>{I.currentTarget.contains(I.relatedTarget)||T(!1)},children:[x&&!E?h.jsx("button",{type:"button",className:"pg-entry-none",title:"None (null). Click to write one.",disabled:u,onClick:()=>T(!0),children:"None"}):h.jsx(Ir,{propDef:{...z,type:b},value:g?a:v,onChange:o,plugins:e,path:l,disabled:u,className:g?void 0:"token-editor pg-entry-text"}),(l==null?void 0:l.length)===1&&(d!=null&&d.length)?h.jsx(q9,{interpolatables:d,onChange:o,disabled:u}):null,h.jsx("button",{type:"button",className:"pg-entry-toggle",disabled:u,onClick:()=>{p({slot:m,structured:!g}),o(nn(g?c.text:y))},children:g?"Text":"JSON"}),c.nullable&&!x&&h.jsx("button",{type:"button",className:"pg-entry-set-null",title:"Set to null",disabled:u,onClick:()=>{p({slot:m,structured:!1}),T(!1),o(Fx)},children:"None"})]})}function r({propDef:s,value:a,onChange:o,path:l,disabled:u}){return s.type.kind!=="record"?null:h.jsx(V9,{value:{...s.type.value,defaultValue:Fx},current:a,onChange:o,plugins:e,path:l,disabled:u})}function n({propDef:s,value:a,onChange:o,path:l=[],disabled:u}){const c=Vx(s.type,l);if(!c)return null;const{fixed:d,rest:m,min:f}=c,p=H9(a),g=Math.max(p.length,f),y=x=>({...d[x]??m,name:`Level ${x}`}),b=x=>d.length>0?F9(x,d.length):x<p.length&&p.length>f,v=x=>o({kind:"array",elements:x});return h.jsxs("ol",{className:"pg-score-levels",start:0,children:[Array.from({length:g},(x,E)=>h.jsxs("li",{className:"pg-score-level",children:[h.jsx("span",{className:"pg-score-level-number",children:E}),h.jsx("div",{className:"pg-score-level-editor",children:h.jsx(Ir,{propDef:y(E),value:p[E],onChange:T=>{const C=[...p];for(let L=C.length;L<E;L++)C[L]=nn(y(L).type);C[E]=T,v(C)},plugins:e,path:[...l,String(E)],disabled:u})}),b(E)?h.jsx("button",{type:"button",className:"pg-delete-msg",title:"Remove level",disabled:u,onClick:()=>v(p.filter((T,C)=>C!==E)),children:"×"}):h.jsx("span",{className:"pg-delete-msg pg-delete-msg-spacer","aria-hidden":"true",children:"×"})]},E)),h.jsx("button",{type:"button",className:"pg-add-level-btn",disabled:u,onClick:()=>{const x=[...p];for(let E=x.length;E<g;E++)x[E]=nn(y(E).type);v([...x,nn(m.type)])},children:"+ Add level"})]})}function i({propDef:s,value:a,onChange:o,path:l=[],disabled:u}){if(s.type.kind!=="object")return null;const c=(a==null?void 0:a.kind)==="object"?a.properties:{};return h.jsx("div",{className:"pg-noul-criteria",children:s.type.properties.map(d=>h.jsxs("div",{className:"pg-noul-outcome",children:[h.jsxs("span",{className:"pg-noul-outcome-label",children:[h.jsx("strong",{children:d.name==="true"?"Yes":"No"})," means"]}),h.jsx(Ir,{propDef:d,value:c[d.name],onChange:m=>o({kind:"object",properties:{...c,[d.name]:m}}),plugins:e,path:[...l,d.name],disabled:u})]},d.name))})}return e.push({match:s=>!!vd(s),component:t},{match:_U,component:r},{match:(s,a)=>!!Vx(s,a),component:n},{match:(s,a)=>s.kind==="object"&&a[a.length-1]==="criteria"&&s.properties.length===2&&s.properties.every(o=>o.name==="true"||o.name==="false"),component:i}),e}function yU(e){return e===void 0?{}:e.kind==="object"?e.properties:void 0}function xU(e){return e.type.kind==="record"?e.type.value:void 0}function SU(e){const t=new Set(Object.keys(e));for(let r=Object.keys(e).length+1;;r++){const n=`question_${r}`;if(!t.has(n))return n}}const wU=e=>e.charAt(0).toUpperCase()+e.slice(1);function EU(e){const t=U9(e);if(t.length>0)return t.map(({label:n,factory:i})=>({key:i.def.name,label:n,create:()=>n1(i)}));const r=B9(e.type);return r?r.cases.map(n=>({key:String(n.discriminatorValue),label:wU(String(n.discriminatorValue)),create:()=>({kind:"object",properties:{[r.discriminator]:{kind:"primitive",value:n.discriminatorValue},...Object.fromEntries(n.properties.filter(i=>!i.optional).map(i=>[i.name,i.defaultValue??nn(i.type)]))}})})):[]}function kU(e,t){const r=SU(e);return{id:r,questions:{...e,[r]:t.create()}}}function CU(e,t,r){return z9(e,t,r)}function qx({value:e}){return h.jsx("div",{className:"pg-msg-content","data-readonly":"true",children:e===void 0?"":ma(e)})}function TU({id:e,questions:t,disabled:r,onRename:n}){return h.jsx(bU,{className:"pg-question-id",label:"Question id",title:"Identifies this question's answer",value:e,validate:i=>$9(t,e,i),readOnly:r,onCommit:n})}function AU({prompt:e,onUpdate:t,modelDefinition:r}){const n=w.useRef(!1),[i,s]=w.useState(0),[a,o]=_d(e.state.value,i,n),[l,u]=_d(e.questions.value,i,n),c=w.useMemo(vU,[]),d=w.useRef(null),m=w.useRef(null),f=w.useMemo(()=>L9(e.functionParameters),[e.functionParameters]),p=w.useRef({}),g=(A,z)=>{clearTimeout(p.current[A]),p.current[A]=setTimeout(()=>t({[A]:z}),Um)},y=()=>{n.current=!0},b=A=>{A.currentTarget.contains(A.relatedTarget)||(n.current=!1,s(z=>z+1))},v=w.useMemo(()=>({...e.state.def,interpolatables:f}),[e.state.def,f]),x=w.useMemo(()=>{const A=xU(e.questions.def);return A&&{...A,interpolatables:f}},[e.questions.def,f]),E=yU(l),T=cl(e.questionsEditable,l),C=w.useMemo(()=>x?EU(x):[],[x]),L=(A,z=!1)=>{const I={kind:"object",properties:A};u(I),z?(clearTimeout(p.current.questions),t({questions:I})):g("questions",I)};return w.useEffect(()=>{var z,I;const A=m.current;A!==null&&(m.current=null,(I=(z=d.current)==null?void 0:z.querySelector(`[data-question-index="${A}"] [contenteditable="true"], [data-question-index="${A}"] textarea, [data-question-index="${A}"] input:not(.pg-question-id)`))==null||I.focus())}),h.jsxs("div",{className:"pg-editor pg-questions-editor",children:[h.jsx("div",{className:"pg-panel",children:h.jsx("div",{className:"pg-panel-model-row",children:h.jsx(TA,{definition:r,value:e.model,editable:cl(e.modelEditable,e.model),onChange:A=>t({model:A})})})}),h.jsxs("div",{className:"pg-panel",onFocus:y,onBlur:b,children:[h.jsxs("div",{className:"pg-panel-card pg-state-card",children:[h.jsxs("div",{className:"pg-msg-header",children:[h.jsx("span",{className:"pg-role-label",children:"State"}),h.jsx("span",{className:"pg-card-hint",title:"What the questions are about",children:"?"})]}),cl(e.stateEditable,a)?h.jsx(Ir,{propDef:v,value:a,onChange:A=>{o(A),g("state",A)},plugins:c,path:["state"]}):h.jsx(qx,{value:a})]}),h.jsx("div",{className:"pg-msg-header",children:h.jsx("span",{className:"pg-role-label",children:"Questions"})}),h.jsx("div",{className:"pg-questions",ref:d,children:T&&x&&E?Object.entries(E).map(([A,z],I)=>h.jsxs("div",{className:"pg-panel-card pg-question-card","data-question-index":I,children:[h.jsxs("div",{className:"pg-msg-header",children:[h.jsx(TU,{id:A,questions:E,disabled:!1,onRename:B=>L(CU(E,A,B),!0)}),h.jsx("button",{type:"button",className:"pg-delete-msg",title:"Delete question",onClick:()=>{const B={...E};delete B[A],L(B,!0)},children:"×"})]}),h.jsx(Ir,{propDef:{...x,name:A},value:z,onChange:B=>L({...E,[A]:B}),plugins:c,path:["questions",A]})]},I)):h.jsx("div",{className:"pg-panel-card",children:h.jsx(qx,{value:l})})}),T&&x&&E&&C.length>0&&h.jsx("div",{className:"pg-panel-footer",children:h.jsxs("div",{className:"pg-add-msg-btn pg-add-question",children:["+ Add question",h.jsxs("select",{"aria-label":"Add question",className:"pg-model-overlay-select",value:"",onChange:A=>{const z=C.find(B=>B.key===A.target.value);if(!z)return;const I=kU(E,z);m.current=Object.keys(I.questions).length-1,L(I.questions,!0)},children:[h.jsx("option",{value:"",children:"Choose…"}),C.map(({key:A,label:z})=>h.jsx("option",{value:A,children:z},A))]})]})})]})]})}function NU({prompt:e,onUpdate:t,modelDefinition:r}){const n=w.useCallback(s=>t({...s,style:"questions"}),[t]),i=w.useCallback(s=>t({...s,style:"chat"}),[t]);switch(e.style){case"chat":return h.jsx(gU,{prompt:e,onUpdate:i,modelDefinition:r});case"questions":return h.jsx(AU,{prompt:e,onUpdate:n,modelDefinition:r})}}const RU=w.memo(NU);function AA(e){var n;const t=w.useRef(null),r=JSON.stringify(e)??"";return((n=t.current)==null?void 0:n.json)!==r&&(t.current={value:e,json:r}),t.current.value}function LU(e){return e instanceof Element&&!!e.closest(".add-to-dataset-menu")}const IU=6e3;function DU(e){return e.length===0?"":` · skipped ${[...new Set(e.map(r=>r.name))].join(", ")} (no matching field)`}function d_({inputs:e,resources:t,newDatasetFields:r,prompt:n,source:i,disabled:s,className:a,children:o,onOpenDataset:l}){const[u,c]=w.useState(!1),[d,m]=w.useState(null),[f,p]=w.useState(null),[g,y]=w.useState(null),[b,v]=w.useState(!1),[x,E]=w.useState(""),[T,C]=w.useState(!1),[L,A]=w.useState(null),z=w.useRef(null),I=w.useCallback(()=>{c(!1),v(!1),E("")},[]),{triggerRef:B,popoverRef:j,style:G}=Fi({open:u,onClose:I,matchTriggerWidth:!1});w.useEffect(()=>{if(!u)return;let R=!1;return y(null),Promise.all([eA(),rA()]).then(([de,Te])=>{var H;R||(m(de),p(((H=Te[0])==null?void 0:H.id)??null))}).catch(de=>!R&&y(de.message)),()=>{R=!0}},[u]),w.useEffect(()=>{var R;b&&((R=z.current)==null||R.focus())},[b]),w.useEffect(()=>{if(!(L!=null&&L.ok))return;const R=setTimeout(()=>A(null),IU);return()=>clearTimeout(R)},[L]);const W=async(R,de)=>{const{cells:Te,skipped:H}=vA(e,de),Oe=yA(t);await VH(R.providerId,R.id,[{cells:Te,source:i,...Oe&&{resources:Oe}}]);const Pe=DU(H);A({ok:!0,message:`Added to ${R.name}${Pe}`,dataset:{providerId:R.providerId,id:R.id,name:R.name},skipped:Pe})},Y=async R=>{C(!0);try{await R(),I()}catch(de){A({ok:!1,message:de.message}),I()}finally{C(!1)}},V=()=>Y(async()=>{const R=x.trim();if(!R||!f)return;const de=await tA(f,{name:R,fields:r,...n&&{prompt:n.link}});await W({...de,providerId:f},de.fields)}),X=[...d??[]].sort((R,de)=>{const Te=Hh(R.prompt,n==null?void 0:n.openable),H=Hh(de.prompt,n==null?void 0:n.openable);return Te===H?0:Te?-1:1}),P=u&&cn.createPortal(h.jsxs("div",{className:"add-to-dataset-menu",ref:j,style:G,role:"menu",children:[g&&h.jsx("div",{className:"add-to-dataset-error",children:g}),!d&&!g&&h.jsx("div",{className:"add-to-dataset-empty",children:"Loading…"}),X.map(R=>{const de=R.error?0:FF(e,R.fields),Te=Hh(R.prompt,n==null?void 0:n.openable);return h.jsxs("button",{type:"button",role:"menuitem",className:"add-to-dataset-item",disabled:T||de===0,onClick:()=>Y(()=>W(R,R.fields)),title:R.error??void 0,children:[h.jsxs("span",{className:"add-to-dataset-item-name",children:[R.name,Te&&h.jsx("span",{className:"add-to-dataset-linked",children:"linked"})]}),h.jsx("span",{className:"add-to-dataset-item-meta",children:R.error?"can't be opened":de===0?"no matching fields":`${de} of ${e.length} field${e.length===1?"":"s"}`})]},`${R.providerId}:${R.id}`)}),d&&X.length>0&&h.jsx("div",{className:"add-to-dataset-divider"}),b?h.jsxs("form",{className:"add-to-dataset-new",onSubmit:R=>{R.preventDefault(),V()},children:[h.jsx("input",{ref:z,className:"add-to-dataset-name",placeholder:"Dataset name","aria-label":"New dataset name",value:x,onChange:R=>E(R.target.value),disabled:T}),h.jsx("button",{type:"submit",className:"add-to-dataset-create",disabled:T||!x.trim()||!f,children:"Create"})]}):h.jsx("button",{type:"button",role:"menuitem",className:"add-to-dataset-item add-to-dataset-item-new",onClick:()=>v(!0),disabled:T||!!d&&!f,children:h.jsx("span",{className:"add-to-dataset-item-name",children:"New dataset…"})})]}),document.body),re=L==null?void 0:L.dataset;return h.jsxs("span",{className:"add-to-dataset",children:[L&&h.jsxs("span",{className:`add-to-dataset-outcome${L.ok?"":" add-to-dataset-outcome-error"}`,role:"status",title:L.message,children:[re&&l?h.jsxs("span",{children:["Added to"," ",h.jsxs("button",{type:"button",className:"add-to-dataset-link",onClick:R=>{R.stopPropagation(),l(re)},children:[re.name," ↗"]}),L.skipped]}):L.message,h.jsx("button",{type:"button",className:"pg-dismiss","aria-label":"Dismiss",onClick:()=>A(null),children:"×"})]}),h.jsx("button",{type:"button",ref:B,className:a??"add-to-dataset-btn",onClick:()=>{A(null),c(R=>!R)},disabled:s,"aria-haspopup":"menu","aria-expanded":u,title:"Add these inputs to a dataset",children:o??h.jsxs(h.Fragment,{children:[h.jsx(Jd,{}),"Add to dataset"]})}),P]})}function NA(e){switch(e.kind){case"dataset":return[e.field];case"object":return Object.values(e.properties).flatMap(NA);default:return[]}}function RA(e){switch(e.kind){case"input":return[e];case"object":return Object.values(e.properties).flatMap(RA);default:return[]}}function Vm(e,t,r=i=>i,n=""){const i=[];for(const s of e){const a=n?`${n}.${s.name}`:s.name,o=t[s.name],l=o&&r(o);if(!l){s.optional||i.push(a);continue}l.kind==="object"&&s.type.kind==="object"&&i.push(...Vm(s.type.properties,l.properties,r,a))}return i}function kve(e,t,r){var c;const n=[],{prompt:i,fields:s}=r,a=s&&new Set(s.map(d=>d.id)),o=(d,m)=>{if(a)for(const f of NA(d))a.has(f)||n.push(`${m} is bound to a column that no longer exists`)},l=[["function",e.functionInputs,i==null?void 0:i.functionParameters],["execute",e.executeInputs,(i==null?void 0:i.executeParameters)??[]]];for(const[d,m,f]of l){for(const[p,g]of Object.entries(m)){const y=`Input '${Fh(d,p)}'`;if(f&&!f.some(b=>b.name===p)){n.push(`${y} is bound, but the prompt no longer has it`);continue}o(g,y)}if(f)for(const p of Vm(f,m))n.push(`Input '${Fh(d,p)}' is required but unbound`)}for(const[d,m]of Object.entries(e.resources??{}))for(const[f,p]of Object.entries(m.args??{}))o(p,`Resource '${d}': '${f}'`);i&&n.push(...BF(e,i,{undeclaredInstances:!0}));const u=i&&gA(i);for(const d of t){const m=(c=r.checks)==null?void 0:c.find(p=>p.uri===d.uri),f=`Check '${d.label??(m==null?void 0:m.label)??d.uri}'`;if(r.checks&&!m){n.push(`${f} no longer exists`);continue}if(m!=null&&m.error){n.push(`${f} can't load: ${m.error}`);continue}for(const[p,g]of Object.entries(d.args)){const y=`${f}: '${p}'`;if(o(g,y),!!u)for(const b of RA(g))u[b.half].has(b.path)||n.push(`${y} names input '${Fh(b.half,b.path)}', which the prompt doesn't have`)}if(m)for(const p of Vm(m.parameters,d.args))n.push(`${f}: '${p}' is required but unbound`)}return n}const f_="@@column/",m_="@@input/",qm="@@instance/",LA="@@new-column",Gx="Dataset columns",OU="Prompt inputs",Wx="Resources in this run",G4="New";function W4(e){return`${f_}${e}`}function Y4(e,t){return`${m_}${e}/${t}`}function oa(e,t){return t===void 0?`${qm}${e}`:`${qm}${e}/${t}`}function Bl(e){if(!e.startsWith(qm))return;const t=e.slice(qm.length),r=t.indexOf("/");return r<0?{name:t}:{name:t.slice(0,r),output:t.slice(r+1)}}function K4(e){return e.startsWith("@@")}function p_(e){if(e.startsWith(f_))return{kind:"dataset",field:e.slice(f_.length)};if(e.startsWith(m_)){const r=e.slice(m_.length),n=r.indexOf("/"),i=r.slice(0,n);return i!=="function"&&i!=="execute"?void 0:{kind:"input",half:i,path:r.slice(n+1)}}const t=Bl(e);if(t)return{kind:"instance",...t}}function MU(e){if(e.kind==="dataset")return W4(e.field);if(e.kind==="input")return Y4(e.half,e.path);if(e.kind==="instance")return oa(e.name,e.output)}function jU(e,t){return e==="execute"?`execute.${t}`:t}function yd(e,t){return e.syntax===t.syntax?!0:e.kind==="union"?e.types.every(r=>yd(r,t)):t.kind==="union"?t.types.some(r=>yd(e,r)):e.kind==="primitive"&&t.kind==="primitive"&&e.base===t.base}function BU(e,t,r,n){const[i,...s]=r.split("."),a=(l,u)=>{if(u.length===0)return n;const[c,...d]=u,m=(l==null?void 0:l.kind)==="object"?{...l.properties}:{};return m[c]=a(m[c],d),{kind:"object",properties:m}},o=t==="function"?"functionInputs":"executeInputs";return{...e,[o]:{...e[o],[i]:a(e[o][i],s)}}}function X4(e){return[...wl(e.functionParameters).map(t=>({half:"function",path:t.path,type:t.type})),...wl(e.executeParameters??[]).map(t=>({half:"execute",path:t.path,type:t.type}))]}function IA(e,t,r){return[...e.map(n=>({uri:W4(n.id),label:n.def.name,scope:"run",group:[Gx]})),...r?[{uri:LA,label:r,scope:"run",group:[Gx]}]:[],...t.map(n=>({uri:Y4(n.half,n.path),label:`= ${jU(n.half,n.path)}`,scope:"run",group:[OU]}))]}function PU(e,t){var o,l;const r=X4(t),n=t.fields??[],i=(u,c)=>{const d=[];for(const m of n)(t.offerMismatches||yd(m.def.type,u))&&d.push(W4(m.id));for(const m of r)if(!(c&&m.half===c.half&&mA(m.path,c.path))&&!(!t.offerMismatches&&!yd(m.type,u))){if(c){const f={kind:"input",half:m.half,path:m.path},p=BU(t.bindings,c.half,c.path,f);if(pA(p))continue}d.push(Y4(m.half,m.path))}return d},s=(u,c)=>{const d={...c};for(const m of r.filter(f=>f.half===u)){const f=i(m.type,m);t.newColumn&&f.push(LA),f.length>0&&(d[m.path]=[...d[m.path]??[],...f])}return d},a={...e==null?void 0:e.resourceSlots};for(const u of(e==null?void 0:e.resources)??[]){if(!((o=u.parameters)!=null&&o.length))continue;const c={...(l=e==null?void 0:e.resourceSlots)==null?void 0:l[u.uri]};for(const d of wl(u.parameters)){const m=i(d.type);m.length>0&&(c[d.path]=[...c[d.path]??[],...m])}a[u.uri]=c}return{resources:[...(e==null?void 0:e.resources)??[],...IA(n,r,t.newColumn?"+ New column from this slot":void 0)],functionSlots:s("function",e==null?void 0:e.functionSlots),executeSlots:s("execute",e==null?void 0:e.executeSlots),resourceSlots:a}}function Cve(e,t){const r=X4(t),n=IA(t.fields??[],r,"+ New column from this parameter"),i=n.map(s=>s.uri);return{resources:n,functionSlots:Object.fromEntries(wl(e).map(s=>[s.path,i])),executeSlots:{}}}function zU(e,t,r){var a,o,l;const n=p_(e);if(!n)return;let i,s="";if(n.kind==="dataset")i=(o=(a=r.fields)==null?void 0:a.find(u=>u.id===n.field))==null?void 0:o.def.type,s=i?"column from dataset":"column no longer exists";else if(n.kind==="input"){const{half:u,path:c}=n;i=(l=X4(r).find(d=>d.half===u&&d.path===c))==null?void 0:l.type,s=i?"same value as that input":"input no longer exists"}return i&&!yd(i,t)?{note:s,warning:`${i.syntax} into ${t.syntax}`}:{note:s}}function $U(e,t){const r=Object.entries(t);if(r.length===0)return[...e];const n=new Map(e.map(a=>[a.uri,a])),i=new Map;for(const a of e)a.parent&&i.set(a.parent,[...i.get(a.parent)??[],a]);return[...r.flatMap(([a,{uri:o}])=>{const l=n.get(o),u=(l==null?void 0:l.scope)??"run";return[{uri:oa(a),label:a,scope:u,group:[Wx],...(l==null?void 0:l.value)!==void 0&&{value:l.value}},...(i.get(o)??[]).map(c=>({uri:oa(a,c.uri.slice(o.length+1)),label:c.label,scope:u,group:[Wx],parent:oa(a),...c.value!==void 0&&{value:c.value}}))]}),...e.map(a=>K4(a.uri)?a:{...a,group:[G4,...a.group??[]]})]}function HU(e,t,r){const n=Object.entries(r);if(n.length===0)return{...e};const i=new Map(t.flatMap(s=>s.parent?[[s.uri,s.parent]]:[]));return Object.fromEntries(Object.entries(e??{}).map(([s,a])=>{const o=[];for(const[l,{uri:u}]of n)for(const c of a)c===u?o.push(oa(l)):i.get(c)===u&&o.push(oa(l,c.slice(u.length+1)));return[s,[...o,...a]]}))}function FU(e,t){const r=(e==null?void 0:e.resources)??[],n=i=>HU(i,r,t);return{resources:$U(r,t),functionSlots:n(e==null?void 0:e.functionSlots),executeSlots:n(e==null?void 0:e.executeSlots),...(e==null?void 0:e.resourceSlots)&&{resourceSlots:Object.fromEntries(Object.entries(e.resourceSlots).map(([i,s])=>[i,n(s)]))}}}function UU(e,t,r,n={}){const i=Bl(e);if(!i)return;const s=t[i.name],a=i.output===void 0?i.name:`${i.name}.${i.output}`;if(!s)return n.rowsMayDeclare?{label:a,note:"not declared here: each row must declare it"}:{label:a,note:"resource no longer in this run",missing:!0};const o=r.get(s.uri);return{label:a,note:(o==null?void 0:o.label)??s.uri}}function Q4(e){return`pg-exec-params:${e.globalId??e.id}`}function Tve(e){try{const t=localStorage.getItem(Q4(e)),r=t?JSON.parse(t):void 0;return r&&typeof r=="object"?r:void 0}catch{return}}const hl="";function Gi(e){if(!e)return;const t=e.resources??{},r=t[hl];if(r)return p_(r);const n=Object.entries(t).flatMap(([s,a])=>{if(s===hl)return[];const o=p_(a);return o?[[s,o]]:[]});if(n.length===0)return e.value?{kind:"value",value:e.value}:void 0;let i=e.value?{kind:"value",value:e.value}:{kind:"object",properties:{}};for(const[s,a]of n)i=DA(i,s.split("."),a);return i}function DA(e,t,r){if(t.length===0)return r;const[n,...i]=t,s={...VU(e)};return s[n]=DA(s[n]??{kind:"object",properties:{}},i,r),{kind:"object",properties:s}}function VU(e){return e.kind==="object"?e.properties:e.kind==="value"&&e.value.kind==="object"?Object.fromEntries(Object.entries(e.value.properties).map(([t,r])=>[t,{kind:"value",value:r}])):{}}function dl(e){if(!e)return{};const t={};let r;const n=(s,a)=>{switch(s.kind){case"value":a===hl?r=s.value:i(a,s.value);break;case"object":for(const[o,l]of Object.entries(s.properties))n(l,a===hl?o:`${a}.${o}`);break;case"dataset":case"input":case"instance":t[a]=MU(s);break}},i=(s,a)=>{const o=s.split(".");(r==null?void 0:r.kind)!=="object"&&(r={kind:"object",properties:{}});let l=r;for(const u of o.slice(0,-1)){const c=l.properties[u];(c==null?void 0:c.kind)!=="object"&&(l.properties[u]={kind:"object",properties:{}}),l=l.properties[u]}l.properties[o[o.length-1]]=a};return n(e,hl),{...r?{value:r}:{},...Object.keys(t).length>0?{resources:t}:{}}}function Yx(e,t,r){const[n]=t?Vm([e],{[e.name]:t}):[e.name];if(n===void 0)return;let i=e;for(const s of n.split(".").slice(1)){if(i.type.kind!=="object")break;i=i.type.properties.find(a=>a.name===s)??i}return i.type.kind!=="opaque"?`Parameter '${n}' is required`:r?`Parameter '${n}' needs a resource — pick one from its dropdown`:`Parameter '${n}' is a ${i.type.syntax}, which can't be typed in. Export a resource() from a *.playground.ts beside the prompt, or from .evalution/playground/, to supply one.`}function qU(e){if(e.type.kind!=="object")return;const t=e.type.properties.filter(r=>r.type.kind==="object");return t.length>=2?t:void 0}function Kx(e){const t=qU(e)??[],r=new Map;for(const n of t)if(n.type.kind==="object")for(const i of n.type.properties){const s=`${i.name}\0${i.type.syntax}`,a=r.get(s);a?(a.members.push(n.name),a.optional=a.optional&&i.optional):r.set(s,{name:i.name,type:i.type,optional:i.optional,members:[n.name]})}return[...r.values()]}function Xx(e){return e.some(t=>t.members.length>=2)}function GU(e){return new Set(e.flatMap(t=>t.members)).size}function WU(e,t){if(e){if(e.kind==="object")return e.properties[t];if(e.kind==="value"&&e.value.kind==="object"){const r=e.value.properties[t];return r?{kind:"value",value:r}:void 0}}}function OA(e,t){return t.reduce((r,n)=>WU(r,n),e)}function Z4(e,t){if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||!e||!t||Array.isArray(e)!==Array.isArray(t))return!1;const r=Object.keys(e),n=Object.keys(t);return r.length!==n.length?!1:r.every(i=>Z4(e[i],t[i]))}function MA(e,t){const r={};for(const n of e){const i=n.members.map(l=>OA(t,[l,n.name])),s=i.filter(l=>l!==void 0);if(s.length===0){r[n.name]={};continue}if(s.length<i.length)return null;const[a,...o]=s;if(!o.every(l=>Z4(l,a)))return null;r[n.name]=dl(a)}return{fields:r}}function g_(e,t){const r={},n={};for(const i of e){const a=i.members.map(c=>[c,OA(t,[c,i.name])]).filter(c=>c[1]!==void 0);if(a.length===0){r[i.name]={};continue}const[[,o],...l]=a,u=l.filter(([,c])=>!Z4(c,o)).map(([c])=>c);u.length>0&&(n[i.name]=u),r[i.name]=dl(o)}return{selection:{fields:r},overwritten:n}}function YU(e,t){if(MA(e,t)!==null)return;const{selection:r,overwritten:n}=g_(e,t);return{input:b_(e,r),overwritten:n}}function b_(e,t){const r={};for(const i of e){const s=Gi(t.fields[i.name]);if(s)for(const a of i.members)r[a]??(r[a]={}),r[a][i.name]=s}const n={};for(const[i,s]of Object.entries(r))n[i]={kind:"object",properties:s};return Object.keys(n).length>0?{kind:"object",properties:n}:void 0}function KU(e,t,r,n){return r||(t&&MA(e,t)===null?"expanded":n??"expanded")}function XU(e){return"__group"in e}function QU(e,t){const r=t instanceof Set?t:new Set(t),n=new Map;for(const o of e){if(o.parent===void 0)continue;const l=n.get(o.parent);l?l.push(o):n.set(o.parent,[o])}const i=[];for(const o of e){if(o.parent!==void 0)continue;const l=ZU(o,n.get(o.uri)??[],r);l&&i.push({group:o.group??[],node:l})}const s=JU(i),[a]=s;return s.length===1&&a.kind==="group"&&a.label===G4?a.children??[]:s}function Ff(e,...t){return[...e,...t].join(" / ")}function jA(e,t){return`${e} → ${t}`}function ZU(e,t,r){const n=e.group??[],i=Ff(n,e.label),s=r.has(e.uri),a=t.filter(u=>r.has(u.uri)),o=u=>({kind:"output",uri:u.uri,label:u.label,breadcrumb:Ff(n,e.label,u.label)});if(!s){if(a.length===0)return null;if(a.length===1){const u=a[0];return{kind:"output",uri:u.uri,label:jA(e.label,u.label),breadcrumb:Ff(n,e.label,u.label)}}return{kind:"resource",label:e.label,breadcrumb:i,children:a.map(o)}}if(a.length===0)return{kind:"resource",uri:e.uri,label:e.label,breadcrumb:i};const l={kind:"resource",uri:e.uri,label:e.label,breadcrumb:i};return{kind:"resource",uri:e.uri,label:e.label,breadcrumb:i,children:[l,...a.map(o)]}}function JU(e){const t=[],r=new Map;for(const{group:n,node:i}of e){let s=t,a="";const o=[];for(const l of n){a=a?`${a}/${l}`:l,o.push(l);let u=r.get(a);u||(u={__group:!0,label:l,breadcrumb:Ff(o),children:[]},r.set(a,u),s.push(u)),s=u.children}s.push(i)}return BA(t)}function BA(e){const t=[];for(const r of e){if(!XU(r)){t.push(r);continue}const n=BA(r.children);n.length!==0&&(n.length===1&&r.label!==G4?t.push(n[0]):t.push({kind:"group",label:r.label,breadcrumb:r.breadcrumb,children:n}))}return t}function eV(e){const t=[],r=n=>{for(const i of n)i.uri!==void 0&&t.push(i),i.children&&r(i.children)};return r(e),t}const tV=8,Qx='[role="menuitem"]',Ug=8;function PA({resources:e,matching:t,chosen:r,stale:n,editable:i,label:s,onChoose:a,triggerLabel:o}){const[l,u]=w.useState(!1),[c,d]=w.useState(""),m=()=>{u(!1),d("")},f=C=>{a(C),m()},{triggerRef:p,popoverRef:g,style:y}=Fi({open:l,onClose:m,matchTriggerWidth:!1,extraContains:C=>{var L;return!!((L=C.closest)!=null&&L.call(C,".pg-source-menu-flyout"))}}),b=w.useMemo(()=>QU(e,t.map(C=>C.uri)),[e,t]),v=w.useMemo(()=>eV(b),[b]),x=v.length>=tV,E=x&&c.trim()?v.filter(C=>C.breadcrumb.toLowerCase().includes(c.trim().toLowerCase())):void 0,T=o?void 0:i?"custom":r?void 0:"placeholder";return h.jsxs("div",{className:"pg-source-picker",children:[h.jsx("button",{ref:p,type:"button",className:o?"pg-resources-add":"pg-slot-source-wrap","aria-haspopup":"menu","aria-expanded":l,"aria-label":o?void 0:`Source for ${s}`,title:o?void 0:"Pick a resource",onClick:()=>u(C=>!C),children:o??h.jsx("span",{className:"pg-slot-source-icon","aria-hidden":"true",children:"⋯"})}),l&&cn.createPortal(h.jsxs("div",{ref:g,className:"pg-source-menu-root",style:y,children:[x&&h.jsx("input",{type:"text",className:"pg-source-menu-filter",placeholder:"Filter…",value:c,onChange:C=>d(C.target.value),autoFocus:!0}),E?h.jsx(rV,{nodes:E,chosen:r,onChoose:f}):h.jsx(zA,{nodes:b,chosen:r,headerKind:T,stale:n,onChoose:f,depth:0,autoFocusFirst:!x})]}),document.body)]})}function rV({nodes:e,chosen:t,onChoose:r}){return h.jsxs("div",{className:"pg-source-menu",role:"menu",children:[e.length===0&&h.jsx("div",{className:"pg-source-menu-empty",children:"No matches"}),e.map(n=>h.jsxs("button",{type:"button",role:"menuitem",className:"pg-source-menu-item"+(n.uri===t?" selected":""),title:n.breadcrumb,onClick:()=>r(n.uri),children:[h.jsx("span",{className:"pg-source-menu-check",children:n.uri===t?"✓":""}),h.jsx("span",{className:"pg-source-menu-label",children:n.label}),h.jsx("span",{className:"pg-source-menu-breadcrumb",children:n.breadcrumb})]},n.uri))]})}function zA({nodes:e,chosen:t,headerKind:r,stale:n,onChoose:i,depth:s,onLeaveLevel:a,autoFocusFirst:o}){const[l,u]=w.useState(null),c=w.useRef(null);w.useEffect(()=>{var f,p;o&&((p=(f=c.current)==null?void 0:f.querySelector(Qx))==null||p.focus())},[]);const d=f=>{var v;const p=c.current;if(!p)return;const g=Array.from(p.querySelectorAll(Qx));if(g.length===0)return;const y=g.indexOf(document.activeElement),b=y<0?0:(y+f+g.length)%g.length;(v=g[b])==null||v.focus()},m=f=>{if(l===null)switch(f.key){case"ArrowDown":f.preventDefault(),d(1);break;case"ArrowUp":f.preventDefault(),d(-1);break;case"ArrowLeft":s>0&&(f.preventDefault(),a==null||a());break;case"Escape":s>0&&(f.preventDefault(),f.stopPropagation(),a==null||a());break}};return h.jsxs("div",{className:"pg-source-menu",role:"menu",ref:c,onKeyDown:m,children:[r==="custom"&&h.jsx(Zx,{label:"Custom",selected:!t,onClick:()=>i(null)}),r==="placeholder"&&h.jsx("div",{className:"pg-source-menu-placeholder",children:"Pick a resource…"}),e.length===0&&!r&&!n&&h.jsx("div",{className:"pg-source-menu-empty",children:"No sources available"}),e.map((f,p)=>h.jsx(nV,{node:f,chosen:t,open:l===p,onOpen:()=>u(p),onClose:()=>u(null),onChoose:i,depth:s},f.uri??`group-${p}-${f.label}`)),n&&h.jsx(Zx,{label:`${n} (unavailable)`,selected:!0,muted:!0,onClick:()=>i(n)})]})}function Zx({label:e,selected:t,muted:r,onClick:n}){return h.jsxs("button",{type:"button",role:"menuitem",className:"pg-source-menu-item"+(t?" selected":"")+(r?" muted":""),onClick:n,children:[h.jsx("span",{className:"pg-source-menu-check",children:t?"✓":""}),h.jsx("span",{className:"pg-source-menu-label",children:e})]})}function nV({node:e,chosen:t,open:r,onOpen:n,onClose:i,onChoose:s,depth:a}){const o=w.useRef(null),l=w.useRef(null),[u,c]=w.useState({}),d=!!e.children&&e.children.length>0,m=!!e.uri&&e.uri===t,f=()=>{var b;if(!d)return;const y=(b=o.current)==null?void 0:b.getBoundingClientRect();if(y){const v=y.right+220>window.innerWidth;c({position:"fixed",top:y.top,maxHeight:window.innerHeight-2*Ug,overflowY:"auto",...v?{right:window.innerWidth-y.left}:{left:y.right},zIndex:1e4+a})}n()};w.useLayoutEffect(()=>{const y=l.current,b=u.top;if(!r||!y||typeof b!="number")return;const v=Math.max(Ug,Math.min(b,window.innerHeight-Ug-y.getBoundingClientRect().height));v!==b&&c({...u,top:v})},[r,u]);const p=()=>{d?f():e.uri&&s(e.uri)},g=y=>{y.key==="ArrowRight"&&d?(y.preventDefault(),f()):y.key==="Enter"&&(y.preventDefault(),p())};return h.jsxs("div",{className:"pg-source-menu-row-wrap",onMouseEnter:d?f:void 0,children:[h.jsxs("button",{ref:o,type:"button",role:"menuitem",className:"pg-source-menu-item"+(m?" selected":""),title:e.breadcrumb,"aria-haspopup":d?"menu":void 0,"aria-expanded":d?r:void 0,onClick:p,onKeyDown:g,children:[h.jsx("span",{className:"pg-source-menu-check",children:m?"✓":""}),h.jsx("span",{className:"pg-source-menu-label",children:e.label}),d&&h.jsx("span",{className:"pg-source-menu-caret","aria-hidden":"true",children:"▸"})]}),d&&r&&cn.createPortal(h.jsx("div",{ref:l,className:"pg-source-menu-flyout",style:u,children:h.jsx(zA,{nodes:e.children,chosen:t,onChoose:s,depth:a+1,autoFocusFirst:!0,onLeaveLevel:()=>{var y;i(),(y=o.current)==null||y.focus()}})}),document.body)]})}function Jx(e,t){if(!e.parent)return e.label;const r=t.get(e.parent);return r?jA(r.label,e.label):e.label}function iV(){}function eS({propDef:e,resources:t,matching:r,chosen:n,onChoose:i,context:s,children:a}){var f;const o=e.type.kind!=="opaque",l=n?r.find(p=>p.uri===n):void 0,u=n&&K4(n)?((f=s==null?void 0:s.describePseudo)==null?void 0:f.call(s,n,e.type))??{note:""}:void 0,c=n&&!l&&!(u!=null&&u.label)?n:void 0,d=w.useMemo(()=>new Map(t.map(p=>[p.uri,p])),[t]);if(r.length===0&&!c&&!u&&o)return h.jsx(h.Fragment,{children:a});const m=u?u.label??(l?Jx(l,d):void 0):void 0;return h.jsxs("div",{className:"pg-slot",children:[h.jsx("div",{className:"pg-slot-body",children:o&&(l==null?void 0:l.value)!==void 0?h.jsx("div",{className:"pg-slot-preview",title:l.uri,children:h.jsx(Ir,{propDef:e,value:$m(l.value),onChange:iV,disabled:!0})}):u&&m!==void 0?h.jsxs("span",{className:"pg-slot-chip pg-slot-chip-pseudo"+(u.warning||u.missing?" pg-slot-chip-warning":""),title:u.warning?`Type mismatch: ${u.warning}`:void 0,children:[u.onOpen?h.jsxs("button",{type:"button",className:"pg-slot-instance-link",title:"Show this resource",onClick:u.onOpen,children:["◆ ",m]}):m,(u.warning||u.note)&&h.jsx("em",{className:"pg-slot-chip-note",children:u.warning?`⚠ ${u.warning}`:u.note})]}):l?h.jsxs("span",{className:"pg-slot-chip",title:l.uri,children:[Jx(l,d),h.jsx("em",{className:"pg-slot-chip-note",children:l.scope==="server"?"created once per server":"created for each run"})]}):c?h.jsx("div",{className:"pg-slot-hint",children:h.jsx("span",{children:"Resource no longer available"})}):o?a:h.jsxs("div",{className:"pg-slot-hint",children:[h.jsx("span",{children:"No editor for this type"}),h.jsx("a",{className:"pg-slot-hint-help",href:"https://example.com/docs/opaque-types",target:"_blank",rel:"noreferrer","aria-label":"Learn more about opaque types",children:"?"})]})}),(r.length>0||c||u)&&h.jsx(PA,{resources:t,matching:r,chosen:n,stale:c,editable:o,label:e.name,onChoose:i})]})}function J4({propDef:e,selection:t,onChange:r,resources:n,slots:i,context:s}){var f;const a=w.useMemo(()=>new Map(n.map(p=>[p.uri,p])),[n]),o=w.useRef(t);o.current=t;const l=w.useRef(r);l.current=r;const u=w.useRef(s);u.current=s;const c=w.useCallback((p,g)=>{var E;const y=o.current,b={...y.resources??{}},v=(E=u.current)==null?void 0:E.adopt,x=g&&!K4(g)&&v?v(g):g;x?b[p]=x:delete b[p],l.current({...y,resources:b})},[]),d=w.useMemo(()=>{const p=new Set(Object.keys(i).filter(y=>y!==e.name));return[{match:(y,b)=>y.kind==="opaque"||p.has($A(e.name,b)),component:y=>{var E;const b=sV(y.path),v=y.path,x=d.map(T=>({...T,match:(C,L)=>L!==v&&T.match(C,L)}));return h.jsx(eS,{propDef:y.propDef,resources:n,matching:tS(i,e.name,y.path,a),chosen:(E=o.current.resources)==null?void 0:E[b],onChoose:T=>c(b,T),context:u.current,children:h.jsx(Ir,{propDef:y.propDef,value:y.value,onChange:y.onChange,plugins:x,path:y.path})})}}]},[i,e.name,a,c,n]),m=tS(i,e.name,[e.name],a);return h.jsx(eS,{propDef:e,resources:n,matching:m,chosen:(f=t.resources)==null?void 0:f[hl],onChoose:p=>c(hl,p),context:s,children:h.jsx(Ir,{propDef:e,value:t.value,onChange:p=>r({...t,value:p}),plugins:d,path:[e.name]})})}function $A(e,t){return(t??[e]).join(".")}function sV(e){return(e??[]).slice(1).join(".")}function tS(e,t,r,n){return(e[$A(t,r)]??[]).map(s=>n.get(s)).filter(s=>!!s&&!s.error)}function aV(e){return((e==null?void 0:e.resources)??[]).filter(t=>!!t.error)}function oV({propDef:e,groups:t,selection:r,onChange:n,resources:i,slots:s,overwritten:a,context:o}){const l=GU(t);return h.jsx(h.Fragment,{children:t.map(u=>{const c={name:u.name,type:u.type,optional:u.optional},d=uV(s,e.name,u),m=(a==null?void 0:a[u.name])??[];return h.jsxs("div",{className:"pg-exec-param pg-combined-row",children:[h.jsxs("div",{className:"pg-exec-param-label",children:[h.jsxs("span",{className:"pg-exec-param-name",children:[u.name,u.optional?"":" *"]}),h.jsx("span",{className:"pg-exec-param-type",title:u.type.syntax,children:bd(u.type.syntax,60)}),h.jsx("span",{className:"pg-combined-members",children:lV(u,l)})]}),m.length>0&&h.jsxs("div",{className:"pg-combined-note",children:["Overwrote ",m.join(", ")]}),d.length>0&&h.jsxs("div",{className:"pg-combined-note",children:[d.length===1?"A matching resource is":`${d.length} matching resources are`," ","pinned to only some members and isn't offered here."]}),h.jsx(J4,{propDef:c,selection:r.fields[u.name]??{},onChange:f=>n({fields:{...r.fields,[u.name]:f}}),resources:i,slots:cV(s,e.name,u),context:o})]},u.name)})})}function lV(e,t){return e.members.length===t?`all ${t}`:e.members.join(", ")}function HA(e,t,r){const n=r.members.map(a=>new Set(e[`${t}.${a}.${r.name}`]??[])),[i,...s]=n;return i?[...i].filter(a=>s.every(o=>o.has(a))):[]}function uV(e,t,r){const n=new Set(r.members.flatMap(s=>e[`${t}.${s}.${r.name}`]??[])),i=new Set(HA(e,t,r));return[...n].filter(s=>!i.has(s))}function cV(e,t,r){const n=r.members[0],i=`${t}.${n}.`,s=`${i}${r.name}`,a={};for(const[o,l]of Object.entries(e))(o===s||o.startsWith(`${s}.`))&&(a[o.slice(i.length)]=l);return a[r.name]=HA(e,t,r),a}function hV(e){const t=Object.entries(e);if(t.length!==0)return Object.fromEntries(t.map(([r,{uri:n,args:i}])=>{const s=Object.fromEntries(Object.entries(i).flatMap(([a,o])=>{const l=Gi(o);return l?[[a,l]]:[]}));return[r,Object.keys(s).length>0?{uri:n,args:s}:{uri:n}]}))}function FA(e){if(!e||typeof e!="object")return{};const t={};for(const[r,n]of Object.entries(e))!n||typeof n.uri!="string"||(t[r]={uri:n.uri,args:Object.fromEntries(Object.entries(n.args??{}).map(([i,s])=>[i,dl(s)]))});return t}function UA(e,t){const r=new Set(t);let i=(e.slice(e.lastIndexOf("#")+1).split(".")[0]??"").replace(/[^A-Za-z0-9_-]/g,"_");if(dA(i)||(i=`r_${i}`),!r.has(i))return i;for(let s=2;;s++)if(!r.has(`${i}${s}`))return`${i}${s}`}function VA(e,t){const r=UA(t,Object.keys(e));return{instances:{...e,[r]:{uri:t,args:{}}},name:r}}function dV(e,t,r){var o;const n=r.get(t),i=(n==null?void 0:n.parent)??t,s=n!=null&&n.parent?t.slice(n.parent.length+1):void 0;if(((o=r.get(i))==null?void 0:o.scope)==="server"){const l=Object.entries(e).find(([,u])=>u.uri===i);if(l)return{instances:e,uri:oa(l[0],s)}}const a=VA(e,i);return{instances:a.instances,uri:oa(a.name,s)}}function fV(e,t,r){if(!e.resources)return e;let n=!1;const i={};for(const[s,a]of Object.entries(e.resources)){const o=Bl(a);if((o==null?void 0:o.name)!==t){i[s]=a;continue}n=!0,r!==null&&(i[s]=oa(r,o.output))}return n?Object.keys(i).length>0?{...e,resources:i}:(({resources:s,...a})=>a)(e):e}function Gm(e,t,r){let n=!1;const i={};for(const[s,a]of Object.entries(e)){const o=fV(a,t,r);o!==a&&(n=!0),i[s]=o}return n?i:e}function mV(e,t,r){if(t===r)return e;const n=qA(r,e,t);if(n)throw new Error(n);return Object.fromEntries(Object.entries(e).map(([i,s])=>[i===t?r:i,{...s,args:Gm(s.args,t,r)}]))}function qA(e,t,r){if(!dA(e))return"Use letters, digits, '_' and '-', not starting with a digit or '-'.";if(e!==r&&Object.hasOwn(t,e))return`There's already a resource named '${e}'.`}function pV(e,t){return Object.fromEntries(Object.entries(e).filter(([r])=>r!==t).map(([r,n])=>[r,{...n,args:Gm(n.args,t,null)}]))}function gV(e,t){const r=e[t];if(!r)return{instances:e,name:t};const n=UA(t.replace(/\d+$/,"")||t,Object.keys(e)),i={};for(const[s,a]of Object.entries(e))i[s]=a,s===t&&(i[n]={uri:r.uri,args:structuredClone(r.args)});return{instances:i,name:n}}function rS(e,t,r){return Object.entries((e==null?void 0:e.resources)??{}).flatMap(([n,i])=>{var s;return((s=Bl(i))==null?void 0:s.name)===t?[n===""?r:`${r}.${n}`]:[]})}function bV(e,t,r){const n=[];for(const{prefix:i,selections:s}of r)for(const[a,o]of Object.entries(s))n.push(...rS(o,e,i?`${i}.${a}`:a));for(const[i,s]of Object.entries(t))if(i!==e)for(const[a,o]of Object.entries(s.args))n.push(...rS(o,e,`${i}.${a}`));return n}function _V(e){const t=new Set;for(const r of Object.values(e.args))for(const n of Object.values(r.resources??{})){const i=Bl(n);i&&t.add(i.name)}return t}function vV(e,t){const r=new Set([t]);let n=!0;for(;n;){n=!1;for(const[i,s]of Object.entries(e))r.has(i)||[..._V(s)].some(a=>r.has(a))&&(r.add(i),n=!0)}return r}function yV(e,t){const r=new Map;for(const[s,a]of Object.entries(e))r.set(a.uri,[...r.get(a.uri)??[],s]);const n=new Map,i=(s,a,o)=>{var l,u;for(const c of Object.values(((l=t.get(s))==null?void 0:l.dependencies)??{})){const d=r.get(c)??[];if(d.length===1)continue;let m=n.get(c);m||(m={uri:c,usedBy:[],...d.length>1&&{ambiguous:d}},n.set(c,m)),m.usedBy.includes(a)||m.usedBy.push(a),d.length===0&&!o.has(c)&&i(c,((u=t.get(c))==null?void 0:u.label)??c,new Set([...o,c]))}};for(const[s,a]of Object.entries(e))i(a.uri,s,new Set([a.uri]));return[...n.values()]}const xV=1200;function SV(e,t){e.scrollIntoView({behavior:"smooth",block:t}),e.classList.remove("pg-row-highlight"),e.offsetWidth,e.classList.add("pg-row-highlight"),window.setTimeout(()=>e.classList.remove("pg-row-highlight"),xV)}function GA(e){const t=document.querySelector(`[data-instance-card="${CSS.escape(e)}"]`);t&&SV(t,"center")}function wV({instances:e,onChange:t,sources:r,catalog:n,referencedBy:i,context:s}){const a=w.useMemo(()=>new Map(n.map(f=>[f.uri,f])),[n]),o=Object.entries(e),l=yV(e,a),u=n.filter(f=>!f.parent&&!f.error&&!((f.scope==="server"||f.value!==void 0)&&o.some(([,p])=>p.uri===f.uri))),c=w.useRef(null);w.useEffect(()=>{const f=c.current;f===null||!Object.hasOwn(e,f)||(c.current=null,GA(f))},[e]);const d=f=>{c.current=f.name,t(f.instances)},m=f=>{f&&d(VA(e,f))};return h.jsxs("section",{className:"pg-resources","aria-label":"Resources",children:[h.jsxs("div",{className:"pg-resources-header",children:[h.jsx("span",{className:"pg-resources-title",children:"Resources"}),u.length>0&&h.jsx(PA,{resources:n,matching:u,chosen:void 0,stale:void 0,editable:!1,label:"Resources",triggerLabel:"+ Add resource",onChoose:m})]}),o.map(([f,p])=>h.jsx(kV,{name:f,instances:e,resource:a.get(p.uri),onChange:t,onDuplicate:()=>d(gV(e,f)),sources:r,referencedBy:i(f),context:s},f)),l.map(f=>{const p=a.get(f.uri);return h.jsxs("div",{className:"pg-resource-card pg-resource-dependency",children:[h.jsxs("div",{className:"pg-resource-head",children:[h.jsxs("span",{className:"pg-resource-name",children:["◆ ",(p==null?void 0:p.label)??f.uri]}),h.jsxs("span",{className:"pg-resource-meta",children:[WA(p)," · dependency"]}),!f.ambiguous&&h.jsx("button",{type:"button",className:"pg-resource-action","aria-label":`Add ${(p==null?void 0:p.label)??f.uri} to the run explicitly`,title:"Add to the run explicitly (to set arguments or a name)",onClick:()=>m(f.uri),children:h.jsx(Zd,{})})]}),h.jsx("div",{className:"pg-resource-refs"+(f.ambiguous?" pg-resource-refs-warning":""),children:f.ambiguous?`⚠ ${f.usedBy.join(", ")} can't tell which to use: ${f.ambiguous.join(", ")}`:`implicit instance for ${f.usedBy.join(", ")}`})]},f.uri)})]})}function WA(e){return(e==null?void 0:e.scope)==="server"?"shared":"per run"}function EV(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[h.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),h.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function kV({name:e,instances:t,resource:r,onChange:n,onDuplicate:i,sources:s,referencedBy:a,context:o}){var L;const l=t[e],[u,c]=w.useState(null),[d,m]=w.useState(!1),f=()=>m(!1),{triggerRef:p,popoverRef:g,style:y}=Fi({open:d,onClose:f,matchTriggerWidth:!1}),b=u===null?void 0:qA(u,t,e),v=()=>{u!==null&&(!b&&u!==e&&n(mV(t,e,u),{kind:"rename",from:e,to:u}),c(null))},x=()=>{a.length>0&&!window.confirm(`Remove '${e}'? ${a.join(", ")} will be cleared.`)||n(pV(t,e),{kind:"remove",name:e})},E=vV(t,e),T=Object.fromEntries(Object.entries(((L=s.resourceSlots)==null?void 0:L[l.uri])??{}).map(([A,z])=>[A,z.filter(I=>{const B=Bl(I);return!B||!E.has(B.name)})])),C=(r==null?void 0:r.parameters)??[];return h.jsxs("div",{className:"pg-resource-card","data-instance-card":e,children:[h.jsxs("div",{className:"pg-resource-head",children:[u===null?h.jsxs("button",{type:"button",className:"pg-resource-name pg-resource-rename",title:"Rename",onClick:()=>c(e),children:["◆ ",e," ",h.jsx("span",{"aria-hidden":"true",children:"✎"})]}):h.jsx("input",{className:"pg-resource-name-input","aria-label":`Name for ${e}`,"aria-invalid":!!b,title:b,value:u,autoFocus:!0,onChange:A=>c(A.target.value),onBlur:v,onKeyDown:A=>{A.key==="Enter"&&v(),A.key==="Escape"&&c(null)}}),h.jsxs("span",{className:"pg-resource-meta",title:l.uri,children:[r?r.label:"Resource no longer available",r&&` · ${WA(r)}`]}),h.jsxs("span",{className:"pg-resource-actions",children:[h.jsx("button",{type:"button",ref:p,className:"pg-resource-action pg-resource-menu-trigger","aria-label":`Actions for ${e}`,"aria-haspopup":"menu","aria-expanded":d,title:"Actions",onClick:()=>m(A=>!A),children:h.jsx(EV,{})}),d&&cn.createPortal(h.jsxs("div",{className:"trace-header-menu",ref:g,style:y,role:"menu",children:[(r==null?void 0:r.scope)!=="server"&&h.jsx("button",{type:"button",role:"menuitem",className:"trace-header-menu-item",onClick:()=>{f(),i()},children:h.jsx("span",{className:"trace-header-menu-item-label",children:"Duplicate"})}),h.jsx("button",{type:"button",role:"menuitem",className:"trace-header-menu-item","aria-label":`Remove ${e}`,onClick:()=>{f(),x()},children:h.jsx("span",{className:"trace-header-menu-item-label",children:"Remove"})})]}),document.body)]})]}),b&&h.jsx("div",{className:"pg-resource-refs-warning",children:b}),h.jsx("div",{className:"pg-resource-refs",children:a.length>0?`→ ${a.join(", ")}`:"not bound to a slot: runs for its side effects"}),C.length>0&&h.jsx("div",{className:"pg-args-form",children:C.map(A=>h.jsxs("div",{className:"pg-args-row",children:[h.jsx("span",{className:"pg-args-name",children:A.name}),A.description&&h.jsx("div",{className:"pg-exec-param-desc",children:A.description}),h.jsx(J4,{propDef:A,selection:l.args[A.name]??{},onChange:z=>n(I=>{const B=I[e];return B?{...I,[e]:{...B,args:{...B.args,[A.name]:z}}}:I}),resources:s.resources,slots:T,context:o})]},A.name))})]})}function CV({instances:e,catalogByUri:t,adopt:r,describeOther:n,rowsMayDeclare:i}){return{adopt:r,describePseudo:(s,a)=>{const o=UU(s,e,t,{rowsMayDeclare:i});if(!o)return n==null?void 0:n(s,a);const l=Bl(s),u=Object.hasOwn(e,l.name);return{...o,...u&&{onOpen:()=>GA(l.name)}}}}}function TV(e,t,r){const[n,i]=w.useState(e),s=w.useRef(n),a=w.useRef(t);a.current=t;const o=w.useRef(r);o.current=r;const l=w.useCallback(c=>{var m;const d=typeof c=="function"?c(s.current):c;d!==s.current&&(s.current=d,i(d),(m=o.current)==null||m.call(o,d))},[]),u=w.useCallback(c=>{const d=dV(s.current,c,a.current);return l(d.instances),d.uri},[l]);return{instances:n,setInstances:l,adopt:u}}const nS=new Set;function AV({name:e,reason:t}){return h.jsxs(h.Fragment,{children:[h.jsx("code",{children:e}),t==="resource-out-of-scope"?" uses a resource this prompt can't see":" has no matching parameter"]})}const NV=[],RV=[];function iS(e,t){return Object.fromEntries(e.flatMap(r=>{const n=Gi(t[r.name]);return n?[[r.name,n]]:[]}))}function Wm(e={}){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,dl(r)]))}function LV(e){var r,n;const t={fn:{},exec:{},layout:{fn:{},exec:{}},instances:{}};try{const i=localStorage.getItem(Q4(e));if(!i)return t;const s=JSON.parse(i);return!s||typeof s!="object"?t:{fn:Wm(s.functionInputs),exec:Wm(s.executeInputs),layout:{fn:((r=s.layout)==null?void 0:r.functionSlots)??{},exec:((n=s.layout)==null?void 0:n.executeSlots)??{}},instances:FA(s.resources)}}catch{return t}}function F0(e,t,r,n){const i={...e[t]};return n===void 0?delete i[r]:i[r]=n,{...e,[t]:i}}function IV({prompt:e,promptRef:t,runDisabledReason:r,onExecuted:n,fill:i,onOpenFillSource:s,onOpenDataset:a}){var Pe;const o=w.useState(()=>LV(e))[0],[l,u]=w.useState(o.fn),[c,d]=w.useState(o.exec),[m,f]=w.useState(o.layout),[p,g]=w.useState({fn:{},exec:{}}),[y,b]=w.useState(!1),[v,x]=w.useState(null),[E,T]=w.useState(null),C=e.executeParameters??NV,L=aV(e.inputSources),A=((Pe=e.inputSources)==null?void 0:Pe.resources)??RV,z=w.useMemo(()=>new Map(A.map(ee=>[ee.uri,ee])),[A]),{instances:I,setInstances:B,adopt:j}=TV(o.instances,z),G=w.useMemo(()=>{const ee=hV(I);return{functionInputs:iS(e.functionParameters,l),executeInputs:iS(C,c),...ee&&{resources:ee}}},[e.functionParameters,C,l,c,I]),W=AA(PU(FU(e.inputSources,I),{functionParameters:e.functionParameters,executeParameters:C,bindings:G}));w.useEffect(()=>{try{localStorage.setItem(Q4(e),JSON.stringify({functionInputs:G.functionInputs,executeInputs:G.executeInputs,...G.resources&&{resources:G.resources},layout:{functionSlots:m.fn,executeSlots:m.exec}}))}catch{}},[G,m]);const Y=ee=>(oe,Be)=>{const we=ee==="fn"?{...l,[oe]:Be}:l,_e=ee==="exec"?{...c,[oe]:Be}:c;u(we),d(_e)},V=(ee,oe)=>{if(B(ee),!oe)return;const[Be,we]=oe.kind==="rename"?[oe.from,oe.to]:[oe.name,null];u(_e=>Gm(_e,Be,we)),d(_e=>Gm(_e,Be,we))},X=CV({instances:I,catalogByUri:z,adopt:j,describeOther:(ee,oe)=>zU(ee,oe,{functionParameters:e.functionParameters,executeParameters:C})}),P=(ee,oe,Be)=>{var je,Ke,Le;const we=ee==="fn"?l:c,_e=(Le=ee==="fn"?(je=e.inputLayout)==null?void 0:je.functionSlots:(Ke=e.inputLayout)==null?void 0:Ke.executeSlots)==null?void 0:Le[oe.name];return KU(Be,Gi(we[oe.name]),m[ee][oe.name],_e)};w.useEffect(()=>{const ee=(we,_e,je)=>{let Ke=je;for(const Le of _e){const it=Kx(Le);if(!Xx(it)||P(we,Le,it)!=="combined")continue;const zt=YU(it,Gi(je[Le.name]));zt&&(Ke={...Ke,[Le.name]:dl(zt.input)},g(ot=>F0(ot,we,Le.name,zt.overwritten)))}return Ke},oe=ee("fn",e.functionParameters,l),Be=ee("exec",C,c);oe!==l&&u(oe),Be!==c&&d(Be)},[l,c,m,e]);const re=(ee,oe,Be,we)=>{let _e=l,je=c;if(we==="combined"){const Le=Gi((ee==="fn"?_e:je)[oe.name]),{selection:it,overwritten:zt}=g_(Be,Le),ot=dl(b_(Be,it));ee==="fn"?_e={..._e,[oe.name]:ot}:je={...je,[oe.name]:ot},u(_e),d(je),g(Br=>F0(Br,ee,oe.name,zt))}else g(Ke=>F0(Ke,ee,oe.name,void 0));f(F0(m,ee,oe.name,we))},R=({requireAll:ee})=>{const oe={};for(const we of e.functionParameters){const _e=Gi(l[we.name]);_e&&(oe[we.name]=_e);const je=ee&&(_e||!we.optional&&we.defaultValue===void 0)&&Yx(we,_e,!!e.inputSources);if(je)return x(je),null}const Be={};for(const we of C){const _e=Gi(c[we.name]);_e&&(Be[we.name]=_e);const je=ee&&(_e||!we.optional)&&Yx(we,_e,!!e.inputSources);if(je)return x(je),null}return{functionInputs:oe,executeInputs:Be,...G.resources&&{resources:G.resources}}},de=()=>{const ee=R({requireAll:!0});return ee?{functionInputs:e.functionParameters.map(Be=>ee.functionInputs[Be.name]??(Be.defaultValue?{kind:"value",value:Be.defaultValue}:{kind:"value",value:{kind:"primitive",value:void 0}})),executeInputs:ee.executeInputs,...ee.resources&&{resources:ee.resources}}:null};w.useEffect(()=>{if(!i||nS.has(i.nonce))return;nS.add(i.nonce);const ee=[...e.functionParameters.filter(oe=>!(oe.name in i.functionInputs)&&Gi(l[oe.name])).map(oe=>oe.name),...C.filter(oe=>!(oe.name in i.executeInputs)&&Gi(c[oe.name])).map(oe=>oe.name)];if(u({...l,...Wm(i.functionInputs)}),d({...c,...Wm(i.executeInputs)}),i.resources){const oe=FA(i.resources);B(Be=>({...Be,...oe}))}T({from:i.from,kept:ee,skipped:i.skipped})},[i==null?void 0:i.nonce]);const Te=PF(e,R({requireAll:!1})??{functionInputs:{},executeInputs:{}}),H=async()=>{x(null);const ee=de();if(ee){b(!0);try{const oe=await SH(e,ee,t);n==null||n({...oe,label:e.name})}catch(oe){x(oe.message)}finally{b(!1)}}},Oe=(ee,oe,Be,we)=>ee.map(_e=>{const je=Kx(_e),Ke=Xx(je),Le=Ke?P(we,_e,je):"expanded";return h.jsxs("div",{className:"pg-exec-param",children:[h.jsxs("div",{className:"pg-exec-param-label",children:[h.jsxs("span",{className:"pg-exec-param-name",children:[_e.name,_e.optional?"":" *"]}),h.jsx("span",{className:"pg-exec-param-type",title:_e.type.syntax,children:bd(_e.type.syntax,60)})]}),_e.description&&h.jsx("div",{className:"pg-exec-param-desc",children:_e.description}),Ke&&h.jsx("div",{className:"pg-combined-toggle",children:h.jsx("div",{className:"pg-layout-tabs",role:"tablist","aria-label":`Layout for ${_e.name}`,children:["expanded","combined"].map(it=>h.jsx("button",{type:"button",role:"tab","aria-selected":Le===it,className:`pg-layout-tab${Le===it?" pg-layout-tab-active":""}`,onClick:()=>re(we,_e,je,it),children:it==="expanded"?"Expanded":"Combined"},it))})}),Le==="combined"?h.jsx(oV,{propDef:_e,groups:je,selection:g_(je,Gi(oe[_e.name])).selection,onChange:it=>Y(we)(_e.name,dl(b_(je,it))),resources:(W==null?void 0:W.resources)??[],slots:Be,overwritten:p[we][_e.name],context:X}):h.jsx(J4,{propDef:_e,selection:oe[_e.name]??{},onChange:it=>Y(we)(_e.name,it),resources:(W==null?void 0:W.resources)??[],slots:Be,context:X})]},_e.name)});return h.jsxs(sU,{title:"Execute",actions:e.providerId&&h.jsx(d_,{inputs:Te,resources:G.resources,newDatasetFields:C9(e),prompt:{link:{id:e.globalId??e.id,providerId:e.providerId},openable:{id:e.id,providerId:e.providerId}},source:{kind:"playground",promptId:e.id,providerId:e.providerId},disabled:Te.length===0,onOpenDataset:a}),error:v,onDismissError:()=>x(null),footer:h.jsx("button",{type:"button",className:"pg-run-btn",onClick:H,disabled:y||!!r,title:r,children:y?"…":"▶ Run"}),children:[E&&h.jsxs("div",{className:"pg-exec-fill-notice",role:"status",children:[h.jsxs("span",{children:["Filled from"," ",s?h.jsxs("button",{type:"button",className:"pg-exec-fill-link",onClick:ee=>{ee.stopPropagation(),s(E.from)},title:E.from.description,children:[E.from.type," ↗"]}):E.from.type,E.kept.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("br",{}),"Not filled: ",E.kept.map((ee,oe)=>h.jsxs("span",{children:[oe>0&&", ",h.jsx("code",{children:ee})]},ee))]})]}),E.skipped.map(ee=>h.jsx("span",{className:"pg-exec-fill-skipped",children:AV(ee)},ee.name)),h.jsx("button",{type:"button",className:"pg-dismiss","aria-label":"Dismiss",onClick:()=>T(null),children:"×"})]}),Oe(e.functionParameters,l,(W==null?void 0:W.functionSlots)??{},"fn"),C.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"pg-exec-section"}),Oe(C,c,(W==null?void 0:W.executeSlots)??{},"exec")]}),(A.length>0||Object.keys(I).length>0)&&h.jsx(wV,{instances:I,onChange:V,sources:W,catalog:A,referencedBy:ee=>bV(ee,I,[{selections:l},{selections:c}]),context:X}),L.map(ee=>h.jsxs("div",{className:"pg-exec-error",children:["Playground module ",h.jsx("code",{children:ee.uri})," failed to load: ",ee.error]},ee.uri))]})}const DV=2e3;function sS(e){return e.split(/(\s+)/).filter(t=>t!=="")}function OV(e,t){const r=sS(e),n=sS(t);let i=0;for(;i<r.length&&i<n.length&&r[i]===n[i];)i++;let s=r.length,a=n.length;for(;s>i&&a>i&&r[s-1]===n[a-1];)s--,a--;const o=[],l=(u,c)=>{if(!c)return;const d=o.at(-1);(d==null?void 0:d.type)===u?d.text+=c:o.push({type:u,text:c})};l("same",r.slice(0,i).join(""));for(const u of MV(r.slice(i,s),n.slice(i,a)))l(u.type,u.text);return l("same",r.slice(s).join("")),o}function MV(e,t){const r=e.length,n=t.length;if(r===0||n===0)return[...r?[{type:"del",text:e.join("")}]:[],...n?[{type:"add",text:t.join("")}]:[]];const i=Math.min(r+n,DV),s=i+1;let a=new Int32Array(2*i+3);const o=[];let l=!1;for(let m=0;m<=i&&!l;m++){o.push(a.slice());const f=a.slice();for(let p=-m;p<=m;p+=2){let g=p===-m||p!==m&&a[s+p-1]<a[s+p+1]?a[s+p+1]:a[s+p-1]+1,y=g-p;for(;g<r&&y<n&&e[g]===t[y];)g++,y++;if(f[s+p]=g,g>=r&&y>=n){l=!0;break}}a=f}if(!l)return[{type:"del",text:e.join("")},{type:"add",text:t.join("")}];const u=[];let c=r,d=n;for(let m=o.length-1;m>=0;m--){const f=o[m],p=c-d,g=p===-m||p!==m&&f[s+p-1]<f[s+p+1]?p+1:p-1,y=f[s+g],b=y-g;for(;c>y&&d>b;)u.push({type:"same",text:e[--c]}),d--;if(m===0)break;c===y?u.push({type:"add",text:t[--d]}):u.push({type:"del",text:e[--c]})}return u.reverse()}function xc(e){return e.names.length>0?e.names[0]:e.wip?"unsaved edits":`variation ${zi(e.id)}`}function Uf(e){return!e||e.version===void 0&&e.variation===void 0}function jV(e,t){if(!Uf(t))return t;if(e.wipId)return{promptId:e.id,variation:e.wipId}}function BV(e){var t;return!!((t=e.variation)!=null&&t.wip)&&!!e.variation.onHead}function PV(e,t){const{variation:r,version:n,dirty:i,wipId:s,...a}=t;return{...e,...a,ref:{promptId:e.id},atHead:!0,dirty:void 0,wipId:void 0}}function zV(e){var n,i;const t=e.variation,r=e.version?zi(e.version.id):void 0;if(t!=null&&t.wip)return`${t.onHead?"Working tree":r??"Old version"} · ● unsaved`;if(t){const s=xc(t);return e.atHead===!1&&r?`${s} · on ${r}`:s}return(n=e.ref)!=null&&n.version&&r?(i=e.version)!=null&&i.message?`${r} · ${e.version.message}`:r:e.dirty?"Working tree · ● unsaved":"Working tree"}function $V(e){return e.variation?xc(e.variation):e.version?zi(e.version.id):"this version"}function YA(e){return!!e.variation&&!e.variation.wip}function HV(e){const t={modelEditable:!1,modelParametersEditable:!1};return e.style==="chat"?{...e,...t,systemEditable:!1,messagesEditable:!1}:{...e,...t,stateEditable:!1,questionsEditable:!1}}function FV(e){const t=YA(e),r=e.atHead===!1;if(t&&r)return"Saved variations are read-only, and run only on the working tree.";if(t)return"Saved variations are read-only.";if(r)return"Running is only available on the working tree."}function UV(e){var t;if((t=e.variation)!=null&&t.pending)return"Resolve the conflicts before running.";if(e.atHead===!1)return"Running is only available on the working tree."}function aS(e){return e==null?"":Array.isArray(e)?e.map(t=>t&&typeof t=="object"&&"role"in t?`${t.role}: ${Vf(t.content)}`:Vf(t)).join(`
85
85
 
86
86
  `):Vf(e)}function Vf(e){if(e==null)return"(not set)";if(Array.isArray(e))return e.length===0?"(none)":`${e.length} message${e.length===1?"":"s"}`;if(typeof e!="object")return String(e);const t=e;if(typeof t.displayValue=="string")return t.displayValue;switch(t.kind){case"primitive":return typeof t.value=="string"?t.value:String(t.value);case"template":return t.value.map(r=>typeof r=="string"?r:`\${${r.expr}}`).join("");case"functionCall":return`${t.callee}(${t.args.map(Vf).join(", ")})`;case"reference":return t.path.join(".");case"raw":return t.sourceText;default:return JSON.stringify(e)}}const VV=30;function qV(e){const t=Math.round((Date.now()-e)/1e3);if(t<60)return"just now";const r=Math.round(t/60);if(r<60)return`${r}m ago`;const n=Math.round(r/60);return n<48?`${n}h ago`:new Date(e).toLocaleDateString()}function GV({head:e,shown:t,onSelect:r}){var C,L;const[n,i]=w.useState(!1),[s,a]=w.useState(null),[o,l]=w.useState(null),[u,c]=w.useState(null),d=w.useCallback(()=>i(!1),[]),{triggerRef:m,popoverRef:f,style:p}=Fi({open:n,onClose:d,matchTriggerWidth:!1});w.useEffect(()=>{if(!n)return;let A=!1;return c(null),Promise.all([EH(e).catch(()=>[]),wH(e,{limit:VV})]).then(([z,I])=>{A||(a(z),l(I))}).catch(z=>!A&&c(z.message)),()=>{A=!0}},[n,e]);const g=A=>{i(!1),r(A)},y=t.ref,b=A=>(A.variation??void 0)===((y==null?void 0:y.variation)??void 0)&&(A.version??void 0)===((y==null?void 0:y.version)??void 0),v=e.providerId??"",x=(s??[]).filter(A=>!A.wip),E=(s??[]).filter(A=>A.wip&&!A.onHead),T=n&&cn.createPortal(h.jsxs("div",{className:"pg-ref-menu",ref:f,style:p,role:"menu",children:[h.jsx("button",{type:"button",role:"menuitem",className:"pg-ref-item","aria-current":!(y!=null&&y.version)&&!(y!=null&&y.variation)||((C=t.variation)==null?void 0:C.wip)&&t.variation.onHead,onClick:()=>g(void 0),children:h.jsxs("span",{className:"pg-ref-item-name",children:["Working tree",e.dirty&&h.jsx("span",{className:"pg-ref-dot",children:" ● unsaved"})]})}),u&&h.jsx("div",{className:"pg-ref-error",children:u}),!o&&!u&&h.jsx("div",{className:"pg-ref-empty",children:"Loading…"}),x.length>0&&h.jsx("div",{className:"pg-ref-heading",children:"Variations"}),x.map(A=>h.jsx(WV,{variation:A,current:b({variation:A.id}),onPick:()=>g({promptId:e.id,variation:A.id}),onRename:async z=>{const I=await LH(v,A.id,A.names[0],z);a(B=>(B??[]).map(j=>j.id===A.id?I:j))},onDelete:async()=>{await IH(v,A),a(z=>(z??[]).filter(I=>I.id!==A.id)),b({variation:A.id})&&g(void 0)}},A.id)),E.length>0&&h.jsx("div",{className:"pg-ref-heading",children:"Unsaved edits to old versions"}),E.map(A=>h.jsxs("button",{type:"button",role:"menuitem",className:"pg-ref-item","aria-current":b({variation:A.id}),onClick:()=>g({promptId:e.id,variation:A.id}),children:[h.jsx("span",{className:"pg-ref-item-name",children:"● unsaved"}),h.jsx("span",{className:"pg-ref-item-meta",children:A.base?`on ${zi(A.base)}`:"on uncommitted changes"})]},A.id)),o&&o.length>0&&h.jsx("div",{className:"pg-ref-heading",children:"History"}),o==null?void 0:o.map(A=>h.jsxs("button",{type:"button",role:"menuitem",className:"pg-ref-item","aria-current":b({version:A.id}),onClick:()=>g({promptId:e.id,version:A.id}),title:A.message,children:[h.jsxs("span",{className:"pg-ref-item-name",children:[h.jsx("code",{children:zi(A.id)}),A.message&&h.jsxs("span",{className:"pg-ref-item-message",children:[" ",A.message]})]}),h.jsx("span",{className:"pg-ref-item-meta",children:qV(A.time)})]},A.id)),(o==null?void 0:o.length)===0&&h.jsx("div",{className:"pg-ref-empty",children:"No saved versions yet"})]}),document.body);return h.jsxs(h.Fragment,{children:[h.jsxs("button",{type:"button",ref:m,className:"pg-ref-chip"+((L=t.variation)!=null&&L.wip||e.dirty?" pg-ref-chip--dirty":"")+(t.atHead===!1?" pg-ref-chip--old":""),onClick:()=>i(A=>!A),"aria-haspopup":"menu","aria-expanded":n,title:"Versions and variations",children:[h.jsx("span",{className:"pg-ref-chip-label",children:zV(t)}),h.jsx("span",{className:"pg-ref-chip-caret",children:"▾"})]}),T]})}function WV({variation:e,current:t,onPick:r,onRename:n,onDelete:i}){const s=xc(e),[a,o]=w.useState(!1),[l,u]=w.useState(s),[c,d]=w.useState(!1),[m,f]=w.useState(null),p=async g=>{d(!0),f(null);try{return await g(),!0}catch(y){return f((y==null?void 0:y.message)??String(y)),!1}finally{d(!1)}};if(a){const g=()=>{o(!1),f(null)};return h.jsxs("form",{className:"pg-ref-rename",onSubmit:async y=>{y.preventDefault();const b=l.trim();if(!b||b===s)return g();await p(()=>n(b))&&o(!1)},children:[h.jsx("input",{autoFocus:!0,className:"pg-ref-name-input","aria-label":"Variation name",value:l,disabled:c,onFocus:y=>y.currentTarget.select(),onChange:y=>u(y.target.value),onKeyDown:y=>{y.key==="Escape"&&(y.stopPropagation(),g())}}),h.jsx("button",{type:"submit",className:"pg-ref-btn",disabled:c,children:"Rename"}),m&&h.jsx("div",{className:"pg-ref-error",children:m})]})}return h.jsxs("div",{className:"pg-ref-row",children:[h.jsxs("button",{type:"button",role:"menuitem",className:"pg-ref-item","aria-current":t,onClick:r,children:[h.jsx("span",{className:"pg-ref-item-name",children:s}),h.jsx("span",{className:"pg-ref-item-meta",children:e.base?`on ${zi(e.base)}`:"on uncommitted changes"})]}),h.jsxs("div",{className:"pg-ref-row-actions",children:[h.jsx("button",{type:"button",className:"pg-ref-row-btn","aria-label":`Rename ${s}`,title:"Rename",disabled:c,onClick:()=>{u(s),o(!0)},children:"✎"}),h.jsx("button",{type:"button",className:"pg-ref-row-btn","aria-label":`Delete ${s}`,title:"Delete",disabled:c,onClick:()=>{window.confirm(`Delete the variation "${s}"? Traces that ran it can still open it.`)&&p(i)},children:"×"})]}),m&&h.jsx("div",{className:"pg-ref-error",children:m})]})}function YV({shown:e,busy:t,onSave:r,onDiscard:n,onSaveAs:i}){const[s,a]=w.useState(!1),[o,l]=w.useState(""),u=e.variation;return u!=null&&u.pending?null:s?h.jsxs("form",{className:"pg-ref-actions",onSubmit:c=>{c.preventDefault(),o.trim()&&(i(o.trim()),a(!1),l(""))},children:[h.jsx("input",{autoFocus:!0,className:"pg-ref-name-input",placeholder:"Variation name","aria-label":"Variation name",value:o,onChange:c=>l(c.target.value),onKeyDown:c=>c.key==="Escape"&&a(!1)}),h.jsx("button",{type:"submit",className:"pg-ref-btn",disabled:t,children:"Save"}),h.jsx("button",{type:"button",className:"pg-ref-btn pg-ref-btn--quiet",onClick:()=>a(!1),children:"Cancel"})]}):h.jsxs("div",{className:"pg-ref-actions",children:[(u==null?void 0:u.wip)&&u.onHead&&h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",className:"pg-ref-btn pg-ref-btn--primary",onClick:r,disabled:t,title:"Write these edits into the prompt's file (⌘S)",children:"Save"}),h.jsx("button",{type:"button",className:"pg-ref-btn",onClick:n,disabled:t,title:"Throw away these edits",children:"Discard"})]}),(u==null?void 0:u.wip)&&!u.onHead&&h.jsx("button",{type:"button",className:"pg-ref-btn",onClick:n,disabled:t,children:"Discard"}),(u==null?void 0:u.wip)&&h.jsx("button",{type:"button",className:"pg-ref-btn pg-ref-btn--quiet",onClick:()=>a(!0),disabled:t,children:"Save as variation…"})]})}function KV({shown:e,busy:t,onOpenOnHead:r}){const n=FV(e);if(!n)return null;const i=e.version,s=e.atHead===!1;return h.jsxs("div",{className:"pg-ref-banner",role:"status",children:[h.jsxs("span",{children:["Viewing"," ",e.variation&&h.jsx("strong",{children:xc(e.variation)}),e.variation&&s&&" on ",s&&h.jsxs(h.Fragment,{children:[h.jsx("code",{children:i?zi(i.id):"an old version"}),(i==null?void 0:i.message)&&h.jsxs(h.Fragment,{children:[" · ",i.message]})]}),". ",n]}),h.jsx("button",{type:"button",className:"pg-ref-btn",onClick:r,disabled:t,title:"Bring this into the working tree's unsaved edits, to edit and run",children:"Open on working tree"})]})}const XV=280,oS=100;function QV({conflict:e,labels:t}){const[r,n]=w.useState(new Set),i=OV(aS(e.target),aS(e.variation));return h.jsxs("div",{className:"pg-conflict-diff-wrap",children:[h.jsxs("div",{className:"pg-conflict-legend",children:[h.jsxs("span",{className:"pg-diff-del",children:["only in ",t.target]}),h.jsxs("span",{className:"pg-diff-add",children:["only in ",t.variation]})]}),h.jsx("div",{className:"pg-conflict-diff",children:i.map((s,a)=>{if(s.type==="del")return h.jsx("del",{className:"pg-diff-del",children:s.text},a);if(s.type==="add")return h.jsx("ins",{className:"pg-diff-add",children:s.text},a);const o=s.text;if(o.length<=XV||r.has(a))return h.jsx("span",{children:o},a);const l=a===0?"":o.slice(0,oS),u=a===i.length-1?"":o.slice(-oS);return h.jsxs("span",{children:[l,h.jsxs("button",{type:"button",className:"pg-diff-fold",onClick:()=>n(c=>new Set(c).add(a)),children:["… ",o.length-l.length-u.length," unchanged characters …"]}),u]},a)})})]})}function KA({conflicts:e,labels:t,busy:r,applyLabel:n,onApply:i}){const[s,a]=w.useState({}),o=e.every(l=>s[l.field]);return h.jsxs("div",{className:"pg-conflict-fields",children:[e.map(l=>h.jsxs("div",{className:"pg-conflict-field",children:[h.jsxs("div",{className:"pg-conflict-field-head",children:[h.jsx("span",{className:"pg-conflict-field-name",children:l.field}),h.jsx("div",{className:"pg-conflict-choices",role:"radiogroup",children:["target","variation"].map(u=>h.jsxs("label",{className:"pg-conflict-choice"+(s[l.field]===u?" is-chosen":""),children:[h.jsx("input",{type:"radio",name:`conflict-${l.field}`,checked:s[l.field]===u,onChange:()=>a(c=>({...c,[l.field]:u}))}),"Keep ",u==="target"?t.target:t.variation]},u))})]}),h.jsx(QV,{conflict:l,labels:t})]},l.field)),h.jsx("div",{className:"pg-conflict-actions",children:h.jsx("button",{type:"button",className:"pg-ref-btn pg-ref-btn--primary",disabled:r||!o,onClick:()=>i(s),title:o?void 0:"Choose a side for every field first",children:n})})]})}function ZV({shown:e,busy:t,onResolve:r,onDiscard:n}){var o;const i=(o=e.variation)==null?void 0:o.pending;if(!i)return null;const s=i.conflicts.some(l=>l.field==="prompt"),{labels:a}=i;return h.jsxs("div",{className:"pg-conflict-bar",role:"alert",children:[h.jsx("div",{className:"pg-conflict-title",children:s?"This prompt no longer exists on the working tree.":`The ${a.target} changed ${i.conflicts.length===1?"a field":"fields"} your ${a.variation} also change. Choose which to keep:`}),!s&&h.jsx(KA,{conflicts:i.conflicts,labels:a,busy:t,applyLabel:"Apply",onApply:r}),h.jsx("div",{className:"pg-conflict-actions",children:h.jsxs("button",{type:"button",className:"pg-ref-btn",disabled:t,onClick:n,children:["Discard ",a.variation]})})]})}function JV({conflict:e,what:t,busy:r,onReplace:n,onCancel:i,onCombine:s}){const{conflicts:a,labels:o}=e,l=a.some(d=>d.field==="prompt"),u=o.target==="unsaved edits",c=a.map(d=>d.field).join(", ");return h.jsxs("div",{className:"pg-conflict-bar pg-open-conflicts",role:"alertdialog",children:[h.jsx("div",{className:"pg-conflict-title",children:l?`${t} can't be opened: this prompt no longer exists on the working tree.`:u?`Your unsaved edits also change ${c}. How should ${t} be opened?`:`The working tree has changed ${c} since ${t}. How should it be opened?`}),h.jsxs("div",{className:"pg-open-options",children:[u&&h.jsxs("button",{type:"button",className:"pg-ref-btn",disabled:r,onClick:n,children:["Discard unsaved edits and open ",t]}),h.jsx("button",{type:"button",className:"pg-ref-btn pg-ref-btn--quiet",disabled:r,onClick:i,children:"Cancel"})]}),!l&&h.jsxs("div",{className:"pg-open-combine",children:[h.jsxs("div",{className:"pg-open-combine-title",children:["Or combine ",t," with the ",o.target,", choosing for each field:"]}),h.jsx(KA,{conflicts:a,labels:o,busy:r,applyLabel:`Open ${t} with these choices`,onApply:s})]})]})}const eq=800;function __(e){return Array.isArray(e)?`[${e.map(__).join(",")}]`:e&&typeof e=="object"?`{${Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>`${JSON.stringify(t)}:${__(r)}`).join(",")}}`:JSON.stringify(e)??"undefined"}function Ql(e){return __(e)}function tq(e){return!!e&&typeof e=="object"&&e.ok===!1}function rq(e){var t;return e.variation?!e.variation.wip:!!((t=e.ref)!=null&&t.version)}function lS(e){return!!(e!=null&&e.wip)&&!!e.onHead&&!e.pending}function Zl(e){return e?`${e.promptId}|${e.version??""}|${e.variation??""}`:""}function nq({prompt:e,promptRef:t,onRefChange:r,refreshKey:n,onRefresh:i,onUpdate:s,onDirtyChange:a,onExecuted:o,fill:l,onOpenFillSource:u,onOpenDataset:c,agents:d=[],onAskAgent:m}){var Br;const[f,p]=w.useState(!1),[g,y]=w.useState(!1),[b,v]=w.useState(null),[x,E]=w.useState(null),[T]=q4(wA),C=jV(e,t),[L,A]=w.useState(null),[z,I]=w.useState(""),B=w.useRef(new Map),j=C&&L&&L.id===e.id?L:e,G=!!e.ref,W=!!C&&z!==Zl(C),Y=w.useRef(j),V=w.useRef(C),X=w.useRef(e);w.useEffect(()=>{Y.current=j,V.current=C,X.current=e}),w.useEffect(()=>{a(f)},[f,a]),w.useEffect(()=>{e.providerId&&(E(null),bH(e.providerId,e.style).then(E).catch(()=>{}))},[e.providerId,e.style]);const[P]=w.useState(qF),re=w.useRef(0),R=w.useCallback(Fe=>{const He=X.current;if(Fe.ref&&I(Zl(Fe.ref)),Uf(Fe.ref)){A(null),Uf(t)||r==null||r(void 0),s(Fe);return}A(Fe),BV(Fe)?(Uf(t)||r==null||r(void 0),(He.wipId!==Fe.variation.id||!He.dirty)&&s({...He,dirty:!0,wipId:Fe.variation.id})):Zl(Fe.ref)!==Zl(t)&&(r==null||r(Fe.ref))},[t,r,s]),de=Zl(C);w.useEffect(()=>{if(!C||!e.providerId){A(null);return}const Fe=z!==de,He=B.current.get(de);He&&(A(He),I(de));let be=!1;const Ge=re.current;return yH(e.providerId,e.id,C).then(ht=>{be||(rq(ht)&&B.current.set(de,ht),I(de),!(!Fe&&(re.current!==Ge||P.size>0))&&(L&&Ql(ht)===Ql(L)&&Zl(ht.ref)===de||R(ht)))}).catch(ht=>{if(!be){if(Fe){const pt=C.version?zi(C.version):"this variation";v(`Can't open ${pt}: ${ht.message}`)}A(null),r==null||r(void 0),i==null||i()}}),()=>{be=!0}},[de,n,e.providerId,e.id]);const Te=w.useCallback(async Fe=>{const He=++re.current,be=Y.current,Ge=V.current,ht=aU(be,Fe);Ql(ht)!==Ql(be)&&(Y.current=ht,G&&A(ht),(!G||!Ge)&&s(ht)),p(!0),v(null);try{const{prompt:pt}=await xH(be,Fe,Ge);if(He!==re.current)return;G?(Y.current=pt,R(pt)):Ql(pt)!==Ql(Y.current)&&(Y.current=pt,s(pt))}catch(pt){v(pt.message)}finally{p(!1)}},[s,G,R]),H=w.useCallback(Fe=>P.track(Te(Fe)),[P,Te]),Oe=w.useCallback(async Fe=>{y(!0),v(null);try{const He=await Fe();tq(He)&&v(`Conflicts on ${He.conflicts.map(be=>be.field).join(", ")} — resolve them in the conflict bar.`)}catch(He){v(He.message)}finally{y(!1),i==null||i()}},[i]),Pe=w.useMemo(()=>YA(j)?HV(j):j,[j]),ee=e.providerId??"",oe=j.variation,Be=w.useCallback(()=>{P.size===0&&!lS(Y.current.variation)||Oe(async()=>{await P.settled();const Fe=Y.current.variation;if(!lS(Fe))return;const He=await kH(ee,Fe.id);return He.ok&&(A(null),s(PV(X.current,Y.current))),He})},[Oe,P,ee,s]),we=()=>oe&&Oe(async()=>{await CH(ee,oe.id),A(null),r==null||r(void 0),oe.onHead&&s({...X.current,dirty:void 0,wipId:void 0})}),_e=Fe=>oe&&Oe(async()=>{await RH(ee,oe.id,Fe)}),[je,Ke]=w.useState(null),Le=(Fe={})=>Oe(async()=>{const He=oe?await TH(ee,oe.id,Fe):await AH(e,j.ref.version,Fe);if(!He.ok){Ke(be=>({conflicts:He.conflicts,labels:He.labels??{target:"unsaved edits",variation:"this version"},key:((be==null?void 0:be.key)??0)+1}));return}Ke(null),A(null),r==null||r(void 0)}),it=()=>Le();w.useEffect(()=>Ke(null),[de]);const zt=Fe=>oe&&Oe(()=>NH(ee,oe.id,Fe));w.useEffect(()=>{const Fe=He=>{if((He.metaKey||He.ctrlKey)&&He.key==="s"){const be=Y.current.variation;(be!=null&&be.wip&&be.onHead||P.size>0)&&(He.preventDefault(),Be())}};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[Be,P]);const ot=T&&(oe!=null&&oe.wip)&&oe.onHead&&!oe.pending?`${oe.id}@${oe.updatedAt}`:void 0;return w.useEffect(()=>{if(!ot||f)return;const Fe=setTimeout(Be,eq);return()=>clearTimeout(Fe)},[ot,f,Be]),h.jsx(iU,{loading:W,header:h.jsxs("div",{className:"pg-prompt-header",children:[h.jsxs("div",{className:"pg-prompt-header-row",children:[h.jsx("span",{className:"pg-prompt-name",children:e.name}),G&&h.jsx(GV,{head:e,shown:j,onSelect:Fe=>r==null?void 0:r(Fe)}),h.jsxs("div",{className:"pg-prompt-header-right",children:[b&&h.jsxs("div",{className:"pg-header-error",children:[b,h.jsx("button",{type:"button",className:"pg-dismiss",onClick:()=>v(null),children:"×"})]}),m&&h.jsx(kA,{agents:d,onAsk:m}),G&&h.jsx(YV,{shown:j,busy:g,onSave:Be,onDiscard:we,onSaveAs:_e})]})]}),e.treePath&&e.treePath.length>0&&h.jsxs("span",{className:"pg-prompt-path",children:[h.jsx(a1,{}),h.jsx("span",{className:"pg-prompt-path-text",children:e.treePath.join("/")})]}),je?h.jsx(JV,{conflict:je,what:$V(j),busy:g,onReplace:()=>Le({replace:!0}),onCancel:()=>Ke(null),onCombine:Fe=>Le({choices:Fe})},je.key):h.jsx(KV,{shown:j,busy:g,onOpenOnHead:it}),h.jsx(ZV,{shown:j,busy:g,onResolve:zt,onDiscard:we},JSON.stringify(((Br=oe==null?void 0:oe.pending)==null?void 0:Br.conflicts)??null))]}),editor:h.jsx(RU,{prompt:Pe,onUpdate:H,modelDefinition:x}),panel:h.jsx(IV,{prompt:j,promptRef:C,runDisabledReason:UV(j),onExecuted:o,fill:l,onOpenFillSource:u,onOpenDataset:c})})}function iq(e){const t={subdirs:{},files:{}};for(const r of e){const n=r.treePath;if(!n||n.length===0){const o=r.name;t.files[o]||(t.files[o]=[]),t.files[o].push(r);continue}const i=n[n.length-1],s=n.slice(0,-1);let a=t;for(const o of s)a.subdirs[o]||(a.subdirs[o]={subdirs:{},files:{}}),a=a.subdirs[o];a.files[i]||(a.files[i]=[]),a.files[i].push(r)}return t}function XA(e){const t=[],r=Object.keys(e.subdirs).sort(),n=Object.keys(e.files).sort();for(const i of r){let s=i,a=e.subdirs[i];for(;Object.keys(a.subdirs).length===1&&Object.keys(a.files).length===0;){const[o,l]=Object.entries(a.subdirs)[0];s+="/"+o,a=l}t.push({type:"dir",label:s,children:XA(a)})}for(const i of n)t.push({type:"file",label:i,prompts:e.files[i]});return t}function QA(e,t){const r=t.toLowerCase(),n=[];for(const i of e)if(i.type==="dir"){const s=QA(i.children,t);(s.length>0||i.label.toLowerCase().includes(r))&&n.push({...i,children:s.length>0?s:i.children})}else{const s=i.label.toLowerCase().includes(r),a=i.prompts.filter(o=>o.name.toLowerCase().includes(r));s?n.push(i):a.length>0&&n.push({...i,prompts:a})}return n}function ZA({expanded:e}){return h.jsx("svg",{className:"tree-disclosure",width:"8",height:"8",viewBox:"0 0 8 8",fill:"currentColor",children:e?h.jsx("path",{d:"M1 2h6L4 6.5z"}):h.jsx("path",{d:"M2 1v6L6.5 4z"})})}function sq(){return h.jsx("svg",{className:"tree-icon",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:h.jsx("path",{d:"M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"})})}function JA(){return h.jsxs("svg",{className:"tree-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),h.jsx("polyline",{points:"14 2 14 8 20 8"})]})}function aq({initialValue:e,onCommit:t,onCancel:r}){const[n,i]=w.useState(e),s=w.useRef(null);return w.useEffect(()=>{var a;(a=s.current)==null||a.select()},[]),h.jsx("input",{ref:s,className:"tree-rename-input",value:n,onChange:a=>i(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),n.trim()?t(n.trim()):r()),a.key==="Escape"&&(a.preventDefault(),r())},onBlur:()=>{n.trim()&&n.trim()!==e?t(n.trim()):r()},onClick:a=>a.stopPropagation()})}function uS({prompt:e,indent:t,selectedId:r,onSelect:n,renamingId:i,onStartRename:s,onCommitRename:a,onCancelRename:o}){const l=e.id===r,u=e.id===i;return h.jsxs("div",{className:`tree-row${l?" tree-row-selected":""}`,style:{paddingLeft:t},onClick:()=>n(Hf(e.providerId,`selecting prompt ${e.id}`),e.id),onDoubleClick:c=>{c.stopPropagation(),s(e.id)},title:e.name,children:[h.jsx("span",{className:"tree-icon-prompt",children:h.jsx(JA,{})}),u?h.jsx(aq,{initialValue:e.name,onCommit:c=>a(e.id,c),onCancel:o}):h.jsxs("span",{className:"tree-row-label",children:[e.name,e.dirty&&h.jsxs("span",{className:"tree-row-dirty",title:"Unsaved edits",children:[" ","●"]})]})]})}function eN({node:e,depth:t,...r}){const[n,i]=w.useState(!0),s=e.prompts.length>1,a=t*18;return s?h.jsxs("div",{children:[h.jsxs("div",{className:"tree-row",style:{paddingLeft:10+a},onClick:()=>i(o=>!o),title:e.label,children:[h.jsx(ZA,{expanded:n}),h.jsx("span",{className:"tree-icon-file",children:h.jsx(JA,{})}),h.jsx("span",{className:"tree-row-label",children:e.label})]}),n&&e.prompts.map(o=>h.jsx(uS,{prompt:o,indent:10+a+18+16,...r},o.id))]}):h.jsx(uS,{prompt:e.prompts[0],indent:10+a+14,...r})}function tN({node:e,depth:t,...r}){const[n,i]=w.useState(!0),s=t*18;return h.jsxs("div",{children:[h.jsxs("div",{className:"tree-row",style:{paddingLeft:10+s},onClick:()=>i(a=>!a),title:e.label,children:[h.jsx(ZA,{expanded:n}),h.jsx("span",{className:"tree-icon-folder",children:h.jsx(sq,{})}),h.jsx("span",{className:"tree-row-label",children:e.label})]}),n&&h.jsx("div",{children:e.children.map((a,o)=>a.type==="dir"?h.jsx(tN,{node:a,depth:t+1,...r},o):h.jsx(eN,{node:a,depth:t+1,...r},o))})]})}function oq({prompts:e,selectedId:t,onSelect:r,loading:n,error:i,onAddPrompt:s,onRenamePrompt:a}){const[o,l]=w.useState(""),[u,c]=w.useState(!1),[d,m]=w.useState(null),f=(b,v)=>{m(null),a==null||a(b,v)},p=w.useMemo(()=>{const b=iq(e),v=XA(b);return o?QA(v,o):v},[e,o]),g=h.jsxs("div",{className:"section-panel-header",children:[h.jsx("span",{children:"Prompts"}),h.jsxs("div",{className:"section-panel-header-actions",children:[h.jsx("button",{type:"button",className:"tree-toolbar-btn",title:"Toggle search",onClick:()=>{c(b=>(b&&l(""),!b))},children:h.jsx(sA,{})}),s&&h.jsx("button",{type:"button",className:"tree-toolbar-btn",onClick:s,title:"New prompt",children:h.jsx(Zd,{})})]})]}),y=u&&h.jsx("div",{className:"tree-header-search",children:h.jsx("input",{type:"text",placeholder:"Filter",value:o,onChange:b=>l(b.target.value),onKeyDown:b=>{b.key==="Escape"&&(b.preventDefault(),l(""),c(!1))},autoFocus:!0})});return n?h.jsxs(h.Fragment,{children:[g,y,h.jsx("div",{className:"section-panel-body",children:h.jsx("div",{className:"tree-status",children:"Loading..."})})]}):i?h.jsxs(h.Fragment,{children:[g,y,h.jsx("div",{className:"section-panel-body",children:h.jsxs("div",{className:"tree-status tree-error",children:["Error: ",i]})})]}):e.length===0?h.jsxs(h.Fragment,{children:[g,y,h.jsx("div",{className:"section-panel-body",children:h.jsxs("div",{className:"tree-empty-state",children:[h.jsx("p",{children:"No prompts found."}),s&&h.jsx("button",{type:"button",className:"tree-add-prompt-btn",onClick:s,children:"Create a prompt"})]})})]}):h.jsxs(h.Fragment,{children:[g,y,h.jsx("div",{className:"section-panel-body file-tree",children:p.map((b,v)=>b.type==="dir"?h.jsx(tN,{node:b,depth:0,selectedId:t,onSelect:r,renamingId:d,onStartRename:m,onCommitRename:f,onCancelRename:()=>m(null)},v):h.jsx(eN,{node:b,depth:0,selectedId:t,onSelect:r,renamingId:d,onStartRename:m,onCommitRename:f,onCancelRename:()=>m(null)},v))})]})}function lq(){return h.jsxs("svg",{className:"tree-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("circle",{cx:"12",cy:"12",r:"4"}),h.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"4"}),h.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"22"}),h.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),h.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),h.jsx("line",{x1:"2",y1:"12",x2:"4",y2:"12"}),h.jsx("line",{x1:"20",y1:"12",x2:"22",y2:"12"}),h.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),h.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]})}function uq(){return h.jsxs("svg",{className:"tree-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("path",{d:"M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2z"}),h.jsx("polyline",{points:"17 21 17 13 7 13 7 21"}),h.jsx("polyline",{points:"7 3 7 8 15 8"})]})}const rN=[{id:"appearance",label:"Appearance",icon:lq},{id:"load-save",label:"Load/Save",icon:uq}],nN=e=>rN.find(t=>t.id===e).label;function cq({selectedSection:e,onSelect:t}){return h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"section-panel-header",children:h.jsx("span",{children:"Settings"})}),h.jsx("div",{className:"section-panel-body",children:rN.map(r=>h.jsxs("div",{className:"tree-row"+(r.id===e?" tree-row-selected":""),style:{paddingLeft:10},onClick:()=>t(r.id),children:[h.jsx("span",{className:"tree-icon-file",children:h.jsx(r.icon,{})}),h.jsx("span",{className:"tree-row-label",children:r.label})]},r.id))})]})}function hq(e){return e==="light"||e==="dark"?e:"system"}const Ym=SA("evalution.theme","system",hq);function dq(e,t){return e==="system"?t?"dark":"light":e}const Pu=typeof window<"u"?window.matchMedia("(prefers-color-scheme: dark)"):null,v_=new Set;function Vg(){document.documentElement.dataset.theme=dq(Ym.get(),!!(Pu!=null&&Pu.matches));for(const e of v_)e()}typeof document<"u"&&(Vg(),Ym.subscribe(Vg),Pu==null||Pu.addEventListener("change",()=>{Ym.get()==="system"&&Vg()}));function fq(e){return v_.add(e),()=>v_.delete(e)}const mq=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function pq(){const[e,t]=q4(Ym);return h.jsxs("div",{className:"settings-row",children:[h.jsx("span",{className:"settings-row-label",children:"Theme"}),h.jsx("div",{className:"settings-segmented",role:"radiogroup","aria-label":"Theme",children:mq.map(r=>h.jsx("button",{type:"button",role:"radio","aria-checked":e===r.value,className:"settings-segmented-btn"+(e===r.value?" is-active":""),onClick:()=>t(r.value),children:r.label},r.value))})]})}function gq(){const[e,t]=q4(wA);return h.jsxs("label",{className:"settings-row settings-checkbox-row",children:[h.jsx("input",{type:"checkbox",checked:e,onChange:r=>t(r.target.checked)}),h.jsx("span",{className:"settings-row-label",children:"Autosave"}),h.jsx("span",{className:"settings-row-hint",children:"Save unsaved edits to the file automatically once they settle."})]})}function bq({section:e}){return h.jsxs("div",{className:"settings-view",children:[h.jsx("h2",{className:"settings-view-title",children:nN(e)}),e==="appearance"?h.jsx(pq,{}):h.jsx(gq,{})]})}function _q(){return h.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),h.jsx("polyline",{points:"14 2 14 8 20 8"})]})}function vq({id:e,name:t,icon:r,active:n,dirty:i,onClick:s,onClose:a,onDragStart:o,onDragEnd:l}){return h.jsxs("button",{type:"button",id:e,title:t,className:`tab${n?" tab-active":""}`,draggable:!0,onDragStart:o,onDragEnd:l,onClick:u=>{u.stopPropagation(),s()},children:[h.jsx("span",{className:"tab-icon",children:r??h.jsx(_q,{})}),h.jsx("span",{className:"tab-label",children:t}),i&&h.jsx("span",{className:"tab-dirty",children:"●"}),h.jsx("span",{className:`tab-close${i?" tab-close--dirty":""}`,onClick:a,children:"×"})]})}/**
87
87
  * Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
@@ -282,7 +282,7 @@ XID_Continue XIDC
282
282
  XID_Start XIDS`.split(/\s/).map(e=>[S1(e),e])),Pte=new Map([["s",Nr(383)],[Nr(383),"s"]]),zte=new Map([[Nr(223),Nr(7838)],[Nr(107),Nr(8490)],[Nr(229),Nr(8491)],[Nr(969),Nr(8486)]]),$te=new Map([Da(453),Da(456),Da(459),Da(498),...y2(8072,8079),...y2(8088,8095),...y2(8104,8111),Da(8124),Da(8140),Da(8188)]),Hte=new Map([["alnum",rt`[\p{Alpha}\p{Nd}]`],["alpha",rt`\p{Alpha}`],["ascii",rt`\p{ASCII}`],["blank",rt`[\p{Zs}\t]`],["cntrl",rt`\p{Cc}`],["digit",rt`\p{Nd}`],["graph",rt`[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]`],["lower",rt`\p{Lower}`],["print",rt`[[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]\p{Zs}]`],["punct",rt`[\p{P}\p{S}]`],["space",rt`\p{space}`],["upper",rt`\p{Upper}`],["word",rt`[\p{Alpha}\p{M}\p{Nd}\p{Pc}]`],["xdigit",rt`\p{AHex}`]]);function Fte(e,t){const r=[];for(let n=e;n<=t;n++)r.push(n);return r}function Da(e){const t=Nr(e);return[t.toLowerCase(),t]}function y2(e,t){return Fte(e,t).map(r=>Da(r))}var IL=new Set(["Lower","Lowercase","Upper","Uppercase","Ll","Lowercase_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter"]);function Ute(e,t){const r={accuracy:"default",asciiWordBoundaries:!1,avoidSubclass:!1,bestEffortTarget:"ES2025",...t};DL(e);const n={accuracy:r.accuracy,asciiWordBoundaries:r.asciiWordBoundaries,avoidSubclass:r.avoidSubclass,flagDirectivesByAlt:new Map,jsGroupNameMap:new Map,minTargetEs2024:Tv(r.bestEffortTarget,"ES2024"),passedLookbehind:!1,strategy:null,subroutineRefMap:new Map,supportedGNodes:new Set,digitIsAscii:e.flags.digitIsAscii,spaceIsAscii:e.flags.spaceIsAscii,wordIsAscii:e.flags.wordIsAscii};qh(e,Vte,n);const i={dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},s={currentFlags:i,prevFlags:null,globalFlags:i,groupOriginByCopy:new Map,groupsByName:new Map,multiplexCapturesToLeftByRef:new Map,openRefs:new Map,reffedNodesByReferencer:new Map,subroutineRefMap:n.subroutineRefMap};qh(e,qte,s);const a={groupsByName:s.groupsByName,highestOrphanBackref:0,numCapturesToLeft:0,reffedNodesByReferencer:s.reffedNodesByReferencer};return qh(e,Gte,a),e._originMap=s.groupOriginByCopy,e._strategy=n.strategy,e}var Vte={AbsenceFunction({node:e,parent:t,replaceWith:r}){const{body:n,kind:i}=e;if(i==="repeater"){const s=Xi();s.body[0].body.push(Ko({negate:!0,body:n}),cu("Any"));const a=Xi();a.body[0].body.push(EL("greedy",0,1/0,s)),r(ur(a,t),{traverse:!0})}else throw new Error('Unsupported absence function "(?~|"')},Alternative:{enter({node:e,parent:t,key:r},{flagDirectivesByAlt:n}){const i=e.body.filter(s=>s.kind==="flags");for(let s=r+1;s<t.body.length;s++){const a=t.body[s];Rd(n,a,[]).push(...i)}},exit({node:e},{flagDirectivesByAlt:t}){var r;if((r=t.get(e))!=null&&r.length){const n=ML(t.get(e));if(n){const i=Xi({flags:n});i.body[0].body=e.body,e.body=[ur(i,e)]}}}},Assertion({node:e,parent:t,key:r,container:n,root:i,remove:s,replaceWith:a},o){const{kind:l,negate:u}=e,{asciiWordBoundaries:c,avoidSubclass:d,supportedGNodes:m,wordIsAscii:f}=o;if(l==="text_segment_boundary")throw new Error(`Unsupported text segment boundary "\\${u?"Y":"y"}"`);if(l==="line_end")a(ur(Ko({body:[Al({body:[wv("string_end")]}),Al({body:[x1(10)]})]}),t));else if(l==="line_start")a(ur(Us(rt`(?<=\A|\n(?!\z))`,{skipLookbehindValidation:!0}),t));else if(l==="search_start")if(m.has(e))i.flags.sticky=!0,s();else{const p=n[r-1];if(p&&Zte(p))a(ur(Ko({negate:!0}),t));else{if(d)throw new Error(rt`Uses "\G" in a way that requires a subclass`);a(Oa(wv("string_start"),t)),o.strategy="clip_search"}}else if(!(l==="string_end"||l==="string_start"))if(l==="string_end_newline")a(ur(Us(rt`(?=\n?\z)`),t));else if(l==="word_boundary"){if(!f&&!c){const p=`(?:(?<=${Fs})(?!${Fs})|(?<!${Fs})(?=${Fs}))`,g=`(?:(?<=${Fs})(?=${Fs})|(?<!${Fs})(?!${Fs}))`;a(ur(Us(u?g:p),t))}}else throw new Error(`Unexpected assertion kind "${l}"`)},Backreference({node:e},{jsGroupNameMap:t}){let{ref:r}=e;typeof r=="string"&&!S2(r)&&(r=x2(r,t),e.ref=r)},CapturingGroup({node:e},{jsGroupNameMap:t,subroutineRefMap:r}){let{name:n}=e;n&&!S2(n)&&(n=x2(n,t),e.name=n),r.set(e.number,e),n&&r.set(n,e)},CharacterClassRange({node:e,parent:t,replaceWith:r}){if(t.kind==="intersection"){const n=Jf({body:[e]});r(ur(n,t),{traverse:!0})}},CharacterSet({node:e,parent:t,replaceWith:r},{accuracy:n,minTargetEs2024:i,digitIsAscii:s,spaceIsAscii:a,wordIsAscii:o}){const{kind:l,negate:u,value:c}=e;if(s&&(l==="digit"||c==="digit")){r(Oa(kv("digit",{negate:u}),t));return}if(a&&(l==="space"||c==="space")){r(ur(w2(Us(jte),u),t));return}if(o&&(l==="word"||c==="word")){r(Oa(kv("word",{negate:u}),t));return}if(l==="any")r(Oa(cu("Any"),t));else if(l==="digit")r(Oa(cu("Nd",{negate:u}),t));else if(l!=="dot")if(l==="text_segment"){if(n==="strict")throw new Error(rt`Use of "\X" requires non-strict accuracy`);const d="\\p{Emoji}(?:\\p{EMod}|\\uFE0F\\u20E3?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})?",m=rt`\p{RI}{2}|${d}(?:\u200D${d})*`;r(ur(Us(rt`(?>\r\n|${i?rt`\p{RGI_Emoji}`:m}|\P{M}\p{M}*)`,{skipPropertyNameValidation:!0}),t))}else if(l==="hex")r(Oa(cu("AHex",{negate:u}),t));else if(l==="newline")r(ur(Us(u?`[^
283
283
  ]`:`(?>\r
284
284
  ?|[
285
- \v\f…\u2028\u2029])`),t));else if(l==="posix")if(!i&&(c==="graph"||c==="print")){if(n==="strict")throw new Error(`POSIX class "${c}" requires min target ES2024 or non-strict accuracy`);let d={graph:"!-~",print:" -~"}[c];u&&(d=`\0-${Nr(d.codePointAt(0)-1)}${Nr(d.codePointAt(2)+1)}-􏿿`),r(ur(Us(`[${d}]`),t))}else r(ur(w2(Us(Hte.get(c)),u),t));else if(l==="property")D3.has(S1(c))||(e.key="sc");else if(l==="space")r(Oa(cu("space",{negate:u}),t));else if(l==="word")r(ur(w2(Us(Fs),u),t));else throw new Error(`Unexpected character set kind "${l}"`)},Directive({node:e,parent:t,root:r,remove:n,replaceWith:i,removeAllPrevSiblings:s,removeAllNextSiblings:a}){const{kind:o,flags:l}=e;if(o==="flags")if(!l.enable&&!l.disable)n();else{const u=Xi({flags:l});u.body[0].body=a(),i(ur(u,t),{traverse:!0})}else if(o==="keep"){const u=r.body[0],d=r.body.length===1&&xL(u,{type:"Group"})&&u.body[0].body.length===1?u.body[0]:r;if(t.parent!==d||d.body.length>1)throw new Error(rt`Uses "\K" in a way that's unsupported`);const m=Ko({behind:!0});m.body[0].body=s(),i(ur(m,t))}else throw new Error(`Unexpected directive kind "${o}"`)},Flags({node:e,parent:t}){if(e.posixIsAscii)throw new Error('Unsupported flag "P"');if(e.textSegmentMode==="word")throw new Error('Unsupported flag "y{w}"');["digitIsAscii","extended","posixIsAscii","spaceIsAscii","wordIsAscii","textSegmentMode"].forEach(r=>delete e[r]),Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;const{enable:t,disable:r}=e.flags;t!=null&&t.extended&&delete t.extended,r!=null&&r.extended&&delete r.extended,t!=null&&t.dotAll&&(r!=null&&r.dotAll)&&delete t.dotAll,t!=null&&t.ignoreCase&&(r!=null&&r.ignoreCase)&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable,r&&!Object.keys(r).length&&delete e.flags.disable,!e.flags.enable&&!e.flags.disable&&delete e.flags},LookaroundAssertion({node:e},t){const{kind:r}=e;r==="lookbehind"&&(t.passedLookbehind=!0)},NamedCallout({node:e,parent:t,replaceWith:r}){const{kind:n}=e;if(n==="fail")r(ur(Ko({negate:!0}),t));else throw new Error(`Unsupported named callout "(*${n.toUpperCase()}"`)},Quantifier({node:e}){if(e.body.type==="Quantifier"){const t=Xi();t.body[0].body.push(e.body),e.body=ur(t,e)}},Regex:{enter({node:e},{supportedGNodes:t}){const r=[];let n=!1,i=!1;for(const s of e.body)if(s.body.length===1&&s.body[0].kind==="search_start")s.body.pop();else{const a=BL(s.body);a?(n=!0,Array.isArray(a)?r.push(...a):r.push(a)):i=!0}n&&!i&&r.forEach(s=>t.add(s))},exit(e,{accuracy:t,passedLookbehind:r,strategy:n}){if(t==="strict"&&r&&n)throw new Error(rt`Uses "\G" in a way that requires non-strict accuracy`)}},Subroutine({node:e},{jsGroupNameMap:t}){let{ref:r}=e;typeof r=="string"&&!S2(r)&&(r=x2(r,t),e.ref=r)}},qte={Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByReferencer:r}){const{orphan:n,ref:i}=e;n||r.set(e,[...t.get(i).map(({node:s})=>s)])},CapturingGroup:{enter({node:e,parent:t,replaceWith:r,skip:n},{groupOriginByCopy:i,groupsByName:s,multiplexCapturesToLeftByRef:a,openRefs:o,reffedNodesByReferencer:l}){const u=i.get(e);if(u&&o.has(e.number)){const d=Oa(m8(e.number),t);l.set(d,o.get(e.number)),r(d);return}o.set(e.number,e),a.set(e.number,[]),e.name&&Rd(a,e.name,[]);const c=a.get(e.name??e.number);for(let d=0;d<c.length;d++){const m=c[d];if(u===m.node||u&&u===m.origin||e===m.origin){c.splice(d,1);break}}if(a.get(e.number).push({node:e,origin:u}),e.name&&a.get(e.name).push({node:e,origin:u}),e.name){const d=Rd(s,e.name,new Map);let m=!1;if(u)m=!0;else for(const f of d.values())if(!f.hasDuplicateNameToRemove){m=!0;break}s.get(e.name).set(e,{node:e,hasDuplicateNameToRemove:m})}},exit({node:e},{openRefs:t}){t.get(e.number)===e&&t.delete(e.number)}},Group:{enter({node:e},t){t.prevFlags=t.currentFlags,e.flags&&(t.currentFlags=_p(t.currentFlags,e.flags))},exit(e,t){t.currentFlags=t.prevFlags}},Subroutine({node:e,parent:t,replaceWith:r},n){const{isRecursive:i,ref:s}=e;if(i){let c=t;for(;(c=c.parent)&&!(c.type==="CapturingGroup"&&(c.name===s||c.number===s)););n.reffedNodesByReferencer.set(e,c);return}const a=n.subroutineRefMap.get(s),o=s===0,l=o?m8(0):OL(a,n.groupOriginByCopy,null);let u=l;if(!o){const c=ML(Kte(a,m=>m.type==="Group"&&!!m.flags)),d=c?_p(n.globalFlags,c):n.globalFlags;Wte(d,n.currentFlags)||(u=Xi({flags:Xte(d)}),u.body[0].body.push(l))}r(ur(u,t),{traverse:!o})}},Gte={Backreference({node:e,parent:t,replaceWith:r},n){if(e.orphan){n.highestOrphanBackref=Math.max(n.highestOrphanBackref,e.ref);return}const s=n.reffedNodesByReferencer.get(e).filter(a=>Yte(a,e));if(!s.length)r(ur(Ko({negate:!0}),t));else if(s.length>1){const a=Xi({atomic:!0,body:s.reverse().map(o=>Al({body:[Ev(o.number)]}))});r(ur(a,t))}else e.ref=s[0].number},CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,e.name&&t.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove&&delete e.name},Regex:{exit({node:e},t){const r=Math.max(t.highestOrphanBackref-t.numCapturesToLeft,0);for(let n=0;n<r;n++){const i=wL();e.body.at(-1).body.push(i)}}},Subroutine({node:e},t){!e.isRecursive||e.ref===0||(e.ref=t.reffedNodesByReferencer.get(e).number)}};function DL(e){qh(e,{"*"({node:t,parent:r}){t.parent=r}})}function Wte(e,t){return e.dotAll===t.dotAll&&e.ignoreCase===t.ignoreCase}function Yte(e,t){let r=t;do{if(r.type==="Regex")return!1;if(r.type==="Alternative")continue;if(r===e)return!1;const n=jL(r.parent);for(const i of n){if(i===r)break;if(i===e||PL(i,e))return!0}}while(r=r.parent);throw new Error("Unexpected path")}function OL(e,t,r,n){const i=Array.isArray(e)?[]:{};for(const[s,a]of Object.entries(e))s==="parent"?i.parent=Array.isArray(r)?n:r:a&&typeof a=="object"?i[s]=OL(a,t,i,r):(s==="type"&&a==="CapturingGroup"&&t.set(i,t.get(e)??e),i[s]=a);return i}function m8(e){const t=kL(e);return t.isRecursive=!0,t}function Kte(e,t){const r=[];for(;e=e.parent;)(!t||t(e))&&r.push(e);return r}function x2(e,t){if(t.has(e))return t.get(e);const r=`$${t.size}_${e.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/ug,"_")}`;return t.set(e,r),r}function ML(e){const t=["dotAll","ignoreCase"],r={enable:{},disable:{}};return e.forEach(({flags:n})=>{t.forEach(i=>{var s,a;(s=n.enable)!=null&&s[i]&&(delete r.disable[i],r.enable[i]=!0),(a=n.disable)!=null&&a[i]&&(r.disable[i]=!0)})}),Object.keys(r.enable).length||delete r.enable,Object.keys(r.disable).length||delete r.disable,r.enable||r.disable?r:null}function Xte({dotAll:e,ignoreCase:t}){const r={};return(e||t)&&(r.enable={},e&&(r.enable.dotAll=!0),t&&(r.enable.ignoreCase=!0)),(!e||!t)&&(r.disable={},!e&&(r.disable.dotAll=!0),!t&&(r.disable.ignoreCase=!0)),r}function jL(e){if(!e)throw new Error("Node expected");const{body:t}=e;return Array.isArray(t)?t:t?[t]:null}function BL(e){const t=e.find(r=>r.kind==="search_start"||Jte(r,{negate:!1})||!Qte(r));if(!t)return null;if(t.kind==="search_start")return t;if(t.type==="LookaroundAssertion")return t.body[0].body[0];if(t.type==="CapturingGroup"||t.type==="Group"){const r=[];for(const n of t.body){const i=BL(n.body);if(!i)return null;Array.isArray(i)?r.push(...i):r.push(i)}return r}return null}function PL(e,t){const r=jL(e)??[];for(const n of r)if(n===t||PL(n,t))return!0;return!1}function Qte({type:e}){return e==="Assertion"||e==="Directive"||e==="LookaroundAssertion"}function Zte(e){const t=["Character","CharacterClass","CharacterSet"];return t.includes(e.type)||e.type==="Quantifier"&&e.min&&t.includes(e.body.type)}function Jte(e,t){const r={negate:null,...t};return e.type==="LookaroundAssertion"&&(r.negate===null||e.negate===r.negate)&&e.body.length===1&&xL(e.body[0],{type:"Assertion",kind:"search_start"})}function S2(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function Us(e,t){const n=SL(e,{...t,unicodePropertyMap:D3}).body;return n.length>1||n[0].body.length>1?Xi({body:n}):n[0].body[0]}function w2(e,t){return e.negate=t,e}function Oa(e,t){return e.parent=t,e}function ur(e,t){return DL(e),e.parent=t,e}function ere(e,t){const r=RL(t),n=Tv(r.target,"ES2024"),i=Tv(r.target,"ES2025"),s=r.rules.recursionLimit;if(!Number.isInteger(s)||s<2||s>20)throw new Error("Invalid recursionLimit; use 2-20");let a=null,o=null;if(!i){const f=[e.flags.ignoreCase];qh(e,tre,{getCurrentModI:()=>f.at(-1),popModI(){f.pop()},pushModI(p){f.push(p)},setHasCasedChar(){f.at(-1)?a=!0:o=!0}})}const l={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||a)&&!o)};let u=e;const c={accuracy:r.accuracy,appliedGlobalFlags:l,captureMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},inCharClass:!1,lastNode:u,originMap:e._originMap,recursionLimit:s,useAppliedIgnoreCase:!!(!i&&a&&o),useFlagMods:i,useFlagV:n,verbose:r.verbose};function d(f){return c.lastNode=u,u=f,Ote(rre[f.type],`Unexpected node type "${f.type}"`)(f,c,d)}const m={pattern:e.body.map(d).join("|"),flags:d(e.flags),options:{...e.options}};return n||(delete m.options.force.v,m.options.disable.v=!0,m.options.unicodeSetsPlugin=null),m._captureTransfers=new Map,m._hiddenCaptures=[],c.captureMap.forEach((f,p)=>{f.hidden&&m._hiddenCaptures.push(p),f.transferTo&&Rd(m._captureTransfers,f.transferTo,[]).push(p)}),m}var tre={"*":{enter({node:e},t){if(g8(e)){const r=t.getCurrentModI();t.pushModI(e.flags?_p({ignoreCase:r},e.flags).ignoreCase:r)}},exit({node:e},t){g8(e)&&t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){O3(Nr(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},r){t(),zL(e,{firstOnly:!0}).length&&r.setHasCasedChar()},CharacterSet({node:e},t){e.kind==="property"&&IL.has(e.value)&&t.setHasCasedChar()}},rre={Alternative({body:e},t,r){return e.map(r).join("")},Assertion({kind:e,negate:t}){if(e==="string_end")return"$";if(e==="string_start")return"^";if(e==="word_boundary")return t?rt`\B`:rt`\b`;throw new Error(`Unexpected assertion kind "${e}"`)},Backreference({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&t.accuracy==="strict"&&t.currentFlags.ignoreCase&&!t.captureMap.get(e).ignoreCase)throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");return"\\"+e},CapturingGroup(e,t,r){const{body:n,name:i,number:s}=e,a={ignoreCase:t.currentFlags.ignoreCase},o=t.originMap.get(e);return o&&(a.hidden=!0,s>o.number&&(a.transferTo=o.number)),t.captureMap.set(s,a),`(${i?`?<${i}>`:""}${n.map(r).join("|")})`},Character({value:e},t){const r=Nr(e),n=nu(e,{escDigit:t.lastNode.type==="Backreference",inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(n!==r)return n;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&O3(r)){const i=LL(r);return t.inCharClass?i.join(""):i.length>1?`[${i.join("")}]`:i[0]}return r},CharacterClass(e,t,r){const{kind:n,negate:i,parent:s}=e;let{body:a}=e;if(n==="intersection"&&!t.useFlagV)throw new Error("Use of character class intersection requires min target ES2024");Qi.bugFlagVLiteralHyphenIsRange&&t.useFlagV&&a.some(b8)&&(a=[x1(45),...a.filter(u=>!b8(u))]);const o=()=>`[${i?"^":""}${a.map(r).join(n==="intersection"?"&&":"")}]`;if(!t.inCharClass){if((!t.useFlagV||Qi.bugNestedClassIgnoresNegation)&&!i){const c=a.filter(d=>d.type==="CharacterClass"&&d.kind==="union"&&d.negate);if(c.length){const d=Xi(),m=d.body[0];return d.parent=s,m.parent=d,a=a.filter(f=>!c.includes(f)),e.body=a,a.length?(e.parent=m,m.body.push(e)):d.body.pop(),c.forEach(f=>{const p=Al({body:[f]});f.parent=p,p.parent=d,d.body.push(p)}),r(d)}}t.inCharClass=!0;const u=o();return t.inCharClass=!1,u}const l=a[0];if(n==="union"&&!i&&l&&((!t.useFlagV||!t.verbose)&&s.kind==="union"&&!(Qi.bugFlagVLiteralHyphenIsRange&&t.useFlagV)||!t.verbose&&s.kind==="intersection"&&a.length===1&&l.type!=="CharacterClassRange"))return a.map(r).join("");if(!t.useFlagV&&s.type==="CharacterClass")throw new Error("Uses nested character class in a way that requires min target ES2024");return o()},CharacterClassRange(e,t){const r=e.min.value,n=e.max.value,i={escDigit:!1,inCharClass:!0,useFlagV:t.useFlagV},s=nu(r,i),a=nu(n,i),o=new Set;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){const l=zL(e);ore(l).forEach(c=>{o.add(Array.isArray(c)?`${nu(c[0],i)}-${nu(c[1],i)}`:nu(c,i))})}return`${s}-${a}${[...o].join("")}`},CharacterSet({kind:e,negate:t,value:r,key:n},i){if(e==="dot")return i.currentFlags.dotAll?i.appliedGlobalFlags.dotAll||i.useFlagMods?".":"[^]":rt`[^\n]`;if(e==="digit")return t?rt`\D`:rt`\d`;if(e==="property"){if(i.useAppliedIgnoreCase&&i.currentFlags.ignoreCase&&IL.has(r))throw new Error(`Unicode property "${r}" can't be case-insensitive when other chars have specific case`);return`${t?rt`\P`:rt`\p`}{${n?`${n}=`:""}${r}}`}if(e==="word")return t?rt`\W`:rt`\w`;throw new Error(`Unexpected character set kind "${e}"`)},Flags(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")},Group({atomic:e,body:t,flags:r,parent:n},i,s){const a=i.currentFlags;r&&(i.currentFlags=_p(a,r));const o=t.map(s).join("|"),l=!i.verbose&&t.length===1&&n.type!=="Quantifier"&&!e&&(!i.useFlagMods||!r)?o:`(?${lre(e,r,i.useFlagMods)}${o})`;return i.currentFlags=a,l},LookaroundAssertion({body:e,kind:t,negate:r},n,i){return`(?${`${t==="lookahead"?"":"<"}${r?"!":"="}`}${e.map(i).join("|")})`},Quantifier(e,t,r){return r(e.body)+ure(e)},Subroutine({isRecursive:e,ref:t},r){if(!e)throw new Error("Unexpected non-recursive subroutine in transformed AST");const n=r.recursionLimit;return t===0?`(?R=${n})`:rt`\g<${t}&R=${n}>`}},nre=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),ire=new Set(["-","\\","]","^","["]),sre=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),p8=new Map([[9,rt`\t`],[10,rt`\n`],[11,rt`\v`],[12,rt`\f`],[13,rt`\r`],[8232,rt`\u2028`],[8233,rt`\u2029`],[65279,rt`\uFEFF`]]),are=new RegExp("^\\p{Cased}$","u");function O3(e){return are.test(e)}function zL(e,t){const r=!!(t!=null&&t.firstOnly),n=e.min.value,i=e.max.value,s=[];if(n<65&&(i===65535||i>=131071)||n===65536&&i>=131071)return s;for(let a=n;a<=i;a++){const o=Nr(a);if(!O3(o))continue;const l=LL(o).filter(u=>{const c=u.codePointAt(0);return c<n||c>i});if(l.length&&(s.push(...l),r))break}return s}function nu(e,{escDigit:t,inCharClass:r,useFlagV:n}){if(p8.has(e))return p8.get(e);if(e<32||e>126&&e<160||e>262143||t&&cre(e))return e>255?`\\u{${e.toString(16).toUpperCase()}}`:`\\x${e.toString(16).toUpperCase().padStart(2,"0")}`;const i=r?n?sre:ire:nre,s=Nr(e);return(i.has(s)?"\\":"")+s}function ore(e){const t=e.map(i=>i.codePointAt(0)).sort((i,s)=>i-s),r=[];let n=null;for(let i=0;i<t.length;i++)t[i+1]===t[i]+1?n??(n=t[i]):n===null?r.push(t[i]):(r.push([n,t[i]]),n=null);return r}function lre(e,t,r){if(e)return">";let n="";if(t&&r){const{enable:i,disable:s}=t;n=(i!=null&&i.ignoreCase?"i":"")+(i!=null&&i.dotAll?"s":"")+(s?"-":"")+(s!=null&&s.ignoreCase?"i":"")+(s!=null&&s.dotAll?"s":"")}return`${n}:`}function ure({kind:e,max:t,min:r}){let n;return!r&&t===1?n="?":!r&&t===1/0?n="*":r===1&&t===1/0?n="+":r===t?n=`{${r}}`:n=`{${r},${t===1/0?"":t}}`,n+{greedy:"",lazy:"?",possessive:"+"}[e]}function g8({type:e}){return e==="CapturingGroup"||e==="Group"||e==="LookaroundAssertion"}function cre(e){return e>47&&e<58}function b8({type:e,value:t}){return e==="Character"&&t===45}var qa,Ks,nl,Ga,il,Bd,Av,go,hre=(go=class extends RegExp{constructor(r,n,i){var t=(...d3e)=>(super(...d3e),Io(this,Bd),Io(this,qa,new Map),Io(this,Ks,null),Io(this,nl),Io(this,Ga,null),Io(this,il,null),J(this,"rawOptions",{}),this);const s=!!(i!=null&&i.lazyCompile);if(r instanceof RegExp){if(i)throw new Error("Cannot provide options when copying a regexp");const a=r;t(a,n),Ui(this,nl,a.source),a instanceof go&&(Ui(this,qa,wn(a,qa)),Ui(this,Ga,wn(a,Ga)),Ui(this,il,wn(a,il)),this.rawOptions=a.rawOptions)}else{const a={hiddenCaptures:[],strategy:null,transfers:[],...i};t(s?"":r,n),Ui(this,nl,r),Ui(this,qa,fre(a.hiddenCaptures,a.transfers)),Ui(this,il,a.strategy),this.rawOptions=i??{}}s||Ui(this,Ks,this)}get source(){return wn(this,nl)||"(?:)"}exec(r){if(!wn(this,Ks)){const{lazyCompile:s,...a}=this.rawOptions;Ui(this,Ks,new go(wn(this,nl),this.flags,a))}const n=this.global||this.sticky,i=this.lastIndex;if(wn(this,il)==="clip_search"&&n&&i){this.lastIndex=0;const s=eg(this,Bd,Av).call(this,r.slice(i));return s&&(dre(s,i,r,this.hasIndices),this.lastIndex+=i),s}return eg(this,Bd,Av).call(this,r)}},qa=new WeakMap,Ks=new WeakMap,nl=new WeakMap,Ga=new WeakMap,il=new WeakMap,Bd=new WeakSet,Av=function(r){wn(this,Ks).lastIndex=this.lastIndex;const n=Y6(go.prototype,this,"exec").call(wn(this,Ks),r);if(this.lastIndex=wn(this,Ks).lastIndex,!n||!wn(this,qa).size)return n;const i=[...n];n.length=1;let s;this.hasIndices&&(s=[...n.indices],n.indices.length=1);const a=[0];for(let o=1;o<i.length;o++){const{hidden:l,transferTo:u}=wn(this,qa).get(o)??{};if(l?a.push(null):(a.push(n.length),n.push(i[o]),this.hasIndices&&n.indices.push(s[o])),u&&i[o]!==void 0){const c=a[u];if(!c)throw new Error(`Invalid capture transfer to "${c}"`);if(n[c]=i[o],this.hasIndices&&(n.indices[c]=s[o]),n.groups){wn(this,Ga)||Ui(this,Ga,mre(this.source));const d=wn(this,Ga).get(u);d&&(n.groups[d]=i[o],this.hasIndices&&(n.indices.groups[d]=s[o]))}}}return n},go);function dre(e,t,r,n){if(e.index+=t,e.input=r,n){const i=e.indices;for(let a=0;a<i.length;a++){const o=i[a];o&&(i[a]=[o[0]+t,o[1]+t])}const s=i.groups;s&&Object.keys(s).forEach(a=>{const o=s[a];o&&(s[a]=[o[0]+t,o[1]+t])})}}function fre(e,t){const r=new Map;for(const n of e)r.set(n,{hidden:!0});for(const[n,i]of t)for(const s of i)Rd(r,s,{}).transferTo=n;return r}function mre(e){const t=/(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu,r=new Map;let n=0,i=0,s;for(;s=t.exec(e);){const{0:a,groups:{capture:o,name:l}}=s;a==="["?n++:n?a==="]"&&n--:o&&(i++,l&&r.set(i,l))}return r}function pre(e,t){const r=gre(e,t);return r.options?new hre(r.pattern,r.flags,r.options):new RegExp(r.pattern,r.flags)}function gre(e,t){const r=RL(t),n=SL(e,{flags:r.flags,normalizeUnknownPropertyNames:!0,rules:{captureGroup:r.rules.captureGroup,singleline:r.rules.singleline},skipBackrefValidation:r.rules.allowOrphanBackrefs,unicodePropertyMap:D3}),i=Ute(n,{accuracy:r.accuracy,asciiWordBoundaries:r.rules.asciiWordBoundaries,avoidSubclass:r.avoidSubclass,bestEffortTarget:r.target}),s=ere(i,r),a=Ite(s.pattern,{captureTransfers:s._captureTransfers,hiddenCaptures:s._hiddenCaptures,mode:"external"}),o=Rte(a.pattern),l=Nte(o.pattern,{captureTransfers:a.captureTransfers,hiddenCaptures:a.hiddenCaptures}),u={pattern:l.pattern,flags:`${r.hasIndices?"d":""}${r.global?"g":""}${s.flags}${s.options.disable.v?"u":"v"}`};if(r.avoidSubclass){if(r.lazyCompileLength!==1/0)throw new Error("Lazy compilation requires subclass")}else{const c=l.hiddenCaptures.sort((p,g)=>p-g),d=Array.from(l.captureTransfers),m=i._strategy,f=u.pattern.length>=r.lazyCompileLength;(c.length||d.length||m||f)&&(u.options={...c.length&&{hiddenCaptures:c},...d.length&&{transfers:d},...m&&{strategy:m},...f&&{lazyCompile:f}})}return u}const _8=4294967295;class bre{constructor(t,r={}){J(this,"regexps");this.patterns=t,this.options=r;const{forgiving:n=!1,cache:i,regexConstructor:s}=r;if(!s)throw new Error("Option `regexConstructor` is not provided");this.regexps=t.map(a=>{if(typeof a!="string")return a;const o=i==null?void 0:i.get(a);if(o){if(o instanceof RegExp)return o;if(n)return null;throw o}try{const l=s(a);return i==null||i.set(a,l),l}catch(l){if(i==null||i.set(a,l),n)return null;throw l}})}findNextMatchSync(t,r,n){const i=typeof t=="string"?t:t.content,s=[];function a(o,l,u=0){return{index:o,captureIndices:l.indices.map(c=>c==null?{start:_8,end:_8,length:0}:{start:c[0]+u,end:c[1]+u,length:c[1]-c[0]})}}for(let o=0;o<this.regexps.length;o++){const l=this.regexps[o];if(l)try{l.lastIndex=r;const u=l.exec(i);if(!u)continue;if(u.index===r)return a(o,u,0);s.push([o,u,0])}catch(u){if(this.options.forgiving)continue;throw u}}if(s.length){const o=Math.min(...s.map(l=>l[1].index));for(const[l,u,c]of s)if(u.index===o)return a(l,u,c)}return null}}function _re(e,t){return pre(e,{global:!0,hasIndices:!0,lazyCompileLength:3e3,rules:{allowOrphanBackrefs:!0,asciiWordBoundaries:!0,captureGroup:!0,recursionLimit:5,singleline:!0},...t})}function vre(e={}){const t=Object.assign({target:"auto",cache:new Map},e);return t.regexConstructor||(t.regexConstructor=r=>_re(r,{target:t.target})),{createScanner(r){return new bre(r,t)},createString(r){return{content:r}}}}var yre=vre({forgiving:!0}),xre=Object.fromEntries(A3.flatMap(e=>{var t;return((t=e.aliases)!=null?t:[]).map(r=>[r,e.id])})),em=new Set(Object.keys(mL)),v8=e=>{let t=e.trim().toLowerCase();return xre[t]||(em.has(t),t)},E2=new Map,k2=new Map,iu=new Map,vp=e=>{var t;return typeof e=="string"?e:(t=e.name)!=null?t:"custom"},Sre=(e,t)=>`${e}-${vp(t[0])}-${vp(t[1])}`,wre=(e,t,r)=>{let n=e.slice(0,100),i=e.length>100?e.slice(-100):"";return`${t}:${r[0]}:${r[1]}:${e.length}:${n}:${i}`},Ere=(e,t)=>{let r=Sre(e,t);if(E2.has(r))return E2.get(r);let n=Dee({themes:t,langs:[e],engine:yre});return E2.set(r,n),n};function kre(e={}){var t;let r=(t=e.themes)!=null?t:["github-light","github-dark"];return{name:"shiki",type:"code-highlighter",supportsLanguage(n){let i=v8(n);return em.has(i)},getSupportedLanguages(){return Array.from(em)},getThemes(){return r},highlight({code:n,language:i,themes:s},a){let o=v8(i),l=[vp(s[0]),vp(s[1])],u=wre(n,o,l);if(k2.has(u))return k2.get(u);a&&(iu.has(u)||iu.set(u,new Set),iu.get(u).add(a));let c=em.has(o)?o:"text";return Ere(c,s).then(d=>{let m=d.getLoadedLanguages().includes(o)?o:"text",f=d.codeToTokens(n,{lang:m,themes:{light:l[0],dark:l[1]}});k2.set(u,f);let p=iu.get(u);if(p){for(let g of p)g(f);iu.delete(u)}}).catch(d=>{console.error("[Streamdown Code] Failed to highlight code:",d),iu.delete(u)}),null}}}var Cre=kre();const y8=/[#.]/g;function Tre(e,t){const r=e||"",n={};let i=0,s,a;for(;i<r.length;){y8.lastIndex=i;const o=y8.exec(r),l=r.slice(i,o?o.index:r.length);l&&(s?s==="#"?n.id=l:Array.isArray(n.className)?n.className.push(l):n.className=[l]:a=l,i+=l.length),o&&(s=o[0],i++)}return{type:"element",tagName:a||t||"div",properties:n,children:[]}}function $L(e,t,r){const n=r?Lre(r):void 0;function i(s,a,...o){let l;if(s==null){l={type:"root",children:[]};const u=a;o.unshift(u)}else{l=Tre(s,t);const u=l.tagName.toLowerCase(),c=n?n.get(u):void 0;if(l.tagName=c||u,Are(a))o.unshift(a);else for(const[d,m]of Object.entries(a))Nre(e,l.properties,d,m)}for(const u of o)Nv(l.children,u);return l.type==="element"&&l.tagName==="template"&&(l.content={type:"root",children:l.children},l.children=[]),l}return i}function Are(e){if(e===null||typeof e!="object"||Array.isArray(e))return!0;if(typeof e.type!="string")return!1;const t=e,r=Object.keys(e);for(const n of r){const i=t[n];if(i&&typeof i=="object"){if(!Array.isArray(i))return!0;const s=i;for(const a of s)if(typeof a!="number"&&typeof a!="string")return!0}}return!!("children"in e&&Array.isArray(e.children))}function Nre(e,t,r,n){const i=d0(e,r);let s;if(n!=null){if(typeof n=="number"){if(Number.isNaN(n))return;s=n}else typeof n=="boolean"?s=n:typeof n=="string"?i.spaceSeparated?s=Uw(n):i.commaSeparated?s=Fw(n):i.commaOrSpaceSeparated?s=Uw(Fw(n).join(" ")):s=x8(i,i.property,n):Array.isArray(n)?s=[...n]:s=i.property==="style"?Rre(n):String(n);if(Array.isArray(s)){const a=[];for(const o of s)a.push(x8(i,i.property,o));s=a}i.property==="className"&&Array.isArray(t.className)&&(s=t.className.concat(s)),t[i.property]=s}}function Nv(e,t){if(t!=null)if(typeof t=="number"||typeof t=="string")e.push({type:"text",value:String(t)});else if(Array.isArray(t))for(const r of t)Nv(e,r);else if(typeof t=="object"&&"type"in t)t.type==="root"?Nv(e,t.children):e.push(t);else throw new Error("Expected node, nodes, or string, got `"+t+"`")}function x8(e,t,r){if(typeof r=="string"){if(e.number&&r&&!Number.isNaN(Number(r)))return Number(r);if((e.boolean||e.overloadedBoolean)&&(r===""||Ad(r)===Ad(t)))return!0}return r}function Rre(e){const t=[];for(const[r,n]of Object.entries(e))t.push([r,n].join(": "));return t.join("; ")}function Lre(e){const t=new Map;for(const r of e)t.set(r.toLowerCase(),r);return t}const Ire=["altGlyph","altGlyphDef","altGlyphItem","animateColor","animateMotion","animateTransform","clipPath","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","foreignObject","glyphRef","linearGradient","radialGradient","solidColor","textArea","textPath"],HL=$L(Cc,"div"),FL=$L(Rs,"g",Ire),vs={html:"http://www.w3.org/1999/xhtml",mathml:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Dre(e,t){return UL(e,{})||{type:"root",children:[]}}function UL(e,t){const r=Ore(e,t);return r&&t.afterTransform&&t.afterTransform(e,r),r}function Ore(e,t){switch(e.nodeType){case 1:return Pre(e,t);case 3:return jre(e);case 8:return Bre(e);case 9:return S8(e,t);case 10:return Mre();case 11:return S8(e,t);default:return}}function S8(e,t){return{type:"root",children:VL(e,t)}}function Mre(){return{type:"doctype"}}function jre(e){return{type:"text",value:e.nodeValue||""}}function Bre(e){return{type:"comment",value:e.nodeValue||""}}function Pre(e,t){const r=e.namespaceURI,n=r===vs.svg?FL:HL,i=r===vs.html?e.tagName.toLowerCase():e.tagName,s=r===vs.html&&i==="template"?e.content:e,a=e.getAttributeNames(),o={};let l=-1;for(;++l<a.length;)o[a[l]]=e.getAttribute(a[l])||"";return n(i,o,VL(s,t))}function VL(e,t){const r=e.childNodes,n=[];let i=-1;for(;++i<r.length;){const s=UL(r[i],t);s!==void 0&&n.push(s)}return n}new DOMParser;function zre(e,t){const r=$re(e);return Dre(r)}function $re(e){const t=document.createElement("template");return t.innerHTML=e,t.content}const w8=function(e,t,r){const n=l0(r);if(!e||!e.type||!e.children)throw new Error("Expected parent node");if(typeof t=="number"){if(t<0||t===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if(t=e.children.indexOf(t),t<0)throw new Error("Expected child node or index");for(;++t<e.children.length;)if(n(e.children[t],t,e))return e.children[t]},$l=function(e){if(e==null)return Ure;if(typeof e=="string")return Fre(e);if(typeof e=="object")return Hre(e);if(typeof e=="function")return M3(e);throw new Error("Expected function, string, or array as `test`")};function Hre(e){const t=[];let r=-1;for(;++r<e.length;)t[r]=$l(e[r]);return M3(n);function n(...i){let s=-1;for(;++s<t.length;)if(t[s].apply(this,i))return!0;return!1}}function Fre(e){return M3(t);function t(r){return r.tagName===e}}function M3(e){return t;function t(r,n,i){return!!(Vre(r)&&e.call(this,r,typeof n=="number"?n:void 0,i||void 0))}}function Ure(e){return!!(e&&typeof e=="object"&&"type"in e&&e.type==="element"&&"tagName"in e&&typeof e.tagName=="string")}function Vre(e){return e!==null&&typeof e=="object"&&"type"in e&&"tagName"in e}const E8=/\n/g,k8=/[\t ]+/g,Rv=$l("br"),C8=$l(Zre),qre=$l("p"),T8=$l("tr"),Gre=$l(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",Qre,Jre]),qL=$l(["address","article","aside","blockquote","body","caption","center","dd","dialog","dir","dl","dt","div","figure","figcaption","footer","form,","h1","h2","h3","h4","h5","h6","header","hgroup","hr","html","legend","li","listing","main","menu","nav","ol","p","plaintext","pre","section","ul","xmp"]);function Wre(e,t){const r=t||{},n="children"in e?e.children:[],i=qL(e),s=YL(e,{whitespace:r.whitespace||"normal"}),a=[];(e.type==="text"||e.type==="comment")&&a.push(...WL(e,{breakBefore:!0,breakAfter:!0}));let o=-1;for(;++o<n.length;)a.push(...GL(n[o],e,{whitespace:s,breakBefore:o?void 0:i,breakAfter:o<n.length-1?Rv(n[o+1]):i}));const l=[];let u;for(o=-1;++o<a.length;){const c=a[o];typeof c=="number"?u!==void 0&&c>u&&(u=c):c&&(u!==void 0&&u>-1&&l.push(`
285
+ \v\f…\u2028\u2029])`),t));else if(l==="posix")if(!i&&(c==="graph"||c==="print")){if(n==="strict")throw new Error(`POSIX class "${c}" requires min target ES2024 or non-strict accuracy`);let d={graph:"!-~",print:" -~"}[c];u&&(d=`\0-${Nr(d.codePointAt(0)-1)}${Nr(d.codePointAt(2)+1)}-􏿿`),r(ur(Us(`[${d}]`),t))}else r(ur(w2(Us(Hte.get(c)),u),t));else if(l==="property")D3.has(S1(c))||(e.key="sc");else if(l==="space")r(Oa(cu("space",{negate:u}),t));else if(l==="word")r(ur(w2(Us(Fs),u),t));else throw new Error(`Unexpected character set kind "${l}"`)},Directive({node:e,parent:t,root:r,remove:n,replaceWith:i,removeAllPrevSiblings:s,removeAllNextSiblings:a}){const{kind:o,flags:l}=e;if(o==="flags")if(!l.enable&&!l.disable)n();else{const u=Xi({flags:l});u.body[0].body=a(),i(ur(u,t),{traverse:!0})}else if(o==="keep"){const u=r.body[0],d=r.body.length===1&&xL(u,{type:"Group"})&&u.body[0].body.length===1?u.body[0]:r;if(t.parent!==d||d.body.length>1)throw new Error(rt`Uses "\K" in a way that's unsupported`);const m=Ko({behind:!0});m.body[0].body=s(),i(ur(m,t))}else throw new Error(`Unexpected directive kind "${o}"`)},Flags({node:e,parent:t}){if(e.posixIsAscii)throw new Error('Unsupported flag "P"');if(e.textSegmentMode==="word")throw new Error('Unsupported flag "y{w}"');["digitIsAscii","extended","posixIsAscii","spaceIsAscii","wordIsAscii","textSegmentMode"].forEach(r=>delete e[r]),Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;const{enable:t,disable:r}=e.flags;t!=null&&t.extended&&delete t.extended,r!=null&&r.extended&&delete r.extended,t!=null&&t.dotAll&&(r!=null&&r.dotAll)&&delete t.dotAll,t!=null&&t.ignoreCase&&(r!=null&&r.ignoreCase)&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable,r&&!Object.keys(r).length&&delete e.flags.disable,!e.flags.enable&&!e.flags.disable&&delete e.flags},LookaroundAssertion({node:e},t){const{kind:r}=e;r==="lookbehind"&&(t.passedLookbehind=!0)},NamedCallout({node:e,parent:t,replaceWith:r}){const{kind:n}=e;if(n==="fail")r(ur(Ko({negate:!0}),t));else throw new Error(`Unsupported named callout "(*${n.toUpperCase()}"`)},Quantifier({node:e}){if(e.body.type==="Quantifier"){const t=Xi();t.body[0].body.push(e.body),e.body=ur(t,e)}},Regex:{enter({node:e},{supportedGNodes:t}){const r=[];let n=!1,i=!1;for(const s of e.body)if(s.body.length===1&&s.body[0].kind==="search_start")s.body.pop();else{const a=BL(s.body);a?(n=!0,Array.isArray(a)?r.push(...a):r.push(a)):i=!0}n&&!i&&r.forEach(s=>t.add(s))},exit(e,{accuracy:t,passedLookbehind:r,strategy:n}){if(t==="strict"&&r&&n)throw new Error(rt`Uses "\G" in a way that requires non-strict accuracy`)}},Subroutine({node:e},{jsGroupNameMap:t}){let{ref:r}=e;typeof r=="string"&&!S2(r)&&(r=x2(r,t),e.ref=r)}},qte={Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByReferencer:r}){const{orphan:n,ref:i}=e;n||r.set(e,[...t.get(i).map(({node:s})=>s)])},CapturingGroup:{enter({node:e,parent:t,replaceWith:r,skip:n},{groupOriginByCopy:i,groupsByName:s,multiplexCapturesToLeftByRef:a,openRefs:o,reffedNodesByReferencer:l}){const u=i.get(e);if(u&&o.has(e.number)){const d=Oa(m8(e.number),t);l.set(d,o.get(e.number)),r(d);return}o.set(e.number,e),a.set(e.number,[]),e.name&&Rd(a,e.name,[]);const c=a.get(e.name??e.number);for(let d=0;d<c.length;d++){const m=c[d];if(u===m.node||u&&u===m.origin||e===m.origin){c.splice(d,1);break}}if(a.get(e.number).push({node:e,origin:u}),e.name&&a.get(e.name).push({node:e,origin:u}),e.name){const d=Rd(s,e.name,new Map);let m=!1;if(u)m=!0;else for(const f of d.values())if(!f.hasDuplicateNameToRemove){m=!0;break}s.get(e.name).set(e,{node:e,hasDuplicateNameToRemove:m})}},exit({node:e},{openRefs:t}){t.get(e.number)===e&&t.delete(e.number)}},Group:{enter({node:e},t){t.prevFlags=t.currentFlags,e.flags&&(t.currentFlags=_p(t.currentFlags,e.flags))},exit(e,t){t.currentFlags=t.prevFlags}},Subroutine({node:e,parent:t,replaceWith:r},n){const{isRecursive:i,ref:s}=e;if(i){let c=t;for(;(c=c.parent)&&!(c.type==="CapturingGroup"&&(c.name===s||c.number===s)););n.reffedNodesByReferencer.set(e,c);return}const a=n.subroutineRefMap.get(s),o=s===0,l=o?m8(0):OL(a,n.groupOriginByCopy,null);let u=l;if(!o){const c=ML(Kte(a,m=>m.type==="Group"&&!!m.flags)),d=c?_p(n.globalFlags,c):n.globalFlags;Wte(d,n.currentFlags)||(u=Xi({flags:Xte(d)}),u.body[0].body.push(l))}r(ur(u,t),{traverse:!o})}},Gte={Backreference({node:e,parent:t,replaceWith:r},n){if(e.orphan){n.highestOrphanBackref=Math.max(n.highestOrphanBackref,e.ref);return}const s=n.reffedNodesByReferencer.get(e).filter(a=>Yte(a,e));if(!s.length)r(ur(Ko({negate:!0}),t));else if(s.length>1){const a=Xi({atomic:!0,body:s.reverse().map(o=>Al({body:[Ev(o.number)]}))});r(ur(a,t))}else e.ref=s[0].number},CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,e.name&&t.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove&&delete e.name},Regex:{exit({node:e},t){const r=Math.max(t.highestOrphanBackref-t.numCapturesToLeft,0);for(let n=0;n<r;n++){const i=wL();e.body.at(-1).body.push(i)}}},Subroutine({node:e},t){!e.isRecursive||e.ref===0||(e.ref=t.reffedNodesByReferencer.get(e).number)}};function DL(e){qh(e,{"*"({node:t,parent:r}){t.parent=r}})}function Wte(e,t){return e.dotAll===t.dotAll&&e.ignoreCase===t.ignoreCase}function Yte(e,t){let r=t;do{if(r.type==="Regex")return!1;if(r.type==="Alternative")continue;if(r===e)return!1;const n=jL(r.parent);for(const i of n){if(i===r)break;if(i===e||PL(i,e))return!0}}while(r=r.parent);throw new Error("Unexpected path")}function OL(e,t,r,n){const i=Array.isArray(e)?[]:{};for(const[s,a]of Object.entries(e))s==="parent"?i.parent=Array.isArray(r)?n:r:a&&typeof a=="object"?i[s]=OL(a,t,i,r):(s==="type"&&a==="CapturingGroup"&&t.set(i,t.get(e)??e),i[s]=a);return i}function m8(e){const t=kL(e);return t.isRecursive=!0,t}function Kte(e,t){const r=[];for(;e=e.parent;)(!t||t(e))&&r.push(e);return r}function x2(e,t){if(t.has(e))return t.get(e);const r=`$${t.size}_${e.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/ug,"_")}`;return t.set(e,r),r}function ML(e){const t=["dotAll","ignoreCase"],r={enable:{},disable:{}};return e.forEach(({flags:n})=>{t.forEach(i=>{var s,a;(s=n.enable)!=null&&s[i]&&(delete r.disable[i],r.enable[i]=!0),(a=n.disable)!=null&&a[i]&&(r.disable[i]=!0)})}),Object.keys(r.enable).length||delete r.enable,Object.keys(r.disable).length||delete r.disable,r.enable||r.disable?r:null}function Xte({dotAll:e,ignoreCase:t}){const r={};return(e||t)&&(r.enable={},e&&(r.enable.dotAll=!0),t&&(r.enable.ignoreCase=!0)),(!e||!t)&&(r.disable={},!e&&(r.disable.dotAll=!0),!t&&(r.disable.ignoreCase=!0)),r}function jL(e){if(!e)throw new Error("Node expected");const{body:t}=e;return Array.isArray(t)?t:t?[t]:null}function BL(e){const t=e.find(r=>r.kind==="search_start"||Jte(r,{negate:!1})||!Qte(r));if(!t)return null;if(t.kind==="search_start")return t;if(t.type==="LookaroundAssertion")return t.body[0].body[0];if(t.type==="CapturingGroup"||t.type==="Group"){const r=[];for(const n of t.body){const i=BL(n.body);if(!i)return null;Array.isArray(i)?r.push(...i):r.push(i)}return r}return null}function PL(e,t){const r=jL(e)??[];for(const n of r)if(n===t||PL(n,t))return!0;return!1}function Qte({type:e}){return e==="Assertion"||e==="Directive"||e==="LookaroundAssertion"}function Zte(e){const t=["Character","CharacterClass","CharacterSet"];return t.includes(e.type)||e.type==="Quantifier"&&e.min&&t.includes(e.body.type)}function Jte(e,t){const r={negate:null,...t};return e.type==="LookaroundAssertion"&&(r.negate===null||e.negate===r.negate)&&e.body.length===1&&xL(e.body[0],{type:"Assertion",kind:"search_start"})}function S2(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function Us(e,t){const n=SL(e,{...t,unicodePropertyMap:D3}).body;return n.length>1||n[0].body.length>1?Xi({body:n}):n[0].body[0]}function w2(e,t){return e.negate=t,e}function Oa(e,t){return e.parent=t,e}function ur(e,t){return DL(e),e.parent=t,e}function ere(e,t){const r=RL(t),n=Tv(r.target,"ES2024"),i=Tv(r.target,"ES2025"),s=r.rules.recursionLimit;if(!Number.isInteger(s)||s<2||s>20)throw new Error("Invalid recursionLimit; use 2-20");let a=null,o=null;if(!i){const f=[e.flags.ignoreCase];qh(e,tre,{getCurrentModI:()=>f.at(-1),popModI(){f.pop()},pushModI(p){f.push(p)},setHasCasedChar(){f.at(-1)?a=!0:o=!0}})}const l={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||a)&&!o)};let u=e;const c={accuracy:r.accuracy,appliedGlobalFlags:l,captureMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},inCharClass:!1,lastNode:u,originMap:e._originMap,recursionLimit:s,useAppliedIgnoreCase:!!(!i&&a&&o),useFlagMods:i,useFlagV:n,verbose:r.verbose};function d(f){return c.lastNode=u,u=f,Ote(rre[f.type],`Unexpected node type "${f.type}"`)(f,c,d)}const m={pattern:e.body.map(d).join("|"),flags:d(e.flags),options:{...e.options}};return n||(delete m.options.force.v,m.options.disable.v=!0,m.options.unicodeSetsPlugin=null),m._captureTransfers=new Map,m._hiddenCaptures=[],c.captureMap.forEach((f,p)=>{f.hidden&&m._hiddenCaptures.push(p),f.transferTo&&Rd(m._captureTransfers,f.transferTo,[]).push(p)}),m}var tre={"*":{enter({node:e},t){if(g8(e)){const r=t.getCurrentModI();t.pushModI(e.flags?_p({ignoreCase:r},e.flags).ignoreCase:r)}},exit({node:e},t){g8(e)&&t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){O3(Nr(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},r){t(),zL(e,{firstOnly:!0}).length&&r.setHasCasedChar()},CharacterSet({node:e},t){e.kind==="property"&&IL.has(e.value)&&t.setHasCasedChar()}},rre={Alternative({body:e},t,r){return e.map(r).join("")},Assertion({kind:e,negate:t}){if(e==="string_end")return"$";if(e==="string_start")return"^";if(e==="word_boundary")return t?rt`\B`:rt`\b`;throw new Error(`Unexpected assertion kind "${e}"`)},Backreference({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&t.accuracy==="strict"&&t.currentFlags.ignoreCase&&!t.captureMap.get(e).ignoreCase)throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");return"\\"+e},CapturingGroup(e,t,r){const{body:n,name:i,number:s}=e,a={ignoreCase:t.currentFlags.ignoreCase},o=t.originMap.get(e);return o&&(a.hidden=!0,s>o.number&&(a.transferTo=o.number)),t.captureMap.set(s,a),`(${i?`?<${i}>`:""}${n.map(r).join("|")})`},Character({value:e},t){const r=Nr(e),n=nu(e,{escDigit:t.lastNode.type==="Backreference",inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(n!==r)return n;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&O3(r)){const i=LL(r);return t.inCharClass?i.join(""):i.length>1?`[${i.join("")}]`:i[0]}return r},CharacterClass(e,t,r){const{kind:n,negate:i,parent:s}=e;let{body:a}=e;if(n==="intersection"&&!t.useFlagV)throw new Error("Use of character class intersection requires min target ES2024");Qi.bugFlagVLiteralHyphenIsRange&&t.useFlagV&&a.some(b8)&&(a=[x1(45),...a.filter(u=>!b8(u))]);const o=()=>`[${i?"^":""}${a.map(r).join(n==="intersection"?"&&":"")}]`;if(!t.inCharClass){if((!t.useFlagV||Qi.bugNestedClassIgnoresNegation)&&!i){const c=a.filter(d=>d.type==="CharacterClass"&&d.kind==="union"&&d.negate);if(c.length){const d=Xi(),m=d.body[0];return d.parent=s,m.parent=d,a=a.filter(f=>!c.includes(f)),e.body=a,a.length?(e.parent=m,m.body.push(e)):d.body.pop(),c.forEach(f=>{const p=Al({body:[f]});f.parent=p,p.parent=d,d.body.push(p)}),r(d)}}t.inCharClass=!0;const u=o();return t.inCharClass=!1,u}const l=a[0];if(n==="union"&&!i&&l&&((!t.useFlagV||!t.verbose)&&s.kind==="union"&&!(Qi.bugFlagVLiteralHyphenIsRange&&t.useFlagV)||!t.verbose&&s.kind==="intersection"&&a.length===1&&l.type!=="CharacterClassRange"))return a.map(r).join("");if(!t.useFlagV&&s.type==="CharacterClass")throw new Error("Uses nested character class in a way that requires min target ES2024");return o()},CharacterClassRange(e,t){const r=e.min.value,n=e.max.value,i={escDigit:!1,inCharClass:!0,useFlagV:t.useFlagV},s=nu(r,i),a=nu(n,i),o=new Set;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){const l=zL(e);ore(l).forEach(c=>{o.add(Array.isArray(c)?`${nu(c[0],i)}-${nu(c[1],i)}`:nu(c,i))})}return`${s}-${a}${[...o].join("")}`},CharacterSet({kind:e,negate:t,value:r,key:n},i){if(e==="dot")return i.currentFlags.dotAll?i.appliedGlobalFlags.dotAll||i.useFlagMods?".":"[^]":rt`[^\n]`;if(e==="digit")return t?rt`\D`:rt`\d`;if(e==="property"){if(i.useAppliedIgnoreCase&&i.currentFlags.ignoreCase&&IL.has(r))throw new Error(`Unicode property "${r}" can't be case-insensitive when other chars have specific case`);return`${t?rt`\P`:rt`\p`}{${n?`${n}=`:""}${r}}`}if(e==="word")return t?rt`\W`:rt`\w`;throw new Error(`Unexpected character set kind "${e}"`)},Flags(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")},Group({atomic:e,body:t,flags:r,parent:n},i,s){const a=i.currentFlags;r&&(i.currentFlags=_p(a,r));const o=t.map(s).join("|"),l=!i.verbose&&t.length===1&&n.type!=="Quantifier"&&!e&&(!i.useFlagMods||!r)?o:`(?${lre(e,r,i.useFlagMods)}${o})`;return i.currentFlags=a,l},LookaroundAssertion({body:e,kind:t,negate:r},n,i){return`(?${`${t==="lookahead"?"":"<"}${r?"!":"="}`}${e.map(i).join("|")})`},Quantifier(e,t,r){return r(e.body)+ure(e)},Subroutine({isRecursive:e,ref:t},r){if(!e)throw new Error("Unexpected non-recursive subroutine in transformed AST");const n=r.recursionLimit;return t===0?`(?R=${n})`:rt`\g<${t}&R=${n}>`}},nre=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),ire=new Set(["-","\\","]","^","["]),sre=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),p8=new Map([[9,rt`\t`],[10,rt`\n`],[11,rt`\v`],[12,rt`\f`],[13,rt`\r`],[8232,rt`\u2028`],[8233,rt`\u2029`],[65279,rt`\uFEFF`]]),are=new RegExp("^\\p{Cased}$","u");function O3(e){return are.test(e)}function zL(e,t){const r=!!(t!=null&&t.firstOnly),n=e.min.value,i=e.max.value,s=[];if(n<65&&(i===65535||i>=131071)||n===65536&&i>=131071)return s;for(let a=n;a<=i;a++){const o=Nr(a);if(!O3(o))continue;const l=LL(o).filter(u=>{const c=u.codePointAt(0);return c<n||c>i});if(l.length&&(s.push(...l),r))break}return s}function nu(e,{escDigit:t,inCharClass:r,useFlagV:n}){if(p8.has(e))return p8.get(e);if(e<32||e>126&&e<160||e>262143||t&&cre(e))return e>255?`\\u{${e.toString(16).toUpperCase()}}`:`\\x${e.toString(16).toUpperCase().padStart(2,"0")}`;const i=r?n?sre:ire:nre,s=Nr(e);return(i.has(s)?"\\":"")+s}function ore(e){const t=e.map(i=>i.codePointAt(0)).sort((i,s)=>i-s),r=[];let n=null;for(let i=0;i<t.length;i++)t[i+1]===t[i]+1?n??(n=t[i]):n===null?r.push(t[i]):(r.push([n,t[i]]),n=null);return r}function lre(e,t,r){if(e)return">";let n="";if(t&&r){const{enable:i,disable:s}=t;n=(i!=null&&i.ignoreCase?"i":"")+(i!=null&&i.dotAll?"s":"")+(s?"-":"")+(s!=null&&s.ignoreCase?"i":"")+(s!=null&&s.dotAll?"s":"")}return`${n}:`}function ure({kind:e,max:t,min:r}){let n;return!r&&t===1?n="?":!r&&t===1/0?n="*":r===1&&t===1/0?n="+":r===t?n=`{${r}}`:n=`{${r},${t===1/0?"":t}}`,n+{greedy:"",lazy:"?",possessive:"+"}[e]}function g8({type:e}){return e==="CapturingGroup"||e==="Group"||e==="LookaroundAssertion"}function cre(e){return e>47&&e<58}function b8({type:e,value:t}){return e==="Character"&&t===45}var qa,Ks,nl,Ga,il,Bd,Av,go,hre=(go=class extends RegExp{constructor(r,n,i){var t=(...f3e)=>(super(...f3e),Io(this,Bd),Io(this,qa,new Map),Io(this,Ks,null),Io(this,nl),Io(this,Ga,null),Io(this,il,null),J(this,"rawOptions",{}),this);const s=!!(i!=null&&i.lazyCompile);if(r instanceof RegExp){if(i)throw new Error("Cannot provide options when copying a regexp");const a=r;t(a,n),Ui(this,nl,a.source),a instanceof go&&(Ui(this,qa,wn(a,qa)),Ui(this,Ga,wn(a,Ga)),Ui(this,il,wn(a,il)),this.rawOptions=a.rawOptions)}else{const a={hiddenCaptures:[],strategy:null,transfers:[],...i};t(s?"":r,n),Ui(this,nl,r),Ui(this,qa,fre(a.hiddenCaptures,a.transfers)),Ui(this,il,a.strategy),this.rawOptions=i??{}}s||Ui(this,Ks,this)}get source(){return wn(this,nl)||"(?:)"}exec(r){if(!wn(this,Ks)){const{lazyCompile:s,...a}=this.rawOptions;Ui(this,Ks,new go(wn(this,nl),this.flags,a))}const n=this.global||this.sticky,i=this.lastIndex;if(wn(this,il)==="clip_search"&&n&&i){this.lastIndex=0;const s=eg(this,Bd,Av).call(this,r.slice(i));return s&&(dre(s,i,r,this.hasIndices),this.lastIndex+=i),s}return eg(this,Bd,Av).call(this,r)}},qa=new WeakMap,Ks=new WeakMap,nl=new WeakMap,Ga=new WeakMap,il=new WeakMap,Bd=new WeakSet,Av=function(r){wn(this,Ks).lastIndex=this.lastIndex;const n=Y6(go.prototype,this,"exec").call(wn(this,Ks),r);if(this.lastIndex=wn(this,Ks).lastIndex,!n||!wn(this,qa).size)return n;const i=[...n];n.length=1;let s;this.hasIndices&&(s=[...n.indices],n.indices.length=1);const a=[0];for(let o=1;o<i.length;o++){const{hidden:l,transferTo:u}=wn(this,qa).get(o)??{};if(l?a.push(null):(a.push(n.length),n.push(i[o]),this.hasIndices&&n.indices.push(s[o])),u&&i[o]!==void 0){const c=a[u];if(!c)throw new Error(`Invalid capture transfer to "${c}"`);if(n[c]=i[o],this.hasIndices&&(n.indices[c]=s[o]),n.groups){wn(this,Ga)||Ui(this,Ga,mre(this.source));const d=wn(this,Ga).get(u);d&&(n.groups[d]=i[o],this.hasIndices&&(n.indices.groups[d]=s[o]))}}}return n},go);function dre(e,t,r,n){if(e.index+=t,e.input=r,n){const i=e.indices;for(let a=0;a<i.length;a++){const o=i[a];o&&(i[a]=[o[0]+t,o[1]+t])}const s=i.groups;s&&Object.keys(s).forEach(a=>{const o=s[a];o&&(s[a]=[o[0]+t,o[1]+t])})}}function fre(e,t){const r=new Map;for(const n of e)r.set(n,{hidden:!0});for(const[n,i]of t)for(const s of i)Rd(r,s,{}).transferTo=n;return r}function mre(e){const t=/(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu,r=new Map;let n=0,i=0,s;for(;s=t.exec(e);){const{0:a,groups:{capture:o,name:l}}=s;a==="["?n++:n?a==="]"&&n--:o&&(i++,l&&r.set(i,l))}return r}function pre(e,t){const r=gre(e,t);return r.options?new hre(r.pattern,r.flags,r.options):new RegExp(r.pattern,r.flags)}function gre(e,t){const r=RL(t),n=SL(e,{flags:r.flags,normalizeUnknownPropertyNames:!0,rules:{captureGroup:r.rules.captureGroup,singleline:r.rules.singleline},skipBackrefValidation:r.rules.allowOrphanBackrefs,unicodePropertyMap:D3}),i=Ute(n,{accuracy:r.accuracy,asciiWordBoundaries:r.rules.asciiWordBoundaries,avoidSubclass:r.avoidSubclass,bestEffortTarget:r.target}),s=ere(i,r),a=Ite(s.pattern,{captureTransfers:s._captureTransfers,hiddenCaptures:s._hiddenCaptures,mode:"external"}),o=Rte(a.pattern),l=Nte(o.pattern,{captureTransfers:a.captureTransfers,hiddenCaptures:a.hiddenCaptures}),u={pattern:l.pattern,flags:`${r.hasIndices?"d":""}${r.global?"g":""}${s.flags}${s.options.disable.v?"u":"v"}`};if(r.avoidSubclass){if(r.lazyCompileLength!==1/0)throw new Error("Lazy compilation requires subclass")}else{const c=l.hiddenCaptures.sort((p,g)=>p-g),d=Array.from(l.captureTransfers),m=i._strategy,f=u.pattern.length>=r.lazyCompileLength;(c.length||d.length||m||f)&&(u.options={...c.length&&{hiddenCaptures:c},...d.length&&{transfers:d},...m&&{strategy:m},...f&&{lazyCompile:f}})}return u}const _8=4294967295;class bre{constructor(t,r={}){J(this,"regexps");this.patterns=t,this.options=r;const{forgiving:n=!1,cache:i,regexConstructor:s}=r;if(!s)throw new Error("Option `regexConstructor` is not provided");this.regexps=t.map(a=>{if(typeof a!="string")return a;const o=i==null?void 0:i.get(a);if(o){if(o instanceof RegExp)return o;if(n)return null;throw o}try{const l=s(a);return i==null||i.set(a,l),l}catch(l){if(i==null||i.set(a,l),n)return null;throw l}})}findNextMatchSync(t,r,n){const i=typeof t=="string"?t:t.content,s=[];function a(o,l,u=0){return{index:o,captureIndices:l.indices.map(c=>c==null?{start:_8,end:_8,length:0}:{start:c[0]+u,end:c[1]+u,length:c[1]-c[0]})}}for(let o=0;o<this.regexps.length;o++){const l=this.regexps[o];if(l)try{l.lastIndex=r;const u=l.exec(i);if(!u)continue;if(u.index===r)return a(o,u,0);s.push([o,u,0])}catch(u){if(this.options.forgiving)continue;throw u}}if(s.length){const o=Math.min(...s.map(l=>l[1].index));for(const[l,u,c]of s)if(u.index===o)return a(l,u,c)}return null}}function _re(e,t){return pre(e,{global:!0,hasIndices:!0,lazyCompileLength:3e3,rules:{allowOrphanBackrefs:!0,asciiWordBoundaries:!0,captureGroup:!0,recursionLimit:5,singleline:!0},...t})}function vre(e={}){const t=Object.assign({target:"auto",cache:new Map},e);return t.regexConstructor||(t.regexConstructor=r=>_re(r,{target:t.target})),{createScanner(r){return new bre(r,t)},createString(r){return{content:r}}}}var yre=vre({forgiving:!0}),xre=Object.fromEntries(A3.flatMap(e=>{var t;return((t=e.aliases)!=null?t:[]).map(r=>[r,e.id])})),em=new Set(Object.keys(mL)),v8=e=>{let t=e.trim().toLowerCase();return xre[t]||(em.has(t),t)},E2=new Map,k2=new Map,iu=new Map,vp=e=>{var t;return typeof e=="string"?e:(t=e.name)!=null?t:"custom"},Sre=(e,t)=>`${e}-${vp(t[0])}-${vp(t[1])}`,wre=(e,t,r)=>{let n=e.slice(0,100),i=e.length>100?e.slice(-100):"";return`${t}:${r[0]}:${r[1]}:${e.length}:${n}:${i}`},Ere=(e,t)=>{let r=Sre(e,t);if(E2.has(r))return E2.get(r);let n=Dee({themes:t,langs:[e],engine:yre});return E2.set(r,n),n};function kre(e={}){var t;let r=(t=e.themes)!=null?t:["github-light","github-dark"];return{name:"shiki",type:"code-highlighter",supportsLanguage(n){let i=v8(n);return em.has(i)},getSupportedLanguages(){return Array.from(em)},getThemes(){return r},highlight({code:n,language:i,themes:s},a){let o=v8(i),l=[vp(s[0]),vp(s[1])],u=wre(n,o,l);if(k2.has(u))return k2.get(u);a&&(iu.has(u)||iu.set(u,new Set),iu.get(u).add(a));let c=em.has(o)?o:"text";return Ere(c,s).then(d=>{let m=d.getLoadedLanguages().includes(o)?o:"text",f=d.codeToTokens(n,{lang:m,themes:{light:l[0],dark:l[1]}});k2.set(u,f);let p=iu.get(u);if(p){for(let g of p)g(f);iu.delete(u)}}).catch(d=>{console.error("[Streamdown Code] Failed to highlight code:",d),iu.delete(u)}),null}}}var Cre=kre();const y8=/[#.]/g;function Tre(e,t){const r=e||"",n={};let i=0,s,a;for(;i<r.length;){y8.lastIndex=i;const o=y8.exec(r),l=r.slice(i,o?o.index:r.length);l&&(s?s==="#"?n.id=l:Array.isArray(n.className)?n.className.push(l):n.className=[l]:a=l,i+=l.length),o&&(s=o[0],i++)}return{type:"element",tagName:a||t||"div",properties:n,children:[]}}function $L(e,t,r){const n=r?Lre(r):void 0;function i(s,a,...o){let l;if(s==null){l={type:"root",children:[]};const u=a;o.unshift(u)}else{l=Tre(s,t);const u=l.tagName.toLowerCase(),c=n?n.get(u):void 0;if(l.tagName=c||u,Are(a))o.unshift(a);else for(const[d,m]of Object.entries(a))Nre(e,l.properties,d,m)}for(const u of o)Nv(l.children,u);return l.type==="element"&&l.tagName==="template"&&(l.content={type:"root",children:l.children},l.children=[]),l}return i}function Are(e){if(e===null||typeof e!="object"||Array.isArray(e))return!0;if(typeof e.type!="string")return!1;const t=e,r=Object.keys(e);for(const n of r){const i=t[n];if(i&&typeof i=="object"){if(!Array.isArray(i))return!0;const s=i;for(const a of s)if(typeof a!="number"&&typeof a!="string")return!0}}return!!("children"in e&&Array.isArray(e.children))}function Nre(e,t,r,n){const i=d0(e,r);let s;if(n!=null){if(typeof n=="number"){if(Number.isNaN(n))return;s=n}else typeof n=="boolean"?s=n:typeof n=="string"?i.spaceSeparated?s=Uw(n):i.commaSeparated?s=Fw(n):i.commaOrSpaceSeparated?s=Uw(Fw(n).join(" ")):s=x8(i,i.property,n):Array.isArray(n)?s=[...n]:s=i.property==="style"?Rre(n):String(n);if(Array.isArray(s)){const a=[];for(const o of s)a.push(x8(i,i.property,o));s=a}i.property==="className"&&Array.isArray(t.className)&&(s=t.className.concat(s)),t[i.property]=s}}function Nv(e,t){if(t!=null)if(typeof t=="number"||typeof t=="string")e.push({type:"text",value:String(t)});else if(Array.isArray(t))for(const r of t)Nv(e,r);else if(typeof t=="object"&&"type"in t)t.type==="root"?Nv(e,t.children):e.push(t);else throw new Error("Expected node, nodes, or string, got `"+t+"`")}function x8(e,t,r){if(typeof r=="string"){if(e.number&&r&&!Number.isNaN(Number(r)))return Number(r);if((e.boolean||e.overloadedBoolean)&&(r===""||Ad(r)===Ad(t)))return!0}return r}function Rre(e){const t=[];for(const[r,n]of Object.entries(e))t.push([r,n].join(": "));return t.join("; ")}function Lre(e){const t=new Map;for(const r of e)t.set(r.toLowerCase(),r);return t}const Ire=["altGlyph","altGlyphDef","altGlyphItem","animateColor","animateMotion","animateTransform","clipPath","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","foreignObject","glyphRef","linearGradient","radialGradient","solidColor","textArea","textPath"],HL=$L(Cc,"div"),FL=$L(Rs,"g",Ire),vs={html:"http://www.w3.org/1999/xhtml",mathml:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Dre(e,t){return UL(e,{})||{type:"root",children:[]}}function UL(e,t){const r=Ore(e,t);return r&&t.afterTransform&&t.afterTransform(e,r),r}function Ore(e,t){switch(e.nodeType){case 1:return Pre(e,t);case 3:return jre(e);case 8:return Bre(e);case 9:return S8(e,t);case 10:return Mre();case 11:return S8(e,t);default:return}}function S8(e,t){return{type:"root",children:VL(e,t)}}function Mre(){return{type:"doctype"}}function jre(e){return{type:"text",value:e.nodeValue||""}}function Bre(e){return{type:"comment",value:e.nodeValue||""}}function Pre(e,t){const r=e.namespaceURI,n=r===vs.svg?FL:HL,i=r===vs.html?e.tagName.toLowerCase():e.tagName,s=r===vs.html&&i==="template"?e.content:e,a=e.getAttributeNames(),o={};let l=-1;for(;++l<a.length;)o[a[l]]=e.getAttribute(a[l])||"";return n(i,o,VL(s,t))}function VL(e,t){const r=e.childNodes,n=[];let i=-1;for(;++i<r.length;){const s=UL(r[i],t);s!==void 0&&n.push(s)}return n}new DOMParser;function zre(e,t){const r=$re(e);return Dre(r)}function $re(e){const t=document.createElement("template");return t.innerHTML=e,t.content}const w8=function(e,t,r){const n=l0(r);if(!e||!e.type||!e.children)throw new Error("Expected parent node");if(typeof t=="number"){if(t<0||t===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if(t=e.children.indexOf(t),t<0)throw new Error("Expected child node or index");for(;++t<e.children.length;)if(n(e.children[t],t,e))return e.children[t]},$l=function(e){if(e==null)return Ure;if(typeof e=="string")return Fre(e);if(typeof e=="object")return Hre(e);if(typeof e=="function")return M3(e);throw new Error("Expected function, string, or array as `test`")};function Hre(e){const t=[];let r=-1;for(;++r<e.length;)t[r]=$l(e[r]);return M3(n);function n(...i){let s=-1;for(;++s<t.length;)if(t[s].apply(this,i))return!0;return!1}}function Fre(e){return M3(t);function t(r){return r.tagName===e}}function M3(e){return t;function t(r,n,i){return!!(Vre(r)&&e.call(this,r,typeof n=="number"?n:void 0,i||void 0))}}function Ure(e){return!!(e&&typeof e=="object"&&"type"in e&&e.type==="element"&&"tagName"in e&&typeof e.tagName=="string")}function Vre(e){return e!==null&&typeof e=="object"&&"type"in e&&"tagName"in e}const E8=/\n/g,k8=/[\t ]+/g,Rv=$l("br"),C8=$l(Zre),qre=$l("p"),T8=$l("tr"),Gre=$l(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",Qre,Jre]),qL=$l(["address","article","aside","blockquote","body","caption","center","dd","dialog","dir","dl","dt","div","figure","figcaption","footer","form,","h1","h2","h3","h4","h5","h6","header","hgroup","hr","html","legend","li","listing","main","menu","nav","ol","p","plaintext","pre","section","ul","xmp"]);function Wre(e,t){const r=t||{},n="children"in e?e.children:[],i=qL(e),s=YL(e,{whitespace:r.whitespace||"normal"}),a=[];(e.type==="text"||e.type==="comment")&&a.push(...WL(e,{breakBefore:!0,breakAfter:!0}));let o=-1;for(;++o<n.length;)a.push(...GL(n[o],e,{whitespace:s,breakBefore:o?void 0:i,breakAfter:o<n.length-1?Rv(n[o+1]):i}));const l=[];let u;for(o=-1;++o<a.length;){const c=a[o];typeof c=="number"?u!==void 0&&c>u&&(u=c):c&&(u!==void 0&&u>-1&&l.push(`
286
286
  `.repeat(u)||" "),u=-1,l.push(c))}return l.join("")}function GL(e,t,r){return e.type==="element"?Yre(e,t,r):e.type==="text"?r.whitespace==="normal"?WL(e,r):Kre(e):[]}function Yre(e,t,r){const n=YL(e,r),i=e.children||[];let s=-1,a=[];if(Gre(e))return a;let o,l;for(Rv(e)||T8(e)&&w8(t,e,T8)?l=`
287
287
  `:qre(e)?(o=2,l=2):qL(e)&&(o=1,l=1);++s<i.length;)a=a.concat(GL(i[s],e,{whitespace:n,breakBefore:s?void 0:o,breakAfter:s<i.length-1?Rv(i[s+1]):l}));return C8(e)&&w8(t,e,C8)&&a.push(" "),o&&a.unshift(o),l&&a.push(l),a}function WL(e,t){const r=String(e.value),n=[],i=[];let s=0;for(;s<=r.length;){E8.lastIndex=s;const l=E8.exec(r),u=l&&"index"in l?l.index:r.length;n.push(Xre(r.slice(s,u).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g,""),s===0?t.breakBefore:!0,u===r.length?t.breakAfter:!0)),s=u+1}let a=-1,o;for(;++a<n.length;)n[a].charCodeAt(n[a].length-1)===8203||a<n.length-1&&n[a+1].charCodeAt(0)===8203?(i.push(n[a]),o=void 0):n[a]?(typeof o=="number"&&i.push(o),i.push(n[a]),o=0):(a===0||a===n.length-1)&&i.push(0);return i}function Kre(e){return[String(e.value)]}function Xre(e,t,r){const n=[];let i=0,s;for(;i<e.length;){k8.lastIndex=i;const a=k8.exec(e);s=a?a.index:e.length,!i&&!s&&a&&!t&&n.push(""),i!==s&&n.push(e.slice(i,s)),i=a?s+a[0].length:s}return i!==s&&!r&&n.push(""),n.join(" ")}function YL(e,t){if(e.type==="element"){const r=e.properties||{};switch(e.tagName){case"listing":case"plaintext":case"xmp":return"pre";case"nobr":return"nowrap";case"pre":return r.wrap?"pre-wrap":"pre";case"td":case"th":return r.noWrap?"nowrap":t.whitespace;case"textarea":return"pre-wrap"}}return t.whitespace}function Qre(e){return!!(e.properties||{}).hidden}function Zre(e){return e.tagName==="td"||e.tagName==="th"}function Jre(e){return e.tagName==="dialog"&&!(e.properties||{}).open}class pe extends Error{constructor(t,r){var n="KaTeX parse error: "+t,i,s,a=r&&r.loc;if(a&&a.start<=a.end){var o=a.lexer.input;i=a.start,s=a.end,i===o.length?n+=" at end of input: ":n+=" at position "+(i+1)+": ";var l=o.slice(i,s).replace(/[^]/g,"$&̲"),u;i>15?u="…"+o.slice(i-15,i):u=o.slice(0,i);var c;s+15<o.length?c=o.slice(s,s+15)+"…":c=o.slice(s),n+=u+l+c}super(n),this.name="ParseError",this.position=void 0,this.length=void 0,this.rawMessage=void 0,Object.setPrototypeOf(this,pe.prototype),this.position=i,i!=null&&s!=null&&(this.length=s-i),this.rawMessage=t}}var ene=/([A-Z])/g,tne=e=>e.replace(ene,"-$1").toLowerCase(),rne={"&":"&amp;",">":"&gt;","<":"&lt;",'"':"&quot;","'":"&#x27;"},nne=/[&><"']/g,yn=e=>String(e).replace(nne,t=>rne[t]),tm=e=>e.type==="ordgroup"||e.type==="color"?e.body.length===1?tm(e.body[0]):e:e.type==="font"?tm(e.body):e,ine=new Set(["mathord","textord","atom"]),ya=e=>ine.has(tm(e).type),sne=e=>{var t=/^[\x00-\x20]*([^\\/#?]*?)(:|&#0*58|&#x0*3a|&colon)/i.exec(e);return t?t[2]!==":"||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():"_relative"},Lv={displayMode:{type:"boolean",description:"Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.",cli:"-d, --display-mode"},output:{type:{enum:["htmlAndMathml","html","mathml"]},description:"Determines the markup language of the output.",cli:"-F, --format <type>"},leqno:{type:"boolean",description:"Render display math in leqno style (left-justified tags)."},fleqn:{type:"boolean",description:"Render display math flush left."},throwOnError:{type:"boolean",default:!0,cli:"-t, --no-throw-on-error",cliDescription:"Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error."},errorColor:{type:"string",default:"#cc0000",cli:"-c, --error-color <color>",cliDescription:"A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.",cliProcessor:e=>"#"+e},macros:{type:"object",cli:"-m, --macro <def>",cliDescription:"Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).",cliDefault:[],cliProcessor:(e,t)=>(t.push(e),t)},minRuleThickness:{type:"number",description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:"--min-rule-thickness <size>",cliProcessor:parseFloat},colorIsTextColor:{type:"boolean",description:"Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.",cli:"-b, --color-is-text-color"},strict:{type:[{enum:["warn","ignore","error"]},"boolean","function"],description:"Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.",cli:"-S, --strict",cliDefault:!1},trust:{type:["boolean","function"],description:"Trust the input, enabling all HTML features such as \\url.",cli:"-T, --trust"},maxSize:{type:"number",default:1/0,description:"If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large",processor:e=>Math.max(0,e),cli:"-s, --max-size <n>",cliProcessor:parseInt},maxExpand:{type:"number",default:1e3,description:"Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.",processor:e=>Math.max(0,e),cli:"-e, --max-expand <n>",cliProcessor:e=>e==="Infinity"?1/0:parseInt(e)},globalGroup:{type:"boolean",cli:!1}};function ane(e){if(typeof e!="string")return e.enum[0];switch(e){case"boolean":return!1;case"string":return"";case"number":return 0;case"object":return{};default:throw new Error("Unexpected schema type; settings must declare an explicit default.")}}function one(e){if(e.default!==void 0)return e.default;var t=Array.isArray(e.type)?e.type[0]:e.type;return ane(t)}function lne(e,t,r,n){var i=r[t];e[t]=i!==void 0?n.processor?n.processor(i):i:one(n)}class j3{constructor(t){t===void 0&&(t={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,t=t||{};for(var r of Object.keys(Lv)){var n=Lv[r];n&&lne(this,r,t,n)}}reportNonstrict(t,r,n){var i=this.strict;if(typeof i=="function"&&(i=i(t,r,n)),!(!i||i==="ignore")){if(i===!0||i==="error")throw new pe("LaTeX-incompatible input and strict mode is set to 'error': "+(r+" ["+t+"]"),n);i==="warn"?typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(r+" ["+t+"]")):typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+i+"': "+r+" ["+t+"]"))}}useStrictBehavior(t,r,n){var i=this.strict;if(typeof i=="function")try{i=i(t,r,n)}catch{i="error"}return!i||i==="ignore"?!1:i===!0||i==="error"?!0:i==="warn"?(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(r+" ["+t+"]")),!1):(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+i+"': "+r+" ["+t+"]")),!1)}isTrusted(t){if("url"in t&&t.url&&!t.protocol){var r=sne(t.url);if(r==null)return!1;t.protocol=r}var n=typeof this.trust=="function"?this.trust(t):this.trust;return!!n}}class Na{constructor(t,r,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=t,this.size=r,this.cramped=n}sup(){return fs[une[this.id]]}sub(){return fs[cne[this.id]]}fracNum(){return fs[hne[this.id]]}fracDen(){return fs[dne[this.id]]}cramp(){return fs[fne[this.id]]}text(){return fs[mne[this.id]]}isTight(){return this.size>=2}}var B3=0,yp=1,$u=2,la=3,Ld=4,Oi=5,nc=6,Ln=7,fs=[new Na(B3,0,!1),new Na(yp,0,!0),new Na($u,1,!1),new Na(la,1,!0),new Na(Ld,2,!1),new Na(Oi,2,!0),new Na(nc,3,!1),new Na(Ln,3,!0)],une=[Ld,Oi,Ld,Oi,nc,Ln,nc,Ln],cne=[Oi,Oi,Oi,Oi,Ln,Ln,Ln,Ln],hne=[$u,la,Ld,Oi,nc,Ln,nc,Ln],dne=[la,la,Oi,Oi,Ln,Ln,Ln,Ln],fne=[yp,yp,la,la,Oi,Oi,Ln,Ln],mne=[B3,yp,$u,la,$u,la,$u,la],et={DISPLAY:fs[B3],TEXT:fs[$u],SCRIPT:fs[Ld],SCRIPTSCRIPT:fs[nc]},Iv=[{name:"latin",blocks:[[256,591],[768,879]]},{name:"cyrillic",blocks:[[1024,1279]]},{name:"armenian",blocks:[[1328,1423]]},{name:"brahmic",blocks:[[2304,4255]]},{name:"georgian",blocks:[[4256,4351]]},{name:"cjk",blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:"hangul",blocks:[[44032,55215]]}];function pne(e){for(var t=0;t<Iv.length;t++)for(var r=Iv[t],n=0;n<r.blocks.length;n++){var i=r.blocks[n];if(e>=i[0]&&e<=i[1])return r.name}return null}var rm=[];Iv.forEach(e=>e.blocks.forEach(t=>rm.push(...t)));function KL(e){for(var t=0;t<rm.length;t+=2)if(e>=rm[t]&&e<=rm[t+1])return!0;return!1}var Tr=e=>e+" "+e,su=80,gne=function(t,r){return"M95,"+(622+t+r)+`
288
288
  c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14
@@ -653,8 +653,8 @@ ${e}</tr>
653
653
  `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${cs(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:r}){let n=this.parser.parseInline(r),i=B7(e);if(i===null)return n;e=i;let s='<a href="'+e+'"';return t&&(s+=' title="'+cs(t)+'"'),s+=">"+n+"</a>",s}image({href:e,title:t,text:r,tokens:n}){n&&(r=this.parser.parseInline(n,this.parser.textRenderer));let i=B7(e);if(i===null)return cs(r);e=i;let s=`<img src="${e}" alt="${cs(r)}"`;return t&&(s+=` title="${cs(t)}"`),s+=">",s}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:cs(e.text)}},L6=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},Yi=class hy{constructor(t){J(this,"options");J(this,"renderer");J(this,"textRenderer");this.options=t||ql,this.options.renderer=this.options.renderer||new Op,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new L6}static parse(t,r){return new hy(r).parse(t)}static parseInline(t,r){return new hy(r).parseInline(t)}parse(t){var n,i;this.renderer.parser=this;let r="";for(let s=0;s<t.length;s++){let a=t[s];if((i=(n=this.options.extensions)==null?void 0:n.renderers)!=null&&i[a.type]){let l=a,u=this.options.extensions.renderers[l.type].call({parser:this},l);if(u!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(l.type)){r+=u||"";continue}}let o=a;switch(o.type){case"space":{r+=this.renderer.space(o);break}case"hr":{r+=this.renderer.hr(o);break}case"heading":{r+=this.renderer.heading(o);break}case"code":{r+=this.renderer.code(o);break}case"table":{r+=this.renderer.table(o);break}case"blockquote":{r+=this.renderer.blockquote(o);break}case"list":{r+=this.renderer.list(o);break}case"checkbox":{r+=this.renderer.checkbox(o);break}case"html":{r+=this.renderer.html(o);break}case"def":{r+=this.renderer.def(o);break}case"paragraph":{r+=this.renderer.paragraph(o);break}case"text":{r+=this.renderer.text(o);break}default:{let l='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return r}parseInline(t,r=this.renderer){var i,s;this.renderer.parser=this;let n="";for(let a=0;a<t.length;a++){let o=t[a];if((s=(i=this.options.extensions)==null?void 0:i.renderers)!=null&&s[o.type]){let u=this.options.extensions.renderers[o.type].call({parser:this},o);if(u!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(o.type)){n+=u||"";continue}}let l=o;switch(l.type){case"escape":{n+=r.text(l);break}case"html":{n+=r.html(l);break}case"link":{n+=r.link(l);break}case"image":{n+=r.image(l);break}case"checkbox":{n+=r.checkbox(l);break}case"strong":{n+=r.strong(l);break}case"em":{n+=r.em(l);break}case"codespan":{n+=r.codespan(l);break}case"br":{n+=r.br(l);break}case"del":{n+=r.del(l);break}case"text":{n+=r.text(l);break}default:{let u='Token with "'+l.type+'" type was not found.';if(this.options.silent)return console.error(u),"";throw new Error(u)}}}return n}},Ef,Eh=(Ef=class{constructor(e){J(this,"options");J(this,"block");this.options=e||ql}preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?Ti.lex:Ti.lexInline}provideParser(e=this.block){return e?Yi.parse:Yi.parseInline}},J(Ef,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens","emStrongMask"])),J(Ef,"passThroughHooksRespectAsync",new Set(["preprocess","postprocess","processAllTokens"])),Ef),z1e=class{constructor(...t){J(this,"defaults",w6());J(this,"options",this.setOptions);J(this,"parse",this.parseMarkdown(!0));J(this,"parseInline",this.parseMarkdown(!1));J(this,"Parser",Yi);J(this,"Renderer",Op);J(this,"TextRenderer",L6);J(this,"Lexer",Ti);J(this,"Tokenizer",Dp);J(this,"Hooks",Eh);this.use(...t)}walkTokens(t,r){var i,s;let n=[];for(let a of t)switch(n=n.concat(r.call(this,a)),a.type){case"table":{let o=a;for(let l of o.header)n=n.concat(this.walkTokens(l.tokens,r));for(let l of o.rows)for(let u of l)n=n.concat(this.walkTokens(u.tokens,r));break}case"list":{let o=a;n=n.concat(this.walkTokens(o.items,r));break}default:{let o=a;(s=(i=this.defaults.extensions)==null?void 0:i.childTokens)!=null&&s[o.type]?this.defaults.extensions.childTokens[o.type].forEach(l=>{let u=o[l].flat(1/0);n=n.concat(this.walkTokens(u,r))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,r)))}}return n}use(...t){let r=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let i={...n};if(i.async=this.defaults.async||i.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){let a=r.renderers[s.name];a?r.renderers[s.name]=function(...o){let l=s.renderer.apply(this,o);return l===!1&&(l=a.apply(this,o)),l}:r.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let a=r[s.level];a?a.unshift(s.tokenizer):r[s.level]=[s.tokenizer],s.start&&(s.level==="block"?r.startBlock?r.startBlock.push(s.start):r.startBlock=[s.start]:s.level==="inline"&&(r.startInline?r.startInline.push(s.start):r.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(r.childTokens[s.name]=s.childTokens)}),i.extensions=r),n.renderer){let s=this.defaults.renderer||new Op(this.defaults);for(let a in n.renderer){if(!(a in s))throw new Error(`renderer '${a}' does not exist`);if(["options","parser"].includes(a))continue;let o=a,l=n.renderer[o],u=s[o];s[o]=(...c)=>{let d=l.apply(s,c);return d===!1&&(d=u.apply(s,c)),d||""}}i.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new Dp(this.defaults);for(let a in n.tokenizer){if(!(a in s))throw new Error(`tokenizer '${a}' does not exist`);if(["options","rules","lexer"].includes(a))continue;let o=a,l=n.tokenizer[o],u=s[o];s[o]=(...c)=>{let d=l.apply(s,c);return d===!1&&(d=u.apply(s,c)),d}}i.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new Eh;for(let a in n.hooks){if(!(a in s))throw new Error(`hook '${a}' does not exist`);if(["options","block"].includes(a))continue;let o=a,l=n.hooks[o],u=s[o];Eh.passThroughHooks.has(a)?s[o]=c=>{if(this.defaults.async&&Eh.passThroughHooksRespectAsync.has(a))return(async()=>{let m=await l.call(s,c);return u.call(s,m)})();let d=l.call(s,c);return u.call(s,d)}:s[o]=(...c)=>{if(this.defaults.async)return(async()=>{let m=await l.apply(s,c);return m===!1&&(m=await u.apply(s,c)),m})();let d=l.apply(s,c);return d===!1&&(d=u.apply(s,c)),d}}i.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,a=n.walkTokens;i.walkTokens=function(o){let l=[];return l.push(a.call(this,o)),s&&(l=l.concat(s.call(this,o))),l}}this.defaults={...this.defaults,...i}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,r){return Ti.lex(t,r??this.defaults)}parser(t,r){return Yi.parse(t,r??this.defaults)}parseMarkdown(t){return(r,n)=>{let i={...n},s={...this.defaults,...i},a=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&i.async===!1)return a(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 r>"u"||r===null)return a(new Error("marked(): input parameter is undefined or null"));if(typeof r!="string")return a(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(r)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=t),s.async)return(async()=>{let o=s.hooks?await s.hooks.preprocess(r):r,l=await(s.hooks?await s.hooks.provideLexer(t):t?Ti.lex:Ti.lexInline)(o,s),u=s.hooks?await s.hooks.processAllTokens(l):l;s.walkTokens&&await Promise.all(this.walkTokens(u,s.walkTokens));let c=await(s.hooks?await s.hooks.provideParser(t):t?Yi.parse:Yi.parseInline)(u,s);return s.hooks?await s.hooks.postprocess(c):c})().catch(a);try{s.hooks&&(r=s.hooks.preprocess(r));let o=(s.hooks?s.hooks.provideLexer(t):t?Ti.lex:Ti.lexInline)(r,s);s.hooks&&(o=s.hooks.processAllTokens(o)),s.walkTokens&&this.walkTokens(o,s.walkTokens);let l=(s.hooks?s.hooks.provideParser(t):t?Yi.parse:Yi.parseInline)(o,s);return s.hooks&&(l=s.hooks.postprocess(l)),l}catch(o){return a(o)}}}onError(t,r){return n=>{if(n.message+=`
654
654
  Please report this to https://github.com/markedjs/marked.`,t){let i="<p>An error occurred:</p><pre>"+cs(n.message+"",!0)+"</pre>";return r?Promise.resolve(i):i}if(r)return Promise.reject(n);throw n}}},Rl=new z1e;function Dt(e,t){return Rl.parse(e,t)}Dt.options=Dt.setOptions=function(e){return Rl.setOptions(e),Dt.defaults=Rl.defaults,nM(Dt.defaults),Dt};Dt.getDefaults=w6;Dt.defaults=ql;Dt.use=function(...e){return Rl.use(...e),Dt.defaults=Rl.defaults,nM(Dt.defaults),Dt};Dt.walkTokens=function(e,t){return Rl.walkTokens(e,t)};Dt.parseInline=Rl.parseInline;Dt.Parser=Yi;Dt.parser=Yi.parse;Dt.Renderer=Op;Dt.TextRenderer=L6;Dt.Lexer=Ti;Dt.lexer=Ti.lex;Dt.Tokenizer=Dp;Dt.Hooks=Eh;Dt.parse=Dt;Dt.options;Dt.setOptions;Dt.use;Dt.walkTokens;Dt.parseInline;Yi.parse;Ti.lex;var $1e=300,H1e="300px",F1e=500;function U1e(e={}){let{immediate:t=!1,debounceDelay:r=$1e,rootMargin:n=H1e,idleTimeout:i=F1e}=e,[s,a]=w.useState(!1),o=w.useRef(null),l=w.useRef(null),u=w.useRef(null),c=w.useMemo(()=>f=>{let p=Date.now();return window.setTimeout(()=>{f({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-p))})},1)},[]),d=w.useMemo(()=>typeof window<"u"&&window.requestIdleCallback?(f,p)=>window.requestIdleCallback(f,p):c,[c]),m=w.useMemo(()=>typeof window<"u"&&window.cancelIdleCallback?f=>window.cancelIdleCallback(f):f=>{clearTimeout(f)},[]);return w.useEffect(()=>{if(t){a(!0);return}let f=o.current;if(!f)return;l.current&&(clearTimeout(l.current),l.current=null),u.current&&(m(u.current),u.current=null);let p=()=>{l.current&&(clearTimeout(l.current),l.current=null),u.current&&(m(u.current),u.current=null)},g=x=>{u.current=d(E=>{E.timeRemaining()>0||E.didTimeout?(a(!0),x.disconnect()):u.current=d(()=>{a(!0),x.disconnect()},{timeout:i/2})},{timeout:i})},y=x=>{p(),l.current=window.setTimeout(()=>{var E,T;let C=x.takeRecords();(C.length===0||(T=(E=C.at(-1))==null?void 0:E.isIntersecting)!=null&&T)&&g(x)},r)},b=(x,E)=>{x.isIntersecting?y(E):p()},v=new IntersectionObserver(x=>{for(let E of x)b(E,v)},{rootMargin:n,threshold:0});return v.observe(f),()=>{l.current&&clearTimeout(l.current),u.current&&m(u.current),v.disconnect()}},[t,r,n,i,m,d]),{shouldRender:s,containerRef:o}}var V1e=320,q1e=4,fM=()=>typeof performance>"u"?Date.now():performance.now();function $7(e){var t,r;let n=(t=e==null?void 0:e.now)!=null?t:fM,i=(r=e==null?void 0:e.maxBacklogMs)!=null?r:V1e,s=0,a=0;return{now:n,beginPass(o){a=Math.min(Math.max(s,o),o+i)},mark(){return a},rewind(o){a=o},take(o,l,u){if(o<=0)return{baseDelay:0,step:Math.max(0,l)};let c=Math.max(0,l),d=c===0?0:Math.min(c,q1e),m=Math.max(a,u),f=u+i,p=m+Math.max(0,o-1)*c,g=c;if(p>f&&o>1)if(m<f){let b=f-m;g=Math.max(d,b/(o-1))}else g=d;let y=Math.max(0,Math.round(m-u));return a=m+o*g,{baseDelay:y,step:g}},commitPass(){s=a}}}var mM=/\s/,I6=/^\s+$/,G1e=new Set(["pre","svg","math","annotation"]),W1e=new Set(["img","hr"]),S0=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",D6=e=>e.some(t=>S0(t)&&G1e.has(t.tagName)),Y1e=e=>{for(let t=e.length-1;t>=0;t--){let r=e[t];if(S0(r)&&r.tagName==="li")return r}},K1e=(e,t,r,n)=>{e.properties!=null||(e.properties={}),e.properties["data-sd-animate-marker"]=!0;let i=typeof e.properties.style=="string"?`${e.properties.style};`:"";e.properties.style=`${i}--sd-marker-duration:${t}ms;--sd-marker-delay:${Math.round(r)}ms;--sd-marker-easing:${n}`},X1e=new Set(["ul","ol","li"]),pM=e=>{for(let t of e.children)if(S0(t)){if(t.tagName==="input")return t;if(X1e.has(t.tagName))continue;let r=pM(t);if(r)return r}},gM=(e,t,r,n)=>{e.properties!=null||(e.properties={}),e.properties["data-sd-animate"]=!0;let i=typeof e.properties.style=="string"?`${e.properties.style};`:"";e.properties.style=`${i}--sd-animation:sd-${t.animation};--sd-duration:${r}ms;--sd-easing:${t.easing};--sd-delay:${Math.round(n)}ms`},Q1e=(e,t,r,n)=>{let i=pM(e);i&&gM(i,t,r,n)},Z1e=(e,t,r,n,i,s)=>{if(D6(t))return;let a=n.prevContentLength,o=i.count;i.count+=1;let l=a>0&&o<a,u=l?0:s.baseDelay+i.newIndex++*s.step;gM(e,r,l?0:r.duration,u)},J1e=e=>{var t;for(let r=e.length-1;r>=0;r-=1){let n=e[r];if(S0(n)){if((t=n.properties)!=null&&t["data-sd-animated"])break;n.properties={...n.properties,"data-sd-animated":!0}}}},bM=e=>{let t=[],r="",n=!1;for(let i of e){let s=mM.test(i);if(s!==n&&r){if(s){r+=i,n=!0;continue}t.push(r),r=""}r+=i,n=s}return r&&t.push(r),t},_M=e=>{let t=[],r="";for(let n of e)mM.test(n)?t.length>0&&!I6.test(t.at(-1))?t[t.length-1]+=n:r+=n:(r&&(t.push(r),r=""),t.push(n));return r&&(t.length>0?t[t.length-1]+=r:t.push(r)),t},ege=(e,t,r,n,i,s)=>{let a=`--sd-animation:sd-${t};--sd-duration:${i?0:r}ms;--sd-easing:${n}`;return s&&(a+=`;--sd-delay:${Math.round(s)}ms`),{type:"element",tagName:"span",properties:{"data-sd-animate":!0,style:a},children:[{type:"text",value:e}]}},H7=(e,t)=>!(e>0&&t<e),dy=e=>S0(e)&&W1e.has(e.tagName),tge=(e,t,r)=>{let n=0,i=0;return u0(e,s=>s.type==="text"||dy(s),(s,a)=>{if(D6(a))return eo;if(dy(s)){H7(r,i)&&(n+=1),i+=1;return}let o=s.value;if(!o.trim()){i+=o.length;return}let l=t.sep==="char"?_M(o):bM(o);for(let u of l){let c=i;i+=u.length,!I6.test(u)&&H7(r,c)&&(n+=1)}}),n},rge=(e,t,r,n,i,s)=>{var a;let o=t.at(-1);if(!(o&&"children"in o))return;if(D6(t))return eo;let l=o,u=l.children.indexOf(e);if(u===-1)return;let c=e.value;if(!c.trim()){i.count+=c.length;return}let d=r.sep==="char"?_M(c):bM(c),m=n.prevContentLength,f=!1,p=Y1e(t),g=!!(p&&!((a=p.properties)!=null&&a["data-sd-animate-marker"])),y=!1,b=d.map(v=>{let x=i.count;if(i.count+=v.length,I6.test(v))return{type:"text",value:v};let E=m>0&&x<m,T=E?0:s.baseDelay+i.newIndex++*s.step;if(f=!0,p&&g&&!y){let C=E?0:r.duration;K1e(p,C,T,r.easing),Q1e(p,r,C,T),y=!0}return ege(v,r.animation,r.duration,r.easing,E,T)});return f&&J1e(t),l.children.splice(u,1,...b),u+b.length},nge=0;function vM(e){var t,r,n,i,s;let a={animation:(t=e==null?void 0:e.animation)!=null?t:"fadeIn",duration:(r=e==null?void 0:e.duration)!=null?r:150,easing:(n=e==null?void 0:e.easing)!=null?n:"ease",sep:(i=e==null?void 0:e.sep)!=null?i:"word",stagger:(s=e==null?void 0:e.stagger)!=null?s:40,timeline:e==null?void 0:e.timeline},o={committedCharCount:0,prevContentLength:0,lastRenderCharCount:0,pendingMark:null},l=nge++,u=()=>c=>{var d;let m={count:0,newIndex:0};o.prevContentLength=o.committedCharCount;let f=a.timeline,p=(d=f==null?void 0:f.now())!=null?d:fM();f&&(o.pendingMark===null?o.pendingMark=f.mark():f.rewind(o.pendingMark));let g=f?f.take(tge(c,a,o.prevContentLength),a.stagger,p):{baseDelay:0,step:a.stagger};u0(c,y=>y.type==="text"||dy(y),(y,b)=>{if(y.type==="text")return rge(y,b,a,o,m,g);Z1e(y,b,a,o,m,g)}),o.lastRenderCharCount=m.count,o.prevContentLength=0};return Object.defineProperty(u,"name",{value:`rehypeAnimate$${l}`}),{name:"animate",type:"animate",rehypePlugin:u,setPrevContentLength(c){o.committedCharCount=c,o.prevContentLength=c},getLastRenderCharCount(){return o.lastRenderCharCount},commit(){o.committedCharCount=o.lastRenderCharCount,o.pendingMark=null}}}vM();var yM=w.createContext(!1),ige=()=>w.useContext(yM),W1=(...e)=>qO(RO(e)),sge=(e,t)=>{if(!e||!t)return t;let r=`${e}:`;return t.split(/\s+/).filter(Boolean).map(n=>n.startsWith(r)?n:`${e}:${n}`).join(" ")},age=e=>e?(...t)=>sge(e,qO(RO(t))):W1,Hu=(e,t,r)=>{let n=typeof t=="string"&&r.startsWith("text/csv")?"\uFEFF":"",i=typeof t=="string"?new Blob([n+t],{type:r}):t,s=URL.createObjectURL(i),a=document.createElement("a");a.href=s,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s)},fy=w.createContext(W1),mt=()=>w.useContext(fy),oge=8,xM=e=>{if(!(e===void 0||e===0||e===Number.POSITIVE_INFINITY)){if(typeof e=="number")return Number.isFinite(e)&&e>0?`${e}px`:void 0;if(!(e==="0"||e==="none"||e==="Infinity"))return e}},SM=(e,t,r)=>{let n=w.useRef(null),i=w.useRef(!0),s=w.useRef(!1);return w.useEffect(()=>{let a=n.current;if(!(a&&t))return;let o=()=>{let l=a.scrollHeight-a.scrollTop-a.clientHeight<oge;i.current=l};return a.addEventListener("scroll",o,{passive:!0}),()=>a.removeEventListener("scroll",o)},[t]),w.useEffect(()=>{e&&!s.current&&(i.current=!0),e||(i.current=!0),s.current=e},[e]),w.useEffect(()=>{let a=n.current;a&&t&&e&&i.current&&a.scrollTo({top:a.scrollHeight,behavior:"instant"})},[e,t,r]),n},lge=W1("block"),uge=W1("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-6","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),cge=e=>{let t={};for(let r of e.split(";")){let n=r.indexOf(":");if(n>0){let i=r.slice(0,n).trim(),s=r.slice(n+1).trim();i&&s&&(t[i]=s)}}return t},hge=w.memo(({children:e,result:t,language:r,className:n,maxHeight:i,startLine:s,lineNumbers:a=!0,...o})=>{let l=mt(),{isAnimating:u}=w.useContext(un),c=xM(i),d=SM(u,!!c,t),m=w.useMemo(()=>l(uge),[l]),f=w.useMemo(()=>l(lge),[l]),p=w.useMemo(()=>{let g={};return t.bg&&(g["--sdm-bg"]=t.bg),t.fg&&(g["--sdm-fg"]=t.fg),t.rootStyle&&Object.assign(g,cge(t.rootStyle)),g},[t.bg,t.fg,t.rootStyle]);return h.jsx("div",{className:l(n,c?"overflow-y-auto":null,"overflow-x-auto rounded-md border border-border bg-background p-4 text-sm"),"data-language":r,"data-streamdown":"code-block-body",ref:d,style:c?{maxHeight:c}:void 0,...o,children:h.jsx("pre",{className:l(n,"bg-[var(--sdm-bg,inherit)]","dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))]"),style:p,children:h.jsx("code",{className:a?l("[counter-increment:line_0] [counter-reset:line]"):void 0,style:a&&s&&s>1?{counterReset:`line ${s-1}`}:void 0,children:t.tokens.map((g,y)=>h.jsx("span",{className:a?m:f,children:g.length===0||g.length===1&&g[0].content===""?`
655
655
  `:g.map((b,v)=>{let x={},E=!!b.bgColor;if(b.color&&(x["--sdm-c"]=b.color),b.bgColor&&(x["--sdm-tbg"]=b.bgColor),b.htmlStyle)for(let[T,C]of Object.entries(b.htmlStyle))T==="color"?x["--sdm-c"]=C:T==="background-color"?(x["--sdm-tbg"]=C,E=!0):x[T]=C;return h.jsx("span",{className:l("text-[var(--sdm-c,inherit)]","dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]",E&&"bg-[var(--sdm-tbg)]",E&&"dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),style:x,...b.htmlAttrs,children:b.content},v)})},y))})})})}),dge=({className:e,language:t,style:r,isIncomplete:n,...i})=>{let s=mt();return h.jsx("div",{className:s("my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",e),"data-incomplete":n||void 0,"data-language":t,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...r},...i})},wM=w.createContext({code:""}),EM=()=>w.useContext(wM),fge=({language:e})=>{let t=mt();return h.jsx("div",{className:t("flex h-8 items-center text-muted-foreground text-xs"),"data-language":e,"data-streamdown":"code-block-header",children:h.jsx("span",{className:t("ml-1 font-mono lowercase"),children:e})})},mge=e=>{let t=e.length;for(;t>0&&e[t-1]===`
656
- `;)t--;return e.slice(0,t)},pge=w.lazy(()=>O(()=>import("./highlighted-body-KPVGNVTW-D7b_g0Y9.js"),[]).then(e=>({default:e.HighlightedCodeBlockBody}))),gge=({code:e,language:t,className:r,children:n,isIncomplete:i=!1,startLine:s,lineNumbers:a,...o})=>{let l=mt(),{codeBlockMaxHeight:u}=w.useContext(un),c=w.useMemo(()=>mge(e),[e]),d=w.useMemo(()=>({bg:"transparent",fg:"inherit",tokens:c.split(`
657
- `).map(m=>[{content:m,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[c]);return h.jsx(wM.Provider,{value:{code:e},children:h.jsxs(dge,{dir:"ltr",isIncomplete:i,language:t,children:[h.jsx(fge,{language:t}),n?h.jsx("div",{className:l("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:h.jsx("div",{className:l("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"code-block-actions",children:n})}):null,h.jsx(w.Suspense,{fallback:h.jsx(hge,{className:r,language:t,lineNumbers:a,maxHeight:u,result:d,startLine:s,...o}),children:h.jsx(pge,{className:r,code:c,language:t,lineNumbers:a,maxHeight:u,raw:d,startLine:s,...o})})]})})},bge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})}),_ge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),vge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",fill:"currentColor",fillRule:"evenodd"})}),yge=e=>h.jsxs("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:[h.jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),xge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",fill:"currentColor",fillRule:"evenodd"})}),Sge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",fill:"currentColor",fillRule:"evenodd"})}),wge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",fill:"currentColor",fillRule:"evenodd"})}),Ege=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M13.5 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z",fill:"currentColor",fillRule:"evenodd"})}),kge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),Cge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),kh={CheckIcon:bge,CopyIcon:_ge,DownloadIcon:vge,ExternalLinkIcon:Ege,Loader2Icon:yge,Maximize2Icon:xge,RotateCcwIcon:Sge,XIcon:wge,ZoomInIcon:kge,ZoomOutIcon:Cge},kM=w.createContext(kh),Tge=(e,t)=>{if(e===t)return!0;if(!(e&&t))return e===t;let r=Object.keys(e),n=Object.keys(t);return r.length!==n.length?!1:r.every(i=>e[i]===t[i])},F7=({icons:e,children:t})=>{let r=w.useRef(e),n=w.useRef(e?{...kh,...e}:kh);Tge(r.current,e)||(r.current=e,n.current=e?{...kh,...e}:kh);let i=n.current;return h.jsx(kM.Provider,{value:i,children:t})},ts=()=>w.useContext(kM),CM={copyCode:"Copy Code",downloadFile:"Download file",downloadDiagram:"Download diagram",downloadDiagramAsSvg:"Download diagram as SVG",downloadDiagramAsPng:"Download diagram as PNG",downloadDiagramAsMmd:"Download diagram as MMD",viewFullscreen:"View fullscreen",exitFullscreen:"Exit fullscreen",mermaidFormatSvg:"SVG",mermaidFormatPng:"PNG",mermaidFormatMmd:"MMD",zoomIn:"Zoom in",zoomOut:"Zoom out",resetView:"Reset zoom and pan",copyTable:"Copy table",copyTableAsMarkdown:"Copy table as Markdown",copyTableAsCsv:"Copy table as CSV",copyTableAsTsv:"Copy table as TSV",downloadTable:"Download table",downloadTableAsCsv:"Download table as CSV",downloadTableAsMarkdown:"Download table as Markdown",tableFormatMarkdown:"Markdown",tableFormatCsv:"CSV",tableFormatTsv:"TSV",imageNotAvailable:"Image not available",downloadImage:"Download image",openExternalLink:"Open external link?",externalLinkWarning:"You're about to visit an external website.",close:"Close",copyLink:"Copy link",copied:"Copied",openLink:"Open link"},my=w.createContext(CM),js=()=>w.useContext(my),py=({onCopy:e,onError:t,timeout:r=2e3,children:n,className:i,code:s,...a})=>{let o=mt(),[l,u]=w.useState(!1),c=w.useRef(0),{code:d}=EM(),{isAnimating:m}=w.useContext(un),f=js(),p=s??d,g=async()=>{var v;if(typeof window>"u"||!((v=navigator==null?void 0:navigator.clipboard)!=null&&v.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{l||(await navigator.clipboard.writeText(p),u(!0),e==null||e(),c.current=window.setTimeout(()=>u(!1),r))}catch(x){t==null||t(x)}};w.useEffect(()=>()=>{window.clearTimeout(c.current)},[]);let y=ts(),b=l?y.CheckIcon:y.CopyIcon;return h.jsxs(h.Fragment,{children:[h.jsx("button",{"aria-label":f.copyCode,className:o("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",i),"data-streamdown":"code-block-copy-button",disabled:m,onClick:g,title:f.copyCode,type:"button",...a,children:n??h.jsx(b,{"aria-hidden":"true",size:14})}),l&&h.jsx("output",{"aria-live":"polite",className:"sr-only",children:f.copied})]})},O6=(e,t,r)=>{if(typeof e=="boolean")return r;let n=e[t];if(typeof n!="object")return r;let i=n.download;return typeof i!="object"?r:i.filename||r},U7={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",文言:"wy"},Age=({onDownload:e,onError:t,language:r,children:n,className:i,code:s,...a})=>{let o=mt(),{code:l}=EM(),{isAnimating:u,controls:c}=w.useContext(un),d=js(),m=ts(),f=s??l,p=r&&r in U7?U7[r]:"txt",g=`${O6(c,"code","file")}.${p}`,y="text/plain",b=()=>{try{Hu(g,f,y),e==null||e()}catch(v){t==null||t(v)}};return h.jsx("button",{"aria-label":d.downloadFile,className:o("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",i),"data-streamdown":"code-block-download-button",disabled:u,onClick:b,title:d.downloadFile,type:"button",...a,children:n??h.jsx(m.DownloadIcon,{size:14})})},V7=()=>{let{Loader2Icon:e}=ts(),t=mt();return h.jsxs("div",{className:t("w-full divide-y divide-border overflow-hidden rounded-xl border border-border"),children:[h.jsx("div",{className:t("h-[46px] w-full bg-muted/80")}),h.jsx("div",{className:t("flex w-full items-center justify-center p-4"),children:h.jsx(e,{className:t("size-4 animate-spin")})})]})},Nge=/\.[^/.]+$/,Rge=({node:e,className:t,src:r,alt:n,onLoad:i,onError:s,showControls:a=!0,showDownloadControl:o=!0,...l})=>{let{DownloadIcon:u}=ts(),c=mt(),d=w.useRef(null),[m,f]=w.useState(!1),[p,g]=w.useState(!1),y=js(),b=l.width!=null||l.height!=null,v=(m||b)&&!p&&a&&o,x=p&&!b;w.useEffect(()=>{let L=d.current;if(L!=null&&L.complete){let A=L.naturalWidth>0;f(A),g(!A)}},[]);let E=w.useCallback(L=>{f(!0),g(!1),i==null||i(L)},[i]),T=w.useCallback(L=>{f(!1),g(!0),s==null||s(L)},[s]),C=async()=>{if(r)try{let L=await(await fetch(r)).blob(),A=new URL(r,window.location.origin).pathname.split("/").pop()||"",z=A.split(".").pop(),I=A.includes(".")&&z!==void 0&&z.length<=4,B="";if(I)B=A;else{let j=L.type,G="png";j.includes("jpeg")||j.includes("jpg")?G="jpg":j.includes("png")?G="png":j.includes("svg")?G="svg":j.includes("gif")?G="gif":j.includes("webp")&&(G="webp"),B=`${(n||A||"image").replace(Nge,"")}.${G}`}Hu(B,L,L.type)}catch{window.open(r,"_blank")}};return r?h.jsxs("div",{className:c("group relative my-4 inline-block"),"data-streamdown":"image-wrapper",children:[h.jsx("img",{alt:n,className:c("max-w-full rounded-lg",x&&"hidden",t),"data-streamdown":"image",onError:T,onLoad:E,ref:d,src:r,...l}),x&&h.jsx("span",{className:c("text-muted-foreground text-xs italic"),"data-streamdown":"image-fallback",children:y.imageNotAvailable}),a&&h.jsx("div",{className:c("pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"),"data-streamdown":"image-overlay"}),v&&h.jsx("button",{className:c("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:C,title:y.downloadImage,type:"button",children:h.jsx(u,{size:14})})]}):null},td=0,M6=()=>{td+=1,td===1&&(document.body.style.overflow="hidden")},j6=()=>{td=Math.max(0,td-1),td===0&&(document.body.style.overflow="")},Lge=({url:e,isOpen:t,onClose:r,onConfirm:n})=>{let{CheckIcon:i,CopyIcon:s,ExternalLinkIcon:a,XIcon:o}=ts(),l=mt(),[u,c]=w.useState(!1),d=js(),m=w.useCallback(async()=>{try{await navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),2e3)}catch{}},[e]),f=w.useCallback(()=>{n(),r()},[n,r]);if(w.useEffect(()=>{if(t){M6();let g=y=>{y.key==="Escape"&&r()};return document.addEventListener("keydown",g),()=>{document.removeEventListener("keydown",g),j6()}}},[t,r]),!t||typeof document>"u")return null;let p=h.jsx("div",{className:l("fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm"),"data-streamdown":"link-safety-modal",onClick:r,onKeyDown:g=>{g.key==="Escape"&&r()},role:"button",tabIndex:0,children:h.jsxs("div",{className:l("relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg"),onClick:g=>g.stopPropagation(),onKeyDown:g=>g.stopPropagation(),role:"presentation",children:[h.jsx("button",{className:l("absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:r,title:d.close,type:"button",children:h.jsx(o,{size:16})}),h.jsxs("div",{className:l("flex flex-col gap-2"),children:[h.jsxs("div",{className:l("flex items-center gap-2 font-semibold text-lg"),children:[h.jsx(a,{size:20}),h.jsx("span",{children:d.openExternalLink})]}),h.jsx("p",{className:l("text-muted-foreground text-sm"),children:d.externalLinkWarning})]}),h.jsx("div",{className:l("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),h.jsxs("div",{className:l("flex gap-2"),children:[h.jsx("button",{className:l("flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted"),onClick:m,type:"button",children:u?h.jsxs(h.Fragment,{children:[h.jsx(i,{size:14}),h.jsx("span",{children:d.copied})]}):h.jsxs(h.Fragment,{children:[h.jsx(s,{size:14}),h.jsx("span",{children:d.copyLink})]})}),h.jsxs("button",{className:l("flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90"),onClick:f,type:"button",children:[h.jsx(a,{size:14}),h.jsx("span",{children:d.openLink})]})]})]})});return cn.createPortal(p,document.body)},gy=w.createContext(null),B6=()=>w.useContext(gy),Rye=()=>{var e;let t=B6();return(e=t==null?void 0:t.code)!=null?e:null},P6=()=>{var e;let t=B6();return(e=t==null?void 0:t.mermaid)!=null?e:null},Ige=e=>{var t;let r=B6();return r!=null&&r.renderers&&e&&(t=r.renderers.find(n=>Array.isArray(n.language)?n.language.includes(e):n.language===e))!=null?t:null},Dge=e=>{if(typeof DOMParser>"u"||typeof XMLSerializer>"u")return e;let t=new DOMParser().parseFromString(e,"text/html").querySelector("svg");return t?new XMLSerializer().serializeToString(t):e},Oge=(e,t)=>{var r;let n=(r=void 0)!=null?r:5;return new Promise((i,s)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),o=new Image;o.crossOrigin="anonymous",o.onload=()=>{let l=document.createElement("canvas"),u=o.width*n,c=o.height*n;l.width=u,l.height=c;let d=l.getContext("2d");if(!d){s(new Error("Failed to create 2D canvas context for PNG export"));return}d.drawImage(o,0,0,u,c),l.toBlob(m=>{if(!m){s(new Error("Failed to create PNG blob"));return}i(m)},"image/png")},o.onerror=()=>s(new Error("Failed to load SVG image")),o.src=a})},TM=({chart:e,children:t,className:r,onDownload:n,config:i,onError:s})=>{let a=mt(),[o,l]=w.useState(!1),u=w.useRef(null),{isAnimating:c,controls:d}=w.useContext(un),m=ts(),f=P6(),p=js(),g=O6(d,"mermaid","diagram"),y=async b=>{try{if(b==="mmd"){let L=`${g}.mmd`;Hu(L,e,"text/plain"),l(!1),n==null||n(b);return}if(!f){s==null||s(new Error("Mermaid plugin not available"));return}let v=f.getMermaid(i),x=e.split("").reduce((L,A)=>(L<<5)-L+A.charCodeAt(0)|0,0),E=`mermaid-${Math.abs(x)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:T}=await v.render(E,e);if(!T){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}let C=Dge(T);if(b==="svg"){let L=`${g}.svg`;Hu(L,C,"image/svg+xml"),l(!1),n==null||n(b);return}if(b==="png"){let L=await Oge(C);Hu(`${g}.png`,L,"image/png"),n==null||n(b),l(!1);return}}catch(v){s==null||s(v)}};return w.useEffect(()=>{let b=v=>{let x=v.composedPath();u.current&&!x.includes(u.current)&&l(!1)};return document.addEventListener("mousedown",b),()=>{document.removeEventListener("mousedown",b)}},[]),h.jsxs("div",{className:a("relative"),ref:u,children:[h.jsx("button",{"aria-label":p.downloadDiagram,className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:c,onClick:()=>l(!o),title:p.downloadDiagram,type:"button",children:t??h.jsx(m.DownloadIcon,{"aria-hidden":"true",size:14})}),o?h.jsxs("div",{className:a("absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[h.jsx("button",{"aria-label":p.downloadDiagramAsSvg,className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("svg"),title:p.downloadDiagramAsSvg,type:"button",children:p.mermaidFormatSvg}),h.jsx("button",{"aria-label":p.downloadDiagramAsPng,className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("png"),title:p.downloadDiagramAsPng,type:"button",children:p.mermaidFormatPng}),h.jsx("button",{"aria-label":p.downloadDiagramAsMmd,className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("mmd"),title:p.downloadDiagramAsMmd,type:"button",children:p.mermaidFormatMmd})]}):null]})},Mge=({chart:e,config:t,onFullscreen:r,onExit:n,className:i,...s})=>{let{Maximize2Icon:a,XIcon:o}=ts(),l=mt(),[u,c]=w.useState(!1),{isAnimating:d,controls:m}=w.useContext(un),f=js(),p=(()=>{if(typeof m=="boolean")return m;let v=m.mermaid;return v===!1?!1:v===!0||v===void 0?!0:v.panZoom!==!1})(),g=(()=>{if(typeof m=="boolean")return m;let v=m.mermaid;return v===!1?!1:v===!0||v===void 0?!0:v.download!==!1})(),y=(()=>{if(typeof m=="boolean")return m;let v=m.mermaid;return v===!1?!1:v===!0||v===void 0?!0:v.copy!==!1})(),b=()=>{c(!u)};return w.useEffect(()=>{if(u){M6();let v=x=>{x.key==="Escape"&&c(!1)};return document.addEventListener("keydown",v),()=>{document.removeEventListener("keydown",v),j6()}}},[u]),w.useEffect(()=>{u?r==null||r():n&&n()},[u,r,n]),h.jsxs(h.Fragment,{children:[h.jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",i),disabled:d,onClick:b,title:f.viewFullscreen,type:"button",...s,"aria-label":f.viewFullscreen,children:h.jsx(a,{"aria-hidden":"true",size:14})}),u?cn.createPortal(h.jsxs("div",{"aria-label":f.viewFullscreen,"aria-modal":"true",className:l("fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm"),"data-streamdown":"mermaid-fullscreen",onClick:b,onKeyDown:v=>{v.key==="Escape"&&b()},role:"dialog",children:[h.jsxs("div",{className:l("absolute top-4 right-4 z-10 flex items-center gap-1"),onClick:v=>v.stopPropagation(),onKeyDown:v=>v.stopPropagation(),role:"presentation",children:[g?h.jsx(TM,{chart:e,config:t}):null,y?h.jsx(py,{code:e}):null,h.jsx("button",{"aria-label":f.exitFullscreen,className:l("rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:b,title:f.exitFullscreen,type:"button",children:h.jsx(o,{"aria-hidden":"true",size:20})})]}),h.jsx("div",{className:l("flex size-full items-center justify-center p-4"),onClick:v=>v.stopPropagation(),onKeyDown:v=>v.stopPropagation(),role:"presentation",children:h.jsx(mj,{chart:e,className:l("size-full [&_svg]:h-auto [&_svg]:w-auto"),config:t,fullscreen:!0,showControls:p})})]}),document.body):null]})};function by(e){var t;if(e.nodeType===Node.TEXT_NODE)return(t=e.textContent)!=null?t:"";if(e.nodeType!==Node.ELEMENT_NODE)return"";let r=e;return r.tagName==="BR"?`
656
+ `;)t--;return e.slice(0,t)},pge=w.lazy(()=>O(()=>import("./highlighted-body-KPVGNVTW-B5z7-guY.js"),[]).then(e=>({default:e.HighlightedCodeBlockBody}))),gge=({code:e,language:t,className:r,children:n,isIncomplete:i=!1,startLine:s,lineNumbers:a,...o})=>{let l=mt(),{codeBlockMaxHeight:u}=w.useContext(un),c=w.useMemo(()=>mge(e),[e]),d=w.useMemo(()=>({bg:"transparent",fg:"inherit",tokens:c.split(`
657
+ `).map(m=>[{content:m,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[c]);return h.jsx(wM.Provider,{value:{code:e},children:h.jsxs(dge,{dir:"ltr",isIncomplete:i,language:t,children:[h.jsx(fge,{language:t}),n?h.jsx("div",{className:l("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:h.jsx("div",{className:l("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"code-block-actions",children:n})}):null,h.jsx(w.Suspense,{fallback:h.jsx(hge,{className:r,language:t,lineNumbers:a,maxHeight:u,result:d,startLine:s,...o}),children:h.jsx(pge,{className:r,code:c,language:t,lineNumbers:a,maxHeight:u,raw:d,startLine:s,...o})})]})})},bge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})}),_ge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),vge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",fill:"currentColor",fillRule:"evenodd"})}),yge=e=>h.jsxs("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:[h.jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),h.jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),xge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",fill:"currentColor",fillRule:"evenodd"})}),Sge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",fill:"currentColor",fillRule:"evenodd"})}),wge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",fill:"currentColor",fillRule:"evenodd"})}),Ege=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M13.5 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z",fill:"currentColor",fillRule:"evenodd"})}),kge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),Cge=e=>h.jsx("svg",{"aria-hidden":"true",color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:h.jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),kh={CheckIcon:bge,CopyIcon:_ge,DownloadIcon:vge,ExternalLinkIcon:Ege,Loader2Icon:yge,Maximize2Icon:xge,RotateCcwIcon:Sge,XIcon:wge,ZoomInIcon:kge,ZoomOutIcon:Cge},kM=w.createContext(kh),Tge=(e,t)=>{if(e===t)return!0;if(!(e&&t))return e===t;let r=Object.keys(e),n=Object.keys(t);return r.length!==n.length?!1:r.every(i=>e[i]===t[i])},F7=({icons:e,children:t})=>{let r=w.useRef(e),n=w.useRef(e?{...kh,...e}:kh);Tge(r.current,e)||(r.current=e,n.current=e?{...kh,...e}:kh);let i=n.current;return h.jsx(kM.Provider,{value:i,children:t})},ts=()=>w.useContext(kM),CM={copyCode:"Copy Code",downloadFile:"Download file",downloadDiagram:"Download diagram",downloadDiagramAsSvg:"Download diagram as SVG",downloadDiagramAsPng:"Download diagram as PNG",downloadDiagramAsMmd:"Download diagram as MMD",viewFullscreen:"View fullscreen",exitFullscreen:"Exit fullscreen",mermaidFormatSvg:"SVG",mermaidFormatPng:"PNG",mermaidFormatMmd:"MMD",zoomIn:"Zoom in",zoomOut:"Zoom out",resetView:"Reset zoom and pan",copyTable:"Copy table",copyTableAsMarkdown:"Copy table as Markdown",copyTableAsCsv:"Copy table as CSV",copyTableAsTsv:"Copy table as TSV",downloadTable:"Download table",downloadTableAsCsv:"Download table as CSV",downloadTableAsMarkdown:"Download table as Markdown",tableFormatMarkdown:"Markdown",tableFormatCsv:"CSV",tableFormatTsv:"TSV",imageNotAvailable:"Image not available",downloadImage:"Download image",openExternalLink:"Open external link?",externalLinkWarning:"You're about to visit an external website.",close:"Close",copyLink:"Copy link",copied:"Copied",openLink:"Open link"},my=w.createContext(CM),js=()=>w.useContext(my),py=({onCopy:e,onError:t,timeout:r=2e3,children:n,className:i,code:s,...a})=>{let o=mt(),[l,u]=w.useState(!1),c=w.useRef(0),{code:d}=EM(),{isAnimating:m}=w.useContext(un),f=js(),p=s??d,g=async()=>{var v;if(typeof window>"u"||!((v=navigator==null?void 0:navigator.clipboard)!=null&&v.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{l||(await navigator.clipboard.writeText(p),u(!0),e==null||e(),c.current=window.setTimeout(()=>u(!1),r))}catch(x){t==null||t(x)}};w.useEffect(()=>()=>{window.clearTimeout(c.current)},[]);let y=ts(),b=l?y.CheckIcon:y.CopyIcon;return h.jsxs(h.Fragment,{children:[h.jsx("button",{"aria-label":f.copyCode,className:o("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",i),"data-streamdown":"code-block-copy-button",disabled:m,onClick:g,title:f.copyCode,type:"button",...a,children:n??h.jsx(b,{"aria-hidden":"true",size:14})}),l&&h.jsx("output",{"aria-live":"polite",className:"sr-only",children:f.copied})]})},O6=(e,t,r)=>{if(typeof e=="boolean")return r;let n=e[t];if(typeof n!="object")return r;let i=n.download;return typeof i!="object"?r:i.filename||r},U7={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",文言:"wy"},Age=({onDownload:e,onError:t,language:r,children:n,className:i,code:s,...a})=>{let o=mt(),{code:l}=EM(),{isAnimating:u,controls:c}=w.useContext(un),d=js(),m=ts(),f=s??l,p=r&&r in U7?U7[r]:"txt",g=`${O6(c,"code","file")}.${p}`,y="text/plain",b=()=>{try{Hu(g,f,y),e==null||e()}catch(v){t==null||t(v)}};return h.jsx("button",{"aria-label":d.downloadFile,className:o("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",i),"data-streamdown":"code-block-download-button",disabled:u,onClick:b,title:d.downloadFile,type:"button",...a,children:n??h.jsx(m.DownloadIcon,{size:14})})},V7=()=>{let{Loader2Icon:e}=ts(),t=mt();return h.jsxs("div",{className:t("w-full divide-y divide-border overflow-hidden rounded-xl border border-border"),children:[h.jsx("div",{className:t("h-[46px] w-full bg-muted/80")}),h.jsx("div",{className:t("flex w-full items-center justify-center p-4"),children:h.jsx(e,{className:t("size-4 animate-spin")})})]})},Nge=/\.[^/.]+$/,Rge=({node:e,className:t,src:r,alt:n,onLoad:i,onError:s,showControls:a=!0,showDownloadControl:o=!0,...l})=>{let{DownloadIcon:u}=ts(),c=mt(),d=w.useRef(null),[m,f]=w.useState(!1),[p,g]=w.useState(!1),y=js(),b=l.width!=null||l.height!=null,v=(m||b)&&!p&&a&&o,x=p&&!b;w.useEffect(()=>{let L=d.current;if(L!=null&&L.complete){let A=L.naturalWidth>0;f(A),g(!A)}},[]);let E=w.useCallback(L=>{f(!0),g(!1),i==null||i(L)},[i]),T=w.useCallback(L=>{f(!1),g(!0),s==null||s(L)},[s]),C=async()=>{if(r)try{let L=await(await fetch(r)).blob(),A=new URL(r,window.location.origin).pathname.split("/").pop()||"",z=A.split(".").pop(),I=A.includes(".")&&z!==void 0&&z.length<=4,B="";if(I)B=A;else{let j=L.type,G="png";j.includes("jpeg")||j.includes("jpg")?G="jpg":j.includes("png")?G="png":j.includes("svg")?G="svg":j.includes("gif")?G="gif":j.includes("webp")&&(G="webp"),B=`${(n||A||"image").replace(Nge,"")}.${G}`}Hu(B,L,L.type)}catch{window.open(r,"_blank")}};return r?h.jsxs("div",{className:c("group relative my-4 inline-block"),"data-streamdown":"image-wrapper",children:[h.jsx("img",{alt:n,className:c("max-w-full rounded-lg",x&&"hidden",t),"data-streamdown":"image",onError:T,onLoad:E,ref:d,src:r,...l}),x&&h.jsx("span",{className:c("text-muted-foreground text-xs italic"),"data-streamdown":"image-fallback",children:y.imageNotAvailable}),a&&h.jsx("div",{className:c("pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"),"data-streamdown":"image-overlay"}),v&&h.jsx("button",{className:c("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:C,title:y.downloadImage,type:"button",children:h.jsx(u,{size:14})})]}):null},td=0,M6=()=>{td+=1,td===1&&(document.body.style.overflow="hidden")},j6=()=>{td=Math.max(0,td-1),td===0&&(document.body.style.overflow="")},Lge=({url:e,isOpen:t,onClose:r,onConfirm:n})=>{let{CheckIcon:i,CopyIcon:s,ExternalLinkIcon:a,XIcon:o}=ts(),l=mt(),[u,c]=w.useState(!1),d=js(),m=w.useCallback(async()=>{try{await navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),2e3)}catch{}},[e]),f=w.useCallback(()=>{n(),r()},[n,r]);if(w.useEffect(()=>{if(t){M6();let g=y=>{y.key==="Escape"&&r()};return document.addEventListener("keydown",g),()=>{document.removeEventListener("keydown",g),j6()}}},[t,r]),!t||typeof document>"u")return null;let p=h.jsx("div",{className:l("fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm"),"data-streamdown":"link-safety-modal",onClick:r,onKeyDown:g=>{g.key==="Escape"&&r()},role:"button",tabIndex:0,children:h.jsxs("div",{className:l("relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg"),onClick:g=>g.stopPropagation(),onKeyDown:g=>g.stopPropagation(),role:"presentation",children:[h.jsx("button",{className:l("absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:r,title:d.close,type:"button",children:h.jsx(o,{size:16})}),h.jsxs("div",{className:l("flex flex-col gap-2"),children:[h.jsxs("div",{className:l("flex items-center gap-2 font-semibold text-lg"),children:[h.jsx(a,{size:20}),h.jsx("span",{children:d.openExternalLink})]}),h.jsx("p",{className:l("text-muted-foreground text-sm"),children:d.externalLinkWarning})]}),h.jsx("div",{className:l("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),h.jsxs("div",{className:l("flex gap-2"),children:[h.jsx("button",{className:l("flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted"),onClick:m,type:"button",children:u?h.jsxs(h.Fragment,{children:[h.jsx(i,{size:14}),h.jsx("span",{children:d.copied})]}):h.jsxs(h.Fragment,{children:[h.jsx(s,{size:14}),h.jsx("span",{children:d.copyLink})]})}),h.jsxs("button",{className:l("flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90"),onClick:f,type:"button",children:[h.jsx(a,{size:14}),h.jsx("span",{children:d.openLink})]})]})]})});return cn.createPortal(p,document.body)},gy=w.createContext(null),B6=()=>w.useContext(gy),Lye=()=>{var e;let t=B6();return(e=t==null?void 0:t.code)!=null?e:null},P6=()=>{var e;let t=B6();return(e=t==null?void 0:t.mermaid)!=null?e:null},Ige=e=>{var t;let r=B6();return r!=null&&r.renderers&&e&&(t=r.renderers.find(n=>Array.isArray(n.language)?n.language.includes(e):n.language===e))!=null?t:null},Dge=e=>{if(typeof DOMParser>"u"||typeof XMLSerializer>"u")return e;let t=new DOMParser().parseFromString(e,"text/html").querySelector("svg");return t?new XMLSerializer().serializeToString(t):e},Oge=(e,t)=>{var r;let n=(r=void 0)!=null?r:5;return new Promise((i,s)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),o=new Image;o.crossOrigin="anonymous",o.onload=()=>{let l=document.createElement("canvas"),u=o.width*n,c=o.height*n;l.width=u,l.height=c;let d=l.getContext("2d");if(!d){s(new Error("Failed to create 2D canvas context for PNG export"));return}d.drawImage(o,0,0,u,c),l.toBlob(m=>{if(!m){s(new Error("Failed to create PNG blob"));return}i(m)},"image/png")},o.onerror=()=>s(new Error("Failed to load SVG image")),o.src=a})},TM=({chart:e,children:t,className:r,onDownload:n,config:i,onError:s})=>{let a=mt(),[o,l]=w.useState(!1),u=w.useRef(null),{isAnimating:c,controls:d}=w.useContext(un),m=ts(),f=P6(),p=js(),g=O6(d,"mermaid","diagram"),y=async b=>{try{if(b==="mmd"){let L=`${g}.mmd`;Hu(L,e,"text/plain"),l(!1),n==null||n(b);return}if(!f){s==null||s(new Error("Mermaid plugin not available"));return}let v=f.getMermaid(i),x=e.split("").reduce((L,A)=>(L<<5)-L+A.charCodeAt(0)|0,0),E=`mermaid-${Math.abs(x)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:T}=await v.render(E,e);if(!T){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}let C=Dge(T);if(b==="svg"){let L=`${g}.svg`;Hu(L,C,"image/svg+xml"),l(!1),n==null||n(b);return}if(b==="png"){let L=await Oge(C);Hu(`${g}.png`,L,"image/png"),n==null||n(b),l(!1);return}}catch(v){s==null||s(v)}};return w.useEffect(()=>{let b=v=>{let x=v.composedPath();u.current&&!x.includes(u.current)&&l(!1)};return document.addEventListener("mousedown",b),()=>{document.removeEventListener("mousedown",b)}},[]),h.jsxs("div",{className:a("relative"),ref:u,children:[h.jsx("button",{"aria-label":p.downloadDiagram,className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:c,onClick:()=>l(!o),title:p.downloadDiagram,type:"button",children:t??h.jsx(m.DownloadIcon,{"aria-hidden":"true",size:14})}),o?h.jsxs("div",{className:a("absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[h.jsx("button",{"aria-label":p.downloadDiagramAsSvg,className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("svg"),title:p.downloadDiagramAsSvg,type:"button",children:p.mermaidFormatSvg}),h.jsx("button",{"aria-label":p.downloadDiagramAsPng,className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("png"),title:p.downloadDiagramAsPng,type:"button",children:p.mermaidFormatPng}),h.jsx("button",{"aria-label":p.downloadDiagramAsMmd,className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("mmd"),title:p.downloadDiagramAsMmd,type:"button",children:p.mermaidFormatMmd})]}):null]})},Mge=({chart:e,config:t,onFullscreen:r,onExit:n,className:i,...s})=>{let{Maximize2Icon:a,XIcon:o}=ts(),l=mt(),[u,c]=w.useState(!1),{isAnimating:d,controls:m}=w.useContext(un),f=js(),p=(()=>{if(typeof m=="boolean")return m;let v=m.mermaid;return v===!1?!1:v===!0||v===void 0?!0:v.panZoom!==!1})(),g=(()=>{if(typeof m=="boolean")return m;let v=m.mermaid;return v===!1?!1:v===!0||v===void 0?!0:v.download!==!1})(),y=(()=>{if(typeof m=="boolean")return m;let v=m.mermaid;return v===!1?!1:v===!0||v===void 0?!0:v.copy!==!1})(),b=()=>{c(!u)};return w.useEffect(()=>{if(u){M6();let v=x=>{x.key==="Escape"&&c(!1)};return document.addEventListener("keydown",v),()=>{document.removeEventListener("keydown",v),j6()}}},[u]),w.useEffect(()=>{u?r==null||r():n&&n()},[u,r,n]),h.jsxs(h.Fragment,{children:[h.jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",i),disabled:d,onClick:b,title:f.viewFullscreen,type:"button",...s,"aria-label":f.viewFullscreen,children:h.jsx(a,{"aria-hidden":"true",size:14})}),u?cn.createPortal(h.jsxs("div",{"aria-label":f.viewFullscreen,"aria-modal":"true",className:l("fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm"),"data-streamdown":"mermaid-fullscreen",onClick:b,onKeyDown:v=>{v.key==="Escape"&&b()},role:"dialog",children:[h.jsxs("div",{className:l("absolute top-4 right-4 z-10 flex items-center gap-1"),onClick:v=>v.stopPropagation(),onKeyDown:v=>v.stopPropagation(),role:"presentation",children:[g?h.jsx(TM,{chart:e,config:t}):null,y?h.jsx(py,{code:e}):null,h.jsx("button",{"aria-label":f.exitFullscreen,className:l("rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:b,title:f.exitFullscreen,type:"button",children:h.jsx(o,{"aria-hidden":"true",size:20})})]}),h.jsx("div",{className:l("flex size-full items-center justify-center p-4"),onClick:v=>v.stopPropagation(),onKeyDown:v=>v.stopPropagation(),role:"presentation",children:h.jsx(mj,{chart:e,className:l("size-full [&_svg]:h-auto [&_svg]:w-auto"),config:t,fullscreen:!0,showControls:p})})]}),document.body):null]})};function by(e){var t;if(e.nodeType===Node.TEXT_NODE)return(t=e.textContent)!=null?t:"";if(e.nodeType!==Node.ELEMENT_NODE)return"";let r=e;return r.tagName==="BR"?`
658
658
  `:Array.from(r.childNodes).map(by).join("")}var AM=e=>{let t=[],r=[],n=e.querySelectorAll("thead th");for(let s of n)t.push(by(s).trim());let i=e.querySelectorAll("tbody tr");for(let s of i){let a=[],o=s.querySelectorAll("td");for(let l of o)a.push(by(l).trim());r.push(a)}return{headers:t,rows:r}},NM=e=>{var t;if(typeof e!="object")return",";let r=e.table;return typeof r!="object"?",":(t=r.csvSeparator)!=null?t:","},RM=(e,t=",")=>{let r;t==="auto"?Intl.NumberFormat().format(1.1).includes(",")?r=";":r=",":r=t;let{headers:n,rows:i}=e,s=u=>{let c=!1;for(let d of u)if(d===r||d==='"'||d===`
659
659
  `||d==="\r"){c=!0;break}return c?`"${u.replace(/"/g,'""')}"`:u},a=n.length>0?i.length+1:i.length,o=new Array(a),l=0;n.length>0&&(o[l]=n.map(s).join(r),l+=1);for(let u of i)o[l]=u.map(s).join(r),l+=1;return o.join(`
660
660
  `)},jge=e=>{let{headers:t,rows:r}=e,n=o=>{let l=!1;for(let c of o)if(c===" "||c===`
@@ -663,7 +663,7 @@ Please report this to https://github.com/markedjs/marked.`,t){let i="<p>An error
663
663
  `)},ob=e=>{let t=!1;for(let n of e)if(n==="\\"||n==="|"||n===`
664
664
  `){t=!0;break}if(!t)return e;let r=[];for(let n of e)n==="\\"?r.push("\\\\"):n==="|"?r.push("\\|"):n===`
665
665
  `?r.push("<br>"):r.push(n);return r.join("")},LM=e=>{let{headers:t,rows:r}=e;if(t.length===0)return"";let n=new Array(r.length+2),i=0,s=t.map(o=>ob(o));n[i]=`| ${s.join(" | ")} |`,i+=1;let a=new Array(t.length);for(let o=0;o<t.length;o+=1)a[o]="---";n[i]=`| ${a.join(" | ")} |`,i+=1;for(let o of r)if(o.length<t.length){let l=new Array(t.length);for(let u=0;u<t.length;u+=1)l[u]=u<o.length?ob(o[u]):"";n[i]=`| ${l.join(" | ")} |`,i+=1}else{let l=o.map(u=>ob(u));n[i]=`| ${l.join(" | ")} |`,i+=1}return n.join(`
666
- `)},IM=({children:e,className:t,onCopy:r,onError:n,timeout:i=2e3})=>{let s=mt(),[a,o]=w.useState(!1),[l,u]=w.useState(!1),c=w.useRef(null),d=w.useRef(0),{isAnimating:m,controls:f}=w.useContext(un),p=js(),g=NM(f),y=async x=>{var E,T;if(typeof window>"u"||!((E=navigator==null?void 0:navigator.clipboard)!=null&&E.write)){n==null||n(new Error("Clipboard API not available"));return}try{let C=(T=c.current)==null?void 0:T.closest('[data-streamdown="table-wrapper"]'),L=C==null?void 0:C.querySelector("table");if(!L){n==null||n(new Error("Table not found"));return}let A=AM(L),z="";x==="csv"?z=RM(A,g):x==="tsv"?z=jge(A):z=LM(A);let I=new ClipboardItem({"text/plain":new Blob([z],{type:"text/plain"}),"text/html":new Blob([L.outerHTML],{type:"text/html"})});await navigator.clipboard.write([I]),u(!0),o(!1),r==null||r(x),d.current=window.setTimeout(()=>u(!1),i)}catch(C){n==null||n(C)}};w.useEffect(()=>{let x=E=>{let T=E.composedPath();c.current&&!T.includes(c.current)&&o(!1)};return document.addEventListener("mousedown",x),()=>{document.removeEventListener("mousedown",x),window.clearTimeout(d.current)}},[]);let b=ts(),v=l?b.CheckIcon:b.CopyIcon;return h.jsxs("div",{className:s("relative"),ref:c,children:[h.jsx("button",{className:s("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>o(!a),title:p.copyTable,type:"button",children:e??h.jsx(v,{height:14,width:14})}),a?h.jsxs("div",{className:s("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[h.jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("md"),title:p.copyTableAsMarkdown,type:"button",children:p.tableFormatMarkdown}),h.jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("csv"),title:p.copyTableAsCsv,type:"button",children:p.tableFormatCsv}),h.jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("tsv"),title:p.copyTableAsTsv,type:"button",children:p.tableFormatTsv})]}):null]})},DM=({children:e,className:t,onDownload:r,onError:n})=>{let i=mt(),[s,a]=w.useState(!1),o=w.useRef(null),{isAnimating:l,controls:u}=w.useContext(un),c=js(),d=ts(),m=NM(u),f=p=>{var g;try{let y=(g=o.current)==null?void 0:g.closest('[data-streamdown="table-wrapper"]'),b=y==null?void 0:y.querySelector("table");if(!b){n==null||n(new Error("Table not found"));return}let v=AM(b),x=p==="csv"?RM(v,m):LM(v),E=p==="csv"?"csv":"md",T=`${O6(u,"table","table")}.${E}`;Hu(T,x,p==="csv"?"text/csv":"text/markdown"),a(!1),r==null||r(p)}catch(y){n==null||n(y)}};return w.useEffect(()=>{let p=g=>{let y=g.composedPath();o.current&&!y.includes(o.current)&&a(!1)};return document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p)}},[]),h.jsxs("div",{className:i("relative"),ref:o,children:[h.jsx("button",{className:i("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:l,onClick:()=>a(!s),title:c.downloadTable,type:"button",children:e??h.jsx(d.DownloadIcon,{size:14})}),s?h.jsxs("div",{className:i("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[h.jsx("button",{className:i("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("csv"),title:c.downloadTableAsCsv,type:"button",children:c.tableFormatCsv}),h.jsx("button",{className:i("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("markdown"),title:c.downloadTableAsMarkdown,type:"button",children:c.tableFormatMarkdown})]}):null]})},Bge=({children:e,className:t,showCopy:r=!0,showDownload:n=!0})=>{let{Maximize2Icon:i,XIcon:s}=ts(),a=mt(),[o,l]=w.useState(!1),{isAnimating:u}=w.useContext(un),c=js(),d=()=>{l(!0)},m=()=>{l(!1)};return w.useEffect(()=>{if(o){M6();let f=p=>{p.key==="Escape"&&l(!1)};return document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f),j6()}}},[o]),h.jsxs(h.Fragment,{children:[h.jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:u,onClick:d,title:c.viewFullscreen,type:"button",children:h.jsx(i,{size:14})}),o?cn.createPortal(h.jsx("div",{"aria-label":c.viewFullscreen,"aria-modal":"true",className:a("fixed inset-0 z-50 flex flex-col bg-background"),"data-streamdown":"table-fullscreen",onClick:m,onKeyDown:f=>{f.key==="Escape"&&m()},role:"dialog",children:h.jsxs("div",{className:a("flex h-full flex-col"),"data-streamdown":"table-wrapper",onClick:f=>f.stopPropagation(),onKeyDown:f=>f.stopPropagation(),role:"presentation",children:[h.jsxs("div",{className:a("flex items-center justify-end gap-1 p-4"),children:[r?h.jsx(IM,{}):null,n?h.jsx(DM,{}):null,h.jsx("button",{className:a("rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:m,title:c.exitFullscreen,type:"button",children:h.jsx(s,{size:20})})]}),h.jsx("div",{className:a("flex-1 overflow-auto p-4 pt-0 [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10"),children:h.jsx("table",{className:a("w-full border-collapse border border-border"),"data-streamdown":"table",children:e})})]})}),document.body):null]})},Pge=({children:e,className:t,maxHeight:r,showControls:n,showCopy:i=!0,showDownload:s=!0,showFullscreen:a=!0,...o})=>{let l=mt(),{isAnimating:u}=w.useContext(un),c=xM(r),d=SM(u,!!c,e),m=n&&i,f=n&&s,p=n&&a,g=m||f||p;return h.jsxs("div",{className:l("my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2"),"data-streamdown":"table-wrapper",children:[g?h.jsxs("div",{className:l("flex items-center justify-end gap-1"),children:[m?h.jsx(IM,{}):null,f?h.jsx(DM,{}):null,p?h.jsx(Bge,{showCopy:m,showDownload:f,children:e}):null]}):null,h.jsx("div",{className:l("border-collapse overflow-x-auto overflow-y-auto rounded-md border border-border bg-background"),ref:d,style:c?{maxHeight:c}:void 0,children:h.jsx("table",{className:l("w-full divide-y divide-border",t),"data-streamdown":"table",...o,children:e})})]})},zge=/startLine=(\d+)/,$ge=/\bnoLineNumbers\b/,Hge=w.lazy(()=>O(()=>Promise.resolve().then(()=>$_e),void 0).then(e=>({default:e.Mermaid}))),Fge=/language-([^\s]+)/,Uge="node";function Gt(e,t){let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;let n=e,i=t;for(let s of r)if(s!==Uge&&!Object.is(n[s],i[s]))return!1;return!0}function Vge(e,t){var r,n;return((r=e==null?void 0:e.properties)==null?void 0:r.metastring)===((n=t==null?void 0:t.properties)==null?void 0:n.metastring)}var Mp=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,lb=(e,t)=>{if(typeof e=="boolean")return e;let r=e.table;return r===!1?!1:r===!0||r===void 0?!0:r[t]!==!1},q7=(e,t)=>{if(typeof e=="boolean")return e;let r=e.code;return r===!1?!1:r===!0||r===void 0?!0:r[t]!==!1},yf=(e,t)=>{if(typeof e=="boolean")return e;let r=e.mermaid;return r===!1?!1:r===!0||r===void 0?!0:r[t]!==!1},qge=(e,t)=>{if(typeof e=="boolean")return e;let r=e.image;return r===!1?!1:r===!0||r===void 0?!0:r[t]!==!1},z6=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("ol",{className:i("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e})},(e,t)=>Gt(e,t));z6.displayName="MarkdownOl";var OM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("li",{className:i("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e})},(e,t)=>Gt(e,t));OM.displayName="MarkdownLi";var MM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("ul",{className:i("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e})},(e,t)=>Gt(e,t));MM.displayName="MarkdownUl";var jM=w.memo(({className:e,node:t,...r})=>{let n=mt();return h.jsx("hr",{className:n("my-6 border-border",e),"data-streamdown":"horizontal-rule",...r})},(e,t)=>Gt(e,t));jM.displayName="MarkdownHr";var BM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("span",{className:i("font-semibold",t),"data-streamdown":"strong",...n,children:e})},(e,t)=>Gt(e,t));BM.displayName="MarkdownStrong";var Gge=({children:e,className:t,href:r,node:n,...i})=>{let s=mt(),{linkSafety:a}=w.useContext(un),[o,l]=w.useState(!1),u=r==="streamdown:incomplete-link",c=w.useCallback(async p=>{if(!(!(a!=null&&a.enabled&&r)||u)){if(p.preventDefault(),a.onLinkCheck&&await a.onLinkCheck(r)){window.open(r,"_blank","noreferrer");return}l(!0)}},[a,r,u]),d=w.useCallback(()=>{r&&window.open(r,"_blank","noreferrer")},[r]),m=w.useCallback(()=>{l(!1)},[]),f={url:r??"",isOpen:o,onClose:m,onConfirm:d};return a!=null&&a.enabled&&r?h.jsxs(h.Fragment,{children:[h.jsx("button",{className:s("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":u,"data-streamdown":"link",onClick:c,type:"button",children:e}),a.renderModal?a.renderModal(f):h.jsx(Lge,{...f})]}):h.jsx("a",{className:s("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":u,"data-streamdown":"link",href:r,rel:"noreferrer",target:"_blank",...i,children:e})},PM=w.memo(Gge,(e,t)=>Gt(e,t));PM.displayName="MarkdownA";var zM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h1",{className:i("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e})},(e,t)=>Gt(e,t));zM.displayName="MarkdownH1";var $M=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h2",{className:i("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e})},(e,t)=>Gt(e,t));$M.displayName="MarkdownH2";var HM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h3",{className:i("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e})},(e,t)=>Gt(e,t));HM.displayName="MarkdownH3";var FM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h4",{className:i("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e})},(e,t)=>Gt(e,t));FM.displayName="MarkdownH4";var UM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h5",{className:i("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e})},(e,t)=>Gt(e,t));UM.displayName="MarkdownH5";var VM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h6",{className:i("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e})},(e,t)=>Gt(e,t));VM.displayName="MarkdownH6";var qM=w.memo(({children:e,className:t,node:r,...n})=>{let{controls:i,tableMaxHeight:s}=w.useContext(un),a=Mp(i,"table"),o=lb(i,"copy"),l=lb(i,"download"),u=lb(i,"fullscreen");return h.jsx(Pge,{className:t,maxHeight:s,showControls:a,showCopy:o,showDownload:l,showFullscreen:u,...n,children:e})},(e,t)=>Gt(e,t));qM.displayName="MarkdownTable";var GM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("thead",{className:i("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e})},(e,t)=>Gt(e,t));GM.displayName="MarkdownThead";var WM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("tbody",{className:i("divide-y divide-border",t),"data-streamdown":"table-body",...n,children:e})},(e,t)=>Gt(e,t));WM.displayName="MarkdownTbody";var YM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("tr",{className:i("border-border",t),"data-streamdown":"table-row",...n,children:e})},(e,t)=>Gt(e,t));YM.displayName="MarkdownTr";var KM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("th",{className:i("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e})},(e,t)=>Gt(e,t));KM.displayName="MarkdownTh";var XM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("td",{className:i("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e})},(e,t)=>Gt(e,t));XM.displayName="MarkdownTd";var QM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("blockquote",{className:i("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e})},(e,t)=>Gt(e,t));QM.displayName="MarkdownBlockquote";var ZM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("sup",{className:i("text-sm",t),"data-streamdown":"superscript",...n,children:e})},(e,t)=>Gt(e,t));ZM.displayName="MarkdownSup";var JM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("sub",{className:i("text-sm",t),"data-streamdown":"subscript",...n,children:e})},(e,t)=>Gt(e,t));JM.displayName="MarkdownSub";var ej=w.memo(({children:e,className:t,node:r,...n})=>{if("data-footnotes"in n){let i=a=>{var o,l;if(!w.isValidElement(a))return!1;let u=Array.isArray(a.props.children)?a.props.children:[a.props.children],c=!1,d=!1;for(let m of u)if(m){if(typeof m=="string")m.trim()!==""&&(c=!0);else if(w.isValidElement(m))if(((o=m.props)==null?void 0:o["data-footnote-backref"])!==void 0)d=!0;else{let f=Array.isArray(m.props.children)?m.props.children:[m.props.children];for(let p of f){if(typeof p=="string"&&p.trim()!==""){c=!0;break}if(w.isValidElement(p)&&((l=p.props)==null?void 0:l["data-footnote-backref"])===void 0){c=!0;break}}}}return d&&!c},s=Array.isArray(e)?e.map(a=>{if(!w.isValidElement(a))return a;if(a.type===z6){let o=(Array.isArray(a.props.children)?a.props.children:[a.props.children]).filter(l=>!i(l));return o.length===0?null:{...a,props:{...a.props,children:o}}}return a}):e;return(Array.isArray(s)?s.some(a=>a!==null):s!==null)?h.jsx("section",{className:t,...n,children:s}):null}return h.jsx("section",{className:t,...n,children:e})},(e,t)=>Gt(e,t));ej.displayName="MarkdownSection";var Wge=({node:e,className:t,children:r,...n})=>{var i,s;let a=mt(),o=!("data-block"in n),{mermaid:l,controls:u,lineNumbers:c}=w.useContext(un),d=P6(),m=ige(),f=t==null?void 0:t.match(Fge),p=(i=f==null?void 0:f.at(1))!=null?i:"",g=Ige(p);if(o)return h.jsx("code",{className:a("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:r});let y=(s=e==null?void 0:e.properties)==null?void 0:s.metastring,b=y==null?void 0:y.match(zge),v=b?Number.parseInt(b[1],10):void 0,x=v!==void 0&&v>=1?v:void 0,E=!(y&&$ge.test(y))&&c!==!1,T="";if(w.isValidElement(r)&&r.props&&typeof r.props=="object"&&"children"in r.props&&typeof r.props.children=="string"?T=r.props.children:typeof r=="string"&&(T=r),g){let B=g.component;return h.jsx(w.Suspense,{fallback:h.jsx(V7,{}),children:h.jsx(B,{code:T,isIncomplete:m,language:p,meta:y})})}if(p==="mermaid"&&d){let B=Mp(u,"mermaid"),j=yf(u,"download"),G=yf(u,"copy"),W=yf(u,"fullscreen"),Y=yf(u,"panZoom"),V=B&&(j||G||W);return h.jsx(w.Suspense,{fallback:h.jsx(V7,{}),children:h.jsxs("div",{className:a("group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",t),"data-streamdown":"mermaid-block",children:[h.jsx("div",{className:a("flex h-8 items-center text-muted-foreground text-xs"),children:h.jsx("span",{className:a("ml-1 font-mono lowercase"),children:"mermaid"})}),V?h.jsx("div",{className:a("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:h.jsxs("div",{className:a("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"mermaid-block-actions",children:[j?h.jsx(TM,{chart:T,config:l==null?void 0:l.config}):null,G?h.jsx(py,{code:T}):null,W?h.jsx(Mge,{chart:T,config:l==null?void 0:l.config}):null]})}):null,h.jsx("div",{className:a("rounded-md border border-border bg-background"),children:h.jsx(Hge,{chart:T,config:l==null?void 0:l.config,showControls:Y})})]})})}let C=Mp(u,"code"),L=q7(u,"download"),A=q7(u,"copy"),{"data-block":z,...I}=n;return h.jsx(gge,{className:t,code:T,isIncomplete:m,language:p,lineNumbers:E,startLine:x,...I,children:C?h.jsxs(h.Fragment,{children:[L?h.jsx(Age,{code:T,language:p}):null,A?h.jsx(py,{}):null]}):null})},tj=w.memo(Wge,(e,t)=>Gt(e,t)&&Vge(e.node,t.node));tj.displayName="MarkdownCode";var Yge=({node:e,className:t,...r})=>{let{controls:n}=w.useContext(un),i=Mp(n,"image"),s=i&&qge(n,"download");return h.jsx(Rge,{className:t,node:e,showControls:i,showDownloadControl:s,...r})},rj=w.memo(Yge,(e,t)=>Gt(e,t));rj.displayName="MarkdownImg";var nj=w.memo(({children:e,node:t,...r})=>{let n=(Array.isArray(e)?e:[e]).filter(i=>i!=null&&i!=="");if(n.length===1&&w.isValidElement(n[0])){let i=n[0].props.node,s=i==null?void 0:i.tagName;if(s==="img")return h.jsx(h.Fragment,{children:e});if(s==="code"&&"data-block"in n[0].props)return h.jsx(h.Fragment,{children:e})}return h.jsx("p",{...r,children:e})},(e,t)=>Gt(e,t));nj.displayName="MarkdownParagraph";var Kge={ol:z6,li:OM,ul:MM,hr:jM,strong:BM,a:PM,h1:zM,h2:$M,h3:HM,h4:FM,h5:UM,h6:VM,table:qM,thead:GM,tbody:WM,tr:YM,th:KM,td:XM,blockquote:QM,code:tj,img:rj,pre:({children:e})=>w.isValidElement(e)?w.cloneElement(e,{"data-block":"true"}):e,sup:ZM,sub:JM,p:nj,section:ej},Xge=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,Qge=new RegExp("\\p{L}","u");function ij(e){let t=e.replace(/(```|~~~)[\s\S]*?\1/g,"").replace(/^#{1,6}\s+/gm,"").replace(/(\*{1,3}|_{1,3})/g,"").replace(/`[^`]*`/g,"").replace(/\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/^[\s>*\-+\d.]+/gm,""),r,n=0,i=0;for(let s of t){if(Xge.test(s)){r!=null||(r="rtl"),i+=1;continue}Qge.test(s)&&(r!=null||(r="ltr"),n+=1)}return i>n?"rtl":n>i?"ltr":r??"ltr"}var Zge=/^[ \t]{0,3}(`{3,}|~{3,})/,Jge=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,G7=e=>{let t=e.split(`
666
+ `)},IM=({children:e,className:t,onCopy:r,onError:n,timeout:i=2e3})=>{let s=mt(),[a,o]=w.useState(!1),[l,u]=w.useState(!1),c=w.useRef(null),d=w.useRef(0),{isAnimating:m,controls:f}=w.useContext(un),p=js(),g=NM(f),y=async x=>{var E,T;if(typeof window>"u"||!((E=navigator==null?void 0:navigator.clipboard)!=null&&E.write)){n==null||n(new Error("Clipboard API not available"));return}try{let C=(T=c.current)==null?void 0:T.closest('[data-streamdown="table-wrapper"]'),L=C==null?void 0:C.querySelector("table");if(!L){n==null||n(new Error("Table not found"));return}let A=AM(L),z="";x==="csv"?z=RM(A,g):x==="tsv"?z=jge(A):z=LM(A);let I=new ClipboardItem({"text/plain":new Blob([z],{type:"text/plain"}),"text/html":new Blob([L.outerHTML],{type:"text/html"})});await navigator.clipboard.write([I]),u(!0),o(!1),r==null||r(x),d.current=window.setTimeout(()=>u(!1),i)}catch(C){n==null||n(C)}};w.useEffect(()=>{let x=E=>{let T=E.composedPath();c.current&&!T.includes(c.current)&&o(!1)};return document.addEventListener("mousedown",x),()=>{document.removeEventListener("mousedown",x),window.clearTimeout(d.current)}},[]);let b=ts(),v=l?b.CheckIcon:b.CopyIcon;return h.jsxs("div",{className:s("relative"),ref:c,children:[h.jsx("button",{className:s("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>o(!a),title:p.copyTable,type:"button",children:e??h.jsx(v,{height:14,width:14})}),a?h.jsxs("div",{className:s("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[h.jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("md"),title:p.copyTableAsMarkdown,type:"button",children:p.tableFormatMarkdown}),h.jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("csv"),title:p.copyTableAsCsv,type:"button",children:p.tableFormatCsv}),h.jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>y("tsv"),title:p.copyTableAsTsv,type:"button",children:p.tableFormatTsv})]}):null]})},DM=({children:e,className:t,onDownload:r,onError:n})=>{let i=mt(),[s,a]=w.useState(!1),o=w.useRef(null),{isAnimating:l,controls:u}=w.useContext(un),c=js(),d=ts(),m=NM(u),f=p=>{var g;try{let y=(g=o.current)==null?void 0:g.closest('[data-streamdown="table-wrapper"]'),b=y==null?void 0:y.querySelector("table");if(!b){n==null||n(new Error("Table not found"));return}let v=AM(b),x=p==="csv"?RM(v,m):LM(v),E=p==="csv"?"csv":"md",T=`${O6(u,"table","table")}.${E}`;Hu(T,x,p==="csv"?"text/csv":"text/markdown"),a(!1),r==null||r(p)}catch(y){n==null||n(y)}};return w.useEffect(()=>{let p=g=>{let y=g.composedPath();o.current&&!y.includes(o.current)&&a(!1)};return document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p)}},[]),h.jsxs("div",{className:i("relative"),ref:o,children:[h.jsx("button",{className:i("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:l,onClick:()=>a(!s),title:c.downloadTable,type:"button",children:e??h.jsx(d.DownloadIcon,{size:14})}),s?h.jsxs("div",{className:i("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[h.jsx("button",{className:i("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("csv"),title:c.downloadTableAsCsv,type:"button",children:c.tableFormatCsv}),h.jsx("button",{className:i("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("markdown"),title:c.downloadTableAsMarkdown,type:"button",children:c.tableFormatMarkdown})]}):null]})},Bge=({children:e,className:t,showCopy:r=!0,showDownload:n=!0})=>{let{Maximize2Icon:i,XIcon:s}=ts(),a=mt(),[o,l]=w.useState(!1),{isAnimating:u}=w.useContext(un),c=js(),d=()=>{l(!0)},m=()=>{l(!1)};return w.useEffect(()=>{if(o){M6();let f=p=>{p.key==="Escape"&&l(!1)};return document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f),j6()}}},[o]),h.jsxs(h.Fragment,{children:[h.jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:u,onClick:d,title:c.viewFullscreen,type:"button",children:h.jsx(i,{size:14})}),o?cn.createPortal(h.jsx("div",{"aria-label":c.viewFullscreen,"aria-modal":"true",className:a("fixed inset-0 z-50 flex flex-col bg-background"),"data-streamdown":"table-fullscreen",onClick:m,onKeyDown:f=>{f.key==="Escape"&&m()},role:"dialog",children:h.jsxs("div",{className:a("flex h-full flex-col"),"data-streamdown":"table-wrapper",onClick:f=>f.stopPropagation(),onKeyDown:f=>f.stopPropagation(),role:"presentation",children:[h.jsxs("div",{className:a("flex items-center justify-end gap-1 p-4"),children:[r?h.jsx(IM,{}):null,n?h.jsx(DM,{}):null,h.jsx("button",{className:a("rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:m,title:c.exitFullscreen,type:"button",children:h.jsx(s,{size:20})})]}),h.jsx("div",{className:a("flex-1 overflow-auto p-4 pt-0 [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10"),children:h.jsx("table",{className:a("w-full border-collapse border border-border"),"data-streamdown":"table",children:e})})]})}),document.body):null]})},Pge=({children:e,className:t,maxHeight:r,showControls:n,showCopy:i=!0,showDownload:s=!0,showFullscreen:a=!0,...o})=>{let l=mt(),{isAnimating:u}=w.useContext(un),c=xM(r),d=SM(u,!!c,e),m=n&&i,f=n&&s,p=n&&a,g=m||f||p;return h.jsxs("div",{className:l("my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2"),"data-streamdown":"table-wrapper",children:[g?h.jsxs("div",{className:l("flex items-center justify-end gap-1"),children:[m?h.jsx(IM,{}):null,f?h.jsx(DM,{}):null,p?h.jsx(Bge,{showCopy:m,showDownload:f,children:e}):null]}):null,h.jsx("div",{className:l("border-collapse overflow-x-auto overflow-y-auto rounded-md border border-border bg-background"),ref:d,style:c?{maxHeight:c}:void 0,children:h.jsx("table",{className:l("w-full divide-y divide-border",t),"data-streamdown":"table",...o,children:e})})]})},zge=/startLine=(\d+)/,$ge=/\bnoLineNumbers\b/,Hge=w.lazy(()=>O(()=>Promise.resolve().then(()=>H_e),void 0).then(e=>({default:e.Mermaid}))),Fge=/language-([^\s]+)/,Uge="node";function Gt(e,t){let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;let n=e,i=t;for(let s of r)if(s!==Uge&&!Object.is(n[s],i[s]))return!1;return!0}function Vge(e,t){var r,n;return((r=e==null?void 0:e.properties)==null?void 0:r.metastring)===((n=t==null?void 0:t.properties)==null?void 0:n.metastring)}var Mp=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,lb=(e,t)=>{if(typeof e=="boolean")return e;let r=e.table;return r===!1?!1:r===!0||r===void 0?!0:r[t]!==!1},q7=(e,t)=>{if(typeof e=="boolean")return e;let r=e.code;return r===!1?!1:r===!0||r===void 0?!0:r[t]!==!1},yf=(e,t)=>{if(typeof e=="boolean")return e;let r=e.mermaid;return r===!1?!1:r===!0||r===void 0?!0:r[t]!==!1},qge=(e,t)=>{if(typeof e=="boolean")return e;let r=e.image;return r===!1?!1:r===!0||r===void 0?!0:r[t]!==!1},z6=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("ol",{className:i("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e})},(e,t)=>Gt(e,t));z6.displayName="MarkdownOl";var OM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("li",{className:i("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e})},(e,t)=>Gt(e,t));OM.displayName="MarkdownLi";var MM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("ul",{className:i("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e})},(e,t)=>Gt(e,t));MM.displayName="MarkdownUl";var jM=w.memo(({className:e,node:t,...r})=>{let n=mt();return h.jsx("hr",{className:n("my-6 border-border",e),"data-streamdown":"horizontal-rule",...r})},(e,t)=>Gt(e,t));jM.displayName="MarkdownHr";var BM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("span",{className:i("font-semibold",t),"data-streamdown":"strong",...n,children:e})},(e,t)=>Gt(e,t));BM.displayName="MarkdownStrong";var Gge=({children:e,className:t,href:r,node:n,...i})=>{let s=mt(),{linkSafety:a}=w.useContext(un),[o,l]=w.useState(!1),u=r==="streamdown:incomplete-link",c=w.useCallback(async p=>{if(!(!(a!=null&&a.enabled&&r)||u)){if(p.preventDefault(),a.onLinkCheck&&await a.onLinkCheck(r)){window.open(r,"_blank","noreferrer");return}l(!0)}},[a,r,u]),d=w.useCallback(()=>{r&&window.open(r,"_blank","noreferrer")},[r]),m=w.useCallback(()=>{l(!1)},[]),f={url:r??"",isOpen:o,onClose:m,onConfirm:d};return a!=null&&a.enabled&&r?h.jsxs(h.Fragment,{children:[h.jsx("button",{className:s("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":u,"data-streamdown":"link",onClick:c,type:"button",children:e}),a.renderModal?a.renderModal(f):h.jsx(Lge,{...f})]}):h.jsx("a",{className:s("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":u,"data-streamdown":"link",href:r,rel:"noreferrer",target:"_blank",...i,children:e})},PM=w.memo(Gge,(e,t)=>Gt(e,t));PM.displayName="MarkdownA";var zM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h1",{className:i("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e})},(e,t)=>Gt(e,t));zM.displayName="MarkdownH1";var $M=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h2",{className:i("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e})},(e,t)=>Gt(e,t));$M.displayName="MarkdownH2";var HM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h3",{className:i("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e})},(e,t)=>Gt(e,t));HM.displayName="MarkdownH3";var FM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h4",{className:i("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e})},(e,t)=>Gt(e,t));FM.displayName="MarkdownH4";var UM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h5",{className:i("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e})},(e,t)=>Gt(e,t));UM.displayName="MarkdownH5";var VM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("h6",{className:i("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e})},(e,t)=>Gt(e,t));VM.displayName="MarkdownH6";var qM=w.memo(({children:e,className:t,node:r,...n})=>{let{controls:i,tableMaxHeight:s}=w.useContext(un),a=Mp(i,"table"),o=lb(i,"copy"),l=lb(i,"download"),u=lb(i,"fullscreen");return h.jsx(Pge,{className:t,maxHeight:s,showControls:a,showCopy:o,showDownload:l,showFullscreen:u,...n,children:e})},(e,t)=>Gt(e,t));qM.displayName="MarkdownTable";var GM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("thead",{className:i("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e})},(e,t)=>Gt(e,t));GM.displayName="MarkdownThead";var WM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("tbody",{className:i("divide-y divide-border",t),"data-streamdown":"table-body",...n,children:e})},(e,t)=>Gt(e,t));WM.displayName="MarkdownTbody";var YM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("tr",{className:i("border-border",t),"data-streamdown":"table-row",...n,children:e})},(e,t)=>Gt(e,t));YM.displayName="MarkdownTr";var KM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("th",{className:i("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e})},(e,t)=>Gt(e,t));KM.displayName="MarkdownTh";var XM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("td",{className:i("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e})},(e,t)=>Gt(e,t));XM.displayName="MarkdownTd";var QM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("blockquote",{className:i("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e})},(e,t)=>Gt(e,t));QM.displayName="MarkdownBlockquote";var ZM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("sup",{className:i("text-sm",t),"data-streamdown":"superscript",...n,children:e})},(e,t)=>Gt(e,t));ZM.displayName="MarkdownSup";var JM=w.memo(({children:e,className:t,node:r,...n})=>{let i=mt();return h.jsx("sub",{className:i("text-sm",t),"data-streamdown":"subscript",...n,children:e})},(e,t)=>Gt(e,t));JM.displayName="MarkdownSub";var ej=w.memo(({children:e,className:t,node:r,...n})=>{if("data-footnotes"in n){let i=a=>{var o,l;if(!w.isValidElement(a))return!1;let u=Array.isArray(a.props.children)?a.props.children:[a.props.children],c=!1,d=!1;for(let m of u)if(m){if(typeof m=="string")m.trim()!==""&&(c=!0);else if(w.isValidElement(m))if(((o=m.props)==null?void 0:o["data-footnote-backref"])!==void 0)d=!0;else{let f=Array.isArray(m.props.children)?m.props.children:[m.props.children];for(let p of f){if(typeof p=="string"&&p.trim()!==""){c=!0;break}if(w.isValidElement(p)&&((l=p.props)==null?void 0:l["data-footnote-backref"])===void 0){c=!0;break}}}}return d&&!c},s=Array.isArray(e)?e.map(a=>{if(!w.isValidElement(a))return a;if(a.type===z6){let o=(Array.isArray(a.props.children)?a.props.children:[a.props.children]).filter(l=>!i(l));return o.length===0?null:{...a,props:{...a.props,children:o}}}return a}):e;return(Array.isArray(s)?s.some(a=>a!==null):s!==null)?h.jsx("section",{className:t,...n,children:s}):null}return h.jsx("section",{className:t,...n,children:e})},(e,t)=>Gt(e,t));ej.displayName="MarkdownSection";var Wge=({node:e,className:t,children:r,...n})=>{var i,s;let a=mt(),o=!("data-block"in n),{mermaid:l,controls:u,lineNumbers:c}=w.useContext(un),d=P6(),m=ige(),f=t==null?void 0:t.match(Fge),p=(i=f==null?void 0:f.at(1))!=null?i:"",g=Ige(p);if(o)return h.jsx("code",{className:a("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:r});let y=(s=e==null?void 0:e.properties)==null?void 0:s.metastring,b=y==null?void 0:y.match(zge),v=b?Number.parseInt(b[1],10):void 0,x=v!==void 0&&v>=1?v:void 0,E=!(y&&$ge.test(y))&&c!==!1,T="";if(w.isValidElement(r)&&r.props&&typeof r.props=="object"&&"children"in r.props&&typeof r.props.children=="string"?T=r.props.children:typeof r=="string"&&(T=r),g){let B=g.component;return h.jsx(w.Suspense,{fallback:h.jsx(V7,{}),children:h.jsx(B,{code:T,isIncomplete:m,language:p,meta:y})})}if(p==="mermaid"&&d){let B=Mp(u,"mermaid"),j=yf(u,"download"),G=yf(u,"copy"),W=yf(u,"fullscreen"),Y=yf(u,"panZoom"),V=B&&(j||G||W);return h.jsx(w.Suspense,{fallback:h.jsx(V7,{}),children:h.jsxs("div",{className:a("group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",t),"data-streamdown":"mermaid-block",children:[h.jsx("div",{className:a("flex h-8 items-center text-muted-foreground text-xs"),children:h.jsx("span",{className:a("ml-1 font-mono lowercase"),children:"mermaid"})}),V?h.jsx("div",{className:a("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:h.jsxs("div",{className:a("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"mermaid-block-actions",children:[j?h.jsx(TM,{chart:T,config:l==null?void 0:l.config}):null,G?h.jsx(py,{code:T}):null,W?h.jsx(Mge,{chart:T,config:l==null?void 0:l.config}):null]})}):null,h.jsx("div",{className:a("rounded-md border border-border bg-background"),children:h.jsx(Hge,{chart:T,config:l==null?void 0:l.config,showControls:Y})})]})})}let C=Mp(u,"code"),L=q7(u,"download"),A=q7(u,"copy"),{"data-block":z,...I}=n;return h.jsx(gge,{className:t,code:T,isIncomplete:m,language:p,lineNumbers:E,startLine:x,...I,children:C?h.jsxs(h.Fragment,{children:[L?h.jsx(Age,{code:T,language:p}):null,A?h.jsx(py,{}):null]}):null})},tj=w.memo(Wge,(e,t)=>Gt(e,t)&&Vge(e.node,t.node));tj.displayName="MarkdownCode";var Yge=({node:e,className:t,...r})=>{let{controls:n}=w.useContext(un),i=Mp(n,"image"),s=i&&qge(n,"download");return h.jsx(Rge,{className:t,node:e,showControls:i,showDownloadControl:s,...r})},rj=w.memo(Yge,(e,t)=>Gt(e,t));rj.displayName="MarkdownImg";var nj=w.memo(({children:e,node:t,...r})=>{let n=(Array.isArray(e)?e:[e]).filter(i=>i!=null&&i!=="");if(n.length===1&&w.isValidElement(n[0])){let i=n[0].props.node,s=i==null?void 0:i.tagName;if(s==="img")return h.jsx(h.Fragment,{children:e});if(s==="code"&&"data-block"in n[0].props)return h.jsx(h.Fragment,{children:e})}return h.jsx("p",{...r,children:e})},(e,t)=>Gt(e,t));nj.displayName="MarkdownParagraph";var Kge={ol:z6,li:OM,ul:MM,hr:jM,strong:BM,a:PM,h1:zM,h2:$M,h3:HM,h4:FM,h5:UM,h6:VM,table:qM,thead:GM,tbody:WM,tr:YM,th:KM,td:XM,blockquote:QM,code:tj,img:rj,pre:({children:e})=>w.isValidElement(e)?w.cloneElement(e,{"data-block":"true"}):e,sup:ZM,sub:JM,p:nj,section:ej},Xge=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,Qge=new RegExp("\\p{L}","u");function ij(e){let t=e.replace(/(```|~~~)[\s\S]*?\1/g,"").replace(/^#{1,6}\s+/gm,"").replace(/(\*{1,3}|_{1,3})/g,"").replace(/`[^`]*`/g,"").replace(/\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/^[\s>*\-+\d.]+/gm,""),r,n=0,i=0;for(let s of t){if(Xge.test(s)){r!=null||(r="rtl"),i+=1;continue}Qge.test(s)&&(r!=null||(r="ltr"),n+=1)}return i>n?"rtl":n>i?"ltr":r??"ltr"}var Zge=/^[ \t]{0,3}(`{3,}|~{3,})/,Jge=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,G7=e=>{let t=e.split(`
667
667
  `),r=null,n=0;for(let i of t){let s=Zge.exec(i);if(r===null){if(s){let a=s[1];r=a[0],n=a.length}}else if(s){let a=s[1],o=a[0],l=a.length;o===r&&l>=n&&(r=null,n=0)}}return r!==null},e2e=e=>{let t=e.split(`
668
668
  `);for(let r of t){let n=r.trim();if(n.length>0&&n.includes("|")&&Jge.test(n))return!0}return!1},t2e=()=>e=>{$i(e,"html",(t,r,n)=>{!n||typeof r!="number"||(n.children[r]={type:"text",value:t.value})})},W7=[],Y7={allowDangerousHtml:!0},xf=new WeakMap,r2e=class{constructor(){this.cache=new Map,this.keyCache=new WeakMap,this.maxSize=100}generateCacheKey(e){let t=this.keyCache.get(e);if(t)return t;let r=e.rehypePlugins,n=e.remarkPlugins,i=e.remarkRehypeOptions;if(!(r||n||i)){let c="default";return this.keyCache.set(e,c),c}let s=c=>{if(!c||c.length===0)return"";let d="";for(let m=0;m<c.length;m+=1){let f=c[m];if(m>0&&(d+=","),Array.isArray(f)){let[p,g]=f;if(typeof p=="function"){let y=xf.get(p);y||(y=p.name,xf.set(p,y)),d+=y}else d+=String(p);d+=":",d+=JSON.stringify(g)}else if(typeof f=="function"){let p=xf.get(f);p||(p=f.name,xf.set(f,p)),d+=p}else d+=String(f)}return d},a=s(r),o=s(n),l=i?JSON.stringify(i):"",u=`${o}::${a}::${l}`;return this.keyCache.set(e,u),u}get(e){let t=this.generateCacheKey(e),r=this.cache.get(t);return r&&(this.cache.delete(t),this.cache.set(t,r)),r}set(e,t){let r=this.generateCacheKey(e);if(this.cache.size>=this.maxSize){let n=this.cache.keys().next().value;n&&this.cache.delete(n)}this.cache.set(r,t)}clear(){this.cache.clear()}},K7=new r2e,sj=e=>{let t=n2e(e),r=e.children||"",n=t.runSync(t.parse(r),r);return c2e(n,e)},n2e=e=>{let t=K7.get(e);if(t)return t;let r=s2e(e);return K7.set(e,r),r},i2e=e=>e.some(t=>Array.isArray(t)?t[0]===ey:t===ey),s2e=e=>{let t=e.rehypePlugins||W7,r=e.remarkPlugins||W7,n=i2e(t)?r:[...r,t2e],i=e.remarkRehypeOptions?{...Y7,...e.remarkRehypeOptions}:Y7;return Kpe().use(Kme).use(n).use(Lpe,i).use(t)},a2e=e=>e,o2e=(e,t,r,n)=>{r?e.children.splice(t,1):e.children[t]={type:"text",value:n}},l2e=(e,t)=>{var r;for(let n in J2)if(Object.hasOwn(J2,n)&&Object.hasOwn(e.properties,n)){let i=e.properties[n],s=J2[n];(s===null||s.includes(e.tagName))&&(e.properties[n]=(r=t(String(i||""),n,e))!=null?r:void 0)}},u2e=(e,t,r,n,i,s)=>{let a=!1;return n?a=!n.includes(e.tagName):i&&(a=i.includes(e.tagName)),!a&&s&&typeof t=="number"&&(a=!s(e,t,r)),a},c2e=(e,t)=>{let{allowElement:r,allowedElements:n,disallowedElements:i,skipHtml:s,unwrapDisallowed:a,urlTransform:o}=t;if(r||n||i||s||o){let l=o||a2e;$i(e,(u,c,d)=>{if(u.type==="raw"&&d&&typeof c=="number")return o2e(d,c,s,u.value),c;if(u.type==="element"&&(l2e(u,l),u2e(u,c,d,n,i,r)&&d&&typeof c=="number"))return a&&u.children?d.children.splice(c,1,...u.children):d.children.splice(c,1),c})}return nme(e,{Fragment:h.Fragment,components:t.components,ignoreInvalidStyle:!0,jsx:h.jsx,jsxs:h.jsxs,passKeys:!0,passNode:!0})},h2e=/\[\^[\w-]{1,200}\](?!:)/,d2e=/\[\^[\w-]{1,200}\]:/,f2e=/<([A-Za-z][\w:-]*)[\s>/]/,m2e=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),X7=new Map,Q7=new Map,p2e=e=>{let t=e.toLowerCase(),r=X7.get(t);if(r)return r;let n=new RegExp(`<${t}(?=[\\s>/])[^>]*>`,"gi");return X7.set(t,n),n},g2e=e=>{let t=e.toLowerCase(),r=Q7.get(t);if(r)return r;let n=new RegExp(`</${t}(?=[\\s>])[^>]*>`,"gi");return Q7.set(t,n),n},Z7=(e,t)=>{if(m2e.has(t.toLowerCase()))return 0;let r=e.match(p2e(t));if(!r)return 0;let n=0;for(let i of r)i.trimEnd().endsWith("/>")||(n+=1);return n},J7=(e,t)=>{let r=e.match(g2e(t));return r?r.length:0},b2e=e=>{let t=0;for(let r=0;r<e.length-1;r+=1)e[r]==="$"&&e[r+1]==="$"&&(t+=1,r+=1);return t},_2e=e=>{let t=h2e.test(e),r=d2e.test(e);if(t||r)return[e];let n=Ti.lex(e,{gfm:!0}),i=[],s=[],a=!1;for(let o of n){let l=o.raw,u=i.length;if(s.length>0){i[u-1]+=l;let c=s.at(-1),d=Z7(l,c),m=J7(l,c);for(let f=0;f<d;f+=1)s.push(c);for(let f=0;f<m;f+=1)s.length>0&&s.at(-1)===c&&s.pop();continue}if(o.type==="html"&&o.block){let c=l.match(f2e);if(c){let d=c[1],m=Z7(l,d),f=J7(l,d);m>f&&s.push(d)}}if(u>0&&!a){let c=i[u-1];if(b2e(c)%2===1){i[u-1]=c+l;continue}}i.push(l),o.type!=="space"&&(a=o.type==="code")}return i},v2e=/^\n*/,y2e=/\n*$/,_y=/\n\n/g,x2e=(e,t,r)=>{if(!t.includes(`
669
669
  `))return e+t+r;let n=t.replace(_y,`
@@ -698,4 +698,4 @@ ${d}`,i=e.length;break}return i===0?e:n+e.slice(i)},w2e=(e,t)=>{if(!t.length)ret
698
698
  <rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
699
699
  <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
700
700
  </svg>
701
- `;function s_e({text:e,multiline:t,children:r}){const[n,i]=w.useState(!1),s=w.useCallback(async()=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)}catch{}},[e]);return h.jsxs("div",{className:`copy-box${t?" copy-box-multiline":""}`,children:[t?h.jsx("pre",{children:e}):h.jsx("span",{className:"copy-box-text",children:r??e}),h.jsx("button",{type:"button",className:"copy-box-btn",onClick:s,title:n?"Copied!":"Copy to clipboard","aria-label":n?"Copied":"Copy to clipboard",children:h.jsx("span",{dangerouslySetInnerHTML:{__html:n?n_e:i_e}})})]})}function a_e({onOpenTerminal:e}){const[t,r]=w.useState([]),[n,i]=w.useState([]),[s,a]=w.useState(null),[o,l]=w.useState(new Set),[u,c]=w.useState(new Set),[d,m]=w.useState(new Set),[f,p]=w.useState({});w.useEffect(()=>{let E=!1;return uH().then(({agent:T,sdk:C})=>{E||(r(T),i(C),a(L=>{var A;return L??((A=C[0])==null?void 0:A.id)??null}))}).catch(()=>{}),()=>{E=!0}},[]),w.useEffect(()=>{const E=T=>{const{stepId:C}=T.detail;m(L=>new Set(L).add(C))};return window.addEventListener(nv,E),()=>window.removeEventListener(nv,E)},[]);const g=n.find(E=>E.id===s),y=(E,T)=>(E.completed||d.has(E.id))&&(E.kind!=="create_config"||T<g.steps.length-1),b=(E,T)=>u.has(E.id)||E.kind==="create_config"&&(E.completed||d.has(E.id))&&T===g.steps.length-1,v=E=>l(T=>{const C=new Set(T);return C.has(E)?C.delete(E):C.add(E),C}),x=async E=>{if(g){c(T=>new Set(T).add(E.id)),p(T=>{const{[E.id]:C,...L}=T;return L});try{await cH(g.id,E.id),m(T=>new Set(T).add(E.id))}catch(T){p(C=>({...C,[E.id]:T.message}))}finally{c(T=>{const C=new Set(T);return C.delete(E.id),C})}}};return h.jsxs("div",{className:"setup-split",children:[h.jsxs("section",{className:"setup-pane",children:[h.jsx("h3",{children:"Set up with a coding agent"}),h.jsxs("div",{className:"setup-sdk-options",role:"group","aria-label":"Coding agent",children:[t.map(E=>{const T=E.steps[0],C=T==null?void 0:T.disabledReason,L=C??`Run ${E.label}`;return h.jsx("span",{className:"setup-agent-option-wrap",title:L,children:h.jsxs("button",{type:"button",className:"setup-sdk-option",disabled:!!C,title:L,onClick:()=>{!T||T.kind==="create_config"||e==null||e(E.id,T.id,iv(T),E.label)},children:[h.jsx("span",{className:"setup-sdk-icon","aria-hidden":"true",children:h.jsx(Fm,{provider:E.icon,size:20})}),h.jsx("span",{children:E.label})]})},E.id)}),h.jsx("a",{className:"setup-sdk-option setup-sdk-option-link",href:EA,target:"_blank",rel:"noopener",children:"Other"})]})]}),h.jsx("div",{className:"setup-divider",children:h.jsx("span",{children:"or set up manually"})}),h.jsxs("section",{className:"setup-pane",children:[h.jsxs("h3",{children:["Manual setup —"," ",h.jsx("a",{className:"welcome-link",href:WF,target:"_blank",rel:"noopener",children:"full docs ↗"})]}),h.jsx("div",{className:"welcome-field",children:h.jsxs("div",{className:"setup-sdk-options",role:"group","aria-label":"AI SDK",children:[n.map(E=>h.jsxs("button",{type:"button",className:`setup-sdk-option${E.id===s?" setup-sdk-option-selected":""}`,"aria-pressed":E.id===s,onClick:()=>a(E.id),children:[h.jsx("span",{className:"setup-sdk-icon","aria-hidden":"true",children:h.jsx(Fm,{provider:E.icon,size:20})}),h.jsx("span",{children:E.label})]},E.id)),h.jsx("a",{className:"setup-sdk-option setup-sdk-option-link",href:XF,target:"_blank",rel:"noopener",children:"Other"})]})}),g&&h.jsx("ol",{className:"setup-steps",children:g.steps.map((E,T)=>h.jsxs("li",{className:`setup-step${y(E,T)?" setup-step-done":""}${b(E,T)?" setup-step-running":""}`,children:[h.jsxs("div",{className:"setup-step-row",children:[h.jsxs("span",{className:"setup-step-label",children:[o_e(E),E.kind==="create_config"&&h.jsx("button",{type:"button",className:"setup-step-expand welcome-link",onClick:()=>v(E.id),children:o.has(E.id)?"Hide":"Show"})]}),h.jsx("span",{className:"setup-step-action",children:l_e(E,{done:y(E,T),running:b(E,T),onCreate:()=>x(E),onRun:()=>{if(E.kind==="create_config"||!g)return;const C=E.kind==="install_package"?`Install ${E.package}`:E.label;e==null||e(g.id,E.id,iv(E),C)}})})]}),E.kind==="create_config"&&o.has(E.id)&&h.jsxs("div",{className:"setup-config-snippet",children:[h.jsx(s_e,{text:E.contents,multiline:!0}),h.jsx("a",{className:"welcome-link setup-config-docs",href:YF,target:"_blank",rel:"noopener",children:"Config docs ↗"})]}),f[E.id]&&h.jsx("div",{className:"setup-file-status setup-file-error",children:f[E.id]})]},E.id))})]})]})}function o_e(e){switch(e.kind){case"create_config":return h.jsxs(h.Fragment,{children:["Create config: ",h.jsx("code",{children:e.path})]});case"install_package":return h.jsxs(h.Fragment,{children:["Install package: ",h.jsx("code",{children:e.package})]});case"run_command":return h.jsxs(h.Fragment,{children:["Run ",h.jsx("code",{children:e.command})]})}}function dk(e,t){return e?h.jsx("span",{className:"setup-step-action-wrap",title:e,children:t}):t}function fk({kind:e}){const t={className:"setup-step-btn-icon",width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0};switch(e){case"create_config":return h.jsxs("svg",{...t,children:[h.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),h.jsx("path",{d:"M14 2v6h6"}),h.jsx("path",{d:"M12 12v6M9 15h6"})]});case"install_package":return h.jsxs("svg",{...t,children:[h.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),h.jsx("path",{d:"M7 10l5 5 5-5"}),h.jsx("path",{d:"M12 15V3"})]});case"run_command":return h.jsx("svg",{...t,children:h.jsx("path",{d:"M6 4l14 8-14 8z",fill:"currentColor",stroke:"none"})})}}function l_e(e,t){if(e.kind==="create_config")return t.done?h.jsx("span",{className:"setup-step-status setup-file-created",children:"Created"}):dk(e.disabledReason,h.jsxs("button",{type:"button",className:"setup-step-btn",onClick:t.onCreate,disabled:t.running||!!e.disabledReason,title:e.disabledReason,children:[h.jsx(fk,{kind:e.kind}),t.running?"Creating…":"Create"]}));if(e.kind==="install_package"&&t.done)return h.jsx("span",{className:"setup-step-status setup-file-created",children:"Installed"});const r=e.disabledReason??iv(e);return dk(e.disabledReason,h.jsxs("button",{type:"button",className:"setup-step-btn",onClick:t.onRun,disabled:!!e.disabledReason,title:r,children:[h.jsx(fk,{kind:e.kind}),e.kind==="install_package"?"Install":"Run"]}))}const Rj="all-set",u_e=[{id:"setup",title:"Set up project",Component:a_e},{id:Rj,title:"You're all set",Component:r_e}];function c_e({onCreatePrompt:e,onOpenTerminal:t,configured:r=!1,steps:n=u_e}){const i=n.findIndex(m=>m.id===Rj),[s,a]=w.useState(r&&i>=0?i:0);w.useEffect(()=>{r&&i>=0&&a(i)},[r,i]);const o=n[s],l=s===0,u=s===n.length-1,c=()=>a(m=>Math.min(m+1,n.length-1)),d=o.Component;return h.jsx("div",{className:"welcome",children:h.jsxs("div",{className:"welcome-card",children:[h.jsxs("header",{className:"welcome-header",children:[h.jsx("img",{className:"welcome-logo",src:"/favicon.svg",width:"36",height:"49",alt:""}),h.jsx("ol",{className:"welcome-progress",children:n.map((m,f)=>{const p=f===s?"active":f<s?"done":"todo",g=f<s&&!!m.canReturn;return h.jsx("li",{className:`welcome-progress-${p}`,children:g?h.jsxs("button",{type:"button",className:"welcome-progress-btn",onClick:()=>a(f),children:[h.jsx("span",{className:"welcome-progress-dot",children:f+1}),h.jsx("span",{className:"welcome-progress-label",children:m.title})]}):h.jsxs(h.Fragment,{children:[n.length>1&&h.jsx("span",{className:"welcome-progress-dot",children:f+1}),h.jsx("span",{className:"welcome-progress-label",children:m.title})]})},m.id)})})]}),h.jsx("div",{className:"welcome-step-body",children:h.jsx(d,{onNext:c,isFirst:l,isLast:u,onCreatePrompt:e,onOpenTerminal:t})})]})})}function h_e(){const[e,t]=w.useState([]),[r,n]=w.useState(!0),[i,s]=w.useState(null),a=w.useCallback(async()=>{try{s(null),t(await eA())}catch(o){s(o.message)}finally{n(!1)}},[]);return w.useEffect(()=>{a()},[a]),{datasets:e,loading:r,error:i,refetch:a}}function d_e(){const[e,t]=w.useState([]),[r,n]=w.useState(!0),[i,s]=w.useState(null),a=w.useCallback(async()=>{try{s(null),t(await WH())}catch(o){s(o.message)}finally{n(!1)}},[]);return w.useEffect(()=>{a()},[a]),{evals:e,loading:r,error:i,refetch:a}}function f_e(){const[e,t]=w.useState([]),[r,n]=w.useState(!0),[i,s]=w.useState(null),a=w.useCallback(async()=>{try{s(null),t(await gH())}catch(l){s(l.message)}finally{n(!1)}},[]);w.useEffect(()=>{a()},[a]);const o=w.useCallback(l=>{t(u=>{let c=!1;const d=u.map(m=>Hh(m,l)?(c=!0,l):m);return c?d:[...u,l]})},[]);return{prompts:e,loading:r,error:i,refetch:a,patchPrompt:o}}const m_e=1e4;function p_e({win:e,doc:t,onFocus:r,minIntervalMs:n=m_e,now:i=Date.now}){let s=Number.NEGATIVE_INFINITY;const a=()=>{i()-s<n||(s=i(),r())},o=()=>{t.visibilityState==="visible"&&a()};return e.addEventListener("focus",a),t.addEventListener("visibilitychange",o),()=>{e.removeEventListener("focus",a),t.removeEventListener("visibilitychange",o)}}function g_e(){w.useEffect(()=>p_e({win:window,doc:document,onFocus:()=>{hH().catch(()=>{})}}),[])}function mk({initial:e,min:t=0,max:r=1/0,direction:n="horizontal",storageKey:i}){const[s,a]=w.useState(()=>{if(i)try{const y=localStorage.getItem(i);if(y){const b=JSON.parse(y);if(b&&typeof b=="object")return b}}catch{}return e}),o=w.useRef(s);o.current=s;const l=y=>{i&&localStorage.setItem(i,JSON.stringify(y))},u=y=>{o.current=y,a(y),l(y)},c=w.useRef(null),d=w.useRef(0),m=w.useRef(0);return w.useEffect(()=>{const y=v=>{if(!c.current)return;const x=n==="horizontal"?v.clientX:v.clientY,E=Math.max(t,Math.min(r,m.current+(x-d.current)));u({...o.current,[c.current]:E})},b=()=>{c.current=null};return window.addEventListener("mousemove",y),window.addEventListener("mouseup",b),()=>{window.removeEventListener("mousemove",y),window.removeEventListener("mouseup",b)}},[n,t,r]),{sizes:s,getOnMouseDown:(y,b)=>v=>{c.current=y,d.current=n==="horizontal"?v.clientX:v.clientY,m.current=b,v.preventDefault()},setSize:(y,b)=>u({...o.current,[y]:b}),deleteSize:y=>{const{[y]:b,...v}=o.current;u(v)}}}const b_e=[1e3,2e3,5e3,1e4,3e4];function __e({onMessage:e,onOpen:t,retryDelaysMs:r=b_e}){let n,i,s=0,a=!1;const o=()=>{const u=new EventSource("/api/events");n=u,u.onopen=()=>{s=0,t==null||t()},u.onmessage=c=>{try{e(JSON.parse(c.data))}catch(d){console.error("Failed to parse SSE message:",d)}},u.onerror=c=>{u.readyState===EventSource.CLOSED&&(console.error("SSE connection closed; reconnecting:",c),l())}},l=()=>{if(a||i!==void 0)return;const u=r[Math.min(s,r.length-1)]??1e3;s+=1,i=setTimeout(()=>{i=void 0,!a&&(n==null||n.close(),o())},u)};return o(),()=>{a=!0,i!==void 0&&clearTimeout(i),n==null||n.close()}}function v_e(e,t){w.useEffect(()=>__e({onMessage:e,onOpen:t}),[e,t])}const y_e={list:MH,groups:OH},Lj="trace-list-grouping";function x_e(){try{const e=localStorage.getItem(Lj);if(e)return PY(JSON.parse(e))}catch{}return YN.grouping}const pk=()=>Intl.DateTimeFormat().resolvedOptions().timeZone,ub=e=>[...e].sort((t,r)=>r.startTime-t.startTime);function S_e(e=y_e){const[t,r]=w.useState(()=>({...YN,grouping:x_e()})),[n,i]=w.useState([]),[s,a]=w.useState(),[o,l]=w.useState({}),[u,c]=w.useState(!0),[d,m]=w.useState(null),f=w.useRef(t),p=w.useRef(e);p.current=e;const g=w.useRef(o);g.current=o;const y=w.useRef(new Set),b=w.useRef(0),v=w.useCallback(async()=>{const C=++b.current,{search:L,filters:A,grouping:z}=f.current,I=p.current;try{if(typeof z=="string"){const B=ub(await I.list({search:L,filters:A}));if(C!==b.current)return;i(B),a(void 0),l({})}else{const B=await I.groups({search:L,filters:A,groupBy:z,timeZone:pk()}),j=B.filter(W=>g.current[W.key]),G=await Promise.all(j.map(W=>I.list({search:L,filters:[...A,W.filter]})));if(C!==b.current)return;a(B),l(Object.fromEntries(j.map((W,Y)=>[W.key,ub(G[Y])])))}m(null)}catch(B){C===b.current&&m(B.message)}finally{C===b.current&&c(!1)}},[]),x=w.useCallback(C=>{f.current=C,g.current={},y.current.clear(),l({}),r(C);try{localStorage.setItem(Lj,JSON.stringify(C.grouping))}catch{}v()},[v]),E=w.useCallback(C=>{const{key:L}=C;if(g.current[L]||y.current.has(L))return;y.current.add(L);const A=f.current;p.current.list({search:A.search,filters:[...A.filters,C.filter]}).then(z=>{f.current===A&&l(I=>({...I,[L]:ub(z)}))}).catch(()=>{}).finally(()=>{f.current===A&&y.current.delete(L)})},[]),T=w.useCallback(C=>{const{search:L,filters:A}=f.current;return p.current.groups({search:L,filters:A.filter(z=>z.column!==C),groupBy:{column:C},timeZone:pk()})},[]);return w.useEffect(()=>{v()},[v]),{traces:n,groups:s,members:o,loadGroup:E,facets:T,view:t,setView:x,loading:u,error:d,refetch:v}}function w_e(e,t,r,n,i,s){var m,f;const a=n(r),o=e.find(p=>p.tabs.some(g=>n(g)===a));if(o)return{panes:e.map(p=>p.id===o.id?{...p,tabs:i.replace?p.tabs.map(g=>n(g)===a?r:g):p.tabs,activeTabKey:a}:p),focusId:o.id,flashId:o.id};const l=e.findIndex(p=>p.id===t);if(l<0)return{panes:e,focusId:t};let u=t,c=e,d;if(i.split){const p=((m=e[l+1])==null?void 0:m.id)??((f=e[l-1])==null?void 0:f.id);p?u=p:(u=s(),c=[...e],c.splice(l+1,0,{id:u,tabs:[],activeTabKey:null}),d=t)}return{panes:c.map(p=>p.id===u?{...p,tabs:[...p.tabs,r],activeTabKey:a}:p),focusId:u,...d&&{splitFrom:d}}}function E_e(e){return{traces:e.some(t=>t.kind==="traces"),evals:e.some(t=>t.kind==="evals"),datasets:new Set(e.flatMap(t=>t.kind==="dataset"&&t.key?[Za({providerId:t.provider,id:t.key})]:[]))}}const k_e=w.lazy(()=>O(()=>import("./DatasetView-B1KoSX7p.js").then(e=>e.D),__vite__mapDeps([101,102]))),C_e=w.lazy(()=>O(()=>import("./EvalView-BW2qyhFj.js"),[])),T_e=w.lazy(()=>O(()=>import("./EvalRunView-By5RN8fo.js"),[])),Ij="welcome",Ht=e=>e.type==="prompt"?`prompt:${e.providerId}:${e.promptId}`:e.type==="trace"?`trace:${e.providerId}:${e.traceId}`:e.type==="dataset"?`dataset:${e.providerId}:${e.datasetId}`:e.type==="eval"?`eval:${e.providerId}:${e.evalId}`:e.type==="eval-run"?`eval-run:${e.providerId}:${e.runId}`:e.type==="terminal"?`terminal:${e.id}`:e.type==="settings"?`settings:${e.section}`:Ij;let A_e=0,N_e=0;const Sy=()=>`pane${++N_e}`,gk=Sy(),R_e=1200;function bk(e){const t=document.querySelector(`[data-pane="${CSS.escape(e)}"]`);t&&(t.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}),t.classList.remove("pane-flash"),t.offsetWidth,t.classList.add("pane-flash"),window.setTimeout(()=>t.classList.remove("pane-flash"),R_e))}function L_e(){return h.jsx("img",{src:"/favicon.svg",width:"22",height:"30",alt:"evalution logo",style:{display:"block"}})}function _k(){return h.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("line",{x1:"4",y1:"6",x2:"14",y2:"6"}),h.jsx("line",{x1:"8",y1:"12",x2:"20",y2:"12"}),h.jsx("line",{x1:"6",y1:"18",x2:"16",y2:"18"})]})}function I_e(){return h.jsx(o1,{size:20})}function D_e(){return h.jsx(Jd,{size:20})}function O_e(){return h.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),h.jsx("polyline",{points:"14 2 14 8 20 8"}),h.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),h.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),h.jsx("line",{x1:"10",y1:"9",x2:"8",y2:"9"})]})}function vk(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("circle",{cx:"12",cy:"12",r:"3"}),h.jsx("path",{d:"M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 11-2.83 2.83l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 11-2.83-2.83l.06-.06a1.65 1.65 0 00.33-1.82 1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 112.83-2.83l.06.06a1.65 1.65 0 001.82.33H9a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 112.83 2.83l-.06.06a1.65 1.65 0 00-.33 1.82V9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"})]})}function M_e(){return h.jsx("span",{className:"welcome-tab-emoji",role:"img","aria-label":"Welcome",children:"👋"})}function j_e(){return h.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("polyline",{points:"4 17 10 11 4 5"}),h.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function B_e(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),h.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]})}function P_e(){const{prompts:e,loading:t,error:r,refetch:n,patchPrompt:i}=f_e(),s=S_e(),{traces:a,refetch:o}=s,{datasets:l,loading:u,error:c,refetch:d}=h_e(),[m,f]=w.useState(0),{evals:p,loading:g,error:y,refetch:b}=d_e(),[v,x]=w.useState(0),[E,T]=w.useState({}),[C,L]=w.useState(null),[A,z]=w.useState([]),I=w.useMemo(()=>E_e(A),[A]),B=w.useCallback(()=>{dH().then(z).catch(()=>{})},[]),[j,G]=w.useState(0),[W,Y]=w.useState([{id:gk,tabs:[],activeTabKey:null}]),[V,X]=w.useState(gk),[P,re]=w.useState(""),[R,de]=w.useState([]),[Te,H]=w.useState(!1),[Oe,Pe]=w.useState(),[ee,oe]=w.useState("prompts"),[Be,we]=w.useState(!1),[_e,je]=w.useState(()=>new URLSearchParams(window.location.search).get("expand")!=="true"),[Ke,Le]=w.useState(null),[it,zt]=w.useState(new Set),ot=w.useRef(new Set),Br=w.useRef(null),Fe=w.useRef(!1),He=mk({initial:{w:224},min:120,max:600,storageKey:"sidebar-width"}),be=mk({initial:{},min:150,storageKey:"pane-widths"}),Ge=w.useRef(null),ht=w.useRef(!1);w.useEffect(()=>{const Q=ie=>{ht.current=ie.metaKey||ie.ctrlKey};return window.addEventListener("pointerdown",Q,!0),window.addEventListener("click",Q,!0),()=>{window.removeEventListener("pointerdown",Q,!0),window.removeEventListener("click",Q,!0)}},[]);const pt=w.useRef(null),Qe=w.useCallback(()=>{fetch("/api/config",{cache:"no-store"}).then(Q=>Q.json()).then(Q=>{re(Q.rootPath),H(!!Q.configured),Pe(Q.projectUrl??void 0)}).catch(()=>{})},[]);w.useEffect(()=>{Qe()},[Qe]),w.useEffect(()=>{fH().then(de).catch(()=>{})},[]);const hn=w.useCallback(Q=>{if(Q.type==="sync-status")z(Q.adopting);else if(Q.type==="prompt-changed"){if(r$(Q.event.type,Q.providerId,Q.event.promptId))return;n(),G(ie=>ie+1)}else if(Q.type==="trace-changed")o();else if(Q.type==="dataset-changed")d(),f(ie=>ie+1);else if(Q.type==="views-changed")xy();else if(Q.type==="eval-changed")b(),x(ie=>ie+1);else if(Q.type==="eval-run"){o();const{type:ie,...ke}=Q;T(Ee=>{if(ke.status==="running")return{...Ee,[ke.runId]:ke};const{[ke.runId]:ce,...ve}=Ee;return ve})}},[n,o,d,b]),te=w.useCallback(()=>{Qe(),B(),n(),o(),d(),b(),xy()},[Qe,B,n,o,d,b]);v_e(hn,te),g_e(),w.useEffect(()=>{if(t)return;const Q=new Set(e.map(ie=>`${ie.providerId}:${ie.id}`));Y(ie=>ie.map(ke=>{const Ee=ke.tabs.filter(ve=>ve.type!=="prompt"||Q.has(`${ve.providerId}:${ve.promptId}`));if(Ee.length===ke.tabs.length)return ke;const ce=Ee.some(ve=>Ht(ve)===ke.activeTabKey);return{...ke,tabs:Ee,activeTabKey:ce?ke.activeTabKey:Ee.at(-1)?Ht(Ee.at(-1)):null}}))},[e,t]),w.useEffect(()=>{if(t)return;Y(ie=>{const ke=ie.some(Ee=>Ee.tabs.some(ce=>ce.type==="welcome"));return e.length===0?ke?ie:ie.map((Ee,ce)=>ce===0?{...Ee,tabs:[{type:"welcome"},...Ee.tabs],activeTabKey:Ij}:Ee):ke?ie.map(Ee=>{const ce=Ee.tabs.filter(tt=>tt.type!=="welcome"),ve=ce.some(tt=>Ht(tt)===Ee.activeTabKey);return{...Ee,tabs:ce,activeTabKey:ve?Ee.activeTabKey:ce.at(-1)?Ht(ce.at(-1)):null}}):ie});const Q=Br.current;e.length===0?je(!1):Q===0&&je(!0),Br.current=e.length},[t,e.length]);const xe=w.useCallback((Q,ie)=>{zt(ke=>{const Ee=lH(ke,Q,ie);return ot.current=Ee,Ee})},[]);w.useEffect(()=>{const Q=ie=>{ot.current.size>0&&(ie.preventDefault(),ie.returnValue="")};return window.addEventListener("beforeunload",Q),()=>window.removeEventListener("beforeunload",Q)},[]);const Ve=w.useCallback((Q,ie)=>{Y(ke=>ke.map(Ee=>Ee.tabs.some(ce=>Ht(ce)===Q)?{...Ee,tabs:Ee.tabs.map(ce=>{if(Ht(ce)!==Q||ce.type!=="prompt")return ce;const{ref:ve,...tt}=ce;return ie?{...tt,ref:ie}:tt})}:Ee))},[]),Ze=(Q,ie)=>{const ke={type:"prompt",providerId:Q,promptId:ie},Ee=Ht(ke);Y(ce=>ce.map(ve=>ve.id!==V?ve:{...ve,tabs:ve.tabs.some(tt=>Ht(tt)===Ee)?ve.tabs:[...ve.tabs,ke],activeTabKey:Ee}))};w.useEffect(()=>{if(t||Fe.current)return;const Q=new URLSearchParams(window.location.search).get("prompt"),ie=Q?e.find(ke=>ke.id===Q):void 0;ie!=null&&ie.providerId&&Ze(ie.providerId,ie.id),Fe.current=!0},[t,e]),w.useEffect(()=>{const Q=DK(window.location.search);Q&&xt({type:"trace",providerId:Q.providerId,traceId:Q.traceId,rootSpanId:"",label:"Trace"})},[]);const xt=Q=>{const ie=Ht(Q);Y(ke=>{const Ee=ke.find(ce=>ce.tabs.some(ve=>Ht(ve)===ie));return Ee?(X(Ee.id),bk(Ee.id),ke.map(ce=>ce.id===Ee.id?{...ce,activeTabKey:ie}:ce)):ke.map(ce=>ce.id!==V?ce:{...ce,tabs:[...ce.tabs,Q],activeTabKey:ie})})},Pr=(Q,ie,{replace:ke=!1,split:Ee=!0}={})=>{Y(ce=>{var tt;const ve=w_e(ce,Q,ie,Ht,{replace:ke,split:Ee},Sy);if(ve.panes===ce)return ce;if(ve.splitFrom){const Ce=(tt=Ge.current)==null?void 0:tt.querySelector(`[data-pane="${ve.splitFrom}"]`),Ne=(Ce==null?void 0:Ce.getBoundingClientRect().width)??400;be.setSize(ve.splitFrom,Math.max(200,Math.floor(Ne/2)))}return X(ve.focusId),ve.flashId&&bk(ve.flashId),ve.panes})},dn=(Q,ie,ke=!1)=>Pr(Q,ie,{replace:ke,split:ht.current}),bi=(Q,ie,ke,Ee)=>{const ce={type:"terminal",id:`t${++A_e}`,target:ie,command:ke,label:Ee??ke};Pr(Q,ce)},rs=async(Q,ie,ke)=>{try{const Ee=await mH(ie.id,ke);bi(Q,{kind:"agent",agentId:ie.id,context:ke},Ee,ie.label)}catch(Ee){console.error(`Couldn't launch ${ie.label}:`,Ee)}},ns=Q=>e.find(ie=>Hh(ie,Q)),zr=(Q,ie,ke,Ee)=>{const ve={type:"prompt",providerId:Hf(ie.providerId,`opening prompt ${ie.id}`),promptId:ie.id,...ke&&{fill:ke},...Ee&&{ref:Ee}};dn(Q,ve,!!ke||!!Ee)},Ea=(Q,ie,ke,Ee)=>{const ce=ns(ie),ve=ce&&_A(ie)?VF(bA(ie,ce),ce,{type:"trace",description:`trace ${ke.slice(0,8)}…`,providerId:Ee,traceId:ke},ie.resources):void 0,tt=ie.variation?{promptId:ie.id,variation:ie.variation}:ie.version?{promptId:ie.id,version:ie.version}:void 0;zr(Q,{id:ie.id,providerId:ie.providerId},ve,tt)},zn=(Q,ie,ke)=>({type:"eval-run",providerId:Q,runId:ie.id,label:`${ke} · ${ks(ie.startedAt)}`}),X1=(Q,ie)=>{var ke;return{type:"trace",providerId:Q,traceId:ie,rootSpanId:"",label:((ke=a.find(Ee=>Ee.id===ie&&Ee.providerId===Q))==null?void 0:ke.name)??`trace ${ie.slice(0,8)}…`}},Dj=(Q,ie)=>dn(Q,ie.type==="trace"?X1(ie.providerId,ie.traceId):{type:"dataset",providerId:ie.providerId,datasetId:ie.datasetId,label:ie.name}),zc=Q=>{for(const ie of W)ie.tabs.some(ke=>Ht(ke)===Q)&&U6(ie.id,Q)},Oj=(Q,ie)=>{const{tracerProviderId:ke,traceId:Ee,rootSpanId:ce,label:ve}=ie;Pr(Q,{type:"trace",providerId:ke,traceId:Ee,rootSpanId:ce,label:ve})},U6=(Q,ie)=>{xe(ie,!1),Y(ke=>{const Ee=ke.find(Ne=>Ne.id===Q),ce=Ee.tabs.filter(Ne=>Ht(Ne)!==ie);if(ce.length===0&&ke.length>1){const Ne=ke.filter(mn=>mn.id!==Q),fn=ke.findIndex(mn=>mn.id===Q);return X(Ne[Math.min(fn,Ne.length-1)].id),be.deleteSize(Q),Ne}const ve=Ee.tabs.findIndex(Ne=>Ht(Ne)===ie),tt=ce[Math.min(ve,ce.length-1)],Ce=Ee.activeTabKey===ie?tt?Ht(tt):null:Ee.activeTabKey;return ke.map(Ne=>Ne.id===Q?{...Ne,tabs:ce,activeTabKey:Ce}:Ne)})},Mj=(Q,ie,ke)=>{ke.stopPropagation(),U6(Q,ie)},jj=Q=>{var ve;const ie=Sy(),ke=(ve=Ge.current)==null?void 0:ve.querySelector(`[data-pane="${Q}"]`),Ee=(ke==null?void 0:ke.getBoundingClientRect().width)??400,ce=Math.max(200,Math.floor(Ee/2));be.setSize(Q,ce),Y(tt=>{const Ce=tt.findIndex(fn=>fn.id===Q),Ne=[...tt];return Ne.splice(Ce+1,0,{id:ie,tabs:[],activeTabKey:null}),Ne}),X(ie)},V6=(Q,ie,ke)=>{Q!==ke&&(Y(Ee=>{const ce=Ee.find(Ce=>Ce.id===Q),ve=ce.tabs.find(Ce=>Ht(Ce)===ie);if(!ve)return Ee;const tt=ce.tabs.filter(Ce=>Ht(Ce)!==ie);return tt.length===0&&Ee.length>1?(be.deleteSize(Q),Ee.filter(Ne=>Ne.id!==Q).map(Ne=>{if(Ne.id===ke){const fn=Ne.tabs.some(mn=>Ht(mn)===ie);return{...Ne,tabs:fn?Ne.tabs:[...Ne.tabs,ve],activeTabKey:ie}}return Ne})):Ee.map(Ce=>{if(Ce.id===Q){const Ne=Ce.activeTabKey===ie,fn=Ce.tabs.findIndex(mn=>Ht(mn)===ie);return{...Ce,tabs:tt,activeTabKey:Ne?tt[Math.min(fn,tt.length-1)]?Ht(tt[Math.min(fn,tt.length-1)]):null:Ce.activeTabKey}}if(Ce.id===ke){const Ne=Ce.tabs.some(fn=>Ht(fn)===ie);return{...Ce,tabs:Ne?Ce.tabs:[...Ce.tabs,ve],activeTabKey:ie}}return Ce})}),X(ke))},q6="~/Library/Mobile Documents/com~apple~CloudDocs",Q1=P.replace(/^\/Users\/[^/]+/,"~"),w0=Q1.startsWith(q6),Gl=w0?Q1.slice(q6.length)||"/":Q1,G6=w0?`iCloud Drive${Gl!=="/"?Gl:""}`:Gl;w.useEffect(()=>{P&&(document.title=G6)},[G6,P]);const E0=W.find(Q=>Q.id===V)??W[0],Zt=(E0==null?void 0:E0.tabs.find(Q=>Ht(Q)===E0.activeTabKey))??null,Bj=(Zt==null?void 0:Zt.type)==="prompt"?Zt.promptId:null,Pj=(Zt==null?void 0:Zt.type)==="trace"?`${Zt.providerId}:${Zt.traceId}`:null,zj=(Zt==null?void 0:Zt.type)==="dataset"?Za({providerId:Zt.providerId,id:Zt.datasetId}):null,$j=(Zt==null?void 0:Zt.type)==="eval"?lA({providerId:Zt.providerId,id:Zt.evalId}):null,Hj=(Zt==null?void 0:Zt.type)==="settings"?Zt.section:null,Wl=He.sizes.w;return h.jsxs("div",{className:"app",children:[h.jsxs("div",{className:"app-titlebar",children:[h.jsx("div",{className:"app-titlebar-icon",children:h.jsx(L_e,{})}),P&&_e&&h.jsxs("span",{className:"header-path",children:[w0&&h.jsx("svg",{className:"icloud-icon",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:h.jsx("path",{d:"M18 10h-1.26A8 8 0 109 20h9a5 5 0 000-10z"})}),w0&&h.jsx("span",{children:"iCloud Drive"}),Gl&&Gl!=="/"&&Gl]})]}),h.jsxs("div",{className:"app-main",children:[h.jsxs("div",{className:"icon-strip",children:[h.jsxs("nav",{className:"icon-nav",children:[h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="prompts"&&_e?"active":""}`,onClick:()=>{ee==="prompts"&&_e?je(!1):(oe("prompts"),je(!0))},title:"Prompts",children:h.jsx(O_e,{})}),h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="traces"&&_e?"active":""}`,onClick:()=>{ee==="traces"&&_e?je(!1):(oe("traces"),je(!0))},title:"Traces",children:h.jsx(_k,{})}),h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="datasets"&&_e?"active":""}`,onClick:()=>{ee==="datasets"&&_e?je(!1):(oe("datasets"),je(!0))},title:"Datasets",children:h.jsx(D_e,{})}),h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="evals"&&_e?"active":""}`,onClick:()=>{ee==="evals"&&_e?je(!1):(oe("evals"),je(!0))},title:"Evals",children:h.jsx(I_e,{})})]}),h.jsx("nav",{className:"icon-nav-bottom",children:h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="settings"&&_e?"active":""}`,onClick:()=>{ee==="settings"&&_e?je(!1):(oe("settings"),je(!0))},title:"Settings",children:h.jsx(vk,{})})})]}),h.jsxs("div",{className:"content-area",children:[h.jsxs("div",{className:"content-header",children:[h.jsx("div",{className:"content-header-spacer",style:{width:_e?Wl+4:14}}),W.map((Q,ie)=>{const Ee=ie===W.length-1?void 0:be.sizes[Q.id],ce=!_e&&ie===0?14:0;return h.jsxs(w.Fragment,{children:[ie>0&&h.jsx("div",{className:"pane-resize-divider",onMouseDown:be.getOnMouseDown(W[ie-1].id,be.sizes[W[ie-1].id]??200)}),h.jsxs("div",{className:`pane-tabbar${Q.id===Ke?" pane-drop-target":""}`,style:Ee!==void 0?{width:Ee-ce,flexShrink:0}:{flex:1},onDragOver:ve=>{ve.preventDefault(),Le(Q.id)},onDragLeave:ve=>{ve.currentTarget.contains(ve.relatedTarget)||Le(null)},onDrop:()=>{Le(null),pt.current&&V6(pt.current.paneId,pt.current.key,Q.id)},children:[h.jsx("div",{className:"pane-tabs-scroll",children:Q.tabs.map(ve=>{const tt=Ht(ve),Ce=ve.type==="prompt"?e.find(mn=>mn.id===ve.promptId&&mn.providerId===ve.providerId):void 0,Ne=ve.type==="prompt"?(Ce==null?void 0:Ce.name)??ve.promptId:ve.type==="trace"||ve.type==="dataset"||ve.type==="eval"||ve.type==="eval-run"||ve.type==="terminal"?ve.label:ve.type==="settings"?nN(ve.section):"Welcome",fn=ve.type==="trace"?h.jsx(_k,{}):ve.type==="dataset"?h.jsx(Jd,{size:14}):ve.type==="eval"||ve.type==="eval-run"?h.jsx(o1,{size:14}):ve.type==="welcome"?h.jsx(M_e,{}):ve.type==="terminal"?h.jsx(j_e,{}):ve.type==="settings"?h.jsx(vk,{}):void 0;return h.jsx(vq,{name:Ne,icon:fn,active:tt===Q.activeTabKey,dirty:it.has(tt)||!!(Ce!=null&&Ce.dirty),onClick:()=>{X(Q.id),Y(mn=>mn.map(Z1=>Z1.id===Q.id?{...Z1,activeTabKey:tt}:Z1))},onClose:mn=>Mj(Q.id,tt,mn),onDragStart:()=>{pt.current={paneId:Q.id,key:tt}},onDragEnd:()=>{pt.current=null}},tt)})}),h.jsx("button",{type:"button",className:"tab-split-btn",onClick:()=>jj(Q.id),title:"Split pane",children:h.jsx(B_e,{})})]})]},Q.id)})]}),h.jsxs("div",{className:"content-card",ref:Ge,children:[_e&&h.jsxs(h.Fragment,{children:[h.jsxs("aside",{className:"section-panel",style:{width:Wl},children:[ee==="prompts"&&h.jsx(oq,{prompts:e,selectedId:Bj,onSelect:Ze,loading:t,error:r,onAddPrompt:()=>we(!0),onRenamePrompt:async(Q,ie)=>{const ke=e.find(ce=>ce.id===Q);if(!ke)return;const Ee=await vH(ke,ie).catch(()=>null);Ee&&(n(),Ze(Hf(Ee.providerId??ke.providerId,`selecting renamed prompt ${Ee.id}`),Ee.id))}}),ee==="traces"&&h.jsx(EK,{listing:s,selectedTraceKey:Pj,onSelect:Q=>xt({type:"trace",providerId:Q.providerId,traceId:Q.id,rootSpanId:"",label:Q.name}),sidebarWidth:Wl,onResizeSidebar:Q=>He.setSize("w",Q),syncing:I.traces}),ee==="datasets"&&h.jsx(TF,{datasets:l,loading:u,error:c,selectedKey:zj,onSelect:Q=>xt({type:"dataset",providerId:Q.providerId,datasetId:Q.id,label:Q.name}),promptName:Q=>{var ie;return(ie=ns(Q))==null?void 0:ie.name},sidebarWidth:Wl,onResizeSidebar:Q=>He.setSize("w",Q),syncing:I.datasets}),ee==="evals"&&h.jsx(RF,{evals:p,loading:g,error:y,selectedKey:$j,onSelect:Q=>xt({type:"eval",providerId:Q.providerId,evalId:Q.id,label:Q.name}),onNew:()=>L({}),promptName:Q=>{var ie;return(ie=hA(e,Q))==null?void 0:ie.name},sidebarWidth:Wl,onResizeSidebar:Q=>He.setSize("w",Q),syncing:I.evals}),ee==="settings"&&h.jsx(cq,{selectedSection:Hj,onSelect:Q=>xt({type:"settings",section:Q})})]}),h.jsx("div",{className:"resize-handle",onMouseDown:He.getOnMouseDown("w",Wl)})]}),W.map((Q,ie)=>{const Ee=ie===W.length-1?void 0:be.sizes[Q.id];return h.jsxs(w.Fragment,{children:[ie>0&&h.jsx("div",{className:"resize-handle",onMouseDown:be.getOnMouseDown(W[ie-1].id,be.sizes[W[ie-1].id]??200)}),h.jsxs("main",{className:"main-content","data-pane":Q.id,style:Ee!==void 0?{width:Ee,flexShrink:0}:{flex:1},onClick:()=>X(Q.id),onDragOver:ce=>ce.preventDefault(),onDrop:()=>{pt.current&&V6(pt.current.paneId,pt.current.key,Q.id)},children:[Q.tabs.length===0&&h.jsx("div",{className:"empty-state",children:h.jsx("img",{src:"/favicon.svg",alt:"",style:{width:96,height:96,opacity:.18}})}),Q.tabs.map(ce=>{const ve=Ht(ce),tt=ve===Q.activeTabKey?{display:"contents"}:{display:"none"};if(ce.type==="welcome")return h.jsx("div",{style:tt,children:h.jsx(c_e,{configured:Te,onCreatePrompt:()=>we(!0),onOpenTerminal:(Ce,Ne,fn,mn)=>bi(Q.id,{kind:"setup",taskId:Ce,stepId:Ne},fn,mn)})},ve);if(ce.type==="terminal")return h.jsx("div",{style:tt,children:h.jsx(jY,{target:ce.target,command:ce.command})},ve);if(ce.type==="settings")return h.jsx("div",{style:tt,children:h.jsx(bq,{section:ce.section})},ve);if(ce.type==="prompt"){const Ce=e.find(Ne=>Ne.id===ce.promptId&&Ne.providerId===ce.providerId)??null;return Ce?h.jsx("div",{style:tt,children:h.jsx(nq,{prompt:Ce,promptRef:ce.ref,onRefChange:Ne=>Ve(ve,Ne),refreshKey:j,onRefresh:n,onUpdate:i,onDirtyChange:Ne=>xe(ve,Ne),onExecuted:Ne=>Oj(Q.id,Ne),fill:ce.fill,onOpenFillSource:Ne=>Dj(Q.id,Ne),onOpenDataset:Ne=>dn(Q.id,{type:"dataset",providerId:Ne.providerId,datasetId:Ne.id,label:Ne.name}),agents:R,onAskAgent:Ne=>rs(Q.id,Ne,{type:"prompt",providerId:ce.providerId,promptId:ce.promptId})})},ve):null}return ce.type==="dataset"?h.jsx("div",{style:tt,children:h.jsx(w.Suspense,{fallback:null,children:h.jsx(k_e,{providerId:ce.providerId,datasetId:ce.datasetId,version:m,findPrompt:ns,prompts:e,onOpenPrompt:Ce=>zr(Q.id,Ce),onOpenInPlayground:(Ce,Ne)=>zr(Q.id,Ce,Ne),onOpenTrace:(Ce,Ne)=>dn(Q.id,X1(Ce,Ne)),onDeleted:()=>zc(ve),onNewEval:L,evals:p,onRunStarted:(Ce,Ne)=>Pr(Q.id,zn(Ce.providerId,Ne,Ce.name)),agents:R,onAskAgent:(Ce,Ne)=>rs(Q.id,Ce,{type:"dataset",providerId:ce.providerId,datasetId:ce.datasetId,...(Ne==null?void 0:Ne.length)&&{rowIds:[...Ne]}})})})},ve):ce.type==="eval"?h.jsx("div",{style:tt,children:h.jsx(w.Suspense,{fallback:null,children:h.jsx(C_e,{providerId:ce.providerId,evalId:ce.evalId,prompts:e,datasets:l,version:v,datasetVersion:m,progress:E,onOpenRun:(Ce,Ne)=>dn(Q.id,zn(ce.providerId,Ce,Ne)),onRunStarted:(Ce,Ne)=>Pr(Q.id,zn(ce.providerId,Ce,Ne)),onOpenPrompt:Ce=>zr(Q.id,Ce),onOpenDataset:Ce=>dn(Q.id,{type:"dataset",providerId:Ce.providerId,datasetId:Ce.id,label:Ce.name}),onDeleted:()=>zc(ve),onDuplicated:Ce=>{b(),Pr(Q.id,{type:"eval",providerId:Ce.providerId,evalId:Ce.id,label:Ce.name},{split:!1})},onRunDeleted:Ce=>zc(Ht({type:"eval-run",providerId:ce.providerId,runId:Ce.id})),agents:R,onAskAgent:Ce=>rs(Q.id,Ce,{type:"eval",providerId:ce.providerId,evalId:ce.evalId})})})},ve):ce.type==="eval-run"?h.jsx("div",{style:tt,children:h.jsx(w.Suspense,{fallback:null,children:h.jsx(T_e,{providerId:ce.providerId,runId:ce.runId,version:v,progress:E[ce.runId],onOpenTrace:(Ce,Ne)=>dn(Q.id,X1(Ce,Ne)),onDeleted:()=>zc(ve)})})},ve):h.jsx("div",{style:tt,children:h.jsx(t_e,{providerId:ce.providerId,traceId:ce.traceId,initialSpanId:ce.rootSpanId||void 0,onOpenPrompt:Ce=>Ea(Q.id,Ce,ce.traceId,ce.providerId),findPrompt:ns,evalVersion:v,onOpenEvalRun:(Ce,Ne,fn)=>dn(Q.id,zn(Ce,Ne,fn)),onDeleted:()=>{zc(ve),o()},projectUrl:Oe,agents:R,onAskAgent:Ce=>rs(Q.id,Ce,{type:"trace",providerId:ce.providerId,traceId:ce.traceId})})},ve)})]})]},Q.id)})]})]})]}),C&&h.jsx(IF,{prompts:e,datasets:l,seed:C,onClose:()=>L(null),onCreated:Q=>{L(null),b(),xt({type:"eval",providerId:Q.providerId,evalId:Q.id,label:Q.name})}}),Be&&h.jsx(ZH,{onClose:()=>we(!1),onCreated:Q=>{we(!1),n(),Ze(Hf(Q.providerId,`selecting created prompt ${Q.id}`),Q.id)}})]})}const z_e=Fz.createRoot(document.getElementById("root"));z_e.render(h.jsx(cB.StrictMode,{children:h.jsx(P_e,{})}));const $_e=Object.freeze(Object.defineProperty({__proto__:null,Mermaid:mj},Symbol.toStringTag,{value:"Module"}));export{rve as $,Cve as A,Eve as B,AA as C,PU as D,o1 as E,FU as F,kve as G,CV as H,kA as I,cve as J,Jd as K,sU as L,bV as M,nve as N,NF as O,a1 as P,qH as Q,wV as R,un as S,Ix as T,iU as U,EH as V,uve as W,FA as X,hV as Y,YH as Z,bve as _,ive as a,xve as a$,bU as a0,bd as a1,J4 as a2,l_ as a3,dV as a4,zU as a5,Gm as a6,dl as a7,Gi as a8,LA as a9,HU as aA,$U as aB,pw as aC,Ki as aD,fq as aE,Kbe as aF,AK as aG,MK as aH,U_e as aI,wve as aJ,Q_e as aK,Ybe as aL,GA as aM,hk as aN,OK as aO,VH as aP,G_e as aQ,J_e as aR,Sve as aS,CA as aT,jK as aU,mF as aV,Zbe as aW,Jbe as aX,dve as aY,fw as aZ,VF as a_,W_e as aa,W4 as ab,cn as ac,cB as ad,lm as ae,wy as af,O as ag,dA as ah,Hh as ai,Gz as aj,Fi as ak,qz as al,yve as am,vve as an,_F as ao,lF as ap,vF as aq,hve as ar,Ss as as,wl as at,SV as au,o_ as av,Qd as aw,nA as ax,BK as ay,mw as az,mve as b,V_e as b0,X_e as b1,K_e as b2,Y_e as b3,Z_e as b4,Xbe as b5,q_e as b6,pve as c,oA as d,ave as e,ks as f,sve as g,zx as h,AF as i,h as j,fo as k,Sl as l,gve as m,ove as n,Rye as o,hge as p,c_ as q,w as r,fve as s,hA as t,eve as u,_ve as v,F_e as w,lve as x,tve as y,Za as z};
701
+ `;function s_e({text:e,multiline:t,children:r}){const[n,i]=w.useState(!1),s=w.useCallback(async()=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)}catch{}},[e]);return h.jsxs("div",{className:`copy-box${t?" copy-box-multiline":""}`,children:[t?h.jsx("pre",{children:e}):h.jsx("span",{className:"copy-box-text",children:r??e}),h.jsx("button",{type:"button",className:"copy-box-btn",onClick:s,title:n?"Copied!":"Copy to clipboard","aria-label":n?"Copied":"Copy to clipboard",children:h.jsx("span",{dangerouslySetInnerHTML:{__html:n?n_e:i_e}})})]})}function a_e({onOpenTerminal:e}){const[t,r]=w.useState([]),[n,i]=w.useState([]),[s,a]=w.useState(null),[o,l]=w.useState(new Set),[u,c]=w.useState(new Set),[d,m]=w.useState(new Set),[f,p]=w.useState({});w.useEffect(()=>{let E=!1;return uH().then(({agent:T,sdk:C})=>{E||(r(T),i(C),a(L=>{var A;return L??((A=C[0])==null?void 0:A.id)??null}))}).catch(()=>{}),()=>{E=!0}},[]),w.useEffect(()=>{const E=T=>{const{stepId:C}=T.detail;m(L=>new Set(L).add(C))};return window.addEventListener(nv,E),()=>window.removeEventListener(nv,E)},[]);const g=n.find(E=>E.id===s),y=(E,T)=>(E.completed||d.has(E.id))&&(E.kind!=="create_config"||T<g.steps.length-1),b=(E,T)=>u.has(E.id)||E.kind==="create_config"&&(E.completed||d.has(E.id))&&T===g.steps.length-1,v=E=>l(T=>{const C=new Set(T);return C.has(E)?C.delete(E):C.add(E),C}),x=async E=>{if(g){c(T=>new Set(T).add(E.id)),p(T=>{const{[E.id]:C,...L}=T;return L});try{await cH(g.id,E.id),m(T=>new Set(T).add(E.id))}catch(T){p(C=>({...C,[E.id]:T.message}))}finally{c(T=>{const C=new Set(T);return C.delete(E.id),C})}}};return h.jsxs("div",{className:"setup-split",children:[h.jsxs("section",{className:"setup-pane",children:[h.jsx("h3",{children:"Set up with a coding agent"}),h.jsxs("div",{className:"setup-sdk-options",role:"group","aria-label":"Coding agent",children:[t.map(E=>{const T=E.steps[0],C=T==null?void 0:T.disabledReason,L=C??`Run ${E.label}`;return h.jsx("span",{className:"setup-agent-option-wrap",title:L,children:h.jsxs("button",{type:"button",className:"setup-sdk-option",disabled:!!C,title:L,onClick:()=>{!T||T.kind==="create_config"||e==null||e(E.id,T.id,iv(T),E.label)},children:[h.jsx("span",{className:"setup-sdk-icon","aria-hidden":"true",children:h.jsx(Fm,{provider:E.icon,size:20})}),h.jsx("span",{children:E.label})]})},E.id)}),h.jsx("a",{className:"setup-sdk-option setup-sdk-option-link",href:EA,target:"_blank",rel:"noopener",children:"Other"})]})]}),h.jsx("div",{className:"setup-divider",children:h.jsx("span",{children:"or set up manually"})}),h.jsxs("section",{className:"setup-pane",children:[h.jsxs("h3",{children:["Manual setup —"," ",h.jsx("a",{className:"welcome-link",href:WF,target:"_blank",rel:"noopener",children:"full docs ↗"})]}),h.jsx("div",{className:"welcome-field",children:h.jsxs("div",{className:"setup-sdk-options",role:"group","aria-label":"AI SDK",children:[n.map(E=>h.jsxs("button",{type:"button",className:`setup-sdk-option${E.id===s?" setup-sdk-option-selected":""}`,"aria-pressed":E.id===s,onClick:()=>a(E.id),children:[h.jsx("span",{className:"setup-sdk-icon","aria-hidden":"true",children:h.jsx(Fm,{provider:E.icon,size:20})}),h.jsx("span",{children:E.label})]},E.id)),h.jsx("a",{className:"setup-sdk-option setup-sdk-option-link",href:XF,target:"_blank",rel:"noopener",children:"Other"})]})}),g&&h.jsx("ol",{className:"setup-steps",children:g.steps.map((E,T)=>h.jsxs("li",{className:`setup-step${y(E,T)?" setup-step-done":""}${b(E,T)?" setup-step-running":""}`,children:[h.jsxs("div",{className:"setup-step-row",children:[h.jsxs("span",{className:"setup-step-label",children:[o_e(E),E.kind==="create_config"&&h.jsx("button",{type:"button",className:"setup-step-expand welcome-link",onClick:()=>v(E.id),children:o.has(E.id)?"Hide":"Show"})]}),h.jsx("span",{className:"setup-step-action",children:l_e(E,{done:y(E,T),running:b(E,T),onCreate:()=>x(E),onRun:()=>{if(E.kind==="create_config"||!g)return;const C=E.kind==="install_package"?`Install ${E.package}`:E.label;e==null||e(g.id,E.id,iv(E),C)}})})]}),E.kind==="create_config"&&o.has(E.id)&&h.jsxs("div",{className:"setup-config-snippet",children:[h.jsx(s_e,{text:E.contents,multiline:!0}),h.jsx("a",{className:"welcome-link setup-config-docs",href:YF,target:"_blank",rel:"noopener",children:"Config docs ↗"})]}),f[E.id]&&h.jsx("div",{className:"setup-file-status setup-file-error",children:f[E.id]})]},E.id))})]})]})}function o_e(e){switch(e.kind){case"create_config":return h.jsxs(h.Fragment,{children:["Create config: ",h.jsx("code",{children:e.path})]});case"install_package":return h.jsxs(h.Fragment,{children:["Install package: ",h.jsx("code",{children:e.package})]});case"run_command":return h.jsxs(h.Fragment,{children:["Run ",h.jsx("code",{children:e.command})]})}}function dk(e,t){return e?h.jsx("span",{className:"setup-step-action-wrap",title:e,children:t}):t}function fk({kind:e}){const t={className:"setup-step-btn-icon",width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0};switch(e){case"create_config":return h.jsxs("svg",{...t,children:[h.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),h.jsx("path",{d:"M14 2v6h6"}),h.jsx("path",{d:"M12 12v6M9 15h6"})]});case"install_package":return h.jsxs("svg",{...t,children:[h.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),h.jsx("path",{d:"M7 10l5 5 5-5"}),h.jsx("path",{d:"M12 15V3"})]});case"run_command":return h.jsx("svg",{...t,children:h.jsx("path",{d:"M6 4l14 8-14 8z",fill:"currentColor",stroke:"none"})})}}function l_e(e,t){if(e.kind==="create_config")return t.done?h.jsx("span",{className:"setup-step-status setup-file-created",children:"Created"}):dk(e.disabledReason,h.jsxs("button",{type:"button",className:"setup-step-btn",onClick:t.onCreate,disabled:t.running||!!e.disabledReason,title:e.disabledReason,children:[h.jsx(fk,{kind:e.kind}),t.running?"Creating…":"Create"]}));if(e.kind==="install_package"&&t.done)return h.jsx("span",{className:"setup-step-status setup-file-created",children:"Installed"});const r=e.disabledReason??iv(e);return dk(e.disabledReason,h.jsxs("button",{type:"button",className:"setup-step-btn",onClick:t.onRun,disabled:!!e.disabledReason,title:r,children:[h.jsx(fk,{kind:e.kind}),e.kind==="install_package"?"Install":"Run"]}))}const Rj="all-set",u_e=[{id:"setup",title:"Set up project",Component:a_e},{id:Rj,title:"You're all set",Component:r_e}];function c_e({onCreatePrompt:e,onOpenTerminal:t,configured:r=!1,steps:n=u_e}){const i=n.findIndex(m=>m.id===Rj),[s,a]=w.useState(r&&i>=0?i:0);w.useEffect(()=>{r&&i>=0&&a(i)},[r,i]);const o=n[s],l=s===0,u=s===n.length-1,c=()=>a(m=>Math.min(m+1,n.length-1)),d=o.Component;return h.jsx("div",{className:"welcome",children:h.jsxs("div",{className:"welcome-card",children:[h.jsxs("header",{className:"welcome-header",children:[h.jsx("img",{className:"welcome-logo",src:"/favicon.svg",width:"36",height:"49",alt:""}),h.jsx("ol",{className:"welcome-progress",children:n.map((m,f)=>{const p=f===s?"active":f<s?"done":"todo",g=f<s&&!!m.canReturn;return h.jsx("li",{className:`welcome-progress-${p}`,children:g?h.jsxs("button",{type:"button",className:"welcome-progress-btn",onClick:()=>a(f),children:[h.jsx("span",{className:"welcome-progress-dot",children:f+1}),h.jsx("span",{className:"welcome-progress-label",children:m.title})]}):h.jsxs(h.Fragment,{children:[n.length>1&&h.jsx("span",{className:"welcome-progress-dot",children:f+1}),h.jsx("span",{className:"welcome-progress-label",children:m.title})]})},m.id)})})]}),h.jsx("div",{className:"welcome-step-body",children:h.jsx(d,{onNext:c,isFirst:l,isLast:u,onCreatePrompt:e,onOpenTerminal:t})})]})})}function h_e(){const[e,t]=w.useState([]),[r,n]=w.useState(!0),[i,s]=w.useState(null),a=w.useCallback(async()=>{try{s(null),t(await eA())}catch(o){s(o.message)}finally{n(!1)}},[]);return w.useEffect(()=>{a()},[a]),{datasets:e,loading:r,error:i,refetch:a}}function d_e(){const[e,t]=w.useState([]),[r,n]=w.useState(!0),[i,s]=w.useState(null),a=w.useCallback(async()=>{try{s(null),t(await WH())}catch(o){s(o.message)}finally{n(!1)}},[]);return w.useEffect(()=>{a()},[a]),{evals:e,loading:r,error:i,refetch:a}}function f_e(){const[e,t]=w.useState([]),[r,n]=w.useState(!0),[i,s]=w.useState(null),a=w.useCallback(async()=>{try{s(null),t(await gH())}catch(l){s(l.message)}finally{n(!1)}},[]);w.useEffect(()=>{a()},[a]);const o=w.useCallback(l=>{t(u=>{let c=!1;const d=u.map(m=>Hh(m,l)?(c=!0,l):m);return c?d:[...u,l]})},[]);return{prompts:e,loading:r,error:i,refetch:a,patchPrompt:o}}const m_e=1e4;function p_e({win:e,doc:t,onFocus:r,minIntervalMs:n=m_e,now:i=Date.now}){let s=Number.NEGATIVE_INFINITY;const a=()=>{i()-s<n||(s=i(),r())},o=()=>{t.visibilityState==="visible"&&a()};return e.addEventListener("focus",a),t.addEventListener("visibilitychange",o),()=>{e.removeEventListener("focus",a),t.removeEventListener("visibilitychange",o)}}function g_e(){w.useEffect(()=>p_e({win:window,doc:document,onFocus:()=>{hH().catch(()=>{})}}),[])}function mk({initial:e,min:t=0,max:r=1/0,direction:n="horizontal",storageKey:i}){const[s,a]=w.useState(()=>{if(i)try{const y=localStorage.getItem(i);if(y){const b=JSON.parse(y);if(b&&typeof b=="object")return b}}catch{}return e}),o=w.useRef(s);o.current=s;const l=y=>{i&&localStorage.setItem(i,JSON.stringify(y))},u=y=>{o.current=y,a(y),l(y)},c=w.useRef(null),d=w.useRef(0),m=w.useRef(0);return w.useEffect(()=>{const y=v=>{if(!c.current)return;const x=n==="horizontal"?v.clientX:v.clientY,E=Math.max(t,Math.min(r,m.current+(x-d.current)));u({...o.current,[c.current]:E})},b=()=>{c.current=null};return window.addEventListener("mousemove",y),window.addEventListener("mouseup",b),()=>{window.removeEventListener("mousemove",y),window.removeEventListener("mouseup",b)}},[n,t,r]),{sizes:s,getOnMouseDown:(y,b)=>v=>{c.current=y,d.current=n==="horizontal"?v.clientX:v.clientY,m.current=b,v.preventDefault()},setSize:(y,b)=>u({...o.current,[y]:b}),deleteSize:y=>{const{[y]:b,...v}=o.current;u(v)}}}const b_e=[1e3,2e3,5e3,1e4,3e4],__e=6e4;function v_e({onMessage:e,onOpen:t,retryDelaysMs:r=b_e,doc:n=typeof document>"u"?void 0:document,hiddenGraceMs:i=__e}){let s,a,o,l=0,u=!1;const c=()=>{const p=new EventSource("/api/events");s=p,p.onopen=()=>{l=0,t==null||t()},p.onmessage=g=>{try{e(JSON.parse(g.data))}catch(y){console.error("Failed to parse SSE message:",y)}},p.onerror=g=>{p.readyState===EventSource.CLOSED&&(console.error("SSE connection closed; reconnecting:",g),f())}},d=()=>{a!==void 0&&clearTimeout(a),a=void 0,l=0,s==null||s.close(),s=void 0},m=()=>{if(!(u||!n)){if(n.visibilityState==="hidden"){o??(o=setTimeout(()=>{o=void 0,d()},i));return}o!==void 0&&clearTimeout(o),o=void 0,s||c()}},f=()=>{if(u||a!==void 0)return;const p=r[Math.min(l,r.length-1)]??1e3;l+=1,a=setTimeout(()=>{a=void 0,!u&&(s==null||s.close(),c())},p)};return(n==null?void 0:n.visibilityState)!=="hidden"&&c(),n==null||n.addEventListener("visibilitychange",m),()=>{u=!0,n==null||n.removeEventListener("visibilitychange",m),o!==void 0&&clearTimeout(o),d()}}function y_e(e,t){w.useEffect(()=>v_e({onMessage:e,onOpen:t}),[e,t])}const x_e={list:MH,groups:OH},Lj="trace-list-grouping";function S_e(){try{const e=localStorage.getItem(Lj);if(e)return PY(JSON.parse(e))}catch{}return YN.grouping}const pk=()=>Intl.DateTimeFormat().resolvedOptions().timeZone,ub=e=>[...e].sort((t,r)=>r.startTime-t.startTime);function w_e(e=x_e){const[t,r]=w.useState(()=>({...YN,grouping:S_e()})),[n,i]=w.useState([]),[s,a]=w.useState(),[o,l]=w.useState({}),[u,c]=w.useState(!0),[d,m]=w.useState(null),f=w.useRef(t),p=w.useRef(e);p.current=e;const g=w.useRef(o);g.current=o;const y=w.useRef(new Set),b=w.useRef(0),v=w.useCallback(async()=>{const C=++b.current,{search:L,filters:A,grouping:z}=f.current,I=p.current;try{if(typeof z=="string"){const B=ub(await I.list({search:L,filters:A}));if(C!==b.current)return;i(B),a(void 0),l({})}else{const B=await I.groups({search:L,filters:A,groupBy:z,timeZone:pk()}),j=B.filter(W=>g.current[W.key]),G=await Promise.all(j.map(W=>I.list({search:L,filters:[...A,W.filter]})));if(C!==b.current)return;a(B),l(Object.fromEntries(j.map((W,Y)=>[W.key,ub(G[Y])])))}m(null)}catch(B){C===b.current&&m(B.message)}finally{C===b.current&&c(!1)}},[]),x=w.useCallback(C=>{f.current=C,g.current={},y.current.clear(),l({}),r(C);try{localStorage.setItem(Lj,JSON.stringify(C.grouping))}catch{}v()},[v]),E=w.useCallback(C=>{const{key:L}=C;if(g.current[L]||y.current.has(L))return;y.current.add(L);const A=f.current;p.current.list({search:A.search,filters:[...A.filters,C.filter]}).then(z=>{f.current===A&&l(I=>({...I,[L]:ub(z)}))}).catch(()=>{}).finally(()=>{f.current===A&&y.current.delete(L)})},[]),T=w.useCallback(C=>{const{search:L,filters:A}=f.current;return p.current.groups({search:L,filters:A.filter(z=>z.column!==C),groupBy:{column:C},timeZone:pk()})},[]);return w.useEffect(()=>{v()},[v]),{traces:n,groups:s,members:o,loadGroup:E,facets:T,view:t,setView:x,loading:u,error:d,refetch:v}}function E_e(e,t,r,n,i,s){var m,f;const a=n(r),o=e.find(p=>p.tabs.some(g=>n(g)===a));if(o)return{panes:e.map(p=>p.id===o.id?{...p,tabs:i.replace?p.tabs.map(g=>n(g)===a?r:g):p.tabs,activeTabKey:a}:p),focusId:o.id,flashId:o.id};const l=e.findIndex(p=>p.id===t);if(l<0)return{panes:e,focusId:t};let u=t,c=e,d;if(i.split){const p=((m=e[l+1])==null?void 0:m.id)??((f=e[l-1])==null?void 0:f.id);p?u=p:(u=s(),c=[...e],c.splice(l+1,0,{id:u,tabs:[],activeTabKey:null}),d=t)}return{panes:c.map(p=>p.id===u?{...p,tabs:[...p.tabs,r],activeTabKey:a}:p),focusId:u,...d&&{splitFrom:d}}}function k_e(e){return{traces:e.some(t=>t.kind==="traces"),evals:e.some(t=>t.kind==="evals"),datasets:new Set(e.flatMap(t=>t.kind==="dataset"&&t.key?[Za({providerId:t.provider,id:t.key})]:[]))}}const C_e=w.lazy(()=>O(()=>import("./DatasetView-dWZOCEO1.js").then(e=>e.D),__vite__mapDeps([101,102]))),T_e=w.lazy(()=>O(()=>import("./EvalView-By5XAZnh.js"),[])),A_e=w.lazy(()=>O(()=>import("./EvalRunView-Cm1YhpbN.js"),[])),Ij="welcome",Ht=e=>e.type==="prompt"?`prompt:${e.providerId}:${e.promptId}`:e.type==="trace"?`trace:${e.providerId}:${e.traceId}`:e.type==="dataset"?`dataset:${e.providerId}:${e.datasetId}`:e.type==="eval"?`eval:${e.providerId}:${e.evalId}`:e.type==="eval-run"?`eval-run:${e.providerId}:${e.runId}`:e.type==="terminal"?`terminal:${e.id}`:e.type==="settings"?`settings:${e.section}`:Ij;let N_e=0,R_e=0;const Sy=()=>`pane${++R_e}`,gk=Sy(),L_e=1200;function bk(e){const t=document.querySelector(`[data-pane="${CSS.escape(e)}"]`);t&&(t.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}),t.classList.remove("pane-flash"),t.offsetWidth,t.classList.add("pane-flash"),window.setTimeout(()=>t.classList.remove("pane-flash"),L_e))}function I_e(){return h.jsx("img",{src:"/favicon.svg",width:"22",height:"30",alt:"evalution logo",style:{display:"block"}})}function _k(){return h.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("line",{x1:"4",y1:"6",x2:"14",y2:"6"}),h.jsx("line",{x1:"8",y1:"12",x2:"20",y2:"12"}),h.jsx("line",{x1:"6",y1:"18",x2:"16",y2:"18"})]})}function D_e(){return h.jsx(o1,{size:20})}function O_e(){return h.jsx(Jd,{size:20})}function M_e(){return h.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),h.jsx("polyline",{points:"14 2 14 8 20 8"}),h.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),h.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),h.jsx("line",{x1:"10",y1:"9",x2:"8",y2:"9"})]})}function vk(){return h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("circle",{cx:"12",cy:"12",r:"3"}),h.jsx("path",{d:"M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 11-2.83 2.83l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 11-2.83-2.83l.06-.06a1.65 1.65 0 00.33-1.82 1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 112.83-2.83l.06.06a1.65 1.65 0 001.82.33H9a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 112.83 2.83l-.06.06a1.65 1.65 0 00-.33 1.82V9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"})]})}function j_e(){return h.jsx("span",{className:"welcome-tab-emoji",role:"img","aria-label":"Welcome",children:"👋"})}function B_e(){return h.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("polyline",{points:"4 17 10 11 4 5"}),h.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function P_e(){return h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),h.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]})}function z_e(){const{prompts:e,loading:t,error:r,refetch:n,patchPrompt:i}=f_e(),s=w_e(),{traces:a,refetch:o}=s,{datasets:l,loading:u,error:c,refetch:d}=h_e(),[m,f]=w.useState(0),{evals:p,loading:g,error:y,refetch:b}=d_e(),[v,x]=w.useState(0),[E,T]=w.useState({}),[C,L]=w.useState(null),[A,z]=w.useState([]),I=w.useMemo(()=>k_e(A),[A]),B=w.useCallback(()=>{dH().then(z).catch(()=>{})},[]),[j,G]=w.useState(0),[W,Y]=w.useState([{id:gk,tabs:[],activeTabKey:null}]),[V,X]=w.useState(gk),[P,re]=w.useState(""),[R,de]=w.useState([]),[Te,H]=w.useState(!1),[Oe,Pe]=w.useState(),[ee,oe]=w.useState("prompts"),[Be,we]=w.useState(!1),[_e,je]=w.useState(()=>new URLSearchParams(window.location.search).get("expand")!=="true"),[Ke,Le]=w.useState(null),[it,zt]=w.useState(new Set),ot=w.useRef(new Set),Br=w.useRef(null),Fe=w.useRef(!1),He=mk({initial:{w:224},min:120,max:600,storageKey:"sidebar-width"}),be=mk({initial:{},min:150,storageKey:"pane-widths"}),Ge=w.useRef(null),ht=w.useRef(!1);w.useEffect(()=>{const Q=ie=>{ht.current=ie.metaKey||ie.ctrlKey};return window.addEventListener("pointerdown",Q,!0),window.addEventListener("click",Q,!0),()=>{window.removeEventListener("pointerdown",Q,!0),window.removeEventListener("click",Q,!0)}},[]);const pt=w.useRef(null),Qe=w.useCallback(()=>{fetch("/api/config",{cache:"no-store"}).then(Q=>Q.json()).then(Q=>{re(Q.rootPath),H(!!Q.configured),Pe(Q.projectUrl??void 0)}).catch(()=>{})},[]);w.useEffect(()=>{Qe()},[Qe]),w.useEffect(()=>{fH().then(de).catch(()=>{})},[]);const hn=w.useCallback(Q=>{if(Q.type==="sync-status")z(Q.adopting);else if(Q.type==="prompt-changed"){if(r$(Q.event.type,Q.providerId,Q.event.promptId))return;n(),G(ie=>ie+1)}else if(Q.type==="trace-changed")o();else if(Q.type==="dataset-changed")d(),f(ie=>ie+1);else if(Q.type==="views-changed")xy();else if(Q.type==="eval-changed")b(),x(ie=>ie+1);else if(Q.type==="eval-run"){o();const{type:ie,...ke}=Q;T(Ee=>{if(ke.status==="running")return{...Ee,[ke.runId]:ke};const{[ke.runId]:ce,...ve}=Ee;return ve})}},[n,o,d,b]),te=w.useCallback(()=>{Qe(),B(),n(),o(),d(),b(),xy()},[Qe,B,n,o,d,b]);y_e(hn,te),g_e(),w.useEffect(()=>{if(t)return;const Q=new Set(e.map(ie=>`${ie.providerId}:${ie.id}`));Y(ie=>ie.map(ke=>{const Ee=ke.tabs.filter(ve=>ve.type!=="prompt"||Q.has(`${ve.providerId}:${ve.promptId}`));if(Ee.length===ke.tabs.length)return ke;const ce=Ee.some(ve=>Ht(ve)===ke.activeTabKey);return{...ke,tabs:Ee,activeTabKey:ce?ke.activeTabKey:Ee.at(-1)?Ht(Ee.at(-1)):null}}))},[e,t]),w.useEffect(()=>{if(t)return;Y(ie=>{const ke=ie.some(Ee=>Ee.tabs.some(ce=>ce.type==="welcome"));return e.length===0?ke?ie:ie.map((Ee,ce)=>ce===0?{...Ee,tabs:[{type:"welcome"},...Ee.tabs],activeTabKey:Ij}:Ee):ke?ie.map(Ee=>{const ce=Ee.tabs.filter(tt=>tt.type!=="welcome"),ve=ce.some(tt=>Ht(tt)===Ee.activeTabKey);return{...Ee,tabs:ce,activeTabKey:ve?Ee.activeTabKey:ce.at(-1)?Ht(ce.at(-1)):null}}):ie});const Q=Br.current;e.length===0?je(!1):Q===0&&je(!0),Br.current=e.length},[t,e.length]);const xe=w.useCallback((Q,ie)=>{zt(ke=>{const Ee=lH(ke,Q,ie);return ot.current=Ee,Ee})},[]);w.useEffect(()=>{const Q=ie=>{ot.current.size>0&&(ie.preventDefault(),ie.returnValue="")};return window.addEventListener("beforeunload",Q),()=>window.removeEventListener("beforeunload",Q)},[]);const Ve=w.useCallback((Q,ie)=>{Y(ke=>ke.map(Ee=>Ee.tabs.some(ce=>Ht(ce)===Q)?{...Ee,tabs:Ee.tabs.map(ce=>{if(Ht(ce)!==Q||ce.type!=="prompt")return ce;const{ref:ve,...tt}=ce;return ie?{...tt,ref:ie}:tt})}:Ee))},[]),Ze=(Q,ie)=>{const ke={type:"prompt",providerId:Q,promptId:ie},Ee=Ht(ke);Y(ce=>ce.map(ve=>ve.id!==V?ve:{...ve,tabs:ve.tabs.some(tt=>Ht(tt)===Ee)?ve.tabs:[...ve.tabs,ke],activeTabKey:Ee}))};w.useEffect(()=>{if(t||Fe.current)return;const Q=new URLSearchParams(window.location.search).get("prompt"),ie=Q?e.find(ke=>ke.id===Q):void 0;ie!=null&&ie.providerId&&Ze(ie.providerId,ie.id),Fe.current=!0},[t,e]),w.useEffect(()=>{const Q=DK(window.location.search);Q&&xt({type:"trace",providerId:Q.providerId,traceId:Q.traceId,rootSpanId:"",label:"Trace"})},[]);const xt=Q=>{const ie=Ht(Q);Y(ke=>{const Ee=ke.find(ce=>ce.tabs.some(ve=>Ht(ve)===ie));return Ee?(X(Ee.id),bk(Ee.id),ke.map(ce=>ce.id===Ee.id?{...ce,activeTabKey:ie}:ce)):ke.map(ce=>ce.id!==V?ce:{...ce,tabs:[...ce.tabs,Q],activeTabKey:ie})})},Pr=(Q,ie,{replace:ke=!1,split:Ee=!0}={})=>{Y(ce=>{var tt;const ve=E_e(ce,Q,ie,Ht,{replace:ke,split:Ee},Sy);if(ve.panes===ce)return ce;if(ve.splitFrom){const Ce=(tt=Ge.current)==null?void 0:tt.querySelector(`[data-pane="${ve.splitFrom}"]`),Ne=(Ce==null?void 0:Ce.getBoundingClientRect().width)??400;be.setSize(ve.splitFrom,Math.max(200,Math.floor(Ne/2)))}return X(ve.focusId),ve.flashId&&bk(ve.flashId),ve.panes})},dn=(Q,ie,ke=!1)=>Pr(Q,ie,{replace:ke,split:ht.current}),bi=(Q,ie,ke,Ee)=>{const ce={type:"terminal",id:`t${++N_e}`,target:ie,command:ke,label:Ee??ke};Pr(Q,ce)},rs=async(Q,ie,ke)=>{try{const Ee=await mH(ie.id,ke);bi(Q,{kind:"agent",agentId:ie.id,context:ke},Ee,ie.label)}catch(Ee){console.error(`Couldn't launch ${ie.label}:`,Ee)}},ns=Q=>e.find(ie=>Hh(ie,Q)),zr=(Q,ie,ke,Ee)=>{const ve={type:"prompt",providerId:Hf(ie.providerId,`opening prompt ${ie.id}`),promptId:ie.id,...ke&&{fill:ke},...Ee&&{ref:Ee}};dn(Q,ve,!!ke||!!Ee)},Ea=(Q,ie,ke,Ee)=>{const ce=ns(ie),ve=ce&&_A(ie)?VF(bA(ie,ce),ce,{type:"trace",description:`trace ${ke.slice(0,8)}…`,providerId:Ee,traceId:ke},ie.resources):void 0,tt=ie.variation?{promptId:ie.id,variation:ie.variation}:ie.version?{promptId:ie.id,version:ie.version}:void 0;zr(Q,{id:ie.id,providerId:ie.providerId},ve,tt)},zn=(Q,ie,ke)=>({type:"eval-run",providerId:Q,runId:ie.id,label:`${ke} · ${ks(ie.startedAt)}`}),X1=(Q,ie)=>{var ke;return{type:"trace",providerId:Q,traceId:ie,rootSpanId:"",label:((ke=a.find(Ee=>Ee.id===ie&&Ee.providerId===Q))==null?void 0:ke.name)??`trace ${ie.slice(0,8)}…`}},Dj=(Q,ie)=>dn(Q,ie.type==="trace"?X1(ie.providerId,ie.traceId):{type:"dataset",providerId:ie.providerId,datasetId:ie.datasetId,label:ie.name}),zc=Q=>{for(const ie of W)ie.tabs.some(ke=>Ht(ke)===Q)&&U6(ie.id,Q)},Oj=(Q,ie)=>{const{tracerProviderId:ke,traceId:Ee,rootSpanId:ce,label:ve}=ie;Pr(Q,{type:"trace",providerId:ke,traceId:Ee,rootSpanId:ce,label:ve})},U6=(Q,ie)=>{xe(ie,!1),Y(ke=>{const Ee=ke.find(Ne=>Ne.id===Q),ce=Ee.tabs.filter(Ne=>Ht(Ne)!==ie);if(ce.length===0&&ke.length>1){const Ne=ke.filter(mn=>mn.id!==Q),fn=ke.findIndex(mn=>mn.id===Q);return X(Ne[Math.min(fn,Ne.length-1)].id),be.deleteSize(Q),Ne}const ve=Ee.tabs.findIndex(Ne=>Ht(Ne)===ie),tt=ce[Math.min(ve,ce.length-1)],Ce=Ee.activeTabKey===ie?tt?Ht(tt):null:Ee.activeTabKey;return ke.map(Ne=>Ne.id===Q?{...Ne,tabs:ce,activeTabKey:Ce}:Ne)})},Mj=(Q,ie,ke)=>{ke.stopPropagation(),U6(Q,ie)},jj=Q=>{var ve;const ie=Sy(),ke=(ve=Ge.current)==null?void 0:ve.querySelector(`[data-pane="${Q}"]`),Ee=(ke==null?void 0:ke.getBoundingClientRect().width)??400,ce=Math.max(200,Math.floor(Ee/2));be.setSize(Q,ce),Y(tt=>{const Ce=tt.findIndex(fn=>fn.id===Q),Ne=[...tt];return Ne.splice(Ce+1,0,{id:ie,tabs:[],activeTabKey:null}),Ne}),X(ie)},V6=(Q,ie,ke)=>{Q!==ke&&(Y(Ee=>{const ce=Ee.find(Ce=>Ce.id===Q),ve=ce.tabs.find(Ce=>Ht(Ce)===ie);if(!ve)return Ee;const tt=ce.tabs.filter(Ce=>Ht(Ce)!==ie);return tt.length===0&&Ee.length>1?(be.deleteSize(Q),Ee.filter(Ne=>Ne.id!==Q).map(Ne=>{if(Ne.id===ke){const fn=Ne.tabs.some(mn=>Ht(mn)===ie);return{...Ne,tabs:fn?Ne.tabs:[...Ne.tabs,ve],activeTabKey:ie}}return Ne})):Ee.map(Ce=>{if(Ce.id===Q){const Ne=Ce.activeTabKey===ie,fn=Ce.tabs.findIndex(mn=>Ht(mn)===ie);return{...Ce,tabs:tt,activeTabKey:Ne?tt[Math.min(fn,tt.length-1)]?Ht(tt[Math.min(fn,tt.length-1)]):null:Ce.activeTabKey}}if(Ce.id===ke){const Ne=Ce.tabs.some(fn=>Ht(fn)===ie);return{...Ce,tabs:Ne?Ce.tabs:[...Ce.tabs,ve],activeTabKey:ie}}return Ce})}),X(ke))},q6="~/Library/Mobile Documents/com~apple~CloudDocs",Q1=P.replace(/^\/Users\/[^/]+/,"~"),w0=Q1.startsWith(q6),Gl=w0?Q1.slice(q6.length)||"/":Q1,G6=w0?`iCloud Drive${Gl!=="/"?Gl:""}`:Gl;w.useEffect(()=>{P&&(document.title=G6)},[G6,P]);const E0=W.find(Q=>Q.id===V)??W[0],Zt=(E0==null?void 0:E0.tabs.find(Q=>Ht(Q)===E0.activeTabKey))??null,Bj=(Zt==null?void 0:Zt.type)==="prompt"?Zt.promptId:null,Pj=(Zt==null?void 0:Zt.type)==="trace"?`${Zt.providerId}:${Zt.traceId}`:null,zj=(Zt==null?void 0:Zt.type)==="dataset"?Za({providerId:Zt.providerId,id:Zt.datasetId}):null,$j=(Zt==null?void 0:Zt.type)==="eval"?lA({providerId:Zt.providerId,id:Zt.evalId}):null,Hj=(Zt==null?void 0:Zt.type)==="settings"?Zt.section:null,Wl=He.sizes.w;return h.jsxs("div",{className:"app",children:[h.jsxs("div",{className:"app-titlebar",children:[h.jsx("div",{className:"app-titlebar-icon",children:h.jsx(I_e,{})}),P&&_e&&h.jsxs("span",{className:"header-path",children:[w0&&h.jsx("svg",{className:"icloud-icon",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:h.jsx("path",{d:"M18 10h-1.26A8 8 0 109 20h9a5 5 0 000-10z"})}),w0&&h.jsx("span",{children:"iCloud Drive"}),Gl&&Gl!=="/"&&Gl]})]}),h.jsxs("div",{className:"app-main",children:[h.jsxs("div",{className:"icon-strip",children:[h.jsxs("nav",{className:"icon-nav",children:[h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="prompts"&&_e?"active":""}`,onClick:()=>{ee==="prompts"&&_e?je(!1):(oe("prompts"),je(!0))},title:"Prompts",children:h.jsx(M_e,{})}),h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="traces"&&_e?"active":""}`,onClick:()=>{ee==="traces"&&_e?je(!1):(oe("traces"),je(!0))},title:"Traces",children:h.jsx(_k,{})}),h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="datasets"&&_e?"active":""}`,onClick:()=>{ee==="datasets"&&_e?je(!1):(oe("datasets"),je(!0))},title:"Datasets",children:h.jsx(O_e,{})}),h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="evals"&&_e?"active":""}`,onClick:()=>{ee==="evals"&&_e?je(!1):(oe("evals"),je(!0))},title:"Evals",children:h.jsx(D_e,{})})]}),h.jsx("nav",{className:"icon-nav-bottom",children:h.jsx("button",{type:"button",className:`icon-nav-btn ${ee==="settings"&&_e?"active":""}`,onClick:()=>{ee==="settings"&&_e?je(!1):(oe("settings"),je(!0))},title:"Settings",children:h.jsx(vk,{})})})]}),h.jsxs("div",{className:"content-area",children:[h.jsxs("div",{className:"content-header",children:[h.jsx("div",{className:"content-header-spacer",style:{width:_e?Wl+4:14}}),W.map((Q,ie)=>{const Ee=ie===W.length-1?void 0:be.sizes[Q.id],ce=!_e&&ie===0?14:0;return h.jsxs(w.Fragment,{children:[ie>0&&h.jsx("div",{className:"pane-resize-divider",onMouseDown:be.getOnMouseDown(W[ie-1].id,be.sizes[W[ie-1].id]??200)}),h.jsxs("div",{className:`pane-tabbar${Q.id===Ke?" pane-drop-target":""}`,style:Ee!==void 0?{width:Ee-ce,flexShrink:0}:{flex:1},onDragOver:ve=>{ve.preventDefault(),Le(Q.id)},onDragLeave:ve=>{ve.currentTarget.contains(ve.relatedTarget)||Le(null)},onDrop:()=>{Le(null),pt.current&&V6(pt.current.paneId,pt.current.key,Q.id)},children:[h.jsx("div",{className:"pane-tabs-scroll",children:Q.tabs.map(ve=>{const tt=Ht(ve),Ce=ve.type==="prompt"?e.find(mn=>mn.id===ve.promptId&&mn.providerId===ve.providerId):void 0,Ne=ve.type==="prompt"?(Ce==null?void 0:Ce.name)??ve.promptId:ve.type==="trace"||ve.type==="dataset"||ve.type==="eval"||ve.type==="eval-run"||ve.type==="terminal"?ve.label:ve.type==="settings"?nN(ve.section):"Welcome",fn=ve.type==="trace"?h.jsx(_k,{}):ve.type==="dataset"?h.jsx(Jd,{size:14}):ve.type==="eval"||ve.type==="eval-run"?h.jsx(o1,{size:14}):ve.type==="welcome"?h.jsx(j_e,{}):ve.type==="terminal"?h.jsx(B_e,{}):ve.type==="settings"?h.jsx(vk,{}):void 0;return h.jsx(vq,{name:Ne,icon:fn,active:tt===Q.activeTabKey,dirty:it.has(tt)||!!(Ce!=null&&Ce.dirty),onClick:()=>{X(Q.id),Y(mn=>mn.map(Z1=>Z1.id===Q.id?{...Z1,activeTabKey:tt}:Z1))},onClose:mn=>Mj(Q.id,tt,mn),onDragStart:()=>{pt.current={paneId:Q.id,key:tt}},onDragEnd:()=>{pt.current=null}},tt)})}),h.jsx("button",{type:"button",className:"tab-split-btn",onClick:()=>jj(Q.id),title:"Split pane",children:h.jsx(P_e,{})})]})]},Q.id)})]}),h.jsxs("div",{className:"content-card",ref:Ge,children:[_e&&h.jsxs(h.Fragment,{children:[h.jsxs("aside",{className:"section-panel",style:{width:Wl},children:[ee==="prompts"&&h.jsx(oq,{prompts:e,selectedId:Bj,onSelect:Ze,loading:t,error:r,onAddPrompt:()=>we(!0),onRenamePrompt:async(Q,ie)=>{const ke=e.find(ce=>ce.id===Q);if(!ke)return;const Ee=await vH(ke,ie).catch(()=>null);Ee&&(n(),Ze(Hf(Ee.providerId??ke.providerId,`selecting renamed prompt ${Ee.id}`),Ee.id))}}),ee==="traces"&&h.jsx(EK,{listing:s,selectedTraceKey:Pj,onSelect:Q=>xt({type:"trace",providerId:Q.providerId,traceId:Q.id,rootSpanId:"",label:Q.name}),sidebarWidth:Wl,onResizeSidebar:Q=>He.setSize("w",Q),syncing:I.traces}),ee==="datasets"&&h.jsx(TF,{datasets:l,loading:u,error:c,selectedKey:zj,onSelect:Q=>xt({type:"dataset",providerId:Q.providerId,datasetId:Q.id,label:Q.name}),promptName:Q=>{var ie;return(ie=ns(Q))==null?void 0:ie.name},sidebarWidth:Wl,onResizeSidebar:Q=>He.setSize("w",Q),syncing:I.datasets}),ee==="evals"&&h.jsx(RF,{evals:p,loading:g,error:y,selectedKey:$j,onSelect:Q=>xt({type:"eval",providerId:Q.providerId,evalId:Q.id,label:Q.name}),onNew:()=>L({}),promptName:Q=>{var ie;return(ie=hA(e,Q))==null?void 0:ie.name},sidebarWidth:Wl,onResizeSidebar:Q=>He.setSize("w",Q),syncing:I.evals}),ee==="settings"&&h.jsx(cq,{selectedSection:Hj,onSelect:Q=>xt({type:"settings",section:Q})})]}),h.jsx("div",{className:"resize-handle",onMouseDown:He.getOnMouseDown("w",Wl)})]}),W.map((Q,ie)=>{const Ee=ie===W.length-1?void 0:be.sizes[Q.id];return h.jsxs(w.Fragment,{children:[ie>0&&h.jsx("div",{className:"resize-handle",onMouseDown:be.getOnMouseDown(W[ie-1].id,be.sizes[W[ie-1].id]??200)}),h.jsxs("main",{className:"main-content","data-pane":Q.id,style:Ee!==void 0?{width:Ee,flexShrink:0}:{flex:1},onClick:()=>X(Q.id),onDragOver:ce=>ce.preventDefault(),onDrop:()=>{pt.current&&V6(pt.current.paneId,pt.current.key,Q.id)},children:[Q.tabs.length===0&&h.jsx("div",{className:"empty-state",children:h.jsx("img",{src:"/favicon.svg",alt:"",style:{width:96,height:96,opacity:.18}})}),Q.tabs.map(ce=>{const ve=Ht(ce),tt=ve===Q.activeTabKey?{display:"contents"}:{display:"none"};if(ce.type==="welcome")return h.jsx("div",{style:tt,children:h.jsx(c_e,{configured:Te,onCreatePrompt:()=>we(!0),onOpenTerminal:(Ce,Ne,fn,mn)=>bi(Q.id,{kind:"setup",taskId:Ce,stepId:Ne},fn,mn)})},ve);if(ce.type==="terminal")return h.jsx("div",{style:tt,children:h.jsx(jY,{target:ce.target,command:ce.command})},ve);if(ce.type==="settings")return h.jsx("div",{style:tt,children:h.jsx(bq,{section:ce.section})},ve);if(ce.type==="prompt"){const Ce=e.find(Ne=>Ne.id===ce.promptId&&Ne.providerId===ce.providerId)??null;return Ce?h.jsx("div",{style:tt,children:h.jsx(nq,{prompt:Ce,promptRef:ce.ref,onRefChange:Ne=>Ve(ve,Ne),refreshKey:j,onRefresh:n,onUpdate:i,onDirtyChange:Ne=>xe(ve,Ne),onExecuted:Ne=>Oj(Q.id,Ne),fill:ce.fill,onOpenFillSource:Ne=>Dj(Q.id,Ne),onOpenDataset:Ne=>dn(Q.id,{type:"dataset",providerId:Ne.providerId,datasetId:Ne.id,label:Ne.name}),agents:R,onAskAgent:Ne=>rs(Q.id,Ne,{type:"prompt",providerId:ce.providerId,promptId:ce.promptId})})},ve):null}return ce.type==="dataset"?h.jsx("div",{style:tt,children:h.jsx(w.Suspense,{fallback:null,children:h.jsx(C_e,{providerId:ce.providerId,datasetId:ce.datasetId,version:m,findPrompt:ns,prompts:e,onOpenPrompt:Ce=>zr(Q.id,Ce),onOpenInPlayground:(Ce,Ne)=>zr(Q.id,Ce,Ne),onOpenTrace:(Ce,Ne)=>dn(Q.id,X1(Ce,Ne)),onDeleted:()=>zc(ve),onNewEval:L,evals:p,onRunStarted:(Ce,Ne)=>Pr(Q.id,zn(Ce.providerId,Ne,Ce.name)),agents:R,onAskAgent:(Ce,Ne)=>rs(Q.id,Ce,{type:"dataset",providerId:ce.providerId,datasetId:ce.datasetId,...(Ne==null?void 0:Ne.length)&&{rowIds:[...Ne]}})})})},ve):ce.type==="eval"?h.jsx("div",{style:tt,children:h.jsx(w.Suspense,{fallback:null,children:h.jsx(T_e,{providerId:ce.providerId,evalId:ce.evalId,prompts:e,datasets:l,version:v,datasetVersion:m,progress:E,onOpenRun:(Ce,Ne)=>dn(Q.id,zn(ce.providerId,Ce,Ne)),onRunStarted:(Ce,Ne)=>Pr(Q.id,zn(ce.providerId,Ce,Ne)),onOpenPrompt:Ce=>zr(Q.id,Ce),onOpenDataset:Ce=>dn(Q.id,{type:"dataset",providerId:Ce.providerId,datasetId:Ce.id,label:Ce.name}),onDeleted:()=>zc(ve),onDuplicated:Ce=>{b(),Pr(Q.id,{type:"eval",providerId:Ce.providerId,evalId:Ce.id,label:Ce.name},{split:!1})},onRunDeleted:Ce=>zc(Ht({type:"eval-run",providerId:ce.providerId,runId:Ce.id})),agents:R,onAskAgent:Ce=>rs(Q.id,Ce,{type:"eval",providerId:ce.providerId,evalId:ce.evalId})})})},ve):ce.type==="eval-run"?h.jsx("div",{style:tt,children:h.jsx(w.Suspense,{fallback:null,children:h.jsx(A_e,{providerId:ce.providerId,runId:ce.runId,version:v,progress:E[ce.runId],onOpenTrace:(Ce,Ne)=>dn(Q.id,X1(Ce,Ne)),onDeleted:()=>zc(ve)})})},ve):h.jsx("div",{style:tt,children:h.jsx(t_e,{providerId:ce.providerId,traceId:ce.traceId,initialSpanId:ce.rootSpanId||void 0,onOpenPrompt:Ce=>Ea(Q.id,Ce,ce.traceId,ce.providerId),findPrompt:ns,evalVersion:v,onOpenEvalRun:(Ce,Ne,fn)=>dn(Q.id,zn(Ce,Ne,fn)),onDeleted:()=>{zc(ve),o()},projectUrl:Oe,agents:R,onAskAgent:Ce=>rs(Q.id,Ce,{type:"trace",providerId:ce.providerId,traceId:ce.traceId})})},ve)})]})]},Q.id)})]})]})]}),C&&h.jsx(IF,{prompts:e,datasets:l,seed:C,onClose:()=>L(null),onCreated:Q=>{L(null),b(),xt({type:"eval",providerId:Q.providerId,evalId:Q.id,label:Q.name})}}),Be&&h.jsx(ZH,{onClose:()=>we(!1),onCreated:Q=>{we(!1),n(),Ze(Hf(Q.providerId,`selecting created prompt ${Q.id}`),Q.id)}})]})}const $_e=Fz.createRoot(document.getElementById("root"));$_e.render(h.jsx(cB.StrictMode,{children:h.jsx(z_e,{})}));const H_e=Object.freeze(Object.defineProperty({__proto__:null,Mermaid:mj},Symbol.toStringTag,{value:"Module"}));export{nve as $,Tve as A,kve as B,AA as C,PU as D,o1 as E,FU as F,Cve as G,CV as H,kA as I,hve as J,Jd as K,sU as L,bV as M,ive as N,NF as O,a1 as P,qH as Q,wV as R,un as S,Ix as T,iU as U,EH as V,cve as W,FA as X,hV as Y,YH as Z,_ve as _,sve as a,Sve as a$,bU as a0,bd as a1,J4 as a2,l_ as a3,dV as a4,zU as a5,Gm as a6,dl as a7,Gi as a8,LA as a9,HU as aA,$U as aB,pw as aC,Ki as aD,fq as aE,Kbe as aF,AK as aG,MK as aH,V_e as aI,Eve as aJ,Z_e as aK,Ybe as aL,GA as aM,hk as aN,OK as aO,VH as aP,W_e as aQ,eve as aR,wve as aS,CA as aT,jK as aU,mF as aV,Zbe as aW,Jbe as aX,fve as aY,fw as aZ,VF as a_,Y_e as aa,W4 as ab,cn as ac,cB as ad,lm as ae,wy as af,O as ag,dA as ah,Hh as ai,Gz as aj,Fi as ak,qz as al,xve as am,yve as an,_F as ao,lF as ap,vF as aq,dve as ar,Ss as as,wl as at,SV as au,o_ as av,Qd as aw,nA as ax,BK as ay,mw as az,pve as b,q_e as b0,Q_e as b1,X_e as b2,K_e as b3,J_e as b4,Xbe as b5,G_e as b6,gve as c,oA as d,ove as e,ks as f,ave as g,zx as h,AF as i,h as j,fo as k,Sl as l,bve as m,lve as n,Lye as o,hge as p,c_ as q,w as r,mve as s,hA as t,tve as u,vve as v,U_e as w,uve as x,rve as y,Za as z};