pmx-canvas 0.8.0 → 0.8.2
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/.github/extensions/pmx-canvas/runtime.json +1 -1
- package/CHANGELOG.md +17 -0
- package/Readme.md +2 -2
- package/dist/canvas/global.css +6 -5
- package/dist/canvas/index.js +12 -12
- package/dist/canvas/mcp-app.html +22 -21
- package/dist/json-render/index.css +81 -1
- package/dist/json-render/index.js +1 -1
- package/dist/types/client/nodes/HtmlNode.d.ts +1 -0
- package/docs/design/Chrome.dc.html +3 -0
- package/docs/design.md +6 -3
- package/docs/http-api.md +6 -1
- package/docs/mcp.md +4 -1
- package/package.json +1 -1
- package/plugins/pmx-canvas/com.github.copilot/extensions/pmx-canvas/runtime.json +1 -1
- package/plugins/pmx-canvas/plugin.json +1 -1
- package/plugins/pmx-canvas/runtime.json +1 -1
- package/skills/pmx-canvas/SKILL.md +20 -3
- package/skills/pmx-canvas/evals/evals.json +62 -0
- package/skills/pmx-canvas/references/ax-html-control-surface.md +6 -0
- package/skills/pmx-canvas/references/installing-pmx-canvas.md +6 -6
- package/src/cli/commands/nodes.ts +3 -2
- package/src/cli/index.ts +2 -1
- package/src/client/nodes/HtmlNode.tsx +12 -2
- package/src/client/theme/global.css +6 -5
- package/src/json-render/renderer/index.css +6 -1
- package/src/json-render/renderer/index.tsx +0 -1
- package/src/server/canvas-operations.ts +1 -1
- package/src/server/context-reads.ts +1 -0
- package/src/server/index.ts +22 -2
- package/src/server/operations/mcp.ts +6 -0
- package/src/server/operations/ops/json-render.ts +5 -1
- package/src/server/operations/registry.ts +3 -1
package/dist/canvas/mcp-app.html
CHANGED
|
@@ -637,8 +637,8 @@ body,
|
|
|
637
637
|
}
|
|
638
638
|
.node-port::after {
|
|
639
639
|
content: '';
|
|
640
|
-
width: calc(
|
|
641
|
-
height: calc(
|
|
640
|
+
width: calc(4px * var(--node-port-scale, 1));
|
|
641
|
+
height: calc(4px * var(--node-port-scale, 1));
|
|
642
642
|
border-radius: 50%;
|
|
643
643
|
background: var(--c-accent);
|
|
644
644
|
border: calc(2px * var(--node-port-scale, 1)) solid var(--c-panel);
|
|
@@ -776,14 +776,15 @@ body,
|
|
|
776
776
|
}
|
|
777
777
|
|
|
778
778
|
/* ⋯ and × appear on hover or keyboard focus; expand and the context pin
|
|
779
|
-
always show (docs/design/Chrome.dc.html).
|
|
779
|
+
always show (docs/design/Chrome.dc.html). Reserve their slots so revealing
|
|
780
|
+
them cannot move the pin out from under the pointer onto Close. */
|
|
780
781
|
.canvas-node .node-controls .node-hover-control {
|
|
781
|
-
|
|
782
|
+
visibility: hidden;
|
|
782
783
|
}
|
|
783
784
|
|
|
784
785
|
.canvas-node:hover .node-controls .node-hover-control,
|
|
785
786
|
.canvas-node:focus-within .node-controls .node-hover-control {
|
|
786
|
-
|
|
787
|
+
visibility: visible;
|
|
787
788
|
}
|
|
788
789
|
|
|
789
790
|
.canvas-node .node-body {
|
|
@@ -7525,7 +7526,7 @@ html.is-node-dragging .intent-line-layer {
|
|
|
7525
7526
|
|
|
7526
7527
|
${l}${u}
|
|
7527
7528
|
|
|
7528
|
-
`}}};Jo.tableCaption={filter:["caption"],replacement:()=>""};Jo.tableColgroup={filter:["colgroup","col"],replacement:()=>""};Jo.tableSection={filter:["thead","tbody","tfoot"],replacement:function(e){return e}};function qA(e){var t=e.parentNode;return t.nodeName==="THEAD"||t.firstChild===e&&(t.nodeName==="TABLE"||GA(t))&&UA.call(e.childNodes,function(n){return n.nodeName==="TH"})}function GA(e){var t=e.previousSibling;return e.nodeName==="TBODY"&&(!t||t.nodeName==="THEAD"&&/^\s*$/i.test(t.textContent))}function yw(e,t=null,n=null){if(n===null)n=jA.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=KA(r,t," ");return o+r+" |"}function bw(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(bw(n))return!0}return!1}var Np=(e,t)=>{if(!e.childNodes)return!1;for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];if(t==="code"&&Rp&&Rp(o))return!0;if(t.includes(o.nodeName))return!0;if(Np(o,t))return!0}return!1},xw=(e,t)=>{let n=["UL","OL","H1","H2","H3","H4","H5","H6","HR","BLOCKQUOTE"];if(t.preserveNestedTables)n.push("TABLE");return Np(e,"code")||Np(e,n)};function zp(e){let t=pw.get(e);if(t!==void 0)return t;let n=VA(e);return pw.set(e,n),n}function VA(e){if(!e)return!0;if(!e.rows)return!0;if(e.rows.length===1&&e.rows[0].childNodes.length<=1)return!0;if(bw(e))return!0;return!1}function XA(e){let t=e.parentNode;while(t.nodeName!=="DIV")if(t=t.parentNode,!t)return null;return t}function ww(e){let t=e.parentNode;while(t.nodeName!=="TABLE")if(t=t.parentNode,!t)return null;return t}function KA(e,t,n){let o=t.getAttribute("colspan")||1;for(let r=1;r<o;r++)e+=" | "+n.repeat(3);return e}function Sw(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 _w(e){Rp=e.isCodeBlock,hw=e.options,e.keep(function(n){if(n.nodeName==="TABLE"&&xw(n,e.options))return!0;return!1});for(var t in Jo)e.addRule(t,Jo[t])}function kw(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 JA(e){e.use([mw,fw,_w,kw])}zr.gfm=JA;zr.highlightedCodeBlock=mw;zr.strikethrough=fw;zr.tables=_w;zr.taskListItems=kw});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 Vz=Object.freeze({status:"aborted"});function H(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 Xz=Symbol("zod_brand");class so extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class us extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}var Pa={};function _n(e){if(e)Object.assign(Pa,e);return Pa}function Na(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 _u(e,t="|"){return e.map((n)=>Eu(n)).join(t)}function ds(e,t){if(typeof t==="bigint")return t.toString();return t}function ps(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw Error("cached value already set")}}}function za(e){return e===null||e===void 0}function Ma(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function bf(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 yf=Symbol("evaluating");function Be(e,t,n){let o=void 0;Object.defineProperty(e,t,{get(){if(o===yf)return;if(o===void 0)o=yf,o=n();return o},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function gr(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function No(...e){let t={};for(let n of e){let o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function ku(e){return JSON.stringify(e)}function xf(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var Tu="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Yr(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var wf=ps(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function vr(e){if(Yr(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(Yr(n)===!1)return!1;if(Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)return!1;return!0}function Cu(e){if(vr(e))return{...e};if(Array.isArray(e))return[...e];return e}var Sf=new Set(["string","number","symbol"]);function zo(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function qn(e,t,n){let o=new e._zod.constr(t??e._zod.def);if(!t||n?.parent)o._zod.parent=e;return o}function ee(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 Eu(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function _f(e){return Object.keys(e).filter((t)=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var kf={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 M0(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=No(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 gr(this,"shape",a),a},checks:[]});return qn(e,s)}function $0(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=No(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 gr(this,"shape",a),a},checks:[]});return qn(e,s)}function O0(e,t){if(!vr(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=No(e._zod.def,{get shape(){let s={...e._zod.def.shape,...t};return gr(this,"shape",s),s}});return qn(e,r)}function L0(e,t){if(!vr(t))throw Error("Invalid input to safeExtend: expected a plain object");let n=No(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t};return gr(this,"shape",o),o}});return qn(e,n)}function D0(e,t){let n=No(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t._zod.def.shape};return gr(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return qn(e,n)}function F0(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=No(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 gr(this,"shape",l),l},checks:[]});return qn(t,a)}function H0(e,t,n){let o=No(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 gr(this,"shape",s),s}});return qn(t,o)}function yr(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 Mo(e,t){return t.map((n)=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function Ra(e){return typeof e==="string"?e:e?.message}function Gn(e,t,n){let o={...e,path:e.path??[]};if(!e.message){let r=Ra(e.inst?._zod.def?.error?.(e))??Ra(t?.error?.(e))??Ra(n.customError?.(e))??Ra(n.localeError?.(e))??"Invalid input";o.message=r}if(delete o.inst,delete o.continue,!t?.reportInput)delete o.input;return o}function $a(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function Tf(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 br(...e){let[t,n,o]=e;if(typeof t==="string")return{message:t,code:"custom",input:n,inst:o};return{...t}}var Cf=(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,ds,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Oa=H("$ZodError",Cf),Iu=H("$ZodError",Cf,{Parent:Error});function Ef(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 If(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 La=(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 so;if(a.issues.length){let c=new(r?.Err??e)(a.issues.map((l)=>Gn(l,s,_n())));throw Tu(c,r?.callee),c}return a.value};var Da=(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)=>Gn(l,s,_n())));throw Tu(c,r?.callee),c}return a.value};var ms=(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 so;return s.issues.length?{success:!1,error:new(e??Oa)(s.issues.map((a)=>Gn(a,r,_n())))}:{success:!0,data:s.value}},fs=ms(Iu),hs=(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)=>Gn(a,r,_n())))}:{success:!0,data:s.value}},Fa=hs(Iu),Af=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return La(e)(t,n,r)};var Pf=(e)=>(t,n,o)=>La(e)(t,n,o);var Rf=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return Da(e)(t,n,r)};var Nf=(e)=>async(t,n,o)=>Da(e)(t,n,o);var zf=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ms(e)(t,n,r)};var Mf=(e)=>(t,n,o)=>ms(e)(t,n,o);var $f=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return hs(e)(t,n,r)};var Of=(e)=>async(t,n,o)=>hs(e)(t,n,o);var Lf=/^[cC][^\s-]{8,}$/,Df=/^[0-9a-z]+$/,Ff=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Hf=/^[0-9a-vA-V]{20}$/,Bf=/^[A-Za-z0-9]{27}$/,jf=/^[a-zA-Z0-9_-]{21}$/,Uf=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Zf=/^([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})$/,Au=(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 Wf=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var j0="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function qf(){return new RegExp(j0,"u")}var Gf=/^(?:(?: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])$/,Vf=/^(([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 Xf=/^((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])$/,Kf=/^(([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])$/,Jf=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Pu=/^[A-Za-z0-9_-]*$/;var Yf=/^\+[1-9]\d{6,14}$/,Qf="(?:(?:\\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])))",eh=new RegExp(`^${Qf}$`);function th(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 nh(e){return new RegExp(`^${th(e)}$`)}function oh(e){let t=th({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(`^${Qf}T(?:${o})$`)}var rh=(e)=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var ih=/^-?\d+$/,Ru=/^-?\d+(?:\.\d+)?$/,sh=/^(?:true|false)$/i,ah=/^null$/i;var ch=/^undefined$/i;var lh=/^[^A-Z]*$/,uh=/^[^a-z]*$/;var Pt=H("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),dh={number:"number",bigint:"bigint",object:"date"},Nu=H("$ZodCheckLessThan",(e,t)=>{Pt.init(e,t);let n=dh[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})}}),zu=H("$ZodCheckGreaterThan",(e,t)=>{Pt.init(e,t);let n=dh[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})}}),ph=H("$ZodCheckMultipleOf",(e,t)=>{Pt.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):bf(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})}}),mh=H("$ZodCheckNumberFormat",(e,t)=>{Pt.init(e,t),t.format=t.format||"float64";let n=t.format?.includes("int"),o=n?"int":"number",[r,s]=kf[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=ih}),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 fh=H("$ZodCheckMaxLength",(e,t)=>{var n;Pt.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!za(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=$a(r);o.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),hh=H("$ZodCheckMinLength",(e,t)=>{var n;Pt.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!za(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=$a(r);o.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),gh=H("$ZodCheckLengthEquals",(e,t)=>{var n;Pt.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!za(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=$a(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})}}),gs=H("$ZodCheckStringFormat",(e,t)=>{var n,o;if(Pt.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=()=>{})}),vh=H("$ZodCheckRegex",(e,t)=>{gs.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})}}),yh=H("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=lh),gs.init(e,t)}),bh=H("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=uh),gs.init(e,t)}),xh=H("$ZodCheckIncludes",(e,t)=>{Pt.init(e,t);let n=zo(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})}}),wh=H("$ZodCheckStartsWith",(e,t)=>{Pt.init(e,t);let n=new RegExp(`^${zo(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})}}),Sh=H("$ZodCheckEndsWith",(e,t)=>{Pt.init(e,t);let n=new RegExp(`.*${zo(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 _h=H("$ZodCheckOverwrite",(e,t)=>{Pt.init(e,t),e._zod.check=(n)=>{n.value=t.tx(n.value)}});class Mu{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(`
|
|
7529
|
+
`}}};Jo.tableCaption={filter:["caption"],replacement:()=>""};Jo.tableColgroup={filter:["colgroup","col"],replacement:()=>""};Jo.tableSection={filter:["thead","tbody","tfoot"],replacement:function(e){return e}};function qA(e){var t=e.parentNode;return t.nodeName==="THEAD"||t.firstChild===e&&(t.nodeName==="TABLE"||GA(t))&&UA.call(e.childNodes,function(n){return n.nodeName==="TH"})}function GA(e){var t=e.previousSibling;return e.nodeName==="TBODY"&&(!t||t.nodeName==="THEAD"&&/^\s*$/i.test(t.textContent))}function yw(e,t=null,n=null){if(n===null)n=jA.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=KA(r,t," ");return o+r+" |"}function bw(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(bw(n))return!0}return!1}var Np=(e,t)=>{if(!e.childNodes)return!1;for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];if(t==="code"&&Rp&&Rp(o))return!0;if(t.includes(o.nodeName))return!0;if(Np(o,t))return!0}return!1},xw=(e,t)=>{let n=["UL","OL","H1","H2","H3","H4","H5","H6","HR","BLOCKQUOTE"];if(t.preserveNestedTables)n.push("TABLE");return Np(e,"code")||Np(e,n)};function zp(e){let t=pw.get(e);if(t!==void 0)return t;let n=VA(e);return pw.set(e,n),n}function VA(e){if(!e)return!0;if(!e.rows)return!0;if(e.rows.length===1&&e.rows[0].childNodes.length<=1)return!0;if(bw(e))return!0;return!1}function XA(e){let t=e.parentNode;while(t.nodeName!=="DIV")if(t=t.parentNode,!t)return null;return t}function ww(e){let t=e.parentNode;while(t.nodeName!=="TABLE")if(t=t.parentNode,!t)return null;return t}function KA(e,t,n){let o=t.getAttribute("colspan")||1;for(let r=1;r<o;r++)e+=" | "+n.repeat(3);return e}function Sw(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 _w(e){Rp=e.isCodeBlock,hw=e.options,e.keep(function(n){if(n.nodeName==="TABLE"&&xw(n,e.options))return!0;return!1});for(var t in Jo)e.addRule(t,Jo[t])}function kw(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 JA(e){e.use([mw,fw,_w,kw])}zr.gfm=JA;zr.highlightedCodeBlock=mw;zr.strikethrough=fw;zr.tables=_w;zr.taskListItems=kw});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 Xz=Object.freeze({status:"aborted"});function H(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 Kz=Symbol("zod_brand");class so extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class us extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}var Pa={};function _n(e){if(e)Object.assign(Pa,e);return Pa}function Na(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 _u(e,t="|"){return e.map((n)=>Eu(n)).join(t)}function ds(e,t){if(typeof t==="bigint")return t.toString();return t}function ps(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw Error("cached value already set")}}}function za(e){return e===null||e===void 0}function Ma(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function bf(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 yf=Symbol("evaluating");function Be(e,t,n){let o=void 0;Object.defineProperty(e,t,{get(){if(o===yf)return;if(o===void 0)o=yf,o=n();return o},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function gr(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function No(...e){let t={};for(let n of e){let o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function ku(e){return JSON.stringify(e)}function xf(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var Tu="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Yr(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var wf=ps(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function vr(e){if(Yr(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(Yr(n)===!1)return!1;if(Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)return!1;return!0}function Cu(e){if(vr(e))return{...e};if(Array.isArray(e))return[...e];return e}var Sf=new Set(["string","number","symbol"]);function zo(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function qn(e,t,n){let o=new e._zod.constr(t??e._zod.def);if(!t||n?.parent)o._zod.parent=e;return o}function ee(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 Eu(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function _f(e){return Object.keys(e).filter((t)=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var kf={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 M0(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=No(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 gr(this,"shape",a),a},checks:[]});return qn(e,s)}function $0(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=No(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 gr(this,"shape",a),a},checks:[]});return qn(e,s)}function O0(e,t){if(!vr(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=No(e._zod.def,{get shape(){let s={...e._zod.def.shape,...t};return gr(this,"shape",s),s}});return qn(e,r)}function L0(e,t){if(!vr(t))throw Error("Invalid input to safeExtend: expected a plain object");let n=No(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t};return gr(this,"shape",o),o}});return qn(e,n)}function D0(e,t){let n=No(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t._zod.def.shape};return gr(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return qn(e,n)}function F0(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=No(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 gr(this,"shape",l),l},checks:[]});return qn(t,a)}function H0(e,t,n){let o=No(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 gr(this,"shape",s),s}});return qn(t,o)}function yr(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 Mo(e,t){return t.map((n)=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function Ra(e){return typeof e==="string"?e:e?.message}function Gn(e,t,n){let o={...e,path:e.path??[]};if(!e.message){let r=Ra(e.inst?._zod.def?.error?.(e))??Ra(t?.error?.(e))??Ra(n.customError?.(e))??Ra(n.localeError?.(e))??"Invalid input";o.message=r}if(delete o.inst,delete o.continue,!t?.reportInput)delete o.input;return o}function $a(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function Tf(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 br(...e){let[t,n,o]=e;if(typeof t==="string")return{message:t,code:"custom",input:n,inst:o};return{...t}}var Cf=(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,ds,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Oa=H("$ZodError",Cf),Iu=H("$ZodError",Cf,{Parent:Error});function Ef(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 If(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 La=(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 so;if(a.issues.length){let c=new(r?.Err??e)(a.issues.map((l)=>Gn(l,s,_n())));throw Tu(c,r?.callee),c}return a.value};var Da=(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)=>Gn(l,s,_n())));throw Tu(c,r?.callee),c}return a.value};var ms=(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 so;return s.issues.length?{success:!1,error:new(e??Oa)(s.issues.map((a)=>Gn(a,r,_n())))}:{success:!0,data:s.value}},fs=ms(Iu),hs=(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)=>Gn(a,r,_n())))}:{success:!0,data:s.value}},Fa=hs(Iu),Af=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return La(e)(t,n,r)};var Pf=(e)=>(t,n,o)=>La(e)(t,n,o);var Rf=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return Da(e)(t,n,r)};var Nf=(e)=>async(t,n,o)=>Da(e)(t,n,o);var zf=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ms(e)(t,n,r)};var Mf=(e)=>(t,n,o)=>ms(e)(t,n,o);var $f=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return hs(e)(t,n,r)};var Of=(e)=>async(t,n,o)=>hs(e)(t,n,o);var Lf=/^[cC][^\s-]{8,}$/,Df=/^[0-9a-z]+$/,Ff=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Hf=/^[0-9a-vA-V]{20}$/,Bf=/^[A-Za-z0-9]{27}$/,jf=/^[a-zA-Z0-9_-]{21}$/,Uf=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Zf=/^([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})$/,Au=(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 Wf=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var j0="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function qf(){return new RegExp(j0,"u")}var Gf=/^(?:(?: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])$/,Vf=/^(([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 Xf=/^((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])$/,Kf=/^(([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])$/,Jf=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Pu=/^[A-Za-z0-9_-]*$/;var Yf=/^\+[1-9]\d{6,14}$/,Qf="(?:(?:\\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])))",eh=new RegExp(`^${Qf}$`);function th(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 nh(e){return new RegExp(`^${th(e)}$`)}function oh(e){let t=th({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(`^${Qf}T(?:${o})$`)}var rh=(e)=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var ih=/^-?\d+$/,Ru=/^-?\d+(?:\.\d+)?$/,sh=/^(?:true|false)$/i,ah=/^null$/i;var ch=/^undefined$/i;var lh=/^[^A-Z]*$/,uh=/^[^a-z]*$/;var Pt=H("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),dh={number:"number",bigint:"bigint",object:"date"},Nu=H("$ZodCheckLessThan",(e,t)=>{Pt.init(e,t);let n=dh[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})}}),zu=H("$ZodCheckGreaterThan",(e,t)=>{Pt.init(e,t);let n=dh[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})}}),ph=H("$ZodCheckMultipleOf",(e,t)=>{Pt.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):bf(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})}}),mh=H("$ZodCheckNumberFormat",(e,t)=>{Pt.init(e,t),t.format=t.format||"float64";let n=t.format?.includes("int"),o=n?"int":"number",[r,s]=kf[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=ih}),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 fh=H("$ZodCheckMaxLength",(e,t)=>{var n;Pt.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!za(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=$a(r);o.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),hh=H("$ZodCheckMinLength",(e,t)=>{var n;Pt.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!za(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=$a(r);o.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),gh=H("$ZodCheckLengthEquals",(e,t)=>{var n;Pt.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!za(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=$a(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})}}),gs=H("$ZodCheckStringFormat",(e,t)=>{var n,o;if(Pt.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=()=>{})}),vh=H("$ZodCheckRegex",(e,t)=>{gs.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})}}),yh=H("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=lh),gs.init(e,t)}),bh=H("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=uh),gs.init(e,t)}),xh=H("$ZodCheckIncludes",(e,t)=>{Pt.init(e,t);let n=zo(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})}}),wh=H("$ZodCheckStartsWith",(e,t)=>{Pt.init(e,t);let n=new RegExp(`^${zo(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})}}),Sh=H("$ZodCheckEndsWith",(e,t)=>{Pt.init(e,t);let n=new RegExp(`.*${zo(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 _h=H("$ZodCheckOverwrite",(e,t)=>{Pt.init(e,t),e._zod.check=(n)=>{n.value=t.tx(n.value)}});class Mu{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(`
|
|
7529
7530
|
`).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(`
|
|
7530
7531
|
`))}}var Th={major:4,minor:3,patch:6};var Ke=H("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Th;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=yr(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 so;if(p||f instanceof Promise)p=(p??Promise.resolve()).then(async()=>{if(await f,a.issues.length===m)return;if(!u)u=yr(a,m)});else{if(a.issues.length===m)continue;if(!u)u=yr(a,m)}}if(p)return p.then(()=>a);return a},s=(a,c,l)=>{if(yr(a))return a.aborted=!0,a;let u=r(c,o,l);if(u instanceof Promise){if(l.async===!1)throw new so;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 so;return l.then((u)=>r(u,o,c))}return r(l,o,c)}}Be(e,"~standard",()=>({validate:(r)=>{try{let s=fs(e,r);return s.success?{value:s.data}:{issues:s.error?.issues}}catch(s){return Fa(e,r).then((a)=>a.success?{value:a.data}:{issues:a.error?.issues})}},vendor:"zod",version:1}))}),Ua=H("$ZodString",(e,t)=>{Ke.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??rh(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}}),et=H("$ZodStringFormat",(e,t)=>{gs.init(e,t),Ua.init(e,t)}),Mh=H("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Zf),et.init(e,t)}),$h=H("$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=Au(o))}else t.pattern??(t.pattern=Au());et.init(e,t)}),Oh=H("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Wf),et.init(e,t)}),Lh=H("$ZodURL",(e,t)=>{et.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})}}}),Dh=H("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=qf()),et.init(e,t)}),Fh=H("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=jf),et.init(e,t)}),Hh=H("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Lf),et.init(e,t)}),Bh=H("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Df),et.init(e,t)}),jh=H("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Ff),et.init(e,t)}),Uh=H("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Hf),et.init(e,t)}),Zh=H("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Bf),et.init(e,t)}),Wh=H("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=oh(t)),et.init(e,t)}),qh=H("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=eh),et.init(e,t)}),Gh=H("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=nh(t)),et.init(e,t)}),Vh=H("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Uf),et.init(e,t)}),Xh=H("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Gf),et.init(e,t),e._zod.bag.format="ipv4"}),Kh=H("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Vf),et.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 Jh=H("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Xf),et.init(e,t)}),Yh=H("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Kf),et.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 Qh(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var eg=H("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Jf),et.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=(n)=>{if(Qh(n.value))return;n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function W0(e){if(!Pu.test(e))return!1;let t=e.replace(/[-_]/g,(o)=>o==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return Qh(n)}var tg=H("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Pu),et.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=(n)=>{if(W0(n.value))return;n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),ng=H("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Yf),et.init(e,t)});function q0(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 og=H("$ZodJWT",(e,t)=>{et.init(e,t),e._zod.check=(n)=>{if(q0(n.value,t.alg))return;n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}});var Ou=H("$ZodNumber",(e,t)=>{Ke.init(e,t),e._zod.pattern=e._zod.bag.pattern??Ru,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}}),rg=H("$ZodNumberFormat",(e,t)=>{mh.init(e,t),Ou.init(e,t)}),ig=H("$ZodBoolean",(e,t)=>{Ke.init(e,t),e._zod.pattern=sh,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 sg=H("$ZodUndefined",(e,t)=>{Ke.init(e,t),e._zod.pattern=ch,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}}),ag=H("$ZodNull",(e,t)=>{Ke.init(e,t),e._zod.pattern=ah,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 cg=H("$ZodUnknown",(e,t)=>{Ke.init(e,t),e._zod.parse=(n)=>n}),lg=H("$ZodNever",(e,t)=>{Ke.init(e,t),e._zod.parse=(n,o)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function Ch(e,t,n){if(e.issues.length)t.issues.push(...Mo(n,e.issues));t.value[n]=e.value}var ug=H("$ZodArray",(e,t)=>{Ke.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)=>Ch(u,n,a)));else Ch(l,n,a)}if(s.length)return Promise.all(s).then(()=>n);return n}});function ja(e,t,n,o,r){if(e.issues.length){if(r&&!(n in o))return;t.issues.push(...Mo(n,e.issues))}if(e.value===void 0){if(n in o)t.value[n]=void 0}else t.value[n]=e.value}function dg(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=_f(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function pg(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)=>ja(f,n,d,t,p)));else ja(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 G0=H("$ZodObject",(e,t)=>{if(Ke.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=ps(()=>dg(t));Be(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=Yr,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((w)=>ja(w,c,m,u,h)));else ja(v,c,m,u,h)}if(!s)return p.length?Promise.all(p).then(()=>c):c;return pg(p,u,c,l,o.value,e)}}),mg=H("$ZodObjectJIT",(e,t)=>{G0.init(e,t);let n=e._zod.parse,o=ps(()=>dg(t)),r=(m)=>{let f=new Mu(["shape","payload","ctx"]),h=o.value,v=(R)=>{let M=ku(R);return`shape[${M}]._zod.run({ value: input[${M}], issues: [] }, ctx)`};f.write("const input = payload.value;");let w=Object.create(null),g=0;for(let R of h.keys)w[R]=`key_${g++}`;f.write("const newResult = {};");for(let R of h.keys){let M=w[R],O=ku(R),N=m[R]?._zod?.optout==="optional";if(f.write(`const ${M} = ${v(R)};`),N)f.write(`
|
|
7531
7532
|
if (${M}.issues.length) {
|
|
@@ -7561,9 +7562,9 @@ ${l}${u}
|
|
|
7561
7562
|
newResult[${O}] = ${M}.value;
|
|
7562
7563
|
}
|
|
7563
7564
|
|
|
7564
|
-
`)}f.write("payload.value = newResult;"),f.write("return payload;");let x=f.compile();return(R,M)=>x(m,R,M)},s,a=Yr,c=!Pa.jitless,u=c&&wf.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 pg([],h,m,f,d,e)}return n(m,f)}});function Eh(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)=>!yr(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)=>Gn(a,o,_n())))}),t}var Lu=H("$ZodUnion",(e,t)=>{Ke.init(e,t),Be(e._zod,"optin",()=>t.options.some((r)=>r._zod.optin==="optional")?"optional":void 0),Be(e._zod,"optout",()=>t.options.some((r)=>r._zod.optout==="optional")?"optional":void 0),Be(e._zod,"values",()=>{if(t.options.every((r)=>r._zod.values))return new Set(t.options.flatMap((r)=>Array.from(r._zod.values)));return}),Be(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)=>Ma(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 Eh(c,r,e,s);return Promise.all(c).then((l)=>Eh(l,r,e,s))}});var fg=H("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Lu.init(e,t);let n=e._zod.parse;Be(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=ps(()=>{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(!Yr(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}}),hg=H("$ZodIntersection",(e,t)=>{Ke.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])=>Ih(n,l,u));return Ih(n,s,a)}});function $u(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(vr(e)&&vr(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=$u(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=$u(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 Ih(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(yr(e))return e;let a=$u(t.value,n.value);if(!a.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return e.value=a.data,e}var gg=H("$ZodRecord",(e,t)=>{Ke.init(e,t),e._zod.parse=(n,o)=>{let r=n.value;if(!vr(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(...Mo(u,d.issues));n.value[u]=d.value}));else{if(p.issues.length)n.issues.push(...Mo(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"&&Ru.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)=>Gn(d,o,_n())),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(...Mo(c,d.issues));n.value[l.value]=d.value}));else{if(p.issues.length)n.issues.push(...Mo(c,p.issues));n.value[l.value]=p.value}}}if(s.length)return Promise.all(s).then(()=>n);return n}});var vg=H("$ZodEnum",(e,t)=>{Ke.init(e,t);let n=Na(t.entries),o=new Set(n);e._zod.values=o,e._zod.pattern=new RegExp(`^(${n.filter((r)=>Sf.has(typeof r)).map((r)=>typeof r==="string"?zo(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}}),yg=H("$ZodLiteral",(e,t)=>{if(Ke.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"?zo(o):o?zo(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 bg=H("$ZodTransform",(e,t)=>{Ke.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new us(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 so;return n.value=r,n}});function Ah(e,t){if(e.issues.length&&t===void 0)return{issues:[],value:void 0};return e}var Du=H("$ZodOptional",(e,t)=>{Ke.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Be(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Be(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ma(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)=>Ah(s,n.value));return Ah(r,n.value)}if(n.value===void 0)return n;return t.innerType._zod.run(n,o)}}),xg=H("$ZodExactOptional",(e,t)=>{Du.init(e,t),Be(e._zod,"values",()=>t.innerType._zod.values),Be(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,o)=>t.innerType._zod.run(n,o)}),wg=H("$ZodNullable",(e,t)=>{Ke.init(e,t),Be(e._zod,"optin",()=>t.innerType._zod.optin),Be(e._zod,"optout",()=>t.innerType._zod.optout),Be(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ma(n.source)}|null)$`):void 0}),Be(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)}}),Sg=H("$ZodDefault",(e,t)=>{Ke.init(e,t),e._zod.optin="optional",Be(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)=>Ph(s,t));return Ph(r,t)}});function Ph(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var _g=H("$ZodPrefault",(e,t)=>{Ke.init(e,t),e._zod.optin="optional",Be(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)}}),kg=H("$ZodNonOptional",(e,t)=>{Ke.init(e,t),Be(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)=>Rh(s,e));return Rh(r,e)}});function Rh(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 Tg=H("$ZodCatch",(e,t)=>{Ke.init(e,t),Be(e._zod,"optin",()=>t.innerType._zod.optin),Be(e._zod,"optout",()=>t.innerType._zod.optout),Be(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)=>Gn(a,o,_n()))},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)=>Gn(s,o,_n()))},input:n.value}),n.issues=[];return n}});var Cg=H("$ZodPipe",(e,t)=>{Ke.init(e,t),Be(e._zod,"values",()=>t.in._zod.values),Be(e._zod,"optin",()=>t.in._zod.optin),Be(e._zod,"optout",()=>t.out._zod.optout),Be(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)=>Ba(a,t.in,o));return Ba(s,t.in,o)}let r=t.in._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>Ba(s,t.out,o));return Ba(r,t.out,o)}});function Ba(e,t,n){if(e.issues.length)return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},n)}var Eg=H("$ZodReadonly",(e,t)=>{Ke.init(e,t),Be(e._zod,"propValues",()=>t.innerType._zod.propValues),Be(e._zod,"values",()=>t.innerType._zod.values),Be(e._zod,"optin",()=>t.innerType?._zod?.optin),Be(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(Nh);return Nh(r)}});function Nh(e){return e.value=Object.freeze(e.value),e}var Ig=H("$ZodCustom",(e,t)=>{Pt.init(e,t),Ke.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)=>zh(s,n,o,e));zh(r,n,o,e);return}});function zh(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(br(r))}}var V0=()=>{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=Tf(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 ${Eu(r.values[0])}`;return`Invalid option: expected one of ${_u(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":""}: ${_u(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 Fu(){return{localeError:V0()}}var Ag,pM=Symbol("ZodOutput"),mM=Symbol("ZodInput");class Pg{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 X0(){return new Pg}(Ag=globalThis).__zod_globalRegistry??(Ag.__zod_globalRegistry=X0());var xr=globalThis.__zod_globalRegistry;function Rg(e,t){return new e({type:"string",...ee(t)})}function Ng(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...ee(t)})}function Hu(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...ee(t)})}function zg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...ee(t)})}function Mg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...ee(t)})}function $g(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...ee(t)})}function Og(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...ee(t)})}function Lg(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...ee(t)})}function Dg(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...ee(t)})}function Fg(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...ee(t)})}function Hg(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...ee(t)})}function Bg(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...ee(t)})}function jg(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...ee(t)})}function Ug(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...ee(t)})}function Zg(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...ee(t)})}function Wg(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...ee(t)})}function qg(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...ee(t)})}function Gg(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...ee(t)})}function Vg(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...ee(t)})}function Xg(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...ee(t)})}function Kg(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...ee(t)})}function Jg(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...ee(t)})}function Yg(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...ee(t)})}function Qg(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...ee(t)})}function ev(e,t){return new e({type:"string",format:"date",check:"string_format",...ee(t)})}function tv(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...ee(t)})}function nv(e,t){return new e({type:"string",format:"duration",check:"string_format",...ee(t)})}function ov(e,t){return new e({type:"number",checks:[],...ee(t)})}function rv(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...ee(t)})}function iv(e,t){return new e({type:"boolean",...ee(t)})}function sv(e,t){return new e({type:"undefined",...ee(t)})}function av(e,t){return new e({type:"null",...ee(t)})}function cv(e){return new e({type:"unknown"})}function lv(e,t){return new e({type:"never",...ee(t)})}function Za(e,t){return new Nu({check:"less_than",...ee(t),value:e,inclusive:!1})}function vs(e,t){return new Nu({check:"less_than",...ee(t),value:e,inclusive:!0})}function Wa(e,t){return new zu({check:"greater_than",...ee(t),value:e,inclusive:!1})}function ys(e,t){return new zu({check:"greater_than",...ee(t),value:e,inclusive:!0})}function qa(e,t){return new ph({check:"multiple_of",...ee(t),value:e})}function Ga(e,t){return new fh({check:"max_length",...ee(t),maximum:e})}function Qr(e,t){return new hh({check:"min_length",...ee(t),minimum:e})}function Va(e,t){return new gh({check:"length_equals",...ee(t),length:e})}function Bu(e,t){return new vh({check:"string_format",format:"regex",...ee(t),pattern:e})}function ju(e){return new yh({check:"string_format",format:"lowercase",...ee(e)})}function Uu(e){return new bh({check:"string_format",format:"uppercase",...ee(e)})}function Zu(e,t){return new xh({check:"string_format",format:"includes",...ee(t),includes:e})}function Wu(e,t){return new wh({check:"string_format",format:"starts_with",...ee(t),prefix:e})}function qu(e,t){return new Sh({check:"string_format",format:"ends_with",...ee(t),suffix:e})}function $o(e){return new _h({check:"overwrite",tx:e})}function Gu(e){return $o((t)=>t.normalize(e))}function Vu(){return $o((e)=>e.trim())}function Xu(){return $o((e)=>e.toLowerCase())}function Ku(){return $o((e)=>e.toUpperCase())}function Ju(){return $o((e)=>xf(e))}function uv(e,t,n){return new e({type:"array",element:t,...ee(n)})}function dv(e,t,n){let o=ee(n);return o.abort??(o.abort=!0),new e({type:"custom",check:"custom",fn:t,...o})}function pv(e,t,n){return new e({type:"custom",check:"custom",fn:t,...ee(n)})}function mv(e){let t=K0((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(br(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(br(r))}},e(n.value,n)));return t}function K0(e,t){let n=new Pt({check:"custom",...ee(t)});return n._zod.check=e,n}function Yu(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??xr,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 mt(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;mt(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"&&Jt(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 Qu(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>
|
|
7565
|
+
`)}f.write("payload.value = newResult;"),f.write("return payload;");let x=f.compile();return(R,M)=>x(m,R,M)},s,a=Yr,c=!Pa.jitless,u=c&&wf.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 pg([],h,m,f,d,e)}return n(m,f)}});function Eh(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)=>!yr(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)=>Gn(a,o,_n())))}),t}var Lu=H("$ZodUnion",(e,t)=>{Ke.init(e,t),Be(e._zod,"optin",()=>t.options.some((r)=>r._zod.optin==="optional")?"optional":void 0),Be(e._zod,"optout",()=>t.options.some((r)=>r._zod.optout==="optional")?"optional":void 0),Be(e._zod,"values",()=>{if(t.options.every((r)=>r._zod.values))return new Set(t.options.flatMap((r)=>Array.from(r._zod.values)));return}),Be(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)=>Ma(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 Eh(c,r,e,s);return Promise.all(c).then((l)=>Eh(l,r,e,s))}});var fg=H("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Lu.init(e,t);let n=e._zod.parse;Be(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=ps(()=>{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(!Yr(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}}),hg=H("$ZodIntersection",(e,t)=>{Ke.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])=>Ih(n,l,u));return Ih(n,s,a)}});function $u(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(vr(e)&&vr(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=$u(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=$u(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 Ih(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(yr(e))return e;let a=$u(t.value,n.value);if(!a.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return e.value=a.data,e}var gg=H("$ZodRecord",(e,t)=>{Ke.init(e,t),e._zod.parse=(n,o)=>{let r=n.value;if(!vr(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(...Mo(u,d.issues));n.value[u]=d.value}));else{if(p.issues.length)n.issues.push(...Mo(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"&&Ru.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)=>Gn(d,o,_n())),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(...Mo(c,d.issues));n.value[l.value]=d.value}));else{if(p.issues.length)n.issues.push(...Mo(c,p.issues));n.value[l.value]=p.value}}}if(s.length)return Promise.all(s).then(()=>n);return n}});var vg=H("$ZodEnum",(e,t)=>{Ke.init(e,t);let n=Na(t.entries),o=new Set(n);e._zod.values=o,e._zod.pattern=new RegExp(`^(${n.filter((r)=>Sf.has(typeof r)).map((r)=>typeof r==="string"?zo(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}}),yg=H("$ZodLiteral",(e,t)=>{if(Ke.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"?zo(o):o?zo(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 bg=H("$ZodTransform",(e,t)=>{Ke.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new us(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 so;return n.value=r,n}});function Ah(e,t){if(e.issues.length&&t===void 0)return{issues:[],value:void 0};return e}var Du=H("$ZodOptional",(e,t)=>{Ke.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Be(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Be(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ma(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)=>Ah(s,n.value));return Ah(r,n.value)}if(n.value===void 0)return n;return t.innerType._zod.run(n,o)}}),xg=H("$ZodExactOptional",(e,t)=>{Du.init(e,t),Be(e._zod,"values",()=>t.innerType._zod.values),Be(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,o)=>t.innerType._zod.run(n,o)}),wg=H("$ZodNullable",(e,t)=>{Ke.init(e,t),Be(e._zod,"optin",()=>t.innerType._zod.optin),Be(e._zod,"optout",()=>t.innerType._zod.optout),Be(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ma(n.source)}|null)$`):void 0}),Be(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)}}),Sg=H("$ZodDefault",(e,t)=>{Ke.init(e,t),e._zod.optin="optional",Be(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)=>Ph(s,t));return Ph(r,t)}});function Ph(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var _g=H("$ZodPrefault",(e,t)=>{Ke.init(e,t),e._zod.optin="optional",Be(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)}}),kg=H("$ZodNonOptional",(e,t)=>{Ke.init(e,t),Be(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)=>Rh(s,e));return Rh(r,e)}});function Rh(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 Tg=H("$ZodCatch",(e,t)=>{Ke.init(e,t),Be(e._zod,"optin",()=>t.innerType._zod.optin),Be(e._zod,"optout",()=>t.innerType._zod.optout),Be(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)=>Gn(a,o,_n()))},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)=>Gn(s,o,_n()))},input:n.value}),n.issues=[];return n}});var Cg=H("$ZodPipe",(e,t)=>{Ke.init(e,t),Be(e._zod,"values",()=>t.in._zod.values),Be(e._zod,"optin",()=>t.in._zod.optin),Be(e._zod,"optout",()=>t.out._zod.optout),Be(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)=>Ba(a,t.in,o));return Ba(s,t.in,o)}let r=t.in._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>Ba(s,t.out,o));return Ba(r,t.out,o)}});function Ba(e,t,n){if(e.issues.length)return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},n)}var Eg=H("$ZodReadonly",(e,t)=>{Ke.init(e,t),Be(e._zod,"propValues",()=>t.innerType._zod.propValues),Be(e._zod,"values",()=>t.innerType._zod.values),Be(e._zod,"optin",()=>t.innerType?._zod?.optin),Be(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(Nh);return Nh(r)}});function Nh(e){return e.value=Object.freeze(e.value),e}var Ig=H("$ZodCustom",(e,t)=>{Pt.init(e,t),Ke.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)=>zh(s,n,o,e));zh(r,n,o,e);return}});function zh(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(br(r))}}var V0=()=>{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=Tf(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 ${Eu(r.values[0])}`;return`Invalid option: expected one of ${_u(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":""}: ${_u(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 Fu(){return{localeError:V0()}}var Ag,mM=Symbol("ZodOutput"),fM=Symbol("ZodInput");class Pg{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 X0(){return new Pg}(Ag=globalThis).__zod_globalRegistry??(Ag.__zod_globalRegistry=X0());var xr=globalThis.__zod_globalRegistry;function Rg(e,t){return new e({type:"string",...ee(t)})}function Ng(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...ee(t)})}function Hu(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...ee(t)})}function zg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...ee(t)})}function Mg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...ee(t)})}function $g(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...ee(t)})}function Og(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...ee(t)})}function Lg(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...ee(t)})}function Dg(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...ee(t)})}function Fg(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...ee(t)})}function Hg(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...ee(t)})}function Bg(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...ee(t)})}function jg(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...ee(t)})}function Ug(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...ee(t)})}function Zg(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...ee(t)})}function Wg(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...ee(t)})}function qg(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...ee(t)})}function Gg(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...ee(t)})}function Vg(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...ee(t)})}function Xg(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...ee(t)})}function Kg(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...ee(t)})}function Jg(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...ee(t)})}function Yg(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...ee(t)})}function Qg(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...ee(t)})}function ev(e,t){return new e({type:"string",format:"date",check:"string_format",...ee(t)})}function tv(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...ee(t)})}function nv(e,t){return new e({type:"string",format:"duration",check:"string_format",...ee(t)})}function ov(e,t){return new e({type:"number",checks:[],...ee(t)})}function rv(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...ee(t)})}function iv(e,t){return new e({type:"boolean",...ee(t)})}function sv(e,t){return new e({type:"undefined",...ee(t)})}function av(e,t){return new e({type:"null",...ee(t)})}function cv(e){return new e({type:"unknown"})}function lv(e,t){return new e({type:"never",...ee(t)})}function Za(e,t){return new Nu({check:"less_than",...ee(t),value:e,inclusive:!1})}function vs(e,t){return new Nu({check:"less_than",...ee(t),value:e,inclusive:!0})}function Wa(e,t){return new zu({check:"greater_than",...ee(t),value:e,inclusive:!1})}function ys(e,t){return new zu({check:"greater_than",...ee(t),value:e,inclusive:!0})}function qa(e,t){return new ph({check:"multiple_of",...ee(t),value:e})}function Ga(e,t){return new fh({check:"max_length",...ee(t),maximum:e})}function Qr(e,t){return new hh({check:"min_length",...ee(t),minimum:e})}function Va(e,t){return new gh({check:"length_equals",...ee(t),length:e})}function Bu(e,t){return new vh({check:"string_format",format:"regex",...ee(t),pattern:e})}function ju(e){return new yh({check:"string_format",format:"lowercase",...ee(e)})}function Uu(e){return new bh({check:"string_format",format:"uppercase",...ee(e)})}function Zu(e,t){return new xh({check:"string_format",format:"includes",...ee(t),includes:e})}function Wu(e,t){return new wh({check:"string_format",format:"starts_with",...ee(t),prefix:e})}function qu(e,t){return new Sh({check:"string_format",format:"ends_with",...ee(t),suffix:e})}function $o(e){return new _h({check:"overwrite",tx:e})}function Gu(e){return $o((t)=>t.normalize(e))}function Vu(){return $o((e)=>e.trim())}function Xu(){return $o((e)=>e.toLowerCase())}function Ku(){return $o((e)=>e.toUpperCase())}function Ju(){return $o((e)=>xf(e))}function uv(e,t,n){return new e({type:"array",element:t,...ee(n)})}function dv(e,t,n){let o=ee(n);return o.abort??(o.abort=!0),new e({type:"custom",check:"custom",fn:t,...o})}function pv(e,t,n){return new e({type:"custom",check:"custom",fn:t,...ee(n)})}function mv(e){let t=K0((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(br(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(br(r))}},e(n.value,n)));return t}function K0(e,t){let n=new Pt({check:"custom",...ee(t)});return n._zod.check=e,n}function Yu(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??xr,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 mt(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;mt(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"&&Jt(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 Qu(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>
|
|
7565
7566
|
|
|
7566
|
-
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 ed(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:bs(t,"input",e.processors),output:bs(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function Jt(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 Jt(o.element,n);if(o.type==="set")return Jt(o.valueType,n);if(o.type==="lazy")return Jt(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 Jt(o.innerType,n);if(o.type==="intersection")return Jt(o.left,n)||Jt(o.right,n);if(o.type==="record"||o.type==="map")return Jt(o.keyType,n)||Jt(o.valueType,n);if(o.type==="pipe")return Jt(o.in,n)||Jt(o.out,n);if(o.type==="object"){for(let r in o.shape)if(Jt(o.shape[r],n))return!0;return!1}if(o.type==="union"){for(let r of o.options)if(Jt(r,n))return!0;return!1}if(o.type==="tuple"){for(let r of o.items)if(Jt(r,n))return!0;if(o.rest&&Jt(o.rest,n))return!0;return!1}return!1}var fv=(e,t={})=>(n)=>{let o=Yu({...n,processors:t});return mt(e,o),Qu(o,e),ed(o,e)},bs=(e,t,n={})=>(o)=>{let{libraryOptions:r,target:s}=o??{},a=Yu({...r??{},target:s,io:t,processors:n});return mt(e,a),Qu(a,e),ed(a,e)};var J0={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},hv=(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=J0[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}))]}},gv=(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},vv=(e,t,n,o)=>{n.type="boolean"};var yv=(e,t,n,o)=>{if(t.target==="openapi-3.0")n.type="string",n.nullable=!0,n.enum=[null];else n.type="null"},bv=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Undefined cannot be represented in JSON Schema")};var xv=(e,t,n,o)=>{n.not={}};var wv=(e,t,n,o)=>{};var Sv=(e,t,n,o)=>{let r=e._zod.def,s=Na(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},_v=(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 kv=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Custom types cannot be represented in JSON Schema")};var Tv=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Transforms cannot be represented in JSON Schema")};var Cv=(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=mt(s.element,t,{...o,path:[...o.path,"items"]})},Ev=(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]=mt(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=mt(s.catchall,t,{...o,path:[...o.path,"additionalProperties"]})},Iv=(e,t,n,o)=>{let r=e._zod.def,s=r.inclusive===!1,a=r.options.map((c,l)=>mt(c,t,{...o,path:[...o.path,s?"oneOf":"anyOf",l]}));if(s)n.oneOf=a;else n.anyOf=a},Av=(e,t,n,o)=>{let r=e._zod.def,s=mt(r.left,t,{...o,path:[...o.path,"allOf",0]}),a=mt(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 Pv=(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=mt(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=mt(s.keyType,t,{...o,path:[...o.path,"propertyNames"]});r.additionalProperties=mt(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}},Rv=(e,t,n,o)=>{let r=e._zod.def,s=mt(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"}]},Nv=(e,t,n,o)=>{let r=e._zod.def;mt(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType},zv=(e,t,n,o)=>{let r=e._zod.def;mt(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.default=JSON.parse(JSON.stringify(r.defaultValue))},Mv=(e,t,n,o)=>{let r=e._zod.def;mt(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))},$v=(e,t,n,o)=>{let r=e._zod.def;mt(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},Ov=(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;mt(s,t,o);let a=t.seen.get(e);a.ref=s},Lv=(e,t,n,o)=>{let r=e._zod.def;mt(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.readOnly=!0};var td=(e,t,n,o)=>{let r=e._zod.def;mt(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType};function Xa(e){return!!e._zod}function Ka(e,t){if(Xa(e))return fs(e,t);return e.safeParse(t)}function Dv(e){if(!e)return;let t;if(Xa(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 Fv(e){if(Xa(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}var iT=H("ZodISODateTime",(e,t)=>{Wh.init(e,t),nt.init(e,t)});function nd(e){return Qg(iT,e)}var sT=H("ZodISODate",(e,t)=>{qh.init(e,t),nt.init(e,t)});function Hv(e){return ev(sT,e)}var aT=H("ZodISOTime",(e,t)=>{Gh.init(e,t),nt.init(e,t)});function Bv(e){return tv(aT,e)}var cT=H("ZodISODuration",(e,t)=>{Vh.init(e,t),nt.init(e,t)});function jv(e){return nv(cT,e)}var Uv=(e,t)=>{Oa.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:(n)=>If(e,n)},flatten:{value:(n)=>Ef(e,n)},addIssue:{value:(n)=>{e.issues.push(n),e.message=JSON.stringify(e.issues,ds,2)}},addIssues:{value:(n)=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,ds,2)}},isEmpty:{get(){return e.issues.length===0}}})},n$=H("ZodError",Uv),dn=H("ZodError",Uv,{Parent:Error});var Zv=La(dn),Wv=Da(dn),qv=ms(dn),Gv=hs(dn),Vv=Af(dn),Xv=Pf(dn),Kv=Rf(dn),Jv=Nf(dn),Yv=zf(dn),Qv=Mf(dn),ey=$f(dn),ty=Of(dn);var tt=H("ZodType",(e,t)=>(Ke.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:bs(e,"input"),output:bs(e,"output")}}),e.toJSONSchema=fv(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(No(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)=>qn(e,n,o),e.brand=()=>e,e.register=(n,o)=>(n.add(e,o),e),e.parse=(n,o)=>Zv(e,n,o,{callee:e.parse}),e.safeParse=(n,o)=>qv(e,n,o),e.parseAsync=async(n,o)=>Wv(e,n,o,{callee:e.parseAsync}),e.safeParseAsync=async(n,o)=>Gv(e,n,o),e.spa=e.safeParseAsync,e.encode=(n,o)=>Vv(e,n,o),e.decode=(n,o)=>Xv(e,n,o),e.encodeAsync=async(n,o)=>Kv(e,n,o),e.decodeAsync=async(n,o)=>Jv(e,n,o),e.safeEncode=(n,o)=>Yv(e,n,o),e.safeDecode=(n,o)=>Qv(e,n,o),e.safeEncodeAsync=async(n,o)=>ey(e,n,o),e.safeDecodeAsync=async(n,o)=>ty(e,n,o),e.refine=(n,o)=>e.check(eC(n,o)),e.superRefine=(n)=>e.check(tC(n)),e.overwrite=(n)=>e.check($o(n)),e.optional=()=>at(e),e.exactOptional=()=>jT(e),e.nullable=()=>ry(e),e.nullish=()=>at(ry(e)),e.nonoptional=(n)=>VT(e,n),e.array=()=>te(e),e.or=(n)=>he([e,n]),e.and=(n)=>Ya(e,n),e.transform=(n)=>id(e,uy(n)),e.default=(n)=>WT(e,n),e.prefault=(n)=>GT(e,n),e.catch=(n)=>KT(e,n),e.pipe=(n)=>id(e,n),e.readonly=()=>QT(e),e.describe=(n)=>{let o=e.clone();return xr.add(o,{description:n}),o},Object.defineProperty(e,"description",{get(){return xr.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return xr.get(e);let o=e.clone();return xr.add(o,n[0]),o},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=(n)=>n(e),e)),iy=H("_ZodString",(e,t)=>{Ua.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(o,r,s)=>hv(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(Bu(...o)),e.includes=(...o)=>e.check(Zu(...o)),e.startsWith=(...o)=>e.check(Wu(...o)),e.endsWith=(...o)=>e.check(qu(...o)),e.min=(...o)=>e.check(Qr(...o)),e.max=(...o)=>e.check(Ga(...o)),e.length=(...o)=>e.check(Va(...o)),e.nonempty=(...o)=>e.check(Qr(1,...o)),e.lowercase=(o)=>e.check(ju(o)),e.uppercase=(o)=>e.check(Uu(o)),e.trim=()=>e.check(Vu()),e.normalize=(...o)=>e.check(Gu(...o)),e.toLowerCase=()=>e.check(Xu()),e.toUpperCase=()=>e.check(Ku()),e.slugify=()=>e.check(Ju())}),dT=H("ZodString",(e,t)=>{Ua.init(e,t),iy.init(e,t),e.email=(n)=>e.check(Ng(pT,n)),e.url=(n)=>e.check(Lg(mT,n)),e.jwt=(n)=>e.check(Yg(IT,n)),e.emoji=(n)=>e.check(Dg(fT,n)),e.guid=(n)=>e.check(Hu(ny,n)),e.uuid=(n)=>e.check(zg(Ja,n)),e.uuidv4=(n)=>e.check(Mg(Ja,n)),e.uuidv6=(n)=>e.check($g(Ja,n)),e.uuidv7=(n)=>e.check(Og(Ja,n)),e.nanoid=(n)=>e.check(Fg(hT,n)),e.guid=(n)=>e.check(Hu(ny,n)),e.cuid=(n)=>e.check(Hg(gT,n)),e.cuid2=(n)=>e.check(Bg(vT,n)),e.ulid=(n)=>e.check(jg(yT,n)),e.base64=(n)=>e.check(Xg(TT,n)),e.base64url=(n)=>e.check(Kg(CT,n)),e.xid=(n)=>e.check(Ug(bT,n)),e.ksuid=(n)=>e.check(Zg(xT,n)),e.ipv4=(n)=>e.check(Wg(wT,n)),e.ipv6=(n)=>e.check(qg(ST,n)),e.cidrv4=(n)=>e.check(Gg(_T,n)),e.cidrv6=(n)=>e.check(Vg(kT,n)),e.e164=(n)=>e.check(Jg(ET,n)),e.datetime=(n)=>e.check(nd(n)),e.date=(n)=>e.check(Hv(n)),e.time=(n)=>e.check(Bv(n)),e.duration=(n)=>e.check(jv(n))});function C(e){return Rg(dT,e)}var nt=H("ZodStringFormat",(e,t)=>{et.init(e,t),iy.init(e,t)}),pT=H("ZodEmail",(e,t)=>{Oh.init(e,t),nt.init(e,t)});var ny=H("ZodGUID",(e,t)=>{Mh.init(e,t),nt.init(e,t)});var Ja=H("ZodUUID",(e,t)=>{$h.init(e,t),nt.init(e,t)});var mT=H("ZodURL",(e,t)=>{Lh.init(e,t),nt.init(e,t)});var fT=H("ZodEmoji",(e,t)=>{Dh.init(e,t),nt.init(e,t)});var hT=H("ZodNanoID",(e,t)=>{Fh.init(e,t),nt.init(e,t)});var gT=H("ZodCUID",(e,t)=>{Hh.init(e,t),nt.init(e,t)});var vT=H("ZodCUID2",(e,t)=>{Bh.init(e,t),nt.init(e,t)});var yT=H("ZodULID",(e,t)=>{jh.init(e,t),nt.init(e,t)});var bT=H("ZodXID",(e,t)=>{Uh.init(e,t),nt.init(e,t)});var xT=H("ZodKSUID",(e,t)=>{Zh.init(e,t),nt.init(e,t)});var wT=H("ZodIPv4",(e,t)=>{Xh.init(e,t),nt.init(e,t)});var ST=H("ZodIPv6",(e,t)=>{Kh.init(e,t),nt.init(e,t)});var _T=H("ZodCIDRv4",(e,t)=>{Jh.init(e,t),nt.init(e,t)});var kT=H("ZodCIDRv6",(e,t)=>{Yh.init(e,t),nt.init(e,t)});var TT=H("ZodBase64",(e,t)=>{eg.init(e,t),nt.init(e,t)});var CT=H("ZodBase64URL",(e,t)=>{tg.init(e,t),nt.init(e,t)});var ET=H("ZodE164",(e,t)=>{ng.init(e,t),nt.init(e,t)});var IT=H("ZodJWT",(e,t)=>{og.init(e,t),nt.init(e,t)});var sy=H("ZodNumber",(e,t)=>{Ou.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(o,r,s)=>gv(e,o,r,s),e.gt=(o,r)=>e.check(Wa(o,r)),e.gte=(o,r)=>e.check(ys(o,r)),e.min=(o,r)=>e.check(ys(o,r)),e.lt=(o,r)=>e.check(Za(o,r)),e.lte=(o,r)=>e.check(vs(o,r)),e.max=(o,r)=>e.check(vs(o,r)),e.int=(o)=>e.check(oy(o)),e.safe=(o)=>e.check(oy(o)),e.positive=(o)=>e.check(Wa(0,o)),e.nonnegative=(o)=>e.check(ys(0,o)),e.negative=(o)=>e.check(Za(0,o)),e.nonpositive=(o)=>e.check(vs(0,o)),e.multipleOf=(o,r)=>e.check(qa(o,r)),e.step=(o,r)=>e.check(qa(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 ne(e){return ov(sy,e)}var AT=H("ZodNumberFormat",(e,t)=>{rg.init(e,t),sy.init(e,t)});function oy(e){return rv(AT,e)}var PT=H("ZodBoolean",(e,t)=>{ig.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>vv(e,n,o,r)});function Re(e){return iv(PT,e)}var RT=H("ZodUndefined",(e,t)=>{sg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>bv(e,n,o,r)});function ei(e){return sv(RT,e)}var NT=H("ZodNull",(e,t)=>{ag.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>yv(e,n,o,r)});function sd(e){return av(NT,e)}var zT=H("ZodUnknown",(e,t)=>{cg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>wv(e,n,o,r)});function He(){return cv(zT)}var MT=H("ZodNever",(e,t)=>{lg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>xv(e,n,o,r)});function ay(e){return lv(MT,e)}var $T=H("ZodArray",(e,t)=>{ug.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Cv(e,n,o,r),e.element=t.element,e.min=(n,o)=>e.check(Qr(n,o)),e.nonempty=(n)=>e.check(Qr(1,n)),e.max=(n,o)=>e.check(Ga(n,o)),e.length=(n,o)=>e.check(Va(n,o)),e.unwrap=()=>e.element});function te(e,t){return uv($T,e,t)}var ad=H("ZodObject",(e,t)=>{mg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ev(e,n,o,r),Be(e,"shape",()=>t.shape),e.keyof=()=>jt(Object.keys(e._zod.def.shape)),e.catchall=(n)=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:He()}),e.loose=()=>e.clone({...e._zod.def,catchall:He()}),e.strict=()=>e.clone({...e._zod.def,catchall:ay()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=(n)=>O0(e,n),e.safeExtend=(n)=>L0(e,n),e.merge=(n)=>D0(e,n),e.pick=(n)=>M0(e,n),e.omit=(n)=>$0(e,n),e.partial=(...n)=>F0(dy,e,n[0]),e.required=(...n)=>H0(py,e,n[0])});function S(e,t){let n={type:"object",shape:e??{},...ee(t)};return new ad(n)}function cy(e,t){return new ad({type:"object",shape:e,catchall:ay(),...ee(t)})}function Yt(e,t){return new ad({type:"object",shape:e,catchall:He(),...ee(t)})}var ly=H("ZodUnion",(e,t)=>{Lu.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Iv(e,n,o,r),e.options=t.options});function he(e,t){return new ly({type:"union",options:e,...ee(t)})}var OT=H("ZodDiscriminatedUnion",(e,t)=>{ly.init(e,t),fg.init(e,t)});function cd(e,t,n){return new OT({type:"union",options:t,discriminator:e,...ee(n)})}var LT=H("ZodIntersection",(e,t)=>{hg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Av(e,n,o,r)});function Ya(e,t){return new LT({type:"intersection",left:e,right:t})}var DT=H("ZodRecord",(e,t)=>{gg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Pv(e,n,o,r),e.keyType=t.keyType,e.valueType=t.valueType});function $e(e,t,n){return new DT({type:"record",keyType:e,valueType:t,...ee(n)})}var rd=H("ZodEnum",(e,t)=>{vg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(o,r,s)=>Sv(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 rd({...t,checks:[],...ee(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 rd({...t,checks:[],...ee(r),entries:s})}});function jt(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map((o)=>[o,o])):e;return new rd({type:"enum",entries:n,...ee(t)})}var FT=H("ZodLiteral",(e,t)=>{yg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>_v(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 b(e,t){return new FT({type:"literal",values:Array.isArray(e)?e:[e],...ee(t)})}var HT=H("ZodTransform",(e,t)=>{bg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Tv(e,n,o,r),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new us(e.constructor.name);n.addIssue=(s)=>{if(typeof s==="string")n.issues.push(br(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(br(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 uy(e){return new HT({type:"transform",transform:e})}var dy=H("ZodOptional",(e,t)=>{Du.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>td(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function at(e){return new dy({type:"optional",innerType:e})}var BT=H("ZodExactOptional",(e,t)=>{xg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>td(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function jT(e){return new BT({type:"optional",innerType:e})}var UT=H("ZodNullable",(e,t)=>{wg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Rv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function ry(e){return new UT({type:"nullable",innerType:e})}var ZT=H("ZodDefault",(e,t)=>{Sg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>zv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function WT(e,t){return new ZT({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():Cu(t)}})}var qT=H("ZodPrefault",(e,t)=>{_g.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Mv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function GT(e,t){return new qT({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():Cu(t)}})}var py=H("ZodNonOptional",(e,t)=>{kg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Nv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function VT(e,t){return new py({type:"nonoptional",innerType:e,...ee(t)})}var XT=H("ZodCatch",(e,t)=>{Tg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>$v(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function KT(e,t){return new XT({type:"catch",innerType:e,catchValue:typeof t==="function"?t:()=>t})}var JT=H("ZodPipe",(e,t)=>{Cg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ov(e,n,o,r),e.in=t.in,e.out=t.out});function id(e,t){return new JT({type:"pipe",in:e,out:t})}var YT=H("ZodReadonly",(e,t)=>{Eg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Lv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function QT(e){return new YT({type:"readonly",innerType:e})}var my=H("ZodCustom",(e,t)=>{Ig.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>kv(e,n,o,r)});function fy(e,t){return dv(my,e??(()=>!0),t)}function eC(e,t={}){return pv(my,e,t)}function tC(e){return mv(e)}function ld(e,t){return id(uy(e),t)}_n(Fu());var Oo="io.modelcontextprotocol/related-task",ec="2.0",Rt=fy((e)=>e!==null&&(typeof e==="object"||typeof e==="function")),hy=he([C(),ne().int()]),gy=C(),vO=Yt({ttl:he([ne(),sd()]).optional(),pollInterval:ne().optional()}),nC=S({ttl:ne().optional()}),oC=S({taskId:C()}),ud=Yt({progressToken:hy.optional(),[Oo]:oC.optional()}),pn=S({_meta:ud.optional()}),ws=pn.extend({task:nC.optional()}),vy=(e)=>ws.safeParse(e).success,Nt=S({method:C(),params:pn.loose().optional()}),kn=S({_meta:ud.optional()}),Tn=S({method:C(),params:kn.loose().optional()}),zt=Yt({_meta:ud.optional()}),Lo=he([C(),ne().int()]),yy=S({jsonrpc:b(ec),id:Lo,...Nt.shape}).strict(),dd=(e)=>yy.safeParse(e).success,by=S({jsonrpc:b(ec),...Tn.shape}).strict(),xy=(e)=>by.safeParse(e).success,pd=S({jsonrpc:b(ec),id:Lo,result:zt}).strict(),Ss=(e)=>pd.safeParse(e).success;var Ue;(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"})(Ue||(Ue={}));var md=S({jsonrpc:b(ec),id:Lo.optional(),error:S({code:ne().int(),message:C(),data:He().optional()})}).strict();var wy=(e)=>md.safeParse(e).success;var tc=he([yy,by,pd,md]),yO=he([pd,md]),_s=zt.strict(),rC=kn.extend({requestId:Lo.optional(),reason:C().optional()}),nc=Tn.extend({method:b("notifications/cancelled"),params:rC}),iC=S({src:C(),mimeType:C().optional(),sizes:te(C()).optional(),theme:jt(["light","dark"]).optional()}),ks=S({icons:te(iC).optional()}),ti=S({name:C(),title:C().optional()}),Do=ti.extend({...ti.shape,...ks.shape,version:C(),websiteUrl:C().optional(),description:C().optional()}),sC=Ya(S({applyDefaults:Re().optional()}),$e(C(),He())),aC=ld((e)=>{if(e&&typeof e==="object"&&!Array.isArray(e)){if(Object.keys(e).length===0)return{form:{}}}return e},Ya(S({form:sC.optional(),url:Rt.optional()}),$e(C(),He()).optional())),cC=Yt({list:Rt.optional(),cancel:Rt.optional(),requests:Yt({sampling:Yt({createMessage:Rt.optional()}).optional(),elicitation:Yt({create:Rt.optional()}).optional()}).optional()}),lC=Yt({list:Rt.optional(),cancel:Rt.optional(),requests:Yt({tools:Yt({call:Rt.optional()}).optional()}).optional()}),uC=S({experimental:$e(C(),Rt).optional(),sampling:S({context:Rt.optional(),tools:Rt.optional()}).optional(),elicitation:aC.optional(),roots:S({listChanged:Re().optional()}).optional(),tasks:cC.optional()}),dC=pn.extend({protocolVersion:C(),capabilities:uC,clientInfo:Do}),pC=Nt.extend({method:b("initialize"),params:dC});var mC=S({experimental:$e(C(),Rt).optional(),logging:Rt.optional(),completions:Rt.optional(),prompts:S({listChanged:Re().optional()}).optional(),resources:S({subscribe:Re().optional(),listChanged:Re().optional()}).optional(),tools:S({listChanged:Re().optional()}).optional(),tasks:lC.optional()}),fC=zt.extend({protocolVersion:C(),capabilities:mC,serverInfo:Do,instructions:C().optional()}),hC=Tn.extend({method:b("notifications/initialized"),params:kn.optional()});var co=Nt.extend({method:b("ping"),params:pn.optional()}),gC=S({progress:ne(),total:at(ne()),message:at(C())}),vC=S({...kn.shape,...gC.shape,progressToken:hy}),oc=Tn.extend({method:b("notifications/progress"),params:vC}),yC=pn.extend({cursor:gy.optional()}),Ts=Nt.extend({params:yC.optional()}),Cs=zt.extend({nextCursor:gy.optional()}),bC=jt(["working","input_required","completed","failed","cancelled"]),Es=S({taskId:C(),status:bC,ttl:he([ne(),sd()]),createdAt:C(),lastUpdatedAt:C(),pollInterval:at(ne()),statusMessage:at(C())}),rc=zt.extend({task:Es}),xC=kn.merge(Es),Is=Tn.extend({method:b("notifications/tasks/status"),params:xC}),ic=Nt.extend({method:b("tasks/get"),params:pn.extend({taskId:C()})}),sc=zt.merge(Es),ac=Nt.extend({method:b("tasks/result"),params:pn.extend({taskId:C()})}),bO=zt.loose(),cc=Ts.extend({method:b("tasks/list")}),lc=Cs.extend({tasks:te(Es)}),uc=Nt.extend({method:b("tasks/cancel"),params:pn.extend({taskId:C()})}),Sy=zt.merge(Es),_y=S({uri:C(),mimeType:at(C()),_meta:$e(C(),He()).optional()}),ky=_y.extend({text:C()}),fd=C().refine((e)=>{try{return atob(e),!0}catch{return!1}},{message:"Invalid Base64 string"}),Ty=_y.extend({blob:fd}),As=jt(["user","assistant"]),ni=S({audience:te(As).optional(),priority:ne().min(0).max(1).optional(),lastModified:nd({offset:!0}).optional()}),Cy=S({...ti.shape,...ks.shape,uri:C(),description:at(C()),mimeType:at(C()),annotations:ni.optional(),_meta:at(Yt({}))}),wC=S({...ti.shape,...ks.shape,uriTemplate:C(),description:at(C()),mimeType:at(C()),annotations:ni.optional(),_meta:at(Yt({}))}),hd=Ts.extend({method:b("resources/list")}),oi=Cs.extend({resources:te(Cy)}),gd=Ts.extend({method:b("resources/templates/list")}),vd=Cs.extend({resourceTemplates:te(wC)}),yd=pn.extend({uri:C()}),SC=yd,bd=Nt.extend({method:b("resources/read"),params:SC}),ri=zt.extend({contents:te(he([ky,Ty]))}),xd=Tn.extend({method:b("notifications/resources/list_changed"),params:kn.optional()}),_C=yd,kC=Nt.extend({method:b("resources/subscribe"),params:_C}),TC=yd,CC=Nt.extend({method:b("resources/unsubscribe"),params:TC}),EC=kn.extend({uri:C()}),IC=Tn.extend({method:b("notifications/resources/updated"),params:EC}),AC=S({name:C(),description:at(C()),required:at(Re())}),PC=S({...ti.shape,...ks.shape,description:at(C()),arguments:at(te(AC)),_meta:at(Yt({}))}),wd=Ts.extend({method:b("prompts/list")}),Sd=Cs.extend({prompts:te(PC)}),RC=pn.extend({name:C(),arguments:$e(C(),C()).optional()}),NC=Nt.extend({method:b("prompts/get"),params:RC}),_d=S({type:b("text"),text:C(),annotations:ni.optional(),_meta:$e(C(),He()).optional()}),kd=S({type:b("image"),data:fd,mimeType:C(),annotations:ni.optional(),_meta:$e(C(),He()).optional()}),Td=S({type:b("audio"),data:fd,mimeType:C(),annotations:ni.optional(),_meta:$e(C(),He()).optional()}),zC=S({type:b("tool_use"),name:C(),id:C(),input:$e(C(),He()),_meta:$e(C(),He()).optional()}),Ps=S({type:b("resource"),resource:he([ky,Ty]),annotations:ni.optional(),_meta:$e(C(),He()).optional()}),Rs=Cy.extend({type:b("resource_link")}),lo=he([_d,kd,Td,Rs,Ps]),MC=S({role:As,content:lo}),$C=zt.extend({description:C().optional(),messages:te(MC)}),Cd=Tn.extend({method:b("notifications/prompts/list_changed"),params:kn.optional()}),OC=S({title:C().optional(),readOnlyHint:Re().optional(),destructiveHint:Re().optional(),idempotentHint:Re().optional(),openWorldHint:Re().optional()}),LC=S({taskSupport:jt(["required","optional","forbidden"]).optional()}),ii=S({...ti.shape,...ks.shape,description:C().optional(),inputSchema:S({type:b("object"),properties:$e(C(),Rt).optional(),required:te(C()).optional()}).catchall(He()),outputSchema:S({type:b("object"),properties:$e(C(),Rt).optional(),required:te(C()).optional()}).catchall(He()).optional(),annotations:OC.optional(),execution:LC.optional(),_meta:$e(C(),He()).optional()}),si=Ts.extend({method:b("tools/list")}),DC=Cs.extend({tools:te(ii)}),Mn=zt.extend({content:te(lo).default([]),structuredContent:$e(C(),He()).optional(),isError:Re().optional()}),xO=Mn.or(zt.extend({toolResult:He()})),FC=ws.extend({name:C(),arguments:$e(C(),He()).optional()}),ai=Nt.extend({method:b("tools/call"),params:FC}),Ed=Tn.extend({method:b("notifications/tools/list_changed"),params:kn.optional()}),wO=S({autoRefresh:Re().default(!0),debounceMs:ne().int().nonnegative().default(300)}),Ey=jt(["debug","info","notice","warning","error","critical","alert","emergency"]),HC=pn.extend({level:Ey}),BC=Nt.extend({method:b("logging/setLevel"),params:HC}),jC=kn.extend({level:Ey,logger:C().optional(),data:He()}),Id=Tn.extend({method:b("notifications/message"),params:jC}),UC=S({name:C().optional()}),ZC=S({hints:te(UC).optional(),costPriority:ne().min(0).max(1).optional(),speedPriority:ne().min(0).max(1).optional(),intelligencePriority:ne().min(0).max(1).optional()}),WC=S({mode:jt(["auto","required","none"]).optional()}),qC=S({type:b("tool_result"),toolUseId:C().describe("The unique identifier for the corresponding tool call."),content:te(lo).default([]),structuredContent:S({}).loose().optional(),isError:Re().optional(),_meta:$e(C(),He()).optional()}),GC=cd("type",[_d,kd,Td]),Qa=cd("type",[_d,kd,Td,zC,qC]),VC=S({role:As,content:he([Qa,te(Qa)]),_meta:$e(C(),He()).optional()}),XC=ws.extend({messages:te(VC),modelPreferences:ZC.optional(),systemPrompt:C().optional(),includeContext:jt(["none","thisServer","allServers"]).optional(),temperature:ne().optional(),maxTokens:ne().int(),stopSequences:te(C()).optional(),metadata:Rt.optional(),tools:te(ii).optional(),toolChoice:WC.optional()}),KC=Nt.extend({method:b("sampling/createMessage"),params:XC}),JC=zt.extend({model:C(),stopReason:at(jt(["endTurn","stopSequence","maxTokens"]).or(C())),role:As,content:GC}),YC=zt.extend({model:C(),stopReason:at(jt(["endTurn","stopSequence","maxTokens","toolUse"]).or(C())),role:As,content:he([Qa,te(Qa)])}),QC=S({type:b("boolean"),title:C().optional(),description:C().optional(),default:Re().optional()}),eE=S({type:b("string"),title:C().optional(),description:C().optional(),minLength:ne().optional(),maxLength:ne().optional(),format:jt(["email","uri","date","date-time"]).optional(),default:C().optional()}),tE=S({type:jt(["number","integer"]),title:C().optional(),description:C().optional(),minimum:ne().optional(),maximum:ne().optional(),default:ne().optional()}),nE=S({type:b("string"),title:C().optional(),description:C().optional(),enum:te(C()),default:C().optional()}),oE=S({type:b("string"),title:C().optional(),description:C().optional(),oneOf:te(S({const:C(),title:C()})),default:C().optional()}),rE=S({type:b("string"),title:C().optional(),description:C().optional(),enum:te(C()),enumNames:te(C()).optional(),default:C().optional()}),iE=he([nE,oE]),sE=S({type:b("array"),title:C().optional(),description:C().optional(),minItems:ne().optional(),maxItems:ne().optional(),items:S({type:b("string"),enum:te(C())}),default:te(C()).optional()}),aE=S({type:b("array"),title:C().optional(),description:C().optional(),minItems:ne().optional(),maxItems:ne().optional(),items:S({anyOf:te(S({const:C(),title:C()}))}),default:te(C()).optional()}),cE=he([sE,aE]),lE=he([rE,iE,cE]),uE=he([lE,QC,eE,tE]),dE=ws.extend({mode:b("form").optional(),message:C(),requestedSchema:S({type:b("object"),properties:$e(C(),uE),required:te(C()).optional()})}),pE=ws.extend({mode:b("url"),message:C(),elicitationId:C(),url:C().url()}),mE=he([dE,pE]),fE=Nt.extend({method:b("elicitation/create"),params:mE}),hE=kn.extend({elicitationId:C()}),gE=Tn.extend({method:b("notifications/elicitation/complete"),params:hE}),vE=zt.extend({action:jt(["accept","decline","cancel"]),content:ld((e)=>e===null?void 0:e,$e(C(),he([C(),ne(),Re(),te(C())])).optional())}),yE=S({type:b("ref/resource"),uri:C()});var bE=S({type:b("ref/prompt"),name:C()}),xE=pn.extend({ref:he([bE,yE]),argument:S({name:C(),value:C()}),context:S({arguments:$e(C(),C()).optional()}).optional()}),wE=Nt.extend({method:b("completion/complete"),params:xE});var SE=zt.extend({completion:Yt({values:te(C()).max(100),total:at(ne().int()),hasMore:at(Re())})}),_E=S({uri:C().startsWith("file://"),name:C().optional(),_meta:$e(C(),He()).optional()}),kE=Nt.extend({method:b("roots/list"),params:pn.optional()}),TE=zt.extend({roots:te(_E)}),CE=Tn.extend({method:b("notifications/roots/list_changed"),params:kn.optional()}),SO=he([co,pC,wE,BC,NC,wd,hd,gd,bd,kC,CC,ai,si,ic,ac,cc,uc]),_O=he([nc,oc,hC,CE,Is]),kO=he([_s,JC,YC,vE,TE,sc,lc,rc]),TO=he([co,KC,fE,kE,ic,ac,cc,uc]),CO=he([nc,oc,Id,IC,xd,Ed,Cd,Is,gE]),EO=he([_s,fC,SE,$C,Sd,oi,vd,ri,Mn,DC,sc,lc,rc]);class Oe 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===Ue.UrlElicitationRequired&&n){let o=n;if(o.elicitations)return new Iy(o.elicitations,t)}return new Oe(e,t,n)}}class Iy extends Oe{constructor(e,t=`URL elicitation${e.length>1?"s":""} required`){super(Ue.UrlElicitationRequired,t,{elicitations:e})}get elicitations(){return this.data?.elicitations??[]}}function Fo(e){return e==="completed"||e==="failed"||e==="cancelled"}var EE=Symbol("Let zodToJsonSchema decide on which parser to use");var sL=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function Ad(e){let n=Dv(e)?.method;if(!n)throw Error("Schema is missing a method literal");let o=Fv(n);if(typeof o!=="string")throw Error("Schema method literal must be a string");return o}function Pd(e,t){let n=Ka(e,t);if(!n.success)throw n.error;return n.data}var zE=60000;class ci{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(nc,(t)=>{this._oncancel(t)}),this.setNotificationHandler(oc,(t)=>{this._onprogress(t)}),this.setRequestHandler(co,(t)=>({})),this._taskStore=e?.taskStore,this._taskMessageQueue=e?.taskMessageQueue,this._taskStore)this.setRequestHandler(ic,async(t,n)=>{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new Oe(Ue.InvalidParams,"Failed to retrieve task: Task not found");return{...o}}),this.setRequestHandler(ac,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 Oe(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 Oe(Ue.InvalidParams,`Task not found: ${r}`);if(!Fo(s.status))return await this._waitForTaskUpdate(r,n.signal),await o();if(Fo(s.status)){let a=await this._taskStore.getTaskResult(r,n.sessionId);return this._clearTaskQueue(r),{...a,_meta:{...a._meta,[Oo]:{taskId:r}}}}return await o()};return await o()}),this.setRequestHandler(cc,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 Oe(Ue.InvalidParams,`Failed to list tasks: ${o instanceof Error?o.message:String(o)}`)}}),this.setRequestHandler(uc,async(t,n)=>{try{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new Oe(Ue.InvalidParams,`Task not found: ${t.params.taskId}`);if(Fo(o.status))throw new Oe(Ue.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 Oe(Ue.InvalidParams,`Task not found after cancellation: ${t.params.taskId}`);return{_meta:{},...r}}catch(o){if(o instanceof Oe)throw o;throw new Oe(Ue.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),Oe.fromError(Ue.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),Ss(r)||wy(r))this._onresponse(r);else if(dd(r))this._onrequest(r,s);else if(xy(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=Oe.fromError(Ue.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?.[Oo]?.taskId;if(n===void 0){let u={jsonrpc:"2.0",id:e.id,error:{code:Ue.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=vy(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 Oe(Ue.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:Ue.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),Ss(e))n(e);else{let s=new Oe(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(Ss(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(Ss(e))o(e);else{let s=Oe.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 Oe?s:new Oe(Ue.InternalError,String(s))}}return}let r;try{let s=await this.request(e,rc,n);if(s.task)r=s.task.taskId,yield{type:"taskCreated",task:s.task};else throw new Oe(Ue.InternalError,"Task creation did not return a task");while(!0){let a=await this.getTask({taskId:r},n);if(yield{type:"taskStatus",task:a},Fo(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 Oe(Ue.InternalError,`Task ${r} failed`)};else if(a.status==="cancelled")yield{type:"error",error:new Oe(Ue.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 Oe?s:new Oe(Ue.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||{},[Oo]: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((R)=>this._onerror(Error(`Failed to send cancellation: ${R}`)));let x=g instanceof Oe?g:new Oe(Ue.RequestTimeout,String(g));u(x)};this._responseHandlers.set(d,(g)=>{if(n?.signal?.aborted)return;if(g instanceof Error)return u(g);try{let x=Ka(t,g.result);if(!x.success)u(x.error);else l(x.data)}catch(x){u(x)}}),n?.signal?.addEventListener("abort",()=>{f(n?.signal?.reason)});let h=n?.timeout??zE,v=()=>f(Oe.fromError(Ue.RequestTimeout,"Request timed out",{timeout:h}));this._setupTimeout(d,h,n?.maxTotalTimeout,v,n?.resetTimeoutOnProgress??!1);let w=c?.taskId;if(w){let g=(x)=>{let R=this._responseHandlers.get(d);if(R)R(x);else this._onerror(Error(`Response handler missing for side-channeled request ${d}`))};this._requestResolvers.set(d,g),this._enqueueTaskMessage(w,{type:"request",message:m,timestamp:Date.now()}).catch((x)=>{this._cleanupTimeout(d),u(x)})}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},sc,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},lc,t)}async cancelTask(e,t){return this.request({method:"tasks/cancel",params:e},Sy,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||{},[Oo]: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||{},[Oo]: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||{},[Oo]:t.relatedTask}}};await this._transport.send(s,t)}setRequestHandler(e,t){let n=Ad(e);this.assertRequestHandlerCapability(n),this._requestHandlers.set(n,(o,r)=>{let s=Pd(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=Ad(e);this._notificationHandlers.set(n,(o)=>{let r=Pd(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"&&dd(o.message)){let r=o.message.id,s=this._requestResolvers.get(r);if(s)s(new Oe(Ue.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 Oe(Ue.InvalidRequest,"Request cancelled"));return}let s=setTimeout(o,n);t.addEventListener("abort",()=>{clearTimeout(s),r(new Oe(Ue.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 Oe(Ue.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=Is.parse({method:"notifications/tasks/status",params:a});if(await this.notification(c),Fo(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 Oe(Ue.InvalidParams,`Task "${o}" not found - it may have been cleaned up`);if(Fo(a.status))throw new Oe(Ue.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=Is.parse({method:"notifications/tasks/status",params:c});if(await this.notification(l),Fo(c.status))this._cleanupTaskProgressHandler(o)}},listTasks:(o)=>n.listTasks(o,t)}}}var ME="2026-01-26";var $E="ui/notifications/tool-input-partial";class Py{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=tc.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!==$E)console.debug("Sending message",e);this.eventTarget.postMessage(e,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}var OE=he([b("light"),b("dark")]).describe("Color theme preference for the host environment."),zs=he([b("inline"),b("fullscreen"),b("pip")]).describe("Display mode for UI presentation."),LE=he([b("--color-background-primary"),b("--color-background-secondary"),b("--color-background-tertiary"),b("--color-background-inverse"),b("--color-background-ghost"),b("--color-background-info"),b("--color-background-danger"),b("--color-background-success"),b("--color-background-warning"),b("--color-background-disabled"),b("--color-text-primary"),b("--color-text-secondary"),b("--color-text-tertiary"),b("--color-text-inverse"),b("--color-text-ghost"),b("--color-text-info"),b("--color-text-danger"),b("--color-text-success"),b("--color-text-warning"),b("--color-text-disabled"),b("--color-border-primary"),b("--color-border-secondary"),b("--color-border-tertiary"),b("--color-border-inverse"),b("--color-border-ghost"),b("--color-border-info"),b("--color-border-danger"),b("--color-border-success"),b("--color-border-warning"),b("--color-border-disabled"),b("--color-ring-primary"),b("--color-ring-secondary"),b("--color-ring-inverse"),b("--color-ring-info"),b("--color-ring-danger"),b("--color-ring-success"),b("--color-ring-warning"),b("--font-sans"),b("--font-mono"),b("--font-weight-normal"),b("--font-weight-medium"),b("--font-weight-semibold"),b("--font-weight-bold"),b("--font-text-xs-size"),b("--font-text-sm-size"),b("--font-text-md-size"),b("--font-text-lg-size"),b("--font-heading-xs-size"),b("--font-heading-sm-size"),b("--font-heading-md-size"),b("--font-heading-lg-size"),b("--font-heading-xl-size"),b("--font-heading-2xl-size"),b("--font-heading-3xl-size"),b("--font-text-xs-line-height"),b("--font-text-sm-line-height"),b("--font-text-md-line-height"),b("--font-text-lg-line-height"),b("--font-heading-xs-line-height"),b("--font-heading-sm-line-height"),b("--font-heading-md-line-height"),b("--font-heading-lg-line-height"),b("--font-heading-xl-line-height"),b("--font-heading-2xl-line-height"),b("--font-heading-3xl-line-height"),b("--border-radius-xs"),b("--border-radius-sm"),b("--border-radius-md"),b("--border-radius-lg"),b("--border-radius-xl"),b("--border-radius-full"),b("--border-width-regular"),b("--shadow-hairline"),b("--shadow-sm"),b("--shadow-md"),b("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."),DE=$e(LE.describe(`Style variables for theming MCP apps.
|
|
7567
|
+
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 ed(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:bs(t,"input",e.processors),output:bs(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function Jt(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 Jt(o.element,n);if(o.type==="set")return Jt(o.valueType,n);if(o.type==="lazy")return Jt(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 Jt(o.innerType,n);if(o.type==="intersection")return Jt(o.left,n)||Jt(o.right,n);if(o.type==="record"||o.type==="map")return Jt(o.keyType,n)||Jt(o.valueType,n);if(o.type==="pipe")return Jt(o.in,n)||Jt(o.out,n);if(o.type==="object"){for(let r in o.shape)if(Jt(o.shape[r],n))return!0;return!1}if(o.type==="union"){for(let r of o.options)if(Jt(r,n))return!0;return!1}if(o.type==="tuple"){for(let r of o.items)if(Jt(r,n))return!0;if(o.rest&&Jt(o.rest,n))return!0;return!1}return!1}var fv=(e,t={})=>(n)=>{let o=Yu({...n,processors:t});return mt(e,o),Qu(o,e),ed(o,e)},bs=(e,t,n={})=>(o)=>{let{libraryOptions:r,target:s}=o??{},a=Yu({...r??{},target:s,io:t,processors:n});return mt(e,a),Qu(a,e),ed(a,e)};var J0={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},hv=(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=J0[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}))]}},gv=(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},vv=(e,t,n,o)=>{n.type="boolean"};var yv=(e,t,n,o)=>{if(t.target==="openapi-3.0")n.type="string",n.nullable=!0,n.enum=[null];else n.type="null"},bv=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Undefined cannot be represented in JSON Schema")};var xv=(e,t,n,o)=>{n.not={}};var wv=(e,t,n,o)=>{};var Sv=(e,t,n,o)=>{let r=e._zod.def,s=Na(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},_v=(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 kv=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Custom types cannot be represented in JSON Schema")};var Tv=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Transforms cannot be represented in JSON Schema")};var Cv=(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=mt(s.element,t,{...o,path:[...o.path,"items"]})},Ev=(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]=mt(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=mt(s.catchall,t,{...o,path:[...o.path,"additionalProperties"]})},Iv=(e,t,n,o)=>{let r=e._zod.def,s=r.inclusive===!1,a=r.options.map((c,l)=>mt(c,t,{...o,path:[...o.path,s?"oneOf":"anyOf",l]}));if(s)n.oneOf=a;else n.anyOf=a},Av=(e,t,n,o)=>{let r=e._zod.def,s=mt(r.left,t,{...o,path:[...o.path,"allOf",0]}),a=mt(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 Pv=(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=mt(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=mt(s.keyType,t,{...o,path:[...o.path,"propertyNames"]});r.additionalProperties=mt(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}},Rv=(e,t,n,o)=>{let r=e._zod.def,s=mt(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"}]},Nv=(e,t,n,o)=>{let r=e._zod.def;mt(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType},zv=(e,t,n,o)=>{let r=e._zod.def;mt(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.default=JSON.parse(JSON.stringify(r.defaultValue))},Mv=(e,t,n,o)=>{let r=e._zod.def;mt(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))},$v=(e,t,n,o)=>{let r=e._zod.def;mt(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},Ov=(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;mt(s,t,o);let a=t.seen.get(e);a.ref=s},Lv=(e,t,n,o)=>{let r=e._zod.def;mt(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.readOnly=!0};var td=(e,t,n,o)=>{let r=e._zod.def;mt(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType};function Xa(e){return!!e._zod}function Ka(e,t){if(Xa(e))return fs(e,t);return e.safeParse(t)}function Dv(e){if(!e)return;let t;if(Xa(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 Fv(e){if(Xa(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}var iT=H("ZodISODateTime",(e,t)=>{Wh.init(e,t),nt.init(e,t)});function nd(e){return Qg(iT,e)}var sT=H("ZodISODate",(e,t)=>{qh.init(e,t),nt.init(e,t)});function Hv(e){return ev(sT,e)}var aT=H("ZodISOTime",(e,t)=>{Gh.init(e,t),nt.init(e,t)});function Bv(e){return tv(aT,e)}var cT=H("ZodISODuration",(e,t)=>{Vh.init(e,t),nt.init(e,t)});function jv(e){return nv(cT,e)}var Uv=(e,t)=>{Oa.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:(n)=>If(e,n)},flatten:{value:(n)=>Ef(e,n)},addIssue:{value:(n)=>{e.issues.push(n),e.message=JSON.stringify(e.issues,ds,2)}},addIssues:{value:(n)=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,ds,2)}},isEmpty:{get(){return e.issues.length===0}}})},o$=H("ZodError",Uv),dn=H("ZodError",Uv,{Parent:Error});var Zv=La(dn),Wv=Da(dn),qv=ms(dn),Gv=hs(dn),Vv=Af(dn),Xv=Pf(dn),Kv=Rf(dn),Jv=Nf(dn),Yv=zf(dn),Qv=Mf(dn),ey=$f(dn),ty=Of(dn);var tt=H("ZodType",(e,t)=>(Ke.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:bs(e,"input"),output:bs(e,"output")}}),e.toJSONSchema=fv(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(No(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)=>qn(e,n,o),e.brand=()=>e,e.register=(n,o)=>(n.add(e,o),e),e.parse=(n,o)=>Zv(e,n,o,{callee:e.parse}),e.safeParse=(n,o)=>qv(e,n,o),e.parseAsync=async(n,o)=>Wv(e,n,o,{callee:e.parseAsync}),e.safeParseAsync=async(n,o)=>Gv(e,n,o),e.spa=e.safeParseAsync,e.encode=(n,o)=>Vv(e,n,o),e.decode=(n,o)=>Xv(e,n,o),e.encodeAsync=async(n,o)=>Kv(e,n,o),e.decodeAsync=async(n,o)=>Jv(e,n,o),e.safeEncode=(n,o)=>Yv(e,n,o),e.safeDecode=(n,o)=>Qv(e,n,o),e.safeEncodeAsync=async(n,o)=>ey(e,n,o),e.safeDecodeAsync=async(n,o)=>ty(e,n,o),e.refine=(n,o)=>e.check(eC(n,o)),e.superRefine=(n)=>e.check(tC(n)),e.overwrite=(n)=>e.check($o(n)),e.optional=()=>at(e),e.exactOptional=()=>jT(e),e.nullable=()=>ry(e),e.nullish=()=>at(ry(e)),e.nonoptional=(n)=>VT(e,n),e.array=()=>te(e),e.or=(n)=>he([e,n]),e.and=(n)=>Ya(e,n),e.transform=(n)=>id(e,uy(n)),e.default=(n)=>WT(e,n),e.prefault=(n)=>GT(e,n),e.catch=(n)=>KT(e,n),e.pipe=(n)=>id(e,n),e.readonly=()=>QT(e),e.describe=(n)=>{let o=e.clone();return xr.add(o,{description:n}),o},Object.defineProperty(e,"description",{get(){return xr.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return xr.get(e);let o=e.clone();return xr.add(o,n[0]),o},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=(n)=>n(e),e)),iy=H("_ZodString",(e,t)=>{Ua.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(o,r,s)=>hv(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(Bu(...o)),e.includes=(...o)=>e.check(Zu(...o)),e.startsWith=(...o)=>e.check(Wu(...o)),e.endsWith=(...o)=>e.check(qu(...o)),e.min=(...o)=>e.check(Qr(...o)),e.max=(...o)=>e.check(Ga(...o)),e.length=(...o)=>e.check(Va(...o)),e.nonempty=(...o)=>e.check(Qr(1,...o)),e.lowercase=(o)=>e.check(ju(o)),e.uppercase=(o)=>e.check(Uu(o)),e.trim=()=>e.check(Vu()),e.normalize=(...o)=>e.check(Gu(...o)),e.toLowerCase=()=>e.check(Xu()),e.toUpperCase=()=>e.check(Ku()),e.slugify=()=>e.check(Ju())}),dT=H("ZodString",(e,t)=>{Ua.init(e,t),iy.init(e,t),e.email=(n)=>e.check(Ng(pT,n)),e.url=(n)=>e.check(Lg(mT,n)),e.jwt=(n)=>e.check(Yg(IT,n)),e.emoji=(n)=>e.check(Dg(fT,n)),e.guid=(n)=>e.check(Hu(ny,n)),e.uuid=(n)=>e.check(zg(Ja,n)),e.uuidv4=(n)=>e.check(Mg(Ja,n)),e.uuidv6=(n)=>e.check($g(Ja,n)),e.uuidv7=(n)=>e.check(Og(Ja,n)),e.nanoid=(n)=>e.check(Fg(hT,n)),e.guid=(n)=>e.check(Hu(ny,n)),e.cuid=(n)=>e.check(Hg(gT,n)),e.cuid2=(n)=>e.check(Bg(vT,n)),e.ulid=(n)=>e.check(jg(yT,n)),e.base64=(n)=>e.check(Xg(TT,n)),e.base64url=(n)=>e.check(Kg(CT,n)),e.xid=(n)=>e.check(Ug(bT,n)),e.ksuid=(n)=>e.check(Zg(xT,n)),e.ipv4=(n)=>e.check(Wg(wT,n)),e.ipv6=(n)=>e.check(qg(ST,n)),e.cidrv4=(n)=>e.check(Gg(_T,n)),e.cidrv6=(n)=>e.check(Vg(kT,n)),e.e164=(n)=>e.check(Jg(ET,n)),e.datetime=(n)=>e.check(nd(n)),e.date=(n)=>e.check(Hv(n)),e.time=(n)=>e.check(Bv(n)),e.duration=(n)=>e.check(jv(n))});function C(e){return Rg(dT,e)}var nt=H("ZodStringFormat",(e,t)=>{et.init(e,t),iy.init(e,t)}),pT=H("ZodEmail",(e,t)=>{Oh.init(e,t),nt.init(e,t)});var ny=H("ZodGUID",(e,t)=>{Mh.init(e,t),nt.init(e,t)});var Ja=H("ZodUUID",(e,t)=>{$h.init(e,t),nt.init(e,t)});var mT=H("ZodURL",(e,t)=>{Lh.init(e,t),nt.init(e,t)});var fT=H("ZodEmoji",(e,t)=>{Dh.init(e,t),nt.init(e,t)});var hT=H("ZodNanoID",(e,t)=>{Fh.init(e,t),nt.init(e,t)});var gT=H("ZodCUID",(e,t)=>{Hh.init(e,t),nt.init(e,t)});var vT=H("ZodCUID2",(e,t)=>{Bh.init(e,t),nt.init(e,t)});var yT=H("ZodULID",(e,t)=>{jh.init(e,t),nt.init(e,t)});var bT=H("ZodXID",(e,t)=>{Uh.init(e,t),nt.init(e,t)});var xT=H("ZodKSUID",(e,t)=>{Zh.init(e,t),nt.init(e,t)});var wT=H("ZodIPv4",(e,t)=>{Xh.init(e,t),nt.init(e,t)});var ST=H("ZodIPv6",(e,t)=>{Kh.init(e,t),nt.init(e,t)});var _T=H("ZodCIDRv4",(e,t)=>{Jh.init(e,t),nt.init(e,t)});var kT=H("ZodCIDRv6",(e,t)=>{Yh.init(e,t),nt.init(e,t)});var TT=H("ZodBase64",(e,t)=>{eg.init(e,t),nt.init(e,t)});var CT=H("ZodBase64URL",(e,t)=>{tg.init(e,t),nt.init(e,t)});var ET=H("ZodE164",(e,t)=>{ng.init(e,t),nt.init(e,t)});var IT=H("ZodJWT",(e,t)=>{og.init(e,t),nt.init(e,t)});var sy=H("ZodNumber",(e,t)=>{Ou.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(o,r,s)=>gv(e,o,r,s),e.gt=(o,r)=>e.check(Wa(o,r)),e.gte=(o,r)=>e.check(ys(o,r)),e.min=(o,r)=>e.check(ys(o,r)),e.lt=(o,r)=>e.check(Za(o,r)),e.lte=(o,r)=>e.check(vs(o,r)),e.max=(o,r)=>e.check(vs(o,r)),e.int=(o)=>e.check(oy(o)),e.safe=(o)=>e.check(oy(o)),e.positive=(o)=>e.check(Wa(0,o)),e.nonnegative=(o)=>e.check(ys(0,o)),e.negative=(o)=>e.check(Za(0,o)),e.nonpositive=(o)=>e.check(vs(0,o)),e.multipleOf=(o,r)=>e.check(qa(o,r)),e.step=(o,r)=>e.check(qa(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 ne(e){return ov(sy,e)}var AT=H("ZodNumberFormat",(e,t)=>{rg.init(e,t),sy.init(e,t)});function oy(e){return rv(AT,e)}var PT=H("ZodBoolean",(e,t)=>{ig.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>vv(e,n,o,r)});function Re(e){return iv(PT,e)}var RT=H("ZodUndefined",(e,t)=>{sg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>bv(e,n,o,r)});function ei(e){return sv(RT,e)}var NT=H("ZodNull",(e,t)=>{ag.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>yv(e,n,o,r)});function sd(e){return av(NT,e)}var zT=H("ZodUnknown",(e,t)=>{cg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>wv(e,n,o,r)});function He(){return cv(zT)}var MT=H("ZodNever",(e,t)=>{lg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>xv(e,n,o,r)});function ay(e){return lv(MT,e)}var $T=H("ZodArray",(e,t)=>{ug.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Cv(e,n,o,r),e.element=t.element,e.min=(n,o)=>e.check(Qr(n,o)),e.nonempty=(n)=>e.check(Qr(1,n)),e.max=(n,o)=>e.check(Ga(n,o)),e.length=(n,o)=>e.check(Va(n,o)),e.unwrap=()=>e.element});function te(e,t){return uv($T,e,t)}var ad=H("ZodObject",(e,t)=>{mg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ev(e,n,o,r),Be(e,"shape",()=>t.shape),e.keyof=()=>jt(Object.keys(e._zod.def.shape)),e.catchall=(n)=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:He()}),e.loose=()=>e.clone({...e._zod.def,catchall:He()}),e.strict=()=>e.clone({...e._zod.def,catchall:ay()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=(n)=>O0(e,n),e.safeExtend=(n)=>L0(e,n),e.merge=(n)=>D0(e,n),e.pick=(n)=>M0(e,n),e.omit=(n)=>$0(e,n),e.partial=(...n)=>F0(dy,e,n[0]),e.required=(...n)=>H0(py,e,n[0])});function S(e,t){let n={type:"object",shape:e??{},...ee(t)};return new ad(n)}function cy(e,t){return new ad({type:"object",shape:e,catchall:ay(),...ee(t)})}function Yt(e,t){return new ad({type:"object",shape:e,catchall:He(),...ee(t)})}var ly=H("ZodUnion",(e,t)=>{Lu.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Iv(e,n,o,r),e.options=t.options});function he(e,t){return new ly({type:"union",options:e,...ee(t)})}var OT=H("ZodDiscriminatedUnion",(e,t)=>{ly.init(e,t),fg.init(e,t)});function cd(e,t,n){return new OT({type:"union",options:t,discriminator:e,...ee(n)})}var LT=H("ZodIntersection",(e,t)=>{hg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Av(e,n,o,r)});function Ya(e,t){return new LT({type:"intersection",left:e,right:t})}var DT=H("ZodRecord",(e,t)=>{gg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Pv(e,n,o,r),e.keyType=t.keyType,e.valueType=t.valueType});function $e(e,t,n){return new DT({type:"record",keyType:e,valueType:t,...ee(n)})}var rd=H("ZodEnum",(e,t)=>{vg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(o,r,s)=>Sv(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 rd({...t,checks:[],...ee(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 rd({...t,checks:[],...ee(r),entries:s})}});function jt(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map((o)=>[o,o])):e;return new rd({type:"enum",entries:n,...ee(t)})}var FT=H("ZodLiteral",(e,t)=>{yg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>_v(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 b(e,t){return new FT({type:"literal",values:Array.isArray(e)?e:[e],...ee(t)})}var HT=H("ZodTransform",(e,t)=>{bg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Tv(e,n,o,r),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new us(e.constructor.name);n.addIssue=(s)=>{if(typeof s==="string")n.issues.push(br(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(br(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 uy(e){return new HT({type:"transform",transform:e})}var dy=H("ZodOptional",(e,t)=>{Du.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>td(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function at(e){return new dy({type:"optional",innerType:e})}var BT=H("ZodExactOptional",(e,t)=>{xg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>td(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function jT(e){return new BT({type:"optional",innerType:e})}var UT=H("ZodNullable",(e,t)=>{wg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Rv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function ry(e){return new UT({type:"nullable",innerType:e})}var ZT=H("ZodDefault",(e,t)=>{Sg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>zv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function WT(e,t){return new ZT({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():Cu(t)}})}var qT=H("ZodPrefault",(e,t)=>{_g.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Mv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function GT(e,t){return new qT({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():Cu(t)}})}var py=H("ZodNonOptional",(e,t)=>{kg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Nv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function VT(e,t){return new py({type:"nonoptional",innerType:e,...ee(t)})}var XT=H("ZodCatch",(e,t)=>{Tg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>$v(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function KT(e,t){return new XT({type:"catch",innerType:e,catchValue:typeof t==="function"?t:()=>t})}var JT=H("ZodPipe",(e,t)=>{Cg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ov(e,n,o,r),e.in=t.in,e.out=t.out});function id(e,t){return new JT({type:"pipe",in:e,out:t})}var YT=H("ZodReadonly",(e,t)=>{Eg.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Lv(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function QT(e){return new YT({type:"readonly",innerType:e})}var my=H("ZodCustom",(e,t)=>{Ig.init(e,t),tt.init(e,t),e._zod.processJSONSchema=(n,o,r)=>kv(e,n,o,r)});function fy(e,t){return dv(my,e??(()=>!0),t)}function eC(e,t={}){return pv(my,e,t)}function tC(e){return mv(e)}function ld(e,t){return id(uy(e),t)}_n(Fu());var Oo="io.modelcontextprotocol/related-task",ec="2.0",Rt=fy((e)=>e!==null&&(typeof e==="object"||typeof e==="function")),hy=he([C(),ne().int()]),gy=C(),yO=Yt({ttl:he([ne(),sd()]).optional(),pollInterval:ne().optional()}),nC=S({ttl:ne().optional()}),oC=S({taskId:C()}),ud=Yt({progressToken:hy.optional(),[Oo]:oC.optional()}),pn=S({_meta:ud.optional()}),ws=pn.extend({task:nC.optional()}),vy=(e)=>ws.safeParse(e).success,Nt=S({method:C(),params:pn.loose().optional()}),kn=S({_meta:ud.optional()}),Tn=S({method:C(),params:kn.loose().optional()}),zt=Yt({_meta:ud.optional()}),Lo=he([C(),ne().int()]),yy=S({jsonrpc:b(ec),id:Lo,...Nt.shape}).strict(),dd=(e)=>yy.safeParse(e).success,by=S({jsonrpc:b(ec),...Tn.shape}).strict(),xy=(e)=>by.safeParse(e).success,pd=S({jsonrpc:b(ec),id:Lo,result:zt}).strict(),Ss=(e)=>pd.safeParse(e).success;var Ue;(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"})(Ue||(Ue={}));var md=S({jsonrpc:b(ec),id:Lo.optional(),error:S({code:ne().int(),message:C(),data:He().optional()})}).strict();var wy=(e)=>md.safeParse(e).success;var tc=he([yy,by,pd,md]),bO=he([pd,md]),_s=zt.strict(),rC=kn.extend({requestId:Lo.optional(),reason:C().optional()}),nc=Tn.extend({method:b("notifications/cancelled"),params:rC}),iC=S({src:C(),mimeType:C().optional(),sizes:te(C()).optional(),theme:jt(["light","dark"]).optional()}),ks=S({icons:te(iC).optional()}),ti=S({name:C(),title:C().optional()}),Do=ti.extend({...ti.shape,...ks.shape,version:C(),websiteUrl:C().optional(),description:C().optional()}),sC=Ya(S({applyDefaults:Re().optional()}),$e(C(),He())),aC=ld((e)=>{if(e&&typeof e==="object"&&!Array.isArray(e)){if(Object.keys(e).length===0)return{form:{}}}return e},Ya(S({form:sC.optional(),url:Rt.optional()}),$e(C(),He()).optional())),cC=Yt({list:Rt.optional(),cancel:Rt.optional(),requests:Yt({sampling:Yt({createMessage:Rt.optional()}).optional(),elicitation:Yt({create:Rt.optional()}).optional()}).optional()}),lC=Yt({list:Rt.optional(),cancel:Rt.optional(),requests:Yt({tools:Yt({call:Rt.optional()}).optional()}).optional()}),uC=S({experimental:$e(C(),Rt).optional(),sampling:S({context:Rt.optional(),tools:Rt.optional()}).optional(),elicitation:aC.optional(),roots:S({listChanged:Re().optional()}).optional(),tasks:cC.optional()}),dC=pn.extend({protocolVersion:C(),capabilities:uC,clientInfo:Do}),pC=Nt.extend({method:b("initialize"),params:dC});var mC=S({experimental:$e(C(),Rt).optional(),logging:Rt.optional(),completions:Rt.optional(),prompts:S({listChanged:Re().optional()}).optional(),resources:S({subscribe:Re().optional(),listChanged:Re().optional()}).optional(),tools:S({listChanged:Re().optional()}).optional(),tasks:lC.optional()}),fC=zt.extend({protocolVersion:C(),capabilities:mC,serverInfo:Do,instructions:C().optional()}),hC=Tn.extend({method:b("notifications/initialized"),params:kn.optional()});var co=Nt.extend({method:b("ping"),params:pn.optional()}),gC=S({progress:ne(),total:at(ne()),message:at(C())}),vC=S({...kn.shape,...gC.shape,progressToken:hy}),oc=Tn.extend({method:b("notifications/progress"),params:vC}),yC=pn.extend({cursor:gy.optional()}),Ts=Nt.extend({params:yC.optional()}),Cs=zt.extend({nextCursor:gy.optional()}),bC=jt(["working","input_required","completed","failed","cancelled"]),Es=S({taskId:C(),status:bC,ttl:he([ne(),sd()]),createdAt:C(),lastUpdatedAt:C(),pollInterval:at(ne()),statusMessage:at(C())}),rc=zt.extend({task:Es}),xC=kn.merge(Es),Is=Tn.extend({method:b("notifications/tasks/status"),params:xC}),ic=Nt.extend({method:b("tasks/get"),params:pn.extend({taskId:C()})}),sc=zt.merge(Es),ac=Nt.extend({method:b("tasks/result"),params:pn.extend({taskId:C()})}),xO=zt.loose(),cc=Ts.extend({method:b("tasks/list")}),lc=Cs.extend({tasks:te(Es)}),uc=Nt.extend({method:b("tasks/cancel"),params:pn.extend({taskId:C()})}),Sy=zt.merge(Es),_y=S({uri:C(),mimeType:at(C()),_meta:$e(C(),He()).optional()}),ky=_y.extend({text:C()}),fd=C().refine((e)=>{try{return atob(e),!0}catch{return!1}},{message:"Invalid Base64 string"}),Ty=_y.extend({blob:fd}),As=jt(["user","assistant"]),ni=S({audience:te(As).optional(),priority:ne().min(0).max(1).optional(),lastModified:nd({offset:!0}).optional()}),Cy=S({...ti.shape,...ks.shape,uri:C(),description:at(C()),mimeType:at(C()),annotations:ni.optional(),_meta:at(Yt({}))}),wC=S({...ti.shape,...ks.shape,uriTemplate:C(),description:at(C()),mimeType:at(C()),annotations:ni.optional(),_meta:at(Yt({}))}),hd=Ts.extend({method:b("resources/list")}),oi=Cs.extend({resources:te(Cy)}),gd=Ts.extend({method:b("resources/templates/list")}),vd=Cs.extend({resourceTemplates:te(wC)}),yd=pn.extend({uri:C()}),SC=yd,bd=Nt.extend({method:b("resources/read"),params:SC}),ri=zt.extend({contents:te(he([ky,Ty]))}),xd=Tn.extend({method:b("notifications/resources/list_changed"),params:kn.optional()}),_C=yd,kC=Nt.extend({method:b("resources/subscribe"),params:_C}),TC=yd,CC=Nt.extend({method:b("resources/unsubscribe"),params:TC}),EC=kn.extend({uri:C()}),IC=Tn.extend({method:b("notifications/resources/updated"),params:EC}),AC=S({name:C(),description:at(C()),required:at(Re())}),PC=S({...ti.shape,...ks.shape,description:at(C()),arguments:at(te(AC)),_meta:at(Yt({}))}),wd=Ts.extend({method:b("prompts/list")}),Sd=Cs.extend({prompts:te(PC)}),RC=pn.extend({name:C(),arguments:$e(C(),C()).optional()}),NC=Nt.extend({method:b("prompts/get"),params:RC}),_d=S({type:b("text"),text:C(),annotations:ni.optional(),_meta:$e(C(),He()).optional()}),kd=S({type:b("image"),data:fd,mimeType:C(),annotations:ni.optional(),_meta:$e(C(),He()).optional()}),Td=S({type:b("audio"),data:fd,mimeType:C(),annotations:ni.optional(),_meta:$e(C(),He()).optional()}),zC=S({type:b("tool_use"),name:C(),id:C(),input:$e(C(),He()),_meta:$e(C(),He()).optional()}),Ps=S({type:b("resource"),resource:he([ky,Ty]),annotations:ni.optional(),_meta:$e(C(),He()).optional()}),Rs=Cy.extend({type:b("resource_link")}),lo=he([_d,kd,Td,Rs,Ps]),MC=S({role:As,content:lo}),$C=zt.extend({description:C().optional(),messages:te(MC)}),Cd=Tn.extend({method:b("notifications/prompts/list_changed"),params:kn.optional()}),OC=S({title:C().optional(),readOnlyHint:Re().optional(),destructiveHint:Re().optional(),idempotentHint:Re().optional(),openWorldHint:Re().optional()}),LC=S({taskSupport:jt(["required","optional","forbidden"]).optional()}),ii=S({...ti.shape,...ks.shape,description:C().optional(),inputSchema:S({type:b("object"),properties:$e(C(),Rt).optional(),required:te(C()).optional()}).catchall(He()),outputSchema:S({type:b("object"),properties:$e(C(),Rt).optional(),required:te(C()).optional()}).catchall(He()).optional(),annotations:OC.optional(),execution:LC.optional(),_meta:$e(C(),He()).optional()}),si=Ts.extend({method:b("tools/list")}),DC=Cs.extend({tools:te(ii)}),Mn=zt.extend({content:te(lo).default([]),structuredContent:$e(C(),He()).optional(),isError:Re().optional()}),wO=Mn.or(zt.extend({toolResult:He()})),FC=ws.extend({name:C(),arguments:$e(C(),He()).optional()}),ai=Nt.extend({method:b("tools/call"),params:FC}),Ed=Tn.extend({method:b("notifications/tools/list_changed"),params:kn.optional()}),SO=S({autoRefresh:Re().default(!0),debounceMs:ne().int().nonnegative().default(300)}),Ey=jt(["debug","info","notice","warning","error","critical","alert","emergency"]),HC=pn.extend({level:Ey}),BC=Nt.extend({method:b("logging/setLevel"),params:HC}),jC=kn.extend({level:Ey,logger:C().optional(),data:He()}),Id=Tn.extend({method:b("notifications/message"),params:jC}),UC=S({name:C().optional()}),ZC=S({hints:te(UC).optional(),costPriority:ne().min(0).max(1).optional(),speedPriority:ne().min(0).max(1).optional(),intelligencePriority:ne().min(0).max(1).optional()}),WC=S({mode:jt(["auto","required","none"]).optional()}),qC=S({type:b("tool_result"),toolUseId:C().describe("The unique identifier for the corresponding tool call."),content:te(lo).default([]),structuredContent:S({}).loose().optional(),isError:Re().optional(),_meta:$e(C(),He()).optional()}),GC=cd("type",[_d,kd,Td]),Qa=cd("type",[_d,kd,Td,zC,qC]),VC=S({role:As,content:he([Qa,te(Qa)]),_meta:$e(C(),He()).optional()}),XC=ws.extend({messages:te(VC),modelPreferences:ZC.optional(),systemPrompt:C().optional(),includeContext:jt(["none","thisServer","allServers"]).optional(),temperature:ne().optional(),maxTokens:ne().int(),stopSequences:te(C()).optional(),metadata:Rt.optional(),tools:te(ii).optional(),toolChoice:WC.optional()}),KC=Nt.extend({method:b("sampling/createMessage"),params:XC}),JC=zt.extend({model:C(),stopReason:at(jt(["endTurn","stopSequence","maxTokens"]).or(C())),role:As,content:GC}),YC=zt.extend({model:C(),stopReason:at(jt(["endTurn","stopSequence","maxTokens","toolUse"]).or(C())),role:As,content:he([Qa,te(Qa)])}),QC=S({type:b("boolean"),title:C().optional(),description:C().optional(),default:Re().optional()}),eE=S({type:b("string"),title:C().optional(),description:C().optional(),minLength:ne().optional(),maxLength:ne().optional(),format:jt(["email","uri","date","date-time"]).optional(),default:C().optional()}),tE=S({type:jt(["number","integer"]),title:C().optional(),description:C().optional(),minimum:ne().optional(),maximum:ne().optional(),default:ne().optional()}),nE=S({type:b("string"),title:C().optional(),description:C().optional(),enum:te(C()),default:C().optional()}),oE=S({type:b("string"),title:C().optional(),description:C().optional(),oneOf:te(S({const:C(),title:C()})),default:C().optional()}),rE=S({type:b("string"),title:C().optional(),description:C().optional(),enum:te(C()),enumNames:te(C()).optional(),default:C().optional()}),iE=he([nE,oE]),sE=S({type:b("array"),title:C().optional(),description:C().optional(),minItems:ne().optional(),maxItems:ne().optional(),items:S({type:b("string"),enum:te(C())}),default:te(C()).optional()}),aE=S({type:b("array"),title:C().optional(),description:C().optional(),minItems:ne().optional(),maxItems:ne().optional(),items:S({anyOf:te(S({const:C(),title:C()}))}),default:te(C()).optional()}),cE=he([sE,aE]),lE=he([rE,iE,cE]),uE=he([lE,QC,eE,tE]),dE=ws.extend({mode:b("form").optional(),message:C(),requestedSchema:S({type:b("object"),properties:$e(C(),uE),required:te(C()).optional()})}),pE=ws.extend({mode:b("url"),message:C(),elicitationId:C(),url:C().url()}),mE=he([dE,pE]),fE=Nt.extend({method:b("elicitation/create"),params:mE}),hE=kn.extend({elicitationId:C()}),gE=Tn.extend({method:b("notifications/elicitation/complete"),params:hE}),vE=zt.extend({action:jt(["accept","decline","cancel"]),content:ld((e)=>e===null?void 0:e,$e(C(),he([C(),ne(),Re(),te(C())])).optional())}),yE=S({type:b("ref/resource"),uri:C()});var bE=S({type:b("ref/prompt"),name:C()}),xE=pn.extend({ref:he([bE,yE]),argument:S({name:C(),value:C()}),context:S({arguments:$e(C(),C()).optional()}).optional()}),wE=Nt.extend({method:b("completion/complete"),params:xE});var SE=zt.extend({completion:Yt({values:te(C()).max(100),total:at(ne().int()),hasMore:at(Re())})}),_E=S({uri:C().startsWith("file://"),name:C().optional(),_meta:$e(C(),He()).optional()}),kE=Nt.extend({method:b("roots/list"),params:pn.optional()}),TE=zt.extend({roots:te(_E)}),CE=Tn.extend({method:b("notifications/roots/list_changed"),params:kn.optional()}),_O=he([co,pC,wE,BC,NC,wd,hd,gd,bd,kC,CC,ai,si,ic,ac,cc,uc]),kO=he([nc,oc,hC,CE,Is]),TO=he([_s,JC,YC,vE,TE,sc,lc,rc]),CO=he([co,KC,fE,kE,ic,ac,cc,uc]),EO=he([nc,oc,Id,IC,xd,Ed,Cd,Is,gE]),IO=he([_s,fC,SE,$C,Sd,oi,vd,ri,Mn,DC,sc,lc,rc]);class Oe 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===Ue.UrlElicitationRequired&&n){let o=n;if(o.elicitations)return new Iy(o.elicitations,t)}return new Oe(e,t,n)}}class Iy extends Oe{constructor(e,t=`URL elicitation${e.length>1?"s":""} required`){super(Ue.UrlElicitationRequired,t,{elicitations:e})}get elicitations(){return this.data?.elicitations??[]}}function Fo(e){return e==="completed"||e==="failed"||e==="cancelled"}var EE=Symbol("Let zodToJsonSchema decide on which parser to use");var aL=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function Ad(e){let n=Dv(e)?.method;if(!n)throw Error("Schema is missing a method literal");let o=Fv(n);if(typeof o!=="string")throw Error("Schema method literal must be a string");return o}function Pd(e,t){let n=Ka(e,t);if(!n.success)throw n.error;return n.data}var zE=60000;class ci{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(nc,(t)=>{this._oncancel(t)}),this.setNotificationHandler(oc,(t)=>{this._onprogress(t)}),this.setRequestHandler(co,(t)=>({})),this._taskStore=e?.taskStore,this._taskMessageQueue=e?.taskMessageQueue,this._taskStore)this.setRequestHandler(ic,async(t,n)=>{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new Oe(Ue.InvalidParams,"Failed to retrieve task: Task not found");return{...o}}),this.setRequestHandler(ac,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 Oe(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 Oe(Ue.InvalidParams,`Task not found: ${r}`);if(!Fo(s.status))return await this._waitForTaskUpdate(r,n.signal),await o();if(Fo(s.status)){let a=await this._taskStore.getTaskResult(r,n.sessionId);return this._clearTaskQueue(r),{...a,_meta:{...a._meta,[Oo]:{taskId:r}}}}return await o()};return await o()}),this.setRequestHandler(cc,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 Oe(Ue.InvalidParams,`Failed to list tasks: ${o instanceof Error?o.message:String(o)}`)}}),this.setRequestHandler(uc,async(t,n)=>{try{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new Oe(Ue.InvalidParams,`Task not found: ${t.params.taskId}`);if(Fo(o.status))throw new Oe(Ue.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 Oe(Ue.InvalidParams,`Task not found after cancellation: ${t.params.taskId}`);return{_meta:{},...r}}catch(o){if(o instanceof Oe)throw o;throw new Oe(Ue.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),Oe.fromError(Ue.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),Ss(r)||wy(r))this._onresponse(r);else if(dd(r))this._onrequest(r,s);else if(xy(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=Oe.fromError(Ue.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?.[Oo]?.taskId;if(n===void 0){let u={jsonrpc:"2.0",id:e.id,error:{code:Ue.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=vy(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 Oe(Ue.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:Ue.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),Ss(e))n(e);else{let s=new Oe(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(Ss(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(Ss(e))o(e);else{let s=Oe.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 Oe?s:new Oe(Ue.InternalError,String(s))}}return}let r;try{let s=await this.request(e,rc,n);if(s.task)r=s.task.taskId,yield{type:"taskCreated",task:s.task};else throw new Oe(Ue.InternalError,"Task creation did not return a task");while(!0){let a=await this.getTask({taskId:r},n);if(yield{type:"taskStatus",task:a},Fo(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 Oe(Ue.InternalError,`Task ${r} failed`)};else if(a.status==="cancelled")yield{type:"error",error:new Oe(Ue.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 Oe?s:new Oe(Ue.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||{},[Oo]: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((R)=>this._onerror(Error(`Failed to send cancellation: ${R}`)));let x=g instanceof Oe?g:new Oe(Ue.RequestTimeout,String(g));u(x)};this._responseHandlers.set(d,(g)=>{if(n?.signal?.aborted)return;if(g instanceof Error)return u(g);try{let x=Ka(t,g.result);if(!x.success)u(x.error);else l(x.data)}catch(x){u(x)}}),n?.signal?.addEventListener("abort",()=>{f(n?.signal?.reason)});let h=n?.timeout??zE,v=()=>f(Oe.fromError(Ue.RequestTimeout,"Request timed out",{timeout:h}));this._setupTimeout(d,h,n?.maxTotalTimeout,v,n?.resetTimeoutOnProgress??!1);let w=c?.taskId;if(w){let g=(x)=>{let R=this._responseHandlers.get(d);if(R)R(x);else this._onerror(Error(`Response handler missing for side-channeled request ${d}`))};this._requestResolvers.set(d,g),this._enqueueTaskMessage(w,{type:"request",message:m,timestamp:Date.now()}).catch((x)=>{this._cleanupTimeout(d),u(x)})}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},sc,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},lc,t)}async cancelTask(e,t){return this.request({method:"tasks/cancel",params:e},Sy,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||{},[Oo]: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||{},[Oo]: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||{},[Oo]:t.relatedTask}}};await this._transport.send(s,t)}setRequestHandler(e,t){let n=Ad(e);this.assertRequestHandlerCapability(n),this._requestHandlers.set(n,(o,r)=>{let s=Pd(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=Ad(e);this._notificationHandlers.set(n,(o)=>{let r=Pd(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"&&dd(o.message)){let r=o.message.id,s=this._requestResolvers.get(r);if(s)s(new Oe(Ue.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 Oe(Ue.InvalidRequest,"Request cancelled"));return}let s=setTimeout(o,n);t.addEventListener("abort",()=>{clearTimeout(s),r(new Oe(Ue.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 Oe(Ue.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=Is.parse({method:"notifications/tasks/status",params:a});if(await this.notification(c),Fo(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 Oe(Ue.InvalidParams,`Task "${o}" not found - it may have been cleaned up`);if(Fo(a.status))throw new Oe(Ue.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=Is.parse({method:"notifications/tasks/status",params:c});if(await this.notification(l),Fo(c.status))this._cleanupTaskProgressHandler(o)}},listTasks:(o)=>n.listTasks(o,t)}}}var ME="2026-01-26";var $E="ui/notifications/tool-input-partial";class Py{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=tc.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!==$E)console.debug("Sending message",e);this.eventTarget.postMessage(e,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}var OE=he([b("light"),b("dark")]).describe("Color theme preference for the host environment."),zs=he([b("inline"),b("fullscreen"),b("pip")]).describe("Display mode for UI presentation."),LE=he([b("--color-background-primary"),b("--color-background-secondary"),b("--color-background-tertiary"),b("--color-background-inverse"),b("--color-background-ghost"),b("--color-background-info"),b("--color-background-danger"),b("--color-background-success"),b("--color-background-warning"),b("--color-background-disabled"),b("--color-text-primary"),b("--color-text-secondary"),b("--color-text-tertiary"),b("--color-text-inverse"),b("--color-text-ghost"),b("--color-text-info"),b("--color-text-danger"),b("--color-text-success"),b("--color-text-warning"),b("--color-text-disabled"),b("--color-border-primary"),b("--color-border-secondary"),b("--color-border-tertiary"),b("--color-border-inverse"),b("--color-border-ghost"),b("--color-border-info"),b("--color-border-danger"),b("--color-border-success"),b("--color-border-warning"),b("--color-border-disabled"),b("--color-ring-primary"),b("--color-ring-secondary"),b("--color-ring-inverse"),b("--color-ring-info"),b("--color-ring-danger"),b("--color-ring-success"),b("--color-ring-warning"),b("--font-sans"),b("--font-mono"),b("--font-weight-normal"),b("--font-weight-medium"),b("--font-weight-semibold"),b("--font-weight-bold"),b("--font-text-xs-size"),b("--font-text-sm-size"),b("--font-text-md-size"),b("--font-text-lg-size"),b("--font-heading-xs-size"),b("--font-heading-sm-size"),b("--font-heading-md-size"),b("--font-heading-lg-size"),b("--font-heading-xl-size"),b("--font-heading-2xl-size"),b("--font-heading-3xl-size"),b("--font-text-xs-line-height"),b("--font-text-sm-line-height"),b("--font-text-md-line-height"),b("--font-text-lg-line-height"),b("--font-heading-xs-line-height"),b("--font-heading-sm-line-height"),b("--font-heading-md-line-height"),b("--font-heading-lg-line-height"),b("--font-heading-xl-line-height"),b("--font-heading-2xl-line-height"),b("--font-heading-3xl-line-height"),b("--border-radius-xs"),b("--border-radius-sm"),b("--border-radius-md"),b("--border-radius-lg"),b("--border-radius-xl"),b("--border-radius-full"),b("--border-width-regular"),b("--shadow-hairline"),b("--shadow-sm"),b("--shadow-md"),b("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."),DE=$e(LE.describe(`Style variables for theming MCP apps.
|
|
7567
7568
|
|
|
7568
7569
|
Individual style keys are optional - hosts may provide any subset of these values.
|
|
7569
7570
|
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
@@ -7581,10 +7582,10 @@ Individual style keys are optional - hosts may provide any subset of these value
|
|
|
7581
7582
|
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
7582
7583
|
|
|
7583
7584
|
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
7584
|
-
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),
|
|
7585
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),uF=S({method:b("ui/open-link"),params:S({url:C().describe("URL to open in the host's browser")})}),FE=S({isError:Re().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),HE=S({isError:Re().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),BE=S({isError:Re().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),dF=S({method:b("ui/notifications/sandbox-proxy-ready"),params:S({})}),Rd=S({connectDomains:te(C()).optional().describe(`Origins for network requests (fetch/XHR/WebSocket).
|
|
7585
7586
|
|
|
7586
7587
|
- Maps to CSP \`connect-src\` directive
|
|
7587
|
-
- Empty or omitted → no network connections (secure default)`),resourceDomains:te(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:te(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:te(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'`)")}),Nd=S({camera:S({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:S({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:S({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:S({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),
|
|
7588
|
+
- Empty or omitted → no network connections (secure default)`),resourceDomains:te(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:te(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:te(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'`)")}),Nd=S({camera:S({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:S({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:S({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:S({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),pF=S({method:b("ui/notifications/size-changed"),params:S({width:ne().optional().describe("New width in pixels."),height:ne().optional().describe("New height in pixels.")})}),jE=S({method:b("ui/notifications/tool-input"),params:S({arguments:$e(C(),He().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),UE=S({method:b("ui/notifications/tool-input-partial"),params:S({arguments:$e(C(),He().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),ZE=S({method:b("ui/notifications/tool-cancelled"),params:S({reason:C().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),WE=S({fonts:C().optional()}),qE=S({variables:DE.optional().describe("CSS variables for theming the app."),css:WE.optional().describe("CSS blocks that apps can inject.")}),GE=S({method:b("ui/resource-teardown"),params:S({})}),mF=$e(C(),He()),Ay=S({text:S({}).optional().describe("Host supports text content blocks."),image:S({}).optional().describe("Host supports image content blocks."),audio:S({}).optional().describe("Host supports audio content blocks."),resource:S({}).optional().describe("Host supports resource content blocks."),resourceLink:S({}).optional().describe("Host supports resource link content blocks."),structuredContent:S({}).optional().describe("Host supports structured content.")}),fF=S({method:b("ui/notifications/request-teardown"),params:S({}).optional()}),VE=S({experimental:S({}).optional().describe("Experimental features (structure TBD)."),openLinks:S({}).optional().describe("Host supports opening external URLs."),downloadFile:S({}).optional().describe("Host supports file downloads via ui/download-file."),serverTools:S({listChanged:Re().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:S({listChanged:Re().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:S({}).optional().describe("Host accepts log messages."),sandbox:S({permissions:Nd.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:Rd.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:Ay.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:Ay.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),XE=S({experimental:S({}).optional().describe("Experimental features (structure TBD)."),tools:S({listChanged:Re().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:te(zs).optional().describe("Display modes the app supports.")}),hF=S({method:b("ui/notifications/initialized"),params:S({}).optional()}),gF=S({csp:Rd.optional().describe("Content Security Policy configuration for UI resources."),permissions:Nd.optional().describe("Sandbox permissions requested by the UI resource."),domain:C().optional().describe(`Dedicated origin for view sandbox.
|
|
7588
7589
|
|
|
7589
7590
|
Useful when views need stable, dedicated origins for OAuth callbacks, CORS policies, or API key allowlists.
|
|
7590
7591
|
|
|
@@ -7598,10 +7599,10 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
7598
7599
|
|
|
7599
7600
|
- \`true\`: request visible border + background
|
|
7600
7601
|
- \`false\`: request no visible border + background
|
|
7601
|
-
- omitted: host decides border`)}),
|
|
7602
|
+
- omitted: host decides border`)}),vF=S({method:b("ui/request-display-mode"),params:S({mode:zs.describe("The display mode being requested.")})}),KE=S({mode:zs.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),JE=he([b("model"),b("app")]).describe("Tool visibility scope - who can access the tool."),yF=S({resourceUri:C().optional(),visibility:te(JE).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
7602
7603
|
- "model": Tool visible to and callable by the agent
|
|
7603
|
-
- "app": Tool callable by the app from this server only`)}),
|
|
7604
|
-
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([b("web"),b("desktop"),b("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:S({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:S({top:ne().describe("Top safe area inset in pixels."),right:ne().describe("Right safe area inset in pixels."),bottom:ne().describe("Bottom safe area inset in pixels."),left:ne().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),QE=S({method:b("ui/notifications/host-context-changed"),params:Ry.describe("Partial context update containing only changed fields.")}),SF=S({method:b("ui/update-model-context"),params:S({content:te(lo).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:$e(C(),He().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),_F=S({method:b("ui/initialize"),params:S({appInfo:Do.describe("App identification (name and version)."),appCapabilities:XE.describe("Features and capabilities this app provides."),protocolVersion:C().describe("Protocol version this app supports.")})}),eI=S({protocolVersion:C().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Do.describe("Host application identification and version."),hostCapabilities:VE.describe("Features and capabilities provided by the host."),hostContext:Ry.describe("Rich context about the host environment.")}).passthrough();class zd extends ci{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;constructor(e,t={},n={autoResize:!0}){super(n);this._appInfo=e,this._capabilities=t,this.options=n,this.setRequestHandler(co,(o)=>(console.log("Received ping:",o.params),{})),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(e){this.setNotificationHandler(jE,(t)=>e(t.params))}set ontoolinputpartial(e){this.setNotificationHandler(UE,(t)=>e(t.params))}set ontoolresult(e){this.setNotificationHandler(YE,(t)=>e(t.params))}set ontoolcancelled(e){this.setNotificationHandler(ZE,(t)=>e(t.params))}set onhostcontextchanged(e){this.setNotificationHandler(QE,(t)=>{this._hostContext={...this._hostContext,...t.params},e(t.params)})}set onteardown(e){this.setRequestHandler(GE,(t,n)=>e(t.params,n))}set oncalltool(e){this.setRequestHandler(ai,(t,n)=>e(t.params,n))}set onlisttools(e){this.setRequestHandler(si,(t,n)=>e(t.params,n))}assertCapabilityForMethod(e){}assertRequestHandlerCapability(e){switch(e){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${e} registered`)}}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")}async callServerTool(e,t){if(typeof e==="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:e},Mn,t)}async readServerResource(e,t){return await this.request({method:"resources/read",params:e},ri,t)}async listServerResources(e,t){return await this.request({method:"resources/list",params:e},oi,t)}sendMessage(e,t){return this.request({method:"ui/message",params:e},BE,t)}sendLog(e){return this.notification({method:"notifications/message",params:e})}updateModelContext(e,t){return this.request({method:"ui/update-model-context",params:e},_s,t)}openLink(e,t){return this.request({method:"ui/open-link",params:e},FE,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this.request({method:"ui/download-file",params:e},HE,t)}requestTeardown(e={}){return this.notification({method:"ui/notifications/request-teardown",params:e})}requestDisplayMode(e,t){return this.request({method:"ui/request-display-mode",params:e},KE,t)}sendSizeChanged(e){return this.notification({method:"ui/notifications/size-changed",params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,o=()=>{if(e)return;e=!0,requestAnimationFrame(()=>{e=!1;let s=document.documentElement,a=s.style.width,c=s.style.height;s.style.width="fit-content",s.style.height="max-content";let l=s.getBoundingClientRect();s.style.width=a,s.style.height=c;let u=window.innerWidth-s.clientWidth,p=Math.ceil(l.width+u),d=Math.ceil(l.height);if(p!==t||d!==n)t=p,n=d,this.sendSizeChanged({width:p,height:d})})};o();let r=new ResizeObserver(o);return r.observe(document.documentElement),r.observe(document.body),()=>r.disconnect()}async connect(e=new Py(window.parent,window.parent),t){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(e);try{let n=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:ME}},eI,t);if(n===void 0)throw Error(`Server sent invalid initialize result: ${n}`);if(this._hostCapabilities=n.hostCapabilities,this._hostInfo=n.hostInfo,this._hostContext=n.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize)this.setupSizeChangedNotifications()}catch(n){throw this.close(),n}}}var gc,Fe,Oy,Ld,Ho,Ny,Ly,Dy,Fy,Dd,Md,$d,tI,mc={},fc=[],nI=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,vc=Array.isArray;function po(e,t){for(var n in t)e[n]=t[n];return e}function Fd(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function oI(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?gc.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 pc(e,a,o,r,null)}function pc(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?++Oy:r,__i:-1,__u:0};return r==null&&Fe.vnode!=null&&Fe.vnode(s),s}function _e(e){return e.children}function li(e,t){this.props=e,this.context=t}function ui(e,t){if(t==null)return e.__?ui(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"?ui(e):null}function rI(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,o=[],r=[],s=po({},t);s.__v=t.__v+1,Fe.vnode&&Fe.vnode(s),Hd(e.__P,s,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,o,n==null?ui(t):n,!!(32&t.__u),r),s.__v=t.__v,s.__.__k[s.__i]=s,Uy(o,s,r),t.__e=t.__=null,s.__e!=n&&Hy(s)}}function Hy(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}),Hy(e)}function zy(e){(!e.__d&&(e.__d=!0)&&Ho.push(e)&&!hc.__r++||Ny!=Fe.debounceRendering)&&((Ny=Fe.debounceRendering)||Ly)(hc)}function hc(){try{for(var e,t=1;Ho.length;)Ho.length>t&&Ho.sort(Dy),e=Ho.shift(),t=Ho.length,rI(e)}finally{Ho.length=hc.__r=0}}function By(e,t,n,o,r,s,a,c,l,u,p){var d,m,f,h,v,w,g,x=o&&o.__k||fc,R=t.length;for(l=iI(n,t,x,l,R),d=0;d<R;d++)(f=n.__k[d])!=null&&(m=f.__i!=-1&&x[f.__i]||mc,f.__i=d,w=Hd(e,f,m,r,s,a,c,l,u,p),h=f.__e,f.ref&&m.ref!=f.ref&&(m.ref&&Bd(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=jy(f,l,e,g):typeof f.type=="function"&&w!==void 0?l=w:h&&(l=h.nextSibling),f.__u&=-7);return n.__e=v,l}function iI(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]=pc(null,a,null,null,null):vc(a)?a=e.__k[s]=pc(_e,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=e.__k[s]=pc(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=sI(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=ui(c)),Wy(c,c));return o}function jy(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=jy(r[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=ui(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function sI(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 My(e,t,n){t[0]=="-"?e.setProperty(t,n==null?"":n):e[t]=n==null?"":typeof n!="number"||nI.test(t)?n:n+"px"}function dc(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||My(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||My(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Fy,"$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=Dd,e.addEventListener(t,s?$d:Md,s)):e.removeEventListener(t,s?$d:Md,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 $y(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=Dd++;else if(t.t<n.u)return;return n(Fe.event?Fe.event(t):t)}}}function Hd(e,t,n,o,r,s,a,c,l,u){var p,d,m,f,h,v,w,g,x,R,M,O,k,N,_,E=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),s=[c=t.__e=n.__e]),(p=Fe.__b)&&p(t);e:if(typeof E=="function")try{if(g=t.props,x=E.prototype&&E.prototype.render,R=(p=E.contextType)&&o[p.__c],M=p?R?R.props.value:p.__:o,n.__c?w=(d=t.__c=n.__c).__=d.__E:(x?t.__c=d=new E(g,M):(t.__c=d=new li(g,M),d.constructor=E,d.render=cI),R&&R.sub(d),d.state||(d.state={}),d.__n=o,m=d.__d=!0,d.__h=[],d._sb=[]),x&&d.__s==null&&(d.__s=d.state),x&&E.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=po({},d.__s)),po(d.__s,E.getDerivedStateFromProps(g,d.__s))),f=d.props,h=d.state,d.__v=t,m)x&&E.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),x&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(x&&E.getDerivedStateFromProps==null&&g!==f&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(g,M),t.__v==n.__v||!d.__e&&d.shouldComponentUpdate!=null&&d.shouldComponentUpdate(g,d.__s,M)===!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)}),fc.push.apply(d.__h,d._sb),d._sb=[],d.__h.length&&a.push(d);break e}d.componentWillUpdate!=null&&d.componentWillUpdate(g,d.__s,M),x&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(f,h,v)})}if(d.context=M,d.props=g,d.__P=e,d.__e=!1,O=Fe.__r,k=0,x)d.state=d.__s,d.__d=!1,O&&O(t),p=d.render(d.props,d.state,d.context),fc.push.apply(d.__h,d._sb),d._sb=[];else do d.__d=!1,O&&O(t),p=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++k<25);d.state=d.__s,d.getChildContext!=null&&(o=po(po({},o),d.getChildContext())),x&&!m&&d.getSnapshotBeforeUpdate!=null&&(v=d.getSnapshotBeforeUpdate(f,h)),N=p!=null&&p.type===_e&&p.key==null?Zy(p.props.children):p,c=By(e,vc(N)?N:[N],t,n,o,r,s,a,c,l,u),d.base=t.__e,t.__u&=-161,d.__h.length&&a.push(d),w&&(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(_=s.length;_--;)Fd(s[_]);Od(t)}else t.__e=n.__e,t.__k=n.__k,z.then||Od(t);Fe.__e(z,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=aI(n.__e,t,n,o,r,s,a,l,u);return(p=Fe.diffed)&&p(t),128&t.__u?void 0:c}function Od(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(Od))}function Uy(e,t,n){for(var o=0;o<n.length;o++)Bd(n[o],n[++o],n[++o]);Fe.__c&&Fe.__c(t,e),e.some(function(r){try{e=r.__h,r.__h=[],e.some(function(s){s.call(r)})}catch(s){Fe.__e(s,r.__v)}})}function Zy(e){return typeof e!="object"||e==null||e.__b>0?e:vc(e)?e.map(Zy):po({},e)}function aI(e,t,n,o,r,s,a,c,l){var u,p,d,m,f,h,v,w=n.props||mc,{props:g,type:x}=t;if(x=="svg"?r="http://www.w3.org/2000/svg":x=="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==!!x&&(x?f.localName==x:f.nodeType==3)){e=f,s[u]=null;break}}if(e==null){if(x==null)return document.createTextNode(g);e=document.createElementNS(r,x,g.is&&g),c&&(Fe.__m&&Fe.__m(t,s),c=!1),s=null}if(x==null)w===g||c&&e.data==g||(e.data=g);else{if(s=s&&gc.call(e.childNodes),!c&&s!=null)for(w={},u=0;u<e.attributes.length;u++)w[(f=e.attributes[u]).name]=f.value;for(u in w)f=w[u],u=="dangerouslySetInnerHTML"?d=f:u=="children"||(u in g)||u=="value"&&("defaultValue"in g)||u=="checked"&&("defaultChecked"in g)||dc(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"||w[u]===f||dc(e,u,f,w[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=""),By(t.type=="template"?e.content:e,vc(m)?m:[m],t,n,o,x=="foreignObject"?"http://www.w3.org/1999/xhtml":r,s,a,s?s[0]:n.__k&&ui(n,0),c,l),s!=null)for(u=s.length;u--;)Fd(s[u]);c||(u="value",x=="progress"&&h==null?e.removeAttribute("value"):h!=null&&(h!==e[u]||x=="progress"&&!h||x=="option"&&h!=w[u])&&dc(e,u,h,w[u],r),u="checked",v!=null&&v!=e[u]&&dc(e,u,v,w[u],r))}return e}function Bd(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){Fe.__e(r,n)}}function Wy(e,t,n){var o,r;if(Fe.unmount&&Fe.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Bd(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){Fe.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(r=0;r<o.length;r++)o[r]&&Wy(o[r],t,n||typeof e.type!="function");n||Fd(e.__e),e.__c=e.__=e.__e=void 0}function cI(e,t,n){return this.constructor(e,n)}function Ms(e,t,n){var o,r,s,a;t==document&&(t=document.documentElement),Fe.__&&Fe.__(e,t),r=(o=typeof n=="function")?null:n&&n.__k||t.__k,s=[],a=[],Hd(t,e=(!o&&n||t).__k=oI(_e,null,[e]),r||mc,mc,t.namespaceURI,!o&&n?[n]:r?null:t.firstChild?gc.call(t.childNodes):null,s,!o&&n?n:r?r.__e:t.firstChild,o,a),Uy(s,e,a)}gc=fc.slice,Fe={__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}},Oy=0,Ld=function(e){return e!=null&&e.constructor===void 0},li.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=po({},this.state),typeof e=="function"&&(e=e(po({},n),this.props)),e&&po(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),zy(this))},li.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),zy(this))},li.prototype.render=_e,Ho=[],Ly=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Dy=function(e,t){return e.__v.__b-t.__v.__b},hc.__r=0,Fy=/(PointerCapture)$|Capture$/i,Dd=0,Md=$y(!1),$d=$y(!0),tI=0;var di,dt,jd,qy,$s=0,eb=[],ft=Fe,{__b:Gy,__r:Vy,diffed:Xy,__c:Ky,unmount:Jy,__:Yy}=ft;function bc(e,t){ft.__h&&ft.__h(dt,e,$s||t),$s=0;var n=dt.__H||(dt.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function I(e){return $s=1,lI(tb,e)}function lI(e,t,n){var o=bc(di++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):tb(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=dt,!dt.__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};dt.__f=!0;var s=dt.shouldComponentUpdate,a=dt.componentWillUpdate;dt.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)},dt.shouldComponentUpdate=r}return o.__N||o.__}function B(e,t){var n=bc(di++,3);!ft.__s&&Zd(n.__H,t)&&(n.__=e,n.u=t,dt.__H.__h.push(n))}function Cn(e,t){var n=bc(di++,4);!ft.__s&&Zd(n.__H,t)&&(n.__=e,n.u=t,dt.__h.push(n))}function L(e){return $s=5,Ze(function(){return{current:e}},[])}function Ze(e,t){var n=bc(di++,7);return Zd(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function j(e,t){return $s=8,Ze(function(){return e},t)}function uI(){for(var e;e=eb.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(yc),t.__h.some(Ud),t.__h=[]}catch(n){t.__h=[],ft.__e(n,e.__v)}}}ft.__b=function(e){dt=null,Gy&&Gy(e)},ft.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Yy&&Yy(e,t)},ft.__r=function(e){Vy&&Vy(e),di=0;var t=(dt=e.__c).__H;t&&(jd===dt?(t.__h=[],dt.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(yc),t.__h.some(Ud),t.__h=[],di=0)),jd=dt},ft.diffed=function(e){Xy&&Xy(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(eb.push(t)!==1&&qy===ft.requestAnimationFrame||((qy=ft.requestAnimationFrame)||dI)(uI)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),jd=dt=null},ft.__c=function(e,t){t.some(function(n){try{n.__h.some(yc),n.__h=n.__h.filter(function(o){return!o.__||Ud(o)})}catch(o){t.some(function(r){r.__h&&(r.__h=[])}),t=[],ft.__e(o,n.__v)}}),Ky&&Ky(e,t)},ft.unmount=function(e){Jy&&Jy(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{yc(o)}catch(r){t=r}}),n.__H=void 0,t&&ft.__e(t,n.__v))};var Qy=typeof requestAnimationFrame=="function";function dI(e){var t,n=function(){clearTimeout(o),Qy&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Qy&&(t=requestAnimationFrame(n))}function yc(e){var t=dt,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),dt=t}function Ud(e){var t=dt;e.__c=e.__(),dt=t}function Zd(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function tb(e,t){return typeof t=="function"?t(e):t}var Wd=S({x:ne(),y:ne(),scale:ne().positive()}),pI=S({target:he([cy({nodeId:C().min(1)}),cy({viewport:Wd})]),duration:ne().nonnegative().max(3600).optional(),easing:jt(["linear","ease-in-out","ease-out"]).optional(),padding:ne().nonnegative().optional(),pullback:ne().min(0).max(4).optional()}),RF=S({stops:te(pI).max(1000)});function nb(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 ob(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 qd=null;function rb(e){qd=e}function bt(){if(qd?.isConnected){let e=qd.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 Bo(){let e=bt();return{x:e.left+e.width/2,y:e.top+e.height/2}}function Gd(){let e=16;try{let t=bt(),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 mI=Symbol.for("preact-signals");function _c(){if(!(mo>1)){var e,t=!1;(function(){var r=wc;wc=void 0;while(r!==void 0){if(r.S.v===r.v)r.S.i=r.i;r=r.o}})();while(Os!==void 0){var n=Os;Os=void 0,xc++;while(n!==void 0){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&ab(n))try{n.c()}catch(r){if(!t)e=r,t=!0}n=o}}if(xc=0,mo--,t)throw e}else mo--}function mn(e){if(mo>0)return e();Vd=++fI,mo++;try{return e()}finally{_c()}}var We=void 0;function Xd(e){var t=We;We=void 0;try{return e()}finally{We=t}}var ib,Os=void 0,mo=0,xc=0,fI=0,Vd=0,wc=void 0,Sc=0;function sb(e){if(We!==void 0){var t=e.n;if(t===void 0||t.t!==We){if(t={i:0,S:e,p:We.s,n:void 0,t:We,e:void 0,x:void 0,r:t},We.s!==void 0)We.s.n=t;if(We.s=t,e.n=t,32&We.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=We.s,t.n=void 0,We.s.n=t,We.s=t}return t}}}function xt(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}xt.prototype.brand=mI;xt.prototype.h=function(){return!0};xt.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 Xd(function(){var o;(o=t.W)==null||o.call(t)})};xt.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)Xd(function(){var r;(r=t.Z)==null||r.call(t)})}}};xt.prototype.subscribe=function(e){var t=this;return on(function(){var n=t.value,o=We;We=void 0;try{e(n)}finally{We=o}},{name:"sub"})};xt.prototype.valueOf=function(){return this.value};xt.prototype.toString=function(){return this.value+""};xt.prototype.toJSON=function(){return this.value};xt.prototype.peek=function(){var e=We;We=void 0;try{return this.value}finally{We=e}};Object.defineProperty(xt.prototype,"value",{get:function(){var e=sb(this);if(e!==void 0)e.i=this.i;return this.v},set:function(e){if(e!==this.v){if(xc>100)throw Error("Cycle detected");(function(n){if(mo!==0&&xc===0){if(n.l!==Vd)n.l=Vd,wc={S:n,v:n.v,i:n.i,o:wc}}})(this),this.v=e,this.i++,Sc++,mo++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{_c()}}}});function K(e,t){return new xt(e,t)}function ab(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 cb(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 lb(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 Sr(e,t){xt.call(this,void 0),this.x=e,this.s=void 0,this.g=Sc-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}Sr.prototype=new xt;Sr.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===Sc)return!0;if(this.g=Sc,this.f|=1,this.i>0&&!ab(this))return this.f&=-2,!0;var e=We;try{cb(this),We=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 We=e,lb(this),this.f&=-2,!0};Sr.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)}xt.prototype.S.call(this,e)};Sr.prototype.U=function(e){if(this.t!==void 0){if(xt.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)}}};Sr.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(Sr.prototype,"value",{get:function(){if(1&this.f)throw Error("Cycle detected");var e=sb(this);if(this.h(),e!==void 0)e.i=this.i;if(16&this.f)throw this.v;return this.v}});function Ve(e,t){return new Sr(e,t)}function ub(e){var t=e.m;if(e.m=void 0,typeof t=="function"){mo++;var n=We;We=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,Kd(e),o}finally{We=n,_c()}}}function Kd(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,ub(e)}function hI(e){if(We!==this)throw Error("Out-of-order effect");if(lb(this),We=e,this.f&=-2,8&this.f)Kd(this);_c()}function pi(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,ib)ib.push(this)}pi.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()}};pi.prototype.S=function(){if(1&this.f)throw Error("Cycle detected");this.f|=1,this.f&=-9,ub(this),cb(this),mo++;var e=We;return We=this,hI.bind(this,e)};pi.prototype.N=function(){if(!(2&this.f))this.f|=2,this.u=Os,Os=this};pi.prototype.d=function(){if(this.f|=8,!(1&this.f))Kd(this)};pi.prototype.dispose=function(){this.d()};function on(e,t){var n=new pi(e,t);try{n.c()}catch(r){throw n.d(),r}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var db,Jd,kc,gI=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var pb=[];on(function(){db=this.N})();function mi(e,t){Fe[e]=t.bind(null,Fe[e]||function(){})}function Tc(e){if(kc){var t=kc;kc=void 0,t()}kc=e&&e.S()}function mb(e){var t=this,n=e.data,o=yI(n);o.value=n;var r=Ze(function(){var c=t,l=t.__v;while(l=l.__)if(l.__c){l.__c.__$f|=4;break}var u=Ve(function(){var f=o.value.value;return f===0?0:f===!0?"":f||""}),p=Ve(function(){return!Array.isArray(u.value)&&!Ld(u.value)}),d=on(function(){if(this.N=fb,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}mb.displayName="ReactiveTextNode";Object.defineProperties(xt.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:mb},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});mi("__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 xt){if(!n)t.__np=n={};n[r]=s,o[r]=s.peek()}}}e(t)});mi("__r",function(e,t){if(e(t),t.type!==_e){Tc();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 on(function(){a=this},{name:s}),a.c=r,a}(function(){var r;if(gI)(r=n.y)==null||r.call(n);o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:"")}Jd=o,Tc(n)}});mi("__e",function(e,t,n,o){Tc(),Jd=void 0,e(t,n,o)});mi("diffed",function(e,t){Tc(),Jd=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=vI(n,l,p),s[l]=u;else u.o(p,r)}for(var d in o)r[d]=o[d]}}e(t)});function vI(e,t,n,o){var r=t in e&&e.ownerSVGElement===void 0,s=K(n),a=n.peek();return{o:function(c,l){s.value=c,a=c.peek()},d:on(function(){this.N=fb;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})}}mi("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)});mi("__h",function(e,t,n,o){if(o<3||o===9)t.__$f|=2;e(t,n,o)});li.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 yI(e,t){return Ze(function(){return K(e,t)},[])}var bI=function(e){queueMicrotask(function(){queueMicrotask(e)})};function xI(){mn(function(){var e;while(e=pb.shift())db.call(e)})}function fb(){if(pb.push(this)===1)(Fe.requestAnimationFrame||bI)(xI)}var $t={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"},Ls=new Set(["markdown","mcp-app","webpage","json-render","graph","context","ledger","file","diff","mermaid","image","html"]);function hb(e){return e.type==="mcp-app"&&e.data.mode==="ext-app"&&e.data.serverName==="Excalidraw"&&e.data.toolName==="create_view"}function gb(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 wI(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=gb(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 SI(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 _I(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 kI(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 TI(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((x)=>x.id)),a=e.filter((x)=>(o.get(x.id)??0)===0&&(r.get(x.id)??0)>0).sort((x,R)=>x.sortKey.x-R.sortKey.x||x.sortKey.y-R.sortKey.y),c=a.length>0?a:[e.slice().sort((x,R)=>x.sortKey.x-R.sortKey.x||x.sortKey.y-R.sortKey.y)[0]],l=new Map,u=c.map((x)=>x.id);for(let x of c)l.set(x.id,0);while(u.length>0){let x=u.shift(),R=l.get(x)??0;for(let M of n.get(x)??[]){if(!s.has(M)||l.has(M))continue;l.set(M,R+1),u.push(M)}}let p=0;for(let x of e){if(l.has(x.id))continue;l.set(x.id,p),p+=1}let d=new Map;for(let x of e){let R=l.get(x.id)??0;if(!d.has(R))d.set(R,[]);d.get(R).push(x)}let m=Array.from(d.keys()).sort((x,R)=>x-R);for(let x of m)d.get(x).sort((R,M)=>R.sortKey.y-M.sortKey.y||R.sortKey.x-M.sortKey.x);let f=new Map,h=new Map,v=0;for(let x of m){let R=d.get(x),M=R.reduce((k,N,_)=>k+N.size.height+(_>0?72:0),0),O=Math.max(...R.map((k)=>k.size.width));f.set(x,M),h.set(x,O),v=Math.max(v,M)}let w=new Map,g=0;for(let x of m){let R=d.get(x),M=f.get(x)??0,O=h.get(x)??0,k=Math.max(0,(v-M)/2);for(let N of R)w.set(N.id,{x:g,y:k}),k+=N.size.height+72;g+=O+96}return{positions:w,size:{width:Math.max(0,g-96),height:v},sortKey:e[0].sortKey}}function CI(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 EI(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 Yd(e,t,n){let{units:o,nodesById:r,nodeToUnit:s}=wI(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}=SI(o,s,t),m=CI(o,u),f=new Map,h=[];for(let v of m){let w=_I(v,u).map((k)=>n==="graph"?TI(k,l,u,p,d):kI(k)),g={x:Math.min(...v.map((k)=>k.origin.x)),y:Math.min(...v.map((k)=>k.origin.y))},x=EI(w,g),R=new Map(v.map((k)=>[k.id,k.size])),M=(k)=>{let{POSITIVE_INFINITY:N,POSITIVE_INFINITY:_,NEGATIVE_INFINITY:E,NEGATIVE_INFINITY:z}=Number;for(let[X,W]of k){let J=R.get(X);if(!J)continue;N=Math.min(N,W.x),_=Math.min(_,W.y),E=Math.max(E,W.x+J.width),z=Math.max(z,W.y+J.height)}return{x:N,y:_,width:E-N,height:z-_}},O=x;for(let k=0;k<=h.length;k++){let N=M(O),_=h.filter((X)=>N.x<X.x+X.width+220&&N.x+N.width+220>X.x&&N.y<X.y+X.height+180&&N.y+N.height+180>X.y);if(_.length===0)break;let E=Math.max(..._.map((X)=>X.y+X.height))+180-N.y;if(E<=0)break;let z=new Map;for(let[X,W]of O)z.set(X,{x:W.x,y:W.y+E});O=z}for(let[k,N]of O)f.set(k,N);h.push(M(O))}for(let v of o){let w=f.get(v.id);if(!w)continue;let g=w.x-v.origin.x,x=w.y-v.origin.y;if(v.groupId){let O=[];for(let N of v.memberIds){let _=r.get(N);if(!_)continue;let E={x:_.position.x+g,y:_.position.y+x};a.set(N,E),O.push({position:E,size:_.size})}let k=gb(O);if(k)c.set(v.groupId,k);continue}let R=v.memberIds[0],M=r.get(R);if(!M)continue;a.set(R,{x:M.position.x+g,y:M.position.y+x})}return{nodePositions:a,groupBounds:c}}var II=700,AI=1600;function PI(e){return e.replace(/\r\n?/g,`
|
|
7604
|
+
- "app": Tool callable by the app from this server only`)}),bF=S({mimeTypes:te(C()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),xF=S({method:b("ui/download-file"),params:S({contents:te(he([Ps,Rs])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),wF=S({method:b("ui/message"),params:S({role:b("user").describe('Message role, currently only "user" is supported.'),content:te(lo).describe("Message content blocks (text, image, etc.).")})}),SF=S({method:b("ui/notifications/sandbox-resource-ready"),params:S({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:Rd.optional().describe("CSP configuration from resource metadata."),permissions:Nd.optional().describe("Sandbox permissions from resource metadata.")})}),YE=S({method:b("ui/notifications/tool-result"),params:Mn.describe("Standard MCP tool execution result.")}),Ry=S({toolInfo:S({id:Lo.optional().describe("JSON-RPC id of the tools/call request."),tool:ii.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:OE.optional().describe("Current color theme preference."),styles:qE.optional().describe("Style configuration for theming the app."),displayMode:zs.optional().describe("How the UI is currently displayed."),availableDisplayModes:te(zs).optional().describe("Display modes the host supports."),containerDimensions:he([S({height:ne().describe("Fixed container height in pixels.")}),S({maxHeight:he([ne(),ei()]).optional().describe("Maximum container height in pixels.")})]).and(he([S({width:ne().describe("Fixed container width in pixels.")}),S({maxWidth:he([ne(),ei()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
7605
|
+
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([b("web"),b("desktop"),b("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:S({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:S({top:ne().describe("Top safe area inset in pixels."),right:ne().describe("Right safe area inset in pixels."),bottom:ne().describe("Bottom safe area inset in pixels."),left:ne().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),QE=S({method:b("ui/notifications/host-context-changed"),params:Ry.describe("Partial context update containing only changed fields.")}),_F=S({method:b("ui/update-model-context"),params:S({content:te(lo).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:$e(C(),He().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),kF=S({method:b("ui/initialize"),params:S({appInfo:Do.describe("App identification (name and version)."),appCapabilities:XE.describe("Features and capabilities this app provides."),protocolVersion:C().describe("Protocol version this app supports.")})}),eI=S({protocolVersion:C().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Do.describe("Host application identification and version."),hostCapabilities:VE.describe("Features and capabilities provided by the host."),hostContext:Ry.describe("Rich context about the host environment.")}).passthrough();class zd extends ci{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;constructor(e,t={},n={autoResize:!0}){super(n);this._appInfo=e,this._capabilities=t,this.options=n,this.setRequestHandler(co,(o)=>(console.log("Received ping:",o.params),{})),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(e){this.setNotificationHandler(jE,(t)=>e(t.params))}set ontoolinputpartial(e){this.setNotificationHandler(UE,(t)=>e(t.params))}set ontoolresult(e){this.setNotificationHandler(YE,(t)=>e(t.params))}set ontoolcancelled(e){this.setNotificationHandler(ZE,(t)=>e(t.params))}set onhostcontextchanged(e){this.setNotificationHandler(QE,(t)=>{this._hostContext={...this._hostContext,...t.params},e(t.params)})}set onteardown(e){this.setRequestHandler(GE,(t,n)=>e(t.params,n))}set oncalltool(e){this.setRequestHandler(ai,(t,n)=>e(t.params,n))}set onlisttools(e){this.setRequestHandler(si,(t,n)=>e(t.params,n))}assertCapabilityForMethod(e){}assertRequestHandlerCapability(e){switch(e){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${e} registered`)}}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")}async callServerTool(e,t){if(typeof e==="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:e},Mn,t)}async readServerResource(e,t){return await this.request({method:"resources/read",params:e},ri,t)}async listServerResources(e,t){return await this.request({method:"resources/list",params:e},oi,t)}sendMessage(e,t){return this.request({method:"ui/message",params:e},BE,t)}sendLog(e){return this.notification({method:"notifications/message",params:e})}updateModelContext(e,t){return this.request({method:"ui/update-model-context",params:e},_s,t)}openLink(e,t){return this.request({method:"ui/open-link",params:e},FE,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this.request({method:"ui/download-file",params:e},HE,t)}requestTeardown(e={}){return this.notification({method:"ui/notifications/request-teardown",params:e})}requestDisplayMode(e,t){return this.request({method:"ui/request-display-mode",params:e},KE,t)}sendSizeChanged(e){return this.notification({method:"ui/notifications/size-changed",params:e})}setupSizeChangedNotifications(){let e=!1,t=0,n=0,o=()=>{if(e)return;e=!0,requestAnimationFrame(()=>{e=!1;let s=document.documentElement,a=s.style.width,c=s.style.height;s.style.width="fit-content",s.style.height="max-content";let l=s.getBoundingClientRect();s.style.width=a,s.style.height=c;let u=window.innerWidth-s.clientWidth,p=Math.ceil(l.width+u),d=Math.ceil(l.height);if(p!==t||d!==n)t=p,n=d,this.sendSizeChanged({width:p,height:d})})};o();let r=new ResizeObserver(o);return r.observe(document.documentElement),r.observe(document.body),()=>r.disconnect()}async connect(e=new Py(window.parent,window.parent),t){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(e);try{let n=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:ME}},eI,t);if(n===void 0)throw Error(`Server sent invalid initialize result: ${n}`);if(this._hostCapabilities=n.hostCapabilities,this._hostInfo=n.hostInfo,this._hostContext=n.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize)this.setupSizeChangedNotifications()}catch(n){throw this.close(),n}}}var gc,Fe,Oy,Ld,Ho,Ny,Ly,Dy,Fy,Dd,Md,$d,tI,mc={},fc=[],nI=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,vc=Array.isArray;function po(e,t){for(var n in t)e[n]=t[n];return e}function Fd(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function oI(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?gc.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 pc(e,a,o,r,null)}function pc(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?++Oy:r,__i:-1,__u:0};return r==null&&Fe.vnode!=null&&Fe.vnode(s),s}function _e(e){return e.children}function li(e,t){this.props=e,this.context=t}function ui(e,t){if(t==null)return e.__?ui(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"?ui(e):null}function rI(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,o=[],r=[],s=po({},t);s.__v=t.__v+1,Fe.vnode&&Fe.vnode(s),Hd(e.__P,s,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,o,n==null?ui(t):n,!!(32&t.__u),r),s.__v=t.__v,s.__.__k[s.__i]=s,Uy(o,s,r),t.__e=t.__=null,s.__e!=n&&Hy(s)}}function Hy(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}),Hy(e)}function zy(e){(!e.__d&&(e.__d=!0)&&Ho.push(e)&&!hc.__r++||Ny!=Fe.debounceRendering)&&((Ny=Fe.debounceRendering)||Ly)(hc)}function hc(){try{for(var e,t=1;Ho.length;)Ho.length>t&&Ho.sort(Dy),e=Ho.shift(),t=Ho.length,rI(e)}finally{Ho.length=hc.__r=0}}function By(e,t,n,o,r,s,a,c,l,u,p){var d,m,f,h,v,w,g,x=o&&o.__k||fc,R=t.length;for(l=iI(n,t,x,l,R),d=0;d<R;d++)(f=n.__k[d])!=null&&(m=f.__i!=-1&&x[f.__i]||mc,f.__i=d,w=Hd(e,f,m,r,s,a,c,l,u,p),h=f.__e,f.ref&&m.ref!=f.ref&&(m.ref&&Bd(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=jy(f,l,e,g):typeof f.type=="function"&&w!==void 0?l=w:h&&(l=h.nextSibling),f.__u&=-7);return n.__e=v,l}function iI(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]=pc(null,a,null,null,null):vc(a)?a=e.__k[s]=pc(_e,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=e.__k[s]=pc(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=sI(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=ui(c)),Wy(c,c));return o}function jy(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=jy(r[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=ui(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function sI(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 My(e,t,n){t[0]=="-"?e.setProperty(t,n==null?"":n):e[t]=n==null?"":typeof n!="number"||nI.test(t)?n:n+"px"}function dc(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||My(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||My(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Fy,"$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=Dd,e.addEventListener(t,s?$d:Md,s)):e.removeEventListener(t,s?$d:Md,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 $y(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=Dd++;else if(t.t<n.u)return;return n(Fe.event?Fe.event(t):t)}}}function Hd(e,t,n,o,r,s,a,c,l,u){var p,d,m,f,h,v,w,g,x,R,M,O,k,N,_,E=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),s=[c=t.__e=n.__e]),(p=Fe.__b)&&p(t);e:if(typeof E=="function")try{if(g=t.props,x=E.prototype&&E.prototype.render,R=(p=E.contextType)&&o[p.__c],M=p?R?R.props.value:p.__:o,n.__c?w=(d=t.__c=n.__c).__=d.__E:(x?t.__c=d=new E(g,M):(t.__c=d=new li(g,M),d.constructor=E,d.render=cI),R&&R.sub(d),d.state||(d.state={}),d.__n=o,m=d.__d=!0,d.__h=[],d._sb=[]),x&&d.__s==null&&(d.__s=d.state),x&&E.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=po({},d.__s)),po(d.__s,E.getDerivedStateFromProps(g,d.__s))),f=d.props,h=d.state,d.__v=t,m)x&&E.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),x&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(x&&E.getDerivedStateFromProps==null&&g!==f&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(g,M),t.__v==n.__v||!d.__e&&d.shouldComponentUpdate!=null&&d.shouldComponentUpdate(g,d.__s,M)===!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)}),fc.push.apply(d.__h,d._sb),d._sb=[],d.__h.length&&a.push(d);break e}d.componentWillUpdate!=null&&d.componentWillUpdate(g,d.__s,M),x&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(f,h,v)})}if(d.context=M,d.props=g,d.__P=e,d.__e=!1,O=Fe.__r,k=0,x)d.state=d.__s,d.__d=!1,O&&O(t),p=d.render(d.props,d.state,d.context),fc.push.apply(d.__h,d._sb),d._sb=[];else do d.__d=!1,O&&O(t),p=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++k<25);d.state=d.__s,d.getChildContext!=null&&(o=po(po({},o),d.getChildContext())),x&&!m&&d.getSnapshotBeforeUpdate!=null&&(v=d.getSnapshotBeforeUpdate(f,h)),N=p!=null&&p.type===_e&&p.key==null?Zy(p.props.children):p,c=By(e,vc(N)?N:[N],t,n,o,r,s,a,c,l,u),d.base=t.__e,t.__u&=-161,d.__h.length&&a.push(d),w&&(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(_=s.length;_--;)Fd(s[_]);Od(t)}else t.__e=n.__e,t.__k=n.__k,z.then||Od(t);Fe.__e(z,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=aI(n.__e,t,n,o,r,s,a,l,u);return(p=Fe.diffed)&&p(t),128&t.__u?void 0:c}function Od(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(Od))}function Uy(e,t,n){for(var o=0;o<n.length;o++)Bd(n[o],n[++o],n[++o]);Fe.__c&&Fe.__c(t,e),e.some(function(r){try{e=r.__h,r.__h=[],e.some(function(s){s.call(r)})}catch(s){Fe.__e(s,r.__v)}})}function Zy(e){return typeof e!="object"||e==null||e.__b>0?e:vc(e)?e.map(Zy):po({},e)}function aI(e,t,n,o,r,s,a,c,l){var u,p,d,m,f,h,v,w=n.props||mc,{props:g,type:x}=t;if(x=="svg"?r="http://www.w3.org/2000/svg":x=="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==!!x&&(x?f.localName==x:f.nodeType==3)){e=f,s[u]=null;break}}if(e==null){if(x==null)return document.createTextNode(g);e=document.createElementNS(r,x,g.is&&g),c&&(Fe.__m&&Fe.__m(t,s),c=!1),s=null}if(x==null)w===g||c&&e.data==g||(e.data=g);else{if(s=s&&gc.call(e.childNodes),!c&&s!=null)for(w={},u=0;u<e.attributes.length;u++)w[(f=e.attributes[u]).name]=f.value;for(u in w)f=w[u],u=="dangerouslySetInnerHTML"?d=f:u=="children"||(u in g)||u=="value"&&("defaultValue"in g)||u=="checked"&&("defaultChecked"in g)||dc(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"||w[u]===f||dc(e,u,f,w[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=""),By(t.type=="template"?e.content:e,vc(m)?m:[m],t,n,o,x=="foreignObject"?"http://www.w3.org/1999/xhtml":r,s,a,s?s[0]:n.__k&&ui(n,0),c,l),s!=null)for(u=s.length;u--;)Fd(s[u]);c||(u="value",x=="progress"&&h==null?e.removeAttribute("value"):h!=null&&(h!==e[u]||x=="progress"&&!h||x=="option"&&h!=w[u])&&dc(e,u,h,w[u],r),u="checked",v!=null&&v!=e[u]&&dc(e,u,v,w[u],r))}return e}function Bd(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){Fe.__e(r,n)}}function Wy(e,t,n){var o,r;if(Fe.unmount&&Fe.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Bd(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){Fe.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(r=0;r<o.length;r++)o[r]&&Wy(o[r],t,n||typeof e.type!="function");n||Fd(e.__e),e.__c=e.__=e.__e=void 0}function cI(e,t,n){return this.constructor(e,n)}function Ms(e,t,n){var o,r,s,a;t==document&&(t=document.documentElement),Fe.__&&Fe.__(e,t),r=(o=typeof n=="function")?null:n&&n.__k||t.__k,s=[],a=[],Hd(t,e=(!o&&n||t).__k=oI(_e,null,[e]),r||mc,mc,t.namespaceURI,!o&&n?[n]:r?null:t.firstChild?gc.call(t.childNodes):null,s,!o&&n?n:r?r.__e:t.firstChild,o,a),Uy(s,e,a)}gc=fc.slice,Fe={__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}},Oy=0,Ld=function(e){return e!=null&&e.constructor===void 0},li.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=po({},this.state),typeof e=="function"&&(e=e(po({},n),this.props)),e&&po(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),zy(this))},li.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),zy(this))},li.prototype.render=_e,Ho=[],Ly=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Dy=function(e,t){return e.__v.__b-t.__v.__b},hc.__r=0,Fy=/(PointerCapture)$|Capture$/i,Dd=0,Md=$y(!1),$d=$y(!0),tI=0;var di,dt,jd,qy,$s=0,eb=[],ft=Fe,{__b:Gy,__r:Vy,diffed:Xy,__c:Ky,unmount:Jy,__:Yy}=ft;function bc(e,t){ft.__h&&ft.__h(dt,e,$s||t),$s=0;var n=dt.__H||(dt.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function I(e){return $s=1,lI(tb,e)}function lI(e,t,n){var o=bc(di++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):tb(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=dt,!dt.__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};dt.__f=!0;var s=dt.shouldComponentUpdate,a=dt.componentWillUpdate;dt.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)},dt.shouldComponentUpdate=r}return o.__N||o.__}function B(e,t){var n=bc(di++,3);!ft.__s&&Zd(n.__H,t)&&(n.__=e,n.u=t,dt.__H.__h.push(n))}function Cn(e,t){var n=bc(di++,4);!ft.__s&&Zd(n.__H,t)&&(n.__=e,n.u=t,dt.__h.push(n))}function L(e){return $s=5,Ze(function(){return{current:e}},[])}function Ze(e,t){var n=bc(di++,7);return Zd(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function j(e,t){return $s=8,Ze(function(){return e},t)}function uI(){for(var e;e=eb.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(yc),t.__h.some(Ud),t.__h=[]}catch(n){t.__h=[],ft.__e(n,e.__v)}}}ft.__b=function(e){dt=null,Gy&&Gy(e)},ft.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Yy&&Yy(e,t)},ft.__r=function(e){Vy&&Vy(e),di=0;var t=(dt=e.__c).__H;t&&(jd===dt?(t.__h=[],dt.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(yc),t.__h.some(Ud),t.__h=[],di=0)),jd=dt},ft.diffed=function(e){Xy&&Xy(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(eb.push(t)!==1&&qy===ft.requestAnimationFrame||((qy=ft.requestAnimationFrame)||dI)(uI)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),jd=dt=null},ft.__c=function(e,t){t.some(function(n){try{n.__h.some(yc),n.__h=n.__h.filter(function(o){return!o.__||Ud(o)})}catch(o){t.some(function(r){r.__h&&(r.__h=[])}),t=[],ft.__e(o,n.__v)}}),Ky&&Ky(e,t)},ft.unmount=function(e){Jy&&Jy(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{yc(o)}catch(r){t=r}}),n.__H=void 0,t&&ft.__e(t,n.__v))};var Qy=typeof requestAnimationFrame=="function";function dI(e){var t,n=function(){clearTimeout(o),Qy&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Qy&&(t=requestAnimationFrame(n))}function yc(e){var t=dt,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),dt=t}function Ud(e){var t=dt;e.__c=e.__(),dt=t}function Zd(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function tb(e,t){return typeof t=="function"?t(e):t}var Wd=S({x:ne(),y:ne(),scale:ne().positive()}),pI=S({target:he([cy({nodeId:C().min(1)}),cy({viewport:Wd})]),duration:ne().nonnegative().max(3600).optional(),easing:jt(["linear","ease-in-out","ease-out"]).optional(),padding:ne().nonnegative().optional(),pullback:ne().min(0).max(4).optional()}),NF=S({stops:te(pI).max(1000)});function nb(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 ob(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 qd=null;function rb(e){qd=e}function bt(){if(qd?.isConnected){let e=qd.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 Bo(){let e=bt();return{x:e.left+e.width/2,y:e.top+e.height/2}}function Gd(){let e=16;try{let t=bt(),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 mI=Symbol.for("preact-signals");function _c(){if(!(mo>1)){var e,t=!1;(function(){var r=wc;wc=void 0;while(r!==void 0){if(r.S.v===r.v)r.S.i=r.i;r=r.o}})();while(Os!==void 0){var n=Os;Os=void 0,xc++;while(n!==void 0){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&ab(n))try{n.c()}catch(r){if(!t)e=r,t=!0}n=o}}if(xc=0,mo--,t)throw e}else mo--}function mn(e){if(mo>0)return e();Vd=++fI,mo++;try{return e()}finally{_c()}}var We=void 0;function Xd(e){var t=We;We=void 0;try{return e()}finally{We=t}}var ib,Os=void 0,mo=0,xc=0,fI=0,Vd=0,wc=void 0,Sc=0;function sb(e){if(We!==void 0){var t=e.n;if(t===void 0||t.t!==We){if(t={i:0,S:e,p:We.s,n:void 0,t:We,e:void 0,x:void 0,r:t},We.s!==void 0)We.s.n=t;if(We.s=t,e.n=t,32&We.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=We.s,t.n=void 0,We.s.n=t,We.s=t}return t}}}function xt(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}xt.prototype.brand=mI;xt.prototype.h=function(){return!0};xt.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 Xd(function(){var o;(o=t.W)==null||o.call(t)})};xt.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)Xd(function(){var r;(r=t.Z)==null||r.call(t)})}}};xt.prototype.subscribe=function(e){var t=this;return on(function(){var n=t.value,o=We;We=void 0;try{e(n)}finally{We=o}},{name:"sub"})};xt.prototype.valueOf=function(){return this.value};xt.prototype.toString=function(){return this.value+""};xt.prototype.toJSON=function(){return this.value};xt.prototype.peek=function(){var e=We;We=void 0;try{return this.value}finally{We=e}};Object.defineProperty(xt.prototype,"value",{get:function(){var e=sb(this);if(e!==void 0)e.i=this.i;return this.v},set:function(e){if(e!==this.v){if(xc>100)throw Error("Cycle detected");(function(n){if(mo!==0&&xc===0){if(n.l!==Vd)n.l=Vd,wc={S:n,v:n.v,i:n.i,o:wc}}})(this),this.v=e,this.i++,Sc++,mo++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{_c()}}}});function K(e,t){return new xt(e,t)}function ab(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 cb(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 lb(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 Sr(e,t){xt.call(this,void 0),this.x=e,this.s=void 0,this.g=Sc-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}Sr.prototype=new xt;Sr.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===Sc)return!0;if(this.g=Sc,this.f|=1,this.i>0&&!ab(this))return this.f&=-2,!0;var e=We;try{cb(this),We=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 We=e,lb(this),this.f&=-2,!0};Sr.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)}xt.prototype.S.call(this,e)};Sr.prototype.U=function(e){if(this.t!==void 0){if(xt.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)}}};Sr.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(Sr.prototype,"value",{get:function(){if(1&this.f)throw Error("Cycle detected");var e=sb(this);if(this.h(),e!==void 0)e.i=this.i;if(16&this.f)throw this.v;return this.v}});function Ve(e,t){return new Sr(e,t)}function ub(e){var t=e.m;if(e.m=void 0,typeof t=="function"){mo++;var n=We;We=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,Kd(e),o}finally{We=n,_c()}}}function Kd(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,ub(e)}function hI(e){if(We!==this)throw Error("Out-of-order effect");if(lb(this),We=e,this.f&=-2,8&this.f)Kd(this);_c()}function pi(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,ib)ib.push(this)}pi.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()}};pi.prototype.S=function(){if(1&this.f)throw Error("Cycle detected");this.f|=1,this.f&=-9,ub(this),cb(this),mo++;var e=We;return We=this,hI.bind(this,e)};pi.prototype.N=function(){if(!(2&this.f))this.f|=2,this.u=Os,Os=this};pi.prototype.d=function(){if(this.f|=8,!(1&this.f))Kd(this)};pi.prototype.dispose=function(){this.d()};function on(e,t){var n=new pi(e,t);try{n.c()}catch(r){throw n.d(),r}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var db,Jd,kc,gI=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var pb=[];on(function(){db=this.N})();function mi(e,t){Fe[e]=t.bind(null,Fe[e]||function(){})}function Tc(e){if(kc){var t=kc;kc=void 0,t()}kc=e&&e.S()}function mb(e){var t=this,n=e.data,o=yI(n);o.value=n;var r=Ze(function(){var c=t,l=t.__v;while(l=l.__)if(l.__c){l.__c.__$f|=4;break}var u=Ve(function(){var f=o.value.value;return f===0?0:f===!0?"":f||""}),p=Ve(function(){return!Array.isArray(u.value)&&!Ld(u.value)}),d=on(function(){if(this.N=fb,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}mb.displayName="ReactiveTextNode";Object.defineProperties(xt.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:mb},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});mi("__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 xt){if(!n)t.__np=n={};n[r]=s,o[r]=s.peek()}}}e(t)});mi("__r",function(e,t){if(e(t),t.type!==_e){Tc();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 on(function(){a=this},{name:s}),a.c=r,a}(function(){var r;if(gI)(r=n.y)==null||r.call(n);o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:"")}Jd=o,Tc(n)}});mi("__e",function(e,t,n,o){Tc(),Jd=void 0,e(t,n,o)});mi("diffed",function(e,t){Tc(),Jd=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=vI(n,l,p),s[l]=u;else u.o(p,r)}for(var d in o)r[d]=o[d]}}e(t)});function vI(e,t,n,o){var r=t in e&&e.ownerSVGElement===void 0,s=K(n),a=n.peek();return{o:function(c,l){s.value=c,a=c.peek()},d:on(function(){this.N=fb;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})}}mi("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)});mi("__h",function(e,t,n,o){if(o<3||o===9)t.__$f|=2;e(t,n,o)});li.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 yI(e,t){return Ze(function(){return K(e,t)},[])}var bI=function(e){queueMicrotask(function(){queueMicrotask(e)})};function xI(){mn(function(){var e;while(e=pb.shift())db.call(e)})}function fb(){if(pb.push(this)===1)(Fe.requestAnimationFrame||bI)(xI)}var $t={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"},Ls=new Set(["markdown","mcp-app","webpage","json-render","graph","context","ledger","file","diff","mermaid","image","html"]);function hb(e){return e.type==="mcp-app"&&e.data.mode==="ext-app"&&e.data.serverName==="Excalidraw"&&e.data.toolName==="create_view"}function gb(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 wI(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=gb(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 SI(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 _I(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 kI(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 TI(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((x)=>x.id)),a=e.filter((x)=>(o.get(x.id)??0)===0&&(r.get(x.id)??0)>0).sort((x,R)=>x.sortKey.x-R.sortKey.x||x.sortKey.y-R.sortKey.y),c=a.length>0?a:[e.slice().sort((x,R)=>x.sortKey.x-R.sortKey.x||x.sortKey.y-R.sortKey.y)[0]],l=new Map,u=c.map((x)=>x.id);for(let x of c)l.set(x.id,0);while(u.length>0){let x=u.shift(),R=l.get(x)??0;for(let M of n.get(x)??[]){if(!s.has(M)||l.has(M))continue;l.set(M,R+1),u.push(M)}}let p=0;for(let x of e){if(l.has(x.id))continue;l.set(x.id,p),p+=1}let d=new Map;for(let x of e){let R=l.get(x.id)??0;if(!d.has(R))d.set(R,[]);d.get(R).push(x)}let m=Array.from(d.keys()).sort((x,R)=>x-R);for(let x of m)d.get(x).sort((R,M)=>R.sortKey.y-M.sortKey.y||R.sortKey.x-M.sortKey.x);let f=new Map,h=new Map,v=0;for(let x of m){let R=d.get(x),M=R.reduce((k,N,_)=>k+N.size.height+(_>0?72:0),0),O=Math.max(...R.map((k)=>k.size.width));f.set(x,M),h.set(x,O),v=Math.max(v,M)}let w=new Map,g=0;for(let x of m){let R=d.get(x),M=f.get(x)??0,O=h.get(x)??0,k=Math.max(0,(v-M)/2);for(let N of R)w.set(N.id,{x:g,y:k}),k+=N.size.height+72;g+=O+96}return{positions:w,size:{width:Math.max(0,g-96),height:v},sortKey:e[0].sortKey}}function CI(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 EI(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 Yd(e,t,n){let{units:o,nodesById:r,nodeToUnit:s}=wI(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}=SI(o,s,t),m=CI(o,u),f=new Map,h=[];for(let v of m){let w=_I(v,u).map((k)=>n==="graph"?TI(k,l,u,p,d):kI(k)),g={x:Math.min(...v.map((k)=>k.origin.x)),y:Math.min(...v.map((k)=>k.origin.y))},x=EI(w,g),R=new Map(v.map((k)=>[k.id,k.size])),M=(k)=>{let{POSITIVE_INFINITY:N,POSITIVE_INFINITY:_,NEGATIVE_INFINITY:E,NEGATIVE_INFINITY:z}=Number;for(let[X,W]of k){let J=R.get(X);if(!J)continue;N=Math.min(N,W.x),_=Math.min(_,W.y),E=Math.max(E,W.x+J.width),z=Math.max(z,W.y+J.height)}return{x:N,y:_,width:E-N,height:z-_}},O=x;for(let k=0;k<=h.length;k++){let N=M(O),_=h.filter((X)=>N.x<X.x+X.width+220&&N.x+N.width+220>X.x&&N.y<X.y+X.height+180&&N.y+N.height+180>X.y);if(_.length===0)break;let E=Math.max(..._.map((X)=>X.y+X.height))+180-N.y;if(E<=0)break;let z=new Map;for(let[X,W]of O)z.set(X,{x:W.x,y:W.y+E});O=z}for(let[k,N]of O)f.set(k,N);h.push(M(O))}for(let v of o){let w=f.get(v.id);if(!w)continue;let g=w.x-v.origin.x,x=w.y-v.origin.y;if(v.groupId){let O=[];for(let N of v.memberIds){let _=r.get(N);if(!_)continue;let E={x:_.position.x+g,y:_.position.y+x};a.set(N,E),O.push({position:E,size:_.size})}let k=gb(O);if(k)c.set(v.groupId,k);continue}let R=v.memberIds[0],M=r.get(R);if(!M)continue;a.set(R,{x:M.position.x+g,y:M.position.y+x})}return{nodePositions:a,groupBounds:c}}var II=700,AI=1600;function PI(e){return e.replace(/\r\n?/g,`
|
|
7605
7606
|
`).replace(/[ \t\f\v]+/g," ").replace(/\n\s+/g,`
|
|
7606
7607
|
`).replace(/\s+\n/g,`
|
|
7607
7608
|
`).replace(/\n{3,}/g,`
|
|
@@ -7726,10 +7727,10 @@ Individual style keys are optional - hosts may provide any subset of these value
|
|
|
7726
7727
|
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
7727
7728
|
|
|
7728
7729
|
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
7729
|
-
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),S1=S({method:b("ui/open-link"),params:S({url:C().describe("URL to open in the host's browser")})}),
|
|
7730
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),S1=S({method:b("ui/open-link"),params:S({url:C().describe("URL to open in the host's browser")})}),fU=S({isError:Re().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),hU=S({isError:Re().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),gU=S({isError:Re().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),_1=S({method:b("ui/notifications/sandbox-proxy-ready"),params:S({})}),pm=S({connectDomains:te(C()).optional().describe(`Origins for network requests (fetch/XHR/WebSocket).
|
|
7730
7731
|
|
|
7731
7732
|
- Maps to CSP \`connect-src\` directive
|
|
7732
|
-
- Empty or omitted → no network connections (secure default)`),resourceDomains:te(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:te(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:te(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'`)")}),mm=S({camera:S({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:S({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:S({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:S({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),k1=S({method:b("ui/notifications/size-changed"),params:S({width:ne().optional().describe("New width in pixels."),height:ne().optional().describe("New height in pixels.")})}),
|
|
7733
|
+
- Empty or omitted → no network connections (secure default)`),resourceDomains:te(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:te(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:te(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'`)")}),mm=S({camera:S({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:S({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:S({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:S({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),k1=S({method:b("ui/notifications/size-changed"),params:S({width:ne().optional().describe("New width in pixels."),height:ne().optional().describe("New height in pixels.")})}),vU=S({method:b("ui/notifications/tool-input"),params:S({arguments:$e(C(),He().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),yU=S({method:b("ui/notifications/tool-input-partial"),params:S({arguments:$e(C(),He().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),bU=S({method:b("ui/notifications/tool-cancelled"),params:S({reason:C().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),T1=S({fonts:C().optional()}),C1=S({variables:w1.optional().describe("CSS variables for theming the app."),css:T1.optional().describe("CSS blocks that apps can inject.")}),xU=S({method:b("ui/resource-teardown"),params:S({})}),E1=$e(C(),He()),CS=S({text:S({}).optional().describe("Host supports text content blocks."),image:S({}).optional().describe("Host supports image content blocks."),audio:S({}).optional().describe("Host supports audio content blocks."),resource:S({}).optional().describe("Host supports resource content blocks."),resourceLink:S({}).optional().describe("Host supports resource link content blocks."),structuredContent:S({}).optional().describe("Host supports structured content.")}),I1=S({method:b("ui/notifications/request-teardown"),params:S({}).optional()}),A1=S({experimental:S({}).optional().describe("Experimental features (structure TBD)."),openLinks:S({}).optional().describe("Host supports opening external URLs."),downloadFile:S({}).optional().describe("Host supports file downloads via ui/download-file."),serverTools:S({listChanged:Re().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:S({listChanged:Re().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:S({}).optional().describe("Host accepts log messages."),sandbox:S({permissions:mm.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:pm.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:CS.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:CS.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),P1=S({experimental:S({}).optional().describe("Experimental features (structure TBD)."),tools:S({listChanged:Re().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:te(ca).optional().describe("Display modes the app supports.")}),R1=S({method:b("ui/notifications/initialized"),params:S({}).optional()}),wU=S({csp:pm.optional().describe("Content Security Policy configuration for UI resources."),permissions:mm.optional().describe("Sandbox permissions requested by the UI resource."),domain:C().optional().describe(`Dedicated origin for view sandbox.
|
|
7733
7734
|
|
|
7734
7735
|
Useful when views need stable, dedicated origins for OAuth callbacks, CORS policies, or API key allowlists.
|
|
7735
7736
|
|
|
@@ -7743,10 +7744,10 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
7743
7744
|
|
|
7744
7745
|
- \`true\`: request visible border + background
|
|
7745
7746
|
- \`false\`: request no visible border + background
|
|
7746
|
-
- omitted: host decides border`)}),ES=S({method:b("ui/request-display-mode"),params:S({mode:ca.describe("The display mode being requested.")})}),
|
|
7747
|
+
- omitted: host decides border`)}),ES=S({method:b("ui/request-display-mode"),params:S({mode:ca.describe("The display mode being requested.")})}),SU=S({mode:ca.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),N1=he([b("model"),b("app")]).describe("Tool visibility scope - who can access the tool."),_U=S({resourceUri:C().optional(),visibility:te(N1).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
7747
7748
|
- "model": Tool visible to and callable by the agent
|
|
7748
|
-
- "app": Tool callable by the app from this server only`)}),
|
|
7749
|
-
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([b("web"),b("desktop"),b("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:S({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:S({top:ne().describe("Top safe area inset in pixels."),right:ne().describe("Right safe area inset in pixels."),bottom:ne().describe("Bottom safe area inset in pixels."),left:ne().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),CU=S({method:b("ui/notifications/host-context-changed"),params:AS.describe("Partial context update containing only changed fields.")}),$1=S({method:b("ui/update-model-context"),params:S({content:te(lo).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:$e(C(),He().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),O1=S({method:b("ui/initialize"),params:S({appInfo:Do.describe("App identification (name and version)."),appCapabilities:P1.describe("Features and capabilities this app provides."),protocolVersion:C().describe("Protocol version this app supports.")})}),EU=S({protocolVersion:C().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Do.describe("Host application identification and version."),hostCapabilities:A1.describe("Features and capabilities provided by the host."),hostContext:AS.describe("Rich context about the host environment.")}).passthrough();class fm{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=tc.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!==y1)console.debug("Sending message",e);this.eventTarget.postMessage(e,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}function PS(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 L1=[IS];class hm extends ci{_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(O1,(r)=>this._oninitialize(r)),this.setRequestHandler(co,(r,s)=>(this.onping?.(r.params,s),{})),this.setRequestHandler(ES,(r)=>({mode:this._hostContext.displayMode??"inline"}))}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;set onsizechange(e){this.setNotificationHandler(k1,(t)=>e(t.params))}set onsandboxready(e){this.setNotificationHandler(_1,(t)=>e(t.params))}set oninitialized(e){this.setNotificationHandler(R1,(t)=>e(t.params))}set onmessage(e){this.setRequestHandler(M1,async(t,n)=>e(t.params,n))}set onopenlink(e){this.setRequestHandler(S1,async(t,n)=>e(t.params,n))}set ondownloadfile(e){this.setRequestHandler(z1,async(t,n)=>e(t.params,n))}set onrequestteardown(e){this.setNotificationHandler(I1,(t)=>e(t.params))}set onrequestdisplaymode(e){this.setRequestHandler(ES,async(t,n)=>e(t.params,n))}set onloggingmessage(e){this.setNotificationHandler(Id,async(t)=>{e(t.params)})}set onupdatemodelcontext(e){this.setRequestHandler($1,async(t,n)=>e(t.params,n))}set oncalltool(e){this.setRequestHandler(ai,async(t,n)=>e(t.params,n))}sendToolListChanged(e={}){return this.notification({method:"notifications/tools/list_changed",params:e})}set onlistresources(e){this.setRequestHandler(hd,async(t,n)=>e(t.params,n))}set onlistresourcetemplates(e){this.setRequestHandler(gd,async(t,n)=>e(t.params,n))}set onreadresource(e){this.setRequestHandler(bd,async(t,n)=>e(t.params,n))}sendResourceListChanged(e={}){return this.notification({method:"notifications/resources/list_changed",params:e})}set onlistprompts(e){this.setRequestHandler(wd,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:L1.includes(t)?t:IS,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(D1(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},E1,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},Mn,{signal:o.signal}),t.tools.listChanged)this._client.setNotificationHandler(Ed,(n)=>this.sendToolListChanged(n.params))}if(t.resources){if(this.onlistresources=async(n,o)=>this._client.request({method:"resources/list",params:n},oi,{signal:o.signal}),this.onlistresourcetemplates=async(n,o)=>this._client.request({method:"resources/templates/list",params:n},vd,{signal:o.signal}),this.onreadresource=async(n,o)=>this._client.request({method:"resources/read",params:n},ri,{signal:o.signal}),t.resources.listChanged)this._client.setNotificationHandler(xd,(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(Cd,(n)=>this.sendPromptListChanged(n.params))}}return super.connect(e)}}function D1(e,t){return JSON.stringify(e)===JSON.stringify(t)}function gm(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function F1(e){return gm(e)&&Array.isArray(e.content)&&e.content.every((t)=>gm(t)&&typeof t.type==="string")}function H1(...e){for(let t of e)if(typeof t==="string"){if(t.trim().length>0)return t}return}function B1(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 vm(e){let t=e.success===!1;if(F1(e.result))return{...e.result,isError:e.result.isError===!0||t};let n=gm(e.result)?e.result:null,o=H1(e.detailedContent,e.content,n?.detailedContent,n?.content,n?.textResultForLlm,n?.text,n?.message,typeof e.result==="string"?e.result:void 0,e.error)??B1(e.result);return{content:o?[{type:"text",text:o}]:[],isError:t}}function RS(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 NS(e){return Boolean(e)&&typeof e==="object"&&e!==null&&!Array.isArray(e)&&"ok"in e&&typeof e.ok==="boolean"}async function j1(e,t){let n=await ct("/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||!NS(o)||!o.ok||typeof o.url!=="string"){let r=NS(o)&&o.error?o.error:`Frame document request failed with HTTP ${n.status}`;throw Error(r)}return o.url}function zS(e,t){let n=Lt.value,[o,r]=I(null),[s,a]=I(0),c=L(0);B(()=>{if(r(null),!e||n!=="src")return;let u=!1;return c.current=Ar.value,j1(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=Ar.value;return B(()=>{if(n!=="src"||l===c.current)return;if(!o){a((p)=>p+1);return}let u=!1;return ct(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]),Ze(()=>{if(n==="srcdoc"&&e)return{attributes:{srcdoc:e},ready:!0,key:`srcdoc-${Mi(e)}`};return{attributes:o?{src:o}:{},ready:Boolean(o),key:o??""}},[o,n,e])}function ji(e){let{enabled:t,token:n,nodeId:o,sourceSurface:r,iframeRef:s}=e;Cn(()=>{if(!t||!n)return;function a(c){if(c.source!==s.current?.contentWindow)return;let l=c.data;if(!l||l.source!==kl||l.token!==n||l.nodeId!==o)return;let u=l.interaction;if(!u||typeof u.type!=="string")return;let p=u.type;qc({type:p,sourceNodeId:o,sourceSurface:r,...u.payload&&typeof u.payload==="object"?{payload:u.payload}:{}}).then((d)=>{if(d.ok)rn("context","AX interaction",p,[o]);s.current?.contentWindow?.postMessage({source:Tl,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 Lr(e,t){let o=await(await ct(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 Dr(e){return/AppleWebKit/.test(e)&&!/Chrome|Chromium|CriOS|Edg|Android/.test(e)}function U1(e){let{userAgent:t,visibilityState:n,rect:o,viewport:r,alreadyRearmed:s}=e;if(s)return!1;if(!Dr(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 BS=1000,MS=7000;function It(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});Z1({t:Date.now(),nodeId:e,event:t})}var $S=[],ym=null;function Z1(e){if($S.push({...e,...typeof document<"u"?{visibility:document.visibilityState}:{}}),ym)return;ym=setTimeout(()=>{ym=null;let t=$S.splice(0);if(t.length===0)return;ct("/api/canvas/debug/ext-app-recovery",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entries:t})}).catch(()=>{})},1500)}var OS=Promise.resolve();function LS(e){OS=OS.then(async()=>{if(!e.remount())return;await e.awaitBoot(),await new Promise((t)=>setTimeout(t,BS))}).catch(()=>{})}function W1(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 q1(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 DS(e,t,n){if(await e.sendToolInput({arguments:t}),n)await e.sendToolResult(n)}function G1(e){return typeof e==="string"&&e.trim().length>0?e.trim():em}function V1(e,t){return`<script data-pmx-canvas-ax-bridge>
|
|
7749
|
+
- "app": Tool callable by the app from this server only`)}),kU=S({mimeTypes:te(C()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),z1=S({method:b("ui/download-file"),params:S({contents:te(he([Ps,Rs])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),M1=S({method:b("ui/message"),params:S({role:b("user").describe('Message role, currently only "user" is supported.'),content:te(lo).describe("Message content blocks (text, image, etc.).")})}),TU=S({method:b("ui/notifications/sandbox-resource-ready"),params:S({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:pm.optional().describe("CSP configuration from resource metadata."),permissions:mm.optional().describe("Sandbox permissions from resource metadata.")})}),CU=S({method:b("ui/notifications/tool-result"),params:Mn.describe("Standard MCP tool execution result.")}),AS=S({toolInfo:S({id:Lo.optional().describe("JSON-RPC id of the tools/call request."),tool:ii.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:b1.optional().describe("Current color theme preference."),styles:C1.optional().describe("Style configuration for theming the app."),displayMode:ca.optional().describe("How the UI is currently displayed."),availableDisplayModes:te(ca).optional().describe("Display modes the host supports."),containerDimensions:he([S({height:ne().describe("Fixed container height in pixels.")}),S({maxHeight:he([ne(),ei()]).optional().describe("Maximum container height in pixels.")})]).and(he([S({width:ne().describe("Fixed container width in pixels.")}),S({maxWidth:he([ne(),ei()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
7750
|
+
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([b("web"),b("desktop"),b("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:S({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:S({top:ne().describe("Top safe area inset in pixels."),right:ne().describe("Right safe area inset in pixels."),bottom:ne().describe("Bottom safe area inset in pixels."),left:ne().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),EU=S({method:b("ui/notifications/host-context-changed"),params:AS.describe("Partial context update containing only changed fields.")}),$1=S({method:b("ui/update-model-context"),params:S({content:te(lo).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:$e(C(),He().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),O1=S({method:b("ui/initialize"),params:S({appInfo:Do.describe("App identification (name and version)."),appCapabilities:P1.describe("Features and capabilities this app provides."),protocolVersion:C().describe("Protocol version this app supports.")})}),IU=S({protocolVersion:C().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Do.describe("Host application identification and version."),hostCapabilities:A1.describe("Features and capabilities provided by the host."),hostContext:AS.describe("Rich context about the host environment.")}).passthrough();class fm{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=tc.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!==y1)console.debug("Sending message",e);this.eventTarget.postMessage(e,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}function PS(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 L1=[IS];class hm extends ci{_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(O1,(r)=>this._oninitialize(r)),this.setRequestHandler(co,(r,s)=>(this.onping?.(r.params,s),{})),this.setRequestHandler(ES,(r)=>({mode:this._hostContext.displayMode??"inline"}))}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;set onsizechange(e){this.setNotificationHandler(k1,(t)=>e(t.params))}set onsandboxready(e){this.setNotificationHandler(_1,(t)=>e(t.params))}set oninitialized(e){this.setNotificationHandler(R1,(t)=>e(t.params))}set onmessage(e){this.setRequestHandler(M1,async(t,n)=>e(t.params,n))}set onopenlink(e){this.setRequestHandler(S1,async(t,n)=>e(t.params,n))}set ondownloadfile(e){this.setRequestHandler(z1,async(t,n)=>e(t.params,n))}set onrequestteardown(e){this.setNotificationHandler(I1,(t)=>e(t.params))}set onrequestdisplaymode(e){this.setRequestHandler(ES,async(t,n)=>e(t.params,n))}set onloggingmessage(e){this.setNotificationHandler(Id,async(t)=>{e(t.params)})}set onupdatemodelcontext(e){this.setRequestHandler($1,async(t,n)=>e(t.params,n))}set oncalltool(e){this.setRequestHandler(ai,async(t,n)=>e(t.params,n))}sendToolListChanged(e={}){return this.notification({method:"notifications/tools/list_changed",params:e})}set onlistresources(e){this.setRequestHandler(hd,async(t,n)=>e(t.params,n))}set onlistresourcetemplates(e){this.setRequestHandler(gd,async(t,n)=>e(t.params,n))}set onreadresource(e){this.setRequestHandler(bd,async(t,n)=>e(t.params,n))}sendResourceListChanged(e={}){return this.notification({method:"notifications/resources/list_changed",params:e})}set onlistprompts(e){this.setRequestHandler(wd,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:L1.includes(t)?t:IS,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(D1(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},E1,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},Mn,{signal:o.signal}),t.tools.listChanged)this._client.setNotificationHandler(Ed,(n)=>this.sendToolListChanged(n.params))}if(t.resources){if(this.onlistresources=async(n,o)=>this._client.request({method:"resources/list",params:n},oi,{signal:o.signal}),this.onlistresourcetemplates=async(n,o)=>this._client.request({method:"resources/templates/list",params:n},vd,{signal:o.signal}),this.onreadresource=async(n,o)=>this._client.request({method:"resources/read",params:n},ri,{signal:o.signal}),t.resources.listChanged)this._client.setNotificationHandler(xd,(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(Cd,(n)=>this.sendPromptListChanged(n.params))}}return super.connect(e)}}function D1(e,t){return JSON.stringify(e)===JSON.stringify(t)}function gm(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function F1(e){return gm(e)&&Array.isArray(e.content)&&e.content.every((t)=>gm(t)&&typeof t.type==="string")}function H1(...e){for(let t of e)if(typeof t==="string"){if(t.trim().length>0)return t}return}function B1(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 vm(e){let t=e.success===!1;if(F1(e.result))return{...e.result,isError:e.result.isError===!0||t};let n=gm(e.result)?e.result:null,o=H1(e.detailedContent,e.content,n?.detailedContent,n?.content,n?.textResultForLlm,n?.text,n?.message,typeof e.result==="string"?e.result:void 0,e.error)??B1(e.result);return{content:o?[{type:"text",text:o}]:[],isError:t}}function RS(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 NS(e){return Boolean(e)&&typeof e==="object"&&e!==null&&!Array.isArray(e)&&"ok"in e&&typeof e.ok==="boolean"}async function j1(e,t){let n=await ct("/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||!NS(o)||!o.ok||typeof o.url!=="string"){let r=NS(o)&&o.error?o.error:`Frame document request failed with HTTP ${n.status}`;throw Error(r)}return o.url}function zS(e,t){let n=Lt.value,[o,r]=I(null),[s,a]=I(0),c=L(0);B(()=>{if(r(null),!e||n!=="src")return;let u=!1;return c.current=Ar.value,j1(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=Ar.value;return B(()=>{if(n!=="src"||l===c.current)return;if(!o){a((p)=>p+1);return}let u=!1;return ct(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]),Ze(()=>{if(n==="srcdoc"&&e)return{attributes:{srcdoc:e},ready:!0,key:`srcdoc-${Mi(e)}`};return{attributes:o?{src:o}:{},ready:Boolean(o),key:o??""}},[o,n,e])}function ji(e){let{enabled:t,token:n,nodeId:o,sourceSurface:r,iframeRef:s}=e;Cn(()=>{if(!t||!n)return;function a(c){if(c.source!==s.current?.contentWindow)return;let l=c.data;if(!l||l.source!==kl||l.token!==n||l.nodeId!==o)return;let u=l.interaction;if(!u||typeof u.type!=="string")return;let p=u.type;qc({type:p,sourceNodeId:o,sourceSurface:r,...u.payload&&typeof u.payload==="object"?{payload:u.payload}:{}}).then((d)=>{if(d.ok)rn("context","AX interaction",p,[o]);s.current?.contentWindow?.postMessage({source:Tl,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 Lr(e,t){let o=await(await ct(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 Dr(e){return/AppleWebKit/.test(e)&&!/Chrome|Chromium|CriOS|Edg|Android/.test(e)}function U1(e){let{userAgent:t,visibilityState:n,rect:o,viewport:r,alreadyRearmed:s}=e;if(s)return!1;if(!Dr(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 BS=1000,MS=7000;function It(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});Z1({t:Date.now(),nodeId:e,event:t})}var $S=[],ym=null;function Z1(e){if($S.push({...e,...typeof document<"u"?{visibility:document.visibilityState}:{}}),ym)return;ym=setTimeout(()=>{ym=null;let t=$S.splice(0);if(t.length===0)return;ct("/api/canvas/debug/ext-app-recovery",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entries:t})}).catch(()=>{})},1500)}var OS=Promise.resolve();function LS(e){OS=OS.then(async()=>{if(!e.remount())return;await e.awaitBoot(),await new Promise((t)=>setTimeout(t,BS))}).catch(()=>{})}function W1(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 q1(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 DS(e,t,n){if(await e.sendToolInput({arguments:t}),n)await e.sendToolResult(n)}function G1(e){return typeof e==="string"&&e.trim().length>0?e.trim():em}function V1(e,t){return`<script data-pmx-canvas-ax-bridge>
|
|
7750
7751
|
(function () {
|
|
7751
7752
|
const PMX_AX_TOKEN = ${JSON.stringify(e)};
|
|
7752
7753
|
const PMX_AX_NODE_ID = ${JSON.stringify(t)};
|
|
@@ -7871,8 +7872,8 @@ container holding the app. Specify either width or maxWidth, and either height o
|
|
|
7871
7872
|
});
|
|
7872
7873
|
sendPaintTick();
|
|
7873
7874
|
})();
|
|
7874
|
-
<\/script>`}function FS(){return"<style data-pmx-canvas-ext-app-base>html, body { background: transparent !important; }</style>"}function HS(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 Ui(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 bm(e,t){let n=e?.getBoundingClientRect();return{width:Ui(e?.clientWidth??0,Ui(n?.width??0,t.width)),height:Ui(e?.clientHeight??0,Ui(n?.height??0,t.height))}}function K1(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>0&&!t}function J1(e,t){return Math.max(Ui(e,1),Ui(t,1))}function jS({node:e,expanded:t=!1}){let n=L(null),o=L(null),r=L(null),s=L(null),a=L({}),c=L(void 0),l=L(!1),u=L(void 0),p=L(null),d=L(!1),m=L(null),f=L(0),h=L([]),v=L(""),w=L(!1),g=L(!1),x=L([]),R=L(!1),M=L(!1),O=L(!1),k=L(!1),[N,_]=I("loading"),[E,z]=I(null),[X,W]=I(0),[J,G]=I(!1),[T,q]=I(!1),[ae,be]=I(()=>t||typeof navigator>"u"||typeof window>"u"||!Dr(navigator.userAgent)),pe=e.data.html,Me=e.data.serverName,Te=e.data.appSessionId,De=e.data.toolInput??{},cn=e.data.toolResult,Rn=e.data.toolName??"ext-app",F=e.data.toolDefinition,Y=e.data.toolCallId,Ce=typeof Y==="string"||typeof Y==="number"?Y:void 0,me=e.data.resourceMeta,xe=e.data.sessionStatus,ce=e.data.sessionError,se=e.size.height,Z=e.id,we=W1(e,X),A=G1(null),fe=e.data.axCapabilities?.enabled===!0&&typeof pe==="string"&&pe.length>0,ge=Ze(()=>`ax-${crypto.randomUUID()}`,[]),Vt=fe?V1(ge,Z):"",_t=typeof pe==="string"&&pe.length>0?X1(ge,Z):"",Xt=zS(HS(pe??"",FS()+_t+Vt),A);B(()=>{function Q(de){if(de.source!==n.current?.contentWindow)return;let Ee=de.data;if(!Ee||Ee.source!==Cl||Ee.token!==ge||Ee.nodeId!==Z)return;if(g.current=!0,Ee.kind==="paint-tick"){let Ae=Ee,Ht={content:Ae.content===!0,detail:typeof Ae.detail==="string"?Ae.detail:""};for(let zn of h.current.splice(0))zn(Ht)}}return window.addEventListener("message",Q),()=>window.removeEventListener("message",Q)},[ge,Z]),B(()=>{if(ae)return;LS({remount:()=>{if(k.current)return!1;return It(Z,"mount-slot"),be(!0),!0},awaitBoot:()=>new Promise((Q)=>{let de=window.setTimeout(Ee,MS);function Ee(){window.clearTimeout(de),Q()}x.current.push(Ee)})})},[]),ji({enabled:fe,token:ge,nodeId:Z,sourceSurface:"mcp-app",iframeRef:n});let bn=3,mr=(Q)=>{if(f.current>=bn)return It(Z,`remount-cap-hit (${Q})`),!1;if(R.current)return!0;return f.current+=1,R.current=!0,It(Z,`remount-queued #${f.current} (${Q})`),LS({remount:()=>{if(R.current=!1,k.current||!t&&ot.value===Z)return It(Z,"remount-skipped"),G(!1),!1;return M.current=typeof document<"u"&&document.visibilityState==="hidden",It(Z,`remount-run #${f.current}`),_("loading"),W((de)=>de+1),!0},awaitBoot:()=>new Promise((de)=>{let Ee=window.setTimeout(Ae,MS);function Ae(){window.clearTimeout(Ee),de()}x.current.push(Ae)})}),!0},Ta=1500,xn=()=>new Promise((Q)=>{let de=n.current?.contentWindow;if(!de||k.current){Q("timeout");return}let Ee=!1,Ae=window.setTimeout(()=>{if(Ee)return;Ee=!0,Q("timeout")},Ta);h.current.push((Ht)=>{if(Ee)return;Ee=!0,window.clearTimeout(Ae),v.current=Ht.detail,Q(Ht.content?"content-verified":"tick-no-content")}),de.postMessage({source:Qp,token:ge},"*")}),Nn=async(Q)=>{let de=Date.now()+Q;while(Date.now()<de&&!k.current){if(await xn()==="content-verified")return!0;await new Promise((Ee)=>window.setTimeout(Ee,400))}return!1},no=()=>new Promise((Q)=>{let de=n.current;if(!de){Q();return}let Ee=de.style.width,Ae=de.style.height;de.style.width="140%",de.style.height="140%",requestAnimationFrame(()=>{requestAnimationFrame(()=>{de.style.width=Ee,de.style.height=Ae,It(Z,"soft-expand-cycle"),Q()})})}),rs=600,oo=()=>{if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;let Q=n.current;if(!Q||k.current)return;if(!U1({userAgent:navigator.userAgent,visibilityState:document.visibilityState,rect:Q.getBoundingClientRect(),viewport:{width:window.innerWidth,height:window.innerHeight},alreadyRearmed:O.current}))return;O.current=!0,window.setTimeout(()=>{if(k.current||document.visibilityState==="visible")return;f.current=0,q(!1),M.current=!1,It(Z,"assume-visible-rearm"),mr("assume-visible")},rs)},Co=(Q="")=>{let de=v.current?` [${v.current}]`:"";return typeof document<"u"&&document.visibilityState==="hidden"?`paint-ok (content-verified)${de}${Q} (host hidden)`:`paint-ok (content-verified)${de}${Q}`},is=async()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Dr(navigator.userAgent))return;G(!0);let Q=await xn();if(Q==="content-verified"){It(Z,Co()),G(!1),oo();return}if(It(Z,Q==="tick-no-content"?`paint-fail (tick without content: ${v.current||"unknown"})`:"paint-fail (no tick)"),await no(),Q=await xn(),Q==="content-verified"){It(Z,Co(" (after soft-expand)")),G(!1),oo();return}if(k.current)return;if(Q==="tick-no-content"&&await Nn(3000)){It(Z,Co(" (after content wait)")),G(!1),oo();return}if(k.current)return;if(!mr("paint-fail"))It(Z,"recovery-exhausted"),G(!1),q(!0),oo()};B(()=>{if(t)return;if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;if(!Dr(navigator.userAgent))return;function Q(){if(document.visibilityState!=="visible")return;if(!M.current||k.current)return;M.current=!1,f.current=0,q(!1),It(Z,"visible-again-rearm"),mr("visible-after-hidden-boot")}return document.addEventListener("visibilitychange",Q),()=>document.removeEventListener("visibilitychange",Q)},[t,Z]);let Eo=6000;B(()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Dr(navigator.userAgent))return;if(!Xt.ready||!ae)return;let Q=window.setTimeout(()=>{if(w.current||g.current||k.current)return;mr("boot-watchdog")},Eo);return()=>window.clearTimeout(Q)},[we,Xt.ready,t,ae]),B(()=>()=>{k.current=!0;for(let Q of x.current.splice(0))Q();for(let Q of h.current.splice(0))Q({content:!1,detail:"unmounted"})},[]);let Io=(Q)=>er(Q),ln=t||ot.value===Z;a.current=De,c.current=cn;let fr=xe==="error"&&typeof pe==="string"&&pe.length>0,Gr=xe==="error"?fr?`Live session unavailable — showing saved content. Reopen the app to restore interactivity.${ce?` (${ce})`:""}`:ce??"Saved app session is unavailable. Reopen the app to restore interactivity.":"Reconnecting saved app session...",Vr=(Q)=>{let de=c.current;if(!Q||!d.current||!de)return null;if(u.current===de)return null;if(u.current&&RS(u.current,de))return u.current=de,null;if(p.current)return p.current;let Ee=Q.sendToolResult(de).then(()=>{u.current=de,l.current=!0,_("done")}).catch((Ae)=>{let Ht=Ae instanceof Error?Ae.message:String(Ae);throw z(`Tool result delivery failed: ${Ht}`),Ae}).finally(()=>{p.current=null});return p.current=Ee,Ee};if(B(()=>{if(!pe||!Xt.ready||!ae)return;let Q=n.current;if(!Q)return;let de=!1,Ee=null,Ae=null,Ht=null,zn=null,Zn=null;l.current=!1,u.current=void 0,p.current=null,d.current=!1,w.current=!1,g.current=!1;let Ao=()=>{if(!Ee)return;clearTimeout(Ee),Ee=null};return(async()=>{if(!pe)return;let un=Q.contentWindow;if(!un)throw Error("Ext-app iframe window is unavailable");let wn=(Ie=ot.value===Z?"fullscreen":"inline")=>({theme:Io(gt.value),platform:"web",containerDimensions:bm(Q,{width:e.size.width,height:se}),displayMode:Ie,locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,...F?{toolInfo:{id:Ce,tool:F}}:{}}),Sn=()=>{if(zn!==null)return;zn=requestAnimationFrame(()=>{if(zn=null,de||!d.current)return;je.setHostContext?.(wn())})},ro=()=>{if(Zn!==null)return;Zn=requestAnimationFrame(()=>{Zn=requestAnimationFrame(()=>{if(Zn=null,de||!d.current)return;je.sendHostContextChange?.(wn())})})},Xr=()=>{if(!Dr(navigator.userAgent))return;if(Ae)clearTimeout(Ae);Ae=setTimeout(()=>{if(Ae=null,de)return;is()},BS+200)},je=new hm(null,{name:"PMX Canvas",version:"1.0.0"},{openLinks:{},serverTools:{listChanged:!1},serverResources:{listChanged:!1},logging:{},updateModelContext:{text:{},structuredContent:{}}},{hostContext:wn(ln?"fullscreen":"inline")});je.onsizechange=async({height:Ie})=>{if(K1(Ie,ot.value===Z)){let ut=bm(Q.parentElement??Q,{width:e.size.width,height:se}),Bt=J1(Ie,ut.height);Q.style.height=`${Bt}px`;let io=D.value.get(Z)?.size??e.size,Po=Math.max(io.height,Bt+Di);if(Math.abs(Po-io.height)>8){if(tl(Z,{width:io.width,height:Po}),s.current!==null)window.clearTimeout(s.current);s.current=window.setTimeout(()=>{Tt({recordHistory:!1}),s.current=null},0)}}return{}},je.onopenlink=async({url:Ie})=>(window.open(Ie,"_blank","noopener"),{}),je.onsandboxready=async()=>{await je.sendSandboxResourceReady({html:HS(pe,FS()),sandbox:em,...me?.csp?{csp:me.csp}:{},...me?.permissions?{permissions:me.permissions}:{}})},je.onrequestdisplaymode=async({mode:Ie})=>{let{nextMode:ut,shouldExpand:Bt,shouldCollapse:io}=q1(Ie,ln);if(Bt)En(Z);else if(io)xo();return{mode:ut}},je.oncalltool=async(Ie)=>{if(!Te)throw Error(Gr);try{let ut=await Lr("/api/ext-app/call-tool",{sessionId:Te,nodeId:Z,serverName:Me,toolName:Ie.name,arguments:Ie.arguments??{}});return z(null),ut}catch(ut){let Bt=ut instanceof Error?ut.message:String(ut);throw z(`Tool call failed: ${Bt}`),ut}},je.setRequestHandler(si,async()=>{if(!Te)return{tools:[]};return Lr("/api/ext-app/list-tools",{sessionId:Te})}),je.onlistresources=async()=>Te?Lr("/api/ext-app/list-resources",{sessionId:Te}):{resources:[]},je.onlistresourcetemplates=async()=>Te?Lr("/api/ext-app/list-resource-templates",{sessionId:Te}):{resourceTemplates:[]},je.onreadresource=async(Ie)=>{if(!Te)throw Error(Gr);return Lr("/api/ext-app/read-resource",{sessionId:Te,uri:Ie.uri})},je.onlistprompts=async()=>Te?Lr("/api/ext-app/list-prompts",{sessionId:Te}):{prompts:[]},je.onupdatemodelcontext=async(Ie)=>{if(!Te)return{};return await Lr("/api/ext-app/model-context",{nodeId:Z,...Array.isArray(Ie.content)?{content:Ie.content}:{},...Ie.structuredContent&&typeof Ie.structuredContent==="object"?{structuredContent:Ie.structuredContent}:{}}),{}};let ss=new fm(un,un);if(je.oninitialized=()=>{if(de)return;Ao(),d.current=!0,w.current=!0,It(Z,"initialized"),_("ready"),z(null),Promise.resolve(je.sendHostContextChange(wn(ln?"fullscreen":"inline"))).then(()=>DS(je,a.current,void 0)).then(()=>Vr(je)).then(()=>{let Ie=()=>{for(let ut of x.current.splice(0))ut()};if(typeof navigator<"u"&&Dr(navigator.userAgent))Nn(4000).then((ut)=>{It(Z,ut?"settled (content-verified)":`settled (content-timeout${v.current?`: ${v.current}`:""})`),Ie()});else It(Z,"settled"),Ie();ro(),Xr()}).catch((Ie)=>{let ut=Ie instanceof Error?Ie.message:String(Ie);z(`Bridge bootstrap failed: ${ut}`)})},Ee=setTimeout(()=>{if(de||d.current)return;let Ie=c.current,ut=wn(ln?"fullscreen":"inline");d.current=!0,je.setHostContext?.(ut),Promise.resolve(je.sendHostContextChange(ut)).then(()=>DS(je,a.current,Ie)).then(()=>{if(l.current=Boolean(Ie),Ie)u.current=Ie;if(_(Ie?"done":"ready"),z(null),ro(),Xr(),g.current){It(Z,"settled (fallback)");for(let Bt of x.current.splice(0))Bt()}}).catch((Bt)=>{let io=Bt instanceof Error?Bt.message:String(Bt);z(`Bridge bootstrap fallback failed: ${io}`)})},1200),await je.connect(ss),de){Ao(),await ss.close();return}if(o.current=je,r.current=ss,Ht=new ResizeObserver(Sn),Ht.observe(Q),Q.parentElement)Ht.observe(Q.parentElement);let as=!0;m.current=gt.subscribe((Ie)=>{if(as){as=!1;return}if(de)return;je.setHostContext?.({...wn(),theme:Io(Ie)}),je.sendHostContextChange?.(wn())}),Vr(je)})().catch((un)=>{Ao(),console.error("[ext-app] Bridge init failed:",un),z(un?.message??"Bridge initialization failed")}),()=>{if(de=!0,Ao(),Ae)clearTimeout(Ae),Ae=null;if(Ht?.disconnect(),Ht=null,zn!==null)cancelAnimationFrame(zn),zn=null;if(Zn!==null)cancelAnimationFrame(Zn),Zn=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((un)=>{console.error("[ext-app] transport close failed:",un)}),r.current=null}},[we,Xt.key,ae]),B(()=>{if(cn&&o.current&&(N==="ready"||N==="done"))Vr(o.current)},[cn,N]),B(()=>{let Q=o.current;if(n.current)n.current.style.height="100%";if(!Q||!d.current)return;let de=null,Ee=null;return de=requestAnimationFrame(()=>{de=null,Ee=requestAnimationFrame(()=>{if(Ee=null,!d.current)return;let Ae={theme:Io(gt.value),platform:"web",containerDimensions:bm(n.current,{width:e.size.width,height:se}),displayMode:ln?"fullscreen":"inline",locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};Q.setHostContext?.(Ae),Q.sendHostContextChange?.(Ae)})}),()=>{if(de!==null)cancelAnimationFrame(de);if(Ee!==null)cancelAnimationFrame(Ee)}},[ln,se]),!pe)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 ",Rn," 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:[xe&&xe!=="ready"&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:xe==="error"&&!fr?"color-mix(in srgb, var(--c-danger) 12%, transparent)":"color-mix(in srgb, var(--c-warn) 10%, transparent)",color:xe==="error"&&!fr?"var(--c-danger)":"var(--c-warn)",borderBottom:`1px solid ${xe==="error"&&!fr?"color-mix(in srgb, var(--c-danger) 12%, transparent)":"color-mix(in srgb, var(--c-warn) 15%, transparent)"}`},children:Gr},void 0,!1,void 0,this),E&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:"color-mix(in srgb, var(--c-danger) 12%, transparent)",color:"var(--c-danger)",borderBottom:"1px solid color-mix(in srgb, var(--c-danger) 12%, transparent)",display:"flex",alignItems:"center",gap:"6px"},children:[i("span",{children:"⚠"},void 0,!1,void 0,this),i("span",{style:{flex:1},children:E},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>{z(null),_("loading"),W((Q)=>Q+1)},style:{background:"var(--c-surface-hover)",border:"1px solid color-mix(in srgb, var(--c-danger) 12%, transparent)",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(Xe,{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:[ae&&i("iframe",{ref:n,...Xt.attributes,sandbox:A,allow:PS(me?.permissions),style:{flex:1,width:"100%",height:"100%",minHeight:0,border:"none",background:"var(--c-panel)",pointerEvents:ln?"auto":"none"},title:`Ext App: ${Rn}`},we,!1,void 0,this),T&&!E&&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:(Q)=>{Q.stopPropagation(),It(Z,"manual-retry"),f.current=0,q(!1),_("loading"),W((de)=>de+1)},style:{background:"var(--c-surface-hover)",border:"1px solid color-mix(in srgb, var(--c-warn) 15%, transparent)",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),(N==="loading"||J)&&!E&&!T&&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:N==="loading"?`Connecting to ${Rn}...`:"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),!ln&&!(T&&!E)&&i("button",{type:"button",onClick:(Q)=>{Q.stopPropagation(),En(Z)},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 la=new Map,US=!1;function ZS(e,t,n){if(!US)US=!0,on(()=>{let s=D.value,a=Tr.value;for(let[c,l]of la){let u=s.get(c);if(!u||l.epoch!==a||l.version!==u.data.specVersion||l.documentUrl!==u.data.url)la.delete(c)}}),window.addEventListener("message",(s)=>{let a=s.data;if(!a||a.source!==Yp||a.type!=="snapshot"||typeof a.nodeId!=="string")return;let c=la.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=D.value.get(e);if(!o)return;let r=la.get(e);if(!r)r={epoch:Tr.value,version:o.data.specVersion,documentUrl:o.data.url,state:null,owners:[]},la.set(e,r);r.owners=[...r.owners.filter((s)=>s.source!==n).slice(-1),{token:t,source:n}],n.postMessage({source:Yp,type:"restore",token:t,state:r.state},"*")}function Y1(e,t,n,o,r,s,a,c){if(!e)return e;try{let l=ke()&&e.startsWith("/"),u=new URL(e,l?"https://pmx.invalid":window.location.origin);if(u.searchParams.set("theme",er(gt.value)),t)u.searchParams.set("display","expanded");if(typeof n==="number")u.searchParams.set("v",String(n));if(o)u.searchParams.set("axToken",o);if(r)u.searchParams.set("axNodeId",r);if(s)u.searchParams.set("frameToken",s);if(a)u.searchParams.set("fit","content");if(c)u.searchParams.set("stateToken",c);return l?`${u.pathname}${u.search}`:u.toString()}catch{return e}}function Q1(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 xm({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=L(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=(w,g)=>i("iframe",{ref:g?void 0:t,...w.source,class:s,sandbox:a,allow:c,tabIndex:l,loading:Lt.value==="srcdoc"?void 0:"lazy",onLoad:(x)=>{if(o?.(x.currentTarget),!g){n();return}let R=++h.current,M=x.currentTarget;requestAnimationFrame(()=>requestAnimationFrame(()=>{if(h.current!==R)return;t.current=M,d(w),f(null),n()}))},style:{position:"absolute",inset:0,width:"100%",height:"100%",visibility:g?"hidden":"visible",background:"var(--c-panel-soft)"},title:r},w.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 tr({node:e,expanded:t=!1}){if(e.data.mode==="ext-app")return i(jS,{node:e,expanded:t},void 0,!1,void 0,this);return i(eR,{node:e,expanded:t},void 0,!1,void 0,this)}function eR({node:e,expanded:t}){let n=L(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=Ze(()=>c?`ax-${crypto.randomUUID()}`:"",[c]),p=lm(e)&&!t,d=Ze(()=>p?`frame-${crypto.randomUUID()}`:"",[p]);Fi(e,n,d),ji({enabled:c&&Boolean(u),token:u,nodeId:e.id,sourceSurface:l,iframeRef:n});let m=gn.value,f=()=>{if(!c||!u||m==null)return;n.current?.contentWindow?.postMessage({source:In,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=Ze(()=>r?`ui-${crypto.randomUUID()}`:"",[r,h,e.data.url]),w=Y1(e.data.url||"",t,h,u||void 0,c?e.id:void 0,d||void 0,p,v||void 0),g=Hi(w),x=e.data.sourceServer||"",R=e.data.hostMode||"hosted",M=e.data.fallbackReason,O=e.data.trustedDomain===!0||Q1(w);if(R==="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),M&&i("div",{style:{color:"var(--c-muted)",fontSize:"11px"},children:["Reason: ",M]},void 0,!0,void 0,this),i("a",{href:w,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all"},children:w},void 0,!1,void 0,this),x&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px"},children:["Source: ",x]},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:[!O&&i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"color-mix(in srgb, var(--c-warn) 10%, transparent)",color:"var(--c-warn)",borderBottom:"1px solid color-mix(in srgb, var(--c-warn) 15%, transparent)"},children:"Unverified domain"},void 0,!1,void 0,this),i(xm,{source:g,iframeRef:n,onDocumentLoad:(k)=>{if(v&&k.contentWindow)ZS(e.id,v,k.contentWindow)},onLoad:f,title:`MCP App: ${x}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var tR=null;function Zi(){tR=null}var WS={idle:"var(--c-muted)",running:"var(--c-accent)",planning:"var(--c-agent)",thinking:"var(--c-agent)",drafting:"var(--c-accent)",tooling:"var(--c-accent)",review:"var(--c-ok)","waiting-approval":"var(--c-warn)",waiting:"var(--c-warn)"};function nR(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 Fl({node:e}){let t=nR(e),n=e.data.detail||"",o=e.data.message||"",r=e.data.level||"ok",s=e.data.activeTool,a=e.data.subagent,c=WS[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-agent)"},children:[i("span",{style:{fontSize:"10px"},children:"⚙"},void 0,!1,void 0,this),i("span",{style:{fontFamily:"var(--font-code)",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 Wi(e){return typeof e==="string"&&e.trim().length>0?e.trim():null}function qS(e){if(typeof e==="string"){let r=Wi(e);return r?{title:"Evidence warning",detail:r}:null}if(!e||typeof e!=="object")return null;let t=e,n=Wi(t.title)??"Evidence warning",o=Wi(t.detail);return o?{title:n,detail:o}:null}function oR(e){let t=[],n=qS(e.data.warning);if(n)t.push(n);let o=e.data.warnings;if(Array.isArray(o))for(let s of o){let a=qS(s);if(a)t.push(a)}let r=Wi(e.data.validationStatus)?.toLowerCase();if(r==="failed"||r==="invalid")t.push({title:"Image failed validation",detail:Wi(e.data.validationMessage)??"Review this image before using it as evidence."});return t}function rR(e){let t=[e.data.title,e.data.caption,e.data.alt,e.data.src,e.data.path].map((n)=>Wi(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 GS(e){let t=oR(e);if(t.length>0)return t;if(rR(e))return[{title:"Captured login page",detail:"This image looks like an auth screen. Treat it as environment context, not product evidence."}];return[]}function Hl({node:e,expanded:t=!1}){let n=e.data.src||"",o=e.data.alt||e.data.title||"Image",r=e.data.caption||"",s=GS(e),a=Pi(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,w]=I({w:0,h:0}),g=L(null),x=L(!1),R=L({x:0,y:0}),M=j((J)=>{let G=J.target;w({w:G.naturalWidth,h:G.naturalHeight}),l(!0),p(!1)},[]),O=j(()=>{p(!0),l(!1)},[]);B(()=>{m(1),h({x:0,y:0})},[n]);let k=j((J)=>{J.preventDefault(),J.stopPropagation();let G=J.deltaY>0?0.9:1.1;m((T)=>Math.max(0.25,Math.min(10,T*G)))},[]),N=j((J)=>{if(d<=1)return;J.stopPropagation(),x.current=!0,R.current={x:J.clientX,y:J.clientY},J.target.setPointerCapture(J.pointerId)},[d]),_=j((J)=>{if(!x.current)return;let G=J.clientX-R.current.x,T=J.clientY-R.current.y;R.current={x:J.clientX,y:J.clientY},h((q)=>({x:q.x+G,y:q.y+T}))},[]),E=j(()=>{x.current=!1},[]),z=j(()=>{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 X=v.w>0?`${v.w}×${v.h}`:"",W=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((J)=>i("div",{class:"image-node-warning",children:[i("span",{class:"image-node-warning-title",children:J.title},void 0,!1,void 0,this),i("span",{class:"image-node-warning-detail",children:J.detail},void 0,!1,void 0,this)]},`${J.title}-${J.detail}`,!0,void 0,this))},void 0,!1,void 0,this),i("div",{class:"image-node-viewport",onWheel:k,onPointerDown:N,onPointerMove:_,onPointerUp:E,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:M,onError:O,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||X||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:[X&&i("span",{children:X},void 0,!1,void 0,this),d!==1&&i("button",{type:"button",class:"image-node-zoom-reset",onClick:z,title:"Reset zoom",children:[W,"% ",i(il,{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 VS({node:e}){if((e.data.children??[]).filter((o)=>D.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 iR(e){try{return new URL(e).host}catch{return e}}function sR(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleString()}function Bl({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=sR(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,w]=I(t);B(()=>{if(t)w(!0)},[t]);let g=j(async()=>{if(!n||f)return;h(!0);try{await Wc(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 x=a==="ready"?"var(--c-ok)":a==="error"?"var(--c-danger)":"var(--c-muted)";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:iR(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:x,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.04em",flexShrink:0},children:[i("span",{style:{width:"7px",height:"7px",borderRadius:"999px",background:x}},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:()=>w((R)=>!R),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 XS(e){return e.type==="html"&&e.data.presentation===!0}function ua({node:e,expanded:t=!1,presentation:n=!1,presentationExitToken:o,autoFocus:r=!1}){let s=L(null),a=gt.value,c=Ze(()=>`theme-${crypto.randomUUID()}`,[]),l=Ze(()=>`ax-${crypto.randomUUID()}`,[]),u=Ze(()=>`frame-${crypto.randomUUID()}`,[]),p=typeof e.data.html==="string"?e.data.html:typeof e.data.content==="string"?e.data.content:"",d=Ze(()=>Mi(p),[p]),m=Ze(()=>p?oa(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=Hi(m);Fi(e,s,t?"":u),ji({enabled:!0,token:l,nodeId:e.id,sourceSurface:"html-node",iframeRef:s}),B(()=>{if(s.current?.contentWindow?.postMessage({source:In,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),w=gn.value;B(()=>{if(!v||w==null)return;s.current?.contentWindow?.postMessage({source:In,type:"ax-update",token:l,state:w},"*")},[v,w,l]),B(()=>{if(!r)return;let x=window.setTimeout(()=>s.current?.focus(),0);return()=>window.clearTimeout(x)},[r,m]);let g=()=>{if(s.current?.contentWindow?.postMessage({source:In,type:"theme-update",token:c,theme:a},"*"),v&&gn.value!=null)s.current?.contentWindow?.postMessage({source:In,type:"ax-update",token:l,state:gn.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(xm,{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 wm=null;async function KS(){if(!wm)wm=await Ub();return wm}function JS(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 aR({html:e}){let t=L(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=to(e),n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function cR(e,t){return`${e.role}:${e.status??"none"}:${t}:${e.text}`}function YS({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 QS({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(Xe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jl({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,w]=I(null),[g,x]=I(new Map),R=L(null),M=L(null),O=n[n.length-1],k=`${n.length}:${O?.role??""}:${O?.status??""}:${Math.floor((O?.text?.length??0)/200)}`;B(()=>{if(t&&c&&R.current)R.current.focus()},[t,c]),B(()=>{if(!k)return;if(M.current)M.current.scrollTo({top:M.current.scrollHeight,behavior:"smooth"})},[k]);let N=L(null),_=L(n);_.current=n,B(()=>{let G=n.some((q)=>q.role==="assistant"&&q.status==="streaming"),T=()=>{let q=!1,be=_.current.map((pe,Me)=>({turn:pe,index:Me})).filter(({turn:pe})=>pe.role==="assistant"&&pe.text);if(be.length===0)return;return Promise.all(be.map(async({turn:pe,index:Me})=>{let Te=await Kn(pe.text);return{index:Me,html:to(Te)}})).then((pe)=>{if(q)return;let Me=new Map;for(let Te of pe)Me.set(Te.index,Te.html);x(Me)}),()=>{q=!0}};if(!G){if(N.current)clearTimeout(N.current),N.current=null;return T()}if(N.current)clearTimeout(N.current);return N.current=setTimeout(()=>{N.current=null,T()},400),()=>{if(N.current)clearTimeout(N.current),N.current=null}},[n]);let E=j(async()=>{let G=d.trim();if(!G)return;let T=d;w(null),ve(e.id,{turns:[{role:"user",text:G,status:"pending"}],threadStatus:"pending",text:G}),m("");let q=Array.isArray(e.data.contextNodeIds)?e.data.contextNodeIds:void 0;if(!(await js(G,e.position,e.id,q,e.id)).ok)ve(e.id,{turns:[],threadStatus:"draft",text:"",status:"draft"}),m(T),w("Failed to send prompt. Your draft has been restored.")},[d,e.id,e.position,e.data.contextNodeIds]),z=j(async()=>{let G=f.trim();if(!G)return;let T=f;w(null);let q=Array.isArray(e.data.turns)?[...e.data.turns]:[];if(q.push({role:"user",text:G,status:"pending"}),ve(e.id,{turns:q,threadStatus:"pending"}),h(""),!(await Zb(e.id,G)).ok)q.pop(),ve(e.id,{turns:q,threadStatus:"answered"}),h(T),w("Failed to send reply. Your draft has been restored.")},[f,e.id,e.data.turns]),X=j((G)=>{if(G.key==="Enter"&&(G.metaKey||G.ctrlKey)){G.preventDefault(),E();return}if(G.key==="Tab"&&d.startsWith("/")){G.preventDefault();let T=d.slice(1).split(/\s/)[0];if(T)KS().then((q)=>{let ae=JS(T,q);if(ae)m(`/${ae}`)})}},[E,d]),W=j((G)=>{if(G.key==="Enter"&&(G.metaKey||G.ctrlKey)){G.preventDefault(),z();return}if(G.key==="Tab"&&f.startsWith("/")){G.preventDefault();let T=f.slice(1).split(/\s/)[0];if(T)KS().then((q)=>{let ae=JS(T,q);if(ae)h(`/${ae}`)})}},[z,f]),J=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(YS,{count:J},void 0,!1,void 0,this),i(QS,{message:v,onDismiss:()=>w(null)},void 0,!1,void 0,this),i("textarea",{ref:R,value:d,onInput:(G)=>m(G.target.value),onKeyDown:X,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-ui)",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:E,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(YS,{count:J},void 0,!1,void 0,this),i(QS,{message:v,onDismiss:()=>w(null)},void 0,!1,void 0,this),i("div",{ref:M,style:{flex:1,overflow:"auto",minHeight:0},children:n.map((G,T)=>i("div",{children:[T>0&&i("div",{class:"thread-turn-divider"},void 0,!1,void 0,this),G.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:G.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${G.status==="streaming"?" pulsing":""}`},void 0,!1,void 0,this),"PMX"]},void 0,!0,void 0,this),G.status==="streaming"&&!G.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:G.text?1:0.4},children:g.get(T)?i(_e,{children:[i(aR,{html:g.get(T)??""},void 0,!1,void 0,this),G.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:G.status==="streaming"?"Waiting for response…":G.text||"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},cR(G,T),!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:(G)=>h(G.target.value),onKeyDown:W,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-ui)",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:!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 lR({html:e}){let t=L(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=to(e),n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function Ul({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 Kn(n).then((p)=>{if(!u)s(to(p))}),()=>{u=!0}},[n]);let l=j(()=>{js("",{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(lR,{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 e_(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 t_={mcp:"var(--c-muted)",file:"var(--c-muted)",subagent:"var(--c-subagent)",other:"var(--c-muted)"},uR={running:"⠋",success:"✓",failed:"✕"},dR={running:"var(--c-accent)",success:"var(--c-ok)",failed:"var(--c-danger)"};function Zl({node:e}){let{toolName:t,category:n,status:o,duration:r,resultSummary:s,error:a}=e_(e.data),c=t_[n]??t_.other,l=uR[o]??"◌",u=dR[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(--font-code)",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)}var pR=new Set(["png","jpg","jpeg","gif","svg","webp","bmp","ico","avif"]),mR=new Set(["md","mdx","markdown"]);function fR(e){let t=e.split(".").pop()?.toLowerCase()??"";if(pR.has(t))return"image";if(mR.has(t))return"markdown";return"file"}async function qi(e,t,n){let o=Pe.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=fR(u.name),v=u.name;if(/\.(pdf|pptx?|xlsx?|docx?|od[pts])$/i.test(v)){if(!o||u.size===0||u.size>20971520){rn("remove","File not attached","Open a board and choose a nonempty file under 20 MiB.");continue}let w=new URLSearchParams({boardId:o,name:v,mime:u.type,x:String(m),y:String(f)});rn("context","Attaching document",v),await re("attachDocument",`/api/canvas/attachments?${w}`,null,{method:"POST",body:u});continue}if(Pe.value!==o)return;if(h==="image"){let w=new FileReader,g=await new Promise((x)=>{w.onload=()=>x(w.result),w.readAsDataURL(u)});if(Pe.value!==o)return;await Dn({type:"image",title:v,content:g,x:m,y:f,width:400,height:300,...o?{boardId:o}:{}})}else{let w=await u.text();if(Pe.value!==o)return;let g=h==="markdown"||h==="file";await Dn({type:h,title:v,content:w,x:m,y:f,width:g?720:400,height:g?500:300,...o?{boardId:o}:{}})}}}var n_={width:260,height:150},hR={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 _m(e){return!!e&&e in $t}function _o(e){if(!e)return null;let t=D.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 Sm(e){return{x:e.left+e.width/2,y:e.top+e.height/2}}function da(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 o_(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 km({intent:e}){let t=_m(e.nodeType)?Bn(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:()=>Oi.value=e.id,onMouseLeave:()=>{if(Oi.value===e.id)Oi.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(),Cr(e)},children:i(Xe,{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 r_({intent:e,rect:t}){let n=_m(e.nodeType)?Bn(e.nodeType):null,o=_m(e.nodeType)?$t[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:da(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(km,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function i_({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:da(e)},children:[n==="edit"&&i("div",{class:"intent-edit-bar"},void 0,!1,void 0,this),i(km,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function gR(e){let t=e.phase==="settling"?_o(e.settledNodeId):null;switch(e.kind){case"create":{if(!e.position)return null;let n=e.nodeType&&hR[e.nodeType]||n_,o=t??{left:e.position.x,top:e.position.y,...n};return i(r_,{intent:e,rect:o},e.id,!1,void 0,this)}case"move":{if(!e.position)return null;let o=_o(e.nodeId)??n_,r=t??{left:e.position.x,top:e.position.y,width:o.width,height:o.height};return i(r_,{intent:e,rect:r},e.id,!1,void 0,this)}case"remove":{let n=t??_o(e.nodeId);if(!n)return null;return i(i_,{intent:e,rect:n,variant:"remove"},e.id,!1,void 0,this)}case"edit":{let n=t??_o(e.nodeId);if(!n)return null;return i(i_,{intent:e,rect:n,variant:"edit"},e.id,!1,void 0,this)}case"connect":{if(!e.edge)return null;let n=_o(e.edge.from),o=_o(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:da(e)},children:i(km,{intent:e},void 0,!1,void 0,this)},e.id,!1,void 0,this)}default:return null}}function s_(){let e=Array.from(lt.value.values());if(B(()=>{function t(n){if(n.key!=="Escape")return;let o=Oi.value;if(!o)return;let r=lt.value.get(o);if(!r||r.phase!=="forming")return;n.stopImmediatePropagation(),n.preventDefault(),Cr(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&<.value.get(n)?.phase!=="forming")$r(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=_o(t.edge.from),o=_o(t.edge.to);if(!n||!o)return null;return i("path",{d:o_(Sm(n),Sm(o)),class:`intent-edge type-${t.edge.type}`,style:{opacity:da(t)}},`line-${t.id}`,!1,void 0,this)}if(t.kind==="move"&&t.position){let n=_o(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:o_(Sm(n),r),class:"intent-trail",markerEnd:"url(#intent-arrow)",style:{opacity:da(t)}},`line-${t.id}`,!1,void 0,this)}return null})]},void 0,!0,void 0,this),e.map(gR)]},void 0,!0,void 0,this)}var a_=32000;var Wl="Agent session";function c_(e){return e.some((t)=>t.attached)}function l_(e){return e.filter((t)=>!t.attached)}function nr(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"}}var At=K([]),Tm=K({used:0,total:a_}),or=K([]),Fr=K(!1),Gi=K(!1),Cm=K(null);function An(e){return At.value.find((n)=>n.sessionId===e)?.parentAgentId?"var(--c-subagent)":"var(--c-agent)"}function u_(e){return(e.trim().replace(/^[^a-z0-9]+/i,"").charAt(0)||e.trim().charAt(0)||"?").toUpperCase()}function ql(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 St=Ve(()=>c_(At.value)),Em=Ve(()=>l_(At.value)),d_=Ve(()=>{let e=new Set;return[...At.value].filter((t)=>t.label!==Wl).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))}),p_=Ve(()=>At.value.filter((e)=>e.attached)),Vi=Ve(()=>At.value.find((e)=>e.attached)??null);function vR(e){let t=new Set;for(let n of e)if(n.nodeId&&n.kind!=="create")t.add(n.nodeId);return t}var Gl=Ve(()=>vR(lt.value.values()));function Vl(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 Im(e){if(!e)return;if(Array.isArray(e.presences))At.value=e.presences;if(e.budget&&Number.isFinite(e.budget.used)&&Number.isFinite(e.budget.total))Tm.value={used:e.budget.used,total:e.budget.total};if(Array.isArray(e.activity))or.value=e.activity}function m_(){let e=L(new Map),t=ie.value.scale,n=D.value,o=1/Math.max(0.05,t),r=At.value.map((s)=>{let a=Vl(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":An(s.sessionId)},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:nr(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 ko(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 f_(){let e=ko(sa.value.length>0?5000:0),t=sa.value.filter((o)=>o.cursor!==null&&(!o.lastSeenAt||e-Date.parse(o.lastSeenAt)<lS+5000));if(t.length===0)return null;let n=1/Math.max(0.05,ie.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 Xl(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 Pm(){let e=gn.value;return e&&typeof e==="object"?e:{}}var h_=Ve(()=>Pm().workItems??[]),Rm=Ve(()=>Pm().approvalGates??[]),Hr=Ve(()=>Rm.value.filter((e)=>e.status==="pending")),rr=Ve(()=>{let e=Pm().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 g_(e){return(await fn("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 v_=Ve(()=>Rm.value.filter((e)=>e.status==="held")),y_=Ve(()=>Rm.value.filter((e)=>e.status==="approved"||e.status==="rejected")),b_=K({events:[],evidence:[],steering:[]}),Br=K("all");function Nm(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 yR=new Set(["api","mcp","sdk","cli"]);function Am(e,t){if(e?.trim())return e.trim();let n=t?.trim();if(n&&!yR.has(n))return n;return null}var bR=/^(node|edge|group|annotation|jsonrender|graph|render)\.|^arrange$|^canvas\.clear$|^snapshot\.restore$/,x_=K(null),fa=K(new Set),xR={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 wR(e,t=40,n=[],o=null,r="all"){let s=n.find((l)=>bR.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,...!ke()&&o?.actor==="agent"&&s?.id===l.id?{undoable:!0}:{}})),...e.events.map((l)=>({id:`event-${l.id}`,kind:l.kind,label:xR[l.kind]??l.kind,body:l.detail?`${l.summary} — ${l.detail}`:l.summary,createdAt:l.createdAt,who:Am(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:Am(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:Am(l.agentId,l.source)}})],c=r==="all"?a:a.filter((l)=>Nm(l.kind)===r);return c.sort((l,u)=>l.createdAt<u.createdAt?1:l.createdAt>u.createdAt?-1:0),c.slice(0,t)}var w_=Ve(()=>wR(b_.value,40,or.value,x_.value,Br.value));async function ir(){let[e,t]=await Promise.all([re("refreshTimeline","/api/canvas/ax/timeline?limit=40",null),re("refreshHistoryTop","/api/canvas/history",null)]);if(t)x_.value=t.top??null;if(!e)return;b_.value={events:Array.isArray(e.events)?e.events:[],evidence:Array.isArray(e.evidence)?e.evidence:[],steering:Array.isArray(e.steering)?e.steering:[]}}async function zm(e){if(!(await fn("undoAgentEdit","/api/canvas/undo",{method:"POST"})).ok)return!1;return fa.value=new Set([...fa.value,e.id]),await Ln("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"})}),ir(),!0}async function Mm(e=!1){if(ke())return rn("remove","Undo / redo unavailable","Open the local PMX workbench to use shared history."),!1;let t=await fn(e?"redo":"undo",e?"/api/canvas/redo":"/api/canvas/undo",{method:"POST"});if(t.ok)ir();return t.ok}async function S_(e,t){if(!(await fn("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 Ln("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 __(e){return(await fn("reopenGate",`/api/canvas/ax/approval/${encodeURIComponent(e.id)}/reopen`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser"})})).ok}async function k_(e,t){return(await fn("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 sr(){return(await fn("startSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser",label:Wl,attached:!0,phase:"idle"})})).ok}async function Kl(e){return(await fn("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}function pa(e){if(!Array.isArray(e))return[];return e.flatMap((t)=>{if(!t||typeof t!=="object")return[];let n=t;if(typeof n.id!=="string"||typeof n.title!=="string")return[];return[{id:n.id,title:n.title,...typeof n.reason==="string"?{reason:n.reason}:{}}]})}var ar=K(null);function $m(e){let t=Xi.value?.context;ar.value=e&&t?new Set([...t.read,...t.pinned,...t.created,...t.edited].map((n)=>n.id)):null}var Xi=K(null);function ma(e,t){let n=new Set(e.map((o)=>o.id));return[...e,...t.filter((o)=>!n.has(o.id))]}function SR(e,t){return{labels:[...new Set([...e.labels,...t.labels])],sessions:e.sessions+1,endedAt:t.endedAt,endedBy:e.endedBy===t.endedBy?t.endedBy:void 0,counts:t.counts,snapshot:null,context:{read:ma(e.context.read,t.context.read),pinned:ma(e.context.pinned,t.context.pinned),created:ma(e.context.created,t.context.created),edited:ma(e.context.edited,t.context.edited),changedSinceRead:ma(e.context.changedSinceRead,t.context.changedSinceRead)}}}function T_(e){let{counts:t,snapshot:n,context:o}=e;if(typeof e.label!=="string"||typeof e.endedAt!=="string")return;if(e.unchanged===!0||typeof e.parentAgentId==="string")return;let r={labels:[e.label],sessions:1,endedAt:e.endedAt,endedBy:e.endedBy==="human"||e.endedBy==="agent"||e.endedBy==="idle-timeout"?e.endedBy:void 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,context:{read:pa(o?.read),pinned:pa(o?.pinned),created:pa(o?.created),edited:pa(o?.edited),changedSinceRead:pa(o?.changedSinceRead)}},s=Xi.value;if(Xi.value=s?SR(s,r):r,s&&ar.value)$m(!0)}function Jl(){Xi.value=null,ar.value=null}function C_(){if(!St.value)return null;let e=rr.value;if(!e)return null;let t=D.value,n=e.nodeIds.map((s)=>t.get(s)).filter((s)=>s!==void 0),o=Xl(n,e.padding);if(!o)return null;let r=1/Math.max(0.05,ie.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 E_=K(new Map),ha=K({});function Om(e){E_.value=new Map((e.nodes??[]).map((t)=>[t.nodeId,t])),ha.value=e.pins??{}}async function Yl(){let e=await re("fetchContextStatus","/api/canvas/ax/context-status",{});if(e.ok&&e.boardId===Pe.value)Om(e)}function I_(e,t){let n=E_.value.get(e),o=ha.value[e]?.pinnedAt;if(!n||o&&n.lastReadAt<o)return{kind:"not-read"};if(t>n.readRevision)return{kind:"changed",by:n.lastReadBy,at:n.lastReadAt};return{kind:"read",by:n.lastReadBy,at:n.lastReadAt,count:n.readCount}}function Ql(e){return e.agentId?.trim()||e.source}var A_="",P_=new Map,R_=Ve(()=>{let e=ze.value,t=new Map;if(e.size>0){let o=new Map;for(let r of ep([...D.value.values()],e)){let s=r.pinnedNodeTitle??r.pinnedNodeId;for(let a of r.neighbors){let c=o.get(a.id)??[];c.push({pinNodeId:r.pinnedNodeId,pinTitle:s,distance:a.distance}),o.set(a.id,c)}}for(let[r,s]of o)s.sort((a,c)=>a.distance-c.distance),t.set(r,s.map(({pinNodeId:a,pinTitle:c})=>({pinNodeId:a,pinTitle:c})))}let n=[...t].sort(([o],[r])=>o.localeCompare(r)).map(([o,r])=>`${o}:${r.map((s)=>`${s.pinNodeId}=${s.pinTitle}`).join(",")}`).join("|");if(n===A_)return P_;return A_=n,P_=t,t});function Qe({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)}var eu={eye:"M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6S2 12 2 12zM12 9.5a2.5 2.5 0 1 0 0 5a2.5 2.5 0 1 0 0-5",eyeOff:"M3 3l18 18M10.6 6.1A10 10 0 0 1 12 6c6.5 0 10 6 10 6a17 17 0 0 1-3 3.6M6.6 6.6C3.8 8.3 2 12 2 12s3.5 6 10 6a9.6 9.6 0 0 0 4.4-1",spark:"M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8z",pen:"M4 20l4.2-1L19 8.2 15.8 5 5 15.8z",warn:"M12 4l9 16H3zM12 10v4M12 17v.5"};function N_(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function _R(e,t){if(t){let n=ha.value[e.id],o=n?.pinnedBy.actor==="agent"?` Pinned by ${Ql(n.pinnedBy)}${n.reason?`: ${n.reason}`:""}.`:"",r=I_(e.id,e.contentRevision??0);if(r.kind==="not-read")return{tone:"muted",glyph:"eyeOff",word:"not read",label:"Not read yet",body:`In context, but no agent has loaded it since it was pinned.${o}`};if(r.kind==="changed")return{tone:"warn",glyph:"warn",word:"changed since read",label:"The agent's copy is out of date",body:`Changed after ${r.by} read it at ${N_(r.at)}.${o}`};return{tone:"agent",glyph:"eye",word:"read",label:"Read by the agent",body:`${r.count>1?`Read ${r.count} times · last`:"Read"} ${N_(r.at)} by ${r.by}.${o}`}}if(e.lastEditedBy?.actor==="human")return null;if(e.createdBy?.actor==="agent"){let n=Ql(e.createdBy);return{tone:"agent",glyph:"spark",word:`by ${n}`,label:`Created by ${n}`,body:"The byline stays until you edit the node."}}if(e.lastEditedBy?.actor==="agent")return{tone:"agent",glyph:"pen",word:"edited",label:`Edited by ${Ql(e.lastEditedBy)}`,body:"The mark stays until you edit the node."};return null}function z_({node:e,pinned:t}){let n=_R(e,t);if(!n)return null;return i(Qe,{label:n.label,body:n.body,align:"end",tapToOpen:!0,children:i("span",{class:`node-context-mark is-${n.tone}`,"data-mark":n.word,children:[i("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:i("path",{d:eu[n.glyph]},void 0,!1,void 0,this)},void 0,!1,void 0,this),n.word]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function M_(e){return ha.value[e]?.pinnedBy.actor==="agent"}function $_({node:e,pinned:t}){let[n,o]=I(!1),r=t?void 0:R_.value.get(e.id);if(!r||r.length===0)return null;let s=r.length>1?`near ${r.length}`:"near",a=n?r.map((c)=>{let l=D.value.get(c.pinNodeId);return l?`“${c.pinTitle}” (${Math.round(Qd(e,l))} px)`:`“${c.pinTitle}”`}).join(", "):"";return i(Qe,{label:n?`Near ${a}`:"Near a pin",body:"The agent gets its title and a short summary, not its full content. Pin it to send its content.",align:"end",tapToOpen:!0,children:i("span",{class:"node-near-mark","data-near":r.map((c)=>c.pinNodeId).join(" "),onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),onFocusIn:()=>o(!0),onFocusOut:()=>o(!1),children:[i("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[i("circle",{cx:"12",cy:"12",r:"8",class:"node-near-ring"},void 0,!1,void 0,this),i("circle",{cx:"12",cy:"12",r:"2.2",class:"node-near-dot"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function kR(e){let t=typeof e==="number"&&Number.isFinite(e)?Math.floor(e):1;return Math.max(1,Math.min(20,t))}function tu(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function ga(e){return typeof e==="string"&&e.length>0}function O_(e){let t=e.axStep;if(!tu(t))return null;if(!ga(t.flowId)||!ga(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 L_(e){let t=e.axFlow;if(!tu(t)||!ga(t.flowId)||!Array.isArray(t.steps))return null;let n=[];for(let r of t.steps){if(!tu(r)||!ga(r.nodeId)||!ga(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=tu(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:kR(o.maxRuns)}}}var TR={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)"},F_={display:"flex",alignItems:"center",gap:"6px",flexWrap:"wrap"},H_={fontSize:"10px",color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginRight:"auto"},B_={...Nr,background:"color-mix(in srgb, var(--c-accent) 25%, transparent)",color:"var(--c-text)"},CR=[{status:"in-progress",label:"Start",toast:"Step started"},{status:"done",label:"Done",toast:"Step done"},{status:"blocked",label:"Blocked",toast:"Step blocked"}];async function D_(e,t,n){let o={...t,loop:n};ve(e.id,{axFlow:o}),await kt(e.id,{data:{axFlow:o}})}function j_(e){return typeof e?.axWorkStatus==="string"?e.axWorkStatus:"todo"}function ER({node:e,flow:t}){let[n,o]=I(""),{running:r,run:s,maxRuns:a}=t.loop,c=async()=>{await D_(e,t,{running:!0,run:s>=a?0:s,maxRuns:a});let u=t.steps.find((d)=>j_(D.value.get(d.nodeId)?.data)!=="done"),p=u??t.steps[t.steps.length-1];await Ko(e,"ax.work.update",{id:p.workItemId,status:u?"in-progress":"done"},"Loop running")},l=async()=>{let u=n.trim();if(!u)return;await Ko(e,"ax.steer",{message:u},"Steering sent"),o("")};return i("div",{class:"ax-flow-controls",style:{...F_,marginTop:"6px",rowGap:"4px"},children:[i("span",{class:"ax-flow-runs",style:H_,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:B_,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(),D_(e,t,{...t.loop,running:!1})},children:"Stop"},void 0,!1,void 0,this):i("button",{type:"button",class:"ax-node-action",style:Nr,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:Nr,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 nu({node:e}){let t=O_(e.data);if(!t)return null;let n=L_(e.data),o=j_(e.data);return i("div",{class:"ax-step-dock",style:TR,children:[i("div",{class:"ax-step-controls",style:F_,children:[i("span",{class:"ax-step-position",style:H_,children:["Step ",t.index,"/",t.total]},void 0,!0,void 0,this),CR.map((r)=>i("button",{type:"button",class:"ax-node-action","aria-pressed":o===r.status,style:o===r.status?B_:Nr,title:`Set this step's work item to "${r.status}".`,onClick:(s)=>{s.stopPropagation(),Ko(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(ER,{node:e,flow:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Ki=8,jr=K(null),Ji=[],Yi=[],W_=null;function U_(e){let t=e?.data.parentGroup;return typeof t==="string"&&t.length>0?t:null}function Z_(e){if(!e||!Array.isArray(e.data.children))return[];return e.data.children.filter((t)=>typeof t==="string")}function IR(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=U_(r);while(s&&!o.has(s))o.add(s),s=U_(n.get(s));if(r.type!=="group")return o;let a=[...Z_(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(...Z_(l))}return o}function q_(e,t){Ji=[],Yi=[],W_=e;let n=Array.from(t),o=IR(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;Ji.push({val:s,minY:l,maxY:u}),Ji.push({val:a,minY:l,maxY:u}),Ji.push({val:c,minY:l,maxY:u}),Yi.push({val:l,minX:s,maxX:a}),Yi.push({val:u,minX:s,maxX:a}),Yi.push({val:p,minX:s,maxX:a})}}function G_(){Ji=[],Yi=[],W_=null}function V_(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=Ki+1,p=null;for(let v=0;v<3;v++){let w=r[v];for(let g of Ji){let x=Math.abs(w-g.val);if(x<u)u=x,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=Ki+1,f=null;for(let v=0;v<3;v++){let w=s[v];for(let g of Yi){let x=Math.abs(w-g.val);if(x<m)m=x,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<=Ki)h.push(p);if(f&&m<=Ki)h.push(f);return{x:l!==null&&u<=Ki?l:e,y:d!==null&&m<=Ki?d:t,guides:h}}function X_({nodeId:e,viewport:t,onMove:n,onDragEnd:o,onClick:r}){let s=L(!1),a=L({x:0,y:0}),c=L({x:0,y:0});return j((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 x=m;m=null;let R=t.value.scale,M=(x.x-a.current.x)/R,O=(x.y-a.current.y)/R;n(e,c.current.x+M,c.current.y+O)},w=(x)=>{if(!s.current)return;if(!h&&Math.hypot(x.clientX-u.clientX,x.clientY-u.clientY)<4)return;if(h=!0,m={x:x.clientX,y:x.clientY},f!==null)return;f=window.requestAnimationFrame(v)},g=(x)=>{if(f!==null)window.cancelAnimationFrame(f),v();if(s.current=!1,document.documentElement.classList.remove("is-node-dragging"),document.removeEventListener("pointermove",w),document.removeEventListener("pointerup",g),document.removeEventListener("pointercancel",g),o(),!h&&x.type==="pointerup")r?.()};document.addEventListener("pointermove",w),document.addEventListener("pointerup",g),document.addEventListener("pointercancel",g)},[e,t,n,o,r])}var AR=200,PR=100;function K_({nodeId:e,viewport:t,onResize:n,onResizeEnd:o}){let r=L(!1),s=L({x:0,y:0}),a=L({w:0,h:0});return j((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 w=d;d=null;let g=t.value.scale,x=(w.x-s.current.x)/g,R=(w.y-s.current.y)/g;n(e,Math.max(AR,a.current.w+x),Math.max(PR,a.current.h+R))},h=(w)=>{if(!r.current)return;if(d={x:w.clientX,y:w.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 RR={ArrowLeft:{dx:-1,dy:0},ArrowRight:{dx:1,dy:0},ArrowUp:{dx:0,dy:-1},ArrowDown:{dx:0,dy:1}};function NR(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 zR=0.4,MR=0.55,$R=175;function OR(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*zR/Di);if(Number.isFinite(n)&&n>0)r=Math.min(r,n*MR/$R);return Math.max(1,r)}function J_({node:e,children:t,onContextMenu:n}){let o=qe.value===e.id,r=Ne.value.has(e.id),s=ze.value.has(e.id),a=Rc.value.has(e.id),c=!o&&sx.value.has(e.id),l=go.value,u=l!==null&&l.has(e.id),p=l!==null&&!l.has(e.id),[d,m]=I(!1),f=L(null),h=j((A,ue,fe)=>{let ge=V_(ue,fe,e.size.width,e.size.height),Vt=D.value.get(A);if(Vt?.position.x===ge.x&&Vt.position.y===ge.y){jr.value=ge.guides.length>0?ge.guides:null;return}wt(A,{position:{x:ge.x,y:ge.y}}),jr.value=ge.guides.length>0?ge.guides:null,dx(A)},[e.size.width,e.size.height]),v=L(null),w=j(()=>{if(G_(),jr.value=null,am(null),v.current)document.removeEventListener("keydown",v.current),v.current=null;Tt();let A=Jn.value;if(ux(),!A||A.nodeId!==e.id)return;if(A.mode==="add")fp(A.groupId,[e.id]);else{let ue=D.value.get(A.groupId),fe=Array.isArray(ue?.data.children)?ue.data.children.filter((ge)=>typeof ge==="string"&&ge!==e.id):[];Gc(A.groupId,fe)}},[e.id]),g=X_({nodeId:e.id,viewport:ie,onMove:h,onDragEnd:w,onClick:()=>{Ne.value=new Set([e.id])}}),x=j((A,ue,fe)=>{let ge=D.value.get(A);if(ge?.size.width===ue&&ge.size.height===fe)return;wt(A,{size:{width:ue,height:fe}})},[]),R=j(()=>{ve(e.id,{userResized:!0}),kt(e.id,{data:{userResized:!0}}),Tt()},[e.id]),M=K_({nodeId:e.id,viewport:ie,onResize:x,onResizeEnd:R}),O=j((A)=>{A.stopPropagation(),A.preventDefault(),Ye.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]),k=j((A)=>{if(A.button!==0)return;if(d)return;if(A.target instanceof Element&&A.target.closest("button, input")){A.stopPropagation();return}if(en.value==="connect"){O(A);return}if(A.shiftKey){A.stopPropagation(),vp(e.id);return}if(yo(e.id),am(e.id),yS(e.id,typeof e.data.title==="string"&&e.data.title?e.data.title:e.type),q_(e.id,D.value.values()),e.type!=="group"){let ue=(fe)=>{if(fe.key==="Escape")lx()};v.current=ue,document.addEventListener("keydown",ue)}g(A,e.position.x,e.position.y)},[e.id,e.type,e.data.title,e.position.x,e.position.y,g,d,O]),N=j((A)=>{if(A.button!==0)return;if(A.stopPropagation(),en.value==="connect"){O(A);return}if(A.shiftKey){vp(e.id);return}yo(e.id)},[e.id,O]),_=j((A)=>{if((A.target instanceof Element?A.target:null)?.closest('button, input, textarea, select, a, [contenteditable="true"]'))return;if(n)n(A,e.id)},[n,e.id]),E=j((A)=>{let ue=A.target;if(ue&&ue!==A.currentTarget&&ue.closest('input, textarea, [contenteditable="true"]'))return;let fe=RR[A.key];if(fe){A.preventDefault();let ge=NR(e,fe,D.value.values());if(!ge)return;yo(ge.id),requestAnimationFrame(()=>{document.querySelector(`.canvas-node[data-node-id="${CSS.escape(ge.id)}"]`)?.focus()})}else if(A.key==="Enter"&&A.target===A.currentTarget&&Ls.has(e.type))A.preventDefault(),En(e.id)},[e]),z=e.data.title||(e.type==="file"?(e.data.path||e.data.content||"").split(/[\\/]/).pop()??"":"")||$t[e.type],X=j((A)=>{let ue=A.trim();if(ue&&ue!==z)ve(e.id,{title:ue}),kt(e.id,{title:ue});m(!1)},[e.id,z]),W=L(null),J=L(!1),G=L(null);B(()=>{if(J.current||!cm(e))return;let A=W.current;if(!A)return;let ue=new ResizeObserver(()=>{if(J.current){ue.disconnect();return}let fe=A.scrollHeight,ge=_S(e,fe);if(ge===null)return;if(Math.abs(ge-e.size.height)>8){if(tl(e.id,{width:e.size.width,height:ge}),G.current!==null)window.clearTimeout(G.current);G.current=window.setTimeout(()=>{Tt({recordHistory:!1}),G.current=null},0)}J.current=!0,ue.disconnect()});return ue.observe(A),()=>{if(ue.disconnect(),G.current!==null)window.clearTimeout(G.current),G.current=null}},[e.id,e.type,e.data.mode,e.data.strictSize,e.collapsed,e.size.width,e.size.height]);let T=e.pinned,q=e.type==="trace",ae=q&&e.data.status==="running",be=e.type==="group",pe=e.data.strictSize===!0,Me=Math.max(ie.value.scale,0.01),Te=OR(Me,e.collapsed?0:e.size.height,e.size.width),De=be&&e.data.color?e.data.color:void 0,cn={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":Te.toFixed(3),"--node-port-scale":(1/Me).toFixed(3),...De?{"--group-color":De}:{}},Rn=St.value&&Gl.value.has(e.id),F=["canvas-node",o?"active":"",c?"neighbor":"",u?"search-match":"",p?"search-dimmed":"",r?"selected":"",s?"context-pinned":"",a?"attention-pulse":"",T?"pinned":"",q?"trace-node":"",ae?"trace-running":"",be?"group-node":"",pe?"strict-size":"",Rn?"agent-mutating":"",ar.value&&!ar.value.has(e.id)?"lens-dimmed":""].filter(Boolean).join(" "),Y=be?(Array.isArray(e.data.children)?e.data.children:[]).filter((A)=>typeof A==="string"&&D.value.has(A)):[],[Ce,me]=I(!1),xe=Jn.value,ce=be&&xe?.groupId===e.id&&xe.mode==="add",se=be&&xe?.groupId===e.id&&xe.mode==="remove",Z=Ye.value?.targetId===e.id,we=be?[...new Set(Y.map((A)=>D.value.get(A)?.type).filter((A)=>!!A))].slice(0,4):[];if(be&&e.collapsed)return i("div",{class:`${F} group-chip`,"data-node-type":e.type,style:{...cn,width:"auto",height:"auto"},onPointerDown:N,onDblClick:_,title:"Expand group","data-testid":"group-chip",children:i("div",{class:"node-titlebar group-chip-inner",onPointerDown:k,children:[i("button",{type:"button",class:"group-chip-expand","aria-label":`Expand group ${z}`,onClick:(A)=>{A.stopPropagation(),Gs(e.id)},children:i(Vs,{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:z},void 0,!1,void 0,this),i("div",{class:"group-chip-meta",children:[we.map((A)=>i("span",{class:"group-kind-dot","aria-hidden":"true"},A,!1,void 0,this)),i("span",{class:"group-chip-count",children:[Y.length," node",Y.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:`${F}${ce?" is-drop-target":""}${se?" is-drop-source":""}${Z?" is-edge-target":""}${be&&Ce?" group-menu-open":""}`,"data-node-type":e.type,"data-node-id":e.id,style:cn,tabIndex:o?0:-1,onKeyDown:E,onPointerDown:N,onMouseDown:(A)=>{if(A.shiftKey)A.preventDefault()},onDblClick:_,children:[i("div",{class:"node-content",children:[be&&i("div",{class:"node-titlebar group-edge-row",onPointerDown:k,children:[i("span",{class:"group-name-pill",children:[d?i("input",{ref:f,class:"node-title-input group-title-input",value:z,onBlur:(A)=>X(A.target.value),onKeyDown:(A)=>{if(A.key==="Enter")X(A.target.value);if(A.key==="Escape")m(!1)},onClick:(A)=>A.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"group-name",title:z,children:z},void 0,!1,void 0,this),i("span",{class:"group-count",children:Y.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":`${z} actions`,children:[i("button",{type:"button",class:"group-action",title:"Auto-arrange children","aria-label":"Auto-arrange children",disabled:Y.length===0,onClick:(A)=>{A.stopPropagation(),fp(e.id,Y,"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:(A)=>{A.stopPropagation(),Gs(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":Ce,onClick:(A)=>{A.stopPropagation(),me((ue)=>!ue)},children:i(Tp,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),Ce&&i("div",{class:"group-menu",role:"menu",onPointerDown:(A)=>A.stopPropagation(),children:[i("button",{type:"button",role:"menuitem",onClick:(A)=>{A.stopPropagation(),me(!1),m(!0),requestAnimationFrame(()=>f.current?.focus())},children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",onClick:(A)=>{A.stopPropagation(),me(!1),Wo(e.id),wi(e.id)},children:"Ungroup"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",disabled:Y.length===0,onClick:(A)=>{A.stopPropagation(),me(!1),Yc(Y)},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),!be&&i("div",{class:"node-titlebar",onPointerDown:k,children:[i("span",{class:"node-type-icon","aria-hidden":"true",children:(()=>{let A=Bn(e.type);return i(A,{size:Math.round(14*Te)},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),d?i("input",{ref:f,class:"node-title-input",value:z,onBlur:(A)=>X(A.target.value),onKeyDown:(A)=>{if(A.key==="Enter")X(A.target.value);if(A.key==="Escape")m(!1)},onClick:(A)=>A.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"node-title",title:z,children:z},void 0,!1,void 0,this),i($_,{node:e,pinned:s},void 0,!1,void 0,this),i(z_,{node:e,pinned:s},void 0,!1,void 0,this),i("div",{class:"node-controls",children:[T&&i("span",{class:"pin-indicator",title:"Pinned",children:"⊙"},void 0,!1,void 0,this),Ls.has(e.type)&&i("button",{type:"button",onClick:(A)=>{A.stopPropagation(),En(e.id)},title:"Expand (focus mode)",children:i(zx,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:`ctx-pin-btn${s?" ctx-pin-active":""}`,onClick:(A)=>{A.stopPropagation(),Qn(e.id)},title:s?"Remove from context":"Add to context","aria-label":s?"Remove from context":"Add to context","aria-pressed":s,children:i("span",{class:"ctx-pin-mark",children:[i(ul,{},void 0,!1,void 0,this),s&&M_(e.id)&&i("span",{class:"ctx-pin-agent-dot","aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"node-hover-control",onClick:(A)=>{A.stopPropagation(),n?.(A,e.id)},title:"More actions","aria-label":"More actions",children:i(Tp,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"node-hover-control",onClick:(A)=>{A.stopPropagation(),Uo(e.id)},title:"Close",children:i(Xe,{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:W,class:"node-body",children:[t,i(nu,{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:(A)=>M(A,e.size.width,e.size.height)},void 0,!1,void 0,this),r&&["tl","tr","bl","br"].map((A)=>i("span",{class:`node-selection-handle is-${A}`,"aria-hidden":"true"},A,!1,void 0,this)),Or.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),Or.value.get(e.id)," took over — agent yielded"]},void 0,!0,void 0,this),!be&&["top","right","bottom","left"].map((A)=>i("div",{class:`node-port node-port-${A}`,onPointerDown:(ue)=>{if(ue.button!==0)return;ue.stopPropagation(),ue.preventDefault(),ue.currentTarget.setPointerCapture(ue.pointerId);let fe=e.position.x+e.size.width/2,ge=e.position.y+e.size.height/2,Vt=e.size.width/2,_t=e.size.height/2,Xt,bn;switch(A){case"top":Xt=fe,bn=ge-_t;break;case"bottom":Xt=fe,bn=ge+_t;break;case"left":Xt=fe-Vt,bn=ge;break;case"right":Xt=fe+Vt,bn=ge;break}Ye.value={fromId:e.id,fromX:Xt,fromY:bn,cursorX:Xt,cursorY:bn}}},A,!1,void 0,this))]},void 0,!0,void 0,this)}function ou({node:e}){let t=typeof e.data.boardId==="string"?e.data.boardId:"",n=Ut.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 sn(n.id),children:[n?"Open board":"Target unavailable",n&&i(Xo,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var LR={relation:"var(--c-muted)","depends-on":"var(--c-rel-informs)",flow:"var(--c-accent)",references:"var(--c-muted)"},DR=new Set(["depends-on","flow"]);function FR(e){if(!Number.isFinite(e)||e<=0)return 1;return e<1?1/e:1}function HR(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 ru(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 iu(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 BR(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 jR({edge:e,fromNode:t,toNode:n,focused:o,dimmed:r,selected:s,scale:a,onContextMenu:c}){let l=ru(t,n),u=ru(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=iu(l,f),v=iu(u,f),w=`M ${l.x} ${l.y} C ${h.x} ${h.y}, ${v.x} ${v.y}, ${u.x} ${u.y}`,g=LR[e.type],x=DR.has(e.type),R=HR(e,a),M=Math.min(a,2.2),O=e.label&&a<=3.4?BR(l.x,l.y,h.x,h.y,v.x,v.y,u.x,u.y):null,k=`edge-path-${e.id}`;return i("g",{children:[i("path",{d:w,fill:"none",stroke:"transparent","stroke-width":12*a,style:{cursor:"pointer",pointerEvents:"stroke"},onClick:(N)=>{N.stopPropagation(),Yn.value=e.id},onDblClick:c?(N)=>c(N,e.id):void 0},void 0,!1,void 0,this),(o||s)&&i("path",{d:w,fill:"none",stroke:g,"stroke-width":6*a,"stroke-dasharray":R,opacity:s?0.3:0.15,style:{filter:"blur(3px)"}},void 0,!1,void 0,this),i("path",{id:k,d:w,class:s?"edge-selected":void 0,fill:"none",stroke:g,"stroke-width":(s?3:o?2.5:1.5)*a,"stroke-dasharray":R,"marker-end":x?"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:`#${k}`},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O&&e.label&&i("g",{transform:`translate(${O.x}, ${O.y})`,children:[i("rect",{class:"edge-label-bg",x:-(e.label.length*3.5+8)*M,y:-10*M,width:(e.label.length*7+16)*M,height:20*M,rx:4*M},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 Y_({nodes:e,edges:t,onEdgeContextMenu:n}){let o=e.value,r=Array.from(t.value.values()),s=qe.value,a=s!==null,c=go.value,l=c!==null,u=FR(ie.value.scale);if(r.length===0&&!Ye.value)return null;let p=96,d=Array.from(o.values());if(d.length===0)return null;let m=Math.min(...d.map((x)=>x.position.x))-p,f=Math.min(...d.map((x)=>x.position.y))-p,h=Math.max(...d.map((x)=>x.position.x+x.size.width))+p,v=Math.max(...d.map((x)=>x.position.y+x.size.height))+p,w=Math.max(1,h-m),g=Math.max(1,v-f);return i("svg",{"aria-label":"Canvas connections",role:"img",viewBox:`${m} ${f} ${w} ${g}`,width:w,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((x)=>{let R=Jc(x.from),M=Jc(x.to);if(!R||!M||R.id===M.id)return null;let O=a&&(x.from===s||x.to===s),k=l&&!(c.has(x.from)||c.has(x.to));return i(jR,{edge:x,fromNode:R,toNode:M,focused:O,dimmed:a&&!O||k,selected:Yn.value===x.id,scale:u,onContextMenu:n},x.id,!1,void 0,this)}),Ye.value&&(()=>{let x=Ye.value,R=Jc(x.fromId),M={position:{x:x.cursorX,y:x.cursorY},size:{width:1,height:1}},O;if(R){let k=ru(R,M),N=ru(M,R),_=N.x-k.x,E=N.y-k.y,z=Math.sqrt(_*_+E*E),X=Math.min(Math.max(z*0.35,32),160),W=iu(k,X),J=iu(N,X);O=`M ${k.x} ${k.y} C ${W.x} ${W.y}, ${J.x} ${J.y}, ${N.x} ${N.y}`}else{let k=x.cursorX-x.fromX,N=x.cursorY-x.fromY,_=Math.sqrt(k*k+N*N),E=Math.min(_*0.25,80),z=k/(_||1),X=N/(_||1);O=`M ${x.fromX} ${x.fromY} C ${x.fromX+z*E} ${x.fromY+X*E}, ${x.cursorX-z*E} ${x.cursorY-X*E}, ${x.cursorX} ${x.cursorY}`}return i("g",{children:[i("path",{d:O,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:O,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:x.cursorX,cy:x.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 UR(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 Lm({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-ui)","font-weight":"700",opacity:"0.95",children:t.text},t.id,!1,void 0,this)}return i("path",{d:UR(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 ZR(e){switch(e.type){case"markdown":return i(_l,{node:e},void 0,!1,void 0,this);case"mcp-app":return i(tr,{node:e},void 0,!1,void 0,this);case"webpage":return i(Bl,{node:e},void 0,!1,void 0,this);case"json-render":return i(tr,{node:e},void 0,!1,void 0,this);case"graph":return i(tr,{node:e},void 0,!1,void 0,this);case"board":return i(ou,{node:e},void 0,!1,void 0,this);case"prompt":return i(jl,{node:e},void 0,!1,void 0,this);case"response":return i(Ul,{node:e},void 0,!1,void 0,this);case"status":return i(Fl,{node:e},void 0,!1,void 0,this);case"context":return i(pl,{node:e},void 0,!1,void 0,this);case"ledger":return i(gl,{node:e},void 0,!1,void 0,this);case"trace":return i(Zl,{node:e},void 0,!1,void 0,this);case"file":return i(hl,{node:e},void 0,!1,void 0,this);case"diff":return i(ml,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Dl,{node:e},void 0,!1,void 0,this);case"image":return i(Hl,{node:e},void 0,!1,void 0,this);case"html":return i(ua,{node:e},void 0,!1,void 0,this);case"group":return i(VS,{node:e},void 0,!1,void 0,this);default:return i("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function WR(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 qR(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&&WR(t,c,l)<=n+r.width/2)return r}}return null}var Dm="currentColor",Q_=4,ek=24,GR=14,tk={width:520,height:420};function VR(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 Hm(e){let t=e.trim();if(!t)return[];let n=t.includes(`
|
|
7875
|
-
`)?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=VR(a);if(!c||o.has(c))continue;o.add(c),r.push(c)}return r}function XR(e){let t=Hm(e.getData("text/uri-list"));if(t.length>0)return t;return Hm(e.getData("text/plain"))}function KR(e){if(!e)return!1;return e.types.includes("text/uri-list")||e.types.includes("text/plain")}function Fm(e){if(!(e instanceof HTMLElement))return!1;return Boolean(e.closest('input, textarea, select, [contenteditable="true"], [contenteditable=""]'))}function JR(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 nk({onNodeContextMenu:e,onEdgeContextMenu:t,onCanvasContextMenu:n,annotationMode:o=!1,annotationTool:r=null}){let s=ie.value,a=L(!1),c=L(null),l=L(!1),u=L([]),[p,d]=I(null),[m,f]=I(null),[h,v]=I(null),w=L(null),[g,x]=I(!1),R=L(0),M=L(null),O=L(null);B(()=>{let F=null,Y=on(()=>{ie.value;let Ce=O.current;if(!Ce)return;if(Ce.style.willChange="transform",F)clearTimeout(F);F=setTimeout(()=>{Ce.style.willChange="auto"},180)});return()=>{if(F)clearTimeout(F);Y()}},[]);let k=rl({viewport:ie,disabled:o,onViewportChange:(F)=>{if(a.current||o)return;bo(),bx(F)},onViewportCommit:(F)=>{if(a.current||o)return;bo(),wx(F)}}),N=j((F)=>{w.current=F,v(F)},[]),_=j(async(F,Y,Ce)=>{if(F.length===0)return;let{width:me,height:xe}=tk,ce=24,se=Math.ceil(Math.sqrt(F.length)),Z=Math.ceil(F.length/se),we=se*me+Math.max(0,se-1)*ce,A=Z*xe+Math.max(0,Z-1)*ce;for(let ue=0;ue<F.length;ue++){let fe=ue%se,ge=Math.floor(ue/se),Vt=Y-we/2+fe*(me+ce),_t=Ce-A/2+ge*(xe+ce);await Dn({type:"webpage",content:F[ue],x:Vt,y:_t,width:me,height:xe})}},[]),E=j((F)=>{let Y=k.current;if(!Y)return;if(r==="eraser"){if((F.target instanceof Element?F.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;F.preventDefault(),F.stopPropagation();let Z=Y.getBoundingClientRect(),we=ie.value,A={x:(F.clientX-Z.left-we.x)/we.scale,y:(F.clientY-Z.top-we.y)/we.scale},ue=qR(Array.from(_i.value.values()),A,GR/we.scale);if(ue)yx(ue.id);return}if(r==="text"){if((F.target instanceof Element?F.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;F.preventDefault(),F.stopPropagation(),qe.value=null,Wt();let Z=Y.getBoundingClientRect(),we=ie.value;N({x:(F.clientX-Z.left-we.x)/we.scale,y:(F.clientY-Z.top-we.y)/we.scale,value:""});return}if(r==="pen"){if((F.target instanceof Element?F.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;F.preventDefault(),F.stopPropagation(),qe.value=null,Wt(),l.current=!0;let Z=Y.getBoundingClientRect(),we=ie.value,A={x:(F.clientX-Z.left-we.x)/we.scale,y:(F.clientY-Z.top-we.y)/we.scale};u.current=[A],f({id:"draft-annotation",type:"freehand",points:[A],bounds:{x:0,y:0,width:0,height:0},color:Dm,width:Q_,createdAt:""}),Y.setPointerCapture(F.pointerId);return}if(F.target!==Y)return;if(Ti()||F.button===1||F.button===2){if(!F.shiftKey&&!M.current)qe.value=null,Wt();return}F.preventDefault(),F.stopPropagation(),a.current=!0;let Ce=Y.getBoundingClientRect(),me=F.clientX-Ce.left,xe=F.clientY-Ce.top,ce={startX:me,startY:xe,currentX:me,currentY:xe};M.current=ce,d(ce),Y.setPointerCapture(F.pointerId)},[r,k]);B(()=>on(()=>{let F=ie.value,Y=c.current,Ce=k.current;if(!Y||!Ce)return;let me=Ce.getBoundingClientRect();$l({x:(Y.x-me.left-F.x)/F.scale,y:(Y.y-me.top-F.y)/F.scale})}),[]);let z=j((F)=>{{let me=k.current;if(me){c.current={x:F.clientX,y:F.clientY};let xe=me.getBoundingClientRect(),ce=ie.value;$l({x:(F.clientX-xe.left-ce.x)/ce.scale,y:(F.clientY-xe.top-ce.y)/ce.scale})}}if(l.current){let me=k.current;if(!me)return;let xe=me.getBoundingClientRect(),ce=ie.value,se={x:(F.clientX-xe.left-ce.x)/ce.scale,y:(F.clientY-xe.top-ce.y)/ce.scale},Z=u.current.at(-1);if(Z&&Math.hypot(se.x-Z.x,se.y-Z.y)<2)return;u.current=[...u.current,se],f((we)=>we?{...we,points:u.current}:null);return}if(!a.current||!M.current)return;let Y=k.current?.getBoundingClientRect();if(!Y)return;let Ce={...M.current,currentX:F.clientX-Y.left,currentY:F.clientY-Y.top};M.current=Ce,d(Ce)},[k]),X=j((F)=>{if(l.current){l.current=!1;let se=u.current;if(u.current=[],f(null),se.length>=2)wp({points:se,color:Dm,width:Q_});let Z=k.current;if(Z?.hasPointerCapture(F.pointerId))Z.releasePointerCapture(F.pointerId);return}let Y=M.current;if(!a.current||!Y)return;a.current=!1,M.current=null;let Ce=Math.min(Y.startX,Y.currentX),me=Math.max(Y.startX,Y.currentX),xe=Math.min(Y.startY,Y.currentY),ce=Math.max(Y.startY,Y.currentY);if(me-Ce<=5&&ce-xe<=5)qe.value=null,Wt();if(me-Ce>5||ce-xe>5){let se=ie.value,Z=(Ce-se.x)/se.scale,we=(me-se.x)/se.scale,A=(xe-se.y)/se.scale,ue=(ce-se.y)/se.scale,fe=[];for(let ge of D.value.values()){let Vt=ge.position.x,_t=ge.position.y;if(Vt+ge.size.width>Z&&Vt<we&&_t+ge.size.height>A&&_t<ue)fe.push(ge.id)}if(fe.length>0)ax(fe)}d(null)},[]);B(()=>{if(o)return;if(!l.current&&!m&&!h)return;l.current=!1,u.current=[],f(null),N(null)},[o,m,N,h]);let W=j(()=>{let F=w.current;if(!F)return;let Y=F.value.trim();if(N(null),!Y)return;let Ce={x:F.x,y:F.y};wp({type:"text",points:[Ce],color:Dm,width:ek,text:Y})},[N]);B(()=>{if(r!=="text"&&h)N(null)},[r,N,h]),B(()=>{let F=(ce,se,Z)=>{let we=null;for(let A of D.value.values()){if(A.id===Z||A.type==="group")continue;if(ce>=A.position.x&&ce<=A.position.x+A.size.width&&se>=A.position.y&&se<=A.position.y+A.size.height)we=A.id}return we};function Y(ce){if(!Ye.value)return;let se=k.current;if(!se)return;let Z=se.getBoundingClientRect(),we=ie.value,A=(ce.clientX-Z.left-we.x)/we.scale,ue=(ce.clientY-Z.top-we.y)/we.scale;Ye.value={...Ye.value,cursorX:A,cursorY:ue,targetId:F(A,ue,Ye.value.fromId)}}function Ce(){let ce=Ye.value;if(!ce)return;Ye.value=null;let se=ce.targetId;if(!se)return;if(ce.withLabel){vn("Edge label","label text").then((Z)=>{Er(ce.fromId,se,"relation",Z??void 0)});return}Er(ce.fromId,se,"relation",void 0)}function me(ce){let se=Ye.value;if(!se)return;if(ce.key==="Escape")ce.preventDefault(),Ye.value=null;else if(ce.key==="l"||ce.key==="L")ce.preventDefault(),Ye.value={...se,withLabel:!se.withLabel}}function xe(){Ye.value=null}return document.addEventListener("pointermove",Y),document.addEventListener("pointerup",Ce),document.addEventListener("pointercancel",xe),document.addEventListener("keydown",me),()=>{document.removeEventListener("pointermove",Y),document.removeEventListener("pointerup",Ce),document.removeEventListener("pointercancel",xe),document.removeEventListener("keydown",me)}},[k]);let J=j((F)=>{if(o)return;let Y=k.current;if(!Y||F.target!==Y||!n)return;let Ce=Y.getBoundingClientRect(),me=ie.value,xe=(F.clientX-Ce.left-me.x)/me.scale,ce=(F.clientY-Ce.top-me.y)/me.scale;n(F,xe,ce)},[o,k,n]),G=j((F)=>{F.preventDefault()},[]),T=j((F)=>{if(Fm(F.target instanceof Element?F.target:null))return;F.preventDefault()},[]),q=j((F)=>{if(F.preventDefault(),R.current++,F.dataTransfer?.types.includes("Files")||KR(F.dataTransfer))x(!0)},[]),ae=j((F)=>{if(F.preventDefault(),F.dataTransfer)F.dataTransfer.dropEffect="copy"},[]),be=j((F)=>{if(F.preventDefault(),R.current--,R.current<=0)R.current=0,x(!1)},[]),pe=j(async(F)=>{F.preventDefault(),x(!1),R.current=0;let Y=k.current;if(!Y||!F.dataTransfer)return;let Ce=Y.getBoundingClientRect(),me=ie.value,xe=(F.clientX-Ce.left-me.x)/me.scale,ce=(F.clientY-Ce.top-me.y)/me.scale,se=Array.from(F.dataTransfer.files);if(se.length===0){let Z=XR(F.dataTransfer);await _(Z,xe,ce);return}await qi(se,xe,ce)},[k,_]);B(()=>{let F=async(Y)=>{if(Y.defaultPrevented)return;if(Fm(Y.target instanceof Element?Y.target:null))return;if(Fm(document.activeElement))return;let Ce=Y.clipboardData?.getData("text/plain")??"",me=Hm(Ce);if(me.length===0)return;let xe=k.current;if(!xe)return;Y.preventDefault();let ce=xe.getBoundingClientRect(),se=ie.value,Z=(ce.width/2-se.x)/se.scale,we=(ce.height/2-se.y)/se.scale;await _(me,Z,we)};return document.addEventListener("paste",F),()=>{document.removeEventListener("paste",F)}},[k,_]);let Me=JR(D.value.values(),ot.value,new Set(yp.value.keys())),Te=Jn.value,De=Te?D.value.get(Te.groupId):void 0,cn=Te?D.value.get(Te.nodeId):void 0,Rn=null;if(p){let F=Math.min(p.startX,p.currentX),Y=Math.min(p.startY,p.currentY),Ce=Math.abs(p.currentX-p.startX),me=Math.abs(p.currentY-p.startY);Rn={position:"absolute",left:`${F}px`,top:`${Y}px`,width:`${Ce}px`,height:`${me}px`,pointerEvents:"none"}}return i("div",{class:`canvas-viewport${Ti()?" pan-mode":""}`,ref:k,tabIndex:0,onPointerDown:E,onPointerMove:z,onPointerLeave:()=>{c.current=null,$l(null)},onPointerUp:X,onContextMenu:G,onDblClick:J,onDragStart:T,onDragEnter:q,onDragOver:ae,onDragLeave:be,onDrop:pe,style:{width:"100%",height:"100%",position:"relative",overflow:"hidden",cursor:r==="eraser"?"cell":r==="text"?"text":o||Ye.value||a.current||en.value==="connect"?"crosshair":Ti()?"grab":"default"},children:[i("div",{ref:O,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(C_,{},void 0,!1,void 0,this),i(s_,{},void 0,!1,void 0,this),i(m_,{},void 0,!1,void 0,this),i(f_,{},void 0,!1,void 0,this),i(Y_,{nodes:D,edges:Je,onEdgeContextMenu:t},void 0,!1,void 0,this),Ye.value&&i("div",{class:"edge-hint-pill","data-testid":"edge-hint",style:{left:`${Ye.value.cursorX+14}px`,top:`${Ye.value.cursorY+14}px`},children:[i("span",{class:"edge-hint-main",children:Ye.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",Ye.value.withLabel?" · label on":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Te&&De&&cn&&i("div",{class:"drop-pill","data-testid":"drop-pill",style:{left:`${cn.position.x}px`,top:`${cn.position.y+cn.size.height+10}px`},children:[i("span",{class:"drop-pill-text",children:Te.mode==="add"?`release to add to ${String(De.data.title??"group")}`:`release to remove from ${String(De.data.title??"group")}`},void 0,!1,void 0,this),i("span",{class:"drop-pill-hint",children:Te.mode==="add"?"esc keeps it out":"esc keeps it in"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Lm,{annotations:Array.from(_i.value.values())},void 0,!1,void 0,this),m&&m.points.length>=2&&i(Lm,{annotations:[m]},void 0,!1,void 0,this),Me.map((F)=>i(J_,{node:F,onContextMenu:e,children:ZR(F)},F.id,!1,void 0,this)),jr.value&&i("svg",{class:"snap-guides-svg",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:jr.value.map((F,Y)=>F.axis==="x"?i("line",{x1:F.pos,y1:F.from-20,x2:F.pos,y2:F.to+20,class:"snap-guide-line"},Y,!1,void 0,this):i("line",{x1:F.from-20,y1:F.pos,x2:F.to+20,y2:F.pos,class:"snap-guide-line"},Y,!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:`${ek*s.scale}px`},onInput:(F)=>N({...h,value:F.target.value}),onBlur:W,onPointerDown:(F)=>F.stopPropagation(),onKeyDown:(F)=>{if(F.key==="Enter")F.preventDefault(),W();if(F.key==="Escape")F.preventDefault(),N(null)}},void 0,!1,void 0,this),Rn&&i("div",{class:"lasso-rect",style:Rn},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 su({label:e,value:t,options:n,onChange:o,className:r="",above:s=!1}){let[a,c]=I(!1),l=L(null),u=L(null),p=L(null),d=()=>{c(!1),u.current?.focus()};return Cn(()=>{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((w)=>w===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(sl,{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 ok(){let e=[...ze.value],t=D.value,[n,o]=I(""),[r,s]=I(!1),a=d_.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 k_(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),w=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:w,children:w},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-chip-unpin","aria-label":`Unpin ${w}`,title:"Remove from context",onClick:()=>Qn(h),children:i(Xe,{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(Ai,{size:15,class:"command-bar-icon"},void 0,!1,void 0,this),u&&i(su,{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`:"",w=h.polling?" · polling":"";return{value:h.value,disabled:!h.steerable,label:h.attached?`${h.label}${w}${v}`:h.steerable?`${h.label} · writer${w}${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 ${rt("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 Bm=Ve(()=>{if(hn.value==="disconnected")return"reconnecting";if(hn.value==="connected"&&!Qt.value&&Ar.value>1)return"resyncing";return null});function rk(){let e=Bm.value;if(!e)return null;if(e==="reconnecting"){let t=Pr.value,n=Rr.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 YR={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 Pn(e){if(e.x!==void 0&&e.y!==void 0)return Dn(e);let t=YR[e.type]??{width:360,height:200},n=e.width??t.width,o=e.height??t.height,r=Bo(),s=ie.value,a=await Dn({...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)pt(a.id);return a}var au=!1,ik=!1,Ur=null,Qi=null;function jm(){return au}function cu(){au=!1,ik=!0,sk()}function sk(){if(Ur&&Qi)Ur.removeEventListener("change",Qi);Ur=null,Qi=null}function QR(){if(typeof window>"u"||!window.location)return null;let e=new URLSearchParams(window.location.search).get("theme");if(e==="auto")return"auto";return aa(e)?e:null}function ak(e){if(ik)return;let t=QR();if(!t)return;if(sk(),au=!0,t!=="auto"){e(t);return}Ur=window.matchMedia("(prefers-color-scheme: light)"),Qi=()=>{if(au&&Ur)e(Ur.matches?"daylight":"harbor")},Qi(),Ur.addEventListener("change",Qi)}var eN='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function an(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(eN)),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 tN(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 nN(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 Um={md:"markdown",app:"mcp-app",web:"webpage",ui:"json-render",chart:"graph",ctx:"context",log:"ledger"};function oN(e){let t=e.toLowerCase().trim();if(t.startsWith("type:")){let n=t.slice(5).trim(),r=Object.keys($t).find((a)=>a.startsWith(n));if(r)return{typeFilter:r,remaining:""};let s=Um[n];if(s)return{typeFilter:s,remaining:""}}if(Um[t])return{typeFilter:Um[t],remaining:""};return{typeFilter:null,remaining:e}}function ck({onClose:e,onToggleMinimap:t}){let[n,o]=I(""),[r,s]=I(0),[a,c]=I([]),[l,u]=I("idle"),p=L(null),d=L(null),m=L(null);an(m,!0,{initial:p}),B(()=>{setTimeout(()=>p.current?.focus(),30)},[]),B(()=>{let k=n.trim();if(k.length<2){c([]),u("idle");return}let N=!0;u("loading");let _=window.setTimeout(()=>void re("paletteLibrarySearch",`/api/canvas/search?q=${encodeURIComponent(k)}&scope=library&limit=12`,null).then((E)=>{if(!N)return;if(!E){c([]),u("error");return}c(E.results??[]),u("idle")}),150);return()=>{N=!1,window.clearTimeout(_)}},[n]);let f=j(()=>{let k=[];for(let _ of D.value.values()){let E=_.data.title||$t[_.type],z=_.data.content||_.data.path||"",X=_.type==="group"&&Array.isArray(_.data.children)?_.data.children.length:0;k.push({id:`node:${_.id}`,kind:"node",label:E,description:_.type==="group"?`group · ${X} node${X===1?"":"s"}`:z.length>60?`${$t[_.type].toLowerCase()} · ${z.slice(0,60)}…`:z?`${$t[_.type].toLowerCase()} · ${z}`:$t[_.type].toLowerCase(),icon:Bn(_.type),nodeType:_.type,action:()=>{pt(_.id),e()}})}let N=[{label:"New markdown note",shortcut:"M",icon:Vo,iconTone:"accent",action:()=>{Pn({type:"markdown",title:"New note",width:520,height:360}),e()}},{label:"Link to board…",icon:Bn("board"),iconTone:"accent",action:()=>{window.dispatchEvent(new CustomEvent("pmx-open-board-link")),e()}},...St.value?[]:[{label:"Start agent session",icon:Ai,iconTone:"purple",action:()=>{sr(),e()}}],{label:"Fit view",shortcut:"F",icon:al,iconTone:"muted",action:()=>{Ei(bt().width,bt().height),e()}},{label:"Auto-arrange (grid)",icon:wo,iconTone:"muted",action:()=>{nl(),e()}},{label:"Auto-arrange (graph-aware)",icon:wo,iconTone:"muted",action:()=>{ol(),e()}},{label:"Toggle minimap",icon:cl,iconTone:"muted",action:()=>{t(),e()}},{label:"Toggle theme (Harbor/Daylight)",icon:ll,iconTone:"muted",action:()=>{let _=er(gt.value)==="dark"?"daylight":"harbor";cu(),document.documentElement.setAttribute("data-theme",_),Zi(),gt.value=_,Uc(_),e()}}];for(let _ of N)k.push({id:`action:${_.label}`,kind:"action",label:_.label,..._.shortcut?{shortcut:_.shortcut}:{},icon:_.icon,..._.iconTone?{iconTone:_.iconTone}:{},action:_.action});return k},[e,t]),{typeFilter:h,remaining:v}=oN(n),w=f(),g;if(!n.trim())g=w.map((k)=>({...k,score:0,indices:[]}));else{g=[];for(let k of w){if(h){if(k.kind!=="node"||k.nodeType!==h)continue;if(!v){g.push({...k,score:0,indices:[]});continue}}let N=tN(v||n,k.label);if(N.match)g.push({...k,score:N.score,indices:N.indices})}g.sort((k,N)=>N.score-k.score)}for(let k of a)g.push({id:`library:${k.boardId}:${k.cardId}`,kind:"library",label:k.title||k.boardTitle,description:`${k.boardTitle} · ${k.snippet}`,icon:Bn("board"),score:0,indices:[],action:()=>{(async()=>{if(await sn(k.boardId),Pe.value!==k.boardId)return;for(let N=0;N<40&&Pe.value===k.boardId;N++){if(D.value.has(k.cardId)){pt(k.cardId),e();return}await new Promise((_)=>window.setTimeout(_,25))}})()}});g=[...g.filter((k)=>k.kind==="action"),...g.filter((k)=>k.kind==="node"),...g.filter((k)=>k.kind==="library")];let x=g.findIndex((k)=>k.kind==="node"),R=g.findIndex((k)=>k.kind==="library");B(()=>{if(!n.trim()){go.value=null;return}let k=new Set;for(let N of g)if(N.kind==="node")k.add(N.id.slice(5));go.value=k.size>0?k:null},[n,g]),B(()=>()=>{go.value=null},[]);let M=Math.min(r,Math.max(0,g.length-1)),O=j((k)=>{if(k.key==="ArrowDown")k.preventDefault(),s((N)=>Math.min(N+1,g.length-1));else if(k.key==="ArrowUp")k.preventDefault(),s((N)=>Math.max(N-1,0));else if(k.key==="Enter"){if(k.preventDefault(),g[M])g[M].action()}else if(k.key==="Escape")k.preventDefault(),k.stopPropagation(),e()},[g,M,e]);return B(()=>{let k=d.current;if(!k)return;k.children[M]?.scrollIntoView({block:"nearest"})},[M]),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:(k)=>k.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:(k)=>o(k.target.value),onKeyDown:O,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((k,N)=>{let _=k.icon,E=N===0&&k.kind==="action"?"Actions":N===x?"Jump to":N===R?"Across boards":null;return i("div",{class:"command-palette-row",children:[E&&i("div",{class:"command-palette-group",children:E},void 0,!1,void 0,this),i("button",{type:"button",class:`command-palette-item${N===M?" selected":""}`,onMouseEnter:()=>s(N),onClick:()=>k.action(),children:[i("span",{class:`command-palette-icon tone-${k.iconTone??"kind"}`,"aria-hidden":"true",children:i(_,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"command-palette-label",children:[k.indices.length>0?nN(k.label,k.indices):k.label,k.description&&i("span",{class:"command-palette-desc",children:[" — ",k.description]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),k.shortcut&&i("kbd",{class:"command-palette-kbd",children:k.shortcut},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},k.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:rt("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 lk({onClose:e}){let t=L(null),n=L(null),[o,r]=I(""),[s,a]=I("");an(t,!0,{initial:n});let c=Ut.value.filter((u)=>u.id!==Pe.value&&u.name.toLowerCase().includes(o.trim().toLowerCase())),l=async(u)=>{let p=Ut.value.find((h)=>h.id===u);if(!p)return a("That board is no longer available.");let d=Bo(),m=ie.value;if(!(await re("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:Ut.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 uk(){let[e,t]=I(null),n=j((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"node",x:a.clientX,y:a.clientY,nodeId:c})},[]),o=j((a,c,l)=>{a.preventDefault(),a.stopPropagation(),t({kind:"canvas",x:a.clientX,y:a.clientY,canvasX:c,canvasY:l})},[]),r=j((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"edge",x:a.clientX,y:a.clientY,edgeId:c})},[]),s=j(()=>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 rN="#4bbcFF",iN=[{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 dk({menu:e,onClose:t}){let n;if(e.kind==="node"){let c=D.value.get(e.nodeId);if(!c)return null;n=dN(c)}else if(e.kind==="edge"){let c=e.edgeId,l=Je.value.get(c);n=[{label:l?.label?`Edit label “${l.label.slice(0,18)}${l.label.length>18?"…":""}”`:"Add label…",action:()=>{vn("Edge label (empty clears it)","label text",{initial:l?.label??"",allowEmpty:!0,confirm:"Save"}).then((u)=>{if(u===null)return;Vc(c,{label:u})})}},{separator:!0},...["flow","depends-on","relation","references"].map((u)=>({label:`${l?.type===u?"✓":" "} ${u}`,action:()=>void Vc(c,{type:u})})),{separator:!0},...["solid","dashed","dotted"].map((u)=>({label:`${(l?.style??"solid")===u?"✓":" "} ${u}`,action:()=>void Vc(c,{style:u})})),{separator:!0},{label:"Delete edge",danger:!0,action:()=>void Xc(c)}]}else n=uN(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 sN(e){return(typeof e.data.path==="string"?e.data.path.trim():"")||null}function lu(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 pk(e){if(typeof e.data.color!=="string"||!e.data.color.trim())return null;return lu(e.data.color)}function aN(e){let t=pk(e);return t&&/^#[0-9a-f]{6}$/.test(t)?t:lu(rN)}function Zm(e,t){let n=t?lu(t):null;wt(e.id,{data:{...e.data,color:n}}),kt(e.id,{data:{color:n}})}function cN(e,t){let n=pk(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:()=>{Zm(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:iN.map((o)=>{let r=lu(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:()=>{Zm(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:aN(e),onClick:(o)=>o.stopPropagation(),onInput:(o)=>{Zm(e,o.currentTarget.value),t()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function qm(e,t,n,o){return{x:e-n/2,y:t-o/2}}function lN(e,t){return e.trim().replace(/[?#].*$/,"").split("/").filter(Boolean).at(-1)||t}async function Wm(e){let t=await vn(e.promptLabel,e.placeholder??"");if(!t)return;let n=t.trim();if(!n)return;let o=qm(e.canvasX,e.canvasY,e.width,e.height);if(!(await Dn({type:e.type,...e.type!=="webpage"?{title:lN(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 uN(e,t){return[{label:"New note",action:()=>{let r=qm(e,t,520,360);Dn({type:"markdown",title:"New note",x:r.x,y:r.y,width:520,height:360})}},{label:"Open webpage...",action:()=>{Wm({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:()=>{Wm({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:()=>{Wm({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=qm(e,t,600,400);xi({title:"Group",x:r.x,y:r.y,width:600,height:400})}}]}function dN(e){let t=[],n=sN(e);if(t.push({label:"Focus",action:()=>pt(e.id)}),t.push({label:"Rename…",action:()=>{vn("Rename node","Node title",{initial:typeof e.data.title==="string"?e.data.title:"",confirm:"Save"}).then((l)=>{if(!l?.trim())return;kt(e.id,{title:l.trim()})})}}),Ls.has(e.type))t.push({label:"Expand",shortcut:"⤢",action:()=>En(e.id)});if(t.push({label:e.collapsed?"Expand":"Collapse",action:()=>Gs(e.id)}),El(e))t.push({label:"Open in new tab",action:()=>void Il(e)});let o=ze.value.has(e.id);t.push({label:o?"Unpin from context":"Pin as context",action:()=>Qn(e.id)}),t.push({label:e.pinned?"Unlock position":"Lock position (no auto-arrange)",action:()=>{let l=!e.pinned;wt(e.id,{pinned:l}),kt(e.id,{pinned:l}),Tt()}});let r=Ws.value;if(r&&r.from!==e.id){let l=D.value.get(r.from),u=l?(l.data.title||l.id).slice(0,20):r.from;t.push({label:`Connect from "${u}"`,action:()=>{Er(r.from,e.id,"relation"),Ws.value=null}})}t.push({label:r?"Connect from here (replace)":"Connect from here",action:()=>{Ws.value={from:e.id}}});let s=Array.from(Je.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:()=>Hb("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:()=>{Wc(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)=>cN(e,u)}),l.length>0)t.push({label:`Ungroup (${l.length} node${l.length!==1?"s":""})`,action:()=>{Wo(e.id),wi(e.id)}})}let a=typeof e.data.parentGroup==="string"?e.data.parentGroup:null,c=a?D.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:()=>{Gc(c.id,u)}})}return t.push({separator:!0}),t.push({label:e.type==="group"?"Delete frame (children stay)":"Delete",danger:!0,action:()=>{Uo(e.id)}}),t}function mk(){let e=ze.value.size;if(e===0||Vn.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:hx,title:"Clear all context pins","aria-label":"Clear all context pins",children:i(Xe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function fk({onClose:e}){let t=L(null),[n,o]=I("Bug report"),[r,s]=I(""),[a,c]=I("");return an(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(su,{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}
|
|
7875
|
+
<\/script>`}function FS(){return"<style data-pmx-canvas-ext-app-base>html, body { background: transparent !important; }</style>"}function HS(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 Ui(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 bm(e,t){let n=e?.getBoundingClientRect();return{width:Ui(e?.clientWidth??0,Ui(n?.width??0,t.width)),height:Ui(e?.clientHeight??0,Ui(n?.height??0,t.height))}}function K1(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>0&&!t}function J1(e,t){return Math.max(Ui(e,1),Ui(t,1))}function jS({node:e,expanded:t=!1}){let n=L(null),o=L(null),r=L(null),s=L(null),a=L({}),c=L(void 0),l=L(!1),u=L(void 0),p=L(null),d=L(!1),m=L(null),f=L(0),h=L([]),v=L(""),w=L(!1),g=L(!1),x=L([]),R=L(!1),M=L(!1),O=L(!1),k=L(!1),[N,_]=I("loading"),[E,z]=I(null),[X,W]=I(0),[J,G]=I(!1),[T,q]=I(!1),[ae,be]=I(()=>t||typeof navigator>"u"||typeof window>"u"||!Dr(navigator.userAgent)),pe=e.data.html,Me=e.data.serverName,Te=e.data.appSessionId,De=e.data.toolInput??{},cn=e.data.toolResult,Rn=e.data.toolName??"ext-app",F=e.data.toolDefinition,Y=e.data.toolCallId,Ce=typeof Y==="string"||typeof Y==="number"?Y:void 0,me=e.data.resourceMeta,xe=e.data.sessionStatus,ce=e.data.sessionError,se=e.size.height,Z=e.id,we=W1(e,X),A=G1(null),fe=e.data.axCapabilities?.enabled===!0&&typeof pe==="string"&&pe.length>0,ge=Ze(()=>`ax-${crypto.randomUUID()}`,[]),Vt=fe?V1(ge,Z):"",_t=typeof pe==="string"&&pe.length>0?X1(ge,Z):"",Xt=zS(HS(pe??"",FS()+_t+Vt),A);B(()=>{function Q(de){if(de.source!==n.current?.contentWindow)return;let Ee=de.data;if(!Ee||Ee.source!==Cl||Ee.token!==ge||Ee.nodeId!==Z)return;if(g.current=!0,Ee.kind==="paint-tick"){let Ae=Ee,Ht={content:Ae.content===!0,detail:typeof Ae.detail==="string"?Ae.detail:""};for(let zn of h.current.splice(0))zn(Ht)}}return window.addEventListener("message",Q),()=>window.removeEventListener("message",Q)},[ge,Z]),B(()=>{if(ae)return;LS({remount:()=>{if(k.current)return!1;return It(Z,"mount-slot"),be(!0),!0},awaitBoot:()=>new Promise((Q)=>{let de=window.setTimeout(Ee,MS);function Ee(){window.clearTimeout(de),Q()}x.current.push(Ee)})})},[]),ji({enabled:fe,token:ge,nodeId:Z,sourceSurface:"mcp-app",iframeRef:n});let bn=3,mr=(Q)=>{if(f.current>=bn)return It(Z,`remount-cap-hit (${Q})`),!1;if(R.current)return!0;return f.current+=1,R.current=!0,It(Z,`remount-queued #${f.current} (${Q})`),LS({remount:()=>{if(R.current=!1,k.current||!t&&ot.value===Z)return It(Z,"remount-skipped"),G(!1),!1;return M.current=typeof document<"u"&&document.visibilityState==="hidden",It(Z,`remount-run #${f.current}`),_("loading"),W((de)=>de+1),!0},awaitBoot:()=>new Promise((de)=>{let Ee=window.setTimeout(Ae,MS);function Ae(){window.clearTimeout(Ee),de()}x.current.push(Ae)})}),!0},Ta=1500,xn=()=>new Promise((Q)=>{let de=n.current?.contentWindow;if(!de||k.current){Q("timeout");return}let Ee=!1,Ae=window.setTimeout(()=>{if(Ee)return;Ee=!0,Q("timeout")},Ta);h.current.push((Ht)=>{if(Ee)return;Ee=!0,window.clearTimeout(Ae),v.current=Ht.detail,Q(Ht.content?"content-verified":"tick-no-content")}),de.postMessage({source:Qp,token:ge},"*")}),Nn=async(Q)=>{let de=Date.now()+Q;while(Date.now()<de&&!k.current){if(await xn()==="content-verified")return!0;await new Promise((Ee)=>window.setTimeout(Ee,400))}return!1},no=()=>new Promise((Q)=>{let de=n.current;if(!de){Q();return}let Ee=de.style.width,Ae=de.style.height;de.style.width="140%",de.style.height="140%",requestAnimationFrame(()=>{requestAnimationFrame(()=>{de.style.width=Ee,de.style.height=Ae,It(Z,"soft-expand-cycle"),Q()})})}),rs=600,oo=()=>{if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;let Q=n.current;if(!Q||k.current)return;if(!U1({userAgent:navigator.userAgent,visibilityState:document.visibilityState,rect:Q.getBoundingClientRect(),viewport:{width:window.innerWidth,height:window.innerHeight},alreadyRearmed:O.current}))return;O.current=!0,window.setTimeout(()=>{if(k.current||document.visibilityState==="visible")return;f.current=0,q(!1),M.current=!1,It(Z,"assume-visible-rearm"),mr("assume-visible")},rs)},Co=(Q="")=>{let de=v.current?` [${v.current}]`:"";return typeof document<"u"&&document.visibilityState==="hidden"?`paint-ok (content-verified)${de}${Q} (host hidden)`:`paint-ok (content-verified)${de}${Q}`},is=async()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Dr(navigator.userAgent))return;G(!0);let Q=await xn();if(Q==="content-verified"){It(Z,Co()),G(!1),oo();return}if(It(Z,Q==="tick-no-content"?`paint-fail (tick without content: ${v.current||"unknown"})`:"paint-fail (no tick)"),await no(),Q=await xn(),Q==="content-verified"){It(Z,Co(" (after soft-expand)")),G(!1),oo();return}if(k.current)return;if(Q==="tick-no-content"&&await Nn(3000)){It(Z,Co(" (after content wait)")),G(!1),oo();return}if(k.current)return;if(!mr("paint-fail"))It(Z,"recovery-exhausted"),G(!1),q(!0),oo()};B(()=>{if(t)return;if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;if(!Dr(navigator.userAgent))return;function Q(){if(document.visibilityState!=="visible")return;if(!M.current||k.current)return;M.current=!1,f.current=0,q(!1),It(Z,"visible-again-rearm"),mr("visible-after-hidden-boot")}return document.addEventListener("visibilitychange",Q),()=>document.removeEventListener("visibilitychange",Q)},[t,Z]);let Eo=6000;B(()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Dr(navigator.userAgent))return;if(!Xt.ready||!ae)return;let Q=window.setTimeout(()=>{if(w.current||g.current||k.current)return;mr("boot-watchdog")},Eo);return()=>window.clearTimeout(Q)},[we,Xt.ready,t,ae]),B(()=>()=>{k.current=!0;for(let Q of x.current.splice(0))Q();for(let Q of h.current.splice(0))Q({content:!1,detail:"unmounted"})},[]);let Io=(Q)=>er(Q),ln=t||ot.value===Z;a.current=De,c.current=cn;let fr=xe==="error"&&typeof pe==="string"&&pe.length>0,Gr=xe==="error"?fr?`Live session unavailable — showing saved content. Reopen the app to restore interactivity.${ce?` (${ce})`:""}`:ce??"Saved app session is unavailable. Reopen the app to restore interactivity.":"Reconnecting saved app session...",Vr=(Q)=>{let de=c.current;if(!Q||!d.current||!de)return null;if(u.current===de)return null;if(u.current&&RS(u.current,de))return u.current=de,null;if(p.current)return p.current;let Ee=Q.sendToolResult(de).then(()=>{u.current=de,l.current=!0,_("done")}).catch((Ae)=>{let Ht=Ae instanceof Error?Ae.message:String(Ae);throw z(`Tool result delivery failed: ${Ht}`),Ae}).finally(()=>{p.current=null});return p.current=Ee,Ee};if(B(()=>{if(!pe||!Xt.ready||!ae)return;let Q=n.current;if(!Q)return;let de=!1,Ee=null,Ae=null,Ht=null,zn=null,Zn=null;l.current=!1,u.current=void 0,p.current=null,d.current=!1,w.current=!1,g.current=!1;let Ao=()=>{if(!Ee)return;clearTimeout(Ee),Ee=null};return(async()=>{if(!pe)return;let un=Q.contentWindow;if(!un)throw Error("Ext-app iframe window is unavailable");let wn=(Ie=ot.value===Z?"fullscreen":"inline")=>({theme:Io(gt.value),platform:"web",containerDimensions:bm(Q,{width:e.size.width,height:se}),displayMode:Ie,locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,...F?{toolInfo:{id:Ce,tool:F}}:{}}),Sn=()=>{if(zn!==null)return;zn=requestAnimationFrame(()=>{if(zn=null,de||!d.current)return;je.setHostContext?.(wn())})},ro=()=>{if(Zn!==null)return;Zn=requestAnimationFrame(()=>{Zn=requestAnimationFrame(()=>{if(Zn=null,de||!d.current)return;je.sendHostContextChange?.(wn())})})},Xr=()=>{if(!Dr(navigator.userAgent))return;if(Ae)clearTimeout(Ae);Ae=setTimeout(()=>{if(Ae=null,de)return;is()},BS+200)},je=new hm(null,{name:"PMX Canvas",version:"1.0.0"},{openLinks:{},serverTools:{listChanged:!1},serverResources:{listChanged:!1},logging:{},updateModelContext:{text:{},structuredContent:{}}},{hostContext:wn(ln?"fullscreen":"inline")});je.onsizechange=async({height:Ie})=>{if(K1(Ie,ot.value===Z)){let ut=bm(Q.parentElement??Q,{width:e.size.width,height:se}),Bt=J1(Ie,ut.height);Q.style.height=`${Bt}px`;let io=D.value.get(Z)?.size??e.size,Po=Math.max(io.height,Bt+Di);if(Math.abs(Po-io.height)>8){if(tl(Z,{width:io.width,height:Po}),s.current!==null)window.clearTimeout(s.current);s.current=window.setTimeout(()=>{Tt({recordHistory:!1}),s.current=null},0)}}return{}},je.onopenlink=async({url:Ie})=>(window.open(Ie,"_blank","noopener"),{}),je.onsandboxready=async()=>{await je.sendSandboxResourceReady({html:HS(pe,FS()),sandbox:em,...me?.csp?{csp:me.csp}:{},...me?.permissions?{permissions:me.permissions}:{}})},je.onrequestdisplaymode=async({mode:Ie})=>{let{nextMode:ut,shouldExpand:Bt,shouldCollapse:io}=q1(Ie,ln);if(Bt)En(Z);else if(io)xo();return{mode:ut}},je.oncalltool=async(Ie)=>{if(!Te)throw Error(Gr);try{let ut=await Lr("/api/ext-app/call-tool",{sessionId:Te,nodeId:Z,serverName:Me,toolName:Ie.name,arguments:Ie.arguments??{}});return z(null),ut}catch(ut){let Bt=ut instanceof Error?ut.message:String(ut);throw z(`Tool call failed: ${Bt}`),ut}},je.setRequestHandler(si,async()=>{if(!Te)return{tools:[]};return Lr("/api/ext-app/list-tools",{sessionId:Te})}),je.onlistresources=async()=>Te?Lr("/api/ext-app/list-resources",{sessionId:Te}):{resources:[]},je.onlistresourcetemplates=async()=>Te?Lr("/api/ext-app/list-resource-templates",{sessionId:Te}):{resourceTemplates:[]},je.onreadresource=async(Ie)=>{if(!Te)throw Error(Gr);return Lr("/api/ext-app/read-resource",{sessionId:Te,uri:Ie.uri})},je.onlistprompts=async()=>Te?Lr("/api/ext-app/list-prompts",{sessionId:Te}):{prompts:[]},je.onupdatemodelcontext=async(Ie)=>{if(!Te)return{};return await Lr("/api/ext-app/model-context",{nodeId:Z,...Array.isArray(Ie.content)?{content:Ie.content}:{},...Ie.structuredContent&&typeof Ie.structuredContent==="object"?{structuredContent:Ie.structuredContent}:{}}),{}};let ss=new fm(un,un);if(je.oninitialized=()=>{if(de)return;Ao(),d.current=!0,w.current=!0,It(Z,"initialized"),_("ready"),z(null),Promise.resolve(je.sendHostContextChange(wn(ln?"fullscreen":"inline"))).then(()=>DS(je,a.current,void 0)).then(()=>Vr(je)).then(()=>{let Ie=()=>{for(let ut of x.current.splice(0))ut()};if(typeof navigator<"u"&&Dr(navigator.userAgent))Nn(4000).then((ut)=>{It(Z,ut?"settled (content-verified)":`settled (content-timeout${v.current?`: ${v.current}`:""})`),Ie()});else It(Z,"settled"),Ie();ro(),Xr()}).catch((Ie)=>{let ut=Ie instanceof Error?Ie.message:String(Ie);z(`Bridge bootstrap failed: ${ut}`)})},Ee=setTimeout(()=>{if(de||d.current)return;let Ie=c.current,ut=wn(ln?"fullscreen":"inline");d.current=!0,je.setHostContext?.(ut),Promise.resolve(je.sendHostContextChange(ut)).then(()=>DS(je,a.current,Ie)).then(()=>{if(l.current=Boolean(Ie),Ie)u.current=Ie;if(_(Ie?"done":"ready"),z(null),ro(),Xr(),g.current){It(Z,"settled (fallback)");for(let Bt of x.current.splice(0))Bt()}}).catch((Bt)=>{let io=Bt instanceof Error?Bt.message:String(Bt);z(`Bridge bootstrap fallback failed: ${io}`)})},1200),await je.connect(ss),de){Ao(),await ss.close();return}if(o.current=je,r.current=ss,Ht=new ResizeObserver(Sn),Ht.observe(Q),Q.parentElement)Ht.observe(Q.parentElement);let as=!0;m.current=gt.subscribe((Ie)=>{if(as){as=!1;return}if(de)return;je.setHostContext?.({...wn(),theme:Io(Ie)}),je.sendHostContextChange?.(wn())}),Vr(je)})().catch((un)=>{Ao(),console.error("[ext-app] Bridge init failed:",un),z(un?.message??"Bridge initialization failed")}),()=>{if(de=!0,Ao(),Ae)clearTimeout(Ae),Ae=null;if(Ht?.disconnect(),Ht=null,zn!==null)cancelAnimationFrame(zn),zn=null;if(Zn!==null)cancelAnimationFrame(Zn),Zn=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((un)=>{console.error("[ext-app] transport close failed:",un)}),r.current=null}},[we,Xt.key,ae]),B(()=>{if(cn&&o.current&&(N==="ready"||N==="done"))Vr(o.current)},[cn,N]),B(()=>{let Q=o.current;if(n.current)n.current.style.height="100%";if(!Q||!d.current)return;let de=null,Ee=null;return de=requestAnimationFrame(()=>{de=null,Ee=requestAnimationFrame(()=>{if(Ee=null,!d.current)return;let Ae={theme:Io(gt.value),platform:"web",containerDimensions:bm(n.current,{width:e.size.width,height:se}),displayMode:ln?"fullscreen":"inline",locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};Q.setHostContext?.(Ae),Q.sendHostContextChange?.(Ae)})}),()=>{if(de!==null)cancelAnimationFrame(de);if(Ee!==null)cancelAnimationFrame(Ee)}},[ln,se]),!pe)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 ",Rn," 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:[xe&&xe!=="ready"&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:xe==="error"&&!fr?"color-mix(in srgb, var(--c-danger) 12%, transparent)":"color-mix(in srgb, var(--c-warn) 10%, transparent)",color:xe==="error"&&!fr?"var(--c-danger)":"var(--c-warn)",borderBottom:`1px solid ${xe==="error"&&!fr?"color-mix(in srgb, var(--c-danger) 12%, transparent)":"color-mix(in srgb, var(--c-warn) 15%, transparent)"}`},children:Gr},void 0,!1,void 0,this),E&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:"color-mix(in srgb, var(--c-danger) 12%, transparent)",color:"var(--c-danger)",borderBottom:"1px solid color-mix(in srgb, var(--c-danger) 12%, transparent)",display:"flex",alignItems:"center",gap:"6px"},children:[i("span",{children:"⚠"},void 0,!1,void 0,this),i("span",{style:{flex:1},children:E},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>{z(null),_("loading"),W((Q)=>Q+1)},style:{background:"var(--c-surface-hover)",border:"1px solid color-mix(in srgb, var(--c-danger) 12%, transparent)",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(Xe,{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:[ae&&i("iframe",{ref:n,...Xt.attributes,sandbox:A,allow:PS(me?.permissions),style:{flex:1,width:"100%",height:"100%",minHeight:0,border:"none",background:"var(--c-panel)",pointerEvents:ln?"auto":"none"},title:`Ext App: ${Rn}`},we,!1,void 0,this),T&&!E&&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:(Q)=>{Q.stopPropagation(),It(Z,"manual-retry"),f.current=0,q(!1),_("loading"),W((de)=>de+1)},style:{background:"var(--c-surface-hover)",border:"1px solid color-mix(in srgb, var(--c-warn) 15%, transparent)",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),(N==="loading"||J)&&!E&&!T&&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:N==="loading"?`Connecting to ${Rn}...`:"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),!ln&&!(T&&!E)&&i("button",{type:"button",onClick:(Q)=>{Q.stopPropagation(),En(Z)},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 la=new Map,US=!1;function ZS(e,t,n){if(!US)US=!0,on(()=>{let s=D.value,a=Tr.value;for(let[c,l]of la){let u=s.get(c);if(!u||l.epoch!==a||l.version!==u.data.specVersion||l.documentUrl!==u.data.url)la.delete(c)}}),window.addEventListener("message",(s)=>{let a=s.data;if(!a||a.source!==Yp||a.type!=="snapshot"||typeof a.nodeId!=="string")return;let c=la.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=D.value.get(e);if(!o)return;let r=la.get(e);if(!r)r={epoch:Tr.value,version:o.data.specVersion,documentUrl:o.data.url,state:null,owners:[]},la.set(e,r);r.owners=[...r.owners.filter((s)=>s.source!==n).slice(-1),{token:t,source:n}],n.postMessage({source:Yp,type:"restore",token:t,state:r.state},"*")}function Y1(e,t,n,o,r,s,a,c){if(!e)return e;try{let l=ke()&&e.startsWith("/"),u=new URL(e,l?"https://pmx.invalid":window.location.origin);if(u.searchParams.set("theme",er(gt.value)),t)u.searchParams.set("display","expanded");if(typeof n==="number")u.searchParams.set("v",String(n));if(o)u.searchParams.set("axToken",o);if(r)u.searchParams.set("axNodeId",r);if(s)u.searchParams.set("frameToken",s);if(a)u.searchParams.set("fit","content");if(c)u.searchParams.set("stateToken",c);return l?`${u.pathname}${u.search}`:u.toString()}catch{return e}}function Q1(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 xm({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=L(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=(w,g)=>i("iframe",{ref:g?void 0:t,...w.source,class:s,sandbox:a,allow:c,tabIndex:l,loading:Lt.value==="srcdoc"?void 0:"lazy",onLoad:(x)=>{if(o?.(x.currentTarget),!g){n();return}let R=++h.current,M=x.currentTarget;requestAnimationFrame(()=>requestAnimationFrame(()=>{if(h.current!==R)return;t.current=M,d(w),f(null),n()}))},style:{position:"absolute",inset:0,width:"100%",height:"100%",visibility:g?"hidden":"visible",background:"var(--c-panel-soft)"},title:r},w.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 tr({node:e,expanded:t=!1}){if(e.data.mode==="ext-app")return i(jS,{node:e,expanded:t},void 0,!1,void 0,this);return i(eR,{node:e,expanded:t},void 0,!1,void 0,this)}function eR({node:e,expanded:t}){let n=L(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=Ze(()=>c?`ax-${crypto.randomUUID()}`:"",[c]),p=lm(e)&&!t,d=Ze(()=>p?`frame-${crypto.randomUUID()}`:"",[p]);Fi(e,n,d),ji({enabled:c&&Boolean(u),token:u,nodeId:e.id,sourceSurface:l,iframeRef:n});let m=gn.value,f=()=>{if(!c||!u||m==null)return;n.current?.contentWindow?.postMessage({source:In,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=Ze(()=>r?`ui-${crypto.randomUUID()}`:"",[r,h,e.data.url]),w=Y1(e.data.url||"",t,h,u||void 0,c?e.id:void 0,d||void 0,p,v||void 0),g=Hi(w),x=e.data.sourceServer||"",R=e.data.hostMode||"hosted",M=e.data.fallbackReason,O=e.data.trustedDomain===!0||Q1(w);if(R==="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),M&&i("div",{style:{color:"var(--c-muted)",fontSize:"11px"},children:["Reason: ",M]},void 0,!0,void 0,this),i("a",{href:w,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all"},children:w},void 0,!1,void 0,this),x&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px"},children:["Source: ",x]},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:[!O&&i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"color-mix(in srgb, var(--c-warn) 10%, transparent)",color:"var(--c-warn)",borderBottom:"1px solid color-mix(in srgb, var(--c-warn) 15%, transparent)"},children:"Unverified domain"},void 0,!1,void 0,this),i(xm,{source:g,iframeRef:n,onDocumentLoad:(k)=>{if(v&&k.contentWindow)ZS(e.id,v,k.contentWindow)},onLoad:f,title:`MCP App: ${x}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var tR=null;function Zi(){tR=null}var WS={idle:"var(--c-muted)",running:"var(--c-accent)",planning:"var(--c-agent)",thinking:"var(--c-agent)",drafting:"var(--c-accent)",tooling:"var(--c-accent)",review:"var(--c-ok)","waiting-approval":"var(--c-warn)",waiting:"var(--c-warn)"};function nR(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 Fl({node:e}){let t=nR(e),n=e.data.detail||"",o=e.data.message||"",r=e.data.level||"ok",s=e.data.activeTool,a=e.data.subagent,c=WS[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-agent)"},children:[i("span",{style:{fontSize:"10px"},children:"⚙"},void 0,!1,void 0,this),i("span",{style:{fontFamily:"var(--font-code)",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 Wi(e){return typeof e==="string"&&e.trim().length>0?e.trim():null}function qS(e){if(typeof e==="string"){let r=Wi(e);return r?{title:"Evidence warning",detail:r}:null}if(!e||typeof e!=="object")return null;let t=e,n=Wi(t.title)??"Evidence warning",o=Wi(t.detail);return o?{title:n,detail:o}:null}function oR(e){let t=[],n=qS(e.data.warning);if(n)t.push(n);let o=e.data.warnings;if(Array.isArray(o))for(let s of o){let a=qS(s);if(a)t.push(a)}let r=Wi(e.data.validationStatus)?.toLowerCase();if(r==="failed"||r==="invalid")t.push({title:"Image failed validation",detail:Wi(e.data.validationMessage)??"Review this image before using it as evidence."});return t}function rR(e){let t=[e.data.title,e.data.caption,e.data.alt,e.data.src,e.data.path].map((n)=>Wi(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 GS(e){let t=oR(e);if(t.length>0)return t;if(rR(e))return[{title:"Captured login page",detail:"This image looks like an auth screen. Treat it as environment context, not product evidence."}];return[]}function Hl({node:e,expanded:t=!1}){let n=e.data.src||"",o=e.data.alt||e.data.title||"Image",r=e.data.caption||"",s=GS(e),a=Pi(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,w]=I({w:0,h:0}),g=L(null),x=L(!1),R=L({x:0,y:0}),M=j((J)=>{let G=J.target;w({w:G.naturalWidth,h:G.naturalHeight}),l(!0),p(!1)},[]),O=j(()=>{p(!0),l(!1)},[]);B(()=>{m(1),h({x:0,y:0})},[n]);let k=j((J)=>{J.preventDefault(),J.stopPropagation();let G=J.deltaY>0?0.9:1.1;m((T)=>Math.max(0.25,Math.min(10,T*G)))},[]),N=j((J)=>{if(d<=1)return;J.stopPropagation(),x.current=!0,R.current={x:J.clientX,y:J.clientY},J.target.setPointerCapture(J.pointerId)},[d]),_=j((J)=>{if(!x.current)return;let G=J.clientX-R.current.x,T=J.clientY-R.current.y;R.current={x:J.clientX,y:J.clientY},h((q)=>({x:q.x+G,y:q.y+T}))},[]),E=j(()=>{x.current=!1},[]),z=j(()=>{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 X=v.w>0?`${v.w}×${v.h}`:"",W=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((J)=>i("div",{class:"image-node-warning",children:[i("span",{class:"image-node-warning-title",children:J.title},void 0,!1,void 0,this),i("span",{class:"image-node-warning-detail",children:J.detail},void 0,!1,void 0,this)]},`${J.title}-${J.detail}`,!0,void 0,this))},void 0,!1,void 0,this),i("div",{class:"image-node-viewport",onWheel:k,onPointerDown:N,onPointerMove:_,onPointerUp:E,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:M,onError:O,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||X||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:[X&&i("span",{children:X},void 0,!1,void 0,this),d!==1&&i("button",{type:"button",class:"image-node-zoom-reset",onClick:z,title:"Reset zoom",children:[W,"% ",i(il,{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 VS({node:e}){if((e.data.children??[]).filter((o)=>D.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 iR(e){try{return new URL(e).host}catch{return e}}function sR(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleString()}function Bl({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=sR(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,w]=I(t);B(()=>{if(t)w(!0)},[t]);let g=j(async()=>{if(!n||f)return;h(!0);try{await Wc(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 x=a==="ready"?"var(--c-ok)":a==="error"?"var(--c-danger)":"var(--c-muted)";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:iR(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:x,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.04em",flexShrink:0},children:[i("span",{style:{width:"7px",height:"7px",borderRadius:"999px",background:x}},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:()=>w((R)=>!R),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 XS(e){return e.type==="html"&&e.data.presentation===!0}function aR(e){let t=e;if(t?.enabled!==!0)return"disabled";if(!Array.isArray(t.allowed))return"enabled:default";let n=[...new Set(t.allowed.filter((o)=>typeof o==="string"))].sort();return n.length>0?`enabled:${n.join(",")}`:"disabled"}function ua({node:e,expanded:t=!1,presentation:n=!1,presentationExitToken:o,autoFocus:r=!1}){let s=L(null),a=gt.value,c=aR(e.data.axCapabilities),l=Ze(()=>`theme-${crypto.randomUUID()}`,[]),u=Ze(()=>`ax-${crypto.randomUUID()}`,[c]),p=Ze(()=>`frame-${crypto.randomUUID()}`,[]),d=typeof e.data.html==="string"?e.data.html:typeof e.data.content==="string"?e.data.content:"",m=Ze(()=>Mi(d),[d]),f=Ze(()=>d?oa(e.id,{theme:a,themeToken:l,present:n,presentToken:o,v:m,axToken:u,frameToken:p}):"",[d,n,o,l,m,e.id,u,p]),h=Hi(f);Fi(e,s,t?"":p),ji({enabled:!0,token:u,nodeId:e.id,sourceSurface:"html-node",iframeRef:s}),B(()=>{if(s.current?.contentWindow?.postMessage({source:In,type:"theme-update",token:l,theme:a},"*"),r)s.current?.focus()},[a,l]);let v=e.data.axCapabilities,w=v?.enabled===!0&&(!Array.isArray(v.allowed)||v.allowed.length>0),g=gn.value;B(()=>{if(!w||g==null)return;s.current?.contentWindow?.postMessage({source:In,type:"ax-update",token:u,state:g},"*")},[w,g,u]),B(()=>{if(!r)return;let R=window.setTimeout(()=>s.current?.focus(),0);return()=>window.clearTimeout(R)},[r,f]);let x=()=>{if(s.current?.contentWindow?.postMessage({source:In,type:"theme-update",token:l,theme:a},"*"),w&&gn.value!=null)s.current?.contentWindow?.postMessage({source:In,type:"ax-update",token:u,state:gn.value},"*");if(r)s.current?.focus()};if(!d)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(xm,{source:h,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:x},void 0,!1,void 0,this)}var wm=null;async function KS(){if(!wm)wm=await Ub();return wm}function JS(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 cR({html:e}){let t=L(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=to(e),n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function lR(e,t){return`${e.role}:${e.status??"none"}:${t}:${e.text}`}function YS({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 QS({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(Xe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jl({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,w]=I(null),[g,x]=I(new Map),R=L(null),M=L(null),O=n[n.length-1],k=`${n.length}:${O?.role??""}:${O?.status??""}:${Math.floor((O?.text?.length??0)/200)}`;B(()=>{if(t&&c&&R.current)R.current.focus()},[t,c]),B(()=>{if(!k)return;if(M.current)M.current.scrollTo({top:M.current.scrollHeight,behavior:"smooth"})},[k]);let N=L(null),_=L(n);_.current=n,B(()=>{let G=n.some((q)=>q.role==="assistant"&&q.status==="streaming"),T=()=>{let q=!1,be=_.current.map((pe,Me)=>({turn:pe,index:Me})).filter(({turn:pe})=>pe.role==="assistant"&&pe.text);if(be.length===0)return;return Promise.all(be.map(async({turn:pe,index:Me})=>{let Te=await Kn(pe.text);return{index:Me,html:to(Te)}})).then((pe)=>{if(q)return;let Me=new Map;for(let Te of pe)Me.set(Te.index,Te.html);x(Me)}),()=>{q=!0}};if(!G){if(N.current)clearTimeout(N.current),N.current=null;return T()}if(N.current)clearTimeout(N.current);return N.current=setTimeout(()=>{N.current=null,T()},400),()=>{if(N.current)clearTimeout(N.current),N.current=null}},[n]);let E=j(async()=>{let G=d.trim();if(!G)return;let T=d;w(null),ve(e.id,{turns:[{role:"user",text:G,status:"pending"}],threadStatus:"pending",text:G}),m("");let q=Array.isArray(e.data.contextNodeIds)?e.data.contextNodeIds:void 0;if(!(await js(G,e.position,e.id,q,e.id)).ok)ve(e.id,{turns:[],threadStatus:"draft",text:"",status:"draft"}),m(T),w("Failed to send prompt. Your draft has been restored.")},[d,e.id,e.position,e.data.contextNodeIds]),z=j(async()=>{let G=f.trim();if(!G)return;let T=f;w(null);let q=Array.isArray(e.data.turns)?[...e.data.turns]:[];if(q.push({role:"user",text:G,status:"pending"}),ve(e.id,{turns:q,threadStatus:"pending"}),h(""),!(await Zb(e.id,G)).ok)q.pop(),ve(e.id,{turns:q,threadStatus:"answered"}),h(T),w("Failed to send reply. Your draft has been restored.")},[f,e.id,e.data.turns]),X=j((G)=>{if(G.key==="Enter"&&(G.metaKey||G.ctrlKey)){G.preventDefault(),E();return}if(G.key==="Tab"&&d.startsWith("/")){G.preventDefault();let T=d.slice(1).split(/\s/)[0];if(T)KS().then((q)=>{let ae=JS(T,q);if(ae)m(`/${ae}`)})}},[E,d]),W=j((G)=>{if(G.key==="Enter"&&(G.metaKey||G.ctrlKey)){G.preventDefault(),z();return}if(G.key==="Tab"&&f.startsWith("/")){G.preventDefault();let T=f.slice(1).split(/\s/)[0];if(T)KS().then((q)=>{let ae=JS(T,q);if(ae)h(`/${ae}`)})}},[z,f]),J=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(YS,{count:J},void 0,!1,void 0,this),i(QS,{message:v,onDismiss:()=>w(null)},void 0,!1,void 0,this),i("textarea",{ref:R,value:d,onInput:(G)=>m(G.target.value),onKeyDown:X,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-ui)",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:E,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(YS,{count:J},void 0,!1,void 0,this),i(QS,{message:v,onDismiss:()=>w(null)},void 0,!1,void 0,this),i("div",{ref:M,style:{flex:1,overflow:"auto",minHeight:0},children:n.map((G,T)=>i("div",{children:[T>0&&i("div",{class:"thread-turn-divider"},void 0,!1,void 0,this),G.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:G.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${G.status==="streaming"?" pulsing":""}`},void 0,!1,void 0,this),"PMX"]},void 0,!0,void 0,this),G.status==="streaming"&&!G.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:G.text?1:0.4},children:g.get(T)?i(_e,{children:[i(cR,{html:g.get(T)??""},void 0,!1,void 0,this),G.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:G.status==="streaming"?"Waiting for response…":G.text||"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},lR(G,T),!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:(G)=>h(G.target.value),onKeyDown:W,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-ui)",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:!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 uR({html:e}){let t=L(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=to(e),n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function Ul({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 Kn(n).then((p)=>{if(!u)s(to(p))}),()=>{u=!0}},[n]);let l=j(()=>{js("",{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(uR,{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 e_(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 t_={mcp:"var(--c-muted)",file:"var(--c-muted)",subagent:"var(--c-subagent)",other:"var(--c-muted)"},dR={running:"⠋",success:"✓",failed:"✕"},pR={running:"var(--c-accent)",success:"var(--c-ok)",failed:"var(--c-danger)"};function Zl({node:e}){let{toolName:t,category:n,status:o,duration:r,resultSummary:s,error:a}=e_(e.data),c=t_[n]??t_.other,l=dR[o]??"◌",u=pR[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(--font-code)",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)}var mR=new Set(["png","jpg","jpeg","gif","svg","webp","bmp","ico","avif"]),fR=new Set(["md","mdx","markdown"]);function hR(e){let t=e.split(".").pop()?.toLowerCase()??"";if(mR.has(t))return"image";if(fR.has(t))return"markdown";return"file"}async function qi(e,t,n){let o=Pe.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=hR(u.name),v=u.name;if(/\.(pdf|pptx?|xlsx?|docx?|od[pts])$/i.test(v)){if(!o||u.size===0||u.size>20971520){rn("remove","File not attached","Open a board and choose a nonempty file under 20 MiB.");continue}let w=new URLSearchParams({boardId:o,name:v,mime:u.type,x:String(m),y:String(f)});rn("context","Attaching document",v),await re("attachDocument",`/api/canvas/attachments?${w}`,null,{method:"POST",body:u});continue}if(Pe.value!==o)return;if(h==="image"){let w=new FileReader,g=await new Promise((x)=>{w.onload=()=>x(w.result),w.readAsDataURL(u)});if(Pe.value!==o)return;await Dn({type:"image",title:v,content:g,x:m,y:f,width:400,height:300,...o?{boardId:o}:{}})}else{let w=await u.text();if(Pe.value!==o)return;let g=h==="markdown"||h==="file";await Dn({type:h,title:v,content:w,x:m,y:f,width:g?720:400,height:g?500:300,...o?{boardId:o}:{}})}}}var n_={width:260,height:150},gR={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 _m(e){return!!e&&e in $t}function _o(e){if(!e)return null;let t=D.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 Sm(e){return{x:e.left+e.width/2,y:e.top+e.height/2}}function da(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 o_(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 km({intent:e}){let t=_m(e.nodeType)?Bn(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:()=>Oi.value=e.id,onMouseLeave:()=>{if(Oi.value===e.id)Oi.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(),Cr(e)},children:i(Xe,{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 r_({intent:e,rect:t}){let n=_m(e.nodeType)?Bn(e.nodeType):null,o=_m(e.nodeType)?$t[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:da(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(km,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function i_({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:da(e)},children:[n==="edit"&&i("div",{class:"intent-edit-bar"},void 0,!1,void 0,this),i(km,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function vR(e){let t=e.phase==="settling"?_o(e.settledNodeId):null;switch(e.kind){case"create":{if(!e.position)return null;let n=e.nodeType&&gR[e.nodeType]||n_,o=t??{left:e.position.x,top:e.position.y,...n};return i(r_,{intent:e,rect:o},e.id,!1,void 0,this)}case"move":{if(!e.position)return null;let o=_o(e.nodeId)??n_,r=t??{left:e.position.x,top:e.position.y,width:o.width,height:o.height};return i(r_,{intent:e,rect:r},e.id,!1,void 0,this)}case"remove":{let n=t??_o(e.nodeId);if(!n)return null;return i(i_,{intent:e,rect:n,variant:"remove"},e.id,!1,void 0,this)}case"edit":{let n=t??_o(e.nodeId);if(!n)return null;return i(i_,{intent:e,rect:n,variant:"edit"},e.id,!1,void 0,this)}case"connect":{if(!e.edge)return null;let n=_o(e.edge.from),o=_o(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:da(e)},children:i(km,{intent:e},void 0,!1,void 0,this)},e.id,!1,void 0,this)}default:return null}}function s_(){let e=Array.from(lt.value.values());if(B(()=>{function t(n){if(n.key!=="Escape")return;let o=Oi.value;if(!o)return;let r=lt.value.get(o);if(!r||r.phase!=="forming")return;n.stopImmediatePropagation(),n.preventDefault(),Cr(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&<.value.get(n)?.phase!=="forming")$r(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=_o(t.edge.from),o=_o(t.edge.to);if(!n||!o)return null;return i("path",{d:o_(Sm(n),Sm(o)),class:`intent-edge type-${t.edge.type}`,style:{opacity:da(t)}},`line-${t.id}`,!1,void 0,this)}if(t.kind==="move"&&t.position){let n=_o(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:o_(Sm(n),r),class:"intent-trail",markerEnd:"url(#intent-arrow)",style:{opacity:da(t)}},`line-${t.id}`,!1,void 0,this)}return null})]},void 0,!0,void 0,this),e.map(vR)]},void 0,!0,void 0,this)}var a_=32000;var Wl="Agent session";function c_(e){return e.some((t)=>t.attached)}function l_(e){return e.filter((t)=>!t.attached)}function nr(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"}}var At=K([]),Tm=K({used:0,total:a_}),or=K([]),Fr=K(!1),Gi=K(!1),Cm=K(null);function An(e){return At.value.find((n)=>n.sessionId===e)?.parentAgentId?"var(--c-subagent)":"var(--c-agent)"}function u_(e){return(e.trim().replace(/^[^a-z0-9]+/i,"").charAt(0)||e.trim().charAt(0)||"?").toUpperCase()}function ql(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 St=Ve(()=>c_(At.value)),Em=Ve(()=>l_(At.value)),d_=Ve(()=>{let e=new Set;return[...At.value].filter((t)=>t.label!==Wl).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))}),p_=Ve(()=>At.value.filter((e)=>e.attached)),Vi=Ve(()=>At.value.find((e)=>e.attached)??null);function yR(e){let t=new Set;for(let n of e)if(n.nodeId&&n.kind!=="create")t.add(n.nodeId);return t}var Gl=Ve(()=>yR(lt.value.values()));function Vl(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 Im(e){if(!e)return;if(Array.isArray(e.presences))At.value=e.presences;if(e.budget&&Number.isFinite(e.budget.used)&&Number.isFinite(e.budget.total))Tm.value={used:e.budget.used,total:e.budget.total};if(Array.isArray(e.activity))or.value=e.activity}function m_(){let e=L(new Map),t=ie.value.scale,n=D.value,o=1/Math.max(0.05,t),r=At.value.map((s)=>{let a=Vl(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":An(s.sessionId)},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:nr(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 ko(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 f_(){let e=ko(sa.value.length>0?5000:0),t=sa.value.filter((o)=>o.cursor!==null&&(!o.lastSeenAt||e-Date.parse(o.lastSeenAt)<lS+5000));if(t.length===0)return null;let n=1/Math.max(0.05,ie.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 Xl(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 Pm(){let e=gn.value;return e&&typeof e==="object"?e:{}}var h_=Ve(()=>Pm().workItems??[]),Rm=Ve(()=>Pm().approvalGates??[]),Hr=Ve(()=>Rm.value.filter((e)=>e.status==="pending")),rr=Ve(()=>{let e=Pm().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 g_(e){return(await fn("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 v_=Ve(()=>Rm.value.filter((e)=>e.status==="held")),y_=Ve(()=>Rm.value.filter((e)=>e.status==="approved"||e.status==="rejected")),b_=K({events:[],evidence:[],steering:[]}),Br=K("all");function Nm(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 bR=new Set(["api","mcp","sdk","cli"]);function Am(e,t){if(e?.trim())return e.trim();let n=t?.trim();if(n&&!bR.has(n))return n;return null}var xR=/^(node|edge|group|annotation|jsonrender|graph|render)\.|^arrange$|^canvas\.clear$|^snapshot\.restore$/,x_=K(null),fa=K(new Set),wR={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 SR(e,t=40,n=[],o=null,r="all"){let s=n.find((l)=>xR.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,...!ke()&&o?.actor==="agent"&&s?.id===l.id?{undoable:!0}:{}})),...e.events.map((l)=>({id:`event-${l.id}`,kind:l.kind,label:wR[l.kind]??l.kind,body:l.detail?`${l.summary} — ${l.detail}`:l.summary,createdAt:l.createdAt,who:Am(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:Am(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:Am(l.agentId,l.source)}})],c=r==="all"?a:a.filter((l)=>Nm(l.kind)===r);return c.sort((l,u)=>l.createdAt<u.createdAt?1:l.createdAt>u.createdAt?-1:0),c.slice(0,t)}var w_=Ve(()=>SR(b_.value,40,or.value,x_.value,Br.value));async function ir(){let[e,t]=await Promise.all([re("refreshTimeline","/api/canvas/ax/timeline?limit=40",null),re("refreshHistoryTop","/api/canvas/history",null)]);if(t)x_.value=t.top??null;if(!e)return;b_.value={events:Array.isArray(e.events)?e.events:[],evidence:Array.isArray(e.evidence)?e.evidence:[],steering:Array.isArray(e.steering)?e.steering:[]}}async function zm(e){if(!(await fn("undoAgentEdit","/api/canvas/undo",{method:"POST"})).ok)return!1;return fa.value=new Set([...fa.value,e.id]),await Ln("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"})}),ir(),!0}async function Mm(e=!1){if(ke())return rn("remove","Undo / redo unavailable","Open the local PMX workbench to use shared history."),!1;let t=await fn(e?"redo":"undo",e?"/api/canvas/redo":"/api/canvas/undo",{method:"POST"});if(t.ok)ir();return t.ok}async function S_(e,t){if(!(await fn("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 Ln("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 __(e){return(await fn("reopenGate",`/api/canvas/ax/approval/${encodeURIComponent(e.id)}/reopen`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser"})})).ok}async function k_(e,t){return(await fn("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 sr(){return(await fn("startSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser",label:Wl,attached:!0,phase:"idle"})})).ok}async function Kl(e){return(await fn("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}function pa(e){if(!Array.isArray(e))return[];return e.flatMap((t)=>{if(!t||typeof t!=="object")return[];let n=t;if(typeof n.id!=="string"||typeof n.title!=="string")return[];return[{id:n.id,title:n.title,...typeof n.reason==="string"?{reason:n.reason}:{}}]})}var ar=K(null);function $m(e){let t=Xi.value?.context;ar.value=e&&t?new Set([...t.read,...t.pinned,...t.created,...t.edited].map((n)=>n.id)):null}var Xi=K(null);function ma(e,t){let n=new Set(e.map((o)=>o.id));return[...e,...t.filter((o)=>!n.has(o.id))]}function _R(e,t){return{labels:[...new Set([...e.labels,...t.labels])],sessions:e.sessions+1,endedAt:t.endedAt,endedBy:e.endedBy===t.endedBy?t.endedBy:void 0,counts:t.counts,snapshot:null,context:{read:ma(e.context.read,t.context.read),pinned:ma(e.context.pinned,t.context.pinned),created:ma(e.context.created,t.context.created),edited:ma(e.context.edited,t.context.edited),changedSinceRead:ma(e.context.changedSinceRead,t.context.changedSinceRead)}}}function T_(e){let{counts:t,snapshot:n,context:o}=e;if(typeof e.label!=="string"||typeof e.endedAt!=="string")return;if(e.unchanged===!0||typeof e.parentAgentId==="string")return;let r={labels:[e.label],sessions:1,endedAt:e.endedAt,endedBy:e.endedBy==="human"||e.endedBy==="agent"||e.endedBy==="idle-timeout"?e.endedBy:void 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,context:{read:pa(o?.read),pinned:pa(o?.pinned),created:pa(o?.created),edited:pa(o?.edited),changedSinceRead:pa(o?.changedSinceRead)}},s=Xi.value;if(Xi.value=s?_R(s,r):r,s&&ar.value)$m(!0)}function Jl(){Xi.value=null,ar.value=null}function C_(){if(!St.value)return null;let e=rr.value;if(!e)return null;let t=D.value,n=e.nodeIds.map((s)=>t.get(s)).filter((s)=>s!==void 0),o=Xl(n,e.padding);if(!o)return null;let r=1/Math.max(0.05,ie.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 E_=K(new Map),ha=K({});function Om(e){E_.value=new Map((e.nodes??[]).map((t)=>[t.nodeId,t])),ha.value=e.pins??{}}async function Yl(){let e=await re("fetchContextStatus","/api/canvas/ax/context-status",{});if(e.ok&&e.boardId===Pe.value)Om(e)}function I_(e,t){let n=E_.value.get(e),o=ha.value[e]?.pinnedAt;if(!n||o&&n.lastReadAt<o)return{kind:"not-read"};if(t>n.readRevision)return{kind:"changed",by:n.lastReadBy,at:n.lastReadAt};return{kind:"read",by:n.lastReadBy,at:n.lastReadAt,count:n.readCount}}function Ql(e){return e.agentId?.trim()||e.source}var A_="",P_=new Map,R_=Ve(()=>{let e=ze.value,t=new Map;if(e.size>0){let o=new Map;for(let r of ep([...D.value.values()],e)){let s=r.pinnedNodeTitle??r.pinnedNodeId;for(let a of r.neighbors){let c=o.get(a.id)??[];c.push({pinNodeId:r.pinnedNodeId,pinTitle:s,distance:a.distance}),o.set(a.id,c)}}for(let[r,s]of o)s.sort((a,c)=>a.distance-c.distance),t.set(r,s.map(({pinNodeId:a,pinTitle:c})=>({pinNodeId:a,pinTitle:c})))}let n=[...t].sort(([o],[r])=>o.localeCompare(r)).map(([o,r])=>`${o}:${r.map((s)=>`${s.pinNodeId}=${s.pinTitle}`).join(",")}`).join("|");if(n===A_)return P_;return A_=n,P_=t,t});function Qe({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)}var eu={eye:"M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6S2 12 2 12zM12 9.5a2.5 2.5 0 1 0 0 5a2.5 2.5 0 1 0 0-5",eyeOff:"M3 3l18 18M10.6 6.1A10 10 0 0 1 12 6c6.5 0 10 6 10 6a17 17 0 0 1-3 3.6M6.6 6.6C3.8 8.3 2 12 2 12s3.5 6 10 6a9.6 9.6 0 0 0 4.4-1",spark:"M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8z",pen:"M4 20l4.2-1L19 8.2 15.8 5 5 15.8z",warn:"M12 4l9 16H3zM12 10v4M12 17v.5"};function N_(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function kR(e,t){if(t){let n=ha.value[e.id],o=n?.pinnedBy.actor==="agent"?` Pinned by ${Ql(n.pinnedBy)}${n.reason?`: ${n.reason}`:""}.`:"",r=I_(e.id,e.contentRevision??0);if(r.kind==="not-read")return{tone:"muted",glyph:"eyeOff",word:"not read",label:"Not read yet",body:`In context, but no agent has loaded it since it was pinned.${o}`};if(r.kind==="changed")return{tone:"warn",glyph:"warn",word:"changed since read",label:"The agent's copy is out of date",body:`Changed after ${r.by} read it at ${N_(r.at)}.${o}`};return{tone:"agent",glyph:"eye",word:"read",label:"Read by the agent",body:`${r.count>1?`Read ${r.count} times · last`:"Read"} ${N_(r.at)} by ${r.by}.${o}`}}if(e.lastEditedBy?.actor==="human")return null;if(e.createdBy?.actor==="agent"){let n=Ql(e.createdBy);return{tone:"agent",glyph:"spark",word:`by ${n}`,label:`Created by ${n}`,body:"The byline stays until you edit the node."}}if(e.lastEditedBy?.actor==="agent")return{tone:"agent",glyph:"pen",word:"edited",label:`Edited by ${Ql(e.lastEditedBy)}`,body:"The mark stays until you edit the node."};return null}function z_({node:e,pinned:t}){let n=kR(e,t);if(!n)return null;return i(Qe,{label:n.label,body:n.body,align:"end",tapToOpen:!0,children:i("span",{class:`node-context-mark is-${n.tone}`,"data-mark":n.word,children:[i("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:i("path",{d:eu[n.glyph]},void 0,!1,void 0,this)},void 0,!1,void 0,this),n.word]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function M_(e){return ha.value[e]?.pinnedBy.actor==="agent"}function $_({node:e,pinned:t}){let[n,o]=I(!1),r=t?void 0:R_.value.get(e.id);if(!r||r.length===0)return null;let s=r.length>1?`near ${r.length}`:"near",a=n?r.map((c)=>{let l=D.value.get(c.pinNodeId);return l?`“${c.pinTitle}” (${Math.round(Qd(e,l))} px)`:`“${c.pinTitle}”`}).join(", "):"";return i(Qe,{label:n?`Near ${a}`:"Near a pin",body:"The agent gets its title and a short summary, not its full content. Pin it to send its content.",align:"end",tapToOpen:!0,children:i("span",{class:"node-near-mark","data-near":r.map((c)=>c.pinNodeId).join(" "),onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),onFocusIn:()=>o(!0),onFocusOut:()=>o(!1),children:[i("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[i("circle",{cx:"12",cy:"12",r:"8",class:"node-near-ring"},void 0,!1,void 0,this),i("circle",{cx:"12",cy:"12",r:"2.2",class:"node-near-dot"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function TR(e){let t=typeof e==="number"&&Number.isFinite(e)?Math.floor(e):1;return Math.max(1,Math.min(20,t))}function tu(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function ga(e){return typeof e==="string"&&e.length>0}function O_(e){let t=e.axStep;if(!tu(t))return null;if(!ga(t.flowId)||!ga(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 L_(e){let t=e.axFlow;if(!tu(t)||!ga(t.flowId)||!Array.isArray(t.steps))return null;let n=[];for(let r of t.steps){if(!tu(r)||!ga(r.nodeId)||!ga(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=tu(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:TR(o.maxRuns)}}}var CR={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)"},F_={display:"flex",alignItems:"center",gap:"6px",flexWrap:"wrap"},H_={fontSize:"10px",color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginRight:"auto"},B_={...Nr,background:"color-mix(in srgb, var(--c-accent) 25%, transparent)",color:"var(--c-text)"},ER=[{status:"in-progress",label:"Start",toast:"Step started"},{status:"done",label:"Done",toast:"Step done"},{status:"blocked",label:"Blocked",toast:"Step blocked"}];async function D_(e,t,n){let o={...t,loop:n};ve(e.id,{axFlow:o}),await kt(e.id,{data:{axFlow:o}})}function j_(e){return typeof e?.axWorkStatus==="string"?e.axWorkStatus:"todo"}function IR({node:e,flow:t}){let[n,o]=I(""),{running:r,run:s,maxRuns:a}=t.loop,c=async()=>{await D_(e,t,{running:!0,run:s>=a?0:s,maxRuns:a});let u=t.steps.find((d)=>j_(D.value.get(d.nodeId)?.data)!=="done"),p=u??t.steps[t.steps.length-1];await Ko(e,"ax.work.update",{id:p.workItemId,status:u?"in-progress":"done"},"Loop running")},l=async()=>{let u=n.trim();if(!u)return;await Ko(e,"ax.steer",{message:u},"Steering sent"),o("")};return i("div",{class:"ax-flow-controls",style:{...F_,marginTop:"6px",rowGap:"4px"},children:[i("span",{class:"ax-flow-runs",style:H_,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:B_,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(),D_(e,t,{...t.loop,running:!1})},children:"Stop"},void 0,!1,void 0,this):i("button",{type:"button",class:"ax-node-action",style:Nr,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:Nr,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 nu({node:e}){let t=O_(e.data);if(!t)return null;let n=L_(e.data),o=j_(e.data);return i("div",{class:"ax-step-dock",style:CR,children:[i("div",{class:"ax-step-controls",style:F_,children:[i("span",{class:"ax-step-position",style:H_,children:["Step ",t.index,"/",t.total]},void 0,!0,void 0,this),ER.map((r)=>i("button",{type:"button",class:"ax-node-action","aria-pressed":o===r.status,style:o===r.status?B_:Nr,title:`Set this step's work item to "${r.status}".`,onClick:(s)=>{s.stopPropagation(),Ko(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(IR,{node:e,flow:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Ki=8,jr=K(null),Ji=[],Yi=[],W_=null;function U_(e){let t=e?.data.parentGroup;return typeof t==="string"&&t.length>0?t:null}function Z_(e){if(!e||!Array.isArray(e.data.children))return[];return e.data.children.filter((t)=>typeof t==="string")}function AR(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=U_(r);while(s&&!o.has(s))o.add(s),s=U_(n.get(s));if(r.type!=="group")return o;let a=[...Z_(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(...Z_(l))}return o}function q_(e,t){Ji=[],Yi=[],W_=e;let n=Array.from(t),o=AR(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;Ji.push({val:s,minY:l,maxY:u}),Ji.push({val:a,minY:l,maxY:u}),Ji.push({val:c,minY:l,maxY:u}),Yi.push({val:l,minX:s,maxX:a}),Yi.push({val:u,minX:s,maxX:a}),Yi.push({val:p,minX:s,maxX:a})}}function G_(){Ji=[],Yi=[],W_=null}function V_(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=Ki+1,p=null;for(let v=0;v<3;v++){let w=r[v];for(let g of Ji){let x=Math.abs(w-g.val);if(x<u)u=x,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=Ki+1,f=null;for(let v=0;v<3;v++){let w=s[v];for(let g of Yi){let x=Math.abs(w-g.val);if(x<m)m=x,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<=Ki)h.push(p);if(f&&m<=Ki)h.push(f);return{x:l!==null&&u<=Ki?l:e,y:d!==null&&m<=Ki?d:t,guides:h}}function X_({nodeId:e,viewport:t,onMove:n,onDragEnd:o,onClick:r}){let s=L(!1),a=L({x:0,y:0}),c=L({x:0,y:0});return j((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 x=m;m=null;let R=t.value.scale,M=(x.x-a.current.x)/R,O=(x.y-a.current.y)/R;n(e,c.current.x+M,c.current.y+O)},w=(x)=>{if(!s.current)return;if(!h&&Math.hypot(x.clientX-u.clientX,x.clientY-u.clientY)<4)return;if(h=!0,m={x:x.clientX,y:x.clientY},f!==null)return;f=window.requestAnimationFrame(v)},g=(x)=>{if(f!==null)window.cancelAnimationFrame(f),v();if(s.current=!1,document.documentElement.classList.remove("is-node-dragging"),document.removeEventListener("pointermove",w),document.removeEventListener("pointerup",g),document.removeEventListener("pointercancel",g),o(),!h&&x.type==="pointerup")r?.()};document.addEventListener("pointermove",w),document.addEventListener("pointerup",g),document.addEventListener("pointercancel",g)},[e,t,n,o,r])}var PR=200,RR=100;function K_({nodeId:e,viewport:t,onResize:n,onResizeEnd:o}){let r=L(!1),s=L({x:0,y:0}),a=L({w:0,h:0});return j((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 w=d;d=null;let g=t.value.scale,x=(w.x-s.current.x)/g,R=(w.y-s.current.y)/g;n(e,Math.max(PR,a.current.w+x),Math.max(RR,a.current.h+R))},h=(w)=>{if(!r.current)return;if(d={x:w.clientX,y:w.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 NR={ArrowLeft:{dx:-1,dy:0},ArrowRight:{dx:1,dy:0},ArrowUp:{dx:0,dy:-1},ArrowDown:{dx:0,dy:1}};function zR(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 MR=0.4,$R=0.55,OR=175;function LR(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*MR/Di);if(Number.isFinite(n)&&n>0)r=Math.min(r,n*$R/OR);return Math.max(1,r)}function J_({node:e,children:t,onContextMenu:n}){let o=qe.value===e.id,r=Ne.value.has(e.id),s=ze.value.has(e.id),a=Rc.value.has(e.id),c=!o&&sx.value.has(e.id),l=go.value,u=l!==null&&l.has(e.id),p=l!==null&&!l.has(e.id),[d,m]=I(!1),f=L(null),h=j((A,ue,fe)=>{let ge=V_(ue,fe,e.size.width,e.size.height),Vt=D.value.get(A);if(Vt?.position.x===ge.x&&Vt.position.y===ge.y){jr.value=ge.guides.length>0?ge.guides:null;return}wt(A,{position:{x:ge.x,y:ge.y}}),jr.value=ge.guides.length>0?ge.guides:null,dx(A)},[e.size.width,e.size.height]),v=L(null),w=j(()=>{if(G_(),jr.value=null,am(null),v.current)document.removeEventListener("keydown",v.current),v.current=null;Tt();let A=Jn.value;if(ux(),!A||A.nodeId!==e.id)return;if(A.mode==="add")fp(A.groupId,[e.id]);else{let ue=D.value.get(A.groupId),fe=Array.isArray(ue?.data.children)?ue.data.children.filter((ge)=>typeof ge==="string"&&ge!==e.id):[];Gc(A.groupId,fe)}},[e.id]),g=X_({nodeId:e.id,viewport:ie,onMove:h,onDragEnd:w,onClick:()=>{Ne.value=new Set([e.id])}}),x=j((A,ue,fe)=>{let ge=D.value.get(A);if(ge?.size.width===ue&&ge.size.height===fe)return;wt(A,{size:{width:ue,height:fe}})},[]),R=j(()=>{ve(e.id,{userResized:!0}),kt(e.id,{data:{userResized:!0}}),Tt()},[e.id]),M=K_({nodeId:e.id,viewport:ie,onResize:x,onResizeEnd:R}),O=j((A)=>{A.stopPropagation(),A.preventDefault(),Ye.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]),k=j((A)=>{if(A.button!==0)return;if(d)return;if(A.target instanceof Element&&A.target.closest("button, input")){A.stopPropagation();return}if(en.value==="connect"){O(A);return}if(A.shiftKey){A.stopPropagation(),vp(e.id);return}if(yo(e.id),am(e.id),yS(e.id,typeof e.data.title==="string"&&e.data.title?e.data.title:e.type),q_(e.id,D.value.values()),e.type!=="group"){let ue=(fe)=>{if(fe.key==="Escape")lx()};v.current=ue,document.addEventListener("keydown",ue)}g(A,e.position.x,e.position.y)},[e.id,e.type,e.data.title,e.position.x,e.position.y,g,d,O]),N=j((A)=>{if(A.button!==0)return;if(A.stopPropagation(),en.value==="connect"){O(A);return}if(A.shiftKey){vp(e.id);return}yo(e.id)},[e.id,O]),_=j((A)=>{if((A.target instanceof Element?A.target:null)?.closest('button, input, textarea, select, a, [contenteditable="true"]'))return;if(n)n(A,e.id)},[n,e.id]),E=j((A)=>{let ue=A.target;if(ue&&ue!==A.currentTarget&&ue.closest('input, textarea, [contenteditable="true"]'))return;let fe=NR[A.key];if(fe){A.preventDefault();let ge=zR(e,fe,D.value.values());if(!ge)return;yo(ge.id),requestAnimationFrame(()=>{document.querySelector(`.canvas-node[data-node-id="${CSS.escape(ge.id)}"]`)?.focus()})}else if(A.key==="Enter"&&A.target===A.currentTarget&&Ls.has(e.type))A.preventDefault(),En(e.id)},[e]),z=e.data.title||(e.type==="file"?(e.data.path||e.data.content||"").split(/[\\/]/).pop()??"":"")||$t[e.type],X=j((A)=>{let ue=A.trim();if(ue&&ue!==z)ve(e.id,{title:ue}),kt(e.id,{title:ue});m(!1)},[e.id,z]),W=L(null),J=L(!1),G=L(null);B(()=>{if(J.current||!cm(e))return;let A=W.current;if(!A)return;let ue=new ResizeObserver(()=>{if(J.current){ue.disconnect();return}let fe=A.scrollHeight,ge=_S(e,fe);if(ge===null)return;if(Math.abs(ge-e.size.height)>8){if(tl(e.id,{width:e.size.width,height:ge}),G.current!==null)window.clearTimeout(G.current);G.current=window.setTimeout(()=>{Tt({recordHistory:!1}),G.current=null},0)}J.current=!0,ue.disconnect()});return ue.observe(A),()=>{if(ue.disconnect(),G.current!==null)window.clearTimeout(G.current),G.current=null}},[e.id,e.type,e.data.mode,e.data.strictSize,e.collapsed,e.size.width,e.size.height]);let T=e.pinned,q=e.type==="trace",ae=q&&e.data.status==="running",be=e.type==="group",pe=e.data.strictSize===!0,Me=Math.max(ie.value.scale,0.01),Te=LR(Me,e.collapsed?0:e.size.height,e.size.width),De=be&&e.data.color?e.data.color:void 0,cn={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":Te.toFixed(3),"--node-port-scale":(1/Me).toFixed(3),...De?{"--group-color":De}:{}},Rn=St.value&&Gl.value.has(e.id),F=["canvas-node",o?"active":"",c?"neighbor":"",u?"search-match":"",p?"search-dimmed":"",r?"selected":"",s?"context-pinned":"",a?"attention-pulse":"",T?"pinned":"",q?"trace-node":"",ae?"trace-running":"",be?"group-node":"",pe?"strict-size":"",Rn?"agent-mutating":"",ar.value&&!ar.value.has(e.id)?"lens-dimmed":""].filter(Boolean).join(" "),Y=be?(Array.isArray(e.data.children)?e.data.children:[]).filter((A)=>typeof A==="string"&&D.value.has(A)):[],[Ce,me]=I(!1),xe=Jn.value,ce=be&&xe?.groupId===e.id&&xe.mode==="add",se=be&&xe?.groupId===e.id&&xe.mode==="remove",Z=Ye.value?.targetId===e.id,we=be?[...new Set(Y.map((A)=>D.value.get(A)?.type).filter((A)=>!!A))].slice(0,4):[];if(be&&e.collapsed)return i("div",{class:`${F} group-chip`,"data-node-type":e.type,style:{...cn,width:"auto",height:"auto"},onPointerDown:N,onDblClick:_,title:"Expand group","data-testid":"group-chip",children:i("div",{class:"node-titlebar group-chip-inner",onPointerDown:k,children:[i("button",{type:"button",class:"group-chip-expand","aria-label":`Expand group ${z}`,onClick:(A)=>{A.stopPropagation(),Gs(e.id)},children:i(Vs,{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:z},void 0,!1,void 0,this),i("div",{class:"group-chip-meta",children:[we.map((A)=>i("span",{class:"group-kind-dot","aria-hidden":"true"},A,!1,void 0,this)),i("span",{class:"group-chip-count",children:[Y.length," node",Y.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:`${F}${ce?" is-drop-target":""}${se?" is-drop-source":""}${Z?" is-edge-target":""}${be&&Ce?" group-menu-open":""}`,"data-node-type":e.type,"data-node-id":e.id,style:cn,tabIndex:o?0:-1,onKeyDown:E,onPointerDown:N,onMouseDown:(A)=>{if(A.shiftKey)A.preventDefault()},onDblClick:_,children:[i("div",{class:"node-content",children:[be&&i("div",{class:"node-titlebar group-edge-row",onPointerDown:k,children:[i("span",{class:"group-name-pill",children:[d?i("input",{ref:f,class:"node-title-input group-title-input",value:z,onBlur:(A)=>X(A.target.value),onKeyDown:(A)=>{if(A.key==="Enter")X(A.target.value);if(A.key==="Escape")m(!1)},onClick:(A)=>A.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"group-name",title:z,children:z},void 0,!1,void 0,this),i("span",{class:"group-count",children:Y.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":`${z} actions`,children:[i("button",{type:"button",class:"group-action",title:"Auto-arrange children","aria-label":"Auto-arrange children",disabled:Y.length===0,onClick:(A)=>{A.stopPropagation(),fp(e.id,Y,"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:(A)=>{A.stopPropagation(),Gs(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":Ce,onClick:(A)=>{A.stopPropagation(),me((ue)=>!ue)},children:i(Tp,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),Ce&&i("div",{class:"group-menu",role:"menu",onPointerDown:(A)=>A.stopPropagation(),children:[i("button",{type:"button",role:"menuitem",onClick:(A)=>{A.stopPropagation(),me(!1),m(!0),requestAnimationFrame(()=>f.current?.focus())},children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",onClick:(A)=>{A.stopPropagation(),me(!1),Wo(e.id),wi(e.id)},children:"Ungroup"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",disabled:Y.length===0,onClick:(A)=>{A.stopPropagation(),me(!1),Yc(Y)},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),!be&&i("div",{class:"node-titlebar",onPointerDown:k,children:[i("span",{class:"node-type-icon","aria-hidden":"true",children:(()=>{let A=Bn(e.type);return i(A,{size:Math.round(14*Te)},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),d?i("input",{ref:f,class:"node-title-input",value:z,onBlur:(A)=>X(A.target.value),onKeyDown:(A)=>{if(A.key==="Enter")X(A.target.value);if(A.key==="Escape")m(!1)},onClick:(A)=>A.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"node-title",title:z,children:z},void 0,!1,void 0,this),i($_,{node:e,pinned:s},void 0,!1,void 0,this),i(z_,{node:e,pinned:s},void 0,!1,void 0,this),i("div",{class:"node-controls",children:[T&&i("span",{class:"pin-indicator",title:"Pinned",children:"⊙"},void 0,!1,void 0,this),Ls.has(e.type)&&i("button",{type:"button",onClick:(A)=>{A.stopPropagation(),En(e.id)},title:"Expand (focus mode)",children:i(zx,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:`ctx-pin-btn${s?" ctx-pin-active":""}`,onClick:(A)=>{A.stopPropagation(),Qn(e.id)},title:s?"Remove from context":"Add to context","aria-label":s?"Remove from context":"Add to context","aria-pressed":s,children:i("span",{class:"ctx-pin-mark",children:[i(ul,{},void 0,!1,void 0,this),s&&M_(e.id)&&i("span",{class:"ctx-pin-agent-dot","aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"node-hover-control",onClick:(A)=>{A.stopPropagation(),n?.(A,e.id)},title:"More actions","aria-label":"More actions",children:i(Tp,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"node-hover-control",onClick:(A)=>{A.stopPropagation(),Uo(e.id)},title:"Close",children:i(Xe,{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:W,class:"node-body",children:[t,i(nu,{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:(A)=>M(A,e.size.width,e.size.height)},void 0,!1,void 0,this),r&&["tl","tr","bl","br"].map((A)=>i("span",{class:`node-selection-handle is-${A}`,"aria-hidden":"true"},A,!1,void 0,this)),Or.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),Or.value.get(e.id)," took over — agent yielded"]},void 0,!0,void 0,this),!be&&["top","right","bottom","left"].map((A)=>i("div",{class:`node-port node-port-${A}`,onPointerDown:(ue)=>{if(ue.button!==0)return;ue.stopPropagation(),ue.preventDefault(),ue.currentTarget.setPointerCapture(ue.pointerId);let fe=e.position.x+e.size.width/2,ge=e.position.y+e.size.height/2,Vt=e.size.width/2,_t=e.size.height/2,Xt,bn;switch(A){case"top":Xt=fe,bn=ge-_t;break;case"bottom":Xt=fe,bn=ge+_t;break;case"left":Xt=fe-Vt,bn=ge;break;case"right":Xt=fe+Vt,bn=ge;break}Ye.value={fromId:e.id,fromX:Xt,fromY:bn,cursorX:Xt,cursorY:bn}}},A,!1,void 0,this))]},void 0,!0,void 0,this)}function ou({node:e}){let t=typeof e.data.boardId==="string"?e.data.boardId:"",n=Ut.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 sn(n.id),children:[n?"Open board":"Target unavailable",n&&i(Xo,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var DR={relation:"var(--c-muted)","depends-on":"var(--c-rel-informs)",flow:"var(--c-accent)",references:"var(--c-muted)"},FR=new Set(["depends-on","flow"]);function HR(e){if(!Number.isFinite(e)||e<=0)return 1;return e<1?1/e:1}function BR(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 ru(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 iu(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 jR(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 UR({edge:e,fromNode:t,toNode:n,focused:o,dimmed:r,selected:s,scale:a,onContextMenu:c}){let l=ru(t,n),u=ru(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=iu(l,f),v=iu(u,f),w=`M ${l.x} ${l.y} C ${h.x} ${h.y}, ${v.x} ${v.y}, ${u.x} ${u.y}`,g=DR[e.type],x=FR.has(e.type),R=BR(e,a),M=Math.min(a,2.2),O=e.label&&a<=3.4?jR(l.x,l.y,h.x,h.y,v.x,v.y,u.x,u.y):null,k=`edge-path-${e.id}`;return i("g",{children:[i("path",{d:w,fill:"none",stroke:"transparent","stroke-width":12*a,style:{cursor:"pointer",pointerEvents:"stroke"},onClick:(N)=>{N.stopPropagation(),Yn.value=e.id},onDblClick:c?(N)=>c(N,e.id):void 0},void 0,!1,void 0,this),(o||s)&&i("path",{d:w,fill:"none",stroke:g,"stroke-width":6*a,"stroke-dasharray":R,opacity:s?0.3:0.15,style:{filter:"blur(3px)"}},void 0,!1,void 0,this),i("path",{id:k,d:w,class:s?"edge-selected":void 0,fill:"none",stroke:g,"stroke-width":(s?3:o?2.5:1.5)*a,"stroke-dasharray":R,"marker-end":x?"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:`#${k}`},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O&&e.label&&i("g",{transform:`translate(${O.x}, ${O.y})`,children:[i("rect",{class:"edge-label-bg",x:-(e.label.length*3.5+8)*M,y:-10*M,width:(e.label.length*7+16)*M,height:20*M,rx:4*M},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 Y_({nodes:e,edges:t,onEdgeContextMenu:n}){let o=e.value,r=Array.from(t.value.values()),s=qe.value,a=s!==null,c=go.value,l=c!==null,u=HR(ie.value.scale);if(r.length===0&&!Ye.value)return null;let p=96,d=Array.from(o.values());if(d.length===0)return null;let m=Math.min(...d.map((x)=>x.position.x))-p,f=Math.min(...d.map((x)=>x.position.y))-p,h=Math.max(...d.map((x)=>x.position.x+x.size.width))+p,v=Math.max(...d.map((x)=>x.position.y+x.size.height))+p,w=Math.max(1,h-m),g=Math.max(1,v-f);return i("svg",{"aria-label":"Canvas connections",role:"img",viewBox:`${m} ${f} ${w} ${g}`,width:w,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((x)=>{let R=Jc(x.from),M=Jc(x.to);if(!R||!M||R.id===M.id)return null;let O=a&&(x.from===s||x.to===s),k=l&&!(c.has(x.from)||c.has(x.to));return i(UR,{edge:x,fromNode:R,toNode:M,focused:O,dimmed:a&&!O||k,selected:Yn.value===x.id,scale:u,onContextMenu:n},x.id,!1,void 0,this)}),Ye.value&&(()=>{let x=Ye.value,R=Jc(x.fromId),M={position:{x:x.cursorX,y:x.cursorY},size:{width:1,height:1}},O;if(R){let k=ru(R,M),N=ru(M,R),_=N.x-k.x,E=N.y-k.y,z=Math.sqrt(_*_+E*E),X=Math.min(Math.max(z*0.35,32),160),W=iu(k,X),J=iu(N,X);O=`M ${k.x} ${k.y} C ${W.x} ${W.y}, ${J.x} ${J.y}, ${N.x} ${N.y}`}else{let k=x.cursorX-x.fromX,N=x.cursorY-x.fromY,_=Math.sqrt(k*k+N*N),E=Math.min(_*0.25,80),z=k/(_||1),X=N/(_||1);O=`M ${x.fromX} ${x.fromY} C ${x.fromX+z*E} ${x.fromY+X*E}, ${x.cursorX-z*E} ${x.cursorY-X*E}, ${x.cursorX} ${x.cursorY}`}return i("g",{children:[i("path",{d:O,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:O,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:x.cursorX,cy:x.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 ZR(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 Lm({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-ui)","font-weight":"700",opacity:"0.95",children:t.text},t.id,!1,void 0,this)}return i("path",{d:ZR(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 WR(e){switch(e.type){case"markdown":return i(_l,{node:e},void 0,!1,void 0,this);case"mcp-app":return i(tr,{node:e},void 0,!1,void 0,this);case"webpage":return i(Bl,{node:e},void 0,!1,void 0,this);case"json-render":return i(tr,{node:e},void 0,!1,void 0,this);case"graph":return i(tr,{node:e},void 0,!1,void 0,this);case"board":return i(ou,{node:e},void 0,!1,void 0,this);case"prompt":return i(jl,{node:e},void 0,!1,void 0,this);case"response":return i(Ul,{node:e},void 0,!1,void 0,this);case"status":return i(Fl,{node:e},void 0,!1,void 0,this);case"context":return i(pl,{node:e},void 0,!1,void 0,this);case"ledger":return i(gl,{node:e},void 0,!1,void 0,this);case"trace":return i(Zl,{node:e},void 0,!1,void 0,this);case"file":return i(hl,{node:e},void 0,!1,void 0,this);case"diff":return i(ml,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Dl,{node:e},void 0,!1,void 0,this);case"image":return i(Hl,{node:e},void 0,!1,void 0,this);case"html":return i(ua,{node:e},void 0,!1,void 0,this);case"group":return i(VS,{node:e},void 0,!1,void 0,this);default:return i("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function qR(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 GR(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&&qR(t,c,l)<=n+r.width/2)return r}}return null}var Dm="currentColor",Q_=4,ek=24,VR=14,tk={width:520,height:420};function XR(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 Hm(e){let t=e.trim();if(!t)return[];let n=t.includes(`
|
|
7876
|
+
`)?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=XR(a);if(!c||o.has(c))continue;o.add(c),r.push(c)}return r}function KR(e){let t=Hm(e.getData("text/uri-list"));if(t.length>0)return t;return Hm(e.getData("text/plain"))}function JR(e){if(!e)return!1;return e.types.includes("text/uri-list")||e.types.includes("text/plain")}function Fm(e){if(!(e instanceof HTMLElement))return!1;return Boolean(e.closest('input, textarea, select, [contenteditable="true"], [contenteditable=""]'))}function YR(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 nk({onNodeContextMenu:e,onEdgeContextMenu:t,onCanvasContextMenu:n,annotationMode:o=!1,annotationTool:r=null}){let s=ie.value,a=L(!1),c=L(null),l=L(!1),u=L([]),[p,d]=I(null),[m,f]=I(null),[h,v]=I(null),w=L(null),[g,x]=I(!1),R=L(0),M=L(null),O=L(null);B(()=>{let F=null,Y=on(()=>{ie.value;let Ce=O.current;if(!Ce)return;if(Ce.style.willChange="transform",F)clearTimeout(F);F=setTimeout(()=>{Ce.style.willChange="auto"},180)});return()=>{if(F)clearTimeout(F);Y()}},[]);let k=rl({viewport:ie,disabled:o,onViewportChange:(F)=>{if(a.current||o)return;bo(),bx(F)},onViewportCommit:(F)=>{if(a.current||o)return;bo(),wx(F)}}),N=j((F)=>{w.current=F,v(F)},[]),_=j(async(F,Y,Ce)=>{if(F.length===0)return;let{width:me,height:xe}=tk,ce=24,se=Math.ceil(Math.sqrt(F.length)),Z=Math.ceil(F.length/se),we=se*me+Math.max(0,se-1)*ce,A=Z*xe+Math.max(0,Z-1)*ce;for(let ue=0;ue<F.length;ue++){let fe=ue%se,ge=Math.floor(ue/se),Vt=Y-we/2+fe*(me+ce),_t=Ce-A/2+ge*(xe+ce);await Dn({type:"webpage",content:F[ue],x:Vt,y:_t,width:me,height:xe})}},[]),E=j((F)=>{let Y=k.current;if(!Y)return;if(r==="eraser"){if((F.target instanceof Element?F.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;F.preventDefault(),F.stopPropagation();let Z=Y.getBoundingClientRect(),we=ie.value,A={x:(F.clientX-Z.left-we.x)/we.scale,y:(F.clientY-Z.top-we.y)/we.scale},ue=GR(Array.from(_i.value.values()),A,VR/we.scale);if(ue)yx(ue.id);return}if(r==="text"){if((F.target instanceof Element?F.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;F.preventDefault(),F.stopPropagation(),qe.value=null,Wt();let Z=Y.getBoundingClientRect(),we=ie.value;N({x:(F.clientX-Z.left-we.x)/we.scale,y:(F.clientY-Z.top-we.y)/we.scale,value:""});return}if(r==="pen"){if((F.target instanceof Element?F.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;F.preventDefault(),F.stopPropagation(),qe.value=null,Wt(),l.current=!0;let Z=Y.getBoundingClientRect(),we=ie.value,A={x:(F.clientX-Z.left-we.x)/we.scale,y:(F.clientY-Z.top-we.y)/we.scale};u.current=[A],f({id:"draft-annotation",type:"freehand",points:[A],bounds:{x:0,y:0,width:0,height:0},color:Dm,width:Q_,createdAt:""}),Y.setPointerCapture(F.pointerId);return}if(F.target!==Y)return;if(Ti()||F.button===1||F.button===2){if(!F.shiftKey&&!M.current)qe.value=null,Wt();return}F.preventDefault(),F.stopPropagation(),a.current=!0;let Ce=Y.getBoundingClientRect(),me=F.clientX-Ce.left,xe=F.clientY-Ce.top,ce={startX:me,startY:xe,currentX:me,currentY:xe};M.current=ce,d(ce),Y.setPointerCapture(F.pointerId)},[r,k]);B(()=>on(()=>{let F=ie.value,Y=c.current,Ce=k.current;if(!Y||!Ce)return;let me=Ce.getBoundingClientRect();$l({x:(Y.x-me.left-F.x)/F.scale,y:(Y.y-me.top-F.y)/F.scale})}),[]);let z=j((F)=>{{let me=k.current;if(me){c.current={x:F.clientX,y:F.clientY};let xe=me.getBoundingClientRect(),ce=ie.value;$l({x:(F.clientX-xe.left-ce.x)/ce.scale,y:(F.clientY-xe.top-ce.y)/ce.scale})}}if(l.current){let me=k.current;if(!me)return;let xe=me.getBoundingClientRect(),ce=ie.value,se={x:(F.clientX-xe.left-ce.x)/ce.scale,y:(F.clientY-xe.top-ce.y)/ce.scale},Z=u.current.at(-1);if(Z&&Math.hypot(se.x-Z.x,se.y-Z.y)<2)return;u.current=[...u.current,se],f((we)=>we?{...we,points:u.current}:null);return}if(!a.current||!M.current)return;let Y=k.current?.getBoundingClientRect();if(!Y)return;let Ce={...M.current,currentX:F.clientX-Y.left,currentY:F.clientY-Y.top};M.current=Ce,d(Ce)},[k]),X=j((F)=>{if(l.current){l.current=!1;let se=u.current;if(u.current=[],f(null),se.length>=2)wp({points:se,color:Dm,width:Q_});let Z=k.current;if(Z?.hasPointerCapture(F.pointerId))Z.releasePointerCapture(F.pointerId);return}let Y=M.current;if(!a.current||!Y)return;a.current=!1,M.current=null;let Ce=Math.min(Y.startX,Y.currentX),me=Math.max(Y.startX,Y.currentX),xe=Math.min(Y.startY,Y.currentY),ce=Math.max(Y.startY,Y.currentY);if(me-Ce<=5&&ce-xe<=5)qe.value=null,Wt();if(me-Ce>5||ce-xe>5){let se=ie.value,Z=(Ce-se.x)/se.scale,we=(me-se.x)/se.scale,A=(xe-se.y)/se.scale,ue=(ce-se.y)/se.scale,fe=[];for(let ge of D.value.values()){let Vt=ge.position.x,_t=ge.position.y;if(Vt+ge.size.width>Z&&Vt<we&&_t+ge.size.height>A&&_t<ue)fe.push(ge.id)}if(fe.length>0)ax(fe)}d(null)},[]);B(()=>{if(o)return;if(!l.current&&!m&&!h)return;l.current=!1,u.current=[],f(null),N(null)},[o,m,N,h]);let W=j(()=>{let F=w.current;if(!F)return;let Y=F.value.trim();if(N(null),!Y)return;let Ce={x:F.x,y:F.y};wp({type:"text",points:[Ce],color:Dm,width:ek,text:Y})},[N]);B(()=>{if(r!=="text"&&h)N(null)},[r,N,h]),B(()=>{let F=(ce,se,Z)=>{let we=null;for(let A of D.value.values()){if(A.id===Z||A.type==="group")continue;if(ce>=A.position.x&&ce<=A.position.x+A.size.width&&se>=A.position.y&&se<=A.position.y+A.size.height)we=A.id}return we};function Y(ce){if(!Ye.value)return;let se=k.current;if(!se)return;let Z=se.getBoundingClientRect(),we=ie.value,A=(ce.clientX-Z.left-we.x)/we.scale,ue=(ce.clientY-Z.top-we.y)/we.scale;Ye.value={...Ye.value,cursorX:A,cursorY:ue,targetId:F(A,ue,Ye.value.fromId)}}function Ce(){let ce=Ye.value;if(!ce)return;Ye.value=null;let se=ce.targetId;if(!se)return;if(ce.withLabel){vn("Edge label","label text").then((Z)=>{Er(ce.fromId,se,"relation",Z??void 0)});return}Er(ce.fromId,se,"relation",void 0)}function me(ce){let se=Ye.value;if(!se)return;if(ce.key==="Escape")ce.preventDefault(),Ye.value=null;else if(ce.key==="l"||ce.key==="L")ce.preventDefault(),Ye.value={...se,withLabel:!se.withLabel}}function xe(){Ye.value=null}return document.addEventListener("pointermove",Y),document.addEventListener("pointerup",Ce),document.addEventListener("pointercancel",xe),document.addEventListener("keydown",me),()=>{document.removeEventListener("pointermove",Y),document.removeEventListener("pointerup",Ce),document.removeEventListener("pointercancel",xe),document.removeEventListener("keydown",me)}},[k]);let J=j((F)=>{if(o)return;let Y=k.current;if(!Y||F.target!==Y||!n)return;let Ce=Y.getBoundingClientRect(),me=ie.value,xe=(F.clientX-Ce.left-me.x)/me.scale,ce=(F.clientY-Ce.top-me.y)/me.scale;n(F,xe,ce)},[o,k,n]),G=j((F)=>{F.preventDefault()},[]),T=j((F)=>{if(Fm(F.target instanceof Element?F.target:null))return;F.preventDefault()},[]),q=j((F)=>{if(F.preventDefault(),R.current++,F.dataTransfer?.types.includes("Files")||JR(F.dataTransfer))x(!0)},[]),ae=j((F)=>{if(F.preventDefault(),F.dataTransfer)F.dataTransfer.dropEffect="copy"},[]),be=j((F)=>{if(F.preventDefault(),R.current--,R.current<=0)R.current=0,x(!1)},[]),pe=j(async(F)=>{F.preventDefault(),x(!1),R.current=0;let Y=k.current;if(!Y||!F.dataTransfer)return;let Ce=Y.getBoundingClientRect(),me=ie.value,xe=(F.clientX-Ce.left-me.x)/me.scale,ce=(F.clientY-Ce.top-me.y)/me.scale,se=Array.from(F.dataTransfer.files);if(se.length===0){let Z=KR(F.dataTransfer);await _(Z,xe,ce);return}await qi(se,xe,ce)},[k,_]);B(()=>{let F=async(Y)=>{if(Y.defaultPrevented)return;if(Fm(Y.target instanceof Element?Y.target:null))return;if(Fm(document.activeElement))return;let Ce=Y.clipboardData?.getData("text/plain")??"",me=Hm(Ce);if(me.length===0)return;let xe=k.current;if(!xe)return;Y.preventDefault();let ce=xe.getBoundingClientRect(),se=ie.value,Z=(ce.width/2-se.x)/se.scale,we=(ce.height/2-se.y)/se.scale;await _(me,Z,we)};return document.addEventListener("paste",F),()=>{document.removeEventListener("paste",F)}},[k,_]);let Me=YR(D.value.values(),ot.value,new Set(yp.value.keys())),Te=Jn.value,De=Te?D.value.get(Te.groupId):void 0,cn=Te?D.value.get(Te.nodeId):void 0,Rn=null;if(p){let F=Math.min(p.startX,p.currentX),Y=Math.min(p.startY,p.currentY),Ce=Math.abs(p.currentX-p.startX),me=Math.abs(p.currentY-p.startY);Rn={position:"absolute",left:`${F}px`,top:`${Y}px`,width:`${Ce}px`,height:`${me}px`,pointerEvents:"none"}}return i("div",{class:`canvas-viewport${Ti()?" pan-mode":""}`,ref:k,tabIndex:0,onPointerDown:E,onPointerMove:z,onPointerLeave:()=>{c.current=null,$l(null)},onPointerUp:X,onContextMenu:G,onDblClick:J,onDragStart:T,onDragEnter:q,onDragOver:ae,onDragLeave:be,onDrop:pe,style:{width:"100%",height:"100%",position:"relative",overflow:"hidden",cursor:r==="eraser"?"cell":r==="text"?"text":o||Ye.value||a.current||en.value==="connect"?"crosshair":Ti()?"grab":"default"},children:[i("div",{ref:O,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(C_,{},void 0,!1,void 0,this),i(s_,{},void 0,!1,void 0,this),i(m_,{},void 0,!1,void 0,this),i(f_,{},void 0,!1,void 0,this),i(Y_,{nodes:D,edges:Je,onEdgeContextMenu:t},void 0,!1,void 0,this),Ye.value&&i("div",{class:"edge-hint-pill","data-testid":"edge-hint",style:{left:`${Ye.value.cursorX+14}px`,top:`${Ye.value.cursorY+14}px`},children:[i("span",{class:"edge-hint-main",children:Ye.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",Ye.value.withLabel?" · label on":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Te&&De&&cn&&i("div",{class:"drop-pill","data-testid":"drop-pill",style:{left:`${cn.position.x}px`,top:`${cn.position.y+cn.size.height+10}px`},children:[i("span",{class:"drop-pill-text",children:Te.mode==="add"?`release to add to ${String(De.data.title??"group")}`:`release to remove from ${String(De.data.title??"group")}`},void 0,!1,void 0,this),i("span",{class:"drop-pill-hint",children:Te.mode==="add"?"esc keeps it out":"esc keeps it in"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Lm,{annotations:Array.from(_i.value.values())},void 0,!1,void 0,this),m&&m.points.length>=2&&i(Lm,{annotations:[m]},void 0,!1,void 0,this),Me.map((F)=>i(J_,{node:F,onContextMenu:e,children:WR(F)},F.id,!1,void 0,this)),jr.value&&i("svg",{class:"snap-guides-svg",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:jr.value.map((F,Y)=>F.axis==="x"?i("line",{x1:F.pos,y1:F.from-20,x2:F.pos,y2:F.to+20,class:"snap-guide-line"},Y,!1,void 0,this):i("line",{x1:F.from-20,y1:F.pos,x2:F.to+20,y2:F.pos,class:"snap-guide-line"},Y,!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:`${ek*s.scale}px`},onInput:(F)=>N({...h,value:F.target.value}),onBlur:W,onPointerDown:(F)=>F.stopPropagation(),onKeyDown:(F)=>{if(F.key==="Enter")F.preventDefault(),W();if(F.key==="Escape")F.preventDefault(),N(null)}},void 0,!1,void 0,this),Rn&&i("div",{class:"lasso-rect",style:Rn},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 su({label:e,value:t,options:n,onChange:o,className:r="",above:s=!1}){let[a,c]=I(!1),l=L(null),u=L(null),p=L(null),d=()=>{c(!1),u.current?.focus()};return Cn(()=>{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((w)=>w===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(sl,{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 ok(){let e=[...ze.value],t=D.value,[n,o]=I(""),[r,s]=I(!1),a=d_.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 k_(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),w=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:w,children:w},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-chip-unpin","aria-label":`Unpin ${w}`,title:"Remove from context",onClick:()=>Qn(h),children:i(Xe,{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(Ai,{size:15,class:"command-bar-icon"},void 0,!1,void 0,this),u&&i(su,{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`:"",w=h.polling?" · polling":"";return{value:h.value,disabled:!h.steerable,label:h.attached?`${h.label}${w}${v}`:h.steerable?`${h.label} · writer${w}${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 ${rt("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 Bm=Ve(()=>{if(hn.value==="disconnected")return"reconnecting";if(hn.value==="connected"&&!Qt.value&&Ar.value>1)return"resyncing";return null});function rk(){let e=Bm.value;if(!e)return null;if(e==="reconnecting"){let t=Pr.value,n=Rr.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 QR={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 Pn(e){if(e.x!==void 0&&e.y!==void 0)return Dn(e);let t=QR[e.type]??{width:360,height:200},n=e.width??t.width,o=e.height??t.height,r=Bo(),s=ie.value,a=await Dn({...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)pt(a.id);return a}var au=!1,ik=!1,Ur=null,Qi=null;function jm(){return au}function cu(){au=!1,ik=!0,sk()}function sk(){if(Ur&&Qi)Ur.removeEventListener("change",Qi);Ur=null,Qi=null}function eN(){if(typeof window>"u"||!window.location)return null;let e=new URLSearchParams(window.location.search).get("theme");if(e==="auto")return"auto";return aa(e)?e:null}function ak(e){if(ik)return;let t=eN();if(!t)return;if(sk(),au=!0,t!=="auto"){e(t);return}Ur=window.matchMedia("(prefers-color-scheme: light)"),Qi=()=>{if(au&&Ur)e(Ur.matches?"daylight":"harbor")},Qi(),Ur.addEventListener("change",Qi)}var tN='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function an(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(tN)),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 nN(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 oN(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 Um={md:"markdown",app:"mcp-app",web:"webpage",ui:"json-render",chart:"graph",ctx:"context",log:"ledger"};function rN(e){let t=e.toLowerCase().trim();if(t.startsWith("type:")){let n=t.slice(5).trim(),r=Object.keys($t).find((a)=>a.startsWith(n));if(r)return{typeFilter:r,remaining:""};let s=Um[n];if(s)return{typeFilter:s,remaining:""}}if(Um[t])return{typeFilter:Um[t],remaining:""};return{typeFilter:null,remaining:e}}function ck({onClose:e,onToggleMinimap:t}){let[n,o]=I(""),[r,s]=I(0),[a,c]=I([]),[l,u]=I("idle"),p=L(null),d=L(null),m=L(null);an(m,!0,{initial:p}),B(()=>{setTimeout(()=>p.current?.focus(),30)},[]),B(()=>{let k=n.trim();if(k.length<2){c([]),u("idle");return}let N=!0;u("loading");let _=window.setTimeout(()=>void re("paletteLibrarySearch",`/api/canvas/search?q=${encodeURIComponent(k)}&scope=library&limit=12`,null).then((E)=>{if(!N)return;if(!E){c([]),u("error");return}c(E.results??[]),u("idle")}),150);return()=>{N=!1,window.clearTimeout(_)}},[n]);let f=j(()=>{let k=[];for(let _ of D.value.values()){let E=_.data.title||$t[_.type],z=_.data.content||_.data.path||"",X=_.type==="group"&&Array.isArray(_.data.children)?_.data.children.length:0;k.push({id:`node:${_.id}`,kind:"node",label:E,description:_.type==="group"?`group · ${X} node${X===1?"":"s"}`:z.length>60?`${$t[_.type].toLowerCase()} · ${z.slice(0,60)}…`:z?`${$t[_.type].toLowerCase()} · ${z}`:$t[_.type].toLowerCase(),icon:Bn(_.type),nodeType:_.type,action:()=>{pt(_.id),e()}})}let N=[{label:"New markdown note",shortcut:"M",icon:Vo,iconTone:"accent",action:()=>{Pn({type:"markdown",title:"New note",width:520,height:360}),e()}},{label:"Link to board…",icon:Bn("board"),iconTone:"accent",action:()=>{window.dispatchEvent(new CustomEvent("pmx-open-board-link")),e()}},...St.value?[]:[{label:"Start agent session",icon:Ai,iconTone:"purple",action:()=>{sr(),e()}}],{label:"Fit view",shortcut:"F",icon:al,iconTone:"muted",action:()=>{Ei(bt().width,bt().height),e()}},{label:"Auto-arrange (grid)",icon:wo,iconTone:"muted",action:()=>{nl(),e()}},{label:"Auto-arrange (graph-aware)",icon:wo,iconTone:"muted",action:()=>{ol(),e()}},{label:"Toggle minimap",icon:cl,iconTone:"muted",action:()=>{t(),e()}},{label:"Toggle theme (Harbor/Daylight)",icon:ll,iconTone:"muted",action:()=>{let _=er(gt.value)==="dark"?"daylight":"harbor";cu(),document.documentElement.setAttribute("data-theme",_),Zi(),gt.value=_,Uc(_),e()}}];for(let _ of N)k.push({id:`action:${_.label}`,kind:"action",label:_.label,..._.shortcut?{shortcut:_.shortcut}:{},icon:_.icon,..._.iconTone?{iconTone:_.iconTone}:{},action:_.action});return k},[e,t]),{typeFilter:h,remaining:v}=rN(n),w=f(),g;if(!n.trim())g=w.map((k)=>({...k,score:0,indices:[]}));else{g=[];for(let k of w){if(h){if(k.kind!=="node"||k.nodeType!==h)continue;if(!v){g.push({...k,score:0,indices:[]});continue}}let N=nN(v||n,k.label);if(N.match)g.push({...k,score:N.score,indices:N.indices})}g.sort((k,N)=>N.score-k.score)}for(let k of a)g.push({id:`library:${k.boardId}:${k.cardId}`,kind:"library",label:k.title||k.boardTitle,description:`${k.boardTitle} · ${k.snippet}`,icon:Bn("board"),score:0,indices:[],action:()=>{(async()=>{if(await sn(k.boardId),Pe.value!==k.boardId)return;for(let N=0;N<40&&Pe.value===k.boardId;N++){if(D.value.has(k.cardId)){pt(k.cardId),e();return}await new Promise((_)=>window.setTimeout(_,25))}})()}});g=[...g.filter((k)=>k.kind==="action"),...g.filter((k)=>k.kind==="node"),...g.filter((k)=>k.kind==="library")];let x=g.findIndex((k)=>k.kind==="node"),R=g.findIndex((k)=>k.kind==="library");B(()=>{if(!n.trim()){go.value=null;return}let k=new Set;for(let N of g)if(N.kind==="node")k.add(N.id.slice(5));go.value=k.size>0?k:null},[n,g]),B(()=>()=>{go.value=null},[]);let M=Math.min(r,Math.max(0,g.length-1)),O=j((k)=>{if(k.key==="ArrowDown")k.preventDefault(),s((N)=>Math.min(N+1,g.length-1));else if(k.key==="ArrowUp")k.preventDefault(),s((N)=>Math.max(N-1,0));else if(k.key==="Enter"){if(k.preventDefault(),g[M])g[M].action()}else if(k.key==="Escape")k.preventDefault(),k.stopPropagation(),e()},[g,M,e]);return B(()=>{let k=d.current;if(!k)return;k.children[M]?.scrollIntoView({block:"nearest"})},[M]),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:(k)=>k.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:(k)=>o(k.target.value),onKeyDown:O,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((k,N)=>{let _=k.icon,E=N===0&&k.kind==="action"?"Actions":N===x?"Jump to":N===R?"Across boards":null;return i("div",{class:"command-palette-row",children:[E&&i("div",{class:"command-palette-group",children:E},void 0,!1,void 0,this),i("button",{type:"button",class:`command-palette-item${N===M?" selected":""}`,onMouseEnter:()=>s(N),onClick:()=>k.action(),children:[i("span",{class:`command-palette-icon tone-${k.iconTone??"kind"}`,"aria-hidden":"true",children:i(_,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"command-palette-label",children:[k.indices.length>0?oN(k.label,k.indices):k.label,k.description&&i("span",{class:"command-palette-desc",children:[" — ",k.description]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),k.shortcut&&i("kbd",{class:"command-palette-kbd",children:k.shortcut},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},k.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:rt("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 lk({onClose:e}){let t=L(null),n=L(null),[o,r]=I(""),[s,a]=I("");an(t,!0,{initial:n});let c=Ut.value.filter((u)=>u.id!==Pe.value&&u.name.toLowerCase().includes(o.trim().toLowerCase())),l=async(u)=>{let p=Ut.value.find((h)=>h.id===u);if(!p)return a("That board is no longer available.");let d=Bo(),m=ie.value;if(!(await re("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:Ut.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 uk(){let[e,t]=I(null),n=j((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"node",x:a.clientX,y:a.clientY,nodeId:c})},[]),o=j((a,c,l)=>{a.preventDefault(),a.stopPropagation(),t({kind:"canvas",x:a.clientX,y:a.clientY,canvasX:c,canvasY:l})},[]),r=j((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"edge",x:a.clientX,y:a.clientY,edgeId:c})},[]),s=j(()=>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 iN="#4bbcFF",sN=[{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 dk({menu:e,onClose:t}){let n;if(e.kind==="node"){let c=D.value.get(e.nodeId);if(!c)return null;n=pN(c)}else if(e.kind==="edge"){let c=e.edgeId,l=Je.value.get(c);n=[{label:l?.label?`Edit label “${l.label.slice(0,18)}${l.label.length>18?"…":""}”`:"Add label…",action:()=>{vn("Edge label (empty clears it)","label text",{initial:l?.label??"",allowEmpty:!0,confirm:"Save"}).then((u)=>{if(u===null)return;Vc(c,{label:u})})}},{separator:!0},...["flow","depends-on","relation","references"].map((u)=>({label:`${l?.type===u?"✓":" "} ${u}`,action:()=>void Vc(c,{type:u})})),{separator:!0},...["solid","dashed","dotted"].map((u)=>({label:`${(l?.style??"solid")===u?"✓":" "} ${u}`,action:()=>void Vc(c,{style:u})})),{separator:!0},{label:"Delete edge",danger:!0,action:()=>void Xc(c)}]}else n=dN(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 aN(e){return(typeof e.data.path==="string"?e.data.path.trim():"")||null}function lu(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 pk(e){if(typeof e.data.color!=="string"||!e.data.color.trim())return null;return lu(e.data.color)}function cN(e){let t=pk(e);return t&&/^#[0-9a-f]{6}$/.test(t)?t:lu(iN)}function Zm(e,t){let n=t?lu(t):null;wt(e.id,{data:{...e.data,color:n}}),kt(e.id,{data:{color:n}})}function lN(e,t){let n=pk(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:()=>{Zm(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:sN.map((o)=>{let r=lu(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:()=>{Zm(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:cN(e),onClick:(o)=>o.stopPropagation(),onInput:(o)=>{Zm(e,o.currentTarget.value),t()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function qm(e,t,n,o){return{x:e-n/2,y:t-o/2}}function uN(e,t){return e.trim().replace(/[?#].*$/,"").split("/").filter(Boolean).at(-1)||t}async function Wm(e){let t=await vn(e.promptLabel,e.placeholder??"");if(!t)return;let n=t.trim();if(!n)return;let o=qm(e.canvasX,e.canvasY,e.width,e.height);if(!(await Dn({type:e.type,...e.type!=="webpage"?{title:uN(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 dN(e,t){return[{label:"New note",action:()=>{let r=qm(e,t,520,360);Dn({type:"markdown",title:"New note",x:r.x,y:r.y,width:520,height:360})}},{label:"Open webpage...",action:()=>{Wm({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:()=>{Wm({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:()=>{Wm({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=qm(e,t,600,400);xi({title:"Group",x:r.x,y:r.y,width:600,height:400})}}]}function pN(e){let t=[],n=aN(e);if(t.push({label:"Focus",action:()=>pt(e.id)}),t.push({label:"Rename…",action:()=>{vn("Rename node","Node title",{initial:typeof e.data.title==="string"?e.data.title:"",confirm:"Save"}).then((l)=>{if(!l?.trim())return;kt(e.id,{title:l.trim()})})}}),Ls.has(e.type))t.push({label:"Expand",shortcut:"⤢",action:()=>En(e.id)});if(t.push({label:e.collapsed?"Expand":"Collapse",action:()=>Gs(e.id)}),El(e))t.push({label:"Open in new tab",action:()=>void Il(e)});let o=ze.value.has(e.id);t.push({label:o?"Unpin from context":"Pin as context",action:()=>Qn(e.id)}),t.push({label:e.pinned?"Unlock position":"Lock position (no auto-arrange)",action:()=>{let l=!e.pinned;wt(e.id,{pinned:l}),kt(e.id,{pinned:l}),Tt()}});let r=Ws.value;if(r&&r.from!==e.id){let l=D.value.get(r.from),u=l?(l.data.title||l.id).slice(0,20):r.from;t.push({label:`Connect from "${u}"`,action:()=>{Er(r.from,e.id,"relation"),Ws.value=null}})}t.push({label:r?"Connect from here (replace)":"Connect from here",action:()=>{Ws.value={from:e.id}}});let s=Array.from(Je.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:()=>Hb("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:()=>{Wc(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)=>lN(e,u)}),l.length>0)t.push({label:`Ungroup (${l.length} node${l.length!==1?"s":""})`,action:()=>{Wo(e.id),wi(e.id)}})}let a=typeof e.data.parentGroup==="string"?e.data.parentGroup:null,c=a?D.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:()=>{Gc(c.id,u)}})}return t.push({separator:!0}),t.push({label:e.type==="group"?"Delete frame (children stay)":"Delete",danger:!0,action:()=>{Uo(e.id)}}),t}function mk(){let e=ze.value.size;if(e===0||Vn.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:hx,title:"Clear all context pins","aria-label":"Clear all context pins",children:i(Xe,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function fk({onClose:e}){let t=L(null),[n,o]=I("Bug report"),[r,s]=I(""),[a,c]=I("");return an(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(su,{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}
|
|
7876
7877
|
|
|
7877
|
-
${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(Xo,{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 va(e,t){console.error(`[tool-rail] ${e} failed`,t)}function Zr(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"}};vn(t[e].message,t[e].placeholder).then((n)=>{if(!n)return;Pn({type:e,content:n}).catch((o)=>va(`create ${e}`,o))})}function yt({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(_e,{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 hk({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:r,onOpenPalette:s,onOpenShortcuts:a,annotationTool:c,onSetAnnotationTool:l}){let u=en.value,p=ki.value,d=Array.from(D.value.values()).filter((z)=>z.type==="trace").length,m=Je.value.size,[f,h]=I(!1),[v,w]=I(null),[g,x]=I(null),R=L(null),M=L(null),O=(z)=>(X)=>{if(v===z){w(null);return}let W=X.currentTarget.getBoundingClientRect();x({bottom:W.bottom,right:W.right}),w(z)},k=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 z=(W)=>{if(R.current&&W.target instanceof Node&&!R.current.contains(W.target))w(null)},X=(W)=>{if(W.key==="Escape")w(null)};return document.addEventListener("pointerdown",z),document.addEventListener("keydown",X),()=>{document.removeEventListener("pointerdown",z),document.removeEventListener("keydown",X)}},[v]);let N=(z)=>{cu(),document.documentElement.setAttribute("data-theme",z),Zi(),gt.value=z,Uc(z),w(null)},_=dm(gt.value),E=(z,X={})=>{ct(`/api/workbench/intent?_ts=${Date.now()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:z,payload:X})}).catch((W)=>va("sendIntent",W))};return i(_e,{children:[i("div",{class:"tool-rail",ref:R,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[i(yt,{label:"Home",ariaLabel:"PMX Canvas — Home",onClick:()=>{w(null),sn(null).catch((z)=>va("openHome",z))},children:i("span",{class:"rail-brand",children:i(dl,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Bug and feedback",menuOpen:f,onClick:()=>{w(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(yt,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>en.value="select",children:i(Gx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>en.value="pan",children:i(Vx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>en.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(yt,{label:"Markdown note",shortcut:"M",onClick:()=>void Pn({type:"markdown",title:"New note",width:520,height:360}).catch((z)=>va("create markdown",z)),children:i(Vo,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{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:()=>M.current?.click(),children:i($x,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("input",{ref:M,type:"file",hidden:!0,multiple:!0,"aria-label":"Attach files",onChange:(z)=>{let X=bt(),W=ie.value;qi(Array.from(z.currentTarget.files??[]),(X.width/2-W.x)/W.scale,(X.height/2-W.y)/W.scale),z.currentTarget.value=""}},void 0,!1,void 0,this),i(yt,{label:"Webpage",shortcut:"W",onClick:()=>Zr("webpage"),children:i(Ii,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Group",shortcut:"G",onClick:()=>void Pn({type:"group",title:"Group"}).catch((z)=>va("create group",z)),children:i(Ep,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Draw",shortcut:"A",active:c==="pen",onClick:()=>l(c==="pen"?null:"pen"),children:i(Fx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Text note",active:c==="text",onClick:()=>l(c==="text"?null:"text"),children:i(Bx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Eraser",active:c==="eraser",onClick:()=>l(c==="eraser"?null:"eraser"),children:i(Hx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-spacer"},void 0,!1,void 0,this),i(yt,{label:"Search & commands",shortcut:rt("K"),onClick:s,children:i(Wx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Arrange",detail:m>0?"graph-aware":"grid",onClick:()=>m>0?ol():nl(),children:i(wo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),!ke()&&i(yt,{label:p?"Disable trace":"Enable trace",active:p,onClick:()=>E("trace-toggle",{enabled:!p}),children:i(Ux,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),!ke()&&(p||d>0)&&i(yt,{label:"Clear trace",onClick:()=>E("trace-clear"),children:i(Zx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:e?"Hide minimap":"Show minimap",active:e,onClick:t,children:i(cl,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Snapshots",active:n,onClick:o,btnRef:r,children:i(jx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"toolbar-menu-anchor",children:[i(yt,{label:"Theme",detail:Bi[_].label,menuOpen:v==="theme",ariaLabel:"Choose theme",active:v==="theme",onClick:O("theme"),children:er(_)==="dark"?i(Dx,{},void 0,!1,void 0,this):i(ll,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v==="theme"&&i("div",{class:"toolbar-menu",style:k,role:"menu","aria-label":"Theme",children:um.map((z)=>i("button",{type:"button",role:"menuitemradio","aria-checked":_===z,class:`toolbar-menu-item${_===z?" active":""}`,onClick:()=>N(z),children:[i("span",{class:"theme-swatch",style:{background:Bi[z].swatchBg},children:i("span",{class:"theme-swatch-dot",style:{background:Bi[z].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{children:Bi[z].label},void 0,!1,void 0,this),_===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(yt,{label:"Shortcuts",shortcut:"?",onClick:a,children:i(qx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f&&i(fk,{onClose:()=>h(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function gk({onOpenPalette:e}){let t=L(null),n=()=>{Pn({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(r)=>{if(!r||r.length===0)return;let s=Bo(),a=ie.value;await qi(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(Vo,{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:()=>Zr("webpage"),children:[i(Ii,{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:rt("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 sr(),children:[i(Ai,{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 · ",rt("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 vk="From old snapshots";function yk(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 Gm(e){return e.split("/").map((t,n,o)=>o.slice(0,n+1).join("/"))}function bk({board:e,folders:t,onClose:n}){let o=L(null),[r,s]=I(e.category??""),[a,c]=I(""),[l,u]=I(!1),[p,d]=I("");an(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=yk(m)}catch(v){d(v instanceof Error?v.message:String(v));return}if(u(!0),d(""),await Fc(e.id,{category:h}),Ut.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 xk({board:e,onClose:t}){let n=L(null),o=L(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),[w,g]=I(""),[x,R]=I(!1);return an(n,!0,{initial:o}),B(()=>{let O=!0;return Ob(e.id).then((k)=>{if(!O)return;if(!k||!Array.isArray(k.cards))return g("Could not load reusable cards. Try again.");s(k),c(new Set(k.cards.filter((N)=>N.reusable).map((N)=>N.id)))}),()=>{O=!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:(O)=>O.stopPropagation(),children:i("form",{onSubmit:async(O)=>{if(O.preventDefault(),!l.trim()||!r)return;R(!0),g("");let k=await Lb({sourceBoardId:e.id,name:l.trim(),...e.category?{category:e.category}:{},nodeIds:[...a],includeReadme:p,includeStructure:m});if(R(!1),!k)return g("Could not create the board. Try a different name.");if(h)await sn(k.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:(O)=>u(O.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!r&&!w&&i("div",{class:"board-copy-status",role:"status",children:"Loading reusable cards…"},void 0,!1,void 0,this),w&&i("div",{class:"board-copy-error",role:"alert",children:w},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((O)=>O.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((O)=>O.reusable).map((O)=>i("label",{class:"board-copy-card",children:[i("input",{type:"checkbox",checked:a.has(O.id),onChange:(k)=>{let N=new Set(a);k.currentTarget.checked?N.add(O.id):N.delete(O.id),c(N)}},void 0,!1,void 0,this),i("span",{children:[i("strong",{children:O.title||"Untitled card"},void 0,!1,void 0,this),i("small",{children:O.type},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},O.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:(O)=>f(O.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:(O)=>d(O.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:(O)=>v(O.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()||x,children:x?"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 pN(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 wk(e){return`${e} node${e!==1?"s":""}`}async function Vm(){let e=await vn("New board","Board name",{confirm:"Create"});if(e)await $b(e)}var Sk="pmx-canvas-home-collapsed";function mN(){try{let e=localStorage.getItem(Sk);if(e)return new Set(JSON.parse(e))}catch{}return new Set([vk])}function fN(e){try{localStorage.setItem(Sk,JSON.stringify([...e]))}catch{}}function _k(){let e=Ut.value,[t,n]=I(null),[o,r]=I(null),[s,a]=I(null),[c,l]=I(""),[u,p]=I([]),[d,m]=I(mN),f=L(0),h=[...new Set(e.flatMap((E)=>E.category?Gm(E.category):[]))].sort((E,z)=>E.localeCompare(z)),v=c.trim().toLocaleLowerCase(),w=e.filter((E)=>`${E.name} ${E.category??""}`.toLocaleLowerCase().includes(v)),g=new Set(w.flatMap((E)=>E.category?Gm(E.category):[])),x=e.find((E)=>E.id===o),R=e.find((E)=>E.id===s);B(()=>{let E=c.trim();if(!E){p([]);return}let z=!1,X=window.setTimeout(()=>{re("searchLibrary",`/api/canvas/search?q=${encodeURIComponent(E)}&scope=library&limit=30`,null).then((W)=>{if(!z)p(W?.results??[])})},150);return()=>{z=!0,window.clearTimeout(X)}},[c]);let M=async(E)=>{let z=++f.current;await sn(E.boardId);for(let X=0;X<40;X++){if(z!==f.current||Pe.value!==E.boardId)return;if(D.value.has(E.cardId)){pt(E.cardId);return}await new Promise((W)=>window.setTimeout(W,25))}},O=(E)=>{let z=new Set(d);if(z.has(E))z.delete(E);else z.add(E);m(z),fN(z)},k=async(E)=>{let z=await vn("Rename board","Board name",{initial:E.name,confirm:"Rename"});if(z&&z!==E.name)await Fc(E.id,{name:z})},N=(E)=>t===E.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:E.name},void 0,!1,void 0,this)," and its ",wk(E.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),Fb(E.id)},children:"Delete board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},E.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 sn(E.id),children:[i("span",{class:"home-board-name",children:E.name},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[wk(E.nodeCount)," · ",pN(E.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(E.id),children:"Move"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action","aria-haspopup":"dialog",onClick:()=>a(E.id),children:"Create from…"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>void k(E),children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>n(E.id),children:"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},E.id,!0,void 0,this),_=(E,z)=>{let X=h.filter((T)=>T.slice(0,T.lastIndexOf("/"))===E&&T.includes("/")),W=w.filter((T)=>T.category===E),J=w.filter((T)=>T.category===E||T.category?.startsWith(`${E}/`)).length,G=!!v||!d.has(E);return i("section",{class:"home-section","data-testid":"home-section","data-folder":E,"aria-label":E,children:[i("button",{type:"button",class:"home-section-head","aria-expanded":G,onClick:()=>O(E),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:E.split("/").at(-1)},void 0,!1,void 0,this),i("span",{class:"home-section-count",children:J},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G&&i("div",{class:"home-folder-children",style:{marginLeft:z<5?"14px":"0"},children:[X.filter((T)=>g.has(T)).map((T)=>_(T,z+1)),W.length>0&&i("ul",{class:"home-view-list","aria-label":`Boards in ${E}`,children:W.map(N)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},E,!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 Vm(),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:(E)=>l(E.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((E)=>i("li",{class:"home-board",children:i("button",{type:"button",class:"home-board-open",onClick:()=>void M(E),children:[i("span",{class:"home-board-name",children:E.title||E.boardTitle},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[E.boardTitle," · ",E.snippet]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},`${E.boardId}:${E.cardId}`,!1,void 0,this))},void 0,!1,void 0,this):w.length===0?i("div",{class:"home-view-empty",role:"status",children:["No boards match “",c,"”."]},void 0,!0,void 0,this):i(_e,{children:[h.filter((E)=>!E.includes("/")&&g.has(E)).map((E)=>_(E,0)),w.some((E)=>!E.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:w.filter((E)=>!E.category).map(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),x&&i(bk,{board:x,folders:h,onClose:()=>r(null)},x.id,!1,void 0,this),R&&i(xk,{board:R,onClose:()=>a(null)},R.id,!1,void 0,this)]},void 0,!0,void 0,this)}var es=K(!1);function hN(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}function kk(){let[e,t]=I(!1),[n,o]=I(!1),[r,s]=I(null),[a,c]=I(null),[l,u]=I(!1),[p,d]=I(""),m=es.value,f=Pe.value;if(B(()=>{if(!m||!f)return;let v=!0;return c(null),d(""),s(null),re("exportPreview",`/api/canvas/export/preview?board=${encodeURIComponent(f)}&includeFiles=${e}&includeDerivedText=${n}`,null).then((w)=>{if(v)s(w?.manifest??null)}),()=>{v=!1}},[m,e,n,f]),B(()=>{o(!1)},[m,f]),B(()=>{if(!m)return;let v=(w)=>{if(w.key!=="Escape")return;w.stopPropagation(),es.value=!1};return window.addEventListener("keydown",v,{capture:!0}),()=>window.removeEventListener("keydown",v,{capture:!0})},[m]),!m)return null;let h=async()=>{if(!r||r.boardId!==Pe.value)return;u(!0);let v=await re("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),v?.path&&Pe.value===r.boardId)c(v)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>es.value=!1,children:i("div",{class:"text-prompt export-dialog",role:"dialog","aria-label":"Export board","data-testid":"export-dialog",onPointerDown:(v)=>v.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(_e,{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((v)=>`${v.title} (${v.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:(v)=>o(v.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:(v)=>t(v.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((v)=>v.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 (",hN(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:ke()?i("button",{type:"button",disabled:l,onClick:async()=>{u(!0),d("");try{await Rb(a.url)}catch(v){d(v instanceof Error?v.message:"Download failed. Try again.")}finally{u(!1)}},children:l?"Downloading…":"Download"},void 0,!1,void 0,this):i(_e,{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,!1,void 0,this),ke()&&i("p",{children:"Download the HTML file to open it outside ChatGPT."},void 0,!1,void 0,this),p&&i("p",{role:"alert",children:p},void 0,!1,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:()=>es.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 h(),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 Xm({presence:e,size:t=18}){return i("span",{class:"writer-avatar",style:{background:An(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:u_(e.label)},void 0,!1,void 0,this)}function Tk(){let e=Em.value;if(St.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=Fr.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:()=>{Fr.value=!o},children:[i("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((r)=>i(Xm,{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 gN(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 vN(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function yN(){return[...lt.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function Ck(){let e=Fr.value,t=Em.value,n=ko(e?1e4:0);if(B(()=>{if(!e)return;let c=(l)=>{if(l.key!=="Escape")return;if(Gi.value)Gi.value=!1;else Fr.value=!1};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e]),!e||St.value||t.length===0)return null;let o=Cm.value,r=yN().filter((c)=>!o||(c.source??"")===o),s=or.value.filter((c)=>!o||c.sessionId===o),a=(c,l)=>i("button",{type:"button",class:`activity-filter${o===c?" is-active":""}`,style:c?{"--writer":An(c)}:void 0,"aria-pressed":o===c,onClick:()=>{Cm.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"," ",ql(vN(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:()=>{Fr.value=!1},children:i(Xe,{},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:()=>{Cr(c).then((l)=>{if(l)$r(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}=gN(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:An(c.sessionId)},children:c.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"activity-age",children:ql(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:()=>{Gi.value=!0},children:"Writers"},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{Fr.value=!1,sr()},children:["Start session ",i(Xo,{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 bN(){let e=[];if(rr.value)e.push("scoped");if(Hr.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function Ek(){let e=Gi.value,t=ko(e?1e4:0),n=L(null);if(an(n,e),!e)return null;let o=At.value.filter((a)=>a.attached),r=At.value.filter((a)=>!a.attached),s=()=>{Gi.value=!1};return i(_e,{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:ho.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(Xe,{},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(Xm,{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:bN()},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(Xm,{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"," ",ql(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 Ik(e,t){switch(e.type){case"markdown":return i(_l,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return i(tr,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return i(Bl,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return i(tr,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return i(tr,{node:e,expanded:t},void 0,!1,void 0,this);case"board":return i(ou,{node:e},void 0,!1,void 0,this);case"prompt":return i(jl,{node:e},void 0,!1,void 0,this);case"response":return i(Ul,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return i(Fl,{node:e},void 0,!1,void 0,this);case"context":return i(pl,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return i(gl,{node:e},void 0,!1,void 0,this);case"trace":return i(Zl,{node:e},void 0,!1,void 0,this);case"file":return i(hl,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return i(ml,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Dl,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return i(Hl,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return i(ua,{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 Ak(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 xN(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function wN(e,t){return e!==null&&typeof e==="object"&&e.source===In&&e.type==="presentation-exit"&&e.token===t}function SN(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function Pk(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function Rk(){let e=ot.value,t=e?D.value.get(e):void 0,[n,o]=I(!1),[r,s]=I(!1),[a,c]=I(""),l=L(null),u=L(null),p=j(()=>{s(!1),xo()},[]),d=j(()=>{c(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),s(!0)},[]),m=j((T)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:In,token:a,...T},"*")},[a]),f=j(()=>{s(!1)},[]),h=j((T)=>{if(T.key==="Escape"){T.preventDefault(),T.stopPropagation(),s(!1);return}if(T.key==="Tab"&&!Pk(T.target)){T.preventDefault(),T.stopPropagation(),u.current?.focus();return}if((T.key===" "||T.key==="Enter")&&Pk(T.target))return;if(!SN(T.key))return;T.preventDefault(),T.stopPropagation(),m({type:"presentation-key",key:T.key})},[m]),v=j((T)=>{if(T.target.classList.contains("expanded-overlay-backdrop"))xo()},[]),w=j(()=>{if(!t)return;let T=Ak(t);if(!T)return;navigator.clipboard.writeText(T).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),g=j(()=>{if(!e)return;Qn(e)},[e]);B(()=>{s(!1)},[e]),Cn(()=>{if(!r)return;let T=()=>{let be=l.current;if(!be||be.contains(document.activeElement))return;be.focus()},q=[0,50,150].map((be)=>window.setTimeout(T,be)),ae=(be)=>{if(!wN(be.data,a))return;s(!1)};return document.addEventListener("keydown",h,!0),window.addEventListener("message",ae),()=>{q.forEach((be)=>{window.clearTimeout(be)}),document.removeEventListener("keydown",h,!0),window.removeEventListener("message",ae)}},[h,a,r]);let x=L(null),R=j(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]);if(an(x,t!==void 0,{restoreTo:R}),!t)return null;let M=t.data.title||t.data.path?.split("/").pop()||$t[t.type],O=Ak(t),k=xN(O),N=e?ze.value.has(e):!1,_=O.length>0,E=Fn.value===e,z=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",X=XS(t),W=Bn(t.type),J=t.data.provenance&&typeof t.data.provenance==="object"?t.data.provenance:null,G=J?[J.sourceKind,J.sourceUri,J.syncedAt?`synced ${J.syncedAt.slice(11,16)}`:null].filter((T)=>typeof T==="string"&&T.length>0).join(" · "):null;return i("div",{class:"expanded-overlay-backdrop",onPointerDown:v,style:{pointerEvents:E?"none":"auto"},children:i("div",{ref:x,class:`expanded-overlay-panel${N?" is-pinned":""}`,role:"dialog","aria-modal":"true","aria-label":M,"data-testid":"expanded-node",children:[i("div",{class:"expanded-header",children:[i("span",{class:"expanded-kind-icon","aria-hidden":"true",children:i(W,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"expanded-title",children:M},void 0,!1,void 0,this),i("span",{class:"expanded-kind-pill",children:$t[t.type]},void 0,!1,void 0,this),i("button",{type:"button",class:`expanded-pin${N?" is-on":""}`,onClick:g,title:N?"In agent context — click to unpin":"Pin as agent context","aria-pressed":N,children:"✦"},void 0,!1,void 0,this),i("span",{class:"expanded-spacer"},void 0,!1,void 0,this),i("div",{class:"expanded-actions",children:[_&&i("button",{type:"button",class:"expanded-action-btn",onClick:w,title:"Copy content to clipboard",children:n?"Copied!":"Copy"},void 0,!1,void 0,this),El(t)&&i("button",{type:"button",class:"expanded-action-btn",onClick:()=>void Il(t),title:"Open as a full-page site in the system browser",children:["Open in tab ",i(Xo,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&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(Xe,{},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:Ik(t,!0)},void 0,!1,void 0,this):Ik(t,!0)},void 0,!1,void 0,this),i("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:i(nu,{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:[G,k>0?`${k.toLocaleString()} word${k!==1?"s":""}`:null].filter(Boolean).join(" · ")||$t[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${E?" is-saving":""}`,children:E?"Saving edits…":"esc or click outside to close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&r&&i("div",{ref:l,class:"html-presentation-overlay",role:"dialog","aria-modal":"true","aria-label":`Present ${M}`,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(ua,{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 zk=168,Mk=112,uu=20;function Nk(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 w of r)s=Math.min(s,w.position.x),a=Math.min(a,w.position.y),c=Math.max(c,w.position.x+w.size.width),l=Math.max(l,w.position.y+w.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)-uu,minY:Math.min(a,p)-uu,maxX:Math.max(c,d)+uu,maxY:Math.max(l,m)+uu},h=f.maxX-f.minX||1,v=f.maxY-f.minY||1;return{bounds:f,scale:Math.min(zk/h,Mk/v)}}function $k({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:r}){let s=L(null),a=L(!1),c=t.value,l=e.value,u=Nk(c,l,o,r),{bounds:p,scale:d}=u,m=(_)=>(_-p.minX)*d,f=(_)=>(_-p.minY)*d,h=j((_)=>{let E=s.current;if(!E)return;let z=E.getBoundingClientRect(),X=(_.clientX-z.left)/z.width*zk,W=(_.clientY-z.top)/z.height*Mk,J=Nk(t.value,e.value,o,r),G=e.value,T=o/G.scale,q=r/G.scale,ae=X/J.scale+J.bounds.minX,be=W/J.scale+J.bounds.minY;n(-(ae-T/2)*G.scale,-(be-q/2)*G.scale)},[t,e,o,r,n]),v=j((_)=>{_.stopPropagation(),_.preventDefault(),a.current=!0,h(_);let E=(X)=>{if(a.current)h(X)},z=()=>{a.current=!1,document.removeEventListener("pointermove",E),document.removeEventListener("pointerup",z)};document.addEventListener("pointermove",E),document.addEventListener("pointerup",z)},[h]),w=Ne.value,g=ze.value,x=St.value?Gl.value:new Set,R=rr.value,M=R?Xl(R.nodeIds.map((_)=>c.get(_)).filter((_)=>_!==void 0),R.padding):null,O=At.value.map((_)=>({id:_.sessionId,phase:_.phase,worker:_.parentAgentId!=null,external:!_.attached,at:Vl(_,(E)=>c.get(E))})).filter((_)=>_.at!==null),k=-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((_)=>{let E=_.type==="group";return i("span",{class:`minimap-node${E?" is-group":""}${w.has(_.id)?" is-selected":""}${g.has(_.id)?" is-pinned":""}${x.has(_.id)?" is-agent":""}`,"data-kind":_.type,style:{left:`${m(_.position.x)}px`,top:`${f(_.position.y)}px`,width:`${Math.max(E?6:4,_.size.width*d)}px`,height:`${Math.max(E?5:3,_.size.height*d)}px`}},_.id,!1,void 0,this)}),M&&i("span",{class:"minimap-fence",style:{left:`${m(M.x)}px`,top:`${f(M.y)}px`,width:`${M.width*d}px`,height:`${M.height*d}px`}},void 0,!1,void 0,this),O.map((_)=>i("span",{class:`minimap-presence phase-${_.phase}${_.worker?" is-worker":""}${_.external?" is-external":""}`,style:{left:`${m(_.at.x)-4}px`,top:`${f(_.at.y)-4}px`,"--identity-color":An(_.id)}},_.id,!1,void 0,this)),i("span",{class:"minimap-frame",style:{left:`${m(k)}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 Ok(){let e=Ne.value.size,t=j(()=>{let c=Array.from(Ne.value);if(c.length===0)return;Yc(c),Wt()},[]),n=j(()=>{let c=Array.from(Ne.value);if(c.length===0)return;xi({title:"Group",childIds:c}),Wt()},[]),o=j(()=>{let c=Array.from(Ne.value);for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++)Er(c[l],c[u],"relation");Wt()},[]),r=j(()=>{let c=Array.from(Ne.value);for(let l of c)Uo(l);Wt()},[]);if(e===0)return null;let s=e>=2,a=!St.value&&ze.value.size>0&&!Vn.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(_e,{children:[i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Qe,{label:"Align left",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align left",onClick:()=>bp("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(Qe,{label:"Align top",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align top",onClick:()=>bp("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(Qe,{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:()=>mx(),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(Qe,{label:"Auto-arrange selection",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Auto-arrange",onClick:()=>fx(),children:i(wo,{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(Qe,{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(Qe,{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(Qe,{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(Qe,{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(Qe,{label:"Clear selection",shortcut:"Esc",side:"up",children:i("button",{type:"button",class:"selection-bar-icon",onClick:Wt,"aria-label":"Clear selection",children:i(Xe,{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 du(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 pu(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 _N={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},kN={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},Lk=[{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"}],Dk=Object.fromEntries(Lk.map((e)=>[e.id,e.hint])),TN={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 Km(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 CN({item:e}){let t=_N[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&&pt(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:kN[e.status]??t},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:Km(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function EN({gate:e,now:t}){let[n,o]=I(null),r=async(c)=>{o(c),await S_(e,c),o(null)},s=e.nodeIds[0],a=du(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&&pt(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 ",pu(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:Km(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function IN({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),__(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 AN(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 PN({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:AN(e)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function RN(){let e=rr.value,t=Ne.value.size,[n,o]=I(!1),r=(s)=>{o(!0),g_(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(_e,{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(_e,{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([...Ne.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 NN(e){if(e==="browser")return"you";return At.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function zN({entry:e}){let t=fa.value.has(e.id);return i("li",{class:`session-timeline-row tone-${TN[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:Dk[Nm(e.kind)],children:e.label},void 0,!1,void 0,this),e.who&&i("span",{class:"session-timeline-who",style:{"--identity-color":An(e.who)},children:NN(e.who)},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:Km(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 zm(e),children:[i(Cp,{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 Fk(){let[e,t]=I(!1),n=Vi.value,o=h_.value,r=Hr.value,s=v_.value,a=y_.value,c=w_.value,[l,u]=I(!1),[p,d]=I(null),m=ko();if(B(()=>{ir()},[]),!(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:nr(n),"aria-label":`Session live: ${nr(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:nr(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 Kl(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(Vs,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(RN,{},void 0,!1,void 0,this),(()=>{let h=c.find((v)=>v.undoable&&!fa.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 zm(h),children:[i(Cp,{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((O)=>O.status==="in-progress"||O.status==="todo").length,v=o.filter((O)=>O.status!=="cancelled"),w=v.filter((O)=>O.status==="done").length,g=o.length-v.length,x=r.length>0,R=l||x,M=h>0?`${h} running`:v.length>0?`${w}/${v.length} done${g>0?` · ${g} cancelled`:""}`:o.length>0?`${o.length} cancelled`:"none yet";return i(_e,{children:[i("button",{type:"button",class:"session-section-toggle","aria-expanded":R,"data-testid":"work-items-toggle",onClick:()=>u((O)=>!O),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),M]},void 0,!0,void 0,this),i("span",{class:`session-section-chevron${R?" is-open":""}`,"aria-hidden":"true",children:i(Vs,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R&&(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((O)=>i(EN,{gate:O,now:m},O.id,!1,void 0,this)),s.map((O)=>i(IN,{gate:O},O.id,!1,void 0,this)),a.map((O)=>i(PN,{gate:O},O.id,!1,void 0,this)),o.map((O)=>i(CN,{item:O},O.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:Lk.map((h)=>i("button",{type:"button",class:`activity-filter${Br.value===h.id?" is-active":""}`,"aria-pressed":Br.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:()=>{Br.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:Dk[p??Br.value]},void 0,!1,void 0,this),c.length===0?i("div",{class:"session-empty",children:Br.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(zN,{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 Jm(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)}}var Hk=(e)=>e.map((t)=>t.title).join(", ");function MN({context:e,label:t}){let o=[{key:"read",name:"Read",glyph:"eye"},{key:"pinned",name:"Pinned",glyph:"pin"},{key:"created",name:"Created",glyph:"spark"},{key:"edited",name:"Edited",glyph:"pen"}].filter((s)=>e[s.key].length>0);if(o.length===0&&e.changedSinceRead.length===0)return null;let r=ar.value!==null;return i("div",{class:"session-receipt-context","data-testid":"session-receipt-context",children:[e.changedSinceRead.length>0&&i("div",{class:"session-receipt-warn",children:[i("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:i("path",{d:eu.warn},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{children:[Hk(e.changedSinceRead)," changed after ",t," read"," ",e.changedSinceRead.length===1?"it":"them","."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),o.map((s)=>i("div",{class:"session-receipt-context-row","data-row":s.key,children:[i("div",{class:"session-receipt-context-head",children:[s.glyph==="pin"?i(ul,{},void 0,!1,void 0,this):i("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:i("path",{d:eu[s.glyph]},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"session-receipt-context-name",children:s.name},void 0,!1,void 0,this),i("span",{class:"session-receipt-context-count",children:e[s.key].length},void 0,!1,void 0,this),s.key==="pinned"&&i("button",{type:"button",class:"session-receipt-mini",onClick:()=>{for(let a of e.pinned)Qn(a.id)},children:"Unpin"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-context-items",children:s.key==="pinned"?e.pinned.map((a)=>a.reason?`${a.title} — “${a.reason}”`:a.title).join("; "):Hk(e[s.key])},void 0,!1,void 0,this)]},s.key,!0,void 0,this)),i("button",{type:"button",role:"switch","aria-checked":r,class:`session-receipt-lens${r?" is-on":""}`,onClick:()=>$m(!r),children:[i("span",{class:"session-receipt-lens-track","aria-hidden":"true",children:i("span",{class:"session-receipt-lens-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Dim untouched nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Bk({onOpenSnapshots:e}){let t=Xi.value,[n,o]=I(null),[r,s]=I(!1);if(B(()=>o(null),[t]),!t)return null;let a=async()=>{if(!t.snapshot)return;s(!0);try{let u=await ct(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(u.ok){let p=await u.json();o(Jm(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.sessions>1?`${t.sessions} sessions ended`: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:Jl,"aria-label":"Dismiss receipt",children:i(Xe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.sessions>1&&i("div",{class:"session-receipt-who",children:t.labels.join(", ")},void 0,!1,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(MN,{context:t.context,label:t.labels.join(", ")},void 0,!1,void 0,this),i("div",{class:"session-receipt-note",children:t.sessions>1?"History has each session’s diff and the snapshot from before it.":t.snapshot?"A snapshot of the board from before this session is saved — restore it to undo the session.":t.context.created.length===0&&t.context.edited.length===0?"The board itself did not change — nothing to restore.":"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 $N=[{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:rt("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:rt("0"),desc:"Reset viewport to origin"},{keys:`${rt("+")} / ${rt("−")}`,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:Js?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:Js?"⌘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 jk({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:$N.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:ke()&&n.desc.startsWith("Undo / redo")?"Undo / redo — available in the local workbench only":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 Uk="Before session · ";function Zk(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 ON(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 mu(e){if(!e.startsWith(Uk))return null;let t=e.slice(Uk.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function Wk({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,w]=I({}),g=L(null),x=L(null);B(()=>{if(!e)return;a(!0),Kb().then((_)=>{r(_),a(!1)})},[e]),B(()=>{if(e)setTimeout(()=>x.current?.focus(),50)},[e]),B(()=>{if(!e)return;let _=(E)=>{let z=g.current,X=n.current;if(z&&!z.contains(E.target)&&X&&!X.contains(E.target))t()};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[e,t]),B(()=>{if(!e)return;let _=(E)=>{if(E.key==="Escape")t()};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[e,t]);let R=j(async()=>{let _=d.trim();if(!_)return;l(!0);let E=await Jb(_);if(l(!1),E.ok&&E.snapshot)r((z)=>[E.snapshot,...z]),m("")},[d]),M=j(async(_)=>{h(null),p(_);let E=await Yb(_);if(p(null),E.ok)t()},[t]),O=j(async(_)=>{if((await Qb(_)).ok)r((z)=>z.filter((X)=>X.id!==_));h(null)},[]),k=j(async(_)=>{w((z)=>({...z,[_]:"loading"}));let E=await re("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(_)}/diff`,{});w((z)=>({...z,[_]:Jm(E.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let N=(_,E)=>f?.id===_.id?i(_e,{children:[i("button",{type:"button",class:`snapshot-action-btn ${f.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>f.action==="delete"?O(_.id):M(_.id),title:f.action==="delete"?"Confirm delete":"Confirm restore",disabled:u!==null,children:f.action==="delete"?"Delete":u===_.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(_e,{children:[i("button",{type:"button",class:"snapshot-action-btn snapshot-action-restore",onClick:()=>h({id:_.id,action:"restore"}),title:ke()?"Restore this snapshot — replaces the current canvas":"Restore this snapshot — replaces the current canvas (undoable)",disabled:u!==null,children:u===_.id?"Restoring…":E},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn snapshot-action-delete",onClick:()=>h({id:_.id,action:"delete"}),title:"Delete this snapshot","aria-label":"Delete snapshot",disabled:u!==null,children:i(Xe,{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(Xe,{},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:x,type:"text",class:"snapshot-name-input",value:d,onInput:(_)=>m(_.target.value),onKeyDown:(_)=>{if(_.key==="Enter")R()},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:R,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:ke()?"Restoring replaces the current canvas. Save a snapshot first to keep your current state.":"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((_)=>mu(_.name)===null),...o.some((_)=>mu(_.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((_)=>mu(_.name)!==null)].map((_)=>{if(_.id==="__sessions-header__")return i("div",{class:"snapshot-section-header","data-testid":"history-sessions-header",children:"Sessions"},_.id,!1,void 0,this);let E=mu(_.name),z=v[_.id];if(E!==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 — ",E]},void 0,!0,void 0,this),i("span",{class:"snapshot-item-time",children:Zk(_.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:["snapshot at session start · ",_.nodeCount," node",_.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 k(_.id),children:z==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),N(_,"Restore pre-state")]},void 0,!0,void 0,this)]},_.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:_.name},void 0,!1,void 0,this),i("span",{class:"snapshot-item-time",children:Zk(_.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:[_.nodeCount," node",_.nodeCount!==1?"s":"",_.edgeCount>0?` · ${_.edgeCount} edge${_.edgeCount!==1?"s":""}`:""," · ",ON(_.createdAt)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-actions",children:N(_,"Restore")},void 0,!1,void 0,this)]},_.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 LN=8;function DN({children:e}){let t=Ze(()=>document.createElement("div"),[]);return Cn(()=>(document.body.appendChild(t),()=>{Ms(null,t),t.remove()}),[t]),Cn(()=>Ms(e,t),[e,t]),null}function qk({fallbackName:e}){let[t,n]=I(!1),o=L(null),r=L(null),s=L(null);Cn(()=>{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=Hc(),c=!Xn.value?e:a?a.name:"Home",l=Ut.value.filter((d)=>d.id!==Pe.value).slice(0,LN),u=r.current?.getBoundingClientRect(),p=(d)=>{n(!1),sn(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(sl,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&u&&i(DN,{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(dl,{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),Vm()},children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:i(Rx,{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(wo,{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 Gk=3,Vk={"waiting-approval":0,thinking:1,tooling:2,idle:3};function FN(){let e=p_.value;if(e.length===0)return null;let t=e.filter((c)=>!c.parentAgentId||!e.some((l)=>l.sessionId!==c.sessionId&&!l.parentAgentId&&(l.sessionId===c.parentAgentId||l.source===c.parentAgentId))),n=[...t].sort((c,l)=>(Vk[c.phase]??4)-(Vk[l.phase]??4)),o=n.slice(0,Gk),r=n.slice(Gk),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(_e,{children:[i("span",{class:"agent-chips",children:o.map((c)=>{let l=c.parentAgentId?0:At.value.filter((u)=>u.parentAgentId!=null&&(u.parentAgentId===c.sessionId||u.parentAgentId===c.source)).length;return i(Qe,{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":An(c.sessionId)},children:[i("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"agent-chip-label",children:nr(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(),Kl({source:c.source,agentId:c.agentId})},children:i(Xe,{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(Qe,{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 HN(){let e=Hr.value.length,t=Vi.value!==null&&e>0,n=ko(t?1000:0);if(!t)return null;let o=Hr.value.map((r)=>du(r,n)).filter((r)=>r!==null).sort((r,s)=>r-s)[0];return i(Qe,{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&&` · ${pu(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function BN(e){if(e>0.9)return"danger";if(e>=0.7)return"warn";return"ok"}function ya(e){return e>=1000?`${(e/1000).toFixed(e>=1e4?0:1)}k`:String(e)}function jN(){let e=Vi.value;if(!e)return null;let t=Tm.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:`${ya(n.used)} of ${ya(n.total)} tokens of the agent's actual context window are used. Your ✦-pinned nodes account for ≈ ${ya(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: ≈ ${ya(t.used)} of a ${ya(t.total)}-token budget. When the agent's host reports its real context window, this meter switches to showing that instead.`};return i(Qe,{label:c.label,body:c.body,tapToOpen:!0,children:i("span",{class:`context-budget tone-${BN(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 UN(){let[e,t]=I(!1);if(Vi.value)return null;return i(Qe,{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),sr().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 Xk(){let e=hn.value,t=Qt.value,n=ie.value,o=D.value.size,r=Je.value.size,s=ki.value,a=Array.from(D.value.values()).filter((f)=>f.type==="trace").length,[c,l]=I("");B(()=>{let f=!1;return ct("/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=Bm.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=bt();Ei(f.width,f.height)};return i("div",{class:"top-bar",children:[i(Qe,{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(qk,{fallbackName:c||"PMX Canvas"},void 0,!1,void 0,this),i("span",{class:"top-bar-meta hud-collapsible-text",children:ho.value?ho.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(FN,{},void 0,!1,void 0,this),i(HN,{},void 0,!1,void 0,this),i(jN,{},void 0,!1,void 0,this),i(Tk,{},void 0,!1,void 0,this),!ke()&&i(UN,{},void 0,!1,void 0,this),i("div",{class:"top-bar-sep"},void 0,!1,void 0,this),Pe.value&&i(Qe,{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:()=>{es.value=!0},children:"Export"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Pe.value&&i(Qe,{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:()=>{Hn.value=!0},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Qe,{label:"Zoom out",shortcut:rt("−"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>Ci(0.8),"aria-label":"Zoom out",children:i(Lx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Qe,{label:"Reset zoom",shortcut:rt("0"),children:i("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>qo({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(Qe,{label:"Zoom in",shortcut:rt("+"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>Ci(1.25),"aria-label":"Zoom in",children:i(Ox,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Qe,{label:"Fit all",shortcut:"F",align:"end",children:i("button",{type:"button",class:"top-bar-btn",onClick:m,"aria-label":"Fit canvas",children:i(al,{},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 cr={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 ba(e,t,n,o={}){let r=cr[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 Wr=null,Sa=null,fu=0,lr=null,ZN=3000,WN=2000,Kk=5000,xa=!1,To=null,ts=null,dr=0,ur=null;function qN(){if(ke())return"poll";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 ns=new Map;function _a(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 gu(e){if(!Sa)return e;let t=Sa.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 ka(e,t,n){return gu(ba(e,t,n))}function GN(){return Ll([...D.value.values()],cr.markdown.w,cr.markdown.h)}function os(){if(!D.value.has("status-main"))vo(ka("status-main","status",{phase:"idle",message:"",elapsed:0}))}function VN(e,t){let n=`md-${_a(e)}`;if(D.value.get(n))ve(n,{path:e,title:t}),qe.value=n;else{let r=GN(),s=ka(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=r,vo(s),pt(n)}}function XN(e){if(D.value.get("context-main"))ve("context-main",{cards:e});else if(e.length>0){let o=ka("context-main","context",{cards:e});vo(o)}}function KN(e){let t=e.url,n=`mcp-${_a(t)}`;if(D.value.get(n))ve(n,e);else vo(ka(n,"mcp-app",e)),pt(n)}function JN(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(D.value.get(o)){ve(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[w,g]of D.value.entries())if(g.type==="mcp-app"&&g.data.mode==="ext-app"&&g.data.serverName===s&&g.data.toolName===a&&!g.data.toolResult){ve(w,{...e});return}}let{_x:c,_y:l,_width:u,_height:p}=e,d=cr["mcp-app"],m=u??d.w,f=p??d.h,h=c===void 0||l===void 0?Ll([...D.value.values()],m,f):null,v=gu(ba(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}}));vo(v),pt(o,{recordHistory:!1})}function YN(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(D.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&D.value.has(n))return n;for(let[o,r]of D.value.entries())if(r.type==="mcp-app"&&r.data.mode==="ext-app"&&r.data.toolCallId===e)return o;return null}function n0(e){let t=typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null;if(t&&D.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return YN(e.toolCallId)}function o0(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,r]of D.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 r0(e){if(D.value.get("ledger-main"))ve("ledger-main",e);else{let o=ka("ledger-main","ledger",e);o.collapsed=!0,vo(o)}}function tf(e){if(!aa(e))return;if(document.documentElement.setAttribute("data-theme",e),Zi(),gt.value!==e)gt.value=e}function QN(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 ez(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function nf(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 i0(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 tz(e){let t=nf(e),n=i0(e);return t&&n?{...t,...n}:null}function nz(e){if(typeof e.id!=="string"||!e.id)return null;if(!QN(e.type))return null;let t=nf(e.position),n=i0(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,contentRevision:typeof e.contentRevision==="number"?e.contentRevision:0,...Jk(e.createdBy)?{createdBy:e.createdBy}:{},...Jk(e.lastEditedBy)?{lastEditedBy:e.lastEditedBy}:{},data:o}}function Jk(e){if(!e||typeof e!=="object")return!1;let t=e;return typeof t.actor==="string"&&typeof t.source==="string"}function oz(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(!ez(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 rz(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)=>nf(o)).filter((o)=>o!==null),n=tz(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 Yk="pmx-canvas-version-reload";function iz(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(Yk)===r)return;window.sessionStorage.setItem(Yk,r)}catch{return}window.location.reload()}function sz(e){let t=or.value[0]?.id;if(Im(e),St.value&&or.value[0]?.id!==t)ir()}function az(e){T_(e)}var Qk=null,wa=0,Ym=0,Qm=0;function cz(e){sm(e)}function lz(){let e=++wa;Sa=null,Qt.value=!1,Pl(),cx(),$c(),Jl(),Om({}),gn.value=null,of();let t=Ym,n=Qm;jb().then((o)=>{if(e===wa&&t===Ym)s0({layout:o})}),re("fetchPinnedContext","/api/canvas/pinned-context",{}).then((o)=>{if(e===wa&&n===Qm)a0({nodeIds:o.nodeIds})})}Mb(lz);function uz(e){if(ho.value=e.sessionId||"",hn.value="connected",lp().then(Us),Ar.value+=1,iz(e.version,e.bundleStamp),qb().then(Im),Yl(),Qk?.(),!Bc&&!ke())Qk=bS();if(re("fetchHumanPresence","/api/canvas/human-presence",null).then(sm),of().then(()=>{if(St.value)ir()}),typeof e.theme==="string"&&!jm())tf(e.theme);if(e.ledgerSummary)r0(e.ledgerSummary)}function dz(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(VN(t,n),e.ledgerSummary)r0(e.ledgerSummary)}function pz(e){os(),ve("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function mz(e){os(),ve("status-main",{phase:e.phase,detail:e.detail})}function fz(e){let t=e.cards??[];XN(t)}function hz(e){if(typeof e.url==="string"&&e.url)KN({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function gz(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let r=`mcp-${_a(o)}`;if(D.value.has(r))ve(r,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function vz(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${_a(e.url)}`;if(D.value.has(t))ve(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function yz(e){let n=D.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);ve("context-main",{auxTabs:o})}function bz(e){if(D.value.has("context-main"))if(e.mode==="all")ve("context-main",{auxTabs:[]});else{let o=D.value.get("context-main");if(!o)return;let r=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);ve("context-main",{auxTabs:r})}}function xz(e){os(),ve("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function wz(e){os(),ve("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function Sz(e){os(),ve("status-main",{activeTool:null})}function _z(e){if(e.state==="active"&&e.path){let n=`md-${_a(e.path)}`;if(D.value.has(n))ve(n,{reviewActive:!0})}}function kz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;JN({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 Tz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=n0(e)??o0(e.serverName,e.toolName);if(!t)return;if(D.value.has(t))ve(t,{html:e.html})}function Cz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=n0(e)??o0(e.serverName,e.toolName);if(!t)return;if(D.value.has(t)){if(e.success===!1){Wo(t);return}ve(t,{toolResult:vm({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 Ez(e){os(),ve("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function Iz(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:r,contextNodeIds:s}=e;if(e.threadNodeId&&D.value.has(e.threadNodeId)){let a=e.threadNodeId,c=D.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"});ve(a,{turns:l,threadStatus:"pending"});return}if(!D.value.has(t)){let a=o??cr.prompt;vo(gu(ba(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}}))),pt(t)}if(r&&D.value.has(r))Si({id:`edge-${r}-${t}`,from:r,to:t,type:"flow",style:"dashed"})}function Az(e){let{nodeId:t,status:n}=e;if(t&&D.value.has(t))ve(t,{status:n})}function Pz(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?D.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){ns.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),ve(n,{turns:s,threadStatus:"streaming",_activeResponseId:t}),pt(n);return}let r=o?{x:o.position.x,y:o.position.y+o.size.height+24}:{x:cr.response.x,y:cr.response.y};if(!D.value.has(t))vo(gu(ba(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:r})));if(n)Si({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});pt(t)}function Rz(e){let t=e.responseNodeId;if(!t)return;let n=ns.get(t);if(n){let o=D.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";ve(n,{turns:r,threadStatus:"streaming"})}return}if(!D.value.has(t))return;ve(t,{content:e.content,status:"streaming"})}function Nz(e){let t=e.responseNodeId;if(!t)return;let n=ns.get(t);if(n){let s=D.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";ve(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}ns.delete(t);return}if(!D.value.has(t))return;ve(t,{content:e.content,status:"complete"});let r=D.value.get(t)?.data.promptNodeId;if(r){let s=`edge-${r}-${t}`,a=Je.value.get(s);if(a)vx(s),Si({...a,animated:!1})}}function s0(e){let t=e.layout;if(!t?.nodes)return;Ym+=1;let n=!Qt.value;Qt.value=!0;let o=t.nodes.map(nz).filter((c)=>c!==null),r=Array.isArray(t.edges)?t.edges.map(oz).filter((c)=>c!==null):Array.from(Je.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(rz).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)bo();_x({...a?{viewport:a}:{},nodes:o,edges:r,...s?{annotations:s}:{}},{applyViewport:n}),ap({event:"canvas-layout-update",data:e})}function zz(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function Mz(e){if(_p())return;let t=e.nodeId;if(t&&D.value.has(t)){if(e.noPan===!0){yo(t);return}pt(t)}}function $z(e){if(_p())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;bo(),xx({x:n,y:o,scale:r})}function Oz(e){if(D.value.get("context-main"))ve("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function Lz(e){ki.value=e.enabled===!0}function Dz(e){if(typeof e.theme==="string"&&!jm())tf(e.theme)}function a0(e){Qm+=1;let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];gx(t),ap({event:"context-pins-changed",data:e}),Yl()}function Fz(){Yl()}var hu=null,ef=0;async function of(){let e=++ef,t=wa,n=await Wb();if(e===ef&&t===wa)gn.value=n}function e0(){if(hu)clearTimeout(hu);ef+=1,hu=setTimeout(()=>{if(hu=null,of(),St.value)ir()},150)}function Hz(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;dS(t)}function Bz(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)mS(t,typeof e.nodeId==="string"?e.nodeId:void 0);else im(t)}var c0={connected:uz,"workbench-open":dz,"canvas-status":pz,"execution-phase":mz,"context-cards":fz,"mcp-app-candidate":hz,"mcp-app-host-snapshot":gz,"mcp-app-host-fallback":vz,"aux-open":yz,"aux-close":bz,"assistant-complete":xz,"tool-start":wz,"tool-complete":Sz,"review-state":_z,"subagent-status":Ez,"ext-app-open":kz,"ext-app-update":Tz,"ext-app-result":Cz,"context-pins-changed":a0,"context-status-changed":Fz,"boards-changed":kr,"canvas-layout-update":s0,"canvas-focus-node":Mz,"canvas-viewport-update":$z,"context-usage":Oz,"trace-state":Lz,"theme-changed":Dz,"canvas-prompt-created":Iz,"canvas-prompt-status":Az,"canvas-response-start":Pz,"canvas-response-delta":Rz,"canvas-response-complete":Nz,"ax-state-changed":e0,"ax-event-created":e0,"ax-intent":Hz,"ax-intent-clear":Bz,"agent-presence":sz,"human-presence":cz,"agent-session-ended":az};function l0(e,t){let n=c0[e];if(!n)return;let o=n;try{o(t)}catch(r){console.warn(`[sse-bridge] Handler for "${e}" failed:`,r)}}function t0(){xa=!0,dr+=1;let e=dr;hn.value="connecting";let t=null,n=!1,o=async()=>{if(e!==dr)return;try{let r=new URLSearchParams;if(ts!==null)r.set("since",String(ts));let s=ho.value;if(s)r.set("session",s);let a=r.toString(),c=await ct(`/api/workbench/poll${a?`?${a}`:""}`);if(e!==dr)return;if(!c.ok)throw Error(`poll failed with HTTP ${c.status}`);let l=await c.json();if(e!==dr)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){ts=null,To=setTimeout(()=>void o(),0);return}if(l.snapshot&&n)Sa=Sp(),Qt.value=!1,$c(),Pl(),ns.clear();for(let p of l.events)l0(p.event,p.payload);n=!0,ts=l.seq,Pr.value=0,Rr.value=0,hn.value="connected",To=setTimeout(()=>void o(),WN)}catch(r){if(e!==dr)return;console.warn("[sse-bridge] poll transport error:",r),hn.value="disconnected",Pr.value+=1,Rr.value=Kk,To=setTimeout(()=>void o(),Kk)}};return o(),()=>{if(dr+=1,xa=!1,ts=null,To)clearTimeout(To),To=null}}function rf(){if(ak(tf),Sa=Sp(),Qt.value=!1,$c(),Pl(),ns.clear(),lr)clearTimeout(lr),lr=null;let e=qN();if(e==="poll"||xa)return t0();let t=ho.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";hn.value="connecting";let o=new EventSource(n);Wr=o;let r=!1;if(ur)clearTimeout(ur);if(ur=null,e!=="sse")ur=setTimeout(()=>{if(ur=null,r||Wr!==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(),Wr=null,t0()},ZN);for(let[s]of Object.entries(c0))o.addEventListener(s,(a)=>{r=!0;try{l0(s,JSON.parse(a.data))}catch(c){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,c)}});return o.onopen=()=>{if(Wr!==o)return;fu=0,Pr.value=0,Rr.value=0,hn.value="connected"},o.onerror=()=>{if(Wr!==o)return;hn.value="disconnected",o.close(),Wr=null,fu+=1;let s=zz(fu);Pr.value=fu,Rr.value=s,lr=setTimeout(()=>{lr=null,rf()},s)},()=>{if(lr)clearTimeout(lr),lr=null;if(ur)clearTimeout(ur),ur=null;if(xa){if(dr+=1,xa=!1,ts=null,To)clearTimeout(To),To=null}o.close(),Wr=null}}function qr(e,t){console.error(`[app] ${e} failed`,t)}function u0(){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=L(null),{menu:f,openNodeMenu:h,openCanvasMenu:v,openEdgeMenu:w,closeMenu:g}=uk(),x=Qt.value,R=Xn.value&&Pe.value===null,M=St.value,O=j(()=>t((W)=>!W),[]),k=j(()=>o((W)=>!W),[]),N=j(()=>o(!1),[]),_=j((W)=>d(W),[]),E=j((W,J)=>{qo({x:W,y:J,scale:ie.value.scale},200)},[]);B(()=>rf(),[]),B(()=>{let W=()=>c(!0);return window.addEventListener("pmx-open-board-link",W),()=>window.removeEventListener("pmx-open-board-link",W)},[]),B(()=>{let W=null,J=()=>{if(W!==null)window.clearTimeout(W);W=window.setTimeout(()=>{W=null,Us()},400)};return window.addEventListener("resize",J),()=>{if(W!==null)window.clearTimeout(W);window.removeEventListener("resize",J)}},[]),B(()=>{let W=(T)=>{let q=(T.metaKey||T.ctrlKey)&&!T.altKey;if(q&&T.key==="k"){T.preventDefault(),s((pe)=>!pe);return}if(T.key==="Escape"&&p){T.preventDefault(),d(null);return}if(T.key==="Escape"&&ot.value&&!Fn.value){T.preventDefault(),xo();return}if(T.key==="Escape"&&r){T.preventDefault(),s(!1);return}if(T.key==="Escape"&&l){T.preventDefault(),u(!1);return}let ae=T.target,be=ae?.tagName;if(be==="INPUT"||be==="TEXTAREA"||ae?.isContentEditable)return;if(T.key===" "&&!T.repeat&&!q){T.preventDefault(),qs.value=!0;return}if(T.key==="?"||T.key==="/"&&T.shiftKey){T.preventDefault(),u((pe)=>!pe);return}if(q&&(T.key==="z"||T.key==="Z"))T.preventDefault(),Mm(T.shiftKey);else if(q&&(T.key==="y"||T.key==="Y"))T.preventDefault(),Mm(!0);else if(q&&T.key==="0")T.preventDefault(),qo({x:0,y:0,scale:1},250);else if(q&&(T.key==="="||T.key==="+"))T.preventDefault(),Ci(1.25);else if(q&&T.key==="-")T.preventDefault(),Ci(0.8);else if(T.key==="Escape"){if(Ne.value.size>0||Yn.value!==null){Wt();return}qe.value=null,g()}else if(T.key==="Tab")T.preventDefault(),Tx(T.shiftKey?-1:1);else if(T.key==="Delete"||T.key==="Backspace"){if(Yn.value!==null){let Me=Yn.value;T.preventDefault(),Yn.value=null,Xc(Me).catch((Te)=>qr("delete-edge",Te));return}let pe=Ne.value.size>0?[...Ne.value]:qe.value?[qe.value]:[];if(pe.length===0)return;T.preventDefault();for(let Me of pe)Uo(Me).catch((Te)=>qr("delete",Te));Wt(),qe.value=null}else if(qe.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(T.key)){T.preventDefault();let pe=T.key.replace("Arrow","").toLowerCase();Cx(pe)}else if(!q&&!T.altKey){let pe=T.key.toLowerCase();if(pe==="v"&&!T.shiftKey)en.value="select";else if(pe==="c"&&!T.shiftKey&&!q)T.preventDefault(),en.value=en.value==="connect"?"select":"connect";else if(pe==="m"&&!T.shiftKey)T.preventDefault(),Pn({type:"markdown",title:"New note",width:520,height:360}).catch((Me)=>qr("create markdown",Me));else if(pe==="a"&&!T.shiftKey)T.preventDefault(),d((Me)=>Me==="pen"?null:"pen");else if(pe==="g"&&!T.shiftKey){T.preventDefault();let Me=Array.from(Ne.value);if(Me.length>=2)xi({title:"Group",childIds:Me}).catch((Te)=>qr("group selection",Te)),Wt();else Pn({type:"group",title:"Group"}).catch((Te)=>qr("create group",Te))}else if(pe==="g"&&T.shiftKey){T.preventDefault();for(let Me of px())Wo(Me),wi(Me).catch((Te)=>qr("ungroup",Te));Wt()}else if(pe==="i"&&!T.shiftKey)T.preventDefault(),Zr("image");else if(pe==="w"&&!T.shiftKey)T.preventDefault(),Zr("webpage");else if(pe==="h"&&!T.shiftKey)T.preventDefault(),Pn({type:"html",title:"HTML surface"}).catch((Me)=>qr("create html",Me));else if(pe==="f"&&T.shiftKey)T.preventDefault(),Zr("file");else if(pe==="f"&&!T.shiftKey){T.preventDefault();let Me=bt();Ei(Me.width,Me.height)}}},J=(T)=>{if(T.key===" ")qs.value=!1},G=()=>{qs.value=!1};return document.addEventListener("keydown",W),document.addEventListener("keyup",J),window.addEventListener("blur",G),()=>{document.removeEventListener("keydown",W),document.removeEventListener("keyup",J),window.removeEventListener("blur",G)}},[p,g,r,l]),B(()=>{let W=window.setTimeout(()=>void Us(),250);return()=>window.clearTimeout(W)},[M]),B(()=>{if(!x)return;let W=window.__pmxCanvasBootstrapReady;if(typeof W==="function")W()},[x]);let z=Array.from(D.value.values()),X=bt();return i("div",{class:`app-shell${Hn.value?" is-presenting":""}`,"data-session-active":M?"true":"false",children:[i(Ax,{},void 0,!1,void 0,this),i(hk,{minimapVisible:e,onToggleMinimap:O,snapshotOpen:n,onToggleSnapshot:k,snapshotBtnRef:m,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>u((W)=>!W),annotationTool:p,onSetAnnotationTool:_},void 0,!1,void 0,this),i("div",{class:"app-main",children:[i(Xk,{},void 0,!1,void 0,this),i(rk,{},void 0,!1,void 0,this),i("div",{class:"canvas-region",ref:(W)=>rb(W),children:[i(nk,{onNodeContextMenu:h,onCanvasContextMenu:v,onEdgeContextMenu:w,annotationMode:p!==null,annotationTool:p},void 0,!1,void 0,this),i(Kx,{},void 0,!1,void 0,this),i(Xx,{},void 0,!1,void 0,this),i(Ck,{},void 0,!1,void 0,this),i(Ek,{},void 0,!1,void 0,this),R?i(_k,{},void 0,!1,void 0,this):x&&z.length===0&<.value.size===0&&i(gk,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),Ne.value.size>0&&i(Ok,{},void 0,!1,void 0,this),M&&!ke()?i(ok,{},void 0,!1,void 0,this):ze.value.size>0&&i(mk,{},void 0,!1,void 0,this),i(Bk,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),i(Yx,{},void 0,!1,void 0,this),i(kk,{},void 0,!1,void 0,this),ot.value&&i(Rk,{},void 0,!1,void 0,this),i(Wk,{open:n,onClose:N,anchorRef:m},void 0,!1,void 0,this),e&&!R&&i($k,{viewport:ie,nodes:D,edges:Je,onNavigate:E,containerWidth:X.width,containerHeight:X.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M&&i(Fk,{},void 0,!1,void 0,this),f&&i(dk,{menu:f,onClose:g},void 0,!1,void 0,this),r&&i(ck,{onClose:()=>s(!1),onToggleMinimap:O},void 0,!1,void 0,this),a&&i(lk,{onClose:()=>c(!1)},void 0,!1,void 0,this),l&&i(jk,{onClose:()=>u(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var jz=S({x:ne(),y:ne()}),v9=S({boardId:C().nullable(),boardName:C(),boards:te(S({id:C(),name:C()})),revision:C(),nodes:te(S({id:C(),type:C(),title:C(),text:C(),contentRevision:ne().int().nonnegative(),editableContent:C().optional(),position:jz,size:S({width:ne(),height:ne()}),image:C().optional()})),edges:te(S({id:C(),from:C(),to:C(),label:C()})),pinnedNodeIds:te(C())});function d0(e,t,n=[]){let o=new Set(e.nodes.map((c)=>c.id)),r=new Set(t.filter((c)=>o.has(c)).slice(0,20)),s=new Set(e.pinnedNodeIds.filter((c)=>o.has(c)).slice(0,20)),a=new Set(n.filter((c)=>o.has(c)).slice(0,20));return{boardId:e.boardId,boardName:e.boardName,selectedNodeIds:[...r],focusedNodeIds:[...a],pinnedNodeIds:[...s],nodes:e.nodes.filter((c)=>r.has(c.id)||s.has(c.id)||a.has(c.id)).map((c)=>({id:c.id,type:c.type,title:c.title,contentRevision:c.contentRevision,text:c.text.slice(0,700)}))}}var pr=new zd({name:"PMX Canvas",version:"1.0.0"},{availableDisplayModes:["inline","fullscreen"]}),Uz=S({status:ne(),body:C(),contentType:C(),encoding:jt(["text","base64"])});Ab(async(e,t)=>{let n=typeof e==="string"?e:e instanceof URL?e.toString():e.url,o=(t?.method??(e instanceof Request?e.method:"GET")).toUpperCase();if(t?.body!==void 0&&typeof t.body!=="string")return Response.json({ok:!1,error:"Document uploads require the local PMX workbench."},{status:403});t?.signal?.throwIfAborted();let r=await pr.callServerTool({name:"pmx_workbench_request",arguments:{path:n,method:o,...t?.body===void 0?{}:{body:t.body},expectedBoardId:Pe.value}});t?.signal?.throwIfAborted();let s=Uz.parse(r._meta?.response),a=s.encoding==="base64"?Uint8Array.from(atob(s.body),(c)=>c.charCodeAt(0)):s.body;return new Response(o==="HEAD"||s.status===204?null:a,{status:s.status,headers:{"Content-Type":s.contentType}})});var Zz=S({focus:te(C())});function Wz(){let e=Zz.safeParse(gn.value);return d0({boardId:Pe.value,boardName:Ut.value.find((t)=>t.id===Pe.value)?.name??"Home",pinnedNodeIds:[...ze.value],nodes:[...D.value.values()].map((t)=>({id:t.id,type:t.type,title:typeof t.data.title==="string"?t.data.title:t.type,contentRevision:t.contentRevision??0,text:Cc(t)}))},[...Ne.value],e.success?e.data.focus:[])}function qz(){let[e,t]=I(""),[n,o]=I(0),r=L(Promise.resolve()),s=Wz(),a=JSON.stringify(s),c=L(a);c.current=a;let l=pr.getHostCapabilities(),u=Xn.value;return B(()=>{if(!u||!l?.updateModelContext||e===a)return;let p=!1,d;return r.current=r.current.then(async()=>{if(p||c.current!==a)return;if(t(""),await pr.updateModelContext({structuredContent:s}),p||c.current!==a)return;t(a)}).catch(()=>{if(!p&&c.current===a)d=setTimeout(()=>o((m)=>m+1),2000)}),()=>{p=!0,clearTimeout(d)}},[a,u,n]),i("div",{class:"pmx-host-app",children:i(u0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)}pr.ontoolresult=()=>{};pr.connect().then(async()=>{if(!pr.getHostCapabilities()?.serverTools)throw Error("This host does not support app tool calls.");if(pr.getHostCapabilities()?.downloadFile)Pb((e)=>pr.downloadFile({contents:[{type:"resource",resource:{uri:`file:///${encodeURIComponent(e.name)}`,mimeType:e.mimeType,text:e.text}}]}));await iw(),Ms(i(qz,{},void 0,!1,void 0,this),document.getElementById("app"))}).catch((e)=>{document.getElementById("app").textContent=`Could not connect PMX: ${String(e)}`});})();
|
|
7878
|
+
${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(Xo,{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 va(e,t){console.error(`[tool-rail] ${e} failed`,t)}function Zr(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"}};vn(t[e].message,t[e].placeholder).then((n)=>{if(!n)return;Pn({type:e,content:n}).catch((o)=>va(`create ${e}`,o))})}function yt({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(_e,{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 hk({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:r,onOpenPalette:s,onOpenShortcuts:a,annotationTool:c,onSetAnnotationTool:l}){let u=en.value,p=ki.value,d=Array.from(D.value.values()).filter((z)=>z.type==="trace").length,m=Je.value.size,[f,h]=I(!1),[v,w]=I(null),[g,x]=I(null),R=L(null),M=L(null),O=(z)=>(X)=>{if(v===z){w(null);return}let W=X.currentTarget.getBoundingClientRect();x({bottom:W.bottom,right:W.right}),w(z)},k=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 z=(W)=>{if(R.current&&W.target instanceof Node&&!R.current.contains(W.target))w(null)},X=(W)=>{if(W.key==="Escape")w(null)};return document.addEventListener("pointerdown",z),document.addEventListener("keydown",X),()=>{document.removeEventListener("pointerdown",z),document.removeEventListener("keydown",X)}},[v]);let N=(z)=>{cu(),document.documentElement.setAttribute("data-theme",z),Zi(),gt.value=z,Uc(z),w(null)},_=dm(gt.value),E=(z,X={})=>{ct(`/api/workbench/intent?_ts=${Date.now()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:z,payload:X})}).catch((W)=>va("sendIntent",W))};return i(_e,{children:[i("div",{class:"tool-rail",ref:R,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[i(yt,{label:"Home",ariaLabel:"PMX Canvas — Home",onClick:()=>{w(null),sn(null).catch((z)=>va("openHome",z))},children:i("span",{class:"rail-brand",children:i(dl,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Bug and feedback",menuOpen:f,onClick:()=>{w(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(yt,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>en.value="select",children:i(Gx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>en.value="pan",children:i(Vx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>en.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(yt,{label:"Markdown note",shortcut:"M",onClick:()=>void Pn({type:"markdown",title:"New note",width:520,height:360}).catch((z)=>va("create markdown",z)),children:i(Vo,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{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:()=>M.current?.click(),children:i($x,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("input",{ref:M,type:"file",hidden:!0,multiple:!0,"aria-label":"Attach files",onChange:(z)=>{let X=bt(),W=ie.value;qi(Array.from(z.currentTarget.files??[]),(X.width/2-W.x)/W.scale,(X.height/2-W.y)/W.scale),z.currentTarget.value=""}},void 0,!1,void 0,this),i(yt,{label:"Webpage",shortcut:"W",onClick:()=>Zr("webpage"),children:i(Ii,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Group",shortcut:"G",onClick:()=>void Pn({type:"group",title:"Group"}).catch((z)=>va("create group",z)),children:i(Ep,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Draw",shortcut:"A",active:c==="pen",onClick:()=>l(c==="pen"?null:"pen"),children:i(Fx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Text note",active:c==="text",onClick:()=>l(c==="text"?null:"text"),children:i(Bx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Eraser",active:c==="eraser",onClick:()=>l(c==="eraser"?null:"eraser"),children:i(Hx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-spacer"},void 0,!1,void 0,this),i(yt,{label:"Search & commands",shortcut:rt("K"),onClick:s,children:i(Wx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Arrange",detail:m>0?"graph-aware":"grid",onClick:()=>m>0?ol():nl(),children:i(wo,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),!ke()&&i(yt,{label:p?"Disable trace":"Enable trace",active:p,onClick:()=>E("trace-toggle",{enabled:!p}),children:i(Ux,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),!ke()&&(p||d>0)&&i(yt,{label:"Clear trace",onClick:()=>E("trace-clear"),children:i(Zx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:e?"Hide minimap":"Show minimap",active:e,onClick:t,children:i(cl,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(yt,{label:"Snapshots",active:n,onClick:o,btnRef:r,children:i(jx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"toolbar-menu-anchor",children:[i(yt,{label:"Theme",detail:Bi[_].label,menuOpen:v==="theme",ariaLabel:"Choose theme",active:v==="theme",onClick:O("theme"),children:er(_)==="dark"?i(Dx,{},void 0,!1,void 0,this):i(ll,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v==="theme"&&i("div",{class:"toolbar-menu",style:k,role:"menu","aria-label":"Theme",children:um.map((z)=>i("button",{type:"button",role:"menuitemradio","aria-checked":_===z,class:`toolbar-menu-item${_===z?" active":""}`,onClick:()=>N(z),children:[i("span",{class:"theme-swatch",style:{background:Bi[z].swatchBg},children:i("span",{class:"theme-swatch-dot",style:{background:Bi[z].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{children:Bi[z].label},void 0,!1,void 0,this),_===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(yt,{label:"Shortcuts",shortcut:"?",onClick:a,children:i(qx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f&&i(fk,{onClose:()=>h(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function gk({onOpenPalette:e}){let t=L(null),n=()=>{Pn({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(r)=>{if(!r||r.length===0)return;let s=Bo(),a=ie.value;await qi(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(Vo,{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:()=>Zr("webpage"),children:[i(Ii,{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:rt("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 sr(),children:[i(Ai,{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 · ",rt("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 vk="From old snapshots";function yk(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 Gm(e){return e.split("/").map((t,n,o)=>o.slice(0,n+1).join("/"))}function bk({board:e,folders:t,onClose:n}){let o=L(null),[r,s]=I(e.category??""),[a,c]=I(""),[l,u]=I(!1),[p,d]=I("");an(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=yk(m)}catch(v){d(v instanceof Error?v.message:String(v));return}if(u(!0),d(""),await Fc(e.id,{category:h}),Ut.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 xk({board:e,onClose:t}){let n=L(null),o=L(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),[w,g]=I(""),[x,R]=I(!1);return an(n,!0,{initial:o}),B(()=>{let O=!0;return Ob(e.id).then((k)=>{if(!O)return;if(!k||!Array.isArray(k.cards))return g("Could not load reusable cards. Try again.");s(k),c(new Set(k.cards.filter((N)=>N.reusable).map((N)=>N.id)))}),()=>{O=!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:(O)=>O.stopPropagation(),children:i("form",{onSubmit:async(O)=>{if(O.preventDefault(),!l.trim()||!r)return;R(!0),g("");let k=await Lb({sourceBoardId:e.id,name:l.trim(),...e.category?{category:e.category}:{},nodeIds:[...a],includeReadme:p,includeStructure:m});if(R(!1),!k)return g("Could not create the board. Try a different name.");if(h)await sn(k.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:(O)=>u(O.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!r&&!w&&i("div",{class:"board-copy-status",role:"status",children:"Loading reusable cards…"},void 0,!1,void 0,this),w&&i("div",{class:"board-copy-error",role:"alert",children:w},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((O)=>O.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((O)=>O.reusable).map((O)=>i("label",{class:"board-copy-card",children:[i("input",{type:"checkbox",checked:a.has(O.id),onChange:(k)=>{let N=new Set(a);k.currentTarget.checked?N.add(O.id):N.delete(O.id),c(N)}},void 0,!1,void 0,this),i("span",{children:[i("strong",{children:O.title||"Untitled card"},void 0,!1,void 0,this),i("small",{children:O.type},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},O.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:(O)=>f(O.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:(O)=>d(O.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:(O)=>v(O.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()||x,children:x?"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 mN(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 wk(e){return`${e} node${e!==1?"s":""}`}async function Vm(){let e=await vn("New board","Board name",{confirm:"Create"});if(e)await $b(e)}var Sk="pmx-canvas-home-collapsed";function fN(){try{let e=localStorage.getItem(Sk);if(e)return new Set(JSON.parse(e))}catch{}return new Set([vk])}function hN(e){try{localStorage.setItem(Sk,JSON.stringify([...e]))}catch{}}function _k(){let e=Ut.value,[t,n]=I(null),[o,r]=I(null),[s,a]=I(null),[c,l]=I(""),[u,p]=I([]),[d,m]=I(fN),f=L(0),h=[...new Set(e.flatMap((E)=>E.category?Gm(E.category):[]))].sort((E,z)=>E.localeCompare(z)),v=c.trim().toLocaleLowerCase(),w=e.filter((E)=>`${E.name} ${E.category??""}`.toLocaleLowerCase().includes(v)),g=new Set(w.flatMap((E)=>E.category?Gm(E.category):[])),x=e.find((E)=>E.id===o),R=e.find((E)=>E.id===s);B(()=>{let E=c.trim();if(!E){p([]);return}let z=!1,X=window.setTimeout(()=>{re("searchLibrary",`/api/canvas/search?q=${encodeURIComponent(E)}&scope=library&limit=30`,null).then((W)=>{if(!z)p(W?.results??[])})},150);return()=>{z=!0,window.clearTimeout(X)}},[c]);let M=async(E)=>{let z=++f.current;await sn(E.boardId);for(let X=0;X<40;X++){if(z!==f.current||Pe.value!==E.boardId)return;if(D.value.has(E.cardId)){pt(E.cardId);return}await new Promise((W)=>window.setTimeout(W,25))}},O=(E)=>{let z=new Set(d);if(z.has(E))z.delete(E);else z.add(E);m(z),hN(z)},k=async(E)=>{let z=await vn("Rename board","Board name",{initial:E.name,confirm:"Rename"});if(z&&z!==E.name)await Fc(E.id,{name:z})},N=(E)=>t===E.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:E.name},void 0,!1,void 0,this)," and its ",wk(E.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),Fb(E.id)},children:"Delete board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},E.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 sn(E.id),children:[i("span",{class:"home-board-name",children:E.name},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[wk(E.nodeCount)," · ",mN(E.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(E.id),children:"Move"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action","aria-haspopup":"dialog",onClick:()=>a(E.id),children:"Create from…"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>void k(E),children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>n(E.id),children:"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},E.id,!0,void 0,this),_=(E,z)=>{let X=h.filter((T)=>T.slice(0,T.lastIndexOf("/"))===E&&T.includes("/")),W=w.filter((T)=>T.category===E),J=w.filter((T)=>T.category===E||T.category?.startsWith(`${E}/`)).length,G=!!v||!d.has(E);return i("section",{class:"home-section","data-testid":"home-section","data-folder":E,"aria-label":E,children:[i("button",{type:"button",class:"home-section-head","aria-expanded":G,onClick:()=>O(E),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:E.split("/").at(-1)},void 0,!1,void 0,this),i("span",{class:"home-section-count",children:J},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G&&i("div",{class:"home-folder-children",style:{marginLeft:z<5?"14px":"0"},children:[X.filter((T)=>g.has(T)).map((T)=>_(T,z+1)),W.length>0&&i("ul",{class:"home-view-list","aria-label":`Boards in ${E}`,children:W.map(N)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},E,!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 Vm(),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:(E)=>l(E.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((E)=>i("li",{class:"home-board",children:i("button",{type:"button",class:"home-board-open",onClick:()=>void M(E),children:[i("span",{class:"home-board-name",children:E.title||E.boardTitle},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[E.boardTitle," · ",E.snippet]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},`${E.boardId}:${E.cardId}`,!1,void 0,this))},void 0,!1,void 0,this):w.length===0?i("div",{class:"home-view-empty",role:"status",children:["No boards match “",c,"”."]},void 0,!0,void 0,this):i(_e,{children:[h.filter((E)=>!E.includes("/")&&g.has(E)).map((E)=>_(E,0)),w.some((E)=>!E.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:w.filter((E)=>!E.category).map(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),x&&i(bk,{board:x,folders:h,onClose:()=>r(null)},x.id,!1,void 0,this),R&&i(xk,{board:R,onClose:()=>a(null)},R.id,!1,void 0,this)]},void 0,!0,void 0,this)}var es=K(!1);function gN(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}function kk(){let[e,t]=I(!1),[n,o]=I(!1),[r,s]=I(null),[a,c]=I(null),[l,u]=I(!1),[p,d]=I(""),m=es.value,f=Pe.value;if(B(()=>{if(!m||!f)return;let v=!0;return c(null),d(""),s(null),re("exportPreview",`/api/canvas/export/preview?board=${encodeURIComponent(f)}&includeFiles=${e}&includeDerivedText=${n}`,null).then((w)=>{if(v)s(w?.manifest??null)}),()=>{v=!1}},[m,e,n,f]),B(()=>{o(!1)},[m,f]),B(()=>{if(!m)return;let v=(w)=>{if(w.key!=="Escape")return;w.stopPropagation(),es.value=!1};return window.addEventListener("keydown",v,{capture:!0}),()=>window.removeEventListener("keydown",v,{capture:!0})},[m]),!m)return null;let h=async()=>{if(!r||r.boardId!==Pe.value)return;u(!0);let v=await re("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),v?.path&&Pe.value===r.boardId)c(v)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>es.value=!1,children:i("div",{class:"text-prompt export-dialog",role:"dialog","aria-label":"Export board","data-testid":"export-dialog",onPointerDown:(v)=>v.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(_e,{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((v)=>`${v.title} (${v.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:(v)=>o(v.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:(v)=>t(v.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((v)=>v.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 (",gN(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:ke()?i("button",{type:"button",disabled:l,onClick:async()=>{u(!0),d("");try{await Rb(a.url)}catch(v){d(v instanceof Error?v.message:"Download failed. Try again.")}finally{u(!1)}},children:l?"Downloading…":"Download"},void 0,!1,void 0,this):i(_e,{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,!1,void 0,this),ke()&&i("p",{children:"Download the HTML file to open it outside ChatGPT."},void 0,!1,void 0,this),p&&i("p",{role:"alert",children:p},void 0,!1,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:()=>es.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 h(),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 Xm({presence:e,size:t=18}){return i("span",{class:"writer-avatar",style:{background:An(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:u_(e.label)},void 0,!1,void 0,this)}function Tk(){let e=Em.value;if(St.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=Fr.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:()=>{Fr.value=!o},children:[i("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((r)=>i(Xm,{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 vN(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 yN(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function bN(){return[...lt.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function Ck(){let e=Fr.value,t=Em.value,n=ko(e?1e4:0);if(B(()=>{if(!e)return;let c=(l)=>{if(l.key!=="Escape")return;if(Gi.value)Gi.value=!1;else Fr.value=!1};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e]),!e||St.value||t.length===0)return null;let o=Cm.value,r=bN().filter((c)=>!o||(c.source??"")===o),s=or.value.filter((c)=>!o||c.sessionId===o),a=(c,l)=>i("button",{type:"button",class:`activity-filter${o===c?" is-active":""}`,style:c?{"--writer":An(c)}:void 0,"aria-pressed":o===c,onClick:()=>{Cm.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"," ",ql(yN(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:()=>{Fr.value=!1},children:i(Xe,{},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:()=>{Cr(c).then((l)=>{if(l)$r(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}=vN(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:An(c.sessionId)},children:c.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"activity-age",children:ql(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:()=>{Gi.value=!0},children:"Writers"},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{Fr.value=!1,sr()},children:["Start session ",i(Xo,{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 xN(){let e=[];if(rr.value)e.push("scoped");if(Hr.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function Ek(){let e=Gi.value,t=ko(e?1e4:0),n=L(null);if(an(n,e),!e)return null;let o=At.value.filter((a)=>a.attached),r=At.value.filter((a)=>!a.attached),s=()=>{Gi.value=!1};return i(_e,{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:ho.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(Xe,{},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(Xm,{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:xN()},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(Xm,{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"," ",ql(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 Ik(e,t){switch(e.type){case"markdown":return i(_l,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return i(tr,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return i(Bl,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return i(tr,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return i(tr,{node:e,expanded:t},void 0,!1,void 0,this);case"board":return i(ou,{node:e},void 0,!1,void 0,this);case"prompt":return i(jl,{node:e},void 0,!1,void 0,this);case"response":return i(Ul,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return i(Fl,{node:e},void 0,!1,void 0,this);case"context":return i(pl,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return i(gl,{node:e},void 0,!1,void 0,this);case"trace":return i(Zl,{node:e},void 0,!1,void 0,this);case"file":return i(hl,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return i(ml,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Dl,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return i(Hl,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return i(ua,{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 Ak(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 wN(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function SN(e,t){return e!==null&&typeof e==="object"&&e.source===In&&e.type==="presentation-exit"&&e.token===t}function _N(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function Pk(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function Rk(){let e=ot.value,t=e?D.value.get(e):void 0,[n,o]=I(!1),[r,s]=I(!1),[a,c]=I(""),l=L(null),u=L(null),p=j(()=>{s(!1),xo()},[]),d=j(()=>{c(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),s(!0)},[]),m=j((T)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:In,token:a,...T},"*")},[a]),f=j(()=>{s(!1)},[]),h=j((T)=>{if(T.key==="Escape"){T.preventDefault(),T.stopPropagation(),s(!1);return}if(T.key==="Tab"&&!Pk(T.target)){T.preventDefault(),T.stopPropagation(),u.current?.focus();return}if((T.key===" "||T.key==="Enter")&&Pk(T.target))return;if(!_N(T.key))return;T.preventDefault(),T.stopPropagation(),m({type:"presentation-key",key:T.key})},[m]),v=j((T)=>{if(T.target.classList.contains("expanded-overlay-backdrop"))xo()},[]),w=j(()=>{if(!t)return;let T=Ak(t);if(!T)return;navigator.clipboard.writeText(T).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),g=j(()=>{if(!e)return;Qn(e)},[e]);B(()=>{s(!1)},[e]),Cn(()=>{if(!r)return;let T=()=>{let be=l.current;if(!be||be.contains(document.activeElement))return;be.focus()},q=[0,50,150].map((be)=>window.setTimeout(T,be)),ae=(be)=>{if(!SN(be.data,a))return;s(!1)};return document.addEventListener("keydown",h,!0),window.addEventListener("message",ae),()=>{q.forEach((be)=>{window.clearTimeout(be)}),document.removeEventListener("keydown",h,!0),window.removeEventListener("message",ae)}},[h,a,r]);let x=L(null),R=j(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]);if(an(x,t!==void 0,{restoreTo:R}),!t)return null;let M=t.data.title||t.data.path?.split("/").pop()||$t[t.type],O=Ak(t),k=wN(O),N=e?ze.value.has(e):!1,_=O.length>0,E=Fn.value===e,z=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",X=XS(t),W=Bn(t.type),J=t.data.provenance&&typeof t.data.provenance==="object"?t.data.provenance:null,G=J?[J.sourceKind,J.sourceUri,J.syncedAt?`synced ${J.syncedAt.slice(11,16)}`:null].filter((T)=>typeof T==="string"&&T.length>0).join(" · "):null;return i("div",{class:"expanded-overlay-backdrop",onPointerDown:v,style:{pointerEvents:E?"none":"auto"},children:i("div",{ref:x,class:`expanded-overlay-panel${N?" is-pinned":""}`,role:"dialog","aria-modal":"true","aria-label":M,"data-testid":"expanded-node",children:[i("div",{class:"expanded-header",children:[i("span",{class:"expanded-kind-icon","aria-hidden":"true",children:i(W,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"expanded-title",children:M},void 0,!1,void 0,this),i("span",{class:"expanded-kind-pill",children:$t[t.type]},void 0,!1,void 0,this),i("button",{type:"button",class:`expanded-pin${N?" is-on":""}`,onClick:g,title:N?"In agent context — click to unpin":"Pin as agent context","aria-pressed":N,children:"✦"},void 0,!1,void 0,this),i("span",{class:"expanded-spacer"},void 0,!1,void 0,this),i("div",{class:"expanded-actions",children:[_&&i("button",{type:"button",class:"expanded-action-btn",onClick:w,title:"Copy content to clipboard",children:n?"Copied!":"Copy"},void 0,!1,void 0,this),El(t)&&i("button",{type:"button",class:"expanded-action-btn",onClick:()=>void Il(t),title:"Open as a full-page site in the system browser",children:["Open in tab ",i(Xo,{size:14},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&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(Xe,{},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:Ik(t,!0)},void 0,!1,void 0,this):Ik(t,!0)},void 0,!1,void 0,this),i("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:i(nu,{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:[G,k>0?`${k.toLocaleString()} word${k!==1?"s":""}`:null].filter(Boolean).join(" · ")||$t[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${E?" is-saving":""}`,children:E?"Saving edits…":"esc or click outside to close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&r&&i("div",{ref:l,class:"html-presentation-overlay",role:"dialog","aria-modal":"true","aria-label":`Present ${M}`,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(ua,{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 zk=168,Mk=112,uu=20;function Nk(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 w of r)s=Math.min(s,w.position.x),a=Math.min(a,w.position.y),c=Math.max(c,w.position.x+w.size.width),l=Math.max(l,w.position.y+w.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)-uu,minY:Math.min(a,p)-uu,maxX:Math.max(c,d)+uu,maxY:Math.max(l,m)+uu},h=f.maxX-f.minX||1,v=f.maxY-f.minY||1;return{bounds:f,scale:Math.min(zk/h,Mk/v)}}function $k({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:r}){let s=L(null),a=L(!1),c=t.value,l=e.value,u=Nk(c,l,o,r),{bounds:p,scale:d}=u,m=(_)=>(_-p.minX)*d,f=(_)=>(_-p.minY)*d,h=j((_)=>{let E=s.current;if(!E)return;let z=E.getBoundingClientRect(),X=(_.clientX-z.left)/z.width*zk,W=(_.clientY-z.top)/z.height*Mk,J=Nk(t.value,e.value,o,r),G=e.value,T=o/G.scale,q=r/G.scale,ae=X/J.scale+J.bounds.minX,be=W/J.scale+J.bounds.minY;n(-(ae-T/2)*G.scale,-(be-q/2)*G.scale)},[t,e,o,r,n]),v=j((_)=>{_.stopPropagation(),_.preventDefault(),a.current=!0,h(_);let E=(X)=>{if(a.current)h(X)},z=()=>{a.current=!1,document.removeEventListener("pointermove",E),document.removeEventListener("pointerup",z)};document.addEventListener("pointermove",E),document.addEventListener("pointerup",z)},[h]),w=Ne.value,g=ze.value,x=St.value?Gl.value:new Set,R=rr.value,M=R?Xl(R.nodeIds.map((_)=>c.get(_)).filter((_)=>_!==void 0),R.padding):null,O=At.value.map((_)=>({id:_.sessionId,phase:_.phase,worker:_.parentAgentId!=null,external:!_.attached,at:Vl(_,(E)=>c.get(E))})).filter((_)=>_.at!==null),k=-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((_)=>{let E=_.type==="group";return i("span",{class:`minimap-node${E?" is-group":""}${w.has(_.id)?" is-selected":""}${g.has(_.id)?" is-pinned":""}${x.has(_.id)?" is-agent":""}`,"data-kind":_.type,style:{left:`${m(_.position.x)}px`,top:`${f(_.position.y)}px`,width:`${Math.max(E?6:4,_.size.width*d)}px`,height:`${Math.max(E?5:3,_.size.height*d)}px`}},_.id,!1,void 0,this)}),M&&i("span",{class:"minimap-fence",style:{left:`${m(M.x)}px`,top:`${f(M.y)}px`,width:`${M.width*d}px`,height:`${M.height*d}px`}},void 0,!1,void 0,this),O.map((_)=>i("span",{class:`minimap-presence phase-${_.phase}${_.worker?" is-worker":""}${_.external?" is-external":""}`,style:{left:`${m(_.at.x)-4}px`,top:`${f(_.at.y)-4}px`,"--identity-color":An(_.id)}},_.id,!1,void 0,this)),i("span",{class:"minimap-frame",style:{left:`${m(k)}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 Ok(){let e=Ne.value.size,t=j(()=>{let c=Array.from(Ne.value);if(c.length===0)return;Yc(c),Wt()},[]),n=j(()=>{let c=Array.from(Ne.value);if(c.length===0)return;xi({title:"Group",childIds:c}),Wt()},[]),o=j(()=>{let c=Array.from(Ne.value);for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++)Er(c[l],c[u],"relation");Wt()},[]),r=j(()=>{let c=Array.from(Ne.value);for(let l of c)Uo(l);Wt()},[]);if(e===0)return null;let s=e>=2,a=!St.value&&ze.value.size>0&&!Vn.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(_e,{children:[i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Qe,{label:"Align left",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align left",onClick:()=>bp("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(Qe,{label:"Align top",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align top",onClick:()=>bp("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(Qe,{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:()=>mx(),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(Qe,{label:"Auto-arrange selection",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Auto-arrange",onClick:()=>fx(),children:i(wo,{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(Qe,{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(Qe,{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(Qe,{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(Qe,{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(Qe,{label:"Clear selection",shortcut:"Esc",side:"up",children:i("button",{type:"button",class:"selection-bar-icon",onClick:Wt,"aria-label":"Clear selection",children:i(Xe,{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 du(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 pu(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 kN={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},TN={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},Lk=[{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"}],Dk=Object.fromEntries(Lk.map((e)=>[e.id,e.hint])),CN={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 Km(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 EN({item:e}){let t=kN[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&&pt(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:TN[e.status]??t},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:Km(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function IN({gate:e,now:t}){let[n,o]=I(null),r=async(c)=>{o(c),await S_(e,c),o(null)},s=e.nodeIds[0],a=du(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&&pt(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 ",pu(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:Km(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function AN({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),__(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 PN(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 RN({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:PN(e)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function NN(){let e=rr.value,t=Ne.value.size,[n,o]=I(!1),r=(s)=>{o(!0),g_(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(_e,{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(_e,{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([...Ne.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 zN(e){if(e==="browser")return"you";return At.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function MN({entry:e}){let t=fa.value.has(e.id);return i("li",{class:`session-timeline-row tone-${CN[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:Dk[Nm(e.kind)],children:e.label},void 0,!1,void 0,this),e.who&&i("span",{class:"session-timeline-who",style:{"--identity-color":An(e.who)},children:zN(e.who)},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:Km(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 zm(e),children:[i(Cp,{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 Fk(){let[e,t]=I(!1),n=Vi.value,o=h_.value,r=Hr.value,s=v_.value,a=y_.value,c=w_.value,[l,u]=I(!1),[p,d]=I(null),m=ko();if(B(()=>{ir()},[]),!(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:nr(n),"aria-label":`Session live: ${nr(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:nr(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 Kl(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(Vs,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(NN,{},void 0,!1,void 0,this),(()=>{let h=c.find((v)=>v.undoable&&!fa.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 zm(h),children:[i(Cp,{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((O)=>O.status==="in-progress"||O.status==="todo").length,v=o.filter((O)=>O.status!=="cancelled"),w=v.filter((O)=>O.status==="done").length,g=o.length-v.length,x=r.length>0,R=l||x,M=h>0?`${h} running`:v.length>0?`${w}/${v.length} done${g>0?` · ${g} cancelled`:""}`:o.length>0?`${o.length} cancelled`:"none yet";return i(_e,{children:[i("button",{type:"button",class:"session-section-toggle","aria-expanded":R,"data-testid":"work-items-toggle",onClick:()=>u((O)=>!O),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),M]},void 0,!0,void 0,this),i("span",{class:`session-section-chevron${R?" is-open":""}`,"aria-hidden":"true",children:i(Vs,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R&&(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((O)=>i(IN,{gate:O,now:m},O.id,!1,void 0,this)),s.map((O)=>i(AN,{gate:O},O.id,!1,void 0,this)),a.map((O)=>i(RN,{gate:O},O.id,!1,void 0,this)),o.map((O)=>i(EN,{item:O},O.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:Lk.map((h)=>i("button",{type:"button",class:`activity-filter${Br.value===h.id?" is-active":""}`,"aria-pressed":Br.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:()=>{Br.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:Dk[p??Br.value]},void 0,!1,void 0,this),c.length===0?i("div",{class:"session-empty",children:Br.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(MN,{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 Jm(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)}}var Hk=(e)=>e.map((t)=>t.title).join(", ");function $N({context:e,label:t}){let o=[{key:"read",name:"Read",glyph:"eye"},{key:"pinned",name:"Pinned",glyph:"pin"},{key:"created",name:"Created",glyph:"spark"},{key:"edited",name:"Edited",glyph:"pen"}].filter((s)=>e[s.key].length>0);if(o.length===0&&e.changedSinceRead.length===0)return null;let r=ar.value!==null;return i("div",{class:"session-receipt-context","data-testid":"session-receipt-context",children:[e.changedSinceRead.length>0&&i("div",{class:"session-receipt-warn",children:[i("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:i("path",{d:eu.warn},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{children:[Hk(e.changedSinceRead)," changed after ",t," read"," ",e.changedSinceRead.length===1?"it":"them","."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),o.map((s)=>i("div",{class:"session-receipt-context-row","data-row":s.key,children:[i("div",{class:"session-receipt-context-head",children:[s.glyph==="pin"?i(ul,{},void 0,!1,void 0,this):i("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:i("path",{d:eu[s.glyph]},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"session-receipt-context-name",children:s.name},void 0,!1,void 0,this),i("span",{class:"session-receipt-context-count",children:e[s.key].length},void 0,!1,void 0,this),s.key==="pinned"&&i("button",{type:"button",class:"session-receipt-mini",onClick:()=>{for(let a of e.pinned)Qn(a.id)},children:"Unpin"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-context-items",children:s.key==="pinned"?e.pinned.map((a)=>a.reason?`${a.title} — “${a.reason}”`:a.title).join("; "):Hk(e[s.key])},void 0,!1,void 0,this)]},s.key,!0,void 0,this)),i("button",{type:"button",role:"switch","aria-checked":r,class:`session-receipt-lens${r?" is-on":""}`,onClick:()=>$m(!r),children:[i("span",{class:"session-receipt-lens-track","aria-hidden":"true",children:i("span",{class:"session-receipt-lens-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Dim untouched nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Bk({onOpenSnapshots:e}){let t=Xi.value,[n,o]=I(null),[r,s]=I(!1);if(B(()=>o(null),[t]),!t)return null;let a=async()=>{if(!t.snapshot)return;s(!0);try{let u=await ct(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(u.ok){let p=await u.json();o(Jm(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.sessions>1?`${t.sessions} sessions ended`: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:Jl,"aria-label":"Dismiss receipt",children:i(Xe,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.sessions>1&&i("div",{class:"session-receipt-who",children:t.labels.join(", ")},void 0,!1,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($N,{context:t.context,label:t.labels.join(", ")},void 0,!1,void 0,this),i("div",{class:"session-receipt-note",children:t.sessions>1?"History has each session’s diff and the snapshot from before it.":t.snapshot?"A snapshot of the board from before this session is saved — restore it to undo the session.":t.context.created.length===0&&t.context.edited.length===0?"The board itself did not change — nothing to restore.":"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 ON=[{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:rt("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:rt("0"),desc:"Reset viewport to origin"},{keys:`${rt("+")} / ${rt("−")}`,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:Js?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:Js?"⌘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 jk({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:ON.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:ke()&&n.desc.startsWith("Undo / redo")?"Undo / redo — available in the local workbench only":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 Uk="Before session · ";function Zk(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 LN(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 mu(e){if(!e.startsWith(Uk))return null;let t=e.slice(Uk.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function Wk({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,w]=I({}),g=L(null),x=L(null);B(()=>{if(!e)return;a(!0),Kb().then((_)=>{r(_),a(!1)})},[e]),B(()=>{if(e)setTimeout(()=>x.current?.focus(),50)},[e]),B(()=>{if(!e)return;let _=(E)=>{let z=g.current,X=n.current;if(z&&!z.contains(E.target)&&X&&!X.contains(E.target))t()};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[e,t]),B(()=>{if(!e)return;let _=(E)=>{if(E.key==="Escape")t()};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[e,t]);let R=j(async()=>{let _=d.trim();if(!_)return;l(!0);let E=await Jb(_);if(l(!1),E.ok&&E.snapshot)r((z)=>[E.snapshot,...z]),m("")},[d]),M=j(async(_)=>{h(null),p(_);let E=await Yb(_);if(p(null),E.ok)t()},[t]),O=j(async(_)=>{if((await Qb(_)).ok)r((z)=>z.filter((X)=>X.id!==_));h(null)},[]),k=j(async(_)=>{w((z)=>({...z,[_]:"loading"}));let E=await re("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(_)}/diff`,{});w((z)=>({...z,[_]:Jm(E.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let N=(_,E)=>f?.id===_.id?i(_e,{children:[i("button",{type:"button",class:`snapshot-action-btn ${f.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>f.action==="delete"?O(_.id):M(_.id),title:f.action==="delete"?"Confirm delete":"Confirm restore",disabled:u!==null,children:f.action==="delete"?"Delete":u===_.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(_e,{children:[i("button",{type:"button",class:"snapshot-action-btn snapshot-action-restore",onClick:()=>h({id:_.id,action:"restore"}),title:ke()?"Restore this snapshot — replaces the current canvas":"Restore this snapshot — replaces the current canvas (undoable)",disabled:u!==null,children:u===_.id?"Restoring…":E},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn snapshot-action-delete",onClick:()=>h({id:_.id,action:"delete"}),title:"Delete this snapshot","aria-label":"Delete snapshot",disabled:u!==null,children:i(Xe,{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(Xe,{},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:x,type:"text",class:"snapshot-name-input",value:d,onInput:(_)=>m(_.target.value),onKeyDown:(_)=>{if(_.key==="Enter")R()},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:R,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:ke()?"Restoring replaces the current canvas. Save a snapshot first to keep your current state.":"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((_)=>mu(_.name)===null),...o.some((_)=>mu(_.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((_)=>mu(_.name)!==null)].map((_)=>{if(_.id==="__sessions-header__")return i("div",{class:"snapshot-section-header","data-testid":"history-sessions-header",children:"Sessions"},_.id,!1,void 0,this);let E=mu(_.name),z=v[_.id];if(E!==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 — ",E]},void 0,!0,void 0,this),i("span",{class:"snapshot-item-time",children:Zk(_.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:["snapshot at session start · ",_.nodeCount," node",_.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 k(_.id),children:z==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),N(_,"Restore pre-state")]},void 0,!0,void 0,this)]},_.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:_.name},void 0,!1,void 0,this),i("span",{class:"snapshot-item-time",children:Zk(_.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:[_.nodeCount," node",_.nodeCount!==1?"s":"",_.edgeCount>0?` · ${_.edgeCount} edge${_.edgeCount!==1?"s":""}`:""," · ",LN(_.createdAt)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-actions",children:N(_,"Restore")},void 0,!1,void 0,this)]},_.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 DN=8;function FN({children:e}){let t=Ze(()=>document.createElement("div"),[]);return Cn(()=>(document.body.appendChild(t),()=>{Ms(null,t),t.remove()}),[t]),Cn(()=>Ms(e,t),[e,t]),null}function qk({fallbackName:e}){let[t,n]=I(!1),o=L(null),r=L(null),s=L(null);Cn(()=>{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=Hc(),c=!Xn.value?e:a?a.name:"Home",l=Ut.value.filter((d)=>d.id!==Pe.value).slice(0,DN),u=r.current?.getBoundingClientRect(),p=(d)=>{n(!1),sn(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(sl,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&u&&i(FN,{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(dl,{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),Vm()},children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:i(Rx,{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(wo,{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 Gk=3,Vk={"waiting-approval":0,thinking:1,tooling:2,idle:3};function HN(){let e=p_.value;if(e.length===0)return null;let t=e.filter((c)=>!c.parentAgentId||!e.some((l)=>l.sessionId!==c.sessionId&&!l.parentAgentId&&(l.sessionId===c.parentAgentId||l.source===c.parentAgentId))),n=[...t].sort((c,l)=>(Vk[c.phase]??4)-(Vk[l.phase]??4)),o=n.slice(0,Gk),r=n.slice(Gk),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(_e,{children:[i("span",{class:"agent-chips",children:o.map((c)=>{let l=c.parentAgentId?0:At.value.filter((u)=>u.parentAgentId!=null&&(u.parentAgentId===c.sessionId||u.parentAgentId===c.source)).length;return i(Qe,{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":An(c.sessionId)},children:[i("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"agent-chip-label",children:nr(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(),Kl({source:c.source,agentId:c.agentId})},children:i(Xe,{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(Qe,{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 BN(){let e=Hr.value.length,t=Vi.value!==null&&e>0,n=ko(t?1000:0);if(!t)return null;let o=Hr.value.map((r)=>du(r,n)).filter((r)=>r!==null).sort((r,s)=>r-s)[0];return i(Qe,{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&&` · ${pu(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function jN(e){if(e>0.9)return"danger";if(e>=0.7)return"warn";return"ok"}function ya(e){return e>=1000?`${(e/1000).toFixed(e>=1e4?0:1)}k`:String(e)}function UN(){let e=Vi.value;if(!e)return null;let t=Tm.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:`${ya(n.used)} of ${ya(n.total)} tokens of the agent's actual context window are used. Your ✦-pinned nodes account for ≈ ${ya(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: ≈ ${ya(t.used)} of a ${ya(t.total)}-token budget. When the agent's host reports its real context window, this meter switches to showing that instead.`};return i(Qe,{label:c.label,body:c.body,tapToOpen:!0,children:i("span",{class:`context-budget tone-${jN(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 ZN(){let[e,t]=I(!1);if(Vi.value)return null;return i(Qe,{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),sr().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 Xk(){let e=hn.value,t=Qt.value,n=ie.value,o=D.value.size,r=Je.value.size,s=ki.value,a=Array.from(D.value.values()).filter((f)=>f.type==="trace").length,[c,l]=I("");B(()=>{let f=!1;return ct("/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=Bm.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=bt();Ei(f.width,f.height)};return i("div",{class:"top-bar",children:[i(Qe,{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(qk,{fallbackName:c||"PMX Canvas"},void 0,!1,void 0,this),i("span",{class:"top-bar-meta hud-collapsible-text",children:ho.value?ho.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(HN,{},void 0,!1,void 0,this),i(BN,{},void 0,!1,void 0,this),i(UN,{},void 0,!1,void 0,this),i(Tk,{},void 0,!1,void 0,this),!ke()&&i(ZN,{},void 0,!1,void 0,this),i("div",{class:"top-bar-sep"},void 0,!1,void 0,this),Pe.value&&i(Qe,{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:()=>{es.value=!0},children:"Export"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Pe.value&&i(Qe,{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:()=>{Hn.value=!0},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Qe,{label:"Zoom out",shortcut:rt("−"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>Ci(0.8),"aria-label":"Zoom out",children:i(Lx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Qe,{label:"Reset zoom",shortcut:rt("0"),children:i("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>qo({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(Qe,{label:"Zoom in",shortcut:rt("+"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>Ci(1.25),"aria-label":"Zoom in",children:i(Ox,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Qe,{label:"Fit all",shortcut:"F",align:"end",children:i("button",{type:"button",class:"top-bar-btn",onClick:m,"aria-label":"Fit canvas",children:i(al,{},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 cr={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 ba(e,t,n,o={}){let r=cr[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 Wr=null,Sa=null,fu=0,lr=null,WN=3000,qN=2000,Kk=5000,xa=!1,To=null,ts=null,dr=0,ur=null;function GN(){if(ke())return"poll";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 ns=new Map;function _a(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 gu(e){if(!Sa)return e;let t=Sa.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 ka(e,t,n){return gu(ba(e,t,n))}function VN(){return Ll([...D.value.values()],cr.markdown.w,cr.markdown.h)}function os(){if(!D.value.has("status-main"))vo(ka("status-main","status",{phase:"idle",message:"",elapsed:0}))}function XN(e,t){let n=`md-${_a(e)}`;if(D.value.get(n))ve(n,{path:e,title:t}),qe.value=n;else{let r=VN(),s=ka(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=r,vo(s),pt(n)}}function KN(e){if(D.value.get("context-main"))ve("context-main",{cards:e});else if(e.length>0){let o=ka("context-main","context",{cards:e});vo(o)}}function JN(e){let t=e.url,n=`mcp-${_a(t)}`;if(D.value.get(n))ve(n,e);else vo(ka(n,"mcp-app",e)),pt(n)}function YN(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(D.value.get(o)){ve(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[w,g]of D.value.entries())if(g.type==="mcp-app"&&g.data.mode==="ext-app"&&g.data.serverName===s&&g.data.toolName===a&&!g.data.toolResult){ve(w,{...e});return}}let{_x:c,_y:l,_width:u,_height:p}=e,d=cr["mcp-app"],m=u??d.w,f=p??d.h,h=c===void 0||l===void 0?Ll([...D.value.values()],m,f):null,v=gu(ba(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}}));vo(v),pt(o,{recordHistory:!1})}function QN(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(D.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&D.value.has(n))return n;for(let[o,r]of D.value.entries())if(r.type==="mcp-app"&&r.data.mode==="ext-app"&&r.data.toolCallId===e)return o;return null}function n0(e){let t=typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null;if(t&&D.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return QN(e.toolCallId)}function o0(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,r]of D.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 r0(e){if(D.value.get("ledger-main"))ve("ledger-main",e);else{let o=ka("ledger-main","ledger",e);o.collapsed=!0,vo(o)}}function tf(e){if(!aa(e))return;if(document.documentElement.setAttribute("data-theme",e),Zi(),gt.value!==e)gt.value=e}function ez(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 tz(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function nf(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 i0(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 nz(e){let t=nf(e),n=i0(e);return t&&n?{...t,...n}:null}function oz(e){if(typeof e.id!=="string"||!e.id)return null;if(!ez(e.type))return null;let t=nf(e.position),n=i0(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,contentRevision:typeof e.contentRevision==="number"?e.contentRevision:0,...Jk(e.createdBy)?{createdBy:e.createdBy}:{},...Jk(e.lastEditedBy)?{lastEditedBy:e.lastEditedBy}:{},data:o}}function Jk(e){if(!e||typeof e!=="object")return!1;let t=e;return typeof t.actor==="string"&&typeof t.source==="string"}function rz(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(!tz(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 iz(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)=>nf(o)).filter((o)=>o!==null),n=nz(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 Yk="pmx-canvas-version-reload";function sz(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(Yk)===r)return;window.sessionStorage.setItem(Yk,r)}catch{return}window.location.reload()}function az(e){let t=or.value[0]?.id;if(Im(e),St.value&&or.value[0]?.id!==t)ir()}function cz(e){T_(e)}var Qk=null,wa=0,Ym=0,Qm=0;function lz(e){sm(e)}function uz(){let e=++wa;Sa=null,Qt.value=!1,Pl(),cx(),$c(),Jl(),Om({}),gn.value=null,of();let t=Ym,n=Qm;jb().then((o)=>{if(e===wa&&t===Ym)s0({layout:o})}),re("fetchPinnedContext","/api/canvas/pinned-context",{}).then((o)=>{if(e===wa&&n===Qm)a0({nodeIds:o.nodeIds})})}Mb(uz);function dz(e){if(ho.value=e.sessionId||"",hn.value="connected",lp().then(Us),Ar.value+=1,sz(e.version,e.bundleStamp),qb().then(Im),Yl(),Qk?.(),!Bc&&!ke())Qk=bS();if(re("fetchHumanPresence","/api/canvas/human-presence",null).then(sm),of().then(()=>{if(St.value)ir()}),typeof e.theme==="string"&&!jm())tf(e.theme);if(e.ledgerSummary)r0(e.ledgerSummary)}function pz(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(XN(t,n),e.ledgerSummary)r0(e.ledgerSummary)}function mz(e){os(),ve("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function fz(e){os(),ve("status-main",{phase:e.phase,detail:e.detail})}function hz(e){let t=e.cards??[];KN(t)}function gz(e){if(typeof e.url==="string"&&e.url)JN({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function vz(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let r=`mcp-${_a(o)}`;if(D.value.has(r))ve(r,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function yz(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${_a(e.url)}`;if(D.value.has(t))ve(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function bz(e){let n=D.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);ve("context-main",{auxTabs:o})}function xz(e){if(D.value.has("context-main"))if(e.mode==="all")ve("context-main",{auxTabs:[]});else{let o=D.value.get("context-main");if(!o)return;let r=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);ve("context-main",{auxTabs:r})}}function wz(e){os(),ve("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function Sz(e){os(),ve("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function _z(e){os(),ve("status-main",{activeTool:null})}function kz(e){if(e.state==="active"&&e.path){let n=`md-${_a(e.path)}`;if(D.value.has(n))ve(n,{reviewActive:!0})}}function Tz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;YN({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 Cz(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=n0(e)??o0(e.serverName,e.toolName);if(!t)return;if(D.value.has(t))ve(t,{html:e.html})}function Ez(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=n0(e)??o0(e.serverName,e.toolName);if(!t)return;if(D.value.has(t)){if(e.success===!1){Wo(t);return}ve(t,{toolResult:vm({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 Iz(e){os(),ve("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function Az(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:r,contextNodeIds:s}=e;if(e.threadNodeId&&D.value.has(e.threadNodeId)){let a=e.threadNodeId,c=D.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"});ve(a,{turns:l,threadStatus:"pending"});return}if(!D.value.has(t)){let a=o??cr.prompt;vo(gu(ba(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}}))),pt(t)}if(r&&D.value.has(r))Si({id:`edge-${r}-${t}`,from:r,to:t,type:"flow",style:"dashed"})}function Pz(e){let{nodeId:t,status:n}=e;if(t&&D.value.has(t))ve(t,{status:n})}function Rz(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?D.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){ns.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),ve(n,{turns:s,threadStatus:"streaming",_activeResponseId:t}),pt(n);return}let r=o?{x:o.position.x,y:o.position.y+o.size.height+24}:{x:cr.response.x,y:cr.response.y};if(!D.value.has(t))vo(gu(ba(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:r})));if(n)Si({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});pt(t)}function Nz(e){let t=e.responseNodeId;if(!t)return;let n=ns.get(t);if(n){let o=D.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";ve(n,{turns:r,threadStatus:"streaming"})}return}if(!D.value.has(t))return;ve(t,{content:e.content,status:"streaming"})}function zz(e){let t=e.responseNodeId;if(!t)return;let n=ns.get(t);if(n){let s=D.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";ve(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}ns.delete(t);return}if(!D.value.has(t))return;ve(t,{content:e.content,status:"complete"});let r=D.value.get(t)?.data.promptNodeId;if(r){let s=`edge-${r}-${t}`,a=Je.value.get(s);if(a)vx(s),Si({...a,animated:!1})}}function s0(e){let t=e.layout;if(!t?.nodes)return;Ym+=1;let n=!Qt.value;Qt.value=!0;let o=t.nodes.map(oz).filter((c)=>c!==null),r=Array.isArray(t.edges)?t.edges.map(rz).filter((c)=>c!==null):Array.from(Je.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(iz).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)bo();_x({...a?{viewport:a}:{},nodes:o,edges:r,...s?{annotations:s}:{}},{applyViewport:n}),ap({event:"canvas-layout-update",data:e})}function Mz(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function $z(e){if(_p())return;let t=e.nodeId;if(t&&D.value.has(t)){if(e.noPan===!0){yo(t);return}pt(t)}}function Oz(e){if(_p())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;bo(),xx({x:n,y:o,scale:r})}function Lz(e){if(D.value.get("context-main"))ve("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function Dz(e){ki.value=e.enabled===!0}function Fz(e){if(typeof e.theme==="string"&&!jm())tf(e.theme)}function a0(e){Qm+=1;let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];gx(t),ap({event:"context-pins-changed",data:e}),Yl()}function Hz(){Yl()}var hu=null,ef=0;async function of(){let e=++ef,t=wa,n=await Wb();if(e===ef&&t===wa)gn.value=n}function e0(){if(hu)clearTimeout(hu);ef+=1,hu=setTimeout(()=>{if(hu=null,of(),St.value)ir()},150)}function Bz(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;dS(t)}function jz(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)mS(t,typeof e.nodeId==="string"?e.nodeId:void 0);else im(t)}var c0={connected:dz,"workbench-open":pz,"canvas-status":mz,"execution-phase":fz,"context-cards":hz,"mcp-app-candidate":gz,"mcp-app-host-snapshot":vz,"mcp-app-host-fallback":yz,"aux-open":bz,"aux-close":xz,"assistant-complete":wz,"tool-start":Sz,"tool-complete":_z,"review-state":kz,"subagent-status":Iz,"ext-app-open":Tz,"ext-app-update":Cz,"ext-app-result":Ez,"context-pins-changed":a0,"context-status-changed":Hz,"boards-changed":kr,"canvas-layout-update":s0,"canvas-focus-node":$z,"canvas-viewport-update":Oz,"context-usage":Lz,"trace-state":Dz,"theme-changed":Fz,"canvas-prompt-created":Az,"canvas-prompt-status":Pz,"canvas-response-start":Rz,"canvas-response-delta":Nz,"canvas-response-complete":zz,"ax-state-changed":e0,"ax-event-created":e0,"ax-intent":Bz,"ax-intent-clear":jz,"agent-presence":az,"human-presence":lz,"agent-session-ended":cz};function l0(e,t){let n=c0[e];if(!n)return;let o=n;try{o(t)}catch(r){console.warn(`[sse-bridge] Handler for "${e}" failed:`,r)}}function t0(){xa=!0,dr+=1;let e=dr;hn.value="connecting";let t=null,n=!1,o=async()=>{if(e!==dr)return;try{let r=new URLSearchParams;if(ts!==null)r.set("since",String(ts));let s=ho.value;if(s)r.set("session",s);let a=r.toString(),c=await ct(`/api/workbench/poll${a?`?${a}`:""}`);if(e!==dr)return;if(!c.ok)throw Error(`poll failed with HTTP ${c.status}`);let l=await c.json();if(e!==dr)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){ts=null,To=setTimeout(()=>void o(),0);return}if(l.snapshot&&n)Sa=Sp(),Qt.value=!1,$c(),Pl(),ns.clear();for(let p of l.events)l0(p.event,p.payload);n=!0,ts=l.seq,Pr.value=0,Rr.value=0,hn.value="connected",To=setTimeout(()=>void o(),qN)}catch(r){if(e!==dr)return;console.warn("[sse-bridge] poll transport error:",r),hn.value="disconnected",Pr.value+=1,Rr.value=Kk,To=setTimeout(()=>void o(),Kk)}};return o(),()=>{if(dr+=1,xa=!1,ts=null,To)clearTimeout(To),To=null}}function rf(){if(ak(tf),Sa=Sp(),Qt.value=!1,$c(),Pl(),ns.clear(),lr)clearTimeout(lr),lr=null;let e=GN();if(e==="poll"||xa)return t0();let t=ho.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";hn.value="connecting";let o=new EventSource(n);Wr=o;let r=!1;if(ur)clearTimeout(ur);if(ur=null,e!=="sse")ur=setTimeout(()=>{if(ur=null,r||Wr!==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(),Wr=null,t0()},WN);for(let[s]of Object.entries(c0))o.addEventListener(s,(a)=>{r=!0;try{l0(s,JSON.parse(a.data))}catch(c){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,c)}});return o.onopen=()=>{if(Wr!==o)return;fu=0,Pr.value=0,Rr.value=0,hn.value="connected"},o.onerror=()=>{if(Wr!==o)return;hn.value="disconnected",o.close(),Wr=null,fu+=1;let s=Mz(fu);Pr.value=fu,Rr.value=s,lr=setTimeout(()=>{lr=null,rf()},s)},()=>{if(lr)clearTimeout(lr),lr=null;if(ur)clearTimeout(ur),ur=null;if(xa){if(dr+=1,xa=!1,ts=null,To)clearTimeout(To),To=null}o.close(),Wr=null}}function qr(e,t){console.error(`[app] ${e} failed`,t)}function u0(){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=L(null),{menu:f,openNodeMenu:h,openCanvasMenu:v,openEdgeMenu:w,closeMenu:g}=uk(),x=Qt.value,R=Xn.value&&Pe.value===null,M=St.value,O=j(()=>t((W)=>!W),[]),k=j(()=>o((W)=>!W),[]),N=j(()=>o(!1),[]),_=j((W)=>d(W),[]),E=j((W,J)=>{qo({x:W,y:J,scale:ie.value.scale},200)},[]);B(()=>rf(),[]),B(()=>{let W=()=>c(!0);return window.addEventListener("pmx-open-board-link",W),()=>window.removeEventListener("pmx-open-board-link",W)},[]),B(()=>{let W=null,J=()=>{if(W!==null)window.clearTimeout(W);W=window.setTimeout(()=>{W=null,Us()},400)};return window.addEventListener("resize",J),()=>{if(W!==null)window.clearTimeout(W);window.removeEventListener("resize",J)}},[]),B(()=>{let W=(T)=>{let q=(T.metaKey||T.ctrlKey)&&!T.altKey;if(q&&T.key==="k"){T.preventDefault(),s((pe)=>!pe);return}if(T.key==="Escape"&&p){T.preventDefault(),d(null);return}if(T.key==="Escape"&&ot.value&&!Fn.value){T.preventDefault(),xo();return}if(T.key==="Escape"&&r){T.preventDefault(),s(!1);return}if(T.key==="Escape"&&l){T.preventDefault(),u(!1);return}let ae=T.target,be=ae?.tagName;if(be==="INPUT"||be==="TEXTAREA"||ae?.isContentEditable)return;if(T.key===" "&&!T.repeat&&!q){T.preventDefault(),qs.value=!0;return}if(T.key==="?"||T.key==="/"&&T.shiftKey){T.preventDefault(),u((pe)=>!pe);return}if(q&&(T.key==="z"||T.key==="Z"))T.preventDefault(),Mm(T.shiftKey);else if(q&&(T.key==="y"||T.key==="Y"))T.preventDefault(),Mm(!0);else if(q&&T.key==="0")T.preventDefault(),qo({x:0,y:0,scale:1},250);else if(q&&(T.key==="="||T.key==="+"))T.preventDefault(),Ci(1.25);else if(q&&T.key==="-")T.preventDefault(),Ci(0.8);else if(T.key==="Escape"){if(Ne.value.size>0||Yn.value!==null){Wt();return}qe.value=null,g()}else if(T.key==="Tab")T.preventDefault(),Tx(T.shiftKey?-1:1);else if(T.key==="Delete"||T.key==="Backspace"){if(Yn.value!==null){let Me=Yn.value;T.preventDefault(),Yn.value=null,Xc(Me).catch((Te)=>qr("delete-edge",Te));return}let pe=Ne.value.size>0?[...Ne.value]:qe.value?[qe.value]:[];if(pe.length===0)return;T.preventDefault();for(let Me of pe)Uo(Me).catch((Te)=>qr("delete",Te));Wt(),qe.value=null}else if(qe.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(T.key)){T.preventDefault();let pe=T.key.replace("Arrow","").toLowerCase();Cx(pe)}else if(!q&&!T.altKey){let pe=T.key.toLowerCase();if(pe==="v"&&!T.shiftKey)en.value="select";else if(pe==="c"&&!T.shiftKey&&!q)T.preventDefault(),en.value=en.value==="connect"?"select":"connect";else if(pe==="m"&&!T.shiftKey)T.preventDefault(),Pn({type:"markdown",title:"New note",width:520,height:360}).catch((Me)=>qr("create markdown",Me));else if(pe==="a"&&!T.shiftKey)T.preventDefault(),d((Me)=>Me==="pen"?null:"pen");else if(pe==="g"&&!T.shiftKey){T.preventDefault();let Me=Array.from(Ne.value);if(Me.length>=2)xi({title:"Group",childIds:Me}).catch((Te)=>qr("group selection",Te)),Wt();else Pn({type:"group",title:"Group"}).catch((Te)=>qr("create group",Te))}else if(pe==="g"&&T.shiftKey){T.preventDefault();for(let Me of px())Wo(Me),wi(Me).catch((Te)=>qr("ungroup",Te));Wt()}else if(pe==="i"&&!T.shiftKey)T.preventDefault(),Zr("image");else if(pe==="w"&&!T.shiftKey)T.preventDefault(),Zr("webpage");else if(pe==="h"&&!T.shiftKey)T.preventDefault(),Pn({type:"html",title:"HTML surface"}).catch((Me)=>qr("create html",Me));else if(pe==="f"&&T.shiftKey)T.preventDefault(),Zr("file");else if(pe==="f"&&!T.shiftKey){T.preventDefault();let Me=bt();Ei(Me.width,Me.height)}}},J=(T)=>{if(T.key===" ")qs.value=!1},G=()=>{qs.value=!1};return document.addEventListener("keydown",W),document.addEventListener("keyup",J),window.addEventListener("blur",G),()=>{document.removeEventListener("keydown",W),document.removeEventListener("keyup",J),window.removeEventListener("blur",G)}},[p,g,r,l]),B(()=>{let W=window.setTimeout(()=>void Us(),250);return()=>window.clearTimeout(W)},[M]),B(()=>{if(!x)return;let W=window.__pmxCanvasBootstrapReady;if(typeof W==="function")W()},[x]);let z=Array.from(D.value.values()),X=bt();return i("div",{class:`app-shell${Hn.value?" is-presenting":""}`,"data-session-active":M?"true":"false",children:[i(Ax,{},void 0,!1,void 0,this),i(hk,{minimapVisible:e,onToggleMinimap:O,snapshotOpen:n,onToggleSnapshot:k,snapshotBtnRef:m,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>u((W)=>!W),annotationTool:p,onSetAnnotationTool:_},void 0,!1,void 0,this),i("div",{class:"app-main",children:[i(Xk,{},void 0,!1,void 0,this),i(rk,{},void 0,!1,void 0,this),i("div",{class:"canvas-region",ref:(W)=>rb(W),children:[i(nk,{onNodeContextMenu:h,onCanvasContextMenu:v,onEdgeContextMenu:w,annotationMode:p!==null,annotationTool:p},void 0,!1,void 0,this),i(Kx,{},void 0,!1,void 0,this),i(Xx,{},void 0,!1,void 0,this),i(Ck,{},void 0,!1,void 0,this),i(Ek,{},void 0,!1,void 0,this),R?i(_k,{},void 0,!1,void 0,this):x&&z.length===0&<.value.size===0&&i(gk,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),Ne.value.size>0&&i(Ok,{},void 0,!1,void 0,this),M&&!ke()?i(ok,{},void 0,!1,void 0,this):ze.value.size>0&&i(mk,{},void 0,!1,void 0,this),i(Bk,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),i(Yx,{},void 0,!1,void 0,this),i(kk,{},void 0,!1,void 0,this),ot.value&&i(Rk,{},void 0,!1,void 0,this),i(Wk,{open:n,onClose:N,anchorRef:m},void 0,!1,void 0,this),e&&!R&&i($k,{viewport:ie,nodes:D,edges:Je,onNavigate:E,containerWidth:X.width,containerHeight:X.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M&&i(Fk,{},void 0,!1,void 0,this),f&&i(dk,{menu:f,onClose:g},void 0,!1,void 0,this),r&&i(ck,{onClose:()=>s(!1),onToggleMinimap:O},void 0,!1,void 0,this),a&&i(lk,{onClose:()=>c(!1)},void 0,!1,void 0,this),l&&i(jk,{onClose:()=>u(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Uz=S({x:ne(),y:ne()}),y9=S({boardId:C().nullable(),boardName:C(),boards:te(S({id:C(),name:C()})),revision:C(),nodes:te(S({id:C(),type:C(),title:C(),text:C(),contentRevision:ne().int().nonnegative(),editableContent:C().optional(),position:Uz,size:S({width:ne(),height:ne()}),image:C().optional()})),edges:te(S({id:C(),from:C(),to:C(),label:C()})),pinnedNodeIds:te(C())});function d0(e,t,n=[]){let o=new Set(e.nodes.map((c)=>c.id)),r=new Set(t.filter((c)=>o.has(c)).slice(0,20)),s=new Set(e.pinnedNodeIds.filter((c)=>o.has(c)).slice(0,20)),a=new Set(n.filter((c)=>o.has(c)).slice(0,20));return{boardId:e.boardId,boardName:e.boardName,selectedNodeIds:[...r],focusedNodeIds:[...a],pinnedNodeIds:[...s],nodes:e.nodes.filter((c)=>r.has(c.id)||s.has(c.id)||a.has(c.id)).map((c)=>({id:c.id,type:c.type,title:c.title,contentRevision:c.contentRevision,text:c.text.slice(0,700)}))}}var pr=new zd({name:"PMX Canvas",version:"1.0.0"},{availableDisplayModes:["inline","fullscreen"]}),Zz=S({status:ne(),body:C(),contentType:C(),encoding:jt(["text","base64"])});Ab(async(e,t)=>{let n=typeof e==="string"?e:e instanceof URL?e.toString():e.url,o=(t?.method??(e instanceof Request?e.method:"GET")).toUpperCase();if(t?.body!==void 0&&typeof t.body!=="string")return Response.json({ok:!1,error:"Document uploads require the local PMX workbench."},{status:403});t?.signal?.throwIfAborted();let r=await pr.callServerTool({name:"pmx_workbench_request",arguments:{path:n,method:o,...t?.body===void 0?{}:{body:t.body},expectedBoardId:Pe.value}});t?.signal?.throwIfAborted();let s=Zz.parse(r._meta?.response),a=s.encoding==="base64"?Uint8Array.from(atob(s.body),(c)=>c.charCodeAt(0)):s.body;return new Response(o==="HEAD"||s.status===204?null:a,{status:s.status,headers:{"Content-Type":s.contentType}})});var Wz=S({focus:te(C())});function qz(){let e=Wz.safeParse(gn.value);return d0({boardId:Pe.value,boardName:Ut.value.find((t)=>t.id===Pe.value)?.name??"Home",pinnedNodeIds:[...ze.value],nodes:[...D.value.values()].map((t)=>({id:t.id,type:t.type,title:typeof t.data.title==="string"?t.data.title:t.type,contentRevision:t.contentRevision??0,text:Cc(t)}))},[...Ne.value],e.success?e.data.focus:[])}function Gz(){let[e,t]=I(""),[n,o]=I(0),r=L(Promise.resolve()),s=qz(),a=JSON.stringify(s),c=L(a);c.current=a;let l=pr.getHostCapabilities(),u=Xn.value;return B(()=>{if(!u||!l?.updateModelContext||e===a)return;let p=!1,d;return r.current=r.current.then(async()=>{if(p||c.current!==a)return;if(t(""),await pr.updateModelContext({structuredContent:s}),p||c.current!==a)return;t(a)}).catch(()=>{if(!p&&c.current===a)d=setTimeout(()=>o((m)=>m+1),2000)}),()=>{p=!0,clearTimeout(d)}},[a,u,n]),i("div",{class:"pmx-host-app",children:i(u0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)}pr.ontoolresult=()=>{};pr.connect().then(async()=>{if(!pr.getHostCapabilities()?.serverTools)throw Error("This host does not support app tool calls.");if(pr.getHostCapabilities()?.downloadFile)Pb((e)=>pr.downloadFile({contents:[{type:"resource",resource:{uri:`file:///${encodeURIComponent(e.name)}`,mimeType:e.mimeType,text:e.text}}]}));await iw(),Ms(i(Gz,{},void 0,!1,void 0,this),document.getElementById("app"))}).catch((e)=>{document.getElementById("app").textContent=`Could not connect PMX: ${String(e)}`});})();
|
|
7878
7879
|
</script></body></html>
|