pmx-canvas 0.2.2 → 0.2.4

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.
@@ -222,5 +222,5 @@ container holding the app. Specify either width or maxWidth, and either height o
222
222
  try { window.dispatchEvent(new CustomEvent('pmx-ax-ack', { detail: { result: result, interaction: m.interaction || null } })); } catch (e) {}
223
223
  });
224
224
  })();
225
- </script>`}function HA($,v){if(!v)return $;let g=/<head\b[^>]*>/i.exec($);if(g?.index!==void 0){let U=g.index+g[0].length;return`${$.slice(0,U)}${v}${$.slice(U)}`}let _=/<body\b[^>]*>/i.exec($);if(_?.index!==void 0){let U=_.index+_[0].length;return`${$.slice(0,U)}${v}${$.slice(U)}`}return`${v}${$}`}function zU($,v){if(Number.isFinite($)&&$>0)return Math.round($);if(Number.isFinite(v)&&v>0)return Math.round(v);return 1}function aO($,v){let g=$?.getBoundingClientRect();return{width:zU($?.clientWidth??0,zU(g?.width??0,v.width)),height:zU($?.clientHeight??0,zU(g?.height??0,v.height))}}function LA($,v){return typeof $==="number"&&Number.isFinite($)&&$>0&&!v}function YA($,v){return Math.max(zU($,1),zU(v,1))}function AW({node:$,expanded:v=!1}){let g=V(null),_=V(null),U=V(null),z=V(null),b=V({}),J=V(void 0),G=V(!1),K=V(void 0),W=V(null),B=V(!1),P=V(null),[k,A]=x("loading"),[L,I]=x(null),[Y,F]=x(0),X=$.data.html,Q=$.data.serverName,u=$.data.appSessionId,c=$.data.toolInput??{},N=$.data.toolResult,t=$.data.toolName??"ext-app",a=$.data.toolDefinition,r=$.data.toolCallId,y=typeof r==="string"||typeof r==="number"?r:void 0,v$=$.data.resourceMeta,p=$.data.sessionStatus,i=$.data.sessionError,Y$=$.size.height,_$=$.id,x$=BA($,Y),S=PA(null),$$=$.data.axCapabilities?.enabled===!0&&typeof X==="string"&&X.length>0,s=o$(()=>`ax-${crypto.randomUUID()}`,[]),K$=$$?IA(s,_$):"",J$=YW(HA(X??"",K$),S);m(()=>{if(!$$)return;function o(z$){if(z$.source!==g.current?.contentWindow)return;let B$=z$.data;if(!B$||B$.source!=="pmx-canvas-ax"||B$.token!==s||B$.nodeId!==_$)return;let P$=B$.interaction;if(!P$||typeof P$.type!=="string")return;let R$=P$.type;k6({type:R$,sourceNodeId:_$,sourceSurface:"mcp-app",...P$.payload&&typeof P$.payload==="object"?{payload:P$.payload}:{}}).then((Ov)=>{if(Ov.ok)Nv("context","AX interaction",R$,[_$]);else Nv("remove","AX interaction rejected",Ov.error??Ov.code??"",[_$]);g.current?.contentWindow?.postMessage({source:"pmx-canvas-ax-ack",token:s,...B$.correlationId?{correlationId:B$.correlationId}:{},interaction:{type:R$},result:Ov},"*")})}return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[$$,s,_$]);let e=(o)=>o==="light"?"light":"dark",f=v||c$.value===_$;b.current=c,J.current=N;let d=p==="error"?i??"Saved app session is unavailable. Reopen the app to restore interactivity.":"Reconnecting saved app session...",W$=(o)=>{let z$=J.current;if(!o||!B.current||!z$)return null;if(K.current===z$)return null;if(K.current&&IW(K.current,z$))return K.current=z$,null;if(W.current)return W.current;let B$=o.sendToolResult(z$).then(()=>{K.current=z$,G.current=!0,A("done")}).catch((P$)=>{let R$=P$ instanceof Error?P$.message:String(P$);throw I(`Tool result delivery failed: ${R$}`),P$}).finally(()=>{W.current=null});return W.current=B$,B$};if(m(()=>{if(!X||!J$.ready)return;let o=g.current;if(!o)return;let z$=!1,B$=null,P$=null,R$=null,Ov=null;G.current=!1,K.current=void 0,W.current=null,B.current=!1;let C6=()=>{if(!B$)return;clearTimeout(B$),B$=null};return(async()=>{if(!X)return;let Dv=o.contentWindow;if(!Dv)throw Error("Ext-app iframe window is unavailable");let Fv=(A$=c$.value===_$?"fullscreen":"inline")=>({theme:e(V$.value),platform:"web",containerDimensions:aO(o,{width:$.size.width,height:Y$}),displayMode:A$,locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,...a?{toolInfo:{id:y,tool:a}}:{}}),U4=()=>{if(R$!==null)return;R$=requestAnimationFrame(()=>{if(R$=null,z$||!B.current)return;y$.setHostContext?.(Fv())})},Tg=()=>{if(Ov!==null)return;Ov=requestAnimationFrame(()=>{Ov=requestAnimationFrame(()=>{if(Ov=null,z$||!B.current)return;y$.sendHostContextChange?.(Fv())})})},y$=new oO(null,{name:"PMX Canvas",version:"1.0.0"},{openLinks:{},serverTools:{listChanged:!1},serverResources:{listChanged:!1},logging:{},updateModelContext:{text:{},structuredContent:{}}},{hostContext:Fv(f?"fullscreen":"inline")});y$.onsizechange=async({height:A$})=>{if(LA(A$,c$.value===_$)){let Gv=aO(o.parentElement??o,{width:$.size.width,height:Y$}),cv=YA(A$,Gv.height);o.style.height=`${cv}px`;let f6=T.value.get(_$)?.size??$.size,XG=Math.max(f6.height,cv+h3);if(Math.abs(XG-f6.height)>8){if(L4(_$,{width:f6.width,height:XG}),z.current!==null)window.clearTimeout(z.current);z.current=window.setTimeout(()=>{n$({recordHistory:!1}),z.current=null},0)}}return{}},y$.onopenlink=async({url:A$})=>{return window.open(A$,"_blank","noopener"),{}},y$.onsandboxready=async()=>{await y$.sendSandboxResourceReady({html:X,sandbox:dO,...v$?.csp?{csp:v$.csp}:{},...v$?.permissions?{permissions:v$.permissions}:{}})},y$.onrequestdisplaymode=async({mode:A$})=>{let{nextMode:Gv,shouldExpand:cv,shouldCollapse:f6}=kA(A$,f);if(cv)U6(_$);else if(f6)l6();return{mode:Gv}},y$.oncalltool=async(A$)=>{if(!u)throw Error(d);try{let Gv=await e6("/api/ext-app/call-tool",{sessionId:u,nodeId:_$,serverName:Q,toolName:A$.name,arguments:A$.arguments??{}});return I(null),Gv}catch(Gv){let cv=Gv instanceof Error?Gv.message:String(Gv);throw I(`Tool call failed: ${cv}`),Gv}},y$.setRequestHandler(qg,async()=>{if(!u)return{tools:[]};return e6("/api/ext-app/list-tools",{sessionId:u})}),y$.onlistresources=async()=>u?e6("/api/ext-app/list-resources",{sessionId:u}):{resources:[]},y$.onlistresourcetemplates=async()=>u?e6("/api/ext-app/list-resource-templates",{sessionId:u}):{resourceTemplates:[]},y$.onreadresource=async(A$)=>{if(!u)throw Error(d);return e6("/api/ext-app/read-resource",{sessionId:u,uri:A$.uri})},y$.onlistprompts=async()=>u?e6("/api/ext-app/list-prompts",{sessionId:u}):{prompts:[]},y$.onupdatemodelcontext=async(A$)=>{if(!u)return{};return await e6("/api/ext-app/model-context",{nodeId:_$,...Array.isArray(A$.content)?{content:A$.content}:{},...A$.structuredContent&&typeof A$.structuredContent==="object"?{structuredContent:A$.structuredContent}:{}}),{}};let c0=new X0(Dv,Dv);if(y$.oninitialized=()=>{if(z$)return;C6(),B.current=!0,A("ready"),I(null),Promise.resolve(y$.sendHostContextChange(Fv(f?"fullscreen":"inline"))).then(()=>FW(y$,b.current,void 0)).then(()=>W$(y$)).then(()=>Tg()).catch((A$)=>{let Gv=A$ instanceof Error?A$.message:String(A$);I(`Bridge bootstrap failed: ${Gv}`)})},B$=setTimeout(()=>{if(z$||B.current)return;let A$=J.current,Gv=Fv(f?"fullscreen":"inline");B.current=!0,y$.setHostContext?.(Gv),Promise.resolve(y$.sendHostContextChange(Gv)).then(()=>FW(y$,b.current,A$)).then(()=>{if(G.current=Boolean(A$),A$)K.current=A$;A(A$?"done":"ready"),I(null),Tg()}).catch((cv)=>{let f6=cv instanceof Error?cv.message:String(cv);I(`Bridge bootstrap fallback failed: ${f6}`)})},1200),await y$.connect(c0),z$){C6(),await c0.close();return}if(_.current=y$,U.current=c0,P$=new ResizeObserver(U4),P$.observe(o),o.parentElement)P$.observe(o.parentElement);let qG=!0;P.current=V$.subscribe((A$)=>{if(qG){qG=!1;return}if(z$)return;y$.setHostContext?.({...Fv(),theme:e(A$)}),y$.sendHostContextChange?.(Fv())}),W$(y$)})().catch((Dv)=>{C6(),console.error("[ext-app] Bridge init failed:",Dv),I(Dv?.message??"Bridge initialization failed")}),()=>{if(z$=!0,C6(),P$?.disconnect(),P$=null,R$!==null)cancelAnimationFrame(R$),R$=null;if(Ov!==null)cancelAnimationFrame(Ov),Ov=null;if(B.current=!1,W.current=null,P.current?.(),P.current=null,z.current!==null)window.clearTimeout(z.current),z.current=null;if(_.current=null,U.current)U.current.close().catch((Dv)=>{console.error("[ext-app] transport close failed:",Dv)}),U.current=null}},[x$,J$.key]),m(()=>{if(N&&_.current&&(k==="ready"||k==="done"))W$(_.current)},[N,k]),m(()=>{let o=_.current;if(g.current)g.current.style.height="100%";if(!o||!B.current)return;let z$=null,B$=null;return z$=requestAnimationFrame(()=>{z$=null,B$=requestAnimationFrame(()=>{if(B$=null,!B.current)return;let P$={theme:e(V$.value),platform:"web",containerDimensions:aO(g.current,{width:$.size.width,height:Y$}),displayMode:f?"fullscreen":"inline",locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};o.setHostContext?.(P$),o.sendHostContextChange?.(P$)})}),()=>{if(z$!==null)cancelAnimationFrame(z$);if(B$!==null)cancelAnimationFrame(B$)}},[f,Y$]),!X)return O("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--c-muted)",fontSize:"13px",flexDirection:"column",gap:"8px"},children:[O("div",{style:{opacity:0.6},children:["Loading ",t," viewer..."]},void 0,!0,void 0,this),O("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),O("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return O("div",{style:{flex:1,width:"100%",height:"100%",minWidth:0,minHeight:0,display:"flex",flexDirection:"column"},children:[p&&p!=="ready"&&O("div",{style:{padding:"6px 10px",fontSize:"11px",background:p==="error"?"var(--c-danger-12)":"var(--c-warn-10)",color:p==="error"?"var(--c-danger)":"var(--c-warn)",borderBottom:`1px solid ${p==="error"?"var(--c-danger-12)":"var(--c-warn-15)"}`},children:d},void 0,!1,void 0,this),L&&O("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:[O("span",{children:"⚠"},void 0,!1,void 0,this),O("span",{style:{flex:1},children:L},void 0,!1,void 0,this),O("button",{type:"button",onClick:()=>{I(null),A("loading"),F((o)=>o+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),O("button",{type:"button",onClick:()=>I(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),k==="loading"&&O("div",{style:{padding:"8px",fontSize:"11px",color:"var(--c-muted)"},children:"Connecting to ext-app viewer..."},void 0,!1,void 0,this),O("div",{style:{flex:1,position:"relative",display:"flex",minHeight:0,height:"100%"},children:[O("iframe",{ref:g,...J$.attributes,sandbox:S,allow:PW(v$?.permissions),style:{flex:1,width:"100%",height:"100%",minHeight:0,border:"none",background:"var(--c-panel)",pointerEvents:f?"auto":"none"},title:`Ext App: ${t}`},x$,!1,void 0,this),!f&&O("button",{type:"button",onClick:(o)=>{o.stopPropagation(),U6(_$)},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 w0($,v,g){let _=V($);_.current=$;let U=V(null);m(()=>{if(!g)return;function z(b){if(b.source!==v.current?.contentWindow)return;let J=b.data;if(!J||J.source!=="pmx-canvas-frame"||J.type!=="content-height"||J.token!==g)return;let G=_.current,K=typeof J.height==="number"?J.height:0,W=o3(G,K);if(W===null)return;if(L4(G.id,{width:G.size.width,height:W}),U.current!==null)window.clearTimeout(U.current);U.current=window.setTimeout(()=>{n$({recordHistory:!1}),U.current=null},300)}return window.addEventListener("message",z),()=>{if(window.removeEventListener("message",z),U.current!==null)window.clearTimeout(U.current),U.current=null}},[$.id,g])}function FA($,v,g,_,U,z,b){if(!$)return $;try{let J=new URL($,window.location.origin);if(J.searchParams.set("theme",V$.value==="light"?"light":"dark"),v)J.searchParams.set("display","expanded");if(typeof g==="number")J.searchParams.set("v",String(g));if(_)J.searchParams.set("axToken",_);if(U)J.searchParams.set("axNodeId",U);if(z)J.searchParams.set("frameToken",z);if(b)J.searchParams.set("fit","content");return J.toString()}catch{return $}}function AA($,v=window.location.origin){if(!$)return!1;try{let g=new URL(v).origin,_=new URL($,g);return _.origin===g&&_.pathname.startsWith("/api/canvas/frame-documents/")}catch{return!1}}function j6({node:$,expanded:v=!1}){if($.data.mode==="ext-app")return O(AW,{node:$,expanded:v},void 0,!1,void 0,this);return O(qA,{node:$,expanded:v},void 0,!1,void 0,this)}function qA({node:$,expanded:v}){let g=V(null),_=$.type==="mcp-app"&&$.data.viewerType==="web-artifact",U=$.type==="json-render"||$.type==="graph",z=$.data.axCapabilities?.enabled,J=(U||_)&&(_?z===!0:z!==!1),G=_?"mcp-app":"json-render",K=o$(()=>J?`ax-${crypto.randomUUID()}`:"",[J]),W=j2($)&&!v,B=o$(()=>W?`frame-${crypto.randomUUID()}`:"",[W]);w0($,g,B),m(()=>{if(!J||!K)return;function Q(u){if(u.source!==g.current?.contentWindow)return;let c=u.data;if(!c||c.source!=="pmx-canvas-ax"||c.token!==K||c.nodeId!==$.id)return;let N=c.interaction;if(!N||typeof N.type!=="string")return;let t=N.type;k6({type:t,sourceNodeId:$.id,sourceSurface:G,...N.payload&&typeof N.payload==="object"?{payload:N.payload}:{}}).then((a)=>{if(a.ok)Nv("context","AX interaction",t,[$.id]);else Nv("remove","AX interaction rejected",a.error??a.code??"",[$.id]);g.current?.contentWindow?.postMessage({source:"pmx-canvas-ax-ack",token:K,...c.correlationId?{correlationId:c.correlationId}:{},interaction:{type:t},result:a},"*")})}return window.addEventListener("message",Q),()=>window.removeEventListener("message",Q)},[J,K,$.id]);let P=I6.value,k=()=>{if(!J||!K||P==null)return;g.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"ax-update",token:K,state:P},"*")};m(k,[J,K,P]);let A=typeof $.data.specVersion==="number"?$.data.specVersion:void 0,L=FA($.data.url||"",v,A,K||void 0,J?$.id:void 0,B||void 0,W),I=$.data.sourceServer||"",Y=$.data.hostMode||"hosted",F=$.data.fallbackReason,X=$.data.trustedDomain===!0||AA(L);if(Y==="fallback")return O("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[O("div",{style:{color:"var(--c-warn)",display:"flex",alignItems:"center",gap:"6px"},children:[O("span",{children:"⚠"},void 0,!1,void 0,this),O("span",{children:"Cannot embed — opened externally"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F&&O("div",{style:{color:"var(--c-muted)",fontSize:"11px"},children:["Reason: ",F]},void 0,!0,void 0,this),O("a",{href:L,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all"},children:L},void 0,!1,void 0,this),I&&O("div",{style:{color:"var(--c-dim)",fontSize:"10px"},children:["Source: ",I]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return O("div",{style:{height:"100%",display:"flex",flexDirection:"column",...v?{flex:1,minHeight:0,width:"100%"}:{}},children:[!X&&O("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),O("iframe",{ref:g,src:L,class:"mcp-app-frame",sandbox:"allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox",allow:"clipboard-read; clipboard-write",loading:"lazy",onLoad:k,style:{flex:1,minHeight:0,width:"100%"},title:`MCP App: ${I}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Mg=null;function t$($){return getComputedStyle(document.documentElement).getPropertyValue($).trim()}function Z0(){if(Mg)return Mg;return Mg={bg:t$("--c-bg"),panel:t$("--c-panel"),panelSoft:t$("--c-panel-soft"),line:t$("--c-line"),text:t$("--c-text"),textSoft:t$("--c-text-soft"),muted:t$("--c-muted"),dim:t$("--c-dim"),accent:t$("--c-accent"),ok:t$("--c-ok"),warn:t$("--c-warn"),warnAlt:t$("--c-warn-alt"),danger:t$("--c-danger"),purple:t$("--c-purple"),thinking:t$("--c-thinking"),subagent:t$("--c-subagent"),font:t$("--font"),mono:t$("--mono")},Mg}function bU(){Mg=null}var S0={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 sO($){let v=typeof $.data.phase==="string"&&$.data.phase.trim().length>0?$.data.phase.trim():"";if(v)return v;let g=typeof $.data.content==="string"&&$.data.content.trim().length>0?$.data.content.trim():"";if(g)return g;return(typeof $.data.status==="string"&&$.data.status.trim().length>0?$.data.status.trim():"")||"idle"}function JU({node:$}){let v=sO($),g=$.data.detail||"",_=$.data.message||"",U=$.data.level||"ok",z=$.data.activeTool,b=$.data.subagent,J=S0[v]??"var(--c-muted)",G=v!=="idle";return O("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[O("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[O("div",{style:{width:"8px",height:"8px",borderRadius:"50%",background:J,boxShadow:G?`0 0 8px ${J}`:"none",animation:G?"pulse 1.5s infinite":"none",flexShrink:0}},void 0,!1,void 0,this),O("span",{style:{fontWeight:600,color:J,textTransform:"uppercase",letterSpacing:"0.05em"},children:v},void 0,!1,void 0,this),g&&O("span",{style:{color:"var(--c-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z&&O("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-warn)"},children:[O("span",{style:{fontSize:"10px"},children:"⚙"},void 0,!1,void 0,this),O("span",{style:{fontFamily:"var(--mono)",fontSize:"11px"},children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b&&b.state!=="completed"&&O("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-subagent)"},children:[O("span",{style:{fontSize:"10px"},children:"⠉"},void 0,!1,void 0,this),O("span",{children:b.name},void 0,!1,void 0,this),O("span",{style:{color:"var(--c-muted)",fontSize:"10px"},children:["(",b.state,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),_&&O("div",{style:{color:U==="warn"?"var(--c-warn)":U==="error"?"var(--c-danger)":"var(--c-muted)",lineHeight:1.4},children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function OU($){return typeof $==="string"&&$.trim().length>0?$.trim():null}function qW($){if(typeof $==="string"){let U=OU($);return U?{title:"Evidence warning",detail:U}:null}if(!$||typeof $!=="object")return null;let v=$,g=OU(v.title)??"Evidence warning",_=OU(v.detail);return _?{title:g,detail:_}:null}function XA($){let v=[],g=qW($.data.warning);if(g)v.push(g);let _=$.data.warnings;if(Array.isArray(_))for(let z of _){let b=qW(z);if(b)v.push(b)}let U=OU($.data.validationStatus)?.toLowerCase();if(U==="failed"||U==="invalid")v.push({title:"Image failed validation",detail:OU($.data.validationMessage)??"Review this image before using it as evidence."});return v}function wA($){let v=[$.data.title,$.data.caption,$.data.alt,$.data.src,$.data.path].map((g)=>OU(g)?.toLowerCase()??"").join(" ");if(v.length===0)return!1;return["login","log in","sign in","signin","password","2fa","mfa","authenticate","authentication","sso"].some((g)=>v.includes(g))}function XW($){let v=XA($);if(v.length>0)return v;if(wA($))return[{title:"Captured login page",detail:"This image looks like an auth screen. Treat it as environment context, not product evidence."}];return[]}function M0({node:$,expanded:v=!1}){let g=$.data.src||"",_=$.data.alt||$.data.title||"Image",U=$.data.caption||"",z=XW($),b=g.startsWith("data:")||g.startsWith("http://")||g.startsWith("https://")?g:`/api/canvas/image/${$.id}`,[J,G]=x(!1),[K,W]=x(!1),[B,P]=x(1),[k,A]=x({x:0,y:0}),[L,I]=x({w:0,h:0}),Y=V(null),F=V(!1),X=V({x:0,y:0}),Q=M((p)=>{let i=p.target;I({w:i.naturalWidth,h:i.naturalHeight}),G(!0),W(!1)},[]),u=M(()=>{W(!0),G(!1)},[]);m(()=>{P(1),A({x:0,y:0})},[g]);let c=M((p)=>{p.preventDefault(),p.stopPropagation();let i=p.deltaY>0?0.9:1.1;P((Y$)=>Math.max(0.25,Math.min(10,Y$*i)))},[]),N=M((p)=>{if(B<=1)return;p.stopPropagation(),F.current=!0,X.current={x:p.clientX,y:p.clientY},p.target.setPointerCapture(p.pointerId)},[B]),t=M((p)=>{if(!F.current)return;let i=p.clientX-X.current.x,Y$=p.clientY-X.current.y;X.current={x:p.clientX,y:p.clientY},A((_$)=>({x:_$.x+i,y:_$.y+Y$}))},[]),a=M(()=>{F.current=!1},[]),r=M(()=>{P(1),A({x:0,y:0})},[]);if(!g)return O("div",{class:"image-node-empty",children:[O("div",{class:"image-node-empty-icon",children:"\uD83D\uDDBC"},void 0,!1,void 0,this),O("div",{class:"image-node-empty-text",children:"No image source"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let y=L.w>0?`${L.w}×${L.h}`:"",v$=Math.round(B*100);return O("div",{class:`image-node ${v?"image-node-expanded":""}`,ref:Y,children:[z.length>0&&O("div",{class:"image-node-warning-stack",children:z.map((p)=>O("div",{class:"image-node-warning",children:[O("span",{class:"image-node-warning-title",children:p.title},void 0,!1,void 0,this),O("span",{class:"image-node-warning-detail",children:p.detail},void 0,!1,void 0,this)]},`${p.title}-${p.detail}`,!0,void 0,this))},void 0,!1,void 0,this),O("div",{class:"image-node-viewport",onWheel:c,onPointerDown:N,onPointerMove:t,onPointerUp:a,style:{cursor:B>1?"grab":"default"},children:[!J&&!K&&O("div",{class:"image-node-loading",children:"Loading…"},void 0,!1,void 0,this),K&&O("div",{class:"image-node-error",children:[O("div",{class:"image-node-error-icon",children:"⚠"},void 0,!1,void 0,this),O("div",{children:"Failed to load image"},void 0,!1,void 0,this),O("div",{class:"image-node-error-path",children:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("img",{src:b,alt:_,onLoad:Q,onError:u,draggable:!1,style:{transform:`translate(${k.x}px, ${k.y}px) scale(${B})`,opacity:J?1:0,display:K?"none":"block"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(U||y||B!==1)&&O("div",{class:"image-node-footer",children:[U&&O("span",{class:"image-node-caption",children:U},void 0,!1,void 0,this),O("span",{class:"image-node-meta",children:[y&&O("span",{children:y},void 0,!1,void 0,this),B!==1&&O("button",{type:"button",class:"image-node-zoom-reset",onClick:r,title:"Reset zoom",children:[v$,"% ↺"]},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 wW({node:$}){let v=$.data.children??[],g=T.value,_=v.filter((J)=>g.has(J)),U=_.length,z={};for(let J of _){let G=g.get(J);if(G)z[G.type]=(z[G.type]??0)+1}let b=Object.entries(z).map(([J,G])=>`${G} ${J}`).join(", ");return O("div",{class:"group-node-body",children:[O("div",{class:"group-summary",children:[O("span",{class:"group-child-count",children:[U," node",U!==1?"s":""]},void 0,!0,void 0,this),b&&O("span",{class:"group-type-summary",children:b},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U===0&&O("div",{class:"group-empty-hint",children:"Drag nodes here or use the selection bar to group nodes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ZA($){try{return new URL($).host}catch{return $}}function SA($){if(!$)return null;let v=new Date($);return Number.isNaN(v.getTime())?null:v.toLocaleString()}function Q0({node:$,expanded:v=!1}){let g=typeof $.data.url==="string"?$.data.url:"",_=typeof $.data.pageTitle==="string"?$.data.pageTitle:"",U=typeof $.data.description==="string"?$.data.description:"",z=typeof $.data.excerpt==="string"?$.data.excerpt:typeof $.data.content==="string"?$.data.content:"",b=typeof $.data.status==="string"?$.data.status:"idle",J=typeof $.data.error==="string"?$.data.error:"",G=SA(typeof $.data.fetchedAt==="string"?$.data.fetchedAt:void 0),K=typeof $.data.statusCode==="number"?$.data.statusCode:null,W=typeof $.data.imageUrl==="string"?$.data.imageUrl:"",B=$.data.frameBlocked===!0,P=typeof $.data.frameBlockedReason==="string"?$.data.frameBlockedReason:"",[k,A]=x(!1),[L,I]=x(v);m(()=>{if(v)I(!0)},[v]);let Y=M(async()=>{if(!g||k)return;A(!0);try{await J_($.id)}finally{A(!1)}},[$.id,k,g]);if(!g)return O("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No webpage URL set"},void 0,!1,void 0,this);let F=b==="ready"?"var(--c-ok)":b==="error"?"var(--c-danger)":"var(--c-warn)";return O("div",{style:{display:"flex",flexDirection:"column",gap:"12px",height:"100%"},children:[O("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[O("div",{style:{minWidth:0,flex:1},children:[O("div",{style:{fontSize:"12px",color:"var(--c-muted)"},children:ZA(g)},void 0,!1,void 0,this),O("div",{style:{fontSize:v?"18px":"15px",fontWeight:700,color:"var(--c-text)"},children:_||$.data.title||g},void 0,!1,void 0,this),O("a",{href:g,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all",textDecoration:"none"},children:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"999px",background:"rgba(255,255,255,0.04)",color:F,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.04em",flexShrink:0},children:[O("span",{style:{width:"7px",height:"7px",borderRadius:"999px",background:F}},void 0,!1,void 0,this),b]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),(U||W)&&O("div",{style:{display:"grid",gridTemplateColumns:W&&v?"160px 1fr":"1fr",gap:"12px",alignItems:"start"},children:[W&&v&&O("img",{src:W,alt:_||"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),U&&O("p",{style:{margin:0,color:"var(--c-text-soft)",lineHeight:1.5,fontSize:v?"14px":"12px"},children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{style:{display:"flex",gap:"8px",flexWrap:"wrap"},children:[O("button",{type:"button",onClick:Y,disabled:k,style:{border:"1px solid var(--c-line)",background:"var(--c-panel-soft)",color:"var(--c-text)",borderRadius:"8px",padding:"6px 10px",cursor:k?"progress":"pointer",fontSize:"12px"},children:k||b==="fetching"?"Refreshing…":"Refresh"},void 0,!1,void 0,this),v&&!B&&O("button",{type:"button",onClick:()=>I((X)=>!X),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:L?"Hide live preview":"Show live preview"},void 0,!1,void 0,this),O("button",{type:"button",onClick:()=>window.open(g,"_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),v&&B&&O("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[O("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),O("div",{style:{padding:"20px",color:"var(--c-text-soft)",lineHeight:1.6,fontSize:"13px"},children:P||"The remote site blocks iframe embedding."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v&&L&&!B&&O("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[O("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),O("iframe",{class:"webpage-node-iframe",title:_||$.data.title||g,src:g,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:v?"320px":"180px",border:"none",background:"#fff"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(G||K!==null)&&O("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap",color:"var(--c-muted)",fontSize:"11px"},children:[G&&O("span",{children:["Fetched ",G]},void 0,!0,void 0,this),K!==null&&O("span",{children:["HTTP ",K]},void 0,!0,void 0,this),B&&O("span",{children:"Preview blocked by site"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J&&O("div",{style:{color:"var(--c-danger)",fontSize:"12px",lineHeight:1.5},children:J},void 0,!1,void 0,this),O("div",{style:{flex:1,minHeight:0,overflow:"auto",border:"1px solid var(--c-line)",borderRadius:"10px",background:"var(--c-panel-soft)",padding:v?"14px":"10px"},children:z?O("div",{style:{whiteSpace:"pre-wrap",lineHeight:1.55,color:"var(--c-text)",fontSize:v?"14px":"12px"},children:z},void 0,!1,void 0,this):O("div",{style:{color:"var(--c-dim)",fontStyle:"italic"},children:b==="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 ZW($){let v=5381;for(let g=0;g<$.length;g+=1)v=(v<<5)+v+$.charCodeAt(g)|0;return(v>>>0).toString(36)}function eO($,v={}){let g=new URLSearchParams;if(g.set("theme",v.theme??V$.value),v.themeToken)g.set("themeToken",v.themeToken);if(v.present)g.set("present","1");if(v.presentToken)g.set("presentToken",v.presentToken);if(v.v)g.set("v",v.v);if(v.axToken)g.set("axToken",v.axToken);if(v.frameToken)g.set("frameToken",v.frameToken);return`/api/canvas/surface/${encodeURIComponent($)}?${g.toString()}`}function N0($){return HW($.type,$.data)}async function u0($){let v=eO($.id);if(!(await LK($.id,v)).opened)window.open(v,"_blank","noopener")}function SW($){return $.type==="html"&&$.data.presentation===!0}function Qg({node:$,expanded:v=!1,presentation:g=!1,presentationExitToken:_,autoFocus:U=!1}){let z=V(null),b=V$.value,J=o$(()=>`theme-${crypto.randomUUID()}`,[]),G=o$(()=>`ax-${crypto.randomUUID()}`,[]),K=o$(()=>`frame-${crypto.randomUUID()}`,[]),W=typeof $.data.html==="string"?$.data.html:typeof $.data.content==="string"?$.data.content:"",B=o$(()=>ZW(W),[W]),P=o$(()=>W?eO($.id,{theme:b,themeToken:J,present:g,presentToken:_,v:B,axToken:G,frameToken:K}):"",[W,g,_,J,B,$.id,G,K]);w0($,z,v?"":K),m(()=>{function Y(F){if(F.source!==z.current?.contentWindow)return;let X=F.data;if(!X||X.source!=="pmx-canvas-ax"||X.token!==G||X.nodeId!==$.id)return;let Q=X.interaction;if(!Q||typeof Q.type!=="string")return;let u=Q.type;k6({type:u,sourceNodeId:$.id,sourceSurface:"html-node",...Q.payload&&typeof Q.payload==="object"?{payload:Q.payload}:{}}).then((c)=>{if(c.ok)Nv("context","AX interaction",u,[$.id]);else Nv("remove","AX interaction rejected",c.error??c.code??"",[$.id]);z.current?.contentWindow?.postMessage({source:"pmx-canvas-ax-ack",token:G,...X.correlationId?{correlationId:X.correlationId}:{},interaction:{type:u},result:c},"*")})}return window.addEventListener("message",Y),()=>window.removeEventListener("message",Y)},[G,$.id]),m(()=>{if(z.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"theme-update",token:J,theme:b},"*"),U)z.current?.focus()},[b,J]);let k=$.data.axCapabilities,A=k?.enabled===!0&&(!Array.isArray(k.allowed)||k.allowed.length>0),L=I6.value;m(()=>{if(!A||L==null)return;z.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"ax-update",token:G,state:L},"*")},[A,L,G]),m(()=>{if(!U)return;let Y=window.setTimeout(()=>z.current?.focus(),0);return()=>window.clearTimeout(Y)},[U,P]);let I=()=>{if(z.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"theme-update",token:J,theme:b},"*"),A&&I6.value!=null)z.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"ax-update",token:G,state:I6.value},"*");if(U)z.current?.focus()};if(!W)return O("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No HTML content set"},void 0,!1,void 0,this);return O("iframe",{ref:z,class:g?"html-node-frame html-node-frame-presentation":"html-node-frame",title:typeof $.data.title==="string"?$.data.title:"HTML node",sandbox:"allow-scripts",src:P,tabIndex:U?0:void 0,onLoad:I,style:{width:"100%",height:"100%",minHeight:g?0:v?"70vh":"300px",border:"none",background:"var(--c-bg)",borderRadius:g?0:"6px",display:"block"}},void 0,!1,void 0,this)}var $G=null;async function MW(){if(!$G)$G=await kK();return $G}function QW($,v){if(!$)return null;let g=$.toLowerCase(),_=v.find((z)=>z.name.toLowerCase()===g);if(_)return _.name;let U=v.filter((z)=>z.name.toLowerCase().startsWith(g));return U.length===1?U[0].name:null}function MA($){return $.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 QA({html:$}){let v=V(null);return m(()=>{let g=v.current;if(!g)return;if(g.replaceChildren(),!$)return;let _=document.createElement("template");_.innerHTML=$,g.append(_.content.cloneNode(!0))},[$]),O("div",{ref:v},void 0,!1,void 0,this)}function NA($,v){return`${$.role}:${$.status??"none"}:${v}:${$.text}`}function NW({count:$}){if($===0)return null;return O("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:["✦"," ",$," context node",$!==1?"s":""," attached"]},void 0,!0,void 0,this)}function uW({message:$,onDismiss:v}){if(!$)return null;return O("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:[O("span",{style:{flex:1},children:$},void 0,!1,void 0,this),O("button",{type:"button",onClick:v,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 r0({node:$,expanded:v=!1}){let g=Array.isArray($.data.turns)?$.data.turns:[],_=g.length===0,U=$.data.text||"",z=$.data.status||"draft",b=_?z:$.data.threadStatus||"draft",J=b==="draft",G=b==="pending"||b==="sending",K=b==="streaming",W=b==="answered",[B,P]=x(""),[k,A]=x(""),[L,I]=x(null),[Y,F]=x(new Map),X=V(null),Q=V(null),u=g[g.length-1],c=`${g.length}:${u?.role??""}:${u?.status??""}:${Math.floor((u?.text?.length??0)/200)}`;m(()=>{if(v&&J&&X.current)X.current.focus()},[v,J]),m(()=>{if(!c)return;if(Q.current)Q.current.scrollTo({top:Q.current.scrollHeight,behavior:"smooth"})},[c]);let N=V(null),t=V(g);t.current=g,m(()=>{let i=g.some((_$)=>_$.role==="assistant"&&_$.status==="streaming"),Y$=()=>{let _$=!1,S=t.current.map((h,$$)=>({turn:h,index:$$})).filter(({turn:h})=>h.role==="assistant"&&h.text);if(S.length===0)return;return Promise.all(S.map(async({turn:h,index:$$})=>{let s=await $6(h.text);return{index:$$,html:MA(s)}})).then((h)=>{if(_$)return;let $$=new Map;for(let s of h)$$.set(s.index,s.html);F($$)}),()=>{_$=!0}};if(!i){if(N.current)clearTimeout(N.current),N.current=null;return Y$()}if(N.current)clearTimeout(N.current);return N.current=setTimeout(()=>{N.current=null,Y$()},400),()=>{if(N.current)clearTimeout(N.current),N.current=null}},[g]);let a=M(async()=>{let i=B.trim();if(!i)return;let Y$=B;I(null),g$($.id,{turns:[{role:"user",text:i,status:"pending"}],threadStatus:"pending",text:i}),P("");let _$=Array.isArray($.data.contextNodeIds)?$.data.contextNodeIds:void 0;if(!(await AU(i,$.position,$.id,_$,$.id)).ok)g$($.id,{turns:[],threadStatus:"draft",text:"",status:"draft"}),P(Y$),I("Failed to send prompt. Your draft has been restored.")},[B,$.id,$.position,$.data.contextNodeIds]),r=M(async()=>{let i=k.trim();if(!i)return;let Y$=k;I(null);let _$=Array.isArray($.data.turns)?[...$.data.turns]:[];if(_$.push({role:"user",text:i,status:"pending"}),g$($.id,{turns:_$,threadStatus:"pending"}),A(""),!(await PK($.id,i)).ok)_$.pop(),g$($.id,{turns:_$,threadStatus:"answered"}),A(Y$),I("Failed to send reply. Your draft has been restored.")},[k,$.id,$.data.turns]),y=M((i)=>{if(i.key==="Enter"&&(i.metaKey||i.ctrlKey)){i.preventDefault(),a();return}if(i.key==="Tab"&&B.startsWith("/")){i.preventDefault();let Y$=B.slice(1).split(/\s/)[0];if(Y$)MW().then((_$)=>{let x$=QW(Y$,_$);if(x$)P(`/${x$}`)})}},[a,B]),v$=M((i)=>{if(i.key==="Enter"&&(i.metaKey||i.ctrlKey)){i.preventDefault(),r();return}if(i.key==="Tab"&&k.startsWith("/")){i.preventDefault();let Y$=k.slice(1).split(/\s/)[0];if(Y$)MW().then((_$)=>{let x$=QW(Y$,_$);if(x$)A(`/${x$}`)})}},[r,k]),p=Array.isArray($.data.contextNodeIds)?$.data.contextNodeIds.length:0;if(J&&g.length===0)return O("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%",gap:"8px"},children:[O(NW,{count:p},void 0,!1,void 0,this),O(uW,{message:L,onDismiss:()=>I(null)},void 0,!1,void 0,this),O("textarea",{ref:X,value:B,onInput:(i)=>P(i.target.value),onKeyDown:y,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),O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[O("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter to send"]},void 0,!0,void 0,this),O("button",{type:"button",onClick:a,disabled:!B.trim(),style:{padding:"5px 14px",fontSize:"12px",fontWeight:600,background:B.trim()?"var(--c-accent)":"var(--c-line)",color:B.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:B.trim()?"pointer":"default"},children:"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(_)return O("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[O("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:U},void 0,!1,void 0,this),O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:"6px",borderTop:"1px solid var(--c-line)",marginTop:"4px"},children:O("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:G?"var(--c-warn)":W?"var(--c-ok)":"var(--c-muted)"},children:G?"Sending…":W?"Answered":z},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return O("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[O(NW,{count:p},void 0,!1,void 0,this),O(uW,{message:L,onDismiss:()=>I(null)},void 0,!1,void 0,this),O("div",{ref:Q,style:{flex:1,overflow:"auto",minHeight:0},children:g.map((i,Y$)=>O("div",{children:[Y$>0&&O("div",{class:"thread-turn-divider"},void 0,!1,void 0,this),i.role==="user"?O("div",{class:"thread-turn-user",children:[O("div",{class:"thread-turn-role",children:[O("span",{class:"status-dot"},void 0,!1,void 0,this),"You"]},void 0,!0,void 0,this),O("div",{style:{fontSize:v?"15px":"13px",lineHeight:v?"1.7":"1.55",color:"var(--c-text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:i.text},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O("div",{class:"thread-turn-assistant",children:[O("div",{class:"thread-turn-role",children:[O("span",{class:`status-dot${i.status==="streaming"?" pulsing":""}`},void 0,!1,void 0,this),"PMX"]},void 0,!0,void 0,this),i.status==="streaming"&&!i.text&&O("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),O("div",{class:v?"md-reader-content":void 0,style:{fontSize:v?void 0:"13px",lineHeight:v?void 0:"1.55",opacity:i.text?1:0.4},children:Y.get(Y$)?O(d$,{children:[O(QA,{html:Y.get(Y$)??""},void 0,!1,void 0,this),i.status==="streaming"&&O("span",{class:"streaming-cursor"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O("div",{style:{color:"var(--c-muted)",fontStyle:"italic"},children:i.status==="streaming"?"Waiting for response…":i.text||"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},NA(i,Y$),!0,void 0,this))},void 0,!1,void 0,this),O("div",{style:{flexShrink:0,borderTop:"1px solid var(--c-line)",marginTop:"4px",paddingTop:"6px"},children:[O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:W?"6px":0},children:[O("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:K?"var(--c-accent)":G?"var(--c-warn)":W?"var(--c-ok)":"var(--c-muted)"},children:K?"Streaming…":G?"Sending…":W?"Answered":b},void 0,!1,void 0,this),O("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:[g.length," turn",g.length!==1?"s":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),W&&O("div",{class:"thread-reply-area",children:[O("textarea",{value:k,onInput:(i)=>A(i.target.value),onKeyDown:v$,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),O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"4px"},children:[O("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter"]},void 0,!0,void 0,this),O("button",{type:"button",onClick:r,disabled:!k.trim(),style:{padding:"3px 10px",fontSize:"11px",fontWeight:600,background:k.trim()?"var(--c-accent)":"var(--c-line)",color:k.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:k.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 uA($){return $.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 rA({html:$}){let v=V(null);return m(()=>{let g=v.current;if(!g)return;if(g.replaceChildren(),!$)return;let _=document.createElement("template");_.innerHTML=$,g.append(_.content.cloneNode(!0))},[$]),O("div",{ref:v},void 0,!1,void 0,this)}function R0({node:$,expanded:v=!1}){let g=$.data.content||"",_=$.data.status||"streaming",[U,z]=x(""),b=_==="streaming",J=_==="complete";m(()=>{if(!g){z("");return}let K=!1;return $6(g).then((W)=>{if(!K)z(uA(W))}),()=>{K=!0}},[g]);let G=M(()=>{AU("",{x:$.position.x,y:$.position.y+$.size.height+24},$.id)},[$]);return O("div",{class:"response-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[b&&O("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),O("div",{class:v?"md-reader":void 0,style:{flex:1,overflow:"auto",minHeight:0,opacity:g?1:0.4,transition:"opacity 0.2s ease"},children:U?O("div",{class:v?"md-reader-content":void 0,children:O(rA,{html:U},void 0,!1,void 0,this)},void 0,!1,void 0,this):O("div",{style:{color:"var(--c-muted)",fontStyle:"italic",fontSize:"13px"},children:b?"Waiting for response…":"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:"6px",borderTop:"1px solid var(--c-line)",marginTop:"4px",flexShrink:0},children:[O("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:b?"var(--c-accent)":J?"var(--c-ok)":"var(--c-muted)"},children:b?"Streaming…":J?"Complete":_},void 0,!1,void 0,this),J&&O("button",{type:"button",onClick:G,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 rW($){return{toolName:$.toolName||$.title||"unknown",category:$.category||"other",status:$.status||"running",duration:$.duration||"",resultSummary:$.resultSummary||$.content||"",error:$.error||""}}var RW={mcp:"var(--c-accent)",file:"var(--c-warn)",subagent:"var(--c-purple)",other:"var(--c-muted)"},RA={running:"⠋",success:"✓",failed:"✕"},yA={running:"var(--c-accent)",success:"var(--c-ok)",failed:"var(--c-danger)"};function y0({node:$}){let{toolName:v,category:g,status:_,duration:U,resultSummary:z,error:b}=rW($.data),J=RW[g]??RW.other,G=RA[_]??"◌",K=yA[_]??"var(--c-muted)",W=_==="running",B=b?b.slice(0,30):z.length>30?`${z.slice(0,28)}…`:z;return O("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"0 12px",height:"100%",overflow:"hidden"},children:[O("span",{style:{fontSize:"14px",color:K,flexShrink:0,animation:W?"pulse 1.5s infinite":"none"},children:G},void 0,!1,void 0,this),O("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:[O("div",{style:{fontFamily:"var(--mono)",fontSize:"11px",fontWeight:600,color:J,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v},void 0,!1,void 0,this),B&&O("div",{style:{fontSize:"10px",color:b?"var(--c-danger)":"var(--c-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:1.3},children:B},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&O("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:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function UG($){let v=T.value.get($);if(!v||v.dockPosition!==null)return null;return{left:v.position.x,top:v.position.y,width:v.size.width,height:v.size.height}}function DA($){let v=$.map((G)=>UG(G)).filter((G)=>G!==null);if(v.length===0)return null;let g=Math.min(...v.map((G)=>G.left)),_=Math.min(...v.map((G)=>G.top)),U=Math.max(...v.map((G)=>G.left+G.width)),z=Math.max(...v.map((G)=>G.top+G.height)),b=54,J=46;return{left:g-b,top:_-J,width:U-g+b*2,height:z-_+J*2}}function vG($,v){return{left:`${$.left}px`,top:`${$.top}px`,width:`${$.width}px`,height:`${$.height}px`,borderRadius:`${v}px`}}function yW(){let $=Array.from(G4.value),v=Array.from(K4.value),g=sg.value;if($.length===0&&v.length===0)return null;return O("div",{class:"attention-field-layer","aria-hidden":"true",children:[g.map((_)=>{let U=DA(_.nodeIds);if(!U)return null;return O("div",{class:"attention-field-region",style:vG(U,42)},_.id,!1,void 0,this)}),v.map((_)=>{let U=UG(_);if(!U)return null;return O("div",{class:"attention-field-node attention-field-secondary",style:vG({left:U.left-18,top:U.top-18,width:U.width+36,height:U.height+36},28)},`secondary-${_}`,!1,void 0,this)}),$.map((_)=>{let U=UG(_);if(!U)return null;return O("div",{class:"attention-field-node attention-field-primary",style:vG({left:U.left-24,top:U.top-24,width:U.width+48,height:U.height+48},30)},`primary-${_}`,!1,void 0,this)})]},void 0,!0,void 0,this)}var Mv=k$(new Map),GU=k$(null),TA=480,jA=320,Ng=new Map,O6=null;function gG($){Mv.value=$,CA()}function _G($){let v=Ng.get($);if(v)clearTimeout(v),Ng.delete($)}function DW($){_G($.id);let v=new Map(Mv.value);v.set($.id,{...$,phase:"forming"}),gG(v)}function VA($){if(_G($),!Mv.value.has($))return;let v=new Map(Mv.value);v.delete($),gG(v)}function TW($,v,g,_){let U=Mv.value.get($);if(!U||U.phase===v)return;let z=new Map(Mv.value);z.set($,{...U,phase:v,..._?{settledNodeId:_}:{}}),gG(z),_G($),Ng.set($,setTimeout(()=>VA($),g))}function jW($,v){TW($,"settling",TA,v)}function zG($){TW($,"dissolving",jA)}function VW(){for(let $ of Ng.values())clearTimeout($);if(Ng.clear(),O6)clearInterval(O6),O6=null;GU.value=null,Mv.value=new Map}function CA(){if(O6||Mv.value.size===0)return;O6=setInterval(()=>{let $=Date.now();for(let v of Mv.value.values())if(v.phase==="forming"&&v.expiresAt<=$)zG(v.id);if(Mv.value.size===0&&O6)clearInterval(O6),O6=null},1000),O6.unref?.()}var fA={fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"};function q$({size:$=16,children:v,...g}){return O("svg",{width:$,height:$,viewBox:"0 0 16 16",...fA,...g,children:v},void 0,!1,void 0,this)}function cW($){return O(q$,{...$,children:[O("polyline",{points:"1 5 1 1 5 1"},void 0,!1,void 0,this),O("polyline",{points:"11 1 15 1 15 5"},void 0,!1,void 0,this),O("polyline",{points:"15 11 15 15 11 15"},void 0,!1,void 0,this),O("polyline",{points:"5 15 1 15 1 11"},void 0,!1,void 0,this),O("rect",{x:"4",y:"4",width:"8",height:"8",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function mW($){return O(q$,{...$,children:[O("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"4.5",x2:"8",y2:"6.5"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"9.5",x2:"8",y2:"11.5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"8",x2:"6.5",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"9.5",y1:"8",x2:"11.5",y2:"8"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function EW($){return O(q$,{...$,children:[O("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),O("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),O("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this),O("line",{x1:"7",y1:"5",x2:"7",y2:"9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function iW($){return O(q$,{...$,children:[O("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),O("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),O("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function lW($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),O("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),O("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),O("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),O("line",{x1:"6.5",y1:"4",x2:"9.5",y2:"4"},void 0,!1,void 0,this),O("line",{x1:"6.5",y1:"12",x2:"9.5",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"6.5",x2:"4",y2:"9.5"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"6.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function hW($){return O(q$,{...$,children:[O("rect",{x:"1",y:"2",width:"14",height:"12",rx:"1.5"},void 0,!1,void 0,this),O("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 xW($){return O(q$,{...$,children:[O("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"1",x2:"8",y2:"3"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"13",x2:"8",y2:"15"},void 0,!1,void 0,this),O("line",{x1:"1",y1:"8",x2:"3",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"13",y1:"8",x2:"15",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"3.05",y1:"3.05",x2:"4.46",y2:"4.46"},void 0,!1,void 0,this),O("line",{x1:"11.54",y1:"11.54",x2:"12.95",y2:"12.95"},void 0,!1,void 0,this),O("line",{x1:"3.05",y1:"12.95",x2:"4.46",y2:"11.54"},void 0,!1,void 0,this),O("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 pW($){return O(q$,{...$,children:O("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 oW($){return O(q$,{...$,children:[O("path",{d:"M3 13l2.8-.7L13 5.1 10.9 3 3.7 10.2 3 13Z"},void 0,!1,void 0,this),O("path",{d:"M9.8 4.1l2.1 2.1"},void 0,!1,void 0,this),O("path",{d:"M2.5 14h11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function nW($){return O(q$,{...$,children:[O("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),O("path",{d:"M7.5 6 12 10.5"},void 0,!1,void 0,this),O("path",{d:"M8.5 14H14"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function tW($){return O(q$,{...$,children:[O("path",{d:"M3 4h10"},void 0,!1,void 0,this),O("path",{d:"M8 4v8"},void 0,!1,void 0,this),O("path",{d:"M6 12h4"},void 0,!1,void 0,this),O("path",{d:"M4.5 4 4 6"},void 0,!1,void 0,this),O("path",{d:"M11.5 4 12 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function dW($){return O(q$,{...$,children:[O("rect",{x:"1",y:"4",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),O("path",{d:"M5.5 4 L6.5 2.5 H9.5 L10.5 4"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"9",r:"2.3"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function aW($){return O(q$,{...$,children:[O("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),O("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 sW($){return O(q$,{...$,children:[O("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),O("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"10.5"},void 0,!1,void 0,this),O("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 eW($){return O(q$,{...$,children:[O("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),O("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 $B($){return O(q$,{...$,children:[O("rect",{x:"1",y:"3",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"6",x2:"5",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"7.5",y1:"6",x2:"8.5",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"11",y1:"6",x2:"12",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"10",x2:"12",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function vB({size:$=22,class:v}){return O("svg",{width:$,height:$,viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",class:v,"aria-hidden":"true",children:[O("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),O("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),O("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),O("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 CW($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"6",x2:"10",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"8.5",x2:"8",y2:"8.5"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"11",x2:"11",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function cA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),O("path",{d:"M4 13.5 L5.5 11.5 L8 11.5"},void 0,!1,void 0,this),O("polyline",{points:"5 6 7 8 5 10"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"10",x2:"11",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function mA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),O("path",{d:"M12 13.5 L10.5 11.5 L8 11.5"},void 0,!1,void 0,this),O("circle",{cx:"5",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("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 EA($){return O(q$,{...$,children:[O("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),O("polyline",{points:"9 1.5 9 5 12.5 5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"8.5",x2:"10.5",y2:"8.5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"11",x2:"9",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function iA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("circle",{cx:"5.5",cy:"6.5",r:"1.2"},void 0,!1,void 0,this),O("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 fW($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"1.5",y1:"5.5",x2:"14.5",y2:"5.5"},void 0,!1,void 0,this),O("circle",{cx:"3.3",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"5",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"6.7",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"8",x2:"12",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"10",x2:"10",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function lA($){return O(q$,{...$,children:[O("rect",{x:"2",y:"4",width:"12",height:"10",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"2",y1:"6.5",x2:"14",y2:"6.5"},void 0,!1,void 0,this),O("path",{d:"M11 1.5 L11 4"},void 0,!1,void 0,this),O("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 hA($){return O(q$,{...$,children:[O("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),O("rect",{x:"4",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),O("rect",{x:"8.5",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),O("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 xA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),O("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),O("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 pA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("path",{d:"M3.5 10.5 L6 6.5 L8.5 9.5 L12.5 5"},void 0,!1,void 0,this),O("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 oA($){return O(q$,{...$,children:[O("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"5.5",x2:"11.5",y2:"5.5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"8",x2:"11.5",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"10.5",x2:"8",y2:"10.5"},void 0,!1,void 0,this),O("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 nA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this),O("path",{d:"M4 11 L4 6 L6 8.5 L8 6 L8 11"},void 0,!1,void 0,this),O("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 tA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("polyline",{points:"10 5 13 5 13 8"},void 0,!1,void 0,this),O("line",{x1:"13",y1:"5",x2:"8",y2:"10"},void 0,!1,void 0,this),O("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 dA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("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),O("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 aA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"5.2",y1:"6",x2:"8",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"8",x2:"10.8",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"8",x2:"8",y2:"11"},void 0,!1,void 0,this),O("circle",{cx:"5.2",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"10.8",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"11",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ug($){switch($){case"markdown":return CW;case"prompt":return cA;case"response":return mA;case"file":return EA;case"image":return iA;case"webpage":return fW;case"context":return lA;case"group":return hA;case"status":return xA;case"trace":return pA;case"ledger":return oA;case"mcp-app":return nA;case"ext-app":return tA;case"json-render":return dA;case"graph":return aA;case"html":return fW;default:return CW}}var UB={width:260,height:150},sA={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 JG($){return!!$&&$ in a$}function G6($){if(!$)return null;let v=T.value.get($);if(!v||v.dockPosition!==null)return null;return{left:v.position.x,top:v.position.y,width:v.size.width,height:v.size.height}}function bG($){return{x:$.left+$.width/2,y:$.top+$.height/2}}function rg($){if(typeof $.confidence!=="number")return 0.82;return 0.4+Math.max(0,Math.min(1,$.confidence))*0.55}function gB($,v){let g=Math.max(40,Math.abs(v.x-$.x)/2);return`M ${$.x} ${$.y} C ${$.x+g} ${$.y}, ${v.x-g} ${v.y}, ${v.x} ${v.y}`}function OG({intent:$}){let v=JG($.nodeType)?ug($.nodeType):null,g=$.label||$.kind,_=typeof $.confidence==="number"?`${Math.round($.confidence*100)}%`:null;return O("div",{class:"intent-info",onMouseEnter:()=>GU.value=$.id,onMouseLeave:()=>{if(GU.value===$.id)GU.value=null},children:[O("div",{class:"intent-chip",children:[typeof $.seq==="number"&&O("span",{class:"intent-seq",children:$.seq},void 0,!1,void 0,this),v&&O("span",{class:"intent-chip-icon","aria-hidden":"true",children:O(v,{size:12},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("span",{class:"intent-chip-label",children:g},void 0,!1,void 0,this),_&&O("span",{class:"intent-confidence",children:_},void 0,!1,void 0,this),$.phase==="forming"&&O("button",{type:"button",class:"intent-veto",title:"Veto this move (Esc)","aria-label":"Veto this move",onClick:(U)=>{U.stopPropagation(),z2($)},children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$.reason&&O("div",{class:"intent-reason",children:$.reason},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _B({intent:$,rect:v}){let g=JG($.nodeType)?ug($.nodeType):null,_=JG($.nodeType)?a$[$.nodeType]:"Node";return O("div",{class:`intent-ghost intent-ghost-box is-${$.phase}`,"data-intent-id":$.id,style:{left:`${v.left}px`,top:`${v.top}px`,width:`${v.width}px`,height:`${v.height}px`,opacity:rg($)},children:[O("div",{class:"intent-ghost-titlebar",children:[O("span",{class:"intent-ghost-icon","aria-hidden":"true",children:g?O(g,{size:13},void 0,!1,void 0,this):"◇"},void 0,!1,void 0,this),O("span",{class:"intent-ghost-badge",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O(OG,{intent:$},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zB({intent:$,rect:v,variant:g}){return O("div",{class:`intent-ghost intent-ghost-${g} is-${$.phase}`,"data-intent-id":$.id,style:{left:`${v.left}px`,top:`${v.top}px`,width:`${v.width}px`,height:`${v.height}px`,opacity:rg($)},children:[g==="edit"&&O("div",{class:"intent-edit-bar"},void 0,!1,void 0,this),O(OG,{intent:$},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function eA($){let v=$.phase==="settling"?G6($.settledNodeId):null;switch($.kind){case"create":{if(!$.position)return null;let g=$.nodeType&&sA[$.nodeType]||UB,_=v??{left:$.position.x,top:$.position.y,...g};return O(_B,{intent:$,rect:_},$.id,!1,void 0,this)}case"move":{if(!$.position)return null;let _=G6($.nodeId)??UB,U=v??{left:$.position.x,top:$.position.y,width:_.width,height:_.height};return O(_B,{intent:$,rect:U},$.id,!1,void 0,this)}case"remove":{let g=v??G6($.nodeId);if(!g)return null;return O(zB,{intent:$,rect:g,variant:"remove"},$.id,!1,void 0,this)}case"edit":{let g=v??G6($.nodeId);if(!g)return null;return O(zB,{intent:$,rect:g,variant:"edit"},$.id,!1,void 0,this)}case"connect":{if(!$.edge)return null;let g=G6($.edge.from),_=G6($.edge.to);if(!g||!_)return null;let U={x:(g.left+g.width/2+_.left+_.width/2)/2,y:(g.top+g.height/2+_.top+_.height/2)/2},z={left:U.x-110,top:U.y-18,width:220,height:36};return O("div",{class:`intent-ghost intent-ghost-connect is-${$.phase}`,"data-intent-id":$.id,style:{left:`${z.left}px`,top:`${z.top}px`,width:`${z.width}px`,opacity:rg($)},children:O(OG,{intent:$},void 0,!1,void 0,this)},$.id,!1,void 0,this)}default:return null}}function bB(){let $=Array.from(Mv.value.values());if(m(()=>{function v(g){if(g.key!=="Escape")return;let _=GU.value;if(!_)return;let U=Mv.value.get(_);if(!U||U.phase!=="forming")return;g.stopImmediatePropagation(),g.preventDefault(),z2(U)}return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[]),$.length===0)return null;return O("div",{class:"intent-layer",children:[O("svg",{class:"intent-line-layer",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},children:[O("defs",{children:O("marker",{id:"intent-arrow",markerWidth:"8",markerHeight:"8",refX:"6",refY:"3",orient:"auto",children:O("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),$.map((v)=>{if(v.kind==="connect"&&v.edge){let g=G6(v.edge.from),_=G6(v.edge.to);if(!g||!_)return null;return O("path",{d:gB(bG(g),bG(_)),class:`intent-edge type-${v.edge.type}`,style:{opacity:rg(v)}},`line-${v.id}`,!1,void 0,this)}if(v.kind==="move"&&v.position){let g=G6(v.nodeId);if(!g)return null;let _=g,U={x:v.position.x+_.width/2,y:v.position.y+_.height/2};return O("path",{d:gB(bG(g),U),class:"intent-trail",markerEnd:"url(#intent-arrow)",style:{opacity:rg(v)}},`line-${v.id}`,!1,void 0,this)}return null})]},void 0,!0,void 0,this),$.map(eA)]},void 0,!0,void 0,this)}var KU=8,$4=k$(null),WU=[],BU=[],GB=null;function JB($){let v=$?.data.parentGroup;return typeof v==="string"&&v.length>0?v:null}function OB($){if(!$||!Array.isArray($.data.children))return[];return $.data.children.filter((v)=>typeof v==="string")}function $q($,v){let g=new Map(v.map((J)=>[J.id,J])),_=new Set([$]),U=g.get($);if(!U)return _;let z=JB(U);while(z&&!_.has(z))_.add(z),z=JB(g.get(z));if(U.type!=="group")return _;let b=[...OB(U)];while(b.length>0){let J=b.pop();if(!J||_.has(J))continue;_.add(J);let G=g.get(J);if(G?.type==="group")b.push(...OB(G))}return _}function KB($,v){WU=[],BU=[],GB=$;let g=Array.from(v),_=$q($,g);for(let U of g){if(_.has(U.id)||U.dockPosition!==null)continue;let z=U.position.x,b=U.position.x+U.size.width,J=U.position.x+U.size.width/2,G=U.position.y,K=U.position.y+U.size.height,W=U.position.y+U.size.height/2;WU.push({val:z,minY:G,maxY:K}),WU.push({val:b,minY:G,maxY:K}),WU.push({val:J,minY:G,maxY:K}),BU.push({val:G,minX:z,maxX:b}),BU.push({val:K,minX:z,maxX:b}),BU.push({val:W,minX:z,maxX:b})}}function WB(){WU=[],BU=[],GB=null}function BB($,v,g,_){let U=[$,$+g/2,$+g],z=[v,v+_/2,v+_],b=[0,g/2,g],J=[0,_/2,_],G=null,K=KU+1,W=null;for(let L=0;L<3;L++){let I=U[L];for(let Y of WU){let F=Math.abs(I-Y.val);if(F<K)K=F,G=Y.val-b[L],W={axis:"x",pos:Y.val,from:Math.min(Y.minY,v),to:Math.max(Y.maxY,v+_)}}}let B=null,P=KU+1,k=null;for(let L=0;L<3;L++){let I=z[L];for(let Y of BU){let F=Math.abs(I-Y.val);if(F<P)P=F,B=Y.val-J[L],k={axis:"y",pos:Y.val,from:Math.min(Y.minX,$),to:Math.max(Y.maxX,$+g)}}}let A=[];if(W&&K<=KU)A.push(W);if(k&&P<=KU)A.push(k);return{x:G!==null&&K<=KU?G:$,y:B!==null&&P<=KU?B:v,guides:A}}function kB({nodeId:$,viewport:v,onMove:g,onDragEnd:_}){let U=V(!1),z=V({x:0,y:0}),b=V({x:0,y:0});return M((G,K,W)=>{G.stopPropagation(),G.preventDefault(),U.current=!0,document.documentElement.classList.add("is-node-dragging"),window.getSelection()?.removeAllRanges(),z.current={x:G.clientX,y:G.clientY},b.current={x:K,y:W};let B=null,P=null,k=()=>{if(P=null,!U.current||!B)return;let I=B;B=null;let Y=v.value.scale,F=(I.x-z.current.x)/Y,X=(I.y-z.current.y)/Y;g($,b.current.x+F,b.current.y+X)},A=(I)=>{if(!U.current)return;if(B={x:I.clientX,y:I.clientY},P!==null)return;P=window.requestAnimationFrame(k)},L=()=>{if(P!==null)window.cancelAnimationFrame(P),k();U.current=!1,document.documentElement.classList.remove("is-node-dragging"),document.removeEventListener("pointermove",A),document.removeEventListener("pointerup",L),document.removeEventListener("pointercancel",L),_()};document.addEventListener("pointermove",A),document.addEventListener("pointerup",L),document.addEventListener("pointercancel",L)},[$,v,g,_])}var vq=200,Uq=100;function PB({nodeId:$,viewport:v,onResize:g,onResizeEnd:_}){let U=V(!1),z=V({x:0,y:0}),b=V({w:0,h:0});return M((G,K,W)=>{G.stopPropagation(),G.preventDefault(),U.current=!0,z.current={x:G.clientX,y:G.clientY},b.current={w:K,h:W},document.documentElement.classList.add("is-node-resizing");let B=null,P=null,k=()=>{if(P=null,!U.current||!B)return;let I=B;B=null;let Y=v.value.scale,F=(I.x-z.current.x)/Y,X=(I.y-z.current.y)/Y;g($,Math.max(vq,b.current.w+F),Math.max(Uq,b.current.h+X))},A=(I)=>{if(!U.current)return;if(B={x:I.clientX,y:I.clientY},P!==null)return;P=window.requestAnimationFrame(k)},L=()=>{if(P!==null)window.cancelAnimationFrame(P),k();U.current=!1,document.documentElement.classList.remove("is-node-resizing"),document.removeEventListener("pointermove",A),document.removeEventListener("pointerup",L),document.removeEventListener("pointercancel",L),_()};document.addEventListener("pointermove",A),document.addEventListener("pointerup",L),document.addEventListener("pointercancel",L)},[$,v,g,_])}function IB({node:$,children:v,onContextMenu:g}){let _=T$.value===$.id,U=i$.value.has($.id),z=j$.value.has($.id),b=G4.value.has($.id),J=!b&&K4.value.has($.id),G=eg.value.has($.id),K=!_&&NK.value.has($.id),W=H6.value,B=W!==null&&W.has($.id),P=W!==null&&!W.has($.id),[k,A]=x(!1),L=V(null),I=M((f,d,W$)=>{let o=BB(d,W$,$.size.width,$.size.height),z$=T.value.get(f);if(z$?.position.x===o.x&&z$.position.y===o.y){$4.value=o.guides.length>0?o.guides:null;return}Kv(f,{position:{x:o.x,y:o.y}}),$4.value=o.guides.length>0?o.guides:null},[$.size.width,$.size.height]),Y=M(()=>{WB(),$4.value=null,n$()},[]),F=kB({nodeId:$.id,viewport:H$,onMove:I,onDragEnd:Y}),X=M((f,d,W$)=>{let o=T.value.get(f);if(o?.size.width===d&&o.size.height===W$)return;Kv(f,{size:{width:d,height:W$}})},[]),Q=M(()=>{g$($.id,{userResized:!0}),Av($.id,{data:{userResized:!0}}),n$()},[$.id]),u=PB({nodeId:$.id,viewport:H$,onResize:X,onResizeEnd:Q}),c=M((f)=>{if(k)return;L6($.id),KB($.id,T.value.values()),F(f,$.position.x,$.position.y)},[$.id,$.position.x,$.position.y,F,k]),N=M((f)=>{if(f.stopPropagation(),f.shiftKey){uK($.id);return}L6($.id)},[$.id]),t=M((f)=>{if(g)g(f,$.id)},[g,$.id]),a=M((f)=>{f.stopPropagation(),A(!0),requestAnimationFrame(()=>L.current?.focus())},[]),r=$.data.title||a$[$.type],y=M((f)=>{let d=f.trim();if(d&&d!==r)g$($.id,{title:d}),Av($.id,{title:d});A(!1)},[$.id,r]),v$=V(null),p=V(!1),i=V(null);m(()=>{if(p.current||!T2($))return;let f=v$.current;if(!f)return;let d=new ResizeObserver(()=>{if(p.current){d.disconnect();return}let W$=f.scrollHeight,o=p3($,W$);if(o===null)return;if(Math.abs(o-$.size.height)>8){if(L4($.id,{width:$.size.width,height:o}),i.current!==null)window.clearTimeout(i.current);i.current=window.setTimeout(()=>{n$({recordHistory:!1}),i.current=null},0)}p.current=!0,d.disconnect()});return d.observe(f),()=>{if(d.disconnect(),i.current!==null)window.clearTimeout(i.current),i.current=null}},[$.id,$.type,$.data.mode,$.data.strictSize,$.collapsed,$.dockPosition,$.size.width,$.size.height]);let Y$=$.pinned,_$=$.type==="trace",x$=_$&&$.data.status==="running",S=$.type==="group",h=$.data.strictSize===!0,$$=Math.max(H$.value.scale,0.01),s=$$<1?Math.min(2.2,1/$$):1,K$=S&&$.data.color?$.data.color:void 0,J$={left:`${$.position.x}px`,top:`${$.position.y}px`,width:`${$.size.width}px`,height:$.collapsed?"auto":`${$.size.height}px`,zIndex:$.zIndex,"--node-chrome-scale":s.toFixed(3),...K$?{"--group-color":K$}:{}},e=["canvas-node",_?"active":"",K?"neighbor":"",B?"search-match":"",P?"search-dimmed":"",U?"selected":"",z?"context-pinned":"",b?"attention-focus-primary":"",J?"attention-focus-secondary":"",G?"attention-pulse":"",Y$?"pinned":"",_$?"trace-node":"",x$?"trace-running":"",S?"group-node":"",h?"strict-size":""].filter(Boolean).join(" ");return O("div",{class:e,style:J$,onPointerDown:N,onContextMenu:t,children:[O("div",{class:"node-titlebar",onPointerDown:c,children:[O("span",{class:"node-type-icon","aria-hidden":"true",children:(()=>{let f=ug($.type);return O(f,{size:Math.round(14*s)},void 0,!1,void 0,this)})()},void 0,!1,void 0,this),O("span",{class:"node-type-badge",children:a$[$.type]},void 0,!1,void 0,this),k?O("input",{ref:L,class:"node-title-input",value:r,onBlur:(f)=>y(f.target.value),onKeyDown:(f)=>{if(f.key==="Enter")y(f.target.value);if(f.key==="Escape")A(!1)},onClick:(f)=>f.stopPropagation()},void 0,!1,void 0,this):O("span",{class:"node-title",onDblClick:a,title:"Double-click to rename",children:r},void 0,!1,void 0,this),O("div",{class:"node-controls",children:[Y$&&O("span",{class:"pin-indicator",title:"Pinned",children:"⊙"},void 0,!1,void 0,this),O("button",{type:"button",class:`ctx-pin-btn${z?" ctx-pin-active":""}`,onClick:(f)=>{f.stopPropagation(),I4($.id)},title:z?"Remove from context":"Add to context",children:"✦"},void 0,!1,void 0,this),N0($)&&O("button",{type:"button",onClick:(f)=>{f.stopPropagation(),u0($)},title:"Open as site",children:"↗"},void 0,!1,void 0,this),__.has($.type)&&O("button",{type:"button",onClick:(f)=>{f.stopPropagation(),U6($.id)},title:"Expand (focus mode)",children:"⤢"},void 0,!1,void 0,this),O("button",{type:"button",onClick:(f)=>{f.stopPropagation(),Y6($.id)},title:$.collapsed?"Expand":"Collapse",children:$.collapsed?"▸":"▾"},void 0,!1,void 0,this),O("button",{type:"button",onClick:(f)=>{f.stopPropagation(),H4($.id),O_($.id)},title:"Close",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!$.collapsed&&O("div",{ref:v$,class:"node-body",children:v},void 0,!1,void 0,this),!$.collapsed&&O("div",{class:"node-resize-handle",onPointerDown:(f)=>u(f,$.size.width,$.size.height)},void 0,!1,void 0,this),["top","right","bottom","left"].map((f)=>O("div",{class:`node-port node-port-${f}`,onPointerDown:(d)=>{d.stopPropagation(),d.preventDefault();let W$=$.position.x+$.size.width/2,o=$.position.y+$.size.height/2,z$=$.size.width/2,B$=$.size.height/2,P$,R$;switch(f){case"top":P$=W$,R$=o-B$;break;case"bottom":P$=W$,R$=o+B$;break;case"left":P$=W$-z$,R$=o;break;case"right":P$=W$+z$,R$=o;break}Qv.value={fromId:$.id,fromX:P$,fromY:R$,cursorX:P$,cursorY:R$}}},f,!1,void 0,this))]},void 0,!0,void 0,this)}var gq={relation:"var(--c-muted)","depends-on":"var(--c-warn)",flow:"var(--c-accent)",references:"var(--c-dim)"},_q=new Set(["depends-on","flow"]);function zq($){if($.style==="dashed")return"8 4";if($.style==="dotted")return"3 3";if($.type==="references"&&!$.style)return"8 4";return}function HB($,v){let g=$.position.x+$.size.width/2,_=$.position.y+$.size.height/2,U=v.position.x+v.size.width/2,z=v.position.y+v.size.height/2,b=U-g,J=z-_,G=$.size.width/2,K=$.size.height/2,W=Math.abs(J/(b||0.001)),B=K/(G||0.001);if(W>B){let k=J>0?1:-1;return{x:g+K/W*(b>0?1:-1),y:_+K*k}}let P=b>0?1:-1;return{x:g+G*P,y:_+W*G*(J>0?1:-1)}}function bq($,v,g,_,U,z,b,J){return{x:0.125*$+0.375*g+0.375*U+0.125*b,y:0.125*v+0.375*_+0.375*z+0.125*J}}function Jq({edge:$,fromNode:v,toNode:g,focused:_,dimmed:U}){let z=HB(v,g),b=HB(g,v),J=b.x-z.x,G=b.y-z.y,K=Math.sqrt(J*J+G*G),W=Math.min(K*0.25,80),B=J/(K||1),P=G/(K||1),k=z.x+B*W,A=z.y+P*W,L=b.x-B*W,I=b.y-P*W,Y=`M ${z.x} ${z.y} C ${k} ${A}, ${L} ${I}, ${b.x} ${b.y}`,F=gq[$.type],X=_q.has($.type),Q=zq($),u=$.label?bq(z.x,z.y,k,A,L,I,b.x,b.y):null,c=`edge-path-${$.id}`;return O("g",{children:[O("path",{d:Y,fill:"none",stroke:"transparent","stroke-width":"12",style:{cursor:"pointer"}},void 0,!1,void 0,this),_&&O("path",{d:Y,fill:"none",stroke:F,"stroke-width":"6","stroke-dasharray":Q,opacity:"0.15",style:{filter:"blur(3px)"}},void 0,!1,void 0,this),O("path",{id:c,d:Y,fill:"none",stroke:F,"stroke-width":_?2.5:1.5,"stroke-dasharray":Q,"marker-end":X?"url(#edge-arrow)":void 0,opacity:U?0.2:_?1:0.75,style:{transition:"opacity 0.2s, stroke-width 0.2s"}},void 0,!1,void 0,this),$.animated&&O("circle",{r:"3",fill:F,opacity:"0.9",children:O("animateMotion",{dur:"2s",repeatCount:"indefinite",children:O("mpath",{href:`#${c}`},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),u&&$.label&&O("g",{transform:`translate(${u.x}, ${u.y})`,children:[O("rect",{class:"edge-label-bg",x:-($.label.length*3.5+8),y:"-10",width:$.label.length*7+16,height:"20",rx:"4"},void 0,!1,void 0,this),O("text",{class:"edge-label","text-anchor":"middle","dominant-baseline":"central",fill:"var(--c-text)","font-size":"11",children:$.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function LB({nodes:$,edges:v}){let g=$.value,_=Array.from(v.value.values()),U=T$.value,z=U!==null,b=H6.value,J=b!==null;if(_.length===0)return null;let G=96,K=Array.from(g.values()),W=Math.min(...K.map((I)=>I.position.x))-G,B=Math.min(...K.map((I)=>I.position.y))-G,P=Math.max(...K.map((I)=>I.position.x+I.size.width))+G,k=Math.max(...K.map((I)=>I.position.y+I.size.height))+G,A=Math.max(1,P-W),L=Math.max(1,k-B);return O("svg",{"aria-label":"Canvas connections",role:"img",viewBox:`${W} ${B} ${A} ${L}`,width:A,height:L,style:{position:"absolute",top:`${B}px`,left:`${W}px`,pointerEvents:"none",overflow:"visible"},children:[O("title",{children:"Canvas connections"},void 0,!1,void 0,this),O("defs",{children:O("marker",{id:"edge-arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"8",markerHeight:"8",orient:"auto-start-reverse",children:O("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),_.map((I)=>{let Y=g.get(I.from),F=g.get(I.to);if(!Y||!F)return null;let X=z&&(I.from===U||I.to===U),Q=J&&!(b.has(I.from)||b.has(I.to));return O(Jq,{edge:I,fromNode:Y,toNode:F,focused:X,dimmed:z&&!X||Q},I.id,!1,void 0,this)}),Qv.value&&(()=>{let I=Qv.value,Y=I.cursorX-I.fromX,F=I.cursorY-I.fromY,X=Math.sqrt(Y*Y+F*F),Q=Math.min(X*0.25,80),u=Y/(X||1),c=F/(X||1),N=`M ${I.fromX} ${I.fromY} C ${I.fromX+u*Q} ${I.fromY+c*Q}, ${I.cursorX-u*Q} ${I.cursorY-c*Q}, ${I.cursorX} ${I.cursorY}`;return O("g",{children:[O("path",{d:N,fill:"none",stroke:"var(--c-accent)","stroke-width":"6",opacity:"0.1",style:{filter:"blur(3px)"}},void 0,!1,void 0,this),O("path",{d:N,fill:"none",stroke:"var(--c-accent)","stroke-width":"2","stroke-dasharray":"6 4",opacity:"0.8"},void 0,!1,void 0,this),O("circle",{cx:I.cursorX,cy:I.cursorY,r:"5",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 Oq($){let[v,...g]=$;if(!v)return"";return g.reduce((_,U)=>`${_} L ${U.x} ${U.y}`,`M ${v.x} ${v.y}`)}function GG({annotations:$}){if($.length===0)return null;return O("svg",{class:"annotation-layer","aria-hidden":"true",children:$.map((v)=>{let g=v.color==="currentColor"?"var(--c-annotation)":v.color;if(v.type==="text"){let _=v.points[0];if(!_||!v.text)return null;return O("text",{x:_.x,y:_.y,fill:g,"font-size":v.width,"font-family":"var(--font)","font-weight":"700",opacity:"0.95",children:v.text},v.id,!1,void 0,this)}return O("path",{d:Oq(v.points),fill:"none",stroke:g,"stroke-width":v.width,"stroke-linecap":"round","stroke-linejoin":"round",opacity:"0.9"},v.id,!1,void 0,this)})},void 0,!1,void 0,this)}var Gq=0.1,Kq=4,YB=1;function FB($){return Math.min(Kq,Math.max(Gq,$))}function AB({viewport:$,onViewportChange:v,onViewportCommit:g,disabled:_=!1}){let U=V(null),z=V(!1),b=V({x:0,y:0}),J=V(0),G=V(null),K=M((I)=>{if(G.current!==null)window.clearTimeout(G.current);G.current=window.setTimeout(()=>{G.current=null,g(I)},140)},[g]),W=M((I)=>{if(_)return;I.preventDefault();let Y=$.value;if(I.ctrlKey||I.metaKey){let F=U.current?.getBoundingClientRect();if(!F)return;let X=I.clientX-F.left,Q=I.clientY-F.top,u=-I.deltaY*0.002,c=FB(Y.scale*(1+u)),N=c/Y.scale,t={x:X-N*(X-Y.x),y:Q-N*(Q-Y.y),scale:c};v(t),K(t)}else{let F={x:Y.x-I.deltaX*YB,y:Y.y-I.deltaY*YB,scale:Y.scale};v(F),K(F)}},[_,$,v,K]),B=M((I)=>{if(_)return;let Y=U.current;if(!Y||I.target!==Y)return;z.current=!0,b.current={x:I.clientX,y:I.clientY},Y.setPointerCapture(I.pointerId)},[_]),P=M((I)=>{if(!z.current)return;if(_)return;let Y=I.clientX-b.current.x,F=I.clientY-b.current.y;b.current={x:I.clientX,y:I.clientY};let X=$.value;v({x:X.x+Y,y:X.y+F,scale:X.scale})},[_,$,v]),k=M(()=>{if(z.current)g($.value);z.current=!1},[g,$]),A=M((I)=>{if(_)return;if(I.touches.length!==2){J.current=0;return}I.preventDefault();let Y=I.touches[0],F=I.touches[1],X=Math.hypot(F.clientX-Y.clientX,F.clientY-Y.clientY),Q=(Y.clientX+F.clientX)/2,u=(Y.clientY+F.clientY)/2;if(J.current>0){let c=$.value,N=U.current?.getBoundingClientRect();if(!N)return;let t=Q-N.left,a=u-N.top,r=X/J.current,y=FB(c.scale*r),v$=y/c.scale,p={x:t-v$*(t-c.x),y:a-v$*(a-c.y),scale:y};v(p),K(p)}J.current=X},[_,$,v,K]),L=M(()=>{if(G.current!==null)window.clearTimeout(G.current),G.current=null;g($.value),J.current=0},[g,$]);return m(()=>{let I=U.current;if(!I)return;return I.addEventListener("wheel",W,{passive:!1}),I.addEventListener("pointerdown",B),I.addEventListener("pointermove",P),I.addEventListener("pointerup",k),I.addEventListener("pointercancel",k),I.addEventListener("touchmove",A,{passive:!1}),I.addEventListener("touchend",L),()=>{if(G.current!==null)window.clearTimeout(G.current);I.removeEventListener("wheel",W),I.removeEventListener("pointerdown",B),I.removeEventListener("pointermove",P),I.removeEventListener("pointerup",k),I.removeEventListener("pointercancel",k),I.removeEventListener("touchmove",A),I.removeEventListener("touchend",L)}},[W,B,P,k,A,L]),U}function Wq($){switch($.type){case"markdown":return O(r_,{node:$},void 0,!1,void 0,this);case"mcp-app":return O(j6,{node:$},void 0,!1,void 0,this);case"webpage":return O(Q0,{node:$},void 0,!1,void 0,this);case"json-render":return O(j6,{node:$},void 0,!1,void 0,this);case"graph":return O(j6,{node:$},void 0,!1,void 0,this);case"prompt":return O(r0,{node:$},void 0,!1,void 0,this);case"response":return O(R0,{node:$},void 0,!1,void 0,this);case"status":return O(JU,{node:$},void 0,!1,void 0,this);case"context":return O(h6,{node:$},void 0,!1,void 0,this);case"ledger":return O(X4,{node:$},void 0,!1,void 0,this);case"trace":return O(y0,{node:$},void 0,!1,void 0,this);case"file":return O(Z_,{node:$},void 0,!1,void 0,this);case"image":return O(M0,{node:$},void 0,!1,void 0,this);case"html":return O(Qg,{node:$},void 0,!1,void 0,this);case"group":return O(wW,{node:$},void 0,!1,void 0,this);default:return O("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function Bq($,v,g){let _=g.x-v.x,U=g.y-v.y,z=_*_+U*U;if(z===0)return Math.hypot($.x-v.x,$.y-v.y);let b=Math.max(0,Math.min(1,(($.x-v.x)*_+($.y-v.y)*U)/z));return Math.hypot($.x-(v.x+b*_),$.y-(v.y+b*U))}function kq($,v,g){for(let _=$.length-1;_>=0;_--){let U=$[_];if(!U)continue;let z=g+U.width;if(v.x<U.bounds.x-z||v.x>U.bounds.x+U.bounds.width+z||v.y<U.bounds.y-z||v.y>U.bounds.y+U.bounds.height+z)continue;if(U.type==="text")return U;for(let b=1;b<U.points.length;b++){let J=U.points[b-1],G=U.points[b];if(J&&G&&Bq(v,J,G)<=g+U.width/2)return U}}return null}var KG="currentColor",qB=4,XB=24,Pq=14,Iq=new Set(["png","jpg","jpeg","gif","svg","webp","bmp","ico","avif"]),Hq=new Set(["md","mdx","markdown"]),wB={width:520,height:420};function Lq($){let v=$.trim();if(!v||/\s/.test(v))return null;let g=/^[a-z][a-z0-9+.-]*:/i.test(v)?v:`https://${v}`;try{let _=new URL(g);if(_.protocol!=="http:"&&_.protocol!=="https:")return null;return _.toString()}catch{return null}}function WG($){let v=$.trim();if(!v)return[];let g=v.includes(`
225
+ </script>`}function HA($,v){if(!v)return $;let g=/<head\b[^>]*>/i.exec($);if(g?.index!==void 0){let U=g.index+g[0].length;return`${$.slice(0,U)}${v}${$.slice(U)}`}let _=/<body\b[^>]*>/i.exec($);if(_?.index!==void 0){let U=_.index+_[0].length;return`${$.slice(0,U)}${v}${$.slice(U)}`}return`${v}${$}`}function zU($,v){if(Number.isFinite($)&&$>0)return Math.round($);if(Number.isFinite(v)&&v>0)return Math.round(v);return 1}function aO($,v){let g=$?.getBoundingClientRect();return{width:zU($?.clientWidth??0,zU(g?.width??0,v.width)),height:zU($?.clientHeight??0,zU(g?.height??0,v.height))}}function LA($,v){return typeof $==="number"&&Number.isFinite($)&&$>0&&!v}function YA($,v){return Math.max(zU($,1),zU(v,1))}function AW({node:$,expanded:v=!1}){let g=V(null),_=V(null),U=V(null),z=V(null),b=V({}),J=V(void 0),G=V(!1),K=V(void 0),W=V(null),B=V(!1),P=V(null),[k,A]=x("loading"),[L,I]=x(null),[Y,F]=x(0),X=$.data.html,Q=$.data.serverName,u=$.data.appSessionId,c=$.data.toolInput??{},N=$.data.toolResult,t=$.data.toolName??"ext-app",a=$.data.toolDefinition,r=$.data.toolCallId,y=typeof r==="string"||typeof r==="number"?r:void 0,v$=$.data.resourceMeta,p=$.data.sessionStatus,i=$.data.sessionError,Y$=$.size.height,_$=$.id,x$=BA($,Y),S=PA(null),$$=$.data.axCapabilities?.enabled===!0&&typeof X==="string"&&X.length>0,s=o$(()=>`ax-${crypto.randomUUID()}`,[]),K$=$$?IA(s,_$):"",J$=YW(HA(X??"",K$),S);m(()=>{if(!$$)return;function o(z$){if(z$.source!==g.current?.contentWindow)return;let B$=z$.data;if(!B$||B$.source!=="pmx-canvas-ax"||B$.token!==s||B$.nodeId!==_$)return;let P$=B$.interaction;if(!P$||typeof P$.type!=="string")return;let R$=P$.type;k6({type:R$,sourceNodeId:_$,sourceSurface:"mcp-app",...P$.payload&&typeof P$.payload==="object"?{payload:P$.payload}:{}}).then((Ov)=>{if(Ov.ok)Nv("context","AX interaction",R$,[_$]);else Nv("remove","AX interaction rejected",Ov.error??Ov.code??"",[_$]);g.current?.contentWindow?.postMessage({source:"pmx-canvas-ax-ack",token:s,...B$.correlationId?{correlationId:B$.correlationId}:{},interaction:{type:R$},result:Ov},"*")})}return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[$$,s,_$]);let e=(o)=>o==="light"?"light":"dark",f=v||c$.value===_$;b.current=c,J.current=N;let d=p==="error"?i??"Saved app session is unavailable. Reopen the app to restore interactivity.":"Reconnecting saved app session...",W$=(o)=>{let z$=J.current;if(!o||!B.current||!z$)return null;if(K.current===z$)return null;if(K.current&&IW(K.current,z$))return K.current=z$,null;if(W.current)return W.current;let B$=o.sendToolResult(z$).then(()=>{K.current=z$,G.current=!0,A("done")}).catch((P$)=>{let R$=P$ instanceof Error?P$.message:String(P$);throw I(`Tool result delivery failed: ${R$}`),P$}).finally(()=>{W.current=null});return W.current=B$,B$};if(m(()=>{if(!X||!J$.ready)return;let o=g.current;if(!o)return;let z$=!1,B$=null,P$=null,R$=null,Ov=null;G.current=!1,K.current=void 0,W.current=null,B.current=!1;let C6=()=>{if(!B$)return;clearTimeout(B$),B$=null};return(async()=>{if(!X)return;let Dv=o.contentWindow;if(!Dv)throw Error("Ext-app iframe window is unavailable");let Fv=(A$=c$.value===_$?"fullscreen":"inline")=>({theme:e(V$.value),platform:"web",containerDimensions:aO(o,{width:$.size.width,height:Y$}),displayMode:A$,locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,...a?{toolInfo:{id:y,tool:a}}:{}}),U4=()=>{if(R$!==null)return;R$=requestAnimationFrame(()=>{if(R$=null,z$||!B.current)return;y$.setHostContext?.(Fv())})},Tg=()=>{if(Ov!==null)return;Ov=requestAnimationFrame(()=>{Ov=requestAnimationFrame(()=>{if(Ov=null,z$||!B.current)return;y$.sendHostContextChange?.(Fv())})})},y$=new oO(null,{name:"PMX Canvas",version:"1.0.0"},{openLinks:{},serverTools:{listChanged:!1},serverResources:{listChanged:!1},logging:{},updateModelContext:{text:{},structuredContent:{}}},{hostContext:Fv(f?"fullscreen":"inline")});y$.onsizechange=async({height:A$})=>{if(LA(A$,c$.value===_$)){let Gv=aO(o.parentElement??o,{width:$.size.width,height:Y$}),cv=YA(A$,Gv.height);o.style.height=`${cv}px`;let f6=T.value.get(_$)?.size??$.size,XG=Math.max(f6.height,cv+h3);if(Math.abs(XG-f6.height)>8){if(L4(_$,{width:f6.width,height:XG}),z.current!==null)window.clearTimeout(z.current);z.current=window.setTimeout(()=>{n$({recordHistory:!1}),z.current=null},0)}}return{}},y$.onopenlink=async({url:A$})=>{return window.open(A$,"_blank","noopener"),{}},y$.onsandboxready=async()=>{await y$.sendSandboxResourceReady({html:X,sandbox:dO,...v$?.csp?{csp:v$.csp}:{},...v$?.permissions?{permissions:v$.permissions}:{}})},y$.onrequestdisplaymode=async({mode:A$})=>{let{nextMode:Gv,shouldExpand:cv,shouldCollapse:f6}=kA(A$,f);if(cv)U6(_$);else if(f6)l6();return{mode:Gv}},y$.oncalltool=async(A$)=>{if(!u)throw Error(d);try{let Gv=await e6("/api/ext-app/call-tool",{sessionId:u,nodeId:_$,serverName:Q,toolName:A$.name,arguments:A$.arguments??{}});return I(null),Gv}catch(Gv){let cv=Gv instanceof Error?Gv.message:String(Gv);throw I(`Tool call failed: ${cv}`),Gv}},y$.setRequestHandler(qg,async()=>{if(!u)return{tools:[]};return e6("/api/ext-app/list-tools",{sessionId:u})}),y$.onlistresources=async()=>u?e6("/api/ext-app/list-resources",{sessionId:u}):{resources:[]},y$.onlistresourcetemplates=async()=>u?e6("/api/ext-app/list-resource-templates",{sessionId:u}):{resourceTemplates:[]},y$.onreadresource=async(A$)=>{if(!u)throw Error(d);return e6("/api/ext-app/read-resource",{sessionId:u,uri:A$.uri})},y$.onlistprompts=async()=>u?e6("/api/ext-app/list-prompts",{sessionId:u}):{prompts:[]},y$.onupdatemodelcontext=async(A$)=>{if(!u)return{};return await e6("/api/ext-app/model-context",{nodeId:_$,...Array.isArray(A$.content)?{content:A$.content}:{},...A$.structuredContent&&typeof A$.structuredContent==="object"?{structuredContent:A$.structuredContent}:{}}),{}};let c0=new X0(Dv,Dv);if(y$.oninitialized=()=>{if(z$)return;C6(),B.current=!0,A("ready"),I(null),Promise.resolve(y$.sendHostContextChange(Fv(f?"fullscreen":"inline"))).then(()=>FW(y$,b.current,void 0)).then(()=>W$(y$)).then(()=>Tg()).catch((A$)=>{let Gv=A$ instanceof Error?A$.message:String(A$);I(`Bridge bootstrap failed: ${Gv}`)})},B$=setTimeout(()=>{if(z$||B.current)return;let A$=J.current,Gv=Fv(f?"fullscreen":"inline");B.current=!0,y$.setHostContext?.(Gv),Promise.resolve(y$.sendHostContextChange(Gv)).then(()=>FW(y$,b.current,A$)).then(()=>{if(G.current=Boolean(A$),A$)K.current=A$;A(A$?"done":"ready"),I(null),Tg()}).catch((cv)=>{let f6=cv instanceof Error?cv.message:String(cv);I(`Bridge bootstrap fallback failed: ${f6}`)})},1200),await y$.connect(c0),z$){C6(),await c0.close();return}if(_.current=y$,U.current=c0,P$=new ResizeObserver(U4),P$.observe(o),o.parentElement)P$.observe(o.parentElement);let qG=!0;P.current=V$.subscribe((A$)=>{if(qG){qG=!1;return}if(z$)return;y$.setHostContext?.({...Fv(),theme:e(A$)}),y$.sendHostContextChange?.(Fv())}),W$(y$)})().catch((Dv)=>{C6(),console.error("[ext-app] Bridge init failed:",Dv),I(Dv?.message??"Bridge initialization failed")}),()=>{if(z$=!0,C6(),P$?.disconnect(),P$=null,R$!==null)cancelAnimationFrame(R$),R$=null;if(Ov!==null)cancelAnimationFrame(Ov),Ov=null;if(B.current=!1,W.current=null,P.current?.(),P.current=null,z.current!==null)window.clearTimeout(z.current),z.current=null;if(_.current=null,U.current)U.current.close().catch((Dv)=>{console.error("[ext-app] transport close failed:",Dv)}),U.current=null}},[x$,J$.key]),m(()=>{if(N&&_.current&&(k==="ready"||k==="done"))W$(_.current)},[N,k]),m(()=>{let o=_.current;if(g.current)g.current.style.height="100%";if(!o||!B.current)return;let z$=null,B$=null;return z$=requestAnimationFrame(()=>{z$=null,B$=requestAnimationFrame(()=>{if(B$=null,!B.current)return;let P$={theme:e(V$.value),platform:"web",containerDimensions:aO(g.current,{width:$.size.width,height:Y$}),displayMode:f?"fullscreen":"inline",locale:navigator.language,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};o.setHostContext?.(P$),o.sendHostContextChange?.(P$)})}),()=>{if(z$!==null)cancelAnimationFrame(z$);if(B$!==null)cancelAnimationFrame(B$)}},[f,Y$]),!X)return O("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--c-muted)",fontSize:"13px",flexDirection:"column",gap:"8px"},children:[O("div",{style:{opacity:0.6},children:["Loading ",t," viewer..."]},void 0,!0,void 0,this),O("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),O("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return O("div",{style:{flex:1,width:"100%",height:"100%",minWidth:0,minHeight:0,display:"flex",flexDirection:"column"},children:[p&&p!=="ready"&&O("div",{style:{padding:"6px 10px",fontSize:"11px",background:p==="error"?"var(--c-danger-12)":"var(--c-warn-10)",color:p==="error"?"var(--c-danger)":"var(--c-warn)",borderBottom:`1px solid ${p==="error"?"var(--c-danger-12)":"var(--c-warn-15)"}`},children:d},void 0,!1,void 0,this),L&&O("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:[O("span",{children:"⚠"},void 0,!1,void 0,this),O("span",{style:{flex:1},children:L},void 0,!1,void 0,this),O("button",{type:"button",onClick:()=>{I(null),A("loading"),F((o)=>o+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),O("button",{type:"button",onClick:()=>I(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),k==="loading"&&O("div",{style:{padding:"8px",fontSize:"11px",color:"var(--c-muted)"},children:"Connecting to ext-app viewer..."},void 0,!1,void 0,this),O("div",{style:{flex:1,position:"relative",display:"flex",minHeight:0,height:"100%"},children:[O("iframe",{ref:g,...J$.attributes,sandbox:S,allow:PW(v$?.permissions),style:{flex:1,width:"100%",height:"100%",minHeight:0,border:"none",background:"var(--c-panel)",pointerEvents:f&&k!=="loading"?"auto":"none"},title:`Ext App: ${t}`},x$,!1,void 0,this),!f&&O("button",{type:"button",onClick:(o)=>{o.stopPropagation(),U6(_$)},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 w0($,v,g){let _=V($);_.current=$;let U=V(null);m(()=>{if(!g)return;function z(b){if(b.source!==v.current?.contentWindow)return;let J=b.data;if(!J||J.source!=="pmx-canvas-frame"||J.type!=="content-height"||J.token!==g)return;let G=_.current,K=typeof J.height==="number"?J.height:0,W=o3(G,K);if(W===null)return;if(L4(G.id,{width:G.size.width,height:W}),U.current!==null)window.clearTimeout(U.current);U.current=window.setTimeout(()=>{n$({recordHistory:!1}),U.current=null},300)}return window.addEventListener("message",z),()=>{if(window.removeEventListener("message",z),U.current!==null)window.clearTimeout(U.current),U.current=null}},[$.id,g])}function FA($,v,g,_,U,z,b){if(!$)return $;try{let J=new URL($,window.location.origin);if(J.searchParams.set("theme",V$.value==="light"?"light":"dark"),v)J.searchParams.set("display","expanded");if(typeof g==="number")J.searchParams.set("v",String(g));if(_)J.searchParams.set("axToken",_);if(U)J.searchParams.set("axNodeId",U);if(z)J.searchParams.set("frameToken",z);if(b)J.searchParams.set("fit","content");return J.toString()}catch{return $}}function AA($,v=window.location.origin){if(!$)return!1;try{let g=new URL(v).origin,_=new URL($,g);return _.origin===g&&_.pathname.startsWith("/api/canvas/frame-documents/")}catch{return!1}}function j6({node:$,expanded:v=!1}){if($.data.mode==="ext-app")return O(AW,{node:$,expanded:v},void 0,!1,void 0,this);return O(qA,{node:$,expanded:v},void 0,!1,void 0,this)}function qA({node:$,expanded:v}){let g=V(null),_=$.type==="mcp-app"&&$.data.viewerType==="web-artifact",U=$.type==="json-render"||$.type==="graph",z=$.data.axCapabilities?.enabled,J=(U||_)&&(_?z===!0:z!==!1),G=_?"mcp-app":"json-render",K=o$(()=>J?`ax-${crypto.randomUUID()}`:"",[J]),W=j2($)&&!v,B=o$(()=>W?`frame-${crypto.randomUUID()}`:"",[W]);w0($,g,B),m(()=>{if(!J||!K)return;function Q(u){if(u.source!==g.current?.contentWindow)return;let c=u.data;if(!c||c.source!=="pmx-canvas-ax"||c.token!==K||c.nodeId!==$.id)return;let N=c.interaction;if(!N||typeof N.type!=="string")return;let t=N.type;k6({type:t,sourceNodeId:$.id,sourceSurface:G,...N.payload&&typeof N.payload==="object"?{payload:N.payload}:{}}).then((a)=>{if(a.ok)Nv("context","AX interaction",t,[$.id]);else Nv("remove","AX interaction rejected",a.error??a.code??"",[$.id]);g.current?.contentWindow?.postMessage({source:"pmx-canvas-ax-ack",token:K,...c.correlationId?{correlationId:c.correlationId}:{},interaction:{type:t},result:a},"*")})}return window.addEventListener("message",Q),()=>window.removeEventListener("message",Q)},[J,K,$.id]);let P=I6.value,k=()=>{if(!J||!K||P==null)return;g.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"ax-update",token:K,state:P},"*")};m(k,[J,K,P]);let A=typeof $.data.specVersion==="number"?$.data.specVersion:void 0,L=FA($.data.url||"",v,A,K||void 0,J?$.id:void 0,B||void 0,W),I=$.data.sourceServer||"",Y=$.data.hostMode||"hosted",F=$.data.fallbackReason,X=$.data.trustedDomain===!0||AA(L);if(Y==="fallback")return O("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[O("div",{style:{color:"var(--c-warn)",display:"flex",alignItems:"center",gap:"6px"},children:[O("span",{children:"⚠"},void 0,!1,void 0,this),O("span",{children:"Cannot embed — opened externally"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F&&O("div",{style:{color:"var(--c-muted)",fontSize:"11px"},children:["Reason: ",F]},void 0,!0,void 0,this),O("a",{href:L,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all"},children:L},void 0,!1,void 0,this),I&&O("div",{style:{color:"var(--c-dim)",fontSize:"10px"},children:["Source: ",I]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return O("div",{style:{height:"100%",display:"flex",flexDirection:"column",...v?{flex:1,minHeight:0,width:"100%"}:{}},children:[!X&&O("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),O("iframe",{ref:g,src:L,class:"mcp-app-frame",sandbox:"allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox",allow:"clipboard-read; clipboard-write",loading:"lazy",onLoad:k,style:{flex:1,minHeight:0,width:"100%"},title:`MCP App: ${I}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Mg=null;function t$($){return getComputedStyle(document.documentElement).getPropertyValue($).trim()}function Z0(){if(Mg)return Mg;return Mg={bg:t$("--c-bg"),panel:t$("--c-panel"),panelSoft:t$("--c-panel-soft"),line:t$("--c-line"),text:t$("--c-text"),textSoft:t$("--c-text-soft"),muted:t$("--c-muted"),dim:t$("--c-dim"),accent:t$("--c-accent"),ok:t$("--c-ok"),warn:t$("--c-warn"),warnAlt:t$("--c-warn-alt"),danger:t$("--c-danger"),purple:t$("--c-purple"),thinking:t$("--c-thinking"),subagent:t$("--c-subagent"),font:t$("--font"),mono:t$("--mono")},Mg}function bU(){Mg=null}var S0={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 sO($){let v=typeof $.data.phase==="string"&&$.data.phase.trim().length>0?$.data.phase.trim():"";if(v)return v;let g=typeof $.data.content==="string"&&$.data.content.trim().length>0?$.data.content.trim():"";if(g)return g;return(typeof $.data.status==="string"&&$.data.status.trim().length>0?$.data.status.trim():"")||"idle"}function JU({node:$}){let v=sO($),g=$.data.detail||"",_=$.data.message||"",U=$.data.level||"ok",z=$.data.activeTool,b=$.data.subagent,J=S0[v]??"var(--c-muted)",G=v!=="idle";return O("div",{style:{display:"flex",flexDirection:"column",gap:"8px",fontSize:"12px"},children:[O("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[O("div",{style:{width:"8px",height:"8px",borderRadius:"50%",background:J,boxShadow:G?`0 0 8px ${J}`:"none",animation:G?"pulse 1.5s infinite":"none",flexShrink:0}},void 0,!1,void 0,this),O("span",{style:{fontWeight:600,color:J,textTransform:"uppercase",letterSpacing:"0.05em"},children:v},void 0,!1,void 0,this),g&&O("span",{style:{color:"var(--c-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z&&O("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-warn)"},children:[O("span",{style:{fontSize:"10px"},children:"⚙"},void 0,!1,void 0,this),O("span",{style:{fontFamily:"var(--mono)",fontSize:"11px"},children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b&&b.state!=="completed"&&O("div",{style:{display:"flex",alignItems:"center",gap:"6px",color:"var(--c-subagent)"},children:[O("span",{style:{fontSize:"10px"},children:"⠉"},void 0,!1,void 0,this),O("span",{children:b.name},void 0,!1,void 0,this),O("span",{style:{color:"var(--c-muted)",fontSize:"10px"},children:["(",b.state,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),_&&O("div",{style:{color:U==="warn"?"var(--c-warn)":U==="error"?"var(--c-danger)":"var(--c-muted)",lineHeight:1.4},children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function OU($){return typeof $==="string"&&$.trim().length>0?$.trim():null}function qW($){if(typeof $==="string"){let U=OU($);return U?{title:"Evidence warning",detail:U}:null}if(!$||typeof $!=="object")return null;let v=$,g=OU(v.title)??"Evidence warning",_=OU(v.detail);return _?{title:g,detail:_}:null}function XA($){let v=[],g=qW($.data.warning);if(g)v.push(g);let _=$.data.warnings;if(Array.isArray(_))for(let z of _){let b=qW(z);if(b)v.push(b)}let U=OU($.data.validationStatus)?.toLowerCase();if(U==="failed"||U==="invalid")v.push({title:"Image failed validation",detail:OU($.data.validationMessage)??"Review this image before using it as evidence."});return v}function wA($){let v=[$.data.title,$.data.caption,$.data.alt,$.data.src,$.data.path].map((g)=>OU(g)?.toLowerCase()??"").join(" ");if(v.length===0)return!1;return["login","log in","sign in","signin","password","2fa","mfa","authenticate","authentication","sso"].some((g)=>v.includes(g))}function XW($){let v=XA($);if(v.length>0)return v;if(wA($))return[{title:"Captured login page",detail:"This image looks like an auth screen. Treat it as environment context, not product evidence."}];return[]}function M0({node:$,expanded:v=!1}){let g=$.data.src||"",_=$.data.alt||$.data.title||"Image",U=$.data.caption||"",z=XW($),b=g.startsWith("data:")||g.startsWith("http://")||g.startsWith("https://")?g:`/api/canvas/image/${$.id}`,[J,G]=x(!1),[K,W]=x(!1),[B,P]=x(1),[k,A]=x({x:0,y:0}),[L,I]=x({w:0,h:0}),Y=V(null),F=V(!1),X=V({x:0,y:0}),Q=M((p)=>{let i=p.target;I({w:i.naturalWidth,h:i.naturalHeight}),G(!0),W(!1)},[]),u=M(()=>{W(!0),G(!1)},[]);m(()=>{P(1),A({x:0,y:0})},[g]);let c=M((p)=>{p.preventDefault(),p.stopPropagation();let i=p.deltaY>0?0.9:1.1;P((Y$)=>Math.max(0.25,Math.min(10,Y$*i)))},[]),N=M((p)=>{if(B<=1)return;p.stopPropagation(),F.current=!0,X.current={x:p.clientX,y:p.clientY},p.target.setPointerCapture(p.pointerId)},[B]),t=M((p)=>{if(!F.current)return;let i=p.clientX-X.current.x,Y$=p.clientY-X.current.y;X.current={x:p.clientX,y:p.clientY},A((_$)=>({x:_$.x+i,y:_$.y+Y$}))},[]),a=M(()=>{F.current=!1},[]),r=M(()=>{P(1),A({x:0,y:0})},[]);if(!g)return O("div",{class:"image-node-empty",children:[O("div",{class:"image-node-empty-icon",children:"\uD83D\uDDBC"},void 0,!1,void 0,this),O("div",{class:"image-node-empty-text",children:"No image source"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let y=L.w>0?`${L.w}×${L.h}`:"",v$=Math.round(B*100);return O("div",{class:`image-node ${v?"image-node-expanded":""}`,ref:Y,children:[z.length>0&&O("div",{class:"image-node-warning-stack",children:z.map((p)=>O("div",{class:"image-node-warning",children:[O("span",{class:"image-node-warning-title",children:p.title},void 0,!1,void 0,this),O("span",{class:"image-node-warning-detail",children:p.detail},void 0,!1,void 0,this)]},`${p.title}-${p.detail}`,!0,void 0,this))},void 0,!1,void 0,this),O("div",{class:"image-node-viewport",onWheel:c,onPointerDown:N,onPointerMove:t,onPointerUp:a,style:{cursor:B>1?"grab":"default"},children:[!J&&!K&&O("div",{class:"image-node-loading",children:"Loading…"},void 0,!1,void 0,this),K&&O("div",{class:"image-node-error",children:[O("div",{class:"image-node-error-icon",children:"⚠"},void 0,!1,void 0,this),O("div",{children:"Failed to load image"},void 0,!1,void 0,this),O("div",{class:"image-node-error-path",children:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("img",{src:b,alt:_,onLoad:Q,onError:u,draggable:!1,style:{transform:`translate(${k.x}px, ${k.y}px) scale(${B})`,opacity:J?1:0,display:K?"none":"block"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(U||y||B!==1)&&O("div",{class:"image-node-footer",children:[U&&O("span",{class:"image-node-caption",children:U},void 0,!1,void 0,this),O("span",{class:"image-node-meta",children:[y&&O("span",{children:y},void 0,!1,void 0,this),B!==1&&O("button",{type:"button",class:"image-node-zoom-reset",onClick:r,title:"Reset zoom",children:[v$,"% ↺"]},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 wW({node:$}){let v=$.data.children??[],g=T.value,_=v.filter((J)=>g.has(J)),U=_.length,z={};for(let J of _){let G=g.get(J);if(G)z[G.type]=(z[G.type]??0)+1}let b=Object.entries(z).map(([J,G])=>`${G} ${J}`).join(", ");return O("div",{class:"group-node-body",children:[O("div",{class:"group-summary",children:[O("span",{class:"group-child-count",children:[U," node",U!==1?"s":""]},void 0,!0,void 0,this),b&&O("span",{class:"group-type-summary",children:b},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U===0&&O("div",{class:"group-empty-hint",children:"Drag nodes here or use the selection bar to group nodes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ZA($){try{return new URL($).host}catch{return $}}function SA($){if(!$)return null;let v=new Date($);return Number.isNaN(v.getTime())?null:v.toLocaleString()}function Q0({node:$,expanded:v=!1}){let g=typeof $.data.url==="string"?$.data.url:"",_=typeof $.data.pageTitle==="string"?$.data.pageTitle:"",U=typeof $.data.description==="string"?$.data.description:"",z=typeof $.data.excerpt==="string"?$.data.excerpt:typeof $.data.content==="string"?$.data.content:"",b=typeof $.data.status==="string"?$.data.status:"idle",J=typeof $.data.error==="string"?$.data.error:"",G=SA(typeof $.data.fetchedAt==="string"?$.data.fetchedAt:void 0),K=typeof $.data.statusCode==="number"?$.data.statusCode:null,W=typeof $.data.imageUrl==="string"?$.data.imageUrl:"",B=$.data.frameBlocked===!0,P=typeof $.data.frameBlockedReason==="string"?$.data.frameBlockedReason:"",[k,A]=x(!1),[L,I]=x(v);m(()=>{if(v)I(!0)},[v]);let Y=M(async()=>{if(!g||k)return;A(!0);try{await J_($.id)}finally{A(!1)}},[$.id,k,g]);if(!g)return O("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No webpage URL set"},void 0,!1,void 0,this);let F=b==="ready"?"var(--c-ok)":b==="error"?"var(--c-danger)":"var(--c-warn)";return O("div",{style:{display:"flex",flexDirection:"column",gap:"12px",height:"100%"},children:[O("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[O("div",{style:{minWidth:0,flex:1},children:[O("div",{style:{fontSize:"12px",color:"var(--c-muted)"},children:ZA(g)},void 0,!1,void 0,this),O("div",{style:{fontSize:v?"18px":"15px",fontWeight:700,color:"var(--c-text)"},children:_||$.data.title||g},void 0,!1,void 0,this),O("a",{href:g,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--c-accent)",fontSize:"12px",wordBreak:"break-all",textDecoration:"none"},children:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"999px",background:"rgba(255,255,255,0.04)",color:F,fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.04em",flexShrink:0},children:[O("span",{style:{width:"7px",height:"7px",borderRadius:"999px",background:F}},void 0,!1,void 0,this),b]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),(U||W)&&O("div",{style:{display:"grid",gridTemplateColumns:W&&v?"160px 1fr":"1fr",gap:"12px",alignItems:"start"},children:[W&&v&&O("img",{src:W,alt:_||"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),U&&O("p",{style:{margin:0,color:"var(--c-text-soft)",lineHeight:1.5,fontSize:v?"14px":"12px"},children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{style:{display:"flex",gap:"8px",flexWrap:"wrap"},children:[O("button",{type:"button",onClick:Y,disabled:k,style:{border:"1px solid var(--c-line)",background:"var(--c-panel-soft)",color:"var(--c-text)",borderRadius:"8px",padding:"6px 10px",cursor:k?"progress":"pointer",fontSize:"12px"},children:k||b==="fetching"?"Refreshing…":"Refresh"},void 0,!1,void 0,this),v&&!B&&O("button",{type:"button",onClick:()=>I((X)=>!X),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:L?"Hide live preview":"Show live preview"},void 0,!1,void 0,this),O("button",{type:"button",onClick:()=>window.open(g,"_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),v&&B&&O("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[O("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),O("div",{style:{padding:"20px",color:"var(--c-text-soft)",lineHeight:1.6,fontSize:"13px"},children:P||"The remote site blocks iframe embedding."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v&&L&&!B&&O("div",{style:{border:"1px solid var(--c-line)",borderRadius:"12px",overflow:"hidden",background:"var(--c-panel-soft)"},children:[O("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),O("iframe",{class:"webpage-node-iframe",title:_||$.data.title||g,src:g,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:v?"320px":"180px",border:"none",background:"#fff"}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(G||K!==null)&&O("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap",color:"var(--c-muted)",fontSize:"11px"},children:[G&&O("span",{children:["Fetched ",G]},void 0,!0,void 0,this),K!==null&&O("span",{children:["HTTP ",K]},void 0,!0,void 0,this),B&&O("span",{children:"Preview blocked by site"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J&&O("div",{style:{color:"var(--c-danger)",fontSize:"12px",lineHeight:1.5},children:J},void 0,!1,void 0,this),O("div",{style:{flex:1,minHeight:0,overflow:"auto",border:"1px solid var(--c-line)",borderRadius:"10px",background:"var(--c-panel-soft)",padding:v?"14px":"10px"},children:z?O("div",{style:{whiteSpace:"pre-wrap",lineHeight:1.55,color:"var(--c-text)",fontSize:v?"14px":"12px"},children:z},void 0,!1,void 0,this):O("div",{style:{color:"var(--c-dim)",fontStyle:"italic"},children:b==="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 ZW($){let v=5381;for(let g=0;g<$.length;g+=1)v=(v<<5)+v+$.charCodeAt(g)|0;return(v>>>0).toString(36)}function eO($,v={}){let g=new URLSearchParams;if(g.set("theme",v.theme??V$.value),v.themeToken)g.set("themeToken",v.themeToken);if(v.present)g.set("present","1");if(v.presentToken)g.set("presentToken",v.presentToken);if(v.v)g.set("v",v.v);if(v.axToken)g.set("axToken",v.axToken);if(v.frameToken)g.set("frameToken",v.frameToken);return`/api/canvas/surface/${encodeURIComponent($)}?${g.toString()}`}function N0($){return HW($.type,$.data)}async function u0($){let v=eO($.id);if(!(await LK($.id,v)).opened)window.open(v,"_blank","noopener")}function SW($){return $.type==="html"&&$.data.presentation===!0}function Qg({node:$,expanded:v=!1,presentation:g=!1,presentationExitToken:_,autoFocus:U=!1}){let z=V(null),b=V$.value,J=o$(()=>`theme-${crypto.randomUUID()}`,[]),G=o$(()=>`ax-${crypto.randomUUID()}`,[]),K=o$(()=>`frame-${crypto.randomUUID()}`,[]),W=typeof $.data.html==="string"?$.data.html:typeof $.data.content==="string"?$.data.content:"",B=o$(()=>ZW(W),[W]),P=o$(()=>W?eO($.id,{theme:b,themeToken:J,present:g,presentToken:_,v:B,axToken:G,frameToken:K}):"",[W,g,_,J,B,$.id,G,K]);w0($,z,v?"":K),m(()=>{function Y(F){if(F.source!==z.current?.contentWindow)return;let X=F.data;if(!X||X.source!=="pmx-canvas-ax"||X.token!==G||X.nodeId!==$.id)return;let Q=X.interaction;if(!Q||typeof Q.type!=="string")return;let u=Q.type;k6({type:u,sourceNodeId:$.id,sourceSurface:"html-node",...Q.payload&&typeof Q.payload==="object"?{payload:Q.payload}:{}}).then((c)=>{if(c.ok)Nv("context","AX interaction",u,[$.id]);else Nv("remove","AX interaction rejected",c.error??c.code??"",[$.id]);z.current?.contentWindow?.postMessage({source:"pmx-canvas-ax-ack",token:G,...X.correlationId?{correlationId:X.correlationId}:{},interaction:{type:u},result:c},"*")})}return window.addEventListener("message",Y),()=>window.removeEventListener("message",Y)},[G,$.id]),m(()=>{if(z.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"theme-update",token:J,theme:b},"*"),U)z.current?.focus()},[b,J]);let k=$.data.axCapabilities,A=k?.enabled===!0&&(!Array.isArray(k.allowed)||k.allowed.length>0),L=I6.value;m(()=>{if(!A||L==null)return;z.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"ax-update",token:G,state:L},"*")},[A,L,G]),m(()=>{if(!U)return;let Y=window.setTimeout(()=>z.current?.focus(),0);return()=>window.clearTimeout(Y)},[U,P]);let I=()=>{if(z.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"theme-update",token:J,theme:b},"*"),A&&I6.value!=null)z.current?.contentWindow?.postMessage({source:"pmx-canvas-html-node",type:"ax-update",token:G,state:I6.value},"*");if(U)z.current?.focus()};if(!W)return O("div",{style:{color:"var(--c-dim)",fontStyle:"italic",padding:"12px"},children:"No HTML content set"},void 0,!1,void 0,this);return O("iframe",{ref:z,class:g?"html-node-frame html-node-frame-presentation":"html-node-frame",title:typeof $.data.title==="string"?$.data.title:"HTML node",sandbox:"allow-scripts",src:P,tabIndex:U?0:void 0,onLoad:I,style:{width:"100%",height:"100%",minHeight:g?0:v?"70vh":"300px",border:"none",background:"var(--c-bg)",borderRadius:g?0:"6px",display:"block"}},void 0,!1,void 0,this)}var $G=null;async function MW(){if(!$G)$G=await kK();return $G}function QW($,v){if(!$)return null;let g=$.toLowerCase(),_=v.find((z)=>z.name.toLowerCase()===g);if(_)return _.name;let U=v.filter((z)=>z.name.toLowerCase().startsWith(g));return U.length===1?U[0].name:null}function MA($){return $.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 QA({html:$}){let v=V(null);return m(()=>{let g=v.current;if(!g)return;if(g.replaceChildren(),!$)return;let _=document.createElement("template");_.innerHTML=$,g.append(_.content.cloneNode(!0))},[$]),O("div",{ref:v},void 0,!1,void 0,this)}function NA($,v){return`${$.role}:${$.status??"none"}:${v}:${$.text}`}function NW({count:$}){if($===0)return null;return O("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:["✦"," ",$," context node",$!==1?"s":""," attached"]},void 0,!0,void 0,this)}function uW({message:$,onDismiss:v}){if(!$)return null;return O("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:[O("span",{style:{flex:1},children:$},void 0,!1,void 0,this),O("button",{type:"button",onClick:v,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 r0({node:$,expanded:v=!1}){let g=Array.isArray($.data.turns)?$.data.turns:[],_=g.length===0,U=$.data.text||"",z=$.data.status||"draft",b=_?z:$.data.threadStatus||"draft",J=b==="draft",G=b==="pending"||b==="sending",K=b==="streaming",W=b==="answered",[B,P]=x(""),[k,A]=x(""),[L,I]=x(null),[Y,F]=x(new Map),X=V(null),Q=V(null),u=g[g.length-1],c=`${g.length}:${u?.role??""}:${u?.status??""}:${Math.floor((u?.text?.length??0)/200)}`;m(()=>{if(v&&J&&X.current)X.current.focus()},[v,J]),m(()=>{if(!c)return;if(Q.current)Q.current.scrollTo({top:Q.current.scrollHeight,behavior:"smooth"})},[c]);let N=V(null),t=V(g);t.current=g,m(()=>{let i=g.some((_$)=>_$.role==="assistant"&&_$.status==="streaming"),Y$=()=>{let _$=!1,S=t.current.map((h,$$)=>({turn:h,index:$$})).filter(({turn:h})=>h.role==="assistant"&&h.text);if(S.length===0)return;return Promise.all(S.map(async({turn:h,index:$$})=>{let s=await $6(h.text);return{index:$$,html:MA(s)}})).then((h)=>{if(_$)return;let $$=new Map;for(let s of h)$$.set(s.index,s.html);F($$)}),()=>{_$=!0}};if(!i){if(N.current)clearTimeout(N.current),N.current=null;return Y$()}if(N.current)clearTimeout(N.current);return N.current=setTimeout(()=>{N.current=null,Y$()},400),()=>{if(N.current)clearTimeout(N.current),N.current=null}},[g]);let a=M(async()=>{let i=B.trim();if(!i)return;let Y$=B;I(null),g$($.id,{turns:[{role:"user",text:i,status:"pending"}],threadStatus:"pending",text:i}),P("");let _$=Array.isArray($.data.contextNodeIds)?$.data.contextNodeIds:void 0;if(!(await AU(i,$.position,$.id,_$,$.id)).ok)g$($.id,{turns:[],threadStatus:"draft",text:"",status:"draft"}),P(Y$),I("Failed to send prompt. Your draft has been restored.")},[B,$.id,$.position,$.data.contextNodeIds]),r=M(async()=>{let i=k.trim();if(!i)return;let Y$=k;I(null);let _$=Array.isArray($.data.turns)?[...$.data.turns]:[];if(_$.push({role:"user",text:i,status:"pending"}),g$($.id,{turns:_$,threadStatus:"pending"}),A(""),!(await PK($.id,i)).ok)_$.pop(),g$($.id,{turns:_$,threadStatus:"answered"}),A(Y$),I("Failed to send reply. Your draft has been restored.")},[k,$.id,$.data.turns]),y=M((i)=>{if(i.key==="Enter"&&(i.metaKey||i.ctrlKey)){i.preventDefault(),a();return}if(i.key==="Tab"&&B.startsWith("/")){i.preventDefault();let Y$=B.slice(1).split(/\s/)[0];if(Y$)MW().then((_$)=>{let x$=QW(Y$,_$);if(x$)P(`/${x$}`)})}},[a,B]),v$=M((i)=>{if(i.key==="Enter"&&(i.metaKey||i.ctrlKey)){i.preventDefault(),r();return}if(i.key==="Tab"&&k.startsWith("/")){i.preventDefault();let Y$=k.slice(1).split(/\s/)[0];if(Y$)MW().then((_$)=>{let x$=QW(Y$,_$);if(x$)A(`/${x$}`)})}},[r,k]),p=Array.isArray($.data.contextNodeIds)?$.data.contextNodeIds.length:0;if(J&&g.length===0)return O("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%",gap:"8px"},children:[O(NW,{count:p},void 0,!1,void 0,this),O(uW,{message:L,onDismiss:()=>I(null)},void 0,!1,void 0,this),O("textarea",{ref:X,value:B,onInput:(i)=>P(i.target.value),onKeyDown:y,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),O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[O("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter to send"]},void 0,!0,void 0,this),O("button",{type:"button",onClick:a,disabled:!B.trim(),style:{padding:"5px 14px",fontSize:"12px",fontWeight:600,background:B.trim()?"var(--c-accent)":"var(--c-line)",color:B.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:B.trim()?"pointer":"default"},children:"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(_)return O("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[O("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:U},void 0,!1,void 0,this),O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:"6px",borderTop:"1px solid var(--c-line)",marginTop:"4px"},children:O("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:G?"var(--c-warn)":W?"var(--c-ok)":"var(--c-muted)"},children:G?"Sending…":W?"Answered":z},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return O("div",{class:"prompt-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[O(NW,{count:p},void 0,!1,void 0,this),O(uW,{message:L,onDismiss:()=>I(null)},void 0,!1,void 0,this),O("div",{ref:Q,style:{flex:1,overflow:"auto",minHeight:0},children:g.map((i,Y$)=>O("div",{children:[Y$>0&&O("div",{class:"thread-turn-divider"},void 0,!1,void 0,this),i.role==="user"?O("div",{class:"thread-turn-user",children:[O("div",{class:"thread-turn-role",children:[O("span",{class:"status-dot"},void 0,!1,void 0,this),"You"]},void 0,!0,void 0,this),O("div",{style:{fontSize:v?"15px":"13px",lineHeight:v?"1.7":"1.55",color:"var(--c-text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:i.text},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O("div",{class:"thread-turn-assistant",children:[O("div",{class:"thread-turn-role",children:[O("span",{class:`status-dot${i.status==="streaming"?" pulsing":""}`},void 0,!1,void 0,this),"PMX"]},void 0,!0,void 0,this),i.status==="streaming"&&!i.text&&O("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),O("div",{class:v?"md-reader-content":void 0,style:{fontSize:v?void 0:"13px",lineHeight:v?void 0:"1.55",opacity:i.text?1:0.4},children:Y.get(Y$)?O(d$,{children:[O(QA,{html:Y.get(Y$)??""},void 0,!1,void 0,this),i.status==="streaming"&&O("span",{class:"streaming-cursor"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O("div",{style:{color:"var(--c-muted)",fontStyle:"italic"},children:i.status==="streaming"?"Waiting for response…":i.text||"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},NA(i,Y$),!0,void 0,this))},void 0,!1,void 0,this),O("div",{style:{flexShrink:0,borderTop:"1px solid var(--c-line)",marginTop:"4px",paddingTop:"6px"},children:[O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:W?"6px":0},children:[O("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:K?"var(--c-accent)":G?"var(--c-warn)":W?"var(--c-ok)":"var(--c-muted)"},children:K?"Streaming…":G?"Sending…":W?"Answered":b},void 0,!1,void 0,this),O("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:[g.length," turn",g.length!==1?"s":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),W&&O("div",{class:"thread-reply-area",children:[O("textarea",{value:k,onInput:(i)=>A(i.target.value),onKeyDown:v$,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),O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"4px"},children:[O("span",{style:{fontSize:"10px",color:"var(--c-muted)"},children:["⌘","+Enter"]},void 0,!0,void 0,this),O("button",{type:"button",onClick:r,disabled:!k.trim(),style:{padding:"3px 10px",fontSize:"11px",fontWeight:600,background:k.trim()?"var(--c-accent)":"var(--c-line)",color:k.trim()?"var(--c-contrast-fg)":"var(--c-muted)",border:"none",borderRadius:"var(--radius-sm)",cursor:k.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 uA($){return $.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 rA({html:$}){let v=V(null);return m(()=>{let g=v.current;if(!g)return;if(g.replaceChildren(),!$)return;let _=document.createElement("template");_.innerHTML=$,g.append(_.content.cloneNode(!0))},[$]),O("div",{ref:v},void 0,!1,void 0,this)}function R0({node:$,expanded:v=!1}){let g=$.data.content||"",_=$.data.status||"streaming",[U,z]=x(""),b=_==="streaming",J=_==="complete";m(()=>{if(!g){z("");return}let K=!1;return $6(g).then((W)=>{if(!K)z(uA(W))}),()=>{K=!0}},[g]);let G=M(()=>{AU("",{x:$.position.x,y:$.position.y+$.size.height+24},$.id)},[$]);return O("div",{class:"response-node-inner",style:{display:"flex",flexDirection:"column",height:"100%"},children:[b&&O("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),O("div",{class:v?"md-reader":void 0,style:{flex:1,overflow:"auto",minHeight:0,opacity:g?1:0.4,transition:"opacity 0.2s ease"},children:U?O("div",{class:v?"md-reader-content":void 0,children:O(rA,{html:U},void 0,!1,void 0,this)},void 0,!1,void 0,this):O("div",{style:{color:"var(--c-muted)",fontStyle:"italic",fontSize:"13px"},children:b?"Waiting for response…":"Empty response"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:"6px",borderTop:"1px solid var(--c-line)",marginTop:"4px",flexShrink:0},children:[O("span",{style:{fontSize:"10px",textTransform:"uppercase",fontWeight:600,color:b?"var(--c-accent)":J?"var(--c-ok)":"var(--c-muted)"},children:b?"Streaming…":J?"Complete":_},void 0,!1,void 0,this),J&&O("button",{type:"button",onClick:G,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 rW($){return{toolName:$.toolName||$.title||"unknown",category:$.category||"other",status:$.status||"running",duration:$.duration||"",resultSummary:$.resultSummary||$.content||"",error:$.error||""}}var RW={mcp:"var(--c-accent)",file:"var(--c-warn)",subagent:"var(--c-purple)",other:"var(--c-muted)"},RA={running:"⠋",success:"✓",failed:"✕"},yA={running:"var(--c-accent)",success:"var(--c-ok)",failed:"var(--c-danger)"};function y0({node:$}){let{toolName:v,category:g,status:_,duration:U,resultSummary:z,error:b}=rW($.data),J=RW[g]??RW.other,G=RA[_]??"◌",K=yA[_]??"var(--c-muted)",W=_==="running",B=b?b.slice(0,30):z.length>30?`${z.slice(0,28)}…`:z;return O("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"0 12px",height:"100%",overflow:"hidden"},children:[O("span",{style:{fontSize:"14px",color:K,flexShrink:0,animation:W?"pulse 1.5s infinite":"none"},children:G},void 0,!1,void 0,this),O("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:[O("div",{style:{fontFamily:"var(--mono)",fontSize:"11px",fontWeight:600,color:J,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v},void 0,!1,void 0,this),B&&O("div",{style:{fontSize:"10px",color:b?"var(--c-danger)":"var(--c-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:1.3},children:B},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&O("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:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function UG($){let v=T.value.get($);if(!v||v.dockPosition!==null)return null;return{left:v.position.x,top:v.position.y,width:v.size.width,height:v.size.height}}function DA($){let v=$.map((G)=>UG(G)).filter((G)=>G!==null);if(v.length===0)return null;let g=Math.min(...v.map((G)=>G.left)),_=Math.min(...v.map((G)=>G.top)),U=Math.max(...v.map((G)=>G.left+G.width)),z=Math.max(...v.map((G)=>G.top+G.height)),b=54,J=46;return{left:g-b,top:_-J,width:U-g+b*2,height:z-_+J*2}}function vG($,v){return{left:`${$.left}px`,top:`${$.top}px`,width:`${$.width}px`,height:`${$.height}px`,borderRadius:`${v}px`}}function yW(){let $=Array.from(G4.value),v=Array.from(K4.value),g=sg.value;if($.length===0&&v.length===0)return null;return O("div",{class:"attention-field-layer","aria-hidden":"true",children:[g.map((_)=>{let U=DA(_.nodeIds);if(!U)return null;return O("div",{class:"attention-field-region",style:vG(U,42)},_.id,!1,void 0,this)}),v.map((_)=>{let U=UG(_);if(!U)return null;return O("div",{class:"attention-field-node attention-field-secondary",style:vG({left:U.left-18,top:U.top-18,width:U.width+36,height:U.height+36},28)},`secondary-${_}`,!1,void 0,this)}),$.map((_)=>{let U=UG(_);if(!U)return null;return O("div",{class:"attention-field-node attention-field-primary",style:vG({left:U.left-24,top:U.top-24,width:U.width+48,height:U.height+48},30)},`primary-${_}`,!1,void 0,this)})]},void 0,!0,void 0,this)}var Mv=k$(new Map),GU=k$(null),TA=480,jA=320,Ng=new Map,O6=null;function gG($){Mv.value=$,CA()}function _G($){let v=Ng.get($);if(v)clearTimeout(v),Ng.delete($)}function DW($){_G($.id);let v=new Map(Mv.value);v.set($.id,{...$,phase:"forming"}),gG(v)}function VA($){if(_G($),!Mv.value.has($))return;let v=new Map(Mv.value);v.delete($),gG(v)}function TW($,v,g,_){let U=Mv.value.get($);if(!U||U.phase===v)return;let z=new Map(Mv.value);z.set($,{...U,phase:v,..._?{settledNodeId:_}:{}}),gG(z),_G($),Ng.set($,setTimeout(()=>VA($),g))}function jW($,v){TW($,"settling",TA,v)}function zG($){TW($,"dissolving",jA)}function VW(){for(let $ of Ng.values())clearTimeout($);if(Ng.clear(),O6)clearInterval(O6),O6=null;GU.value=null,Mv.value=new Map}function CA(){if(O6||Mv.value.size===0)return;O6=setInterval(()=>{let $=Date.now();for(let v of Mv.value.values())if(v.phase==="forming"&&v.expiresAt<=$)zG(v.id);if(Mv.value.size===0&&O6)clearInterval(O6),O6=null},1000),O6.unref?.()}var fA={fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"};function q$({size:$=16,children:v,...g}){return O("svg",{width:$,height:$,viewBox:"0 0 16 16",...fA,...g,children:v},void 0,!1,void 0,this)}function cW($){return O(q$,{...$,children:[O("polyline",{points:"1 5 1 1 5 1"},void 0,!1,void 0,this),O("polyline",{points:"11 1 15 1 15 5"},void 0,!1,void 0,this),O("polyline",{points:"15 11 15 15 11 15"},void 0,!1,void 0,this),O("polyline",{points:"5 15 1 15 1 11"},void 0,!1,void 0,this),O("rect",{x:"4",y:"4",width:"8",height:"8",rx:"1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function mW($){return O(q$,{...$,children:[O("rect",{x:"2",y:"2",width:"12",height:"12",rx:"2"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"4.5",x2:"8",y2:"6.5"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"9.5",x2:"8",y2:"11.5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"8",x2:"6.5",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"9.5",y1:"8",x2:"11.5",y2:"8"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function EW($){return O(q$,{...$,children:[O("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),O("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),O("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this),O("line",{x1:"7",y1:"5",x2:"7",y2:"9"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function iW($){return O(q$,{...$,children:[O("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),O("line",{x1:"10.5",y1:"10.5",x2:"14.5",y2:"14.5"},void 0,!1,void 0,this),O("line",{x1:"5",y1:"7",x2:"9",y2:"7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function lW($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),O("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),O("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),O("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1"},void 0,!1,void 0,this),O("line",{x1:"6.5",y1:"4",x2:"9.5",y2:"4"},void 0,!1,void 0,this),O("line",{x1:"6.5",y1:"12",x2:"9.5",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"6.5",x2:"4",y2:"9.5"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"6.5",x2:"12",y2:"9.5"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function hW($){return O(q$,{...$,children:[O("rect",{x:"1",y:"2",width:"14",height:"12",rx:"1.5"},void 0,!1,void 0,this),O("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 xW($){return O(q$,{...$,children:[O("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"1",x2:"8",y2:"3"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"13",x2:"8",y2:"15"},void 0,!1,void 0,this),O("line",{x1:"1",y1:"8",x2:"3",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"13",y1:"8",x2:"15",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"3.05",y1:"3.05",x2:"4.46",y2:"4.46"},void 0,!1,void 0,this),O("line",{x1:"11.54",y1:"11.54",x2:"12.95",y2:"12.95"},void 0,!1,void 0,this),O("line",{x1:"3.05",y1:"12.95",x2:"4.46",y2:"11.54"},void 0,!1,void 0,this),O("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 pW($){return O(q$,{...$,children:O("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 oW($){return O(q$,{...$,children:[O("path",{d:"M3 13l2.8-.7L13 5.1 10.9 3 3.7 10.2 3 13Z"},void 0,!1,void 0,this),O("path",{d:"M9.8 4.1l2.1 2.1"},void 0,!1,void 0,this),O("path",{d:"M2.5 14h11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function nW($){return O(q$,{...$,children:[O("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),O("path",{d:"M7.5 6 12 10.5"},void 0,!1,void 0,this),O("path",{d:"M8.5 14H14"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function tW($){return O(q$,{...$,children:[O("path",{d:"M3 4h10"},void 0,!1,void 0,this),O("path",{d:"M8 4v8"},void 0,!1,void 0,this),O("path",{d:"M6 12h4"},void 0,!1,void 0,this),O("path",{d:"M4.5 4 4 6"},void 0,!1,void 0,this),O("path",{d:"M11.5 4 12 6"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function dW($){return O(q$,{...$,children:[O("rect",{x:"1",y:"4",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),O("path",{d:"M5.5 4 L6.5 2.5 H9.5 L10.5 4"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"9",r:"2.3"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function aW($){return O(q$,{...$,children:[O("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),O("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 sW($){return O(q$,{...$,children:[O("circle",{cx:"8",cy:"8",r:"6"},void 0,!1,void 0,this),O("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"10.5"},void 0,!1,void 0,this),O("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 eW($){return O(q$,{...$,children:[O("circle",{cx:"7",cy:"7",r:"4.5"},void 0,!1,void 0,this),O("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 $B($){return O(q$,{...$,children:[O("rect",{x:"1",y:"3",width:"14",height:"10",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"6",x2:"5",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"7.5",y1:"6",x2:"8.5",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"11",y1:"6",x2:"12",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"10",x2:"12",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function vB({size:$=22,class:v}){return O("svg",{width:$,height:$,viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",class:v,"aria-hidden":"true",children:[O("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),O("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),O("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),O("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 CW($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"6",x2:"10",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"8.5",x2:"8",y2:"8.5"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"11",x2:"11",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function cA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),O("path",{d:"M4 13.5 L5.5 11.5 L8 11.5"},void 0,!1,void 0,this),O("polyline",{points:"5 6 7 8 5 10"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"10",x2:"11",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function mA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"9",rx:"1.5"},void 0,!1,void 0,this),O("path",{d:"M12 13.5 L10.5 11.5 L8 11.5"},void 0,!1,void 0,this),O("circle",{cx:"5",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"7",r:"0.9",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("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 EA($){return O(q$,{...$,children:[O("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),O("polyline",{points:"9 1.5 9 5 12.5 5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"8.5",x2:"10.5",y2:"8.5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"11",x2:"9",y2:"11"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function iA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("circle",{cx:"5.5",cy:"6.5",r:"1.2"},void 0,!1,void 0,this),O("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 fW($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"1.5",y1:"5.5",x2:"14.5",y2:"5.5"},void 0,!1,void 0,this),O("circle",{cx:"3.3",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"5",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"6.7",cy:"4",r:"0.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"8",x2:"12",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"4",y1:"10",x2:"10",y2:"10"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function lA($){return O(q$,{...$,children:[O("rect",{x:"2",y:"4",width:"12",height:"10",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"2",y1:"6.5",x2:"14",y2:"6.5"},void 0,!1,void 0,this),O("path",{d:"M11 1.5 L11 4"},void 0,!1,void 0,this),O("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 hA($){return O(q$,{...$,children:[O("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),O("rect",{x:"4",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),O("rect",{x:"8.5",y:"4",width:"3.5",height:"3.5",rx:"0.6"},void 0,!1,void 0,this),O("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 xA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("circle",{cx:"4.5",cy:"8",r:"1.1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("line",{x1:"6.5",y1:"6.5",x2:"12.5",y2:"6.5"},void 0,!1,void 0,this),O("line",{x1:"6.5",y1:"8",x2:"11",y2:"8"},void 0,!1,void 0,this),O("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 pA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("path",{d:"M3.5 10.5 L6 6.5 L8.5 9.5 L12.5 5"},void 0,!1,void 0,this),O("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 oA($){return O(q$,{...$,children:[O("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"5.5",x2:"11.5",y2:"5.5"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"8",x2:"11.5",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"4.5",y1:"10.5",x2:"8",y2:"10.5"},void 0,!1,void 0,this),O("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 nA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"1.5",width:"13",height:"13",rx:"2"},void 0,!1,void 0,this),O("path",{d:"M4 11 L4 6 L6 8.5 L8 6 L8 11"},void 0,!1,void 0,this),O("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 tA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("polyline",{points:"10 5 13 5 13 8"},void 0,!1,void 0,this),O("line",{x1:"13",y1:"5",x2:"8",y2:"10"},void 0,!1,void 0,this),O("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 dA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("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),O("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 aA($){return O(q$,{...$,children:[O("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"},void 0,!1,void 0,this),O("line",{x1:"5.2",y1:"6",x2:"8",y2:"8"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"8",x2:"10.8",y2:"6"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"8",x2:"8",y2:"11"},void 0,!1,void 0,this),O("circle",{cx:"5.2",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"10.8",cy:"6",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"8",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this),O("circle",{cx:"8",cy:"11",r:"1",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ug($){switch($){case"markdown":return CW;case"prompt":return cA;case"response":return mA;case"file":return EA;case"image":return iA;case"webpage":return fW;case"context":return lA;case"group":return hA;case"status":return xA;case"trace":return pA;case"ledger":return oA;case"mcp-app":return nA;case"ext-app":return tA;case"json-render":return dA;case"graph":return aA;case"html":return fW;default:return CW}}var UB={width:260,height:150},sA={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 JG($){return!!$&&$ in a$}function G6($){if(!$)return null;let v=T.value.get($);if(!v||v.dockPosition!==null)return null;return{left:v.position.x,top:v.position.y,width:v.size.width,height:v.size.height}}function bG($){return{x:$.left+$.width/2,y:$.top+$.height/2}}function rg($){if(typeof $.confidence!=="number")return 0.82;return 0.4+Math.max(0,Math.min(1,$.confidence))*0.55}function gB($,v){let g=Math.max(40,Math.abs(v.x-$.x)/2);return`M ${$.x} ${$.y} C ${$.x+g} ${$.y}, ${v.x-g} ${v.y}, ${v.x} ${v.y}`}function OG({intent:$}){let v=JG($.nodeType)?ug($.nodeType):null,g=$.label||$.kind,_=typeof $.confidence==="number"?`${Math.round($.confidence*100)}%`:null;return O("div",{class:"intent-info",onMouseEnter:()=>GU.value=$.id,onMouseLeave:()=>{if(GU.value===$.id)GU.value=null},children:[O("div",{class:"intent-chip",children:[typeof $.seq==="number"&&O("span",{class:"intent-seq",children:$.seq},void 0,!1,void 0,this),v&&O("span",{class:"intent-chip-icon","aria-hidden":"true",children:O(v,{size:12},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("span",{class:"intent-chip-label",children:g},void 0,!1,void 0,this),_&&O("span",{class:"intent-confidence",children:_},void 0,!1,void 0,this),$.phase==="forming"&&O("button",{type:"button",class:"intent-veto",title:"Veto this move (Esc)","aria-label":"Veto this move",onClick:(U)=>{U.stopPropagation(),z2($)},children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$.reason&&O("div",{class:"intent-reason",children:$.reason},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _B({intent:$,rect:v}){let g=JG($.nodeType)?ug($.nodeType):null,_=JG($.nodeType)?a$[$.nodeType]:"Node";return O("div",{class:`intent-ghost intent-ghost-box is-${$.phase}`,"data-intent-id":$.id,style:{left:`${v.left}px`,top:`${v.top}px`,width:`${v.width}px`,height:`${v.height}px`,opacity:rg($)},children:[O("div",{class:"intent-ghost-titlebar",children:[O("span",{class:"intent-ghost-icon","aria-hidden":"true",children:g?O(g,{size:13},void 0,!1,void 0,this):"◇"},void 0,!1,void 0,this),O("span",{class:"intent-ghost-badge",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O(OG,{intent:$},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zB({intent:$,rect:v,variant:g}){return O("div",{class:`intent-ghost intent-ghost-${g} is-${$.phase}`,"data-intent-id":$.id,style:{left:`${v.left}px`,top:`${v.top}px`,width:`${v.width}px`,height:`${v.height}px`,opacity:rg($)},children:[g==="edit"&&O("div",{class:"intent-edit-bar"},void 0,!1,void 0,this),O(OG,{intent:$},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function eA($){let v=$.phase==="settling"?G6($.settledNodeId):null;switch($.kind){case"create":{if(!$.position)return null;let g=$.nodeType&&sA[$.nodeType]||UB,_=v??{left:$.position.x,top:$.position.y,...g};return O(_B,{intent:$,rect:_},$.id,!1,void 0,this)}case"move":{if(!$.position)return null;let _=G6($.nodeId)??UB,U=v??{left:$.position.x,top:$.position.y,width:_.width,height:_.height};return O(_B,{intent:$,rect:U},$.id,!1,void 0,this)}case"remove":{let g=v??G6($.nodeId);if(!g)return null;return O(zB,{intent:$,rect:g,variant:"remove"},$.id,!1,void 0,this)}case"edit":{let g=v??G6($.nodeId);if(!g)return null;return O(zB,{intent:$,rect:g,variant:"edit"},$.id,!1,void 0,this)}case"connect":{if(!$.edge)return null;let g=G6($.edge.from),_=G6($.edge.to);if(!g||!_)return null;let U={x:(g.left+g.width/2+_.left+_.width/2)/2,y:(g.top+g.height/2+_.top+_.height/2)/2},z={left:U.x-110,top:U.y-18,width:220,height:36};return O("div",{class:`intent-ghost intent-ghost-connect is-${$.phase}`,"data-intent-id":$.id,style:{left:`${z.left}px`,top:`${z.top}px`,width:`${z.width}px`,opacity:rg($)},children:O(OG,{intent:$},void 0,!1,void 0,this)},$.id,!1,void 0,this)}default:return null}}function bB(){let $=Array.from(Mv.value.values());if(m(()=>{function v(g){if(g.key!=="Escape")return;let _=GU.value;if(!_)return;let U=Mv.value.get(_);if(!U||U.phase!=="forming")return;g.stopImmediatePropagation(),g.preventDefault(),z2(U)}return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[]),$.length===0)return null;return O("div",{class:"intent-layer",children:[O("svg",{class:"intent-line-layer",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},children:[O("defs",{children:O("marker",{id:"intent-arrow",markerWidth:"8",markerHeight:"8",refX:"6",refY:"3",orient:"auto",children:O("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),$.map((v)=>{if(v.kind==="connect"&&v.edge){let g=G6(v.edge.from),_=G6(v.edge.to);if(!g||!_)return null;return O("path",{d:gB(bG(g),bG(_)),class:`intent-edge type-${v.edge.type}`,style:{opacity:rg(v)}},`line-${v.id}`,!1,void 0,this)}if(v.kind==="move"&&v.position){let g=G6(v.nodeId);if(!g)return null;let _=g,U={x:v.position.x+_.width/2,y:v.position.y+_.height/2};return O("path",{d:gB(bG(g),U),class:"intent-trail",markerEnd:"url(#intent-arrow)",style:{opacity:rg(v)}},`line-${v.id}`,!1,void 0,this)}return null})]},void 0,!0,void 0,this),$.map(eA)]},void 0,!0,void 0,this)}var KU=8,$4=k$(null),WU=[],BU=[],GB=null;function JB($){let v=$?.data.parentGroup;return typeof v==="string"&&v.length>0?v:null}function OB($){if(!$||!Array.isArray($.data.children))return[];return $.data.children.filter((v)=>typeof v==="string")}function $q($,v){let g=new Map(v.map((J)=>[J.id,J])),_=new Set([$]),U=g.get($);if(!U)return _;let z=JB(U);while(z&&!_.has(z))_.add(z),z=JB(g.get(z));if(U.type!=="group")return _;let b=[...OB(U)];while(b.length>0){let J=b.pop();if(!J||_.has(J))continue;_.add(J);let G=g.get(J);if(G?.type==="group")b.push(...OB(G))}return _}function KB($,v){WU=[],BU=[],GB=$;let g=Array.from(v),_=$q($,g);for(let U of g){if(_.has(U.id)||U.dockPosition!==null)continue;let z=U.position.x,b=U.position.x+U.size.width,J=U.position.x+U.size.width/2,G=U.position.y,K=U.position.y+U.size.height,W=U.position.y+U.size.height/2;WU.push({val:z,minY:G,maxY:K}),WU.push({val:b,minY:G,maxY:K}),WU.push({val:J,minY:G,maxY:K}),BU.push({val:G,minX:z,maxX:b}),BU.push({val:K,minX:z,maxX:b}),BU.push({val:W,minX:z,maxX:b})}}function WB(){WU=[],BU=[],GB=null}function BB($,v,g,_){let U=[$,$+g/2,$+g],z=[v,v+_/2,v+_],b=[0,g/2,g],J=[0,_/2,_],G=null,K=KU+1,W=null;for(let L=0;L<3;L++){let I=U[L];for(let Y of WU){let F=Math.abs(I-Y.val);if(F<K)K=F,G=Y.val-b[L],W={axis:"x",pos:Y.val,from:Math.min(Y.minY,v),to:Math.max(Y.maxY,v+_)}}}let B=null,P=KU+1,k=null;for(let L=0;L<3;L++){let I=z[L];for(let Y of BU){let F=Math.abs(I-Y.val);if(F<P)P=F,B=Y.val-J[L],k={axis:"y",pos:Y.val,from:Math.min(Y.minX,$),to:Math.max(Y.maxX,$+g)}}}let A=[];if(W&&K<=KU)A.push(W);if(k&&P<=KU)A.push(k);return{x:G!==null&&K<=KU?G:$,y:B!==null&&P<=KU?B:v,guides:A}}function kB({nodeId:$,viewport:v,onMove:g,onDragEnd:_}){let U=V(!1),z=V({x:0,y:0}),b=V({x:0,y:0});return M((G,K,W)=>{G.stopPropagation(),G.preventDefault(),U.current=!0,document.documentElement.classList.add("is-node-dragging"),window.getSelection()?.removeAllRanges(),z.current={x:G.clientX,y:G.clientY},b.current={x:K,y:W};let B=null,P=null,k=()=>{if(P=null,!U.current||!B)return;let I=B;B=null;let Y=v.value.scale,F=(I.x-z.current.x)/Y,X=(I.y-z.current.y)/Y;g($,b.current.x+F,b.current.y+X)},A=(I)=>{if(!U.current)return;if(B={x:I.clientX,y:I.clientY},P!==null)return;P=window.requestAnimationFrame(k)},L=()=>{if(P!==null)window.cancelAnimationFrame(P),k();U.current=!1,document.documentElement.classList.remove("is-node-dragging"),document.removeEventListener("pointermove",A),document.removeEventListener("pointerup",L),document.removeEventListener("pointercancel",L),_()};document.addEventListener("pointermove",A),document.addEventListener("pointerup",L),document.addEventListener("pointercancel",L)},[$,v,g,_])}var vq=200,Uq=100;function PB({nodeId:$,viewport:v,onResize:g,onResizeEnd:_}){let U=V(!1),z=V({x:0,y:0}),b=V({w:0,h:0});return M((G,K,W)=>{G.stopPropagation(),G.preventDefault(),U.current=!0,z.current={x:G.clientX,y:G.clientY},b.current={w:K,h:W},document.documentElement.classList.add("is-node-resizing");let B=null,P=null,k=()=>{if(P=null,!U.current||!B)return;let I=B;B=null;let Y=v.value.scale,F=(I.x-z.current.x)/Y,X=(I.y-z.current.y)/Y;g($,Math.max(vq,b.current.w+F),Math.max(Uq,b.current.h+X))},A=(I)=>{if(!U.current)return;if(B={x:I.clientX,y:I.clientY},P!==null)return;P=window.requestAnimationFrame(k)},L=()=>{if(P!==null)window.cancelAnimationFrame(P),k();U.current=!1,document.documentElement.classList.remove("is-node-resizing"),document.removeEventListener("pointermove",A),document.removeEventListener("pointerup",L),document.removeEventListener("pointercancel",L),_()};document.addEventListener("pointermove",A),document.addEventListener("pointerup",L),document.addEventListener("pointercancel",L)},[$,v,g,_])}function IB({node:$,children:v,onContextMenu:g}){let _=T$.value===$.id,U=i$.value.has($.id),z=j$.value.has($.id),b=G4.value.has($.id),J=!b&&K4.value.has($.id),G=eg.value.has($.id),K=!_&&NK.value.has($.id),W=H6.value,B=W!==null&&W.has($.id),P=W!==null&&!W.has($.id),[k,A]=x(!1),L=V(null),I=M((f,d,W$)=>{let o=BB(d,W$,$.size.width,$.size.height),z$=T.value.get(f);if(z$?.position.x===o.x&&z$.position.y===o.y){$4.value=o.guides.length>0?o.guides:null;return}Kv(f,{position:{x:o.x,y:o.y}}),$4.value=o.guides.length>0?o.guides:null},[$.size.width,$.size.height]),Y=M(()=>{WB(),$4.value=null,n$()},[]),F=kB({nodeId:$.id,viewport:H$,onMove:I,onDragEnd:Y}),X=M((f,d,W$)=>{let o=T.value.get(f);if(o?.size.width===d&&o.size.height===W$)return;Kv(f,{size:{width:d,height:W$}})},[]),Q=M(()=>{g$($.id,{userResized:!0}),Av($.id,{data:{userResized:!0}}),n$()},[$.id]),u=PB({nodeId:$.id,viewport:H$,onResize:X,onResizeEnd:Q}),c=M((f)=>{if(k)return;L6($.id),KB($.id,T.value.values()),F(f,$.position.x,$.position.y)},[$.id,$.position.x,$.position.y,F,k]),N=M((f)=>{if(f.stopPropagation(),f.shiftKey){uK($.id);return}L6($.id)},[$.id]),t=M((f)=>{if(g)g(f,$.id)},[g,$.id]),a=M((f)=>{f.stopPropagation(),A(!0),requestAnimationFrame(()=>L.current?.focus())},[]),r=$.data.title||a$[$.type],y=M((f)=>{let d=f.trim();if(d&&d!==r)g$($.id,{title:d}),Av($.id,{title:d});A(!1)},[$.id,r]),v$=V(null),p=V(!1),i=V(null);m(()=>{if(p.current||!T2($))return;let f=v$.current;if(!f)return;let d=new ResizeObserver(()=>{if(p.current){d.disconnect();return}let W$=f.scrollHeight,o=p3($,W$);if(o===null)return;if(Math.abs(o-$.size.height)>8){if(L4($.id,{width:$.size.width,height:o}),i.current!==null)window.clearTimeout(i.current);i.current=window.setTimeout(()=>{n$({recordHistory:!1}),i.current=null},0)}p.current=!0,d.disconnect()});return d.observe(f),()=>{if(d.disconnect(),i.current!==null)window.clearTimeout(i.current),i.current=null}},[$.id,$.type,$.data.mode,$.data.strictSize,$.collapsed,$.dockPosition,$.size.width,$.size.height]);let Y$=$.pinned,_$=$.type==="trace",x$=_$&&$.data.status==="running",S=$.type==="group",h=$.data.strictSize===!0,$$=Math.max(H$.value.scale,0.01),s=$$<1?Math.min(2.2,1/$$):1,K$=S&&$.data.color?$.data.color:void 0,J$={left:`${$.position.x}px`,top:`${$.position.y}px`,width:`${$.size.width}px`,height:$.collapsed?"auto":`${$.size.height}px`,zIndex:$.zIndex,"--node-chrome-scale":s.toFixed(3),...K$?{"--group-color":K$}:{}},e=["canvas-node",_?"active":"",K?"neighbor":"",B?"search-match":"",P?"search-dimmed":"",U?"selected":"",z?"context-pinned":"",b?"attention-focus-primary":"",J?"attention-focus-secondary":"",G?"attention-pulse":"",Y$?"pinned":"",_$?"trace-node":"",x$?"trace-running":"",S?"group-node":"",h?"strict-size":""].filter(Boolean).join(" ");return O("div",{class:e,style:J$,onPointerDown:N,onContextMenu:t,children:[O("div",{class:"node-titlebar",onPointerDown:c,children:[O("span",{class:"node-type-icon","aria-hidden":"true",children:(()=>{let f=ug($.type);return O(f,{size:Math.round(14*s)},void 0,!1,void 0,this)})()},void 0,!1,void 0,this),O("span",{class:"node-type-badge",children:a$[$.type]},void 0,!1,void 0,this),k?O("input",{ref:L,class:"node-title-input",value:r,onBlur:(f)=>y(f.target.value),onKeyDown:(f)=>{if(f.key==="Enter")y(f.target.value);if(f.key==="Escape")A(!1)},onClick:(f)=>f.stopPropagation()},void 0,!1,void 0,this):O("span",{class:"node-title",onDblClick:a,title:"Double-click to rename",children:r},void 0,!1,void 0,this),O("div",{class:"node-controls",children:[Y$&&O("span",{class:"pin-indicator",title:"Pinned",children:"⊙"},void 0,!1,void 0,this),O("button",{type:"button",class:`ctx-pin-btn${z?" ctx-pin-active":""}`,onClick:(f)=>{f.stopPropagation(),I4($.id)},title:z?"Remove from context":"Add to context",children:"✦"},void 0,!1,void 0,this),N0($)&&O("button",{type:"button",onClick:(f)=>{f.stopPropagation(),u0($)},title:"Open as site",children:"↗"},void 0,!1,void 0,this),__.has($.type)&&O("button",{type:"button",onClick:(f)=>{f.stopPropagation(),U6($.id)},title:"Expand (focus mode)",children:"⤢"},void 0,!1,void 0,this),O("button",{type:"button",onClick:(f)=>{f.stopPropagation(),Y6($.id)},title:$.collapsed?"Expand":"Collapse",children:$.collapsed?"▸":"▾"},void 0,!1,void 0,this),O("button",{type:"button",onClick:(f)=>{f.stopPropagation(),H4($.id),O_($.id)},title:"Close",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!$.collapsed&&O("div",{ref:v$,class:"node-body",children:v},void 0,!1,void 0,this),!$.collapsed&&O("div",{class:"node-resize-handle",onPointerDown:(f)=>u(f,$.size.width,$.size.height)},void 0,!1,void 0,this),["top","right","bottom","left"].map((f)=>O("div",{class:`node-port node-port-${f}`,onPointerDown:(d)=>{d.stopPropagation(),d.preventDefault();let W$=$.position.x+$.size.width/2,o=$.position.y+$.size.height/2,z$=$.size.width/2,B$=$.size.height/2,P$,R$;switch(f){case"top":P$=W$,R$=o-B$;break;case"bottom":P$=W$,R$=o+B$;break;case"left":P$=W$-z$,R$=o;break;case"right":P$=W$+z$,R$=o;break}Qv.value={fromId:$.id,fromX:P$,fromY:R$,cursorX:P$,cursorY:R$}}},f,!1,void 0,this))]},void 0,!0,void 0,this)}var gq={relation:"var(--c-muted)","depends-on":"var(--c-warn)",flow:"var(--c-accent)",references:"var(--c-dim)"},_q=new Set(["depends-on","flow"]);function zq($){if($.style==="dashed")return"8 4";if($.style==="dotted")return"3 3";if($.type==="references"&&!$.style)return"8 4";return}function HB($,v){let g=$.position.x+$.size.width/2,_=$.position.y+$.size.height/2,U=v.position.x+v.size.width/2,z=v.position.y+v.size.height/2,b=U-g,J=z-_,G=$.size.width/2,K=$.size.height/2,W=Math.abs(J/(b||0.001)),B=K/(G||0.001);if(W>B){let k=J>0?1:-1;return{x:g+K/W*(b>0?1:-1),y:_+K*k}}let P=b>0?1:-1;return{x:g+G*P,y:_+W*G*(J>0?1:-1)}}function bq($,v,g,_,U,z,b,J){return{x:0.125*$+0.375*g+0.375*U+0.125*b,y:0.125*v+0.375*_+0.375*z+0.125*J}}function Jq({edge:$,fromNode:v,toNode:g,focused:_,dimmed:U}){let z=HB(v,g),b=HB(g,v),J=b.x-z.x,G=b.y-z.y,K=Math.sqrt(J*J+G*G),W=Math.min(K*0.25,80),B=J/(K||1),P=G/(K||1),k=z.x+B*W,A=z.y+P*W,L=b.x-B*W,I=b.y-P*W,Y=`M ${z.x} ${z.y} C ${k} ${A}, ${L} ${I}, ${b.x} ${b.y}`,F=gq[$.type],X=_q.has($.type),Q=zq($),u=$.label?bq(z.x,z.y,k,A,L,I,b.x,b.y):null,c=`edge-path-${$.id}`;return O("g",{children:[O("path",{d:Y,fill:"none",stroke:"transparent","stroke-width":"12",style:{cursor:"pointer"}},void 0,!1,void 0,this),_&&O("path",{d:Y,fill:"none",stroke:F,"stroke-width":"6","stroke-dasharray":Q,opacity:"0.15",style:{filter:"blur(3px)"}},void 0,!1,void 0,this),O("path",{id:c,d:Y,fill:"none",stroke:F,"stroke-width":_?2.5:1.5,"stroke-dasharray":Q,"marker-end":X?"url(#edge-arrow)":void 0,opacity:U?0.2:_?1:0.75,style:{transition:"opacity 0.2s, stroke-width 0.2s"}},void 0,!1,void 0,this),$.animated&&O("circle",{r:"3",fill:F,opacity:"0.9",children:O("animateMotion",{dur:"2s",repeatCount:"indefinite",children:O("mpath",{href:`#${c}`},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),u&&$.label&&O("g",{transform:`translate(${u.x}, ${u.y})`,children:[O("rect",{class:"edge-label-bg",x:-($.label.length*3.5+8),y:"-10",width:$.label.length*7+16,height:"20",rx:"4"},void 0,!1,void 0,this),O("text",{class:"edge-label","text-anchor":"middle","dominant-baseline":"central",fill:"var(--c-text)","font-size":"11",children:$.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function LB({nodes:$,edges:v}){let g=$.value,_=Array.from(v.value.values()),U=T$.value,z=U!==null,b=H6.value,J=b!==null;if(_.length===0)return null;let G=96,K=Array.from(g.values()),W=Math.min(...K.map((I)=>I.position.x))-G,B=Math.min(...K.map((I)=>I.position.y))-G,P=Math.max(...K.map((I)=>I.position.x+I.size.width))+G,k=Math.max(...K.map((I)=>I.position.y+I.size.height))+G,A=Math.max(1,P-W),L=Math.max(1,k-B);return O("svg",{"aria-label":"Canvas connections",role:"img",viewBox:`${W} ${B} ${A} ${L}`,width:A,height:L,style:{position:"absolute",top:`${B}px`,left:`${W}px`,pointerEvents:"none",overflow:"visible"},children:[O("title",{children:"Canvas connections"},void 0,!1,void 0,this),O("defs",{children:O("marker",{id:"edge-arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"8",markerHeight:"8",orient:"auto-start-reverse",children:O("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),_.map((I)=>{let Y=g.get(I.from),F=g.get(I.to);if(!Y||!F)return null;let X=z&&(I.from===U||I.to===U),Q=J&&!(b.has(I.from)||b.has(I.to));return O(Jq,{edge:I,fromNode:Y,toNode:F,focused:X,dimmed:z&&!X||Q},I.id,!1,void 0,this)}),Qv.value&&(()=>{let I=Qv.value,Y=I.cursorX-I.fromX,F=I.cursorY-I.fromY,X=Math.sqrt(Y*Y+F*F),Q=Math.min(X*0.25,80),u=Y/(X||1),c=F/(X||1),N=`M ${I.fromX} ${I.fromY} C ${I.fromX+u*Q} ${I.fromY+c*Q}, ${I.cursorX-u*Q} ${I.cursorY-c*Q}, ${I.cursorX} ${I.cursorY}`;return O("g",{children:[O("path",{d:N,fill:"none",stroke:"var(--c-accent)","stroke-width":"6",opacity:"0.1",style:{filter:"blur(3px)"}},void 0,!1,void 0,this),O("path",{d:N,fill:"none",stroke:"var(--c-accent)","stroke-width":"2","stroke-dasharray":"6 4",opacity:"0.8"},void 0,!1,void 0,this),O("circle",{cx:I.cursorX,cy:I.cursorY,r:"5",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 Oq($){let[v,...g]=$;if(!v)return"";return g.reduce((_,U)=>`${_} L ${U.x} ${U.y}`,`M ${v.x} ${v.y}`)}function GG({annotations:$}){if($.length===0)return null;return O("svg",{class:"annotation-layer","aria-hidden":"true",children:$.map((v)=>{let g=v.color==="currentColor"?"var(--c-annotation)":v.color;if(v.type==="text"){let _=v.points[0];if(!_||!v.text)return null;return O("text",{x:_.x,y:_.y,fill:g,"font-size":v.width,"font-family":"var(--font)","font-weight":"700",opacity:"0.95",children:v.text},v.id,!1,void 0,this)}return O("path",{d:Oq(v.points),fill:"none",stroke:g,"stroke-width":v.width,"stroke-linecap":"round","stroke-linejoin":"round",opacity:"0.9"},v.id,!1,void 0,this)})},void 0,!1,void 0,this)}var Gq=0.1,Kq=4,YB=1;function FB($){return Math.min(Kq,Math.max(Gq,$))}function AB({viewport:$,onViewportChange:v,onViewportCommit:g,disabled:_=!1}){let U=V(null),z=V(!1),b=V({x:0,y:0}),J=V(0),G=V(null),K=M((I)=>{if(G.current!==null)window.clearTimeout(G.current);G.current=window.setTimeout(()=>{G.current=null,g(I)},140)},[g]),W=M((I)=>{if(_)return;I.preventDefault();let Y=$.value;if(I.ctrlKey||I.metaKey){let F=U.current?.getBoundingClientRect();if(!F)return;let X=I.clientX-F.left,Q=I.clientY-F.top,u=-I.deltaY*0.002,c=FB(Y.scale*(1+u)),N=c/Y.scale,t={x:X-N*(X-Y.x),y:Q-N*(Q-Y.y),scale:c};v(t),K(t)}else{let F={x:Y.x-I.deltaX*YB,y:Y.y-I.deltaY*YB,scale:Y.scale};v(F),K(F)}},[_,$,v,K]),B=M((I)=>{if(_)return;let Y=U.current;if(!Y||I.target!==Y)return;z.current=!0,b.current={x:I.clientX,y:I.clientY},Y.setPointerCapture(I.pointerId)},[_]),P=M((I)=>{if(!z.current)return;if(_)return;let Y=I.clientX-b.current.x,F=I.clientY-b.current.y;b.current={x:I.clientX,y:I.clientY};let X=$.value;v({x:X.x+Y,y:X.y+F,scale:X.scale})},[_,$,v]),k=M(()=>{if(z.current)g($.value);z.current=!1},[g,$]),A=M((I)=>{if(_)return;if(I.touches.length!==2){J.current=0;return}I.preventDefault();let Y=I.touches[0],F=I.touches[1],X=Math.hypot(F.clientX-Y.clientX,F.clientY-Y.clientY),Q=(Y.clientX+F.clientX)/2,u=(Y.clientY+F.clientY)/2;if(J.current>0){let c=$.value,N=U.current?.getBoundingClientRect();if(!N)return;let t=Q-N.left,a=u-N.top,r=X/J.current,y=FB(c.scale*r),v$=y/c.scale,p={x:t-v$*(t-c.x),y:a-v$*(a-c.y),scale:y};v(p),K(p)}J.current=X},[_,$,v,K]),L=M(()=>{if(G.current!==null)window.clearTimeout(G.current),G.current=null;g($.value),J.current=0},[g,$]);return m(()=>{let I=U.current;if(!I)return;return I.addEventListener("wheel",W,{passive:!1}),I.addEventListener("pointerdown",B),I.addEventListener("pointermove",P),I.addEventListener("pointerup",k),I.addEventListener("pointercancel",k),I.addEventListener("touchmove",A,{passive:!1}),I.addEventListener("touchend",L),()=>{if(G.current!==null)window.clearTimeout(G.current);I.removeEventListener("wheel",W),I.removeEventListener("pointerdown",B),I.removeEventListener("pointermove",P),I.removeEventListener("pointerup",k),I.removeEventListener("pointercancel",k),I.removeEventListener("touchmove",A),I.removeEventListener("touchend",L)}},[W,B,P,k,A,L]),U}function Wq($){switch($.type){case"markdown":return O(r_,{node:$},void 0,!1,void 0,this);case"mcp-app":return O(j6,{node:$},void 0,!1,void 0,this);case"webpage":return O(Q0,{node:$},void 0,!1,void 0,this);case"json-render":return O(j6,{node:$},void 0,!1,void 0,this);case"graph":return O(j6,{node:$},void 0,!1,void 0,this);case"prompt":return O(r0,{node:$},void 0,!1,void 0,this);case"response":return O(R0,{node:$},void 0,!1,void 0,this);case"status":return O(JU,{node:$},void 0,!1,void 0,this);case"context":return O(h6,{node:$},void 0,!1,void 0,this);case"ledger":return O(X4,{node:$},void 0,!1,void 0,this);case"trace":return O(y0,{node:$},void 0,!1,void 0,this);case"file":return O(Z_,{node:$},void 0,!1,void 0,this);case"image":return O(M0,{node:$},void 0,!1,void 0,this);case"html":return O(Qg,{node:$},void 0,!1,void 0,this);case"group":return O(wW,{node:$},void 0,!1,void 0,this);default:return O("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function Bq($,v,g){let _=g.x-v.x,U=g.y-v.y,z=_*_+U*U;if(z===0)return Math.hypot($.x-v.x,$.y-v.y);let b=Math.max(0,Math.min(1,(($.x-v.x)*_+($.y-v.y)*U)/z));return Math.hypot($.x-(v.x+b*_),$.y-(v.y+b*U))}function kq($,v,g){for(let _=$.length-1;_>=0;_--){let U=$[_];if(!U)continue;let z=g+U.width;if(v.x<U.bounds.x-z||v.x>U.bounds.x+U.bounds.width+z||v.y<U.bounds.y-z||v.y>U.bounds.y+U.bounds.height+z)continue;if(U.type==="text")return U;for(let b=1;b<U.points.length;b++){let J=U.points[b-1],G=U.points[b];if(J&&G&&Bq(v,J,G)<=g+U.width/2)return U}}return null}var KG="currentColor",qB=4,XB=24,Pq=14,Iq=new Set(["png","jpg","jpeg","gif","svg","webp","bmp","ico","avif"]),Hq=new Set(["md","mdx","markdown"]),wB={width:520,height:420};function Lq($){let v=$.trim();if(!v||/\s/.test(v))return null;let g=/^[a-z][a-z0-9+.-]*:/i.test(v)?v:`https://${v}`;try{let _=new URL(g);if(_.protocol!=="http:"&&_.protocol!=="https:")return null;return _.toString()}catch{return null}}function WG($){let v=$.trim();if(!v)return[];let g=v.includes(`
226
226
  `)?v.split(/\r?\n/):v.split(/\s+/),_=new Set,U=[];for(let z of g){let b=z.trim();if(!b||b.startsWith("#"))continue;let J=Lq(b);if(!J||_.has(J))continue;_.add(J),U.push(J)}return U}function Yq($){let v=WG($.getData("text/uri-list"));if(v.length>0)return v;return WG($.getData("text/plain"))}function Fq($){if(!$)return!1;return $.types.includes("text/uri-list")||$.types.includes("text/plain")}function ZB($){if(!($ instanceof HTMLElement))return!1;return Boolean($.closest('input, textarea, select, [contenteditable="true"], [contenteditable=""]'))}function Aq($){let v=$.split(".").pop()?.toLowerCase()??"";if(Iq.has(v))return"image";if(Hq.has(v))return"markdown";return"file"}function qq($,v){let g=[],_=0;for(let U of $){if(U.dockPosition!==null)continue;if(v&&U.id===v)continue;if(U.type==="group")g.splice(_++,0,U);else g.push(U)}return g}function SB({onNodeContextMenu:$,onCanvasContextMenu:v,annotationMode:g=!1,annotationTool:_=null}){let U=H$.value,z=V(!1),b=V(!1),J=V([]),[G,K]=x(null),[W,B]=x(null),[P,k]=x(null),A=V(null),[L,I]=x(!1),Y=V(0),F=V(null),X=AB({viewport:H$,disabled:g,onViewportChange:(S)=>{if(z.current||g)return;F4(),fK(S)},onViewportCommit:(S)=>{if(z.current||g)return;F4(),mK(S)}}),Q=M((S)=>{A.current=S,k(S)},[]),u=M(async(S,h,$$)=>{if(S.length===0)return;let{width:s,height:K$}=wB,J$=24,e=Math.ceil(Math.sqrt(S.length)),f=Math.ceil(S.length/e),d=e*s+Math.max(0,e-1)*J$,W$=f*K$+Math.max(0,f-1)*J$;for(let o=0;o<S.length;o++){let z$=o%e,B$=Math.floor(o/e),P$=h-d/2+z$*(s+J$),R$=$$-W$/2+B$*(K$+J$);await mv({type:"webpage",content:S[o],x:P$,y:R$,width:s,height:K$})}},[]),c=M((S)=>{let h=X.current;if(!h)return;if(_==="eraser"){if((S.target instanceof Element?S.target:null)?.closest(".hud-layer, .snapshot-panel, .context-menu, .command-palette"))return;S.preventDefault(),S.stopPropagation();let f=h.getBoundingClientRect(),d=H$.value,W$={x:(S.clientX-f.left-d.x)/d.scale,y:(S.clientY-f.top-d.y)/d.scale},o=kq(Array.from(k4.value.values()),W$,Pq/d.scale);if(o)VK(o.id);return}if(_==="text"){if((S.target instanceof Element?S.target:null)?.closest(".hud-layer, .snapshot-panel, .context-menu, .command-palette"))return;S.preventDefault(),S.stopPropagation(),T$.value=null,Tv();let f=h.getBoundingClientRect(),d=H$.value;Q({x:(S.clientX-f.left-d.x)/d.scale,y:(S.clientY-f.top-d.y)/d.scale,value:""});return}if(_==="pen"){if((S.target instanceof Element?S.target:null)?.closest(".hud-layer, .snapshot-panel, .context-menu, .command-palette"))return;S.preventDefault(),S.stopPropagation(),T$.value=null,Tv(),b.current=!0;let f=h.getBoundingClientRect(),d=H$.value,W$={x:(S.clientX-f.left-d.x)/d.scale,y:(S.clientY-f.top-d.y)/d.scale};J.current=[W$],B({id:"draft-annotation",type:"freehand",points:[W$],bounds:{x:0,y:0,width:0,height:0},color:KG,width:qB,createdAt:""}),h.setPointerCapture(S.pointerId);return}if(S.target!==h)return;if(!S.shiftKey){if(!F.current)T$.value=null,Tv();return}S.preventDefault(),S.stopPropagation(),z.current=!0;let $$=h.getBoundingClientRect(),s=S.clientX-$$.left,K$=S.clientY-$$.top,J$={startX:s,startY:K$,currentX:s,currentY:K$};F.current=J$,K(J$),h.setPointerCapture(S.pointerId)},[_,X]),N=M((S)=>{if(b.current){let s=X.current;if(!s)return;let K$=s.getBoundingClientRect(),J$=H$.value,e={x:(S.clientX-K$.left-J$.x)/J$.scale,y:(S.clientY-K$.top-J$.y)/J$.scale},f=J.current.at(-1);if(f&&Math.hypot(e.x-f.x,e.y-f.y)<2)return;J.current=[...J.current,e],B((d)=>d?{...d,points:J.current}:null);return}if(!z.current||!F.current)return;let h=X.current?.getBoundingClientRect();if(!h)return;let $$={...F.current,currentX:S.clientX-h.left,currentY:S.clientY-h.top};F.current=$$,K($$)},[X]),t=M((S)=>{if(b.current){b.current=!1;let e=J.current;if(J.current=[],B(null),e.length>=2)O2({points:e,color:KG,width:qB});let f=X.current;if(f?.hasPointerCapture(S.pointerId))f.releasePointerCapture(S.pointerId);return}let h=F.current;if(!z.current||!h)return;z.current=!1,F.current=null;let $$=Math.min(h.startX,h.currentX),s=Math.max(h.startX,h.currentX),K$=Math.min(h.startY,h.currentY),J$=Math.max(h.startY,h.currentY);if(s-$$>5||J$-K$>5){let e=H$.value,f=($$-e.x)/e.scale,d=(s-e.x)/e.scale,W$=(K$-e.y)/e.scale,o=(J$-e.y)/e.scale,z$=[];for(let B$ of T.value.values()){if(B$.dockPosition!==null)continue;let P$=B$.position.x,R$=B$.position.y;if(P$+B$.size.width>f&&P$<d&&R$+B$.size.height>W$&&R$<o)z$.push(B$.id)}if(z$.length>0)rK(z$)}K(null)},[]);m(()=>{if(g)return;if(!b.current&&!W&&!P)return;b.current=!1,J.current=[],B(null),Q(null)},[g,W,Q,P]);let a=M(()=>{let S=A.current;if(!S)return;let h=S.value.trim();if(Q(null),!h)return;let $$={x:S.x,y:S.y};O2({type:"text",points:[$$],color:KG,width:XB,text:h})},[Q]);m(()=>{if(_!=="text"&&P)Q(null)},[_,Q,P]),m(()=>{function S($$){if(!Qv.value)return;let s=X.current;if(!s)return;let K$=s.getBoundingClientRect(),J$=H$.value;Qv.value={...Qv.value,cursorX:($$.clientX-K$.left-J$.x)/J$.scale,cursorY:($$.clientY-K$.top-J$.y)/J$.scale}}function h($$){let s=Qv.value;if(!s)return;Qv.value=null;let K$=X.current;if(!K$)return;let J$=K$.getBoundingClientRect(),e=H$.value,f=($$.clientX-J$.left-e.x)/e.scale,d=($$.clientY-J$.top-e.y)/e.scale;for(let W$ of T.value.values()){if(W$.id===s.fromId||W$.dockPosition!==null)continue;if(f>=W$.position.x&&f<=W$.position.x+W$.size.width&&d>=W$.position.y&&d<=W$.position.y+W$.size.height){W4(s.fromId,W$.id,"relation");return}}}return document.addEventListener("pointermove",S),document.addEventListener("pointerup",h),()=>{document.removeEventListener("pointermove",S),document.removeEventListener("pointerup",h)}},[X]);let r=M((S)=>{if(g)return;let h=X.current;if(!h||S.target!==h)return;let $$=h.getBoundingClientRect(),s=H$.value,K$=(S.clientX-$$.left-s.x)/s.scale,J$=(S.clientY-$$.top-s.y)/s.scale,e=520,f=360;mv({type:"markdown",title:"New note",x:K$-e/2,y:J$-f/2,width:e,height:f})},[g,X]),y=M((S)=>{if(g)return;if(!v)return;let h=X.current;if(!h)return;if((S.target instanceof Element?S.target:null)?.closest(".canvas-node"))return;let s=h.getBoundingClientRect(),K$=H$.value,J$=(S.clientX-s.left-K$.x)/K$.scale,e=(S.clientY-s.top-K$.y)/K$.scale;v(S,J$,e)},[g,X,v]),v$=M((S)=>{if(S.preventDefault(),Y.current++,S.dataTransfer?.types.includes("Files")||Fq(S.dataTransfer))I(!0)},[]),p=M((S)=>{if(S.preventDefault(),S.dataTransfer)S.dataTransfer.dropEffect="copy"},[]),i=M((S)=>{if(S.preventDefault(),Y.current--,Y.current<=0)Y.current=0,I(!1)},[]),Y$=M(async(S)=>{S.preventDefault(),I(!1),Y.current=0;let h=X.current;if(!h||!S.dataTransfer)return;let $$=h.getBoundingClientRect(),s=H$.value,K$=(S.clientX-$$.left-s.x)/s.scale,J$=(S.clientY-$$.top-s.y)/s.scale,e=Array.from(S.dataTransfer.files);if(e.length===0){let z$=Yq(S.dataTransfer);await u(z$,K$,J$);return}let f=400,d=300,W$=20,o=Math.ceil(Math.sqrt(e.length));for(let z$=0;z$<e.length;z$++){let B$=e[z$],P$=z$%o,R$=Math.floor(z$/o),Ov=K$-o*(f+W$)/2+P$*(f+W$),C6=J$-d/2+R$*(d+W$),IU=Aq(B$.name),Dv=B$.name;if(IU==="image"){let Fv=new FileReader,U4=await new Promise((Tg)=>{Fv.onload=()=>Tg(Fv.result),Fv.readAsDataURL(B$)});await mv({type:"image",title:Dv,content:U4,x:Ov,y:C6,width:f,height:d})}else{let Fv=await B$.text(),U4=IU==="markdown"||IU==="file";await mv({type:IU,title:Dv,content:Fv,x:Ov,y:C6,width:U4?720:f,height:U4?500:d})}}},[X,u]);m(()=>{let S=async(h)=>{if(h.defaultPrevented)return;if(ZB(h.target instanceof Element?h.target:null))return;if(ZB(document.activeElement))return;let $$=h.clipboardData?.getData("text/plain")??"",s=WG($$);if(s.length===0)return;let K$=X.current;if(!K$)return;h.preventDefault();let J$=K$.getBoundingClientRect(),e=H$.value,f=(J$.width/2-e.x)/e.scale,d=(J$.height/2-e.y)/e.scale;await u(s,f,d)};return document.addEventListener("paste",S),()=>{document.removeEventListener("paste",S)}},[X,u]);let _$=qq(T.value.values(),c$.value),x$=null;if(G){let S=Math.min(G.startX,G.currentX),h=Math.min(G.startY,G.currentY),$$=Math.abs(G.currentX-G.startX),s=Math.abs(G.currentY-G.startY);x$={position:"absolute",left:`${S}px`,top:`${h}px`,width:`${$$}px`,height:`${s}px`,pointerEvents:"none"}}return O("div",{class:"canvas-viewport",ref:X,tabIndex:0,onPointerDown:c,onPointerMove:N,onPointerUp:t,onContextMenu:y,onDblClick:r,onDragEnter:v$,onDragOver:p,onDragLeave:i,onDrop:Y$,style:{width:"100%",height:"100%",position:"relative",overflow:"hidden",cursor:_==="eraser"?"cell":_==="text"?"text":g||Qv.value||z.current?"crosshair":"grab"},children:[O("div",{style:{transform:`matrix(${U.scale}, 0, 0, ${U.scale}, ${U.x}, ${U.y})`,transformOrigin:"0 0",willChange:"transform",position:"absolute",top:0,left:0},children:[O(yW,{},void 0,!1,void 0,this),O(bB,{},void 0,!1,void 0,this),O(LB,{nodes:T,edges:m$},void 0,!1,void 0,this),O(GG,{annotations:Array.from(k4.value.values())},void 0,!1,void 0,this),W&&W.points.length>=2&&O(GG,{annotations:[W]},void 0,!1,void 0,this),_$.map((S)=>O(IB,{node:S,onContextMenu:$,children:Wq(S)},S.id,!1,void 0,this)),$4.value&&O("svg",{class:"snap-guides-svg",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:$4.value.map((S,h)=>S.axis==="x"?O("line",{x1:S.pos,y1:S.from-20,x2:S.pos,y2:S.to+20,class:"snap-guide-line"},h,!1,void 0,this):O("line",{x1:S.from-20,y1:S.pos,x2:S.to+20,y2:S.pos,class:"snap-guide-line"},h,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g&&O("div",{class:`annotation-capture-layer${_==="eraser"?" erasing":""}${_==="text"?" text":""}`,"aria-hidden":"true"},void 0,!1,void 0,this),P&&O("input",{class:"annotation-text-input",value:P.value,autoFocus:!0,style:{left:`${P.x*U.scale+U.x}px`,top:`${P.y*U.scale+U.y}px`,fontSize:`${XB*U.scale}px`},onInput:(S)=>Q({...P,value:S.target.value}),onBlur:a,onPointerDown:(S)=>S.stopPropagation(),onKeyDown:(S)=>{if(S.key==="Enter")S.preventDefault(),a();if(S.key==="Escape")S.preventDefault(),Q(null)}},void 0,!1,void 0,this),x$&&O("div",{class:"lasso-rect",style:x$},void 0,!1,void 0,this),L&&O("div",{class:"drop-zone-overlay",children:O("div",{class:"drop-zone-indicator",children:[O("div",{class:"drop-zone-icon",children:"+"},void 0,!1,void 0,this),O("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 Xq($,v){let g=$.toLowerCase(),_=v.toLowerCase(),U=[],z=0,b=0,J=-1;for(let G=0;G<_.length&&z<g.length;G++)if(_[G]===g[z]){if(U.push(G),b+=J===G-1?10:1,G===0||_[G-1]===" "||_[G-1]==="-"||_[G-1]==="_")b+=5;J=G,z++}return{match:z===g.length,score:b,indices:U}}function wq($,v){if(v.length===0)return $;let g=[],_=0;for(let U of v){if(U>_)g.push($.slice(_,U));g.push(O("mark",{children:$[U]},U,!1,void 0,this)),_=U+1}if(_<$.length)g.push($.slice(_));return g}var BG={md:"markdown",app:"mcp-app",web:"webpage",ui:"json-render",chart:"graph",ctx:"context",log:"ledger"};function Zq($){let v=$.toLowerCase().trim();if(v.startsWith("type:")){let g=v.slice(5).trim(),U=Object.keys(a$).find((b)=>b.startsWith(g));if(U)return{typeFilter:U,remaining:""};let z=BG[g];if(z)return{typeFilter:z,remaining:""}}if(BG[v])return{typeFilter:BG[v],remaining:""};return{typeFilter:null,remaining:$}}function MB({onClose:$,onToggleMinimap:v}){let[g,_]=x(""),[U,z]=x(0),b=V(null),J=V(null);m(()=>{setTimeout(()=>b.current?.focus(),30)},[]);let G=M(()=>{let L=[];for(let Y of T.value.values()){let F=Y.data.title||a$[Y.type],X=Y.data.content||Y.data.path||"";L.push({id:`node:${Y.id}`,kind:"node",label:F,description:X.length>80?X.slice(0,80)+"...":X||void 0,badge:a$[Y.type],nodeType:Y.type,action:()=>{Pv(Y.id),$()}})}let I=[{label:"New note (markdown node)",badge:"CREATE",action:()=>{mv({type:"markdown",title:"New note",width:520,height:360}),$()}},{label:"Fit all nodes",badge:"VIEW",action:()=>{H_(window.innerWidth,window.innerHeight),$()}},{label:"Auto-arrange (grid)",badge:"LAYOUT",action:()=>{L_(),$()}},{label:"Auto-arrange (graph-aware)",badge:"LAYOUT",action:()=>{Y_(),$()}},{label:"Toggle minimap",badge:"VIEW",action:()=>{v(),$()}},{label:"Toggle theme (dark/light)",badge:"THEME",action:()=>{let Y=V$.value==="dark"?"light":"dark";document.documentElement.setAttribute("data-theme",Y),bU(),V$.value=Y,b_(Y),$()}}];for(let Y of I)L.push({id:`action:${Y.label}`,kind:"action",label:Y.label,badge:Y.badge,badgeClass:"command-palette-badge--action",action:Y.action});return L},[$,v]),{typeFilter:K,remaining:W}=Zq(g),B=G(),P;if(!g.trim())P=B.map((L)=>({...L,score:0,indices:[]}));else{P=[];for(let L of B){if(K){if(L.kind!=="node"||L.nodeType!==K)continue;if(!W){P.push({...L,score:0,indices:[]});continue}}let I=Xq(W||g,L.label);if(I.match)P.push({...L,score:I.score,indices:I.indices})}P.sort((L,I)=>I.score-L.score)}m(()=>{if(!g.trim()){H6.value=null;return}let L=new Set;for(let I of P)if(I.kind==="node")L.add(I.id.slice(5));H6.value=L.size>0?L:null},[g,P]),m(()=>{return()=>{H6.value=null}},[]);let k=Math.min(U,Math.max(0,P.length-1)),A=M((L)=>{if(L.key==="ArrowDown")L.preventDefault(),z((I)=>Math.min(I+1,P.length-1));else if(L.key==="ArrowUp")L.preventDefault(),z((I)=>Math.max(I-1,0));else if(L.key==="Enter"){if(L.preventDefault(),P[k])P[k].action()}else if(L.key==="Escape")L.preventDefault(),L.stopPropagation(),$()},[P,k,$]);return m(()=>{let L=J.current;if(!L)return;L.children[k]?.scrollIntoView({block:"nearest"})},[k]),m(()=>{z(0)},[g]),O("div",{class:"command-palette-backdrop",onMouseDown:$,children:O("div",{class:"command-palette",onMouseDown:(L)=>L.stopPropagation(),children:[O("input",{ref:b,type:"text",class:"command-palette-input",value:g,onInput:(L)=>_(L.target.value),onKeyDown:A,placeholder:`Search nodes and actions... (${Xv}+K)`},void 0,!1,void 0,this),O("div",{class:"command-palette-hint",children:[O("span",{children:[O("kbd",{children:"↑"},void 0,!1,void 0,this),O("kbd",{children:"↓"},void 0,!1,void 0,this)," navigate"]},void 0,!0,void 0,this),O("span",{children:[O("kbd",{children:"↵"},void 0,!1,void 0,this)," select"]},void 0,!0,void 0,this),O("span",{children:[O("kbd",{children:"esc"},void 0,!1,void 0,this)," close"]},void 0,!0,void 0,this),O("span",{children:[O("kbd",{children:"type:"},void 0,!1,void 0,this)," filter by type"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"command-palette-results",ref:J,children:[P.length===0&&O("div",{class:"command-palette-empty",children:"No matching nodes or actions"},void 0,!1,void 0,this),P.map((L,I)=>O("button",{type:"button",class:`command-palette-item${I===k?" selected":""}`,onMouseEnter:()=>z(I),onClick:()=>L.action(),children:[O("span",{class:`command-palette-badge${L.badgeClass?` ${L.badgeClass}`:""}`,children:L.badge},void 0,!1,void 0,this),O("span",{class:"command-palette-label",children:L.indices.length>0?wq(L.label,L.indices):L.label},void 0,!1,void 0,this),L.description&&O("span",{class:"command-palette-desc",children:L.description},void 0,!1,void 0,this)]},L.id,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function QB(){let[$,v]=x(null),g=M((z,b)=>{z.preventDefault(),z.stopPropagation(),v({kind:"node",x:z.clientX,y:z.clientY,nodeId:b})},[]),_=M((z,b,J)=>{z.preventDefault(),z.stopPropagation(),v({kind:"canvas",x:z.clientX,y:z.clientY,canvasX:b,canvasY:J})},[]),U=M(()=>v(null),[]);return m(()=>{if(!$)return;let z=()=>v(null),b=(J)=>{if(J.key==="Escape")v(null)};return document.addEventListener("click",z),document.addEventListener("keydown",b),()=>{document.removeEventListener("click",z),document.removeEventListener("keydown",b)}},[$]),{menu:$,openNodeMenu:g,openCanvasMenu:_,closeMenu:U}}var Sq="#4bbcFF",Mq=[{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 NB({menu:$,onClose:v}){let g;if($.kind==="node"){let J=T.value.get($.nodeId);if(!J)return null;g=yq(J)}else g=Rq($.canvasX,$.canvasY);let _=new Map,U=g.some((J)=>J.render)?g.length*32+168:g.length*32+8,z=Math.min($.x,Math.max(12,window.innerWidth-240)),b=Math.min($.y,Math.max(12,window.innerHeight-U));return O("div",{class:"context-menu",style:{position:"fixed",left:`${z}px`,top:`${b}px`,zIndex:1e4},onPointerDown:(J)=>J.stopPropagation(),onClick:(J)=>J.stopPropagation(),children:g.map((J)=>{let G=J.separator?"separator":J.render?"custom":`${J.label??"item"}:${J.shortcut??""}`,K=(_.get(G)??0)+1;_.set(G,K);let W=`${G}:${K}`;if(J.separator)return O("div",{class:"context-menu-separator"},W,!1,void 0,this);if(J.render)return O("div",{class:"context-menu-custom",children:J.render(v)},W,!1,void 0,this);return O("button",{type:"button",class:"context-menu-item",onClick:()=>{J.action?.(),v()},children:[O("span",{class:"context-menu-label",children:J.label},void 0,!1,void 0,this),J.shortcut&&O("span",{class:"context-menu-shortcut",children:J.shortcut},void 0,!1,void 0,this)]},W,!0,void 0,this)})},void 0,!1,void 0,this)}function Qq($){return(typeof $.data.path==="string"?$.data.path.trim():"")||null}function D0($){let v=$.trim().toLowerCase(),g=v.match(/^#([0-9a-f]{3})$/);if(g){let[_,U,z]=g[1].split("");return`#${_}${_}${U}${U}${z}${z}`}return v}function uB($){if(typeof $.data.color!=="string"||!$.data.color.trim())return null;return D0($.data.color)}function Nq($){let v=uB($);return v&&/^#[0-9a-f]{6}$/.test(v)?v:D0(Sq)}function kG($,v){let g=v?D0(v):null;Kv($.id,{data:{...$.data,color:g}}),Av($.id,{data:{color:g}})}function uq($,v){let g=uB($);return O("div",{class:"context-menu-section",children:[O("div",{class:"context-menu-section-header",children:[O("span",{class:"context-menu-section-label",children:"Group color"},void 0,!1,void 0,this),O("button",{type:"button",class:"context-menu-reset",onClick:()=>{kG($,null),v()},children:"Theme default"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"context-menu-color-grid",children:Mq.map((_)=>{let U=D0(_.value);return O("button",{type:"button",class:`context-menu-color-swatch${g===U?" active":""}`,"aria-label":`Set group color to ${_.label}`,title:_.label,style:{"--swatch-color":_.value},onClick:()=>{kG($,_.value),v()},children:[O("span",{class:"context-menu-color-dot",style:{"--swatch-color":_.value}},void 0,!1,void 0,this),O("span",{children:_.label},void 0,!1,void 0,this)]},_.value,!0,void 0,this)})},void 0,!1,void 0,this),O("label",{class:"context-menu-color-custom",children:[O("span",{children:"Custom"},void 0,!1,void 0,this),O("input",{type:"color",class:"context-menu-color-input","aria-label":"Custom group color",value:Nq($),onClick:(_)=>_.stopPropagation(),onInput:(_)=>{kG($,_.currentTarget.value),v()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function IG($,v,g,_){return{x:$-g/2,y:v-_/2}}function rq($,v){return $.trim().replace(/[?#].*$/,"").split("/").filter(Boolean).at(-1)||v}async function PG($){let v=window.prompt($.promptLabel,$.placeholder??"");if(!v)return;let g=v.trim();if(!g)return;let _=IG($.canvasX,$.canvasY,$.width,$.height);if(!(await mv({type:$.type,...$.type!=="webpage"?{title:rq(g,$.titleFallback)}:{},content:g,x:_.x,y:_.y,width:$.width,height:$.height})).ok)window.alert($.errorMessage)}function Rq($,v){return[{label:"New note",action:()=>{let U=IG($,v,520,360);mv({type:"markdown",title:"New note",x:U.x,y:U.y,width:520,height:360})}},{label:"Open webpage...",action:()=>{PG({promptLabel:"Webpage URL:",type:"webpage",canvasX:$,canvasY:v,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:()=>{PG({promptLabel:"Workspace path or absolute file path:",type:"file",canvasX:$,canvasY:v,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:()=>{PG({promptLabel:"Image path, URL, or data URI:",type:"image",canvasX:$,canvasY:v,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 U=IG($,v,600,400);G_({title:"Group",x:U.x,y:U.y,width:600,height:400})}}]}function yq($){let v=[],g=Qq($);if(v.push({label:"Focus",action:()=>Pv($.id)}),__.has($.type))v.push({label:"Expand",shortcut:"⤢",action:()=>U6($.id)});v.push({label:$.collapsed?"Expand":"Collapse",action:()=>Y6($.id)});let _=j$.value.has($.id);v.push({label:_?"Unpin from context":"Pin as context",action:()=>I4($.id)}),v.push({label:$.pinned?"Unlock position":"Lock position (no auto-arrange)",action:()=>{let b=!$.pinned;Kv($.id,{pinned:b}),Av($.id,{pinned:b}),n$()}});let U=B_.value;if(U&&U.from!==$.id){let b=T.value.get(U.from),J=b?(b.data.title||b.id).slice(0,20):U.from;v.push({label:`Connect from "${J}"`,action:()=>{W4(U.from,$.id,"relation"),B_.value=null}})}v.push({label:U?"Connect from here (replace)":"Connect from here",action:()=>{B_.value={from:$.id}}});let z=Array.from(m$.value.values()).filter((b)=>b.from===$.id||b.to===$.id).length;if(z>0)v.push({label:`${z} edge${z!==1?"s":""} connected`});if(v.push({separator:!0}),($.type==="markdown"||$.type==="file"||$.type==="image")&&g)v.push({label:"Open in browser",action:()=>{window.open(`/artifact?path=${encodeURIComponent(g)}`,"_blank","noopener")}}),v.push({label:"Copy path",action:()=>{navigator.clipboard.writeText(g)}});if($.type==="mcp-app"||$.type==="json-render"||$.type==="graph")if($.data.chartConfig){let b=$.data.chartConfig.title||"chart";v.push({label:"Copy chart data",action:()=>{navigator.clipboard.writeText(JSON.stringify($.data.chartConfig,null,2))}})}else{let b=$.data.url;if(v.push({label:"Open in browser",action:()=>{if(b)window.open(b,"_blank")}}),v.push({label:"Focus in TUI",action:()=>WK("mcp-app-focus",{url:b})}),$.type==="json-render"||$.type==="graph")v.push({label:"Copy spec",action:()=>{navigator.clipboard.writeText(JSON.stringify($.data.spec??$.data.graphConfig??{},null,2))}})}if($.type==="webpage"){let b=typeof $.data.url==="string"?$.data.url:"";v.push({label:"Refresh webpage",action:()=>{J_($.id)}}),v.push({label:"Open in browser",action:()=>{if(b)window.open(b,"_blank","noopener")}}),v.push({label:"Copy URL",action:()=>{if(b)navigator.clipboard.writeText(b)}})}if($.type==="group"){let b=$.data.children??[];if(v.push({separator:!0}),v.push({render:(J)=>uq($,J)}),b.length>0)v.push({label:`Ungroup (${b.length} node${b.length!==1?"s":""})`,action:()=>FK($.id)})}if($.type==="status"||$.type==="ledger")if(v.push({separator:!0}),$.dockPosition!==null)v.push({label:"Undock to canvas",action:()=>Y4($.id)});else v.push({label:"Dock left of toolbar",action:()=>G2($.id,"left")}),v.push({label:"Dock right of toolbar",action:()=>G2($.id,"right")});return v.push({separator:!0}),v.push({label:"Close",action:()=>{H4($.id),O_($.id)}}),v}function rB(){let $=j$.value.size;if($===0||B6.value||I_.value)return null;return O("div",{class:"context-pin-bar",children:[O("span",{class:"context-pin-bar-count",children:["✦"," ",$," node",$!==1?"s":""," in context"]},void 0,!0,void 0,this),O("button",{type:"button",class:"context-pin-bar-btn context-pin-bar-clear",onClick:yK,title:"Clear all context pins",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function RB({node:$}){let v=sO($),g=$.data.activeTool,_=$.data.subagent,U=S0[v]??"var(--c-muted)";return O("span",{style:{display:"flex",alignItems:"center",gap:"6px",flex:1,minWidth:0},children:[O("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:U,animation:v!=="idle"?"pulse 1.5s infinite":"none",flexShrink:0}},void 0,!1,void 0,this),O("span",{style:{color:U,fontSize:"10px",textTransform:"uppercase",fontWeight:600},children:v},void 0,!1,void 0,this),g&&O("span",{style:{color:"var(--c-warn)",fontSize:"10px",fontFamily:"var(--mono)"},children:["⚙ ",g]},void 0,!0,void 0,this),_&&_.state!=="completed"&&O("span",{style:{color:"var(--c-subagent)",fontSize:"10px"},children:["⠉ ",_.name]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Dq($){switch($.type){case"status":return O(JU,{node:$},void 0,!1,void 0,this);case"ledger":return O(X4,{node:$},void 0,!1,void 0,this);case"context":return O(h6,{node:$},void 0,!1,void 0,this);default:return null}}function Tq($){let v=Array.isArray($.data.cards)?$.data.cards:[],g=Array.isArray($.data.auxTabs)?$.data.auxTabs:[];return v.length+g.length}function jq({node:$}){let v=TK(),g=v.length>0?v.length:Tq($),_=g>0,U=$.collapsed===!0,z=()=>{v_(),Y6($.id)};if(U)return O("div",{class:"docked-node docked-node--collapsed","data-docked-node":"true",children:O("div",{class:"docked-node-header",children:[O("span",{class:"node-type-badge",children:"Context"},void 0,!1,void 0,this),_&&O("span",{class:"docked-node-count","aria-hidden":"true",children:g>99?"99+":g},void 0,!1,void 0,this),O("div",{class:"docked-node-controls",children:[O("button",{type:"button",onClick:(b)=>{b.stopPropagation(),z()},title:_?`${g} item${g===1?"":"s"} in agent context — expand`:"Expand agent context","aria-label":_?`Context — ${g} item${g===1?"":"s"}`:"Expand agent context",children:"▸"},void 0,!1,void 0,this),O("button",{type:"button",onClick:(b)=>{b.stopPropagation(),Y4($.id)},title:"Undock to canvas","aria-label":"Undock to canvas",children:"⊙"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return O("aside",{class:"context-dock-panel","data-docked-node":"true","aria-label":"Agent context",children:[O("div",{class:"context-dock-header",children:[O("div",{class:"context-dock-header-text",children:[O("span",{class:"context-dock-title",children:"Context"},void 0,!1,void 0,this),O("span",{class:"context-dock-subtitle",children:_?`${g} item${g===1?"":"s"} in agent context`:"Active agent context"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"context-dock-controls",children:[O("button",{type:"button",class:"context-dock-icon-button",onClick:(b)=>{b.stopPropagation(),Y4($.id)},"aria-label":"Undock to canvas",title:"Undock to canvas",children:"⊙"},void 0,!1,void 0,this),O("button",{type:"button",class:"context-dock-icon-button",onClick:(b)=>{b.stopPropagation(),Y6($.id)},"aria-label":"Collapse context panel",title:"Collapse",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"context-dock-body",children:O(h6,{node:$,pinnedNodes:v},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function HG({node:$}){if($.type==="context")return O(jq,{node:$},void 0,!1,void 0,this);return O("div",{class:`docked-node${$.collapsed?" docked-node--collapsed":""}`,"data-docked-node":"true",children:[O("div",{class:"docked-node-header",children:[O("span",{class:"node-type-badge",children:a$[$.type]??$.type},void 0,!1,void 0,this),$.type==="status"&&$.collapsed&&O(RB,{node:$},void 0,!1,void 0,this),O("div",{class:"docked-node-controls",children:[O("button",{type:"button",onClick:(v)=>{v.stopPropagation(),Y6($.id)},title:$.collapsed?"Expand":"Collapse",children:$.collapsed?"▸":"▾"},void 0,!1,void 0,this),O("button",{type:"button",onClick:(v)=>{v.stopPropagation(),Y4($.id)},title:"Undock to canvas",children:"⊙"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!$.collapsed&&O("div",{class:"docked-node-body",children:Dq($)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function yB($,v){switch($.type){case"markdown":return O(r_,{node:$,expanded:v},void 0,!1,void 0,this);case"mcp-app":return O(j6,{node:$,expanded:v},void 0,!1,void 0,this);case"webpage":return O(Q0,{node:$,expanded:v},void 0,!1,void 0,this);case"json-render":return O(j6,{node:$,expanded:v},void 0,!1,void 0,this);case"graph":return O(j6,{node:$,expanded:v},void 0,!1,void 0,this);case"prompt":return O(r0,{node:$},void 0,!1,void 0,this);case"response":return O(R0,{node:$,expanded:v},void 0,!1,void 0,this);case"status":return O(JU,{node:$},void 0,!1,void 0,this);case"context":return O(h6,{node:$,expanded:v},void 0,!1,void 0,this);case"ledger":return O(X4,{node:$},void 0,!1,void 0,this);case"trace":return O(y0,{node:$},void 0,!1,void 0,this);case"file":return O(Z_,{node:$,expanded:v},void 0,!1,void 0,this);case"image":return O(M0,{node:$,expanded:v},void 0,!1,void 0,this);case"html":return O(Qg,{node:$,expanded:v},void 0,!1,void 0,this);default:return O("div",{children:"Unknown node type"},void 0,!1,void 0,this)}}function DB($){switch($.type){case"markdown":return $.data.content||"";case"file":return $.data.fileContent||"";case"webpage":return $.data.content||"";case"html":return $.data.html||$.data.content||"";case"json-render":case"graph":return JSON.stringify($.data.spec??$.data.graphConfig??{},null,2);default:return""}}function Vq($){if(!$)return 0;return $.split(/\s+/).filter(Boolean).length}function Cq($,v){return $!==null&&typeof $==="object"&&$.source==="pmx-canvas-html-node"&&$.type==="presentation-exit"&&$.token===v}function fq($){return $==="ArrowRight"||$==="PageDown"||$===" "||$==="ArrowLeft"||$==="PageUp"||$==="Home"||$==="End"}function TB($){return $ instanceof HTMLElement&&Boolean($.closest(".html-presentation-exit"))}function jB(){let $=c$.value,v=$?T.value.get($):void 0,[g,_]=x(!1),[U,z]=x(!1),[b,J]=x(""),G=V(null),K=V(null),W=M(()=>{z(!1),l6()},[]),B=M(()=>{J(`presentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`),z(!0)},[]),P=M((r)=>{document.querySelector(".html-presentation-overlay iframe.html-node-frame-presentation")?.contentWindow?.postMessage({source:"pmx-canvas-html-node",token:b,...r},"*")},[b]),k=M(()=>{z(!1)},[]),A=M((r)=>{if(r.key==="Escape"){r.preventDefault(),r.stopPropagation(),z(!1);return}if(r.key==="Tab"&&!TB(r.target)){r.preventDefault(),r.stopPropagation(),K.current?.focus();return}if((r.key===" "||r.key==="Enter")&&TB(r.target))return;if(!fq(r.key))return;r.preventDefault(),r.stopPropagation(),P({type:"presentation-key",key:r.key})},[P]),L=M((r)=>{if(r.target.classList.contains("expanded-overlay-backdrop"))l6()},[]),I=M(()=>{if(!v)return;let r=DB(v);if(!r)return;navigator.clipboard.writeText(r).then(()=>{_(!0),setTimeout(()=>_(!1),1500)})},[v]),Y=M(()=>{if(!$)return;I4($)},[$]);if(m(()=>{z(!1)},[$]),hg(()=>{if(!U)return;let r=()=>{let p=G.current;if(!p||p.contains(document.activeElement))return;p.focus()},y=[0,50,150].map((p)=>window.setTimeout(r,p)),v$=(p)=>{if(!Cq(p.data,b))return;z(!1)};return document.addEventListener("keydown",A,!0),window.addEventListener("message",v$),()=>{y.forEach((p)=>window.clearTimeout(p)),document.removeEventListener("keydown",A,!0),window.removeEventListener("message",v$)}},[A,b,U]),!v)return null;let F=v.data.title||v.data.path?.split("/").pop()||a$[v.type],X=DB(v),Q=Vq(X),u=$?j$.value.has($):!1,c=X.length>0,N=Ev.value===$,t=v.type==="mcp-app"||v.type==="webpage"||v.type==="json-render"||v.type==="graph",a=SW(v);return O("div",{class:"expanded-overlay-backdrop",onPointerDown:L,style:{position:"fixed",inset:0,zIndex:10001,background:"rgba(10,14,30,0.85)",backdropFilter:"blur(8px)",display:"flex",alignItems:"stretch",justifyContent:"center",padding:"32px",pointerEvents:N?"none":"auto"},children:O("div",{class:"expanded-overlay-panel",style:{flex:1,maxWidth:"1200px",display:"flex",flexDirection:"column",background:"var(--c-panel)",border:`1px solid ${u?"var(--c-warn)":"var(--c-accent)"}`,borderRadius:"var(--radius)",boxShadow:`0 0 0 1px ${u?"var(--c-warn)":"var(--c-accent)"}, 0 24px 80px rgba(0,0,0,0.6)`,overflow:"hidden"},children:[O("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 16px",background:"var(--c-panel-glass)",borderBottom:"1px solid var(--c-line)",flexShrink:0},children:[O("span",{style:{fontSize:"10px",padding:"1px 6px",borderRadius:"4px",background:"var(--c-accent-12)",color:"var(--c-accent)",textTransform:"uppercase",letterSpacing:"0.04em"},children:a$[v.type]},void 0,!1,void 0,this),O("span",{style:{flex:1,fontSize:"13px",fontWeight:600,color:"var(--c-text)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:F},void 0,!1,void 0,this),O("div",{class:"expanded-actions",children:[O("button",{type:"button",class:`expanded-action-btn ${u?"expanded-action-active":""}`,onClick:Y,title:u?"Remove from context":"Pin as context",children:u?"✦ In context":"✦ Pin as context"},void 0,!1,void 0,this),c&&O("button",{type:"button",class:"expanded-action-btn",onClick:I,title:"Copy content to clipboard",children:g?"Copied!":"Copy"},void 0,!1,void 0,this),N0(v)&&O("button",{type:"button",class:"expanded-action-btn",onClick:()=>void u0(v),title:"Open as a full-page site in the system browser",children:"Open as site"},void 0,!1,void 0,this),a&&O("button",{type:"button",class:"expanded-action-btn expanded-action-primary",onClick:B,title:"Present this HTML node fullscreen",children:"Present"},void 0,!1,void 0,this),Q>0&&O("span",{class:"expanded-meta",children:[Q.toLocaleString()," word",Q!==1?"s":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O("span",{style:{fontSize:"10px",color:N?"var(--c-warn)":"var(--c-muted)"},children:N?"Saving edits...":"Esc to close"},void 0,!1,void 0,this),O("button",{type:"button",onClick:W,style:{background:"none",border:"none",color:"var(--c-muted)",cursor:"pointer",padding:"2px 6px",fontSize:"16px",lineHeight:1,borderRadius:"4px"},onMouseEnter:(r)=>{r.target.style.color="var(--c-text)"},onMouseLeave:(r)=>{r.target.style.color="var(--c-muted)"},title:"Close (Esc)",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{style:{flex:1,overflow:"auto",padding:"16px",minHeight:0,...t?{display:"flex",flexDirection:"column"}:{}},children:t?O("div",{style:{flex:1,minHeight:0,display:"flex"},children:yB(v,!0)},void 0,!1,void 0,this):yB(v,!0)},void 0,!1,void 0,this),a&&U&&O("div",{ref:G,class:"html-presentation-overlay",role:"dialog","aria-modal":"true","aria-label":`Present ${F}`,tabIndex:-1,onKeyDownCapture:A,children:[O("button",{ref:K,type:"button",class:"html-presentation-exit",onClick:k,title:"Exit presentation (Esc)","aria-label":"Exit presentation",children:"Exit presentation"},void 0,!1,void 0,this),O("div",{class:"html-presentation-stage",children:O(Qg,{node:v,expanded:!0,presentation:!0,presentationExitToken:b},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 kU=180,PU=120,T0=20;function cq(){let $=Z0();return{markdown:$.accent,"mcp-app":$.ok,webpage:$.warn,"json-render":$.ok,graph:$.purple,prompt:$.accent,response:$.ok,status:$.warn,context:$.muted,ledger:$.dim,trace:$.purple,file:$.accent,image:$.ok,html:$.warn,group:$.dim}}function mq(){let $=Z0();return{relation:$.muted,"depends-on":$.warn,flow:$.accent,references:$.dim}}function VB($,v,g,_){let U=Array.from($.values()),z=0,b=0,J=1000,G=800;if(U.length>0){z=Number.POSITIVE_INFINITY,b=Number.POSITIVE_INFINITY,J=Number.NEGATIVE_INFINITY,G=Number.NEGATIVE_INFINITY;for(let I of U)z=Math.min(z,I.position.x),b=Math.min(b,I.position.y),J=Math.max(J,I.position.x+I.size.width),G=Math.max(G,I.position.y+I.size.height)}let K=-v.x/v.scale,W=-v.y/v.scale,B=K+g/v.scale,P=W+_/v.scale,k={minX:Math.min(z,K)-T0,minY:Math.min(b,W)-T0,maxX:Math.max(J,B)+T0,maxY:Math.max(G,P)+T0},A=k.maxX-k.minX||1,L=k.maxY-k.minY||1;return{bounds:k,scale:Math.min(kU/A,PU/L)}}function CB({viewport:$,nodes:v,edges:g,onNavigate:_,containerWidth:U,containerHeight:z}){let b=V(null),J=V(!1),G=V(null),K=V(null),W=M(()=>{let L=b.current;if(!L)return;let I=L.getContext("2d");if(!I)return;let Y=v.value,F=g.value,X=$.value,Q=window.devicePixelRatio||1;L.width=kU*Q,L.height=PU*Q,I.scale(Q,Q),I.clearRect(0,0,kU,PU);let u=Z0();I.fillStyle=u.panel+"d9",I.fillRect(0,0,kU,PU);let c=VB(Y,X,U,z);G.current=c;let{bounds:N,scale:t}=c,a=(S)=>(S-N.minX)*t,r=(S)=>(S-N.minY)*t,y=Array.from(Y.values()),v$=cq();for(let S of y)I.fillStyle=v$[S.type]??u.muted,I.globalAlpha=0.6,I.fillRect(a(S.position.x),r(S.position.y),Math.max(4,S.size.width*t),Math.max(3,S.size.height*t));let p=mq();for(let S of F.values()){let h=Y.get(S.from),$$=Y.get(S.to);if(!h||!$$)continue;let s=a(h.position.x+h.size.width/2),K$=r(h.position.y+h.size.height/2),J$=a($$.position.x+$$.size.width/2),e=r($$.position.y+$$.size.height/2);I.beginPath(),I.moveTo(s,K$),I.lineTo(J$,e),I.strokeStyle=p[S.type]??u.muted,I.globalAlpha=0.3,I.lineWidth=0.5,I.stroke()}let i=-X.x/X.scale,Y$=-X.y/X.scale,_$=U/X.scale,x$=z/X.scale;I.globalAlpha=1,I.strokeStyle=u.accent,I.lineWidth=1.5,I.strokeRect(a(i),r(Y$),_$*t,x$*t)},[v,g,$,U,z]),B=V(W);B.current=W;let P=M(()=>{if(K.current!==null)return;K.current=window.requestAnimationFrame(()=>{K.current=null,B.current()})},[]);_K(()=>{V$.value,v.value,g.value,$.value,P()}),m(()=>{P()},[U,z,P]),m(()=>()=>{if(K.current!==null)window.cancelAnimationFrame(K.current),K.current=null},[]);let k=M((L)=>{let I=b.current;if(!I)return;let Y=I.getBoundingClientRect(),F=L.clientX-Y.left,X=L.clientY-Y.top,Q=G.current??VB(v.value,$.value,U,z);G.current=Q;let{bounds:u,scale:c}=Q,N=$.value,t=U/N.scale,a=z/N.scale,r=F/c+u.minX,y=X/c+u.minY;_(-(r-t/2)*N.scale,-(y-a/2)*N.scale)},[v,$,U,z,_]),A=M((L)=>{L.stopPropagation(),J.current=!0,k(L);let I=(F)=>{if(J.current)k(F)},Y=()=>{J.current=!1,document.removeEventListener("pointermove",I),document.removeEventListener("pointerup",Y)};document.addEventListener("pointermove",I),document.addEventListener("pointerup",Y)},[k]);return O("div",{style:{position:"fixed",bottom:"16px",right:"16px",zIndex:9998,border:"1px solid var(--c-line)",borderRadius:"var(--radius-sm)",overflow:"hidden",boxShadow:"0 4px 16px var(--c-shadow)"},children:O("canvas",{ref:b,width:kU,height:PU,style:{width:`${kU}px`,height:`${PU}px`,display:"block",cursor:"pointer"},onPointerDown:A},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function fB(){let $=i$.value.size;if($===0)return null;let v=M(()=>{let U=Array.from(i$.value);if(U.length===0)return;RK(U),Tv()},[]),g=M(()=>{let U=Array.from(i$.value);if(U.length===0)return;G_({title:"Group",childIds:U}),Tv()},[]),_=M(()=>{let U=Array.from(i$.value);for(let z=0;z<U.length;z++)for(let b=z+1;b<U.length;b++)W4(U[z],U[b],"relation");Tv()},[]);return O("div",{class:"selection-bar",children:[O("span",{class:"selection-bar-count",children:["✦"," ",$," node",$!==1?"s":""," selected"]},void 0,!0,void 0,this),O("button",{type:"button",class:"selection-bar-btn selection-bar-pin-ctx",onClick:v,children:"Pin as context"},void 0,!1,void 0,this),$>=2&&O("button",{type:"button",class:"selection-bar-btn",onClick:g,children:"Group"},void 0,!1,void 0,this),$>=2&&O("button",{type:"button",class:"selection-bar-btn",onClick:_,children:"Connect"},void 0,!1,void 0,this),O("button",{type:"button",class:"selection-bar-btn selection-bar-clear",onClick:Tv,title:"Clear selection",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Eq=[{title:"Navigation",shortcuts:[{keys:`${Xv}+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:`${Xv}+0`,desc:"Reset viewport to origin"},{keys:`${Xv}++ / ${Xv}+−`,desc:"Zoom in / out"}]},{title:"Creation",shortcuts:[{keys:"Double-click",desc:"Create new markdown note 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:"Shift+Drag",desc:"Lasso select multiple nodes"},{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 toolbar)"},{keys:"Right-click",desc:"Context menu — dock, focus, connect"}]}];function cB({onClose:$}){return O("div",{class:"shortcut-overlay-backdrop",onMouseDown:$,children:O("div",{class:"shortcut-overlay",onMouseDown:(v)=>v.stopPropagation(),children:[O("div",{class:"shortcut-overlay-header",children:[O("span",{class:"shortcut-overlay-title",children:"Keyboard Shortcuts"},void 0,!1,void 0,this),O("span",{class:"shortcut-overlay-hint",children:["Press ",O("kbd",{children:"?"},void 0,!1,void 0,this)," or ",O("kbd",{children:"Esc"},void 0,!1,void 0,this)," to close"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"shortcut-overlay-body",children:Eq.map((v)=>O("div",{class:"shortcut-group",children:[O("div",{class:"shortcut-group-title",children:v.title},void 0,!1,void 0,this),v.shortcuts.map((g)=>O("div",{class:"shortcut-row",children:[O("kbd",{class:"shortcut-keys",children:g.keys},void 0,!1,void 0,this),O("span",{class:"shortcut-desc",children:g.desc},void 0,!1,void 0,this)]},g.keys,!0,void 0,this))]},v.title,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function iq($){let v=Date.now()-new Date($).getTime(),g=Math.floor(v/60000);if(g<1)return"just now";if(g<60)return`${g}m ago`;let _=Math.floor(g/60);if(_<24)return`${_}h ago`;return`${Math.floor(_/24)}d ago`}function mB({open:$,onClose:v,anchorRef:g}){let[_,U]=x([]),[z,b]=x(!1),[J,G]=x(!1),[K,W]=x(null),[B,P]=x(""),[k,A]=x(null),L=V(null),I=V(null);m(()=>{if(!$)return;b(!0),AK().then((N)=>{U(N),b(!1)})},[$]),m(()=>{if($)setTimeout(()=>I.current?.focus(),50)},[$]),m(()=>{if(!$)return;let N=(t)=>{let a=L.current,r=g.current;if(a&&!a.contains(t.target)&&r&&!r.contains(t.target))v()};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[$,v]),m(()=>{if(!$)return;let N=(t)=>{if(t.key==="Escape")v()};return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[$,v]);let Y=M(async()=>{let N=B.trim();if(!N)return;G(!0);let t=await qK(N);if(G(!1),t.ok&&t.snapshot)U((a)=>[t.snapshot,...a]),P("")},[B]),F=M(async(N)=>{A(null),W(N);let t=await XK(N);if(W(null),t.ok)v()},[v]),X=M(async(N)=>{if((await wK(N)).ok)U((a)=>a.filter((r)=>r.id!==N));A(null)},[]);if(!$)return null;let Q=g.current?.getBoundingClientRect(),u=Q?Math.max(8,Q.left-120):100,c=Q?Q.bottom+8:48;return O("div",{ref:L,class:"snapshot-panel",style:{left:`${u}px`,top:`${c}px`},children:[O("div",{class:"snapshot-panel-header",children:[O("span",{class:"snapshot-panel-title",children:"Snapshots"},void 0,!1,void 0,this),O("button",{type:"button",class:"snapshot-panel-close",onClick:v,title:"Close",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"snapshot-save-form",children:[O("input",{ref:I,type:"text",class:"snapshot-name-input",value:B,onInput:(N)=>P(N.target.value),onKeyDown:(N)=>{if(N.key==="Enter")Y()},placeholder:"Snapshot name...",maxLength:80,disabled:J},void 0,!1,void 0,this),O("button",{type:"button",class:"snapshot-save-btn",onClick:Y,disabled:!B.trim()||J,children:J?"...":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"snapshot-restore-note",children:"Restoring replaces the current canvas. You can undo it if needed."},void 0,!1,void 0,this),O("div",{class:"snapshot-list",children:[z&&O("div",{class:"snapshot-empty",children:"Loading..."},void 0,!1,void 0,this),!z&&_.length===0&&O("div",{class:"snapshot-empty",children:"No snapshots yet. Save one to capture the current canvas state."},void 0,!1,void 0,this),!z&&_.map((N)=>O("div",{class:"snapshot-item",children:[O("div",{class:"snapshot-item-info",children:[O("span",{class:"snapshot-item-name",children:N.name},void 0,!1,void 0,this),O("span",{class:"snapshot-item-meta",children:[N.nodeCount," node",N.nodeCount!==1?"s":"",N.edgeCount>0?` · ${N.edgeCount} edge${N.edgeCount!==1?"s":""}`:""," · ",iq(N.createdAt)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"snapshot-item-actions",children:k?.id===N.id?O(d$,{children:[O("button",{type:"button",class:`snapshot-action-btn ${k.action==="delete"?"snapshot-action-confirm":"snapshot-action-restore"}`,onClick:()=>k.action==="delete"?X(N.id):F(N.id),title:k.action==="delete"?"Confirm delete":"Confirm restore",disabled:K!==null,children:k.action==="delete"?"Delete":K===N.id?"Restoring...":"Confirm"},void 0,!1,void 0,this),O("button",{type:"button",class:"snapshot-action-btn",onClick:()=>A(null),title:"Cancel",disabled:K!==null,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O(d$,{children:[O("button",{type:"button",class:"snapshot-action-btn snapshot-action-restore",onClick:()=>A({id:N.id,action:"restore"}),title:"Restore this snapshot",disabled:K!==null,children:K===N.id?"Restoring...":"Restore"},void 0,!1,void 0,this),O("button",{type:"button",class:"snapshot-action-btn snapshot-action-delete",onClick:()=>A({id:N.id,action:"delete"}),title:"Delete this snapshot",disabled:K!==null,children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},N.id,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function EB($,v,g,_,U){return $.x<_.position.x+_.size.width+U&&$.x+v+U>_.position.x&&$.y<_.position.y+_.size.height+U&&$.y+g+U>_.position.y}function lq($,v,g,_,U){return _.some((z)=>EB($,v,g,z,U))}function hq($,v,g,_,U){return _.find((z)=>EB($,v,g,z,U))}function j0($,v,g,_=24){if($.length===0)return{x:40,y:80};let U=$[$.length-1],z={x:U.position.x+U.size.width+_,y:U.position.y};if(!lq(z,v,g,$,_))return z;let b=40,J=80,G=3000,K=J;for(let B=0;B<20;B++){let P=b;while(P+v<G){let L=hq({x:P,y:K},v,g,$,_);if(!L)return{x:P,y:K};P=L.position.x+L.size.width+_}K=$.filter((L)=>L.position.y<=K+g+_&&L.position.y+L.size.height+_>K).reduce((L,I)=>Math.max(L,I.position.y+I.size.height),K)+_}let W=$.reduce((B,P)=>Math.max(B,P.position.y+P.size.height),0);return{x:b,y:W+_}}var Rg=null,YG=null,LG=0,V6=null,C0=new Map;function yg($){let v=0;for(let g=0;g<$.length;g++)v=(v<<5)-v+$.charCodeAt(g)|0;return Math.abs(v).toString(36)}function f0($){if(!YG)return $;let v=YG.get($.id);if(!v)return $;return{...$,position:v.position??$.position,size:v.size??$.size,collapsed:v.collapsed??$.collapsed,pinned:v.pinned??$.pinned,dockPosition:v.dockPosition!==void 0?v.dockPosition:$.dockPosition}}var tv={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},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 Dg($,v,g,_=null){let U=tv[v];return f0({id:$,type:v,position:{x:U.x,y:U.y},size:{width:U.w,height:U.h},zIndex:v==="status"?0:1,collapsed:!1,pinned:!1,dockPosition:_,data:g})}function xq(){return j0([...T.value.values()],tv.markdown.w,tv.markdown.h)}function v4(){if(!T.value.has("status-main"))v6(Dg("status-main","status",{phase:"idle",message:"",elapsed:0},"left"))}function pq($,v){let g=`md-${yg($)}`;if(T.value.get(g))g$(g,{path:$,title:v}),T$.value=g;else{let U=xq(),z=Dg(g,"markdown",{path:$,title:v,content:"",rendered:""});if(z.position=U,v6(z),!z.dockPosition)Pv(g)}}function oq($){if(T.value.get("context-main"))g$("context-main",{cards:$});else if($.length>0){let _=Dg("context-main","context",{cards:$});v6(_)}}function nq($){let v=$.url,g=`mcp-${yg(v)}`;if(T.value.get(g))g$(g,$);else v6(Dg(g,"mcp-app",$)),Pv(g)}function tq($){let v=$.toolCallId,_=(typeof $.nodeId==="string"&&$.nodeId.length>0?$.nodeId:null)??(v.startsWith("ext-app-")?v:`ext-app-${v}`);if(T.value.get(_)){g$(_,$);return}let{serverName:z,toolName:b}=$;if(z&&b){for(let[I,Y]of T.value.entries())if(Y.type==="mcp-app"&&Y.data.mode==="ext-app"&&Y.data.serverName===z&&Y.data.toolName===b&&!Y.data.toolResult){g$(I,{...$});return}}let{_x:J,_y:G,_width:K,_height:W}=$,B=tv["mcp-app"],P=K??B.w,k=W??B.h,A=J===void 0||G===void 0?j0([...T.value.values()],P,k):null,L=f0({id:_,type:"mcp-app",position:{x:J??A?.x??B.x,y:G??A?.y??B.y},size:{width:P,height:k},zIndex:1,collapsed:!1,pinned:!1,dockPosition:null,data:{mode:"ext-app",...$}});if(v6(L),!L.dockPosition)Pv(_,{recordHistory:!1})}function dq($){let v=$.startsWith("ext-app-")?$:`ext-app-${$}`;if(T.value.has(v))return v;let g=`ext-app-${$}`;if(g!==v&&T.value.has(g))return g;for(let[_,U]of T.value.entries())if(U.type==="mcp-app"&&U.data.mode==="ext-app"&&U.data.toolCallId===$)return _;return null}function lB($){let v=typeof $.nodeId==="string"&&$.nodeId.length>0?$.nodeId:null;if(v&&T.value.has(v))return v;if(typeof $.toolCallId!=="string"||!$.toolCallId)return null;return dq($.toolCallId)}function hB($,v){if(typeof $!=="string"||!$)return null;if(typeof v!=="string"||!v)return null;let g=null;for(let[_,U]of T.value.entries())if(U.type==="mcp-app"&&U.data.mode==="ext-app"&&U.data.serverName===$&&U.data.toolName===v&&!U.data.toolResult){if(g)return null;g=_}return g}function xB($){if(T.value.get("ledger-main"))g$("ledger-main",$);else{let _=Dg("ledger-main","ledger",$,"right");_.collapsed=!0,v6(_)}}function pB($){if(!($==="dark"||$==="light"||$==="high-contrast"))return;if(document.documentElement.setAttribute("data-theme",$),bU(),V$.value!==$)V$.value=$}function aq($){return $==="markdown"||$==="mcp-app"||$==="webpage"||$==="json-render"||$==="graph"||$==="prompt"||$==="response"||$==="status"||$==="context"||$==="ledger"||$==="trace"||$==="file"||$==="image"||$==="html"||$==="group"}function sq($){return $==="relation"||$==="depends-on"||$==="flow"||$==="references"}function FG($){if(!$||typeof $!=="object")return null;let v=$;if(typeof v.x!=="number"||typeof v.y!=="number")return null;return{x:v.x,y:v.y}}function oB($){if(!$||typeof $!=="object")return null;let v=$;if(typeof v.width!=="number"||typeof v.height!=="number")return null;return{width:v.width,height:v.height}}function eq($){let v=FG($),g=oB($);return v&&g?{...v,...g}:null}function $X($){if(typeof $.id!=="string"||!$.id)return null;if(!aq($.type))return null;let v=FG($.position),g=oB($.size);if(!v||!g)return null;let _=$.dockPosition==="left"||$.dockPosition==="right"?$.dockPosition:null,U=$.data&&typeof $.data==="object"?Object.fromEntries(Object.entries($.data)):{};return{id:$.id,type:$.type,position:v,size:g,zIndex:typeof $.zIndex==="number"?$.zIndex:1,collapsed:$.collapsed===!0,pinned:$.pinned===!0,dockPosition:_,data:U}}function vX($){if(typeof $.id!=="string"||!$.id)return null;if(typeof $.from!=="string"||!$.from)return null;if(typeof $.to!=="string"||!$.to)return null;if(!sq($.type))return null;return{id:$.id,from:$.from,to:$.to,type:$.type,...typeof $.label==="string"?{label:$.label}:{},...$.style==="solid"||$.style==="dashed"||$.style==="dotted"?{style:$.style}:{},...$.animated===!0?{animated:!0}:{}}}function UX($){if(typeof $.id!=="string"||!$.id)return null;if($.type!=="freehand"&&$.type!=="text")return null;if(!Array.isArray($.points))return null;let v=$.points.map((_)=>FG(_)).filter((_)=>_!==null),g=eq($.bounds);if(v.length<($.type==="text"?1:2)||!g)return null;return{id:$.id,type:$.type,points:v,bounds:g,color:typeof $.color==="string"?$.color:"#f97316",width:typeof $.width==="number"?$.width:4,...typeof $.text==="string"?{text:$.text}:{},...typeof $.label==="string"?{label:$.label}:{},createdAt:typeof $.createdAt==="string"?$.createdAt:""}}function gX($){if(P4.value=$.sessionId||"",E6.value="connected",typeof $.theme==="string")pB($.theme);if($.ledgerSummary)xB($.ledgerSummary)}function _X($){if(typeof $.path!=="string"||!$.path)return;let v=$.path,g=(typeof $.title==="string"?$.title:"")||v.split("/").pop()||"Untitled";if(pq(v,g),$.ledgerSummary)xB($.ledgerSummary)}function zX($){v4(),g$("status-main",{message:typeof $.message==="string"?$.message:String($.message??""),level:$.level??"ok",source:$.source})}function bX($){v4(),g$("status-main",{phase:$.phase,detail:$.detail})}function JX($){let v=$.cards??[];oq(v)}function OX($){if(typeof $.url==="string"&&$.url)nq({url:$.url,sourceServer:$.sourceServer,sourceTool:$.sourceTool,inferredType:$.inferredType,trustedDomain:$.trustedDomain,hostMode:$.hostMode??"hosted"})}function GX($){let v=$.sessions??[];for(let g of v){let _=g.url;if(!_)continue;let U=`mcp-${yg(_)}`;if(T.value.has(U))g$(U,{sessionState:g.state,lastSeenAt:g.lastSeenAt})}}function KX($){if(typeof $.url==="string"&&$.url){let v=`mcp-${yg($.url)}`;if(T.value.has(v))g$(v,{hostMode:"fallback",fallbackReason:$.reasonCode})}}function WX($){let g=T.value.get("context-main");if(!g)return;let _=(g.data.auxTabs??[]).concat($);g$("context-main",{auxTabs:_})}function BX($){if(T.value.has("context-main"))if($.mode==="all")g$("context-main",{auxTabs:[]});else{let _=T.value.get("context-main");if(!_)return;let U=(_.data.auxTabs??[]).filter((z)=>z.id!==$.id);g$("context-main",{auxTabs:U})}}function kX($){v4(),g$("status-main",{phase:"idle",lastCompletion:{tokenCount:$.tokenCount,artifactCount:$.artifactCount}})}function PX($){v4(),g$("status-main",{phase:"tooling",detail:`${$.name}`,activeTool:$.name})}function IX($){v4(),g$("status-main",{activeTool:null})}function HX($){if($.state==="active"&&$.path){let g=`md-${yg($.path)}`;if(T.value.has(g))g$(g,{reviewActive:!0})}}function LX($){if(typeof $.toolCallId!=="string"||!$.toolCallId)return;tq({toolCallId:$.toolCallId,...typeof $.nodeId==="string"&&$.nodeId.length>0?{nodeId:$.nodeId}:{},title:$.title,html:$.html,toolInput:$.toolInput,serverName:$.serverName,toolName:$.toolName,appSessionId:$.appSessionId,resourceUri:$.resourceUri,toolDefinition:$.toolDefinition,resourceMeta:$.resourceMeta,hostMode:"hosted",trustedDomain:!0,...$.chartConfig?{chartConfig:$.chartConfig}:{},...typeof $.x==="number"&&{_x:$.x},...typeof $.y==="number"&&{_y:$.y},...typeof $.width==="number"&&{_width:$.width},...typeof $.height==="number"&&{_height:$.height}})}function YX($){if(typeof $.toolCallId!=="string"||!$.toolCallId)return;let v=lB($)??hB($.serverName,$.toolName);if(!v)return;if(T.value.has(v))g$(v,{html:$.html})}function FX($){if(typeof $.toolCallId!=="string"||!$.toolCallId)return;let v=lB($)??hB($.serverName,$.toolName);if(!v)return;if(T.value.has(v)){if($.success===!1){H4(v);return}g$(v,{toolResult:tO({result:$.result,success:typeof $.success==="boolean"?$.success:void 0,error:typeof $.error==="string"?$.error:void 0,content:typeof $.content==="string"?$.content:void 0,detailedContent:typeof $.detailedContent==="string"?$.detailedContent:void 0})})}}function AX($){v4(),g$("status-main",{subagent:{state:$.state,name:$.agentDisplayName??$.agentName}})}function qX($){let v=$.nodeId;if(!v)return;let g=$.text||"",_=$.position,U=$.parentNodeId,z=$.contextNodeIds;if($.threadNodeId&&T.value.has($.threadNodeId)){let b=$.threadNodeId,J=T.value.get(b);if(!J)return;let G=Array.isArray(J.data.turns)?[...J.data.turns]:[],K=G[G.length-1];if(!K||K.role!=="user"||K.text!==g)G.push({role:"user",text:g,status:"pending"});g$(b,{turns:G,threadStatus:"pending"});return}if(!T.value.has(v)){let b=_??tv.prompt;v6(f0({id:v,type:"prompt",position:{x:b.x,y:b.y},size:{width:tv.prompt.w,height:400},zIndex:1,collapsed:!1,pinned:!1,dockPosition:null,data:{text:g,turns:g?[{role:"user",text:g,status:"pending"}]:[],threadStatus:g?"pending":"draft",status:g?"pending":"draft",parentNodeId:U,contextNodeIds:z}})),Pv(v)}if(U&&T.value.has(U))P_({id:`edge-${U}-${v}`,from:U,to:v,type:"flow",style:"dashed"})}function XX($){let{nodeId:v,status:g}=$;if(v&&T.value.has(v))g$(v,{status:g})}function wX($){let{responseNodeId:v,promptNodeId:g}=$;if(!v)return;let _=g?T.value.get(g):void 0;if(_&&Array.isArray(_.data.turns)){C0.set(v,g);let z=[..._.data.turns];z.push({role:"assistant",text:"",status:"streaming"}),g$(g,{turns:z,threadStatus:"streaming",_activeResponseId:v}),Pv(g);return}let U=_?{x:_.position.x,y:_.position.y+_.size.height+24}:{x:tv.response.x,y:tv.response.y};if(!T.value.has(v))v6(f0({id:v,type:"response",position:U,size:{width:tv.response.w,height:tv.response.h},zIndex:1,collapsed:!1,pinned:!1,dockPosition:null,data:{content:"",status:"streaming",promptNodeId:g}}));if(g)P_({id:`edge-${g}-${v}`,from:g,to:v,type:"flow",animated:!0});Pv(v)}function ZX($){let v=$.responseNodeId;if(!v)return;let g=C0.get(v);if(g){let _=T.value.get(g);if(_&&Array.isArray(_.data.turns)){let U=[..._.data.turns],z=U[U.length-1];if(z&&z.role==="assistant")z.text=$.content,z.status="streaming";g$(g,{turns:U,threadStatus:"streaming"})}return}if(!T.value.has(v))return;g$(v,{content:$.content,status:"streaming"})}function SX($){let v=$.responseNodeId;if(!v)return;let g=C0.get(v);if(g){let z=T.value.get(g);if(z&&Array.isArray(z.data.turns)){let b=[...z.data.turns],J=b[b.length-1];if(J&&J.role==="assistant")J.text=$.content,J.status="complete";g$(g,{turns:b,threadStatus:"answered",_activeResponseId:void 0})}C0.delete(v);return}if(!T.value.has(v))return;g$(v,{content:$.content,status:"complete"});let U=T.value.get(v)?.data.promptNodeId;if(U){let z=`edge-${U}-${v}`,b=m$.value.get(z);if(b)jK(z),P_({...b,animated:!1})}}function MX($){let v=$.layout;if(!v?.nodes)return;let g=!i6.value;i6.value=!0;let _=v.nodes.map($X).filter((J)=>J!==null),U=Array.isArray(v.edges)?v.edges.map(vX).filter((J)=>J!==null):Array.from(m$.value.values()),z=Array.isArray(v.annotations)?v.annotations.map(UX).filter((J)=>J!==null):void 0,b=v.viewport?{x:typeof v.viewport.x==="number"?v.viewport.x:0,y:typeof v.viewport.y==="number"?v.viewport.y:0,scale:typeof v.viewport.scale==="number"?v.viewport.scale:1}:void 0;F4(),iK({...b?{viewport:b}:{},nodes:_,edges:U,...z?{annotations:z}:{}},{applyViewport:g}),L2({event:"canvas-layout-update",data:$})}function QX($){if($<=1)return 500;if($===2)return 1000;return Math.min(2500,1500+($-3)*500)}function NX($){let v=$.nodeId;if(v&&T.value.has(v)){if($.noPan===!0){L6(v);return}Pv(v)}}function uX($){let v=$.viewport;if(!v)return;let g=typeof v.x==="number"?v.x:0,_=typeof v.y==="number"?v.y:0,U=typeof v.scale==="number"?v.scale:1;F4(),cK({x:g,y:_,scale:U})}function rX($){if(T.value.get("context-main"))g$("context-main",{currentTokens:$.currentTokens,tokenLimit:$.tokenLimit,messagesLength:$.messagesLength,utilization:$.utilization,nearLimit:$.nearLimit})}function RX($){W_.value=$.enabled===!0}function yX($){if(typeof $.theme==="string")pB($.theme)}function DX($){let v=Array.isArray($.nodeIds)?$.nodeIds.filter((g)=>typeof g==="string"):[];DK(v),L2({event:"context-pins-changed",data:$})}var V0=null;function iB(){if(V0)clearTimeout(V0);V0=setTimeout(()=>{V0=null,HK().then(($)=>{I6.value=$})},150)}function TX($){let v=$.intent;if(!v||typeof v.id!=="string"||typeof v.kind!=="string"||typeof v.expiresAt!=="number")return;DW(v)}function jX($){let v=typeof $.id==="string"?$.id:"";if(!v)return;if($.settled===!0)jW(v,typeof $.nodeId==="string"?$.nodeId:void 0);else zG(v)}var VX={connected:gX,"workbench-open":_X,"canvas-status":zX,"execution-phase":bX,"context-cards":JX,"mcp-app-candidate":OX,"mcp-app-host-snapshot":GX,"mcp-app-host-fallback":KX,"aux-open":WX,"aux-close":BX,"assistant-complete":kX,"tool-start":PX,"tool-complete":IX,"review-state":HX,"subagent-status":AX,"ext-app-open":LX,"ext-app-update":YX,"ext-app-result":FX,"context-pins-changed":DX,"canvas-layout-update":MX,"canvas-focus-node":NX,"canvas-viewport-update":uX,"context-usage":rX,"trace-state":RX,"theme-changed":yX,"canvas-prompt-created":qX,"canvas-prompt-status":XX,"canvas-response-start":wX,"canvas-response-delta":ZX,"canvas-response-complete":SX,"ax-state-changed":iB,"ax-event-created":iB,"ax-intent":TX,"ax-intent-clear":jX};function AG(){if(YG=hK(),v4(),i6.value=!1,z3(),VW(),V6)clearTimeout(V6),V6=null;let $=P4.value,v=$?`/api/workbench/events?session=${$}`:"/api/workbench/events";E6.value="connecting";let g=new EventSource(v);Rg=g;for(let[_,U]of Object.entries(VX))g.addEventListener(_,(z)=>{try{U(JSON.parse(z.data))}catch(b){console.warn(`[sse-bridge] Failed to parse "${_}" event:`,b)}});return g.onopen=()=>{if(Rg!==g)return;LG=0,E6.value="connected"},g.onerror=()=>{if(Rg!==g)return;E6.value="disconnected",g.close(),Rg=null,LG+=1,V6=setTimeout(()=>{V6=null,AG()},QX(LG))},()=>{if(V6)clearTimeout(V6),V6=null;g.close(),Rg=null}}function CX($,v){console.error(`[app] ${$} failed`,v)}function nB($,v={}){fetch(`/api/workbench/intent?_ts=${Date.now()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:$,payload:v})}).catch((g)=>{CX("sendIntent",g)})}function zv({label:$,detail:v,shortcut:g,align:_="center",children:U}){return O("span",{class:`toolbar-tooltip-anchor toolbar-tooltip-anchor-${_}`,children:[U,O("span",{class:"toolbar-tooltip",role:"tooltip",children:[O("span",{class:"toolbar-tooltip-label",children:$},void 0,!1,void 0,this),(v||g)&&O("span",{class:"toolbar-tooltip-meta",children:[v&&O("span",{children:v},void 0,!1,void 0,this),g&&O("kbd",{class:"toolbar-tooltip-shortcut",children:g},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 fX({minimapVisible:$,onToggleMinimap:v,snapshotOpen:g,onToggleSnapshot:_,snapshotBtnRef:U,onOpenPalette:z,onOpenShortcuts:b,annotationTool:J,onToggleAnnotationMode:G,onToggleAnnotationEraser:K,onToggleTextAnnotation:W}){let B=E6.value,P=i6.value,k=H$.value,A=T.value.size,L=m$.value.size,I=W_.value,Y=Array.from(T.value.values()).filter((u)=>u.type==="trace").length,F=B==="connected"&&!P?"syncing":B,X=F.charAt(0).toUpperCase()+F.slice(1),Q=P?[`${A} node${A!==1?"s":""}`,...L>0?[`${L} edge${L!==1?"s":""}`]:[],...Y>0?[`${Y} trace${Y!==1?"s":""}`]:I?["trace armed"]:[]].join(" · "):"Syncing canvas…";return O("div",{class:"toolbar-group",children:[O("div",{class:"canvas-toolbar",children:[O(zv,{label:"PMX Canvas",detail:"Focus Field · spatial workbench for coding agents",align:"start",children:O("span",{class:"canvas-brand","aria-label":"PMX Canvas",children:O(vB,{size:22},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{class:"separator"},void 0,!1,void 0,this),O(zv,{label:"Canvas status",detail:P?X:"Syncing canvas from server",align:"start",children:O("span",{class:`connection-dot ${B}`,"aria-label":`Canvas status: ${F}`},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("span",{class:"hud-collapsible-text",style:{fontSize:"11px",color:"var(--c-muted)"},children:P4.value?P4.value.slice(0,12):"…"},void 0,!1,void 0,this),O("div",{class:"separator"},void 0,!1,void 0,this),O(zv,{label:"Fit canvas",detail:"Frame every node on screen",children:O("button",{type:"button",onClick:()=>H_(window.innerWidth,window.innerHeight),"aria-label":"Fit canvas",children:O(cW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(zv,{label:"Reset view",shortcut:`${Xv}+0`,children:O("button",{type:"button",onClick:()=>iv({x:0,y:0,scale:1},250),"aria-label":"Reset view",children:O(mW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(zv,{label:"Zoom in",shortcut:`${Xv}++`,children:O("button",{type:"button",onClick:()=>iv({...k,scale:Math.min(4,k.scale*1.25)},150),"aria-label":"Zoom in",children:O(EW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(zv,{label:"Zoom out",shortcut:`${Xv}+-`,children:O("button",{type:"button",onClick:()=>iv({...k,scale:Math.max(0.1,k.scale/1.25)},150),"aria-label":"Zoom out",children:O(iW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("span",{class:"hud-collapsible-text",style:{fontSize:"10px",color:"var(--c-dim)",minWidth:"36px",textAlign:"center"},children:[Math.round(k.scale*100),"%"]},void 0,!0,void 0,this),O("div",{class:"separator"},void 0,!1,void 0,this),O(zv,{label:"Arrange layout",detail:L>0?"Graph-aware layout for connected nodes":"Grid layout for loose nodes",children:O("button",{type:"button",onClick:()=>L>0?Y_():L_(),"aria-label":"Arrange layout",children:O(lW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(zv,{label:$?"Hide minimap":"Show minimap",detail:"Quickly navigate large canvases",children:O("button",{type:"button",onClick:v,"aria-label":$?"Hide minimap":"Show minimap",style:{color:$?"var(--c-accent)":void 0},children:O(hW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(zv,{label:`Switch to ${V$.value==="dark"?"light":"dark"} theme`,detail:`Current theme: ${V$.value}`,children:O("button",{type:"button",onClick:()=>{let u=V$.value==="dark"?"light":"dark";document.documentElement.setAttribute("data-theme",u),bU(),V$.value=u,b_(u)},"aria-label":`Switch to ${V$.value==="dark"?"light":"dark"} theme`,children:V$.value==="dark"?O(xW,{},void 0,!1,void 0,this):O(pW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(zv,{label:"Snapshots",detail:"Capture and restore canvas states",align:"end",children:O("button",{ref:U,type:"button",onClick:_,"aria-label":"Snapshots",style:{color:g?"var(--c-accent)":void 0},children:O(dW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"canvas-toolbar",children:[O(zv,{label:I?"Disable trace":"Enable trace",detail:I?"Stop collecting new trace nodes":"Capture agent execution on the canvas",children:O("button",{type:"button",onClick:()=>nB("trace-toggle",{enabled:!I}),"aria-label":I?"Disable trace":"Enable trace",style:{color:I?"var(--c-purple)":void 0},children:O(aW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),(I||Y>0)&&O(zv,{label:"Clear trace",detail:Y>0?`Remove ${Y} trace node${Y===1?"":"s"}`:"Trace is enabled but still empty",children:O("button",{type:"button",onClick:()=>nB("trace-clear"),"aria-label":"Clear trace",children:O(sW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{class:"separator"},void 0,!1,void 0,this),O(zv,{label:J==="pen"?"Stop annotating":"Annotate canvas",detail:"Draw directly on the canvas for human-visible markup",children:O("button",{type:"button",onClick:G,"aria-label":J==="pen"?"Stop annotating":"Annotate canvas","aria-pressed":J==="pen",style:{color:J==="pen"?"var(--c-accent)":void 0},children:O(oW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(zv,{label:J==="eraser"?"Stop erasing":"Erase annotations",detail:"Click a drawn annotation to remove it",children:O("button",{type:"button",onClick:K,"aria-label":J==="eraser"?"Stop erasing":"Erase annotations","aria-pressed":J==="eraser",style:{color:J==="eraser"?"var(--c-accent)":void 0},children:O(nW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(zv,{label:J==="text"?"Stop text annotations":"Text annotations",detail:"Click anywhere to type an intent note",children:O("button",{type:"button",onClick:W,"aria-label":J==="text"?"Stop text annotations":"Text annotations","aria-pressed":J==="text",style:{color:J==="text"?"var(--c-accent)":void 0},children:O(tW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{class:"separator"},void 0,!1,void 0,this),O(zv,{label:"Search nodes and actions",shortcut:`${Xv}+K`,children:O("button",{type:"button",onClick:z,"aria-label":"Search nodes and actions",children:O(eW,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(zv,{label:"Keyboard shortcuts",shortcut:"?",align:"end",children:O("button",{type:"button",onClick:b,"aria-label":"Keyboard shortcuts",children:O($B,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("span",{class:"hud-collapsible-text",style:{fontSize:"10px",color:"var(--c-dim)"},children:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function cX({onOpenPalette:$}){return O("div",{class:"welcome-card",children:[O("div",{class:"welcome-icon",children:"◇"},void 0,!1,void 0,this),O("div",{class:"welcome-title",children:"Shape What The Agent Sees"},void 0,!1,void 0,this),O("div",{class:"welcome-subtitle",children:"Lay out notes, files, and evidence. Bring related nodes together. Pin what matters. The board will reflect the active focus."},void 0,!1,void 0,this),O("div",{class:"welcome-hints",children:[O("button",{type:"button",class:"welcome-hint",onClick:$,children:[O("kbd",{children:[Xv,"+K"]},void 0,!0,void 0,this),O("span",{children:"Create a note"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"welcome-hint",children:[O("kbd",{children:"Drop files"},void 0,!1,void 0,this),O("span",{children:"Add evidence to the board"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"welcome-hint",children:[O("kbd",{children:"✦"},void 0,!1,void 0,this),O("span",{children:"Pin important nodes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"welcome-hint",children:[O("kbd",{children:"Move nearby"},void 0,!1,void 0,this),O("span",{children:"Shape the focus field"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O("div",{class:"welcome-footer",children:"The canvas is a shared attention surface, not just an editor."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function tB(){let[$,v]=x(!0),[g,_]=x(!1),[U,z]=x(!1),[b,J]=x(!1),[G,K]=x(null),W=V(null),{menu:B,openNodeMenu:P,openCanvasMenu:k,closeMenu:A}=QB(),L=i6.value,I=M(()=>v((r)=>!r),[]),Y=M(()=>_((r)=>!r),[]),F=M(()=>_(!1),[]),X=M(()=>K((r)=>r==="pen"?null:"pen"),[]),Q=M(()=>K((r)=>r==="eraser"?null:"eraser"),[]),u=M(()=>K((r)=>r==="text"?null:"text"),[]),c=M((r,y)=>{iv({x:r,y,scale:H$.value.scale},200)},[]);m(()=>{return AG()},[]),m(()=>{let r=(y)=>{let v$=y.metaKey||y.ctrlKey;if(v$&&y.key==="k"){y.preventDefault(),z((i)=>!i);return}if(y.key==="Escape"&&G){y.preventDefault(),K(null);return}if(y.key==="Escape"&&c$.value&&!Ev.value){y.preventDefault(),l6();return}if(y.key==="Escape"&&U){y.preventDefault(),z(!1);return}if(y.key==="Escape"&&b){y.preventDefault(),J(!1);return}let p=y.target?.tagName;if(p==="INPUT"||p==="TEXTAREA")return;if(y.key==="?"||y.key==="/"&&y.shiftKey){y.preventDefault(),J((i)=>!i);return}if(v$&&y.key==="0")y.preventDefault(),iv({x:0,y:0,scale:1},250);else if(v$&&(y.key==="="||y.key==="+")){y.preventDefault();let i=H$.value;iv({...i,scale:Math.min(4,i.scale*1.25)},150)}else if(v$&&y.key==="-"){y.preventDefault();let i=H$.value;iv({...i,scale:Math.max(0.1,i.scale/1.25)},150)}else if(y.key==="Escape"){if(i$.value.size>0){Tv();return}T$.value=null,A()}else if(y.key==="Tab")y.preventDefault(),xK(y.shiftKey?-1:1);else if(T$.value&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(y.key)){y.preventDefault();let i=y.key.replace("Arrow","").toLowerCase();pK(i)}};return document.addEventListener("keydown",r),()=>{document.removeEventListener("keydown",r)}},[G,A,U,b]),m(()=>{if(!L)return;let r=window.__pmxCanvasBootstrapReady;if(typeof r==="function")r()},[L]);let N=Array.from(T.value.values()),t=N.filter((r)=>r.dockPosition==="left"),a=N.filter((r)=>r.dockPosition==="right").sort((r,y)=>{let v$={context:0,ledger:1};return(v$[r.type]??2)-(v$[y.type]??2)});return O("div",{style:{width:"100%",height:"100%",position:"relative"},children:[O("div",{class:"hud-layer",children:[O("div",{class:"hud-left",children:t.map((r)=>O(HG,{node:r},r.id,!1,void 0,this))},void 0,!1,void 0,this),O(fX,{minimapVisible:$,onToggleMinimap:I,snapshotOpen:g,onToggleSnapshot:Y,snapshotBtnRef:W,onOpenPalette:()=>z(!0),onOpenShortcuts:()=>J((r)=>!r),annotationTool:G,onToggleAnnotationMode:X,onToggleAnnotationEraser:Q,onToggleTextAnnotation:u},void 0,!1,void 0,this),O("div",{class:"hud-right",children:a.map((r)=>O(HG,{node:r},r.id,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O(nK,{},void 0,!1,void 0,this),O(oK,{},void 0,!1,void 0,this),O(SB,{onNodeContextMenu:P,onCanvasContextMenu:k,annotationMode:G!==null,annotationTool:G},void 0,!1,void 0,this),L&&N.filter((r)=>!r.dockPosition).length===0&&O(cX,{onOpenPalette:()=>z(!0)},void 0,!1,void 0,this),i$.value.size>0&&O(fB,{},void 0,!1,void 0,this),j$.value.size>0&&O(rB,{},void 0,!1,void 0,this),c$.value&&O(jB,{},void 0,!1,void 0,this),O(mB,{open:g,onClose:F,anchorRef:W},void 0,!1,void 0,this),$&&O(CB,{viewport:H$,nodes:T,edges:m$,onNavigate:c,containerWidth:window.innerWidth,containerHeight:window.innerHeight},void 0,!1,void 0,this),B&&O(NB,{menu:B,onClose:A},void 0,!1,void 0,this),U&&O(MB,{onClose:()=>z(!1),onToggleMinimap:I},void 0,!1,void 0,this),b&&O(cB,{onClose:()=>J(!1)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var dB=document.getElementById("app");if(dB)CG(O(tB,{},void 0,!1,void 0,this),dB);