pmx-canvas 0.6.5 → 0.7.1

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.
Files changed (181) hide show
  1. package/.github/extensions/pmx-canvas/extension.mjs +139 -14
  2. package/CHANGELOG.md +70 -0
  3. package/Readme.md +32 -6
  4. package/dist/canvas/global.css +510 -31
  5. package/dist/canvas/index.js +92 -77
  6. package/dist/types/cli/agent.d.ts +3 -0
  7. package/dist/types/cli/commands/backup.d.ts +1 -0
  8. package/dist/types/cli/commands/boards.d.ts +1 -0
  9. package/dist/types/cli/commands/export.d.ts +1 -0
  10. package/dist/types/cli/daemon.d.ts +5 -5
  11. package/dist/types/cli/shared.d.ts +3 -1
  12. package/dist/types/client/canvas/BoardCopyDialog.d.ts +5 -0
  13. package/dist/types/client/canvas/BoardFolderDialog.d.ts +7 -0
  14. package/dist/types/client/canvas/BoardLinkDialog.d.ts +3 -0
  15. package/dist/types/client/canvas/BoardSwitcher.d.ts +8 -0
  16. package/dist/types/client/canvas/ExportDialog.d.ts +7 -0
  17. package/dist/types/client/canvas/HomeView.d.ts +9 -0
  18. package/dist/types/client/nodes/AttachmentNode.d.ts +6 -0
  19. package/dist/types/client/nodes/BoardNode.d.ts +5 -0
  20. package/dist/types/client/state/boards-store.d.ts +79 -0
  21. package/dist/types/client/state/canvas-store.d.ts +2 -0
  22. package/dist/types/client/state/intent-bridge.d.ts +1 -0
  23. package/dist/types/client/state/session-store.d.ts +7 -0
  24. package/dist/types/client/types.d.ts +2 -2
  25. package/dist/types/json-render/catalog.d.ts +1 -1
  26. package/dist/types/json-render/charts/definitions.d.ts +1 -1
  27. package/dist/types/json-render/server.d.ts +6 -0
  28. package/dist/types/mcp/canvas-access.d.ts +10 -3
  29. package/dist/types/mcp/context-uri-template.d.ts +6 -0
  30. package/dist/types/server/agent-presence.d.ts +1 -1
  31. package/dist/types/server/attribution.d.ts +11 -0
  32. package/dist/types/server/ax-context.d.ts +3 -1
  33. package/dist/types/server/ax-interaction.d.ts +2 -2
  34. package/dist/types/server/ax-state.d.ts +13 -3
  35. package/dist/types/server/backup.d.ts +36 -0
  36. package/dist/types/server/board-export.d.ts +45 -0
  37. package/dist/types/server/canvas-db.d.ts +63 -9
  38. package/dist/types/server/canvas-operations.d.ts +23 -0
  39. package/dist/types/server/canvas-provenance.d.ts +1 -1
  40. package/dist/types/server/canvas-state.d.ts +140 -3
  41. package/dist/types/server/context-brief.d.ts +111 -0
  42. package/dist/types/server/context-reads.d.ts +55 -0
  43. package/dist/types/server/document-import.d.ts +66 -0
  44. package/dist/types/server/index.d.ts +103 -4
  45. package/dist/types/server/mutation-history.d.ts +1 -0
  46. package/dist/types/server/operations/invoker.d.ts +2 -0
  47. package/dist/types/server/operations/mcp.d.ts +7 -1
  48. package/dist/types/server/operations/ops/ax-shared.d.ts +2 -2
  49. package/dist/types/server/operations/ops/backup.d.ts +2 -0
  50. package/dist/types/server/operations/ops/boards.d.ts +10 -0
  51. package/dist/types/server/operations/ops/export.d.ts +2 -0
  52. package/dist/types/server/operations/ops/imports.d.ts +2 -0
  53. package/dist/types/server/operations/ops/nodes.d.ts +1 -1
  54. package/dist/types/server/operations/ops/query.d.ts +2 -0
  55. package/dist/types/server/operations/registry.d.ts +9 -1
  56. package/dist/types/server/operations/types.d.ts +1 -1
  57. package/dist/types/server/server.d.ts +1 -0
  58. package/dist/types/server/trace-manager.d.ts +7 -0
  59. package/dist/types/server/webpage-node.d.ts +22 -1
  60. package/dist/types/server/workbench-auth.d.ts +3 -0
  61. package/dist/types/shared/boards.d.ts +6 -0
  62. package/docs/RELEASE.md +5 -0
  63. package/docs/cli.md +73 -0
  64. package/docs/http-api.md +198 -2
  65. package/docs/mcp.md +71 -6
  66. package/docs/node-types.md +26 -0
  67. package/docs/plans/plan-010-attributed-ask-answers.md +39 -0
  68. package/docs/plans/plan-011-context-read-instrumentation.md +54 -0
  69. package/docs/plans/plan-012-many-boards-stage-1.md +98 -0
  70. package/docs/plans/plan-013-static-board-export.md +47 -0
  71. package/docs/plans/plan-014-connected-board-memory.md +140 -0
  72. package/docs/product-vision-2026-09.md +118 -18
  73. package/docs/sdk.md +50 -0
  74. package/package.json +1 -1
  75. package/skills/pmx-canvas/SKILL.md +68 -11
  76. package/skills/pmx-canvas/evals/evals.json +130 -0
  77. package/skills/pmx-canvas/references/full-reference.md +43 -7
  78. package/skills/pmx-canvas/references/github-copilot-app-adapter.md +3 -0
  79. package/skills/pmx-canvas/references/installing-pmx-canvas.md +4 -4
  80. package/skills/pmx-canvas/references/tours-and-recording.md +69 -0
  81. package/skills/pmx-canvas-orchestration/SKILL.md +5 -0
  82. package/skills/pmx-canvas-testing/SKILL.md +11 -2
  83. package/src/cli/agent.ts +4 -0
  84. package/src/cli/commands/apps.ts +1 -1
  85. package/src/cli/commands/ax.ts +13 -0
  86. package/src/cli/commands/backup.ts +66 -0
  87. package/src/cli/commands/boards.ts +71 -0
  88. package/src/cli/commands/export.ts +37 -0
  89. package/src/cli/commands/nodes.ts +4 -1
  90. package/src/cli/commands/pins.ts +6 -2
  91. package/src/cli/commands/pump.ts +3 -0
  92. package/src/cli/commands/query.ts +33 -7
  93. package/src/cli/commands/view.ts +7 -5
  94. package/src/cli/daemon.ts +37 -7
  95. package/src/cli/index.ts +19 -9
  96. package/src/cli/shared.ts +11 -2
  97. package/src/client/App.tsx +21 -4
  98. package/src/client/canvas/AttentionToast.tsx +5 -3
  99. package/src/client/canvas/BoardCopyDialog.tsx +153 -0
  100. package/src/client/canvas/BoardFolderDialog.tsx +120 -0
  101. package/src/client/canvas/BoardLinkDialog.tsx +93 -0
  102. package/src/client/canvas/BoardSwitcher.tsx +149 -0
  103. package/src/client/canvas/CanvasNode.tsx +0 -1
  104. package/src/client/canvas/CanvasViewport.tsx +3 -0
  105. package/src/client/canvas/CommandPalette.tsx +107 -4
  106. package/src/client/canvas/ContextMenu.tsx +4 -1
  107. package/src/client/canvas/ExpandedNodeOverlay.tsx +3 -0
  108. package/src/client/canvas/ExportDialog.tsx +199 -0
  109. package/src/client/canvas/HomeView.tsx +277 -0
  110. package/src/client/canvas/Presentation.tsx +39 -9
  111. package/src/client/canvas/SelectionBar.tsx +0 -2
  112. package/src/client/canvas/SessionPanel.tsx +28 -1
  113. package/src/client/canvas/ToolRail.tsx +38 -3
  114. package/src/client/canvas/TopBar.tsx +34 -18
  115. package/src/client/canvas/import-files.ts +19 -1
  116. package/src/client/canvas/kind-colors.ts +1 -0
  117. package/src/client/icons.tsx +2 -0
  118. package/src/client/nodes/AttachmentNode.tsx +145 -0
  119. package/src/client/nodes/BoardNode.tsx +35 -0
  120. package/src/client/nodes/FileNode.tsx +6 -0
  121. package/src/client/nodes/MarkdownNode.tsx +47 -19
  122. package/src/client/nodes/ax-node-actions.ts +2 -5
  123. package/src/client/nodes/use-ax-surface-bridge.ts +1 -1
  124. package/src/client/state/attention-bridge.ts +3 -1
  125. package/src/client/state/boards-store.ts +167 -0
  126. package/src/client/state/canvas-store.ts +22 -0
  127. package/src/client/state/intent-bridge.ts +30 -2
  128. package/src/client/state/node-factory.ts +1 -0
  129. package/src/client/state/session-store.ts +5 -0
  130. package/src/client/state/sse-bridge.ts +52 -6
  131. package/src/client/theme/global.css +510 -31
  132. package/src/client/types.ts +2 -0
  133. package/src/json-render/server.ts +16 -9
  134. package/src/mcp/canvas-access.ts +59 -22
  135. package/src/mcp/context-uri-template.ts +28 -0
  136. package/src/mcp/server.ts +122 -15
  137. package/src/server/agent-context.ts +116 -29
  138. package/src/server/attribution.ts +29 -0
  139. package/src/server/ax-context.ts +4 -2
  140. package/src/server/ax-interaction.ts +1 -0
  141. package/src/server/ax-state-manager.ts +72 -3
  142. package/src/server/ax-state.ts +41 -0
  143. package/src/server/backup.ts +178 -0
  144. package/src/server/board-export.ts +686 -0
  145. package/src/server/canvas-db.ts +599 -107
  146. package/src/server/canvas-operations.ts +68 -9
  147. package/src/server/canvas-provenance.ts +1 -0
  148. package/src/server/canvas-schema.ts +12 -0
  149. package/src/server/canvas-state.ts +774 -45
  150. package/src/server/context-brief.ts +372 -0
  151. package/src/server/context-reads.ts +238 -0
  152. package/src/server/demo-state.json +659 -2
  153. package/src/server/document-import.ts +223 -0
  154. package/src/server/index.ts +231 -5
  155. package/src/server/mutation-history.ts +10 -13
  156. package/src/server/operations/composites.ts +26 -4
  157. package/src/server/operations/http.ts +9 -3
  158. package/src/server/operations/index.ts +8 -0
  159. package/src/server/operations/invoker.ts +14 -3
  160. package/src/server/operations/mcp.ts +50 -11
  161. package/src/server/operations/ops/app.ts +5 -0
  162. package/src/server/operations/ops/ax-read.ts +10 -6
  163. package/src/server/operations/ops/ax-timeline.ts +75 -0
  164. package/src/server/operations/ops/backup.ts +134 -0
  165. package/src/server/operations/ops/batch.ts +8 -1
  166. package/src/server/operations/ops/boards.ts +351 -0
  167. package/src/server/operations/ops/export.ts +74 -0
  168. package/src/server/operations/ops/ext-app.ts +4 -0
  169. package/src/server/operations/ops/imports.ts +236 -0
  170. package/src/server/operations/ops/nodes.ts +57 -5
  171. package/src/server/operations/ops/query.ts +206 -9
  172. package/src/server/operations/registry.ts +123 -31
  173. package/src/server/operations/types.ts +1 -1
  174. package/src/server/server.ts +146 -2
  175. package/src/server/spatial-analysis.ts +9 -17
  176. package/src/server/trace-manager.ts +19 -0
  177. package/src/server/web-artifacts.ts +2 -1
  178. package/src/server/webpage-node.ts +173 -13
  179. package/src/server/workbench-auth.ts +11 -0
  180. package/src/shared/boards.ts +18 -0
  181. package/src/shared/node-sizes.ts +1 -0
@@ -1,141 +1,156 @@
1
- var Xw=Object.create;var{getPrototypeOf:Kw,defineProperty:Qd,getOwnPropertyNames:Jw}=Object;var ep=Object.prototype.hasOwnProperty;function Yw(e){return this[e]}var Qw,e_,t_=(e,t,n)=>{var o=e!=null&&typeof e==="object";if(o){var r=t?Qw??=new WeakMap:e_??=new WeakMap,s=r.get(e);if(s)return s}n=e!=null?Xw(Kw(e)):{};let a=t||!e||!e.__esModule||!ep.call(e,"default")?Qd(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let c of Jw(e))if(!ep.call(a,c))Qd(a,c,{get:Yw.bind(e,c),enumerable:!0})}if(o)r.set(e,a);return a};var n_=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var uy=n_(function(ly){Object.defineProperty(ly,"__esModule",{value:!0});var Xv=/highlight-(?:text|source)-([a-z0-9]+)/;function Jv(e){e.addRule("highlightedCodeBlock",{filter:function(t){var n=t.firstChild;return t.nodeName==="DIV"&&Xv.test(t.className)&&n&&n.nodeName==="PRE"},replacement:function(t,n,o){var r=n.className||"",s=(r.match(Xv)||[null,""])[1];return`
1
+ var Z_=Object.create;var{getPrototypeOf:U_,defineProperty:Ap,getOwnPropertyNames:q_}=Object;var zp=Object.prototype.hasOwnProperty;function W_(e){return this[e]}var V_,G_,X_=(e,t,n)=>{var o=e!=null&&typeof e==="object";if(o){var r=t?V_??=new WeakMap:G_??=new WeakMap,s=r.get(e);if(s)return s}n=e!=null?Z_(U_(e)):{};let a=t||!e||!e.__esModule||!zp.call(e,"default")?Ap(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let c of q_(e))if(!zp.call(a,c))Ap(a,c,{get:W_.bind(e,c),enumerable:!0})}if(o)r.set(e,a);return a};var K_=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Yy=K_(function(Jy){Object.defineProperty(Jy,"__esModule",{value:!0});var Ly=/highlight-(?:text|source)-([a-z0-9]+)/;function Fy(e){e.addRule("highlightedCodeBlock",{filter:function(t){var n=t.firstChild;return t.nodeName==="DIV"&&Ly.test(t.className)&&n&&n.nodeName==="PRE"},replacement:function(t,n,o){var r=n.className||"",s=(r.match(Ly)||[null,""])[1];return`
2
2
 
3
3
  `+o.fence+s+`
4
4
  `+n.firstChild.textContent+`
5
5
  `+o.fence+`
6
6
 
7
- `}})}function Yv(e){e.addRule("strikethrough",{filter:["del","s","strike"],replacement:function(t){return"~~"+t+"~~"}})}var t0=Array.prototype.indexOf,n0=Array.prototype.every,Zn={},o0={left:":---",right:"---:",center:":---:"},ru=null,Qv=null,Kv=new WeakMap;function r0(e){return e?(e.getAttribute("align")||e.style.textAlign||"").toLowerCase():""}function ey(e){return e?o0[e]:"---"}function ty(e,t){var n={left:0,right:0,center:0,"":0},o="";for(var r=0;r<e.rows.length;++r){var s=e.rows[r];if(t<s.childNodes.length){var a=r0(s.childNodes[t]);if(++n[a],n[a]>n[o])o=a}}return o}Zn.tableCell={filter:["th","td"],replacement:function(e,t){if(su(iy(t)))return e;return ny(e,t)}};Zn.tableRow={filter:"tr",replacement:function(e,t){let n=iy(t);if(su(n))return e;var o="";if(i0(t)){let a=sy(n);for(var r=0;r<a;r++){let c=r<t.childNodes.length?t.childNodes[r]:null;var s=ey(ty(n,r));o+=ny(s,c,r)}}return`
7
+ `}})}function By(e){e.addRule("strikethrough",{filter:["del","s","strike"],replacement:function(t){return"~~"+t+"~~"}})}var eC=Array.prototype.indexOf,tC=Array.prototype.every,Yn={},nC={left:":---",right:"---:",center:":---:"},Iu=null,Hy=null,Dy=new WeakMap;function oC(e){return e?(e.getAttribute("align")||e.style.textAlign||"").toLowerCase():""}function jy(e){return e?nC[e]:"---"}function Zy(e,t){var n={left:0,right:0,center:0,"":0},o="";for(var r=0;r<e.rows.length;++r){var s=e.rows[r];if(t<s.childNodes.length){var a=oC(s.childNodes[t]);if(++n[a],n[a]>n[o])o=a}}return o}Yn.tableCell={filter:["th","td"],replacement:function(e,t){if(Au(Vy(t)))return e;return Uy(e,t)}};Yn.tableRow={filter:"tr",replacement:function(e,t){let n=Vy(t);if(Au(n))return e;var o="";if(rC(t)){let a=Gy(n);for(var r=0;r<a;r++){let c=r<t.childNodes.length?t.childNodes[r]:null;var s=jy(Zy(n,r));o+=Uy(s,c,r)}}return`
8
8
  `+e+(o?`
9
- `+o:"")}};Zn.table={filter:function(e,t){return e.nodeName==="TABLE"},replacement:function(e,t){if(ry(t,Qv)){let c=t.outerHTML,l=c0(t);if(l===null||!l.classList.contains("joplin-table-wrapper"))return`
9
+ `+o:"")}};Yn.table={filter:function(e,t){return e.nodeName==="TABLE"},replacement:function(e,t){if(Wy(t,Hy)){let c=t.outerHTML,l=aC(t);if(l===null||!l.classList.contains("joplin-table-wrapper"))return`
10
10
 
11
11
  <div class="joplin-table-wrapper">${c}</div>
12
12
 
13
- `;else return c}else{if(su(t))return e;e=e.replace(/\n+/g,`
13
+ `;else return c}else{if(Au(t))return e;e=e.replace(/\n+/g,`
14
14
  `);var n=e.trim().split(`
15
- `);if(n.length>=2)n=n[1];var o=/\| :?---/.test(n),r=sy(t),s="";if(r&&!o){s="|"+" |".repeat(r)+`
16
- |`;for(var a=0;a<r;++a)s+=" "+ey(ty(t,a))+" |"}let c=t.caption?t.caption.textContent||"":"",l=c?`${c}
15
+ `);if(n.length>=2)n=n[1];var o=/\| :?---/.test(n),r=Gy(t),s="";if(r&&!o){s="|"+" |".repeat(r)+`
16
+ |`;for(var a=0;a<r;++a)s+=" "+jy(Zy(t,a))+" |"}let c=t.caption?t.caption.textContent||"":"",l=c?`${c}
17
17
 
18
18
  `:"",u=`${s}${e}`.trimStart();return`
19
19
 
20
20
  ${l}${u}
21
21
 
22
- `}}};Zn.tableCaption={filter:["caption"],replacement:()=>""};Zn.tableColgroup={filter:["colgroup","col"],replacement:()=>""};Zn.tableSection={filter:["thead","tbody","tfoot"],replacement:function(e){return e}};function i0(e){var t=e.parentNode;return t.nodeName==="THEAD"||t.firstChild===e&&(t.nodeName==="TABLE"||s0(t))&&n0.call(e.childNodes,function(n){return n.nodeName==="TH"})}function s0(e){var t=e.previousSibling;return e.nodeName==="TBODY"&&(!t||t.nodeName==="THEAD"&&/^\s*$/i.test(t.textContent))}function ny(e,t=null,n=null){if(n===null)n=t0.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=l0(r,t," ");return o+r+" |"}function oy(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(oy(n))return!0}return!1}var iu=(e,t)=>{if(!e.childNodes)return!1;for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];if(t==="code"&&ru&&ru(o))return!0;if(t.includes(o.nodeName))return!0;if(iu(o,t))return!0}return!1},ry=(e,t)=>{let n=["UL","OL","H1","H2","H3","H4","H5","H6","HR","BLOCKQUOTE"];if(t.preserveNestedTables)n.push("TABLE");return iu(e,"code")||iu(e,n)};function su(e){let t=Kv.get(e);if(t!==void 0)return t;let n=a0(e);return Kv.set(e,n),n}function a0(e){if(!e)return!0;if(!e.rows)return!0;if(e.rows.length===1&&e.rows[0].childNodes.length<=1)return!0;if(oy(e))return!0;return!1}function c0(e){let t=e.parentNode;while(t.nodeName!=="DIV")if(t=t.parentNode,!t)return null;return t}function iy(e){let t=e.parentNode;while(t.nodeName!=="TABLE")if(t=t.parentNode,!t)return null;return t}function l0(e,t,n){let o=t.getAttribute("colspan")||1;for(let r=1;r<o;r++)e+=" | "+n.repeat(3);return e}function sy(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 ay(e){ru=e.isCodeBlock,Qv=e.options,e.keep(function(n){if(n.nodeName==="TABLE"&&ry(n,e.options))return!0;return!1});for(var t in Zn)e.addRule(t,Zn[t])}function cy(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 u0(e){e.use([Jv,Yv,ay,cy])}ly.gfm=u0;ly.highlightedCodeBlock=Jv;ly.strikethrough=Yv;ly.tables=ay;ly.taskListItems=cy});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 Hi,ge,ip,Ac,In,tp,sp,ap,cp,Ic,Cc,Tc,o_,Fi={},ji=[],r_=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Bi=Array.isArray;function sn(e,t){for(var n in t)e[n]=t[n];return e}function zc(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function i_(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?Hi.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 Di(e,a,o,r,null)}function Di(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?++ip:r,__i:-1,__u:0};return r==null&&ge.vnode!=null&&ge.vnode(s),s}function ve(e){return e.children}function Oo(e,t){this.props=e,this.context=t}function Lo(e,t){if(t==null)return e.__?Lo(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"?Lo(e):null}function s_(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,o=[],r=[],s=sn({},t);s.__v=t.__v+1,ge.vnode&&ge.vnode(s),Pc(e.__P,s,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,o,n==null?Lo(t):n,!!(32&t.__u),r),s.__v=t.__v,s.__.__k[s.__i]=s,pp(o,s,r),t.__e=t.__=null,s.__e!=n&&lp(s)}}function lp(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}),lp(e)}function np(e){(!e.__d&&(e.__d=!0)&&In.push(e)&&!Zi.__r++||tp!=ge.debounceRendering)&&((tp=ge.debounceRendering)||sp)(Zi)}function Zi(){try{for(var e,t=1;In.length;)In.length>t&&In.sort(ap),e=In.shift(),t=In.length,s_(e)}finally{In.length=Zi.__r=0}}function up(e,t,n,o,r,s,a,c,l,u,d){var p,f,m,v,y,x,h,g=o&&o.__k||ji,b=t.length;for(l=a_(n,t,g,l,b),p=0;p<b;p++)(m=n.__k[p])!=null&&(f=m.__i!=-1&&g[m.__i]||Fi,m.__i=p,x=Pc(e,m,f,r,s,a,c,l,u,d),v=m.__e,m.ref&&f.ref!=m.ref&&(f.ref&&Nc(f.ref,null,m),d.push(m.ref,m.__c||v,m)),y==null&&v!=null&&(y=v),(h=!!(4&m.__u))||f.__k===m.__k?l=dp(m,l,e,h):typeof m.type=="function"&&x!==void 0?l=x:v&&(l=v.nextSibling),m.__u&=-7);return n.__e=y,l}function a_(e,t,n,o,r){var s,a,c,l,u,d=n.length,p=d,f=0;for(e.__k=Array(r),s=0;s<r;s++)(a=t[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=e.__k[s]=Di(null,a,null,null,null):Bi(a)?a=e.__k[s]=Di(ve,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=e.__k[s]=Di(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):e.__k[s]=a,l=s+f,a.__=e,a.__b=e.__b+1,c=null,(u=a.__i=c_(a,n,l,p))!=-1&&(p--,(c=n[u])&&(c.__u|=2)),c==null||c.__v==null?(u==-1&&(r>d?f--:r<d&&f++),typeof a.type!="function"&&(a.__u|=4)):u!=l&&(u==l-1?f--:u==l+1?f++:(u>l?f--:f++,a.__u|=4))):e.__k[s]=null;if(p)for(s=0;s<d;s++)(c=n[s])!=null&&(2&c.__u)==0&&(c.__e==o&&(o=Lo(c)),fp(c,c));return o}function dp(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=dp(r[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=Lo(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function c_(e,t,n,o){var r,s,a,{key:c,type:l}=e,u=t[n],d=u!=null&&(2&u.__u)==0;if(u===null&&c==null||d&&c==u.key&&l==u.type)return n;if(o>(d?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 op(e,t,n){t[0]=="-"?e.setProperty(t,n==null?"":n):e[t]=n==null?"":typeof n!="number"||r_.test(t)?n:n+"px"}function Li(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||op(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||op(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(cp,"$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=Ic,e.addEventListener(t,s?Tc:Cc,s)):e.removeEventListener(t,s?Tc:Cc,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 rp(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=Ic++;else if(t.t<n.u)return;return n(ge.event?ge.event(t):t)}}}function Pc(e,t,n,o,r,s,a,c,l,u){var d,p,f,m,v,y,x,h,g,b,E,j,_,R,A,C=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),s=[c=t.__e=n.__e]),(d=ge.__b)&&d(t);e:if(typeof C=="function")try{if(h=t.props,g=C.prototype&&C.prototype.render,b=(d=C.contextType)&&o[d.__c],E=d?b?b.props.value:d.__:o,n.__c?x=(p=t.__c=n.__c).__=p.__E:(g?t.__c=p=new C(h,E):(t.__c=p=new Oo(h,E),p.constructor=C,p.render=u_),b&&b.sub(p),p.state||(p.state={}),p.__n=o,f=p.__d=!0,p.__h=[],p._sb=[]),g&&p.__s==null&&(p.__s=p.state),g&&C.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=sn({},p.__s)),sn(p.__s,C.getDerivedStateFromProps(h,p.__s))),m=p.props,v=p.state,p.__v=t,f)g&&C.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),g&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(g&&C.getDerivedStateFromProps==null&&h!==m&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(h,E),t.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&p.shouldComponentUpdate(h,p.__s,E)===!1){t.__v!=n.__v&&(p.props=h,p.state=p.__s,p.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(Z){Z&&(Z.__=t)}),ji.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&a.push(p);break e}p.componentWillUpdate!=null&&p.componentWillUpdate(h,p.__s,E),g&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(m,v,y)})}if(p.context=E,p.props=h,p.__P=e,p.__e=!1,j=ge.__r,_=0,g)p.state=p.__s,p.__d=!1,j&&j(t),d=p.render(p.props,p.state,p.context),ji.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,j&&j(t),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++_<25);p.state=p.__s,p.getChildContext!=null&&(o=sn(sn({},o),p.getChildContext())),g&&!f&&p.getSnapshotBeforeUpdate!=null&&(y=p.getSnapshotBeforeUpdate(m,v)),R=d!=null&&d.type===ve&&d.key==null?mp(d.props.children):d,c=up(e,Bi(R)?R:[R],t,n,o,r,s,a,c,l,u),p.base=t.__e,t.__u&=-161,p.__h.length&&a.push(p),x&&(p.__E=p.__=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(A=s.length;A--;)zc(s[A]);Ec(t)}else t.__e=n.__e,t.__k=n.__k,Z.then||Ec(t);ge.__e(Z,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=l_(n.__e,t,n,o,r,s,a,l,u);return(d=ge.diffed)&&d(t),128&t.__u?void 0:c}function Ec(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(Ec))}function pp(e,t,n){for(var o=0;o<n.length;o++)Nc(n[o],n[++o],n[++o]);ge.__c&&ge.__c(t,e),e.some(function(r){try{e=r.__h,r.__h=[],e.some(function(s){s.call(r)})}catch(s){ge.__e(s,r.__v)}})}function mp(e){return typeof e!="object"||e==null||e.__b>0?e:Bi(e)?e.map(mp):sn({},e)}function l_(e,t,n,o,r,s,a,c,l){var u,d,p,f,m,v,y,x=n.props||Fi,{props:h,type:g}=t;if(g=="svg"?r="http://www.w3.org/2000/svg":g=="math"?r="http://www.w3.org/1998/Math/MathML":r||(r="http://www.w3.org/1999/xhtml"),s!=null){for(u=0;u<s.length;u++)if((m=s[u])&&"setAttribute"in m==!!g&&(g?m.localName==g:m.nodeType==3)){e=m,s[u]=null;break}}if(e==null){if(g==null)return document.createTextNode(h);e=document.createElementNS(r,g,h.is&&h),c&&(ge.__m&&ge.__m(t,s),c=!1),s=null}if(g==null)x===h||c&&e.data==h||(e.data=h);else{if(s=s&&Hi.call(e.childNodes),!c&&s!=null)for(x={},u=0;u<e.attributes.length;u++)x[(m=e.attributes[u]).name]=m.value;for(u in x)m=x[u],u=="dangerouslySetInnerHTML"?p=m:u=="children"||(u in h)||u=="value"&&("defaultValue"in h)||u=="checked"&&("defaultChecked"in h)||Li(e,u,null,m,r);for(u in h)m=h[u],u=="children"?f=m:u=="dangerouslySetInnerHTML"?d=m:u=="value"?v=m:u=="checked"?y=m:c&&typeof m!="function"||x[u]===m||Li(e,u,m,x[u],r);if(d)c||p&&(d.__html==p.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[];else if(p&&(e.innerHTML=""),up(t.type=="template"?e.content:e,Bi(f)?f:[f],t,n,o,g=="foreignObject"?"http://www.w3.org/1999/xhtml":r,s,a,s?s[0]:n.__k&&Lo(n,0),c,l),s!=null)for(u=s.length;u--;)zc(s[u]);c||(u="value",g=="progress"&&v==null?e.removeAttribute("value"):v!=null&&(v!==e[u]||g=="progress"&&!v||g=="option"&&v!=x[u])&&Li(e,u,v,x[u],r),u="checked",y!=null&&y!=e[u]&&Li(e,u,y,x[u],r))}return e}function Nc(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){ge.__e(r,n)}}function fp(e,t,n){var o,r;if(ge.unmount&&ge.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Nc(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){ge.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(r=0;r<o.length;r++)o[r]&&fp(o[r],t,n||typeof e.type!="function");n||zc(e.__e),e.__c=e.__=e.__e=void 0}function u_(e,t,n){return this.constructor(e,n)}function hp(e,t,n){var o,r,s,a;t==document&&(t=document.documentElement),ge.__&&ge.__(e,t),r=(o=typeof n=="function")?null:n&&n.__k||t.__k,s=[],a=[],Pc(t,e=(!o&&n||t).__k=i_(ve,null,[e]),r||Fi,Fi,t.namespaceURI,!o&&n?[n]:r?null:t.firstChild?Hi.call(t.childNodes):null,s,!o&&n?n:r?r.__e:t.firstChild,o,a),pp(s,e,a)}Hi=ji.slice,ge={__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}},ip=0,Ac=function(e){return e!=null&&e.constructor===void 0},Oo.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=sn({},this.state),typeof e=="function"&&(e=e(sn({},n),this.props)),e&&sn(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),np(this))},Oo.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),np(this))},Oo.prototype.render=ve,In=[],sp=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ap=function(e,t){return e.__v.__b-t.__v.__b},Zi.__r=0,cp=/(PointerCapture)$|Capture$/i,Ic=0,Cc=rp(!1),Tc=rp(!0),o_=0;var Do,Ve,Rc,gp,$r=0,kp=[],Xe=ge,{__b:vp,__r:yp,diffed:xp,__c:bp,unmount:wp,__:_p}=Xe;function Wi(e,t){Xe.__h&&Xe.__h(Ve,e,$r||t),$r=0;var n=Ve.__H||(Ve.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function O(e){return $r=1,d_(Cp,e)}function d_(e,t,n){var o=Wi(Do++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):Cp(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=Ve,!Ve.__f)){var r=function(c,l,u){if(!o.__c.__H)return!0;var d=o.__c.__H.__.filter(function(f){return f.__c});if(d.every(function(f){return!f.__N}))return!s||s.call(this,c,l,u);var p=o.__c.props!==c;return d.some(function(f){if(f.__N){var m=f.__[0];f.__=f.__N,f.__N=void 0,m!==f.__[0]&&(p=!0)}}),s&&s.call(this,c,l,u)||p};Ve.__f=!0;var s=Ve.shouldComponentUpdate,a=Ve.componentWillUpdate;Ve.componentWillUpdate=function(c,l,u){if(this.__e){var d=s;s=void 0,r(c,l,u),s=d}a&&a.call(this,c,l,u)},Ve.shouldComponentUpdate=r}return o.__N||o.__}function D(e,t){var n=Wi(Do++,3);!Xe.__s&&Mc(n.__H,t)&&(n.__=e,n.u=t,Ve.__H.__h.push(n))}function qi(e,t){var n=Wi(Do++,4);!Xe.__s&&Mc(n.__H,t)&&(n.__=e,n.u=t,Ve.__h.push(n))}function M(e){return $r=5,Ie(function(){return{current:e}},[])}function Ie(e,t){var n=Wi(Do++,7);return Mc(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function L(e,t){return $r=8,Ie(function(){return e},t)}function p_(){for(var e;e=kp.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Ui),t.__h.some($c),t.__h=[]}catch(n){t.__h=[],Xe.__e(n,e.__v)}}}Xe.__b=function(e){Ve=null,vp&&vp(e)},Xe.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),_p&&_p(e,t)},Xe.__r=function(e){yp&&yp(e),Do=0;var t=(Ve=e.__c).__H;t&&(Rc===Ve?(t.__h=[],Ve.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(Ui),t.__h.some($c),t.__h=[],Do=0)),Rc=Ve},Xe.diffed=function(e){xp&&xp(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(kp.push(t)!==1&&gp===Xe.requestAnimationFrame||((gp=Xe.requestAnimationFrame)||m_)(p_)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Rc=Ve=null},Xe.__c=function(e,t){t.some(function(n){try{n.__h.some(Ui),n.__h=n.__h.filter(function(o){return!o.__||$c(o)})}catch(o){t.some(function(r){r.__h&&(r.__h=[])}),t=[],Xe.__e(o,n.__v)}}),bp&&bp(e,t)},Xe.unmount=function(e){wp&&wp(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{Ui(o)}catch(r){t=r}}),n.__H=void 0,t&&Xe.__e(t,n.__v))};var Sp=typeof requestAnimationFrame=="function";function m_(e){var t,n=function(){clearTimeout(o),Sp&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Sp&&(t=requestAnimationFrame(n))}function Ui(e){var t=Ve,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),Ve=t}function $c(e){var t=Ve;e.__c=e.__(),Ve=t}function Mc(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function Cp(e,t){return typeof t=="function"?t(e):t}var hz=Object.freeze({status:"aborted"});function z(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,d=Object.keys(u);for(let p=0;p<d.length;p++){let f=d[p];if(!(f in c))c[f]=u[f].bind(c)}}let r=n?.Parent??Object;class s extends r{}Object.defineProperty(s,"name",{value:e});function a(c){var l;let u=n?.Parent?new s:this;o(u,c),(l=u._zod).deferred??(l.deferred=[]);for(let d of u._zod.deferred)d();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 gz=Symbol("zod_brand");class an extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Mr extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}var Vi={};function Mt(e){if(e)Object.assign(Vi,e);return Vi}function Xi(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 Lc(e,t="|"){return e.map((n)=>Zc(n)).join(t)}function Or(e,t){if(typeof t==="bigint")return t.toString();return t}function Lr(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw Error("cached value already set")}}}function Ki(e){return e===null||e===void 0}function Ji(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function Ep(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 Tp=Symbol("evaluating");function be(e,t,n){let o=void 0;Object.defineProperty(e,t,{get(){if(o===Tp)return;if(o===void 0)o=Tp,o=n();return o},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function ao(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function zn(...e){let t={};for(let n of e){let o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function Dc(e){return JSON.stringify(e)}function Ap(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var Fc="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Fo(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var Ip=Lr(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function co(e){if(Fo(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(Fo(n)===!1)return!1;if(Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)return!1;return!0}function jc(e){if(co(e))return{...e};if(Array.isArray(e))return[...e];return e}var zp=new Set(["string","number","symbol"]);function Pn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Jt(e,t,n){let o=new e._zod.constr(t??e._zod.def);if(!t||n?.parent)o._zod.parent=e;return o}function G(e){let t=e;if(!t)return{};if(typeof t==="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function Zc(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function Pp(e){return Object.keys(e).filter((t)=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var Np={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 f_(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=zn(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 ao(this,"shape",a),a},checks:[]});return Jt(e,s)}function h_(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=zn(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 ao(this,"shape",a),a},checks:[]});return Jt(e,s)}function g_(e,t){if(!co(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=zn(e._zod.def,{get shape(){let s={...e._zod.def.shape,...t};return ao(this,"shape",s),s}});return Jt(e,r)}function v_(e,t){if(!co(t))throw Error("Invalid input to safeExtend: expected a plain object");let n=zn(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t};return ao(this,"shape",o),o}});return Jt(e,n)}function y_(e,t){let n=zn(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t._zod.def.shape};return ao(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return Jt(e,n)}function x_(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=zn(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 ao(this,"shape",l),l},checks:[]});return Jt(t,a)}function b_(e,t,n){let o=zn(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 ao(this,"shape",s),s}});return Jt(t,o)}function lo(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 Nn(e,t){return t.map((n)=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function Gi(e){return typeof e==="string"?e:e?.message}function Yt(e,t,n){let o={...e,path:e.path??[]};if(!e.message){let r=Gi(e.inst?._zod.def?.error?.(e))??Gi(t?.error?.(e))??Gi(n.customError?.(e))??Gi(n.localeError?.(e))??"Invalid input";o.message=r}if(delete o.inst,delete o.continue,!t?.reportInput)delete o.input;return o}function Yi(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function Rp(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 uo(...e){let[t,n,o]=e;if(typeof t==="string")return{message:t,code:"custom",input:n,inst:o};return{...t}}var $p=(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,Or,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Qi=z("$ZodError",$p),Hc=z("$ZodError",$p,{Parent:Error});function Mp(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 Op(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 es=(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 an;if(a.issues.length){let c=new(r?.Err??e)(a.issues.map((l)=>Yt(l,s,Mt())));throw Fc(c,r?.callee),c}return a.value};var ts=(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)=>Yt(l,s,Mt())));throw Fc(c,r?.callee),c}return a.value};var Dr=(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 an;return s.issues.length?{success:!1,error:new(e??Qi)(s.issues.map((a)=>Yt(a,r,Mt())))}:{success:!0,data:s.value}},Fr=Dr(Hc),jr=(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)=>Yt(a,r,Mt())))}:{success:!0,data:s.value}},ns=jr(Hc),Lp=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return es(e)(t,n,r)};var Dp=(e)=>(t,n,o)=>es(e)(t,n,o);var Fp=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ts(e)(t,n,r)};var jp=(e)=>async(t,n,o)=>ts(e)(t,n,o);var Zp=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return Dr(e)(t,n,r)};var Hp=(e)=>(t,n,o)=>Dr(e)(t,n,o);var Bp=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return jr(e)(t,n,r)};var Up=(e)=>async(t,n,o)=>jr(e)(t,n,o);var Wp=/^[cC][^\s-]{8,}$/,qp=/^[0-9a-z]+$/,Vp=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Gp=/^[0-9a-vA-V]{20}$/,Xp=/^[A-Za-z0-9]{27}$/,Kp=/^[a-zA-Z0-9_-]{21}$/,Jp=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Yp=/^([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})$/,Bc=(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 Qp=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var __="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function em(){return new RegExp(__,"u")}var tm=/^(?:(?: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])$/,nm=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;var om=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,rm=/^(([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])$/,im=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Uc=/^[A-Za-z0-9_-]*$/;var sm=/^\+[1-9]\d{6,14}$/,am="(?:(?:\\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])))",cm=new RegExp(`^${am}$`);function lm(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function um(e){return new RegExp(`^${lm(e)}$`)}function dm(e){let t=lm({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(`^${am}T(?:${o})$`)}var pm=(e)=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var mm=/^-?\d+$/,Wc=/^-?\d+(?:\.\d+)?$/,fm=/^(?:true|false)$/i,hm=/^null$/i;var gm=/^undefined$/i;var vm=/^[^A-Z]*$/,ym=/^[^a-z]*$/;var it=z("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),xm={number:"number",bigint:"bigint",object:"date"},qc=z("$ZodCheckLessThan",(e,t)=>{it.init(e,t);let n=xm[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})}}),Vc=z("$ZodCheckGreaterThan",(e,t)=>{it.init(e,t);let n=xm[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})}}),bm=z("$ZodCheckMultipleOf",(e,t)=>{it.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):Ep(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})}}),wm=z("$ZodCheckNumberFormat",(e,t)=>{it.init(e,t),t.format=t.format||"float64";let n=t.format?.includes("int"),o=n?"int":"number",[r,s]=Np[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=mm}),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 _m=z("$ZodCheckMaxLength",(e,t)=>{var n;it.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!Ki(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=Yi(r);o.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Sm=z("$ZodCheckMinLength",(e,t)=>{var n;it.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!Ki(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=Yi(r);o.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),km=z("$ZodCheckLengthEquals",(e,t)=>{var n;it.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!Ki(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=Yi(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})}}),Zr=z("$ZodCheckStringFormat",(e,t)=>{var n,o;if(it.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=()=>{})}),Cm=z("$ZodCheckRegex",(e,t)=>{Zr.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})}}),Tm=z("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=vm),Zr.init(e,t)}),Em=z("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=ym),Zr.init(e,t)}),Am=z("$ZodCheckIncludes",(e,t)=>{it.init(e,t);let n=Pn(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})}}),Im=z("$ZodCheckStartsWith",(e,t)=>{it.init(e,t);let n=new RegExp(`^${Pn(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})}}),zm=z("$ZodCheckEndsWith",(e,t)=>{it.init(e,t);let n=new RegExp(`.*${Pn(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 Pm=z("$ZodCheckOverwrite",(e,t)=>{it.init(e,t),e._zod.check=(n)=>{n.value=t.tx(n.value)}});class Gc{constructor(e=[]){if(this.content=[],this.indent=0,this)this.args=e}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let n=e.split(`
22
+ `}}};Yn.tableCaption={filter:["caption"],replacement:()=>""};Yn.tableColgroup={filter:["colgroup","col"],replacement:()=>""};Yn.tableSection={filter:["thead","tbody","tfoot"],replacement:function(e){return e}};function rC(e){var t=e.parentNode;return t.nodeName==="THEAD"||t.firstChild===e&&(t.nodeName==="TABLE"||iC(t))&&tC.call(e.childNodes,function(n){return n.nodeName==="TH"})}function iC(e){var t=e.previousSibling;return e.nodeName==="TBODY"&&(!t||t.nodeName==="THEAD"&&/^\s*$/i.test(t.textContent))}function Uy(e,t=null,n=null){if(n===null)n=eC.call(t.parentNode.childNodes,t);var o=" ";if(n===0)o="| ";let r=e.trim().replace(/\n\r/g,"<br>").replace(/\n/g,"<br>");r=r.replace(/\|+/g,"\\|");while(r.length<3)r+=" ";if(t)r=cC(r,t," ");return o+r+" |"}function qy(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(qy(n))return!0}return!1}var Eu=(e,t)=>{if(!e.childNodes)return!1;for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];if(t==="code"&&Iu&&Iu(o))return!0;if(t.includes(o.nodeName))return!0;if(Eu(o,t))return!0}return!1},Wy=(e,t)=>{let n=["UL","OL","H1","H2","H3","H4","H5","H6","HR","BLOCKQUOTE"];if(t.preserveNestedTables)n.push("TABLE");return Eu(e,"code")||Eu(e,n)};function Au(e){let t=Dy.get(e);if(t!==void 0)return t;let n=sC(e);return Dy.set(e,n),n}function sC(e){if(!e)return!0;if(!e.rows)return!0;if(e.rows.length===1&&e.rows[0].childNodes.length<=1)return!0;if(qy(e))return!0;return!1}function aC(e){let t=e.parentNode;while(t.nodeName!=="DIV")if(t=t.parentNode,!t)return null;return t}function Vy(e){let t=e.parentNode;while(t.nodeName!=="TABLE")if(t=t.parentNode,!t)return null;return t}function cC(e,t,n){let o=t.getAttribute("colspan")||1;for(let r=1;r<o;r++)e+=" | "+n.repeat(3);return e}function Gy(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 Xy(e){Iu=e.isCodeBlock,Hy=e.options,e.keep(function(n){if(n.nodeName==="TABLE"&&Wy(n,e.options))return!0;return!1});for(var t in Yn)e.addRule(t,Yn[t])}function Ky(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 lC(e){e.use([Fy,By,Xy,Ky])}Jy.gfm=lC;Jy.highlightedCodeBlock=Fy;Jy.strikethrough=By;Jy.tables=Xy;Jy.taskListItems=Ky});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 rs,we,Mp,Kc,Ln,Pp,Op,Lp,Dp,Jc,Vc,Gc,J_,ts={},ns=[],Y_=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,is=Array.isArray;function mn(e,t){for(var n in t)e[n]=t[n];return e}function Yc(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function Q_(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?rs.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 es(e,a,o,r,null)}function es(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?++Mp:r,__i:-1,__u:0};return r==null&&we.vnode!=null&&we.vnode(s),s}function de(e){return e.children}function Wo(e,t){this.props=e,this.context=t}function Vo(e,t){if(t==null)return e.__?Vo(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"?Vo(e):null}function eS(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,o=[],r=[],s=mn({},t);s.__v=t.__v+1,we.vnode&&we.vnode(s),Qc(e.__P,s,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,o,n==null?Vo(t):n,!!(32&t.__u),r),s.__v=t.__v,s.__.__k[s.__i]=s,jp(o,s,r),t.__e=t.__=null,s.__e!=n&&Fp(s)}}function Fp(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}),Fp(e)}function Np(e){(!e.__d&&(e.__d=!0)&&Ln.push(e)&&!os.__r++||Pp!=we.debounceRendering)&&((Pp=we.debounceRendering)||Op)(os)}function os(){try{for(var e,t=1;Ln.length;)Ln.length>t&&Ln.sort(Lp),e=Ln.shift(),t=Ln.length,eS(e)}finally{Ln.length=os.__r=0}}function Bp(e,t,n,o,r,s,a,c,l,u,p){var d,f,m,h,v,x,g,y=o&&o.__k||ns,E=t.length;for(l=tS(n,t,y,l,E),d=0;d<E;d++)(m=n.__k[d])!=null&&(f=m.__i!=-1&&y[m.__i]||ts,m.__i=d,x=Qc(e,m,f,r,s,a,c,l,u,p),h=m.__e,m.ref&&f.ref!=m.ref&&(f.ref&&el(f.ref,null,m),p.push(m.ref,m.__c||h,m)),v==null&&h!=null&&(v=h),(g=!!(4&m.__u))||f.__k===m.__k?l=Hp(m,l,e,g):typeof m.type=="function"&&x!==void 0?l=x:h&&(l=h.nextSibling),m.__u&=-7);return n.__e=v,l}function tS(e,t,n,o,r){var s,a,c,l,u,p=n.length,d=p,f=0;for(e.__k=Array(r),s=0;s<r;s++)(a=t[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=e.__k[s]=es(null,a,null,null,null):is(a)?a=e.__k[s]=es(de,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=e.__k[s]=es(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):e.__k[s]=a,l=s+f,a.__=e,a.__b=e.__b+1,c=null,(u=a.__i=nS(a,n,l,d))!=-1&&(d--,(c=n[u])&&(c.__u|=2)),c==null||c.__v==null?(u==-1&&(r>p?f--:r<p&&f++),typeof a.type!="function"&&(a.__u|=4)):u!=l&&(u==l-1?f--:u==l+1?f++:(u>l?f--:f++,a.__u|=4))):e.__k[s]=null;if(d)for(s=0;s<p;s++)(c=n[s])!=null&&(2&c.__u)==0&&(c.__e==o&&(o=Vo(c)),Up(c,c));return o}function Hp(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=Hp(r[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=Vo(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function nS(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 Rp(e,t,n){t[0]=="-"?e.setProperty(t,n==null?"":n):e[t]=n==null?"":typeof n!="number"||Y_.test(t)?n:n+"px"}function Qi(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||Rp(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||Rp(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Dp,"$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=Jc,e.addEventListener(t,s?Gc:Vc,s)):e.removeEventListener(t,s?Gc:Vc,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 $p(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=Jc++;else if(t.t<n.u)return;return n(we.event?we.event(t):t)}}}function Qc(e,t,n,o,r,s,a,c,l,u){var p,d,f,m,h,v,x,g,y,E,L,P,b,T,w,_=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),s=[c=t.__e=n.__e]),(p=we.__b)&&p(t);e:if(typeof _=="function")try{if(g=t.props,y=_.prototype&&_.prototype.render,E=(p=_.contextType)&&o[p.__c],L=p?E?E.props.value:p.__:o,n.__c?x=(d=t.__c=n.__c).__=d.__E:(y?t.__c=d=new _(g,L):(t.__c=d=new Wo(g,L),d.constructor=_,d.render=rS),E&&E.sub(d),d.state||(d.state={}),d.__n=o,f=d.__d=!0,d.__h=[],d._sb=[]),y&&d.__s==null&&(d.__s=d.state),y&&_.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=mn({},d.__s)),mn(d.__s,_.getDerivedStateFromProps(g,d.__s))),m=d.props,h=d.state,d.__v=t,f)y&&_.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),y&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(y&&_.getDerivedStateFromProps==null&&g!==m&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(g,L),t.__v==n.__v||!d.__e&&d.shouldComponentUpdate!=null&&d.shouldComponentUpdate(g,d.__s,L)===!1){t.__v!=n.__v&&(d.props=g,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(z){z&&(z.__=t)}),ns.push.apply(d.__h,d._sb),d._sb=[],d.__h.length&&a.push(d);break e}d.componentWillUpdate!=null&&d.componentWillUpdate(g,d.__s,L),y&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(m,h,v)})}if(d.context=L,d.props=g,d.__P=e,d.__e=!1,P=we.__r,b=0,y)d.state=d.__s,d.__d=!1,P&&P(t),p=d.render(d.props,d.state,d.context),ns.push.apply(d.__h,d._sb),d._sb=[];else do d.__d=!1,P&&P(t),p=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++b<25);d.state=d.__s,d.getChildContext!=null&&(o=mn(mn({},o),d.getChildContext())),y&&!f&&d.getSnapshotBeforeUpdate!=null&&(v=d.getSnapshotBeforeUpdate(m,h)),T=p!=null&&p.type===de&&p.key==null?Zp(p.props.children):p,c=Bp(e,is(T)?T:[T],t,n,o,r,s,a,c,l,u),d.base=t.__e,t.__u&=-161,d.__h.length&&a.push(d),x&&(d.__E=d.__=null)}catch(z){if(t.__v=null,l||s!=null)if(z.then){for(t.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;s[s.indexOf(c)]=null,t.__e=c}else{for(w=s.length;w--;)Yc(s[w]);Xc(t)}else t.__e=n.__e,t.__k=n.__k,z.then||Xc(t);we.__e(z,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=oS(n.__e,t,n,o,r,s,a,l,u);return(p=we.diffed)&&p(t),128&t.__u?void 0:c}function Xc(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(Xc))}function jp(e,t,n){for(var o=0;o<n.length;o++)el(n[o],n[++o],n[++o]);we.__c&&we.__c(t,e),e.some(function(r){try{e=r.__h,r.__h=[],e.some(function(s){s.call(r)})}catch(s){we.__e(s,r.__v)}})}function Zp(e){return typeof e!="object"||e==null||e.__b>0?e:is(e)?e.map(Zp):mn({},e)}function oS(e,t,n,o,r,s,a,c,l){var u,p,d,f,m,h,v,x=n.props||ts,{props:g,type:y}=t;if(y=="svg"?r="http://www.w3.org/2000/svg":y=="math"?r="http://www.w3.org/1998/Math/MathML":r||(r="http://www.w3.org/1999/xhtml"),s!=null){for(u=0;u<s.length;u++)if((m=s[u])&&"setAttribute"in m==!!y&&(y?m.localName==y:m.nodeType==3)){e=m,s[u]=null;break}}if(e==null){if(y==null)return document.createTextNode(g);e=document.createElementNS(r,y,g.is&&g),c&&(we.__m&&we.__m(t,s),c=!1),s=null}if(y==null)x===g||c&&e.data==g||(e.data=g);else{if(s=s&&rs.call(e.childNodes),!c&&s!=null)for(x={},u=0;u<e.attributes.length;u++)x[(m=e.attributes[u]).name]=m.value;for(u in x)m=x[u],u=="dangerouslySetInnerHTML"?d=m:u=="children"||(u in g)||u=="value"&&("defaultValue"in g)||u=="checked"&&("defaultChecked"in g)||Qi(e,u,null,m,r);for(u in g)m=g[u],u=="children"?f=m:u=="dangerouslySetInnerHTML"?p=m:u=="value"?h=m:u=="checked"?v=m:c&&typeof m!="function"||x[u]===m||Qi(e,u,m,x[u],r);if(p)c||d&&(p.__html==d.__html||p.__html==e.innerHTML)||(e.innerHTML=p.__html),t.__k=[];else if(d&&(e.innerHTML=""),Bp(t.type=="template"?e.content:e,is(f)?f:[f],t,n,o,y=="foreignObject"?"http://www.w3.org/1999/xhtml":r,s,a,s?s[0]:n.__k&&Vo(n,0),c,l),s!=null)for(u=s.length;u--;)Yc(s[u]);c||(u="value",y=="progress"&&h==null?e.removeAttribute("value"):h!=null&&(h!==e[u]||y=="progress"&&!h||y=="option"&&h!=x[u])&&Qi(e,u,h,x[u],r),u="checked",v!=null&&v!=e[u]&&Qi(e,u,v,x[u],r))}return e}function el(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){we.__e(r,n)}}function Up(e,t,n){var o,r;if(we.unmount&&we.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||el(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){we.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(r=0;r<o.length;r++)o[r]&&Up(o[r],t,n||typeof e.type!="function");n||Yc(e.__e),e.__c=e.__=e.__e=void 0}function rS(e,t,n){return this.constructor(e,n)}function Vr(e,t,n){var o,r,s,a;t==document&&(t=document.documentElement),we.__&&we.__(e,t),r=(o=typeof n=="function")?null:n&&n.__k||t.__k,s=[],a=[],Qc(t,e=(!o&&n||t).__k=Q_(de,null,[e]),r||ts,ts,t.namespaceURI,!o&&n?[n]:r?null:t.firstChild?rs.call(t.childNodes):null,s,!o&&n?n:r?r.__e:t.firstChild,o,a),jp(s,e,a)}rs=ns.slice,we={__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}},Mp=0,Kc=function(e){return e!=null&&e.constructor===void 0},Wo.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=mn({},this.state),typeof e=="function"&&(e=e(mn({},n),this.props)),e&&mn(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Np(this))},Wo.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Np(this))},Wo.prototype.render=de,Ln=[],Op=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Lp=function(e,t){return e.__v.__b-t.__v.__b},os.__r=0,Dp=/(PointerCapture)$|Capture$/i,Jc=0,Vc=$p(!1),Gc=$p(!0),J_=0;var Go,Xe,tl,qp,Gr=0,Qp=[],Je=we,{__b:Wp,__r:Vp,diffed:Gp,__c:Xp,unmount:Kp,__:Jp}=Je;function as(e,t){Je.__h&&Je.__h(Xe,e,Gr||t),Gr=0;var n=Xe.__H||(Xe.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function I(e){return Gr=1,iS(em,e)}function iS(e,t,n){var o=as(Go++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):em(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=Xe,!Xe.__f)){var r=function(c,l,u){if(!o.__c.__H)return!0;var p=o.__c.__H.__.filter(function(f){return f.__c});if(p.every(function(f){return!f.__N}))return!s||s.call(this,c,l,u);var d=o.__c.props!==c;return p.some(function(f){if(f.__N){var m=f.__[0];f.__=f.__N,f.__N=void 0,m!==f.__[0]&&(d=!0)}}),s&&s.call(this,c,l,u)||d};Xe.__f=!0;var s=Xe.shouldComponentUpdate,a=Xe.componentWillUpdate;Xe.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)},Xe.shouldComponentUpdate=r}return o.__N||o.__}function B(e,t){var n=as(Go++,3);!Je.__s&&ol(n.__H,t)&&(n.__=e,n.u=t,Xe.__H.__h.push(n))}function Dn(e,t){var n=as(Go++,4);!Je.__s&&ol(n.__H,t)&&(n.__=e,n.u=t,Xe.__h.push(n))}function R(e){return Gr=5,Ie(function(){return{current:e}},[])}function Ie(e,t){var n=as(Go++,7);return ol(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function H(e,t){return Gr=8,Ie(function(){return e},t)}function sS(){for(var e;e=Qp.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(ss),t.__h.some(nl),t.__h=[]}catch(n){t.__h=[],Je.__e(n,e.__v)}}}Je.__b=function(e){Xe=null,Wp&&Wp(e)},Je.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Jp&&Jp(e,t)},Je.__r=function(e){Vp&&Vp(e),Go=0;var t=(Xe=e.__c).__H;t&&(tl===Xe?(t.__h=[],Xe.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(ss),t.__h.some(nl),t.__h=[],Go=0)),tl=Xe},Je.diffed=function(e){Gp&&Gp(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Qp.push(t)!==1&&qp===Je.requestAnimationFrame||((qp=Je.requestAnimationFrame)||aS)(sS)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),tl=Xe=null},Je.__c=function(e,t){t.some(function(n){try{n.__h.some(ss),n.__h=n.__h.filter(function(o){return!o.__||nl(o)})}catch(o){t.some(function(r){r.__h&&(r.__h=[])}),t=[],Je.__e(o,n.__v)}}),Xp&&Xp(e,t)},Je.unmount=function(e){Kp&&Kp(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{ss(o)}catch(r){t=r}}),n.__H=void 0,t&&Je.__e(t,n.__v))};var Yp=typeof requestAnimationFrame=="function";function aS(e){var t,n=function(){clearTimeout(o),Yp&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Yp&&(t=requestAnimationFrame(n))}function ss(e){var t=Xe,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),Xe=t}function nl(e){var t=Xe;e.__c=e.__(),Xe=t}function ol(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function em(e,t){return typeof t=="function"?t(e):t}var bz=Object.freeze({status:"aborted"});function O(e,t,n){function o(c,l){if(!c._zod)Object.defineProperty(c,"_zod",{value:{def:l,constr:a,traits:new Set},enumerable:!1});if(c._zod.traits.has(e))return;c._zod.traits.add(e),t(c,l);let u=a.prototype,p=Object.keys(u);for(let d=0;d<p.length;d++){let f=p[d];if(!(f in c))c[f]=u[f].bind(c)}}let r=n?.Parent??Object;class s extends r{}Object.defineProperty(s,"name",{value:e});function a(c){var l;let u=n?.Parent?new s:this;o(u,c),(l=u._zod).deferred??(l.deferred=[]);for(let p of u._zod.deferred)p();return u}return Object.defineProperty(a,"init",{value:o}),Object.defineProperty(a,Symbol.hasInstance,{value:(c)=>{if(n?.Parent&&c instanceof n.Parent)return!0;return c?._zod?.traits?.has(e)}}),Object.defineProperty(a,"name",{value:e}),a}var xz=Symbol("zod_brand");class fn extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Xr extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}var cs={};function Ht(e){if(e)Object.assign(cs,e);return cs}function us(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 il(e,t="|"){return e.map((n)=>ll(n)).join(t)}function Kr(e,t){if(typeof t==="bigint")return t.toString();return t}function Jr(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw Error("cached value already set")}}}function ds(e){return e===null||e===void 0}function ps(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function nm(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 tm=Symbol("evaluating");function _e(e,t,n){let o=void 0;Object.defineProperty(e,t,{get(){if(o===tm)return;if(o===void 0)o=tm,o=n();return o},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function yo(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Fn(...e){let t={};for(let n of e){let o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function sl(e){return JSON.stringify(e)}function om(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var al="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Xo(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var rm=Jr(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function bo(e){if(Xo(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(Xo(n)===!1)return!1;if(Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)return!1;return!0}function cl(e){if(bo(e))return{...e};if(Array.isArray(e))return[...e];return e}var im=new Set(["string","number","symbol"]);function Bn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function an(e,t,n){let o=new e._zod.constr(t??e._zod.def);if(!t||n?.parent)o._zod.parent=e;return o}function G(e){let t=e;if(!t)return{};if(typeof t==="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function ll(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function sm(e){return Object.keys(e).filter((t)=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var am={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 cS(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=Fn(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 yo(this,"shape",a),a},checks:[]});return an(e,s)}function lS(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=Fn(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 yo(this,"shape",a),a},checks:[]});return an(e,s)}function uS(e,t){if(!bo(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=Fn(e._zod.def,{get shape(){let s={...e._zod.def.shape,...t};return yo(this,"shape",s),s}});return an(e,r)}function dS(e,t){if(!bo(t))throw Error("Invalid input to safeExtend: expected a plain object");let n=Fn(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t};return yo(this,"shape",o),o}});return an(e,n)}function pS(e,t){let n=Fn(e._zod.def,{get shape(){let o={...e._zod.def.shape,...t._zod.def.shape};return yo(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return an(e,n)}function mS(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=Fn(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 yo(this,"shape",l),l},checks:[]});return an(t,a)}function fS(e,t,n){let o=Fn(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 yo(this,"shape",s),s}});return an(t,o)}function xo(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 Hn(e,t){return t.map((n)=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function ls(e){return typeof e==="string"?e:e?.message}function cn(e,t,n){let o={...e,path:e.path??[]};if(!e.message){let r=ls(e.inst?._zod.def?.error?.(e))??ls(t?.error?.(e))??ls(n.customError?.(e))??ls(n.localeError?.(e))??"Invalid input";o.message=r}if(delete o.inst,delete o.continue,!t?.reportInput)delete o.input;return o}function ms(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function cm(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 wo(...e){let[t,n,o]=e;if(typeof t==="string")return{message:t,code:"custom",input:n,inst:o};return{...t}}var lm=(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,Kr,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},fs=O("$ZodError",lm),ul=O("$ZodError",lm,{Parent:Error});function um(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 dm(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 hs=(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 fn;if(a.issues.length){let c=new(r?.Err??e)(a.issues.map((l)=>cn(l,s,Ht())));throw al(c,r?.callee),c}return a.value};var gs=(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)=>cn(l,s,Ht())));throw al(c,r?.callee),c}return a.value};var Yr=(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 fn;return s.issues.length?{success:!1,error:new(e??fs)(s.issues.map((a)=>cn(a,r,Ht())))}:{success:!0,data:s.value}},Qr=Yr(ul),ei=(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)=>cn(a,r,Ht())))}:{success:!0,data:s.value}},vs=ei(ul),pm=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return hs(e)(t,n,r)};var mm=(e)=>(t,n,o)=>hs(e)(t,n,o);var fm=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return gs(e)(t,n,r)};var hm=(e)=>async(t,n,o)=>gs(e)(t,n,o);var gm=(e)=>(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return Yr(e)(t,n,r)};var vm=(e)=>(t,n,o)=>Yr(e)(t,n,o);var ym=(e)=>async(t,n,o)=>{let r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ei(e)(t,n,r)};var bm=(e)=>async(t,n,o)=>ei(e)(t,n,o);var xm=/^[cC][^\s-]{8,}$/,wm=/^[0-9a-z]+$/,_m=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Sm=/^[0-9a-vA-V]{20}$/,km=/^[A-Za-z0-9]{27}$/,Cm=/^[a-zA-Z0-9_-]{21}$/,Tm=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Im=/^([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})$/,dl=(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 Em=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var gS="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Am(){return new RegExp(gS,"u")}var zm=/^(?:(?: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])$/,Pm=/^(([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 Nm=/^((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])$/,Rm=/^(([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])$/,$m=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,pl=/^[A-Za-z0-9_-]*$/;var Mm=/^\+[1-9]\d{6,14}$/,Om="(?:(?:\\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])))",Lm=new RegExp(`^${Om}$`);function Dm(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 Fm(e){return new RegExp(`^${Dm(e)}$`)}function Bm(e){let t=Dm({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(`^${Om}T(?:${o})$`)}var Hm=(e)=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var jm=/^-?\d+$/,ml=/^-?\d+(?:\.\d+)?$/,Zm=/^(?:true|false)$/i,Um=/^null$/i;var qm=/^undefined$/i;var Wm=/^[^A-Z]*$/,Vm=/^[^a-z]*$/;var ct=O("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Gm={number:"number",bigint:"bigint",object:"date"},fl=O("$ZodCheckLessThan",(e,t)=>{ct.init(e,t);let n=Gm[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})}}),hl=O("$ZodCheckGreaterThan",(e,t)=>{ct.init(e,t);let n=Gm[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})}}),Xm=O("$ZodCheckMultipleOf",(e,t)=>{ct.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):nm(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})}}),Km=O("$ZodCheckNumberFormat",(e,t)=>{ct.init(e,t),t.format=t.format||"float64";let n=t.format?.includes("int"),o=n?"int":"number",[r,s]=am[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=jm}),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 Jm=O("$ZodCheckMaxLength",(e,t)=>{var n;ct.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!ds(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=ms(r);o.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Ym=O("$ZodCheckMinLength",(e,t)=>{var n;ct.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!ds(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=ms(r);o.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Qm=O("$ZodCheckLengthEquals",(e,t)=>{var n;ct.init(e,t),(n=e._zod.def).when??(n.when=(o)=>{let r=o.value;return!ds(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=ms(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})}}),ti=O("$ZodCheckStringFormat",(e,t)=>{var n,o;if(ct.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=()=>{})}),ef=O("$ZodCheckRegex",(e,t)=>{ti.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})}}),tf=O("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Wm),ti.init(e,t)}),nf=O("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Vm),ti.init(e,t)}),of=O("$ZodCheckIncludes",(e,t)=>{ct.init(e,t);let n=Bn(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})}}),rf=O("$ZodCheckStartsWith",(e,t)=>{ct.init(e,t);let n=new RegExp(`^${Bn(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})}}),sf=O("$ZodCheckEndsWith",(e,t)=>{ct.init(e,t);let n=new RegExp(`.*${Bn(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 af=O("$ZodCheckOverwrite",(e,t)=>{ct.init(e,t),e._zod.check=(n)=>{n.value=t.tx(n.value)}});class gl{constructor(e=[]){if(this.content=[],this.indent=0,this)this.args=e}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let n=e.split(`
23
23
  `).filter((s)=>s),o=Math.min(...n.map((s)=>s.length-s.trimStart().length)),r=n.map((s)=>s.slice(o)).map((s)=>" ".repeat(this.indent*2)+s);for(let s of r)this.content.push(s)}compile(){let e=Function,t=this?.args,o=[...(this?.content??[""]).map((r)=>` ${r}`)];return new e(...t,o.join(`
24
- `))}}var Rm={major:4,minor:3,patch:6};var Re=z("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Rm;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=lo(a),d;for(let p of c){if(p._zod.def.when){if(!p._zod.def.when(a))continue}else if(u)continue;let f=a.issues.length,m=p._zod.check(a);if(m instanceof Promise&&l?.async===!1)throw new an;if(d||m instanceof Promise)d=(d??Promise.resolve()).then(async()=>{if(await m,a.issues.length===f)return;if(!u)u=lo(a,f)});else{if(a.issues.length===f)continue;if(!u)u=lo(a,f)}}if(d)return d.then(()=>a);return a},s=(a,c,l)=>{if(lo(a))return a.aborted=!0,a;let u=r(c,o,l);if(u instanceof Promise){if(l.async===!1)throw new an;return u.then((d)=>e._zod.parse(d,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((d)=>s(d,a,c));return s(u,a,c)}let l=e._zod.parse(a,c);if(l instanceof Promise){if(c.async===!1)throw new an;return l.then((u)=>r(u,o,c))}return r(l,o,c)}}be(e,"~standard",()=>({validate:(r)=>{try{let s=Fr(e,r);return s.success?{value:s.data}:{issues:s.error?.issues}}catch(s){return ns(e,r).then((a)=>a.success?{value:a.data}:{issues:a.error?.issues})}},vendor:"zod",version:1}))}),ss=z("$ZodString",(e,t)=>{Re.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??pm(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}}),Oe=z("$ZodStringFormat",(e,t)=>{Zr.init(e,t),ss.init(e,t)}),Hm=z("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Yp),Oe.init(e,t)}),Bm=z("$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=Bc(o))}else t.pattern??(t.pattern=Bc());Oe.init(e,t)}),Um=z("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Qp),Oe.init(e,t)}),Wm=z("$ZodURL",(e,t)=>{Oe.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})}}}),qm=z("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=em()),Oe.init(e,t)}),Vm=z("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Kp),Oe.init(e,t)}),Gm=z("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Wp),Oe.init(e,t)}),Xm=z("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=qp),Oe.init(e,t)}),Km=z("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Vp),Oe.init(e,t)}),Jm=z("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Gp),Oe.init(e,t)}),Ym=z("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Xp),Oe.init(e,t)}),Qm=z("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=dm(t)),Oe.init(e,t)}),ef=z("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=cm),Oe.init(e,t)}),tf=z("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=um(t)),Oe.init(e,t)}),nf=z("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Jp),Oe.init(e,t)}),of=z("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=tm),Oe.init(e,t),e._zod.bag.format="ipv4"}),rf=z("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=nm),Oe.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 sf=z("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=om),Oe.init(e,t)}),af=z("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=rm),Oe.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 cf(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var lf=z("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=im),Oe.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=(n)=>{if(cf(n.value))return;n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function C_(e){if(!Uc.test(e))return!1;let t=e.replace(/[-_]/g,(o)=>o==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return cf(n)}var uf=z("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Uc),Oe.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=(n)=>{if(C_(n.value))return;n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),df=z("$ZodE164",(e,t)=>{t.pattern??(t.pattern=sm),Oe.init(e,t)});function T_(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 pf=z("$ZodJWT",(e,t)=>{Oe.init(e,t),e._zod.check=(n)=>{if(T_(n.value,t.alg))return;n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}});var Kc=z("$ZodNumber",(e,t)=>{Re.init(e,t),e._zod.pattern=e._zod.bag.pattern??Wc,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}}),mf=z("$ZodNumberFormat",(e,t)=>{wm.init(e,t),Kc.init(e,t)}),ff=z("$ZodBoolean",(e,t)=>{Re.init(e,t),e._zod.pattern=fm,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 hf=z("$ZodUndefined",(e,t)=>{Re.init(e,t),e._zod.pattern=gm,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}}),gf=z("$ZodNull",(e,t)=>{Re.init(e,t),e._zod.pattern=hm,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 vf=z("$ZodUnknown",(e,t)=>{Re.init(e,t),e._zod.parse=(n)=>n}),yf=z("$ZodNever",(e,t)=>{Re.init(e,t),e._zod.parse=(n,o)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function $m(e,t,n){if(e.issues.length)t.issues.push(...Nn(n,e.issues));t.value[n]=e.value}var xf=z("$ZodArray",(e,t)=>{Re.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)=>$m(u,n,a)));else $m(l,n,a)}if(s.length)return Promise.all(s).then(()=>n);return n}});function is(e,t,n,o,r){if(e.issues.length){if(r&&!(n in o))return;t.issues.push(...Nn(n,e.issues))}if(e.value===void 0){if(n in o)t.value[n]=void 0}else t.value[n]=e.value}function bf(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=Pp(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function wf(e,t,n,o,r,s){let a=[],c=r.keySet,l=r.catchall._zod,u=l.def.type,d=l.optout==="optional";for(let p in t){if(c.has(p))continue;if(u==="never"){a.push(p);continue}let f=l.run({value:t[p],issues:[]},o);if(f instanceof Promise)e.push(f.then((m)=>is(m,n,p,t,d)));else is(f,n,p,t,d)}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 E_=z("$ZodObject",(e,t)=>{if(Re.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=Lr(()=>bf(t));be(e._zod,"propValues",()=>{let c=t.shape,l={};for(let u in c){let d=c[u]._zod;if(d.values){l[u]??(l[u]=new Set);for(let p of d.values)l[u].add(p)}}return l});let r=Fo,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 d=[],p=a.shape;for(let f of a.keys){let m=p[f],v=m._zod.optout==="optional",y=m._zod.run({value:u[f],issues:[]},l);if(y instanceof Promise)d.push(y.then((x)=>is(x,c,f,u,v)));else is(y,c,f,u,v)}if(!s)return d.length?Promise.all(d).then(()=>c):c;return wf(d,u,c,l,o.value,e)}}),_f=z("$ZodObjectJIT",(e,t)=>{E_.init(e,t);let n=e._zod.parse,o=Lr(()=>bf(t)),r=(f)=>{let m=new Gc(["shape","payload","ctx"]),v=o.value,y=(b)=>{let E=Dc(b);return`shape[${E}]._zod.run({ value: input[${E}], issues: [] }, ctx)`};m.write("const input = payload.value;");let x=Object.create(null),h=0;for(let b of v.keys)x[b]=`key_${h++}`;m.write("const newResult = {};");for(let b of v.keys){let E=x[b],j=Dc(b),R=f[b]?._zod?.optout==="optional";if(m.write(`const ${E} = ${y(b)};`),R)m.write(`
25
- if (${E}.issues.length) {
26
- if (${j} in input) {
27
- payload.issues = payload.issues.concat(${E}.issues.map(iss => ({
24
+ `))}}var lf={major:4,minor:3,patch:6};var Me=O("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=lf;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=xo(a),p;for(let d of c){if(d._zod.def.when){if(!d._zod.def.when(a))continue}else if(u)continue;let f=a.issues.length,m=d._zod.check(a);if(m instanceof Promise&&l?.async===!1)throw new fn;if(p||m instanceof Promise)p=(p??Promise.resolve()).then(async()=>{if(await m,a.issues.length===f)return;if(!u)u=xo(a,f)});else{if(a.issues.length===f)continue;if(!u)u=xo(a,f)}}if(p)return p.then(()=>a);return a},s=(a,c,l)=>{if(xo(a))return a.aborted=!0,a;let u=r(c,o,l);if(u instanceof Promise){if(l.async===!1)throw new fn;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 fn;return l.then((u)=>r(u,o,c))}return r(l,o,c)}}_e(e,"~standard",()=>({validate:(r)=>{try{let s=Qr(e,r);return s.success?{value:s.data}:{issues:s.error?.issues}}catch(s){return vs(e,r).then((a)=>a.success?{value:a.data}:{issues:a.error?.issues})}},vendor:"zod",version:1}))}),ws=O("$ZodString",(e,t)=>{Me.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Hm(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}}),Fe=O("$ZodStringFormat",(e,t)=>{ti.init(e,t),ws.init(e,t)}),yf=O("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Im),Fe.init(e,t)}),bf=O("$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=dl(o))}else t.pattern??(t.pattern=dl());Fe.init(e,t)}),xf=O("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Em),Fe.init(e,t)}),wf=O("$ZodURL",(e,t)=>{Fe.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})}}}),_f=O("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Am()),Fe.init(e,t)}),Sf=O("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Cm),Fe.init(e,t)}),kf=O("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=xm),Fe.init(e,t)}),Cf=O("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=wm),Fe.init(e,t)}),Tf=O("$ZodULID",(e,t)=>{t.pattern??(t.pattern=_m),Fe.init(e,t)}),If=O("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Sm),Fe.init(e,t)}),Ef=O("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=km),Fe.init(e,t)}),Af=O("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=Bm(t)),Fe.init(e,t)}),zf=O("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Lm),Fe.init(e,t)}),Pf=O("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Fm(t)),Fe.init(e,t)}),Nf=O("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Tm),Fe.init(e,t)}),Rf=O("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=zm),Fe.init(e,t),e._zod.bag.format="ipv4"}),$f=O("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Pm),Fe.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 Mf=O("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Nm),Fe.init(e,t)}),Of=O("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Rm),Fe.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 Lf(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var Df=O("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=$m),Fe.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=(n)=>{if(Lf(n.value))return;n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function bS(e){if(!pl.test(e))return!1;let t=e.replace(/[-_]/g,(o)=>o==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return Lf(n)}var Ff=O("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=pl),Fe.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=(n)=>{if(bS(n.value))return;n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Bf=O("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Mm),Fe.init(e,t)});function xS(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 Hf=O("$ZodJWT",(e,t)=>{Fe.init(e,t),e._zod.check=(n)=>{if(xS(n.value,t.alg))return;n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}});var yl=O("$ZodNumber",(e,t)=>{Me.init(e,t),e._zod.pattern=e._zod.bag.pattern??ml,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}}),jf=O("$ZodNumberFormat",(e,t)=>{Km.init(e,t),yl.init(e,t)}),Zf=O("$ZodBoolean",(e,t)=>{Me.init(e,t),e._zod.pattern=Zm,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 Uf=O("$ZodUndefined",(e,t)=>{Me.init(e,t),e._zod.pattern=qm,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}}),qf=O("$ZodNull",(e,t)=>{Me.init(e,t),e._zod.pattern=Um,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 Wf=O("$ZodUnknown",(e,t)=>{Me.init(e,t),e._zod.parse=(n)=>n}),Vf=O("$ZodNever",(e,t)=>{Me.init(e,t),e._zod.parse=(n,o)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function uf(e,t,n){if(e.issues.length)t.issues.push(...Hn(n,e.issues));t.value[n]=e.value}var Gf=O("$ZodArray",(e,t)=>{Me.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)=>uf(u,n,a)));else uf(l,n,a)}if(s.length)return Promise.all(s).then(()=>n);return n}});function xs(e,t,n,o,r){if(e.issues.length){if(r&&!(n in o))return;t.issues.push(...Hn(n,e.issues))}if(e.value===void 0){if(n in o)t.value[n]=void 0}else t.value[n]=e.value}function Xf(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=sm(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Kf(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 f=l.run({value:t[d],issues:[]},o);if(f instanceof Promise)e.push(f.then((m)=>xs(m,n,d,t,p)));else xs(f,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 wS=O("$ZodObject",(e,t)=>{if(Me.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=Jr(()=>Xf(t));_e(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=Xo,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 f of a.keys){let m=d[f],h=m._zod.optout==="optional",v=m._zod.run({value:u[f],issues:[]},l);if(v instanceof Promise)p.push(v.then((x)=>xs(x,c,f,u,h)));else xs(v,c,f,u,h)}if(!s)return p.length?Promise.all(p).then(()=>c):c;return Kf(p,u,c,l,o.value,e)}}),Jf=O("$ZodObjectJIT",(e,t)=>{wS.init(e,t);let n=e._zod.parse,o=Jr(()=>Xf(t)),r=(f)=>{let m=new gl(["shape","payload","ctx"]),h=o.value,v=(E)=>{let L=sl(E);return`shape[${L}]._zod.run({ value: input[${L}], issues: [] }, ctx)`};m.write("const input = payload.value;");let x=Object.create(null),g=0;for(let E of h.keys)x[E]=`key_${g++}`;m.write("const newResult = {};");for(let E of h.keys){let L=x[E],P=sl(E),T=f[E]?._zod?.optout==="optional";if(m.write(`const ${L} = ${v(E)};`),T)m.write(`
25
+ if (${L}.issues.length) {
26
+ if (${P} in input) {
27
+ payload.issues = payload.issues.concat(${L}.issues.map(iss => ({
28
28
  ...iss,
29
- path: iss.path ? [${j}, ...iss.path] : [${j}]
29
+ path: iss.path ? [${P}, ...iss.path] : [${P}]
30
30
  })));
31
31
  }
32
32
  }
33
33
 
34
- if (${E}.value === undefined) {
35
- if (${j} in input) {
36
- newResult[${j}] = undefined;
34
+ if (${L}.value === undefined) {
35
+ if (${P} in input) {
36
+ newResult[${P}] = undefined;
37
37
  }
38
38
  } else {
39
- newResult[${j}] = ${E}.value;
39
+ newResult[${P}] = ${L}.value;
40
40
  }
41
41
 
42
42
  `);else m.write(`
43
- if (${E}.issues.length) {
44
- payload.issues = payload.issues.concat(${E}.issues.map(iss => ({
43
+ if (${L}.issues.length) {
44
+ payload.issues = payload.issues.concat(${L}.issues.map(iss => ({
45
45
  ...iss,
46
- path: iss.path ? [${j}, ...iss.path] : [${j}]
46
+ path: iss.path ? [${P}, ...iss.path] : [${P}]
47
47
  })));
48
48
  }
49
49
 
50
- if (${E}.value === undefined) {
51
- if (${j} in input) {
52
- newResult[${j}] = undefined;
50
+ if (${L}.value === undefined) {
51
+ if (${P} in input) {
52
+ newResult[${P}] = undefined;
53
53
  }
54
54
  } else {
55
- newResult[${j}] = ${E}.value;
55
+ newResult[${P}] = ${L}.value;
56
56
  }
57
57
 
58
- `)}m.write("payload.value = newResult;"),m.write("return payload;");let g=m.compile();return(b,E)=>g(f,b,E)},s,a=Fo,c=!Vi.jitless,u=c&&Ip.value,d=t.catchall,p;e._zod.parse=(f,m)=>{p??(p=o.value);let v=f.value;if(!a(v))return f.issues.push({expected:"object",code:"invalid_type",input:v,inst:e}),f;if(c&&u&&m?.async===!1&&m.jitless!==!0){if(!s)s=r(t.shape);if(f=s(f,m),!d)return f;return wf([],v,f,m,p,e)}return n(f,m)}});function Mm(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)=>!lo(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)=>Yt(a,o,Mt())))}),t}var Jc=z("$ZodUnion",(e,t)=>{Re.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)=>Ji(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 Mm(c,r,e,s);return Promise.all(c).then((l)=>Mm(l,r,e,s))}});var Sf=z("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Jc.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=Lr(()=>{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(!Fo(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}}),kf=z("$ZodIntersection",(e,t)=>{Re.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])=>Om(n,l,u));return Om(n,s,a)}});function Xc(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(co(e)&&co(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=Xc(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=Xc(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 Om(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(lo(e))return e;let a=Xc(t.value,n.value);if(!a.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return e.value=a.data,e}var Cf=z("$ZodRecord",(e,t)=>{Re.init(e,t),e._zod.parse=(n,o)=>{let r=n.value;if(!co(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 d=t.valueType._zod.run({value:r[u],issues:[]},o);if(d instanceof Promise)s.push(d.then((p)=>{if(p.issues.length)n.issues.push(...Nn(u,p.issues));n.value[u]=p.value}));else{if(d.issues.length)n.issues.push(...Nn(u,d.issues));n.value[u]=d.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"&&Wc.test(c)&&l.issues.length){let p=t.keyType._zod.run({value:Number(c),issues:[]},o);if(p instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(p.issues.length===0)l=p}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((p)=>Yt(p,o,Mt())),input:c,path:[c],inst:e});continue}let d=t.valueType._zod.run({value:r[c],issues:[]},o);if(d instanceof Promise)s.push(d.then((p)=>{if(p.issues.length)n.issues.push(...Nn(c,p.issues));n.value[l.value]=p.value}));else{if(d.issues.length)n.issues.push(...Nn(c,d.issues));n.value[l.value]=d.value}}}if(s.length)return Promise.all(s).then(()=>n);return n}});var Tf=z("$ZodEnum",(e,t)=>{Re.init(e,t);let n=Xi(t.entries),o=new Set(n);e._zod.values=o,e._zod.pattern=new RegExp(`^(${n.filter((r)=>zp.has(typeof r)).map((r)=>typeof r==="string"?Pn(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}}),Ef=z("$ZodLiteral",(e,t)=>{if(Re.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"?Pn(o):o?Pn(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 Af=z("$ZodTransform",(e,t)=>{Re.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new Mr(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 an;return n.value=r,n}});function Lm(e,t){if(e.issues.length&&t===void 0)return{issues:[],value:void 0};return e}var Yc=z("$ZodOptional",(e,t)=>{Re.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(`^(${Ji(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)=>Lm(s,n.value));return Lm(r,n.value)}if(n.value===void 0)return n;return t.innerType._zod.run(n,o)}}),If=z("$ZodExactOptional",(e,t)=>{Yc.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)}),zf=z("$ZodNullable",(e,t)=>{Re.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(`^(${Ji(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)}}),Pf=z("$ZodDefault",(e,t)=>{Re.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)=>Dm(s,t));return Dm(r,t)}});function Dm(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var Nf=z("$ZodPrefault",(e,t)=>{Re.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)}}),Rf=z("$ZodNonOptional",(e,t)=>{Re.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)=>Fm(s,e));return Fm(r,e)}});function Fm(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 $f=z("$ZodCatch",(e,t)=>{Re.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)=>Yt(a,o,Mt()))},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)=>Yt(s,o,Mt()))},input:n.value}),n.issues=[];return n}});var Mf=z("$ZodPipe",(e,t)=>{Re.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)=>rs(a,t.in,o));return rs(s,t.in,o)}let r=t.in._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>rs(s,t.out,o));return rs(r,t.out,o)}});function rs(e,t,n){if(e.issues.length)return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},n)}var Of=z("$ZodReadonly",(e,t)=>{Re.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(jm);return jm(r)}});function jm(e){return e.value=Object.freeze(e.value),e}var Lf=z("$ZodCustom",(e,t)=>{it.init(e,t),Re.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)=>Zm(s,n,o,e));Zm(r,n,o,e);return}});function Zm(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(uo(r))}}var A_=()=>{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=Rp(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 ${Zc(r.values[0])}`;return`Invalid option: expected one of ${Lc(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":""}: ${Lc(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 Qc(){return{localeError:A_()}}var Df,Rz=Symbol("ZodOutput"),$z=Symbol("ZodInput");class Ff{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 I_(){return new Ff}(Df=globalThis).__zod_globalRegistry??(Df.__zod_globalRegistry=I_());var po=globalThis.__zod_globalRegistry;function jf(e,t){return new e({type:"string",...G(t)})}function Zf(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...G(t)})}function el(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...G(t)})}function Hf(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...G(t)})}function Bf(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...G(t)})}function Uf(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...G(t)})}function Wf(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...G(t)})}function qf(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...G(t)})}function Vf(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...G(t)})}function Gf(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...G(t)})}function Xf(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...G(t)})}function Kf(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...G(t)})}function Jf(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...G(t)})}function Yf(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...G(t)})}function Qf(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...G(t)})}function eh(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...G(t)})}function th(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...G(t)})}function nh(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...G(t)})}function oh(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...G(t)})}function rh(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...G(t)})}function ih(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...G(t)})}function sh(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...G(t)})}function ah(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...G(t)})}function ch(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...G(t)})}function lh(e,t){return new e({type:"string",format:"date",check:"string_format",...G(t)})}function uh(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...G(t)})}function dh(e,t){return new e({type:"string",format:"duration",check:"string_format",...G(t)})}function ph(e,t){return new e({type:"number",checks:[],...G(t)})}function mh(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...G(t)})}function fh(e,t){return new e({type:"boolean",...G(t)})}function hh(e,t){return new e({type:"undefined",...G(t)})}function gh(e,t){return new e({type:"null",...G(t)})}function vh(e){return new e({type:"unknown"})}function yh(e,t){return new e({type:"never",...G(t)})}function as(e,t){return new qc({check:"less_than",...G(t),value:e,inclusive:!1})}function Hr(e,t){return new qc({check:"less_than",...G(t),value:e,inclusive:!0})}function cs(e,t){return new Vc({check:"greater_than",...G(t),value:e,inclusive:!1})}function Br(e,t){return new Vc({check:"greater_than",...G(t),value:e,inclusive:!0})}function ls(e,t){return new bm({check:"multiple_of",...G(t),value:e})}function us(e,t){return new _m({check:"max_length",...G(t),maximum:e})}function jo(e,t){return new Sm({check:"min_length",...G(t),minimum:e})}function ds(e,t){return new km({check:"length_equals",...G(t),length:e})}function tl(e,t){return new Cm({check:"string_format",format:"regex",...G(t),pattern:e})}function nl(e){return new Tm({check:"string_format",format:"lowercase",...G(e)})}function ol(e){return new Em({check:"string_format",format:"uppercase",...G(e)})}function rl(e,t){return new Am({check:"string_format",format:"includes",...G(t),includes:e})}function il(e,t){return new Im({check:"string_format",format:"starts_with",...G(t),prefix:e})}function sl(e,t){return new zm({check:"string_format",format:"ends_with",...G(t),suffix:e})}function Rn(e){return new Pm({check:"overwrite",tx:e})}function al(e){return Rn((t)=>t.normalize(e))}function cl(){return Rn((e)=>e.trim())}function ll(){return Rn((e)=>e.toLowerCase())}function ul(){return Rn((e)=>e.toUpperCase())}function dl(){return Rn((e)=>Ap(e))}function xh(e,t,n){return new e({type:"array",element:t,...G(n)})}function bh(e,t,n){let o=G(n);return o.abort??(o.abort=!0),new e({type:"custom",check:"custom",fn:t,...o})}function wh(e,t,n){return new e({type:"custom",check:"custom",fn:t,...G(n)})}function _h(e){let t=z_((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(uo(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(uo(r))}},e(n.value,n)));return t}function z_(e,t){let n=new it({check:"custom",...G(t)});return n._zod.check=e,n}function pl(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??po,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 Ke(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 d={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,a.schema,d);else{let f=a.schema,m=t.processors[r.type];if(!m)throw Error(`[toJSONSchema]: Non-representable type encountered: ${r.type}`);m(e,t,f,d)}let p=e._zod.parent;if(p){if(!a.ref)a.ref=p;Ke(p,t,d),t.seen.get(p).isParent=!0}}let l=t.metadataRegistry.get(e);if(l)Object.assign(a.schema,l);if(t.io==="input"&&xt(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 ml(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 p=e.external.registry.get(a[0])?.id,f=e.external.uri??((v)=>v);if(p)return{ref:f(p)};let m=a[1].defId??a[1].schema.id??`schema${e.counter++}`;return a[1].defId=m,{defId:m,ref:`${f("__shared")}#/${c}/${m}`}}if(a[1]===n)return{ref:"#"};let u=`${"#"}/${c}/`,d=a[1].schema.id??`__schema${e.counter++}`;return{defId:d,ref:u+d}},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 d=c.schema;for(let p in d)delete d[p];d.$ref=l};if(e.cycles==="throw")for(let a of e.seen.entries()){let c=a[1];if(c.cycle)throw Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
58
+ `)}m.write("payload.value = newResult;"),m.write("return payload;");let y=m.compile();return(E,L)=>y(f,E,L)},s,a=Xo,c=!cs.jitless,u=c&&rm.value,p=t.catchall,d;e._zod.parse=(f,m)=>{d??(d=o.value);let h=f.value;if(!a(h))return f.issues.push({expected:"object",code:"invalid_type",input:h,inst:e}),f;if(c&&u&&m?.async===!1&&m.jitless!==!0){if(!s)s=r(t.shape);if(f=s(f,m),!p)return f;return Kf([],h,f,m,d,e)}return n(f,m)}});function df(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)=>!xo(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)=>cn(a,o,Ht())))}),t}var bl=O("$ZodUnion",(e,t)=>{Me.init(e,t),_e(e._zod,"optin",()=>t.options.some((r)=>r._zod.optin==="optional")?"optional":void 0),_e(e._zod,"optout",()=>t.options.some((r)=>r._zod.optout==="optional")?"optional":void 0),_e(e._zod,"values",()=>{if(t.options.every((r)=>r._zod.values))return new Set(t.options.flatMap((r)=>Array.from(r._zod.values)));return}),_e(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)=>ps(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 df(c,r,e,s);return Promise.all(c).then((l)=>df(l,r,e,s))}});var Yf=O("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,bl.init(e,t);let n=e._zod.parse;_e(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=Jr(()=>{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(!Xo(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}}),Qf=O("$ZodIntersection",(e,t)=>{Me.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])=>pf(n,l,u));return pf(n,s,a)}});function vl(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(bo(e)&&bo(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=vl(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=vl(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 pf(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(xo(e))return e;let a=vl(t.value,n.value);if(!a.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return e.value=a.data,e}var eh=O("$ZodRecord",(e,t)=>{Me.init(e,t),e._zod.parse=(n,o)=>{let r=n.value;if(!bo(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(...Hn(u,d.issues));n.value[u]=d.value}));else{if(p.issues.length)n.issues.push(...Hn(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"&&ml.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)=>cn(d,o,Ht())),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(...Hn(c,d.issues));n.value[l.value]=d.value}));else{if(p.issues.length)n.issues.push(...Hn(c,p.issues));n.value[l.value]=p.value}}}if(s.length)return Promise.all(s).then(()=>n);return n}});var th=O("$ZodEnum",(e,t)=>{Me.init(e,t);let n=us(t.entries),o=new Set(n);e._zod.values=o,e._zod.pattern=new RegExp(`^(${n.filter((r)=>im.has(typeof r)).map((r)=>typeof r==="string"?Bn(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}}),nh=O("$ZodLiteral",(e,t)=>{if(Me.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"?Bn(o):o?Bn(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 oh=O("$ZodTransform",(e,t)=>{Me.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new Xr(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 fn;return n.value=r,n}});function mf(e,t){if(e.issues.length&&t===void 0)return{issues:[],value:void 0};return e}var xl=O("$ZodOptional",(e,t)=>{Me.init(e,t),e._zod.optin="optional",e._zod.optout="optional",_e(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),_e(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${ps(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)=>mf(s,n.value));return mf(r,n.value)}if(n.value===void 0)return n;return t.innerType._zod.run(n,o)}}),rh=O("$ZodExactOptional",(e,t)=>{xl.init(e,t),_e(e._zod,"values",()=>t.innerType._zod.values),_e(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,o)=>t.innerType._zod.run(n,o)}),ih=O("$ZodNullable",(e,t)=>{Me.init(e,t),_e(e._zod,"optin",()=>t.innerType._zod.optin),_e(e._zod,"optout",()=>t.innerType._zod.optout),_e(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${ps(n.source)}|null)$`):void 0}),_e(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)}}),sh=O("$ZodDefault",(e,t)=>{Me.init(e,t),e._zod.optin="optional",_e(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)=>ff(s,t));return ff(r,t)}});function ff(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var ah=O("$ZodPrefault",(e,t)=>{Me.init(e,t),e._zod.optin="optional",_e(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)}}),ch=O("$ZodNonOptional",(e,t)=>{Me.init(e,t),_e(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)=>hf(s,e));return hf(r,e)}});function hf(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 lh=O("$ZodCatch",(e,t)=>{Me.init(e,t),_e(e._zod,"optin",()=>t.innerType._zod.optin),_e(e._zod,"optout",()=>t.innerType._zod.optout),_e(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)=>cn(a,o,Ht()))},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)=>cn(s,o,Ht()))},input:n.value}),n.issues=[];return n}});var uh=O("$ZodPipe",(e,t)=>{Me.init(e,t),_e(e._zod,"values",()=>t.in._zod.values),_e(e._zod,"optin",()=>t.in._zod.optin),_e(e._zod,"optout",()=>t.out._zod.optout),_e(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)=>bs(a,t.in,o));return bs(s,t.in,o)}let r=t.in._zod.run(n,o);if(r instanceof Promise)return r.then((s)=>bs(s,t.out,o));return bs(r,t.out,o)}});function bs(e,t,n){if(e.issues.length)return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},n)}var dh=O("$ZodReadonly",(e,t)=>{Me.init(e,t),_e(e._zod,"propValues",()=>t.innerType._zod.propValues),_e(e._zod,"values",()=>t.innerType._zod.values),_e(e._zod,"optin",()=>t.innerType?._zod?.optin),_e(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(gf);return gf(r)}});function gf(e){return e.value=Object.freeze(e.value),e}var ph=O("$ZodCustom",(e,t)=>{ct.init(e,t),Me.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)=>vf(s,n,o,e));vf(r,n,o,e);return}});function vf(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(wo(r))}}var _S=()=>{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=cm(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 ${ll(r.values[0])}`;return`Invalid option: expected one of ${il(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":""}: ${il(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 wl(){return{localeError:_S()}}var mh,Lz=Symbol("ZodOutput"),Dz=Symbol("ZodInput");class fh{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 SS(){return new fh}(mh=globalThis).__zod_globalRegistry??(mh.__zod_globalRegistry=SS());var _o=globalThis.__zod_globalRegistry;function hh(e,t){return new e({type:"string",...G(t)})}function gh(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...G(t)})}function _l(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...G(t)})}function vh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...G(t)})}function yh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...G(t)})}function bh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...G(t)})}function xh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...G(t)})}function wh(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...G(t)})}function _h(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...G(t)})}function Sh(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...G(t)})}function kh(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...G(t)})}function Ch(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...G(t)})}function Th(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...G(t)})}function Ih(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...G(t)})}function Eh(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...G(t)})}function Ah(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...G(t)})}function zh(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...G(t)})}function Ph(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...G(t)})}function Nh(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...G(t)})}function Rh(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...G(t)})}function $h(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...G(t)})}function Mh(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...G(t)})}function Oh(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...G(t)})}function Lh(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...G(t)})}function Dh(e,t){return new e({type:"string",format:"date",check:"string_format",...G(t)})}function Fh(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...G(t)})}function Bh(e,t){return new e({type:"string",format:"duration",check:"string_format",...G(t)})}function Hh(e,t){return new e({type:"number",checks:[],...G(t)})}function jh(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...G(t)})}function Zh(e,t){return new e({type:"boolean",...G(t)})}function Uh(e,t){return new e({type:"undefined",...G(t)})}function qh(e,t){return new e({type:"null",...G(t)})}function Wh(e){return new e({type:"unknown"})}function Vh(e,t){return new e({type:"never",...G(t)})}function _s(e,t){return new fl({check:"less_than",...G(t),value:e,inclusive:!1})}function ni(e,t){return new fl({check:"less_than",...G(t),value:e,inclusive:!0})}function Ss(e,t){return new hl({check:"greater_than",...G(t),value:e,inclusive:!1})}function oi(e,t){return new hl({check:"greater_than",...G(t),value:e,inclusive:!0})}function ks(e,t){return new Xm({check:"multiple_of",...G(t),value:e})}function Cs(e,t){return new Jm({check:"max_length",...G(t),maximum:e})}function Ko(e,t){return new Ym({check:"min_length",...G(t),minimum:e})}function Ts(e,t){return new Qm({check:"length_equals",...G(t),length:e})}function Sl(e,t){return new ef({check:"string_format",format:"regex",...G(t),pattern:e})}function kl(e){return new tf({check:"string_format",format:"lowercase",...G(e)})}function Cl(e){return new nf({check:"string_format",format:"uppercase",...G(e)})}function Tl(e,t){return new of({check:"string_format",format:"includes",...G(t),includes:e})}function Il(e,t){return new rf({check:"string_format",format:"starts_with",...G(t),prefix:e})}function El(e,t){return new sf({check:"string_format",format:"ends_with",...G(t),suffix:e})}function jn(e){return new af({check:"overwrite",tx:e})}function Al(e){return jn((t)=>t.normalize(e))}function zl(){return jn((e)=>e.trim())}function Pl(){return jn((e)=>e.toLowerCase())}function Nl(){return jn((e)=>e.toUpperCase())}function Rl(){return jn((e)=>om(e))}function Gh(e,t,n){return new e({type:"array",element:t,...G(n)})}function Xh(e,t,n){let o=G(n);return o.abort??(o.abort=!0),new e({type:"custom",check:"custom",fn:t,...o})}function Kh(e,t,n){return new e({type:"custom",check:"custom",fn:t,...G(n)})}function Jh(e){let t=kS((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(wo(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(wo(r))}},e(n.value,n)));return t}function kS(e,t){let n=new ct({check:"custom",...G(t)});return n._zod.check=e,n}function $l(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??_o,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 Ye(e,t,n={path:[],schemaPath:[]}){var o;let r=e._zod.def,s=t.seen.get(e);if(s){if(s.count++,n.schemaPath.includes(e))s.cycle=n.path;return s.schema}let a={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,a);let c=e._zod.toJSONSchema?.();if(c)a.schema=c;else{let p={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,a.schema,p);else{let f=a.schema,m=t.processors[r.type];if(!m)throw Error(`[toJSONSchema]: Non-representable type encountered: ${r.type}`);m(e,t,f,p)}let d=e._zod.parent;if(d){if(!a.ref)a.ref=d;Ye(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"&&St(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 Ml(e,t){let n=e.seen.get(t);if(!n)throw Error("Unprocessed schema. This is a bug in Zod.");let o=new Map;for(let a of e.seen.entries()){let c=e.metadataRegistry.get(a[0])?.id;if(c){let l=o.get(c);if(l&&l!==a[0])throw Error(`Duplicate schema id "${c}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);o.set(c,a[0])}}let r=(a)=>{let c=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let d=e.external.registry.get(a[0])?.id,f=e.external.uri??((h)=>h);if(d)return{ref:f(d)};let m=a[1].defId??a[1].schema.id??`schema${e.counter++}`;return a[1].defId=m,{defId:m,ref:`${f("__shared")}#/${c}/${m}`}}if(a[1]===n)return{ref:"#"};let u=`${"#"}/${c}/`,p=a[1].schema.id??`__schema${e.counter++}`;return{defId:p,ref:u+p}},s=(a)=>{if(a[1].schema.$ref)return;let c=a[1],{ref:l,defId:u}=r(a);if(c.def={...c.schema},u)c.defId=u;let p=c.schema;for(let d in p)delete p[d];p.$ref=l};if(e.cycles==="throw")for(let a of e.seen.entries()){let c=a[1];if(c.cycle)throw Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
59
59
 
60
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let a of e.seen.entries()){let c=a[1];if(t===a[0]){s(a);continue}if(e.external){let u=e.external.registry.get(a[0])?.id;if(t!==a[0]&&u){s(a);continue}}if(e.metadataRegistry.get(a[0])?.id){s(a);continue}if(c.cycle){s(a);continue}if(c.count>1){if(e.reused==="ref"){s(a);continue}}}}function fl(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},d=c.ref;if(c.ref=null,d){o(d);let f=e.seen.get(d),m=f.schema;if(m.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))l.allOf=l.allOf??[],l.allOf.push(m);else Object.assign(l,m);if(Object.assign(l,u),a._zod.parent===d)for(let y in l){if(y==="$ref"||y==="allOf")continue;if(!(y in u))delete l[y]}if(m.$ref&&f.def)for(let y in l){if(y==="$ref"||y==="allOf")continue;if(y in f.def&&JSON.stringify(l[y])===JSON.stringify(f.def[y]))delete l[y]}}let p=a._zod.parent;if(p&&p!==d){o(p);let f=e.seen.get(p);if(f?.schema.$ref){if(l.$ref=f.schema.$ref,f.def)for(let m in l){if(m==="$ref"||m==="allOf")continue;if(m in f.def&&JSON.stringify(l[m])===JSON.stringify(f.def[m]))delete l[m]}}}e.override({zodSchema:a,jsonSchema:l,path:c.path??[]})};for(let a of[...e.seen.entries()].reverse())o(a[0]);let r={};if(e.target==="draft-2020-12")r.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")r.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")r.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let a=e.external.registry.get(t)?.id;if(!a)throw Error("Schema is missing an `id` property");r.$id=e.external.uri(a)}Object.assign(r,n.def??n.schema);let s=e.external?.defs??{};for(let a of e.seen.entries()){let c=a[1];if(c.def&&c.defId)s[c.defId]=c.def}if(e.external);else if(Object.keys(s).length>0)if(e.target==="draft-2020-12")r.$defs=s;else r.definitions=s;try{let a=JSON.parse(JSON.stringify(r));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:Ur(t,"input",e.processors),output:Ur(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function xt(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 xt(o.element,n);if(o.type==="set")return xt(o.valueType,n);if(o.type==="lazy")return xt(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 xt(o.innerType,n);if(o.type==="intersection")return xt(o.left,n)||xt(o.right,n);if(o.type==="record"||o.type==="map")return xt(o.keyType,n)||xt(o.valueType,n);if(o.type==="pipe")return xt(o.in,n)||xt(o.out,n);if(o.type==="object"){for(let r in o.shape)if(xt(o.shape[r],n))return!0;return!1}if(o.type==="union"){for(let r of o.options)if(xt(r,n))return!0;return!1}if(o.type==="tuple"){for(let r of o.items)if(xt(r,n))return!0;if(o.rest&&xt(o.rest,n))return!0;return!1}return!1}var Sh=(e,t={})=>(n)=>{let o=pl({...n,processors:t});return Ke(e,o),ml(o,e),fl(o,e)},Ur=(e,t,n={})=>(o)=>{let{libraryOptions:r,target:s}=o??{},a=pl({...r??{},target:s,io:t,processors:n});return Ke(e,a),ml(a,e),fl(a,e)};var P_={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},kh=(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=P_[c]??c,r.format==="")delete r.format;if(c==="time")delete r.format}if(u)r.contentEncoding=u;if(l&&l.size>0){let d=[...l];if(d.length===1)r.pattern=d[0].source;else if(d.length>1)r.allOf=[...d.map((p)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:p.source}))]}},Ch=(e,t,n,o)=>{let r=n,{minimum:s,maximum:a,format:c,multipleOf:l,exclusiveMaximum:u,exclusiveMinimum:d}=e._zod.bag;if(typeof c==="string"&&c.includes("int"))r.type="integer";else r.type="number";if(typeof d==="number")if(t.target==="draft-04"||t.target==="openapi-3.0")r.minimum=d,r.exclusiveMinimum=!0;else r.exclusiveMinimum=d;if(typeof s==="number"){if(r.minimum=s,typeof d==="number"&&t.target!=="draft-04")if(d>=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},Th=(e,t,n,o)=>{n.type="boolean"};var Eh=(e,t,n,o)=>{if(t.target==="openapi-3.0")n.type="string",n.nullable=!0,n.enum=[null];else n.type="null"},Ah=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Undefined cannot be represented in JSON Schema")};var Ih=(e,t,n,o)=>{n.not={}};var zh=(e,t,n,o)=>{};var Ph=(e,t,n,o)=>{let r=e._zod.def,s=Xi(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},Nh=(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 Rh=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Custom types cannot be represented in JSON Schema")};var $h=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Transforms cannot be represented in JSON Schema")};var Mh=(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=Ke(s.element,t,{...o,path:[...o.path,"items"]})},Oh=(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]=Ke(a[u],t,{...o,path:[...o.path,"properties",u]});let c=new Set(Object.keys(a)),l=new Set([...c].filter((u)=>{let d=s.shape[u]._zod;if(t.io==="input")return d.optin===void 0;else return d.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=Ke(s.catchall,t,{...o,path:[...o.path,"additionalProperties"]})},Lh=(e,t,n,o)=>{let r=e._zod.def,s=r.inclusive===!1,a=r.options.map((c,l)=>Ke(c,t,{...o,path:[...o.path,s?"oneOf":"anyOf",l]}));if(s)n.oneOf=a;else n.anyOf=a},Dh=(e,t,n,o)=>{let r=e._zod.def,s=Ke(r.left,t,{...o,path:[...o.path,"allOf",0]}),a=Ke(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 Fh=(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 d=Ke(s.valueType,t,{...o,path:[...o.path,"patternProperties","*"]});r.patternProperties={};for(let p of l)r.patternProperties[p.source]=d}else{if(t.target==="draft-07"||t.target==="draft-2020-12")r.propertyNames=Ke(s.keyType,t,{...o,path:[...o.path,"propertyNames"]});r.additionalProperties=Ke(s.valueType,t,{...o,path:[...o.path,"additionalProperties"]})}let u=a._zod.values;if(u){let d=[...u].filter((p)=>typeof p==="string"||typeof p==="number");if(d.length>0)r.required=d}},jh=(e,t,n,o)=>{let r=e._zod.def,s=Ke(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"}]},Zh=(e,t,n,o)=>{let r=e._zod.def;Ke(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType},Hh=(e,t,n,o)=>{let r=e._zod.def;Ke(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.default=JSON.parse(JSON.stringify(r.defaultValue))},Bh=(e,t,n,o)=>{let r=e._zod.def;Ke(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))},Uh=(e,t,n,o)=>{let r=e._zod.def;Ke(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},Wh=(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;Ke(s,t,o);let a=t.seen.get(e);a.ref=s},qh=(e,t,n,o)=>{let r=e._zod.def;Ke(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.readOnly=!0};var hl=(e,t,n,o)=>{let r=e._zod.def;Ke(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType};var F_=z("ZodISODateTime",(e,t)=>{Qm.init(e,t),je.init(e,t)});function gl(e){return ch(F_,e)}var j_=z("ZodISODate",(e,t)=>{ef.init(e,t),je.init(e,t)});function Vh(e){return lh(j_,e)}var Z_=z("ZodISOTime",(e,t)=>{tf.init(e,t),je.init(e,t)});function Gh(e){return uh(Z_,e)}var H_=z("ZodISODuration",(e,t)=>{nf.init(e,t),je.init(e,t)});function Xh(e){return dh(H_,e)}var Kh=(e,t)=>{Qi.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:(n)=>Op(e,n)},flatten:{value:(n)=>Mp(e,n)},addIssue:{value:(n)=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Or,2)}},addIssues:{value:(n)=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Or,2)}},isEmpty:{get(){return e.issues.length===0}}})},u1=z("ZodError",Kh),Tt=z("ZodError",Kh,{Parent:Error});var Jh=es(Tt),Yh=ts(Tt),Qh=Dr(Tt),eg=jr(Tt),tg=Lp(Tt),ng=Dp(Tt),og=Fp(Tt),rg=jp(Tt),ig=Zp(Tt),sg=Hp(Tt),ag=Bp(Tt),cg=Up(Tt);var Le=z("ZodType",(e,t)=>(Re.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:Ur(e,"input"),output:Ur(e,"output")}}),e.toJSONSchema=Sh(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(zn(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)=>Jt(e,n,o),e.brand=()=>e,e.register=(n,o)=>(n.add(e,o),e),e.parse=(n,o)=>Jh(e,n,o,{callee:e.parse}),e.safeParse=(n,o)=>Qh(e,n,o),e.parseAsync=async(n,o)=>Yh(e,n,o,{callee:e.parseAsync}),e.safeParseAsync=async(n,o)=>eg(e,n,o),e.spa=e.safeParseAsync,e.encode=(n,o)=>tg(e,n,o),e.decode=(n,o)=>ng(e,n,o),e.encodeAsync=async(n,o)=>og(e,n,o),e.decodeAsync=async(n,o)=>rg(e,n,o),e.safeEncode=(n,o)=>ig(e,n,o),e.safeDecode=(n,o)=>sg(e,n,o),e.safeEncodeAsync=async(n,o)=>ag(e,n,o),e.safeDecodeAsync=async(n,o)=>cg(e,n,o),e.refine=(n,o)=>e.check($S(n,o)),e.superRefine=(n)=>e.check(MS(n)),e.overwrite=(n)=>e.check(Rn(n)),e.optional=()=>Be(e),e.exactOptional=()=>_S(e),e.nullable=()=>dg(e),e.nullish=()=>Be(dg(e)),e.nonoptional=(n)=>AS(e,n),e.array=()=>re(e),e.or=(n)=>ue([e,n]),e.and=(n)=>ms(e,n),e.transform=(n)=>xl(e,vg(n)),e.default=(n)=>CS(e,n),e.prefault=(n)=>ES(e,n),e.catch=(n)=>zS(e,n),e.pipe=(n)=>xl(e,n),e.readonly=()=>RS(e),e.describe=(n)=>{let o=e.clone();return po.add(o,{description:n}),o},Object.defineProperty(e,"description",{get(){return po.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return po.get(e);let o=e.clone();return po.add(o,n[0]),o},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=(n)=>n(e),e)),pg=z("_ZodString",(e,t)=>{ss.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(o,r,s)=>kh(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(tl(...o)),e.includes=(...o)=>e.check(rl(...o)),e.startsWith=(...o)=>e.check(il(...o)),e.endsWith=(...o)=>e.check(sl(...o)),e.min=(...o)=>e.check(jo(...o)),e.max=(...o)=>e.check(us(...o)),e.length=(...o)=>e.check(ds(...o)),e.nonempty=(...o)=>e.check(jo(1,...o)),e.lowercase=(o)=>e.check(nl(o)),e.uppercase=(o)=>e.check(ol(o)),e.trim=()=>e.check(cl()),e.normalize=(...o)=>e.check(al(...o)),e.toLowerCase=()=>e.check(ll()),e.toUpperCase=()=>e.check(ul()),e.slugify=()=>e.check(dl())}),W_=z("ZodString",(e,t)=>{ss.init(e,t),pg.init(e,t),e.email=(n)=>e.check(Zf(q_,n)),e.url=(n)=>e.check(qf(V_,n)),e.jwt=(n)=>e.check(ah(cS,n)),e.emoji=(n)=>e.check(Vf(G_,n)),e.guid=(n)=>e.check(el(lg,n)),e.uuid=(n)=>e.check(Hf(ps,n)),e.uuidv4=(n)=>e.check(Bf(ps,n)),e.uuidv6=(n)=>e.check(Uf(ps,n)),e.uuidv7=(n)=>e.check(Wf(ps,n)),e.nanoid=(n)=>e.check(Gf(X_,n)),e.guid=(n)=>e.check(el(lg,n)),e.cuid=(n)=>e.check(Xf(K_,n)),e.cuid2=(n)=>e.check(Kf(J_,n)),e.ulid=(n)=>e.check(Jf(Y_,n)),e.base64=(n)=>e.check(rh(iS,n)),e.base64url=(n)=>e.check(ih(sS,n)),e.xid=(n)=>e.check(Yf(Q_,n)),e.ksuid=(n)=>e.check(Qf(eS,n)),e.ipv4=(n)=>e.check(eh(tS,n)),e.ipv6=(n)=>e.check(th(nS,n)),e.cidrv4=(n)=>e.check(nh(oS,n)),e.cidrv6=(n)=>e.check(oh(rS,n)),e.e164=(n)=>e.check(sh(aS,n)),e.datetime=(n)=>e.check(gl(n)),e.date=(n)=>e.check(Vh(n)),e.time=(n)=>e.check(Gh(n)),e.duration=(n)=>e.check(Xh(n))});function S(e){return jf(W_,e)}var je=z("ZodStringFormat",(e,t)=>{Oe.init(e,t),pg.init(e,t)}),q_=z("ZodEmail",(e,t)=>{Um.init(e,t),je.init(e,t)});var lg=z("ZodGUID",(e,t)=>{Hm.init(e,t),je.init(e,t)});var ps=z("ZodUUID",(e,t)=>{Bm.init(e,t),je.init(e,t)});var V_=z("ZodURL",(e,t)=>{Wm.init(e,t),je.init(e,t)});var G_=z("ZodEmoji",(e,t)=>{qm.init(e,t),je.init(e,t)});var X_=z("ZodNanoID",(e,t)=>{Vm.init(e,t),je.init(e,t)});var K_=z("ZodCUID",(e,t)=>{Gm.init(e,t),je.init(e,t)});var J_=z("ZodCUID2",(e,t)=>{Xm.init(e,t),je.init(e,t)});var Y_=z("ZodULID",(e,t)=>{Km.init(e,t),je.init(e,t)});var Q_=z("ZodXID",(e,t)=>{Jm.init(e,t),je.init(e,t)});var eS=z("ZodKSUID",(e,t)=>{Ym.init(e,t),je.init(e,t)});var tS=z("ZodIPv4",(e,t)=>{of.init(e,t),je.init(e,t)});var nS=z("ZodIPv6",(e,t)=>{rf.init(e,t),je.init(e,t)});var oS=z("ZodCIDRv4",(e,t)=>{sf.init(e,t),je.init(e,t)});var rS=z("ZodCIDRv6",(e,t)=>{af.init(e,t),je.init(e,t)});var iS=z("ZodBase64",(e,t)=>{lf.init(e,t),je.init(e,t)});var sS=z("ZodBase64URL",(e,t)=>{uf.init(e,t),je.init(e,t)});var aS=z("ZodE164",(e,t)=>{df.init(e,t),je.init(e,t)});var cS=z("ZodJWT",(e,t)=>{pf.init(e,t),je.init(e,t)});var mg=z("ZodNumber",(e,t)=>{Kc.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(o,r,s)=>Ch(e,o,r,s),e.gt=(o,r)=>e.check(cs(o,r)),e.gte=(o,r)=>e.check(Br(o,r)),e.min=(o,r)=>e.check(Br(o,r)),e.lt=(o,r)=>e.check(as(o,r)),e.lte=(o,r)=>e.check(Hr(o,r)),e.max=(o,r)=>e.check(Hr(o,r)),e.int=(o)=>e.check(ug(o)),e.safe=(o)=>e.check(ug(o)),e.positive=(o)=>e.check(cs(0,o)),e.nonnegative=(o)=>e.check(Br(0,o)),e.negative=(o)=>e.check(as(0,o)),e.nonpositive=(o)=>e.check(Hr(0,o)),e.multipleOf=(o,r)=>e.check(ls(o,r)),e.step=(o,r)=>e.check(ls(o,r)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??0.5),e.isFinite=!0,e.format=n.format??null});function ae(e){return ph(mg,e)}var lS=z("ZodNumberFormat",(e,t)=>{mf.init(e,t),mg.init(e,t)});function ug(e){return mh(lS,e)}var uS=z("ZodBoolean",(e,t)=>{ff.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Th(e,n,o,r)});function ze(e){return fh(uS,e)}var dS=z("ZodUndefined",(e,t)=>{hf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ah(e,n,o,r)});function bl(e){return hh(dS,e)}var pS=z("ZodNull",(e,t)=>{gf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Eh(e,n,o,r)});function wl(e){return gh(pS,e)}var mS=z("ZodUnknown",(e,t)=>{vf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>zh(e,n,o,r)});function Ee(){return vh(mS)}var fS=z("ZodNever",(e,t)=>{yf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ih(e,n,o,r)});function fg(e){return yh(fS,e)}var hS=z("ZodArray",(e,t)=>{xf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Mh(e,n,o,r),e.element=t.element,e.min=(n,o)=>e.check(jo(n,o)),e.nonempty=(n)=>e.check(jo(1,n)),e.max=(n,o)=>e.check(us(n,o)),e.length=(n,o)=>e.check(ds(n,o)),e.unwrap=()=>e.element});function re(e,t){return xh(hS,e,t)}var _l=z("ZodObject",(e,t)=>{_f.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Oh(e,n,o,r),be(e,"shape",()=>t.shape),e.keyof=()=>wt(Object.keys(e._zod.def.shape)),e.catchall=(n)=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Ee()}),e.loose=()=>e.clone({...e._zod.def,catchall:Ee()}),e.strict=()=>e.clone({...e._zod.def,catchall:fg()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=(n)=>g_(e,n),e.safeExtend=(n)=>v_(e,n),e.merge=(n)=>y_(e,n),e.pick=(n)=>f_(e,n),e.omit=(n)=>h_(e,n),e.partial=(...n)=>x_(yg,e,n[0]),e.required=(...n)=>b_(xg,e,n[0])});function k(e,t){let n={type:"object",shape:e??{},...G(t)};return new _l(n)}function hg(e,t){return new _l({type:"object",shape:e,catchall:fg(),...G(t)})}function bt(e,t){return new _l({type:"object",shape:e,catchall:Ee(),...G(t)})}var gg=z("ZodUnion",(e,t)=>{Jc.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Lh(e,n,o,r),e.options=t.options});function ue(e,t){return new gg({type:"union",options:e,...G(t)})}var gS=z("ZodDiscriminatedUnion",(e,t)=>{gg.init(e,t),Sf.init(e,t)});function Sl(e,t,n){return new gS({type:"union",options:t,discriminator:e,...G(n)})}var vS=z("ZodIntersection",(e,t)=>{kf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Dh(e,n,o,r)});function ms(e,t){return new vS({type:"intersection",left:e,right:t})}var yS=z("ZodRecord",(e,t)=>{Cf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Fh(e,n,o,r),e.keyType=t.keyType,e.valueType=t.valueType});function ke(e,t,n){return new yS({type:"record",keyType:e,valueType:t,...G(n)})}var yl=z("ZodEnum",(e,t)=>{Tf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(o,r,s)=>Ph(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 yl({...t,checks:[],...G(r),entries:s})},e.exclude=(o,r)=>{let s={...t.entries};for(let a of o)if(n.has(a))delete s[a];else throw Error(`Key ${a} not found in enum`);return new yl({...t,checks:[],...G(r),entries:s})}});function wt(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map((o)=>[o,o])):e;return new yl({type:"enum",entries:n,...G(t)})}var xS=z("ZodLiteral",(e,t)=>{Ef.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Nh(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 w(e,t){return new xS({type:"literal",values:Array.isArray(e)?e:[e],...G(t)})}var bS=z("ZodTransform",(e,t)=>{Af.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>$h(e,n,o,r),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new Mr(e.constructor.name);n.addIssue=(s)=>{if(typeof s==="string")n.issues.push(uo(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(uo(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 vg(e){return new bS({type:"transform",transform:e})}var yg=z("ZodOptional",(e,t)=>{Yc.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>hl(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function Be(e){return new yg({type:"optional",innerType:e})}var wS=z("ZodExactOptional",(e,t)=>{If.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>hl(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function _S(e){return new wS({type:"optional",innerType:e})}var SS=z("ZodNullable",(e,t)=>{zf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>jh(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function dg(e){return new SS({type:"nullable",innerType:e})}var kS=z("ZodDefault",(e,t)=>{Pf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Hh(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function CS(e,t){return new kS({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():jc(t)}})}var TS=z("ZodPrefault",(e,t)=>{Nf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Bh(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function ES(e,t){return new TS({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():jc(t)}})}var xg=z("ZodNonOptional",(e,t)=>{Rf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Zh(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function AS(e,t){return new xg({type:"nonoptional",innerType:e,...G(t)})}var IS=z("ZodCatch",(e,t)=>{$f.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Uh(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function zS(e,t){return new IS({type:"catch",innerType:e,catchValue:typeof t==="function"?t:()=>t})}var PS=z("ZodPipe",(e,t)=>{Mf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Wh(e,n,o,r),e.in=t.in,e.out=t.out});function xl(e,t){return new PS({type:"pipe",in:e,out:t})}var NS=z("ZodReadonly",(e,t)=>{Of.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>qh(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function RS(e){return new NS({type:"readonly",innerType:e})}var bg=z("ZodCustom",(e,t)=>{Lf.init(e,t),Le.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Rh(e,n,o,r)});function wg(e,t){return bh(bg,e??(()=>!0),t)}function $S(e,t={}){return wh(bg,e,t)}function MS(e){return _h(e)}function kl(e,t){return xl(vg(e),t)}Mt(Qc());var Cl=k({x:ae(),y:ae(),scale:ae().positive()}),OS=k({target:ue([hg({nodeId:S().min(1)}),hg({viewport:Cl})]),duration:ae().nonnegative().max(3600).optional(),easing:wt(["linear","ease-in-out","ease-out"]).optional(),padding:ae().nonnegative().optional(),pullback:ae().min(0).max(4).optional()}),CP=k({stops:re(OS).max(1000)});function _g(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 Sg(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)),d=(o/2-e.x)/e.scale*(1-l)+(o/2-t.x)/t.scale*l,p=(r/2-e.y)/e.scale*(1-l)+(r/2-t.y)/t.scale*l;return{x:o/2-d*u,y:r/2-p*u,scale:u}}var Tl=null;function kg(e){Tl=e}function st(){if(Tl?.isConnected){let e=Tl.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 Zo(){let e=st();return{x:e.left+e.width/2,y:e.top+e.height/2}}function El(){let e=16;try{let t=st(),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 LS=Symbol.for("preact-signals");function ys(){if(!(ln>1)){var e,t=!1;(function(){var r=gs;gs=void 0;while(r!==void 0){if(r.S.v===r.v)r.S.i=r.i;r=r.o}})();while(qr!==void 0){var n=qr;qr=void 0,hs++;while(n!==void 0){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Eg(n))try{n.c()}catch(r){if(!t)e=r,t=!0}n=o}}if(hs=0,ln--,t)throw e}else ln--}function Ot(e){if(ln>0)return e();Al=++DS,ln++;try{return e()}finally{ys()}}var _e=void 0;function Il(e){var t=_e;_e=void 0;try{return e()}finally{_e=t}}var Cg,qr=void 0,ln=0,hs=0,DS=0,Al=0,gs=void 0,vs=0;function Tg(e){if(_e!==void 0){var t=e.n;if(t===void 0||t.t!==_e){if(t={i:0,S:e,p:_e.s,n:void 0,t:_e,e:void 0,x:void 0,r:t},_e.s!==void 0)_e.s.n=t;if(_e.s=t,e.n=t,32&_e.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=_e.s,t.n=void 0,_e.s.n=t,_e.s=t}return t}}}function Qe(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}Qe.prototype.brand=LS;Qe.prototype.h=function(){return!0};Qe.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 Il(function(){var o;(o=t.W)==null||o.call(t)})};Qe.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)Il(function(){var r;(r=t.Z)==null||r.call(t)})}}};Qe.prototype.subscribe=function(e){var t=this;return Lt(function(){var n=t.value,o=_e;_e=void 0;try{e(n)}finally{_e=o}},{name:"sub"})};Qe.prototype.valueOf=function(){return this.value};Qe.prototype.toString=function(){return this.value+""};Qe.prototype.toJSON=function(){return this.value};Qe.prototype.peek=function(){var e=_e;_e=void 0;try{return this.value}finally{_e=e}};Object.defineProperty(Qe.prototype,"value",{get:function(){var e=Tg(this);if(e!==void 0)e.i=this.i;return this.v},set:function(e){if(e!==this.v){if(hs>100)throw Error("Cycle detected");(function(n){if(ln!==0&&hs===0){if(n.l!==Al)n.l=Al,gs={S:n,v:n.v,i:n.i,o:gs}}})(this),this.v=e,this.i++,vs++,ln++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{ys()}}}});function V(e,t){return new Qe(e,t)}function Eg(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 Ag(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 Ig(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 mo(e,t){Qe.call(this,void 0),this.x=e,this.s=void 0,this.g=vs-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}mo.prototype=new Qe;mo.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===vs)return!0;if(this.g=vs,this.f|=1,this.i>0&&!Eg(this))return this.f&=-2,!0;var e=_e;try{Ag(this),_e=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 _e=e,Ig(this),this.f&=-2,!0};mo.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)}Qe.prototype.S.call(this,e)};mo.prototype.U=function(e){if(this.t!==void 0){if(Qe.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)}}};mo.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(mo.prototype,"value",{get:function(){if(1&this.f)throw Error("Cycle detected");var e=Tg(this);if(this.h(),e!==void 0)e.i=this.i;if(16&this.f)throw this.v;return this.v}});function De(e,t){return new mo(e,t)}function zg(e){var t=e.m;if(e.m=void 0,typeof t=="function"){ln++;var n=_e;_e=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,zl(e),o}finally{_e=n,ys()}}}function zl(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,zg(e)}function FS(e){if(_e!==this)throw Error("Out-of-order effect");if(Ig(this),_e=e,this.f&=-2,8&this.f)zl(this);ys()}function Ho(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,Cg)Cg.push(this)}Ho.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()}};Ho.prototype.S=function(){if(1&this.f)throw Error("Cycle detected");this.f|=1,this.f&=-9,zg(this),Ag(this),ln++;var e=_e;return _e=this,FS.bind(this,e)};Ho.prototype.N=function(){if(!(2&this.f))this.f|=2,this.u=qr,qr=this};Ho.prototype.d=function(){if(this.f|=8,!(1&this.f))zl(this)};Ho.prototype.dispose=function(){this.d()};function Lt(e,t){var n=new Ho(e,t);try{n.c()}catch(r){throw n.d(),r}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var Pg,Pl,xs,jS=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var Ng=[];Lt(function(){Pg=this.N})();function Bo(e,t){ge[e]=t.bind(null,ge[e]||function(){})}function bs(e){if(xs){var t=xs;xs=void 0,t()}xs=e&&e.S()}function Rg(e){var t=this,n=e.data,o=HS(n);o.value=n;var r=Ie(function(){var c=t,l=t.__v;while(l=l.__)if(l.__c){l.__c.__$f|=4;break}var u=De(function(){var m=o.value.value;return m===0?0:m===!0?"":m||""}),d=De(function(){return!Array.isArray(u.value)&&!Ac(u.value)}),p=Lt(function(){if(this.N=$g,d.value){var m=u.value;if(c.__v&&c.__v.__e&&c.__v.__e.nodeType===3)c.__v.__e.data=m}}),f=t.__$u.d;return t.__$u.d=function(){p(),f.call(this)},[d,u]},[]),s=r[0],a=r[1];return s.value?a.peek():a.value}Rg.displayName="ReactiveTextNode";Object.defineProperties(Qe.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Rg},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});Bo("__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 Qe){if(!n)t.__np=n={};n[r]=s,o[r]=s.peek()}}}e(t)});Bo("__r",function(e,t){if(e(t),t.type!==ve){bs();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 Lt(function(){a=this},{name:s}),a.c=r,a}(function(){var r;if(jS)(r=n.y)==null||r.call(n);o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:"")}Pl=o,bs(n)}});Bo("__e",function(e,t,n,o){bs(),Pl=void 0,e(t,n,o)});Bo("diffed",function(e,t){bs(),Pl=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],d=o[l];if(u===void 0)u=ZS(n,l,d),s[l]=u;else u.o(d,r)}for(var p in o)r[p]=o[p]}}e(t)});function ZS(e,t,n,o){var r=t in e&&e.ownerSVGElement===void 0,s=V(n),a=n.peek();return{o:function(c,l){s.value=c,a=c.peek()},d:Lt(function(){this.N=$g;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})}}Bo("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)});Bo("__h",function(e,t,n,o){if(o<3||o===9)t.__$f|=2;e(t,n,o)});Oo.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 HS(e,t){return Ie(function(){return V(e,t)},[])}var BS=function(e){queueMicrotask(function(){queueMicrotask(e)})};function US(){Ot(function(){var e;while(e=Ng.shift())Pg.call(e)})}function $g(){if(Ng.push(this)===1)(ge.requestAnimationFrame||BS)(US)}var at={markdown:"MD","mcp-app":"APP",webpage:"WEB","json-render":"UI",graph:"GRAPH",prompt:"ASK",response:"ANS",status:"STATUS",context:"CONTEXT",ledger:"LOG",trace:"TRACE",file:"FILE",diff:"DIFF",mermaid:"MERMAID",image:"IMG",html:"HTML",group:"GROUP"},Vr=new Set(["markdown","mcp-app","webpage","json-render","graph","context","ledger","file","diff","mermaid","image","html"]);function Mg(e){return e.type==="mcp-app"&&e.data.mode==="ext-app"&&e.data.serverName==="Excalidraw"&&e.data.toolName==="create_view"}function Og(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 WS(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:"",d=u?n.get(u):void 0;if(!d||d.type!=="group")continue;if(!s.has(u))s.set(u,[]);s.get(u).push(l)}let a=t.filter((l)=>l.type==="group").sort((l,u)=>l.position.y-u.position.y||l.position.x-u.position.x);for(let l of a){let u=s.get(l.id)??[];if(u.length===0){let m=`unit:${l.id}`;r.push({id:m,memberIds:[l.id],origin:{...l.position},size:{...l.size},sortKey:{x:l.position.x,y:l.position.y}}),o.set(l.id,m);continue}let d=u.map((m)=>({position:m.position,size:m.size})),p=Og(d);if(!p)continue;let f=`group:${l.id}`;r.push({id:f,memberIds:u.map((m)=>m.id),origin:{x:p.x,y:p.y},size:{width:p.width,height:p.height},sortKey:{x:p.x,y:p.y},groupId:l.id}),o.set(l.id,f);for(let m of u)o.set(m.id,f)}let c=t.filter((l)=>!o.has(l.id)).sort((l,u)=>l.position.y-u.position.y||l.position.x-u.position.x);for(let l of c){let u=`unit:${l.id}`;r.push({id:u,memberIds:[l.id],origin:{...l.position},size:{...l.size},sortKey:{x:l.position.x,y:l.position.y}}),o.set(l.id,u)}return{units:r,nodesById:n,nodeToUnit:o}}function qS(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 VS(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 d of t.get(u)??[]){if(o.has(d))continue;o.add(d),a.push(d)}}let l=c.map((u)=>n.get(u)).filter((u)=>u!==void 0).sort((u,d)=>u.sortKey.y-d.sortKey.y||u.sortKey.x-d.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 GS(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 XS(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((g)=>g.id)),a=e.filter((g)=>(o.get(g.id)??0)===0&&(r.get(g.id)??0)>0).sort((g,b)=>g.sortKey.x-b.sortKey.x||g.sortKey.y-b.sortKey.y),c=a.length>0?a:[e.slice().sort((g,b)=>g.sortKey.x-b.sortKey.x||g.sortKey.y-b.sortKey.y)[0]],l=new Map,u=c.map((g)=>g.id);for(let g of c)l.set(g.id,0);while(u.length>0){let g=u.shift(),b=l.get(g)??0;for(let E of n.get(g)??[]){if(!s.has(E)||l.has(E))continue;l.set(E,b+1),u.push(E)}}let d=0;for(let g of e){if(l.has(g.id))continue;l.set(g.id,d),d+=1}let p=new Map;for(let g of e){let b=l.get(g.id)??0;if(!p.has(b))p.set(b,[]);p.get(b).push(g)}let f=Array.from(p.keys()).sort((g,b)=>g-b);for(let g of f)p.get(g).sort((b,E)=>b.sortKey.y-E.sortKey.y||b.sortKey.x-E.sortKey.x);let m=new Map,v=new Map,y=0;for(let g of f){let b=p.get(g),E=b.reduce((_,R,A)=>_+R.size.height+(A>0?72:0),0),j=Math.max(...b.map((_)=>_.size.width));m.set(g,E),v.set(g,j),y=Math.max(y,E)}let x=new Map,h=0;for(let g of f){let b=p.get(g),E=m.get(g)??0,j=v.get(g)??0,_=Math.max(0,(y-E)/2);for(let R of b)x.set(R.id,{x:h,y:_}),_+=R.size.height+72;h+=j+96}return{positions:x,size:{width:Math.max(0,h-96),height:y},sortKey:e[0].sortKey}}function KS(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 d=l;while(n.get(d)!==d){let p=n.get(d);n.set(d,u),d=p}return u},r=(l,u)=>{let d=o(l),p=o(u);if(d!==p)n.set(d,p)},s=160;for(let l=0;l<e.length;l++)for(let u=l+1;u<e.length;u++){let d=e[l],p=e[u];if(d.origin.x-160<p.origin.x+p.size.width+160&&d.origin.x+d.size.width+160>p.origin.x-160&&d.origin.y-160<p.origin.y+p.size.height+160&&d.origin.y+d.size.height+160>p.origin.y-160)r(d.id,p.id)}for(let[l,u]of t)for(let d of u)if(n.has(l)&&n.has(d))r(l,d);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,d)=>u.sortKey.y-d.sortKey.y||u.sortKey.x-d.sortKey.x);return c.sort((l,u)=>l[0].sortKey.y-u[0].sortKey.y||l[0].sortKey.x-u[0].sortKey.x)}function JS(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 Nl(e,t,n){let{units:o,nodesById:r,nodeToUnit:s}=WS(e),a=new Map,c=new Map;if(o.length===0)return{nodePositions:a,groupBounds:c};let{outgoing:l,undirected:u,indegree:d,outdegree:p}=qS(o,s,t),f=KS(o,u),m=new Map,v=[];for(let y of f){let x=VS(y,u).map((_)=>n==="graph"?XS(_,l,u,d,p):GS(_)),h={x:Math.min(...y.map((_)=>_.origin.x)),y:Math.min(...y.map((_)=>_.origin.y))},g=JS(x,h),b=new Map(y.map((_)=>[_.id,_.size])),E=(_)=>{let{POSITIVE_INFINITY:R,POSITIVE_INFINITY:A,NEGATIVE_INFINITY:C,NEGATIVE_INFINITY:Z}=Number;for(let[F,T]of _){let B=b.get(F);if(!B)continue;R=Math.min(R,T.x),A=Math.min(A,T.y),C=Math.max(C,T.x+B.width),Z=Math.max(Z,T.y+B.height)}return{x:R,y:A,width:C-R,height:Z-A}},j=g;for(let _=0;_<=v.length;_++){let R=E(j),A=v.filter((F)=>R.x<F.x+F.width+220&&R.x+R.width+220>F.x&&R.y<F.y+F.height+180&&R.y+R.height+180>F.y);if(A.length===0)break;let C=Math.max(...A.map((F)=>F.y+F.height))+180-R.y;if(C<=0)break;let Z=new Map;for(let[F,T]of j)Z.set(F,{x:T.x,y:T.y+C});j=Z}for(let[_,R]of j)m.set(_,R);v.push(E(j))}for(let y of o){let x=m.get(y.id);if(!x)continue;let h=x.x-y.origin.x,g=x.y-y.origin.y;if(y.groupId){let j=[];for(let R of y.memberIds){let A=r.get(R);if(!A)continue;let C={x:A.position.x+h,y:A.position.y+g};a.set(R,C),j.push({position:C,size:A.size})}let _=Og(j);if(_)c.set(y.groupId,_);continue}let b=y.memberIds[0],E=r.get(b);if(!E)continue;a.set(b,{x:E.position.x+h,y:E.position.y+g})}return{nodePositions:a,groupBounds:c}}function Rl(e,t){console.error(`[intent-bridge] ${e} failed`,t)}var ws=(()=>{try{let e=new URLSearchParams(window.location.search).get("agent")?.trim();return e?e.slice(0,64):null}catch{return null}})();function $l(e){let t={...e?.headers};if(ws)t["x-pmx-source"]=ws;else t["X-PMX-Workbench"]="1";return{...e,headers:t}}async function de(e,t,n,o){try{return await(await fetch(t,$l(o))).json()}catch(r){return Rl(e,r),n}}async function Et(e,t,n){try{return{ok:(await fetch(t,$l(n))).ok}}catch(o){return Rl(e,o),{ok:!1}}}async function Ut(e,t,n){try{await fetch(t,$l(n))}catch(o){Rl(e,o)}}async function Lg(e,t={}){return de("sendIntent","/api/workbench/intent",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:e,payload:t})})}async function fo(e){let n=`Veto: do not ${e.label?.trim()||`${e.kind} intent`}${e.reason?` — ${e.reason}`:""}.`;if((await de("vetoGhostIntent",`/api/canvas/ax/intent/${encodeURIComponent(e.id)}`,{ok:!1,cleared:!1},{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({vetoed:!0})})).cleared!==!0)return!1;return await Ut("vetoGhostSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:n,source:"browser"})}),!0}async function un(e){return(await de("renderMarkdown","/api/render",{},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({markdown:e})})).html??""}async function Gr(e){return de("fetchFile",`/api/file?path=${encodeURIComponent(e)}`,{content:""})}async function Dg(e,t){return de("saveFile","/api/file/save",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,content:t})})}async function _s(e){return Et("openWorkbenchFile","/api/workbench/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})}async function Ss(e){return de("saveCanvasTheme","/api/canvas/theme",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({theme:e})})}async function Fg(){return[]}async function Xr(e,t,n,o,r){if(!e.trim())return{ok:!1,error:"Prompt text is required"};return de("submitCanvasPrompt","/api/canvas/prompt",{ok:!1,error:"Network error"},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e,...t?{position:t}:{},...n?{parentNodeId:n}:{},...o&&o.length>0?{contextNodeIds:o}:{},...r?{threadNodeId:r}:{}})})}async function jg(e,t){return Xr(t,void 0,void 0,void 0,e)}async function ks(e,t={}){await Ut("pushCanvasUpdate","/api/canvas/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:e,...t.recordHistory===!1?{recordHistory:!1}:{}})})}async function ho(e,t,n,o){return de("createEdgeFromClient","/api/canvas/edge",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:e,to:t,type:n,label:o})})}async function Wt(e){return de("createNodeFromClient","/api/canvas/node",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function ct(e,t){return de("updateNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}`,{ok:!1},{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Cs(e,t){return de("refreshWebpageNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}/refresh`,{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{url:t}:{})})}async function $n(e){return de("removeNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}`,{ok:!1},{method:"DELETE"})}async function Ml(){return de("fetchAxSurfaceState","/api/canvas/ax/surface-snapshot",null)}async function Zg(){return de("fetchAgentPresence","/api/canvas/ax/presence",null)}async function Hg(e,t){return de("openNodeInSystemBrowserRequest","/api/canvas/open-external",{ok:!1,opened:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodeId:e,url:t})})}async function Ts(e){return de("submitAxInteractionFromClient","/api/canvas/ax/interaction",{ok:!1,code:"request-failed",error:"Request failed"},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceSurface:"native-node",...e,source:"browser"})})}async function Bg(e,t={}){return de("updateViewportFromClient","/api/canvas/viewport",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,...Ug(),...t.recordHistory===!1?{recordHistory:!1}:{}})})}function Ug(){if(typeof window>"u")return{};let e=st(),t=Math.round(e.width),n=Math.round(e.height);if(!t||!n)return{};return{clientWidth:t,clientHeight:n}}async function Kr(){let e=Ug();if(!("clientWidth"in e))return;await Ut("reportClientViewportSize","/api/canvas/viewport",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,recordHistory:!1})})}async function Uo(e){return de("createGroupFromClient","/api/canvas/group",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function Ol(e,t,n){return de("addToGroupFromClient","/api/canvas/group/add",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({groupId:e,childIds:t,...n?{childLayout:n}:{}})})}async function Es(e,t){return ct(e,{children:t})}async function Wo(e){return de("ungroupFromClient","/api/canvas/group/ungroup",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({groupId:e})})}async function Wg(){return de("listSnapshots","/api/canvas/snapshots?all=true",[])}async function qg(e){return de("saveSnapshot","/api/canvas/snapshots",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})}async function Vg(e){return de("restoreSnapshot",`/api/canvas/snapshots/${e}`,{ok:!1},{method:"POST"})}async function Gg(e){return de("deleteSnapshot",`/api/canvas/snapshots/${e}`,{ok:!1},{method:"DELETE"})}async function As(e,t){return de("updateEdgeFromClient",`/api/canvas/edge/${encodeURIComponent(e)}`,{ok:!1},{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Is(e){return de("removeEdgeFromClient","/api/canvas/edge",{ok:!1},{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({edge_id:e})})}function Qg(e,t){console.error(`[canvas-store] ${e} failed`,t)}var ee=V({x:0,y:0,scale:1}),N=V(new Map),$e=V(new Map),Vo=V(new Map),Ce=V(null),pn=V(null),It=V("connecting"),go=V(0),vo=V(0),yo=V(0),mn=V(""),Go=V(!1),Je=V("dark"),St=V(!1),qt=V(null),Ue=V(null),Qt=V(null),At=null,qo,Xg=100,YS=2500,zs=V(null),Ze=V(null),On=V(null),ye=V(new Set),Ae=V(new Set),_t=V("select"),Yr=V(!1);function Xo(){return _t.value==="pan"||Yr.value}function ev(e,t){if(!e)return new Set;let n=new Set;for(let o of t.values()){if(o.from===e)n.add(o.to);if(o.to===e)n.add(o.from)}return n}var tv=De(()=>ev(Ce.value,$e.value));function Kg(e,t){let n=new Set;for(let o of e)if(t.has(o))n.add(o);return n}function Jg(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Fl(e){let t=new Set(ye.value);if(t.has(e))t.delete(e);else t.add(e);ye.value=t}function nv(e){ye.value=new Set(e)}function gt(){if(pn.value=null,ye.value.size===0)return;ye.value=new Set}var dn=V(null),jl=!1;function ov(){jl=!0,dn.value=null}function rv(){jl=!1,dn.value=null}function Ll(e){return{x:e.position.x,y:e.position.y,w:e.size.width,h:e.size.height}}function QS(e,t,n){let o=Ll(e);return t>=o.x&&t<=o.x+o.w&&n>=o.y&&n<=o.y+o.h}function Yg(e,t){let n=Ll(e),o=Ll(t);return n.x+n.w<o.x||n.x>o.x+o.w||n.y+n.h<o.y||n.y>o.y+o.h}function iv(e){let t=N.value.get(e);if(!t||t.type==="group")return;let n=typeof t.data.parentGroup==="string"?t.data.parentGroup:null,o=n?N.value.get(n):void 0,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2,a=null;for(let c of N.value.values()){if(c.type!=="group"||c.id===n||c.collapsed)continue;if(QS(c,r,s))a=c}if(!jl){let c=a?{nodeId:e,groupId:a.id,mode:"add"}:o&&Yg(t,o)?{nodeId:e,groupId:o.id,mode:"remove"}:null,l=dn.value;if((l?.groupId??null)!==(c?.groupId??null)||l?.mode!==c?.mode)dn.value=c}if(o&&o.data.frameMode!=="manual"&&!Yg(t,o)){let l=Math.min(o.position.x,t.position.x-22),u=Math.min(o.position.y,t.position.y-22-32),d=Math.max(o.position.x+o.size.width,t.position.x+t.size.width+22),p=Math.max(o.position.y+o.size.height,t.position.y+t.size.height+22);if(l!==o.position.x||u!==o.position.y||d!==o.position.x+o.size.width||p!==o.position.y+o.size.height)$s(o.id,{position:{x:l,y:u},size:{width:d-l,height:p-u}},{skipGroupChildTranslation:!0})}}var Zl=De(()=>{let e=new Map;for(let t of N.value.values()){if(t.type!=="group"||!t.collapsed)continue;let n=Array.isArray(t.data.children)?t.data.children:[];for(let o of n)if(typeof o==="string")e.set(o,t.id)}return e});function Ps(e){let t=Zl.value.get(e);return N.value.get(t??e)}function sv(){let e=new Set;for(let t of ye.value){let n=N.value.get(t);if(!n)continue;if(n.type==="group")e.add(n.id);else if(typeof n.data.parentGroup==="string")e.add(n.data.parentGroup)}return[...e]}function Hl(e){let t=Bl();if(t.length<2)return;let n=Math.min(...t.map((l)=>e==="left"?l.position.x:l.position.y)),o=24,r=new Map;for(let l of t)r.set(l.id,e==="left"?{x:n,y:l.position.y}:{x:l.position.x,y:n});let s=(l,u)=>l.x<u.x+u.w&&u.x<l.x+l.w&&l.y<u.y+u.h&&u.y<l.y+l.h,a=t.map((l)=>{let u=r.get(l.id);return{node:l,x:u.x,y:u.y,w:l.size.width,h:l.size.height}});if(a.some((l,u)=>a.some((d,p)=>p>u&&s(l,d)))){let l=[...t].sort((d,p)=>e==="left"?d.position.y-p.position.y:d.position.x-p.position.x),u=e==="left"?Math.min(...t.map((d)=>d.position.y)):Math.min(...t.map((d)=>d.position.x));for(let d of l)r.set(d.id,e==="left"?{x:n,y:u}:{x:u,y:n}),u+=(e==="left"?d.size.height:d.size.width)+o}Ot(()=>{for(let l of t)et(l.id,{position:r.get(l.id)})}),ot()}function av(){let e=Bl().sort((c,l)=>c.position.x-l.position.x);if(e.length<3)return;let t=e[0],o=e[e.length-1].position.x-(t.position.x+t.size.width),r=e.slice(1,-1),s=r.reduce((c,l)=>c+l.size.width,0),a=(o-s)/(r.length+1);Ot(()=>{if(a<8){let l=t.position.x+t.size.width+24;for(let u of e.slice(1))et(u.id,{position:{x:l,y:u.position.y}}),l+=u.size.width+24;return}let c=t.position.x+t.size.width+a;for(let l of r)et(l.id,{position:{x:c,y:l.position.y}}),c+=l.size.width+a}),ot()}function cv(e=24){let t=Bl().sort((c,l)=>c.position.y-l.position.y||c.position.x-l.position.x);if(t.length<2)return;let n=Math.min(...t.map((c)=>c.position.x)),o=Math.min(...t.map((c)=>c.position.y)),r=Math.ceil(Math.sqrt(t.length)),s=Math.max(...t.map((c)=>c.size.width)),a=Math.max(...t.map((c)=>c.size.height));Ot(()=>{t.forEach((c,l)=>{et(c.id,{position:{x:n+l%r*(s+e),y:o+Math.floor(l/r)*(a+e)}})})}),ot()}function Bl(){let e=ye.value;if(e.size===0)return[];return Array.from(e).map((t)=>N.value.get(t)).filter((t)=>t!==void 0)}function Ln(e){let t=new Set(Ae.value);if(t.has(e))t.delete(e);else t.add(e);Ae.value=t,ot(),Rs(t)}function Ns(e){let t=new Set(Ae.value);for(let n of e)t.add(n);Ae.value=t,ot(),Rs(t)}function lv(){if(Ae.value.size===0)return;Ae.value=new Set,ot(),Rs(new Set)}function uv(e){Ae.value=new Set(e)}function Rs(e){Ut("syncContextPinsToServer","/api/canvas/context-pins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodeIds:Array.from(e)})})}var Jr=1;function fn(e){Ot(()=>{let t=new Map(N.value);if(e.zIndex>=Jr)Jr=e.zIndex+1;t.set(e.id,e),N.value=t,Ce.value=e.id})}function et(e,t){$s(e,t)}function $s(e,t,n={}){let o=N.value.get(e);if(!o)return;let r=new Map(N.value);if(o.type==="group"&&t.position&&n.skipGroupChildTranslation!==!0){let a=t.position.x-o.position.x,c=t.position.y-o.position.y;if(a!==0||c!==0){let l=Array.isArray(o.data.children)?o.data.children.filter((u)=>typeof u==="string"):[];for(let u of l){let d=r.get(u);if(!d||d.type==="group")continue;r.set(u,{...d,position:{x:d.position.x+a,y:d.position.y+c}})}}}r.set(e,{...o,...t}),N.value=r;let s=r.get(e)?.data.appCheckpoint?.updatedAt;if(Qt.value===e&&s!==void 0&&s!==qo)Dl(e)}function ie(e,t){let n=N.value.get(e);if(!n)return;et(e,{data:{...n.data,...t}})}function zt(e){ek(e);let t=new Map(N.value);if(t.delete(e),N.value=t,Ce.value===e)Ce.value=null;if(Ue.value===e)Ue.value=null;if(ye.value.has(e)){let n=new Set(ye.value);n.delete(e),ye.value=n}if(Ae.value.has(e)){let n=new Set(Ae.value);n.delete(e),Ae.value=n,Rs(n)}}function Ms(e){let t=new Map($e.value);t.set(e.id,e),$e.value=t}function dv(e){let t=new Map($e.value);t.delete(e),$e.value=t}function ek(e){let t=!1,n=new Map($e.value);for(let[o,r]of n)if(r.from===e||r.to===e)n.delete(o),t=!0;if(t)$e.value=n}function tk(e){let t=new Map(Vo.value);if(!t.delete(e))return;Vo.value=t}async function Ul(e){return Et("createAnnotationFromClient","/api/canvas/annotation",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function pv(e){let t=await Et("removeAnnotationFromClient",`/api/canvas/annotation/${encodeURIComponent(e)}`,{method:"DELETE"});if(t.ok)tk(e);return t}function Os(e,t){if(!N.value.get(e))return;et(e,{size:t})}function hn(e){let t=N.value.get(e);if(!t)return;Ot(()=>{if(et(e,{zIndex:Jr++}),t.type==="group"&&Array.isArray(t.data.children)){for(let n of t.data.children)if(typeof n==="string"&&N.value.has(n))et(n,{zIndex:Jr++})}}),Ce.value=e}function Ko(e){let t=N.value.get(e);if(!t)return;et(e,{collapsed:!t.collapsed}),ot()}function mv(e){ee.value={...ee.value,...e}}function fv(e){ee.value=e}function hv(e){gv(e)}function gv(e,t={}){ee.value=e,ot(t),Bg(e,t)}function vv(e,t={}){let n=new Map,o=1;for(let p of e.nodes)if(n.set(p.id,p),p.zIndex>=o)o=p.zIndex+1;let r=e.edges.filter((p)=>n.has(p.from)&&n.has(p.to)),s=new Map;for(let p of r)s.set(p.id,p);let a=new Map;for(let p of e.annotations??[])a.set(p.id,p);let c=Ce.value!==null&&n.has(Ce.value)?Ce.value:null,l=Ue.value!==null&&n.has(Ue.value)?Ue.value:null,u=Kg(ye.value,n),d=Kg(Ae.value,n);Ot(()=>{if(t.applyViewport===!0&&e.viewport)ee.value=e.viewport;if(Jr=o,N.value=n,$e.value=s,Vo.value=a,Ce.value=c,Ue.value=l,!Jg(ye.value,u))ye.value=u;if(!Jg(Ae.value,d))Ae.value=d})}var Mn=null;function nk(e){return 1-(1-e)**3}function Jo(e,t=150){let n=ee.value,o=Math.min(4,Math.max(0.1,n.scale*e));if(o===n.scale)return;let r=o/n.scale,{x:s,y:a}=Zo();Dn({x:s-r*(s-n.x),y:a-r*(a-n.y),scale:o},t)}function Dn(e,t=300,n={}){if(Mn!==null)cancelAnimationFrame(Mn);let o={...ee.value},r=performance.now();function s(a){let c=a-r,l=Math.min(1,c/t),u=nk(l);if(ee.value={x:o.x+(e.x-o.x)*u,y:o.y+(e.y-o.y)*u,scale:o.scale+(e.scale-o.scale)*u},l<1)Mn=requestAnimationFrame(s);else Mn=null,gv(e,n)}Mn=requestAnimationFrame(s)}function gn(){if(Mn!==null)cancelAnimationFrame(Mn),Mn=null}var yv="pmx-canvas-layout";function ot(e={}){try{let t=Array.from(N.value.values()),n=t.map((r)=>({id:r.id,position:r.position,size:r.size,collapsed:r.collapsed})),o={viewport:ee.value,nodes:t.map((r)=>({id:r.id,type:r.type,position:r.position,size:r.size,collapsed:r.collapsed,pinned:r.pinned})),edges:Array.from($e.value.values()).map((r)=>({id:r.id,from:r.from,to:r.to,type:r.type,label:r.label,style:r.style,animated:r.animated})),contextPinnedNodeIds:Array.from(Ae.value)};localStorage.setItem(yv,JSON.stringify(o)),ks(n,e)}catch(t){Qg("persistLayout",t)}}function Wl(){try{let e=localStorage.getItem(yv);if(!e)return null;let t=JSON.parse(e),n=Array.isArray(t.nodes)?t.nodes:[];if(n.length===0)return null;let o=new Map;for(let r of n){if(typeof r.id!=="string"||r.id.length===0)continue;o.set(r.id,{...r.position?{position:r.position}:{},...r.size?{size:r.size}:{},...r.collapsed!==void 0?{collapsed:r.collapsed}:{},...r.pinned!==void 0?{pinned:r.pinned}:{}})}return o.size>0?o:null}catch(e){return Qg("restoreLayout",e),null}}function Yo(e,t){let n=Array.from(N.value.values());if(n.length===0)return;let{POSITIVE_INFINITY:o,POSITIVE_INFINITY:r,NEGATIVE_INFINITY:s,NEGATIVE_INFINITY:a}=Number;for(let y of n)o=Math.min(o,y.position.x),r=Math.min(r,y.position.y),s=Math.max(s,y.position.x+y.size.width),a=Math.max(a,y.position.y+y.size.height);let c=El(),l=Math.max(80,e-c.left-c.right),u=Math.max(80,t-c.top-c.bottom),d=Math.max(1,s-o),p=Math.max(1,a-r),f=Math.min(1,Math.min(l/d,u/p)),m=(o+s)/2,v=(r+a)/2;Dn({x:c.left+l/2-m*f,y:c.top+u/2-v*f,scale:f})}function tt(e,t={}){let n=N.value.get(e);if(!n)return;let o=ee.value,r=st(),s=El(),a=Math.max(80,r.width-s.left-s.right),c=Math.max(80,r.height-s.top-s.bottom),l=Math.min(o.scale,a/n.size.width,c/n.size.height),u=n.position.x+n.size.width/2,d=n.position.y+n.size.height/2;Dn({x:s.left+a/2-u*l,y:s.top+c/2-d*l,scale:l},300,t),hn(e)}function xv(e=1){let t=Array.from(N.value.keys());if(t.length===0)return;let o=((Ce.value?t.indexOf(Ce.value):-1)+e+t.length)%t.length,r=t[o];hn(r),tt(r)}function bv(e){let t=Ce.value;if(!t)return;let n=N.value.get(t);if(!n)return;let o=ev(t,$e.value);if(o.size===0)return;let r=n.position.x+n.size.width/2,s=n.position.y+n.size.height/2,a=null,c=-1/0;for(let l of o){let u=N.value.get(l);if(!u)continue;let d=u.position.x+u.size.width/2,p=u.position.y+u.size.height/2,f=d-r,m=p-s,v=Math.sqrt(f*f+m*m);if(v<1)continue;let y;switch(e){case"up":y=-m;break;case"down":y=m;break;case"left":y=-f;break;case"right":y=f;break}if(y<=0)continue;let x=y/v-v*0.001;if(x>c)c=x,a=l}if(a)tt(a)}function en(e){if(!N.value.get(e))return;if(At!==null)clearTimeout(At),At=null;Qt.value=null,qo=void 0,hn(e),Ue.value=e}function Dl(e){if(At!==null)clearTimeout(At),At=null;if(Ue.value===e)Ue.value=null;if(Qt.value===e)Qt.value=null;qo=void 0}function xo(){let e=Ue.value,t=e?N.value.get(e):void 0;if(e&&t&&Mg(t)){let n=e,o=Date.now();if(Qt.value=n,qo=t.data.appCheckpoint?.updatedAt,At!==null)clearTimeout(At);let r=()=>{let a=N.value.get(n)?.data.appCheckpoint?.updatedAt;if(a!==void 0&&a!==qo){Dl(n);return}if(Date.now()-o>=YS){Dl(n);return}At=setTimeout(r,Xg)};At=setTimeout(r,Xg);return}if(At!==null)clearTimeout(At),At=null;Qt.value=null,qo=void 0,Ue.value=null}function Ls(){let e=Nl(Array.from(N.value.values()),Array.from($e.value.values()),"grid");if(e.nodePositions.size===0&&e.groupBounds.size===0)return;Ot(()=>{for(let[t,n]of e.nodePositions.entries())et(t,{position:n});for(let[t,n]of e.groupBounds.entries())$s(t,{position:{x:n.x,y:n.y},size:{width:n.width,height:n.height}},{skipGroupChildTranslation:!0})}),ot()}function Ds(){let e=Nl(Array.from(N.value.values()),Array.from($e.value.values()),"graph");if(e.nodePositions.size===0&&e.groupBounds.size===0)return;Ot(()=>{for(let[t,n]of e.nodePositions.entries())et(t,{position:n});for(let[t,n]of e.groupBounds.entries())$s(t,{position:{x:n.x,y:n.y},size:{width:n.width,height:n.height}},{skipGroupChildTranslation:!0})}),ot()}var tn=V(!1),bo=V(!1);function ql(){return tn.value||bo.value}var ok=0;function i(e,t,n,o,r,s){t||(t={});var a,c,l=t;if("ref"in l)for(c in l={},t)c=="ref"?a=t[c]:l[c]=t[c];var u={type:e,props:l,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ok,__i:-1,__u:0,__source:r,__self:s};if(typeof e=="function"&&(a=e.defaultProps))for(c in a)l[c]===void 0&&(l[c]=a[c]);return ge.vnode&&ge.vnode(u),u}function wv(){let[e,t]=O({stops:[]}),[n,o]=O(0),[r,s]=O(""),a=tn.value,c=St.value;return D(()=>{let l=new URLSearchParams(location.search);return tn.value=l.get("present")==="1",bo.value=l.get("capture")==="1",window.pmxCapture={ready:()=>St.value,area:st,camera:()=>({...ee.value}),frame:async(u)=>(bo.value=!0,gn(),ee.value=Cl.parse(u),await new Promise((d)=>requestAnimationFrame(()=>requestAnimationFrame(()=>d()))),{...ee.value})},()=>{delete window.pmxCapture,tn.value=!1,bo.value=!1}},[]),D(()=>{if(!a||!c)return;let l=!1;return de("read tour","/api/canvas/tour",{tour:{stops:[]}}).then((u)=>{if(!l)t(u.tour),o(0)}),()=>{l=!0}},[a,c]),D(()=>{if(!a||bo.value)return;let l=e.stops[n];if(!l)return;let u=st(),d;try{d=_g(l,[...N.value.values()],u.width,u.height),s("")}catch(x){s(x instanceof Error?x.message:String(x));return}gn();let p={...ee.value},f=performance.now(),m=(l.duration??1)*1000,v=0,y=(x)=>{if(bo.value)return;let h=m===0?1:Math.min(1,(x-f)/m);if(ee.value=Sg(p,d,h,u.width,u.height,l.easing,l.pullback),h<1)v=requestAnimationFrame(y)};return v=requestAnimationFrame(y),()=>cancelAnimationFrame(v)},[a,n,e]),D(()=>{if(!a)return;let l=(u)=>{if(u.stopImmediatePropagation(),["Escape","ArrowRight","ArrowDown","ArrowLeft","ArrowUp"," "].includes(u.key))u.preventDefault();if(u.key==="Escape")tn.value=!1;if(["ArrowRight","ArrowDown"," "].includes(u.key))o((d)=>Math.max(0,Math.min(e.stops.length-1,d+1)));if(["ArrowLeft","ArrowUp"].includes(u.key))o((d)=>Math.max(0,d-1))};return document.addEventListener("keydown",l,!0),()=>document.removeEventListener("keydown",l,!0)},[a,e]),a&&r?i("div",{class:"presentation-error",role:"alert",children:r},void 0,!1,void 0,this):null}var Fs=V(null),Qr=V([]),er=V(new Set),tr=V(new Set),js=V([]),Zs=V(new Set),nn=V(!1),Qo=V(0);function _v(){Fs.value=null,Qr.value=[],er.value=new Set,tr.value=new Set,js.value=[],Zs.value=new Set,nn.value=!1,Qo.value=0}function Hs(){nn.value=!0,Qo.value=0}function Sv(){nn.value=!1}function kv(e,t,n){er.value=new Set(e),tr.value=new Set(t),js.value=n}function Bs(e){Fs.value=e}function Cv(e,t=6){if(Qr.value=[e,...Qr.value].slice(0,t),!nn.value)Qo.value=Math.min(99,Qo.value+1)}function Us(e){Zs.value=new Set(e)}function rk(e){return new Date(e).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}function ik(){Hs()}function Tv(){let e=Qr.value;if(e.length===0)return null;let t=nn.value,n=Qo.value;if(!t)return i("button",{type:"button",class:"attention-history-tab",onClick:ik,"aria-label":n>0?`Recent updates — ${n} new`:"Recent updates",title:n>0?`${n} new updates since last viewed`:"Recent updates",children:[i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"9.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"attention-history-tab-label",children:"Updates"},void 0,!1,void 0,this),n>0&&i("span",{class:"attention-history-tab-badge","aria-hidden":"true",children:n>9?"9+":n},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("aside",{class:"attention-history","aria-label":"Recent semantic changes",children:[i("div",{class:"attention-history-header",children:[i("div",{class:"attention-history-header-text",children:[i("span",{class:"attention-history-title",children:"Recent Updates"},void 0,!1,void 0,this),i("span",{class:"attention-history-subtitle",children:"Focus and meaning shifts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"attention-history-close",onClick:Sv,"aria-label":"Collapse changes panel",title:"Collapse",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"attention-history-list",children:e.map((o)=>i("article",{class:`attention-history-entry attention-tone-${o.tone}`,children:[i("div",{class:"attention-history-meta",children:[i("span",{class:"attention-history-kind",children:o.title},void 0,!1,void 0,this),i("time",{class:"attention-history-time",dateTime:new Date(o.createdAt).toISOString(),children:rk(o.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("p",{class:"attention-history-detail",children:o.detail},void 0,!1,void 0,this)]},o.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ev(){let e=Fs.value;if(!e)return null;return i("button",{type:"button",class:`attention-toast attention-tone-${e.tone}`,onClick:Hs,"aria-label":`${e.title} — open change history`,title:e.detail||e.title,children:[i("span",{class:"attention-toast-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"attention-toast-title",children:e.title},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var ti=V(null),Av=0;function on(e,t,n={}){return new Promise((o)=>{ti.value?.resolve(null),Av+=1,ti.value={seq:Av,title:e,placeholder:t,initial:n.initial??"",allowEmpty:n.allowEmpty??!1,confirm:n.confirm??"Add",resolve:o}})}function ei(e){let t=ti.value;ti.value=null,t?.resolve(e)}function Iv(){let e=ti.value,t=M(null);if(D(()=>{if(!e)return;let o=(r)=>{if(r.key!=="Escape")return;r.preventDefault(),r.stopPropagation(),ei(null)};return window.addEventListener("keydown",o,{capture:!0}),()=>window.removeEventListener("keydown",o,{capture:!0})},[e]),!e)return null;let n=()=>{let o=t.current?.value.trim()??"";ei(o?o:e.allowEmpty?"":null)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>ei(null),children:i("div",{class:"text-prompt",role:"dialog","aria-label":e.title,"data-testid":"text-prompt",onPointerDown:(o)=>o.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:e.title},void 0,!1,void 0,this),i("input",{ref:(o)=>{if(t.current=o,!o)return;if(o.focus(),e.initial)o.select()},class:"text-prompt-input",type:"text",defaultValue:e.initial,placeholder:e.placeholder,onKeyDown:(o)=>{if(o.key==="Enter")o.preventDefault(),o.stopPropagation(),n();else if(o.key==="Escape")o.preventDefault(),o.stopPropagation(),ei(null)}},e.seq,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:()=>ei(null),children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"button",class:"text-prompt-confirm",onClick:n,children:e.confirm},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var sk=700,ak=1600;function ck(e){return e.replace(/\r\n?/g,`
60
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let a of e.seen.entries()){let c=a[1];if(t===a[0]){s(a);continue}if(e.external){let u=e.external.registry.get(a[0])?.id;if(t!==a[0]&&u){s(a);continue}}if(e.metadataRegistry.get(a[0])?.id){s(a);continue}if(c.cycle){s(a);continue}if(c.count>1){if(e.reused==="ref"){s(a);continue}}}}function Ol(e,t){let n=e.seen.get(t);if(!n)throw Error("Unprocessed schema. This is a bug in Zod.");let o=(a)=>{let c=e.seen.get(a);if(c.ref===null)return;let l=c.def??c.schema,u={...l},p=c.ref;if(c.ref=null,p){o(p);let f=e.seen.get(p),m=f.schema;if(m.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))l.allOf=l.allOf??[],l.allOf.push(m);else Object.assign(l,m);if(Object.assign(l,u),a._zod.parent===p)for(let v in l){if(v==="$ref"||v==="allOf")continue;if(!(v in u))delete l[v]}if(m.$ref&&f.def)for(let v in l){if(v==="$ref"||v==="allOf")continue;if(v in f.def&&JSON.stringify(l[v])===JSON.stringify(f.def[v]))delete l[v]}}let d=a._zod.parent;if(d&&d!==p){o(d);let f=e.seen.get(d);if(f?.schema.$ref){if(l.$ref=f.schema.$ref,f.def)for(let m in l){if(m==="$ref"||m==="allOf")continue;if(m in f.def&&JSON.stringify(l[m])===JSON.stringify(f.def[m]))delete l[m]}}}e.override({zodSchema:a,jsonSchema:l,path:c.path??[]})};for(let a of[...e.seen.entries()].reverse())o(a[0]);let r={};if(e.target==="draft-2020-12")r.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")r.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")r.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let a=e.external.registry.get(t)?.id;if(!a)throw Error("Schema is missing an `id` property");r.$id=e.external.uri(a)}Object.assign(r,n.def??n.schema);let s=e.external?.defs??{};for(let a of e.seen.entries()){let c=a[1];if(c.def&&c.defId)s[c.defId]=c.def}if(e.external);else if(Object.keys(s).length>0)if(e.target==="draft-2020-12")r.$defs=s;else r.definitions=s;try{let a=JSON.parse(JSON.stringify(r));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:ri(t,"input",e.processors),output:ri(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function St(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 St(o.element,n);if(o.type==="set")return St(o.valueType,n);if(o.type==="lazy")return St(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 St(o.innerType,n);if(o.type==="intersection")return St(o.left,n)||St(o.right,n);if(o.type==="record"||o.type==="map")return St(o.keyType,n)||St(o.valueType,n);if(o.type==="pipe")return St(o.in,n)||St(o.out,n);if(o.type==="object"){for(let r in o.shape)if(St(o.shape[r],n))return!0;return!1}if(o.type==="union"){for(let r of o.options)if(St(r,n))return!0;return!1}if(o.type==="tuple"){for(let r of o.items)if(St(r,n))return!0;if(o.rest&&St(o.rest,n))return!0;return!1}return!1}var Yh=(e,t={})=>(n)=>{let o=$l({...n,processors:t});return Ye(e,o),Ml(o,e),Ol(o,e)},ri=(e,t,n={})=>(o)=>{let{libraryOptions:r,target:s}=o??{},a=$l({...r??{},target:s,io:t,processors:n});return Ye(e,a),Ml(a,e),Ol(a,e)};var CS={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Qh=(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=CS[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}))]}},eg=(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},tg=(e,t,n,o)=>{n.type="boolean"};var ng=(e,t,n,o)=>{if(t.target==="openapi-3.0")n.type="string",n.nullable=!0,n.enum=[null];else n.type="null"},og=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Undefined cannot be represented in JSON Schema")};var rg=(e,t,n,o)=>{n.not={}};var ig=(e,t,n,o)=>{};var sg=(e,t,n,o)=>{let r=e._zod.def,s=us(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},ag=(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 cg=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Custom types cannot be represented in JSON Schema")};var lg=(e,t,n,o)=>{if(t.unrepresentable==="throw")throw Error("Transforms cannot be represented in JSON Schema")};var ug=(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=Ye(s.element,t,{...o,path:[...o.path,"items"]})},dg=(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]=Ye(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=Ye(s.catchall,t,{...o,path:[...o.path,"additionalProperties"]})},pg=(e,t,n,o)=>{let r=e._zod.def,s=r.inclusive===!1,a=r.options.map((c,l)=>Ye(c,t,{...o,path:[...o.path,s?"oneOf":"anyOf",l]}));if(s)n.oneOf=a;else n.anyOf=a},mg=(e,t,n,o)=>{let r=e._zod.def,s=Ye(r.left,t,{...o,path:[...o.path,"allOf",0]}),a=Ye(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 fg=(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=Ye(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=Ye(s.keyType,t,{...o,path:[...o.path,"propertyNames"]});r.additionalProperties=Ye(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}},hg=(e,t,n,o)=>{let r=e._zod.def,s=Ye(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"}]},gg=(e,t,n,o)=>{let r=e._zod.def;Ye(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType},vg=(e,t,n,o)=>{let r=e._zod.def;Ye(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.default=JSON.parse(JSON.stringify(r.defaultValue))},yg=(e,t,n,o)=>{let r=e._zod.def;Ye(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))},bg=(e,t,n,o)=>{let r=e._zod.def;Ye(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},xg=(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;Ye(s,t,o);let a=t.seen.get(e);a.ref=s},wg=(e,t,n,o)=>{let r=e._zod.def;Ye(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType,n.readOnly=!0};var Ll=(e,t,n,o)=>{let r=e._zod.def;Ye(r.innerType,t,o);let s=t.seen.get(e);s.ref=r.innerType};var RS=O("ZodISODateTime",(e,t)=>{Af.init(e,t),Ze.init(e,t)});function Dl(e){return Lh(RS,e)}var $S=O("ZodISODate",(e,t)=>{zf.init(e,t),Ze.init(e,t)});function _g(e){return Dh($S,e)}var MS=O("ZodISOTime",(e,t)=>{Pf.init(e,t),Ze.init(e,t)});function Sg(e){return Fh(MS,e)}var OS=O("ZodISODuration",(e,t)=>{Nf.init(e,t),Ze.init(e,t)});function kg(e){return Bh(OS,e)}var Cg=(e,t)=>{fs.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:(n)=>dm(e,n)},flatten:{value:(n)=>um(e,n)},addIssue:{value:(n)=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Kr,2)}},addIssues:{value:(n)=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Kr,2)}},isEmpty:{get(){return e.issues.length===0}}})},fP=O("ZodError",Cg),Nt=O("ZodError",Cg,{Parent:Error});var Tg=hs(Nt),Ig=gs(Nt),Eg=Yr(Nt),Ag=ei(Nt),zg=pm(Nt),Pg=mm(Nt),Ng=fm(Nt),Rg=hm(Nt),$g=gm(Nt),Mg=vm(Nt),Og=ym(Nt),Lg=bm(Nt);var Be=O("ZodType",(e,t)=>(Me.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:ri(e,"input"),output:ri(e,"output")}}),e.toJSONSchema=Yh(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Fn(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)=>an(e,n,o),e.brand=()=>e,e.register=(n,o)=>(n.add(e,o),e),e.parse=(n,o)=>Tg(e,n,o,{callee:e.parse}),e.safeParse=(n,o)=>Eg(e,n,o),e.parseAsync=async(n,o)=>Ig(e,n,o,{callee:e.parseAsync}),e.safeParseAsync=async(n,o)=>Ag(e,n,o),e.spa=e.safeParseAsync,e.encode=(n,o)=>zg(e,n,o),e.decode=(n,o)=>Pg(e,n,o),e.encodeAsync=async(n,o)=>Ng(e,n,o),e.decodeAsync=async(n,o)=>Rg(e,n,o),e.safeEncode=(n,o)=>$g(e,n,o),e.safeDecode=(n,o)=>Mg(e,n,o),e.safeEncodeAsync=async(n,o)=>Og(e,n,o),e.safeDecodeAsync=async(n,o)=>Lg(e,n,o),e.refine=(n,o)=>e.check(Ek(n,o)),e.superRefine=(n)=>e.check(Ak(n)),e.overwrite=(n)=>e.check(jn(n)),e.optional=()=>We(e),e.exactOptional=()=>gk(e),e.nullable=()=>Bg(e),e.nullish=()=>We(Bg(e)),e.nonoptional=(n)=>_k(e,n),e.array=()=>re(e),e.or=(n)=>fe([e,n]),e.and=(n)=>Es(e,n),e.transform=(n)=>Hl(e,Wg(n)),e.default=(n)=>bk(e,n),e.prefault=(n)=>wk(e,n),e.catch=(n)=>kk(e,n),e.pipe=(n)=>Hl(e,n),e.readonly=()=>Ik(e),e.describe=(n)=>{let o=e.clone();return _o.add(o,{description:n}),o},Object.defineProperty(e,"description",{get(){return _o.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return _o.get(e);let o=e.clone();return _o.add(o,n[0]),o},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=(n)=>n(e),e)),Hg=O("_ZodString",(e,t)=>{ws.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(o,r,s)=>Qh(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(Sl(...o)),e.includes=(...o)=>e.check(Tl(...o)),e.startsWith=(...o)=>e.check(Il(...o)),e.endsWith=(...o)=>e.check(El(...o)),e.min=(...o)=>e.check(Ko(...o)),e.max=(...o)=>e.check(Cs(...o)),e.length=(...o)=>e.check(Ts(...o)),e.nonempty=(...o)=>e.check(Ko(1,...o)),e.lowercase=(o)=>e.check(kl(o)),e.uppercase=(o)=>e.check(Cl(o)),e.trim=()=>e.check(zl()),e.normalize=(...o)=>e.check(Al(...o)),e.toLowerCase=()=>e.check(Pl()),e.toUpperCase=()=>e.check(Nl()),e.slugify=()=>e.check(Rl())}),FS=O("ZodString",(e,t)=>{ws.init(e,t),Hg.init(e,t),e.email=(n)=>e.check(gh(BS,n)),e.url=(n)=>e.check(wh(HS,n)),e.jwt=(n)=>e.check(Oh(nk,n)),e.emoji=(n)=>e.check(_h(jS,n)),e.guid=(n)=>e.check(_l(Dg,n)),e.uuid=(n)=>e.check(vh(Is,n)),e.uuidv4=(n)=>e.check(yh(Is,n)),e.uuidv6=(n)=>e.check(bh(Is,n)),e.uuidv7=(n)=>e.check(xh(Is,n)),e.nanoid=(n)=>e.check(Sh(ZS,n)),e.guid=(n)=>e.check(_l(Dg,n)),e.cuid=(n)=>e.check(kh(US,n)),e.cuid2=(n)=>e.check(Ch(qS,n)),e.ulid=(n)=>e.check(Th(WS,n)),e.base64=(n)=>e.check(Rh(QS,n)),e.base64url=(n)=>e.check($h(ek,n)),e.xid=(n)=>e.check(Ih(VS,n)),e.ksuid=(n)=>e.check(Eh(GS,n)),e.ipv4=(n)=>e.check(Ah(XS,n)),e.ipv6=(n)=>e.check(zh(KS,n)),e.cidrv4=(n)=>e.check(Ph(JS,n)),e.cidrv6=(n)=>e.check(Nh(YS,n)),e.e164=(n)=>e.check(Mh(tk,n)),e.datetime=(n)=>e.check(Dl(n)),e.date=(n)=>e.check(_g(n)),e.time=(n)=>e.check(Sg(n)),e.duration=(n)=>e.check(kg(n))});function C(e){return hh(FS,e)}var Ze=O("ZodStringFormat",(e,t)=>{Fe.init(e,t),Hg.init(e,t)}),BS=O("ZodEmail",(e,t)=>{xf.init(e,t),Ze.init(e,t)});var Dg=O("ZodGUID",(e,t)=>{yf.init(e,t),Ze.init(e,t)});var Is=O("ZodUUID",(e,t)=>{bf.init(e,t),Ze.init(e,t)});var HS=O("ZodURL",(e,t)=>{wf.init(e,t),Ze.init(e,t)});var jS=O("ZodEmoji",(e,t)=>{_f.init(e,t),Ze.init(e,t)});var ZS=O("ZodNanoID",(e,t)=>{Sf.init(e,t),Ze.init(e,t)});var US=O("ZodCUID",(e,t)=>{kf.init(e,t),Ze.init(e,t)});var qS=O("ZodCUID2",(e,t)=>{Cf.init(e,t),Ze.init(e,t)});var WS=O("ZodULID",(e,t)=>{Tf.init(e,t),Ze.init(e,t)});var VS=O("ZodXID",(e,t)=>{If.init(e,t),Ze.init(e,t)});var GS=O("ZodKSUID",(e,t)=>{Ef.init(e,t),Ze.init(e,t)});var XS=O("ZodIPv4",(e,t)=>{Rf.init(e,t),Ze.init(e,t)});var KS=O("ZodIPv6",(e,t)=>{$f.init(e,t),Ze.init(e,t)});var JS=O("ZodCIDRv4",(e,t)=>{Mf.init(e,t),Ze.init(e,t)});var YS=O("ZodCIDRv6",(e,t)=>{Of.init(e,t),Ze.init(e,t)});var QS=O("ZodBase64",(e,t)=>{Df.init(e,t),Ze.init(e,t)});var ek=O("ZodBase64URL",(e,t)=>{Ff.init(e,t),Ze.init(e,t)});var tk=O("ZodE164",(e,t)=>{Bf.init(e,t),Ze.init(e,t)});var nk=O("ZodJWT",(e,t)=>{Hf.init(e,t),Ze.init(e,t)});var jg=O("ZodNumber",(e,t)=>{yl.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(o,r,s)=>eg(e,o,r,s),e.gt=(o,r)=>e.check(Ss(o,r)),e.gte=(o,r)=>e.check(oi(o,r)),e.min=(o,r)=>e.check(oi(o,r)),e.lt=(o,r)=>e.check(_s(o,r)),e.lte=(o,r)=>e.check(ni(o,r)),e.max=(o,r)=>e.check(ni(o,r)),e.int=(o)=>e.check(Fg(o)),e.safe=(o)=>e.check(Fg(o)),e.positive=(o)=>e.check(Ss(0,o)),e.nonnegative=(o)=>e.check(oi(0,o)),e.negative=(o)=>e.check(_s(0,o)),e.nonpositive=(o)=>e.check(ni(0,o)),e.multipleOf=(o,r)=>e.check(ks(o,r)),e.step=(o,r)=>e.check(ks(o,r)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??0.5),e.isFinite=!0,e.format=n.format??null});function ce(e){return Hh(jg,e)}var ok=O("ZodNumberFormat",(e,t)=>{jf.init(e,t),jg.init(e,t)});function Fg(e){return jh(ok,e)}var rk=O("ZodBoolean",(e,t)=>{Zf.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>tg(e,n,o,r)});function Ne(e){return Zh(rk,e)}var ik=O("ZodUndefined",(e,t)=>{Uf.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>og(e,n,o,r)});function jl(e){return Uh(ik,e)}var sk=O("ZodNull",(e,t)=>{qf.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>ng(e,n,o,r)});function Zl(e){return qh(sk,e)}var ak=O("ZodUnknown",(e,t)=>{Wf.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>ig(e,n,o,r)});function ze(){return Wh(ak)}var ck=O("ZodNever",(e,t)=>{Vf.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>rg(e,n,o,r)});function Zg(e){return Vh(ck,e)}var lk=O("ZodArray",(e,t)=>{Gf.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>ug(e,n,o,r),e.element=t.element,e.min=(n,o)=>e.check(Ko(n,o)),e.nonempty=(n)=>e.check(Ko(1,n)),e.max=(n,o)=>e.check(Cs(n,o)),e.length=(n,o)=>e.check(Ts(n,o)),e.unwrap=()=>e.element});function re(e,t){return Gh(lk,e,t)}var Ul=O("ZodObject",(e,t)=>{Jf.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>dg(e,n,o,r),_e(e,"shape",()=>t.shape),e.keyof=()=>Ct(Object.keys(e._zod.def.shape)),e.catchall=(n)=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:ze()}),e.loose=()=>e.clone({...e._zod.def,catchall:ze()}),e.strict=()=>e.clone({...e._zod.def,catchall:Zg()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=(n)=>uS(e,n),e.safeExtend=(n)=>dS(e,n),e.merge=(n)=>pS(e,n),e.pick=(n)=>cS(e,n),e.omit=(n)=>lS(e,n),e.partial=(...n)=>mS(Vg,e,n[0]),e.required=(...n)=>fS(Gg,e,n[0])});function A(e,t){let n={type:"object",shape:e??{},...G(t)};return new Ul(n)}function Ug(e,t){return new Ul({type:"object",shape:e,catchall:Zg(),...G(t)})}function kt(e,t){return new Ul({type:"object",shape:e,catchall:ze(),...G(t)})}var qg=O("ZodUnion",(e,t)=>{bl.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>pg(e,n,o,r),e.options=t.options});function fe(e,t){return new qg({type:"union",options:e,...G(t)})}var uk=O("ZodDiscriminatedUnion",(e,t)=>{qg.init(e,t),Yf.init(e,t)});function ql(e,t,n){return new uk({type:"union",options:t,discriminator:e,...G(n)})}var dk=O("ZodIntersection",(e,t)=>{Qf.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>mg(e,n,o,r)});function Es(e,t){return new dk({type:"intersection",left:e,right:t})}var pk=O("ZodRecord",(e,t)=>{eh.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>fg(e,n,o,r),e.keyType=t.keyType,e.valueType=t.valueType});function Ee(e,t,n){return new pk({type:"record",keyType:e,valueType:t,...G(n)})}var Bl=O("ZodEnum",(e,t)=>{th.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(o,r,s)=>sg(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 Bl({...t,checks:[],...G(r),entries:s})},e.exclude=(o,r)=>{let s={...t.entries};for(let a of o)if(n.has(a))delete s[a];else throw Error(`Key ${a} not found in enum`);return new Bl({...t,checks:[],...G(r),entries:s})}});function Ct(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map((o)=>[o,o])):e;return new Bl({type:"enum",entries:n,...G(t)})}var mk=O("ZodLiteral",(e,t)=>{nh.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>ag(e,n,o,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function k(e,t){return new mk({type:"literal",values:Array.isArray(e)?e:[e],...G(t)})}var fk=O("ZodTransform",(e,t)=>{oh.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>lg(e,n,o,r),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new Xr(e.constructor.name);n.addIssue=(s)=>{if(typeof s==="string")n.issues.push(wo(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(wo(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 Wg(e){return new fk({type:"transform",transform:e})}var Vg=O("ZodOptional",(e,t)=>{xl.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ll(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function We(e){return new Vg({type:"optional",innerType:e})}var hk=O("ZodExactOptional",(e,t)=>{rh.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>Ll(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function gk(e){return new hk({type:"optional",innerType:e})}var vk=O("ZodNullable",(e,t)=>{ih.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>hg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function Bg(e){return new vk({type:"nullable",innerType:e})}var yk=O("ZodDefault",(e,t)=>{sh.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>vg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function bk(e,t){return new yk({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():cl(t)}})}var xk=O("ZodPrefault",(e,t)=>{ah.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>yg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function wk(e,t){return new xk({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():cl(t)}})}var Gg=O("ZodNonOptional",(e,t)=>{ch.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>gg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function _k(e,t){return new Gg({type:"nonoptional",innerType:e,...G(t)})}var Sk=O("ZodCatch",(e,t)=>{lh.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>bg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function kk(e,t){return new Sk({type:"catch",innerType:e,catchValue:typeof t==="function"?t:()=>t})}var Ck=O("ZodPipe",(e,t)=>{uh.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>xg(e,n,o,r),e.in=t.in,e.out=t.out});function Hl(e,t){return new Ck({type:"pipe",in:e,out:t})}var Tk=O("ZodReadonly",(e,t)=>{dh.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>wg(e,n,o,r),e.unwrap=()=>e._zod.def.innerType});function Ik(e){return new Tk({type:"readonly",innerType:e})}var Xg=O("ZodCustom",(e,t)=>{ph.init(e,t),Be.init(e,t),e._zod.processJSONSchema=(n,o,r)=>cg(e,n,o,r)});function Kg(e,t){return Xh(Xg,e??(()=>!0),t)}function Ek(e,t={}){return Kh(Xg,e,t)}function Ak(e){return Jh(e)}function Wl(e,t){return Hl(Wg(e),t)}Ht(wl());var Vl=A({x:ce(),y:ce(),scale:ce().positive()}),zk=A({target:fe([Ug({nodeId:C().min(1)}),Ug({viewport:Vl})]),duration:ce().nonnegative().max(3600).optional(),easing:Ct(["linear","ease-in-out","ease-out"]).optional(),padding:ce().nonnegative().optional(),pullback:ce().min(0).max(4).optional()}),AN=A({stops:re(zk).max(1000)});function Jg(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 Yg(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 Gl=null;function Qg(e){Gl=e}function ot(){if(Gl?.isConnected){let e=Gl.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 Zn(){let e=ot();return{x:e.left+e.width/2,y:e.top+e.height/2}}function Xl(){let e=16;try{let t=ot(),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 Pk=Symbol.for("preact-signals");function Rs(){if(!(gn>1)){var e,t=!1;(function(){var r=Ps;Ps=void 0;while(r!==void 0){if(r.S.v===r.v)r.S.i=r.i;r=r.o}})();while(si!==void 0){var n=si;si=void 0,zs++;while(n!==void 0){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&nv(n))try{n.c()}catch(r){if(!t)e=r,t=!0}n=o}}if(zs=0,gn--,t)throw e}else gn--}function Rt(e){if(gn>0)return e();Kl=++Nk,gn++;try{return e()}finally{Rs()}}var ke=void 0;function Jl(e){var t=ke;ke=void 0;try{return e()}finally{ke=t}}var ev,si=void 0,gn=0,zs=0,Nk=0,Kl=0,Ps=void 0,Ns=0;function tv(e){if(ke!==void 0){var t=e.n;if(t===void 0||t.t!==ke){if(t={i:0,S:e,p:ke.s,n:void 0,t:ke,e:void 0,x:void 0,r:t},ke.s!==void 0)ke.s.n=t;if(ke.s=t,e.n=t,32&ke.f)e.S(t);return t}else if(t.i===-1){if(t.i=0,t.n!==void 0){if(t.n.p=t.p,t.p!==void 0)t.p.n=t.n;t.p=ke.s,t.n=void 0,ke.s.n=t,ke.s=t}return t}}}function rt(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}rt.prototype.brand=Pk;rt.prototype.h=function(){return!0};rt.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 Jl(function(){var o;(o=t.W)==null||o.call(t)})};rt.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)Jl(function(){var r;(r=t.Z)==null||r.call(t)})}}};rt.prototype.subscribe=function(e){var t=this;return jt(function(){var n=t.value,o=ke;ke=void 0;try{e(n)}finally{ke=o}},{name:"sub"})};rt.prototype.valueOf=function(){return this.value};rt.prototype.toString=function(){return this.value+""};rt.prototype.toJSON=function(){return this.value};rt.prototype.peek=function(){var e=ke;ke=void 0;try{return this.value}finally{ke=e}};Object.defineProperty(rt.prototype,"value",{get:function(){var e=tv(this);if(e!==void 0)e.i=this.i;return this.v},set:function(e){if(e!==this.v){if(zs>100)throw Error("Cycle detected");(function(n){if(gn!==0&&zs===0){if(n.l!==Kl)n.l=Kl,Ps={S:n,v:n.v,i:n.i,o:Ps}}})(this),this.v=e,this.i++,Ns++,gn++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Rs()}}}});function q(e,t){return new rt(e,t)}function nv(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 ov(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 rv(e){var t=e.s,n=void 0;while(t!==void 0){var o=t.p;if(t.i===-1){if(t.S.U(t),o!==void 0)o.n=t.n;if(t.n!==void 0)t.n.p=o}else n=t;if(t.S.n=t.r,t.r!==void 0)t.r=void 0;t=o}e.s=n}function So(e,t){rt.call(this,void 0),this.x=e,this.s=void 0,this.g=Ns-1,this.f=4,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}So.prototype=new rt;So.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32)return!0;if(this.f&=-5,this.g===Ns)return!0;if(this.g=Ns,this.f|=1,this.i>0&&!nv(this))return this.f&=-2,!0;var e=ke;try{ov(this),ke=this;var t=this.x();if(16&this.f||this.v!==t||this.i===0)this.v=t,this.f&=-17,this.i++}catch(n){this.v=n,this.f|=16,this.i++}return ke=e,rv(this),this.f&=-2,!0};So.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}rt.prototype.S.call(this,e)};So.prototype.U=function(e){if(this.t!==void 0){if(rt.prototype.U.call(this,e),this.t===void 0){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}}};So.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(So.prototype,"value",{get:function(){if(1&this.f)throw Error("Cycle detected");var e=tv(this);if(this.h(),e!==void 0)e.i=this.i;if(16&this.f)throw this.v;return this.v}});function Oe(e,t){return new So(e,t)}function iv(e){var t=e.m;if(e.m=void 0,typeof t=="function"){gn++;var n=ke;ke=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,Yl(e),o}finally{ke=n,Rs()}}}function Yl(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,iv(e)}function Rk(e){if(ke!==this)throw Error("Out-of-order effect");if(rv(this),ke=e,this.f&=-2,8&this.f)Yl(this);Rs()}function Jo(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,ev)ev.push(this)}Jo.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()}};Jo.prototype.S=function(){if(1&this.f)throw Error("Cycle detected");this.f|=1,this.f&=-9,iv(this),ov(this),gn++;var e=ke;return ke=this,Rk.bind(this,e)};Jo.prototype.N=function(){if(!(2&this.f))this.f|=2,this.u=si,si=this};Jo.prototype.d=function(){if(this.f|=8,!(1&this.f))Yl(this)};Jo.prototype.dispose=function(){this.d()};function jt(e,t){var n=new Jo(e,t);try{n.c()}catch(r){throw n.d(),r}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var sv,Ql,$s,$k=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var av=[];jt(function(){sv=this.N})();function Yo(e,t){we[e]=t.bind(null,we[e]||function(){})}function Ms(e){if($s){var t=$s;$s=void 0,t()}$s=e&&e.S()}function cv(e){var t=this,n=e.data,o=Ok(n);o.value=n;var r=Ie(function(){var c=t,l=t.__v;while(l=l.__)if(l.__c){l.__c.__$f|=4;break}var u=Oe(function(){var m=o.value.value;return m===0?0:m===!0?"":m||""}),p=Oe(function(){return!Array.isArray(u.value)&&!Kc(u.value)}),d=jt(function(){if(this.N=lv,p.value){var m=u.value;if(c.__v&&c.__v.__e&&c.__v.__e.nodeType===3)c.__v.__e.data=m}}),f=t.__$u.d;return t.__$u.d=function(){d(),f.call(this)},[p,u]},[]),s=r[0],a=r[1];return s.value?a.peek():a.value}cv.displayName="ReactiveTextNode";Object.defineProperties(rt.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:cv},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});Yo("__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 rt){if(!n)t.__np=n={};n[r]=s,o[r]=s.peek()}}}e(t)});Yo("__r",function(e,t){if(e(t),t.type!==de){Ms();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 jt(function(){a=this},{name:s}),a.c=r,a}(function(){var r;if($k)(r=n.y)==null||r.call(n);o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:"")}Ql=o,Ms(n)}});Yo("__e",function(e,t,n,o){Ms(),Ql=void 0,e(t,n,o)});Yo("diffed",function(e,t){Ms(),Ql=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=Mk(n,l,p),s[l]=u;else u.o(p,r)}for(var d in o)r[d]=o[d]}}e(t)});function Mk(e,t,n,o){var r=t in e&&e.ownerSVGElement===void 0,s=q(n),a=n.peek();return{o:function(c,l){s.value=c,a=c.peek()},d:jt(function(){this.N=lv;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})}}Yo("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)});Yo("__h",function(e,t,n,o){if(o<3||o===9)t.__$f|=2;e(t,n,o)});Wo.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 Ok(e,t){return Ie(function(){return q(e,t)},[])}var Lk=function(e){queueMicrotask(function(){queueMicrotask(e)})};function Dk(){Rt(function(){var e;while(e=av.shift())sv.call(e)})}function lv(){if(av.push(this)===1)(we.requestAnimationFrame||Lk)(Dk)}var lt={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"},ai=new Set(["markdown","mcp-app","webpage","json-render","graph","context","ledger","file","diff","mermaid","image","html"]);function uv(e){return e.type==="mcp-app"&&e.data.mode==="ext-app"&&e.data.serverName==="Excalidraw"&&e.data.toolName==="create_view"}function dv(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 Fk(e){let t=e.filter((l)=>!l.pinned),n=new Map(t.map((l)=>[l.id,l])),o=new Map,r=[],s=new Map;for(let l of t){if(l.type==="group")continue;let u=typeof l.data.parentGroup==="string"?l.data.parentGroup:"",p=u?n.get(u):void 0;if(!p||p.type!=="group")continue;if(!s.has(u))s.set(u,[]);s.get(u).push(l)}let a=t.filter((l)=>l.type==="group").sort((l,u)=>l.position.y-u.position.y||l.position.x-u.position.x);for(let l of a){let u=s.get(l.id)??[];if(u.length===0){let m=`unit:${l.id}`;r.push({id:m,memberIds:[l.id],origin:{...l.position},size:{...l.size},sortKey:{x:l.position.x,y:l.position.y}}),o.set(l.id,m);continue}let p=u.map((m)=>({position:m.position,size:m.size})),d=dv(p);if(!d)continue;let f=`group:${l.id}`;r.push({id:f,memberIds:u.map((m)=>m.id),origin:{x:d.x,y:d.y},size:{width:d.width,height:d.height},sortKey:{x:d.x,y:d.y},groupId:l.id}),o.set(l.id,f);for(let m of u)o.set(m.id,f)}let c=t.filter((l)=>!o.has(l.id)).sort((l,u)=>l.position.y-u.position.y||l.position.x-u.position.x);for(let l of c){let u=`unit:${l.id}`;r.push({id:u,memberIds:[l.id],origin:{...l.position},size:{...l.size},sortKey:{x:l.position.x,y:l.position.y}}),o.set(l.id,u)}return{units:r,nodesById:n,nodeToUnit:o}}function Bk(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 Hk(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 jk(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 Zk(e,t,n,o,r){if(e.length===1)return{positions:new Map([[e[0].id,{x:0,y:0}]]),size:{...e[0].size},sortKey:e[0].sortKey};let s=new Set(e.map((y)=>y.id)),a=e.filter((y)=>(o.get(y.id)??0)===0&&(r.get(y.id)??0)>0).sort((y,E)=>y.sortKey.x-E.sortKey.x||y.sortKey.y-E.sortKey.y),c=a.length>0?a:[e.slice().sort((y,E)=>y.sortKey.x-E.sortKey.x||y.sortKey.y-E.sortKey.y)[0]],l=new Map,u=c.map((y)=>y.id);for(let y of c)l.set(y.id,0);while(u.length>0){let y=u.shift(),E=l.get(y)??0;for(let L of n.get(y)??[]){if(!s.has(L)||l.has(L))continue;l.set(L,E+1),u.push(L)}}let p=0;for(let y of e){if(l.has(y.id))continue;l.set(y.id,p),p+=1}let d=new Map;for(let y of e){let E=l.get(y.id)??0;if(!d.has(E))d.set(E,[]);d.get(E).push(y)}let f=Array.from(d.keys()).sort((y,E)=>y-E);for(let y of f)d.get(y).sort((E,L)=>E.sortKey.y-L.sortKey.y||E.sortKey.x-L.sortKey.x);let m=new Map,h=new Map,v=0;for(let y of f){let E=d.get(y),L=E.reduce((b,T,w)=>b+T.size.height+(w>0?72:0),0),P=Math.max(...E.map((b)=>b.size.width));m.set(y,L),h.set(y,P),v=Math.max(v,L)}let x=new Map,g=0;for(let y of f){let E=d.get(y),L=m.get(y)??0,P=h.get(y)??0,b=Math.max(0,(v-L)/2);for(let T of E)x.set(T.id,{x:g,y:b}),b+=T.size.height+72;g+=P+96}return{positions:x,size:{width:Math.max(0,g-96),height:v},sortKey:e[0].sortKey}}function Uk(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 qk(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 eu(e,t,n){let{units:o,nodesById:r,nodeToUnit:s}=Fk(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}=Bk(o,s,t),f=Uk(o,u),m=new Map,h=[];for(let v of f){let x=Hk(v,u).map((b)=>n==="graph"?Zk(b,l,u,p,d):jk(b)),g={x:Math.min(...v.map((b)=>b.origin.x)),y:Math.min(...v.map((b)=>b.origin.y))},y=qk(x,g),E=new Map(v.map((b)=>[b.id,b.size])),L=(b)=>{let{POSITIVE_INFINITY:T,POSITIVE_INFINITY:w,NEGATIVE_INFINITY:_,NEGATIVE_INFINITY:z}=Number;for(let[U,N]of b){let Z=E.get(U);if(!Z)continue;T=Math.min(T,N.x),w=Math.min(w,N.y),_=Math.max(_,N.x+Z.width),z=Math.max(z,N.y+Z.height)}return{x:T,y:w,width:_-T,height:z-w}},P=y;for(let b=0;b<=h.length;b++){let T=L(P),w=h.filter((U)=>T.x<U.x+U.width+220&&T.x+T.width+220>U.x&&T.y<U.y+U.height+180&&T.y+T.height+180>U.y);if(w.length===0)break;let _=Math.max(...w.map((U)=>U.y+U.height))+180-T.y;if(_<=0)break;let z=new Map;for(let[U,N]of P)z.set(U,{x:N.x,y:N.y+_});P=z}for(let[b,T]of P)m.set(b,T);h.push(L(P))}for(let v of o){let x=m.get(v.id);if(!x)continue;let g=x.x-v.origin.x,y=x.y-v.origin.y;if(v.groupId){let P=[];for(let T of v.memberIds){let w=r.get(T);if(!w)continue;let _={x:w.position.x+g,y:w.position.y+y};a.set(T,_),P.push({position:_,size:w.size})}let b=dv(P);if(b)c.set(v.groupId,b);continue}let E=v.memberIds[0],L=r.get(E);if(!L)continue;a.set(E,{x:L.position.x+g,y:L.position.y+y})}return{nodePositions:a,groupBounds:c}}var Wk=700,Vk=1600;function Gk(e){return e.replace(/\r\n?/g,`
61
61
  `).replace(/[ \t\f\v]+/g," ").replace(/\n\s+/g,`
62
62
  `).replace(/\s+\n/g,`
63
63
  `).replace(/\n{3,}/g,`
64
64
 
65
- `).trim()}function kt(e,t){if(t<=0)return"";let n=ck(e);if(n.length<=t)return n;if(t<=1)return n.slice(0,t);return`${n.slice(0,Math.max(0,t-1)).trimEnd()}…`}function Ws(e,t){if(typeof e==="string")return kt(e,t);if(e===null||e===void 0)return"";try{return kt(JSON.stringify(e),t)}catch{return""}}function lk(e,t){let n=[],o=typeof e.url==="string"?e.url:"",r=typeof e.pageTitle==="string"?e.pageTitle:"",s=typeof e.description==="string"?e.description:"",a=typeof e.status==="string"?e.status:"",c=typeof e.statusCode==="number"?e.statusCode:null,l=typeof e.error==="string"?e.error:"",u=typeof e.content==="string"?e.content:typeof e.excerpt==="string"?e.excerpt:"";if(o)n.push(`URL: ${o}`);if(r)n.push(`Title: ${r}`);if(s)n.push(`Description: ${s}`);if(a||c!==null)n.push(`Fetch: ${a||"unknown"}${c!==null?` (${c})`:""}`);if(l)n.push(`Error: ${l}`);let d=n.join(`
66
- `),p=Math.max(0,t-d.length-(d?2:0)),f=p>0?kt(u,p):"";if(d&&f)return`${d}
67
-
68
- ${f}`;if(d)return kt(d,t);return kt(u,t)}function uk(e){if(e===null||e===void 0)return"";if(typeof e!=="object"||Array.isArray(e))return"";let t=e.elements;if(Array.isArray(t))return`Diagram elements: ${t.length}`;let n=Object.keys(e).sort();return n.length>0?`Input keys: ${n.join(", ")}`:""}function dk(e,t){let n=[],o=typeof e.title==="string"?e.title:"",r=typeof e.mode==="string"?e.mode:"",s=typeof e.hostMode==="string"?e.hostMode:"",a=typeof e.serverName==="string"?e.serverName:"",c=typeof e.toolName==="string"?e.toolName:"",l=typeof e.resourceUri==="string"?e.resourceUri:"",u=typeof e.path==="string"?e.path:"",d=typeof e.url==="string"?e.url:"",p=typeof e.sessionStatus==="string"?e.sessionStatus:"",f=uk(e.toolInput);if(o)n.push(`App: ${o}`);if(r||s)n.push(`Mode: ${[r,s].filter(Boolean).join(" / ")}`);if(a||c)n.push(`Source: ${[a,c].filter(Boolean).join(" / ")}`);if(l)n.push(`Resource: ${l}`);if(u)n.push(`Path: ${u}`);if(d)n.push(`URL: ${d}`);if(p)n.push(`Session: ${p}`);if(f)n.push(f);if(n.length===0)return"MCP App node";return kt(n.join(`
69
- `),t)}function pk(e,t){let n=[],o=typeof e.content==="string"?e.content:"",r=typeof e.title==="string"?e.title:"",s=typeof e.path==="string"?e.path:"",a=typeof e.url==="string"?e.url:"",c=typeof e.projectPath==="string"?e.projectPath:"",l=typeof e.artifactBytes==="number"?e.artifactBytes:null,u=typeof e.sourceFileCount==="number"?e.sourceFileCount:null,d=Array.isArray(e.sourceFiles)?e.sourceFiles.filter((f)=>typeof f==="string"):[],p=Array.isArray(e.deps)?e.deps.filter((f)=>typeof f==="string"):[];if(o)n.push(o);if(!o&&r)n.push(`Web artifact: ${r}`);if(d.length>0&&!o.includes("Source files:")){let f=u!==null?Math.max(0,u-d.length):0;n.push(`Source files: ${d.join(", ")}${f>0?`, +${f} more`:""}`)}if(l!==null&&!o.includes("Artifact bytes:"))n.push(`Artifact bytes: ${l}`);if(p.length>0&&!o.includes("Dependencies:"))n.push(`Dependencies: ${p.join(", ")}`);if(s)n.push(`Path: ${s}`);if(c)n.push(`Project: ${c}`);if(a)n.push(`URL: ${a}`);return n.length>0?kt(n.join(`
70
- `),t):"Web artifact node"}function mk(e,t){let n=[],o=typeof e.htmlPrimitive==="string"?e.htmlPrimitive:"",r=typeof e.description==="string"?e.description:"",s=e.primitiveData;if(o)n.push(`HTML primitive: ${o}`);if(r)n.push(r);if(s!==void 0)n.push(`Data: ${Ws(s,t)}`);return kt(n.join(`
71
- `),t)}function zv(e,t={}){let n=t.defaultTextLength??sk,o=t.webpageTextLength??ak;switch(e.type){case"markdown":{let r=e.data.rendered||e.data.content||"";return kt(r,n)}case"mcp-app":{if(e.data.viewerType==="web-artifact")return pk(e.data,n);let r=e.data.chartConfig;if(r){let s=r.title||"Untitled chart",a=r.type||"unknown",c=Array.isArray(r.labels)?r.labels.join(", "):"";return kt(`Chart: ${s} (${a}). Labels: ${c}`,n)}return dk(e.data,n)}case"webpage":return lk(e.data,o);case"json-render":case"graph":{let r=e.data.graphConfig;if(r)return kt(`Graph: ${JSON.stringify(r)}`,n);return Ws(e.data.spec??{},n)}case"html":{if(typeof e.data.agentSummary==="string")return kt(e.data.agentSummary,n);if(typeof e.data.htmlPrimitive==="string")return mk(e.data,n);return Ws({title:e.data.title,description:e.data.description,summary:e.data.summary,contentSummary:e.data.contentSummary,embeddedNodeIds:e.data.embeddedNodeIds,embeddedUrls:e.data.embeddedUrls},n)}case"prompt":case"response":{let r=e.data.text||e.data.content||"";return kt(r,n)}case"file":{let r=typeof e.data.path==="string"?e.data.path:"",s=typeof e.data.fileContent==="string"?e.data.fileContent:typeof e.data.content==="string"?e.data.content:"",a=r?`Path: ${r}
72
-
73
- `:"",c=Math.max(0,n-a.length);return`${a}${kt(s,c)}`.trim()}default:return Ws(e.data,n)}}function fk(e,t){let n=e.position.x+e.size.width/2,o=e.position.y+e.size.height/2,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2;return Math.sqrt((n-r)**2+(o-s)**2)}function hk(e,t){let n=e.position.x+e.size.width,o=e.position.y+e.size.height,r=t.position.x+t.size.width,s=t.position.y+t.size.height,a=Math.max(0,Math.max(e.position.x,t.position.x)-Math.min(n,r)),c=Math.max(0,Math.max(e.position.y,t.position.y)-Math.min(o,s));return Math.sqrt(a**2+c**2)}function gk(e){let t=[...e],n=100;return t.sort((o,r)=>{let s=Math.floor(o.position.y/100),a=Math.floor(r.position.y/100);if(s!==a)return s-a;return o.position.x-r.position.x}),t}function vk(e){let t=e.find((r)=>r.data.title&&typeof r.data.title==="string");if(t&&e.length<=3)return e.filter((s)=>s.data.title).map((s)=>s.data.title).slice(0,3).join(", ");let n={};for(let r of e)n[r.type]=(n[r.type]??0)+1;let o=Object.entries(n).map(([r,s])=>s===1?r:`${s} ${r}`);if(t)return`${t.data.title} + ${o.join(", ")}`;return o.join(", ")}function yk(e,t){return e.x<=t.x+t.width&&e.x+e.width>=t.x&&e.y<=t.y+t.height&&e.y+e.height>=t.y}function xk(e,t){let n=t.filter((r)=>yk(e.bounds,{x:r.position.x,y:r.position.y,width:r.size.width,height:r.size.height})),o=n.map((r)=>typeof r.data.title==="string"&&r.data.title.length>0?r.data.title:r.id);return{id:e.id,label:e.label??e.text??null,bounds:e.bounds,targetNodeIds:n.map((r)=>r.id),targetNodeTitles:o,target:o.length>0?o.join(", "):"empty canvas region"}}function bk(e,t=200){if(e.length===0)return[];let n=new Map,o=(l)=>{while(n.get(l)!==l){let u=n.get(l);n.set(l,n.get(u)),l=u}return l},r=(l,u)=>{let d=o(l),p=o(u);if(d!==p)n.set(d,p)};for(let l of e)n.set(l.id,l.id);for(let l=0;l<e.length;l++)for(let u=l+1;u<e.length;u++)if(hk(e[l],e[u])<=t)r(e[l].id,e[u].id);let s=new Map;for(let l of e){let u=o(l.id);if(!s.has(u))s.set(u,[]);s.get(u).push(l)}let a=[],c=0;for(let[,l]of s){if(l.length<2)continue;let u=l.map((h)=>h.position.x),d=l.map((h)=>h.position.y),p=l.map((h)=>h.position.x+h.size.width),f=l.map((h)=>h.position.y+h.size.height),m=Math.min(...u),v=Math.min(...d),y=Math.max(...p),x=Math.max(...f);a.push({id:`cluster-${c++}`,nodeIds:l.map((h)=>h.id),label:vk(l),centroid:{x:Math.round((m+y)/2),y:Math.round((v+x)/2)},bounds:{x:m,y:v,width:y-m,height:x-v}})}return a.sort((l,u)=>{let d=Math.floor(l.centroid.y/200),p=Math.floor(u.centroid.y/200);if(d!==p)return d-p;return l.centroid.x-u.centroid.x}),a}function wk(e,t,n=5,o=600){let r=e.filter((a)=>t.has(a.id)),s=e.filter((a)=>!t.has(a.id));return r.map((a)=>{let c=s.map((l)=>({node:l,distance:fk(a,l)})).filter((l)=>l.distance<=o).sort((l,u)=>l.distance-u.distance).slice(0,n);return{pinnedNodeId:a.id,pinnedNodeTitle:a.data.title??null,neighbors:c.map((l)=>({id:l.node.id,type:l.node.type,title:l.node.data.title??null,distance:Math.round(l.distance)}))}})}function ni(e,t,n,o=[]){let r=bk(e),s=new Map;for(let u of r)for(let d of u.nodeIds)s.set(d,u.id);let c=gk(e).map((u,d)=>({id:u.id,type:u.type,title:u.data.title??null,content:zv(u,{defaultTextLength:320,webpageTextLength:640})||null,clusterId:s.get(u.id)??null,readingOrder:d})),l=wk(e,n);return{totalNodes:e.length,clusters:r,nodesInReadingOrder:c,pinnedNeighborhoods:l,annotations:o.map((u)=>xk(u,e))}}function nr(e){if(!e)return null;let t=e.data.title;return typeof t==="string"&&t.trim().length>0?t.trim():null}function qs(e,t){return{id:e?.id??t,title:nr(e),nodeType:e?.type??"markdown"}}function Pv(e,t){return{id:e.id,edgeType:e.type,fromId:e.from,toId:e.to,fromTitle:nr(t.get(e.from)),toTitle:nr(t.get(e.to))}}function Vs(e){return new Map(e.map((t)=>[t.id,t]))}function Nv(e){return new Map(e.map((t)=>[t.id,t]))}function Vt(e){return Array.from(e).sort((t,n)=>t.localeCompare(n))}function Vl(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Gl(e){if(!e||e.type!=="group")return[];let t=e.data.children;if(!Array.isArray(t))return[];return t.filter((n)=>typeof n==="string").sort((n,o)=>n.localeCompare(o))}function Rv(e){let t=new Map;for(let n of e.clusters){let o=[...n.nodeIds].sort((r,s)=>r.localeCompare(s));for(let r of o)t.set(r,o.filter((s)=>s!==r))}return t}function $v(e){let t=new Map;for(let n of e.pinnedNeighborhoods)t.set(n.pinnedNodeId,n.neighbors.map((o)=>o.id).sort((o,r)=>o.localeCompare(r)));return t}function _k(e,t){let n=Vt(Array.from(t).filter((r)=>!e.has(r))),o=Vt(Array.from(e).filter((r)=>!t.has(r)));return{added:n,removed:o}}function Mv(e){let t=e&&typeof e==="object"?e:{};return{timestamp:typeof t.timestamp==="string"?t.timestamp:void 0,sessionId:typeof t.sessionId==="string"?t.sessionId:void 0}}function Sk(e,t,n){if(!e||!n)return{layout:e,pinnedNodeIds:[],primaryFocusNodeIds:[],secondaryFocusNodeIds:[],regions:[],spatial:n};let o=Vs(e.nodes),r=Vt(t).filter((l)=>o.has(l)),s=new Set(r),a=new Set,c=[];for(let l of n.pinnedNeighborhoods){if(!s.has(l.pinnedNodeId))continue;let u=Vt([l.pinnedNodeId,...l.neighbors.map((d)=>d.id)]).filter((d,p,f)=>f.indexOf(d)===p&&o.has(d));for(let d of u)if(!s.has(d))a.add(d);c.push({id:`region-${l.pinnedNodeId}`,primaryNodeId:l.pinnedNodeId,nodeIds:u})}if(c.length===0&&r.length>0)for(let l of r)c.push({id:`region-${l}`,primaryNodeId:l,nodeIds:[l]});return{layout:e,pinnedNodeIds:r,primaryFocusNodeIds:r,secondaryFocusNodeIds:Vt(a),regions:c,spatial:n}}class Gs{currentLayout=null;currentPins=new Set;previousSpatial=null;setInitialPins(e){this.currentPins=new Set(e)}getAttentionSnapshot(){return Sk(this.currentLayout,this.currentPins,this.previousSpatial)}handleMessage(e){if(e.event==="context-pins-changed")return this.handleContextPinsChanged(e.data);if(e.event==="canvas-layout-update")return this.handleLayoutUpdate(e.data);return[]}handleContextPinsChanged(e){let t=e&&typeof e==="object"?e:{},n=Array.isArray(t.nodeIds)?t.nodeIds.filter((u)=>typeof u==="string"):[],o=Mv(e),r=new Set(n),{added:s,removed:a}=_k(this.currentPins,r);if(this.currentPins=r,!this.currentLayout)return[];let c=Vs(this.currentLayout.nodes),l={added:s.map((u)=>qs(c.get(u),u)),removed:a.map((u)=>qs(c.get(u),u))};if(this.previousSpatial=ni(this.currentLayout.nodes,this.currentLayout.edges,this.currentPins,this.currentLayout.annotations??[]),l.added.length===0&&l.removed.length===0)return[];return[{type:"context-pin",...o,...l}]}handleLayoutUpdate(e){let t=e&&typeof e==="object"?e:{},n=t.layout&&typeof t.layout==="object"?t.layout:null;if(!n)return[];let o=Mv(e);if(!this.currentLayout)return this.currentLayout=n,this.previousSpatial=ni(n.nodes,n.edges,this.currentPins,n.annotations??[]),[];let r=this.currentLayout,s=this.previousSpatial??ni(r.nodes,r.edges,this.currentPins,r.annotations??[]),a=ni(n.nodes,n.edges,this.currentPins,n.annotations??[]),c=[],l=Vs(r.nodes),u=Vs(n.nodes),d=Nv(r.edges),p=Nv(n.edges),f=Vt(Array.from(p.keys()).filter((h)=>!d.has(h))).map((h)=>p.get(h)).filter((h)=>h!==void 0);if(f.length>0)c.push({type:"connect",...o,edges:f.map((h)=>Pv(h,u))});let m=Vt(Array.from(l.keys()).filter((h)=>!u.has(h))),v=Vt(Array.from(d.keys()).filter((h)=>!p.has(h)));if(m.length>0||v.length>0)c.push({type:"remove",...o,nodes:m.map((h)=>qs(l.get(h),h)),edges:v.map((h)=>d.get(h)).filter((h)=>h!==void 0).map((h)=>Pv(h,l))});let y=this.buildGroupEvent(l,u,o);if(y)c.push(y);let x=this.buildMoveEndEvent(r,n,l,u,s,a,o);if(x)c.push(x);return this.currentLayout=n,this.previousSpatial=a,c}buildGroupEvent(e,t,n){let o=Vt(Array.from(e.values()).filter((c)=>c.type==="group").map((c)=>c.id)),r=Vt(Array.from(t.values()).filter((c)=>c.type==="group").map((c)=>c.id)),s=r.filter((c)=>!o.includes(c)).map((c)=>{let l=t.get(c),u=Gl(l);return{id:c,title:nr(l),childCount:u.length}}),a=[];for(let c of r.filter((l)=>o.includes(l))){let l=Gl(e.get(c)),u=Gl(t.get(c));if(Vl(l,u))continue;a.push({id:c,title:nr(t.get(c)),addedChildIds:u.filter((d)=>!l.includes(d)),removedChildIds:l.filter((d)=>!u.includes(d)),childCount:u.length})}if(s.length===0&&a.length===0)return null;return{type:"group",...n,created:s,updated:a}}buildMoveEndEvent(e,t,n,o,r,s,a){let c=Vt(Array.from(o.keys()).filter((x)=>{let h=n.get(x),g=o.get(x);if(!h||!g)return!1;return h.position.x!==g.position.x||h.position.y!==g.position.y}));if(c.length===0)return null;let l=Rv(r),u=Rv(s),d=$v(r),p=$v(s),f=new Map,m=(x,h)=>{let g=f.get(x)??new Set;g.add(h),f.set(x,g)};for(let x of c){let h=l.get(x)??[],g=u.get(x)??[];if(!Vl(h,g))if(h.length===0&&g.length>0)m(x,"joined cluster");else if(h.length>0&&g.length===0)m(x,"left cluster");else m(x,"cluster changed")}let v=new Set([...d.keys(),...p.keys()]);for(let x of v){let h=d.get(x)??[],g=p.get(x)??[];if(Vl(h,g))continue;let b=nr(o.get(x)??n.get(x))??x,E=g.filter((_)=>!h.includes(_)),j=h.filter((_)=>!g.includes(_));for(let _ of E)if(c.includes(_))m(_,`entered pinned neighborhood of "${b}"`);for(let _ of j)if(c.includes(_))m(_,`left pinned neighborhood of "${b}"`);if(c.includes(x))m(x,"pinned neighborhood changed")}let y=c.filter((x)=>(f.get(x)?.size??0)>0).map((x)=>{let h=o.get(x);return{...qs(h,x),reasons:Array.from(f.get(x)??[]).sort((g,b)=>g.localeCompare(b))}});if(y.length===0)return null;return{type:"move-end",...a,nodes:y}}}var Yl=new Gs,or=[],oi=null,rr=null,Xl="",Kl=0;function Lv(e,t){return globalThis.setTimeout(e,t)}function Jl(e){if(e===null)return;globalThis.clearTimeout(e)}function kk(e){if(typeof globalThis.requestAnimationFrame==="function"){globalThis.requestAnimationFrame(()=>e());return}e()}function Fn(e,t){return e&&e.trim().length>0?e.trim():t}function vn(e,t=3){if(e.length===0)return"";if(e.length<=t)return e.join(", ");return`${e.slice(0,t).join(", ")} +${e.length-t}`}function Ck(e){return Array.from(new Set(Array.from(e).filter((t)=>t.length>0)))}function Gt(e,t,n,o,r=Date.now()){return{id:`${e}-${r}-${Math.random().toString(36).slice(2,8)}`,tone:e,title:t,detail:n,nodeIds:Ck(o),createdAt:r}}function Ov(e){if(e==="joined cluster")return"joined a nearby cluster";if(e==="left cluster")return"moved away from its cluster";if(e==="cluster changed")return"shifted into a different cluster";if(e==="pinned neighborhood changed")return"changed the local focus field";let t=/^entered pinned neighborhood of "(.+)"$/.exec(e);if(t)return`moved into focus around ${t[1]}`;let n=/^left pinned neighborhood of "(.+)"$/.exec(e);if(n)return`moved out of focus around ${n[1]}`;return e}function Tk(e){let t=e.added.map((r)=>Fn(r.title,r.id)),n=e.removed.map((r)=>Fn(r.title,r.id));if(t.length===0&&n.length===0)return null;let o="";if(t.length>0&&n.length===0)o=`Now in focus: ${vn(t)}`;else if(n.length>0&&t.length===0)o=`Removed from focus: ${vn(n)}`;else{let r=[];if(t.length>0)r.push(`${vn(t)} added`);if(n.length>0)r.push(`${vn(n)} removed`);o=r.join(" · ")}return Gt("context","Context updated",o,[...e.added.map((r)=>r.id),...e.removed.map((r)=>r.id)],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function Ek(e){if(e.edges.length===0)return null;if(e.edges.length===1){let t=e.edges[0];return Gt("relationship","Relationship added",`${Fn(t.fromTitle,t.fromId)} linked to ${Fn(t.toTitle,t.toId)}`,[t.fromId,t.toId],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}return Gt("relationship","Relationships added",`${e.edges.length} connections changed the board structure`,e.edges.flatMap((t)=>[t.fromId,t.toId]),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function Ak(e){if(e.nodes.length===0&&e.edges.length===0)return null;let t=e.nodes.map((o)=>Fn(o.title,o.id)),n=[];if(t.length>0)n.push(vn(t));if(e.edges.length>0)n.push(`${e.edges.length} relationship${e.edges.length===1?"":"s"}`);return Gt("remove","Items removed",n.join(" · "),[...e.nodes.map((o)=>o.id),...e.edges.flatMap((o)=>[o.fromId,o.toId])],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function Ik(e){if(e.created.length>0){let t=e.created.map((n)=>Fn(n.title,n.id));return Gt("group",e.created.length===1?"Group created":"Groups created",e.created.length===1?`${t[0]} now frames ${e.created[0].childCount} items`:vn(t),e.created.map((n)=>n.id),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}if(e.updated.length>0){let t=e.updated.map((n)=>Fn(n.title,n.id));return Gt("group",e.updated.length===1?"Group updated":"Groups updated",e.updated.length===1?`${t[0]} now holds ${e.updated[0].childCount} items`:vn(t),e.updated.map((n)=>n.id),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}return null}function zk(e){if(e.nodes.length===0)return null;let t=e.nodes.flatMap((s)=>s.reasons),n=e.nodes.map((s)=>Fn(s.title,s.id)),o=e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now();if(t.some((s)=>s.includes("pinned neighborhood"))){if(e.nodes.length===1)return Gt("neighborhood","Neighborhood changed",`${n[0]} ${Ov(e.nodes[0].reasons[0])}`,e.nodes.map((s)=>s.id),o);return Gt("neighborhood","Neighborhood changed",vn(n),e.nodes.map((s)=>s.id),o)}let r=t.filter((s)=>s.includes("cluster"));if(r.length>0){let s=r.every((a)=>a==="joined cluster");if(e.nodes.length===1)return Gt("cluster",s?"Cluster formed":"Cluster changed",`${n[0]} ${Ov(e.nodes[0].reasons[0])}`,e.nodes.map((a)=>a.id),o);return Gt("cluster",s?"Cluster formed":"Cluster changed",vn(n),e.nodes.map((a)=>a.id),o)}return null}function Pk(e){switch(e.type){case"context-pin":return Tk(e);case"connect":return Ek(e);case"remove":return Ak(e);case"group":return Ik(e);case"move-end":return zk(e)}}function Nk(){let e=Yl.getAttentionSnapshot();kv(e.primaryFocusNodeIds,e.secondaryFocusNodeIds,e.regions)}function Dv(){if(oi!==null)return;let e=or.shift()??null;if(!e){Bs(null);return}Bs(e);let t=Math.max(1800,Math.min(2800,1600+e.detail.length*18));oi=Lv(()=>{oi=null,Bs(null),Dv()},t)}function Fv(e){if(or.push(e),or.length>3)or.splice(0,or.length-3);Dv()}function ir(e,t,n="",o=[]){Fv(Gt(e,t,n,o))}function Rk(e){if(Jl(rr),rr=null,Us([]),e.length===0)return;kk(()=>{Us(e),rr=Lv(()=>{rr=null,Us([])},900)})}function $k(e){let t=`${e.tone}:${e.title}:${e.detail}`,n=e.createdAt;if(t===Xl&&n-Kl<1200)return!0;return Xl=t,Kl=n,!1}function Ql(){Jl(oi),Jl(rr),oi=null,rr=null,or=[],Xl="",Kl=0,Yl=new Gs,_v()}function eu(e){let t=Yl.handleMessage(e).map((n)=>Pk(n)).filter((n)=>n!==null);Nk();for(let n of t){if($k(n))continue;Cv(n),Fv(n),Rk(n.nodeIds)}}async function jn(e,t,n,o){let r=await Ts({type:t,sourceNodeId:e.id,sourceSurface:"native-node",...n?{payload:n}:{}});if(r.ok)ir("context",o,"",[e.id]);else ir("remove","AX action failed",r.error??r.code??"Unknown error",[e.id])}var wo={padding:"3px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer",flexShrink:0};function Mk(e){let t=e.title||e.label||e.key||"Context",n=e.summary?.trim()||"Available in startup context.",o=e.pathDisplay||e.path||"",r=e.category==="profile"?"Operator":e.category==="planning"||e.category==="memory"?"Product":e.category?e.category.charAt(0).toUpperCase()+e.category.slice(1):void 0,s=e.sourceKind==="global"?"Global":"Workspace",a=e.state==="missing"?"Missing":e.state==="stale"?"Stale":e.state==="invalid"?"Invalid":"Loaded";return{title:t,summary:n,pathDisplay:o,category:r,sourceKind:s,status:a,required:e.required===!0}}function Xt(e){return typeof e==="string"?e.trim():""}function Ok(e){return e.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}function Lk(e){let t=Xt(e.title),n=Xt(e.content),o=Ok(Xt(e.rendered)),r=n||o,s=Xt(e.path);if(!t&&!r&&!s)return null;return{title:t||"Context",summary:r,path:s}}function Dk(e){let t=Xt(e.data.title)||e.id,n=Xt(e.data.content)||Xt(e.data.excerpt)||Xt(e.data.description)||Xt(e.data.pageTitle)||"",o=Xt(e.data.path)||Xt(e.data.url);return{id:e.id,title:t,summary:n,kind:at[e.type]??e.type,path:o}}function jv(e){if(e===null||!Number.isFinite(e)||e<0)return"0";if(e>=1e6)return`${(e/1e6).toFixed(1)}m`;if(e>=1000)return`${(e/1000).toFixed(1)}k`;return`${Math.round(e)}`}function Fk(e){if(e>=0.95)return"var(--c-danger)";if(e>=0.85)return"var(--c-warn)";if(e>=0.7)return"var(--c-warn)";return"var(--c-accent)"}function Xs({node:e,expanded:t=!1,pinnedNodes:n=[]}){let o=e.data.cards??[],r=e.data.auxTabs??[],s=n.map(Dk),a=s.length>0,c=typeof e.data.currentTokens==="number"?e.data.currentTokens:null,l=typeof e.data.tokenLimit==="number"?e.data.tokenLimit:null,u=typeof e.data.utilization==="number"?e.data.utilization:null,d=typeof e.data.messagesLength==="number"?e.data.messagesLength:null,p=u!==null?Math.max(0,Math.min(100,Math.round(u*100))):null,f=Fk(u??0),m=!a&&o.length===0&&r.length===0?Lk(e.data):null,v=async(y)=>{let x=typeof y.path==="string"?y.path.trim():"";if(!x)return;await _s(x)};return i("div",{style:{display:"flex",flexDirection:"column",gap:t?"10px":"6px",fontSize:t?"14px":"12px",maxWidth:t?"760px":void 0,margin:t?"0 auto":void 0,width:t?"100%":void 0,padding:t?"8px 0":void 0},children:[i("div",{style:{display:"flex",justifyContent:"flex-end"},children:i("button",{type:"button",class:"ax-node-action",title:"Point the agent at this node — sets it as the agent's current AX focus so the agent pulls it into context to work on next (a one-click alternative to manually pinning).",style:wo,onClick:(y)=>{y.stopPropagation(),jn(e,"ax.focus.set",void 0,"Focus set")},children:"Set focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),l!==null&&l>0&&i("div",{style:{marginBottom:"8px"},children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:"Token Usage"},void 0,!1,void 0,this),i("div",{style:{height:"6px",background:"var(--c-surface-hover)",borderRadius:"3px",overflow:"hidden",marginBottom:"4px"},children:i("div",{style:{height:"100%",width:`${Math.min(100,(u??0)*100)}%`,background:f,borderRadius:"3px",transition:"width 0.3s ease"}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{style:{fontSize:"11px",color:"var(--c-muted)"},children:[p,"% — ",jv(c)," / ",jv(l)," tokens",d!==null&&i(ve,{children:[" · ",d," messages"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:["Pinned Context (",s.length,")"]},void 0,!0,void 0,this),s.map((y)=>i("div",{style:{padding:"6px 8px",background:"var(--c-surface-subtle)",borderRadius:"6px",marginBottom:"4px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"2px"},children:y.title},void 0,!1,void 0,this),y.summary&&i("div",{style:{color:"var(--c-muted)",fontSize:"10px",lineHeight:1.45,marginBottom:"4px",whiteSpace:"pre-wrap"},children:y.summary},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"4px",flexWrap:"wrap",marginTop:"4px"},children:i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:y.kind},void 0,!1,void 0,this)},void 0,!1,void 0,this),y.path&&i("div",{style:{marginTop:"6px"},children:[i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all",marginBottom:"6px"},children:y.path},void 0,!1,void 0,this),y.path.startsWith("/")&&i("button",{type:"button",onClick:()=>void _s(y.path),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},y.id,!0,void 0,this))]},void 0,!0,void 0,this),!a&&o.length>0&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:["Context (",o.length,")"]},void 0,!0,void 0,this),o.map((y)=>{let x=Mk(y);return i("div",{style:{padding:"6px 8px",background:"var(--c-surface-subtle)",borderRadius:"6px",marginBottom:"4px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"2px"},children:x.title},void 0,!1,void 0,this),i("div",{style:{color:"var(--c-muted)",fontSize:"10px",lineHeight:1.45,marginBottom:"4px"},children:x.summary},void 0,!1,void 0,this),x.pathDisplay&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all"},children:x.pathDisplay},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"4px",flexWrap:"wrap",marginTop:"4px"},children:[i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-accent-10)",color:"var(--c-accent)",borderRadius:"3px",display:"inline-block"},children:x.status},void 0,!1,void 0,this),x.category&&i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:x.category},void 0,!1,void 0,this),i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:x.sourceKind},void 0,!1,void 0,this),x.required&&i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-warn-12)",color:"var(--c-warn-alt)",borderRadius:"3px",display:"inline-block"},children:"Required"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y.path&&i("div",{style:{marginTop:"6px"},children:i("button",{type:"button",onClick:()=>void v(y),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},y.key??x.pathDisplay??x.title,!0,void 0,this)})]},void 0,!0,void 0,this),!a&&r.length>0&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px",marginTop:o.length>0?"8px":0},children:["References (",r.length,")"]},void 0,!0,void 0,this),r.map((y)=>i("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",padding:"4px 8px",color:"var(--c-accent)",fontSize:"11px",textDecoration:"none",borderRadius:"4px",marginBottom:"2px",wordBreak:"break-all"},children:[y.url,y.reason&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",marginLeft:"6px"},children:["(",y.reason,")"]},void 0,!0,void 0,this)]},y.id,!0,void 0,this))]},void 0,!0,void 0,this),m&&i("div",{style:{padding:"8px 10px",background:"var(--c-surface-subtle)",borderRadius:"6px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"4px"},children:m.title},void 0,!1,void 0,this),m.summary&&i("div",{style:{color:"var(--c-text-soft)",fontSize:"11px",lineHeight:1.5,whiteSpace:"pre-wrap"},children:m.summary},void 0,!1,void 0,this),m.path&&i("div",{style:{marginTop:"6px"},children:[i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all",marginBottom:"6px"},children:m.path},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>void _s(m.path),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!a&&!m&&o.length===0&&r.length===0&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic"},children:"No context loaded"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Zv(e){return e.replace(/^[ab]\//,"")}function jk(e,t){if(t&&t!=="/dev/null")return Zv(t);if(e&&e!=="/dev/null")return Zv(e);return null}function Zk(e){if(!e.trim())return[];let t=e.split(`
74
- `);if(t.length>0&&t[t.length-1]==="")t.pop();let n=[],o=null,r=!1,s=(a)=>{let c={path:a,lines:[]};return r=!1,n.push(c),c};for(let a=0;a<t.length;a++){let c=t[a]??"",l=c.match(/^diff --git a\/(.+?) b\/(.+)$/);if(l){o=s(l[2]??null);continue}let u=t[a+1]??"";if(c.startsWith("--- ")&&u.startsWith("+++ ")){let p=jk(c.slice(4).trim(),u.slice(4).trim());if(o&&!r){if(!o.path)o.path=p}else o=s(p);a++;continue}if(!o)o=s(null);let d=o;if(c.startsWith("@@"))r=!0,d.lines.push({kind:"hunk",text:c});else if(c.startsWith("+"))d.lines.push({kind:"add",text:c});else if(c.startsWith("-"))d.lines.push({kind:"remove",text:c});else d.lines.push({kind:"context",text:c})}return n}function Ks({node:e}){let t=typeof e.data.content==="string"?e.data.content:"",n=Ie(()=>Zk(t),[t]);if(n.length===0)return i("div",{class:"diff-node diff-node-empty",children:"Empty diff"},void 0,!1,void 0,this);return i("div",{class:"diff-node",children:n.map((o,r)=>i("div",{class:"diff-file",children:[o.path&&i("div",{class:"diff-file-header",children:o.path},void 0,!1,void 0,this),i("pre",{class:"diff-lines",children:o.lines.map((s,a)=>i("div",{class:s.kind==="hunk"?"diff-hunk":`diff-line-${s.kind}`,children:s.text||" "},a,!1,void 0,this))},void 0,!1,void 0,this)]},`${o.path??"anonymous"}-${r}`,!0,void 0,this))},void 0,!1,void 0,this)}var Hv="pmx-canvas-iframe-probe";var Hk="/api/canvas/iframe-probe",Bk=3000,vt=V(null);function Uk(){let e=new URLSearchParams(window.location.search).get("iframe-mode");return e==="srcdoc"||e==="src"?e:null}function Bv(e=Bk){return new Promise((t)=>{let n=document.createElement("iframe");n.setAttribute("data-pmx-iframe-probe",""),n.style.cssText="position:fixed;width:1px;height:1px;left:-9999px;border:none",n.setAttribute("sandbox","allow-scripts");let o=(a)=>{window.clearTimeout(s),window.removeEventListener("message",r),n.remove(),t(a)},r=(a)=>{if(a.source!==n.contentWindow)return;if(a.data?.source!==Hv)return;o(!0)},s=window.setTimeout(()=>o(!1),e);window.addEventListener("message",r),n.addEventListener("error",()=>o(!1)),n.src=Hk,(document.body??document.documentElement).appendChild(n)})}var Js=null;function Wk(){try{return window.self!==window.top}catch{return!0}}function qk(){return window.__PMX_AMP_ORB===!0}function Uv(e={}){if(vt.value)return Promise.resolve(vt.value);if(Js)return Js;let t=Uk();if(t)return vt.value=t,Promise.resolve(t);if(!(e.embedded??Wk()))return vt.value="src",Bv(e.probeTimeoutMs).then((n)=>{if(!n&&vt.value==="src")vt.value="srcdoc"}),Promise.resolve("src");if(e.ampOrb??qk())return vt.value="srcdoc",Promise.resolve("srcdoc");return Js=Bv(e.probeTimeoutMs).then((n)=>{let o=n?"src":"srcdoc";return vt.value=o,o}),Js}function Vk(e){let t=e.split(".").pop()?.toLowerCase()??"";return{ts:"TypeScript",tsx:"TSX",js:"JavaScript",jsx:"JSX",py:"Python",rs:"Rust",go:"Go",rb:"Ruby",java:"Java",kt:"Kotlin",swift:"Swift",c:"C",cpp:"C++",h:"C/C++",css:"CSS",html:"HTML",json:"JSON",yaml:"YAML",yml:"YAML",md:"Markdown",toml:"TOML",sql:"SQL",sh:"Shell",bash:"Shell",xml:"XML",graphql:"GraphQL",proto:"Protobuf"}[t]??(t.toUpperCase()||"Text")}var tu=500;function Gk(e){let t=e.toLowerCase();if(t.endsWith(".csv"))return",";if(t.endsWith(".tsv"))return"\t";return null}function Xk(e,t){let n=[],o=[],r="",s=!1,a=!1;for(let l=0;l<e.length;l++){let u=e[l];if(a=!0,s){if(u==='"')if(e[l+1]==='"')r+='"',l++;else s=!1;else if(u==="\r"&&e[l+1]===`
65
+ `).trim()}function Qe(e,t){if(t<=0)return"";let n=Gk(e);if(n.length<=t)return n;if(t<=1)return n.slice(0,t);return`${n.slice(0,Math.max(0,t-1)).trimEnd()}…`}function ko(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)?e:{}}function Qo(e){if(typeof e==="string"||typeof e==="number"||typeof e==="boolean")return String(e);if(Array.isArray(e))return e.map(Qo).filter(Boolean).join(`
66
+ `);return Object.entries(ko(e)).map(([t,n])=>{let o=Qo(n);return o?`${t}: ${o}`:""}).filter(Boolean).join("; ")}function ut(e,t){return t.map((n)=>{let o=e[n];return typeof o==="string"||typeof o==="number"||typeof o==="boolean"?String(o):""}).filter(Boolean).join(`
67
+ `)}function Xk(e){let t=typeof e.graphType==="string"?e.graphType:"chart",n=Qo(e.data);return`Chart: ${t}.
68
+ ${ut(e,["title","beforeLabel","afterLabel"])}
69
+ ${n||"No chart values available."}`}function Kk(e){let t=ko(e),n=ko(t.elements),o=new Set,r=[],s=(a)=>{if(o.has(a))return;o.add(a);let c=ko(n[a]),l=ko(c.props),u=ut(l,["title","description","text","content","label","value","caption"]);if(u)r.push(u);if(Array.isArray(l.data))r.push(Qo(l.data));if(Array.isArray(c.children)){for(let p of c.children)if(typeof p==="string")s(p)}};if(typeof t.root==="string")s(t.root);return r.length?`Authored surface content (dynamic visibility not evaluated):
70
+ ${r.join(`
71
+ `)}`:"Interactive surface. No static text available; inspect the rendered surface."}function Jk(e,t){let n=[],o=typeof e.url==="string"?e.url:"",r=typeof e.pageTitle==="string"?e.pageTitle:"",s=typeof e.description==="string"?e.description:"",a=typeof e.status==="string"?e.status:"",c=typeof e.statusCode==="number"?e.statusCode:null,l=typeof e.error==="string"?e.error:"",u=typeof e.content==="string"?e.content:typeof e.excerpt==="string"?e.excerpt:"";if(o)n.push(`URL: ${o}`);if(r)n.push(`Title: ${r}`);if(s)n.push(`Description: ${s}`);if(a||c!==null)n.push(`Fetch: ${a||"unknown"}${c!==null?` (${c})`:""}`);if(l)n.push(`Error: ${l}`);let p=n.join(`
72
+ `),d=Math.max(0,t-p.length-(p?2:0)),f=d>0?Qe(u,d):"";if(p&&f)return`${p}
73
+
74
+ ${f}`;if(p)return Qe(p,t);return Qe(u,t)}function Yk(e){if(e===null||e===void 0)return"";if(typeof e!=="object"||Array.isArray(e))return"";let t=e.elements;if(Array.isArray(t)){let n=t.map((o)=>ut(ko(o),["text","label"])).filter(Boolean);return`Diagram elements: ${t.length}
75
+ ${n.length?`Diagram labels: ${n.join("; ")}`:"No diagram description available."}`}return"No app content description available."}function Qk(e,t){let n=[],o=typeof e.title==="string"?e.title:"",r=typeof e.mode==="string"?e.mode:"",s=typeof e.hostMode==="string"?e.hostMode:"",a=typeof e.serverName==="string"?e.serverName:"",c=typeof e.toolName==="string"?e.toolName:"",l=typeof e.resourceUri==="string"?e.resourceUri:"",u=typeof e.path==="string"?e.path:"",p=typeof e.url==="string"?e.url:"",d=typeof e.sessionStatus==="string"?e.sessionStatus:"",f=Yk(e.toolInput);if(o)n.push(`App: ${o}`);if(r||s)n.push(`Mode: ${[r,s].filter(Boolean).join(" / ")}`);if(a||c)n.push(`Source: ${[a,c].filter(Boolean).join(" / ")}`);if(l)n.push(`Resource: ${l}`);if(u)n.push(`Path: ${u}`);if(p)n.push(`URL: ${p}`);if(d)n.push(`Session: ${d}`);if(f)n.push(f);if(n.length===0)return"MCP App node";return Qe(n.join(`
76
+ `),t)}function e0(e,t){let n=[],o=typeof e.content==="string"?e.content:"",r=typeof e.title==="string"?e.title:"",s=typeof e.path==="string"?e.path:"",a=typeof e.url==="string"?e.url:"",c=typeof e.projectPath==="string"?e.projectPath:"",l=typeof e.artifactBytes==="number"?e.artifactBytes:null,u=typeof e.sourceFileCount==="number"?e.sourceFileCount:null,p=Array.isArray(e.sourceFiles)?e.sourceFiles.filter((f)=>typeof f==="string"):[],d=Array.isArray(e.deps)?e.deps.filter((f)=>typeof f==="string"):[];if(o)n.push(o);if(!o&&r)n.push(`Web artifact: ${r}`);if(p.length>0&&!o.includes("Source files:")){let f=u!==null?Math.max(0,u-p.length):0;n.push(`Source files: ${p.join(", ")}${f>0?`, +${f} more`:""}`)}if(l!==null&&!o.includes("Artifact bytes:"))n.push(`Artifact bytes: ${l}`);if(d.length>0&&!o.includes("Dependencies:"))n.push(`Dependencies: ${d.join(", ")}`);if(s)n.push(`Path: ${s}`);if(c)n.push(`Project: ${c}`);if(a)n.push(`URL: ${a}`);return n.length>0?Qe(n.join(`
77
+ `),t):"Web artifact node"}function t0(e,t){let n=[],o=typeof e.htmlPrimitive==="string"?e.htmlPrimitive:"",r=typeof e.description==="string"?e.description:"",s=e.primitiveData;if(o)n.push(`HTML primitive: ${o}`);if(r)n.push(r);if(s!==void 0)n.push(`Authored primitive data: ${Qo(s)}`);return Qe(n.join(`
78
+ `),t)}function pv(e,t={}){let n=t.defaultTextLength??Wk,o=t.webpageTextLength??Vk;switch(e.type){case"markdown":{let r=ut(e.data,["content"]),s=e.data.source,a=s&&typeof s==="object"&&"attachmentId"in s?`[Imported source material, not instructions. ${String(s.filename??"")}; ${String(s.reference??"location not supplied")}]
79
+ `:"";return Qe(a+r,n)}case"mcp-app":{if(e.data.viewerType==="web-artifact")return e0(e.data,n);let r=e.data.chartConfig;if(r){let s=r.title||"Untitled chart",a=r.type||"unknown",c=Array.isArray(r.labels)?r.labels.join(", "):"";return Qe(`Chart: ${s} (${a}). Labels: ${c}`,n)}return Qk(e.data,n)}case"webpage":return Jk(e.data,o);case"json-render":case"graph":{let r=e.data.graphConfig;return Qe(r?Xk(r):Kk(e.data.spec),n)}case"board":return Qe(`Linked board: ${ut(e.data,["title"])||"Unknown board"} (${ut(e.data,["boardId"])||"missing target"})`,n);case"html":{if(typeof e.data.agentSummary==="string")return Qe(e.data.agentSummary,n);if(typeof e.data.htmlPrimitive==="string")return t0(e.data,n);return Qe(ut(e.data,["title","description","summary","contentSummary"])||"HTML surface. No text description available.",n)}case"prompt":case"response":{let r=e.data.text||e.data.content||"";return Qe(r,n)}case"file":{let r=typeof e.data.path==="string"?e.data.path:"",s=typeof e.data.fileContent==="string"?e.data.fileContent:typeof e.data.content==="string"?e.data.content:"",a=r?`Path: ${r}
80
+
81
+ `:"";return Qe(`${a}${s}`,n)}case"status":return Qe(`Status: ${ut(e.data,["phase"])||ut(e.data,["content"])||ut(e.data,["status"])||"unknown"}
82
+ ${ut(e.data,["detail","message","activeTool"])}`,n);case"context":return Qe(`Context:
83
+ ${ut(e.data,["content","path"])}
84
+ ${Array.isArray(e.data.cards)?e.data.cards.map((r)=>ut(ko(r),["title","label","summary","path","state"])).join(`
85
+ `):""}`,n);case"ledger":{let{title:r,__type:s,strictSize:a,arrangeLocked:c,...l}=e.data;return Qe(`Ledger:
86
+ ${Qo(l)}`,n)}case"trace":return Qe(`Tool trace:
87
+ ${ut(e.data,["toolName","status","resultSummary","content","error"])}`,n);case"diff":case"mermaid":return Qe(`${e.type==="diff"?"Diff":"Mermaid diagram source"}:
88
+ ${ut(e.data,["content"])}`,n);case"image":return Qe(ut(e.data,["alt","caption","description"])||"No image description available; inspect the image.",n);case"group":return Qe(`Group: ${ut(e.data,["title"])||"Untitled"}. ${Array.isArray(e.data.children)?e.data.children.length:0} cards.`,n)}}function n0(e,t){let n=e.position.x+e.size.width/2,o=e.position.y+e.size.height/2,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2;return Math.sqrt((n-r)**2+(o-s)**2)}function o0(e,t){let n=e.position.x+e.size.width,o=e.position.y+e.size.height,r=t.position.x+t.size.width,s=t.position.y+t.size.height,a=Math.max(0,Math.max(e.position.x,t.position.x)-Math.min(n,r)),c=Math.max(0,Math.max(e.position.y,t.position.y)-Math.min(o,s));return Math.sqrt(a**2+c**2)}function r0(e){let t=[...e],n=100;return t.sort((o,r)=>{let s=Math.floor(o.position.y/100),a=Math.floor(r.position.y/100);if(s!==a)return s-a;return o.position.x-r.position.x}),t}function i0(e){let t=e.find((r)=>r.data.title&&typeof r.data.title==="string");if(t&&e.length<=3)return e.filter((s)=>s.data.title).map((s)=>s.data.title).slice(0,3).join(", ");let n={};for(let r of e)n[r.type]=(n[r.type]??0)+1;let o=Object.entries(n).map(([r,s])=>s===1?r:`${s} ${r}`);if(t)return`${t.data.title} + ${o.join(", ")}`;return o.join(", ")}function s0(e,t){return e.x<=t.x+t.width&&e.x+e.width>=t.x&&e.y<=t.y+t.height&&e.y+e.height>=t.y}function a0(e,t){let n=t.filter((r)=>s0(e.bounds,{x:r.position.x,y:r.position.y,width:r.size.width,height:r.size.height})),o=n.map((r)=>typeof r.data.title==="string"&&r.data.title.length>0?r.data.title:r.id);return{id:e.id,label:e.label??e.text??null,bounds:e.bounds,targetNodeIds:n.map((r)=>r.id),targetNodeTitles:o,target:o.length>0?o.join(", "):"empty canvas region"}}function c0(e,t=200){if(e.length===0)return[];let n=new Map,o=(l)=>{while(n.get(l)!==l){let u=n.get(l);n.set(l,n.get(u)),l=u}return l},r=(l,u)=>{let p=o(l),d=o(u);if(p!==d)n.set(p,d)};for(let l of e)n.set(l.id,l.id);for(let l=0;l<e.length;l++)for(let u=l+1;u<e.length;u++)if(o0(e[l],e[u])<=t)r(e[l].id,e[u].id);let s=new Map;for(let l of e){let u=o(l.id);if(!s.has(u))s.set(u,[]);s.get(u).push(l)}let a=[],c=0;for(let[,l]of s){if(l.length<2)continue;let u=l.map((g)=>g.position.x),p=l.map((g)=>g.position.y),d=l.map((g)=>g.position.x+g.size.width),f=l.map((g)=>g.position.y+g.size.height),m=Math.min(...u),h=Math.min(...p),v=Math.max(...d),x=Math.max(...f);a.push({id:`cluster-${c++}`,nodeIds:l.map((g)=>g.id),label:i0(l),centroid:{x:Math.round((m+v)/2),y:Math.round((h+x)/2)},bounds:{x:m,y:h,width:v-m,height:x-h}})}return a.sort((l,u)=>{let p=Math.floor(l.centroid.y/200),d=Math.floor(u.centroid.y/200);if(p!==d)return p-d;return l.centroid.x-u.centroid.x}),a}function l0(e,t,n=5,o=600){let r=e.filter((a)=>t.has(a.id)),s=e.filter((a)=>!t.has(a.id));return r.map((a)=>{let c=s.map((l)=>({node:l,distance:n0(a,l)})).filter((l)=>l.distance<=o).sort((l,u)=>l.distance-u.distance).slice(0,n);return{pinnedNodeId:a.id,pinnedNodeTitle:a.data.title??null,neighbors:c.map((l)=>({id:l.node.id,type:l.node.type,title:l.node.data.title??null,distance:Math.round(l.distance)}))}})}function ci(e,t,n,o=[]){let r=c0(e),s=new Map;for(let u of r)for(let p of u.nodeIds)s.set(p,u.id);let c=r0(e).map((u,p)=>({id:u.id,type:u.type,title:u.data.title??null,content:pv(u,{defaultTextLength:320,webpageTextLength:640})||null,clusterId:s.get(u.id)??null,readingOrder:p})),l=l0(e,n);return{totalNodes:e.length,clusters:r,nodesInReadingOrder:c,pinnedNeighborhoods:l,annotations:o.map((u)=>a0(u,e))}}function er(e){if(!e)return null;let t=e.data.title;return typeof t==="string"&&t.trim().length>0?t.trim():null}function Os(e,t){return{id:e?.id??t,title:er(e),nodeType:e?.type??"markdown"}}function mv(e,t){return{id:e.id,edgeType:e.type,fromId:e.from,toId:e.to,fromTitle:er(t.get(e.from)),toTitle:er(t.get(e.to))}}function Ls(e){return new Map(e.map((t)=>[t.id,t]))}function fv(e){return new Map(e.map((t)=>[t.id,t]))}function Kt(e){return Array.from(e).sort((t,n)=>t.localeCompare(n))}function tu(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function nu(e){if(!e||e.type!=="group")return[];let t=e.data.children;if(!Array.isArray(t))return[];return t.filter((n)=>typeof n==="string").sort((n,o)=>n.localeCompare(o))}function hv(e){let t=new Map;for(let n of e.clusters){let o=[...n.nodeIds].sort((r,s)=>r.localeCompare(s));for(let r of o)t.set(r,o.filter((s)=>s!==r))}return t}function gv(e){let t=new Map;for(let n of e.pinnedNeighborhoods)t.set(n.pinnedNodeId,n.neighbors.map((o)=>o.id).sort((o,r)=>o.localeCompare(r)));return t}function u0(e,t){let n=Kt(Array.from(t).filter((r)=>!e.has(r))),o=Kt(Array.from(e).filter((r)=>!t.has(r)));return{added:n,removed:o}}function vv(e){let t=e&&typeof e==="object"?e:{};return{timestamp:typeof t.timestamp==="string"?t.timestamp:void 0,sessionId:typeof t.sessionId==="string"?t.sessionId:void 0}}function d0(e,t,n){if(!e||!n)return{layout:e,pinnedNodeIds:[],primaryFocusNodeIds:[],secondaryFocusNodeIds:[],regions:[],spatial:n};let o=Ls(e.nodes),r=Kt(t).filter((l)=>o.has(l)),s=new Set(r),a=new Set,c=[];for(let l of n.pinnedNeighborhoods){if(!s.has(l.pinnedNodeId))continue;let u=Kt([l.pinnedNodeId,...l.neighbors.map((p)=>p.id)]).filter((p,d,f)=>f.indexOf(p)===d&&o.has(p));for(let p of u)if(!s.has(p))a.add(p);c.push({id:`region-${l.pinnedNodeId}`,primaryNodeId:l.pinnedNodeId,nodeIds:u})}if(c.length===0&&r.length>0)for(let l of r)c.push({id:`region-${l}`,primaryNodeId:l,nodeIds:[l]});return{layout:e,pinnedNodeIds:r,primaryFocusNodeIds:r,secondaryFocusNodeIds:Kt(a),regions:c,spatial:n}}class Ds{currentLayout=null;currentPins=new Set;previousSpatial=null;setInitialPins(e){this.currentPins=new Set(e)}getAttentionSnapshot(){return d0(this.currentLayout,this.currentPins,this.previousSpatial)}handleMessage(e){if(e.event==="context-pins-changed")return this.handleContextPinsChanged(e.data);if(e.event==="canvas-layout-update")return this.handleLayoutUpdate(e.data);return[]}handleContextPinsChanged(e){let t=e&&typeof e==="object"?e:{},n=Array.isArray(t.nodeIds)?t.nodeIds.filter((u)=>typeof u==="string"):[],o=vv(e),r=new Set(n),{added:s,removed:a}=u0(this.currentPins,r);if(this.currentPins=r,!this.currentLayout)return[];let c=Ls(this.currentLayout.nodes),l={added:s.map((u)=>Os(c.get(u),u)),removed:a.map((u)=>Os(c.get(u),u))};if(this.previousSpatial=ci(this.currentLayout.nodes,this.currentLayout.edges,this.currentPins,this.currentLayout.annotations??[]),l.added.length===0&&l.removed.length===0)return[];return[{type:"context-pin",...o,...l}]}handleLayoutUpdate(e){let t=e&&typeof e==="object"?e:{},n=t.layout&&typeof t.layout==="object"?t.layout:null;if(!n)return[];let o=vv(e);if(!this.currentLayout)return this.currentLayout=n,this.previousSpatial=ci(n.nodes,n.edges,this.currentPins,n.annotations??[]),[];let r=this.currentLayout,s=this.previousSpatial??ci(r.nodes,r.edges,this.currentPins,r.annotations??[]),a=ci(n.nodes,n.edges,this.currentPins,n.annotations??[]),c=[],l=Ls(r.nodes),u=Ls(n.nodes),p=fv(r.edges),d=fv(n.edges),f=Kt(Array.from(d.keys()).filter((g)=>!p.has(g))).map((g)=>d.get(g)).filter((g)=>g!==void 0);if(f.length>0)c.push({type:"connect",...o,edges:f.map((g)=>mv(g,u))});let m=Kt(Array.from(l.keys()).filter((g)=>!u.has(g))),h=Kt(Array.from(p.keys()).filter((g)=>!d.has(g)));if(m.length>0||h.length>0)c.push({type:"remove",...o,nodes:m.map((g)=>Os(l.get(g),g)),edges:h.map((g)=>p.get(g)).filter((g)=>g!==void 0).map((g)=>mv(g,l))});let v=this.buildGroupEvent(l,u,o);if(v)c.push(v);let x=this.buildMoveEndEvent(r,n,l,u,s,a,o);if(x)c.push(x);return this.currentLayout=n,this.previousSpatial=a,c}buildGroupEvent(e,t,n){let o=Kt(Array.from(e.values()).filter((c)=>c.type==="group").map((c)=>c.id)),r=Kt(Array.from(t.values()).filter((c)=>c.type==="group").map((c)=>c.id)),s=r.filter((c)=>!o.includes(c)).map((c)=>{let l=t.get(c),u=nu(l);return{id:c,title:er(l),childCount:u.length}}),a=[];for(let c of r.filter((l)=>o.includes(l))){let l=nu(e.get(c)),u=nu(t.get(c));if(tu(l,u))continue;a.push({id:c,title:er(t.get(c)),addedChildIds:u.filter((p)=>!l.includes(p)),removedChildIds:l.filter((p)=>!u.includes(p)),childCount:u.length})}if(s.length===0&&a.length===0)return null;return{type:"group",...n,created:s,updated:a}}buildMoveEndEvent(e,t,n,o,r,s,a){let c=Kt(Array.from(o.keys()).filter((x)=>{let g=n.get(x),y=o.get(x);if(!g||!y)return!1;return g.position.x!==y.position.x||g.position.y!==y.position.y}));if(c.length===0)return null;let l=hv(r),u=hv(s),p=gv(r),d=gv(s),f=new Map,m=(x,g)=>{let y=f.get(x)??new Set;y.add(g),f.set(x,y)};for(let x of c){let g=l.get(x)??[],y=u.get(x)??[];if(!tu(g,y))if(g.length===0&&y.length>0)m(x,"joined cluster");else if(g.length>0&&y.length===0)m(x,"left cluster");else m(x,"cluster changed")}let h=new Set([...p.keys(),...d.keys()]);for(let x of h){let g=p.get(x)??[],y=d.get(x)??[];if(tu(g,y))continue;let E=er(o.get(x)??n.get(x))??x,L=y.filter((b)=>!g.includes(b)),P=g.filter((b)=>!y.includes(b));for(let b of L)if(c.includes(b))m(b,`entered pinned neighborhood of "${E}"`);for(let b of P)if(c.includes(b))m(b,`left pinned neighborhood of "${E}"`);if(c.includes(x))m(x,"pinned neighborhood changed")}let v=c.filter((x)=>(f.get(x)?.size??0)>0).map((x)=>{let g=o.get(x);return{...Os(g,x),reasons:Array.from(f.get(x)??[]).sort((y,E)=>y.localeCompare(E))}});if(v.length===0)return null;return{type:"move-end",...a,nodes:v}}}var Fs=q(null),li=q([]),nr=q(new Set),or=q(new Set),Bs=q([]),Hs=q(new Set),ln=q(!1),tr=q(0);function yv(){Fs.value=null,li.value=[],nr.value=new Set,or.value=new Set,Bs.value=[],Hs.value=new Set,ln.value=!1,tr.value=0}function js(){ln.value=!0,tr.value=0}function bv(){ln.value=!1}function xv(e,t,n){nr.value=new Set(e),or.value=new Set(t),Bs.value=n}function Zs(e){Fs.value=e}function ou(e,t=6){if(li.value=[e,...li.value].slice(0,t),!ln.value)tr.value=Math.min(99,tr.value+1)}function Us(e){Hs.value=new Set(e)}var au=new Ds,rr=[],ui=null,ir=null,ru="",iu=0;function _v(e,t){return globalThis.setTimeout(e,t)}function su(e){if(e===null)return;globalThis.clearTimeout(e)}function p0(e){if(typeof globalThis.requestAnimationFrame==="function"){globalThis.requestAnimationFrame(()=>e());return}e()}function Un(e,t){return e&&e.trim().length>0?e.trim():t}function vn(e,t=3){if(e.length===0)return"";if(e.length<=t)return e.join(", ");return`${e.slice(0,t).join(", ")} +${e.length-t}`}function m0(e){return Array.from(new Set(Array.from(e).filter((t)=>t.length>0)))}function Jt(e,t,n,o,r=Date.now()){return{id:`${e}-${r}-${Math.random().toString(36).slice(2,8)}`,tone:e,title:t,detail:n,nodeIds:m0(o),createdAt:r}}function wv(e){if(e==="joined cluster")return"joined a nearby cluster";if(e==="left cluster")return"moved away from its cluster";if(e==="cluster changed")return"shifted into a different cluster";if(e==="pinned neighborhood changed")return"changed the local focus field";let t=/^entered pinned neighborhood of "(.+)"$/.exec(e);if(t)return`moved into focus around ${t[1]}`;let n=/^left pinned neighborhood of "(.+)"$/.exec(e);if(n)return`moved out of focus around ${n[1]}`;return e}function f0(e){let t=e.added.map((r)=>Un(r.title,r.id)),n=e.removed.map((r)=>Un(r.title,r.id));if(t.length===0&&n.length===0)return null;let o="";if(t.length>0&&n.length===0)o=`Now in focus: ${vn(t)}`;else if(n.length>0&&t.length===0)o=`Removed from focus: ${vn(n)}`;else{let r=[];if(t.length>0)r.push(`${vn(t)} added`);if(n.length>0)r.push(`${vn(n)} removed`);o=r.join(" · ")}return Jt("context","Context updated",o,[...e.added.map((r)=>r.id),...e.removed.map((r)=>r.id)],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function h0(e){if(e.edges.length===0)return null;if(e.edges.length===1){let t=e.edges[0];return Jt("relationship","Relationship added",`${Un(t.fromTitle,t.fromId)} linked to ${Un(t.toTitle,t.toId)}`,[t.fromId,t.toId],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}return Jt("relationship","Relationships added",`${e.edges.length} connections changed the board structure`,e.edges.flatMap((t)=>[t.fromId,t.toId]),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function g0(e){if(e.nodes.length===0&&e.edges.length===0)return null;let t=e.nodes.map((o)=>Un(o.title,o.id)),n=[];if(t.length>0)n.push(vn(t));if(e.edges.length>0)n.push(`${e.edges.length} relationship${e.edges.length===1?"":"s"}`);return Jt("remove","Items removed",n.join(" · "),[...e.nodes.map((o)=>o.id),...e.edges.flatMap((o)=>[o.fromId,o.toId])],e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}function v0(e){if(e.created.length>0){let t=e.created.map((n)=>Un(n.title,n.id));return Jt("group",e.created.length===1?"Group created":"Groups created",e.created.length===1?`${t[0]} now frames ${e.created[0].childCount} items`:vn(t),e.created.map((n)=>n.id),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}if(e.updated.length>0){let t=e.updated.map((n)=>Un(n.title,n.id));return Jt("group",e.updated.length===1?"Group updated":"Groups updated",e.updated.length===1?`${t[0]} now holds ${e.updated[0].childCount} items`:vn(t),e.updated.map((n)=>n.id),e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now())}return null}function y0(e){if(e.nodes.length===0)return null;let t=e.nodes.flatMap((s)=>s.reasons),n=e.nodes.map((s)=>Un(s.title,s.id)),o=e.timestamp?Date.parse(e.timestamp)||Date.now():Date.now();if(t.some((s)=>s.includes("pinned neighborhood"))){if(e.nodes.length===1)return Jt("neighborhood","Neighborhood changed",`${n[0]} ${wv(e.nodes[0].reasons[0])}`,e.nodes.map((s)=>s.id),o);return Jt("neighborhood","Neighborhood changed",vn(n),e.nodes.map((s)=>s.id),o)}let r=t.filter((s)=>s.includes("cluster"));if(r.length>0){let s=r.every((a)=>a==="joined cluster");if(e.nodes.length===1)return Jt("cluster",s?"Cluster formed":"Cluster changed",`${n[0]} ${wv(e.nodes[0].reasons[0])}`,e.nodes.map((a)=>a.id),o);return Jt("cluster",s?"Cluster formed":"Cluster changed",vn(n),e.nodes.map((a)=>a.id),o)}return null}function b0(e){switch(e.type){case"context-pin":return f0(e);case"connect":return h0(e);case"remove":return g0(e);case"group":return v0(e);case"move-end":return y0(e)}}function x0(){let e=au.getAttentionSnapshot();xv(e.primaryFocusNodeIds,e.secondaryFocusNodeIds,e.regions)}function Sv(){if(ui!==null)return;let e=rr.shift()??null;if(!e){Zs(null);return}Zs(e);let t=Math.max(1800,Math.min(2800,1600+e.detail.length*18));ui=_v(()=>{ui=null,Zs(null),Sv()},t)}function kv(e){if(rr.push(e),rr.length>3)rr.splice(0,rr.length-3);Sv()}function yn(e,t,n="",o=[]){let r=Jt(e,t,n,o);ou(r),kv(r)}function w0(e){if(su(ir),ir=null,Us([]),e.length===0)return;p0(()=>{Us(e),ir=_v(()=>{ir=null,Us([])},900)})}function _0(e){let t=`${e.tone}:${e.title}:${e.detail}`,n=e.createdAt;if(t===ru&&n-iu<1200)return!0;return ru=t,iu=n,!1}function qs(){su(ui),su(ir),ui=null,ir=null,rr=[],ru="",iu=0,au=new Ds,yv()}function cu(e){let t=au.handleMessage(e).map((n)=>b0(n)).filter((n)=>n!==null);x0();for(let n of t){if(_0(n))continue;ou(n),kv(n),w0(n.nodeIds)}}function lu(e,t){console.error(`[intent-bridge] ${e} failed`,t)}var Ws=(()=>{try{let e=new URLSearchParams(window.location.search).get("agent")?.trim();return e?e.slice(0,64):null}catch{return null}})();function uu(e){let t={...e?.headers};if(Ws)t["x-pmx-source"]=Ws;else{t["X-PMX-Workbench"]="1";let n=window.__PMX_WORKBENCH_TOKEN;if(typeof n==="string")t["X-PMX-Workbench-Token"]=n}return{...e,headers:t}}function du(e,t,n){if(e.ok||(t?.method??"GET").toUpperCase()==="GET")return;let o=n!==null&&typeof n==="object"&&"error"in n&&typeof n.error==="string"?n.error:"";yn("remove","Change refused",o||`The server answered ${e.status}.`)}async function pu(e){try{return await e.json()}catch{return null}}async function Y(e,t,n,o){try{let r=await fetch(t,uu(o)),s=await pu(r);if(du(r,o,s),s===null)throw Error(`${r.status} response had no JSON body`);return s}catch(r){return lu(e,r),n}}async function $t(e,t,n){try{let o=await fetch(t,uu(n));if(!o.ok)du(o,n,await pu(o));return{ok:o.ok}}catch(o){return lu(e,o),{ok:!1}}}async function Yt(e,t,n){try{let o=await fetch(t,uu(n));if(!o.ok)du(o,n,await pu(o))}catch(o){lu(e,o)}}async function Cv(e,t={}){return Y("sendIntent","/api/workbench/intent",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:e,payload:t})})}async function Co(e){let n=`Veto: do not ${e.label?.trim()||`${e.kind} intent`}${e.reason?` — ${e.reason}`:""}.`;if((await Y("vetoGhostIntent",`/api/canvas/ax/intent/${encodeURIComponent(e.id)}`,{ok:!1,cleared:!1},{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({vetoed:!0})})).cleared!==!0)return!1;return await Yt("vetoGhostSteering","/api/canvas/ax/steer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:n,source:"browser"})}),!0}async function bn(e){return(await Y("renderMarkdown","/api/render",{},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({markdown:e})})).html??""}async function di(e){return Y("fetchFile",`/api/file?path=${encodeURIComponent(e)}`,{content:""})}async function Tv(e,t){return Y("saveFile","/api/file/save",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,content:t})})}async function Vs(e){return $t("openWorkbenchFile","/api/workbench/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})}async function Iv(){return Y("fetchCanvasState","/api/canvas/state?includeBlobs=true",{})}async function Gs(e){return Y("saveCanvasTheme","/api/canvas/theme",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({theme:e})})}async function Ev(){return[]}async function pi(e,t,n,o,r){if(!e.trim())return{ok:!1,error:"Prompt text is required"};return Y("submitCanvasPrompt","/api/canvas/prompt",{ok:!1,error:"Network error"},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e,...t?{position:t}:{},...n?{parentNodeId:n}:{},...o&&o.length>0?{contextNodeIds:o}:{},...r?{threadNodeId:r}:{}})})}async function Av(e,t){return pi(t,void 0,void 0,void 0,e)}async function Xs(e,t={}){await Yt("pushCanvasUpdate","/api/canvas/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:e,...t.recordHistory===!1?{recordHistory:!1}:{}})})}async function To(e,t,n,o){return Y("createEdgeFromClient","/api/canvas/edge",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:e,to:t,type:n,label:o})})}async function Qt(e){return Y("createNodeFromClient","/api/canvas/node",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function dt(e,t){return Y("updateNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}`,{ok:!1},{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Ks(e,t){return Y("refreshWebpageNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}/refresh`,{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{url:t}:{})})}async function qn(e){return Y("removeNodeFromClient",`/api/canvas/node/${encodeURIComponent(e)}`,{ok:!1},{method:"DELETE"})}async function zv(){return Y("fetchAxSurfaceState","/api/canvas/ax/surface-snapshot",null)}async function Pv(){return Y("fetchAgentPresence","/api/canvas/ax/presence",null)}async function Nv(e,t){return Y("openNodeInSystemBrowserRequest","/api/canvas/open-external",{ok:!1,opened:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodeId:e,url:t})})}async function Js(e){return Y("submitAxInteractionFromClient","/api/canvas/ax/interaction",{ok:!1,code:"request-failed",error:"Request failed"},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceSurface:"native-node",...e,source:"browser"})})}async function Rv(e,t={}){return Y("updateViewportFromClient","/api/canvas/viewport",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,...$v(),...t.recordHistory===!1?{recordHistory:!1}:{}})})}function $v(){if(typeof window>"u")return{};let e=ot(),t=Math.round(e.width),n=Math.round(e.height);if(!t||!n)return{};return{clientWidth:t,clientHeight:n}}async function mi(){let e=$v();if(!("clientWidth"in e))return;await Yt("reportClientViewportSize","/api/canvas/viewport",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,recordHistory:!1})})}async function sr(e){return Y("createGroupFromClient","/api/canvas/group",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function mu(e,t,n){return Y("addToGroupFromClient","/api/canvas/group/add",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({groupId:e,childIds:t,...n?{childLayout:n}:{}})})}async function Ys(e,t){return dt(e,{children:t})}async function ar(e){return Y("ungroupFromClient","/api/canvas/group/ungroup",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({groupId:e})})}async function Mv(){return Y("listSnapshots","/api/canvas/snapshots?all=true",[])}async function Ov(e){return Y("saveSnapshot","/api/canvas/snapshots",{ok:!1},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})}async function Lv(e){return Y("restoreSnapshot",`/api/canvas/snapshots/${e}`,{ok:!1},{method:"POST"})}async function Dv(e){return Y("deleteSnapshot",`/api/canvas/snapshots/${e}`,{ok:!1},{method:"DELETE"})}async function Qs(e,t){return Y("updateEdgeFromClient",`/api/canvas/edge/${encodeURIComponent(e)}`,{ok:!1},{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function ea(e){return Y("removeEdgeFromClient","/api/canvas/edge",{ok:!1},{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({edge_id:e})})}function Zv(e,t){console.error(`[canvas-store] ${e} failed`,t)}var J=q({x:0,y:0,scale:1}),F=q(new Map),Le=q(new Map),cr=q(new Map),Ce=q(null),dn=q(null),Mt=q("connecting"),Eo=q(0),Ao=q(0),zo=q(0),xn=q(""),lr=q(!1),et=q("dark"),Tt=q(!1),tn=q(null),Ue=q(null),en=q(null),bt=null,Io,Fv=100,S0=2500,hi=q(null),He=q(null),wn=q(null),ye=q(new Set),Ae=q(new Set),It=q("select"),gi=q(!1);function ur(){return It.value==="pan"||gi.value}function Uv(e,t){if(!e)return new Set;let n=new Set;for(let o of t.values()){if(o.from===e)n.add(o.to);if(o.to===e)n.add(o.from)}return n}var qv=Oe(()=>Uv(Ce.value,Le.value));function Bv(e,t){let n=new Set;for(let o of e)if(t.has(o))n.add(o);return n}function Hv(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function gu(e){let t=new Set(ye.value);if(t.has(e))t.delete(e);else t.add(e);ye.value=t}function Wv(e){ye.value=new Set(e)}function xt(){if(dn.value=null,ye.value.size===0)return;ye.value=new Set}function Vv(){if(bt!==null)clearTimeout(bt),bt=null;Rt(()=>{Ce.value=null,Ue.value=null,en.value=null,Io=void 0,ye.value=new Set,dn.value=null,hi.value=null,He.value=null,wn.value=null,un.value=null,Ae.value=new Set}),ta=!1}var un=q(null),ta=!1;function Gv(){ta=!0,un.value=null}function Xv(){ta=!1,un.value=null}function fu(e){return{x:e.position.x,y:e.position.y,w:e.size.width,h:e.size.height}}function k0(e,t,n){let o=fu(e);return t>=o.x&&t<=o.x+o.w&&n>=o.y&&n<=o.y+o.h}function jv(e,t){let n=fu(e),o=fu(t);return n.x+n.w<o.x||n.x>o.x+o.w||n.y+n.h<o.y||n.y>o.y+o.h}function Kv(e){let t=F.value.get(e);if(!t||t.type==="group")return;let n=typeof t.data.parentGroup==="string"?t.data.parentGroup:null,o=n?F.value.get(n):void 0,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2,a=null;for(let c of F.value.values()){if(c.type!=="group"||c.id===n||c.collapsed)continue;if(k0(c,r,s))a=c}if(!ta){let c=a?{nodeId:e,groupId:a.id,mode:"add"}:o&&jv(t,o)?{nodeId:e,groupId:o.id,mode:"remove"}:null,l=un.value;if((l?.groupId??null)!==(c?.groupId??null)||l?.mode!==c?.mode)un.value=c}if(o&&o.data.frameMode!=="manual"&&!jv(t,o)){let l=Math.min(o.position.x,t.position.x-22),u=Math.min(o.position.y,t.position.y-22-32),p=Math.max(o.position.x+o.size.width,t.position.x+t.size.width+22),d=Math.max(o.position.y+o.size.height,t.position.y+t.size.height+22);if(l!==o.position.x||u!==o.position.y||p!==o.position.x+o.size.width||d!==o.position.y+o.size.height)ia(o.id,{position:{x:l,y:u},size:{width:p-l,height:d-u}},{skipGroupChildTranslation:!0})}}var vu=Oe(()=>{let e=new Map;for(let t of F.value.values()){if(t.type!=="group"||!t.collapsed)continue;let n=Array.isArray(t.data.children)?t.data.children:[];for(let o of n)if(typeof o==="string")e.set(o,t.id)}return e});function na(e){let t=vu.value.get(e);return F.value.get(t??e)}function Jv(){let e=new Set;for(let t of ye.value){let n=F.value.get(t);if(!n)continue;if(n.type==="group")e.add(n.id);else if(typeof n.data.parentGroup==="string")e.add(n.data.parentGroup)}return[...e]}function yu(e){let t=bu();if(t.length<2)return;let n=Math.min(...t.map((l)=>e==="left"?l.position.x:l.position.y)),o=24,r=new Map;for(let l of t)r.set(l.id,e==="left"?{x:n,y:l.position.y}:{x:l.position.x,y:n});let s=(l,u)=>l.x<u.x+u.w&&u.x<l.x+l.w&&l.y<u.y+u.h&&u.y<l.y+l.h,a=t.map((l)=>{let u=r.get(l.id);return{node:l,x:u.x,y:u.y,w:l.size.width,h:l.size.height}});if(a.some((l,u)=>a.some((p,d)=>d>u&&s(l,p)))){let l=[...t].sort((p,d)=>e==="left"?p.position.y-d.position.y:p.position.x-d.position.x),u=e==="left"?Math.min(...t.map((p)=>p.position.y)):Math.min(...t.map((p)=>p.position.x));for(let p of l)r.set(p.id,e==="left"?{x:n,y:u}:{x:u,y:n}),u+=(e==="left"?p.size.height:p.size.width)+o}Rt(()=>{for(let l of t)it(l.id,{position:r.get(l.id)})}),st()}function Yv(){let e=bu().sort((c,l)=>c.position.x-l.position.x);if(e.length<3)return;let t=e[0],o=e[e.length-1].position.x-(t.position.x+t.size.width),r=e.slice(1,-1),s=r.reduce((c,l)=>c+l.size.width,0),a=(o-s)/(r.length+1);Rt(()=>{if(a<8){let l=t.position.x+t.size.width+24;for(let u of e.slice(1))it(u.id,{position:{x:l,y:u.position.y}}),l+=u.size.width+24;return}let c=t.position.x+t.size.width+a;for(let l of r)it(l.id,{position:{x:c,y:l.position.y}}),c+=l.size.width+a}),st()}function Qv(e=24){let t=bu().sort((c,l)=>c.position.y-l.position.y||c.position.x-l.position.x);if(t.length<2)return;let n=Math.min(...t.map((c)=>c.position.x)),o=Math.min(...t.map((c)=>c.position.y)),r=Math.ceil(Math.sqrt(t.length)),s=Math.max(...t.map((c)=>c.size.width)),a=Math.max(...t.map((c)=>c.size.height));Rt(()=>{t.forEach((c,l)=>{it(c.id,{position:{x:n+l%r*(s+e),y:o+Math.floor(l/r)*(a+e)}})})}),st()}function bu(){let e=ye.value;if(e.size===0)return[];return Array.from(e).map((t)=>F.value.get(t)).filter((t)=>t!==void 0)}function Vn(e){let t=new Set(Ae.value);if(t.has(e))t.delete(e);else t.add(e);Ae.value=t,st(),ra(t)}function oa(e){let t=new Set(Ae.value);for(let n of e)t.add(n);Ae.value=t,st(),ra(t)}function ey(){if(Ae.value.size===0)return;Ae.value=new Set,st(),ra(new Set)}function ty(e){Ae.value=new Set(e)}function ra(e){Yt("syncContextPinsToServer","/api/canvas/context-pins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodeIds:Array.from(e)})})}var fi=1;function _n(e){Rt(()=>{let t=new Map(F.value);if(e.zIndex>=fi)fi=e.zIndex+1;t.set(e.id,e),F.value=t,Ce.value=e.id})}function it(e,t){ia(e,t)}function ia(e,t,n={}){let o=F.value.get(e);if(!o)return;let r=new Map(F.value);if(o.type==="group"&&t.position&&n.skipGroupChildTranslation!==!0){let a=t.position.x-o.position.x,c=t.position.y-o.position.y;if(a!==0||c!==0){let l=Array.isArray(o.data.children)?o.data.children.filter((u)=>typeof u==="string"):[];for(let u of l){let p=r.get(u);if(!p||p.type==="group")continue;r.set(u,{...p,position:{x:p.position.x+a,y:p.position.y+c}})}}}r.set(e,{...o,...t}),F.value=r;let s=r.get(e)?.data.appCheckpoint?.updatedAt;if(en.value===e&&s!==void 0&&s!==Io)hu(e)}function ie(e,t){let n=F.value.get(e);if(!n)return;it(e,{data:{...n.data,...t}})}function Gn(e){C0(e);let t=new Map(F.value);if(t.delete(e),F.value=t,Ce.value===e)Ce.value=null;if(Ue.value===e)Ue.value=null;if(ye.value.has(e)){let n=new Set(ye.value);n.delete(e),ye.value=n}if(Ae.value.has(e)){let n=new Set(Ae.value);n.delete(e),Ae.value=n,ra(n)}}function sa(e){let t=new Map(Le.value);t.set(e.id,e),Le.value=t}function ny(e){let t=new Map(Le.value);t.delete(e),Le.value=t}function C0(e){let t=!1,n=new Map(Le.value);for(let[o,r]of n)if(r.from===e||r.to===e)n.delete(o),t=!0;if(t)Le.value=n}function T0(e){let t=new Map(cr.value);if(!t.delete(e))return;cr.value=t}async function xu(e){return $t("createAnnotationFromClient","/api/canvas/annotation",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function oy(e){let t=await $t("removeAnnotationFromClient",`/api/canvas/annotation/${encodeURIComponent(e)}`,{method:"DELETE"});if(t.ok)T0(e);return t}function aa(e,t){if(!F.value.get(e))return;it(e,{size:t})}function Sn(e){let t=F.value.get(e);if(!t)return;Rt(()=>{if(it(e,{zIndex:fi++}),t.type==="group"&&Array.isArray(t.data.children)){for(let n of t.data.children)if(typeof n==="string"&&F.value.has(n))it(n,{zIndex:fi++})}}),Ce.value=e}function dr(e){let t=F.value.get(e);if(!t)return;it(e,{collapsed:!t.collapsed}),st()}function ry(e){J.value={...J.value,...e}}function iy(e){J.value=e}function sy(e){ay(e)}function ay(e,t={}){J.value=e,st(t),Rv(e,t)}function cy(e,t={}){let n=new Map,o=1;for(let d of e.nodes)if(n.set(d.id,d),d.zIndex>=o)o=d.zIndex+1;let r=e.edges.filter((d)=>n.has(d.from)&&n.has(d.to)),s=new Map;for(let d of r)s.set(d.id,d);let a=new Map;for(let d of e.annotations??[])a.set(d.id,d);let c=Ce.value!==null&&n.has(Ce.value)?Ce.value:null,l=Ue.value!==null&&n.has(Ue.value)?Ue.value:null,u=Bv(ye.value,n),p=Bv(Ae.value,n);Rt(()=>{if(t.applyViewport===!0&&e.viewport)J.value=e.viewport;if(fi=o,F.value=n,Le.value=s,cr.value=a,Ce.value=c,Ue.value=l,!Hv(ye.value,u))ye.value=u;if(!Hv(Ae.value,p))Ae.value=p})}var Wn=null;function I0(e){return 1-(1-e)**3}function pr(e,t=150){let n=J.value,o=Math.min(4,Math.max(0.1,n.scale*e));if(o===n.scale)return;let r=o/n.scale,{x:s,y:a}=Zn();Xn({x:s-r*(s-n.x),y:a-r*(a-n.y),scale:o},t)}function Xn(e,t=300,n={}){if(Wn!==null)cancelAnimationFrame(Wn);let o={...J.value},r=performance.now();function s(a){let c=a-r,l=Math.min(1,c/t),u=I0(l);if(J.value={x:o.x+(e.x-o.x)*u,y:o.y+(e.y-o.y)*u,scale:o.scale+(e.scale-o.scale)*u},l<1)Wn=requestAnimationFrame(s);else Wn=null,ay(e,n)}Wn=requestAnimationFrame(s)}function kn(){if(Wn!==null)cancelAnimationFrame(Wn),Wn=null}var ly="pmx-canvas-layout";function st(e={}){try{let t=Array.from(F.value.values()),n=t.map((r)=>({id:r.id,position:r.position,size:r.size,collapsed:r.collapsed})),o={viewport:J.value,nodes:t.map((r)=>({id:r.id,type:r.type,position:r.position,size:r.size,collapsed:r.collapsed,pinned:r.pinned})),edges:Array.from(Le.value.values()).map((r)=>({id:r.id,from:r.from,to:r.to,type:r.type,label:r.label,style:r.style,animated:r.animated})),contextPinnedNodeIds:Array.from(Ae.value)};localStorage.setItem(ly,JSON.stringify(o)),Xs(n,e)}catch(t){Zv("persistLayout",t)}}function wu(){try{let e=localStorage.getItem(ly);if(!e)return null;let t=JSON.parse(e),n=Array.isArray(t.nodes)?t.nodes:[];if(n.length===0)return null;let o=new Map;for(let r of n){if(typeof r.id!=="string"||r.id.length===0)continue;o.set(r.id,{...r.position?{position:r.position}:{},...r.size?{size:r.size}:{},...r.collapsed!==void 0?{collapsed:r.collapsed}:{},...r.pinned!==void 0?{pinned:r.pinned}:{}})}return o.size>0?o:null}catch(e){return Zv("restoreLayout",e),null}}function mr(e,t){let n=Array.from(F.value.values());if(n.length===0)return;let{POSITIVE_INFINITY:o,POSITIVE_INFINITY:r,NEGATIVE_INFINITY:s,NEGATIVE_INFINITY:a}=Number;for(let v of n)o=Math.min(o,v.position.x),r=Math.min(r,v.position.y),s=Math.max(s,v.position.x+v.size.width),a=Math.max(a,v.position.y+v.size.height);let c=Xl(),l=Math.max(80,e-c.left-c.right),u=Math.max(80,t-c.top-c.bottom),p=Math.max(1,s-o),d=Math.max(1,a-r),f=Math.min(1,Math.min(l/p,u/d)),m=(o+s)/2,h=(r+a)/2;Xn({x:c.left+l/2-m*f,y:c.top+u/2-h*f,scale:f})}function Ke(e,t={}){let n=F.value.get(e);if(!n)return;let o=J.value,r=ot(),s=Xl(),a=Math.max(80,r.width-s.left-s.right),c=Math.max(80,r.height-s.top-s.bottom),l=Math.min(o.scale,a/n.size.width,c/n.size.height),u=n.position.x+n.size.width/2,p=n.position.y+n.size.height/2;Xn({x:s.left+a/2-u*l,y:s.top+c/2-p*l,scale:l},300,t),Sn(e)}function uy(e=1){let t=Array.from(F.value.keys());if(t.length===0)return;let o=((Ce.value?t.indexOf(Ce.value):-1)+e+t.length)%t.length,r=t[o];Sn(r),Ke(r)}function dy(e){let t=Ce.value;if(!t)return;let n=F.value.get(t);if(!n)return;let o=Uv(t,Le.value);if(o.size===0)return;let r=n.position.x+n.size.width/2,s=n.position.y+n.size.height/2,a=null,c=-1/0;for(let l of o){let u=F.value.get(l);if(!u)continue;let p=u.position.x+u.size.width/2,d=u.position.y+u.size.height/2,f=p-r,m=d-s,h=Math.sqrt(f*f+m*m);if(h<1)continue;let v;switch(e){case"up":v=-m;break;case"down":v=m;break;case"left":v=-f;break;case"right":v=f;break}if(v<=0)continue;let x=v/h-h*0.001;if(x>c)c=x,a=l}if(a)Ke(a)}function Zt(e){if(!F.value.get(e))return;if(bt!==null)clearTimeout(bt),bt=null;en.value=null,Io=void 0,Sn(e),Ue.value=e}function hu(e){if(bt!==null)clearTimeout(bt),bt=null;if(Ue.value===e)Ue.value=null;if(en.value===e)en.value=null;Io=void 0}function Cn(){let e=Ue.value,t=e?F.value.get(e):void 0;if(e&&t&&uv(t)){let n=e,o=Date.now();if(en.value=n,Io=t.data.appCheckpoint?.updatedAt,bt!==null)clearTimeout(bt);let r=()=>{let a=F.value.get(n)?.data.appCheckpoint?.updatedAt;if(a!==void 0&&a!==Io){hu(n);return}if(Date.now()-o>=S0){hu(n);return}bt=setTimeout(r,Fv)};bt=setTimeout(r,Fv);return}if(bt!==null)clearTimeout(bt),bt=null;en.value=null,Io=void 0,Ue.value=null}function ca(){let e=eu(Array.from(F.value.values()),Array.from(Le.value.values()),"grid");if(e.nodePositions.size===0&&e.groupBounds.size===0)return;Rt(()=>{for(let[t,n]of e.nodePositions.entries())it(t,{position:n});for(let[t,n]of e.groupBounds.entries())ia(t,{position:{x:n.x,y:n.y},size:{width:n.width,height:n.height}},{skipGroupChildTranslation:!0})}),st()}function la(){let e=eu(Array.from(F.value.values()),Array.from(Le.value.values()),"graph");if(e.nodePositions.size===0&&e.groupBounds.size===0)return;Rt(()=>{for(let[t,n]of e.nodePositions.entries())it(t,{position:n});for(let[t,n]of e.groupBounds.entries())ia(t,{position:{x:n.x,y:n.y},size:{width:n.width,height:n.height}},{skipGroupChildTranslation:!0})}),st()}var nn=q(!1),Kn=q(!1);function _u(){return nn.value||Kn.value}var E0=0.1,A0=4,py=1;function my(e){return Math.min(A0,Math.max(E0,e))}function ua({viewport:e,onViewportChange:t,onViewportCommit:n,disabled:o=!1}){let r=R(null),s=R(!1),a=R({x:0,y:0}),c=R(0),l=R(null),u=H((g)=>{if(l.current!==null)window.clearTimeout(l.current);l.current=window.setTimeout(()=>{l.current=null,n(g)},140)},[n]);function p(g){if(g.deltaMode!==0)return g.deltaX===0;return g.deltaX===0&&Number.isInteger(g.deltaY)&&Math.abs(g.deltaY)>=50}let d=H((g)=>{if(o)return;g.preventDefault();let y=e.value;if(g.ctrlKey||g.metaKey||p(g)){let E=r.current?.getBoundingClientRect();if(!E)return;let L=g.clientX-E.left,P=g.clientY-E.top,b=-g.deltaY*0.002,T=my(y.scale*(1+b)),w=T/y.scale,_={x:L-w*(L-y.x),y:P-w*(P-y.y),scale:T};t(_),u(_)}else{let E={x:y.x-g.deltaX*py,y:y.y-g.deltaY*py,scale:y.scale};t(E),u(E)}},[o,e,t,u]),f=H((g)=>{if(o)return;let y=r.current;if(!y)return;if(g.button===1||g.button===2)g.preventDefault();else if(ur()){if(g.target!==y)return;g.preventDefault()}else return;s.current=!0,document.documentElement.classList.add("is-canvas-panning"),a.current={x:g.clientX,y:g.clientY},y.setPointerCapture(g.pointerId)},[o]),m=H((g)=>{if(!s.current)return;if(o)return;let y=g.clientX-a.current.x,E=g.clientY-a.current.y;a.current={x:g.clientX,y:g.clientY};let L=e.value;t({x:L.x+y,y:L.y+E,scale:L.scale})},[o,e,t]),h=H(()=>{if(s.current)n(e.value);s.current=!1,document.documentElement.classList.remove("is-canvas-panning")},[n,e]),v=H((g)=>{if(o)return;if(g.touches.length!==2){c.current=0;return}g.preventDefault();let y=g.touches[0],E=g.touches[1],L=Math.hypot(E.clientX-y.clientX,E.clientY-y.clientY),P=(y.clientX+E.clientX)/2,b=(y.clientY+E.clientY)/2;if(c.current>0){let T=e.value,w=r.current?.getBoundingClientRect();if(!w)return;let _=P-w.left,z=b-w.top,U=L/c.current,N=my(T.scale*U),Z=N/T.scale,j={x:_-Z*(_-T.x),y:z-Z*(z-T.y),scale:N};t(j),u(j)}c.current=L},[o,e,t,u]),x=H(()=>{if(l.current!==null)window.clearTimeout(l.current),l.current=null;n(e.value),c.current=0},[n,e]);return B(()=>{let g=r.current;if(!g)return;return g.addEventListener("wheel",d,{passive:!1}),g.addEventListener("pointerdown",f),g.addEventListener("pointermove",m),g.addEventListener("pointerup",h),g.addEventListener("pointercancel",h),g.addEventListener("lostpointercapture",h),g.addEventListener("touchmove",v,{passive:!1}),g.addEventListener("touchend",x),()=>{if(l.current!==null)window.clearTimeout(l.current);g.removeEventListener("wheel",d),g.removeEventListener("pointerdown",f),g.removeEventListener("pointermove",m),g.removeEventListener("pointerup",h),g.removeEventListener("pointercancel",h),g.removeEventListener("lostpointercapture",h),g.removeEventListener("touchmove",v),g.removeEventListener("touchend",x)}},[d,f,m,h,v,x]),B(()=>()=>{document.documentElement.classList.remove("is-canvas-panning")},[]),r}var z0=0;function i(e,t,n,o,r,s){t||(t={});var a,c,l=t;if("ref"in l)for(c in l={},t)c=="ref"?a=t[c]:l[c]=t[c];var u={type:e,props:l,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--z0,__i:-1,__u:0,__source:r,__self:s};if(typeof e=="function"&&(a=e.defaultProps))for(c in a)l[c]===void 0&&(l[c]=a[c]);return we.vnode&&we.vnode(u),u}function fy(){let[e,t]=I({stops:[]}),[n,o]=I(0),[r,s]=I(""),a=nn.value,c=Tt.value,l=R(0),u=(d)=>{cancelAnimationFrame(l.current),J.value=d},p=ua({viewport:J,onViewportChange:u,onViewportCommit:u});return B(()=>{let d=new URLSearchParams(location.search);return nn.value=d.get("present")==="1",Kn.value=d.get("capture")==="1",window.pmxCapture={ready:()=>Tt.value,area:ot,camera:()=>({...J.value}),frame:async(f)=>(Kn.value=!0,kn(),J.value=Vl.parse(f),await new Promise((m)=>requestAnimationFrame(()=>requestAnimationFrame(()=>m()))),{...J.value})},()=>{delete window.pmxCapture,nn.value=!1,Kn.value=!1}},[]),B(()=>{if(!a||!c)return;let d=!1;return Y("read tour","/api/canvas/tour",{tour:{stops:[]}}).then((f)=>{if(!d)t(f.tour),o(0)}),()=>{d=!0}},[a,c]),B(()=>{if(!a||Kn.value)return;let d=e.stops[n];if(!d)return;let f=ot(),m;try{m=Jg(d,[...F.value.values()],f.width,f.height),s("")}catch(y){s(y instanceof Error?y.message:String(y));return}kn();let h={...J.value},v=performance.now(),x=(d.duration??1)*1000,g=(y)=>{if(Kn.value)return;let E=x===0?1:Math.min(1,(y-v)/x);if(J.value=Yg(h,m,E,f.width,f.height,d.easing,d.pullback),E<1)l.current=requestAnimationFrame(g)};return l.current=requestAnimationFrame(g),()=>cancelAnimationFrame(l.current)},[a,n,e]),B(()=>{if(!a)return;let d=(f)=>{if(f.stopImmediatePropagation(),f.target instanceof HTMLButtonElement&&["Enter"," "].includes(f.key))return;if(["Escape","ArrowRight","ArrowDown","ArrowLeft","ArrowUp"," "].includes(f.key))f.preventDefault();if(f.key==="Escape")nn.value=!1;if(["ArrowRight","ArrowDown"," "].includes(f.key))o((m)=>Math.max(0,Math.min(e.stops.length-1,m+1)));if(["ArrowLeft","ArrowUp"].includes(f.key))o((m)=>Math.max(0,m-1))};return document.addEventListener("keydown",d,!0),()=>document.removeEventListener("keydown",d,!0)},[a,e]),a?i(de,{children:[!Kn.value&&i("div",{class:"presentation-navigation",ref:p,onPointerDown:(d)=>{if(d.button===1||d.button===2)cancelAnimationFrame(l.current)},onContextMenu:(d)=>d.preventDefault(),children:i("button",{type:"button",class:"presentation-exit",onClick:()=>nn.value=!1,children:"Exit presentation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r&&i("div",{class:"presentation-error",role:"alert",children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null}function P0(e){return new Date(e).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}function N0(){js()}function hy(){let e=li.value;if(e.length===0)return null;let t=ln.value,n=tr.value;if(!t)return i("button",{type:"button",class:"attention-history-tab",onClick:N0,"aria-label":n>0?`Recent updates — ${n} new`:"Recent updates",title:n>0?`${n} new updates since last viewed`:"Recent updates",children:[i("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"9.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"attention-history-tab-label",children:"Updates"},void 0,!1,void 0,this),n>0&&i("span",{class:"attention-history-tab-badge","aria-hidden":"true",children:n>9?"9+":n},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("aside",{class:"attention-history","aria-label":"Recent semantic changes",children:[i("div",{class:"attention-history-header",children:[i("div",{class:"attention-history-header-text",children:[i("span",{class:"attention-history-title",children:"Recent Updates"},void 0,!1,void 0,this),i("span",{class:"attention-history-subtitle",children:"Focus and meaning shifts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"attention-history-close",onClick:bv,"aria-label":"Collapse changes panel",title:"Collapse",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"attention-history-list",children:e.map((o)=>i("article",{class:`attention-history-entry attention-tone-${o.tone}`,children:[i("div",{class:"attention-history-meta",children:[i("span",{class:"attention-history-kind",children:o.title},void 0,!1,void 0,this),i("time",{class:"attention-history-time",dateTime:new Date(o.createdAt).toISOString(),children:P0(o.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("p",{class:"attention-history-detail",children:o.detail},void 0,!1,void 0,this)]},o.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function gy(){let e=Fs.value;if(!e)return null;return i("button",{type:"button",class:`attention-toast attention-tone-${e.tone}`,onClick:js,"aria-label":`${e.title}${e.detail?`: ${e.detail}`:""} — open change history`,children:[i("span",{class:"attention-toast-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"attention-toast-copy",children:[i("span",{class:"attention-toast-title",children:e.title},void 0,!1,void 0,this),e.detail&&i("span",{class:"attention-toast-detail",children:e.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var yi=q(null),vy=0;function Ot(e,t,n={}){return new Promise((o)=>{yi.value?.resolve(null),vy+=1,yi.value={seq:vy,title:e,placeholder:t,initial:n.initial??"",allowEmpty:n.allowEmpty??!1,confirm:n.confirm??"Add",resolve:o}})}function vi(e){let t=yi.value;yi.value=null,t?.resolve(e)}function yy(){let e=yi.value,t=R(null);if(B(()=>{if(!e)return;let o=(r)=>{if(r.key!=="Escape")return;r.preventDefault(),r.stopPropagation(),vi(null)};return window.addEventListener("keydown",o,{capture:!0}),()=>window.removeEventListener("keydown",o,{capture:!0})},[e]),!e)return null;let n=()=>{let o=t.current?.value.trim()??"";vi(o?o:e.allowEmpty?"":null)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>vi(null),children:i("div",{class:"text-prompt",role:"dialog","aria-label":e.title,"data-testid":"text-prompt",onPointerDown:(o)=>o.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:e.title},void 0,!1,void 0,this),i("input",{ref:(o)=>{if(t.current=o,!o)return;if(o.focus(),e.initial)o.select()},class:"text-prompt-input",type:"text",defaultValue:e.initial,placeholder:e.placeholder,onKeyDown:(o)=>{if(o.key==="Enter")o.preventDefault(),o.stopPropagation(),n();else if(o.key==="Escape")o.preventDefault(),o.stopPropagation(),vi(null)}},e.seq,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:()=>vi(null),children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"button",class:"text-prompt-confirm",onClick:n,children:e.confirm},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}async function Jn(e,t,n,o){if((await Js({type:t,sourceNodeId:e.id,sourceSurface:"native-node",...n?{payload:n}:{}})).ok)yn("context",o,"",[e.id])}var Po={padding:"3px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer",flexShrink:0};function R0(e){let t=e.title||e.label||e.key||"Context",n=e.summary?.trim()||"Available in startup context.",o=e.pathDisplay||e.path||"",r=e.category==="profile"?"Operator":e.category==="planning"||e.category==="memory"?"Product":e.category?e.category.charAt(0).toUpperCase()+e.category.slice(1):void 0,s=e.sourceKind==="global"?"Global":"Workspace",a=e.state==="missing"?"Missing":e.state==="stale"?"Stale":e.state==="invalid"?"Invalid":"Loaded";return{title:t,summary:n,pathDisplay:o,category:r,sourceKind:s,status:a,required:e.required===!0}}function on(e){return typeof e==="string"?e.trim():""}function $0(e){return e.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}function M0(e){let t=on(e.title),n=on(e.content),o=$0(on(e.rendered)),r=n||o,s=on(e.path);if(!t&&!r&&!s)return null;return{title:t||"Context",summary:r,path:s}}function O0(e){let t=on(e.data.title)||e.id,n=on(e.data.content)||on(e.data.excerpt)||on(e.data.description)||on(e.data.pageTitle)||"",o=on(e.data.path)||on(e.data.url);return{id:e.id,title:t,summary:n,kind:lt[e.type]??e.type,path:o}}function by(e){if(e===null||!Number.isFinite(e)||e<0)return"0";if(e>=1e6)return`${(e/1e6).toFixed(1)}m`;if(e>=1000)return`${(e/1000).toFixed(1)}k`;return`${Math.round(e)}`}function L0(e){if(e>=0.95)return"var(--c-danger)";if(e>=0.85)return"var(--c-warn)";if(e>=0.7)return"var(--c-warn)";return"var(--c-accent)"}function da({node:e,expanded:t=!1,pinnedNodes:n=[]}){let o=e.data.cards??[],r=e.data.auxTabs??[],s=n.map(O0),a=s.length>0,c=typeof e.data.currentTokens==="number"?e.data.currentTokens:null,l=typeof e.data.tokenLimit==="number"?e.data.tokenLimit:null,u=typeof e.data.utilization==="number"?e.data.utilization:null,p=typeof e.data.messagesLength==="number"?e.data.messagesLength:null,d=u!==null?Math.max(0,Math.min(100,Math.round(u*100))):null,f=L0(u??0),m=!a&&o.length===0&&r.length===0?M0(e.data):null,h=async(v)=>{let x=typeof v.path==="string"?v.path.trim():"";if(!x)return;await Vs(x)};return i("div",{style:{display:"flex",flexDirection:"column",gap:t?"10px":"6px",fontSize:t?"14px":"12px",maxWidth:t?"760px":void 0,margin:t?"0 auto":void 0,width:t?"100%":void 0,padding:t?"8px 0":void 0},children:[i("div",{style:{display:"flex",justifyContent:"flex-end"},children:i("button",{type:"button",class:"ax-node-action",title:"Point the agent at this node — sets it as the agent's current AX focus so the agent pulls it into context to work on next (a one-click alternative to manually pinning).",style:Po,onClick:(v)=>{v.stopPropagation(),Jn(e,"ax.focus.set",void 0,"Focus set")},children:"Set focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),l!==null&&l>0&&i("div",{style:{marginBottom:"8px"},children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:"Token Usage"},void 0,!1,void 0,this),i("div",{style:{height:"6px",background:"var(--c-surface-hover)",borderRadius:"3px",overflow:"hidden",marginBottom:"4px"},children:i("div",{style:{height:"100%",width:`${Math.min(100,(u??0)*100)}%`,background:f,borderRadius:"3px",transition:"width 0.3s ease"}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{style:{fontSize:"11px",color:"var(--c-muted)"},children:[d,"% — ",by(c)," / ",by(l)," tokens",p!==null&&i(de,{children:[" · ",p," messages"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:["Pinned Context (",s.length,")"]},void 0,!0,void 0,this),s.map((v)=>i("div",{style:{padding:"6px 8px",background:"var(--c-surface-subtle)",borderRadius:"6px",marginBottom:"4px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"2px"},children:v.title},void 0,!1,void 0,this),v.summary&&i("div",{style:{color:"var(--c-muted)",fontSize:"10px",lineHeight:1.45,marginBottom:"4px",whiteSpace:"pre-wrap"},children:v.summary},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"4px",flexWrap:"wrap",marginTop:"4px"},children:i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:v.kind},void 0,!1,void 0,this)},void 0,!1,void 0,this),v.path&&i("div",{style:{marginTop:"6px"},children:[i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all",marginBottom:"6px"},children:v.path},void 0,!1,void 0,this),v.path.startsWith("/")&&i("button",{type:"button",onClick:()=>void Vs(v.path),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},v.id,!0,void 0,this))]},void 0,!0,void 0,this),!a&&o.length>0&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px"},children:["Context (",o.length,")"]},void 0,!0,void 0,this),o.map((v)=>{let x=R0(v);return i("div",{style:{padding:"6px 8px",background:"var(--c-surface-subtle)",borderRadius:"6px",marginBottom:"4px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"2px"},children:x.title},void 0,!1,void 0,this),i("div",{style:{color:"var(--c-muted)",fontSize:"10px",lineHeight:1.45,marginBottom:"4px"},children:x.summary},void 0,!1,void 0,this),x.pathDisplay&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all"},children:x.pathDisplay},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"4px",flexWrap:"wrap",marginTop:"4px"},children:[i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-accent-10)",color:"var(--c-accent)",borderRadius:"3px",display:"inline-block"},children:x.status},void 0,!1,void 0,this),x.category&&i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:x.category},void 0,!1,void 0,this),i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-surface-hover)",color:"var(--c-text-soft)",borderRadius:"3px",display:"inline-block"},children:x.sourceKind},void 0,!1,void 0,this),x.required&&i("span",{style:{fontSize:"9px",padding:"1px 4px",background:"var(--c-warn-12)",color:"var(--c-warn-alt)",borderRadius:"3px",display:"inline-block"},children:"Required"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v.path&&i("div",{style:{marginTop:"6px"},children:i("button",{type:"button",onClick:()=>void h(v),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},v.key??x.pathDisplay??x.title,!0,void 0,this)})]},void 0,!0,void 0,this),!a&&r.length>0&&i("div",{children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"6px",marginTop:o.length>0?"8px":0},children:["References (",r.length,")"]},void 0,!0,void 0,this),r.map((v)=>i("a",{href:v.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",padding:"4px 8px",color:"var(--c-accent)",fontSize:"11px",textDecoration:"none",borderRadius:"4px",marginBottom:"2px",wordBreak:"break-all"},children:[v.url,v.reason&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",marginLeft:"6px"},children:["(",v.reason,")"]},void 0,!0,void 0,this)]},v.id,!0,void 0,this))]},void 0,!0,void 0,this),m&&i("div",{style:{padding:"8px 10px",background:"var(--c-surface-subtle)",borderRadius:"6px",borderLeft:"2px solid var(--c-accent)"},children:[i("div",{style:{fontWeight:600,color:"var(--c-text)",marginBottom:"4px"},children:m.title},void 0,!1,void 0,this),m.summary&&i("div",{style:{color:"var(--c-text-soft)",fontSize:"11px",lineHeight:1.5,whiteSpace:"pre-wrap"},children:m.summary},void 0,!1,void 0,this),m.path&&i("div",{style:{marginTop:"6px"},children:[i("div",{style:{color:"var(--c-dim)",fontSize:"10px",wordBreak:"break-all",marginBottom:"6px"},children:m.path},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>void Vs(m.path),style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-accent-12)",border:"1px solid var(--c-accent-25)",borderRadius:"4px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Open in canvas"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!a&&!m&&o.length===0&&r.length===0&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic"},children:"No context loaded"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function xy(e){return e.replace(/^[ab]\//,"")}function D0(e,t){if(t&&t!=="/dev/null")return xy(t);if(e&&e!=="/dev/null")return xy(e);return null}function F0(e){if(!e.trim())return[];let t=e.split(`
89
+ `);if(t.length>0&&t[t.length-1]==="")t.pop();let n=[],o=null,r=!1,s=(a)=>{let c={path:a,lines:[]};return r=!1,n.push(c),c};for(let a=0;a<t.length;a++){let c=t[a]??"",l=c.match(/^diff --git a\/(.+?) b\/(.+)$/);if(l){o=s(l[2]??null);continue}let u=t[a+1]??"";if(c.startsWith("--- ")&&u.startsWith("+++ ")){let d=D0(c.slice(4).trim(),u.slice(4).trim());if(o&&!r){if(!o.path)o.path=d}else o=s(d);a++;continue}if(!o)o=s(null);let p=o;if(c.startsWith("@@"))r=!0,p.lines.push({kind:"hunk",text:c});else if(c.startsWith("+"))p.lines.push({kind:"add",text:c});else if(c.startsWith("-"))p.lines.push({kind:"remove",text:c});else p.lines.push({kind:"context",text:c})}return n}function pa({node:e}){let t=typeof e.data.content==="string"?e.data.content:"",n=Ie(()=>F0(t),[t]);if(n.length===0)return i("div",{class:"diff-node diff-node-empty",children:"Empty diff"},void 0,!1,void 0,this);return i("div",{class:"diff-node",children:n.map((o,r)=>i("div",{class:"diff-file",children:[o.path&&i("div",{class:"diff-file-header",children:o.path},void 0,!1,void 0,this),i("pre",{class:"diff-lines",children:o.lines.map((s,a)=>i("div",{class:s.kind==="hunk"?"diff-hunk":`diff-line-${s.kind}`,children:s.text||" "},a,!1,void 0,this))},void 0,!1,void 0,this)]},`${o.path??"anonymous"}-${r}`,!0,void 0,this))},void 0,!1,void 0,this)}var wy="pmx-canvas-iframe-probe";var B0="/api/canvas/iframe-probe",H0=3000,wt=q(null);function j0(){let e=new URLSearchParams(window.location.search).get("iframe-mode");return e==="srcdoc"||e==="src"?e:null}function _y(e=H0){return new Promise((t)=>{let n=document.createElement("iframe");n.setAttribute("data-pmx-iframe-probe",""),n.style.cssText="position:fixed;width:1px;height:1px;left:-9999px;border:none",n.setAttribute("sandbox","allow-scripts");let o=(a)=>{window.clearTimeout(s),window.removeEventListener("message",r),n.remove(),t(a)},r=(a)=>{if(a.source!==n.contentWindow)return;if(a.data?.source!==wy)return;o(!0)},s=window.setTimeout(()=>o(!1),e);window.addEventListener("message",r),n.addEventListener("error",()=>o(!1)),n.src=B0,(document.body??document.documentElement).appendChild(n)})}var ma=null;function Z0(){try{return window.self!==window.top}catch{return!0}}function U0(){return window.__PMX_AMP_ORB===!0}function Sy(e={}){if(wt.value)return Promise.resolve(wt.value);if(ma)return ma;let t=j0();if(t)return wt.value=t,Promise.resolve(t);if(!(e.embedded??Z0()))return wt.value="src",_y(e.probeTimeoutMs).then((n)=>{if(!n&&wt.value==="src")wt.value="srcdoc"}),Promise.resolve("src");if(e.ampOrb??U0())return wt.value="srcdoc",Promise.resolve("srcdoc");return ma=_y(e.probeTimeoutMs).then((n)=>{let o=n?"src":"srcdoc";return wt.value=o,o}),ma}var Et=q([]),Pe=q(null),fr=q(!1),Cy=null,hr=0,fa=0,ky=Promise.resolve();function Ty(e){Cy=e}function No(e){if(!e||!Array.isArray(e.boards))return;hr+=1;let t=typeof e.activeBoardId==="string"?e.activeBoardId:null,n=fr.value&&(t!==Pe.value||e.reloaded===!0);if(Et.value=e.boards,Pe.value=t,fr.value=!0,n)Cy?.()}async function Su(){let e=hr,t=await Y("loadBoards","/api/canvas/boards",null);if(e===hr)No(t)}async function ha(e,t,n,o,r=hr){let s=await Y(e,t,null,{method:n,headers:{"Content-Type":"application/json"},...o===void 0?{}:{body:JSON.stringify(o)}});return r===hr?s:null}async function At(e){let t=++fa,n=hr,o=null,r=ky.then(async()=>{o=await ha("openBoard","/api/canvas/boards/open","POST",{id:e},n)});if(ky=r.catch(()=>{return}),await r,t===fa)No(o)}async function Iy(e){let t=++fa,n=await Y("createBoard","/api/canvas/boards",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})});if(n?.board&&t===fa)await At(n.board.id)}async function Ey(e){return Y("previewBoardCopy","/api/canvas/boards/from",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceBoardId:e,name:"Preview",preview:!0})})}async function Ay(e){let t=await Y("createBoardFrom","/api/canvas/boards/from",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return await Su(),t?.board??null}async function ga(e,t){let n=await ha("updateBoard",`/api/canvas/boards/${encodeURIComponent(e)}`,"PATCH",{...t,...t.category===null?{category:""}:{}});No(n)}async function zy(e,t){let n=await ha("setBoardReadme",`/api/canvas/boards/${encodeURIComponent(e)}`,"PATCH",{readmeNodeId:t});No(n)}async function Py(e){let t=await ha("deleteBoard",`/api/canvas/boards/${encodeURIComponent(e)}`,"DELETE");No(t)}function va(){return Et.value.find((e)=>e.id===Pe.value)??null}function Ny({node:e,expanded:t=!1}){let n=String(e.data.attachmentId),o=Pe.value,[r,s]=I(null),[a,c]=I(t),[l,u]=I(!1);B(()=>{let f=!0,m=async()=>{let v=await Y("readImports",`/api/canvas/imports?boardId=${encodeURIComponent(o??"")}`,null);if(f)s(v?.imports?.find((x)=>x.attachmentId===n)??null)};m();let h=window.setInterval(()=>void m(),2000);return()=>{f=!1,window.clearInterval(h)}},[n,o]),B(()=>{if(!a)return;let f=(m)=>{if(m.key==="Escape")m.stopPropagation(),c(!1)};return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[a]);let p=async(f)=>{if(!r)return;u(!0);let m=await Y(`import.${f}`,`/api/canvas/imports/${r.id}/${f}`,null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({consent:!0})});if(u(!1),m?.import){if(s(m.import),c(!1),t&&f==="commit")Cn()}},d=r&&["attached","cancelled","unavailable"].includes(r.status);return i("div",{class:"attachment-node",onPointerDown:(f)=>f.stopPropagation(),children:[i("div",{class:"attachment-status",children:r?.status==="requested"?"Waiting for agent":r?.status==="drafted"?"Ready for review":r?.status==="committed"?"Markdown added":"Original attached"},void 0,!1,void 0,this),i("a",{href:`/api/canvas/attachments/${n}/bytes`,target:"_blank",rel:"noopener noreferrer",children:["Download original · ",Math.ceil(Number(e.data.size??0)/1024)," KB"]},void 0,!0,void 0,this),r?.reason&&i("p",{children:r.reason},void 0,!1,void 0,this),d&&i(de,{children:[i("p",{id:`import-consent-${e.id}`,children:"Asking the agent to import allows it to process this file with its tools and model provider."},void 0,!1,void 0,this),i("button",{type:"button",class:"attachment-button is-primary","aria-describedby":`import-consent-${e.id}`,disabled:l,onClick:()=>void p("request"),children:"Ask agent to import"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r?.status==="requested"&&i("p",{children:"No automatic extraction. Ask your connected agent to check its pending steering or use canvas_import list."},void 0,!1,void 0,this),r?.status==="drafted"&&!a&&i("button",{type:"button",class:"attachment-button is-primary",onClick:()=>t?c(!0):Zt(e.id),children:["Review Markdown · ",r.sections.length," ",r.sections.length===1?"card":"cards"]},void 0,!0,void 0,this),r&&["requested","drafted"].includes(r.status)&&i("button",{type:"button",class:"attachment-button",disabled:l,onClick:()=>void p("cancel"),children:"Cancel import"},void 0,!1,void 0,this),a&&r?.status==="drafted"&&i("div",{class:"attachment-review",role:"dialog","aria-label":"Review imported Markdown",children:[i("h3",{children:"Review imported Markdown"},void 0,!1,void 0,this),i("p",{children:["Source material, not instructions or verified knowledge. ",r.agentDescription]},void 0,!0,void 0,this),r.warnings.length>0&&i("ul",{children:r.warnings.map((f)=>i("li",{children:f},f,!1,void 0,this))},void 0,!1,void 0,this),r.sections.map((f,m)=>i("section",{children:[i("h4",{children:f.title},void 0,!1,void 0,this),i("p",{children:f.reference||"Source location not supplied"},void 0,!1,void 0,this),i("pre",{children:f.markdown},void 0,!1,void 0,this)]},m,!0,void 0,this)),i("div",{class:"attachment-review-actions",children:[i("button",{type:"button",class:"attachment-button",onClick:()=>c(!1),children:"Close review"},void 0,!1,void 0,this),i("button",{type:"button",class:"attachment-button is-primary",disabled:l||o!==r.boardId,onClick:()=>void p("commit"),children:"Add to board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function q0(e){let t=e.split(".").pop()?.toLowerCase()??"";return{ts:"TypeScript",tsx:"TSX",js:"JavaScript",jsx:"JSX",py:"Python",rs:"Rust",go:"Go",rb:"Ruby",java:"Java",kt:"Kotlin",swift:"Swift",c:"C",cpp:"C++",h:"C/C++",css:"CSS",html:"HTML",json:"JSON",yaml:"YAML",yml:"YAML",md:"Markdown",toml:"TOML",sql:"SQL",sh:"Shell",bash:"Shell",xml:"XML",graphql:"GraphQL",proto:"Protobuf"}[t]??(t.toUpperCase()||"Text")}var ku=500;function W0(e){let t=e.toLowerCase();if(t.endsWith(".csv"))return",";if(t.endsWith(".tsv"))return"\t";return null}function V0(e,t){let n=[],o=[],r="",s=!1,a=!1;for(let l=0;l<e.length;l++){let u=e[l];if(a=!0,s){if(u==='"')if(e[l+1]==='"')r+='"',l++;else s=!1;else if(u==="\r"&&e[l+1]===`
75
90
  `)r+=`
76
91
  `,l++;else r+=u;continue}if(u==='"'&&r==="")s=!0;else if(u===t)o.push(r),r="";else if(u===`
77
92
  `||u==="\r"){if(u==="\r"&&e[l+1]===`
78
- `)l++;o.push(r),r="",n.push(o),o=[],a=!1}else r+=u}if(a)o.push(r),n.push(o);let c=n.shift()??[];return{header:c,rows:n.map((l)=>Array.from({length:c.length},(u,d)=>l[d]??""))}}function nu(e){if(!Number.isFinite(e)||e<0)return"";if(e<1024)return`${Math.round(e)} B`;let t=["KB","MB","GB","TB"],n=e/1024,o=0;while(n>=1024&&o<t.length-1)n/=1024,o++;return`${n<10?n.toFixed(1):Math.round(n)} ${t[o]}`}function Ys({node:e,expanded:t=!1}){let n=e.data.path||e.data.content||"",o=e.data.title||n.split("/").pop()||"File",r=e.data.fileContent,s=e.data.updatedAt,a=e.data.lineCount,c=e.data.byteSize,l=e.data.binary===!0,u=e.data.truncated===!0,p=e.data.mimeType==="application/pdf"||n.toLowerCase().endsWith(".pdf"),f=l||p,[m,v]=O(r??""),[y,x]=O(!r&&!!n&&!f),[h,g]=O(null),[b,E]=O(0);D(()=>{if(!n)return;if(f){x(!1);return}if(r!==void 0){v(r),x(!1);return}let H=!1;return x(!0),g(null),Gr(n).then(({content:U})=>{if(H)return;if(!U&&U!==""){g("File not found"),x(!1);return}v(U),x(!1);let te=U.split(`
79
- `).length;ie(e.id,{fileContent:U,lineCount:te}),ct(e.id,{data:{fileContent:U,lineCount:te}})}).catch(()=>{if(!H)g("Failed to load file"),x(!1)}),()=>{H=!0}},[n,r,f]),D(()=>{if(r!==void 0&&r!==m)v(r)},[r]);let j=L(()=>{if(!n)return;if(f){E((H)=>H+1);return}x(!0),g(null),ie(e.id,{fileContent:void 0}),ct(e.id,{data:{fileContent:void 0}}),Gr(n).then(({content:H})=>{v(H),x(!1);let U=H.split(`
80
- `).length,te=new Date().toISOString();ie(e.id,{fileContent:H,lineCount:U,updatedAt:te}),ct(e.id,{data:{fileContent:H,lineCount:U,updatedAt:te}})}).catch(()=>{g("Failed to reload"),x(!1)})},[n,e.id,f]),_=Vk(n),R=m.split(`
81
- `),A=`${String(R.length).length+1}ch`,C=Gk(n),Z=Ie(()=>{if(!C||f||!m)return null;let H=Xk(m,C);return H.header.length>=2?H:null},[m,C,f]),F=`/api/canvas/file-bytes?nodeId=${encodeURIComponent(e.id)}${b?`&v=${b}`:""}`,T=vt.value==="srcdoc",B=f||Z!==null,W=u?i("div",{class:"file-node-notice",children:["Showing the first ",nu(m.length)," of ",nu(c??m.length)]},void 0,!0,void 0,this):null;if(!n)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No file path set"},void 0,!1,void 0,this);return i("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:"var(--mono)",fontSize:t?"13px":"11px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",borderBottom:"1px solid var(--c-line)",flexShrink:0},children:[i("span",{style:{fontSize:"9px",padding:"1px 5px",background:"var(--c-accent-12)",color:"var(--c-accent)",borderRadius:"3px",fontWeight:600},children:_},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-text-soft)",fontSize:t?"12px":"10px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:n,children:n},void 0,!1,void 0,this),a!==void 0&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",flexShrink:0},children:[a," lines"]},void 0,!0,void 0,this),s&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",flexShrink:0},children:new Date(s).toLocaleTimeString()},void 0,!1,void 0,this),i("button",{type:"button",class:"ax-node-action",title:"Mark this file as AX evidence",onClick:(H)=>{H.stopPropagation(),jn(e,"ax.evidence.add",{kind:"file",title:n.split("/").pop()||n,ref:n},"Marked as evidence")},style:{background:"none",border:"none",color:"var(--c-muted)",cursor:"pointer",padding:"2px 4px",fontSize:"12px",flexShrink:0},children:"⊕"},void 0,!1,void 0,this),i("button",{type:"button",onClick:j,title:"Reload file",style:{background:"none",border:"none",color:"var(--c-muted)",cursor:"pointer",padding:"2px 4px",fontSize:"12px",flexShrink:0},children:"↻"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{flex:1,minHeight:0,overflow:B?"hidden":"auto",padding:B?0:"8px 0",background:t?"var(--c-panel-soft)":void 0,borderRadius:t?"0 0 8px 8px":void 0},children:[p&&(T?i("div",{class:"file-node-placeholder",children:[i("div",{children:"PDF preview is unavailable in this embedded host."},void 0,!1,void 0,this),i("a",{class:"file-node-link",href:F,target:"_blank",rel:"noreferrer",children:"Open PDF"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i("iframe",{src:F,title:o,sandbox:"",style:{width:"100%",height:"100%",border:"none",display:"block"}},void 0,!1,void 0,this)),!p&&l&&i("div",{class:"file-node-placeholder",children:[i("div",{class:"file-node-placeholder-name",children:o},void 0,!1,void 0,this),i("div",{children:"Binary file"},void 0,!1,void 0,this),c!==void 0&&i("div",{children:nu(c)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!f&&i(ve,{children:[y&&i("div",{style:{color:"var(--c-dim)",padding:"12px",fontStyle:"italic"},children:"Loading…"},void 0,!1,void 0,this),h&&i("div",{style:{color:"var(--c-danger)",padding:"12px"},children:h},void 0,!1,void 0,this),!y&&!h&&(Z?i("div",{class:"file-table-shell",children:[W,Z.rows.length>tu&&i("div",{class:"file-node-notice",children:["Showing ",tu," of ",Z.rows.length," rows"]},void 0,!0,void 0,this),i("div",{class:"file-table-wrap",children:i("table",{class:"file-table",children:[i("thead",{children:i("tr",{children:Z.header.map((H,U)=>i("th",{children:H},U,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("tbody",{children:Z.rows.slice(0,tu).map((H,U)=>i("tr",{children:H.map((te,xe)=>i("td",{children:te},xe,!1,void 0,this))},U,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i(ve,{children:[W,i("pre",{style:{margin:0,lineHeight:"1.55",tabSize:2},children:R.map((H,U)=>i("div",{style:{display:"flex",minHeight:"1.55em"},children:[i("span",{style:{width:A,minWidth:A,textAlign:"right",color:"var(--c-dim)",paddingRight:"12px",paddingLeft:"10px",userSelect:"none",flexShrink:0,opacity:0.6},children:U+1},void 0,!1,void 0,this),i("code",{style:{color:"var(--c-text)",whiteSpace:"pre",paddingRight:"10px"},children:H||`
82
- `},void 0,!1,void 0,this)]},U,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Kk=new Set(["title","__type","content","strictSize","arrangeLocked"]);function Qs({node:e}){let t=e.data,o=(typeof t.content==="string"?t.content:"").split(/\r\n|\r|\n|\\n/).map((s)=>s.trimEnd()).filter((s)=>s.length>0),r=Object.entries(t).filter(([s])=>!Kk.has(s));if(o.length===0&&r.length===0)return i("div",{style:{color:"var(--c-dim)",fontSize:"12px",fontStyle:"italic"},children:"No ledger data"},void 0,!1,void 0,this);return i("div",{style:{display:"flex",flexDirection:"column",gap:"4px",fontSize:"12px"},children:[o.length>0&&i("div",{style:{display:"flex",flexDirection:"column"},children:o.map((s,a)=>i("div",{style:{padding:"3px 0",borderBottom:a<o.length-1?"1px solid rgba(45,55,90,0.3)":"none",color:"var(--c-text)",fontFamily:"var(--mono)",fontSize:"11px",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:s},a,!1,void 0,this))},void 0,!1,void 0,this),r.map(([s,a])=>i("div",{style:{display:"flex",justifyContent:"space-between",gap:"8px",padding:"3px 0",borderBottom:"1px solid rgba(45,55,90,0.3)"},children:[i("span",{style:{color:"var(--c-muted)",fontSize:"11px",flexShrink:0},children:s.replace(/([A-Z])/g," $1").replace(/^./,(c)=>c.toUpperCase())},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-text)",fontFamily:"var(--mono)",fontSize:"11px",textAlign:"right",wordBreak:"break-word"},children:typeof a==="object"?JSON.stringify(a):String(a??"—")},void 0,!1,void 0,this)]},s,!0,void 0,this))]},void 0,!0,void 0,this)}var ri=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),Wv=ri?"⌘":"Ctrl";function He(e){return ri?`${Wv}${e}`:`${Wv}+${e}`}function ea(e,t){let{selectionStart:n,selectionEnd:o,value:r}=e,s=r.slice(n,o),a=r.slice(Math.max(0,n-t.length),n),c=r.slice(o,o+t.length);if(a===t&&c===t){let l=r.slice(0,n-t.length)+s+r.slice(o+t.length);rn(e,l,n-t.length,o-t.length);return}if(s){let l=r.slice(0,n)+t+s+t+r.slice(o);rn(e,l,n+t.length,o+t.length)}else{let l=r.slice(0,n)+t+t+r.slice(o);rn(e,l,n+t.length,n+t.length)}}function ii(e,t){let{selectionStart:n,selectionEnd:o,value:r}=e,s=r.lastIndexOf(`
93
+ `)l++;o.push(r),r="",n.push(o),o=[],a=!1}else r+=u}if(a)o.push(r),n.push(o);let c=n.shift()??[];return{header:c,rows:n.map((l)=>Array.from({length:c.length},(u,p)=>l[p]??""))}}function Cu(e){if(!Number.isFinite(e)||e<0)return"";if(e<1024)return`${Math.round(e)} B`;let t=["KB","MB","GB","TB"],n=e/1024,o=0;while(n>=1024&&o<t.length-1)n/=1024,o++;return`${n<10?n.toFixed(1):Math.round(n)} ${t[o]}`}function ya({node:e,expanded:t=!1}){if(typeof e.data.attachmentId==="string")return i(Ny,{node:e,expanded:t},void 0,!1,void 0,this);return i(G0,{node:e,expanded:t},void 0,!1,void 0,this)}function G0({node:e,expanded:t=!1}){let n=e.data.path||e.data.content||"",o=e.data.title||n.split("/").pop()||"File",r=e.data.fileContent,s=e.data.updatedAt,a=e.data.lineCount,c=e.data.byteSize,l=e.data.binary===!0,u=e.data.truncated===!0,d=e.data.mimeType==="application/pdf"||n.toLowerCase().endsWith(".pdf"),f=l||d,[m,h]=I(r??""),[v,x]=I(!r&&!!n&&!f),[g,y]=I(null),[E,L]=I(0);B(()=>{if(!n)return;if(f){x(!1);return}if(r!==void 0){h(r),x(!1);return}let S=!1;return x(!0),y(null),di(n).then(({content:V})=>{if(S)return;if(!V&&V!==""){y("File not found"),x(!1);return}h(V),x(!1);let he=V.split(`
94
+ `).length;ie(e.id,{fileContent:V,lineCount:he}),dt(e.id,{data:{fileContent:V,lineCount:he}})}).catch(()=>{if(!S)y("Failed to load file"),x(!1)}),()=>{S=!0}},[n,r,f]),B(()=>{if(r!==void 0&&r!==m)h(r)},[r]);let P=H(()=>{if(!n)return;if(f){L((S)=>S+1);return}x(!0),y(null),ie(e.id,{fileContent:void 0}),dt(e.id,{data:{fileContent:void 0}}),di(n).then(({content:S})=>{h(S),x(!1);let V=S.split(`
95
+ `).length,he=new Date().toISOString();ie(e.id,{fileContent:S,lineCount:V,updatedAt:he}),dt(e.id,{data:{fileContent:S,lineCount:V,updatedAt:he}})}).catch(()=>{y("Failed to reload"),x(!1)})},[n,e.id,f]),b=q0(n),T=m.split(`
96
+ `),w=`${String(T.length).length+1}ch`,_=W0(n),z=Ie(()=>{if(!_||f||!m)return null;let S=V0(m,_);return S.header.length>=2?S:null},[m,_,f]),U=`/api/canvas/file-bytes?nodeId=${encodeURIComponent(e.id)}${E?`&v=${E}`:""}`,N=wt.value==="srcdoc",Z=f||z!==null,j=u?i("div",{class:"file-node-notice",children:["Showing the first ",Cu(m.length)," of ",Cu(c??m.length)]},void 0,!0,void 0,this):null;if(!n)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No file path set"},void 0,!1,void 0,this);return i("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:"var(--mono)",fontSize:t?"13px":"11px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",borderBottom:"1px solid var(--c-line)",flexShrink:0},children:[i("span",{style:{fontSize:"9px",padding:"1px 5px",background:"var(--c-accent-12)",color:"var(--c-accent)",borderRadius:"3px",fontWeight:600},children:b},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-text-soft)",fontSize:t?"12px":"10px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:n,children:n},void 0,!1,void 0,this),a!==void 0&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",flexShrink:0},children:[a," lines"]},void 0,!0,void 0,this),s&&i("span",{style:{color:"var(--c-dim)",fontSize:"10px",flexShrink:0},children:new Date(s).toLocaleTimeString()},void 0,!1,void 0,this),i("button",{type:"button",class:"ax-node-action",title:"Mark this file as AX evidence",onClick:(S)=>{S.stopPropagation(),Jn(e,"ax.evidence.add",{kind:"file",title:n.split("/").pop()||n,ref:n},"Marked as evidence")},style:{background:"none",border:"none",color:"var(--c-muted)",cursor:"pointer",padding:"2px 4px",fontSize:"12px",flexShrink:0},children:"⊕"},void 0,!1,void 0,this),i("button",{type:"button",onClick:P,title:"Reload file",style:{background:"none",border:"none",color:"var(--c-muted)",cursor:"pointer",padding:"2px 4px",fontSize:"12px",flexShrink:0},children:"↻"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{flex:1,minHeight:0,overflow:Z?"hidden":"auto",padding:Z?0:"8px 0",background:t?"var(--c-panel-soft)":void 0,borderRadius:t?"0 0 8px 8px":void 0},children:[d&&(N?i("div",{class:"file-node-placeholder",children:[i("div",{children:"PDF preview is unavailable in this embedded host."},void 0,!1,void 0,this),i("a",{class:"file-node-link",href:U,target:"_blank",rel:"noreferrer",children:"Open PDF"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i("iframe",{src:U,title:o,sandbox:"",style:{width:"100%",height:"100%",border:"none",display:"block"}},void 0,!1,void 0,this)),!d&&l&&i("div",{class:"file-node-placeholder",children:[i("div",{class:"file-node-placeholder-name",children:o},void 0,!1,void 0,this),i("div",{children:"Binary file"},void 0,!1,void 0,this),c!==void 0&&i("div",{children:Cu(c)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!f&&i(de,{children:[v&&i("div",{style:{color:"var(--c-dim)",padding:"12px",fontStyle:"italic"},children:"Loading…"},void 0,!1,void 0,this),g&&i("div",{style:{color:"var(--c-danger)",padding:"12px"},children:g},void 0,!1,void 0,this),!v&&!g&&(z?i("div",{class:"file-table-shell",children:[j,z.rows.length>ku&&i("div",{class:"file-node-notice",children:["Showing ",ku," of ",z.rows.length," rows"]},void 0,!0,void 0,this),i("div",{class:"file-table-wrap",children:i("table",{class:"file-table",children:[i("thead",{children:i("tr",{children:z.header.map((S,V)=>i("th",{children:S},V,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("tbody",{children:z.rows.slice(0,ku).map((S,V)=>i("tr",{children:S.map((he,je)=>i("td",{children:he},je,!1,void 0,this))},V,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i(de,{children:[j,i("pre",{style:{margin:0,lineHeight:"1.55",tabSize:2},children:T.map((S,V)=>i("div",{style:{display:"flex",minHeight:"1.55em"},children:[i("span",{style:{width:w,minWidth:w,textAlign:"right",color:"var(--c-dim)",paddingRight:"12px",paddingLeft:"10px",userSelect:"none",flexShrink:0,opacity:0.6},children:V+1},void 0,!1,void 0,this),i("code",{style:{color:"var(--c-text)",whiteSpace:"pre",paddingRight:"10px"},children:S||`
97
+ `},void 0,!1,void 0,this)]},V,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var X0=new Set(["title","__type","content","strictSize","arrangeLocked"]);function ba({node:e}){let t=e.data,o=(typeof t.content==="string"?t.content:"").split(/\r\n|\r|\n|\\n/).map((s)=>s.trimEnd()).filter((s)=>s.length>0),r=Object.entries(t).filter(([s])=>!X0.has(s));if(o.length===0&&r.length===0)return i("div",{style:{color:"var(--c-dim)",fontSize:"12px",fontStyle:"italic"},children:"No ledger data"},void 0,!1,void 0,this);return i("div",{style:{display:"flex",flexDirection:"column",gap:"4px",fontSize:"12px"},children:[o.length>0&&i("div",{style:{display:"flex",flexDirection:"column"},children:o.map((s,a)=>i("div",{style:{padding:"3px 0",borderBottom:a<o.length-1?"1px solid rgba(45,55,90,0.3)":"none",color:"var(--c-text)",fontFamily:"var(--mono)",fontSize:"11px",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:s},a,!1,void 0,this))},void 0,!1,void 0,this),r.map(([s,a])=>i("div",{style:{display:"flex",justifyContent:"space-between",gap:"8px",padding:"3px 0",borderBottom:"1px solid rgba(45,55,90,0.3)"},children:[i("span",{style:{color:"var(--c-muted)",fontSize:"11px",flexShrink:0},children:s.replace(/([A-Z])/g," $1").replace(/^./,(c)=>c.toUpperCase())},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-text)",fontFamily:"var(--mono)",fontSize:"11px",textAlign:"right",wordBreak:"break-word"},children:typeof a==="object"?JSON.stringify(a):String(a??"—")},void 0,!1,void 0,this)]},s,!0,void 0,this))]},void 0,!0,void 0,this)}var bi=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),Ry=bi?"⌘":"Ctrl";function qe(e){return bi?`${Ry}${e}`:`${Ry}+${e}`}function xa(e,t){let{selectionStart:n,selectionEnd:o,value:r}=e,s=r.slice(n,o),a=r.slice(Math.max(0,n-t.length),n),c=r.slice(o,o+t.length);if(a===t&&c===t){let l=r.slice(0,n-t.length)+s+r.slice(o+t.length);pn(e,l,n-t.length,o-t.length);return}if(s){let l=r.slice(0,n)+t+s+t+r.slice(o);pn(e,l,n+t.length,o+t.length)}else{let l=r.slice(0,n)+t+t+r.slice(o);pn(e,l,n+t.length,n+t.length)}}function xi(e,t){let{selectionStart:n,selectionEnd:o,value:r}=e,s=r.lastIndexOf(`
83
98
  `,n-1)+1,a=r.indexOf(`
84
- `,o),c=a===-1?r.length:a,l=r.slice(s,c);if(l.startsWith(t)){let d=r.slice(0,s)+l.slice(t.length)+r.slice(c);rn(e,d,Math.max(s,n-t.length),Math.max(s,o-t.length));return}let u=r.slice(0,s)+t+r.slice(s);rn(e,u,n+t.length,o+t.length)}function Jk(e){let{selectionStart:t,selectionEnd:n,value:o}=e,r=o.slice(t,n);if(r){let s=o.slice(0,t)+`[${r}](url)`+o.slice(n),a=t+r.length+3;rn(e,s,a,a+3)}else{let s=o.slice(0,t)+"[text](url)"+o.slice(n);rn(e,s,t+1,t+5)}}function Yk(e){let{selectionStart:t,selectionEnd:n,value:o}=e,r=o.slice(t,n),s="```";if(r){let a=o.slice(0,t)+`\`\`\`
99
+ `,o),c=a===-1?r.length:a,l=r.slice(s,c);if(l.startsWith(t)){let p=r.slice(0,s)+l.slice(t.length)+r.slice(c);pn(e,p,Math.max(s,n-t.length),Math.max(s,o-t.length));return}let u=r.slice(0,s)+t+r.slice(s);pn(e,u,n+t.length,o+t.length)}function K0(e){let{selectionStart:t,selectionEnd:n,value:o}=e,r=o.slice(t,n);if(r){let s=o.slice(0,t)+`[${r}](url)`+o.slice(n),a=t+r.length+3;pn(e,s,a,a+3)}else{let s=o.slice(0,t)+"[text](url)"+o.slice(n);pn(e,s,t+1,t+5)}}function J0(e){let{selectionStart:t,selectionEnd:n,value:o}=e,r=o.slice(t,n),s="```";if(r){let a=o.slice(0,t)+`\`\`\`
85
100
  ${r}
86
- \`\`\``+o.slice(n);rn(e,a,t+3+1,t+3+1+r.length)}else{let a=o.slice(0,t)+"```\n\n```"+o.slice(n);rn(e,a,t+3+1,t+3+1)}}function qv(e,t){let{selectionStart:n,selectionEnd:o,value:r}=e,s=r.lastIndexOf(`
101
+ \`\`\``+o.slice(n);pn(e,a,t+3+1,t+3+1+r.length)}else{let a=o.slice(0,t)+"```\n\n```"+o.slice(n);pn(e,a,t+3+1,t+3+1)}}function $y(e,t){let{selectionStart:n,selectionEnd:o,value:r}=e,s=r.lastIndexOf(`
87
102
  `,n-1)+1,a=r.indexOf(`
88
103
  `,o),c=a===-1?r.length:a,l=r.slice(s,c).split(`
89
- `),u=n,d=o,p=l.map((m,v)=>{if(t){if(m.startsWith(" ")){if(v===0)u=Math.max(s,u-2);return d-=2,m.slice(2)}else if(m.startsWith("\t")){if(v===0)u=Math.max(s,u-1);return d-=1,m.slice(1)}return m}else{if(v===0)u+=2;return d+=2," "+m}}),f=r.slice(0,s)+p.join(`
90
- `)+r.slice(c);rn(e,f,u,d)}function rn(e,t,n,o){let r=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set;if(r)r.call(e,t);else e.value=t;e.selectionStart=n,e.selectionEnd=o,e.dispatchEvent(new Event("input",{bubbles:!0}))}var ta=[{key:"bold",label:"Bold",icon:"B",shortcut:"b",action:(e)=>ea(e,"**")},{key:"italic",label:"Italic",icon:"I",shortcut:"i",action:(e)=>ea(e,"_")},{key:"strike",label:"Strikethrough",icon:"S",shortcut:"u",action:(e)=>ea(e,"~~")},{key:"code",label:"Inline code",icon:"`",shortcut:"e",action:(e)=>ea(e,"`")},{key:"link",label:"Link",icon:"\uD83D\uDD17",shortcut:"k",action:Jk},{key:"h1",label:"Heading 1",icon:"H1",action:(e)=>ii(e,"# ")},{key:"h2",label:"Heading 2",icon:"H2",action:(e)=>ii(e,"## ")},{key:"quote",label:"Blockquote",icon:"❝",action:(e)=>ii(e,"> ")},{key:"ul",label:"Bullet list",icon:"•",action:(e)=>ii(e,"- ")},{key:"ol",label:"Numbered list",icon:"1.",action:(e)=>ii(e,"1. ")},{key:"codeblock",label:"Code block",icon:"{ }",action:Yk}];function Vv(e,t){if(!(e.metaKey||e.ctrlKey))return!1;let n=ta.find((o)=>o.shortcut===e.key);if(!n)return!1;return e.preventDefault(),n.action(t),!0}function Gv(e){if(e.selectionStart===e.selectionEnd)return null;let t=document.createElement("div"),n=getComputedStyle(e),o=["fontFamily","fontSize","fontWeight","lineHeight","letterSpacing","wordSpacing","textIndent","whiteSpace","wordWrap","overflowWrap","paddingTop","paddingRight","paddingBottom","paddingLeft","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","boxSizing","width"];for(let d of o)t.style[d]=n[d];t.style.position="absolute",t.style.visibility="hidden",t.style.overflow="hidden",t.style.height="auto",t.style.top="0",t.style.left="0";let r=e.value,s=document.createTextNode(r.slice(0,e.selectionStart)),a=document.createElement("span");a.textContent=r.slice(e.selectionStart,e.selectionEnd)||".",t.appendChild(s),t.appendChild(a),t.appendChild(document.createTextNode(r.slice(e.selectionEnd))),document.body.appendChild(t);let c=a.getBoundingClientRect(),l=t.getBoundingClientRect(),u=e.getBoundingClientRect();return document.body.removeChild(t),{top:u.top+(c.top-l.top)-e.scrollTop,left:u.left+(c.left-l.left)-e.scrollLeft,width:c.width}}var Qk=ta.filter((e)=>e.shortcut),e0=ta.filter((e)=>!e.shortcut);function ou({textareaRef:e}){let[t,n]=O(!1),[o,r]=O({top:0,left:0}),s=M(null),a=M(null),c=L(()=>{let u=e.current;if(!u||u.selectionStart===u.selectionEnd){n(!1);return}let d=Gv(u);if(!d){n(!1);return}let p=380,f=Math.max(8,Math.min(d.left+d.width/2-p/2,window.innerWidth-p-8));r({top:d.top-40,left:f}),n(!0)},[e]);D(()=>{let u=e.current;if(!u)return;let d=()=>{if(a.current)clearTimeout(a.current);a.current=setTimeout(c,50)},p=()=>{a.current=setTimeout(()=>n(!1),200)},f=(m)=>{if(m.shiftKey||m.key.startsWith("Arrow"))d()};return u.addEventListener("select",d),u.addEventListener("mouseup",d),u.addEventListener("keyup",f),u.addEventListener("blur",p),()=>{if(u.removeEventListener("select",d),u.removeEventListener("mouseup",d),u.removeEventListener("keyup",f),u.removeEventListener("blur",p),a.current)clearTimeout(a.current)}},[e,c]);let l=L((u)=>{let d=e.current;if(d)u.action(d),d.focus()},[e]);if(!t)return null;return i("div",{ref:s,class:"md-format-bar",style:{top:`${o.top}px`,left:`${o.left}px`},onMouseDown:(u)=>u.preventDefault(),children:[Qk.map((u)=>i("button",{type:"button",class:`md-format-btn md-format-btn-${u.key}`,title:`${u.label} (${He(u.shortcut.toUpperCase())})`,onClick:()=>l(u),children:u.icon},u.key,!1,void 0,this)),i("div",{class:"md-format-divider"},void 0,!1,void 0,this),e0.map((u)=>i("button",{type:"button",class:`md-format-btn md-format-btn-${u.key}`,title:u.label,onClick:()=>l(u),children:u.icon},u.key,!1,void 0,this))]},void 0,!0,void 0,this)}var Ty=t_(uy(),1);function g0(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)if(Object.prototype.hasOwnProperty.call(n,o))e[o]=n[o]}return e}function uu(e,t){return Array(t+1).join(e)}function my(e){return e.replace(/^\n*/,"")}function fy(e){var t=e.length;while(t>0&&e[t-1]===`
91
- `)t--;return e.substring(0,t)}function hy(e){return fy(my(e))}var v0=["ADDRESS","ARTICLE","ASIDE","AUDIO","BLOCKQUOTE","BODY","CANVAS","CENTER","DD","DIR","DIV","DL","DT","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","FRAMESET","H1","H2","H3","H4","H5","H6","HEADER","HGROUP","HR","HTML","ISINDEX","LI","MAIN","MENU","NAV","NOFRAMES","NOSCRIPT","OL","OUTPUT","P","PRE","SECTION","TABLE","TBODY","TD","TFOOT","TH","THEAD","TR","UL"];function du(e){return pu(e,v0)}var gy=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];function vy(e){return pu(e,gy)}function y0(e){return xy(e,gy)}var yy=["A","TABLE","THEAD","TBODY","TFOOT","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"];function x0(e){return pu(e,yy)}function b0(e){return xy(e,yy)}function pu(e,t){return t.indexOf(e.nodeName)>=0}function xy(e,t){return e.getElementsByTagName&&t.some(function(n){return e.getElementsByTagName(n).length})}var w0=[[/\\/g,"\\\\"],[/\*/g,"\\*"],[/^-/g,"\\-"],[/^\+ /g,"\\+ "],[/^(=+)/g,"\\$1"],[/^(#{1,6}) /g,"\\$1 "],[/`/g,"\\`"],[/^~~~/g,"\\~~~"],[/\[/g,"\\["],[/\]/g,"\\]"],[/^>/g,"\\>"],[/_/g,"\\_"],[/^(\d+)\. /g,"$1\\. "]];function by(e){return w0.reduce(function(t,n){return t.replace(n[0],n[1])},e)}var yt={};yt.paragraph={filter:"p",replacement:function(e){return`
104
+ `),u=n,p=o,d=l.map((m,h)=>{if(t){if(m.startsWith(" ")){if(h===0)u=Math.max(s,u-2);return p-=2,m.slice(2)}else if(m.startsWith("\t")){if(h===0)u=Math.max(s,u-1);return p-=1,m.slice(1)}return m}else{if(h===0)u+=2;return p+=2," "+m}}),f=r.slice(0,s)+d.join(`
105
+ `)+r.slice(c);pn(e,f,u,p)}function pn(e,t,n,o){let r=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set;if(r)r.call(e,t);else e.value=t;e.selectionStart=n,e.selectionEnd=o,e.dispatchEvent(new Event("input",{bubbles:!0}))}var wa=[{key:"bold",label:"Bold",icon:"B",shortcut:"b",action:(e)=>xa(e,"**")},{key:"italic",label:"Italic",icon:"I",shortcut:"i",action:(e)=>xa(e,"_")},{key:"strike",label:"Strikethrough",icon:"S",shortcut:"u",action:(e)=>xa(e,"~~")},{key:"code",label:"Inline code",icon:"`",shortcut:"e",action:(e)=>xa(e,"`")},{key:"link",label:"Link",icon:"\uD83D\uDD17",shortcut:"k",action:K0},{key:"h1",label:"Heading 1",icon:"H1",action:(e)=>xi(e,"# ")},{key:"h2",label:"Heading 2",icon:"H2",action:(e)=>xi(e,"## ")},{key:"quote",label:"Blockquote",icon:"❝",action:(e)=>xi(e,"> ")},{key:"ul",label:"Bullet list",icon:"•",action:(e)=>xi(e,"- ")},{key:"ol",label:"Numbered list",icon:"1.",action:(e)=>xi(e,"1. ")},{key:"codeblock",label:"Code block",icon:"{ }",action:J0}];function My(e,t){if(!(e.metaKey||e.ctrlKey))return!1;let n=wa.find((o)=>o.shortcut===e.key);if(!n)return!1;return e.preventDefault(),n.action(t),!0}function Oy(e){if(e.selectionStart===e.selectionEnd)return null;let t=document.createElement("div"),n=getComputedStyle(e),o=["fontFamily","fontSize","fontWeight","lineHeight","letterSpacing","wordSpacing","textIndent","whiteSpace","wordWrap","overflowWrap","paddingTop","paddingRight","paddingBottom","paddingLeft","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","boxSizing","width"];for(let p of o)t.style[p]=n[p];t.style.position="absolute",t.style.visibility="hidden",t.style.overflow="hidden",t.style.height="auto",t.style.top="0",t.style.left="0";let r=e.value,s=document.createTextNode(r.slice(0,e.selectionStart)),a=document.createElement("span");a.textContent=r.slice(e.selectionStart,e.selectionEnd)||".",t.appendChild(s),t.appendChild(a),t.appendChild(document.createTextNode(r.slice(e.selectionEnd))),document.body.appendChild(t);let c=a.getBoundingClientRect(),l=t.getBoundingClientRect(),u=e.getBoundingClientRect();return document.body.removeChild(t),{top:u.top+(c.top-l.top)-e.scrollTop,left:u.left+(c.left-l.left)-e.scrollLeft,width:c.width}}var Y0=wa.filter((e)=>e.shortcut),Q0=wa.filter((e)=>!e.shortcut);function Tu({textareaRef:e}){let[t,n]=I(!1),[o,r]=I({top:0,left:0}),s=R(null),a=R(null),c=H(()=>{let u=e.current;if(!u||u.selectionStart===u.selectionEnd){n(!1);return}let p=Oy(u);if(!p){n(!1);return}let d=380,f=Math.max(8,Math.min(p.left+p.width/2-d/2,window.innerWidth-d-8));r({top:p.top-40,left:f}),n(!0)},[e]);B(()=>{let u=e.current;if(!u)return;let p=()=>{if(a.current)clearTimeout(a.current);a.current=setTimeout(c,50)},d=()=>{a.current=setTimeout(()=>n(!1),200)},f=(m)=>{if(m.shiftKey||m.key.startsWith("Arrow"))p()};return u.addEventListener("select",p),u.addEventListener("mouseup",p),u.addEventListener("keyup",f),u.addEventListener("blur",d),()=>{if(u.removeEventListener("select",p),u.removeEventListener("mouseup",p),u.removeEventListener("keyup",f),u.removeEventListener("blur",d),a.current)clearTimeout(a.current)}},[e,c]);let l=H((u)=>{let p=e.current;if(p)u.action(p),p.focus()},[e]);if(!t)return null;return i("div",{ref:s,class:"md-format-bar",style:{top:`${o.top}px`,left:`${o.left}px`},onMouseDown:(u)=>u.preventDefault(),children:[Y0.map((u)=>i("button",{type:"button",class:`md-format-btn md-format-btn-${u.key}`,title:`${u.label} (${qe(u.shortcut.toUpperCase())})`,onClick:()=>l(u),children:u.icon},u.key,!1,void 0,this)),i("div",{class:"md-format-divider"},void 0,!1,void 0,this),Q0.map((u)=>i("button",{type:"button",class:`md-format-btn md-format-btn-${u.key}`,title:u.label,onClick:()=>l(u),children:u.icon},u.key,!1,void 0,this))]},void 0,!0,void 0,this)}var fb=X_(Yy(),1);function hC(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)if(Object.prototype.hasOwnProperty.call(n,o))e[o]=n[o]}return e}function Ru(e,t){return Array(t+1).join(e)}function tb(e){return e.replace(/^\n*/,"")}function nb(e){var t=e.length;while(t>0&&e[t-1]===`
106
+ `)t--;return e.substring(0,t)}function ob(e){return nb(tb(e))}var gC=["ADDRESS","ARTICLE","ASIDE","AUDIO","BLOCKQUOTE","BODY","CANVAS","CENTER","DD","DIR","DIV","DL","DT","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","FRAMESET","H1","H2","H3","H4","H5","H6","HEADER","HGROUP","HR","HTML","ISINDEX","LI","MAIN","MENU","NAV","NOFRAMES","NOSCRIPT","OL","OUTPUT","P","PRE","SECTION","TABLE","TBODY","TD","TFOOT","TH","THEAD","TR","UL"];function $u(e){return Mu(e,gC)}var rb=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];function ib(e){return Mu(e,rb)}function vC(e){return ab(e,rb)}var sb=["A","TABLE","THEAD","TBODY","TFOOT","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"];function yC(e){return Mu(e,sb)}function bC(e){return ab(e,sb)}function Mu(e,t){return t.indexOf(e.nodeName)>=0}function ab(e,t){return e.getElementsByTagName&&t.some(function(n){return e.getElementsByTagName(n).length})}var xC=[[/\\/g,"\\\\"],[/\*/g,"\\*"],[/^-/g,"\\-"],[/^\+ /g,"\\+ "],[/^(=+)/g,"\\$1"],[/^(#{1,6}) /g,"\\$1 "],[/`/g,"\\`"],[/^~~~/g,"\\~~~"],[/\[/g,"\\["],[/\]/g,"\\]"],[/^>/g,"\\>"],[/_/g,"\\_"],[/^(\d+)\. /g,"$1\\. "]];function cb(e){return xC.reduce(function(t,n){return t.replace(n[0],n[1])},e)}var _t={};_t.paragraph={filter:"p",replacement:function(e){return`
92
107
 
93
108
  `+e+`
94
109
 
95
- `}};yt.lineBreak={filter:"br",replacement:function(e,t,n){return n.br+`
96
- `}};yt.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,t,n){var o=Number(t.nodeName.charAt(1));if(n.headingStyle==="setext"&&o<3){var r=uu(o===1?"=":"-",e.length);return`
110
+ `}};_t.lineBreak={filter:"br",replacement:function(e,t,n){return n.br+`
111
+ `}};_t.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,t,n){var o=Number(t.nodeName.charAt(1));if(n.headingStyle==="setext"&&o<3){var r=Ru(o===1?"=":"-",e.length);return`
97
112
 
98
113
  `+e+`
99
114
  `+r+`
100
115
 
101
116
  `}else return`
102
117
 
103
- `+uu("#",o)+" "+e+`
118
+ `+Ru("#",o)+" "+e+`
104
119
 
105
- `}};yt.blockquote={filter:"blockquote",replacement:function(e){return e=hy(e).replace(/^/gm,"> "),`
120
+ `}};_t.blockquote={filter:"blockquote",replacement:function(e){return e=ob(e).replace(/^/gm,"> "),`
106
121
 
107
122
  `+e+`
108
123
 
109
- `}};yt.list={filter:["ul","ol"],replacement:function(e,t){var n=t.parentNode;if(n.nodeName==="LI"&&n.lastElementChild===t)return`
124
+ `}};_t.list={filter:["ul","ol"],replacement:function(e,t){var n=t.parentNode;if(n.nodeName==="LI"&&n.lastElementChild===t)return`
110
125
  `+e;else return`
111
126
 
112
127
  `+e+`
113
128
 
114
- `}};yt.listItem={filter:"li",replacement:function(e,t,n){var o=n.bulletListMarker+" ",r=t.parentNode;if(r.nodeName==="OL"){var s=r.getAttribute("start"),a=Array.prototype.indexOf.call(r.children,t);o=(s?Number(s)+a:a+1)+". "}var c=/\n$/.test(e);return e=hy(e)+(c?`
129
+ `}};_t.listItem={filter:"li",replacement:function(e,t,n){var o=n.bulletListMarker+" ",r=t.parentNode;if(r.nodeName==="OL"){var s=r.getAttribute("start"),a=Array.prototype.indexOf.call(r.children,t);o=(s?Number(s)+a:a+1)+". "}var c=/\n$/.test(e);return e=ob(e)+(c?`
115
130
  `:""),e=e.replace(/\n/gm,`
116
131
  `+" ".repeat(o.length)),o+e+(t.nextSibling?`
117
- `:"")}};yt.indentedCodeBlock={filter:function(e,t){return t.codeBlockStyle==="indented"&&e.nodeName==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"},replacement:function(e,t,n){return`
132
+ `:"")}};_t.indentedCodeBlock={filter:function(e,t){return t.codeBlockStyle==="indented"&&e.nodeName==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"},replacement:function(e,t,n){return`
118
133
 
119
134
  `+t.firstChild.textContent.replace(/\n/g,`
120
135
  `)+`
121
136
 
122
- `}};yt.fencedCodeBlock={filter:function(e,t){return t.codeBlockStyle==="fenced"&&e.nodeName==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"},replacement:function(e,t,n){var o=t.firstChild.getAttribute("class")||"",r=(o.match(/language-(\S+)/)||[null,""])[1],s=t.firstChild.textContent,a=n.fence.charAt(0),c=3,l=new RegExp("^"+a+"{3,}","gm"),u;while(u=l.exec(s))if(u[0].length>=c)c=u[0].length+1;var d=uu(a,c);return`
137
+ `}};_t.fencedCodeBlock={filter:function(e,t){return t.codeBlockStyle==="fenced"&&e.nodeName==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"},replacement:function(e,t,n){var o=t.firstChild.getAttribute("class")||"",r=(o.match(/language-(\S+)/)||[null,""])[1],s=t.firstChild.textContent,a=n.fence.charAt(0),c=3,l=new RegExp("^"+a+"{3,}","gm"),u;while(u=l.exec(s))if(u[0].length>=c)c=u[0].length+1;var p=Ru(a,c);return`
123
138
 
124
- `+d+r+`
139
+ `+p+r+`
125
140
  `+s.replace(/\n$/,"")+`
126
- `+d+`
141
+ `+p+`
127
142
 
128
- `}};yt.horizontalRule={filter:"hr",replacement:function(e,t,n){return`
143
+ `}};_t.horizontalRule={filter:"hr",replacement:function(e,t,n){return`
129
144
 
130
145
  `+n.hr+`
131
146
 
132
- `}};yt.inlineLink={filter:function(e,t){return t.linkStyle==="inlined"&&e.nodeName==="A"&&e.getAttribute("href")},replacement:function(e,t){var n=mu(t.getAttribute("href")),o=fu(na(t.getAttribute("title"))),r=o?' "'+o+'"':"";return"["+e+"]("+n+r+")"}};yt.referenceLink={filter:function(e,t){return t.linkStyle==="referenced"&&e.nodeName==="A"&&e.getAttribute("href")},replacement:function(e,t,n){var o=mu(t.getAttribute("href")),r=na(t.getAttribute("title"));if(r)r=' "'+fu(r)+'"';var s,a;switch(n.linkReferenceStyle){case"collapsed":s="["+e+"][]",a="["+e+"]: "+o+r;break;case"shortcut":s="["+e+"]",a="["+e+"]: "+o+r;break;default:var c=this.references.length+1;s="["+e+"]["+c+"]",a="["+c+"]: "+o+r}return this.references.push(a),s},references:[],append:function(e){var t="";if(this.references.length)t=`
147
+ `}};_t.inlineLink={filter:function(e,t){return t.linkStyle==="inlined"&&e.nodeName==="A"&&e.getAttribute("href")},replacement:function(e,t){var n=Ou(t.getAttribute("href")),o=Lu(_a(t.getAttribute("title"))),r=o?' "'+o+'"':"";return"["+e+"]("+n+r+")"}};_t.referenceLink={filter:function(e,t){return t.linkStyle==="referenced"&&e.nodeName==="A"&&e.getAttribute("href")},replacement:function(e,t,n){var o=Ou(t.getAttribute("href")),r=_a(t.getAttribute("title"));if(r)r=' "'+Lu(r)+'"';var s,a;switch(n.linkReferenceStyle){case"collapsed":s="["+e+"][]",a="["+e+"]: "+o+r;break;case"shortcut":s="["+e+"]",a="["+e+"]: "+o+r;break;default:var c=this.references.length+1;s="["+e+"]["+c+"]",a="["+c+"]: "+o+r}return this.references.push(a),s},references:[],append:function(e){var t="";if(this.references.length)t=`
133
148
 
134
149
  `+this.references.join(`
135
150
  `)+`
136
151
 
137
- `,this.references=[];return t}};yt.emphasis={filter:["em","i"],replacement:function(e,t,n){if(!e.trim())return"";return n.emDelimiter+e+n.emDelimiter}};yt.strong={filter:["strong","b"],replacement:function(e,t,n){if(!e.trim())return"";return n.strongDelimiter+e+n.strongDelimiter}};yt.code={filter:function(e){var t=e.previousSibling||e.nextSibling,n=e.parentNode.nodeName==="PRE"&&!t;return e.nodeName==="CODE"&&!n},replacement:function(e){if(!e)return"";e=e.replace(/\r?\n|\r/g," ");var t=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"",n="`",o=e.match(/`+/gm)||[];while(o.indexOf(n)!==-1)n=n+"`";return n+t+e+t+n}};yt.image={filter:"img",replacement:function(e,t){var n=by(na(t.getAttribute("alt"))),o=mu(t.getAttribute("src")||""),r=na(t.getAttribute("title")),s=r?' "'+fu(r)+'"':"";return o?"!["+n+"]("+o+s+")":""}};function na(e){return e?e.replace(/(\n+\s*)+/g,`
138
- `):""}function mu(e){var t=e.replace(/([<>()])/g,"\\$1");return t.indexOf(" ")>=0?"<"+t+">":t}function fu(e){return e.replace(/"/g,"\\\"")}function wy(e){this.options=e,this._keep=[],this._remove=[],this.blankRule={replacement:e.blankReplacement},this.keepReplacement=e.keepReplacement,this.defaultRule={replacement:e.defaultReplacement},this.array=[];for(var t in e.rules)this.array.push(e.rules[t])}wy.prototype={add:function(e,t){this.array.unshift(t)},keep:function(e){this._keep.unshift({filter:e,replacement:this.keepReplacement})},remove:function(e){this._remove.unshift({filter:e,replacement:function(){return""}})},forNode:function(e){if(e.isBlank)return this.blankRule;var t;if(t=au(this.array,e,this.options))return t;if(t=au(this._keep,e,this.options))return t;if(t=au(this._remove,e,this.options))return t;return this.defaultRule},forEach:function(e){for(var t=0;t<this.array.length;t++)e(this.array[t],t)}};function au(e,t,n){for(var o=0;o<e.length;o++){var r=e[o];if(_0(r,t,n))return r}return}function _0(e,t,n){var o=e.filter;if(typeof o==="string"){if(o===t.nodeName.toLowerCase())return!0}else if(Array.isArray(o)){if(o.indexOf(t.nodeName.toLowerCase())>-1)return!0}else if(typeof o==="function"){if(o.call(e,t,n))return!0}else throw TypeError("`filter` needs to be a string, array, or function")}function S0(e){var{element:t,isBlock:n,isVoid:o}=e,r=e.isPre||function(p){return p.nodeName==="PRE"};if(!t.firstChild||r(t))return;var s=null,a=!1,c=null,l=dy(c,t,r);while(l!==t){if(l.nodeType===3||l.nodeType===4){var u=l.data.replace(/[ \r\n\t]+/g," ");if((!s||/ $/.test(s.data))&&!a&&u[0]===" ")u=u.substr(1);if(!u){l=cu(l);continue}l.data=u,s=l}else if(l.nodeType===1){if(n(l)||l.nodeName==="BR"){if(s)s.data=s.data.replace(/ $/,"");s=null,a=!1}else if(o(l)||r(l))s=null,a=!0;else if(s)a=!1}else{l=cu(l);continue}var d=dy(c,l,r);c=l,l=d}if(s){if(s.data=s.data.replace(/ $/,""),!s.data)cu(s)}}function cu(e){var t=e.nextSibling||e.parentNode;return e.parentNode.removeChild(e),t}function dy(e,t,n){if(e&&e.parentNode===t||n(t))return t.nextSibling||t.parentNode;return t.firstChild||t.nextSibling||t.parentNode}var hu=typeof window<"u"?window:{};function k0(){var e=hu.DOMParser,t=!1;try{if(new e().parseFromString("","text/html"))t=!0}catch(n){}return t}function C0(){var e=function(){};if(T0())e.prototype.parseFromString=function(t){var n=new window.ActiveXObject("htmlfile");return n.designMode="on",n.open(),n.write(t),n.close(),n};else e.prototype.parseFromString=function(t){var n=document.implementation.createHTMLDocument("");return n.open(),n.write(t),n.close(),n};return e}function T0(){var e=!1;try{document.implementation.createHTMLDocument("").open()}catch(t){if(hu.ActiveXObject)e=!0}return e}var E0=k0()?hu.DOMParser:C0();function A0(e,t){var n;if(typeof e==="string"){var o=I0().parseFromString('<x-turndown id="turndown-root">'+e+"</x-turndown>","text/html");n=o.getElementById("turndown-root")}else n=e.cloneNode(!0);return S0({element:n,isBlock:du,isVoid:vy,isPre:t.preformattedCode?z0:null}),n}var lu;function I0(){return lu=lu||new E0,lu}function z0(e){return e.nodeName==="PRE"||e.nodeName==="CODE"}function P0(e,t){return e.isBlock=du(e),e.isCode=e.nodeName==="CODE"||e.parentNode.isCode,e.isBlank=N0(e),e.flankingWhitespace=R0(e,t),e}function N0(e){return!vy(e)&&!x0(e)&&/^\s*$/i.test(e.textContent)&&!y0(e)&&!b0(e)}function R0(e,t){if(e.isBlock||t.preformattedCode&&e.isCode)return{leading:"",trailing:""};var n=$0(e.textContent);if(n.leadingAscii&&py("left",e,t))n.leading=n.leadingNonAscii;if(n.trailingAscii&&py("right",e,t))n.trailing=n.trailingNonAscii;return{leading:n.leading,trailing:n.trailing}}function $0(e){var t=e.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);return{leading:t[1],leadingAscii:t[2],leadingNonAscii:t[3],trailing:t[4],trailingNonAscii:t[5],trailingAscii:t[6]}}function py(e,t,n){var o,r,s;if(e==="left")o=t.previousSibling,r=/ $/;else o=t.nextSibling,r=/^ /;if(o){if(o.nodeType===3)s=r.test(o.nodeValue);else if(n.preformattedCode&&o.nodeName==="CODE")s=!1;else if(o.nodeType===1&&!du(o))s=r.test(o.textContent)}return s}var M0=Array.prototype.reduce;function si(e){if(!(this instanceof si))return new si(e);var t={rules:yt,headingStyle:"setext",hr:"* * *",bulletListMarker:"*",codeBlockStyle:"indented",fence:"```",emDelimiter:"_",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",br:" ",preformattedCode:!1,blankReplacement:function(n,o){return o.isBlock?`
152
+ `,this.references=[];return t}};_t.emphasis={filter:["em","i"],replacement:function(e,t,n){if(!e.trim())return"";return n.emDelimiter+e+n.emDelimiter}};_t.strong={filter:["strong","b"],replacement:function(e,t,n){if(!e.trim())return"";return n.strongDelimiter+e+n.strongDelimiter}};_t.code={filter:function(e){var t=e.previousSibling||e.nextSibling,n=e.parentNode.nodeName==="PRE"&&!t;return e.nodeName==="CODE"&&!n},replacement:function(e){if(!e)return"";e=e.replace(/\r?\n|\r/g," ");var t=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"",n="`",o=e.match(/`+/gm)||[];while(o.indexOf(n)!==-1)n=n+"`";return n+t+e+t+n}};_t.image={filter:"img",replacement:function(e,t){var n=cb(_a(t.getAttribute("alt"))),o=Ou(t.getAttribute("src")||""),r=_a(t.getAttribute("title")),s=r?' "'+Lu(r)+'"':"";return o?"!["+n+"]("+o+s+")":""}};function _a(e){return e?e.replace(/(\n+\s*)+/g,`
153
+ `):""}function Ou(e){var t=e.replace(/([<>()])/g,"\\$1");return t.indexOf(" ")>=0?"<"+t+">":t}function Lu(e){return e.replace(/"/g,"\\\"")}function lb(e){this.options=e,this._keep=[],this._remove=[],this.blankRule={replacement:e.blankReplacement},this.keepReplacement=e.keepReplacement,this.defaultRule={replacement:e.defaultReplacement},this.array=[];for(var t in e.rules)this.array.push(e.rules[t])}lb.prototype={add:function(e,t){this.array.unshift(t)},keep:function(e){this._keep.unshift({filter:e,replacement:this.keepReplacement})},remove:function(e){this._remove.unshift({filter:e,replacement:function(){return""}})},forNode:function(e){if(e.isBlank)return this.blankRule;var t;if(t=zu(this.array,e,this.options))return t;if(t=zu(this._keep,e,this.options))return t;if(t=zu(this._remove,e,this.options))return t;return this.defaultRule},forEach:function(e){for(var t=0;t<this.array.length;t++)e(this.array[t],t)}};function zu(e,t,n){for(var o=0;o<e.length;o++){var r=e[o];if(wC(r,t,n))return r}return}function wC(e,t,n){var o=e.filter;if(typeof o==="string"){if(o===t.nodeName.toLowerCase())return!0}else if(Array.isArray(o)){if(o.indexOf(t.nodeName.toLowerCase())>-1)return!0}else if(typeof o==="function"){if(o.call(e,t,n))return!0}else throw TypeError("`filter` needs to be a string, array, or function")}function _C(e){var{element:t,isBlock:n,isVoid:o}=e,r=e.isPre||function(d){return d.nodeName==="PRE"};if(!t.firstChild||r(t))return;var s=null,a=!1,c=null,l=Qy(c,t,r);while(l!==t){if(l.nodeType===3||l.nodeType===4){var u=l.data.replace(/[ \r\n\t]+/g," ");if((!s||/ $/.test(s.data))&&!a&&u[0]===" ")u=u.substr(1);if(!u){l=Pu(l);continue}l.data=u,s=l}else if(l.nodeType===1){if(n(l)||l.nodeName==="BR"){if(s)s.data=s.data.replace(/ $/,"");s=null,a=!1}else if(o(l)||r(l))s=null,a=!0;else if(s)a=!1}else{l=Pu(l);continue}var p=Qy(c,l,r);c=l,l=p}if(s){if(s.data=s.data.replace(/ $/,""),!s.data)Pu(s)}}function Pu(e){var t=e.nextSibling||e.parentNode;return e.parentNode.removeChild(e),t}function Qy(e,t,n){if(e&&e.parentNode===t||n(t))return t.nextSibling||t.parentNode;return t.firstChild||t.nextSibling||t.parentNode}var Du=typeof window<"u"?window:{};function SC(){var e=Du.DOMParser,t=!1;try{if(new e().parseFromString("","text/html"))t=!0}catch(n){}return t}function kC(){var e=function(){};if(CC())e.prototype.parseFromString=function(t){var n=new window.ActiveXObject("htmlfile");return n.designMode="on",n.open(),n.write(t),n.close(),n};else e.prototype.parseFromString=function(t){var n=document.implementation.createHTMLDocument("");return n.open(),n.write(t),n.close(),n};return e}function CC(){var e=!1;try{document.implementation.createHTMLDocument("").open()}catch(t){if(Du.ActiveXObject)e=!0}return e}var TC=SC()?Du.DOMParser:kC();function IC(e,t){var n;if(typeof e==="string"){var o=EC().parseFromString('<x-turndown id="turndown-root">'+e+"</x-turndown>","text/html");n=o.getElementById("turndown-root")}else n=e.cloneNode(!0);return _C({element:n,isBlock:$u,isVoid:ib,isPre:t.preformattedCode?AC:null}),n}var Nu;function EC(){return Nu=Nu||new TC,Nu}function AC(e){return e.nodeName==="PRE"||e.nodeName==="CODE"}function zC(e,t){return e.isBlock=$u(e),e.isCode=e.nodeName==="CODE"||e.parentNode.isCode,e.isBlank=PC(e),e.flankingWhitespace=NC(e,t),e}function PC(e){return!ib(e)&&!yC(e)&&/^\s*$/i.test(e.textContent)&&!vC(e)&&!bC(e)}function NC(e,t){if(e.isBlock||t.preformattedCode&&e.isCode)return{leading:"",trailing:""};var n=RC(e.textContent);if(n.leadingAscii&&eb("left",e,t))n.leading=n.leadingNonAscii;if(n.trailingAscii&&eb("right",e,t))n.trailing=n.trailingNonAscii;return{leading:n.leading,trailing:n.trailing}}function RC(e){var t=e.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);return{leading:t[1],leadingAscii:t[2],leadingNonAscii:t[3],trailing:t[4],trailingNonAscii:t[5],trailingAscii:t[6]}}function eb(e,t,n){var o,r,s;if(e==="left")o=t.previousSibling,r=/ $/;else o=t.nextSibling,r=/^ /;if(o){if(o.nodeType===3)s=r.test(o.nodeValue);else if(n.preformattedCode&&o.nodeName==="CODE")s=!1;else if(o.nodeType===1&&!$u(o))s=r.test(o.textContent)}return s}var $C=Array.prototype.reduce;function wi(e){if(!(this instanceof wi))return new wi(e);var t={rules:_t,headingStyle:"setext",hr:"* * *",bulletListMarker:"*",codeBlockStyle:"indented",fence:"```",emDelimiter:"_",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",br:" ",preformattedCode:!1,blankReplacement:function(n,o){return o.isBlock?`
139
154
 
140
155
  `:""},keepReplacement:function(n,o){return o.isBlock?`
141
156
 
@@ -145,15 +160,15 @@ ${r}
145
160
 
146
161
  `+n+`
147
162
 
148
- `:n}};this.options=g0({},t,e),this.rules=new wy(this.options)}si.prototype={turndown:function(e){if(!D0(e))throw TypeError(e+" is not a string, or an element/document/fragment node.");if(e==="")return"";var t=_y.call(this,new A0(e,this.options));return O0.call(this,t)},use:function(e){if(Array.isArray(e))for(var t=0;t<e.length;t++)this.use(e[t]);else if(typeof e==="function")e(this);else throw TypeError("plugin must be a Function or an Array of Functions");return this},addRule:function(e,t){return this.rules.add(e,t),this},keep:function(e){return this.rules.keep(e),this},remove:function(e){return this.rules.remove(e),this},escape:function(e){return by(e)}};function _y(e){var t=this;return M0.call(e.childNodes,function(n,o){o=new P0(o,t.options);var r="";if(o.nodeType===3)r=o.isCode?o.nodeValue:t.escape(o.nodeValue);else if(o.nodeType===1)r=L0.call(t,o);return Sy(n,r)},"")}function O0(e){var t=this;return this.rules.forEach(function(n){if(typeof n.append==="function")e=Sy(e,n.append(t.options))}),e.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}function L0(e){var t=this.rules.forNode(e),n=_y.call(this,e),o=e.flankingWhitespace;if(o.leading||o.trailing)n=n.trim();return o.leading+t.replacement(n,e,this.options)+o.trailing}function Sy(e,t){var n=fy(e),o=my(t),r=Math.max(e.length-n.length,t.length-o.length),s=`
163
+ `:n}};this.options=hC({},t,e),this.rules=new lb(this.options)}wi.prototype={turndown:function(e){if(!LC(e))throw TypeError(e+" is not a string, or an element/document/fragment node.");if(e==="")return"";var t=ub.call(this,new IC(e,this.options));return MC.call(this,t)},use:function(e){if(Array.isArray(e))for(var t=0;t<e.length;t++)this.use(e[t]);else if(typeof e==="function")e(this);else throw TypeError("plugin must be a Function or an Array of Functions");return this},addRule:function(e,t){return this.rules.add(e,t),this},keep:function(e){return this.rules.keep(e),this},remove:function(e){return this.rules.remove(e),this},escape:function(e){return cb(e)}};function ub(e){var t=this;return $C.call(e.childNodes,function(n,o){o=new zC(o,t.options);var r="";if(o.nodeType===3)r=o.isCode?o.nodeValue:t.escape(o.nodeValue);else if(o.nodeType===1)r=OC.call(t,o);return db(n,r)},"")}function MC(e){var t=this;return this.rules.forEach(function(n){if(typeof n.append==="function")e=db(e,n.append(t.options))}),e.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}function OC(e){var t=this.rules.forNode(e),n=ub.call(this,e),o=e.flankingWhitespace;if(o.leading||o.trailing)n=n.trim();return o.leading+t.replacement(n,e,this.options)+o.trailing}function db(e,t){var n=nb(e),o=tb(t),r=Math.max(e.length-n.length,t.length-o.length),s=`
149
164
 
150
- `.substring(0,r);return n+s+o}function D0(e){return e!=null&&(typeof e==="string"||e.nodeType&&(e.nodeType===1||e.nodeType===9||e.nodeType===11))}function oa(){let e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0).cloneRange():null;on("Link URL","https://example.com").then((n)=>{if(!n)return;let o=n.trim().toLowerCase();if(o.startsWith("javascript:")||o.startsWith("data:"))return;if(t){let r=window.getSelection();r?.removeAllRanges(),r?.addRange(t)}document.execCommand("createLink",!1,n)})}function ky(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);if(t.collapsed)return;let n=t.toString(),o=document.createElement("code");o.textContent=n,t.deleteContents(),t.insertNode(o);let r=document.createRange();r.setStartAfter(o),r.setEndAfter(o),e.removeAllRanges(),e.addRange(r)}var ra=8,F0=[{kind:"exec",command:"bold",icon:"B",title:`Bold (${He("B")})`},{kind:"exec",command:"italic",icon:"I",title:`Italic (${He("I")})`},{kind:"exec",command:"strikeThrough",icon:"S",title:"Strikethrough"},{kind:"code",icon:"{ }",title:"Inline code",dividerBefore:!0},{kind:"block",tag:"H1",icon:"H1",title:"Heading 1",dividerBefore:!0},{kind:"block",tag:"H2",icon:"H2",title:"Heading 2"},{kind:"block",tag:"H3",icon:"H3",title:"Heading 3"},{kind:"block",tag:"P",icon:"¶",title:"Paragraph"},{kind:"block",tag:"BLOCKQUOTE",icon:"❝",title:"Quote",dividerBefore:!0},{kind:"exec",command:"insertUnorderedList",icon:"•",title:"Bullet list"},{kind:"exec",command:"insertOrderedList",icon:"1.",title:"Numbered list"},{kind:"link",icon:"\uD83D\uDD17",title:`Link (${He("K")})`,dividerBefore:!0}];function j0(e){switch(e.kind){case"exec":document.execCommand(e.command);return;case"block":document.execCommand("formatBlock",!1,e.tag);return;case"code":ky();return;case"link":oa();return}}function Cy({hostRef:e,onChange:t}){let[n,o]=O(!1),[r,s]=O({top:0,left:0}),[a,c]=O(0),l=M(null),u=M(null),d=L(()=>{let m=e.current;if(!m){o(!1);return}let v=window.getSelection();if(!v||v.rangeCount===0||v.isCollapsed){o(!1);return}let y=v.getRangeAt(0);if(!m.contains(y.commonAncestorContainer)){o(!1);return}let x=y.getBoundingClientRect();if(x.width===0&&x.height===0){o(!1);return}let h=a||420,g=Math.max(ra,Math.min(x.left+x.width/2-h/2,window.innerWidth-h-ra)),b=Math.max(ra,x.top-ra-36);s({top:b,left:g}),o(!0)},[e,a]),p=L(()=>{if(u.current!==null)return;u.current=requestAnimationFrame(()=>{u.current=null,d()})},[d]);D(()=>(document.addEventListener("selectionchange",p),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{if(document.removeEventListener("selectionchange",p),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p),u.current!==null)cancelAnimationFrame(u.current)}),[p]),qi(()=>{if(!n)return;let m=l.current;if(!m)return;let v=m.getBoundingClientRect().width;if(v&&Math.abs(v-a)>1)c(v)},[n,a]);let f=L((m)=>{j0(m),t(),d()},[t,d]);if(!n)return null;return i("div",{ref:l,class:"md-inline-format-bar",style:{top:`${r.top}px`,left:`${r.left}px`},onMouseDown:(m)=>m.preventDefault(),children:F0.flatMap((m,v)=>{let y=i("button",{type:"button",class:"md-inline-format-btn",title:m.title,onClick:()=>f(m),children:m.icon},`btn-${v}`,!1,void 0,this);return m.dividerBefore?[i("span",{class:"md-inline-format-divider"},`div-${v}`,!1,void 0,this),y]:[y]})},void 0,!1,void 0,this)}var gu=null;function Z0(){if(gu)return gu;let e=new si({headingStyle:"atx",codeBlockStyle:"fenced",emDelimiter:"*",bulletListMarker:"-"});return e.use(Ty.gfm),gu=e,e}function Ey({initialHtml:e,className:t,onChange:n,onSave:o}){let r=M(null),s=M(e);D(()=>{let f=r.current;if(!f)return;f.innerHTML=s.current;for(let m of f.querySelectorAll('input[type="checkbox"][disabled]'))m.removeAttribute("disabled")},[]);let a=L(()=>{let f=r.current;if(!f)return"";return Z0().turndown(f.innerHTML)},[]),c=L(()=>{n(a())},[n,a]),l=L(()=>{let f=r.current;if(!f||!f.isConnected||f.innerHTML==="")return;o?.(a())},[o,a]),u=L((f)=>{if(!(f.metaKey||f.ctrlKey))return;if(f.key==="s"){f.preventDefault(),l();return}if(f.key==="b"){f.preventDefault(),document.execCommand("bold"),c();return}if(f.key==="i"){f.preventDefault(),document.execCommand("italic"),c();return}if(f.key==="k")f.preventDefault(),oa(),c()},[c,l]),d=L((f)=>{let m=f.target;if(m instanceof HTMLInputElement&&m.type==="checkbox")m.toggleAttribute("checked",m.checked),c()},[c]),p=L((f)=>{let m=f.clipboardData?.getData("text/plain");if(m==null)return;f.preventDefault(),document.execCommand("insertText",!1,m),c()},[c]);return i(ve,{children:[i("div",{ref:r,class:t,contentEditable:!0,spellcheck:!1,onInput:c,onKeyDown:u,onPaste:p,onClick:d,onBlur:l},void 0,!1,void 0,this),i(Cy,{hostRef:r,onChange:c},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function vu({html:e,className:t,style:n,onTaskToggle:o}){let r=M(null),s=M(o);return s.current=o,D(()=>{let c=r.current;if(!c)return;if(c.replaceChildren(),!e)return;let l=document.createElement("template");if(l.innerHTML=e,c.append(l.content.cloneNode(!0)),s.current)for(let u of c.querySelectorAll('input[type="checkbox"][disabled]'))u.removeAttribute("disabled")},[e]),i("div",{ref:r,class:t,style:n,onClick:o?(c)=>{let l=s.current,u=r.current;if(!u||!l)return;let d=c.target,p=null;if(d instanceof HTMLInputElement&&d.type==="checkbox")p=d;else{let v=d.closest("li")?.querySelector(':scope > input[type="checkbox"]');if(v&&c.clientX<=v.getBoundingClientRect().right+6)p=v}if(!p)return;c.stopPropagation();let f=[...u.querySelectorAll('input[type="checkbox"]')].indexOf(p);if(f>=0)l(f)}:void 0},void 0,!1,void 0,this)}function H0(e,t){let n=-1;return e.replace(/^(\s*(?:[-*+]|\d+[.)])\s+\[)([ xX])(\])/gm,(o,r,s,a)=>{if(n+=1,n!==t)return o;return`${r}${s===" "?"x":" "}${a}`})}function ia({node:e,expanded:t=!1}){let n=e.data.path,[o,r]=O(""),[s,a]=O(""),[c,l]=O(!1),[u,d]=O(!1),[p,f]=O(!1),[m,v]=O(!1),y=M(null),x=M(null),h=M(""),g=M(null),b=e.data.reviewActive;D(()=>{let F=!1;return(async()=>{let T;if(n){let W=await Gr(n);if(F)return;T=W.content}else if(e.data.content)T=e.data.content;else{l(!0);return}r(T);let B=await un(T);if(F)return;a(B),l(!0),ie(e.id,{content:T,rendered:B})})(),()=>{F=!0}},[n,e.id,e.data.content]);let E=L(async(F)=>{let T=F.target.value;r(T),v(!0);let B=await un(T);a(B)},[]),j=L(async(F)=>{if(!n){let B=await un(F);a(B),v(!1),ie(e.id,{content:F,rendered:B}),await ct(e.id,{content:F,data:{rendered:B}});return}f(!0);let T=await Dg(n,F);if(f(!1),T.ok){let B=await un(F);a(B),v(!1),ie(e.id,{content:F,rendered:B,savedAt:T.updatedAt}),await ct(e.id,{content:F,data:{rendered:B,savedAt:T.updatedAt}})}},[n,e.id]),_=L(async()=>{if(!m)return;await j(o)},[m,o,j]),R=L((F)=>{if((F.metaKey||F.ctrlKey)&&F.key==="s"){F.preventDefault(),_();return}let T=y.current;if(T&&Vv(F,T))return;if(T&&F.key==="Tab")F.preventDefault(),qv(T,F.shiftKey)},[_]);g.current=j;let A=L((F)=>{if(r(F),v(!0),h.current=F,x.current!==null)window.clearTimeout(x.current);x.current=window.setTimeout(()=>{x.current=null,j(F)},800)},[j]),C=L((F)=>{if(r(F),h.current=F,x.current!==null)window.clearTimeout(x.current),x.current=null;j(F)},[j]);D(()=>()=>{if(x.current===null)return;window.clearTimeout(x.current),x.current=null;let F=g.current;if(F)F(h.current)},[e.id]);let Z=b?i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-ok-10)",color:"var(--c-ok)",borderBottom:"1px solid var(--c-ok-20)",textTransform:"uppercase",letterSpacing:"0.05em",fontWeight:600},children:"Review active"},void 0,!1,void 0,this):null;if(u&&t)return i("div",{class:"md-editor-expanded",onKeyDown:R,children:[i("div",{class:"md-editor-toolbar",children:[i("button",{type:"button",class:"md-toolbar-btn",onClick:()=>d(!1),children:"← Back to document"},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"6px",alignItems:"center"},children:[n&&i("span",{class:"md-toolbar-path",children:n.split("/").pop()},void 0,!1,void 0,this),i("button",{type:"button",class:`md-toolbar-btn${m?" md-toolbar-btn-primary":""}`,onClick:_,disabled:!m||p,children:p?"Saving…":m?"Save":"Saved"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"md-editor-split",children:[i("div",{style:{flex:1,position:"relative",display:"flex",flexDirection:"column"},children:[i("textarea",{ref:y,value:o,onInput:E,spellcheck:!1},void 0,!1,void 0,this),i(ou,{textareaRef:y},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(vu,{html:s,className:"md-preview"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(u)return i("div",{class:"md-editor-split",style:{height:"100%"},onKeyDown:R,children:[i("div",{style:{flex:1,position:"relative",display:"flex",flexDirection:"column"},children:[i("textarea",{ref:y,value:o,onInput:E,spellcheck:!1},void 0,!1,void 0,this),i(ou,{textareaRef:y},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(vu,{html:s,className:"md-preview"},void 0,!1,void 0,this),i("div",{style:{position:"absolute",bottom:"8px",right:"8px",display:"flex",gap:"6px"},children:[i("button",{type:"button",onClick:()=>d(!1),style:{padding:"4px 10px",fontSize:"11px",background:"var(--c-input-bg)",border:"1px solid var(--c-line)",borderRadius:"6px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Document"},void 0,!1,void 0,this),i("button",{type:"button",onClick:_,disabled:!m||p,style:{padding:"4px 10px",fontSize:"11px",background:m?"var(--c-accent-25)":"var(--c-input-bg)",border:`1px solid ${m?"var(--c-accent)":"var(--c-line)"}`,borderRadius:"6px",color:m?"var(--c-text)":"var(--c-dim)",cursor:m?"pointer":"default"},children:p?"Saving…":m?"Save":"Saved"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(t)return i("div",{style:{height:"100%",position:"relative"},children:[Z,i("div",{class:"md-reader",children:c?i(Ey,{initialHtml:s||"<p><br></p>",className:"md-reader-content md-reader-editable",onChange:A,onSave:C},e.id,!1,void 0,this):i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"24px"},children:"Loading…"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"md-edit-fab",onClick:()=>d(!0),children:"</> Source"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{style:{height:"100%",position:"relative"},children:[Z,i(vu,{html:s,style:{padding:s?"0":"12px",color:s?void 0:"var(--c-dim)"},onTaskToggle:(F)=>{let T=H0(o,F);if(T!==o)C(T)}},void 0,!1,void 0,this),!c&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"Loading…"},void 0,!1,void 0,this),c&&!s&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"Empty node"},void 0,!1,void 0,this),i("button",{type:"button",class:"md-edit-btn",onClick:()=>en(e.id),children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var sa="pmx-canvas-ax",aa="pmx-canvas-ax-ack",Dt="pmx-canvas-html-node",ca="pmx-canvas-ext-app-alive",yu="pmx-canvas-ext-app-paint-probe";function Ay(e,t){switch(e){case"html":return typeof t.html==="string"&&t.html.length>0||typeof t.content==="string"&&t.content.length>0;case"mermaid":return typeof t.content==="string"&&t.content.trim().length>0;case"json-render":case"graph":return!0;case"mcp-app":return t.viewerType==="web-artifact"&&typeof t.path==="string"&&t.path.length>0||typeof t.url==="string"&&t.url.length>0;case"webpage":return typeof t.url==="string"&&t.url.length>0;default:return!1}}var xu="allow-scripts allow-popups allow-popups-to-escape-sandbox";function sr(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t<<5)+t+e.charCodeAt(n)|0;return(t>>>0).toString(36)}function ai(e,t={}){let n=new URLSearchParams;if(n.set("theme",t.theme??Je.value),t.themeToken)n.set("themeToken",t.themeToken);if(t.present)n.set("present","1");if(t.presentToken)n.set("presentToken",t.presentToken);if(t.v)n.set("v",t.v);if(t.axToken)n.set("axToken",t.axToken);if(t.frameToken)n.set("frameToken",t.frameToken);return`/api/canvas/surface/${encodeURIComponent(e)}?${n.toString()}`}function la(e){return Ay(e.type,e.data)}async function ua(e){let t=ai(e.id);if(!(await Hg(e.id,t)).opened)window.open(t,"_blank","noopener")}var Iy=30000;var bu=80;var We=V(new Map),cr=V(null),B0=480,U0=320,W0=650,ci=new Map,ar=new Map,da=new Map,yn=null;function wu(e){We.value=e,q0()}function _u(e){let t=ci.get(e);if(t)clearTimeout(t),ci.delete(e)}function Su(e){let t=ar.get(e);if(t)clearTimeout(t),ar.delete(e)}function Py(e){if(_u(e.id),Su(e.id),!We.value.has(e.id))da.set(e.id,Date.now());let t=new Map(We.value);t.set(e.id,{...e,phase:"forming"}),wu(t)}function _o(e){if(_u(e),Su(e),da.delete(e),!We.value.has(e))return;let t=new Map(We.value);t.delete(e),wu(t)}function zy(e,t,n,o){let r=We.value.get(e);if(!r||r.phase===t)return;let s=new Map(We.value);s.set(e,{...r,phase:t,...o?{settledNodeId:o}:{}}),wu(s),_u(e),ci.set(e,setTimeout(()=>_o(e),n+1500))}function Ny(e,t,n,o){Su(e);let r=Date.now()-(da.get(e)??0),s=Math.max(0,W0-r);if(s===0){zy(e,t,n,o);return}ar.set(e,setTimeout(()=>{ar.delete(e),zy(e,t,n,o)},s))}function Ry(e,t){Ny(e,"settling",B0,t)}function ku(e){Ny(e,"dissolving",U0)}function Cu(){for(let e of ci.values())clearTimeout(e);ci.clear();for(let e of ar.values())clearTimeout(e);if(ar.clear(),da.clear(),yn)clearInterval(yn),yn=null;cr.value=null,We.value=new Map}function q0(){if(yn||We.value.size===0)return;yn=setInterval(()=>{let e=Date.now();for(let t of We.value.values())if(t.phase==="forming"&&t.expiresAt<=e)ku(t.id);if(We.value.size===0&&yn)clearInterval(yn),yn=null},1000),yn.unref?.()}function V0(e,t){try{let n=window.sessionStorage.getItem(e);if(n)return n;let o=t();return window.sessionStorage.setItem(e,o),o}catch{return t()}}var fa=V0("pmx-canvas-human-client",()=>`tab-${Math.random().toString(36).slice(2,8)}`);function G0(){try{let e=new URLSearchParams(window.location.search).get("name")?.trim();if(e)return window.localStorage.setItem("pmx-canvas-human-name",e),e;let t=window.localStorage.getItem("pmx-canvas-human-name")?.trim();if(t)return t}catch{}return`guest-${fa.slice(-4)}`}var My=V(G0()),Oy=V([]),ui=De(()=>Oy.value.filter((e)=>e.clientId!==fa)),So=V(new Map);function Tu(e){if(!e||!Array.isArray(e.humans))return;Oy.value=e.humans}var lr=V(null),ha=null,Ly=0,li=null;function ma(e){Ut("humanPresence","/api/canvas/human-presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({clientId:fa,name:My.value,...e})})}function $y(){li=null,Ly=Date.now(),ma({cursor:ha,grabbingNodeId:lr.value})}function ga(e){ha=e;let t=Date.now()-Ly;if(t>=bu){if(li)clearTimeout(li);$y()}else if(!li)li=setTimeout($y,bu-t)}function Eu(e){lr.value=e,ma({cursor:ha,grabbingNodeId:e})}function X0(e,t){let n=new Map(So.value);n.set(e,t),So.value=n,setTimeout(()=>{let o=new Map(So.value);if(o.get(e)===t)o.delete(e),So.value=o},6000)}function Dy(e,t){let n=[...We.value.values()].filter((r)=>r.nodeId===e&&!r.auto&&r.phase==="forming");if(n.length===0)return;let o=My.value;X0(e,o);for(let r of n)fo({id:r.id,kind:r.kind,label:r.label,reason:`${o} took over “${t}” mid-edit — yield and requeue the change once it is released`}).then((s)=>{if(s)_o(r.id)});Ut("yieldEvent","/api/canvas/ax/event",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({kind:"yield",summary:`${o} grabbed “${t}” mid-edit — agent yielded, change requeued`,nodeIds:[e],source:"browser"})})}var pa=null;function Fy(){ma({cursor:ha,grabbingNodeId:lr.value}),pa=setInterval(()=>ma({grabbingNodeId:lr.value}),3000);let e=()=>{try{navigator.sendBeacon?.("/api/canvas/human-presence",new Blob([JSON.stringify({clientId:fa,left:!0})],{type:"application/json"}))}catch{}};return window.addEventListener("pagehide",e),()=>{if(pa)clearInterval(pa);pa=null,window.removeEventListener("pagehide",e)}}var K0={markdown:{width:360,height:180},context:{width:360,height:180},file:{width:360,height:200},diff:{width:420,height:240},mermaid:{width:360,height:240},status:{width:280,height:120},ledger:{width:320,height:200},image:{width:240,height:180},html:{width:420,height:280},webpage:{width:420,height:280},"json-render":{width:420,height:280},graph:{width:420,height:280},"mcp-app":{width:480,height:320}};function jy(e){return K0[e]}function Zy(e,t,n,o,r){return e.x<o.position.x+o.size.width+r&&e.x+t+r>o.position.x&&e.y<o.position.y+o.size.height+r&&e.y+n+r>o.position.y}function J0(e,t,n,o,r){return o.some((s)=>Zy(e,t,n,s,r))}function va(e,t,n,o,r){return o.find((s)=>Zy(e,t,n,s,r))}function ya(e,t,n,o=24){if(e.length===0)return{x:40,y:80};let r=e[e.length-1],s={x:r.position.x+r.size.width+o,y:r.position.y};if(!J0(s,t,n,e,o))return s;let a=40,c=80,l=3000,u=c;for(let p=0;p<20;p++){let f=a;while(f+t<l){let y=va({x:f,y:u},t,n,e,o);if(!y)return{x:f,y:u};f=y.position.x+y.size.width+o}u=e.filter((y)=>y.position.y<=u+n+o&&y.position.y+y.size.height+o>u).reduce((y,x)=>Math.max(y,x.position.y+x.size.height),u)+o}let d=e.reduce((p,f)=>Math.max(p,f.position.y+f.size.height),0);return{x:a,y:d+o}}var ur=37,Y0=600,Q0=1400,eC=24;function tC(e){return e.type==="html"||e.type==="mermaid"||e.type==="json-render"||e.type==="graph"||e.type==="mcp-app"||e.type==="webpage"}function nC(e){if(e.type==="html")return e.data.presentation!==!0;if(e.type==="mermaid")return!0;if(e.type==="json-render"||e.type==="graph")return!0;if(e.type==="mcp-app")return e.data.viewerType==="web-artifact";return!1}function Hy(e){return e.collapsed===!0||e.data.strictSize===!0||e.data.userResized===!0||e.type==="group"}function Au(e){return!Hy(e)&&!tC(e)}function By(e,t){if(!Au(e)||t<=0)return null;let n=Math.min(t+ur,Y0),o=jy(e.type);return o?Math.max(n,o.height):n}function Iu(e){return nC(e)&&!Hy(e)}function Uy(e,t){if(!Iu(e)||!Number.isFinite(t)||t<=0)return null;let n=Math.min(t+ur+eC,Q0);return n>e.size.height+8?n:null}function Wy(e,t,n){if(t<=e.size.height||e.pinned||e.data.parentGroup)return e.position;let o=n.filter((a)=>a.id!==e.id&&!a.pinned&&a.type!=="group"),r={...e.position},s=va(r,e.size.width,t,o,24);while(s)r.y=s.position.y+s.size.height+24,s=va(r,e.size.width,t,o,24);return r}function dr(e,t,n){D(()=>{if(!n)return;let o=null,r=null,s=()=>lr.value===e.id||ui.value.some((d)=>d.grabbingNodeId===e.id);function a(){if(o=null,s()||r===null)return;let d=r;r=null;let p=N.value.get(e.id);if(!p)return;let f=Uy(p,d);if(f===null)return;let m=Wy(p,f,Array.from(N.value.values())),v=m.x!==p.position.x||m.y!==p.position.y,y={size:{width:p.size.width,height:f},...v?{position:m}:{}};et(p.id,y),ks([{id:p.id,...y}],{recordHistory:v})}function c(){if(o!==null)clearTimeout(o);o=r!==null&&!s()?setTimeout(a,300):null}let l=Lt(()=>{s(),c()});function u(d){if(d.source!==t.current?.contentWindow)return;let p=d.data;if(!p||p.source!=="pmx-canvas-frame"||p.type!=="content-height"||p.token!==n)return;if(typeof p.height!=="number"||!Number.isFinite(p.height)||p.height<=0)return;r=p.height,c()}return window.addEventListener("message",u),()=>{if(window.removeEventListener("message",u),l(),o!==null)clearTimeout(o)}},[e.id,n])}function oC(e){try{return new URL(e,window.location.origin).origin===window.location.origin}catch{return!1}}function pr(e){let t=vt.value,[n,o]=O(null),r=Boolean(e)&&oC(e),s=t==="srcdoc"&&r;if(D(()=>{if(!s)return;let a=!1;return fetch(`${e}${e.includes("?")?"&":"?"}inline-assets=1`,{credentials:"same-origin"}).then((c)=>c.ok?c.text():Promise.reject(Error(`HTTP ${c.status}`))).then((c)=>{if(!a)o({url:e,html:c})}).catch((c)=>{if(console.error("[surface-frame] srcdoc fetch failed, falling back to src:",e,c),!a)o({url:e,html:""})}),()=>{a=!0}},[s,e]),!e)return{};if(!s)return t===null&&r?{}:{src:e};if(n)return n.html?{srcdoc:n.html}:{src:n.url};return{}}function xa({node:e,expanded:t=!1}){let n=M(null),o=Je.value,r=Ie(()=>`theme-${crypto.randomUUID()}`,[]),s=Ie(()=>`frame-${crypto.randomUUID()}`,[]),a=typeof e.data.content==="string"?e.data.content:"",c=e.data.fit==="none"?"none":"contain",l=Ie(()=>sr(`${c}:${a}`),[a,c]),u=Ie(()=>a?ai(e.id,{theme:o,themeToken:r,v:l,frameToken:s}):"",[a,r,l,e.id,s]),d=pr(u);dr(e,n,t?"":s);let p=()=>{n.current?.contentWindow?.postMessage({source:Dt,type:"theme-update",token:r,theme:o},"*")};if(D(p,[o,r]),!a)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No diagram source set"},void 0,!1,void 0,this);return i("iframe",{ref:n,class:"html-node-frame",title:typeof e.data.title==="string"?e.data.title:"Mermaid diagram",sandbox:"allow-scripts",...d,onLoad:p,style:{width:"100%",height:"100%",minHeight:t?"70vh":"0",border:"none",background:"var(--c-bg)",borderRadius:"6px",display:"block"}},void 0,!1,void 0,this)}var zu=["dark","light","high-contrast","midnight","sepia","arctic","ember","forest","volt"];function di(e){return typeof e==="string"&&zu.includes(e)}function Pu(e,t="dark"){return di(e)?e:t}var mr={dark:{label:"Dark",scheme:"dark",swatchBg:"#081524",swatchAccent:"#4BBCFF"},light:{label:"Light",scheme:"light",swatchBg:"#F4EFE6",swatchAccent:"#1A7ABF"},"high-contrast":{label:"High contrast",scheme:"dark",swatchBg:"#000000",swatchAccent:"#00ffff"},midnight:{label:"Midnight",scheme:"dark",swatchBg:"#0A0D1C",swatchAccent:"#8B96FF"},sepia:{label:"Sepia",scheme:"light",swatchBg:"#F2E7D5",swatchAccent:"#B4632C"},arctic:{label:"Arctic",scheme:"dark",swatchBg:"#20242E",swatchAccent:"#7FC8DE"},ember:{label:"Ember",scheme:"dark",swatchBg:"#0B0B0C",swatchAccent:"#F34E1C"},forest:{label:"Forest",scheme:"dark",swatchBg:"#0C1712",swatchAccent:"#5CCF8F"},volt:{label:"Volt",scheme:"dark",swatchBg:"#0B0D0B",swatchAccent:"#DFDFC1"}};function fr(e){return mr[Pu(e)].scheme}var Hn="io.modelcontextprotocol/related-task",wa="2.0",lt=wg((e)=>e!==null&&(typeof e==="object"||typeof e==="function")),qy=ue([S(),ae().int()]),Vy=S(),h$=bt({ttl:ue([ae(),wl()]).optional(),pollInterval:ae().optional()}),rC=k({ttl:ae().optional()}),iC=k({taskId:S()}),Nu=bt({progressToken:qy.optional(),[Hn]:iC.optional()}),Pt=k({_meta:Nu.optional()}),pi=Pt.extend({task:rC.optional()}),Gy=(e)=>pi.safeParse(e).success,ut=k({method:S(),params:Pt.loose().optional()}),Ft=k({_meta:Nu.optional()}),jt=k({method:S(),params:Ft.loose().optional()}),dt=bt({_meta:Nu.optional()}),gr=ue([S(),ae().int()]),Xy=k({jsonrpc:w(wa),id:gr,...ut.shape}).strict(),Ru=(e)=>Xy.safeParse(e).success,Ky=k({jsonrpc:w(wa),...jt.shape}).strict(),Jy=(e)=>Ky.safeParse(e).success,$u=k({jsonrpc:w(wa),id:gr,result:dt}).strict(),mi=(e)=>$u.safeParse(e).success;var Se;(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"})(Se||(Se={}));var Mu=k({jsonrpc:w(wa),id:gr.optional(),error:k({code:ae().int(),message:S(),data:Ee().optional()})}).strict();var Yy=(e)=>Mu.safeParse(e).success;var Qy=ue([Xy,Ky,$u,Mu]),g$=ue([$u,Mu]),Ou=dt.strict(),sC=Ft.extend({requestId:gr.optional(),reason:S().optional()}),_a=jt.extend({method:w("notifications/cancelled"),params:sC}),aC=k({src:S(),mimeType:S().optional(),sizes:re(S()).optional(),theme:wt(["light","dark"]).optional()}),fi=k({icons:re(aC).optional()}),hr=k({name:S(),title:S().optional()}),hi=hr.extend({...hr.shape,...fi.shape,version:S(),websiteUrl:S().optional(),description:S().optional()}),cC=ms(k({applyDefaults:ze().optional()}),ke(S(),Ee())),lC=kl((e)=>{if(e&&typeof e==="object"&&!Array.isArray(e)){if(Object.keys(e).length===0)return{form:{}}}return e},ms(k({form:cC.optional(),url:lt.optional()}),ke(S(),Ee()).optional())),uC=bt({list:lt.optional(),cancel:lt.optional(),requests:bt({sampling:bt({createMessage:lt.optional()}).optional(),elicitation:bt({create:lt.optional()}).optional()}).optional()}),dC=bt({list:lt.optional(),cancel:lt.optional(),requests:bt({tools:bt({call:lt.optional()}).optional()}).optional()}),pC=k({experimental:ke(S(),lt).optional(),sampling:k({context:lt.optional(),tools:lt.optional()}).optional(),elicitation:lC.optional(),roots:k({listChanged:ze().optional()}).optional(),tasks:uC.optional()}),mC=Pt.extend({protocolVersion:S(),capabilities:pC,clientInfo:hi}),fC=ut.extend({method:w("initialize"),params:mC});var hC=k({experimental:ke(S(),lt).optional(),logging:lt.optional(),completions:lt.optional(),prompts:k({listChanged:ze().optional()}).optional(),resources:k({subscribe:ze().optional(),listChanged:ze().optional()}).optional(),tools:k({listChanged:ze().optional()}).optional(),tasks:dC.optional()}),gC=dt.extend({protocolVersion:S(),capabilities:hC,serverInfo:hi,instructions:S().optional()}),vC=jt.extend({method:w("notifications/initialized"),params:Ft.optional()});var ko=ut.extend({method:w("ping"),params:Pt.optional()}),yC=k({progress:ae(),total:Be(ae()),message:Be(S())}),xC=k({...Ft.shape,...yC.shape,progressToken:qy}),Sa=jt.extend({method:w("notifications/progress"),params:xC}),bC=Pt.extend({cursor:Vy.optional()}),gi=ut.extend({params:bC.optional()}),vi=dt.extend({nextCursor:Vy.optional()}),wC=wt(["working","input_required","completed","failed","cancelled"]),yi=k({taskId:S(),status:wC,ttl:ue([ae(),wl()]),createdAt:S(),lastUpdatedAt:S(),pollInterval:Be(ae()),statusMessage:Be(S())}),ka=dt.extend({task:yi}),_C=Ft.merge(yi),xi=jt.extend({method:w("notifications/tasks/status"),params:_C}),Ca=ut.extend({method:w("tasks/get"),params:Pt.extend({taskId:S()})}),Ta=dt.merge(yi),Ea=ut.extend({method:w("tasks/result"),params:Pt.extend({taskId:S()})}),v$=dt.loose(),Aa=gi.extend({method:w("tasks/list")}),Ia=vi.extend({tasks:re(yi)}),za=ut.extend({method:w("tasks/cancel"),params:Pt.extend({taskId:S()})}),ex=dt.merge(yi),tx=k({uri:S(),mimeType:Be(S()),_meta:ke(S(),Ee()).optional()}),nx=tx.extend({text:S()}),Lu=S().refine((e)=>{try{return atob(e),!0}catch{return!1}},{message:"Invalid Base64 string"}),ox=tx.extend({blob:Lu}),bi=wt(["user","assistant"]),vr=k({audience:re(bi).optional(),priority:ae().min(0).max(1).optional(),lastModified:gl({offset:!0}).optional()}),rx=k({...hr.shape,...fi.shape,uri:S(),description:Be(S()),mimeType:Be(S()),annotations:vr.optional(),_meta:Be(bt({}))}),SC=k({...hr.shape,...fi.shape,uriTemplate:S(),description:Be(S()),mimeType:Be(S()),annotations:vr.optional(),_meta:Be(bt({}))}),Du=gi.extend({method:w("resources/list")}),Pa=vi.extend({resources:re(rx)}),Fu=gi.extend({method:w("resources/templates/list")}),ju=vi.extend({resourceTemplates:re(SC)}),Zu=Pt.extend({uri:S()}),kC=Zu,Hu=ut.extend({method:w("resources/read"),params:kC}),Na=dt.extend({contents:re(ue([nx,ox]))}),Bu=jt.extend({method:w("notifications/resources/list_changed"),params:Ft.optional()}),CC=Zu,TC=ut.extend({method:w("resources/subscribe"),params:CC}),EC=Zu,AC=ut.extend({method:w("resources/unsubscribe"),params:EC}),IC=Ft.extend({uri:S()}),zC=jt.extend({method:w("notifications/resources/updated"),params:IC}),PC=k({name:S(),description:Be(S()),required:Be(ze())}),NC=k({...hr.shape,...fi.shape,description:Be(S()),arguments:Be(re(PC)),_meta:Be(bt({}))}),Uu=gi.extend({method:w("prompts/list")}),Wu=vi.extend({prompts:re(NC)}),RC=Pt.extend({name:S(),arguments:ke(S(),S()).optional()}),$C=ut.extend({method:w("prompts/get"),params:RC}),qu=k({type:w("text"),text:S(),annotations:vr.optional(),_meta:ke(S(),Ee()).optional()}),Vu=k({type:w("image"),data:Lu,mimeType:S(),annotations:vr.optional(),_meta:ke(S(),Ee()).optional()}),Gu=k({type:w("audio"),data:Lu,mimeType:S(),annotations:vr.optional(),_meta:ke(S(),Ee()).optional()}),MC=k({type:w("tool_use"),name:S(),id:S(),input:ke(S(),Ee()),_meta:ke(S(),Ee()).optional()}),Xu=k({type:w("resource"),resource:ue([nx,ox]),annotations:vr.optional(),_meta:ke(S(),Ee()).optional()}),Ku=rx.extend({type:w("resource_link")}),yr=ue([qu,Vu,Gu,Ku,Xu]),OC=k({role:bi,content:yr}),LC=dt.extend({description:S().optional(),messages:re(OC)}),Ju=jt.extend({method:w("notifications/prompts/list_changed"),params:Ft.optional()}),DC=k({title:S().optional(),readOnlyHint:ze().optional(),destructiveHint:ze().optional(),idempotentHint:ze().optional(),openWorldHint:ze().optional()}),FC=k({taskSupport:wt(["required","optional","forbidden"]).optional()}),Ra=k({...hr.shape,...fi.shape,description:S().optional(),inputSchema:k({type:w("object"),properties:ke(S(),lt).optional(),required:re(S()).optional()}).catchall(Ee()),outputSchema:k({type:w("object"),properties:ke(S(),lt).optional(),required:re(S()).optional()}).catchall(Ee()).optional(),annotations:DC.optional(),execution:FC.optional(),_meta:ke(S(),Ee()).optional()}),$a=gi.extend({method:w("tools/list")}),jC=vi.extend({tools:re(Ra)}),Co=dt.extend({content:re(yr).default([]),structuredContent:ke(S(),Ee()).optional(),isError:ze().optional()}),y$=Co.or(dt.extend({toolResult:Ee()})),ZC=pi.extend({name:S(),arguments:ke(S(),Ee()).optional()}),Ma=ut.extend({method:w("tools/call"),params:ZC}),Yu=jt.extend({method:w("notifications/tools/list_changed"),params:Ft.optional()}),x$=k({autoRefresh:ze().default(!0),debounceMs:ae().int().nonnegative().default(300)}),ix=wt(["debug","info","notice","warning","error","critical","alert","emergency"]),HC=Pt.extend({level:ix}),BC=ut.extend({method:w("logging/setLevel"),params:HC}),UC=Ft.extend({level:ix,logger:S().optional(),data:Ee()}),Qu=jt.extend({method:w("notifications/message"),params:UC}),WC=k({name:S().optional()}),qC=k({hints:re(WC).optional(),costPriority:ae().min(0).max(1).optional(),speedPriority:ae().min(0).max(1).optional(),intelligencePriority:ae().min(0).max(1).optional()}),VC=k({mode:wt(["auto","required","none"]).optional()}),GC=k({type:w("tool_result"),toolUseId:S().describe("The unique identifier for the corresponding tool call."),content:re(yr).default([]),structuredContent:k({}).loose().optional(),isError:ze().optional(),_meta:ke(S(),Ee()).optional()}),XC=Sl("type",[qu,Vu,Gu]),ba=Sl("type",[qu,Vu,Gu,MC,GC]),KC=k({role:bi,content:ue([ba,re(ba)]),_meta:ke(S(),Ee()).optional()}),JC=pi.extend({messages:re(KC),modelPreferences:qC.optional(),systemPrompt:S().optional(),includeContext:wt(["none","thisServer","allServers"]).optional(),temperature:ae().optional(),maxTokens:ae().int(),stopSequences:re(S()).optional(),metadata:lt.optional(),tools:re(Ra).optional(),toolChoice:VC.optional()}),YC=ut.extend({method:w("sampling/createMessage"),params:JC}),QC=dt.extend({model:S(),stopReason:Be(wt(["endTurn","stopSequence","maxTokens"]).or(S())),role:bi,content:XC}),eT=dt.extend({model:S(),stopReason:Be(wt(["endTurn","stopSequence","maxTokens","toolUse"]).or(S())),role:bi,content:ue([ba,re(ba)])}),tT=k({type:w("boolean"),title:S().optional(),description:S().optional(),default:ze().optional()}),nT=k({type:w("string"),title:S().optional(),description:S().optional(),minLength:ae().optional(),maxLength:ae().optional(),format:wt(["email","uri","date","date-time"]).optional(),default:S().optional()}),oT=k({type:wt(["number","integer"]),title:S().optional(),description:S().optional(),minimum:ae().optional(),maximum:ae().optional(),default:ae().optional()}),rT=k({type:w("string"),title:S().optional(),description:S().optional(),enum:re(S()),default:S().optional()}),iT=k({type:w("string"),title:S().optional(),description:S().optional(),oneOf:re(k({const:S(),title:S()})),default:S().optional()}),sT=k({type:w("string"),title:S().optional(),description:S().optional(),enum:re(S()),enumNames:re(S()).optional(),default:S().optional()}),aT=ue([rT,iT]),cT=k({type:w("array"),title:S().optional(),description:S().optional(),minItems:ae().optional(),maxItems:ae().optional(),items:k({type:w("string"),enum:re(S())}),default:re(S()).optional()}),lT=k({type:w("array"),title:S().optional(),description:S().optional(),minItems:ae().optional(),maxItems:ae().optional(),items:k({anyOf:re(k({const:S(),title:S()}))}),default:re(S()).optional()}),uT=ue([cT,lT]),dT=ue([sT,aT,uT]),pT=ue([dT,tT,nT,oT]),mT=pi.extend({mode:w("form").optional(),message:S(),requestedSchema:k({type:w("object"),properties:ke(S(),pT),required:re(S()).optional()})}),fT=pi.extend({mode:w("url"),message:S(),elicitationId:S(),url:S().url()}),hT=ue([mT,fT]),gT=ut.extend({method:w("elicitation/create"),params:hT}),vT=Ft.extend({elicitationId:S()}),yT=jt.extend({method:w("notifications/elicitation/complete"),params:vT}),xT=dt.extend({action:wt(["accept","decline","cancel"]),content:kl((e)=>e===null?void 0:e,ke(S(),ue([S(),ae(),ze(),re(S())])).optional())}),bT=k({type:w("ref/resource"),uri:S()});var wT=k({type:w("ref/prompt"),name:S()}),_T=Pt.extend({ref:ue([wT,bT]),argument:k({name:S(),value:S()}),context:k({arguments:ke(S(),S()).optional()}).optional()}),ST=ut.extend({method:w("completion/complete"),params:_T});var kT=dt.extend({completion:bt({values:re(S()).max(100),total:Be(ae().int()),hasMore:Be(ze())})}),CT=k({uri:S().startsWith("file://"),name:S().optional(),_meta:ke(S(),Ee()).optional()}),TT=ut.extend({method:w("roots/list"),params:Pt.optional()}),ET=dt.extend({roots:re(CT)}),AT=jt.extend({method:w("notifications/roots/list_changed"),params:Ft.optional()}),b$=ue([ko,fC,ST,BC,$C,Uu,Du,Fu,Hu,TC,AC,Ma,$a,Ca,Ea,Aa,za]),w$=ue([_a,Sa,vC,AT,xi]),_$=ue([Ou,QC,eT,xT,ET,Ta,Ia,ka]),S$=ue([ko,YC,gT,TT,Ca,Ea,Aa,za]),k$=ue([_a,Sa,Qu,zC,Bu,Yu,Ju,xi,yT]),C$=ue([Ou,gC,kT,LC,Wu,Pa,ju,Na,Co,jC,Ta,Ia,ka]);class fe 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===Se.UrlElicitationRequired&&n){let o=n;if(o.elicitations)return new sx(o.elicitations,t)}return new fe(e,t,n)}}class sx extends fe{constructor(e,t=`URL elicitation${e.length>1?"s":""} required`){super(Se.UrlElicitationRequired,t,{elicitations:e})}get elicitations(){return this.data?.elicitations??[]}}function Oa(e){return!!e._zod}function La(e,t){if(Oa(e))return Fr(e,t);return e.safeParse(t)}function ax(e){if(!e)return;let t;if(Oa(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 cx(e){if(Oa(e)){let s=e._zod?.def;if(s){if(s.value!==void 0)return s.value;if(Array.isArray(s.values)&&s.values.length>0)return s.values[0]}}let n=e._def;if(n){if(n.value!==void 0)return n.value;if(Array.isArray(n.values)&&n.values.length>0)return n.values[0]}let o=e.value;if(o!==void 0)return o;return}function Bn(e){return e==="completed"||e==="failed"||e==="cancelled"}var IT=Symbol("Let zodToJsonSchema decide on which parser to use");var vM=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function ed(e){let n=ax(e)?.method;if(!n)throw Error("Schema is missing a method literal");let o=cx(n);if(typeof o!=="string")throw Error("Schema method literal must be a string");return o}function td(e,t){let n=La(e,t);if(!n.success)throw n.error;return n.data}var MT=60000;class Da{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(_a,(t)=>{this._oncancel(t)}),this.setNotificationHandler(Sa,(t)=>{this._onprogress(t)}),this.setRequestHandler(ko,(t)=>({})),this._taskStore=e?.taskStore,this._taskMessageQueue=e?.taskMessageQueue,this._taskStore)this.setRequestHandler(Ca,async(t,n)=>{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new fe(Se.InvalidParams,"Failed to retrieve task: Task not found");return{...o}}),this.setRequestHandler(Ea,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 d=c,p=new fe(d.error.code,d.error.message,d.error.data);u(p)}else{let d=a.type==="response"?"Response":"Error";this._onerror(Error(`${d} 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 fe(Se.InvalidParams,`Task not found: ${r}`);if(!Bn(s.status))return await this._waitForTaskUpdate(r,n.signal),await o();if(Bn(s.status)){let a=await this._taskStore.getTaskResult(r,n.sessionId);return this._clearTaskQueue(r),{...a,_meta:{...a._meta,[Hn]:{taskId:r}}}}return await o()};return await o()}),this.setRequestHandler(Aa,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 fe(Se.InvalidParams,`Failed to list tasks: ${o instanceof Error?o.message:String(o)}`)}}),this.setRequestHandler(za,async(t,n)=>{try{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new fe(Se.InvalidParams,`Task not found: ${t.params.taskId}`);if(Bn(o.status))throw new fe(Se.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 fe(Se.InvalidParams,`Task not found after cancellation: ${t.params.taskId}`);return{_meta:{},...r}}catch(o){if(o instanceof fe)throw o;throw new fe(Se.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),fe.fromError(Se.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),mi(r)||Yy(r))this._onresponse(r);else if(Ru(r))this._onrequest(r,s);else if(Jy(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=fe.fromError(Se.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?.[Hn]?.taskId;if(n===void 0){let u={jsonrpc:"2.0",id:e.id,error:{code:Se.MethodNotFound,message:"Method not found"}};if(r&&this._taskMessageQueue)this._enqueueTaskMessage(r,{type:"error",message:u,timestamp:Date.now()},o?.sessionId).catch((d)=>this._onerror(Error(`Failed to enqueue error response: ${d}`)));else o?.send(u).catch((d)=>this._onerror(Error(`Failed to send an error response: ${d}`)));return}let s=new AbortController;this._requestHandlerAbortControllers.set(e.id,s);let a=Gy(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 d={relatedRequestId:e.id};if(r)d.relatedTask={taskId:r};await this.notification(u,d)},sendRequest:async(u,d,p)=>{if(s.signal.aborted)throw new fe(Se.ConnectionClosed,"Request was cancelled");let f={...p,relatedRequestId:e.id};if(r&&!f.relatedTask)f.relatedTask={taskId:r};let m=f.relatedTask?.taskId??r;if(m&&c)await c.updateTaskStatus(m,"input_required");return await this.request(u,d,f)},authInfo:t?.authInfo,requestId:e.id,requestInfo:t?.requestInfo,taskId:r,taskStore:c,taskRequestedTtl:a?.ttl,closeSSEStream:t?.closeSSEStream,closeStandaloneSSEStream:t?.closeStandaloneSSEStream};Promise.resolve().then(()=>{if(a)this.assertTaskHandlerCapability(e.method)}).then(()=>n(e,l)).then(async(u)=>{if(s.signal.aborted)return;let d={result:u,jsonrpc:"2.0",id:e.id};if(r&&this._taskMessageQueue)await this._enqueueTaskMessage(r,{type:"response",message:d,timestamp:Date.now()},o?.sessionId);else await o?.send(d)},async(u)=>{if(s.signal.aborted)return;let d={jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(u.code)?u.code:Se.InternalError,message:u.message??"Internal error",...u.data!==void 0&&{data:u.data}}};if(r&&this._taskMessageQueue)await this._enqueueTaskMessage(r,{type:"error",message:d,timestamp:Date.now()},o?.sessionId);else await o?.send(d)}).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),mi(e))n(e);else{let s=new fe(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(mi(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(mi(e))o(e);else{let s=fe.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 fe?s:new fe(Se.InternalError,String(s))}}return}let r;try{let s=await this.request(e,ka,n);if(s.task)r=s.task.taskId,yield{type:"taskCreated",task:s.task};else throw new fe(Se.InternalError,"Task creation did not return a task");while(!0){let a=await this.getTask({taskId:r},n);if(yield{type:"taskStatus",task:a},Bn(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 fe(Se.InternalError,`Task ${r} failed`)};else if(a.status==="cancelled")yield{type:"error",error:new fe(Se.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 fe?s:new fe(Se.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 d=(h)=>{u(h)};if(!this._transport){d(Error("Not connected"));return}if(this._options?.enforceStrictCapabilities===!0)try{if(this.assertCapabilityForMethod(e.method),a)this.assertTaskCapability(e.method)}catch(h){d(h);return}n?.signal?.throwIfAborted();let p=this._requestMessageId++,f={...e,jsonrpc:"2.0",id:p};if(n?.onprogress)this._progressHandlers.set(p,n.onprogress),f.params={...e.params,_meta:{...e.params?._meta||{},progressToken:p}};if(a)f.params={...f.params,task:a};if(c)f.params={...f.params,_meta:{...f.params?._meta||{},[Hn]:c}};let m=(h)=>{this._responseHandlers.delete(p),this._progressHandlers.delete(p),this._cleanupTimeout(p),this._transport?.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:p,reason:String(h)}},{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s}).catch((b)=>this._onerror(Error(`Failed to send cancellation: ${b}`)));let g=h instanceof fe?h:new fe(Se.RequestTimeout,String(h));u(g)};this._responseHandlers.set(p,(h)=>{if(n?.signal?.aborted)return;if(h instanceof Error)return u(h);try{let g=La(t,h.result);if(!g.success)u(g.error);else l(g.data)}catch(g){u(g)}}),n?.signal?.addEventListener("abort",()=>{m(n?.signal?.reason)});let v=n?.timeout??MT,y=()=>m(fe.fromError(Se.RequestTimeout,"Request timed out",{timeout:v}));this._setupTimeout(p,v,n?.maxTotalTimeout,y,n?.resetTimeoutOnProgress??!1);let x=c?.taskId;if(x){let h=(g)=>{let b=this._responseHandlers.get(p);if(b)b(g);else this._onerror(Error(`Response handler missing for side-channeled request ${p}`))};this._requestResolvers.set(p,h),this._enqueueTaskMessage(x,{type:"request",message:f,timestamp:Date.now()}).catch((g)=>{this._cleanupTimeout(p),u(g)})}else this._transport.send(f,{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s}).catch((h)=>{this._cleanupTimeout(p),u(h)})})}async getTask(e,t){return this.request({method:"tasks/get",params:e},Ta,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},Ia,t)}async cancelTask(e,t){return this.request({method:"tasks/cancel",params:e},ex,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||{},[Hn]: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||{},[Hn]: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||{},[Hn]:t.relatedTask}}};await this._transport.send(s,t)}setRequestHandler(e,t){let n=ed(e);this.assertRequestHandlerCapability(n),this._requestHandlers.set(n,(o,r)=>{let s=td(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=ed(e);this._notificationHandlers.set(n,(o)=>{let r=td(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"&&Ru(o.message)){let r=o.message.id,s=this._requestResolvers.get(r);if(s)s(new fe(Se.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 fe(Se.InvalidRequest,"Request cancelled"));return}let s=setTimeout(o,n);t.addEventListener("abort",()=>{clearTimeout(s),r(new fe(Se.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 fe(Se.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=xi.parse({method:"notifications/tasks/status",params:a});if(await this.notification(c),Bn(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 fe(Se.InvalidParams,`Task "${o}" not found - it may have been cleaned up`);if(Bn(a.status))throw new fe(Se.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=xi.parse({method:"notifications/tasks/status",params:c});if(await this.notification(l),Bn(c.status))this._cleanupTaskProgressHandler(o)}},listTasks:(o)=>n.listTasks(o,t)}}}var dx="2026-01-26";var OT="ui/notifications/tool-input-partial";var LT=ue([w("light"),w("dark")]).describe("Color theme preference for the host environment."),_i=ue([w("inline"),w("fullscreen"),w("pip")]).describe("Display mode for UI presentation."),DT=ue([w("--color-background-primary"),w("--color-background-secondary"),w("--color-background-tertiary"),w("--color-background-inverse"),w("--color-background-ghost"),w("--color-background-info"),w("--color-background-danger"),w("--color-background-success"),w("--color-background-warning"),w("--color-background-disabled"),w("--color-text-primary"),w("--color-text-secondary"),w("--color-text-tertiary"),w("--color-text-inverse"),w("--color-text-ghost"),w("--color-text-info"),w("--color-text-danger"),w("--color-text-success"),w("--color-text-warning"),w("--color-text-disabled"),w("--color-border-primary"),w("--color-border-secondary"),w("--color-border-tertiary"),w("--color-border-inverse"),w("--color-border-ghost"),w("--color-border-info"),w("--color-border-danger"),w("--color-border-success"),w("--color-border-warning"),w("--color-border-disabled"),w("--color-ring-primary"),w("--color-ring-secondary"),w("--color-ring-inverse"),w("--color-ring-info"),w("--color-ring-danger"),w("--color-ring-success"),w("--color-ring-warning"),w("--font-sans"),w("--font-mono"),w("--font-weight-normal"),w("--font-weight-medium"),w("--font-weight-semibold"),w("--font-weight-bold"),w("--font-text-xs-size"),w("--font-text-sm-size"),w("--font-text-md-size"),w("--font-text-lg-size"),w("--font-heading-xs-size"),w("--font-heading-sm-size"),w("--font-heading-md-size"),w("--font-heading-lg-size"),w("--font-heading-xl-size"),w("--font-heading-2xl-size"),w("--font-heading-3xl-size"),w("--font-text-xs-line-height"),w("--font-text-sm-line-height"),w("--font-text-md-line-height"),w("--font-text-lg-line-height"),w("--font-heading-xs-line-height"),w("--font-heading-sm-line-height"),w("--font-heading-md-line-height"),w("--font-heading-lg-line-height"),w("--font-heading-xl-line-height"),w("--font-heading-2xl-line-height"),w("--font-heading-3xl-line-height"),w("--border-radius-xs"),w("--border-radius-sm"),w("--border-radius-md"),w("--border-radius-lg"),w("--border-radius-xl"),w("--border-radius-full"),w("--border-width-regular"),w("--shadow-hairline"),w("--shadow-sm"),w("--shadow-md"),w("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."),FT=ke(DT.describe(`Style variables for theming MCP apps.
165
+ `.substring(0,r);return n+s+o}function LC(e){return e!=null&&(typeof e==="string"||e.nodeType&&(e.nodeType===1||e.nodeType===9||e.nodeType===11))}function Sa(){let e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0).cloneRange():null;Ot("Link URL","https://example.com").then((n)=>{if(!n)return;let o=n.trim().toLowerCase();if(o.startsWith("javascript:")||o.startsWith("data:"))return;if(t){let r=window.getSelection();r?.removeAllRanges(),r?.addRange(t)}document.execCommand("createLink",!1,n)})}function pb(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);if(t.collapsed)return;let n=t.toString(),o=document.createElement("code");o.textContent=n,t.deleteContents(),t.insertNode(o);let r=document.createRange();r.setStartAfter(o),r.setEndAfter(o),e.removeAllRanges(),e.addRange(r)}var ka=8,DC=[{kind:"exec",command:"bold",icon:"B",title:`Bold (${qe("B")})`},{kind:"exec",command:"italic",icon:"I",title:`Italic (${qe("I")})`},{kind:"exec",command:"strikeThrough",icon:"S",title:"Strikethrough"},{kind:"code",icon:"{ }",title:"Inline code",dividerBefore:!0},{kind:"block",tag:"H1",icon:"H1",title:"Heading 1",dividerBefore:!0},{kind:"block",tag:"H2",icon:"H2",title:"Heading 2"},{kind:"block",tag:"H3",icon:"H3",title:"Heading 3"},{kind:"block",tag:"P",icon:"¶",title:"Paragraph"},{kind:"block",tag:"BLOCKQUOTE",icon:"❝",title:"Quote",dividerBefore:!0},{kind:"exec",command:"insertUnorderedList",icon:"•",title:"Bullet list"},{kind:"exec",command:"insertOrderedList",icon:"1.",title:"Numbered list"},{kind:"link",icon:"\uD83D\uDD17",title:`Link (${qe("K")})`,dividerBefore:!0}];function FC(e){switch(e.kind){case"exec":document.execCommand(e.command);return;case"block":document.execCommand("formatBlock",!1,e.tag);return;case"code":pb();return;case"link":Sa();return}}function mb({hostRef:e,onChange:t}){let[n,o]=I(!1),[r,s]=I({top:0,left:0}),[a,c]=I(0),l=R(null),u=R(null),p=H(()=>{let m=e.current;if(!m){o(!1);return}let h=window.getSelection();if(!h||h.rangeCount===0||h.isCollapsed){o(!1);return}let v=h.getRangeAt(0);if(!m.contains(v.commonAncestorContainer)){o(!1);return}let x=v.getBoundingClientRect();if(x.width===0&&x.height===0){o(!1);return}let g=a||420,y=Math.max(ka,Math.min(x.left+x.width/2-g/2,window.innerWidth-g-ka)),E=Math.max(ka,x.top-ka-36);s({top:E,left:y}),o(!0)},[e,a]),d=H(()=>{if(u.current!==null)return;u.current=requestAnimationFrame(()=>{u.current=null,p()})},[p]);B(()=>(document.addEventListener("selectionchange",d),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{if(document.removeEventListener("selectionchange",d),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d),u.current!==null)cancelAnimationFrame(u.current)}),[d]),Dn(()=>{if(!n)return;let m=l.current;if(!m)return;let h=m.getBoundingClientRect().width;if(h&&Math.abs(h-a)>1)c(h)},[n,a]);let f=H((m)=>{FC(m),t(),p()},[t,p]);if(!n)return null;return i("div",{ref:l,class:"md-inline-format-bar",style:{top:`${r.top}px`,left:`${r.left}px`},onMouseDown:(m)=>m.preventDefault(),children:DC.flatMap((m,h)=>{let v=i("button",{type:"button",class:"md-inline-format-btn",title:m.title,onClick:()=>f(m),children:m.icon},`btn-${h}`,!1,void 0,this);return m.dividerBefore?[i("span",{class:"md-inline-format-divider"},`div-${h}`,!1,void 0,this),v]:[v]})},void 0,!1,void 0,this)}var Fu=null;function BC(){if(Fu)return Fu;let e=new wi({headingStyle:"atx",codeBlockStyle:"fenced",emDelimiter:"*",bulletListMarker:"-"});return e.use(fb.gfm),Fu=e,e}function hb({initialHtml:e,className:t,onChange:n,onSave:o}){let r=R(null),s=R(e);B(()=>{let f=r.current;if(!f)return;f.innerHTML=s.current;for(let m of f.querySelectorAll('input[type="checkbox"][disabled]'))m.removeAttribute("disabled")},[]);let a=H(()=>{let f=r.current;if(!f)return"";return BC().turndown(f.innerHTML)},[]),c=H(()=>{n(a())},[n,a]),l=H(()=>{let f=r.current;if(!f||!f.isConnected||f.innerHTML==="")return;o?.(a())},[o,a]),u=H((f)=>{if(!(f.metaKey||f.ctrlKey))return;if(f.key==="s"){f.preventDefault(),l();return}if(f.key==="b"){f.preventDefault(),document.execCommand("bold"),c();return}if(f.key==="i"){f.preventDefault(),document.execCommand("italic"),c();return}if(f.key==="k")f.preventDefault(),Sa(),c()},[c,l]),p=H((f)=>{let m=f.target;if(m instanceof HTMLInputElement&&m.type==="checkbox")m.toggleAttribute("checked",m.checked),c()},[c]),d=H((f)=>{let m=f.clipboardData?.getData("text/plain");if(m==null)return;f.preventDefault(),document.execCommand("insertText",!1,m),c()},[c]);return i(de,{children:[i("div",{ref:r,class:t,contentEditable:!0,spellcheck:!1,onInput:c,onKeyDown:u,onPaste:d,onClick:p,onBlur:l},void 0,!1,void 0,this),i(mb,{hostRef:r,onChange:c},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Bu({html:e,className:t,style:n,onTaskToggle:o}){let r=R(null),s=R(o);return s.current=o,B(()=>{let c=r.current;if(!c)return;if(c.replaceChildren(),!e)return;let l=document.createElement("template");if(l.innerHTML=e,c.append(l.content.cloneNode(!0)),s.current)for(let u of c.querySelectorAll('input[type="checkbox"][disabled]'))u.removeAttribute("disabled")},[e]),i("div",{ref:r,class:t,style:n,onClick:o?(c)=>{let l=s.current,u=r.current;if(!u||!l)return;let p=c.target,d=null;if(p instanceof HTMLInputElement&&p.type==="checkbox")d=p;else{let h=p.closest("li")?.querySelector(':scope > input[type="checkbox"]');if(h&&c.clientX<=h.getBoundingClientRect().right+6)d=h}if(!d)return;c.stopPropagation();let f=[...u.querySelectorAll('input[type="checkbox"]')].indexOf(d);if(f>=0)l(f)}:void 0},void 0,!1,void 0,this)}function HC(e,t){let n=-1;return e.replace(/^(\s*(?:[-*+]|\d+[.)])\s+\[)([ xX])(\])/gm,(o,r,s,a)=>{if(n+=1,n!==t)return o;return`${r}${s===" "?"x":" "}${a}`})}function Ca({node:e,expanded:t=!1}){let n=va(),o=e.data.path,[r,s]=I(""),[a,c]=I(""),[l,u]=I(!1),[p,d]=I(!1),[f,m]=I(!1),[h,v]=I(!1),x=R(null),g=R(null),y=R(""),E=R(null),L=e.data.reviewActive;B(()=>{let N=!1;return(async()=>{let Z;if(o){let S=await di(o);if(N)return;Z=S.content}else if(e.data.content)Z=e.data.content;else{u(!0);return}s(Z);let j=await bn(Z);if(N)return;c(j),u(!0),ie(e.id,{content:Z,rendered:j})})(),()=>{N=!0}},[o,e.id,e.data.content]);let P=H(async(N)=>{let Z=N.target.value;s(Z),v(!0);let j=await bn(Z);c(j)},[]),b=H(async(N)=>{if(!o){let j=await bn(N);c(j),v(!1),ie(e.id,{content:N,rendered:j}),await dt(e.id,{content:N,data:{rendered:j}});return}m(!0);let Z=await Tv(o,N);if(m(!1),Z.ok){let j=await bn(N);c(j),v(!1),ie(e.id,{content:N,rendered:j,savedAt:Z.updatedAt}),await dt(e.id,{content:N,data:{rendered:j,savedAt:Z.updatedAt}})}},[o,e.id]),T=H(async()=>{if(!h)return;await b(r)},[h,r,b]),w=H((N)=>{if((N.metaKey||N.ctrlKey)&&N.key==="s"){N.preventDefault(),T();return}let Z=x.current;if(Z&&My(N,Z))return;if(Z&&N.key==="Tab")N.preventDefault(),$y(Z,N.shiftKey)},[T]);E.current=b;let _=H((N)=>{if(s(N),v(!0),y.current=N,g.current!==null)window.clearTimeout(g.current);g.current=window.setTimeout(()=>{g.current=null,b(N)},800)},[b]),z=H((N)=>{if(s(N),y.current=N,g.current!==null)window.clearTimeout(g.current),g.current=null;b(N)},[b]);B(()=>()=>{if(g.current===null)return;window.clearTimeout(g.current),g.current=null;let N=E.current;if(N)N(y.current)},[e.id]);let U=L?i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-ok-10)",color:"var(--c-ok)",borderBottom:"1px solid var(--c-ok-20)",textTransform:"uppercase",letterSpacing:"0.05em",fontWeight:600},children:"Review active"},void 0,!1,void 0,this):null;if(p&&t)return i("div",{class:"md-editor-expanded",onKeyDown:w,children:[i("div",{class:"md-editor-toolbar",children:[i("button",{type:"button",class:"md-toolbar-btn",onClick:()=>d(!1),children:"← Back to document"},void 0,!1,void 0,this),i("div",{style:{display:"flex",gap:"6px",alignItems:"center"},children:[o&&i("span",{class:"md-toolbar-path",children:o.split("/").pop()},void 0,!1,void 0,this),i("button",{type:"button",class:`md-toolbar-btn${h?" md-toolbar-btn-primary":""}`,onClick:T,disabled:!h||f,children:f?"Saving…":h?"Save":"Saved"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"md-editor-split",children:[i("div",{style:{flex:1,position:"relative",display:"flex",flexDirection:"column"},children:[i("textarea",{ref:x,value:r,onInput:P,spellcheck:!1},void 0,!1,void 0,this),i(Tu,{textareaRef:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Bu,{html:a,className:"md-preview"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(p)return i("div",{class:"md-editor-split",style:{height:"100%"},onKeyDown:w,children:[i("div",{style:{flex:1,position:"relative",display:"flex",flexDirection:"column"},children:[i("textarea",{ref:x,value:r,onInput:P,spellcheck:!1},void 0,!1,void 0,this),i(Tu,{textareaRef:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(Bu,{html:a,className:"md-preview"},void 0,!1,void 0,this),i("div",{style:{position:"absolute",bottom:"8px",right:"8px",display:"flex",gap:"6px"},children:[i("button",{type:"button",onClick:()=>d(!1),style:{padding:"4px 10px",fontSize:"11px",background:"var(--c-input-bg)",border:"1px solid var(--c-line)",borderRadius:"6px",color:"var(--c-text-soft)",cursor:"pointer"},children:"Document"},void 0,!1,void 0,this),i("button",{type:"button",onClick:T,disabled:!h||f,style:{padding:"4px 10px",fontSize:"11px",background:h?"var(--c-accent-25)":"var(--c-input-bg)",border:`1px solid ${h?"var(--c-accent)":"var(--c-line)"}`,borderRadius:"6px",color:h?"var(--c-text)":"var(--c-dim)",cursor:h?"pointer":"default"},children:f?"Saving…":h?"Save":"Saved"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(t)return i("div",{style:{height:"100%",position:"relative"},children:[U,i("div",{class:"md-reader",children:l?i(hb,{initialHtml:a||"<p><br></p>",className:"md-reader-content md-reader-editable",onChange:_,onSave:z},e.id,!1,void 0,this):i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"24px"},children:"Loading…"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"md-edit-fab",onClick:()=>d(!0),children:"</> Source"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{class:"md-card-preview",children:[i("div",{class:"md-card-content",children:[U,i(Bu,{html:a,style:{padding:a?"0":"12px",color:a?void 0:"var(--c-dim)"},onTaskToggle:(N)=>{let Z=HC(r,N);if(Z!==r)z(Z)}},void 0,!1,void 0,this),!l&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"Loading…"},void 0,!1,void 0,this),l&&!a&&i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"Empty node"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.data.source&&typeof e.data.source==="object"&&"attachmentId"in e.data.source&&i("div",{class:"md-import-source",children:["Source material ·"," ",i("a",{href:`/api/canvas/attachments/${encodeURIComponent(String(e.data.source.attachmentId))}/bytes`,target:"_blank",rel:"noopener noreferrer",children:String(e.data.source.filename??"Original")},void 0,!1,void 0,this)," · ",String(e.data.source.reference??"Location not supplied")]},void 0,!0,void 0,this),i("div",{class:"md-card-actions",children:[n&&i("button",{type:"button",class:"md-readme-btn","aria-pressed":n.readmeNodeId===e.id,onClick:()=>void zy(n.id,n.readmeNodeId===e.id?null:e.id),children:n.readmeNodeId===e.id?"README":"Set as README"},void 0,!1,void 0,this),i("button",{type:"button",class:"md-card-edit",onClick:()=>Zt(e.id),children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Ta="pmx-canvas-ax",Ia="pmx-canvas-ax-ack",Ut="pmx-canvas-html-node",Ea="pmx-canvas-ext-app-alive",Hu="pmx-canvas-ext-app-paint-probe";function gb(e,t){switch(e){case"html":return typeof t.html==="string"&&t.html.length>0||typeof t.content==="string"&&t.content.length>0;case"mermaid":return typeof t.content==="string"&&t.content.trim().length>0;case"json-render":case"graph":return!0;case"mcp-app":return t.viewerType==="web-artifact"&&typeof t.path==="string"&&t.path.length>0||typeof t.url==="string"&&t.url.length>0;case"webpage":return typeof t.url==="string"&&t.url.length>0;default:return!1}}var ju="allow-scripts allow-popups allow-popups-to-escape-sandbox";function gr(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t<<5)+t+e.charCodeAt(n)|0;return(t>>>0).toString(36)}function _i(e,t={}){let n=new URLSearchParams;if(n.set("theme",t.theme??et.value),t.themeToken)n.set("themeToken",t.themeToken);if(t.present)n.set("present","1");if(t.presentToken)n.set("presentToken",t.presentToken);if(t.v)n.set("v",t.v);if(t.axToken)n.set("axToken",t.axToken);if(t.frameToken)n.set("frameToken",t.frameToken);return`/api/canvas/surface/${encodeURIComponent(e)}?${n.toString()}`}function Aa(e){return gb(e.type,e.data)}async function za(e){let t=_i(e.id);if(!(await Nv(e.id,t)).opened)window.open(t,"_blank","noopener")}var vb=30000;var Zu=80;var Ve=q(new Map),yr=q(null),jC=480,ZC=320,UC=650,Si=new Map,vr=new Map,Pa=new Map,Tn=null;function Uu(e){Ve.value=e,qC()}function qu(e){let t=Si.get(e);if(t)clearTimeout(t),Si.delete(e)}function Wu(e){let t=vr.get(e);if(t)clearTimeout(t),vr.delete(e)}function bb(e){if(qu(e.id),Wu(e.id),!Ve.value.has(e.id))Pa.set(e.id,Date.now());let t=new Map(Ve.value);t.set(e.id,{...e,phase:"forming"}),Uu(t)}function Ro(e){if(qu(e),Wu(e),Pa.delete(e),!Ve.value.has(e))return;let t=new Map(Ve.value);t.delete(e),Uu(t)}function yb(e,t,n,o){let r=Ve.value.get(e);if(!r||r.phase===t)return;let s=new Map(Ve.value);s.set(e,{...r,phase:t,...o?{settledNodeId:o}:{}}),Uu(s),qu(e),Si.set(e,setTimeout(()=>Ro(e),n+1500))}function xb(e,t,n,o){Wu(e);let r=Date.now()-(Pa.get(e)??0),s=Math.max(0,UC-r);if(s===0){yb(e,t,n,o);return}vr.set(e,setTimeout(()=>{vr.delete(e),yb(e,t,n,o)},s))}function wb(e,t){xb(e,"settling",jC,t)}function Vu(e){xb(e,"dissolving",ZC)}function Na(){for(let e of Si.values())clearTimeout(e);Si.clear();for(let e of vr.values())clearTimeout(e);if(vr.clear(),Pa.clear(),Tn)clearInterval(Tn),Tn=null;yr.value=null,Ve.value=new Map}function qC(){if(Tn||Ve.value.size===0)return;Tn=setInterval(()=>{let e=Date.now();for(let t of Ve.value.values())if(t.phase==="forming"&&t.expiresAt<=e)Vu(t.id);if(Ve.value.size===0&&Tn)clearInterval(Tn),Tn=null},1000),Tn.unref?.()}function WC(e,t){try{let n=window.sessionStorage.getItem(e);if(n)return n;let o=t();return window.sessionStorage.setItem(e,o),o}catch{return t()}}var Ma=WC("pmx-canvas-human-client",()=>`tab-${Math.random().toString(36).slice(2,8)}`);function VC(){try{let e=new URLSearchParams(window.location.search).get("name")?.trim();if(e)return window.localStorage.setItem("pmx-canvas-human-name",e),e;let t=window.localStorage.getItem("pmx-canvas-human-name")?.trim();if(t)return t}catch{}return`guest-${Ma.slice(-4)}`}var Sb=q(VC()),kb=q([]),Ci=Oe(()=>kb.value.filter((e)=>e.clientId!==Ma)),$o=q(new Map);function Gu(e){if(!e||!Array.isArray(e.humans))return;kb.value=e.humans}var br=q(null),Oa=null,Cb=0,ki=null;function $a(e){Yt("humanPresence","/api/canvas/human-presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({clientId:Ma,name:Sb.value,...e})})}function _b(){ki=null,Cb=Date.now(),$a({cursor:Oa,grabbingNodeId:br.value})}function La(e){Oa=e;let t=Date.now()-Cb;if(t>=Zu){if(ki)clearTimeout(ki);_b()}else if(!ki)ki=setTimeout(_b,Zu-t)}function Xu(e){br.value=e,$a({cursor:Oa,grabbingNodeId:e})}function GC(e,t){let n=new Map($o.value);n.set(e,t),$o.value=n,setTimeout(()=>{let o=new Map($o.value);if(o.get(e)===t)o.delete(e),$o.value=o},6000)}function Tb(e,t){let n=[...Ve.value.values()].filter((r)=>r.nodeId===e&&!r.auto&&r.phase==="forming");if(n.length===0)return;let o=Sb.value;GC(e,o);for(let r of n)Co({id:r.id,kind:r.kind,label:r.label,reason:`${o} took over “${t}” mid-edit — yield and requeue the change once it is released`}).then((s)=>{if(s)Ro(r.id)});Yt("yieldEvent","/api/canvas/ax/event",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({kind:"yield",summary:`${o} grabbed “${t}” mid-edit — agent yielded, change requeued`,nodeIds:[e],source:"browser"})})}var Ra=null;function Ib(){$a({cursor:Oa,grabbingNodeId:br.value}),Ra=setInterval(()=>$a({grabbingNodeId:br.value}),3000);let e=()=>{try{navigator.sendBeacon?.("/api/canvas/human-presence",new Blob([JSON.stringify({clientId:Ma,left:!0})],{type:"application/json"}))}catch{}};return window.addEventListener("pagehide",e),()=>{if(Ra)clearInterval(Ra);Ra=null,window.removeEventListener("pagehide",e)}}var XC={markdown:{width:360,height:180},board:{width:320,height:140},context:{width:360,height:180},file:{width:360,height:200},diff:{width:420,height:240},mermaid:{width:360,height:240},status:{width:280,height:120},ledger:{width:320,height:200},image:{width:240,height:180},html:{width:420,height:280},webpage:{width:420,height:280},"json-render":{width:420,height:280},graph:{width:420,height:280},"mcp-app":{width:480,height:320}};function Eb(e){return XC[e]}function Ab(e,t,n,o,r){return e.x<o.position.x+o.size.width+r&&e.x+t+r>o.position.x&&e.y<o.position.y+o.size.height+r&&e.y+n+r>o.position.y}function KC(e,t,n,o,r){return o.some((s)=>Ab(e,t,n,s,r))}function Da(e,t,n,o,r){return o.find((s)=>Ab(e,t,n,s,r))}function Fa(e,t,n,o=24){if(e.length===0)return{x:40,y:80};let r=e[e.length-1],s={x:r.position.x+r.size.width+o,y:r.position.y};if(!KC(s,t,n,e,o))return s;let a=40,c=80,l=3000,u=c;for(let d=0;d<20;d++){let f=a;while(f+t<l){let v=Da({x:f,y:u},t,n,e,o);if(!v)return{x:f,y:u};f=v.position.x+v.size.width+o}u=e.filter((v)=>v.position.y<=u+n+o&&v.position.y+v.size.height+o>u).reduce((v,x)=>Math.max(v,x.position.y+x.size.height),u)+o}let p=e.reduce((d,f)=>Math.max(d,f.position.y+f.size.height),0);return{x:a,y:p+o}}var xr=37,JC=600,YC=1400,QC=24;function eT(e){return e.type==="html"||e.type==="mermaid"||e.type==="json-render"||e.type==="graph"||e.type==="mcp-app"||e.type==="webpage"}function tT(e){if(e.type==="html")return e.data.presentation!==!0;if(e.type==="mermaid")return!0;if(e.type==="json-render"||e.type==="graph")return!0;if(e.type==="mcp-app")return e.data.viewerType==="web-artifact";return!1}function zb(e){return e.collapsed===!0||e.data.strictSize===!0||e.data.userResized===!0||e.type==="group"}function Ku(e){return!zb(e)&&!eT(e)}function Pb(e,t){if(!Ku(e)||t<=0)return null;let n=Math.min(t+xr,JC),o=Eb(e.type);return o?Math.max(n,o.height):n}function Ju(e){return tT(e)&&!zb(e)}function Nb(e,t){if(!Ju(e)||!Number.isFinite(t)||t<=0)return null;let n=Math.min(t+xr+QC,YC);return n>e.size.height+8?n:null}function Rb(e,t,n){if(t<=e.size.height||e.pinned||e.data.parentGroup)return e.position;let o=n.filter((a)=>a.id!==e.id&&!a.pinned&&a.type!=="group"),r={...e.position},s=Da(r,e.size.width,t,o,24);while(s)r.y=s.position.y+s.size.height+24,s=Da(r,e.size.width,t,o,24);return r}function wr(e,t,n){B(()=>{if(!n)return;let o=null,r=null,s=()=>br.value===e.id||Ci.value.some((p)=>p.grabbingNodeId===e.id);function a(){if(o=null,s()||r===null)return;let p=r;r=null;let d=F.value.get(e.id);if(!d)return;let f=Nb(d,p);if(f===null)return;let m=Rb(d,f,Array.from(F.value.values())),h=m.x!==d.position.x||m.y!==d.position.y,v={size:{width:d.size.width,height:f},...h?{position:m}:{}};it(d.id,v),Xs([{id:d.id,...v}],{recordHistory:h})}function c(){if(o!==null)clearTimeout(o);o=r!==null&&!s()?setTimeout(a,300):null}let l=jt(()=>{s(),c()});function u(p){if(p.source!==t.current?.contentWindow)return;let d=p.data;if(!d||d.source!=="pmx-canvas-frame"||d.type!=="content-height"||d.token!==n)return;if(typeof d.height!=="number"||!Number.isFinite(d.height)||d.height<=0)return;r=d.height,c()}return window.addEventListener("message",u),()=>{if(window.removeEventListener("message",u),l(),o!==null)clearTimeout(o)}},[e.id,n])}function nT(e){try{return new URL(e,window.location.origin).origin===window.location.origin}catch{return!1}}function _r(e){let t=wt.value,[n,o]=I(null),r=Boolean(e)&&nT(e),s=t==="srcdoc"&&r;if(B(()=>{if(!s)return;let a=!1;return fetch(`${e}${e.includes("?")?"&":"?"}inline-assets=1`,{credentials:"same-origin"}).then((c)=>c.ok?c.text():Promise.reject(Error(`HTTP ${c.status}`))).then((c)=>{if(!a)o({url:e,html:c})}).catch((c)=>{if(console.error("[surface-frame] srcdoc fetch failed, falling back to src:",e,c),!a)o({url:e,html:""})}),()=>{a=!0}},[s,e]),!e)return{};if(!s)return t===null&&r?{}:{src:e};if(n)return n.html?{srcdoc:n.html}:{src:n.url};return{}}function Ba({node:e,expanded:t=!1}){let n=R(null),o=et.value,r=Ie(()=>`theme-${crypto.randomUUID()}`,[]),s=Ie(()=>`frame-${crypto.randomUUID()}`,[]),a=typeof e.data.content==="string"?e.data.content:"",c=e.data.fit==="none"?"none":"contain",l=Ie(()=>gr(`${c}:${a}`),[a,c]),u=Ie(()=>a?_i(e.id,{theme:o,themeToken:r,v:l,frameToken:s}):"",[a,r,l,e.id,s]),p=_r(u);wr(e,n,t?"":s);let d=()=>{n.current?.contentWindow?.postMessage({source:Ut,type:"theme-update",token:r,theme:o},"*")};if(B(d,[o,r]),!a)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No diagram source set"},void 0,!1,void 0,this);return i("iframe",{ref:n,class:"html-node-frame",title:typeof e.data.title==="string"?e.data.title:"Mermaid diagram",sandbox:"allow-scripts",...p,onLoad:d,style:{width:"100%",height:"100%",minHeight:t?"70vh":"0",border:"none",background:"var(--c-bg)",borderRadius:"6px",display:"block"}},void 0,!1,void 0,this)}var Yu=["dark","light","high-contrast","midnight","sepia","arctic","ember","forest","volt"];function Ti(e){return typeof e==="string"&&Yu.includes(e)}function Qu(e,t="dark"){return Ti(e)?e:t}var Sr={dark:{label:"Dark",scheme:"dark",swatchBg:"#081524",swatchAccent:"#4BBCFF"},light:{label:"Light",scheme:"light",swatchBg:"#F4EFE6",swatchAccent:"#1A7ABF"},"high-contrast":{label:"High contrast",scheme:"dark",swatchBg:"#000000",swatchAccent:"#00ffff"},midnight:{label:"Midnight",scheme:"dark",swatchBg:"#0A0D1C",swatchAccent:"#8B96FF"},sepia:{label:"Sepia",scheme:"light",swatchBg:"#F2E7D5",swatchAccent:"#B4632C"},arctic:{label:"Arctic",scheme:"dark",swatchBg:"#20242E",swatchAccent:"#7FC8DE"},ember:{label:"Ember",scheme:"dark",swatchBg:"#0B0B0C",swatchAccent:"#F34E1C"},forest:{label:"Forest",scheme:"dark",swatchBg:"#0C1712",swatchAccent:"#5CCF8F"},volt:{label:"Volt",scheme:"dark",swatchBg:"#0B0D0B",swatchAccent:"#DFDFC1"}};function kr(e){return Sr[Qu(e)].scheme}var Qn="io.modelcontextprotocol/related-task",ja="2.0",pt=Kg((e)=>e!==null&&(typeof e==="object"||typeof e==="function")),$b=fe([C(),ce().int()]),Mb=C(),MM=kt({ttl:fe([ce(),Zl()]).optional(),pollInterval:ce().optional()}),oT=A({ttl:ce().optional()}),rT=A({taskId:C()}),ed=kt({progressToken:$b.optional(),[Qn]:rT.optional()}),Lt=A({_meta:ed.optional()}),Ii=Lt.extend({task:oT.optional()}),Ob=(e)=>Ii.safeParse(e).success,mt=A({method:C(),params:Lt.loose().optional()}),qt=A({_meta:ed.optional()}),Wt=A({method:C(),params:qt.loose().optional()}),ft=kt({_meta:ed.optional()}),Tr=fe([C(),ce().int()]),Lb=A({jsonrpc:k(ja),id:Tr,...mt.shape}).strict(),td=(e)=>Lb.safeParse(e).success,Db=A({jsonrpc:k(ja),...Wt.shape}).strict(),Fb=(e)=>Db.safeParse(e).success,nd=A({jsonrpc:k(ja),id:Tr,result:ft}).strict(),Ei=(e)=>nd.safeParse(e).success;var Te;(function(e){e[e.ConnectionClosed=-32000]="ConnectionClosed",e[e.RequestTimeout=-32001]="RequestTimeout",e[e.ParseError=-32700]="ParseError",e[e.InvalidRequest=-32600]="InvalidRequest",e[e.MethodNotFound=-32601]="MethodNotFound",e[e.InvalidParams=-32602]="InvalidParams",e[e.InternalError=-32603]="InternalError",e[e.UrlElicitationRequired=-32042]="UrlElicitationRequired"})(Te||(Te={}));var od=A({jsonrpc:k(ja),id:Tr.optional(),error:A({code:ce().int(),message:C(),data:ze().optional()})}).strict();var Bb=(e)=>od.safeParse(e).success;var Hb=fe([Lb,Db,nd,od]),OM=fe([nd,od]),rd=ft.strict(),iT=qt.extend({requestId:Tr.optional(),reason:C().optional()}),Za=Wt.extend({method:k("notifications/cancelled"),params:iT}),sT=A({src:C(),mimeType:C().optional(),sizes:re(C()).optional(),theme:Ct(["light","dark"]).optional()}),Ai=A({icons:re(sT).optional()}),Cr=A({name:C(),title:C().optional()}),zi=Cr.extend({...Cr.shape,...Ai.shape,version:C(),websiteUrl:C().optional(),description:C().optional()}),aT=Es(A({applyDefaults:Ne().optional()}),Ee(C(),ze())),cT=Wl((e)=>{if(e&&typeof e==="object"&&!Array.isArray(e)){if(Object.keys(e).length===0)return{form:{}}}return e},Es(A({form:aT.optional(),url:pt.optional()}),Ee(C(),ze()).optional())),lT=kt({list:pt.optional(),cancel:pt.optional(),requests:kt({sampling:kt({createMessage:pt.optional()}).optional(),elicitation:kt({create:pt.optional()}).optional()}).optional()}),uT=kt({list:pt.optional(),cancel:pt.optional(),requests:kt({tools:kt({call:pt.optional()}).optional()}).optional()}),dT=A({experimental:Ee(C(),pt).optional(),sampling:A({context:pt.optional(),tools:pt.optional()}).optional(),elicitation:cT.optional(),roots:A({listChanged:Ne().optional()}).optional(),tasks:lT.optional()}),pT=Lt.extend({protocolVersion:C(),capabilities:dT,clientInfo:zi}),mT=mt.extend({method:k("initialize"),params:pT});var fT=A({experimental:Ee(C(),pt).optional(),logging:pt.optional(),completions:pt.optional(),prompts:A({listChanged:Ne().optional()}).optional(),resources:A({subscribe:Ne().optional(),listChanged:Ne().optional()}).optional(),tools:A({listChanged:Ne().optional()}).optional(),tasks:uT.optional()}),hT=ft.extend({protocolVersion:C(),capabilities:fT,serverInfo:zi,instructions:C().optional()}),gT=Wt.extend({method:k("notifications/initialized"),params:qt.optional()});var Mo=mt.extend({method:k("ping"),params:Lt.optional()}),vT=A({progress:ce(),total:We(ce()),message:We(C())}),yT=A({...qt.shape,...vT.shape,progressToken:$b}),Ua=Wt.extend({method:k("notifications/progress"),params:yT}),bT=Lt.extend({cursor:Mb.optional()}),Pi=mt.extend({params:bT.optional()}),Ni=ft.extend({nextCursor:Mb.optional()}),xT=Ct(["working","input_required","completed","failed","cancelled"]),Ri=A({taskId:C(),status:xT,ttl:fe([ce(),Zl()]),createdAt:C(),lastUpdatedAt:C(),pollInterval:We(ce()),statusMessage:We(C())}),qa=ft.extend({task:Ri}),wT=qt.merge(Ri),$i=Wt.extend({method:k("notifications/tasks/status"),params:wT}),Wa=mt.extend({method:k("tasks/get"),params:Lt.extend({taskId:C()})}),Va=ft.merge(Ri),Ga=mt.extend({method:k("tasks/result"),params:Lt.extend({taskId:C()})}),LM=ft.loose(),Xa=Pi.extend({method:k("tasks/list")}),Ka=Ni.extend({tasks:re(Ri)}),Ja=mt.extend({method:k("tasks/cancel"),params:Lt.extend({taskId:C()})}),jb=ft.merge(Ri),Zb=A({uri:C(),mimeType:We(C()),_meta:Ee(C(),ze()).optional()}),Ub=Zb.extend({text:C()}),id=C().refine((e)=>{try{return atob(e),!0}catch{return!1}},{message:"Invalid Base64 string"}),qb=Zb.extend({blob:id}),Mi=Ct(["user","assistant"]),Ir=A({audience:re(Mi).optional(),priority:ce().min(0).max(1).optional(),lastModified:Dl({offset:!0}).optional()}),Wb=A({...Cr.shape,...Ai.shape,uri:C(),description:We(C()),mimeType:We(C()),annotations:Ir.optional(),_meta:We(kt({}))}),_T=A({...Cr.shape,...Ai.shape,uriTemplate:C(),description:We(C()),mimeType:We(C()),annotations:Ir.optional(),_meta:We(kt({}))}),sd=Pi.extend({method:k("resources/list")}),Ya=Ni.extend({resources:re(Wb)}),ad=Pi.extend({method:k("resources/templates/list")}),cd=Ni.extend({resourceTemplates:re(_T)}),ld=Lt.extend({uri:C()}),ST=ld,ud=mt.extend({method:k("resources/read"),params:ST}),Qa=ft.extend({contents:re(fe([Ub,qb]))}),dd=Wt.extend({method:k("notifications/resources/list_changed"),params:qt.optional()}),kT=ld,CT=mt.extend({method:k("resources/subscribe"),params:kT}),TT=ld,IT=mt.extend({method:k("resources/unsubscribe"),params:TT}),ET=qt.extend({uri:C()}),AT=Wt.extend({method:k("notifications/resources/updated"),params:ET}),zT=A({name:C(),description:We(C()),required:We(Ne())}),PT=A({...Cr.shape,...Ai.shape,description:We(C()),arguments:We(re(zT)),_meta:We(kt({}))}),pd=Pi.extend({method:k("prompts/list")}),md=Ni.extend({prompts:re(PT)}),NT=Lt.extend({name:C(),arguments:Ee(C(),C()).optional()}),RT=mt.extend({method:k("prompts/get"),params:NT}),fd=A({type:k("text"),text:C(),annotations:Ir.optional(),_meta:Ee(C(),ze()).optional()}),hd=A({type:k("image"),data:id,mimeType:C(),annotations:Ir.optional(),_meta:Ee(C(),ze()).optional()}),gd=A({type:k("audio"),data:id,mimeType:C(),annotations:Ir.optional(),_meta:Ee(C(),ze()).optional()}),$T=A({type:k("tool_use"),name:C(),id:C(),input:Ee(C(),ze()),_meta:Ee(C(),ze()).optional()}),vd=A({type:k("resource"),resource:fe([Ub,qb]),annotations:Ir.optional(),_meta:Ee(C(),ze()).optional()}),yd=Wb.extend({type:k("resource_link")}),Er=fe([fd,hd,gd,yd,vd]),MT=A({role:Mi,content:Er}),OT=ft.extend({description:C().optional(),messages:re(MT)}),bd=Wt.extend({method:k("notifications/prompts/list_changed"),params:qt.optional()}),LT=A({title:C().optional(),readOnlyHint:Ne().optional(),destructiveHint:Ne().optional(),idempotentHint:Ne().optional(),openWorldHint:Ne().optional()}),DT=A({taskSupport:Ct(["required","optional","forbidden"]).optional()}),ec=A({...Cr.shape,...Ai.shape,description:C().optional(),inputSchema:A({type:k("object"),properties:Ee(C(),pt).optional(),required:re(C()).optional()}).catchall(ze()),outputSchema:A({type:k("object"),properties:Ee(C(),pt).optional(),required:re(C()).optional()}).catchall(ze()).optional(),annotations:LT.optional(),execution:DT.optional(),_meta:Ee(C(),ze()).optional()}),tc=Pi.extend({method:k("tools/list")}),FT=Ni.extend({tools:re(ec)}),Oo=ft.extend({content:re(Er).default([]),structuredContent:Ee(C(),ze()).optional(),isError:Ne().optional()}),DM=Oo.or(ft.extend({toolResult:ze()})),BT=Ii.extend({name:C(),arguments:Ee(C(),ze()).optional()}),nc=mt.extend({method:k("tools/call"),params:BT}),xd=Wt.extend({method:k("notifications/tools/list_changed"),params:qt.optional()}),FM=A({autoRefresh:Ne().default(!0),debounceMs:ce().int().nonnegative().default(300)}),Vb=Ct(["debug","info","notice","warning","error","critical","alert","emergency"]),HT=Lt.extend({level:Vb}),jT=mt.extend({method:k("logging/setLevel"),params:HT}),ZT=qt.extend({level:Vb,logger:C().optional(),data:ze()}),wd=Wt.extend({method:k("notifications/message"),params:ZT}),UT=A({name:C().optional()}),qT=A({hints:re(UT).optional(),costPriority:ce().min(0).max(1).optional(),speedPriority:ce().min(0).max(1).optional(),intelligencePriority:ce().min(0).max(1).optional()}),WT=A({mode:Ct(["auto","required","none"]).optional()}),VT=A({type:k("tool_result"),toolUseId:C().describe("The unique identifier for the corresponding tool call."),content:re(Er).default([]),structuredContent:A({}).loose().optional(),isError:Ne().optional(),_meta:Ee(C(),ze()).optional()}),GT=ql("type",[fd,hd,gd]),Ha=ql("type",[fd,hd,gd,$T,VT]),XT=A({role:Mi,content:fe([Ha,re(Ha)]),_meta:Ee(C(),ze()).optional()}),KT=Ii.extend({messages:re(XT),modelPreferences:qT.optional(),systemPrompt:C().optional(),includeContext:Ct(["none","thisServer","allServers"]).optional(),temperature:ce().optional(),maxTokens:ce().int(),stopSequences:re(C()).optional(),metadata:pt.optional(),tools:re(ec).optional(),toolChoice:WT.optional()}),JT=mt.extend({method:k("sampling/createMessage"),params:KT}),YT=ft.extend({model:C(),stopReason:We(Ct(["endTurn","stopSequence","maxTokens"]).or(C())),role:Mi,content:GT}),QT=ft.extend({model:C(),stopReason:We(Ct(["endTurn","stopSequence","maxTokens","toolUse"]).or(C())),role:Mi,content:fe([Ha,re(Ha)])}),eI=A({type:k("boolean"),title:C().optional(),description:C().optional(),default:Ne().optional()}),tI=A({type:k("string"),title:C().optional(),description:C().optional(),minLength:ce().optional(),maxLength:ce().optional(),format:Ct(["email","uri","date","date-time"]).optional(),default:C().optional()}),nI=A({type:Ct(["number","integer"]),title:C().optional(),description:C().optional(),minimum:ce().optional(),maximum:ce().optional(),default:ce().optional()}),oI=A({type:k("string"),title:C().optional(),description:C().optional(),enum:re(C()),default:C().optional()}),rI=A({type:k("string"),title:C().optional(),description:C().optional(),oneOf:re(A({const:C(),title:C()})),default:C().optional()}),iI=A({type:k("string"),title:C().optional(),description:C().optional(),enum:re(C()),enumNames:re(C()).optional(),default:C().optional()}),sI=fe([oI,rI]),aI=A({type:k("array"),title:C().optional(),description:C().optional(),minItems:ce().optional(),maxItems:ce().optional(),items:A({type:k("string"),enum:re(C())}),default:re(C()).optional()}),cI=A({type:k("array"),title:C().optional(),description:C().optional(),minItems:ce().optional(),maxItems:ce().optional(),items:A({anyOf:re(A({const:C(),title:C()}))}),default:re(C()).optional()}),lI=fe([aI,cI]),uI=fe([iI,sI,lI]),dI=fe([uI,eI,tI,nI]),pI=Ii.extend({mode:k("form").optional(),message:C(),requestedSchema:A({type:k("object"),properties:Ee(C(),dI),required:re(C()).optional()})}),mI=Ii.extend({mode:k("url"),message:C(),elicitationId:C(),url:C().url()}),fI=fe([pI,mI]),hI=mt.extend({method:k("elicitation/create"),params:fI}),gI=qt.extend({elicitationId:C()}),vI=Wt.extend({method:k("notifications/elicitation/complete"),params:gI}),yI=ft.extend({action:Ct(["accept","decline","cancel"]),content:Wl((e)=>e===null?void 0:e,Ee(C(),fe([C(),ce(),Ne(),re(C())])).optional())}),bI=A({type:k("ref/resource"),uri:C()});var xI=A({type:k("ref/prompt"),name:C()}),wI=Lt.extend({ref:fe([xI,bI]),argument:A({name:C(),value:C()}),context:A({arguments:Ee(C(),C()).optional()}).optional()}),_I=mt.extend({method:k("completion/complete"),params:wI});var SI=ft.extend({completion:kt({values:re(C()).max(100),total:We(ce().int()),hasMore:We(Ne())})}),kI=A({uri:C().startsWith("file://"),name:C().optional(),_meta:Ee(C(),ze()).optional()}),CI=mt.extend({method:k("roots/list"),params:Lt.optional()}),TI=ft.extend({roots:re(kI)}),II=Wt.extend({method:k("notifications/roots/list_changed"),params:qt.optional()}),BM=fe([Mo,mT,_I,jT,RT,pd,sd,ad,ud,CT,IT,nc,tc,Wa,Ga,Xa,Ja]),HM=fe([Za,Ua,gT,II,$i]),jM=fe([rd,YT,QT,yI,TI,Va,Ka,qa]),ZM=fe([Mo,JT,hI,CI,Wa,Ga,Xa,Ja]),UM=fe([Za,Ua,wd,AT,dd,xd,bd,$i,vI]),qM=fe([rd,hT,SI,OT,md,Ya,cd,Qa,Oo,FT,Va,Ka,qa]);class be extends Error{constructor(e,t,n){super(`MCP error ${e}: ${t}`);this.code=e,this.data=n,this.name="McpError"}static fromError(e,t,n){if(e===Te.UrlElicitationRequired&&n){let o=n;if(o.elicitations)return new Gb(o.elicitations,t)}return new be(e,t,n)}}class Gb extends be{constructor(e,t=`URL elicitation${e.length>1?"s":""} required`){super(Te.UrlElicitationRequired,t,{elicitations:e})}get elicitations(){return this.data?.elicitations??[]}}function oc(e){return!!e._zod}function rc(e,t){if(oc(e))return Qr(e,t);return e.safeParse(t)}function Xb(e){if(!e)return;let t;if(oc(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 Kb(e){if(oc(e)){let s=e._zod?.def;if(s){if(s.value!==void 0)return s.value;if(Array.isArray(s.values)&&s.values.length>0)return s.values[0]}}let n=e._def;if(n){if(n.value!==void 0)return n.value;if(Array.isArray(n.values)&&n.values.length>0)return n.values[0]}let o=e.value;if(o!==void 0)return o;return}function eo(e){return e==="completed"||e==="failed"||e==="cancelled"}var EI=Symbol("Let zodToJsonSchema decide on which parser to use");var LO=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function _d(e){let n=Xb(e)?.method;if(!n)throw Error("Schema is missing a method literal");let o=Kb(n);if(typeof o!=="string")throw Error("Schema method literal must be a string");return o}function Sd(e,t){let n=rc(e,t);if(!n.success)throw n.error;return n.data}var $I=60000;class ic{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(Za,(t)=>{this._oncancel(t)}),this.setNotificationHandler(Ua,(t)=>{this._onprogress(t)}),this.setRequestHandler(Mo,(t)=>({})),this._taskStore=e?.taskStore,this._taskMessageQueue=e?.taskMessageQueue,this._taskStore)this.setRequestHandler(Wa,async(t,n)=>{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new be(Te.InvalidParams,"Failed to retrieve task: Task not found");return{...o}}),this.setRequestHandler(Ga,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 be(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 be(Te.InvalidParams,`Task not found: ${r}`);if(!eo(s.status))return await this._waitForTaskUpdate(r,n.signal),await o();if(eo(s.status)){let a=await this._taskStore.getTaskResult(r,n.sessionId);return this._clearTaskQueue(r),{...a,_meta:{...a._meta,[Qn]:{taskId:r}}}}return await o()};return await o()}),this.setRequestHandler(Xa,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 be(Te.InvalidParams,`Failed to list tasks: ${o instanceof Error?o.message:String(o)}`)}}),this.setRequestHandler(Ja,async(t,n)=>{try{let o=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!o)throw new be(Te.InvalidParams,`Task not found: ${t.params.taskId}`);if(eo(o.status))throw new be(Te.InvalidParams,`Cannot cancel task in terminal status: ${o.status}`);await this._taskStore.updateTaskStatus(t.params.taskId,"cancelled","Client cancelled task execution.",n.sessionId),this._clearTaskQueue(t.params.taskId);let r=await this._taskStore.getTask(t.params.taskId,n.sessionId);if(!r)throw new be(Te.InvalidParams,`Task not found after cancellation: ${t.params.taskId}`);return{_meta:{},...r}}catch(o){if(o instanceof be)throw o;throw new be(Te.InvalidRequest,`Failed to cancel task: ${o instanceof Error?o.message:String(o)}`)}})}async _oncancel(e){if(!e.params.requestId)return;this._requestHandlerAbortControllers.get(e.params.requestId)?.abort(e.params.reason)}_setupTimeout(e,t,n,o,r=!1){this._timeoutInfo.set(e,{timeoutId:setTimeout(o,t),startTime:Date.now(),timeout:t,maxTotalTimeout:n,resetTimeoutOnProgress:r,onTimeout:o})}_resetTimeout(e){let t=this._timeoutInfo.get(e);if(!t)return!1;let n=Date.now()-t.startTime;if(t.maxTotalTimeout&&n>=t.maxTotalTimeout)throw this._timeoutInfo.delete(e),be.fromError(Te.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:t.maxTotalTimeout,totalElapsed:n});return clearTimeout(t.timeoutId),t.timeoutId=setTimeout(t.onTimeout,t.timeout),!0}_cleanupTimeout(e){let t=this._timeoutInfo.get(e);if(t)clearTimeout(t.timeoutId),this._timeoutInfo.delete(e)}async connect(e){if(this._transport)throw Error("Already connected to a transport. Call close() before connecting to a new transport, or use a separate Protocol instance per connection.");this._transport=e;let t=this.transport?.onclose;this._transport.onclose=()=>{t?.(),this._onclose()};let n=this.transport?.onerror;this._transport.onerror=(r)=>{n?.(r),this._onerror(r)};let o=this._transport?.onmessage;this._transport.onmessage=(r,s)=>{if(o?.(r,s),Ei(r)||Bb(r))this._onresponse(r);else if(td(r))this._onrequest(r,s);else if(Fb(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=be.fromError(Te.ConnectionClosed,"Connection closed");this._transport=void 0,this.onclose?.();for(let n of e.values())n(t)}_onerror(e){this.onerror?.(e)}_onnotification(e){let t=this._notificationHandlers.get(e.method)??this.fallbackNotificationHandler;if(t===void 0)return;Promise.resolve().then(()=>t(e)).catch((n)=>this._onerror(Error(`Uncaught error in notification handler: ${n}`)))}_onrequest(e,t){let n=this._requestHandlers.get(e.method)??this.fallbackRequestHandler,o=this._transport,r=e.params?._meta?.[Qn]?.taskId;if(n===void 0){let u={jsonrpc:"2.0",id:e.id,error:{code:Te.MethodNotFound,message:"Method not found"}};if(r&&this._taskMessageQueue)this._enqueueTaskMessage(r,{type:"error",message:u,timestamp:Date.now()},o?.sessionId).catch((p)=>this._onerror(Error(`Failed to enqueue error response: ${p}`)));else o?.send(u).catch((p)=>this._onerror(Error(`Failed to send an error response: ${p}`)));return}let s=new AbortController;this._requestHandlerAbortControllers.set(e.id,s);let a=Ob(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 be(Te.ConnectionClosed,"Request was cancelled");let f={...d,relatedRequestId:e.id};if(r&&!f.relatedTask)f.relatedTask={taskId:r};let m=f.relatedTask?.taskId??r;if(m&&c)await c.updateTaskStatus(m,"input_required");return await this.request(u,p,f)},authInfo:t?.authInfo,requestId:e.id,requestInfo:t?.requestInfo,taskId:r,taskStore:c,taskRequestedTtl:a?.ttl,closeSSEStream:t?.closeSSEStream,closeStandaloneSSEStream:t?.closeStandaloneSSEStream};Promise.resolve().then(()=>{if(a)this.assertTaskHandlerCapability(e.method)}).then(()=>n(e,l)).then(async(u)=>{if(s.signal.aborted)return;let p={result:u,jsonrpc:"2.0",id:e.id};if(r&&this._taskMessageQueue)await this._enqueueTaskMessage(r,{type:"response",message:p,timestamp:Date.now()},o?.sessionId);else await o?.send(p)},async(u)=>{if(s.signal.aborted)return;let p={jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(u.code)?u.code:Te.InternalError,message:u.message??"Internal error",...u.data!==void 0&&{data:u.data}}};if(r&&this._taskMessageQueue)await this._enqueueTaskMessage(r,{type:"error",message:p,timestamp:Date.now()},o?.sessionId);else await o?.send(p)}).catch((u)=>this._onerror(Error(`Failed to send response: ${u}`))).finally(()=>{if(this._requestHandlerAbortControllers.get(e.id)===s)this._requestHandlerAbortControllers.delete(e.id)})}_onprogress(e){let{progressToken:t,...n}=e.params,o=Number(t),r=this._progressHandlers.get(o);if(!r){this._onerror(Error(`Received a progress notification for an unknown token: ${JSON.stringify(e)}`));return}let s=this._responseHandlers.get(o),a=this._timeoutInfo.get(o);if(a&&s&&a.resetTimeoutOnProgress)try{this._resetTimeout(o)}catch(c){this._responseHandlers.delete(o),this._progressHandlers.delete(o),this._cleanupTimeout(o),s(c);return}r(n)}_onresponse(e){let t=Number(e.id),n=this._requestResolvers.get(t);if(n){if(this._requestResolvers.delete(t),Ei(e))n(e);else{let s=new be(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(Ei(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(Ei(e))o(e);else{let s=be.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 be?s:new be(Te.InternalError,String(s))}}return}let r;try{let s=await this.request(e,qa,n);if(s.task)r=s.task.taskId,yield{type:"taskCreated",task:s.task};else throw new be(Te.InternalError,"Task creation did not return a task");while(!0){let a=await this.getTask({taskId:r},n);if(yield{type:"taskStatus",task:a},eo(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 be(Te.InternalError,`Task ${r} failed`)};else if(a.status==="cancelled")yield{type:"error",error:new be(Te.InternalError,`Task ${r} was cancelled`)};return}if(a.status==="input_required"){yield{type:"result",result:await this.getTaskResult({taskId:r},t,n)};return}let c=a.pollInterval??this._options?.defaultTaskPollInterval??1000;await new Promise((l)=>setTimeout(l,c)),n?.signal?.throwIfAborted()}}catch(s){yield{type:"error",error:s instanceof be?s:new be(Te.InternalError,String(s))}}}request(e,t,n){let{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s,task:a,relatedTask:c}=n??{};return new Promise((l,u)=>{let p=(g)=>{u(g)};if(!this._transport){p(Error("Not connected"));return}if(this._options?.enforceStrictCapabilities===!0)try{if(this.assertCapabilityForMethod(e.method),a)this.assertTaskCapability(e.method)}catch(g){p(g);return}n?.signal?.throwIfAborted();let d=this._requestMessageId++,f={...e,jsonrpc:"2.0",id:d};if(n?.onprogress)this._progressHandlers.set(d,n.onprogress),f.params={...e.params,_meta:{...e.params?._meta||{},progressToken:d}};if(a)f.params={...f.params,task:a};if(c)f.params={...f.params,_meta:{...f.params?._meta||{},[Qn]:c}};let m=(g)=>{this._responseHandlers.delete(d),this._progressHandlers.delete(d),this._cleanupTimeout(d),this._transport?.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:d,reason:String(g)}},{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s}).catch((E)=>this._onerror(Error(`Failed to send cancellation: ${E}`)));let y=g instanceof be?g:new be(Te.RequestTimeout,String(g));u(y)};this._responseHandlers.set(d,(g)=>{if(n?.signal?.aborted)return;if(g instanceof Error)return u(g);try{let y=rc(t,g.result);if(!y.success)u(y.error);else l(y.data)}catch(y){u(y)}}),n?.signal?.addEventListener("abort",()=>{m(n?.signal?.reason)});let h=n?.timeout??$I,v=()=>m(be.fromError(Te.RequestTimeout,"Request timed out",{timeout:h}));this._setupTimeout(d,h,n?.maxTotalTimeout,v,n?.resetTimeoutOnProgress??!1);let x=c?.taskId;if(x){let g=(y)=>{let E=this._responseHandlers.get(d);if(E)E(y);else this._onerror(Error(`Response handler missing for side-channeled request ${d}`))};this._requestResolvers.set(d,g),this._enqueueTaskMessage(x,{type:"request",message:f,timestamp:Date.now()}).catch((y)=>{this._cleanupTimeout(d),u(y)})}else this._transport.send(f,{relatedRequestId:o,resumptionToken:r,onresumptiontoken:s}).catch((g)=>{this._cleanupTimeout(d),u(g)})})}async getTask(e,t){return this.request({method:"tasks/get",params:e},Va,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},Ka,t)}async cancelTask(e,t){return this.request({method:"tasks/cancel",params:e},jb,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||{},[Qn]: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||{},[Qn]: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||{},[Qn]:t.relatedTask}}};await this._transport.send(s,t)}setRequestHandler(e,t){let n=_d(e);this.assertRequestHandlerCapability(n),this._requestHandlers.set(n,(o,r)=>{let s=Sd(e,o);return Promise.resolve(t(s,r))})}removeRequestHandler(e){this._requestHandlers.delete(e)}assertCanSetRequestHandler(e){if(this._requestHandlers.has(e))throw Error(`A request handler for ${e} already exists, which would be overridden`)}setNotificationHandler(e,t){let n=_d(e);this._notificationHandlers.set(n,(o)=>{let r=Sd(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"&&td(o.message)){let r=o.message.id,s=this._requestResolvers.get(r);if(s)s(new be(Te.InternalError,"Task cancelled or completed")),this._requestResolvers.delete(r);else this._onerror(Error(`Resolver missing for request ${r} during task ${e} cleanup`))}}}async _waitForTaskUpdate(e,t){let n=this._options?.defaultTaskPollInterval??1000;try{let o=await this._taskStore?.getTask(e);if(o?.pollInterval)n=o.pollInterval}catch{}return new Promise((o,r)=>{if(t.aborted){r(new be(Te.InvalidRequest,"Request cancelled"));return}let s=setTimeout(o,n);t.addEventListener("abort",()=>{clearTimeout(s),r(new be(Te.InvalidRequest,"Request cancelled"))},{once:!0})})}requestTaskStore(e,t){let n=this._taskStore;if(!n)throw Error("No task store configured");return{createTask:async(o)=>{if(!e)throw Error("No request provided");return await n.createTask(o,e.id,{method:e.method,params:e.params},t)},getTask:async(o)=>{let r=await n.getTask(o,t);if(!r)throw new be(Te.InvalidParams,"Failed to retrieve task: Task not found");return r},storeTaskResult:async(o,r,s)=>{await n.storeTaskResult(o,r,s,t);let a=await n.getTask(o,t);if(a){let c=$i.parse({method:"notifications/tasks/status",params:a});if(await this.notification(c),eo(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 be(Te.InvalidParams,`Task "${o}" not found - it may have been cleaned up`);if(eo(a.status))throw new be(Te.InvalidParams,`Cannot update task "${o}" from terminal status "${a.status}" to "${r}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);await n.updateTaskStatus(o,r,s,t);let c=await n.getTask(o,t);if(c){let l=$i.parse({method:"notifications/tasks/status",params:c});if(await this.notification(l),eo(c.status))this._cleanupTaskProgressHandler(o)}},listTasks:(o)=>n.listTasks(o,t)}}}var Qb="2026-01-26";var MI="ui/notifications/tool-input-partial";var OI=fe([k("light"),k("dark")]).describe("Color theme preference for the host environment."),Li=fe([k("inline"),k("fullscreen"),k("pip")]).describe("Display mode for UI presentation."),LI=fe([k("--color-background-primary"),k("--color-background-secondary"),k("--color-background-tertiary"),k("--color-background-inverse"),k("--color-background-ghost"),k("--color-background-info"),k("--color-background-danger"),k("--color-background-success"),k("--color-background-warning"),k("--color-background-disabled"),k("--color-text-primary"),k("--color-text-secondary"),k("--color-text-tertiary"),k("--color-text-inverse"),k("--color-text-ghost"),k("--color-text-info"),k("--color-text-danger"),k("--color-text-success"),k("--color-text-warning"),k("--color-text-disabled"),k("--color-border-primary"),k("--color-border-secondary"),k("--color-border-tertiary"),k("--color-border-inverse"),k("--color-border-ghost"),k("--color-border-info"),k("--color-border-danger"),k("--color-border-success"),k("--color-border-warning"),k("--color-border-disabled"),k("--color-ring-primary"),k("--color-ring-secondary"),k("--color-ring-inverse"),k("--color-ring-info"),k("--color-ring-danger"),k("--color-ring-success"),k("--color-ring-warning"),k("--font-sans"),k("--font-mono"),k("--font-weight-normal"),k("--font-weight-medium"),k("--font-weight-semibold"),k("--font-weight-bold"),k("--font-text-xs-size"),k("--font-text-sm-size"),k("--font-text-md-size"),k("--font-text-lg-size"),k("--font-heading-xs-size"),k("--font-heading-sm-size"),k("--font-heading-md-size"),k("--font-heading-lg-size"),k("--font-heading-xl-size"),k("--font-heading-2xl-size"),k("--font-heading-3xl-size"),k("--font-text-xs-line-height"),k("--font-text-sm-line-height"),k("--font-text-md-line-height"),k("--font-text-lg-line-height"),k("--font-heading-xs-line-height"),k("--font-heading-sm-line-height"),k("--font-heading-md-line-height"),k("--font-heading-lg-line-height"),k("--font-heading-xl-line-height"),k("--font-heading-2xl-line-height"),k("--font-heading-3xl-line-height"),k("--border-radius-xs"),k("--border-radius-sm"),k("--border-radius-md"),k("--border-radius-lg"),k("--border-radius-xl"),k("--border-radius-full"),k("--border-width-regular"),k("--shadow-hairline"),k("--shadow-sm"),k("--shadow-md"),k("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."),DI=Ee(LI.describe(`Style variables for theming MCP apps.
151
166
 
152
167
  Individual style keys are optional - hosts may provide any subset of these values.
153
168
  Values are strings containing CSS values (colors, sizes, font stacks, etc.).
154
169
 
155
170
  Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
156
- for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),ue([S(),bl()]).describe(`Style variables for theming MCP apps.
171
+ for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),fe([C(),jl()]).describe(`Style variables for theming MCP apps.
157
172
 
158
173
  Individual style keys are optional - hosts may provide any subset of these values.
159
174
  Values are strings containing CSS values (colors, sizes, font stacks, etc.).
@@ -165,10 +180,10 @@ Individual style keys are optional - hosts may provide any subset of these value
165
180
  Values are strings containing CSS values (colors, sizes, font stacks, etc.).
166
181
 
167
182
  Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
168
- for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),jT=k({method:w("ui/open-link"),params:k({url:S().describe("URL to open in the host's browser")})}),x2=k({isError:ze().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),b2=k({isError:ze().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),w2=k({isError:ze().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),ZT=k({method:w("ui/notifications/sandbox-proxy-ready"),params:k({})}),nd=k({connectDomains:re(S()).optional().describe(`Origins for network requests (fetch/XHR/WebSocket).
183
+ for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),FI=A({method:k("ui/open-link"),params:A({url:C().describe("URL to open in the host's browser")})}),F2=A({isError:Ne().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),B2=A({isError:Ne().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),H2=A({isError:Ne().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),BI=A({method:k("ui/notifications/sandbox-proxy-ready"),params:A({})}),kd=A({connectDomains:re(C()).optional().describe(`Origins for network requests (fetch/XHR/WebSocket).
169
184
 
170
185
  - Maps to CSP \`connect-src\` directive
171
- - Empty or omitted → no network connections (secure default)`),resourceDomains:re(S()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"),frameDomains:re(S()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"),baseUriDomains:re(S()).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'`)")}),od=k({camera:k({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:k({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:k({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:k({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),HT=k({method:w("ui/notifications/size-changed"),params:k({width:ae().optional().describe("New width in pixels."),height:ae().optional().describe("New height in pixels.")})}),_2=k({method:w("ui/notifications/tool-input"),params:k({arguments:ke(S(),Ee().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),S2=k({method:w("ui/notifications/tool-input-partial"),params:k({arguments:ke(S(),Ee().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),k2=k({method:w("ui/notifications/tool-cancelled"),params:k({reason:S().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),BT=k({fonts:S().optional()}),UT=k({variables:FT.optional().describe("CSS variables for theming the app."),css:BT.optional().describe("CSS blocks that apps can inject.")}),C2=k({method:w("ui/resource-teardown"),params:k({})}),WT=ke(S(),Ee()),lx=k({text:k({}).optional().describe("Host supports text content blocks."),image:k({}).optional().describe("Host supports image content blocks."),audio:k({}).optional().describe("Host supports audio content blocks."),resource:k({}).optional().describe("Host supports resource content blocks."),resourceLink:k({}).optional().describe("Host supports resource link content blocks."),structuredContent:k({}).optional().describe("Host supports structured content.")}),qT=k({method:w("ui/notifications/request-teardown"),params:k({}).optional()}),VT=k({experimental:k({}).optional().describe("Experimental features (structure TBD)."),openLinks:k({}).optional().describe("Host supports opening external URLs."),downloadFile:k({}).optional().describe("Host supports file downloads via ui/download-file."),serverTools:k({listChanged:ze().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:k({listChanged:ze().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:k({}).optional().describe("Host accepts log messages."),sandbox:k({permissions:od.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:nd.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:lx.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:lx.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),GT=k({experimental:k({}).optional().describe("Experimental features (structure TBD)."),tools:k({listChanged:ze().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:re(_i).optional().describe("Display modes the app supports.")}),XT=k({method:w("ui/notifications/initialized"),params:k({}).optional()}),T2=k({csp:nd.optional().describe("Content Security Policy configuration for UI resources."),permissions:od.optional().describe("Sandbox permissions requested by the UI resource."),domain:S().optional().describe(`Dedicated origin for view sandbox.
186
+ - Empty or omitted → no network connections (secure default)`),resourceDomains:re(C()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"),frameDomains:re(C()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"),baseUriDomains:re(C()).optional().describe("Allowed base URIs for the document.\n\n- Maps to CSP `base-uri` directive\n- Empty or omitted → only same origin allowed (`base-uri 'self'`)")}),Cd=A({camera:A({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:A({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:A({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:A({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),HI=A({method:k("ui/notifications/size-changed"),params:A({width:ce().optional().describe("New width in pixels."),height:ce().optional().describe("New height in pixels.")})}),j2=A({method:k("ui/notifications/tool-input"),params:A({arguments:Ee(C(),ze().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),Z2=A({method:k("ui/notifications/tool-input-partial"),params:A({arguments:Ee(C(),ze().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),U2=A({method:k("ui/notifications/tool-cancelled"),params:A({reason:C().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),jI=A({fonts:C().optional()}),ZI=A({variables:DI.optional().describe("CSS variables for theming the app."),css:jI.optional().describe("CSS blocks that apps can inject.")}),q2=A({method:k("ui/resource-teardown"),params:A({})}),UI=Ee(C(),ze()),Jb=A({text:A({}).optional().describe("Host supports text content blocks."),image:A({}).optional().describe("Host supports image content blocks."),audio:A({}).optional().describe("Host supports audio content blocks."),resource:A({}).optional().describe("Host supports resource content blocks."),resourceLink:A({}).optional().describe("Host supports resource link content blocks."),structuredContent:A({}).optional().describe("Host supports structured content.")}),qI=A({method:k("ui/notifications/request-teardown"),params:A({}).optional()}),WI=A({experimental:A({}).optional().describe("Experimental features (structure TBD)."),openLinks:A({}).optional().describe("Host supports opening external URLs."),downloadFile:A({}).optional().describe("Host supports file downloads via ui/download-file."),serverTools:A({listChanged:Ne().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:A({listChanged:Ne().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:A({}).optional().describe("Host accepts log messages."),sandbox:A({permissions:Cd.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:kd.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:Jb.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:Jb.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),VI=A({experimental:A({}).optional().describe("Experimental features (structure TBD)."),tools:A({listChanged:Ne().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:re(Li).optional().describe("Display modes the app supports.")}),GI=A({method:k("ui/notifications/initialized"),params:A({}).optional()}),W2=A({csp:kd.optional().describe("Content Security Policy configuration for UI resources."),permissions:Cd.optional().describe("Sandbox permissions requested by the UI resource."),domain:C().optional().describe(`Dedicated origin for view sandbox.
172
187
 
173
188
  Useful when views need stable, dedicated origins for OAuth callbacks, CORS policies, or API key allowlists.
174
189
 
@@ -176,16 +191,16 @@ Useful when views need stable, dedicated origins for OAuth callbacks, CORS polic
176
191
  - Hash-based subdomains (e.g., \`{hash}.claudemcpcontent.com\`)
177
192
  - URL-derived subdomains (e.g., \`www-example-com.oaiusercontent.com\`)
178
193
 
179
- If omitted, host uses default sandbox origin (typically per-conversation).`),prefersBorder:ze().optional().describe(`Visual boundary preference - true if view prefers a visible border.
194
+ If omitted, host uses default sandbox origin (typically per-conversation).`),prefersBorder:Ne().optional().describe(`Visual boundary preference - true if view prefers a visible border.
180
195
 
181
196
  Boolean requesting whether a visible border and background is provided by the host. Specifying an explicit value for this is recommended because hosts' defaults may vary.
182
197
 
183
198
  - \`true\`: request visible border + background
184
199
  - \`false\`: request no visible border + background
185
- - omitted: host decides border`)}),ux=k({method:w("ui/request-display-mode"),params:k({mode:_i.describe("The display mode being requested.")})}),E2=k({mode:_i.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),KT=ue([w("model"),w("app")]).describe("Tool visibility scope - who can access the tool."),A2=k({resourceUri:S().optional(),visibility:re(KT).optional().describe(`Who can access this tool. Default: ["model", "app"]
200
+ - omitted: host decides border`)}),Yb=A({method:k("ui/request-display-mode"),params:A({mode:Li.describe("The display mode being requested.")})}),V2=A({mode:Li.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),XI=fe([k("model"),k("app")]).describe("Tool visibility scope - who can access the tool."),G2=A({resourceUri:C().optional(),visibility:re(XI).optional().describe(`Who can access this tool. Default: ["model", "app"]
186
201
  - "model": Tool visible to and callable by the agent
187
- - "app": Tool callable by the app from this server only`)}),I2=k({mimeTypes:re(S()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),JT=k({method:w("ui/download-file"),params:k({contents:re(ue([Xu,Ku])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),YT=k({method:w("ui/message"),params:k({role:w("user").describe('Message role, currently only "user" is supported.'),content:re(yr).describe("Message content blocks (text, image, etc.).")})}),z2=k({method:w("ui/notifications/sandbox-resource-ready"),params:k({html:S().describe("HTML content to load into the inner iframe."),sandbox:S().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:nd.optional().describe("CSP configuration from resource metadata."),permissions:od.optional().describe("Sandbox permissions from resource metadata.")})}),P2=k({method:w("ui/notifications/tool-result"),params:Co.describe("Standard MCP tool execution result.")}),px=k({toolInfo:k({id:gr.optional().describe("JSON-RPC id of the tools/call request."),tool:Ra.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:LT.optional().describe("Current color theme preference."),styles:UT.optional().describe("Style configuration for theming the app."),displayMode:_i.optional().describe("How the UI is currently displayed."),availableDisplayModes:re(_i).optional().describe("Display modes the host supports."),containerDimensions:ue([k({height:ae().describe("Fixed container height in pixels.")}),k({maxHeight:ue([ae(),bl()]).optional().describe("Maximum container height in pixels.")})]).and(ue([k({width:ae().describe("Fixed container width in pixels.")}),k({maxWidth:ue([ae(),bl()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
188
- container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:S().optional().describe("User's language and region preference in BCP 47 format."),timeZone:S().optional().describe("User's timezone in IANA format."),userAgent:S().optional().describe("Host application identifier."),platform:ue([w("web"),w("desktop"),w("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:k({touch:ze().optional().describe("Whether the device supports touch input."),hover:ze().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:k({top:ae().describe("Top safe area inset in pixels."),right:ae().describe("Right safe area inset in pixels."),bottom:ae().describe("Bottom safe area inset in pixels."),left:ae().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),N2=k({method:w("ui/notifications/host-context-changed"),params:px.describe("Partial context update containing only changed fields.")}),QT=k({method:w("ui/update-model-context"),params:k({content:re(yr).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:ke(S(),Ee().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),eE=k({method:w("ui/initialize"),params:k({appInfo:hi.describe("App identification (name and version)."),appCapabilities:GT.describe("Features and capabilities this app provides."),protocolVersion:S().describe("Protocol version this app supports.")})}),R2=k({protocolVersion:S().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:hi.describe("Host application identification and version."),hostCapabilities:VT.describe("Features and capabilities provided by the host."),hostContext:px.describe("Rich context about the host environment.")}).passthrough();class rd{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=Qy.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!==OT)console.debug("Sending message",e);this.eventTarget.postMessage(e,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}function mx(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 tE=[dx];class id extends Da{_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(eE,(r)=>this._oninitialize(r)),this.setRequestHandler(ko,(r,s)=>(this.onping?.(r.params,s),{})),this.setRequestHandler(ux,(r)=>({mode:this._hostContext.displayMode??"inline"}))}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;set onsizechange(e){this.setNotificationHandler(HT,(t)=>e(t.params))}set onsandboxready(e){this.setNotificationHandler(ZT,(t)=>e(t.params))}set oninitialized(e){this.setNotificationHandler(XT,(t)=>e(t.params))}set onmessage(e){this.setRequestHandler(YT,async(t,n)=>e(t.params,n))}set onopenlink(e){this.setRequestHandler(jT,async(t,n)=>e(t.params,n))}set ondownloadfile(e){this.setRequestHandler(JT,async(t,n)=>e(t.params,n))}set onrequestteardown(e){this.setNotificationHandler(qT,(t)=>e(t.params))}set onrequestdisplaymode(e){this.setRequestHandler(ux,async(t,n)=>e(t.params,n))}set onloggingmessage(e){this.setNotificationHandler(Qu,async(t)=>{e(t.params)})}set onupdatemodelcontext(e){this.setRequestHandler(QT,async(t,n)=>e(t.params,n))}set oncalltool(e){this.setRequestHandler(Ma,async(t,n)=>e(t.params,n))}sendToolListChanged(e={}){return this.notification({method:"notifications/tools/list_changed",params:e})}set onlistresources(e){this.setRequestHandler(Du,async(t,n)=>e(t.params,n))}set onlistresourcetemplates(e){this.setRequestHandler(Fu,async(t,n)=>e(t.params,n))}set onreadresource(e){this.setRequestHandler(Hu,async(t,n)=>e(t.params,n))}sendResourceListChanged(e={}){return this.notification({method:"notifications/resources/list_changed",params:e})}set onlistprompts(e){this.setRequestHandler(Uu,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:tE.includes(t)?t:dx,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(nE(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},WT,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},Co,{signal:o.signal}),t.tools.listChanged)this._client.setNotificationHandler(Yu,(n)=>this.sendToolListChanged(n.params))}if(t.resources){if(this.onlistresources=async(n,o)=>this._client.request({method:"resources/list",params:n},Pa,{signal:o.signal}),this.onlistresourcetemplates=async(n,o)=>this._client.request({method:"resources/templates/list",params:n},ju,{signal:o.signal}),this.onreadresource=async(n,o)=>this._client.request({method:"resources/read",params:n},Na,{signal:o.signal}),t.resources.listChanged)this._client.setNotificationHandler(Bu,(n)=>this.sendResourceListChanged(n.params))}if(t.prompts){if(this.onlistprompts=async(n,o)=>this._client.request({method:"prompts/list",params:n},Wu,{signal:o.signal}),t.prompts.listChanged)this._client.setNotificationHandler(Ju,(n)=>this.sendPromptListChanged(n.params))}}return super.connect(e)}}function nE(e,t){return JSON.stringify(e)===JSON.stringify(t)}function sd(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function oE(e){return sd(e)&&Array.isArray(e.content)&&e.content.every((t)=>sd(t)&&typeof t.type==="string")}function rE(...e){for(let t of e)if(typeof t==="string"){if(t.trim().length>0)return t}return}function iE(e){if(typeof e==="string")return e;if(e===void 0)return;try{return JSON.stringify(e)}catch(t){return console.debug("[ext-app-tool-result] stringify failed",t),String(e)}}function ad(e){let t=e.success===!1;if(oE(e.result))return{...e.result,isError:e.result.isError===!0||t};let n=sd(e.result)?e.result:null,o=rE(e.detailedContent,e.content,n?.detailedContent,n?.content,n?.textResultForLlm,n?.text,n?.message,typeof e.result==="string"?e.result:void 0,e.error)??iE(e.result);return{content:o?[{type:"text",text:o}]:[],isError:t}}function fx(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 hx(e){return Boolean(e)&&typeof e==="object"&&e!==null&&!Array.isArray(e)&&"ok"in e&&typeof e.ok==="boolean"}async function sE(e,t){let n=await fetch("/api/canvas/frame-documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:e,sandbox:t})}),o=await n.json();if(!n.ok||!hx(o)||!o.ok||typeof o.url!=="string"){let r=hx(o)&&o.error?o.error:`Frame document request failed with HTTP ${n.status}`;throw Error(r)}return o.url}function gx(e,t){let n=vt.value,[o,r]=O(null),[s,a]=O(0),c=M(0);D(()=>{if(r(null),!e||n!=="src")return;let u=!1;return c.current=go.value,sE(e,t).then((d)=>{if(!u)r(d)}).catch((d)=>{console.error("[iframe-document] failed to create frame document:",d)}),()=>{u=!0}},[e,t,n,s]);let l=go.value;return D(()=>{if(n!=="src"||l===c.current)return;if(!o){a((d)=>d+1);return}let u=!1;return fetch(o,{method:"HEAD"}).then((d)=>{if(u)return;if(d.ok){c.current=l;return}a((p)=>p+1)}).catch(()=>{}),()=>{u=!0}},[l,o,n]),Ie(()=>{if(n==="srcdoc"&&e)return{attributes:{srcdoc:e},ready:!0,key:`srcdoc-${sr(e)}`};return{attributes:o?{src:o}:{},ready:Boolean(o),key:o??""}},[o,n,e])}function xr(e){let{enabled:t,token:n,nodeId:o,sourceSurface:r,iframeRef:s}=e;D(()=>{if(!t||!n)return;function a(c){if(c.source!==s.current?.contentWindow)return;let l=c.data;if(!l||l.source!==sa||l.token!==n||l.nodeId!==o)return;let u=l.interaction;if(!u||typeof u.type!=="string")return;let d=u.type;Ts({type:d,sourceNodeId:o,sourceSurface:r,...u.payload&&typeof u.payload==="object"?{payload:u.payload}:{}}).then((p)=>{if(p.ok)ir("context","AX interaction",d,[o]);else ir("remove","AX interaction rejected",p.error??p.code??"",[o]);s.current?.contentWindow?.postMessage({source:aa,token:n,...l.correlationId?{correlationId:l.correlationId}:{},interaction:{type:d},result:p},"*")})}return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[t,n,o,r])}async function To(e,t){let o=await(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json();if(!o.ok)throw Error(o.error??`Request failed: ${e}`);return o.result}function Eo(e){return/AppleWebKit/.test(e)&&!/Chrome|Chromium|CriOS|Edg|Android/.test(e)}function aE(e){let{userAgent:t,visibilityState:n,rect:o,viewport:r,alreadyRearmed:s}=e;if(s)return!1;if(!Eo(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 kx=1000,vx=7000;function rt(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});cE({t:Date.now(),nodeId:e,event:t})}var yx=[],cd=null;function cE(e){if(yx.push({...e,...typeof document<"u"?{visibility:document.visibilityState}:{}}),cd)return;cd=setTimeout(()=>{cd=null;let t=yx.splice(0);if(t.length===0)return;fetch("/api/canvas/debug/ext-app-recovery",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entries:t})}).catch(()=>{})},1500)}var xx=Promise.resolve();function bx(e){xx=xx.then(async()=>{if(!e.remount())return;await e.awaitBoot(),await new Promise((t)=>setTimeout(t,kx))}).catch(()=>{})}function lE(e,t){let n=typeof e.data.html==="string"?e.data.html:"",o=typeof e.data.serverName==="string"?e.data.serverName:"",r=typeof e.data.appSessionId==="string"?e.data.appSessionId:"",s=typeof e.data.sessionStatus==="string"?e.data.sessionStatus:"";return`${e.id}:${t}:${o}:${r}:${s}:${n}`}function uE(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 wx(e,t,n){if(await e.sendToolInput({arguments:t}),n)await e.sendToolResult(n)}function dE(e){return typeof e==="string"&&e.trim().length>0?e.trim():xu}function pE(e,t){return`<script data-pmx-canvas-ax-bridge>
202
+ - "app": Tool callable by the app from this server only`)}),X2=A({mimeTypes:re(C()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),KI=A({method:k("ui/download-file"),params:A({contents:re(fe([vd,yd])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),JI=A({method:k("ui/message"),params:A({role:k("user").describe('Message role, currently only "user" is supported.'),content:re(Er).describe("Message content blocks (text, image, etc.).")})}),K2=A({method:k("ui/notifications/sandbox-resource-ready"),params:A({html:C().describe("HTML content to load into the inner iframe."),sandbox:C().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:kd.optional().describe("CSP configuration from resource metadata."),permissions:Cd.optional().describe("Sandbox permissions from resource metadata.")})}),J2=A({method:k("ui/notifications/tool-result"),params:Oo.describe("Standard MCP tool execution result.")}),ex=A({toolInfo:A({id:Tr.optional().describe("JSON-RPC id of the tools/call request."),tool:ec.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:OI.optional().describe("Current color theme preference."),styles:ZI.optional().describe("Style configuration for theming the app."),displayMode:Li.optional().describe("How the UI is currently displayed."),availableDisplayModes:re(Li).optional().describe("Display modes the host supports."),containerDimensions:fe([A({height:ce().describe("Fixed container height in pixels.")}),A({maxHeight:fe([ce(),jl()]).optional().describe("Maximum container height in pixels.")})]).and(fe([A({width:ce().describe("Fixed container width in pixels.")}),A({maxWidth:fe([ce(),jl()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
203
+ container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:C().optional().describe("User's language and region preference in BCP 47 format."),timeZone:C().optional().describe("User's timezone in IANA format."),userAgent:C().optional().describe("Host application identifier."),platform:fe([k("web"),k("desktop"),k("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:A({touch:Ne().optional().describe("Whether the device supports touch input."),hover:Ne().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:A({top:ce().describe("Top safe area inset in pixels."),right:ce().describe("Right safe area inset in pixels."),bottom:ce().describe("Bottom safe area inset in pixels."),left:ce().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),Y2=A({method:k("ui/notifications/host-context-changed"),params:ex.describe("Partial context update containing only changed fields.")}),YI=A({method:k("ui/update-model-context"),params:A({content:re(Er).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:Ee(C(),ze().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),QI=A({method:k("ui/initialize"),params:A({appInfo:zi.describe("App identification (name and version)."),appCapabilities:VI.describe("Features and capabilities this app provides."),protocolVersion:C().describe("Protocol version this app supports.")})}),Q2=A({protocolVersion:C().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:zi.describe("Host application identification and version."),hostCapabilities:WI.describe("Features and capabilities provided by the host."),hostContext:ex.describe("Rich context about the host environment.")}).passthrough();class Td{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=Hb.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!==MI)console.debug("Sending message",e);this.eventTarget.postMessage(e,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}function tx(e){if(!e)return"";let t=[];if(e.camera)t.push("camera");if(e.microphone)t.push("microphone");if(e.geolocation)t.push("geolocation");if(e.clipboardWrite)t.push("clipboard-write");return t.join("; ")}var eE=[Qb];class Id extends ic{_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(QI,(r)=>this._oninitialize(r)),this.setRequestHandler(Mo,(r,s)=>(this.onping?.(r.params,s),{})),this.setRequestHandler(Yb,(r)=>({mode:this._hostContext.displayMode??"inline"}))}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;set onsizechange(e){this.setNotificationHandler(HI,(t)=>e(t.params))}set onsandboxready(e){this.setNotificationHandler(BI,(t)=>e(t.params))}set oninitialized(e){this.setNotificationHandler(GI,(t)=>e(t.params))}set onmessage(e){this.setRequestHandler(JI,async(t,n)=>e(t.params,n))}set onopenlink(e){this.setRequestHandler(FI,async(t,n)=>e(t.params,n))}set ondownloadfile(e){this.setRequestHandler(KI,async(t,n)=>e(t.params,n))}set onrequestteardown(e){this.setNotificationHandler(qI,(t)=>e(t.params))}set onrequestdisplaymode(e){this.setRequestHandler(Yb,async(t,n)=>e(t.params,n))}set onloggingmessage(e){this.setNotificationHandler(wd,async(t)=>{e(t.params)})}set onupdatemodelcontext(e){this.setRequestHandler(YI,async(t,n)=>e(t.params,n))}set oncalltool(e){this.setRequestHandler(nc,async(t,n)=>e(t.params,n))}sendToolListChanged(e={}){return this.notification({method:"notifications/tools/list_changed",params:e})}set onlistresources(e){this.setRequestHandler(sd,async(t,n)=>e(t.params,n))}set onlistresourcetemplates(e){this.setRequestHandler(ad,async(t,n)=>e(t.params,n))}set onreadresource(e){this.setRequestHandler(ud,async(t,n)=>e(t.params,n))}sendResourceListChanged(e={}){return this.notification({method:"notifications/resources/list_changed",params:e})}set onlistprompts(e){this.setRequestHandler(pd,async(t,n)=>e(t.params,n))}sendPromptListChanged(e={}){return this.notification({method:"notifications/prompts/list_changed",params:e})}assertCapabilityForMethod(e){}assertRequestHandlerCapability(e){}assertNotificationCapability(e){}assertTaskCapability(e){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(e){throw Error("Task handlers are not supported in MCP Apps")}getCapabilities(){return this._capabilities}async _oninitialize(e){let t=e.params.protocolVersion;return this._appCapabilities=e.params.appCapabilities,this._appInfo=e.params.appInfo,{protocolVersion:eE.includes(t)?t:Qb,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(tE(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},UI,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},Oo,{signal:o.signal}),t.tools.listChanged)this._client.setNotificationHandler(xd,(n)=>this.sendToolListChanged(n.params))}if(t.resources){if(this.onlistresources=async(n,o)=>this._client.request({method:"resources/list",params:n},Ya,{signal:o.signal}),this.onlistresourcetemplates=async(n,o)=>this._client.request({method:"resources/templates/list",params:n},cd,{signal:o.signal}),this.onreadresource=async(n,o)=>this._client.request({method:"resources/read",params:n},Qa,{signal:o.signal}),t.resources.listChanged)this._client.setNotificationHandler(dd,(n)=>this.sendResourceListChanged(n.params))}if(t.prompts){if(this.onlistprompts=async(n,o)=>this._client.request({method:"prompts/list",params:n},md,{signal:o.signal}),t.prompts.listChanged)this._client.setNotificationHandler(bd,(n)=>this.sendPromptListChanged(n.params))}}return super.connect(e)}}function tE(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Ed(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function nE(e){return Ed(e)&&Array.isArray(e.content)&&e.content.every((t)=>Ed(t)&&typeof t.type==="string")}function oE(...e){for(let t of e)if(typeof t==="string"){if(t.trim().length>0)return t}return}function rE(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 Ad(e){let t=e.success===!1;if(nE(e.result))return{...e.result,isError:e.result.isError===!0||t};let n=Ed(e.result)?e.result:null,o=oE(e.detailedContent,e.content,n?.detailedContent,n?.content,n?.textResultForLlm,n?.text,n?.message,typeof e.result==="string"?e.result:void 0,e.error)??rE(e.result);return{content:o?[{type:"text",text:o}]:[],isError:t}}function nx(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 ox(e){return Boolean(e)&&typeof e==="object"&&e!==null&&!Array.isArray(e)&&"ok"in e&&typeof e.ok==="boolean"}async function iE(e,t){let n=await fetch("/api/canvas/frame-documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:e,sandbox:t})}),o=await n.json();if(!n.ok||!ox(o)||!o.ok||typeof o.url!=="string"){let r=ox(o)&&o.error?o.error:`Frame document request failed with HTTP ${n.status}`;throw Error(r)}return o.url}function rx(e,t){let n=wt.value,[o,r]=I(null),[s,a]=I(0),c=R(0);B(()=>{if(r(null),!e||n!=="src")return;let u=!1;return c.current=Eo.value,iE(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=Eo.value;return B(()=>{if(n!=="src"||l===c.current)return;if(!o){a((p)=>p+1);return}let u=!1;return fetch(o,{method:"HEAD"}).then((p)=>{if(u)return;if(p.ok){c.current=l;return}a((d)=>d+1)}).catch(()=>{}),()=>{u=!0}},[l,o,n]),Ie(()=>{if(n==="srcdoc"&&e)return{attributes:{srcdoc:e},ready:!0,key:`srcdoc-${gr(e)}`};return{attributes:o?{src:o}:{},ready:Boolean(o),key:o??""}},[o,n,e])}function Ar(e){let{enabled:t,token:n,nodeId:o,sourceSurface:r,iframeRef:s}=e;B(()=>{if(!t||!n)return;function a(c){if(c.source!==s.current?.contentWindow)return;let l=c.data;if(!l||l.source!==Ta||l.token!==n||l.nodeId!==o)return;let u=l.interaction;if(!u||typeof u.type!=="string")return;let p=u.type;Js({type:p,sourceNodeId:o,sourceSurface:r,...u.payload&&typeof u.payload==="object"?{payload:u.payload}:{}}).then((d)=>{if(d.ok)yn("context","AX interaction",p,[o]);s.current?.contentWindow?.postMessage({source:Ia,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 Lo(e,t){let o=await(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json();if(!o.ok)throw Error(o.error??`Request failed: ${e}`);return o.result}function Do(e){return/AppleWebKit/.test(e)&&!/Chrome|Chromium|CriOS|Edg|Android/.test(e)}function sE(e){let{userAgent:t,visibilityState:n,rect:o,viewport:r,alreadyRearmed:s}=e;if(s)return!1;if(!Do(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 px=1000,ix=7000;function at(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});aE({t:Date.now(),nodeId:e,event:t})}var sx=[],zd=null;function aE(e){if(sx.push({...e,...typeof document<"u"?{visibility:document.visibilityState}:{}}),zd)return;zd=setTimeout(()=>{zd=null;let t=sx.splice(0);if(t.length===0)return;fetch("/api/canvas/debug/ext-app-recovery",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entries:t})}).catch(()=>{})},1500)}var ax=Promise.resolve();function cx(e){ax=ax.then(async()=>{if(!e.remount())return;await e.awaitBoot(),await new Promise((t)=>setTimeout(t,px))}).catch(()=>{})}function cE(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 lE(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 lx(e,t,n){if(await e.sendToolInput({arguments:t}),n)await e.sendToolResult(n)}function uE(e){return typeof e==="string"&&e.trim().length>0?e.trim():ju}function dE(e,t){return`<script data-pmx-canvas-ax-bridge>
189
204
  (function () {
190
205
  const PMX_AX_TOKEN = ${JSON.stringify(e)};
191
206
  const PMX_AX_NODE_ID = ${JSON.stringify(t)};
@@ -203,7 +218,7 @@ container holding the app. Specify either width or maxWidth, and either height o
203
218
  }, 10000);
204
219
  pending.set(correlationId, function (result) { clearTimeout(timer); resolve(result); });
205
220
  window.parent.postMessage({
206
- source: '${sa}',
221
+ source: '${Ta}',
207
222
  token: PMX_AX_TOKEN,
208
223
  nodeId: PMX_AX_NODE_ID,
209
224
  correlationId: correlationId,
@@ -216,7 +231,7 @@ container holding the app. Specify either width or maxWidth, and either height o
216
231
  };
217
232
  window.addEventListener('message', function (event) {
218
233
  const m = event.data;
219
- if (!m || m.source !== '${aa}' || m.token !== PMX_AX_TOKEN) return;
234
+ if (!m || m.source !== '${Ia}' || m.token !== PMX_AX_TOKEN) return;
220
235
  const result = m.result || { ok: false };
221
236
  const resolver = m.correlationId ? pending.get(m.correlationId) : undefined;
222
237
  if (resolver) { pending.delete(m.correlationId); resolver(result); }
@@ -226,11 +241,11 @@ container holding the app. Specify either width or maxWidth, and either height o
226
241
  try { window.dispatchEvent(new CustomEvent('pmx-ax-ack', { detail: { result: result, interaction: m.interaction || null } })); } catch (e) {}
227
242
  });
228
243
  })();
229
- </script>`}function mE(e,t){return`<script data-pmx-canvas-boot-beacon>
244
+ </script>`}function pE(e,t){return`<script data-pmx-canvas-boot-beacon>
230
245
  (function () {
231
246
  var TOKEN = ${JSON.stringify(e)};
232
247
  var NODE_ID = ${JSON.stringify(t)};
233
- window.parent.postMessage({ source: '${ca}', token: TOKEN, nodeId: NODE_ID }, '*');
248
+ window.parent.postMessage({ source: '${Ea}', token: TOKEN, nodeId: NODE_ID }, '*');
234
249
  // Paint-tick answers (Finding N): a double rAF only fires when this frame's
235
250
  // rendering pipeline is actually running — a frame whose layer WebKit never
236
251
  // composites stays silent, and that silence drives the parent's recovery
@@ -300,17 +315,17 @@ container holding the app. Specify either width or maxWidth, and either height o
300
315
  requestAnimationFrame(function () {
301
316
  requestAnimationFrame(function () {
302
317
  var v = contentVerdict();
303
- window.parent.postMessage({ source: '${ca}', token: TOKEN, nodeId: NODE_ID, kind: 'paint-tick', content: v.content, detail: v.detail }, '*');
318
+ window.parent.postMessage({ source: '${Ea}', token: TOKEN, nodeId: NODE_ID, kind: 'paint-tick', content: v.content, detail: v.detail }, '*');
304
319
  });
305
320
  });
306
321
  }
307
322
  window.addEventListener('message', function (event) {
308
323
  var m = event.data;
309
- if (m && m.source === '${yu}' && m.token === TOKEN) sendPaintTick();
324
+ if (m && m.source === '${Hu}' && m.token === TOKEN) sendPaintTick();
310
325
  });
311
326
  sendPaintTick();
312
327
  })();
313
- </script>`}function _x(){return"<style data-pmx-canvas-ext-app-base>html, body { background: transparent !important; }</style>"}function Sx(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 br(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 ld(e,t){let n=e?.getBoundingClientRect();return{width:br(e?.clientWidth??0,br(n?.width??0,t.width)),height:br(e?.clientHeight??0,br(n?.height??0,t.height))}}function fE(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>0&&!t}function hE(e,t){return Math.max(br(e,1),br(t,1))}function Cx({node:e,expanded:t=!1}){let n=M(null),o=M(null),r=M(null),s=M(null),a=M({}),c=M(void 0),l=M(!1),u=M(void 0),d=M(null),p=M(!1),f=M(null),m=M(0),v=M([]),y=M(""),x=M(!1),h=M(!1),g=M([]),b=M(!1),E=M(!1),j=M(!1),_=M(!1),[R,A]=O("loading"),[C,Z]=O(null),[F,T]=O(0),[B,W]=O(!1),[H,U]=O(!1),[te,xe]=O(()=>t||typeof navigator>"u"||typeof window>"u"||!Eo(navigator.userAgent)),Fe=e.data.html,qe=e.data.serverName,Te=e.data.appSessionId,oo=e.data.toolInput??{},Zt=e.data.toolResult,Kt=e.data.toolName??"ext-app",I=e.data.toolDefinition,K=e.data.toolCallId,le=typeof K==="string"||typeof K==="number"?K:void 0,Y=e.data.resourceMeta,J=e.data.sessionStatus,Q=e.data.sessionError,ne=e.size.height,q=e.id,ce=lE(e,F),ht=dE(null),P=e.data.axCapabilities?.enabled===!0&&typeof Fe==="string"&&Fe.length>0,se=Ie(()=>`ax-${crypto.randomUUID()}`,[]),Me=P?pE(se,q):"",pe=typeof Fe==="string"&&Fe.length>0?mE(se,q):"",Ht=gx(Sx(Fe??"",_x()+pe+Me),ht);D(()=>{function X(oe){if(oe.source!==n.current?.contentWindow)return;let he=oe.data;if(!he||he.source!==ca||he.token!==se||he.nodeId!==q)return;if(h.current=!0,he.kind==="paint-tick"){let Pe=he,Rt={content:Pe.content===!0,detail:typeof Pe.detail==="string"?Pe.detail:""};for(let En of v.current.splice(0))En(Rt)}}return window.addEventListener("message",X),()=>window.removeEventListener("message",X)},[se,q]),D(()=>{if(te)return;bx({remount:()=>{if(_.current)return!1;return rt(q,"mount-slot"),xe(!0),!0},awaitBoot:()=>new Promise((X)=>{let oe=window.setTimeout(he,vx);function he(){window.clearTimeout(oe),X()}g.current.push(he)})})},[]),xr({enabled:P,token:se,nodeId:q,sourceSurface:"mcp-app",iframeRef:n});let Ri=3,Bt=(X)=>{if(m.current>=Ri)return rt(q,`remount-cap-hit (${X})`),!1;if(b.current)return!0;return m.current+=1,b.current=!0,rt(q,`remount-queued #${m.current} (${X})`),bx({remount:()=>{if(b.current=!1,_.current||!t&&Ue.value===q)return rt(q,"remount-skipped"),W(!1),!1;return E.current=typeof document<"u"&&document.visibilityState==="hidden",rt(q,`remount-run #${m.current}`),A("loading"),T((oe)=>oe+1),!0},awaitBoot:()=>new Promise((oe)=>{let he=window.setTimeout(Pe,vx);function Pe(){window.clearTimeout(he),oe()}g.current.push(Pe)})}),!0},Cn=1500,xc=()=>new Promise((X)=>{let oe=n.current?.contentWindow;if(!oe||_.current){X("timeout");return}let he=!1,Pe=window.setTimeout(()=>{if(he)return;he=!0,X("timeout")},Cn);v.current.push((Rt)=>{if(he)return;he=!0,window.clearTimeout(Pe),y.current=Rt.detail,X(Rt.content?"content-verified":"tick-no-content")}),oe.postMessage({source:yu,token:se},"*")}),Gd=async(X)=>{let oe=Date.now()+X;while(Date.now()<oe&&!_.current){if(await xc()==="content-verified")return!0;await new Promise((he)=>window.setTimeout(he,400))}return!1},Uw=()=>new Promise((X)=>{let oe=n.current;if(!oe){X();return}let he=oe.style.width,Pe=oe.style.height;oe.style.width="140%",oe.style.height="140%",requestAnimationFrame(()=>{requestAnimationFrame(()=>{oe.style.width=he,oe.style.height=Pe,rt(q,"soft-expand-cycle"),X()})})}),Ww=600,$i=()=>{if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;let X=n.current;if(!X||_.current)return;if(!aE({userAgent:navigator.userAgent,visibilityState:document.visibilityState,rect:X.getBoundingClientRect(),viewport:{width:window.innerWidth,height:window.innerHeight},alreadyRearmed:j.current}))return;j.current=!0,window.setTimeout(()=>{if(_.current||document.visibilityState==="visible")return;m.current=0,U(!1),E.current=!1,rt(q,"assume-visible-rearm"),Bt("assume-visible")},Ww)},bc=(X="")=>{let oe=y.current?` [${y.current}]`:"";return typeof document<"u"&&document.visibilityState==="hidden"?`paint-ok (content-verified)${oe}${X} (host hidden)`:`paint-ok (content-verified)${oe}${X}`},qw=async()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Eo(navigator.userAgent))return;W(!0);let X=await xc();if(X==="content-verified"){rt(q,bc()),W(!1),$i();return}if(rt(q,X==="tick-no-content"?`paint-fail (tick without content: ${y.current||"unknown"})`:"paint-fail (no tick)"),await Uw(),X=await xc(),X==="content-verified"){rt(q,bc(" (after soft-expand)")),W(!1),$i();return}if(_.current)return;if(X==="tick-no-content"&&await Gd(3000)){rt(q,bc(" (after content wait)")),W(!1),$i();return}if(_.current)return;if(!Bt("paint-fail"))rt(q,"recovery-exhausted"),W(!1),U(!0),$i()};D(()=>{if(t)return;if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;if(!Eo(navigator.userAgent))return;function X(){if(document.visibilityState!=="visible")return;if(!E.current||_.current)return;E.current=!1,m.current=0,U(!1),rt(q,"visible-again-rearm"),Bt("visible-after-hidden-boot")}return document.addEventListener("visibilitychange",X),()=>document.removeEventListener("visibilitychange",X)},[t,q]);let Vw=6000;D(()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Eo(navigator.userAgent))return;if(!Ht.ready||!te)return;let X=window.setTimeout(()=>{if(x.current||h.current||_.current)return;Bt("boot-watchdog")},Vw);return()=>window.clearTimeout(X)},[ce,Ht.ready,t,te]),D(()=>()=>{_.current=!0;for(let X of g.current.splice(0))X();for(let X of v.current.splice(0))X({content:!1,detail:"unmounted"})},[]);let wc=(X)=>fr(X),Tn=t||Ue.value===q;a.current=oo,c.current=Zt;let Mi=J==="error"&&typeof Fe==="string"&&Fe.length>0,_c=J==="error"?Mi?`Live session unavailable — showing saved content. Reopen the app to restore interactivity.${Q?` (${Q})`:""}`:Q??"Saved app session is unavailable. Reopen the app to restore interactivity.":"Reconnecting saved app session...",Sc=(X)=>{let oe=c.current;if(!X||!p.current||!oe)return null;if(u.current===oe)return null;if(u.current&&fx(u.current,oe))return u.current=oe,null;if(d.current)return d.current;let he=X.sendToolResult(oe).then(()=>{u.current=oe,l.current=!0,A("done")}).catch((Pe)=>{let Rt=Pe instanceof Error?Pe.message:String(Pe);throw Z(`Tool result delivery failed: ${Rt}`),Pe}).finally(()=>{d.current=null});return d.current=he,he};if(D(()=>{if(!Fe||!Ht.ready||!te)return;let X=n.current;if(!X)return;let oe=!1,he=null,Pe=null,Rt=null,En=null,ro=null;l.current=!1,u.current=void 0,d.current=null,p.current=!1,x.current=!1,h.current=!1;let Oi=()=>{if(!he)return;clearTimeout(he),he=null};return(async()=>{if(!Fe)return;let An=X.contentWindow;if(!An)throw Error("Ext-app iframe window is unavailable");let io=(me=Ue.value===q?"fullscreen":"inline")=>({theme:wc(Je.value),platform:"web",containerDimensions:ld(X,{width:e.size.width,height:ne}),displayMode:me,locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,...I?{toolInfo:{id:le,tool:I}}:{}}),Gw=()=>{if(En!==null)return;En=requestAnimationFrame(()=>{if(En=null,oe||!p.current)return;Ne.setHostContext?.(io())})},Xd=()=>{if(ro!==null)return;ro=requestAnimationFrame(()=>{ro=requestAnimationFrame(()=>{if(ro=null,oe||!p.current)return;Ne.sendHostContextChange?.(io())})})},Kd=()=>{if(!Eo(navigator.userAgent))return;if(Pe)clearTimeout(Pe);Pe=setTimeout(()=>{if(Pe=null,oe)return;qw()},kx+200)},Ne=new id(null,{name:"PMX Canvas",version:"1.0.0"},{openLinks:{},serverTools:{listChanged:!1},serverResources:{listChanged:!1},logging:{},updateModelContext:{text:{},structuredContent:{}}},{hostContext:io(Tn?"fullscreen":"inline")});Ne.onsizechange=async({height:me})=>{if(fE(me,Ue.value===q)){let Ye=ld(X.parentElement??X,{width:e.size.width,height:ne}),$t=hE(me,Ye.height);X.style.height=`${$t}px`;let so=N.value.get(q)?.size??e.size,Yd=Math.max(so.height,$t+ur);if(Math.abs(Yd-so.height)>8){if(Os(q,{width:so.width,height:Yd}),s.current!==null)window.clearTimeout(s.current);s.current=window.setTimeout(()=>{ot({recordHistory:!1}),s.current=null},0)}}return{}},Ne.onopenlink=async({url:me})=>(window.open(me,"_blank","noopener"),{}),Ne.onsandboxready=async()=>{await Ne.sendSandboxResourceReady({html:Sx(Fe,_x()),sandbox:xu,...Y?.csp?{csp:Y.csp}:{},...Y?.permissions?{permissions:Y.permissions}:{}})},Ne.onrequestdisplaymode=async({mode:me})=>{let{nextMode:Ye,shouldExpand:$t,shouldCollapse:so}=uE(me,Tn);if($t)en(q);else if(so)xo();return{mode:Ye}},Ne.oncalltool=async(me)=>{if(!Te)throw Error(_c);try{let Ye=await To("/api/ext-app/call-tool",{sessionId:Te,nodeId:q,serverName:qe,toolName:me.name,arguments:me.arguments??{}});return Z(null),Ye}catch(Ye){let $t=Ye instanceof Error?Ye.message:String(Ye);throw Z(`Tool call failed: ${$t}`),Ye}},Ne.setRequestHandler($a,async()=>{if(!Te)return{tools:[]};return To("/api/ext-app/list-tools",{sessionId:Te})}),Ne.onlistresources=async()=>Te?To("/api/ext-app/list-resources",{sessionId:Te}):{resources:[]},Ne.onlistresourcetemplates=async()=>Te?To("/api/ext-app/list-resource-templates",{sessionId:Te}):{resourceTemplates:[]},Ne.onreadresource=async(me)=>{if(!Te)throw Error(_c);return To("/api/ext-app/read-resource",{sessionId:Te,uri:me.uri})},Ne.onlistprompts=async()=>Te?To("/api/ext-app/list-prompts",{sessionId:Te}):{prompts:[]},Ne.onupdatemodelcontext=async(me)=>{if(!Te)return{};return await To("/api/ext-app/model-context",{nodeId:q,...Array.isArray(me.content)?{content:me.content}:{},...me.structuredContent&&typeof me.structuredContent==="object"?{structuredContent:me.structuredContent}:{}}),{}};let kc=new rd(An,An);if(Ne.oninitialized=()=>{if(oe)return;Oi(),p.current=!0,x.current=!0,rt(q,"initialized"),A("ready"),Z(null),Promise.resolve(Ne.sendHostContextChange(io(Tn?"fullscreen":"inline"))).then(()=>wx(Ne,a.current,void 0)).then(()=>Sc(Ne)).then(()=>{let me=()=>{for(let Ye of g.current.splice(0))Ye()};if(typeof navigator<"u"&&Eo(navigator.userAgent))Gd(4000).then((Ye)=>{rt(q,Ye?"settled (content-verified)":`settled (content-timeout${y.current?`: ${y.current}`:""})`),me()});else rt(q,"settled"),me();Xd(),Kd()}).catch((me)=>{let Ye=me instanceof Error?me.message:String(me);Z(`Bridge bootstrap failed: ${Ye}`)})},he=setTimeout(()=>{if(oe||p.current)return;let me=c.current,Ye=io(Tn?"fullscreen":"inline");p.current=!0,Ne.setHostContext?.(Ye),Promise.resolve(Ne.sendHostContextChange(Ye)).then(()=>wx(Ne,a.current,me)).then(()=>{if(l.current=Boolean(me),me)u.current=me;if(A(me?"done":"ready"),Z(null),Xd(),Kd(),h.current){rt(q,"settled (fallback)");for(let $t of g.current.splice(0))$t()}}).catch(($t)=>{let so=$t instanceof Error?$t.message:String($t);Z(`Bridge bootstrap fallback failed: ${so}`)})},1200),await Ne.connect(kc),oe){Oi(),await kc.close();return}if(o.current=Ne,r.current=kc,Rt=new ResizeObserver(Gw),Rt.observe(X),X.parentElement)Rt.observe(X.parentElement);let Jd=!0;f.current=Je.subscribe((me)=>{if(Jd){Jd=!1;return}if(oe)return;Ne.setHostContext?.({...io(),theme:wc(me)}),Ne.sendHostContextChange?.(io())}),Sc(Ne)})().catch((An)=>{Oi(),console.error("[ext-app] Bridge init failed:",An),Z(An?.message??"Bridge initialization failed")}),()=>{if(oe=!0,Oi(),Pe)clearTimeout(Pe),Pe=null;if(Rt?.disconnect(),Rt=null,En!==null)cancelAnimationFrame(En),En=null;if(ro!==null)cancelAnimationFrame(ro),ro=null;if(p.current=!1,d.current=null,f.current?.(),f.current=null,s.current!==null)window.clearTimeout(s.current),s.current=null;if(o.current=null,r.current)r.current.close().catch((An)=>{console.error("[ext-app] transport close failed:",An)}),r.current=null}},[ce,Ht.key,te]),D(()=>{if(Zt&&o.current&&(R==="ready"||R==="done"))Sc(o.current)},[Zt,R]),D(()=>{let X=o.current;if(n.current)n.current.style.height="100%";if(!X||!p.current)return;let oe=null,he=null;return oe=requestAnimationFrame(()=>{oe=null,he=requestAnimationFrame(()=>{if(he=null,!p.current)return;let Pe={theme:wc(Je.value),platform:"web",containerDimensions:ld(n.current,{width:e.size.width,height:ne}),displayMode:Tn?"fullscreen":"inline",locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};X.setHostContext?.(Pe),X.sendHostContextChange?.(Pe)})}),()=>{if(oe!==null)cancelAnimationFrame(oe);if(he!==null)cancelAnimationFrame(he)}},[Tn,ne]),!Fe)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 ",Kt," 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:[J&&J!=="ready"&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:J==="error"&&!Mi?"var(--c-danger-12)":"var(--c-warn-10)",color:J==="error"&&!Mi?"var(--c-danger)":"var(--c-warn)",borderBottom:`1px solid ${J==="error"&&!Mi?"var(--c-danger-12)":"var(--c-warn-15)"}`},children:_c},void 0,!1,void 0,this),C&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:"var(--c-danger-12)",color:"var(--c-danger)",borderBottom:"1px solid var(--c-danger-12)",display:"flex",alignItems:"center",gap:"6px"},children:[i("span",{children:"⚠"},void 0,!1,void 0,this),i("span",{style:{flex:1},children:C},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>{Z(null),A("loading"),T((X)=>X+1)},style:{background:"var(--c-surface-hover)",border:"1px solid var(--c-danger-12)",borderRadius:"3px",color:"var(--c-danger)",cursor:"pointer",fontSize:"10px",padding:"1px 6px"},children:"Retry"},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>Z(null),style:{background:"none",border:"none",color:"var(--c-danger)",cursor:"pointer",fontSize:"13px",padding:"0 2px"},children:"×"},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:[te&&i("iframe",{ref:n,...Ht.attributes,sandbox:ht,allow:mx(Y?.permissions),style:{flex:1,width:"100%",height:"100%",minHeight:0,border:"none",background:"var(--c-panel)",pointerEvents:Tn?"auto":"none"},title:`Ext App: ${Kt}`},ce,!1,void 0,this),H&&!C&&i("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"10px",background:"var(--c-panel)",color:"var(--c-warn)",fontSize:"12px"},children:[i("div",{children:"App surface failed to paint."},void 0,!1,void 0,this),i("button",{type:"button",onClick:(X)=>{X.stopPropagation(),rt(q,"manual-retry"),m.current=0,U(!1),A("loading"),T((oe)=>oe+1)},style:{background:"var(--c-surface-hover)",border:"1px solid var(--c-warn-15)",borderRadius:"4px",color:"var(--c-warn)",cursor:"pointer",fontSize:"11px",padding:"3px 10px"},children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(R==="loading"||B)&&!C&&!H&&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:R==="loading"?`Connecting to ${Kt}...`:"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),!Tn&&!(H&&!C)&&i("button",{type:"button",onClick:(X)=>{X.stopPropagation(),en(q)},class:"ext-app-preview-catcher",title:"Click to open",style:{position:"absolute",top:0,right:"56px",bottom:"56px",left:0,background:"transparent",border:"none",padding:0,margin:0,cursor:"zoom-in"},"aria-label":"Open full view to edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function gE(e,t,n,o,r,s,a){if(!e)return e;try{let c=new URL(e,window.location.origin);if(c.searchParams.set("theme",fr(Je.value)),t)c.searchParams.set("display","expanded");if(typeof n==="number")c.searchParams.set("v",String(n));if(o)c.searchParams.set("axToken",o);if(r)c.searchParams.set("axNodeId",r);if(s)c.searchParams.set("frameToken",s);if(a)c.searchParams.set("fit","content");return c.toString()}catch{return e}}function vE(e,t=window.location.origin){if(!e)return!1;try{let n=new URL(t).origin,o=new URL(e,n);return o.origin===n&&o.pathname.startsWith("/api/canvas/frame-documents/")}catch{return!1}}function ud({source:e,iframeRef:t,onLoad:n,title:o,className:r="mcp-app-frame",sandbox:s="allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox",allow:a="clipboard-read; clipboard-write",tabIndex:c}){let l=e.src??e.srcdoc??"",[u,d]=O({key:l,source:e}),[p,f]=O(null),m=M(0);D(()=>{if(m.current+=1,!l||l===u.key){f(null);return}if(!u.key){d({key:l,source:e});return}f({key:l,source:e})},[l,u.key]),D(()=>()=>{m.current+=1},[]);let v=(y,x)=>i("iframe",{ref:x?void 0:t,...y.source,class:r,sandbox:s,allow:a,tabIndex:c,loading:vt.value==="srcdoc"?void 0:"lazy",onLoad:(h)=>{if(!x){n();return}let g=++m.current,b=h.currentTarget;requestAnimationFrame(()=>requestAnimationFrame(()=>{if(m.current!==g)return;t.current=b,d(y),f(null),n()}))},style:{position:"absolute",inset:0,width:"100%",height:"100%",visibility:x?"hidden":"visible",background:"var(--c-panel-soft)"},title:o},y.key,!1,void 0,this);return i("div",{class:"mcp-app-frame-stack",children:[v(u,!1),p&&v(p,!0)]},void 0,!0,void 0,this)}function Un({node:e,expanded:t=!1}){if(e.data.mode==="ext-app")return i(Cx,{node:e,expanded:t},void 0,!1,void 0,this);return i(yE,{node:e,expanded:t},void 0,!1,void 0,this)}function yE({node:e,expanded:t}){let n=M(null),o=e.type==="mcp-app"&&e.data.viewerType==="web-artifact",r=e.type==="json-render"||e.type==="graph",s=e.data.axCapabilities?.enabled,c=(r||o)&&(o?s===!0:s!==!1),l=o?"mcp-app":"json-render",u=Ie(()=>c?`ax-${crypto.randomUUID()}`:"",[c]),d=Iu(e)&&!t,p=Ie(()=>d?`frame-${crypto.randomUUID()}`:"",[d]);dr(e,n,p),xr({enabled:c&&Boolean(u),token:u,nodeId:e.id,sourceSurface:l,iframeRef:n});let f=qt.value,m=()=>{if(!c||!u||f==null)return;n.current?.contentWindow?.postMessage({source:Dt,type:"ax-update",token:u,state:f},"*")};D(m,[c,u,f]);let v=typeof e.data.specVersion==="number"?e.data.specVersion:void 0,y=gE(e.data.url||"",t,v,u||void 0,c?e.id:void 0,p||void 0,d),x=pr(y),h=e.data.sourceServer||"",g=e.data.hostMode||"hosted",b=e.data.fallbackReason,E=e.data.trustedDomain===!0||vE(y);if(g==="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),b&&i("div",{style:{color:"var(--c-muted)",fontSize:"11px"},children:["Reason: ",b]},void 0,!0,void 0,this),i("a",{href:y,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all"},children:y},void 0,!1,void 0,this),h&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px"},children:["Source: ",h]},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:[!E&&i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-warn-10)",color:"var(--c-warn)",borderBottom:"1px solid var(--c-warn-15)"},children:"Unverified domain"},void 0,!1,void 0,this),i(ud,{source:x,iframeRef:n,onLoad:m,title:`MCP App: ${h}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var xE=null;function wr(){xE=null}var Tx={idle:"var(--c-muted)",running:"var(--c-accent)",planning:"var(--c-thinking)",thinking:"var(--c-thinking)",drafting:"var(--c-accent)",tooling:"var(--c-accent)",review:"var(--c-ok)","waiting-approval":"var(--c-warn)",waiting:"var(--c-warn-alt)"};function bE(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 Fa({node:e}){let t=bE(e),n=e.data.detail||"",o=e.data.message||"",r=e.data.level||"ok",s=e.data.activeTool,a=e.data.subagent,c=Tx[t]??"var(--c-muted)",l=t!=="idle";return i("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i("div",{style:{width:"8px",height:"8px",borderRadius:"50%",background:c,boxShadow:l?`0 0 8px ${c}`:"none",animation:l?"pulse 1.5s infinite":"none",flexShrink:0}},void 0,!1,void 0,this),i("span",{style:{fontWeight:600,color:c,textTransform:"uppercase",letterSpacing:"0.05em"},children:t},void 0,!1,void 0,this),n&&i("span",{style:{color:"var(--c-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-warn)"},children:[i("span",{style:{fontSize:"10px"},children:"⚙"},void 0,!1,void 0,this),i("span",{style:{fontFamily:"var(--mono)",fontSize:"11px"},children:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a&&a.state!=="completed"&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-subagent)"},children:[i("span",{style:{fontSize:"10px"},children:"⠉"},void 0,!1,void 0,this),i("span",{children:a.name},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-muted)",fontSize:"10px"},children:["(",a.state,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),o&&i("div",{style:{color:r==="warn"?"var(--c-warn)":r==="error"?"var(--c-danger)":"var(--c-muted)",lineHeight:1.4},children:o},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _r(e){return typeof e==="string"&&e.trim().length>0?e.trim():null}function Ex(e){if(typeof e==="string"){let r=_r(e);return r?{title:"Evidence warning",detail:r}:null}if(!e||typeof e!=="object")return null;let t=e,n=_r(t.title)??"Evidence warning",o=_r(t.detail);return o?{title:n,detail:o}:null}function wE(e){let t=[],n=Ex(e.data.warning);if(n)t.push(n);let o=e.data.warnings;if(Array.isArray(o))for(let s of o){let a=Ex(s);if(a)t.push(a)}let r=_r(e.data.validationStatus)?.toLowerCase();if(r==="failed"||r==="invalid")t.push({title:"Image failed validation",detail:_r(e.data.validationMessage)??"Review this image before using it as evidence."});return t}function _E(e){let t=[e.data.title,e.data.caption,e.data.alt,e.data.src,e.data.path].map((n)=>_r(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 Ax(e){let t=wE(e);if(t.length>0)return t;if(_E(e))return[{title:"Captured login page",detail:"This image looks like an auth screen. Treat it as environment context, not product evidence."}];return[]}function ja({node:e,expanded:t=!1}){let n=e.data.src||"",o=e.data.alt||e.data.title||"Image",r=e.data.caption||"",s=Ax(e),a=n.startsWith("data:")||n.startsWith("http://")||n.startsWith("https://")?n:`/api/canvas/image/${e.id}`,[c,l]=O(!1),[u,d]=O(!1),[p,f]=O(1),[m,v]=O({x:0,y:0}),[y,x]=O({w:0,h:0}),h=M(null),g=M(!1),b=M({x:0,y:0}),E=L((B)=>{let W=B.target;x({w:W.naturalWidth,h:W.naturalHeight}),l(!0),d(!1)},[]),j=L(()=>{d(!0),l(!1)},[]);D(()=>{f(1),v({x:0,y:0})},[n]);let _=L((B)=>{B.preventDefault(),B.stopPropagation();let W=B.deltaY>0?0.9:1.1;f((H)=>Math.max(0.25,Math.min(10,H*W)))},[]),R=L((B)=>{if(p<=1)return;B.stopPropagation(),g.current=!0,b.current={x:B.clientX,y:B.clientY},B.target.setPointerCapture(B.pointerId)},[p]),A=L((B)=>{if(!g.current)return;let W=B.clientX-b.current.x,H=B.clientY-b.current.y;b.current={x:B.clientX,y:B.clientY},v((U)=>({x:U.x+W,y:U.y+H}))},[]),C=L(()=>{g.current=!1},[]),Z=L(()=>{f(1),v({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 F=y.w>0?`${y.w}×${y.h}`:"",T=Math.round(p*100);return i("div",{class:`image-node ${t?"image-node-expanded":""}`,ref:h,children:[s.length>0&&i("div",{class:"image-node-warning-stack",children:s.map((B)=>i("div",{class:"image-node-warning",children:[i("span",{class:"image-node-warning-title",children:B.title},void 0,!1,void 0,this),i("span",{class:"image-node-warning-detail",children:B.detail},void 0,!1,void 0,this)]},`${B.title}-${B.detail}`,!0,void 0,this))},void 0,!1,void 0,this),i("div",{class:"image-node-viewport",onWheel:_,onPointerDown:R,onPointerMove:A,onPointerUp:C,style:{cursor:p>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:E,onError:j,draggable:!1,style:{transform:`translate(${m.x}px, ${m.y}px) scale(${p})`,opacity:c?1:0,display:u?"none":"block"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(r||F||p!==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:[F&&i("span",{children:F},void 0,!1,void 0,this),p!==1&&i("button",{type:"button",class:"image-node-zoom-reset",onClick:Z,title:"Reset zoom",children:[T,"% ↺"]},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 Ix({node:e}){if((e.data.children??[]).filter((o)=>N.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 SE(e){try{return new URL(e).host}catch{return e}}function kE(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleString()}function Za({node:e,expanded:t=!1}){let n=typeof e.data.url==="string"?e.data.url:"",o=typeof e.data.pageTitle==="string"?e.data.pageTitle:"",r=typeof e.data.description==="string"?e.data.description:"",s=typeof e.data.excerpt==="string"?e.data.excerpt:typeof e.data.content==="string"?e.data.content:"",a=typeof e.data.status==="string"?e.data.status:"idle",c=typeof e.data.error==="string"?e.data.error:"",l=kE(typeof e.data.fetchedAt==="string"?e.data.fetchedAt:void 0),u=typeof e.data.statusCode==="number"?e.data.statusCode:null,d=typeof e.data.imageUrl==="string"?e.data.imageUrl:"",p=e.data.frameBlocked===!0,f=typeof e.data.frameBlockedReason==="string"?e.data.frameBlockedReason:"",[m,v]=O(!1),[y,x]=O(t);D(()=>{if(t)x(!0)},[t]);let h=L(async()=>{if(!n||m)return;v(!0);try{await Cs(e.id)}finally{v(!1)}},[e.id,m,n]);if(!n)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No webpage URL set"},void 0,!1,void 0,this);let g=a==="ready"?"var(--c-ok)":a==="error"?"var(--c-danger)":"var(--c-warn)";return i("div",{style:{display:"flex",flexDirection:"column",gap:"12px",height:"100%"},children:[i("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[i("div",{style:{minWidth:0,flex:1},children:[i("div",{style:{fontSize:"12px",color:"var(--c-muted)"},children:SE(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:g,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.04em",flexShrink:0},children:[i("span",{style:{width:"7px",height:"7px",borderRadius:"999px",background:g}},void 0,!1,void 0,this),a]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),(r||d)&&i("div",{style:{display:"grid",gridTemplateColumns:d&&t?"160px 1fr":"1fr",gap:"12px",alignItems:"start"},children:[d&&t&&i("img",{src:d,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:h,disabled:m,style:{border:"1px solid var(--c-line)",background:"var(--c-panel-soft)",color:"var(--c-text)",borderRadius:"8px",padding:"6px 10px",cursor:m?"progress":"pointer",fontSize:"12px"},children:m||a==="fetching"?"Refreshing…":"Refresh"},void 0,!1,void 0,this),t&&!p&&i("button",{type:"button",onClick:()=>x((b)=>!b),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:y?"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&&p&&i("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[i("div",{style:{padding:"8px 12px",fontSize:"11px",color:"var(--c-muted)",borderBottom:"1px solid var(--c-line)",background:"rgba(255,255,255,0.03)"},children:"Live preview unavailable. This site refuses embedding, so PMX Canvas cannot show it inline."},void 0,!1,void 0,this),i("div",{style:{padding:"20px",color:"var(--c-text-soft)",lineHeight:1.6,fontSize:"13px"},children:f||"The remote site blocks iframe embedding."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&y&&!p&&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),p&&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 zx(e){return e.type==="html"&&e.data.presentation===!0}function Si({node:e,expanded:t=!1,presentation:n=!1,presentationExitToken:o,autoFocus:r=!1}){let s=M(null),a=Je.value,c=Ie(()=>`theme-${crypto.randomUUID()}`,[]),l=Ie(()=>`ax-${crypto.randomUUID()}`,[]),u=Ie(()=>`frame-${crypto.randomUUID()}`,[]),d=typeof e.data.html==="string"?e.data.html:typeof e.data.content==="string"?e.data.content:"",p=Ie(()=>sr(d),[d]),f=Ie(()=>d?ai(e.id,{theme:a,themeToken:c,present:n,presentToken:o,v:p,axToken:l,frameToken:u}):"",[d,n,o,c,p,e.id,l,u]),m=pr(f);dr(e,s,t?"":u),xr({enabled:!0,token:l,nodeId:e.id,sourceSurface:"html-node",iframeRef:s}),D(()=>{if(s.current?.contentWindow?.postMessage({source:Dt,type:"theme-update",token:c,theme:a},"*"),r)s.current?.focus()},[a,c]);let v=e.data.axCapabilities,y=v?.enabled===!0&&(!Array.isArray(v.allowed)||v.allowed.length>0),x=qt.value;D(()=>{if(!y||x==null)return;s.current?.contentWindow?.postMessage({source:Dt,type:"ax-update",token:l,state:x},"*")},[y,x,l]),D(()=>{if(!r)return;let g=window.setTimeout(()=>s.current?.focus(),0);return()=>window.clearTimeout(g)},[r,f]);let h=()=>{if(s.current?.contentWindow?.postMessage({source:Dt,type:"theme-update",token:c,theme:a},"*"),y&&qt.value!=null)s.current?.contentWindow?.postMessage({source:Dt,type:"ax-update",token:l,state:qt.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(ud,{source:m,iframeRef:s,className:n?"html-node-frame html-node-frame-presentation":t?"html-node-frame html-node-frame-expanded":"html-node-frame",title:typeof e.data.title==="string"?e.data.title:"HTML node",sandbox:"allow-scripts",allow:"",tabIndex:r?0:void 0,onLoad:h},void 0,!1,void 0,this)}var dd=null;async function Px(){if(!dd)dd=await Fg();return dd}function Nx(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 CE(e){return e.replace(/<script[\s>][\s\S]*?<\/script>/gi,"").replace(/<iframe[\s>][\s\S]*?<\/iframe>/gi,"").replace(/<object[\s>][\s\S]*?<\/object>/gi,"").replace(/<embed[\s>][\s\S]*?(?:\/>|<\/embed>)/gi,"").replace(/<link[\s>][\s\S]*?(?:\/>|<\/link>)/gi,"").replace(/\bon\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,"").replace(/href\s*=\s*"javascript:[^"]*"/gi,'href="#"').replace(/href\s*=\s*'javascript:[^']*'/gi,"href='#'")}function TE({html:e}){let t=M(null);return D(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=e,n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function EE(e,t){return`${e.role}:${e.status??"none"}:${t}:${e.text}`}function Rx({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 $x({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,style:{background:"none",border:"none",color:"var(--c-danger)",cursor:"pointer",fontSize:"13px",padding:"0 2px"},children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ha({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",d=a==="answered",[p,f]=O(""),[m,v]=O(""),[y,x]=O(null),[h,g]=O(new Map),b=M(null),E=M(null),j=n[n.length-1],_=`${n.length}:${j?.role??""}:${j?.status??""}:${Math.floor((j?.text?.length??0)/200)}`;D(()=>{if(t&&c&&b.current)b.current.focus()},[t,c]),D(()=>{if(!_)return;if(E.current)E.current.scrollTo({top:E.current.scrollHeight,behavior:"smooth"})},[_]);let R=M(null),A=M(n);A.current=n,D(()=>{let W=n.some((U)=>U.role==="assistant"&&U.status==="streaming"),H=()=>{let U=!1,xe=A.current.map((Fe,qe)=>({turn:Fe,index:qe})).filter(({turn:Fe})=>Fe.role==="assistant"&&Fe.text);if(xe.length===0)return;return Promise.all(xe.map(async({turn:Fe,index:qe})=>{let Te=await un(Fe.text);return{index:qe,html:CE(Te)}})).then((Fe)=>{if(U)return;let qe=new Map;for(let Te of Fe)qe.set(Te.index,Te.html);g(qe)}),()=>{U=!0}};if(!W){if(R.current)clearTimeout(R.current),R.current=null;return H()}if(R.current)clearTimeout(R.current);return R.current=setTimeout(()=>{R.current=null,H()},400),()=>{if(R.current)clearTimeout(R.current),R.current=null}},[n]);let C=L(async()=>{let W=p.trim();if(!W)return;let H=p;x(null),ie(e.id,{turns:[{role:"user",text:W,status:"pending"}],threadStatus:"pending",text:W}),f("");let U=Array.isArray(e.data.contextNodeIds)?e.data.contextNodeIds:void 0;if(!(await Xr(W,e.position,e.id,U,e.id)).ok)ie(e.id,{turns:[],threadStatus:"draft",text:"",status:"draft"}),f(H),x("Failed to send prompt. Your draft has been restored.")},[p,e.id,e.position,e.data.contextNodeIds]),Z=L(async()=>{let W=m.trim();if(!W)return;let H=m;x(null);let U=Array.isArray(e.data.turns)?[...e.data.turns]:[];if(U.push({role:"user",text:W,status:"pending"}),ie(e.id,{turns:U,threadStatus:"pending"}),v(""),!(await jg(e.id,W)).ok)U.pop(),ie(e.id,{turns:U,threadStatus:"answered"}),v(H),x("Failed to send reply. Your draft has been restored.")},[m,e.id,e.data.turns]),F=L((W)=>{if(W.key==="Enter"&&(W.metaKey||W.ctrlKey)){W.preventDefault(),C();return}if(W.key==="Tab"&&p.startsWith("/")){W.preventDefault();let H=p.slice(1).split(/\s/)[0];if(H)Px().then((U)=>{let te=Nx(H,U);if(te)f(`/${te}`)})}},[C,p]),T=L((W)=>{if(W.key==="Enter"&&(W.metaKey||W.ctrlKey)){W.preventDefault(),Z();return}if(W.key==="Tab"&&m.startsWith("/")){W.preventDefault();let H=m.slice(1).split(/\s/)[0];if(H)Px().then((U)=>{let te=Nx(H,U);if(te)v(`/${te}`)})}},[Z,m]),B=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(Rx,{count:B},void 0,!1,void 0,this),i($x,{message:y,onDismiss:()=>x(null)},void 0,!1,void 0,this),i("textarea",{ref:b,value:p,onInput:(W)=>f(W.target.value),onKeyDown:F,placeholder:"Ask the agent something…",spellcheck:!1,style:{flex:1,resize:"none",background:"rgba(10,14,30,0.4)",border:"1px solid var(--c-line)",borderRadius:"var(--radius-sm)",color:"var(--c-text)",fontFamily:"var(--font)",fontSize:"13px",lineHeight:"1.5",padding:"8px 10px",outline:"none"}},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter to send"]},void 0,!0,void 0,this),i("button",{type:"button",onClick:C,disabled:!p.trim(),style:{padding:"5px 14px",fontSize:"12px",fontWeight:600,background:p.trim()?"var(--c-accent)":"var(--c-line)",color:p.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:p.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)":d?"var(--c-ok)":"var(--c-muted)"},children:l?"Sending…":d?"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(Rx,{count:B},void 0,!1,void 0,this),i($x,{message:y,onDismiss:()=>x(null)},void 0,!1,void 0,this),i("div",{ref:E,style:{flex:1,overflow:"auto",minHeight:0},children:n.map((W,H)=>i("div",{children:[H>0&&i("div",{class:"thread-turn-divider"},void 0,!1,void 0,this),W.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:W.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${W.status==="streaming"?" pulsing":""}`},void 0,!1,void 0,this),"PMX"]},void 0,!0,void 0,this),W.status==="streaming"&&!W.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:W.text?1:0.4},children:h.get(H)?i(ve,{children:[i(TE,{html:h.get(H)??""},void 0,!1,void 0,this),W.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:W.status==="streaming"?"Waiting for response…":W.text||"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},EE(W,H),!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:d?"6px":0},children:[i("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:u?"var(--c-accent)":l?"var(--c-warn)":d?"var(--c-ok)":"var(--c-muted)"},children:u?"Streaming…":l?"Sending…":d?"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),d&&i("div",{class:"thread-reply-area",children:[i("textarea",{value:m,onInput:(W)=>v(W.target.value),onKeyDown:T,placeholder:"Reply…",spellcheck:!1,rows:2,style:{width:"100%",resize:"none",background:"rgba(10,14,30,0.4)",border:"1px solid var(--c-line)",borderRadius:"var(--radius-sm)",color:"var(--c-text)",fontFamily:"var(--font)",fontSize:"12px",lineHeight:"1.5",padding:"6px 8px",outline:"none"}},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"4px"},children:[i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter"]},void 0,!0,void 0,this),i("button",{type:"button",onClick:Z,disabled:!m.trim(),style:{padding:"3px 10px",fontSize:"11px",fontWeight:600,background:m.trim()?"var(--c-accent)":"var(--c-line)",color:m.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:m.trim()?"pointer":"default"},children:"Reply"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function AE(e){return e.replace(/<script[\s>][\s\S]*?<\/script>/gi,"").replace(/<iframe[\s>][\s\S]*?<\/iframe>/gi,"").replace(/<object[\s>][\s\S]*?<\/object>/gi,"").replace(/<embed[\s>][\s\S]*?(?:\/>|<\/embed>)/gi,"").replace(/<link[\s>][\s\S]*?(?:\/>|<\/link>)/gi,"").replace(/\bon\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,"").replace(/href\s*=\s*"javascript:[^"]*"/gi,'href="#"').replace(/href\s*=\s*'javascript:[^']*'/gi,"href='#'")}function IE({html:e}){let t=M(null);return D(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=e,n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function Ba({node:e,expanded:t=!1}){let n=e.data.content||"",o=e.data.status||"streaming",[r,s]=O(""),a=o==="streaming",c=o==="complete";D(()=>{if(!n){s("");return}let u=!1;return un(n).then((d)=>{if(!u)s(AE(d))}),()=>{u=!0}},[n]);let l=L(()=>{Xr("",{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(IE,{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 Mx(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 Ox={mcp:"var(--c-accent)",file:"var(--c-warn)",subagent:"var(--c-purple)",other:"var(--c-muted)"},zE={running:"⠋",success:"✓",failed:"✕"},PE={running:"var(--c-accent)",success:"var(--c-ok)",failed:"var(--c-danger)"};function Ua({node:e}){let{toolName:t,category:n,status:o,duration:r,resultSummary:s,error:a}=Mx(e.data),c=Ox[n]??Ox.other,l=zE[o]??"◌",u=PE[o]??"var(--c-muted)",d=o==="running",p=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:d?"pulse 1.5s infinite":"none"},children:l},void 0,!1,void 0,this),i("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:[i("div",{style:{fontFamily:"var(--mono)",fontSize:"11px",fontWeight:600,color:c,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t},void 0,!1,void 0,this),p&&i("div",{style:{fontSize:"10px",color:a?"var(--c-danger)":"var(--c-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:1.3},children:p},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r&&i("span",{style:{fontSize:"9px",padding:"1px 5px",borderRadius:"3px",background:"rgba(255,255,255,0.06)",color:"var(--c-muted)",flexShrink:0,whiteSpace:"nowrap"},children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function md(e){let t=N.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 NE(e){let t=e.map((l)=>md(l)).filter((l)=>l!==null);if(t.length===0)return null;let n=Math.min(...t.map((l)=>l.left)),o=Math.min(...t.map((l)=>l.top)),r=Math.max(...t.map((l)=>l.left+l.width)),s=Math.max(...t.map((l)=>l.top+l.height)),a=54,c=46;return{left:n-a,top:o-c,width:r-n+a*2,height:s-o+c*2}}function pd(e,t){return{left:`${e.left}px`,top:`${e.top}px`,width:`${e.width}px`,height:`${e.height}px`,borderRadius:`${t}px`}}function Lx(){let e=Array.from(er.value),t=Array.from(tr.value),n=js.value;if(e.length===0&&t.length===0)return null;let o=[...N.value.values()],r=o.length>0?(Math.max(...o.map((s)=>s.position.x+s.size.width))-Math.min(...o.map((s)=>s.position.x)))*(Math.max(...o.map((s)=>s.position.y+s.size.height))-Math.min(...o.map((s)=>s.position.y))):0;return i("div",{class:"attention-field-layer","aria-hidden":"true",children:[n.map((s)=>{let a=NE(s.nodeIds);if(!a)return null;if(r>0&&a.width*a.height>=r*0.75)return null;return i("div",{class:"attention-field-region",style:pd(a,42)},s.id,!1,void 0,this)}),t.map((s)=>{let a=md(s);if(!a)return null;return i("div",{class:"attention-field-node attention-field-secondary",style:pd({left:a.left-18,top:a.top-18,width:a.width+36,height:a.height+36},28)},`secondary-${s}`,!1,void 0,this)}),e.map((s)=>{let a=md(s);if(!a)return null;return i("div",{class:"attention-field-node attention-field-primary",style:pd({left:a.left-24,top:a.top-24,width:a.width+48,height:a.height+48},30)},`primary-${s}`,!1,void 0,this)})]},void 0,!0,void 0,this)}var RE=new Set(["png","jpg","jpeg","gif","svg","webp","bmp","ico","avif"]),$E=new Set(["md","mdx","markdown"]);function ME(e){let t=e.split(".").pop()?.toLowerCase()??"";if(RE.has(t))return"image";if($E.has(t))return"markdown";return"file"}async function Wa(e,t,n){let a=Math.ceil(Math.sqrt(e.length));for(let c=0;c<e.length;c++){let l=e[c],u=c%a,d=Math.floor(c/a),p=t-a*420/2+u*420,f=n-150+d*320,m=ME(l.name),v=l.name;if(m==="image"){let y=new FileReader,x=await new Promise((h)=>{y.onload=()=>h(y.result),y.readAsDataURL(l)});await Wt({type:"image",title:v,content:x,x:p,y:f,width:400,height:300})}else{let y=await l.text(),x=m==="markdown"||m==="file";await Wt({type:m,title:v,content:y,x:p,y:f,width:x?720:400,height:x?500:300})}}}var OE={fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"};function we({size:e=16,children:t,...n}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",...OE,...n,children:t},void 0,!1,void 0,this)}function Va(e){return i(we,{...e,children:[i("polyline",{points:"1 5 1 1 5 1"},void 0,!1,void 0,this),i("polyline",{points:"11 1 15 1 15 5"},void 0,!1,void 0,this),i("polyline",{points:"15 11 15 15 11 15"},void 0,!1,void 0,this),i("polyline",{points:"5 15 1 15 1 11"},void 0,!1,void 0,this),i("rect",{x:"4",y:"4",width:"8",height:"8",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Fx(e){return i(we,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),i("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this),i("line",{x1:"7",y1:"5",x2:"7",y2:"9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jx(e){return i(we,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),i("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ao(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"4",x2:"9.5",y2:"4"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"12",x2:"9.5",y2:"12"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6.5",x2:"4",y2:"9.5"},void 0,!1,void 0,this),i("line",{x1:"12",y1:"6.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ga(e){return i(we,{...e,children:[i("rect",{x:"1",y:"2",width:"14",height:"12",rx:"1.5"},void 0,!1,void 0,this),i("rect",{x:"8",y:"7",width:"6",height:"6",rx:"1",fill:"currentColor","fill-opacity":"0.2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Zx(e){return i(we,{...e,children:[i("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"1",x2:"8",y2:"3"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"13",x2:"8",y2:"15"},void 0,!1,void 0,this),i("line",{x1:"1",y1:"8",x2:"3",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"13",y1:"8",x2:"15",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"3.05",y1:"3.05",x2:"4.46",y2:"4.46"},void 0,!1,void 0,this),i("line",{x1:"11.54",y1:"11.54",x2:"12.95",y2:"12.95"},void 0,!1,void 0,this),i("line",{x1:"3.05",y1:"12.95",x2:"4.46",y2:"11.54"},void 0,!1,void 0,this),i("line",{x1:"11.54",y1:"4.46",x2:"12.95",y2:"3.05"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Xa(e){return i(we,{...e,children:i("path",{d:"M13 9.5A5.5 5.5 0 1 1 6.5 3 4.5 4.5 0 0 0 13 9.5Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function fd(e){return i(we,{...e,children:[i("path",{d:"M3 13l2.8-.7L13 5.1 10.9 3 3.7 10.2 3 13Z"},void 0,!1,void 0,this),i("path",{d:"M9.8 4.1l2.1 2.1"},void 0,!1,void 0,this),i("path",{d:"M2.5 14h11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function hd(e){return i(we,{...e,children:[i("path",{d:"M3 10.5 8.5 5a2 2 0 0 1 2.8 0l1.7 1.7a2 2 0 0 1 0 2.8L8.5 14H5.8L3 11.2Z"},void 0,!1,void 0,this),i("path",{d:"M7.5 6 12 10.5"},void 0,!1,void 0,this),i("path",{d:"M8.5 14H14"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function gd(e){return i(we,{...e,children:[i("path",{d:"M3 4h10"},void 0,!1,void 0,this),i("path",{d:"M8 4v8"},void 0,!1,void 0,this),i("path",{d:"M6 12h4"},void 0,!1,void 0,this),i("path",{d:"M4.5 4 4 6"},void 0,!1,void 0,this),i("path",{d:"M11.5 4 12 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Hx(e){return i(we,{...e,children:[i("rect",{x:"1",y:"4",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M5.5 4 L6.5 2.5 H9.5 L10.5 4"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"9",r:"2.3"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Bx(e){return i(we,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"0.8",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ux(e){return i(we,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"10.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"5.5",x2:"5.5",y2:"10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Wx(e){return i(we,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function qx(e){return i(we,{...e,children:[i("rect",{x:"1",y:"3",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6",x2:"5",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"7.5",y1:"6",x2:"8.5",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"11",y1:"6",x2:"12",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"10",x2:"12",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function kr(e){return i(we,{...e,children:i("path",{d:"M2 13 L2 4 A2 2 0 0 1 4 2 L12 2 A2 2 0 0 1 14 4 L14 9 A2 2 0 0 1 12 11 L5 11 Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Vx({size:e=22,class:t}){return i("svg",{width:e,height:e,viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",class:t,"aria-hidden":"true",children:[i("rect",{x:"8",y:"8",width:"48",height:"48",rx:"7",fill:"none",stroke:"currentColor","stroke-width":"2.2",opacity:"0.35"},void 0,!1,void 0,this),i("rect",{x:"16",y:"16",width:"32",height:"32",rx:"5",fill:"none",stroke:"currentColor","stroke-width":"2.2",opacity:"0.6"},void 0,!1,void 0,this),i("rect",{x:"24",y:"24",width:"16",height:"16",rx:"3",fill:"none",stroke:"currentColor","stroke-width":"2.2"},void 0,!1,void 0,this),i("rect",{x:"29",y:"29",width:"6",height:"6",rx:"1",fill:"currentColor"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Gx({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M3 2l10 5.5-4.2 1.3L7.5 13z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Xx({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M5 7.5V3.8a1 1 0 0 1 2 0V7m0-3.9a1 1 0 0 1 2 0V7m0-2.7a1 1 0 0 1 2 0V7.4m0-.9a1 1 0 0 1 2 0v3.2A4.3 4.3 0 0 1 8.7 14H8a4.3 4.3 0 0 1-3.6-2L2.7 9.3a1 1 0 0 1 1.6-1.2L5 9.2"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Kx({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M6 4.5L2.5 8 6 11.5M10 4.5L13.5 8 10 11.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Wn(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6",x2:"10",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"8.5",x2:"8",y2:"8.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"11",x2:"11",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function LE(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M4 13.5 L5.5 11.5 L8 11.5"},void 0,!1,void 0,this),i("polyline",{points:"5 6 7 8 5 10"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"10",x2:"11",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function DE(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M12 13.5 L10.5 11.5 L8 11.5"},void 0,!1,void 0,this),i("circle",{cx:"5",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"11",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function qa(e){return i(we,{...e,children:[i("path",{d:"M3 1.5h6l3.5 3.5v8a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V2.5a1 1 0 0 1 1-1z"},void 0,!1,void 0,this),i("polyline",{points:"9 1.5 9 5 12.5 5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"8.5",x2:"10.5",y2:"8.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"11",x2:"9",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function vd(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"5.5",cy:"6.5",r:"1.2"},void 0,!1,void 0,this),i("path",{d:"M1.8 12 L6 8.5 L9 11 L11.5 9 L14.2 12"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Sr(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"1.5",y1:"5.5",x2:"14.5",y2:"5.5"},void 0,!1,void 0,this),i("circle",{cx:"3.3",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"5",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"6.7",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"8",x2:"12",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"10",x2:"10",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function FE(e){return i(we,{...e,children:[i("rect",{x:"2",y:"4",width:"12",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"2",y1:"6.5",x2:"14",y2:"6.5"},void 0,!1,void 0,this),i("path",{d:"M11 1.5 L11 4"},void 0,!1,void 0,this),i("circle",{cx:"11",cy:"4",r:"1.6",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function yd(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"1.5","stroke-dasharray":"2 1.5"},void 0,!1,void 0,this),i("rect",{x:"4",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),i("rect",{x:"8.5",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),i("rect",{x:"6.25",y:"8.5",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jE(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"9.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ZE(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M3.5 10.5 L6 6.5 L8.5 9.5 L12.5 5"},void 0,!1,void 0,this),i("circle",{cx:"12.5",cy:"5",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function HE(e){return i(we,{...e,children:[i("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"5.5",x2:"11.5",y2:"5.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"8",x2:"11.5",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"10.5",x2:"8",y2:"10.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"2",x2:"6.5",y2:"14",opacity:"0.45"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function BE(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this),i("path",{d:"M4 11 L4 6 L6 8.5 L8 6 L8 11"},void 0,!1,void 0,this),i("path",{d:"M10 11 L10 6 L12.5 11 L12.5 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function UE(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("polyline",{points:"10 5 13 5 13 8"},void 0,!1,void 0,this),i("line",{x1:"13",y1:"5",x2:"8",y2:"10"},void 0,!1,void 0,this),i("path",{d:"M6 6 L3.5 6 L3.5 11.5 L10 11.5 L10 9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function WE(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M7 5.5 C 5.5 5.5 5.5 8 4 8 C 5.5 8 5.5 10.5 7 10.5"},void 0,!1,void 0,this),i("path",{d:"M9 5.5 C 10.5 5.5 10.5 8 12 8 C 10.5 8 10.5 10.5 9 10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Dx(e){return i(we,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"5.2",y1:"6",x2:"8",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"8",x2:"10.8",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"8",x2:"8",y2:"11"},void 0,!1,void 0,this),i("circle",{cx:"5.2",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"10.8",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"11",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function bn(e){switch(e){case"markdown":return Wn;case"prompt":return LE;case"response":return DE;case"file":return qa;case"diff":return qa;case"mermaid":return Dx;case"image":return vd;case"webpage":return Sr;case"context":return FE;case"group":return yd;case"status":return jE;case"trace":return ZE;case"ledger":return HE;case"mcp-app":return BE;case"ext-app":return UE;case"json-render":return WE;case"graph":return Dx;case"html":return Sr;default:return Wn}}var Jx={width:260,height:150},qE={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 bd(e){return!!e&&e in at}function wn(e){if(!e)return null;let t=N.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 xd(e){return{x:e.left+e.width/2,y:e.top+e.height/2}}function ki(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 Yx(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 wd({intent:e}){let t=bd(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:()=>cr.value=e.id,onMouseLeave:()=>{if(cr.value===e.id)cr.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(),fo(e)},children:"✕"},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 Qx({intent:e,rect:t}){let n=bd(e.nodeType)?bn(e.nodeType):null,o=bd(e.nodeType)?at[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:ki(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(wd,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function eb({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:ki(e)},children:[n==="edit"&&i("div",{class:"intent-edit-bar"},void 0,!1,void 0,this),i(wd,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function VE(e){let t=e.phase==="settling"?wn(e.settledNodeId):null;switch(e.kind){case"create":{if(!e.position)return null;let n=e.nodeType&&qE[e.nodeType]||Jx,o=t??{left:e.position.x,top:e.position.y,...n};return i(Qx,{intent:e,rect:o},e.id,!1,void 0,this)}case"move":{if(!e.position)return null;let o=wn(e.nodeId)??Jx,r=t??{left:e.position.x,top:e.position.y,width:o.width,height:o.height};return i(Qx,{intent:e,rect:r},e.id,!1,void 0,this)}case"remove":{let n=t??wn(e.nodeId);if(!n)return null;return i(eb,{intent:e,rect:n,variant:"remove"},e.id,!1,void 0,this)}case"edit":{let n=t??wn(e.nodeId);if(!n)return null;return i(eb,{intent:e,rect:n,variant:"edit"},e.id,!1,void 0,this)}case"connect":{if(!e.edge)return null;let n=wn(e.edge.from),o=wn(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:ki(e)},children:i(wd,{intent:e},void 0,!1,void 0,this)},e.id,!1,void 0,this)}default:return null}}function tb(){let e=Array.from(We.value.values());if(D(()=>{function t(n){if(n.key!=="Escape")return;let o=cr.value;if(!o)return;let r=We.value.get(o);if(!r||r.phase!=="forming")return;n.stopImmediatePropagation(),n.preventDefault(),fo(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&&We.value.get(n)?.phase!=="forming")_o(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=wn(t.edge.from),o=wn(t.edge.to);if(!n||!o)return null;return i("path",{d:Yx(xd(n),xd(o)),class:`intent-edge type-${t.edge.type}`,style:{opacity:ki(t)}},`line-${t.id}`,!1,void 0,this)}if(t.kind==="move"&&t.position){let n=wn(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:Yx(xd(n),r),class:"intent-trail",markerEnd:"url(#intent-arrow)",style:{opacity:ki(t)}},`line-${t.id}`,!1,void 0,this)}return null})]},void 0,!0,void 0,this),e.map(VE)]},void 0,!0,void 0,this)}var nb=32000;var Ka="Agent session";function ob(e){return e.some((t)=>t.attached)}function rb(e){return e.filter((t)=>!t.attached)}function qn(e){switch(e.phase){case"thinking":return"Thinking";case"tooling":return e.detail?`Running ${e.detail}`:"Working";case"waiting-approval":return"Waiting on you";default:return"Idle"}}function Vn(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return(t%360+360)%360}var mt=V([]),Sd=V({used:0,total:nb}),Gn=V([]),Io=V(!1),Cr=V(!1),kd=V(null),ib=["var(--c-purple)","var(--c-accent)","var(--c-ok)","var(--c-warn)","var(--c-danger)"],_d=new Map;function Ja(e){let t=_d.get(e);if(t)return t;let n=ib[_d.size%ib.length];return _d.set(e,n),n}function sb(e){return(e.trim().replace(/^[^a-z0-9]+/i,"").charAt(0)||e.trim().charAt(0)||"?").toUpperCase()}function Ya(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 ft=De(()=>ob(mt.value)),Cd=De(()=>rb(mt.value)),ab=De(()=>{let e=new Set;return[...mt.value].filter((t)=>t.label!==Ka).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))}),cb=De(()=>mt.value.filter((e)=>e.attached)),Tr=De(()=>mt.value.find((e)=>e.attached)??null);function GE(e){let t=new Set;for(let n of e)if(n.nodeId&&n.kind!=="create")t.add(n.nodeId);return t}var lb=De(()=>GE(We.value.values()));function Qa(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 Td(e){if(!e)return;if(Array.isArray(e.presences))mt.value=e.presences;if(e.budget&&Number.isFinite(e.budget.used)&&Number.isFinite(e.budget.total))Sd.value={used:e.budget.used,total:e.budget.total};if(Array.isArray(e.activity))Gn.value=e.activity}function ub(){let e=M(new Map),t=ee.value.scale,n=N.value,o=1/Math.max(0.05,t),r=mt.value.map((s)=>{let a=Qa(s,(l)=>n.get(l));if(a)e.current.set(s.sessionId,a);let c=a??e.current.get(s.sessionId)??null;return c?{presence:s,position:c}:null}).filter((s)=>s!==null);if(r.length===0)return null;return i("div",{class:"agent-presence-layer","aria-hidden":"true",children:r.map(({presence:s,position:a})=>i("div",{class:`agent-cursor phase-${s.phase}${s.cursor?" has-explicit-cursor":""}${s.attached?"":" is-external"}${s.parentAgentId?" is-worker":""}`,"data-session-id":s.sessionId,style:{transform:`translate(${a.x}px, ${a.y}px)`,"--identity-color":`hsl(${Vn(s.sessionId)} 65% 62%)`},children:i("div",{class:"agent-cursor-inner",style:{transform:`scale(${o})`},children:[i("svg",{class:"agent-cursor-glyph",width:"16",height:"18",viewBox:"0 0 16 18","aria-hidden":"true",children:i("path",{d:"M1.5 1.5L14.5 9.2 8.3 10.6 5.2 16.5z",fill:"currentColor",stroke:"var(--c-bg)","stroke-width":"1.2"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"agent-cursor-chip",children:[i("span",{class:"agent-cursor-dot"},void 0,!1,void 0,this),i("span",{class:"agent-cursor-label",children:qn(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 _n(e=1000){let[t,n]=O(()=>Date.now());return D(()=>{if(e<=0)return;n(Date.now());let o=window.setInterval(()=>n(Date.now()),e);return()=>window.clearInterval(o)},[e]),t}function db(){let e=_n(ui.value.length>0?5000:0),t=ui.value.filter((o)=>o.cursor!==null&&(!o.lastSeenAt||e-Date.parse(o.lastSeenAt)<Iy+5000));if(t.length===0)return null;let n=1/Math.max(0.05,ee.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 ec(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 Ad(){let e=qt.value;return e&&typeof e==="object"?e:{}}var pb=De(()=>Ad().workItems??[]),mb=De(()=>Ad().approvalGates??[]),zo=De(()=>mb.value.filter((e)=>e.status==="pending")),Xn=De(()=>{let e=Ad().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 fb(e){return(await Et("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 hb=De(()=>mb.value.filter((e)=>e.status==="held")),gb=V({events:[],evidence:[],steering:[]}),Po=V("all");function Id(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 XE=new Set(["api","mcp","sdk","cli"]);function Ed(e,t){if(e?.trim())return e.trim();let n=t?.trim();if(n&&!XE.has(n))return n;return null}var KE=/^(node|edge|group|annotation|jsonrender|graph|render)\.|^arrange$|^canvas\.clear$|^snapshot\.restore$/,vb=V(null),Ci=V(new Set),JE={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 YE(e,t=40,n=[],o=null,r="all"){let s=n.find((l)=>KE.test(l.op)),a=[...n.map((l)=>({id:`update-${l.id}`,kind:"update",label:"Update",body:l.summary,createdAt:l.at,who:l.sessionId??null,...o?.actor==="agent"&&s?.id===l.id?{undoable:!0}:{}})),...e.events.map((l)=>({id:`event-${l.id}`,kind:l.kind,label:JE[l.kind]??l.kind,body:l.detail?`${l.summary} — ${l.detail}`:l.summary,createdAt:l.createdAt,who:Ed(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:Ed(l.agentId,l.source)})),...e.steering.map((l)=>{let u=l.agentId??(l.source&&l.source!=="browser"?l.source:null),d=l.target?`→ ${l.target} · `:u?"→ all · ":"",p=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} `:""}${d}${l.message}${p}`,createdAt:l.createdAt,who:Ed(l.agentId,l.source)}})],c=r==="all"?a:a.filter((l)=>Id(l.kind)===r);return c.sort((l,u)=>l.createdAt<u.createdAt?1:l.createdAt>u.createdAt?-1:0),c.slice(0,t)}var yb=De(()=>YE(gb.value,40,Gn.value,vb.value,Po.value));async function Kn(){let[e,t]=await Promise.all([de("refreshTimeline","/api/canvas/ax/timeline?limit=40",null),de("refreshHistoryTop","/api/canvas/history",null)]);if(t)vb.value=t.top??null;if(!e)return;gb.value={events:Array.isArray(e.events)?e.events:[],evidence:Array.isArray(e.evidence)?e.evidence:[],steering:Array.isArray(e.steering)?e.steering:[]}}async function zd(e){if(!(await Et("undoAgentEdit","/api/canvas/undo",{method:"POST"})).ok)return!1;return Ci.value=new Set([...Ci.value,e.id]),await Ut("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"})}),Kn(),!0}async function Pd(e=!1){let t=await Et(e?"redo":"undo",e?"/api/canvas/redo":"/api/canvas/undo",{method:"POST"});if(t.ok)Kn();return t.ok}async function xb(e,t){if(!(await Et("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 Ut("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 bb(e){return(await Et("reopenGate",`/api/canvas/ax/approval/${encodeURIComponent(e.id)}/reopen`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser"})})).ok}async function wb(e,t){return(await Et("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 Jn(){return(await Et("startSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser",label:Ka,attached:!0,phase:"idle"})})).ok}async function tc(e){return(await Et("endSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:e.source,agentId:e.agentId,attached:!1,endedBy:"human"})})).ok}var nc=V(null);function _b(e){let{counts:t,snapshot:n}=e;if(typeof e.label!=="string"||typeof e.endedAt!=="string")return;if(e.unchanged===!0||typeof e.parentAgentId==="string")return;nc.value={label:e.label,endedAt:e.endedAt,endedBy:e.endedBy==="human"||e.endedBy==="agent"||e.endedBy==="idle-timeout"?e.endedBy:void 0,unchanged:e.unchanged===!0,counts:{items:Number(t?.items??0)||0,done:Number(t?.done??0)||0,cancelled:Number(t?.cancelled??0)||0,rejected:Number(t?.rejected??0)||0,held:Number(t?.held??0)||0},snapshot:n&&typeof n.id==="string"?{id:n.id,name:String(n.name??"")}:null}}function Sb(){nc.value=null}function kb(){if(!ft.value)return null;let e=Xn.value;if(!e)return null;let t=N.value,n=e.nodeIds.map((s)=>t.get(s)).filter((s)=>s!==void 0),o=ec(n,e.padding);if(!o)return null;let r=1/Math.max(0.05,ee.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 oc={markdown:"var(--c-accent)","mcp-app":"var(--c-ok)",webpage:"var(--c-warn)","json-render":"var(--c-ok)",graph:"var(--c-purple)",prompt:"var(--c-accent)",response:"var(--c-ok)",status:"var(--c-warn)",context:"var(--c-muted)",ledger:"var(--c-dim)",trace:"var(--c-purple)",file:"var(--c-accent)",diff:"var(--c-ok)",mermaid:"var(--c-purple)",image:"var(--c-ok)",html:"var(--c-warn)",group:"var(--c-accent)"};function QE(e){let t=typeof e==="number"&&Number.isFinite(e)?Math.floor(e):1;return Math.max(1,Math.min(20,t))}function rc(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Ti(e){return typeof e==="string"&&e.length>0}function Cb(e){let t=e.axStep;if(!rc(t))return null;if(!Ti(t.flowId)||!Ti(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 Tb(e){let t=e.axFlow;if(!rc(t)||!Ti(t.flowId)||!Array.isArray(t.steps))return null;let n=[];for(let r of t.steps){if(!rc(r)||!Ti(r.nodeId)||!Ti(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=rc(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:QE(o.maxRuns)}}}var eA={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)"},Ab={display:"flex",alignItems:"center",gap:"6px",flexWrap:"wrap"},Ib={fontSize:"10px",color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginRight:"auto"},zb={...wo,background:"var(--c-accent-25)",color:"var(--c-text)"},tA=[{status:"in-progress",label:"Start",toast:"Step started"},{status:"done",label:"Done",toast:"Step done"},{status:"blocked",label:"Blocked",toast:"Step blocked"}];async function Eb(e,t,n){let o={...t,loop:n};ie(e.id,{axFlow:o}),await ct(e.id,{data:{axFlow:o}})}function Pb(e){return typeof e?.axWorkStatus==="string"?e.axWorkStatus:"todo"}function nA({node:e,flow:t}){let[n,o]=O(""),{running:r,run:s,maxRuns:a}=t.loop,c=async()=>{await Eb(e,t,{running:!0,run:s>=a?0:s,maxRuns:a});let u=t.steps.find((p)=>Pb(N.value.get(p.nodeId)?.data)!=="done"),d=u??t.steps[t.steps.length-1];await jn(e,"ax.work.update",{id:d.workItemId,status:u?"in-progress":"done"},"Loop running")},l=async()=>{let u=n.trim();if(!u)return;await jn(e,"ax.steer",{message:u},"Steering sent"),o("")};return i("div",{class:"ax-flow-controls",style:{...Ab,marginTop:"6px",rowGap:"4px"},children:[i("span",{class:"ax-flow-runs",style:Ib,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:zb,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(),Eb(e,t,{...t.loop,running:!1})},children:"Stop"},void 0,!1,void 0,this):i("button",{type:"button",class:"ax-node-action",style:wo,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:wo,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 ic({node:e}){let t=Cb(e.data);if(!t)return null;let n=Tb(e.data),o=Pb(e.data);return i("div",{class:"ax-step-dock",style:eA,children:[i("div",{class:"ax-step-controls",style:Ab,children:[i("span",{class:"ax-step-position",style:Ib,children:["Step ",t.index,"/",t.total]},void 0,!0,void 0,this),tA.map((r)=>i("button",{type:"button",class:"ax-node-action","aria-pressed":o===r.status,style:o===r.status?zb:wo,title:`Set this step's work item to "${r.status}".`,onClick:(s)=>{s.stopPropagation(),jn(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(nA,{node:e,flow:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Er=8,No=V(null),Ar=[],Ir=[],$b=null;function Nb(e){let t=e?.data.parentGroup;return typeof t==="string"&&t.length>0?t:null}function Rb(e){if(!e||!Array.isArray(e.data.children))return[];return e.data.children.filter((t)=>typeof t==="string")}function oA(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=Nb(r);while(s&&!o.has(s))o.add(s),s=Nb(n.get(s));if(r.type!=="group")return o;let a=[...Rb(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(...Rb(l))}return o}function Mb(e,t){Ar=[],Ir=[],$b=e;let n=Array.from(t),o=oA(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,d=r.position.y+r.size.height/2;Ar.push({val:s,minY:l,maxY:u}),Ar.push({val:a,minY:l,maxY:u}),Ar.push({val:c,minY:l,maxY:u}),Ir.push({val:l,minX:s,maxX:a}),Ir.push({val:u,minX:s,maxX:a}),Ir.push({val:d,minX:s,maxX:a})}}function Ob(){Ar=[],Ir=[],$b=null}function Lb(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=Er+1,d=null;for(let y=0;y<3;y++){let x=r[y];for(let h of Ar){let g=Math.abs(x-h.val);if(g<u)u=g,l=h.val-a[y],d={axis:"x",pos:h.val,from:Math.min(h.minY,t),to:Math.max(h.maxY,t+o)}}}let p=null,f=Er+1,m=null;for(let y=0;y<3;y++){let x=s[y];for(let h of Ir){let g=Math.abs(x-h.val);if(g<f)f=g,p=h.val-c[y],m={axis:"y",pos:h.val,from:Math.min(h.minX,e),to:Math.max(h.maxX,e+n)}}}let v=[];if(d&&u<=Er)v.push(d);if(m&&f<=Er)v.push(m);return{x:l!==null&&u<=Er?l:e,y:p!==null&&f<=Er?p:t,guides:v}}function Db({nodeId:e,viewport:t,onMove:n,onDragEnd:o,onClick:r}){let s=M(!1),a=M({x:0,y:0}),c=M({x:0,y:0});return L((u,d,p)=>{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:d,y:p};let f=null,m=null,v=!1,y=()=>{if(m=null,!s.current||!f)return;let g=f;f=null;let b=t.value.scale,E=(g.x-a.current.x)/b,j=(g.y-a.current.y)/b;n(e,c.current.x+E,c.current.y+j)},x=(g)=>{if(!s.current)return;if(!v&&Math.hypot(g.clientX-u.clientX,g.clientY-u.clientY)<4)return;if(v=!0,f={x:g.clientX,y:g.clientY},m!==null)return;m=window.requestAnimationFrame(y)},h=(g)=>{if(m!==null)window.cancelAnimationFrame(m),y();if(s.current=!1,document.documentElement.classList.remove("is-node-dragging"),document.removeEventListener("pointermove",x),document.removeEventListener("pointerup",h),document.removeEventListener("pointercancel",h),o(),!v&&g.type==="pointerup")r?.()};document.addEventListener("pointermove",x),document.addEventListener("pointerup",h),document.addEventListener("pointercancel",h)},[e,t,n,o,r])}var rA=200,iA=100;function Fb({nodeId:e,viewport:t,onResize:n,onResizeEnd:o}){let r=M(!1),s=M({x:0,y:0}),a=M({w:0,h:0});return L((l,u,d)=>{l.stopPropagation(),l.preventDefault(),r.current=!0,s.current={x:l.clientX,y:l.clientY},a.current={w:u,h:d},document.documentElement.classList.add("is-node-resizing");let p=null,f=null,m=()=>{if(f=null,!r.current||!p)return;let x=p;p=null;let h=t.value.scale,g=(x.x-s.current.x)/h,b=(x.y-s.current.y)/h;n(e,Math.max(rA,a.current.w+g),Math.max(iA,a.current.h+b))},v=(x)=>{if(!r.current)return;if(p={x:x.clientX,y:x.clientY},f!==null)return;f=window.requestAnimationFrame(m)},y=()=>{if(f!==null)window.cancelAnimationFrame(f),m();r.current=!1,document.documentElement.classList.remove("is-node-resizing"),document.removeEventListener("pointermove",v),document.removeEventListener("pointerup",y),document.removeEventListener("pointercancel",y),o()};document.addEventListener("pointermove",v),document.addEventListener("pointerup",y),document.addEventListener("pointercancel",y)},[e,t,n,o])}var sA={ArrowLeft:{dx:-1,dy:0},ArrowRight:{dx:1,dy:0},ArrowUp:{dx:0,dy:-1},ArrowDown:{dx:0,dy:1}};function aA(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,d=l*t.dx+u*t.dy;if(d<=0)continue;let p=Math.abs(l*t.dy)+Math.abs(u*t.dx);if(p>d)continue;let f=d+p*2;if(f<a)a=f,s=c}return s}var cA=0.4,lA=0.55,uA=175;function dA(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*cA/ur);if(Number.isFinite(n)&&n>0)r=Math.min(r,n*lA/uA);return Math.max(1,r)}function jb({node:e,children:t,onContextMenu:n}){let o=Ce.value===e.id,r=ye.value.has(e.id),s=Ae.value.has(e.id),a=er.value.has(e.id),c=!a&&tr.value.has(e.id),l=Zs.value.has(e.id),u=!o&&tv.value.has(e.id),d=On.value,p=d!==null&&d.has(e.id),f=d!==null&&!d.has(e.id),[m,v]=O(!1),y=M(null),x=L((P,se,Me)=>{let pe=Lb(se,Me,e.size.width,e.size.height),Ht=N.value.get(P);if(Ht?.position.x===pe.x&&Ht.position.y===pe.y){No.value=pe.guides.length>0?pe.guides:null;return}et(P,{position:{x:pe.x,y:pe.y}}),No.value=pe.guides.length>0?pe.guides:null,iv(P)},[e.size.width,e.size.height]),h=M(null),g=L(()=>{if(Ob(),No.value=null,Eu(null),h.current)document.removeEventListener("keydown",h.current),h.current=null;ot();let P=dn.value;if(rv(),!P||P.nodeId!==e.id)return;if(P.mode==="add")Ol(P.groupId,[e.id]);else{let se=N.value.get(P.groupId),Me=Array.isArray(se?.data.children)?se.data.children.filter((pe)=>typeof pe==="string"&&pe!==e.id):[];Es(P.groupId,Me)}},[e.id]),b=Db({nodeId:e.id,viewport:ee,onMove:x,onDragEnd:g,onClick:()=>{ye.value=new Set([e.id])}}),E=L((P,se,Me)=>{let pe=N.value.get(P);if(pe?.size.width===se&&pe.size.height===Me)return;et(P,{size:{width:se,height:Me}})},[]),j=L(()=>{ie(e.id,{userResized:!0}),ct(e.id,{data:{userResized:!0}}),ot()},[e.id]),_=Fb({nodeId:e.id,viewport:ee,onResize:E,onResizeEnd:j}),R=L((P)=>{P.stopPropagation(),P.preventDefault(),Ze.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]),A=L((P)=>{if(P.button!==0)return;if(m)return;if(P.target instanceof Element&&P.target.closest("button, input")){P.stopPropagation();return}if(_t.value==="connect"){R(P);return}if(P.shiftKey){P.stopPropagation(),Fl(e.id);return}if(hn(e.id),Eu(e.id),Dy(e.id,typeof e.data.title==="string"&&e.data.title?e.data.title:e.type),Mb(e.id,N.value.values()),e.type!=="group"){let se=(Me)=>{if(Me.key==="Escape")ov()};h.current=se,document.addEventListener("keydown",se)}b(P,e.position.x,e.position.y)},[e.id,e.type,e.data.title,e.position.x,e.position.y,b,m,R]),C=L((P)=>{if(P.button!==0)return;if(P.stopPropagation(),_t.value==="connect"){R(P);return}if(P.shiftKey){Fl(e.id);return}hn(e.id)},[e.id,R]),Z=L((P)=>{if((P.target instanceof Element?P.target:null)?.closest('button, input, textarea, select, a, [contenteditable="true"]'))return;if(n)n(P,e.id)},[n,e.id]),F=L((P)=>{let se=P.target;if(se&&se!==P.currentTarget&&se.closest('input, textarea, [contenteditable="true"]'))return;let Me=sA[P.key];if(Me){P.preventDefault();let pe=aA(e,Me,N.value.values());if(!pe)return;hn(pe.id),requestAnimationFrame(()=>{document.querySelector(`.canvas-node[data-node-id="${CSS.escape(pe.id)}"]`)?.focus()})}else if(P.key==="Enter"&&P.target===P.currentTarget&&Vr.has(e.type))P.preventDefault(),en(e.id)},[e]),T=e.data.title||(e.type==="file"?(e.data.path||e.data.content||"").split(/[\\/]/).pop()??"":"")||at[e.type],B=L((P)=>{let se=P.trim();if(se&&se!==T)ie(e.id,{title:se}),ct(e.id,{title:se});v(!1)},[e.id,T]),W=M(null),H=M(!1),U=M(null);D(()=>{if(H.current||!Au(e))return;let P=W.current;if(!P)return;let se=new ResizeObserver(()=>{if(H.current){se.disconnect();return}let Me=P.scrollHeight,pe=By(e,Me);if(pe===null)return;if(Math.abs(pe-e.size.height)>8){if(Os(e.id,{width:e.size.width,height:pe}),U.current!==null)window.clearTimeout(U.current);U.current=window.setTimeout(()=>{ot({recordHistory:!1}),U.current=null},0)}H.current=!0,se.disconnect()});return se.observe(P),()=>{if(se.disconnect(),U.current!==null)window.clearTimeout(U.current),U.current=null}},[e.id,e.type,e.data.mode,e.data.strictSize,e.collapsed,e.size.width,e.size.height]);let te=e.pinned,xe=e.type==="trace",Fe=xe&&e.data.status==="running",qe=e.type==="group",Te=e.data.strictSize===!0,oo=Math.max(ee.value.scale,0.01),Zt=dA(oo,e.collapsed?0:e.size.height,e.size.width),Kt=qe&&e.data.color?e.data.color:void 0,I={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":Zt.toFixed(3),...Kt?{"--group-color":Kt}:{}},K=ft.value&&lb.value.has(e.id),le=["canvas-node",o?"active":"",u?"neighbor":"",p?"search-match":"",f?"search-dimmed":"",r?"selected":"",s?"context-pinned":"",a?"attention-focus-primary":"",c?"attention-focus-secondary":"",l?"attention-pulse":"",te?"pinned":"",xe?"trace-node":"",Fe?"trace-running":"",qe?"group-node":"",Te?"strict-size":"",K?"agent-mutating":""].filter(Boolean).join(" "),Y=qe?(Array.isArray(e.data.children)?e.data.children:[]).filter((P)=>typeof P==="string"&&N.value.has(P)):[],[J,Q]=O(!1),ne=dn.value,q=qe&&ne?.groupId===e.id&&ne.mode==="add",ce=qe&&ne?.groupId===e.id&&ne.mode==="remove",ht=Ze.value?.targetId===e.id,Ct=qe?[...new Set(Y.map((P)=>N.value.get(P)?.type).filter((P)=>!!P))].slice(0,4):[];if(qe&&e.collapsed)return i("div",{class:`${le} group-chip`,"data-node-type":e.type,style:{...I,width:"auto",height:"auto"},onPointerDown:C,onDblClick:Z,title:"Expand group","data-testid":"group-chip",children:i("div",{class:"node-titlebar group-chip-inner",onPointerDown:A,children:[i("button",{type:"button",class:"group-chip-expand","aria-label":`Expand group ${T}`,onClick:(P)=>{P.stopPropagation(),Ko(e.id)},children:"▸"},void 0,!1,void 0,this),i("div",{class:"group-chip-text",children:[i("div",{class:"group-chip-name",children:T},void 0,!1,void 0,this),i("div",{class:"group-chip-meta",children:[Ct.map((P)=>i("span",{class:"group-kind-dot",style:{background:oc[P]},"aria-hidden":"true"},P,!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:`${le}${q?" is-drop-target":""}${ce?" is-drop-source":""}${ht?" is-edge-target":""}${qe&&J?" group-menu-open":""}`,"data-node-type":e.type,"data-node-id":e.id,style:I,tabIndex:o?0:-1,onKeyDown:F,onPointerDown:C,onMouseDown:(P)=>{if(P.shiftKey)P.preventDefault()},onDblClick:Z,children:[qe&&i("div",{class:"node-titlebar group-edge-row",onPointerDown:A,children:[i("span",{class:"group-name-pill",children:[m?i("input",{ref:y,class:"node-title-input group-title-input",value:T,onBlur:(P)=>B(P.target.value),onKeyDown:(P)=>{if(P.key==="Enter")B(P.target.value);if(P.key==="Escape")v(!1)},onClick:(P)=>P.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"group-name",title:T,children:T},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":`${T} actions`,children:[i("button",{type:"button",class:"group-action",title:"Auto-arrange children","aria-label":"Auto-arrange children",disabled:Y.length===0,onClick:(P)=>{P.stopPropagation(),Ol(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:(P)=>{P.stopPropagation(),Ko(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":J,onClick:(P)=>{P.stopPropagation(),Q((se)=>!se)},children:"⋯"},void 0,!1,void 0,this),J&&i("div",{class:"group-menu",role:"menu",onPointerDown:(P)=>P.stopPropagation(),children:[i("button",{type:"button",role:"menuitem",onClick:(P)=>{P.stopPropagation(),Q(!1),v(!0),requestAnimationFrame(()=>y.current?.focus())},children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",onClick:(P)=>{P.stopPropagation(),Q(!1),zt(e.id),Wo(e.id)},children:"Ungroup"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",disabled:Y.length===0,onClick:(P)=>{P.stopPropagation(),Q(!1),Ns(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),!qe&&i("div",{class:"node-titlebar",onPointerDown:A,children:[i("span",{class:"node-type-icon","aria-hidden":"true",children:(()=>{let P=bn(e.type);return i(P,{size:Math.round(14*Zt)},void 0,!1,void 0,this)})()},void 0,!1,void 0,this),typeof e.data.axWorkStatus==="string"&&i("span",{class:`node-ax-status node-ax-status-${e.data.axWorkStatus}`,children:e.data.axWorkStatus},void 0,!1,void 0,this),m?i("input",{ref:y,class:"node-title-input",value:T,onBlur:(P)=>B(P.target.value),onKeyDown:(P)=>{if(P.key==="Enter")B(P.target.value);if(P.key==="Escape")v(!1)},onClick:(P)=>P.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"node-title",title:T,children:T},void 0,!1,void 0,this),i("div",{class:"node-controls",children:[te&&i("span",{class:"pin-indicator",title:"Pinned",children:"⊙"},void 0,!1,void 0,this),i("button",{type:"button",class:`ctx-pin-btn${s?" ctx-pin-active":""}`,onClick:(P)=>{P.stopPropagation(),Ln(e.id)},title:s?"Remove from context":"Add to context",children:"✦"},void 0,!1,void 0,this),la(e)&&i("button",{type:"button",onClick:(P)=>{P.stopPropagation(),ua(e)},title:"Open as site",children:"↗"},void 0,!1,void 0,this),Vr.has(e.type)&&i("button",{type:"button",onClick:(P)=>{P.stopPropagation(),en(e.id)},title:"Expand (focus mode)",children:"⤢"},void 0,!1,void 0,this),i("button",{type:"button",onClick:(P)=>{P.stopPropagation(),Ko(e.id)},title:e.collapsed?"Expand":"Collapse",children:e.collapsed?"▸":"▾"},void 0,!1,void 0,this),i("button",{type:"button",onClick:(P)=>{P.stopPropagation(),zt(e.id),$n(e.id)},title:"Close",children:"×"},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(ic,{node:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!e.collapsed&&i("div",{class:"node-resize-handle",onPointerDown:(P)=>_(P,e.size.width,e.size.height)},void 0,!1,void 0,this),r&&["tl","tr","bl","br"].map((P)=>i("span",{class:`node-selection-handle is-${P}`,"aria-hidden":"true"},P,!1,void 0,this)),So.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),So.value.get(e.id)," took over — agent yielded"]},void 0,!0,void 0,this),!qe&&["top","right","bottom","left"].map((P)=>i("div",{class:`node-port node-port-${P}`,onPointerDown:(se)=>{se.stopPropagation(),se.preventDefault();let Me=e.position.x+e.size.width/2,pe=e.position.y+e.size.height/2,Ht=e.size.width/2,Ri=e.size.height/2,Bt,Cn;switch(P){case"top":Bt=Me,Cn=pe-Ri;break;case"bottom":Bt=Me,Cn=pe+Ri;break;case"left":Bt=Me-Ht,Cn=pe;break;case"right":Bt=Me+Ht,Cn=pe;break}Ze.value={fromId:e.id,fromX:Bt,fromY:Cn,cursorX:Bt,cursorY:Cn}}},P,!1,void 0,this))]},void 0,!0,void 0,this)}var pA={relation:"var(--c-muted)","depends-on":"var(--c-warn)",flow:"var(--c-accent)",references:"var(--c-muted)"},mA=new Set(["depends-on","flow"]);function fA(e){if(!Number.isFinite(e)||e<=0)return 1;return e<1?1/e:1}function hA(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 sc(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,d=Math.abs(c/(a||0.001)),p=u/(l||0.001);if(d>p){let m=c>0?1:-1;return{x:n+u/d*(a>0?1:-1),y:o+u*m,side:m>0?"bottom":"top"}}let f=a>0?1:-1;return{x:n+l*f,y:o+d*l*(c>0?1:-1),side:f>0?"right":"left"}}function ac(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 gA(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 vA({edge:e,fromNode:t,toNode:n,focused:o,dimmed:r,selected:s,scale:a,onContextMenu:c}){let l=sc(t,n),u=sc(n,t),d=u.x-l.x,p=u.y-l.y,f=Math.sqrt(d*d+p*p),m=Math.min(Math.max(f*0.35,32),160),v=ac(l,m),y=ac(u,m),x=`M ${l.x} ${l.y} C ${v.x} ${v.y}, ${y.x} ${y.y}, ${u.x} ${u.y}`,h=pA[e.type],g=mA.has(e.type),b=hA(e,a),E=Math.min(a,2.2),j=e.label&&a<=3.4?gA(l.x,l.y,v.x,v.y,y.x,y.y,u.x,u.y):null,_=`edge-path-${e.id}`;return i("g",{children:[i("path",{d:x,fill:"none",stroke:"transparent","stroke-width":12*a,style:{cursor:"pointer",pointerEvents:"stroke"},onClick:(R)=>{R.stopPropagation(),pn.value=e.id},onDblClick:c?(R)=>c(R,e.id):void 0},void 0,!1,void 0,this),(o||s)&&i("path",{d:x,fill:"none",stroke:h,"stroke-width":6*a,"stroke-dasharray":b,opacity:s?0.3:0.15,style:{filter:"blur(3px)"}},void 0,!1,void 0,this),i("path",{id:_,d:x,class:s?"edge-selected":void 0,fill:"none",stroke:h,"stroke-width":(s?3:o?2.5:1.5)*a,"stroke-dasharray":b,"marker-end":g?"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:h,opacity:"0.9",children:i("animateMotion",{dur:"2s",repeatCount:"indefinite",children:i("mpath",{href:`#${_}`},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),j&&e.label&&i("g",{transform:`translate(${j.x}, ${j.y})`,children:[i("rect",{class:"edge-label-bg",x:-(e.label.length*3.5+8)*E,y:-10*E,width:(e.label.length*7+16)*E,height:20*E,rx:4*E},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 Zb({nodes:e,edges:t,onEdgeContextMenu:n}){let o=e.value,r=Array.from(t.value.values()),s=Ce.value,a=s!==null,c=On.value,l=c!==null,u=fA(ee.value.scale);if(r.length===0&&!Ze.value)return null;let d=96,p=Array.from(o.values());if(p.length===0)return null;let f=Math.min(...p.map((g)=>g.position.x))-d,m=Math.min(...p.map((g)=>g.position.y))-d,v=Math.max(...p.map((g)=>g.position.x+g.size.width))+d,y=Math.max(...p.map((g)=>g.position.y+g.size.height))+d,x=Math.max(1,v-f),h=Math.max(1,y-m);return i("svg",{"aria-label":"Canvas connections",role:"img",viewBox:`${f} ${m} ${x} ${h}`,width:x,height:h,style:{position:"absolute",top:`${m}px`,left:`${f}px`,pointerEvents:"none",overflow:"visible","--edge-chrome-scale":u.toFixed(3),"--edge-label-scale":Math.min(u,2.2).toFixed(3)},children:[i("title",{children:"Canvas connections"},void 0,!1,void 0,this),i("defs",{children:i("marker",{id:"edge-arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:8*Math.min(u,2.2),markerHeight:8*Math.min(u,2.2),orient:"auto-start-reverse",children:i("path",{d:"M 0 1 L 10 5 L 0 9 z",fill:"currentColor",opacity:"0.75"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r.map((g)=>{let b=Ps(g.from),E=Ps(g.to);if(!b||!E||b.id===E.id)return null;let j=a&&(g.from===s||g.to===s),_=l&&!(c.has(g.from)||c.has(g.to));return i(vA,{edge:g,fromNode:b,toNode:E,focused:j,dimmed:a&&!j||_,selected:pn.value===g.id,scale:u,onContextMenu:n},g.id,!1,void 0,this)}),Ze.value&&(()=>{let g=Ze.value,b=Ps(g.fromId),E={position:{x:g.cursorX,y:g.cursorY},size:{width:1,height:1}},j;if(b){let _=sc(b,E),R=sc(E,b),A=R.x-_.x,C=R.y-_.y,Z=Math.sqrt(A*A+C*C),F=Math.min(Math.max(Z*0.35,32),160),T=ac(_,F),B=ac(R,F);j=`M ${_.x} ${_.y} C ${T.x} ${T.y}, ${B.x} ${B.y}, ${R.x} ${R.y}`}else{let _=g.cursorX-g.fromX,R=g.cursorY-g.fromY,A=Math.sqrt(_*_+R*R),C=Math.min(A*0.25,80),Z=_/(A||1),F=R/(A||1);j=`M ${g.fromX} ${g.fromY} C ${g.fromX+Z*C} ${g.fromY+F*C}, ${g.cursorX-Z*C} ${g.cursorY-F*C}, ${g.cursorX} ${g.cursorY}`}return i("g",{children:[i("path",{d:j,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:j,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:g.cursorX,cy:g.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 yA(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 Nd({annotations:e}){if(e.length===0)return null;return i("svg",{class:"annotation-layer","aria-hidden":"true",children:e.map((t)=>{let n=t.color==="currentColor"?"var(--c-annotation)":t.color;if(t.type==="text"){let o=t.points[0];if(!o||!t.text)return null;return i("text",{x:o.x,y:o.y,fill:n,"font-size":t.width,"font-family":"var(--font)","font-weight":"700",opacity:"0.95",children:t.text},t.id,!1,void 0,this)}return i("path",{d:yA(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)}var xA=0.1,bA=4,Hb=1;function Bb(e){return Math.min(bA,Math.max(xA,e))}function Ub({viewport:e,onViewportChange:t,onViewportCommit:n,disabled:o=!1}){let r=M(null),s=M(!1),a=M({x:0,y:0}),c=M(0),l=M(null),u=L((h)=>{if(l.current!==null)window.clearTimeout(l.current);l.current=window.setTimeout(()=>{l.current=null,n(h)},140)},[n]);function d(h){if(h.deltaMode!==0)return h.deltaX===0;return h.deltaX===0&&Number.isInteger(h.deltaY)&&Math.abs(h.deltaY)>=50}let p=L((h)=>{if(o)return;h.preventDefault();let g=e.value;if(h.ctrlKey||h.metaKey||d(h)){let b=r.current?.getBoundingClientRect();if(!b)return;let E=h.clientX-b.left,j=h.clientY-b.top,_=-h.deltaY*0.002,R=Bb(g.scale*(1+_)),A=R/g.scale,C={x:E-A*(E-g.x),y:j-A*(j-g.y),scale:R};t(C),u(C)}else{let b={x:g.x-h.deltaX*Hb,y:g.y-h.deltaY*Hb,scale:g.scale};t(b),u(b)}},[o,e,t,u]),f=L((h)=>{if(o)return;let g=r.current;if(!g)return;if(h.button===1||h.button===2)h.preventDefault();else if(Xo()){if(h.target!==g)return;h.preventDefault()}else return;s.current=!0,document.documentElement.classList.add("is-canvas-panning"),a.current={x:h.clientX,y:h.clientY},g.setPointerCapture(h.pointerId)},[o]),m=L((h)=>{if(!s.current)return;if(o)return;let g=h.clientX-a.current.x,b=h.clientY-a.current.y;a.current={x:h.clientX,y:h.clientY};let E=e.value;t({x:E.x+g,y:E.y+b,scale:E.scale})},[o,e,t]),v=L(()=>{if(s.current)n(e.value);s.current=!1,document.documentElement.classList.remove("is-canvas-panning")},[n,e]),y=L((h)=>{if(o)return;if(h.touches.length!==2){c.current=0;return}h.preventDefault();let g=h.touches[0],b=h.touches[1],E=Math.hypot(b.clientX-g.clientX,b.clientY-g.clientY),j=(g.clientX+b.clientX)/2,_=(g.clientY+b.clientY)/2;if(c.current>0){let R=e.value,A=r.current?.getBoundingClientRect();if(!A)return;let C=j-A.left,Z=_-A.top,F=E/c.current,T=Bb(R.scale*F),B=T/R.scale,W={x:C-B*(C-R.x),y:Z-B*(Z-R.y),scale:T};t(W),u(W)}c.current=E},[o,e,t,u]),x=L(()=>{if(l.current!==null)window.clearTimeout(l.current),l.current=null;n(e.value),c.current=0},[n,e]);return D(()=>{let h=r.current;if(!h)return;return h.addEventListener("wheel",p,{passive:!1}),h.addEventListener("pointerdown",f),h.addEventListener("pointermove",m),h.addEventListener("pointerup",v),h.addEventListener("pointercancel",v),h.addEventListener("lostpointercapture",v),h.addEventListener("touchmove",y,{passive:!1}),h.addEventListener("touchend",x),()=>{if(l.current!==null)window.clearTimeout(l.current);h.removeEventListener("wheel",p),h.removeEventListener("pointerdown",f),h.removeEventListener("pointermove",m),h.removeEventListener("pointerup",v),h.removeEventListener("pointercancel",v),h.removeEventListener("lostpointercapture",v),h.removeEventListener("touchmove",y),h.removeEventListener("touchend",x)}},[p,f,m,v,y,x]),D(()=>()=>{document.documentElement.classList.remove("is-canvas-panning")},[]),r}function wA(e){switch(e.type){case"markdown":return i(ia,{node:e},void 0,!1,void 0,this);case"mcp-app":return i(Un,{node:e},void 0,!1,void 0,this);case"webpage":return i(Za,{node:e},void 0,!1,void 0,this);case"json-render":return i(Un,{node:e},void 0,!1,void 0,this);case"graph":return i(Un,{node:e},void 0,!1,void 0,this);case"prompt":return i(Ha,{node:e},void 0,!1,void 0,this);case"response":return i(Ba,{node:e},void 0,!1,void 0,this);case"status":return i(Fa,{node:e},void 0,!1,void 0,this);case"context":return i(Xs,{node:e},void 0,!1,void 0,this);case"ledger":return i(Qs,{node:e},void 0,!1,void 0,this);case"trace":return i(Ua,{node:e},void 0,!1,void 0,this);case"file":return i(Ys,{node:e},void 0,!1,void 0,this);case"diff":return i(Ks,{node:e},void 0,!1,void 0,this);case"mermaid":return i(xa,{node:e},void 0,!1,void 0,this);case"image":return i(ja,{node:e},void 0,!1,void 0,this);case"html":return i(Si,{node:e},void 0,!1,void 0,this);case"group":return i(Ix,{node:e},void 0,!1,void 0,this);default:return i("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function _A(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 SA(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&&_A(t,c,l)<=n+r.width/2)return r}}return null}var Rd="currentColor",Wb=4,qb=24,kA=14,Vb={width:520,height:420};function CA(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 Md(e){let t=e.trim();if(!t)return[];let n=t.includes(`
314
- `)?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=CA(a);if(!c||o.has(c))continue;o.add(c),r.push(c)}return r}function TA(e){let t=Md(e.getData("text/uri-list"));if(t.length>0)return t;return Md(e.getData("text/plain"))}function EA(e){if(!e)return!1;return e.types.includes("text/uri-list")||e.types.includes("text/plain")}function $d(e){if(!(e instanceof HTMLElement))return!1;return Boolean(e.closest('input, textarea, select, [contenteditable="true"], [contenteditable=""]'))}function AA(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 Gb({onNodeContextMenu:e,onEdgeContextMenu:t,onCanvasContextMenu:n,annotationMode:o=!1,annotationTool:r=null}){let s=ee.value,a=M(!1),c=M(null),l=M(!1),u=M([]),[d,p]=O(null),[f,m]=O(null),[v,y]=O(null),x=M(null),[h,g]=O(!1),b=M(0),E=M(null),j=M(null);D(()=>{let I=null,K=Lt(()=>{ee.value;let le=j.current;if(!le)return;if(le.style.willChange="transform",I)clearTimeout(I);I=setTimeout(()=>{le.style.willChange="auto"},180)});return()=>{if(I)clearTimeout(I);K()}},[]);let _=Ub({viewport:ee,disabled:o,onViewportChange:(I)=>{if(a.current||o)return;gn(),mv(I)},onViewportCommit:(I)=>{if(a.current||o)return;gn(),hv(I)}}),R=L((I)=>{x.current=I,y(I)},[]),A=L(async(I,K,le)=>{if(I.length===0)return;let{width:Y,height:J}=Vb,Q=24,ne=Math.ceil(Math.sqrt(I.length)),q=Math.ceil(I.length/ne),ce=ne*Y+Math.max(0,ne-1)*Q,ht=q*J+Math.max(0,q-1)*Q;for(let Ct=0;Ct<I.length;Ct++){let P=Ct%ne,se=Math.floor(Ct/ne),Me=K-ce/2+P*(Y+Q),pe=le-ht/2+se*(J+Q);await Wt({type:"webpage",content:I[Ct],x:Me,y:pe,width:Y,height:J})}},[]),C=L((I)=>{let K=_.current;if(!K)return;if(r==="eraser"){if((I.target instanceof Element?I.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;I.preventDefault(),I.stopPropagation();let q=K.getBoundingClientRect(),ce=ee.value,ht={x:(I.clientX-q.left-ce.x)/ce.scale,y:(I.clientY-q.top-ce.y)/ce.scale},Ct=SA(Array.from(Vo.value.values()),ht,kA/ce.scale);if(Ct)pv(Ct.id);return}if(r==="text"){if((I.target instanceof Element?I.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;I.preventDefault(),I.stopPropagation(),Ce.value=null,gt();let q=K.getBoundingClientRect(),ce=ee.value;R({x:(I.clientX-q.left-ce.x)/ce.scale,y:(I.clientY-q.top-ce.y)/ce.scale,value:""});return}if(r==="pen"){if((I.target instanceof Element?I.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;I.preventDefault(),I.stopPropagation(),Ce.value=null,gt(),l.current=!0;let q=K.getBoundingClientRect(),ce=ee.value,ht={x:(I.clientX-q.left-ce.x)/ce.scale,y:(I.clientY-q.top-ce.y)/ce.scale};u.current=[ht],m({id:"draft-annotation",type:"freehand",points:[ht],bounds:{x:0,y:0,width:0,height:0},color:Rd,width:Wb,createdAt:""}),K.setPointerCapture(I.pointerId);return}if(I.target!==K)return;if(Xo()||I.button===1||I.button===2){if(!I.shiftKey&&!E.current)Ce.value=null,gt();return}I.preventDefault(),I.stopPropagation(),a.current=!0;let le=K.getBoundingClientRect(),Y=I.clientX-le.left,J=I.clientY-le.top,Q={startX:Y,startY:J,currentX:Y,currentY:J};E.current=Q,p(Q),K.setPointerCapture(I.pointerId)},[r,_]);D(()=>Lt(()=>{let I=ee.value,K=c.current,le=_.current;if(!K||!le)return;let Y=le.getBoundingClientRect();ga({x:(K.x-Y.left-I.x)/I.scale,y:(K.y-Y.top-I.y)/I.scale})}),[]);let Z=L((I)=>{{let Y=_.current;if(Y){c.current={x:I.clientX,y:I.clientY};let J=Y.getBoundingClientRect(),Q=ee.value;ga({x:(I.clientX-J.left-Q.x)/Q.scale,y:(I.clientY-J.top-Q.y)/Q.scale})}}if(l.current){let Y=_.current;if(!Y)return;let J=Y.getBoundingClientRect(),Q=ee.value,ne={x:(I.clientX-J.left-Q.x)/Q.scale,y:(I.clientY-J.top-Q.y)/Q.scale},q=u.current.at(-1);if(q&&Math.hypot(ne.x-q.x,ne.y-q.y)<2)return;u.current=[...u.current,ne],m((ce)=>ce?{...ce,points:u.current}:null);return}if(!a.current||!E.current)return;let K=_.current?.getBoundingClientRect();if(!K)return;let le={...E.current,currentX:I.clientX-K.left,currentY:I.clientY-K.top};E.current=le,p(le)},[_]),F=L((I)=>{if(l.current){l.current=!1;let ne=u.current;if(u.current=[],m(null),ne.length>=2)Ul({points:ne,color:Rd,width:Wb});let q=_.current;if(q?.hasPointerCapture(I.pointerId))q.releasePointerCapture(I.pointerId);return}let K=E.current;if(!a.current||!K)return;a.current=!1,E.current=null;let le=Math.min(K.startX,K.currentX),Y=Math.max(K.startX,K.currentX),J=Math.min(K.startY,K.currentY),Q=Math.max(K.startY,K.currentY);if(Y-le<=5&&Q-J<=5)Ce.value=null,gt();if(Y-le>5||Q-J>5){let ne=ee.value,q=(le-ne.x)/ne.scale,ce=(Y-ne.x)/ne.scale,ht=(J-ne.y)/ne.scale,Ct=(Q-ne.y)/ne.scale,P=[];for(let se of N.value.values()){let Me=se.position.x,pe=se.position.y;if(Me+se.size.width>q&&Me<ce&&pe+se.size.height>ht&&pe<Ct)P.push(se.id)}if(P.length>0)nv(P)}p(null)},[]);D(()=>{if(o)return;if(!l.current&&!f&&!v)return;l.current=!1,u.current=[],m(null),R(null)},[o,f,R,v]);let T=L(()=>{let I=x.current;if(!I)return;let K=I.value.trim();if(R(null),!K)return;let le={x:I.x,y:I.y};Ul({type:"text",points:[le],color:Rd,width:qb,text:K})},[R]);D(()=>{if(r!=="text"&&v)R(null)},[r,R,v]),D(()=>{let I=(J,Q,ne)=>{let q=null;for(let ce of N.value.values()){if(ce.id===ne||ce.type==="group")continue;if(J>=ce.position.x&&J<=ce.position.x+ce.size.width&&Q>=ce.position.y&&Q<=ce.position.y+ce.size.height)q=ce.id}return q};function K(J){if(!Ze.value)return;let Q=_.current;if(!Q)return;let ne=Q.getBoundingClientRect(),q=ee.value,ce=(J.clientX-ne.left-q.x)/q.scale,ht=(J.clientY-ne.top-q.y)/q.scale;Ze.value={...Ze.value,cursorX:ce,cursorY:ht,targetId:I(ce,ht,Ze.value.fromId)}}function le(){let J=Ze.value;if(!J)return;Ze.value=null;let Q=J.targetId;if(!Q)return;if(J.withLabel){on("Edge label","label text").then((ne)=>{ho(J.fromId,Q,"relation",ne??void 0)});return}ho(J.fromId,Q,"relation",void 0)}function Y(J){let Q=Ze.value;if(!Q)return;if(J.key==="Escape")J.preventDefault(),Ze.value=null;else if(J.key==="l"||J.key==="L")J.preventDefault(),Ze.value={...Q,withLabel:!Q.withLabel}}return document.addEventListener("pointermove",K),document.addEventListener("pointerup",le),document.addEventListener("keydown",Y),()=>{document.removeEventListener("pointermove",K),document.removeEventListener("pointerup",le),document.removeEventListener("keydown",Y)}},[_]);let B=L((I)=>{if(o)return;let K=_.current;if(!K||I.target!==K||!n)return;let le=K.getBoundingClientRect(),Y=ee.value,J=(I.clientX-le.left-Y.x)/Y.scale,Q=(I.clientY-le.top-Y.y)/Y.scale;n(I,J,Q)},[o,_,n]),W=L((I)=>{I.preventDefault()},[]),H=L((I)=>{if($d(I.target instanceof Element?I.target:null))return;I.preventDefault()},[]),U=L((I)=>{if(I.preventDefault(),b.current++,I.dataTransfer?.types.includes("Files")||EA(I.dataTransfer))g(!0)},[]),te=L((I)=>{if(I.preventDefault(),I.dataTransfer)I.dataTransfer.dropEffect="copy"},[]),xe=L((I)=>{if(I.preventDefault(),b.current--,b.current<=0)b.current=0,g(!1)},[]),Fe=L(async(I)=>{I.preventDefault(),g(!1),b.current=0;let K=_.current;if(!K||!I.dataTransfer)return;let le=K.getBoundingClientRect(),Y=ee.value,J=(I.clientX-le.left-Y.x)/Y.scale,Q=(I.clientY-le.top-Y.y)/Y.scale,ne=Array.from(I.dataTransfer.files);if(ne.length===0){let q=TA(I.dataTransfer);await A(q,J,Q);return}await Wa(ne,J,Q)},[_,A]);D(()=>{let I=async(K)=>{if(K.defaultPrevented)return;if($d(K.target instanceof Element?K.target:null))return;if($d(document.activeElement))return;let le=K.clipboardData?.getData("text/plain")??"",Y=Md(le);if(Y.length===0)return;let J=_.current;if(!J)return;K.preventDefault();let Q=J.getBoundingClientRect(),ne=ee.value,q=(Q.width/2-ne.x)/ne.scale,ce=(Q.height/2-ne.y)/ne.scale;await A(Y,q,ce)};return document.addEventListener("paste",I),()=>{document.removeEventListener("paste",I)}},[_,A]);let qe=AA(N.value.values(),Ue.value,new Set(Zl.value.keys())),Te=dn.value,oo=Te?N.value.get(Te.groupId):void 0,Zt=Te?N.value.get(Te.nodeId):void 0,Kt=null;if(d){let I=Math.min(d.startX,d.currentX),K=Math.min(d.startY,d.currentY),le=Math.abs(d.currentX-d.startX),Y=Math.abs(d.currentY-d.startY);Kt={position:"absolute",left:`${I}px`,top:`${K}px`,width:`${le}px`,height:`${Y}px`,pointerEvents:"none"}}return i("div",{class:`canvas-viewport${Xo()?" pan-mode":""}`,ref:_,tabIndex:0,onPointerDown:C,onPointerMove:Z,onPointerLeave:()=>{c.current=null,ga(null)},onPointerUp:F,onContextMenu:W,onDblClick:B,onDragStart:H,onDragEnter:U,onDragOver:te,onDragLeave:xe,onDrop:Fe,style:{width:"100%",height:"100%",position:"relative",overflow:"hidden",cursor:r==="eraser"?"cell":r==="text"?"text":o||Ze.value||a.current||_t.value==="connect"?"crosshair":Xo()?"grab":"default"},children:[i("div",{ref:j,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(Lx,{},void 0,!1,void 0,this),i(kb,{},void 0,!1,void 0,this),i(tb,{},void 0,!1,void 0,this),i(ub,{},void 0,!1,void 0,this),i(db,{},void 0,!1,void 0,this),i(Zb,{nodes:N,edges:$e,onEdgeContextMenu:t},void 0,!1,void 0,this),Ze.value&&i("div",{class:"edge-hint-pill","data-testid":"edge-hint",style:{left:`${Ze.value.cursorX+14}px`,top:`${Ze.value.cursorY+14}px`},children:[i("span",{class:"edge-hint-main",children:Ze.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",Ze.value.withLabel?" · label on":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Te&&oo&&Zt&&i("div",{class:"drop-pill","data-testid":"drop-pill",style:{left:`${Zt.position.x}px`,top:`${Zt.position.y+Zt.size.height+10}px`},children:[i("span",{class:"drop-pill-text",children:Te.mode==="add"?`release to add to ${String(oo.data.title??"group")}`:`release to remove from ${String(oo.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(Nd,{annotations:Array.from(Vo.value.values())},void 0,!1,void 0,this),f&&f.points.length>=2&&i(Nd,{annotations:[f]},void 0,!1,void 0,this),qe.map((I)=>i(jb,{node:I,onContextMenu:e,children:wA(I)},I.id,!1,void 0,this)),No.value&&i("svg",{class:"snap-guides-svg",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:No.value.map((I,K)=>I.axis==="x"?i("line",{x1:I.pos,y1:I.from-20,x2:I.pos,y2:I.to+20,class:"snap-guide-line"},K,!1,void 0,this):i("line",{x1:I.from-20,y1:I.pos,x2:I.to+20,y2:I.pos,class:"snap-guide-line"},K,!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),v&&i("input",{class:"annotation-text-input",value:v.value,autoFocus:!0,style:{left:`${v.x*s.scale+s.x}px`,top:`${v.y*s.scale+s.y}px`,fontSize:`${qb*s.scale}px`},onInput:(I)=>R({...v,value:I.target.value}),onBlur:T,onPointerDown:(I)=>I.stopPropagation(),onKeyDown:(I)=>{if(I.key==="Enter")I.preventDefault(),T();if(I.key==="Escape")I.preventDefault(),R(null)}},void 0,!1,void 0,this),Kt&&i("div",{class:"lasso-rect",style:Kt},void 0,!1,void 0,this),h&&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 Xb(){let e=[...Ae.value],t=N.value,[n,o]=O(""),[r,s]=O(!1),a=ab.value,[c,l]=O(null),u=a.length>=2,d=!u&&a.length===1&&a[0].steerable?a[0]:null,p=u?c?a.find((v)=>v.value===c&&v.steerable)??null:null:d,f=p?.value??null,m=async()=>{let v=n.trim();if(!v||r)return;s(!0);let y=await wb(v,f);if(s(!1),y)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((v)=>{let y=t.get(v),x=typeof y?.data.title==="string"&&y.data.title.trim()?y.data.title:y?.type??v;return i("span",{class:"command-bar-chip","data-node-id":v,children:[i("span",{class:"command-bar-chip-glyph","aria-hidden":"true",children:"✦"},void 0,!1,void 0,this),i("span",{class:"command-bar-chip-label",title:x,children:x},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-chip-unpin","aria-label":`Unpin ${x}`,title:"Remove from context",onClick:()=>Ln(v),children:"×"},void 0,!1,void 0,this)]},v,!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(kr,{size:15,class:"command-bar-icon"},void 0,!1,void 0,this),u&&i("select",{class:"command-bar-target","aria-label":"Steer which agent",title:"Connected agents — steering reaches all of them unless you address one",value:f??"",onChange:(v)=>l(v.target.value||null),children:[i("option",{value:"",children:"All agents"},void 0,!1,void 0,this),a.map((v)=>{let y=v.pendingSteers&&v.pendingSteers>0?` · ${v.pendingSteers} queued`:"",x=v.polling?" · polling":"";return i("option",{value:v.value,disabled:!v.steerable,children:v.attached?`${v.label}${x}${y}`:v.steerable?`${v.label} · writer${x}${y}`:`${v.label} · no inbox`},v.value,!1,void 0,this)})]},void 0,!0,void 0,this),i("input",{class:"command-bar-input",type:"text",value:n,placeholder:`Steer ${p?.label??"the agent"}, or ${He("K")} to search the board…`,"aria-label":"Steer the agent",disabled:r,onInput:(v)=>o(v.target.value),onKeyDown:(v)=>{if(v.key==="Enter")v.preventDefault(),m()}},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-send",disabled:r||!n.trim(),onClick:()=>void m(),children:r?"Sending…":"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Od=De(()=>{if(It.value==="disconnected")return"reconnecting";if(It.value==="connected"&&!St.value&&go.value>1)return"resyncing";return null});function Kb(){let e=Od.value;if(!e)return null;if(e==="reconnecting"){let t=vo.value,n=yo.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 IA={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 Nt(e){if(e.x!==void 0&&e.y!==void 0)return Wt(e);let t=IA[e.type]??{width:360,height:200},n=e.width??t.width,o=e.height??t.height,r=Zo(),s=ee.value,a=await Wt({...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)tt(a.id);return a}var cc=!1,Jb=!1,Ro=null,zr=null;function Ld(){return cc}function lc(){cc=!1,Jb=!0,Yb()}function Yb(){if(Ro&&zr)Ro.removeEventListener("change",zr);Ro=null,zr=null}function zA(){if(typeof window>"u"||!window.location)return null;let e=new URLSearchParams(window.location.search).get("theme");if(e==="auto")return"auto";return di(e)?e:null}function Qb(e){if(Jb)return;let t=zA();if(!t)return;if(Yb(),cc=!0,t!=="auto"){e(t);return}Ro=window.matchMedia("(prefers-color-scheme: light)"),zr=()=>{if(cc&&Ro)e(Ro.matches?"light":"dark")},zr(),Ro.addEventListener("change",zr)}var PA='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Yn(e,t,n={}){D(()=>{if(!t)return;let o=e.current;if(!o)return;let r=document.activeElement,s=n.restoreTo,a=()=>Array.from(o.querySelectorAll(PA)),c=n.initial?.current??a()[0];if(c&&!o.contains(document.activeElement))c.focus();let l=(u)=>{if(u.key!=="Tab")return;let d=a();if(d.length===0)return;let p=d[0],f=d[d.length-1],m=document.activeElement;if(u.shiftKey&&(m===p||!o.contains(m)))u.preventDefault(),f.focus();else if(!u.shiftKey&&m===f)u.preventDefault(),p.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 NA(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 RA(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 Dd={md:"markdown",app:"mcp-app",web:"webpage",ui:"json-render",chart:"graph",ctx:"context",log:"ledger"};function $A(e){let t=e.toLowerCase().trim();if(t.startsWith("type:")){let n=t.slice(5).trim(),r=Object.keys(at).find((a)=>a.startsWith(n));if(r)return{typeFilter:r,remaining:""};let s=Dd[n];if(s)return{typeFilter:s,remaining:""}}if(Dd[t])return{typeFilter:Dd[t],remaining:""};return{typeFilter:null,remaining:e}}function ew({onClose:e,onToggleMinimap:t}){let[n,o]=O(""),[r,s]=O(0),a=M(null),c=M(null),l=M(null);Yn(l,!0,{initial:a}),D(()=>{setTimeout(()=>a.current?.focus(),30)},[]);let u=L(()=>{let h=[];for(let b of N.value.values()){let E=b.data.title||at[b.type],j=b.data.content||b.data.path||"",_=b.type==="group"&&Array.isArray(b.data.children)?b.data.children.length:0;h.push({id:`node:${b.id}`,kind:"node",label:E,description:b.type==="group"?`group · ${_} node${_===1?"":"s"}`:j.length>60?`${at[b.type].toLowerCase()} · ${j.slice(0,60)}…`:j?`${at[b.type].toLowerCase()} · ${j}`:at[b.type].toLowerCase(),icon:bn(b.type),nodeType:b.type,action:()=>{tt(b.id),e()}})}let g=[{label:"New markdown note",shortcut:"M",icon:Wn,iconTone:"accent",action:()=>{Nt({type:"markdown",title:"New note",width:520,height:360}),e()}},...ft.value?[]:[{label:"Start agent session",icon:kr,iconTone:"purple",action:()=>{Jn(),e()}}],{label:"Fit view",shortcut:"F",icon:Va,iconTone:"muted",action:()=>{Yo(st().width,st().height),e()}},{label:"Auto-arrange (grid)",icon:Ao,iconTone:"muted",action:()=>{Ls(),e()}},{label:"Auto-arrange (graph-aware)",icon:Ao,iconTone:"muted",action:()=>{Ds(),e()}},{label:"Toggle minimap",icon:Ga,iconTone:"muted",action:()=>{t(),e()}},{label:"Toggle theme (dark/light)",icon:Xa,iconTone:"muted",action:()=>{let b=Je.value==="dark"?"light":"dark";lc(),document.documentElement.setAttribute("data-theme",b),wr(),Je.value=b,Ss(b),e()}}];for(let b of g)h.push({id:`action:${b.label}`,kind:"action",label:b.label,...b.shortcut?{shortcut:b.shortcut}:{},icon:b.icon,...b.iconTone?{iconTone:b.iconTone}:{},action:b.action});return h},[e,t]),{typeFilter:d,remaining:p}=$A(n),f=u(),m;if(!n.trim())m=f.map((h)=>({...h,score:0,indices:[]}));else{m=[];for(let h of f){if(d){if(h.kind!=="node"||h.nodeType!==d)continue;if(!p){m.push({...h,score:0,indices:[]});continue}}let g=NA(p||n,h.label);if(g.match)m.push({...h,score:g.score,indices:g.indices})}m.sort((h,g)=>g.score-h.score)}m=[...m.filter((h)=>h.kind==="action"),...m.filter((h)=>h.kind==="node")];let v=m.findIndex((h)=>h.kind==="node");D(()=>{if(!n.trim()){On.value=null;return}let h=new Set;for(let g of m)if(g.kind==="node")h.add(g.id.slice(5));On.value=h.size>0?h:null},[n,m]),D(()=>()=>{On.value=null},[]);let y=Math.min(r,Math.max(0,m.length-1)),x=L((h)=>{if(h.key==="ArrowDown")h.preventDefault(),s((g)=>Math.min(g+1,m.length-1));else if(h.key==="ArrowUp")h.preventDefault(),s((g)=>Math.max(g-1,0));else if(h.key==="Enter"){if(h.preventDefault(),m[y])m[y].action()}else if(h.key==="Escape")h.preventDefault(),h.stopPropagation(),e()},[m,y,e]);return D(()=>{let h=c.current;if(!h)return;h.children[y]?.scrollIntoView({block:"nearest"})},[y]),D(()=>{s(0)},[n]),i("div",{class:"command-palette-backdrop",onMouseDown:e,children:i("div",{ref:l,class:"command-palette",role:"dialog","aria-modal":"true","aria-label":"Search and commands",onMouseDown:(h)=>h.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:a,type:"text",class:"command-palette-input",value:n,onInput:(h)=>o(h.target.value),onKeyDown:x,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:c,children:[m.length===0&&i("div",{class:"command-palette-empty",children:"No matching nodes or actions"},void 0,!1,void 0,this),m.map((h,g)=>{let b=h.icon,E=g===0&&h.kind==="action"?"Actions":g===v?"Jump to":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${g===y?" selected":""}`,onMouseEnter:()=>s(g),onClick:()=>h.action(),children:[i("span",{class:`command-palette-icon tone-${h.iconTone??"kind"}`,"aria-hidden":"true",children:i(b,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"command-palette-label",children:[h.indices.length>0?RA(h.label,h.indices):h.label,h.description&&i("span",{class:"command-palette-desc",children:[" — ",h.description]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h.shortcut&&i("kbd",{class:"command-palette-kbd",children:h.shortcut},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},h.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:He("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 tw(){let[e,t]=O(null),n=L((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"node",x:a.clientX,y:a.clientY,nodeId:c})},[]),o=L((a,c,l)=>{a.preventDefault(),a.stopPropagation(),t({kind:"canvas",x:a.clientX,y:a.clientY,canvasX:c,canvasY:l})},[]),r=L((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"edge",x:a.clientX,y:a.clientY,edgeId:c})},[]),s=L(()=>t(null),[]);return D(()=>{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 MA="#4bbcFF",OA=[{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 nw({menu:e,onClose:t}){let n;if(e.kind==="node"){let c=N.value.get(e.nodeId);if(!c)return null;n=HA(c)}else if(e.kind==="edge"){let c=e.edgeId,l=$e.value.get(c);n=[{label:l?.label?`Edit label “${l.label.slice(0,18)}${l.label.length>18?"…":""}”`:"Add label…",action:()=>{on("Edge label (empty clears it)","label text",{initial:l?.label??"",allowEmpty:!0,confirm:"Save"}).then((u)=>{if(u===null)return;As(c,{label:u})})}},{separator:!0},...["flow","depends-on","relation","references"].map((u)=>({label:`${l?.type===u?"✓":" "} ${u}`,action:()=>void As(c,{type:u})})),{separator:!0},...["solid","dashed","dotted"].map((u)=>({label:`${(l?.style??"solid")===u?"✓":" "} ${u}`,action:()=>void As(c,{style:u})})),{separator:!0},{label:"Delete edge",danger:!0,action:()=>void Is(c)}]}else n=ZA(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 d=`${l}:${u}`;if(c.separator)return i("div",{class:"context-menu-separator"},d,!1,void 0,this);if(c.render)return i("div",{class:"context-menu-custom",children:c.render(t)},d,!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)]},d,!0,void 0,this)})},void 0,!1,void 0,this)}function LA(e){return(typeof e.data.path==="string"?e.data.path.trim():"")||null}function uc(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 ow(e){if(typeof e.data.color!=="string"||!e.data.color.trim())return null;return uc(e.data.color)}function DA(e){let t=ow(e);return t&&/^#[0-9a-f]{6}$/.test(t)?t:uc(MA)}function Fd(e,t){let n=t?uc(t):null;et(e.id,{data:{...e.data,color:n}}),ct(e.id,{data:{color:n}})}function FA(e,t){let n=ow(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:()=>{Fd(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:OA.map((o)=>{let r=uc(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:()=>{Fd(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:DA(e),onClick:(o)=>o.stopPropagation(),onInput:(o)=>{Fd(e,o.currentTarget.value),t()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Zd(e,t,n,o){return{x:e-n/2,y:t-o/2}}function jA(e,t){return e.trim().replace(/[?#].*$/,"").split("/").filter(Boolean).at(-1)||t}async function jd(e){let t=await on(e.promptLabel,e.placeholder??"");if(!t)return;let n=t.trim();if(!n)return;let o=Zd(e.canvasX,e.canvasY,e.width,e.height);if(!(await Wt({type:e.type,...e.type!=="webpage"?{title:jA(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 ZA(e,t){return[{label:"New note",action:()=>{let r=Zd(e,t,520,360);Wt({type:"markdown",title:"New note",x:r.x,y:r.y,width:520,height:360})}},{label:"Open webpage...",action:()=>{jd({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:()=>{jd({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:()=>{jd({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."})}},{separator:!0},{label:"New group",action:()=>{let r=Zd(e,t,600,400);Uo({title:"Group",x:r.x,y:r.y,width:600,height:400})}}]}function HA(e){let t=[],n=LA(e);if(t.push({label:"Focus",action:()=>tt(e.id)}),t.push({label:"Rename…",action:()=>{on("Rename node","Node title",{initial:typeof e.data.title==="string"?e.data.title:"",confirm:"Save"}).then((l)=>{if(!l?.trim())return;ct(e.id,{title:l.trim()})})}}),Vr.has(e.type))t.push({label:"Expand",shortcut:"⤢",action:()=>en(e.id)});t.push({label:e.collapsed?"Expand":"Collapse",action:()=>Ko(e.id)});let o=Ae.value.has(e.id);t.push({label:o?"Unpin from context":"Pin as context",action:()=>Ln(e.id)}),t.push({label:e.pinned?"Unlock position":"Lock position (no auto-arrange)",action:()=>{let l=!e.pinned;et(e.id,{pinned:l}),ct(e.id,{pinned:l}),ot()}});let r=zs.value;if(r&&r.from!==e.id){let l=N.value.get(r.from),u=l?(l.data.title||l.id).slice(0,20):r.from;t.push({label:`Connect from "${u}"`,action:()=>{ho(r.from,e.id,"relation"),zs.value=null}})}t.push({label:r?"Connect from here (replace)":"Connect from here",action:()=>{zs.value={from:e.id}}});let s=Array.from($e.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:()=>Lg("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:()=>{Cs(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)=>FA(e,u)}),l.length>0)t.push({label:`Ungroup (${l.length} node${l.length!==1?"s":""})`,action:()=>{zt(e.id),Wo(e.id)}})}let a=typeof e.data.parentGroup==="string"?e.data.parentGroup:null,c=a?N.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((d)=>d!==e.id):[];t.push({label:`Remove from “${l}”`,action:()=>{Es(c.id,u)}})}return t.push({separator:!0}),t.push({label:e.type==="group"?"Delete frame (children stay)":"Delete",danger:!0,action:()=>{zt(e.id),$n(e.id)}}),t}function rw(){let e=Ae.value.size;if(e===0||nn.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:lv,title:"Clear all context pins",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function iw({onClose:e}){let t=M(null),[n,o]=O("Bug report"),[r,s]=O(""),[a,c]=O("");return Yn(t,!0),i("div",{class:"text-prompt-backdrop feedback-backdrop",onPointerDown:e,children:i("form",{ref:t,class:"text-prompt feedback-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"feedback-title","aria-describedby":"feedback-privacy",action:"https://github.com/pskoett/pmx-canvas/issues/new",method:"get",target:"_blank",rel:"noopener noreferrer",onPointerDown:(l)=>l.stopPropagation(),onKeyDown:(l)=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),e()},children:[i("div",{id:"feedback-title",class:"text-prompt-title",children:"Bug and feedback"},void 0,!1,void 0,this),i("p",{id:"feedback-privacy",class:"feedback-note",children:"Opens a draft issue in pskoett/pmx-canvas. Review and submit it on GitHub using your account. Issues are public. Only what you enter below is included; no board contents, workspace paths, screenshots, or logs are attached."},void 0,!1,void 0,this),i("label",{children:["Feedback type",i("select",{class:"text-prompt-input",value:n,onChange:(l)=>o(l.currentTarget.value),children:[i("option",{children:"Bug report"},void 0,!1,void 0,this),i("option",{children:"Feature request"},void 0,!1,void 0,this),i("option",{children:"General feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("label",{children:["Title",i("input",{class:"text-prompt-input",name:"title",required:!0,maxLength:120,value:r,onInput:(l)=>s(l.currentTarget.value),placeholder:"A short summary"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("label",{children:["Description",i("textarea",{class:"text-prompt-input",required:!0,maxLength:1200,rows:6,value:a,onInput:(l)=>c(l.currentTarget.value),placeholder:"What happened, what you expected, and steps to reproduce — or describe your idea."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{type:"hidden",name:"body",value:`## ${n}
328
+ </script>`}function ux(){return"<style data-pmx-canvas-ext-app-base>html, body { background: transparent !important; }</style>"}function dx(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 zr(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 Pd(e,t){let n=e?.getBoundingClientRect();return{width:zr(e?.clientWidth??0,zr(n?.width??0,t.width)),height:zr(e?.clientHeight??0,zr(n?.height??0,t.height))}}function mE(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>0&&!t}function fE(e,t){return Math.max(zr(e,1),zr(t,1))}function mx({node:e,expanded:t=!1}){let n=R(null),o=R(null),r=R(null),s=R(null),a=R({}),c=R(void 0),l=R(!1),u=R(void 0),p=R(null),d=R(!1),f=R(null),m=R(0),h=R([]),v=R(""),x=R(!1),g=R(!1),y=R([]),E=R(!1),L=R(!1),P=R(!1),b=R(!1),[T,w]=I("loading"),[_,z]=I(null),[U,N]=I(0),[Z,j]=I(!1),[S,V]=I(!1),[he,je]=I(()=>t||typeof navigator>"u"||typeof window>"u"||!Do(navigator.userAgent)),se=e.data.html,ue=e.data.serverName,pe=e.data.appSessionId,fo=e.data.toolInput??{},Vt=e.data.toolResult,sn=e.data.toolName??"ext-app",M=e.data.toolDefinition,K=e.data.toolCallId,me=typeof K==="string"||typeof K==="number"?K:void 0,ee=e.data.resourceMeta,Q=e.data.sessionStatus,te=e.data.sessionError,ne=e.size.height,W=e.id,le=cE(e,U),yt=uE(null),D=e.data.axCapabilities?.enabled===!0&&typeof se==="string"&&se.length>0,ae=Ie(()=>`ax-${crypto.randomUUID()}`,[]),De=D?dE(ae,W):"",ge=typeof se==="string"&&se.length>0?pE(ae,W):"",Gt=rx(dx(se??"",ux()+ge+De),yt);B(()=>{function X(oe){if(oe.source!==n.current?.contentWindow)return;let xe=oe.data;if(!xe||xe.source!==Ea||xe.token!==ae||xe.nodeId!==W)return;if(g.current=!0,xe.kind==="paint-tick"){let Re=xe,Ft={content:Re.content===!0,detail:typeof Re.detail==="string"?Re.detail:""};for(let Mn of h.current.splice(0))Mn(Ft)}}return window.addEventListener("message",X),()=>window.removeEventListener("message",X)},[ae,W]),B(()=>{if(he)return;cx({remount:()=>{if(b.current)return!1;return at(W,"mount-slot"),je(!0),!0},awaitBoot:()=>new Promise((X)=>{let oe=window.setTimeout(xe,ix);function xe(){window.clearTimeout(oe),X()}y.current.push(xe)})})},[]),Ar({enabled:D,token:ae,nodeId:W,sourceSurface:"mcp-app",iframeRef:n});let Xi=3,Xt=(X)=>{if(m.current>=Xi)return at(W,`remount-cap-hit (${X})`),!1;if(E.current)return!0;return m.current+=1,E.current=!0,at(W,`remount-queued #${m.current} (${X})`),cx({remount:()=>{if(E.current=!1,b.current||!t&&Ue.value===W)return at(W,"remount-skipped"),j(!1),!1;return L.current=typeof document<"u"&&document.visibilityState==="hidden",at(W,`remount-run #${m.current}`),w("loading"),N((oe)=>oe+1),!0},awaitBoot:()=>new Promise((oe)=>{let xe=window.setTimeout(Re,ix);function Re(){window.clearTimeout(xe),oe()}y.current.push(Re)})}),!0},Rn=1500,Hc=()=>new Promise((X)=>{let oe=n.current?.contentWindow;if(!oe||b.current){X("timeout");return}let xe=!1,Re=window.setTimeout(()=>{if(xe)return;xe=!0,X("timeout")},Rn);h.current.push((Ft)=>{if(xe)return;xe=!0,window.clearTimeout(Re),v.current=Ft.detail,X(Ft.content?"content-verified":"tick-no-content")}),oe.postMessage({source:Hu,token:ae},"*")}),kp=async(X)=>{let oe=Date.now()+X;while(Date.now()<oe&&!b.current){if(await Hc()==="content-verified")return!0;await new Promise((xe)=>window.setTimeout(xe,400))}return!1},D_=()=>new Promise((X)=>{let oe=n.current;if(!oe){X();return}let xe=oe.style.width,Re=oe.style.height;oe.style.width="140%",oe.style.height="140%",requestAnimationFrame(()=>{requestAnimationFrame(()=>{oe.style.width=xe,oe.style.height=Re,at(W,"soft-expand-cycle"),X()})})}),F_=600,Ki=()=>{if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;let X=n.current;if(!X||b.current)return;if(!sE({userAgent:navigator.userAgent,visibilityState:document.visibilityState,rect:X.getBoundingClientRect(),viewport:{width:window.innerWidth,height:window.innerHeight},alreadyRearmed:P.current}))return;P.current=!0,window.setTimeout(()=>{if(b.current||document.visibilityState==="visible")return;m.current=0,V(!1),L.current=!1,at(W,"assume-visible-rearm"),Xt("assume-visible")},F_)},jc=(X="")=>{let oe=v.current?` [${v.current}]`:"";return typeof document<"u"&&document.visibilityState==="hidden"?`paint-ok (content-verified)${oe}${X} (host hidden)`:`paint-ok (content-verified)${oe}${X}`},B_=async()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Do(navigator.userAgent))return;j(!0);let X=await Hc();if(X==="content-verified"){at(W,jc()),j(!1),Ki();return}if(at(W,X==="tick-no-content"?`paint-fail (tick without content: ${v.current||"unknown"})`:"paint-fail (no tick)"),await D_(),X=await Hc(),X==="content-verified"){at(W,jc(" (after soft-expand)")),j(!1),Ki();return}if(b.current)return;if(X==="tick-no-content"&&await kp(3000)){at(W,jc(" (after content wait)")),j(!1),Ki();return}if(b.current)return;if(!Xt("paint-fail"))at(W,"recovery-exhausted"),j(!1),V(!0),Ki()};B(()=>{if(t)return;if(typeof document>"u"||typeof navigator>"u"||typeof window>"u")return;if(!Do(navigator.userAgent))return;function X(){if(document.visibilityState!=="visible")return;if(!L.current||b.current)return;L.current=!1,m.current=0,V(!1),at(W,"visible-again-rearm"),Xt("visible-after-hidden-boot")}return document.addEventListener("visibilitychange",X),()=>document.removeEventListener("visibilitychange",X)},[t,W]);let H_=6000;B(()=>{if(typeof navigator>"u"||typeof window>"u")return;if(!Do(navigator.userAgent))return;if(!Gt.ready||!he)return;let X=window.setTimeout(()=>{if(x.current||g.current||b.current)return;Xt("boot-watchdog")},H_);return()=>window.clearTimeout(X)},[le,Gt.ready,t,he]),B(()=>()=>{b.current=!0;for(let X of y.current.splice(0))X();for(let X of h.current.splice(0))X({content:!1,detail:"unmounted"})},[]);let Zc=(X)=>kr(X),$n=t||Ue.value===W;a.current=fo,c.current=Vt;let Ji=Q==="error"&&typeof se==="string"&&se.length>0,Uc=Q==="error"?Ji?`Live session unavailable — showing saved content. Reopen the app to restore interactivity.${te?` (${te})`:""}`:te??"Saved app session is unavailable. Reopen the app to restore interactivity.":"Reconnecting saved app session...",qc=(X)=>{let oe=c.current;if(!X||!d.current||!oe)return null;if(u.current===oe)return null;if(u.current&&nx(u.current,oe))return u.current=oe,null;if(p.current)return p.current;let xe=X.sendToolResult(oe).then(()=>{u.current=oe,l.current=!0,w("done")}).catch((Re)=>{let Ft=Re instanceof Error?Re.message:String(Re);throw z(`Tool result delivery failed: ${Ft}`),Re}).finally(()=>{p.current=null});return p.current=xe,xe};if(B(()=>{if(!se||!Gt.ready||!he)return;let X=n.current;if(!X)return;let oe=!1,xe=null,Re=null,Ft=null,Mn=null,ho=null;l.current=!1,u.current=void 0,p.current=null,d.current=!1,x.current=!1,g.current=!1;let Yi=()=>{if(!xe)return;clearTimeout(xe),xe=null};return(async()=>{if(!se)return;let On=X.contentWindow;if(!On)throw Error("Ext-app iframe window is unavailable");let go=(ve=Ue.value===W?"fullscreen":"inline")=>({theme:Zc(et.value),platform:"web",containerDimensions:Pd(X,{width:e.size.width,height:ne}),displayMode:ve,locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,...M?{toolInfo:{id:me,tool:M}}:{}}),j_=()=>{if(Mn!==null)return;Mn=requestAnimationFrame(()=>{if(Mn=null,oe||!d.current)return;$e.setHostContext?.(go())})},Cp=()=>{if(ho!==null)return;ho=requestAnimationFrame(()=>{ho=requestAnimationFrame(()=>{if(ho=null,oe||!d.current)return;$e.sendHostContextChange?.(go())})})},Tp=()=>{if(!Do(navigator.userAgent))return;if(Re)clearTimeout(Re);Re=setTimeout(()=>{if(Re=null,oe)return;B_()},px+200)},$e=new Id(null,{name:"PMX Canvas",version:"1.0.0"},{openLinks:{},serverTools:{listChanged:!1},serverResources:{listChanged:!1},logging:{},updateModelContext:{text:{},structuredContent:{}}},{hostContext:go($n?"fullscreen":"inline")});$e.onsizechange=async({height:ve})=>{if(mE(ve,Ue.value===W)){let nt=Pd(X.parentElement??X,{width:e.size.width,height:ne}),Bt=fE(ve,nt.height);X.style.height=`${Bt}px`;let vo=F.value.get(W)?.size??e.size,Ep=Math.max(vo.height,Bt+xr);if(Math.abs(Ep-vo.height)>8){if(aa(W,{width:vo.width,height:Ep}),s.current!==null)window.clearTimeout(s.current);s.current=window.setTimeout(()=>{st({recordHistory:!1}),s.current=null},0)}}return{}},$e.onopenlink=async({url:ve})=>(window.open(ve,"_blank","noopener"),{}),$e.onsandboxready=async()=>{await $e.sendSandboxResourceReady({html:dx(se,ux()),sandbox:ju,...ee?.csp?{csp:ee.csp}:{},...ee?.permissions?{permissions:ee.permissions}:{}})},$e.onrequestdisplaymode=async({mode:ve})=>{let{nextMode:nt,shouldExpand:Bt,shouldCollapse:vo}=lE(ve,$n);if(Bt)Zt(W);else if(vo)Cn();return{mode:nt}},$e.oncalltool=async(ve)=>{if(!pe)throw Error(Uc);try{let nt=await Lo("/api/ext-app/call-tool",{sessionId:pe,nodeId:W,serverName:ue,toolName:ve.name,arguments:ve.arguments??{}});return z(null),nt}catch(nt){let Bt=nt instanceof Error?nt.message:String(nt);throw z(`Tool call failed: ${Bt}`),nt}},$e.setRequestHandler(tc,async()=>{if(!pe)return{tools:[]};return Lo("/api/ext-app/list-tools",{sessionId:pe})}),$e.onlistresources=async()=>pe?Lo("/api/ext-app/list-resources",{sessionId:pe}):{resources:[]},$e.onlistresourcetemplates=async()=>pe?Lo("/api/ext-app/list-resource-templates",{sessionId:pe}):{resourceTemplates:[]},$e.onreadresource=async(ve)=>{if(!pe)throw Error(Uc);return Lo("/api/ext-app/read-resource",{sessionId:pe,uri:ve.uri})},$e.onlistprompts=async()=>pe?Lo("/api/ext-app/list-prompts",{sessionId:pe}):{prompts:[]},$e.onupdatemodelcontext=async(ve)=>{if(!pe)return{};return await Lo("/api/ext-app/model-context",{nodeId:W,...Array.isArray(ve.content)?{content:ve.content}:{},...ve.structuredContent&&typeof ve.structuredContent==="object"?{structuredContent:ve.structuredContent}:{}}),{}};let Wc=new Td(On,On);if($e.oninitialized=()=>{if(oe)return;Yi(),d.current=!0,x.current=!0,at(W,"initialized"),w("ready"),z(null),Promise.resolve($e.sendHostContextChange(go($n?"fullscreen":"inline"))).then(()=>lx($e,a.current,void 0)).then(()=>qc($e)).then(()=>{let ve=()=>{for(let nt of y.current.splice(0))nt()};if(typeof navigator<"u"&&Do(navigator.userAgent))kp(4000).then((nt)=>{at(W,nt?"settled (content-verified)":`settled (content-timeout${v.current?`: ${v.current}`:""})`),ve()});else at(W,"settled"),ve();Cp(),Tp()}).catch((ve)=>{let nt=ve instanceof Error?ve.message:String(ve);z(`Bridge bootstrap failed: ${nt}`)})},xe=setTimeout(()=>{if(oe||d.current)return;let ve=c.current,nt=go($n?"fullscreen":"inline");d.current=!0,$e.setHostContext?.(nt),Promise.resolve($e.sendHostContextChange(nt)).then(()=>lx($e,a.current,ve)).then(()=>{if(l.current=Boolean(ve),ve)u.current=ve;if(w(ve?"done":"ready"),z(null),Cp(),Tp(),g.current){at(W,"settled (fallback)");for(let Bt of y.current.splice(0))Bt()}}).catch((Bt)=>{let vo=Bt instanceof Error?Bt.message:String(Bt);z(`Bridge bootstrap fallback failed: ${vo}`)})},1200),await $e.connect(Wc),oe){Yi(),await Wc.close();return}if(o.current=$e,r.current=Wc,Ft=new ResizeObserver(j_),Ft.observe(X),X.parentElement)Ft.observe(X.parentElement);let Ip=!0;f.current=et.subscribe((ve)=>{if(Ip){Ip=!1;return}if(oe)return;$e.setHostContext?.({...go(),theme:Zc(ve)}),$e.sendHostContextChange?.(go())}),qc($e)})().catch((On)=>{Yi(),console.error("[ext-app] Bridge init failed:",On),z(On?.message??"Bridge initialization failed")}),()=>{if(oe=!0,Yi(),Re)clearTimeout(Re),Re=null;if(Ft?.disconnect(),Ft=null,Mn!==null)cancelAnimationFrame(Mn),Mn=null;if(ho!==null)cancelAnimationFrame(ho),ho=null;if(d.current=!1,p.current=null,f.current?.(),f.current=null,s.current!==null)window.clearTimeout(s.current),s.current=null;if(o.current=null,r.current)r.current.close().catch((On)=>{console.error("[ext-app] transport close failed:",On)}),r.current=null}},[le,Gt.key,he]),B(()=>{if(Vt&&o.current&&(T==="ready"||T==="done"))qc(o.current)},[Vt,T]),B(()=>{let X=o.current;if(n.current)n.current.style.height="100%";if(!X||!d.current)return;let oe=null,xe=null;return oe=requestAnimationFrame(()=>{oe=null,xe=requestAnimationFrame(()=>{if(xe=null,!d.current)return;let Re={theme:Zc(et.value),platform:"web",containerDimensions:Pd(n.current,{width:e.size.width,height:ne}),displayMode:$n?"fullscreen":"inline",locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};X.setHostContext?.(Re),X.sendHostContextChange?.(Re)})}),()=>{if(oe!==null)cancelAnimationFrame(oe);if(xe!==null)cancelAnimationFrame(xe)}},[$n,ne]),!se)return i("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--c-muted)",fontSize:"13px",flexDirection:"column",gap:"8px"},children:[i("div",{style:{opacity:0.6},children:["Loading ",sn," viewer..."]},void 0,!0,void 0,this),i("div",{style:{width:"24px",height:"24px",border:"2px solid var(--c-line)",borderTopColor:"var(--c-muted)",borderRadius:"50%",animation:"spin 1s linear infinite"}},void 0,!1,void 0,this),i("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{style:{flex:1,width:"100%",height:"100%",minWidth:0,minHeight:0,display:"flex",flexDirection:"column"},children:[Q&&Q!=="ready"&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:Q==="error"&&!Ji?"var(--c-danger-12)":"var(--c-warn-10)",color:Q==="error"&&!Ji?"var(--c-danger)":"var(--c-warn)",borderBottom:`1px solid ${Q==="error"&&!Ji?"var(--c-danger-12)":"var(--c-warn-15)"}`},children:Uc},void 0,!1,void 0,this),_&&i("div",{style:{padding:"6px 10px",fontSize:"11px",background:"var(--c-danger-12)",color:"var(--c-danger)",borderBottom:"1px solid var(--c-danger-12)",display:"flex",alignItems:"center",gap:"6px"},children:[i("span",{children:"⚠"},void 0,!1,void 0,this),i("span",{style:{flex:1},children:_},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>{z(null),w("loading"),N((X)=>X+1)},style:{background:"var(--c-surface-hover)",border:"1px solid var(--c-danger-12)",borderRadius:"3px",color:"var(--c-danger)",cursor:"pointer",fontSize:"10px",padding:"1px 6px"},children:"Retry"},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>z(null),style:{background:"none",border:"none",color:"var(--c-danger)",cursor:"pointer",fontSize:"13px",padding:"0 2px"},children:"×"},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:[he&&i("iframe",{ref:n,...Gt.attributes,sandbox:yt,allow:tx(ee?.permissions),style:{flex:1,width:"100%",height:"100%",minHeight:0,border:"none",background:"var(--c-panel)",pointerEvents:$n?"auto":"none"},title:`Ext App: ${sn}`},le,!1,void 0,this),S&&!_&&i("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"10px",background:"var(--c-panel)",color:"var(--c-warn)",fontSize:"12px"},children:[i("div",{children:"App surface failed to paint."},void 0,!1,void 0,this),i("button",{type:"button",onClick:(X)=>{X.stopPropagation(),at(W,"manual-retry"),m.current=0,V(!1),w("loading"),N((oe)=>oe+1)},style:{background:"var(--c-surface-hover)",border:"1px solid var(--c-warn-15)",borderRadius:"4px",color:"var(--c-warn)",cursor:"pointer",fontSize:"11px",padding:"3px 10px"},children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(T==="loading"||Z)&&!_&&!S&&i("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"10px",background:"var(--c-panel)",color:"var(--c-muted)",fontSize:"12px",pointerEvents:"none"},children:[i("div",{style:{width:"22px",height:"22px",border:"2px solid var(--c-line)",borderTopColor:"var(--c-muted)",borderRadius:"50%",animation:"spin 1s linear infinite"}},void 0,!1,void 0,this),i("div",{children:T==="loading"?`Connecting to ${sn}...`:"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),!$n&&!(S&&!_)&&i("button",{type:"button",onClick:(X)=>{X.stopPropagation(),Zt(W)},class:"ext-app-preview-catcher",title:"Click to open",style:{position:"absolute",top:0,right:"56px",bottom:"56px",left:0,background:"transparent",border:"none",padding:0,margin:0,cursor:"zoom-in"},"aria-label":"Open full view to edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function hE(e,t,n,o,r,s,a){if(!e)return e;try{let c=new URL(e,window.location.origin);if(c.searchParams.set("theme",kr(et.value)),t)c.searchParams.set("display","expanded");if(typeof n==="number")c.searchParams.set("v",String(n));if(o)c.searchParams.set("axToken",o);if(r)c.searchParams.set("axNodeId",r);if(s)c.searchParams.set("frameToken",s);if(a)c.searchParams.set("fit","content");return c.toString()}catch{return e}}function gE(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 Nd({source:e,iframeRef:t,onLoad:n,title:o,className:r="mcp-app-frame",sandbox:s="allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox",allow:a="clipboard-read; clipboard-write",tabIndex:c}){let l=e.src??e.srcdoc??"",[u,p]=I({key:l,source:e}),[d,f]=I(null),m=R(0);B(()=>{if(m.current+=1,!l||l===u.key){f(null);return}if(!u.key){p({key:l,source:e});return}f({key:l,source:e})},[l,u.key]),B(()=>()=>{m.current+=1},[]);let h=(v,x)=>i("iframe",{ref:x?void 0:t,...v.source,class:r,sandbox:s,allow:a,tabIndex:c,loading:wt.value==="srcdoc"?void 0:"lazy",onLoad:(g)=>{if(!x){n();return}let y=++m.current,E=g.currentTarget;requestAnimationFrame(()=>requestAnimationFrame(()=>{if(m.current!==y)return;t.current=E,p(v),f(null),n()}))},style:{position:"absolute",inset:0,width:"100%",height:"100%",visibility:x?"hidden":"visible",background:"var(--c-panel-soft)"},title:o},v.key,!1,void 0,this);return i("div",{class:"mcp-app-frame-stack",children:[h(u,!1),d&&h(d,!0)]},void 0,!0,void 0,this)}function to({node:e,expanded:t=!1}){if(e.data.mode==="ext-app")return i(mx,{node:e,expanded:t},void 0,!1,void 0,this);return i(vE,{node:e,expanded:t},void 0,!1,void 0,this)}function vE({node:e,expanded:t}){let n=R(null),o=e.type==="mcp-app"&&e.data.viewerType==="web-artifact",r=e.type==="json-render"||e.type==="graph",s=e.data.axCapabilities?.enabled,c=(r||o)&&(o?s===!0:s!==!1),l=o?"mcp-app":"json-render",u=Ie(()=>c?`ax-${crypto.randomUUID()}`:"",[c]),p=Ju(e)&&!t,d=Ie(()=>p?`frame-${crypto.randomUUID()}`:"",[p]);wr(e,n,d),Ar({enabled:c&&Boolean(u),token:u,nodeId:e.id,sourceSurface:l,iframeRef:n});let f=tn.value,m=()=>{if(!c||!u||f==null)return;n.current?.contentWindow?.postMessage({source:Ut,type:"ax-update",token:u,state:f},"*")};B(m,[c,u,f]);let h=typeof e.data.specVersion==="number"?e.data.specVersion:void 0,v=hE(e.data.url||"",t,h,u||void 0,c?e.id:void 0,d||void 0,p),x=_r(v),g=e.data.sourceServer||"",y=e.data.hostMode||"hosted",E=e.data.fallbackReason,L=e.data.trustedDomain===!0||gE(v);if(y==="fallback")return i("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[i("div",{style:{color:"var(--c-warn)",display:"flex",alignItems:"center",gap:"6px"},children:[i("span",{children:"⚠"},void 0,!1,void 0,this),i("span",{children:"Cannot embed — opened externally"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E&&i("div",{style:{color:"var(--c-muted)",fontSize:"11px"},children:["Reason: ",E]},void 0,!0,void 0,this),i("a",{href:v,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all"},children:v},void 0,!1,void 0,this),g&&i("div",{style:{color:"var(--c-dim)",fontSize:"10px"},children:["Source: ",g]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return i("div",{style:{height:"100%",display:"flex",flexDirection:"column",...t?{flex:1,minHeight:0,width:"100%"}:{}},children:[!L&&i("div",{style:{padding:"4px 8px",fontSize:"10px",background:"var(--c-warn-10)",color:"var(--c-warn)",borderBottom:"1px solid var(--c-warn-15)"},children:"Unverified domain"},void 0,!1,void 0,this),i(Nd,{source:x,iframeRef:n,onLoad:m,title:`MCP App: ${g}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var yE=null;function Pr(){yE=null}var fx={idle:"var(--c-muted)",running:"var(--c-accent)",planning:"var(--c-thinking)",thinking:"var(--c-thinking)",drafting:"var(--c-accent)",tooling:"var(--c-accent)",review:"var(--c-ok)","waiting-approval":"var(--c-warn)",waiting:"var(--c-warn-alt)"};function bE(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 sc({node:e}){let t=bE(e),n=e.data.detail||"",o=e.data.message||"",r=e.data.level||"ok",s=e.data.activeTool,a=e.data.subagent,c=fx[t]??"var(--c-muted)",l=t!=="idle";return i("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i("div",{style:{width:"8px",height:"8px",borderRadius:"50%",background:c,boxShadow:l?`0 0 8px ${c}`:"none",animation:l?"pulse 1.5s infinite":"none",flexShrink:0}},void 0,!1,void 0,this),i("span",{style:{fontWeight:600,color:c,textTransform:"uppercase",letterSpacing:"0.05em"},children:t},void 0,!1,void 0,this),n&&i("span",{style:{color:"var(--c-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-warn)"},children:[i("span",{style:{fontSize:"10px"},children:"⚙"},void 0,!1,void 0,this),i("span",{style:{fontFamily:"var(--mono)",fontSize:"11px"},children:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a&&a.state!=="completed"&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-subagent)"},children:[i("span",{style:{fontSize:"10px"},children:"⠉"},void 0,!1,void 0,this),i("span",{children:a.name},void 0,!1,void 0,this),i("span",{style:{color:"var(--c-muted)",fontSize:"10px"},children:["(",a.state,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),o&&i("div",{style:{color:r==="warn"?"var(--c-warn)":r==="error"?"var(--c-danger)":"var(--c-muted)",lineHeight:1.4},children:o},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Nr(e){return typeof e==="string"&&e.trim().length>0?e.trim():null}function hx(e){if(typeof e==="string"){let r=Nr(e);return r?{title:"Evidence warning",detail:r}:null}if(!e||typeof e!=="object")return null;let t=e,n=Nr(t.title)??"Evidence warning",o=Nr(t.detail);return o?{title:n,detail:o}:null}function xE(e){let t=[],n=hx(e.data.warning);if(n)t.push(n);let o=e.data.warnings;if(Array.isArray(o))for(let s of o){let a=hx(s);if(a)t.push(a)}let r=Nr(e.data.validationStatus)?.toLowerCase();if(r==="failed"||r==="invalid")t.push({title:"Image failed validation",detail:Nr(e.data.validationMessage)??"Review this image before using it as evidence."});return t}function wE(e){let t=[e.data.title,e.data.caption,e.data.alt,e.data.src,e.data.path].map((n)=>Nr(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 gx(e){let t=xE(e);if(t.length>0)return t;if(wE(e))return[{title:"Captured login page",detail:"This image looks like an auth screen. Treat it as environment context, not product evidence."}];return[]}function ac({node:e,expanded:t=!1}){let n=e.data.src||"",o=e.data.alt||e.data.title||"Image",r=e.data.caption||"",s=gx(e),a=n.startsWith("data:")||n.startsWith("http://")||n.startsWith("https://")?n:`/api/canvas/image/${e.id}`,[c,l]=I(!1),[u,p]=I(!1),[d,f]=I(1),[m,h]=I({x:0,y:0}),[v,x]=I({w:0,h:0}),g=R(null),y=R(!1),E=R({x:0,y:0}),L=H((Z)=>{let j=Z.target;x({w:j.naturalWidth,h:j.naturalHeight}),l(!0),p(!1)},[]),P=H(()=>{p(!0),l(!1)},[]);B(()=>{f(1),h({x:0,y:0})},[n]);let b=H((Z)=>{Z.preventDefault(),Z.stopPropagation();let j=Z.deltaY>0?0.9:1.1;f((S)=>Math.max(0.25,Math.min(10,S*j)))},[]),T=H((Z)=>{if(d<=1)return;Z.stopPropagation(),y.current=!0,E.current={x:Z.clientX,y:Z.clientY},Z.target.setPointerCapture(Z.pointerId)},[d]),w=H((Z)=>{if(!y.current)return;let j=Z.clientX-E.current.x,S=Z.clientY-E.current.y;E.current={x:Z.clientX,y:Z.clientY},h((V)=>({x:V.x+j,y:V.y+S}))},[]),_=H(()=>{y.current=!1},[]),z=H(()=>{f(1),h({x:0,y:0})},[]);if(!n)return i("div",{class:"image-node-empty",children:[i("div",{class:"image-node-empty-icon",children:"\uD83D\uDDBC"},void 0,!1,void 0,this),i("div",{class:"image-node-empty-text",children:"No image source"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let U=v.w>0?`${v.w}×${v.h}`:"",N=Math.round(d*100);return i("div",{class:`image-node ${t?"image-node-expanded":""}`,ref:g,children:[s.length>0&&i("div",{class:"image-node-warning-stack",children:s.map((Z)=>i("div",{class:"image-node-warning",children:[i("span",{class:"image-node-warning-title",children:Z.title},void 0,!1,void 0,this),i("span",{class:"image-node-warning-detail",children:Z.detail},void 0,!1,void 0,this)]},`${Z.title}-${Z.detail}`,!0,void 0,this))},void 0,!1,void 0,this),i("div",{class:"image-node-viewport",onWheel:b,onPointerDown:T,onPointerMove:w,onPointerUp:_,style:{cursor:d>1?"grab":"default"},children:[!c&&!u&&i("div",{class:"image-node-loading",children:"Loading…"},void 0,!1,void 0,this),u&&i("div",{class:"image-node-error",children:[i("div",{class:"image-node-error-icon",children:"⚠"},void 0,!1,void 0,this),i("div",{children:"Failed to load image"},void 0,!1,void 0,this),i("div",{class:"image-node-error-path",children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("img",{src:a,alt:o,onLoad:L,onError:P,draggable:!1,style:{transform:`translate(${m.x}px, ${m.y}px) scale(${d})`,opacity:c?1:0,display:u?"none":"block"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(r||U||d!==1)&&i("div",{class:"image-node-footer",children:[r&&i("span",{class:"image-node-caption",children:r},void 0,!1,void 0,this),i("span",{class:"image-node-meta",children:[U&&i("span",{children:U},void 0,!1,void 0,this),d!==1&&i("button",{type:"button",class:"image-node-zoom-reset",onClick:z,title:"Reset zoom",children:[N,"% ↺"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function vx({node:e}){if((e.data.children??[]).filter((o)=>F.value.has(o)).length>0)return null;return i("div",{class:"group-empty-hint",children:"Drop nodes here — release while the frame lights up to add them"},void 0,!1,void 0,this)}function _E(e){try{return new URL(e).host}catch{return e}}function SE(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleString()}function cc({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=SE(typeof e.data.fetchedAt==="string"?e.data.fetchedAt:void 0),u=typeof e.data.statusCode==="number"?e.data.statusCode:null,p=typeof e.data.imageUrl==="string"?e.data.imageUrl:"",d=e.data.frameBlocked===!0,f=typeof e.data.frameBlockedReason==="string"?e.data.frameBlockedReason:"",[m,h]=I(!1),[v,x]=I(t);B(()=>{if(t)x(!0)},[t]);let g=H(async()=>{if(!n||m)return;h(!0);try{await Ks(e.id)}finally{h(!1)}},[e.id,m,n]);if(!n)return i("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No webpage URL set"},void 0,!1,void 0,this);let y=a==="ready"?"var(--c-ok)":a==="error"?"var(--c-danger)":"var(--c-warn)";return i("div",{style:{display:"flex",flexDirection:"column",gap:"12px",height:"100%"},children:[i("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[i("div",{style:{minWidth:0,flex:1},children:[i("div",{style:{fontSize:"12px",color:"var(--c-muted)"},children:_E(n)},void 0,!1,void 0,this),i("div",{style:{fontSize:t?"18px":"15px",fontWeight:700,color:"var(--c-text)"},children:o||e.data.title||n},void 0,!1,void 0,this),i("a",{href:n,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all",textDecoration:"none"},children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"999px",background:"rgba(255,255,255,0.04)",color:y,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.04em",flexShrink:0},children:[i("span",{style:{width:"7px",height:"7px",borderRadius:"999px",background:y}},void 0,!1,void 0,this),a]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),(r||p)&&i("div",{style:{display:"grid",gridTemplateColumns:p&&t?"160px 1fr":"1fr",gap:"12px",alignItems:"start"},children:[p&&t&&i("img",{src:p,alt:o||"Webpage preview image",style:{width:"160px",height:"96px",objectFit:"cover",borderRadius:"10px",border:"1px solid var(--c-line)",background:"var(--c-panel-soft)"}},void 0,!1,void 0,this),r&&i("p",{style:{margin:0,color:"var(--c-text-soft)",lineHeight:1.5,fontSize:t?"14px":"12px"},children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{style:{display:"flex",gap:"8px",flexWrap:"wrap"},children:[i("button",{type:"button",onClick:g,disabled:m,style:{border:"1px solid var(--c-line)",background:"var(--c-panel-soft)",color:"var(--c-text)",borderRadius:"8px",padding:"6px 10px",cursor:m?"progress":"pointer",fontSize:"12px"},children:m||a==="fetching"?"Refreshing…":"Refresh"},void 0,!1,void 0,this),t&&!d&&i("button",{type:"button",onClick:()=>x((E)=>!E),style:{border:"1px solid var(--c-line)",background:"var(--c-panel-soft)",color:"var(--c-text)",borderRadius:"8px",padding:"6px 10px",cursor:"pointer",fontSize:"12px"},children:v?"Hide live preview":"Show live preview"},void 0,!1,void 0,this),i("button",{type:"button",onClick:()=>window.open(n,"_blank","noopener"),style:{border:"1px solid var(--c-line)",background:"transparent",color:"var(--c-accent)",borderRadius:"8px",padding:"6px 10px",cursor:"pointer",fontSize:"12px"},children:"Open in browser"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&d&&i("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[i("div",{style:{padding:"8px 12px",fontSize:"11px",color:"var(--c-muted)",borderBottom:"1px solid var(--c-line)",background:"rgba(255,255,255,0.03)"},children:"Live preview unavailable. This site refuses embedding, so PMX Canvas cannot show it inline."},void 0,!1,void 0,this),i("div",{style:{padding:"20px",color:"var(--c-text-soft)",lineHeight:1.6,fontSize:"13px"},children:f||"The remote site blocks iframe embedding."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&v&&!d&&i("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[i("div",{style:{padding:"8px 12px",fontSize:"11px",color:"var(--c-muted)",borderBottom:"1px solid var(--c-line)",background:"rgba(255,255,255,0.03)"},children:"Live preview (best effort). If this stays blank, the site likely blocks framing. The cached text snapshot below still works."},void 0,!1,void 0,this),i("iframe",{class:"webpage-node-iframe",title:o||e.data.title||n,src:n,loading:"lazy",referrerPolicy:"no-referrer",sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-presentation allow-scripts",style:{display:"block",width:"100%",height:t?"320px":"180px",border:"none",background:"#fff"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(l||u!==null)&&i("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap",color:"var(--c-muted)",fontSize:"11px"},children:[l&&i("span",{children:["Fetched ",l]},void 0,!0,void 0,this),u!==null&&i("span",{children:["HTTP ",u]},void 0,!0,void 0,this),d&&i("span",{children:"Preview blocked by site"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c&&i("div",{style:{color:"var(--c-danger)",fontSize:"12px",lineHeight:1.5},children:c},void 0,!1,void 0,this),i("div",{style:{flex:1,minHeight:0,overflow:"auto",border:"1px solid var(--c-line)",borderRadius:"10px",background:"var(--c-panel-soft)",padding:t?"14px":"10px"},children:s?i("div",{style:{whiteSpace:"pre-wrap",lineHeight:1.55,color:"var(--c-text)",fontSize:t?"14px":"12px"},children:s},void 0,!1,void 0,this):i("div",{style:{color:"var(--c-dim)",fontStyle:"italic"},children:a==="error"?"No cached page text available.":"Waiting for page text..."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function yx(e){return e.type==="html"&&e.data.presentation===!0}function Di({node:e,expanded:t=!1,presentation:n=!1,presentationExitToken:o,autoFocus:r=!1}){let s=R(null),a=et.value,c=Ie(()=>`theme-${crypto.randomUUID()}`,[]),l=Ie(()=>`ax-${crypto.randomUUID()}`,[]),u=Ie(()=>`frame-${crypto.randomUUID()}`,[]),p=typeof e.data.html==="string"?e.data.html:typeof e.data.content==="string"?e.data.content:"",d=Ie(()=>gr(p),[p]),f=Ie(()=>p?_i(e.id,{theme:a,themeToken:c,present:n,presentToken:o,v:d,axToken:l,frameToken:u}):"",[p,n,o,c,d,e.id,l,u]),m=_r(f);wr(e,s,t?"":u),Ar({enabled:!0,token:l,nodeId:e.id,sourceSurface:"html-node",iframeRef:s}),B(()=>{if(s.current?.contentWindow?.postMessage({source:Ut,type:"theme-update",token:c,theme:a},"*"),r)s.current?.focus()},[a,c]);let h=e.data.axCapabilities,v=h?.enabled===!0&&(!Array.isArray(h.allowed)||h.allowed.length>0),x=tn.value;B(()=>{if(!v||x==null)return;s.current?.contentWindow?.postMessage({source:Ut,type:"ax-update",token:l,state:x},"*")},[v,x,l]),B(()=>{if(!r)return;let y=window.setTimeout(()=>s.current?.focus(),0);return()=>window.clearTimeout(y)},[r,f]);let g=()=>{if(s.current?.contentWindow?.postMessage({source:Ut,type:"theme-update",token:c,theme:a},"*"),v&&tn.value!=null)s.current?.contentWindow?.postMessage({source:Ut,type:"ax-update",token:l,state:tn.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(Nd,{source:m,iframeRef:s,className:n?"html-node-frame html-node-frame-presentation":t?"html-node-frame html-node-frame-expanded":"html-node-frame",title:typeof e.data.title==="string"?e.data.title:"HTML node",sandbox:"allow-scripts",allow:"",tabIndex:r?0:void 0,onLoad:g},void 0,!1,void 0,this)}var Rd=null;async function bx(){if(!Rd)Rd=await Ev();return Rd}function xx(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 kE(e){return e.replace(/<script[\s>][\s\S]*?<\/script>/gi,"").replace(/<iframe[\s>][\s\S]*?<\/iframe>/gi,"").replace(/<object[\s>][\s\S]*?<\/object>/gi,"").replace(/<embed[\s>][\s\S]*?(?:\/>|<\/embed>)/gi,"").replace(/<link[\s>][\s\S]*?(?:\/>|<\/link>)/gi,"").replace(/\bon\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,"").replace(/href\s*=\s*"javascript:[^"]*"/gi,'href="#"').replace(/href\s*=\s*'javascript:[^']*'/gi,"href='#'")}function CE({html:e}){let t=R(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=e,n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function TE(e,t){return`${e.role}:${e.status??"none"}:${t}:${e.text}`}function wx({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 _x({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,style:{background:"none",border:"none",color:"var(--c-danger)",cursor:"pointer",fontSize:"13px",padding:"0 2px"},children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function lc({node:e,expanded:t=!1}){let n=Array.isArray(e.data.turns)?e.data.turns:[],o=n.length===0,r=e.data.text||"",s=e.data.status||"draft",a=o?s:e.data.threadStatus||"draft",c=a==="draft",l=a==="pending"||a==="sending",u=a==="streaming",p=a==="answered",[d,f]=I(""),[m,h]=I(""),[v,x]=I(null),[g,y]=I(new Map),E=R(null),L=R(null),P=n[n.length-1],b=`${n.length}:${P?.role??""}:${P?.status??""}:${Math.floor((P?.text?.length??0)/200)}`;B(()=>{if(t&&c&&E.current)E.current.focus()},[t,c]),B(()=>{if(!b)return;if(L.current)L.current.scrollTo({top:L.current.scrollHeight,behavior:"smooth"})},[b]);let T=R(null),w=R(n);w.current=n,B(()=>{let j=n.some((V)=>V.role==="assistant"&&V.status==="streaming"),S=()=>{let V=!1,je=w.current.map((se,ue)=>({turn:se,index:ue})).filter(({turn:se})=>se.role==="assistant"&&se.text);if(je.length===0)return;return Promise.all(je.map(async({turn:se,index:ue})=>{let pe=await bn(se.text);return{index:ue,html:kE(pe)}})).then((se)=>{if(V)return;let ue=new Map;for(let pe of se)ue.set(pe.index,pe.html);y(ue)}),()=>{V=!0}};if(!j){if(T.current)clearTimeout(T.current),T.current=null;return S()}if(T.current)clearTimeout(T.current);return T.current=setTimeout(()=>{T.current=null,S()},400),()=>{if(T.current)clearTimeout(T.current),T.current=null}},[n]);let _=H(async()=>{let j=d.trim();if(!j)return;let S=d;x(null),ie(e.id,{turns:[{role:"user",text:j,status:"pending"}],threadStatus:"pending",text:j}),f("");let V=Array.isArray(e.data.contextNodeIds)?e.data.contextNodeIds:void 0;if(!(await pi(j,e.position,e.id,V,e.id)).ok)ie(e.id,{turns:[],threadStatus:"draft",text:"",status:"draft"}),f(S),x("Failed to send prompt. Your draft has been restored.")},[d,e.id,e.position,e.data.contextNodeIds]),z=H(async()=>{let j=m.trim();if(!j)return;let S=m;x(null);let V=Array.isArray(e.data.turns)?[...e.data.turns]:[];if(V.push({role:"user",text:j,status:"pending"}),ie(e.id,{turns:V,threadStatus:"pending"}),h(""),!(await Av(e.id,j)).ok)V.pop(),ie(e.id,{turns:V,threadStatus:"answered"}),h(S),x("Failed to send reply. Your draft has been restored.")},[m,e.id,e.data.turns]),U=H((j)=>{if(j.key==="Enter"&&(j.metaKey||j.ctrlKey)){j.preventDefault(),_();return}if(j.key==="Tab"&&d.startsWith("/")){j.preventDefault();let S=d.slice(1).split(/\s/)[0];if(S)bx().then((V)=>{let he=xx(S,V);if(he)f(`/${he}`)})}},[_,d]),N=H((j)=>{if(j.key==="Enter"&&(j.metaKey||j.ctrlKey)){j.preventDefault(),z();return}if(j.key==="Tab"&&m.startsWith("/")){j.preventDefault();let S=m.slice(1).split(/\s/)[0];if(S)bx().then((V)=>{let he=xx(S,V);if(he)h(`/${he}`)})}},[z,m]),Z=Array.isArray(e.data.contextNodeIds)?e.data.contextNodeIds.length:0;if(c&&n.length===0)return i("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%",gap:"8px"},children:[i(wx,{count:Z},void 0,!1,void 0,this),i(_x,{message:v,onDismiss:()=>x(null)},void 0,!1,void 0,this),i("textarea",{ref:E,value:d,onInput:(j)=>f(j.target.value),onKeyDown:U,placeholder:"Ask the agent something…",spellcheck:!1,style:{flex:1,resize:"none",background:"rgba(10,14,30,0.4)",border:"1px solid var(--c-line)",borderRadius:"var(--radius-sm)",color:"var(--c-text)",fontFamily:"var(--font)",fontSize:"13px",lineHeight:"1.5",padding:"8px 10px",outline:"none"}},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter to send"]},void 0,!0,void 0,this),i("button",{type:"button",onClick:_,disabled:!d.trim(),style:{padding:"5px 14px",fontSize:"12px",fontWeight:600,background:d.trim()?"var(--c-accent)":"var(--c-line)",color:d.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:d.trim()?"pointer":"default"},children:"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(o)return i("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[i("div",{style:{flex:1,padding:"2px 0",fontSize:"13px",lineHeight:"1.55",color:"var(--c-text)",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto"},children:r},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:"6px",borderTop:"1px solid var(--c-line)",marginTop:"4px"},children:i("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:l?"var(--c-warn)":p?"var(--c-ok)":"var(--c-muted)"},children:l?"Sending…":p?"Answered":s},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[i(wx,{count:Z},void 0,!1,void 0,this),i(_x,{message:v,onDismiss:()=>x(null)},void 0,!1,void 0,this),i("div",{ref:L,style:{flex:1,overflow:"auto",minHeight:0},children:n.map((j,S)=>i("div",{children:[S>0&&i("div",{class:"thread-turn-divider"},void 0,!1,void 0,this),j.role==="user"?i("div",{class:"thread-turn-user",children:[i("div",{class:"thread-turn-role",children:[i("span",{class:"status-dot"},void 0,!1,void 0,this),"You"]},void 0,!0,void 0,this),i("div",{style:{fontSize:t?"15px":"13px",lineHeight:t?"1.7":"1.55",color:"var(--c-text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:j.text},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i("div",{class:"thread-turn-assistant",children:[i("div",{class:"thread-turn-role",children:[i("span",{class:`status-dot${j.status==="streaming"?" pulsing":""}`},void 0,!1,void 0,this),"PMX"]},void 0,!0,void 0,this),j.status==="streaming"&&!j.text&&i("div",{style:{height:"2px",background:"linear-gradient(90deg, transparent, var(--c-ok), transparent)",animation:"response-stream-pulse 1.5s ease-in-out infinite",borderRadius:"1px",marginBottom:"4px"}},void 0,!1,void 0,this),i("div",{class:t?"md-reader-content":void 0,style:{fontSize:t?void 0:"13px",lineHeight:t?void 0:"1.55",opacity:j.text?1:0.4},children:g.get(S)?i(de,{children:[i(CE,{html:g.get(S)??""},void 0,!1,void 0,this),j.status==="streaming"&&i("span",{class:"streaming-cursor"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i("div",{style:{color:"var(--c-muted)",fontStyle:"italic"},children:j.status==="streaming"?"Waiting for response…":j.text||"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},TE(j,S),!0,void 0,this))},void 0,!1,void 0,this),i("div",{style:{flexShrink:0,borderTop:"1px solid var(--c-line)",marginTop:"4px",paddingTop:"6px"},children:[i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:p?"6px":0},children:[i("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:u?"var(--c-accent)":l?"var(--c-warn)":p?"var(--c-ok)":"var(--c-muted)"},children:u?"Streaming…":l?"Sending…":p?"Answered":a},void 0,!1,void 0,this),i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:[n.length," turn",n.length!==1?"s":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),p&&i("div",{class:"thread-reply-area",children:[i("textarea",{value:m,onInput:(j)=>h(j.target.value),onKeyDown:N,placeholder:"Reply…",spellcheck:!1,rows:2,style:{width:"100%",resize:"none",background:"rgba(10,14,30,0.4)",border:"1px solid var(--c-line)",borderRadius:"var(--radius-sm)",color:"var(--c-text)",fontFamily:"var(--font)",fontSize:"12px",lineHeight:"1.5",padding:"6px 8px",outline:"none"}},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"4px"},children:[i("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter"]},void 0,!0,void 0,this),i("button",{type:"button",onClick:z,disabled:!m.trim(),style:{padding:"3px 10px",fontSize:"11px",fontWeight:600,background:m.trim()?"var(--c-accent)":"var(--c-line)",color:m.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:m.trim()?"pointer":"default"},children:"Reply"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function IE(e){return e.replace(/<script[\s>][\s\S]*?<\/script>/gi,"").replace(/<iframe[\s>][\s\S]*?<\/iframe>/gi,"").replace(/<object[\s>][\s\S]*?<\/object>/gi,"").replace(/<embed[\s>][\s\S]*?(?:\/>|<\/embed>)/gi,"").replace(/<link[\s>][\s\S]*?(?:\/>|<\/link>)/gi,"").replace(/\bon\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,"").replace(/href\s*=\s*"javascript:[^"]*"/gi,'href="#"').replace(/href\s*=\s*'javascript:[^']*'/gi,"href='#'")}function EE({html:e}){let t=R(null);return B(()=>{let n=t.current;if(!n)return;if(n.replaceChildren(),!e)return;let o=document.createElement("template");o.innerHTML=e,n.append(o.content.cloneNode(!0))},[e]),i("div",{ref:t},void 0,!1,void 0,this)}function uc({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 bn(n).then((p)=>{if(!u)s(IE(p))}),()=>{u=!0}},[n]);let l=H(()=>{pi("",{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(EE,{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 Sx(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 kx={mcp:"var(--c-accent)",file:"var(--c-warn)",subagent:"var(--c-purple)",other:"var(--c-muted)"},AE={running:"⠋",success:"✓",failed:"✕"},zE={running:"var(--c-accent)",success:"var(--c-ok)",failed:"var(--c-danger)"};function dc({node:e}){let{toolName:t,category:n,status:o,duration:r,resultSummary:s,error:a}=Sx(e.data),c=kx[n]??kx.other,l=AE[o]??"◌",u=zE[o]??"var(--c-muted)",p=o==="running",d=a?a.slice(0,30):s.length>30?`${s.slice(0,28)}…`:s;return i("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"0 12px",height:"100%",overflow:"hidden"},children:[i("span",{style:{fontSize:"14px",color:u,flexShrink:0,animation:p?"pulse 1.5s infinite":"none"},children:l},void 0,!1,void 0,this),i("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:[i("div",{style:{fontFamily:"var(--mono)",fontSize:"11px",fontWeight:600,color:c,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t},void 0,!1,void 0,this),d&&i("div",{style:{fontSize:"10px",color:a?"var(--c-danger)":"var(--c-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:1.3},children:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r&&i("span",{style:{fontSize:"9px",padding:"1px 5px",borderRadius:"3px",background:"rgba(255,255,255,0.06)",color:"var(--c-muted)",flexShrink:0,whiteSpace:"nowrap"},children:r},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Md(e){let t=F.value.get(e);if(!t)return null;return{left:t.position.x,top:t.position.y,width:t.size.width,height:t.size.height}}function PE(e){let t=e.map((l)=>Md(l)).filter((l)=>l!==null);if(t.length===0)return null;let n=Math.min(...t.map((l)=>l.left)),o=Math.min(...t.map((l)=>l.top)),r=Math.max(...t.map((l)=>l.left+l.width)),s=Math.max(...t.map((l)=>l.top+l.height)),a=54,c=46;return{left:n-a,top:o-c,width:r-n+a*2,height:s-o+c*2}}function $d(e,t){return{left:`${e.left}px`,top:`${e.top}px`,width:`${e.width}px`,height:`${e.height}px`,borderRadius:`${t}px`}}function Cx(){let e=Array.from(nr.value),t=Array.from(or.value),n=Bs.value;if(e.length===0&&t.length===0)return null;let o=[...F.value.values()],r=o.length>0?(Math.max(...o.map((s)=>s.position.x+s.size.width))-Math.min(...o.map((s)=>s.position.x)))*(Math.max(...o.map((s)=>s.position.y+s.size.height))-Math.min(...o.map((s)=>s.position.y))):0;return i("div",{class:"attention-field-layer","aria-hidden":"true",children:[n.map((s)=>{let a=PE(s.nodeIds);if(!a)return null;if(r>0&&a.width*a.height>=r*0.75)return null;return i("div",{class:"attention-field-region",style:$d(a,42)},s.id,!1,void 0,this)}),t.map((s)=>{let a=Md(s);if(!a)return null;return i("div",{class:"attention-field-node attention-field-secondary",style:$d({left:a.left-18,top:a.top-18,width:a.width+36,height:a.height+36},28)},`secondary-${s}`,!1,void 0,this)}),e.map((s)=>{let a=Md(s);if(!a)return null;return i("div",{class:"attention-field-node attention-field-primary",style:$d({left:a.left-24,top:a.top-24,width:a.width+48,height:a.height+48},30)},`primary-${s}`,!1,void 0,this)})]},void 0,!0,void 0,this)}var NE=new Set(["png","jpg","jpeg","gif","svg","webp","bmp","ico","avif"]),RE=new Set(["md","mdx","markdown"]);function $E(e){let t=e.split(".").pop()?.toLowerCase()??"";if(NE.has(t))return"image";if(RE.has(t))return"markdown";return"file"}async function Rr(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),f=t-c*420/2+p*420,m=n-150+d*320,h=$E(u.name),v=u.name;if(/\.(pdf|pptx?|xlsx?|docx?|od[pts])$/i.test(v)){if(!o||u.size===0||u.size>20971520){yn("remove","File not attached","Open a board and choose a nonempty file under 20 MiB.");continue}let x=new URLSearchParams({boardId:o,name:v,mime:u.type,x:String(f),y:String(m)});yn("context","Attaching document",v),await Y("attachDocument",`/api/canvas/attachments?${x}`,null,{method:"POST",body:u});continue}if(Pe.value!==o)return;if(h==="image"){let x=new FileReader,g=await new Promise((y)=>{x.onload=()=>y(x.result),x.readAsDataURL(u)});if(Pe.value!==o)return;await Qt({type:"image",title:v,content:g,x:f,y:m,width:400,height:300,...o?{boardId:o}:{}})}else{let x=await u.text();if(Pe.value!==o)return;let g=h==="markdown"||h==="file";await Qt({type:h,title:v,content:x,x:f,y:m,width:g?720:400,height:g?500:300,...o?{boardId:o}:{}})}}}var ME={fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"};function Se({size:e=16,children:t,...n}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",...ME,...n,children:t},void 0,!1,void 0,this)}function mc(e){return i(Se,{...e,children:[i("polyline",{points:"1 5 1 1 5 1"},void 0,!1,void 0,this),i("polyline",{points:"11 1 15 1 15 5"},void 0,!1,void 0,this),i("polyline",{points:"15 11 15 15 11 15"},void 0,!1,void 0,this),i("polyline",{points:"5 15 1 15 1 11"},void 0,!1,void 0,this),i("rect",{x:"4",y:"4",width:"8",height:"8",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Tx(e){return i(Se,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),i("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this),i("line",{x1:"7",y1:"5",x2:"7",y2:"9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ix(e){return i(Se,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),i("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function En(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"4",x2:"9.5",y2:"4"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"12",x2:"9.5",y2:"12"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6.5",x2:"4",y2:"9.5"},void 0,!1,void 0,this),i("line",{x1:"12",y1:"6.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function fc(e){return i(Se,{...e,children:[i("rect",{x:"1",y:"2",width:"14",height:"12",rx:"1.5"},void 0,!1,void 0,this),i("rect",{x:"8",y:"7",width:"6",height:"6",rx:"1",fill:"currentColor","fill-opacity":"0.2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ex(e){return i(Se,{...e,children:[i("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"1",x2:"8",y2:"3"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"13",x2:"8",y2:"15"},void 0,!1,void 0,this),i("line",{x1:"1",y1:"8",x2:"3",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"13",y1:"8",x2:"15",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"3.05",y1:"3.05",x2:"4.46",y2:"4.46"},void 0,!1,void 0,this),i("line",{x1:"11.54",y1:"11.54",x2:"12.95",y2:"12.95"},void 0,!1,void 0,this),i("line",{x1:"3.05",y1:"12.95",x2:"4.46",y2:"11.54"},void 0,!1,void 0,this),i("line",{x1:"11.54",y1:"4.46",x2:"12.95",y2:"3.05"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function hc(e){return i(Se,{...e,children:i("path",{d:"M13 9.5A5.5 5.5 0 1 1 6.5 3 4.5 4.5 0 0 0 13 9.5Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Ld(e){return i(Se,{...e,children:[i("path",{d:"M3 13l2.8-.7L13 5.1 10.9 3 3.7 10.2 3 13Z"},void 0,!1,void 0,this),i("path",{d:"M9.8 4.1l2.1 2.1"},void 0,!1,void 0,this),i("path",{d:"M2.5 14h11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Dd(e){return i(Se,{...e,children:[i("path",{d:"M3 10.5 8.5 5a2 2 0 0 1 2.8 0l1.7 1.7a2 2 0 0 1 0 2.8L8.5 14H5.8L3 11.2Z"},void 0,!1,void 0,this),i("path",{d:"M7.5 6 12 10.5"},void 0,!1,void 0,this),i("path",{d:"M8.5 14H14"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Fd(e){return i(Se,{...e,children:[i("path",{d:"M3 4h10"},void 0,!1,void 0,this),i("path",{d:"M8 4v8"},void 0,!1,void 0,this),i("path",{d:"M6 12h4"},void 0,!1,void 0,this),i("path",{d:"M4.5 4 4 6"},void 0,!1,void 0,this),i("path",{d:"M11.5 4 12 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ax(e){return i(Se,{...e,children:[i("rect",{x:"1",y:"4",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M5.5 4 L6.5 2.5 H9.5 L10.5 4"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"9",r:"2.3"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zx(e){return i(Se,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"0.8",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Px(e){return i(Se,{...e,children:[i("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),i("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"10.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"5.5",x2:"5.5",y2:"10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Nx(e){return i(Se,{...e,children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Rx(e){return i(Se,{...e,children:[i("rect",{x:"1",y:"3",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6",x2:"5",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"7.5",y1:"6",x2:"8.5",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"11",y1:"6",x2:"12",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"10",x2:"12",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Mr(e){return i(Se,{...e,children:i("path",{d:"M2 13 L2 4 A2 2 0 0 1 4 2 L12 2 A2 2 0 0 1 14 4 L14 9 A2 2 0 0 1 12 11 L5 11 Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function gc({size:e=22,class:t}){return i("svg",{width:e,height:e,viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",class:t,"aria-hidden":"true",children:[i("rect",{x:"8",y:"8",width:"48",height:"48",rx:"7",fill:"none",stroke:"currentColor","stroke-width":"2.2",opacity:"0.35"},void 0,!1,void 0,this),i("rect",{x:"16",y:"16",width:"32",height:"32",rx:"5",fill:"none",stroke:"currentColor","stroke-width":"2.2",opacity:"0.6"},void 0,!1,void 0,this),i("rect",{x:"24",y:"24",width:"16",height:"16",rx:"3",fill:"none",stroke:"currentColor","stroke-width":"2.2"},void 0,!1,void 0,this),i("rect",{x:"29",y:"29",width:"6",height:"6",rx:"1",fill:"currentColor"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $x({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M3 2l10 5.5-4.2 1.3L7.5 13z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Mx({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M5 7.5V3.8a1 1 0 0 1 2 0V7m0-3.9a1 1 0 0 1 2 0V7m0-2.7a1 1 0 0 1 2 0V7.4m0-.9a1 1 0 0 1 2 0v3.2A4.3 4.3 0 0 1 8.7 14H8a4.3 4.3 0 0 1-3.6-2L2.7 9.3a1 1 0 0 1 1.6-1.2L5 9.2"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Ox({size:e=15}){return i("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M6 4.5L2.5 8 6 11.5M10 4.5L13.5 8 10 11.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function no(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"6",x2:"10",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"8.5",x2:"8",y2:"8.5"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"11",x2:"11",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function OE(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M4 13.5 L5.5 11.5 L8 11.5"},void 0,!1,void 0,this),i("polyline",{points:"5 6 7 8 5 10"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"10",x2:"11",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function LE(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M12 13.5 L10.5 11.5 L8 11.5"},void 0,!1,void 0,this),i("circle",{cx:"5",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"11",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function pc(e){return i(Se,{...e,children:[i("path",{d:"M3 1.5h6l3.5 3.5v8a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V2.5a1 1 0 0 1 1-1z"},void 0,!1,void 0,this),i("polyline",{points:"9 1.5 9 5 12.5 5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"8.5",x2:"10.5",y2:"8.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"11",x2:"9",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Bd(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"5.5",cy:"6.5",r:"1.2"},void 0,!1,void 0,this),i("path",{d:"M1.8 12 L6 8.5 L9 11 L11.5 9 L14.2 12"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $r(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"1.5",y1:"5.5",x2:"14.5",y2:"5.5"},void 0,!1,void 0,this),i("circle",{cx:"3.3",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"5",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"6.7",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"8",x2:"12",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"4",y1:"10",x2:"10",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function DE(e){return i(Se,{...e,children:[i("rect",{x:"2",y:"4",width:"12",height:"10",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"2",y1:"6.5",x2:"14",y2:"6.5"},void 0,!1,void 0,this),i("path",{d:"M11 1.5 L11 4"},void 0,!1,void 0,this),i("circle",{cx:"11",cy:"4",r:"1.6",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Hd(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"1.5","stroke-dasharray":"2 1.5"},void 0,!1,void 0,this),i("rect",{x:"4",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),i("rect",{x:"8.5",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),i("rect",{x:"6.25",y:"8.5",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function FE(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"9.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function BE(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M3.5 10.5 L6 6.5 L8.5 9.5 L12.5 5"},void 0,!1,void 0,this),i("circle",{cx:"12.5",cy:"5",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function HE(e){return i(Se,{...e,children:[i("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"5.5",x2:"11.5",y2:"5.5"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"8",x2:"11.5",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"4.5",y1:"10.5",x2:"8",y2:"10.5"},void 0,!1,void 0,this),i("line",{x1:"6.5",y1:"2",x2:"6.5",y2:"14",opacity:"0.45"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jE(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this),i("path",{d:"M4 11 L4 6 L6 8.5 L8 6 L8 11"},void 0,!1,void 0,this),i("path",{d:"M10 11 L10 6 L12.5 11 L12.5 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ZE(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("polyline",{points:"10 5 13 5 13 8"},void 0,!1,void 0,this),i("line",{x1:"13",y1:"5",x2:"8",y2:"10"},void 0,!1,void 0,this),i("path",{d:"M6 6 L3.5 6 L3.5 11.5 L10 11.5 L10 9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function UE(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("path",{d:"M7 5.5 C 5.5 5.5 5.5 8 4 8 C 5.5 8 5.5 10.5 7 10.5"},void 0,!1,void 0,this),i("path",{d:"M9 5.5 C 10.5 5.5 10.5 8 12 8 C 10.5 8 10.5 10.5 9 10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Od(e){return i(Se,{...e,children:[i("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),i("line",{x1:"5.2",y1:"6",x2:"8",y2:"8"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"8",x2:"10.8",y2:"6"},void 0,!1,void 0,this),i("line",{x1:"8",y1:"8",x2:"8",y2:"11"},void 0,!1,void 0,this),i("circle",{cx:"5.2",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"10.8",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),i("circle",{cx:"8",cy:"11",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function rn(e){switch(e){case"markdown":return no;case"prompt":return OE;case"response":return LE;case"file":return pc;case"diff":return pc;case"mermaid":return Od;case"image":return Bd;case"webpage":return $r;case"context":return DE;case"group":return Hd;case"status":return FE;case"trace":return BE;case"ledger":return HE;case"mcp-app":return jE;case"ext-app":return ZE;case"json-render":return UE;case"graph":return Od;case"board":return Od;case"html":return $r;default:return no}}var Lx={width:260,height:150},qE={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 Zd(e){return!!e&&e in lt}function An(e){if(!e)return null;let t=F.value.get(e);if(!t)return null;return{left:t.position.x,top:t.position.y,width:t.size.width,height:t.size.height}}function jd(e){return{x:e.left+e.width/2,y:e.top+e.height/2}}function Fi(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 Dx(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 Ud({intent:e}){let t=Zd(e.nodeType)?rn(e.nodeType):null,n=e.label||e.kind,o=typeof e.confidence==="number"?`${Math.round(e.confidence*100)}%`:null;return i("div",{class:"intent-info",onMouseEnter:()=>yr.value=e.id,onMouseLeave:()=>{if(yr.value===e.id)yr.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(),Co(e)},children:"✕"},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 Fx({intent:e,rect:t}){let n=Zd(e.nodeType)?rn(e.nodeType):null,o=Zd(e.nodeType)?lt[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:Fi(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(Ud,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Bx({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:Fi(e)},children:[n==="edit"&&i("div",{class:"intent-edit-bar"},void 0,!1,void 0,this),i(Ud,{intent:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function WE(e){let t=e.phase==="settling"?An(e.settledNodeId):null;switch(e.kind){case"create":{if(!e.position)return null;let n=e.nodeType&&qE[e.nodeType]||Lx,o=t??{left:e.position.x,top:e.position.y,...n};return i(Fx,{intent:e,rect:o},e.id,!1,void 0,this)}case"move":{if(!e.position)return null;let o=An(e.nodeId)??Lx,r=t??{left:e.position.x,top:e.position.y,width:o.width,height:o.height};return i(Fx,{intent:e,rect:r},e.id,!1,void 0,this)}case"remove":{let n=t??An(e.nodeId);if(!n)return null;return i(Bx,{intent:e,rect:n,variant:"remove"},e.id,!1,void 0,this)}case"edit":{let n=t??An(e.nodeId);if(!n)return null;return i(Bx,{intent:e,rect:n,variant:"edit"},e.id,!1,void 0,this)}case"connect":{if(!e.edge)return null;let n=An(e.edge.from),o=An(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:Fi(e)},children:i(Ud,{intent:e},void 0,!1,void 0,this)},e.id,!1,void 0,this)}default:return null}}function Hx(){let e=Array.from(Ve.value.values());if(B(()=>{function t(n){if(n.key!=="Escape")return;let o=yr.value;if(!o)return;let r=Ve.value.get(o);if(!r||r.phase!=="forming")return;n.stopImmediatePropagation(),n.preventDefault(),Co(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&&Ve.value.get(n)?.phase!=="forming")Ro(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=An(t.edge.from),o=An(t.edge.to);if(!n||!o)return null;return i("path",{d:Dx(jd(n),jd(o)),class:`intent-edge type-${t.edge.type}`,style:{opacity:Fi(t)}},`line-${t.id}`,!1,void 0,this)}if(t.kind==="move"&&t.position){let n=An(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:Dx(jd(n),r),class:"intent-trail",markerEnd:"url(#intent-arrow)",style:{opacity:Fi(t)}},`line-${t.id}`,!1,void 0,this)}return null})]},void 0,!0,void 0,this),e.map(WE)]},void 0,!0,void 0,this)}var jx=32000;var vc="Agent session";function Zx(e){return e.some((t)=>t.attached)}function Ux(e){return e.filter((t)=>!t.attached)}function oo(e){switch(e.phase){case"thinking":return"Thinking";case"tooling":return e.detail?`Running ${e.detail}`:"Working";case"waiting-approval":return"Waiting on you";default:return"Idle"}}function ro(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return(t%360+360)%360}var gt=q([]),Wd=q({used:0,total:jx}),io=q([]),Fo=q(!1),Or=q(!1),Vd=q(null),qx=["var(--c-purple)","var(--c-accent)","var(--c-ok)","var(--c-warn)","var(--c-danger)"],qd=new Map;function yc(e){let t=qd.get(e);if(t)return t;let n=qx[qd.size%qx.length];return qd.set(e,n),n}function Wx(e){return(e.trim().replace(/^[^a-z0-9]+/i,"").charAt(0)||e.trim().charAt(0)||"?").toUpperCase()}function bc(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 vt=Oe(()=>Zx(gt.value)),Gd=Oe(()=>Ux(gt.value)),Vx=Oe(()=>{let e=new Set;return[...gt.value].filter((t)=>t.label!==vc).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))}),Gx=Oe(()=>gt.value.filter((e)=>e.attached)),Lr=Oe(()=>gt.value.find((e)=>e.attached)??null);function VE(e){let t=new Set;for(let n of e)if(n.nodeId&&n.kind!=="create")t.add(n.nodeId);return t}var Xx=Oe(()=>VE(Ve.value.values()));function xc(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 Xd(e){if(!e)return;if(Array.isArray(e.presences))gt.value=e.presences;if(e.budget&&Number.isFinite(e.budget.used)&&Number.isFinite(e.budget.total))Wd.value={used:e.budget.used,total:e.budget.total};if(Array.isArray(e.activity))io.value=e.activity}function Kx(){let e=R(new Map),t=J.value.scale,n=F.value,o=1/Math.max(0.05,t),r=gt.value.map((s)=>{let a=xc(s,(l)=>n.get(l));if(a)e.current.set(s.sessionId,a);let c=a??e.current.get(s.sessionId)??null;return c?{presence:s,position:c}:null}).filter((s)=>s!==null);if(r.length===0)return null;return i("div",{class:"agent-presence-layer","aria-hidden":"true",children:r.map(({presence:s,position:a})=>i("div",{class:`agent-cursor phase-${s.phase}${s.cursor?" has-explicit-cursor":""}${s.attached?"":" is-external"}${s.parentAgentId?" is-worker":""}`,"data-session-id":s.sessionId,style:{transform:`translate(${a.x}px, ${a.y}px)`,"--identity-color":`hsl(${ro(s.sessionId)} 65% 62%)`},children:i("div",{class:"agent-cursor-inner",style:{transform:`scale(${o})`},children:[i("svg",{class:"agent-cursor-glyph",width:"16",height:"18",viewBox:"0 0 16 18","aria-hidden":"true",children:i("path",{d:"M1.5 1.5L14.5 9.2 8.3 10.6 5.2 16.5z",fill:"currentColor",stroke:"var(--c-bg)","stroke-width":"1.2"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"agent-cursor-chip",children:[i("span",{class:"agent-cursor-dot"},void 0,!1,void 0,this),i("span",{class:"agent-cursor-label",children:oo(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 zn(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 Jx(){let e=zn(Ci.value.length>0?5000:0),t=Ci.value.filter((o)=>o.cursor!==null&&(!o.lastSeenAt||e-Date.parse(o.lastSeenAt)<vb+5000));if(t.length===0)return null;let n=1/Math.max(0.05,J.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 wc(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 Jd(){let e=tn.value;return e&&typeof e==="object"?e:{}}var Yx=Oe(()=>Jd().workItems??[]),Yd=Oe(()=>Jd().approvalGates??[]),Bo=Oe(()=>Yd.value.filter((e)=>e.status==="pending")),so=Oe(()=>{let e=Jd().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 Qx(e){return(await $t("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 ew=Oe(()=>Yd.value.filter((e)=>e.status==="held")),tw=Oe(()=>Yd.value.filter((e)=>e.status==="approved"||e.status==="rejected")),nw=q({events:[],evidence:[],steering:[]}),Ho=q("all");function Qd(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 GE=new Set(["api","mcp","sdk","cli"]);function Kd(e,t){if(e?.trim())return e.trim();let n=t?.trim();if(n&&!GE.has(n))return n;return null}var XE=/^(node|edge|group|annotation|jsonrender|graph|render)\.|^arrange$|^canvas\.clear$|^snapshot\.restore$/,ow=q(null),Bi=q(new Set),KE={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 JE(e,t=40,n=[],o=null,r="all"){let s=n.find((l)=>XE.test(l.op)),a=[...n.map((l)=>({id:`update-${l.id}`,kind:"update",label:"Update",body:l.summary,createdAt:l.at,who:l.sessionId??null,...o?.actor==="agent"&&s?.id===l.id?{undoable:!0}:{}})),...e.events.map((l)=>({id:`event-${l.id}`,kind:l.kind,label:KE[l.kind]??l.kind,body:l.detail?`${l.summary} — ${l.detail}`:l.summary,createdAt:l.createdAt,who:Kd(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:Kd(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:Kd(l.agentId,l.source)}})],c=r==="all"?a:a.filter((l)=>Qd(l.kind)===r);return c.sort((l,u)=>l.createdAt<u.createdAt?1:l.createdAt>u.createdAt?-1:0),c.slice(0,t)}var rw=Oe(()=>JE(nw.value,40,io.value,ow.value,Ho.value));async function ao(){let[e,t]=await Promise.all([Y("refreshTimeline","/api/canvas/ax/timeline?limit=40",null),Y("refreshHistoryTop","/api/canvas/history",null)]);if(t)ow.value=t.top??null;if(!e)return;nw.value={events:Array.isArray(e.events)?e.events:[],evidence:Array.isArray(e.evidence)?e.evidence:[],steering:Array.isArray(e.steering)?e.steering:[]}}async function ep(e){if(!(await $t("undoAgentEdit","/api/canvas/undo",{method:"POST"})).ok)return!1;return Bi.value=new Set([...Bi.value,e.id]),await Yt("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"})}),ao(),!0}async function tp(e=!1){let t=await $t(e?"redo":"undo",e?"/api/canvas/redo":"/api/canvas/undo",{method:"POST"});if(t.ok)ao();return t.ok}async function iw(e,t){if(!(await $t("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 Yt("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 sw(e){return(await $t("reopenGate",`/api/canvas/ax/approval/${encodeURIComponent(e.id)}/reopen`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser"})})).ok}async function aw(e,t){return(await $t("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 co(){return(await $t("startSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"browser",label:vc,attached:!0,phase:"idle"})})).ok}async function _c(e){return(await $t("endSession","/api/canvas/ax/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:e.source,agentId:e.agentId,attached:!1,endedBy:"human"})})).ok}var Sc=q(null);function cw(e){let{counts:t,snapshot:n}=e;if(typeof e.label!=="string"||typeof e.endedAt!=="string")return;if(e.unchanged===!0||typeof e.parentAgentId==="string")return;Sc.value={label:e.label,endedAt:e.endedAt,endedBy:e.endedBy==="human"||e.endedBy==="agent"||e.endedBy==="idle-timeout"?e.endedBy:void 0,unchanged:e.unchanged===!0,counts:{items:Number(t?.items??0)||0,done:Number(t?.done??0)||0,cancelled:Number(t?.cancelled??0)||0,rejected:Number(t?.rejected??0)||0,held:Number(t?.held??0)||0},snapshot:n&&typeof n.id==="string"?{id:n.id,name:String(n.name??"")}:null}}function kc(){Sc.value=null}function lw(){if(!vt.value)return null;let e=so.value;if(!e)return null;let t=F.value,n=e.nodeIds.map((s)=>t.get(s)).filter((s)=>s!==void 0),o=wc(n,e.padding);if(!o)return null;let r=1/Math.max(0.05,J.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 Cc={markdown:"var(--c-accent)","mcp-app":"var(--c-ok)",webpage:"var(--c-warn)","json-render":"var(--c-ok)",graph:"var(--c-purple)",board:"var(--c-accent)",prompt:"var(--c-accent)",response:"var(--c-ok)",status:"var(--c-warn)",context:"var(--c-muted)",ledger:"var(--c-dim)",trace:"var(--c-purple)",file:"var(--c-accent)",diff:"var(--c-ok)",mermaid:"var(--c-purple)",image:"var(--c-ok)",html:"var(--c-warn)",group:"var(--c-accent)"};function YE(e){let t=typeof e==="number"&&Number.isFinite(e)?Math.floor(e):1;return Math.max(1,Math.min(20,t))}function Tc(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Hi(e){return typeof e==="string"&&e.length>0}function uw(e){let t=e.axStep;if(!Tc(t))return null;if(!Hi(t.flowId)||!Hi(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 dw(e){let t=e.axFlow;if(!Tc(t)||!Hi(t.flowId)||!Array.isArray(t.steps))return null;let n=[];for(let r of t.steps){if(!Tc(r)||!Hi(r.nodeId)||!Hi(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=Tc(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:YE(o.maxRuns)}}}var QE={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)"},mw={display:"flex",alignItems:"center",gap:"6px",flexWrap:"wrap"},fw={fontSize:"10px",color:"var(--c-muted)",textTransform:"uppercase",letterSpacing:"0.04em",marginRight:"auto"},hw={...Po,background:"var(--c-accent-25)",color:"var(--c-text)"},eA=[{status:"in-progress",label:"Start",toast:"Step started"},{status:"done",label:"Done",toast:"Step done"},{status:"blocked",label:"Blocked",toast:"Step blocked"}];async function pw(e,t,n){let o={...t,loop:n};ie(e.id,{axFlow:o}),await dt(e.id,{data:{axFlow:o}})}function gw(e){return typeof e?.axWorkStatus==="string"?e.axWorkStatus:"todo"}function tA({node:e,flow:t}){let[n,o]=I(""),{running:r,run:s,maxRuns:a}=t.loop,c=async()=>{await pw(e,t,{running:!0,run:s>=a?0:s,maxRuns:a});let u=t.steps.find((d)=>gw(F.value.get(d.nodeId)?.data)!=="done"),p=u??t.steps[t.steps.length-1];await Jn(e,"ax.work.update",{id:p.workItemId,status:u?"in-progress":"done"},"Loop running")},l=async()=>{let u=n.trim();if(!u)return;await Jn(e,"ax.steer",{message:u},"Steering sent"),o("")};return i("div",{class:"ax-flow-controls",style:{...mw,marginTop:"6px",rowGap:"4px"},children:[i("span",{class:"ax-flow-runs",style:fw,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:hw,title:"Stop the loop now. The stop is persisted on this node, so it survives a refresh and no further step is opened.",onClick:(u)=>{u.stopPropagation(),pw(e,t,{...t.loop,running:!1})},children:"Stop"},void 0,!1,void 0,this):i("button",{type:"button",class:"ax-node-action",style:Po,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:Po,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 Ic({node:e}){let t=uw(e.data);if(!t)return null;let n=dw(e.data),o=gw(e.data);return i("div",{class:"ax-step-dock",style:QE,children:[i("div",{class:"ax-step-controls",style:mw,children:[i("span",{class:"ax-step-position",style:fw,children:["Step ",t.index,"/",t.total]},void 0,!0,void 0,this),eA.map((r)=>i("button",{type:"button",class:"ax-node-action","aria-pressed":o===r.status,style:o===r.status?hw:Po,title:`Set this step's work item to "${r.status}".`,onClick:(s)=>{s.stopPropagation(),Jn(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(tA,{node:e,flow:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Dr=8,jo=q(null),Fr=[],Br=[],bw=null;function vw(e){let t=e?.data.parentGroup;return typeof t==="string"&&t.length>0?t:null}function yw(e){if(!e||!Array.isArray(e.data.children))return[];return e.data.children.filter((t)=>typeof t==="string")}function nA(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=vw(r);while(s&&!o.has(s))o.add(s),s=vw(n.get(s));if(r.type!=="group")return o;let a=[...yw(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(...yw(l))}return o}function xw(e,t){Fr=[],Br=[],bw=e;let n=Array.from(t),o=nA(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;Fr.push({val:s,minY:l,maxY:u}),Fr.push({val:a,minY:l,maxY:u}),Fr.push({val:c,minY:l,maxY:u}),Br.push({val:l,minX:s,maxX:a}),Br.push({val:u,minX:s,maxX:a}),Br.push({val:p,minX:s,maxX:a})}}function ww(){Fr=[],Br=[],bw=null}function _w(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=Dr+1,p=null;for(let v=0;v<3;v++){let x=r[v];for(let g of Fr){let y=Math.abs(x-g.val);if(y<u)u=y,l=g.val-a[v],p={axis:"x",pos:g.val,from:Math.min(g.minY,t),to:Math.max(g.maxY,t+o)}}}let d=null,f=Dr+1,m=null;for(let v=0;v<3;v++){let x=s[v];for(let g of Br){let y=Math.abs(x-g.val);if(y<f)f=y,d=g.val-c[v],m={axis:"y",pos:g.val,from:Math.min(g.minX,e),to:Math.max(g.maxX,e+n)}}}let h=[];if(p&&u<=Dr)h.push(p);if(m&&f<=Dr)h.push(m);return{x:l!==null&&u<=Dr?l:e,y:d!==null&&f<=Dr?d:t,guides:h}}function Sw({nodeId:e,viewport:t,onMove:n,onDragEnd:o,onClick:r}){let s=R(!1),a=R({x:0,y:0}),c=R({x:0,y:0});return H((u,p,d)=>{u.stopPropagation(),u.preventDefault(),s.current=!0,document.documentElement.classList.add("is-node-dragging"),window.getSelection()?.removeAllRanges(),a.current={x:u.clientX,y:u.clientY},c.current={x:p,y:d};let f=null,m=null,h=!1,v=()=>{if(m=null,!s.current||!f)return;let y=f;f=null;let E=t.value.scale,L=(y.x-a.current.x)/E,P=(y.y-a.current.y)/E;n(e,c.current.x+L,c.current.y+P)},x=(y)=>{if(!s.current)return;if(!h&&Math.hypot(y.clientX-u.clientX,y.clientY-u.clientY)<4)return;if(h=!0,f={x:y.clientX,y:y.clientY},m!==null)return;m=window.requestAnimationFrame(v)},g=(y)=>{if(m!==null)window.cancelAnimationFrame(m),v();if(s.current=!1,document.documentElement.classList.remove("is-node-dragging"),document.removeEventListener("pointermove",x),document.removeEventListener("pointerup",g),document.removeEventListener("pointercancel",g),o(),!h&&y.type==="pointerup")r?.()};document.addEventListener("pointermove",x),document.addEventListener("pointerup",g),document.addEventListener("pointercancel",g)},[e,t,n,o,r])}var oA=200,rA=100;function kw({nodeId:e,viewport:t,onResize:n,onResizeEnd:o}){let r=R(!1),s=R({x:0,y:0}),a=R({w:0,h:0});return H((l,u,p)=>{l.stopPropagation(),l.preventDefault(),r.current=!0,s.current={x:l.clientX,y:l.clientY},a.current={w:u,h:p},document.documentElement.classList.add("is-node-resizing");let d=null,f=null,m=()=>{if(f=null,!r.current||!d)return;let x=d;d=null;let g=t.value.scale,y=(x.x-s.current.x)/g,E=(x.y-s.current.y)/g;n(e,Math.max(oA,a.current.w+y),Math.max(rA,a.current.h+E))},h=(x)=>{if(!r.current)return;if(d={x:x.clientX,y:x.clientY},f!==null)return;f=window.requestAnimationFrame(m)},v=()=>{if(f!==null)window.cancelAnimationFrame(f),m();r.current=!1,document.documentElement.classList.remove("is-node-resizing"),document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",v),document.removeEventListener("pointercancel",v),o()};document.addEventListener("pointermove",h),document.addEventListener("pointerup",v),document.addEventListener("pointercancel",v)},[e,t,n,o])}var iA={ArrowLeft:{dx:-1,dy:0},ArrowRight:{dx:1,dy:0},ArrowUp:{dx:0,dy:-1},ArrowDown:{dx:0,dy:1}};function sA(e,t,n){let o=e.position.x+e.size.width/2,r=e.position.y+e.size.height/2,s=null,a=Number.POSITIVE_INFINITY;for(let c of n){if(c.id===e.id)continue;let l=c.position.x+c.size.width/2-o,u=c.position.y+c.size.height/2-r,p=l*t.dx+u*t.dy;if(p<=0)continue;let d=Math.abs(l*t.dy)+Math.abs(u*t.dx);if(d>p)continue;let f=p+d*2;if(f<a)a=f,s=c}return s}var aA=0.4,cA=0.55,lA=175;function uA(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*aA/xr);if(Number.isFinite(n)&&n>0)r=Math.min(r,n*cA/lA);return Math.max(1,r)}function Cw({node:e,children:t,onContextMenu:n}){let o=Ce.value===e.id,r=ye.value.has(e.id),s=Ae.value.has(e.id),a=nr.value.has(e.id),c=!a&&or.value.has(e.id),l=Hs.value.has(e.id),u=!o&&qv.value.has(e.id),p=wn.value,d=p!==null&&p.has(e.id),f=p!==null&&!p.has(e.id),[m,h]=I(!1),v=R(null),x=H((D,ae,De)=>{let ge=_w(ae,De,e.size.width,e.size.height),Gt=F.value.get(D);if(Gt?.position.x===ge.x&&Gt.position.y===ge.y){jo.value=ge.guides.length>0?ge.guides:null;return}it(D,{position:{x:ge.x,y:ge.y}}),jo.value=ge.guides.length>0?ge.guides:null,Kv(D)},[e.size.width,e.size.height]),g=R(null),y=H(()=>{if(ww(),jo.value=null,Xu(null),g.current)document.removeEventListener("keydown",g.current),g.current=null;st();let D=un.value;if(Xv(),!D||D.nodeId!==e.id)return;if(D.mode==="add")mu(D.groupId,[e.id]);else{let ae=F.value.get(D.groupId),De=Array.isArray(ae?.data.children)?ae.data.children.filter((ge)=>typeof ge==="string"&&ge!==e.id):[];Ys(D.groupId,De)}},[e.id]),E=Sw({nodeId:e.id,viewport:J,onMove:x,onDragEnd:y,onClick:()=>{ye.value=new Set([e.id])}}),L=H((D,ae,De)=>{let ge=F.value.get(D);if(ge?.size.width===ae&&ge.size.height===De)return;it(D,{size:{width:ae,height:De}})},[]),P=H(()=>{ie(e.id,{userResized:!0}),dt(e.id,{data:{userResized:!0}}),st()},[e.id]),b=kw({nodeId:e.id,viewport:J,onResize:L,onResizeEnd:P}),T=H((D)=>{D.stopPropagation(),D.preventDefault(),He.value={fromId:e.id,fromX:e.position.x+e.size.width/2,fromY:e.position.y+e.size.height/2,cursorX:e.position.x+e.size.width/2,cursorY:e.position.y+e.size.height/2,targetId:null}},[e.id,e.position.x,e.position.y,e.size.width,e.size.height]),w=H((D)=>{if(D.button!==0)return;if(m)return;if(D.target instanceof Element&&D.target.closest("button, input")){D.stopPropagation();return}if(It.value==="connect"){T(D);return}if(D.shiftKey){D.stopPropagation(),gu(e.id);return}if(Sn(e.id),Xu(e.id),Tb(e.id,typeof e.data.title==="string"&&e.data.title?e.data.title:e.type),xw(e.id,F.value.values()),e.type!=="group"){let ae=(De)=>{if(De.key==="Escape")Gv()};g.current=ae,document.addEventListener("keydown",ae)}E(D,e.position.x,e.position.y)},[e.id,e.type,e.data.title,e.position.x,e.position.y,E,m,T]),_=H((D)=>{if(D.button!==0)return;if(D.stopPropagation(),It.value==="connect"){T(D);return}if(D.shiftKey){gu(e.id);return}Sn(e.id)},[e.id,T]),z=H((D)=>{if((D.target instanceof Element?D.target:null)?.closest('button, input, textarea, select, a, [contenteditable="true"]'))return;if(n)n(D,e.id)},[n,e.id]),U=H((D)=>{let ae=D.target;if(ae&&ae!==D.currentTarget&&ae.closest('input, textarea, [contenteditable="true"]'))return;let De=iA[D.key];if(De){D.preventDefault();let ge=sA(e,De,F.value.values());if(!ge)return;Sn(ge.id),requestAnimationFrame(()=>{document.querySelector(`.canvas-node[data-node-id="${CSS.escape(ge.id)}"]`)?.focus()})}else if(D.key==="Enter"&&D.target===D.currentTarget&&ai.has(e.type))D.preventDefault(),Zt(e.id)},[e]),N=e.data.title||(e.type==="file"?(e.data.path||e.data.content||"").split(/[\\/]/).pop()??"":"")||lt[e.type],Z=H((D)=>{let ae=D.trim();if(ae&&ae!==N)ie(e.id,{title:ae}),dt(e.id,{title:ae});h(!1)},[e.id,N]),j=R(null),S=R(!1),V=R(null);B(()=>{if(S.current||!Ku(e))return;let D=j.current;if(!D)return;let ae=new ResizeObserver(()=>{if(S.current){ae.disconnect();return}let De=D.scrollHeight,ge=Pb(e,De);if(ge===null)return;if(Math.abs(ge-e.size.height)>8){if(aa(e.id,{width:e.size.width,height:ge}),V.current!==null)window.clearTimeout(V.current);V.current=window.setTimeout(()=>{st({recordHistory:!1}),V.current=null},0)}S.current=!0,ae.disconnect()});return ae.observe(D),()=>{if(ae.disconnect(),V.current!==null)window.clearTimeout(V.current),V.current=null}},[e.id,e.type,e.data.mode,e.data.strictSize,e.collapsed,e.size.width,e.size.height]);let he=e.pinned,je=e.type==="trace",se=je&&e.data.status==="running",ue=e.type==="group",pe=e.data.strictSize===!0,fo=Math.max(J.value.scale,0.01),Vt=uA(fo,e.collapsed?0:e.size.height,e.size.width),sn=ue&&e.data.color?e.data.color:void 0,M={left:`${e.position.x}px`,top:`${e.position.y}px`,width:`${e.size.width}px`,height:e.collapsed?"auto":`${e.size.height}px`,zIndex:e.zIndex,"--node-chrome-scale":Vt.toFixed(3),...sn?{"--group-color":sn}:{}},K=vt.value&&Xx.value.has(e.id),me=["canvas-node",o?"active":"",u?"neighbor":"",d?"search-match":"",f?"search-dimmed":"",r?"selected":"",s?"context-pinned":"",a?"attention-focus-primary":"",c?"attention-focus-secondary":"",l?"attention-pulse":"",he?"pinned":"",je?"trace-node":"",se?"trace-running":"",ue?"group-node":"",pe?"strict-size":"",K?"agent-mutating":""].filter(Boolean).join(" "),ee=ue?(Array.isArray(e.data.children)?e.data.children:[]).filter((D)=>typeof D==="string"&&F.value.has(D)):[],[Q,te]=I(!1),ne=un.value,W=ue&&ne?.groupId===e.id&&ne.mode==="add",le=ue&&ne?.groupId===e.id&&ne.mode==="remove",yt=He.value?.targetId===e.id,Pt=ue?[...new Set(ee.map((D)=>F.value.get(D)?.type).filter((D)=>!!D))].slice(0,4):[];if(ue&&e.collapsed)return i("div",{class:`${me} group-chip`,"data-node-type":e.type,style:{...M,width:"auto",height:"auto"},onPointerDown:_,onDblClick:z,title:"Expand group","data-testid":"group-chip",children:i("div",{class:"node-titlebar group-chip-inner",onPointerDown:w,children:[i("button",{type:"button",class:"group-chip-expand","aria-label":`Expand group ${N}`,onClick:(D)=>{D.stopPropagation(),dr(e.id)},children:"▸"},void 0,!1,void 0,this),i("div",{class:"group-chip-text",children:[i("div",{class:"group-chip-name",children:N},void 0,!1,void 0,this),i("div",{class:"group-chip-meta",children:[Pt.map((D)=>i("span",{class:"group-kind-dot",style:{background:Cc[D]},"aria-hidden":"true"},D,!1,void 0,this)),i("span",{class:"group-chip-count",children:[ee.length," node",ee.length===1?"":"s"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return i("div",{class:`${me}${W?" is-drop-target":""}${le?" is-drop-source":""}${yt?" is-edge-target":""}${ue&&Q?" group-menu-open":""}`,"data-node-type":e.type,"data-node-id":e.id,style:M,tabIndex:o?0:-1,onKeyDown:U,onPointerDown:_,onMouseDown:(D)=>{if(D.shiftKey)D.preventDefault()},onDblClick:z,children:[ue&&i("div",{class:"node-titlebar group-edge-row",onPointerDown:w,children:[i("span",{class:"group-name-pill",children:[m?i("input",{ref:v,class:"node-title-input group-title-input",value:N,onBlur:(D)=>Z(D.target.value),onKeyDown:(D)=>{if(D.key==="Enter")Z(D.target.value);if(D.key==="Escape")h(!1)},onClick:(D)=>D.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"group-name",title:N,children:N},void 0,!1,void 0,this),i("span",{class:"group-count",children:ee.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"group-edge-spacer"},void 0,!1,void 0,this),i("span",{class:"group-actions",role:"toolbar","aria-label":`${N} actions`,children:[i("button",{type:"button",class:"group-action",title:"Auto-arrange children","aria-label":"Auto-arrange children",disabled:ee.length===0,onClick:(D)=>{D.stopPropagation(),mu(e.id,ee,"grid")},children:i("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","aria-hidden":"true",children:[i("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),i("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"group-action",title:"Collapse group","aria-label":"Collapse group",onClick:(D)=>{D.stopPropagation(),dr(e.id)},children:i("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:i("path",{d:"M3 10 L8 5 L13 10"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("button",{type:"button",class:"group-action",title:"Rename · Ungroup · Pin all to context","aria-label":"Group menu","aria-expanded":Q,onClick:(D)=>{D.stopPropagation(),te((ae)=>!ae)},children:"⋯"},void 0,!1,void 0,this),Q&&i("div",{class:"group-menu",role:"menu",onPointerDown:(D)=>D.stopPropagation(),children:[i("button",{type:"button",role:"menuitem",onClick:(D)=>{D.stopPropagation(),te(!1),h(!0),requestAnimationFrame(()=>v.current?.focus())},children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",onClick:(D)=>{D.stopPropagation(),te(!1),Gn(e.id),ar(e.id)},children:"Ungroup"},void 0,!1,void 0,this),i("button",{type:"button",role:"menuitem",disabled:ee.length===0,onClick:(D)=>{D.stopPropagation(),te(!1),oa(ee)},children:"Pin all to context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!ue&&i("div",{class:"node-titlebar",onPointerDown:w,children:[i("span",{class:"node-type-icon","aria-hidden":"true",children:(()=>{let D=rn(e.type);return i(D,{size:Math.round(14*Vt)},void 0,!1,void 0,this)})()},void 0,!1,void 0,this),typeof e.data.axWorkStatus==="string"&&i("span",{class:`node-ax-status node-ax-status-${e.data.axWorkStatus}`,children:e.data.axWorkStatus},void 0,!1,void 0,this),m?i("input",{ref:v,class:"node-title-input",value:N,onBlur:(D)=>Z(D.target.value),onKeyDown:(D)=>{if(D.key==="Enter")Z(D.target.value);if(D.key==="Escape")h(!1)},onClick:(D)=>D.stopPropagation()},void 0,!1,void 0,this):i("span",{class:"node-title",title:N,children:N},void 0,!1,void 0,this),i("div",{class:"node-controls",children:[he&&i("span",{class:"pin-indicator",title:"Pinned",children:"⊙"},void 0,!1,void 0,this),i("button",{type:"button",class:`ctx-pin-btn${s?" ctx-pin-active":""}`,onClick:(D)=>{D.stopPropagation(),Vn(e.id)},title:s?"Remove from context":"Add to context",children:"✦"},void 0,!1,void 0,this),Aa(e)&&i("button",{type:"button",onClick:(D)=>{D.stopPropagation(),za(e)},title:"Open as site",children:"↗"},void 0,!1,void 0,this),ai.has(e.type)&&i("button",{type:"button",onClick:(D)=>{D.stopPropagation(),Zt(e.id)},title:"Expand (focus mode)",children:"⤢"},void 0,!1,void 0,this),i("button",{type:"button",onClick:(D)=>{D.stopPropagation(),dr(e.id)},title:e.collapsed?"Expand":"Collapse",children:e.collapsed?"▸":"▾"},void 0,!1,void 0,this),i("button",{type:"button",onClick:(D)=>{D.stopPropagation(),qn(e.id)},title:"Close",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!e.collapsed&&i("div",{ref:j,class:"node-body",children:[t,i(Ic,{node:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!e.collapsed&&i("div",{class:"node-resize-handle",onPointerDown:(D)=>b(D,e.size.width,e.size.height)},void 0,!1,void 0,this),r&&["tl","tr","bl","br"].map((D)=>i("span",{class:`node-selection-handle is-${D}`,"aria-hidden":"true"},D,!1,void 0,this)),$o.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),$o.value.get(e.id)," took over — agent yielded"]},void 0,!0,void 0,this),!ue&&["top","right","bottom","left"].map((D)=>i("div",{class:`node-port node-port-${D}`,onPointerDown:(ae)=>{ae.stopPropagation(),ae.preventDefault();let De=e.position.x+e.size.width/2,ge=e.position.y+e.size.height/2,Gt=e.size.width/2,Xi=e.size.height/2,Xt,Rn;switch(D){case"top":Xt=De,Rn=ge-Xi;break;case"bottom":Xt=De,Rn=ge+Xi;break;case"left":Xt=De-Gt,Rn=ge;break;case"right":Xt=De+Gt,Rn=ge;break}He.value={fromId:e.id,fromX:Xt,fromY:Rn,cursorX:Xt,cursorY:Rn}}},D,!1,void 0,this))]},void 0,!0,void 0,this)}function Ec({node:e}){let t=typeof e.data.boardId==="string"?e.data.boardId:"",n=Et.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 At(n.id),children:[n?"Open board":"Target unavailable",n&&i("span",{"aria-hidden":"true",children:"↗"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var dA={relation:"var(--c-muted)","depends-on":"var(--c-warn)",flow:"var(--c-accent)",references:"var(--c-muted)"},pA=new Set(["depends-on","flow"]);function mA(e){if(!Number.isFinite(e)||e<=0)return 1;return e<1?1/e:1}function fA(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 Ac(e,t){let n=e.position.x+e.size.width/2,o=e.position.y+e.size.height/2,r=t.position.x+t.size.width/2,s=t.position.y+t.size.height/2,a=r-n,c=s-o,l=e.size.width/2,u=e.size.height/2,p=Math.abs(c/(a||0.001)),d=u/(l||0.001);if(p>d){let m=c>0?1:-1;return{x:n+u/p*(a>0?1:-1),y:o+u*m,side:m>0?"bottom":"top"}}let f=a>0?1:-1;return{x:n+l*f,y:o+p*l*(c>0?1:-1),side:f>0?"right":"left"}}function zc(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 hA(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 gA({edge:e,fromNode:t,toNode:n,focused:o,dimmed:r,selected:s,scale:a,onContextMenu:c}){let l=Ac(t,n),u=Ac(n,t),p=u.x-l.x,d=u.y-l.y,f=Math.sqrt(p*p+d*d),m=Math.min(Math.max(f*0.35,32),160),h=zc(l,m),v=zc(u,m),x=`M ${l.x} ${l.y} C ${h.x} ${h.y}, ${v.x} ${v.y}, ${u.x} ${u.y}`,g=dA[e.type],y=pA.has(e.type),E=fA(e,a),L=Math.min(a,2.2),P=e.label&&a<=3.4?hA(l.x,l.y,h.x,h.y,v.x,v.y,u.x,u.y):null,b=`edge-path-${e.id}`;return i("g",{children:[i("path",{d:x,fill:"none",stroke:"transparent","stroke-width":12*a,style:{cursor:"pointer",pointerEvents:"stroke"},onClick:(T)=>{T.stopPropagation(),dn.value=e.id},onDblClick:c?(T)=>c(T,e.id):void 0},void 0,!1,void 0,this),(o||s)&&i("path",{d:x,fill:"none",stroke:g,"stroke-width":6*a,"stroke-dasharray":E,opacity:s?0.3:0.15,style:{filter:"blur(3px)"}},void 0,!1,void 0,this),i("path",{id:b,d:x,class:s?"edge-selected":void 0,fill:"none",stroke:g,"stroke-width":(s?3:o?2.5:1.5)*a,"stroke-dasharray":E,"marker-end":y?"url(#edge-arrow)":void 0,opacity:s?1:r?0.2:o?1:0.85,style:{transition:"opacity 0.2s, stroke-width 0.2s"}},void 0,!1,void 0,this),e.animated&&i("circle",{r:3*a,fill:g,opacity:"0.9",children:i("animateMotion",{dur:"2s",repeatCount:"indefinite",children:i("mpath",{href:`#${b}`},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),P&&e.label&&i("g",{transform:`translate(${P.x}, ${P.y})`,children:[i("rect",{class:"edge-label-bg",x:-(e.label.length*3.5+8)*L,y:-10*L,width:(e.label.length*7+16)*L,height:20*L,rx:4*L},void 0,!1,void 0,this),i("text",{class:"edge-label","text-anchor":"middle","dominant-baseline":"central",fill:"var(--c-text)",children:e.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Tw({nodes:e,edges:t,onEdgeContextMenu:n}){let o=e.value,r=Array.from(t.value.values()),s=Ce.value,a=s!==null,c=wn.value,l=c!==null,u=mA(J.value.scale);if(r.length===0&&!He.value)return null;let p=96,d=Array.from(o.values());if(d.length===0)return null;let f=Math.min(...d.map((y)=>y.position.x))-p,m=Math.min(...d.map((y)=>y.position.y))-p,h=Math.max(...d.map((y)=>y.position.x+y.size.width))+p,v=Math.max(...d.map((y)=>y.position.y+y.size.height))+p,x=Math.max(1,h-f),g=Math.max(1,v-m);return i("svg",{"aria-label":"Canvas connections",role:"img",viewBox:`${f} ${m} ${x} ${g}`,width:x,height:g,style:{position:"absolute",top:`${m}px`,left:`${f}px`,pointerEvents:"none",overflow:"visible","--edge-chrome-scale":u.toFixed(3),"--edge-label-scale":Math.min(u,2.2).toFixed(3)},children:[i("title",{children:"Canvas connections"},void 0,!1,void 0,this),i("defs",{children:i("marker",{id:"edge-arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:8*Math.min(u,2.2),markerHeight:8*Math.min(u,2.2),orient:"auto-start-reverse",children:i("path",{d:"M 0 1 L 10 5 L 0 9 z",fill:"currentColor",opacity:"0.75"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r.map((y)=>{let E=na(y.from),L=na(y.to);if(!E||!L||E.id===L.id)return null;let P=a&&(y.from===s||y.to===s),b=l&&!(c.has(y.from)||c.has(y.to));return i(gA,{edge:y,fromNode:E,toNode:L,focused:P,dimmed:a&&!P||b,selected:dn.value===y.id,scale:u,onContextMenu:n},y.id,!1,void 0,this)}),He.value&&(()=>{let y=He.value,E=na(y.fromId),L={position:{x:y.cursorX,y:y.cursorY},size:{width:1,height:1}},P;if(E){let b=Ac(E,L),T=Ac(L,E),w=T.x-b.x,_=T.y-b.y,z=Math.sqrt(w*w+_*_),U=Math.min(Math.max(z*0.35,32),160),N=zc(b,U),Z=zc(T,U);P=`M ${b.x} ${b.y} C ${N.x} ${N.y}, ${Z.x} ${Z.y}, ${T.x} ${T.y}`}else{let b=y.cursorX-y.fromX,T=y.cursorY-y.fromY,w=Math.sqrt(b*b+T*T),_=Math.min(w*0.25,80),z=b/(w||1),U=T/(w||1);P=`M ${y.fromX} ${y.fromY} C ${y.fromX+z*_} ${y.fromY+U*_}, ${y.cursorX-z*_} ${y.cursorY-U*_}, ${y.cursorX} ${y.cursorY}`}return i("g",{children:[i("path",{d:P,fill:"none",stroke:"var(--c-accent)","stroke-width":6*u,opacity:"0.1",style:{filter:"blur(3px)"}},void 0,!1,void 0,this),i("path",{d:P,fill:"none",stroke:"var(--c-accent)","stroke-width":2*u,"stroke-dasharray":`${6*u} ${4*u}`,opacity:"0.8"},void 0,!1,void 0,this),i("circle",{cx:y.cursorX,cy:y.cursorY,r:5*u,fill:"var(--c-accent)",opacity:"0.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})()]},void 0,!0,void 0,this)}function vA(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 np({annotations:e}){if(e.length===0)return null;return i("svg",{class:"annotation-layer","aria-hidden":"true",children:e.map((t)=>{let n=t.color==="currentColor"?"var(--c-annotation)":t.color;if(t.type==="text"){let o=t.points[0];if(!o||!t.text)return null;return i("text",{x:o.x,y:o.y,fill:n,"font-size":t.width,"font-family":"var(--font)","font-weight":"700",opacity:"0.95",children:t.text},t.id,!1,void 0,this)}return i("path",{d:vA(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 yA(e){switch(e.type){case"markdown":return i(Ca,{node:e},void 0,!1,void 0,this);case"mcp-app":return i(to,{node:e},void 0,!1,void 0,this);case"webpage":return i(cc,{node:e},void 0,!1,void 0,this);case"json-render":return i(to,{node:e},void 0,!1,void 0,this);case"graph":return i(to,{node:e},void 0,!1,void 0,this);case"board":return i(Ec,{node:e},void 0,!1,void 0,this);case"prompt":return i(lc,{node:e},void 0,!1,void 0,this);case"response":return i(uc,{node:e},void 0,!1,void 0,this);case"status":return i(sc,{node:e},void 0,!1,void 0,this);case"context":return i(da,{node:e},void 0,!1,void 0,this);case"ledger":return i(ba,{node:e},void 0,!1,void 0,this);case"trace":return i(dc,{node:e},void 0,!1,void 0,this);case"file":return i(ya,{node:e},void 0,!1,void 0,this);case"diff":return i(pa,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Ba,{node:e},void 0,!1,void 0,this);case"image":return i(ac,{node:e},void 0,!1,void 0,this);case"html":return i(Di,{node:e},void 0,!1,void 0,this);case"group":return i(vx,{node:e},void 0,!1,void 0,this);default:return i("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function bA(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 xA(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&&bA(t,c,l)<=n+r.width/2)return r}}return null}var op="currentColor",Iw=4,Ew=24,wA=14,Aw={width:520,height:420};function _A(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 ip(e){let t=e.trim();if(!t)return[];let n=t.includes(`
329
+ `)?t.split(/\r?\n/):t.split(/\s+/),o=new Set,r=[];for(let s of n){let a=s.trim();if(!a||a.startsWith("#"))continue;let c=_A(a);if(!c||o.has(c))continue;o.add(c),r.push(c)}return r}function SA(e){let t=ip(e.getData("text/uri-list"));if(t.length>0)return t;return ip(e.getData("text/plain"))}function kA(e){if(!e)return!1;return e.types.includes("text/uri-list")||e.types.includes("text/plain")}function rp(e){if(!(e instanceof HTMLElement))return!1;return Boolean(e.closest('input, textarea, select, [contenteditable="true"], [contenteditable=""]'))}function CA(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 zw({onNodeContextMenu:e,onEdgeContextMenu:t,onCanvasContextMenu:n,annotationMode:o=!1,annotationTool:r=null}){let s=J.value,a=R(!1),c=R(null),l=R(!1),u=R([]),[p,d]=I(null),[f,m]=I(null),[h,v]=I(null),x=R(null),[g,y]=I(!1),E=R(0),L=R(null),P=R(null);B(()=>{let M=null,K=jt(()=>{J.value;let me=P.current;if(!me)return;if(me.style.willChange="transform",M)clearTimeout(M);M=setTimeout(()=>{me.style.willChange="auto"},180)});return()=>{if(M)clearTimeout(M);K()}},[]);let b=ua({viewport:J,disabled:o,onViewportChange:(M)=>{if(a.current||o)return;kn(),ry(M)},onViewportCommit:(M)=>{if(a.current||o)return;kn(),sy(M)}}),T=H((M)=>{x.current=M,v(M)},[]),w=H(async(M,K,me)=>{if(M.length===0)return;let{width:ee,height:Q}=Aw,te=24,ne=Math.ceil(Math.sqrt(M.length)),W=Math.ceil(M.length/ne),le=ne*ee+Math.max(0,ne-1)*te,yt=W*Q+Math.max(0,W-1)*te;for(let Pt=0;Pt<M.length;Pt++){let D=Pt%ne,ae=Math.floor(Pt/ne),De=K-le/2+D*(ee+te),ge=me-yt/2+ae*(Q+te);await Qt({type:"webpage",content:M[Pt],x:De,y:ge,width:ee,height:Q})}},[]),_=H((M)=>{let K=b.current;if(!K)return;if(r==="eraser"){if((M.target instanceof Element?M.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;M.preventDefault(),M.stopPropagation();let W=K.getBoundingClientRect(),le=J.value,yt={x:(M.clientX-W.left-le.x)/le.scale,y:(M.clientY-W.top-le.y)/le.scale},Pt=xA(Array.from(cr.value.values()),yt,wA/le.scale);if(Pt)oy(Pt.id);return}if(r==="text"){if((M.target instanceof Element?M.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;M.preventDefault(),M.stopPropagation(),Ce.value=null,xt();let W=K.getBoundingClientRect(),le=J.value;T({x:(M.clientX-W.left-le.x)/le.scale,y:(M.clientY-W.top-le.y)/le.scale,value:""});return}if(r==="pen"){if((M.target instanceof Element?M.target:null)?.closest(".tool-rail, .top-bar, .snapshot-panel, .context-menu, .command-palette"))return;M.preventDefault(),M.stopPropagation(),Ce.value=null,xt(),l.current=!0;let W=K.getBoundingClientRect(),le=J.value,yt={x:(M.clientX-W.left-le.x)/le.scale,y:(M.clientY-W.top-le.y)/le.scale};u.current=[yt],m({id:"draft-annotation",type:"freehand",points:[yt],bounds:{x:0,y:0,width:0,height:0},color:op,width:Iw,createdAt:""}),K.setPointerCapture(M.pointerId);return}if(M.target!==K)return;if(ur()||M.button===1||M.button===2){if(!M.shiftKey&&!L.current)Ce.value=null,xt();return}M.preventDefault(),M.stopPropagation(),a.current=!0;let me=K.getBoundingClientRect(),ee=M.clientX-me.left,Q=M.clientY-me.top,te={startX:ee,startY:Q,currentX:ee,currentY:Q};L.current=te,d(te),K.setPointerCapture(M.pointerId)},[r,b]);B(()=>jt(()=>{let M=J.value,K=c.current,me=b.current;if(!K||!me)return;let ee=me.getBoundingClientRect();La({x:(K.x-ee.left-M.x)/M.scale,y:(K.y-ee.top-M.y)/M.scale})}),[]);let z=H((M)=>{{let ee=b.current;if(ee){c.current={x:M.clientX,y:M.clientY};let Q=ee.getBoundingClientRect(),te=J.value;La({x:(M.clientX-Q.left-te.x)/te.scale,y:(M.clientY-Q.top-te.y)/te.scale})}}if(l.current){let ee=b.current;if(!ee)return;let Q=ee.getBoundingClientRect(),te=J.value,ne={x:(M.clientX-Q.left-te.x)/te.scale,y:(M.clientY-Q.top-te.y)/te.scale},W=u.current.at(-1);if(W&&Math.hypot(ne.x-W.x,ne.y-W.y)<2)return;u.current=[...u.current,ne],m((le)=>le?{...le,points:u.current}:null);return}if(!a.current||!L.current)return;let K=b.current?.getBoundingClientRect();if(!K)return;let me={...L.current,currentX:M.clientX-K.left,currentY:M.clientY-K.top};L.current=me,d(me)},[b]),U=H((M)=>{if(l.current){l.current=!1;let ne=u.current;if(u.current=[],m(null),ne.length>=2)xu({points:ne,color:op,width:Iw});let W=b.current;if(W?.hasPointerCapture(M.pointerId))W.releasePointerCapture(M.pointerId);return}let K=L.current;if(!a.current||!K)return;a.current=!1,L.current=null;let me=Math.min(K.startX,K.currentX),ee=Math.max(K.startX,K.currentX),Q=Math.min(K.startY,K.currentY),te=Math.max(K.startY,K.currentY);if(ee-me<=5&&te-Q<=5)Ce.value=null,xt();if(ee-me>5||te-Q>5){let ne=J.value,W=(me-ne.x)/ne.scale,le=(ee-ne.x)/ne.scale,yt=(Q-ne.y)/ne.scale,Pt=(te-ne.y)/ne.scale,D=[];for(let ae of F.value.values()){let De=ae.position.x,ge=ae.position.y;if(De+ae.size.width>W&&De<le&&ge+ae.size.height>yt&&ge<Pt)D.push(ae.id)}if(D.length>0)Wv(D)}d(null)},[]);B(()=>{if(o)return;if(!l.current&&!f&&!h)return;l.current=!1,u.current=[],m(null),T(null)},[o,f,T,h]);let N=H(()=>{let M=x.current;if(!M)return;let K=M.value.trim();if(T(null),!K)return;let me={x:M.x,y:M.y};xu({type:"text",points:[me],color:op,width:Ew,text:K})},[T]);B(()=>{if(r!=="text"&&h)T(null)},[r,T,h]),B(()=>{let M=(Q,te,ne)=>{let W=null;for(let le of F.value.values()){if(le.id===ne||le.type==="group")continue;if(Q>=le.position.x&&Q<=le.position.x+le.size.width&&te>=le.position.y&&te<=le.position.y+le.size.height)W=le.id}return W};function K(Q){if(!He.value)return;let te=b.current;if(!te)return;let ne=te.getBoundingClientRect(),W=J.value,le=(Q.clientX-ne.left-W.x)/W.scale,yt=(Q.clientY-ne.top-W.y)/W.scale;He.value={...He.value,cursorX:le,cursorY:yt,targetId:M(le,yt,He.value.fromId)}}function me(){let Q=He.value;if(!Q)return;He.value=null;let te=Q.targetId;if(!te)return;if(Q.withLabel){Ot("Edge label","label text").then((ne)=>{To(Q.fromId,te,"relation",ne??void 0)});return}To(Q.fromId,te,"relation",void 0)}function ee(Q){let te=He.value;if(!te)return;if(Q.key==="Escape")Q.preventDefault(),He.value=null;else if(Q.key==="l"||Q.key==="L")Q.preventDefault(),He.value={...te,withLabel:!te.withLabel}}return document.addEventListener("pointermove",K),document.addEventListener("pointerup",me),document.addEventListener("keydown",ee),()=>{document.removeEventListener("pointermove",K),document.removeEventListener("pointerup",me),document.removeEventListener("keydown",ee)}},[b]);let Z=H((M)=>{if(o)return;let K=b.current;if(!K||M.target!==K||!n)return;let me=K.getBoundingClientRect(),ee=J.value,Q=(M.clientX-me.left-ee.x)/ee.scale,te=(M.clientY-me.top-ee.y)/ee.scale;n(M,Q,te)},[o,b,n]),j=H((M)=>{M.preventDefault()},[]),S=H((M)=>{if(rp(M.target instanceof Element?M.target:null))return;M.preventDefault()},[]),V=H((M)=>{if(M.preventDefault(),E.current++,M.dataTransfer?.types.includes("Files")||kA(M.dataTransfer))y(!0)},[]),he=H((M)=>{if(M.preventDefault(),M.dataTransfer)M.dataTransfer.dropEffect="copy"},[]),je=H((M)=>{if(M.preventDefault(),E.current--,E.current<=0)E.current=0,y(!1)},[]),se=H(async(M)=>{M.preventDefault(),y(!1),E.current=0;let K=b.current;if(!K||!M.dataTransfer)return;let me=K.getBoundingClientRect(),ee=J.value,Q=(M.clientX-me.left-ee.x)/ee.scale,te=(M.clientY-me.top-ee.y)/ee.scale,ne=Array.from(M.dataTransfer.files);if(ne.length===0){let W=SA(M.dataTransfer);await w(W,Q,te);return}await Rr(ne,Q,te)},[b,w]);B(()=>{let M=async(K)=>{if(K.defaultPrevented)return;if(rp(K.target instanceof Element?K.target:null))return;if(rp(document.activeElement))return;let me=K.clipboardData?.getData("text/plain")??"",ee=ip(me);if(ee.length===0)return;let Q=b.current;if(!Q)return;K.preventDefault();let te=Q.getBoundingClientRect(),ne=J.value,W=(te.width/2-ne.x)/ne.scale,le=(te.height/2-ne.y)/ne.scale;await w(ee,W,le)};return document.addEventListener("paste",M),()=>{document.removeEventListener("paste",M)}},[b,w]);let ue=CA(F.value.values(),Ue.value,new Set(vu.value.keys())),pe=un.value,fo=pe?F.value.get(pe.groupId):void 0,Vt=pe?F.value.get(pe.nodeId):void 0,sn=null;if(p){let M=Math.min(p.startX,p.currentX),K=Math.min(p.startY,p.currentY),me=Math.abs(p.currentX-p.startX),ee=Math.abs(p.currentY-p.startY);sn={position:"absolute",left:`${M}px`,top:`${K}px`,width:`${me}px`,height:`${ee}px`,pointerEvents:"none"}}return i("div",{class:`canvas-viewport${ur()?" pan-mode":""}`,ref:b,tabIndex:0,onPointerDown:_,onPointerMove:z,onPointerLeave:()=>{c.current=null,La(null)},onPointerUp:U,onContextMenu:j,onDblClick:Z,onDragStart:S,onDragEnter:V,onDragOver:he,onDragLeave:je,onDrop:se,style:{width:"100%",height:"100%",position:"relative",overflow:"hidden",cursor:r==="eraser"?"cell":r==="text"?"text":o||He.value||a.current||It.value==="connect"?"crosshair":ur()?"grab":"default"},children:[i("div",{ref:P,class:"canvas-world",style:{transform:`matrix(${s.scale}, 0, 0, ${s.scale}, ${s.x}, ${s.y})`,transformOrigin:"0 0",position:"absolute",top:0,left:0},children:[i(Cx,{},void 0,!1,void 0,this),i(lw,{},void 0,!1,void 0,this),i(Hx,{},void 0,!1,void 0,this),i(Kx,{},void 0,!1,void 0,this),i(Jx,{},void 0,!1,void 0,this),i(Tw,{nodes:F,edges:Le,onEdgeContextMenu:t},void 0,!1,void 0,this),He.value&&i("div",{class:"edge-hint-pill","data-testid":"edge-hint",style:{left:`${He.value.cursorX+14}px`,top:`${He.value.cursorY+14}px`},children:[i("span",{class:"edge-hint-main",children:He.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",He.value.withLabel?" · label on":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),pe&&fo&&Vt&&i("div",{class:"drop-pill","data-testid":"drop-pill",style:{left:`${Vt.position.x}px`,top:`${Vt.position.y+Vt.size.height+10}px`},children:[i("span",{class:"drop-pill-text",children:pe.mode==="add"?`release to add to ${String(fo.data.title??"group")}`:`release to remove from ${String(fo.data.title??"group")}`},void 0,!1,void 0,this),i("span",{class:"drop-pill-hint",children:pe.mode==="add"?"esc keeps it out":"esc keeps it in"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(np,{annotations:Array.from(cr.value.values())},void 0,!1,void 0,this),f&&f.points.length>=2&&i(np,{annotations:[f]},void 0,!1,void 0,this),ue.map((M)=>i(Cw,{node:M,onContextMenu:e,children:yA(M)},M.id,!1,void 0,this)),jo.value&&i("svg",{class:"snap-guides-svg",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:jo.value.map((M,K)=>M.axis==="x"?i("line",{x1:M.pos,y1:M.from-20,x2:M.pos,y2:M.to+20,class:"snap-guide-line"},K,!1,void 0,this):i("line",{x1:M.from-20,y1:M.pos,x2:M.to+20,y2:M.pos,class:"snap-guide-line"},K,!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:`${Ew*s.scale}px`},onInput:(M)=>T({...h,value:M.target.value}),onBlur:N,onPointerDown:(M)=>M.stopPropagation(),onKeyDown:(M)=>{if(M.key==="Enter")M.preventDefault(),N();if(M.key==="Escape")M.preventDefault(),T(null)}},void 0,!1,void 0,this),sn&&i("div",{class:"lasso-rect",style:sn},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 Pw(){let e=[...Ae.value],t=F.value,[n,o]=I(""),[r,s]=I(!1),a=Vx.value,[c,l]=I(null),u=a.length>=2,p=!u&&a.length===1&&a[0].steerable?a[0]:null,d=u?c?a.find((h)=>h.value===c&&h.steerable)??null:null:p,f=d?.value??null,m=async()=>{let h=n.trim();if(!h||r)return;s(!0);let v=await aw(h,f);if(s(!1),v)o("")};return i("div",{class:"command-bar","data-testid":"command-bar",children:[e.length>0&&i("div",{class:"command-bar-chips","aria-label":"Pinned context",children:[e.map((h)=>{let v=t.get(h),x=typeof v?.data.title==="string"&&v.data.title.trim()?v.data.title:v?.type??h;return i("span",{class:"command-bar-chip","data-node-id":h,children:[i("span",{class:"command-bar-chip-glyph","aria-hidden":"true",children:"✦"},void 0,!1,void 0,this),i("span",{class:"command-bar-chip-label",title:x,children:x},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-chip-unpin","aria-label":`Unpin ${x}`,title:"Remove from context",onClick:()=>Vn(h),children:"×"},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(Mr,{size:15,class:"command-bar-icon"},void 0,!1,void 0,this),u&&i("select",{class:"command-bar-target","aria-label":"Steer which agent",title:"Connected agents — steering reaches all of them unless you address one",value:f??"",onChange:(h)=>l(h.target.value||null),children:[i("option",{value:"",children:"All agents"},void 0,!1,void 0,this),a.map((h)=>{let v=h.pendingSteers&&h.pendingSteers>0?` · ${h.pendingSteers} queued`:"",x=h.polling?" · polling":"";return i("option",{value:h.value,disabled:!h.steerable,children:h.attached?`${h.label}${x}${v}`:h.steerable?`${h.label} · writer${x}${v}`:`${h.label} · no inbox`},h.value,!1,void 0,this)})]},void 0,!0,void 0,this),i("input",{class:"command-bar-input",type:"text",value:n,placeholder:`Steer ${d?.label??"the agent"}, or ${qe("K")} to search the board…`,"aria-label":"Steer the agent",disabled:r,onInput:(h)=>o(h.target.value),onKeyDown:(h)=>{if(h.key==="Enter")h.preventDefault(),m()}},void 0,!1,void 0,this),i("button",{type:"button",class:"command-bar-send",disabled:r||!n.trim(),onClick:()=>void m(),children:r?"Sending…":"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var sp=Oe(()=>{if(Mt.value==="disconnected")return"reconnecting";if(Mt.value==="connected"&&!Tt.value&&Eo.value>1)return"resyncing";return null});function Nw(){let e=sp.value;if(!e)return null;if(e==="reconnecting"){let t=Ao.value,n=zo.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 TA={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 Dt(e){if(e.x!==void 0&&e.y!==void 0)return Qt(e);let t=TA[e.type]??{width:360,height:200},n=e.width??t.width,o=e.height??t.height,r=Zn(),s=J.value,a=await Qt({...e,width:n,height:o,x:Math.round((r.x-s.x)/s.scale-n/2),y:Math.round((r.y-s.y)/s.scale-o/2)});if(a.ok&&a.id)Ke(a.id);return a}var Pc=!1,Rw=!1,Zo=null,Hr=null;function ap(){return Pc}function Nc(){Pc=!1,Rw=!0,$w()}function $w(){if(Zo&&Hr)Zo.removeEventListener("change",Hr);Zo=null,Hr=null}function IA(){if(typeof window>"u"||!window.location)return null;let e=new URLSearchParams(window.location.search).get("theme");if(e==="auto")return"auto";return Ti(e)?e:null}function Mw(e){if(Rw)return;let t=IA();if(!t)return;if($w(),Pc=!0,t!=="auto"){e(t);return}Zo=window.matchMedia("(prefers-color-scheme: light)"),Hr=()=>{if(Pc&&Zo)e(Zo.matches?"light":"dark")},Hr(),Zo.addEventListener("change",Hr)}var EA='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function zt(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(EA)),c=n.initial?.current??a()[0];if(c&&!o.contains(document.activeElement))c.focus();let l=(u)=>{if(u.key!=="Tab")return;let p=a();if(p.length===0)return;let d=p[0],f=p[p.length-1],m=document.activeElement;if(u.shiftKey&&(m===d||!o.contains(m)))u.preventDefault(),f.focus();else if(!u.shiftKey&&m===f)u.preventDefault(),d.focus()};return o.addEventListener("keydown",l),()=>{if(o.removeEventListener("keydown",l),s)requestAnimationFrame(()=>s()?.focus());else if(r&&document.contains(r)&&r!==document.body)r.focus()}},[e,t,n.initial,n.restoreTo])}function AA(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 zA(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 cp={md:"markdown",app:"mcp-app",web:"webpage",ui:"json-render",chart:"graph",ctx:"context",log:"ledger"};function PA(e){let t=e.toLowerCase().trim();if(t.startsWith("type:")){let n=t.slice(5).trim(),r=Object.keys(lt).find((a)=>a.startsWith(n));if(r)return{typeFilter:r,remaining:""};let s=cp[n];if(s)return{typeFilter:s,remaining:""}}if(cp[t])return{typeFilter:cp[t],remaining:""};return{typeFilter:null,remaining:e}}function Ow({onClose:e,onToggleMinimap:t}){let[n,o]=I(""),[r,s]=I(0),[a,c]=I([]),[l,u]=I("idle"),p=R(null),d=R(null),f=R(null);zt(f,!0,{initial:p}),B(()=>{setTimeout(()=>p.current?.focus(),30)},[]),B(()=>{let b=n.trim();if(b.length<2){c([]),u("idle");return}let T=!0;u("loading");let w=window.setTimeout(()=>void Y("paletteLibrarySearch",`/api/canvas/search?q=${encodeURIComponent(b)}&scope=library&limit=12`,null).then((_)=>{if(!T)return;if(!_){c([]),u("error");return}c(_.results??[]),u("idle")}),150);return()=>{T=!1,window.clearTimeout(w)}},[n]);let m=H(()=>{let b=[];for(let w of F.value.values()){let _=w.data.title||lt[w.type],z=w.data.content||w.data.path||"",U=w.type==="group"&&Array.isArray(w.data.children)?w.data.children.length:0;b.push({id:`node:${w.id}`,kind:"node",label:_,description:w.type==="group"?`group · ${U} node${U===1?"":"s"}`:z.length>60?`${lt[w.type].toLowerCase()} · ${z.slice(0,60)}…`:z?`${lt[w.type].toLowerCase()} · ${z}`:lt[w.type].toLowerCase(),icon:rn(w.type),nodeType:w.type,action:()=>{Ke(w.id),e()}})}let T=[{label:"New markdown note",shortcut:"M",icon:no,iconTone:"accent",action:()=>{Dt({type:"markdown",title:"New note",width:520,height:360}),e()}},{label:"Link to board…",icon:rn("board"),iconTone:"accent",action:()=>{window.dispatchEvent(new CustomEvent("pmx-open-board-link")),e()}},...vt.value?[]:[{label:"Start agent session",icon:Mr,iconTone:"purple",action:()=>{co(),e()}}],{label:"Fit view",shortcut:"F",icon:mc,iconTone:"muted",action:()=>{mr(ot().width,ot().height),e()}},{label:"Auto-arrange (grid)",icon:En,iconTone:"muted",action:()=>{ca(),e()}},{label:"Auto-arrange (graph-aware)",icon:En,iconTone:"muted",action:()=>{la(),e()}},{label:"Toggle minimap",icon:fc,iconTone:"muted",action:()=>{t(),e()}},{label:"Toggle theme (dark/light)",icon:hc,iconTone:"muted",action:()=>{let w=et.value==="dark"?"light":"dark";Nc(),document.documentElement.setAttribute("data-theme",w),Pr(),et.value=w,Gs(w),e()}}];for(let w of T)b.push({id:`action:${w.label}`,kind:"action",label:w.label,...w.shortcut?{shortcut:w.shortcut}:{},icon:w.icon,...w.iconTone?{iconTone:w.iconTone}:{},action:w.action});return b},[e,t]),{typeFilter:h,remaining:v}=PA(n),x=m(),g;if(!n.trim())g=x.map((b)=>({...b,score:0,indices:[]}));else{g=[];for(let b of x){if(h){if(b.kind!=="node"||b.nodeType!==h)continue;if(!v){g.push({...b,score:0,indices:[]});continue}}let T=AA(v||n,b.label);if(T.match)g.push({...b,score:T.score,indices:T.indices})}g.sort((b,T)=>T.score-b.score)}for(let b of a)g.push({id:`library:${b.boardId}:${b.cardId}`,kind:"library",label:b.title||b.boardTitle,description:`${b.boardTitle} · ${b.snippet}`,icon:rn("board"),score:0,indices:[],action:()=>{(async()=>{if(await At(b.boardId),Pe.value!==b.boardId)return;for(let T=0;T<40&&Pe.value===b.boardId;T++){if(F.value.has(b.cardId)){Ke(b.cardId),e();return}await new Promise((w)=>window.setTimeout(w,25))}})()}});g=[...g.filter((b)=>b.kind==="action"),...g.filter((b)=>b.kind==="node"),...g.filter((b)=>b.kind==="library")];let y=g.findIndex((b)=>b.kind==="node"),E=g.findIndex((b)=>b.kind==="library");B(()=>{if(!n.trim()){wn.value=null;return}let b=new Set;for(let T of g)if(T.kind==="node")b.add(T.id.slice(5));wn.value=b.size>0?b:null},[n,g]),B(()=>()=>{wn.value=null},[]);let L=Math.min(r,Math.max(0,g.length-1)),P=H((b)=>{if(b.key==="ArrowDown")b.preventDefault(),s((T)=>Math.min(T+1,g.length-1));else if(b.key==="ArrowUp")b.preventDefault(),s((T)=>Math.max(T-1,0));else if(b.key==="Enter"){if(b.preventDefault(),g[L])g[L].action()}else if(b.key==="Escape")b.preventDefault(),b.stopPropagation(),e()},[g,L,e]);return B(()=>{let b=d.current;if(!b)return;b.children[L]?.scrollIntoView({block:"nearest"})},[L]),B(()=>{s(0)},[n]),i("div",{class:"command-palette-backdrop",onMouseDown:e,children:i("div",{ref:f,class:"command-palette",role:"dialog","aria-modal":"true","aria-label":"Search and commands",onMouseDown:(b)=>b.stopPropagation(),children:[i("div",{class:"command-palette-search",children:[i("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),i("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{ref:p,type:"text",class:"command-palette-input",value:n,onInput:(b)=>o(b.target.value),onKeyDown:P,placeholder:"Search nodes, run actions, jump to…","aria-label":"Search nodes, run actions, jump to"},void 0,!1,void 0,this),i("kbd",{class:"command-palette-esc",children:"esc"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"command-palette-results",ref:d,children:[l==="loading"&&i("div",{class:"command-palette-empty",role:"status",children:"Searching all boards…"},void 0,!1,void 0,this),l==="error"&&i("div",{class:"command-palette-empty",role:"alert",children:"Library search is unavailable."},void 0,!1,void 0,this),g.length===0&&l!=="loading"&&i("div",{class:"command-palette-empty",children:"No matching nodes, boards, or actions"},void 0,!1,void 0,this),g.map((b,T)=>{let w=b.icon,_=T===0&&b.kind==="action"?"Actions":T===y?"Jump to":T===E?"Across boards":null;return i("div",{class:"command-palette-row",children:[_&&i("div",{class:"command-palette-group",children:_},void 0,!1,void 0,this),i("button",{type:"button",class:`command-palette-item${T===L?" selected":""}`,onMouseEnter:()=>s(T),onClick:()=>b.action(),children:[i("span",{class:`command-palette-icon tone-${b.iconTone??"kind"}`,"aria-hidden":"true",children:i(w,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"command-palette-label",children:[b.indices.length>0?zA(b.label,b.indices):b.label,b.description&&i("span",{class:"command-palette-desc",children:[" — ",b.description]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),b.shortcut&&i("kbd",{class:"command-palette-kbd",children:b.shortcut},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},b.id,!0,void 0,this)})]},void 0,!0,void 0,this),i("div",{class:"command-palette-hint",children:[i("span",{children:"↑↓ navigate"},void 0,!1,void 0,this),i("span",{children:"↵ open"},void 0,!1,void 0,this),i("span",{children:"esc close"},void 0,!1,void 0,this),i("span",{children:"type: filter"},void 0,!1,void 0,this),i("span",{class:"command-palette-hint-spacer"},void 0,!1,void 0,this),i("span",{children:qe("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 Lw({onClose:e}){let t=R(null),n=R(null),[o,r]=I(""),[s,a]=I("");zt(t,!0,{initial:n});let c=Et.value.filter((u)=>u.id!==Pe.value&&u.name.toLowerCase().includes(o.trim().toLowerCase())),l=async(u)=>{let p=Et.value.find((h)=>h.id===u);if(!p)return a("That board is no longer available.");let d=Zn(),f=J.value;if(!(await Y("createBoardLink","/api/canvas/node",{},{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"board",title:p.name,x:Math.round((d.x-f.x)/f.scale-180),y:Math.round((d.y-f.y)/f.scale-100),width:360,height:200,data:{boardId:u}})})).ok)return a("Could not create the board link.");e()};return i("div",{class:"text-prompt-backdrop",onMouseDown:e,children:i("div",{ref:t,class:"text-prompt board-link-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"board-link-title",onMouseDown:(u)=>u.stopPropagation(),children:[i("h2",{id:"board-link-title",children:"Link to a board"},void 0,!1,void 0,this),i("input",{ref:n,type:"search",class:"text-prompt-input","aria-label":"Find a board to link",placeholder:"Find a board…",value:o,onInput:(u)=>r(u.currentTarget.value)},void 0,!1,void 0,this),s&&i("div",{role:"alert",class:"board-copy-error",children:s},void 0,!1,void 0,this),i("ul",{class:"board-link-results",children:[c.map((u)=>i("li",{children:i("button",{type:"button",onClick:()=>void l(u.id),children:[i("span",{children:u.name},void 0,!1,void 0,this),i("small",{children:[u.nodeCount," nodes"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},u.id,!1,void 0,this)),c.length===0&&i("li",{class:"board-copy-status",children:Et.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 Dw(){let[e,t]=I(null),n=H((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"node",x:a.clientX,y:a.clientY,nodeId:c})},[]),o=H((a,c,l)=>{a.preventDefault(),a.stopPropagation(),t({kind:"canvas",x:a.clientX,y:a.clientY,canvasX:c,canvasY:l})},[]),r=H((a,c)=>{a.preventDefault(),a.stopPropagation(),t({kind:"edge",x:a.clientX,y:a.clientY,edgeId:c})},[]),s=H(()=>t(null),[]);return B(()=>{if(!e)return;let a=()=>t(null),c=(l)=>{if(l.key==="Escape")t(null)};return document.addEventListener("click",a),document.addEventListener("keydown",c),()=>{document.removeEventListener("click",a),document.removeEventListener("keydown",c)}},[e]),{menu:e,openNodeMenu:n,openCanvasMenu:o,openEdgeMenu:r,closeMenu:s}}var NA="#4bbcFF",RA=[{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 Fw({menu:e,onClose:t}){let n;if(e.kind==="node"){let c=F.value.get(e.nodeId);if(!c)return null;n=FA(c)}else if(e.kind==="edge"){let c=e.edgeId,l=Le.value.get(c);n=[{label:l?.label?`Edit label “${l.label.slice(0,18)}${l.label.length>18?"…":""}”`:"Add label…",action:()=>{Ot("Edge label (empty clears it)","label text",{initial:l?.label??"",allowEmpty:!0,confirm:"Save"}).then((u)=>{if(u===null)return;Qs(c,{label:u})})}},{separator:!0},...["flow","depends-on","relation","references"].map((u)=>({label:`${l?.type===u?"✓":" "} ${u}`,action:()=>void Qs(c,{type:u})})),{separator:!0},...["solid","dashed","dotted"].map((u)=>({label:`${(l?.style??"solid")===u?"✓":" "} ${u}`,action:()=>void Qs(c,{style:u})})),{separator:!0},{label:"Delete edge",danger:!0,action:()=>void ea(c)}]}else n=DA(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 $A(e){return(typeof e.data.path==="string"?e.data.path.trim():"")||null}function Rc(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 Bw(e){if(typeof e.data.color!=="string"||!e.data.color.trim())return null;return Rc(e.data.color)}function MA(e){let t=Bw(e);return t&&/^#[0-9a-f]{6}$/.test(t)?t:Rc(NA)}function lp(e,t){let n=t?Rc(t):null;it(e.id,{data:{...e.data,color:n}}),dt(e.id,{data:{color:n}})}function OA(e,t){let n=Bw(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:()=>{lp(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:RA.map((o)=>{let r=Rc(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:()=>{lp(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:MA(e),onClick:(o)=>o.stopPropagation(),onInput:(o)=>{lp(e,o.currentTarget.value),t()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function dp(e,t,n,o){return{x:e-n/2,y:t-o/2}}function LA(e,t){return e.trim().replace(/[?#].*$/,"").split("/").filter(Boolean).at(-1)||t}async function up(e){let t=await Ot(e.promptLabel,e.placeholder??"");if(!t)return;let n=t.trim();if(!n)return;let o=dp(e.canvasX,e.canvasY,e.width,e.height);if(!(await Qt({type:e.type,...e.type!=="webpage"?{title:LA(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 DA(e,t){return[{label:"New note",action:()=>{let r=dp(e,t,520,360);Qt({type:"markdown",title:"New note",x:r.x,y:r.y,width:520,height:360})}},{label:"Open webpage...",action:()=>{up({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:()=>{up({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:()=>{up({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=dp(e,t,600,400);sr({title:"Group",x:r.x,y:r.y,width:600,height:400})}}]}function FA(e){let t=[],n=$A(e);if(t.push({label:"Focus",action:()=>Ke(e.id)}),t.push({label:"Rename…",action:()=>{Ot("Rename node","Node title",{initial:typeof e.data.title==="string"?e.data.title:"",confirm:"Save"}).then((l)=>{if(!l?.trim())return;dt(e.id,{title:l.trim()})})}}),ai.has(e.type))t.push({label:"Expand",shortcut:"⤢",action:()=>Zt(e.id)});t.push({label:e.collapsed?"Expand":"Collapse",action:()=>dr(e.id)});let o=Ae.value.has(e.id);t.push({label:o?"Unpin from context":"Pin as context",action:()=>Vn(e.id)}),t.push({label:e.pinned?"Unlock position":"Lock position (no auto-arrange)",action:()=>{let l=!e.pinned;it(e.id,{pinned:l}),dt(e.id,{pinned:l}),st()}});let r=hi.value;if(r&&r.from!==e.id){let l=F.value.get(r.from),u=l?(l.data.title||l.id).slice(0,20):r.from;t.push({label:`Connect from "${u}"`,action:()=>{To(r.from,e.id,"relation"),hi.value=null}})}t.push({label:r?"Connect from here (replace)":"Connect from here",action:()=>{hi.value={from:e.id}}});let s=Array.from(Le.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:()=>Cv("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:()=>{Ks(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)=>OA(e,u)}),l.length>0)t.push({label:`Ungroup (${l.length} node${l.length!==1?"s":""})`,action:()=>{Gn(e.id),ar(e.id)}})}let a=typeof e.data.parentGroup==="string"?e.data.parentGroup:null,c=a?F.value.get(a):void 0;if(c&&c.type==="group"){let l=typeof c.data.title==="string"&&c.data.title?c.data.title:"frame",u=Array.isArray(c.data.children)?c.data.children.filter((p)=>p!==e.id):[];t.push({label:`Remove from “${l}”`,action:()=>{Ys(c.id,u)}})}return t.push({separator:!0}),t.push({label:e.type==="group"?"Delete frame (children stay)":"Delete",danger:!0,action:()=>{qn(e.id)}}),t}function Hw(){let e=Ae.value.size;if(e===0||ln.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:ey,title:"Clear all context pins",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jw({onClose:e}){let t=R(null),[n,o]=I("Bug report"),[r,s]=I(""),[a,c]=I("");return zt(t,!0),i("div",{class:"text-prompt-backdrop feedback-backdrop",onPointerDown:e,children:i("form",{ref:t,class:"text-prompt feedback-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"feedback-title","aria-describedby":"feedback-privacy",action:"https://github.com/pskoett/pmx-canvas/issues/new",method:"get",target:"_blank",rel:"noopener noreferrer",onPointerDown:(l)=>l.stopPropagation(),onKeyDown:(l)=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),e()},children:[i("div",{id:"feedback-title",class:"text-prompt-title",children:"Bug and feedback"},void 0,!1,void 0,this),i("p",{id:"feedback-privacy",class:"feedback-note",children:"Opens a draft issue in pskoett/pmx-canvas. Review and submit it on GitHub using your account. Issues are public. Only what you enter below is included; no board contents, workspace paths, screenshots, or logs are attached."},void 0,!1,void 0,this),i("label",{children:["Feedback type",i("select",{class:"text-prompt-input",value:n,onChange:(l)=>o(l.currentTarget.value),children:[i("option",{children:"Bug report"},void 0,!1,void 0,this),i("option",{children:"Feature request"},void 0,!1,void 0,this),i("option",{children:"General feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("label",{children:["Title",i("input",{class:"text-prompt-input",name:"title",required:!0,maxLength:120,value:r,onInput:(l)=>s(l.currentTarget.value),placeholder:"A short summary"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("label",{children:["Description",i("textarea",{class:"text-prompt-input",required:!0,maxLength:1200,rows:6,value:a,onInput:(l)=>c(l.currentTarget.value),placeholder:"What happened, what you expected, and steps to reproduce — or describe your idea."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{type:"hidden",name:"body",value:`## ${n}
315
330
 
316
- ${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 ↗"},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 Ei(e,t){console.error(`[tool-rail] ${e} failed`,t)}function Sn(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"}};on(t[e].message,t[e].placeholder).then((n)=>{if(!n)return;Nt({type:e,content:n}).catch((o)=>Ei(`create ${e}`,o))})}function nt({label:e,shortcut:t,detail:n,ariaLabel:o,active:r,menuOpen:s,onClick:a,btnRef:c,children:l}){let[u,d]=O(null),p=(v)=>{let y=v.currentTarget.getBoundingClientRect();d({left:y.right+10,top:y.top+y.height/2})},f=()=>d(null),m=o??(t?`${e} (${t})`:n?`${e} (${n})`:e);return i(ve,{children:[i("button",{ref:c,type:"button",class:`rail-btn${r?" active":""}`,"aria-label":m,"aria-pressed":r===void 0?void 0:r,onClick:(v)=>{f(),a(v)},onPointerEnter:p,onPointerLeave:f,onFocus:p,onBlur:f,children:l},void 0,!1,void 0,this),u&&!s&&i("span",{class:"toolbar-tooltip rail-tooltip",role:"tooltip","data-testid":"rail-tooltip",style:{left:`${u.left}px`,top:`${u.top}px`},children:[i("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),(t||n)&&i("span",{class:"toolbar-tooltip-meta",children:[t&&i("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this),n&&i("span",{children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function sw({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:r,onOpenPalette:s,onOpenShortcuts:a,annotationTool:c,onSetAnnotationTool:l}){let u=_t.value,d=Go.value,p=Array.from(N.value.values()).filter((C)=>C.type==="trace").length,f=$e.value.size,[m,v]=O(!1),[y,x]=O(null),[h,g]=O(null),b=M(null),E=(C)=>(Z)=>{if(y===C){x(null);return}let F=Z.currentTarget.getBoundingClientRect();g({top:F.top,bottom:F.bottom,right:F.right}),x(C)},j=(C)=>h?C?{position:"fixed",left:`${h.right+8}px`,bottom:`${window.innerHeight-h.bottom}px`,top:"auto",right:"auto"}:{position:"fixed",left:`${h.right+8}px`,top:`${h.top}px`,right:"auto"}:void 0;D(()=>{if(!y)return;let C=(F)=>{if(b.current&&F.target instanceof Node&&!b.current.contains(F.target))x(null)},Z=(F)=>{if(F.key==="Escape")x(null)};return document.addEventListener("pointerdown",C),document.addEventListener("keydown",Z),()=>{document.removeEventListener("pointerdown",C),document.removeEventListener("keydown",Z)}},[y]);let _=(C)=>{lc(),document.documentElement.setAttribute("data-theme",C),wr(),Je.value=C,Ss(C),x(null)},R=Pu(Je.value),A=(C,Z={})=>{fetch(`/api/workbench/intent?_ts=${Date.now()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:C,payload:Z})}).catch((F)=>Ei("sendIntent",F))};return i(ve,{children:[i("div",{class:"tool-rail",ref:b,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[i("span",{class:"rail-brand",title:"PMX Canvas","aria-label":"PMX Canvas",children:i(Vx,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Bug and feedback",menuOpen:m,onClick:()=>{x(null),v(!0)},children:i("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:[i("rect",{x:"4.5",y:"5",width:"7",height:"9",rx:"3.5"},void 0,!1,void 0,this),i("path",{d:"M6 5V4a2 2 0 0 1 4 0v1M8 8v6M2 4l2.5 2M14 4l-2.5 2M1.5 9h3M11.5 9h3M2 14l2.5-2M14 14l-2.5-2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-divider"},void 0,!1,void 0,this),i(nt,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>_t.value="select",children:i(Gx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>_t.value="pan",children:i(Xx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>_t.value="connect",children:i("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","aria-hidden":"true",children:[i("circle",{cx:"4",cy:"4",r:"2"},void 0,!1,void 0,this),i("circle",{cx:"12",cy:"12",r:"2"},void 0,!1,void 0,this),i("path",{d:"M5.5 5.5 C 8 8, 8 8, 10.5 10.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-divider"},void 0,!1,void 0,this),i(nt,{label:"Markdown note",shortcut:"M",onClick:()=>void Nt({type:"markdown",title:"New note",width:520,height:360}).catch((C)=>Ei("create markdown",C)),children:i(Wn,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Image",shortcut:"I",onClick:()=>Sn("image"),children:i(vd,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"File",shortcut:"Shift+F",onClick:()=>Sn("file"),children:i(qa,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Webpage",shortcut:"W",onClick:()=>Sn("webpage"),children:i(Sr,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"HTML surface",shortcut:"H",onClick:()=>void Nt({type:"html",title:"HTML surface"}).catch((C)=>Ei("create html",C)),children:i(Kx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Group",shortcut:"G",onClick:()=>void Nt({type:"group",title:"Group"}).catch((C)=>Ei("create group",C)),children:i(yd,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"toolbar-menu-anchor",children:[i(nt,{label:"Annotate",shortcut:"A",detail:"Draw · Text note · Eraser",active:c!==null,menuOpen:y==="annotate",onClick:E("annotate"),children:c==="eraser"?i(hd,{},void 0,!1,void 0,this):c==="text"?i(gd,{},void 0,!1,void 0,this):i(fd,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),y==="annotate"&&i("div",{class:"toolbar-menu",style:j(!1),role:"menu","aria-label":"Annotate",children:[i("button",{type:"button",class:`toolbar-menu-item${c==="pen"?" active":""}`,onClick:()=>{l(c==="pen"?null:"pen"),x(null)},children:[i(fd,{},void 0,!1,void 0,this),i("span",{children:c==="pen"?"Stop annotating":"Draw (A)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:`toolbar-menu-item${c==="text"?" active":""}`,onClick:()=>{l(c==="text"?null:"text"),x(null)},children:[i(gd,{},void 0,!1,void 0,this),i("span",{children:c==="text"?"Stop text notes":"Text note"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:`toolbar-menu-item${c==="eraser"?" active":""}`,onClick:()=>{l(c==="eraser"?null:"eraser"),x(null)},children:[i(hd,{},void 0,!1,void 0,this),i("span",{children:c==="eraser"?"Stop erasing":"Eraser"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"rail-spacer"},void 0,!1,void 0,this),i(nt,{label:"Search & commands",shortcut:He("K"),onClick:s,children:i(Wx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Arrange",detail:f>0?"graph-aware":"grid",onClick:()=>f>0?Ds():Ls(),children:i(Ao,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:d?"Disable trace":"Enable trace",active:d,onClick:()=>A("trace-toggle",{enabled:!d}),children:i(Bx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),(d||p>0)&&i(nt,{label:"Clear trace",onClick:()=>A("trace-clear"),children:i(Ux,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:e?"Hide minimap":"Show minimap",active:e,onClick:t,children:i(Ga,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(nt,{label:"Snapshots",active:n,onClick:o,btnRef:r,children:i(Hx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"toolbar-menu-anchor",children:[i(nt,{label:"Theme",detail:mr[R].label,menuOpen:y==="theme",ariaLabel:"Choose theme",active:y==="theme",onClick:E("theme"),children:fr(R)==="dark"?i(Zx,{},void 0,!1,void 0,this):i(Xa,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),y==="theme"&&i("div",{class:"toolbar-menu",style:j(!0),role:"menu","aria-label":"Theme",children:zu.map((C)=>i("button",{type:"button",role:"menuitemradio","aria-checked":R===C,class:`toolbar-menu-item${R===C?" active":""}`,onClick:()=>_(C),children:[i("span",{class:"theme-swatch",style:{background:mr[C].swatchBg},children:i("span",{class:"theme-swatch-dot",style:{background:mr[C].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{children:mr[C].label},void 0,!1,void 0,this),R===C&&i("span",{class:"toolbar-menu-check","aria-hidden":"true",children:"✓"},void 0,!1,void 0,this)]},C,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(nt,{label:"Shortcuts",shortcut:"?",onClick:a,children:i(qx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m&&i(iw,{onClose:()=>v(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function aw({onOpenPalette:e}){let t=M(null),n=()=>{Nt({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(r)=>{if(!r||r.length===0)return;let s=Zo(),a=ee.value;await Wa(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(Wn,{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:()=>Sn("webpage"),children:[i(Sr,{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:He("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 Jn(),children:[i(kr,{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 · ",He("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)}function Hd({presence:e,size:t=18}){return i("span",{class:"writer-avatar",style:{background:Ja(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:sb(e.label)},void 0,!1,void 0,this)}function cw(){let e=Cd.value;if(ft.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=Io.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:()=>{Io.value=!o},children:[i("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((r)=>i(Hd,{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 BA(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 UA(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function WA(){return[...We.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function lw(){let e=Io.value,t=Cd.value,n=_n(e?1e4:0);if(D(()=>{if(!e)return;let c=(l)=>{if(l.key!=="Escape")return;if(Cr.value)Cr.value=!1;else Io.value=!1};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e]),!e||ft.value||t.length===0)return null;let o=kd.value,r=WA().filter((c)=>!o||(c.source??"")===o),s=Gn.value.filter((c)=>!o||c.sessionId===o),a=(c,l)=>i("button",{type:"button",class:`activity-filter${o===c?" is-active":""}`,style:c?{"--writer":Ja(c)}:void 0,"aria-pressed":o===c,onClick:()=>{kd.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"," ",Ya(UA(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:()=>{Io.value=!1},children:"×"},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:()=>{fo(c).then((l)=>{if(l)_o(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}=BA(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:Ja(c.sessionId)},children:c.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"activity-age",children:Ya(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:()=>{Cr.value=!0},children:"Writers"},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{Io.value=!1,Jn()},children:"Start session ↗"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function qA(){let e=[];if(Xn.value)e.push("scoped");if(zo.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function uw(){let e=Cr.value,t=_n(e?1e4:0),n=M(null);if(Yn(n,e),!e)return null;let o=mt.value.filter((a)=>a.attached),r=mt.value.filter((a)=>!a.attached),s=()=>{Cr.value=!1};return i(ve,{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:mn.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:"×"},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(Hd,{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:qA()},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(Hd,{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"," ",Ya(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 dw(e,t){switch(e.type){case"markdown":return i(ia,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return i(Un,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return i(Za,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return i(Un,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return i(Un,{node:e,expanded:t},void 0,!1,void 0,this);case"prompt":return i(Ha,{node:e},void 0,!1,void 0,this);case"response":return i(Ba,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return i(Fa,{node:e},void 0,!1,void 0,this);case"context":return i(Xs,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return i(Qs,{node:e},void 0,!1,void 0,this);case"trace":return i(Ua,{node:e},void 0,!1,void 0,this);case"file":return i(Ys,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return i(Ks,{node:e},void 0,!1,void 0,this);case"mermaid":return i(xa,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return i(ja,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return i(Si,{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 pw(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 VA(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function GA(e,t){return e!==null&&typeof e==="object"&&e.source===Dt&&e.type==="presentation-exit"&&e.token===t}function XA(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function mw(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function fw(){let e=Ue.value,t=e?N.value.get(e):void 0,[n,o]=O(!1),[r,s]=O(!1),[a,c]=O(""),l=M(null),u=M(null),d=L(()=>{s(!1),xo()},[]),p=L(()=>{c(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),s(!0)},[]),f=L((H)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:Dt,token:a,...H},"*")},[a]),m=L(()=>{s(!1)},[]),v=L((H)=>{if(H.key==="Escape"){H.preventDefault(),H.stopPropagation(),s(!1);return}if(H.key==="Tab"&&!mw(H.target)){H.preventDefault(),H.stopPropagation(),u.current?.focus();return}if((H.key===" "||H.key==="Enter")&&mw(H.target))return;if(!XA(H.key))return;H.preventDefault(),H.stopPropagation(),f({type:"presentation-key",key:H.key})},[f]),y=L((H)=>{if(H.target.classList.contains("expanded-overlay-backdrop"))xo()},[]),x=L(()=>{if(!t)return;let H=pw(t);if(!H)return;navigator.clipboard.writeText(H).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),h=L(()=>{if(!e)return;Ln(e)},[e]);D(()=>{s(!1)},[e]),qi(()=>{if(!r)return;let H=()=>{let xe=l.current;if(!xe||xe.contains(document.activeElement))return;xe.focus()},U=[0,50,150].map((xe)=>window.setTimeout(H,xe)),te=(xe)=>{if(!GA(xe.data,a))return;s(!1)};return document.addEventListener("keydown",v,!0),window.addEventListener("message",te),()=>{U.forEach((xe)=>{window.clearTimeout(xe)}),document.removeEventListener("keydown",v,!0),window.removeEventListener("message",te)}},[v,a,r]);let g=M(null),b=L(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]);if(Yn(g,t!==void 0,{restoreTo:b}),!t)return null;let E=t.data.title||t.data.path?.split("/").pop()||at[t.type],j=pw(t),_=VA(j),R=e?Ae.value.has(e):!1,A=j.length>0,C=Qt.value===e,Z=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",F=zx(t),T=bn(t.type),B=t.data.provenance&&typeof t.data.provenance==="object"?t.data.provenance:null,W=B?[B.sourceKind,B.sourceUri,B.syncedAt?`synced ${B.syncedAt.slice(11,16)}`:null].filter((H)=>typeof H==="string"&&H.length>0).join(" · "):null;return i("div",{class:"expanded-overlay-backdrop",onPointerDown:y,style:{pointerEvents:C?"none":"auto"},children:i("div",{ref:g,class:`expanded-overlay-panel${R?" is-pinned":""}`,role:"dialog","aria-modal":"true","aria-label":E,"data-testid":"expanded-node",children:[i("div",{class:"expanded-header",children:[i("span",{class:"expanded-kind-icon","aria-hidden":"true",children:i(T,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"expanded-title",children:E},void 0,!1,void 0,this),i("span",{class:"expanded-kind-pill",children:at[t.type]},void 0,!1,void 0,this),i("button",{type:"button",class:`expanded-pin${R?" is-on":""}`,onClick:h,title:R?"In agent context — click to unpin":"Pin as agent context","aria-pressed":R,children:"✦"},void 0,!1,void 0,this),i("span",{class:"expanded-spacer"},void 0,!1,void 0,this),i("div",{class:"expanded-actions",children:[A&&i("button",{type:"button",class:"expanded-action-btn",onClick:x,title:"Copy content to clipboard",children:n?"Copied!":"Copy"},void 0,!1,void 0,this),la(t)&&i("button",{type:"button",class:"expanded-action-btn",onClick:()=>void ua(t),title:"Open as a full-page site in the system browser",children:"Open in tab ↗"},void 0,!1,void 0,this),F&&i("button",{type:"button",class:"expanded-action-btn expanded-action-primary",onClick:p,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:d,title:"Close (Esc)","aria-label":"Close",children:"×"},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:dw(t,!0)},void 0,!1,void 0,this):dw(t,!0)},void 0,!1,void 0,this),i("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:i(ic,{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:[W,_>0?`${_.toLocaleString()} word${_!==1?"s":""}`:null].filter(Boolean).join(" · ")||at[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${C?" is-saving":""}`,children:C?"Saving edits…":"esc or click outside to close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F&&r&&i("div",{ref:l,class:"html-presentation-overlay",role:"dialog","aria-modal":"true","aria-label":`Present ${E}`,tabIndex:-1,onKeyDownCapture:v,children:[i("button",{ref:u,type:"button",class:"html-presentation-exit",onClick:m,title:"Exit presentation (Esc)","aria-label":"Exit presentation",children:"Exit presentation"},void 0,!1,void 0,this),i("div",{class:"html-presentation-stage",children:i(Si,{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 gw=168,vw=112,dc=20;function hw(e,t,n,o){let r=Array.from(e.values()),s=0,a=0,c=1000,l=800;if(r.length>0){s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let x of r)s=Math.min(s,x.position.x),a=Math.min(a,x.position.y),c=Math.max(c,x.position.x+x.size.width),l=Math.max(l,x.position.y+x.size.height)}let u=-t.x/t.scale,d=-t.y/t.scale,p=u+n/t.scale,f=d+o/t.scale,m={minX:Math.min(s,u)-dc,minY:Math.min(a,d)-dc,maxX:Math.max(c,p)+dc,maxY:Math.max(l,f)+dc},v=m.maxX-m.minX||1,y=m.maxY-m.minY||1;return{bounds:m,scale:Math.min(gw/v,vw/y)}}function yw({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:r}){let s=M(null),a=M(!1),c=t.value,l=e.value,u=hw(c,l,o,r),{bounds:d,scale:p}=u,f=(_)=>(_-d.minX)*p,m=(_)=>(_-d.minY)*p,v=L((_)=>{let R=s.current;if(!R)return;let A=R.getBoundingClientRect(),C=(_.clientX-A.left)/A.width*gw,Z=(_.clientY-A.top)/A.height*vw,F=hw(t.value,e.value,o,r),T=e.value,B=o/T.scale,W=r/T.scale,H=C/F.scale+F.bounds.minX,U=Z/F.scale+F.bounds.minY;n(-(H-B/2)*T.scale,-(U-W/2)*T.scale)},[t,e,o,r,n]),y=L((_)=>{_.stopPropagation(),_.preventDefault(),a.current=!0,v(_);let R=(C)=>{if(a.current)v(C)},A=()=>{a.current=!1,document.removeEventListener("pointermove",R),document.removeEventListener("pointerup",A)};document.addEventListener("pointermove",R),document.addEventListener("pointerup",A)},[v]),x=ye.value,h=Xn.value,g=h?ec(h.nodeIds.map((_)=>c.get(_)).filter((_)=>_!==void 0),h.padding):null,b=mt.value.map((_)=>({id:_.sessionId,phase:_.phase,worker:_.parentAgentId!=null,external:!_.attached,at:Qa(_,(R)=>c.get(R))})).filter((_)=>_.at!==null),E=-l.x/l.scale,j=-l.y/l.scale;return i("div",{ref:s,class:"minimap","data-testid":"minimap",title:"Click to jump · drag the frame to pan",onPointerDown:y,children:[Array.from(c.values()).map((_)=>{let R=_.type==="group";return i("span",{class:`minimap-node${R?" is-group":""}${x.has(_.id)?" is-selected":""}`,"data-kind":_.type,style:{left:`${f(_.position.x)}px`,top:`${m(_.position.y)}px`,width:`${Math.max(R?6:4,_.size.width*p)}px`,height:`${Math.max(R?5:3,_.size.height*p)}px`,"--kind":oc[_.type]}},_.id,!1,void 0,this)}),g&&i("span",{class:"minimap-fence",style:{left:`${f(g.x)}px`,top:`${m(g.y)}px`,width:`${g.width*p}px`,height:`${g.height*p}px`}},void 0,!1,void 0,this),b.map((_)=>i("span",{class:`minimap-presence phase-${_.phase}${_.worker?" is-worker":""}${_.external?" is-external":""}`,style:{left:`${f(_.at.x)-4}px`,top:`${m(_.at.y)-4}px`,"--identity-color":`hsl(${Vn(_.id)} 65% 62%)`}},_.id,!1,void 0,this)),i("span",{class:"minimap-frame",style:{left:`${f(E)}px`,top:`${m(j)}px`,width:`${o/l.scale*p}px`,height:`${r/l.scale*p}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 Ge({label:e,shortcut:t,body:n,align:o="center",side:r="down",tapToOpen:s=!1,children:a}){return i("span",{class:`toolbar-tooltip-anchor toolbar-tooltip-anchor-${o}${r==="up"?" toolbar-tooltip-anchor-up":""}${s?" toolbar-tooltip-anchor-tap":""}`,tabIndex:s?-1:void 0,children:[a,i("span",{class:"toolbar-tooltip",role:"tooltip",children:[i("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),n&&i("span",{class:"toolbar-tooltip-body",children:n},void 0,!1,void 0,this),t&&i("span",{class:"toolbar-tooltip-meta",children:i("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function xw(){let e=ye.value.size,t=L(()=>{let c=Array.from(ye.value);if(c.length===0)return;Ns(c),gt()},[]),n=L(()=>{let c=Array.from(ye.value);if(c.length===0)return;Uo({title:"Group",childIds:c}),gt()},[]),o=L(()=>{let c=Array.from(ye.value);for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++)ho(c[l],c[u],"relation");gt()},[]),r=L(()=>{let c=Array.from(ye.value);for(let l of c)zt(l),$n(l);gt()},[]);if(e===0)return null;let s=e>=2,a=!ft.value&&Ae.value.size>0&&!nn.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(ve,{children:[i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Ge,{label:"Align left",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align left",onClick:()=>Hl("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(Ge,{label:"Align top",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align top",onClick:()=>Hl("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(Ge,{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:()=>av(),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(Ge,{label:"Auto-arrange selection",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Auto-arrange",onClick:()=>cv(),children:i(Ao,{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(Ge,{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(Ge,{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(Ge,{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(Ge,{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(Ge,{label:"Clear selection",shortcut:"Esc",side:"up",children:i("button",{type:"button",class:"selection-bar-icon",onClick:gt,"aria-label":"Clear selection",children:"×"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function pc(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 mc(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 KA={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},JA={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},bw=[{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"}],ww=Object.fromEntries(bw.map((e)=>[e.id,e.hint])),YA={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 Bd(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 QA({item:e}){let t=KA[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&&tt(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:JA[e.status]??t},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:Bd(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function eI({gate:e,now:t}){let[n,o]=O(null),r=async(c)=>{o(c),await xb(e,c),o(null)},s=e.nodeIds[0],a=pc(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&&tt(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 ",mc(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:Bd(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function tI({gate:e}){let[t,n]=O(!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),bb(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 nI(){let e=Xn.value,t=ye.value.size,[n,o]=O(!1),r=(s)=>{o(!0),fb(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(ve,{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(ve,{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([...ye.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 oI(e){if(e==="browser")return"you";return mt.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function rI({entry:e}){let t=Ci.value.has(e.id);return i("li",{class:`session-timeline-row tone-${YA[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:ww[Id(e.kind)],children:e.label},void 0,!1,void 0,this),e.who&&i("span",{class:"session-timeline-who",style:{"--identity-color":`hsl(${Vn(e.who)} 65% 62%)`},children:oI(e.who)},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:Bd(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 zd(e),children:"↩ undo this edit"},void 0,!1,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 _w(){let[e,t]=O(!1),n=Tr.value,o=pb.value,r=zo.value,s=hb.value,a=yb.value,[c,l]=O(!1),[u,d]=O(null),p=_n();if(D(()=>{Kn()},[]),!(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:qn(n),"aria-label":`Session live: ${qn(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:qn(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 tc(n),children:"End"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-collapse",onClick:()=>t(!1),title:"Collapse session panel",children:"›"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(nI,{},void 0,!1,void 0,this),(()=>{let m=a.find((v)=>v.undoable&&!Ci.value.has(v.id));if(!m)return null;return i("div",{class:"session-undo-row","data-testid":"session-undo-row",children:[i("span",{class:"session-undo-text",title:m.body,children:["Agent edit on top: ",m.body]},void 0,!0,void 0,this),i("button",{type:"button",class:"session-undo-btn",onClick:()=>void zd(m),children:"↩ Undo"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})(),i("div",{class:"session-panel-body",children:[i("section",{class:"session-section",children:(()=>{let m=o.filter((E)=>E.status==="in-progress"||E.status==="todo").length,v=o.filter((E)=>E.status!=="cancelled"),y=v.filter((E)=>E.status==="done").length,x=o.length-v.length,h=r.length>0,g=c||h,b=m>0?`${m} running`:v.length>0?`${y}/${v.length} done${x>0?` · ${x} cancelled`:""}`:o.length>0?`${o.length} cancelled`:"none yet";return i(ve,{children:[i("button",{type:"button",class:"session-section-toggle","aria-expanded":g,"data-testid":"work-items-toggle",onClick:()=>l((E)=>!E),children:[i("span",{class:"session-section-title",children:"Work items"},void 0,!1,void 0,this),i("span",{class:"session-work-summary",children:[m>0&&i("span",{class:"session-work-dot","aria-hidden":"true"},void 0,!1,void 0,this),b]},void 0,!0,void 0,this),i("span",{class:`session-section-chevron${g?" is-open":""}`,"aria-hidden":"true",children:"›"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g&&(r.length===0&&s.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((E)=>i(eI,{gate:E,now:p},E.id,!1,void 0,this)),s.map((E)=>i(tI,{gate:E},E.id,!1,void 0,this)),o.map((E)=>i(QA,{item:E},E.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:bw.map((m)=>i("button",{type:"button",class:`activity-filter${Po.value===m.id?" is-active":""}`,"aria-pressed":Po.value===m.id,title:m.hint,onMouseEnter:()=>d(m.id),onMouseLeave:()=>d((v)=>v===m.id?null:v),onFocus:()=>d(m.id),onBlur:()=>d((v)=>v===m.id?null:v),onClick:()=>{Po.value=m.id},children:m.label},m.id,!1,void 0,this))},void 0,!1,void 0,this),i("div",{class:"session-timeline-hint","data-testid":"timeline-filter-hint",children:ww[u??Po.value]},void 0,!1,void 0,this),a.length===0?i("div",{class:"session-empty",children:Po.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:a.map((m)=>i(rI,{entry:m},m.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 Ud(e){if(!e||typeof e!=="object")return null;let t=e,n=(o)=>Array.isArray(o)?o.length:0;return{added:n(t.addedNodes)+n(t.addedEdges),removed:n(t.removedNodes)+n(t.removedEdges),modified:n(t.modifiedNodes)}}function Sw({onOpenSnapshots:e}){let t=nc.value,[n,o]=O(null),[r,s]=O(!1);if(!t)return null;let a=async()=>{if(!t.snapshot)return;s(!0);try{let u=await fetch(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(u.ok){let d=await u.json();o(Ud(d.diff)??{added:0,removed:0,modified:0})}}finally{s(!1)}},c=new Date(t.endedAt),l=Number.isNaN(c.getTime())?"":`${String(c.getHours()).padStart(2,"0")}:${String(c.getMinutes()).padStart(2,"0")}`;return i("div",{class:"session-receipt","data-testid":"session-receipt",role:"status",children:[i("div",{class:"session-receipt-head",children:[i("span",{class:"session-receipt-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"session-receipt-title",children:[t.endedBy==="human"?"Session ended by you":t.endedBy==="idle-timeout"?"Session ended — idle timeout":t.endedBy==="agent"?"Session ended by the agent":"Session ended",l?` · ${l}`:""]},void 0,!0,void 0,this),i("button",{type:"button",class:"session-receipt-close",onClick:Sb,"aria-label":"Dismiss receipt",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-tiles",children:[i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Items"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value",children:t.counts.items},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Done"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-ok",children:t.counts.done},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.cancelled>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Cancelled"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-muted",children:t.counts.cancelled},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.rejected>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Rejected"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-danger",children:t.counts.rejected},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.held>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Held"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-warn",children:t.counts.held},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-note",children:t.snapshot?"A snapshot of the board from before this session is saved — restore it to undo the session.":t.unchanged?"This session changed nothing on the board — no snapshot kept.":"The board was empty when the session started — nothing to restore."},void 0,!1,void 0,this),n&&i("div",{class:"session-receipt-diff","data-testid":"session-receipt-diff",children:["This session: ",n.added," added · ",n.removed," removed · ",n.modified," modified"]},void 0,!0,void 0,this),i("div",{class:"session-receipt-actions",children:[t.snapshot&&i("button",{type:"button",class:"session-receipt-primary",disabled:r,onClick:()=>void a(),children:r?"Comparing…":"View diff"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-receipt-secondary",title:"Open the History drawer — saved boards and past sessions",onClick:e,children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var iI=[{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:He("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:He("0"),desc:"Reset viewport to origin"},{keys:`${He("+")} / ${He("−")}`,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:ri?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:ri?"⌘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 kw({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:iI.map((t)=>i("div",{class:"shortcut-group",children:[i("div",{class:"shortcut-group-title",children:t.title},void 0,!1,void 0,this),t.shortcuts.map((n)=>i("div",{class:"shortcut-row",children:[i("kbd",{class:"shortcut-keys",children:n.keys},void 0,!1,void 0,this),i("span",{class:"shortcut-desc",children:n.desc},void 0,!1,void 0,this)]},n.keys,!0,void 0,this))]},t.title,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var Cw="Before session · ";function Tw(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 sI(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 fc(e){if(!e.startsWith(Cw))return null;let t=e.slice(Cw.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function Ew({open:e,onClose:t,anchorRef:n}){let[o,r]=O([]),[s,a]=O(!1),[c,l]=O(!1),[u,d]=O(null),[p,f]=O(""),[m,v]=O(null),[y,x]=O({}),h=M(null),g=M(null);D(()=>{if(!e)return;a(!0),Wg().then((A)=>{r(A),a(!1)})},[e]),D(()=>{if(e)setTimeout(()=>g.current?.focus(),50)},[e]),D(()=>{if(!e)return;let A=(C)=>{let Z=h.current,F=n.current;if(Z&&!Z.contains(C.target)&&F&&!F.contains(C.target))t()};return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[e,t]),D(()=>{if(!e)return;let A=(C)=>{if(C.key==="Escape")t()};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[e,t]);let b=L(async()=>{let A=p.trim();if(!A)return;l(!0);let C=await qg(A);if(l(!1),C.ok&&C.snapshot)r((Z)=>[C.snapshot,...Z]),f("")},[p]),E=L(async(A)=>{v(null),d(A);let C=await Vg(A);if(d(null),C.ok)t()},[t]),j=L(async(A)=>{if((await Gg(A)).ok)r((Z)=>Z.filter((F)=>F.id!==A));v(null)},[]),_=L(async(A)=>{x((Z)=>({...Z,[A]:"loading"}));let C=await de("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(A)}/diff`,{});x((Z)=>({...Z,[A]:Ud(C.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let R=(A,C)=>m?.id===A.id?i(ve,{children:[i("button",{type:"button",class:`snapshot-action-btn ${m.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>m.action==="delete"?j(A.id):E(A.id),title:m.action==="delete"?"Confirm delete":"Confirm restore",disabled:u!==null,children:m.action==="delete"?"Delete":u===A.id?"Restoring…":"Confirm"},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn",onClick:()=>v(null),title:"Cancel",disabled:u!==null,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i(ve,{children:[i("button",{type:"button",class:"snapshot-action-btn snapshot-action-restore",onClick:()=>v({id:A.id,action:"restore"}),title:"Restore this snapshot — replaces the current canvas (undoable)",disabled:u!==null,children:u===A.id?"Restoring…":C},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn snapshot-action-delete",onClick:()=>v({id:A.id,action:"delete"}),title:"Delete this snapshot","aria-label":"Delete snapshot",disabled:u!==null,children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return i("div",{ref:h,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:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-save-form",children:[i("input",{ref:g,type:"text",class:"snapshot-name-input",value:p,onInput:(A)=>f(A.target.value),onKeyDown:(A)=>{if(A.key==="Enter")b()},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:b,disabled:!p.trim()||c,children:c?"…":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-restore-note",children:"Restoring replaces the current canvas. You can undo it if needed."},void 0,!1,void 0,this),i("div",{class:"snapshot-list",children:[s&&i("div",{class:"snapshot-empty",children:"Loading…"},void 0,!1,void 0,this),!s&&o.length===0&&i("div",{class:"snapshot-empty",children:"No history yet. Save a snapshot, or start an agent session — it snapshots for you."},void 0,!1,void 0,this),!s&&[...o.filter((A)=>fc(A.name)===null),...o.some((A)=>fc(A.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((A)=>fc(A.name)!==null)].map((A)=>{if(A.id==="__sessions-header__")return i("div",{class:"snapshot-section-header","data-testid":"history-sessions-header",children:"Sessions"},A.id,!1,void 0,this);let C=fc(A.name),Z=y[A.id];if(C!==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 — ",C]},void 0,!0,void 0,this),i("span",{class:"snapshot-item-time",children:Tw(A.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:["snapshot at session start · ",A.nodeCount," node",A.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 _(A.id),children:Z==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),R(A,"Restore pre-state")]},void 0,!0,void 0,this)]},A.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:A.name},void 0,!1,void 0,this),i("span",{class:"snapshot-item-time",children:Tw(A.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:[A.nodeCount," node",A.nodeCount!==1?"s":"",A.edgeCount>0?` · ${A.edgeCount} edge${A.edgeCount!==1?"s":""}`:""," · ",sI(A.createdAt)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-actions",children:R(A,"Restore")},void 0,!1,void 0,this)]},A.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 Aw=3,Iw={"waiting-approval":0,thinking:1,tooling:2,idle:3};function aI(){let e=cb.value;if(e.length===0)return null;let t=e.filter((c)=>!c.parentAgentId||!e.some((l)=>l.sessionId!==c.sessionId&&(l.sessionId===c.parentAgentId||l.source===c.parentAgentId))),n=[...t].sort((c,l)=>(Iw[c.phase]??4)-(Iw[l.phase]??4)),o=n.slice(0,Aw),r=n.slice(Aw),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(ve,{children:[i("span",{class:"agent-chips",children:o.map((c)=>{let l=mt.value.filter((u)=>u.parentAgentId!=null&&(u.parentAgentId===c.sessionId||u.parentAgentId===c.source)).length;return i(Ge,{label:`Agent session — ${c.label}`,tapToOpen:!0,body:"What this attached agent is doing right now: idle, thinking, running a tool, or waiting on your approval. Steer it from the composer below.",children:i("span",{class:`agent-chip phase-${c.phase}`,"data-phase":c.phase,style:{"--identity-color":`hsl(${Vn(c.sessionId)} 65% 62%)`},children:[i("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"agent-chip-label",children:qn(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(),tc({source:c.source,agentId:c.agentId})},children:"×"},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(Ge,{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 cI(){let e=zo.value.length,t=Tr.value!==null&&e>0,n=_n(t?1000:0);if(!t)return null;let o=zo.value.map((r)=>pc(r,n)).filter((r)=>r!==null).sort((r,s)=>r-s)[0];return i(Ge,{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&&` · ${mc(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function lI(e){if(e>0.9)return"danger";if(e>=0.7)return"warn";return"ok"}function Ai(e){return e>=1000?`${(e/1000).toFixed(e>=1e4?0:1)}k`:String(e)}function uI(){let e=Tr.value;if(!e)return null;let t=Sd.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:`${Ai(n.used)} of ${Ai(n.total)} tokens of the agent's actual context window are used. Your ✦-pinned nodes account for ≈ ${Ai(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: ≈ ${Ai(t.used)} of a ${Ai(t.total)}-token budget. When the agent's host reports its real context window, this meter switches to showing that instead.`};return i(Ge,{label:c.label,body:c.body,tapToOpen:!0,children:i("span",{class:`context-budget tone-${lI(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 dI(){let[e,t]=O(!1);if(Tr.value)return null;return i(Ge,{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),Jn().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 zw(){let e=It.value,t=St.value,n=ee.value,o=N.value.size,r=$e.value.size,s=Go.value,a=Array.from(N.value.values()).filter((m)=>m.type==="trace").length,[c,l]=O("");D(()=>{let m=!1;return fetch("/health").then((v)=>v.ok?v.json():null).then((v)=>{if(m||typeof v?.workspace!=="string"||!v.workspace)return;let y=v.workspace.replace(/[\\/]+$/,"").split(/[\\/]/).pop();if(y)l(y)}).catch(()=>{}),()=>{m=!0}},[]);let u=Od.value,d=u??(e==="connected"&&!t?"syncing":e),p=t?[`${o} node${o!==1?"s":""}`,...r>0?[`${r} edge${r!==1?"s":""}`]:[],...a>0?[`${a} trace${a!==1?"s":""}`]:s?["trace armed"]:[]].join(" · "):"Syncing canvas…",f=()=>{let m=st();Yo(m.width,m.height)};return i("div",{class:"top-bar",children:[i(Ge,{label:`Canvas status: ${d}`,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: ${d}`},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"top-bar-title",title:c||"PMX Canvas",children:c||"PMX Canvas"},void 0,!1,void 0,this),i("span",{class:"top-bar-meta hud-collapsible-text",children:mn.value?mn.value.slice(0,12):"…"},void 0,!1,void 0,this),i("span",{class:"top-bar-meta hud-collapsible-text",children:p},void 0,!1,void 0,this),i("span",{class:"top-bar-spacer"},void 0,!1,void 0,this),i(aI,{},void 0,!1,void 0,this),i(cI,{},void 0,!1,void 0,this),i(uI,{},void 0,!1,void 0,this),i(cw,{},void 0,!1,void 0,this),i(dI,{},void 0,!1,void 0,this),i("div",{class:"top-bar-sep"},void 0,!1,void 0,this),i(Ge,{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:()=>{tn.value=!0},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Ge,{label:"Zoom out",shortcut:He("−"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>Jo(0.8),"aria-label":"Zoom out",children:i(jx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Ge,{label:"Reset zoom",shortcut:He("0"),children:i("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>Dn({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(Ge,{label:"Zoom in",shortcut:He("+"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>Jo(1.25),"aria-label":"Zoom in",children:i(Fx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Ge,{label:"Fit all",shortcut:"F",align:"end",children:i("button",{type:"button",class:"top-bar-btn",onClick:f,"aria-label":"Fit canvas",children:i(Va,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Qn={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},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 Ii(e,t,n,o={}){let r=Qn[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 $o=null,vc=null,hc=0,eo=null,pI=3000,mI=2000,Pw=5000,zi=!1,kn=null,Pr=null,no=0,to=null;function fI(){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 Nr=new Map;function Pi(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 yc(e){if(!vc)return e;let t=vc.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 Ni(e,t,n){return yc(Ii(e,t,n))}function hI(){return ya([...N.value.values()],Qn.markdown.w,Qn.markdown.h)}function Rr(){if(!N.value.has("status-main"))fn(Ni("status-main","status",{phase:"idle",message:"",elapsed:0}))}function gI(e,t){let n=`md-${Pi(e)}`;if(N.value.get(n))ie(n,{path:e,title:t}),Ce.value=n;else{let r=hI(),s=Ni(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=r,fn(s),tt(n)}}function vI(e){if(N.value.get("context-main"))ie("context-main",{cards:e});else if(e.length>0){let o=Ni("context-main","context",{cards:e});fn(o)}}function yI(e){let t=e.url,n=`mcp-${Pi(t)}`;if(N.value.get(n))ie(n,e);else fn(Ni(n,"mcp-app",e)),tt(n)}function xI(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(N.value.get(o)){ie(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[x,h]of N.value.entries())if(h.type==="mcp-app"&&h.data.mode==="ext-app"&&h.data.serverName===s&&h.data.toolName===a&&!h.data.toolResult){ie(x,{...e});return}}let{_x:c,_y:l,_width:u,_height:d}=e,p=Qn["mcp-app"],f=u??p.w,m=d??p.h,v=c===void 0||l===void 0?ya([...N.value.values()],f,m):null,y=yc(Ii(o,"mcp-app",{mode:"ext-app",...e},{position:{x:c??v?.x??p.x,y:l??v?.y??p.y},size:{width:f,height:m}}));fn(y),tt(o,{recordHistory:!1})}function bI(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(N.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&N.value.has(n))return n;for(let[o,r]of N.value.entries())if(r.type==="mcp-app"&&r.data.mode==="ext-app"&&r.data.toolCallId===e)return o;return null}function Ow(e){let t=typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null;if(t&&N.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return bI(e.toolCallId)}function Lw(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,r]of N.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 Dw(e){if(N.value.get("ledger-main"))ie("ledger-main",e);else{let o=Ni("ledger-main","ledger",e);o.collapsed=!0,fn(o)}}function Wd(e){if(!di(e))return;if(document.documentElement.setAttribute("data-theme",e),wr(),Je.value!==e)Je.value=e}function wI(e){return e==="markdown"||e==="mcp-app"||e==="webpage"||e==="json-render"||e==="graph"||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 _I(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function qd(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 Fw(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 SI(e){let t=qd(e),n=Fw(e);return t&&n?{...t,...n}:null}function kI(e){if(typeof e.id!=="string"||!e.id)return null;if(!wI(e.type))return null;let t=qd(e.position),n=Fw(e.size);if(!t||!n)return null;let o=e.data&&typeof e.data==="object"?Object.fromEntries(Object.entries(e.data)):{};return{id:e.id,type:e.type,position:t,size:n,zIndex:typeof e.zIndex==="number"?e.zIndex:1,collapsed:e.collapsed===!0,pinned:e.pinned===!0,data:o}}function CI(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(!_I(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 TI(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)=>qd(o)).filter((o)=>o!==null),n=SI(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 Nw="pmx-canvas-version-reload";function EI(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(Nw)===r)return;window.sessionStorage.setItem(Nw,r)}catch{return}window.location.reload()}function AI(e){let t=Gn.value[0]?.id;if(Td(e),ft.value&&Gn.value[0]?.id!==t)Kn()}function II(e){_b(e)}var Rw=null;function zI(e){Tu(e)}function PI(e){if(mn.value=e.sessionId||"",It.value="connected",go.value+=1,EI(e.version,e.bundleStamp),Kr(),Zg().then(Td),Rw?.(),!ws)Rw=Fy();if(de("fetchHumanPresence","/api/canvas/human-presence",null).then(Tu),Ml().then((t)=>{if(qt.value=t,ft.value)Kn()}),typeof e.theme==="string"&&!Ld())Wd(e.theme);if(e.ledgerSummary)Dw(e.ledgerSummary)}function NI(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(gI(t,n),e.ledgerSummary)Dw(e.ledgerSummary)}function RI(e){Rr(),ie("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function $I(e){Rr(),ie("status-main",{phase:e.phase,detail:e.detail})}function MI(e){let t=e.cards??[];vI(t)}function OI(e){if(typeof e.url==="string"&&e.url)yI({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function LI(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let r=`mcp-${Pi(o)}`;if(N.value.has(r))ie(r,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function DI(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${Pi(e.url)}`;if(N.value.has(t))ie(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function FI(e){let n=N.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);ie("context-main",{auxTabs:o})}function jI(e){if(N.value.has("context-main"))if(e.mode==="all")ie("context-main",{auxTabs:[]});else{let o=N.value.get("context-main");if(!o)return;let r=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);ie("context-main",{auxTabs:r})}}function ZI(e){Rr(),ie("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function HI(e){Rr(),ie("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function BI(e){Rr(),ie("status-main",{activeTool:null})}function UI(e){if(e.state==="active"&&e.path){let n=`md-${Pi(e.path)}`;if(N.value.has(n))ie(n,{reviewActive:!0})}}function WI(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;xI({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 qI(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=Ow(e)??Lw(e.serverName,e.toolName);if(!t)return;if(N.value.has(t))ie(t,{html:e.html})}function VI(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=Ow(e)??Lw(e.serverName,e.toolName);if(!t)return;if(N.value.has(t)){if(e.success===!1){zt(t);return}ie(t,{toolResult:ad({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 GI(e){Rr(),ie("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function XI(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:r,contextNodeIds:s}=e;if(e.threadNodeId&&N.value.has(e.threadNodeId)){let a=e.threadNodeId,c=N.value.get(a);if(!c)return;let l=Array.isArray(c.data.turns)?[...c.data.turns]:[],u=l[l.length-1];if(!u||u.role!=="user"||u.text!==n)l.push({role:"user",text:n,status:"pending"});ie(a,{turns:l,threadStatus:"pending"});return}if(!N.value.has(t)){let a=o??Qn.prompt;fn(yc(Ii(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}}))),tt(t)}if(r&&N.value.has(r))Ms({id:`edge-${r}-${t}`,from:r,to:t,type:"flow",style:"dashed"})}function KI(e){let{nodeId:t,status:n}=e;if(t&&N.value.has(t))ie(t,{status:n})}function JI(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?N.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){Nr.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),ie(n,{turns:s,threadStatus:"streaming",_activeResponseId:t}),tt(n);return}let r=o?{x:o.position.x,y:o.position.y+o.size.height+24}:{x:Qn.response.x,y:Qn.response.y};if(!N.value.has(t))fn(yc(Ii(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:r})));if(n)Ms({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});tt(t)}function YI(e){let t=e.responseNodeId;if(!t)return;let n=Nr.get(t);if(n){let o=N.value.get(n);if(o&&Array.isArray(o.data.turns)){let r=[...o.data.turns],s=r[r.length-1];if(s&&s.role==="assistant")s.text=e.content,s.status="streaming";ie(n,{turns:r,threadStatus:"streaming"})}return}if(!N.value.has(t))return;ie(t,{content:e.content,status:"streaming"})}function QI(e){let t=e.responseNodeId;if(!t)return;let n=Nr.get(t);if(n){let s=N.value.get(n);if(s&&Array.isArray(s.data.turns)){let a=[...s.data.turns],c=a[a.length-1];if(c&&c.role==="assistant")c.text=e.content,c.status="complete";ie(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}Nr.delete(t);return}if(!N.value.has(t))return;ie(t,{content:e.content,status:"complete"});let r=N.value.get(t)?.data.promptNodeId;if(r){let s=`edge-${r}-${t}`,a=$e.value.get(s);if(a)dv(s),Ms({...a,animated:!1})}}function ez(e){let t=e.layout;if(!t?.nodes)return;let n=!St.value;St.value=!0;let o=t.nodes.map(kI).filter((c)=>c!==null),r=Array.isArray(t.edges)?t.edges.map(CI).filter((c)=>c!==null):Array.from($e.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(TI).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)gn();vv({...a?{viewport:a}:{},nodes:o,edges:r,...s?{annotations:s}:{}},{applyViewport:n}),eu({event:"canvas-layout-update",data:e})}function tz(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function nz(e){if(ql())return;let t=e.nodeId;if(t&&N.value.has(t)){if(e.noPan===!0){hn(t);return}tt(t)}}function oz(e){if(ql())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;gn(),fv({x:n,y:o,scale:r})}function rz(e){if(N.value.get("context-main"))ie("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function iz(e){Go.value=e.enabled===!0}function sz(e){if(typeof e.theme==="string"&&!Ld())Wd(e.theme)}function az(e){let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];uv(t),eu({event:"context-pins-changed",data:e})}var gc=null;function $w(){if(gc)clearTimeout(gc);gc=setTimeout(()=>{if(gc=null,Ml().then((e)=>{qt.value=e}),ft.value)Kn()},150)}function cz(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;Py(t)}function lz(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)Ry(t,typeof e.nodeId==="string"?e.nodeId:void 0);else ku(t)}var jw={connected:PI,"workbench-open":NI,"canvas-status":RI,"execution-phase":$I,"context-cards":MI,"mcp-app-candidate":OI,"mcp-app-host-snapshot":LI,"mcp-app-host-fallback":DI,"aux-open":FI,"aux-close":jI,"assistant-complete":ZI,"tool-start":HI,"tool-complete":BI,"review-state":UI,"subagent-status":GI,"ext-app-open":WI,"ext-app-update":qI,"ext-app-result":VI,"context-pins-changed":az,"canvas-layout-update":ez,"canvas-focus-node":nz,"canvas-viewport-update":oz,"context-usage":rz,"trace-state":iz,"theme-changed":sz,"canvas-prompt-created":XI,"canvas-prompt-status":KI,"canvas-response-start":JI,"canvas-response-delta":YI,"canvas-response-complete":QI,"ax-state-changed":$w,"ax-event-created":$w,"ax-intent":cz,"ax-intent-clear":lz,"agent-presence":AI,"human-presence":zI,"agent-session-ended":II};function Zw(e,t){let n=jw[e];if(!n)return;let o=n;try{o(t)}catch(r){console.warn(`[sse-bridge] Handler for "${e}" failed:`,r)}}function Mw(){zi=!0,no+=1;let e=no;It.value="connecting";let t=null,n=!1,o=async()=>{if(e!==no)return;try{let r=new URLSearchParams;if(Pr!==null)r.set("since",String(Pr));let s=mn.value;if(s)r.set("session",s);let a=r.toString(),c=await fetch(`/api/workbench/poll${a?`?${a}`:""}`);if(e!==no)return;if(!c.ok)throw Error(`poll failed with HTTP ${c.status}`);let l=await c.json();if(e!==no)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){Pr=null,kn=setTimeout(()=>void o(),0);return}if(l.snapshot&&n)vc=Wl(),St.value=!1,Ql(),Cu(),Nr.clear();for(let d of l.events)Zw(d.event,d.payload);n=!0,Pr=l.seq,vo.value=0,yo.value=0,It.value="connected",kn=setTimeout(()=>void o(),mI)}catch(r){if(e!==no)return;console.warn("[sse-bridge] poll transport error:",r),It.value="disconnected",vo.value+=1,yo.value=Pw,kn=setTimeout(()=>void o(),Pw)}};return o(),()=>{if(no+=1,zi=!1,Pr=null,kn)clearTimeout(kn),kn=null}}function Vd(){if(Qb(Wd),vc=Wl(),St.value=!1,Ql(),Cu(),Nr.clear(),eo)clearTimeout(eo),eo=null;let e=fI();if(e==="poll"||zi)return Mw();let t=mn.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";It.value="connecting";let o=new EventSource(n);$o=o;let r=!1;if(to)clearTimeout(to);if(to=null,e!=="sse")to=setTimeout(()=>{if(to=null,r||$o!==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(),$o=null,Mw()},pI);for(let[s]of Object.entries(jw))o.addEventListener(s,(a)=>{r=!0;try{Zw(s,JSON.parse(a.data))}catch(c){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,c)}});return o.onopen=()=>{if($o!==o)return;hc=0,vo.value=0,yo.value=0,It.value="connected"},o.onerror=()=>{if($o!==o)return;It.value="disconnected",o.close(),$o=null,hc+=1;let s=tz(hc);vo.value=hc,yo.value=s,eo=setTimeout(()=>{eo=null,Vd()},s)},()=>{if(eo)clearTimeout(eo),eo=null;if(to)clearTimeout(to),to=null;if(zi){if(no+=1,zi=!1,Pr=null,kn)clearTimeout(kn),kn=null}o.close(),$o=null}}function Mo(e,t){console.error(`[app] ${e} failed`,t)}function Hw(){let[e,t]=O(!0),[n,o]=O(!1),[r,s]=O(!1),[a,c]=O(!1),[l,u]=O(null),d=M(null),{menu:p,openNodeMenu:f,openCanvasMenu:m,openEdgeMenu:v,closeMenu:y}=tw(),x=St.value,h=ft.value,g=L(()=>t((C)=>!C),[]),b=L(()=>o((C)=>!C),[]),E=L(()=>o(!1),[]),j=L((C)=>u(C),[]),_=L((C,Z)=>{Dn({x:C,y:Z,scale:ee.value.scale},200)},[]);D(()=>Vd(),[]),D(()=>{let C=null,Z=()=>{if(C!==null)window.clearTimeout(C);C=window.setTimeout(()=>{C=null,Kr()},400)};return window.addEventListener("resize",Z),()=>{if(C!==null)window.clearTimeout(C);window.removeEventListener("resize",Z)}},[]),D(()=>{let C=(T)=>{let B=(T.metaKey||T.ctrlKey)&&!T.altKey;if(B&&T.key==="k"){T.preventDefault(),s((U)=>!U);return}if(T.key==="Escape"&&l){T.preventDefault(),u(null);return}if(T.key==="Escape"&&Ue.value&&!Qt.value){T.preventDefault(),xo();return}if(T.key==="Escape"&&r){T.preventDefault(),s(!1);return}if(T.key==="Escape"&&a){T.preventDefault(),c(!1);return}let W=T.target,H=W?.tagName;if(H==="INPUT"||H==="TEXTAREA"||W?.isContentEditable)return;if(T.key===" "&&!T.repeat&&!B){T.preventDefault(),Yr.value=!0;return}if(T.key==="?"||T.key==="/"&&T.shiftKey){T.preventDefault(),c((U)=>!U);return}if(B&&(T.key==="z"||T.key==="Z"))T.preventDefault(),Pd(T.shiftKey);else if(B&&(T.key==="y"||T.key==="Y"))T.preventDefault(),Pd(!0);else if(B&&T.key==="0")T.preventDefault(),Dn({x:0,y:0,scale:1},250);else if(B&&(T.key==="="||T.key==="+"))T.preventDefault(),Jo(1.25);else if(B&&T.key==="-")T.preventDefault(),Jo(0.8);else if(T.key==="Escape"){if(ye.value.size>0||pn.value!==null){gt();return}Ce.value=null,y()}else if(T.key==="Tab")T.preventDefault(),xv(T.shiftKey?-1:1);else if(T.key==="Delete"||T.key==="Backspace"){if(pn.value!==null){let te=pn.value;T.preventDefault(),pn.value=null,Is(te).catch((xe)=>Mo("delete-edge",xe));return}let U=ye.value.size>0?[...ye.value]:Ce.value?[Ce.value]:[];if(U.length===0)return;T.preventDefault();for(let te of U)zt(te),$n(te).catch((xe)=>Mo("delete",xe));gt(),Ce.value=null}else if(Ce.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(T.key)){T.preventDefault();let U=T.key.replace("Arrow","").toLowerCase();bv(U)}else if(!B&&!T.altKey){let U=T.key.toLowerCase();if(U==="v"&&!T.shiftKey)_t.value="select";else if(U==="c"&&!T.shiftKey&&!B)T.preventDefault(),_t.value=_t.value==="connect"?"select":"connect";else if(U==="m"&&!T.shiftKey)T.preventDefault(),Nt({type:"markdown",title:"New note",width:520,height:360}).catch((te)=>Mo("create markdown",te));else if(U==="a"&&!T.shiftKey)T.preventDefault(),u((te)=>te==="pen"?null:"pen");else if(U==="g"&&!T.shiftKey){T.preventDefault();let te=Array.from(ye.value);if(te.length>=2)Uo({title:"Group",childIds:te}).catch((xe)=>Mo("group selection",xe)),gt();else Nt({type:"group",title:"Group"}).catch((xe)=>Mo("create group",xe))}else if(U==="g"&&T.shiftKey){T.preventDefault();for(let te of sv())zt(te),Wo(te).catch((xe)=>Mo("ungroup",xe));gt()}else if(U==="i"&&!T.shiftKey)T.preventDefault(),Sn("image");else if(U==="w"&&!T.shiftKey)T.preventDefault(),Sn("webpage");else if(U==="h"&&!T.shiftKey)T.preventDefault(),Nt({type:"html",title:"HTML surface"}).catch((te)=>Mo("create html",te));else if(U==="f"&&T.shiftKey)T.preventDefault(),Sn("file");else if(U==="f"&&!T.shiftKey){T.preventDefault();let te=st();Yo(te.width,te.height)}}},Z=(T)=>{if(T.key===" ")Yr.value=!1},F=()=>{Yr.value=!1};return document.addEventListener("keydown",C),document.addEventListener("keyup",Z),window.addEventListener("blur",F),()=>{document.removeEventListener("keydown",C),document.removeEventListener("keyup",Z),window.removeEventListener("blur",F)}},[l,y,r,a]),D(()=>{let C=window.setTimeout(()=>void Kr(),250);return()=>window.clearTimeout(C)},[h]),D(()=>{if(!x)return;let C=window.__pmxCanvasBootstrapReady;if(typeof C==="function")C()},[x]);let R=Array.from(N.value.values()),A=st();return i("div",{class:`app-shell${tn.value?" is-presenting":""}`,"data-session-active":h?"true":"false",children:[i(wv,{},void 0,!1,void 0,this),i(sw,{minimapVisible:e,onToggleMinimap:g,snapshotOpen:n,onToggleSnapshot:b,snapshotBtnRef:d,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>c((C)=>!C),annotationTool:l,onSetAnnotationTool:j},void 0,!1,void 0,this),i("div",{class:"app-main",children:[i(zw,{},void 0,!1,void 0,this),i(Kb,{},void 0,!1,void 0,this),i("div",{class:"canvas-region",ref:(C)=>kg(C),children:[i(Gb,{onNodeContextMenu:f,onCanvasContextMenu:m,onEdgeContextMenu:v,annotationMode:l!==null,annotationTool:l},void 0,!1,void 0,this),i(Ev,{},void 0,!1,void 0,this),i(Tv,{},void 0,!1,void 0,this),i(lw,{},void 0,!1,void 0,this),i(uw,{},void 0,!1,void 0,this),x&&R.length===0&&We.value.size===0&&i(aw,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),ye.value.size>0&&i(xw,{},void 0,!1,void 0,this),h?i(Xb,{},void 0,!1,void 0,this):Ae.value.size>0&&i(rw,{},void 0,!1,void 0,this),i(Sw,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),i(Iv,{},void 0,!1,void 0,this),Ue.value&&i(fw,{},void 0,!1,void 0,this),i(Ew,{open:n,onClose:E,anchorRef:d},void 0,!1,void 0,this),e&&i(yw,{viewport:ee,nodes:N,edges:$e,onNavigate:_,containerWidth:A.width,containerHeight:A.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h&&i(_w,{},void 0,!1,void 0,this),p&&i(nw,{menu:p,onClose:y},void 0,!1,void 0,this),r&&i(ew,{onClose:()=>s(!1),onToggleMinimap:g},void 0,!1,void 0,this),a&&i(kw,{onClose:()=>c(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}Uv();var Bw=document.getElementById("app");if(Bw)hp(i(Hw,{},void 0,!1,void 0,this),Bw);
331
+ ${a.trim()}`},void 0,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:e,children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"submit",class:"text-prompt-confirm",disabled:!r.trim()||!a.trim(),children:"Continue on GitHub ↗"},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 jr(e,t){console.error(`[tool-rail] ${e} failed`,t)}function Pn(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"}};Ot(t[e].message,t[e].placeholder).then((n)=>{if(!n)return;Dt({type:e,content:n}).catch((o)=>jr(`create ${e}`,o))})}function tt({label:e,shortcut:t,detail:n,ariaLabel:o,active:r,menuOpen:s,onClick:a,btnRef:c,children:l}){let[u,p]=I(null),d=(h)=>{let v=h.currentTarget.getBoundingClientRect();p({left:v.right+10,top:v.top+v.height/2})},f=()=>p(null),m=o??(t?`${e} (${t})`:n?`${e} (${n})`:e);return i(de,{children:[i("button",{ref:c,type:"button",class:`rail-btn${r?" active":""}`,"aria-label":m,"aria-pressed":r===void 0?void 0:r,onClick:(h)=>{f(),a(h)},onPointerEnter:d,onPointerLeave:f,onFocus:d,onBlur:f,children:l},void 0,!1,void 0,this),u&&!s&&i("span",{class:"toolbar-tooltip rail-tooltip",role:"tooltip","data-testid":"rail-tooltip",style:{left:`${u.left}px`,top:`${u.top}px`},children:[i("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),(t||n)&&i("span",{class:"toolbar-tooltip-meta",children:[t&&i("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this),n&&i("span",{children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Zw({minimapVisible:e,onToggleMinimap:t,snapshotOpen:n,onToggleSnapshot:o,snapshotBtnRef:r,onOpenPalette:s,onOpenShortcuts:a,annotationTool:c,onSetAnnotationTool:l}){let u=It.value,p=lr.value,d=Array.from(F.value.values()).filter((z)=>z.type==="trace").length,f=Le.value.size,[m,h]=I(!1),[v,x]=I(null),[g,y]=I(null),E=R(null),L=R(null),P=(z)=>(U)=>{if(v===z){x(null);return}let N=U.currentTarget.getBoundingClientRect();y({top:N.top,bottom:N.bottom,right:N.right}),x(z)},b=(z)=>g?z?{position:"fixed",left:`${g.right+8}px`,bottom:`${window.innerHeight-g.bottom}px`,top:"auto",right:"auto"}:{position:"fixed",left:`${g.right+8}px`,top:`${g.top}px`,right:"auto"}:void 0;B(()=>{if(!v)return;let z=(N)=>{if(E.current&&N.target instanceof Node&&!E.current.contains(N.target))x(null)},U=(N)=>{if(N.key==="Escape")x(null)};return document.addEventListener("pointerdown",z),document.addEventListener("keydown",U),()=>{document.removeEventListener("pointerdown",z),document.removeEventListener("keydown",U)}},[v]);let T=(z)=>{Nc(),document.documentElement.setAttribute("data-theme",z),Pr(),et.value=z,Gs(z),x(null)},w=Qu(et.value),_=(z,U={})=>{fetch(`/api/workbench/intent?_ts=${Date.now()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:z,payload:U})}).catch((N)=>jr("sendIntent",N))};return i(de,{children:[i("div",{class:"tool-rail",ref:E,role:"toolbar","aria-label":"Canvas tools","aria-orientation":"vertical",children:[i(tt,{label:"Home",ariaLabel:"PMX Canvas — Home",onClick:()=>{x(null),At(null).catch((z)=>jr("openHome",z))},children:i("span",{class:"rail-brand",children:i(gc,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"Bug and feedback",menuOpen:m,onClick:()=>{x(null),h(!0)},children:i("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:[i("rect",{x:"4.5",y:"5",width:"7",height:"9",rx:"3.5"},void 0,!1,void 0,this),i("path",{d:"M6 5V4a2 2 0 0 1 4 0v1M8 8v6M2 4l2.5 2M14 4l-2.5 2M1.5 9h3M11.5 9h3M2 14l2.5-2M14 14l-2.5-2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i("div",{class:"rail-divider"},void 0,!1,void 0,this),i(tt,{label:"Select",shortcut:"V",active:u==="select",onClick:()=>It.value="select",children:i($x,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"Pan",shortcut:"Space",active:u==="pan",onClick:()=>It.value="pan",children:i(Mx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"Connect",shortcut:"C",active:u==="connect",onClick:()=>It.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(tt,{label:"Markdown note",shortcut:"M",onClick:()=>void Dt({type:"markdown",title:"New note",width:520,height:360}).catch((z)=>jr("create markdown",z)),children:i(no,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"Image",shortcut:"I",onClick:()=>Pn("image"),children:i(Bd,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"File",shortcut:"Shift+F",onClick:()=>Pn("file"),children:i(pc,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"Attach document",onClick:()=>L.current?.click(),children:i("span",{"aria-hidden":"true",children:"↥"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("input",{ref:L,type:"file",hidden:!0,multiple:!0,accept:".pdf,.ppt,.pptx,.xls,.xlsx,.doc,.docx,.odt,.ods,.odp","aria-label":"Attach documents",onChange:(z)=>{let U=ot(),N=J.value;Rr(Array.from(z.currentTarget.files??[]),(U.width/2-N.x)/N.scale,(U.height/2-N.y)/N.scale),z.currentTarget.value=""}},void 0,!1,void 0,this),i(tt,{label:"Webpage",shortcut:"W",onClick:()=>Pn("webpage"),children:i($r,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"HTML surface",shortcut:"H",onClick:()=>void Dt({type:"html",title:"HTML surface"}).catch((z)=>jr("create html",z)),children:i(Ox,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"Group",shortcut:"G",onClick:()=>void Dt({type:"group",title:"Group"}).catch((z)=>jr("create group",z)),children:i(Hd,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"toolbar-menu-anchor",children:[i(tt,{label:"Annotate",shortcut:"A",detail:"Draw · Text note · Eraser",active:c!==null,menuOpen:v==="annotate",onClick:P("annotate"),children:c==="eraser"?i(Dd,{},void 0,!1,void 0,this):c==="text"?i(Fd,{},void 0,!1,void 0,this):i(Ld,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v==="annotate"&&i("div",{class:"toolbar-menu",style:b(!1),role:"menu","aria-label":"Annotate",children:[i("button",{type:"button",class:`toolbar-menu-item${c==="pen"?" active":""}`,onClick:()=>{l(c==="pen"?null:"pen"),x(null)},children:[i(Ld,{},void 0,!1,void 0,this),i("span",{children:c==="pen"?"Stop annotating":"Draw (A)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:`toolbar-menu-item${c==="text"?" active":""}`,onClick:()=>{l(c==="text"?null:"text"),x(null)},children:[i(Fd,{},void 0,!1,void 0,this),i("span",{children:c==="text"?"Stop text notes":"Text note"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:`toolbar-menu-item${c==="eraser"?" active":""}`,onClick:()=>{l(c==="eraser"?null:"eraser"),x(null)},children:[i(Dd,{},void 0,!1,void 0,this),i("span",{children:c==="eraser"?"Stop erasing":"Eraser"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"rail-spacer"},void 0,!1,void 0,this),i(tt,{label:"Search & commands",shortcut:qe("K"),onClick:s,children:i(Nx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"Arrange",detail:f>0?"graph-aware":"grid",onClick:()=>f>0?la():ca(),children:i(En,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:p?"Disable trace":"Enable trace",active:p,onClick:()=>_("trace-toggle",{enabled:!p}),children:i(zx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),(p||d>0)&&i(tt,{label:"Clear trace",onClick:()=>_("trace-clear"),children:i(Px,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:e?"Hide minimap":"Show minimap",active:e,onClick:t,children:i(fc,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(tt,{label:"Snapshots",active:n,onClick:o,btnRef:r,children:i(Ax,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"toolbar-menu-anchor",children:[i(tt,{label:"Theme",detail:Sr[w].label,menuOpen:v==="theme",ariaLabel:"Choose theme",active:v==="theme",onClick:P("theme"),children:kr(w)==="dark"?i(Ex,{},void 0,!1,void 0,this):i(hc,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v==="theme"&&i("div",{class:"toolbar-menu",style:b(!0),role:"menu","aria-label":"Theme",children:Yu.map((z)=>i("button",{type:"button",role:"menuitemradio","aria-checked":w===z,class:`toolbar-menu-item${w===z?" active":""}`,onClick:()=>T(z),children:[i("span",{class:"theme-swatch",style:{background:Sr[z].swatchBg},children:i("span",{class:"theme-swatch-dot",style:{background:Sr[z].swatchAccent}},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{children:Sr[z].label},void 0,!1,void 0,this),w===z&&i("span",{class:"toolbar-menu-check","aria-hidden":"true",children:"✓"},void 0,!1,void 0,this)]},z,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(tt,{label:"Shortcuts",shortcut:"?",onClick:a,children:i(Rx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m&&i(jw,{onClose:()=>h(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Uw({onOpenPalette:e}){let t=R(null),n=()=>{Dt({type:"markdown",title:"New note",width:520,height:360}).catch(()=>{})},o=async(r)=>{if(!r||r.length===0)return;let s=Zn(),a=J.value;await Rr(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(no,{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:()=>Pn("webpage"),children:[i($r,{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:qe("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 co(),children:[i(Mr,{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 · ",qe("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 qw="From old snapshots";function Ww(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 pp(e){return e.split("/").map((t,n,o)=>o.slice(0,n+1).join("/"))}function Vw({board:e,folders:t,onClose:n}){let o=R(null),[r,s]=I(e.category??""),[a,c]=I(""),[l,u]=I(!1),[p,d]=I("");zt(o,!0),B(()=>{let h=(v)=>{if(v.key!=="Escape")return;if(v.preventDefault(),v.stopPropagation(),!l)n()};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[l,n]);let f=a.trim()?[r,a.trim()].filter(Boolean).join("/"):r,m=async()=>{let h;try{if(a.includes("/"))throw Error("Use one folder name; choose its parent above.");h=Ww(f)}catch(v){d(v instanceof Error?v.message:String(v));return}if(u(!0),d(""),await ga(e.id,{category:h}),Et.value.find((v)=>v.id===e.id)?.category===h)n();else d("Could not move this board. Try again.");u(!1)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>!l&&n(),children:i("div",{ref:o,class:"text-prompt home-folder-dialog",role:"dialog","aria-modal":"true","aria-label":`Move ${e.name}`,onPointerDown:(h)=>h.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:["Move “",e.name,"”"]},void 0,!0,void 0,this),i("p",{class:"home-folder-hint",children:"Choose a folder, or create one inside it. The board keeps its content and links."},void 0,!1,void 0,this),i("fieldset",{class:"home-folder-options",disabled:l,children:[i("legend",{children:"Destination folder"},void 0,!1,void 0,this),["",...t].map((h)=>i("label",{class:"home-folder-option",style:{paddingLeft:`${8+Math.min(h.split("/").length-1,5)*14}px`},children:[i("input",{type:"radio",name:"folder-destination",value:h,checked:r===h,onChange:()=>{s(h),d("")}},void 0,!1,void 0,this),i("span",{children:h||"Home (no folder)"},void 0,!1,void 0,this)]},h,!0,void 0,this))]},void 0,!0,void 0,this),i("label",{class:"home-folder-new",children:["New folder inside ",r||"Home"," ",i("span",{class:"home-folder-hint",children:"(optional)"},void 0,!1,void 0,this),i("input",{class:"text-prompt-input","aria-label":"New folder name",placeholder:"e.g. Decisions",maxLength:60,value:a,disabled:l,onInput:(h)=>{c(h.currentTarget.value),d("")}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"home-folder-hint",children:["Move to: ",i("strong",{children:f||"Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p&&i("p",{role:"alert",children:p},void 0,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",disabled:l,onClick:n,children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"button",class:"text-prompt-confirm",disabled:l||f===(e.category??""),onClick:()=>void m(),children:l?"Moving…":"Move board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Gw({board:e,onClose:t}){let n=R(null),o=R(null),[r,s]=I(null),[a,c]=I(new Set),[l,u]=I(`${e.name} copy`),[p,d]=I(!0),[f,m]=I(!0),[h,v]=I(!1),[x,g]=I(""),[y,E]=I(!1);return zt(n,!0,{initial:o}),B(()=>{let P=!0;return Ey(e.id).then((b)=>{if(!P)return;if(!b||!Array.isArray(b.cards))return g("Could not load reusable cards. Try again.");s(b),c(new Set(b.cards.filter((T)=>T.reusable).map((T)=>T.id)))}),()=>{P=!1}},[e.id]),i("div",{class:"text-prompt-backdrop",onMouseDown:t,children:i("div",{ref:n,class:"text-prompt board-copy-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"board-copy-title",onMouseDown:(P)=>P.stopPropagation(),children:i("form",{onSubmit:async(P)=>{if(P.preventDefault(),!l.trim()||!r)return;E(!0),g("");let b=await Ay({sourceBoardId:e.id,name:l.trim(),...e.category?{category:e.category}:{},nodeIds:[...a],includeReadme:p,includeStructure:f});if(E(!1),!b)return g("Could not create the board. Try a different name.");if(h)await At(b.id);t()},children:[i("h2",{id:"board-copy-title",children:["Create from ",e.name]},void 0,!0,void 0,this),i("label",{class:"board-copy-field",children:["Board name",i("input",{ref:o,class:"text-prompt-input",value:l,onInput:(P)=>u(P.currentTarget.value)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!r&&!x&&i("div",{class:"board-copy-status",role:"status",children:"Loading reusable cards…"},void 0,!1,void 0,this),x&&i("div",{class:"board-copy-error",role:"alert",children:x},void 0,!1,void 0,this),r&&i("fieldset",{class:"board-copy-cards",children:[i("legend",{children:"Cards to copy"},void 0,!1,void 0,this),r.cards.filter((P)=>P.reusable).length===0?i("div",{class:"board-copy-status",children:"No reusable cards on this board."},void 0,!1,void 0,this):r.cards.filter((P)=>P.reusable).map((P)=>i("label",{class:"board-copy-card",children:[i("input",{type:"checkbox",checked:a.has(P.id),onChange:(b)=>{let T=new Set(a);b.currentTarget.checked?T.add(P.id):T.delete(P.id),c(T)}},void 0,!1,void 0,this),i("span",{children:[i("strong",{children:P.title||"Untitled card"},void 0,!1,void 0,this),i("small",{children:P.type},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},P.id,!0,void 0,this))]},void 0,!0,void 0,this),i("div",{class:"board-copy-options",children:[i("label",{children:[i("input",{type:"checkbox",checked:f,onChange:(P)=>m(P.currentTarget.checked)},void 0,!1,void 0,this)," ","Preserve groups and connections"]},void 0,!0,void 0,this),i("label",{children:[i("input",{type:"checkbox",checked:p,disabled:!r?.readmeNodeId,onChange:(P)=>d(P.currentTarget.checked)},void 0,!1,void 0,this)," ","Include README"]},void 0,!0,void 0,this),i("label",{children:[i("input",{type:"checkbox",checked:h,onChange:(P)=>v(P.currentTarget.checked)},void 0,!1,void 0,this)," Open the new board after creating"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("p",{class:"board-copy-note",children:"Only selected cards and structure are copied. Asks, history, and context pins start clear."},void 0,!1,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",onClick:t,children:"Cancel"},void 0,!1,void 0,this),i("button",{type:"submit",disabled:!r||!l.trim()||y,children:y?"Creating…":"Create board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function BA(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 Xw(e){return`${e} node${e!==1?"s":""}`}async function mp(){let e=await Ot("New board","Board name",{confirm:"Create"});if(e)await Iy(e)}var Kw="pmx-canvas-home-collapsed";function HA(){try{let e=localStorage.getItem(Kw);if(e)return new Set(JSON.parse(e))}catch{}return new Set([qw])}function jA(e){try{localStorage.setItem(Kw,JSON.stringify([...e]))}catch{}}function Jw(){let e=Et.value,[t,n]=I(null),[o,r]=I(null),[s,a]=I(null),[c,l]=I(""),[u,p]=I([]),[d,f]=I(HA),m=R(0),h=[...new Set(e.flatMap((_)=>_.category?pp(_.category):[]))].sort((_,z)=>_.localeCompare(z)),v=c.trim().toLocaleLowerCase(),x=e.filter((_)=>`${_.name} ${_.category??""}`.toLocaleLowerCase().includes(v)),g=new Set(x.flatMap((_)=>_.category?pp(_.category):[])),y=e.find((_)=>_.id===o),E=e.find((_)=>_.id===s);B(()=>{let _=c.trim();if(!_){p([]);return}let z=!1,U=window.setTimeout(()=>{Y("searchLibrary",`/api/canvas/search?q=${encodeURIComponent(_)}&scope=library&limit=30`,null).then((N)=>{if(!z)p(N?.results??[])})},150);return()=>{z=!0,window.clearTimeout(U)}},[c]);let L=async(_)=>{let z=++m.current;await At(_.boardId);for(let U=0;U<40;U++){if(z!==m.current||Pe.value!==_.boardId)return;if(F.value.has(_.cardId)){Ke(_.cardId);return}await new Promise((N)=>window.setTimeout(N,25))}},P=(_)=>{let z=new Set(d);if(z.has(_))z.delete(_);else z.add(_);f(z),jA(z)},b=async(_)=>{let z=await Ot("Rename board","Board name",{initial:_.name,confirm:"Rename"});if(z&&z!==_.name)await ga(_.id,{name:z})},T=(_)=>t===_.id?i("li",{class:"home-board is-confirming","data-testid":"home-board",children:[i("div",{class:"home-board-confirm-text",children:["Delete ",i("strong",{children:_.name},void 0,!1,void 0,this)," and its ",Xw(_.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),Py(_.id)},children:"Delete board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},_.id,!0,void 0,this):i("li",{class:"home-board","data-testid":"home-board",children:[i("button",{type:"button",class:"home-board-open",onClick:()=>void At(_.id),children:[i("span",{class:"home-board-name",children:_.name},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[Xw(_.nodeCount)," · ",BA(_.lastOpenedAt)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"home-board-actions",children:[i("button",{type:"button",class:"home-board-action","aria-haspopup":"dialog",onClick:()=>r(_.id),children:"Move"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action","aria-haspopup":"dialog",onClick:()=>a(_.id),children:"Create from…"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>void b(_),children:"Rename"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-board-action",onClick:()=>n(_.id),children:"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},_.id,!0,void 0,this),w=(_,z)=>{let U=h.filter((S)=>S.slice(0,S.lastIndexOf("/"))===_&&S.includes("/")),N=x.filter((S)=>S.category===_),Z=x.filter((S)=>S.category===_||S.category?.startsWith(`${_}/`)).length,j=!!v||!d.has(_);return i("section",{class:"home-section","data-testid":"home-section","data-folder":_,"aria-label":_,children:[i("button",{type:"button",class:"home-section-head","aria-expanded":j,onClick:()=>P(_),children:[i("svg",{class:"home-section-chevron",viewBox:"0 0 20 20",width:"18",height:"18",fill:"none","aria-hidden":"true",children:i("path",{d:"m7.5 4.75 5.25 5.25-5.25 5.25"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("svg",{class:"home-section-folder",viewBox:"0 0 20 20",width:"18",height:"18",fill:"none","aria-hidden":"true",children:i("path",{d:"M2.75 5.75A1.75 1.75 0 0 1 4.5 4h3l1.75 2h6.25a1.75 1.75 0 0 1 1.75 1.75v6.5A1.75 1.75 0 0 1 15.5 16h-11a1.75 1.75 0 0 1-1.75-1.75v-8.5Z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"home-section-name",children:_.split("/").at(-1)},void 0,!1,void 0,this),i("span",{class:"home-section-count",children:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&i("div",{class:"home-folder-children",style:{marginLeft:z<5?"14px":"0"},children:[U.filter((S)=>g.has(S)).map((S)=>w(S,z+1)),N.length>0&&i("ul",{class:"home-view-list","aria-label":`Boards in ${_}`,children:N.map(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},_,!0,void 0,this)};return i("div",{class:"home-view","data-testid":"home-view",children:[i("div",{class:"home-view-inner",children:[i("div",{class:"home-view-head",children:[i("h1",{class:"home-view-title",children:"Boards"},void 0,!1,void 0,this),i("button",{type:"button",class:"home-view-new",onClick:()=>void mp(),children:"New board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("input",{class:"text-prompt-input home-search",type:"search","aria-label":"Find boards and folders",placeholder:"Find boards and folders…",value:c,onInput:(_)=>l(_.currentTarget.value)},void 0,!1,void 0,this),e.length===0?i("div",{class:"home-view-empty",children:"No boards yet. Create one, or let an agent start writing — it opens one."},void 0,!1,void 0,this):v&&u.length>0?i("ul",{class:"home-view-list","aria-label":"Library search results",children:u.map((_)=>i("li",{class:"home-board",children:i("button",{type:"button",class:"home-board-open",onClick:()=>void L(_),children:[i("span",{class:"home-board-name",children:_.title||_.boardTitle},void 0,!1,void 0,this),i("span",{class:"home-board-meta",children:[_.boardTitle," · ",_.snippet]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},`${_.boardId}:${_.cardId}`,!1,void 0,this))},void 0,!1,void 0,this):x.length===0?i("div",{class:"home-view-empty",role:"status",children:["No boards match “",c,"”."]},void 0,!0,void 0,this):i(de,{children:[h.filter((_)=>!_.includes("/")&&g.has(_)).map((_)=>w(_,0)),x.some((_)=>!_.category)&&i("section",{"aria-label":"Unfiled boards",children:[h.length>0&&i("div",{class:"home-folder-hint",children:"Unfiled boards"},void 0,!1,void 0,this),i("ul",{class:"home-view-list",children:x.filter((_)=>!_.category).map(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),y&&i(Vw,{board:y,folders:h,onClose:()=>r(null)},y.id,!1,void 0,this),E&&i(Gw,{board:E,onClose:()=>a(null)},E.id,!1,void 0,this)]},void 0,!0,void 0,this)}var Zr=q(!1);function ZA(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.ceil(e/1024)} KB`}function Yw(){let[e,t]=I(!1),[n,o]=I(!1),[r,s]=I(null),[a,c]=I(null),[l,u]=I(!1),p=Zr.value,d=Pe.value;if(B(()=>{if(!p||!d)return;let m=!0;return c(null),s(null),Y("exportPreview",`/api/canvas/export/preview?board=${encodeURIComponent(d)}&includeFiles=${e}&includeDerivedText=${n}`,null).then((h)=>{if(m)s(h?.manifest??null)}),()=>{m=!1}},[p,e,n,d]),B(()=>{o(!1)},[p,d]),B(()=>{if(!p)return;let m=(h)=>{if(h.key!=="Escape")return;h.stopPropagation(),Zr.value=!1};return window.addEventListener("keydown",m,{capture:!0}),()=>window.removeEventListener("keydown",m,{capture:!0})},[p]),!p)return null;let f=async()=>{if(!r||r.boardId!==Pe.value)return;u(!0);let m=await Y("exportBoard","/api/canvas/export",null,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({board:r.boardId,includeFiles:e,includeDerivedText:n})});if(u(!1),m?.path&&Pe.value===r.boardId)c(m)};return i("div",{class:"text-prompt-backdrop",onPointerDown:()=>Zr.value=!1,children:i("div",{class:"text-prompt export-dialog",role:"dialog","aria-label":"Export board","data-testid":"export-dialog",onPointerDown:(m)=>m.stopPropagation(),children:[i("div",{class:"text-prompt-title",children:["Export ",r?`“${r.boardName}”`:"board"]},void 0,!0,void 0,this),!r?i("div",{class:"export-dialog-note",children:"Reading the board…"},void 0,!1,void 0,this):i(de,{children:[i("div",{class:"export-dialog-note",children:"One HTML file anyone can open without installing anything. It will contain:"},void 0,!1,void 0,this),i("ul",{class:"export-dialog-list",children:[i("li",{children:[r.cards," card",r.cards!==1?"s":""," and ",r.connections," connection",r.connections!==1?"s":""]},void 0,!0,void 0,this),r.frames>0&&i("li",{children:[r.frames," embedded pages, charts or diagrams, with the code that draws them"]},void 0,!0,void 0,this),r.embeddedImages>0&&i("li",{children:[r.embeddedImages," local images"]},void 0,!0,void 0,this),r.placeholders.length>0&&i("li",{children:["Shown as placeholders:"," ",r.placeholders.map((m)=>`${m.title} (${m.reason})`).join(", ")]},void 0,!0,void 0,this),r.remoteImages.length>0&&i("li",{children:["Web images loaded when opened: ",r.remoteImages.join(", ")]},void 0,!0,void 0,this),r.links.length>0&&i("li",{children:["Links included in cards: ",r.links.join(", ")]},void 0,!0,void 0,this),r.frameNetworkDestinations.length>0&&i("li",{children:["Network destinations referenced by embedded pages: ",r.frameNetworkDestinations.join(", ")]},void 0,!0,void 0,this),r.embeddedCodeCanAccessNetwork&&i("li",{children:"Warning: embedded code can access the network. Scripts may contact destinations that cannot be listed in advance."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(r.attachments?.length??0)>0&&i("p",{children:"Original attachments are excluded. Their filenames remain visible."},void 0,!1,void 0,this),(r.sourceDerivedCards?.length??0)>0&&i("label",{class:"export-dialog-files",children:[i("input",{type:"checkbox",checked:n,onChange:(m)=>o(m.currentTarget.checked)},void 0,!1,void 0,this),i("span",{children:["Include imported document text (",r.sourceDerivedCards.length," cards)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r.files.length>0&&i("label",{class:"export-dialog-files",children:[i("input",{type:"checkbox",checked:e,onChange:(m)=>t(m.target.checked)},void 0,!1,void 0,this),i("span",{children:["Include the contents of ",r.files.length," local file",r.files.length!==1?"s":"",": ",r.files.map((m)=>m.path).join(", ")]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a&&i("div",{class:"export-dialog-result","data-testid":"export-result",children:[i("div",{children:["Saved (",ZA(a.bytes),"): ",i("code",{children:a.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"export-dialog-links",children:[i("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",children:"Open"},void 0,!1,void 0,this),i("a",{class:"is-primary",href:`${a.url}?download=1`,children:"Download"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"text-prompt-actions",children:[i("button",{type:"button",class:"text-prompt-cancel",onClick:()=>Zr.value=!1,children:a?"Done":"Cancel"},void 0,!1,void 0,this),!a&&i("button",{type:"button",class:"text-prompt-confirm",disabled:!r||l,onClick:()=>void f(),children:l?"Exporting…":"Export"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function fp({presence:e,size:t=18}){return i("span",{class:"writer-avatar",style:{background:yc(e.sessionId),width:`${t}px`,height:`${t}px`},"aria-hidden":"true",children:Wx(e.label)},void 0,!1,void 0,this)}function Qw(){let e=Gd.value;if(vt.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=Fo.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:()=>{Fo.value=!o},children:[i("span",{class:"external-indicator-avatars",children:e.slice(0,3).map((r)=>i(fp,{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 UA(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 qA(e){return e.reduce((t,n)=>n.lastSeenAt>t?n.lastSeenAt:t,"")}function WA(){return[...Ve.value.values()].filter((e)=>!e.auto&&e.phase==="forming")}function e_(){let e=Fo.value,t=Gd.value,n=zn(e?1e4:0);if(B(()=>{if(!e)return;let c=(l)=>{if(l.key!=="Escape")return;if(Or.value)Or.value=!1;else Fo.value=!1};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e]),!e||vt.value||t.length===0)return null;let o=Vd.value,r=WA().filter((c)=>!o||(c.source??"")===o),s=io.value.filter((c)=>!o||c.sessionId===o),a=(c,l)=>i("button",{type:"button",class:`activity-filter${o===c?" is-active":""}`,style:c?{"--writer":yc(c)}:void 0,"aria-pressed":o===c,onClick:()=>{Vd.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"," ",bc(qA(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:()=>{Fo.value=!1},children:"×"},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:()=>{Co(c).then((l)=>{if(l)Ro(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}=UA(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:yc(c.sessionId)},children:c.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"activity-age",children:bc(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:()=>{Or.value=!0},children:"Writers"},void 0,!1,void 0,this),i("button",{type:"button",class:"activity-feed-link is-accent",onClick:()=>{Fo.value=!1,co()},children:"Start session ↗"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function VA(){let e=[];if(so.value)e.push("scoped");if(Bo.value.length>0)e.push("gated");return e.length>0?e.join(" + "):"open"}function t_(){let e=Or.value,t=zn(e?1e4:0),n=R(null);if(zt(n,e),!e)return null;let o=gt.value.filter((a)=>a.attached),r=gt.value.filter((a)=>!a.attached),s=()=>{Or.value=!1};return i(de,{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:xn.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:"×"},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(fp,{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:VA()},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(fp,{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"," ",bc(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 n_(e,t){switch(e.type){case"markdown":return i(Ca,{node:e,expanded:t},void 0,!1,void 0,this);case"mcp-app":return i(to,{node:e,expanded:t},void 0,!1,void 0,this);case"webpage":return i(cc,{node:e,expanded:t},void 0,!1,void 0,this);case"json-render":return i(to,{node:e,expanded:t},void 0,!1,void 0,this);case"graph":return i(to,{node:e,expanded:t},void 0,!1,void 0,this);case"board":return i(Ec,{node:e},void 0,!1,void 0,this);case"prompt":return i(lc,{node:e},void 0,!1,void 0,this);case"response":return i(uc,{node:e,expanded:t},void 0,!1,void 0,this);case"status":return i(sc,{node:e},void 0,!1,void 0,this);case"context":return i(da,{node:e,expanded:t},void 0,!1,void 0,this);case"ledger":return i(ba,{node:e},void 0,!1,void 0,this);case"trace":return i(dc,{node:e},void 0,!1,void 0,this);case"file":return i(ya,{node:e,expanded:t},void 0,!1,void 0,this);case"diff":return i(pa,{node:e},void 0,!1,void 0,this);case"mermaid":return i(Ba,{node:e,expanded:t},void 0,!1,void 0,this);case"image":return i(ac,{node:e,expanded:t},void 0,!1,void 0,this);case"html":return i(Di,{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 o_(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 GA(e){if(!e)return 0;return e.split(/\s+/).filter(Boolean).length}function XA(e,t){return e!==null&&typeof e==="object"&&e.source===Ut&&e.type==="presentation-exit"&&e.token===t}function KA(e){return e==="ArrowRight"||e==="PageDown"||e===" "||e==="ArrowLeft"||e==="PageUp"||e==="Home"||e==="End"}function r_(e){return e instanceof HTMLElement&&Boolean(e.closest(".html-presentation-exit"))}function i_(){let e=Ue.value,t=e?F.value.get(e):void 0,[n,o]=I(!1),[r,s]=I(!1),[a,c]=I(""),l=R(null),u=R(null),p=H(()=>{s(!1),Cn()},[]),d=H(()=>{c(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),s(!0)},[]),f=H((S)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:Ut,token:a,...S},"*")},[a]),m=H(()=>{s(!1)},[]),h=H((S)=>{if(S.key==="Escape"){S.preventDefault(),S.stopPropagation(),s(!1);return}if(S.key==="Tab"&&!r_(S.target)){S.preventDefault(),S.stopPropagation(),u.current?.focus();return}if((S.key===" "||S.key==="Enter")&&r_(S.target))return;if(!KA(S.key))return;S.preventDefault(),S.stopPropagation(),f({type:"presentation-key",key:S.key})},[f]),v=H((S)=>{if(S.target.classList.contains("expanded-overlay-backdrop"))Cn()},[]),x=H(()=>{if(!t)return;let S=o_(t);if(!S)return;navigator.clipboard.writeText(S).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},[t]),g=H(()=>{if(!e)return;Vn(e)},[e]);B(()=>{s(!1)},[e]),Dn(()=>{if(!r)return;let S=()=>{let je=l.current;if(!je||je.contains(document.activeElement))return;je.focus()},V=[0,50,150].map((je)=>window.setTimeout(S,je)),he=(je)=>{if(!XA(je.data,a))return;s(!1)};return document.addEventListener("keydown",h,!0),window.addEventListener("message",he),()=>{V.forEach((je)=>{window.clearTimeout(je)}),document.removeEventListener("keydown",h,!0),window.removeEventListener("message",he)}},[h,a,r]);let y=R(null),E=H(()=>e?document.querySelector(`.canvas-node[data-node-id="${CSS.escape(e)}"]`):null,[e]);if(zt(y,t!==void 0,{restoreTo:E}),!t)return null;let L=t.data.title||t.data.path?.split("/").pop()||lt[t.type],P=o_(t),b=GA(P),T=e?Ae.value.has(e):!1,w=P.length>0,_=en.value===e,z=t.type==="mcp-app"||t.type==="webpage"||t.type==="json-render"||t.type==="graph",U=yx(t),N=rn(t.type),Z=t.data.provenance&&typeof t.data.provenance==="object"?t.data.provenance:null,j=Z?[Z.sourceKind,Z.sourceUri,Z.syncedAt?`synced ${Z.syncedAt.slice(11,16)}`:null].filter((S)=>typeof S==="string"&&S.length>0).join(" · "):null;return i("div",{class:"expanded-overlay-backdrop",onPointerDown:v,style:{pointerEvents:_?"none":"auto"},children:i("div",{ref:y,class:`expanded-overlay-panel${T?" is-pinned":""}`,role:"dialog","aria-modal":"true","aria-label":L,"data-testid":"expanded-node",children:[i("div",{class:"expanded-header",children:[i("span",{class:"expanded-kind-icon","aria-hidden":"true",children:i(N,{size:15},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"expanded-title",children:L},void 0,!1,void 0,this),i("span",{class:"expanded-kind-pill",children:lt[t.type]},void 0,!1,void 0,this),i("button",{type:"button",class:`expanded-pin${T?" is-on":""}`,onClick:g,title:T?"In agent context — click to unpin":"Pin as agent context","aria-pressed":T,children:"✦"},void 0,!1,void 0,this),i("span",{class:"expanded-spacer"},void 0,!1,void 0,this),i("div",{class:"expanded-actions",children:[w&&i("button",{type:"button",class:"expanded-action-btn",onClick:x,title:"Copy content to clipboard",children:n?"Copied!":"Copy"},void 0,!1,void 0,this),Aa(t)&&i("button",{type:"button",class:"expanded-action-btn",onClick:()=>void za(t),title:"Open as a full-page site in the system browser",children:"Open in tab ↗"},void 0,!1,void 0,this),U&&i("button",{type:"button",class:"expanded-action-btn expanded-action-primary",onClick:d,title:"Present this HTML node fullscreen",children:"Present"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{type:"button",class:"expanded-close",onClick:p,title:"Close (Esc)","aria-label":"Close",children:"×"},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:n_(t,!0)},void 0,!1,void 0,this):n_(t,!0)},void 0,!1,void 0,this),i("div",{style:{"--ax-dock-bleed":"0px","--ax-dock-pad":"16px"},children:i(Ic,{node:t},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("div",{class:"expanded-footer",children:[i("span",{class:"expanded-footer-meta",children:[j,b>0?`${b.toLocaleString()} word${b!==1?"s":""}`:null].filter(Boolean).join(" · ")||lt[t.type].toLowerCase()},void 0,!1,void 0,this),i("span",{class:"expanded-spacer"},void 0,!1,void 0,this),i("span",{class:`expanded-footer-hint${_?" is-saving":""}`,children:_?"Saving edits…":"esc or click outside to close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&r&&i("div",{ref:l,class:"html-presentation-overlay",role:"dialog","aria-modal":"true","aria-label":`Present ${L}`,tabIndex:-1,onKeyDownCapture:h,children:[i("button",{ref:u,type:"button",class:"html-presentation-exit",onClick:m,title:"Exit presentation (Esc)","aria-label":"Exit presentation",children:"Exit presentation"},void 0,!1,void 0,this),i("div",{class:"html-presentation-stage",children:i(Di,{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 a_=168,c_=112,$c=20;function s_(e,t,n,o){let r=Array.from(e.values()),s=0,a=0,c=1000,l=800;if(r.length>0){s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let x of r)s=Math.min(s,x.position.x),a=Math.min(a,x.position.y),c=Math.max(c,x.position.x+x.size.width),l=Math.max(l,x.position.y+x.size.height)}let u=-t.x/t.scale,p=-t.y/t.scale,d=u+n/t.scale,f=p+o/t.scale,m={minX:Math.min(s,u)-$c,minY:Math.min(a,p)-$c,maxX:Math.max(c,d)+$c,maxY:Math.max(l,f)+$c},h=m.maxX-m.minX||1,v=m.maxY-m.minY||1;return{bounds:m,scale:Math.min(a_/h,c_/v)}}function l_({viewport:e,nodes:t,onNavigate:n,containerWidth:o,containerHeight:r}){let s=R(null),a=R(!1),c=t.value,l=e.value,u=s_(c,l,o,r),{bounds:p,scale:d}=u,f=(b)=>(b-p.minX)*d,m=(b)=>(b-p.minY)*d,h=H((b)=>{let T=s.current;if(!T)return;let w=T.getBoundingClientRect(),_=(b.clientX-w.left)/w.width*a_,z=(b.clientY-w.top)/w.height*c_,U=s_(t.value,e.value,o,r),N=e.value,Z=o/N.scale,j=r/N.scale,S=_/U.scale+U.bounds.minX,V=z/U.scale+U.bounds.minY;n(-(S-Z/2)*N.scale,-(V-j/2)*N.scale)},[t,e,o,r,n]),v=H((b)=>{b.stopPropagation(),b.preventDefault(),a.current=!0,h(b);let T=(_)=>{if(a.current)h(_)},w=()=>{a.current=!1,document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",w)};document.addEventListener("pointermove",T),document.addEventListener("pointerup",w)},[h]),x=ye.value,g=so.value,y=g?wc(g.nodeIds.map((b)=>c.get(b)).filter((b)=>b!==void 0),g.padding):null,E=gt.value.map((b)=>({id:b.sessionId,phase:b.phase,worker:b.parentAgentId!=null,external:!b.attached,at:xc(b,(T)=>c.get(T))})).filter((b)=>b.at!==null),L=-l.x/l.scale,P=-l.y/l.scale;return i("div",{ref:s,class:"minimap","data-testid":"minimap",title:"Click to jump · drag the frame to pan",onPointerDown:v,children:[Array.from(c.values()).map((b)=>{let T=b.type==="group";return i("span",{class:`minimap-node${T?" is-group":""}${x.has(b.id)?" is-selected":""}`,"data-kind":b.type,style:{left:`${f(b.position.x)}px`,top:`${m(b.position.y)}px`,width:`${Math.max(T?6:4,b.size.width*d)}px`,height:`${Math.max(T?5:3,b.size.height*d)}px`,"--kind":Cc[b.type]}},b.id,!1,void 0,this)}),y&&i("span",{class:"minimap-fence",style:{left:`${f(y.x)}px`,top:`${m(y.y)}px`,width:`${y.width*d}px`,height:`${y.height*d}px`}},void 0,!1,void 0,this),E.map((b)=>i("span",{class:`minimap-presence phase-${b.phase}${b.worker?" is-worker":""}${b.external?" is-external":""}`,style:{left:`${f(b.at.x)-4}px`,top:`${m(b.at.y)-4}px`,"--identity-color":`hsl(${ro(b.id)} 65% 62%)`}},b.id,!1,void 0,this)),i("span",{class:"minimap-frame",style:{left:`${f(L)}px`,top:`${m(P)}px`,width:`${o/l.scale*d}px`,height:`${r/l.scale*d}px`}},void 0,!1,void 0,this),i("span",{class:"minimap-zoom",children:[Math.round(l.scale*100),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Ge({label:e,shortcut:t,body:n,align:o="center",side:r="down",tapToOpen:s=!1,children:a}){return i("span",{class:`toolbar-tooltip-anchor toolbar-tooltip-anchor-${o}${r==="up"?" toolbar-tooltip-anchor-up":""}${s?" toolbar-tooltip-anchor-tap":""}`,tabIndex:s?-1:void 0,children:[a,i("span",{class:"toolbar-tooltip",role:"tooltip",children:[i("span",{class:"toolbar-tooltip-label",children:e},void 0,!1,void 0,this),n&&i("span",{class:"toolbar-tooltip-body",children:n},void 0,!1,void 0,this),t&&i("span",{class:"toolbar-tooltip-meta",children:i("kbd",{class:"toolbar-tooltip-shortcut",children:t},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function u_(){let e=ye.value.size,t=H(()=>{let c=Array.from(ye.value);if(c.length===0)return;oa(c),xt()},[]),n=H(()=>{let c=Array.from(ye.value);if(c.length===0)return;sr({title:"Group",childIds:c}),xt()},[]),o=H(()=>{let c=Array.from(ye.value);for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++)To(c[l],c[u],"relation");xt()},[]),r=H(()=>{let c=Array.from(ye.value);for(let l of c)qn(l);xt()},[]);if(e===0)return null;let s=e>=2,a=!vt.value&&Ae.value.size>0&&!ln.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(de,{children:[i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Ge,{label:"Align left",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align left",onClick:()=>yu("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(Ge,{label:"Align top",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Align top",onClick:()=>yu("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(Ge,{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:()=>Yv(),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(Ge,{label:"Auto-arrange selection",side:"up",children:i("button",{type:"button",class:"selection-bar-icon","aria-label":"Auto-arrange",onClick:()=>Qv(),children:i(En,{size:14},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i("span",{class:"selection-bar-sep"},void 0,!1,void 0,this),i(Ge,{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(Ge,{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(Ge,{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(Ge,{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(Ge,{label:"Clear selection",shortcut:"Esc",side:"up",children:i("button",{type:"button",class:"selection-bar-icon",onClick:xt,"aria-label":"Clear selection",children:"×"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Mc(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 Oc(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 JA={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"vetoed"},YA={todo:"queued","in-progress":"running",blocked:"awaiting",done:"done",cancelled:"cancelled"},d_=[{id:"all",label:"All",hint:"Everything below in one feed, newest first"},{id:"update",label:"Updates",hint:"Board edits agents made — nodes, edges, pins, work items"},{id:"steer",label:"Steer",hint:"Instructions sent to agents — by you from the composer, or agent-to-agent"},{id:"assistant",label:"Assistant",hint:"Messages agents posted for you to read"},{id:"event",label:"Events",hint:"Run telemetry — tool runs, approvals, failures, policy notes"},{id:"evidence",label:"Evidence",hint:"Proof agents recorded — test results, artifacts, links"}],p_=Object.fromEntries(d_.map((e)=>[e.id,e.hint])),QA={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 hp(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 e1({item:e}){let t=JA[e.status]??"queued",n=e.nodeIds[0];return i("li",{class:`session-item status-${t}`,"data-work-item-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("button",{type:"button",class:"session-item-title",title:n?"Focus the linked node":void 0,disabled:!n,onClick:()=>n&&Ke(n),children:e.title},void 0,!1,void 0,this),e.detail&&i("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("span",{class:"session-item-status",children:YA[e.status]??t},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:hp(e.updatedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function t1({gate:e,now:t}){let[n,o]=I(null),r=async(c)=>{o(c),await iw(e,c),o(null)},s=e.nodeIds[0],a=Mc(e,t);return i("li",{class:"session-item status-awaiting session-gate","data-gate-id":e.id,children:[i("span",{class:"session-glyph","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-item-main",children:[i("button",{type:"button",class:"session-item-title",title:s?"Focus the linked node":void 0,disabled:!s,onClick:()=>s&&Ke(s),children:e.title},void 0,!1,void 0,this),e.detail&&i("div",{class:"session-item-detail",children:e.detail},void 0,!1,void 0,this),a!==null&&i("div",{class:"session-gate-ttl","data-testid":"gate-countdown",children:["auto-holds in ",Oc(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:hp(e.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function n1({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),sw(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 o1(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 r1({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:o1(e)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function i1(){let e=so.value,t=ye.value.size,[n,o]=I(!1),r=(s)=>{o(!0),Qx(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(de,{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(de,{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([...ye.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 s1(e){if(e==="browser")return"you";return gt.value.find((n)=>n.sessionId===e||n.source===e)?.label??e}function a1({entry:e}){let t=Bi.value.has(e.id);return i("li",{class:`session-timeline-row tone-${QA[e.kind]??"muted"}`,children:[i("span",{class:"session-timeline-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("div",{class:"session-timeline-main",children:[i("div",{class:"session-timeline-head",children:[i("span",{class:"session-timeline-label",title:p_[Qd(e.kind)],children:e.label},void 0,!1,void 0,this),e.who&&i("span",{class:"session-timeline-who",style:{"--identity-color":`hsl(${ro(e.who)} 65% 62%)`},children:s1(e.who)},void 0,!1,void 0,this),i("span",{class:"session-item-time",children:hp(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 ep(e),children:"↩ undo this edit"},void 0,!1,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 m_(){let[e,t]=I(!1),n=Lr.value,o=Yx.value,r=Bo.value,s=ew.value,a=tw.value,c=rw.value,[l,u]=I(!1),[p,d]=I(null),f=zn();if(B(()=>{ao()},[]),!(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:oo(n),"aria-label":`Session live: ${oo(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:oo(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 _c(n),children:"End"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-collapse",onClick:()=>t(!1),title:"Collapse session panel",children:"›"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i(i1,{},void 0,!1,void 0,this),(()=>{let h=c.find((v)=>v.undoable&&!Bi.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 ep(h),children:"↩ Undo"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})(),i("div",{class:"session-panel-body",children:[i("section",{class:"session-section",children:(()=>{let h=o.filter((P)=>P.status==="in-progress"||P.status==="todo").length,v=o.filter((P)=>P.status!=="cancelled"),x=v.filter((P)=>P.status==="done").length,g=o.length-v.length,y=r.length>0,E=l||y,L=h>0?`${h} running`:v.length>0?`${x}/${v.length} done${g>0?` · ${g} cancelled`:""}`:o.length>0?`${o.length} cancelled`:"none yet";return i(de,{children:[i("button",{type:"button",class:"session-section-toggle","aria-expanded":E,"data-testid":"work-items-toggle",onClick:()=>u((P)=>!P),children:[i("span",{class:"session-section-title",children:"Work items"},void 0,!1,void 0,this),i("span",{class:"session-work-summary",children:[h>0&&i("span",{class:"session-work-dot","aria-hidden":"true"},void 0,!1,void 0,this),L]},void 0,!0,void 0,this),i("span",{class:`session-section-chevron${E?" is-open":""}`,"aria-hidden":"true",children:"›"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E&&(r.length===0&&s.length===0&&a.length===0&&o.length===0?i("div",{class:"session-empty",children:"No work items yet — the agent's tasks and gates appear here."},void 0,!1,void 0,this):i("ul",{class:"session-list","aria-live":"polite","aria-label":"Work items and gates",children:[r.map((P)=>i(t1,{gate:P,now:f},P.id,!1,void 0,this)),s.map((P)=>i(n1,{gate:P},P.id,!1,void 0,this)),a.map((P)=>i(r1,{gate:P},P.id,!1,void 0,this)),o.map((P)=>i(e1,{item:P},P.id,!1,void 0,this))]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)})()},void 0,!1,void 0,this),i("section",{class:"session-section",children:[i("h3",{class:"session-section-title",children:"Timeline"},void 0,!1,void 0,this),i("div",{class:"session-timeline-filters",role:"group","aria-label":"Filter timeline",children:d_.map((h)=>i("button",{type:"button",class:`activity-filter${Ho.value===h.id?" is-active":""}`,"aria-pressed":Ho.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:()=>{Ho.value=h.id},children:h.label},h.id,!1,void 0,this))},void 0,!1,void 0,this),i("div",{class:"session-timeline-hint","data-testid":"timeline-filter-hint",children:p_[p??Ho.value]},void 0,!1,void 0,this),c.length===0?i("div",{class:"session-empty",children:Ho.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(a1,{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 gp(e){if(!e||typeof e!=="object")return null;let t=e,n=(o)=>Array.isArray(o)?o.length:0;return{added:n(t.addedNodes)+n(t.addedEdges),removed:n(t.removedNodes)+n(t.removedEdges),modified:n(t.modifiedNodes)}}function f_({onOpenSnapshots:e}){let t=Sc.value,[n,o]=I(null),[r,s]=I(!1);if(!t)return null;let a=async()=>{if(!t.snapshot)return;s(!0);try{let u=await fetch(`/api/canvas/snapshots/${encodeURIComponent(t.snapshot.id)}/diff`,{headers:{"x-pmx-workbench":"1"}});if(u.ok){let p=await u.json();o(gp(p.diff)??{added:0,removed:0,modified:0})}}finally{s(!1)}},c=new Date(t.endedAt),l=Number.isNaN(c.getTime())?"":`${String(c.getHours()).padStart(2,"0")}:${String(c.getMinutes()).padStart(2,"0")}`;return i("div",{class:"session-receipt","data-testid":"session-receipt",role:"status",children:[i("div",{class:"session-receipt-head",children:[i("span",{class:"session-receipt-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"session-receipt-title",children:[t.endedBy==="human"?"Session ended by you":t.endedBy==="idle-timeout"?"Session ended — idle timeout":t.endedBy==="agent"?"Session ended by the agent":"Session ended",l?` · ${l}`:""]},void 0,!0,void 0,this),i("button",{type:"button",class:"session-receipt-close",onClick:kc,"aria-label":"Dismiss receipt",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-tiles",children:[i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Items"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value",children:t.counts.items},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Done"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-ok",children:t.counts.done},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.cancelled>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Cancelled"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-muted",children:t.counts.cancelled},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.rejected>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Rejected"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-danger",children:t.counts.rejected},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.counts.held>0&&i("div",{class:"session-receipt-tile",children:[i("span",{class:"session-receipt-tile-label",children:"Held"},void 0,!1,void 0,this),i("span",{class:"session-receipt-tile-value tone-warn",children:t.counts.held},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"session-receipt-note",children:t.snapshot?"A snapshot of the board from before this session is saved — restore it to undo the session.":t.unchanged?"This session changed nothing on the board — no snapshot kept.":"The board was empty when the session started — nothing to restore."},void 0,!1,void 0,this),n&&i("div",{class:"session-receipt-diff","data-testid":"session-receipt-diff",children:["This session: ",n.added," added · ",n.removed," removed · ",n.modified," modified"]},void 0,!0,void 0,this),i("div",{class:"session-receipt-actions",children:[t.snapshot&&i("button",{type:"button",class:"session-receipt-primary",disabled:r,onClick:()=>void a(),children:r?"Comparing…":"View diff"},void 0,!1,void 0,this),i("button",{type:"button",class:"session-receipt-secondary",title:"Open the History drawer — saved boards and past sessions",onClick:e,children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var c1=[{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:qe("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:qe("0"),desc:"Reset viewport to origin"},{keys:`${qe("+")} / ${qe("−")}`,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:bi?"Delete / ⌫":"Delete / Backspace",desc:"Delete the selection (or the focused node)"},{keys:bi?"⌘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 h_({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:c1.map((t)=>i("div",{class:"shortcut-group",children:[i("div",{class:"shortcut-group-title",children:t.title},void 0,!1,void 0,this),t.shortcuts.map((n)=>i("div",{class:"shortcut-row",children:[i("kbd",{class:"shortcut-keys",children:n.keys},void 0,!1,void 0,this),i("span",{class:"shortcut-desc",children:n.desc},void 0,!1,void 0,this)]},n.keys,!0,void 0,this))]},t.title,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var g_="Before session · ";function v_(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 l1(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 Lc(e){if(!e.startsWith(g_))return null;let t=e.slice(g_.length),n=t.lastIndexOf(" · ");return n>0?t.slice(0,n):t}function y_({open:e,onClose:t,anchorRef:n}){let[o,r]=I([]),[s,a]=I(!1),[c,l]=I(!1),[u,p]=I(null),[d,f]=I(""),[m,h]=I(null),[v,x]=I({}),g=R(null),y=R(null);B(()=>{if(!e)return;a(!0),Mv().then((w)=>{r(w),a(!1)})},[e]),B(()=>{if(e)setTimeout(()=>y.current?.focus(),50)},[e]),B(()=>{if(!e)return;let w=(_)=>{let z=g.current,U=n.current;if(z&&!z.contains(_.target)&&U&&!U.contains(_.target))t()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,t]),B(()=>{if(!e)return;let w=(_)=>{if(_.key==="Escape")t()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[e,t]);let E=H(async()=>{let w=d.trim();if(!w)return;l(!0);let _=await Ov(w);if(l(!1),_.ok&&_.snapshot)r((z)=>[_.snapshot,...z]),f("")},[d]),L=H(async(w)=>{h(null),p(w);let _=await Lv(w);if(p(null),_.ok)t()},[t]),P=H(async(w)=>{if((await Dv(w)).ok)r((z)=>z.filter((U)=>U.id!==w));h(null)},[]),b=H(async(w)=>{x((z)=>({...z,[w]:"loading"}));let _=await Y("snapshotDiff",`/api/canvas/snapshots/${encodeURIComponent(w)}/diff`,{});x((z)=>({...z,[w]:gp(_.diff)??{added:0,removed:0,modified:0}}))},[]);if(!e)return null;let T=(w,_)=>m?.id===w.id?i(de,{children:[i("button",{type:"button",class:`snapshot-action-btn ${m.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>m.action==="delete"?P(w.id):L(w.id),title:m.action==="delete"?"Confirm delete":"Confirm restore",disabled:u!==null,children:m.action==="delete"?"Delete":u===w.id?"Restoring…":"Confirm"},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn",onClick:()=>h(null),title:"Cancel",disabled:u!==null,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):i(de,{children:[i("button",{type:"button",class:"snapshot-action-btn snapshot-action-restore",onClick:()=>h({id:w.id,action:"restore"}),title:"Restore this snapshot — replaces the current canvas (undoable)",disabled:u!==null,children:u===w.id?"Restoring…":_},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-action-btn snapshot-action-delete",onClick:()=>h({id:w.id,action:"delete"}),title:"Delete this snapshot","aria-label":"Delete snapshot",disabled:u!==null,children:"✕"},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:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-save-form",children:[i("input",{ref:y,type:"text",class:"snapshot-name-input",value:d,onInput:(w)=>f(w.target.value),onKeyDown:(w)=>{if(w.key==="Enter")E()},placeholder:"Save a snapshot as…","aria-label":"Snapshot name",maxLength:80,disabled:c},void 0,!1,void 0,this),i("button",{type:"button",class:"snapshot-save-btn",onClick:E,disabled:!d.trim()||c,children:c?"…":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-restore-note",children:"Restoring replaces the current canvas. You can undo it if needed."},void 0,!1,void 0,this),i("div",{class:"snapshot-list",children:[s&&i("div",{class:"snapshot-empty",children:"Loading…"},void 0,!1,void 0,this),!s&&o.length===0&&i("div",{class:"snapshot-empty",children:"No history yet. Save a snapshot, or start an agent session — it snapshots for you."},void 0,!1,void 0,this),!s&&[...o.filter((w)=>Lc(w.name)===null),...o.some((w)=>Lc(w.name)!==null)?[{id:"__sessions-header__"}]:[],...o.filter((w)=>Lc(w.name)!==null)].map((w)=>{if(w.id==="__sessions-header__")return i("div",{class:"snapshot-section-header","data-testid":"history-sessions-header",children:"Sessions"},w.id,!1,void 0,this);let _=Lc(w.name),z=v[w.id];if(_!==null)return i("div",{class:"snapshot-item is-session","data-testid":"history-session",children:[i("div",{class:"snapshot-item-head",children:[i("span",{class:"snapshot-session-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"snapshot-item-name",children:["Agent session — ",_]},void 0,!0,void 0,this),i("span",{class:"snapshot-item-time",children:v_(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:["snapshot at session start · ",w.nodeCount," node",w.nodeCount!==1?"s":"",z&&z!=="loading"&&i("span",{class:"snapshot-item-diff",children:[" ","· since: ",z.added," added · ",z.removed," removed · ",z.modified," modified"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-actions is-session",children:[i("button",{type:"button",class:"snapshot-action-btn snapshot-action-diff",disabled:z==="loading",onClick:()=>void b(w.id),children:z==="loading"?"Comparing…":"View diff"},void 0,!1,void 0,this),T(w,"Restore pre-state")]},void 0,!0,void 0,this)]},w.id,!0,void 0,this);return i("div",{class:"snapshot-item","data-testid":"history-snapshot",children:[i("div",{class:"snapshot-item-head",children:[i("span",{class:"snapshot-item-glyph","aria-hidden":"true",children:"◫"},void 0,!1,void 0,this),i("span",{class:"snapshot-item-name",children:w.name},void 0,!1,void 0,this),i("span",{class:"snapshot-item-time",children:v_(w.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-meta",children:[w.nodeCount," node",w.nodeCount!==1?"s":"",w.edgeCount>0?` · ${w.edgeCount} edge${w.edgeCount!==1?"s":""}`:""," · ",l1(w.createdAt)]},void 0,!0,void 0,this),i("div",{class:"snapshot-item-actions",children:T(w,"Restore")},void 0,!1,void 0,this)]},w.id,!0,void 0,this)})]},void 0,!0,void 0,this),i("div",{class:"snapshot-panel-foot",children:"Every agent session start writes a snapshot automatically."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var u1=8;function d1({children:e}){let t=Ie(()=>document.createElement("div"),[]);return Dn(()=>(document.body.appendChild(t),()=>{Vr(null,t),t.remove()}),[t]),Dn(()=>Vr(e,t),[e,t]),null}function b_({fallbackName:e}){let[t,n]=I(!1),o=R(null),r=R(null),s=R(null);Dn(()=>{if(!t)return;let d=(m)=>{if(m.target instanceof Node&&!o.current?.contains(m.target)&&!s.current?.contains(m.target))n(!1)},f=(m)=>{if(m.key==="Escape")m.stopPropagation(),n(!1),r.current?.focus()};return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",f,!0),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",f,!0)}},[t]);let a=va(),c=!fr.value?e:a?a.name:"Home",l=Et.value.filter((d)=>d.id!==Pe.value).slice(0,u1),u=r.current?.getBoundingClientRect(),p=(d)=>{n(!1),At(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:"▾"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t&&u&&i(d1,{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(gc,{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),mp()},children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:"+"},void 0,!1,void 0,this),"New board…"]},void 0,!0,void 0,this),i("button",{type:"button",role:"menuitem",class:"toolbar-menu-item",onClick:()=>p(null),children:[i("span",{class:"board-switcher-icon","aria-hidden":"true",children:i(En,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this),"All boards (Home)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var x_=3,w_={"waiting-approval":0,thinking:1,tooling:2,idle:3};function p1(){let e=Gx.value;if(e.length===0)return null;let t=e.filter((c)=>!c.parentAgentId||!e.some((l)=>l.sessionId!==c.sessionId&&(l.sessionId===c.parentAgentId||l.source===c.parentAgentId))),n=[...t].sort((c,l)=>(w_[c.phase]??4)-(w_[l.phase]??4)),o=n.slice(0,x_),r=n.slice(x_),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(de,{children:[i("span",{class:"agent-chips",children:o.map((c)=>{let l=gt.value.filter((u)=>u.parentAgentId!=null&&(u.parentAgentId===c.sessionId||u.parentAgentId===c.source)).length;return i(Ge,{label:`Agent session — ${c.label}`,tapToOpen:!0,body:"What this attached agent is doing right now: idle, thinking, running a tool, or waiting on your approval. Steer it from the composer below.",children:i("span",{class:`agent-chip phase-${c.phase}`,"data-phase":c.phase,style:{"--identity-color":`hsl(${ro(c.sessionId)} 65% 62%)`},children:[i("span",{class:"agent-chip-dot","aria-hidden":"true"},void 0,!1,void 0,this),i("span",{class:"agent-chip-label",children:oo(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(),_c({source:c.source,agentId:c.agentId})},children:"×"},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(Ge,{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 m1(){let e=Bo.value.length,t=Lr.value!==null&&e>0,n=zn(t?1000:0);if(!t)return null;let o=Bo.value.map((r)=>Mc(r,n)).filter((r)=>r!==null).sort((r,s)=>r-s)[0];return i(Ge,{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&&` · ${Oc(o)}`]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function f1(e){if(e>0.9)return"danger";if(e>=0.7)return"warn";return"ok"}function ji(e){return e>=1000?`${(e/1000).toFixed(e>=1e4?0:1)}k`:String(e)}function h1(){let e=Lr.value;if(!e)return null;let t=Wd.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:`${ji(n.used)} of ${ji(n.total)} tokens of the agent's actual context window are used. Your ✦-pinned nodes account for ≈ ${ji(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: ≈ ${ji(t.used)} of a ${ji(t.total)}-token budget. When the agent's host reports its real context window, this meter switches to showing that instead.`};return i(Ge,{label:c.label,body:c.body,tapToOpen:!0,children:i("span",{class:`context-budget tone-${f1(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 g1(){let[e,t]=I(!1);if(Lr.value)return null;return i(Ge,{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),co().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 __(){let e=Mt.value,t=Tt.value,n=J.value,o=F.value.size,r=Le.value.size,s=lr.value,a=Array.from(F.value.values()).filter((m)=>m.type==="trace").length,[c,l]=I("");B(()=>{let m=!1;return fetch("/health").then((h)=>h.ok?h.json():null).then((h)=>{if(m||typeof h?.workspace!=="string"||!h.workspace)return;let v=h.workspace.replace(/[\\/]+$/,"").split(/[\\/]/).pop();if(v)l(v)}).catch(()=>{}),()=>{m=!0}},[]);let u=sp.value,p=u??(e==="connected"&&!t?"syncing":e),d=t?[`${o} node${o!==1?"s":""}`,...r>0?[`${r} edge${r!==1?"s":""}`]:[],...a>0?[`${a} trace${a!==1?"s":""}`]:s?["trace armed"]:[]].join(" · "):"Syncing canvas…",f=()=>{let m=ot();mr(m.width,m.height)};return i("div",{class:"top-bar",children:[i(Ge,{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(b_,{fallbackName:c||"PMX Canvas"},void 0,!1,void 0,this),i("span",{class:"top-bar-meta hud-collapsible-text",children:xn.value?xn.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(p1,{},void 0,!1,void 0,this),i(m1,{},void 0,!1,void 0,this),i(h1,{},void 0,!1,void 0,this),i(Qw,{},void 0,!1,void 0,this),i(g1,{},void 0,!1,void 0,this),i("div",{class:"top-bar-sep"},void 0,!1,void 0,this),Pe.value&&i(Ge,{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:()=>{Zr.value=!0},children:"Export"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Pe.value&&i(Ge,{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:()=>{nn.value=!0},children:"Present"},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Ge,{label:"Zoom out",shortcut:qe("−"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>pr(0.8),"aria-label":"Zoom out",children:i(Ix,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Ge,{label:"Reset zoom",shortcut:qe("0"),children:i("button",{type:"button",class:"top-bar-zoom-label",onClick:()=>Xn({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(Ge,{label:"Zoom in",shortcut:qe("+"),children:i("button",{type:"button",class:"top-bar-btn",onClick:()=>pr(1.25),"aria-label":"Zoom in",children:i(Tx,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),i(Ge,{label:"Fit all",shortcut:"F",align:"end",children:i("button",{type:"button",class:"top-bar-btn",onClick:f,"aria-label":"Fit canvas",children:i(mc,{},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 lo={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 Zi(e,t,n,o={}){let r=lo[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 Uo=null,Wi=null,Dc=0,uo=null,v1=3000,y1=2000,S_=5000,Ui=!1,Nn=null,Ur=null,mo=0,po=null;function b1(){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 qr=new Map;function Vi(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 Bc(e){if(!Wi)return e;let t=Wi.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 Gi(e,t,n){return Bc(Zi(e,t,n))}function x1(){return Fa([...F.value.values()],lo.markdown.w,lo.markdown.h)}function Wr(){if(!F.value.has("status-main"))_n(Gi("status-main","status",{phase:"idle",message:"",elapsed:0}))}function w1(e,t){let n=`md-${Vi(e)}`;if(F.value.get(n))ie(n,{path:e,title:t}),Ce.value=n;else{let r=x1(),s=Gi(n,"markdown",{path:e,title:t,content:"",rendered:""});s.position=r,_n(s),Ke(n)}}function _1(e){if(F.value.get("context-main"))ie("context-main",{cards:e});else if(e.length>0){let o=Gi("context-main","context",{cards:e});_n(o)}}function S1(e){let t=e.url,n=`mcp-${Vi(t)}`;if(F.value.get(n))ie(n,e);else _n(Gi(n,"mcp-app",e)),Ke(n)}function k1(e){let t=e.toolCallId,o=(typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null)??(t.startsWith("ext-app-")?t:`ext-app-${t}`);if(F.value.get(o)){ie(o,e);return}let{serverName:s,toolName:a}=e;if(s&&a){for(let[x,g]of F.value.entries())if(g.type==="mcp-app"&&g.data.mode==="ext-app"&&g.data.serverName===s&&g.data.toolName===a&&!g.data.toolResult){ie(x,{...e});return}}let{_x:c,_y:l,_width:u,_height:p}=e,d=lo["mcp-app"],f=u??d.w,m=p??d.h,h=c===void 0||l===void 0?Fa([...F.value.values()],f,m):null,v=Bc(Zi(o,"mcp-app",{mode:"ext-app",...e},{position:{x:c??h?.x??d.x,y:l??h?.y??d.y},size:{width:f,height:m}}));_n(v),Ke(o,{recordHistory:!1})}function C1(e){let t=e.startsWith("ext-app-")?e:`ext-app-${e}`;if(F.value.has(t))return t;let n=`ext-app-${e}`;if(n!==t&&F.value.has(n))return n;for(let[o,r]of F.value.entries())if(r.type==="mcp-app"&&r.data.mode==="ext-app"&&r.data.toolCallId===e)return o;return null}function E_(e){let t=typeof e.nodeId==="string"&&e.nodeId.length>0?e.nodeId:null;if(t&&F.value.has(t))return t;if(typeof e.toolCallId!=="string"||!e.toolCallId)return null;return C1(e.toolCallId)}function A_(e,t){if(typeof e!=="string"||!e)return null;if(typeof t!=="string"||!t)return null;let n=null;for(let[o,r]of F.value.entries())if(r.type==="mcp-app"&&r.data.mode==="ext-app"&&r.data.serverName===e&&r.data.toolName===t&&!r.data.toolResult){if(n)return null;n=o}return n}function z_(e){if(F.value.get("ledger-main"))ie("ledger-main",e);else{let o=Gi("ledger-main","ledger",e);o.collapsed=!0,_n(o)}}function xp(e){if(!Ti(e))return;if(document.documentElement.setAttribute("data-theme",e),Pr(),et.value!==e)et.value=e}function T1(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 I1(e){return e==="relation"||e==="depends-on"||e==="flow"||e==="references"}function wp(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 P_(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 E1(e){let t=wp(e),n=P_(e);return t&&n?{...t,...n}:null}function A1(e){if(typeof e.id!=="string"||!e.id)return null;if(!T1(e.type))return null;let t=wp(e.position),n=P_(e.size);if(!t||!n)return null;let o=e.data&&typeof e.data==="object"?Object.fromEntries(Object.entries(e.data)):{};return{id:e.id,type:e.type,position:t,size:n,zIndex:typeof e.zIndex==="number"?e.zIndex:1,collapsed:e.collapsed===!0,pinned:e.pinned===!0,data:o}}function z1(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(!I1(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 P1(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)=>wp(o)).filter((o)=>o!==null),n=E1(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 k_="pmx-canvas-version-reload";function N1(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(k_)===r)return;window.sessionStorage.setItem(k_,r)}catch{return}window.location.reload()}function R1(e){let t=io.value[0]?.id;if(Xd(e),vt.value&&io.value[0]?.id!==t)ao()}function $1(e){cw(e)}var C_=null,qi=0,vp=0,yp=0;function M1(e){Gu(e)}function O1(){let e=++qi;Wi=null,Tt.value=!1,Na(),Vv(),qs(),kc(),tn.value=null,_p();let t=vp,n=yp;Iv().then((o)=>{if(e===qi&&t===vp)N_({layout:o})}),Y("fetchPinnedContext","/api/canvas/pinned-context",{}).then((o)=>{if(e===qi&&n===yp)R_({nodeIds:o.nodeIds})})}Ty(O1);function L1(e){if(xn.value=e.sessionId||"",Mt.value="connected",Su(),Eo.value+=1,N1(e.version,e.bundleStamp),mi(),Pv().then(Xd),C_?.(),!Ws)C_=Ib();if(Y("fetchHumanPresence","/api/canvas/human-presence",null).then(Gu),_p().then(()=>{if(vt.value)ao()}),typeof e.theme==="string"&&!ap())xp(e.theme);if(e.ledgerSummary)z_(e.ledgerSummary)}function D1(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(w1(t,n),e.ledgerSummary)z_(e.ledgerSummary)}function F1(e){Wr(),ie("status-main",{message:typeof e.message==="string"?e.message:String(e.message??""),level:e.level??"ok",source:e.source})}function B1(e){Wr(),ie("status-main",{phase:e.phase,detail:e.detail})}function H1(e){let t=e.cards??[];_1(t)}function j1(e){if(typeof e.url==="string"&&e.url)S1({url:e.url,sourceServer:e.sourceServer,sourceTool:e.sourceTool,inferredType:e.inferredType,trustedDomain:e.trustedDomain,hostMode:e.hostMode??"hosted"})}function Z1(e){let t=e.sessions??[];for(let n of t){let o=n.url;if(!o)continue;let r=`mcp-${Vi(o)}`;if(F.value.has(r))ie(r,{sessionState:n.state,lastSeenAt:n.lastSeenAt})}}function U1(e){if(typeof e.url==="string"&&e.url){let t=`mcp-${Vi(e.url)}`;if(F.value.has(t))ie(t,{hostMode:"fallback",fallbackReason:e.reasonCode})}}function q1(e){let n=F.value.get("context-main");if(!n)return;let o=(n.data.auxTabs??[]).concat(e);ie("context-main",{auxTabs:o})}function W1(e){if(F.value.has("context-main"))if(e.mode==="all")ie("context-main",{auxTabs:[]});else{let o=F.value.get("context-main");if(!o)return;let r=(o.data.auxTabs??[]).filter((s)=>s.id!==e.id);ie("context-main",{auxTabs:r})}}function V1(e){Wr(),ie("status-main",{phase:"idle",lastCompletion:{tokenCount:e.tokenCount,artifactCount:e.artifactCount}})}function G1(e){Wr(),ie("status-main",{phase:"tooling",detail:`${e.name}`,activeTool:e.name})}function X1(e){Wr(),ie("status-main",{activeTool:null})}function K1(e){if(e.state==="active"&&e.path){let n=`md-${Vi(e.path)}`;if(F.value.has(n))ie(n,{reviewActive:!0})}}function J1(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;k1({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 Y1(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=E_(e)??A_(e.serverName,e.toolName);if(!t)return;if(F.value.has(t))ie(t,{html:e.html})}function Q1(e){if(typeof e.toolCallId!=="string"||!e.toolCallId)return;let t=E_(e)??A_(e.serverName,e.toolName);if(!t)return;if(F.value.has(t)){if(e.success===!1){Gn(t);return}ie(t,{toolResult:Ad({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){Wr(),ie("status-main",{subagent:{state:e.state,name:e.agentDisplayName??e.agentName}})}function tz(e){let t=e.nodeId;if(!t)return;let n=e.text||"",{position:o,parentNodeId:r,contextNodeIds:s}=e;if(e.threadNodeId&&F.value.has(e.threadNodeId)){let a=e.threadNodeId,c=F.value.get(a);if(!c)return;let l=Array.isArray(c.data.turns)?[...c.data.turns]:[],u=l[l.length-1];if(!u||u.role!=="user"||u.text!==n)l.push({role:"user",text:n,status:"pending"});ie(a,{turns:l,threadStatus:"pending"});return}if(!F.value.has(t)){let a=o??lo.prompt;_n(Bc(Zi(t,"prompt",{text:n,turns:n?[{role:"user",text:n,status:"pending"}]:[],threadStatus:n?"pending":"draft",status:n?"pending":"draft",parentNodeId:r,contextNodeIds:s},{position:{x:a.x,y:a.y}}))),Ke(t)}if(r&&F.value.has(r))sa({id:`edge-${r}-${t}`,from:r,to:t,type:"flow",style:"dashed"})}function nz(e){let{nodeId:t,status:n}=e;if(t&&F.value.has(t))ie(t,{status:n})}function oz(e){let{responseNodeId:t,promptNodeId:n}=e;if(!t)return;let o=n?F.value.get(n):void 0;if(o&&Array.isArray(o.data.turns)){qr.set(t,n);let s=[...o.data.turns];s.push({role:"assistant",text:"",status:"streaming"}),ie(n,{turns:s,threadStatus:"streaming",_activeResponseId:t}),Ke(n);return}let r=o?{x:o.position.x,y:o.position.y+o.size.height+24}:{x:lo.response.x,y:lo.response.y};if(!F.value.has(t))_n(Bc(Zi(t,"response",{content:"",status:"streaming",promptNodeId:n},{position:r})));if(n)sa({id:`edge-${n}-${t}`,from:n,to:t,type:"flow",animated:!0});Ke(t)}function rz(e){let t=e.responseNodeId;if(!t)return;let n=qr.get(t);if(n){let o=F.value.get(n);if(o&&Array.isArray(o.data.turns)){let r=[...o.data.turns],s=r[r.length-1];if(s&&s.role==="assistant")s.text=e.content,s.status="streaming";ie(n,{turns:r,threadStatus:"streaming"})}return}if(!F.value.has(t))return;ie(t,{content:e.content,status:"streaming"})}function iz(e){let t=e.responseNodeId;if(!t)return;let n=qr.get(t);if(n){let s=F.value.get(n);if(s&&Array.isArray(s.data.turns)){let a=[...s.data.turns],c=a[a.length-1];if(c&&c.role==="assistant")c.text=e.content,c.status="complete";ie(n,{turns:a,threadStatus:"answered",_activeResponseId:void 0})}qr.delete(t);return}if(!F.value.has(t))return;ie(t,{content:e.content,status:"complete"});let r=F.value.get(t)?.data.promptNodeId;if(r){let s=`edge-${r}-${t}`,a=Le.value.get(s);if(a)ny(s),sa({...a,animated:!1})}}function N_(e){let t=e.layout;if(!t?.nodes)return;vp+=1;let n=!Tt.value;Tt.value=!0;let o=t.nodes.map(A1).filter((c)=>c!==null),r=Array.isArray(t.edges)?t.edges.map(z1).filter((c)=>c!==null):Array.from(Le.value.values()),s=Array.isArray(t.annotations)?t.annotations.map(P1).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)kn();cy({...a?{viewport:a}:{},nodes:o,edges:r,...s?{annotations:s}:{}},{applyViewport:n}),cu({event:"canvas-layout-update",data:e})}function sz(e){if(e<=1)return 500;if(e===2)return 1000;return Math.min(2500,1500+(e-3)*500)}function az(e){if(_u())return;let t=e.nodeId;if(t&&F.value.has(t)){if(e.noPan===!0){Sn(t);return}Ke(t)}}function cz(e){if(_u())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;kn(),iy({x:n,y:o,scale:r})}function lz(e){if(F.value.get("context-main"))ie("context-main",{currentTokens:e.currentTokens,tokenLimit:e.tokenLimit,messagesLength:e.messagesLength,utilization:e.utilization,nearLimit:e.nearLimit})}function uz(e){lr.value=e.enabled===!0}function dz(e){if(typeof e.theme==="string"&&!ap())xp(e.theme)}function R_(e){yp+=1;let t=Array.isArray(e.nodeIds)?e.nodeIds.filter((n)=>typeof n==="string"):[];ty(t),cu({event:"context-pins-changed",data:e})}var Fc=null,bp=0;async function _p(){let e=++bp,t=qi,n=await zv();if(e===bp&&t===qi)tn.value=n}function T_(){if(Fc)clearTimeout(Fc);bp+=1,Fc=setTimeout(()=>{if(Fc=null,_p(),vt.value)ao()},150)}function pz(e){let t=e.intent;if(!t||typeof t.id!=="string"||typeof t.kind!=="string"||typeof t.expiresAt!=="number")return;bb(t)}function mz(e){let t=typeof e.id==="string"?e.id:"";if(!t)return;if(e.settled===!0)wb(t,typeof e.nodeId==="string"?e.nodeId:void 0);else Vu(t)}var $_={connected:L1,"workbench-open":D1,"canvas-status":F1,"execution-phase":B1,"context-cards":H1,"mcp-app-candidate":j1,"mcp-app-host-snapshot":Z1,"mcp-app-host-fallback":U1,"aux-open":q1,"aux-close":W1,"assistant-complete":V1,"tool-start":G1,"tool-complete":X1,"review-state":K1,"subagent-status":ez,"ext-app-open":J1,"ext-app-update":Y1,"ext-app-result":Q1,"context-pins-changed":R_,"boards-changed":No,"canvas-layout-update":N_,"canvas-focus-node":az,"canvas-viewport-update":cz,"context-usage":lz,"trace-state":uz,"theme-changed":dz,"canvas-prompt-created":tz,"canvas-prompt-status":nz,"canvas-response-start":oz,"canvas-response-delta":rz,"canvas-response-complete":iz,"ax-state-changed":T_,"ax-event-created":T_,"ax-intent":pz,"ax-intent-clear":mz,"agent-presence":R1,"human-presence":M1,"agent-session-ended":$1};function M_(e,t){let n=$_[e];if(!n)return;let o=n;try{o(t)}catch(r){console.warn(`[sse-bridge] Handler for "${e}" failed:`,r)}}function I_(){Ui=!0,mo+=1;let e=mo;Mt.value="connecting";let t=null,n=!1,o=async()=>{if(e!==mo)return;try{let r=new URLSearchParams;if(Ur!==null)r.set("since",String(Ur));let s=xn.value;if(s)r.set("session",s);let a=r.toString(),c=await fetch(`/api/workbench/poll${a?`?${a}`:""}`);if(e!==mo)return;if(!c.ok)throw Error(`poll failed with HTTP ${c.status}`);let l=await c.json();if(e!==mo)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){Ur=null,Nn=setTimeout(()=>void o(),0);return}if(l.snapshot&&n)Wi=wu(),Tt.value=!1,qs(),Na(),qr.clear();for(let p of l.events)M_(p.event,p.payload);n=!0,Ur=l.seq,Ao.value=0,zo.value=0,Mt.value="connected",Nn=setTimeout(()=>void o(),y1)}catch(r){if(e!==mo)return;console.warn("[sse-bridge] poll transport error:",r),Mt.value="disconnected",Ao.value+=1,zo.value=S_,Nn=setTimeout(()=>void o(),S_)}};return o(),()=>{if(mo+=1,Ui=!1,Ur=null,Nn)clearTimeout(Nn),Nn=null}}function Sp(){if(Mw(xp),Wi=wu(),Tt.value=!1,qs(),Na(),qr.clear(),uo)clearTimeout(uo),uo=null;let e=b1();if(e==="poll"||Ui)return I_();let t=xn.value,n=t?`/api/workbench/events?session=${t}`:"/api/workbench/events";Mt.value="connecting";let o=new EventSource(n);Uo=o;let r=!1;if(po)clearTimeout(po);if(po=null,e!=="sse")po=setTimeout(()=>{if(po=null,r||Uo!==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(),Uo=null,I_()},v1);for(let[s]of Object.entries($_))o.addEventListener(s,(a)=>{r=!0;try{M_(s,JSON.parse(a.data))}catch(c){console.warn(`[sse-bridge] Failed to parse "${s}" event:`,c)}});return o.onopen=()=>{if(Uo!==o)return;Dc=0,Ao.value=0,zo.value=0,Mt.value="connected"},o.onerror=()=>{if(Uo!==o)return;Mt.value="disconnected",o.close(),Uo=null,Dc+=1;let s=sz(Dc);Ao.value=Dc,zo.value=s,uo=setTimeout(()=>{uo=null,Sp()},s)},()=>{if(uo)clearTimeout(uo),uo=null;if(po)clearTimeout(po),po=null;if(Ui){if(mo+=1,Ui=!1,Ur=null,Nn)clearTimeout(Nn),Nn=null}o.close(),Uo=null}}function qo(e,t){console.error(`[app] ${e} failed`,t)}function O_(){let[e,t]=I(!0),[n,o]=I(!1),[r,s]=I(!1),[a,c]=I(!1),[l,u]=I(!1),[p,d]=I(null),f=R(null),{menu:m,openNodeMenu:h,openCanvasMenu:v,openEdgeMenu:x,closeMenu:g}=Dw(),y=Tt.value,E=fr.value&&Pe.value===null,L=vt.value,P=H(()=>t((N)=>!N),[]),b=H(()=>o((N)=>!N),[]),T=H(()=>o(!1),[]),w=H((N)=>d(N),[]),_=H((N,Z)=>{Xn({x:N,y:Z,scale:J.value.scale},200)},[]);B(()=>Sp(),[]),B(()=>{let N=()=>c(!0);return window.addEventListener("pmx-open-board-link",N),()=>window.removeEventListener("pmx-open-board-link",N)},[]),B(()=>{let N=null,Z=()=>{if(N!==null)window.clearTimeout(N);N=window.setTimeout(()=>{N=null,mi()},400)};return window.addEventListener("resize",Z),()=>{if(N!==null)window.clearTimeout(N);window.removeEventListener("resize",Z)}},[]),B(()=>{let N=(S)=>{let V=(S.metaKey||S.ctrlKey)&&!S.altKey;if(V&&S.key==="k"){S.preventDefault(),s((se)=>!se);return}if(S.key==="Escape"&&p){S.preventDefault(),d(null);return}if(S.key==="Escape"&&Ue.value&&!en.value){S.preventDefault(),Cn();return}if(S.key==="Escape"&&r){S.preventDefault(),s(!1);return}if(S.key==="Escape"&&l){S.preventDefault(),u(!1);return}let he=S.target,je=he?.tagName;if(je==="INPUT"||je==="TEXTAREA"||he?.isContentEditable)return;if(S.key===" "&&!S.repeat&&!V){S.preventDefault(),gi.value=!0;return}if(S.key==="?"||S.key==="/"&&S.shiftKey){S.preventDefault(),u((se)=>!se);return}if(V&&(S.key==="z"||S.key==="Z"))S.preventDefault(),tp(S.shiftKey);else if(V&&(S.key==="y"||S.key==="Y"))S.preventDefault(),tp(!0);else if(V&&S.key==="0")S.preventDefault(),Xn({x:0,y:0,scale:1},250);else if(V&&(S.key==="="||S.key==="+"))S.preventDefault(),pr(1.25);else if(V&&S.key==="-")S.preventDefault(),pr(0.8);else if(S.key==="Escape"){if(ye.value.size>0||dn.value!==null){xt();return}Ce.value=null,g()}else if(S.key==="Tab")S.preventDefault(),uy(S.shiftKey?-1:1);else if(S.key==="Delete"||S.key==="Backspace"){if(dn.value!==null){let ue=dn.value;S.preventDefault(),dn.value=null,ea(ue).catch((pe)=>qo("delete-edge",pe));return}let se=ye.value.size>0?[...ye.value]:Ce.value?[Ce.value]:[];if(se.length===0)return;S.preventDefault();for(let ue of se)qn(ue).catch((pe)=>qo("delete",pe));xt(),Ce.value=null}else if(Ce.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(S.key)){S.preventDefault();let se=S.key.replace("Arrow","").toLowerCase();dy(se)}else if(!V&&!S.altKey){let se=S.key.toLowerCase();if(se==="v"&&!S.shiftKey)It.value="select";else if(se==="c"&&!S.shiftKey&&!V)S.preventDefault(),It.value=It.value==="connect"?"select":"connect";else if(se==="m"&&!S.shiftKey)S.preventDefault(),Dt({type:"markdown",title:"New note",width:520,height:360}).catch((ue)=>qo("create markdown",ue));else if(se==="a"&&!S.shiftKey)S.preventDefault(),d((ue)=>ue==="pen"?null:"pen");else if(se==="g"&&!S.shiftKey){S.preventDefault();let ue=Array.from(ye.value);if(ue.length>=2)sr({title:"Group",childIds:ue}).catch((pe)=>qo("group selection",pe)),xt();else Dt({type:"group",title:"Group"}).catch((pe)=>qo("create group",pe))}else if(se==="g"&&S.shiftKey){S.preventDefault();for(let ue of Jv())Gn(ue),ar(ue).catch((pe)=>qo("ungroup",pe));xt()}else if(se==="i"&&!S.shiftKey)S.preventDefault(),Pn("image");else if(se==="w"&&!S.shiftKey)S.preventDefault(),Pn("webpage");else if(se==="h"&&!S.shiftKey)S.preventDefault(),Dt({type:"html",title:"HTML surface"}).catch((ue)=>qo("create html",ue));else if(se==="f"&&S.shiftKey)S.preventDefault(),Pn("file");else if(se==="f"&&!S.shiftKey){S.preventDefault();let ue=ot();mr(ue.width,ue.height)}}},Z=(S)=>{if(S.key===" ")gi.value=!1},j=()=>{gi.value=!1};return document.addEventListener("keydown",N),document.addEventListener("keyup",Z),window.addEventListener("blur",j),()=>{document.removeEventListener("keydown",N),document.removeEventListener("keyup",Z),window.removeEventListener("blur",j)}},[p,g,r,l]),B(()=>{let N=window.setTimeout(()=>void mi(),250);return()=>window.clearTimeout(N)},[L]),B(()=>{if(!y)return;let N=window.__pmxCanvasBootstrapReady;if(typeof N==="function")N()},[y]);let z=Array.from(F.value.values()),U=ot();return i("div",{class:`app-shell${nn.value?" is-presenting":""}`,"data-session-active":L?"true":"false",children:[i(fy,{},void 0,!1,void 0,this),i(Zw,{minimapVisible:e,onToggleMinimap:P,snapshotOpen:n,onToggleSnapshot:b,snapshotBtnRef:f,onOpenPalette:()=>s(!0),onOpenShortcuts:()=>u((N)=>!N),annotationTool:p,onSetAnnotationTool:w},void 0,!1,void 0,this),i("div",{class:"app-main",children:[i(__,{},void 0,!1,void 0,this),i(Nw,{},void 0,!1,void 0,this),i("div",{class:"canvas-region",ref:(N)=>Qg(N),children:[i(zw,{onNodeContextMenu:h,onCanvasContextMenu:v,onEdgeContextMenu:x,annotationMode:p!==null,annotationTool:p},void 0,!1,void 0,this),i(gy,{},void 0,!1,void 0,this),i(hy,{},void 0,!1,void 0,this),i(e_,{},void 0,!1,void 0,this),i(t_,{},void 0,!1,void 0,this),E?i(Jw,{},void 0,!1,void 0,this):y&&z.length===0&&Ve.value.size===0&&i(Uw,{onOpenPalette:()=>s(!0)},void 0,!1,void 0,this),ye.value.size>0&&i(u_,{},void 0,!1,void 0,this),L?i(Pw,{},void 0,!1,void 0,this):Ae.value.size>0&&i(Hw,{},void 0,!1,void 0,this),i(f_,{onOpenSnapshots:()=>o(!0)},void 0,!1,void 0,this),i(yy,{},void 0,!1,void 0,this),i(Yw,{},void 0,!1,void 0,this),Ue.value&&i(i_,{},void 0,!1,void 0,this),i(y_,{open:n,onClose:T,anchorRef:f},void 0,!1,void 0,this),e&&!E&&i(l_,{viewport:J,nodes:F,edges:Le,onNavigate:_,containerWidth:U.width,containerHeight:U.height},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L&&i(m_,{},void 0,!1,void 0,this),m&&i(Fw,{menu:m,onClose:g},void 0,!1,void 0,this),r&&i(Ow,{onClose:()=>s(!1),onToggleMinimap:P},void 0,!1,void 0,this),a&&i(Lw,{onClose:()=>c(!1)},void 0,!1,void 0,this),l&&i(h_,{onClose:()=>u(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}Sy();var L_=document.getElementById("app");if(L_)Vr(i(O_,{},void 0,!1,void 0,this),L_);