pmx-canvas 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/Readme.md +25 -11
- package/dist/canvas/global.css +123 -40
- package/dist/canvas/index.js +84 -84
- package/dist/json-render/index.js +55 -55
- package/dist/types/client/canvas/ChoiceMenu.d.ts +13 -0
- package/dist/types/client/nodes/McpAppNode.d.ts +2 -1
- package/dist/types/client/nodes/viewer-runtime-state.d.ts +1 -0
- package/dist/types/client/state/canvas-store.d.ts +2 -0
- package/dist/types/client/state/intent-bridge.d.ts +1 -1
- package/dist/types/json-render/renderer/index.d.ts +2 -1
- package/dist/types/json-render/server.d.ts +2 -0
- package/dist/types/shared/ax-surface-protocol.d.ts +2 -0
- package/docs/ax-host-adapter-contract.md +13 -2
- package/package.json +1 -1
- package/skills/pmx-canvas/SKILL.md +23 -11
- package/skills/pmx-canvas/evals/evals.json +69 -0
- package/skills/pmx-canvas/references/full-reference.md +3 -3
- package/skills/pmx-canvas/references/installing-pmx-canvas.md +76 -4
- package/skills/pmx-canvas-testing/SKILL.md +49 -0
- package/src/client/canvas/CanvasNode.tsx +200 -195
- package/src/client/canvas/CanvasViewport.tsx +6 -0
- package/src/client/canvas/ChoiceMenu.tsx +122 -0
- package/src/client/canvas/CommandBar.tsx +25 -23
- package/src/client/canvas/FeedbackDialog.tsx +10 -8
- package/src/client/canvas/ToolRail.tsx +46 -99
- package/src/client/nodes/McpAppNode.tsx +16 -0
- package/src/client/nodes/use-ax-surface-bridge.ts +4 -2
- package/src/client/nodes/viewer-runtime-state.ts +78 -0
- package/src/client/state/canvas-store.ts +3 -0
- package/src/client/state/intent-bridge.ts +14 -2
- package/src/client/theme/global.css +123 -40
- package/src/json-render/renderer/index.tsx +58 -38
- package/src/json-render/server.ts +8 -1
- package/src/server/server.ts +3 -1
- package/src/shared/ax-surface-protocol.ts +3 -0
package/dist/canvas/index.js
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
var
|
|
1
|
+
var ck=Object.create;var{getPrototypeOf:lk,defineProperty:$p,getOwnPropertyNames:uk}=Object;var Mp=Object.prototype.hasOwnProperty;function dk(e){return this[e]}var pk,mk,fk=(e,t,n)=>{var o=e!=null&&typeof e==="object";if(o){var r=t?pk??=new WeakMap:mk??=new WeakMap,s=r.get(e);if(s)return s}n=e!=null?ck(lk(e)):{};let a=t||!e||!e.__esModule||!Mp.call(e,"default")?$p(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let c of uk(e))if(!Mp.call(a,c))$p(a,c,{get:dk.bind(e,c),enumerable:!0})}if(o)r.set(e,a);return a};var hk=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Tb=hk(function(Cb){Object.defineProperty(Cb,"__esModule",{value:!0});var db=/highlight-(?:text|source)-([a-z0-9]+)/;function mb(e){e.addRule("highlightedCodeBlock",{filter:function(t){var n=t.firstChild;return t.nodeName==="DIV"&&db.test(t.className)&&n&&n.nodeName==="PRE"},replacement:function(t,n,o){var r=n.className||"",s=(r.match(db)||[null,""])[1];return`
|
|
2
2
|
|
|
3
3
|
`+o.fence+s+`
|
|
4
4
|
`+n.firstChild.textContent+`
|
|
5
5
|
`+o.fence+`
|
|
6
6
|
|
|
7
|
-
`}})}function
|
|
7
|
+
`}})}function fb(e){e.addRule("strikethrough",{filter:["del","s","strike"],replacement:function(t){return"~~"+t+"~~"}})}var EC=Array.prototype.indexOf,AC=Array.prototype.every,to={},zC={left:":---",right:"---:",center:":---:"},Ou=null,hb=null,pb=new WeakMap;function PC(e){return e?(e.getAttribute("align")||e.style.textAlign||"").toLowerCase():""}function gb(e){return e?zC[e]:"---"}function vb(e,t){var n={left:0,right:0,center:0,"":0},o="";for(var r=0;r<e.rows.length;++r){var s=e.rows[r];if(t<s.childNodes.length){var a=PC(s.childNodes[t]);if(++n[a],n[a]>n[o])o=a}}return o}to.tableCell={filter:["th","td"],replacement:function(e,t){if(Fu(wb(t)))return e;return yb(e,t)}};to.tableRow={filter:"tr",replacement:function(e,t){let n=wb(t);if(Fu(n))return e;var o="";if(NC(t)){let a=_b(n);for(var r=0;r<a;r++){let c=r<t.childNodes.length?t.childNodes[r]:null;var s=gb(vb(n,r));o+=yb(s,c,r)}}return`
|
|
8
8
|
`+e+(o?`
|
|
9
|
-
`+o:"")}};to.table={filter:function(e,t){return e.nodeName==="TABLE"},replacement:function(e,t){if(
|
|
9
|
+
`+o:"")}};to.table={filter:function(e,t){return e.nodeName==="TABLE"},replacement:function(e,t){if(xb(t,hb)){let c=t.outerHTML,l=MC(t);if(l===null||!l.classList.contains("joplin-table-wrapper"))return`
|
|
10
10
|
|
|
11
11
|
<div class="joplin-table-wrapper">${c}</div>
|
|
12
12
|
|
|
13
|
-
`;else return c}else{if(
|
|
13
|
+
`;else return c}else{if(Fu(t))return e;e=e.replace(/\n+/g,`
|
|
14
14
|
`);var n=e.trim().split(`
|
|
15
|
-
`);if(n.length>=2)n=n[1];var o=/\| :?---/.test(n),r=
|
|
16
|
-
|`;for(var a=0;a<r;++a)s+=" "+
|
|
15
|
+
`);if(n.length>=2)n=n[1];var o=/\| :?---/.test(n),r=_b(t),s="";if(r&&!o){s="|"+" |".repeat(r)+`
|
|
16
|
+
|`;for(var a=0;a<r;++a)s+=" "+gb(vb(t,a))+" |"}let c=t.caption?t.caption.textContent||"":"",l=c?`${c}
|
|
17
17
|
|
|
18
18
|
`:"",u=`${s}${e}`.trimStart();return`
|
|
19
19
|
|
|
20
20
|
${l}${u}
|
|
21
21
|
|
|
22
|
-
`}}};to.tableCaption={filter:["caption"],replacement:()=>""};to.tableColgroup={filter:["colgroup","col"],replacement:()=>""};to.tableSection={filter:["thead","tbody","tfoot"],replacement:function(e){return e}};function IC(e){var t=e.parentNode;return t.nodeName==="THEAD"||t.firstChild===e&&(t.nodeName==="TABLE"||EC(t))&&kC.call(e.childNodes,function(n){return n.nodeName==="TH"})}function EC(e){var t=e.previousSibling;return e.nodeName==="TBODY"&&(!t||t.nodeName==="THEAD"&&/^\s*$/i.test(t.textContent))}function gb(e,t=null,n=null){if(n===null)n=SC.call(t.parentNode.childNodes,t);var o=" ";if(n===0)o="| ";let r=e.trim().replace(/\n\r/g,"<br>").replace(/\n/g,"<br>");r=r.replace(/\|+/g,"\\|");while(r.length<3)r+=" ";if(t)r=PC(r,t," ");return o+r+" |"}function vb(e){if(!e.childNodes)return!1;for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(n.nodeName==="TABLE")return!0;if(vb(n))return!0}return!1}var Bu=(e,t)=>{if(!e.childNodes)return!1;for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];if(t==="code"&&Fu&&Fu(o))return!0;if(t.includes(o.nodeName))return!0;if(Bu(o,t))return!0}return!1},yb=(e,t)=>{let n=["UL","OL","H1","H2","H3","H4","H5","H6","HR","BLOCKQUOTE"];if(t.preserveNestedTables)n.push("TABLE");return Bu(e,"code")||Bu(e,n)};function Hu(e){let t=ub.get(e);if(t!==void 0)return t;let n=AC(e);return ub.set(e,n),n}function AC(e){if(!e)return!0;if(!e.rows)return!0;if(e.rows.length===1&&e.rows[0].childNodes.length<=1)return!0;if(vb(e))return!0;return!1}function zC(e){let t=e.parentNode;while(t.nodeName!=="DIV")if(t=t.parentNode,!t)return null;return t}function bb(e){let t=e.parentNode;while(t.nodeName!=="TABLE")if(t=t.parentNode,!t)return null;return t}function PC(e,t,n){let o=t.getAttribute("colspan")||1;for(let r=1;r<o;r++)e+=" | "+n.repeat(3);return e}function xb(e){let t=0;for(let n=0;n<e.rows.length;n++){let r=e.rows[n].childNodes.length;if(r>t)t=r}return t}function wb(e){Fu=e.isCodeBlock,mb=e.options,e.keep(function(n){if(n.nodeName==="TABLE"&&yb(n,e.options))return!0;return!1});for(var t in to)e.addRule(t,to[t])}function _b(e){e.addRule("taskListItems",{filter:function(t){let n=t.parentNode,o=n.parentNode;return t.type==="checkbox"&&(n.nodeName==="LI"||n.nodeName==="LABEL"&&o&&o.nodeName==="LI")},replacement:function(t,n){return(n.checked?"[x]":"[ ]")+" "}})}function NC(e){e.use([db,pb,wb,_b])}Sb.gfm=NC;Sb.highlightedCodeBlock=db;Sb.strikethrough=pb;Sb.tables=wb;Sb.taskListItems=_b});if(typeof crypto<"u"&&typeof crypto.randomUUID!=="function")crypto.randomUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e)=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)});var as,_e,Hp,tl,Fn,Lp,jp,Zp,Up,nl,Yc,Qc,pS,rs={},is=[],mS=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,cs=Array.isArray;function hn(e,t){for(var n in t)e[n]=t[n];return e}function ol(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function fS(e,t,n){var o,r,s,a={};for(s in t)s=="key"?o=t[s]:s=="ref"?r=t[s]:a[s]=t[s];if(arguments.length>2&&(a.children=arguments.length>3?as.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)a[s]===void 0&&(a[s]=e.defaultProps[s]);return os(e,a,o,r,null)}function os(e,t,n,o,r){var s={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:r==null?++Hp:r,__i:-1,__u:0};return r==null&&_e.vnode!=null&&_e.vnode(s),s}function pe(e){return e.children}function Go(e,t){this.props=e,this.context=t}function Xo(e,t){if(t==null)return e.__?Xo(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?Xo(e):null}function hS(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,o=[],r=[],s=hn({},t);s.__v=t.__v+1,_e.vnode&&_e.vnode(s),rl(e.__P,s,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,o,n==null?Xo(t):n,!!(32&t.__u),r),s.__v=t.__v,s.__.__k[s.__i]=s,Gp(o,s,r),t.__e=t.__=null,s.__e!=n&&qp(s)}}function qp(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),qp(e)}function Dp(e){(!e.__d&&(e.__d=!0)&&Fn.push(e)&&!ss.__r++||Lp!=_e.debounceRendering)&&((Lp=_e.debounceRendering)||jp)(ss)}function ss(){try{for(var e,t=1;Fn.length;)Fn.length>t&&Fn.sort(Zp),e=Fn.shift(),t=Fn.length,hS(e)}finally{Fn.length=ss.__r=0}}function Wp(e,t,n,o,r,s,a,c,l,u,p){var d,f,m,h,v,x,g,y=o&&o.__k||is,E=t.length;for(l=gS(n,t,y,l,E),d=0;d<E;d++)(m=n.__k[d])!=null&&(f=m.__i!=-1&&y[m.__i]||rs,m.__i=d,x=rl(e,m,f,r,s,a,c,l,u,p),h=m.__e,m.ref&&f.ref!=m.ref&&(f.ref&&il(f.ref,null,m),p.push(m.ref,m.__c||h,m)),v==null&&h!=null&&(v=h),(g=!!(4&m.__u))||f.__k===m.__k?l=Vp(m,l,e,g):typeof m.type=="function"&&x!==void 0?l=x:h&&(l=h.nextSibling),m.__u&=-7);return n.__e=v,l}function gS(e,t,n,o,r){var s,a,c,l,u,p=n.length,d=p,f=0;for(e.__k=Array(r),s=0;s<r;s++)(a=t[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=e.__k[s]=os(null,a,null,null,null):cs(a)?a=e.__k[s]=os(pe,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=e.__k[s]=os(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):e.__k[s]=a,l=s+f,a.__=e,a.__b=e.__b+1,c=null,(u=a.__i=vS(a,n,l,d))!=-1&&(d--,(c=n[u])&&(c.__u|=2)),c==null||c.__v==null?(u==-1&&(r>p?f--:r<p&&f++),typeof a.type!="function"&&(a.__u|=4)):u!=l&&(u==l-1?f--:u==l+1?f++:(u>l?f--:f++,a.__u|=4))):e.__k[s]=null;if(d)for(s=0;s<p;s++)(c=n[s])!=null&&(2&c.__u)==0&&(c.__e==o&&(o=Xo(c)),Jp(c,c));return o}function Vp(e,t,n,o){var r,s;if(typeof e.type=="function"){for(r=e.__k,s=0;r&&s<r.length;s++)r[s]&&(r[s].__=e,t=Vp(r[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=Xo(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function vS(e,t,n,o){var r,s,a,{key:c,type:l}=e,u=t[n],p=u!=null&&(2&u.__u)==0;if(u===null&&c==null||p&&c==u.key&&l==u.type)return n;if(o>(p?1:0)){for(r=n-1,s=n+1;r>=0||s<t.length;)if((u=t[a=r>=0?r--:s++])!=null&&(2&u.__u)==0&&c==u.key&&l==u.type)return a}return-1}function Fp(e,t,n){t[0]=="-"?e.setProperty(t,n==null?"":n):e[t]=n==null?"":typeof n!="number"||mS.test(t)?n:n+"px"}function ns(e,t,n,o,r){var s,a;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||Fp(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||Fp(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Up,"$1")),a=t.toLowerCase(),t=a in e||t=="onFocusOut"||t=="onFocusIn"?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+s]=n,n?o?n.u=o.u:(n.u=nl,e.addEventListener(t,s?Qc:Yc,s)):e.removeEventListener(t,s?Qc:Yc,s);else{if(r=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n==null?"":n;break e}catch(c){}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function Bp(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=nl++;else if(t.t<n.u)return;return n(_e.event?_e.event(t):t)}}}function rl(e,t,n,o,r,s,a,c,l,u){var p,d,f,m,h,v,x,g,y,E,L,P,b,T,w,_=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),s=[c=t.__e=n.__e]),(p=_e.__b)&&p(t);e:if(typeof _=="function")try{if(g=t.props,y=_.prototype&&_.prototype.render,E=(p=_.contextType)&&o[p.__c],L=p?E?E.props.value:p.__:o,n.__c?x=(d=t.__c=n.__c).__=d.__E:(y?t.__c=d=new _(g,L):(t.__c=d=new Go(g,L),d.constructor=_,d.render=bS),E&&E.sub(d),d.state||(d.state={}),d.__n=o,f=d.__d=!0,d.__h=[],d._sb=[]),y&&d.__s==null&&(d.__s=d.state),y&&_.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=hn({},d.__s)),hn(d.__s,_.getDerivedStateFromProps(g,d.__s))),m=d.props,h=d.state,d.__v=t,f)y&&_.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),y&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(y&&_.getDerivedStateFromProps==null&&g!==m&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(g,L),t.__v==n.__v||!d.__e&&d.shouldComponentUpdate!=null&&d.shouldComponentUpdate(g,d.__s,L)===!1){t.__v!=n.__v&&(d.props=g,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(z){z&&(z.__=t)}),is.push.apply(d.__h,d._sb),d._sb=[],d.__h.length&&a.push(d);break e}d.componentWillUpdate!=null&&d.componentWillUpdate(g,d.__s,L),y&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(m,h,v)})}if(d.context=L,d.props=g,d.__P=e,d.__e=!1,P=_e.__r,b=0,y)d.state=d.__s,d.__d=!1,P&&P(t),p=d.render(d.props,d.state,d.context),is.push.apply(d.__h,d._sb),d._sb=[];else do d.__d=!1,P&&P(t),p=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++b<25);d.state=d.__s,d.getChildContext!=null&&(o=hn(hn({},o),d.getChildContext())),y&&!f&&d.getSnapshotBeforeUpdate!=null&&(v=d.getSnapshotBeforeUpdate(m,h)),T=p!=null&&p.type===pe&&p.key==null?Xp(p.props.children):p,c=Wp(e,cs(T)?T:[T],t,n,o,r,s,a,c,l,u),d.base=t.__e,t.__u&=-161,d.__h.length&&a.push(d),x&&(d.__E=d.__=null)}catch(z){if(t.__v=null,l||s!=null)if(z.then){for(t.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;s[s.indexOf(c)]=null,t.__e=c}else{for(w=s.length;w--;)ol(s[w]);el(t)}else t.__e=n.__e,t.__k=n.__k,z.then||el(t);_e.__e(z,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=yS(n.__e,t,n,o,r,s,a,l,u);return(p=_e.diffed)&&p(t),128&t.__u?void 0:c}function el(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(el))}function Gp(e,t,n){for(var o=0;o<n.length;o++)il(n[o],n[++o],n[++o]);_e.__c&&_e.__c(t,e),e.some(function(r){try{e=r.__h,r.__h=[],e.some(function(s){s.call(r)})}catch(s){_e.__e(s,r.__v)}})}function Xp(e){return typeof e!="object"||e==null||e.__b>0?e:cs(e)?e.map(Xp):hn({},e)}function yS(e,t,n,o,r,s,a,c,l){var u,p,d,f,m,h,v,x=n.props||rs,{props:g,type:y}=t;if(y=="svg"?r="http://www.w3.org/2000/svg":y=="math"?r="http://www.w3.org/1998/Math/MathML":r||(r="http://www.w3.org/1999/xhtml"),s!=null){for(u=0;u<s.length;u++)if((m=s[u])&&"setAttribute"in m==!!y&&(y?m.localName==y:m.nodeType==3)){e=m,s[u]=null;break}}if(e==null){if(y==null)return document.createTextNode(g);e=document.createElementNS(r,y,g.is&&g),c&&(_e.__m&&_e.__m(t,s),c=!1),s=null}if(y==null)x===g||c&&e.data==g||(e.data=g);else{if(s=s&&as.call(e.childNodes),!c&&s!=null)for(x={},u=0;u<e.attributes.length;u++)x[(m=e.attributes[u]).name]=m.value;for(u in x)m=x[u],u=="dangerouslySetInnerHTML"?d=m:u=="children"||(u in g)||u=="value"&&("defaultValue"in g)||u=="checked"&&("defaultChecked"in g)||ns(e,u,null,m,r);for(u in g)m=g[u],u=="children"?f=m:u=="dangerouslySetInnerHTML"?p=m:u=="value"?h=m:u=="checked"?v=m:c&&typeof m!="function"||x[u]===m||ns(e,u,m,x[u],r);if(p)c||d&&(p.__html==d.__html||p.__html==e.innerHTML)||(e.innerHTML=p.__html),t.__k=[];else if(d&&(e.innerHTML=""),Wp(t.type=="template"?e.content:e,cs(f)?f:[f],t,n,o,y=="foreignObject"?"http://www.w3.org/1999/xhtml":r,s,a,s?s[0]:n.__k&&Xo(n,0),c,l),s!=null)for(u=s.length;u--;)ol(s[u]);c||(u="value",y=="progress"&&h==null?e.removeAttribute("value"):h!=null&&(h!==e[u]||y=="progress"&&!h||y=="option"&&h!=x[u])&&ns(e,u,h,x[u],r),u="checked",v!=null&&v!=e[u]&&ns(e,u,v,x[u],r))}return e}function il(e,t,n){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(r){_e.__e(r,n)}}function Jp(e,t,n){var o,r;if(_e.unmount&&_e.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||il(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){_e.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(r=0;r<o.length;r++)o[r]&&Jp(o[r],t,n||typeof e.type!="function");n||ol(e.__e),e.__c=e.__=e.__e=void 0}function bS(e,t,n){return this.constructor(e,n)}function Jr(e,t,n){var o,r,s,a;t==document&&(t=document.documentElement),_e.__&&_e.__(e,t),r=(o=typeof n=="function")?null:n&&n.__k||t.__k,s=[],a=[],rl(t,e=(!o&&n||t).__k=fS(pe,null,[e]),r||rs,rs,t.namespaceURI,!o&&n?[n]:r?null:t.firstChild?as.call(t.childNodes):null,s,!o&&n?n:r?r.__e:t.firstChild,o,a),Gp(s,e,a)}as=is.slice,_e={__e:function(e,t,n,o){for(var r,s,a;t=t.__;)if((r=t.__c)&&!r.__)try{if((s=r.constructor)&&s.getDerivedStateFromError!=null&&(r.setState(s.getDerivedStateFromError(e)),a=r.__d),r.componentDidCatch!=null&&(r.componentDidCatch(e,o||{}),a=r.__d),a)return r.__E=r}catch(c){e=c}throw e}},Hp=0,tl=function(e){return e!=null&&e.constructor===void 0},Go.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=hn({},this.state),typeof e=="function"&&(e=e(hn({},n),this.props)),e&&hn(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Dp(this))},Go.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Dp(this))},Go.prototype.render=pe,Fn=[],jp=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Zp=function(e,t){return e.__v.__b-t.__v.__b},ss.__r=0,Up=/(PointerCapture)$|Capture$/i,nl=0,Yc=Bp(!1),Qc=Bp(!0),pS=0;var Jo,Je,sl,Kp,Kr=0,im=[],Ye=_e,{__b:Yp,__r:Qp,diffed:em,__c:tm,unmount:nm,__:om}=Ye;function us(e,t){Ye.__h&&Ye.__h(Je,e,Kr||t),Kr=0;var n=Je.__H||(Je.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function I(e){return Kr=1,xS(sm,e)}function xS(e,t,n){var o=us(Jo++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):sm(void 0,t),function(c){var l=o.__N?o.__N[0]:o.__[0],u=o.t(l,c);l!==u&&(o.__N=[u,o.__[1]],o.__c.setState({}))}],o.__c=Je,!Je.__f)){var r=function(c,l,u){if(!o.__c.__H)return!0;var p=o.__c.__H.__.filter(function(f){return f.__c});if(p.every(function(f){return!f.__N}))return!s||s.call(this,c,l,u);var d=o.__c.props!==c;return p.some(function(f){if(f.__N){var m=f.__[0];f.__=f.__N,f.__N=void 0,m!==f.__[0]&&(d=!0)}}),s&&s.call(this,c,l,u)||d};Je.__f=!0;var s=Je.shouldComponentUpdate,a=Je.componentWillUpdate;Je.componentWillUpdate=function(c,l,u){if(this.__e){var p=s;s=void 0,r(c,l,u),s=p}a&&a.call(this,c,l,u)},Je.shouldComponentUpdate=r}return o.__N||o.__}function B(e,t){var n=us(Jo++,3);!Ye.__s&&cl(n.__H,t)&&(n.__=e,n.u=t,Je.__H.__h.push(n))}function Bn(e,t){var n=us(Jo++,4);!Ye.__s&&cl(n.__H,t)&&(n.__=e,n.u=t,Je.__h.push(n))}function R(e){return Kr=5,Ie(function(){return{current:e}},[])}function Ie(e,t){var n=us(Jo++,7);return cl(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function H(e,t){return Kr=8,Ie(function(){return e},t)}function wS(){for(var e;e=im.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(ls),t.__h.some(al),t.__h=[]}catch(n){t.__h=[],Ye.__e(n,e.__v)}}}Ye.__b=function(e){Je=null,Yp&&Yp(e)},Ye.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),om&&om(e,t)},Ye.__r=function(e){Qp&&Qp(e),Jo=0;var t=(Je=e.__c).__H;t&&(sl===Je?(t.__h=[],Je.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(ls),t.__h.some(al),t.__h=[],Jo=0)),sl=Je},Ye.diffed=function(e){em&&em(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(im.push(t)!==1&&Kp===Ye.requestAnimationFrame||((Kp=Ye.requestAnimationFrame)||_S)(wS)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),sl=Je=null},Ye.__c=function(e,t){t.some(function(n){try{n.__h.some(ls),n.__h=n.__h.filter(function(o){return!o.__||al(o)})}catch(o){t.some(function(r){r.__h&&(r.__h=[])}),t=[],Ye.__e(o,n.__v)}}),tm&&tm(e,t)},Ye.unmount=function(e){nm&&nm(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{ls(o)}catch(r){t=r}}),n.__H=void 0,t&&Ye.__e(t,n.__v))};var rm=typeof requestAnimationFrame=="function";function _S(e){var t,n=function(){clearTimeout(o),rm&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);rm&&(t=requestAnimationFrame(n))}function ls(e){var t=Je,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),Je=t}function al(e){var t=Je;e.__c=e.__(),Je=t}function cl(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function sm(e,t){return typeof t=="function"?t(e):t}var Nz=Object.freeze({status:"aborted"});function O(e,t,n){function o(c,l){if(!c._zod)Object.defineProperty(c,"_zod",{value:{def:l,constr:a,traits:new Set},enumerable:!1});if(c._zod.traits.has(e))return;c._zod.traits.add(e),t(c,l);let u=a.prototype,p=Object.keys(u);for(let d=0;d<p.length;d++){let f=p[d];if(!(f in c))c[f]=u[f].bind(c)}}let r=n?.Parent??Object;class s extends r{}Object.defineProperty(s,"name",{value:e});function a(c){var l;let u=n?.Parent?new s:this;o(u,c),(l=u._zod).deferred??(l.deferred=[]);for(let p of u._zod.deferred)p();return u}return Object.defineProperty(a,"init",{value:o}),Object.defineProperty(a,Symbol.hasInstance,{value:(c)=>{if(n?.Parent&&c instanceof n.Parent)return!0;return c?._zod?.traits?.has(e)}}),Object.defineProperty(a,"name",{value:e}),a}var Rz=Symbol("zod_brand");class gn extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Yr extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}var ds={};function jt(e){if(e)Object.assign(ds,e);return ds}function ms(e){let t=Object.values(e).filter((o)=>typeof o==="number");return Object.entries(e).filter(([o,r])=>t.indexOf(+o)===-1).map(([o,r])=>r)}function ul(e,t="|"){return e.map((n)=>fl(n)).join(t)}function Qr(e,t){if(typeof t==="bigint")return t.toString();return t}function ei(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw Error("cached value already set")}}}function fs(e){return e===null||e===void 0}function hs(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function cm(e,t){let n=(e.toString().split(".")[1]||"").length,o=t.toString(),r=(o.split(".")[1]||"").length;if(r===0&&/\d?e-\d?/.test(o)){let l=o.match(/\d?e-(\d?)/);if(l?.[1])r=Number.parseInt(l[1])}let s=n>r?n:r,a=Number.parseInt(e.toFixed(s).replace(".","")),c=Number.parseInt(t.toFixed(s).replace(".",""));return a%c/10**s}var am=Symbol("evaluating");function Se(e,t,n){let o=void 0;Object.defineProperty(e,t,{get(){if(o===am)return;if(o===void 0)o=am,o=n();return o},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function xo(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Hn(...e){let t={};for(let n of e){let o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function dl(e){return JSON.stringify(e)}function lm(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var pl="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Ko(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var um=ei(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function wo(e){if(Ko(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;if(typeof t!=="function")return!0;let n=t.prototype;if(Ko(n)===!1)return!1;if(Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)return!1;return!0}function ml(e){if(wo(e))return{...e};if(Array.isArray(e))return[...e];return e}var dm=new Set(["string","number","symbol"]);function jn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function cn(e,t,n){let o=new e._zod.constr(t??e._zod.def);if(!t||n?.parent)o._zod.parent=e;return o}function G(e){let t=e;if(!t)return{};if(typeof t==="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function fl(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function pm(e){return Object.keys(e).filter((t)=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var mm={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function SS(e,t){let n=e._zod.def,o=n.checks;if(o&&o.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let s=Hn(e._zod.def,{get shape(){let a={};for(let c in t){if(!(c in n.shape))throw Error(`Unrecognized key: "${c}"`);if(!t[c])continue;a[c]=n.shape[c]}return xo(this,"shape",a),a},checks:[]});return cn(e,s)}function kS(e,t){let n=e._zod.def,o=n.checks;if(o&&o.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let s=Hn(e._zod.def,{get shape(){let a={...e._zod.def.shape};for(let c in t){if(!(c in n.shape))throw Error(`Unrecognized key: "${c}"`);if(!t[c])continue;delete a[c]}return xo(this,"shape",a),a},checks:[]});return cn(e,s)}function CS(e,t){if(!wo(t))throw Error("Invalid input to extend: expected a plain object");let n=e._zod.def.checks;if(n&&n.length>0){let s=e._zod.def.shape;for(let a in t)if(Object.getOwnPropertyDescriptor(s,a)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}let r=Hn(e._zod.def,{get shape(){let s={...e._zod.def.shape,...t};return xo(this,"shape",s),s}});return cn(e,r)}function TS(e,t){if(!wo(t))throw Error("Invalid input to safeExtend: expected a plain object");let n=Hn(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t};return xo(this,"shape",o),o}});return cn(e,n)}function IS(e,t){let n=Hn(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t._zod.def.shape};return xo(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return cn(e,n)}function ES(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(".partial() cannot be used on object schemas containing refinements");let a=Hn(t._zod.def,{get shape(){let c=t._zod.def.shape,l={...c};if(n)for(let u in n){if(!(u in c))throw Error(`Unrecognized key: "${u}"`);if(!n[u])continue;l[u]=e?new e({type:"optional",innerType:c[u]}):c[u]}else for(let u in c)l[u]=e?new e({type:"optional",innerType:c[u]}):c[u];return xo(this,"shape",l),l},checks:[]});return cn(t,a)}function AS(e,t,n){let o=Hn(t._zod.def,{get shape(){let r=t._zod.def.shape,s={...r};if(n)for(let a in n){if(!(a in s))throw Error(`Unrecognized key: "${a}"`);if(!n[a])continue;s[a]=new e({type:"nonoptional",innerType:r[a]})}else for(let a in r)s[a]=new e({type:"nonoptional",innerType:r[a]});return xo(this,"shape",s),s}});return cn(t,o)}function _o(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Zn(e,t){return t.map((n)=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function ps(e){return typeof e==="string"?e:e?.message}function ln(e,t,n){let o={...e,path:e.path??[]};if(!e.message){let r=ps(e.inst?._zod.def?.error?.(e))??ps(t?.error?.(e))??ps(n.customError?.(e))??ps(n.localeError?.(e))??"Invalid input";o.message=r}if(delete o.inst,delete o.continue,!t?.reportInput)delete o.input;return o}function gs(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function fm(e){let t=typeof e;switch(t){case"number":return Number.isNaN(e)?"nan":"number";case"object":{if(e===null)return"null";if(Array.isArray(e))return"array";let n=e;if(n&&Object.getPrototypeOf(n)!==Object.prototype&&"constructor"in n&&n.constructor)return n.constructor.name}}return t}function So(...e){let[t,n,o]=e;if(typeof t==="string")return{message:t,code:"custom",input:n,inst:o};return{...t}}var hm=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Qr,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},vs=O("$ZodError",hm),hl=O("$ZodError",hm,{Parent:Error});function gm(e,t=(n)=>n.message){let n={},o=[];for(let r of e.issues)if(r.path.length>0)n[r.path[0]]=n[r.path[0]]||[],n[r.path[0]].push(t(r));else o.push(t(r));return{formErrors:o,fieldErrors:n}}function vm(e,t=(n)=>n.message){let n={_errors:[]},o=(r)=>{for(let s of r.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map((a)=>o({issues:a}));else if(s.code==="invalid_key")o({issues:s.issues});else if(s.code==="invalid_element")o({issues:s.issues});else if(s.path.length===0)n._errors.push(t(s));else{let a=n,c=0;while(c<s.path.length){let l=s.path[c];if(c!==s.path.length-1)a[l]=a[l]||{_errors:[]};else a[l]=a[l]||{_errors:[]},a[l]._errors.push(t(s));a=a[l],c++}}};return o(e),n}var ys=(e)=>(t,n,o,r)=>{let s=o?Object.assign(o,{async:!1}):{async:!1},a=t._zod.run({value:n,issues:[]},s);if(a instanceof Promise)throw new gn;if(a.issues.length){let c=new(r?.Err??e)(a.issues.map((l)=>ln(l,s,jt())));throw pl(c,r?.callee),c}return a.value};var bs=(e)=>async(t,n,o,r)=>{let s=o?Object.assign(o,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},s);if(a instanceof Promise)a=await a;if(a.issues.length){let c=new(r?.Err??e)(a.issues.map((l)=>ln(l,s,jt())));throw pl(c,r?.callee),c}return a.value};var ti=(e)=>(t,n,o)=>{let r=o?{...o,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},r);if(s instanceof Promise)throw new gn;return s.issues.length?{success:!1,error:new(e??vs)(s.issues.map((a)=>ln(a,r,jt())))}:{success:!0,data:s.value}},ni=ti(hl),oi=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{async:!0}):{async:!0},s=t._zod.run({value:n,issues:[]},r);if(s instanceof Promise)s=await s;return s.issues.length?{success:!1,error:new e(s.issues.map((a)=>ln(a,r,jt())))}:{success:!0,data:s.value}},xs=oi(hl),ym=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ys(e)(t,n,r)};var bm=(e)=>(t,n,o)=>ys(e)(t,n,o);var xm=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return bs(e)(t,n,r)};var wm=(e)=>async(t,n,o)=>bs(e)(t,n,o);var _m=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ti(e)(t,n,r)};var Sm=(e)=>(t,n,o)=>ti(e)(t,n,o);var km=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return oi(e)(t,n,r)};var Cm=(e)=>async(t,n,o)=>oi(e)(t,n,o);var Tm=/^[cC][^\s-]{8,}$/,Im=/^[0-9a-z]+$/,Em=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Am=/^[0-9a-vA-V]{20}$/,zm=/^[A-Za-z0-9]{27}$/,Pm=/^[a-zA-Z0-9_-]{21}$/,Nm=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Rm=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,gl=(e)=>{if(!e)return/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)};var $m=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var PS="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Mm(){return new RegExp(PS,"u")}var Om=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Lm=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;var Dm=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Fm=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Bm=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,vl=/^[A-Za-z0-9_-]*$/;var Hm=/^\+[1-9]\d{6,14}$/,jm="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Zm=new RegExp(`^${jm}$`);function Um(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function qm(e){return new RegExp(`^${Um(e)}$`)}function Wm(e){let t=Um({precision:e.precision}),n=["Z"];if(e.local)n.push("");if(e.offset)n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let o=`${t}(?:${n.join("|")})`;return new RegExp(`^${jm}T(?:${o})$`)}var Vm=(e)=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var Gm=/^-?\d+$/,yl=/^-?\d+(?:\.\d+)?$/,Xm=/^(?:true|false)$/i,Jm=/^null$/i;var Km=/^undefined$/i;var Ym=/^[^A-Z]*$/,Qm=/^[^a-z]*$/;var lt=O("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),ef={number:"number",bigint:"bigint",object:"date"},bl=O("$ZodCheckLessThan",(e,t)=>{lt.init(e,t);let n=ef[typeof t.value];e._zod.onattach.push((o)=>{let r=o._zod.bag,s=(t.inclusive?r.maximum:r.exclusiveMaximum)??Number.POSITIVE_INFINITY;if(t.value<s)if(t.inclusive)r.maximum=t.value;else r.exclusiveMaximum=t.value}),e._zod.check=(o)=>{if(t.inclusive?o.value<=t.value:o.value<t.value)return;o.issues.push({origin:n,code:"too_big",maximum:typeof t.value==="object"?t.value.getTime():t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),xl=O("$ZodCheckGreaterThan",(e,t)=>{lt.init(e,t);let n=ef[typeof t.value];e._zod.onattach.push((o)=>{let r=o._zod.bag,s=(t.inclusive?r.minimum:r.exclusiveMinimum)??Number.NEGATIVE_INFINITY;if(t.value>s)if(t.inclusive)r.minimum=t.value;else r.exclusiveMinimum=t.value}),e._zod.check=(o)=>{if(t.inclusive?o.value>=t.value:o.value>t.value)return;o.issues.push({origin:n,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tf=O("$ZodCheckMultipleOf",(e,t)=>{lt.init(e,t),e._zod.onattach.push((n)=>{var o;(o=n._zod.bag).multipleOf??(o.multipleOf=t.value)}),e._zod.check=(n)=>{if(typeof n.value!==typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof n.value==="bigint"?n.value%t.value===BigInt(0):cm(n.value,t.value)===0)return;n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),nf=O("$ZodCheckNumberFormat",(e,t)=>{lt.init(e,t),t.format=t.format||"float64";let n=t.format?.includes("int"),o=n?"int":"number",[r,s]=mm[t.format];e._zod.onattach.push((a)=>{let c=a._zod.bag;if(c.format=t.format,c.minimum=r,c.maximum=s,n)c.pattern=Gm}),e._zod.check=(a)=>{let c=a.value;if(n){if(!Number.isInteger(c)){a.issues.push({expected:o,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){if(c>0)a.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,inclusive:!0,continue:!t.abort});else a.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,inclusive:!0,continue:!t.abort});return}}if(c<r)a.issues.push({origin:"number",input:c,code:"too_small",minimum:r,inclusive:!0,inst:e,continue:!t.abort});if(c>s)a.issues.push({origin:"number",input:c,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}});var of=O("$ZodCheckMaxLength",(e,t)=>{var n;lt.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!fs(r)&&r.length!==void 0}),e._zod.onattach.push((o)=>{let r=o._zod.bag.maximum??Number.POSITIVE_INFINITY;if(t.maximum<r)o._zod.bag.maximum=t.maximum}),e._zod.check=(o)=>{let r=o.value;if(r.length<=t.maximum)return;let a=gs(r);o.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),rf=O("$ZodCheckMinLength",(e,t)=>{var n;lt.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!fs(r)&&r.length!==void 0}),e._zod.onattach.push((o)=>{let r=o._zod.bag.minimum??Number.NEGATIVE_INFINITY;if(t.minimum>r)o._zod.bag.minimum=t.minimum}),e._zod.check=(o)=>{let r=o.value;if(r.length>=t.minimum)return;let a=gs(r);o.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),sf=O("$ZodCheckLengthEquals",(e,t)=>{var n;lt.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!fs(r)&&r.length!==void 0}),e._zod.onattach.push((o)=>{let r=o._zod.bag;r.minimum=t.length,r.maximum=t.length,r.length=t.length}),e._zod.check=(o)=>{let r=o.value,s=r.length;if(s===t.length)return;let a=gs(r),c=s>t.length;o.issues.push({origin:a,...c?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:o.value,inst:e,continue:!t.abort})}}),ri=O("$ZodCheckStringFormat",(e,t)=>{var n,o;if(lt.init(e,t),e._zod.onattach.push((r)=>{let s=r._zod.bag;if(s.format=t.format,t.pattern)s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern)}),t.pattern)(n=e._zod).check??(n.check=(r)=>{if(t.pattern.lastIndex=0,t.pattern.test(r.value))return;r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})});else(o=e._zod).check??(o.check=()=>{})}),af=O("$ZodCheckRegex",(e,t)=>{ri.init(e,t),e._zod.check=(n)=>{if(t.pattern.lastIndex=0,t.pattern.test(n.value))return;n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),cf=O("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Ym),ri.init(e,t)}),lf=O("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Qm),ri.init(e,t)}),uf=O("$ZodCheckIncludes",(e,t)=>{lt.init(e,t);let n=jn(t.includes),o=new RegExp(typeof t.position==="number"?`^.{${t.position}}${n}`:n);t.pattern=o,e._zod.onattach.push((r)=>{let s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(o)}),e._zod.check=(r)=>{if(r.value.includes(t.includes,t.position))return;r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),df=O("$ZodCheckStartsWith",(e,t)=>{lt.init(e,t);let n=new RegExp(`^${jn(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push((o)=>{let r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=(o)=>{if(o.value.startsWith(t.prefix))return;o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:o.value,inst:e,continue:!t.abort})}}),pf=O("$ZodCheckEndsWith",(e,t)=>{lt.init(e,t);let n=new RegExp(`.*${jn(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push((o)=>{let r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=(o)=>{if(o.value.endsWith(t.suffix))return;o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:o.value,inst:e,continue:!t.abort})}});var mf=O("$ZodCheckOverwrite",(e,t)=>{lt.init(e,t),e._zod.check=(n)=>{n.value=t.tx(n.value)}});class wl{constructor(e=[]){if(this.content=[],this.indent=0,this)this.args=e}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let n=e.split(`
|
|
22
|
+
`}}};to.tableCaption={filter:["caption"],replacement:()=>""};to.tableColgroup={filter:["colgroup","col"],replacement:()=>""};to.tableSection={filter:["thead","tbody","tfoot"],replacement:function(e){return e}};function NC(e){var t=e.parentNode;return t.nodeName==="THEAD"||t.firstChild===e&&(t.nodeName==="TABLE"||RC(t))&&AC.call(e.childNodes,function(n){return n.nodeName==="TH"})}function RC(e){var t=e.previousSibling;return e.nodeName==="TBODY"&&(!t||t.nodeName==="THEAD"&&/^\s*$/i.test(t.textContent))}function yb(e,t=null,n=null){if(n===null)n=EC.call(t.parentNode.childNodes,t);var o=" ";if(n===0)o="| ";let r=e.trim().replace(/\n\r/g,"<br>").replace(/\n/g,"<br>");r=r.replace(/\|+/g,"\\|");while(r.length<3)r+=" ";if(t)r=LC(r,t," ");return o+r+" |"}function bb(e){if(!e.childNodes)return!1;for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(n.nodeName==="TABLE")return!0;if(bb(n))return!0}return!1}var Du=(e,t)=>{if(!e.childNodes)return!1;for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];if(t==="code"&&Ou&&Ou(o))return!0;if(t.includes(o.nodeName))return!0;if(Du(o,t))return!0}return!1},xb=(e,t)=>{let n=["UL","OL","H1","H2","H3","H4","H5","H6","HR","BLOCKQUOTE"];if(t.preserveNestedTables)n.push("TABLE");return Du(e,"code")||Du(e,n)};function Fu(e){let t=pb.get(e);if(t!==void 0)return t;let n=$C(e);return pb.set(e,n),n}function $C(e){if(!e)return!0;if(!e.rows)return!0;if(e.rows.length===1&&e.rows[0].childNodes.length<=1)return!0;if(bb(e))return!0;return!1}function MC(e){let t=e.parentNode;while(t.nodeName!=="DIV")if(t=t.parentNode,!t)return null;return t}function wb(e){let t=e.parentNode;while(t.nodeName!=="TABLE")if(t=t.parentNode,!t)return null;return t}function LC(e,t,n){let o=t.getAttribute("colspan")||1;for(let r=1;r<o;r++)e+=" | "+n.repeat(3);return e}function _b(e){let t=0;for(let n=0;n<e.rows.length;n++){let r=e.rows[n].childNodes.length;if(r>t)t=r}return t}function kb(e){Ou=e.isCodeBlock,hb=e.options,e.keep(function(n){if(n.nodeName==="TABLE"&&xb(n,e.options))return!0;return!1});for(var t in to)e.addRule(t,to[t])}function Sb(e){e.addRule("taskListItems",{filter:function(t){let n=t.parentNode,o=n.parentNode;return t.type==="checkbox"&&(n.nodeName==="LI"||n.nodeName==="LABEL"&&o&&o.nodeName==="LI")},replacement:function(t,n){return(n.checked?"[x]":"[ ]")+" "}})}function OC(e){e.use([mb,fb,kb,Sb])}Cb.gfm=OC;Cb.highlightedCodeBlock=mb;Cb.strikethrough=fb;Cb.tables=kb;Cb.taskListItems=Sb});if(typeof crypto<"u"&&typeof crypto.randomUUID!=="function")crypto.randomUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e)=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)});var ds,_e,Bp,ol,Bn,Lp,Hp,jp,Zp,rl,el,tl,gk,cs={},ls=[],vk=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ps=Array.isArray;function vn(e,t){for(var n in t)e[n]=t[n];return e}function il(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function yk(e,t,n){var o,r,s,a={};for(s in t)s=="key"?o=t[s]:s=="ref"?r=t[s]:a[s]=t[s];if(arguments.length>2&&(a.children=arguments.length>3?ds.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)a[s]===void 0&&(a[s]=e.defaultProps[s]);return as(e,a,o,r,null)}function as(e,t,n,o,r){var s={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:r==null?++Bp:r,__i:-1,__u:0};return r==null&&_e.vnode!=null&&_e.vnode(s),s}function ue(e){return e.children}function Xo(e,t){this.props=e,this.context=t}function Jo(e,t){if(t==null)return e.__?Jo(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?Jo(e):null}function bk(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,o=[],r=[],s=vn({},t);s.__v=t.__v+1,_e.vnode&&_e.vnode(s),sl(e.__P,s,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,o,n==null?Jo(t):n,!!(32&t.__u),r),s.__v=t.__v,s.__.__k[s.__i]=s,Vp(o,s,r),t.__e=t.__=null,s.__e!=n&&Up(s)}}function Up(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),Up(e)}function Op(e){(!e.__d&&(e.__d=!0)&&Bn.push(e)&&!us.__r++||Lp!=_e.debounceRendering)&&((Lp=_e.debounceRendering)||Hp)(us)}function us(){try{for(var e,t=1;Bn.length;)Bn.length>t&&Bn.sort(jp),e=Bn.shift(),t=Bn.length,bk(e)}finally{Bn.length=us.__r=0}}function qp(e,t,n,o,r,s,a,c,l,u,p){var d,m,f,h,v,x,g,y=o&&o.__k||ls,E=t.length;for(l=xk(n,t,y,l,E),d=0;d<E;d++)(f=n.__k[d])!=null&&(m=f.__i!=-1&&y[f.__i]||cs,f.__i=d,x=sl(e,f,m,r,s,a,c,l,u,p),h=f.__e,f.ref&&m.ref!=f.ref&&(m.ref&&al(m.ref,null,f),p.push(f.ref,f.__c||h,f)),v==null&&h!=null&&(v=h),(g=!!(4&f.__u))||m.__k===f.__k?l=Wp(f,l,e,g):typeof f.type=="function"&&x!==void 0?l=x:h&&(l=h.nextSibling),f.__u&=-7);return n.__e=v,l}function xk(e,t,n,o,r){var s,a,c,l,u,p=n.length,d=p,m=0;for(e.__k=Array(r),s=0;s<r;s++)(a=t[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=e.__k[s]=as(null,a,null,null,null):ps(a)?a=e.__k[s]=as(ue,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=e.__k[s]=as(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):e.__k[s]=a,l=s+m,a.__=e,a.__b=e.__b+1,c=null,(u=a.__i=wk(a,n,l,d))!=-1&&(d--,(c=n[u])&&(c.__u|=2)),c==null||c.__v==null?(u==-1&&(r>p?m--:r<p&&m++),typeof a.type!="function"&&(a.__u|=4)):u!=l&&(u==l-1?m--:u==l+1?m++:(u>l?m--:m++,a.__u|=4))):e.__k[s]=null;if(d)for(s=0;s<p;s++)(c=n[s])!=null&&(2&c.__u)==0&&(c.__e==o&&(o=Jo(c)),Xp(c,c));return o}function Wp(e,t,n,o){var r,s;if(typeof e.type=="function"){for(r=e.__k,s=0;r&&s<r.length;s++)r[s]&&(r[s].__=e,t=Wp(r[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=Jo(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function wk(e,t,n,o){var r,s,a,{key:c,type:l}=e,u=t[n],p=u!=null&&(2&u.__u)==0;if(u===null&&c==null||p&&c==u.key&&l==u.type)return n;if(o>(p?1:0)){for(r=n-1,s=n+1;r>=0||s<t.length;)if((u=t[a=r>=0?r--:s++])!=null&&(2&u.__u)==0&&c==u.key&&l==u.type)return a}return-1}function Dp(e,t,n){t[0]=="-"?e.setProperty(t,n==null?"":n):e[t]=n==null?"":typeof n!="number"||vk.test(t)?n:n+"px"}function ss(e,t,n,o,r){var s,a;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||Dp(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||Dp(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Zp,"$1")),a=t.toLowerCase(),t=a in e||t=="onFocusOut"||t=="onFocusIn"?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+s]=n,n?o?n.u=o.u:(n.u=rl,e.addEventListener(t,s?tl:el,s)):e.removeEventListener(t,s?tl:el,s);else{if(r=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n==null?"":n;break e}catch(c){}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function Fp(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=rl++;else if(t.t<n.u)return;return n(_e.event?_e.event(t):t)}}}function sl(e,t,n,o,r,s,a,c,l,u){var p,d,m,f,h,v,x,g,y,E,D,N,b,T,w,_=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),s=[c=t.__e=n.__e]),(p=_e.__b)&&p(t);e:if(typeof _=="function")try{if(g=t.props,y=_.prototype&&_.prototype.render,E=(p=_.contextType)&&o[p.__c],D=p?E?E.props.value:p.__:o,n.__c?x=(d=t.__c=n.__c).__=d.__E:(y?t.__c=d=new _(g,D):(t.__c=d=new Xo(g,D),d.constructor=_,d.render=kk),E&&E.sub(d),d.state||(d.state={}),d.__n=o,m=d.__d=!0,d.__h=[],d._sb=[]),y&&d.__s==null&&(d.__s=d.state),y&&_.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=vn({},d.__s)),vn(d.__s,_.getDerivedStateFromProps(g,d.__s))),f=d.props,h=d.state,d.__v=t,m)y&&_.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),y&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(y&&_.getDerivedStateFromProps==null&&g!==f&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(g,D),t.__v==n.__v||!d.__e&&d.shouldComponentUpdate!=null&&d.shouldComponentUpdate(g,d.__s,D)===!1){t.__v!=n.__v&&(d.props=g,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(P){P&&(P.__=t)}),ls.push.apply(d.__h,d._sb),d._sb=[],d.__h.length&&a.push(d);break e}d.componentWillUpdate!=null&&d.componentWillUpdate(g,d.__s,D),y&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(f,h,v)})}if(d.context=D,d.props=g,d.__P=e,d.__e=!1,N=_e.__r,b=0,y)d.state=d.__s,d.__d=!1,N&&N(t),p=d.render(d.props,d.state,d.context),ls.push.apply(d.__h,d._sb),d._sb=[];else do d.__d=!1,N&&N(t),p=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++b<25);d.state=d.__s,d.getChildContext!=null&&(o=vn(vn({},o),d.getChildContext())),y&&!m&&d.getSnapshotBeforeUpdate!=null&&(v=d.getSnapshotBeforeUpdate(f,h)),T=p!=null&&p.type===ue&&p.key==null?Gp(p.props.children):p,c=qp(e,ps(T)?T:[T],t,n,o,r,s,a,c,l,u),d.base=t.__e,t.__u&=-161,d.__h.length&&a.push(d),x&&(d.__E=d.__=null)}catch(P){if(t.__v=null,l||s!=null)if(P.then){for(t.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;s[s.indexOf(c)]=null,t.__e=c}else{for(w=s.length;w--;)il(s[w]);nl(t)}else t.__e=n.__e,t.__k=n.__k,P.then||nl(t);_e.__e(P,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=_k(n.__e,t,n,o,r,s,a,l,u);return(p=_e.diffed)&&p(t),128&t.__u?void 0:c}function nl(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(nl))}function Vp(e,t,n){for(var o=0;o<n.length;o++)al(n[o],n[++o],n[++o]);_e.__c&&_e.__c(t,e),e.some(function(r){try{e=r.__h,r.__h=[],e.some(function(s){s.call(r)})}catch(s){_e.__e(s,r.__v)}})}function Gp(e){return typeof e!="object"||e==null||e.__b>0?e:ps(e)?e.map(Gp):vn({},e)}function _k(e,t,n,o,r,s,a,c,l){var u,p,d,m,f,h,v,x=n.props||cs,{props:g,type:y}=t;if(y=="svg"?r="http://www.w3.org/2000/svg":y=="math"?r="http://www.w3.org/1998/Math/MathML":r||(r="http://www.w3.org/1999/xhtml"),s!=null){for(u=0;u<s.length;u++)if((f=s[u])&&"setAttribute"in f==!!y&&(y?f.localName==y:f.nodeType==3)){e=f,s[u]=null;break}}if(e==null){if(y==null)return document.createTextNode(g);e=document.createElementNS(r,y,g.is&&g),c&&(_e.__m&&_e.__m(t,s),c=!1),s=null}if(y==null)x===g||c&&e.data==g||(e.data=g);else{if(s=s&&ds.call(e.childNodes),!c&&s!=null)for(x={},u=0;u<e.attributes.length;u++)x[(f=e.attributes[u]).name]=f.value;for(u in x)f=x[u],u=="dangerouslySetInnerHTML"?d=f:u=="children"||(u in g)||u=="value"&&("defaultValue"in g)||u=="checked"&&("defaultChecked"in g)||ss(e,u,null,f,r);for(u in g)f=g[u],u=="children"?m=f:u=="dangerouslySetInnerHTML"?p=f:u=="value"?h=f:u=="checked"?v=f:c&&typeof f!="function"||x[u]===f||ss(e,u,f,x[u],r);if(p)c||d&&(p.__html==d.__html||p.__html==e.innerHTML)||(e.innerHTML=p.__html),t.__k=[];else if(d&&(e.innerHTML=""),qp(t.type=="template"?e.content:e,ps(m)?m:[m],t,n,o,y=="foreignObject"?"http://www.w3.org/1999/xhtml":r,s,a,s?s[0]:n.__k&&Jo(n,0),c,l),s!=null)for(u=s.length;u--;)il(s[u]);c||(u="value",y=="progress"&&h==null?e.removeAttribute("value"):h!=null&&(h!==e[u]||y=="progress"&&!h||y=="option"&&h!=x[u])&&ss(e,u,h,x[u],r),u="checked",v!=null&&v!=e[u]&&ss(e,u,v,x[u],r))}return e}function al(e,t,n){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(r){_e.__e(r,n)}}function Xp(e,t,n){var o,r;if(_e.unmount&&_e.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||al(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){_e.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(r=0;r<o.length;r++)o[r]&&Xp(o[r],t,n||typeof e.type!="function");n||il(e.__e),e.__c=e.__=e.__e=void 0}function kk(e,t,n){return this.constructor(e,n)}function Yr(e,t,n){var o,r,s,a;t==document&&(t=document.documentElement),_e.__&&_e.__(e,t),r=(o=typeof n=="function")?null:n&&n.__k||t.__k,s=[],a=[],sl(t,e=(!o&&n||t).__k=yk(ue,null,[e]),r||cs,cs,t.namespaceURI,!o&&n?[n]:r?null:t.firstChild?ds.call(t.childNodes):null,s,!o&&n?n:r?r.__e:t.firstChild,o,a),Vp(s,e,a)}ds=ls.slice,_e={__e:function(e,t,n,o){for(var r,s,a;t=t.__;)if((r=t.__c)&&!r.__)try{if((s=r.constructor)&&s.getDerivedStateFromError!=null&&(r.setState(s.getDerivedStateFromError(e)),a=r.__d),r.componentDidCatch!=null&&(r.componentDidCatch(e,o||{}),a=r.__d),a)return r.__E=r}catch(c){e=c}throw e}},Bp=0,ol=function(e){return e!=null&&e.constructor===void 0},Xo.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=vn({},this.state),typeof e=="function"&&(e=e(vn({},n),this.props)),e&&vn(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Op(this))},Xo.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Op(this))},Xo.prototype.render=ue,Bn=[],Hp=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,jp=function(e,t){return e.__v.__b-t.__v.__b},us.__r=0,Zp=/(PointerCapture)$|Capture$/i,rl=0,el=Fp(!1),tl=Fp(!0),gk=0;var Ko,Ke,cl,Jp,Qr=0,rm=[],Qe=_e,{__b:Kp,__r:Yp,diffed:Qp,__c:em,unmount:tm,__:nm}=Qe;function fs(e,t){Qe.__h&&Qe.__h(Ke,e,Qr||t),Qr=0;var n=Ke.__H||(Ke.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function I(e){return Qr=1,Sk(im,e)}function Sk(e,t,n){var o=fs(Ko++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):im(void 0,t),function(c){var l=o.__N?o.__N[0]:o.__[0],u=o.t(l,c);l!==u&&(o.__N=[u,o.__[1]],o.__c.setState({}))}],o.__c=Ke,!Ke.__f)){var r=function(c,l,u){if(!o.__c.__H)return!0;var p=o.__c.__H.__.filter(function(m){return m.__c});if(p.every(function(m){return!m.__N}))return!s||s.call(this,c,l,u);var d=o.__c.props!==c;return p.some(function(m){if(m.__N){var f=m.__[0];m.__=m.__N,m.__N=void 0,f!==m.__[0]&&(d=!0)}}),s&&s.call(this,c,l,u)||d};Ke.__f=!0;var s=Ke.shouldComponentUpdate,a=Ke.componentWillUpdate;Ke.componentWillUpdate=function(c,l,u){if(this.__e){var p=s;s=void 0,r(c,l,u),s=p}a&&a.call(this,c,l,u)},Ke.shouldComponentUpdate=r}return o.__N||o.__}function B(e,t){var n=fs(Ko++,3);!Qe.__s&&ul(n.__H,t)&&(n.__=e,n.u=t,Ke.__H.__h.push(n))}function jt(e,t){var n=fs(Ko++,4);!Qe.__s&&ul(n.__H,t)&&(n.__=e,n.u=t,Ke.__h.push(n))}function z(e){return Qr=5,Se(function(){return{current:e}},[])}function Se(e,t){var n=fs(Ko++,7);return ul(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function H(e,t){return Qr=8,Se(function(){return e},t)}function Ck(){for(var e;e=rm.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(ms),t.__h.some(ll),t.__h=[]}catch(n){t.__h=[],Qe.__e(n,e.__v)}}}Qe.__b=function(e){Ke=null,Kp&&Kp(e)},Qe.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),nm&&nm(e,t)},Qe.__r=function(e){Yp&&Yp(e),Ko=0;var t=(Ke=e.__c).__H;t&&(cl===Ke?(t.__h=[],Ke.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(ms),t.__h.some(ll),t.__h=[],Ko=0)),cl=Ke},Qe.diffed=function(e){Qp&&Qp(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(rm.push(t)!==1&&Jp===Qe.requestAnimationFrame||((Jp=Qe.requestAnimationFrame)||Tk)(Ck)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),cl=Ke=null},Qe.__c=function(e,t){t.some(function(n){try{n.__h.some(ms),n.__h=n.__h.filter(function(o){return!o.__||ll(o)})}catch(o){t.some(function(r){r.__h&&(r.__h=[])}),t=[],Qe.__e(o,n.__v)}}),em&&em(e,t)},Qe.unmount=function(e){tm&&tm(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{ms(o)}catch(r){t=r}}),n.__H=void 0,t&&Qe.__e(t,n.__v))};var om=typeof requestAnimationFrame=="function";function Tk(e){var t,n=function(){clearTimeout(o),om&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);om&&(t=requestAnimationFrame(n))}function ms(e){var t=Ke,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),Ke=t}function ll(e){var t=Ke;e.__c=e.__(),Ke=t}function ul(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function im(e,t){return typeof t=="function"?t(e):t}var Oz=Object.freeze({status:"aborted"});function L(e,t,n){function o(c,l){if(!c._zod)Object.defineProperty(c,"_zod",{value:{def:l,constr:a,traits:new Set},enumerable:!1});if(c._zod.traits.has(e))return;c._zod.traits.add(e),t(c,l);let u=a.prototype,p=Object.keys(u);for(let d=0;d<p.length;d++){let m=p[d];if(!(m in c))c[m]=u[m].bind(c)}}let r=n?.Parent??Object;class s extends r{}Object.defineProperty(s,"name",{value:e});function a(c){var l;let u=n?.Parent?new s:this;o(u,c),(l=u._zod).deferred??(l.deferred=[]);for(let p of u._zod.deferred)p();return u}return Object.defineProperty(a,"init",{value:o}),Object.defineProperty(a,Symbol.hasInstance,{value:(c)=>{if(n?.Parent&&c instanceof n.Parent)return!0;return c?._zod?.traits?.has(e)}}),Object.defineProperty(a,"name",{value:e}),a}var Dz=Symbol("zod_brand");class yn extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class ei extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}var hs={};function Zt(e){if(e)Object.assign(hs,e);return hs}function vs(e){let t=Object.values(e).filter((o)=>typeof o==="number");return Object.entries(e).filter(([o,r])=>t.indexOf(+o)===-1).map(([o,r])=>r)}function pl(e,t="|"){return e.map((n)=>gl(n)).join(t)}function ti(e,t){if(typeof t==="bigint")return t.toString();return t}function ni(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw Error("cached value already set")}}}function ys(e){return e===null||e===void 0}function bs(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function am(e,t){let n=(e.toString().split(".")[1]||"").length,o=t.toString(),r=(o.split(".")[1]||"").length;if(r===0&&/\d?e-\d?/.test(o)){let l=o.match(/\d?e-(\d?)/);if(l?.[1])r=Number.parseInt(l[1])}let s=n>r?n:r,a=Number.parseInt(e.toFixed(s).replace(".","")),c=Number.parseInt(t.toFixed(s).replace(".",""));return a%c/10**s}var sm=Symbol("evaluating");function ke(e,t,n){let o=void 0;Object.defineProperty(e,t,{get(){if(o===sm)return;if(o===void 0)o=sm,o=n();return o},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function bo(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Hn(...e){let t={};for(let n of e){let o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function ml(e){return JSON.stringify(e)}function cm(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var fl="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Yo(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var lm=ni(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function xo(e){if(Yo(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;if(typeof t!=="function")return!0;let n=t.prototype;if(Yo(n)===!1)return!1;if(Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)return!1;return!0}function hl(e){if(xo(e))return{...e};if(Array.isArray(e))return[...e];return e}var um=new Set(["string","number","symbol"]);function jn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ln(e,t,n){let o=new e._zod.constr(t??e._zod.def);if(!t||n?.parent)o._zod.parent=e;return o}function G(e){let t=e;if(!t)return{};if(typeof t==="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function gl(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function dm(e){return Object.keys(e).filter((t)=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var pm={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Ik(e,t){let n=e._zod.def,o=n.checks;if(o&&o.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let s=Hn(e._zod.def,{get shape(){let a={};for(let c in t){if(!(c in n.shape))throw Error(`Unrecognized key: "${c}"`);if(!t[c])continue;a[c]=n.shape[c]}return bo(this,"shape",a),a},checks:[]});return ln(e,s)}function Ek(e,t){let n=e._zod.def,o=n.checks;if(o&&o.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let s=Hn(e._zod.def,{get shape(){let a={...e._zod.def.shape};for(let c in t){if(!(c in n.shape))throw Error(`Unrecognized key: "${c}"`);if(!t[c])continue;delete a[c]}return bo(this,"shape",a),a},checks:[]});return ln(e,s)}function Ak(e,t){if(!xo(t))throw Error("Invalid input to extend: expected a plain object");let n=e._zod.def.checks;if(n&&n.length>0){let s=e._zod.def.shape;for(let a in t)if(Object.getOwnPropertyDescriptor(s,a)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}let r=Hn(e._zod.def,{get shape(){let s={...e._zod.def.shape,...t};return bo(this,"shape",s),s}});return ln(e,r)}function zk(e,t){if(!xo(t))throw Error("Invalid input to safeExtend: expected a plain object");let n=Hn(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t};return bo(this,"shape",o),o}});return ln(e,n)}function Pk(e,t){let n=Hn(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t._zod.def.shape};return bo(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return ln(e,n)}function Nk(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(".partial() cannot be used on object schemas containing refinements");let a=Hn(t._zod.def,{get shape(){let c=t._zod.def.shape,l={...c};if(n)for(let u in n){if(!(u in c))throw Error(`Unrecognized key: "${u}"`);if(!n[u])continue;l[u]=e?new e({type:"optional",innerType:c[u]}):c[u]}else for(let u in c)l[u]=e?new e({type:"optional",innerType:c[u]}):c[u];return bo(this,"shape",l),l},checks:[]});return ln(t,a)}function Rk(e,t,n){let o=Hn(t._zod.def,{get shape(){let r=t._zod.def.shape,s={...r};if(n)for(let a in n){if(!(a in s))throw Error(`Unrecognized key: "${a}"`);if(!n[a])continue;s[a]=new e({type:"nonoptional",innerType:r[a]})}else for(let a in r)s[a]=new e({type:"nonoptional",innerType:r[a]});return bo(this,"shape",s),s}});return ln(t,o)}function wo(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Zn(e,t){return t.map((n)=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function gs(e){return typeof e==="string"?e:e?.message}function un(e,t,n){let o={...e,path:e.path??[]};if(!e.message){let r=gs(e.inst?._zod.def?.error?.(e))??gs(t?.error?.(e))??gs(n.customError?.(e))??gs(n.localeError?.(e))??"Invalid input";o.message=r}if(delete o.inst,delete o.continue,!t?.reportInput)delete o.input;return o}function xs(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function mm(e){let t=typeof e;switch(t){case"number":return Number.isNaN(e)?"nan":"number";case"object":{if(e===null)return"null";if(Array.isArray(e))return"array";let n=e;if(n&&Object.getPrototypeOf(n)!==Object.prototype&&"constructor"in n&&n.constructor)return n.constructor.name}}return t}function _o(...e){let[t,n,o]=e;if(typeof t==="string")return{message:t,code:"custom",input:n,inst:o};return{...t}}var fm=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,ti,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},ws=L("$ZodError",fm),vl=L("$ZodError",fm,{Parent:Error});function hm(e,t=(n)=>n.message){let n={},o=[];for(let r of e.issues)if(r.path.length>0)n[r.path[0]]=n[r.path[0]]||[],n[r.path[0]].push(t(r));else o.push(t(r));return{formErrors:o,fieldErrors:n}}function gm(e,t=(n)=>n.message){let n={_errors:[]},o=(r)=>{for(let s of r.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map((a)=>o({issues:a}));else if(s.code==="invalid_key")o({issues:s.issues});else if(s.code==="invalid_element")o({issues:s.issues});else if(s.path.length===0)n._errors.push(t(s));else{let a=n,c=0;while(c<s.path.length){let l=s.path[c];if(c!==s.path.length-1)a[l]=a[l]||{_errors:[]};else a[l]=a[l]||{_errors:[]},a[l]._errors.push(t(s));a=a[l],c++}}};return o(e),n}var _s=(e)=>(t,n,o,r)=>{let s=o?Object.assign(o,{async:!1}):{async:!1},a=t._zod.run({value:n,issues:[]},s);if(a instanceof Promise)throw new yn;if(a.issues.length){let c=new(r?.Err??e)(a.issues.map((l)=>un(l,s,Zt())));throw fl(c,r?.callee),c}return a.value};var ks=(e)=>async(t,n,o,r)=>{let s=o?Object.assign(o,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},s);if(a instanceof Promise)a=await a;if(a.issues.length){let c=new(r?.Err??e)(a.issues.map((l)=>un(l,s,Zt())));throw fl(c,r?.callee),c}return a.value};var oi=(e)=>(t,n,o)=>{let r=o?{...o,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},r);if(s instanceof Promise)throw new yn;return s.issues.length?{success:!1,error:new(e??ws)(s.issues.map((a)=>un(a,r,Zt())))}:{success:!0,data:s.value}},ri=oi(vl),ii=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{async:!0}):{async:!0},s=t._zod.run({value:n,issues:[]},r);if(s instanceof Promise)s=await s;return s.issues.length?{success:!1,error:new e(s.issues.map((a)=>un(a,r,Zt())))}:{success:!0,data:s.value}},Ss=ii(vl),vm=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return _s(e)(t,n,r)};var ym=(e)=>(t,n,o)=>_s(e)(t,n,o);var bm=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ks(e)(t,n,r)};var xm=(e)=>async(t,n,o)=>ks(e)(t,n,o);var wm=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return oi(e)(t,n,r)};var _m=(e)=>(t,n,o)=>oi(e)(t,n,o);var km=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ii(e)(t,n,r)};var Sm=(e)=>async(t,n,o)=>ii(e)(t,n,o);var Cm=/^[cC][^\s-]{8,}$/,Tm=/^[0-9a-z]+$/,Im=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Em=/^[0-9a-vA-V]{20}$/,Am=/^[A-Za-z0-9]{27}$/,zm=/^[a-zA-Z0-9_-]{21}$/,Pm=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Nm=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,yl=(e)=>{if(!e)return/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)};var Rm=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var Mk="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function $m(){return new RegExp(Mk,"u")}var Mm=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Lm=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;var Om=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Dm=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Fm=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,bl=/^[A-Za-z0-9_-]*$/;var Bm=/^\+[1-9]\d{6,14}$/,Hm="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",jm=new RegExp(`^${Hm}$`);function Zm(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function Um(e){return new RegExp(`^${Zm(e)}$`)}function qm(e){let t=Zm({precision:e.precision}),n=["Z"];if(e.local)n.push("");if(e.offset)n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let o=`${t}(?:${n.join("|")})`;return new RegExp(`^${Hm}T(?:${o})$`)}var Wm=(e)=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var Vm=/^-?\d+$/,xl=/^-?\d+(?:\.\d+)?$/,Gm=/^(?:true|false)$/i,Xm=/^null$/i;var Jm=/^undefined$/i;var Km=/^[^A-Z]*$/,Ym=/^[^a-z]*$/;var ut=L("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Qm={number:"number",bigint:"bigint",object:"date"},wl=L("$ZodCheckLessThan",(e,t)=>{ut.init(e,t);let n=Qm[typeof t.value];e._zod.onattach.push((o)=>{let r=o._zod.bag,s=(t.inclusive?r.maximum:r.exclusiveMaximum)??Number.POSITIVE_INFINITY;if(t.value<s)if(t.inclusive)r.maximum=t.value;else r.exclusiveMaximum=t.value}),e._zod.check=(o)=>{if(t.inclusive?o.value<=t.value:o.value<t.value)return;o.issues.push({origin:n,code:"too_big",maximum:typeof t.value==="object"?t.value.getTime():t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),_l=L("$ZodCheckGreaterThan",(e,t)=>{ut.init(e,t);let n=Qm[typeof t.value];e._zod.onattach.push((o)=>{let r=o._zod.bag,s=(t.inclusive?r.minimum:r.exclusiveMinimum)??Number.NEGATIVE_INFINITY;if(t.value>s)if(t.inclusive)r.minimum=t.value;else r.exclusiveMinimum=t.value}),e._zod.check=(o)=>{if(t.inclusive?o.value>=t.value:o.value>t.value)return;o.issues.push({origin:n,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),ef=L("$ZodCheckMultipleOf",(e,t)=>{ut.init(e,t),e._zod.onattach.push((n)=>{var o;(o=n._zod.bag).multipleOf??(o.multipleOf=t.value)}),e._zod.check=(n)=>{if(typeof n.value!==typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof n.value==="bigint"?n.value%t.value===BigInt(0):am(n.value,t.value)===0)return;n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),tf=L("$ZodCheckNumberFormat",(e,t)=>{ut.init(e,t),t.format=t.format||"float64";let n=t.format?.includes("int"),o=n?"int":"number",[r,s]=pm[t.format];e._zod.onattach.push((a)=>{let c=a._zod.bag;if(c.format=t.format,c.minimum=r,c.maximum=s,n)c.pattern=Vm}),e._zod.check=(a)=>{let c=a.value;if(n){if(!Number.isInteger(c)){a.issues.push({expected:o,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){if(c>0)a.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,inclusive:!0,continue:!t.abort});else a.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,inclusive:!0,continue:!t.abort});return}}if(c<r)a.issues.push({origin:"number",input:c,code:"too_small",minimum:r,inclusive:!0,inst:e,continue:!t.abort});if(c>s)a.issues.push({origin:"number",input:c,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}});var nf=L("$ZodCheckMaxLength",(e,t)=>{var n;ut.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!ys(r)&&r.length!==void 0}),e._zod.onattach.push((o)=>{let r=o._zod.bag.maximum??Number.POSITIVE_INFINITY;if(t.maximum<r)o._zod.bag.maximum=t.maximum}),e._zod.check=(o)=>{let r=o.value;if(r.length<=t.maximum)return;let a=xs(r);o.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),of=L("$ZodCheckMinLength",(e,t)=>{var n;ut.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!ys(r)&&r.length!==void 0}),e._zod.onattach.push((o)=>{let r=o._zod.bag.minimum??Number.NEGATIVE_INFINITY;if(t.minimum>r)o._zod.bag.minimum=t.minimum}),e._zod.check=(o)=>{let r=o.value;if(r.length>=t.minimum)return;let a=xs(r);o.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),rf=L("$ZodCheckLengthEquals",(e,t)=>{var n;ut.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!ys(r)&&r.length!==void 0}),e._zod.onattach.push((o)=>{let r=o._zod.bag;r.minimum=t.length,r.maximum=t.length,r.length=t.length}),e._zod.check=(o)=>{let r=o.value,s=r.length;if(s===t.length)return;let a=xs(r),c=s>t.length;o.issues.push({origin:a,...c?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:o.value,inst:e,continue:!t.abort})}}),si=L("$ZodCheckStringFormat",(e,t)=>{var n,o;if(ut.init(e,t),e._zod.onattach.push((r)=>{let s=r._zod.bag;if(s.format=t.format,t.pattern)s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern)}),t.pattern)(n=e._zod).check??(n.check=(r)=>{if(t.pattern.lastIndex=0,t.pattern.test(r.value))return;r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})});else(o=e._zod).check??(o.check=()=>{})}),sf=L("$ZodCheckRegex",(e,t)=>{si.init(e,t),e._zod.check=(n)=>{if(t.pattern.lastIndex=0,t.pattern.test(n.value))return;n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),af=L("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Km),si.init(e,t)}),cf=L("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Ym),si.init(e,t)}),lf=L("$ZodCheckIncludes",(e,t)=>{ut.init(e,t);let n=jn(t.includes),o=new RegExp(typeof t.position==="number"?`^.{${t.position}}${n}`:n);t.pattern=o,e._zod.onattach.push((r)=>{let s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(o)}),e._zod.check=(r)=>{if(r.value.includes(t.includes,t.position))return;r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),uf=L("$ZodCheckStartsWith",(e,t)=>{ut.init(e,t);let n=new RegExp(`^${jn(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push((o)=>{let r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=(o)=>{if(o.value.startsWith(t.prefix))return;o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:o.value,inst:e,continue:!t.abort})}}),df=L("$ZodCheckEndsWith",(e,t)=>{ut.init(e,t);let n=new RegExp(`.*${jn(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push((o)=>{let r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=(o)=>{if(o.value.endsWith(t.suffix))return;o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:o.value,inst:e,continue:!t.abort})}});var pf=L("$ZodCheckOverwrite",(e,t)=>{ut.init(e,t),e._zod.check=(n)=>{n.value=t.tx(n.value)}});class kl{constructor(e=[]){if(this.content=[],this.indent=0,this)this.args=e}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let n=e.split(`
|
|
23
23
|
`).filter((s)=>s),o=Math.min(...n.map((s)=>s.length-s.trimStart().length)),r=n.map((s)=>s.slice(o)).map((s)=>" ".repeat(this.indent*2)+s);for(let s of r)this.content.push(s)}compile(){let e=Function,t=this?.args,o=[...(this?.content??[""]).map((r)=>` ${r}`)];return new e(...t,o.join(`
|
|
24
|
-
`))}}var
|
|
25
|
-
if (${
|
|
26
|
-
if (${
|
|
27
|
-
payload.issues = payload.issues.concat(${
|
|
24
|
+
`))}}var ff={major:4,minor:3,patch:6};var Oe=L("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=ff;let o=[...e._zod.def.checks??[]];if(e._zod.traits.has("$ZodCheck"))o.unshift(e);for(let r of o)for(let s of r._zod.onattach)s(e);if(o.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let r=(a,c,l)=>{let u=wo(a),p;for(let d of c){if(d._zod.def.when){if(!d._zod.def.when(a))continue}else if(u)continue;let m=a.issues.length,f=d._zod.check(a);if(f instanceof Promise&&l?.async===!1)throw new yn;if(p||f instanceof Promise)p=(p??Promise.resolve()).then(async()=>{if(await f,a.issues.length===m)return;if(!u)u=wo(a,m)});else{if(a.issues.length===m)continue;if(!u)u=wo(a,m)}}if(p)return p.then(()=>a);return a},s=(a,c,l)=>{if(wo(a))return a.aborted=!0,a;let u=r(c,o,l);if(u instanceof Promise){if(l.async===!1)throw new yn;return u.then((p)=>e._zod.parse(p,l))}return e._zod.parse(u,l)};e._zod.run=(a,c)=>{if(c.skipChecks)return e._zod.parse(a,c);if(c.direction==="backward"){let u=e._zod.parse({value:a.value,issues:[]},{...c,skipChecks:!0});if(u instanceof Promise)return u.then((p)=>s(p,a,c));return s(u,a,c)}let l=e._zod.parse(a,c);if(l instanceof Promise){if(c.async===!1)throw new yn;return l.then((u)=>r(u,o,c))}return r(l,o,c)}}ke(e,"~standard",()=>({validate:(r)=>{try{let s=ri(e,r);return s.success?{value:s.data}:{issues:s.error?.issues}}catch(s){return Ss(e,r).then((a)=>a.success?{value:a.data}:{issues:a.error?.issues})}},vendor:"zod",version:1}))}),Es=L("$ZodString",(e,t)=>{Oe.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Wm(e._zod.bag),e._zod.parse=(n,o)=>{if(t.coerce)try{n.value=String(n.value)}catch(r){}if(typeof n.value==="string")return n;return n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),je=L("$ZodStringFormat",(e,t)=>{si.init(e,t),Es.init(e,t)}),kf=L("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Nm),je.init(e,t)}),Sf=L("$ZodUUID",(e,t)=>{if(t.version){let o={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(o===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=yl(o))}else t.pattern??(t.pattern=yl());je.init(e,t)}),Cf=L("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Rm),je.init(e,t)}),Tf=L("$ZodURL",(e,t)=>{je.init(e,t),e._zod.check=(n)=>{try{let o=n.value.trim(),r=new URL(o);if(t.hostname){if(t.hostname.lastIndex=0,!t.hostname.test(r.hostname))n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})}if(t.protocol){if(t.protocol.lastIndex=0,!t.protocol.test(r.protocol.endsWith(":")?r.protocol.slice(0,-1):r.protocol))n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})}if(t.normalize)n.value=r.href;else n.value=o;return}catch(o){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),If=L("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=$m()),je.init(e,t)}),Ef=L("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=zm),je.init(e,t)}),Af=L("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Cm),je.init(e,t)}),zf=L("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Tm),je.init(e,t)}),Pf=L("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Im),je.init(e,t)}),Nf=L("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Em),je.init(e,t)}),Rf=L("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Am),je.init(e,t)}),$f=L("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=qm(t)),je.init(e,t)}),Mf=L("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=jm),je.init(e,t)}),Lf=L("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Um(t)),je.init(e,t)}),Of=L("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Pm),je.init(e,t)}),Df=L("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Mm),je.init(e,t),e._zod.bag.format="ipv4"}),Ff=L("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Lm),je.init(e,t),e._zod.bag.format="ipv6",e._zod.check=(n)=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}});var Bf=L("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Om),je.init(e,t)}),Hf=L("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Dm),je.init(e,t),e._zod.check=(n)=>{let o=n.value.split("/");try{if(o.length!==2)throw Error();let[r,s]=o;if(!s)throw Error();let a=Number(s);if(`${a}`!==s)throw Error();if(a<0||a>128)throw Error();new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function jf(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var Zf=L("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Fm),je.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=(n)=>{if(jf(n.value))return;n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function Dk(e){if(!bl.test(e))return!1;let t=e.replace(/[-_]/g,(o)=>o==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return jf(n)}var Uf=L("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=bl),je.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=(n)=>{if(Dk(n.value))return;n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),qf=L("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Bm),je.init(e,t)});function Fk(e,t=null){try{let n=e.split(".");if(n.length!==3)return!1;let[o]=n;if(!o)return!1;let r=JSON.parse(atob(o));if("typ"in r&&r?.typ!=="JWT")return!1;if(!r.alg)return!1;if(t&&(!("alg"in r)||r.alg!==t))return!1;return!0}catch{return!1}}var Wf=L("$ZodJWT",(e,t)=>{je.init(e,t),e._zod.check=(n)=>{if(Fk(n.value,t.alg))return;n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}});var Cl=L("$ZodNumber",(e,t)=>{Oe.init(e,t),e._zod.pattern=e._zod.bag.pattern??xl,e._zod.parse=(n,o)=>{if(t.coerce)try{n.value=Number(n.value)}catch(a){}let r=n.value;if(typeof r==="number"&&!Number.isNaN(r)&&Number.isFinite(r))return n;let s=typeof r==="number"?Number.isNaN(r)?"NaN":!Number.isFinite(r)?"Infinity":void 0:void 0;return n.issues.push({expected:"number",code:"invalid_type",input:r,inst:e,...s?{received:s}:{}}),n}}),Vf=L("$ZodNumberFormat",(e,t)=>{tf.init(e,t),Cl.init(e,t)}),Gf=L("$ZodBoolean",(e,t)=>{Oe.init(e,t),e._zod.pattern=Gm,e._zod.parse=(n,o)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(s){}let r=n.value;if(typeof r==="boolean")return n;return n.issues.push({expected:"boolean",code:"invalid_type",input:r,inst:e}),n}});var Xf=L("$ZodUndefined",(e,t)=>{Oe.init(e,t),e._zod.pattern=Jm,e._zod.values=new Set([void 0]),e._zod.optin="optional",e._zod.optout="optional",e._zod.parse=(n,o)=>{let r=n.value;if(typeof r>"u")return n;return n.issues.push({expected:"undefined",code:"invalid_type",input:r,inst:e}),n}}),Jf=L("$ZodNull",(e,t)=>{Oe.init(e,t),e._zod.pattern=Xm,e._zod.values=new Set([null]),e._zod.parse=(n,o)=>{let r=n.value;if(r===null)return n;return n.issues.push({expected:"null",code:"invalid_type",input:r,inst:e}),n}});var Kf=L("$ZodUnknown",(e,t)=>{Oe.init(e,t),e._zod.parse=(n)=>n}),Yf=L("$ZodNever",(e,t)=>{Oe.init(e,t),e._zod.parse=(n,o)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function hf(e,t,n){if(e.issues.length)t.issues.push(...Zn(n,e.issues));t.value[n]=e.value}var Qf=L("$ZodArray",(e,t)=>{Oe.init(e,t),e._zod.parse=(n,o)=>{let r=n.value;if(!Array.isArray(r))return n.issues.push({expected:"array",code:"invalid_type",input:r,inst:e}),n;n.value=Array(r.length);let s=[];for(let a=0;a<r.length;a++){let c=r[a],l=t.element._zod.run({value:c,issues:[]},o);if(l instanceof Promise)s.push(l.then((u)=>hf(u,n,a)));else hf(l,n,a)}if(s.length)return Promise.all(s).then(()=>n);return n}});function Is(e,t,n,o,r){if(e.issues.length){if(r&&!(n in o))return;t.issues.push(...Zn(n,e.issues))}if(e.value===void 0){if(n in o)t.value[n]=void 0}else t.value[n]=e.value}function eh(e){let t=Object.keys(e.shape);for(let o of t)if(!e.shape?.[o]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${o}": expected a Zod schema`);let n=dm(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function th(e,t,n,o,r,s){let a=[],c=r.keySet,l=r.catchall._zod,u=l.def.type,p=l.optout==="optional";for(let d in t){if(c.has(d))continue;if(u==="never"){a.push(d);continue}let m=l.run({value:t[d],issues:[]},o);if(m instanceof Promise)e.push(m.then((f)=>Is(f,n,d,t,p)));else Is(m,n,d,t,p)}if(a.length)n.issues.push({code:"unrecognized_keys",keys:a,input:t,inst:s});if(!e.length)return n;return Promise.all(e).then(()=>n)}var Bk=L("$ZodObject",(e,t)=>{if(Oe.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){let c=t.shape;Object.defineProperty(t,"shape",{get:()=>{let l={...c};return Object.defineProperty(t,"shape",{value:l}),l}})}let o=ni(()=>eh(t));ke(e._zod,"propValues",()=>{let c=t.shape,l={};for(let u in c){let p=c[u]._zod;if(p.values){l[u]??(l[u]=new Set);for(let d of p.values)l[u].add(d)}}return l});let r=Yo,s=t.catchall,a;e._zod.parse=(c,l)=>{a??(a=o.value);let u=c.value;if(!r(u))return c.issues.push({expected:"object",code:"invalid_type",input:u,inst:e}),c;c.value={};let p=[],d=a.shape;for(let m of a.keys){let f=d[m],h=f._zod.optout==="optional",v=f._zod.run({value:u[m],issues:[]},l);if(v instanceof Promise)p.push(v.then((x)=>Is(x,c,m,u,h)));else Is(v,c,m,u,h)}if(!s)return p.length?Promise.all(p).then(()=>c):c;return th(p,u,c,l,o.value,e)}}),nh=L("$ZodObjectJIT",(e,t)=>{Bk.init(e,t);let n=e._zod.parse,o=ni(()=>eh(t)),r=(m)=>{let f=new kl(["shape","payload","ctx"]),h=o.value,v=(E)=>{let D=ml(E);return`shape[${D}]._zod.run({ value: input[${D}], issues: [] }, ctx)`};f.write("const input = payload.value;");let x=Object.create(null),g=0;for(let E of h.keys)x[E]=`key_${g++}`;f.write("const newResult = {};");for(let E of h.keys){let D=x[E],N=ml(E),T=m[E]?._zod?.optout==="optional";if(f.write(`const ${D} = ${v(E)};`),T)f.write(`
|
|
25
|
+
if (${D}.issues.length) {
|
|
26
|
+
if (${N} in input) {
|
|
27
|
+
payload.issues = payload.issues.concat(${D}.issues.map(iss => ({
|
|
28
28
|
...iss,
|
|
29
|
-
path: iss.path ? [${
|
|
29
|
+
path: iss.path ? [${N}, ...iss.path] : [${N}]
|
|
30
30
|
})));
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
if (${
|
|
35
|
-
if (${
|
|
36
|
-
newResult[${
|
|
34
|
+
if (${D}.value === undefined) {
|
|
35
|
+
if (${N} in input) {
|
|
36
|
+
newResult[${N}] = undefined;
|
|
37
37
|
}
|
|
38
38
|
} else {
|
|
39
|
-
newResult[${
|
|
39
|
+
newResult[${N}] = ${D}.value;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
`);else
|
|
43
|
-
if (${
|
|
44
|
-
payload.issues = payload.issues.concat(${
|
|
42
|
+
`);else f.write(`
|
|
43
|
+
if (${D}.issues.length) {
|
|
44
|
+
payload.issues = payload.issues.concat(${D}.issues.map(iss => ({
|
|
45
45
|
...iss,
|
|
46
|
-
path: iss.path ? [${
|
|
46
|
+
path: iss.path ? [${N}, ...iss.path] : [${N}]
|
|
47
47
|
})));
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
if (${
|
|
51
|
-
if (${
|
|
52
|
-
newResult[${
|
|
50
|
+
if (${D}.value === undefined) {
|
|
51
|
+
if (${N} in input) {
|
|
52
|
+
newResult[${N}] = undefined;
|
|
53
53
|
}
|
|
54
54
|
} else {
|
|
55
|
-
newResult[${
|
|
55
|
+
newResult[${N}] = ${D}.value;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
`)}m.write("payload.value = newResult;"),m.write("return payload;");let y=m.compile();return(E,L)=>y(f,E,L)},s,a=Ko,c=!ds.jitless,u=c&&um.value,p=t.catchall,d;e._zod.parse=(f,m)=>{d??(d=o.value);let h=f.value;if(!a(h))return f.issues.push({expected:"object",code:"invalid_type",input:h,inst:e}),f;if(c&&u&&m?.async===!1&&m.jitless!==!0){if(!s)s=r(t.shape);if(f=s(f,m),!p)return f;return nh([],h,f,m,d,e)}return n(f,m)}});function vf(e,t,n,o){for(let s of e)if(s.issues.length===0)return t.value=s.value,t;let r=e.filter((s)=>!_o(s));if(r.length===1)return t.value=r[0].value,r[0];return t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map((s)=>s.issues.map((a)=>ln(a,o,jt())))}),t}var kl=O("$ZodUnion",(e,t)=>{Oe.init(e,t),Se(e._zod,"optin",()=>t.options.some((r)=>r._zod.optin==="optional")?"optional":void 0),Se(e._zod,"optout",()=>t.options.some((r)=>r._zod.optout==="optional")?"optional":void 0),Se(e._zod,"values",()=>{if(t.options.every((r)=>r._zod.values))return new Set(t.options.flatMap((r)=>Array.from(r._zod.values)));return}),Se(e._zod,"pattern",()=>{if(t.options.every((r)=>r._zod.pattern)){let r=t.options.map((s)=>s._zod.pattern);return new RegExp(`^(${r.map((s)=>hs(s.source)).join("|")})$`)}return});let n=t.options.length===1,o=t.options[0]._zod.run;e._zod.parse=(r,s)=>{if(n)return o(r,s);let a=!1,c=[];for(let l of t.options){let u=l._zod.run({value:r.value,issues:[]},s);if(u instanceof Promise)c.push(u),a=!0;else{if(u.issues.length===0)return u;c.push(u)}}if(!a)return vf(c,r,e,s);return Promise.all(c).then((l)=>vf(l,r,e,s))}});var rh=O("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,kl.init(e,t);let n=e._zod.parse;Se(e._zod,"propValues",()=>{let r={};for(let s of t.options){let a=s._zod.propValues;if(!a||Object.keys(a).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(s)}"`);for(let[c,l]of Object.entries(a)){if(!r[c])r[c]=new Set;for(let u of l)r[c].add(u)}}return r});let o=ei(()=>{let r=t.options,s=new Map;for(let a of r){let c=a._zod.propValues?.[t.discriminator];if(!c||c.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(a)}"`);for(let l of c){if(s.has(l))throw Error(`Duplicate discriminator value "${String(l)}"`);s.set(l,a)}}return s});e._zod.parse=(r,s)=>{let a=r.value;if(!Ko(a))return r.issues.push({code:"invalid_type",expected:"object",input:a,inst:e}),r;let c=o.value.get(a?.[t.discriminator]);if(c)return c._zod.run(r,s);if(t.unionFallback)return n(r,s);return r.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,input:a,path:[t.discriminator],inst:e}),r}}),ih=O("$ZodIntersection",(e,t)=>{Oe.init(e,t),e._zod.parse=(n,o)=>{let r=n.value,s=t.left._zod.run({value:r,issues:[]},o),a=t.right._zod.run({value:r,issues:[]},o);if(s instanceof Promise||a instanceof Promise)return Promise.all([s,a]).then(([l,u])=>yf(n,l,u));return yf(n,s,a)}});function _l(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(wo(e)&&wo(t)){let n=Object.keys(t),o=Object.keys(e).filter((s)=>n.indexOf(s)!==-1),r={...e,...t};for(let s of o){let a=_l(e[s],t[s]);if(!a.valid)return{valid:!1,mergeErrorPath:[s,...a.mergeErrorPath]};r[s]=a.data}return{valid:!0,data:r}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let o=0;o<e.length;o++){let r=e[o],s=t[o],a=_l(r,s);if(!a.valid)return{valid:!1,mergeErrorPath:[o,...a.mergeErrorPath]};n.push(a.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function yf(e,t,n){let o=new Map,r;for(let c of t.issues)if(c.code==="unrecognized_keys"){r??(r=c);for(let l of c.keys){if(!o.has(l))o.set(l,{});o.get(l).l=!0}}else e.issues.push(c);for(let c of n.issues)if(c.code==="unrecognized_keys")for(let l of c.keys){if(!o.has(l))o.set(l,{});o.get(l).r=!0}else e.issues.push(c);let s=[...o].filter(([,c])=>c.l&&c.r).map(([c])=>c);if(s.length&&r)e.issues.push({...r,keys:s});if(_o(e))return e;let a=_l(t.value,n.value);if(!a.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return e.value=a.data,e}var sh=O("$ZodRecord",(e,t)=>{Oe.init(e,t),e._zod.parse=(n,o)=>{let r=n.value;if(!wo(r))return n.issues.push({expected:"record",code:"invalid_type",input:r,inst:e}),n;let s=[],a=t.keyType._zod.values;if(a){n.value={};let c=new Set;for(let u of a)if(typeof u==="string"||typeof u==="number"||typeof u==="symbol"){c.add(typeof u==="number"?u.toString():u);let p=t.valueType._zod.run({value:r[u],issues:[]},o);if(p instanceof Promise)s.push(p.then((d)=>{if(d.issues.length)n.issues.push(...Zn(u,d.issues));n.value[u]=d.value}));else{if(p.issues.length)n.issues.push(...Zn(u,p.issues));n.value[u]=p.value}}let l;for(let u in r)if(!c.has(u))l=l??[],l.push(u);if(l&&l.length>0)n.issues.push({code:"unrecognized_keys",input:r,inst:e,keys:l})}else{n.value={};for(let c of Reflect.ownKeys(r)){if(c==="__proto__")continue;let l=t.keyType._zod.run({value:c,issues:[]},o);if(l instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(typeof c==="string"&&yl.test(c)&&l.issues.length){let d=t.keyType._zod.run({value:Number(c),issues:[]},o);if(d instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(d.issues.length===0)l=d}if(l.issues.length){if(t.mode==="loose")n.value[c]=r[c];else n.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map((d)=>ln(d,o,jt())),input:c,path:[c],inst:e});continue}let p=t.valueType._zod.run({value:r[c],issues:[]},o);if(p instanceof Promise)s.push(p.then((d)=>{if(d.issues.length)n.issues.push(...Zn(c,d.issues));n.value[l.value]=d.value}));else{if(p.issues.length)n.issues.push(...Zn(c,p.issues));n.value[l.value]=p.value}}}if(s.length)return Promise.all(s).then(()=>n);return n}});var ah=O("$ZodEnum",(e,t)=>{Oe.init(e,t);let n=ms(t.entries),o=new Set(n);e._zod.values=o,e._zod.pattern=new RegExp(`^(${n.filter((r)=>dm.has(typeof r)).map((r)=>typeof r==="string"?jn(r):r.toString()).join("|")})$`),e._zod.parse=(r,s)=>{let a=r.value;if(o.has(a))return r;return r.issues.push({code:"invalid_value",values:n,input:a,inst:e}),r}}),ch=O("$ZodLiteral",(e,t)=>{if(Oe.init(e,t),t.values.length===0)throw Error("Cannot create literal schema with no valid values");let n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map((o)=>typeof o==="string"?jn(o):o?jn(o.toString()):String(o)).join("|")})$`),e._zod.parse=(o,r)=>{let s=o.value;if(n.has(s))return o;return o.issues.push({code:"invalid_value",values:t.values,input:s,inst:e}),o}});var lh=O("$ZodTransform",(e,t)=>{Oe.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new Yr(e.constructor.name);let r=t.transform(n.value,n);if(o.async)return(r instanceof Promise?r:Promise.resolve(r)).then((a)=>(n.value=a,n));if(r instanceof Promise)throw new gn;return n.value=r,n}});function bf(e,t){if(e.issues.length&&t===void 0)return{issues:[],value:void 0};return e}var Cl=O("$ZodOptional",(e,t)=>{Oe.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Se(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Se(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${hs(n.source)})?$`):void 0}),e._zod.parse=(n,o)=>{if(t.innerType._zod.optin==="optional"){let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>bf(s,n.value));return bf(r,n.value)}if(n.value===void 0)return n;return t.innerType._zod.run(n,o)}}),uh=O("$ZodExactOptional",(e,t)=>{Cl.init(e,t),Se(e._zod,"values",()=>t.innerType._zod.values),Se(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,o)=>t.innerType._zod.run(n,o)}),dh=O("$ZodNullable",(e,t)=>{Oe.init(e,t),Se(e._zod,"optin",()=>t.innerType._zod.optin),Se(e._zod,"optout",()=>t.innerType._zod.optout),Se(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${hs(n.source)}|null)$`):void 0}),Se(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,o)=>{if(n.value===null)return n;return t.innerType._zod.run(n,o)}}),ph=O("$ZodDefault",(e,t)=>{Oe.init(e,t),e._zod.optin="optional",Se(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);if(n.value===void 0)return n.value=t.defaultValue,n;let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>xf(s,t));return xf(r,t)}});function xf(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var mh=O("$ZodPrefault",(e,t)=>{Oe.init(e,t),e._zod.optin="optional",Se(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);if(n.value===void 0)n.value=t.defaultValue;return t.innerType._zod.run(n,o)}}),fh=O("$ZodNonOptional",(e,t)=>{Oe.init(e,t),Se(e._zod,"values",()=>{let n=t.innerType._zod.values;return n?new Set([...n].filter((o)=>o!==void 0)):void 0}),e._zod.parse=(n,o)=>{let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>wf(s,e));return wf(r,e)}});function wf(e,t){if(!e.issues.length&&e.value===void 0)e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t});return e}var hh=O("$ZodCatch",(e,t)=>{Oe.init(e,t),Se(e._zod,"optin",()=>t.innerType._zod.optin),Se(e._zod,"optout",()=>t.innerType._zod.optout),Se(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>{if(n.value=s.value,s.issues.length)n.value=t.catchValue({...n,error:{issues:s.issues.map((a)=>ln(a,o,jt()))},input:n.value}),n.issues=[];return n});if(n.value=r.value,r.issues.length)n.value=t.catchValue({...n,error:{issues:r.issues.map((s)=>ln(s,o,jt()))},input:n.value}),n.issues=[];return n}});var gh=O("$ZodPipe",(e,t)=>{Oe.init(e,t),Se(e._zod,"values",()=>t.in._zod.values),Se(e._zod,"optin",()=>t.in._zod.optin),Se(e._zod,"optout",()=>t.out._zod.optout),Se(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,o)=>{if(o.direction==="backward"){let s=t.out._zod.run(n,o);if(s instanceof Promise)return s.then((a)=>_s(a,t.in,o));return _s(s,t.in,o)}let r=t.in._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>_s(s,t.out,o));return _s(r,t.out,o)}});function _s(e,t,n){if(e.issues.length)return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},n)}var vh=O("$ZodReadonly",(e,t)=>{Oe.init(e,t),Se(e._zod,"propValues",()=>t.innerType._zod.propValues),Se(e._zod,"values",()=>t.innerType._zod.values),Se(e._zod,"optin",()=>t.innerType?._zod?.optin),Se(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then(_f);return _f(r)}});function _f(e){return e.value=Object.freeze(e.value),e}var yh=O("$ZodCustom",(e,t)=>{lt.init(e,t),Oe.init(e,t),e._zod.parse=(n,o)=>n,e._zod.check=(n)=>{let o=n.value,r=t.fn(o);if(r instanceof Promise)return r.then((s)=>Sf(s,n,o,e));Sf(r,n,o,e);return}});function Sf(e,t,n,o){if(!e){let r={code:"custom",input:n,inst:o,path:[...o._zod.def.path??[]],continue:!o._zod.def.abort};if(o._zod.def.params)r.params=o._zod.def.params;t.issues.push(So(r))}}var LS=()=>{let e={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function t(r){return e[r]??null}let n={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",jwt:"JWT",template_literal:"input"},o={nan:"NaN"};return(r)=>{switch(r.code){case"invalid_type":{let s=o[r.expected]??r.expected,a=fm(r.input),c=o[a]??a;return`Invalid input: expected ${s}, received ${c}`}case"invalid_value":if(r.values.length===1)return`Invalid input: expected ${fl(r.values[0])}`;return`Invalid option: expected one of ${ul(r.values,"|")}`;case"too_big":{let s=r.inclusive?"<=":"<",a=t(r.origin);if(a)return`Too big: expected ${r.origin??"value"} to have ${s}${r.maximum.toString()} ${a.unit??"elements"}`;return`Too big: expected ${r.origin??"value"} to be ${s}${r.maximum.toString()}`}case"too_small":{let s=r.inclusive?">=":">",a=t(r.origin);if(a)return`Too small: expected ${r.origin} to have ${s}${r.minimum.toString()} ${a.unit}`;return`Too small: expected ${r.origin} to be ${s}${r.minimum.toString()}`}case"invalid_format":{let s=r;if(s.format==="starts_with")return`Invalid string: must start with "${s.prefix}"`;if(s.format==="ends_with")return`Invalid string: must end with "${s.suffix}"`;if(s.format==="includes")return`Invalid string: must include "${s.includes}"`;if(s.format==="regex")return`Invalid string: must match pattern ${s.pattern}`;return`Invalid ${n[s.format]??r.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${r.divisor}`;case"unrecognized_keys":return`Unrecognized key${r.keys.length>1?"s":""}: ${ul(r.keys,", ")}`;case"invalid_key":return`Invalid key in ${r.origin}`;case"invalid_union":return"Invalid input";case"invalid_element":return`Invalid value in ${r.origin}`;default:return"Invalid input"}}};function Tl(){return{localeError:LS()}}var bh,Jz=Symbol("ZodOutput"),Kz=Symbol("ZodInput");class xh{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==="object"&&"id"in n)this._idmap.set(n.id,e);return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);if(t&&typeof t==="object"&&"id"in t)this._idmap.delete(t.id);return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let o={...n,...this._map.get(e)};return Object.keys(o).length?o:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function DS(){return new xh}(bh=globalThis).__zod_globalRegistry??(bh.__zod_globalRegistry=DS());var ko=globalThis.__zod_globalRegistry;function wh(e,t){return new e({type:"string",...G(t)})}function _h(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...G(t)})}function Il(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...G(t)})}function Sh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...G(t)})}function kh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...G(t)})}function Ch(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...G(t)})}function Th(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...G(t)})}function Ih(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...G(t)})}function Eh(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...G(t)})}function Ah(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...G(t)})}function zh(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...G(t)})}function Ph(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...G(t)})}function Nh(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...G(t)})}function Rh(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...G(t)})}function $h(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...G(t)})}function Mh(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...G(t)})}function Oh(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...G(t)})}function Lh(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...G(t)})}function Dh(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...G(t)})}function Fh(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...G(t)})}function Bh(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...G(t)})}function Hh(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...G(t)})}function jh(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...G(t)})}function Zh(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...G(t)})}function Uh(e,t){return new e({type:"string",format:"date",check:"string_format",...G(t)})}function qh(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...G(t)})}function Wh(e,t){return new e({type:"string",format:"duration",check:"string_format",...G(t)})}function Vh(e,t){return new e({type:"number",checks:[],...G(t)})}function Gh(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...G(t)})}function Xh(e,t){return new e({type:"boolean",...G(t)})}function Jh(e,t){return new e({type:"undefined",...G(t)})}function Kh(e,t){return new e({type:"null",...G(t)})}function Yh(e){return new e({type:"unknown"})}function Qh(e,t){return new e({type:"never",...G(t)})}function Cs(e,t){return new bl({check:"less_than",...G(t),value:e,inclusive:!1})}function ii(e,t){return new bl({check:"less_than",...G(t),value:e,inclusive:!0})}function Ts(e,t){return new xl({check:"greater_than",...G(t),value:e,inclusive:!1})}function si(e,t){return new xl({check:"greater_than",...G(t),value:e,inclusive:!0})}function Is(e,t){return new tf({check:"multiple_of",...G(t),value:e})}function Es(e,t){return new of({check:"max_length",...G(t),maximum:e})}function Yo(e,t){return new rf({check:"min_length",...G(t),minimum:e})}function As(e,t){return new sf({check:"length_equals",...G(t),length:e})}function El(e,t){return new af({check:"string_format",format:"regex",...G(t),pattern:e})}function Al(e){return new cf({check:"string_format",format:"lowercase",...G(e)})}function zl(e){return new lf({check:"string_format",format:"uppercase",...G(e)})}function Pl(e,t){return new uf({check:"string_format",format:"includes",...G(t),includes:e})}function Nl(e,t){return new df({check:"string_format",format:"starts_with",...G(t),prefix:e})}function Rl(e,t){return new pf({check:"string_format",format:"ends_with",...G(t),suffix:e})}function Un(e){return new mf({check:"overwrite",tx:e})}function $l(e){return Un((t)=>t.normalize(e))}function Ml(){return Un((e)=>e.trim())}function Ol(){return Un((e)=>e.toLowerCase())}function Ll(){return Un((e)=>e.toUpperCase())}function Dl(){return Un((e)=>lm(e))}function eg(e,t,n){return new e({type:"array",element:t,...G(n)})}function tg(e,t,n){let o=G(n);return o.abort??(o.abort=!0),new e({type:"custom",check:"custom",fn:t,...o})}function ng(e,t,n){return new e({type:"custom",check:"custom",fn:t,...G(n)})}function og(e){let t=FS((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(So(o,n.value,t._zod.def));else{let r=o;if(r.fatal)r.continue=!1;r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(So(r))}},e(n.value,n)));return t}function FS(e,t){let n=new lt({check:"custom",...G(t)});return n._zod.check=e,n}function Fl(e){let t=e?.target??"draft-2020-12";if(t==="draft-4")t="draft-04";if(t==="draft-7")t="draft-07";return{processors:e.processors??{},metadataRegistry:e?.metadata??ko,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function Qe(e,t,n={path:[],schemaPath:[]}){var o;let r=e._zod.def,s=t.seen.get(e);if(s){if(s.count++,n.schemaPath.includes(e))s.cycle=n.path;return s.schema}let a={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,a);let c=e._zod.toJSONSchema?.();if(c)a.schema=c;else{let p={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,a.schema,p);else{let f=a.schema,m=t.processors[r.type];if(!m)throw Error(`[toJSONSchema]: Non-representable type encountered: ${r.type}`);m(e,t,f,p)}let d=e._zod.parent;if(d){if(!a.ref)a.ref=d;Qe(d,t,p),t.seen.get(d).isParent=!0}}let l=t.metadataRegistry.get(e);if(l)Object.assign(a.schema,l);if(t.io==="input"&&kt(e))delete a.schema.examples,delete a.schema.default;if(t.io==="input"&&a.schema._prefault)(o=a.schema).default??(o.default=a.schema._prefault);return delete a.schema._prefault,t.seen.get(e).schema}function Bl(e,t){let n=e.seen.get(t);if(!n)throw Error("Unprocessed schema. This is a bug in Zod.");let o=new Map;for(let a of e.seen.entries()){let c=e.metadataRegistry.get(a[0])?.id;if(c){let l=o.get(c);if(l&&l!==a[0])throw Error(`Duplicate schema id "${c}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);o.set(c,a[0])}}let r=(a)=>{let c=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let d=e.external.registry.get(a[0])?.id,f=e.external.uri??((h)=>h);if(d)return{ref:f(d)};let m=a[1].defId??a[1].schema.id??`schema${e.counter++}`;return a[1].defId=m,{defId:m,ref:`${f("__shared")}#/${c}/${m}`}}if(a[1]===n)return{ref:"#"};let u=`${"#"}/${c}/`,p=a[1].schema.id??`__schema${e.counter++}`;return{defId:p,ref:u+p}},s=(a)=>{if(a[1].schema.$ref)return;let c=a[1],{ref:l,defId:u}=r(a);if(c.def={...c.schema},u)c.defId=u;let p=c.schema;for(let d in p)delete p[d];p.$ref=l};if(e.cycles==="throw")for(let a of e.seen.entries()){let c=a[1];if(c.cycle)throw Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
|
|
58
|
+
`)}f.write("payload.value = newResult;"),f.write("return payload;");let y=f.compile();return(E,D)=>y(m,E,D)},s,a=Yo,c=!hs.jitless,u=c&&lm.value,p=t.catchall,d;e._zod.parse=(m,f)=>{d??(d=o.value);let h=m.value;if(!a(h))return m.issues.push({expected:"object",code:"invalid_type",input:h,inst:e}),m;if(c&&u&&f?.async===!1&&f.jitless!==!0){if(!s)s=r(t.shape);if(m=s(m,f),!p)return m;return th([],h,m,f,d,e)}return n(m,f)}});function gf(e,t,n,o){for(let s of e)if(s.issues.length===0)return t.value=s.value,t;let r=e.filter((s)=>!wo(s));if(r.length===1)return t.value=r[0].value,r[0];return t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map((s)=>s.issues.map((a)=>un(a,o,Zt())))}),t}var Tl=L("$ZodUnion",(e,t)=>{Oe.init(e,t),ke(e._zod,"optin",()=>t.options.some((r)=>r._zod.optin==="optional")?"optional":void 0),ke(e._zod,"optout",()=>t.options.some((r)=>r._zod.optout==="optional")?"optional":void 0),ke(e._zod,"values",()=>{if(t.options.every((r)=>r._zod.values))return new Set(t.options.flatMap((r)=>Array.from(r._zod.values)));return}),ke(e._zod,"pattern",()=>{if(t.options.every((r)=>r._zod.pattern)){let r=t.options.map((s)=>s._zod.pattern);return new RegExp(`^(${r.map((s)=>bs(s.source)).join("|")})$`)}return});let n=t.options.length===1,o=t.options[0]._zod.run;e._zod.parse=(r,s)=>{if(n)return o(r,s);let a=!1,c=[];for(let l of t.options){let u=l._zod.run({value:r.value,issues:[]},s);if(u instanceof Promise)c.push(u),a=!0;else{if(u.issues.length===0)return u;c.push(u)}}if(!a)return gf(c,r,e,s);return Promise.all(c).then((l)=>gf(l,r,e,s))}});var oh=L("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Tl.init(e,t);let n=e._zod.parse;ke(e._zod,"propValues",()=>{let r={};for(let s of t.options){let a=s._zod.propValues;if(!a||Object.keys(a).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(s)}"`);for(let[c,l]of Object.entries(a)){if(!r[c])r[c]=new Set;for(let u of l)r[c].add(u)}}return r});let o=ni(()=>{let r=t.options,s=new Map;for(let a of r){let c=a._zod.propValues?.[t.discriminator];if(!c||c.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(a)}"`);for(let l of c){if(s.has(l))throw Error(`Duplicate discriminator value "${String(l)}"`);s.set(l,a)}}return s});e._zod.parse=(r,s)=>{let a=r.value;if(!Yo(a))return r.issues.push({code:"invalid_type",expected:"object",input:a,inst:e}),r;let c=o.value.get(a?.[t.discriminator]);if(c)return c._zod.run(r,s);if(t.unionFallback)return n(r,s);return r.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,input:a,path:[t.discriminator],inst:e}),r}}),rh=L("$ZodIntersection",(e,t)=>{Oe.init(e,t),e._zod.parse=(n,o)=>{let r=n.value,s=t.left._zod.run({value:r,issues:[]},o),a=t.right._zod.run({value:r,issues:[]},o);if(s instanceof Promise||a instanceof Promise)return Promise.all([s,a]).then(([l,u])=>vf(n,l,u));return vf(n,s,a)}});function Sl(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(xo(e)&&xo(t)){let n=Object.keys(t),o=Object.keys(e).filter((s)=>n.indexOf(s)!==-1),r={...e,...t};for(let s of o){let a=Sl(e[s],t[s]);if(!a.valid)return{valid:!1,mergeErrorPath:[s,...a.mergeErrorPath]};r[s]=a.data}return{valid:!0,data:r}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let o=0;o<e.length;o++){let r=e[o],s=t[o],a=Sl(r,s);if(!a.valid)return{valid:!1,mergeErrorPath:[o,...a.mergeErrorPath]};n.push(a.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function vf(e,t,n){let o=new Map,r;for(let c of t.issues)if(c.code==="unrecognized_keys"){r??(r=c);for(let l of c.keys){if(!o.has(l))o.set(l,{});o.get(l).l=!0}}else e.issues.push(c);for(let c of n.issues)if(c.code==="unrecognized_keys")for(let l of c.keys){if(!o.has(l))o.set(l,{});o.get(l).r=!0}else e.issues.push(c);let s=[...o].filter(([,c])=>c.l&&c.r).map(([c])=>c);if(s.length&&r)e.issues.push({...r,keys:s});if(wo(e))return e;let a=Sl(t.value,n.value);if(!a.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return e.value=a.data,e}var ih=L("$ZodRecord",(e,t)=>{Oe.init(e,t),e._zod.parse=(n,o)=>{let r=n.value;if(!xo(r))return n.issues.push({expected:"record",code:"invalid_type",input:r,inst:e}),n;let s=[],a=t.keyType._zod.values;if(a){n.value={};let c=new Set;for(let u of a)if(typeof u==="string"||typeof u==="number"||typeof u==="symbol"){c.add(typeof u==="number"?u.toString():u);let p=t.valueType._zod.run({value:r[u],issues:[]},o);if(p instanceof Promise)s.push(p.then((d)=>{if(d.issues.length)n.issues.push(...Zn(u,d.issues));n.value[u]=d.value}));else{if(p.issues.length)n.issues.push(...Zn(u,p.issues));n.value[u]=p.value}}let l;for(let u in r)if(!c.has(u))l=l??[],l.push(u);if(l&&l.length>0)n.issues.push({code:"unrecognized_keys",input:r,inst:e,keys:l})}else{n.value={};for(let c of Reflect.ownKeys(r)){if(c==="__proto__")continue;let l=t.keyType._zod.run({value:c,issues:[]},o);if(l instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(typeof c==="string"&&xl.test(c)&&l.issues.length){let d=t.keyType._zod.run({value:Number(c),issues:[]},o);if(d instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(d.issues.length===0)l=d}if(l.issues.length){if(t.mode==="loose")n.value[c]=r[c];else n.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map((d)=>un(d,o,Zt())),input:c,path:[c],inst:e});continue}let p=t.valueType._zod.run({value:r[c],issues:[]},o);if(p instanceof Promise)s.push(p.then((d)=>{if(d.issues.length)n.issues.push(...Zn(c,d.issues));n.value[l.value]=d.value}));else{if(p.issues.length)n.issues.push(...Zn(c,p.issues));n.value[l.value]=p.value}}}if(s.length)return Promise.all(s).then(()=>n);return n}});var sh=L("$ZodEnum",(e,t)=>{Oe.init(e,t);let n=vs(t.entries),o=new Set(n);e._zod.values=o,e._zod.pattern=new RegExp(`^(${n.filter((r)=>um.has(typeof r)).map((r)=>typeof r==="string"?jn(r):r.toString()).join("|")})$`),e._zod.parse=(r,s)=>{let a=r.value;if(o.has(a))return r;return r.issues.push({code:"invalid_value",values:n,input:a,inst:e}),r}}),ah=L("$ZodLiteral",(e,t)=>{if(Oe.init(e,t),t.values.length===0)throw Error("Cannot create literal schema with no valid values");let n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map((o)=>typeof o==="string"?jn(o):o?jn(o.toString()):String(o)).join("|")})$`),e._zod.parse=(o,r)=>{let s=o.value;if(n.has(s))return o;return o.issues.push({code:"invalid_value",values:t.values,input:s,inst:e}),o}});var ch=L("$ZodTransform",(e,t)=>{Oe.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new ei(e.constructor.name);let r=t.transform(n.value,n);if(o.async)return(r instanceof Promise?r:Promise.resolve(r)).then((a)=>(n.value=a,n));if(r instanceof Promise)throw new yn;return n.value=r,n}});function yf(e,t){if(e.issues.length&&t===void 0)return{issues:[],value:void 0};return e}var Il=L("$ZodOptional",(e,t)=>{Oe.init(e,t),e._zod.optin="optional",e._zod.optout="optional",ke(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),ke(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${bs(n.source)})?$`):void 0}),e._zod.parse=(n,o)=>{if(t.innerType._zod.optin==="optional"){let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>yf(s,n.value));return yf(r,n.value)}if(n.value===void 0)return n;return t.innerType._zod.run(n,o)}}),lh=L("$ZodExactOptional",(e,t)=>{Il.init(e,t),ke(e._zod,"values",()=>t.innerType._zod.values),ke(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,o)=>t.innerType._zod.run(n,o)}),uh=L("$ZodNullable",(e,t)=>{Oe.init(e,t),ke(e._zod,"optin",()=>t.innerType._zod.optin),ke(e._zod,"optout",()=>t.innerType._zod.optout),ke(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${bs(n.source)}|null)$`):void 0}),ke(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,o)=>{if(n.value===null)return n;return t.innerType._zod.run(n,o)}}),dh=L("$ZodDefault",(e,t)=>{Oe.init(e,t),e._zod.optin="optional",ke(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);if(n.value===void 0)return n.value=t.defaultValue,n;let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>bf(s,t));return bf(r,t)}});function bf(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var ph=L("$ZodPrefault",(e,t)=>{Oe.init(e,t),e._zod.optin="optional",ke(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);if(n.value===void 0)n.value=t.defaultValue;return t.innerType._zod.run(n,o)}}),mh=L("$ZodNonOptional",(e,t)=>{Oe.init(e,t),ke(e._zod,"values",()=>{let n=t.innerType._zod.values;return n?new Set([...n].filter((o)=>o!==void 0)):void 0}),e._zod.parse=(n,o)=>{let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>xf(s,e));return xf(r,e)}});function xf(e,t){if(!e.issues.length&&e.value===void 0)e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t});return e}var fh=L("$ZodCatch",(e,t)=>{Oe.init(e,t),ke(e._zod,"optin",()=>t.innerType._zod.optin),ke(e._zod,"optout",()=>t.innerType._zod.optout),ke(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>{if(n.value=s.value,s.issues.length)n.value=t.catchValue({...n,error:{issues:s.issues.map((a)=>un(a,o,Zt()))},input:n.value}),n.issues=[];return n});if(n.value=r.value,r.issues.length)n.value=t.catchValue({...n,error:{issues:r.issues.map((s)=>un(s,o,Zt()))},input:n.value}),n.issues=[];return n}});var hh=L("$ZodPipe",(e,t)=>{Oe.init(e,t),ke(e._zod,"values",()=>t.in._zod.values),ke(e._zod,"optin",()=>t.in._zod.optin),ke(e._zod,"optout",()=>t.out._zod.optout),ke(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,o)=>{if(o.direction==="backward"){let s=t.out._zod.run(n,o);if(s instanceof Promise)return s.then((a)=>Ts(a,t.in,o));return Ts(s,t.in,o)}let r=t.in._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>Ts(s,t.out,o));return Ts(r,t.out,o)}});function Ts(e,t,n){if(e.issues.length)return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},n)}var gh=L("$ZodReadonly",(e,t)=>{Oe.init(e,t),ke(e._zod,"propValues",()=>t.innerType._zod.propValues),ke(e._zod,"values",()=>t.innerType._zod.values),ke(e._zod,"optin",()=>t.innerType?._zod?.optin),ke(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);let r=t.innerType._zod.run(n,o);if(r instanceof Promise)return r.then(wf);return wf(r)}});function wf(e){return e.value=Object.freeze(e.value),e}var vh=L("$ZodCustom",(e,t)=>{ut.init(e,t),Oe.init(e,t),e._zod.parse=(n,o)=>n,e._zod.check=(n)=>{let o=n.value,r=t.fn(o);if(r instanceof Promise)return r.then((s)=>_f(s,n,o,e));_f(r,n,o,e);return}});function _f(e,t,n,o){if(!e){let r={code:"custom",input:n,inst:o,path:[...o._zod.def.path??[]],continue:!o._zod.def.abort};if(o._zod.def.params)r.params=o._zod.def.params;t.issues.push(_o(r))}}var Hk=()=>{let e={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function t(r){return e[r]??null}let n={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",jwt:"JWT",template_literal:"input"},o={nan:"NaN"};return(r)=>{switch(r.code){case"invalid_type":{let s=o[r.expected]??r.expected,a=mm(r.input),c=o[a]??a;return`Invalid input: expected ${s}, received ${c}`}case"invalid_value":if(r.values.length===1)return`Invalid input: expected ${gl(r.values[0])}`;return`Invalid option: expected one of ${pl(r.values,"|")}`;case"too_big":{let s=r.inclusive?"<=":"<",a=t(r.origin);if(a)return`Too big: expected ${r.origin??"value"} to have ${s}${r.maximum.toString()} ${a.unit??"elements"}`;return`Too big: expected ${r.origin??"value"} to be ${s}${r.maximum.toString()}`}case"too_small":{let s=r.inclusive?">=":">",a=t(r.origin);if(a)return`Too small: expected ${r.origin} to have ${s}${r.minimum.toString()} ${a.unit}`;return`Too small: expected ${r.origin} to be ${s}${r.minimum.toString()}`}case"invalid_format":{let s=r;if(s.format==="starts_with")return`Invalid string: must start with "${s.prefix}"`;if(s.format==="ends_with")return`Invalid string: must end with "${s.suffix}"`;if(s.format==="includes")return`Invalid string: must include "${s.includes}"`;if(s.format==="regex")return`Invalid string: must match pattern ${s.pattern}`;return`Invalid ${n[s.format]??r.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${r.divisor}`;case"unrecognized_keys":return`Unrecognized key${r.keys.length>1?"s":""}: ${pl(r.keys,", ")}`;case"invalid_key":return`Invalid key in ${r.origin}`;case"invalid_union":return"Invalid input";case"invalid_element":return`Invalid value in ${r.origin}`;default:return"Invalid input"}}};function El(){return{localeError:Hk()}}var yh,tP=Symbol("ZodOutput"),nP=Symbol("ZodInput");class bh{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==="object"&&"id"in n)this._idmap.set(n.id,e);return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);if(t&&typeof t==="object"&&"id"in t)this._idmap.delete(t.id);return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let o={...n,...this._map.get(e)};return Object.keys(o).length?o:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function jk(){return new bh}(yh=globalThis).__zod_globalRegistry??(yh.__zod_globalRegistry=jk());var ko=globalThis.__zod_globalRegistry;function xh(e,t){return new e({type:"string",...G(t)})}function wh(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...G(t)})}function Al(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...G(t)})}function _h(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...G(t)})}function kh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...G(t)})}function Sh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...G(t)})}function Ch(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...G(t)})}function Th(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...G(t)})}function Ih(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...G(t)})}function Eh(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...G(t)})}function Ah(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...G(t)})}function zh(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...G(t)})}function Ph(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...G(t)})}function Nh(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...G(t)})}function Rh(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...G(t)})}function $h(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...G(t)})}function Mh(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...G(t)})}function Lh(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...G(t)})}function Oh(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...G(t)})}function Dh(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...G(t)})}function Fh(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...G(t)})}function Bh(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...G(t)})}function Hh(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...G(t)})}function jh(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...G(t)})}function Zh(e,t){return new e({type:"string",format:"date",check:"string_format",...G(t)})}function Uh(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...G(t)})}function qh(e,t){return new e({type:"string",format:"duration",check:"string_format",...G(t)})}function Wh(e,t){return new e({type:"number",checks:[],...G(t)})}function Vh(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...G(t)})}function Gh(e,t){return new e({type:"boolean",...G(t)})}function Xh(e,t){return new e({type:"undefined",...G(t)})}function Jh(e,t){return new e({type:"null",...G(t)})}function Kh(e){return new e({type:"unknown"})}function Yh(e,t){return new e({type:"never",...G(t)})}function As(e,t){return new wl({check:"less_than",...G(t),value:e,inclusive:!1})}function ai(e,t){return new wl({check:"less_than",...G(t),value:e,inclusive:!0})}function zs(e,t){return new _l({check:"greater_than",...G(t),value:e,inclusive:!1})}function ci(e,t){return new _l({check:"greater_than",...G(t),value:e,inclusive:!0})}function Ps(e,t){return new ef({check:"multiple_of",...G(t),value:e})}function Ns(e,t){return new nf({check:"max_length",...G(t),maximum:e})}function Qo(e,t){return new of({check:"min_length",...G(t),minimum:e})}function Rs(e,t){return new rf({check:"length_equals",...G(t),length:e})}function zl(e,t){return new sf({check:"string_format",format:"regex",...G(t),pattern:e})}function Pl(e){return new af({check:"string_format",format:"lowercase",...G(e)})}function Nl(e){return new cf({check:"string_format",format:"uppercase",...G(e)})}function Rl(e,t){return new lf({check:"string_format",format:"includes",...G(t),includes:e})}function $l(e,t){return new uf({check:"string_format",format:"starts_with",...G(t),prefix:e})}function Ml(e,t){return new df({check:"string_format",format:"ends_with",...G(t),suffix:e})}function Un(e){return new pf({check:"overwrite",tx:e})}function Ll(e){return Un((t)=>t.normalize(e))}function Ol(){return Un((e)=>e.trim())}function Dl(){return Un((e)=>e.toLowerCase())}function Fl(){return Un((e)=>e.toUpperCase())}function Bl(){return Un((e)=>cm(e))}function Qh(e,t,n){return new e({type:"array",element:t,...G(n)})}function eg(e,t,n){let o=G(n);return o.abort??(o.abort=!0),new e({type:"custom",check:"custom",fn:t,...o})}function tg(e,t,n){return new e({type:"custom",check:"custom",fn:t,...G(n)})}function ng(e){let t=Zk((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(_o(o,n.value,t._zod.def));else{let r=o;if(r.fatal)r.continue=!1;r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(_o(r))}},e(n.value,n)));return t}function Zk(e,t){let n=new ut({check:"custom",...G(t)});return n._zod.check=e,n}function Hl(e){let t=e?.target??"draft-2020-12";if(t==="draft-4")t="draft-04";if(t==="draft-7")t="draft-07";return{processors:e.processors??{},metadataRegistry:e?.metadata??ko,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function et(e,t,n={path:[],schemaPath:[]}){var o;let r=e._zod.def,s=t.seen.get(e);if(s){if(s.count++,n.schemaPath.includes(e))s.cycle=n.path;return s.schema}let a={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,a);let c=e._zod.toJSONSchema?.();if(c)a.schema=c;else{let p={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,a.schema,p);else{let m=a.schema,f=t.processors[r.type];if(!f)throw Error(`[toJSONSchema]: Non-representable type encountered: ${r.type}`);f(e,t,m,p)}let d=e._zod.parent;if(d){if(!a.ref)a.ref=d;et(d,t,p),t.seen.get(d).isParent=!0}}let l=t.metadataRegistry.get(e);if(l)Object.assign(a.schema,l);if(t.io==="input"&&Ct(e))delete a.schema.examples,delete a.schema.default;if(t.io==="input"&&a.schema._prefault)(o=a.schema).default??(o.default=a.schema._prefault);return delete a.schema._prefault,t.seen.get(e).schema}function jl(e,t){let n=e.seen.get(t);if(!n)throw Error("Unprocessed schema. This is a bug in Zod.");let o=new Map;for(let a of e.seen.entries()){let c=e.metadataRegistry.get(a[0])?.id;if(c){let l=o.get(c);if(l&&l!==a[0])throw Error(`Duplicate schema id "${c}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);o.set(c,a[0])}}let r=(a)=>{let c=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let d=e.external.registry.get(a[0])?.id,m=e.external.uri??((h)=>h);if(d)return{ref:m(d)};let f=a[1].defId??a[1].schema.id??`schema${e.counter++}`;return a[1].defId=f,{defId:f,ref:`${m("__shared")}#/${c}/${f}`}}if(a[1]===n)return{ref:"#"};let u=`${"#"}/${c}/`,p=a[1].schema.id??`__schema${e.counter++}`;return{defId:p,ref:u+p}},s=(a)=>{if(a[1].schema.$ref)return;let c=a[1],{ref:l,defId:u}=r(a);if(c.def={...c.schema},u)c.defId=u;let p=c.schema;for(let d in p)delete p[d];p.$ref=l};if(e.cycles==="throw")for(let a of e.seen.entries()){let c=a[1];if(c.cycle)throw Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
|
|
59
59
|
|
|
60
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let a of e.seen.entries()){let c=a[1];if(t===a[0]){s(a);continue}if(e.external){let u=e.external.registry.get(a[0])?.id;if(t!==a[0]&&u){s(a);continue}}if(e.metadataRegistry.get(a[0])?.id){s(a);continue}if(c.cycle){s(a);continue}if(c.count>1){if(e.reused==="ref"){s(a);continue}}}}function Hl(e,t){let n=e.seen.get(t);if(!n)throw Error("Unprocessed schema. This is a bug in Zod.");let o=(a)=>{let c=e.seen.get(a);if(c.ref===null)return;let l=c.def??c.schema,u={...l},p=c.ref;if(c.ref=null,p){o(p);let f=e.seen.get(p),m=f.schema;if(m.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))l.allOf=l.allOf??[],l.allOf.push(m);else Object.assign(l,m);if(Object.assign(l,u),a._zod.parent===p)for(let v in l){if(v==="$ref"||v==="allOf")continue;if(!(v in u))delete l[v]}if(m.$ref&&f.def)for(let v in l){if(v==="$ref"||v==="allOf")continue;if(v in f.def&&JSON.stringify(l[v])===JSON.stringify(f.def[v]))delete l[v]}}let d=a._zod.parent;if(d&&d!==p){o(d);let f=e.seen.get(d);if(f?.schema.$ref){if(l.$ref=f.schema.$ref,f.def)for(let m in l){if(m==="$ref"||m==="allOf")continue;if(m in f.def&&JSON.stringify(l[m])===JSON.stringify(f.def[m]))delete l[m]}}}e.override({zodSchema:a,jsonSchema:l,path:c.path??[]})};for(let a of[...e.seen.entries()].reverse())o(a[0]);let r={};if(e.target==="draft-2020-12")r.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")r.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")r.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let a=e.external.registry.get(t)?.id;if(!a)throw Error("Schema is missing an `id` property");r.$id=e.external.uri(a)}Object.assign(r,n.def??n.schema);let s=e.external?.defs??{};for(let a of e.seen.entries()){let c=a[1];if(c.def&&c.defId)s[c.defId]=c.def}if(e.external);else if(Object.keys(s).length>0)if(e.target==="draft-2020-12")r.$defs=s;else r.definitions=s;try{let a=JSON.parse(JSON.stringify(r));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:ai(t,"input",e.processors),output:ai(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function kt(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let o=e._zod.def;if(o.type==="transform")return!0;if(o.type==="array")return kt(o.element,n);if(o.type==="set")return kt(o.valueType,n);if(o.type==="lazy")return kt(o.getter(),n);if(o.type==="promise"||o.type==="optional"||o.type==="nonoptional"||o.type==="nullable"||o.type==="readonly"||o.type==="default"||o.type==="prefault")return kt(o.innerType,n);if(o.type==="intersection")return kt(o.left,n)||kt(o.right,n);if(o.type==="record"||o.type==="map")return kt(o.keyType,n)||kt(o.valueType,n);if(o.type==="pipe")return kt(o.in,n)||kt(o.out,n);if(o.type==="object"){for(let r in o.shape)if(kt(o.shape[r],n))return!0;return!1}if(o.type==="union"){for(let r of o.options)if(kt(r,n))return!0;return!1}if(o.type==="tuple"){for(let r of o.items)if(kt(r,n))return!0;if(o.rest&&kt(o.rest,n))return!0;return!1}return!1}var rg=(e,t={})=>(n)=>{let o=Fl({...n,processors:t});return Qe(e,o),Bl(o,e),Hl(o,e)},ai=(e,t,n={})=>(o)=>{let{libraryOptions:r,target:s}=o??{},a=Fl({...r??{},target:s,io:t,processors:n});return Qe(e,a),Bl(a,e),Hl(a,e)};var BS={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},ig=(e,t,n,o)=>{let r=n;r.type="string";let{minimum:s,maximum:a,format:c,patterns:l,contentEncoding:u}=e._zod.bag;if(typeof s==="number")r.minLength=s;if(typeof a==="number")r.maxLength=a;if(c){if(r.format=BS[c]??c,r.format==="")delete r.format;if(c==="time")delete r.format}if(u)r.contentEncoding=u;if(l&&l.size>0){let p=[...l];if(p.length===1)r.pattern=p[0].source;else if(p.length>1)r.allOf=[...p.map((d)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:d.source}))]}},sg=(e,t,n,o)=>{let r=n,{minimum:s,maximum:a,format:c,multipleOf:l,exclusiveMaximum:u,exclusiveMinimum:p}=e._zod.bag;if(typeof c==="string"&&c.includes("int"))r.type="integer";else r.type="number";if(typeof p==="number")if(t.target==="draft-04"||t.target==="openapi-3.0")r.minimum=p,r.exclusiveMinimum=!0;else r.exclusiveMinimum=p;if(typeof s==="number"){if(r.minimum=s,typeof p==="number"&&t.target!=="draft-04")if(p>=s)delete r.minimum;else delete r.exclusiveMinimum}if(typeof u==="number")if(t.target==="draft-04"||t.target==="openapi-3.0")r.maximum=u,r.exclusiveMaximum=!0;else r.exclusiveMaximum=u;if(typeof a==="number"){if(r.maximum=a,typeof u==="number"&&t.target!=="draft-04")if(u<=a)delete r.maximum;else delete r.exclusiveMaximum}if(typeof l==="number")r.multipleOf=l},ag=(e,t,n,o)=>{n.type="boolean"};var cg=(e,t,n,o)=>{if(t.target==="openapi-3.0")n.type="string",n.nullable=!0,n.enum=[null];else n.type="null"},lg=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Undefined cannot be represented in JSON Schema")};var ug=(e,t,n,o)=>{n.not={}};var dg=(e,t,n,o)=>{};var pg=(e,t,n,o)=>{let r=e._zod.def,s=ms(r.entries);if(s.every((a)=>typeof a==="number"))n.type="number";if(s.every((a)=>typeof a==="string"))n.type="string";n.enum=s},mg=(e,t,n,o)=>{let r=e._zod.def,s=[];for(let a of r.values)if(a===void 0){if(t.unrepresentable==="throw")throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof a==="bigint")if(t.unrepresentable==="throw")throw Error("BigInt literals cannot be represented in JSON Schema");else s.push(Number(a));else s.push(a);if(s.length===0);else if(s.length===1){let a=s[0];if(n.type=a===null?"null":typeof a,t.target==="draft-04"||t.target==="openapi-3.0")n.enum=[a];else n.const=a}else{if(s.every((a)=>typeof a==="number"))n.type="number";if(s.every((a)=>typeof a==="string"))n.type="string";if(s.every((a)=>typeof a==="boolean"))n.type="boolean";if(s.every((a)=>a===null))n.type="null";n.enum=s}};var fg=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Custom types cannot be represented in JSON Schema")};var hg=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Transforms cannot be represented in JSON Schema")};var gg=(e,t,n,o)=>{let r=n,s=e._zod.def,{minimum:a,maximum:c}=e._zod.bag;if(typeof a==="number")r.minItems=a;if(typeof c==="number")r.maxItems=c;r.type="array",r.items=Qe(s.element,t,{...o,path:[...o.path,"items"]})},vg=(e,t,n,o)=>{let r=n,s=e._zod.def;r.type="object",r.properties={};let a=s.shape;for(let u in a)r.properties[u]=Qe(a[u],t,{...o,path:[...o.path,"properties",u]});let c=new Set(Object.keys(a)),l=new Set([...c].filter((u)=>{let p=s.shape[u]._zod;if(t.io==="input")return p.optin===void 0;else return p.optout===void 0}));if(l.size>0)r.required=Array.from(l);if(s.catchall?._zod.def.type==="never")r.additionalProperties=!1;else if(!s.catchall){if(t.io==="output")r.additionalProperties=!1}else if(s.catchall)r.additionalProperties=Qe(s.catchall,t,{...o,path:[...o.path,"additionalProperties"]})},yg=(e,t,n,o)=>{let r=e._zod.def,s=r.inclusive===!1,a=r.options.map((c,l)=>Qe(c,t,{...o,path:[...o.path,s?"oneOf":"anyOf",l]}));if(s)n.oneOf=a;else n.anyOf=a},bg=(e,t,n,o)=>{let r=e._zod.def,s=Qe(r.left,t,{...o,path:[...o.path,"allOf",0]}),a=Qe(r.right,t,{...o,path:[...o.path,"allOf",1]}),c=(u)=>("allOf"in u)&&Object.keys(u).length===1,l=[...c(s)?s.allOf:[s],...c(a)?a.allOf:[a]];n.allOf=l};var xg=(e,t,n,o)=>{let r=n,s=e._zod.def;r.type="object";let a=s.keyType,l=a._zod.bag?.patterns;if(s.mode==="loose"&&l&&l.size>0){let p=Qe(s.valueType,t,{...o,path:[...o.path,"patternProperties","*"]});r.patternProperties={};for(let d of l)r.patternProperties[d.source]=p}else{if(t.target==="draft-07"||t.target==="draft-2020-12")r.propertyNames=Qe(s.keyType,t,{...o,path:[...o.path,"propertyNames"]});r.additionalProperties=Qe(s.valueType,t,{...o,path:[...o.path,"additionalProperties"]})}let u=a._zod.values;if(u){let p=[...u].filter((d)=>typeof d==="string"||typeof d==="number");if(p.length>0)r.required=p}},wg=(e,t,n,o)=>{let r=e._zod.def,s=Qe(r.innerType,t,o),a=t.seen.get(e);if(t.target==="openapi-3.0")a.ref=r.innerType,n.nullable=!0;else n.anyOf=[s,{type:"null"}]},_g=(e,t,n,o)=>{let r=e._zod.def;Qe(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType},Sg=(e,t,n,o)=>{let r=e._zod.def;Qe(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.default=JSON.parse(JSON.stringify(r.defaultValue))},kg=(e,t,n,o)=>{let r=e._zod.def;Qe(r.innerType,t,o);let s=t.seen.get(e);if(s.ref=r.innerType,t.io==="input")n._prefault=JSON.parse(JSON.stringify(r.defaultValue))},Cg=(e,t,n,o)=>{let r=e._zod.def;Qe(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType;let a;try{a=r.catchValue(void 0)}catch{throw Error("Dynamic catch values are not supported in JSON Schema")}n.default=a},Tg=(e,t,n,o)=>{let r=e._zod.def,s=t.io==="input"?r.in._zod.def.type==="transform"?r.out:r.in:r.out;Qe(s,t,o);let a=t.seen.get(e);a.ref=s},Ig=(e,t,n,o)=>{let r=e._zod.def;Qe(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.readOnly=!0};var jl=(e,t,n,o)=>{let r=e._zod.def;Qe(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType};var GS=O("ZodISODateTime",(e,t)=>{Mf.init(e,t),Ue.init(e,t)});function Zl(e){return Zh(GS,e)}var XS=O("ZodISODate",(e,t)=>{Of.init(e,t),Ue.init(e,t)});function Eg(e){return Uh(XS,e)}var JS=O("ZodISOTime",(e,t)=>{Lf.init(e,t),Ue.init(e,t)});function Ag(e){return qh(JS,e)}var KS=O("ZodISODuration",(e,t)=>{Df.init(e,t),Ue.init(e,t)});function zg(e){return Wh(KS,e)}var Pg=(e,t)=>{vs.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:(n)=>vm(e,n)},flatten:{value:(n)=>gm(e,n)},addIssue:{value:(n)=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Qr,2)}},addIssues:{value:(n)=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Qr,2)}},isEmpty:{get(){return e.issues.length===0}}})},IP=O("ZodError",Pg),Rt=O("ZodError",Pg,{Parent:Error});var Ng=ys(Rt),Rg=bs(Rt),$g=ti(Rt),Mg=oi(Rt),Og=ym(Rt),Lg=bm(Rt),Dg=xm(Rt),Fg=wm(Rt),Bg=_m(Rt),Hg=Sm(Rt),jg=km(Rt),Zg=Cm(Rt);var He=O("ZodType",(e,t)=>(Oe.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:ai(e,"input"),output:ai(e,"output")}}),e.toJSONSchema=rg(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Hn(t,{checks:[...t.checks??[],...n.map((o)=>typeof o==="function"?{_zod:{check:o,def:{check:"custom"},onattach:[]}}:o)]}),{parent:!0}),e.with=e.check,e.clone=(n,o)=>cn(e,n,o),e.brand=()=>e,e.register=(n,o)=>(n.add(e,o),e),e.parse=(n,o)=>Ng(e,n,o,{callee:e.parse}),e.safeParse=(n,o)=>$g(e,n,o),e.parseAsync=async(n,o)=>Rg(e,n,o,{callee:e.parseAsync}),e.safeParseAsync=async(n,o)=>Mg(e,n,o),e.spa=e.safeParseAsync,e.encode=(n,o)=>Og(e,n,o),e.decode=(n,o)=>Lg(e,n,o),e.encodeAsync=async(n,o)=>Dg(e,n,o),e.decodeAsync=async(n,o)=>Fg(e,n,o),e.safeEncode=(n,o)=>Bg(e,n,o),e.safeDecode=(n,o)=>Hg(e,n,o),e.safeEncodeAsync=async(n,o)=>jg(e,n,o),e.safeDecodeAsync=async(n,o)=>Zg(e,n,o),e.refine=(n,o)=>e.check(Zk(n,o)),e.superRefine=(n)=>e.check(Uk(n)),e.overwrite=(n)=>e.check(Un(n)),e.optional=()=>Ve(e),e.exactOptional=()=>Pk(e),e.nullable=()=>Wg(e),e.nullish=()=>Ve(Wg(e)),e.nonoptional=(n)=>Lk(e,n),e.array=()=>re(e),e.or=(n)=>he([e,n]),e.and=(n)=>Ps(e,n),e.transform=(n)=>Wl(e,Yg(n)),e.default=(n)=>$k(e,n),e.prefault=(n)=>Ok(e,n),e.catch=(n)=>Fk(e,n),e.pipe=(n)=>Wl(e,n),e.readonly=()=>jk(e),e.describe=(n)=>{let o=e.clone();return ko.add(o,{description:n}),o},Object.defineProperty(e,"description",{get(){return ko.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return ko.get(e);let o=e.clone();return ko.add(o,n[0]),o},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=(n)=>n(e),e)),Vg=O("_ZodString",(e,t)=>{ks.init(e,t),He.init(e,t),e._zod.processJSONSchema=(o,r,s)=>ig(e,o,r,s);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...o)=>e.check(El(...o)),e.includes=(...o)=>e.check(Pl(...o)),e.startsWith=(...o)=>e.check(Nl(...o)),e.endsWith=(...o)=>e.check(Rl(...o)),e.min=(...o)=>e.check(Yo(...o)),e.max=(...o)=>e.check(Es(...o)),e.length=(...o)=>e.check(As(...o)),e.nonempty=(...o)=>e.check(Yo(1,...o)),e.lowercase=(o)=>e.check(Al(o)),e.uppercase=(o)=>e.check(zl(o)),e.trim=()=>e.check(Ml()),e.normalize=(...o)=>e.check($l(...o)),e.toLowerCase=()=>e.check(Ol()),e.toUpperCase=()=>e.check(Ll()),e.slugify=()=>e.check(Dl())}),ek=O("ZodString",(e,t)=>{ks.init(e,t),Vg.init(e,t),e.email=(n)=>e.check(_h(tk,n)),e.url=(n)=>e.check(Ih(nk,n)),e.jwt=(n)=>e.check(jh(vk,n)),e.emoji=(n)=>e.check(Eh(ok,n)),e.guid=(n)=>e.check(Il(Ug,n)),e.uuid=(n)=>e.check(Sh(zs,n)),e.uuidv4=(n)=>e.check(kh(zs,n)),e.uuidv6=(n)=>e.check(Ch(zs,n)),e.uuidv7=(n)=>e.check(Th(zs,n)),e.nanoid=(n)=>e.check(Ah(rk,n)),e.guid=(n)=>e.check(Il(Ug,n)),e.cuid=(n)=>e.check(zh(ik,n)),e.cuid2=(n)=>e.check(Ph(sk,n)),e.ulid=(n)=>e.check(Nh(ak,n)),e.base64=(n)=>e.check(Fh(fk,n)),e.base64url=(n)=>e.check(Bh(hk,n)),e.xid=(n)=>e.check(Rh(ck,n)),e.ksuid=(n)=>e.check($h(lk,n)),e.ipv4=(n)=>e.check(Mh(uk,n)),e.ipv6=(n)=>e.check(Oh(dk,n)),e.cidrv4=(n)=>e.check(Lh(pk,n)),e.cidrv6=(n)=>e.check(Dh(mk,n)),e.e164=(n)=>e.check(Hh(gk,n)),e.datetime=(n)=>e.check(Zl(n)),e.date=(n)=>e.check(Eg(n)),e.time=(n)=>e.check(Ag(n)),e.duration=(n)=>e.check(zg(n))});function C(e){return wh(ek,e)}var Ue=O("ZodStringFormat",(e,t)=>{Be.init(e,t),Vg.init(e,t)}),tk=O("ZodEmail",(e,t)=>{Tf.init(e,t),Ue.init(e,t)});var Ug=O("ZodGUID",(e,t)=>{kf.init(e,t),Ue.init(e,t)});var zs=O("ZodUUID",(e,t)=>{Cf.init(e,t),Ue.init(e,t)});var nk=O("ZodURL",(e,t)=>{If.init(e,t),Ue.init(e,t)});var ok=O("ZodEmoji",(e,t)=>{Ef.init(e,t),Ue.init(e,t)});var rk=O("ZodNanoID",(e,t)=>{Af.init(e,t),Ue.init(e,t)});var ik=O("ZodCUID",(e,t)=>{zf.init(e,t),Ue.init(e,t)});var sk=O("ZodCUID2",(e,t)=>{Pf.init(e,t),Ue.init(e,t)});var ak=O("ZodULID",(e,t)=>{Nf.init(e,t),Ue.init(e,t)});var ck=O("ZodXID",(e,t)=>{Rf.init(e,t),Ue.init(e,t)});var lk=O("ZodKSUID",(e,t)=>{$f.init(e,t),Ue.init(e,t)});var uk=O("ZodIPv4",(e,t)=>{Ff.init(e,t),Ue.init(e,t)});var dk=O("ZodIPv6",(e,t)=>{Bf.init(e,t),Ue.init(e,t)});var pk=O("ZodCIDRv4",(e,t)=>{Hf.init(e,t),Ue.init(e,t)});var mk=O("ZodCIDRv6",(e,t)=>{jf.init(e,t),Ue.init(e,t)});var fk=O("ZodBase64",(e,t)=>{Uf.init(e,t),Ue.init(e,t)});var hk=O("ZodBase64URL",(e,t)=>{qf.init(e,t),Ue.init(e,t)});var gk=O("ZodE164",(e,t)=>{Wf.init(e,t),Ue.init(e,t)});var vk=O("ZodJWT",(e,t)=>{Vf.init(e,t),Ue.init(e,t)});var Gg=O("ZodNumber",(e,t)=>{Sl.init(e,t),He.init(e,t),e._zod.processJSONSchema=(o,r,s)=>sg(e,o,r,s),e.gt=(o,r)=>e.check(Ts(o,r)),e.gte=(o,r)=>e.check(si(o,r)),e.min=(o,r)=>e.check(si(o,r)),e.lt=(o,r)=>e.check(Cs(o,r)),e.lte=(o,r)=>e.check(ii(o,r)),e.max=(o,r)=>e.check(ii(o,r)),e.int=(o)=>e.check(qg(o)),e.safe=(o)=>e.check(qg(o)),e.positive=(o)=>e.check(Ts(0,o)),e.nonnegative=(o)=>e.check(si(0,o)),e.negative=(o)=>e.check(Cs(0,o)),e.nonpositive=(o)=>e.check(ii(0,o)),e.multipleOf=(o,r)=>e.check(Is(o,r)),e.step=(o,r)=>e.check(Is(o,r)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??0.5),e.isFinite=!0,e.format=n.format??null});function ce(e){return Vh(Gg,e)}var yk=O("ZodNumberFormat",(e,t)=>{Gf.init(e,t),Gg.init(e,t)});function qg(e){return Gh(yk,e)}var bk=O("ZodBoolean",(e,t)=>{Xf.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>ag(e,n,o,r)});function Re(e){return Xh(bk,e)}var xk=O("ZodUndefined",(e,t)=>{Jf.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>lg(e,n,o,r)});function Vl(e){return Jh(xk,e)}var wk=O("ZodNull",(e,t)=>{Kf.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>cg(e,n,o,r)});function Gl(e){return Kh(wk,e)}var _k=O("ZodUnknown",(e,t)=>{Yf.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>dg(e,n,o,r)});function ze(){return Yh(_k)}var Sk=O("ZodNever",(e,t)=>{Qf.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>ug(e,n,o,r)});function Xg(e){return Qh(Sk,e)}var kk=O("ZodArray",(e,t)=>{eh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>gg(e,n,o,r),e.element=t.element,e.min=(n,o)=>e.check(Yo(n,o)),e.nonempty=(n)=>e.check(Yo(1,n)),e.max=(n,o)=>e.check(Es(n,o)),e.length=(n,o)=>e.check(As(n,o)),e.unwrap=()=>e.element});function re(e,t){return eg(kk,e,t)}var Xl=O("ZodObject",(e,t)=>{oh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>vg(e,n,o,r),Se(e,"shape",()=>t.shape),e.keyof=()=>Tt(Object.keys(e._zod.def.shape)),e.catchall=(n)=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:ze()}),e.loose=()=>e.clone({...e._zod.def,catchall:ze()}),e.strict=()=>e.clone({...e._zod.def,catchall:Xg()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=(n)=>CS(e,n),e.safeExtend=(n)=>TS(e,n),e.merge=(n)=>IS(e,n),e.pick=(n)=>SS(e,n),e.omit=(n)=>kS(e,n),e.partial=(...n)=>ES(Qg,e,n[0]),e.required=(...n)=>AS(ev,e,n[0])});function A(e,t){let n={type:"object",shape:e??{},...G(t)};return new Xl(n)}function Jg(e,t){return new Xl({type:"object",shape:e,catchall:Xg(),...G(t)})}function Ct(e,t){return new Xl({type:"object",shape:e,catchall:ze(),...G(t)})}var Kg=O("ZodUnion",(e,t)=>{kl.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>yg(e,n,o,r),e.options=t.options});function he(e,t){return new Kg({type:"union",options:e,...G(t)})}var Ck=O("ZodDiscriminatedUnion",(e,t)=>{Kg.init(e,t),rh.init(e,t)});function Jl(e,t,n){return new Ck({type:"union",options:t,discriminator:e,...G(n)})}var Tk=O("ZodIntersection",(e,t)=>{ih.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>bg(e,n,o,r)});function Ps(e,t){return new Tk({type:"intersection",left:e,right:t})}var Ik=O("ZodRecord",(e,t)=>{sh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>xg(e,n,o,r),e.keyType=t.keyType,e.valueType=t.valueType});function Ee(e,t,n){return new Ik({type:"record",keyType:e,valueType:t,...G(n)})}var ql=O("ZodEnum",(e,t)=>{ah.init(e,t),He.init(e,t),e._zod.processJSONSchema=(o,r,s)=>pg(e,o,r,s),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(o,r)=>{let s={};for(let a of o)if(n.has(a))s[a]=t.entries[a];else throw Error(`Key ${a} not found in enum`);return new ql({...t,checks:[],...G(r),entries:s})},e.exclude=(o,r)=>{let s={...t.entries};for(let a of o)if(n.has(a))delete s[a];else throw Error(`Key ${a} not found in enum`);return new ql({...t,checks:[],...G(r),entries:s})}});function Tt(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map((o)=>[o,o])):e;return new ql({type:"enum",entries:n,...G(t)})}var Ek=O("ZodLiteral",(e,t)=>{ch.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>mg(e,n,o,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function k(e,t){return new Ek({type:"literal",values:Array.isArray(e)?e:[e],...G(t)})}var Ak=O("ZodTransform",(e,t)=>{lh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>hg(e,n,o,r),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new Yr(e.constructor.name);n.addIssue=(s)=>{if(typeof s==="string")n.issues.push(So(s,n.value,t));else{let a=s;if(a.fatal)a.continue=!1;a.code??(a.code="custom"),a.input??(a.input=n.value),a.inst??(a.inst=e),n.issues.push(So(a))}};let r=t.transform(n.value,n);if(r instanceof Promise)return r.then((s)=>(n.value=s,n));return n.value=r,n}});function Yg(e){return new Ak({type:"transform",transform:e})}var Qg=O("ZodOptional",(e,t)=>{Cl.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>jl(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function Ve(e){return new Qg({type:"optional",innerType:e})}var zk=O("ZodExactOptional",(e,t)=>{uh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>jl(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function Pk(e){return new zk({type:"optional",innerType:e})}var Nk=O("ZodNullable",(e,t)=>{dh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>wg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function Wg(e){return new Nk({type:"nullable",innerType:e})}var Rk=O("ZodDefault",(e,t)=>{ph.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Sg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function $k(e,t){return new Rk({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():ml(t)}})}var Mk=O("ZodPrefault",(e,t)=>{mh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>kg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function Ok(e,t){return new Mk({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():ml(t)}})}var ev=O("ZodNonOptional",(e,t)=>{fh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>_g(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function Lk(e,t){return new ev({type:"nonoptional",innerType:e,...G(t)})}var Dk=O("ZodCatch",(e,t)=>{hh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Cg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Fk(e,t){return new Dk({type:"catch",innerType:e,catchValue:typeof t==="function"?t:()=>t})}var Bk=O("ZodPipe",(e,t)=>{gh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Tg(e,n,o,r),e.in=t.in,e.out=t.out});function Wl(e,t){return new Bk({type:"pipe",in:e,out:t})}var Hk=O("ZodReadonly",(e,t)=>{vh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ig(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function jk(e){return new Hk({type:"readonly",innerType:e})}var tv=O("ZodCustom",(e,t)=>{yh.init(e,t),He.init(e,t),e._zod.processJSONSchema=(n,o,r)=>fg(e,n,o,r)});function nv(e,t){return tg(tv,e??(()=>!0),t)}function Zk(e,t={}){return ng(tv,e,t)}function Uk(e){return og(e)}function Kl(e,t){return Wl(Yg(e),t)}jt(Tl());var Yl=A({x:ce(),y:ce(),scale:ce().positive()}),qk=A({target:he([Jg({nodeId:C().min(1)}),Jg({viewport:Yl})]),duration:ce().nonnegative().max(3600).optional(),easing:Tt(["linear","ease-in-out","ease-out"]).optional(),padding:ce().nonnegative().optional(),pullback:ce().min(0).max(4).optional()}),jN=A({stops:re(qk).max(1000)});function ov(e,t,n,o){if("viewport"in e.target)return e.target.viewport;let r=e.target.nodeId,s=t.find((l)=>l.id===r);if(!s)throw Error(`Tour target not found: ${r}`);let a=e.padding??40;if(a*2>=Math.min(n,o))throw Error("Tour padding exceeds viewport");let c=Math.min((n-a*2)/s.size.width,(o-a*2)/s.size.height);return{x:n/2-(s.position.x+s.size.width/2)*c,y:o/2-(s.position.y+s.size.height/2)*c,scale:c}}function rv(e,t,n,o,r,s="ease-in-out",a=0){let c=Math.max(0,Math.min(1,n));if(c===0)return{...e};if(c===1)return{...t};let l=s==="linear"?c:s==="ease-out"?1-(1-c)**3:c*c*(3-2*c),u=Math.exp(Math.log(e.scale)*(1-l)+Math.log(t.scale)*l-a*Math.sin(Math.PI*l)),p=(o/2-e.x)/e.scale*(1-l)+(o/2-t.x)/t.scale*l,d=(r/2-e.y)/e.scale*(1-l)+(r/2-t.y)/t.scale*l;return{x:o/2-p*u,y:r/2-d*u,scale:u}}var Ql=null;function iv(e){Ql=e}function rt(){if(Ql?.isConnected){let e=Ql.getBoundingClientRect();if(e.width>0&&e.height>0)return{left:e.left,top:e.top,width:e.width,height:e.height}}return{left:0,top:0,width:window.innerWidth,height:window.innerHeight}}function qn(){let e=rt();return{x:e.left+e.width/2,y:e.top+e.height/2}}function eu(){let e=16;try{let t=rt(),n=t.top+t.height;for(let o of[".command-bar",".minimap"]){let r=document.querySelector(o);if(!(r instanceof HTMLElement)||!r.isConnected)continue;let s=r.getBoundingClientRect();if(s.height<=0)continue;let a=n-s.top;if(a>0)e=Math.max(e,a+12)}}catch{}return{top:16,right:16,bottom:e,left:16}}var Wk=Symbol.for("preact-signals");function Os(){if(!(yn>1)){var e,t=!1;(function(){var r=$s;$s=void 0;while(r!==void 0){if(r.S.v===r.v)r.S.i=r.i;r=r.o}})();while(li!==void 0){var n=li;li=void 0,Rs++;while(n!==void 0){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&cv(n))try{n.c()}catch(r){if(!t)e=r,t=!0}n=o}}if(Rs=0,yn--,t)throw e}else yn--}function $t(e){if(yn>0)return e();tu=++Vk,yn++;try{return e()}finally{Os()}}var ke=void 0;function nu(e){var t=ke;ke=void 0;try{return e()}finally{ke=t}}var sv,li=void 0,yn=0,Rs=0,Vk=0,tu=0,$s=void 0,Ms=0;function av(e){if(ke!==void 0){var t=e.n;if(t===void 0||t.t!==ke){if(t={i:0,S:e,p:ke.s,n:void 0,t:ke,e:void 0,x:void 0,r:t},ke.s!==void 0)ke.s.n=t;if(ke.s=t,e.n=t,32&ke.f)e.S(t);return t}else if(t.i===-1){if(t.i=0,t.n!==void 0){if(t.n.p=t.p,t.p!==void 0)t.p.n=t.n;t.p=ke.s,t.n=void 0,ke.s.n=t,ke.s=t}return t}}}function it(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}it.prototype.brand=Wk;it.prototype.h=function(){return!0};it.prototype.S=function(e){var t=this,n=this.t;if(n!==e&&e.e===void 0)if(e.x=n,this.t=e,n!==void 0)n.e=e;else nu(function(){var o;(o=t.W)==null||o.call(t)})};it.prototype.U=function(e){var t=this;if(this.t!==void 0){var{e:n,x:o}=e;if(n!==void 0)n.x=o,e.e=void 0;if(o!==void 0)o.e=n,e.x=void 0;if(e===this.t){if(this.t=o,o===void 0)nu(function(){var r;(r=t.Z)==null||r.call(t)})}}};it.prototype.subscribe=function(e){var t=this;return Zt(function(){var n=t.value,o=ke;ke=void 0;try{e(n)}finally{ke=o}},{name:"sub"})};it.prototype.valueOf=function(){return this.value};it.prototype.toString=function(){return this.value+""};it.prototype.toJSON=function(){return this.value};it.prototype.peek=function(){var e=ke;ke=void 0;try{return this.value}finally{ke=e}};Object.defineProperty(it.prototype,"value",{get:function(){var e=av(this);if(e!==void 0)e.i=this.i;return this.v},set:function(e){if(e!==this.v){if(Rs>100)throw Error("Cycle detected");(function(n){if(yn!==0&&Rs===0){if(n.l!==tu)n.l=tu,$s={S:n,v:n.v,i:n.i,o:$s}}})(this),this.v=e,this.i++,Ms++,yn++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Os()}}}});function q(e,t){return new it(e,t)}function cv(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function lv(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0)t.r=n;if(t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function uv(e){var t=e.s,n=void 0;while(t!==void 0){var o=t.p;if(t.i===-1){if(t.S.U(t),o!==void 0)o.n=t.n;if(t.n!==void 0)t.n.p=o}else n=t;if(t.S.n=t.r,t.r!==void 0)t.r=void 0;t=o}e.s=n}function Co(e,t){it.call(this,void 0),this.x=e,this.s=void 0,this.g=Ms-1,this.f=4,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}Co.prototype=new it;Co.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32)return!0;if(this.f&=-5,this.g===Ms)return!0;if(this.g=Ms,this.f|=1,this.i>0&&!cv(this))return this.f&=-2,!0;var e=ke;try{lv(this),ke=this;var t=this.x();if(16&this.f||this.v!==t||this.i===0)this.v=t,this.f&=-17,this.i++}catch(n){this.v=n,this.f|=16,this.i++}return ke=e,uv(this),this.f&=-2,!0};Co.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}it.prototype.S.call(this,e)};Co.prototype.U=function(e){if(this.t!==void 0){if(it.prototype.U.call(this,e),this.t===void 0){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}}};Co.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(Co.prototype,"value",{get:function(){if(1&this.f)throw Error("Cycle detected");var e=av(this);if(this.h(),e!==void 0)e.i=this.i;if(16&this.f)throw this.v;return this.v}});function Le(e,t){return new Co(e,t)}function dv(e){var t=e.m;if(e.m=void 0,typeof t=="function"){yn++;var n=ke;ke=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,ou(e),o}finally{ke=n,Os()}}}function ou(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,dv(e)}function Gk(e){if(ke!==this)throw Error("Out-of-order effect");if(uv(this),ke=e,this.f&=-2,8&this.f)ou(this);Os()}function Qo(e,t){if(this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t==null?void 0:t.name,sv)sv.push(this)}Qo.prototype.c=function(){var e=this.S();try{if(8&this.f)return;if(this.x===void 0)return;var t=this.x();if(typeof t=="function")this.m=t}finally{e()}};Qo.prototype.S=function(){if(1&this.f)throw Error("Cycle detected");this.f|=1,this.f&=-9,dv(this),lv(this),yn++;var e=ke;return ke=this,Gk.bind(this,e)};Qo.prototype.N=function(){if(!(2&this.f))this.f|=2,this.u=li,li=this};Qo.prototype.d=function(){if(this.f|=8,!(1&this.f))ou(this)};Qo.prototype.dispose=function(){this.d()};function Zt(e,t){var n=new Qo(e,t);try{n.c()}catch(r){throw n.d(),r}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var pv,ru,Ls,Xk=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var mv=[];Zt(function(){pv=this.N})();function er(e,t){_e[e]=t.bind(null,_e[e]||function(){})}function Ds(e){if(Ls){var t=Ls;Ls=void 0,t()}Ls=e&&e.S()}function fv(e){var t=this,n=e.data,o=Kk(n);o.value=n;var r=Ie(function(){var c=t,l=t.__v;while(l=l.__)if(l.__c){l.__c.__$f|=4;break}var u=Le(function(){var m=o.value.value;return m===0?0:m===!0?"":m||""}),p=Le(function(){return!Array.isArray(u.value)&&!tl(u.value)}),d=Zt(function(){if(this.N=hv,p.value){var m=u.value;if(c.__v&&c.__v.__e&&c.__v.__e.nodeType===3)c.__v.__e.data=m}}),f=t.__$u.d;return t.__$u.d=function(){d(),f.call(this)},[p,u]},[]),s=r[0],a=r[1];return s.value?a.peek():a.value}fv.displayName="ReactiveTextNode";Object.defineProperties(it.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:fv},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});er("__b",function(e,t){if(typeof t.type=="string"){var n,o=t.props;for(var r in o)if(r!=="children"){var s=o[r];if(s instanceof it){if(!n)t.__np=n={};n[r]=s,o[r]=s.peek()}}}e(t)});er("__r",function(e,t){if(e(t),t.type!==pe){Ds();var n,o=t.__c;if(o){if(o.__$f&=-2,(n=o.__$u)===void 0)o.__$u=n=function(r,s){var a;return Zt(function(){a=this},{name:s}),a.c=r,a}(function(){var r;if(Xk)(r=n.y)==null||r.call(n);o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:"")}ru=o,Ds(n)}});er("__e",function(e,t,n,o){Ds(),ru=void 0,e(t,n,o)});er("diffed",function(e,t){Ds(),ru=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var{__np:o,props:r}=t;if(o){var s=n.U;if(s)for(var a in s){var c=s[a];if(c!==void 0&&!(a in o))c.d(),s[a]=void 0}else s={},n.U=s;for(var l in o){var u=s[l],p=o[l];if(u===void 0)u=Jk(n,l,p),s[l]=u;else u.o(p,r)}for(var d in o)r[d]=o[d]}}e(t)});function Jk(e,t,n,o){var r=t in e&&e.ownerSVGElement===void 0,s=q(n),a=n.peek();return{o:function(c,l){s.value=c,a=c.peek()},d:Zt(function(){this.N=hv;var c=s.value.value;if(a!==c)if(a=void 0,r)e[t]=c;else if(c!=null&&(c!==!1||t[4]==="-"))e.setAttribute(t,c);else e.removeAttribute(t);else a=void 0})}}er("unmount",function(e,t){if(typeof t.type=="string"){var n=t.__e;if(n){var o=n.U;if(o){n.U=void 0;for(var r in o){var s=o[r];if(s)s.d()}}}t.__np=void 0}else{var a=t.__c;if(a){var c=a.__$u;if(c)a.__$u=void 0,c.d()}}e(t)});er("__h",function(e,t,n,o){if(o<3||o===9)t.__$f|=2;e(t,n,o)});Go.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,o=n&&n.s!==void 0;for(var r in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var s=2&this.__$f;if(!(o||s||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(o||4&this.__$f))return!0;if(3&this.__$f)return!0}for(var a in e)if(a!=="__source"&&e[a]!==this.props[a])return!0;for(var c in this.props)if(!(c in e))return!0;return!1};function Kk(e,t){return Ie(function(){return q(e,t)},[])}var Yk=function(e){queueMicrotask(function(){queueMicrotask(e)})};function Qk(){$t(function(){var e;while(e=mv.shift())pv.call(e)})}function hv(){if(mv.push(this)===1)(_e.requestAnimationFrame||Yk)(Qk)}var ut={markdown:"MD","mcp-app":"APP",webpage:"WEB","json-render":"UI",graph:"GRAPH",board:"BOARD",prompt:"ASK",response:"ANS",status:"STATUS",context:"CONTEXT",ledger:"LOG",trace:"TRACE",file:"FILE",diff:"DIFF",mermaid:"MERMAID",image:"IMG",html:"HTML",group:"GROUP"},ui=new Set(["markdown","mcp-app","webpage","json-render","graph","context","ledger","file","diff","mermaid","image","html"]);function gv(e){return e.type==="mcp-app"&&e.data.mode==="ext-app"&&e.data.serverName==="Excalidraw"&&e.data.toolName==="create_view"}function vv(e){if(e.length===0)return null;let{POSITIVE_INFINITY:t,POSITIVE_INFINITY:n,NEGATIVE_INFINITY:o,NEGATIVE_INFINITY:r}=Number;for(let s of e)t=Math.min(t,s.position.x),n=Math.min(n,s.position.y),o=Math.max(o,s.position.x+s.size.width),r=Math.max(r,s.position.y+s.size.height);if(!Number.isFinite(t)||!Number.isFinite(n))return null;return{x:t-40,y:n-40-32,width:o-t+80,height:r-n+80+32}}function e0(e){let t=e.filter((l)=>!l.pinned),n=new Map(t.map((l)=>[l.id,l])),o=new Map,r=[],s=new Map;for(let l of t){if(l.type==="group")continue;let u=typeof l.data.parentGroup==="string"?l.data.parentGroup:"",p=u?n.get(u):void 0;if(!p||p.type!=="group")continue;if(!s.has(u))s.set(u,[]);s.get(u).push(l)}let a=t.filter((l)=>l.type==="group").sort((l,u)=>l.position.y-u.position.y||l.position.x-u.position.x);for(let l of a){let u=s.get(l.id)??[];if(u.length===0){let m=`unit:${l.id}`;r.push({id:m,memberIds:[l.id],origin:{...l.position},size:{...l.size},sortKey:{x:l.position.x,y:l.position.y}}),o.set(l.id,m);continue}let p=u.map((m)=>({position:m.position,size:m.size})),d=vv(p);if(!d)continue;let f=`group:${l.id}`;r.push({id:f,memberIds:u.map((m)=>m.id),origin:{x:d.x,y:d.y},size:{width:d.width,height:d.height},sortKey:{x:d.x,y:d.y},groupId:l.id}),o.set(l.id,f);for(let m of u)o.set(m.id,f)}let c=t.filter((l)=>!o.has(l.id)).sort((l,u)=>l.position.y-u.position.y||l.position.x-u.position.x);for(let l of c){let u=`unit:${l.id}`;r.push({id:u,memberIds:[l.id],origin:{...l.position},size:{...l.size},sortKey:{x:l.position.x,y:l.position.y}}),o.set(l.id,u)}return{units:r,nodesById:n,nodeToUnit:o}}function t0(e,t,n){let o=new Map,r=new Map,s=new Map,a=new Map;for(let c of e)o.set(c.id,new Set),r.set(c.id,new Set),s.set(c.id,0),a.set(c.id,0);for(let c of n){let l=t.get(c.from),u=t.get(c.to);if(!l||!u||l===u)continue;if(!o.get(l).has(u))o.get(l).add(u),a.set(l,(a.get(l)??0)+1),s.set(u,(s.get(u)??0)+1);r.get(l).add(u),r.get(u).add(l)}return{outgoing:o,undirected:r,indegree:s,outdegree:a}}function n0(e,t){let n=new Map(e.map((s)=>[s.id,s])),o=new Set,r=[];for(let s of e){if(o.has(s.id))continue;let a=[s.id],c=[];o.add(s.id);while(a.length>0){let u=a.pop();c.push(u);for(let p of t.get(u)??[]){if(o.has(p))continue;o.add(p),a.push(p)}}let l=c.map((u)=>n.get(u)).filter((u)=>u!==void 0).sort((u,p)=>u.sortKey.y-p.sortKey.y||u.sortKey.x-p.sortKey.x);r.push(l)}return r.sort((s,a)=>s[0].sortKey.y-a[0].sortKey.y||s[0].sortKey.x-a[0].sortKey.x)}function o0(e){let t=new Map,n=0,o=0,r=0,s=0,a=Math.max(900,Math.ceil(Math.sqrt(e.reduce((c,l)=>c+l.size.width*l.size.height,0))));for(let c of e){if(n>0&&n+c.size.width>a)n=0,o+=r+72,r=0;t.set(c.id,{x:n,y:o}),n+=c.size.width+96,r=Math.max(r,c.size.height),s=Math.max(s,n-96)}return{positions:t,size:{width:Math.max(0,s),height:o+r},sortKey:e[0].sortKey}}function r0(e,t,n,o,r){if(e.length===1)return{positions:new Map([[e[0].id,{x:0,y:0}]]),size:{...e[0].size},sortKey:e[0].sortKey};let s=new Set(e.map((y)=>y.id)),a=e.filter((y)=>(o.get(y.id)??0)===0&&(r.get(y.id)??0)>0).sort((y,E)=>y.sortKey.x-E.sortKey.x||y.sortKey.y-E.sortKey.y),c=a.length>0?a:[e.slice().sort((y,E)=>y.sortKey.x-E.sortKey.x||y.sortKey.y-E.sortKey.y)[0]],l=new Map,u=c.map((y)=>y.id);for(let y of c)l.set(y.id,0);while(u.length>0){let y=u.shift(),E=l.get(y)??0;for(let L of n.get(y)??[]){if(!s.has(L)||l.has(L))continue;l.set(L,E+1),u.push(L)}}let p=0;for(let y of e){if(l.has(y.id))continue;l.set(y.id,p),p+=1}let d=new Map;for(let y of e){let E=l.get(y.id)??0;if(!d.has(E))d.set(E,[]);d.get(E).push(y)}let f=Array.from(d.keys()).sort((y,E)=>y-E);for(let y of f)d.get(y).sort((E,L)=>E.sortKey.y-L.sortKey.y||E.sortKey.x-L.sortKey.x);let m=new Map,h=new Map,v=0;for(let y of f){let E=d.get(y),L=E.reduce((b,T,w)=>b+T.size.height+(w>0?72:0),0),P=Math.max(...E.map((b)=>b.size.width));m.set(y,L),h.set(y,P),v=Math.max(v,L)}let x=new Map,g=0;for(let y of f){let E=d.get(y),L=m.get(y)??0,P=h.get(y)??0,b=Math.max(0,(v-L)/2);for(let T of E)x.set(T.id,{x:g,y:b}),b+=T.size.height+72;g+=P+96}return{positions:x,size:{width:Math.max(0,g-96),height:v},sortKey:e[0].sortKey}}function i0(e,t){let n=new Map(e.map((l)=>[l.id,l.id])),o=(l)=>{let u=l;while(n.get(u)!==u)u=n.get(u);let p=l;while(n.get(p)!==p){let d=n.get(p);n.set(p,u),p=d}return u},r=(l,u)=>{let p=o(l),d=o(u);if(p!==d)n.set(p,d)},s=160;for(let l=0;l<e.length;l++)for(let u=l+1;u<e.length;u++){let p=e[l],d=e[u];if(p.origin.x-160<d.origin.x+d.size.width+160&&p.origin.x+p.size.width+160>d.origin.x-160&&p.origin.y-160<d.origin.y+d.size.height+160&&p.origin.y+p.size.height+160>d.origin.y-160)r(p.id,d.id)}for(let[l,u]of t)for(let p of u)if(n.has(l)&&n.has(p))r(l,p);let a=new Map;for(let l of e){let u=o(l.id);if(!a.has(u))a.set(u,[]);a.get(u).push(l)}let c=Array.from(a.values());for(let l of c)l.sort((u,p)=>u.sortKey.y-p.sortKey.y||u.sortKey.x-p.sortKey.x);return c.sort((l,u)=>l[0].sortKey.y-u[0].sortKey.y||l[0].sortKey.x-u[0].sortKey.x)}function s0(e,t){let n=new Map,{x:o,y:r}=t,s=0;for(let a of e){if(o>t.x&&o-t.x+a.size.width>3200)o=t.x,r+=s+180,s=0;for(let[c,l]of a.positions.entries())n.set(c,{x:o+l.x,y:r+l.y});o+=a.size.width+220,s=Math.max(s,a.size.height)}return n}function iu(e,t,n){let{units:o,nodesById:r,nodeToUnit:s}=e0(e),a=new Map,c=new Map;if(o.length===0)return{nodePositions:a,groupBounds:c};let{outgoing:l,undirected:u,indegree:p,outdegree:d}=t0(o,s,t),f=i0(o,u),m=new Map,h=[];for(let v of f){let x=n0(v,u).map((b)=>n==="graph"?r0(b,l,u,p,d):o0(b)),g={x:Math.min(...v.map((b)=>b.origin.x)),y:Math.min(...v.map((b)=>b.origin.y))},y=s0(x,g),E=new Map(v.map((b)=>[b.id,b.size])),L=(b)=>{let{POSITIVE_INFINITY:T,POSITIVE_INFINITY:w,NEGATIVE_INFINITY:_,NEGATIVE_INFINITY:z}=Number;for(let[U,N]of b){let Z=E.get(U);if(!Z)continue;T=Math.min(T,N.x),w=Math.min(w,N.y),_=Math.max(_,N.x+Z.width),z=Math.max(z,N.y+Z.height)}return{x:T,y:w,width:_-T,height:z-w}},P=y;for(let b=0;b<=h.length;b++){let T=L(P),w=h.filter((U)=>T.x<U.x+U.width+220&&T.x+T.width+220>U.x&&T.y<U.y+U.height+180&&T.y+T.height+180>U.y);if(w.length===0)break;let _=Math.max(...w.map((U)=>U.y+U.height))+180-T.y;if(_<=0)break;let z=new Map;for(let[U,N]of P)z.set(U,{x:N.x,y:N.y+_});P=z}for(let[b,T]of P)m.set(b,T);h.push(L(P))}for(let v of o){let x=m.get(v.id);if(!x)continue;let g=x.x-v.origin.x,y=x.y-v.origin.y;if(v.groupId){let P=[];for(let T of v.memberIds){let w=r.get(T);if(!w)continue;let _={x:w.position.x+g,y:w.position.y+y};a.set(T,_),P.push({position:_,size:w.size})}let b=vv(P);if(b)c.set(v.groupId,b);continue}let E=v.memberIds[0],L=r.get(E);if(!L)continue;a.set(E,{x:L.position.x+g,y:L.position.y+y})}return{nodePositions:a,groupBounds:c}}var a0=700,c0=1600;function l0(e){return e.replace(/\r\n?/g,`
|
|
60
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let a of e.seen.entries()){let c=a[1];if(t===a[0]){s(a);continue}if(e.external){let u=e.external.registry.get(a[0])?.id;if(t!==a[0]&&u){s(a);continue}}if(e.metadataRegistry.get(a[0])?.id){s(a);continue}if(c.cycle){s(a);continue}if(c.count>1){if(e.reused==="ref"){s(a);continue}}}}function Zl(e,t){let n=e.seen.get(t);if(!n)throw Error("Unprocessed schema. This is a bug in Zod.");let o=(a)=>{let c=e.seen.get(a);if(c.ref===null)return;let l=c.def??c.schema,u={...l},p=c.ref;if(c.ref=null,p){o(p);let m=e.seen.get(p),f=m.schema;if(f.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))l.allOf=l.allOf??[],l.allOf.push(f);else Object.assign(l,f);if(Object.assign(l,u),a._zod.parent===p)for(let v in l){if(v==="$ref"||v==="allOf")continue;if(!(v in u))delete l[v]}if(f.$ref&&m.def)for(let v in l){if(v==="$ref"||v==="allOf")continue;if(v in m.def&&JSON.stringify(l[v])===JSON.stringify(m.def[v]))delete l[v]}}let d=a._zod.parent;if(d&&d!==p){o(d);let m=e.seen.get(d);if(m?.schema.$ref){if(l.$ref=m.schema.$ref,m.def)for(let f in l){if(f==="$ref"||f==="allOf")continue;if(f in m.def&&JSON.stringify(l[f])===JSON.stringify(m.def[f]))delete l[f]}}}e.override({zodSchema:a,jsonSchema:l,path:c.path??[]})};for(let a of[...e.seen.entries()].reverse())o(a[0]);let r={};if(e.target==="draft-2020-12")r.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")r.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")r.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let a=e.external.registry.get(t)?.id;if(!a)throw Error("Schema is missing an `id` property");r.$id=e.external.uri(a)}Object.assign(r,n.def??n.schema);let s=e.external?.defs??{};for(let a of e.seen.entries()){let c=a[1];if(c.def&&c.defId)s[c.defId]=c.def}if(e.external);else if(Object.keys(s).length>0)if(e.target==="draft-2020-12")r.$defs=s;else r.definitions=s;try{let a=JSON.parse(JSON.stringify(r));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:li(t,"input",e.processors),output:li(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function Ct(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let o=e._zod.def;if(o.type==="transform")return!0;if(o.type==="array")return Ct(o.element,n);if(o.type==="set")return Ct(o.valueType,n);if(o.type==="lazy")return Ct(o.getter(),n);if(o.type==="promise"||o.type==="optional"||o.type==="nonoptional"||o.type==="nullable"||o.type==="readonly"||o.type==="default"||o.type==="prefault")return Ct(o.innerType,n);if(o.type==="intersection")return Ct(o.left,n)||Ct(o.right,n);if(o.type==="record"||o.type==="map")return Ct(o.keyType,n)||Ct(o.valueType,n);if(o.type==="pipe")return Ct(o.in,n)||Ct(o.out,n);if(o.type==="object"){for(let r in o.shape)if(Ct(o.shape[r],n))return!0;return!1}if(o.type==="union"){for(let r of o.options)if(Ct(r,n))return!0;return!1}if(o.type==="tuple"){for(let r of o.items)if(Ct(r,n))return!0;if(o.rest&&Ct(o.rest,n))return!0;return!1}return!1}var og=(e,t={})=>(n)=>{let o=Hl({...n,processors:t});return et(e,o),jl(o,e),Zl(o,e)},li=(e,t,n={})=>(o)=>{let{libraryOptions:r,target:s}=o??{},a=Hl({...r??{},target:s,io:t,processors:n});return et(e,a),jl(a,e),Zl(a,e)};var Uk={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},rg=(e,t,n,o)=>{let r=n;r.type="string";let{minimum:s,maximum:a,format:c,patterns:l,contentEncoding:u}=e._zod.bag;if(typeof s==="number")r.minLength=s;if(typeof a==="number")r.maxLength=a;if(c){if(r.format=Uk[c]??c,r.format==="")delete r.format;if(c==="time")delete r.format}if(u)r.contentEncoding=u;if(l&&l.size>0){let p=[...l];if(p.length===1)r.pattern=p[0].source;else if(p.length>1)r.allOf=[...p.map((d)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:d.source}))]}},ig=(e,t,n,o)=>{let r=n,{minimum:s,maximum:a,format:c,multipleOf:l,exclusiveMaximum:u,exclusiveMinimum:p}=e._zod.bag;if(typeof c==="string"&&c.includes("int"))r.type="integer";else r.type="number";if(typeof p==="number")if(t.target==="draft-04"||t.target==="openapi-3.0")r.minimum=p,r.exclusiveMinimum=!0;else r.exclusiveMinimum=p;if(typeof s==="number"){if(r.minimum=s,typeof p==="number"&&t.target!=="draft-04")if(p>=s)delete r.minimum;else delete r.exclusiveMinimum}if(typeof u==="number")if(t.target==="draft-04"||t.target==="openapi-3.0")r.maximum=u,r.exclusiveMaximum=!0;else r.exclusiveMaximum=u;if(typeof a==="number"){if(r.maximum=a,typeof u==="number"&&t.target!=="draft-04")if(u<=a)delete r.maximum;else delete r.exclusiveMaximum}if(typeof l==="number")r.multipleOf=l},sg=(e,t,n,o)=>{n.type="boolean"};var ag=(e,t,n,o)=>{if(t.target==="openapi-3.0")n.type="string",n.nullable=!0,n.enum=[null];else n.type="null"},cg=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Undefined cannot be represented in JSON Schema")};var lg=(e,t,n,o)=>{n.not={}};var ug=(e,t,n,o)=>{};var dg=(e,t,n,o)=>{let r=e._zod.def,s=vs(r.entries);if(s.every((a)=>typeof a==="number"))n.type="number";if(s.every((a)=>typeof a==="string"))n.type="string";n.enum=s},pg=(e,t,n,o)=>{let r=e._zod.def,s=[];for(let a of r.values)if(a===void 0){if(t.unrepresentable==="throw")throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof a==="bigint")if(t.unrepresentable==="throw")throw Error("BigInt literals cannot be represented in JSON Schema");else s.push(Number(a));else s.push(a);if(s.length===0);else if(s.length===1){let a=s[0];if(n.type=a===null?"null":typeof a,t.target==="draft-04"||t.target==="openapi-3.0")n.enum=[a];else n.const=a}else{if(s.every((a)=>typeof a==="number"))n.type="number";if(s.every((a)=>typeof a==="string"))n.type="string";if(s.every((a)=>typeof a==="boolean"))n.type="boolean";if(s.every((a)=>a===null))n.type="null";n.enum=s}};var mg=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Custom types cannot be represented in JSON Schema")};var fg=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Transforms cannot be represented in JSON Schema")};var hg=(e,t,n,o)=>{let r=n,s=e._zod.def,{minimum:a,maximum:c}=e._zod.bag;if(typeof a==="number")r.minItems=a;if(typeof c==="number")r.maxItems=c;r.type="array",r.items=et(s.element,t,{...o,path:[...o.path,"items"]})},gg=(e,t,n,o)=>{let r=n,s=e._zod.def;r.type="object",r.properties={};let a=s.shape;for(let u in a)r.properties[u]=et(a[u],t,{...o,path:[...o.path,"properties",u]});let c=new Set(Object.keys(a)),l=new Set([...c].filter((u)=>{let p=s.shape[u]._zod;if(t.io==="input")return p.optin===void 0;else return p.optout===void 0}));if(l.size>0)r.required=Array.from(l);if(s.catchall?._zod.def.type==="never")r.additionalProperties=!1;else if(!s.catchall){if(t.io==="output")r.additionalProperties=!1}else if(s.catchall)r.additionalProperties=et(s.catchall,t,{...o,path:[...o.path,"additionalProperties"]})},vg=(e,t,n,o)=>{let r=e._zod.def,s=r.inclusive===!1,a=r.options.map((c,l)=>et(c,t,{...o,path:[...o.path,s?"oneOf":"anyOf",l]}));if(s)n.oneOf=a;else n.anyOf=a},yg=(e,t,n,o)=>{let r=e._zod.def,s=et(r.left,t,{...o,path:[...o.path,"allOf",0]}),a=et(r.right,t,{...o,path:[...o.path,"allOf",1]}),c=(u)=>("allOf"in u)&&Object.keys(u).length===1,l=[...c(s)?s.allOf:[s],...c(a)?a.allOf:[a]];n.allOf=l};var bg=(e,t,n,o)=>{let r=n,s=e._zod.def;r.type="object";let a=s.keyType,l=a._zod.bag?.patterns;if(s.mode==="loose"&&l&&l.size>0){let p=et(s.valueType,t,{...o,path:[...o.path,"patternProperties","*"]});r.patternProperties={};for(let d of l)r.patternProperties[d.source]=p}else{if(t.target==="draft-07"||t.target==="draft-2020-12")r.propertyNames=et(s.keyType,t,{...o,path:[...o.path,"propertyNames"]});r.additionalProperties=et(s.valueType,t,{...o,path:[...o.path,"additionalProperties"]})}let u=a._zod.values;if(u){let p=[...u].filter((d)=>typeof d==="string"||typeof d==="number");if(p.length>0)r.required=p}},xg=(e,t,n,o)=>{let r=e._zod.def,s=et(r.innerType,t,o),a=t.seen.get(e);if(t.target==="openapi-3.0")a.ref=r.innerType,n.nullable=!0;else n.anyOf=[s,{type:"null"}]},wg=(e,t,n,o)=>{let r=e._zod.def;et(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType},_g=(e,t,n,o)=>{let r=e._zod.def;et(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.default=JSON.parse(JSON.stringify(r.defaultValue))},kg=(e,t,n,o)=>{let r=e._zod.def;et(r.innerType,t,o);let s=t.seen.get(e);if(s.ref=r.innerType,t.io==="input")n._prefault=JSON.parse(JSON.stringify(r.defaultValue))},Sg=(e,t,n,o)=>{let r=e._zod.def;et(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType;let a;try{a=r.catchValue(void 0)}catch{throw Error("Dynamic catch values are not supported in JSON Schema")}n.default=a},Cg=(e,t,n,o)=>{let r=e._zod.def,s=t.io==="input"?r.in._zod.def.type==="transform"?r.out:r.in:r.out;et(s,t,o);let a=t.seen.get(e);a.ref=s},Tg=(e,t,n,o)=>{let r=e._zod.def;et(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.readOnly=!0};var Ul=(e,t,n,o)=>{let r=e._zod.def;et(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType};var Yk=L("ZodISODateTime",(e,t)=>{$f.init(e,t),qe.init(e,t)});function ql(e){return jh(Yk,e)}var Qk=L("ZodISODate",(e,t)=>{Mf.init(e,t),qe.init(e,t)});function Ig(e){return Zh(Qk,e)}var eS=L("ZodISOTime",(e,t)=>{Lf.init(e,t),qe.init(e,t)});function Eg(e){return Uh(eS,e)}var tS=L("ZodISODuration",(e,t)=>{Of.init(e,t),qe.init(e,t)});function Ag(e){return qh(tS,e)}var zg=(e,t)=>{ws.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:(n)=>gm(e,n)},flatten:{value:(n)=>hm(e,n)},addIssue:{value:(n)=>{e.issues.push(n),e.message=JSON.stringify(e.issues,ti,2)}},addIssues:{value:(n)=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,ti,2)}},isEmpty:{get(){return e.issues.length===0}}})},NP=L("ZodError",zg),$t=L("ZodError",zg,{Parent:Error});var Pg=_s($t),Ng=ks($t),Rg=oi($t),$g=ii($t),Mg=vm($t),Lg=ym($t),Og=bm($t),Dg=xm($t),Fg=wm($t),Bg=_m($t),Hg=km($t),jg=Sm($t);var Ze=L("ZodType",(e,t)=>(Oe.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:li(e,"input"),output:li(e,"output")}}),e.toJSONSchema=og(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Hn(t,{checks:[...t.checks??[],...n.map((o)=>typeof o==="function"?{_zod:{check:o,def:{check:"custom"},onattach:[]}}:o)]}),{parent:!0}),e.with=e.check,e.clone=(n,o)=>ln(e,n,o),e.brand=()=>e,e.register=(n,o)=>(n.add(e,o),e),e.parse=(n,o)=>Pg(e,n,o,{callee:e.parse}),e.safeParse=(n,o)=>Rg(e,n,o),e.parseAsync=async(n,o)=>Ng(e,n,o,{callee:e.parseAsync}),e.safeParseAsync=async(n,o)=>$g(e,n,o),e.spa=e.safeParseAsync,e.encode=(n,o)=>Mg(e,n,o),e.decode=(n,o)=>Lg(e,n,o),e.encodeAsync=async(n,o)=>Og(e,n,o),e.decodeAsync=async(n,o)=>Dg(e,n,o),e.safeEncode=(n,o)=>Fg(e,n,o),e.safeDecode=(n,o)=>Bg(e,n,o),e.safeEncodeAsync=async(n,o)=>Hg(e,n,o),e.safeDecodeAsync=async(n,o)=>jg(e,n,o),e.refine=(n,o)=>e.check(VS(n,o)),e.superRefine=(n)=>e.check(GS(n)),e.overwrite=(n)=>e.check(Un(n)),e.optional=()=>Ge(e),e.exactOptional=()=>MS(e),e.nullable=()=>qg(e),e.nullish=()=>Ge(qg(e)),e.nonoptional=(n)=>HS(e,n),e.array=()=>re(e),e.or=(n)=>he([e,n]),e.and=(n)=>Ms(e,n),e.transform=(n)=>Gl(e,Kg(n)),e.default=(n)=>DS(e,n),e.prefault=(n)=>BS(e,n),e.catch=(n)=>ZS(e,n),e.pipe=(n)=>Gl(e,n),e.readonly=()=>WS(e),e.describe=(n)=>{let o=e.clone();return ko.add(o,{description:n}),o},Object.defineProperty(e,"description",{get(){return ko.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return ko.get(e);let o=e.clone();return ko.add(o,n[0]),o},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=(n)=>n(e),e)),Wg=L("_ZodString",(e,t)=>{Es.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(o,r,s)=>rg(e,o,r,s);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...o)=>e.check(zl(...o)),e.includes=(...o)=>e.check(Rl(...o)),e.startsWith=(...o)=>e.check($l(...o)),e.endsWith=(...o)=>e.check(Ml(...o)),e.min=(...o)=>e.check(Qo(...o)),e.max=(...o)=>e.check(Ns(...o)),e.length=(...o)=>e.check(Rs(...o)),e.nonempty=(...o)=>e.check(Qo(1,...o)),e.lowercase=(o)=>e.check(Pl(o)),e.uppercase=(o)=>e.check(Nl(o)),e.trim=()=>e.check(Ol()),e.normalize=(...o)=>e.check(Ll(...o)),e.toLowerCase=()=>e.check(Dl()),e.toUpperCase=()=>e.check(Fl()),e.slugify=()=>e.check(Bl())}),rS=L("ZodString",(e,t)=>{Es.init(e,t),Wg.init(e,t),e.email=(n)=>e.check(wh(iS,n)),e.url=(n)=>e.check(Th(sS,n)),e.jwt=(n)=>e.check(Hh(wS,n)),e.emoji=(n)=>e.check(Ih(aS,n)),e.guid=(n)=>e.check(Al(Zg,n)),e.uuid=(n)=>e.check(_h($s,n)),e.uuidv4=(n)=>e.check(kh($s,n)),e.uuidv6=(n)=>e.check(Sh($s,n)),e.uuidv7=(n)=>e.check(Ch($s,n)),e.nanoid=(n)=>e.check(Eh(cS,n)),e.guid=(n)=>e.check(Al(Zg,n)),e.cuid=(n)=>e.check(Ah(lS,n)),e.cuid2=(n)=>e.check(zh(uS,n)),e.ulid=(n)=>e.check(Ph(dS,n)),e.base64=(n)=>e.check(Dh(yS,n)),e.base64url=(n)=>e.check(Fh(bS,n)),e.xid=(n)=>e.check(Nh(pS,n)),e.ksuid=(n)=>e.check(Rh(mS,n)),e.ipv4=(n)=>e.check($h(fS,n)),e.ipv6=(n)=>e.check(Mh(hS,n)),e.cidrv4=(n)=>e.check(Lh(gS,n)),e.cidrv6=(n)=>e.check(Oh(vS,n)),e.e164=(n)=>e.check(Bh(xS,n)),e.datetime=(n)=>e.check(ql(n)),e.date=(n)=>e.check(Ig(n)),e.time=(n)=>e.check(Eg(n)),e.duration=(n)=>e.check(Ag(n))});function C(e){return xh(rS,e)}var qe=L("ZodStringFormat",(e,t)=>{je.init(e,t),Wg.init(e,t)}),iS=L("ZodEmail",(e,t)=>{Cf.init(e,t),qe.init(e,t)});var Zg=L("ZodGUID",(e,t)=>{kf.init(e,t),qe.init(e,t)});var $s=L("ZodUUID",(e,t)=>{Sf.init(e,t),qe.init(e,t)});var sS=L("ZodURL",(e,t)=>{Tf.init(e,t),qe.init(e,t)});var aS=L("ZodEmoji",(e,t)=>{If.init(e,t),qe.init(e,t)});var cS=L("ZodNanoID",(e,t)=>{Ef.init(e,t),qe.init(e,t)});var lS=L("ZodCUID",(e,t)=>{Af.init(e,t),qe.init(e,t)});var uS=L("ZodCUID2",(e,t)=>{zf.init(e,t),qe.init(e,t)});var dS=L("ZodULID",(e,t)=>{Pf.init(e,t),qe.init(e,t)});var pS=L("ZodXID",(e,t)=>{Nf.init(e,t),qe.init(e,t)});var mS=L("ZodKSUID",(e,t)=>{Rf.init(e,t),qe.init(e,t)});var fS=L("ZodIPv4",(e,t)=>{Df.init(e,t),qe.init(e,t)});var hS=L("ZodIPv6",(e,t)=>{Ff.init(e,t),qe.init(e,t)});var gS=L("ZodCIDRv4",(e,t)=>{Bf.init(e,t),qe.init(e,t)});var vS=L("ZodCIDRv6",(e,t)=>{Hf.init(e,t),qe.init(e,t)});var yS=L("ZodBase64",(e,t)=>{Zf.init(e,t),qe.init(e,t)});var bS=L("ZodBase64URL",(e,t)=>{Uf.init(e,t),qe.init(e,t)});var xS=L("ZodE164",(e,t)=>{qf.init(e,t),qe.init(e,t)});var wS=L("ZodJWT",(e,t)=>{Wf.init(e,t),qe.init(e,t)});var Vg=L("ZodNumber",(e,t)=>{Cl.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(o,r,s)=>ig(e,o,r,s),e.gt=(o,r)=>e.check(zs(o,r)),e.gte=(o,r)=>e.check(ci(o,r)),e.min=(o,r)=>e.check(ci(o,r)),e.lt=(o,r)=>e.check(As(o,r)),e.lte=(o,r)=>e.check(ai(o,r)),e.max=(o,r)=>e.check(ai(o,r)),e.int=(o)=>e.check(Ug(o)),e.safe=(o)=>e.check(Ug(o)),e.positive=(o)=>e.check(zs(0,o)),e.nonnegative=(o)=>e.check(ci(0,o)),e.negative=(o)=>e.check(As(0,o)),e.nonpositive=(o)=>e.check(ai(0,o)),e.multipleOf=(o,r)=>e.check(Ps(o,r)),e.step=(o,r)=>e.check(Ps(o,r)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??0.5),e.isFinite=!0,e.format=n.format??null});function ae(e){return Wh(Vg,e)}var _S=L("ZodNumberFormat",(e,t)=>{Vf.init(e,t),Vg.init(e,t)});function Ug(e){return Vh(_S,e)}var kS=L("ZodBoolean",(e,t)=>{Gf.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>sg(e,n,o,r)});function Re(e){return Gh(kS,e)}var SS=L("ZodUndefined",(e,t)=>{Xf.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>cg(e,n,o,r)});function Xl(e){return Xh(SS,e)}var CS=L("ZodNull",(e,t)=>{Jf.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>ag(e,n,o,r)});function Jl(e){return Jh(CS,e)}var TS=L("ZodUnknown",(e,t)=>{Kf.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>ug(e,n,o,r)});function ze(){return Kh(TS)}var IS=L("ZodNever",(e,t)=>{Yf.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>lg(e,n,o,r)});function Gg(e){return Yh(IS,e)}var ES=L("ZodArray",(e,t)=>{Qf.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>hg(e,n,o,r),e.element=t.element,e.min=(n,o)=>e.check(Qo(n,o)),e.nonempty=(n)=>e.check(Qo(1,n)),e.max=(n,o)=>e.check(Ns(n,o)),e.length=(n,o)=>e.check(Rs(n,o)),e.unwrap=()=>e.element});function re(e,t){return Qh(ES,e,t)}var Kl=L("ZodObject",(e,t)=>{nh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>gg(e,n,o,r),ke(e,"shape",()=>t.shape),e.keyof=()=>It(Object.keys(e._zod.def.shape)),e.catchall=(n)=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:ze()}),e.loose=()=>e.clone({...e._zod.def,catchall:ze()}),e.strict=()=>e.clone({...e._zod.def,catchall:Gg()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=(n)=>Ak(e,n),e.safeExtend=(n)=>zk(e,n),e.merge=(n)=>Pk(e,n),e.pick=(n)=>Ik(e,n),e.omit=(n)=>Ek(e,n),e.partial=(...n)=>Nk(Yg,e,n[0]),e.required=(...n)=>Rk(Qg,e,n[0])});function A(e,t){let n={type:"object",shape:e??{},...G(t)};return new Kl(n)}function Xg(e,t){return new Kl({type:"object",shape:e,catchall:Gg(),...G(t)})}function Tt(e,t){return new Kl({type:"object",shape:e,catchall:ze(),...G(t)})}var Jg=L("ZodUnion",(e,t)=>{Tl.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>vg(e,n,o,r),e.options=t.options});function he(e,t){return new Jg({type:"union",options:e,...G(t)})}var AS=L("ZodDiscriminatedUnion",(e,t)=>{Jg.init(e,t),oh.init(e,t)});function Yl(e,t,n){return new AS({type:"union",options:t,discriminator:e,...G(n)})}var zS=L("ZodIntersection",(e,t)=>{rh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>yg(e,n,o,r)});function Ms(e,t){return new zS({type:"intersection",left:e,right:t})}var PS=L("ZodRecord",(e,t)=>{ih.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>bg(e,n,o,r),e.keyType=t.keyType,e.valueType=t.valueType});function Ee(e,t,n){return new PS({type:"record",keyType:e,valueType:t,...G(n)})}var Vl=L("ZodEnum",(e,t)=>{sh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(o,r,s)=>dg(e,o,r,s),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(o,r)=>{let s={};for(let a of o)if(n.has(a))s[a]=t.entries[a];else throw Error(`Key ${a} not found in enum`);return new Vl({...t,checks:[],...G(r),entries:s})},e.exclude=(o,r)=>{let s={...t.entries};for(let a of o)if(n.has(a))delete s[a];else throw Error(`Key ${a} not found in enum`);return new Vl({...t,checks:[],...G(r),entries:s})}});function It(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map((o)=>[o,o])):e;return new Vl({type:"enum",entries:n,...G(t)})}var NS=L("ZodLiteral",(e,t)=>{ah.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>pg(e,n,o,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function S(e,t){return new NS({type:"literal",values:Array.isArray(e)?e:[e],...G(t)})}var RS=L("ZodTransform",(e,t)=>{ch.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>fg(e,n,o,r),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new ei(e.constructor.name);n.addIssue=(s)=>{if(typeof s==="string")n.issues.push(_o(s,n.value,t));else{let a=s;if(a.fatal)a.continue=!1;a.code??(a.code="custom"),a.input??(a.input=n.value),a.inst??(a.inst=e),n.issues.push(_o(a))}};let r=t.transform(n.value,n);if(r instanceof Promise)return r.then((s)=>(n.value=s,n));return n.value=r,n}});function Kg(e){return new RS({type:"transform",transform:e})}var Yg=L("ZodOptional",(e,t)=>{Il.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ul(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function Ge(e){return new Yg({type:"optional",innerType:e})}var $S=L("ZodExactOptional",(e,t)=>{lh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ul(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function MS(e){return new $S({type:"optional",innerType:e})}var LS=L("ZodNullable",(e,t)=>{uh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>xg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function qg(e){return new LS({type:"nullable",innerType:e})}var OS=L("ZodDefault",(e,t)=>{dh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>_g(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function DS(e,t){return new OS({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():hl(t)}})}var FS=L("ZodPrefault",(e,t)=>{ph.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>kg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function BS(e,t){return new FS({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():hl(t)}})}var Qg=L("ZodNonOptional",(e,t)=>{mh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>wg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function HS(e,t){return new Qg({type:"nonoptional",innerType:e,...G(t)})}var jS=L("ZodCatch",(e,t)=>{fh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Sg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function ZS(e,t){return new jS({type:"catch",innerType:e,catchValue:typeof t==="function"?t:()=>t})}var US=L("ZodPipe",(e,t)=>{hh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Cg(e,n,o,r),e.in=t.in,e.out=t.out});function Gl(e,t){return new US({type:"pipe",in:e,out:t})}var qS=L("ZodReadonly",(e,t)=>{gh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Tg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function WS(e){return new qS({type:"readonly",innerType:e})}var ev=L("ZodCustom",(e,t)=>{vh.init(e,t),Ze.init(e,t),e._zod.processJSONSchema=(n,o,r)=>mg(e,n,o,r)});function tv(e,t){return eg(ev,e??(()=>!0),t)}function VS(e,t={}){return tg(ev,e,t)}function GS(e){return ng(e)}function Ql(e,t){return Gl(Kg(e),t)}Zt(El());var eu=A({x:ae(),y:ae(),scale:ae().positive()}),XS=A({target:he([Xg({nodeId:C().min(1)}),Xg({viewport:eu})]),duration:ae().nonnegative().max(3600).optional(),easing:It(["linear","ease-in-out","ease-out"]).optional(),padding:ae().nonnegative().optional(),pullback:ae().min(0).max(4).optional()}),VN=A({stops:re(XS).max(1000)});function nv(e,t,n,o){if("viewport"in e.target)return e.target.viewport;let r=e.target.nodeId,s=t.find((l)=>l.id===r);if(!s)throw Error(`Tour target not found: ${r}`);let a=e.padding??40;if(a*2>=Math.min(n,o))throw Error("Tour padding exceeds viewport");let c=Math.min((n-a*2)/s.size.width,(o-a*2)/s.size.height);return{x:n/2-(s.position.x+s.size.width/2)*c,y:o/2-(s.position.y+s.size.height/2)*c,scale:c}}function ov(e,t,n,o,r,s="ease-in-out",a=0){let c=Math.max(0,Math.min(1,n));if(c===0)return{...e};if(c===1)return{...t};let l=s==="linear"?c:s==="ease-out"?1-(1-c)**3:c*c*(3-2*c),u=Math.exp(Math.log(e.scale)*(1-l)+Math.log(t.scale)*l-a*Math.sin(Math.PI*l)),p=(o/2-e.x)/e.scale*(1-l)+(o/2-t.x)/t.scale*l,d=(r/2-e.y)/e.scale*(1-l)+(r/2-t.y)/t.scale*l;return{x:o/2-p*u,y:r/2-d*u,scale:u}}var tu=null;function rv(e){tu=e}function it(){if(tu?.isConnected){let e=tu.getBoundingClientRect();if(e.width>0&&e.height>0)return{left:e.left,top:e.top,width:e.width,height:e.height}}return{left:0,top:0,width:window.innerWidth,height:window.innerHeight}}function qn(){let e=it();return{x:e.left+e.width/2,y:e.top+e.height/2}}function nu(){let e=16;try{let t=it(),n=t.top+t.height;for(let o of[".command-bar",".minimap"]){let r=document.querySelector(o);if(!(r instanceof HTMLElement)||!r.isConnected)continue;let s=r.getBoundingClientRect();if(s.height<=0)continue;let a=n-s.top;if(a>0)e=Math.max(e,a+12)}}catch{}return{top:16,right:16,bottom:e,left:16}}var JS=Symbol.for("preact-signals");function Bs(){if(!(xn>1)){var e,t=!1;(function(){var r=Ds;Ds=void 0;while(r!==void 0){if(r.S.v===r.v)r.S.i=r.i;r=r.o}})();while(di!==void 0){var n=di;di=void 0,Os++;while(n!==void 0){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&av(n))try{n.c()}catch(r){if(!t)e=r,t=!0}n=o}}if(Os=0,xn--,t)throw e}else xn--}function Mt(e){if(xn>0)return e();ou=++KS,xn++;try{return e()}finally{Bs()}}var Ce=void 0;function ru(e){var t=Ce;Ce=void 0;try{return e()}finally{Ce=t}}var iv,di=void 0,xn=0,Os=0,KS=0,ou=0,Ds=void 0,Fs=0;function sv(e){if(Ce!==void 0){var t=e.n;if(t===void 0||t.t!==Ce){if(t={i:0,S:e,p:Ce.s,n:void 0,t:Ce,e:void 0,x:void 0,r:t},Ce.s!==void 0)Ce.s.n=t;if(Ce.s=t,e.n=t,32&Ce.f)e.S(t);return t}else if(t.i===-1){if(t.i=0,t.n!==void 0){if(t.n.p=t.p,t.p!==void 0)t.p.n=t.n;t.p=Ce.s,t.n=void 0,Ce.s.n=t,Ce.s=t}return t}}}function st(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}st.prototype.brand=JS;st.prototype.h=function(){return!0};st.prototype.S=function(e){var t=this,n=this.t;if(n!==e&&e.e===void 0)if(e.x=n,this.t=e,n!==void 0)n.e=e;else ru(function(){var o;(o=t.W)==null||o.call(t)})};st.prototype.U=function(e){var t=this;if(this.t!==void 0){var{e:n,x:o}=e;if(n!==void 0)n.x=o,e.e=void 0;if(o!==void 0)o.e=n,e.x=void 0;if(e===this.t){if(this.t=o,o===void 0)ru(function(){var r;(r=t.Z)==null||r.call(t)})}}};st.prototype.subscribe=function(e){var t=this;return zt(function(){var n=t.value,o=Ce;Ce=void 0;try{e(n)}finally{Ce=o}},{name:"sub"})};st.prototype.valueOf=function(){return this.value};st.prototype.toString=function(){return this.value+""};st.prototype.toJSON=function(){return this.value};st.prototype.peek=function(){var e=Ce;Ce=void 0;try{return this.value}finally{Ce=e}};Object.defineProperty(st.prototype,"value",{get:function(){var e=sv(this);if(e!==void 0)e.i=this.i;return this.v},set:function(e){if(e!==this.v){if(Os>100)throw Error("Cycle detected");(function(n){if(xn!==0&&Os===0){if(n.l!==ou)n.l=ou,Ds={S:n,v:n.v,i:n.i,o:Ds}}})(this),this.v=e,this.i++,Fs++,xn++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Bs()}}}});function U(e,t){return new st(e,t)}function av(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function cv(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0)t.r=n;if(t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function lv(e){var t=e.s,n=void 0;while(t!==void 0){var o=t.p;if(t.i===-1){if(t.S.U(t),o!==void 0)o.n=t.n;if(t.n!==void 0)t.n.p=o}else n=t;if(t.S.n=t.r,t.r!==void 0)t.r=void 0;t=o}e.s=n}function So(e,t){st.call(this,void 0),this.x=e,this.s=void 0,this.g=Fs-1,this.f=4,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}So.prototype=new st;So.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32)return!0;if(this.f&=-5,this.g===Fs)return!0;if(this.g=Fs,this.f|=1,this.i>0&&!av(this))return this.f&=-2,!0;var e=Ce;try{cv(this),Ce=this;var t=this.x();if(16&this.f||this.v!==t||this.i===0)this.v=t,this.f&=-17,this.i++}catch(n){this.v=n,this.f|=16,this.i++}return Ce=e,lv(this),this.f&=-2,!0};So.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}st.prototype.S.call(this,e)};So.prototype.U=function(e){if(this.t!==void 0){if(st.prototype.U.call(this,e),this.t===void 0){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}}};So.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(So.prototype,"value",{get:function(){if(1&this.f)throw Error("Cycle detected");var e=sv(this);if(this.h(),e!==void 0)e.i=this.i;if(16&this.f)throw this.v;return this.v}});function De(e,t){return new So(e,t)}function uv(e){var t=e.m;if(e.m=void 0,typeof t=="function"){xn++;var n=Ce;Ce=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,iu(e),o}finally{Ce=n,Bs()}}}function iu(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,uv(e)}function YS(e){if(Ce!==this)throw Error("Out-of-order effect");if(lv(this),Ce=e,this.f&=-2,8&this.f)iu(this);Bs()}function er(e,t){if(this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t==null?void 0:t.name,iv)iv.push(this)}er.prototype.c=function(){var e=this.S();try{if(8&this.f)return;if(this.x===void 0)return;var t=this.x();if(typeof t=="function")this.m=t}finally{e()}};er.prototype.S=function(){if(1&this.f)throw Error("Cycle detected");this.f|=1,this.f&=-9,uv(this),cv(this),xn++;var e=Ce;return Ce=this,YS.bind(this,e)};er.prototype.N=function(){if(!(2&this.f))this.f|=2,this.u=di,di=this};er.prototype.d=function(){if(this.f|=8,!(1&this.f))iu(this)};er.prototype.dispose=function(){this.d()};function zt(e,t){var n=new er(e,t);try{n.c()}catch(r){throw n.d(),r}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var dv,su,Hs,QS=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var pv=[];zt(function(){dv=this.N})();function tr(e,t){_e[e]=t.bind(null,_e[e]||function(){})}function js(e){if(Hs){var t=Hs;Hs=void 0,t()}Hs=e&&e.S()}function mv(e){var t=this,n=e.data,o=t0(n);o.value=n;var r=Se(function(){var c=t,l=t.__v;while(l=l.__)if(l.__c){l.__c.__$f|=4;break}var u=De(function(){var f=o.value.value;return f===0?0:f===!0?"":f||""}),p=De(function(){return!Array.isArray(u.value)&&!ol(u.value)}),d=zt(function(){if(this.N=fv,p.value){var f=u.value;if(c.__v&&c.__v.__e&&c.__v.__e.nodeType===3)c.__v.__e.data=f}}),m=t.__$u.d;return t.__$u.d=function(){d(),m.call(this)},[p,u]},[]),s=r[0],a=r[1];return s.value?a.peek():a.value}mv.displayName="ReactiveTextNode";Object.defineProperties(st.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:mv},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});tr("__b",function(e,t){if(typeof t.type=="string"){var n,o=t.props;for(var r in o)if(r!=="children"){var s=o[r];if(s instanceof st){if(!n)t.__np=n={};n[r]=s,o[r]=s.peek()}}}e(t)});tr("__r",function(e,t){if(e(t),t.type!==ue){js();var n,o=t.__c;if(o){if(o.__$f&=-2,(n=o.__$u)===void 0)o.__$u=n=function(r,s){var a;return zt(function(){a=this},{name:s}),a.c=r,a}(function(){var r;if(QS)(r=n.y)==null||r.call(n);o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:"")}su=o,js(n)}});tr("__e",function(e,t,n,o){js(),su=void 0,e(t,n,o)});tr("diffed",function(e,t){js(),su=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var{__np:o,props:r}=t;if(o){var s=n.U;if(s)for(var a in s){var c=s[a];if(c!==void 0&&!(a in o))c.d(),s[a]=void 0}else s={},n.U=s;for(var l in o){var u=s[l],p=o[l];if(u===void 0)u=e0(n,l,p),s[l]=u;else u.o(p,r)}for(var d in o)r[d]=o[d]}}e(t)});function e0(e,t,n,o){var r=t in e&&e.ownerSVGElement===void 0,s=U(n),a=n.peek();return{o:function(c,l){s.value=c,a=c.peek()},d:zt(function(){this.N=fv;var c=s.value.value;if(a!==c)if(a=void 0,r)e[t]=c;else if(c!=null&&(c!==!1||t[4]==="-"))e.setAttribute(t,c);else e.removeAttribute(t);else a=void 0})}}tr("unmount",function(e,t){if(typeof t.type=="string"){var n=t.__e;if(n){var o=n.U;if(o){n.U=void 0;for(var r in o){var s=o[r];if(s)s.d()}}}t.__np=void 0}else{var a=t.__c;if(a){var c=a.__$u;if(c)a.__$u=void 0,c.d()}}e(t)});tr("__h",function(e,t,n,o){if(o<3||o===9)t.__$f|=2;e(t,n,o)});Xo.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,o=n&&n.s!==void 0;for(var r in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var s=2&this.__$f;if(!(o||s||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(o||4&this.__$f))return!0;if(3&this.__$f)return!0}for(var a in e)if(a!=="__source"&&e[a]!==this.props[a])return!0;for(var c in this.props)if(!(c in e))return!0;return!1};function t0(e,t){return Se(function(){return U(e,t)},[])}var n0=function(e){queueMicrotask(function(){queueMicrotask(e)})};function o0(){Mt(function(){var e;while(e=pv.shift())dv.call(e)})}function fv(){if(pv.push(this)===1)(_e.requestAnimationFrame||n0)(o0)}var dt={markdown:"MD","mcp-app":"APP",webpage:"WEB","json-render":"UI",graph:"GRAPH",board:"BOARD",prompt:"ASK",response:"ANS",status:"STATUS",context:"CONTEXT",ledger:"LOG",trace:"TRACE",file:"FILE",diff:"DIFF",mermaid:"MERMAID",image:"IMG",html:"HTML",group:"GROUP"},pi=new Set(["markdown","mcp-app","webpage","json-render","graph","context","ledger","file","diff","mermaid","image","html"]);function hv(e){return e.type==="mcp-app"&&e.data.mode==="ext-app"&&e.data.serverName==="Excalidraw"&&e.data.toolName==="create_view"}function gv(e){if(e.length===0)return null;let{POSITIVE_INFINITY:t,POSITIVE_INFINITY:n,NEGATIVE_INFINITY:o,NEGATIVE_INFINITY:r}=Number;for(let s of e)t=Math.min(t,s.position.x),n=Math.min(n,s.position.y),o=Math.max(o,s.position.x+s.size.width),r=Math.max(r,s.position.y+s.size.height);if(!Number.isFinite(t)||!Number.isFinite(n))return null;return{x:t-40,y:n-40-32,width:o-t+80,height:r-n+80+32}}function r0(e){let t=e.filter((l)=>!l.pinned),n=new Map(t.map((l)=>[l.id,l])),o=new Map,r=[],s=new Map;for(let l of t){if(l.type==="group")continue;let u=typeof l.data.parentGroup==="string"?l.data.parentGroup:"",p=u?n.get(u):void 0;if(!p||p.type!=="group")continue;if(!s.has(u))s.set(u,[]);s.get(u).push(l)}let a=t.filter((l)=>l.type==="group").sort((l,u)=>l.position.y-u.position.y||l.position.x-u.position.x);for(let l of a){let u=s.get(l.id)??[];if(u.length===0){let f=`unit:${l.id}`;r.push({id:f,memberIds:[l.id],origin:{...l.position},size:{...l.size},sortKey:{x:l.position.x,y:l.position.y}}),o.set(l.id,f);continue}let p=u.map((f)=>({position:f.position,size:f.size})),d=gv(p);if(!d)continue;let m=`group:${l.id}`;r.push({id:m,memberIds:u.map((f)=>f.id),origin:{x:d.x,y:d.y},size:{width:d.width,height:d.height},sortKey:{x:d.x,y:d.y},groupId:l.id}),o.set(l.id,m);for(let f of u)o.set(f.id,m)}let c=t.filter((l)=>!o.has(l.id)).sort((l,u)=>l.position.y-u.position.y||l.position.x-u.position.x);for(let l of c){let u=`unit:${l.id}`;r.push({id:u,memberIds:[l.id],origin:{...l.position},size:{...l.size},sortKey:{x:l.position.x,y:l.position.y}}),o.set(l.id,u)}return{units:r,nodesById:n,nodeToUnit:o}}function i0(e,t,n){let o=new Map,r=new Map,s=new Map,a=new Map;for(let c of e)o.set(c.id,new Set),r.set(c.id,new Set),s.set(c.id,0),a.set(c.id,0);for(let c of n){let l=t.get(c.from),u=t.get(c.to);if(!l||!u||l===u)continue;if(!o.get(l).has(u))o.get(l).add(u),a.set(l,(a.get(l)??0)+1),s.set(u,(s.get(u)??0)+1);r.get(l).add(u),r.get(u).add(l)}return{outgoing:o,undirected:r,indegree:s,outdegree:a}}function s0(e,t){let n=new Map(e.map((s)=>[s.id,s])),o=new Set,r=[];for(let s of e){if(o.has(s.id))continue;let a=[s.id],c=[];o.add(s.id);while(a.length>0){let u=a.pop();c.push(u);for(let p of t.get(u)??[]){if(o.has(p))continue;o.add(p),a.push(p)}}let l=c.map((u)=>n.get(u)).filter((u)=>u!==void 0).sort((u,p)=>u.sortKey.y-p.sortKey.y||u.sortKey.x-p.sortKey.x);r.push(l)}return r.sort((s,a)=>s[0].sortKey.y-a[0].sortKey.y||s[0].sortKey.x-a[0].sortKey.x)}function a0(e){let t=new Map,n=0,o=0,r=0,s=0,a=Math.max(900,Math.ceil(Math.sqrt(e.reduce((c,l)=>c+l.size.width*l.size.height,0))));for(let c of e){if(n>0&&n+c.size.width>a)n=0,o+=r+72,r=0;t.set(c.id,{x:n,y:o}),n+=c.size.width+96,r=Math.max(r,c.size.height),s=Math.max(s,n-96)}return{positions:t,size:{width:Math.max(0,s),height:o+r},sortKey:e[0].sortKey}}function c0(e,t,n,o,r){if(e.length===1)return{positions:new Map([[e[0].id,{x:0,y:0}]]),size:{...e[0].size},sortKey:e[0].sortKey};let s=new Set(e.map((y)=>y.id)),a=e.filter((y)=>(o.get(y.id)??0)===0&&(r.get(y.id)??0)>0).sort((y,E)=>y.sortKey.x-E.sortKey.x||y.sortKey.y-E.sortKey.y),c=a.length>0?a:[e.slice().sort((y,E)=>y.sortKey.x-E.sortKey.x||y.sortKey.y-E.sortKey.y)[0]],l=new Map,u=c.map((y)=>y.id);for(let y of c)l.set(y.id,0);while(u.length>0){let y=u.shift(),E=l.get(y)??0;for(let D of n.get(y)??[]){if(!s.has(D)||l.has(D))continue;l.set(D,E+1),u.push(D)}}let p=0;for(let y of e){if(l.has(y.id))continue;l.set(y.id,p),p+=1}let d=new Map;for(let y of e){let E=l.get(y.id)??0;if(!d.has(E))d.set(E,[]);d.get(E).push(y)}let m=Array.from(d.keys()).sort((y,E)=>y-E);for(let y of m)d.get(y).sort((E,D)=>E.sortKey.y-D.sortKey.y||E.sortKey.x-D.sortKey.x);let f=new Map,h=new Map,v=0;for(let y of m){let E=d.get(y),D=E.reduce((b,T,w)=>b+T.size.height+(w>0?72:0),0),N=Math.max(...E.map((b)=>b.size.width));f.set(y,D),h.set(y,N),v=Math.max(v,D)}let x=new Map,g=0;for(let y of m){let E=d.get(y),D=f.get(y)??0,N=h.get(y)??0,b=Math.max(0,(v-D)/2);for(let T of E)x.set(T.id,{x:g,y:b}),b+=T.size.height+72;g+=N+96}return{positions:x,size:{width:Math.max(0,g-96),height:v},sortKey:e[0].sortKey}}function l0(e,t){let n=new Map(e.map((l)=>[l.id,l.id])),o=(l)=>{let u=l;while(n.get(u)!==u)u=n.get(u);let p=l;while(n.get(p)!==p){let d=n.get(p);n.set(p,u),p=d}return u},r=(l,u)=>{let p=o(l),d=o(u);if(p!==d)n.set(p,d)},s=160;for(let l=0;l<e.length;l++)for(let u=l+1;u<e.length;u++){let p=e[l],d=e[u];if(p.origin.x-160<d.origin.x+d.size.width+160&&p.origin.x+p.size.width+160>d.origin.x-160&&p.origin.y-160<d.origin.y+d.size.height+160&&p.origin.y+p.size.height+160>d.origin.y-160)r(p.id,d.id)}for(let[l,u]of t)for(let p of u)if(n.has(l)&&n.has(p))r(l,p);let a=new Map;for(let l of e){let u=o(l.id);if(!a.has(u))a.set(u,[]);a.get(u).push(l)}let c=Array.from(a.values());for(let l of c)l.sort((u,p)=>u.sortKey.y-p.sortKey.y||u.sortKey.x-p.sortKey.x);return c.sort((l,u)=>l[0].sortKey.y-u[0].sortKey.y||l[0].sortKey.x-u[0].sortKey.x)}function u0(e,t){let n=new Map,{x:o,y:r}=t,s=0;for(let a of e){if(o>t.x&&o-t.x+a.size.width>3200)o=t.x,r+=s+180,s=0;for(let[c,l]of a.positions.entries())n.set(c,{x:o+l.x,y:r+l.y});o+=a.size.width+220,s=Math.max(s,a.size.height)}return n}function au(e,t,n){let{units:o,nodesById:r,nodeToUnit:s}=r0(e),a=new Map,c=new Map;if(o.length===0)return{nodePositions:a,groupBounds:c};let{outgoing:l,undirected:u,indegree:p,outdegree:d}=i0(o,s,t),m=l0(o,u),f=new Map,h=[];for(let v of m){let x=s0(v,u).map((b)=>n==="graph"?c0(b,l,u,p,d):a0(b)),g={x:Math.min(...v.map((b)=>b.origin.x)),y:Math.min(...v.map((b)=>b.origin.y))},y=u0(x,g),E=new Map(v.map((b)=>[b.id,b.size])),D=(b)=>{let{POSITIVE_INFINITY:T,POSITIVE_INFINITY:w,NEGATIVE_INFINITY:_,NEGATIVE_INFINITY:P}=Number;for(let[q,R]of b){let Z=E.get(q);if(!Z)continue;T=Math.min(T,R.x),w=Math.min(w,R.y),_=Math.max(_,R.x+Z.width),P=Math.max(P,R.y+Z.height)}return{x:T,y:w,width:_-T,height:P-w}},N=y;for(let b=0;b<=h.length;b++){let T=D(N),w=h.filter((q)=>T.x<q.x+q.width+220&&T.x+T.width+220>q.x&&T.y<q.y+q.height+180&&T.y+T.height+180>q.y);if(w.length===0)break;let _=Math.max(...w.map((q)=>q.y+q.height))+180-T.y;if(_<=0)break;let P=new Map;for(let[q,R]of N)P.set(q,{x:R.x,y:R.y+_});N=P}for(let[b,T]of N)f.set(b,T);h.push(D(N))}for(let v of o){let x=f.get(v.id);if(!x)continue;let g=x.x-v.origin.x,y=x.y-v.origin.y;if(v.groupId){let N=[];for(let T of v.memberIds){let w=r.get(T);if(!w)continue;let _={x:w.position.x+g,y:w.position.y+y};a.set(T,_),N.push({position:_,size:w.size})}let b=gv(N);if(b)c.set(v.groupId,b);continue}let E=v.memberIds[0],D=r.get(E);if(!D)continue;a.set(E,{x:D.position.x+g,y:D.position.y+y})}return{nodePositions:a,groupBounds:c}}var d0=700,p0=1600;function m0(e){return e.replace(/\r\n?/g,`
|
|
61
61
|
`).replace(/[ \t\f\v]+/g," ").replace(/\n\s+/g,`
|
|
62
62
|
`).replace(/\s+\n/g,`
|
|
63
63
|
`).replace(/\n{3,}/g,`
|
|
64
64
|
|
|
65
|
-
`).trim()}function
|
|
66
|
-
`);return Object.entries(
|
|
67
|
-
`)}function
|
|
68
|
-
${
|
|
69
|
-
${n||"No chart values available."}`}function
|
|
65
|
+
`).trim()}function tt(e,t){if(t<=0)return"";let n=m0(e);if(n.length<=t)return n;if(t<=1)return n.slice(0,t);return`${n.slice(0,Math.max(0,t-1)).trimEnd()}…`}function Co(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)?e:{}}function nr(e){if(typeof e==="string"||typeof e==="number"||typeof e==="boolean")return String(e);if(Array.isArray(e))return e.map(nr).filter(Boolean).join(`
|
|
66
|
+
`);return Object.entries(Co(e)).map(([t,n])=>{let o=nr(n);return o?`${t}: ${o}`:""}).filter(Boolean).join("; ")}function pt(e,t){return t.map((n)=>{let o=e[n];return typeof o==="string"||typeof o==="number"||typeof o==="boolean"?String(o):""}).filter(Boolean).join(`
|
|
67
|
+
`)}function f0(e){let t=typeof e.graphType==="string"?e.graphType:"chart",n=nr(e.data);return`Chart: ${t}.
|
|
68
|
+
${pt(e,["title","beforeLabel","afterLabel"])}
|
|
69
|
+
${n||"No chart values available."}`}function h0(e){let t=Co(e),n=Co(t.elements),o=new Set,r=[],s=(a)=>{if(o.has(a))return;o.add(a);let c=Co(n[a]),l=Co(c.props),u=pt(l,["title","description","text","content","label","value","caption"]);if(u)r.push(u);if(Array.isArray(l.data))r.push(nr(l.data));if(Array.isArray(c.children)){for(let p of c.children)if(typeof p==="string")s(p)}};if(typeof t.root==="string")s(t.root);return r.length?`Authored surface content (dynamic visibility not evaluated):
|
|
70
70
|
${r.join(`
|
|
71
|
-
`)}`:"Interactive surface. No static text available; inspect the rendered surface."}function
|
|
72
|
-
`),d=Math.max(0,t-p.length-(p?2:0)),
|
|
73
|
-
|
|
74
|
-
${
|
|
75
|
-
${n.length?`Diagram labels: ${n.join("; ")}`:"No diagram description available."}`}return"No app content description available."}function
|
|
76
|
-
`),t)}function
|
|
77
|
-
`),t):"Web artifact node"}function
|
|
78
|
-
`),t)}function
|
|
79
|
-
`:"";return
|
|
80
|
-
|
|
81
|
-
`:"";return
|
|
82
|
-
${
|
|
83
|
-
${
|
|
84
|
-
${Array.isArray(e.data.cards)?e.data.cards.map((r)=>
|
|
85
|
-
`):""}`,n);case"ledger":{let{title:r,__type:s,strictSize:a,arrangeLocked:c,...l}=e.data;return
|
|
86
|
-
${
|
|
87
|
-
${
|
|
88
|
-
${dt(e.data,["content"])}`,n);case"image":return et(dt(e.data,["alt","caption","description"])||"No image description available; inspect the image.",n);case"group":return et(`Group: ${dt(e.data,["title"])||"Untitled"}. ${Array.isArray(e.data.children)?e.data.children.length:0} cards.`,n)}}function v0(e,t){let n=e.position.x+e.size.width/2,o=e.position.y+e.size.height/2,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2;return Math.sqrt((n-r)**2+(o-s)**2)}function y0(e,t){let n=e.position.x+e.size.width,o=e.position.y+e.size.height,r=t.position.x+t.size.width,s=t.position.y+t.size.height,a=Math.max(0,Math.max(e.position.x,t.position.x)-Math.min(n,r)),c=Math.max(0,Math.max(e.position.y,t.position.y)-Math.min(o,s));return Math.sqrt(a**2+c**2)}function b0(e){let t=[...e],n=100;return t.sort((o,r)=>{let s=Math.floor(o.position.y/100),a=Math.floor(r.position.y/100);if(s!==a)return s-a;return o.position.x-r.position.x}),t}function x0(e){let t=e.find((r)=>r.data.title&&typeof r.data.title==="string");if(t&&e.length<=3)return e.filter((s)=>s.data.title).map((s)=>s.data.title).slice(0,3).join(", ");let n={};for(let r of e)n[r.type]=(n[r.type]??0)+1;let o=Object.entries(n).map(([r,s])=>s===1?r:`${s} ${r}`);if(t)return`${t.data.title} + ${o.join(", ")}`;return o.join(", ")}function w0(e,t){return e.x<=t.x+t.width&&e.x+e.width>=t.x&&e.y<=t.y+t.height&&e.y+e.height>=t.y}function _0(e,t){let n=t.filter((r)=>w0(e.bounds,{x:r.position.x,y:r.position.y,width:r.size.width,height:r.size.height})),o=n.map((r)=>typeof r.data.title==="string"&&r.data.title.length>0?r.data.title:r.id);return{id:e.id,label:e.label??e.text??null,bounds:e.bounds,targetNodeIds:n.map((r)=>r.id),targetNodeTitles:o,target:o.length>0?o.join(", "):"empty canvas region"}}function S0(e,t=200){if(e.length===0)return[];let n=new Map,o=(l)=>{while(n.get(l)!==l){let u=n.get(l);n.set(l,n.get(u)),l=u}return l},r=(l,u)=>{let p=o(l),d=o(u);if(p!==d)n.set(p,d)};for(let l of e)n.set(l.id,l.id);for(let l=0;l<e.length;l++)for(let u=l+1;u<e.length;u++)if(y0(e[l],e[u])<=t)r(e[l].id,e[u].id);let s=new Map;for(let l of e){let u=o(l.id);if(!s.has(u))s.set(u,[]);s.get(u).push(l)}let a=[],c=0;for(let[,l]of s){if(l.length<2)continue;let u=l.map((g)=>g.position.x),p=l.map((g)=>g.position.y),d=l.map((g)=>g.position.x+g.size.width),f=l.map((g)=>g.position.y+g.size.height),m=Math.min(...u),h=Math.min(...p),v=Math.max(...d),x=Math.max(...f);a.push({id:`cluster-${c++}`,nodeIds:l.map((g)=>g.id),label:x0(l),centroid:{x:Math.round((m+v)/2),y:Math.round((h+x)/2)},bounds:{x:m,y:h,width:v-m,height:x-h}})}return a.sort((l,u)=>{let p=Math.floor(l.centroid.y/200),d=Math.floor(u.centroid.y/200);if(p!==d)return p-d;return l.centroid.x-u.centroid.x}),a}function k0(e,t,n=5,o=600){let r=e.filter((a)=>t.has(a.id)),s=e.filter((a)=>!t.has(a.id));return r.map((a)=>{let c=s.map((l)=>({node:l,distance:v0(a,l)})).filter((l)=>l.distance<=o).sort((l,u)=>l.distance-u.distance).slice(0,n);return{pinnedNodeId:a.id,pinnedNodeTitle:a.data.title??null,neighbors:c.map((l)=>({id:l.node.id,type:l.node.type,title:l.node.data.title??null,distance:Math.round(l.distance)}))}})}function di(e,t,n,o=[]){let r=S0(e),s=new Map;for(let u of r)for(let p of u.nodeIds)s.set(p,u.id);let c=b0(e).map((u,p)=>({id:u.id,type:u.type,title:u.data.title??null,content:yv(u,{defaultTextLength:320,webpageTextLength:640})||null,clusterId:s.get(u.id)??null,readingOrder:p})),l=k0(e,n);return{totalNodes:e.length,clusters:r,nodesInReadingOrder:c,pinnedNeighborhoods:l,annotations:o.map((u)=>_0(u,e))}}function nr(e){if(!e)return null;let t=e.data.title;return typeof t==="string"&&t.trim().length>0?t.trim():null}function Fs(e,t){return{id:e?.id??t,title:nr(e),nodeType:e?.type??"markdown"}}function bv(e,t){return{id:e.id,edgeType:e.type,fromId:e.from,toId:e.to,fromTitle:nr(t.get(e.from)),toTitle:nr(t.get(e.to))}}function Bs(e){return new Map(e.map((t)=>[t.id,t]))}function xv(e){return new Map(e.map((t)=>[t.id,t]))}function Kt(e){return Array.from(e).sort((t,n)=>t.localeCompare(n))}function su(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function au(e){if(!e||e.type!=="group")return[];let t=e.data.children;if(!Array.isArray(t))return[];return t.filter((n)=>typeof n==="string").sort((n,o)=>n.localeCompare(o))}function wv(e){let t=new Map;for(let n of e.clusters){let o=[...n.nodeIds].sort((r,s)=>r.localeCompare(s));for(let r of o)t.set(r,o.filter((s)=>s!==r))}return t}function _v(e){let t=new Map;for(let n of e.pinnedNeighborhoods)t.set(n.pinnedNodeId,n.neighbors.map((o)=>o.id).sort((o,r)=>o.localeCompare(r)));return t}function C0(e,t){let n=Kt(Array.from(t).filter((r)=>!e.has(r))),o=Kt(Array.from(e).filter((r)=>!t.has(r)));return{added:n,removed:o}}function Sv(e){let t=e&&typeof e==="object"?e:{};return{timestamp:typeof t.timestamp==="string"?t.timestamp:void 0,sessionId:typeof t.sessionId==="string"?t.sessionId:void 0}}function T0(e,t,n){if(!e||!n)return{layout:e,pinnedNodeIds:[],primaryFocusNodeIds:[],secondaryFocusNodeIds:[],regions:[],spatial:n};let o=Bs(e.nodes),r=Kt(t).filter((l)=>o.has(l)),s=new Set(r),a=new Set,c=[];for(let l of n.pinnedNeighborhoods){if(!s.has(l.pinnedNodeId))continue;let u=Kt([l.pinnedNodeId,...l.neighbors.map((p)=>p.id)]).filter((p,d,f)=>f.indexOf(p)===d&&o.has(p));for(let p of u)if(!s.has(p))a.add(p);c.push({id:`region-${l.pinnedNodeId}`,primaryNodeId:l.pinnedNodeId,nodeIds:u})}if(c.length===0&&r.length>0)for(let l of r)c.push({id:`region-${l}`,primaryNodeId:l,nodeIds:[l]});return{layout:e,pinnedNodeIds:r,primaryFocusNodeIds:r,secondaryFocusNodeIds:Kt(a),regions:c,spatial:n}}class Hs{currentLayout=null;currentPins=new Set;previousSpatial=null;setInitialPins(e){this.currentPins=new Set(e)}getAttentionSnapshot(){return T0(this.currentLayout,this.currentPins,this.previousSpatial)}handleMessage(e){if(e.event==="context-pins-changed")return this.handleContextPinsChanged(e.data);if(e.event==="canvas-layout-update")return this.handleLayoutUpdate(e.data);return[]}handleContextPinsChanged(e){let t=e&&typeof e==="object"?e:{},n=Array.isArray(t.nodeIds)?t.nodeIds.filter((u)=>typeof u==="string"):[],o=Sv(e),r=new Set(n),{added:s,removed:a}=C0(this.currentPins,r);if(this.currentPins=r,!this.currentLayout)return[];let c=Bs(this.currentLayout.nodes),l={added:s.map((u)=>Fs(c.get(u),u)),removed:a.map((u)=>Fs(c.get(u),u))};if(this.previousSpatial=di(this.currentLayout.nodes,this.currentLayout.edges,this.currentPins,this.currentLayout.annotations??[]),l.added.length===0&&l.removed.length===0)return[];return[{type:"context-pin",...o,...l}]}handleLayoutUpdate(e){let t=e&&typeof e==="object"?e:{},n=t.layout&&typeof t.layout==="object"?t.layout:null;if(!n)return[];let o=Sv(e);if(!this.currentLayout)return this.currentLayout=n,this.previousSpatial=di(n.nodes,n.edges,this.currentPins,n.annotations??[]),[];let r=this.currentLayout,s=this.previousSpatial??di(r.nodes,r.edges,this.currentPins,r.annotations??[]),a=di(n.nodes,n.edges,this.currentPins,n.annotations??[]),c=[],l=Bs(r.nodes),u=Bs(n.nodes),p=xv(r.edges),d=xv(n.edges),f=Kt(Array.from(d.keys()).filter((g)=>!p.has(g))).map((g)=>d.get(g)).filter((g)=>g!==void 0);if(f.length>0)c.push({type:"connect",...o,edges:f.map((g)=>bv(g,u))});let m=Kt(Array.from(l.keys()).filter((g)=>!u.has(g))),h=Kt(Array.from(p.keys()).filter((g)=>!d.has(g)));if(m.length>0||h.length>0)c.push({type:"remove",...o,nodes:m.map((g)=>Fs(l.get(g),g)),edges:h.map((g)=>p.get(g)).filter((g)=>g!==void 0).map((g)=>bv(g,l))});let v=this.buildGroupEvent(l,u,o);if(v)c.push(v);let x=this.buildMoveEndEvent(r,n,l,u,s,a,o);if(x)c.push(x);return this.currentLayout=n,this.previousSpatial=a,c}buildGroupEvent(e,t,n){let o=Kt(Array.from(e.values()).filter((c)=>c.type==="group").map((c)=>c.id)),r=Kt(Array.from(t.values()).filter((c)=>c.type==="group").map((c)=>c.id)),s=r.filter((c)=>!o.includes(c)).map((c)=>{let l=t.get(c),u=au(l);return{id:c,title:nr(l),childCount:u.length}}),a=[];for(let c of r.filter((l)=>o.includes(l))){let l=au(e.get(c)),u=au(t.get(c));if(su(l,u))continue;a.push({id:c,title:nr(t.get(c)),addedChildIds:u.filter((p)=>!l.includes(p)),removedChildIds:l.filter((p)=>!u.includes(p)),childCount:u.length})}if(s.length===0&&a.length===0)return null;return{type:"group",...n,created:s,updated:a}}buildMoveEndEvent(e,t,n,o,r,s,a){let c=Kt(Array.from(o.keys()).filter((x)=>{let g=n.get(x),y=o.get(x);if(!g||!y)return!1;return g.position.x!==y.position.x||g.position.y!==y.position.y}));if(c.length===0)return null;let l=wv(r),u=wv(s),p=_v(r),d=_v(s),f=new Map,m=(x,g)=>{let y=f.get(x)??new Set;y.add(g),f.set(x,y)};for(let x of c){let g=l.get(x)??[],y=u.get(x)??[];if(!su(g,y))if(g.length===0&&y.length>0)m(x,"joined cluster");else if(g.length>0&&y.length===0)m(x,"left cluster");else m(x,"cluster changed")}let h=new Set([...p.keys(),...d.keys()]);for(let x of h){let g=p.get(x)??[],y=d.get(x)??[];if(su(g,y))continue;let E=nr(o.get(x)??n.get(x))??x,L=y.filter((b)=>!g.includes(b)),P=g.filter((b)=>!y.includes(b));for(let b of L)if(c.includes(b))m(b,`entered pinned neighborhood of "${E}"`);for(let b of P)if(c.includes(b))m(b,`left pinned neighborhood of "${E}"`);if(c.includes(x))m(x,"pinned neighborhood changed")}let v=c.filter((x)=>(f.get(x)?.size??0)>0).map((x)=>{let g=o.get(x);return{...Fs(g,x),reasons:Array.from(f.get(x)??[]).sort((y,E)=>y.localeCompare(E))}});if(v.length===0)return null;return{type:"move-end",...a,nodes:v}}}var js=q(null),pi=q([]),rr=q(new Set),ir=q(new Set),Zs=q([]),Us=q(new Set),un=q(!1),or=q(0);function kv(){js.value=null,pi.value=[],rr.value=new Set,ir.value=new Set,Zs.value=[],Us.value=new Set,un.value=!1,or.value=0}function qs(){un.value=!0,or.value=0}function Cv(){un.value=!1}function Tv(e,t,n){rr.value=new Set(e),ir.value=new Set(t),Zs.value=n}function Ws(e){js.value=e}function cu(e,t=6){if(pi.value=[e,...pi.value].slice(0,t),!un.value)or.value=Math.min(99,or.value+1)}function Vs(e){Us.value=new Set(e)}var pu=new Hs,sr=[],mi=null,ar=null,lu="",uu=0;function Ev(e,t){return globalThis.setTimeout(e,t)}function du(e){if(e===null)return;globalThis.clearTimeout(e)}function I0(e){if(typeof globalThis.requestAnimationFrame==="function"){globalThis.requestAnimationFrame(()=>e());return}e()}function Wn(e,t){return e&&e.trim().length>0?e.trim():t}function bn(e,t=3){if(e.length===0)return"";if(e.length<=t)return e.join(", ");return`${e.slice(0,t).join(", ")} +${e.length-t}`}function E0(e){return Array.from(new Set(Array.from(e).filter((t)=>t.length>0)))}function Yt(e,t,n,o,r=Date.now()){return{id:`${e}-${r}-${Math.random().toString(36).slice(2,8)}`,tone:e,title:t,detail:n,nodeIds:E0(o),createdAt:r}}function Iv(e){if(e==="joined cluster")return"joined a nearby cluster";if(e==="left cluster")return"moved away from its cluster";if(e==="cluster changed")return"shifted into a different cluster";if(e==="pinned neighborhood changed")return"changed the local focus field";let t=/^entered pinned neighborhood of "(.+)"$/.exec(e);if(t)return`moved into focus around ${t[1]}`;let n=/^left pinned neighborhood of "(.+)"$/.exec(e);if(n)return`moved out of focus around ${n[1]}`;return e}function A0(e){let t=e.added.map((r)=>Wn(r.title,r.id)),n=e.removed.map((r)=>Wn(r.title,r.id));if(t.length===0&&n.length===0)return null;let o="";if(t.length>0&&n.length===0)o=`Now in focus: ${bn(t)}`;else if(n.length>0&&t.length===0)o=`Removed from focus: ${bn(n)}`;else{let r=[];if(t.length>0)r.push(`${bn(t)} added`);if(n.length>0)r.push(`${bn(n)} removed`);o=r.join(" · ")}return Yt("context","Context updated",o,[...e.added.map((r)=>r.id),...e.removed.map((r)=>r.id)],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function z0(e){if(e.edges.length===0)return null;if(e.edges.length===1){let t=e.edges[0];return Yt("relationship","Relationship added",`${Wn(t.fromTitle,t.fromId)} linked to ${Wn(t.toTitle,t.toId)}`,[t.fromId,t.toId],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}return Yt("relationship","Relationships added",`${e.edges.length} connections changed the board structure`,e.edges.flatMap((t)=>[t.fromId,t.toId]),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function P0(e){if(e.nodes.length===0&&e.edges.length===0)return null;let t=e.nodes.map((o)=>Wn(o.title,o.id)),n=[];if(t.length>0)n.push(bn(t));if(e.edges.length>0)n.push(`${e.edges.length} relationship${e.edges.length===1?"":"s"}`);return Yt("remove","Items removed",n.join(" · "),[...e.nodes.map((o)=>o.id),...e.edges.flatMap((o)=>[o.fromId,o.toId])],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function N0(e){if(e.created.length>0){let t=e.created.map((n)=>Wn(n.title,n.id));return Yt("group",e.created.length===1?"Group created":"Groups created",e.created.length===1?`${t[0]} now frames ${e.created[0].childCount} items`:bn(t),e.created.map((n)=>n.id),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}if(e.updated.length>0){let t=e.updated.map((n)=>Wn(n.title,n.id));return Yt("group",e.updated.length===1?"Group updated":"Groups updated",e.updated.length===1?`${t[0]} now holds ${e.updated[0].childCount} items`:bn(t),e.updated.map((n)=>n.id),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}return null}function R0(e){if(e.nodes.length===0)return null;let t=e.nodes.flatMap((s)=>s.reasons),n=e.nodes.map((s)=>Wn(s.title,s.id)),o=e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now();if(t.some((s)=>s.includes("pinned neighborhood"))){if(e.nodes.length===1)return Yt("neighborhood","Neighborhood changed",`${n[0]} ${Iv(e.nodes[0].reasons[0])}`,e.nodes.map((s)=>s.id),o);return Yt("neighborhood","Neighborhood changed",bn(n),e.nodes.map((s)=>s.id),o)}let r=t.filter((s)=>s.includes("cluster"));if(r.length>0){let s=r.every((a)=>a==="joined cluster");if(e.nodes.length===1)return Yt("cluster",s?"Cluster formed":"Cluster changed",`${n[0]} ${Iv(e.nodes[0].reasons[0])}`,e.nodes.map((a)=>a.id),o);return Yt("cluster",s?"Cluster formed":"Cluster changed",bn(n),e.nodes.map((a)=>a.id),o)}return null}function $0(e){switch(e.type){case"context-pin":return A0(e);case"connect":return z0(e);case"remove":return P0(e);case"group":return N0(e);case"move-end":return R0(e)}}function M0(){let e=pu.getAttentionSnapshot();Tv(e.primaryFocusNodeIds,e.secondaryFocusNodeIds,e.regions)}function Av(){if(mi!==null)return;let e=sr.shift()??null;if(!e){Ws(null);return}Ws(e);let t=Math.max(1800,Math.min(2800,1600+e.detail.length*18));mi=Ev(()=>{mi=null,Ws(null),Av()},t)}function zv(e){if(sr.push(e),sr.length>3)sr.splice(0,sr.length-3);Av()}function xn(e,t,n="",o=[]){let r=Yt(e,t,n,o);cu(r),zv(r)}function O0(e){if(du(ar),ar=null,Vs([]),e.length===0)return;I0(()=>{Vs(e),ar=Ev(()=>{ar=null,Vs([])},900)})}function L0(e){let t=`${e.tone}:${e.title}:${e.detail}`,n=e.createdAt;if(t===lu&&n-uu<1200)return!0;return lu=t,uu=n,!1}function Gs(){du(mi),du(ar),mi=null,ar=null,sr=[],lu="",uu=0,pu=new Hs,kv()}function mu(e){let t=pu.handleMessage(e).map((n)=>$0(n)).filter((n)=>n!==null);M0();for(let n of t){if(L0(n))continue;cu(n),zv(n),O0(n.nodeIds)}}function fu(e,t){console.error(`[intent-bridge] ${e} failed`,t)}var Xs=(()=>{try{let e=new URLSearchParams(window.location.search).get("agent")?.trim();return e?e.slice(0,64):null}catch{return null}})();function hu(e){let t={...e?.headers};if(Xs)t["x-pmx-source"]=Xs;else{t["X-PMX-Workbench"]="1";let n=window.__PMX_WORKBENCH_TOKEN;if(typeof n==="string")t["X-PMX-Workbench-Token"]=n}return{...e,headers:t}}function gu(e,t,n){if(e.ok||(t?.method??"GET").toUpperCase()==="GET")return;let o=n!==null&&typeof n==="object"&&"error"in n&&typeof n.error==="string"?n.error:"";xn("remove","Change refused",o||`The server answered ${e.status}.`)}async function vu(e){try{return await e.json()}catch{return null}}async function Y(e,t,n,o){try{let r=await fetch(t,hu(o)),s=await vu(r);if(gu(r,o,s),s===null)throw Error(`${r.status} response had no JSON body`);return s}catch(r){return fu(e,r),n}}async function Mt(e,t,n){try{let o=await fetch(t,hu(n));if(!o.ok)gu(o,n,await vu(o));return{ok:o.ok}}catch(o){return fu(e,o),{ok:!1}}}async function Qt(e,t,n){try{let o=await fetch(t,hu(n));if(!o.ok)gu(o,n,await vu(o))}catch(o){fu(e,o)}}async function Pv(e,t={}){return Y("sendIntent","/api/workbench/intent",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:e,payload:t})})}async function Io(e){let n=`Veto: do not ${e.label?.trim()||`${e.kind} intent`}${e.reason?` — ${e.reason}`:""}.`;if((await Y("vetoGhostIntent",`/api/canvas/ax/intent/${encodeURIComponent(e.id)}`,{ok:!1,cleared:!1},{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({vetoed:!0})})).cleared!==!0)return!1;return await Qt("vetoGhostSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:n,source:"browser"})}),!0}async function wn(e){return(await Y("renderMarkdown","/api/render",{},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({markdown:e})})).html??""}async function fi(e){return Y("fetchFile",`/api/file?path=${encodeURIComponent(e)}`,{content:""})}async function Nv(e,t){return Y("saveFile","/api/file/save",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,content:t})})}async function Js(e){return Mt("openWorkbenchFile","/api/workbench/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})}async function Rv(){return Y("fetchCanvasState","/api/canvas/state?includeBlobs=true",{})}async function Ks(e){return Y("saveCanvasTheme","/api/canvas/theme",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({theme:e})})}async function $v(){return[]}async function hi(e,t,n,o,r){if(!e.trim())return{ok:!1,error:"Prompt text is required"};return Y("submitCanvasPrompt","/api/canvas/prompt",{ok:!1,error:"Network error"},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e,...t?{position:t}:{},...n?{parentNodeId:n}:{},...o&&o.length>0?{contextNodeIds:o}:{},...r?{threadNodeId:r}:{}})})}async function Mv(e,t){return hi(t,void 0,void 0,void 0,e)}async function Ys(e,t={}){await Qt("pushCanvasUpdate","/api/canvas/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:e,...t.recordHistory===!1?{recordHistory:!1}:{}})})}async function Eo(e,t,n,o){return Y("createEdgeFromClient","/api/canvas/edge",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:e,to:t,type:n,label:o})})}async function en(e){return Y("createNodeFromClient","/api/canvas/node",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function pt(e,t){return Y("updateNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}`,{ok:!1},{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Qs(e,t){return Y("refreshWebpageNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}/refresh`,{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{url:t}:{})})}async function Vn(e){return Y("removeNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}`,{ok:!1},{method:"DELETE"})}async function Ov(){return Y("fetchAxSurfaceState","/api/canvas/ax/surface-snapshot",null)}async function Lv(){return Y("fetchAgentPresence","/api/canvas/ax/presence",null)}async function Dv(e,t){return Y("openNodeInSystemBrowserRequest","/api/canvas/open-external",{ok:!1,opened:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodeId:e,url:t})})}async function ea(e){return Y("submitAxInteractionFromClient","/api/canvas/ax/interaction",{ok:!1,code:"request-failed",error:"Request failed"},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceSurface:"native-node",...e,source:"browser"})})}async function Fv(e,t={}){return Y("updateViewportFromClient","/api/canvas/viewport",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,...Bv(),...t.recordHistory===!1?{recordHistory:!1}:{}})})}function Bv(){if(typeof window>"u")return{};let e=rt(),t=Math.round(e.width),n=Math.round(e.height);if(!t||!n)return{};return{clientWidth:t,clientHeight:n}}async function gi(){let e=Bv();if(!("clientWidth"in e))return;await Qt("reportClientViewportSize","/api/canvas/viewport",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,recordHistory:!1})})}async function cr(e){return Y("createGroupFromClient","/api/canvas/group",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function yu(e,t,n){return Y("addToGroupFromClient","/api/canvas/group/add",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({groupId:e,childIds:t,...n?{childLayout:n}:{}})})}async function ta(e,t){return pt(e,{children:t})}async function lr(e){return Y("ungroupFromClient","/api/canvas/group/ungroup",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({groupId:e})})}async function Hv(){return Y("listSnapshots","/api/canvas/snapshots?all=true",[])}async function jv(e){return Y("saveSnapshot","/api/canvas/snapshots",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})}async function Zv(e){return Y("restoreSnapshot",`/api/canvas/snapshots/${e}`,{ok:!1},{method:"POST"})}async function Uv(e){return Y("deleteSnapshot",`/api/canvas/snapshots/${e}`,{ok:!1},{method:"DELETE"})}async function na(e,t){return Y("updateEdgeFromClient",`/api/canvas/edge/${encodeURIComponent(e)}`,{ok:!1},{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function oa(e){return Y("removeEdgeFromClient","/api/canvas/edge",{ok:!1},{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({edge_id:e})})}function Xv(e,t){console.error(`[canvas-store] ${e} failed`,t)}var K=q({x:0,y:0,scale:1}),F=q(new Map),De=q(new Map),ur=q(new Map),Ce=q(null),pn=q(null),Ot=q("connecting"),zo=q(0),Po=q(0),No=q(0),_n=q(""),dr=q(!1),tt=q("dark"),It=q(!1),nn=q(null),qe=q(null),tn=q(null),xt=null,Ao,qv=100,D0=2500,yi=q(null),je=q(null),Sn=q(null),be=q(new Set),Ae=q(new Set),Et=q("select"),bi=q(!1);function pr(){return Et.value==="pan"||bi.value}function Jv(e,t){if(!e)return new Set;let n=new Set;for(let o of t.values()){if(o.from===e)n.add(o.to);if(o.to===e)n.add(o.from)}return n}var Kv=Le(()=>Jv(Ce.value,De.value));function Wv(e,t){let n=new Set;for(let o of e)if(t.has(o))n.add(o);return n}function Vv(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function wu(e){let t=new Set(be.value);if(t.has(e))t.delete(e);else t.add(e);be.value=t}function Yv(e){be.value=new Set(e)}function wt(){if(pn.value=null,be.value.size===0)return;be.value=new Set}function Qv(){if(xt!==null)clearTimeout(xt),xt=null;$t(()=>{Ce.value=null,qe.value=null,tn.value=null,Ao=void 0,be.value=new Set,pn.value=null,yi.value=null,je.value=null,Sn.value=null,dn.value=null,Ae.value=new Set}),ra=!1}var dn=q(null),ra=!1;function ey(){ra=!0,dn.value=null}function ty(){ra=!1,dn.value=null}function bu(e){return{x:e.position.x,y:e.position.y,w:e.size.width,h:e.size.height}}function F0(e,t,n){let o=bu(e);return t>=o.x&&t<=o.x+o.w&&n>=o.y&&n<=o.y+o.h}function Gv(e,t){let n=bu(e),o=bu(t);return n.x+n.w<o.x||n.x>o.x+o.w||n.y+n.h<o.y||n.y>o.y+o.h}function ny(e){let t=F.value.get(e);if(!t||t.type==="group")return;let n=typeof t.data.parentGroup==="string"?t.data.parentGroup:null,o=n?F.value.get(n):void 0,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2,a=null;for(let c of F.value.values()){if(c.type!=="group"||c.id===n||c.collapsed)continue;if(F0(c,r,s))a=c}if(!ra){let c=a?{nodeId:e,groupId:a.id,mode:"add"}:o&&Gv(t,o)?{nodeId:e,groupId:o.id,mode:"remove"}:null,l=dn.value;if((l?.groupId??null)!==(c?.groupId??null)||l?.mode!==c?.mode)dn.value=c}if(o&&o.data.frameMode!=="manual"&&!Gv(t,o)){let l=Math.min(o.position.x,t.position.x-22),u=Math.min(o.position.y,t.position.y-22-32),p=Math.max(o.position.x+o.size.width,t.position.x+t.size.width+22),d=Math.max(o.position.y+o.size.height,t.position.y+t.size.height+22);if(l!==o.position.x||u!==o.position.y||p!==o.position.x+o.size.width||d!==o.position.y+o.size.height)ca(o.id,{position:{x:l,y:u},size:{width:p-l,height:d-u}},{skipGroupChildTranslation:!0})}}var _u=Le(()=>{let e=new Map;for(let t of F.value.values()){if(t.type!=="group"||!t.collapsed)continue;let n=Array.isArray(t.data.children)?t.data.children:[];for(let o of n)if(typeof o==="string")e.set(o,t.id)}return e});function ia(e){let t=_u.value.get(e);return F.value.get(t??e)}function oy(){let e=new Set;for(let t of be.value){let n=F.value.get(t);if(!n)continue;if(n.type==="group")e.add(n.id);else if(typeof n.data.parentGroup==="string")e.add(n.data.parentGroup)}return[...e]}function Su(e){let t=ku();if(t.length<2)return;let n=Math.min(...t.map((l)=>e==="left"?l.position.x:l.position.y)),o=24,r=new Map;for(let l of t)r.set(l.id,e==="left"?{x:n,y:l.position.y}:{x:l.position.x,y:n});let s=(l,u)=>l.x<u.x+u.w&&u.x<l.x+l.w&&l.y<u.y+u.h&&u.y<l.y+l.h,a=t.map((l)=>{let u=r.get(l.id);return{node:l,x:u.x,y:u.y,w:l.size.width,h:l.size.height}});if(a.some((l,u)=>a.some((p,d)=>d>u&&s(l,p)))){let l=[...t].sort((p,d)=>e==="left"?p.position.y-d.position.y:p.position.x-d.position.x),u=e==="left"?Math.min(...t.map((p)=>p.position.y)):Math.min(...t.map((p)=>p.position.x));for(let p of l)r.set(p.id,e==="left"?{x:n,y:u}:{x:u,y:n}),u+=(e==="left"?p.size.height:p.size.width)+o}$t(()=>{for(let l of t)st(l.id,{position:r.get(l.id)})}),at()}function ry(){let e=ku().sort((c,l)=>c.position.x-l.position.x);if(e.length<3)return;let t=e[0],o=e[e.length-1].position.x-(t.position.x+t.size.width),r=e.slice(1,-1),s=r.reduce((c,l)=>c+l.size.width,0),a=(o-s)/(r.length+1);$t(()=>{if(a<8){let l=t.position.x+t.size.width+24;for(let u of e.slice(1))st(u.id,{position:{x:l,y:u.position.y}}),l+=u.size.width+24;return}let c=t.position.x+t.size.width+a;for(let l of r)st(l.id,{position:{x:c,y:l.position.y}}),c+=l.size.width+a}),at()}function iy(e=24){let t=ku().sort((c,l)=>c.position.y-l.position.y||c.position.x-l.position.x);if(t.length<2)return;let n=Math.min(...t.map((c)=>c.position.x)),o=Math.min(...t.map((c)=>c.position.y)),r=Math.ceil(Math.sqrt(t.length)),s=Math.max(...t.map((c)=>c.size.width)),a=Math.max(...t.map((c)=>c.size.height));$t(()=>{t.forEach((c,l)=>{st(c.id,{position:{x:n+l%r*(s+e),y:o+Math.floor(l/r)*(a+e)}})})}),at()}function ku(){let e=be.value;if(e.size===0)return[];return Array.from(e).map((t)=>F.value.get(t)).filter((t)=>t!==void 0)}function Xn(e){let t=new Set(Ae.value);if(t.has(e))t.delete(e);else t.add(e);Ae.value=t,at(),aa(t)}function sa(e){let t=new Set(Ae.value);for(let n of e)t.add(n);Ae.value=t,at(),aa(t)}function sy(){if(Ae.value.size===0)return;Ae.value=new Set,at(),aa(new Set)}function ay(e){Ae.value=new Set(e)}function aa(e){Qt("syncContextPinsToServer","/api/canvas/context-pins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodeIds:Array.from(e)})})}var vi=1;function kn(e){$t(()=>{let t=new Map(F.value);if(e.zIndex>=vi)vi=e.zIndex+1;t.set(e.id,e),F.value=t,Ce.value=e.id})}function st(e,t){ca(e,t)}function ca(e,t,n={}){let o=F.value.get(e);if(!o)return;let r=new Map(F.value);if(o.type==="group"&&t.position&&n.skipGroupChildTranslation!==!0){let a=t.position.x-o.position.x,c=t.position.y-o.position.y;if(a!==0||c!==0){let l=Array.isArray(o.data.children)?o.data.children.filter((u)=>typeof u==="string"):[];for(let u of l){let p=r.get(u);if(!p||p.type==="group")continue;r.set(u,{...p,position:{x:p.position.x+a,y:p.position.y+c}})}}}r.set(e,{...o,...t}),F.value=r;let s=r.get(e)?.data.appCheckpoint?.updatedAt;if(tn.value===e&&s!==void 0&&s!==Ao)xu(e)}function ie(e,t){let n=F.value.get(e);if(!n)return;st(e,{data:{...n.data,...t}})}function Jn(e){B0(e);let t=new Map(F.value);if(t.delete(e),F.value=t,Ce.value===e)Ce.value=null;if(qe.value===e)qe.value=null;if(be.value.has(e)){let n=new Set(be.value);n.delete(e),be.value=n}if(Ae.value.has(e)){let n=new Set(Ae.value);n.delete(e),Ae.value=n,aa(n)}}function la(e){let t=new Map(De.value);t.set(e.id,e),De.value=t}function cy(e){let t=new Map(De.value);t.delete(e),De.value=t}function B0(e){let t=!1,n=new Map(De.value);for(let[o,r]of n)if(r.from===e||r.to===e)n.delete(o),t=!0;if(t)De.value=n}function H0(e){let t=new Map(ur.value);if(!t.delete(e))return;ur.value=t}async function Cu(e){return Mt("createAnnotationFromClient","/api/canvas/annotation",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function ly(e){let t=await Mt("removeAnnotationFromClient",`/api/canvas/annotation/${encodeURIComponent(e)}`,{method:"DELETE"});if(t.ok)H0(e);return t}function ua(e,t){if(!F.value.get(e))return;st(e,{size:t})}function Cn(e){let t=F.value.get(e);if(!t)return;$t(()=>{if(st(e,{zIndex:vi++}),t.type==="group"&&Array.isArray(t.data.children)){for(let n of t.data.children)if(typeof n==="string"&&F.value.has(n))st(n,{zIndex:vi++})}}),Ce.value=e}function mr(e){let t=F.value.get(e);if(!t)return;st(e,{collapsed:!t.collapsed}),at()}function uy(e){K.value={...K.value,...e}}function dy(e){K.value=e}function py(e){my(e)}function my(e,t={}){K.value=e,at(t),Fv(e,t)}function fy(e,t={}){let n=new Map,o=1;for(let d of e.nodes)if(n.set(d.id,d),d.zIndex>=o)o=d.zIndex+1;let r=e.edges.filter((d)=>n.has(d.from)&&n.has(d.to)),s=new Map;for(let d of r)s.set(d.id,d);let a=new Map;for(let d of e.annotations??[])a.set(d.id,d);let c=Ce.value!==null&&n.has(Ce.value)?Ce.value:null,l=qe.value!==null&&n.has(qe.value)?qe.value:null,u=Wv(be.value,n),p=Wv(Ae.value,n);$t(()=>{if(t.applyViewport===!0&&e.viewport)K.value=e.viewport;if(vi=o,F.value=n,De.value=s,ur.value=a,Ce.value=c,qe.value=l,!Vv(be.value,u))be.value=u;if(!Vv(Ae.value,p))Ae.value=p})}var Gn=null;function j0(e){return 1-(1-e)**3}function fr(e,t=150){let n=K.value,o=Math.min(4,Math.max(0.1,n.scale*e));if(o===n.scale)return;let r=o/n.scale,{x:s,y:a}=qn();Kn({x:s-r*(s-n.x),y:a-r*(a-n.y),scale:o},t)}function Kn(e,t=300,n={}){if(Gn!==null)cancelAnimationFrame(Gn);let o={...K.value},r=performance.now();function s(a){let c=a-r,l=Math.min(1,c/t),u=j0(l);if(K.value={x:o.x+(e.x-o.x)*u,y:o.y+(e.y-o.y)*u,scale:o.scale+(e.scale-o.scale)*u},l<1)Gn=requestAnimationFrame(s);else Gn=null,my(e,n)}Gn=requestAnimationFrame(s)}function Tn(){if(Gn!==null)cancelAnimationFrame(Gn),Gn=null}var hy="pmx-canvas-layout";function at(e={}){try{let t=Array.from(F.value.values()),n=t.map((r)=>({id:r.id,position:r.position,size:r.size,collapsed:r.collapsed})),o={viewport:K.value,nodes:t.map((r)=>({id:r.id,type:r.type,position:r.position,size:r.size,collapsed:r.collapsed,pinned:r.pinned})),edges:Array.from(De.value.values()).map((r)=>({id:r.id,from:r.from,to:r.to,type:r.type,label:r.label,style:r.style,animated:r.animated})),contextPinnedNodeIds:Array.from(Ae.value)};localStorage.setItem(hy,JSON.stringify(o)),Ys(n,e)}catch(t){Xv("persistLayout",t)}}function Tu(){try{let e=localStorage.getItem(hy);if(!e)return null;let t=JSON.parse(e),n=Array.isArray(t.nodes)?t.nodes:[];if(n.length===0)return null;let o=new Map;for(let r of n){if(typeof r.id!=="string"||r.id.length===0)continue;o.set(r.id,{...r.position?{position:r.position}:{},...r.size?{size:r.size}:{},...r.collapsed!==void 0?{collapsed:r.collapsed}:{},...r.pinned!==void 0?{pinned:r.pinned}:{}})}return o.size>0?o:null}catch(e){return Xv("restoreLayout",e),null}}function hr(e,t){let n=Array.from(F.value.values());if(n.length===0)return;let{POSITIVE_INFINITY:o,POSITIVE_INFINITY:r,NEGATIVE_INFINITY:s,NEGATIVE_INFINITY:a}=Number;for(let v of n)o=Math.min(o,v.position.x),r=Math.min(r,v.position.y),s=Math.max(s,v.position.x+v.size.width),a=Math.max(a,v.position.y+v.size.height);let c=eu(),l=Math.max(80,e-c.left-c.right),u=Math.max(80,t-c.top-c.bottom),p=Math.max(1,s-o),d=Math.max(1,a-r),f=Math.min(1,Math.min(l/p,u/d)),m=(o+s)/2,h=(r+a)/2;Kn({x:c.left+l/2-m*f,y:c.top+u/2-h*f,scale:f})}function Ke(e,t={}){let n=F.value.get(e);if(!n)return;let o=K.value,r=rt(),s=eu(),a=Math.max(80,r.width-s.left-s.right),c=Math.max(80,r.height-s.top-s.bottom),l=Math.min(o.scale,a/n.size.width,c/n.size.height),u=n.position.x+n.size.width/2,p=n.position.y+n.size.height/2;Kn({x:s.left+a/2-u*l,y:s.top+c/2-p*l,scale:l},300,t),Cn(e)}function gy(e=1){let t=Array.from(F.value.keys());if(t.length===0)return;let o=((Ce.value?t.indexOf(Ce.value):-1)+e+t.length)%t.length,r=t[o];Cn(r),Ke(r)}function vy(e){let t=Ce.value;if(!t)return;let n=F.value.get(t);if(!n)return;let o=Jv(t,De.value);if(o.size===0)return;let r=n.position.x+n.size.width/2,s=n.position.y+n.size.height/2,a=null,c=-1/0;for(let l of o){let u=F.value.get(l);if(!u)continue;let p=u.position.x+u.size.width/2,d=u.position.y+u.size.height/2,f=p-r,m=d-s,h=Math.sqrt(f*f+m*m);if(h<1)continue;let v;switch(e){case"up":v=-m;break;case"down":v=m;break;case"left":v=-f;break;case"right":v=f;break}if(v<=0)continue;let x=v/h-h*0.001;if(x>c)c=x,a=l}if(a)Ke(a)}function Ut(e){if(!F.value.get(e))return;if(xt!==null)clearTimeout(xt),xt=null;tn.value=null,Ao=void 0,Cn(e),qe.value=e}function xu(e){if(xt!==null)clearTimeout(xt),xt=null;if(qe.value===e)qe.value=null;if(tn.value===e)tn.value=null;Ao=void 0}function In(){let e=qe.value,t=e?F.value.get(e):void 0;if(e&&t&&gv(t)){let n=e,o=Date.now();if(tn.value=n,Ao=t.data.appCheckpoint?.updatedAt,xt!==null)clearTimeout(xt);let r=()=>{let a=F.value.get(n)?.data.appCheckpoint?.updatedAt;if(a!==void 0&&a!==Ao){xu(n);return}if(Date.now()-o>=D0){xu(n);return}xt=setTimeout(r,qv)};xt=setTimeout(r,qv);return}if(xt!==null)clearTimeout(xt),xt=null;tn.value=null,Ao=void 0,qe.value=null}function da(){let e=iu(Array.from(F.value.values()),Array.from(De.value.values()),"grid");if(e.nodePositions.size===0&&e.groupBounds.size===0)return;$t(()=>{for(let[t,n]of e.nodePositions.entries())st(t,{position:n});for(let[t,n]of e.groupBounds.entries())ca(t,{position:{x:n.x,y:n.y},size:{width:n.width,height:n.height}},{skipGroupChildTranslation:!0})}),at()}function pa(){let e=iu(Array.from(F.value.values()),Array.from(De.value.values()),"graph");if(e.nodePositions.size===0&&e.groupBounds.size===0)return;$t(()=>{for(let[t,n]of e.nodePositions.entries())st(t,{position:n});for(let[t,n]of e.groupBounds.entries())ca(t,{position:{x:n.x,y:n.y},size:{width:n.width,height:n.height}},{skipGroupChildTranslation:!0})}),at()}var on=q(!1),Yn=q(!1);function Iu(){return on.value||Yn.value}var Z0=0.1,U0=4,yy=1;function by(e){return Math.min(U0,Math.max(Z0,e))}function ma({viewport:e,onViewportChange:t,onViewportCommit:n,disabled:o=!1}){let r=R(null),s=R(!1),a=R({x:0,y:0}),c=R(0),l=R(null),u=H((g)=>{if(l.current!==null)window.clearTimeout(l.current);l.current=window.setTimeout(()=>{l.current=null,n(g)},140)},[n]);function p(g){if(g.deltaMode!==0)return g.deltaX===0;return g.deltaX===0&&Number.isInteger(g.deltaY)&&Math.abs(g.deltaY)>=50}let d=H((g)=>{if(o)return;g.preventDefault();let y=e.value;if(g.ctrlKey||g.metaKey||p(g)){let E=r.current?.getBoundingClientRect();if(!E)return;let L=g.clientX-E.left,P=g.clientY-E.top,b=-g.deltaY*0.002,T=by(y.scale*(1+b)),w=T/y.scale,_={x:L-w*(L-y.x),y:P-w*(P-y.y),scale:T};t(_),u(_)}else{let E={x:y.x-g.deltaX*yy,y:y.y-g.deltaY*yy,scale:y.scale};t(E),u(E)}},[o,e,t,u]),f=H((g)=>{if(o)return;let y=r.current;if(!y)return;if(g.button===1||g.button===2)g.preventDefault();else if(pr()){if(g.target!==y)return;g.preventDefault()}else return;s.current=!0,document.documentElement.classList.add("is-canvas-panning"),a.current={x:g.clientX,y:g.clientY},y.setPointerCapture(g.pointerId)},[o]),m=H((g)=>{if(!s.current)return;if(o)return;let y=g.clientX-a.current.x,E=g.clientY-a.current.y;a.current={x:g.clientX,y:g.clientY};let L=e.value;t({x:L.x+y,y:L.y+E,scale:L.scale})},[o,e,t]),h=H(()=>{if(s.current)n(e.value);s.current=!1,document.documentElement.classList.remove("is-canvas-panning")},[n,e]),v=H((g)=>{if(o)return;if(g.touches.length!==2){c.current=0;return}g.preventDefault();let y=g.touches[0],E=g.touches[1],L=Math.hypot(E.clientX-y.clientX,E.clientY-y.clientY),P=(y.clientX+E.clientX)/2,b=(y.clientY+E.clientY)/2;if(c.current>0){let T=e.value,w=r.current?.getBoundingClientRect();if(!w)return;let _=P-w.left,z=b-w.top,U=L/c.current,N=by(T.scale*U),Z=N/T.scale,j={x:_-Z*(_-T.x),y:z-Z*(z-T.y),scale:N};t(j),u(j)}c.current=L},[o,e,t,u]),x=H(()=>{if(l.current!==null)window.clearTimeout(l.current),l.current=null;n(e.value),c.current=0},[n,e]);return B(()=>{let g=r.current;if(!g)return;return g.addEventListener("wheel",d,{passive:!1}),g.addEventListener("pointerdown",f),g.addEventListener("pointermove",m),g.addEventListener("pointerup",h),g.addEventListener("pointercancel",h),g.addEventListener("lostpointercapture",h),g.addEventListener("touchmove",v,{passive:!1}),g.addEventListener("touchend",x),()=>{if(l.current!==null)window.clearTimeout(l.current);g.removeEventListener("wheel",d),g.removeEventListener("pointerdown",f),g.removeEventListener("pointermove",m),g.removeEventListener("pointerup",h),g.removeEventListener("pointercancel",h),g.removeEventListener("lostpointercapture",h),g.removeEventListener("touchmove",v),g.removeEventListener("touchend",x)}},[d,f,m,h,v,x]),B(()=>()=>{document.documentElement.classList.remove("is-canvas-panning")},[]),r}var q0=0;function i(e,t,n,o,r,s){t||(t={});var a,c,l=t;if("ref"in l)for(c in l={},t)c=="ref"?a=t[c]:l[c]=t[c];var u={type:e,props:l,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--q0,__i:-1,__u:0,__source:r,__self:s};if(typeof e=="function"&&(a=e.defaultProps))for(c in a)l[c]===void 0&&(l[c]=a[c]);return _e.vnode&&_e.vnode(u),u}function xy(){let[e,t]=I({stops:[]}),[n,o]=I(0),[r,s]=I(""),a=on.value,c=It.value,l=R(0),u=(d)=>{cancelAnimationFrame(l.current),K.value=d},p=ma({viewport:K,onViewportChange:u,onViewportCommit:u});return B(()=>{let d=new URLSearchParams(location.search);return on.value=d.get("present")==="1",Yn.value=d.get("capture")==="1",window.pmxCapture={ready:()=>It.value,area:rt,camera:()=>({...K.value}),frame:async(f)=>(Yn.value=!0,Tn(),K.value=Yl.parse(f),await new Promise((m)=>requestAnimationFrame(()=>requestAnimationFrame(()=>m()))),{...K.value})},()=>{delete window.pmxCapture,on.value=!1,Yn.value=!1}},[]),B(()=>{if(!a||!c)return;let d=!1;return Y("read tour","/api/canvas/tour",{tour:{stops:[]}}).then((f)=>{if(!d)t(f.tour),o(0)}),()=>{d=!0}},[a,c]),B(()=>{if(!a||Yn.value)return;let d=e.stops[n];if(!d)return;let f=rt(),m;try{m=ov(d,[...F.value.values()],f.width,f.height),s("")}catch(y){s(y instanceof Error?y.message:String(y));return}Tn();let h={...K.value},v=performance.now(),x=(d.duration??1)*1000,g=(y)=>{if(Yn.value)return;let E=x===0?1:Math.min(1,(y-v)/x);if(K.value=rv(h,m,E,f.width,f.height,d.easing,d.pullback),E<1)l.current=requestAnimationFrame(g)};return l.current=requestAnimationFrame(g),()=>cancelAnimationFrame(l.current)},[a,n,e]),B(()=>{if(!a)return;let d=(f)=>{if(f.stopImmediatePropagation(),f.target instanceof HTMLButtonElement&&["Enter"," "].includes(f.key))return;if(["Escape","ArrowRight","ArrowDown","ArrowLeft","ArrowUp"," "].includes(f.key))f.preventDefault();if(f.key==="Escape")on.value=!1;if(["ArrowRight","ArrowDown"," "].includes(f.key))o((m)=>Math.max(0,Math.min(e.stops.length-1,m+1)));if(["ArrowLeft","ArrowUp"].includes(f.key))o((m)=>Math.max(0,m-1))};return document.addEventListener("keydown",d,!0),()=>document.removeEventListener("keydown",d,!0)},[a,e]),a?i(pe,{children:[!Yn.value&&i("div",{class:"presentation-navigation",ref:p,onPointerDown:(d)=>{if(d.button===1||d.button===2)cancelAnimationFrame(l.current)},onContextMenu:(d)=>d.preventDefault(),children:i("button",{type:"button",class:"presentation-exit",onClick:()=>on.value=!1,children:"Exit presentation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r&&i("div",{class:"presentation-error",role:"alert",children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null}var W0={fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};function le({size:e=16,children:t,...n}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",style:{verticalAlign:"middle",flexShrink:0},...W0,...n,children:t},void 0,!1,void 0,this)}function Pe(e){return i(le,{...e,children:i("path",{d:"m4 4 8 8M12 4l-8 8"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function wy(e){return i(le,{...e,children:i("path",{d:"M8 2v12M2 8h12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function _y(e){return i(le,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("path",{d:"M8 5v6M5 8h6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function vr(e){return i(le,{...e,children:i("polyline",{points:"6 3 11 8 6 13"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Sy(e){return i(le,{...e,children:[i("circle",{cx:"3",cy:"8",r:"0.75"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"0.75"},void 0,!1,void 0,this),i("circle",{cx:"13",cy:"8",r:"0.75"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function mn(e){return i(le,{...e,children:i("path",{d:"M9 2h5v5M14 2 7 9M6 3H2v11h11v-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function ky(e){return i(le,{...e,children:i("path",{d:"M9 2h5v5M14 2l-5 5M7 14H2V9M2 14l5-5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Cy(e){return i(le,{...e,children:i("path",{d:"M14 8H2m5-5-5 5 5 5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function ha(e){return i(le,{...e,children:i("path",{d:"M13.5 6A5.5 5.5 0 1 0 13 11M14 2v4h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Au(e){return i(le,{...e,children:i("path",{d:"M6 2 2 6l4 4M2 6h7a4 4 0 0 1 0 8"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Ty(e){return i(le,{...e,children:i("path",{d:"m8 1 2 5 5 2-5 2-2 5-2-5-5-2 5-2Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Iy(e){return i(le,{...e,children:i("path",{d:"M8 10V2M4.5 5.5 8 2l3.5 3.5M2 10v3.5h12V10"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function ga(e){return i(le,{...e,children:i("polyline",{points:"3 6 8 11 13 6"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function va(e){return i(le,{...e,children:[i("polyline",{points:"1 5 1 1 5 1"},void 0,!1,void 0,this),i("polyline",{points:"11 1 15 1 15 5"},void 0,!1,void 0,this),i("polyline",{points:"15 11 15 15 11 15"},void 0,!1,void 0,this),i("polyline",{points:"5 15 1 15 1 11"},void 0,!1,void 0,this),i("rect",{x:"4",y:"4",width:"8",height:"8",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ey(e){return i(le,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),i("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this),i("line",{x1:"7",y1:"5",x2:"7",y2:"9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ay(e){return i(le,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),i("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function En(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"4",x2:"9.5",y2:"4"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"12",x2:"9.5",y2:"12"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6.5",x2:"4",y2:"9.5"},void 0,!1,void 0,this),i("line",{x1:"12",y1:"6.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ya(e){return i(le,{...e,children:[i("rect",{x:"1",y:"2",width:"14",height:"12",rx:"1.5"},void 0,!1,void 0,this),i("rect",{x:"8",y:"7",width:"6",height:"6",rx:"1",fill:"currentColor","fill-opacity":"0.2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zy(e){return i(le,{...e,children:[i("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"1",x2:"8",y2:"3"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"13",x2:"8",y2:"15"},void 0,!1,void 0,this),i("line",{x1:"1",y1:"8",x2:"3",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"13",y1:"8",x2:"15",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"3.05",y1:"3.05",x2:"4.46",y2:"4.46"},void 0,!1,void 0,this),i("line",{x1:"11.54",y1:"11.54",x2:"12.95",y2:"12.95"},void 0,!1,void 0,this),i("line",{x1:"3.05",y1:"12.95",x2:"4.46",y2:"11.54"},void 0,!1,void 0,this),i("line",{x1:"11.54",y1:"4.46",x2:"12.95",y2:"3.05"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ba(e){return i(le,{...e,children:i("path",{d:"M13 9.5A5.5 5.5 0 1 1 6.5 3 4.5 4.5 0 0 0 13 9.5Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function zu(e){return i(le,{...e,children:[i("path",{d:"M3 13l2.8-.7L13 5.1 10.9 3 3.7 10.2 3 13Z"},void 0,!1,void 0,this),i("path",{d:"M9.8 4.1l2.1 2.1"},void 0,!1,void 0,this),i("path",{d:"M2.5 14h11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Pu(e){return i(le,{...e,children:[i("path",{d:"M3 10.5 8.5 5a2 2 0 0 1 2.8 0l1.7 1.7a2 2 0 0 1 0 2.8L8.5 14H5.8L3 11.2Z"},void 0,!1,void 0,this),i("path",{d:"M7.5 6 12 10.5"},void 0,!1,void 0,this),i("path",{d:"M8.5 14H14"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Nu(e){return i(le,{...e,children:[i("path",{d:"M3 4h10"},void 0,!1,void 0,this),i("path",{d:"M8 4v8"},void 0,!1,void 0,this),i("path",{d:"M6 12h4"},void 0,!1,void 0,this),i("path",{d:"M4.5 4 4 6"},void 0,!1,void 0,this),i("path",{d:"M11.5 4 12 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Py(e){return i(le,{...e,children:[i("rect",{x:"1",y:"4",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M5.5 4 L6.5 2.5 H9.5 L10.5 4"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"9",r:"2.3"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ny(e){return i(le,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"0.8",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ry(e){return i(le,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"10.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"5.5",x2:"5.5",y2:"10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $y(e){return i(le,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function My(e){return i(le,{...e,children:[i("rect",{x:"1",y:"3",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6",x2:"5",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"7.5",y1:"6",x2:"8.5",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"11",y1:"6",x2:"12",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"10",x2:"12",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function yr(e){return i(le,{...e,children:i("path",{d:"M2 13 L2 4 A2 2 0 0 1 4 2 L12 2 A2 2 0 0 1 14 4 L14 9 A2 2 0 0 1 12 11 L5 11 Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function xa({size:e=22,class:t}){return i("svg",{width:e,height:e,viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",class:t,"aria-hidden":"true",children:[i("rect",{x:"8",y:"8",width:"48",height:"48",rx:"7",fill:"none",stroke:"currentColor","stroke-width":"2.2",opacity:"0.35"},void 0,!1,void 0,this),i("rect",{x:"16",y:"16",width:"32",height:"32",rx:"5",fill:"none",stroke:"currentColor","stroke-width":"2.2",opacity:"0.6"},void 0,!1,void 0,this),i("rect",{x:"24",y:"24",width:"16",height:"16",rx:"3",fill:"none",stroke:"currentColor","stroke-width":"2.2"},void 0,!1,void 0,this),i("rect",{x:"29",y:"29",width:"6",height:"6",rx:"1",fill:"currentColor"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Oy({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M3 2l10 5.5-4.2 1.3L7.5 13z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Ly({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M5 7.5V3.8a1 1 0 0 1 2 0V7m0-3.9a1 1 0 0 1 2 0V7m0-2.7a1 1 0 0 1 2 0V7.4m0-.9a1 1 0 0 1 2 0v3.2A4.3 4.3 0 0 1 8.7 14H8a4.3 4.3 0 0 1-3.6-2L2.7 9.3a1 1 0 0 1 1.6-1.2L5 9.2"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Dy({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M6 4.5L2.5 8 6 11.5M10 4.5L13.5 8 10 11.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Qn(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6",x2:"10",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"8.5",x2:"8",y2:"8.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"11",x2:"11",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function V0(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M4 13.5 L5.5 11.5 L8 11.5"},void 0,!1,void 0,this),i("polyline",{points:"5 6 7 8 5 10"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"10",x2:"11",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function G0(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M12 13.5 L10.5 11.5 L8 11.5"},void 0,!1,void 0,this),i("circle",{cx:"5",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"11",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function fa(e){return i(le,{...e,children:[i("path",{d:"M3 1.5h6l3.5 3.5v8a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V2.5a1 1 0 0 1 1-1z"},void 0,!1,void 0,this),i("polyline",{points:"9 1.5 9 5 12.5 5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"8.5",x2:"10.5",y2:"8.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"11",x2:"9",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ru(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"5.5",cy:"6.5",r:"1.2"},void 0,!1,void 0,this),i("path",{d:"M1.8 12 L6 8.5 L9 11 L11.5 9 L14.2 12"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function gr(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"1.5",y1:"5.5",x2:"14.5",y2:"5.5"},void 0,!1,void 0,this),i("circle",{cx:"3.3",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"5",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"6.7",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"8",x2:"12",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"10",x2:"10",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function X0(e){return i(le,{...e,children:[i("rect",{x:"2",y:"4",width:"12",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"2",y1:"6.5",x2:"14",y2:"6.5"},void 0,!1,void 0,this),i("path",{d:"M11 1.5 L11 4"},void 0,!1,void 0,this),i("circle",{cx:"11",cy:"4",r:"1.6",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $u(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"1.5","stroke-dasharray":"2 1.5"},void 0,!1,void 0,this),i("rect",{x:"4",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),i("rect",{x:"8.5",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),i("rect",{x:"6.25",y:"8.5",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function J0(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"9.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function K0(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M3.5 10.5 L6 6.5 L8.5 9.5 L12.5 5"},void 0,!1,void 0,this),i("circle",{cx:"12.5",cy:"5",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Y0(e){return i(le,{...e,children:[i("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"5.5",x2:"11.5",y2:"5.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"8",x2:"11.5",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"10.5",x2:"8",y2:"10.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"2",x2:"6.5",y2:"14",opacity:"0.45"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Q0(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this),i("path",{d:"M4 11 L4 6 L6 8.5 L8 6 L8 11"},void 0,!1,void 0,this),i("path",{d:"M10 11 L10 6 L12.5 11 L12.5 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function eC(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("polyline",{points:"10 5 13 5 13 8"},void 0,!1,void 0,this),i("line",{x1:"13",y1:"5",x2:"8",y2:"10"},void 0,!1,void 0,this),i("path",{d:"M6 6 L3.5 6 L3.5 11.5 L10 11.5 L10 9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function tC(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M7 5.5 C 5.5 5.5 5.5 8 4 8 C 5.5 8 5.5 10.5 7 10.5"},void 0,!1,void 0,this),i("path",{d:"M9 5.5 C 10.5 5.5 10.5 8 12 8 C 10.5 8 10.5 10.5 9 10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Eu(e){return i(le,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"5.2",y1:"6",x2:"8",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"8",x2:"10.8",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"8",x2:"8",y2:"11"},void 0,!1,void 0,this),i("circle",{cx:"5.2",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"10.8",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"11",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function rn(e){switch(e){case"markdown":return Qn;case"prompt":return V0;case"response":return G0;case"file":return fa;case"diff":return fa;case"mermaid":return Eu;case"image":return Ru;case"webpage":return gr;case"context":return X0;case"group":return $u;case"status":return J0;case"trace":return K0;case"ledger":return Y0;case"mcp-app":return Q0;case"ext-app":return eC;case"json-render":return tC;case"graph":return Eu;case"board":return Eu;case"html":return gr;default:return Qn}}function nC(e){return new Date(e).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}function oC(){qs()}function Fy(){let e=pi.value;if(e.length===0)return null;let t=un.value,n=or.value;if(!t)return i("button",{type:"button",class:"attention-history-tab",onClick:oC,"aria-label":n>0?`Recent updates — ${n} new`:"Recent updates",title:n>0?`${n} new updates since last viewed`:"Recent updates",children:[i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"9.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"attention-history-tab-label",children:"Updates"},void 0,!1,void 0,this),n>0&&i("span",{class:"attention-history-tab-badge","aria-hidden":"true",children:n>9?"9+":n},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("aside",{class:"attention-history","aria-label":"Recent semantic changes",children:[i("div",{class:"attention-history-header",children:[i("div",{class:"attention-history-header-text",children:[i("span",{class:"attention-history-title",children:"Recent Updates"},void 0,!1,void 0,this),i("span",{class:"attention-history-subtitle",children:"Focus and meaning shifts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"attention-history-close",onClick:Cv,"aria-label":"Collapse changes panel",title:"Collapse",children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"attention-history-list",children:e.map((o)=>i("article",{class:`attention-history-entry attention-tone-${o.tone}`,children:[i("div",{class:"attention-history-meta",children:[i("span",{class:"attention-history-kind",children:o.title},void 0,!1,void 0,this),i("time",{class:"attention-history-time",dateTime:new Date(o.createdAt).toISOString(),children:nC(o.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("p",{class:"attention-history-detail",children:o.detail},void 0,!1,void 0,this)]},o.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function By(){let e=js.value;if(!e)return null;return i("button",{type:"button",class:`attention-toast attention-tone-${e.tone}`,onClick:qs,"aria-label":`${e.title}${e.detail?`: ${e.detail}`:""} — open change history`,children:[i("span",{class:"attention-toast-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"attention-toast-copy",children:[i("span",{class:"attention-toast-title",children:e.title},void 0,!1,void 0,this),e.detail&&i("span",{class:"attention-toast-detail",children:e.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var wi=q(null),Hy=0;function Lt(e,t,n={}){return new Promise((o)=>{wi.value?.resolve(null),Hy+=1,wi.value={seq:Hy,title:e,placeholder:t,initial:n.initial??"",allowEmpty:n.allowEmpty??!1,confirm:n.confirm??"Add",resolve:o}})}function xi(e){let t=wi.value;wi.value=null,t?.resolve(e)}function jy(){let e=wi.value,t=R(null);if(B(()=>{if(!e)return;let o=(r)=>{if(r.key!=="Escape")return;r.preventDefault(),r.stopPropagation(),xi(null)};return window.addEventListener("keydown",o,{capture:!0}),()=>window.removeEventListener("keydown",o,{capture:!0})},[e]),!e)return null;let n=()=>{let o=t.current?.value.trim()??"";xi(o?o:e.allowEmpty?"":null)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>xi(null),children:i("div",{class:"text-prompt",role:"dialog","aria-label":e.title,"data-testid":"text-prompt",onPointerDown:(o)=>o.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:e.title},void 0,!1,void 0,this),i("input",{ref:(o)=>{if(t.current=o,!o)return;if(o.focus(),e.initial)o.select()},class:"text-prompt-input",type:"text",defaultValue:e.initial,placeholder:e.placeholder,onKeyDown:(o)=>{if(o.key==="Enter")o.preventDefault(),o.stopPropagation(),n();else if(o.key==="Escape")o.preventDefault(),o.stopPropagation(),xi(null)}},e.seq,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:()=>xi(null),children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"button",class:"text-prompt-confirm",onClick:n,children:e.confirm},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}async function eo(e,t,n,o){if((await ea({type:t,sourceNodeId:e.id,sourceSurface:"native-node",...n?{payload:n}:{}})).ok)xn("context",o,"",[e.id])}var Ro={padding:"3px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer",flexShrink:0};function rC(e){let t=e.title||e.label||e.key||"Context",n=e.summary?.trim()||"Available in startup context.",o=e.pathDisplay||e.path||"",r=e.category==="profile"?"Operator":e.category==="planning"||e.category==="memory"?"Product":e.category?e.category.charAt(0).toUpperCase()+e.category.slice(1):void 0,s=e.sourceKind==="global"?"Global":"Workspace",a=e.state==="missing"?"Missing":e.state==="stale"?"Stale":e.state==="invalid"?"Invalid":"Loaded";return{title:t,summary:n,pathDisplay:o,category:r,sourceKind:s,status:a,required:e.required===!0}}function sn(e){return typeof e==="string"?e.trim():""}function iC(e){return e.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}function sC(e){let t=sn(e.title),n=sn(e.content),o=iC(sn(e.rendered)),r=n||o,s=sn(e.path);if(!t&&!r&&!s)return null;return{title:t||"Context",summary:r,path:s}}function aC(e){let t=sn(e.data.title)||e.id,n=sn(e.data.content)||sn(e.data.excerpt)||sn(e.data.description)||sn(e.data.pageTitle)||"",o=sn(e.data.path)||sn(e.data.url);return{id:e.id,title:t,summary:n,kind:ut[e.type]??e.type,path:o}}function Zy(e){if(e===null||!Number.isFinite(e)||e<0)return"0";if(e>=1e6)return`${(e/1e6).toFixed(1)}m`;if(e>=1000)return`${(e/1000).toFixed(1)}k`;return`${Math.round(e)}`}function cC(e){if(e>=0.95)return"var(--c-danger)";if(e>=0.85)return"var(--c-warn)";if(e>=0.7)return"var(--c-warn)";return"var(--c-accent)"}function wa({node:e,expanded:t=!1,pinnedNodes:n=[]}){let o=e.data.cards??[],r=e.data.auxTabs??[],s=n.map(aC),a=s.length>0,c=typeof e.data.currentTokens==="number"?e.data.currentTokens:null,l=typeof e.data.tokenLimit==="number"?e.data.tokenLimit:null,u=typeof e.data.utilization==="number"?e.data.utilization:null,p=typeof e.data.messagesLength==="number"?e.data.messagesLength:null,d=u!==null?Math.max(0,Math.min(100,Math.round(u*100))):null,f=cC(u??0),m=!a&&o.length===0&&r.length===0?sC(e.data):null,h=async(v)=>{let x=typeof v.path==="string"?v.path.trim():"";if(!x)return;await Js(x)};return i("div",{style:{display:"flex",flexDirection:"column",gap:t?"10px":"6px",fontSize:t?"14px":"12px",maxWidth:t?"760px":void 0,margin:t?"0 auto":void 0,width:t?"100%":void 0,padding:t?"8px 0":void 0},children:[i("div",{style:{display:"flex",justifyContent:"flex-end"},children:i("button",{type:"button",class:"ax-node-action",title:"Point the agent at this node — sets it as the agent's current AX focus so the agent pulls it into context to work on next (a one-click alternative to manually pinning).",style:Ro,onClick:(v)=>{v.stopPropagation(),eo(e,"ax.focus.set",void 0,"Focus set")},children:"Set focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),l!==null&&l>0&&i("div",{style:{marginBottom:"8px"},children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:"Token Usage"},void 0,!1,void 0,this),i("div",{style:{height:"6px",background:"var(--c-surface-hover)",borderRadius:"3px",overflow:"hidden",marginBottom:"4px"},children:i("div",{style:{height:"100%",width:`${Math.min(100,(u??0)*100)}%`,background:f,borderRadius:"3px",transition:"width 0.3s ease"}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{style:{fontSize:"11px",color:"var(--c-muted)"},children:[d,"% — ",Zy(c)," / ",Zy(l)," tokens",p!==null&&i(pe,{children:[" · ",p," messages"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:["Pinned Context (",s.length,")"]},void 0,!0,void 0,this),s.map((v)=>i("div",{style:{padding:"6px 8px",background:"var(--c-surface-subtle)",borderRadius:"6px",marginBottom:"4px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"2px"},children:v.title},void 0,!1,void 0,this),v.summary&&i("div",{style:{color:"var(--c-muted)",fontSize:"10px",lineHeight:1.45,marginBottom:"4px",whiteSpace:"pre-wrap"},children:v.summary},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"4px",flexWrap:"wrap",marginTop:"4px"},children:i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:v.kind},void 0,!1,void 0,this)},void 0,!1,void 0,this),v.path&&i("div",{style:{marginTop:"6px"},children:[i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all",marginBottom:"6px"},children:v.path},void 0,!1,void 0,this),v.path.startsWith("/")&&i("button",{type:"button",onClick:()=>void Js(v.path),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},v.id,!0,void 0,this))]},void 0,!0,void 0,this),!a&&o.length>0&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:["Context (",o.length,")"]},void 0,!0,void 0,this),o.map((v)=>{let x=rC(v);return i("div",{style:{padding:"6px 8px",background:"var(--c-surface-subtle)",borderRadius:"6px",marginBottom:"4px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"2px"},children:x.title},void 0,!1,void 0,this),i("div",{style:{color:"var(--c-muted)",fontSize:"10px",lineHeight:1.45,marginBottom:"4px"},children:x.summary},void 0,!1,void 0,this),x.pathDisplay&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all"},children:x.pathDisplay},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"4px",flexWrap:"wrap",marginTop:"4px"},children:[i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-accent-10)",color:"var(--c-accent)",borderRadius:"3px",display:"inline-block"},children:x.status},void 0,!1,void 0,this),x.category&&i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:x.category},void 0,!1,void 0,this),i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:x.sourceKind},void 0,!1,void 0,this),x.required&&i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-warn-12)",color:"var(--c-warn-alt)",borderRadius:"3px",display:"inline-block"},children:"Required"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v.path&&i("div",{style:{marginTop:"6px"},children:i("button",{type:"button",onClick:()=>void h(v),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},v.key??x.pathDisplay??x.title,!0,void 0,this)})]},void 0,!0,void 0,this),!a&&r.length>0&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px",marginTop:o.length>0?"8px":0},children:["References (",r.length,")"]},void 0,!0,void 0,this),r.map((v)=>i("a",{href:v.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",padding:"4px 8px",color:"var(--c-accent)",fontSize:"11px",textDecoration:"none",borderRadius:"4px",marginBottom:"2px",wordBreak:"break-all"},children:[v.url,v.reason&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",marginLeft:"6px"},children:["(",v.reason,")"]},void 0,!0,void 0,this)]},v.id,!0,void 0,this))]},void 0,!0,void 0,this),m&&i("div",{style:{padding:"8px 10px",background:"var(--c-surface-subtle)",borderRadius:"6px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"4px"},children:m.title},void 0,!1,void 0,this),m.summary&&i("div",{style:{color:"var(--c-text-soft)",fontSize:"11px",lineHeight:1.5,whiteSpace:"pre-wrap"},children:m.summary},void 0,!1,void 0,this),m.path&&i("div",{style:{marginTop:"6px"},children:[i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all",marginBottom:"6px"},children:m.path},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>void Js(m.path),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!a&&!m&&o.length===0&&r.length===0&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic"},children:"No context loaded"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Uy(e){return e.replace(/^[ab]\//,"")}function lC(e,t){if(t&&t!=="/dev/null")return Uy(t);if(e&&e!=="/dev/null")return Uy(e);return null}function uC(e){if(!e.trim())return[];let t=e.split(`
|
|
89
|
-
`);if(t.length>0&&t[t.length-1]==="")t.pop();let n=[],o=null,r=!1,s=(a)=>{let c={path:a,lines:[]};return r=!1,n.push(c),c};for(let a=0;a<t.length;a++){let c=t[a]??"",l=c.match(/^diff --git a\/(.+?) b\/(.+)$/);if(l){o=s(l[2]??null);continue}let u=t[a+1]??"";if(c.startsWith("--- ")&&u.startsWith("+++ ")){let d=
|
|
71
|
+
`)}`:"Interactive surface. No static text available; inspect the rendered surface."}function g0(e,t){let n=[],o=typeof e.url==="string"?e.url:"",r=typeof e.pageTitle==="string"?e.pageTitle:"",s=typeof e.description==="string"?e.description:"",a=typeof e.status==="string"?e.status:"",c=typeof e.statusCode==="number"?e.statusCode:null,l=typeof e.error==="string"?e.error:"",u=typeof e.content==="string"?e.content:typeof e.excerpt==="string"?e.excerpt:"";if(o)n.push(`URL: ${o}`);if(r)n.push(`Title: ${r}`);if(s)n.push(`Description: ${s}`);if(a||c!==null)n.push(`Fetch: ${a||"unknown"}${c!==null?` (${c})`:""}`);if(l)n.push(`Error: ${l}`);let p=n.join(`
|
|
72
|
+
`),d=Math.max(0,t-p.length-(p?2:0)),m=d>0?tt(u,d):"";if(p&&m)return`${p}
|
|
73
|
+
|
|
74
|
+
${m}`;if(p)return tt(p,t);return tt(u,t)}function v0(e){if(e===null||e===void 0)return"";if(typeof e!=="object"||Array.isArray(e))return"";let t=e.elements;if(Array.isArray(t)){let n=t.map((o)=>pt(Co(o),["text","label"])).filter(Boolean);return`Diagram elements: ${t.length}
|
|
75
|
+
${n.length?`Diagram labels: ${n.join("; ")}`:"No diagram description available."}`}return"No app content description available."}function y0(e,t){let n=[],o=typeof e.title==="string"?e.title:"",r=typeof e.mode==="string"?e.mode:"",s=typeof e.hostMode==="string"?e.hostMode:"",a=typeof e.serverName==="string"?e.serverName:"",c=typeof e.toolName==="string"?e.toolName:"",l=typeof e.resourceUri==="string"?e.resourceUri:"",u=typeof e.path==="string"?e.path:"",p=typeof e.url==="string"?e.url:"",d=typeof e.sessionStatus==="string"?e.sessionStatus:"",m=v0(e.toolInput);if(o)n.push(`App: ${o}`);if(r||s)n.push(`Mode: ${[r,s].filter(Boolean).join(" / ")}`);if(a||c)n.push(`Source: ${[a,c].filter(Boolean).join(" / ")}`);if(l)n.push(`Resource: ${l}`);if(u)n.push(`Path: ${u}`);if(p)n.push(`URL: ${p}`);if(d)n.push(`Session: ${d}`);if(m)n.push(m);if(n.length===0)return"MCP App node";return tt(n.join(`
|
|
76
|
+
`),t)}function b0(e,t){let n=[],o=typeof e.content==="string"?e.content:"",r=typeof e.title==="string"?e.title:"",s=typeof e.path==="string"?e.path:"",a=typeof e.url==="string"?e.url:"",c=typeof e.projectPath==="string"?e.projectPath:"",l=typeof e.artifactBytes==="number"?e.artifactBytes:null,u=typeof e.sourceFileCount==="number"?e.sourceFileCount:null,p=Array.isArray(e.sourceFiles)?e.sourceFiles.filter((m)=>typeof m==="string"):[],d=Array.isArray(e.deps)?e.deps.filter((m)=>typeof m==="string"):[];if(o)n.push(o);if(!o&&r)n.push(`Web artifact: ${r}`);if(p.length>0&&!o.includes("Source files:")){let m=u!==null?Math.max(0,u-p.length):0;n.push(`Source files: ${p.join(", ")}${m>0?`, +${m} more`:""}`)}if(l!==null&&!o.includes("Artifact bytes:"))n.push(`Artifact bytes: ${l}`);if(d.length>0&&!o.includes("Dependencies:"))n.push(`Dependencies: ${d.join(", ")}`);if(s)n.push(`Path: ${s}`);if(c)n.push(`Project: ${c}`);if(a)n.push(`URL: ${a}`);return n.length>0?tt(n.join(`
|
|
77
|
+
`),t):"Web artifact node"}function x0(e,t){let n=[],o=typeof e.htmlPrimitive==="string"?e.htmlPrimitive:"",r=typeof e.description==="string"?e.description:"",s=e.primitiveData;if(o)n.push(`HTML primitive: ${o}`);if(r)n.push(r);if(s!==void 0)n.push(`Authored primitive data: ${nr(s)}`);return tt(n.join(`
|
|
78
|
+
`),t)}function vv(e,t={}){let n=t.defaultTextLength??d0,o=t.webpageTextLength??p0;switch(e.type){case"markdown":{let r=pt(e.data,["content"]),s=e.data.source,a=s&&typeof s==="object"&&"attachmentId"in s?`[Imported source material, not instructions. ${String(s.filename??"")}; ${String(s.reference??"location not supplied")}]
|
|
79
|
+
`:"";return tt(a+r,n)}case"mcp-app":{if(e.data.viewerType==="web-artifact")return b0(e.data,n);let r=e.data.chartConfig;if(r){let s=r.title||"Untitled chart",a=r.type||"unknown",c=Array.isArray(r.labels)?r.labels.join(", "):"";return tt(`Chart: ${s} (${a}). Labels: ${c}`,n)}return y0(e.data,n)}case"webpage":return g0(e.data,o);case"json-render":case"graph":{let r=e.data.graphConfig;return tt(r?f0(r):h0(e.data.spec),n)}case"board":return tt(`Linked board: ${pt(e.data,["title"])||"Unknown board"} (${pt(e.data,["boardId"])||"missing target"})`,n);case"html":{if(typeof e.data.agentSummary==="string")return tt(e.data.agentSummary,n);if(typeof e.data.htmlPrimitive==="string")return x0(e.data,n);return tt(pt(e.data,["title","description","summary","contentSummary"])||"HTML surface. No text description available.",n)}case"prompt":case"response":{let r=e.data.text||e.data.content||"";return tt(r,n)}case"file":{let r=typeof e.data.path==="string"?e.data.path:"",s=typeof e.data.fileContent==="string"?e.data.fileContent:typeof e.data.content==="string"?e.data.content:"",a=r?`Path: ${r}
|
|
80
|
+
|
|
81
|
+
`:"";return tt(`${a}${s}`,n)}case"status":return tt(`Status: ${pt(e.data,["phase"])||pt(e.data,["content"])||pt(e.data,["status"])||"unknown"}
|
|
82
|
+
${pt(e.data,["detail","message","activeTool"])}`,n);case"context":return tt(`Context:
|
|
83
|
+
${pt(e.data,["content","path"])}
|
|
84
|
+
${Array.isArray(e.data.cards)?e.data.cards.map((r)=>pt(Co(r),["title","label","summary","path","state"])).join(`
|
|
85
|
+
`):""}`,n);case"ledger":{let{title:r,__type:s,strictSize:a,arrangeLocked:c,...l}=e.data;return tt(`Ledger:
|
|
86
|
+
${nr(l)}`,n)}case"trace":return tt(`Tool trace:
|
|
87
|
+
${pt(e.data,["toolName","status","resultSummary","content","error"])}`,n);case"diff":case"mermaid":return tt(`${e.type==="diff"?"Diff":"Mermaid diagram source"}:
|
|
88
|
+
${pt(e.data,["content"])}`,n);case"image":return tt(pt(e.data,["alt","caption","description"])||"No image description available; inspect the image.",n);case"group":return tt(`Group: ${pt(e.data,["title"])||"Untitled"}. ${Array.isArray(e.data.children)?e.data.children.length:0} cards.`,n)}}function w0(e,t){let n=e.position.x+e.size.width/2,o=e.position.y+e.size.height/2,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2;return Math.sqrt((n-r)**2+(o-s)**2)}function _0(e,t){let n=e.position.x+e.size.width,o=e.position.y+e.size.height,r=t.position.x+t.size.width,s=t.position.y+t.size.height,a=Math.max(0,Math.max(e.position.x,t.position.x)-Math.min(n,r)),c=Math.max(0,Math.max(e.position.y,t.position.y)-Math.min(o,s));return Math.sqrt(a**2+c**2)}function k0(e){let t=[...e],n=100;return t.sort((o,r)=>{let s=Math.floor(o.position.y/100),a=Math.floor(r.position.y/100);if(s!==a)return s-a;return o.position.x-r.position.x}),t}function S0(e){let t=e.find((r)=>r.data.title&&typeof r.data.title==="string");if(t&&e.length<=3)return e.filter((s)=>s.data.title).map((s)=>s.data.title).slice(0,3).join(", ");let n={};for(let r of e)n[r.type]=(n[r.type]??0)+1;let o=Object.entries(n).map(([r,s])=>s===1?r:`${s} ${r}`);if(t)return`${t.data.title} + ${o.join(", ")}`;return o.join(", ")}function C0(e,t){return e.x<=t.x+t.width&&e.x+e.width>=t.x&&e.y<=t.y+t.height&&e.y+e.height>=t.y}function T0(e,t){let n=t.filter((r)=>C0(e.bounds,{x:r.position.x,y:r.position.y,width:r.size.width,height:r.size.height})),o=n.map((r)=>typeof r.data.title==="string"&&r.data.title.length>0?r.data.title:r.id);return{id:e.id,label:e.label??e.text??null,bounds:e.bounds,targetNodeIds:n.map((r)=>r.id),targetNodeTitles:o,target:o.length>0?o.join(", "):"empty canvas region"}}function I0(e,t=200){if(e.length===0)return[];let n=new Map,o=(l)=>{while(n.get(l)!==l){let u=n.get(l);n.set(l,n.get(u)),l=u}return l},r=(l,u)=>{let p=o(l),d=o(u);if(p!==d)n.set(p,d)};for(let l of e)n.set(l.id,l.id);for(let l=0;l<e.length;l++)for(let u=l+1;u<e.length;u++)if(_0(e[l],e[u])<=t)r(e[l].id,e[u].id);let s=new Map;for(let l of e){let u=o(l.id);if(!s.has(u))s.set(u,[]);s.get(u).push(l)}let a=[],c=0;for(let[,l]of s){if(l.length<2)continue;let u=l.map((g)=>g.position.x),p=l.map((g)=>g.position.y),d=l.map((g)=>g.position.x+g.size.width),m=l.map((g)=>g.position.y+g.size.height),f=Math.min(...u),h=Math.min(...p),v=Math.max(...d),x=Math.max(...m);a.push({id:`cluster-${c++}`,nodeIds:l.map((g)=>g.id),label:S0(l),centroid:{x:Math.round((f+v)/2),y:Math.round((h+x)/2)},bounds:{x:f,y:h,width:v-f,height:x-h}})}return a.sort((l,u)=>{let p=Math.floor(l.centroid.y/200),d=Math.floor(u.centroid.y/200);if(p!==d)return p-d;return l.centroid.x-u.centroid.x}),a}function E0(e,t,n=5,o=600){let r=e.filter((a)=>t.has(a.id)),s=e.filter((a)=>!t.has(a.id));return r.map((a)=>{let c=s.map((l)=>({node:l,distance:w0(a,l)})).filter((l)=>l.distance<=o).sort((l,u)=>l.distance-u.distance).slice(0,n);return{pinnedNodeId:a.id,pinnedNodeTitle:a.data.title??null,neighbors:c.map((l)=>({id:l.node.id,type:l.node.type,title:l.node.data.title??null,distance:Math.round(l.distance)}))}})}function mi(e,t,n,o=[]){let r=I0(e),s=new Map;for(let u of r)for(let p of u.nodeIds)s.set(p,u.id);let c=k0(e).map((u,p)=>({id:u.id,type:u.type,title:u.data.title??null,content:vv(u,{defaultTextLength:320,webpageTextLength:640})||null,clusterId:s.get(u.id)??null,readingOrder:p})),l=E0(e,n);return{totalNodes:e.length,clusters:r,nodesInReadingOrder:c,pinnedNeighborhoods:l,annotations:o.map((u)=>T0(u,e))}}function or(e){if(!e)return null;let t=e.data.title;return typeof t==="string"&&t.trim().length>0?t.trim():null}function Zs(e,t){return{id:e?.id??t,title:or(e),nodeType:e?.type??"markdown"}}function yv(e,t){return{id:e.id,edgeType:e.type,fromId:e.from,toId:e.to,fromTitle:or(t.get(e.from)),toTitle:or(t.get(e.to))}}function Us(e){return new Map(e.map((t)=>[t.id,t]))}function bv(e){return new Map(e.map((t)=>[t.id,t]))}function Yt(e){return Array.from(e).sort((t,n)=>t.localeCompare(n))}function cu(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function lu(e){if(!e||e.type!=="group")return[];let t=e.data.children;if(!Array.isArray(t))return[];return t.filter((n)=>typeof n==="string").sort((n,o)=>n.localeCompare(o))}function xv(e){let t=new Map;for(let n of e.clusters){let o=[...n.nodeIds].sort((r,s)=>r.localeCompare(s));for(let r of o)t.set(r,o.filter((s)=>s!==r))}return t}function wv(e){let t=new Map;for(let n of e.pinnedNeighborhoods)t.set(n.pinnedNodeId,n.neighbors.map((o)=>o.id).sort((o,r)=>o.localeCompare(r)));return t}function A0(e,t){let n=Yt(Array.from(t).filter((r)=>!e.has(r))),o=Yt(Array.from(e).filter((r)=>!t.has(r)));return{added:n,removed:o}}function _v(e){let t=e&&typeof e==="object"?e:{};return{timestamp:typeof t.timestamp==="string"?t.timestamp:void 0,sessionId:typeof t.sessionId==="string"?t.sessionId:void 0}}function z0(e,t,n){if(!e||!n)return{layout:e,pinnedNodeIds:[],primaryFocusNodeIds:[],secondaryFocusNodeIds:[],regions:[],spatial:n};let o=Us(e.nodes),r=Yt(t).filter((l)=>o.has(l)),s=new Set(r),a=new Set,c=[];for(let l of n.pinnedNeighborhoods){if(!s.has(l.pinnedNodeId))continue;let u=Yt([l.pinnedNodeId,...l.neighbors.map((p)=>p.id)]).filter((p,d,m)=>m.indexOf(p)===d&&o.has(p));for(let p of u)if(!s.has(p))a.add(p);c.push({id:`region-${l.pinnedNodeId}`,primaryNodeId:l.pinnedNodeId,nodeIds:u})}if(c.length===0&&r.length>0)for(let l of r)c.push({id:`region-${l}`,primaryNodeId:l,nodeIds:[l]});return{layout:e,pinnedNodeIds:r,primaryFocusNodeIds:r,secondaryFocusNodeIds:Yt(a),regions:c,spatial:n}}class qs{currentLayout=null;currentPins=new Set;previousSpatial=null;setInitialPins(e){this.currentPins=new Set(e)}getAttentionSnapshot(){return z0(this.currentLayout,this.currentPins,this.previousSpatial)}handleMessage(e){if(e.event==="context-pins-changed")return this.handleContextPinsChanged(e.data);if(e.event==="canvas-layout-update")return this.handleLayoutUpdate(e.data);return[]}handleContextPinsChanged(e){let t=e&&typeof e==="object"?e:{},n=Array.isArray(t.nodeIds)?t.nodeIds.filter((u)=>typeof u==="string"):[],o=_v(e),r=new Set(n),{added:s,removed:a}=A0(this.currentPins,r);if(this.currentPins=r,!this.currentLayout)return[];let c=Us(this.currentLayout.nodes),l={added:s.map((u)=>Zs(c.get(u),u)),removed:a.map((u)=>Zs(c.get(u),u))};if(this.previousSpatial=mi(this.currentLayout.nodes,this.currentLayout.edges,this.currentPins,this.currentLayout.annotations??[]),l.added.length===0&&l.removed.length===0)return[];return[{type:"context-pin",...o,...l}]}handleLayoutUpdate(e){let t=e&&typeof e==="object"?e:{},n=t.layout&&typeof t.layout==="object"?t.layout:null;if(!n)return[];let o=_v(e);if(!this.currentLayout)return this.currentLayout=n,this.previousSpatial=mi(n.nodes,n.edges,this.currentPins,n.annotations??[]),[];let r=this.currentLayout,s=this.previousSpatial??mi(r.nodes,r.edges,this.currentPins,r.annotations??[]),a=mi(n.nodes,n.edges,this.currentPins,n.annotations??[]),c=[],l=Us(r.nodes),u=Us(n.nodes),p=bv(r.edges),d=bv(n.edges),m=Yt(Array.from(d.keys()).filter((g)=>!p.has(g))).map((g)=>d.get(g)).filter((g)=>g!==void 0);if(m.length>0)c.push({type:"connect",...o,edges:m.map((g)=>yv(g,u))});let f=Yt(Array.from(l.keys()).filter((g)=>!u.has(g))),h=Yt(Array.from(p.keys()).filter((g)=>!d.has(g)));if(f.length>0||h.length>0)c.push({type:"remove",...o,nodes:f.map((g)=>Zs(l.get(g),g)),edges:h.map((g)=>p.get(g)).filter((g)=>g!==void 0).map((g)=>yv(g,l))});let v=this.buildGroupEvent(l,u,o);if(v)c.push(v);let x=this.buildMoveEndEvent(r,n,l,u,s,a,o);if(x)c.push(x);return this.currentLayout=n,this.previousSpatial=a,c}buildGroupEvent(e,t,n){let o=Yt(Array.from(e.values()).filter((c)=>c.type==="group").map((c)=>c.id)),r=Yt(Array.from(t.values()).filter((c)=>c.type==="group").map((c)=>c.id)),s=r.filter((c)=>!o.includes(c)).map((c)=>{let l=t.get(c),u=lu(l);return{id:c,title:or(l),childCount:u.length}}),a=[];for(let c of r.filter((l)=>o.includes(l))){let l=lu(e.get(c)),u=lu(t.get(c));if(cu(l,u))continue;a.push({id:c,title:or(t.get(c)),addedChildIds:u.filter((p)=>!l.includes(p)),removedChildIds:l.filter((p)=>!u.includes(p)),childCount:u.length})}if(s.length===0&&a.length===0)return null;return{type:"group",...n,created:s,updated:a}}buildMoveEndEvent(e,t,n,o,r,s,a){let c=Yt(Array.from(o.keys()).filter((x)=>{let g=n.get(x),y=o.get(x);if(!g||!y)return!1;return g.position.x!==y.position.x||g.position.y!==y.position.y}));if(c.length===0)return null;let l=xv(r),u=xv(s),p=wv(r),d=wv(s),m=new Map,f=(x,g)=>{let y=m.get(x)??new Set;y.add(g),m.set(x,y)};for(let x of c){let g=l.get(x)??[],y=u.get(x)??[];if(!cu(g,y))if(g.length===0&&y.length>0)f(x,"joined cluster");else if(g.length>0&&y.length===0)f(x,"left cluster");else f(x,"cluster changed")}let h=new Set([...p.keys(),...d.keys()]);for(let x of h){let g=p.get(x)??[],y=d.get(x)??[];if(cu(g,y))continue;let E=or(o.get(x)??n.get(x))??x,D=y.filter((b)=>!g.includes(b)),N=g.filter((b)=>!y.includes(b));for(let b of D)if(c.includes(b))f(b,`entered pinned neighborhood of "${E}"`);for(let b of N)if(c.includes(b))f(b,`left pinned neighborhood of "${E}"`);if(c.includes(x))f(x,"pinned neighborhood changed")}let v=c.filter((x)=>(m.get(x)?.size??0)>0).map((x)=>{let g=o.get(x);return{...Zs(g,x),reasons:Array.from(m.get(x)??[]).sort((y,E)=>y.localeCompare(E))}});if(v.length===0)return null;return{type:"move-end",...a,nodes:v}}}var Ws=U(null),fi=U([]),ir=U(new Set),sr=U(new Set),Vs=U([]),Gs=U(new Set),dn=U(!1),rr=U(0);function kv(){Ws.value=null,fi.value=[],ir.value=new Set,sr.value=new Set,Vs.value=[],Gs.value=new Set,dn.value=!1,rr.value=0}function Xs(){dn.value=!0,rr.value=0}function Sv(){dn.value=!1}function Cv(e,t,n){ir.value=new Set(e),sr.value=new Set(t),Vs.value=n}function Js(e){Ws.value=e}function uu(e,t=6){if(fi.value=[e,...fi.value].slice(0,t),!dn.value)rr.value=Math.min(99,rr.value+1)}function Ks(e){Gs.value=new Set(e)}var fu=new qs,ar=[],hi=null,cr=null,du="",pu=0;function Iv(e,t){return globalThis.setTimeout(e,t)}function mu(e){if(e===null)return;globalThis.clearTimeout(e)}function P0(e){if(typeof globalThis.requestAnimationFrame==="function"){globalThis.requestAnimationFrame(()=>e());return}e()}function Wn(e,t){return e&&e.trim().length>0?e.trim():t}function wn(e,t=3){if(e.length===0)return"";if(e.length<=t)return e.join(", ");return`${e.slice(0,t).join(", ")} +${e.length-t}`}function N0(e){return Array.from(new Set(Array.from(e).filter((t)=>t.length>0)))}function Qt(e,t,n,o,r=Date.now()){return{id:`${e}-${r}-${Math.random().toString(36).slice(2,8)}`,tone:e,title:t,detail:n,nodeIds:N0(o),createdAt:r}}function Tv(e){if(e==="joined cluster")return"joined a nearby cluster";if(e==="left cluster")return"moved away from its cluster";if(e==="cluster changed")return"shifted into a different cluster";if(e==="pinned neighborhood changed")return"changed the local focus field";let t=/^entered pinned neighborhood of "(.+)"$/.exec(e);if(t)return`moved into focus around ${t[1]}`;let n=/^left pinned neighborhood of "(.+)"$/.exec(e);if(n)return`moved out of focus around ${n[1]}`;return e}function R0(e){let t=e.added.map((r)=>Wn(r.title,r.id)),n=e.removed.map((r)=>Wn(r.title,r.id));if(t.length===0&&n.length===0)return null;let o="";if(t.length>0&&n.length===0)o=`Now in focus: ${wn(t)}`;else if(n.length>0&&t.length===0)o=`Removed from focus: ${wn(n)}`;else{let r=[];if(t.length>0)r.push(`${wn(t)} added`);if(n.length>0)r.push(`${wn(n)} removed`);o=r.join(" · ")}return Qt("context","Context updated",o,[...e.added.map((r)=>r.id),...e.removed.map((r)=>r.id)],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function $0(e){if(e.edges.length===0)return null;if(e.edges.length===1){let t=e.edges[0];return Qt("relationship","Relationship added",`${Wn(t.fromTitle,t.fromId)} linked to ${Wn(t.toTitle,t.toId)}`,[t.fromId,t.toId],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}return Qt("relationship","Relationships added",`${e.edges.length} connections changed the board structure`,e.edges.flatMap((t)=>[t.fromId,t.toId]),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function M0(e){if(e.nodes.length===0&&e.edges.length===0)return null;let t=e.nodes.map((o)=>Wn(o.title,o.id)),n=[];if(t.length>0)n.push(wn(t));if(e.edges.length>0)n.push(`${e.edges.length} relationship${e.edges.length===1?"":"s"}`);return Qt("remove","Items removed",n.join(" · "),[...e.nodes.map((o)=>o.id),...e.edges.flatMap((o)=>[o.fromId,o.toId])],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function L0(e){if(e.created.length>0){let t=e.created.map((n)=>Wn(n.title,n.id));return Qt("group",e.created.length===1?"Group created":"Groups created",e.created.length===1?`${t[0]} now frames ${e.created[0].childCount} items`:wn(t),e.created.map((n)=>n.id),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}if(e.updated.length>0){let t=e.updated.map((n)=>Wn(n.title,n.id));return Qt("group",e.updated.length===1?"Group updated":"Groups updated",e.updated.length===1?`${t[0]} now holds ${e.updated[0].childCount} items`:wn(t),e.updated.map((n)=>n.id),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}return null}function O0(e){if(e.nodes.length===0)return null;let t=e.nodes.flatMap((s)=>s.reasons),n=e.nodes.map((s)=>Wn(s.title,s.id)),o=e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now();if(t.some((s)=>s.includes("pinned neighborhood"))){if(e.nodes.length===1)return Qt("neighborhood","Neighborhood changed",`${n[0]} ${Tv(e.nodes[0].reasons[0])}`,e.nodes.map((s)=>s.id),o);return Qt("neighborhood","Neighborhood changed",wn(n),e.nodes.map((s)=>s.id),o)}let r=t.filter((s)=>s.includes("cluster"));if(r.length>0){let s=r.every((a)=>a==="joined cluster");if(e.nodes.length===1)return Qt("cluster",s?"Cluster formed":"Cluster changed",`${n[0]} ${Tv(e.nodes[0].reasons[0])}`,e.nodes.map((a)=>a.id),o);return Qt("cluster",s?"Cluster formed":"Cluster changed",wn(n),e.nodes.map((a)=>a.id),o)}return null}function D0(e){switch(e.type){case"context-pin":return R0(e);case"connect":return $0(e);case"remove":return M0(e);case"group":return L0(e);case"move-end":return O0(e)}}function F0(){let e=fu.getAttentionSnapshot();Cv(e.primaryFocusNodeIds,e.secondaryFocusNodeIds,e.regions)}function Ev(){if(hi!==null)return;let e=ar.shift()??null;if(!e){Js(null);return}Js(e);let t=Math.max(1800,Math.min(2800,1600+e.detail.length*18));hi=Iv(()=>{hi=null,Js(null),Ev()},t)}function Av(e){if(ar.push(e),ar.length>3)ar.splice(0,ar.length-3);Ev()}function pn(e,t,n="",o=[]){let r=Qt(e,t,n,o);uu(r),Av(r)}function B0(e){if(mu(cr),cr=null,Ks([]),e.length===0)return;P0(()=>{Ks(e),cr=Iv(()=>{cr=null,Ks([])},900)})}function H0(e){let t=`${e.tone}:${e.title}:${e.detail}`,n=e.createdAt;if(t===du&&n-pu<1200)return!0;return du=t,pu=n,!1}function Ys(){mu(hi),mu(cr),hi=null,cr=null,ar=[],du="",pu=0,fu=new qs,kv()}function hu(e){let t=fu.handleMessage(e).map((n)=>D0(n)).filter((n)=>n!==null);F0();for(let n of t){if(H0(n))continue;uu(n),Av(n),B0(n.nodeIds)}}function gu(e,t){console.error(`[intent-bridge] ${e} failed`,t)}var Qs=(()=>{try{let e=new URLSearchParams(window.location.search).get("agent")?.trim();return e?e.slice(0,64):null}catch{return null}})();function vu(e){let t={...e?.headers};if(Qs)t["x-pmx-source"]=Qs;else{t["X-PMX-Workbench"]="1";let n=window.__PMX_WORKBENCH_TOKEN;if(typeof n==="string")t["X-PMX-Workbench-Token"]=n}return{...e,headers:t}}function yu(e,t,n){if(e.ok||(t?.method??"GET").toUpperCase()==="GET")return;let o=n!==null&&typeof n==="object"&&"error"in n&&typeof n.error==="string"?n.error:"";pn("remove","Change refused",o||`The server answered ${e.status}.`)}async function bu(e){try{return await e.json()}catch{return null}}async function Y(e,t,n,o){try{let r=await fetch(t,vu(o)),s=await bu(r);if(yu(r,o,s),s===null)throw Error(`${r.status} response had no JSON body`);return s}catch(r){return gu(e,r),n}}async function Lt(e,t,n){try{let o=await fetch(t,vu(n));if(!o.ok)yu(o,n,await bu(o));return{ok:o.ok}}catch(o){return gu(e,o),{ok:!1}}}async function en(e,t,n){try{let o=await fetch(t,vu(n));if(!o.ok)yu(o,n,await bu(o))}catch(o){gu(e,o)}}async function zv(e,t={}){return Y("sendIntent","/api/workbench/intent",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:e,payload:t})})}async function Io(e){let n=`Veto: do not ${e.label?.trim()||`${e.kind} intent`}${e.reason?` — ${e.reason}`:""}.`;if((await Y("vetoGhostIntent",`/api/canvas/ax/intent/${encodeURIComponent(e.id)}`,{ok:!1,cleared:!1},{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({vetoed:!0})})).cleared!==!0)return!1;return await en("vetoGhostSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:n,source:"browser"})}),!0}async function _n(e){return(await Y("renderMarkdown","/api/render",{},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({markdown:e})})).html??""}async function gi(e){return Y("fetchFile",`/api/file?path=${encodeURIComponent(e)}`,{content:""})}async function Pv(e,t){return Y("saveFile","/api/file/save",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,content:t})})}async function ea(e){return Lt("openWorkbenchFile","/api/workbench/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})}async function Nv(){return Y("fetchCanvasState","/api/canvas/state?includeBlobs=true",{})}async function ta(e){return Y("saveCanvasTheme","/api/canvas/theme",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({theme:e})})}async function Rv(){return[]}async function vi(e,t,n,o,r){if(!e.trim())return{ok:!1,error:"Prompt text is required"};return Y("submitCanvasPrompt","/api/canvas/prompt",{ok:!1,error:"Network error"},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e,...t?{position:t}:{},...n?{parentNodeId:n}:{},...o&&o.length>0?{contextNodeIds:o}:{},...r?{threadNodeId:r}:{}})})}async function $v(e,t){return vi(t,void 0,void 0,void 0,e)}async function na(e,t={}){await en("pushCanvasUpdate","/api/canvas/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:e,...t.recordHistory===!1?{recordHistory:!1}:{}})})}async function Eo(e,t,n,o){let r=To.value,s=await Y("createEdgeFromClient","/api/canvas/edge",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:e,to:t,type:n,label:o})});if(r===To.value&&O.value.has(e)&&O.value.has(t)){if(s.ok){let{ok:a,...c}=s;dr(c)}else if(!s.error)pn("remove","Connection not added","Could not reach the server. Try again.")}return s}async function tn(e){return Y("createNodeFromClient","/api/canvas/node",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function mt(e,t){return Y("updateNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}`,{ok:!1},{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function oa(e,t){return Y("refreshWebpageNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}/refresh`,{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{url:t}:{})})}async function Vn(e){return Y("removeNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}`,{ok:!1},{method:"DELETE"})}async function Mv(){return Y("fetchAxSurfaceState","/api/canvas/ax/surface-snapshot",null)}async function Lv(){return Y("fetchAgentPresence","/api/canvas/ax/presence",null)}async function Ov(e,t){return Y("openNodeInSystemBrowserRequest","/api/canvas/open-external",{ok:!1,opened:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodeId:e,url:t})})}async function ra(e){return Y("submitAxInteractionFromClient","/api/canvas/ax/interaction",{ok:!1,code:"request-failed",error:"Request failed"},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceSurface:"native-node",...e,source:"browser"})})}async function Dv(e,t={}){return Y("updateViewportFromClient","/api/canvas/viewport",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,...Fv(),...t.recordHistory===!1?{recordHistory:!1}:{}})})}function Fv(){if(typeof window>"u")return{};let e=it(),t=Math.round(e.width),n=Math.round(e.height);if(!t||!n)return{};return{clientWidth:t,clientHeight:n}}async function yi(){let e=Fv();if(!("clientWidth"in e))return;await en("reportClientViewportSize","/api/canvas/viewport",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,recordHistory:!1})})}async function lr(e){return Y("createGroupFromClient","/api/canvas/group",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function xu(e,t,n){return Y("addToGroupFromClient","/api/canvas/group/add",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({groupId:e,childIds:t,...n?{childLayout:n}:{}})})}async function ia(e,t){return mt(e,{children:t})}async function ur(e){return Y("ungroupFromClient","/api/canvas/group/ungroup",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({groupId:e})})}async function Bv(){return Y("listSnapshots","/api/canvas/snapshots?all=true",[])}async function Hv(e){return Y("saveSnapshot","/api/canvas/snapshots",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})}async function jv(e){return Y("restoreSnapshot",`/api/canvas/snapshots/${e}`,{ok:!1},{method:"POST"})}async function Zv(e){return Y("deleteSnapshot",`/api/canvas/snapshots/${e}`,{ok:!1},{method:"DELETE"})}async function sa(e,t){return Y("updateEdgeFromClient",`/api/canvas/edge/${encodeURIComponent(e)}`,{ok:!1},{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function aa(e){return Y("removeEdgeFromClient","/api/canvas/edge",{ok:!1},{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({edge_id:e})})}function Gv(e,t){console.error(`[canvas-store] ${e} failed`,t)}var K=U({x:0,y:0,scale:1}),O=U(new Map),Fe=U(new Map),pr=U(new Map),Te=U(null),fn=U(null),Ot=U("connecting"),zo=U(0),Po=U(0),No=U(0),kn=U(""),mr=U(!1),nt=U("dark"),Et=U(!1),on=U(null),We=U(null),nn=U(null),wt=null,Ao,Uv=100,j0=2500,xi=U(null),To=U(0),Be=U(null),Sn=U(null),be=U(new Set),Ae=U(new Set),At=U("select"),wi=U(!1);function fr(){return At.value==="pan"||wi.value}function Xv(e,t){if(!e)return new Set;let n=new Set;for(let o of t.values()){if(o.from===e)n.add(o.to);if(o.to===e)n.add(o.from)}return n}var Jv=De(()=>Xv(Te.value,Fe.value));function qv(e,t){let n=new Set;for(let o of e)if(t.has(o))n.add(o);return n}function Wv(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function ku(e){let t=new Set(be.value);if(t.has(e))t.delete(e);else t.add(e);be.value=t}function Kv(e){be.value=new Set(e)}function _t(){if(fn.value=null,be.value.size===0)return;be.value=new Set}function Yv(){if(wt!==null)clearTimeout(wt),wt=null;Mt(()=>{To.value+=1,Te.value=null,We.value=null,nn.value=null,Ao=void 0,be.value=new Set,fn.value=null,xi.value=null,Be.value=null,Sn.value=null,mn.value=null,Ae.value=new Set}),ca=!1}var mn=U(null),ca=!1;function Qv(){ca=!0,mn.value=null}function ey(){ca=!1,mn.value=null}function wu(e){return{x:e.position.x,y:e.position.y,w:e.size.width,h:e.size.height}}function Z0(e,t,n){let o=wu(e);return t>=o.x&&t<=o.x+o.w&&n>=o.y&&n<=o.y+o.h}function Vv(e,t){let n=wu(e),o=wu(t);return n.x+n.w<o.x||n.x>o.x+o.w||n.y+n.h<o.y||n.y>o.y+o.h}function ty(e){let t=O.value.get(e);if(!t||t.type==="group")return;let n=typeof t.data.parentGroup==="string"?t.data.parentGroup:null,o=n?O.value.get(n):void 0,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2,a=null;for(let c of O.value.values()){if(c.type!=="group"||c.id===n||c.collapsed)continue;if(Z0(c,r,s))a=c}if(!ca){let c=a?{nodeId:e,groupId:a.id,mode:"add"}:o&&Vv(t,o)?{nodeId:e,groupId:o.id,mode:"remove"}:null,l=mn.value;if((l?.groupId??null)!==(c?.groupId??null)||l?.mode!==c?.mode)mn.value=c}if(o&&o.data.frameMode!=="manual"&&!Vv(t,o)){let l=Math.min(o.position.x,t.position.x-22),u=Math.min(o.position.y,t.position.y-22-32),p=Math.max(o.position.x+o.size.width,t.position.x+t.size.width+22),d=Math.max(o.position.y+o.size.height,t.position.y+t.size.height+22);if(l!==o.position.x||u!==o.position.y||p!==o.position.x+o.size.width||d!==o.position.y+o.size.height)pa(o.id,{position:{x:l,y:u},size:{width:p-l,height:d-u}},{skipGroupChildTranslation:!0})}}var Su=De(()=>{let e=new Map;for(let t of O.value.values()){if(t.type!=="group"||!t.collapsed)continue;let n=Array.isArray(t.data.children)?t.data.children:[];for(let o of n)if(typeof o==="string")e.set(o,t.id)}return e});function la(e){let t=Su.value.get(e);return O.value.get(t??e)}function ny(){let e=new Set;for(let t of be.value){let n=O.value.get(t);if(!n)continue;if(n.type==="group")e.add(n.id);else if(typeof n.data.parentGroup==="string")e.add(n.data.parentGroup)}return[...e]}function Cu(e){let t=Tu();if(t.length<2)return;let n=Math.min(...t.map((l)=>e==="left"?l.position.x:l.position.y)),o=24,r=new Map;for(let l of t)r.set(l.id,e==="left"?{x:n,y:l.position.y}:{x:l.position.x,y:n});let s=(l,u)=>l.x<u.x+u.w&&u.x<l.x+l.w&&l.y<u.y+u.h&&u.y<l.y+l.h,a=t.map((l)=>{let u=r.get(l.id);return{node:l,x:u.x,y:u.y,w:l.size.width,h:l.size.height}});if(a.some((l,u)=>a.some((p,d)=>d>u&&s(l,p)))){let l=[...t].sort((p,d)=>e==="left"?p.position.y-d.position.y:p.position.x-d.position.x),u=e==="left"?Math.min(...t.map((p)=>p.position.y)):Math.min(...t.map((p)=>p.position.x));for(let p of l)r.set(p.id,e==="left"?{x:n,y:u}:{x:u,y:n}),u+=(e==="left"?p.size.height:p.size.width)+o}Mt(()=>{for(let l of t)at(l.id,{position:r.get(l.id)})}),ct()}function oy(){let e=Tu().sort((c,l)=>c.position.x-l.position.x);if(e.length<3)return;let t=e[0],o=e[e.length-1].position.x-(t.position.x+t.size.width),r=e.slice(1,-1),s=r.reduce((c,l)=>c+l.size.width,0),a=(o-s)/(r.length+1);Mt(()=>{if(a<8){let l=t.position.x+t.size.width+24;for(let u of e.slice(1))at(u.id,{position:{x:l,y:u.position.y}}),l+=u.size.width+24;return}let c=t.position.x+t.size.width+a;for(let l of r)at(l.id,{position:{x:c,y:l.position.y}}),c+=l.size.width+a}),ct()}function ry(e=24){let t=Tu().sort((c,l)=>c.position.y-l.position.y||c.position.x-l.position.x);if(t.length<2)return;let n=Math.min(...t.map((c)=>c.position.x)),o=Math.min(...t.map((c)=>c.position.y)),r=Math.ceil(Math.sqrt(t.length)),s=Math.max(...t.map((c)=>c.size.width)),a=Math.max(...t.map((c)=>c.size.height));Mt(()=>{t.forEach((c,l)=>{at(c.id,{position:{x:n+l%r*(s+e),y:o+Math.floor(l/r)*(a+e)}})})}),ct()}function Tu(){let e=be.value;if(e.size===0)return[];return Array.from(e).map((t)=>O.value.get(t)).filter((t)=>t!==void 0)}function Xn(e){let t=new Set(Ae.value);if(t.has(e))t.delete(e);else t.add(e);Ae.value=t,ct(),da(t)}function ua(e){let t=new Set(Ae.value);for(let n of e)t.add(n);Ae.value=t,ct(),da(t)}function iy(){if(Ae.value.size===0)return;Ae.value=new Set,ct(),da(new Set)}function sy(e){Ae.value=new Set(e)}function da(e){en("syncContextPinsToServer","/api/canvas/context-pins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodeIds:Array.from(e)})})}var bi=1;function Cn(e){Mt(()=>{let t=new Map(O.value);if(e.zIndex>=bi)bi=e.zIndex+1;t.set(e.id,e),O.value=t,Te.value=e.id})}function at(e,t){pa(e,t)}function pa(e,t,n={}){let o=O.value.get(e);if(!o)return;let r=new Map(O.value);if(o.type==="group"&&t.position&&n.skipGroupChildTranslation!==!0){let a=t.position.x-o.position.x,c=t.position.y-o.position.y;if(a!==0||c!==0){let l=Array.isArray(o.data.children)?o.data.children.filter((u)=>typeof u==="string"):[];for(let u of l){let p=r.get(u);if(!p||p.type==="group")continue;r.set(u,{...p,position:{x:p.position.x+a,y:p.position.y+c}})}}}r.set(e,{...o,...t}),O.value=r;let s=r.get(e)?.data.appCheckpoint?.updatedAt;if(nn.value===e&&s!==void 0&&s!==Ao)_u(e)}function ie(e,t){let n=O.value.get(e);if(!n)return;at(e,{data:{...n.data,...t}})}function Jn(e){U0(e);let t=new Map(O.value);if(t.delete(e),O.value=t,Te.value===e)Te.value=null;if(We.value===e)We.value=null;if(be.value.has(e)){let n=new Set(be.value);n.delete(e),be.value=n}if(Ae.value.has(e)){let n=new Set(Ae.value);n.delete(e),Ae.value=n,da(n)}}function dr(e){let t=new Map(Fe.value);t.set(e.id,e),Fe.value=t}function ay(e){let t=new Map(Fe.value);t.delete(e),Fe.value=t}function U0(e){let t=!1,n=new Map(Fe.value);for(let[o,r]of n)if(r.from===e||r.to===e)n.delete(o),t=!0;if(t)Fe.value=n}function q0(e){let t=new Map(pr.value);if(!t.delete(e))return;pr.value=t}async function Iu(e){return Lt("createAnnotationFromClient","/api/canvas/annotation",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function cy(e){let t=await Lt("removeAnnotationFromClient",`/api/canvas/annotation/${encodeURIComponent(e)}`,{method:"DELETE"});if(t.ok)q0(e);return t}function ma(e,t){if(!O.value.get(e))return;at(e,{size:t})}function Tn(e){let t=O.value.get(e);if(!t)return;Mt(()=>{if(at(e,{zIndex:bi++}),t.type==="group"&&Array.isArray(t.data.children)){for(let n of t.data.children)if(typeof n==="string"&&O.value.has(n))at(n,{zIndex:bi++})}}),Te.value=e}function hr(e){let t=O.value.get(e);if(!t)return;at(e,{collapsed:!t.collapsed}),ct()}function ly(e){K.value={...K.value,...e}}function uy(e){K.value=e}function dy(e){py(e)}function py(e,t={}){K.value=e,ct(t),Dv(e,t)}function my(e,t={}){let n=new Map,o=1;for(let d of e.nodes)if(n.set(d.id,d),d.zIndex>=o)o=d.zIndex+1;let r=e.edges.filter((d)=>n.has(d.from)&&n.has(d.to)),s=new Map;for(let d of r)s.set(d.id,d);let a=new Map;for(let d of e.annotations??[])a.set(d.id,d);let c=Te.value!==null&&n.has(Te.value)?Te.value:null,l=We.value!==null&&n.has(We.value)?We.value:null,u=qv(be.value,n),p=qv(Ae.value,n);Mt(()=>{if(t.applyViewport===!0&&e.viewport)K.value=e.viewport;if(bi=o,O.value=n,Fe.value=s,pr.value=a,Te.value=c,We.value=l,!Wv(be.value,u))be.value=u;if(!Wv(Ae.value,p))Ae.value=p})}var Gn=null;function W0(e){return 1-(1-e)**3}function gr(e,t=150){let n=K.value,o=Math.min(4,Math.max(0.1,n.scale*e));if(o===n.scale)return;let r=o/n.scale,{x:s,y:a}=qn();Kn({x:s-r*(s-n.x),y:a-r*(a-n.y),scale:o},t)}function Kn(e,t=300,n={}){if(Gn!==null)cancelAnimationFrame(Gn);let o={...K.value},r=performance.now();function s(a){let c=a-r,l=Math.min(1,c/t),u=W0(l);if(K.value={x:o.x+(e.x-o.x)*u,y:o.y+(e.y-o.y)*u,scale:o.scale+(e.scale-o.scale)*u},l<1)Gn=requestAnimationFrame(s);else Gn=null,py(e,n)}Gn=requestAnimationFrame(s)}function In(){if(Gn!==null)cancelAnimationFrame(Gn),Gn=null}var fy="pmx-canvas-layout";function ct(e={}){try{let t=Array.from(O.value.values()),n=t.map((r)=>({id:r.id,position:r.position,size:r.size,collapsed:r.collapsed})),o={viewport:K.value,nodes:t.map((r)=>({id:r.id,type:r.type,position:r.position,size:r.size,collapsed:r.collapsed,pinned:r.pinned})),edges:Array.from(Fe.value.values()).map((r)=>({id:r.id,from:r.from,to:r.to,type:r.type,label:r.label,style:r.style,animated:r.animated})),contextPinnedNodeIds:Array.from(Ae.value)};localStorage.setItem(fy,JSON.stringify(o)),na(n,e)}catch(t){Gv("persistLayout",t)}}function Eu(){try{let e=localStorage.getItem(fy);if(!e)return null;let t=JSON.parse(e),n=Array.isArray(t.nodes)?t.nodes:[];if(n.length===0)return null;let o=new Map;for(let r of n){if(typeof r.id!=="string"||r.id.length===0)continue;o.set(r.id,{...r.position?{position:r.position}:{},...r.size?{size:r.size}:{},...r.collapsed!==void 0?{collapsed:r.collapsed}:{},...r.pinned!==void 0?{pinned:r.pinned}:{}})}return o.size>0?o:null}catch(e){return Gv("restoreLayout",e),null}}function vr(e,t){let n=Array.from(O.value.values());if(n.length===0)return;let{POSITIVE_INFINITY:o,POSITIVE_INFINITY:r,NEGATIVE_INFINITY:s,NEGATIVE_INFINITY:a}=Number;for(let v of n)o=Math.min(o,v.position.x),r=Math.min(r,v.position.y),s=Math.max(s,v.position.x+v.size.width),a=Math.max(a,v.position.y+v.size.height);let c=nu(),l=Math.max(80,e-c.left-c.right),u=Math.max(80,t-c.top-c.bottom),p=Math.max(1,s-o),d=Math.max(1,a-r),m=Math.min(1,Math.min(l/p,u/d)),f=(o+s)/2,h=(r+a)/2;Kn({x:c.left+l/2-f*m,y:c.top+u/2-h*m,scale:m})}function Ye(e,t={}){let n=O.value.get(e);if(!n)return;let o=K.value,r=it(),s=nu(),a=Math.max(80,r.width-s.left-s.right),c=Math.max(80,r.height-s.top-s.bottom),l=Math.min(o.scale,a/n.size.width,c/n.size.height),u=n.position.x+n.size.width/2,p=n.position.y+n.size.height/2;Kn({x:s.left+a/2-u*l,y:s.top+c/2-p*l,scale:l},300,t),Tn(e)}function hy(e=1){let t=Array.from(O.value.keys());if(t.length===0)return;let o=((Te.value?t.indexOf(Te.value):-1)+e+t.length)%t.length,r=t[o];Tn(r),Ye(r)}function gy(e){let t=Te.value;if(!t)return;let n=O.value.get(t);if(!n)return;let o=Xv(t,Fe.value);if(o.size===0)return;let r=n.position.x+n.size.width/2,s=n.position.y+n.size.height/2,a=null,c=-1/0;for(let l of o){let u=O.value.get(l);if(!u)continue;let p=u.position.x+u.size.width/2,d=u.position.y+u.size.height/2,m=p-r,f=d-s,h=Math.sqrt(m*m+f*f);if(h<1)continue;let v;switch(e){case"up":v=-f;break;case"down":v=f;break;case"left":v=-m;break;case"right":v=m;break}if(v<=0)continue;let x=v/h-h*0.001;if(x>c)c=x,a=l}if(a)Ye(a)}function Ut(e){if(!O.value.get(e))return;if(wt!==null)clearTimeout(wt),wt=null;nn.value=null,Ao=void 0,Tn(e),We.value=e}function _u(e){if(wt!==null)clearTimeout(wt),wt=null;if(We.value===e)We.value=null;if(nn.value===e)nn.value=null;Ao=void 0}function En(){let e=We.value,t=e?O.value.get(e):void 0;if(e&&t&&hv(t)){let n=e,o=Date.now();if(nn.value=n,Ao=t.data.appCheckpoint?.updatedAt,wt!==null)clearTimeout(wt);let r=()=>{let a=O.value.get(n)?.data.appCheckpoint?.updatedAt;if(a!==void 0&&a!==Ao){_u(n);return}if(Date.now()-o>=j0){_u(n);return}wt=setTimeout(r,Uv)};wt=setTimeout(r,Uv);return}if(wt!==null)clearTimeout(wt),wt=null;nn.value=null,Ao=void 0,We.value=null}function fa(){let e=au(Array.from(O.value.values()),Array.from(Fe.value.values()),"grid");if(e.nodePositions.size===0&&e.groupBounds.size===0)return;Mt(()=>{for(let[t,n]of e.nodePositions.entries())at(t,{position:n});for(let[t,n]of e.groupBounds.entries())pa(t,{position:{x:n.x,y:n.y},size:{width:n.width,height:n.height}},{skipGroupChildTranslation:!0})}),ct()}function ha(){let e=au(Array.from(O.value.values()),Array.from(Fe.value.values()),"graph");if(e.nodePositions.size===0&&e.groupBounds.size===0)return;Mt(()=>{for(let[t,n]of e.nodePositions.entries())at(t,{position:n});for(let[t,n]of e.groupBounds.entries())pa(t,{position:{x:n.x,y:n.y},size:{width:n.width,height:n.height}},{skipGroupChildTranslation:!0})}),ct()}var rn=U(!1),Yn=U(!1);function Au(){return rn.value||Yn.value}var V0=0.1,G0=4,vy=1;function yy(e){return Math.min(G0,Math.max(V0,e))}function ga({viewport:e,onViewportChange:t,onViewportCommit:n,disabled:o=!1}){let r=z(null),s=z(!1),a=z({x:0,y:0}),c=z(0),l=z(null),u=H((g)=>{if(l.current!==null)window.clearTimeout(l.current);l.current=window.setTimeout(()=>{l.current=null,n(g)},140)},[n]);function p(g){if(g.deltaMode!==0)return g.deltaX===0;return g.deltaX===0&&Number.isInteger(g.deltaY)&&Math.abs(g.deltaY)>=50}let d=H((g)=>{if(o)return;g.preventDefault();let y=e.value;if(g.ctrlKey||g.metaKey||p(g)){let E=r.current?.getBoundingClientRect();if(!E)return;let D=g.clientX-E.left,N=g.clientY-E.top,b=-g.deltaY*0.002,T=yy(y.scale*(1+b)),w=T/y.scale,_={x:D-w*(D-y.x),y:N-w*(N-y.y),scale:T};t(_),u(_)}else{let E={x:y.x-g.deltaX*vy,y:y.y-g.deltaY*vy,scale:y.scale};t(E),u(E)}},[o,e,t,u]),m=H((g)=>{if(o)return;let y=r.current;if(!y)return;if(g.button===1||g.button===2)g.preventDefault();else if(fr()){if(g.target!==y)return;g.preventDefault()}else return;s.current=!0,document.documentElement.classList.add("is-canvas-panning"),a.current={x:g.clientX,y:g.clientY},y.setPointerCapture(g.pointerId)},[o]),f=H((g)=>{if(!s.current)return;if(o)return;let y=g.clientX-a.current.x,E=g.clientY-a.current.y;a.current={x:g.clientX,y:g.clientY};let D=e.value;t({x:D.x+y,y:D.y+E,scale:D.scale})},[o,e,t]),h=H(()=>{if(s.current)n(e.value);s.current=!1,document.documentElement.classList.remove("is-canvas-panning")},[n,e]),v=H((g)=>{if(o)return;if(g.touches.length!==2){c.current=0;return}g.preventDefault();let y=g.touches[0],E=g.touches[1],D=Math.hypot(E.clientX-y.clientX,E.clientY-y.clientY),N=(y.clientX+E.clientX)/2,b=(y.clientY+E.clientY)/2;if(c.current>0){let T=e.value,w=r.current?.getBoundingClientRect();if(!w)return;let _=N-w.left,P=b-w.top,q=D/c.current,R=yy(T.scale*q),Z=R/T.scale,j={x:_-Z*(_-T.x),y:P-Z*(P-T.y),scale:R};t(j),u(j)}c.current=D},[o,e,t,u]),x=H(()=>{if(l.current!==null)window.clearTimeout(l.current),l.current=null;n(e.value),c.current=0},[n,e]);return B(()=>{let g=r.current;if(!g)return;return g.addEventListener("wheel",d,{passive:!1}),g.addEventListener("pointerdown",m),g.addEventListener("pointermove",f),g.addEventListener("pointerup",h),g.addEventListener("pointercancel",h),g.addEventListener("lostpointercapture",h),g.addEventListener("touchmove",v,{passive:!1}),g.addEventListener("touchend",x),()=>{if(l.current!==null)window.clearTimeout(l.current);g.removeEventListener("wheel",d),g.removeEventListener("pointerdown",m),g.removeEventListener("pointermove",f),g.removeEventListener("pointerup",h),g.removeEventListener("pointercancel",h),g.removeEventListener("lostpointercapture",h),g.removeEventListener("touchmove",v),g.removeEventListener("touchend",x)}},[d,m,f,h,v,x]),B(()=>()=>{document.documentElement.classList.remove("is-canvas-panning")},[]),r}var X0=0;function i(e,t,n,o,r,s){t||(t={});var a,c,l=t;if("ref"in l)for(c in l={},t)c=="ref"?a=t[c]:l[c]=t[c];var u={type:e,props:l,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--X0,__i:-1,__u:0,__source:r,__self:s};if(typeof e=="function"&&(a=e.defaultProps))for(c in a)l[c]===void 0&&(l[c]=a[c]);return _e.vnode&&_e.vnode(u),u}function by(){let[e,t]=I({stops:[]}),[n,o]=I(0),[r,s]=I(""),a=rn.value,c=Et.value,l=z(0),u=(d)=>{cancelAnimationFrame(l.current),K.value=d},p=ga({viewport:K,onViewportChange:u,onViewportCommit:u});return B(()=>{let d=new URLSearchParams(location.search);return rn.value=d.get("present")==="1",Yn.value=d.get("capture")==="1",window.pmxCapture={ready:()=>Et.value,area:it,camera:()=>({...K.value}),frame:async(m)=>(Yn.value=!0,In(),K.value=eu.parse(m),await new Promise((f)=>requestAnimationFrame(()=>requestAnimationFrame(()=>f()))),{...K.value})},()=>{delete window.pmxCapture,rn.value=!1,Yn.value=!1}},[]),B(()=>{if(!a||!c)return;let d=!1;return Y("read tour","/api/canvas/tour",{tour:{stops:[]}}).then((m)=>{if(!d)t(m.tour),o(0)}),()=>{d=!0}},[a,c]),B(()=>{if(!a||Yn.value)return;let d=e.stops[n];if(!d)return;let m=it(),f;try{f=nv(d,[...O.value.values()],m.width,m.height),s("")}catch(y){s(y instanceof Error?y.message:String(y));return}In();let h={...K.value},v=performance.now(),x=(d.duration??1)*1000,g=(y)=>{if(Yn.value)return;let E=x===0?1:Math.min(1,(y-v)/x);if(K.value=ov(h,f,E,m.width,m.height,d.easing,d.pullback),E<1)l.current=requestAnimationFrame(g)};return l.current=requestAnimationFrame(g),()=>cancelAnimationFrame(l.current)},[a,n,e]),B(()=>{if(!a)return;let d=(m)=>{if(m.stopImmediatePropagation(),m.target instanceof HTMLButtonElement&&["Enter"," "].includes(m.key))return;if(["Escape","ArrowRight","ArrowDown","ArrowLeft","ArrowUp"," "].includes(m.key))m.preventDefault();if(m.key==="Escape")rn.value=!1;if(["ArrowRight","ArrowDown"," "].includes(m.key))o((f)=>Math.max(0,Math.min(e.stops.length-1,f+1)));if(["ArrowLeft","ArrowUp"].includes(m.key))o((f)=>Math.max(0,f-1))};return document.addEventListener("keydown",d,!0),()=>document.removeEventListener("keydown",d,!0)},[a,e]),a?i(ue,{children:[!Yn.value&&i("div",{class:"presentation-navigation",ref:p,onPointerDown:(d)=>{if(d.button===1||d.button===2)cancelAnimationFrame(l.current)},onContextMenu:(d)=>d.preventDefault(),children:i("button",{type:"button",class:"presentation-exit",onClick:()=>rn.value=!1,children:"Exit presentation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r&&i("div",{class:"presentation-error",role:"alert",children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null}var J0={fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};function ce({size:e=16,children:t,...n}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",style:{verticalAlign:"middle",flexShrink:0},...J0,...n,children:t},void 0,!1,void 0,this)}function Pe(e){return i(ce,{...e,children:i("path",{d:"m4 4 8 8M12 4l-8 8"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function wy(e){return i(ce,{...e,children:i("path",{d:"M8 2v12M2 8h12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function _y(e){return i(ce,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("path",{d:"M8 5v6M5 8h6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function br(e){return i(ce,{...e,children:i("polyline",{points:"6 3 11 8 6 13"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function ky(e){return i(ce,{...e,children:[i("circle",{cx:"3",cy:"8",r:"0.75"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"0.75"},void 0,!1,void 0,this),i("circle",{cx:"13",cy:"8",r:"0.75"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function hn(e){return i(ce,{...e,children:i("path",{d:"M9 2h5v5M14 2 7 9M6 3H2v11h11v-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Sy(e){return i(ce,{...e,children:i("path",{d:"M9 2h5v5M14 2l-5 5M7 14H2V9M2 14l5-5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Cy(e){return i(ce,{...e,children:i("path",{d:"M14 8H2m5-5-5 5 5 5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function va(e){return i(ce,{...e,children:i("path",{d:"M13.5 6A5.5 5.5 0 1 0 13 11M14 2v4h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Pu(e){return i(ce,{...e,children:i("path",{d:"M6 2 2 6l4 4M2 6h7a4 4 0 0 1 0 8"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Ty(e){return i(ce,{...e,children:i("path",{d:"m8 1 2 5 5 2-5 2-2 5-2-5-5-2 5-2Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Iy(e){return i(ce,{...e,children:i("path",{d:"M8 10V2M4.5 5.5 8 2l3.5 3.5M2 10v3.5h12V10"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function xr(e){return i(ce,{...e,children:i("polyline",{points:"3 6 8 11 13 6"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function ya(e){return i(ce,{...e,children:[i("polyline",{points:"1 5 1 1 5 1"},void 0,!1,void 0,this),i("polyline",{points:"11 1 15 1 15 5"},void 0,!1,void 0,this),i("polyline",{points:"15 11 15 15 11 15"},void 0,!1,void 0,this),i("polyline",{points:"5 15 1 15 1 11"},void 0,!1,void 0,this),i("rect",{x:"4",y:"4",width:"8",height:"8",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ey(e){return i(ce,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),i("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this),i("line",{x1:"7",y1:"5",x2:"7",y2:"9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ay(e){return i(ce,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),i("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function An(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"4",x2:"9.5",y2:"4"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"12",x2:"9.5",y2:"12"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6.5",x2:"4",y2:"9.5"},void 0,!1,void 0,this),i("line",{x1:"12",y1:"6.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ba(e){return i(ce,{...e,children:[i("rect",{x:"1",y:"2",width:"14",height:"12",rx:"1.5"},void 0,!1,void 0,this),i("rect",{x:"8",y:"7",width:"6",height:"6",rx:"1",fill:"currentColor","fill-opacity":"0.2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zy(e){return i(ce,{...e,children:[i("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"1",x2:"8",y2:"3"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"13",x2:"8",y2:"15"},void 0,!1,void 0,this),i("line",{x1:"1",y1:"8",x2:"3",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"13",y1:"8",x2:"15",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"3.05",y1:"3.05",x2:"4.46",y2:"4.46"},void 0,!1,void 0,this),i("line",{x1:"11.54",y1:"11.54",x2:"12.95",y2:"12.95"},void 0,!1,void 0,this),i("line",{x1:"3.05",y1:"12.95",x2:"4.46",y2:"11.54"},void 0,!1,void 0,this),i("line",{x1:"11.54",y1:"4.46",x2:"12.95",y2:"3.05"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function xa(e){return i(ce,{...e,children:i("path",{d:"M13 9.5A5.5 5.5 0 1 1 6.5 3 4.5 4.5 0 0 0 13 9.5Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Py(e){return i(ce,{...e,children:[i("path",{d:"M3 13l2.8-.7L13 5.1 10.9 3 3.7 10.2 3 13Z"},void 0,!1,void 0,this),i("path",{d:"M9.8 4.1l2.1 2.1"},void 0,!1,void 0,this),i("path",{d:"M2.5 14h11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ny(e){return i(ce,{...e,children:[i("path",{d:"M3 10.5 8.5 5a2 2 0 0 1 2.8 0l1.7 1.7a2 2 0 0 1 0 2.8L8.5 14H5.8L3 11.2Z"},void 0,!1,void 0,this),i("path",{d:"M7.5 6 12 10.5"},void 0,!1,void 0,this),i("path",{d:"M8.5 14H14"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ry(e){return i(ce,{...e,children:[i("path",{d:"M3 4h10"},void 0,!1,void 0,this),i("path",{d:"M8 4v8"},void 0,!1,void 0,this),i("path",{d:"M6 12h4"},void 0,!1,void 0,this),i("path",{d:"M4.5 4 4 6"},void 0,!1,void 0,this),i("path",{d:"M11.5 4 12 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $y(e){return i(ce,{...e,children:[i("rect",{x:"1",y:"4",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M5.5 4 L6.5 2.5 H9.5 L10.5 4"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"9",r:"2.3"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function My(e){return i(ce,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"0.8",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ly(e){return i(ce,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"10.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"5.5",x2:"5.5",y2:"10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Oy(e){return i(ce,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Dy(e){return i(ce,{...e,children:[i("rect",{x:"1",y:"3",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6",x2:"5",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"7.5",y1:"6",x2:"8.5",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"11",y1:"6",x2:"12",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"10",x2:"12",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function wr(e){return i(ce,{...e,children:i("path",{d:"M2 13 L2 4 A2 2 0 0 1 4 2 L12 2 A2 2 0 0 1 14 4 L14 9 A2 2 0 0 1 12 11 L5 11 Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function wa({size:e=22,class:t}){return i("svg",{width:e,height:e,viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",class:t,"aria-hidden":"true",children:[i("rect",{x:"8",y:"8",width:"48",height:"48",rx:"7",fill:"none",stroke:"currentColor","stroke-width":"2.2",opacity:"0.35"},void 0,!1,void 0,this),i("rect",{x:"16",y:"16",width:"32",height:"32",rx:"5",fill:"none",stroke:"currentColor","stroke-width":"2.2",opacity:"0.6"},void 0,!1,void 0,this),i("rect",{x:"24",y:"24",width:"16",height:"16",rx:"3",fill:"none",stroke:"currentColor","stroke-width":"2.2"},void 0,!1,void 0,this),i("rect",{x:"29",y:"29",width:"6",height:"6",rx:"1",fill:"currentColor"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Fy({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M3 2l10 5.5-4.2 1.3L7.5 13z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function By({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M5 7.5V3.8a1 1 0 0 1 2 0V7m0-3.9a1 1 0 0 1 2 0V7m0-2.7a1 1 0 0 1 2 0V7.4m0-.9a1 1 0 0 1 2 0v3.2A4.3 4.3 0 0 1 8.7 14H8a4.3 4.3 0 0 1-3.6-2L2.7 9.3a1 1 0 0 1 1.6-1.2L5 9.2"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Qn(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6",x2:"10",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"8.5",x2:"8",y2:"8.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"11",x2:"11",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function K0(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M4 13.5 L5.5 11.5 L8 11.5"},void 0,!1,void 0,this),i("polyline",{points:"5 6 7 8 5 10"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"10",x2:"11",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Y0(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M12 13.5 L10.5 11.5 L8 11.5"},void 0,!1,void 0,this),i("circle",{cx:"5",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"11",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function xy(e){return i(ce,{...e,children:[i("path",{d:"M3 1.5h6l3.5 3.5v8a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V2.5a1 1 0 0 1 1-1z"},void 0,!1,void 0,this),i("polyline",{points:"9 1.5 9 5 12.5 5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"8.5",x2:"10.5",y2:"8.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"11",x2:"9",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Q0(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"5.5",cy:"6.5",r:"1.2"},void 0,!1,void 0,this),i("path",{d:"M1.8 12 L6 8.5 L9 11 L11.5 9 L14.2 12"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function yr(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"1.5",y1:"5.5",x2:"14.5",y2:"5.5"},void 0,!1,void 0,this),i("circle",{cx:"3.3",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"5",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"6.7",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"8",x2:"12",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"10",x2:"10",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function eC(e){return i(ce,{...e,children:[i("rect",{x:"2",y:"4",width:"12",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"2",y1:"6.5",x2:"14",y2:"6.5"},void 0,!1,void 0,this),i("path",{d:"M11 1.5 L11 4"},void 0,!1,void 0,this),i("circle",{cx:"11",cy:"4",r:"1.6",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Nu(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"1.5","stroke-dasharray":"2 1.5"},void 0,!1,void 0,this),i("rect",{x:"4",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),i("rect",{x:"8.5",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),i("rect",{x:"6.25",y:"8.5",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function tC(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"9.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function nC(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M3.5 10.5 L6 6.5 L8.5 9.5 L12.5 5"},void 0,!1,void 0,this),i("circle",{cx:"12.5",cy:"5",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function oC(e){return i(ce,{...e,children:[i("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"5.5",x2:"11.5",y2:"5.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"8",x2:"11.5",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"10.5",x2:"8",y2:"10.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"2",x2:"6.5",y2:"14",opacity:"0.45"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function rC(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this),i("path",{d:"M4 11 L4 6 L6 8.5 L8 6 L8 11"},void 0,!1,void 0,this),i("path",{d:"M10 11 L10 6 L12.5 11 L12.5 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function iC(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("polyline",{points:"10 5 13 5 13 8"},void 0,!1,void 0,this),i("line",{x1:"13",y1:"5",x2:"8",y2:"10"},void 0,!1,void 0,this),i("path",{d:"M6 6 L3.5 6 L3.5 11.5 L10 11.5 L10 9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function sC(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M7 5.5 C 5.5 5.5 5.5 8 4 8 C 5.5 8 5.5 10.5 7 10.5"},void 0,!1,void 0,this),i("path",{d:"M9 5.5 C 10.5 5.5 10.5 8 12 8 C 10.5 8 10.5 10.5 9 10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zu(e){return i(ce,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"5.2",y1:"6",x2:"8",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"8",x2:"10.8",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"8",x2:"8",y2:"11"},void 0,!1,void 0,this),i("circle",{cx:"5.2",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"10.8",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"11",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function sn(e){switch(e){case"markdown":return Qn;case"prompt":return K0;case"response":return Y0;case"file":return xy;case"diff":return xy;case"mermaid":return zu;case"image":return Q0;case"webpage":return yr;case"context":return eC;case"group":return Nu;case"status":return tC;case"trace":return nC;case"ledger":return oC;case"mcp-app":return rC;case"ext-app":return iC;case"json-render":return sC;case"graph":return zu;case"board":return zu;case"html":return yr;default:return Qn}}function aC(e){return new Date(e).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}function cC(){Xs()}function Hy(){let e=fi.value;if(e.length===0)return null;let t=dn.value,n=rr.value;if(!t)return i("button",{type:"button",class:"attention-history-tab",onClick:cC,"aria-label":n>0?`Recent updates — ${n} new`:"Recent updates",title:n>0?`${n} new updates since last viewed`:"Recent updates",children:[i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"9.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"attention-history-tab-label",children:"Updates"},void 0,!1,void 0,this),n>0&&i("span",{class:"attention-history-tab-badge","aria-hidden":"true",children:n>9?"9+":n},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("aside",{class:"attention-history","aria-label":"Recent semantic changes",children:[i("div",{class:"attention-history-header",children:[i("div",{class:"attention-history-header-text",children:[i("span",{class:"attention-history-title",children:"Recent Updates"},void 0,!1,void 0,this),i("span",{class:"attention-history-subtitle",children:"Focus and meaning shifts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"attention-history-close",onClick:Sv,"aria-label":"Collapse changes panel",title:"Collapse",children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"attention-history-list",children:e.map((o)=>i("article",{class:`attention-history-entry attention-tone-${o.tone}`,children:[i("div",{class:"attention-history-meta",children:[i("span",{class:"attention-history-kind",children:o.title},void 0,!1,void 0,this),i("time",{class:"attention-history-time",dateTime:new Date(o.createdAt).toISOString(),children:aC(o.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("p",{class:"attention-history-detail",children:o.detail},void 0,!1,void 0,this)]},o.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jy(){let e=Ws.value;if(!e)return null;return i("button",{type:"button",class:`attention-toast attention-tone-${e.tone}`,onClick:Xs,"aria-label":`${e.title}${e.detail?`: ${e.detail}`:""} — open change history`,children:[i("span",{class:"attention-toast-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"attention-toast-copy",children:[i("span",{class:"attention-toast-title",children:e.title},void 0,!1,void 0,this),e.detail&&i("span",{class:"attention-toast-detail",children:e.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var ki=U(null),Zy=0;function Dt(e,t,n={}){return new Promise((o)=>{ki.value?.resolve(null),Zy+=1,ki.value={seq:Zy,title:e,placeholder:t,initial:n.initial??"",allowEmpty:n.allowEmpty??!1,confirm:n.confirm??"Add",resolve:o}})}function _i(e){let t=ki.value;ki.value=null,t?.resolve(e)}function Uy(){let e=ki.value,t=z(null);if(B(()=>{if(!e)return;let o=(r)=>{if(r.key!=="Escape")return;r.preventDefault(),r.stopPropagation(),_i(null)};return window.addEventListener("keydown",o,{capture:!0}),()=>window.removeEventListener("keydown",o,{capture:!0})},[e]),!e)return null;let n=()=>{let o=t.current?.value.trim()??"";_i(o?o:e.allowEmpty?"":null)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>_i(null),children:i("div",{class:"text-prompt",role:"dialog","aria-label":e.title,"data-testid":"text-prompt",onPointerDown:(o)=>o.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:e.title},void 0,!1,void 0,this),i("input",{ref:(o)=>{if(t.current=o,!o)return;if(o.focus(),e.initial)o.select()},class:"text-prompt-input",type:"text",defaultValue:e.initial,placeholder:e.placeholder,onKeyDown:(o)=>{if(o.key==="Enter")o.preventDefault(),o.stopPropagation(),n();else if(o.key==="Escape")o.preventDefault(),o.stopPropagation(),_i(null)}},e.seq,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:()=>_i(null),children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"button",class:"text-prompt-confirm",onClick:n,children:e.confirm},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}async function eo(e,t,n,o){if((await ra({type:t,sourceNodeId:e.id,sourceSurface:"native-node",...n?{payload:n}:{}})).ok)pn("context",o,"",[e.id])}var Ro={padding:"3px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer",flexShrink:0};function lC(e){let t=e.title||e.label||e.key||"Context",n=e.summary?.trim()||"Available in startup context.",o=e.pathDisplay||e.path||"",r=e.category==="profile"?"Operator":e.category==="planning"||e.category==="memory"?"Product":e.category?e.category.charAt(0).toUpperCase()+e.category.slice(1):void 0,s=e.sourceKind==="global"?"Global":"Workspace",a=e.state==="missing"?"Missing":e.state==="stale"?"Stale":e.state==="invalid"?"Invalid":"Loaded";return{title:t,summary:n,pathDisplay:o,category:r,sourceKind:s,status:a,required:e.required===!0}}function an(e){return typeof e==="string"?e.trim():""}function uC(e){return e.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}function dC(e){let t=an(e.title),n=an(e.content),o=uC(an(e.rendered)),r=n||o,s=an(e.path);if(!t&&!r&&!s)return null;return{title:t||"Context",summary:r,path:s}}function pC(e){let t=an(e.data.title)||e.id,n=an(e.data.content)||an(e.data.excerpt)||an(e.data.description)||an(e.data.pageTitle)||"",o=an(e.data.path)||an(e.data.url);return{id:e.id,title:t,summary:n,kind:dt[e.type]??e.type,path:o}}function qy(e){if(e===null||!Number.isFinite(e)||e<0)return"0";if(e>=1e6)return`${(e/1e6).toFixed(1)}m`;if(e>=1000)return`${(e/1000).toFixed(1)}k`;return`${Math.round(e)}`}function mC(e){if(e>=0.95)return"var(--c-danger)";if(e>=0.85)return"var(--c-warn)";if(e>=0.7)return"var(--c-warn)";return"var(--c-accent)"}function _a({node:e,expanded:t=!1,pinnedNodes:n=[]}){let o=e.data.cards??[],r=e.data.auxTabs??[],s=n.map(pC),a=s.length>0,c=typeof e.data.currentTokens==="number"?e.data.currentTokens:null,l=typeof e.data.tokenLimit==="number"?e.data.tokenLimit:null,u=typeof e.data.utilization==="number"?e.data.utilization:null,p=typeof e.data.messagesLength==="number"?e.data.messagesLength:null,d=u!==null?Math.max(0,Math.min(100,Math.round(u*100))):null,m=mC(u??0),f=!a&&o.length===0&&r.length===0?dC(e.data):null,h=async(v)=>{let x=typeof v.path==="string"?v.path.trim():"";if(!x)return;await ea(x)};return i("div",{style:{display:"flex",flexDirection:"column",gap:t?"10px":"6px",fontSize:t?"14px":"12px",maxWidth:t?"760px":void 0,margin:t?"0 auto":void 0,width:t?"100%":void 0,padding:t?"8px 0":void 0},children:[i("div",{style:{display:"flex",justifyContent:"flex-end"},children:i("button",{type:"button",class:"ax-node-action",title:"Point the agent at this node — sets it as the agent's current AX focus so the agent pulls it into context to work on next (a one-click alternative to manually pinning).",style:Ro,onClick:(v)=>{v.stopPropagation(),eo(e,"ax.focus.set",void 0,"Focus set")},children:"Set focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),l!==null&&l>0&&i("div",{style:{marginBottom:"8px"},children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:"Token Usage"},void 0,!1,void 0,this),i("div",{style:{height:"6px",background:"var(--c-surface-hover)",borderRadius:"3px",overflow:"hidden",marginBottom:"4px"},children:i("div",{style:{height:"100%",width:`${Math.min(100,(u??0)*100)}%`,background:m,borderRadius:"3px",transition:"width 0.3s ease"}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{style:{fontSize:"11px",color:"var(--c-muted)"},children:[d,"% — ",qy(c)," / ",qy(l)," tokens",p!==null&&i(ue,{children:[" · ",p," messages"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:["Pinned Context (",s.length,")"]},void 0,!0,void 0,this),s.map((v)=>i("div",{style:{padding:"6px 8px",background:"var(--c-surface-subtle)",borderRadius:"6px",marginBottom:"4px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"2px"},children:v.title},void 0,!1,void 0,this),v.summary&&i("div",{style:{color:"var(--c-muted)",fontSize:"10px",lineHeight:1.45,marginBottom:"4px",whiteSpace:"pre-wrap"},children:v.summary},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"4px",flexWrap:"wrap",marginTop:"4px"},children:i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:v.kind},void 0,!1,void 0,this)},void 0,!1,void 0,this),v.path&&i("div",{style:{marginTop:"6px"},children:[i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all",marginBottom:"6px"},children:v.path},void 0,!1,void 0,this),v.path.startsWith("/")&&i("button",{type:"button",onClick:()=>void ea(v.path),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},v.id,!0,void 0,this))]},void 0,!0,void 0,this),!a&&o.length>0&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:["Context (",o.length,")"]},void 0,!0,void 0,this),o.map((v)=>{let x=lC(v);return i("div",{style:{padding:"6px 8px",background:"var(--c-surface-subtle)",borderRadius:"6px",marginBottom:"4px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"2px"},children:x.title},void 0,!1,void 0,this),i("div",{style:{color:"var(--c-muted)",fontSize:"10px",lineHeight:1.45,marginBottom:"4px"},children:x.summary},void 0,!1,void 0,this),x.pathDisplay&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all"},children:x.pathDisplay},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"4px",flexWrap:"wrap",marginTop:"4px"},children:[i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-accent-10)",color:"var(--c-accent)",borderRadius:"3px",display:"inline-block"},children:x.status},void 0,!1,void 0,this),x.category&&i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:x.category},void 0,!1,void 0,this),i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:x.sourceKind},void 0,!1,void 0,this),x.required&&i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-warn-12)",color:"var(--c-warn-alt)",borderRadius:"3px",display:"inline-block"},children:"Required"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v.path&&i("div",{style:{marginTop:"6px"},children:i("button",{type:"button",onClick:()=>void h(v),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},v.key??x.pathDisplay??x.title,!0,void 0,this)})]},void 0,!0,void 0,this),!a&&r.length>0&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px",marginTop:o.length>0?"8px":0},children:["References (",r.length,")"]},void 0,!0,void 0,this),r.map((v)=>i("a",{href:v.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",padding:"4px 8px",color:"var(--c-accent)",fontSize:"11px",textDecoration:"none",borderRadius:"4px",marginBottom:"2px",wordBreak:"break-all"},children:[v.url,v.reason&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",marginLeft:"6px"},children:["(",v.reason,")"]},void 0,!0,void 0,this)]},v.id,!0,void 0,this))]},void 0,!0,void 0,this),f&&i("div",{style:{padding:"8px 10px",background:"var(--c-surface-subtle)",borderRadius:"6px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"4px"},children:f.title},void 0,!1,void 0,this),f.summary&&i("div",{style:{color:"var(--c-text-soft)",fontSize:"11px",lineHeight:1.5,whiteSpace:"pre-wrap"},children:f.summary},void 0,!1,void 0,this),f.path&&i("div",{style:{marginTop:"6px"},children:[i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all",marginBottom:"6px"},children:f.path},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>void ea(f.path),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!a&&!f&&o.length===0&&r.length===0&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic"},children:"No context loaded"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Wy(e){return e.replace(/^[ab]\//,"")}function fC(e,t){if(t&&t!=="/dev/null")return Wy(t);if(e&&e!=="/dev/null")return Wy(e);return null}function hC(e){if(!e.trim())return[];let t=e.split(`
|
|
89
|
+
`);if(t.length>0&&t[t.length-1]==="")t.pop();let n=[],o=null,r=!1,s=(a)=>{let c={path:a,lines:[]};return r=!1,n.push(c),c};for(let a=0;a<t.length;a++){let c=t[a]??"",l=c.match(/^diff --git a\/(.+?) b\/(.+)$/);if(l){o=s(l[2]??null);continue}let u=t[a+1]??"";if(c.startsWith("--- ")&&u.startsWith("+++ ")){let d=fC(c.slice(4).trim(),u.slice(4).trim());if(o&&!r){if(!o.path)o.path=d}else o=s(d);a++;continue}if(!o)o=s(null);let p=o;if(c.startsWith("@@"))r=!0,p.lines.push({kind:"hunk",text:c});else if(c.startsWith("+"))p.lines.push({kind:"add",text:c});else if(c.startsWith("-"))p.lines.push({kind:"remove",text:c});else p.lines.push({kind:"context",text:c})}return n}function ka({node:e}){let t=typeof e.data.content==="string"?e.data.content:"",n=Se(()=>hC(t),[t]);if(n.length===0)return i("div",{class:"diff-node diff-node-empty",children:"Empty diff"},void 0,!1,void 0,this);return i("div",{class:"diff-node",children:n.map((o,r)=>i("div",{class:"diff-file",children:[o.path&&i("div",{class:"diff-file-header",children:o.path},void 0,!1,void 0,this),i("pre",{class:"diff-lines",children:o.lines.map((s,a)=>i("div",{class:s.kind==="hunk"?"diff-hunk":`diff-line-${s.kind}`,children:s.text||" "},a,!1,void 0,this))},void 0,!1,void 0,this)]},`${o.path??"anonymous"}-${r}`,!0,void 0,this))},void 0,!1,void 0,this)}function Vy(e){let t=e.toLowerCase();if(t.endsWith(".csv"))return",";if(t.endsWith(".tsv"))return"\t";return null}function Gy(e,t){let n=[],o=[],r="",s=!1,a=!1;for(let l=0;l<e.length;l++){let u=e[l];if(a=!0,s){if(u==='"')if(e[l+1]==='"')r+='"',l++;else s=!1;else if(u==="\r"&&e[l+1]===`
|
|
90
90
|
`)r+=`
|
|
91
91
|
`,l++;else r+=u;continue}if(u==='"'&&r==="")s=!0;else if(u===t)o.push(r),r="";else if(u===`
|
|
92
92
|
`||u==="\r"){if(u==="\r"&&e[l+1]===`
|
|
93
|
-
`)l++;o.push(r),r="",n.push(o),o=[],a=!1}else r+=u}if(a)o.push(r),n.push(o);let c=n.shift()??[];return{header:c,rows:n.map((l)=>Array.from({length:c.length},(u,p)=>l[p]??""))}}var
|
|
94
|
-
`).length;ie(e.id,{fileContent:V,lineCount:ge}),
|
|
95
|
-
`).length,ge=new Date().toISOString();ie(e.id,{fileContent:
|
|
96
|
-
`),w=`${String(T.length).length+1}ch`,_=
|
|
97
|
-
`},void 0,!1,void 0,this)]},V,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var
|
|
93
|
+
`)l++;o.push(r),r="",n.push(o),o=[],a=!1}else r+=u}if(a)o.push(r),n.push(o);let c=n.shift()??[];return{header:c,rows:n.map((l)=>Array.from({length:c.length},(u,p)=>l[p]??""))}}var Xy="pmx-canvas-iframe-probe";var gC="/api/canvas/iframe-probe",vC=3000,kt=U(null);function yC(){let e=new URLSearchParams(window.location.search).get("iframe-mode");return e==="srcdoc"||e==="src"?e:null}function Jy(e=vC){return new Promise((t)=>{let n=document.createElement("iframe");n.setAttribute("data-pmx-iframe-probe",""),n.style.cssText="position:fixed;width:1px;height:1px;left:-9999px;border:none",n.setAttribute("sandbox","allow-scripts");let o=(a)=>{window.clearTimeout(s),window.removeEventListener("message",r),n.remove(),t(a)},r=(a)=>{if(a.source!==n.contentWindow)return;if(a.data?.source!==Xy)return;o(!0)},s=window.setTimeout(()=>o(!1),e);window.addEventListener("message",r),n.addEventListener("error",()=>o(!1)),n.src=gC,(document.body??document.documentElement).appendChild(n)})}var Sa=null;function bC(){try{return window.self!==window.top}catch{return!0}}function xC(){return window.__PMX_AMP_ORB===!0}function Ky(e={}){if(kt.value)return Promise.resolve(kt.value);if(Sa)return Sa;let t=yC();if(t)return kt.value=t,Promise.resolve(t);if(!(e.embedded??bC()))return kt.value="src",Jy(e.probeTimeoutMs).then((n)=>{if(!n&&kt.value==="src")kt.value="srcdoc"}),Promise.resolve("src");if(e.ampOrb??xC())return kt.value="srcdoc",Promise.resolve("srcdoc");return Sa=Jy(e.probeTimeoutMs).then((n)=>{let o=n?"src":"srcdoc";return kt.value=o,o}),Sa}var Pt=U([]),Ne=U(null),_r=U(!1),Qy=null,kr=0,Ca=0,Yy=Promise.resolve();function eb(e){Qy=e}function $o(e){if(!e||!Array.isArray(e.boards))return;kr+=1;let t=typeof e.activeBoardId==="string"?e.activeBoardId:null,n=_r.value&&(t!==Ne.value||e.reloaded===!0);if(Pt.value=e.boards,Ne.value=t,_r.value=!0,n)Qy?.()}async function Ru(){let e=kr,t=await Y("loadBoards","/api/canvas/boards",null);if(e===kr)$o(t)}async function Ta(e,t,n,o,r=kr){let s=await Y(e,t,null,{method:n,headers:{"Content-Type":"application/json"},...o===void 0?{}:{body:JSON.stringify(o)}});return r===kr?s:null}async function Nt(e){let t=++Ca,n=kr,o=null,r=Yy.then(async()=>{o=await Ta("openBoard","/api/canvas/boards/open","POST",{id:e},n)});if(Yy=r.catch(()=>{return}),await r,t===Ca)$o(o)}async function tb(e){let t=++Ca,n=await Y("createBoard","/api/canvas/boards",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})});if(n?.board&&t===Ca)await Nt(n.board.id)}async function nb(e){return Y("previewBoardCopy","/api/canvas/boards/from",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceBoardId:e,name:"Preview",preview:!0})})}async function ob(e){let t=await Y("createBoardFrom","/api/canvas/boards/from",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return await Ru(),t?.board??null}async function Ia(e,t){let n=await Ta("updateBoard",`/api/canvas/boards/${encodeURIComponent(e)}`,"PATCH",{...t,...t.category===null?{category:""}:{}});$o(n)}async function rb(e,t){let n=await Ta("setBoardReadme",`/api/canvas/boards/${encodeURIComponent(e)}`,"PATCH",{readmeNodeId:t});$o(n)}async function ib(e){let t=await Ta("deleteBoard",`/api/canvas/boards/${encodeURIComponent(e)}`,"DELETE");$o(t)}function Ea(){return Pt.value.find((e)=>e.id===Ne.value)??null}function sb({node:e,expanded:t=!1}){let n=String(e.data.attachmentId),o=Ne.value,[r,s]=I(null),[a,c]=I(t),[l,u]=I(!1);B(()=>{let m=!0,f=async()=>{let v=await Y("readImports",`/api/canvas/imports?boardId=${encodeURIComponent(o??"")}`,null);if(m)s(v?.imports?.find((x)=>x.attachmentId===n)??null)};f();let h=window.setInterval(()=>void f(),2000);return()=>{m=!1,window.clearInterval(h)}},[n,o]),B(()=>{if(!a)return;let m=(f)=>{if(f.key==="Escape")f.stopPropagation(),c(!1)};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[a]);let p=async(m)=>{if(!r)return;u(!0);let f=await Y(`import.${m}`,`/api/canvas/imports/${r.id}/${m}`,null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({consent:!0})});if(u(!1),f?.import){if(s(f.import),c(!1),t&&m==="commit")En()}},d=r&&["attached","cancelled","unavailable"].includes(r.status);return i("div",{class:"attachment-node",onPointerDown:(m)=>m.stopPropagation(),children:[i("div",{class:"attachment-status",children:r?.status==="requested"?"Waiting for agent":r?.status==="drafted"?"Ready for review":r?.status==="committed"?"Markdown added":"Original attached"},void 0,!1,void 0,this),i("a",{href:`/api/canvas/attachments/${n}/bytes`,target:"_blank",rel:"noopener noreferrer",children:["Download original · ",Math.ceil(Number(e.data.size??0)/1024)," KB"]},void 0,!0,void 0,this),r?.reason&&i("p",{children:r.reason},void 0,!1,void 0,this),d&&i(ue,{children:[i("p",{id:`import-consent-${e.id}`,children:"Asking the agent to import allows it to process this file with its tools and model provider."},void 0,!1,void 0,this),i("button",{type:"button",class:"attachment-button is-primary","aria-describedby":`import-consent-${e.id}`,disabled:l,onClick:()=>void p("request"),children:"Ask agent to import"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r?.status==="requested"&&i("p",{children:"No automatic extraction. Ask your connected agent to check its pending steering or use canvas_import list."},void 0,!1,void 0,this),r?.status==="drafted"&&!a&&i("button",{type:"button",class:"attachment-button is-primary",onClick:()=>t?c(!0):Ut(e.id),children:["Review Markdown · ",r.sections.length," ",r.sections.length===1?"card":"cards"]},void 0,!0,void 0,this),r&&["requested","drafted"].includes(r.status)&&i("button",{type:"button",class:"attachment-button",disabled:l,onClick:()=>void p("cancel"),children:"Cancel import"},void 0,!1,void 0,this),a&&r?.status==="drafted"&&i("div",{class:"attachment-review",role:"dialog","aria-label":"Review imported Markdown",children:[i("h3",{children:"Review imported Markdown"},void 0,!1,void 0,this),i("p",{children:["Source material, not instructions or verified knowledge. ",r.agentDescription]},void 0,!0,void 0,this),r.warnings.length>0&&i("ul",{children:r.warnings.map((m)=>i("li",{children:m},m,!1,void 0,this))},void 0,!1,void 0,this),r.sections.map((m,f)=>i("section",{children:[i("h4",{children:m.title},void 0,!1,void 0,this),i("p",{children:m.reference||"Source location not supplied"},void 0,!1,void 0,this),i("pre",{children:m.markdown},void 0,!1,void 0,this)]},f,!0,void 0,this)),i("div",{class:"attachment-review-actions",children:[i("button",{type:"button",class:"attachment-button",onClick:()=>c(!1),children:"Close review"},void 0,!1,void 0,this),i("button",{type:"button",class:"attachment-button is-primary",disabled:l||o!==r.boardId,onClick:()=>void p("commit"),children:"Add to board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function wC(e){let t=e.split(".").pop()?.toLowerCase()??"";return{ts:"TypeScript",tsx:"TSX",js:"JavaScript",jsx:"JSX",py:"Python",rs:"Rust",go:"Go",rb:"Ruby",java:"Java",kt:"Kotlin",swift:"Swift",c:"C",cpp:"C++",h:"C/C++",css:"CSS",html:"HTML",json:"JSON",yaml:"YAML",yml:"YAML",md:"Markdown",toml:"TOML",sql:"SQL",sh:"Shell",bash:"Shell",xml:"XML",graphql:"GraphQL",proto:"Protobuf"}[t]??(t.toUpperCase()||"Text")}var $u=500;function Mu(e){if(!Number.isFinite(e)||e<0)return"";if(e<1024)return`${Math.round(e)} B`;let t=["KB","MB","GB","TB"],n=e/1024,o=0;while(n>=1024&&o<t.length-1)n/=1024,o++;return`${n<10?n.toFixed(1):Math.round(n)} ${t[o]}`}function Aa({node:e,expanded:t=!1}){if(typeof e.data.attachmentId==="string")return i(sb,{node:e,expanded:t},void 0,!1,void 0,this);return i(_C,{node:e,expanded:t},void 0,!1,void 0,this)}function _C({node:e,expanded:t=!1}){let n=e.data.path||e.data.content||"",o=e.data.title||n.split("/").pop()||"File",r=e.data.fileContent,s=e.data.updatedAt,a=e.data.lineCount,c=e.data.byteSize,l=e.data.binary===!0,u=e.data.truncated===!0,d=e.data.mimeType==="application/pdf"||n.toLowerCase().endsWith(".pdf"),m=l||d,[f,h]=I(r??""),[v,x]=I(!r&&!!n&&!m),[g,y]=I(null),[E,D]=I(0);B(()=>{if(!n)return;if(m){x(!1);return}if(r!==void 0){h(r),x(!1);return}let k=!1;return x(!0),y(null),gi(n).then(({content:V})=>{if(k)return;if(!V&&V!==""){y("File not found"),x(!1);return}h(V),x(!1);let ge=V.split(`
|
|
94
|
+
`).length;ie(e.id,{fileContent:V,lineCount:ge}),mt(e.id,{data:{fileContent:V,lineCount:ge}})}).catch(()=>{if(!k)y("Failed to load file"),x(!1)}),()=>{k=!0}},[n,r,m]),B(()=>{if(r!==void 0&&r!==f)h(r)},[r]);let N=H(()=>{if(!n)return;if(m){D((k)=>k+1);return}x(!0),y(null),ie(e.id,{fileContent:void 0}),mt(e.id,{data:{fileContent:void 0}}),gi(n).then(({content:k})=>{h(k),x(!1);let V=k.split(`
|
|
95
|
+
`).length,ge=new Date().toISOString();ie(e.id,{fileContent:k,lineCount:V,updatedAt:ge}),mt(e.id,{data:{fileContent:k,lineCount:V,updatedAt:ge}})}).catch(()=>{y("Failed to reload"),x(!1)})},[n,e.id,m]),b=wC(n),T=f.split(`
|
|
96
|
+
`),w=`${String(T.length).length+1}ch`,_=Vy(n),P=Se(()=>{if(!_||m||!f)return null;let k=Gy(f,_);return k.header.length>=2?k:null},[f,_,m]),q=`/api/canvas/file-bytes?nodeId=${encodeURIComponent(e.id)}${E?`&v=${E}`:""}`,R=kt.value==="srcdoc",Z=m||P!==null,j=u?i("div",{class:"file-node-notice",children:["Showing the first ",Mu(f.length)," of ",Mu(c??f.length)]},void 0,!0,void 0,this):null;if(!n)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No file path set"},void 0,!1,void 0,this);return i("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:"var(--mono)",fontSize:t?"13px":"11px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",borderBottom:"1px solid var(--c-line)",flexShrink:0},children:[i("span",{style:{fontSize:"9px",padding:"1px 5px",background:"var(--c-accent-12)",color:"var(--c-accent)",borderRadius:"3px",fontWeight:600},children:b},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-text-soft)",fontSize:t?"12px":"10px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:n,children:n},void 0,!1,void 0,this),a!==void 0&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",flexShrink:0},children:[a," lines"]},void 0,!0,void 0,this),s&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",flexShrink:0},children:new Date(s).toLocaleTimeString()},void 0,!1,void 0,this),i("button",{type:"button",class:"ax-node-action",title:"Mark this file as AX evidence",onClick:(k)=>{k.stopPropagation(),eo(e,"ax.evidence.add",{kind:"file",title:n.split("/").pop()||n,ref:n},"Marked as evidence")},style:{background:"none",border:"none",color:"var(--c-muted)",cursor:"pointer",padding:"2px 4px",fontSize:"12px",flexShrink:0},children:i(_y,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",onClick:N,title:"Reload file",style:{background:"none",border:"none",color:"var(--c-muted)",cursor:"pointer",padding:"2px 4px",fontSize:"12px",flexShrink:0},children:i(va,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{flex:1,minHeight:0,overflow:Z?"hidden":"auto",padding:Z?0:"8px 0",background:t?"var(--c-panel-soft)":void 0,borderRadius:t?"0 0 8px 8px":void 0},children:[d&&(R?i("div",{class:"file-node-placeholder",children:[i("div",{children:"PDF preview is unavailable in this embedded host."},void 0,!1,void 0,this),i("a",{class:"file-node-link",href:q,target:"_blank",rel:"noreferrer",children:"Open PDF"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i("iframe",{src:q,title:o,sandbox:"",style:{width:"100%",height:"100%",border:"none",display:"block"}},void 0,!1,void 0,this)),!d&&l&&i("div",{class:"file-node-placeholder",children:[i("div",{class:"file-node-placeholder-name",children:o},void 0,!1,void 0,this),i("div",{children:"Binary file"},void 0,!1,void 0,this),c!==void 0&&i("div",{children:Mu(c)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!m&&i(ue,{children:[v&&i("div",{style:{color:"var(--c-dim)",padding:"12px",fontStyle:"italic"},children:"Loading…"},void 0,!1,void 0,this),g&&i("div",{style:{color:"var(--c-danger)",padding:"12px"},children:g},void 0,!1,void 0,this),!v&&!g&&(P?i("div",{class:"file-table-shell",children:[j,P.rows.length>$u&&i("div",{class:"file-node-notice",children:["Showing ",$u," of ",P.rows.length," rows"]},void 0,!0,void 0,this),i("div",{class:"file-table-wrap",children:i("table",{class:"file-table",children:[i("thead",{children:i("tr",{children:P.header.map((k,V)=>i("th",{children:k},V,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("tbody",{children:P.rows.slice(0,$u).map((k,V)=>i("tr",{children:k.map((ge,Ue)=>i("td",{children:ge},Ue,!1,void 0,this))},V,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i(ue,{children:[j,i("pre",{style:{margin:0,lineHeight:"1.55",tabSize:2},children:T.map((k,V)=>i("div",{style:{display:"flex",minHeight:"1.55em"},children:[i("span",{style:{width:w,minWidth:w,textAlign:"right",color:"var(--c-dim)",paddingRight:"12px",paddingLeft:"10px",userSelect:"none",flexShrink:0,opacity:0.6},children:V+1},void 0,!1,void 0,this),i("code",{style:{color:"var(--c-text)",whiteSpace:"pre",paddingRight:"10px"},children:k||`
|
|
97
|
+
`},void 0,!1,void 0,this)]},V,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var kC=new Set(["title","__type","content","strictSize","arrangeLocked"]);function za({node:e}){let t=e.data,o=(typeof t.content==="string"?t.content:"").split(/\r\n|\r|\n|\\n/).map((s)=>s.trimEnd()).filter((s)=>s.length>0),r=Object.entries(t).filter(([s])=>!kC.has(s));if(o.length===0&&r.length===0)return i("div",{style:{color:"var(--c-dim)",fontSize:"12px",fontStyle:"italic"},children:"No ledger data"},void 0,!1,void 0,this);return i("div",{style:{display:"flex",flexDirection:"column",gap:"4px",fontSize:"12px"},children:[o.length>0&&i("div",{style:{display:"flex",flexDirection:"column"},children:o.map((s,a)=>i("div",{style:{padding:"3px 0",borderBottom:a<o.length-1?"1px solid rgba(45,55,90,0.3)":"none",color:"var(--c-text)",fontFamily:"var(--mono)",fontSize:"11px",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:s},a,!1,void 0,this))},void 0,!1,void 0,this),r.map(([s,a])=>i("div",{style:{display:"flex",justifyContent:"space-between",gap:"8px",padding:"3px 0",borderBottom:"1px solid rgba(45,55,90,0.3)"},children:[i("span",{style:{color:"var(--c-muted)",fontSize:"11px",flexShrink:0},children:s.replace(/([A-Z])/g," $1").replace(/^./,(c)=>c.toUpperCase())},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-text)",fontFamily:"var(--mono)",fontSize:"11px",textAlign:"right",wordBreak:"break-word"},children:typeof a==="object"?JSON.stringify(a):String(a??"—")},void 0,!1,void 0,this)]},s,!0,void 0,this))]},void 0,!0,void 0,this)}var Si=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),ab=Si?"⌘":"Ctrl";function Ve(e){return Si?`${ab}${e}`:`${ab}+${e}`}function Pa(e,t){let{selectionStart:n,selectionEnd:o,value:r}=e,s=r.slice(n,o),a=r.slice(Math.max(0,n-t.length),n),c=r.slice(o,o+t.length);if(a===t&&c===t){let l=r.slice(0,n-t.length)+s+r.slice(o+t.length);gn(e,l,n-t.length,o-t.length);return}if(s){let l=r.slice(0,n)+t+s+t+r.slice(o);gn(e,l,n+t.length,o+t.length)}else{let l=r.slice(0,n)+t+t+r.slice(o);gn(e,l,n+t.length,n+t.length)}}function Ci(e,t){let{selectionStart:n,selectionEnd:o,value:r}=e,s=r.lastIndexOf(`
|
|
98
98
|
`,n-1)+1,a=r.indexOf(`
|
|
99
|
-
`,o),c=a===-1?r.length:a,l=r.slice(s,c);if(l.startsWith(t)){let p=r.slice(0,s)+l.slice(t.length)+r.slice(c);
|
|
99
|
+
`,o),c=a===-1?r.length:a,l=r.slice(s,c);if(l.startsWith(t)){let p=r.slice(0,s)+l.slice(t.length)+r.slice(c);gn(e,p,Math.max(s,n-t.length),Math.max(s,o-t.length));return}let u=r.slice(0,s)+t+r.slice(s);gn(e,u,n+t.length,o+t.length)}function SC(e){let{selectionStart:t,selectionEnd:n,value:o}=e,r=o.slice(t,n);if(r){let s=o.slice(0,t)+`[${r}](url)`+o.slice(n),a=t+r.length+3;gn(e,s,a,a+3)}else{let s=o.slice(0,t)+"[text](url)"+o.slice(n);gn(e,s,t+1,t+5)}}function CC(e){let{selectionStart:t,selectionEnd:n,value:o}=e,r=o.slice(t,n),s="```";if(r){let a=o.slice(0,t)+`\`\`\`
|
|
100
100
|
${r}
|
|
101
|
-
\`\`\``+o.slice(n);
|
|
101
|
+
\`\`\``+o.slice(n);gn(e,a,t+3+1,t+3+1+r.length)}else{let a=o.slice(0,t)+"```\n\n```"+o.slice(n);gn(e,a,t+3+1,t+3+1)}}function cb(e,t){let{selectionStart:n,selectionEnd:o,value:r}=e,s=r.lastIndexOf(`
|
|
102
102
|
`,n-1)+1,a=r.indexOf(`
|
|
103
103
|
`,o),c=a===-1?r.length:a,l=r.slice(s,c).split(`
|
|
104
|
-
`),u=n,p=o,d=l.map((
|
|
105
|
-
`)+r.slice(c);
|
|
106
|
-
`)t--;return e.substring(0,t)}function
|
|
104
|
+
`),u=n,p=o,d=l.map((f,h)=>{if(t){if(f.startsWith(" ")){if(h===0)u=Math.max(s,u-2);return p-=2,f.slice(2)}else if(f.startsWith("\t")){if(h===0)u=Math.max(s,u-1);return p-=1,f.slice(1)}return f}else{if(h===0)u+=2;return p+=2," "+f}}),m=r.slice(0,s)+d.join(`
|
|
105
|
+
`)+r.slice(c);gn(e,m,u,p)}function gn(e,t,n,o){let r=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set;if(r)r.call(e,t);else e.value=t;e.selectionStart=n,e.selectionEnd=o,e.dispatchEvent(new Event("input",{bubbles:!0}))}var Na=[{key:"bold",label:"Bold",icon:"B",shortcut:"b",action:(e)=>Pa(e,"**")},{key:"italic",label:"Italic",icon:"I",shortcut:"i",action:(e)=>Pa(e,"_")},{key:"strike",label:"Strikethrough",icon:"S",shortcut:"u",action:(e)=>Pa(e,"~~")},{key:"code",label:"Inline code",icon:"`",shortcut:"e",action:(e)=>Pa(e,"`")},{key:"link",label:"Link",icon:"\uD83D\uDD17",shortcut:"k",action:SC},{key:"h1",label:"Heading 1",icon:"H1",action:(e)=>Ci(e,"# ")},{key:"h2",label:"Heading 2",icon:"H2",action:(e)=>Ci(e,"## ")},{key:"quote",label:"Blockquote",icon:"❝",action:(e)=>Ci(e,"> ")},{key:"ul",label:"Bullet list",icon:"•",action:(e)=>Ci(e,"- ")},{key:"ol",label:"Numbered list",icon:"1.",action:(e)=>Ci(e,"1. ")},{key:"codeblock",label:"Code block",icon:"{ }",action:CC}];function lb(e,t){if(!(e.metaKey||e.ctrlKey))return!1;let n=Na.find((o)=>o.shortcut===e.key);if(!n)return!1;return e.preventDefault(),n.action(t),!0}function ub(e){if(e.selectionStart===e.selectionEnd)return null;let t=document.createElement("div"),n=getComputedStyle(e),o=["fontFamily","fontSize","fontWeight","lineHeight","letterSpacing","wordSpacing","textIndent","whiteSpace","wordWrap","overflowWrap","paddingTop","paddingRight","paddingBottom","paddingLeft","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","boxSizing","width"];for(let p of o)t.style[p]=n[p];t.style.position="absolute",t.style.visibility="hidden",t.style.overflow="hidden",t.style.height="auto",t.style.top="0",t.style.left="0";let r=e.value,s=document.createTextNode(r.slice(0,e.selectionStart)),a=document.createElement("span");a.textContent=r.slice(e.selectionStart,e.selectionEnd)||".",t.appendChild(s),t.appendChild(a),t.appendChild(document.createTextNode(r.slice(e.selectionEnd))),document.body.appendChild(t);let c=a.getBoundingClientRect(),l=t.getBoundingClientRect(),u=e.getBoundingClientRect();return document.body.removeChild(t),{top:u.top+(c.top-l.top)-e.scrollTop,left:u.left+(c.left-l.left)-e.scrollLeft,width:c.width}}var TC=Na.filter((e)=>e.shortcut),IC=Na.filter((e)=>!e.shortcut);function Lu({textareaRef:e}){let[t,n]=I(!1),[o,r]=I({top:0,left:0}),s=z(null),a=z(null),c=H(()=>{let u=e.current;if(!u||u.selectionStart===u.selectionEnd){n(!1);return}let p=ub(u);if(!p){n(!1);return}let d=380,m=Math.max(8,Math.min(p.left+p.width/2-d/2,window.innerWidth-d-8));r({top:p.top-40,left:m}),n(!0)},[e]);B(()=>{let u=e.current;if(!u)return;let p=()=>{if(a.current)clearTimeout(a.current);a.current=setTimeout(c,50)},d=()=>{a.current=setTimeout(()=>n(!1),200)},m=(f)=>{if(f.shiftKey||f.key.startsWith("Arrow"))p()};return u.addEventListener("select",p),u.addEventListener("mouseup",p),u.addEventListener("keyup",m),u.addEventListener("blur",d),()=>{if(u.removeEventListener("select",p),u.removeEventListener("mouseup",p),u.removeEventListener("keyup",m),u.removeEventListener("blur",d),a.current)clearTimeout(a.current)}},[e,c]);let l=H((u)=>{let p=e.current;if(p)u.action(p),p.focus()},[e]);if(!t)return null;return i("div",{ref:s,class:"md-format-bar",style:{top:`${o.top}px`,left:`${o.left}px`},onMouseDown:(u)=>u.preventDefault(),children:[TC.map((u)=>i("button",{type:"button",class:`md-format-btn md-format-btn-${u.key}`,title:`${u.label} (${Ve(u.shortcut.toUpperCase())})`,onClick:()=>l(u),children:u.icon},u.key,!1,void 0,this)),i("div",{class:"md-format-divider"},void 0,!1,void 0,this),IC.map((u)=>i("button",{type:"button",class:`md-format-btn md-format-btn-${u.key}`,title:u.label,onClick:()=>l(u),children:u.icon},u.key,!1,void 0,this))]},void 0,!0,void 0,this)}var jb=fk(Tb(),1);function ZC(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)if(Object.prototype.hasOwnProperty.call(n,o))e[o]=n[o]}return e}function Zu(e,t){return Array(t+1).join(e)}function Ab(e){return e.replace(/^\n*/,"")}function zb(e){var t=e.length;while(t>0&&e[t-1]===`
|
|
106
|
+
`)t--;return e.substring(0,t)}function Pb(e){return zb(Ab(e))}var UC=["ADDRESS","ARTICLE","ASIDE","AUDIO","BLOCKQUOTE","BODY","CANVAS","CENTER","DD","DIR","DIV","DL","DT","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","FRAMESET","H1","H2","H3","H4","H5","H6","HEADER","HGROUP","HR","HTML","ISINDEX","LI","MAIN","MENU","NAV","NOFRAMES","NOSCRIPT","OL","OUTPUT","P","PRE","SECTION","TABLE","TBODY","TD","TFOOT","TH","THEAD","TR","UL"];function Uu(e){return qu(e,UC)}var Nb=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];function Rb(e){return qu(e,Nb)}function qC(e){return Mb(e,Nb)}var $b=["A","TABLE","THEAD","TBODY","TFOOT","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"];function WC(e){return qu(e,$b)}function VC(e){return Mb(e,$b)}function qu(e,t){return t.indexOf(e.nodeName)>=0}function Mb(e,t){return e.getElementsByTagName&&t.some(function(n){return e.getElementsByTagName(n).length})}var GC=[[/\\/g,"\\\\"],[/\*/g,"\\*"],[/^-/g,"\\-"],[/^\+ /g,"\\+ "],[/^(=+)/g,"\\$1"],[/^(#{1,6}) /g,"\\$1 "],[/`/g,"\\`"],[/^~~~/g,"\\~~~"],[/\[/g,"\\["],[/\]/g,"\\]"],[/^>/g,"\\>"],[/_/g,"\\_"],[/^(\d+)\. /g,"$1\\. "]];function Lb(e){return GC.reduce(function(t,n){return t.replace(n[0],n[1])},e)}var St={};St.paragraph={filter:"p",replacement:function(e){return`
|
|
107
107
|
|
|
108
108
|
`+e+`
|
|
109
109
|
|
|
110
110
|
`}};St.lineBreak={filter:"br",replacement:function(e,t,n){return n.br+`
|
|
111
|
-
`}};St.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,t,n){var o=Number(t.nodeName.charAt(1));if(n.headingStyle==="setext"&&o<3){var r=
|
|
111
|
+
`}};St.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,t,n){var o=Number(t.nodeName.charAt(1));if(n.headingStyle==="setext"&&o<3){var r=Zu(o===1?"=":"-",e.length);return`
|
|
112
112
|
|
|
113
113
|
`+e+`
|
|
114
114
|
`+r+`
|
|
115
115
|
|
|
116
116
|
`}else return`
|
|
117
117
|
|
|
118
|
-
`+
|
|
118
|
+
`+Zu("#",o)+" "+e+`
|
|
119
119
|
|
|
120
|
-
`}};St.blockquote={filter:"blockquote",replacement:function(e){return e=
|
|
120
|
+
`}};St.blockquote={filter:"blockquote",replacement:function(e){return e=Pb(e).replace(/^/gm,"> "),`
|
|
121
121
|
|
|
122
122
|
`+e+`
|
|
123
123
|
|
|
@@ -126,7 +126,7 @@ ${r}
|
|
|
126
126
|
|
|
127
127
|
`+e+`
|
|
128
128
|
|
|
129
|
-
`}};St.listItem={filter:"li",replacement:function(e,t,n){var o=n.bulletListMarker+" ",r=t.parentNode;if(r.nodeName==="OL"){var s=r.getAttribute("start"),a=Array.prototype.indexOf.call(r.children,t);o=(s?Number(s)+a:a+1)+". "}var c=/\n$/.test(e);return e=
|
|
129
|
+
`}};St.listItem={filter:"li",replacement:function(e,t,n){var o=n.bulletListMarker+" ",r=t.parentNode;if(r.nodeName==="OL"){var s=r.getAttribute("start"),a=Array.prototype.indexOf.call(r.children,t);o=(s?Number(s)+a:a+1)+". "}var c=/\n$/.test(e);return e=Pb(e)+(c?`
|
|
130
130
|
`:""),e=e.replace(/\n/gm,`
|
|
131
131
|
`+" ".repeat(o.length)),o+e+(t.nextSibling?`
|
|
132
132
|
`:"")}};St.indentedCodeBlock={filter:function(e,t){return t.codeBlockStyle==="indented"&&e.nodeName==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"},replacement:function(e,t,n){return`
|
|
@@ -134,7 +134,7 @@ ${r}
|
|
|
134
134
|
`+t.firstChild.textContent.replace(/\n/g,`
|
|
135
135
|
`)+`
|
|
136
136
|
|
|
137
|
-
`}};St.fencedCodeBlock={filter:function(e,t){return t.codeBlockStyle==="fenced"&&e.nodeName==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"},replacement:function(e,t,n){var o=t.firstChild.getAttribute("class")||"",r=(o.match(/language-(\S+)/)||[null,""])[1],s=t.firstChild.textContent,a=n.fence.charAt(0),c=3,l=new RegExp("^"+a+"{3,}","gm"),u;while(u=l.exec(s))if(u[0].length>=c)c=u[0].length+1;var p=
|
|
137
|
+
`}};St.fencedCodeBlock={filter:function(e,t){return t.codeBlockStyle==="fenced"&&e.nodeName==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"},replacement:function(e,t,n){var o=t.firstChild.getAttribute("class")||"",r=(o.match(/language-(\S+)/)||[null,""])[1],s=t.firstChild.textContent,a=n.fence.charAt(0),c=3,l=new RegExp("^"+a+"{3,}","gm"),u;while(u=l.exec(s))if(u[0].length>=c)c=u[0].length+1;var p=Zu(a,c);return`
|
|
138
138
|
|
|
139
139
|
`+p+r+`
|
|
140
140
|
`+s.replace(/\n$/,"")+`
|
|
@@ -144,13 +144,13 @@ ${r}
|
|
|
144
144
|
|
|
145
145
|
`+n.hr+`
|
|
146
146
|
|
|
147
|
-
`}};St.inlineLink={filter:function(e,t){return t.linkStyle==="inlined"&&e.nodeName==="A"&&e.getAttribute("href")},replacement:function(e,t){var n=
|
|
147
|
+
`}};St.inlineLink={filter:function(e,t){return t.linkStyle==="inlined"&&e.nodeName==="A"&&e.getAttribute("href")},replacement:function(e,t){var n=Wu(t.getAttribute("href")),o=Vu(Ra(t.getAttribute("title"))),r=o?' "'+o+'"':"";return"["+e+"]("+n+r+")"}};St.referenceLink={filter:function(e,t){return t.linkStyle==="referenced"&&e.nodeName==="A"&&e.getAttribute("href")},replacement:function(e,t,n){var o=Wu(t.getAttribute("href")),r=Ra(t.getAttribute("title"));if(r)r=' "'+Vu(r)+'"';var s,a;switch(n.linkReferenceStyle){case"collapsed":s="["+e+"][]",a="["+e+"]: "+o+r;break;case"shortcut":s="["+e+"]",a="["+e+"]: "+o+r;break;default:var c=this.references.length+1;s="["+e+"]["+c+"]",a="["+c+"]: "+o+r}return this.references.push(a),s},references:[],append:function(e){var t="";if(this.references.length)t=`
|
|
148
148
|
|
|
149
149
|
`+this.references.join(`
|
|
150
150
|
`)+`
|
|
151
151
|
|
|
152
|
-
`,this.references=[];return t}};St.emphasis={filter:["em","i"],replacement:function(e,t,n){if(!e.trim())return"";return n.emDelimiter+e+n.emDelimiter}};St.strong={filter:["strong","b"],replacement:function(e,t,n){if(!e.trim())return"";return n.strongDelimiter+e+n.strongDelimiter}};St.code={filter:function(e){var t=e.previousSibling||e.nextSibling,n=e.parentNode.nodeName==="PRE"&&!t;return e.nodeName==="CODE"&&!n},replacement:function(e){if(!e)return"";e=e.replace(/\r?\n|\r/g," ");var t=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"",n="`",o=e.match(/`+/gm)||[];while(o.indexOf(n)!==-1)n=n+"`";return n+t+e+t+n}};St.image={filter:"img",replacement:function(e,t){var n
|
|
153
|
-
`):""}function
|
|
152
|
+
`,this.references=[];return t}};St.emphasis={filter:["em","i"],replacement:function(e,t,n){if(!e.trim())return"";return n.emDelimiter+e+n.emDelimiter}};St.strong={filter:["strong","b"],replacement:function(e,t,n){if(!e.trim())return"";return n.strongDelimiter+e+n.strongDelimiter}};St.code={filter:function(e){var t=e.previousSibling||e.nextSibling,n=e.parentNode.nodeName==="PRE"&&!t;return e.nodeName==="CODE"&&!n},replacement:function(e){if(!e)return"";e=e.replace(/\r?\n|\r/g," ");var t=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"",n="`",o=e.match(/`+/gm)||[];while(o.indexOf(n)!==-1)n=n+"`";return n+t+e+t+n}};St.image={filter:"img",replacement:function(e,t){var n=Lb(Ra(t.getAttribute("alt"))),o=Wu(t.getAttribute("src")||""),r=Ra(t.getAttribute("title")),s=r?' "'+Vu(r)+'"':"";return o?"":""}};function Ra(e){return e?e.replace(/(\n+\s*)+/g,`
|
|
153
|
+
`):""}function Wu(e){var t=e.replace(/([<>()])/g,"\\$1");return t.indexOf(" ")>=0?"<"+t+">":t}function Vu(e){return e.replace(/"/g,"\\\"")}function Ob(e){this.options=e,this._keep=[],this._remove=[],this.blankRule={replacement:e.blankReplacement},this.keepReplacement=e.keepReplacement,this.defaultRule={replacement:e.defaultReplacement},this.array=[];for(var t in e.rules)this.array.push(e.rules[t])}Ob.prototype={add:function(e,t){this.array.unshift(t)},keep:function(e){this._keep.unshift({filter:e,replacement:this.keepReplacement})},remove:function(e){this._remove.unshift({filter:e,replacement:function(){return""}})},forNode:function(e){if(e.isBlank)return this.blankRule;var t;if(t=Bu(this.array,e,this.options))return t;if(t=Bu(this._keep,e,this.options))return t;if(t=Bu(this._remove,e,this.options))return t;return this.defaultRule},forEach:function(e){for(var t=0;t<this.array.length;t++)e(this.array[t],t)}};function Bu(e,t,n){for(var o=0;o<e.length;o++){var r=e[o];if(XC(r,t,n))return r}return}function XC(e,t,n){var o=e.filter;if(typeof o==="string"){if(o===t.nodeName.toLowerCase())return!0}else if(Array.isArray(o)){if(o.indexOf(t.nodeName.toLowerCase())>-1)return!0}else if(typeof o==="function"){if(o.call(e,t,n))return!0}else throw TypeError("`filter` needs to be a string, array, or function")}function JC(e){var{element:t,isBlock:n,isVoid:o}=e,r=e.isPre||function(d){return d.nodeName==="PRE"};if(!t.firstChild||r(t))return;var s=null,a=!1,c=null,l=Ib(c,t,r);while(l!==t){if(l.nodeType===3||l.nodeType===4){var u=l.data.replace(/[ \r\n\t]+/g," ");if((!s||/ $/.test(s.data))&&!a&&u[0]===" ")u=u.substr(1);if(!u){l=Hu(l);continue}l.data=u,s=l}else if(l.nodeType===1){if(n(l)||l.nodeName==="BR"){if(s)s.data=s.data.replace(/ $/,"");s=null,a=!1}else if(o(l)||r(l))s=null,a=!0;else if(s)a=!1}else{l=Hu(l);continue}var p=Ib(c,l,r);c=l,l=p}if(s){if(s.data=s.data.replace(/ $/,""),!s.data)Hu(s)}}function Hu(e){var t=e.nextSibling||e.parentNode;return e.parentNode.removeChild(e),t}function Ib(e,t,n){if(e&&e.parentNode===t||n(t))return t.nextSibling||t.parentNode;return t.firstChild||t.nextSibling||t.parentNode}var Gu=typeof window<"u"?window:{};function KC(){var e=Gu.DOMParser,t=!1;try{if(new e().parseFromString("","text/html"))t=!0}catch(n){}return t}function YC(){var e=function(){};if(QC())e.prototype.parseFromString=function(t){var n=new window.ActiveXObject("htmlfile");return n.designMode="on",n.open(),n.write(t),n.close(),n};else e.prototype.parseFromString=function(t){var n=document.implementation.createHTMLDocument("");return n.open(),n.write(t),n.close(),n};return e}function QC(){var e=!1;try{document.implementation.createHTMLDocument("").open()}catch(t){if(Gu.ActiveXObject)e=!0}return e}var eT=KC()?Gu.DOMParser:YC();function tT(e,t){var n;if(typeof e==="string"){var o=nT().parseFromString('<x-turndown id="turndown-root">'+e+"</x-turndown>","text/html");n=o.getElementById("turndown-root")}else n=e.cloneNode(!0);return JC({element:n,isBlock:Uu,isVoid:Rb,isPre:t.preformattedCode?oT:null}),n}var ju;function nT(){return ju=ju||new eT,ju}function oT(e){return e.nodeName==="PRE"||e.nodeName==="CODE"}function rT(e,t){return e.isBlock=Uu(e),e.isCode=e.nodeName==="CODE"||e.parentNode.isCode,e.isBlank=iT(e),e.flankingWhitespace=sT(e,t),e}function iT(e){return!Rb(e)&&!WC(e)&&/^\s*$/i.test(e.textContent)&&!qC(e)&&!VC(e)}function sT(e,t){if(e.isBlock||t.preformattedCode&&e.isCode)return{leading:"",trailing:""};var n=aT(e.textContent);if(n.leadingAscii&&Eb("left",e,t))n.leading=n.leadingNonAscii;if(n.trailingAscii&&Eb("right",e,t))n.trailing=n.trailingNonAscii;return{leading:n.leading,trailing:n.trailing}}function aT(e){var t=e.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);return{leading:t[1],leadingAscii:t[2],leadingNonAscii:t[3],trailing:t[4],trailingNonAscii:t[5],trailingAscii:t[6]}}function Eb(e,t,n){var o,r,s;if(e==="left")o=t.previousSibling,r=/ $/;else o=t.nextSibling,r=/^ /;if(o){if(o.nodeType===3)s=r.test(o.nodeValue);else if(n.preformattedCode&&o.nodeName==="CODE")s=!1;else if(o.nodeType===1&&!Uu(o))s=r.test(o.textContent)}return s}var cT=Array.prototype.reduce;function Ti(e){if(!(this instanceof Ti))return new Ti(e);var t={rules:St,headingStyle:"setext",hr:"* * *",bulletListMarker:"*",codeBlockStyle:"indented",fence:"```",emDelimiter:"_",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",br:" ",preformattedCode:!1,blankReplacement:function(n,o){return o.isBlock?`
|
|
154
154
|
|
|
155
155
|
`:""},keepReplacement:function(n,o){return o.isBlock?`
|
|
156
156
|
|
|
@@ -160,15 +160,15 @@ ${r}
|
|
|
160
160
|
|
|
161
161
|
`+n+`
|
|
162
162
|
|
|
163
|
-
`:n}};this.options=
|
|
163
|
+
`:n}};this.options=ZC({},t,e),this.rules=new Ob(this.options)}Ti.prototype={turndown:function(e){if(!dT(e))throw TypeError(e+" is not a string, or an element/document/fragment node.");if(e==="")return"";var t=Db.call(this,new tT(e,this.options));return lT.call(this,t)},use:function(e){if(Array.isArray(e))for(var t=0;t<e.length;t++)this.use(e[t]);else if(typeof e==="function")e(this);else throw TypeError("plugin must be a Function or an Array of Functions");return this},addRule:function(e,t){return this.rules.add(e,t),this},keep:function(e){return this.rules.keep(e),this},remove:function(e){return this.rules.remove(e),this},escape:function(e){return Lb(e)}};function Db(e){var t=this;return cT.call(e.childNodes,function(n,o){o=new rT(o,t.options);var r="";if(o.nodeType===3)r=o.isCode?o.nodeValue:t.escape(o.nodeValue);else if(o.nodeType===1)r=uT.call(t,o);return Fb(n,r)},"")}function lT(e){var t=this;return this.rules.forEach(function(n){if(typeof n.append==="function")e=Fb(e,n.append(t.options))}),e.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}function uT(e){var t=this.rules.forNode(e),n=Db.call(this,e),o=e.flankingWhitespace;if(o.leading||o.trailing)n=n.trim();return o.leading+t.replacement(n,e,this.options)+o.trailing}function Fb(e,t){var n=zb(e),o=Ab(t),r=Math.max(e.length-n.length,t.length-o.length),s=`
|
|
164
164
|
|
|
165
|
-
`.substring(0,r);return n+s+o}function sT(e){return e!=null&&(typeof e==="string"||e.nodeType&&(e.nodeType===1||e.nodeType===9||e.nodeType===11))}function Ra(){let e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0).cloneRange():null;Lt("Link URL","https://example.com").then((n)=>{if(!n)return;let o=n.trim().toLowerCase();if(o.startsWith("javascript:")||o.startsWith("data:"))return;if(t){let r=window.getSelection();r?.removeAllRanges(),r?.addRange(t)}document.execCommand("createLink",!1,n)})}function Db(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);if(t.collapsed)return;let n=t.toString(),o=document.createElement("code");o.textContent=n,t.deleteContents(),t.insertNode(o);let r=document.createRange();r.setStartAfter(o),r.setEndAfter(o),e.removeAllRanges(),e.addRange(r)}var $a=8,aT=[{kind:"exec",command:"bold",icon:"B",title:`Bold (${We("B")})`},{kind:"exec",command:"italic",icon:"I",title:`Italic (${We("I")})`},{kind:"exec",command:"strikeThrough",icon:"S",title:"Strikethrough"},{kind:"code",icon:"{ }",title:"Inline code",dividerBefore:!0},{kind:"block",tag:"H1",icon:"H1",title:"Heading 1",dividerBefore:!0},{kind:"block",tag:"H2",icon:"H2",title:"Heading 2"},{kind:"block",tag:"H3",icon:"H3",title:"Heading 3"},{kind:"block",tag:"P",icon:"¶",title:"Paragraph"},{kind:"block",tag:"BLOCKQUOTE",icon:"❝",title:"Quote",dividerBefore:!0},{kind:"exec",command:"insertUnorderedList",icon:"•",title:"Bullet list"},{kind:"exec",command:"insertOrderedList",icon:"1.",title:"Numbered list"},{kind:"link",icon:"\uD83D\uDD17",title:`Link (${We("K")})`,dividerBefore:!0}];function cT(e){switch(e.kind){case"exec":document.execCommand(e.command);return;case"block":document.execCommand("formatBlock",!1,e.tag);return;case"code":Db();return;case"link":Ra();return}}function Fb({hostRef:e,onChange:t}){let[n,o]=I(!1),[r,s]=I({top:0,left:0}),[a,c]=I(0),l=R(null),u=R(null),p=H(()=>{let m=e.current;if(!m){o(!1);return}let h=window.getSelection();if(!h||h.rangeCount===0||h.isCollapsed){o(!1);return}let v=h.getRangeAt(0);if(!m.contains(v.commonAncestorContainer)){o(!1);return}let x=v.getBoundingClientRect();if(x.width===0&&x.height===0){o(!1);return}let g=a||420,y=Math.max($a,Math.min(x.left+x.width/2-g/2,window.innerWidth-g-$a)),E=Math.max($a,x.top-$a-36);s({top:E,left:y}),o(!0)},[e,a]),d=H(()=>{if(u.current!==null)return;u.current=requestAnimationFrame(()=>{u.current=null,p()})},[p]);B(()=>(document.addEventListener("selectionchange",d),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{if(document.removeEventListener("selectionchange",d),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d),u.current!==null)cancelAnimationFrame(u.current)}),[d]),Bn(()=>{if(!n)return;let m=l.current;if(!m)return;let h=m.getBoundingClientRect().width;if(h&&Math.abs(h-a)>1)c(h)},[n,a]);let f=H((m)=>{cT(m),t(),p()},[t,p]);if(!n)return null;return i("div",{ref:l,class:"md-inline-format-bar",style:{top:`${r.top}px`,left:`${r.left}px`},onMouseDown:(m)=>m.preventDefault(),children:aT.flatMap((m,h)=>{let v=i("button",{type:"button",class:"md-inline-format-btn",title:m.title,onClick:()=>f(m),children:m.icon},`btn-${h}`,!1,void 0,this);return m.dividerBefore?[i("span",{class:"md-inline-format-divider"},`div-${h}`,!1,void 0,this),v]:[v]})},void 0,!1,void 0,this)}var Ku=null;function lT(){if(Ku)return Ku;let e=new ki({headingStyle:"atx",codeBlockStyle:"fenced",emDelimiter:"*",bulletListMarker:"-"});return e.use(Bb.gfm),Ku=e,e}function Hb({initialHtml:e,className:t,onChange:n,onSave:o}){let r=R(null),s=R(e);B(()=>{let f=r.current;if(!f)return;f.innerHTML=s.current;for(let m of f.querySelectorAll('input[type="checkbox"][disabled]'))m.removeAttribute("disabled")},[]);let a=H(()=>{let f=r.current;if(!f)return"";return lT().turndown(f.innerHTML)},[]),c=H(()=>{n(a())},[n,a]),l=H(()=>{let f=r.current;if(!f||!f.isConnected||f.innerHTML==="")return;o?.(a())},[o,a]),u=H((f)=>{if(!(f.metaKey||f.ctrlKey))return;if(f.key==="s"){f.preventDefault(),l();return}if(f.key==="b"){f.preventDefault(),document.execCommand("bold"),c();return}if(f.key==="i"){f.preventDefault(),document.execCommand("italic"),c();return}if(f.key==="k")f.preventDefault(),Ra(),c()},[c,l]),p=H((f)=>{let m=f.target;if(m instanceof HTMLInputElement&&m.type==="checkbox")m.toggleAttribute("checked",m.checked),c()},[c]),d=H((f)=>{let m=f.clipboardData?.getData("text/plain");if(m==null)return;f.preventDefault(),document.execCommand("insertText",!1,m),c()},[c]);return i(pe,{children:[i("div",{ref:r,class:t,contentEditable:!0,spellcheck:!1,onInput:c,onKeyDown:u,onPaste:d,onClick:p,onBlur:l},void 0,!1,void 0,this),i(Fb,{hostRef:r,onChange:c},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Yu({html:e,className:t,style:n,onTaskToggle:o}){let r=R(null),s=R(o);return s.current=o,B(()=>{let c=r.current;if(!c)return;if(c.replaceChildren(),!e)return;let l=document.createElement("template");if(l.innerHTML=e,c.append(l.content.cloneNode(!0)),s.current)for(let u of c.querySelectorAll('input[type="checkbox"][disabled]'))u.removeAttribute("disabled")},[e]),i("div",{ref:r,class:t,style:n,onClick:o?(c)=>{let l=s.current,u=r.current;if(!u||!l)return;let p=c.target,d=null;if(p instanceof HTMLInputElement&&p.type==="checkbox")d=p;else{let h=p.closest("li")?.querySelector(':scope > input[type="checkbox"]');if(h&&c.clientX<=h.getBoundingClientRect().right+6)d=h}if(!d)return;c.stopPropagation();let f=[...u.querySelectorAll('input[type="checkbox"]')].indexOf(d);if(f>=0)l(f)}:void 0},void 0,!1,void 0,this)}function uT(e,t){let n=-1;return e.replace(/^(\s*(?:[-*+]|\d+[.)])\s+\[)([ xX])(\])/gm,(o,r,s,a)=>{if(n+=1,n!==t)return o;return`${r}${s===" "?"x":" "}${a}`})}function Ma({node:e,expanded:t=!1}){let n=Ia(),o=e.data.path,[r,s]=I(""),[a,c]=I(""),[l,u]=I(!1),[p,d]=I(!1),[f,m]=I(!1),[h,v]=I(!1),x=R(null),g=R(null),y=R(""),E=R(null),L=e.data.reviewActive;B(()=>{let N=!1;return(async()=>{let Z;if(o){let S=await fi(o);if(N)return;Z=S.content}else if(e.data.content)Z=e.data.content;else{u(!0);return}s(Z);let j=await wn(Z);if(N)return;c(j),u(!0),ie(e.id,{content:Z,rendered:j})})(),()=>{N=!0}},[o,e.id,e.data.content]);let P=H(async(N)=>{let Z=N.target.value;s(Z),v(!0);let j=await wn(Z);c(j)},[]),b=H(async(N)=>{if(!o){let j=await wn(N);c(j),v(!1),ie(e.id,{content:N,rendered:j}),await pt(e.id,{content:N,data:{rendered:j}});return}m(!0);let Z=await Nv(o,N);if(m(!1),Z.ok){let j=await wn(N);c(j),v(!1),ie(e.id,{content:N,rendered:j,savedAt:Z.updatedAt}),await pt(e.id,{content:N,data:{rendered:j,savedAt:Z.updatedAt}})}},[o,e.id]),T=H(async()=>{if(!h)return;await b(r)},[h,r,b]),w=H((N)=>{if((N.metaKey||N.ctrlKey)&&N.key==="s"){N.preventDefault(),T();return}let Z=x.current;if(Z&&ab(N,Z))return;if(Z&&N.key==="Tab")N.preventDefault(),sb(Z,N.shiftKey)},[T]);E.current=b;let _=H((N)=>{if(s(N),v(!0),y.current=N,g.current!==null)window.clearTimeout(g.current);g.current=window.setTimeout(()=>{g.current=null,b(N)},800)},[b]),z=H((N)=>{if(s(N),y.current=N,g.current!==null)window.clearTimeout(g.current),g.current=null;b(N)},[b]);B(()=>()=>{if(g.current===null)return;window.clearTimeout(g.current),g.current=null;let N=E.current;if(N)N(y.current)},[e.id]);let U=L?i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-ok-10)",color:"var(--c-ok)",borderBottom:"1px solid var(--c-ok-20)",textTransform:"uppercase",letterSpacing:"0.05em",fontWeight:600},children:"Review active"},void 0,!1,void 0,this):null;if(p&&t)return i("div",{class:"md-editor-expanded",onKeyDown:w,children:[i("div",{class:"md-editor-toolbar",children:[i("button",{type:"button",class:"md-toolbar-btn",onClick:()=>d(!1),children:[i(Cy,{size:14},void 0,!1,void 0,this)," Back to document"]},void 0,!0,void 0,this),i("div",{style:{display:"flex",gap:"6px",alignItems:"center"},children:[o&&i("span",{class:"md-toolbar-path",children:o.split("/").pop()},void 0,!1,void 0,this),i("button",{type:"button",class:`md-toolbar-btn${h?" md-toolbar-btn-primary":""}`,onClick:T,disabled:!h||f,children:f?"Saving…":h?"Save":"Saved"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"md-editor-split",children:[i("div",{style:{flex:1,position:"relative",display:"flex",flexDirection:"column"},children:[i("textarea",{ref:x,value:r,onInput:P,spellcheck:!1},void 0,!1,void 0,this),i(Du,{textareaRef:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Yu,{html:a,className:"md-preview"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(p)return i("div",{class:"md-editor-split",style:{height:"100%"},onKeyDown:w,children:[i("div",{style:{flex:1,position:"relative",display:"flex",flexDirection:"column"},children:[i("textarea",{ref:x,value:r,onInput:P,spellcheck:!1},void 0,!1,void 0,this),i(Du,{textareaRef:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Yu,{html:a,className:"md-preview"},void 0,!1,void 0,this),i("div",{style:{position:"absolute",bottom:"8px",right:"8px",display:"flex",gap:"6px"},children:[i("button",{type:"button",onClick:()=>d(!1),style:{padding:"4px 10px",fontSize:"11px",background:"var(--c-input-bg)",border:"1px solid var(--c-line)",borderRadius:"6px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Document"},void 0,!1,void 0,this),i("button",{type:"button",onClick:T,disabled:!h||f,style:{padding:"4px 10px",fontSize:"11px",background:h?"var(--c-accent-25)":"var(--c-input-bg)",border:`1px solid ${h?"var(--c-accent)":"var(--c-line)"}`,borderRadius:"6px",color:h?"var(--c-text)":"var(--c-dim)",cursor:h?"pointer":"default"},children:f?"Saving…":h?"Save":"Saved"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(t)return i("div",{style:{height:"100%",position:"relative"},children:[U,i("div",{class:"md-reader",children:l?i(Hb,{initialHtml:a||"<p><br></p>",className:"md-reader-content md-reader-editable",onChange:_,onSave:z},e.id,!1,void 0,this):i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"24px"},children:"Loading…"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"md-edit-fab",onClick:()=>d(!0),children:"</> Source"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{class:"md-card-preview",children:[i("div",{class:"md-card-content",children:[U,i(Yu,{html:a,style:{padding:a?"0":"12px",color:a?void 0:"var(--c-dim)"},onTaskToggle:(N)=>{let Z=uT(r,N);if(Z!==r)z(Z)}},void 0,!1,void 0,this),!l&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"Loading…"},void 0,!1,void 0,this),l&&!a&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"Empty node"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.data.source&&typeof e.data.source==="object"&&"attachmentId"in e.data.source&&i("div",{class:"md-import-source",children:["Source material ·"," ",i("a",{href:`/api/canvas/attachments/${encodeURIComponent(String(e.data.source.attachmentId))}/bytes`,target:"_blank",rel:"noopener noreferrer",children:String(e.data.source.filename??"Original")},void 0,!1,void 0,this)," · ",String(e.data.source.reference??"Location not supplied")]},void 0,!0,void 0,this),i("div",{class:"md-card-actions",children:[n&&i("button",{type:"button",class:"md-readme-btn","aria-pressed":n.readmeNodeId===e.id,onClick:()=>void nb(n.id,n.readmeNodeId===e.id?null:e.id),children:n.readmeNodeId===e.id?"README":"Set as README"},void 0,!1,void 0,this),i("button",{type:"button",class:"md-card-edit",onClick:()=>Ut(e.id),children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Oa="pmx-canvas-ax",La="pmx-canvas-ax-ack",qt="pmx-canvas-html-node",Da="pmx-canvas-ext-app-alive",Qu="pmx-canvas-ext-app-paint-probe";function jb(e,t){switch(e){case"html":return typeof t.html==="string"&&t.html.length>0||typeof t.content==="string"&&t.content.length>0;case"mermaid":return typeof t.content==="string"&&t.content.trim().length>0;case"json-render":case"graph":return!0;case"mcp-app":return t.viewerType==="web-artifact"&&typeof t.path==="string"&&t.path.length>0||typeof t.url==="string"&&t.url.length>0;case"webpage":return typeof t.url==="string"&&t.url.length>0;default:return!1}}var ed="allow-scripts allow-popups allow-popups-to-escape-sandbox";function wr(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t<<5)+t+e.charCodeAt(n)|0;return(t>>>0).toString(36)}function Ci(e,t={}){let n=new URLSearchParams;if(n.set("theme",t.theme??tt.value),t.themeToken)n.set("themeToken",t.themeToken);if(t.present)n.set("present","1");if(t.presentToken)n.set("presentToken",t.presentToken);if(t.v)n.set("v",t.v);if(t.axToken)n.set("axToken",t.axToken);if(t.frameToken)n.set("frameToken",t.frameToken);return`/api/canvas/surface/${encodeURIComponent(e)}?${n.toString()}`}function Fa(e){return jb(e.type,e.data)}async function Ba(e){let t=Ci(e.id);if(!(await Dv(e.id,t)).opened)window.open(t,"_blank","noopener")}var Zb=30000;var td=80;var Ge=q(new Map),Sr=q(null),dT=480,pT=320,mT=650,Ti=new Map,_r=new Map,Ha=new Map,An=null;function nd(e){Ge.value=e,fT()}function od(e){let t=Ti.get(e);if(t)clearTimeout(t),Ti.delete(e)}function rd(e){let t=_r.get(e);if(t)clearTimeout(t),_r.delete(e)}function qb(e){if(od(e.id),rd(e.id),!Ge.value.has(e.id))Ha.set(e.id,Date.now());let t=new Map(Ge.value);t.set(e.id,{...e,phase:"forming"}),nd(t)}function Mo(e){if(od(e),rd(e),Ha.delete(e),!Ge.value.has(e))return;let t=new Map(Ge.value);t.delete(e),nd(t)}function Ub(e,t,n,o){let r=Ge.value.get(e);if(!r||r.phase===t)return;let s=new Map(Ge.value);s.set(e,{...r,phase:t,...o?{settledNodeId:o}:{}}),nd(s),od(e),Ti.set(e,setTimeout(()=>Mo(e),n+1500))}function Wb(e,t,n,o){rd(e);let r=Date.now()-(Ha.get(e)??0),s=Math.max(0,mT-r);if(s===0){Ub(e,t,n,o);return}_r.set(e,setTimeout(()=>{_r.delete(e),Ub(e,t,n,o)},s))}function Vb(e,t){Wb(e,"settling",dT,t)}function id(e){Wb(e,"dissolving",pT)}function ja(){for(let e of Ti.values())clearTimeout(e);Ti.clear();for(let e of _r.values())clearTimeout(e);if(_r.clear(),Ha.clear(),An)clearInterval(An),An=null;Sr.value=null,Ge.value=new Map}function fT(){if(An||Ge.value.size===0)return;An=setInterval(()=>{let e=Date.now();for(let t of Ge.value.values())if(t.phase==="forming"&&t.expiresAt<=e)id(t.id);if(Ge.value.size===0&&An)clearInterval(An),An=null},1000),An.unref?.()}function hT(e,t){try{let n=window.sessionStorage.getItem(e);if(n)return n;let o=t();return window.sessionStorage.setItem(e,o),o}catch{return t()}}var qa=hT("pmx-canvas-human-client",()=>`tab-${Math.random().toString(36).slice(2,8)}`);function gT(){try{let e=new URLSearchParams(window.location.search).get("name")?.trim();if(e)return window.localStorage.setItem("pmx-canvas-human-name",e),e;let t=window.localStorage.getItem("pmx-canvas-human-name")?.trim();if(t)return t}catch{}return`guest-${qa.slice(-4)}`}var Xb=q(gT()),Jb=q([]),Ei=Le(()=>Jb.value.filter((e)=>e.clientId!==qa)),Oo=q(new Map);function sd(e){if(!e||!Array.isArray(e.humans))return;Jb.value=e.humans}var kr=q(null),Wa=null,Kb=0,Ii=null;function Ua(e){Qt("humanPresence","/api/canvas/human-presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({clientId:qa,name:Xb.value,...e})})}function Gb(){Ii=null,Kb=Date.now(),Ua({cursor:Wa,grabbingNodeId:kr.value})}function Va(e){Wa=e;let t=Date.now()-Kb;if(t>=td){if(Ii)clearTimeout(Ii);Gb()}else if(!Ii)Ii=setTimeout(Gb,td-t)}function ad(e){kr.value=e,Ua({cursor:Wa,grabbingNodeId:e})}function vT(e,t){let n=new Map(Oo.value);n.set(e,t),Oo.value=n,setTimeout(()=>{let o=new Map(Oo.value);if(o.get(e)===t)o.delete(e),Oo.value=o},6000)}function Yb(e,t){let n=[...Ge.value.values()].filter((r)=>r.nodeId===e&&!r.auto&&r.phase==="forming");if(n.length===0)return;let o=Xb.value;vT(e,o);for(let r of n)Io({id:r.id,kind:r.kind,label:r.label,reason:`${o} took over “${t}” mid-edit — yield and requeue the change once it is released`}).then((s)=>{if(s)Mo(r.id)});Qt("yieldEvent","/api/canvas/ax/event",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({kind:"yield",summary:`${o} grabbed “${t}” mid-edit — agent yielded, change requeued`,nodeIds:[e],source:"browser"})})}var Za=null;function Qb(){Ua({cursor:Wa,grabbingNodeId:kr.value}),Za=setInterval(()=>Ua({grabbingNodeId:kr.value}),3000);let e=()=>{try{navigator.sendBeacon?.("/api/canvas/human-presence",new Blob([JSON.stringify({clientId:qa,left:!0})],{type:"application/json"}))}catch{}};return window.addEventListener("pagehide",e),()=>{if(Za)clearInterval(Za);Za=null,window.removeEventListener("pagehide",e)}}var yT={markdown:{width:360,height:180},board:{width:320,height:140},context:{width:360,height:180},file:{width:360,height:200},diff:{width:420,height:240},mermaid:{width:360,height:240},status:{width:280,height:120},ledger:{width:320,height:200},image:{width:240,height:180},html:{width:420,height:280},webpage:{width:420,height:280},"json-render":{width:420,height:280},graph:{width:420,height:280},"mcp-app":{width:480,height:320}};function ex(e){return yT[e]}function tx(e,t,n,o,r){return e.x<o.position.x+o.size.width+r&&e.x+t+r>o.position.x&&e.y<o.position.y+o.size.height+r&&e.y+n+r>o.position.y}function bT(e,t,n,o,r){return o.some((s)=>tx(e,t,n,s,r))}function Ga(e,t,n,o,r){return o.find((s)=>tx(e,t,n,s,r))}function Xa(e,t,n,o=24){if(e.length===0)return{x:40,y:80};let r=e[e.length-1],s={x:r.position.x+r.size.width+o,y:r.position.y};if(!bT(s,t,n,e,o))return s;let a=40,c=80,l=3000,u=c;for(let d=0;d<20;d++){let f=a;while(f+t<l){let v=Ga({x:f,y:u},t,n,e,o);if(!v)return{x:f,y:u};f=v.position.x+v.size.width+o}u=e.filter((v)=>v.position.y<=u+n+o&&v.position.y+v.size.height+o>u).reduce((v,x)=>Math.max(v,x.position.y+x.size.height),u)+o}let p=e.reduce((d,f)=>Math.max(d,f.position.y+f.size.height),0);return{x:a,y:p+o}}var Cr=37,xT=600,wT=1400,_T=24;function ST(e){return e.type==="html"||e.type==="mermaid"||e.type==="json-render"||e.type==="graph"||e.type==="mcp-app"||e.type==="webpage"}function kT(e){if(e.type==="html")return e.data.presentation!==!0;if(e.type==="mermaid")return!0;if(e.type==="json-render"||e.type==="graph")return!0;if(e.type==="mcp-app")return e.data.viewerType==="web-artifact";return!1}function nx(e){return e.collapsed===!0||e.data.strictSize===!0||e.data.userResized===!0||e.type==="group"}function cd(e){return!nx(e)&&!ST(e)}function ox(e,t){if(!cd(e)||t<=0)return null;let n=Math.min(t+Cr,xT),o=ex(e.type);return o?Math.max(n,o.height):n}function ld(e){return kT(e)&&!nx(e)}function rx(e,t){if(!ld(e)||!Number.isFinite(t)||t<=0)return null;let n=Math.min(t+Cr+_T,wT);return n>e.size.height+8?n:null}function ix(e,t,n){if(t<=e.size.height||e.pinned||e.data.parentGroup)return e.position;let o=n.filter((a)=>a.id!==e.id&&!a.pinned&&a.type!=="group"),r={...e.position},s=Ga(r,e.size.width,t,o,24);while(s)r.y=s.position.y+s.size.height+24,s=Ga(r,e.size.width,t,o,24);return r}function Tr(e,t,n){B(()=>{if(!n)return;let o=null,r=null,s=()=>kr.value===e.id||Ei.value.some((p)=>p.grabbingNodeId===e.id);function a(){if(o=null,s()||r===null)return;let p=r;r=null;let d=F.value.get(e.id);if(!d)return;let f=rx(d,p);if(f===null)return;let m=ix(d,f,Array.from(F.value.values())),h=m.x!==d.position.x||m.y!==d.position.y,v={size:{width:d.size.width,height:f},...h?{position:m}:{}};st(d.id,v),Ys([{id:d.id,...v}],{recordHistory:h})}function c(){if(o!==null)clearTimeout(o);o=r!==null&&!s()?setTimeout(a,300):null}let l=Zt(()=>{s(),c()});function u(p){if(p.source!==t.current?.contentWindow)return;let d=p.data;if(!d||d.source!=="pmx-canvas-frame"||d.type!=="content-height"||d.token!==n)return;if(typeof d.height!=="number"||!Number.isFinite(d.height)||d.height<=0)return;r=d.height,c()}return window.addEventListener("message",u),()=>{if(window.removeEventListener("message",u),l(),o!==null)clearTimeout(o)}},[e.id,n])}function CT(e){try{return new URL(e,window.location.origin).origin===window.location.origin}catch{return!1}}function Ir(e){let t=_t.value,[n,o]=I(null),r=Boolean(e)&&CT(e),s=t==="srcdoc"&&r;if(B(()=>{if(!s)return;let a=!1;return fetch(`${e}${e.includes("?")?"&":"?"}inline-assets=1`,{credentials:"same-origin"}).then((c)=>c.ok?c.text():Promise.reject(Error(`HTTP ${c.status}`))).then((c)=>{if(!a)o({url:e,html:c})}).catch((c)=>{if(console.error("[surface-frame] srcdoc fetch failed, falling back to src:",e,c),!a)o({url:e,html:""})}),()=>{a=!0}},[s,e]),!e)return{};if(!s)return t===null&&r?{}:{src:e};if(n)return n.html?{srcdoc:n.html}:{src:n.url};return{}}function Ja({node:e,expanded:t=!1}){let n=R(null),o=tt.value,r=Ie(()=>`theme-${crypto.randomUUID()}`,[]),s=Ie(()=>`frame-${crypto.randomUUID()}`,[]),a=typeof e.data.content==="string"?e.data.content:"",c=e.data.fit==="none"?"none":"contain",l=Ie(()=>wr(`${c}:${a}`),[a,c]),u=Ie(()=>a?Ci(e.id,{theme:o,themeToken:r,v:l,frameToken:s}):"",[a,r,l,e.id,s]),p=Ir(u);Tr(e,n,t?"":s);let d=()=>{n.current?.contentWindow?.postMessage({source:qt,type:"theme-update",token:r,theme:o},"*")};if(B(d,[o,r]),!a)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No diagram source set"},void 0,!1,void 0,this);return i("iframe",{ref:n,class:"html-node-frame",title:typeof e.data.title==="string"?e.data.title:"Mermaid diagram",sandbox:"allow-scripts",...p,onLoad:d,style:{width:"100%",height:"100%",minHeight:t?"70vh":"0",border:"none",background:"var(--c-bg)",borderRadius:"6px",display:"block"}},void 0,!1,void 0,this)}var ud=["dark","light","high-contrast","midnight","sepia","arctic","ember","forest","volt"];function Ai(e){return typeof e==="string"&&ud.includes(e)}function dd(e,t="dark"){return Ai(e)?e:t}var Er={dark:{label:"Dark",scheme:"dark",swatchBg:"#081524",swatchAccent:"#4BBCFF"},light:{label:"Light",scheme:"light",swatchBg:"#F4EFE6",swatchAccent:"#1A7ABF"},"high-contrast":{label:"High contrast",scheme:"dark",swatchBg:"#000000",swatchAccent:"#00ffff"},midnight:{label:"Midnight",scheme:"dark",swatchBg:"#0A0D1C",swatchAccent:"#8B96FF"},sepia:{label:"Sepia",scheme:"light",swatchBg:"#F2E7D5",swatchAccent:"#B4632C"},arctic:{label:"Arctic",scheme:"dark",swatchBg:"#20242E",swatchAccent:"#7FC8DE"},ember:{label:"Ember",scheme:"dark",swatchBg:"#0B0B0C",swatchAccent:"#F34E1C"},forest:{label:"Forest",scheme:"dark",swatchBg:"#0C1712",swatchAccent:"#5CCF8F"},volt:{label:"Volt",scheme:"dark",swatchBg:"#0B0D0B",swatchAccent:"#DFDFC1"}};function Ar(e){return Er[dd(e)].scheme}var no="io.modelcontextprotocol/related-task",Ya="2.0",mt=nv((e)=>e!==null&&(typeof e==="object"||typeof e==="function")),sx=he([C(),ce().int()]),ax=C(),tO=Ct({ttl:he([ce(),Gl()]).optional(),pollInterval:ce().optional()}),TT=A({ttl:ce().optional()}),IT=A({taskId:C()}),pd=Ct({progressToken:sx.optional(),[no]:IT.optional()}),Dt=A({_meta:pd.optional()}),zi=Dt.extend({task:TT.optional()}),cx=(e)=>zi.safeParse(e).success,ft=A({method:C(),params:Dt.loose().optional()}),Wt=A({_meta:pd.optional()}),Vt=A({method:C(),params:Wt.loose().optional()}),ht=Ct({_meta:pd.optional()}),Pr=he([C(),ce().int()]),lx=A({jsonrpc:k(Ya),id:Pr,...ft.shape}).strict(),md=(e)=>lx.safeParse(e).success,ux=A({jsonrpc:k(Ya),...Vt.shape}).strict(),dx=(e)=>ux.safeParse(e).success,fd=A({jsonrpc:k(Ya),id:Pr,result:ht}).strict(),Pi=(e)=>fd.safeParse(e).success;var Te;(function(e){e[e.ConnectionClosed=-32000]="ConnectionClosed",e[e.RequestTimeout=-32001]="RequestTimeout",e[e.ParseError=-32700]="ParseError",e[e.InvalidRequest=-32600]="InvalidRequest",e[e.MethodNotFound=-32601]="MethodNotFound",e[e.InvalidParams=-32602]="InvalidParams",e[e.InternalError=-32603]="InternalError",e[e.UrlElicitationRequired=-32042]="UrlElicitationRequired"})(Te||(Te={}));var hd=A({jsonrpc:k(Ya),id:Pr.optional(),error:A({code:ce().int(),message:C(),data:ze().optional()})}).strict();var px=(e)=>hd.safeParse(e).success;var mx=he([lx,ux,fd,hd]),nO=he([fd,hd]),gd=ht.strict(),ET=Wt.extend({requestId:Pr.optional(),reason:C().optional()}),Qa=Vt.extend({method:k("notifications/cancelled"),params:ET}),AT=A({src:C(),mimeType:C().optional(),sizes:re(C()).optional(),theme:Tt(["light","dark"]).optional()}),Ni=A({icons:re(AT).optional()}),zr=A({name:C(),title:C().optional()}),Ri=zr.extend({...zr.shape,...Ni.shape,version:C(),websiteUrl:C().optional(),description:C().optional()}),zT=Ps(A({applyDefaults:Re().optional()}),Ee(C(),ze())),PT=Kl((e)=>{if(e&&typeof e==="object"&&!Array.isArray(e)){if(Object.keys(e).length===0)return{form:{}}}return e},Ps(A({form:zT.optional(),url:mt.optional()}),Ee(C(),ze()).optional())),NT=Ct({list:mt.optional(),cancel:mt.optional(),requests:Ct({sampling:Ct({createMessage:mt.optional()}).optional(),elicitation:Ct({create:mt.optional()}).optional()}).optional()}),RT=Ct({list:mt.optional(),cancel:mt.optional(),requests:Ct({tools:Ct({call:mt.optional()}).optional()}).optional()}),$T=A({experimental:Ee(C(),mt).optional(),sampling:A({context:mt.optional(),tools:mt.optional()}).optional(),elicitation:PT.optional(),roots:A({listChanged:Re().optional()}).optional(),tasks:NT.optional()}),MT=Dt.extend({protocolVersion:C(),capabilities:$T,clientInfo:Ri}),OT=ft.extend({method:k("initialize"),params:MT});var LT=A({experimental:Ee(C(),mt).optional(),logging:mt.optional(),completions:mt.optional(),prompts:A({listChanged:Re().optional()}).optional(),resources:A({subscribe:Re().optional(),listChanged:Re().optional()}).optional(),tools:A({listChanged:Re().optional()}).optional(),tasks:RT.optional()}),DT=ht.extend({protocolVersion:C(),capabilities:LT,serverInfo:Ri,instructions:C().optional()}),FT=Vt.extend({method:k("notifications/initialized"),params:Wt.optional()});var Lo=ft.extend({method:k("ping"),params:Dt.optional()}),BT=A({progress:ce(),total:Ve(ce()),message:Ve(C())}),HT=A({...Wt.shape,...BT.shape,progressToken:sx}),ec=Vt.extend({method:k("notifications/progress"),params:HT}),jT=Dt.extend({cursor:ax.optional()}),$i=ft.extend({params:jT.optional()}),Mi=ht.extend({nextCursor:ax.optional()}),ZT=Tt(["working","input_required","completed","failed","cancelled"]),Oi=A({taskId:C(),status:ZT,ttl:he([ce(),Gl()]),createdAt:C(),lastUpdatedAt:C(),pollInterval:Ve(ce()),statusMessage:Ve(C())}),tc=ht.extend({task:Oi}),UT=Wt.merge(Oi),Li=Vt.extend({method:k("notifications/tasks/status"),params:UT}),nc=ft.extend({method:k("tasks/get"),params:Dt.extend({taskId:C()})}),oc=ht.merge(Oi),rc=ft.extend({method:k("tasks/result"),params:Dt.extend({taskId:C()})}),oO=ht.loose(),ic=$i.extend({method:k("tasks/list")}),sc=Mi.extend({tasks:re(Oi)}),ac=ft.extend({method:k("tasks/cancel"),params:Dt.extend({taskId:C()})}),fx=ht.merge(Oi),hx=A({uri:C(),mimeType:Ve(C()),_meta:Ee(C(),ze()).optional()}),gx=hx.extend({text:C()}),vd=C().refine((e)=>{try{return atob(e),!0}catch{return!1}},{message:"Invalid Base64 string"}),vx=hx.extend({blob:vd}),Di=Tt(["user","assistant"]),Nr=A({audience:re(Di).optional(),priority:ce().min(0).max(1).optional(),lastModified:Zl({offset:!0}).optional()}),yx=A({...zr.shape,...Ni.shape,uri:C(),description:Ve(C()),mimeType:Ve(C()),annotations:Nr.optional(),_meta:Ve(Ct({}))}),qT=A({...zr.shape,...Ni.shape,uriTemplate:C(),description:Ve(C()),mimeType:Ve(C()),annotations:Nr.optional(),_meta:Ve(Ct({}))}),yd=$i.extend({method:k("resources/list")}),cc=Mi.extend({resources:re(yx)}),bd=$i.extend({method:k("resources/templates/list")}),xd=Mi.extend({resourceTemplates:re(qT)}),wd=Dt.extend({uri:C()}),WT=wd,_d=ft.extend({method:k("resources/read"),params:WT}),lc=ht.extend({contents:re(he([gx,vx]))}),Sd=Vt.extend({method:k("notifications/resources/list_changed"),params:Wt.optional()}),VT=wd,GT=ft.extend({method:k("resources/subscribe"),params:VT}),XT=wd,JT=ft.extend({method:k("resources/unsubscribe"),params:XT}),KT=Wt.extend({uri:C()}),YT=Vt.extend({method:k("notifications/resources/updated"),params:KT}),QT=A({name:C(),description:Ve(C()),required:Ve(Re())}),eI=A({...zr.shape,...Ni.shape,description:Ve(C()),arguments:Ve(re(QT)),_meta:Ve(Ct({}))}),kd=$i.extend({method:k("prompts/list")}),Cd=Mi.extend({prompts:re(eI)}),tI=Dt.extend({name:C(),arguments:Ee(C(),C()).optional()}),nI=ft.extend({method:k("prompts/get"),params:tI}),Td=A({type:k("text"),text:C(),annotations:Nr.optional(),_meta:Ee(C(),ze()).optional()}),Id=A({type:k("image"),data:vd,mimeType:C(),annotations:Nr.optional(),_meta:Ee(C(),ze()).optional()}),Ed=A({type:k("audio"),data:vd,mimeType:C(),annotations:Nr.optional(),_meta:Ee(C(),ze()).optional()}),oI=A({type:k("tool_use"),name:C(),id:C(),input:Ee(C(),ze()),_meta:Ee(C(),ze()).optional()}),Ad=A({type:k("resource"),resource:he([gx,vx]),annotations:Nr.optional(),_meta:Ee(C(),ze()).optional()}),zd=yx.extend({type:k("resource_link")}),Rr=he([Td,Id,Ed,zd,Ad]),rI=A({role:Di,content:Rr}),iI=ht.extend({description:C().optional(),messages:re(rI)}),Pd=Vt.extend({method:k("notifications/prompts/list_changed"),params:Wt.optional()}),sI=A({title:C().optional(),readOnlyHint:Re().optional(),destructiveHint:Re().optional(),idempotentHint:Re().optional(),openWorldHint:Re().optional()}),aI=A({taskSupport:Tt(["required","optional","forbidden"]).optional()}),uc=A({...zr.shape,...Ni.shape,description:C().optional(),inputSchema:A({type:k("object"),properties:Ee(C(),mt).optional(),required:re(C()).optional()}).catchall(ze()),outputSchema:A({type:k("object"),properties:Ee(C(),mt).optional(),required:re(C()).optional()}).catchall(ze()).optional(),annotations:sI.optional(),execution:aI.optional(),_meta:Ee(C(),ze()).optional()}),dc=$i.extend({method:k("tools/list")}),cI=Mi.extend({tools:re(uc)}),Do=ht.extend({content:re(Rr).default([]),structuredContent:Ee(C(),ze()).optional(),isError:Re().optional()}),rO=Do.or(ht.extend({toolResult:ze()})),lI=zi.extend({name:C(),arguments:Ee(C(),ze()).optional()}),pc=ft.extend({method:k("tools/call"),params:lI}),Nd=Vt.extend({method:k("notifications/tools/list_changed"),params:Wt.optional()}),iO=A({autoRefresh:Re().default(!0),debounceMs:ce().int().nonnegative().default(300)}),bx=Tt(["debug","info","notice","warning","error","critical","alert","emergency"]),uI=Dt.extend({level:bx}),dI=ft.extend({method:k("logging/setLevel"),params:uI}),pI=Wt.extend({level:bx,logger:C().optional(),data:ze()}),Rd=Vt.extend({method:k("notifications/message"),params:pI}),mI=A({name:C().optional()}),fI=A({hints:re(mI).optional(),costPriority:ce().min(0).max(1).optional(),speedPriority:ce().min(0).max(1).optional(),intelligencePriority:ce().min(0).max(1).optional()}),hI=A({mode:Tt(["auto","required","none"]).optional()}),gI=A({type:k("tool_result"),toolUseId:C().describe("The unique identifier for the corresponding tool call."),content:re(Rr).default([]),structuredContent:A({}).loose().optional(),isError:Re().optional(),_meta:Ee(C(),ze()).optional()}),vI=Jl("type",[Td,Id,Ed]),Ka=Jl("type",[Td,Id,Ed,oI,gI]),yI=A({role:Di,content:he([Ka,re(Ka)]),_meta:Ee(C(),ze()).optional()}),bI=zi.extend({messages:re(yI),modelPreferences:fI.optional(),systemPrompt:C().optional(),includeContext:Tt(["none","thisServer","allServers"]).optional(),temperature:ce().optional(),maxTokens:ce().int(),stopSequences:re(C()).optional(),metadata:mt.optional(),tools:re(uc).optional(),toolChoice:hI.optional()}),xI=ft.extend({method:k("sampling/createMessage"),params:bI}),wI=ht.extend({model:C(),stopReason:Ve(Tt(["endTurn","stopSequence","maxTokens"]).or(C())),role:Di,content:vI}),_I=ht.extend({model:C(),stopReason:Ve(Tt(["endTurn","stopSequence","maxTokens","toolUse"]).or(C())),role:Di,content:he([Ka,re(Ka)])}),SI=A({type:k("boolean"),title:C().optional(),description:C().optional(),default:Re().optional()}),kI=A({type:k("string"),title:C().optional(),description:C().optional(),minLength:ce().optional(),maxLength:ce().optional(),format:Tt(["email","uri","date","date-time"]).optional(),default:C().optional()}),CI=A({type:Tt(["number","integer"]),title:C().optional(),description:C().optional(),minimum:ce().optional(),maximum:ce().optional(),default:ce().optional()}),TI=A({type:k("string"),title:C().optional(),description:C().optional(),enum:re(C()),default:C().optional()}),II=A({type:k("string"),title:C().optional(),description:C().optional(),oneOf:re(A({const:C(),title:C()})),default:C().optional()}),EI=A({type:k("string"),title:C().optional(),description:C().optional(),enum:re(C()),enumNames:re(C()).optional(),default:C().optional()}),AI=he([TI,II]),zI=A({type:k("array"),title:C().optional(),description:C().optional(),minItems:ce().optional(),maxItems:ce().optional(),items:A({type:k("string"),enum:re(C())}),default:re(C()).optional()}),PI=A({type:k("array"),title:C().optional(),description:C().optional(),minItems:ce().optional(),maxItems:ce().optional(),items:A({anyOf:re(A({const:C(),title:C()}))}),default:re(C()).optional()}),NI=he([zI,PI]),RI=he([EI,AI,NI]),$I=he([RI,SI,kI,CI]),MI=zi.extend({mode:k("form").optional(),message:C(),requestedSchema:A({type:k("object"),properties:Ee(C(),$I),required:re(C()).optional()})}),OI=zi.extend({mode:k("url"),message:C(),elicitationId:C(),url:C().url()}),LI=he([MI,OI]),DI=ft.extend({method:k("elicitation/create"),params:LI}),FI=Wt.extend({elicitationId:C()}),BI=Vt.extend({method:k("notifications/elicitation/complete"),params:FI}),HI=ht.extend({action:Tt(["accept","decline","cancel"]),content:Kl((e)=>e===null?void 0:e,Ee(C(),he([C(),ce(),Re(),re(C())])).optional())}),jI=A({type:k("ref/resource"),uri:C()});var ZI=A({type:k("ref/prompt"),name:C()}),UI=Dt.extend({ref:he([ZI,jI]),argument:A({name:C(),value:C()}),context:A({arguments:Ee(C(),C()).optional()}).optional()}),qI=ft.extend({method:k("completion/complete"),params:UI});var WI=ht.extend({completion:Ct({values:re(C()).max(100),total:Ve(ce().int()),hasMore:Ve(Re())})}),VI=A({uri:C().startsWith("file://"),name:C().optional(),_meta:Ee(C(),ze()).optional()}),GI=ft.extend({method:k("roots/list"),params:Dt.optional()}),XI=ht.extend({roots:re(VI)}),JI=Vt.extend({method:k("notifications/roots/list_changed"),params:Wt.optional()}),sO=he([Lo,OT,qI,dI,nI,kd,yd,bd,_d,GT,JT,pc,dc,nc,rc,ic,ac]),aO=he([Qa,ec,FT,JI,Li]),cO=he([gd,wI,_I,HI,XI,oc,sc,tc]),lO=he([Lo,xI,DI,GI,nc,rc,ic,ac]),uO=he([Qa,ec,Rd,YT,Sd,Nd,Pd,Li,BI]),dO=he([gd,DT,WI,iI,Cd,cc,xd,lc,Do,cI,oc,sc,tc]);class xe extends Error{constructor(e,t,n){super(`MCP error ${e}: ${t}`);this.code=e,this.data=n,this.name="McpError"}static fromError(e,t,n){if(e===Te.UrlElicitationRequired&&n){let o=n;if(o.elicitations)return new xx(o.elicitations,t)}return new xe(e,t,n)}}class xx extends xe{constructor(e,t=`URL elicitation${e.length>1?"s":""} required`){super(Te.UrlElicitationRequired,t,{elicitations:e})}get elicitations(){return this.data?.elicitations??[]}}function mc(e){return!!e._zod}function fc(e,t){if(mc(e))return ni(e,t);return e.safeParse(t)}function wx(e){if(!e)return;let t;if(mc(e))t=e._zod?.def?.shape;else t=e.shape;if(!t)return;if(typeof t==="function")try{return t()}catch{return}return t}function _x(e){if(mc(e)){let s=e._zod?.def;if(s){if(s.value!==void 0)return s.value;if(Array.isArray(s.values)&&s.values.length>0)return s.values[0]}}let n=e._def;if(n){if(n.value!==void 0)return n.value;if(Array.isArray(n.values)&&n.values.length>0)return n.values[0]}let o=e.value;if(o!==void 0)return o;return}function oo(e){return e==="completed"||e==="failed"||e==="cancelled"}var KI=Symbol("Let zodToJsonSchema decide on which parser to use");var oL=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function $d(e){let n=wx(e)?.method;if(!n)throw Error("Schema is missing a method literal");let o=_x(n);if(typeof o!=="string")throw Error("Schema method literal must be a string");return o}function Md(e,t){let n=fc(e,t);if(!n.success)throw n.error;return n.data}var oE=60000;class hc{constructor(e){if(this._options=e,this._requestMessageId=0,this._requestHandlers=new Map,this._requestHandlerAbortControllers=new Map,this._notificationHandlers=new Map,this._responseHandlers=new Map,this._progressHandlers=new Map,this._timeoutInfo=new Map,this._pendingDebouncedNotifications=new Set,this._taskProgressTokens=new Map,this._requestResolvers=new Map,this.setNotificationHandler(Qa,(t)=>{this._oncancel(t)}),this.setNotificationHandler(ec,(t)=>{this._onprogress(t)}),this.setRequestHandler(Lo,(t)=>({})),this._taskStore=e?.taskStore,this._taskMessageQueue=e?.taskMessageQueue,this._taskStore)this.setRequestHandler(nc,async(t,n)=>{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new xe(Te.InvalidParams,"Failed to retrieve task: Task not found");return{...o}}),this.setRequestHandler(rc,async(t,n)=>{let o=async()=>{let r=t.params.taskId;if(this._taskMessageQueue){let a;while(a=await this._taskMessageQueue.dequeue(r,n.sessionId)){if(a.type==="response"||a.type==="error"){let c=a.message,l=c.id,u=this._requestResolvers.get(l);if(u)if(this._requestResolvers.delete(l),a.type==="response")u(c);else{let p=c,d=new xe(p.error.code,p.error.message,p.error.data);u(d)}else{let p=a.type==="response"?"Response":"Error";this._onerror(Error(`${p} handler missing for request ${l}`))}continue}await this._transport?.send(a.message,{relatedRequestId:n.requestId})}}let s=await this._taskStore.getTask(r,n.sessionId);if(!s)throw new xe(Te.InvalidParams,`Task not found: ${r}`);if(!oo(s.status))return await this._waitForTaskUpdate(r,n.signal),await o();if(oo(s.status)){let a=await this._taskStore.getTaskResult(r,n.sessionId);return this._clearTaskQueue(r),{...a,_meta:{...a._meta,[no]:{taskId:r}}}}return await o()};return await o()}),this.setRequestHandler(ic,async(t,n)=>{try{let{tasks:o,nextCursor:r}=await this._taskStore.listTasks(t.params?.cursor,n.sessionId);return{tasks:o,nextCursor:r,_meta:{}}}catch(o){throw new xe(Te.InvalidParams,`Failed to list tasks: ${o instanceof Error?o.message:String(o)}`)}}),this.setRequestHandler(ac,async(t,n)=>{try{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new xe(Te.InvalidParams,`Task not found: ${t.params.taskId}`);if(oo(o.status))throw new xe(Te.InvalidParams,`Cannot cancel task in terminal status: ${o.status}`);await this._taskStore.updateTaskStatus(t.params.taskId,"cancelled","Client cancelled task execution.",n.sessionId),this._clearTaskQueue(t.params.taskId);let r=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!r)throw new xe(Te.InvalidParams,`Task not found after cancellation: ${t.params.taskId}`);return{_meta:{},...r}}catch(o){if(o instanceof xe)throw o;throw new xe(Te.InvalidRequest,`Failed to cancel task: ${o instanceof Error?o.message:String(o)}`)}})}async _oncancel(e){if(!e.params.requestId)return;this._requestHandlerAbortControllers.get(e.params.requestId)?.abort(e.params.reason)}_setupTimeout(e,t,n,o,r=!1){this._timeoutInfo.set(e,{timeoutId:setTimeout(o,t),startTime:Date.now(),timeout:t,maxTotalTimeout:n,resetTimeoutOnProgress:r,onTimeout:o})}_resetTimeout(e){let t=this._timeoutInfo.get(e);if(!t)return!1;let n=Date.now()-t.startTime;if(t.maxTotalTimeout&&n>=t.maxTotalTimeout)throw this._timeoutInfo.delete(e),xe.fromError(Te.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:t.maxTotalTimeout,totalElapsed:n});return clearTimeout(t.timeoutId),t.timeoutId=setTimeout(t.onTimeout,t.timeout),!0}_cleanupTimeout(e){let t=this._timeoutInfo.get(e);if(t)clearTimeout(t.timeoutId),this._timeoutInfo.delete(e)}async connect(e){if(this._transport)throw Error("Already connected to a transport. Call close() before connecting to a new transport, or use a separate Protocol instance per connection.");this._transport=e;let t=this.transport?.onclose;this._transport.onclose=()=>{t?.(),this._onclose()};let n=this.transport?.onerror;this._transport.onerror=(r)=>{n?.(r),this._onerror(r)};let o=this._transport?.onmessage;this._transport.onmessage=(r,s)=>{if(o?.(r,s),Pi(r)||px(r))this._onresponse(r);else if(md(r))this._onrequest(r,s);else if(dx(r))this._onnotification(r);else this._onerror(Error(`Unknown message type: ${JSON.stringify(r)}`))},await this._transport.start()}_onclose(){let e=this._responseHandlers;this._responseHandlers=new Map,this._progressHandlers.clear(),this._taskProgressTokens.clear(),this._pendingDebouncedNotifications.clear();for(let n of this._timeoutInfo.values())clearTimeout(n.timeoutId);this._timeoutInfo.clear();for(let n of this._requestHandlerAbortControllers.values())n.abort();this._requestHandlerAbortControllers.clear();let t=xe.fromError(Te.ConnectionClosed,"Connection closed");this._transport=void 0,this.onclose?.();for(let n of e.values())n(t)}_onerror(e){this.onerror?.(e)}_onnotification(e){let t=this._notificationHandlers.get(e.method)??this.fallbackNotificationHandler;if(t===void 0)return;Promise.resolve().then(()=>t(e)).catch((n)=>this._onerror(Error(`Uncaught error in notification handler: ${n}`)))}_onrequest(e,t){let n=this._requestHandlers.get(e.method)??this.fallbackRequestHandler,o=this._transport,r=e.params?._meta?.[no]?.taskId;if(n===void 0){let u={jsonrpc:"2.0",id:e.id,error:{code:Te.MethodNotFound,message:"Method not found"}};if(r&&this._taskMessageQueue)this._enqueueTaskMessage(r,{type:"error",message:u,timestamp:Date.now()},o?.sessionId).catch((p)=>this._onerror(Error(`Failed to enqueue error response: ${p}`)));else o?.send(u).catch((p)=>this._onerror(Error(`Failed to send an error response: ${p}`)));return}let s=new AbortController;this._requestHandlerAbortControllers.set(e.id,s);let a=cx(e.params)?e.params.task:void 0,c=this._taskStore?this.requestTaskStore(e,o?.sessionId):void 0,l={signal:s.signal,sessionId:o?.sessionId,_meta:e.params?._meta,sendNotification:async(u)=>{if(s.signal.aborted)return;let p={relatedRequestId:e.id};if(r)p.relatedTask={taskId:r};await this.notification(u,p)},sendRequest:async(u,p,d)=>{if(s.signal.aborted)throw new xe(Te.ConnectionClosed,"Request was cancelled");let f={...d,relatedRequestId:e.id};if(r&&!f.relatedTask)f.relatedTask={taskId:r};let m=f.relatedTask?.taskId??r;if(m&&c)await c.updateTaskStatus(m,"input_required");return await this.request(u,p,f)},authInfo:t?.authInfo,requestId:e.id,requestInfo:t?.requestInfo,taskId:r,taskStore:c,taskRequestedTtl:a?.ttl,closeSSEStream:t?.closeSSEStream,closeStandaloneSSEStream:t?.closeStandaloneSSEStream};Promise.resolve().then(()=>{if(a)this.assertTaskHandlerCapability(e.method)}).then(()=>n(e,l)).then(async(u)=>{if(s.signal.aborted)return;let p={result:u,jsonrpc:"2.0",id:e.id};if(r&&this._taskMessageQueue)await this._enqueueTaskMessage(r,{type:"response",message:p,timestamp:Date.now()},o?.sessionId);else await o?.send(p)},async(u)=>{if(s.signal.aborted)return;let p={jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(u.code)?u.code:Te.InternalError,message:u.message??"Internal error",...u.data!==void 0&&{data:u.data}}};if(r&&this._taskMessageQueue)await this._enqueueTaskMessage(r,{type:"error",message:p,timestamp:Date.now()},o?.sessionId);else await o?.send(p)}).catch((u)=>this._onerror(Error(`Failed to send response: ${u}`))).finally(()=>{if(this._requestHandlerAbortControllers.get(e.id)===s)this._requestHandlerAbortControllers.delete(e.id)})}_onprogress(e){let{progressToken:t,...n}=e.params,o=Number(t),r=this._progressHandlers.get(o);if(!r){this._onerror(Error(`Received a progress notification for an unknown token: ${JSON.stringify(e)}`));return}let s=this._responseHandlers.get(o),a=this._timeoutInfo.get(o);if(a&&s&&a.resetTimeoutOnProgress)try{this._resetTimeout(o)}catch(c){this._responseHandlers.delete(o),this._progressHandlers.delete(o),this._cleanupTimeout(o),s(c);return}r(n)}_onresponse(e){let t=Number(e.id),n=this._requestResolvers.get(t);if(n){if(this._requestResolvers.delete(t),Pi(e))n(e);else{let s=new xe(e.error.code,e.error.message,e.error.data);n(s)}return}let o=this._responseHandlers.get(t);if(o===void 0){this._onerror(Error(`Received a response for an unknown message ID: ${JSON.stringify(e)}`));return}this._responseHandlers.delete(t),this._cleanupTimeout(t);let r=!1;if(Pi(e)&&e.result&&typeof e.result==="object"){let s=e.result;if(s.task&&typeof s.task==="object"){let a=s.task;if(typeof a.taskId==="string")r=!0,this._taskProgressTokens.set(a.taskId,t)}}if(!r)this._progressHandlers.delete(t);if(Pi(e))o(e);else{let s=xe.fromError(e.error.code,e.error.message,e.error.data);o(s)}}get transport(){return this._transport}async close(){await this._transport?.close()}async*requestStream(e,t,n){let{task:o}=n??{};if(!o){try{yield{type:"result",result:await this.request(e,t,n)}}catch(s){yield{type:"error",error:s instanceof xe?s:new xe(Te.InternalError,String(s))}}return}let r;try{let s=await this.request(e,tc,n);if(s.task)r=s.task.taskId,yield{type:"taskCreated",task:s.task};else throw new xe(Te.InternalError,"Task creation did not return a task");while(!0){let a=await this.getTask({taskId:r},n);if(yield{type:"taskStatus",task:a},oo(a.status)){if(a.status==="completed")yield{type:"result",result:await this.getTaskResult({taskId:r},t,n)};else if(a.status==="failed")yield{type:"error",error:new xe(Te.InternalError,`Task ${r} failed`)};else if(a.status==="cancelled")yield{type:"error",error:new xe(Te.InternalError,`Task ${r} was cancelled`)};return}if(a.status==="input_required"){yield{type:"result",result:await this.getTaskResult({taskId:r},t,n)};return}let c=a.pollInterval??this._options?.defaultTaskPollInterval??1000;await new Promise((l)=>setTimeout(l,c)),n?.signal?.throwIfAborted()}}catch(s){yield{type:"error",error:s instanceof xe?s:new xe(Te.InternalError,String(s))}}}request(e,t,n){let{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s,task:a,relatedTask:c}=n??{};return new Promise((l,u)=>{let p=(g)=>{u(g)};if(!this._transport){p(Error("Not connected"));return}if(this._options?.enforceStrictCapabilities===!0)try{if(this.assertCapabilityForMethod(e.method),a)this.assertTaskCapability(e.method)}catch(g){p(g);return}n?.signal?.throwIfAborted();let d=this._requestMessageId++,f={...e,jsonrpc:"2.0",id:d};if(n?.onprogress)this._progressHandlers.set(d,n.onprogress),f.params={...e.params,_meta:{...e.params?._meta||{},progressToken:d}};if(a)f.params={...f.params,task:a};if(c)f.params={...f.params,_meta:{...f.params?._meta||{},[no]:c}};let m=(g)=>{this._responseHandlers.delete(d),this._progressHandlers.delete(d),this._cleanupTimeout(d),this._transport?.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:d,reason:String(g)}},{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s}).catch((E)=>this._onerror(Error(`Failed to send cancellation: ${E}`)));let y=g instanceof xe?g:new xe(Te.RequestTimeout,String(g));u(y)};this._responseHandlers.set(d,(g)=>{if(n?.signal?.aborted)return;if(g instanceof Error)return u(g);try{let y=fc(t,g.result);if(!y.success)u(y.error);else l(y.data)}catch(y){u(y)}}),n?.signal?.addEventListener("abort",()=>{m(n?.signal?.reason)});let h=n?.timeout??oE,v=()=>m(xe.fromError(Te.RequestTimeout,"Request timed out",{timeout:h}));this._setupTimeout(d,h,n?.maxTotalTimeout,v,n?.resetTimeoutOnProgress??!1);let x=c?.taskId;if(x){let g=(y)=>{let E=this._responseHandlers.get(d);if(E)E(y);else this._onerror(Error(`Response handler missing for side-channeled request ${d}`))};this._requestResolvers.set(d,g),this._enqueueTaskMessage(x,{type:"request",message:f,timestamp:Date.now()}).catch((y)=>{this._cleanupTimeout(d),u(y)})}else this._transport.send(f,{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s}).catch((g)=>{this._cleanupTimeout(d),u(g)})})}async getTask(e,t){return this.request({method:"tasks/get",params:e},oc,t)}async getTaskResult(e,t,n){return this.request({method:"tasks/result",params:e},t,n)}async listTasks(e,t){return this.request({method:"tasks/list",params:e},sc,t)}async cancelTask(e,t){return this.request({method:"tasks/cancel",params:e},fx,t)}async notification(e,t){if(!this._transport)throw Error("Not connected");this.assertNotificationCapability(e.method);let n=t?.relatedTask?.taskId;if(n){let a={...e,jsonrpc:"2.0",params:{...e.params,_meta:{...e.params?._meta||{},[no]:t.relatedTask}}};await this._enqueueTaskMessage(n,{type:"notification",message:a,timestamp:Date.now()});return}if((this._options?.debouncedNotificationMethods??[]).includes(e.method)&&!e.params&&!t?.relatedRequestId&&!t?.relatedTask){if(this._pendingDebouncedNotifications.has(e.method))return;this._pendingDebouncedNotifications.add(e.method),Promise.resolve().then(()=>{if(this._pendingDebouncedNotifications.delete(e.method),!this._transport)return;let a={...e,jsonrpc:"2.0"};if(t?.relatedTask)a={...a,params:{...a.params,_meta:{...a.params?._meta||{},[no]:t.relatedTask}}};this._transport?.send(a,t).catch((c)=>this._onerror(c))});return}let s={...e,jsonrpc:"2.0"};if(t?.relatedTask)s={...s,params:{...s.params,_meta:{...s.params?._meta||{},[no]:t.relatedTask}}};await this._transport.send(s,t)}setRequestHandler(e,t){let n=$d(e);this.assertRequestHandlerCapability(n),this._requestHandlers.set(n,(o,r)=>{let s=Md(e,o);return Promise.resolve(t(s,r))})}removeRequestHandler(e){this._requestHandlers.delete(e)}assertCanSetRequestHandler(e){if(this._requestHandlers.has(e))throw Error(`A request handler for ${e} already exists, which would be overridden`)}setNotificationHandler(e,t){let n=$d(e);this._notificationHandlers.set(n,(o)=>{let r=Md(e,o);return Promise.resolve(t(r))})}removeNotificationHandler(e){this._notificationHandlers.delete(e)}_cleanupTaskProgressHandler(e){let t=this._taskProgressTokens.get(e);if(t!==void 0)this._progressHandlers.delete(t),this._taskProgressTokens.delete(e)}async _enqueueTaskMessage(e,t,n){if(!this._taskStore||!this._taskMessageQueue)throw Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");let o=this._options?.maxTaskQueueSize;await this._taskMessageQueue.enqueue(e,t,n,o)}async _clearTaskQueue(e,t){if(this._taskMessageQueue){let n=await this._taskMessageQueue.dequeueAll(e,t);for(let o of n)if(o.type==="request"&&md(o.message)){let r=o.message.id,s=this._requestResolvers.get(r);if(s)s(new xe(Te.InternalError,"Task cancelled or completed")),this._requestResolvers.delete(r);else this._onerror(Error(`Resolver missing for request ${r} during task ${e} cleanup`))}}}async _waitForTaskUpdate(e,t){let n=this._options?.defaultTaskPollInterval??1000;try{let o=await this._taskStore?.getTask(e);if(o?.pollInterval)n=o.pollInterval}catch{}return new Promise((o,r)=>{if(t.aborted){r(new xe(Te.InvalidRequest,"Request cancelled"));return}let s=setTimeout(o,n);t.addEventListener("abort",()=>{clearTimeout(s),r(new xe(Te.InvalidRequest,"Request cancelled"))},{once:!0})})}requestTaskStore(e,t){let n=this._taskStore;if(!n)throw Error("No task store configured");return{createTask:async(o)=>{if(!e)throw Error("No request provided");return await n.createTask(o,e.id,{method:e.method,params:e.params},t)},getTask:async(o)=>{let r=await n.getTask(o,t);if(!r)throw new xe(Te.InvalidParams,"Failed to retrieve task: Task not found");return r},storeTaskResult:async(o,r,s)=>{await n.storeTaskResult(o,r,s,t);let a=await n.getTask(o,t);if(a){let c=Li.parse({method:"notifications/tasks/status",params:a});if(await this.notification(c),oo(a.status))this._cleanupTaskProgressHandler(o)}},getTaskResult:(o)=>n.getTaskResult(o,t),updateTaskStatus:async(o,r,s)=>{let a=await n.getTask(o,t);if(!a)throw new xe(Te.InvalidParams,`Task "${o}" not found - it may have been cleaned up`);if(oo(a.status))throw new xe(Te.InvalidParams,`Cannot update task "${o}" from terminal status "${a.status}" to "${r}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);await n.updateTaskStatus(o,r,s,t);let c=await n.getTask(o,t);if(c){let l=Li.parse({method:"notifications/tasks/status",params:c});if(await this.notification(l),oo(c.status))this._cleanupTaskProgressHandler(o)}},listTasks:(o)=>n.listTasks(o,t)}}}var Cx="2026-01-26";var rE="ui/notifications/tool-input-partial";var iE=he([k("light"),k("dark")]).describe("Color theme preference for the host environment."),Bi=he([k("inline"),k("fullscreen"),k("pip")]).describe("Display mode for UI presentation."),sE=he([k("--color-background-primary"),k("--color-background-secondary"),k("--color-background-tertiary"),k("--color-background-inverse"),k("--color-background-ghost"),k("--color-background-info"),k("--color-background-danger"),k("--color-background-success"),k("--color-background-warning"),k("--color-background-disabled"),k("--color-text-primary"),k("--color-text-secondary"),k("--color-text-tertiary"),k("--color-text-inverse"),k("--color-text-ghost"),k("--color-text-info"),k("--color-text-danger"),k("--color-text-success"),k("--color-text-warning"),k("--color-text-disabled"),k("--color-border-primary"),k("--color-border-secondary"),k("--color-border-tertiary"),k("--color-border-inverse"),k("--color-border-ghost"),k("--color-border-info"),k("--color-border-danger"),k("--color-border-success"),k("--color-border-warning"),k("--color-border-disabled"),k("--color-ring-primary"),k("--color-ring-secondary"),k("--color-ring-inverse"),k("--color-ring-info"),k("--color-ring-danger"),k("--color-ring-success"),k("--color-ring-warning"),k("--font-sans"),k("--font-mono"),k("--font-weight-normal"),k("--font-weight-medium"),k("--font-weight-semibold"),k("--font-weight-bold"),k("--font-text-xs-size"),k("--font-text-sm-size"),k("--font-text-md-size"),k("--font-text-lg-size"),k("--font-heading-xs-size"),k("--font-heading-sm-size"),k("--font-heading-md-size"),k("--font-heading-lg-size"),k("--font-heading-xl-size"),k("--font-heading-2xl-size"),k("--font-heading-3xl-size"),k("--font-text-xs-line-height"),k("--font-text-sm-line-height"),k("--font-text-md-line-height"),k("--font-text-lg-line-height"),k("--font-heading-xs-line-height"),k("--font-heading-sm-line-height"),k("--font-heading-md-line-height"),k("--font-heading-lg-line-height"),k("--font-heading-xl-line-height"),k("--font-heading-2xl-line-height"),k("--font-heading-3xl-line-height"),k("--border-radius-xs"),k("--border-radius-sm"),k("--border-radius-md"),k("--border-radius-lg"),k("--border-radius-xl"),k("--border-radius-full"),k("--border-width-regular"),k("--shadow-hairline"),k("--shadow-sm"),k("--shadow-md"),k("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."),aE=Ee(sE.describe(`Style variables for theming MCP apps.
|
|
165
|
+
`.substring(0,r);return n+s+o}function dT(e){return e!=null&&(typeof e==="string"||e.nodeType&&(e.nodeType===1||e.nodeType===9||e.nodeType===11))}function $a(){let e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0).cloneRange():null;Dt("Link URL","https://example.com").then((n)=>{if(!n)return;let o=n.trim().toLowerCase();if(o.startsWith("javascript:")||o.startsWith("data:"))return;if(t){let r=window.getSelection();r?.removeAllRanges(),r?.addRange(t)}document.execCommand("createLink",!1,n)})}function Bb(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);if(t.collapsed)return;let n=t.toString(),o=document.createElement("code");o.textContent=n,t.deleteContents(),t.insertNode(o);let r=document.createRange();r.setStartAfter(o),r.setEndAfter(o),e.removeAllRanges(),e.addRange(r)}var Ma=8,pT=[{kind:"exec",command:"bold",icon:"B",title:`Bold (${Ve("B")})`},{kind:"exec",command:"italic",icon:"I",title:`Italic (${Ve("I")})`},{kind:"exec",command:"strikeThrough",icon:"S",title:"Strikethrough"},{kind:"code",icon:"{ }",title:"Inline code",dividerBefore:!0},{kind:"block",tag:"H1",icon:"H1",title:"Heading 1",dividerBefore:!0},{kind:"block",tag:"H2",icon:"H2",title:"Heading 2"},{kind:"block",tag:"H3",icon:"H3",title:"Heading 3"},{kind:"block",tag:"P",icon:"¶",title:"Paragraph"},{kind:"block",tag:"BLOCKQUOTE",icon:"❝",title:"Quote",dividerBefore:!0},{kind:"exec",command:"insertUnorderedList",icon:"•",title:"Bullet list"},{kind:"exec",command:"insertOrderedList",icon:"1.",title:"Numbered list"},{kind:"link",icon:"\uD83D\uDD17",title:`Link (${Ve("K")})`,dividerBefore:!0}];function mT(e){switch(e.kind){case"exec":document.execCommand(e.command);return;case"block":document.execCommand("formatBlock",!1,e.tag);return;case"code":Bb();return;case"link":$a();return}}function Hb({hostRef:e,onChange:t}){let[n,o]=I(!1),[r,s]=I({top:0,left:0}),[a,c]=I(0),l=z(null),u=z(null),p=H(()=>{let f=e.current;if(!f){o(!1);return}let h=window.getSelection();if(!h||h.rangeCount===0||h.isCollapsed){o(!1);return}let v=h.getRangeAt(0);if(!f.contains(v.commonAncestorContainer)){o(!1);return}let x=v.getBoundingClientRect();if(x.width===0&&x.height===0){o(!1);return}let g=a||420,y=Math.max(Ma,Math.min(x.left+x.width/2-g/2,window.innerWidth-g-Ma)),E=Math.max(Ma,x.top-Ma-36);s({top:E,left:y}),o(!0)},[e,a]),d=H(()=>{if(u.current!==null)return;u.current=requestAnimationFrame(()=>{u.current=null,p()})},[p]);B(()=>(document.addEventListener("selectionchange",d),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{if(document.removeEventListener("selectionchange",d),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d),u.current!==null)cancelAnimationFrame(u.current)}),[d]),jt(()=>{if(!n)return;let f=l.current;if(!f)return;let h=f.getBoundingClientRect().width;if(h&&Math.abs(h-a)>1)c(h)},[n,a]);let m=H((f)=>{mT(f),t(),p()},[t,p]);if(!n)return null;return i("div",{ref:l,class:"md-inline-format-bar",style:{top:`${r.top}px`,left:`${r.left}px`},onMouseDown:(f)=>f.preventDefault(),children:pT.flatMap((f,h)=>{let v=i("button",{type:"button",class:"md-inline-format-btn",title:f.title,onClick:()=>m(f),children:f.icon},`btn-${h}`,!1,void 0,this);return f.dividerBefore?[i("span",{class:"md-inline-format-divider"},`div-${h}`,!1,void 0,this),v]:[v]})},void 0,!1,void 0,this)}var Xu=null;function fT(){if(Xu)return Xu;let e=new Ti({headingStyle:"atx",codeBlockStyle:"fenced",emDelimiter:"*",bulletListMarker:"-"});return e.use(jb.gfm),Xu=e,e}function Zb({initialHtml:e,className:t,onChange:n,onSave:o}){let r=z(null),s=z(e);B(()=>{let m=r.current;if(!m)return;m.innerHTML=s.current;for(let f of m.querySelectorAll('input[type="checkbox"][disabled]'))f.removeAttribute("disabled")},[]);let a=H(()=>{let m=r.current;if(!m)return"";return fT().turndown(m.innerHTML)},[]),c=H(()=>{n(a())},[n,a]),l=H(()=>{let m=r.current;if(!m||!m.isConnected||m.innerHTML==="")return;o?.(a())},[o,a]),u=H((m)=>{if(!(m.metaKey||m.ctrlKey))return;if(m.key==="s"){m.preventDefault(),l();return}if(m.key==="b"){m.preventDefault(),document.execCommand("bold"),c();return}if(m.key==="i"){m.preventDefault(),document.execCommand("italic"),c();return}if(m.key==="k")m.preventDefault(),$a(),c()},[c,l]),p=H((m)=>{let f=m.target;if(f instanceof HTMLInputElement&&f.type==="checkbox")f.toggleAttribute("checked",f.checked),c()},[c]),d=H((m)=>{let f=m.clipboardData?.getData("text/plain");if(f==null)return;m.preventDefault(),document.execCommand("insertText",!1,f),c()},[c]);return i(ue,{children:[i("div",{ref:r,class:t,contentEditable:!0,spellcheck:!1,onInput:c,onKeyDown:u,onPaste:d,onClick:p,onBlur:l},void 0,!1,void 0,this),i(Hb,{hostRef:r,onChange:c},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ju({html:e,className:t,style:n,onTaskToggle:o}){let r=z(null),s=z(o);return s.current=o,B(()=>{let c=r.current;if(!c)return;if(c.replaceChildren(),!e)return;let l=document.createElement("template");if(l.innerHTML=e,c.append(l.content.cloneNode(!0)),s.current)for(let u of c.querySelectorAll('input[type="checkbox"][disabled]'))u.removeAttribute("disabled")},[e]),i("div",{ref:r,class:t,style:n,onClick:o?(c)=>{let l=s.current,u=r.current;if(!u||!l)return;let p=c.target,d=null;if(p instanceof HTMLInputElement&&p.type==="checkbox")d=p;else{let h=p.closest("li")?.querySelector(':scope > input[type="checkbox"]');if(h&&c.clientX<=h.getBoundingClientRect().right+6)d=h}if(!d)return;c.stopPropagation();let m=[...u.querySelectorAll('input[type="checkbox"]')].indexOf(d);if(m>=0)l(m)}:void 0},void 0,!1,void 0,this)}function hT(e,t){let n=-1;return e.replace(/^(\s*(?:[-*+]|\d+[.)])\s+\[)([ xX])(\])/gm,(o,r,s,a)=>{if(n+=1,n!==t)return o;return`${r}${s===" "?"x":" "}${a}`})}function La({node:e,expanded:t=!1}){let n=Ea(),o=e.data.path,[r,s]=I(""),[a,c]=I(""),[l,u]=I(!1),[p,d]=I(!1),[m,f]=I(!1),[h,v]=I(!1),x=z(null),g=z(null),y=z(""),E=z(null),D=e.data.reviewActive;B(()=>{let R=!1;return(async()=>{let Z;if(o){let k=await gi(o);if(R)return;Z=k.content}else if(e.data.content)Z=e.data.content;else{u(!0);return}s(Z);let j=await _n(Z);if(R)return;c(j),u(!0),ie(e.id,{content:Z,rendered:j})})(),()=>{R=!0}},[o,e.id,e.data.content]);let N=H(async(R)=>{let Z=R.target.value;s(Z),v(!0);let j=await _n(Z);c(j)},[]),b=H(async(R)=>{if(!o){let j=await _n(R);c(j),v(!1),ie(e.id,{content:R,rendered:j}),await mt(e.id,{content:R,data:{rendered:j}});return}f(!0);let Z=await Pv(o,R);if(f(!1),Z.ok){let j=await _n(R);c(j),v(!1),ie(e.id,{content:R,rendered:j,savedAt:Z.updatedAt}),await mt(e.id,{content:R,data:{rendered:j,savedAt:Z.updatedAt}})}},[o,e.id]),T=H(async()=>{if(!h)return;await b(r)},[h,r,b]),w=H((R)=>{if((R.metaKey||R.ctrlKey)&&R.key==="s"){R.preventDefault(),T();return}let Z=x.current;if(Z&&lb(R,Z))return;if(Z&&R.key==="Tab")R.preventDefault(),cb(Z,R.shiftKey)},[T]);E.current=b;let _=H((R)=>{if(s(R),v(!0),y.current=R,g.current!==null)window.clearTimeout(g.current);g.current=window.setTimeout(()=>{g.current=null,b(R)},800)},[b]),P=H((R)=>{if(s(R),y.current=R,g.current!==null)window.clearTimeout(g.current),g.current=null;b(R)},[b]);B(()=>()=>{if(g.current===null)return;window.clearTimeout(g.current),g.current=null;let R=E.current;if(R)R(y.current)},[e.id]);let q=D?i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-ok-10)",color:"var(--c-ok)",borderBottom:"1px solid var(--c-ok-20)",textTransform:"uppercase",letterSpacing:"0.05em",fontWeight:600},children:"Review active"},void 0,!1,void 0,this):null;if(p&&t)return i("div",{class:"md-editor-expanded",onKeyDown:w,children:[i("div",{class:"md-editor-toolbar",children:[i("button",{type:"button",class:"md-toolbar-btn",onClick:()=>d(!1),children:[i(Cy,{size:14},void 0,!1,void 0,this)," Back to document"]},void 0,!0,void 0,this),i("div",{style:{display:"flex",gap:"6px",alignItems:"center"},children:[o&&i("span",{class:"md-toolbar-path",children:o.split("/").pop()},void 0,!1,void 0,this),i("button",{type:"button",class:`md-toolbar-btn${h?" md-toolbar-btn-primary":""}`,onClick:T,disabled:!h||m,children:m?"Saving…":h?"Save":"Saved"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"md-editor-split",children:[i("div",{style:{flex:1,position:"relative",display:"flex",flexDirection:"column"},children:[i("textarea",{ref:x,value:r,onInput:N,spellcheck:!1},void 0,!1,void 0,this),i(Lu,{textareaRef:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Ju,{html:a,className:"md-preview"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(p)return i("div",{class:"md-editor-split",style:{height:"100%"},onKeyDown:w,children:[i("div",{style:{flex:1,position:"relative",display:"flex",flexDirection:"column"},children:[i("textarea",{ref:x,value:r,onInput:N,spellcheck:!1},void 0,!1,void 0,this),i(Lu,{textareaRef:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Ju,{html:a,className:"md-preview"},void 0,!1,void 0,this),i("div",{style:{position:"absolute",bottom:"8px",right:"8px",display:"flex",gap:"6px"},children:[i("button",{type:"button",onClick:()=>d(!1),style:{padding:"4px 10px",fontSize:"11px",background:"var(--c-input-bg)",border:"1px solid var(--c-line)",borderRadius:"6px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Document"},void 0,!1,void 0,this),i("button",{type:"button",onClick:T,disabled:!h||m,style:{padding:"4px 10px",fontSize:"11px",background:h?"var(--c-accent-25)":"var(--c-input-bg)",border:`1px solid ${h?"var(--c-accent)":"var(--c-line)"}`,borderRadius:"6px",color:h?"var(--c-text)":"var(--c-dim)",cursor:h?"pointer":"default"},children:m?"Saving…":h?"Save":"Saved"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(t)return i("div",{style:{height:"100%",position:"relative"},children:[q,i("div",{class:"md-reader",children:l?i(Zb,{initialHtml:a||"<p><br></p>",className:"md-reader-content md-reader-editable",onChange:_,onSave:P},e.id,!1,void 0,this):i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"24px"},children:"Loading…"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"md-edit-fab",onClick:()=>d(!0),children:"</> Source"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{class:"md-card-preview",children:[i("div",{class:"md-card-content",children:[q,i(Ju,{html:a,style:{padding:a?"0":"12px",color:a?void 0:"var(--c-dim)"},onTaskToggle:(R)=>{let Z=hT(r,R);if(Z!==r)P(Z)}},void 0,!1,void 0,this),!l&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"Loading…"},void 0,!1,void 0,this),l&&!a&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"Empty node"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.data.source&&typeof e.data.source==="object"&&"attachmentId"in e.data.source&&i("div",{class:"md-import-source",children:["Source material ·"," ",i("a",{href:`/api/canvas/attachments/${encodeURIComponent(String(e.data.source.attachmentId))}/bytes`,target:"_blank",rel:"noopener noreferrer",children:String(e.data.source.filename??"Original")},void 0,!1,void 0,this)," · ",String(e.data.source.reference??"Location not supplied")]},void 0,!0,void 0,this),i("div",{class:"md-card-actions",children:[n&&i("button",{type:"button",class:"md-readme-btn","aria-pressed":n.readmeNodeId===e.id,onClick:()=>void rb(n.id,n.readmeNodeId===e.id?null:e.id),children:n.readmeNodeId===e.id?"README":"Set as README"},void 0,!1,void 0,this),i("button",{type:"button",class:"md-card-edit",onClick:()=>Ut(e.id),children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Oa="pmx-canvas-ax",Da="pmx-canvas-ax-ack",qt="pmx-canvas-html-node",Ku="pmx-canvas-json-state",Fa="pmx-canvas-ext-app-alive",Yu="pmx-canvas-ext-app-paint-probe";function Ub(e,t){switch(e){case"html":return typeof t.html==="string"&&t.html.length>0||typeof t.content==="string"&&t.content.length>0;case"mermaid":return typeof t.content==="string"&&t.content.trim().length>0;case"json-render":case"graph":return!0;case"mcp-app":return t.viewerType==="web-artifact"&&typeof t.path==="string"&&t.path.length>0||typeof t.url==="string"&&t.url.length>0;case"webpage":return typeof t.url==="string"&&t.url.length>0;default:return!1}}var Qu="allow-scripts allow-popups allow-popups-to-escape-sandbox";function Sr(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t<<5)+t+e.charCodeAt(n)|0;return(t>>>0).toString(36)}function Ii(e,t={}){let n=new URLSearchParams;if(n.set("theme",t.theme??nt.value),t.themeToken)n.set("themeToken",t.themeToken);if(t.present)n.set("present","1");if(t.presentToken)n.set("presentToken",t.presentToken);if(t.v)n.set("v",t.v);if(t.axToken)n.set("axToken",t.axToken);if(t.frameToken)n.set("frameToken",t.frameToken);return`/api/canvas/surface/${encodeURIComponent(e)}?${n.toString()}`}function Ba(e){return Ub(e.type,e.data)}async function Ha(e){let t=Ii(e.id);if(!(await Ov(e.id,t)).opened)window.open(t,"_blank","noopener")}var qb=30000;var ed=80;var Xe=U(new Map),Tr=U(null),gT=480,vT=320,yT=650,Ei=new Map,Cr=new Map,ja=new Map,zn=null;function td(e){Xe.value=e,bT()}function nd(e){let t=Ei.get(e);if(t)clearTimeout(t),Ei.delete(e)}function od(e){let t=Cr.get(e);if(t)clearTimeout(t),Cr.delete(e)}function Vb(e){if(nd(e.id),od(e.id),!Xe.value.has(e.id))ja.set(e.id,Date.now());let t=new Map(Xe.value);t.set(e.id,{...e,phase:"forming"}),td(t)}function Mo(e){if(nd(e),od(e),ja.delete(e),!Xe.value.has(e))return;let t=new Map(Xe.value);t.delete(e),td(t)}function Wb(e,t,n,o){let r=Xe.value.get(e);if(!r||r.phase===t)return;let s=new Map(Xe.value);s.set(e,{...r,phase:t,...o?{settledNodeId:o}:{}}),td(s),nd(e),Ei.set(e,setTimeout(()=>Mo(e),n+1500))}function Gb(e,t,n,o){od(e);let r=Date.now()-(ja.get(e)??0),s=Math.max(0,yT-r);if(s===0){Wb(e,t,n,o);return}Cr.set(e,setTimeout(()=>{Cr.delete(e),Wb(e,t,n,o)},s))}function Xb(e,t){Gb(e,"settling",gT,t)}function rd(e){Gb(e,"dissolving",vT)}function Za(){for(let e of Ei.values())clearTimeout(e);Ei.clear();for(let e of Cr.values())clearTimeout(e);if(Cr.clear(),ja.clear(),zn)clearInterval(zn),zn=null;Tr.value=null,Xe.value=new Map}function bT(){if(zn||Xe.value.size===0)return;zn=setInterval(()=>{let e=Date.now();for(let t of Xe.value.values())if(t.phase==="forming"&&t.expiresAt<=e)rd(t.id);if(Xe.value.size===0&&zn)clearInterval(zn),zn=null},1000),zn.unref?.()}function xT(e,t){try{let n=window.sessionStorage.getItem(e);if(n)return n;let o=t();return window.sessionStorage.setItem(e,o),o}catch{return t()}}var Wa=xT("pmx-canvas-human-client",()=>`tab-${Math.random().toString(36).slice(2,8)}`);function wT(){try{let e=new URLSearchParams(window.location.search).get("name")?.trim();if(e)return window.localStorage.setItem("pmx-canvas-human-name",e),e;let t=window.localStorage.getItem("pmx-canvas-human-name")?.trim();if(t)return t}catch{}return`guest-${Wa.slice(-4)}`}var Kb=U(wT()),Yb=U([]),zi=De(()=>Yb.value.filter((e)=>e.clientId!==Wa)),Lo=U(new Map);function id(e){if(!e||!Array.isArray(e.humans))return;Yb.value=e.humans}var Ir=U(null),Va=null,Qb=0,Ai=null;function qa(e){en("humanPresence","/api/canvas/human-presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({clientId:Wa,name:Kb.value,...e})})}function Jb(){Ai=null,Qb=Date.now(),qa({cursor:Va,grabbingNodeId:Ir.value})}function Ga(e){Va=e;let t=Date.now()-Qb;if(t>=ed){if(Ai)clearTimeout(Ai);Jb()}else if(!Ai)Ai=setTimeout(Jb,ed-t)}function sd(e){Ir.value=e,qa({cursor:Va,grabbingNodeId:e})}function _T(e,t){let n=new Map(Lo.value);n.set(e,t),Lo.value=n,setTimeout(()=>{let o=new Map(Lo.value);if(o.get(e)===t)o.delete(e),Lo.value=o},6000)}function ex(e,t){let n=[...Xe.value.values()].filter((r)=>r.nodeId===e&&!r.auto&&r.phase==="forming");if(n.length===0)return;let o=Kb.value;_T(e,o);for(let r of n)Io({id:r.id,kind:r.kind,label:r.label,reason:`${o} took over “${t}” mid-edit — yield and requeue the change once it is released`}).then((s)=>{if(s)Mo(r.id)});en("yieldEvent","/api/canvas/ax/event",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({kind:"yield",summary:`${o} grabbed “${t}” mid-edit — agent yielded, change requeued`,nodeIds:[e],source:"browser"})})}var Ua=null;function tx(){qa({cursor:Va,grabbingNodeId:Ir.value}),Ua=setInterval(()=>qa({grabbingNodeId:Ir.value}),3000);let e=()=>{try{navigator.sendBeacon?.("/api/canvas/human-presence",new Blob([JSON.stringify({clientId:Wa,left:!0})],{type:"application/json"}))}catch{}};return window.addEventListener("pagehide",e),()=>{if(Ua)clearInterval(Ua);Ua=null,window.removeEventListener("pagehide",e)}}var kT={markdown:{width:360,height:180},board:{width:320,height:140},context:{width:360,height:180},file:{width:360,height:200},diff:{width:420,height:240},mermaid:{width:360,height:240},status:{width:280,height:120},ledger:{width:320,height:200},image:{width:240,height:180},html:{width:420,height:280},webpage:{width:420,height:280},"json-render":{width:420,height:280},graph:{width:420,height:280},"mcp-app":{width:480,height:320}};function nx(e){return kT[e]}function ox(e,t,n,o,r){return e.x<o.position.x+o.size.width+r&&e.x+t+r>o.position.x&&e.y<o.position.y+o.size.height+r&&e.y+n+r>o.position.y}function ST(e,t,n,o,r){return o.some((s)=>ox(e,t,n,s,r))}function Xa(e,t,n,o,r){return o.find((s)=>ox(e,t,n,s,r))}function Ja(e,t,n,o=24){if(e.length===0)return{x:40,y:80};let r=e[e.length-1],s={x:r.position.x+r.size.width+o,y:r.position.y};if(!ST(s,t,n,e,o))return s;let a=40,c=80,l=3000,u=c;for(let d=0;d<20;d++){let m=a;while(m+t<l){let v=Xa({x:m,y:u},t,n,e,o);if(!v)return{x:m,y:u};m=v.position.x+v.size.width+o}u=e.filter((v)=>v.position.y<=u+n+o&&v.position.y+v.size.height+o>u).reduce((v,x)=>Math.max(v,x.position.y+x.size.height),u)+o}let p=e.reduce((d,m)=>Math.max(d,m.position.y+m.size.height),0);return{x:a,y:p+o}}var Er=37,CT=600,TT=1400,IT=24;function ET(e){return e.type==="html"||e.type==="mermaid"||e.type==="json-render"||e.type==="graph"||e.type==="mcp-app"||e.type==="webpage"}function AT(e){if(e.type==="html")return e.data.presentation!==!0;if(e.type==="mermaid")return!0;if(e.type==="json-render"||e.type==="graph")return!0;if(e.type==="mcp-app")return e.data.viewerType==="web-artifact";return!1}function rx(e){return e.collapsed===!0||e.data.strictSize===!0||e.data.userResized===!0||e.type==="group"}function ad(e){return!rx(e)&&!ET(e)}function ix(e,t){if(!ad(e)||t<=0)return null;let n=Math.min(t+Er,CT),o=nx(e.type);return o?Math.max(n,o.height):n}function cd(e){return AT(e)&&!rx(e)}function sx(e,t){if(!cd(e)||!Number.isFinite(t)||t<=0)return null;let n=Math.min(t+Er+IT,TT);return n>e.size.height+8?n:null}function ax(e,t,n){if(t<=e.size.height||e.pinned||e.data.parentGroup)return e.position;let o=n.filter((a)=>a.id!==e.id&&!a.pinned&&a.type!=="group"),r={...e.position},s=Xa(r,e.size.width,t,o,24);while(s)r.y=s.position.y+s.size.height+24,s=Xa(r,e.size.width,t,o,24);return r}function Ar(e,t,n){B(()=>{if(!n)return;let o=null,r=null,s=()=>Ir.value===e.id||zi.value.some((p)=>p.grabbingNodeId===e.id);function a(){if(o=null,s()||r===null)return;let p=r;r=null;let d=O.value.get(e.id);if(!d)return;let m=sx(d,p);if(m===null)return;let f=ax(d,m,Array.from(O.value.values())),h=f.x!==d.position.x||f.y!==d.position.y,v={size:{width:d.size.width,height:m},...h?{position:f}:{}};at(d.id,v),na([{id:d.id,...v}],{recordHistory:h})}function c(){if(o!==null)clearTimeout(o);o=r!==null&&!s()?setTimeout(a,300):null}let l=zt(()=>{s(),c()});function u(p){if(p.source!==t.current?.contentWindow)return;let d=p.data;if(!d||d.source!=="pmx-canvas-frame"||d.type!=="content-height"||d.token!==n)return;if(typeof d.height!=="number"||!Number.isFinite(d.height)||d.height<=0)return;r=d.height,c()}return window.addEventListener("message",u),()=>{if(window.removeEventListener("message",u),l(),o!==null)clearTimeout(o)}},[e.id,n])}function zT(e){try{return new URL(e,window.location.origin).origin===window.location.origin}catch{return!1}}function zr(e){let t=kt.value,[n,o]=I(null),r=Boolean(e)&&zT(e),s=t==="srcdoc"&&r;if(B(()=>{if(!s)return;let a=!1;return fetch(`${e}${e.includes("?")?"&":"?"}inline-assets=1`,{credentials:"same-origin"}).then((c)=>c.ok?c.text():Promise.reject(Error(`HTTP ${c.status}`))).then((c)=>{if(!a)o({url:e,html:c})}).catch((c)=>{if(console.error("[surface-frame] srcdoc fetch failed, falling back to src:",e,c),!a)o({url:e,html:""})}),()=>{a=!0}},[s,e]),!e)return{};if(!s)return t===null&&r?{}:{src:e};if(n)return n.html?{srcdoc:n.html}:{src:n.url};return{}}function Ka({node:e,expanded:t=!1}){let n=z(null),o=nt.value,r=Se(()=>`theme-${crypto.randomUUID()}`,[]),s=Se(()=>`frame-${crypto.randomUUID()}`,[]),a=typeof e.data.content==="string"?e.data.content:"",c=e.data.fit==="none"?"none":"contain",l=Se(()=>Sr(`${c}:${a}`),[a,c]),u=Se(()=>a?Ii(e.id,{theme:o,themeToken:r,v:l,frameToken:s}):"",[a,r,l,e.id,s]),p=zr(u);Ar(e,n,t?"":s);let d=()=>{n.current?.contentWindow?.postMessage({source:qt,type:"theme-update",token:r,theme:o},"*")};if(B(d,[o,r]),!a)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No diagram source set"},void 0,!1,void 0,this);return i("iframe",{ref:n,class:"html-node-frame",title:typeof e.data.title==="string"?e.data.title:"Mermaid diagram",sandbox:"allow-scripts",...p,onLoad:d,style:{width:"100%",height:"100%",minHeight:t?"70vh":"0",border:"none",background:"var(--c-bg)",borderRadius:"6px",display:"block"}},void 0,!1,void 0,this)}var ld=["dark","light","high-contrast","midnight","sepia","arctic","ember","forest","volt"];function Pi(e){return typeof e==="string"&&ld.includes(e)}function ud(e,t="dark"){return Pi(e)?e:t}var Pr={dark:{label:"Dark",scheme:"dark",swatchBg:"#081524",swatchAccent:"#4BBCFF"},light:{label:"Light",scheme:"light",swatchBg:"#F4EFE6",swatchAccent:"#1A7ABF"},"high-contrast":{label:"High contrast",scheme:"dark",swatchBg:"#000000",swatchAccent:"#00ffff"},midnight:{label:"Midnight",scheme:"dark",swatchBg:"#0A0D1C",swatchAccent:"#8B96FF"},sepia:{label:"Sepia",scheme:"light",swatchBg:"#F2E7D5",swatchAccent:"#B4632C"},arctic:{label:"Arctic",scheme:"dark",swatchBg:"#20242E",swatchAccent:"#7FC8DE"},ember:{label:"Ember",scheme:"dark",swatchBg:"#0B0B0C",swatchAccent:"#F34E1C"},forest:{label:"Forest",scheme:"dark",swatchBg:"#0C1712",swatchAccent:"#5CCF8F"},volt:{label:"Volt",scheme:"dark",swatchBg:"#0B0D0B",swatchAccent:"#DFDFC1"}};function Nr(e){return Pr[ud(e)].scheme}var no="io.modelcontextprotocol/related-task",Qa="2.0",ft=tv((e)=>e!==null&&(typeof e==="object"||typeof e==="function")),cx=he([C(),ae().int()]),lx=C(),aL=Tt({ttl:he([ae(),Jl()]).optional(),pollInterval:ae().optional()}),PT=A({ttl:ae().optional()}),NT=A({taskId:C()}),dd=Tt({progressToken:cx.optional(),[no]:NT.optional()}),Ft=A({_meta:dd.optional()}),Ni=Ft.extend({task:PT.optional()}),ux=(e)=>Ni.safeParse(e).success,ht=A({method:C(),params:Ft.loose().optional()}),Wt=A({_meta:dd.optional()}),Vt=A({method:C(),params:Wt.loose().optional()}),gt=Tt({_meta:dd.optional()}),$r=he([C(),ae().int()]),dx=A({jsonrpc:S(Qa),id:$r,...ht.shape}).strict(),pd=(e)=>dx.safeParse(e).success,px=A({jsonrpc:S(Qa),...Vt.shape}).strict(),mx=(e)=>px.safeParse(e).success,md=A({jsonrpc:S(Qa),id:$r,result:gt}).strict(),Ri=(e)=>md.safeParse(e).success;var Ie;(function(e){e[e.ConnectionClosed=-32000]="ConnectionClosed",e[e.RequestTimeout=-32001]="RequestTimeout",e[e.ParseError=-32700]="ParseError",e[e.InvalidRequest=-32600]="InvalidRequest",e[e.MethodNotFound=-32601]="MethodNotFound",e[e.InvalidParams=-32602]="InvalidParams",e[e.InternalError=-32603]="InternalError",e[e.UrlElicitationRequired=-32042]="UrlElicitationRequired"})(Ie||(Ie={}));var fd=A({jsonrpc:S(Qa),id:$r.optional(),error:A({code:ae().int(),message:C(),data:ze().optional()})}).strict();var fx=(e)=>fd.safeParse(e).success;var hx=he([dx,px,md,fd]),cL=he([md,fd]),hd=gt.strict(),RT=Wt.extend({requestId:$r.optional(),reason:C().optional()}),ec=Vt.extend({method:S("notifications/cancelled"),params:RT}),$T=A({src:C(),mimeType:C().optional(),sizes:re(C()).optional(),theme:It(["light","dark"]).optional()}),$i=A({icons:re($T).optional()}),Rr=A({name:C(),title:C().optional()}),Mi=Rr.extend({...Rr.shape,...$i.shape,version:C(),websiteUrl:C().optional(),description:C().optional()}),MT=Ms(A({applyDefaults:Re().optional()}),Ee(C(),ze())),LT=Ql((e)=>{if(e&&typeof e==="object"&&!Array.isArray(e)){if(Object.keys(e).length===0)return{form:{}}}return e},Ms(A({form:MT.optional(),url:ft.optional()}),Ee(C(),ze()).optional())),OT=Tt({list:ft.optional(),cancel:ft.optional(),requests:Tt({sampling:Tt({createMessage:ft.optional()}).optional(),elicitation:Tt({create:ft.optional()}).optional()}).optional()}),DT=Tt({list:ft.optional(),cancel:ft.optional(),requests:Tt({tools:Tt({call:ft.optional()}).optional()}).optional()}),FT=A({experimental:Ee(C(),ft).optional(),sampling:A({context:ft.optional(),tools:ft.optional()}).optional(),elicitation:LT.optional(),roots:A({listChanged:Re().optional()}).optional(),tasks:OT.optional()}),BT=Ft.extend({protocolVersion:C(),capabilities:FT,clientInfo:Mi}),HT=ht.extend({method:S("initialize"),params:BT});var jT=A({experimental:Ee(C(),ft).optional(),logging:ft.optional(),completions:ft.optional(),prompts:A({listChanged:Re().optional()}).optional(),resources:A({subscribe:Re().optional(),listChanged:Re().optional()}).optional(),tools:A({listChanged:Re().optional()}).optional(),tasks:DT.optional()}),ZT=gt.extend({protocolVersion:C(),capabilities:jT,serverInfo:Mi,instructions:C().optional()}),UT=Vt.extend({method:S("notifications/initialized"),params:Wt.optional()});var Oo=ht.extend({method:S("ping"),params:Ft.optional()}),qT=A({progress:ae(),total:Ge(ae()),message:Ge(C())}),WT=A({...Wt.shape,...qT.shape,progressToken:cx}),tc=Vt.extend({method:S("notifications/progress"),params:WT}),VT=Ft.extend({cursor:lx.optional()}),Li=ht.extend({params:VT.optional()}),Oi=gt.extend({nextCursor:lx.optional()}),GT=It(["working","input_required","completed","failed","cancelled"]),Di=A({taskId:C(),status:GT,ttl:he([ae(),Jl()]),createdAt:C(),lastUpdatedAt:C(),pollInterval:Ge(ae()),statusMessage:Ge(C())}),nc=gt.extend({task:Di}),XT=Wt.merge(Di),Fi=Vt.extend({method:S("notifications/tasks/status"),params:XT}),oc=ht.extend({method:S("tasks/get"),params:Ft.extend({taskId:C()})}),rc=gt.merge(Di),ic=ht.extend({method:S("tasks/result"),params:Ft.extend({taskId:C()})}),lL=gt.loose(),sc=Li.extend({method:S("tasks/list")}),ac=Oi.extend({tasks:re(Di)}),cc=ht.extend({method:S("tasks/cancel"),params:Ft.extend({taskId:C()})}),gx=gt.merge(Di),vx=A({uri:C(),mimeType:Ge(C()),_meta:Ee(C(),ze()).optional()}),yx=vx.extend({text:C()}),gd=C().refine((e)=>{try{return atob(e),!0}catch{return!1}},{message:"Invalid Base64 string"}),bx=vx.extend({blob:gd}),Bi=It(["user","assistant"]),Mr=A({audience:re(Bi).optional(),priority:ae().min(0).max(1).optional(),lastModified:ql({offset:!0}).optional()}),xx=A({...Rr.shape,...$i.shape,uri:C(),description:Ge(C()),mimeType:Ge(C()),annotations:Mr.optional(),_meta:Ge(Tt({}))}),JT=A({...Rr.shape,...$i.shape,uriTemplate:C(),description:Ge(C()),mimeType:Ge(C()),annotations:Mr.optional(),_meta:Ge(Tt({}))}),vd=Li.extend({method:S("resources/list")}),lc=Oi.extend({resources:re(xx)}),yd=Li.extend({method:S("resources/templates/list")}),bd=Oi.extend({resourceTemplates:re(JT)}),xd=Ft.extend({uri:C()}),KT=xd,wd=ht.extend({method:S("resources/read"),params:KT}),uc=gt.extend({contents:re(he([yx,bx]))}),_d=Vt.extend({method:S("notifications/resources/list_changed"),params:Wt.optional()}),YT=xd,QT=ht.extend({method:S("resources/subscribe"),params:YT}),eI=xd,tI=ht.extend({method:S("resources/unsubscribe"),params:eI}),nI=Wt.extend({uri:C()}),oI=Vt.extend({method:S("notifications/resources/updated"),params:nI}),rI=A({name:C(),description:Ge(C()),required:Ge(Re())}),iI=A({...Rr.shape,...$i.shape,description:Ge(C()),arguments:Ge(re(rI)),_meta:Ge(Tt({}))}),kd=Li.extend({method:S("prompts/list")}),Sd=Oi.extend({prompts:re(iI)}),sI=Ft.extend({name:C(),arguments:Ee(C(),C()).optional()}),aI=ht.extend({method:S("prompts/get"),params:sI}),Cd=A({type:S("text"),text:C(),annotations:Mr.optional(),_meta:Ee(C(),ze()).optional()}),Td=A({type:S("image"),data:gd,mimeType:C(),annotations:Mr.optional(),_meta:Ee(C(),ze()).optional()}),Id=A({type:S("audio"),data:gd,mimeType:C(),annotations:Mr.optional(),_meta:Ee(C(),ze()).optional()}),cI=A({type:S("tool_use"),name:C(),id:C(),input:Ee(C(),ze()),_meta:Ee(C(),ze()).optional()}),Ed=A({type:S("resource"),resource:he([yx,bx]),annotations:Mr.optional(),_meta:Ee(C(),ze()).optional()}),Ad=xx.extend({type:S("resource_link")}),Lr=he([Cd,Td,Id,Ad,Ed]),lI=A({role:Bi,content:Lr}),uI=gt.extend({description:C().optional(),messages:re(lI)}),zd=Vt.extend({method:S("notifications/prompts/list_changed"),params:Wt.optional()}),dI=A({title:C().optional(),readOnlyHint:Re().optional(),destructiveHint:Re().optional(),idempotentHint:Re().optional(),openWorldHint:Re().optional()}),pI=A({taskSupport:It(["required","optional","forbidden"]).optional()}),dc=A({...Rr.shape,...$i.shape,description:C().optional(),inputSchema:A({type:S("object"),properties:Ee(C(),ft).optional(),required:re(C()).optional()}).catchall(ze()),outputSchema:A({type:S("object"),properties:Ee(C(),ft).optional(),required:re(C()).optional()}).catchall(ze()).optional(),annotations:dI.optional(),execution:pI.optional(),_meta:Ee(C(),ze()).optional()}),pc=Li.extend({method:S("tools/list")}),mI=Oi.extend({tools:re(dc)}),Do=gt.extend({content:re(Lr).default([]),structuredContent:Ee(C(),ze()).optional(),isError:Re().optional()}),uL=Do.or(gt.extend({toolResult:ze()})),fI=Ni.extend({name:C(),arguments:Ee(C(),ze()).optional()}),mc=ht.extend({method:S("tools/call"),params:fI}),Pd=Vt.extend({method:S("notifications/tools/list_changed"),params:Wt.optional()}),dL=A({autoRefresh:Re().default(!0),debounceMs:ae().int().nonnegative().default(300)}),wx=It(["debug","info","notice","warning","error","critical","alert","emergency"]),hI=Ft.extend({level:wx}),gI=ht.extend({method:S("logging/setLevel"),params:hI}),vI=Wt.extend({level:wx,logger:C().optional(),data:ze()}),Nd=Vt.extend({method:S("notifications/message"),params:vI}),yI=A({name:C().optional()}),bI=A({hints:re(yI).optional(),costPriority:ae().min(0).max(1).optional(),speedPriority:ae().min(0).max(1).optional(),intelligencePriority:ae().min(0).max(1).optional()}),xI=A({mode:It(["auto","required","none"]).optional()}),wI=A({type:S("tool_result"),toolUseId:C().describe("The unique identifier for the corresponding tool call."),content:re(Lr).default([]),structuredContent:A({}).loose().optional(),isError:Re().optional(),_meta:Ee(C(),ze()).optional()}),_I=Yl("type",[Cd,Td,Id]),Ya=Yl("type",[Cd,Td,Id,cI,wI]),kI=A({role:Bi,content:he([Ya,re(Ya)]),_meta:Ee(C(),ze()).optional()}),SI=Ni.extend({messages:re(kI),modelPreferences:bI.optional(),systemPrompt:C().optional(),includeContext:It(["none","thisServer","allServers"]).optional(),temperature:ae().optional(),maxTokens:ae().int(),stopSequences:re(C()).optional(),metadata:ft.optional(),tools:re(dc).optional(),toolChoice:xI.optional()}),CI=ht.extend({method:S("sampling/createMessage"),params:SI}),TI=gt.extend({model:C(),stopReason:Ge(It(["endTurn","stopSequence","maxTokens"]).or(C())),role:Bi,content:_I}),II=gt.extend({model:C(),stopReason:Ge(It(["endTurn","stopSequence","maxTokens","toolUse"]).or(C())),role:Bi,content:he([Ya,re(Ya)])}),EI=A({type:S("boolean"),title:C().optional(),description:C().optional(),default:Re().optional()}),AI=A({type:S("string"),title:C().optional(),description:C().optional(),minLength:ae().optional(),maxLength:ae().optional(),format:It(["email","uri","date","date-time"]).optional(),default:C().optional()}),zI=A({type:It(["number","integer"]),title:C().optional(),description:C().optional(),minimum:ae().optional(),maximum:ae().optional(),default:ae().optional()}),PI=A({type:S("string"),title:C().optional(),description:C().optional(),enum:re(C()),default:C().optional()}),NI=A({type:S("string"),title:C().optional(),description:C().optional(),oneOf:re(A({const:C(),title:C()})),default:C().optional()}),RI=A({type:S("string"),title:C().optional(),description:C().optional(),enum:re(C()),enumNames:re(C()).optional(),default:C().optional()}),$I=he([PI,NI]),MI=A({type:S("array"),title:C().optional(),description:C().optional(),minItems:ae().optional(),maxItems:ae().optional(),items:A({type:S("string"),enum:re(C())}),default:re(C()).optional()}),LI=A({type:S("array"),title:C().optional(),description:C().optional(),minItems:ae().optional(),maxItems:ae().optional(),items:A({anyOf:re(A({const:C(),title:C()}))}),default:re(C()).optional()}),OI=he([MI,LI]),DI=he([RI,$I,OI]),FI=he([DI,EI,AI,zI]),BI=Ni.extend({mode:S("form").optional(),message:C(),requestedSchema:A({type:S("object"),properties:Ee(C(),FI),required:re(C()).optional()})}),HI=Ni.extend({mode:S("url"),message:C(),elicitationId:C(),url:C().url()}),jI=he([BI,HI]),ZI=ht.extend({method:S("elicitation/create"),params:jI}),UI=Wt.extend({elicitationId:C()}),qI=Vt.extend({method:S("notifications/elicitation/complete"),params:UI}),WI=gt.extend({action:It(["accept","decline","cancel"]),content:Ql((e)=>e===null?void 0:e,Ee(C(),he([C(),ae(),Re(),re(C())])).optional())}),VI=A({type:S("ref/resource"),uri:C()});var GI=A({type:S("ref/prompt"),name:C()}),XI=Ft.extend({ref:he([GI,VI]),argument:A({name:C(),value:C()}),context:A({arguments:Ee(C(),C()).optional()}).optional()}),JI=ht.extend({method:S("completion/complete"),params:XI});var KI=gt.extend({completion:Tt({values:re(C()).max(100),total:Ge(ae().int()),hasMore:Ge(Re())})}),YI=A({uri:C().startsWith("file://"),name:C().optional(),_meta:Ee(C(),ze()).optional()}),QI=ht.extend({method:S("roots/list"),params:Ft.optional()}),eE=gt.extend({roots:re(YI)}),tE=Vt.extend({method:S("notifications/roots/list_changed"),params:Wt.optional()}),pL=he([Oo,HT,JI,gI,aI,kd,vd,yd,wd,QT,tI,mc,pc,oc,ic,sc,cc]),mL=he([ec,tc,UT,tE,Fi]),fL=he([hd,TI,II,WI,eE,rc,ac,nc]),hL=he([Oo,CI,ZI,QI,oc,ic,sc,cc]),gL=he([ec,tc,Nd,oI,_d,Pd,zd,Fi,qI]),vL=he([hd,ZT,KI,uI,Sd,lc,bd,uc,Do,mI,rc,ac,nc]);class xe extends Error{constructor(e,t,n){super(`MCP error ${e}: ${t}`);this.code=e,this.data=n,this.name="McpError"}static fromError(e,t,n){if(e===Ie.UrlElicitationRequired&&n){let o=n;if(o.elicitations)return new _x(o.elicitations,t)}return new xe(e,t,n)}}class _x extends xe{constructor(e,t=`URL elicitation${e.length>1?"s":""} required`){super(Ie.UrlElicitationRequired,t,{elicitations:e})}get elicitations(){return this.data?.elicitations??[]}}function fc(e){return!!e._zod}function hc(e,t){if(fc(e))return ri(e,t);return e.safeParse(t)}function kx(e){if(!e)return;let t;if(fc(e))t=e._zod?.def?.shape;else t=e.shape;if(!t)return;if(typeof t==="function")try{return t()}catch{return}return t}function Sx(e){if(fc(e)){let s=e._zod?.def;if(s){if(s.value!==void 0)return s.value;if(Array.isArray(s.values)&&s.values.length>0)return s.values[0]}}let n=e._def;if(n){if(n.value!==void 0)return n.value;if(Array.isArray(n.values)&&n.values.length>0)return n.values[0]}let o=e.value;if(o!==void 0)return o;return}function oo(e){return e==="completed"||e==="failed"||e==="cancelled"}var nE=Symbol("Let zodToJsonSchema decide on which parser to use");var lO=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function Rd(e){let n=kx(e)?.method;if(!n)throw Error("Schema is missing a method literal");let o=Sx(n);if(typeof o!=="string")throw Error("Schema method literal must be a string");return o}function $d(e,t){let n=hc(e,t);if(!n.success)throw n.error;return n.data}var cE=60000;class gc{constructor(e){if(this._options=e,this._requestMessageId=0,this._requestHandlers=new Map,this._requestHandlerAbortControllers=new Map,this._notificationHandlers=new Map,this._responseHandlers=new Map,this._progressHandlers=new Map,this._timeoutInfo=new Map,this._pendingDebouncedNotifications=new Set,this._taskProgressTokens=new Map,this._requestResolvers=new Map,this.setNotificationHandler(ec,(t)=>{this._oncancel(t)}),this.setNotificationHandler(tc,(t)=>{this._onprogress(t)}),this.setRequestHandler(Oo,(t)=>({})),this._taskStore=e?.taskStore,this._taskMessageQueue=e?.taskMessageQueue,this._taskStore)this.setRequestHandler(oc,async(t,n)=>{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new xe(Ie.InvalidParams,"Failed to retrieve task: Task not found");return{...o}}),this.setRequestHandler(ic,async(t,n)=>{let o=async()=>{let r=t.params.taskId;if(this._taskMessageQueue){let a;while(a=await this._taskMessageQueue.dequeue(r,n.sessionId)){if(a.type==="response"||a.type==="error"){let c=a.message,l=c.id,u=this._requestResolvers.get(l);if(u)if(this._requestResolvers.delete(l),a.type==="response")u(c);else{let p=c,d=new xe(p.error.code,p.error.message,p.error.data);u(d)}else{let p=a.type==="response"?"Response":"Error";this._onerror(Error(`${p} handler missing for request ${l}`))}continue}await this._transport?.send(a.message,{relatedRequestId:n.requestId})}}let s=await this._taskStore.getTask(r,n.sessionId);if(!s)throw new xe(Ie.InvalidParams,`Task not found: ${r}`);if(!oo(s.status))return await this._waitForTaskUpdate(r,n.signal),await o();if(oo(s.status)){let a=await this._taskStore.getTaskResult(r,n.sessionId);return this._clearTaskQueue(r),{...a,_meta:{...a._meta,[no]:{taskId:r}}}}return await o()};return await o()}),this.setRequestHandler(sc,async(t,n)=>{try{let{tasks:o,nextCursor:r}=await this._taskStore.listTasks(t.params?.cursor,n.sessionId);return{tasks:o,nextCursor:r,_meta:{}}}catch(o){throw new xe(Ie.InvalidParams,`Failed to list tasks: ${o instanceof Error?o.message:String(o)}`)}}),this.setRequestHandler(cc,async(t,n)=>{try{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new xe(Ie.InvalidParams,`Task not found: ${t.params.taskId}`);if(oo(o.status))throw new xe(Ie.InvalidParams,`Cannot cancel task in terminal status: ${o.status}`);await this._taskStore.updateTaskStatus(t.params.taskId,"cancelled","Client cancelled task execution.",n.sessionId),this._clearTaskQueue(t.params.taskId);let r=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!r)throw new xe(Ie.InvalidParams,`Task not found after cancellation: ${t.params.taskId}`);return{_meta:{},...r}}catch(o){if(o instanceof xe)throw o;throw new xe(Ie.InvalidRequest,`Failed to cancel task: ${o instanceof Error?o.message:String(o)}`)}})}async _oncancel(e){if(!e.params.requestId)return;this._requestHandlerAbortControllers.get(e.params.requestId)?.abort(e.params.reason)}_setupTimeout(e,t,n,o,r=!1){this._timeoutInfo.set(e,{timeoutId:setTimeout(o,t),startTime:Date.now(),timeout:t,maxTotalTimeout:n,resetTimeoutOnProgress:r,onTimeout:o})}_resetTimeout(e){let t=this._timeoutInfo.get(e);if(!t)return!1;let n=Date.now()-t.startTime;if(t.maxTotalTimeout&&n>=t.maxTotalTimeout)throw this._timeoutInfo.delete(e),xe.fromError(Ie.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:t.maxTotalTimeout,totalElapsed:n});return clearTimeout(t.timeoutId),t.timeoutId=setTimeout(t.onTimeout,t.timeout),!0}_cleanupTimeout(e){let t=this._timeoutInfo.get(e);if(t)clearTimeout(t.timeoutId),this._timeoutInfo.delete(e)}async connect(e){if(this._transport)throw Error("Already connected to a transport. Call close() before connecting to a new transport, or use a separate Protocol instance per connection.");this._transport=e;let t=this.transport?.onclose;this._transport.onclose=()=>{t?.(),this._onclose()};let n=this.transport?.onerror;this._transport.onerror=(r)=>{n?.(r),this._onerror(r)};let o=this._transport?.onmessage;this._transport.onmessage=(r,s)=>{if(o?.(r,s),Ri(r)||fx(r))this._onresponse(r);else if(pd(r))this._onrequest(r,s);else if(mx(r))this._onnotification(r);else this._onerror(Error(`Unknown message type: ${JSON.stringify(r)}`))},await this._transport.start()}_onclose(){let e=this._responseHandlers;this._responseHandlers=new Map,this._progressHandlers.clear(),this._taskProgressTokens.clear(),this._pendingDebouncedNotifications.clear();for(let n of this._timeoutInfo.values())clearTimeout(n.timeoutId);this._timeoutInfo.clear();for(let n of this._requestHandlerAbortControllers.values())n.abort();this._requestHandlerAbortControllers.clear();let t=xe.fromError(Ie.ConnectionClosed,"Connection closed");this._transport=void 0,this.onclose?.();for(let n of e.values())n(t)}_onerror(e){this.onerror?.(e)}_onnotification(e){let t=this._notificationHandlers.get(e.method)??this.fallbackNotificationHandler;if(t===void 0)return;Promise.resolve().then(()=>t(e)).catch((n)=>this._onerror(Error(`Uncaught error in notification handler: ${n}`)))}_onrequest(e,t){let n=this._requestHandlers.get(e.method)??this.fallbackRequestHandler,o=this._transport,r=e.params?._meta?.[no]?.taskId;if(n===void 0){let u={jsonrpc:"2.0",id:e.id,error:{code:Ie.MethodNotFound,message:"Method not found"}};if(r&&this._taskMessageQueue)this._enqueueTaskMessage(r,{type:"error",message:u,timestamp:Date.now()},o?.sessionId).catch((p)=>this._onerror(Error(`Failed to enqueue error response: ${p}`)));else o?.send(u).catch((p)=>this._onerror(Error(`Failed to send an error response: ${p}`)));return}let s=new AbortController;this._requestHandlerAbortControllers.set(e.id,s);let a=ux(e.params)?e.params.task:void 0,c=this._taskStore?this.requestTaskStore(e,o?.sessionId):void 0,l={signal:s.signal,sessionId:o?.sessionId,_meta:e.params?._meta,sendNotification:async(u)=>{if(s.signal.aborted)return;let p={relatedRequestId:e.id};if(r)p.relatedTask={taskId:r};await this.notification(u,p)},sendRequest:async(u,p,d)=>{if(s.signal.aborted)throw new xe(Ie.ConnectionClosed,"Request was cancelled");let m={...d,relatedRequestId:e.id};if(r&&!m.relatedTask)m.relatedTask={taskId:r};let f=m.relatedTask?.taskId??r;if(f&&c)await c.updateTaskStatus(f,"input_required");return await this.request(u,p,m)},authInfo:t?.authInfo,requestId:e.id,requestInfo:t?.requestInfo,taskId:r,taskStore:c,taskRequestedTtl:a?.ttl,closeSSEStream:t?.closeSSEStream,closeStandaloneSSEStream:t?.closeStandaloneSSEStream};Promise.resolve().then(()=>{if(a)this.assertTaskHandlerCapability(e.method)}).then(()=>n(e,l)).then(async(u)=>{if(s.signal.aborted)return;let p={result:u,jsonrpc:"2.0",id:e.id};if(r&&this._taskMessageQueue)await this._enqueueTaskMessage(r,{type:"response",message:p,timestamp:Date.now()},o?.sessionId);else await o?.send(p)},async(u)=>{if(s.signal.aborted)return;let p={jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(u.code)?u.code:Ie.InternalError,message:u.message??"Internal error",...u.data!==void 0&&{data:u.data}}};if(r&&this._taskMessageQueue)await this._enqueueTaskMessage(r,{type:"error",message:p,timestamp:Date.now()},o?.sessionId);else await o?.send(p)}).catch((u)=>this._onerror(Error(`Failed to send response: ${u}`))).finally(()=>{if(this._requestHandlerAbortControllers.get(e.id)===s)this._requestHandlerAbortControllers.delete(e.id)})}_onprogress(e){let{progressToken:t,...n}=e.params,o=Number(t),r=this._progressHandlers.get(o);if(!r){this._onerror(Error(`Received a progress notification for an unknown token: ${JSON.stringify(e)}`));return}let s=this._responseHandlers.get(o),a=this._timeoutInfo.get(o);if(a&&s&&a.resetTimeoutOnProgress)try{this._resetTimeout(o)}catch(c){this._responseHandlers.delete(o),this._progressHandlers.delete(o),this._cleanupTimeout(o),s(c);return}r(n)}_onresponse(e){let t=Number(e.id),n=this._requestResolvers.get(t);if(n){if(this._requestResolvers.delete(t),Ri(e))n(e);else{let s=new xe(e.error.code,e.error.message,e.error.data);n(s)}return}let o=this._responseHandlers.get(t);if(o===void 0){this._onerror(Error(`Received a response for an unknown message ID: ${JSON.stringify(e)}`));return}this._responseHandlers.delete(t),this._cleanupTimeout(t);let r=!1;if(Ri(e)&&e.result&&typeof e.result==="object"){let s=e.result;if(s.task&&typeof s.task==="object"){let a=s.task;if(typeof a.taskId==="string")r=!0,this._taskProgressTokens.set(a.taskId,t)}}if(!r)this._progressHandlers.delete(t);if(Ri(e))o(e);else{let s=xe.fromError(e.error.code,e.error.message,e.error.data);o(s)}}get transport(){return this._transport}async close(){await this._transport?.close()}async*requestStream(e,t,n){let{task:o}=n??{};if(!o){try{yield{type:"result",result:await this.request(e,t,n)}}catch(s){yield{type:"error",error:s instanceof xe?s:new xe(Ie.InternalError,String(s))}}return}let r;try{let s=await this.request(e,nc,n);if(s.task)r=s.task.taskId,yield{type:"taskCreated",task:s.task};else throw new xe(Ie.InternalError,"Task creation did not return a task");while(!0){let a=await this.getTask({taskId:r},n);if(yield{type:"taskStatus",task:a},oo(a.status)){if(a.status==="completed")yield{type:"result",result:await this.getTaskResult({taskId:r},t,n)};else if(a.status==="failed")yield{type:"error",error:new xe(Ie.InternalError,`Task ${r} failed`)};else if(a.status==="cancelled")yield{type:"error",error:new xe(Ie.InternalError,`Task ${r} was cancelled`)};return}if(a.status==="input_required"){yield{type:"result",result:await this.getTaskResult({taskId:r},t,n)};return}let c=a.pollInterval??this._options?.defaultTaskPollInterval??1000;await new Promise((l)=>setTimeout(l,c)),n?.signal?.throwIfAborted()}}catch(s){yield{type:"error",error:s instanceof xe?s:new xe(Ie.InternalError,String(s))}}}request(e,t,n){let{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s,task:a,relatedTask:c}=n??{};return new Promise((l,u)=>{let p=(g)=>{u(g)};if(!this._transport){p(Error("Not connected"));return}if(this._options?.enforceStrictCapabilities===!0)try{if(this.assertCapabilityForMethod(e.method),a)this.assertTaskCapability(e.method)}catch(g){p(g);return}n?.signal?.throwIfAborted();let d=this._requestMessageId++,m={...e,jsonrpc:"2.0",id:d};if(n?.onprogress)this._progressHandlers.set(d,n.onprogress),m.params={...e.params,_meta:{...e.params?._meta||{},progressToken:d}};if(a)m.params={...m.params,task:a};if(c)m.params={...m.params,_meta:{...m.params?._meta||{},[no]:c}};let f=(g)=>{this._responseHandlers.delete(d),this._progressHandlers.delete(d),this._cleanupTimeout(d),this._transport?.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:d,reason:String(g)}},{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s}).catch((E)=>this._onerror(Error(`Failed to send cancellation: ${E}`)));let y=g instanceof xe?g:new xe(Ie.RequestTimeout,String(g));u(y)};this._responseHandlers.set(d,(g)=>{if(n?.signal?.aborted)return;if(g instanceof Error)return u(g);try{let y=hc(t,g.result);if(!y.success)u(y.error);else l(y.data)}catch(y){u(y)}}),n?.signal?.addEventListener("abort",()=>{f(n?.signal?.reason)});let h=n?.timeout??cE,v=()=>f(xe.fromError(Ie.RequestTimeout,"Request timed out",{timeout:h}));this._setupTimeout(d,h,n?.maxTotalTimeout,v,n?.resetTimeoutOnProgress??!1);let x=c?.taskId;if(x){let g=(y)=>{let E=this._responseHandlers.get(d);if(E)E(y);else this._onerror(Error(`Response handler missing for side-channeled request ${d}`))};this._requestResolvers.set(d,g),this._enqueueTaskMessage(x,{type:"request",message:m,timestamp:Date.now()}).catch((y)=>{this._cleanupTimeout(d),u(y)})}else this._transport.send(m,{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s}).catch((g)=>{this._cleanupTimeout(d),u(g)})})}async getTask(e,t){return this.request({method:"tasks/get",params:e},rc,t)}async getTaskResult(e,t,n){return this.request({method:"tasks/result",params:e},t,n)}async listTasks(e,t){return this.request({method:"tasks/list",params:e},ac,t)}async cancelTask(e,t){return this.request({method:"tasks/cancel",params:e},gx,t)}async notification(e,t){if(!this._transport)throw Error("Not connected");this.assertNotificationCapability(e.method);let n=t?.relatedTask?.taskId;if(n){let a={...e,jsonrpc:"2.0",params:{...e.params,_meta:{...e.params?._meta||{},[no]:t.relatedTask}}};await this._enqueueTaskMessage(n,{type:"notification",message:a,timestamp:Date.now()});return}if((this._options?.debouncedNotificationMethods??[]).includes(e.method)&&!e.params&&!t?.relatedRequestId&&!t?.relatedTask){if(this._pendingDebouncedNotifications.has(e.method))return;this._pendingDebouncedNotifications.add(e.method),Promise.resolve().then(()=>{if(this._pendingDebouncedNotifications.delete(e.method),!this._transport)return;let a={...e,jsonrpc:"2.0"};if(t?.relatedTask)a={...a,params:{...a.params,_meta:{...a.params?._meta||{},[no]:t.relatedTask}}};this._transport?.send(a,t).catch((c)=>this._onerror(c))});return}let s={...e,jsonrpc:"2.0"};if(t?.relatedTask)s={...s,params:{...s.params,_meta:{...s.params?._meta||{},[no]:t.relatedTask}}};await this._transport.send(s,t)}setRequestHandler(e,t){let n=Rd(e);this.assertRequestHandlerCapability(n),this._requestHandlers.set(n,(o,r)=>{let s=$d(e,o);return Promise.resolve(t(s,r))})}removeRequestHandler(e){this._requestHandlers.delete(e)}assertCanSetRequestHandler(e){if(this._requestHandlers.has(e))throw Error(`A request handler for ${e} already exists, which would be overridden`)}setNotificationHandler(e,t){let n=Rd(e);this._notificationHandlers.set(n,(o)=>{let r=$d(e,o);return Promise.resolve(t(r))})}removeNotificationHandler(e){this._notificationHandlers.delete(e)}_cleanupTaskProgressHandler(e){let t=this._taskProgressTokens.get(e);if(t!==void 0)this._progressHandlers.delete(t),this._taskProgressTokens.delete(e)}async _enqueueTaskMessage(e,t,n){if(!this._taskStore||!this._taskMessageQueue)throw Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");let o=this._options?.maxTaskQueueSize;await this._taskMessageQueue.enqueue(e,t,n,o)}async _clearTaskQueue(e,t){if(this._taskMessageQueue){let n=await this._taskMessageQueue.dequeueAll(e,t);for(let o of n)if(o.type==="request"&&pd(o.message)){let r=o.message.id,s=this._requestResolvers.get(r);if(s)s(new xe(Ie.InternalError,"Task cancelled or completed")),this._requestResolvers.delete(r);else this._onerror(Error(`Resolver missing for request ${r} during task ${e} cleanup`))}}}async _waitForTaskUpdate(e,t){let n=this._options?.defaultTaskPollInterval??1000;try{let o=await this._taskStore?.getTask(e);if(o?.pollInterval)n=o.pollInterval}catch{}return new Promise((o,r)=>{if(t.aborted){r(new xe(Ie.InvalidRequest,"Request cancelled"));return}let s=setTimeout(o,n);t.addEventListener("abort",()=>{clearTimeout(s),r(new xe(Ie.InvalidRequest,"Request cancelled"))},{once:!0})})}requestTaskStore(e,t){let n=this._taskStore;if(!n)throw Error("No task store configured");return{createTask:async(o)=>{if(!e)throw Error("No request provided");return await n.createTask(o,e.id,{method:e.method,params:e.params},t)},getTask:async(o)=>{let r=await n.getTask(o,t);if(!r)throw new xe(Ie.InvalidParams,"Failed to retrieve task: Task not found");return r},storeTaskResult:async(o,r,s)=>{await n.storeTaskResult(o,r,s,t);let a=await n.getTask(o,t);if(a){let c=Fi.parse({method:"notifications/tasks/status",params:a});if(await this.notification(c),oo(a.status))this._cleanupTaskProgressHandler(o)}},getTaskResult:(o)=>n.getTaskResult(o,t),updateTaskStatus:async(o,r,s)=>{let a=await n.getTask(o,t);if(!a)throw new xe(Ie.InvalidParams,`Task "${o}" not found - it may have been cleaned up`);if(oo(a.status))throw new xe(Ie.InvalidParams,`Cannot update task "${o}" from terminal status "${a.status}" to "${r}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);await n.updateTaskStatus(o,r,s,t);let c=await n.getTask(o,t);if(c){let l=Fi.parse({method:"notifications/tasks/status",params:c});if(await this.notification(l),oo(c.status))this._cleanupTaskProgressHandler(o)}},listTasks:(o)=>n.listTasks(o,t)}}}var Ix="2026-01-26";var lE="ui/notifications/tool-input-partial";var uE=he([S("light"),S("dark")]).describe("Color theme preference for the host environment."),ji=he([S("inline"),S("fullscreen"),S("pip")]).describe("Display mode for UI presentation."),dE=he([S("--color-background-primary"),S("--color-background-secondary"),S("--color-background-tertiary"),S("--color-background-inverse"),S("--color-background-ghost"),S("--color-background-info"),S("--color-background-danger"),S("--color-background-success"),S("--color-background-warning"),S("--color-background-disabled"),S("--color-text-primary"),S("--color-text-secondary"),S("--color-text-tertiary"),S("--color-text-inverse"),S("--color-text-ghost"),S("--color-text-info"),S("--color-text-danger"),S("--color-text-success"),S("--color-text-warning"),S("--color-text-disabled"),S("--color-border-primary"),S("--color-border-secondary"),S("--color-border-tertiary"),S("--color-border-inverse"),S("--color-border-ghost"),S("--color-border-info"),S("--color-border-danger"),S("--color-border-success"),S("--color-border-warning"),S("--color-border-disabled"),S("--color-ring-primary"),S("--color-ring-secondary"),S("--color-ring-inverse"),S("--color-ring-info"),S("--color-ring-danger"),S("--color-ring-success"),S("--color-ring-warning"),S("--font-sans"),S("--font-mono"),S("--font-weight-normal"),S("--font-weight-medium"),S("--font-weight-semibold"),S("--font-weight-bold"),S("--font-text-xs-size"),S("--font-text-sm-size"),S("--font-text-md-size"),S("--font-text-lg-size"),S("--font-heading-xs-size"),S("--font-heading-sm-size"),S("--font-heading-md-size"),S("--font-heading-lg-size"),S("--font-heading-xl-size"),S("--font-heading-2xl-size"),S("--font-heading-3xl-size"),S("--font-text-xs-line-height"),S("--font-text-sm-line-height"),S("--font-text-md-line-height"),S("--font-text-lg-line-height"),S("--font-heading-xs-line-height"),S("--font-heading-sm-line-height"),S("--font-heading-md-line-height"),S("--font-heading-lg-line-height"),S("--font-heading-xl-line-height"),S("--font-heading-2xl-line-height"),S("--font-heading-3xl-line-height"),S("--border-radius-xs"),S("--border-radius-sm"),S("--border-radius-md"),S("--border-radius-lg"),S("--border-radius-xl"),S("--border-radius-full"),S("--border-width-regular"),S("--shadow-hairline"),S("--shadow-sm"),S("--shadow-md"),S("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."),pE=Ee(dE.describe(`Style variables for theming MCP apps.
|
|
166
166
|
|
|
167
167
|
Individual style keys are optional - hosts may provide any subset of these values.
|
|
168
168
|
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
169
169
|
|
|
170
170
|
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
171
|
-
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),he([C(),
|
|
171
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),he([C(),Xl()]).describe(`Style variables for theming MCP apps.
|
|
172
172
|
|
|
173
173
|
Individual style keys are optional - hosts may provide any subset of these values.
|
|
174
174
|
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
@@ -180,10 +180,10 @@ Individual style keys are optional - hosts may provide any subset of these value
|
|
|
180
180
|
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
181
181
|
|
|
182
182
|
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
183
|
-
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),
|
|
183
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),mE=A({method:S("ui/open-link"),params:A({url:C().describe("URL to open in the host's browser")})}),dF=A({isError:Re().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),pF=A({isError:Re().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),mF=A({isError:Re().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),fE=A({method:S("ui/notifications/sandbox-proxy-ready"),params:A({})}),Md=A({connectDomains:re(C()).optional().describe(`Origins for network requests (fetch/XHR/WebSocket).
|
|
184
184
|
|
|
185
185
|
- Maps to CSP \`connect-src\` directive
|
|
186
|
-
- Empty or omitted → no network connections (secure default)`),resourceDomains:re(C()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"),frameDomains:re(C()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"),baseUriDomains:re(C()).optional().describe("Allowed base URIs for the document.\n\n- Maps to CSP `base-uri` directive\n- Empty or omitted → only same origin allowed (`base-uri 'self'`)")}),Ld=A({camera:A({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:A({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:A({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:A({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),
|
|
186
|
+
- Empty or omitted → no network connections (secure default)`),resourceDomains:re(C()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"),frameDomains:re(C()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"),baseUriDomains:re(C()).optional().describe("Allowed base URIs for the document.\n\n- Maps to CSP `base-uri` directive\n- Empty or omitted → only same origin allowed (`base-uri 'self'`)")}),Ld=A({camera:A({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:A({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:A({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:A({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),hE=A({method:S("ui/notifications/size-changed"),params:A({width:ae().optional().describe("New width in pixels."),height:ae().optional().describe("New height in pixels.")})}),fF=A({method:S("ui/notifications/tool-input"),params:A({arguments:Ee(C(),ze().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),hF=A({method:S("ui/notifications/tool-input-partial"),params:A({arguments:Ee(C(),ze().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),gF=A({method:S("ui/notifications/tool-cancelled"),params:A({reason:C().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),gE=A({fonts:C().optional()}),vE=A({variables:pE.optional().describe("CSS variables for theming the app."),css:gE.optional().describe("CSS blocks that apps can inject.")}),vF=A({method:S("ui/resource-teardown"),params:A({})}),yE=Ee(C(),ze()),Cx=A({text:A({}).optional().describe("Host supports text content blocks."),image:A({}).optional().describe("Host supports image content blocks."),audio:A({}).optional().describe("Host supports audio content blocks."),resource:A({}).optional().describe("Host supports resource content blocks."),resourceLink:A({}).optional().describe("Host supports resource link content blocks."),structuredContent:A({}).optional().describe("Host supports structured content.")}),bE=A({method:S("ui/notifications/request-teardown"),params:A({}).optional()}),xE=A({experimental:A({}).optional().describe("Experimental features (structure TBD)."),openLinks:A({}).optional().describe("Host supports opening external URLs."),downloadFile:A({}).optional().describe("Host supports file downloads via ui/download-file."),serverTools:A({listChanged:Re().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:A({listChanged:Re().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:A({}).optional().describe("Host accepts log messages."),sandbox:A({permissions:Ld.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:Md.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:Cx.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:Cx.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),wE=A({experimental:A({}).optional().describe("Experimental features (structure TBD)."),tools:A({listChanged:Re().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:re(ji).optional().describe("Display modes the app supports.")}),_E=A({method:S("ui/notifications/initialized"),params:A({}).optional()}),yF=A({csp:Md.optional().describe("Content Security Policy configuration for UI resources."),permissions:Ld.optional().describe("Sandbox permissions requested by the UI resource."),domain:C().optional().describe(`Dedicated origin for view sandbox.
|
|
187
187
|
|
|
188
188
|
Useful when views need stable, dedicated origins for OAuth callbacks, CORS policies, or API key allowlists.
|
|
189
189
|
|
|
@@ -197,10 +197,10 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
197
197
|
|
|
198
198
|
- \`true\`: request visible border + background
|
|
199
199
|
- \`false\`: request no visible border + background
|
|
200
|
-
- omitted: host decides border`)}),
|
|
200
|
+
- omitted: host decides border`)}),Tx=A({method:S("ui/request-display-mode"),params:A({mode:ji.describe("The display mode being requested.")})}),bF=A({mode:ji.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),kE=he([S("model"),S("app")]).describe("Tool visibility scope - who can access the tool."),xF=A({resourceUri:C().optional(),visibility:re(kE).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
201
201
|
- "model": Tool visible to and callable by the agent
|
|
202
|
-
- "app": Tool callable by the app from this server only`)}),
|
|
203
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:C().optional().describe("User's language and region preference in BCP 47 format."),timeZone:C().optional().describe("User's timezone in IANA format."),userAgent:C().optional().describe("Host application identifier."),platform:he([k("web"),k("desktop"),k("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:A({touch:Re().optional().describe("Whether the device supports touch input."),hover:Re().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:A({top:ce().describe("Top safe area inset in pixels."),right:ce().describe("Right safe area inset in pixels."),bottom:ce().describe("Bottom safe area inset in pixels."),left:ce().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),yF=A({method:k("ui/notifications/host-context-changed"),params:Tx.describe("Partial context update containing only changed fields.")}),wE=A({method:k("ui/update-model-context"),params:A({content:re(Rr).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:Ee(C(),ze().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),_E=A({method:k("ui/initialize"),params:A({appInfo:Ri.describe("App identification (name and version)."),appCapabilities:gE.describe("Features and capabilities this app provides."),protocolVersion:C().describe("Protocol version this app supports.")})}),bF=A({protocolVersion:C().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Ri.describe("Host application identification and version."),hostCapabilities:hE.describe("Features and capabilities provided by the host."),hostContext:Tx.describe("Rich context about the host environment.")}).passthrough();class Dd{eventTarget;eventSource;messageListener;constructor(e=window.parent,t){this.eventTarget=e,this.eventSource=t,this.messageListener=(n)=>{if(t&&n.source!==this.eventSource){console.debug("Ignoring message from unknown source",n);return}let o=mx.safeParse(n.data);if(o.success)console.debug("Parsed message",o.data),this.onmessage?.(o.data);else if(n.data?.jsonrpc!=="2.0")console.debug("Ignoring non-JSON-RPC message",o.error.message,n);else console.error("Failed to parse message",o.error.message,n),this.onerror?.(Error("Invalid JSON-RPC message received: "+o.error.message))}}async start(){window.addEventListener("message",this.messageListener)}async send(e,t){if(e.method!==rE)console.debug("Sending message",e);this.eventTarget.postMessage(e,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}function Ix(e){if(!e)return"";let t=[];if(e.camera)t.push("camera");if(e.microphone)t.push("microphone");if(e.geolocation)t.push("geolocation");if(e.clipboardWrite)t.push("clipboard-write");return t.join("; ")}var SE=[Cx];class Fd extends hc{_client;_hostInfo;_capabilities;_appCapabilities;_hostContext={};_appInfo;constructor(e,t,n,o){super(o);this._client=e,this._hostInfo=t,this._capabilities=n,this._hostContext=o?.hostContext||{},this.setRequestHandler(_E,(r)=>this._oninitialize(r)),this.setRequestHandler(Lo,(r,s)=>(this.onping?.(r.params,s),{})),this.setRequestHandler(kx,(r)=>({mode:this._hostContext.displayMode??"inline"}))}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;set onsizechange(e){this.setNotificationHandler(uE,(t)=>e(t.params))}set onsandboxready(e){this.setNotificationHandler(lE,(t)=>e(t.params))}set oninitialized(e){this.setNotificationHandler(vE,(t)=>e(t.params))}set onmessage(e){this.setRequestHandler(xE,async(t,n)=>e(t.params,n))}set onopenlink(e){this.setRequestHandler(cE,async(t,n)=>e(t.params,n))}set ondownloadfile(e){this.setRequestHandler(bE,async(t,n)=>e(t.params,n))}set onrequestteardown(e){this.setNotificationHandler(fE,(t)=>e(t.params))}set onrequestdisplaymode(e){this.setRequestHandler(kx,async(t,n)=>e(t.params,n))}set onloggingmessage(e){this.setNotificationHandler(Rd,async(t)=>{e(t.params)})}set onupdatemodelcontext(e){this.setRequestHandler(wE,async(t,n)=>e(t.params,n))}set oncalltool(e){this.setRequestHandler(pc,async(t,n)=>e(t.params,n))}sendToolListChanged(e={}){return this.notification({method:"notifications/tools/list_changed",params:e})}set onlistresources(e){this.setRequestHandler(yd,async(t,n)=>e(t.params,n))}set onlistresourcetemplates(e){this.setRequestHandler(bd,async(t,n)=>e(t.params,n))}set onreadresource(e){this.setRequestHandler(_d,async(t,n)=>e(t.params,n))}sendResourceListChanged(e={}){return this.notification({method:"notifications/resources/list_changed",params:e})}set onlistprompts(e){this.setRequestHandler(kd,async(t,n)=>e(t.params,n))}sendPromptListChanged(e={}){return this.notification({method:"notifications/prompts/list_changed",params:e})}assertCapabilityForMethod(e){}assertRequestHandlerCapability(e){}assertNotificationCapability(e){}assertTaskCapability(e){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(e){throw Error("Task handlers are not supported in MCP Apps")}getCapabilities(){return this._capabilities}async _oninitialize(e){let t=e.params.protocolVersion;return this._appCapabilities=e.params.appCapabilities,this._appInfo=e.params.appInfo,{protocolVersion:SE.includes(t)?t:Cx,hostCapabilities:this.getCapabilities(),hostInfo:this._hostInfo,hostContext:this._hostContext}}setHostContext(e){let t={},n=!1;for(let o of Object.keys(e)){let r=this._hostContext[o],s=e[o];if(kE(r,s))continue;t[o]=s,n=!0}if(n)this._hostContext=e,this.sendHostContextChange(t)}sendHostContextChange(e){return this.notification({method:"ui/notifications/host-context-changed",params:e})}sendToolInput(e){return this.notification({method:"ui/notifications/tool-input",params:e})}sendToolInputPartial(e){return this.notification({method:"ui/notifications/tool-input-partial",params:e})}sendToolResult(e){return this.notification({method:"ui/notifications/tool-result",params:e})}sendToolCancelled(e){return this.notification({method:"ui/notifications/tool-cancelled",params:e})}sendSandboxResourceReady(e){return this.notification({method:"ui/notifications/sandbox-resource-ready",params:e})}teardownResource(e,t){return this.request({method:"ui/resource-teardown",params:e},mE,t)}sendResourceTeardown=this.teardownResource;async connect(e){if(this.transport)throw Error("AppBridge is already connected. Call close() before connecting again.");if(this._client){let t=this._client.getServerCapabilities();if(!t)throw Error("Client server capabilities not available");if(t.tools){if(this.oncalltool=async(n,o)=>this._client.request({method:"tools/call",params:n},Do,{signal:o.signal}),t.tools.listChanged)this._client.setNotificationHandler(Nd,(n)=>this.sendToolListChanged(n.params))}if(t.resources){if(this.onlistresources=async(n,o)=>this._client.request({method:"resources/list",params:n},cc,{signal:o.signal}),this.onlistresourcetemplates=async(n,o)=>this._client.request({method:"resources/templates/list",params:n},xd,{signal:o.signal}),this.onreadresource=async(n,o)=>this._client.request({method:"resources/read",params:n},lc,{signal:o.signal}),t.resources.listChanged)this._client.setNotificationHandler(Sd,(n)=>this.sendResourceListChanged(n.params))}if(t.prompts){if(this.onlistprompts=async(n,o)=>this._client.request({method:"prompts/list",params:n},Cd,{signal:o.signal}),t.prompts.listChanged)this._client.setNotificationHandler(Pd,(n)=>this.sendPromptListChanged(n.params))}}return super.connect(e)}}function kE(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Bd(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function CE(e){return Bd(e)&&Array.isArray(e.content)&&e.content.every((t)=>Bd(t)&&typeof t.type==="string")}function TE(...e){for(let t of e)if(typeof t==="string"){if(t.trim().length>0)return t}return}function IE(e){if(typeof e==="string")return e;if(e===void 0)return;try{return JSON.stringify(e)}catch(t){return console.debug("[ext-app-tool-result] stringify failed",t),String(e)}}function Hd(e){let t=e.success===!1;if(CE(e.result))return{...e.result,isError:e.result.isError===!0||t};let n=Bd(e.result)?e.result:null,o=TE(e.detailedContent,e.content,n?.detailedContent,n?.content,n?.textResultForLlm,n?.text,n?.message,typeof e.result==="string"?e.result:void 0,e.error)??IE(e.result);return{content:o?[{type:"text",text:o}]:[],isError:t}}function Ex(e,t){if(e===t)return!0;if(e.isError!==t.isError)return!1;try{let n=JSON.stringify(e),o=JSON.stringify(t);if(n===void 0||o===void 0)return!1;if(Math.abs(n.length-o.length)>2000000)return!1;return n===o}catch{return!1}}function Ax(e){return Boolean(e)&&typeof e==="object"&&e!==null&&!Array.isArray(e)&&"ok"in e&&typeof e.ok==="boolean"}async function EE(e,t){let n=await fetch("/api/canvas/frame-documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:e,sandbox:t})}),o=await n.json();if(!n.ok||!Ax(o)||!o.ok||typeof o.url!=="string"){let r=Ax(o)&&o.error?o.error:`Frame document request failed with HTTP ${n.status}`;throw Error(r)}return o.url}function zx(e,t){let n=_t.value,[o,r]=I(null),[s,a]=I(0),c=R(0);B(()=>{if(r(null),!e||n!=="src")return;let u=!1;return c.current=zo.value,EE(e,t).then((p)=>{if(!u)r(p)}).catch((p)=>{console.error("[iframe-document] failed to create frame document:",p)}),()=>{u=!0}},[e,t,n,s]);let l=zo.value;return B(()=>{if(n!=="src"||l===c.current)return;if(!o){a((p)=>p+1);return}let u=!1;return fetch(o,{method:"HEAD"}).then((p)=>{if(u)return;if(p.ok){c.current=l;return}a((d)=>d+1)}).catch(()=>{}),()=>{u=!0}},[l,o,n]),Ie(()=>{if(n==="srcdoc"&&e)return{attributes:{srcdoc:e},ready:!0,key:`srcdoc-${wr(e)}`};return{attributes:o?{src:o}:{},ready:Boolean(o),key:o??""}},[o,n,e])}function $r(e){let{enabled:t,token:n,nodeId:o,sourceSurface:r,iframeRef:s}=e;B(()=>{if(!t||!n)return;function a(c){if(c.source!==s.current?.contentWindow)return;let l=c.data;if(!l||l.source!==Oa||l.token!==n||l.nodeId!==o)return;let u=l.interaction;if(!u||typeof u.type!=="string")return;let p=u.type;ea({type:p,sourceNodeId:o,sourceSurface:r,...u.payload&&typeof u.payload==="object"?{payload:u.payload}:{}}).then((d)=>{if(d.ok)xn("context","AX interaction",p,[o]);s.current?.contentWindow?.postMessage({source:La,token:n,...l.correlationId?{correlationId:l.correlationId}:{},interaction:{type:p},result:d},"*")})}return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[t,n,o,r])}async function Fo(e,t){let o=await(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json();if(!o.ok)throw Error(o.error??`Request failed: ${e}`);return o.result}function Bo(e){return/AppleWebKit/.test(e)&&!/Chrome|Chromium|CriOS|Edg|Android/.test(e)}function AE(e){let{userAgent:t,visibilityState:n,rect:o,viewport:r,alreadyRearmed:s}=e;if(s)return!1;if(!Bo(t))return!1;if(n!=="hidden")return!1;if(o.width<=0||o.height<=0)return!1;return o.bottom>0&&o.right>0&&o.top<r.height&&o.left<r.width}var Dx=1000,Px=7000;function ct(e,t){if(typeof window>"u")return;let n=window;if(n.__PMX_EXTAPP_LOG??=[],n.__PMX_EXTAPP_LOG.length<500)n.__PMX_EXTAPP_LOG.push({t:Date.now(),nodeId:e,event:t});zE({t:Date.now(),nodeId:e,event:t})}var Nx=[],jd=null;function zE(e){if(Nx.push({...e,...typeof document<"u"?{visibility:document.visibilityState}:{}}),jd)return;jd=setTimeout(()=>{jd=null;let t=Nx.splice(0);if(t.length===0)return;fetch("/api/canvas/debug/ext-app-recovery",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entries:t})}).catch(()=>{})},1500)}var Rx=Promise.resolve();function $x(e){Rx=Rx.then(async()=>{if(!e.remount())return;await e.awaitBoot(),await new Promise((t)=>setTimeout(t,Dx))}).catch(()=>{})}function PE(e,t){let n=typeof e.data.html==="string"?e.data.html:"",o=typeof e.data.serverName==="string"?e.data.serverName:"",r=typeof e.data.appSessionId==="string"?e.data.appSessionId:"",s=typeof e.data.sessionStatus==="string"?e.data.sessionStatus:"";return`${e.id}:${t}:${o}:${r}:${s}:${n}`}function NE(e,t){if(e==="fullscreen")return{nextMode:"fullscreen",shouldExpand:!t,shouldCollapse:!1};if(e==="inline")return{nextMode:"inline",shouldExpand:!1,shouldCollapse:t};return{nextMode:e,shouldExpand:!1,shouldCollapse:!1}}async function Mx(e,t,n){if(await e.sendToolInput({arguments:t}),n)await e.sendToolResult(n)}function RE(e){return typeof e==="string"&&e.trim().length>0?e.trim():ed}function $E(e,t){return`<script data-pmx-canvas-ax-bridge>
|
|
202
|
+
- "app": Tool callable by the app from this server only`)}),wF=A({mimeTypes:re(C()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),SE=A({method:S("ui/download-file"),params:A({contents:re(he([Ed,Ad])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),CE=A({method:S("ui/message"),params:A({role:S("user").describe('Message role, currently only "user" is supported.'),content:re(Lr).describe("Message content blocks (text, image, etc.).")})}),_F=A({method:S("ui/notifications/sandbox-resource-ready"),params:A({html:C().describe("HTML content to load into the inner iframe."),sandbox:C().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:Md.optional().describe("CSP configuration from resource metadata."),permissions:Ld.optional().describe("Sandbox permissions from resource metadata.")})}),kF=A({method:S("ui/notifications/tool-result"),params:Do.describe("Standard MCP tool execution result.")}),Ex=A({toolInfo:A({id:$r.optional().describe("JSON-RPC id of the tools/call request."),tool:dc.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:uE.optional().describe("Current color theme preference."),styles:vE.optional().describe("Style configuration for theming the app."),displayMode:ji.optional().describe("How the UI is currently displayed."),availableDisplayModes:re(ji).optional().describe("Display modes the host supports."),containerDimensions:he([A({height:ae().describe("Fixed container height in pixels.")}),A({maxHeight:he([ae(),Xl()]).optional().describe("Maximum container height in pixels.")})]).and(he([A({width:ae().describe("Fixed container width in pixels.")}),A({maxWidth:he([ae(),Xl()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
203
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:C().optional().describe("User's language and region preference in BCP 47 format."),timeZone:C().optional().describe("User's timezone in IANA format."),userAgent:C().optional().describe("Host application identifier."),platform:he([S("web"),S("desktop"),S("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:A({touch:Re().optional().describe("Whether the device supports touch input."),hover:Re().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:A({top:ae().describe("Top safe area inset in pixels."),right:ae().describe("Right safe area inset in pixels."),bottom:ae().describe("Bottom safe area inset in pixels."),left:ae().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),SF=A({method:S("ui/notifications/host-context-changed"),params:Ex.describe("Partial context update containing only changed fields.")}),TE=A({method:S("ui/update-model-context"),params:A({content:re(Lr).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:Ee(C(),ze().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),IE=A({method:S("ui/initialize"),params:A({appInfo:Mi.describe("App identification (name and version)."),appCapabilities:wE.describe("Features and capabilities this app provides."),protocolVersion:C().describe("Protocol version this app supports.")})}),CF=A({protocolVersion:C().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Mi.describe("Host application identification and version."),hostCapabilities:xE.describe("Features and capabilities provided by the host."),hostContext:Ex.describe("Rich context about the host environment.")}).passthrough();class Od{eventTarget;eventSource;messageListener;constructor(e=window.parent,t){this.eventTarget=e,this.eventSource=t,this.messageListener=(n)=>{if(t&&n.source!==this.eventSource){console.debug("Ignoring message from unknown source",n);return}let o=hx.safeParse(n.data);if(o.success)console.debug("Parsed message",o.data),this.onmessage?.(o.data);else if(n.data?.jsonrpc!=="2.0")console.debug("Ignoring non-JSON-RPC message",o.error.message,n);else console.error("Failed to parse message",o.error.message,n),this.onerror?.(Error("Invalid JSON-RPC message received: "+o.error.message))}}async start(){window.addEventListener("message",this.messageListener)}async send(e,t){if(e.method!==lE)console.debug("Sending message",e);this.eventTarget.postMessage(e,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}function Ax(e){if(!e)return"";let t=[];if(e.camera)t.push("camera");if(e.microphone)t.push("microphone");if(e.geolocation)t.push("geolocation");if(e.clipboardWrite)t.push("clipboard-write");return t.join("; ")}var EE=[Ix];class Dd extends gc{_client;_hostInfo;_capabilities;_appCapabilities;_hostContext={};_appInfo;constructor(e,t,n,o){super(o);this._client=e,this._hostInfo=t,this._capabilities=n,this._hostContext=o?.hostContext||{},this.setRequestHandler(IE,(r)=>this._oninitialize(r)),this.setRequestHandler(Oo,(r,s)=>(this.onping?.(r.params,s),{})),this.setRequestHandler(Tx,(r)=>({mode:this._hostContext.displayMode??"inline"}))}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;set onsizechange(e){this.setNotificationHandler(hE,(t)=>e(t.params))}set onsandboxready(e){this.setNotificationHandler(fE,(t)=>e(t.params))}set oninitialized(e){this.setNotificationHandler(_E,(t)=>e(t.params))}set onmessage(e){this.setRequestHandler(CE,async(t,n)=>e(t.params,n))}set onopenlink(e){this.setRequestHandler(mE,async(t,n)=>e(t.params,n))}set ondownloadfile(e){this.setRequestHandler(SE,async(t,n)=>e(t.params,n))}set onrequestteardown(e){this.setNotificationHandler(bE,(t)=>e(t.params))}set onrequestdisplaymode(e){this.setRequestHandler(Tx,async(t,n)=>e(t.params,n))}set onloggingmessage(e){this.setNotificationHandler(Nd,async(t)=>{e(t.params)})}set onupdatemodelcontext(e){this.setRequestHandler(TE,async(t,n)=>e(t.params,n))}set oncalltool(e){this.setRequestHandler(mc,async(t,n)=>e(t.params,n))}sendToolListChanged(e={}){return this.notification({method:"notifications/tools/list_changed",params:e})}set onlistresources(e){this.setRequestHandler(vd,async(t,n)=>e(t.params,n))}set onlistresourcetemplates(e){this.setRequestHandler(yd,async(t,n)=>e(t.params,n))}set onreadresource(e){this.setRequestHandler(wd,async(t,n)=>e(t.params,n))}sendResourceListChanged(e={}){return this.notification({method:"notifications/resources/list_changed",params:e})}set onlistprompts(e){this.setRequestHandler(kd,async(t,n)=>e(t.params,n))}sendPromptListChanged(e={}){return this.notification({method:"notifications/prompts/list_changed",params:e})}assertCapabilityForMethod(e){}assertRequestHandlerCapability(e){}assertNotificationCapability(e){}assertTaskCapability(e){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(e){throw Error("Task handlers are not supported in MCP Apps")}getCapabilities(){return this._capabilities}async _oninitialize(e){let t=e.params.protocolVersion;return this._appCapabilities=e.params.appCapabilities,this._appInfo=e.params.appInfo,{protocolVersion:EE.includes(t)?t:Ix,hostCapabilities:this.getCapabilities(),hostInfo:this._hostInfo,hostContext:this._hostContext}}setHostContext(e){let t={},n=!1;for(let o of Object.keys(e)){let r=this._hostContext[o],s=e[o];if(AE(r,s))continue;t[o]=s,n=!0}if(n)this._hostContext=e,this.sendHostContextChange(t)}sendHostContextChange(e){return this.notification({method:"ui/notifications/host-context-changed",params:e})}sendToolInput(e){return this.notification({method:"ui/notifications/tool-input",params:e})}sendToolInputPartial(e){return this.notification({method:"ui/notifications/tool-input-partial",params:e})}sendToolResult(e){return this.notification({method:"ui/notifications/tool-result",params:e})}sendToolCancelled(e){return this.notification({method:"ui/notifications/tool-cancelled",params:e})}sendSandboxResourceReady(e){return this.notification({method:"ui/notifications/sandbox-resource-ready",params:e})}teardownResource(e,t){return this.request({method:"ui/resource-teardown",params:e},yE,t)}sendResourceTeardown=this.teardownResource;async connect(e){if(this.transport)throw Error("AppBridge is already connected. Call close() before connecting again.");if(this._client){let t=this._client.getServerCapabilities();if(!t)throw Error("Client server capabilities not available");if(t.tools){if(this.oncalltool=async(n,o)=>this._client.request({method:"tools/call",params:n},Do,{signal:o.signal}),t.tools.listChanged)this._client.setNotificationHandler(Pd,(n)=>this.sendToolListChanged(n.params))}if(t.resources){if(this.onlistresources=async(n,o)=>this._client.request({method:"resources/list",params:n},lc,{signal:o.signal}),this.onlistresourcetemplates=async(n,o)=>this._client.request({method:"resources/templates/list",params:n},bd,{signal:o.signal}),this.onreadresource=async(n,o)=>this._client.request({method:"resources/read",params:n},uc,{signal:o.signal}),t.resources.listChanged)this._client.setNotificationHandler(_d,(n)=>this.sendResourceListChanged(n.params))}if(t.prompts){if(this.onlistprompts=async(n,o)=>this._client.request({method:"prompts/list",params:n},Sd,{signal:o.signal}),t.prompts.listChanged)this._client.setNotificationHandler(zd,(n)=>this.sendPromptListChanged(n.params))}}return super.connect(e)}}function AE(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Fd(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function zE(e){return Fd(e)&&Array.isArray(e.content)&&e.content.every((t)=>Fd(t)&&typeof t.type==="string")}function PE(...e){for(let t of e)if(typeof t==="string"){if(t.trim().length>0)return t}return}function NE(e){if(typeof e==="string")return e;if(e===void 0)return;try{return JSON.stringify(e)}catch(t){return console.debug("[ext-app-tool-result] stringify failed",t),String(e)}}function Bd(e){let t=e.success===!1;if(zE(e.result))return{...e.result,isError:e.result.isError===!0||t};let n=Fd(e.result)?e.result:null,o=PE(e.detailedContent,e.content,n?.detailedContent,n?.content,n?.textResultForLlm,n?.text,n?.message,typeof e.result==="string"?e.result:void 0,e.error)??NE(e.result);return{content:o?[{type:"text",text:o}]:[],isError:t}}function zx(e,t){if(e===t)return!0;if(e.isError!==t.isError)return!1;try{let n=JSON.stringify(e),o=JSON.stringify(t);if(n===void 0||o===void 0)return!1;if(Math.abs(n.length-o.length)>2000000)return!1;return n===o}catch{return!1}}function Px(e){return Boolean(e)&&typeof e==="object"&&e!==null&&!Array.isArray(e)&&"ok"in e&&typeof e.ok==="boolean"}async function RE(e,t){let n=await fetch("/api/canvas/frame-documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:e,sandbox:t})}),o=await n.json();if(!n.ok||!Px(o)||!o.ok||typeof o.url!=="string"){let r=Px(o)&&o.error?o.error:`Frame document request failed with HTTP ${n.status}`;throw Error(r)}return o.url}function Nx(e,t){let n=kt.value,[o,r]=I(null),[s,a]=I(0),c=z(0);B(()=>{if(r(null),!e||n!=="src")return;let u=!1;return c.current=zo.value,RE(e,t).then((p)=>{if(!u)r(p)}).catch((p)=>{console.error("[iframe-document] failed to create frame document:",p)}),()=>{u=!0}},[e,t,n,s]);let l=zo.value;return B(()=>{if(n!=="src"||l===c.current)return;if(!o){a((p)=>p+1);return}let u=!1;return fetch(o,{method:"HEAD"}).then((p)=>{if(u)return;if(p.ok){c.current=l;return}a((d)=>d+1)}).catch(()=>{}),()=>{u=!0}},[l,o,n]),Se(()=>{if(n==="srcdoc"&&e)return{attributes:{srcdoc:e},ready:!0,key:`srcdoc-${Sr(e)}`};return{attributes:o?{src:o}:{},ready:Boolean(o),key:o??""}},[o,n,e])}function Or(e){let{enabled:t,token:n,nodeId:o,sourceSurface:r,iframeRef:s}=e;jt(()=>{if(!t||!n)return;function a(c){if(c.source!==s.current?.contentWindow)return;let l=c.data;if(!l||l.source!==Oa||l.token!==n||l.nodeId!==o)return;let u=l.interaction;if(!u||typeof u.type!=="string")return;let p=u.type;ra({type:p,sourceNodeId:o,sourceSurface:r,...u.payload&&typeof u.payload==="object"?{payload:u.payload}:{}}).then((d)=>{if(d.ok)pn("context","AX interaction",p,[o]);s.current?.contentWindow?.postMessage({source:Da,token:n,...l.correlationId?{correlationId:l.correlationId}:{},interaction:{type:p},result:d},"*")})}return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[t,n,o,r])}async function Fo(e,t){let o=await(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json();if(!o.ok)throw Error(o.error??`Request failed: ${e}`);return o.result}function Bo(e){return/AppleWebKit/.test(e)&&!/Chrome|Chromium|CriOS|Edg|Android/.test(e)}function $E(e){let{userAgent:t,visibilityState:n,rect:o,viewport:r,alreadyRearmed:s}=e;if(s)return!1;if(!Bo(t))return!1;if(n!=="hidden")return!1;if(o.width<=0||o.height<=0)return!1;return o.bottom>0&&o.right>0&&o.top<r.height&&o.left<r.width}var Bx=1000,Rx=7000;function lt(e,t){if(typeof window>"u")return;let n=window;if(n.__PMX_EXTAPP_LOG??=[],n.__PMX_EXTAPP_LOG.length<500)n.__PMX_EXTAPP_LOG.push({t:Date.now(),nodeId:e,event:t});ME({t:Date.now(),nodeId:e,event:t})}var $x=[],Hd=null;function ME(e){if($x.push({...e,...typeof document<"u"?{visibility:document.visibilityState}:{}}),Hd)return;Hd=setTimeout(()=>{Hd=null;let t=$x.splice(0);if(t.length===0)return;fetch("/api/canvas/debug/ext-app-recovery",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entries:t})}).catch(()=>{})},1500)}var Mx=Promise.resolve();function Lx(e){Mx=Mx.then(async()=>{if(!e.remount())return;await e.awaitBoot(),await new Promise((t)=>setTimeout(t,Bx))}).catch(()=>{})}function LE(e,t){let n=typeof e.data.html==="string"?e.data.html:"",o=typeof e.data.serverName==="string"?e.data.serverName:"",r=typeof e.data.appSessionId==="string"?e.data.appSessionId:"",s=typeof e.data.sessionStatus==="string"?e.data.sessionStatus:"";return`${e.id}:${t}:${o}:${r}:${s}:${n}`}function OE(e,t){if(e==="fullscreen")return{nextMode:"fullscreen",shouldExpand:!t,shouldCollapse:!1};if(e==="inline")return{nextMode:"inline",shouldExpand:!1,shouldCollapse:t};return{nextMode:e,shouldExpand:!1,shouldCollapse:!1}}async function Ox(e,t,n){if(await e.sendToolInput({arguments:t}),n)await e.sendToolResult(n)}function DE(e){return typeof e==="string"&&e.trim().length>0?e.trim():Qu}function FE(e,t){return`<script data-pmx-canvas-ax-bridge>
|
|
204
204
|
(function () {
|
|
205
205
|
const PMX_AX_TOKEN = ${JSON.stringify(e)};
|
|
206
206
|
const PMX_AX_NODE_ID = ${JSON.stringify(t)};
|
|
@@ -231,7 +231,7 @@ container holding the app. Specify either width or maxWidth, and either height o
|
|
|
231
231
|
};
|
|
232
232
|
window.addEventListener('message', function (event) {
|
|
233
233
|
const m = event.data;
|
|
234
|
-
if (!m || m.source !== '${
|
|
234
|
+
if (!m || m.source !== '${Da}' || m.token !== PMX_AX_TOKEN) return;
|
|
235
235
|
const result = m.result || { ok: false };
|
|
236
236
|
const resolver = m.correlationId ? pending.get(m.correlationId) : undefined;
|
|
237
237
|
if (resolver) { pending.delete(m.correlationId); resolver(result); }
|
|
@@ -241,11 +241,11 @@ container holding the app. Specify either width or maxWidth, and either height o
|
|
|
241
241
|
try { window.dispatchEvent(new CustomEvent('pmx-ax-ack', { detail: { result: result, interaction: m.interaction || null } })); } catch (e) {}
|
|
242
242
|
});
|
|
243
243
|
})();
|
|
244
|
-
</script>`}function
|
|
244
|
+
</script>`}function BE(e,t){return`<script data-pmx-canvas-boot-beacon>
|
|
245
245
|
(function () {
|
|
246
246
|
var TOKEN = ${JSON.stringify(e)};
|
|
247
247
|
var NODE_ID = ${JSON.stringify(t)};
|
|
248
|
-
window.parent.postMessage({ source: '${
|
|
248
|
+
window.parent.postMessage({ source: '${Fa}', token: TOKEN, nodeId: NODE_ID }, '*');
|
|
249
249
|
// Paint-tick answers (Finding N): a double rAF only fires when this frame's
|
|
250
250
|
// rendering pipeline is actually running — a frame whose layer WebKit never
|
|
251
251
|
// composites stays silent, and that silence drives the parent's recovery
|
|
@@ -315,17 +315,17 @@ container holding the app. Specify either width or maxWidth, and either height o
|
|
|
315
315
|
requestAnimationFrame(function () {
|
|
316
316
|
requestAnimationFrame(function () {
|
|
317
317
|
var v = contentVerdict();
|
|
318
|
-
window.parent.postMessage({ source: '${
|
|
318
|
+
window.parent.postMessage({ source: '${Fa}', token: TOKEN, nodeId: NODE_ID, kind: 'paint-tick', content: v.content, detail: v.detail }, '*');
|
|
319
319
|
});
|
|
320
320
|
});
|
|
321
321
|
}
|
|
322
322
|
window.addEventListener('message', function (event) {
|
|
323
323
|
var m = event.data;
|
|
324
|
-
if (m && m.source === '${
|
|
324
|
+
if (m && m.source === '${Yu}' && m.token === TOKEN) sendPaintTick();
|
|
325
325
|
});
|
|
326
326
|
sendPaintTick();
|
|
327
327
|
})();
|
|
328
|
-
</script>`}function Ox(){return"<style data-pmx-canvas-ext-app-base>html, body { background: transparent !important; }</style>"}function Lx(e,t){if(!t)return e;let n=/<head\b[^>]*>/i.exec(e);if(n?.index!==void 0){let r=n.index+n[0].length;return`${e.slice(0,r)}${t}${e.slice(r)}`}let o=/<body\b[^>]*>/i.exec(e);if(o?.index!==void 0){let r=o.index+o[0].length;return`${e.slice(0,r)}${t}${e.slice(r)}`}return`${t}${e}`}function Mr(e,t){if(Number.isFinite(e)&&e>0)return Math.round(e);if(Number.isFinite(t)&&t>0)return Math.round(t);return 1}function Zd(e,t){let n=e?.getBoundingClientRect();return{width:Mr(e?.clientWidth??0,Mr(n?.width??0,t.width)),height:Mr(e?.clientHeight??0,Mr(n?.height??0,t.height))}}function OE(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>0&&!t}function LE(e,t){return Math.max(Mr(e,1),Mr(t,1))}function Fx({node:e,expanded:t=!1}){let n=R(null),o=R(null),r=R(null),s=R(null),a=R({}),c=R(void 0),l=R(!1),u=R(void 0),p=R(null),d=R(!1),f=R(null),m=R(0),h=R([]),v=R(""),x=R(!1),g=R(!1),y=R([]),E=R(!1),L=R(!1),P=R(!1),b=R(!1),[T,w]=I("loading"),[_,z]=I(null),[U,N]=I(0),[Z,j]=I(!1),[S,V]=I(!1),[ge,Ze]=I(()=>t||typeof navigator>"u"||typeof window>"u"||!Bo(navigator.userAgent)),se=e.data.html,de=e.data.serverName,me=e.data.appSessionId,go=e.data.toolInput??{},Gt=e.data.toolResult,an=e.data.toolName??"ext-app",M=e.data.toolDefinition,J=e.data.toolCallId,fe=typeof J==="string"||typeof J==="number"?J:void 0,ee=e.data.resourceMeta,Q=e.data.sessionStatus,te=e.data.sessionError,ne=e.size.height,W=e.id,ue=PE(e,U),bt=RE(null),D=e.data.axCapabilities?.enabled===!0&&typeof se==="string"&&se.length>0,ae=Ie(()=>`ax-${crypto.randomUUID()}`,[]),Fe=D?$E(ae,W):"",ve=typeof se==="string"&&se.length>0?ME(ae,W):"",Xt=zx(Lx(se??"",Ox()+ve+Fe),bt);B(()=>{function X(oe){if(oe.source!==n.current?.contentWindow)return;let we=oe.data;if(!we||we.source!==Da||we.token!==ae||we.nodeId!==W)return;if(g.current=!0,we.kind==="paint-tick"){let $e=we,Bt={content:$e.content===!0,detail:typeof $e.detail==="string"?$e.detail:""};for(let Ln of h.current.splice(0))Ln(Bt)}}return window.addEventListener("message",X),()=>window.removeEventListener("message",X)},[ae,W]),B(()=>{if(ge)return;$x({remount:()=>{if(b.current)return!1;return ct(W,"mount-slot"),Ze(!0),!0},awaitBoot:()=>new Promise((X)=>{let oe=window.setTimeout(we,Px);function we(){window.clearTimeout(oe),X()}y.current.push(we)})})},[]),$r({enabled:D,token:ae,nodeId:W,sourceSurface:"mcp-app",iframeRef:n});let Yi=3,Jt=(X)=>{if(m.current>=Yi)return ct(W,`remount-cap-hit (${X})`),!1;if(E.current)return!0;return m.current+=1,E.current=!0,ct(W,`remount-queued #${m.current} (${X})`),$x({remount:()=>{if(E.current=!1,b.current||!t&&qe.value===W)return ct(W,"remount-skipped"),j(!1),!1;return L.current=typeof document<"u"&&document.visibilityState==="hidden",ct(W,`remount-run #${m.current}`),w("loading"),N((oe)=>oe+1),!0},awaitBoot:()=>new Promise((oe)=>{let we=window.setTimeout($e,Px);function $e(){window.clearTimeout(we),oe()}y.current.push($e)})}),!0},Mn=1500,Wc=()=>new Promise((X)=>{let oe=n.current?.contentWindow;if(!oe||b.current){X("timeout");return}let we=!1,$e=window.setTimeout(()=>{if(we)return;we=!0,X("timeout")},Mn);h.current.push((Bt)=>{if(we)return;we=!0,window.clearTimeout($e),v.current=Bt.detail,X(Bt.content?"content-verified":"tick-no-content")}),oe.postMessage({source:Qu,token:ae},"*")}),zp=async(X)=>{let oe=Date.now()+X;while(Date.now()<oe&&!b.current){if(await Wc()==="content-verified")return!0;await new Promise((we)=>window.setTimeout(we,400))}return!1},Q_=()=>new Promise((X)=>{let oe=n.current;if(!oe){X();return}let we=oe.style.width,$e=oe.style.height;oe.style.width="140%",oe.style.height="140%",requestAnimationFrame(()=>{requestAnimationFrame(()=>{oe.style.width=we,oe.style.height=$e,ct(W,"soft-expand-cycle"),X()})})}),eS=600,Qi=()=>{if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;let X=n.current;if(!X||b.current)return;if(!AE({userAgent:navigator.userAgent,visibilityState:document.visibilityState,rect:X.getBoundingClientRect(),viewport:{width:window.innerWidth,height:window.innerHeight},alreadyRearmed:P.current}))return;P.current=!0,window.setTimeout(()=>{if(b.current||document.visibilityState==="visible")return;m.current=0,V(!1),L.current=!1,ct(W,"assume-visible-rearm"),Jt("assume-visible")},eS)},Vc=(X="")=>{let oe=v.current?` [${v.current}]`:"";return typeof document<"u"&&document.visibilityState==="hidden"?`paint-ok (content-verified)${oe}${X} (host hidden)`:`paint-ok (content-verified)${oe}${X}`},tS=async()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Bo(navigator.userAgent))return;j(!0);let X=await Wc();if(X==="content-verified"){ct(W,Vc()),j(!1),Qi();return}if(ct(W,X==="tick-no-content"?`paint-fail (tick without content: ${v.current||"unknown"})`:"paint-fail (no tick)"),await Q_(),X=await Wc(),X==="content-verified"){ct(W,Vc(" (after soft-expand)")),j(!1),Qi();return}if(b.current)return;if(X==="tick-no-content"&&await zp(3000)){ct(W,Vc(" (after content wait)")),j(!1),Qi();return}if(b.current)return;if(!Jt("paint-fail"))ct(W,"recovery-exhausted"),j(!1),V(!0),Qi()};B(()=>{if(t)return;if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;if(!Bo(navigator.userAgent))return;function X(){if(document.visibilityState!=="visible")return;if(!L.current||b.current)return;L.current=!1,m.current=0,V(!1),ct(W,"visible-again-rearm"),Jt("visible-after-hidden-boot")}return document.addEventListener("visibilitychange",X),()=>document.removeEventListener("visibilitychange",X)},[t,W]);let nS=6000;B(()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Bo(navigator.userAgent))return;if(!Xt.ready||!ge)return;let X=window.setTimeout(()=>{if(x.current||g.current||b.current)return;Jt("boot-watchdog")},nS);return()=>window.clearTimeout(X)},[ue,Xt.ready,t,ge]),B(()=>()=>{b.current=!0;for(let X of y.current.splice(0))X();for(let X of h.current.splice(0))X({content:!1,detail:"unmounted"})},[]);let Gc=(X)=>Ar(X),On=t||qe.value===W;a.current=go,c.current=Gt;let es=Q==="error"&&typeof se==="string"&&se.length>0,Xc=Q==="error"?es?`Live session unavailable — showing saved content. Reopen the app to restore interactivity.${te?` (${te})`:""}`:te??"Saved app session is unavailable. Reopen the app to restore interactivity.":"Reconnecting saved app session...",Jc=(X)=>{let oe=c.current;if(!X||!d.current||!oe)return null;if(u.current===oe)return null;if(u.current&&Ex(u.current,oe))return u.current=oe,null;if(p.current)return p.current;let we=X.sendToolResult(oe).then(()=>{u.current=oe,l.current=!0,w("done")}).catch(($e)=>{let Bt=$e instanceof Error?$e.message:String($e);throw z(`Tool result delivery failed: ${Bt}`),$e}).finally(()=>{p.current=null});return p.current=we,we};if(B(()=>{if(!se||!Xt.ready||!ge)return;let X=n.current;if(!X)return;let oe=!1,we=null,$e=null,Bt=null,Ln=null,vo=null;l.current=!1,u.current=void 0,p.current=null,d.current=!1,x.current=!1,g.current=!1;let ts=()=>{if(!we)return;clearTimeout(we),we=null};return(async()=>{if(!se)return;let Dn=X.contentWindow;if(!Dn)throw Error("Ext-app iframe window is unavailable");let yo=(ye=qe.value===W?"fullscreen":"inline")=>({theme:Gc(tt.value),platform:"web",containerDimensions:Zd(X,{width:e.size.width,height:ne}),displayMode:ye,locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,...M?{toolInfo:{id:fe,tool:M}}:{}}),oS=()=>{if(Ln!==null)return;Ln=requestAnimationFrame(()=>{if(Ln=null,oe||!d.current)return;Me.setHostContext?.(yo())})},Pp=()=>{if(vo!==null)return;vo=requestAnimationFrame(()=>{vo=requestAnimationFrame(()=>{if(vo=null,oe||!d.current)return;Me.sendHostContextChange?.(yo())})})},Np=()=>{if(!Bo(navigator.userAgent))return;if($e)clearTimeout($e);$e=setTimeout(()=>{if($e=null,oe)return;tS()},Dx+200)},Me=new Fd(null,{name:"PMX Canvas",version:"1.0.0"},{openLinks:{},serverTools:{listChanged:!1},serverResources:{listChanged:!1},logging:{},updateModelContext:{text:{},structuredContent:{}}},{hostContext:yo(On?"fullscreen":"inline")});Me.onsizechange=async({height:ye})=>{if(OE(ye,qe.value===W)){let ot=Zd(X.parentElement??X,{width:e.size.width,height:ne}),Ht=LE(ye,ot.height);X.style.height=`${Ht}px`;let bo=F.value.get(W)?.size??e.size,$p=Math.max(bo.height,Ht+Cr);if(Math.abs($p-bo.height)>8){if(ua(W,{width:bo.width,height:$p}),s.current!==null)window.clearTimeout(s.current);s.current=window.setTimeout(()=>{at({recordHistory:!1}),s.current=null},0)}}return{}},Me.onopenlink=async({url:ye})=>(window.open(ye,"_blank","noopener"),{}),Me.onsandboxready=async()=>{await Me.sendSandboxResourceReady({html:Lx(se,Ox()),sandbox:ed,...ee?.csp?{csp:ee.csp}:{},...ee?.permissions?{permissions:ee.permissions}:{}})},Me.onrequestdisplaymode=async({mode:ye})=>{let{nextMode:ot,shouldExpand:Ht,shouldCollapse:bo}=NE(ye,On);if(Ht)Ut(W);else if(bo)In();return{mode:ot}},Me.oncalltool=async(ye)=>{if(!me)throw Error(Xc);try{let ot=await Fo("/api/ext-app/call-tool",{sessionId:me,nodeId:W,serverName:de,toolName:ye.name,arguments:ye.arguments??{}});return z(null),ot}catch(ot){let Ht=ot instanceof Error?ot.message:String(ot);throw z(`Tool call failed: ${Ht}`),ot}},Me.setRequestHandler(dc,async()=>{if(!me)return{tools:[]};return Fo("/api/ext-app/list-tools",{sessionId:me})}),Me.onlistresources=async()=>me?Fo("/api/ext-app/list-resources",{sessionId:me}):{resources:[]},Me.onlistresourcetemplates=async()=>me?Fo("/api/ext-app/list-resource-templates",{sessionId:me}):{resourceTemplates:[]},Me.onreadresource=async(ye)=>{if(!me)throw Error(Xc);return Fo("/api/ext-app/read-resource",{sessionId:me,uri:ye.uri})},Me.onlistprompts=async()=>me?Fo("/api/ext-app/list-prompts",{sessionId:me}):{prompts:[]},Me.onupdatemodelcontext=async(ye)=>{if(!me)return{};return await Fo("/api/ext-app/model-context",{nodeId:W,...Array.isArray(ye.content)?{content:ye.content}:{},...ye.structuredContent&&typeof ye.structuredContent==="object"?{structuredContent:ye.structuredContent}:{}}),{}};let Kc=new Dd(Dn,Dn);if(Me.oninitialized=()=>{if(oe)return;ts(),d.current=!0,x.current=!0,ct(W,"initialized"),w("ready"),z(null),Promise.resolve(Me.sendHostContextChange(yo(On?"fullscreen":"inline"))).then(()=>Mx(Me,a.current,void 0)).then(()=>Jc(Me)).then(()=>{let ye=()=>{for(let ot of y.current.splice(0))ot()};if(typeof navigator<"u"&&Bo(navigator.userAgent))zp(4000).then((ot)=>{ct(W,ot?"settled (content-verified)":`settled (content-timeout${v.current?`: ${v.current}`:""})`),ye()});else ct(W,"settled"),ye();Pp(),Np()}).catch((ye)=>{let ot=ye instanceof Error?ye.message:String(ye);z(`Bridge bootstrap failed: ${ot}`)})},we=setTimeout(()=>{if(oe||d.current)return;let ye=c.current,ot=yo(On?"fullscreen":"inline");d.current=!0,Me.setHostContext?.(ot),Promise.resolve(Me.sendHostContextChange(ot)).then(()=>Mx(Me,a.current,ye)).then(()=>{if(l.current=Boolean(ye),ye)u.current=ye;if(w(ye?"done":"ready"),z(null),Pp(),Np(),g.current){ct(W,"settled (fallback)");for(let Ht of y.current.splice(0))Ht()}}).catch((Ht)=>{let bo=Ht instanceof Error?Ht.message:String(Ht);z(`Bridge bootstrap fallback failed: ${bo}`)})},1200),await Me.connect(Kc),oe){ts(),await Kc.close();return}if(o.current=Me,r.current=Kc,Bt=new ResizeObserver(oS),Bt.observe(X),X.parentElement)Bt.observe(X.parentElement);let Rp=!0;f.current=tt.subscribe((ye)=>{if(Rp){Rp=!1;return}if(oe)return;Me.setHostContext?.({...yo(),theme:Gc(ye)}),Me.sendHostContextChange?.(yo())}),Jc(Me)})().catch((Dn)=>{ts(),console.error("[ext-app] Bridge init failed:",Dn),z(Dn?.message??"Bridge initialization failed")}),()=>{if(oe=!0,ts(),$e)clearTimeout($e),$e=null;if(Bt?.disconnect(),Bt=null,Ln!==null)cancelAnimationFrame(Ln),Ln=null;if(vo!==null)cancelAnimationFrame(vo),vo=null;if(d.current=!1,p.current=null,f.current?.(),f.current=null,s.current!==null)window.clearTimeout(s.current),s.current=null;if(o.current=null,r.current)r.current.close().catch((Dn)=>{console.error("[ext-app] transport close failed:",Dn)}),r.current=null}},[ue,Xt.key,ge]),B(()=>{if(Gt&&o.current&&(T==="ready"||T==="done"))Jc(o.current)},[Gt,T]),B(()=>{let X=o.current;if(n.current)n.current.style.height="100%";if(!X||!d.current)return;let oe=null,we=null;return oe=requestAnimationFrame(()=>{oe=null,we=requestAnimationFrame(()=>{if(we=null,!d.current)return;let $e={theme:Gc(tt.value),platform:"web",containerDimensions:Zd(n.current,{width:e.size.width,height:ne}),displayMode:On?"fullscreen":"inline",locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};X.setHostContext?.($e),X.sendHostContextChange?.($e)})}),()=>{if(oe!==null)cancelAnimationFrame(oe);if(we!==null)cancelAnimationFrame(we)}},[On,ne]),!se)return i("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--c-muted)",fontSize:"13px",flexDirection:"column",gap:"8px"},children:[i("div",{style:{opacity:0.6},children:["Loading ",an," viewer..."]},void 0,!0,void 0,this),i("div",{style:{width:"24px",height:"24px",border:"2px solid var(--c-line)",borderTopColor:"var(--c-muted)",borderRadius:"50%",animation:"spin 1s linear infinite"}},void 0,!1,void 0,this),i("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{style:{flex:1,width:"100%",height:"100%",minWidth:0,minHeight:0,display:"flex",flexDirection:"column"},children:[Q&&Q!=="ready"&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:Q==="error"&&!es?"var(--c-danger-12)":"var(--c-warn-10)",color:Q==="error"&&!es?"var(--c-danger)":"var(--c-warn)",borderBottom:`1px solid ${Q==="error"&&!es?"var(--c-danger-12)":"var(--c-warn-15)"}`},children:Xc},void 0,!1,void 0,this),_&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:"var(--c-danger-12)",color:"var(--c-danger)",borderBottom:"1px solid var(--c-danger-12)",display:"flex",alignItems:"center",gap:"6px"},children:[i("span",{children:"⚠"},void 0,!1,void 0,this),i("span",{style:{flex:1},children:_},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>{z(null),w("loading"),N((X)=>X+1)},style:{background:"var(--c-surface-hover)",border:"1px solid var(--c-danger-12)",borderRadius:"3px",color:"var(--c-danger)",cursor:"pointer",fontSize:"10px",padding:"1px 6px"},children:"Retry"},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>z(null),"aria-label":"Dismiss error",style:{background:"none",border:"none",color:"var(--c-danger)",cursor:"pointer",fontSize:"13px",padding:"0 2px"},children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{flex:1,position:"relative",display:"flex",minHeight:0,height:"100%"},children:[ge&&i("iframe",{ref:n,...Xt.attributes,sandbox:bt,allow:Ix(ee?.permissions),style:{flex:1,width:"100%",height:"100%",minHeight:0,border:"none",background:"var(--c-panel)",pointerEvents:On?"auto":"none"},title:`Ext App: ${an}`},ue,!1,void 0,this),S&&!_&&i("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"10px",background:"var(--c-panel)",color:"var(--c-warn)",fontSize:"12px"},children:[i("div",{children:"App surface failed to paint."},void 0,!1,void 0,this),i("button",{type:"button",onClick:(X)=>{X.stopPropagation(),ct(W,"manual-retry"),m.current=0,V(!1),w("loading"),N((oe)=>oe+1)},style:{background:"var(--c-surface-hover)",border:"1px solid var(--c-warn-15)",borderRadius:"4px",color:"var(--c-warn)",cursor:"pointer",fontSize:"11px",padding:"3px 10px"},children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(T==="loading"||Z)&&!_&&!S&&i("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"10px",background:"var(--c-panel)",color:"var(--c-muted)",fontSize:"12px",pointerEvents:"none"},children:[i("div",{style:{width:"22px",height:"22px",border:"2px solid var(--c-line)",borderTopColor:"var(--c-muted)",borderRadius:"50%",animation:"spin 1s linear infinite"}},void 0,!1,void 0,this),i("div",{children:T==="loading"?`Connecting to ${an}...`:"Finishing paint..."},void 0,!1,void 0,this),i("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!On&&!(S&&!_)&&i("button",{type:"button",onClick:(X)=>{X.stopPropagation(),Ut(W)},class:"ext-app-preview-catcher",title:"Click to open",style:{position:"absolute",top:0,right:"56px",bottom:"56px",left:0,background:"transparent",border:"none",padding:0,margin:0,cursor:"zoom-in"},"aria-label":"Open full view to edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function DE(e,t,n,o,r,s,a){if(!e)return e;try{let c=new URL(e,window.location.origin);if(c.searchParams.set("theme",Ar(tt.value)),t)c.searchParams.set("display","expanded");if(typeof n==="number")c.searchParams.set("v",String(n));if(o)c.searchParams.set("axToken",o);if(r)c.searchParams.set("axNodeId",r);if(s)c.searchParams.set("frameToken",s);if(a)c.searchParams.set("fit","content");return c.toString()}catch{return e}}function FE(e,t=window.location.origin){if(!e)return!1;try{let n=new URL(t).origin,o=new URL(e,n);return o.origin===n&&o.pathname.startsWith("/api/canvas/frame-documents/")}catch{return!1}}function Ud({source:e,iframeRef:t,onLoad:n,title:o,className:r="mcp-app-frame",sandbox:s="allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox",allow:a="clipboard-read; clipboard-write",tabIndex:c}){let l=e.src??e.srcdoc??"",[u,p]=I({key:l,source:e}),[d,f]=I(null),m=R(0);B(()=>{if(m.current+=1,!l||l===u.key){f(null);return}if(!u.key){p({key:l,source:e});return}f({key:l,source:e})},[l,u.key]),B(()=>()=>{m.current+=1},[]);let h=(v,x)=>i("iframe",{ref:x?void 0:t,...v.source,class:r,sandbox:s,allow:a,tabIndex:c,loading:_t.value==="srcdoc"?void 0:"lazy",onLoad:(g)=>{if(!x){n();return}let y=++m.current,E=g.currentTarget;requestAnimationFrame(()=>requestAnimationFrame(()=>{if(m.current!==y)return;t.current=E,p(v),f(null),n()}))},style:{position:"absolute",inset:0,width:"100%",height:"100%",visibility:x?"hidden":"visible",background:"var(--c-panel-soft)"},title:o},v.key,!1,void 0,this);return i("div",{class:"mcp-app-frame-stack",children:[h(u,!1),d&&h(d,!0)]},void 0,!0,void 0,this)}function ro({node:e,expanded:t=!1}){if(e.data.mode==="ext-app")return i(Fx,{node:e,expanded:t},void 0,!1,void 0,this);return i(BE,{node:e,expanded:t},void 0,!1,void 0,this)}function BE({node:e,expanded:t}){let n=R(null),o=e.type==="mcp-app"&&e.data.viewerType==="web-artifact",r=e.type==="json-render"||e.type==="graph",s=e.data.axCapabilities?.enabled,c=(r||o)&&(o?s===!0:s!==!1),l=o?"mcp-app":"json-render",u=Ie(()=>c?`ax-${crypto.randomUUID()}`:"",[c]),p=ld(e)&&!t,d=Ie(()=>p?`frame-${crypto.randomUUID()}`:"",[p]);Tr(e,n,d),$r({enabled:c&&Boolean(u),token:u,nodeId:e.id,sourceSurface:l,iframeRef:n});let f=nn.value,m=()=>{if(!c||!u||f==null)return;n.current?.contentWindow?.postMessage({source:qt,type:"ax-update",token:u,state:f},"*")};B(m,[c,u,f]);let h=typeof e.data.specVersion==="number"?e.data.specVersion:void 0,v=DE(e.data.url||"",t,h,u||void 0,c?e.id:void 0,d||void 0,p),x=Ir(v),g=e.data.sourceServer||"",y=e.data.hostMode||"hosted",E=e.data.fallbackReason,L=e.data.trustedDomain===!0||FE(v);if(y==="fallback")return i("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[i("div",{style:{color:"var(--c-warn)",display:"flex",alignItems:"center",gap:"6px"},children:[i("span",{children:"⚠"},void 0,!1,void 0,this),i("span",{children:"Cannot embed — opened externally"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E&&i("div",{style:{color:"var(--c-muted)",fontSize:"11px"},children:["Reason: ",E]},void 0,!0,void 0,this),i("a",{href:v,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all"},children:v},void 0,!1,void 0,this),g&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px"},children:["Source: ",g]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return i("div",{style:{height:"100%",display:"flex",flexDirection:"column",...t?{flex:1,minHeight:0,width:"100%"}:{}},children:[!L&&i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-warn-10)",color:"var(--c-warn)",borderBottom:"1px solid var(--c-warn-15)"},children:"Unverified domain"},void 0,!1,void 0,this),i(Ud,{source:x,iframeRef:n,onLoad:m,title:`MCP App: ${g}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var HE=null;function Or(){HE=null}var Bx={idle:"var(--c-muted)",running:"var(--c-accent)",planning:"var(--c-thinking)",thinking:"var(--c-thinking)",drafting:"var(--c-accent)",tooling:"var(--c-accent)",review:"var(--c-ok)","waiting-approval":"var(--c-warn)",waiting:"var(--c-warn-alt)"};function jE(e){let t=typeof e.data.phase==="string"&&e.data.phase.trim().length>0?e.data.phase.trim():"";if(t)return t;let n=typeof e.data.content==="string"&&e.data.content.trim().length>0?e.data.content.trim():"";if(n)return n;return(typeof e.data.status==="string"&&e.data.status.trim().length>0?e.data.status.trim():"")||"idle"}function gc({node:e}){let t=jE(e),n=e.data.detail||"",o=e.data.message||"",r=e.data.level||"ok",s=e.data.activeTool,a=e.data.subagent,c=Bx[t]??"var(--c-muted)",l=t!=="idle";return i("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i("div",{style:{width:"8px",height:"8px",borderRadius:"50%",background:c,boxShadow:l?`0 0 8px ${c}`:"none",animation:l?"pulse 1.5s infinite":"none",flexShrink:0}},void 0,!1,void 0,this),i("span",{style:{fontWeight:600,color:c,textTransform:"uppercase",letterSpacing:"0.05em"},children:t},void 0,!1,void 0,this),n&&i("span",{style:{color:"var(--c-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-warn)"},children:[i("span",{style:{fontSize:"10px"},children:"⚙"},void 0,!1,void 0,this),i("span",{style:{fontFamily:"var(--mono)",fontSize:"11px"},children:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a&&a.state!=="completed"&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-subagent)"},children:[i("span",{style:{fontSize:"10px"},children:"⠉"},void 0,!1,void 0,this),i("span",{children:a.name},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-muted)",fontSize:"10px"},children:["(",a.state,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),o&&i("div",{style:{color:r==="warn"?"var(--c-warn)":r==="error"?"var(--c-danger)":"var(--c-muted)",lineHeight:1.4},children:o},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Lr(e){return typeof e==="string"&&e.trim().length>0?e.trim():null}function Hx(e){if(typeof e==="string"){let r=Lr(e);return r?{title:"Evidence warning",detail:r}:null}if(!e||typeof e!=="object")return null;let t=e,n=Lr(t.title)??"Evidence warning",o=Lr(t.detail);return o?{title:n,detail:o}:null}function ZE(e){let t=[],n=Hx(e.data.warning);if(n)t.push(n);let o=e.data.warnings;if(Array.isArray(o))for(let s of o){let a=Hx(s);if(a)t.push(a)}let r=Lr(e.data.validationStatus)?.toLowerCase();if(r==="failed"||r==="invalid")t.push({title:"Image failed validation",detail:Lr(e.data.validationMessage)??"Review this image before using it as evidence."});return t}function UE(e){let t=[e.data.title,e.data.caption,e.data.alt,e.data.src,e.data.path].map((n)=>Lr(n)?.toLowerCase()??"").join(" ");if(t.length===0)return!1;return["login","log in","sign in","signin","password","2fa","mfa","authenticate","authentication","sso"].some((n)=>t.includes(n))}function jx(e){let t=ZE(e);if(t.length>0)return t;if(UE(e))return[{title:"Captured login page",detail:"This image looks like an auth screen. Treat it as environment context, not product evidence."}];return[]}function vc({node:e,expanded:t=!1}){let n=e.data.src||"",o=e.data.alt||e.data.title||"Image",r=e.data.caption||"",s=jx(e),a=n.startsWith("data:")||n.startsWith("http://")||n.startsWith("https://")?n:`/api/canvas/image/${e.id}`,[c,l]=I(!1),[u,p]=I(!1),[d,f]=I(1),[m,h]=I({x:0,y:0}),[v,x]=I({w:0,h:0}),g=R(null),y=R(!1),E=R({x:0,y:0}),L=H((Z)=>{let j=Z.target;x({w:j.naturalWidth,h:j.naturalHeight}),l(!0),p(!1)},[]),P=H(()=>{p(!0),l(!1)},[]);B(()=>{f(1),h({x:0,y:0})},[n]);let b=H((Z)=>{Z.preventDefault(),Z.stopPropagation();let j=Z.deltaY>0?0.9:1.1;f((S)=>Math.max(0.25,Math.min(10,S*j)))},[]),T=H((Z)=>{if(d<=1)return;Z.stopPropagation(),y.current=!0,E.current={x:Z.clientX,y:Z.clientY},Z.target.setPointerCapture(Z.pointerId)},[d]),w=H((Z)=>{if(!y.current)return;let j=Z.clientX-E.current.x,S=Z.clientY-E.current.y;E.current={x:Z.clientX,y:Z.clientY},h((V)=>({x:V.x+j,y:V.y+S}))},[]),_=H(()=>{y.current=!1},[]),z=H(()=>{f(1),h({x:0,y:0})},[]);if(!n)return i("div",{class:"image-node-empty",children:[i("div",{class:"image-node-empty-icon",children:"\uD83D\uDDBC"},void 0,!1,void 0,this),i("div",{class:"image-node-empty-text",children:"No image source"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let U=v.w>0?`${v.w}×${v.h}`:"",N=Math.round(d*100);return i("div",{class:`image-node ${t?"image-node-expanded":""}`,ref:g,children:[s.length>0&&i("div",{class:"image-node-warning-stack",children:s.map((Z)=>i("div",{class:"image-node-warning",children:[i("span",{class:"image-node-warning-title",children:Z.title},void 0,!1,void 0,this),i("span",{class:"image-node-warning-detail",children:Z.detail},void 0,!1,void 0,this)]},`${Z.title}-${Z.detail}`,!0,void 0,this))},void 0,!1,void 0,this),i("div",{class:"image-node-viewport",onWheel:b,onPointerDown:T,onPointerMove:w,onPointerUp:_,style:{cursor:d>1?"grab":"default"},children:[!c&&!u&&i("div",{class:"image-node-loading",children:"Loading…"},void 0,!1,void 0,this),u&&i("div",{class:"image-node-error",children:[i("div",{class:"image-node-error-icon",children:"⚠"},void 0,!1,void 0,this),i("div",{children:"Failed to load image"},void 0,!1,void 0,this),i("div",{class:"image-node-error-path",children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("img",{src:a,alt:o,onLoad:L,onError:P,draggable:!1,style:{transform:`translate(${m.x}px, ${m.y}px) scale(${d})`,opacity:c?1:0,display:u?"none":"block"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(r||U||d!==1)&&i("div",{class:"image-node-footer",children:[r&&i("span",{class:"image-node-caption",children:r},void 0,!1,void 0,this),i("span",{class:"image-node-meta",children:[U&&i("span",{children:U},void 0,!1,void 0,this),d!==1&&i("button",{type:"button",class:"image-node-zoom-reset",onClick:z,title:"Reset zoom",children:[N,"% ",i(ha,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Zx({node:e}){if((e.data.children??[]).filter((o)=>F.value.has(o)).length>0)return null;return i("div",{class:"group-empty-hint",children:"Drop nodes here — release while the frame lights up to add them"},void 0,!1,void 0,this)}function qE(e){try{return new URL(e).host}catch{return e}}function WE(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleString()}function yc({node:e,expanded:t=!1}){let n=typeof e.data.url==="string"?e.data.url:"",o=typeof e.data.pageTitle==="string"?e.data.pageTitle:"",r=typeof e.data.description==="string"?e.data.description:"",s=typeof e.data.excerpt==="string"?e.data.excerpt:typeof e.data.content==="string"?e.data.content:"",a=typeof e.data.status==="string"?e.data.status:"idle",c=typeof e.data.error==="string"?e.data.error:"",l=WE(typeof e.data.fetchedAt==="string"?e.data.fetchedAt:void 0),u=typeof e.data.statusCode==="number"?e.data.statusCode:null,p=typeof e.data.imageUrl==="string"?e.data.imageUrl:"",d=e.data.frameBlocked===!0,f=typeof e.data.frameBlockedReason==="string"?e.data.frameBlockedReason:"",[m,h]=I(!1),[v,x]=I(t);B(()=>{if(t)x(!0)},[t]);let g=H(async()=>{if(!n||m)return;h(!0);try{await Qs(e.id)}finally{h(!1)}},[e.id,m,n]);if(!n)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No webpage URL set"},void 0,!1,void 0,this);let y=a==="ready"?"var(--c-ok)":a==="error"?"var(--c-danger)":"var(--c-warn)";return i("div",{style:{display:"flex",flexDirection:"column",gap:"12px",height:"100%"},children:[i("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[i("div",{style:{minWidth:0,flex:1},children:[i("div",{style:{fontSize:"12px",color:"var(--c-muted)"},children:qE(n)},void 0,!1,void 0,this),i("div",{style:{fontSize:t?"18px":"15px",fontWeight:700,color:"var(--c-text)"},children:o||e.data.title||n},void 0,!1,void 0,this),i("a",{href:n,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all",textDecoration:"none"},children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"999px",background:"rgba(255,255,255,0.04)",color:y,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.04em",flexShrink:0},children:[i("span",{style:{width:"7px",height:"7px",borderRadius:"999px",background:y}},void 0,!1,void 0,this),a]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),(r||p)&&i("div",{style:{display:"grid",gridTemplateColumns:p&&t?"160px 1fr":"1fr",gap:"12px",alignItems:"start"},children:[p&&t&&i("img",{src:p,alt:o||"Webpage preview image",style:{width:"160px",height:"96px",objectFit:"cover",borderRadius:"10px",border:"1px solid var(--c-line)",background:"var(--c-panel-soft)"}},void 0,!1,void 0,this),r&&i("p",{style:{margin:0,color:"var(--c-text-soft)",lineHeight:1.5,fontSize:t?"14px":"12px"},children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{display:"flex",gap:"8px",flexWrap:"wrap"},children:[i("button",{type:"button",onClick:g,disabled:m,style:{border:"1px solid var(--c-line)",background:"var(--c-panel-soft)",color:"var(--c-text)",borderRadius:"8px",padding:"6px 10px",cursor:m?"progress":"pointer",fontSize:"12px"},children:m||a==="fetching"?"Refreshing…":"Refresh"},void 0,!1,void 0,this),t&&!d&&i("button",{type:"button",onClick:()=>x((E)=>!E),style:{border:"1px solid var(--c-line)",background:"var(--c-panel-soft)",color:"var(--c-text)",borderRadius:"8px",padding:"6px 10px",cursor:"pointer",fontSize:"12px"},children:v?"Hide live preview":"Show live preview"},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>window.open(n,"_blank","noopener"),style:{border:"1px solid var(--c-line)",background:"transparent",color:"var(--c-accent)",borderRadius:"8px",padding:"6px 10px",cursor:"pointer",fontSize:"12px"},children:"Open in browser"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&d&&i("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[i("div",{style:{padding:"8px 12px",fontSize:"11px",color:"var(--c-muted)",borderBottom:"1px solid var(--c-line)",background:"rgba(255,255,255,0.03)"},children:"Live preview unavailable. This site refuses embedding, so PMX Canvas cannot show it inline."},void 0,!1,void 0,this),i("div",{style:{padding:"20px",color:"var(--c-text-soft)",lineHeight:1.6,fontSize:"13px"},children:f||"The remote site blocks iframe embedding."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&v&&!d&&i("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[i("div",{style:{padding:"8px 12px",fontSize:"11px",color:"var(--c-muted)",borderBottom:"1px solid var(--c-line)",background:"rgba(255,255,255,0.03)"},children:"Live preview (best effort). If this stays blank, the site likely blocks framing. The cached text snapshot below still works."},void 0,!1,void 0,this),i("iframe",{class:"webpage-node-iframe",title:o||e.data.title||n,src:n,loading:"lazy",referrerPolicy:"no-referrer",sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-presentation allow-scripts",style:{display:"block",width:"100%",height:t?"320px":"180px",border:"none",background:"#fff"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(l||u!==null)&&i("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap",color:"var(--c-muted)",fontSize:"11px"},children:[l&&i("span",{children:["Fetched ",l]},void 0,!0,void 0,this),u!==null&&i("span",{children:["HTTP ",u]},void 0,!0,void 0,this),d&&i("span",{children:"Preview blocked by site"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c&&i("div",{style:{color:"var(--c-danger)",fontSize:"12px",lineHeight:1.5},children:c},void 0,!1,void 0,this),i("div",{style:{flex:1,minHeight:0,overflow:"auto",border:"1px solid var(--c-line)",borderRadius:"10px",background:"var(--c-panel-soft)",padding:t?"14px":"10px"},children:s?i("div",{style:{whiteSpace:"pre-wrap",lineHeight:1.55,color:"var(--c-text)",fontSize:t?"14px":"12px"},children:s},void 0,!1,void 0,this):i("div",{style:{color:"var(--c-dim)",fontStyle:"italic"},children:a==="error"?"No cached page text available.":"Waiting for page text..."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ux(e){return e.type==="html"&&e.data.presentation===!0}function Hi({node:e,expanded:t=!1,presentation:n=!1,presentationExitToken:o,autoFocus:r=!1}){let s=R(null),a=tt.value,c=Ie(()=>`theme-${crypto.randomUUID()}`,[]),l=Ie(()=>`ax-${crypto.randomUUID()}`,[]),u=Ie(()=>`frame-${crypto.randomUUID()}`,[]),p=typeof e.data.html==="string"?e.data.html:typeof e.data.content==="string"?e.data.content:"",d=Ie(()=>wr(p),[p]),f=Ie(()=>p?Ci(e.id,{theme:a,themeToken:c,present:n,presentToken:o,v:d,axToken:l,frameToken:u}):"",[p,n,o,c,d,e.id,l,u]),m=Ir(f);Tr(e,s,t?"":u),$r({enabled:!0,token:l,nodeId:e.id,sourceSurface:"html-node",iframeRef:s}),B(()=>{if(s.current?.contentWindow?.postMessage({source:qt,type:"theme-update",token:c,theme:a},"*"),r)s.current?.focus()},[a,c]);let h=e.data.axCapabilities,v=h?.enabled===!0&&(!Array.isArray(h.allowed)||h.allowed.length>0),x=nn.value;B(()=>{if(!v||x==null)return;s.current?.contentWindow?.postMessage({source:qt,type:"ax-update",token:l,state:x},"*")},[v,x,l]),B(()=>{if(!r)return;let y=window.setTimeout(()=>s.current?.focus(),0);return()=>window.clearTimeout(y)},[r,f]);let g=()=>{if(s.current?.contentWindow?.postMessage({source:qt,type:"theme-update",token:c,theme:a},"*"),v&&nn.value!=null)s.current?.contentWindow?.postMessage({source:qt,type:"ax-update",token:l,state:nn.value},"*");if(r)s.current?.focus()};if(!p)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No HTML content set"},void 0,!1,void 0,this);return i(Ud,{source:m,iframeRef:s,className:n?"html-node-frame html-node-frame-presentation":t?"html-node-frame html-node-frame-expanded":"html-node-frame",title:typeof e.data.title==="string"?e.data.title:"HTML node",sandbox:"allow-scripts",allow:"",tabIndex:r?0:void 0,onLoad:g},void 0,!1,void 0,this)}var qd=null;async function qx(){if(!qd)qd=await $v();return qd}function Wx(e,t){if(!e)return null;let n=e.toLowerCase(),o=t.find((s)=>s.name.toLowerCase()===n);if(o)return o.name;let r=t.filter((s)=>s.name.toLowerCase().startsWith(n));return r.length===1?r[0].name:null}function VE(e){return e.replace(/<script[\s>][\s\S]*?<\/script>/gi,"").replace(/<iframe[\s>][\s\S]*?<\/iframe>/gi,"").replace(/<object[\s>][\s\S]*?<\/object>/gi,"").replace(/<embed[\s>][\s\S]*?(?:\/>|<\/embed>)/gi,"").replace(/<link[\s>][\s\S]*?(?:\/>|<\/link>)/gi,"").replace(/\bon\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,"").replace(/href\s*=\s*"javascript:[^"]*"/gi,'href="#"').replace(/href\s*=\s*'javascript:[^']*'/gi,"href='#'")}function GE({html:e}){let t=R(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=e,n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function XE(e,t){return`${e.role}:${e.status??"none"}:${t}:${e.text}`}function Vx({count:e}){if(e===0)return null;return i("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--c-accent)",background:"rgba(70,182,255,0.08)",borderRadius:"var(--radius-sm)",flexShrink:0},children:["✦"," ",e," context node",e!==1?"s":""," attached"]},void 0,!0,void 0,this)}function Gx({message:e,onDismiss:t}){if(!e)return null;return i("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--c-danger)",background:"rgba(255,80,80,0.08)",borderRadius:"var(--radius-sm)",display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[i("span",{style:{flex:1},children:e},void 0,!1,void 0,this),i("button",{type:"button",onClick:t,"aria-label":"Dismiss error",style:{background:"none",border:"none",color:"var(--c-danger)",cursor:"pointer",fontSize:"13px",padding:"0 2px"},children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function bc({node:e,expanded:t=!1}){let n=Array.isArray(e.data.turns)?e.data.turns:[],o=n.length===0,r=e.data.text||"",s=e.data.status||"draft",a=o?s:e.data.threadStatus||"draft",c=a==="draft",l=a==="pending"||a==="sending",u=a==="streaming",p=a==="answered",[d,f]=I(""),[m,h]=I(""),[v,x]=I(null),[g,y]=I(new Map),E=R(null),L=R(null),P=n[n.length-1],b=`${n.length}:${P?.role??""}:${P?.status??""}:${Math.floor((P?.text?.length??0)/200)}`;B(()=>{if(t&&c&&E.current)E.current.focus()},[t,c]),B(()=>{if(!b)return;if(L.current)L.current.scrollTo({top:L.current.scrollHeight,behavior:"smooth"})},[b]);let T=R(null),w=R(n);w.current=n,B(()=>{let j=n.some((V)=>V.role==="assistant"&&V.status==="streaming"),S=()=>{let V=!1,Ze=w.current.map((se,de)=>({turn:se,index:de})).filter(({turn:se})=>se.role==="assistant"&&se.text);if(Ze.length===0)return;return Promise.all(Ze.map(async({turn:se,index:de})=>{let me=await wn(se.text);return{index:de,html:VE(me)}})).then((se)=>{if(V)return;let de=new Map;for(let me of se)de.set(me.index,me.html);y(de)}),()=>{V=!0}};if(!j){if(T.current)clearTimeout(T.current),T.current=null;return S()}if(T.current)clearTimeout(T.current);return T.current=setTimeout(()=>{T.current=null,S()},400),()=>{if(T.current)clearTimeout(T.current),T.current=null}},[n]);let _=H(async()=>{let j=d.trim();if(!j)return;let S=d;x(null),ie(e.id,{turns:[{role:"user",text:j,status:"pending"}],threadStatus:"pending",text:j}),f("");let V=Array.isArray(e.data.contextNodeIds)?e.data.contextNodeIds:void 0;if(!(await hi(j,e.position,e.id,V,e.id)).ok)ie(e.id,{turns:[],threadStatus:"draft",text:"",status:"draft"}),f(S),x("Failed to send prompt. Your draft has been restored.")},[d,e.id,e.position,e.data.contextNodeIds]),z=H(async()=>{let j=m.trim();if(!j)return;let S=m;x(null);let V=Array.isArray(e.data.turns)?[...e.data.turns]:[];if(V.push({role:"user",text:j,status:"pending"}),ie(e.id,{turns:V,threadStatus:"pending"}),h(""),!(await Mv(e.id,j)).ok)V.pop(),ie(e.id,{turns:V,threadStatus:"answered"}),h(S),x("Failed to send reply. Your draft has been restored.")},[m,e.id,e.data.turns]),U=H((j)=>{if(j.key==="Enter"&&(j.metaKey||j.ctrlKey)){j.preventDefault(),_();return}if(j.key==="Tab"&&d.startsWith("/")){j.preventDefault();let S=d.slice(1).split(/\s/)[0];if(S)qx().then((V)=>{let ge=Wx(S,V);if(ge)f(`/${ge}`)})}},[_,d]),N=H((j)=>{if(j.key==="Enter"&&(j.metaKey||j.ctrlKey)){j.preventDefault(),z();return}if(j.key==="Tab"&&m.startsWith("/")){j.preventDefault();let S=m.slice(1).split(/\s/)[0];if(S)qx().then((V)=>{let ge=Wx(S,V);if(ge)h(`/${ge}`)})}},[z,m]),Z=Array.isArray(e.data.contextNodeIds)?e.data.contextNodeIds.length:0;if(c&&n.length===0)return i("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%",gap:"8px"},children:[i(Vx,{count:Z},void 0,!1,void 0,this),i(Gx,{message:v,onDismiss:()=>x(null)},void 0,!1,void 0,this),i("textarea",{ref:E,value:d,onInput:(j)=>f(j.target.value),onKeyDown:U,placeholder:"Ask the agent something…",spellcheck:!1,style:{flex:1,resize:"none",background:"rgba(10,14,30,0.4)",border:"1px solid var(--c-line)",borderRadius:"var(--radius-sm)",color:"var(--c-text)",fontFamily:"var(--font)",fontSize:"13px",lineHeight:"1.5",padding:"8px 10px",outline:"none"}},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter to send"]},void 0,!0,void 0,this),i("button",{type:"button",onClick:_,disabled:!d.trim(),style:{padding:"5px 14px",fontSize:"12px",fontWeight:600,background:d.trim()?"var(--c-accent)":"var(--c-line)",color:d.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:d.trim()?"pointer":"default"},children:"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(o)return i("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[i("div",{style:{flex:1,padding:"2px 0",fontSize:"13px",lineHeight:"1.55",color:"var(--c-text)",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto"},children:r},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:"6px",borderTop:"1px solid var(--c-line)",marginTop:"4px"},children:i("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:l?"var(--c-warn)":p?"var(--c-ok)":"var(--c-muted)"},children:l?"Sending…":p?"Answered":s},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[i(Vx,{count:Z},void 0,!1,void 0,this),i(Gx,{message:v,onDismiss:()=>x(null)},void 0,!1,void 0,this),i("div",{ref:L,style:{flex:1,overflow:"auto",minHeight:0},children:n.map((j,S)=>i("div",{children:[S>0&&i("div",{class:"thread-turn-divider"},void 0,!1,void 0,this),j.role==="user"?i("div",{class:"thread-turn-user",children:[i("div",{class:"thread-turn-role",children:[i("span",{class:"status-dot"},void 0,!1,void 0,this),"You"]},void 0,!0,void 0,this),i("div",{style:{fontSize:t?"15px":"13px",lineHeight:t?"1.7":"1.55",color:"var(--c-text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:j.text},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i("div",{class:"thread-turn-assistant",children:[i("div",{class:"thread-turn-role",children:[i("span",{class:`status-dot${j.status==="streaming"?" pulsing":""}`},void 0,!1,void 0,this),"PMX"]},void 0,!0,void 0,this),j.status==="streaming"&&!j.text&&i("div",{style:{height:"2px",background:"linear-gradient(90deg, transparent, var(--c-ok), transparent)",animation:"response-stream-pulse 1.5s ease-in-out infinite",borderRadius:"1px",marginBottom:"4px"}},void 0,!1,void 0,this),i("div",{class:t?"md-reader-content":void 0,style:{fontSize:t?void 0:"13px",lineHeight:t?void 0:"1.55",opacity:j.text?1:0.4},children:g.get(S)?i(pe,{children:[i(GE,{html:g.get(S)??""},void 0,!1,void 0,this),j.status==="streaming"&&i("span",{class:"streaming-cursor"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i("div",{style:{color:"var(--c-muted)",fontStyle:"italic"},children:j.status==="streaming"?"Waiting for response…":j.text||"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},XE(j,S),!0,void 0,this))},void 0,!1,void 0,this),i("div",{style:{flexShrink:0,borderTop:"1px solid var(--c-line)",marginTop:"4px",paddingTop:"6px"},children:[i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:p?"6px":0},children:[i("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:u?"var(--c-accent)":l?"var(--c-warn)":p?"var(--c-ok)":"var(--c-muted)"},children:u?"Streaming…":l?"Sending…":p?"Answered":a},void 0,!1,void 0,this),i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:[n.length," turn",n.length!==1?"s":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),p&&i("div",{class:"thread-reply-area",children:[i("textarea",{value:m,onInput:(j)=>h(j.target.value),onKeyDown:N,placeholder:"Reply…",spellcheck:!1,rows:2,style:{width:"100%",resize:"none",background:"rgba(10,14,30,0.4)",border:"1px solid var(--c-line)",borderRadius:"var(--radius-sm)",color:"var(--c-text)",fontFamily:"var(--font)",fontSize:"12px",lineHeight:"1.5",padding:"6px 8px",outline:"none"}},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"4px"},children:[i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter"]},void 0,!0,void 0,this),i("button",{type:"button",onClick:z,disabled:!m.trim(),style:{padding:"3px 10px",fontSize:"11px",fontWeight:600,background:m.trim()?"var(--c-accent)":"var(--c-line)",color:m.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:m.trim()?"pointer":"default"},children:"Reply"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function JE(e){return e.replace(/<script[\s>][\s\S]*?<\/script>/gi,"").replace(/<iframe[\s>][\s\S]*?<\/iframe>/gi,"").replace(/<object[\s>][\s\S]*?<\/object>/gi,"").replace(/<embed[\s>][\s\S]*?(?:\/>|<\/embed>)/gi,"").replace(/<link[\s>][\s\S]*?(?:\/>|<\/link>)/gi,"").replace(/\bon\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,"").replace(/href\s*=\s*"javascript:[^"]*"/gi,'href="#"').replace(/href\s*=\s*'javascript:[^']*'/gi,"href='#'")}function KE({html:e}){let t=R(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=e,n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function xc({node:e,expanded:t=!1}){let n=e.data.content||"",o=e.data.status||"streaming",[r,s]=I(""),a=o==="streaming",c=o==="complete";B(()=>{if(!n){s("");return}let u=!1;return wn(n).then((p)=>{if(!u)s(JE(p))}),()=>{u=!0}},[n]);let l=H(()=>{hi("",{x:e.position.x,y:e.position.y+e.size.height+24},e.id)},[e]);return i("div",{class:"response-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[a&&i("div",{class:"response-streaming-bar",style:{height:"2px",background:"linear-gradient(90deg, transparent, var(--c-accent), transparent)",animation:"response-stream-pulse 1.5s ease-in-out infinite",borderRadius:"1px",marginBottom:"4px",flexShrink:0}},void 0,!1,void 0,this),i("div",{class:t?"md-reader":void 0,style:{flex:1,overflow:"auto",minHeight:0,opacity:n?1:0.4,transition:"opacity 0.2s ease"},children:r?i("div",{class:t?"md-reader-content":void 0,children:i(KE,{html:r},void 0,!1,void 0,this)},void 0,!1,void 0,this):i("div",{style:{color:"var(--c-muted)",fontStyle:"italic",fontSize:"13px"},children:a?"Waiting for response…":"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:"6px",borderTop:"1px solid var(--c-line)",marginTop:"4px",flexShrink:0},children:[i("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:a?"var(--c-accent)":c?"var(--c-ok)":"var(--c-muted)"},children:a?"Streaming…":c?"Complete":o},void 0,!1,void 0,this),c&&i("button",{type:"button",onClick:l,style:{padding:"3px 10px",fontSize:"11px",background:"rgba(70,182,255,0.1)",border:"1px solid rgba(70,182,255,0.3)",borderRadius:"var(--radius-sm)",color:"var(--c-accent)",cursor:"pointer"},children:"Reply"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Xx(e){return{toolName:e.toolName||e.title||"unknown",category:e.category||"other",status:e.status||"running",duration:e.duration||"",resultSummary:e.resultSummary||e.content||"",error:e.error||""}}var Jx={mcp:"var(--c-accent)",file:"var(--c-warn)",subagent:"var(--c-purple)",other:"var(--c-muted)"},YE={running:"⠋",success:"✓",failed:"✕"},QE={running:"var(--c-accent)",success:"var(--c-ok)",failed:"var(--c-danger)"};function wc({node:e}){let{toolName:t,category:n,status:o,duration:r,resultSummary:s,error:a}=Xx(e.data),c=Jx[n]??Jx.other,l=YE[o]??"◌",u=QE[o]??"var(--c-muted)",p=o==="running",d=a?a.slice(0,30):s.length>30?`${s.slice(0,28)}…`:s;return i("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"0 12px",height:"100%",overflow:"hidden"},children:[i("span",{style:{fontSize:"14px",color:u,flexShrink:0,animation:p?"pulse 1.5s infinite":"none"},children:l},void 0,!1,void 0,this),i("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:[i("div",{style:{fontFamily:"var(--mono)",fontSize:"11px",fontWeight:600,color:c,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t},void 0,!1,void 0,this),d&&i("div",{style:{fontSize:"10px",color:a?"var(--c-danger)":"var(--c-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:1.3},children:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r&&i("span",{style:{fontSize:"9px",padding:"1px 5px",borderRadius:"3px",background:"rgba(255,255,255,0.06)",color:"var(--c-muted)",flexShrink:0,whiteSpace:"nowrap"},children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Vd(e){let t=F.value.get(e);if(!t)return null;return{left:t.position.x,top:t.position.y,width:t.size.width,height:t.size.height}}function e1(e){let t=e.map((l)=>Vd(l)).filter((l)=>l!==null);if(t.length===0)return null;let n=Math.min(...t.map((l)=>l.left)),o=Math.min(...t.map((l)=>l.top)),r=Math.max(...t.map((l)=>l.left+l.width)),s=Math.max(...t.map((l)=>l.top+l.height)),a=54,c=46;return{left:n-a,top:o-c,width:r-n+a*2,height:s-o+c*2}}function Wd(e,t){return{left:`${e.left}px`,top:`${e.top}px`,width:`${e.width}px`,height:`${e.height}px`,borderRadius:`${t}px`}}function Kx(){let e=Array.from(rr.value),t=Array.from(ir.value),n=Zs.value;if(e.length===0&&t.length===0)return null;let o=[...F.value.values()],r=o.length>0?(Math.max(...o.map((s)=>s.position.x+s.size.width))-Math.min(...o.map((s)=>s.position.x)))*(Math.max(...o.map((s)=>s.position.y+s.size.height))-Math.min(...o.map((s)=>s.position.y))):0;return i("div",{class:"attention-field-layer","aria-hidden":"true",children:[n.map((s)=>{let a=e1(s.nodeIds);if(!a)return null;if(r>0&&a.width*a.height>=r*0.75)return null;return i("div",{class:"attention-field-region",style:Wd(a,42)},s.id,!1,void 0,this)}),t.map((s)=>{let a=Vd(s);if(!a)return null;return i("div",{class:"attention-field-node attention-field-secondary",style:Wd({left:a.left-18,top:a.top-18,width:a.width+36,height:a.height+36},28)},`secondary-${s}`,!1,void 0,this)}),e.map((s)=>{let a=Vd(s);if(!a)return null;return i("div",{class:"attention-field-node attention-field-primary",style:Wd({left:a.left-24,top:a.top-24,width:a.width+48,height:a.height+48},30)},`primary-${s}`,!1,void 0,this)})]},void 0,!0,void 0,this)}var t1=new Set(["png","jpg","jpeg","gif","svg","webp","bmp","ico","avif"]),n1=new Set(["md","mdx","markdown"]);function o1(e){let t=e.split(".").pop()?.toLowerCase()??"";if(t1.has(t))return"image";if(n1.has(t))return"markdown";return"file"}async function Dr(e,t,n){let o=Ne.value,r=400,s=300,a=20,c=Math.ceil(Math.sqrt(e.length));for(let l=0;l<e.length;l++){let u=e[l],p=l%c,d=Math.floor(l/c),f=t-c*420/2+p*420,m=n-150+d*320,h=o1(u.name),v=u.name;if(/\.(pdf|pptx?|xlsx?|docx?|od[pts])$/i.test(v)){if(!o||u.size===0||u.size>20971520){xn("remove","File not attached","Open a board and choose a nonempty file under 20 MiB.");continue}let x=new URLSearchParams({boardId:o,name:v,mime:u.type,x:String(f),y:String(m)});xn("context","Attaching document",v),await Y("attachDocument",`/api/canvas/attachments?${x}`,null,{method:"POST",body:u});continue}if(Ne.value!==o)return;if(h==="image"){let x=new FileReader,g=await new Promise((y)=>{x.onload=()=>y(x.result),x.readAsDataURL(u)});if(Ne.value!==o)return;await en({type:"image",title:v,content:g,x:f,y:m,width:400,height:300,...o?{boardId:o}:{}})}else{let x=await u.text();if(Ne.value!==o)return;let g=h==="markdown"||h==="file";await en({type:h,title:v,content:x,x:f,y:m,width:g?720:400,height:g?500:300,...o?{boardId:o}:{}})}}}var Yx={width:260,height:150},r1={markdown:{width:300,height:170},status:{width:280,height:110},context:{width:300,height:200},trace:{width:220,height:64},file:{width:300,height:190},image:{width:260,height:200},webpage:{width:320,height:210},html:{width:320,height:210},group:{width:340,height:210},graph:{width:320,height:210},"json-render":{width:320,height:210},"mcp-app":{width:340,height:230}};function Xd(e){return!!e&&e in ut}function Pn(e){if(!e)return null;let t=F.value.get(e);if(!t)return null;return{left:t.position.x,top:t.position.y,width:t.size.width,height:t.size.height}}function Gd(e){return{x:e.left+e.width/2,y:e.top+e.height/2}}function ji(e){let t=typeof e.confidence!=="number"?0.82:0.4+Math.max(0,Math.min(1,e.confidence))*0.55;return e.auto?t*0.62:t}function Qx(e,t){let n=Math.max(40,Math.abs(t.x-e.x)/2);return`M ${e.x} ${e.y} C ${e.x+n} ${e.y}, ${t.x-n} ${t.y}, ${t.x} ${t.y}`}function Jd({intent:e}){let t=Xd(e.nodeType)?rn(e.nodeType):null,n=e.label||e.kind,o=typeof e.confidence==="number"?`${Math.round(e.confidence*100)}%`:null;return i("div",{class:"intent-info",onMouseEnter:()=>Sr.value=e.id,onMouseLeave:()=>{if(Sr.value===e.id)Sr.value=null},children:[i("div",{class:"intent-chip",children:[typeof e.seq==="number"&&i("span",{class:"intent-seq",children:e.seq},void 0,!1,void 0,this),t&&i("span",{class:"intent-chip-icon","aria-hidden":"true",children:i(t,{size:12},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"intent-chip-label",children:n},void 0,!1,void 0,this),o&&i("span",{class:"intent-confidence",children:o},void 0,!1,void 0,this),e.phase==="forming"&&!e.auto&&i("button",{type:"button",class:"intent-veto",title:"Veto this move (Esc)","aria-label":"Veto this move",onClick:(r)=>{r.stopPropagation(),Io(e)},children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.reason&&i("div",{class:"intent-reason",children:e.reason},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ew({intent:e,rect:t}){let n=Xd(e.nodeType)?rn(e.nodeType):null,o=Xd(e.nodeType)?ut[e.nodeType]:"Node";return i("div",{class:`intent-ghost intent-ghost-box is-${e.phase}${e.auto?" is-auto":""}`,"data-intent-id":e.id,style:{left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`,opacity:ji(e)},children:[i("div",{class:"intent-ghost-titlebar",children:[i("span",{class:"intent-ghost-icon","aria-hidden":"true",children:n?i(n,{size:13},void 0,!1,void 0,this):"◇"},void 0,!1,void 0,this),i("span",{class:"intent-ghost-badge",children:o},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Jd,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function tw({intent:e,rect:t,variant:n}){return i("div",{class:`intent-ghost intent-ghost-${n} is-${e.phase}${e.auto?" is-auto":""}`,"data-intent-id":e.id,style:{left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`,opacity:ji(e)},children:[n==="edit"&&i("div",{class:"intent-edit-bar"},void 0,!1,void 0,this),i(Jd,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function i1(e){let t=e.phase==="settling"?Pn(e.settledNodeId):null;switch(e.kind){case"create":{if(!e.position)return null;let n=e.nodeType&&r1[e.nodeType]||Yx,o=t??{left:e.position.x,top:e.position.y,...n};return i(ew,{intent:e,rect:o},e.id,!1,void 0,this)}case"move":{if(!e.position)return null;let o=Pn(e.nodeId)??Yx,r=t??{left:e.position.x,top:e.position.y,width:o.width,height:o.height};return i(ew,{intent:e,rect:r},e.id,!1,void 0,this)}case"remove":{let n=t??Pn(e.nodeId);if(!n)return null;return i(tw,{intent:e,rect:n,variant:"remove"},e.id,!1,void 0,this)}case"edit":{let n=t??Pn(e.nodeId);if(!n)return null;return i(tw,{intent:e,rect:n,variant:"edit"},e.id,!1,void 0,this)}case"connect":{if(!e.edge)return null;let n=Pn(e.edge.from),o=Pn(e.edge.to);if(!n||!o)return null;let r={x:(n.left+n.width/2+o.left+o.width/2)/2,y:(n.top+n.height/2+o.top+o.height/2)/2},s={left:r.x-110,top:r.y-18,width:220,height:36};return i("div",{class:`intent-ghost intent-ghost-connect is-${e.phase}${e.auto?" is-auto":""}`,"data-intent-id":e.id,style:{left:`${s.left}px`,top:`${s.top}px`,width:`${s.width}px`,opacity:ji(e)},children:i(Jd,{intent:e},void 0,!1,void 0,this)},e.id,!1,void 0,this)}default:return null}}function nw(){let e=Array.from(Ge.value.values());if(B(()=>{function t(n){if(n.key!=="Escape")return;let o=Sr.value;if(!o)return;let r=Ge.value.get(o);if(!r||r.phase!=="forming")return;n.stopImmediatePropagation(),n.preventDefault(),Io(r)}return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[]),e.length===0)return null;return i("div",{class:"intent-layer",onAnimationEnd:(t)=>{if(t.animationName!=="intent-settle"&&t.animationName!=="intent-dissolve")return;let n=t.target.dataset.intentId;if(n&&Ge.value.get(n)?.phase!=="forming")Mo(n)},children:[i("svg",{class:"intent-line-layer",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},children:[i("defs",{children:i("marker",{id:"intent-arrow",markerWidth:"8",markerHeight:"8",refX:"6",refY:"3",orient:"auto",children:i("path",{d:"M0,0 L6,3 L0,6 Z",class:"intent-arrow-head"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),e.map((t)=>{if(t.kind==="connect"&&t.edge){let n=Pn(t.edge.from),o=Pn(t.edge.to);if(!n||!o)return null;return i("path",{d:Qx(Gd(n),Gd(o)),class:`intent-edge type-${t.edge.type}`,style:{opacity:ji(t)}},`line-${t.id}`,!1,void 0,this)}if(t.kind==="move"&&t.position){let n=Pn(t.nodeId);if(!n)return null;let o=n,r={x:t.position.x+o.width/2,y:t.position.y+o.height/2};return i("path",{d:Qx(Gd(n),r),class:"intent-trail",markerEnd:"url(#intent-arrow)",style:{opacity:ji(t)}},`line-${t.id}`,!1,void 0,this)}return null})]},void 0,!0,void 0,this),e.map(i1)]},void 0,!0,void 0,this)}var ow=32000;var _c="Agent session";function rw(e){return e.some((t)=>t.attached)}function iw(e){return e.filter((t)=>!t.attached)}function io(e){switch(e.phase){case"thinking":return"Thinking";case"tooling":return e.detail?`Running ${e.detail}`:"Working";case"waiting-approval":return"Waiting on you";default:return"Idle"}}function so(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return(t%360+360)%360}var vt=q([]),Yd=q({used:0,total:ow}),ao=q([]),Ho=q(!1),Fr=q(!1),Qd=q(null),sw=["var(--c-purple)","var(--c-accent)","var(--c-ok)","var(--c-warn)","var(--c-danger)"],Kd=new Map;function Sc(e){let t=Kd.get(e);if(t)return t;let n=sw[Kd.size%sw.length];return Kd.set(e,n),n}function aw(e){return(e.trim().replace(/^[^a-z0-9]+/i,"").charAt(0)||e.trim().charAt(0)||"?").toUpperCase()}function kc(e,t=Date.now()){let n=t-Date.parse(e);if(!Number.isFinite(n)||n<5000)return"now";if(n<60000)return`${Math.floor(n/1000)}s`;if(n<3600000)return`${Math.floor(n/60000)}m`;return`${Math.floor(n/3600000)}h`}var yt=Le(()=>rw(vt.value)),ep=Le(()=>iw(vt.value)),cw=Le(()=>{let e=new Set;return[...vt.value].filter((t)=>t.label!==_c).sort((t,n)=>Number(n.attached)-Number(t.attached)).map((t)=>({value:t.sessionId==="browser"?t.label:t.sessionId,label:t.label,attached:t.attached,steerable:t.attached||t.steerable===!0,pendingSteers:t.pendingSteers??0,polling:t.lastClaimAt!==void 0&&Date.now()-Date.parse(t.lastClaimAt)<300000})).filter((t)=>e.has(t.value)?!1:(e.add(t.value),!0))}),lw=Le(()=>vt.value.filter((e)=>e.attached)),Br=Le(()=>vt.value.find((e)=>e.attached)??null);function s1(e){let t=new Set;for(let n of e)if(n.nodeId&&n.kind!=="create")t.add(n.nodeId);return t}var uw=Le(()=>s1(Ge.value.values()));function Cc(e,t){if(e.cursor)return{x:e.cursor.x,y:e.cursor.y};if(!e.focusNodeId)return null;let n=t(e.focusNodeId);if(!n)return null;return{x:n.position.x+Math.max(24,n.size.width-28),y:n.position.y+16}}function tp(e){if(!e)return;if(Array.isArray(e.presences))vt.value=e.presences;if(e.budget&&Number.isFinite(e.budget.used)&&Number.isFinite(e.budget.total))Yd.value={used:e.budget.used,total:e.budget.total};if(Array.isArray(e.activity))ao.value=e.activity}function dw(){let e=R(new Map),t=K.value.scale,n=F.value,o=1/Math.max(0.05,t),r=vt.value.map((s)=>{let a=Cc(s,(l)=>n.get(l));if(a)e.current.set(s.sessionId,a);let c=a??e.current.get(s.sessionId)??null;return c?{presence:s,position:c}:null}).filter((s)=>s!==null);if(r.length===0)return null;return i("div",{class:"agent-presence-layer","aria-hidden":"true",children:r.map(({presence:s,position:a})=>i("div",{class:`agent-cursor phase-${s.phase}${s.cursor?" has-explicit-cursor":""}${s.attached?"":" is-external"}${s.parentAgentId?" is-worker":""}`,"data-session-id":s.sessionId,style:{transform:`translate(${a.x}px, ${a.y}px)`,"--identity-color":`hsl(${so(s.sessionId)} 65% 62%)`},children:i("div",{class:"agent-cursor-inner",style:{transform:`scale(${o})`},children:[i("svg",{class:"agent-cursor-glyph",width:"16",height:"18",viewBox:"0 0 16 18","aria-hidden":"true",children:i("path",{d:"M1.5 1.5L14.5 9.2 8.3 10.6 5.2 16.5z",fill:"currentColor",stroke:"var(--c-bg)","stroke-width":"1.2"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"agent-cursor-chip",children:[i("span",{class:"agent-cursor-dot"},void 0,!1,void 0,this),i("span",{class:"agent-cursor-label",children:io(s)},void 0,!1,void 0,this),i("span",{class:"agent-cursor-who",children:s.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},s.sessionId,!1,void 0,this))},void 0,!1,void 0,this)}function Nn(e=1000){let[t,n]=I(()=>Date.now());return B(()=>{if(e<=0)return;n(Date.now());let o=window.setInterval(()=>n(Date.now()),e);return()=>window.clearInterval(o)},[e]),t}function pw(){let e=Nn(Ei.value.length>0?5000:0),t=Ei.value.filter((o)=>o.cursor!==null&&(!o.lastSeenAt||e-Date.parse(o.lastSeenAt)<Zb+5000));if(t.length===0)return null;let n=1/Math.max(0.05,K.value.scale);return i("div",{class:"human-presence-layer","aria-hidden":"true",children:t.map((o)=>i("div",{class:`human-cursor${o.grabbingNodeId?" is-grabbing":""}`,"data-client-id":o.clientId,style:{transform:`translate(${o.cursor.x}px, ${o.cursor.y}px)`},children:i("div",{class:"human-cursor-inner",style:{transform:`scale(${n})`},children:[i("svg",{class:"human-cursor-glyph",width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",children:i("path",{d:"M3 2 L13 8 L8.5 9.5 L6.5 14 Z",fill:"currentColor",stroke:"var(--c-bg)","stroke-width":"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"human-cursor-tag",children:o.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},o.clientId,!1,void 0,this))},void 0,!1,void 0,this)}function Tc(e,t){let{POSITIVE_INFINITY:n,POSITIVE_INFINITY:o,NEGATIVE_INFINITY:r,NEGATIVE_INFINITY:s}=Number,a=0;for(let c of e)a+=1,n=Math.min(n,c.position.x),o=Math.min(o,c.position.y),r=Math.max(r,c.position.x+c.size.width),s=Math.max(s,c.position.y+c.size.height);if(a===0)return null;return{x:n-t,y:o-t,width:r-n+t*2,height:s-o+t*2}}function op(){let e=nn.value;return e&&typeof e==="object"?e:{}}var mw=Le(()=>op().workItems??[]),rp=Le(()=>op().approvalGates??[]),jo=Le(()=>rp.value.filter((e)=>e.status==="pending")),co=Le(()=>{let e=op().policy?.scope;return e&&Array.isArray(e.nodeIds)&&e.nodeIds.length>0?{nodeIds:e.nodeIds,padding:typeof e.padding==="number"?e.padding:40}:null});async function fw(e){return(await Mt("setScopeFence","/api/canvas/ax/policy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:e&&e.length>0?{nodeIds:e}:null,source:"browser"})})).ok}var hw=Le(()=>rp.value.filter((e)=>e.status==="held")),gw=Le(()=>rp.value.filter((e)=>e.status==="approved"||e.status==="rejected")),vw=q({events:[],evidence:[],steering:[]}),Zo=q("all");function ip(e){if(e==="update")return"update";if(e==="steer"||e==="steering"||e==="yield")return"steer";if(e==="assistant-message")return"assistant";if(e==="evidence")return"evidence";return"event"}var a1=new Set(["api","mcp","sdk","cli"]);function np(e,t){if(e?.trim())return e.trim();let n=t?.trim();if(n&&!a1.has(n))return n;return null}var c1=/^(node|edge|group|annotation|jsonrender|graph|render)\.|^arrange$|^canvas\.clear$|^snapshot\.restore$/,yw=q(null),Zi=q(new Set),l1={prompt:"Prompt","assistant-message":"Assistant","tool-start":"Tool run","tool-result":"Tool result",failure:"Failure",approval:"Approval",steering:"Steering",command:"Command",note:"Note",policy:"Policy",yield:"Yield"};function u1(e,t=40,n=[],o=null,r="all"){let s=n.find((l)=>c1.test(l.op)),a=[...n.map((l)=>({id:`update-${l.id}`,kind:"update",label:"Update",body:l.summary,createdAt:l.at,who:l.sessionId??null,...o?.actor==="agent"&&s?.id===l.id?{undoable:!0}:{}})),...e.events.map((l)=>({id:`event-${l.id}`,kind:l.kind,label:l1[l.kind]??l.kind,body:l.detail?`${l.summary} — ${l.detail}`:l.summary,createdAt:l.createdAt,who:np(l.agentId,l.source)})),...e.evidence.map((l)=>({id:`evidence-${l.id}`,kind:"evidence",label:"Evidence",body:l.body?`${l.title} — ${l.body}`:l.title,createdAt:l.createdAt,who:np(l.agentId,l.source)})),...e.steering.map((l)=>{let u=l.agentId??(l.source&&l.source!=="browser"?l.source:null),p=l.target?`→ ${l.target} · `:u?"→ all · ":"",d=l.target&&l.delivered===!1?` — waiting for ${l.target} to pick it up`:"";return{id:`steer-${l.id}`,kind:"steer",label:"Steer",body:`${u?`${u} `:""}${p}${l.message}${d}`,createdAt:l.createdAt,who:np(l.agentId,l.source)}})],c=r==="all"?a:a.filter((l)=>ip(l.kind)===r);return c.sort((l,u)=>l.createdAt<u.createdAt?1:l.createdAt>u.createdAt?-1:0),c.slice(0,t)}var bw=Le(()=>u1(vw.value,40,ao.value,yw.value,Zo.value));async function lo(){let[e,t]=await Promise.all([Y("refreshTimeline","/api/canvas/ax/timeline?limit=40",null),Y("refreshHistoryTop","/api/canvas/history",null)]);if(t)yw.value=t.top??null;if(!e)return;vw.value={events:Array.isArray(e.events)?e.events:[],evidence:Array.isArray(e.evidence)?e.evidence:[],steering:Array.isArray(e.steering)?e.steering:[]}}async function sp(e){if(!(await Mt("undoAgentEdit","/api/canvas/undo",{method:"POST"})).ok)return!1;return Zi.value=new Set([...Zi.value,e.id]),await Qt("undoAgentEditSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:`Undid your edit: ${e.body} — it was reverted on the board.`,source:"browser"})}),lo(),!0}async function ap(e=!1){let t=await Mt(e?"redo":"undo",e?"/api/canvas/redo":"/api/canvas/undo",{method:"POST"});if(t.ok)lo();return t.ok}async function xw(e,t){if(!(await Mt("resolveGate",`/api/canvas/ax/approval/${encodeURIComponent(e.id)}/resolve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({decision:t,source:"browser"})})).ok)return!1;if(t==="rejected")await Qt("rejectGateSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:`Rejected gate "${e.title}" — do not proceed with it.`,source:"browser"})});return!0}async function ww(e){return(await Mt("reopenGate",`/api/canvas/ax/approval/${encodeURIComponent(e.id)}/reopen`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser"})})).ok}async function _w(e,t){return(await Mt("sendSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:e,source:"browser",...t?{target:t}:{}})})).ok}async function uo(){return(await Mt("startSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser",label:_c,attached:!0,phase:"idle"})})).ok}async function Ic(e){return(await Mt("endSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:e.source,agentId:e.agentId,attached:!1,endedBy:"human"})})).ok}var Ec=q(null);function Sw(e){let{counts:t,snapshot:n}=e;if(typeof e.label!=="string"||typeof e.endedAt!=="string")return;if(e.unchanged===!0||typeof e.parentAgentId==="string")return;Ec.value={label:e.label,endedAt:e.endedAt,endedBy:e.endedBy==="human"||e.endedBy==="agent"||e.endedBy==="idle-timeout"?e.endedBy:void 0,unchanged:e.unchanged===!0,counts:{items:Number(t?.items??0)||0,done:Number(t?.done??0)||0,cancelled:Number(t?.cancelled??0)||0,rejected:Number(t?.rejected??0)||0,held:Number(t?.held??0)||0},snapshot:n&&typeof n.id==="string"?{id:n.id,name:String(n.name??"")}:null}}function Ac(){Ec.value=null}function kw(){if(!yt.value)return null;let e=co.value;if(!e)return null;let t=F.value,n=e.nodeIds.map((s)=>t.get(s)).filter((s)=>s!==void 0),o=Tc(n,e.padding);if(!o)return null;let r=1/Math.max(0.05,K.value.scale);return i("div",{class:"scope-fence","data-fenced-count":n.length,style:{transform:`translate(${o.x}px, ${o.y}px)`,width:`${o.width}px`,height:`${o.height}px`},"aria-hidden":"true",children:[i("span",{class:"scope-fence-pill scope-fence-pill-top",style:{transform:`scale(${r})`},children:["Agent scope · ",n.length," node",n.length===1?"":"s"]},void 0,!0,void 0,this),i("span",{class:"scope-fence-pill scope-fence-pill-bottom",style:{transform:`scale(${r})`},children:"writes outside are blocked · reads allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var zc={markdown:"var(--c-accent)","mcp-app":"var(--c-ok)",webpage:"var(--c-warn)","json-render":"var(--c-ok)",graph:"var(--c-purple)",board:"var(--c-accent)",prompt:"var(--c-accent)",response:"var(--c-ok)",status:"var(--c-warn)",context:"var(--c-muted)",ledger:"var(--c-dim)",trace:"var(--c-purple)",file:"var(--c-accent)",diff:"var(--c-ok)",mermaid:"var(--c-purple)",image:"var(--c-ok)",html:"var(--c-warn)",group:"var(--c-accent)"};function d1(e){let t=typeof e==="number"&&Number.isFinite(e)?Math.floor(e):1;return Math.max(1,Math.min(20,t))}function Pc(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Ui(e){return typeof e==="string"&&e.length>0}function Cw(e){let t=e.axStep;if(!Pc(t))return null;if(!Ui(t.flowId)||!Ui(t.workItemId))return null;if(typeof t.index!=="number"||typeof t.total!=="number")return null;return{flowId:t.flowId,index:t.index,total:t.total,workItemId:t.workItemId}}function Tw(e){let t=e.axFlow;if(!Pc(t)||!Ui(t.flowId)||!Array.isArray(t.steps))return null;let n=[];for(let r of t.steps){if(!Pc(r)||!Ui(r.nodeId)||!Ui(r.workItemId))return null;if(typeof r.index!=="number")return null;n.push({index:r.index,nodeId:r.nodeId,workItemId:r.workItemId,title:typeof r.title==="string"?r.title:""})}if(n.length===0)return null;let o=Pc(t.loop)?t.loop:{};return{flowId:t.flowId,title:typeof t.title==="string"?t.title:"Flow",steps:n,loop:{running:o.running===!0,run:typeof o.run==="number"&&Number.isFinite(o.run)?Math.max(0,Math.floor(o.run)):0,maxRuns:d1(o.maxRuns)}}}var p1={position:"sticky",bottom:"calc(-1 * var(--ax-dock-bleed, 12px))",marginTop:"12px",marginLeft:"calc(-1 * var(--ax-dock-bleed, 12px))",marginRight:"calc(-1 * var(--ax-dock-bleed, 12px))",marginBottom:"calc(-1 * var(--ax-dock-bleed, 12px))",padding:"9px var(--ax-dock-pad, 12px) 10px",background:"var(--c-panel-overlay)",borderTop:"1px solid var(--c-line)",backdropFilter:"blur(6px)"},Ew={display:"flex",alignItems:"center",gap:"6px",flexWrap:"wrap"},Aw={fontSize:"10px",color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginRight:"auto"},zw={...Ro,background:"var(--c-accent-25)",color:"var(--c-text)"},m1=[{status:"in-progress",label:"Start",toast:"Step started"},{status:"done",label:"Done",toast:"Step done"},{status:"blocked",label:"Blocked",toast:"Step blocked"}];async function Iw(e,t,n){let o={...t,loop:n};ie(e.id,{axFlow:o}),await pt(e.id,{data:{axFlow:o}})}function Pw(e){return typeof e?.axWorkStatus==="string"?e.axWorkStatus:"todo"}function f1({node:e,flow:t}){let[n,o]=I(""),{running:r,run:s,maxRuns:a}=t.loop,c=async()=>{await Iw(e,t,{running:!0,run:s>=a?0:s,maxRuns:a});let u=t.steps.find((d)=>Pw(F.value.get(d.nodeId)?.data)!=="done"),p=u??t.steps[t.steps.length-1];await eo(e,"ax.work.update",{id:p.workItemId,status:u?"in-progress":"done"},"Loop running")},l=async()=>{let u=n.trim();if(!u)return;await eo(e,"ax.steer",{message:u},"Steering sent"),o("")};return i("div",{class:"ax-flow-controls",style:{...Ew,marginTop:"6px",rowGap:"4px"},children:[i("span",{class:"ax-flow-runs",style:Aw,children:r?`Loop running · run ${s+1}/${a}`:`Loop idle · ${s}/${a} runs`},void 0,!1,void 0,this),r?i("button",{type:"button",class:"ax-node-action",style:zw,title:"Stop the loop now. The stop is persisted on this node, so it survives a refresh and no further step is opened.",onClick:(u)=>{u.stopPropagation(),Iw(e,t,{...t.loop,running:!1})},children:"Stop"},void 0,!1,void 0,this):i("button",{type:"button",class:"ax-node-action",style:Ro,title:"Run this flow as a loop: each completed step opens the next one, and the last step starts the next run — until the run cap is reached or you press Stop.",onClick:(u)=>{u.stopPropagation(),c()},children:"Run loop"},void 0,!1,void 0,this),i("input",{class:"ax-flow-steer-input",value:n,placeholder:"Steer the agent…","aria-label":"Steer the agent",onInput:(u)=>o(u.target.value),onClick:(u)=>u.stopPropagation(),onKeyDown:(u)=>{if(u.key!=="Enter")return;u.stopPropagation(),l()},style:{flex:"1 1 120px",minWidth:"90px",fontSize:"10px",padding:"3px 6px",borderRadius:"4px",border:"1px solid var(--c-line)",background:"var(--c-panel-overlay)",color:"var(--c-text)"}},void 0,!1,void 0,this),i("button",{type:"button",class:"ax-node-action",style:Ro,title:"Send a steering message to the agent working this flow.",onClick:(u)=>{u.stopPropagation(),l()},children:"Steer"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Nc({node:e}){let t=Cw(e.data);if(!t)return null;let n=Tw(e.data),o=Pw(e.data);return i("div",{class:"ax-step-dock",style:p1,children:[i("div",{class:"ax-step-controls",style:Ew,children:[i("span",{class:"ax-step-position",style:Aw,children:["Step ",t.index,"/",t.total]},void 0,!0,void 0,this),m1.map((r)=>i("button",{type:"button",class:"ax-node-action","aria-pressed":o===r.status,style:o===r.status?zw:Ro,title:`Set this step's work item to "${r.status}".`,onClick:(s)=>{s.stopPropagation(),eo(e,"ax.work.update",{id:t.workItemId,status:r.status},r.toast)},children:r.label},r.status,!1,void 0,this))]},void 0,!0,void 0,this),n&&i(f1,{node:e,flow:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Hr=8,Uo=q(null),jr=[],Zr=[],$w=null;function Nw(e){let t=e?.data.parentGroup;return typeof t==="string"&&t.length>0?t:null}function Rw(e){if(!e||!Array.isArray(e.data.children))return[];return e.data.children.filter((t)=>typeof t==="string")}function h1(e,t){let n=new Map(t.map((c)=>[c.id,c])),o=new Set([e]),r=n.get(e);if(!r)return o;let s=Nw(r);while(s&&!o.has(s))o.add(s),s=Nw(n.get(s));if(r.type!=="group")return o;let a=[...Rw(r)];while(a.length>0){let c=a.pop();if(!c||o.has(c))continue;o.add(c);let l=n.get(c);if(l?.type==="group")a.push(...Rw(l))}return o}function Mw(e,t){jr=[],Zr=[],$w=e;let n=Array.from(t),o=h1(e,n);for(let r of n){if(o.has(r.id))continue;let s=r.position.x,a=r.position.x+r.size.width,c=r.position.x+r.size.width/2,l=r.position.y,u=r.position.y+r.size.height,p=r.position.y+r.size.height/2;jr.push({val:s,minY:l,maxY:u}),jr.push({val:a,minY:l,maxY:u}),jr.push({val:c,minY:l,maxY:u}),Zr.push({val:l,minX:s,maxX:a}),Zr.push({val:u,minX:s,maxX:a}),Zr.push({val:p,minX:s,maxX:a})}}function Ow(){jr=[],Zr=[],$w=null}function Lw(e,t,n,o){let r=[e,e+n/2,e+n],s=[t,t+o/2,t+o],a=[0,n/2,n],c=[0,o/2,o],l=null,u=Hr+1,p=null;for(let v=0;v<3;v++){let x=r[v];for(let g of jr){let y=Math.abs(x-g.val);if(y<u)u=y,l=g.val-a[v],p={axis:"x",pos:g.val,from:Math.min(g.minY,t),to:Math.max(g.maxY,t+o)}}}let d=null,f=Hr+1,m=null;for(let v=0;v<3;v++){let x=s[v];for(let g of Zr){let y=Math.abs(x-g.val);if(y<f)f=y,d=g.val-c[v],m={axis:"y",pos:g.val,from:Math.min(g.minX,e),to:Math.max(g.maxX,e+n)}}}let h=[];if(p&&u<=Hr)h.push(p);if(m&&f<=Hr)h.push(m);return{x:l!==null&&u<=Hr?l:e,y:d!==null&&f<=Hr?d:t,guides:h}}function Dw({nodeId:e,viewport:t,onMove:n,onDragEnd:o,onClick:r}){let s=R(!1),a=R({x:0,y:0}),c=R({x:0,y:0});return H((u,p,d)=>{u.stopPropagation(),u.preventDefault(),s.current=!0,document.documentElement.classList.add("is-node-dragging"),window.getSelection()?.removeAllRanges(),a.current={x:u.clientX,y:u.clientY},c.current={x:p,y:d};let f=null,m=null,h=!1,v=()=>{if(m=null,!s.current||!f)return;let y=f;f=null;let E=t.value.scale,L=(y.x-a.current.x)/E,P=(y.y-a.current.y)/E;n(e,c.current.x+L,c.current.y+P)},x=(y)=>{if(!s.current)return;if(!h&&Math.hypot(y.clientX-u.clientX,y.clientY-u.clientY)<4)return;if(h=!0,f={x:y.clientX,y:y.clientY},m!==null)return;m=window.requestAnimationFrame(v)},g=(y)=>{if(m!==null)window.cancelAnimationFrame(m),v();if(s.current=!1,document.documentElement.classList.remove("is-node-dragging"),document.removeEventListener("pointermove",x),document.removeEventListener("pointerup",g),document.removeEventListener("pointercancel",g),o(),!h&&y.type==="pointerup")r?.()};document.addEventListener("pointermove",x),document.addEventListener("pointerup",g),document.addEventListener("pointercancel",g)},[e,t,n,o,r])}var g1=200,v1=100;function Fw({nodeId:e,viewport:t,onResize:n,onResizeEnd:o}){let r=R(!1),s=R({x:0,y:0}),a=R({w:0,h:0});return H((l,u,p)=>{l.stopPropagation(),l.preventDefault(),r.current=!0,s.current={x:l.clientX,y:l.clientY},a.current={w:u,h:p},document.documentElement.classList.add("is-node-resizing");let d=null,f=null,m=()=>{if(f=null,!r.current||!d)return;let x=d;d=null;let g=t.value.scale,y=(x.x-s.current.x)/g,E=(x.y-s.current.y)/g;n(e,Math.max(g1,a.current.w+y),Math.max(v1,a.current.h+E))},h=(x)=>{if(!r.current)return;if(d={x:x.clientX,y:x.clientY},f!==null)return;f=window.requestAnimationFrame(m)},v=()=>{if(f!==null)window.cancelAnimationFrame(f),m();r.current=!1,document.documentElement.classList.remove("is-node-resizing"),document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",v),document.removeEventListener("pointercancel",v),o()};document.addEventListener("pointermove",h),document.addEventListener("pointerup",v),document.addEventListener("pointercancel",v)},[e,t,n,o])}var y1={ArrowLeft:{dx:-1,dy:0},ArrowRight:{dx:1,dy:0},ArrowUp:{dx:0,dy:-1},ArrowDown:{dx:0,dy:1}};function b1(e,t,n){let o=e.position.x+e.size.width/2,r=e.position.y+e.size.height/2,s=null,a=Number.POSITIVE_INFINITY;for(let c of n){if(c.id===e.id)continue;let l=c.position.x+c.size.width/2-o,u=c.position.y+c.size.height/2-r,p=l*t.dx+u*t.dy;if(p<=0)continue;let d=Math.abs(l*t.dy)+Math.abs(u*t.dx);if(d>p)continue;let f=p+d*2;if(f<a)a=f,s=c}return s}var x1=0.4,w1=0.55,_1=175;function S1(e,t,n=0){if(!Number.isFinite(e)||e>=1)return 1;let r=Math.min(2.2,1/Math.max(e,0.01));if(Number.isFinite(t)&&t>0)r=Math.min(r,t*x1/Cr);if(Number.isFinite(n)&&n>0)r=Math.min(r,n*w1/_1);return Math.max(1,r)}function Bw({node:e,children:t,onContextMenu:n}){let o=Ce.value===e.id,r=be.value.has(e.id),s=Ae.value.has(e.id),a=rr.value.has(e.id),c=!a&&ir.value.has(e.id),l=Us.value.has(e.id),u=!o&&Kv.value.has(e.id),p=Sn.value,d=p!==null&&p.has(e.id),f=p!==null&&!p.has(e.id),[m,h]=I(!1),v=R(null),x=H((D,ae,Fe)=>{let ve=Lw(ae,Fe,e.size.width,e.size.height),Xt=F.value.get(D);if(Xt?.position.x===ve.x&&Xt.position.y===ve.y){Uo.value=ve.guides.length>0?ve.guides:null;return}st(D,{position:{x:ve.x,y:ve.y}}),Uo.value=ve.guides.length>0?ve.guides:null,ny(D)},[e.size.width,e.size.height]),g=R(null),y=H(()=>{if(Ow(),Uo.value=null,ad(null),g.current)document.removeEventListener("keydown",g.current),g.current=null;at();let D=dn.value;if(ty(),!D||D.nodeId!==e.id)return;if(D.mode==="add")yu(D.groupId,[e.id]);else{let ae=F.value.get(D.groupId),Fe=Array.isArray(ae?.data.children)?ae.data.children.filter((ve)=>typeof ve==="string"&&ve!==e.id):[];ta(D.groupId,Fe)}},[e.id]),E=Dw({nodeId:e.id,viewport:K,onMove:x,onDragEnd:y,onClick:()=>{be.value=new Set([e.id])}}),L=H((D,ae,Fe)=>{let ve=F.value.get(D);if(ve?.size.width===ae&&ve.size.height===Fe)return;st(D,{size:{width:ae,height:Fe}})},[]),P=H(()=>{ie(e.id,{userResized:!0}),pt(e.id,{data:{userResized:!0}}),at()},[e.id]),b=Fw({nodeId:e.id,viewport:K,onResize:L,onResizeEnd:P}),T=H((D)=>{D.stopPropagation(),D.preventDefault(),je.value={fromId:e.id,fromX:e.position.x+e.size.width/2,fromY:e.position.y+e.size.height/2,cursorX:e.position.x+e.size.width/2,cursorY:e.position.y+e.size.height/2,targetId:null}},[e.id,e.position.x,e.position.y,e.size.width,e.size.height]),w=H((D)=>{if(D.button!==0)return;if(m)return;if(D.target instanceof Element&&D.target.closest("button, input")){D.stopPropagation();return}if(Et.value==="connect"){T(D);return}if(D.shiftKey){D.stopPropagation(),wu(e.id);return}if(Cn(e.id),ad(e.id),Yb(e.id,typeof e.data.title==="string"&&e.data.title?e.data.title:e.type),Mw(e.id,F.value.values()),e.type!=="group"){let ae=(Fe)=>{if(Fe.key==="Escape")ey()};g.current=ae,document.addEventListener("keydown",ae)}E(D,e.position.x,e.position.y)},[e.id,e.type,e.data.title,e.position.x,e.position.y,E,m,T]),_=H((D)=>{if(D.button!==0)return;if(D.stopPropagation(),Et.value==="connect"){T(D);return}if(D.shiftKey){wu(e.id);return}Cn(e.id)},[e.id,T]),z=H((D)=>{if((D.target instanceof Element?D.target:null)?.closest('button, input, textarea, select, a, [contenteditable="true"]'))return;if(n)n(D,e.id)},[n,e.id]),U=H((D)=>{let ae=D.target;if(ae&&ae!==D.currentTarget&&ae.closest('input, textarea, [contenteditable="true"]'))return;let Fe=y1[D.key];if(Fe){D.preventDefault();let ve=b1(e,Fe,F.value.values());if(!ve)return;Cn(ve.id),requestAnimationFrame(()=>{document.querySelector(`.canvas-node[data-node-id="${CSS.escape(ve.id)}"]`)?.focus()})}else if(D.key==="Enter"&&D.target===D.currentTarget&&ui.has(e.type))D.preventDefault(),Ut(e.id)},[e]),N=e.data.title||(e.type==="file"?(e.data.path||e.data.content||"").split(/[\\/]/).pop()??"":"")||ut[e.type],Z=H((D)=>{let ae=D.trim();if(ae&&ae!==N)ie(e.id,{title:ae}),pt(e.id,{title:ae});h(!1)},[e.id,N]),j=R(null),S=R(!1),V=R(null);B(()=>{if(S.current||!cd(e))return;let D=j.current;if(!D)return;let ae=new ResizeObserver(()=>{if(S.current){ae.disconnect();return}let Fe=D.scrollHeight,ve=ox(e,Fe);if(ve===null)return;if(Math.abs(ve-e.size.height)>8){if(ua(e.id,{width:e.size.width,height:ve}),V.current!==null)window.clearTimeout(V.current);V.current=window.setTimeout(()=>{at({recordHistory:!1}),V.current=null},0)}S.current=!0,ae.disconnect()});return ae.observe(D),()=>{if(ae.disconnect(),V.current!==null)window.clearTimeout(V.current),V.current=null}},[e.id,e.type,e.data.mode,e.data.strictSize,e.collapsed,e.size.width,e.size.height]);let ge=e.pinned,Ze=e.type==="trace",se=Ze&&e.data.status==="running",de=e.type==="group",me=e.data.strictSize===!0,go=Math.max(K.value.scale,0.01),Gt=S1(go,e.collapsed?0:e.size.height,e.size.width),an=de&&e.data.color?e.data.color:void 0,M={left:`${e.position.x}px`,top:`${e.position.y}px`,width:`${e.size.width}px`,height:e.collapsed?"auto":`${e.size.height}px`,zIndex:e.zIndex,"--node-chrome-scale":Gt.toFixed(3),...an?{"--group-color":an}:{}},J=yt.value&&uw.value.has(e.id),fe=["canvas-node",o?"active":"",u?"neighbor":"",d?"search-match":"",f?"search-dimmed":"",r?"selected":"",s?"context-pinned":"",a?"attention-focus-primary":"",c?"attention-focus-secondary":"",l?"attention-pulse":"",ge?"pinned":"",Ze?"trace-node":"",se?"trace-running":"",de?"group-node":"",me?"strict-size":"",J?"agent-mutating":""].filter(Boolean).join(" "),ee=de?(Array.isArray(e.data.children)?e.data.children:[]).filter((D)=>typeof D==="string"&&F.value.has(D)):[],[Q,te]=I(!1),ne=dn.value,W=de&&ne?.groupId===e.id&&ne.mode==="add",ue=de&&ne?.groupId===e.id&&ne.mode==="remove",bt=je.value?.targetId===e.id,Nt=de?[...new Set(ee.map((D)=>F.value.get(D)?.type).filter((D)=>!!D))].slice(0,4):[];if(de&&e.collapsed)return i("div",{class:`${fe} group-chip`,"data-node-type":e.type,style:{...M,width:"auto",height:"auto"},onPointerDown:_,onDblClick:z,title:"Expand group","data-testid":"group-chip",children:i("div",{class:"node-titlebar group-chip-inner",onPointerDown:w,children:[i("button",{type:"button",class:"group-chip-expand","aria-label":`Expand group ${N}`,onClick:(D)=>{D.stopPropagation(),mr(e.id)},children:i(vr,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{class:"group-chip-text",children:[i("div",{class:"group-chip-name",children:N},void 0,!1,void 0,this),i("div",{class:"group-chip-meta",children:[Nt.map((D)=>i("span",{class:"group-kind-dot",style:{background:zc[D]},"aria-hidden":"true"},D,!1,void 0,this)),i("span",{class:"group-chip-count",children:[ee.length," node",ee.length===1?"":"s"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return i("div",{class:`${fe}${W?" is-drop-target":""}${ue?" is-drop-source":""}${bt?" is-edge-target":""}${de&&Q?" group-menu-open":""}`,"data-node-type":e.type,"data-node-id":e.id,style:M,tabIndex:o?0:-1,onKeyDown:U,onPointerDown:_,onMouseDown:(D)=>{if(D.shiftKey)D.preventDefault()},onDblClick:z,children:[de&&i("div",{class:"node-titlebar group-edge-row",onPointerDown:w,children:[i("span",{class:"group-name-pill",children:[m?i("input",{ref:v,class:"node-title-input group-title-input",value:N,onBlur:(D)=>Z(D.target.value),onKeyDown:(D)=>{if(D.key==="Enter")Z(D.target.value);if(D.key==="Escape")h(!1)},onClick:(D)=>D.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"group-name",title:N,children:N},void 0,!1,void 0,this),i("span",{class:"group-count",children:ee.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"group-edge-spacer"},void 0,!1,void 0,this),i("span",{class:"group-actions",role:"toolbar","aria-label":`${N} actions`,children:[i("button",{type:"button",class:"group-action",title:"Auto-arrange children","aria-label":"Auto-arrange children",disabled:ee.length===0,onClick:(D)=>{D.stopPropagation(),yu(e.id,ee,"grid")},children:i("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","aria-hidden":"true",children:[i("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"group-action",title:"Collapse group","aria-label":"Collapse group",onClick:(D)=>{D.stopPropagation(),mr(e.id)},children:i("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M3 10 L8 5 L13 10"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"group-action",title:"Rename · Ungroup · Pin all to context","aria-label":"Group menu","aria-expanded":Q,onClick:(D)=>{D.stopPropagation(),te((ae)=>!ae)},children:i(Sy,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),Q&&i("div",{class:"group-menu",role:"menu",onPointerDown:(D)=>D.stopPropagation(),children:[i("button",{type:"button",role:"menuitem",onClick:(D)=>{D.stopPropagation(),te(!1),h(!0),requestAnimationFrame(()=>v.current?.focus())},children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",onClick:(D)=>{D.stopPropagation(),te(!1),Jn(e.id),lr(e.id)},children:"Ungroup"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",disabled:ee.length===0,onClick:(D)=>{D.stopPropagation(),te(!1),sa(ee)},children:"Pin all to context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!de&&i("div",{class:"node-titlebar",onPointerDown:w,children:[i("span",{class:"node-type-icon","aria-hidden":"true",children:(()=>{let D=rn(e.type);return i(D,{size:Math.round(14*Gt)},void 0,!1,void 0,this)})()},void 0,!1,void 0,this),typeof e.data.axWorkStatus==="string"&&i("span",{class:`node-ax-status node-ax-status-${e.data.axWorkStatus}`,children:e.data.axWorkStatus},void 0,!1,void 0,this),m?i("input",{ref:v,class:"node-title-input",value:N,onBlur:(D)=>Z(D.target.value),onKeyDown:(D)=>{if(D.key==="Enter")Z(D.target.value);if(D.key==="Escape")h(!1)},onClick:(D)=>D.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"node-title",title:N,children:N},void 0,!1,void 0,this),i("div",{class:"node-controls",children:[ge&&i("span",{class:"pin-indicator",title:"Pinned",children:"⊙"},void 0,!1,void 0,this),i("button",{type:"button",class:`ctx-pin-btn${s?" ctx-pin-active":""}`,onClick:(D)=>{D.stopPropagation(),Xn(e.id)},title:s?"Remove from context":"Add to context",children:i(Ty,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),Fa(e)&&i("button",{type:"button",onClick:(D)=>{D.stopPropagation(),Ba(e)},title:"Open as site",children:i(mn,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),ui.has(e.type)&&i("button",{type:"button",onClick:(D)=>{D.stopPropagation(),Ut(e.id)},title:"Expand (focus mode)",children:i(ky,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",onClick:(D)=>{D.stopPropagation(),mr(e.id)},title:e.collapsed?"Expand":"Collapse",children:e.collapsed?i(vr,{size:14},void 0,!1,void 0,this):i(ga,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",onClick:(D)=>{D.stopPropagation(),Vn(e.id)},title:"Close",children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!e.collapsed&&i("div",{ref:j,class:"node-body",children:[t,i(Nc,{node:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!e.collapsed&&i("div",{class:"node-resize-handle",onPointerDown:(D)=>b(D,e.size.width,e.size.height)},void 0,!1,void 0,this),r&&["tl","tr","bl","br"].map((D)=>i("span",{class:`node-selection-handle is-${D}`,"aria-hidden":"true"},D,!1,void 0,this)),Oo.value.has(e.id)&&i("span",{class:"node-yield-pill","data-testid":"yield-pill",children:[i("span",{class:"node-yield-dot","aria-hidden":"true"},void 0,!1,void 0,this),Oo.value.get(e.id)," took over — agent yielded"]},void 0,!0,void 0,this),!de&&["top","right","bottom","left"].map((D)=>i("div",{class:`node-port node-port-${D}`,onPointerDown:(ae)=>{ae.stopPropagation(),ae.preventDefault();let Fe=e.position.x+e.size.width/2,ve=e.position.y+e.size.height/2,Xt=e.size.width/2,Yi=e.size.height/2,Jt,Mn;switch(D){case"top":Jt=Fe,Mn=ve-Yi;break;case"bottom":Jt=Fe,Mn=ve+Yi;break;case"left":Jt=Fe-Xt,Mn=ve;break;case"right":Jt=Fe+Xt,Mn=ve;break}je.value={fromId:e.id,fromX:Jt,fromY:Mn,cursorX:Jt,cursorY:Mn}}},D,!1,void 0,this))]},void 0,!0,void 0,this)}function Rc({node:e}){let t=typeof e.data.boardId==="string"?e.data.boardId:"",n=At.value.find((o)=>o.id===t);return i("div",{class:"board-node",children:[i("div",{class:"board-node-content",children:[i("div",{class:"board-node-label",children:"Linked board"},void 0,!1,void 0,this),i("strong",{class:"board-node-title",children:n?.name??"Missing board"},void 0,!1,void 0,this),i("div",{class:"board-node-meta",children:n?`${n.nodeCount} nodes`:t||"No target id"},void 0,!1,void 0,this),n?.summary&&i("p",{class:"board-node-summary",children:n.summary},void 0,!1,void 0,this),!!n?.pinnedTitles?.length&&i("p",{class:"board-node-meta",children:["Pinned: ",n.pinnedTitles.map((o)=>o.title).join(", ")]},void 0,!0,void 0,this),!!n?.backlinks?.length&&i("p",{class:"board-node-meta",children:["Linked from: ",[...new Set(n.backlinks.map((o)=>o.title))].join(", ")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("button",{class:"board-node-open",type:"button",disabled:!n,onClick:()=>n&&void zt(n.id),children:[n?"Open board":"Target unavailable",n&&i(mn,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var k1={relation:"var(--c-muted)","depends-on":"var(--c-warn)",flow:"var(--c-accent)",references:"var(--c-muted)"},C1=new Set(["depends-on","flow"]);function T1(e){if(!Number.isFinite(e)||e<=0)return 1;return e<1?1/e:1}function I1(e,t){let n=`${8*t} ${4*t}`;if(e.style==="dashed")return n;if(e.style==="dotted")return`${3*t} ${3*t}`;if(e.type==="references"&&!e.style)return n;return}function $c(e,t){let n=e.position.x+e.size.width/2,o=e.position.y+e.size.height/2,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2,a=r-n,c=s-o,l=e.size.width/2,u=e.size.height/2,p=Math.abs(c/(a||0.001)),d=u/(l||0.001);if(p>d){let m=c>0?1:-1;return{x:n+u/p*(a>0?1:-1),y:o+u*m,side:m>0?"bottom":"top"}}let f=a>0?1:-1;return{x:n+l*f,y:o+p*l*(c>0?1:-1),side:f>0?"right":"left"}}function Mc(e,t){switch(e.side){case"top":return{x:e.x,y:e.y-t};case"bottom":return{x:e.x,y:e.y+t};case"left":return{x:e.x-t,y:e.y};case"right":return{x:e.x+t,y:e.y}}}function E1(e,t,n,o,r,s,a,c){return{x:0.125*e+0.375*n+0.375*r+0.125*a,y:0.125*t+0.375*o+0.375*s+0.125*c}}function A1({edge:e,fromNode:t,toNode:n,focused:o,dimmed:r,selected:s,scale:a,onContextMenu:c}){let l=$c(t,n),u=$c(n,t),p=u.x-l.x,d=u.y-l.y,f=Math.sqrt(p*p+d*d),m=Math.min(Math.max(f*0.35,32),160),h=Mc(l,m),v=Mc(u,m),x=`M ${l.x} ${l.y} C ${h.x} ${h.y}, ${v.x} ${v.y}, ${u.x} ${u.y}`,g=k1[e.type],y=C1.has(e.type),E=I1(e,a),L=Math.min(a,2.2),P=e.label&&a<=3.4?E1(l.x,l.y,h.x,h.y,v.x,v.y,u.x,u.y):null,b=`edge-path-${e.id}`;return i("g",{children:[i("path",{d:x,fill:"none",stroke:"transparent","stroke-width":12*a,style:{cursor:"pointer",pointerEvents:"stroke"},onClick:(T)=>{T.stopPropagation(),pn.value=e.id},onDblClick:c?(T)=>c(T,e.id):void 0},void 0,!1,void 0,this),(o||s)&&i("path",{d:x,fill:"none",stroke:g,"stroke-width":6*a,"stroke-dasharray":E,opacity:s?0.3:0.15,style:{filter:"blur(3px)"}},void 0,!1,void 0,this),i("path",{id:b,d:x,class:s?"edge-selected":void 0,fill:"none",stroke:g,"stroke-width":(s?3:o?2.5:1.5)*a,"stroke-dasharray":E,"marker-end":y?"url(#edge-arrow)":void 0,opacity:s?1:r?0.2:o?1:0.85,style:{transition:"opacity 0.2s, stroke-width 0.2s"}},void 0,!1,void 0,this),e.animated&&i("circle",{r:3*a,fill:g,opacity:"0.9",children:i("animateMotion",{dur:"2s",repeatCount:"indefinite",children:i("mpath",{href:`#${b}`},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),P&&e.label&&i("g",{transform:`translate(${P.x}, ${P.y})`,children:[i("rect",{class:"edge-label-bg",x:-(e.label.length*3.5+8)*L,y:-10*L,width:(e.label.length*7+16)*L,height:20*L,rx:4*L},void 0,!1,void 0,this),i("text",{class:"edge-label","text-anchor":"middle","dominant-baseline":"central",fill:"var(--c-text)",children:e.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Hw({nodes:e,edges:t,onEdgeContextMenu:n}){let o=e.value,r=Array.from(t.value.values()),s=Ce.value,a=s!==null,c=Sn.value,l=c!==null,u=T1(K.value.scale);if(r.length===0&&!je.value)return null;let p=96,d=Array.from(o.values());if(d.length===0)return null;let f=Math.min(...d.map((y)=>y.position.x))-p,m=Math.min(...d.map((y)=>y.position.y))-p,h=Math.max(...d.map((y)=>y.position.x+y.size.width))+p,v=Math.max(...d.map((y)=>y.position.y+y.size.height))+p,x=Math.max(1,h-f),g=Math.max(1,v-m);return i("svg",{"aria-label":"Canvas connections",role:"img",viewBox:`${f} ${m} ${x} ${g}`,width:x,height:g,style:{position:"absolute",top:`${m}px`,left:`${f}px`,pointerEvents:"none",overflow:"visible","--edge-chrome-scale":u.toFixed(3),"--edge-label-scale":Math.min(u,2.2).toFixed(3)},children:[i("title",{children:"Canvas connections"},void 0,!1,void 0,this),i("defs",{children:i("marker",{id:"edge-arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:8*Math.min(u,2.2),markerHeight:8*Math.min(u,2.2),orient:"auto-start-reverse",children:i("path",{d:"M 0 1 L 10 5 L 0 9 z",fill:"currentColor",opacity:"0.75"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r.map((y)=>{let E=ia(y.from),L=ia(y.to);if(!E||!L||E.id===L.id)return null;let P=a&&(y.from===s||y.to===s),b=l&&!(c.has(y.from)||c.has(y.to));return i(A1,{edge:y,fromNode:E,toNode:L,focused:P,dimmed:a&&!P||b,selected:pn.value===y.id,scale:u,onContextMenu:n},y.id,!1,void 0,this)}),je.value&&(()=>{let y=je.value,E=ia(y.fromId),L={position:{x:y.cursorX,y:y.cursorY},size:{width:1,height:1}},P;if(E){let b=$c(E,L),T=$c(L,E),w=T.x-b.x,_=T.y-b.y,z=Math.sqrt(w*w+_*_),U=Math.min(Math.max(z*0.35,32),160),N=Mc(b,U),Z=Mc(T,U);P=`M ${b.x} ${b.y} C ${N.x} ${N.y}, ${Z.x} ${Z.y}, ${T.x} ${T.y}`}else{let b=y.cursorX-y.fromX,T=y.cursorY-y.fromY,w=Math.sqrt(b*b+T*T),_=Math.min(w*0.25,80),z=b/(w||1),U=T/(w||1);P=`M ${y.fromX} ${y.fromY} C ${y.fromX+z*_} ${y.fromY+U*_}, ${y.cursorX-z*_} ${y.cursorY-U*_}, ${y.cursorX} ${y.cursorY}`}return i("g",{children:[i("path",{d:P,fill:"none",stroke:"var(--c-accent)","stroke-width":6*u,opacity:"0.1",style:{filter:"blur(3px)"}},void 0,!1,void 0,this),i("path",{d:P,fill:"none",stroke:"var(--c-accent)","stroke-width":2*u,"stroke-dasharray":`${6*u} ${4*u}`,opacity:"0.8"},void 0,!1,void 0,this),i("circle",{cx:y.cursorX,cy:y.cursorY,r:5*u,fill:"var(--c-accent)",opacity:"0.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})()]},void 0,!0,void 0,this)}function z1(e){let[t,...n]=e;if(!t)return"";return n.reduce((o,r)=>`${o} L ${r.x} ${r.y}`,`M ${t.x} ${t.y}`)}function cp({annotations:e}){if(e.length===0)return null;return i("svg",{class:"annotation-layer","aria-hidden":"true",children:e.map((t)=>{let n=t.color==="currentColor"?"var(--c-annotation)":t.color;if(t.type==="text"){let o=t.points[0];if(!o||!t.text)return null;return i("text",{x:o.x,y:o.y,fill:n,"font-size":t.width,"font-family":"var(--font)","font-weight":"700",opacity:"0.95",children:t.text},t.id,!1,void 0,this)}return i("path",{d:z1(t.points),fill:"none",stroke:n,"stroke-width":t.width,"stroke-linecap":"round","stroke-linejoin":"round",opacity:"0.9"},t.id,!1,void 0,this)})},void 0,!1,void 0,this)}function P1(e){switch(e.type){case"markdown":return i(Ma,{node:e},void 0,!1,void 0,this);case"mcp-app":return i(ro,{node:e},void 0,!1,void 0,this);case"webpage":return i(yc,{node:e},void 0,!1,void 0,this);case"json-render":return i(ro,{node:e},void 0,!1,void 0,this);case"graph":return i(ro,{node:e},void 0,!1,void 0,this);case"board":return i(Rc,{node:e},void 0,!1,void 0,this);case"prompt":return i(bc,{node:e},void 0,!1,void 0,this);case"response":return i(xc,{node:e},void 0,!1,void 0,this);case"status":return i(gc,{node:e},void 0,!1,void 0,this);case"context":return i(wa,{node:e},void 0,!1,void 0,this);case"ledger":return i(Aa,{node:e},void 0,!1,void 0,this);case"trace":return i(wc,{node:e},void 0,!1,void 0,this);case"file":return i(Ea,{node:e},void 0,!1,void 0,this);case"diff":return i(_a,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Ja,{node:e},void 0,!1,void 0,this);case"image":return i(vc,{node:e},void 0,!1,void 0,this);case"html":return i(Hi,{node:e},void 0,!1,void 0,this);case"group":return i(Zx,{node:e},void 0,!1,void 0,this);default:return i("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function N1(e,t,n){let o=n.x-t.x,r=n.y-t.y,s=o*o+r*r;if(s===0)return Math.hypot(e.x-t.x,e.y-t.y);let a=Math.max(0,Math.min(1,((e.x-t.x)*o+(e.y-t.y)*r)/s));return Math.hypot(e.x-(t.x+a*o),e.y-(t.y+a*r))}function R1(e,t,n){for(let o=e.length-1;o>=0;o--){let r=e[o];if(!r)continue;let s=n+r.width;if(t.x<r.bounds.x-s||t.x>r.bounds.x+r.bounds.width+s||t.y<r.bounds.y-s||t.y>r.bounds.y+r.bounds.height+s)continue;if(r.type==="text")return r;for(let a=1;a<r.points.length;a++){let c=r.points[a-1],l=r.points[a];if(c&&l&&N1(t,c,l)<=n+r.width/2)return r}}return null}var lp="currentColor",jw=4,Zw=24,$1=14,Uw={width:520,height:420};function M1(e){let t=e.trim();if(!t||/\s/.test(t))return null;let n=/^[a-z][a-z0-9+.-]*:/i.test(t)?t:`https://${t}`;try{let o=new URL(n);if(o.protocol!=="http:"&&o.protocol!=="https:")return null;return o.toString()}catch{return null}}function dp(e){let t=e.trim();if(!t)return[];let n=t.includes(`
|
|
329
|
-
`)?t.split(/\r?\n/):t.split(/\s+/),o=new Set,r=[];for(let s of n){let a=s.trim();if(!a||a.startsWith("#"))continue;let c=M1(a);if(!c||o.has(c))continue;o.add(c),r.push(c)}return r}function O1(e){let t=dp(e.getData("text/uri-list"));if(t.length>0)return t;return dp(e.getData("text/plain"))}function L1(e){if(!e)return!1;return e.types.includes("text/uri-list")||e.types.includes("text/plain")}function up(e){if(!(e instanceof HTMLElement))return!1;return Boolean(e.closest('input, textarea, select, [contenteditable="true"], [contenteditable=""]'))}function D1(e,t,n=new Set){let o=[],r=0;for(let s of e){if(n.has(s.id))continue;if(t&&s.id===t)continue;if(s.type==="group")o.splice(r++,0,s);else o.push(s)}return o}function qw({onNodeContextMenu:e,onEdgeContextMenu:t,onCanvasContextMenu:n,annotationMode:o=!1,annotationTool:r=null}){let s=K.value,a=R(!1),c=R(null),l=R(!1),u=R([]),[p,d]=I(null),[f,m]=I(null),[h,v]=I(null),x=R(null),[g,y]=I(!1),E=R(0),L=R(null),P=R(null);B(()=>{let M=null,J=Zt(()=>{K.value;let fe=P.current;if(!fe)return;if(fe.style.willChange="transform",M)clearTimeout(M);M=setTimeout(()=>{fe.style.willChange="auto"},180)});return()=>{if(M)clearTimeout(M);J()}},[]);let b=ma({viewport:K,disabled:o,onViewportChange:(M)=>{if(a.current||o)return;Tn(),uy(M)},onViewportCommit:(M)=>{if(a.current||o)return;Tn(),py(M)}}),T=H((M)=>{x.current=M,v(M)},[]),w=H(async(M,J,fe)=>{if(M.length===0)return;let{width:ee,height:Q}=Uw,te=24,ne=Math.ceil(Math.sqrt(M.length)),W=Math.ceil(M.length/ne),ue=ne*ee+Math.max(0,ne-1)*te,bt=W*Q+Math.max(0,W-1)*te;for(let Nt=0;Nt<M.length;Nt++){let D=Nt%ne,ae=Math.floor(Nt/ne),Fe=J-ue/2+D*(ee+te),ve=fe-bt/2+ae*(Q+te);await en({type:"webpage",content:M[Nt],x:Fe,y:ve,width:ee,height:Q})}},[]),_=H((M)=>{let J=b.current;if(!J)return;if(r==="eraser"){if((M.target instanceof Element?M.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;M.preventDefault(),M.stopPropagation();let W=J.getBoundingClientRect(),ue=K.value,bt={x:(M.clientX-W.left-ue.x)/ue.scale,y:(M.clientY-W.top-ue.y)/ue.scale},Nt=R1(Array.from(ur.value.values()),bt,$1/ue.scale);if(Nt)ly(Nt.id);return}if(r==="text"){if((M.target instanceof Element?M.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;M.preventDefault(),M.stopPropagation(),Ce.value=null,wt();let W=J.getBoundingClientRect(),ue=K.value;T({x:(M.clientX-W.left-ue.x)/ue.scale,y:(M.clientY-W.top-ue.y)/ue.scale,value:""});return}if(r==="pen"){if((M.target instanceof Element?M.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;M.preventDefault(),M.stopPropagation(),Ce.value=null,wt(),l.current=!0;let W=J.getBoundingClientRect(),ue=K.value,bt={x:(M.clientX-W.left-ue.x)/ue.scale,y:(M.clientY-W.top-ue.y)/ue.scale};u.current=[bt],m({id:"draft-annotation",type:"freehand",points:[bt],bounds:{x:0,y:0,width:0,height:0},color:lp,width:jw,createdAt:""}),J.setPointerCapture(M.pointerId);return}if(M.target!==J)return;if(pr()||M.button===1||M.button===2){if(!M.shiftKey&&!L.current)Ce.value=null,wt();return}M.preventDefault(),M.stopPropagation(),a.current=!0;let fe=J.getBoundingClientRect(),ee=M.clientX-fe.left,Q=M.clientY-fe.top,te={startX:ee,startY:Q,currentX:ee,currentY:Q};L.current=te,d(te),J.setPointerCapture(M.pointerId)},[r,b]);B(()=>Zt(()=>{let M=K.value,J=c.current,fe=b.current;if(!J||!fe)return;let ee=fe.getBoundingClientRect();Va({x:(J.x-ee.left-M.x)/M.scale,y:(J.y-ee.top-M.y)/M.scale})}),[]);let z=H((M)=>{{let ee=b.current;if(ee){c.current={x:M.clientX,y:M.clientY};let Q=ee.getBoundingClientRect(),te=K.value;Va({x:(M.clientX-Q.left-te.x)/te.scale,y:(M.clientY-Q.top-te.y)/te.scale})}}if(l.current){let ee=b.current;if(!ee)return;let Q=ee.getBoundingClientRect(),te=K.value,ne={x:(M.clientX-Q.left-te.x)/te.scale,y:(M.clientY-Q.top-te.y)/te.scale},W=u.current.at(-1);if(W&&Math.hypot(ne.x-W.x,ne.y-W.y)<2)return;u.current=[...u.current,ne],m((ue)=>ue?{...ue,points:u.current}:null);return}if(!a.current||!L.current)return;let J=b.current?.getBoundingClientRect();if(!J)return;let fe={...L.current,currentX:M.clientX-J.left,currentY:M.clientY-J.top};L.current=fe,d(fe)},[b]),U=H((M)=>{if(l.current){l.current=!1;let ne=u.current;if(u.current=[],m(null),ne.length>=2)Cu({points:ne,color:lp,width:jw});let W=b.current;if(W?.hasPointerCapture(M.pointerId))W.releasePointerCapture(M.pointerId);return}let J=L.current;if(!a.current||!J)return;a.current=!1,L.current=null;let fe=Math.min(J.startX,J.currentX),ee=Math.max(J.startX,J.currentX),Q=Math.min(J.startY,J.currentY),te=Math.max(J.startY,J.currentY);if(ee-fe<=5&&te-Q<=5)Ce.value=null,wt();if(ee-fe>5||te-Q>5){let ne=K.value,W=(fe-ne.x)/ne.scale,ue=(ee-ne.x)/ne.scale,bt=(Q-ne.y)/ne.scale,Nt=(te-ne.y)/ne.scale,D=[];for(let ae of F.value.values()){let Fe=ae.position.x,ve=ae.position.y;if(Fe+ae.size.width>W&&Fe<ue&&ve+ae.size.height>bt&&ve<Nt)D.push(ae.id)}if(D.length>0)Yv(D)}d(null)},[]);B(()=>{if(o)return;if(!l.current&&!f&&!h)return;l.current=!1,u.current=[],m(null),T(null)},[o,f,T,h]);let N=H(()=>{let M=x.current;if(!M)return;let J=M.value.trim();if(T(null),!J)return;let fe={x:M.x,y:M.y};Cu({type:"text",points:[fe],color:lp,width:Zw,text:J})},[T]);B(()=>{if(r!=="text"&&h)T(null)},[r,T,h]),B(()=>{let M=(Q,te,ne)=>{let W=null;for(let ue of F.value.values()){if(ue.id===ne||ue.type==="group")continue;if(Q>=ue.position.x&&Q<=ue.position.x+ue.size.width&&te>=ue.position.y&&te<=ue.position.y+ue.size.height)W=ue.id}return W};function J(Q){if(!je.value)return;let te=b.current;if(!te)return;let ne=te.getBoundingClientRect(),W=K.value,ue=(Q.clientX-ne.left-W.x)/W.scale,bt=(Q.clientY-ne.top-W.y)/W.scale;je.value={...je.value,cursorX:ue,cursorY:bt,targetId:M(ue,bt,je.value.fromId)}}function fe(){let Q=je.value;if(!Q)return;je.value=null;let te=Q.targetId;if(!te)return;if(Q.withLabel){Lt("Edge label","label text").then((ne)=>{Eo(Q.fromId,te,"relation",ne??void 0)});return}Eo(Q.fromId,te,"relation",void 0)}function ee(Q){let te=je.value;if(!te)return;if(Q.key==="Escape")Q.preventDefault(),je.value=null;else if(Q.key==="l"||Q.key==="L")Q.preventDefault(),je.value={...te,withLabel:!te.withLabel}}return document.addEventListener("pointermove",J),document.addEventListener("pointerup",fe),document.addEventListener("keydown",ee),()=>{document.removeEventListener("pointermove",J),document.removeEventListener("pointerup",fe),document.removeEventListener("keydown",ee)}},[b]);let Z=H((M)=>{if(o)return;let J=b.current;if(!J||M.target!==J||!n)return;let fe=J.getBoundingClientRect(),ee=K.value,Q=(M.clientX-fe.left-ee.x)/ee.scale,te=(M.clientY-fe.top-ee.y)/ee.scale;n(M,Q,te)},[o,b,n]),j=H((M)=>{M.preventDefault()},[]),S=H((M)=>{if(up(M.target instanceof Element?M.target:null))return;M.preventDefault()},[]),V=H((M)=>{if(M.preventDefault(),E.current++,M.dataTransfer?.types.includes("Files")||L1(M.dataTransfer))y(!0)},[]),ge=H((M)=>{if(M.preventDefault(),M.dataTransfer)M.dataTransfer.dropEffect="copy"},[]),Ze=H((M)=>{if(M.preventDefault(),E.current--,E.current<=0)E.current=0,y(!1)},[]),se=H(async(M)=>{M.preventDefault(),y(!1),E.current=0;let J=b.current;if(!J||!M.dataTransfer)return;let fe=J.getBoundingClientRect(),ee=K.value,Q=(M.clientX-fe.left-ee.x)/ee.scale,te=(M.clientY-fe.top-ee.y)/ee.scale,ne=Array.from(M.dataTransfer.files);if(ne.length===0){let W=O1(M.dataTransfer);await w(W,Q,te);return}await Dr(ne,Q,te)},[b,w]);B(()=>{let M=async(J)=>{if(J.defaultPrevented)return;if(up(J.target instanceof Element?J.target:null))return;if(up(document.activeElement))return;let fe=J.clipboardData?.getData("text/plain")??"",ee=dp(fe);if(ee.length===0)return;let Q=b.current;if(!Q)return;J.preventDefault();let te=Q.getBoundingClientRect(),ne=K.value,W=(te.width/2-ne.x)/ne.scale,ue=(te.height/2-ne.y)/ne.scale;await w(ee,W,ue)};return document.addEventListener("paste",M),()=>{document.removeEventListener("paste",M)}},[b,w]);let de=D1(F.value.values(),qe.value,new Set(_u.value.keys())),me=dn.value,go=me?F.value.get(me.groupId):void 0,Gt=me?F.value.get(me.nodeId):void 0,an=null;if(p){let M=Math.min(p.startX,p.currentX),J=Math.min(p.startY,p.currentY),fe=Math.abs(p.currentX-p.startX),ee=Math.abs(p.currentY-p.startY);an={position:"absolute",left:`${M}px`,top:`${J}px`,width:`${fe}px`,height:`${ee}px`,pointerEvents:"none"}}return i("div",{class:`canvas-viewport${pr()?" pan-mode":""}`,ref:b,tabIndex:0,onPointerDown:_,onPointerMove:z,onPointerLeave:()=>{c.current=null,Va(null)},onPointerUp:U,onContextMenu:j,onDblClick:Z,onDragStart:S,onDragEnter:V,onDragOver:ge,onDragLeave:Ze,onDrop:se,style:{width:"100%",height:"100%",position:"relative",overflow:"hidden",cursor:r==="eraser"?"cell":r==="text"?"text":o||je.value||a.current||Et.value==="connect"?"crosshair":pr()?"grab":"default"},children:[i("div",{ref:P,class:"canvas-world",style:{transform:`matrix(${s.scale}, 0, 0, ${s.scale}, ${s.x}, ${s.y})`,transformOrigin:"0 0",position:"absolute",top:0,left:0},children:[i(Kx,{},void 0,!1,void 0,this),i(kw,{},void 0,!1,void 0,this),i(nw,{},void 0,!1,void 0,this),i(dw,{},void 0,!1,void 0,this),i(pw,{},void 0,!1,void 0,this),i(Hw,{nodes:F,edges:De,onEdgeContextMenu:t},void 0,!1,void 0,this),je.value&&i("div",{class:"edge-hint-pill","data-testid":"edge-hint",style:{left:`${je.value.cursorX+14}px`,top:`${je.value.cursorY+14}px`},children:[i("span",{class:"edge-hint-main",children:je.value.targetId?"release to connect":"drag onto a node"},void 0,!1,void 0,this),i("span",{class:"edge-hint-keys",children:["esc cancels · L labels",je.value.withLabel?" · label on":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),me&&go&&Gt&&i("div",{class:"drop-pill","data-testid":"drop-pill",style:{left:`${Gt.position.x}px`,top:`${Gt.position.y+Gt.size.height+10}px`},children:[i("span",{class:"drop-pill-text",children:me.mode==="add"?`release to add to ${String(go.data.title??"group")}`:`release to remove from ${String(go.data.title??"group")}`},void 0,!1,void 0,this),i("span",{class:"drop-pill-hint",children:me.mode==="add"?"esc keeps it out":"esc keeps it in"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(cp,{annotations:Array.from(ur.value.values())},void 0,!1,void 0,this),f&&f.points.length>=2&&i(cp,{annotations:[f]},void 0,!1,void 0,this),de.map((M)=>i(Bw,{node:M,onContextMenu:e,children:P1(M)},M.id,!1,void 0,this)),Uo.value&&i("svg",{class:"snap-guides-svg",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:Uo.value.map((M,J)=>M.axis==="x"?i("line",{x1:M.pos,y1:M.from-20,x2:M.pos,y2:M.to+20,class:"snap-guide-line"},J,!1,void 0,this):i("line",{x1:M.from-20,y1:M.pos,x2:M.to+20,y2:M.pos,class:"snap-guide-line"},J,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o&&i("div",{class:`annotation-capture-layer${r==="eraser"?" erasing":""}${r==="text"?" text":""}`,"aria-hidden":"true"},void 0,!1,void 0,this),h&&i("input",{class:"annotation-text-input",value:h.value,autoFocus:!0,style:{left:`${h.x*s.scale+s.x}px`,top:`${h.y*s.scale+s.y}px`,fontSize:`${Zw*s.scale}px`},onInput:(M)=>T({...h,value:M.target.value}),onBlur:N,onPointerDown:(M)=>M.stopPropagation(),onKeyDown:(M)=>{if(M.key==="Enter")M.preventDefault(),N();if(M.key==="Escape")M.preventDefault(),T(null)}},void 0,!1,void 0,this),an&&i("div",{class:"lasso-rect",style:an},void 0,!1,void 0,this),g&&i("div",{class:"drop-zone-overlay",children:i("div",{class:"drop-zone-indicator",children:[i("div",{class:"drop-zone-icon",children:"+"},void 0,!1,void 0,this),i("div",{class:"drop-zone-label",children:"Drop files or URLs to add to canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ww(){let e=[...Ae.value],t=F.value,[n,o]=I(""),[r,s]=I(!1),a=cw.value,[c,l]=I(null),u=a.length>=2,p=!u&&a.length===1&&a[0].steerable?a[0]:null,d=u?c?a.find((h)=>h.value===c&&h.steerable)??null:null:p,f=d?.value??null,m=async()=>{let h=n.trim();if(!h||r)return;s(!0);let v=await _w(h,f);if(s(!1),v)o("")};return i("div",{class:"command-bar","data-testid":"command-bar",children:[e.length>0&&i("div",{class:"command-bar-chips","aria-label":"Pinned context",children:[e.map((h)=>{let v=t.get(h),x=typeof v?.data.title==="string"&&v.data.title.trim()?v.data.title:v?.type??h;return i("span",{class:"command-bar-chip","data-node-id":h,children:[i("span",{class:"command-bar-chip-glyph","aria-hidden":"true",children:"✦"},void 0,!1,void 0,this),i("span",{class:"command-bar-chip-label",title:x,children:x},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-chip-unpin","aria-label":`Unpin ${x}`,title:"Remove from context",onClick:()=>Xn(h),children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},h,!0,void 0,this)}),i("span",{class:"command-bar-chips-note",children:"in agent context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"command-bar-composer",children:[i(yr,{size:15,class:"command-bar-icon"},void 0,!1,void 0,this),u&&i("select",{class:"command-bar-target","aria-label":"Steer which agent",title:"Connected agents — steering reaches all of them unless you address one",value:f??"",onChange:(h)=>l(h.target.value||null),children:[i("option",{value:"",children:"All agents"},void 0,!1,void 0,this),a.map((h)=>{let v=h.pendingSteers&&h.pendingSteers>0?` · ${h.pendingSteers} queued`:"",x=h.polling?" · polling":"";return i("option",{value:h.value,disabled:!h.steerable,children:h.attached?`${h.label}${x}${v}`:h.steerable?`${h.label} · writer${x}${v}`:`${h.label} · no inbox`},h.value,!1,void 0,this)})]},void 0,!0,void 0,this),i("input",{class:"command-bar-input",type:"text",value:n,placeholder:`Steer ${d?.label??"the agent"}, or ${We("K")} to search the board…`,"aria-label":"Steer the agent",disabled:r,onInput:(h)=>o(h.target.value),onKeyDown:(h)=>{if(h.key==="Enter")h.preventDefault(),m()}},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-send",disabled:r||!n.trim(),onClick:()=>void m(),children:r?"Sending…":"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var pp=Le(()=>{if(Ot.value==="disconnected")return"reconnecting";if(Ot.value==="connected"&&!It.value&&zo.value>1)return"resyncing";return null});function Vw(){let e=pp.value;if(!e)return null;if(e==="reconnecting"){let t=Po.value,n=No.value;return i("div",{class:"connection-banner is-reconnecting",role:"status","data-testid":"connection-banner",children:[i("span",{class:"connection-banner-glyph","aria-hidden":"true",children:"↻"},void 0,!1,void 0,this),i("span",{class:"connection-banner-text",children:[i("b",{children:"Reconnecting…"},void 0,!1,void 0,this)," live updates are paused; edits still save, the board may be stale until the stream returns."]},void 0,!0,void 0,this),i("span",{class:"connection-banner-meta",children:[t>0?`retry ${t}`:"retrying",n>0?` · ${Math.max(1,Math.round(n/1000))}s`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}return i("div",{class:"connection-banner is-resyncing",role:"status","data-testid":"connection-banner",children:[i("span",{class:"connection-banner-glyph","aria-hidden":"true",children:"⟳"},void 0,!1,void 0,this),i("span",{class:"connection-banner-text",children:[i("b",{children:"Resyncing from snapshot"},void 0,!1,void 0,this)," — the event cursor went stale; the board reloads without losing local edits."]},void 0,!0,void 0,this),i("span",{class:"connection-banner-progress","aria-hidden":"true",children:i("span",{class:"connection-banner-progress-fill"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var F1={markdown:{width:520,height:360},group:{width:600,height:400},html:{width:720,height:640},image:{width:720,height:520},file:{width:720,height:600},webpage:{width:520,height:420}};async function Ft(e){if(e.x!==void 0&&e.y!==void 0)return en(e);let t=F1[e.type]??{width:360,height:200},n=e.width??t.width,o=e.height??t.height,r=qn(),s=K.value,a=await en({...e,width:n,height:o,x:Math.round((r.x-s.x)/s.scale-n/2),y:Math.round((r.y-s.y)/s.scale-o/2)});if(a.ok&&a.id)Ke(a.id);return a}var Oc=!1,Gw=!1,qo=null,Ur=null;function mp(){return Oc}function Lc(){Oc=!1,Gw=!0,Xw()}function Xw(){if(qo&&Ur)qo.removeEventListener("change",Ur);qo=null,Ur=null}function B1(){if(typeof window>"u"||!window.location)return null;let e=new URLSearchParams(window.location.search).get("theme");if(e==="auto")return"auto";return Ai(e)?e:null}function Jw(e){if(Gw)return;let t=B1();if(!t)return;if(Xw(),Oc=!0,t!=="auto"){e(t);return}qo=window.matchMedia("(prefers-color-scheme: light)"),Ur=()=>{if(Oc&&qo)e(qo.matches?"light":"dark")},Ur(),qo.addEventListener("change",Ur)}var H1='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Pt(e,t,n={}){B(()=>{if(!t)return;let o=e.current;if(!o)return;let r=document.activeElement,s=n.restoreTo,a=()=>Array.from(o.querySelectorAll(H1)),c=n.initial?.current??a()[0];if(c&&!o.contains(document.activeElement))c.focus();let l=(u)=>{if(u.key!=="Tab")return;let p=a();if(p.length===0)return;let d=p[0],f=p[p.length-1],m=document.activeElement;if(u.shiftKey&&(m===d||!o.contains(m)))u.preventDefault(),f.focus();else if(!u.shiftKey&&m===f)u.preventDefault(),d.focus()};return o.addEventListener("keydown",l),()=>{if(o.removeEventListener("keydown",l),s)requestAnimationFrame(()=>s()?.focus());else if(r&&document.contains(r)&&r!==document.body)r.focus()}},[e,t,n.initial,n.restoreTo])}function j1(e,t){let n=e.toLowerCase(),o=t.toLowerCase(),r=[],s=0,a=0,c=-1;for(let l=0;l<o.length&&s<n.length;l++)if(o[l]===n[s]){if(r.push(l),a+=c===l-1?10:1,l===0||o[l-1]===" "||o[l-1]==="-"||o[l-1]==="_")a+=5;c=l,s++}return{match:s===n.length,score:a,indices:r}}function Z1(e,t){if(t.length===0)return e;let n=[],o=0;for(let r of t){if(r>o)n.push(e.slice(o,r));n.push(i("mark",{children:e[r]},r,!1,void 0,this)),o=r+1}if(o<e.length)n.push(e.slice(o));return n}var fp={md:"markdown",app:"mcp-app",web:"webpage",ui:"json-render",chart:"graph",ctx:"context",log:"ledger"};function U1(e){let t=e.toLowerCase().trim();if(t.startsWith("type:")){let n=t.slice(5).trim(),r=Object.keys(ut).find((a)=>a.startsWith(n));if(r)return{typeFilter:r,remaining:""};let s=fp[n];if(s)return{typeFilter:s,remaining:""}}if(fp[t])return{typeFilter:fp[t],remaining:""};return{typeFilter:null,remaining:e}}function Kw({onClose:e,onToggleMinimap:t}){let[n,o]=I(""),[r,s]=I(0),[a,c]=I([]),[l,u]=I("idle"),p=R(null),d=R(null),f=R(null);Pt(f,!0,{initial:p}),B(()=>{setTimeout(()=>p.current?.focus(),30)},[]),B(()=>{let b=n.trim();if(b.length<2){c([]),u("idle");return}let T=!0;u("loading");let w=window.setTimeout(()=>void Y("paletteLibrarySearch",`/api/canvas/search?q=${encodeURIComponent(b)}&scope=library&limit=12`,null).then((_)=>{if(!T)return;if(!_){c([]),u("error");return}c(_.results??[]),u("idle")}),150);return()=>{T=!1,window.clearTimeout(w)}},[n]);let m=H(()=>{let b=[];for(let w of F.value.values()){let _=w.data.title||ut[w.type],z=w.data.content||w.data.path||"",U=w.type==="group"&&Array.isArray(w.data.children)?w.data.children.length:0;b.push({id:`node:${w.id}`,kind:"node",label:_,description:w.type==="group"?`group · ${U} node${U===1?"":"s"}`:z.length>60?`${ut[w.type].toLowerCase()} · ${z.slice(0,60)}…`:z?`${ut[w.type].toLowerCase()} · ${z}`:ut[w.type].toLowerCase(),icon:rn(w.type),nodeType:w.type,action:()=>{Ke(w.id),e()}})}let T=[{label:"New markdown note",shortcut:"M",icon:Qn,iconTone:"accent",action:()=>{Ft({type:"markdown",title:"New note",width:520,height:360}),e()}},{label:"Link to board…",icon:rn("board"),iconTone:"accent",action:()=>{window.dispatchEvent(new CustomEvent("pmx-open-board-link")),e()}},...yt.value?[]:[{label:"Start agent session",icon:yr,iconTone:"purple",action:()=>{uo(),e()}}],{label:"Fit view",shortcut:"F",icon:va,iconTone:"muted",action:()=>{hr(rt().width,rt().height),e()}},{label:"Auto-arrange (grid)",icon:En,iconTone:"muted",action:()=>{da(),e()}},{label:"Auto-arrange (graph-aware)",icon:En,iconTone:"muted",action:()=>{pa(),e()}},{label:"Toggle minimap",icon:ya,iconTone:"muted",action:()=>{t(),e()}},{label:"Toggle theme (dark/light)",icon:ba,iconTone:"muted",action:()=>{let w=tt.value==="dark"?"light":"dark";Lc(),document.documentElement.setAttribute("data-theme",w),Or(),tt.value=w,Ks(w),e()}}];for(let w of T)b.push({id:`action:${w.label}`,kind:"action",label:w.label,...w.shortcut?{shortcut:w.shortcut}:{},icon:w.icon,...w.iconTone?{iconTone:w.iconTone}:{},action:w.action});return b},[e,t]),{typeFilter:h,remaining:v}=U1(n),x=m(),g;if(!n.trim())g=x.map((b)=>({...b,score:0,indices:[]}));else{g=[];for(let b of x){if(h){if(b.kind!=="node"||b.nodeType!==h)continue;if(!v){g.push({...b,score:0,indices:[]});continue}}let T=j1(v||n,b.label);if(T.match)g.push({...b,score:T.score,indices:T.indices})}g.sort((b,T)=>T.score-b.score)}for(let b of a)g.push({id:`library:${b.boardId}:${b.cardId}`,kind:"library",label:b.title||b.boardTitle,description:`${b.boardTitle} · ${b.snippet}`,icon:rn("board"),score:0,indices:[],action:()=>{(async()=>{if(await zt(b.boardId),Ne.value!==b.boardId)return;for(let T=0;T<40&&Ne.value===b.boardId;T++){if(F.value.has(b.cardId)){Ke(b.cardId),e();return}await new Promise((w)=>window.setTimeout(w,25))}})()}});g=[...g.filter((b)=>b.kind==="action"),...g.filter((b)=>b.kind==="node"),...g.filter((b)=>b.kind==="library")];let y=g.findIndex((b)=>b.kind==="node"),E=g.findIndex((b)=>b.kind==="library");B(()=>{if(!n.trim()){Sn.value=null;return}let b=new Set;for(let T of g)if(T.kind==="node")b.add(T.id.slice(5));Sn.value=b.size>0?b:null},[n,g]),B(()=>()=>{Sn.value=null},[]);let L=Math.min(r,Math.max(0,g.length-1)),P=H((b)=>{if(b.key==="ArrowDown")b.preventDefault(),s((T)=>Math.min(T+1,g.length-1));else if(b.key==="ArrowUp")b.preventDefault(),s((T)=>Math.max(T-1,0));else if(b.key==="Enter"){if(b.preventDefault(),g[L])g[L].action()}else if(b.key==="Escape")b.preventDefault(),b.stopPropagation(),e()},[g,L,e]);return B(()=>{let b=d.current;if(!b)return;b.children[L]?.scrollIntoView({block:"nearest"})},[L]),B(()=>{s(0)},[n]),i("div",{class:"command-palette-backdrop",onMouseDown:e,children:i("div",{ref:f,class:"command-palette",role:"dialog","aria-modal":"true","aria-label":"Search and commands",onMouseDown:(b)=>b.stopPropagation(),children:[i("div",{class:"command-palette-search",children:[i("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{ref:p,type:"text",class:"command-palette-input",value:n,onInput:(b)=>o(b.target.value),onKeyDown:P,placeholder:"Search nodes, run actions, jump to…","aria-label":"Search nodes, run actions, jump to"},void 0,!1,void 0,this),i("kbd",{class:"command-palette-esc",children:"esc"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"command-palette-results",ref:d,children:[l==="loading"&&i("div",{class:"command-palette-empty",role:"status",children:"Searching all boards…"},void 0,!1,void 0,this),l==="error"&&i("div",{class:"command-palette-empty",role:"alert",children:"Library search is unavailable."},void 0,!1,void 0,this),g.length===0&&l!=="loading"&&i("div",{class:"command-palette-empty",children:"No matching nodes, boards, or actions"},void 0,!1,void 0,this),g.map((b,T)=>{let w=b.icon,_=T===0&&b.kind==="action"?"Actions":T===y?"Jump to":T===E?"Across boards":null;return i("div",{class:"command-palette-row",children:[_&&i("div",{class:"command-palette-group",children:_},void 0,!1,void 0,this),i("button",{type:"button",class:`command-palette-item${T===L?" selected":""}`,onMouseEnter:()=>s(T),onClick:()=>b.action(),children:[i("span",{class:`command-palette-icon tone-${b.iconTone??"kind"}`,"aria-hidden":"true",children:i(w,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"command-palette-label",children:[b.indices.length>0?Z1(b.label,b.indices):b.label,b.description&&i("span",{class:"command-palette-desc",children:[" — ",b.description]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),b.shortcut&&i("kbd",{class:"command-palette-kbd",children:b.shortcut},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},b.id,!0,void 0,this)})]},void 0,!0,void 0,this),i("div",{class:"command-palette-hint",children:[i("span",{children:"↑↓ navigate"},void 0,!1,void 0,this),i("span",{children:"↵ open"},void 0,!1,void 0,this),i("span",{children:"esc close"},void 0,!1,void 0,this),i("span",{children:"type: filter"},void 0,!1,void 0,this),i("span",{class:"command-palette-hint-spacer"},void 0,!1,void 0,this),i("span",{children:We("K")},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Yw({onClose:e}){let t=R(null),n=R(null),[o,r]=I(""),[s,a]=I("");Pt(t,!0,{initial:n});let c=At.value.filter((u)=>u.id!==Ne.value&&u.name.toLowerCase().includes(o.trim().toLowerCase())),l=async(u)=>{let p=At.value.find((h)=>h.id===u);if(!p)return a("That board is no longer available.");let d=qn(),f=K.value;if(!(await Y("createBoardLink","/api/canvas/node",{},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"board",title:p.name,x:Math.round((d.x-f.x)/f.scale-180),y:Math.round((d.y-f.y)/f.scale-100),width:360,height:200,data:{boardId:u}})})).ok)return a("Could not create the board link.");e()};return i("div",{class:"text-prompt-backdrop",onMouseDown:e,children:i("div",{ref:t,class:"text-prompt board-link-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"board-link-title",onMouseDown:(u)=>u.stopPropagation(),children:[i("h2",{id:"board-link-title",children:"Link to a board"},void 0,!1,void 0,this),i("input",{ref:n,type:"search",class:"text-prompt-input","aria-label":"Find a board to link",placeholder:"Find a board…",value:o,onInput:(u)=>r(u.currentTarget.value)},void 0,!1,void 0,this),s&&i("div",{role:"alert",class:"board-copy-error",children:s},void 0,!1,void 0,this),i("ul",{class:"board-link-results",children:[c.map((u)=>i("li",{children:i("button",{type:"button",onClick:()=>void l(u.id),children:[i("span",{children:u.name},void 0,!1,void 0,this),i("small",{children:[u.nodeCount," nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},u.id,!1,void 0,this)),c.length===0&&i("li",{class:"board-copy-status",children:At.value.length<=1?"Create another board first, then link it here.":"No boards match your search."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"text-prompt-actions",children:i("button",{type:"button",onClick:e,children:"Cancel"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Qw(){let[e,t]=I(null),n=H((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"node",x:a.clientX,y:a.clientY,nodeId:c})},[]),o=H((a,c,l)=>{a.preventDefault(),a.stopPropagation(),t({kind:"canvas",x:a.clientX,y:a.clientY,canvasX:c,canvasY:l})},[]),r=H((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"edge",x:a.clientX,y:a.clientY,edgeId:c})},[]),s=H(()=>t(null),[]);return B(()=>{if(!e)return;let a=()=>t(null),c=(l)=>{if(l.key==="Escape")t(null)};return document.addEventListener("click",a),document.addEventListener("keydown",c),()=>{document.removeEventListener("click",a),document.removeEventListener("keydown",c)}},[e]),{menu:e,openNodeMenu:n,openCanvasMenu:o,openEdgeMenu:r,closeMenu:s}}var q1="#4bbcFF",W1=[{label:"Blue",value:"#3b82f6"},{label:"Green",value:"#22c55e"},{label:"Yellow",value:"#eab308"},{label:"Red",value:"#ef4444"},{label:"Gray",value:"#6b7280"},{label:"Purple",value:"#a855f7"}];function e_({menu:e,onClose:t}){let n;if(e.kind==="node"){let c=F.value.get(e.nodeId);if(!c)return null;n=Y1(c)}else if(e.kind==="edge"){let c=e.edgeId,l=De.value.get(c);n=[{label:l?.label?`Edit label “${l.label.slice(0,18)}${l.label.length>18?"…":""}”`:"Add label…",action:()=>{Lt("Edge label (empty clears it)","label text",{initial:l?.label??"",allowEmpty:!0,confirm:"Save"}).then((u)=>{if(u===null)return;na(c,{label:u})})}},{separator:!0},...["flow","depends-on","relation","references"].map((u)=>({label:`${l?.type===u?"✓":" "} ${u}`,action:()=>void na(c,{type:u})})),{separator:!0},...["solid","dashed","dotted"].map((u)=>({label:`${(l?.style??"solid")===u?"✓":" "} ${u}`,action:()=>void na(c,{style:u})})),{separator:!0},{label:"Delete edge",danger:!0,action:()=>void oa(c)}]}else n=K1(e.canvasX,e.canvasY);let o=new Map,r=n.some((c)=>c.render)?n.length*32+168:n.length*32+8,s=Math.min(e.x,Math.max(12,window.innerWidth-240)),a=Math.min(e.y,Math.max(12,window.innerHeight-r));return i("div",{class:"context-menu",style:{position:"fixed",left:`${s}px`,top:`${a}px`,zIndex:1e4},onPointerDown:(c)=>c.stopPropagation(),onClick:(c)=>c.stopPropagation(),children:n.map((c)=>{let l=c.separator?"separator":c.render?"custom":`${c.label??"item"}:${c.shortcut??""}`,u=(o.get(l)??0)+1;o.set(l,u);let p=`${l}:${u}`;if(c.separator)return i("div",{class:"context-menu-separator"},p,!1,void 0,this);if(c.render)return i("div",{class:"context-menu-custom",children:c.render(t)},p,!1,void 0,this);return i("button",{type:"button",class:`context-menu-item${c.danger?" is-danger":""}`,onClick:()=>{c.action?.(),t()},children:[i("span",{class:"context-menu-label",children:c.label},void 0,!1,void 0,this),c.shortcut&&i("span",{class:"context-menu-shortcut",children:c.shortcut},void 0,!1,void 0,this)]},p,!0,void 0,this)})},void 0,!1,void 0,this)}function V1(e){return(typeof e.data.path==="string"?e.data.path.trim():"")||null}function Dc(e){let t=e.trim().toLowerCase(),n=t.match(/^#([0-9a-f]{3})$/);if(n){let[o,r,s]=n[1].split("");return`#${o}${o}${r}${r}${s}${s}`}return t}function t_(e){if(typeof e.data.color!=="string"||!e.data.color.trim())return null;return Dc(e.data.color)}function G1(e){let t=t_(e);return t&&/^#[0-9a-f]{6}$/.test(t)?t:Dc(q1)}function hp(e,t){let n=t?Dc(t):null;st(e.id,{data:{...e.data,color:n}}),pt(e.id,{data:{color:n}})}function X1(e,t){let n=t_(e);return i("div",{class:"context-menu-section",children:[i("div",{class:"context-menu-section-header",children:[i("span",{class:"context-menu-section-label",children:"Group color"},void 0,!1,void 0,this),i("button",{type:"button",class:"context-menu-reset",onClick:()=>{hp(e,null),t()},children:"Theme default"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"context-menu-color-grid",children:W1.map((o)=>{let r=Dc(o.value);return i("button",{type:"button",class:`context-menu-color-swatch${n===r?" active":""}`,"aria-label":`Set group color to ${o.label}`,title:o.label,style:{"--swatch-color":o.value},onClick:()=>{hp(e,o.value),t()},children:[i("span",{class:"context-menu-color-dot",style:{"--swatch-color":o.value}},void 0,!1,void 0,this),i("span",{children:o.label},void 0,!1,void 0,this)]},o.value,!0,void 0,this)})},void 0,!1,void 0,this),i("label",{class:"context-menu-color-custom",children:[i("span",{children:"Custom"},void 0,!1,void 0,this),i("input",{type:"color",class:"context-menu-color-input","aria-label":"Custom group color",value:G1(e),onClick:(o)=>o.stopPropagation(),onInput:(o)=>{hp(e,o.currentTarget.value),t()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function vp(e,t,n,o){return{x:e-n/2,y:t-o/2}}function J1(e,t){return e.trim().replace(/[?#].*$/,"").split("/").filter(Boolean).at(-1)||t}async function gp(e){let t=await Lt(e.promptLabel,e.placeholder??"");if(!t)return;let n=t.trim();if(!n)return;let o=vp(e.canvasX,e.canvasY,e.width,e.height);if(!(await en({type:e.type,...e.type!=="webpage"?{title:J1(n,e.titleFallback)}:{},content:n,x:o.x,y:o.y,width:e.width,height:e.height})).ok)console.error(`[canvas-menu] ${e.errorMessage}`)}function K1(e,t){return[{label:"New note",action:()=>{let r=vp(e,t,520,360);en({type:"markdown",title:"New note",x:r.x,y:r.y,width:520,height:360})}},{label:"Open webpage...",action:()=>{gp({promptLabel:"Webpage URL:",type:"webpage",canvasX:e,canvasY:t,width:520,height:420,placeholder:"https://example.com",titleFallback:"Webpage",errorMessage:"Could not create webpage node. Enter a valid http(s) URL."})}},{label:"Open file...",action:()=>{gp({promptLabel:"Workspace path or absolute file path:",type:"file",canvasX:e,canvasY:t,width:720,height:500,placeholder:"src/server/server.ts",titleFallback:"File",errorMessage:"Could not create file node. Check the path and try again."})}},{label:"Open image...",action:()=>{gp({promptLabel:"Image path, URL, or data URI:",type:"image",canvasX:e,canvasY:t,width:480,height:360,placeholder:"artifacts/architecture.png",titleFallback:"Image",errorMessage:"Could not create image node. Check the image source and try again."})}},{label:"Link to board…",action:()=>window.dispatchEvent(new CustomEvent("pmx-open-board-link"))},{separator:!0},{label:"New group",action:()=>{let r=vp(e,t,600,400);cr({title:"Group",x:r.x,y:r.y,width:600,height:400})}}]}function Y1(e){let t=[],n=V1(e);if(t.push({label:"Focus",action:()=>Ke(e.id)}),t.push({label:"Rename…",action:()=>{Lt("Rename node","Node title",{initial:typeof e.data.title==="string"?e.data.title:"",confirm:"Save"}).then((l)=>{if(!l?.trim())return;pt(e.id,{title:l.trim()})})}}),ui.has(e.type))t.push({label:"Expand",shortcut:"⤢",action:()=>Ut(e.id)});t.push({label:e.collapsed?"Expand":"Collapse",action:()=>mr(e.id)});let o=Ae.value.has(e.id);t.push({label:o?"Unpin from context":"Pin as context",action:()=>Xn(e.id)}),t.push({label:e.pinned?"Unlock position":"Lock position (no auto-arrange)",action:()=>{let l=!e.pinned;st(e.id,{pinned:l}),pt(e.id,{pinned:l}),at()}});let r=yi.value;if(r&&r.from!==e.id){let l=F.value.get(r.from),u=l?(l.data.title||l.id).slice(0,20):r.from;t.push({label:`Connect from "${u}"`,action:()=>{Eo(r.from,e.id,"relation"),yi.value=null}})}t.push({label:r?"Connect from here (replace)":"Connect from here",action:()=>{yi.value={from:e.id}}});let s=Array.from(De.value.values()).filter((l)=>l.from===e.id||l.to===e.id).length;if(s>0)t.push({label:`${s} edge${s!==1?"s":""} connected`});if(t.push({separator:!0}),(e.type==="markdown"||e.type==="file"||e.type==="image")&&n)t.push({label:"Open in browser",action:()=>{window.open(`/artifact?path=${encodeURIComponent(n)}`,"_blank","noopener")}}),t.push({label:"Copy path",action:()=>{navigator.clipboard.writeText(n)}});if(e.type==="mcp-app"||e.type==="json-render"||e.type==="graph")if(e.data.chartConfig){let l=e.data.chartConfig.title||"chart";t.push({label:"Copy chart data",action:()=>{navigator.clipboard.writeText(JSON.stringify(e.data.chartConfig,null,2))}})}else{let l=e.data.url;if(t.push({label:"Open in browser",action:()=>{if(l)window.open(l,"_blank")}}),t.push({label:"Focus in TUI",action:()=>Pv("mcp-app-focus",{url:l})}),e.type==="json-render"||e.type==="graph")t.push({label:"Copy spec",action:()=>{navigator.clipboard.writeText(JSON.stringify(e.data.spec??e.data.graphConfig??{},null,2))}})}if(e.type==="webpage"){let l=typeof e.data.url==="string"?e.data.url:"";t.push({label:"Refresh webpage",action:()=>{Qs(e.id)}}),t.push({label:"Open in browser",action:()=>{if(l)window.open(l,"_blank","noopener")}}),t.push({label:"Copy URL",action:()=>{if(l)navigator.clipboard.writeText(l)}})}if(e.type==="group"){let l=e.data.children??[];if(t.push({separator:!0}),t.push({render:(u)=>X1(e,u)}),l.length>0)t.push({label:`Ungroup (${l.length} node${l.length!==1?"s":""})`,action:()=>{Jn(e.id),lr(e.id)}})}let a=typeof e.data.parentGroup==="string"?e.data.parentGroup:null,c=a?F.value.get(a):void 0;if(c&&c.type==="group"){let l=typeof c.data.title==="string"&&c.data.title?c.data.title:"frame",u=Array.isArray(c.data.children)?c.data.children.filter((p)=>p!==e.id):[];t.push({label:`Remove from “${l}”`,action:()=>{ta(c.id,u)}})}return t.push({separator:!0}),t.push({label:e.type==="group"?"Delete frame (children stay)":"Delete",danger:!0,action:()=>{Vn(e.id)}}),t}function n_(){let e=Ae.value.size;if(e===0||un.value)return null;return i("div",{class:"context-pin-bar",children:[i("span",{class:"context-pin-bar-count",children:["✦"," ",e," node",e!==1?"s":""," in context"]},void 0,!0,void 0,this),i("button",{type:"button",class:"context-pin-bar-btn context-pin-bar-clear",onClick:sy,title:"Clear all context pins","aria-label":"Clear all context pins",children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function o_({onClose:e}){let t=R(null),[n,o]=I("Bug report"),[r,s]=I(""),[a,c]=I("");return Pt(t,!0),i("div",{class:"text-prompt-backdrop feedback-backdrop",onPointerDown:e,children:i("form",{ref:t,class:"text-prompt feedback-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"feedback-title","aria-describedby":"feedback-privacy",action:"https://github.com/pskoett/pmx-canvas/issues/new",method:"get",target:"_blank",rel:"noopener noreferrer",onPointerDown:(l)=>l.stopPropagation(),onKeyDown:(l)=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),e()},children:[i("div",{id:"feedback-title",class:"text-prompt-title",children:"Bug and feedback"},void 0,!1,void 0,this),i("p",{id:"feedback-privacy",class:"feedback-note",children:"Opens a draft issue in pskoett/pmx-canvas. Review and submit it on GitHub using your account. Issues are public. Only what you enter below is included; no board contents, workspace paths, screenshots, or logs are attached."},void 0,!1,void 0,this),i("label",{children:["Feedback type",i("select",{class:"text-prompt-input",value:n,onChange:(l)=>o(l.currentTarget.value),children:[i("option",{children:"Bug report"},void 0,!1,void 0,this),i("option",{children:"Feature request"},void 0,!1,void 0,this),i("option",{children:"General feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("label",{children:["Title",i("input",{class:"text-prompt-input",name:"title",required:!0,maxLength:120,value:r,onInput:(l)=>s(l.currentTarget.value),placeholder:"A short summary"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("label",{children:["Description",i("textarea",{class:"text-prompt-input",required:!0,maxLength:1200,rows:6,value:a,onInput:(l)=>c(l.currentTarget.value),placeholder:"What happened, what you expected, and steps to reproduce — or describe your idea."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{type:"hidden",name:"body",value:`## ${n}
|
|
328
|
+
</script>`}function Dx(){return"<style data-pmx-canvas-ext-app-base>html, body { background: transparent !important; }</style>"}function Fx(e,t){if(!t)return e;let n=/<head\b[^>]*>/i.exec(e);if(n?.index!==void 0){let r=n.index+n[0].length;return`${e.slice(0,r)}${t}${e.slice(r)}`}let o=/<body\b[^>]*>/i.exec(e);if(o?.index!==void 0){let r=o.index+o[0].length;return`${e.slice(0,r)}${t}${e.slice(r)}`}return`${t}${e}`}function Dr(e,t){if(Number.isFinite(e)&&e>0)return Math.round(e);if(Number.isFinite(t)&&t>0)return Math.round(t);return 1}function jd(e,t){let n=e?.getBoundingClientRect();return{width:Dr(e?.clientWidth??0,Dr(n?.width??0,t.width)),height:Dr(e?.clientHeight??0,Dr(n?.height??0,t.height))}}function HE(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>0&&!t}function jE(e,t){return Math.max(Dr(e,1),Dr(t,1))}function Hx({node:e,expanded:t=!1}){let n=z(null),o=z(null),r=z(null),s=z(null),a=z({}),c=z(void 0),l=z(!1),u=z(void 0),p=z(null),d=z(!1),m=z(null),f=z(0),h=z([]),v=z(""),x=z(!1),g=z(!1),y=z([]),E=z(!1),D=z(!1),N=z(!1),b=z(!1),[T,w]=I("loading"),[_,P]=I(null),[q,R]=I(0),[Z,j]=I(!1),[k,V]=I(!1),[ge,Ue]=I(()=>t||typeof navigator>"u"||typeof window>"u"||!Bo(navigator.userAgent)),se=e.data.html,le=e.data.serverName,pe=e.data.appSessionId,Mn=e.data.toolInput??{},Xt=e.data.toolResult,cn=e.data.toolName??"ext-app",M=e.data.toolDefinition,J=e.data.toolCallId,me=typeof J==="string"||typeof J==="number"?J:void 0,te=e.data.resourceMeta,de=e.data.sessionStatus,Q=e.data.sessionError,ee=e.size.height,W=e.id,fe=LE(e,q),$e=DE(null),F=e.data.axCapabilities?.enabled===!0&&typeof se==="string"&&se.length>0,ne=Se(()=>`ax-${crypto.randomUUID()}`,[]),He=F?FE(ne,W):"",ve=typeof se==="string"&&se.length>0?BE(ne,W):"",Jt=Nx(Fx(se??"",Dx()+ve+He),$e);B(()=>{function X(oe){if(oe.source!==n.current?.contentWindow)return;let we=oe.data;if(!we||we.source!==Fa||we.token!==ne||we.nodeId!==W)return;if(g.current=!0,we.kind==="paint-tick"){let Me=we,Bt={content:Me.content===!0,detail:typeof Me.detail==="string"?Me.detail:""};for(let Dn of h.current.splice(0))Dn(Bt)}}return window.addEventListener("message",X),()=>window.removeEventListener("message",X)},[ne,W]),B(()=>{if(ge)return;Lx({remount:()=>{if(b.current)return!1;return lt(W,"mount-slot"),Ue(!0),!0},awaitBoot:()=>new Promise((X)=>{let oe=window.setTimeout(we,Rx);function we(){window.clearTimeout(oe),X()}y.current.push(we)})})},[]),Or({enabled:F,token:ne,nodeId:W,sourceSurface:"mcp-app",iframeRef:n});let ns=3,Kt=(X)=>{if(f.current>=ns)return lt(W,`remount-cap-hit (${X})`),!1;if(E.current)return!0;return f.current+=1,E.current=!0,lt(W,`remount-queued #${f.current} (${X})`),Lx({remount:()=>{if(E.current=!1,b.current||!t&&We.value===W)return lt(W,"remount-skipped"),j(!1),!1;return D.current=typeof document<"u"&&document.visibilityState==="hidden",lt(W,`remount-run #${f.current}`),w("loading"),R((oe)=>oe+1),!0},awaitBoot:()=>new Promise((oe)=>{let we=window.setTimeout(Me,Rx);function Me(){window.clearTimeout(we),oe()}y.current.push(Me)})}),!0},Ln=1500,Gc=()=>new Promise((X)=>{let oe=n.current?.contentWindow;if(!oe||b.current){X("timeout");return}let we=!1,Me=window.setTimeout(()=>{if(we)return;we=!0,X("timeout")},Ln);h.current.push((Bt)=>{if(we)return;we=!0,window.clearTimeout(Me),v.current=Bt.detail,X(Bt.content?"content-verified":"tick-no-content")}),oe.postMessage({source:Yu,token:ne},"*")}),Ap=async(X)=>{let oe=Date.now()+X;while(Date.now()<oe&&!b.current){if(await Gc()==="content-verified")return!0;await new Promise((we)=>window.setTimeout(we,400))}return!1},ok=()=>new Promise((X)=>{let oe=n.current;if(!oe){X();return}let we=oe.style.width,Me=oe.style.height;oe.style.width="140%",oe.style.height="140%",requestAnimationFrame(()=>{requestAnimationFrame(()=>{oe.style.width=we,oe.style.height=Me,lt(W,"soft-expand-cycle"),X()})})}),rk=600,os=()=>{if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;let X=n.current;if(!X||b.current)return;if(!$E({userAgent:navigator.userAgent,visibilityState:document.visibilityState,rect:X.getBoundingClientRect(),viewport:{width:window.innerWidth,height:window.innerHeight},alreadyRearmed:N.current}))return;N.current=!0,window.setTimeout(()=>{if(b.current||document.visibilityState==="visible")return;f.current=0,V(!1),D.current=!1,lt(W,"assume-visible-rearm"),Kt("assume-visible")},rk)},Xc=(X="")=>{let oe=v.current?` [${v.current}]`:"";return typeof document<"u"&&document.visibilityState==="hidden"?`paint-ok (content-verified)${oe}${X} (host hidden)`:`paint-ok (content-verified)${oe}${X}`},ik=async()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Bo(navigator.userAgent))return;j(!0);let X=await Gc();if(X==="content-verified"){lt(W,Xc()),j(!1),os();return}if(lt(W,X==="tick-no-content"?`paint-fail (tick without content: ${v.current||"unknown"})`:"paint-fail (no tick)"),await ok(),X=await Gc(),X==="content-verified"){lt(W,Xc(" (after soft-expand)")),j(!1),os();return}if(b.current)return;if(X==="tick-no-content"&&await Ap(3000)){lt(W,Xc(" (after content wait)")),j(!1),os();return}if(b.current)return;if(!Kt("paint-fail"))lt(W,"recovery-exhausted"),j(!1),V(!0),os()};B(()=>{if(t)return;if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;if(!Bo(navigator.userAgent))return;function X(){if(document.visibilityState!=="visible")return;if(!D.current||b.current)return;D.current=!1,f.current=0,V(!1),lt(W,"visible-again-rearm"),Kt("visible-after-hidden-boot")}return document.addEventListener("visibilitychange",X),()=>document.removeEventListener("visibilitychange",X)},[t,W]);let sk=6000;B(()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Bo(navigator.userAgent))return;if(!Jt.ready||!ge)return;let X=window.setTimeout(()=>{if(x.current||g.current||b.current)return;Kt("boot-watchdog")},sk);return()=>window.clearTimeout(X)},[fe,Jt.ready,t,ge]),B(()=>()=>{b.current=!0;for(let X of y.current.splice(0))X();for(let X of h.current.splice(0))X({content:!1,detail:"unmounted"})},[]);let Jc=(X)=>Nr(X),On=t||We.value===W;a.current=Mn,c.current=Xt;let rs=de==="error"&&typeof se==="string"&&se.length>0,Kc=de==="error"?rs?`Live session unavailable — showing saved content. Reopen the app to restore interactivity.${Q?` (${Q})`:""}`:Q??"Saved app session is unavailable. Reopen the app to restore interactivity.":"Reconnecting saved app session...",Yc=(X)=>{let oe=c.current;if(!X||!d.current||!oe)return null;if(u.current===oe)return null;if(u.current&&zx(u.current,oe))return u.current=oe,null;if(p.current)return p.current;let we=X.sendToolResult(oe).then(()=>{u.current=oe,l.current=!0,w("done")}).catch((Me)=>{let Bt=Me instanceof Error?Me.message:String(Me);throw P(`Tool result delivery failed: ${Bt}`),Me}).finally(()=>{p.current=null});return p.current=we,we};if(B(()=>{if(!se||!Jt.ready||!ge)return;let X=n.current;if(!X)return;let oe=!1,we=null,Me=null,Bt=null,Dn=null,go=null;l.current=!1,u.current=void 0,p.current=null,d.current=!1,x.current=!1,g.current=!1;let is=()=>{if(!we)return;clearTimeout(we),we=null};return(async()=>{if(!se)return;let Fn=X.contentWindow;if(!Fn)throw Error("Ext-app iframe window is unavailable");let vo=(ye=We.value===W?"fullscreen":"inline")=>({theme:Jc(nt.value),platform:"web",containerDimensions:jd(X,{width:e.size.width,height:ee}),displayMode:ye,locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,...M?{toolInfo:{id:me,tool:M}}:{}}),ak=()=>{if(Dn!==null)return;Dn=requestAnimationFrame(()=>{if(Dn=null,oe||!d.current)return;Le.setHostContext?.(vo())})},zp=()=>{if(go!==null)return;go=requestAnimationFrame(()=>{go=requestAnimationFrame(()=>{if(go=null,oe||!d.current)return;Le.sendHostContextChange?.(vo())})})},Pp=()=>{if(!Bo(navigator.userAgent))return;if(Me)clearTimeout(Me);Me=setTimeout(()=>{if(Me=null,oe)return;ik()},Bx+200)},Le=new Dd(null,{name:"PMX Canvas",version:"1.0.0"},{openLinks:{},serverTools:{listChanged:!1},serverResources:{listChanged:!1},logging:{},updateModelContext:{text:{},structuredContent:{}}},{hostContext:vo(On?"fullscreen":"inline")});Le.onsizechange=async({height:ye})=>{if(HE(ye,We.value===W)){let rt=jd(X.parentElement??X,{width:e.size.width,height:ee}),Ht=jE(ye,rt.height);X.style.height=`${Ht}px`;let yo=O.value.get(W)?.size??e.size,Rp=Math.max(yo.height,Ht+Er);if(Math.abs(Rp-yo.height)>8){if(ma(W,{width:yo.width,height:Rp}),s.current!==null)window.clearTimeout(s.current);s.current=window.setTimeout(()=>{ct({recordHistory:!1}),s.current=null},0)}}return{}},Le.onopenlink=async({url:ye})=>(window.open(ye,"_blank","noopener"),{}),Le.onsandboxready=async()=>{await Le.sendSandboxResourceReady({html:Fx(se,Dx()),sandbox:Qu,...te?.csp?{csp:te.csp}:{},...te?.permissions?{permissions:te.permissions}:{}})},Le.onrequestdisplaymode=async({mode:ye})=>{let{nextMode:rt,shouldExpand:Ht,shouldCollapse:yo}=OE(ye,On);if(Ht)Ut(W);else if(yo)En();return{mode:rt}},Le.oncalltool=async(ye)=>{if(!pe)throw Error(Kc);try{let rt=await Fo("/api/ext-app/call-tool",{sessionId:pe,nodeId:W,serverName:le,toolName:ye.name,arguments:ye.arguments??{}});return P(null),rt}catch(rt){let Ht=rt instanceof Error?rt.message:String(rt);throw P(`Tool call failed: ${Ht}`),rt}},Le.setRequestHandler(pc,async()=>{if(!pe)return{tools:[]};return Fo("/api/ext-app/list-tools",{sessionId:pe})}),Le.onlistresources=async()=>pe?Fo("/api/ext-app/list-resources",{sessionId:pe}):{resources:[]},Le.onlistresourcetemplates=async()=>pe?Fo("/api/ext-app/list-resource-templates",{sessionId:pe}):{resourceTemplates:[]},Le.onreadresource=async(ye)=>{if(!pe)throw Error(Kc);return Fo("/api/ext-app/read-resource",{sessionId:pe,uri:ye.uri})},Le.onlistprompts=async()=>pe?Fo("/api/ext-app/list-prompts",{sessionId:pe}):{prompts:[]},Le.onupdatemodelcontext=async(ye)=>{if(!pe)return{};return await Fo("/api/ext-app/model-context",{nodeId:W,...Array.isArray(ye.content)?{content:ye.content}:{},...ye.structuredContent&&typeof ye.structuredContent==="object"?{structuredContent:ye.structuredContent}:{}}),{}};let Qc=new Od(Fn,Fn);if(Le.oninitialized=()=>{if(oe)return;is(),d.current=!0,x.current=!0,lt(W,"initialized"),w("ready"),P(null),Promise.resolve(Le.sendHostContextChange(vo(On?"fullscreen":"inline"))).then(()=>Ox(Le,a.current,void 0)).then(()=>Yc(Le)).then(()=>{let ye=()=>{for(let rt of y.current.splice(0))rt()};if(typeof navigator<"u"&&Bo(navigator.userAgent))Ap(4000).then((rt)=>{lt(W,rt?"settled (content-verified)":`settled (content-timeout${v.current?`: ${v.current}`:""})`),ye()});else lt(W,"settled"),ye();zp(),Pp()}).catch((ye)=>{let rt=ye instanceof Error?ye.message:String(ye);P(`Bridge bootstrap failed: ${rt}`)})},we=setTimeout(()=>{if(oe||d.current)return;let ye=c.current,rt=vo(On?"fullscreen":"inline");d.current=!0,Le.setHostContext?.(rt),Promise.resolve(Le.sendHostContextChange(rt)).then(()=>Ox(Le,a.current,ye)).then(()=>{if(l.current=Boolean(ye),ye)u.current=ye;if(w(ye?"done":"ready"),P(null),zp(),Pp(),g.current){lt(W,"settled (fallback)");for(let Ht of y.current.splice(0))Ht()}}).catch((Ht)=>{let yo=Ht instanceof Error?Ht.message:String(Ht);P(`Bridge bootstrap fallback failed: ${yo}`)})},1200),await Le.connect(Qc),oe){is(),await Qc.close();return}if(o.current=Le,r.current=Qc,Bt=new ResizeObserver(ak),Bt.observe(X),X.parentElement)Bt.observe(X.parentElement);let Np=!0;m.current=nt.subscribe((ye)=>{if(Np){Np=!1;return}if(oe)return;Le.setHostContext?.({...vo(),theme:Jc(ye)}),Le.sendHostContextChange?.(vo())}),Yc(Le)})().catch((Fn)=>{is(),console.error("[ext-app] Bridge init failed:",Fn),P(Fn?.message??"Bridge initialization failed")}),()=>{if(oe=!0,is(),Me)clearTimeout(Me),Me=null;if(Bt?.disconnect(),Bt=null,Dn!==null)cancelAnimationFrame(Dn),Dn=null;if(go!==null)cancelAnimationFrame(go),go=null;if(d.current=!1,p.current=null,m.current?.(),m.current=null,s.current!==null)window.clearTimeout(s.current),s.current=null;if(o.current=null,r.current)r.current.close().catch((Fn)=>{console.error("[ext-app] transport close failed:",Fn)}),r.current=null}},[fe,Jt.key,ge]),B(()=>{if(Xt&&o.current&&(T==="ready"||T==="done"))Yc(o.current)},[Xt,T]),B(()=>{let X=o.current;if(n.current)n.current.style.height="100%";if(!X||!d.current)return;let oe=null,we=null;return oe=requestAnimationFrame(()=>{oe=null,we=requestAnimationFrame(()=>{if(we=null,!d.current)return;let Me={theme:Jc(nt.value),platform:"web",containerDimensions:jd(n.current,{width:e.size.width,height:ee}),displayMode:On?"fullscreen":"inline",locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};X.setHostContext?.(Me),X.sendHostContextChange?.(Me)})}),()=>{if(oe!==null)cancelAnimationFrame(oe);if(we!==null)cancelAnimationFrame(we)}},[On,ee]),!se)return i("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--c-muted)",fontSize:"13px",flexDirection:"column",gap:"8px"},children:[i("div",{style:{opacity:0.6},children:["Loading ",cn," viewer..."]},void 0,!0,void 0,this),i("div",{style:{width:"24px",height:"24px",border:"2px solid var(--c-line)",borderTopColor:"var(--c-muted)",borderRadius:"50%",animation:"spin 1s linear infinite"}},void 0,!1,void 0,this),i("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{style:{flex:1,width:"100%",height:"100%",minWidth:0,minHeight:0,display:"flex",flexDirection:"column"},children:[de&&de!=="ready"&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:de==="error"&&!rs?"var(--c-danger-12)":"var(--c-warn-10)",color:de==="error"&&!rs?"var(--c-danger)":"var(--c-warn)",borderBottom:`1px solid ${de==="error"&&!rs?"var(--c-danger-12)":"var(--c-warn-15)"}`},children:Kc},void 0,!1,void 0,this),_&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:"var(--c-danger-12)",color:"var(--c-danger)",borderBottom:"1px solid var(--c-danger-12)",display:"flex",alignItems:"center",gap:"6px"},children:[i("span",{children:"⚠"},void 0,!1,void 0,this),i("span",{style:{flex:1},children:_},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>{P(null),w("loading"),R((X)=>X+1)},style:{background:"var(--c-surface-hover)",border:"1px solid var(--c-danger-12)",borderRadius:"3px",color:"var(--c-danger)",cursor:"pointer",fontSize:"10px",padding:"1px 6px"},children:"Retry"},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>P(null),"aria-label":"Dismiss error",style:{background:"none",border:"none",color:"var(--c-danger)",cursor:"pointer",fontSize:"13px",padding:"0 2px"},children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{flex:1,position:"relative",display:"flex",minHeight:0,height:"100%"},children:[ge&&i("iframe",{ref:n,...Jt.attributes,sandbox:$e,allow:Ax(te?.permissions),style:{flex:1,width:"100%",height:"100%",minHeight:0,border:"none",background:"var(--c-panel)",pointerEvents:On?"auto":"none"},title:`Ext App: ${cn}`},fe,!1,void 0,this),k&&!_&&i("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"10px",background:"var(--c-panel)",color:"var(--c-warn)",fontSize:"12px"},children:[i("div",{children:"App surface failed to paint."},void 0,!1,void 0,this),i("button",{type:"button",onClick:(X)=>{X.stopPropagation(),lt(W,"manual-retry"),f.current=0,V(!1),w("loading"),R((oe)=>oe+1)},style:{background:"var(--c-surface-hover)",border:"1px solid var(--c-warn-15)",borderRadius:"4px",color:"var(--c-warn)",cursor:"pointer",fontSize:"11px",padding:"3px 10px"},children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(T==="loading"||Z)&&!_&&!k&&i("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"10px",background:"var(--c-panel)",color:"var(--c-muted)",fontSize:"12px",pointerEvents:"none"},children:[i("div",{style:{width:"22px",height:"22px",border:"2px solid var(--c-line)",borderTopColor:"var(--c-muted)",borderRadius:"50%",animation:"spin 1s linear infinite"}},void 0,!1,void 0,this),i("div",{children:T==="loading"?`Connecting to ${cn}...`:"Finishing paint..."},void 0,!1,void 0,this),i("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!On&&!(k&&!_)&&i("button",{type:"button",onClick:(X)=>{X.stopPropagation(),Ut(W)},class:"ext-app-preview-catcher",title:"Click to open",style:{position:"absolute",top:0,right:"56px",bottom:"56px",left:0,background:"transparent",border:"none",padding:0,margin:0,cursor:"zoom-in"},"aria-label":"Open full view to edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Zi=new Map,jx=!1;function Zx(e,t,n){if(!jx)jx=!0,zt(()=>{let s=O.value,a=To.value;for(let[c,l]of Zi){let u=s.get(c);if(!u||l.epoch!==a||l.version!==u.data.specVersion||l.documentUrl!==u.data.url)Zi.delete(c)}}),window.addEventListener("message",(s)=>{let a=s.data;if(!a||a.source!==Ku||a.type!=="snapshot"||typeof a.nodeId!=="string")return;let c=Zi.get(a.nodeId),l=c?.owners.findIndex((d)=>d.token===a.token&&d.source===s.source)??-1;if(!c||l<0)return;if(!a.state||typeof a.state!=="object"||Array.isArray(a.state))return;let{ax:u,...p}=a.state;c.state=p,c.owners=c.owners.slice(l)});let o=O.value.get(e);if(!o)return;let r=Zi.get(e);if(!r)r={epoch:To.value,version:o.data.specVersion,documentUrl:o.data.url,state:null,owners:[]},Zi.set(e,r);r.owners=[...r.owners.filter((s)=>s.source!==n).slice(-1),{token:t,source:n}],n.postMessage({source:Ku,type:"restore",token:t,state:r.state},"*")}function ZE(e,t,n,o,r,s,a,c){if(!e)return e;try{let l=new URL(e,window.location.origin);if(l.searchParams.set("theme",Nr(nt.value)),t)l.searchParams.set("display","expanded");if(typeof n==="number")l.searchParams.set("v",String(n));if(o)l.searchParams.set("axToken",o);if(r)l.searchParams.set("axNodeId",r);if(s)l.searchParams.set("frameToken",s);if(a)l.searchParams.set("fit","content");if(c)l.searchParams.set("stateToken",c);return l.toString()}catch{return e}}function UE(e,t=window.location.origin){if(!e)return!1;try{let n=new URL(t).origin,o=new URL(e,n);return o.origin===n&&o.pathname.startsWith("/api/canvas/frame-documents/")}catch{return!1}}function Zd({source:e,iframeRef:t,onLoad:n,onDocumentLoad:o,title:r,className:s="mcp-app-frame",sandbox:a="allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox",allow:c="clipboard-read; clipboard-write",tabIndex:l}){let u=e.src??e.srcdoc??"",[p,d]=I({key:u,source:e}),[m,f]=I(null),h=z(0);B(()=>{if(h.current+=1,!u||u===p.key){f(null);return}if(!p.key){d({key:u,source:e});return}f({key:u,source:e})},[u,p.key]),B(()=>()=>{h.current+=1},[]);let v=(x,g)=>i("iframe",{ref:g?void 0:t,...x.source,class:s,sandbox:a,allow:c,tabIndex:l,loading:kt.value==="srcdoc"?void 0:"lazy",onLoad:(y)=>{if(o?.(y.currentTarget),!g){n();return}let E=++h.current,D=y.currentTarget;requestAnimationFrame(()=>requestAnimationFrame(()=>{if(h.current!==E)return;t.current=D,d(x),f(null),n()}))},style:{position:"absolute",inset:0,width:"100%",height:"100%",visibility:g?"hidden":"visible",background:"var(--c-panel-soft)"},title:r},x.key,!1,void 0,this);return i("div",{class:"mcp-app-frame-stack",children:[v(p,!1),m&&v(m,!0)]},void 0,!0,void 0,this)}function ro({node:e,expanded:t=!1}){if(e.data.mode==="ext-app")return i(Hx,{node:e,expanded:t},void 0,!1,void 0,this);return i(qE,{node:e,expanded:t},void 0,!1,void 0,this)}function qE({node:e,expanded:t}){let n=z(null),o=e.type==="mcp-app"&&e.data.viewerType==="web-artifact",r=e.type==="json-render"||e.type==="graph",s=e.data.axCapabilities?.enabled,c=(r||o)&&(o?s===!0:s!==!1),l=o?"mcp-app":"json-render",u=Se(()=>c?`ax-${crypto.randomUUID()}`:"",[c]),p=cd(e)&&!t,d=Se(()=>p?`frame-${crypto.randomUUID()}`:"",[p]);Ar(e,n,d),Or({enabled:c&&Boolean(u),token:u,nodeId:e.id,sourceSurface:l,iframeRef:n});let m=on.value,f=()=>{if(!c||!u||m==null)return;n.current?.contentWindow?.postMessage({source:qt,type:"ax-update",token:u,state:m},"*")};B(f,[c,u,m]);let h=typeof e.data.specVersion==="number"?e.data.specVersion:void 0,v=Se(()=>r?`ui-${crypto.randomUUID()}`:"",[r,h,e.data.url]),x=ZE(e.data.url||"",t,h,u||void 0,c?e.id:void 0,d||void 0,p,v||void 0),g=zr(x),y=e.data.sourceServer||"",E=e.data.hostMode||"hosted",D=e.data.fallbackReason,N=e.data.trustedDomain===!0||UE(x);if(E==="fallback")return i("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[i("div",{style:{color:"var(--c-warn)",display:"flex",alignItems:"center",gap:"6px"},children:[i("span",{children:"⚠"},void 0,!1,void 0,this),i("span",{children:"Cannot embed — opened externally"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D&&i("div",{style:{color:"var(--c-muted)",fontSize:"11px"},children:["Reason: ",D]},void 0,!0,void 0,this),i("a",{href:x,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all"},children:x},void 0,!1,void 0,this),y&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px"},children:["Source: ",y]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return i("div",{style:{height:"100%",display:"flex",flexDirection:"column",...t?{flex:1,minHeight:0,width:"100%"}:{}},children:[!N&&i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-warn-10)",color:"var(--c-warn)",borderBottom:"1px solid var(--c-warn-15)"},children:"Unverified domain"},void 0,!1,void 0,this),i(Zd,{source:g,iframeRef:n,onDocumentLoad:(b)=>{if(v&&b.contentWindow)Zx(e.id,v,b.contentWindow)},onLoad:f,title:`MCP App: ${y}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var WE=null;function Fr(){WE=null}var Ux={idle:"var(--c-muted)",running:"var(--c-accent)",planning:"var(--c-thinking)",thinking:"var(--c-thinking)",drafting:"var(--c-accent)",tooling:"var(--c-accent)",review:"var(--c-ok)","waiting-approval":"var(--c-warn)",waiting:"var(--c-warn-alt)"};function VE(e){let t=typeof e.data.phase==="string"&&e.data.phase.trim().length>0?e.data.phase.trim():"";if(t)return t;let n=typeof e.data.content==="string"&&e.data.content.trim().length>0?e.data.content.trim():"";if(n)return n;return(typeof e.data.status==="string"&&e.data.status.trim().length>0?e.data.status.trim():"")||"idle"}function vc({node:e}){let t=VE(e),n=e.data.detail||"",o=e.data.message||"",r=e.data.level||"ok",s=e.data.activeTool,a=e.data.subagent,c=Ux[t]??"var(--c-muted)",l=t!=="idle";return i("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i("div",{style:{width:"8px",height:"8px",borderRadius:"50%",background:c,boxShadow:l?`0 0 8px ${c}`:"none",animation:l?"pulse 1.5s infinite":"none",flexShrink:0}},void 0,!1,void 0,this),i("span",{style:{fontWeight:600,color:c,textTransform:"uppercase",letterSpacing:"0.05em"},children:t},void 0,!1,void 0,this),n&&i("span",{style:{color:"var(--c-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-warn)"},children:[i("span",{style:{fontSize:"10px"},children:"⚙"},void 0,!1,void 0,this),i("span",{style:{fontFamily:"var(--mono)",fontSize:"11px"},children:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a&&a.state!=="completed"&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-subagent)"},children:[i("span",{style:{fontSize:"10px"},children:"⠉"},void 0,!1,void 0,this),i("span",{children:a.name},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-muted)",fontSize:"10px"},children:["(",a.state,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),o&&i("div",{style:{color:r==="warn"?"var(--c-warn)":r==="error"?"var(--c-danger)":"var(--c-muted)",lineHeight:1.4},children:o},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Br(e){return typeof e==="string"&&e.trim().length>0?e.trim():null}function qx(e){if(typeof e==="string"){let r=Br(e);return r?{title:"Evidence warning",detail:r}:null}if(!e||typeof e!=="object")return null;let t=e,n=Br(t.title)??"Evidence warning",o=Br(t.detail);return o?{title:n,detail:o}:null}function GE(e){let t=[],n=qx(e.data.warning);if(n)t.push(n);let o=e.data.warnings;if(Array.isArray(o))for(let s of o){let a=qx(s);if(a)t.push(a)}let r=Br(e.data.validationStatus)?.toLowerCase();if(r==="failed"||r==="invalid")t.push({title:"Image failed validation",detail:Br(e.data.validationMessage)??"Review this image before using it as evidence."});return t}function XE(e){let t=[e.data.title,e.data.caption,e.data.alt,e.data.src,e.data.path].map((n)=>Br(n)?.toLowerCase()??"").join(" ");if(t.length===0)return!1;return["login","log in","sign in","signin","password","2fa","mfa","authenticate","authentication","sso"].some((n)=>t.includes(n))}function Wx(e){let t=GE(e);if(t.length>0)return t;if(XE(e))return[{title:"Captured login page",detail:"This image looks like an auth screen. Treat it as environment context, not product evidence."}];return[]}function yc({node:e,expanded:t=!1}){let n=e.data.src||"",o=e.data.alt||e.data.title||"Image",r=e.data.caption||"",s=Wx(e),a=n.startsWith("data:")||n.startsWith("http://")||n.startsWith("https://")?n:`/api/canvas/image/${e.id}`,[c,l]=I(!1),[u,p]=I(!1),[d,m]=I(1),[f,h]=I({x:0,y:0}),[v,x]=I({w:0,h:0}),g=z(null),y=z(!1),E=z({x:0,y:0}),D=H((Z)=>{let j=Z.target;x({w:j.naturalWidth,h:j.naturalHeight}),l(!0),p(!1)},[]),N=H(()=>{p(!0),l(!1)},[]);B(()=>{m(1),h({x:0,y:0})},[n]);let b=H((Z)=>{Z.preventDefault(),Z.stopPropagation();let j=Z.deltaY>0?0.9:1.1;m((k)=>Math.max(0.25,Math.min(10,k*j)))},[]),T=H((Z)=>{if(d<=1)return;Z.stopPropagation(),y.current=!0,E.current={x:Z.clientX,y:Z.clientY},Z.target.setPointerCapture(Z.pointerId)},[d]),w=H((Z)=>{if(!y.current)return;let j=Z.clientX-E.current.x,k=Z.clientY-E.current.y;E.current={x:Z.clientX,y:Z.clientY},h((V)=>({x:V.x+j,y:V.y+k}))},[]),_=H(()=>{y.current=!1},[]),P=H(()=>{m(1),h({x:0,y:0})},[]);if(!n)return i("div",{class:"image-node-empty",children:[i("div",{class:"image-node-empty-icon",children:"\uD83D\uDDBC"},void 0,!1,void 0,this),i("div",{class:"image-node-empty-text",children:"No image source"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let q=v.w>0?`${v.w}×${v.h}`:"",R=Math.round(d*100);return i("div",{class:`image-node ${t?"image-node-expanded":""}`,ref:g,children:[s.length>0&&i("div",{class:"image-node-warning-stack",children:s.map((Z)=>i("div",{class:"image-node-warning",children:[i("span",{class:"image-node-warning-title",children:Z.title},void 0,!1,void 0,this),i("span",{class:"image-node-warning-detail",children:Z.detail},void 0,!1,void 0,this)]},`${Z.title}-${Z.detail}`,!0,void 0,this))},void 0,!1,void 0,this),i("div",{class:"image-node-viewport",onWheel:b,onPointerDown:T,onPointerMove:w,onPointerUp:_,style:{cursor:d>1?"grab":"default"},children:[!c&&!u&&i("div",{class:"image-node-loading",children:"Loading…"},void 0,!1,void 0,this),u&&i("div",{class:"image-node-error",children:[i("div",{class:"image-node-error-icon",children:"⚠"},void 0,!1,void 0,this),i("div",{children:"Failed to load image"},void 0,!1,void 0,this),i("div",{class:"image-node-error-path",children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("img",{src:a,alt:o,onLoad:D,onError:N,draggable:!1,style:{transform:`translate(${f.x}px, ${f.y}px) scale(${d})`,opacity:c?1:0,display:u?"none":"block"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(r||q||d!==1)&&i("div",{class:"image-node-footer",children:[r&&i("span",{class:"image-node-caption",children:r},void 0,!1,void 0,this),i("span",{class:"image-node-meta",children:[q&&i("span",{children:q},void 0,!1,void 0,this),d!==1&&i("button",{type:"button",class:"image-node-zoom-reset",onClick:P,title:"Reset zoom",children:[R,"% ",i(va,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Vx({node:e}){if((e.data.children??[]).filter((o)=>O.value.has(o)).length>0)return null;return i("div",{class:"group-empty-hint",children:"Drop nodes here — release while the frame lights up to add them"},void 0,!1,void 0,this)}function JE(e){try{return new URL(e).host}catch{return e}}function KE(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleString()}function bc({node:e,expanded:t=!1}){let n=typeof e.data.url==="string"?e.data.url:"",o=typeof e.data.pageTitle==="string"?e.data.pageTitle:"",r=typeof e.data.description==="string"?e.data.description:"",s=typeof e.data.excerpt==="string"?e.data.excerpt:typeof e.data.content==="string"?e.data.content:"",a=typeof e.data.status==="string"?e.data.status:"idle",c=typeof e.data.error==="string"?e.data.error:"",l=KE(typeof e.data.fetchedAt==="string"?e.data.fetchedAt:void 0),u=typeof e.data.statusCode==="number"?e.data.statusCode:null,p=typeof e.data.imageUrl==="string"?e.data.imageUrl:"",d=e.data.frameBlocked===!0,m=typeof e.data.frameBlockedReason==="string"?e.data.frameBlockedReason:"",[f,h]=I(!1),[v,x]=I(t);B(()=>{if(t)x(!0)},[t]);let g=H(async()=>{if(!n||f)return;h(!0);try{await oa(e.id)}finally{h(!1)}},[e.id,f,n]);if(!n)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No webpage URL set"},void 0,!1,void 0,this);let y=a==="ready"?"var(--c-ok)":a==="error"?"var(--c-danger)":"var(--c-warn)";return i("div",{style:{display:"flex",flexDirection:"column",gap:"12px",height:"100%"},children:[i("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[i("div",{style:{minWidth:0,flex:1},children:[i("div",{style:{fontSize:"12px",color:"var(--c-muted)"},children:JE(n)},void 0,!1,void 0,this),i("div",{style:{fontSize:t?"18px":"15px",fontWeight:700,color:"var(--c-text)"},children:o||e.data.title||n},void 0,!1,void 0,this),i("a",{href:n,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all",textDecoration:"none"},children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"999px",background:"rgba(255,255,255,0.04)",color:y,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.04em",flexShrink:0},children:[i("span",{style:{width:"7px",height:"7px",borderRadius:"999px",background:y}},void 0,!1,void 0,this),a]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),(r||p)&&i("div",{style:{display:"grid",gridTemplateColumns:p&&t?"160px 1fr":"1fr",gap:"12px",alignItems:"start"},children:[p&&t&&i("img",{src:p,alt:o||"Webpage preview image",style:{width:"160px",height:"96px",objectFit:"cover",borderRadius:"10px",border:"1px solid var(--c-line)",background:"var(--c-panel-soft)"}},void 0,!1,void 0,this),r&&i("p",{style:{margin:0,color:"var(--c-text-soft)",lineHeight:1.5,fontSize:t?"14px":"12px"},children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{display:"flex",gap:"8px",flexWrap:"wrap"},children:[i("button",{type:"button",onClick:g,disabled:f,style:{border:"1px solid var(--c-line)",background:"var(--c-panel-soft)",color:"var(--c-text)",borderRadius:"8px",padding:"6px 10px",cursor:f?"progress":"pointer",fontSize:"12px"},children:f||a==="fetching"?"Refreshing…":"Refresh"},void 0,!1,void 0,this),t&&!d&&i("button",{type:"button",onClick:()=>x((E)=>!E),style:{border:"1px solid var(--c-line)",background:"var(--c-panel-soft)",color:"var(--c-text)",borderRadius:"8px",padding:"6px 10px",cursor:"pointer",fontSize:"12px"},children:v?"Hide live preview":"Show live preview"},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>window.open(n,"_blank","noopener"),style:{border:"1px solid var(--c-line)",background:"transparent",color:"var(--c-accent)",borderRadius:"8px",padding:"6px 10px",cursor:"pointer",fontSize:"12px"},children:"Open in browser"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&d&&i("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[i("div",{style:{padding:"8px 12px",fontSize:"11px",color:"var(--c-muted)",borderBottom:"1px solid var(--c-line)",background:"rgba(255,255,255,0.03)"},children:"Live preview unavailable. This site refuses embedding, so PMX Canvas cannot show it inline."},void 0,!1,void 0,this),i("div",{style:{padding:"20px",color:"var(--c-text-soft)",lineHeight:1.6,fontSize:"13px"},children:m||"The remote site blocks iframe embedding."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&v&&!d&&i("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[i("div",{style:{padding:"8px 12px",fontSize:"11px",color:"var(--c-muted)",borderBottom:"1px solid var(--c-line)",background:"rgba(255,255,255,0.03)"},children:"Live preview (best effort). If this stays blank, the site likely blocks framing. The cached text snapshot below still works."},void 0,!1,void 0,this),i("iframe",{class:"webpage-node-iframe",title:o||e.data.title||n,src:n,loading:"lazy",referrerPolicy:"no-referrer",sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-presentation allow-scripts",style:{display:"block",width:"100%",height:t?"320px":"180px",border:"none",background:"#fff"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(l||u!==null)&&i("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap",color:"var(--c-muted)",fontSize:"11px"},children:[l&&i("span",{children:["Fetched ",l]},void 0,!0,void 0,this),u!==null&&i("span",{children:["HTTP ",u]},void 0,!0,void 0,this),d&&i("span",{children:"Preview blocked by site"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c&&i("div",{style:{color:"var(--c-danger)",fontSize:"12px",lineHeight:1.5},children:c},void 0,!1,void 0,this),i("div",{style:{flex:1,minHeight:0,overflow:"auto",border:"1px solid var(--c-line)",borderRadius:"10px",background:"var(--c-panel-soft)",padding:t?"14px":"10px"},children:s?i("div",{style:{whiteSpace:"pre-wrap",lineHeight:1.55,color:"var(--c-text)",fontSize:t?"14px":"12px"},children:s},void 0,!1,void 0,this):i("div",{style:{color:"var(--c-dim)",fontStyle:"italic"},children:a==="error"?"No cached page text available.":"Waiting for page text..."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Gx(e){return e.type==="html"&&e.data.presentation===!0}function Ui({node:e,expanded:t=!1,presentation:n=!1,presentationExitToken:o,autoFocus:r=!1}){let s=z(null),a=nt.value,c=Se(()=>`theme-${crypto.randomUUID()}`,[]),l=Se(()=>`ax-${crypto.randomUUID()}`,[]),u=Se(()=>`frame-${crypto.randomUUID()}`,[]),p=typeof e.data.html==="string"?e.data.html:typeof e.data.content==="string"?e.data.content:"",d=Se(()=>Sr(p),[p]),m=Se(()=>p?Ii(e.id,{theme:a,themeToken:c,present:n,presentToken:o,v:d,axToken:l,frameToken:u}):"",[p,n,o,c,d,e.id,l,u]),f=zr(m);Ar(e,s,t?"":u),Or({enabled:!0,token:l,nodeId:e.id,sourceSurface:"html-node",iframeRef:s}),B(()=>{if(s.current?.contentWindow?.postMessage({source:qt,type:"theme-update",token:c,theme:a},"*"),r)s.current?.focus()},[a,c]);let h=e.data.axCapabilities,v=h?.enabled===!0&&(!Array.isArray(h.allowed)||h.allowed.length>0),x=on.value;B(()=>{if(!v||x==null)return;s.current?.contentWindow?.postMessage({source:qt,type:"ax-update",token:l,state:x},"*")},[v,x,l]),B(()=>{if(!r)return;let y=window.setTimeout(()=>s.current?.focus(),0);return()=>window.clearTimeout(y)},[r,m]);let g=()=>{if(s.current?.contentWindow?.postMessage({source:qt,type:"theme-update",token:c,theme:a},"*"),v&&on.value!=null)s.current?.contentWindow?.postMessage({source:qt,type:"ax-update",token:l,state:on.value},"*");if(r)s.current?.focus()};if(!p)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No HTML content set"},void 0,!1,void 0,this);return i(Zd,{source:f,iframeRef:s,className:n?"html-node-frame html-node-frame-presentation":t?"html-node-frame html-node-frame-expanded":"html-node-frame",title:typeof e.data.title==="string"?e.data.title:"HTML node",sandbox:"allow-scripts",allow:"",tabIndex:r?0:void 0,onLoad:g},void 0,!1,void 0,this)}var Ud=null;async function Xx(){if(!Ud)Ud=await Rv();return Ud}function Jx(e,t){if(!e)return null;let n=e.toLowerCase(),o=t.find((s)=>s.name.toLowerCase()===n);if(o)return o.name;let r=t.filter((s)=>s.name.toLowerCase().startsWith(n));return r.length===1?r[0].name:null}function YE(e){return e.replace(/<script[\s>][\s\S]*?<\/script>/gi,"").replace(/<iframe[\s>][\s\S]*?<\/iframe>/gi,"").replace(/<object[\s>][\s\S]*?<\/object>/gi,"").replace(/<embed[\s>][\s\S]*?(?:\/>|<\/embed>)/gi,"").replace(/<link[\s>][\s\S]*?(?:\/>|<\/link>)/gi,"").replace(/\bon\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,"").replace(/href\s*=\s*"javascript:[^"]*"/gi,'href="#"').replace(/href\s*=\s*'javascript:[^']*'/gi,"href='#'")}function QE({html:e}){let t=z(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=e,n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function e1(e,t){return`${e.role}:${e.status??"none"}:${t}:${e.text}`}function Kx({count:e}){if(e===0)return null;return i("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--c-accent)",background:"rgba(70,182,255,0.08)",borderRadius:"var(--radius-sm)",flexShrink:0},children:["✦"," ",e," context node",e!==1?"s":""," attached"]},void 0,!0,void 0,this)}function Yx({message:e,onDismiss:t}){if(!e)return null;return i("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--c-danger)",background:"rgba(255,80,80,0.08)",borderRadius:"var(--radius-sm)",display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[i("span",{style:{flex:1},children:e},void 0,!1,void 0,this),i("button",{type:"button",onClick:t,"aria-label":"Dismiss error",style:{background:"none",border:"none",color:"var(--c-danger)",cursor:"pointer",fontSize:"13px",padding:"0 2px"},children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function xc({node:e,expanded:t=!1}){let n=Array.isArray(e.data.turns)?e.data.turns:[],o=n.length===0,r=e.data.text||"",s=e.data.status||"draft",a=o?s:e.data.threadStatus||"draft",c=a==="draft",l=a==="pending"||a==="sending",u=a==="streaming",p=a==="answered",[d,m]=I(""),[f,h]=I(""),[v,x]=I(null),[g,y]=I(new Map),E=z(null),D=z(null),N=n[n.length-1],b=`${n.length}:${N?.role??""}:${N?.status??""}:${Math.floor((N?.text?.length??0)/200)}`;B(()=>{if(t&&c&&E.current)E.current.focus()},[t,c]),B(()=>{if(!b)return;if(D.current)D.current.scrollTo({top:D.current.scrollHeight,behavior:"smooth"})},[b]);let T=z(null),w=z(n);w.current=n,B(()=>{let j=n.some((V)=>V.role==="assistant"&&V.status==="streaming"),k=()=>{let V=!1,Ue=w.current.map((se,le)=>({turn:se,index:le})).filter(({turn:se})=>se.role==="assistant"&&se.text);if(Ue.length===0)return;return Promise.all(Ue.map(async({turn:se,index:le})=>{let pe=await _n(se.text);return{index:le,html:YE(pe)}})).then((se)=>{if(V)return;let le=new Map;for(let pe of se)le.set(pe.index,pe.html);y(le)}),()=>{V=!0}};if(!j){if(T.current)clearTimeout(T.current),T.current=null;return k()}if(T.current)clearTimeout(T.current);return T.current=setTimeout(()=>{T.current=null,k()},400),()=>{if(T.current)clearTimeout(T.current),T.current=null}},[n]);let _=H(async()=>{let j=d.trim();if(!j)return;let k=d;x(null),ie(e.id,{turns:[{role:"user",text:j,status:"pending"}],threadStatus:"pending",text:j}),m("");let V=Array.isArray(e.data.contextNodeIds)?e.data.contextNodeIds:void 0;if(!(await vi(j,e.position,e.id,V,e.id)).ok)ie(e.id,{turns:[],threadStatus:"draft",text:"",status:"draft"}),m(k),x("Failed to send prompt. Your draft has been restored.")},[d,e.id,e.position,e.data.contextNodeIds]),P=H(async()=>{let j=f.trim();if(!j)return;let k=f;x(null);let V=Array.isArray(e.data.turns)?[...e.data.turns]:[];if(V.push({role:"user",text:j,status:"pending"}),ie(e.id,{turns:V,threadStatus:"pending"}),h(""),!(await $v(e.id,j)).ok)V.pop(),ie(e.id,{turns:V,threadStatus:"answered"}),h(k),x("Failed to send reply. Your draft has been restored.")},[f,e.id,e.data.turns]),q=H((j)=>{if(j.key==="Enter"&&(j.metaKey||j.ctrlKey)){j.preventDefault(),_();return}if(j.key==="Tab"&&d.startsWith("/")){j.preventDefault();let k=d.slice(1).split(/\s/)[0];if(k)Xx().then((V)=>{let ge=Jx(k,V);if(ge)m(`/${ge}`)})}},[_,d]),R=H((j)=>{if(j.key==="Enter"&&(j.metaKey||j.ctrlKey)){j.preventDefault(),P();return}if(j.key==="Tab"&&f.startsWith("/")){j.preventDefault();let k=f.slice(1).split(/\s/)[0];if(k)Xx().then((V)=>{let ge=Jx(k,V);if(ge)h(`/${ge}`)})}},[P,f]),Z=Array.isArray(e.data.contextNodeIds)?e.data.contextNodeIds.length:0;if(c&&n.length===0)return i("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%",gap:"8px"},children:[i(Kx,{count:Z},void 0,!1,void 0,this),i(Yx,{message:v,onDismiss:()=>x(null)},void 0,!1,void 0,this),i("textarea",{ref:E,value:d,onInput:(j)=>m(j.target.value),onKeyDown:q,placeholder:"Ask the agent something…",spellcheck:!1,style:{flex:1,resize:"none",background:"rgba(10,14,30,0.4)",border:"1px solid var(--c-line)",borderRadius:"var(--radius-sm)",color:"var(--c-text)",fontFamily:"var(--font)",fontSize:"13px",lineHeight:"1.5",padding:"8px 10px",outline:"none"}},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter to send"]},void 0,!0,void 0,this),i("button",{type:"button",onClick:_,disabled:!d.trim(),style:{padding:"5px 14px",fontSize:"12px",fontWeight:600,background:d.trim()?"var(--c-accent)":"var(--c-line)",color:d.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:d.trim()?"pointer":"default"},children:"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(o)return i("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[i("div",{style:{flex:1,padding:"2px 0",fontSize:"13px",lineHeight:"1.55",color:"var(--c-text)",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto"},children:r},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:"6px",borderTop:"1px solid var(--c-line)",marginTop:"4px"},children:i("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:l?"var(--c-warn)":p?"var(--c-ok)":"var(--c-muted)"},children:l?"Sending…":p?"Answered":s},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[i(Kx,{count:Z},void 0,!1,void 0,this),i(Yx,{message:v,onDismiss:()=>x(null)},void 0,!1,void 0,this),i("div",{ref:D,style:{flex:1,overflow:"auto",minHeight:0},children:n.map((j,k)=>i("div",{children:[k>0&&i("div",{class:"thread-turn-divider"},void 0,!1,void 0,this),j.role==="user"?i("div",{class:"thread-turn-user",children:[i("div",{class:"thread-turn-role",children:[i("span",{class:"status-dot"},void 0,!1,void 0,this),"You"]},void 0,!0,void 0,this),i("div",{style:{fontSize:t?"15px":"13px",lineHeight:t?"1.7":"1.55",color:"var(--c-text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:j.text},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i("div",{class:"thread-turn-assistant",children:[i("div",{class:"thread-turn-role",children:[i("span",{class:`status-dot${j.status==="streaming"?" pulsing":""}`},void 0,!1,void 0,this),"PMX"]},void 0,!0,void 0,this),j.status==="streaming"&&!j.text&&i("div",{style:{height:"2px",background:"linear-gradient(90deg, transparent, var(--c-ok), transparent)",animation:"response-stream-pulse 1.5s ease-in-out infinite",borderRadius:"1px",marginBottom:"4px"}},void 0,!1,void 0,this),i("div",{class:t?"md-reader-content":void 0,style:{fontSize:t?void 0:"13px",lineHeight:t?void 0:"1.55",opacity:j.text?1:0.4},children:g.get(k)?i(ue,{children:[i(QE,{html:g.get(k)??""},void 0,!1,void 0,this),j.status==="streaming"&&i("span",{class:"streaming-cursor"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i("div",{style:{color:"var(--c-muted)",fontStyle:"italic"},children:j.status==="streaming"?"Waiting for response…":j.text||"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},e1(j,k),!0,void 0,this))},void 0,!1,void 0,this),i("div",{style:{flexShrink:0,borderTop:"1px solid var(--c-line)",marginTop:"4px",paddingTop:"6px"},children:[i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:p?"6px":0},children:[i("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:u?"var(--c-accent)":l?"var(--c-warn)":p?"var(--c-ok)":"var(--c-muted)"},children:u?"Streaming…":l?"Sending…":p?"Answered":a},void 0,!1,void 0,this),i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:[n.length," turn",n.length!==1?"s":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),p&&i("div",{class:"thread-reply-area",children:[i("textarea",{value:f,onInput:(j)=>h(j.target.value),onKeyDown:R,placeholder:"Reply…",spellcheck:!1,rows:2,style:{width:"100%",resize:"none",background:"rgba(10,14,30,0.4)",border:"1px solid var(--c-line)",borderRadius:"var(--radius-sm)",color:"var(--c-text)",fontFamily:"var(--font)",fontSize:"12px",lineHeight:"1.5",padding:"6px 8px",outline:"none"}},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"4px"},children:[i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter"]},void 0,!0,void 0,this),i("button",{type:"button",onClick:P,disabled:!f.trim(),style:{padding:"3px 10px",fontSize:"11px",fontWeight:600,background:f.trim()?"var(--c-accent)":"var(--c-line)",color:f.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:f.trim()?"pointer":"default"},children:"Reply"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function t1(e){return e.replace(/<script[\s>][\s\S]*?<\/script>/gi,"").replace(/<iframe[\s>][\s\S]*?<\/iframe>/gi,"").replace(/<object[\s>][\s\S]*?<\/object>/gi,"").replace(/<embed[\s>][\s\S]*?(?:\/>|<\/embed>)/gi,"").replace(/<link[\s>][\s\S]*?(?:\/>|<\/link>)/gi,"").replace(/\bon\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,"").replace(/href\s*=\s*"javascript:[^"]*"/gi,'href="#"').replace(/href\s*=\s*'javascript:[^']*'/gi,"href='#'")}function n1({html:e}){let t=z(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=e,n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function wc({node:e,expanded:t=!1}){let n=e.data.content||"",o=e.data.status||"streaming",[r,s]=I(""),a=o==="streaming",c=o==="complete";B(()=>{if(!n){s("");return}let u=!1;return _n(n).then((p)=>{if(!u)s(t1(p))}),()=>{u=!0}},[n]);let l=H(()=>{vi("",{x:e.position.x,y:e.position.y+e.size.height+24},e.id)},[e]);return i("div",{class:"response-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[a&&i("div",{class:"response-streaming-bar",style:{height:"2px",background:"linear-gradient(90deg, transparent, var(--c-accent), transparent)",animation:"response-stream-pulse 1.5s ease-in-out infinite",borderRadius:"1px",marginBottom:"4px",flexShrink:0}},void 0,!1,void 0,this),i("div",{class:t?"md-reader":void 0,style:{flex:1,overflow:"auto",minHeight:0,opacity:n?1:0.4,transition:"opacity 0.2s ease"},children:r?i("div",{class:t?"md-reader-content":void 0,children:i(n1,{html:r},void 0,!1,void 0,this)},void 0,!1,void 0,this):i("div",{style:{color:"var(--c-muted)",fontStyle:"italic",fontSize:"13px"},children:a?"Waiting for response…":"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:"6px",borderTop:"1px solid var(--c-line)",marginTop:"4px",flexShrink:0},children:[i("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:a?"var(--c-accent)":c?"var(--c-ok)":"var(--c-muted)"},children:a?"Streaming…":c?"Complete":o},void 0,!1,void 0,this),c&&i("button",{type:"button",onClick:l,style:{padding:"3px 10px",fontSize:"11px",background:"rgba(70,182,255,0.1)",border:"1px solid rgba(70,182,255,0.3)",borderRadius:"var(--radius-sm)",color:"var(--c-accent)",cursor:"pointer"},children:"Reply"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Qx(e){return{toolName:e.toolName||e.title||"unknown",category:e.category||"other",status:e.status||"running",duration:e.duration||"",resultSummary:e.resultSummary||e.content||"",error:e.error||""}}var ew={mcp:"var(--c-accent)",file:"var(--c-warn)",subagent:"var(--c-purple)",other:"var(--c-muted)"},o1={running:"⠋",success:"✓",failed:"✕"},r1={running:"var(--c-accent)",success:"var(--c-ok)",failed:"var(--c-danger)"};function _c({node:e}){let{toolName:t,category:n,status:o,duration:r,resultSummary:s,error:a}=Qx(e.data),c=ew[n]??ew.other,l=o1[o]??"◌",u=r1[o]??"var(--c-muted)",p=o==="running",d=a?a.slice(0,30):s.length>30?`${s.slice(0,28)}…`:s;return i("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"0 12px",height:"100%",overflow:"hidden"},children:[i("span",{style:{fontSize:"14px",color:u,flexShrink:0,animation:p?"pulse 1.5s infinite":"none"},children:l},void 0,!1,void 0,this),i("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:[i("div",{style:{fontFamily:"var(--mono)",fontSize:"11px",fontWeight:600,color:c,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t},void 0,!1,void 0,this),d&&i("div",{style:{fontSize:"10px",color:a?"var(--c-danger)":"var(--c-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:1.3},children:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r&&i("span",{style:{fontSize:"9px",padding:"1px 5px",borderRadius:"3px",background:"rgba(255,255,255,0.06)",color:"var(--c-muted)",flexShrink:0,whiteSpace:"nowrap"},children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Wd(e){let t=O.value.get(e);if(!t)return null;return{left:t.position.x,top:t.position.y,width:t.size.width,height:t.size.height}}function i1(e){let t=e.map((l)=>Wd(l)).filter((l)=>l!==null);if(t.length===0)return null;let n=Math.min(...t.map((l)=>l.left)),o=Math.min(...t.map((l)=>l.top)),r=Math.max(...t.map((l)=>l.left+l.width)),s=Math.max(...t.map((l)=>l.top+l.height)),a=54,c=46;return{left:n-a,top:o-c,width:r-n+a*2,height:s-o+c*2}}function qd(e,t){return{left:`${e.left}px`,top:`${e.top}px`,width:`${e.width}px`,height:`${e.height}px`,borderRadius:`${t}px`}}function tw(){let e=Array.from(ir.value),t=Array.from(sr.value),n=Vs.value;if(e.length===0&&t.length===0)return null;let o=[...O.value.values()],r=o.length>0?(Math.max(...o.map((s)=>s.position.x+s.size.width))-Math.min(...o.map((s)=>s.position.x)))*(Math.max(...o.map((s)=>s.position.y+s.size.height))-Math.min(...o.map((s)=>s.position.y))):0;return i("div",{class:"attention-field-layer","aria-hidden":"true",children:[n.map((s)=>{let a=i1(s.nodeIds);if(!a)return null;if(r>0&&a.width*a.height>=r*0.75)return null;return i("div",{class:"attention-field-region",style:qd(a,42)},s.id,!1,void 0,this)}),t.map((s)=>{let a=Wd(s);if(!a)return null;return i("div",{class:"attention-field-node attention-field-secondary",style:qd({left:a.left-18,top:a.top-18,width:a.width+36,height:a.height+36},28)},`secondary-${s}`,!1,void 0,this)}),e.map((s)=>{let a=Wd(s);if(!a)return null;return i("div",{class:"attention-field-node attention-field-primary",style:qd({left:a.left-24,top:a.top-24,width:a.width+48,height:a.height+48},30)},`primary-${s}`,!1,void 0,this)})]},void 0,!0,void 0,this)}var s1=new Set(["png","jpg","jpeg","gif","svg","webp","bmp","ico","avif"]),a1=new Set(["md","mdx","markdown"]);function c1(e){let t=e.split(".").pop()?.toLowerCase()??"";if(s1.has(t))return"image";if(a1.has(t))return"markdown";return"file"}async function Hr(e,t,n){let o=Ne.value,r=400,s=300,a=20,c=Math.ceil(Math.sqrt(e.length));for(let l=0;l<e.length;l++){let u=e[l],p=l%c,d=Math.floor(l/c),m=t-c*420/2+p*420,f=n-150+d*320,h=c1(u.name),v=u.name;if(/\.(pdf|pptx?|xlsx?|docx?|od[pts])$/i.test(v)){if(!o||u.size===0||u.size>20971520){pn("remove","File not attached","Open a board and choose a nonempty file under 20 MiB.");continue}let x=new URLSearchParams({boardId:o,name:v,mime:u.type,x:String(m),y:String(f)});pn("context","Attaching document",v),await Y("attachDocument",`/api/canvas/attachments?${x}`,null,{method:"POST",body:u});continue}if(Ne.value!==o)return;if(h==="image"){let x=new FileReader,g=await new Promise((y)=>{x.onload=()=>y(x.result),x.readAsDataURL(u)});if(Ne.value!==o)return;await tn({type:"image",title:v,content:g,x:m,y:f,width:400,height:300,...o?{boardId:o}:{}})}else{let x=await u.text();if(Ne.value!==o)return;let g=h==="markdown"||h==="file";await tn({type:h,title:v,content:x,x:m,y:f,width:g?720:400,height:g?500:300,...o?{boardId:o}:{}})}}}var nw={width:260,height:150},l1={markdown:{width:300,height:170},status:{width:280,height:110},context:{width:300,height:200},trace:{width:220,height:64},file:{width:300,height:190},image:{width:260,height:200},webpage:{width:320,height:210},html:{width:320,height:210},group:{width:340,height:210},graph:{width:320,height:210},"json-render":{width:320,height:210},"mcp-app":{width:340,height:230}};function Gd(e){return!!e&&e in dt}function Nn(e){if(!e)return null;let t=O.value.get(e);if(!t)return null;return{left:t.position.x,top:t.position.y,width:t.size.width,height:t.size.height}}function Vd(e){return{x:e.left+e.width/2,y:e.top+e.height/2}}function qi(e){let t=typeof e.confidence!=="number"?0.82:0.4+Math.max(0,Math.min(1,e.confidence))*0.55;return e.auto?t*0.62:t}function ow(e,t){let n=Math.max(40,Math.abs(t.x-e.x)/2);return`M ${e.x} ${e.y} C ${e.x+n} ${e.y}, ${t.x-n} ${t.y}, ${t.x} ${t.y}`}function Xd({intent:e}){let t=Gd(e.nodeType)?sn(e.nodeType):null,n=e.label||e.kind,o=typeof e.confidence==="number"?`${Math.round(e.confidence*100)}%`:null;return i("div",{class:"intent-info",onMouseEnter:()=>Tr.value=e.id,onMouseLeave:()=>{if(Tr.value===e.id)Tr.value=null},children:[i("div",{class:"intent-chip",children:[typeof e.seq==="number"&&i("span",{class:"intent-seq",children:e.seq},void 0,!1,void 0,this),t&&i("span",{class:"intent-chip-icon","aria-hidden":"true",children:i(t,{size:12},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"intent-chip-label",children:n},void 0,!1,void 0,this),o&&i("span",{class:"intent-confidence",children:o},void 0,!1,void 0,this),e.phase==="forming"&&!e.auto&&i("button",{type:"button",class:"intent-veto",title:"Veto this move (Esc)","aria-label":"Veto this move",onClick:(r)=>{r.stopPropagation(),Io(e)},children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.reason&&i("div",{class:"intent-reason",children:e.reason},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function rw({intent:e,rect:t}){let n=Gd(e.nodeType)?sn(e.nodeType):null,o=Gd(e.nodeType)?dt[e.nodeType]:"Node";return i("div",{class:`intent-ghost intent-ghost-box is-${e.phase}${e.auto?" is-auto":""}`,"data-intent-id":e.id,style:{left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`,opacity:qi(e)},children:[i("div",{class:"intent-ghost-titlebar",children:[i("span",{class:"intent-ghost-icon","aria-hidden":"true",children:n?i(n,{size:13},void 0,!1,void 0,this):"◇"},void 0,!1,void 0,this),i("span",{class:"intent-ghost-badge",children:o},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Xd,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function iw({intent:e,rect:t,variant:n}){return i("div",{class:`intent-ghost intent-ghost-${n} is-${e.phase}${e.auto?" is-auto":""}`,"data-intent-id":e.id,style:{left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`,opacity:qi(e)},children:[n==="edit"&&i("div",{class:"intent-edit-bar"},void 0,!1,void 0,this),i(Xd,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function u1(e){let t=e.phase==="settling"?Nn(e.settledNodeId):null;switch(e.kind){case"create":{if(!e.position)return null;let n=e.nodeType&&l1[e.nodeType]||nw,o=t??{left:e.position.x,top:e.position.y,...n};return i(rw,{intent:e,rect:o},e.id,!1,void 0,this)}case"move":{if(!e.position)return null;let o=Nn(e.nodeId)??nw,r=t??{left:e.position.x,top:e.position.y,width:o.width,height:o.height};return i(rw,{intent:e,rect:r},e.id,!1,void 0,this)}case"remove":{let n=t??Nn(e.nodeId);if(!n)return null;return i(iw,{intent:e,rect:n,variant:"remove"},e.id,!1,void 0,this)}case"edit":{let n=t??Nn(e.nodeId);if(!n)return null;return i(iw,{intent:e,rect:n,variant:"edit"},e.id,!1,void 0,this)}case"connect":{if(!e.edge)return null;let n=Nn(e.edge.from),o=Nn(e.edge.to);if(!n||!o)return null;let r={x:(n.left+n.width/2+o.left+o.width/2)/2,y:(n.top+n.height/2+o.top+o.height/2)/2},s={left:r.x-110,top:r.y-18,width:220,height:36};return i("div",{class:`intent-ghost intent-ghost-connect is-${e.phase}${e.auto?" is-auto":""}`,"data-intent-id":e.id,style:{left:`${s.left}px`,top:`${s.top}px`,width:`${s.width}px`,opacity:qi(e)},children:i(Xd,{intent:e},void 0,!1,void 0,this)},e.id,!1,void 0,this)}default:return null}}function sw(){let e=Array.from(Xe.value.values());if(B(()=>{function t(n){if(n.key!=="Escape")return;let o=Tr.value;if(!o)return;let r=Xe.value.get(o);if(!r||r.phase!=="forming")return;n.stopImmediatePropagation(),n.preventDefault(),Io(r)}return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[]),e.length===0)return null;return i("div",{class:"intent-layer",onAnimationEnd:(t)=>{if(t.animationName!=="intent-settle"&&t.animationName!=="intent-dissolve")return;let n=t.target.dataset.intentId;if(n&&Xe.value.get(n)?.phase!=="forming")Mo(n)},children:[i("svg",{class:"intent-line-layer",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},children:[i("defs",{children:i("marker",{id:"intent-arrow",markerWidth:"8",markerHeight:"8",refX:"6",refY:"3",orient:"auto",children:i("path",{d:"M0,0 L6,3 L0,6 Z",class:"intent-arrow-head"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),e.map((t)=>{if(t.kind==="connect"&&t.edge){let n=Nn(t.edge.from),o=Nn(t.edge.to);if(!n||!o)return null;return i("path",{d:ow(Vd(n),Vd(o)),class:`intent-edge type-${t.edge.type}`,style:{opacity:qi(t)}},`line-${t.id}`,!1,void 0,this)}if(t.kind==="move"&&t.position){let n=Nn(t.nodeId);if(!n)return null;let o=n,r={x:t.position.x+o.width/2,y:t.position.y+o.height/2};return i("path",{d:ow(Vd(n),r),class:"intent-trail",markerEnd:"url(#intent-arrow)",style:{opacity:qi(t)}},`line-${t.id}`,!1,void 0,this)}return null})]},void 0,!0,void 0,this),e.map(u1)]},void 0,!0,void 0,this)}var aw=32000;var kc="Agent session";function cw(e){return e.some((t)=>t.attached)}function lw(e){return e.filter((t)=>!t.attached)}function io(e){switch(e.phase){case"thinking":return"Thinking";case"tooling":return e.detail?`Running ${e.detail}`:"Working";case"waiting-approval":return"Waiting on you";default:return"Idle"}}function so(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return(t%360+360)%360}var yt=U([]),Kd=U({used:0,total:aw}),ao=U([]),Ho=U(!1),jr=U(!1),Yd=U(null),uw=["var(--c-purple)","var(--c-accent)","var(--c-ok)","var(--c-warn)","var(--c-danger)"],Jd=new Map;function Sc(e){let t=Jd.get(e);if(t)return t;let n=uw[Jd.size%uw.length];return Jd.set(e,n),n}function dw(e){return(e.trim().replace(/^[^a-z0-9]+/i,"").charAt(0)||e.trim().charAt(0)||"?").toUpperCase()}function Cc(e,t=Date.now()){let n=t-Date.parse(e);if(!Number.isFinite(n)||n<5000)return"now";if(n<60000)return`${Math.floor(n/1000)}s`;if(n<3600000)return`${Math.floor(n/60000)}m`;return`${Math.floor(n/3600000)}h`}var bt=De(()=>cw(yt.value)),Qd=De(()=>lw(yt.value)),pw=De(()=>{let e=new Set;return[...yt.value].filter((t)=>t.label!==kc).sort((t,n)=>Number(n.attached)-Number(t.attached)).map((t)=>({value:t.sessionId==="browser"?t.label:t.sessionId,label:t.label,attached:t.attached,steerable:t.attached||t.steerable===!0,pendingSteers:t.pendingSteers??0,polling:t.lastClaimAt!==void 0&&Date.now()-Date.parse(t.lastClaimAt)<300000})).filter((t)=>e.has(t.value)?!1:(e.add(t.value),!0))}),mw=De(()=>yt.value.filter((e)=>e.attached)),Zr=De(()=>yt.value.find((e)=>e.attached)??null);function d1(e){let t=new Set;for(let n of e)if(n.nodeId&&n.kind!=="create")t.add(n.nodeId);return t}var fw=De(()=>d1(Xe.value.values()));function Tc(e,t){if(e.cursor)return{x:e.cursor.x,y:e.cursor.y};if(!e.focusNodeId)return null;let n=t(e.focusNodeId);if(!n)return null;return{x:n.position.x+Math.max(24,n.size.width-28),y:n.position.y+16}}function ep(e){if(!e)return;if(Array.isArray(e.presences))yt.value=e.presences;if(e.budget&&Number.isFinite(e.budget.used)&&Number.isFinite(e.budget.total))Kd.value={used:e.budget.used,total:e.budget.total};if(Array.isArray(e.activity))ao.value=e.activity}function hw(){let e=z(new Map),t=K.value.scale,n=O.value,o=1/Math.max(0.05,t),r=yt.value.map((s)=>{let a=Tc(s,(l)=>n.get(l));if(a)e.current.set(s.sessionId,a);let c=a??e.current.get(s.sessionId)??null;return c?{presence:s,position:c}:null}).filter((s)=>s!==null);if(r.length===0)return null;return i("div",{class:"agent-presence-layer","aria-hidden":"true",children:r.map(({presence:s,position:a})=>i("div",{class:`agent-cursor phase-${s.phase}${s.cursor?" has-explicit-cursor":""}${s.attached?"":" is-external"}${s.parentAgentId?" is-worker":""}`,"data-session-id":s.sessionId,style:{transform:`translate(${a.x}px, ${a.y}px)`,"--identity-color":`hsl(${so(s.sessionId)} 65% 62%)`},children:i("div",{class:"agent-cursor-inner",style:{transform:`scale(${o})`},children:[i("svg",{class:"agent-cursor-glyph",width:"16",height:"18",viewBox:"0 0 16 18","aria-hidden":"true",children:i("path",{d:"M1.5 1.5L14.5 9.2 8.3 10.6 5.2 16.5z",fill:"currentColor",stroke:"var(--c-bg)","stroke-width":"1.2"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"agent-cursor-chip",children:[i("span",{class:"agent-cursor-dot"},void 0,!1,void 0,this),i("span",{class:"agent-cursor-label",children:io(s)},void 0,!1,void 0,this),i("span",{class:"agent-cursor-who",children:s.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},s.sessionId,!1,void 0,this))},void 0,!1,void 0,this)}function Rn(e=1000){let[t,n]=I(()=>Date.now());return B(()=>{if(e<=0)return;n(Date.now());let o=window.setInterval(()=>n(Date.now()),e);return()=>window.clearInterval(o)},[e]),t}function gw(){let e=Rn(zi.value.length>0?5000:0),t=zi.value.filter((o)=>o.cursor!==null&&(!o.lastSeenAt||e-Date.parse(o.lastSeenAt)<qb+5000));if(t.length===0)return null;let n=1/Math.max(0.05,K.value.scale);return i("div",{class:"human-presence-layer","aria-hidden":"true",children:t.map((o)=>i("div",{class:`human-cursor${o.grabbingNodeId?" is-grabbing":""}`,"data-client-id":o.clientId,style:{transform:`translate(${o.cursor.x}px, ${o.cursor.y}px)`},children:i("div",{class:"human-cursor-inner",style:{transform:`scale(${n})`},children:[i("svg",{class:"human-cursor-glyph",width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",children:i("path",{d:"M3 2 L13 8 L8.5 9.5 L6.5 14 Z",fill:"currentColor",stroke:"var(--c-bg)","stroke-width":"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"human-cursor-tag",children:o.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},o.clientId,!1,void 0,this))},void 0,!1,void 0,this)}function Ic(e,t){let{POSITIVE_INFINITY:n,POSITIVE_INFINITY:o,NEGATIVE_INFINITY:r,NEGATIVE_INFINITY:s}=Number,a=0;for(let c of e)a+=1,n=Math.min(n,c.position.x),o=Math.min(o,c.position.y),r=Math.max(r,c.position.x+c.size.width),s=Math.max(s,c.position.y+c.size.height);if(a===0)return null;return{x:n-t,y:o-t,width:r-n+t*2,height:s-o+t*2}}function np(){let e=on.value;return e&&typeof e==="object"?e:{}}var vw=De(()=>np().workItems??[]),op=De(()=>np().approvalGates??[]),jo=De(()=>op.value.filter((e)=>e.status==="pending")),co=De(()=>{let e=np().policy?.scope;return e&&Array.isArray(e.nodeIds)&&e.nodeIds.length>0?{nodeIds:e.nodeIds,padding:typeof e.padding==="number"?e.padding:40}:null});async function yw(e){return(await Lt("setScopeFence","/api/canvas/ax/policy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:e&&e.length>0?{nodeIds:e}:null,source:"browser"})})).ok}var bw=De(()=>op.value.filter((e)=>e.status==="held")),xw=De(()=>op.value.filter((e)=>e.status==="approved"||e.status==="rejected")),ww=U({events:[],evidence:[],steering:[]}),Zo=U("all");function rp(e){if(e==="update")return"update";if(e==="steer"||e==="steering"||e==="yield")return"steer";if(e==="assistant-message")return"assistant";if(e==="evidence")return"evidence";return"event"}var p1=new Set(["api","mcp","sdk","cli"]);function tp(e,t){if(e?.trim())return e.trim();let n=t?.trim();if(n&&!p1.has(n))return n;return null}var m1=/^(node|edge|group|annotation|jsonrender|graph|render)\.|^arrange$|^canvas\.clear$|^snapshot\.restore$/,_w=U(null),Wi=U(new Set),f1={prompt:"Prompt","assistant-message":"Assistant","tool-start":"Tool run","tool-result":"Tool result",failure:"Failure",approval:"Approval",steering:"Steering",command:"Command",note:"Note",policy:"Policy",yield:"Yield"};function h1(e,t=40,n=[],o=null,r="all"){let s=n.find((l)=>m1.test(l.op)),a=[...n.map((l)=>({id:`update-${l.id}`,kind:"update",label:"Update",body:l.summary,createdAt:l.at,who:l.sessionId??null,...o?.actor==="agent"&&s?.id===l.id?{undoable:!0}:{}})),...e.events.map((l)=>({id:`event-${l.id}`,kind:l.kind,label:f1[l.kind]??l.kind,body:l.detail?`${l.summary} — ${l.detail}`:l.summary,createdAt:l.createdAt,who:tp(l.agentId,l.source)})),...e.evidence.map((l)=>({id:`evidence-${l.id}`,kind:"evidence",label:"Evidence",body:l.body?`${l.title} — ${l.body}`:l.title,createdAt:l.createdAt,who:tp(l.agentId,l.source)})),...e.steering.map((l)=>{let u=l.agentId??(l.source&&l.source!=="browser"?l.source:null),p=l.target?`→ ${l.target} · `:u?"→ all · ":"",d=l.target&&l.delivered===!1?` — waiting for ${l.target} to pick it up`:"";return{id:`steer-${l.id}`,kind:"steer",label:"Steer",body:`${u?`${u} `:""}${p}${l.message}${d}`,createdAt:l.createdAt,who:tp(l.agentId,l.source)}})],c=r==="all"?a:a.filter((l)=>rp(l.kind)===r);return c.sort((l,u)=>l.createdAt<u.createdAt?1:l.createdAt>u.createdAt?-1:0),c.slice(0,t)}var kw=De(()=>h1(ww.value,40,ao.value,_w.value,Zo.value));async function lo(){let[e,t]=await Promise.all([Y("refreshTimeline","/api/canvas/ax/timeline?limit=40",null),Y("refreshHistoryTop","/api/canvas/history",null)]);if(t)_w.value=t.top??null;if(!e)return;ww.value={events:Array.isArray(e.events)?e.events:[],evidence:Array.isArray(e.evidence)?e.evidence:[],steering:Array.isArray(e.steering)?e.steering:[]}}async function ip(e){if(!(await Lt("undoAgentEdit","/api/canvas/undo",{method:"POST"})).ok)return!1;return Wi.value=new Set([...Wi.value,e.id]),await en("undoAgentEditSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:`Undid your edit: ${e.body} — it was reverted on the board.`,source:"browser"})}),lo(),!0}async function sp(e=!1){let t=await Lt(e?"redo":"undo",e?"/api/canvas/redo":"/api/canvas/undo",{method:"POST"});if(t.ok)lo();return t.ok}async function Sw(e,t){if(!(await Lt("resolveGate",`/api/canvas/ax/approval/${encodeURIComponent(e.id)}/resolve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({decision:t,source:"browser"})})).ok)return!1;if(t==="rejected")await en("rejectGateSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:`Rejected gate "${e.title}" — do not proceed with it.`,source:"browser"})});return!0}async function Cw(e){return(await Lt("reopenGate",`/api/canvas/ax/approval/${encodeURIComponent(e.id)}/reopen`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser"})})).ok}async function Tw(e,t){return(await Lt("sendSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:e,source:"browser",...t?{target:t}:{}})})).ok}async function uo(){return(await Lt("startSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser",label:kc,attached:!0,phase:"idle"})})).ok}async function Ec(e){return(await Lt("endSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:e.source,agentId:e.agentId,attached:!1,endedBy:"human"})})).ok}var Ac=U(null);function Iw(e){let{counts:t,snapshot:n}=e;if(typeof e.label!=="string"||typeof e.endedAt!=="string")return;if(e.unchanged===!0||typeof e.parentAgentId==="string")return;Ac.value={label:e.label,endedAt:e.endedAt,endedBy:e.endedBy==="human"||e.endedBy==="agent"||e.endedBy==="idle-timeout"?e.endedBy:void 0,unchanged:e.unchanged===!0,counts:{items:Number(t?.items??0)||0,done:Number(t?.done??0)||0,cancelled:Number(t?.cancelled??0)||0,rejected:Number(t?.rejected??0)||0,held:Number(t?.held??0)||0},snapshot:n&&typeof n.id==="string"?{id:n.id,name:String(n.name??"")}:null}}function zc(){Ac.value=null}function Ew(){if(!bt.value)return null;let e=co.value;if(!e)return null;let t=O.value,n=e.nodeIds.map((s)=>t.get(s)).filter((s)=>s!==void 0),o=Ic(n,e.padding);if(!o)return null;let r=1/Math.max(0.05,K.value.scale);return i("div",{class:"scope-fence","data-fenced-count":n.length,style:{transform:`translate(${o.x}px, ${o.y}px)`,width:`${o.width}px`,height:`${o.height}px`},"aria-hidden":"true",children:[i("span",{class:"scope-fence-pill scope-fence-pill-top",style:{transform:`scale(${r})`},children:["Agent scope · ",n.length," node",n.length===1?"":"s"]},void 0,!0,void 0,this),i("span",{class:"scope-fence-pill scope-fence-pill-bottom",style:{transform:`scale(${r})`},children:"writes outside are blocked · reads allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Pc={markdown:"var(--c-accent)","mcp-app":"var(--c-ok)",webpage:"var(--c-warn)","json-render":"var(--c-ok)",graph:"var(--c-purple)",board:"var(--c-accent)",prompt:"var(--c-accent)",response:"var(--c-ok)",status:"var(--c-warn)",context:"var(--c-muted)",ledger:"var(--c-dim)",trace:"var(--c-purple)",file:"var(--c-accent)",diff:"var(--c-ok)",mermaid:"var(--c-purple)",image:"var(--c-ok)",html:"var(--c-warn)",group:"var(--c-accent)"};function g1(e){let t=typeof e==="number"&&Number.isFinite(e)?Math.floor(e):1;return Math.max(1,Math.min(20,t))}function Nc(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Vi(e){return typeof e==="string"&&e.length>0}function Aw(e){let t=e.axStep;if(!Nc(t))return null;if(!Vi(t.flowId)||!Vi(t.workItemId))return null;if(typeof t.index!=="number"||typeof t.total!=="number")return null;return{flowId:t.flowId,index:t.index,total:t.total,workItemId:t.workItemId}}function zw(e){let t=e.axFlow;if(!Nc(t)||!Vi(t.flowId)||!Array.isArray(t.steps))return null;let n=[];for(let r of t.steps){if(!Nc(r)||!Vi(r.nodeId)||!Vi(r.workItemId))return null;if(typeof r.index!=="number")return null;n.push({index:r.index,nodeId:r.nodeId,workItemId:r.workItemId,title:typeof r.title==="string"?r.title:""})}if(n.length===0)return null;let o=Nc(t.loop)?t.loop:{};return{flowId:t.flowId,title:typeof t.title==="string"?t.title:"Flow",steps:n,loop:{running:o.running===!0,run:typeof o.run==="number"&&Number.isFinite(o.run)?Math.max(0,Math.floor(o.run)):0,maxRuns:g1(o.maxRuns)}}}var v1={position:"sticky",bottom:"calc(-1 * var(--ax-dock-bleed, 12px))",marginTop:"12px",marginLeft:"calc(-1 * var(--ax-dock-bleed, 12px))",marginRight:"calc(-1 * var(--ax-dock-bleed, 12px))",marginBottom:"calc(-1 * var(--ax-dock-bleed, 12px))",padding:"9px var(--ax-dock-pad, 12px) 10px",background:"var(--c-panel-overlay)",borderTop:"1px solid var(--c-line)",backdropFilter:"blur(6px)"},Nw={display:"flex",alignItems:"center",gap:"6px",flexWrap:"wrap"},Rw={fontSize:"10px",color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginRight:"auto"},$w={...Ro,background:"var(--c-accent-25)",color:"var(--c-text)"},y1=[{status:"in-progress",label:"Start",toast:"Step started"},{status:"done",label:"Done",toast:"Step done"},{status:"blocked",label:"Blocked",toast:"Step blocked"}];async function Pw(e,t,n){let o={...t,loop:n};ie(e.id,{axFlow:o}),await mt(e.id,{data:{axFlow:o}})}function Mw(e){return typeof e?.axWorkStatus==="string"?e.axWorkStatus:"todo"}function b1({node:e,flow:t}){let[n,o]=I(""),{running:r,run:s,maxRuns:a}=t.loop,c=async()=>{await Pw(e,t,{running:!0,run:s>=a?0:s,maxRuns:a});let u=t.steps.find((d)=>Mw(O.value.get(d.nodeId)?.data)!=="done"),p=u??t.steps[t.steps.length-1];await eo(e,"ax.work.update",{id:p.workItemId,status:u?"in-progress":"done"},"Loop running")},l=async()=>{let u=n.trim();if(!u)return;await eo(e,"ax.steer",{message:u},"Steering sent"),o("")};return i("div",{class:"ax-flow-controls",style:{...Nw,marginTop:"6px",rowGap:"4px"},children:[i("span",{class:"ax-flow-runs",style:Rw,children:r?`Loop running · run ${s+1}/${a}`:`Loop idle · ${s}/${a} runs`},void 0,!1,void 0,this),r?i("button",{type:"button",class:"ax-node-action",style:$w,title:"Stop the loop now. The stop is persisted on this node, so it survives a refresh and no further step is opened.",onClick:(u)=>{u.stopPropagation(),Pw(e,t,{...t.loop,running:!1})},children:"Stop"},void 0,!1,void 0,this):i("button",{type:"button",class:"ax-node-action",style:Ro,title:"Run this flow as a loop: each completed step opens the next one, and the last step starts the next run — until the run cap is reached or you press Stop.",onClick:(u)=>{u.stopPropagation(),c()},children:"Run loop"},void 0,!1,void 0,this),i("input",{class:"ax-flow-steer-input",value:n,placeholder:"Steer the agent…","aria-label":"Steer the agent",onInput:(u)=>o(u.target.value),onClick:(u)=>u.stopPropagation(),onKeyDown:(u)=>{if(u.key!=="Enter")return;u.stopPropagation(),l()},style:{flex:"1 1 120px",minWidth:"90px",fontSize:"10px",padding:"3px 6px",borderRadius:"4px",border:"1px solid var(--c-line)",background:"var(--c-panel-overlay)",color:"var(--c-text)"}},void 0,!1,void 0,this),i("button",{type:"button",class:"ax-node-action",style:Ro,title:"Send a steering message to the agent working this flow.",onClick:(u)=>{u.stopPropagation(),l()},children:"Steer"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Rc({node:e}){let t=Aw(e.data);if(!t)return null;let n=zw(e.data),o=Mw(e.data);return i("div",{class:"ax-step-dock",style:v1,children:[i("div",{class:"ax-step-controls",style:Nw,children:[i("span",{class:"ax-step-position",style:Rw,children:["Step ",t.index,"/",t.total]},void 0,!0,void 0,this),y1.map((r)=>i("button",{type:"button",class:"ax-node-action","aria-pressed":o===r.status,style:o===r.status?$w:Ro,title:`Set this step's work item to "${r.status}".`,onClick:(s)=>{s.stopPropagation(),eo(e,"ax.work.update",{id:t.workItemId,status:r.status},r.toast)},children:r.label},r.status,!1,void 0,this))]},void 0,!0,void 0,this),n&&i(b1,{node:e,flow:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Ur=8,Uo=U(null),qr=[],Wr=[],Dw=null;function Lw(e){let t=e?.data.parentGroup;return typeof t==="string"&&t.length>0?t:null}function Ow(e){if(!e||!Array.isArray(e.data.children))return[];return e.data.children.filter((t)=>typeof t==="string")}function x1(e,t){let n=new Map(t.map((c)=>[c.id,c])),o=new Set([e]),r=n.get(e);if(!r)return o;let s=Lw(r);while(s&&!o.has(s))o.add(s),s=Lw(n.get(s));if(r.type!=="group")return o;let a=[...Ow(r)];while(a.length>0){let c=a.pop();if(!c||o.has(c))continue;o.add(c);let l=n.get(c);if(l?.type==="group")a.push(...Ow(l))}return o}function Fw(e,t){qr=[],Wr=[],Dw=e;let n=Array.from(t),o=x1(e,n);for(let r of n){if(o.has(r.id))continue;let s=r.position.x,a=r.position.x+r.size.width,c=r.position.x+r.size.width/2,l=r.position.y,u=r.position.y+r.size.height,p=r.position.y+r.size.height/2;qr.push({val:s,minY:l,maxY:u}),qr.push({val:a,minY:l,maxY:u}),qr.push({val:c,minY:l,maxY:u}),Wr.push({val:l,minX:s,maxX:a}),Wr.push({val:u,minX:s,maxX:a}),Wr.push({val:p,minX:s,maxX:a})}}function Bw(){qr=[],Wr=[],Dw=null}function Hw(e,t,n,o){let r=[e,e+n/2,e+n],s=[t,t+o/2,t+o],a=[0,n/2,n],c=[0,o/2,o],l=null,u=Ur+1,p=null;for(let v=0;v<3;v++){let x=r[v];for(let g of qr){let y=Math.abs(x-g.val);if(y<u)u=y,l=g.val-a[v],p={axis:"x",pos:g.val,from:Math.min(g.minY,t),to:Math.max(g.maxY,t+o)}}}let d=null,m=Ur+1,f=null;for(let v=0;v<3;v++){let x=s[v];for(let g of Wr){let y=Math.abs(x-g.val);if(y<m)m=y,d=g.val-c[v],f={axis:"y",pos:g.val,from:Math.min(g.minX,e),to:Math.max(g.maxX,e+n)}}}let h=[];if(p&&u<=Ur)h.push(p);if(f&&m<=Ur)h.push(f);return{x:l!==null&&u<=Ur?l:e,y:d!==null&&m<=Ur?d:t,guides:h}}function jw({nodeId:e,viewport:t,onMove:n,onDragEnd:o,onClick:r}){let s=z(!1),a=z({x:0,y:0}),c=z({x:0,y:0});return H((u,p,d)=>{u.stopPropagation(),u.preventDefault(),s.current=!0,document.documentElement.classList.add("is-node-dragging"),window.getSelection()?.removeAllRanges(),a.current={x:u.clientX,y:u.clientY},c.current={x:p,y:d};let m=null,f=null,h=!1,v=()=>{if(f=null,!s.current||!m)return;let y=m;m=null;let E=t.value.scale,D=(y.x-a.current.x)/E,N=(y.y-a.current.y)/E;n(e,c.current.x+D,c.current.y+N)},x=(y)=>{if(!s.current)return;if(!h&&Math.hypot(y.clientX-u.clientX,y.clientY-u.clientY)<4)return;if(h=!0,m={x:y.clientX,y:y.clientY},f!==null)return;f=window.requestAnimationFrame(v)},g=(y)=>{if(f!==null)window.cancelAnimationFrame(f),v();if(s.current=!1,document.documentElement.classList.remove("is-node-dragging"),document.removeEventListener("pointermove",x),document.removeEventListener("pointerup",g),document.removeEventListener("pointercancel",g),o(),!h&&y.type==="pointerup")r?.()};document.addEventListener("pointermove",x),document.addEventListener("pointerup",g),document.addEventListener("pointercancel",g)},[e,t,n,o,r])}var w1=200,_1=100;function Zw({nodeId:e,viewport:t,onResize:n,onResizeEnd:o}){let r=z(!1),s=z({x:0,y:0}),a=z({w:0,h:0});return H((l,u,p)=>{l.stopPropagation(),l.preventDefault(),r.current=!0,s.current={x:l.clientX,y:l.clientY},a.current={w:u,h:p},document.documentElement.classList.add("is-node-resizing");let d=null,m=null,f=()=>{if(m=null,!r.current||!d)return;let x=d;d=null;let g=t.value.scale,y=(x.x-s.current.x)/g,E=(x.y-s.current.y)/g;n(e,Math.max(w1,a.current.w+y),Math.max(_1,a.current.h+E))},h=(x)=>{if(!r.current)return;if(d={x:x.clientX,y:x.clientY},m!==null)return;m=window.requestAnimationFrame(f)},v=()=>{if(m!==null)window.cancelAnimationFrame(m),f();r.current=!1,document.documentElement.classList.remove("is-node-resizing"),document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",v),document.removeEventListener("pointercancel",v),o()};document.addEventListener("pointermove",h),document.addEventListener("pointerup",v),document.addEventListener("pointercancel",v)},[e,t,n,o])}var k1={ArrowLeft:{dx:-1,dy:0},ArrowRight:{dx:1,dy:0},ArrowUp:{dx:0,dy:-1},ArrowDown:{dx:0,dy:1}};function S1(e,t,n){let o=e.position.x+e.size.width/2,r=e.position.y+e.size.height/2,s=null,a=Number.POSITIVE_INFINITY;for(let c of n){if(c.id===e.id)continue;let l=c.position.x+c.size.width/2-o,u=c.position.y+c.size.height/2-r,p=l*t.dx+u*t.dy;if(p<=0)continue;let d=Math.abs(l*t.dy)+Math.abs(u*t.dx);if(d>p)continue;let m=p+d*2;if(m<a)a=m,s=c}return s}var C1=0.4,T1=0.55,I1=175;function E1(e,t,n=0){if(!Number.isFinite(e)||e>=1)return 1;let r=Math.min(2.2,1/Math.max(e,0.01));if(Number.isFinite(t)&&t>0)r=Math.min(r,t*C1/Er);if(Number.isFinite(n)&&n>0)r=Math.min(r,n*T1/I1);return Math.max(1,r)}function Uw({node:e,children:t,onContextMenu:n}){let o=Te.value===e.id,r=be.value.has(e.id),s=Ae.value.has(e.id),a=ir.value.has(e.id),c=!a&&sr.value.has(e.id),l=Gs.value.has(e.id),u=!o&&Jv.value.has(e.id),p=Sn.value,d=p!==null&&p.has(e.id),m=p!==null&&!p.has(e.id),[f,h]=I(!1),v=z(null),x=H((F,ne,He)=>{let ve=Hw(ne,He,e.size.width,e.size.height),Jt=O.value.get(F);if(Jt?.position.x===ve.x&&Jt.position.y===ve.y){Uo.value=ve.guides.length>0?ve.guides:null;return}at(F,{position:{x:ve.x,y:ve.y}}),Uo.value=ve.guides.length>0?ve.guides:null,ty(F)},[e.size.width,e.size.height]),g=z(null),y=H(()=>{if(Bw(),Uo.value=null,sd(null),g.current)document.removeEventListener("keydown",g.current),g.current=null;ct();let F=mn.value;if(ey(),!F||F.nodeId!==e.id)return;if(F.mode==="add")xu(F.groupId,[e.id]);else{let ne=O.value.get(F.groupId),He=Array.isArray(ne?.data.children)?ne.data.children.filter((ve)=>typeof ve==="string"&&ve!==e.id):[];ia(F.groupId,He)}},[e.id]),E=jw({nodeId:e.id,viewport:K,onMove:x,onDragEnd:y,onClick:()=>{be.value=new Set([e.id])}}),D=H((F,ne,He)=>{let ve=O.value.get(F);if(ve?.size.width===ne&&ve.size.height===He)return;at(F,{size:{width:ne,height:He}})},[]),N=H(()=>{ie(e.id,{userResized:!0}),mt(e.id,{data:{userResized:!0}}),ct()},[e.id]),b=Zw({nodeId:e.id,viewport:K,onResize:D,onResizeEnd:N}),T=H((F)=>{F.stopPropagation(),F.preventDefault(),Be.value={fromId:e.id,fromX:e.position.x+e.size.width/2,fromY:e.position.y+e.size.height/2,cursorX:e.position.x+e.size.width/2,cursorY:e.position.y+e.size.height/2,targetId:null}},[e.id,e.position.x,e.position.y,e.size.width,e.size.height]),w=H((F)=>{if(F.button!==0)return;if(f)return;if(F.target instanceof Element&&F.target.closest("button, input")){F.stopPropagation();return}if(At.value==="connect"){T(F);return}if(F.shiftKey){F.stopPropagation(),ku(e.id);return}if(Tn(e.id),sd(e.id),ex(e.id,typeof e.data.title==="string"&&e.data.title?e.data.title:e.type),Fw(e.id,O.value.values()),e.type!=="group"){let ne=(He)=>{if(He.key==="Escape")Qv()};g.current=ne,document.addEventListener("keydown",ne)}E(F,e.position.x,e.position.y)},[e.id,e.type,e.data.title,e.position.x,e.position.y,E,f,T]),_=H((F)=>{if(F.button!==0)return;if(F.stopPropagation(),At.value==="connect"){T(F);return}if(F.shiftKey){ku(e.id);return}Tn(e.id)},[e.id,T]),P=H((F)=>{if((F.target instanceof Element?F.target:null)?.closest('button, input, textarea, select, a, [contenteditable="true"]'))return;if(n)n(F,e.id)},[n,e.id]),q=H((F)=>{let ne=F.target;if(ne&&ne!==F.currentTarget&&ne.closest('input, textarea, [contenteditable="true"]'))return;let He=k1[F.key];if(He){F.preventDefault();let ve=S1(e,He,O.value.values());if(!ve)return;Tn(ve.id),requestAnimationFrame(()=>{document.querySelector(`.canvas-node[data-node-id="${CSS.escape(ve.id)}"]`)?.focus()})}else if(F.key==="Enter"&&F.target===F.currentTarget&&pi.has(e.type))F.preventDefault(),Ut(e.id)},[e]),R=e.data.title||(e.type==="file"?(e.data.path||e.data.content||"").split(/[\\/]/).pop()??"":"")||dt[e.type],Z=H((F)=>{let ne=F.trim();if(ne&&ne!==R)ie(e.id,{title:ne}),mt(e.id,{title:ne});h(!1)},[e.id,R]),j=z(null),k=z(!1),V=z(null);B(()=>{if(k.current||!ad(e))return;let F=j.current;if(!F)return;let ne=new ResizeObserver(()=>{if(k.current){ne.disconnect();return}let He=F.scrollHeight,ve=ix(e,He);if(ve===null)return;if(Math.abs(ve-e.size.height)>8){if(ma(e.id,{width:e.size.width,height:ve}),V.current!==null)window.clearTimeout(V.current);V.current=window.setTimeout(()=>{ct({recordHistory:!1}),V.current=null},0)}k.current=!0,ne.disconnect()});return ne.observe(F),()=>{if(ne.disconnect(),V.current!==null)window.clearTimeout(V.current),V.current=null}},[e.id,e.type,e.data.mode,e.data.strictSize,e.collapsed,e.size.width,e.size.height]);let ge=e.pinned,Ue=e.type==="trace",se=Ue&&e.data.status==="running",le=e.type==="group",pe=e.data.strictSize===!0,Mn=Math.max(K.value.scale,0.01),Xt=E1(Mn,e.collapsed?0:e.size.height,e.size.width),cn=le&&e.data.color?e.data.color:void 0,M={left:`${e.position.x}px`,top:`${e.position.y}px`,width:`${e.size.width}px`,height:e.collapsed?"auto":`${e.size.height}px`,zIndex:e.zIndex,"--node-chrome-scale":Xt.toFixed(3),"--node-port-scale":(1/Mn).toFixed(3),...cn?{"--group-color":cn}:{}},J=bt.value&&fw.value.has(e.id),me=["canvas-node",o?"active":"",u?"neighbor":"",d?"search-match":"",m?"search-dimmed":"",r?"selected":"",s?"context-pinned":"",a?"attention-focus-primary":"",c?"attention-focus-secondary":"",l?"attention-pulse":"",ge?"pinned":"",Ue?"trace-node":"",se?"trace-running":"",le?"group-node":"",pe?"strict-size":"",J?"agent-mutating":""].filter(Boolean).join(" "),te=le?(Array.isArray(e.data.children)?e.data.children:[]).filter((F)=>typeof F==="string"&&O.value.has(F)):[],[de,Q]=I(!1),ee=mn.value,W=le&&ee?.groupId===e.id&&ee.mode==="add",fe=le&&ee?.groupId===e.id&&ee.mode==="remove",$e=Be.value?.targetId===e.id,xt=le?[...new Set(te.map((F)=>O.value.get(F)?.type).filter((F)=>!!F))].slice(0,4):[];if(le&&e.collapsed)return i("div",{class:`${me} group-chip`,"data-node-type":e.type,style:{...M,width:"auto",height:"auto"},onPointerDown:_,onDblClick:P,title:"Expand group","data-testid":"group-chip",children:i("div",{class:"node-titlebar group-chip-inner",onPointerDown:w,children:[i("button",{type:"button",class:"group-chip-expand","aria-label":`Expand group ${R}`,onClick:(F)=>{F.stopPropagation(),hr(e.id)},children:i(br,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{class:"group-chip-text",children:[i("div",{class:"group-chip-name",children:R},void 0,!1,void 0,this),i("div",{class:"group-chip-meta",children:[xt.map((F)=>i("span",{class:"group-kind-dot",style:{background:Pc[F]},"aria-hidden":"true"},F,!1,void 0,this)),i("span",{class:"group-chip-count",children:[te.length," node",te.length===1?"":"s"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return i("div",{class:`${me}${W?" is-drop-target":""}${fe?" is-drop-source":""}${$e?" is-edge-target":""}${le&&de?" group-menu-open":""}`,"data-node-type":e.type,"data-node-id":e.id,style:M,tabIndex:o?0:-1,onKeyDown:q,onPointerDown:_,onMouseDown:(F)=>{if(F.shiftKey)F.preventDefault()},onDblClick:P,children:[i("div",{class:"node-content",children:[le&&i("div",{class:"node-titlebar group-edge-row",onPointerDown:w,children:[i("span",{class:"group-name-pill",children:[f?i("input",{ref:v,class:"node-title-input group-title-input",value:R,onBlur:(F)=>Z(F.target.value),onKeyDown:(F)=>{if(F.key==="Enter")Z(F.target.value);if(F.key==="Escape")h(!1)},onClick:(F)=>F.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"group-name",title:R,children:R},void 0,!1,void 0,this),i("span",{class:"group-count",children:te.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"group-edge-spacer"},void 0,!1,void 0,this),i("span",{class:"group-actions",role:"toolbar","aria-label":`${R} actions`,children:[i("button",{type:"button",class:"group-action",title:"Auto-arrange children","aria-label":"Auto-arrange children",disabled:te.length===0,onClick:(F)=>{F.stopPropagation(),xu(e.id,te,"grid")},children:i("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","aria-hidden":"true",children:[i("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"group-action",title:"Collapse group","aria-label":"Collapse group",onClick:(F)=>{F.stopPropagation(),hr(e.id)},children:i("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M3 10 L8 5 L13 10"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"group-action",title:"Rename · Ungroup · Pin all to context","aria-label":"Group menu","aria-expanded":de,onClick:(F)=>{F.stopPropagation(),Q((ne)=>!ne)},children:i(ky,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),de&&i("div",{class:"group-menu",role:"menu",onPointerDown:(F)=>F.stopPropagation(),children:[i("button",{type:"button",role:"menuitem",onClick:(F)=>{F.stopPropagation(),Q(!1),h(!0),requestAnimationFrame(()=>v.current?.focus())},children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",onClick:(F)=>{F.stopPropagation(),Q(!1),Jn(e.id),ur(e.id)},children:"Ungroup"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",disabled:te.length===0,onClick:(F)=>{F.stopPropagation(),Q(!1),ua(te)},children:"Pin all to context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!le&&i("div",{class:"node-titlebar",onPointerDown:w,children:[i("span",{class:"node-type-icon","aria-hidden":"true",children:(()=>{let F=sn(e.type);return i(F,{size:Math.round(14*Xt)},void 0,!1,void 0,this)})()},void 0,!1,void 0,this),typeof e.data.axWorkStatus==="string"&&i("span",{class:`node-ax-status node-ax-status-${e.data.axWorkStatus}`,children:e.data.axWorkStatus},void 0,!1,void 0,this),f?i("input",{ref:v,class:"node-title-input",value:R,onBlur:(F)=>Z(F.target.value),onKeyDown:(F)=>{if(F.key==="Enter")Z(F.target.value);if(F.key==="Escape")h(!1)},onClick:(F)=>F.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"node-title",title:R,children:R},void 0,!1,void 0,this),i("div",{class:"node-controls",children:[ge&&i("span",{class:"pin-indicator",title:"Pinned",children:"⊙"},void 0,!1,void 0,this),i("button",{type:"button",class:`ctx-pin-btn${s?" ctx-pin-active":""}`,onClick:(F)=>{F.stopPropagation(),Xn(e.id)},title:s?"Remove from context":"Add to context",children:i(Ty,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),Ba(e)&&i("button",{type:"button",onClick:(F)=>{F.stopPropagation(),Ha(e)},title:"Open as site",children:i(hn,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),pi.has(e.type)&&i("button",{type:"button",onClick:(F)=>{F.stopPropagation(),Ut(e.id)},title:"Expand (focus mode)",children:i(Sy,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",onClick:(F)=>{F.stopPropagation(),hr(e.id)},title:e.collapsed?"Expand":"Collapse",children:e.collapsed?i(br,{size:14},void 0,!1,void 0,this):i(xr,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",onClick:(F)=>{F.stopPropagation(),Vn(e.id)},title:"Close",children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!e.collapsed&&i("div",{ref:j,class:"node-body",children:[t,i(Rc,{node:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!e.collapsed&&i("div",{class:"node-resize-handle",onPointerDown:(F)=>b(F,e.size.width,e.size.height)},void 0,!1,void 0,this),r&&["tl","tr","bl","br"].map((F)=>i("span",{class:`node-selection-handle is-${F}`,"aria-hidden":"true"},F,!1,void 0,this)),Lo.value.has(e.id)&&i("span",{class:"node-yield-pill","data-testid":"yield-pill",children:[i("span",{class:"node-yield-dot","aria-hidden":"true"},void 0,!1,void 0,this),Lo.value.get(e.id)," took over — agent yielded"]},void 0,!0,void 0,this),!le&&["top","right","bottom","left"].map((F)=>i("div",{class:`node-port node-port-${F}`,onPointerDown:(ne)=>{if(ne.button!==0)return;ne.stopPropagation(),ne.preventDefault(),ne.currentTarget.setPointerCapture(ne.pointerId);let He=e.position.x+e.size.width/2,ve=e.position.y+e.size.height/2,Jt=e.size.width/2,ns=e.size.height/2,Kt,Ln;switch(F){case"top":Kt=He,Ln=ve-ns;break;case"bottom":Kt=He,Ln=ve+ns;break;case"left":Kt=He-Jt,Ln=ve;break;case"right":Kt=He+Jt,Ln=ve;break}Be.value={fromId:e.id,fromX:Kt,fromY:Ln,cursorX:Kt,cursorY:Ln}}},F,!1,void 0,this))]},void 0,!0,void 0,this)}function $c({node:e}){let t=typeof e.data.boardId==="string"?e.data.boardId:"",n=Pt.value.find((o)=>o.id===t);return i("div",{class:"board-node",children:[i("div",{class:"board-node-content",children:[i("div",{class:"board-node-label",children:"Linked board"},void 0,!1,void 0,this),i("strong",{class:"board-node-title",children:n?.name??"Missing board"},void 0,!1,void 0,this),i("div",{class:"board-node-meta",children:n?`${n.nodeCount} nodes`:t||"No target id"},void 0,!1,void 0,this),n?.summary&&i("p",{class:"board-node-summary",children:n.summary},void 0,!1,void 0,this),!!n?.pinnedTitles?.length&&i("p",{class:"board-node-meta",children:["Pinned: ",n.pinnedTitles.map((o)=>o.title).join(", ")]},void 0,!0,void 0,this),!!n?.backlinks?.length&&i("p",{class:"board-node-meta",children:["Linked from: ",[...new Set(n.backlinks.map((o)=>o.title))].join(", ")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("button",{class:"board-node-open",type:"button",disabled:!n,onClick:()=>n&&void Nt(n.id),children:[n?"Open board":"Target unavailable",n&&i(hn,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var A1={relation:"var(--c-muted)","depends-on":"var(--c-warn)",flow:"var(--c-accent)",references:"var(--c-muted)"},z1=new Set(["depends-on","flow"]);function P1(e){if(!Number.isFinite(e)||e<=0)return 1;return e<1?1/e:1}function N1(e,t){let n=`${8*t} ${4*t}`;if(e.style==="dashed")return n;if(e.style==="dotted")return`${3*t} ${3*t}`;if(e.type==="references"&&!e.style)return n;return}function Mc(e,t){let n=e.position.x+e.size.width/2,o=e.position.y+e.size.height/2,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2,a=r-n,c=s-o,l=e.size.width/2,u=e.size.height/2,p=Math.abs(c/(a||0.001)),d=u/(l||0.001);if(p>d){let f=c>0?1:-1;return{x:n+u/p*(a>0?1:-1),y:o+u*f,side:f>0?"bottom":"top"}}let m=a>0?1:-1;return{x:n+l*m,y:o+p*l*(c>0?1:-1),side:m>0?"right":"left"}}function Lc(e,t){switch(e.side){case"top":return{x:e.x,y:e.y-t};case"bottom":return{x:e.x,y:e.y+t};case"left":return{x:e.x-t,y:e.y};case"right":return{x:e.x+t,y:e.y}}}function R1(e,t,n,o,r,s,a,c){return{x:0.125*e+0.375*n+0.375*r+0.125*a,y:0.125*t+0.375*o+0.375*s+0.125*c}}function $1({edge:e,fromNode:t,toNode:n,focused:o,dimmed:r,selected:s,scale:a,onContextMenu:c}){let l=Mc(t,n),u=Mc(n,t),p=u.x-l.x,d=u.y-l.y,m=Math.sqrt(p*p+d*d),f=Math.min(Math.max(m*0.35,32),160),h=Lc(l,f),v=Lc(u,f),x=`M ${l.x} ${l.y} C ${h.x} ${h.y}, ${v.x} ${v.y}, ${u.x} ${u.y}`,g=A1[e.type],y=z1.has(e.type),E=N1(e,a),D=Math.min(a,2.2),N=e.label&&a<=3.4?R1(l.x,l.y,h.x,h.y,v.x,v.y,u.x,u.y):null,b=`edge-path-${e.id}`;return i("g",{children:[i("path",{d:x,fill:"none",stroke:"transparent","stroke-width":12*a,style:{cursor:"pointer",pointerEvents:"stroke"},onClick:(T)=>{T.stopPropagation(),fn.value=e.id},onDblClick:c?(T)=>c(T,e.id):void 0},void 0,!1,void 0,this),(o||s)&&i("path",{d:x,fill:"none",stroke:g,"stroke-width":6*a,"stroke-dasharray":E,opacity:s?0.3:0.15,style:{filter:"blur(3px)"}},void 0,!1,void 0,this),i("path",{id:b,d:x,class:s?"edge-selected":void 0,fill:"none",stroke:g,"stroke-width":(s?3:o?2.5:1.5)*a,"stroke-dasharray":E,"marker-end":y?"url(#edge-arrow)":void 0,opacity:s?1:r?0.2:o?1:0.85,style:{transition:"opacity 0.2s, stroke-width 0.2s"}},void 0,!1,void 0,this),e.animated&&i("circle",{r:3*a,fill:g,opacity:"0.9",children:i("animateMotion",{dur:"2s",repeatCount:"indefinite",children:i("mpath",{href:`#${b}`},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&e.label&&i("g",{transform:`translate(${N.x}, ${N.y})`,children:[i("rect",{class:"edge-label-bg",x:-(e.label.length*3.5+8)*D,y:-10*D,width:(e.label.length*7+16)*D,height:20*D,rx:4*D},void 0,!1,void 0,this),i("text",{class:"edge-label","text-anchor":"middle","dominant-baseline":"central",fill:"var(--c-text)",children:e.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function qw({nodes:e,edges:t,onEdgeContextMenu:n}){let o=e.value,r=Array.from(t.value.values()),s=Te.value,a=s!==null,c=Sn.value,l=c!==null,u=P1(K.value.scale);if(r.length===0&&!Be.value)return null;let p=96,d=Array.from(o.values());if(d.length===0)return null;let m=Math.min(...d.map((y)=>y.position.x))-p,f=Math.min(...d.map((y)=>y.position.y))-p,h=Math.max(...d.map((y)=>y.position.x+y.size.width))+p,v=Math.max(...d.map((y)=>y.position.y+y.size.height))+p,x=Math.max(1,h-m),g=Math.max(1,v-f);return i("svg",{"aria-label":"Canvas connections",role:"img",viewBox:`${m} ${f} ${x} ${g}`,width:x,height:g,style:{position:"absolute",top:`${f}px`,left:`${m}px`,pointerEvents:"none",overflow:"visible","--edge-chrome-scale":u.toFixed(3),"--edge-label-scale":Math.min(u,2.2).toFixed(3)},children:[i("title",{children:"Canvas connections"},void 0,!1,void 0,this),i("defs",{children:i("marker",{id:"edge-arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:8*Math.min(u,2.2),markerHeight:8*Math.min(u,2.2),orient:"auto-start-reverse",children:i("path",{d:"M 0 1 L 10 5 L 0 9 z",fill:"currentColor",opacity:"0.75"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r.map((y)=>{let E=la(y.from),D=la(y.to);if(!E||!D||E.id===D.id)return null;let N=a&&(y.from===s||y.to===s),b=l&&!(c.has(y.from)||c.has(y.to));return i($1,{edge:y,fromNode:E,toNode:D,focused:N,dimmed:a&&!N||b,selected:fn.value===y.id,scale:u,onContextMenu:n},y.id,!1,void 0,this)}),Be.value&&(()=>{let y=Be.value,E=la(y.fromId),D={position:{x:y.cursorX,y:y.cursorY},size:{width:1,height:1}},N;if(E){let b=Mc(E,D),T=Mc(D,E),w=T.x-b.x,_=T.y-b.y,P=Math.sqrt(w*w+_*_),q=Math.min(Math.max(P*0.35,32),160),R=Lc(b,q),Z=Lc(T,q);N=`M ${b.x} ${b.y} C ${R.x} ${R.y}, ${Z.x} ${Z.y}, ${T.x} ${T.y}`}else{let b=y.cursorX-y.fromX,T=y.cursorY-y.fromY,w=Math.sqrt(b*b+T*T),_=Math.min(w*0.25,80),P=b/(w||1),q=T/(w||1);N=`M ${y.fromX} ${y.fromY} C ${y.fromX+P*_} ${y.fromY+q*_}, ${y.cursorX-P*_} ${y.cursorY-q*_}, ${y.cursorX} ${y.cursorY}`}return i("g",{children:[i("path",{d:N,fill:"none",stroke:"var(--c-accent)","stroke-width":6*u,opacity:"0.1",style:{filter:"blur(3px)"}},void 0,!1,void 0,this),i("path",{d:N,fill:"none",stroke:"var(--c-accent)","stroke-width":2*u,"stroke-dasharray":`${6*u} ${4*u}`,opacity:"0.8"},void 0,!1,void 0,this),i("circle",{cx:y.cursorX,cy:y.cursorY,r:5*u,fill:"var(--c-accent)",opacity:"0.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})()]},void 0,!0,void 0,this)}function M1(e){let[t,...n]=e;if(!t)return"";return n.reduce((o,r)=>`${o} L ${r.x} ${r.y}`,`M ${t.x} ${t.y}`)}function ap({annotations:e}){if(e.length===0)return null;return i("svg",{class:"annotation-layer","aria-hidden":"true",children:e.map((t)=>{let n=t.color==="currentColor"?"var(--c-annotation)":t.color;if(t.type==="text"){let o=t.points[0];if(!o||!t.text)return null;return i("text",{x:o.x,y:o.y,fill:n,"font-size":t.width,"font-family":"var(--font)","font-weight":"700",opacity:"0.95",children:t.text},t.id,!1,void 0,this)}return i("path",{d:M1(t.points),fill:"none",stroke:n,"stroke-width":t.width,"stroke-linecap":"round","stroke-linejoin":"round",opacity:"0.9"},t.id,!1,void 0,this)})},void 0,!1,void 0,this)}function L1(e){switch(e.type){case"markdown":return i(La,{node:e},void 0,!1,void 0,this);case"mcp-app":return i(ro,{node:e},void 0,!1,void 0,this);case"webpage":return i(bc,{node:e},void 0,!1,void 0,this);case"json-render":return i(ro,{node:e},void 0,!1,void 0,this);case"graph":return i(ro,{node:e},void 0,!1,void 0,this);case"board":return i($c,{node:e},void 0,!1,void 0,this);case"prompt":return i(xc,{node:e},void 0,!1,void 0,this);case"response":return i(wc,{node:e},void 0,!1,void 0,this);case"status":return i(vc,{node:e},void 0,!1,void 0,this);case"context":return i(_a,{node:e},void 0,!1,void 0,this);case"ledger":return i(za,{node:e},void 0,!1,void 0,this);case"trace":return i(_c,{node:e},void 0,!1,void 0,this);case"file":return i(Aa,{node:e},void 0,!1,void 0,this);case"diff":return i(ka,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Ka,{node:e},void 0,!1,void 0,this);case"image":return i(yc,{node:e},void 0,!1,void 0,this);case"html":return i(Ui,{node:e},void 0,!1,void 0,this);case"group":return i(Vx,{node:e},void 0,!1,void 0,this);default:return i("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function O1(e,t,n){let o=n.x-t.x,r=n.y-t.y,s=o*o+r*r;if(s===0)return Math.hypot(e.x-t.x,e.y-t.y);let a=Math.max(0,Math.min(1,((e.x-t.x)*o+(e.y-t.y)*r)/s));return Math.hypot(e.x-(t.x+a*o),e.y-(t.y+a*r))}function D1(e,t,n){for(let o=e.length-1;o>=0;o--){let r=e[o];if(!r)continue;let s=n+r.width;if(t.x<r.bounds.x-s||t.x>r.bounds.x+r.bounds.width+s||t.y<r.bounds.y-s||t.y>r.bounds.y+r.bounds.height+s)continue;if(r.type==="text")return r;for(let a=1;a<r.points.length;a++){let c=r.points[a-1],l=r.points[a];if(c&&l&&O1(t,c,l)<=n+r.width/2)return r}}return null}var cp="currentColor",Ww=4,Vw=24,F1=14,Gw={width:520,height:420};function B1(e){let t=e.trim();if(!t||/\s/.test(t))return null;let n=/^[a-z][a-z0-9+.-]*:/i.test(t)?t:`https://${t}`;try{let o=new URL(n);if(o.protocol!=="http:"&&o.protocol!=="https:")return null;return o.toString()}catch{return null}}function up(e){let t=e.trim();if(!t)return[];let n=t.includes(`
|
|
329
|
+
`)?t.split(/\r?\n/):t.split(/\s+/),o=new Set,r=[];for(let s of n){let a=s.trim();if(!a||a.startsWith("#"))continue;let c=B1(a);if(!c||o.has(c))continue;o.add(c),r.push(c)}return r}function H1(e){let t=up(e.getData("text/uri-list"));if(t.length>0)return t;return up(e.getData("text/plain"))}function j1(e){if(!e)return!1;return e.types.includes("text/uri-list")||e.types.includes("text/plain")}function lp(e){if(!(e instanceof HTMLElement))return!1;return Boolean(e.closest('input, textarea, select, [contenteditable="true"], [contenteditable=""]'))}function Z1(e,t,n=new Set){let o=[],r=0;for(let s of e){if(n.has(s.id))continue;if(t&&s.id===t)continue;if(s.type==="group")o.splice(r++,0,s);else o.push(s)}return o}function Xw({onNodeContextMenu:e,onEdgeContextMenu:t,onCanvasContextMenu:n,annotationMode:o=!1,annotationTool:r=null}){let s=K.value,a=z(!1),c=z(null),l=z(!1),u=z([]),[p,d]=I(null),[m,f]=I(null),[h,v]=I(null),x=z(null),[g,y]=I(!1),E=z(0),D=z(null),N=z(null);B(()=>{let M=null,J=zt(()=>{K.value;let me=N.current;if(!me)return;if(me.style.willChange="transform",M)clearTimeout(M);M=setTimeout(()=>{me.style.willChange="auto"},180)});return()=>{if(M)clearTimeout(M);J()}},[]);let b=ga({viewport:K,disabled:o,onViewportChange:(M)=>{if(a.current||o)return;In(),ly(M)},onViewportCommit:(M)=>{if(a.current||o)return;In(),dy(M)}}),T=H((M)=>{x.current=M,v(M)},[]),w=H(async(M,J,me)=>{if(M.length===0)return;let{width:te,height:de}=Gw,Q=24,ee=Math.ceil(Math.sqrt(M.length)),W=Math.ceil(M.length/ee),fe=ee*te+Math.max(0,ee-1)*Q,$e=W*de+Math.max(0,W-1)*Q;for(let xt=0;xt<M.length;xt++){let F=xt%ee,ne=Math.floor(xt/ee),He=J-fe/2+F*(te+Q),ve=me-$e/2+ne*(de+Q);await tn({type:"webpage",content:M[xt],x:He,y:ve,width:te,height:de})}},[]),_=H((M)=>{let J=b.current;if(!J)return;if(r==="eraser"){if((M.target instanceof Element?M.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;M.preventDefault(),M.stopPropagation();let W=J.getBoundingClientRect(),fe=K.value,$e={x:(M.clientX-W.left-fe.x)/fe.scale,y:(M.clientY-W.top-fe.y)/fe.scale},xt=D1(Array.from(pr.value.values()),$e,F1/fe.scale);if(xt)cy(xt.id);return}if(r==="text"){if((M.target instanceof Element?M.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;M.preventDefault(),M.stopPropagation(),Te.value=null,_t();let W=J.getBoundingClientRect(),fe=K.value;T({x:(M.clientX-W.left-fe.x)/fe.scale,y:(M.clientY-W.top-fe.y)/fe.scale,value:""});return}if(r==="pen"){if((M.target instanceof Element?M.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;M.preventDefault(),M.stopPropagation(),Te.value=null,_t(),l.current=!0;let W=J.getBoundingClientRect(),fe=K.value,$e={x:(M.clientX-W.left-fe.x)/fe.scale,y:(M.clientY-W.top-fe.y)/fe.scale};u.current=[$e],f({id:"draft-annotation",type:"freehand",points:[$e],bounds:{x:0,y:0,width:0,height:0},color:cp,width:Ww,createdAt:""}),J.setPointerCapture(M.pointerId);return}if(M.target!==J)return;if(fr()||M.button===1||M.button===2){if(!M.shiftKey&&!D.current)Te.value=null,_t();return}M.preventDefault(),M.stopPropagation(),a.current=!0;let me=J.getBoundingClientRect(),te=M.clientX-me.left,de=M.clientY-me.top,Q={startX:te,startY:de,currentX:te,currentY:de};D.current=Q,d(Q),J.setPointerCapture(M.pointerId)},[r,b]);B(()=>zt(()=>{let M=K.value,J=c.current,me=b.current;if(!J||!me)return;let te=me.getBoundingClientRect();Ga({x:(J.x-te.left-M.x)/M.scale,y:(J.y-te.top-M.y)/M.scale})}),[]);let P=H((M)=>{{let te=b.current;if(te){c.current={x:M.clientX,y:M.clientY};let de=te.getBoundingClientRect(),Q=K.value;Ga({x:(M.clientX-de.left-Q.x)/Q.scale,y:(M.clientY-de.top-Q.y)/Q.scale})}}if(l.current){let te=b.current;if(!te)return;let de=te.getBoundingClientRect(),Q=K.value,ee={x:(M.clientX-de.left-Q.x)/Q.scale,y:(M.clientY-de.top-Q.y)/Q.scale},W=u.current.at(-1);if(W&&Math.hypot(ee.x-W.x,ee.y-W.y)<2)return;u.current=[...u.current,ee],f((fe)=>fe?{...fe,points:u.current}:null);return}if(!a.current||!D.current)return;let J=b.current?.getBoundingClientRect();if(!J)return;let me={...D.current,currentX:M.clientX-J.left,currentY:M.clientY-J.top};D.current=me,d(me)},[b]),q=H((M)=>{if(l.current){l.current=!1;let ee=u.current;if(u.current=[],f(null),ee.length>=2)Iu({points:ee,color:cp,width:Ww});let W=b.current;if(W?.hasPointerCapture(M.pointerId))W.releasePointerCapture(M.pointerId);return}let J=D.current;if(!a.current||!J)return;a.current=!1,D.current=null;let me=Math.min(J.startX,J.currentX),te=Math.max(J.startX,J.currentX),de=Math.min(J.startY,J.currentY),Q=Math.max(J.startY,J.currentY);if(te-me<=5&&Q-de<=5)Te.value=null,_t();if(te-me>5||Q-de>5){let ee=K.value,W=(me-ee.x)/ee.scale,fe=(te-ee.x)/ee.scale,$e=(de-ee.y)/ee.scale,xt=(Q-ee.y)/ee.scale,F=[];for(let ne of O.value.values()){let He=ne.position.x,ve=ne.position.y;if(He+ne.size.width>W&&He<fe&&ve+ne.size.height>$e&&ve<xt)F.push(ne.id)}if(F.length>0)Kv(F)}d(null)},[]);B(()=>{if(o)return;if(!l.current&&!m&&!h)return;l.current=!1,u.current=[],f(null),T(null)},[o,m,T,h]);let R=H(()=>{let M=x.current;if(!M)return;let J=M.value.trim();if(T(null),!J)return;let me={x:M.x,y:M.y};Iu({type:"text",points:[me],color:cp,width:Vw,text:J})},[T]);B(()=>{if(r!=="text"&&h)T(null)},[r,T,h]),B(()=>{let M=(Q,ee,W)=>{let fe=null;for(let $e of O.value.values()){if($e.id===W||$e.type==="group")continue;if(Q>=$e.position.x&&Q<=$e.position.x+$e.size.width&&ee>=$e.position.y&&ee<=$e.position.y+$e.size.height)fe=$e.id}return fe};function J(Q){if(!Be.value)return;let ee=b.current;if(!ee)return;let W=ee.getBoundingClientRect(),fe=K.value,$e=(Q.clientX-W.left-fe.x)/fe.scale,xt=(Q.clientY-W.top-fe.y)/fe.scale;Be.value={...Be.value,cursorX:$e,cursorY:xt,targetId:M($e,xt,Be.value.fromId)}}function me(){let Q=Be.value;if(!Q)return;Be.value=null;let ee=Q.targetId;if(!ee)return;if(Q.withLabel){Dt("Edge label","label text").then((W)=>{Eo(Q.fromId,ee,"relation",W??void 0)});return}Eo(Q.fromId,ee,"relation",void 0)}function te(Q){let ee=Be.value;if(!ee)return;if(Q.key==="Escape")Q.preventDefault(),Be.value=null;else if(Q.key==="l"||Q.key==="L")Q.preventDefault(),Be.value={...ee,withLabel:!ee.withLabel}}function de(){Be.value=null}return document.addEventListener("pointermove",J),document.addEventListener("pointerup",me),document.addEventListener("pointercancel",de),document.addEventListener("keydown",te),()=>{document.removeEventListener("pointermove",J),document.removeEventListener("pointerup",me),document.removeEventListener("pointercancel",de),document.removeEventListener("keydown",te)}},[b]);let Z=H((M)=>{if(o)return;let J=b.current;if(!J||M.target!==J||!n)return;let me=J.getBoundingClientRect(),te=K.value,de=(M.clientX-me.left-te.x)/te.scale,Q=(M.clientY-me.top-te.y)/te.scale;n(M,de,Q)},[o,b,n]),j=H((M)=>{M.preventDefault()},[]),k=H((M)=>{if(lp(M.target instanceof Element?M.target:null))return;M.preventDefault()},[]),V=H((M)=>{if(M.preventDefault(),E.current++,M.dataTransfer?.types.includes("Files")||j1(M.dataTransfer))y(!0)},[]),ge=H((M)=>{if(M.preventDefault(),M.dataTransfer)M.dataTransfer.dropEffect="copy"},[]),Ue=H((M)=>{if(M.preventDefault(),E.current--,E.current<=0)E.current=0,y(!1)},[]),se=H(async(M)=>{M.preventDefault(),y(!1),E.current=0;let J=b.current;if(!J||!M.dataTransfer)return;let me=J.getBoundingClientRect(),te=K.value,de=(M.clientX-me.left-te.x)/te.scale,Q=(M.clientY-me.top-te.y)/te.scale,ee=Array.from(M.dataTransfer.files);if(ee.length===0){let W=H1(M.dataTransfer);await w(W,de,Q);return}await Hr(ee,de,Q)},[b,w]);B(()=>{let M=async(J)=>{if(J.defaultPrevented)return;if(lp(J.target instanceof Element?J.target:null))return;if(lp(document.activeElement))return;let me=J.clipboardData?.getData("text/plain")??"",te=up(me);if(te.length===0)return;let de=b.current;if(!de)return;J.preventDefault();let Q=de.getBoundingClientRect(),ee=K.value,W=(Q.width/2-ee.x)/ee.scale,fe=(Q.height/2-ee.y)/ee.scale;await w(te,W,fe)};return document.addEventListener("paste",M),()=>{document.removeEventListener("paste",M)}},[b,w]);let le=Z1(O.value.values(),We.value,new Set(Su.value.keys())),pe=mn.value,Mn=pe?O.value.get(pe.groupId):void 0,Xt=pe?O.value.get(pe.nodeId):void 0,cn=null;if(p){let M=Math.min(p.startX,p.currentX),J=Math.min(p.startY,p.currentY),me=Math.abs(p.currentX-p.startX),te=Math.abs(p.currentY-p.startY);cn={position:"absolute",left:`${M}px`,top:`${J}px`,width:`${me}px`,height:`${te}px`,pointerEvents:"none"}}return i("div",{class:`canvas-viewport${fr()?" pan-mode":""}`,ref:b,tabIndex:0,onPointerDown:_,onPointerMove:P,onPointerLeave:()=>{c.current=null,Ga(null)},onPointerUp:q,onContextMenu:j,onDblClick:Z,onDragStart:k,onDragEnter:V,onDragOver:ge,onDragLeave:Ue,onDrop:se,style:{width:"100%",height:"100%",position:"relative",overflow:"hidden",cursor:r==="eraser"?"cell":r==="text"?"text":o||Be.value||a.current||At.value==="connect"?"crosshair":fr()?"grab":"default"},children:[i("div",{ref:N,class:"canvas-world",style:{transform:`matrix(${s.scale}, 0, 0, ${s.scale}, ${s.x}, ${s.y})`,transformOrigin:"0 0",position:"absolute",top:0,left:0},children:[i(tw,{},void 0,!1,void 0,this),i(Ew,{},void 0,!1,void 0,this),i(sw,{},void 0,!1,void 0,this),i(hw,{},void 0,!1,void 0,this),i(gw,{},void 0,!1,void 0,this),i(qw,{nodes:O,edges:Fe,onEdgeContextMenu:t},void 0,!1,void 0,this),Be.value&&i("div",{class:"edge-hint-pill","data-testid":"edge-hint",style:{left:`${Be.value.cursorX+14}px`,top:`${Be.value.cursorY+14}px`},children:[i("span",{class:"edge-hint-main",children:Be.value.targetId?"release to connect":"drag onto a node"},void 0,!1,void 0,this),i("span",{class:"edge-hint-keys",children:["esc cancels · L labels",Be.value.withLabel?" · label on":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),pe&&Mn&&Xt&&i("div",{class:"drop-pill","data-testid":"drop-pill",style:{left:`${Xt.position.x}px`,top:`${Xt.position.y+Xt.size.height+10}px`},children:[i("span",{class:"drop-pill-text",children:pe.mode==="add"?`release to add to ${String(Mn.data.title??"group")}`:`release to remove from ${String(Mn.data.title??"group")}`},void 0,!1,void 0,this),i("span",{class:"drop-pill-hint",children:pe.mode==="add"?"esc keeps it out":"esc keeps it in"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(ap,{annotations:Array.from(pr.value.values())},void 0,!1,void 0,this),m&&m.points.length>=2&&i(ap,{annotations:[m]},void 0,!1,void 0,this),le.map((M)=>i(Uw,{node:M,onContextMenu:e,children:L1(M)},M.id,!1,void 0,this)),Uo.value&&i("svg",{class:"snap-guides-svg",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:Uo.value.map((M,J)=>M.axis==="x"?i("line",{x1:M.pos,y1:M.from-20,x2:M.pos,y2:M.to+20,class:"snap-guide-line"},J,!1,void 0,this):i("line",{x1:M.from-20,y1:M.pos,x2:M.to+20,y2:M.pos,class:"snap-guide-line"},J,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o&&i("div",{class:`annotation-capture-layer${r==="eraser"?" erasing":""}${r==="text"?" text":""}`,"aria-hidden":"true"},void 0,!1,void 0,this),h&&i("input",{class:"annotation-text-input",value:h.value,autoFocus:!0,style:{left:`${h.x*s.scale+s.x}px`,top:`${h.y*s.scale+s.y}px`,fontSize:`${Vw*s.scale}px`},onInput:(M)=>T({...h,value:M.target.value}),onBlur:R,onPointerDown:(M)=>M.stopPropagation(),onKeyDown:(M)=>{if(M.key==="Enter")M.preventDefault(),R();if(M.key==="Escape")M.preventDefault(),T(null)}},void 0,!1,void 0,this),cn&&i("div",{class:"lasso-rect",style:cn},void 0,!1,void 0,this),g&&i("div",{class:"drop-zone-overlay",children:i("div",{class:"drop-zone-indicator",children:[i("div",{class:"drop-zone-icon",children:"+"},void 0,!1,void 0,this),i("div",{class:"drop-zone-label",children:"Drop files or URLs to add to canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Oc({label:e,value:t,options:n,onChange:o,className:r="",above:s=!1}){let[a,c]=I(!1),l=z(null),u=z(null),p=z(null),d=()=>{c(!1),u.current?.focus()};return jt(()=>{if(!a)return;(p.current?.querySelector('[aria-checked="true"]:not(:disabled)')??p.current?.querySelector("button:not(:disabled)"))?.focus();let f=(h)=>{if(h.target instanceof Node&&!l.current?.contains(h.target))c(!1)};return document.addEventListener("pointerdown",f),()=>document.removeEventListener("pointerdown",f)},[a]),i("div",{ref:l,class:`choice-menu ${r}`,onBlur:(m)=>{if(m.relatedTarget instanceof Node&&!l.current?.contains(m.relatedTarget))c(!1)},onKeyDown:(m)=>{if(m.key!=="Tab"&&(m.key!=="Escape"||a))m.stopPropagation();if(m.key==="Escape"&&a)m.preventDefault(),m.stopPropagation(),d();if(["ArrowDown","ArrowUp","Home","End"].includes(m.key)){if(m.preventDefault(),m.stopPropagation(),!a){c(!0);return}let f=[...p.current?.querySelectorAll("button:not(:disabled)")??[]];if(!f.length)return;let h=f.findIndex((x)=>x===document.activeElement),v=m.key==="Home"?0:m.key==="End"?f.length-1:(h+(m.key==="ArrowUp"?-1:1)+f.length)%f.length;f[v]?.focus()}},children:[i("button",{ref:u,type:"button",class:"choice-menu-trigger","aria-label":e,"aria-haspopup":"menu","aria-expanded":a,onClick:()=>c(!a),children:[i("span",{children:n.find((m)=>m.value===t)?.label??e},void 0,!1,void 0,this),i(xr,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a&&i("div",{ref:p,role:"menu","aria-label":e,class:`toolbar-menu choice-menu-options${s?" opens-above":""}`,children:n.map((m)=>i("button",{type:"button",role:"menuitemradio",class:`toolbar-menu-item${m.value===t?" active":""}`,"aria-checked":m.value===t,disabled:m.disabled,tabIndex:-1,"data-value":m.value,onClick:()=>{o(m.value),d()},children:[i("span",{children:m.label},void 0,!1,void 0,this),m.value===t&&i("span",{class:"toolbar-menu-check","aria-hidden":"true",children:"✓"},void 0,!1,void 0,this)]},m.value,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Jw(){let e=[...Ae.value],t=O.value,[n,o]=I(""),[r,s]=I(!1),a=pw.value,[c,l]=I(null),u=a.length>=2,p=!u&&a.length===1&&a[0].steerable?a[0]:null,d=u?c?a.find((h)=>h.value===c&&h.steerable)??null:null:p,m=d?.value??null,f=async()=>{let h=n.trim();if(!h||r)return;s(!0);let v=await Tw(h,m);if(s(!1),v)o("")};return i("div",{class:"command-bar","data-testid":"command-bar",children:[e.length>0&&i("div",{class:"command-bar-chips","aria-label":"Pinned context",children:[e.map((h)=>{let v=t.get(h),x=typeof v?.data.title==="string"&&v.data.title.trim()?v.data.title:v?.type??h;return i("span",{class:"command-bar-chip","data-node-id":h,children:[i("span",{class:"command-bar-chip-glyph","aria-hidden":"true",children:"✦"},void 0,!1,void 0,this),i("span",{class:"command-bar-chip-label",title:x,children:x},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-chip-unpin","aria-label":`Unpin ${x}`,title:"Remove from context",onClick:()=>Xn(h),children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},h,!0,void 0,this)}),i("span",{class:"command-bar-chips-note",children:"in agent context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"command-bar-composer",children:[i(wr,{size:15,class:"command-bar-icon"},void 0,!1,void 0,this),u&&i(Oc,{className:"command-bar-target",label:"Steer which agent",value:m??"",above:!0,onChange:(h)=>l(h||null),options:[{value:"",label:"All agents"},...a.map((h)=>{let v=h.pendingSteers&&h.pendingSteers>0?` · ${h.pendingSteers} queued`:"",x=h.polling?" · polling":"";return{value:h.value,disabled:!h.steerable,label:h.attached?`${h.label}${x}${v}`:h.steerable?`${h.label} · writer${x}${v}`:`${h.label} · no inbox`}})]},void 0,!1,void 0,this),i("input",{class:"command-bar-input",type:"text",value:n,placeholder:`Steer ${d?.label??"the agent"}, or ${Ve("K")} to search the board…`,"aria-label":"Steer the agent",disabled:r,onInput:(h)=>o(h.target.value),onKeyDown:(h)=>{if(h.key==="Enter")h.preventDefault(),f()}},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-send",disabled:r||!n.trim(),onClick:()=>void f(),children:r?"Sending…":"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var dp=De(()=>{if(Ot.value==="disconnected")return"reconnecting";if(Ot.value==="connected"&&!Et.value&&zo.value>1)return"resyncing";return null});function Kw(){let e=dp.value;if(!e)return null;if(e==="reconnecting"){let t=Po.value,n=No.value;return i("div",{class:"connection-banner is-reconnecting",role:"status","data-testid":"connection-banner",children:[i("span",{class:"connection-banner-glyph","aria-hidden":"true",children:"↻"},void 0,!1,void 0,this),i("span",{class:"connection-banner-text",children:[i("b",{children:"Reconnecting…"},void 0,!1,void 0,this)," live updates are paused; edits still save, the board may be stale until the stream returns."]},void 0,!0,void 0,this),i("span",{class:"connection-banner-meta",children:[t>0?`retry ${t}`:"retrying",n>0?` · ${Math.max(1,Math.round(n/1000))}s`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}return i("div",{class:"connection-banner is-resyncing",role:"status","data-testid":"connection-banner",children:[i("span",{class:"connection-banner-glyph","aria-hidden":"true",children:"⟳"},void 0,!1,void 0,this),i("span",{class:"connection-banner-text",children:[i("b",{children:"Resyncing from snapshot"},void 0,!1,void 0,this)," — the event cursor went stale; the board reloads without losing local edits."]},void 0,!0,void 0,this),i("span",{class:"connection-banner-progress","aria-hidden":"true",children:i("span",{class:"connection-banner-progress-fill"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var U1={markdown:{width:520,height:360},group:{width:600,height:400},html:{width:720,height:640},image:{width:720,height:520},file:{width:720,height:600},webpage:{width:520,height:420}};async function Gt(e){if(e.x!==void 0&&e.y!==void 0)return tn(e);let t=U1[e.type]??{width:360,height:200},n=e.width??t.width,o=e.height??t.height,r=qn(),s=K.value,a=await tn({...e,width:n,height:o,x:Math.round((r.x-s.x)/s.scale-n/2),y:Math.round((r.y-s.y)/s.scale-o/2)});if(a.ok&&a.id)Ye(a.id);return a}var Dc=!1,Yw=!1,qo=null,Vr=null;function pp(){return Dc}function Fc(){Dc=!1,Yw=!0,Qw()}function Qw(){if(qo&&Vr)qo.removeEventListener("change",Vr);qo=null,Vr=null}function q1(){if(typeof window>"u"||!window.location)return null;let e=new URLSearchParams(window.location.search).get("theme");if(e==="auto")return"auto";return Pi(e)?e:null}function e_(e){if(Yw)return;let t=q1();if(!t)return;if(Qw(),Dc=!0,t!=="auto"){e(t);return}qo=window.matchMedia("(prefers-color-scheme: light)"),Vr=()=>{if(Dc&&qo)e(qo.matches?"light":"dark")},Vr(),qo.addEventListener("change",Vr)}var W1='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Rt(e,t,n={}){B(()=>{if(!t)return;let o=e.current;if(!o)return;let r=document.activeElement,s=n.restoreTo,a=()=>Array.from(o.querySelectorAll(W1)),c=n.initial?.current??a()[0];if(c&&!o.contains(document.activeElement))c.focus();let l=(u)=>{if(u.key!=="Tab")return;let p=a();if(p.length===0)return;let d=p[0],m=p[p.length-1],f=document.activeElement;if(u.shiftKey&&(f===d||!o.contains(f)))u.preventDefault(),m.focus();else if(!u.shiftKey&&f===m)u.preventDefault(),d.focus()};return o.addEventListener("keydown",l),()=>{if(o.removeEventListener("keydown",l),s)requestAnimationFrame(()=>s()?.focus());else if(r&&document.contains(r)&&r!==document.body)r.focus()}},[e,t,n.initial,n.restoreTo])}function V1(e,t){let n=e.toLowerCase(),o=t.toLowerCase(),r=[],s=0,a=0,c=-1;for(let l=0;l<o.length&&s<n.length;l++)if(o[l]===n[s]){if(r.push(l),a+=c===l-1?10:1,l===0||o[l-1]===" "||o[l-1]==="-"||o[l-1]==="_")a+=5;c=l,s++}return{match:s===n.length,score:a,indices:r}}function G1(e,t){if(t.length===0)return e;let n=[],o=0;for(let r of t){if(r>o)n.push(e.slice(o,r));n.push(i("mark",{children:e[r]},r,!1,void 0,this)),o=r+1}if(o<e.length)n.push(e.slice(o));return n}var mp={md:"markdown",app:"mcp-app",web:"webpage",ui:"json-render",chart:"graph",ctx:"context",log:"ledger"};function X1(e){let t=e.toLowerCase().trim();if(t.startsWith("type:")){let n=t.slice(5).trim(),r=Object.keys(dt).find((a)=>a.startsWith(n));if(r)return{typeFilter:r,remaining:""};let s=mp[n];if(s)return{typeFilter:s,remaining:""}}if(mp[t])return{typeFilter:mp[t],remaining:""};return{typeFilter:null,remaining:e}}function t_({onClose:e,onToggleMinimap:t}){let[n,o]=I(""),[r,s]=I(0),[a,c]=I([]),[l,u]=I("idle"),p=z(null),d=z(null),m=z(null);Rt(m,!0,{initial:p}),B(()=>{setTimeout(()=>p.current?.focus(),30)},[]),B(()=>{let b=n.trim();if(b.length<2){c([]),u("idle");return}let T=!0;u("loading");let w=window.setTimeout(()=>void Y("paletteLibrarySearch",`/api/canvas/search?q=${encodeURIComponent(b)}&scope=library&limit=12`,null).then((_)=>{if(!T)return;if(!_){c([]),u("error");return}c(_.results??[]),u("idle")}),150);return()=>{T=!1,window.clearTimeout(w)}},[n]);let f=H(()=>{let b=[];for(let w of O.value.values()){let _=w.data.title||dt[w.type],P=w.data.content||w.data.path||"",q=w.type==="group"&&Array.isArray(w.data.children)?w.data.children.length:0;b.push({id:`node:${w.id}`,kind:"node",label:_,description:w.type==="group"?`group · ${q} node${q===1?"":"s"}`:P.length>60?`${dt[w.type].toLowerCase()} · ${P.slice(0,60)}…`:P?`${dt[w.type].toLowerCase()} · ${P}`:dt[w.type].toLowerCase(),icon:sn(w.type),nodeType:w.type,action:()=>{Ye(w.id),e()}})}let T=[{label:"New markdown note",shortcut:"M",icon:Qn,iconTone:"accent",action:()=>{Gt({type:"markdown",title:"New note",width:520,height:360}),e()}},{label:"Link to board…",icon:sn("board"),iconTone:"accent",action:()=>{window.dispatchEvent(new CustomEvent("pmx-open-board-link")),e()}},...bt.value?[]:[{label:"Start agent session",icon:wr,iconTone:"purple",action:()=>{uo(),e()}}],{label:"Fit view",shortcut:"F",icon:ya,iconTone:"muted",action:()=>{vr(it().width,it().height),e()}},{label:"Auto-arrange (grid)",icon:An,iconTone:"muted",action:()=>{fa(),e()}},{label:"Auto-arrange (graph-aware)",icon:An,iconTone:"muted",action:()=>{ha(),e()}},{label:"Toggle minimap",icon:ba,iconTone:"muted",action:()=>{t(),e()}},{label:"Toggle theme (dark/light)",icon:xa,iconTone:"muted",action:()=>{let w=nt.value==="dark"?"light":"dark";Fc(),document.documentElement.setAttribute("data-theme",w),Fr(),nt.value=w,ta(w),e()}}];for(let w of T)b.push({id:`action:${w.label}`,kind:"action",label:w.label,...w.shortcut?{shortcut:w.shortcut}:{},icon:w.icon,...w.iconTone?{iconTone:w.iconTone}:{},action:w.action});return b},[e,t]),{typeFilter:h,remaining:v}=X1(n),x=f(),g;if(!n.trim())g=x.map((b)=>({...b,score:0,indices:[]}));else{g=[];for(let b of x){if(h){if(b.kind!=="node"||b.nodeType!==h)continue;if(!v){g.push({...b,score:0,indices:[]});continue}}let T=V1(v||n,b.label);if(T.match)g.push({...b,score:T.score,indices:T.indices})}g.sort((b,T)=>T.score-b.score)}for(let b of a)g.push({id:`library:${b.boardId}:${b.cardId}`,kind:"library",label:b.title||b.boardTitle,description:`${b.boardTitle} · ${b.snippet}`,icon:sn("board"),score:0,indices:[],action:()=>{(async()=>{if(await Nt(b.boardId),Ne.value!==b.boardId)return;for(let T=0;T<40&&Ne.value===b.boardId;T++){if(O.value.has(b.cardId)){Ye(b.cardId),e();return}await new Promise((w)=>window.setTimeout(w,25))}})()}});g=[...g.filter((b)=>b.kind==="action"),...g.filter((b)=>b.kind==="node"),...g.filter((b)=>b.kind==="library")];let y=g.findIndex((b)=>b.kind==="node"),E=g.findIndex((b)=>b.kind==="library");B(()=>{if(!n.trim()){Sn.value=null;return}let b=new Set;for(let T of g)if(T.kind==="node")b.add(T.id.slice(5));Sn.value=b.size>0?b:null},[n,g]),B(()=>()=>{Sn.value=null},[]);let D=Math.min(r,Math.max(0,g.length-1)),N=H((b)=>{if(b.key==="ArrowDown")b.preventDefault(),s((T)=>Math.min(T+1,g.length-1));else if(b.key==="ArrowUp")b.preventDefault(),s((T)=>Math.max(T-1,0));else if(b.key==="Enter"){if(b.preventDefault(),g[D])g[D].action()}else if(b.key==="Escape")b.preventDefault(),b.stopPropagation(),e()},[g,D,e]);return B(()=>{let b=d.current;if(!b)return;b.children[D]?.scrollIntoView({block:"nearest"})},[D]),B(()=>{s(0)},[n]),i("div",{class:"command-palette-backdrop",onMouseDown:e,children:i("div",{ref:m,class:"command-palette",role:"dialog","aria-modal":"true","aria-label":"Search and commands",onMouseDown:(b)=>b.stopPropagation(),children:[i("div",{class:"command-palette-search",children:[i("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{ref:p,type:"text",class:"command-palette-input",value:n,onInput:(b)=>o(b.target.value),onKeyDown:N,placeholder:"Search nodes, run actions, jump to…","aria-label":"Search nodes, run actions, jump to"},void 0,!1,void 0,this),i("kbd",{class:"command-palette-esc",children:"esc"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"command-palette-results",ref:d,children:[l==="loading"&&i("div",{class:"command-palette-empty",role:"status",children:"Searching all boards…"},void 0,!1,void 0,this),l==="error"&&i("div",{class:"command-palette-empty",role:"alert",children:"Library search is unavailable."},void 0,!1,void 0,this),g.length===0&&l!=="loading"&&i("div",{class:"command-palette-empty",children:"No matching nodes, boards, or actions"},void 0,!1,void 0,this),g.map((b,T)=>{let w=b.icon,_=T===0&&b.kind==="action"?"Actions":T===y?"Jump to":T===E?"Across boards":null;return i("div",{class:"command-palette-row",children:[_&&i("div",{class:"command-palette-group",children:_},void 0,!1,void 0,this),i("button",{type:"button",class:`command-palette-item${T===D?" selected":""}`,onMouseEnter:()=>s(T),onClick:()=>b.action(),children:[i("span",{class:`command-palette-icon tone-${b.iconTone??"kind"}`,"aria-hidden":"true",children:i(w,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"command-palette-label",children:[b.indices.length>0?G1(b.label,b.indices):b.label,b.description&&i("span",{class:"command-palette-desc",children:[" — ",b.description]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),b.shortcut&&i("kbd",{class:"command-palette-kbd",children:b.shortcut},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},b.id,!0,void 0,this)})]},void 0,!0,void 0,this),i("div",{class:"command-palette-hint",children:[i("span",{children:"↑↓ navigate"},void 0,!1,void 0,this),i("span",{children:"↵ open"},void 0,!1,void 0,this),i("span",{children:"esc close"},void 0,!1,void 0,this),i("span",{children:"type: filter"},void 0,!1,void 0,this),i("span",{class:"command-palette-hint-spacer"},void 0,!1,void 0,this),i("span",{children:Ve("K")},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function n_({onClose:e}){let t=z(null),n=z(null),[o,r]=I(""),[s,a]=I("");Rt(t,!0,{initial:n});let c=Pt.value.filter((u)=>u.id!==Ne.value&&u.name.toLowerCase().includes(o.trim().toLowerCase())),l=async(u)=>{let p=Pt.value.find((h)=>h.id===u);if(!p)return a("That board is no longer available.");let d=qn(),m=K.value;if(!(await Y("createBoardLink","/api/canvas/node",{},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"board",title:p.name,x:Math.round((d.x-m.x)/m.scale-180),y:Math.round((d.y-m.y)/m.scale-100),width:360,height:200,data:{boardId:u}})})).ok)return a("Could not create the board link.");e()};return i("div",{class:"text-prompt-backdrop",onMouseDown:e,children:i("div",{ref:t,class:"text-prompt board-link-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"board-link-title",onMouseDown:(u)=>u.stopPropagation(),children:[i("h2",{id:"board-link-title",children:"Link to a board"},void 0,!1,void 0,this),i("input",{ref:n,type:"search",class:"text-prompt-input","aria-label":"Find a board to link",placeholder:"Find a board…",value:o,onInput:(u)=>r(u.currentTarget.value)},void 0,!1,void 0,this),s&&i("div",{role:"alert",class:"board-copy-error",children:s},void 0,!1,void 0,this),i("ul",{class:"board-link-results",children:[c.map((u)=>i("li",{children:i("button",{type:"button",onClick:()=>void l(u.id),children:[i("span",{children:u.name},void 0,!1,void 0,this),i("small",{children:[u.nodeCount," nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},u.id,!1,void 0,this)),c.length===0&&i("li",{class:"board-copy-status",children:Pt.value.length<=1?"Create another board first, then link it here.":"No boards match your search."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"text-prompt-actions",children:i("button",{type:"button",onClick:e,children:"Cancel"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function o_(){let[e,t]=I(null),n=H((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"node",x:a.clientX,y:a.clientY,nodeId:c})},[]),o=H((a,c,l)=>{a.preventDefault(),a.stopPropagation(),t({kind:"canvas",x:a.clientX,y:a.clientY,canvasX:c,canvasY:l})},[]),r=H((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"edge",x:a.clientX,y:a.clientY,edgeId:c})},[]),s=H(()=>t(null),[]);return B(()=>{if(!e)return;let a=()=>t(null),c=(l)=>{if(l.key==="Escape")t(null)};return document.addEventListener("click",a),document.addEventListener("keydown",c),()=>{document.removeEventListener("click",a),document.removeEventListener("keydown",c)}},[e]),{menu:e,openNodeMenu:n,openCanvasMenu:o,openEdgeMenu:r,closeMenu:s}}var J1="#4bbcFF",K1=[{label:"Blue",value:"#3b82f6"},{label:"Green",value:"#22c55e"},{label:"Yellow",value:"#eab308"},{label:"Red",value:"#ef4444"},{label:"Gray",value:"#6b7280"},{label:"Purple",value:"#a855f7"}];function r_({menu:e,onClose:t}){let n;if(e.kind==="node"){let c=O.value.get(e.nodeId);if(!c)return null;n=oA(c)}else if(e.kind==="edge"){let c=e.edgeId,l=Fe.value.get(c);n=[{label:l?.label?`Edit label “${l.label.slice(0,18)}${l.label.length>18?"…":""}”`:"Add label…",action:()=>{Dt("Edge label (empty clears it)","label text",{initial:l?.label??"",allowEmpty:!0,confirm:"Save"}).then((u)=>{if(u===null)return;sa(c,{label:u})})}},{separator:!0},...["flow","depends-on","relation","references"].map((u)=>({label:`${l?.type===u?"✓":" "} ${u}`,action:()=>void sa(c,{type:u})})),{separator:!0},...["solid","dashed","dotted"].map((u)=>({label:`${(l?.style??"solid")===u?"✓":" "} ${u}`,action:()=>void sa(c,{style:u})})),{separator:!0},{label:"Delete edge",danger:!0,action:()=>void aa(c)}]}else n=nA(e.canvasX,e.canvasY);let o=new Map,r=n.some((c)=>c.render)?n.length*32+168:n.length*32+8,s=Math.min(e.x,Math.max(12,window.innerWidth-240)),a=Math.min(e.y,Math.max(12,window.innerHeight-r));return i("div",{class:"context-menu",style:{position:"fixed",left:`${s}px`,top:`${a}px`,zIndex:1e4},onPointerDown:(c)=>c.stopPropagation(),onClick:(c)=>c.stopPropagation(),children:n.map((c)=>{let l=c.separator?"separator":c.render?"custom":`${c.label??"item"}:${c.shortcut??""}`,u=(o.get(l)??0)+1;o.set(l,u);let p=`${l}:${u}`;if(c.separator)return i("div",{class:"context-menu-separator"},p,!1,void 0,this);if(c.render)return i("div",{class:"context-menu-custom",children:c.render(t)},p,!1,void 0,this);return i("button",{type:"button",class:`context-menu-item${c.danger?" is-danger":""}`,onClick:()=>{c.action?.(),t()},children:[i("span",{class:"context-menu-label",children:c.label},void 0,!1,void 0,this),c.shortcut&&i("span",{class:"context-menu-shortcut",children:c.shortcut},void 0,!1,void 0,this)]},p,!0,void 0,this)})},void 0,!1,void 0,this)}function Y1(e){return(typeof e.data.path==="string"?e.data.path.trim():"")||null}function Bc(e){let t=e.trim().toLowerCase(),n=t.match(/^#([0-9a-f]{3})$/);if(n){let[o,r,s]=n[1].split("");return`#${o}${o}${r}${r}${s}${s}`}return t}function i_(e){if(typeof e.data.color!=="string"||!e.data.color.trim())return null;return Bc(e.data.color)}function Q1(e){let t=i_(e);return t&&/^#[0-9a-f]{6}$/.test(t)?t:Bc(J1)}function fp(e,t){let n=t?Bc(t):null;at(e.id,{data:{...e.data,color:n}}),mt(e.id,{data:{color:n}})}function eA(e,t){let n=i_(e);return i("div",{class:"context-menu-section",children:[i("div",{class:"context-menu-section-header",children:[i("span",{class:"context-menu-section-label",children:"Group color"},void 0,!1,void 0,this),i("button",{type:"button",class:"context-menu-reset",onClick:()=>{fp(e,null),t()},children:"Theme default"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"context-menu-color-grid",children:K1.map((o)=>{let r=Bc(o.value);return i("button",{type:"button",class:`context-menu-color-swatch${n===r?" active":""}`,"aria-label":`Set group color to ${o.label}`,title:o.label,style:{"--swatch-color":o.value},onClick:()=>{fp(e,o.value),t()},children:[i("span",{class:"context-menu-color-dot",style:{"--swatch-color":o.value}},void 0,!1,void 0,this),i("span",{children:o.label},void 0,!1,void 0,this)]},o.value,!0,void 0,this)})},void 0,!1,void 0,this),i("label",{class:"context-menu-color-custom",children:[i("span",{children:"Custom"},void 0,!1,void 0,this),i("input",{type:"color",class:"context-menu-color-input","aria-label":"Custom group color",value:Q1(e),onClick:(o)=>o.stopPropagation(),onInput:(o)=>{fp(e,o.currentTarget.value),t()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function gp(e,t,n,o){return{x:e-n/2,y:t-o/2}}function tA(e,t){return e.trim().replace(/[?#].*$/,"").split("/").filter(Boolean).at(-1)||t}async function hp(e){let t=await Dt(e.promptLabel,e.placeholder??"");if(!t)return;let n=t.trim();if(!n)return;let o=gp(e.canvasX,e.canvasY,e.width,e.height);if(!(await tn({type:e.type,...e.type!=="webpage"?{title:tA(n,e.titleFallback)}:{},content:n,x:o.x,y:o.y,width:e.width,height:e.height})).ok)console.error(`[canvas-menu] ${e.errorMessage}`)}function nA(e,t){return[{label:"New note",action:()=>{let r=gp(e,t,520,360);tn({type:"markdown",title:"New note",x:r.x,y:r.y,width:520,height:360})}},{label:"Open webpage...",action:()=>{hp({promptLabel:"Webpage URL:",type:"webpage",canvasX:e,canvasY:t,width:520,height:420,placeholder:"https://example.com",titleFallback:"Webpage",errorMessage:"Could not create webpage node. Enter a valid http(s) URL."})}},{label:"Open file...",action:()=>{hp({promptLabel:"Workspace path or absolute file path:",type:"file",canvasX:e,canvasY:t,width:720,height:500,placeholder:"src/server/server.ts",titleFallback:"File",errorMessage:"Could not create file node. Check the path and try again."})}},{label:"Open image...",action:()=>{hp({promptLabel:"Image path, URL, or data URI:",type:"image",canvasX:e,canvasY:t,width:480,height:360,placeholder:"artifacts/architecture.png",titleFallback:"Image",errorMessage:"Could not create image node. Check the image source and try again."})}},{label:"Link to board…",action:()=>window.dispatchEvent(new CustomEvent("pmx-open-board-link"))},{separator:!0},{label:"New group",action:()=>{let r=gp(e,t,600,400);lr({title:"Group",x:r.x,y:r.y,width:600,height:400})}}]}function oA(e){let t=[],n=Y1(e);if(t.push({label:"Focus",action:()=>Ye(e.id)}),t.push({label:"Rename…",action:()=>{Dt("Rename node","Node title",{initial:typeof e.data.title==="string"?e.data.title:"",confirm:"Save"}).then((l)=>{if(!l?.trim())return;mt(e.id,{title:l.trim()})})}}),pi.has(e.type))t.push({label:"Expand",shortcut:"⤢",action:()=>Ut(e.id)});t.push({label:e.collapsed?"Expand":"Collapse",action:()=>hr(e.id)});let o=Ae.value.has(e.id);t.push({label:o?"Unpin from context":"Pin as context",action:()=>Xn(e.id)}),t.push({label:e.pinned?"Unlock position":"Lock position (no auto-arrange)",action:()=>{let l=!e.pinned;at(e.id,{pinned:l}),mt(e.id,{pinned:l}),ct()}});let r=xi.value;if(r&&r.from!==e.id){let l=O.value.get(r.from),u=l?(l.data.title||l.id).slice(0,20):r.from;t.push({label:`Connect from "${u}"`,action:()=>{Eo(r.from,e.id,"relation"),xi.value=null}})}t.push({label:r?"Connect from here (replace)":"Connect from here",action:()=>{xi.value={from:e.id}}});let s=Array.from(Fe.value.values()).filter((l)=>l.from===e.id||l.to===e.id).length;if(s>0)t.push({label:`${s} edge${s!==1?"s":""} connected`});if(t.push({separator:!0}),(e.type==="markdown"||e.type==="file"||e.type==="image")&&n)t.push({label:"Open in browser",action:()=>{window.open(`/artifact?path=${encodeURIComponent(n)}`,"_blank","noopener")}}),t.push({label:"Copy path",action:()=>{navigator.clipboard.writeText(n)}});if(e.type==="mcp-app"||e.type==="json-render"||e.type==="graph")if(e.data.chartConfig){let l=e.data.chartConfig.title||"chart";t.push({label:"Copy chart data",action:()=>{navigator.clipboard.writeText(JSON.stringify(e.data.chartConfig,null,2))}})}else{let l=e.data.url;if(t.push({label:"Open in browser",action:()=>{if(l)window.open(l,"_blank")}}),t.push({label:"Focus in TUI",action:()=>zv("mcp-app-focus",{url:l})}),e.type==="json-render"||e.type==="graph")t.push({label:"Copy spec",action:()=>{navigator.clipboard.writeText(JSON.stringify(e.data.spec??e.data.graphConfig??{},null,2))}})}if(e.type==="webpage"){let l=typeof e.data.url==="string"?e.data.url:"";t.push({label:"Refresh webpage",action:()=>{oa(e.id)}}),t.push({label:"Open in browser",action:()=>{if(l)window.open(l,"_blank","noopener")}}),t.push({label:"Copy URL",action:()=>{if(l)navigator.clipboard.writeText(l)}})}if(e.type==="group"){let l=e.data.children??[];if(t.push({separator:!0}),t.push({render:(u)=>eA(e,u)}),l.length>0)t.push({label:`Ungroup (${l.length} node${l.length!==1?"s":""})`,action:()=>{Jn(e.id),ur(e.id)}})}let a=typeof e.data.parentGroup==="string"?e.data.parentGroup:null,c=a?O.value.get(a):void 0;if(c&&c.type==="group"){let l=typeof c.data.title==="string"&&c.data.title?c.data.title:"frame",u=Array.isArray(c.data.children)?c.data.children.filter((p)=>p!==e.id):[];t.push({label:`Remove from “${l}”`,action:()=>{ia(c.id,u)}})}return t.push({separator:!0}),t.push({label:e.type==="group"?"Delete frame (children stay)":"Delete",danger:!0,action:()=>{Vn(e.id)}}),t}function s_(){let e=Ae.value.size;if(e===0||dn.value)return null;return i("div",{class:"context-pin-bar",children:[i("span",{class:"context-pin-bar-count",children:["✦"," ",e," node",e!==1?"s":""," in context"]},void 0,!0,void 0,this),i("button",{type:"button",class:"context-pin-bar-btn context-pin-bar-clear",onClick:iy,title:"Clear all context pins","aria-label":"Clear all context pins",children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function a_({onClose:e}){let t=z(null),[n,o]=I("Bug report"),[r,s]=I(""),[a,c]=I("");return Rt(t,!0),i("div",{class:"text-prompt-backdrop feedback-backdrop",onPointerDown:e,children:i("form",{ref:t,class:"text-prompt feedback-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"feedback-title","aria-describedby":"feedback-privacy",action:"https://github.com/pskoett/pmx-canvas/issues/new",method:"get",target:"_blank",rel:"noopener noreferrer",onPointerDown:(l)=>l.stopPropagation(),onKeyDown:(l)=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),e()},children:[i("div",{id:"feedback-title",class:"text-prompt-title",children:"Bug and feedback"},void 0,!1,void 0,this),i("p",{id:"feedback-privacy",class:"feedback-note",children:"Opens a draft issue in pskoett/pmx-canvas. Review and submit it on GitHub using your account. Issues are public. Only what you enter below is included; no board contents, workspace paths, screenshots, or logs are attached."},void 0,!1,void 0,this),i("div",{class:"feedback-field",children:[i("span",{children:"Feedback type"},void 0,!1,void 0,this),i(Oc,{label:"Feedback type",value:n,onChange:o,options:["Bug report","Feature request","General feedback"].map((l)=>({value:l,label:l}))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("label",{children:["Title",i("input",{class:"text-prompt-input",name:"title",required:!0,maxLength:120,value:r,onInput:(l)=>s(l.currentTarget.value),placeholder:"A short summary"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("label",{children:["Description",i("textarea",{class:"text-prompt-input",required:!0,maxLength:1200,rows:6,value:a,onInput:(l)=>c(l.currentTarget.value),placeholder:"What happened, what you expected, and steps to reproduce — or describe your idea."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{type:"hidden",name:"body",value:`## ${n}
|
|
330
330
|
|
|
331
|
-
${a.trim()}`},void 0,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:e,children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"submit",class:"text-prompt-confirm",disabled:!r.trim()||!a.trim(),children:["Continue on GitHub ",i(mn,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function qr(e,t){console.error(`[tool-rail] ${e} failed`,t)}function Rn(e){let t={image:{message:"Image URL (https://… or data:image/…)",placeholder:"https://example.com/diagram.png"},file:{message:"Workspace file path",placeholder:"src/server/server.ts"},webpage:{message:"Page URL",placeholder:"https://example.com"}};Lt(t[e].message,t[e].placeholder).then((n)=>{if(!n)return;Ft({type:e,content:n}).catch((o)=>qr(`create ${e}`,o))})}function nt({label:e,shortcut:t,detail:n,ariaLabel:o,active:r,menuOpen:s,onClick:a,btnRef:c,children:l}){let[u,p]=I(null),d=(h)=>{let v=h.currentTarget.getBoundingClientRect();p({left:v.right+10,top:v.top+v.height/2})},f=()=>p(null),m=o??(t?`${e} (${t})`:n?`${e} (${n})`:e);return i(pe,{children:[i("button",{ref:c,type:"button",class:`rail-btn${r?" active":""}`,"aria-label":m,"aria-pressed":r===void 0?void 0:r,onClick:(h)=>{f(),a(h)},onPointerEnter:d,onPointerLeave:f,onFocus:d,onBlur:f,children:l},void 0,!1,void 0,this),u&&!s&&i("span",{class:"toolbar-tooltip rail-tooltip",role:"tooltip","data-testid":"rail-tooltip",style:{left:`${u.left}px`,top:`${u.top}px`},children:[i("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),(t||n)&&i("span",{class:"toolbar-tooltip-meta",children:[t&&i("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this),n&&i("span",{children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function r_({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:r,onOpenPalette:s,onOpenShortcuts:a,annotationTool:c,onSetAnnotationTool:l}){let u=Et.value,p=dr.value,d=Array.from(F.value.values()).filter((z)=>z.type==="trace").length,f=De.value.size,[m,h]=I(!1),[v,x]=I(null),[g,y]=I(null),E=R(null),L=R(null),P=(z)=>(U)=>{if(v===z){x(null);return}let N=U.currentTarget.getBoundingClientRect();y({top:N.top,bottom:N.bottom,right:N.right}),x(z)},b=(z)=>g?z?{position:"fixed",left:`${g.right+8}px`,bottom:`${window.innerHeight-g.bottom}px`,top:"auto",right:"auto"}:{position:"fixed",left:`${g.right+8}px`,top:`${g.top}px`,right:"auto"}:void 0;B(()=>{if(!v)return;let z=(N)=>{if(E.current&&N.target instanceof Node&&!E.current.contains(N.target))x(null)},U=(N)=>{if(N.key==="Escape")x(null)};return document.addEventListener("pointerdown",z),document.addEventListener("keydown",U),()=>{document.removeEventListener("pointerdown",z),document.removeEventListener("keydown",U)}},[v]);let T=(z)=>{Lc(),document.documentElement.setAttribute("data-theme",z),Or(),tt.value=z,Ks(z),x(null)},w=dd(tt.value),_=(z,U={})=>{fetch(`/api/workbench/intent?_ts=${Date.now()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:z,payload:U})}).catch((N)=>qr("sendIntent",N))};return i(pe,{children:[i("div",{class:"tool-rail",ref:E,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[i(nt,{label:"Home",ariaLabel:"PMX Canvas — Home",onClick:()=>{x(null),zt(null).catch((z)=>qr("openHome",z))},children:i("span",{class:"rail-brand",children:i(xa,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Bug and feedback",menuOpen:m,onClick:()=>{x(null),h(!0)},children:i("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:[i("rect",{x:"4.5",y:"5",width:"7",height:"9",rx:"3.5"},void 0,!1,void 0,this),i("path",{d:"M6 5V4a2 2 0 0 1 4 0v1M8 8v6M2 4l2.5 2M14 4l-2.5 2M1.5 9h3M11.5 9h3M2 14l2.5-2M14 14l-2.5-2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-divider"},void 0,!1,void 0,this),i(nt,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>Et.value="select",children:i(Oy,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>Et.value="pan",children:i(Ly,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>Et.value="connect",children:i("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("circle",{cx:"4",cy:"4",r:"2"},void 0,!1,void 0,this),i("circle",{cx:"12",cy:"12",r:"2"},void 0,!1,void 0,this),i("path",{d:"M5.5 5.5 C 8 8, 8 8, 10.5 10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-divider"},void 0,!1,void 0,this),i(nt,{label:"Markdown note",shortcut:"M",onClick:()=>void Ft({type:"markdown",title:"New note",width:520,height:360}).catch((z)=>qr("create markdown",z)),children:i(Qn,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Image",shortcut:"I",onClick:()=>Rn("image"),children:i(Ru,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"File",shortcut:"Shift+F",onClick:()=>Rn("file"),children:i(fa,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Attach document",onClick:()=>L.current?.click(),children:i(Iy,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("input",{ref:L,type:"file",hidden:!0,multiple:!0,accept:".pdf,.ppt,.pptx,.xls,.xlsx,.doc,.docx,.odt,.ods,.odp","aria-label":"Attach documents",onChange:(z)=>{let U=rt(),N=K.value;Dr(Array.from(z.currentTarget.files??[]),(U.width/2-N.x)/N.scale,(U.height/2-N.y)/N.scale),z.currentTarget.value=""}},void 0,!1,void 0,this),i(nt,{label:"Webpage",shortcut:"W",onClick:()=>Rn("webpage"),children:i(gr,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"HTML surface",shortcut:"H",onClick:()=>void Ft({type:"html",title:"HTML surface"}).catch((z)=>qr("create html",z)),children:i(Dy,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Group",shortcut:"G",onClick:()=>void Ft({type:"group",title:"Group"}).catch((z)=>qr("create group",z)),children:i($u,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"toolbar-menu-anchor",children:[i(nt,{label:"Annotate",shortcut:"A",detail:"Draw · Text note · Eraser",active:c!==null,menuOpen:v==="annotate",onClick:P("annotate"),children:c==="eraser"?i(Pu,{},void 0,!1,void 0,this):c==="text"?i(Nu,{},void 0,!1,void 0,this):i(zu,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v==="annotate"&&i("div",{class:"toolbar-menu",style:b(!1),role:"menu","aria-label":"Annotate",children:[i("button",{type:"button",class:`toolbar-menu-item${c==="pen"?" active":""}`,onClick:()=>{l(c==="pen"?null:"pen"),x(null)},children:[i(zu,{},void 0,!1,void 0,this),i("span",{children:c==="pen"?"Stop annotating":"Draw (A)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:`toolbar-menu-item${c==="text"?" active":""}`,onClick:()=>{l(c==="text"?null:"text"),x(null)},children:[i(Nu,{},void 0,!1,void 0,this),i("span",{children:c==="text"?"Stop text notes":"Text note"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:`toolbar-menu-item${c==="eraser"?" active":""}`,onClick:()=>{l(c==="eraser"?null:"eraser"),x(null)},children:[i(Pu,{},void 0,!1,void 0,this),i("span",{children:c==="eraser"?"Stop erasing":"Eraser"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"rail-spacer"},void 0,!1,void 0,this),i(nt,{label:"Search & commands",shortcut:We("K"),onClick:s,children:i($y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Arrange",detail:f>0?"graph-aware":"grid",onClick:()=>f>0?pa():da(),children:i(En,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:p?"Disable trace":"Enable trace",active:p,onClick:()=>_("trace-toggle",{enabled:!p}),children:i(Ny,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),(p||d>0)&&i(nt,{label:"Clear trace",onClick:()=>_("trace-clear"),children:i(Ry,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:e?"Hide minimap":"Show minimap",active:e,onClick:t,children:i(ya,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Snapshots",active:n,onClick:o,btnRef:r,children:i(Py,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"toolbar-menu-anchor",children:[i(nt,{label:"Theme",detail:Er[w].label,menuOpen:v==="theme",ariaLabel:"Choose theme",active:v==="theme",onClick:P("theme"),children:Ar(w)==="dark"?i(zy,{},void 0,!1,void 0,this):i(ba,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v==="theme"&&i("div",{class:"toolbar-menu",style:b(!0),role:"menu","aria-label":"Theme",children:ud.map((z)=>i("button",{type:"button",role:"menuitemradio","aria-checked":w===z,class:`toolbar-menu-item${w===z?" active":""}`,onClick:()=>T(z),children:[i("span",{class:"theme-swatch",style:{background:Er[z].swatchBg},children:i("span",{class:"theme-swatch-dot",style:{background:Er[z].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{children:Er[z].label},void 0,!1,void 0,this),w===z&&i("span",{class:"toolbar-menu-check","aria-hidden":"true",children:"✓"},void 0,!1,void 0,this)]},z,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(nt,{label:"Shortcuts",shortcut:"?",onClick:a,children:i(My,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m&&i(o_,{onClose:()=>h(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function i_({onOpenPalette:e}){let t=R(null),n=()=>{Ft({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(r)=>{if(!r||r.length===0)return;let s=qn(),a=K.value;await Dr(Array.from(r),(s.x-a.x)/a.scale,(s.y-a.y)/a.scale)};return i("div",{class:"empty-state","data-testid":"empty-state",children:[i("svg",{class:"empty-state-mark",width:"52",height:"52",viewBox:"0 0 64 64",fill:"none","aria-hidden":"true",children:[i("rect",{x:"8",y:"8",width:"48",height:"48",rx:"7"},void 0,!1,void 0,this),i("rect",{x:"20",y:"20",width:"24",height:"24",rx:"4","stroke-dasharray":"4 4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{children:[i("div",{class:"empty-state-title",children:"Nothing on this board yet"},void 0,!1,void 0,this),i("div",{class:"empty-state-sub",children:"Drop files anywhere, paste a link, or start from a note."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"empty-state-grid",children:[i("button",{type:"button",class:"empty-state-action",onClick:n,children:[i(Qn,{size:16,class:"tone-accent"},void 0,!1,void 0,this),i("span",{class:"empty-state-action-label",children:"New markdown note"},void 0,!1,void 0,this),i("kbd",{children:"M"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"empty-state-action",onClick:()=>t.current?.click(),children:[i("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round",class:"tone-warn","aria-hidden":"true",children:[i("path",{d:"M8 10 V2 M8 2 L5 5 M8 2 L11 5"},void 0,!1,void 0,this),i("path",{d:"M2 10 V13 H14 V10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"empty-state-action-label",children:"Drop files"},void 0,!1,void 0,this),i("span",{class:"empty-state-action-hint",children:"or pick"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"empty-state-action",onClick:()=>Rn("webpage"),children:[i(gr,{size:16,class:"tone-ok"},void 0,!1,void 0,this),i("span",{class:"empty-state-action-label",children:"Paste a link"},void 0,!1,void 0,this),i("kbd",{children:We("V")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"empty-state-action is-agent",onClick:()=>void uo(),children:[i(yr,{size:16,class:"tone-purple"},void 0,!1,void 0,this),i("span",{class:"empty-state-action-label",children:"Start agent session"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"empty-state-hint",onClick:e,children:["? shortcuts · ",We("K")," palette"]},void 0,!0,void 0,this),i("input",{ref:t,type:"file",multiple:!0,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:(r)=>{let s=r.currentTarget;o(s.files).finally(()=>{s.value=""})}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var s_="From old snapshots";function a_(e){if(!e?.trim())return null;let t=e.split("/").map((n)=>n.trim());if(t.length>8)throw Error("Folders can be nested up to 8 levels.");if(t.some((n)=>!n||n==="."||n===".."||n.length>60))throw Error('Each folder name must be 1–60 characters, and cannot be "." or "..".');return t.join("/")}function yp(e){return e.split("/").map((t,n,o)=>o.slice(0,n+1).join("/"))}function c_({board:e,folders:t,onClose:n}){let o=R(null),[r,s]=I(e.category??""),[a,c]=I(""),[l,u]=I(!1),[p,d]=I("");Pt(o,!0),B(()=>{let h=(v)=>{if(v.key!=="Escape")return;if(v.preventDefault(),v.stopPropagation(),!l)n()};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[l,n]);let f=a.trim()?[r,a.trim()].filter(Boolean).join("/"):r,m=async()=>{let h;try{if(a.includes("/"))throw Error("Use one folder name; choose its parent above.");h=a_(f)}catch(v){d(v instanceof Error?v.message:String(v));return}if(u(!0),d(""),await Ta(e.id,{category:h}),At.value.find((v)=>v.id===e.id)?.category===h)n();else d("Could not move this board. Try again.");u(!1)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>!l&&n(),children:i("div",{ref:o,class:"text-prompt home-folder-dialog",role:"dialog","aria-modal":"true","aria-label":`Move ${e.name}`,onPointerDown:(h)=>h.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:["Move “",e.name,"”"]},void 0,!0,void 0,this),i("p",{class:"home-folder-hint",children:"Choose a folder, or create one inside it. The board keeps its content and links."},void 0,!1,void 0,this),i("fieldset",{class:"home-folder-options",disabled:l,children:[i("legend",{children:"Destination folder"},void 0,!1,void 0,this),["",...t].map((h)=>i("label",{class:"home-folder-option",style:{paddingLeft:`${8+Math.min(h.split("/").length-1,5)*14}px`},children:[i("input",{type:"radio",name:"folder-destination",value:h,checked:r===h,onChange:()=>{s(h),d("")}},void 0,!1,void 0,this),i("span",{children:h||"Home (no folder)"},void 0,!1,void 0,this)]},h,!0,void 0,this))]},void 0,!0,void 0,this),i("label",{class:"home-folder-new",children:["New folder inside ",r||"Home"," ",i("span",{class:"home-folder-hint",children:"(optional)"},void 0,!1,void 0,this),i("input",{class:"text-prompt-input","aria-label":"New folder name",placeholder:"e.g. Decisions",maxLength:60,value:a,disabled:l,onInput:(h)=>{c(h.currentTarget.value),d("")}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"home-folder-hint",children:["Move to: ",i("strong",{children:f||"Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p&&i("p",{role:"alert",children:p},void 0,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",disabled:l,onClick:n,children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"button",class:"text-prompt-confirm",disabled:l||f===(e.category??""),onClick:()=>void m(),children:l?"Moving…":"Move board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function l_({board:e,onClose:t}){let n=R(null),o=R(null),[r,s]=I(null),[a,c]=I(new Set),[l,u]=I(`${e.name} copy`),[p,d]=I(!0),[f,m]=I(!0),[h,v]=I(!1),[x,g]=I(""),[y,E]=I(!1);return Pt(n,!0,{initial:o}),B(()=>{let P=!0;return eb(e.id).then((b)=>{if(!P)return;if(!b||!Array.isArray(b.cards))return g("Could not load reusable cards. Try again.");s(b),c(new Set(b.cards.filter((T)=>T.reusable).map((T)=>T.id)))}),()=>{P=!1}},[e.id]),i("div",{class:"text-prompt-backdrop",onMouseDown:t,children:i("div",{ref:n,class:"text-prompt board-copy-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"board-copy-title",onMouseDown:(P)=>P.stopPropagation(),children:i("form",{onSubmit:async(P)=>{if(P.preventDefault(),!l.trim()||!r)return;E(!0),g("");let b=await tb({sourceBoardId:e.id,name:l.trim(),...e.category?{category:e.category}:{},nodeIds:[...a],includeReadme:p,includeStructure:f});if(E(!1),!b)return g("Could not create the board. Try a different name.");if(h)await zt(b.id);t()},children:[i("h2",{id:"board-copy-title",children:["Create from ",e.name]},void 0,!0,void 0,this),i("label",{class:"board-copy-field",children:["Board name",i("input",{ref:o,class:"text-prompt-input",value:l,onInput:(P)=>u(P.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!r&&!x&&i("div",{class:"board-copy-status",role:"status",children:"Loading reusable cards…"},void 0,!1,void 0,this),x&&i("div",{class:"board-copy-error",role:"alert",children:x},void 0,!1,void 0,this),r&&i("fieldset",{class:"board-copy-cards",children:[i("legend",{children:"Cards to copy"},void 0,!1,void 0,this),r.cards.filter((P)=>P.reusable).length===0?i("div",{class:"board-copy-status",children:"No reusable cards on this board."},void 0,!1,void 0,this):r.cards.filter((P)=>P.reusable).map((P)=>i("label",{class:"board-copy-card",children:[i("input",{type:"checkbox",checked:a.has(P.id),onChange:(b)=>{let T=new Set(a);b.currentTarget.checked?T.add(P.id):T.delete(P.id),c(T)}},void 0,!1,void 0,this),i("span",{children:[i("strong",{children:P.title||"Untitled card"},void 0,!1,void 0,this),i("small",{children:P.type},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},P.id,!0,void 0,this))]},void 0,!0,void 0,this),i("div",{class:"board-copy-options",children:[i("label",{children:[i("input",{type:"checkbox",checked:f,onChange:(P)=>m(P.currentTarget.checked)},void 0,!1,void 0,this)," ","Preserve groups and connections"]},void 0,!0,void 0,this),i("label",{children:[i("input",{type:"checkbox",checked:p,disabled:!r?.readmeNodeId,onChange:(P)=>d(P.currentTarget.checked)},void 0,!1,void 0,this)," ","Include README"]},void 0,!0,void 0,this),i("label",{children:[i("input",{type:"checkbox",checked:h,onChange:(P)=>v(P.currentTarget.checked)},void 0,!1,void 0,this)," Open the new board after creating"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("p",{class:"board-copy-note",children:"Only selected cards and structure are copied. Asks, history, and context pins start clear."},void 0,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",onClick:t,children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"submit",disabled:!r||!l.trim()||y,children:y?"Creating…":"Create board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Q1(e){if(!e)return"never opened";let t=Math.floor((Date.now()-new Date(e).getTime())/60000);if(t<1)return"just now";if(t<60)return`${t}m ago`;let n=Math.floor(t/60);if(n<24)return`${n}h ago`;let o=Math.floor(n/24);if(o<30)return`${o}d ago`;return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function u_(e){return`${e} node${e!==1?"s":""}`}async function bp(){let e=await Lt("New board","Board name",{confirm:"Create"});if(e)await Qy(e)}var d_="pmx-canvas-home-collapsed";function eA(){try{let e=localStorage.getItem(d_);if(e)return new Set(JSON.parse(e))}catch{}return new Set([s_])}function tA(e){try{localStorage.setItem(d_,JSON.stringify([...e]))}catch{}}function p_(){let e=At.value,[t,n]=I(null),[o,r]=I(null),[s,a]=I(null),[c,l]=I(""),[u,p]=I([]),[d,f]=I(eA),m=R(0),h=[...new Set(e.flatMap((_)=>_.category?yp(_.category):[]))].sort((_,z)=>_.localeCompare(z)),v=c.trim().toLocaleLowerCase(),x=e.filter((_)=>`${_.name} ${_.category??""}`.toLocaleLowerCase().includes(v)),g=new Set(x.flatMap((_)=>_.category?yp(_.category):[])),y=e.find((_)=>_.id===o),E=e.find((_)=>_.id===s);B(()=>{let _=c.trim();if(!_){p([]);return}let z=!1,U=window.setTimeout(()=>{Y("searchLibrary",`/api/canvas/search?q=${encodeURIComponent(_)}&scope=library&limit=30`,null).then((N)=>{if(!z)p(N?.results??[])})},150);return()=>{z=!0,window.clearTimeout(U)}},[c]);let L=async(_)=>{let z=++m.current;await zt(_.boardId);for(let U=0;U<40;U++){if(z!==m.current||Ne.value!==_.boardId)return;if(F.value.has(_.cardId)){Ke(_.cardId);return}await new Promise((N)=>window.setTimeout(N,25))}},P=(_)=>{let z=new Set(d);if(z.has(_))z.delete(_);else z.add(_);f(z),tA(z)},b=async(_)=>{let z=await Lt("Rename board","Board name",{initial:_.name,confirm:"Rename"});if(z&&z!==_.name)await Ta(_.id,{name:z})},T=(_)=>t===_.id?i("li",{class:"home-board is-confirming","data-testid":"home-board",children:[i("div",{class:"home-board-confirm-text",children:["Delete ",i("strong",{children:_.name},void 0,!1,void 0,this)," and its ",u_(_.nodeCount)," and snapshots? This can't be undone."]},void 0,!0,void 0,this),i("div",{class:"home-board-actions",children:[i("button",{type:"button",class:"home-board-action",onClick:()=>n(null),children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action is-danger",onClick:()=>{n(null),ob(_.id)},children:"Delete board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},_.id,!0,void 0,this):i("li",{class:"home-board","data-testid":"home-board",children:[i("button",{type:"button",class:"home-board-open",onClick:()=>void zt(_.id),children:[i("span",{class:"home-board-name",children:_.name},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[u_(_.nodeCount)," · ",Q1(_.lastOpenedAt)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"home-board-actions",children:[i("button",{type:"button",class:"home-board-action","aria-haspopup":"dialog",onClick:()=>r(_.id),children:"Move"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action","aria-haspopup":"dialog",onClick:()=>a(_.id),children:"Create from…"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>void b(_),children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>n(_.id),children:"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},_.id,!0,void 0,this),w=(_,z)=>{let U=h.filter((S)=>S.slice(0,S.lastIndexOf("/"))===_&&S.includes("/")),N=x.filter((S)=>S.category===_),Z=x.filter((S)=>S.category===_||S.category?.startsWith(`${_}/`)).length,j=!!v||!d.has(_);return i("section",{class:"home-section","data-testid":"home-section","data-folder":_,"aria-label":_,children:[i("button",{type:"button",class:"home-section-head","aria-expanded":j,onClick:()=>P(_),children:[i("svg",{class:"home-section-chevron",viewBox:"0 0 20 20",width:"18",height:"18",fill:"none","aria-hidden":"true",children:i("path",{d:"m7.5 4.75 5.25 5.25-5.25 5.25"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("svg",{class:"home-section-folder",viewBox:"0 0 20 20",width:"18",height:"18",fill:"none","aria-hidden":"true",children:i("path",{d:"M2.75 5.75A1.75 1.75 0 0 1 4.5 4h3l1.75 2h6.25a1.75 1.75 0 0 1 1.75 1.75v6.5A1.75 1.75 0 0 1 15.5 16h-11a1.75 1.75 0 0 1-1.75-1.75v-8.5Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"home-section-name",children:_.split("/").at(-1)},void 0,!1,void 0,this),i("span",{class:"home-section-count",children:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&i("div",{class:"home-folder-children",style:{marginLeft:z<5?"14px":"0"},children:[U.filter((S)=>g.has(S)).map((S)=>w(S,z+1)),N.length>0&&i("ul",{class:"home-view-list","aria-label":`Boards in ${_}`,children:N.map(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},_,!0,void 0,this)};return i("div",{class:"home-view","data-testid":"home-view",children:[i("div",{class:"home-view-inner",children:[i("div",{class:"home-view-head",children:[i("h1",{class:"home-view-title",children:"Boards"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-view-new",onClick:()=>void bp(),children:"New board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{class:"text-prompt-input home-search",type:"search","aria-label":"Find boards and folders",placeholder:"Find boards and folders…",value:c,onInput:(_)=>l(_.currentTarget.value)},void 0,!1,void 0,this),e.length===0?i("div",{class:"home-view-empty",children:"No boards yet. Create one, or let an agent start writing — it opens one."},void 0,!1,void 0,this):v&&u.length>0?i("ul",{class:"home-view-list","aria-label":"Library search results",children:u.map((_)=>i("li",{class:"home-board",children:i("button",{type:"button",class:"home-board-open",onClick:()=>void L(_),children:[i("span",{class:"home-board-name",children:_.title||_.boardTitle},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[_.boardTitle," · ",_.snippet]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},`${_.boardId}:${_.cardId}`,!1,void 0,this))},void 0,!1,void 0,this):x.length===0?i("div",{class:"home-view-empty",role:"status",children:["No boards match “",c,"”."]},void 0,!0,void 0,this):i(pe,{children:[h.filter((_)=>!_.includes("/")&&g.has(_)).map((_)=>w(_,0)),x.some((_)=>!_.category)&&i("section",{"aria-label":"Unfiled boards",children:[h.length>0&&i("div",{class:"home-folder-hint",children:"Unfiled boards"},void 0,!1,void 0,this),i("ul",{class:"home-view-list",children:x.filter((_)=>!_.category).map(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),y&&i(c_,{board:y,folders:h,onClose:()=>r(null)},y.id,!1,void 0,this),E&&i(l_,{board:E,onClose:()=>a(null)},E.id,!1,void 0,this)]},void 0,!0,void 0,this)}var Wr=q(!1);function nA(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}function m_(){let[e,t]=I(!1),[n,o]=I(!1),[r,s]=I(null),[a,c]=I(null),[l,u]=I(!1),p=Wr.value,d=Ne.value;if(B(()=>{if(!p||!d)return;let m=!0;return c(null),s(null),Y("exportPreview",`/api/canvas/export/preview?board=${encodeURIComponent(d)}&includeFiles=${e}&includeDerivedText=${n}`,null).then((h)=>{if(m)s(h?.manifest??null)}),()=>{m=!1}},[p,e,n,d]),B(()=>{o(!1)},[p,d]),B(()=>{if(!p)return;let m=(h)=>{if(h.key!=="Escape")return;h.stopPropagation(),Wr.value=!1};return window.addEventListener("keydown",m,{capture:!0}),()=>window.removeEventListener("keydown",m,{capture:!0})},[p]),!p)return null;let f=async()=>{if(!r||r.boardId!==Ne.value)return;u(!0);let m=await Y("exportBoard","/api/canvas/export",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({board:r.boardId,includeFiles:e,includeDerivedText:n})});if(u(!1),m?.path&&Ne.value===r.boardId)c(m)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>Wr.value=!1,children:i("div",{class:"text-prompt export-dialog",role:"dialog","aria-label":"Export board","data-testid":"export-dialog",onPointerDown:(m)=>m.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:["Export ",r?`“${r.boardName}”`:"board"]},void 0,!0,void 0,this),!r?i("div",{class:"export-dialog-note",children:"Reading the board…"},void 0,!1,void 0,this):i(pe,{children:[i("div",{class:"export-dialog-note",children:"One HTML file anyone can open without installing anything. It will contain:"},void 0,!1,void 0,this),i("ul",{class:"export-dialog-list",children:[i("li",{children:[r.cards," card",r.cards!==1?"s":""," and ",r.connections," connection",r.connections!==1?"s":""]},void 0,!0,void 0,this),r.frames>0&&i("li",{children:[r.frames," embedded pages, charts or diagrams, with the code that draws them"]},void 0,!0,void 0,this),r.embeddedImages>0&&i("li",{children:[r.embeddedImages," local images"]},void 0,!0,void 0,this),r.placeholders.length>0&&i("li",{children:["Shown as placeholders:"," ",r.placeholders.map((m)=>`${m.title} (${m.reason})`).join(", ")]},void 0,!0,void 0,this),r.remoteImages.length>0&&i("li",{children:["Web images loaded when opened: ",r.remoteImages.join(", ")]},void 0,!0,void 0,this),r.links.length>0&&i("li",{children:["Links included in cards: ",r.links.join(", ")]},void 0,!0,void 0,this),r.frameNetworkDestinations.length>0&&i("li",{children:["Network destinations referenced by embedded pages: ",r.frameNetworkDestinations.join(", ")]},void 0,!0,void 0,this),r.embeddedCodeCanAccessNetwork&&i("li",{children:"Warning: embedded code can access the network. Scripts may contact destinations that cannot be listed in advance."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(r.attachments?.length??0)>0&&i("p",{children:"Original attachments are excluded. Their filenames remain visible."},void 0,!1,void 0,this),(r.sourceDerivedCards?.length??0)>0&&i("label",{class:"export-dialog-files",children:[i("input",{type:"checkbox",checked:n,onChange:(m)=>o(m.currentTarget.checked)},void 0,!1,void 0,this),i("span",{children:["Include imported document text (",r.sourceDerivedCards.length," cards)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r.files.length>0&&i("label",{class:"export-dialog-files",children:[i("input",{type:"checkbox",checked:e,onChange:(m)=>t(m.target.checked)},void 0,!1,void 0,this),i("span",{children:["Include the contents of ",r.files.length," local file",r.files.length!==1?"s":"",": ",r.files.map((m)=>m.path).join(", ")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a&&i("div",{class:"export-dialog-result","data-testid":"export-result",children:[i("div",{children:["Saved (",nA(a.bytes),"): ",i("code",{children:a.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"export-dialog-links",children:[i("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",children:"Open"},void 0,!1,void 0,this),i("a",{class:"is-primary",href:`${a.url}?download=1`,children:"Download"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:()=>Wr.value=!1,children:a?"Done":"Cancel"},void 0,!1,void 0,this),!a&&i("button",{type:"button",class:"text-prompt-confirm",disabled:!r||l,onClick:()=>void f(),children:l?"Exporting…":"Export"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function xp({presence:e,size:t=18}){return i("span",{class:"writer-avatar",style:{background:Sc(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:aw(e.label)},void 0,!1,void 0,this)}function f_(){let e=ep.value;if(yt.value||e.length===0)return null;let t=e.reduce((r,s)=>r+s.opCount,0),n=e.length===1?e[0].label:`${e.length} writers`,o=Ho.value;return i("button",{type:"button",class:"external-indicator","data-testid":"external-indicator","aria-expanded":o,title:`${e.length} external writer${e.length===1?"":"s"} on this board — click for activity`,onClick:()=>{Ho.value=!o},children:[i("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((r)=>i(xp,{presence:r},r.sessionId,!1,void 0,this))},void 0,!1,void 0,this),i("span",{class:"external-indicator-label",children:n},void 0,!1,void 0,this),i("span",{class:"external-indicator-ops hud-collapsible-text",children:[t," op",t===1?"":"s"]},void 0,!0,void 0,this),i("span",{class:"external-indicator-dot","aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function oA(e){if(e==="node.add"||e==="jsonrender.add"||e==="graph.add"||e==="group.create")return{glyph:"+",tone:"ok"};if(e==="node.remove"||e==="edge.remove"||e==="canvas.clear")return{glyph:"×",tone:"danger"};if(e==="edge.add")return{glyph:"⟶",tone:"accent"};if(e.startsWith("ax."))return{glyph:"◆",tone:"purple"};return{glyph:"✎",tone:"accent"}}function rA(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function iA(){return[...Ge.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function h_(){let e=Ho.value,t=ep.value,n=Nn(e?1e4:0);if(B(()=>{if(!e)return;let c=(l)=>{if(l.key!=="Escape")return;if(Fr.value)Fr.value=!1;else Ho.value=!1};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e]),!e||yt.value||t.length===0)return null;let o=Qd.value,r=iA().filter((c)=>!o||(c.source??"")===o),s=ao.value.filter((c)=>!o||c.sessionId===o),a=(c,l)=>i("button",{type:"button",class:`activity-filter${o===c?" is-active":""}`,style:c?{"--writer":Sc(c)}:void 0,"aria-pressed":o===c,onClick:()=>{Qd.value=c},children:l},void 0,!1,void 0,this);return i("div",{class:"activity-feed","data-testid":"activity-feed",role:"dialog","aria-label":"External activity",children:[i("div",{class:"activity-feed-head",children:[i("span",{class:"external-indicator-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"activity-feed-titles",children:[i("div",{class:"activity-feed-title",children:["External activity — ",t.length," writer",t.length===1?"":"s"]},void 0,!0,void 0,this),i("div",{class:"activity-feed-sub",children:[t.reduce((c,l)=>c+l.opCount,0)," writes · last"," ",kc(rA(t),n)," · no session attached"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"activity-feed-close","aria-label":"Close activity feed",onClick:()=>{Ho.value=!1},children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"activity-filters",children:[a(null,"All"),t.map((c)=>a(c.sessionId,c.label))]},void 0,!0,void 0,this),i("div",{class:"activity-rows",children:[r.map((c)=>i("div",{class:"activity-row is-pending","data-testid":"activity-proposal",children:[i("span",{class:"activity-glyph tone-purple","aria-hidden":"true",children:"▢"},void 0,!1,void 0,this),i("div",{class:"activity-main",children:[i("div",{class:"activity-text",children:["Proposing: ",i("b",{children:c.label?.trim()||`${c.kind} intent`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"activity-meta",children:[c.reason?.trim()||"Intent signalled — a real veto window before the mutation",c.source?` · ${c.source}`:""]},void 0,!0,void 0,this),i("div",{class:"activity-actions",children:[i("button",{type:"button",class:"activity-veto",onClick:()=>{Io(c).then((l)=>{if(l)Mo(c.id)})},children:"Veto"},void 0,!1,void 0,this),i("span",{class:"activity-hint",children:"or hover ghost + Esc"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"activity-age",children:"now"},void 0,!1,void 0,this)]},c.id,!0,void 0,this)),s.length===0&&r.length===0&&i("div",{class:"activity-empty",children:"No writes yet."},void 0,!1,void 0,this),s.map((c)=>{let{glyph:l,tone:u}=oA(c.op);return i("div",{class:"activity-row","data-testid":"activity-row","data-op":c.op,children:[i("span",{class:`activity-glyph tone-${u}`,"aria-hidden":"true",children:l},void 0,!1,void 0,this),i("div",{class:"activity-main",children:[i("div",{class:"activity-text",children:c.summary},void 0,!1,void 0,this),i("div",{class:"activity-writer",style:{color:Sc(c.sessionId)},children:c.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"activity-age",children:kc(c.at,n)},void 0,!1,void 0,this)]},c.id,!0,void 0,this)})]},void 0,!0,void 0,this),i("div",{class:"activity-feed-foot",children:[i("span",{class:"activity-feed-note",children:"All writes ghost first · Esc vetoes"},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-link",onClick:()=>{Fr.value=!0},children:"Writers"},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{Ho.value=!1,uo()},children:["Start session ",i(mn,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function sA(){let e=[];if(co.value)e.push("scoped");if(jo.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function g_(){let e=Fr.value,t=Nn(e?1e4:0),n=R(null);if(Pt(n,e),!e)return null;let o=vt.value.filter((a)=>a.attached),r=vt.value.filter((a)=>!a.attached),s=()=>{Fr.value=!1};return i(pe,{children:[i("div",{class:"writers-scrim",onClick:s,"aria-hidden":"true"},void 0,!1,void 0,this),i("div",{ref:n,class:"writers-sheet","data-testid":"writers-sheet",role:"dialog","aria-modal":"true","aria-label":"Connected writers",children:[i("div",{class:"writers-head",children:[i("span",{class:"writers-title",children:"Connected writers"},void 0,!1,void 0,this),i("span",{class:"writers-board",children:_n.value.slice(0,12)},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-close","aria-label":"Close writers",onClick:s,children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"writers-body",children:[i("div",{class:"writers-section",children:"Agent sessions"},void 0,!1,void 0,this),o.length===0&&i("div",{class:"writers-empty",children:"None attached — start one from the top bar."},void 0,!1,void 0,this),o.map((a)=>i("div",{class:"writers-row",children:[i(xp,{presence:a,size:20},void 0,!1,void 0,this),i("span",{class:"writers-name",children:a.label},void 0,!1,void 0,this),i("span",{class:"writers-config",children:sA()},void 0,!1,void 0,this)]},a.sessionId,!0,void 0,this)),i("div",{class:"writers-section",children:"External writers · MCP"},void 0,!1,void 0,this),r.length===0&&i("div",{class:"writers-empty",children:"No external writers right now."},void 0,!1,void 0,this),r.map((a)=>i("div",{class:"writers-row",children:[i(xp,{presence:a,size:20},void 0,!1,void 0,this),i("span",{class:"writers-name is-mono",children:a.label},void 0,!1,void 0,this),i("span",{class:"writers-meta",children:[a.source!==a.label?`${a.source} · `:"","wrote"," ",kc(a.lastSeenAt,t)," ago"]},void 0,!0,void 0,this)]},a.sessionId,!0,void 0,this))]},void 0,!0,void 0,this),i("div",{class:"writers-foot",children:[i("span",{class:"writers-note",children:"Local-first: any process on this machine can connect and write. Every write ghosts first — veto is the control, not permissions."},void 0,!1,void 0,this),i("button",{type:"button",class:"writers-done",onClick:s,children:"Done"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function v_(e,t){switch(e.type){case"markdown":return i(Ma,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return i(ro,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return i(yc,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return i(ro,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return i(ro,{node:e,expanded:t},void 0,!1,void 0,this);case"board":return i(Rc,{node:e},void 0,!1,void 0,this);case"prompt":return i(bc,{node:e},void 0,!1,void 0,this);case"response":return i(xc,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return i(gc,{node:e},void 0,!1,void 0,this);case"context":return i(wa,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return i(Aa,{node:e},void 0,!1,void 0,this);case"trace":return i(wc,{node:e},void 0,!1,void 0,this);case"file":return i(Ea,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return i(_a,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Ja,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return i(vc,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return i(Hi,{node:e,expanded:t},void 0,!1,void 0,this);default:return i("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function y_(e){switch(e.type){case"markdown":return e.data.content||"";case"diff":return e.data.content||"";case"mermaid":return e.data.content||"";case"file":return e.data.fileContent||"";case"webpage":return e.data.content||"";case"html":return e.data.html||e.data.content||"";case"json-render":case"graph":return JSON.stringify(e.data.spec??e.data.graphConfig??{},null,2);default:return""}}function aA(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function cA(e,t){return e!==null&&typeof e==="object"&&e.source===qt&&e.type==="presentation-exit"&&e.token===t}function lA(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function b_(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function x_(){let e=qe.value,t=e?F.value.get(e):void 0,[n,o]=I(!1),[r,s]=I(!1),[a,c]=I(""),l=R(null),u=R(null),p=H(()=>{s(!1),In()},[]),d=H(()=>{c(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),s(!0)},[]),f=H((S)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:qt,token:a,...S},"*")},[a]),m=H(()=>{s(!1)},[]),h=H((S)=>{if(S.key==="Escape"){S.preventDefault(),S.stopPropagation(),s(!1);return}if(S.key==="Tab"&&!b_(S.target)){S.preventDefault(),S.stopPropagation(),u.current?.focus();return}if((S.key===" "||S.key==="Enter")&&b_(S.target))return;if(!lA(S.key))return;S.preventDefault(),S.stopPropagation(),f({type:"presentation-key",key:S.key})},[f]),v=H((S)=>{if(S.target.classList.contains("expanded-overlay-backdrop"))In()},[]),x=H(()=>{if(!t)return;let S=y_(t);if(!S)return;navigator.clipboard.writeText(S).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),g=H(()=>{if(!e)return;Xn(e)},[e]);B(()=>{s(!1)},[e]),Bn(()=>{if(!r)return;let S=()=>{let Ze=l.current;if(!Ze||Ze.contains(document.activeElement))return;Ze.focus()},V=[0,50,150].map((Ze)=>window.setTimeout(S,Ze)),ge=(Ze)=>{if(!cA(Ze.data,a))return;s(!1)};return document.addEventListener("keydown",h,!0),window.addEventListener("message",ge),()=>{V.forEach((Ze)=>{window.clearTimeout(Ze)}),document.removeEventListener("keydown",h,!0),window.removeEventListener("message",ge)}},[h,a,r]);let y=R(null),E=H(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]);if(Pt(y,t!==void 0,{restoreTo:E}),!t)return null;let L=t.data.title||t.data.path?.split("/").pop()||ut[t.type],P=y_(t),b=aA(P),T=e?Ae.value.has(e):!1,w=P.length>0,_=tn.value===e,z=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",U=Ux(t),N=rn(t.type),Z=t.data.provenance&&typeof t.data.provenance==="object"?t.data.provenance:null,j=Z?[Z.sourceKind,Z.sourceUri,Z.syncedAt?`synced ${Z.syncedAt.slice(11,16)}`:null].filter((S)=>typeof S==="string"&&S.length>0).join(" · "):null;return i("div",{class:"expanded-overlay-backdrop",onPointerDown:v,style:{pointerEvents:_?"none":"auto"},children:i("div",{ref:y,class:`expanded-overlay-panel${T?" is-pinned":""}`,role:"dialog","aria-modal":"true","aria-label":L,"data-testid":"expanded-node",children:[i("div",{class:"expanded-header",children:[i("span",{class:"expanded-kind-icon","aria-hidden":"true",children:i(N,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"expanded-title",children:L},void 0,!1,void 0,this),i("span",{class:"expanded-kind-pill",children:ut[t.type]},void 0,!1,void 0,this),i("button",{type:"button",class:`expanded-pin${T?" is-on":""}`,onClick:g,title:T?"In agent context — click to unpin":"Pin as agent context","aria-pressed":T,children:"✦"},void 0,!1,void 0,this),i("span",{class:"expanded-spacer"},void 0,!1,void 0,this),i("div",{class:"expanded-actions",children:[w&&i("button",{type:"button",class:"expanded-action-btn",onClick:x,title:"Copy content to clipboard",children:n?"Copied!":"Copy"},void 0,!1,void 0,this),Fa(t)&&i("button",{type:"button",class:"expanded-action-btn",onClick:()=>void Ba(t),title:"Open as a full-page site in the system browser",children:["Open in tab ",i(mn,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&i("button",{type:"button",class:"expanded-action-btn expanded-action-primary",onClick:d,title:"Present this HTML node fullscreen",children:"Present"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"expanded-close",onClick:p,title:"Close (Esc)","aria-label":"Close",children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:`expanded-body${z?" is-embedded":""}`,children:z?i("div",{style:{flex:1,minHeight:0,display:"flex"},children:v_(t,!0)},void 0,!1,void 0,this):v_(t,!0)},void 0,!1,void 0,this),i("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:i(Nc,{node:t},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{class:"expanded-footer",children:[i("span",{class:"expanded-footer-meta",children:[j,b>0?`${b.toLocaleString()} word${b!==1?"s":""}`:null].filter(Boolean).join(" · ")||ut[t.type].toLowerCase()},void 0,!1,void 0,this),i("span",{class:"expanded-spacer"},void 0,!1,void 0,this),i("span",{class:`expanded-footer-hint${_?" is-saving":""}`,children:_?"Saving edits…":"esc or click outside to close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&r&&i("div",{ref:l,class:"html-presentation-overlay",role:"dialog","aria-modal":"true","aria-label":`Present ${L}`,tabIndex:-1,onKeyDownCapture:h,children:[i("button",{ref:u,type:"button",class:"html-presentation-exit",onClick:m,title:"Exit presentation (Esc)","aria-label":"Exit presentation",children:"Exit presentation"},void 0,!1,void 0,this),i("div",{class:"html-presentation-stage",children:i(Hi,{node:t,expanded:!0,presentation:!0,presentationExitToken:a},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var __=168,S_=112,Fc=20;function w_(e,t,n,o){let r=Array.from(e.values()),s=0,a=0,c=1000,l=800;if(r.length>0){s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let x of r)s=Math.min(s,x.position.x),a=Math.min(a,x.position.y),c=Math.max(c,x.position.x+x.size.width),l=Math.max(l,x.position.y+x.size.height)}let u=-t.x/t.scale,p=-t.y/t.scale,d=u+n/t.scale,f=p+o/t.scale,m={minX:Math.min(s,u)-Fc,minY:Math.min(a,p)-Fc,maxX:Math.max(c,d)+Fc,maxY:Math.max(l,f)+Fc},h=m.maxX-m.minX||1,v=m.maxY-m.minY||1;return{bounds:m,scale:Math.min(__/h,S_/v)}}function k_({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:r}){let s=R(null),a=R(!1),c=t.value,l=e.value,u=w_(c,l,o,r),{bounds:p,scale:d}=u,f=(b)=>(b-p.minX)*d,m=(b)=>(b-p.minY)*d,h=H((b)=>{let T=s.current;if(!T)return;let w=T.getBoundingClientRect(),_=(b.clientX-w.left)/w.width*__,z=(b.clientY-w.top)/w.height*S_,U=w_(t.value,e.value,o,r),N=e.value,Z=o/N.scale,j=r/N.scale,S=_/U.scale+U.bounds.minX,V=z/U.scale+U.bounds.minY;n(-(S-Z/2)*N.scale,-(V-j/2)*N.scale)},[t,e,o,r,n]),v=H((b)=>{b.stopPropagation(),b.preventDefault(),a.current=!0,h(b);let T=(_)=>{if(a.current)h(_)},w=()=>{a.current=!1,document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",w)};document.addEventListener("pointermove",T),document.addEventListener("pointerup",w)},[h]),x=be.value,g=co.value,y=g?Tc(g.nodeIds.map((b)=>c.get(b)).filter((b)=>b!==void 0),g.padding):null,E=vt.value.map((b)=>({id:b.sessionId,phase:b.phase,worker:b.parentAgentId!=null,external:!b.attached,at:Cc(b,(T)=>c.get(T))})).filter((b)=>b.at!==null),L=-l.x/l.scale,P=-l.y/l.scale;return i("div",{ref:s,class:"minimap","data-testid":"minimap",title:"Click to jump · drag the frame to pan",onPointerDown:v,children:[Array.from(c.values()).map((b)=>{let T=b.type==="group";return i("span",{class:`minimap-node${T?" is-group":""}${x.has(b.id)?" is-selected":""}`,"data-kind":b.type,style:{left:`${f(b.position.x)}px`,top:`${m(b.position.y)}px`,width:`${Math.max(T?6:4,b.size.width*d)}px`,height:`${Math.max(T?5:3,b.size.height*d)}px`,"--kind":zc[b.type]}},b.id,!1,void 0,this)}),y&&i("span",{class:"minimap-fence",style:{left:`${f(y.x)}px`,top:`${m(y.y)}px`,width:`${y.width*d}px`,height:`${y.height*d}px`}},void 0,!1,void 0,this),E.map((b)=>i("span",{class:`minimap-presence phase-${b.phase}${b.worker?" is-worker":""}${b.external?" is-external":""}`,style:{left:`${f(b.at.x)-4}px`,top:`${m(b.at.y)-4}px`,"--identity-color":`hsl(${so(b.id)} 65% 62%)`}},b.id,!1,void 0,this)),i("span",{class:"minimap-frame",style:{left:`${f(L)}px`,top:`${m(P)}px`,width:`${o/l.scale*d}px`,height:`${r/l.scale*d}px`}},void 0,!1,void 0,this),i("span",{class:"minimap-zoom",children:[Math.round(l.scale*100),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Xe({label:e,shortcut:t,body:n,align:o="center",side:r="down",tapToOpen:s=!1,children:a}){return i("span",{class:`toolbar-tooltip-anchor toolbar-tooltip-anchor-${o}${r==="up"?" toolbar-tooltip-anchor-up":""}${s?" toolbar-tooltip-anchor-tap":""}`,tabIndex:s?-1:void 0,children:[a,i("span",{class:"toolbar-tooltip",role:"tooltip",children:[i("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),n&&i("span",{class:"toolbar-tooltip-body",children:n},void 0,!1,void 0,this),t&&i("span",{class:"toolbar-tooltip-meta",children:i("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function C_(){let e=be.value.size,t=H(()=>{let c=Array.from(be.value);if(c.length===0)return;sa(c),wt()},[]),n=H(()=>{let c=Array.from(be.value);if(c.length===0)return;cr({title:"Group",childIds:c}),wt()},[]),o=H(()=>{let c=Array.from(be.value);for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++)Eo(c[l],c[u],"relation");wt()},[]),r=H(()=>{let c=Array.from(be.value);for(let l of c)Vn(l);wt()},[]);if(e===0)return null;let s=e>=2,a=!yt.value&&Ae.value.size>0&&!un.value;return i("div",{class:`selection-bar${a?" is-above-pin-bar":""}`,role:"toolbar","aria-label":"Selection",children:[i("span",{class:"selection-bar-count",children:[e," node",e!==1?"s":""," selected"]},void 0,!0,void 0,this),s&&i(pe,{children:[i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Xe,{label:"Align left",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align left",onClick:()=>Su("left"),children:i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("line",{x1:"2.5",y1:"2",x2:"2.5",y2:"14"},void 0,!1,void 0,this),i("rect",{x:"5",y:"3.5",width:"8",height:"3.5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"5",y:"9",width:"5",height:"3.5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Xe,{label:"Align top",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align top",onClick:()=>Su("top"),children:i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("line",{x1:"2",y1:"2.5",x2:"14",y2:"2.5"},void 0,!1,void 0,this),i("rect",{x:"3.5",y:"5",width:"3.5",height:"8",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9",y:"5",width:"3.5",height:"5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Xe,{label:"Distribute horizontally",body:"Evens the gaps. A selection that cannot fit flows into a clean row instead of overlapping.",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Distribute",disabled:e<3,onClick:()=>ry(),children:i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","aria-hidden":"true",children:[i("rect",{x:"1.5",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"6.25",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"11",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Xe,{label:"Auto-arrange selection",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Auto-arrange",onClick:()=>iy(),children:i(En,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Xe,{label:"Group the selection",shortcut:"G",side:"up",children:i("button",{type:"button",class:"selection-bar-action",onClick:n,children:[i("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-dasharray":"3 2.5","aria-hidden":"true",children:i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Group"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i(Xe,{label:"Connect every pair",side:"up",children:i("button",{type:"button",class:"selection-bar-action",onClick:o,children:"Connect"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Xe,{label:"Pin to agent context",side:"up",children:i("button",{type:"button",class:"selection-bar-action is-pin",onClick:t,children:[i("span",{"aria-hidden":"true",children:"✦"},void 0,!1,void 0,this),"Pin as context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Xe,{label:"Delete selection",side:"up",children:i("button",{type:"button",class:"selection-bar-icon is-danger","aria-label":"Delete selection",onClick:r,children:i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("path",{d:"M2.5 4 H13.5"},void 0,!1,void 0,this),i("path",{d:"M5.5 4 V2.5 H10.5 V4"},void 0,!1,void 0,this),i("path",{d:"M4 4 L4.8 13.5 H11.2 L12 4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Xe,{label:"Clear selection",shortcut:"Esc",side:"up",children:i("button",{type:"button",class:"selection-bar-icon",onClick:wt,"aria-label":"Clear selection",children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Bc(e,t=Date.now()){if(!e.expiresAt)return null;let n=Date.parse(e.expiresAt);if(!Number.isFinite(n))return null;return Math.max(0,n-t)}function Hc(e){let t=Math.max(0,Math.ceil(e/1000)),n=Math.floor(t/60),o=t%60;return`${n}:${String(o).padStart(2,"0")}`}var uA={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},dA={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},T_=[{id:"all",label:"All",hint:"Everything below in one feed, newest first"},{id:"update",label:"Updates",hint:"Board edits agents made — nodes, edges, pins, work items"},{id:"steer",label:"Steer",hint:"Instructions sent to agents — by you from the composer, or agent-to-agent"},{id:"assistant",label:"Assistant",hint:"Messages agents posted for you to read"},{id:"event",label:"Events",hint:"Run telemetry — tool runs, approvals, failures, policy notes"},{id:"evidence",label:"Evidence",hint:"Proof agents recorded — test results, artifacts, links"}],I_=Object.fromEntries(T_.map((e)=>[e.id,e.hint])),pA={policy:"warn",prompt:"accent","assistant-message":"muted","tool-start":"accent","tool-result":"ok",failure:"danger",approval:"warn",steering:"purple",command:"accent",note:"muted",evidence:"ok",steer:"purple",update:"purple",yield:"warn"};function wp(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function mA({item:e}){let t=uA[e.status]??"queued",n=e.nodeIds[0];return i("li",{class:`session-item status-${t}`,"data-work-item-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("button",{type:"button",class:"session-item-title",title:n?"Focus the linked node":void 0,disabled:!n,onClick:()=>n&&Ke(n),children:e.title},void 0,!1,void 0,this),e.detail&&i("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"session-item-status",children:dA[e.status]??t},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:wp(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function fA({gate:e,now:t}){let[n,o]=I(null),r=async(c)=>{o(c),await xw(e,c),o(null)},s=e.nodeIds[0],a=Bc(e,t);return i("li",{class:"session-item status-awaiting session-gate","data-gate-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("button",{type:"button",class:"session-item-title",title:s?"Focus the linked node":void 0,disabled:!s,onClick:()=>s&&Ke(s),children:e.title},void 0,!1,void 0,this),e.detail&&i("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this),a!==null&&i("div",{class:"session-gate-ttl","data-testid":"gate-countdown",children:["auto-holds in ",Hc(a)," if unanswered"]},void 0,!0,void 0,this),i("div",{class:"session-gate-actions",children:[i("button",{type:"button",class:"session-gate-approve",disabled:n!==null,onClick:()=>void r("approved"),children:n==="approved"?"Approving…":"Approve"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-gate-reject",disabled:n!==null,onClick:()=>void r("rejected"),children:n==="rejected"?"Rejecting…":"Reject"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"session-item-time",children:wp(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function hA({gate:e}){let[t,n]=I(!1);return i("li",{class:"session-item status-vetoed session-gate-held","data-gate-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("span",{class:"session-item-title",children:e.title},void 0,!1,void 0,this),i("div",{class:"session-item-detail",children:"Auto-held — no answer in time, the action did not proceed."},void 0,!1,void 0,this),i("div",{class:"session-gate-actions",children:i("button",{type:"button",class:"session-gate-reject",disabled:t,onClick:()=>{n(!0),ww(e).finally(()=>n(!1))},children:t?"Reopening…":"Reopen"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"session-item-status",children:"held"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function gA(e){let t=e.resolvedBy;if(!t)return e.status;let n=e.status==="approved"?"Approved":"Rejected";if(t.actor==="human")return`${n} by you`;if(t.actor==="system")return`${n} by system`;let o=t.agentId||t.source||"agent";return`${e.selfAnswer?"Self-":""}${n.toLowerCase()} by ${o}`}function vA({gate:e}){return i("li",{class:`session-item status-${e.status}`,"data-gate-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("span",{class:"session-item-title",children:e.title},void 0,!1,void 0,this),i("div",{class:"session-item-detail",children:gA(e)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function yA(){let e=co.value,t=be.value.size,[n,o]=I(!1),r=(s)=>{o(!0),fw(s).finally(()=>o(!1))};return i("div",{class:`session-scope${e?" is-fenced":""}`,"data-testid":"session-scope",children:[i("span",{class:"session-scope-dot","aria-hidden":"true"},void 0,!1,void 0,this),e?i(pe,{children:[i("span",{class:"session-scope-text",children:["Scoped to ",i("strong",{children:e.nodeIds.length},void 0,!1,void 0,this)," node",e.nodeIds.length===1?"":"s"," · writes outside are blocked"]},void 0,!0,void 0,this),i("button",{type:"button",class:"session-scope-action",disabled:n,onClick:()=>r(null),children:"Clear"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i(pe,{children:[i("span",{class:"session-scope-text",children:"Unscoped — the agent may write anywhere"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-scope-action",disabled:n||t===0,title:t===0?"Select nodes on the canvas first":"Fence the agent to the selected nodes",onClick:()=>r([...be.value]),children:["Fence to selection",t>0?` (${t})`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function bA(e){if(e==="browser")return"you";return vt.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function xA({entry:e}){let t=Zi.value.has(e.id);return i("li",{class:`session-timeline-row tone-${pA[e.kind]??"muted"}`,children:[i("span",{class:"session-timeline-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-timeline-main",children:[i("div",{class:"session-timeline-head",children:[i("span",{class:"session-timeline-label",title:I_[ip(e.kind)],children:e.label},void 0,!1,void 0,this),e.who&&i("span",{class:"session-timeline-who",style:{"--identity-color":`hsl(${so(e.who)} 65% 62%)`},children:bA(e.who)},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:wp(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-timeline-body",children:e.body},void 0,!1,void 0,this),e.undoable&&!t&&i("button",{type:"button",class:"session-timeline-undo","data-testid":"timeline-undo",onClick:()=>void sp(e),children:[i(Au,{size:14},void 0,!1,void 0,this)," undo this edit"]},void 0,!0,void 0,this),t&&i("div",{class:"session-timeline-undone",children:"undone · steering sent"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function E_(){let[e,t]=I(!1),n=Br.value,o=mw.value,r=jo.value,s=hw.value,a=gw.value,c=bw.value,[l,u]=I(!1),[p,d]=I(null),f=Nn();if(B(()=>{lo()},[]),!(e||r.length>0))return i("aside",{class:"session-panel is-collapsed","aria-label":"Session (collapsed)",children:[i("button",{type:"button",class:"session-collapse",onClick:()=>t(!0),title:"Expand session panel",children:"‹"},void 0,!1,void 0,this),n&&i("span",{class:`session-collapsed-live phase-${n.phase}`,title:io(n),"aria-label":`Session live: ${io(n)}`,children:[i("span",{class:"session-live-dot","aria-hidden":"true"},void 0,!1,void 0,this),"live"]},void 0,!0,void 0,this),i("span",{class:"session-collapsed-label",children:"Session"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("aside",{class:"session-panel","aria-label":"Session",children:[i("header",{class:"session-panel-header",children:[i("span",{class:"session-panel-title",children:"Session"},void 0,!1,void 0,this),n&&i("span",{class:`session-live phase-${n.phase}`,title:io(n),children:[i("span",{class:"session-live-dot","aria-hidden":"true"},void 0,!1,void 0,this),"live"]},void 0,!0,void 0,this),i("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),n&&i("button",{type:"button",class:"session-end",title:"End this session — a receipt and a snapshot of the board follow",onClick:()=>void Ic(n),children:"End"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-collapse",onClick:()=>t(!1),title:"Collapse session panel","aria-label":"Collapse session panel",children:i(vr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(yA,{},void 0,!1,void 0,this),(()=>{let h=c.find((v)=>v.undoable&&!Zi.value.has(v.id));if(!h)return null;return i("div",{class:"session-undo-row","data-testid":"session-undo-row",children:[i("span",{class:"session-undo-text",title:h.body,children:["Agent edit on top: ",h.body]},void 0,!0,void 0,this),i("button",{type:"button",class:"session-undo-btn",onClick:()=>void sp(h),children:[i(Au,{size:14},void 0,!1,void 0,this)," Undo"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)})(),i("div",{class:"session-panel-body",children:[i("section",{class:"session-section",children:(()=>{let h=o.filter((P)=>P.status==="in-progress"||P.status==="todo").length,v=o.filter((P)=>P.status!=="cancelled"),x=v.filter((P)=>P.status==="done").length,g=o.length-v.length,y=r.length>0,E=l||y,L=h>0?`${h} running`:v.length>0?`${x}/${v.length} done${g>0?` · ${g} cancelled`:""}`:o.length>0?`${o.length} cancelled`:"none yet";return i(pe,{children:[i("button",{type:"button",class:"session-section-toggle","aria-expanded":E,"data-testid":"work-items-toggle",onClick:()=>u((P)=>!P),children:[i("span",{class:"session-section-title",children:"Work items"},void 0,!1,void 0,this),i("span",{class:"session-work-summary",children:[h>0&&i("span",{class:"session-work-dot","aria-hidden":"true"},void 0,!1,void 0,this),L]},void 0,!0,void 0,this),i("span",{class:`session-section-chevron${E?" is-open":""}`,"aria-hidden":"true",children:i(vr,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E&&(r.length===0&&s.length===0&&a.length===0&&o.length===0?i("div",{class:"session-empty",children:"No work items yet — the agent's tasks and gates appear here."},void 0,!1,void 0,this):i("ul",{class:"session-list","aria-live":"polite","aria-label":"Work items and gates",children:[r.map((P)=>i(fA,{gate:P,now:f},P.id,!1,void 0,this)),s.map((P)=>i(hA,{gate:P},P.id,!1,void 0,this)),a.map((P)=>i(vA,{gate:P},P.id,!1,void 0,this)),o.map((P)=>i(mA,{item:P},P.id,!1,void 0,this))]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)})()},void 0,!1,void 0,this),i("section",{class:"session-section",children:[i("h3",{class:"session-section-title",children:"Timeline"},void 0,!1,void 0,this),i("div",{class:"session-timeline-filters",role:"group","aria-label":"Filter timeline",children:T_.map((h)=>i("button",{type:"button",class:`activity-filter${Zo.value===h.id?" is-active":""}`,"aria-pressed":Zo.value===h.id,title:h.hint,onMouseEnter:()=>d(h.id),onMouseLeave:()=>d((v)=>v===h.id?null:v),onFocus:()=>d(h.id),onBlur:()=>d((v)=>v===h.id?null:v),onClick:()=>{Zo.value=h.id},children:h.label},h.id,!1,void 0,this))},void 0,!1,void 0,this),i("div",{class:"session-timeline-hint","data-testid":"timeline-filter-hint",children:I_[p??Zo.value]},void 0,!1,void 0,this),c.length===0?i("div",{class:"session-empty",children:Zo.value==="all"?"Nothing recorded yet.":"Nothing of this kind yet."},void 0,!1,void 0,this):i("ul",{class:"session-list session-timeline","aria-live":"polite","aria-label":"Timeline",children:c.map((h)=>i(xA,{entry:h},h.id,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function _p(e){if(!e||typeof e!=="object")return null;let t=e,n=(o)=>Array.isArray(o)?o.length:0;return{added:n(t.addedNodes)+n(t.addedEdges),removed:n(t.removedNodes)+n(t.removedEdges),modified:n(t.modifiedNodes)}}function A_({onOpenSnapshots:e}){let t=Ec.value,[n,o]=I(null),[r,s]=I(!1);if(!t)return null;let a=async()=>{if(!t.snapshot)return;s(!0);try{let u=await fetch(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(u.ok){let p=await u.json();o(_p(p.diff)??{added:0,removed:0,modified:0})}}finally{s(!1)}},c=new Date(t.endedAt),l=Number.isNaN(c.getTime())?"":`${String(c.getHours()).padStart(2,"0")}:${String(c.getMinutes()).padStart(2,"0")}`;return i("div",{class:"session-receipt","data-testid":"session-receipt",role:"status",children:[i("div",{class:"session-receipt-head",children:[i("span",{class:"session-receipt-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"session-receipt-title",children:[t.endedBy==="human"?"Session ended by you":t.endedBy==="idle-timeout"?"Session ended — idle timeout":t.endedBy==="agent"?"Session ended by the agent":"Session ended",l?` · ${l}`:""]},void 0,!0,void 0,this),i("button",{type:"button",class:"session-receipt-close",onClick:Ac,"aria-label":"Dismiss receipt",children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-tiles",children:[i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Items"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value",children:t.counts.items},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Done"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-ok",children:t.counts.done},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.cancelled>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Cancelled"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-muted",children:t.counts.cancelled},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.rejected>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Rejected"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-danger",children:t.counts.rejected},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.held>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Held"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-warn",children:t.counts.held},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-note",children:t.snapshot?"A snapshot of the board from before this session is saved — restore it to undo the session.":t.unchanged?"This session changed nothing on the board — no snapshot kept.":"The board was empty when the session started — nothing to restore."},void 0,!1,void 0,this),n&&i("div",{class:"session-receipt-diff","data-testid":"session-receipt-diff",children:["This session: ",n.added," added · ",n.removed," removed · ",n.modified," modified"]},void 0,!0,void 0,this),i("div",{class:"session-receipt-actions",children:[t.snapshot&&i("button",{type:"button",class:"session-receipt-primary",disabled:r,onClick:()=>void a(),children:r?"Comparing…":"View diff"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-receipt-secondary",title:"Open the History drawer — saved boards and past sessions",onClick:e,children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var wA=[{title:"Tools",shortcuts:[{keys:"V",desc:"Select tool — drag empty space to lasso"},{keys:"Space (hold)",desc:"Pan — drag anywhere moves the board"},{keys:"A",desc:"Annotate — draw on the canvas"}]},{title:"Navigation",shortcuts:[{keys:We("K"),desc:"Command palette — search nodes & actions"},{keys:"Tab / Shift+Tab",desc:"Cycle through nodes"},{keys:"← ↑ → ↓",desc:"Walk graph along edges (when node focused)"},{keys:"F",desc:"Fit all nodes on screen"},{keys:We("0"),desc:"Reset viewport to origin"},{keys:`${We("+")} / ${We("−")}`,desc:"Zoom in / out"}]},{title:"Creation",shortcuts:[{keys:"M",desc:"New markdown note"},{keys:"I / W / H",desc:"New image / webpage / HTML surface"},{keys:"Shift+F",desc:"New file node (workspace path)"},{keys:"G / Shift+G",desc:"Group the selection (new frame when empty) / ungroup"},{keys:"Double-click",desc:"Open actions on a node or create menu on canvas"},{keys:"Drag port → node",desc:"Connect two nodes (hover to reveal ports)"}]},{title:"Selection",shortcuts:[{keys:"Click",desc:"Focus node (highlights neighbors & edges)"},{keys:"Shift+Click",desc:"Toggle node in multi-selection"},{keys:"Drag empty space",desc:"Lasso select multiple nodes"},{keys:_i?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:_i?"⌘Z / ⇧⌘Z":"Ctrl+Z / Ctrl+Y",desc:"Undo / redo — agent edits included"},{keys:"Esc",desc:"Clear selection / close overlay"}]},{title:"View",shortcuts:[{keys:"?",desc:"Toggle this shortcut overlay"},{keys:"Minimap",desc:"Click/drag to navigate (toggle in the rail)"},{keys:"Right-drag",desc:"Pan the board from anywhere"}]}];function z_({onClose:e}){return i("div",{class:"shortcut-overlay-backdrop",onMouseDown:e,children:i("div",{class:"shortcut-overlay",onMouseDown:(t)=>t.stopPropagation(),children:[i("div",{class:"shortcut-overlay-header",children:[i("span",{class:"shortcut-overlay-title",children:"Keyboard Shortcuts"},void 0,!1,void 0,this),i("span",{class:"shortcut-overlay-hint",children:["Press ",i("kbd",{children:"?"},void 0,!1,void 0,this)," or ",i("kbd",{children:"Esc"},void 0,!1,void 0,this)," to close"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"shortcut-overlay-body",children:wA.map((t)=>i("div",{class:"shortcut-group",children:[i("div",{class:"shortcut-group-title",children:t.title},void 0,!1,void 0,this),t.shortcuts.map((n)=>i("div",{class:"shortcut-row",children:[i("kbd",{class:"shortcut-keys",children:n.keys},void 0,!1,void 0,this),i("span",{class:"shortcut-desc",children:n.desc},void 0,!1,void 0,this)]},n.keys,!0,void 0,this))]},t.title,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var P_="Before session · ";function N_(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function _A(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/60000);if(n<1)return"just now";if(n<60)return`${n}m ago`;let o=Math.floor(n/60);if(o<24)return`${o}h ago`;return`${Math.floor(o/24)}d ago`}function jc(e){if(!e.startsWith(P_))return null;let t=e.slice(P_.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function R_({open:e,onClose:t,anchorRef:n}){let[o,r]=I([]),[s,a]=I(!1),[c,l]=I(!1),[u,p]=I(null),[d,f]=I(""),[m,h]=I(null),[v,x]=I({}),g=R(null),y=R(null);B(()=>{if(!e)return;a(!0),Hv().then((w)=>{r(w),a(!1)})},[e]),B(()=>{if(e)setTimeout(()=>y.current?.focus(),50)},[e]),B(()=>{if(!e)return;let w=(_)=>{let z=g.current,U=n.current;if(z&&!z.contains(_.target)&&U&&!U.contains(_.target))t()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,t]),B(()=>{if(!e)return;let w=(_)=>{if(_.key==="Escape")t()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[e,t]);let E=H(async()=>{let w=d.trim();if(!w)return;l(!0);let _=await jv(w);if(l(!1),_.ok&&_.snapshot)r((z)=>[_.snapshot,...z]),f("")},[d]),L=H(async(w)=>{h(null),p(w);let _=await Zv(w);if(p(null),_.ok)t()},[t]),P=H(async(w)=>{if((await Uv(w)).ok)r((z)=>z.filter((U)=>U.id!==w));h(null)},[]),b=H(async(w)=>{x((z)=>({...z,[w]:"loading"}));let _=await Y("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(w)}/diff`,{});x((z)=>({...z,[w]:_p(_.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let T=(w,_)=>m?.id===w.id?i(pe,{children:[i("button",{type:"button",class:`snapshot-action-btn ${m.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>m.action==="delete"?P(w.id):L(w.id),title:m.action==="delete"?"Confirm delete":"Confirm restore",disabled:u!==null,children:m.action==="delete"?"Delete":u===w.id?"Restoring…":"Confirm"},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn",onClick:()=>h(null),title:"Cancel",disabled:u!==null,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i(pe,{children:[i("button",{type:"button",class:"snapshot-action-btn snapshot-action-restore",onClick:()=>h({id:w.id,action:"restore"}),title:"Restore this snapshot — replaces the current canvas (undoable)",disabled:u!==null,children:u===w.id?"Restoring…":_},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn snapshot-action-delete",onClick:()=>h({id:w.id,action:"delete"}),title:"Delete this snapshot","aria-label":"Delete snapshot",disabled:u!==null,children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{ref:g,class:"snapshot-panel","data-testid":"history-drawer",role:"dialog","aria-label":"History",children:[i("div",{class:"snapshot-panel-header",children:[i("span",{class:"snapshot-panel-title",children:"History"},void 0,!1,void 0,this),i("span",{class:"snapshot-panel-sub",children:"snapshots + sessions"},void 0,!1,void 0,this),i("span",{class:"snapshot-panel-spacer"},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-panel-close",onClick:t,title:"Close","aria-label":"Close history",children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-save-form",children:[i("input",{ref:y,type:"text",class:"snapshot-name-input",value:d,onInput:(w)=>f(w.target.value),onKeyDown:(w)=>{if(w.key==="Enter")E()},placeholder:"Save a snapshot as…","aria-label":"Snapshot name",maxLength:80,disabled:c},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-save-btn",onClick:E,disabled:!d.trim()||c,children:c?"…":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-restore-note",children:"Restoring replaces the current canvas. You can undo it if needed."},void 0,!1,void 0,this),i("div",{class:"snapshot-list",children:[s&&i("div",{class:"snapshot-empty",children:"Loading…"},void 0,!1,void 0,this),!s&&o.length===0&&i("div",{class:"snapshot-empty",children:"No history yet. Save a snapshot, or start an agent session — it snapshots for you."},void 0,!1,void 0,this),!s&&[...o.filter((w)=>jc(w.name)===null),...o.some((w)=>jc(w.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((w)=>jc(w.name)!==null)].map((w)=>{if(w.id==="__sessions-header__")return i("div",{class:"snapshot-section-header","data-testid":"history-sessions-header",children:"Sessions"},w.id,!1,void 0,this);let _=jc(w.name),z=v[w.id];if(_!==null)return i("div",{class:"snapshot-item is-session","data-testid":"history-session",children:[i("div",{class:"snapshot-item-head",children:[i("span",{class:"snapshot-session-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"snapshot-item-name",children:["Agent session — ",_]},void 0,!0,void 0,this),i("span",{class:"snapshot-item-time",children:N_(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:["snapshot at session start · ",w.nodeCount," node",w.nodeCount!==1?"s":"",z&&z!=="loading"&&i("span",{class:"snapshot-item-diff",children:[" ","· since: ",z.added," added · ",z.removed," removed · ",z.modified," modified"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-actions is-session",children:[i("button",{type:"button",class:"snapshot-action-btn snapshot-action-diff",disabled:z==="loading",onClick:()=>void b(w.id),children:z==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),T(w,"Restore pre-state")]},void 0,!0,void 0,this)]},w.id,!0,void 0,this);return i("div",{class:"snapshot-item","data-testid":"history-snapshot",children:[i("div",{class:"snapshot-item-head",children:[i("span",{class:"snapshot-item-glyph","aria-hidden":"true",children:"◫"},void 0,!1,void 0,this),i("span",{class:"snapshot-item-name",children:w.name},void 0,!1,void 0,this),i("span",{class:"snapshot-item-time",children:N_(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:[w.nodeCount," node",w.nodeCount!==1?"s":"",w.edgeCount>0?` · ${w.edgeCount} edge${w.edgeCount!==1?"s":""}`:""," · ",_A(w.createdAt)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-actions",children:T(w,"Restore")},void 0,!1,void 0,this)]},w.id,!0,void 0,this)})]},void 0,!0,void 0,this),i("div",{class:"snapshot-panel-foot",children:"Every agent session start writes a snapshot automatically."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var SA=8;function kA({children:e}){let t=Ie(()=>document.createElement("div"),[]);return Bn(()=>(document.body.appendChild(t),()=>{Jr(null,t),t.remove()}),[t]),Bn(()=>Jr(e,t),[e,t]),null}function $_({fallbackName:e}){let[t,n]=I(!1),o=R(null),r=R(null),s=R(null);Bn(()=>{if(!t)return;let d=(m)=>{if(m.target instanceof Node&&!o.current?.contains(m.target)&&!s.current?.contains(m.target))n(!1)},f=(m)=>{if(m.key==="Escape")m.stopPropagation(),n(!1),r.current?.focus()};return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",f,!0),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",f,!0)}},[t]);let a=Ia(),c=!br.value?e:a?a.name:"Home",l=At.value.filter((d)=>d.id!==Ne.value).slice(0,SA),u=r.current?.getBoundingClientRect(),p=(d)=>{n(!1),zt(d)};return i("span",{class:"board-switcher",ref:o,children:[i("button",{ref:r,type:"button",class:"top-bar-title board-switcher-button","aria-haspopup":"menu","aria-expanded":t,"aria-label":`Board: ${c}. Switch board`,onClick:()=>n((d)=>!d),children:[i("span",{class:"board-switcher-name",children:c},void 0,!1,void 0,this),i("span",{class:"board-switcher-caret","aria-hidden":"true",children:i(ga,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&u&&i(kA,{children:i("div",{ref:s,class:"toolbar-menu board-switcher-menu",role:"menu","aria-label":"Boards",style:{position:"fixed",left:`min(${u.left}px, max(12px, calc(100vw - 352px)))`,top:`${u.bottom+8}px`,right:"auto",maxHeight:`min(70vh, calc(100dvh - ${u.bottom+20}px))`},children:[l.length>0&&i("div",{class:"board-switcher-heading",children:"Recent boards"},void 0,!1,void 0,this),i("div",{class:"board-switcher-recents",children:l.map((d)=>i("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>p(d.id),children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:i(xa,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"board-switcher-item-copy",children:[i("span",{class:"board-switcher-item-name",children:d.name},void 0,!1,void 0,this),i("span",{class:"board-switcher-item-folder",children:d.category?.split("/").join(" / ")||"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"board-switcher-item-meta",children:[d.nodeCount," ",d.nodeCount===1?"node":"nodes"]},void 0,!0,void 0,this)]},d.id,!0,void 0,this))},void 0,!1,void 0,this),i("div",{class:"board-switcher-actions",children:[i("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>{n(!1),bp()},children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:i(wy,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),"New board…"]},void 0,!0,void 0,this),i("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>p(null),children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:i(En,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),"All boards (Home)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var M_=3,O_={"waiting-approval":0,thinking:1,tooling:2,idle:3};function CA(){let e=lw.value;if(e.length===0)return null;let t=e.filter((c)=>!c.parentAgentId||!e.some((l)=>l.sessionId!==c.sessionId&&(l.sessionId===c.parentAgentId||l.source===c.parentAgentId))),n=[...t].sort((c,l)=>(O_[c.phase]??4)-(O_[l.phase]??4)),o=n.slice(0,M_),r=n.slice(M_),s=t.reduce((c,l)=>(c[l.phase]=(c[l.phase]??0)+1,c),{}),a=[s["waiting-approval"]&&`${s["waiting-approval"]} waiting on approval`,s.thinking&&`${s.thinking} thinking`,s.tooling&&`${s.tooling} running tools`,s.idle&&`${s.idle} idle`].filter(Boolean).join(", ");return i(pe,{children:[i("span",{class:"agent-chips",children:o.map((c)=>{let l=vt.value.filter((u)=>u.parentAgentId!=null&&(u.parentAgentId===c.sessionId||u.parentAgentId===c.source)).length;return i(Xe,{label:`Agent session — ${c.label}`,tapToOpen:!0,body:"What this attached agent is doing right now: idle, thinking, running a tool, or waiting on your approval. Steer it from the composer below.",children:i("span",{class:`agent-chip phase-${c.phase}`,"data-phase":c.phase,style:{"--identity-color":`hsl(${so(c.sessionId)} 65% 62%)`},children:[i("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"agent-chip-label",children:io(c)},void 0,!1,void 0,this),i("span",{class:"agent-chip-who hud-collapsible-text",children:c.label},void 0,!1,void 0,this),l>0&&i("span",{class:"agent-chip-workers",children:["+",l," worker",l===1?"":"s"]},void 0,!0,void 0,this),i("button",{type:"button",class:"agent-chip-end","aria-label":`End ${c.label} session`,title:`End ${c.label}'s session`,onClick:(u)=>{u.stopPropagation(),Ic({source:c.source,agentId:c.agentId})},children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},c.sessionId,!1,void 0,this)})},void 0,!1,void 0,this),r.length>0&&i(Xe,{label:`${t.length} agent sessions attached`,tapToOpen:!0,body:`${t.length} agents on this board — ${a}. The most active wear their own chips; the rest are here, and idle agents' cursors leave the board until they work again.`,children:i("span",{class:"agent-chip agent-chip-more","data-testid":"agent-chip-more",children:["+",r.length," · ",t.length," agents"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function TA(){let e=jo.value.length,t=Br.value!==null&&e>0,n=Nn(t?1000:0);if(!t)return null;let o=jo.value.map((r)=>Bc(r,n)).filter((r)=>r!==null).sort((r,s)=>r-s)[0];return i(Xe,{label:"Approval gates waiting on you",tapToOpen:!0,body:"The agent is blocked until you approve or reject in the session panel; unanswered gates auto-hold when the countdown runs out.",children:i("span",{class:"gate-badge",children:[e," gate",e===1?"":"s",o!==void 0&&` · ${Hc(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function IA(e){if(e>0.9)return"danger";if(e>=0.7)return"warn";return"ok"}function qi(e){return e>=1000?`${(e/1000).toFixed(e>=1e4?0:1)}k`:String(e)}function EA(){let e=Br.value;if(!e)return null;let t=Yd.value,n=e.contextUsage,o=n?n.used:t.used,r=n?n.total:t.total,s=r>0?Math.min(1,o/r):0,a=Math.round(s*100),c=n?{label:`Context window — reported by ${e.label}`,body:`${qi(n.used)} of ${qi(n.total)} tokens of the agent's actual context window are used. Your ✦-pinned nodes account for ≈ ${qi(t.used)} tokens of it.`}:{label:"Pins — pinned-context size (estimate)",body:`The nodes you pinned (✦) are what the agent is asked to carry as context: ≈ ${qi(t.used)} of a ${qi(t.total)}-token budget. When the agent's host reports its real context window, this meter switches to showing that instead.`};return i(Xe,{label:c.label,body:c.body,tapToOpen:!0,children:i("span",{class:`context-budget tone-${IA(s)}`,"data-mode":n?"window":"pins",children:[i("span",{class:"context-budget-caption hud-collapsible-text",children:n?"Context":"Pins"},void 0,!1,void 0,this),i("span",{class:"context-budget-track","aria-hidden":"true",children:i("span",{class:"context-budget-fill",style:{width:`${a}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"context-budget-label","data-testid":"budget-label",children:[o>0&&a===0?"<1":a,"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function AA(){let[e,t]=I(!1);if(Br.value)return null;return i(Xe,{label:"Start an agent session",body:"Attaches a session to this board: the next agent that writes here is adopted into it, and you get the panel, composer, and receipt.",children:i("button",{type:"button",class:"start-session-btn",disabled:e,onClick:()=>{t(!0),uo().finally(()=>t(!1))},children:[i("span",{class:"start-session-dot","aria-hidden":"true"},void 0,!1,void 0,this),"Start agent session",i("span",{class:"beta-tag",children:"beta"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function L_(){let e=Ot.value,t=It.value,n=K.value,o=F.value.size,r=De.value.size,s=dr.value,a=Array.from(F.value.values()).filter((m)=>m.type==="trace").length,[c,l]=I("");B(()=>{let m=!1;return fetch("/health").then((h)=>h.ok?h.json():null).then((h)=>{if(m||typeof h?.workspace!=="string"||!h.workspace)return;let v=h.workspace.replace(/[\\/]+$/,"").split(/[\\/]/).pop();if(v)l(v)}).catch(()=>{}),()=>{m=!0}},[]);let u=pp.value,p=u??(e==="connected"&&!t?"syncing":e),d=t?[`${o} node${o!==1?"s":""}`,...r>0?[`${r} edge${r!==1?"s":""}`]:[],...a>0?[`${a} trace${a!==1?"s":""}`]:s?["trace armed"]:[]].join(" · "):"Syncing canvas…",f=()=>{let m=rt();hr(m.width,m.height)};return i("div",{class:"top-bar",children:[i(Xe,{label:`Canvas status: ${p}`,tapToOpen:!0,body:"Live updates stream in over SSE; amber means reconnecting.",align:"start",children:i("span",{class:`connection-dot ${u??e}`,"aria-label":`Canvas status: ${p}`},void 0,!1,void 0,this)},void 0,!1,void 0,this),i($_,{fallbackName:c||"PMX Canvas"},void 0,!1,void 0,this),i("span",{class:"top-bar-meta hud-collapsible-text",children:_n.value?_n.value.slice(0,12):"…"},void 0,!1,void 0,this),i("span",{class:"top-bar-meta hud-collapsible-text",children:d},void 0,!1,void 0,this),i("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),i(CA,{},void 0,!1,void 0,this),i(TA,{},void 0,!1,void 0,this),i(EA,{},void 0,!1,void 0,this),i(f_,{},void 0,!1,void 0,this),i(AA,{},void 0,!1,void 0,this),i("div",{class:"top-bar-sep"},void 0,!1,void 0,this),Ne.value&&i(Xe,{label:"Export board",body:"One HTML file of this board that anyone can open, no install needed.",children:i("button",{type:"button",class:"present-button",onClick:()=>{Wr.value=!0},children:"Export"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Ne.value&&i(Xe,{label:"Present board",body:"Arrow keys or Space step through stops; Esc exits. Without a saved tour, groups are read top-to-bottom, left-to-right.",children:i("button",{type:"button",class:"present-button",onClick:()=>{on.value=!0},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Xe,{label:"Zoom out",shortcut:We("−"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>fr(0.8),"aria-label":"Zoom out",children:i(Ay,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Xe,{label:"Reset zoom",shortcut:We("0"),children:i("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>Kn({x:0,y:0,scale:1},250),"aria-label":"Reset view",children:[Math.round(n.scale*100),"%"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i(Xe,{label:"Zoom in",shortcut:We("+"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>fr(1.25),"aria-label":"Zoom in",children:i(Ey,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Xe,{label:"Fit all",shortcut:"F",align:"end",children:i("button",{type:"button",class:"top-bar-btn",onClick:f,"aria-label":"Fit canvas",children:i(va,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var po={status:{x:40,y:80,w:300,h:120},markdown:{x:380,y:80,w:720,h:600},context:{x:1130,y:80,w:320,h:400},"mcp-app":{x:380,y:720,w:960,h:600},webpage:{x:380,y:80,w:520,h:420},"json-render":{x:380,y:720,w:840,h:620},graph:{x:380,y:720,w:760,h:520},board:{x:380,y:80,w:360,h:160},ledger:{x:1130,y:520,w:320,h:280},trace:{x:40,y:900,w:200,h:56},file:{x:380,y:80,w:720,h:600},diff:{x:380,y:80,w:640,h:420},mermaid:{x:380,y:80,w:640,h:460},image:{x:380,y:80,w:720,h:520},html:{x:380,y:80,w:720,h:640},group:{x:220,y:60,w:840,h:560},prompt:{x:380,y:1260,w:520,h:400},response:{x:380,y:1480,w:720,h:400}};function Wi(e,t,n,o={}){let r=po[t];return{id:e,type:t,position:o.position??{x:r.x,y:r.y},size:o.size??{width:r.w,height:r.h},zIndex:t==="status"?0:1,collapsed:!1,pinned:!1,data:n}}var Wo=null,Xi=null,Zc=0,mo=null,zA=3000,PA=2000,D_=5000,Vi=!1,$n=null,Vr=null,ho=0,fo=null;function NA(){if(typeof location>"u"||typeof window>"u")return null;let e=new URLSearchParams(location.search).get("transport");if(e==="poll"||e==="sse")return e;if(window.__PMX_AMP_ORB===!0)return"poll";return null}var Gr=new Map;function Ji(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t).toString(36)}function qc(e){if(!Xi)return e;let t=Xi.get(e.id);if(!t)return e;return{...e,position:t.position??e.position,size:t.size??e.size,collapsed:t.collapsed??e.collapsed,pinned:t.pinned??e.pinned}}function Ki(e,t,n){return qc(Wi(e,t,n))}function RA(){return Xa([...F.value.values()],po.markdown.w,po.markdown.h)}function Xr(){if(!F.value.has("status-main"))kn(Ki("status-main","status",{phase:"idle",message:"",elapsed:0}))}function $A(e,t){let n=`md-${Ji(e)}`;if(F.value.get(n))ie(n,{path:e,title:t}),Ce.value=n;else{let r=RA(),s=Ki(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=r,kn(s),Ke(n)}}function MA(e){if(F.value.get("context-main"))ie("context-main",{cards:e});else if(e.length>0){let o=Ki("context-main","context",{cards:e});kn(o)}}function OA(e){let t=e.url,n=`mcp-${Ji(t)}`;if(F.value.get(n))ie(n,e);else kn(Ki(n,"mcp-app",e)),Ke(n)}function LA(e){let t=e.toolCallId,o=(typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null)??(t.startsWith("ext-app-")?t:`ext-app-${t}`);if(F.value.get(o)){ie(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[x,g]of F.value.entries())if(g.type==="mcp-app"&&g.data.mode==="ext-app"&&g.data.serverName===s&&g.data.toolName===a&&!g.data.toolResult){ie(x,{...e});return}}let{_x:c,_y:l,_width:u,_height:p}=e,d=po["mcp-app"],f=u??d.w,m=p??d.h,h=c===void 0||l===void 0?Xa([...F.value.values()],f,m):null,v=qc(Wi(o,"mcp-app",{mode:"ext-app",...e},{position:{x:c??h?.x??d.x,y:l??h?.y??d.y},size:{width:f,height:m}}));kn(v),Ke(o,{recordHistory:!1})}function DA(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(F.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&F.value.has(n))return n;for(let[o,r]of F.value.entries())if(r.type==="mcp-app"&&r.data.mode==="ext-app"&&r.data.toolCallId===e)return o;return null}function Z_(e){let t=typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null;if(t&&F.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return DA(e.toolCallId)}function U_(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,r]of F.value.entries())if(r.type==="mcp-app"&&r.data.mode==="ext-app"&&r.data.serverName===e&&r.data.toolName===t&&!r.data.toolResult){if(n)return null;n=o}return n}function q_(e){if(F.value.get("ledger-main"))ie("ledger-main",e);else{let o=Ki("ledger-main","ledger",e);o.collapsed=!0,kn(o)}}function Tp(e){if(!Ai(e))return;if(document.documentElement.setAttribute("data-theme",e),Or(),tt.value!==e)tt.value=e}function FA(e){return e==="markdown"||e==="mcp-app"||e==="webpage"||e==="json-render"||e==="graph"||e==="board"||e==="prompt"||e==="response"||e==="status"||e==="context"||e==="ledger"||e==="trace"||e==="file"||e==="diff"||e==="mermaid"||e==="image"||e==="html"||e==="group"}function BA(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function Ip(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.x!=="number"||typeof t.y!=="number")return null;return{x:t.x,y:t.y}}function W_(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.width!=="number"||typeof t.height!=="number")return null;return{width:t.width,height:t.height}}function HA(e){let t=Ip(e),n=W_(e);return t&&n?{...t,...n}:null}function jA(e){if(typeof e.id!=="string"||!e.id)return null;if(!FA(e.type))return null;let t=Ip(e.position),n=W_(e.size);if(!t||!n)return null;let o=e.data&&typeof e.data==="object"?Object.fromEntries(Object.entries(e.data)):{};return{id:e.id,type:e.type,position:t,size:n,zIndex:typeof e.zIndex==="number"?e.zIndex:1,collapsed:e.collapsed===!0,pinned:e.pinned===!0,data:o}}function ZA(e){if(typeof e.id!=="string"||!e.id)return null;if(typeof e.from!=="string"||!e.from)return null;if(typeof e.to!=="string"||!e.to)return null;if(!BA(e.type))return null;return{id:e.id,from:e.from,to:e.to,type:e.type,...typeof e.label==="string"?{label:e.label}:{},...e.style==="solid"||e.style==="dashed"||e.style==="dotted"?{style:e.style}:{},...e.animated===!0?{animated:!0}:{}}}function UA(e){if(typeof e.id!=="string"||!e.id)return null;if(e.type!=="freehand"&&e.type!=="text")return null;if(!Array.isArray(e.points))return null;let t=e.points.map((o)=>Ip(o)).filter((o)=>o!==null),n=HA(e.bounds);if(t.length<(e.type==="text"?1:2)||!n)return null;return{id:e.id,type:e.type,points:t,bounds:n,color:typeof e.color==="string"?e.color:"#f97316",width:typeof e.width==="number"?e.width:4,...typeof e.text==="string"?{text:e.text}:{},...typeof e.label==="string"?{label:e.label}:{},createdAt:typeof e.createdAt==="string"?e.createdAt:""}}var F_="pmx-canvas-version-reload";function qA(e,t){if(typeof window>"u")return;let n=window,o=(s,a)=>typeof s==="string"&&s!==""&&s!=="unknown"&&typeof a==="string"&&a!==""&&a!=="unknown"&&s!==a;if(!o(e,n.__PMX_BOOT_SERVER_VERSION)&&!o(t,n.__PMX_BOOT_BUNDLE_STAMP))return;let r=`${String(e)}::${String(t)}`;try{if(window.sessionStorage.getItem(F_)===r)return;window.sessionStorage.setItem(F_,r)}catch{return}window.location.reload()}function WA(e){let t=ao.value[0]?.id;if(tp(e),yt.value&&ao.value[0]?.id!==t)lo()}function VA(e){Sw(e)}var B_=null,Gi=0,Sp=0,kp=0;function GA(e){sd(e)}function XA(){let e=++Gi;Xi=null,It.value=!1,ja(),Qv(),Gs(),Ac(),nn.value=null,Ep();let t=Sp,n=kp;Rv().then((o)=>{if(e===Gi&&t===Sp)V_({layout:o})}),Y("fetchPinnedContext","/api/canvas/pinned-context",{}).then((o)=>{if(e===Gi&&n===kp)G_({nodeIds:o.nodeIds})})}Yy(XA);function JA(e){if(_n.value=e.sessionId||"",Ot.value="connected",Mu(),zo.value+=1,qA(e.version,e.bundleStamp),gi(),Lv().then(tp),B_?.(),!Xs)B_=Qb();if(Y("fetchHumanPresence","/api/canvas/human-presence",null).then(sd),Ep().then(()=>{if(yt.value)lo()}),typeof e.theme==="string"&&!mp())Tp(e.theme);if(e.ledgerSummary)q_(e.ledgerSummary)}function KA(e){if(typeof e.path!=="string"||!e.path)return;let t=e.path,n=(typeof e.title==="string"?e.title:"")||t.split("/").pop()||"Untitled";if($A(t,n),e.ledgerSummary)q_(e.ledgerSummary)}function YA(e){Xr(),ie("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function QA(e){Xr(),ie("status-main",{phase:e.phase,detail:e.detail})}function ez(e){let t=e.cards??[];MA(t)}function tz(e){if(typeof e.url==="string"&&e.url)OA({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function nz(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let r=`mcp-${Ji(o)}`;if(F.value.has(r))ie(r,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function oz(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${Ji(e.url)}`;if(F.value.has(t))ie(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function rz(e){let n=F.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);ie("context-main",{auxTabs:o})}function iz(e){if(F.value.has("context-main"))if(e.mode==="all")ie("context-main",{auxTabs:[]});else{let o=F.value.get("context-main");if(!o)return;let r=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);ie("context-main",{auxTabs:r})}}function sz(e){Xr(),ie("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function az(e){Xr(),ie("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function cz(e){Xr(),ie("status-main",{activeTool:null})}function lz(e){if(e.state==="active"&&e.path){let n=`md-${Ji(e.path)}`;if(F.value.has(n))ie(n,{reviewActive:!0})}}function uz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;LA({toolCallId:e.toolCallId,...typeof e.nodeId==="string"&&e.nodeId.length>0?{nodeId:e.nodeId}:{},title:e.title,html:e.html,toolInput:e.toolInput,serverName:e.serverName,toolName:e.toolName,appSessionId:e.appSessionId,resourceUri:e.resourceUri,toolDefinition:e.toolDefinition,resourceMeta:e.resourceMeta,hostMode:"hosted",trustedDomain:!0,...e.chartConfig?{chartConfig:e.chartConfig}:{},...typeof e.x==="number"&&{_x:e.x},...typeof e.y==="number"&&{_y:e.y},...typeof e.width==="number"&&{_width:e.width},...typeof e.height==="number"&&{_height:e.height}})}function dz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=Z_(e)??U_(e.serverName,e.toolName);if(!t)return;if(F.value.has(t))ie(t,{html:e.html})}function pz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=Z_(e)??U_(e.serverName,e.toolName);if(!t)return;if(F.value.has(t)){if(e.success===!1){Jn(t);return}ie(t,{toolResult:Hd({result:e.result,success:typeof e.success==="boolean"?e.success:void 0,error:typeof e.error==="string"?e.error:void 0,content:typeof e.content==="string"?e.content:void 0,detailedContent:typeof e.detailedContent==="string"?e.detailedContent:void 0})})}}function mz(e){Xr(),ie("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function fz(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:r,contextNodeIds:s}=e;if(e.threadNodeId&&F.value.has(e.threadNodeId)){let a=e.threadNodeId,c=F.value.get(a);if(!c)return;let l=Array.isArray(c.data.turns)?[...c.data.turns]:[],u=l[l.length-1];if(!u||u.role!=="user"||u.text!==n)l.push({role:"user",text:n,status:"pending"});ie(a,{turns:l,threadStatus:"pending"});return}if(!F.value.has(t)){let a=o??po.prompt;kn(qc(Wi(t,"prompt",{text:n,turns:n?[{role:"user",text:n,status:"pending"}]:[],threadStatus:n?"pending":"draft",status:n?"pending":"draft",parentNodeId:r,contextNodeIds:s},{position:{x:a.x,y:a.y}}))),Ke(t)}if(r&&F.value.has(r))la({id:`edge-${r}-${t}`,from:r,to:t,type:"flow",style:"dashed"})}function hz(e){let{nodeId:t,status:n}=e;if(t&&F.value.has(t))ie(t,{status:n})}function gz(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?F.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){Gr.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),ie(n,{turns:s,threadStatus:"streaming",_activeResponseId:t}),Ke(n);return}let r=o?{x:o.position.x,y:o.position.y+o.size.height+24}:{x:po.response.x,y:po.response.y};if(!F.value.has(t))kn(qc(Wi(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:r})));if(n)la({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});Ke(t)}function vz(e){let t=e.responseNodeId;if(!t)return;let n=Gr.get(t);if(n){let o=F.value.get(n);if(o&&Array.isArray(o.data.turns)){let r=[...o.data.turns],s=r[r.length-1];if(s&&s.role==="assistant")s.text=e.content,s.status="streaming";ie(n,{turns:r,threadStatus:"streaming"})}return}if(!F.value.has(t))return;ie(t,{content:e.content,status:"streaming"})}function yz(e){let t=e.responseNodeId;if(!t)return;let n=Gr.get(t);if(n){let s=F.value.get(n);if(s&&Array.isArray(s.data.turns)){let a=[...s.data.turns],c=a[a.length-1];if(c&&c.role==="assistant")c.text=e.content,c.status="complete";ie(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}Gr.delete(t);return}if(!F.value.has(t))return;ie(t,{content:e.content,status:"complete"});let r=F.value.get(t)?.data.promptNodeId;if(r){let s=`edge-${r}-${t}`,a=De.value.get(s);if(a)cy(s),la({...a,animated:!1})}}function V_(e){let t=e.layout;if(!t?.nodes)return;Sp+=1;let n=!It.value;It.value=!0;let o=t.nodes.map(jA).filter((c)=>c!==null),r=Array.isArray(t.edges)?t.edges.map(ZA).filter((c)=>c!==null):Array.from(De.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(UA).filter((c)=>c!==null):void 0,a=t.viewport?{x:typeof t.viewport.x==="number"?t.viewport.x:0,y:typeof t.viewport.y==="number"?t.viewport.y:0,scale:typeof t.viewport.scale==="number"?t.viewport.scale:1}:void 0;if(n)Tn();fy({...a?{viewport:a}:{},nodes:o,edges:r,...s?{annotations:s}:{}},{applyViewport:n}),mu({event:"canvas-layout-update",data:e})}function bz(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function xz(e){if(Iu())return;let t=e.nodeId;if(t&&F.value.has(t)){if(e.noPan===!0){Cn(t);return}Ke(t)}}function wz(e){if(Iu())return;let t=e.viewport;if(!t)return;let n=typeof t.x==="number"?t.x:0,o=typeof t.y==="number"?t.y:0,r=typeof t.scale==="number"?t.scale:1;Tn(),dy({x:n,y:o,scale:r})}function _z(e){if(F.value.get("context-main"))ie("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function Sz(e){dr.value=e.enabled===!0}function kz(e){if(typeof e.theme==="string"&&!mp())Tp(e.theme)}function G_(e){kp+=1;let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];ay(t),mu({event:"context-pins-changed",data:e})}var Uc=null,Cp=0;async function Ep(){let e=++Cp,t=Gi,n=await Ov();if(e===Cp&&t===Gi)nn.value=n}function H_(){if(Uc)clearTimeout(Uc);Cp+=1,Uc=setTimeout(()=>{if(Uc=null,Ep(),yt.value)lo()},150)}function Cz(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;qb(t)}function Tz(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)Vb(t,typeof e.nodeId==="string"?e.nodeId:void 0);else id(t)}var X_={connected:JA,"workbench-open":KA,"canvas-status":YA,"execution-phase":QA,"context-cards":ez,"mcp-app-candidate":tz,"mcp-app-host-snapshot":nz,"mcp-app-host-fallback":oz,"aux-open":rz,"aux-close":iz,"assistant-complete":sz,"tool-start":az,"tool-complete":cz,"review-state":lz,"subagent-status":mz,"ext-app-open":uz,"ext-app-update":dz,"ext-app-result":pz,"context-pins-changed":G_,"boards-changed":$o,"canvas-layout-update":V_,"canvas-focus-node":xz,"canvas-viewport-update":wz,"context-usage":_z,"trace-state":Sz,"theme-changed":kz,"canvas-prompt-created":fz,"canvas-prompt-status":hz,"canvas-response-start":gz,"canvas-response-delta":vz,"canvas-response-complete":yz,"ax-state-changed":H_,"ax-event-created":H_,"ax-intent":Cz,"ax-intent-clear":Tz,"agent-presence":WA,"human-presence":GA,"agent-session-ended":VA};function J_(e,t){let n=X_[e];if(!n)return;let o=n;try{o(t)}catch(r){console.warn(`[sse-bridge] Handler for "${e}" failed:`,r)}}function j_(){Vi=!0,ho+=1;let e=ho;Ot.value="connecting";let t=null,n=!1,o=async()=>{if(e!==ho)return;try{let r=new URLSearchParams;if(Vr!==null)r.set("since",String(Vr));let s=_n.value;if(s)r.set("session",s);let a=r.toString(),c=await fetch(`/api/workbench/poll${a?`?${a}`:""}`);if(e!==ho)return;if(!c.ok)throw Error(`poll failed with HTTP ${c.status}`);let l=await c.json();if(e!==ho)return;if(!l.ok)throw Error("poll returned ok: false");let u=t;if(t=l.sessionId??null,u!==null&&l.sessionId&&u!==l.sessionId&&!l.snapshot){Vr=null,$n=setTimeout(()=>void o(),0);return}if(l.snapshot&&n)Xi=Tu(),It.value=!1,Gs(),ja(),Gr.clear();for(let p of l.events)J_(p.event,p.payload);n=!0,Vr=l.seq,Po.value=0,No.value=0,Ot.value="connected",$n=setTimeout(()=>void o(),PA)}catch(r){if(e!==ho)return;console.warn("[sse-bridge] poll transport error:",r),Ot.value="disconnected",Po.value+=1,No.value=D_,$n=setTimeout(()=>void o(),D_)}};return o(),()=>{if(ho+=1,Vi=!1,Vr=null,$n)clearTimeout($n),$n=null}}function Ap(){if(Jw(Tp),Xi=Tu(),It.value=!1,Gs(),ja(),Gr.clear(),mo)clearTimeout(mo),mo=null;let e=NA();if(e==="poll"||Vi)return j_();let t=_n.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";Ot.value="connecting";let o=new EventSource(n);Wo=o;let r=!1;if(fo)clearTimeout(fo);if(fo=null,e!=="sse")fo=setTimeout(()=>{if(fo=null,r||Wo!==o)return;console.warn("[sse-bridge] No SSE event within watchdog window — switching to polling transport."),window.dispatchEvent(new Event("pmx-canvas-boot-extend")),o.close(),Wo=null,j_()},zA);for(let[s]of Object.entries(X_))o.addEventListener(s,(a)=>{r=!0;try{J_(s,JSON.parse(a.data))}catch(c){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,c)}});return o.onopen=()=>{if(Wo!==o)return;Zc=0,Po.value=0,No.value=0,Ot.value="connected"},o.onerror=()=>{if(Wo!==o)return;Ot.value="disconnected",o.close(),Wo=null,Zc+=1;let s=bz(Zc);Po.value=Zc,No.value=s,mo=setTimeout(()=>{mo=null,Ap()},s)},()=>{if(mo)clearTimeout(mo),mo=null;if(fo)clearTimeout(fo),fo=null;if(Vi){if(ho+=1,Vi=!1,Vr=null,$n)clearTimeout($n),$n=null}o.close(),Wo=null}}function Vo(e,t){console.error(`[app] ${e} failed`,t)}function K_(){let[e,t]=I(!0),[n,o]=I(!1),[r,s]=I(!1),[a,c]=I(!1),[l,u]=I(!1),[p,d]=I(null),f=R(null),{menu:m,openNodeMenu:h,openCanvasMenu:v,openEdgeMenu:x,closeMenu:g}=Qw(),y=It.value,E=br.value&&Ne.value===null,L=yt.value,P=H(()=>t((N)=>!N),[]),b=H(()=>o((N)=>!N),[]),T=H(()=>o(!1),[]),w=H((N)=>d(N),[]),_=H((N,Z)=>{Kn({x:N,y:Z,scale:K.value.scale},200)},[]);B(()=>Ap(),[]),B(()=>{let N=()=>c(!0);return window.addEventListener("pmx-open-board-link",N),()=>window.removeEventListener("pmx-open-board-link",N)},[]),B(()=>{let N=null,Z=()=>{if(N!==null)window.clearTimeout(N);N=window.setTimeout(()=>{N=null,gi()},400)};return window.addEventListener("resize",Z),()=>{if(N!==null)window.clearTimeout(N);window.removeEventListener("resize",Z)}},[]),B(()=>{let N=(S)=>{let V=(S.metaKey||S.ctrlKey)&&!S.altKey;if(V&&S.key==="k"){S.preventDefault(),s((se)=>!se);return}if(S.key==="Escape"&&p){S.preventDefault(),d(null);return}if(S.key==="Escape"&&qe.value&&!tn.value){S.preventDefault(),In();return}if(S.key==="Escape"&&r){S.preventDefault(),s(!1);return}if(S.key==="Escape"&&l){S.preventDefault(),u(!1);return}let ge=S.target,Ze=ge?.tagName;if(Ze==="INPUT"||Ze==="TEXTAREA"||ge?.isContentEditable)return;if(S.key===" "&&!S.repeat&&!V){S.preventDefault(),bi.value=!0;return}if(S.key==="?"||S.key==="/"&&S.shiftKey){S.preventDefault(),u((se)=>!se);return}if(V&&(S.key==="z"||S.key==="Z"))S.preventDefault(),ap(S.shiftKey);else if(V&&(S.key==="y"||S.key==="Y"))S.preventDefault(),ap(!0);else if(V&&S.key==="0")S.preventDefault(),Kn({x:0,y:0,scale:1},250);else if(V&&(S.key==="="||S.key==="+"))S.preventDefault(),fr(1.25);else if(V&&S.key==="-")S.preventDefault(),fr(0.8);else if(S.key==="Escape"){if(be.value.size>0||pn.value!==null){wt();return}Ce.value=null,g()}else if(S.key==="Tab")S.preventDefault(),gy(S.shiftKey?-1:1);else if(S.key==="Delete"||S.key==="Backspace"){if(pn.value!==null){let de=pn.value;S.preventDefault(),pn.value=null,oa(de).catch((me)=>Vo("delete-edge",me));return}let se=be.value.size>0?[...be.value]:Ce.value?[Ce.value]:[];if(se.length===0)return;S.preventDefault();for(let de of se)Vn(de).catch((me)=>Vo("delete",me));wt(),Ce.value=null}else if(Ce.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(S.key)){S.preventDefault();let se=S.key.replace("Arrow","").toLowerCase();vy(se)}else if(!V&&!S.altKey){let se=S.key.toLowerCase();if(se==="v"&&!S.shiftKey)Et.value="select";else if(se==="c"&&!S.shiftKey&&!V)S.preventDefault(),Et.value=Et.value==="connect"?"select":"connect";else if(se==="m"&&!S.shiftKey)S.preventDefault(),Ft({type:"markdown",title:"New note",width:520,height:360}).catch((de)=>Vo("create markdown",de));else if(se==="a"&&!S.shiftKey)S.preventDefault(),d((de)=>de==="pen"?null:"pen");else if(se==="g"&&!S.shiftKey){S.preventDefault();let de=Array.from(be.value);if(de.length>=2)cr({title:"Group",childIds:de}).catch((me)=>Vo("group selection",me)),wt();else Ft({type:"group",title:"Group"}).catch((me)=>Vo("create group",me))}else if(se==="g"&&S.shiftKey){S.preventDefault();for(let de of oy())Jn(de),lr(de).catch((me)=>Vo("ungroup",me));wt()}else if(se==="i"&&!S.shiftKey)S.preventDefault(),Rn("image");else if(se==="w"&&!S.shiftKey)S.preventDefault(),Rn("webpage");else if(se==="h"&&!S.shiftKey)S.preventDefault(),Ft({type:"html",title:"HTML surface"}).catch((de)=>Vo("create html",de));else if(se==="f"&&S.shiftKey)S.preventDefault(),Rn("file");else if(se==="f"&&!S.shiftKey){S.preventDefault();let de=rt();hr(de.width,de.height)}}},Z=(S)=>{if(S.key===" ")bi.value=!1},j=()=>{bi.value=!1};return document.addEventListener("keydown",N),document.addEventListener("keyup",Z),window.addEventListener("blur",j),()=>{document.removeEventListener("keydown",N),document.removeEventListener("keyup",Z),window.removeEventListener("blur",j)}},[p,g,r,l]),B(()=>{let N=window.setTimeout(()=>void gi(),250);return()=>window.clearTimeout(N)},[L]),B(()=>{if(!y)return;let N=window.__pmxCanvasBootstrapReady;if(typeof N==="function")N()},[y]);let z=Array.from(F.value.values()),U=rt();return i("div",{class:`app-shell${on.value?" is-presenting":""}`,"data-session-active":L?"true":"false",children:[i(xy,{},void 0,!1,void 0,this),i(r_,{minimapVisible:e,onToggleMinimap:P,snapshotOpen:n,onToggleSnapshot:b,snapshotBtnRef:f,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>u((N)=>!N),annotationTool:p,onSetAnnotationTool:w},void 0,!1,void 0,this),i("div",{class:"app-main",children:[i(L_,{},void 0,!1,void 0,this),i(Vw,{},void 0,!1,void 0,this),i("div",{class:"canvas-region",ref:(N)=>iv(N),children:[i(qw,{onNodeContextMenu:h,onCanvasContextMenu:v,onEdgeContextMenu:x,annotationMode:p!==null,annotationTool:p},void 0,!1,void 0,this),i(By,{},void 0,!1,void 0,this),i(Fy,{},void 0,!1,void 0,this),i(h_,{},void 0,!1,void 0,this),i(g_,{},void 0,!1,void 0,this),E?i(p_,{},void 0,!1,void 0,this):y&&z.length===0&&Ge.value.size===0&&i(i_,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),be.value.size>0&&i(C_,{},void 0,!1,void 0,this),L?i(Ww,{},void 0,!1,void 0,this):Ae.value.size>0&&i(n_,{},void 0,!1,void 0,this),i(A_,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),i(jy,{},void 0,!1,void 0,this),i(m_,{},void 0,!1,void 0,this),qe.value&&i(x_,{},void 0,!1,void 0,this),i(R_,{open:n,onClose:T,anchorRef:f},void 0,!1,void 0,this),e&&!E&&i(k_,{viewport:K,nodes:F,edges:De,onNavigate:_,containerWidth:U.width,containerHeight:U.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L&&i(E_,{},void 0,!1,void 0,this),m&&i(e_,{menu:m,onClose:g},void 0,!1,void 0,this),r&&i(Kw,{onClose:()=>s(!1),onToggleMinimap:P},void 0,!1,void 0,this),a&&i(Yw,{onClose:()=>c(!1)},void 0,!1,void 0,this),l&&i(z_,{onClose:()=>u(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}Xy();var Y_=document.getElementById("app");if(Y_)Jr(i(K_,{},void 0,!1,void 0,this),Y_);
|
|
331
|
+
${a.trim()}`},void 0,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:e,children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"submit",class:"text-prompt-confirm",disabled:!r.trim()||!a.trim(),children:["Continue on GitHub ",i(hn,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Gi(e,t){console.error(`[tool-rail] ${e} failed`,t)}function Wo(e){let t={image:{message:"Image URL (https://… or data:image/…)",placeholder:"https://example.com/diagram.png"},file:{message:"Workspace file path",placeholder:"src/server/server.ts"},webpage:{message:"Page URL",placeholder:"https://example.com"}};Dt(t[e].message,t[e].placeholder).then((n)=>{if(!n)return;Gt({type:e,content:n}).catch((o)=>Gi(`create ${e}`,o))})}function ot({label:e,shortcut:t,detail:n,ariaLabel:o,active:r,menuOpen:s,onClick:a,btnRef:c,children:l}){let[u,p]=I(null),d=(h)=>{let v=h.currentTarget.getBoundingClientRect();p({left:v.right+10,top:v.top+v.height/2})},m=()=>p(null),f=o??(t?`${e} (${t})`:n?`${e} (${n})`:e);return i(ue,{children:[i("button",{ref:c,type:"button",class:`rail-btn${r?" active":""}`,"aria-label":f,"aria-pressed":r===void 0?void 0:r,onClick:(h)=>{m(),a(h)},onPointerEnter:d,onPointerLeave:m,onFocus:d,onBlur:m,children:l},void 0,!1,void 0,this),u&&!s&&i("span",{class:"toolbar-tooltip rail-tooltip",role:"tooltip","data-testid":"rail-tooltip",style:{left:`${u.left}px`,top:`${u.top}px`},children:[i("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),(t||n)&&i("span",{class:"toolbar-tooltip-meta",children:[t&&i("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this),n&&i("span",{children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function c_({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:r,onOpenPalette:s,onOpenShortcuts:a,annotationTool:c,onSetAnnotationTool:l}){let u=At.value,p=mr.value,d=Array.from(O.value.values()).filter((P)=>P.type==="trace").length,m=Fe.value.size,[f,h]=I(!1),[v,x]=I(null),[g,y]=I(null),E=z(null),D=z(null),N=(P)=>(q)=>{if(v===P){x(null);return}let R=q.currentTarget.getBoundingClientRect();y({bottom:R.bottom,right:R.right}),x(P)},b=g?{position:"fixed",left:`${g.right+8}px`,bottom:`${window.innerHeight-g.bottom}px`,top:"auto",right:"auto"}:void 0;B(()=>{if(!v)return;let P=(R)=>{if(E.current&&R.target instanceof Node&&!E.current.contains(R.target))x(null)},q=(R)=>{if(R.key==="Escape")x(null)};return document.addEventListener("pointerdown",P),document.addEventListener("keydown",q),()=>{document.removeEventListener("pointerdown",P),document.removeEventListener("keydown",q)}},[v]);let T=(P)=>{Fc(),document.documentElement.setAttribute("data-theme",P),Fr(),nt.value=P,ta(P),x(null)},w=ud(nt.value),_=(P,q={})=>{fetch(`/api/workbench/intent?_ts=${Date.now()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:P,payload:q})}).catch((R)=>Gi("sendIntent",R))};return i(ue,{children:[i("div",{class:"tool-rail",ref:E,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[i(ot,{label:"Home",ariaLabel:"PMX Canvas — Home",onClick:()=>{x(null),Nt(null).catch((P)=>Gi("openHome",P))},children:i("span",{class:"rail-brand",children:i(wa,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Bug and feedback",menuOpen:f,onClick:()=>{x(null),h(!0)},children:i("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:[i("rect",{x:"4.5",y:"5",width:"7",height:"9",rx:"3.5"},void 0,!1,void 0,this),i("path",{d:"M6 5V4a2 2 0 0 1 4 0v1M8 8v6M2 4l2.5 2M14 4l-2.5 2M1.5 9h3M11.5 9h3M2 14l2.5-2M14 14l-2.5-2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-divider"},void 0,!1,void 0,this),i(ot,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>At.value="select",children:i(Fy,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>At.value="pan",children:i(By,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>At.value="connect",children:i("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("circle",{cx:"4",cy:"4",r:"2"},void 0,!1,void 0,this),i("circle",{cx:"12",cy:"12",r:"2"},void 0,!1,void 0,this),i("path",{d:"M5.5 5.5 C 8 8, 8 8, 10.5 10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-divider"},void 0,!1,void 0,this),i(ot,{label:"Markdown note",shortcut:"M",onClick:()=>void Gt({type:"markdown",title:"New note",width:520,height:360}).catch((P)=>Gi("create markdown",P)),children:i(Qn,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Attach files",ariaLabel:"Attach files",detail:"Images (PNG, JPEG, SVG…), Markdown and text/code files. PDF, Word, Excel, PowerPoint and OpenDocument use agent import with review.",onClick:()=>D.current?.click(),children:i(Iy,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("input",{ref:D,type:"file",hidden:!0,multiple:!0,"aria-label":"Attach files",onChange:(P)=>{let q=it(),R=K.value;Hr(Array.from(P.currentTarget.files??[]),(q.width/2-R.x)/R.scale,(q.height/2-R.y)/R.scale),P.currentTarget.value=""}},void 0,!1,void 0,this),i(ot,{label:"Webpage",shortcut:"W",onClick:()=>Wo("webpage"),children:i(yr,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Group",shortcut:"G",onClick:()=>void Gt({type:"group",title:"Group"}).catch((P)=>Gi("create group",P)),children:i(Nu,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Draw",shortcut:"A",active:c==="pen",onClick:()=>l(c==="pen"?null:"pen"),children:i(Py,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Text note",active:c==="text",onClick:()=>l(c==="text"?null:"text"),children:i(Ry,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Eraser",active:c==="eraser",onClick:()=>l(c==="eraser"?null:"eraser"),children:i(Ny,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-spacer"},void 0,!1,void 0,this),i(ot,{label:"Search & commands",shortcut:Ve("K"),onClick:s,children:i(Oy,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Arrange",detail:m>0?"graph-aware":"grid",onClick:()=>m>0?ha():fa(),children:i(An,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:p?"Disable trace":"Enable trace",active:p,onClick:()=>_("trace-toggle",{enabled:!p}),children:i(My,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),(p||d>0)&&i(ot,{label:"Clear trace",onClick:()=>_("trace-clear"),children:i(Ly,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:e?"Hide minimap":"Show minimap",active:e,onClick:t,children:i(ba,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(ot,{label:"Snapshots",active:n,onClick:o,btnRef:r,children:i($y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"toolbar-menu-anchor",children:[i(ot,{label:"Theme",detail:Pr[w].label,menuOpen:v==="theme",ariaLabel:"Choose theme",active:v==="theme",onClick:N("theme"),children:Nr(w)==="dark"?i(zy,{},void 0,!1,void 0,this):i(xa,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v==="theme"&&i("div",{class:"toolbar-menu",style:b,role:"menu","aria-label":"Theme",children:ld.map((P)=>i("button",{type:"button",role:"menuitemradio","aria-checked":w===P,class:`toolbar-menu-item${w===P?" active":""}`,onClick:()=>T(P),children:[i("span",{class:"theme-swatch",style:{background:Pr[P].swatchBg},children:i("span",{class:"theme-swatch-dot",style:{background:Pr[P].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{children:Pr[P].label},void 0,!1,void 0,this),w===P&&i("span",{class:"toolbar-menu-check","aria-hidden":"true",children:"✓"},void 0,!1,void 0,this)]},P,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(ot,{label:"Shortcuts",shortcut:"?",onClick:a,children:i(Dy,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f&&i(a_,{onClose:()=>h(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function l_({onOpenPalette:e}){let t=z(null),n=()=>{Gt({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(r)=>{if(!r||r.length===0)return;let s=qn(),a=K.value;await Hr(Array.from(r),(s.x-a.x)/a.scale,(s.y-a.y)/a.scale)};return i("div",{class:"empty-state","data-testid":"empty-state",children:[i("svg",{class:"empty-state-mark",width:"52",height:"52",viewBox:"0 0 64 64",fill:"none","aria-hidden":"true",children:[i("rect",{x:"8",y:"8",width:"48",height:"48",rx:"7"},void 0,!1,void 0,this),i("rect",{x:"20",y:"20",width:"24",height:"24",rx:"4","stroke-dasharray":"4 4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{children:[i("div",{class:"empty-state-title",children:"Nothing on this board yet"},void 0,!1,void 0,this),i("div",{class:"empty-state-sub",children:"Drop files anywhere, paste a link, or start from a note."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"empty-state-grid",children:[i("button",{type:"button",class:"empty-state-action",onClick:n,children:[i(Qn,{size:16,class:"tone-accent"},void 0,!1,void 0,this),i("span",{class:"empty-state-action-label",children:"New markdown note"},void 0,!1,void 0,this),i("kbd",{children:"M"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"empty-state-action",onClick:()=>t.current?.click(),children:[i("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round",class:"tone-warn","aria-hidden":"true",children:[i("path",{d:"M8 10 V2 M8 2 L5 5 M8 2 L11 5"},void 0,!1,void 0,this),i("path",{d:"M2 10 V13 H14 V10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"empty-state-action-label",children:"Drop files"},void 0,!1,void 0,this),i("span",{class:"empty-state-action-hint",children:"or pick"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"empty-state-action",onClick:()=>Wo("webpage"),children:[i(yr,{size:16,class:"tone-ok"},void 0,!1,void 0,this),i("span",{class:"empty-state-action-label",children:"Paste a link"},void 0,!1,void 0,this),i("kbd",{children:Ve("V")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"empty-state-action is-agent",onClick:()=>void uo(),children:[i(wr,{size:16,class:"tone-purple"},void 0,!1,void 0,this),i("span",{class:"empty-state-action-label",children:"Start agent session"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"empty-state-hint",onClick:e,children:["? shortcuts · ",Ve("K")," palette"]},void 0,!0,void 0,this),i("input",{ref:t,type:"file",multiple:!0,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:(r)=>{let s=r.currentTarget;o(s.files).finally(()=>{s.value=""})}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var u_="From old snapshots";function d_(e){if(!e?.trim())return null;let t=e.split("/").map((n)=>n.trim());if(t.length>8)throw Error("Folders can be nested up to 8 levels.");if(t.some((n)=>!n||n==="."||n===".."||n.length>60))throw Error('Each folder name must be 1–60 characters, and cannot be "." or "..".');return t.join("/")}function vp(e){return e.split("/").map((t,n,o)=>o.slice(0,n+1).join("/"))}function p_({board:e,folders:t,onClose:n}){let o=z(null),[r,s]=I(e.category??""),[a,c]=I(""),[l,u]=I(!1),[p,d]=I("");Rt(o,!0),B(()=>{let h=(v)=>{if(v.key!=="Escape")return;if(v.preventDefault(),v.stopPropagation(),!l)n()};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[l,n]);let m=a.trim()?[r,a.trim()].filter(Boolean).join("/"):r,f=async()=>{let h;try{if(a.includes("/"))throw Error("Use one folder name; choose its parent above.");h=d_(m)}catch(v){d(v instanceof Error?v.message:String(v));return}if(u(!0),d(""),await Ia(e.id,{category:h}),Pt.value.find((v)=>v.id===e.id)?.category===h)n();else d("Could not move this board. Try again.");u(!1)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>!l&&n(),children:i("div",{ref:o,class:"text-prompt home-folder-dialog",role:"dialog","aria-modal":"true","aria-label":`Move ${e.name}`,onPointerDown:(h)=>h.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:["Move “",e.name,"”"]},void 0,!0,void 0,this),i("p",{class:"home-folder-hint",children:"Choose a folder, or create one inside it. The board keeps its content and links."},void 0,!1,void 0,this),i("fieldset",{class:"home-folder-options",disabled:l,children:[i("legend",{children:"Destination folder"},void 0,!1,void 0,this),["",...t].map((h)=>i("label",{class:"home-folder-option",style:{paddingLeft:`${8+Math.min(h.split("/").length-1,5)*14}px`},children:[i("input",{type:"radio",name:"folder-destination",value:h,checked:r===h,onChange:()=>{s(h),d("")}},void 0,!1,void 0,this),i("span",{children:h||"Home (no folder)"},void 0,!1,void 0,this)]},h,!0,void 0,this))]},void 0,!0,void 0,this),i("label",{class:"home-folder-new",children:["New folder inside ",r||"Home"," ",i("span",{class:"home-folder-hint",children:"(optional)"},void 0,!1,void 0,this),i("input",{class:"text-prompt-input","aria-label":"New folder name",placeholder:"e.g. Decisions",maxLength:60,value:a,disabled:l,onInput:(h)=>{c(h.currentTarget.value),d("")}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"home-folder-hint",children:["Move to: ",i("strong",{children:m||"Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p&&i("p",{role:"alert",children:p},void 0,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",disabled:l,onClick:n,children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"button",class:"text-prompt-confirm",disabled:l||m===(e.category??""),onClick:()=>void f(),children:l?"Moving…":"Move board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function m_({board:e,onClose:t}){let n=z(null),o=z(null),[r,s]=I(null),[a,c]=I(new Set),[l,u]=I(`${e.name} copy`),[p,d]=I(!0),[m,f]=I(!0),[h,v]=I(!1),[x,g]=I(""),[y,E]=I(!1);return Rt(n,!0,{initial:o}),B(()=>{let N=!0;return nb(e.id).then((b)=>{if(!N)return;if(!b||!Array.isArray(b.cards))return g("Could not load reusable cards. Try again.");s(b),c(new Set(b.cards.filter((T)=>T.reusable).map((T)=>T.id)))}),()=>{N=!1}},[e.id]),i("div",{class:"text-prompt-backdrop",onMouseDown:t,children:i("div",{ref:n,class:"text-prompt board-copy-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"board-copy-title",onMouseDown:(N)=>N.stopPropagation(),children:i("form",{onSubmit:async(N)=>{if(N.preventDefault(),!l.trim()||!r)return;E(!0),g("");let b=await ob({sourceBoardId:e.id,name:l.trim(),...e.category?{category:e.category}:{},nodeIds:[...a],includeReadme:p,includeStructure:m});if(E(!1),!b)return g("Could not create the board. Try a different name.");if(h)await Nt(b.id);t()},children:[i("h2",{id:"board-copy-title",children:["Create from ",e.name]},void 0,!0,void 0,this),i("label",{class:"board-copy-field",children:["Board name",i("input",{ref:o,class:"text-prompt-input",value:l,onInput:(N)=>u(N.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!r&&!x&&i("div",{class:"board-copy-status",role:"status",children:"Loading reusable cards…"},void 0,!1,void 0,this),x&&i("div",{class:"board-copy-error",role:"alert",children:x},void 0,!1,void 0,this),r&&i("fieldset",{class:"board-copy-cards",children:[i("legend",{children:"Cards to copy"},void 0,!1,void 0,this),r.cards.filter((N)=>N.reusable).length===0?i("div",{class:"board-copy-status",children:"No reusable cards on this board."},void 0,!1,void 0,this):r.cards.filter((N)=>N.reusable).map((N)=>i("label",{class:"board-copy-card",children:[i("input",{type:"checkbox",checked:a.has(N.id),onChange:(b)=>{let T=new Set(a);b.currentTarget.checked?T.add(N.id):T.delete(N.id),c(T)}},void 0,!1,void 0,this),i("span",{children:[i("strong",{children:N.title||"Untitled card"},void 0,!1,void 0,this),i("small",{children:N.type},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},N.id,!0,void 0,this))]},void 0,!0,void 0,this),i("div",{class:"board-copy-options",children:[i("label",{children:[i("input",{type:"checkbox",checked:m,onChange:(N)=>f(N.currentTarget.checked)},void 0,!1,void 0,this)," ","Preserve groups and connections"]},void 0,!0,void 0,this),i("label",{children:[i("input",{type:"checkbox",checked:p,disabled:!r?.readmeNodeId,onChange:(N)=>d(N.currentTarget.checked)},void 0,!1,void 0,this)," ","Include README"]},void 0,!0,void 0,this),i("label",{children:[i("input",{type:"checkbox",checked:h,onChange:(N)=>v(N.currentTarget.checked)},void 0,!1,void 0,this)," Open the new board after creating"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("p",{class:"board-copy-note",children:"Only selected cards and structure are copied. Asks, history, and context pins start clear."},void 0,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",onClick:t,children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"submit",disabled:!r||!l.trim()||y,children:y?"Creating…":"Create board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function rA(e){if(!e)return"never opened";let t=Math.floor((Date.now()-new Date(e).getTime())/60000);if(t<1)return"just now";if(t<60)return`${t}m ago`;let n=Math.floor(t/60);if(n<24)return`${n}h ago`;let o=Math.floor(n/24);if(o<30)return`${o}d ago`;return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function f_(e){return`${e} node${e!==1?"s":""}`}async function yp(){let e=await Dt("New board","Board name",{confirm:"Create"});if(e)await tb(e)}var h_="pmx-canvas-home-collapsed";function iA(){try{let e=localStorage.getItem(h_);if(e)return new Set(JSON.parse(e))}catch{}return new Set([u_])}function sA(e){try{localStorage.setItem(h_,JSON.stringify([...e]))}catch{}}function g_(){let e=Pt.value,[t,n]=I(null),[o,r]=I(null),[s,a]=I(null),[c,l]=I(""),[u,p]=I([]),[d,m]=I(iA),f=z(0),h=[...new Set(e.flatMap((_)=>_.category?vp(_.category):[]))].sort((_,P)=>_.localeCompare(P)),v=c.trim().toLocaleLowerCase(),x=e.filter((_)=>`${_.name} ${_.category??""}`.toLocaleLowerCase().includes(v)),g=new Set(x.flatMap((_)=>_.category?vp(_.category):[])),y=e.find((_)=>_.id===o),E=e.find((_)=>_.id===s);B(()=>{let _=c.trim();if(!_){p([]);return}let P=!1,q=window.setTimeout(()=>{Y("searchLibrary",`/api/canvas/search?q=${encodeURIComponent(_)}&scope=library&limit=30`,null).then((R)=>{if(!P)p(R?.results??[])})},150);return()=>{P=!0,window.clearTimeout(q)}},[c]);let D=async(_)=>{let P=++f.current;await Nt(_.boardId);for(let q=0;q<40;q++){if(P!==f.current||Ne.value!==_.boardId)return;if(O.value.has(_.cardId)){Ye(_.cardId);return}await new Promise((R)=>window.setTimeout(R,25))}},N=(_)=>{let P=new Set(d);if(P.has(_))P.delete(_);else P.add(_);m(P),sA(P)},b=async(_)=>{let P=await Dt("Rename board","Board name",{initial:_.name,confirm:"Rename"});if(P&&P!==_.name)await Ia(_.id,{name:P})},T=(_)=>t===_.id?i("li",{class:"home-board is-confirming","data-testid":"home-board",children:[i("div",{class:"home-board-confirm-text",children:["Delete ",i("strong",{children:_.name},void 0,!1,void 0,this)," and its ",f_(_.nodeCount)," and snapshots? This can't be undone."]},void 0,!0,void 0,this),i("div",{class:"home-board-actions",children:[i("button",{type:"button",class:"home-board-action",onClick:()=>n(null),children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action is-danger",onClick:()=>{n(null),ib(_.id)},children:"Delete board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},_.id,!0,void 0,this):i("li",{class:"home-board","data-testid":"home-board",children:[i("button",{type:"button",class:"home-board-open",onClick:()=>void Nt(_.id),children:[i("span",{class:"home-board-name",children:_.name},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[f_(_.nodeCount)," · ",rA(_.lastOpenedAt)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"home-board-actions",children:[i("button",{type:"button",class:"home-board-action","aria-haspopup":"dialog",onClick:()=>r(_.id),children:"Move"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action","aria-haspopup":"dialog",onClick:()=>a(_.id),children:"Create from…"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>void b(_),children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>n(_.id),children:"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},_.id,!0,void 0,this),w=(_,P)=>{let q=h.filter((k)=>k.slice(0,k.lastIndexOf("/"))===_&&k.includes("/")),R=x.filter((k)=>k.category===_),Z=x.filter((k)=>k.category===_||k.category?.startsWith(`${_}/`)).length,j=!!v||!d.has(_);return i("section",{class:"home-section","data-testid":"home-section","data-folder":_,"aria-label":_,children:[i("button",{type:"button",class:"home-section-head","aria-expanded":j,onClick:()=>N(_),children:[i("svg",{class:"home-section-chevron",viewBox:"0 0 20 20",width:"18",height:"18",fill:"none","aria-hidden":"true",children:i("path",{d:"m7.5 4.75 5.25 5.25-5.25 5.25"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("svg",{class:"home-section-folder",viewBox:"0 0 20 20",width:"18",height:"18",fill:"none","aria-hidden":"true",children:i("path",{d:"M2.75 5.75A1.75 1.75 0 0 1 4.5 4h3l1.75 2h6.25a1.75 1.75 0 0 1 1.75 1.75v6.5A1.75 1.75 0 0 1 15.5 16h-11a1.75 1.75 0 0 1-1.75-1.75v-8.5Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"home-section-name",children:_.split("/").at(-1)},void 0,!1,void 0,this),i("span",{class:"home-section-count",children:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&i("div",{class:"home-folder-children",style:{marginLeft:P<5?"14px":"0"},children:[q.filter((k)=>g.has(k)).map((k)=>w(k,P+1)),R.length>0&&i("ul",{class:"home-view-list","aria-label":`Boards in ${_}`,children:R.map(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},_,!0,void 0,this)};return i("div",{class:"home-view","data-testid":"home-view",children:[i("div",{class:"home-view-inner",children:[i("div",{class:"home-view-head",children:[i("h1",{class:"home-view-title",children:"Boards"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-view-new",onClick:()=>void yp(),children:"New board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{class:"text-prompt-input home-search",type:"search","aria-label":"Find boards and folders",placeholder:"Find boards and folders…",value:c,onInput:(_)=>l(_.currentTarget.value)},void 0,!1,void 0,this),e.length===0?i("div",{class:"home-view-empty",children:"No boards yet. Create one, or let an agent start writing — it opens one."},void 0,!1,void 0,this):v&&u.length>0?i("ul",{class:"home-view-list","aria-label":"Library search results",children:u.map((_)=>i("li",{class:"home-board",children:i("button",{type:"button",class:"home-board-open",onClick:()=>void D(_),children:[i("span",{class:"home-board-name",children:_.title||_.boardTitle},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[_.boardTitle," · ",_.snippet]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},`${_.boardId}:${_.cardId}`,!1,void 0,this))},void 0,!1,void 0,this):x.length===0?i("div",{class:"home-view-empty",role:"status",children:["No boards match “",c,"”."]},void 0,!0,void 0,this):i(ue,{children:[h.filter((_)=>!_.includes("/")&&g.has(_)).map((_)=>w(_,0)),x.some((_)=>!_.category)&&i("section",{"aria-label":"Unfiled boards",children:[h.length>0&&i("div",{class:"home-folder-hint",children:"Unfiled boards"},void 0,!1,void 0,this),i("ul",{class:"home-view-list",children:x.filter((_)=>!_.category).map(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),y&&i(p_,{board:y,folders:h,onClose:()=>r(null)},y.id,!1,void 0,this),E&&i(m_,{board:E,onClose:()=>a(null)},E.id,!1,void 0,this)]},void 0,!0,void 0,this)}var Gr=U(!1);function aA(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}function v_(){let[e,t]=I(!1),[n,o]=I(!1),[r,s]=I(null),[a,c]=I(null),[l,u]=I(!1),p=Gr.value,d=Ne.value;if(B(()=>{if(!p||!d)return;let f=!0;return c(null),s(null),Y("exportPreview",`/api/canvas/export/preview?board=${encodeURIComponent(d)}&includeFiles=${e}&includeDerivedText=${n}`,null).then((h)=>{if(f)s(h?.manifest??null)}),()=>{f=!1}},[p,e,n,d]),B(()=>{o(!1)},[p,d]),B(()=>{if(!p)return;let f=(h)=>{if(h.key!=="Escape")return;h.stopPropagation(),Gr.value=!1};return window.addEventListener("keydown",f,{capture:!0}),()=>window.removeEventListener("keydown",f,{capture:!0})},[p]),!p)return null;let m=async()=>{if(!r||r.boardId!==Ne.value)return;u(!0);let f=await Y("exportBoard","/api/canvas/export",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({board:r.boardId,includeFiles:e,includeDerivedText:n})});if(u(!1),f?.path&&Ne.value===r.boardId)c(f)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>Gr.value=!1,children:i("div",{class:"text-prompt export-dialog",role:"dialog","aria-label":"Export board","data-testid":"export-dialog",onPointerDown:(f)=>f.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:["Export ",r?`“${r.boardName}”`:"board"]},void 0,!0,void 0,this),!r?i("div",{class:"export-dialog-note",children:"Reading the board…"},void 0,!1,void 0,this):i(ue,{children:[i("div",{class:"export-dialog-note",children:"One HTML file anyone can open without installing anything. It will contain:"},void 0,!1,void 0,this),i("ul",{class:"export-dialog-list",children:[i("li",{children:[r.cards," card",r.cards!==1?"s":""," and ",r.connections," connection",r.connections!==1?"s":""]},void 0,!0,void 0,this),r.frames>0&&i("li",{children:[r.frames," embedded pages, charts or diagrams, with the code that draws them"]},void 0,!0,void 0,this),r.embeddedImages>0&&i("li",{children:[r.embeddedImages," local images"]},void 0,!0,void 0,this),r.placeholders.length>0&&i("li",{children:["Shown as placeholders:"," ",r.placeholders.map((f)=>`${f.title} (${f.reason})`).join(", ")]},void 0,!0,void 0,this),r.remoteImages.length>0&&i("li",{children:["Web images loaded when opened: ",r.remoteImages.join(", ")]},void 0,!0,void 0,this),r.links.length>0&&i("li",{children:["Links included in cards: ",r.links.join(", ")]},void 0,!0,void 0,this),r.frameNetworkDestinations.length>0&&i("li",{children:["Network destinations referenced by embedded pages: ",r.frameNetworkDestinations.join(", ")]},void 0,!0,void 0,this),r.embeddedCodeCanAccessNetwork&&i("li",{children:"Warning: embedded code can access the network. Scripts may contact destinations that cannot be listed in advance."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(r.attachments?.length??0)>0&&i("p",{children:"Original attachments are excluded. Their filenames remain visible."},void 0,!1,void 0,this),(r.sourceDerivedCards?.length??0)>0&&i("label",{class:"export-dialog-files",children:[i("input",{type:"checkbox",checked:n,onChange:(f)=>o(f.currentTarget.checked)},void 0,!1,void 0,this),i("span",{children:["Include imported document text (",r.sourceDerivedCards.length," cards)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r.files.length>0&&i("label",{class:"export-dialog-files",children:[i("input",{type:"checkbox",checked:e,onChange:(f)=>t(f.target.checked)},void 0,!1,void 0,this),i("span",{children:["Include the contents of ",r.files.length," local file",r.files.length!==1?"s":"",": ",r.files.map((f)=>f.path).join(", ")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a&&i("div",{class:"export-dialog-result","data-testid":"export-result",children:[i("div",{children:["Saved (",aA(a.bytes),"): ",i("code",{children:a.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"export-dialog-links",children:[i("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",children:"Open"},void 0,!1,void 0,this),i("a",{class:"is-primary",href:`${a.url}?download=1`,children:"Download"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:()=>Gr.value=!1,children:a?"Done":"Cancel"},void 0,!1,void 0,this),!a&&i("button",{type:"button",class:"text-prompt-confirm",disabled:!r||l,onClick:()=>void m(),children:l?"Exporting…":"Export"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function bp({presence:e,size:t=18}){return i("span",{class:"writer-avatar",style:{background:Sc(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:dw(e.label)},void 0,!1,void 0,this)}function y_(){let e=Qd.value;if(bt.value||e.length===0)return null;let t=e.reduce((r,s)=>r+s.opCount,0),n=e.length===1?e[0].label:`${e.length} writers`,o=Ho.value;return i("button",{type:"button",class:"external-indicator","data-testid":"external-indicator","aria-expanded":o,title:`${e.length} external writer${e.length===1?"":"s"} on this board — click for activity`,onClick:()=>{Ho.value=!o},children:[i("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((r)=>i(bp,{presence:r},r.sessionId,!1,void 0,this))},void 0,!1,void 0,this),i("span",{class:"external-indicator-label",children:n},void 0,!1,void 0,this),i("span",{class:"external-indicator-ops hud-collapsible-text",children:[t," op",t===1?"":"s"]},void 0,!0,void 0,this),i("span",{class:"external-indicator-dot","aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function cA(e){if(e==="node.add"||e==="jsonrender.add"||e==="graph.add"||e==="group.create")return{glyph:"+",tone:"ok"};if(e==="node.remove"||e==="edge.remove"||e==="canvas.clear")return{glyph:"×",tone:"danger"};if(e==="edge.add")return{glyph:"⟶",tone:"accent"};if(e.startsWith("ax."))return{glyph:"◆",tone:"purple"};return{glyph:"✎",tone:"accent"}}function lA(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function uA(){return[...Xe.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function b_(){let e=Ho.value,t=Qd.value,n=Rn(e?1e4:0);if(B(()=>{if(!e)return;let c=(l)=>{if(l.key!=="Escape")return;if(jr.value)jr.value=!1;else Ho.value=!1};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e]),!e||bt.value||t.length===0)return null;let o=Yd.value,r=uA().filter((c)=>!o||(c.source??"")===o),s=ao.value.filter((c)=>!o||c.sessionId===o),a=(c,l)=>i("button",{type:"button",class:`activity-filter${o===c?" is-active":""}`,style:c?{"--writer":Sc(c)}:void 0,"aria-pressed":o===c,onClick:()=>{Yd.value=c},children:l},void 0,!1,void 0,this);return i("div",{class:"activity-feed","data-testid":"activity-feed",role:"dialog","aria-label":"External activity",children:[i("div",{class:"activity-feed-head",children:[i("span",{class:"external-indicator-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"activity-feed-titles",children:[i("div",{class:"activity-feed-title",children:["External activity — ",t.length," writer",t.length===1?"":"s"]},void 0,!0,void 0,this),i("div",{class:"activity-feed-sub",children:[t.reduce((c,l)=>c+l.opCount,0)," writes · last"," ",Cc(lA(t),n)," · no session attached"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"activity-feed-close","aria-label":"Close activity feed",onClick:()=>{Ho.value=!1},children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"activity-filters",children:[a(null,"All"),t.map((c)=>a(c.sessionId,c.label))]},void 0,!0,void 0,this),i("div",{class:"activity-rows",children:[r.map((c)=>i("div",{class:"activity-row is-pending","data-testid":"activity-proposal",children:[i("span",{class:"activity-glyph tone-purple","aria-hidden":"true",children:"▢"},void 0,!1,void 0,this),i("div",{class:"activity-main",children:[i("div",{class:"activity-text",children:["Proposing: ",i("b",{children:c.label?.trim()||`${c.kind} intent`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"activity-meta",children:[c.reason?.trim()||"Intent signalled — a real veto window before the mutation",c.source?` · ${c.source}`:""]},void 0,!0,void 0,this),i("div",{class:"activity-actions",children:[i("button",{type:"button",class:"activity-veto",onClick:()=>{Io(c).then((l)=>{if(l)Mo(c.id)})},children:"Veto"},void 0,!1,void 0,this),i("span",{class:"activity-hint",children:"or hover ghost + Esc"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"activity-age",children:"now"},void 0,!1,void 0,this)]},c.id,!0,void 0,this)),s.length===0&&r.length===0&&i("div",{class:"activity-empty",children:"No writes yet."},void 0,!1,void 0,this),s.map((c)=>{let{glyph:l,tone:u}=cA(c.op);return i("div",{class:"activity-row","data-testid":"activity-row","data-op":c.op,children:[i("span",{class:`activity-glyph tone-${u}`,"aria-hidden":"true",children:l},void 0,!1,void 0,this),i("div",{class:"activity-main",children:[i("div",{class:"activity-text",children:c.summary},void 0,!1,void 0,this),i("div",{class:"activity-writer",style:{color:Sc(c.sessionId)},children:c.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"activity-age",children:Cc(c.at,n)},void 0,!1,void 0,this)]},c.id,!0,void 0,this)})]},void 0,!0,void 0,this),i("div",{class:"activity-feed-foot",children:[i("span",{class:"activity-feed-note",children:"All writes ghost first · Esc vetoes"},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-link",onClick:()=>{jr.value=!0},children:"Writers"},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{Ho.value=!1,uo()},children:["Start session ",i(hn,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function dA(){let e=[];if(co.value)e.push("scoped");if(jo.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function x_(){let e=jr.value,t=Rn(e?1e4:0),n=z(null);if(Rt(n,e),!e)return null;let o=yt.value.filter((a)=>a.attached),r=yt.value.filter((a)=>!a.attached),s=()=>{jr.value=!1};return i(ue,{children:[i("div",{class:"writers-scrim",onClick:s,"aria-hidden":"true"},void 0,!1,void 0,this),i("div",{ref:n,class:"writers-sheet","data-testid":"writers-sheet",role:"dialog","aria-modal":"true","aria-label":"Connected writers",children:[i("div",{class:"writers-head",children:[i("span",{class:"writers-title",children:"Connected writers"},void 0,!1,void 0,this),i("span",{class:"writers-board",children:kn.value.slice(0,12)},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-close","aria-label":"Close writers",onClick:s,children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"writers-body",children:[i("div",{class:"writers-section",children:"Agent sessions"},void 0,!1,void 0,this),o.length===0&&i("div",{class:"writers-empty",children:"None attached — start one from the top bar."},void 0,!1,void 0,this),o.map((a)=>i("div",{class:"writers-row",children:[i(bp,{presence:a,size:20},void 0,!1,void 0,this),i("span",{class:"writers-name",children:a.label},void 0,!1,void 0,this),i("span",{class:"writers-config",children:dA()},void 0,!1,void 0,this)]},a.sessionId,!0,void 0,this)),i("div",{class:"writers-section",children:"External writers · MCP"},void 0,!1,void 0,this),r.length===0&&i("div",{class:"writers-empty",children:"No external writers right now."},void 0,!1,void 0,this),r.map((a)=>i("div",{class:"writers-row",children:[i(bp,{presence:a,size:20},void 0,!1,void 0,this),i("span",{class:"writers-name is-mono",children:a.label},void 0,!1,void 0,this),i("span",{class:"writers-meta",children:[a.source!==a.label?`${a.source} · `:"","wrote"," ",Cc(a.lastSeenAt,t)," ago"]},void 0,!0,void 0,this)]},a.sessionId,!0,void 0,this))]},void 0,!0,void 0,this),i("div",{class:"writers-foot",children:[i("span",{class:"writers-note",children:"Local-first: any process on this machine can connect and write. Every write ghosts first — veto is the control, not permissions."},void 0,!1,void 0,this),i("button",{type:"button",class:"writers-done",onClick:s,children:"Done"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function w_(e,t){switch(e.type){case"markdown":return i(La,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return i(ro,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return i(bc,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return i(ro,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return i(ro,{node:e,expanded:t},void 0,!1,void 0,this);case"board":return i($c,{node:e},void 0,!1,void 0,this);case"prompt":return i(xc,{node:e},void 0,!1,void 0,this);case"response":return i(wc,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return i(vc,{node:e},void 0,!1,void 0,this);case"context":return i(_a,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return i(za,{node:e},void 0,!1,void 0,this);case"trace":return i(_c,{node:e},void 0,!1,void 0,this);case"file":return i(Aa,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return i(ka,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Ka,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return i(yc,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return i(Ui,{node:e,expanded:t},void 0,!1,void 0,this);default:return i("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function __(e){switch(e.type){case"markdown":return e.data.content||"";case"diff":return e.data.content||"";case"mermaid":return e.data.content||"";case"file":return e.data.fileContent||"";case"webpage":return e.data.content||"";case"html":return e.data.html||e.data.content||"";case"json-render":case"graph":return JSON.stringify(e.data.spec??e.data.graphConfig??{},null,2);default:return""}}function pA(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function mA(e,t){return e!==null&&typeof e==="object"&&e.source===qt&&e.type==="presentation-exit"&&e.token===t}function fA(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function k_(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function S_(){let e=We.value,t=e?O.value.get(e):void 0,[n,o]=I(!1),[r,s]=I(!1),[a,c]=I(""),l=z(null),u=z(null),p=H(()=>{s(!1),En()},[]),d=H(()=>{c(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),s(!0)},[]),m=H((k)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:qt,token:a,...k},"*")},[a]),f=H(()=>{s(!1)},[]),h=H((k)=>{if(k.key==="Escape"){k.preventDefault(),k.stopPropagation(),s(!1);return}if(k.key==="Tab"&&!k_(k.target)){k.preventDefault(),k.stopPropagation(),u.current?.focus();return}if((k.key===" "||k.key==="Enter")&&k_(k.target))return;if(!fA(k.key))return;k.preventDefault(),k.stopPropagation(),m({type:"presentation-key",key:k.key})},[m]),v=H((k)=>{if(k.target.classList.contains("expanded-overlay-backdrop"))En()},[]),x=H(()=>{if(!t)return;let k=__(t);if(!k)return;navigator.clipboard.writeText(k).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),g=H(()=>{if(!e)return;Xn(e)},[e]);B(()=>{s(!1)},[e]),jt(()=>{if(!r)return;let k=()=>{let Ue=l.current;if(!Ue||Ue.contains(document.activeElement))return;Ue.focus()},V=[0,50,150].map((Ue)=>window.setTimeout(k,Ue)),ge=(Ue)=>{if(!mA(Ue.data,a))return;s(!1)};return document.addEventListener("keydown",h,!0),window.addEventListener("message",ge),()=>{V.forEach((Ue)=>{window.clearTimeout(Ue)}),document.removeEventListener("keydown",h,!0),window.removeEventListener("message",ge)}},[h,a,r]);let y=z(null),E=H(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]);if(Rt(y,t!==void 0,{restoreTo:E}),!t)return null;let D=t.data.title||t.data.path?.split("/").pop()||dt[t.type],N=__(t),b=pA(N),T=e?Ae.value.has(e):!1,w=N.length>0,_=nn.value===e,P=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",q=Gx(t),R=sn(t.type),Z=t.data.provenance&&typeof t.data.provenance==="object"?t.data.provenance:null,j=Z?[Z.sourceKind,Z.sourceUri,Z.syncedAt?`synced ${Z.syncedAt.slice(11,16)}`:null].filter((k)=>typeof k==="string"&&k.length>0).join(" · "):null;return i("div",{class:"expanded-overlay-backdrop",onPointerDown:v,style:{pointerEvents:_?"none":"auto"},children:i("div",{ref:y,class:`expanded-overlay-panel${T?" is-pinned":""}`,role:"dialog","aria-modal":"true","aria-label":D,"data-testid":"expanded-node",children:[i("div",{class:"expanded-header",children:[i("span",{class:"expanded-kind-icon","aria-hidden":"true",children:i(R,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"expanded-title",children:D},void 0,!1,void 0,this),i("span",{class:"expanded-kind-pill",children:dt[t.type]},void 0,!1,void 0,this),i("button",{type:"button",class:`expanded-pin${T?" is-on":""}`,onClick:g,title:T?"In agent context — click to unpin":"Pin as agent context","aria-pressed":T,children:"✦"},void 0,!1,void 0,this),i("span",{class:"expanded-spacer"},void 0,!1,void 0,this),i("div",{class:"expanded-actions",children:[w&&i("button",{type:"button",class:"expanded-action-btn",onClick:x,title:"Copy content to clipboard",children:n?"Copied!":"Copy"},void 0,!1,void 0,this),Ba(t)&&i("button",{type:"button",class:"expanded-action-btn",onClick:()=>void Ha(t),title:"Open as a full-page site in the system browser",children:["Open in tab ",i(hn,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&i("button",{type:"button",class:"expanded-action-btn expanded-action-primary",onClick:d,title:"Present this HTML node fullscreen",children:"Present"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"expanded-close",onClick:p,title:"Close (Esc)","aria-label":"Close",children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:`expanded-body${P?" is-embedded":""}`,children:P?i("div",{style:{flex:1,minHeight:0,display:"flex"},children:w_(t,!0)},void 0,!1,void 0,this):w_(t,!0)},void 0,!1,void 0,this),i("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:i(Rc,{node:t},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{class:"expanded-footer",children:[i("span",{class:"expanded-footer-meta",children:[j,b>0?`${b.toLocaleString()} word${b!==1?"s":""}`:null].filter(Boolean).join(" · ")||dt[t.type].toLowerCase()},void 0,!1,void 0,this),i("span",{class:"expanded-spacer"},void 0,!1,void 0,this),i("span",{class:`expanded-footer-hint${_?" is-saving":""}`,children:_?"Saving edits…":"esc or click outside to close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&r&&i("div",{ref:l,class:"html-presentation-overlay",role:"dialog","aria-modal":"true","aria-label":`Present ${D}`,tabIndex:-1,onKeyDownCapture:h,children:[i("button",{ref:u,type:"button",class:"html-presentation-exit",onClick:f,title:"Exit presentation (Esc)","aria-label":"Exit presentation",children:"Exit presentation"},void 0,!1,void 0,this),i("div",{class:"html-presentation-stage",children:i(Ui,{node:t,expanded:!0,presentation:!0,presentationExitToken:a},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var T_=168,I_=112,Hc=20;function C_(e,t,n,o){let r=Array.from(e.values()),s=0,a=0,c=1000,l=800;if(r.length>0){s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let x of r)s=Math.min(s,x.position.x),a=Math.min(a,x.position.y),c=Math.max(c,x.position.x+x.size.width),l=Math.max(l,x.position.y+x.size.height)}let u=-t.x/t.scale,p=-t.y/t.scale,d=u+n/t.scale,m=p+o/t.scale,f={minX:Math.min(s,u)-Hc,minY:Math.min(a,p)-Hc,maxX:Math.max(c,d)+Hc,maxY:Math.max(l,m)+Hc},h=f.maxX-f.minX||1,v=f.maxY-f.minY||1;return{bounds:f,scale:Math.min(T_/h,I_/v)}}function E_({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:r}){let s=z(null),a=z(!1),c=t.value,l=e.value,u=C_(c,l,o,r),{bounds:p,scale:d}=u,m=(b)=>(b-p.minX)*d,f=(b)=>(b-p.minY)*d,h=H((b)=>{let T=s.current;if(!T)return;let w=T.getBoundingClientRect(),_=(b.clientX-w.left)/w.width*T_,P=(b.clientY-w.top)/w.height*I_,q=C_(t.value,e.value,o,r),R=e.value,Z=o/R.scale,j=r/R.scale,k=_/q.scale+q.bounds.minX,V=P/q.scale+q.bounds.minY;n(-(k-Z/2)*R.scale,-(V-j/2)*R.scale)},[t,e,o,r,n]),v=H((b)=>{b.stopPropagation(),b.preventDefault(),a.current=!0,h(b);let T=(_)=>{if(a.current)h(_)},w=()=>{a.current=!1,document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",w)};document.addEventListener("pointermove",T),document.addEventListener("pointerup",w)},[h]),x=be.value,g=co.value,y=g?Ic(g.nodeIds.map((b)=>c.get(b)).filter((b)=>b!==void 0),g.padding):null,E=yt.value.map((b)=>({id:b.sessionId,phase:b.phase,worker:b.parentAgentId!=null,external:!b.attached,at:Tc(b,(T)=>c.get(T))})).filter((b)=>b.at!==null),D=-l.x/l.scale,N=-l.y/l.scale;return i("div",{ref:s,class:"minimap","data-testid":"minimap",title:"Click to jump · drag the frame to pan",onPointerDown:v,children:[Array.from(c.values()).map((b)=>{let T=b.type==="group";return i("span",{class:`minimap-node${T?" is-group":""}${x.has(b.id)?" is-selected":""}`,"data-kind":b.type,style:{left:`${m(b.position.x)}px`,top:`${f(b.position.y)}px`,width:`${Math.max(T?6:4,b.size.width*d)}px`,height:`${Math.max(T?5:3,b.size.height*d)}px`,"--kind":Pc[b.type]}},b.id,!1,void 0,this)}),y&&i("span",{class:"minimap-fence",style:{left:`${m(y.x)}px`,top:`${f(y.y)}px`,width:`${y.width*d}px`,height:`${y.height*d}px`}},void 0,!1,void 0,this),E.map((b)=>i("span",{class:`minimap-presence phase-${b.phase}${b.worker?" is-worker":""}${b.external?" is-external":""}`,style:{left:`${m(b.at.x)-4}px`,top:`${f(b.at.y)-4}px`,"--identity-color":`hsl(${so(b.id)} 65% 62%)`}},b.id,!1,void 0,this)),i("span",{class:"minimap-frame",style:{left:`${m(D)}px`,top:`${f(N)}px`,width:`${o/l.scale*d}px`,height:`${r/l.scale*d}px`}},void 0,!1,void 0,this),i("span",{class:"minimap-zoom",children:[Math.round(l.scale*100),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Je({label:e,shortcut:t,body:n,align:o="center",side:r="down",tapToOpen:s=!1,children:a}){return i("span",{class:`toolbar-tooltip-anchor toolbar-tooltip-anchor-${o}${r==="up"?" toolbar-tooltip-anchor-up":""}${s?" toolbar-tooltip-anchor-tap":""}`,tabIndex:s?-1:void 0,children:[a,i("span",{class:"toolbar-tooltip",role:"tooltip",children:[i("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),n&&i("span",{class:"toolbar-tooltip-body",children:n},void 0,!1,void 0,this),t&&i("span",{class:"toolbar-tooltip-meta",children:i("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function A_(){let e=be.value.size,t=H(()=>{let c=Array.from(be.value);if(c.length===0)return;ua(c),_t()},[]),n=H(()=>{let c=Array.from(be.value);if(c.length===0)return;lr({title:"Group",childIds:c}),_t()},[]),o=H(()=>{let c=Array.from(be.value);for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++)Eo(c[l],c[u],"relation");_t()},[]),r=H(()=>{let c=Array.from(be.value);for(let l of c)Vn(l);_t()},[]);if(e===0)return null;let s=e>=2,a=!bt.value&&Ae.value.size>0&&!dn.value;return i("div",{class:`selection-bar${a?" is-above-pin-bar":""}`,role:"toolbar","aria-label":"Selection",children:[i("span",{class:"selection-bar-count",children:[e," node",e!==1?"s":""," selected"]},void 0,!0,void 0,this),s&&i(ue,{children:[i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Je,{label:"Align left",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align left",onClick:()=>Cu("left"),children:i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("line",{x1:"2.5",y1:"2",x2:"2.5",y2:"14"},void 0,!1,void 0,this),i("rect",{x:"5",y:"3.5",width:"8",height:"3.5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"5",y:"9",width:"5",height:"3.5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Je,{label:"Align top",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align top",onClick:()=>Cu("top"),children:i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("line",{x1:"2",y1:"2.5",x2:"14",y2:"2.5"},void 0,!1,void 0,this),i("rect",{x:"3.5",y:"5",width:"3.5",height:"8",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9",y:"5",width:"3.5",height:"5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Je,{label:"Distribute horizontally",body:"Evens the gaps. A selection that cannot fit flows into a clean row instead of overlapping.",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Distribute",disabled:e<3,onClick:()=>oy(),children:i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","aria-hidden":"true",children:[i("rect",{x:"1.5",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"6.25",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"11",y:"5",width:"3.5",height:"6",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Je,{label:"Auto-arrange selection",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Auto-arrange",onClick:()=>ry(),children:i(An,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Je,{label:"Group the selection",shortcut:"G",side:"up",children:i("button",{type:"button",class:"selection-bar-action",onClick:n,children:[i("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-dasharray":"3 2.5","aria-hidden":"true",children:i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Group"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i(Je,{label:"Connect every pair",side:"up",children:i("button",{type:"button",class:"selection-bar-action",onClick:o,children:"Connect"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Je,{label:"Pin to agent context",side:"up",children:i("button",{type:"button",class:"selection-bar-action is-pin",onClick:t,children:[i("span",{"aria-hidden":"true",children:"✦"},void 0,!1,void 0,this),"Pin as context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Je,{label:"Delete selection",side:"up",children:i("button",{type:"button",class:"selection-bar-icon is-danger","aria-label":"Delete selection",onClick:r,children:i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("path",{d:"M2.5 4 H13.5"},void 0,!1,void 0,this),i("path",{d:"M5.5 4 V2.5 H10.5 V4"},void 0,!1,void 0,this),i("path",{d:"M4 4 L4.8 13.5 H11.2 L12 4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Je,{label:"Clear selection",shortcut:"Esc",side:"up",children:i("button",{type:"button",class:"selection-bar-icon",onClick:_t,"aria-label":"Clear selection",children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jc(e,t=Date.now()){if(!e.expiresAt)return null;let n=Date.parse(e.expiresAt);if(!Number.isFinite(n))return null;return Math.max(0,n-t)}function Zc(e){let t=Math.max(0,Math.ceil(e/1000)),n=Math.floor(t/60),o=t%60;return`${n}:${String(o).padStart(2,"0")}`}var hA={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},gA={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},z_=[{id:"all",label:"All",hint:"Everything below in one feed, newest first"},{id:"update",label:"Updates",hint:"Board edits agents made — nodes, edges, pins, work items"},{id:"steer",label:"Steer",hint:"Instructions sent to agents — by you from the composer, or agent-to-agent"},{id:"assistant",label:"Assistant",hint:"Messages agents posted for you to read"},{id:"event",label:"Events",hint:"Run telemetry — tool runs, approvals, failures, policy notes"},{id:"evidence",label:"Evidence",hint:"Proof agents recorded — test results, artifacts, links"}],P_=Object.fromEntries(z_.map((e)=>[e.id,e.hint])),vA={policy:"warn",prompt:"accent","assistant-message":"muted","tool-start":"accent","tool-result":"ok",failure:"danger",approval:"warn",steering:"purple",command:"accent",note:"muted",evidence:"ok",steer:"purple",update:"purple",yield:"warn"};function xp(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function yA({item:e}){let t=hA[e.status]??"queued",n=e.nodeIds[0];return i("li",{class:`session-item status-${t}`,"data-work-item-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("button",{type:"button",class:"session-item-title",title:n?"Focus the linked node":void 0,disabled:!n,onClick:()=>n&&Ye(n),children:e.title},void 0,!1,void 0,this),e.detail&&i("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"session-item-status",children:gA[e.status]??t},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:xp(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function bA({gate:e,now:t}){let[n,o]=I(null),r=async(c)=>{o(c),await Sw(e,c),o(null)},s=e.nodeIds[0],a=jc(e,t);return i("li",{class:"session-item status-awaiting session-gate","data-gate-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("button",{type:"button",class:"session-item-title",title:s?"Focus the linked node":void 0,disabled:!s,onClick:()=>s&&Ye(s),children:e.title},void 0,!1,void 0,this),e.detail&&i("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this),a!==null&&i("div",{class:"session-gate-ttl","data-testid":"gate-countdown",children:["auto-holds in ",Zc(a)," if unanswered"]},void 0,!0,void 0,this),i("div",{class:"session-gate-actions",children:[i("button",{type:"button",class:"session-gate-approve",disabled:n!==null,onClick:()=>void r("approved"),children:n==="approved"?"Approving…":"Approve"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-gate-reject",disabled:n!==null,onClick:()=>void r("rejected"),children:n==="rejected"?"Rejecting…":"Reject"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"session-item-time",children:xp(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function xA({gate:e}){let[t,n]=I(!1);return i("li",{class:"session-item status-vetoed session-gate-held","data-gate-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("span",{class:"session-item-title",children:e.title},void 0,!1,void 0,this),i("div",{class:"session-item-detail",children:"Auto-held — no answer in time, the action did not proceed."},void 0,!1,void 0,this),i("div",{class:"session-gate-actions",children:i("button",{type:"button",class:"session-gate-reject",disabled:t,onClick:()=>{n(!0),Cw(e).finally(()=>n(!1))},children:t?"Reopening…":"Reopen"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"session-item-status",children:"held"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function wA(e){let t=e.resolvedBy;if(!t)return e.status;let n=e.status==="approved"?"Approved":"Rejected";if(t.actor==="human")return`${n} by you`;if(t.actor==="system")return`${n} by system`;let o=t.agentId||t.source||"agent";return`${e.selfAnswer?"Self-":""}${n.toLowerCase()} by ${o}`}function _A({gate:e}){return i("li",{class:`session-item status-${e.status}`,"data-gate-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("span",{class:"session-item-title",children:e.title},void 0,!1,void 0,this),i("div",{class:"session-item-detail",children:wA(e)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function kA(){let e=co.value,t=be.value.size,[n,o]=I(!1),r=(s)=>{o(!0),yw(s).finally(()=>o(!1))};return i("div",{class:`session-scope${e?" is-fenced":""}`,"data-testid":"session-scope",children:[i("span",{class:"session-scope-dot","aria-hidden":"true"},void 0,!1,void 0,this),e?i(ue,{children:[i("span",{class:"session-scope-text",children:["Scoped to ",i("strong",{children:e.nodeIds.length},void 0,!1,void 0,this)," node",e.nodeIds.length===1?"":"s"," · writes outside are blocked"]},void 0,!0,void 0,this),i("button",{type:"button",class:"session-scope-action",disabled:n,onClick:()=>r(null),children:"Clear"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i(ue,{children:[i("span",{class:"session-scope-text",children:"Unscoped — the agent may write anywhere"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-scope-action",disabled:n||t===0,title:t===0?"Select nodes on the canvas first":"Fence the agent to the selected nodes",onClick:()=>r([...be.value]),children:["Fence to selection",t>0?` (${t})`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function SA(e){if(e==="browser")return"you";return yt.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function CA({entry:e}){let t=Wi.value.has(e.id);return i("li",{class:`session-timeline-row tone-${vA[e.kind]??"muted"}`,children:[i("span",{class:"session-timeline-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-timeline-main",children:[i("div",{class:"session-timeline-head",children:[i("span",{class:"session-timeline-label",title:P_[rp(e.kind)],children:e.label},void 0,!1,void 0,this),e.who&&i("span",{class:"session-timeline-who",style:{"--identity-color":`hsl(${so(e.who)} 65% 62%)`},children:SA(e.who)},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:xp(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-timeline-body",children:e.body},void 0,!1,void 0,this),e.undoable&&!t&&i("button",{type:"button",class:"session-timeline-undo","data-testid":"timeline-undo",onClick:()=>void ip(e),children:[i(Pu,{size:14},void 0,!1,void 0,this)," undo this edit"]},void 0,!0,void 0,this),t&&i("div",{class:"session-timeline-undone",children:"undone · steering sent"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function N_(){let[e,t]=I(!1),n=Zr.value,o=vw.value,r=jo.value,s=bw.value,a=xw.value,c=kw.value,[l,u]=I(!1),[p,d]=I(null),m=Rn();if(B(()=>{lo()},[]),!(e||r.length>0))return i("aside",{class:"session-panel is-collapsed","aria-label":"Session (collapsed)",children:[i("button",{type:"button",class:"session-collapse",onClick:()=>t(!0),title:"Expand session panel",children:"‹"},void 0,!1,void 0,this),n&&i("span",{class:`session-collapsed-live phase-${n.phase}`,title:io(n),"aria-label":`Session live: ${io(n)}`,children:[i("span",{class:"session-live-dot","aria-hidden":"true"},void 0,!1,void 0,this),"live"]},void 0,!0,void 0,this),i("span",{class:"session-collapsed-label",children:"Session"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("aside",{class:"session-panel","aria-label":"Session",children:[i("header",{class:"session-panel-header",children:[i("span",{class:"session-panel-title",children:"Session"},void 0,!1,void 0,this),n&&i("span",{class:`session-live phase-${n.phase}`,title:io(n),children:[i("span",{class:"session-live-dot","aria-hidden":"true"},void 0,!1,void 0,this),"live"]},void 0,!0,void 0,this),i("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),n&&i("button",{type:"button",class:"session-end",title:"End this session — a receipt and a snapshot of the board follow",onClick:()=>void Ec(n),children:"End"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-collapse",onClick:()=>t(!1),title:"Collapse session panel","aria-label":"Collapse session panel",children:i(br,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(kA,{},void 0,!1,void 0,this),(()=>{let h=c.find((v)=>v.undoable&&!Wi.value.has(v.id));if(!h)return null;return i("div",{class:"session-undo-row","data-testid":"session-undo-row",children:[i("span",{class:"session-undo-text",title:h.body,children:["Agent edit on top: ",h.body]},void 0,!0,void 0,this),i("button",{type:"button",class:"session-undo-btn",onClick:()=>void ip(h),children:[i(Pu,{size:14},void 0,!1,void 0,this)," Undo"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)})(),i("div",{class:"session-panel-body",children:[i("section",{class:"session-section",children:(()=>{let h=o.filter((N)=>N.status==="in-progress"||N.status==="todo").length,v=o.filter((N)=>N.status!=="cancelled"),x=v.filter((N)=>N.status==="done").length,g=o.length-v.length,y=r.length>0,E=l||y,D=h>0?`${h} running`:v.length>0?`${x}/${v.length} done${g>0?` · ${g} cancelled`:""}`:o.length>0?`${o.length} cancelled`:"none yet";return i(ue,{children:[i("button",{type:"button",class:"session-section-toggle","aria-expanded":E,"data-testid":"work-items-toggle",onClick:()=>u((N)=>!N),children:[i("span",{class:"session-section-title",children:"Work items"},void 0,!1,void 0,this),i("span",{class:"session-work-summary",children:[h>0&&i("span",{class:"session-work-dot","aria-hidden":"true"},void 0,!1,void 0,this),D]},void 0,!0,void 0,this),i("span",{class:`session-section-chevron${E?" is-open":""}`,"aria-hidden":"true",children:i(br,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E&&(r.length===0&&s.length===0&&a.length===0&&o.length===0?i("div",{class:"session-empty",children:"No work items yet — the agent's tasks and gates appear here."},void 0,!1,void 0,this):i("ul",{class:"session-list","aria-live":"polite","aria-label":"Work items and gates",children:[r.map((N)=>i(bA,{gate:N,now:m},N.id,!1,void 0,this)),s.map((N)=>i(xA,{gate:N},N.id,!1,void 0,this)),a.map((N)=>i(_A,{gate:N},N.id,!1,void 0,this)),o.map((N)=>i(yA,{item:N},N.id,!1,void 0,this))]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)})()},void 0,!1,void 0,this),i("section",{class:"session-section",children:[i("h3",{class:"session-section-title",children:"Timeline"},void 0,!1,void 0,this),i("div",{class:"session-timeline-filters",role:"group","aria-label":"Filter timeline",children:z_.map((h)=>i("button",{type:"button",class:`activity-filter${Zo.value===h.id?" is-active":""}`,"aria-pressed":Zo.value===h.id,title:h.hint,onMouseEnter:()=>d(h.id),onMouseLeave:()=>d((v)=>v===h.id?null:v),onFocus:()=>d(h.id),onBlur:()=>d((v)=>v===h.id?null:v),onClick:()=>{Zo.value=h.id},children:h.label},h.id,!1,void 0,this))},void 0,!1,void 0,this),i("div",{class:"session-timeline-hint","data-testid":"timeline-filter-hint",children:P_[p??Zo.value]},void 0,!1,void 0,this),c.length===0?i("div",{class:"session-empty",children:Zo.value==="all"?"Nothing recorded yet.":"Nothing of this kind yet."},void 0,!1,void 0,this):i("ul",{class:"session-list session-timeline","aria-live":"polite","aria-label":"Timeline",children:c.map((h)=>i(CA,{entry:h},h.id,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function wp(e){if(!e||typeof e!=="object")return null;let t=e,n=(o)=>Array.isArray(o)?o.length:0;return{added:n(t.addedNodes)+n(t.addedEdges),removed:n(t.removedNodes)+n(t.removedEdges),modified:n(t.modifiedNodes)}}function R_({onOpenSnapshots:e}){let t=Ac.value,[n,o]=I(null),[r,s]=I(!1);if(!t)return null;let a=async()=>{if(!t.snapshot)return;s(!0);try{let u=await fetch(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(u.ok){let p=await u.json();o(wp(p.diff)??{added:0,removed:0,modified:0})}}finally{s(!1)}},c=new Date(t.endedAt),l=Number.isNaN(c.getTime())?"":`${String(c.getHours()).padStart(2,"0")}:${String(c.getMinutes()).padStart(2,"0")}`;return i("div",{class:"session-receipt","data-testid":"session-receipt",role:"status",children:[i("div",{class:"session-receipt-head",children:[i("span",{class:"session-receipt-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"session-receipt-title",children:[t.endedBy==="human"?"Session ended by you":t.endedBy==="idle-timeout"?"Session ended — idle timeout":t.endedBy==="agent"?"Session ended by the agent":"Session ended",l?` · ${l}`:""]},void 0,!0,void 0,this),i("button",{type:"button",class:"session-receipt-close",onClick:zc,"aria-label":"Dismiss receipt",children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-tiles",children:[i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Items"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value",children:t.counts.items},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Done"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-ok",children:t.counts.done},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.cancelled>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Cancelled"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-muted",children:t.counts.cancelled},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.rejected>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Rejected"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-danger",children:t.counts.rejected},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.held>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Held"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-warn",children:t.counts.held},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-note",children:t.snapshot?"A snapshot of the board from before this session is saved — restore it to undo the session.":t.unchanged?"This session changed nothing on the board — no snapshot kept.":"The board was empty when the session started — nothing to restore."},void 0,!1,void 0,this),n&&i("div",{class:"session-receipt-diff","data-testid":"session-receipt-diff",children:["This session: ",n.added," added · ",n.removed," removed · ",n.modified," modified"]},void 0,!0,void 0,this),i("div",{class:"session-receipt-actions",children:[t.snapshot&&i("button",{type:"button",class:"session-receipt-primary",disabled:r,onClick:()=>void a(),children:r?"Comparing…":"View diff"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-receipt-secondary",title:"Open the History drawer — saved boards and past sessions",onClick:e,children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var TA=[{title:"Tools",shortcuts:[{keys:"V",desc:"Select tool — drag empty space to lasso"},{keys:"Space (hold)",desc:"Pan — drag anywhere moves the board"},{keys:"A",desc:"Annotate — draw on the canvas"}]},{title:"Navigation",shortcuts:[{keys:Ve("K"),desc:"Command palette — search nodes & actions"},{keys:"Tab / Shift+Tab",desc:"Cycle through nodes"},{keys:"← ↑ → ↓",desc:"Walk graph along edges (when node focused)"},{keys:"F",desc:"Fit all nodes on screen"},{keys:Ve("0"),desc:"Reset viewport to origin"},{keys:`${Ve("+")} / ${Ve("−")}`,desc:"Zoom in / out"}]},{title:"Creation",shortcuts:[{keys:"M",desc:"New markdown note"},{keys:"I / W / H",desc:"New image / webpage / HTML surface"},{keys:"Shift+F",desc:"New file node (workspace path)"},{keys:"G / Shift+G",desc:"Group the selection (new frame when empty) / ungroup"},{keys:"Double-click",desc:"Open actions on a node or create menu on canvas"},{keys:"Drag port → node",desc:"Connect two nodes (hover to reveal ports)"}]},{title:"Selection",shortcuts:[{keys:"Click",desc:"Focus node (highlights neighbors & edges)"},{keys:"Shift+Click",desc:"Toggle node in multi-selection"},{keys:"Drag empty space",desc:"Lasso select multiple nodes"},{keys:Si?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:Si?"⌘Z / ⇧⌘Z":"Ctrl+Z / Ctrl+Y",desc:"Undo / redo — agent edits included"},{keys:"Esc",desc:"Clear selection / close overlay"}]},{title:"View",shortcuts:[{keys:"?",desc:"Toggle this shortcut overlay"},{keys:"Minimap",desc:"Click/drag to navigate (toggle in the rail)"},{keys:"Right-drag",desc:"Pan the board from anywhere"}]}];function $_({onClose:e}){return i("div",{class:"shortcut-overlay-backdrop",onMouseDown:e,children:i("div",{class:"shortcut-overlay",onMouseDown:(t)=>t.stopPropagation(),children:[i("div",{class:"shortcut-overlay-header",children:[i("span",{class:"shortcut-overlay-title",children:"Keyboard Shortcuts"},void 0,!1,void 0,this),i("span",{class:"shortcut-overlay-hint",children:["Press ",i("kbd",{children:"?"},void 0,!1,void 0,this)," or ",i("kbd",{children:"Esc"},void 0,!1,void 0,this)," to close"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"shortcut-overlay-body",children:TA.map((t)=>i("div",{class:"shortcut-group",children:[i("div",{class:"shortcut-group-title",children:t.title},void 0,!1,void 0,this),t.shortcuts.map((n)=>i("div",{class:"shortcut-row",children:[i("kbd",{class:"shortcut-keys",children:n.keys},void 0,!1,void 0,this),i("span",{class:"shortcut-desc",children:n.desc},void 0,!1,void 0,this)]},n.keys,!0,void 0,this))]},t.title,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var M_="Before session · ";function L_(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function IA(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/60000);if(n<1)return"just now";if(n<60)return`${n}m ago`;let o=Math.floor(n/60);if(o<24)return`${o}h ago`;return`${Math.floor(o/24)}d ago`}function Uc(e){if(!e.startsWith(M_))return null;let t=e.slice(M_.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function O_({open:e,onClose:t,anchorRef:n}){let[o,r]=I([]),[s,a]=I(!1),[c,l]=I(!1),[u,p]=I(null),[d,m]=I(""),[f,h]=I(null),[v,x]=I({}),g=z(null),y=z(null);B(()=>{if(!e)return;a(!0),Bv().then((w)=>{r(w),a(!1)})},[e]),B(()=>{if(e)setTimeout(()=>y.current?.focus(),50)},[e]),B(()=>{if(!e)return;let w=(_)=>{let P=g.current,q=n.current;if(P&&!P.contains(_.target)&&q&&!q.contains(_.target))t()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,t]),B(()=>{if(!e)return;let w=(_)=>{if(_.key==="Escape")t()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[e,t]);let E=H(async()=>{let w=d.trim();if(!w)return;l(!0);let _=await Hv(w);if(l(!1),_.ok&&_.snapshot)r((P)=>[_.snapshot,...P]),m("")},[d]),D=H(async(w)=>{h(null),p(w);let _=await jv(w);if(p(null),_.ok)t()},[t]),N=H(async(w)=>{if((await Zv(w)).ok)r((P)=>P.filter((q)=>q.id!==w));h(null)},[]),b=H(async(w)=>{x((P)=>({...P,[w]:"loading"}));let _=await Y("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(w)}/diff`,{});x((P)=>({...P,[w]:wp(_.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let T=(w,_)=>f?.id===w.id?i(ue,{children:[i("button",{type:"button",class:`snapshot-action-btn ${f.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>f.action==="delete"?N(w.id):D(w.id),title:f.action==="delete"?"Confirm delete":"Confirm restore",disabled:u!==null,children:f.action==="delete"?"Delete":u===w.id?"Restoring…":"Confirm"},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn",onClick:()=>h(null),title:"Cancel",disabled:u!==null,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i(ue,{children:[i("button",{type:"button",class:"snapshot-action-btn snapshot-action-restore",onClick:()=>h({id:w.id,action:"restore"}),title:"Restore this snapshot — replaces the current canvas (undoable)",disabled:u!==null,children:u===w.id?"Restoring…":_},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn snapshot-action-delete",onClick:()=>h({id:w.id,action:"delete"}),title:"Delete this snapshot","aria-label":"Delete snapshot",disabled:u!==null,children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{ref:g,class:"snapshot-panel","data-testid":"history-drawer",role:"dialog","aria-label":"History",children:[i("div",{class:"snapshot-panel-header",children:[i("span",{class:"snapshot-panel-title",children:"History"},void 0,!1,void 0,this),i("span",{class:"snapshot-panel-sub",children:"snapshots + sessions"},void 0,!1,void 0,this),i("span",{class:"snapshot-panel-spacer"},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-panel-close",onClick:t,title:"Close","aria-label":"Close history",children:i(Pe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-save-form",children:[i("input",{ref:y,type:"text",class:"snapshot-name-input",value:d,onInput:(w)=>m(w.target.value),onKeyDown:(w)=>{if(w.key==="Enter")E()},placeholder:"Save a snapshot as…","aria-label":"Snapshot name",maxLength:80,disabled:c},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-save-btn",onClick:E,disabled:!d.trim()||c,children:c?"…":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-restore-note",children:"Restoring replaces the current canvas. You can undo it if needed."},void 0,!1,void 0,this),i("div",{class:"snapshot-list",children:[s&&i("div",{class:"snapshot-empty",children:"Loading…"},void 0,!1,void 0,this),!s&&o.length===0&&i("div",{class:"snapshot-empty",children:"No history yet. Save a snapshot, or start an agent session — it snapshots for you."},void 0,!1,void 0,this),!s&&[...o.filter((w)=>Uc(w.name)===null),...o.some((w)=>Uc(w.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((w)=>Uc(w.name)!==null)].map((w)=>{if(w.id==="__sessions-header__")return i("div",{class:"snapshot-section-header","data-testid":"history-sessions-header",children:"Sessions"},w.id,!1,void 0,this);let _=Uc(w.name),P=v[w.id];if(_!==null)return i("div",{class:"snapshot-item is-session","data-testid":"history-session",children:[i("div",{class:"snapshot-item-head",children:[i("span",{class:"snapshot-session-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"snapshot-item-name",children:["Agent session — ",_]},void 0,!0,void 0,this),i("span",{class:"snapshot-item-time",children:L_(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:["snapshot at session start · ",w.nodeCount," node",w.nodeCount!==1?"s":"",P&&P!=="loading"&&i("span",{class:"snapshot-item-diff",children:[" ","· since: ",P.added," added · ",P.removed," removed · ",P.modified," modified"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-actions is-session",children:[i("button",{type:"button",class:"snapshot-action-btn snapshot-action-diff",disabled:P==="loading",onClick:()=>void b(w.id),children:P==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),T(w,"Restore pre-state")]},void 0,!0,void 0,this)]},w.id,!0,void 0,this);return i("div",{class:"snapshot-item","data-testid":"history-snapshot",children:[i("div",{class:"snapshot-item-head",children:[i("span",{class:"snapshot-item-glyph","aria-hidden":"true",children:"◫"},void 0,!1,void 0,this),i("span",{class:"snapshot-item-name",children:w.name},void 0,!1,void 0,this),i("span",{class:"snapshot-item-time",children:L_(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:[w.nodeCount," node",w.nodeCount!==1?"s":"",w.edgeCount>0?` · ${w.edgeCount} edge${w.edgeCount!==1?"s":""}`:""," · ",IA(w.createdAt)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-actions",children:T(w,"Restore")},void 0,!1,void 0,this)]},w.id,!0,void 0,this)})]},void 0,!0,void 0,this),i("div",{class:"snapshot-panel-foot",children:"Every agent session start writes a snapshot automatically."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var EA=8;function AA({children:e}){let t=Se(()=>document.createElement("div"),[]);return jt(()=>(document.body.appendChild(t),()=>{Yr(null,t),t.remove()}),[t]),jt(()=>Yr(e,t),[e,t]),null}function D_({fallbackName:e}){let[t,n]=I(!1),o=z(null),r=z(null),s=z(null);jt(()=>{if(!t)return;let d=(f)=>{if(f.target instanceof Node&&!o.current?.contains(f.target)&&!s.current?.contains(f.target))n(!1)},m=(f)=>{if(f.key==="Escape")f.stopPropagation(),n(!1),r.current?.focus()};return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",m,!0),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",m,!0)}},[t]);let a=Ea(),c=!_r.value?e:a?a.name:"Home",l=Pt.value.filter((d)=>d.id!==Ne.value).slice(0,EA),u=r.current?.getBoundingClientRect(),p=(d)=>{n(!1),Nt(d)};return i("span",{class:"board-switcher",ref:o,children:[i("button",{ref:r,type:"button",class:"top-bar-title board-switcher-button","aria-haspopup":"menu","aria-expanded":t,"aria-label":`Board: ${c}. Switch board`,onClick:()=>n((d)=>!d),children:[i("span",{class:"board-switcher-name",children:c},void 0,!1,void 0,this),i("span",{class:"board-switcher-caret","aria-hidden":"true",children:i(xr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&u&&i(AA,{children:i("div",{ref:s,class:"toolbar-menu board-switcher-menu",role:"menu","aria-label":"Boards",style:{position:"fixed",left:`min(${u.left}px, max(12px, calc(100vw - 352px)))`,top:`${u.bottom+8}px`,right:"auto",maxHeight:`min(70vh, calc(100dvh - ${u.bottom+20}px))`},children:[l.length>0&&i("div",{class:"board-switcher-heading",children:"Recent boards"},void 0,!1,void 0,this),i("div",{class:"board-switcher-recents",children:l.map((d)=>i("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>p(d.id),children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:i(wa,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"board-switcher-item-copy",children:[i("span",{class:"board-switcher-item-name",children:d.name},void 0,!1,void 0,this),i("span",{class:"board-switcher-item-folder",children:d.category?.split("/").join(" / ")||"Unfiled"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"board-switcher-item-meta",children:[d.nodeCount," ",d.nodeCount===1?"node":"nodes"]},void 0,!0,void 0,this)]},d.id,!0,void 0,this))},void 0,!1,void 0,this),i("div",{class:"board-switcher-actions",children:[i("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>{n(!1),yp()},children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:i(wy,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),"New board…"]},void 0,!0,void 0,this),i("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>p(null),children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:i(An,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),"All boards (Home)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var F_=3,B_={"waiting-approval":0,thinking:1,tooling:2,idle:3};function zA(){let e=mw.value;if(e.length===0)return null;let t=e.filter((c)=>!c.parentAgentId||!e.some((l)=>l.sessionId!==c.sessionId&&(l.sessionId===c.parentAgentId||l.source===c.parentAgentId))),n=[...t].sort((c,l)=>(B_[c.phase]??4)-(B_[l.phase]??4)),o=n.slice(0,F_),r=n.slice(F_),s=t.reduce((c,l)=>(c[l.phase]=(c[l.phase]??0)+1,c),{}),a=[s["waiting-approval"]&&`${s["waiting-approval"]} waiting on approval`,s.thinking&&`${s.thinking} thinking`,s.tooling&&`${s.tooling} running tools`,s.idle&&`${s.idle} idle`].filter(Boolean).join(", ");return i(ue,{children:[i("span",{class:"agent-chips",children:o.map((c)=>{let l=yt.value.filter((u)=>u.parentAgentId!=null&&(u.parentAgentId===c.sessionId||u.parentAgentId===c.source)).length;return i(Je,{label:`Agent session — ${c.label}`,tapToOpen:!0,body:"What this attached agent is doing right now: idle, thinking, running a tool, or waiting on your approval. Steer it from the composer below.",children:i("span",{class:`agent-chip phase-${c.phase}`,"data-phase":c.phase,style:{"--identity-color":`hsl(${so(c.sessionId)} 65% 62%)`},children:[i("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"agent-chip-label",children:io(c)},void 0,!1,void 0,this),i("span",{class:"agent-chip-who hud-collapsible-text",children:c.label},void 0,!1,void 0,this),l>0&&i("span",{class:"agent-chip-workers",children:["+",l," worker",l===1?"":"s"]},void 0,!0,void 0,this),i("button",{type:"button",class:"agent-chip-end","aria-label":`End ${c.label} session`,title:`End ${c.label}'s session`,onClick:(u)=>{u.stopPropagation(),Ec({source:c.source,agentId:c.agentId})},children:i(Pe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},c.sessionId,!1,void 0,this)})},void 0,!1,void 0,this),r.length>0&&i(Je,{label:`${t.length} agent sessions attached`,tapToOpen:!0,body:`${t.length} agents on this board — ${a}. The most active wear their own chips; the rest are here, and idle agents' cursors leave the board until they work again.`,children:i("span",{class:"agent-chip agent-chip-more","data-testid":"agent-chip-more",children:["+",r.length," · ",t.length," agents"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function PA(){let e=jo.value.length,t=Zr.value!==null&&e>0,n=Rn(t?1000:0);if(!t)return null;let o=jo.value.map((r)=>jc(r,n)).filter((r)=>r!==null).sort((r,s)=>r-s)[0];return i(Je,{label:"Approval gates waiting on you",tapToOpen:!0,body:"The agent is blocked until you approve or reject in the session panel; unanswered gates auto-hold when the countdown runs out.",children:i("span",{class:"gate-badge",children:[e," gate",e===1?"":"s",o!==void 0&&` · ${Zc(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function NA(e){if(e>0.9)return"danger";if(e>=0.7)return"warn";return"ok"}function Xi(e){return e>=1000?`${(e/1000).toFixed(e>=1e4?0:1)}k`:String(e)}function RA(){let e=Zr.value;if(!e)return null;let t=Kd.value,n=e.contextUsage,o=n?n.used:t.used,r=n?n.total:t.total,s=r>0?Math.min(1,o/r):0,a=Math.round(s*100),c=n?{label:`Context window — reported by ${e.label}`,body:`${Xi(n.used)} of ${Xi(n.total)} tokens of the agent's actual context window are used. Your ✦-pinned nodes account for ≈ ${Xi(t.used)} tokens of it.`}:{label:"Pins — pinned-context size (estimate)",body:`The nodes you pinned (✦) are what the agent is asked to carry as context: ≈ ${Xi(t.used)} of a ${Xi(t.total)}-token budget. When the agent's host reports its real context window, this meter switches to showing that instead.`};return i(Je,{label:c.label,body:c.body,tapToOpen:!0,children:i("span",{class:`context-budget tone-${NA(s)}`,"data-mode":n?"window":"pins",children:[i("span",{class:"context-budget-caption hud-collapsible-text",children:n?"Context":"Pins"},void 0,!1,void 0,this),i("span",{class:"context-budget-track","aria-hidden":"true",children:i("span",{class:"context-budget-fill",style:{width:`${a}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"context-budget-label","data-testid":"budget-label",children:[o>0&&a===0?"<1":a,"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function $A(){let[e,t]=I(!1);if(Zr.value)return null;return i(Je,{label:"Start an agent session",body:"Attaches a session to this board: the next agent that writes here is adopted into it, and you get the panel, composer, and receipt.",children:i("button",{type:"button",class:"start-session-btn",disabled:e,onClick:()=>{t(!0),uo().finally(()=>t(!1))},children:[i("span",{class:"start-session-dot","aria-hidden":"true"},void 0,!1,void 0,this),"Start agent session",i("span",{class:"beta-tag",children:"beta"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function H_(){let e=Ot.value,t=Et.value,n=K.value,o=O.value.size,r=Fe.value.size,s=mr.value,a=Array.from(O.value.values()).filter((f)=>f.type==="trace").length,[c,l]=I("");B(()=>{let f=!1;return fetch("/health").then((h)=>h.ok?h.json():null).then((h)=>{if(f||typeof h?.workspace!=="string"||!h.workspace)return;let v=h.workspace.replace(/[\\/]+$/,"").split(/[\\/]/).pop();if(v)l(v)}).catch(()=>{}),()=>{f=!0}},[]);let u=dp.value,p=u??(e==="connected"&&!t?"syncing":e),d=t?[`${o} node${o!==1?"s":""}`,...r>0?[`${r} edge${r!==1?"s":""}`]:[],...a>0?[`${a} trace${a!==1?"s":""}`]:s?["trace armed"]:[]].join(" · "):"Syncing canvas…",m=()=>{let f=it();vr(f.width,f.height)};return i("div",{class:"top-bar",children:[i(Je,{label:`Canvas status: ${p}`,tapToOpen:!0,body:"Live updates stream in over SSE; amber means reconnecting.",align:"start",children:i("span",{class:`connection-dot ${u??e}`,"aria-label":`Canvas status: ${p}`},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(D_,{fallbackName:c||"PMX Canvas"},void 0,!1,void 0,this),i("span",{class:"top-bar-meta hud-collapsible-text",children:kn.value?kn.value.slice(0,12):"…"},void 0,!1,void 0,this),i("span",{class:"top-bar-meta hud-collapsible-text",children:d},void 0,!1,void 0,this),i("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),i(zA,{},void 0,!1,void 0,this),i(PA,{},void 0,!1,void 0,this),i(RA,{},void 0,!1,void 0,this),i(y_,{},void 0,!1,void 0,this),i($A,{},void 0,!1,void 0,this),i("div",{class:"top-bar-sep"},void 0,!1,void 0,this),Ne.value&&i(Je,{label:"Export board",body:"One HTML file of this board that anyone can open, no install needed.",children:i("button",{type:"button",class:"present-button",onClick:()=>{Gr.value=!0},children:"Export"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Ne.value&&i(Je,{label:"Present board",body:"Arrow keys or Space step through stops; Esc exits. Without a saved tour, groups are read top-to-bottom, left-to-right.",children:i("button",{type:"button",class:"present-button",onClick:()=>{rn.value=!0},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Je,{label:"Zoom out",shortcut:Ve("−"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>gr(0.8),"aria-label":"Zoom out",children:i(Ay,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Je,{label:"Reset zoom",shortcut:Ve("0"),children:i("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>Kn({x:0,y:0,scale:1},250),"aria-label":"Reset view",children:[Math.round(n.scale*100),"%"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i(Je,{label:"Zoom in",shortcut:Ve("+"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>gr(1.25),"aria-label":"Zoom in",children:i(Ey,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Je,{label:"Fit all",shortcut:"F",align:"end",children:i("button",{type:"button",class:"top-bar-btn",onClick:m,"aria-label":"Fit canvas",children:i(ya,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var po={status:{x:40,y:80,w:300,h:120},markdown:{x:380,y:80,w:720,h:600},context:{x:1130,y:80,w:320,h:400},"mcp-app":{x:380,y:720,w:960,h:600},webpage:{x:380,y:80,w:520,h:420},"json-render":{x:380,y:720,w:840,h:620},graph:{x:380,y:720,w:760,h:520},board:{x:380,y:80,w:360,h:160},ledger:{x:1130,y:520,w:320,h:280},trace:{x:40,y:900,w:200,h:56},file:{x:380,y:80,w:720,h:600},diff:{x:380,y:80,w:640,h:420},mermaid:{x:380,y:80,w:640,h:460},image:{x:380,y:80,w:720,h:520},html:{x:380,y:80,w:720,h:640},group:{x:220,y:60,w:840,h:560},prompt:{x:380,y:1260,w:520,h:400},response:{x:380,y:1480,w:720,h:400}};function Ji(e,t,n,o={}){let r=po[t];return{id:e,type:t,position:o.position??{x:r.x,y:r.y},size:o.size??{width:r.w,height:r.h},zIndex:t==="status"?0:1,collapsed:!1,pinned:!1,data:n}}var Vo=null,Qi=null,qc=0,mo=null,MA=3000,LA=2000,j_=5000,Ki=!1,$n=null,Xr=null,ho=0,fo=null;function OA(){if(typeof location>"u"||typeof window>"u")return null;let e=new URLSearchParams(location.search).get("transport");if(e==="poll"||e==="sse")return e;if(window.__PMX_AMP_ORB===!0)return"poll";return null}var Jr=new Map;function es(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t).toString(36)}function Vc(e){if(!Qi)return e;let t=Qi.get(e.id);if(!t)return e;return{...e,position:t.position??e.position,size:t.size??e.size,collapsed:t.collapsed??e.collapsed,pinned:t.pinned??e.pinned}}function ts(e,t,n){return Vc(Ji(e,t,n))}function DA(){return Ja([...O.value.values()],po.markdown.w,po.markdown.h)}function Kr(){if(!O.value.has("status-main"))Cn(ts("status-main","status",{phase:"idle",message:"",elapsed:0}))}function FA(e,t){let n=`md-${es(e)}`;if(O.value.get(n))ie(n,{path:e,title:t}),Te.value=n;else{let r=DA(),s=ts(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=r,Cn(s),Ye(n)}}function BA(e){if(O.value.get("context-main"))ie("context-main",{cards:e});else if(e.length>0){let o=ts("context-main","context",{cards:e});Cn(o)}}function HA(e){let t=e.url,n=`mcp-${es(t)}`;if(O.value.get(n))ie(n,e);else Cn(ts(n,"mcp-app",e)),Ye(n)}function jA(e){let t=e.toolCallId,o=(typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null)??(t.startsWith("ext-app-")?t:`ext-app-${t}`);if(O.value.get(o)){ie(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[x,g]of O.value.entries())if(g.type==="mcp-app"&&g.data.mode==="ext-app"&&g.data.serverName===s&&g.data.toolName===a&&!g.data.toolResult){ie(x,{...e});return}}let{_x:c,_y:l,_width:u,_height:p}=e,d=po["mcp-app"],m=u??d.w,f=p??d.h,h=c===void 0||l===void 0?Ja([...O.value.values()],m,f):null,v=Vc(Ji(o,"mcp-app",{mode:"ext-app",...e},{position:{x:c??h?.x??d.x,y:l??h?.y??d.y},size:{width:m,height:f}}));Cn(v),Ye(o,{recordHistory:!1})}function ZA(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(O.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&O.value.has(n))return n;for(let[o,r]of O.value.entries())if(r.type==="mcp-app"&&r.data.mode==="ext-app"&&r.data.toolCallId===e)return o;return null}function V_(e){let t=typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null;if(t&&O.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return ZA(e.toolCallId)}function G_(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,r]of O.value.entries())if(r.type==="mcp-app"&&r.data.mode==="ext-app"&&r.data.serverName===e&&r.data.toolName===t&&!r.data.toolResult){if(n)return null;n=o}return n}function X_(e){if(O.value.get("ledger-main"))ie("ledger-main",e);else{let o=ts("ledger-main","ledger",e);o.collapsed=!0,Cn(o)}}function Cp(e){if(!Pi(e))return;if(document.documentElement.setAttribute("data-theme",e),Fr(),nt.value!==e)nt.value=e}function UA(e){return e==="markdown"||e==="mcp-app"||e==="webpage"||e==="json-render"||e==="graph"||e==="board"||e==="prompt"||e==="response"||e==="status"||e==="context"||e==="ledger"||e==="trace"||e==="file"||e==="diff"||e==="mermaid"||e==="image"||e==="html"||e==="group"}function qA(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function Tp(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.x!=="number"||typeof t.y!=="number")return null;return{x:t.x,y:t.y}}function J_(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.width!=="number"||typeof t.height!=="number")return null;return{width:t.width,height:t.height}}function WA(e){let t=Tp(e),n=J_(e);return t&&n?{...t,...n}:null}function VA(e){if(typeof e.id!=="string"||!e.id)return null;if(!UA(e.type))return null;let t=Tp(e.position),n=J_(e.size);if(!t||!n)return null;let o=e.data&&typeof e.data==="object"?Object.fromEntries(Object.entries(e.data)):{};return{id:e.id,type:e.type,position:t,size:n,zIndex:typeof e.zIndex==="number"?e.zIndex:1,collapsed:e.collapsed===!0,pinned:e.pinned===!0,data:o}}function GA(e){if(typeof e.id!=="string"||!e.id)return null;if(typeof e.from!=="string"||!e.from)return null;if(typeof e.to!=="string"||!e.to)return null;if(!qA(e.type))return null;return{id:e.id,from:e.from,to:e.to,type:e.type,...typeof e.label==="string"?{label:e.label}:{},...e.style==="solid"||e.style==="dashed"||e.style==="dotted"?{style:e.style}:{},...e.animated===!0?{animated:!0}:{}}}function XA(e){if(typeof e.id!=="string"||!e.id)return null;if(e.type!=="freehand"&&e.type!=="text")return null;if(!Array.isArray(e.points))return null;let t=e.points.map((o)=>Tp(o)).filter((o)=>o!==null),n=WA(e.bounds);if(t.length<(e.type==="text"?1:2)||!n)return null;return{id:e.id,type:e.type,points:t,bounds:n,color:typeof e.color==="string"?e.color:"#f97316",width:typeof e.width==="number"?e.width:4,...typeof e.text==="string"?{text:e.text}:{},...typeof e.label==="string"?{label:e.label}:{},createdAt:typeof e.createdAt==="string"?e.createdAt:""}}var Z_="pmx-canvas-version-reload";function JA(e,t){if(typeof window>"u")return;let n=window,o=(s,a)=>typeof s==="string"&&s!==""&&s!=="unknown"&&typeof a==="string"&&a!==""&&a!=="unknown"&&s!==a;if(!o(e,n.__PMX_BOOT_SERVER_VERSION)&&!o(t,n.__PMX_BOOT_BUNDLE_STAMP))return;let r=`${String(e)}::${String(t)}`;try{if(window.sessionStorage.getItem(Z_)===r)return;window.sessionStorage.setItem(Z_,r)}catch{return}window.location.reload()}function KA(e){let t=ao.value[0]?.id;if(ep(e),bt.value&&ao.value[0]?.id!==t)lo()}function YA(e){Iw(e)}var U_=null,Yi=0,_p=0,kp=0;function QA(e){id(e)}function ez(){let e=++Yi;Qi=null,Et.value=!1,Za(),Yv(),Ys(),zc(),on.value=null,Ip();let t=_p,n=kp;Nv().then((o)=>{if(e===Yi&&t===_p)K_({layout:o})}),Y("fetchPinnedContext","/api/canvas/pinned-context",{}).then((o)=>{if(e===Yi&&n===kp)Y_({nodeIds:o.nodeIds})})}eb(ez);function tz(e){if(kn.value=e.sessionId||"",Ot.value="connected",Ru(),zo.value+=1,JA(e.version,e.bundleStamp),yi(),Lv().then(ep),U_?.(),!Qs)U_=tx();if(Y("fetchHumanPresence","/api/canvas/human-presence",null).then(id),Ip().then(()=>{if(bt.value)lo()}),typeof e.theme==="string"&&!pp())Cp(e.theme);if(e.ledgerSummary)X_(e.ledgerSummary)}function nz(e){if(typeof e.path!=="string"||!e.path)return;let t=e.path,n=(typeof e.title==="string"?e.title:"")||t.split("/").pop()||"Untitled";if(FA(t,n),e.ledgerSummary)X_(e.ledgerSummary)}function oz(e){Kr(),ie("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function rz(e){Kr(),ie("status-main",{phase:e.phase,detail:e.detail})}function iz(e){let t=e.cards??[];BA(t)}function sz(e){if(typeof e.url==="string"&&e.url)HA({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function az(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let r=`mcp-${es(o)}`;if(O.value.has(r))ie(r,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function cz(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${es(e.url)}`;if(O.value.has(t))ie(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function lz(e){let n=O.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);ie("context-main",{auxTabs:o})}function uz(e){if(O.value.has("context-main"))if(e.mode==="all")ie("context-main",{auxTabs:[]});else{let o=O.value.get("context-main");if(!o)return;let r=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);ie("context-main",{auxTabs:r})}}function dz(e){Kr(),ie("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function pz(e){Kr(),ie("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function mz(e){Kr(),ie("status-main",{activeTool:null})}function fz(e){if(e.state==="active"&&e.path){let n=`md-${es(e.path)}`;if(O.value.has(n))ie(n,{reviewActive:!0})}}function hz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;jA({toolCallId:e.toolCallId,...typeof e.nodeId==="string"&&e.nodeId.length>0?{nodeId:e.nodeId}:{},title:e.title,html:e.html,toolInput:e.toolInput,serverName:e.serverName,toolName:e.toolName,appSessionId:e.appSessionId,resourceUri:e.resourceUri,toolDefinition:e.toolDefinition,resourceMeta:e.resourceMeta,hostMode:"hosted",trustedDomain:!0,...e.chartConfig?{chartConfig:e.chartConfig}:{},...typeof e.x==="number"&&{_x:e.x},...typeof e.y==="number"&&{_y:e.y},...typeof e.width==="number"&&{_width:e.width},...typeof e.height==="number"&&{_height:e.height}})}function gz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=V_(e)??G_(e.serverName,e.toolName);if(!t)return;if(O.value.has(t))ie(t,{html:e.html})}function vz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=V_(e)??G_(e.serverName,e.toolName);if(!t)return;if(O.value.has(t)){if(e.success===!1){Jn(t);return}ie(t,{toolResult:Bd({result:e.result,success:typeof e.success==="boolean"?e.success:void 0,error:typeof e.error==="string"?e.error:void 0,content:typeof e.content==="string"?e.content:void 0,detailedContent:typeof e.detailedContent==="string"?e.detailedContent:void 0})})}}function yz(e){Kr(),ie("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function bz(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:r,contextNodeIds:s}=e;if(e.threadNodeId&&O.value.has(e.threadNodeId)){let a=e.threadNodeId,c=O.value.get(a);if(!c)return;let l=Array.isArray(c.data.turns)?[...c.data.turns]:[],u=l[l.length-1];if(!u||u.role!=="user"||u.text!==n)l.push({role:"user",text:n,status:"pending"});ie(a,{turns:l,threadStatus:"pending"});return}if(!O.value.has(t)){let a=o??po.prompt;Cn(Vc(Ji(t,"prompt",{text:n,turns:n?[{role:"user",text:n,status:"pending"}]:[],threadStatus:n?"pending":"draft",status:n?"pending":"draft",parentNodeId:r,contextNodeIds:s},{position:{x:a.x,y:a.y}}))),Ye(t)}if(r&&O.value.has(r))dr({id:`edge-${r}-${t}`,from:r,to:t,type:"flow",style:"dashed"})}function xz(e){let{nodeId:t,status:n}=e;if(t&&O.value.has(t))ie(t,{status:n})}function wz(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?O.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){Jr.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),ie(n,{turns:s,threadStatus:"streaming",_activeResponseId:t}),Ye(n);return}let r=o?{x:o.position.x,y:o.position.y+o.size.height+24}:{x:po.response.x,y:po.response.y};if(!O.value.has(t))Cn(Vc(Ji(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:r})));if(n)dr({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});Ye(t)}function _z(e){let t=e.responseNodeId;if(!t)return;let n=Jr.get(t);if(n){let o=O.value.get(n);if(o&&Array.isArray(o.data.turns)){let r=[...o.data.turns],s=r[r.length-1];if(s&&s.role==="assistant")s.text=e.content,s.status="streaming";ie(n,{turns:r,threadStatus:"streaming"})}return}if(!O.value.has(t))return;ie(t,{content:e.content,status:"streaming"})}function kz(e){let t=e.responseNodeId;if(!t)return;let n=Jr.get(t);if(n){let s=O.value.get(n);if(s&&Array.isArray(s.data.turns)){let a=[...s.data.turns],c=a[a.length-1];if(c&&c.role==="assistant")c.text=e.content,c.status="complete";ie(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}Jr.delete(t);return}if(!O.value.has(t))return;ie(t,{content:e.content,status:"complete"});let r=O.value.get(t)?.data.promptNodeId;if(r){let s=`edge-${r}-${t}`,a=Fe.value.get(s);if(a)ay(s),dr({...a,animated:!1})}}function K_(e){let t=e.layout;if(!t?.nodes)return;_p+=1;let n=!Et.value;Et.value=!0;let o=t.nodes.map(VA).filter((c)=>c!==null),r=Array.isArray(t.edges)?t.edges.map(GA).filter((c)=>c!==null):Array.from(Fe.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(XA).filter((c)=>c!==null):void 0,a=t.viewport?{x:typeof t.viewport.x==="number"?t.viewport.x:0,y:typeof t.viewport.y==="number"?t.viewport.y:0,scale:typeof t.viewport.scale==="number"?t.viewport.scale:1}:void 0;if(n)In();my({...a?{viewport:a}:{},nodes:o,edges:r,...s?{annotations:s}:{}},{applyViewport:n}),hu({event:"canvas-layout-update",data:e})}function Sz(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function Cz(e){if(Au())return;let t=e.nodeId;if(t&&O.value.has(t)){if(e.noPan===!0){Tn(t);return}Ye(t)}}function Tz(e){if(Au())return;let t=e.viewport;if(!t)return;let n=typeof t.x==="number"?t.x:0,o=typeof t.y==="number"?t.y:0,r=typeof t.scale==="number"?t.scale:1;In(),uy({x:n,y:o,scale:r})}function Iz(e){if(O.value.get("context-main"))ie("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function Ez(e){mr.value=e.enabled===!0}function Az(e){if(typeof e.theme==="string"&&!pp())Cp(e.theme)}function Y_(e){kp+=1;let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];sy(t),hu({event:"context-pins-changed",data:e})}var Wc=null,Sp=0;async function Ip(){let e=++Sp,t=Yi,n=await Mv();if(e===Sp&&t===Yi)on.value=n}function q_(){if(Wc)clearTimeout(Wc);Sp+=1,Wc=setTimeout(()=>{if(Wc=null,Ip(),bt.value)lo()},150)}function zz(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;Vb(t)}function Pz(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)Xb(t,typeof e.nodeId==="string"?e.nodeId:void 0);else rd(t)}var Q_={connected:tz,"workbench-open":nz,"canvas-status":oz,"execution-phase":rz,"context-cards":iz,"mcp-app-candidate":sz,"mcp-app-host-snapshot":az,"mcp-app-host-fallback":cz,"aux-open":lz,"aux-close":uz,"assistant-complete":dz,"tool-start":pz,"tool-complete":mz,"review-state":fz,"subagent-status":yz,"ext-app-open":hz,"ext-app-update":gz,"ext-app-result":vz,"context-pins-changed":Y_,"boards-changed":$o,"canvas-layout-update":K_,"canvas-focus-node":Cz,"canvas-viewport-update":Tz,"context-usage":Iz,"trace-state":Ez,"theme-changed":Az,"canvas-prompt-created":bz,"canvas-prompt-status":xz,"canvas-response-start":wz,"canvas-response-delta":_z,"canvas-response-complete":kz,"ax-state-changed":q_,"ax-event-created":q_,"ax-intent":zz,"ax-intent-clear":Pz,"agent-presence":KA,"human-presence":QA,"agent-session-ended":YA};function ek(e,t){let n=Q_[e];if(!n)return;let o=n;try{o(t)}catch(r){console.warn(`[sse-bridge] Handler for "${e}" failed:`,r)}}function W_(){Ki=!0,ho+=1;let e=ho;Ot.value="connecting";let t=null,n=!1,o=async()=>{if(e!==ho)return;try{let r=new URLSearchParams;if(Xr!==null)r.set("since",String(Xr));let s=kn.value;if(s)r.set("session",s);let a=r.toString(),c=await fetch(`/api/workbench/poll${a?`?${a}`:""}`);if(e!==ho)return;if(!c.ok)throw Error(`poll failed with HTTP ${c.status}`);let l=await c.json();if(e!==ho)return;if(!l.ok)throw Error("poll returned ok: false");let u=t;if(t=l.sessionId??null,u!==null&&l.sessionId&&u!==l.sessionId&&!l.snapshot){Xr=null,$n=setTimeout(()=>void o(),0);return}if(l.snapshot&&n)Qi=Eu(),Et.value=!1,Ys(),Za(),Jr.clear();for(let p of l.events)ek(p.event,p.payload);n=!0,Xr=l.seq,Po.value=0,No.value=0,Ot.value="connected",$n=setTimeout(()=>void o(),LA)}catch(r){if(e!==ho)return;console.warn("[sse-bridge] poll transport error:",r),Ot.value="disconnected",Po.value+=1,No.value=j_,$n=setTimeout(()=>void o(),j_)}};return o(),()=>{if(ho+=1,Ki=!1,Xr=null,$n)clearTimeout($n),$n=null}}function Ep(){if(e_(Cp),Qi=Eu(),Et.value=!1,Ys(),Za(),Jr.clear(),mo)clearTimeout(mo),mo=null;let e=OA();if(e==="poll"||Ki)return W_();let t=kn.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";Ot.value="connecting";let o=new EventSource(n);Vo=o;let r=!1;if(fo)clearTimeout(fo);if(fo=null,e!=="sse")fo=setTimeout(()=>{if(fo=null,r||Vo!==o)return;console.warn("[sse-bridge] No SSE event within watchdog window — switching to polling transport."),window.dispatchEvent(new Event("pmx-canvas-boot-extend")),o.close(),Vo=null,W_()},MA);for(let[s]of Object.entries(Q_))o.addEventListener(s,(a)=>{r=!0;try{ek(s,JSON.parse(a.data))}catch(c){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,c)}});return o.onopen=()=>{if(Vo!==o)return;qc=0,Po.value=0,No.value=0,Ot.value="connected"},o.onerror=()=>{if(Vo!==o)return;Ot.value="disconnected",o.close(),Vo=null,qc+=1;let s=Sz(qc);Po.value=qc,No.value=s,mo=setTimeout(()=>{mo=null,Ep()},s)},()=>{if(mo)clearTimeout(mo),mo=null;if(fo)clearTimeout(fo),fo=null;if(Ki){if(ho+=1,Ki=!1,Xr=null,$n)clearTimeout($n),$n=null}o.close(),Vo=null}}function Go(e,t){console.error(`[app] ${e} failed`,t)}function tk(){let[e,t]=I(!0),[n,o]=I(!1),[r,s]=I(!1),[a,c]=I(!1),[l,u]=I(!1),[p,d]=I(null),m=z(null),{menu:f,openNodeMenu:h,openCanvasMenu:v,openEdgeMenu:x,closeMenu:g}=o_(),y=Et.value,E=_r.value&&Ne.value===null,D=bt.value,N=H(()=>t((R)=>!R),[]),b=H(()=>o((R)=>!R),[]),T=H(()=>o(!1),[]),w=H((R)=>d(R),[]),_=H((R,Z)=>{Kn({x:R,y:Z,scale:K.value.scale},200)},[]);B(()=>Ep(),[]),B(()=>{let R=()=>c(!0);return window.addEventListener("pmx-open-board-link",R),()=>window.removeEventListener("pmx-open-board-link",R)},[]),B(()=>{let R=null,Z=()=>{if(R!==null)window.clearTimeout(R);R=window.setTimeout(()=>{R=null,yi()},400)};return window.addEventListener("resize",Z),()=>{if(R!==null)window.clearTimeout(R);window.removeEventListener("resize",Z)}},[]),B(()=>{let R=(k)=>{let V=(k.metaKey||k.ctrlKey)&&!k.altKey;if(V&&k.key==="k"){k.preventDefault(),s((se)=>!se);return}if(k.key==="Escape"&&p){k.preventDefault(),d(null);return}if(k.key==="Escape"&&We.value&&!nn.value){k.preventDefault(),En();return}if(k.key==="Escape"&&r){k.preventDefault(),s(!1);return}if(k.key==="Escape"&&l){k.preventDefault(),u(!1);return}let ge=k.target,Ue=ge?.tagName;if(Ue==="INPUT"||Ue==="TEXTAREA"||ge?.isContentEditable)return;if(k.key===" "&&!k.repeat&&!V){k.preventDefault(),wi.value=!0;return}if(k.key==="?"||k.key==="/"&&k.shiftKey){k.preventDefault(),u((se)=>!se);return}if(V&&(k.key==="z"||k.key==="Z"))k.preventDefault(),sp(k.shiftKey);else if(V&&(k.key==="y"||k.key==="Y"))k.preventDefault(),sp(!0);else if(V&&k.key==="0")k.preventDefault(),Kn({x:0,y:0,scale:1},250);else if(V&&(k.key==="="||k.key==="+"))k.preventDefault(),gr(1.25);else if(V&&k.key==="-")k.preventDefault(),gr(0.8);else if(k.key==="Escape"){if(be.value.size>0||fn.value!==null){_t();return}Te.value=null,g()}else if(k.key==="Tab")k.preventDefault(),hy(k.shiftKey?-1:1);else if(k.key==="Delete"||k.key==="Backspace"){if(fn.value!==null){let le=fn.value;k.preventDefault(),fn.value=null,aa(le).catch((pe)=>Go("delete-edge",pe));return}let se=be.value.size>0?[...be.value]:Te.value?[Te.value]:[];if(se.length===0)return;k.preventDefault();for(let le of se)Vn(le).catch((pe)=>Go("delete",pe));_t(),Te.value=null}else if(Te.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(k.key)){k.preventDefault();let se=k.key.replace("Arrow","").toLowerCase();gy(se)}else if(!V&&!k.altKey){let se=k.key.toLowerCase();if(se==="v"&&!k.shiftKey)At.value="select";else if(se==="c"&&!k.shiftKey&&!V)k.preventDefault(),At.value=At.value==="connect"?"select":"connect";else if(se==="m"&&!k.shiftKey)k.preventDefault(),Gt({type:"markdown",title:"New note",width:520,height:360}).catch((le)=>Go("create markdown",le));else if(se==="a"&&!k.shiftKey)k.preventDefault(),d((le)=>le==="pen"?null:"pen");else if(se==="g"&&!k.shiftKey){k.preventDefault();let le=Array.from(be.value);if(le.length>=2)lr({title:"Group",childIds:le}).catch((pe)=>Go("group selection",pe)),_t();else Gt({type:"group",title:"Group"}).catch((pe)=>Go("create group",pe))}else if(se==="g"&&k.shiftKey){k.preventDefault();for(let le of ny())Jn(le),ur(le).catch((pe)=>Go("ungroup",pe));_t()}else if(se==="i"&&!k.shiftKey)k.preventDefault(),Wo("image");else if(se==="w"&&!k.shiftKey)k.preventDefault(),Wo("webpage");else if(se==="h"&&!k.shiftKey)k.preventDefault(),Gt({type:"html",title:"HTML surface"}).catch((le)=>Go("create html",le));else if(se==="f"&&k.shiftKey)k.preventDefault(),Wo("file");else if(se==="f"&&!k.shiftKey){k.preventDefault();let le=it();vr(le.width,le.height)}}},Z=(k)=>{if(k.key===" ")wi.value=!1},j=()=>{wi.value=!1};return document.addEventListener("keydown",R),document.addEventListener("keyup",Z),window.addEventListener("blur",j),()=>{document.removeEventListener("keydown",R),document.removeEventListener("keyup",Z),window.removeEventListener("blur",j)}},[p,g,r,l]),B(()=>{let R=window.setTimeout(()=>void yi(),250);return()=>window.clearTimeout(R)},[D]),B(()=>{if(!y)return;let R=window.__pmxCanvasBootstrapReady;if(typeof R==="function")R()},[y]);let P=Array.from(O.value.values()),q=it();return i("div",{class:`app-shell${rn.value?" is-presenting":""}`,"data-session-active":D?"true":"false",children:[i(by,{},void 0,!1,void 0,this),i(c_,{minimapVisible:e,onToggleMinimap:N,snapshotOpen:n,onToggleSnapshot:b,snapshotBtnRef:m,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>u((R)=>!R),annotationTool:p,onSetAnnotationTool:w},void 0,!1,void 0,this),i("div",{class:"app-main",children:[i(H_,{},void 0,!1,void 0,this),i(Kw,{},void 0,!1,void 0,this),i("div",{class:"canvas-region",ref:(R)=>rv(R),children:[i(Xw,{onNodeContextMenu:h,onCanvasContextMenu:v,onEdgeContextMenu:x,annotationMode:p!==null,annotationTool:p},void 0,!1,void 0,this),i(jy,{},void 0,!1,void 0,this),i(Hy,{},void 0,!1,void 0,this),i(b_,{},void 0,!1,void 0,this),i(x_,{},void 0,!1,void 0,this),E?i(g_,{},void 0,!1,void 0,this):y&&P.length===0&&Xe.value.size===0&&i(l_,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),be.value.size>0&&i(A_,{},void 0,!1,void 0,this),D?i(Jw,{},void 0,!1,void 0,this):Ae.value.size>0&&i(s_,{},void 0,!1,void 0,this),i(R_,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),i(Uy,{},void 0,!1,void 0,this),i(v_,{},void 0,!1,void 0,this),We.value&&i(S_,{},void 0,!1,void 0,this),i(O_,{open:n,onClose:T,anchorRef:m},void 0,!1,void 0,this),e&&!E&&i(E_,{viewport:K,nodes:O,edges:Fe,onNavigate:_,containerWidth:q.width,containerHeight:q.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),D&&i(N_,{},void 0,!1,void 0,this),f&&i(r_,{menu:f,onClose:g},void 0,!1,void 0,this),r&&i(t_,{onClose:()=>s(!1),onToggleMinimap:N},void 0,!1,void 0,this),a&&i(n_,{onClose:()=>c(!1)},void 0,!1,void 0,this),l&&i($_,{onClose:()=>u(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}Ky();var nk=document.getElementById("app");if(nk)Yr(i(tk,{},void 0,!1,void 0,this),nk);
|