@abuswami1996/agent-md 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1
4
+
5
+ - Fixed bundled viewer rendering for pie charts that use standard `x` and `y` fields instead of pie-specific `label` and `value` fields.
6
+ - Added colored pie slices for clearer platform/category breakdowns.
7
+
3
8
  ## 0.2.0
4
9
 
5
10
  - Fixed rendered primitive behavior in the bundled browser viewer, including forms, tabs, timelines, query sorting, and flowchart labels.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abuswami1996/agent-md",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Local-first Agent Markdown runtime, validator, browser viewer, and agent skill installer.",
5
5
  "license": "MIT",
6
6
  "author": "Abhinav Swaminathan",
@@ -3401,7 +3401,7 @@ Expecting `+j.join(`, `)+`, got '`+(this.terminals_[S]||S)+`'`:`Parse error on l
3401
3401
  `}else r+=`${e.themeCSS}
3402
3402
  `;return r+SE(n)},`createCssStyles`),bZt=V((e,t)=>MJ(crt(`${e}{${t}}`),prt([V(function(t,n,r,i){if(t.type===`rule`&&Array.isArray(t.props)){if(t.parent&&t.parent.type===`@keyframes`)return;t.props=t.props.map(t=>t.startsWith(e)?t:`${e} ${t}`)}else t.type.startsWith(`@`)&&([`@media`,`@supports`,`@layer`,`@scope`,`@container`,`@starting-style`,`@keyframes`].includes(t.type)||(H.warn(`Removing unsupported at-rule ${t.type} from CSS`),t.type=dJ))},`addNamespace`),frt])),`compileCSS`),xZt=V((e,t,n,r)=>bZt(r,qje(t,yZt(e,n),{...e.themeVariables,theme:e.theme,look:e.look},r)),`createUserStyles`),SZt=V((e=``,t,n)=>{let r=e;return!n&&!t&&(r=r.replace(/marker-end="url\([\d+./:=?A-Za-z-]*?#/g,`marker-end="url(#`)),r=Kj(r),r=r.replace(/<br>/g,`<br/>`),r},`cleanUpSvgCode`),CZt=V((e=``,t)=>`<iframe style="width:${cZt};height:${t?.viewBox?.baseVal?.height?t.viewBox.baseVal.height+`px`:lZt};${uZt}" src="data:text/html;charset=UTF-8;base64,${eZt(`<body style="${dZt}">${e}</body>`)}" sandbox="${fZt}">
3403
3403
  ${pZt}
3404
- </iframe>`,`putIntoIFrame`),wZt=V((e,t,n,r,i)=>{let a=e.append(`div`);a.attr(`id`,n),r&&a.attr(`style`,r);let o=a.append(`svg`).attr(`id`,t).attr(`width`,`100%`).attr(`xmlns`,aZt);return i&&o.attr(`xmlns:xlink`,i),o.append(`g`),e},`appendDivSvgG`);function TZt(e,t){return e.append(`iframe`).attr(`id`,t).attr(`style`,`width: 100%; height: 100%;`).attr(`sandbox`,``)}V(TZt,`sandboxedIframe`);var EZt=V((e,t,n,r)=>{e.getElementById(t)?.remove(),e.getElementById(n)?.remove(),e.getElementById(r)?.remove()},`removeExistingElements`),DZt=V(async function(e,t,n){q9();let r=gZt(t);t=r.code;let i=QE();H.debug(i),t.length>(i?.maxTextSize??tZt)&&(t=nZt);let a=`#${e}`,o=`i`+e,s=`#`+o,l=`d`+e,u=`#`+l,d=V(()=>{let e=fO(p?s:u).node();e&&`remove`in e&&e.remove()},`removeTempElements`),f=fO(document.body),p=i.securityLevel===rZt,m=i.securityLevel===iZt,h=i.fontFamily;n===void 0?(EZt(document,e,l,o),p?(f=fO(TZt(fO(document.body),o).nodes()[0].contentDocument.body),f.node().style.margin=`0`):f=fO(`body`),wZt(f,e,l)):(n&&(n.innerHTML=``),p?(f=fO(TZt(fO(n),o).nodes()[0].contentDocument.body),f.node().style.margin=`0`):f=fO(n),wZt(f,e,l,`font-family: ${h}`,oZt));let g,_;try{g=await GXt.fromText(t,{title:r.title})}catch(e){if(i.suppressErrorRendering)throw d(),e;g=await GXt.fromText(`error`),_=e}let v=f.select(u).node(),y=g.type,b=v.firstChild,x=b.firstChild,S=g.renderer.getClasses?.(t,g),C=xZt(i,y,S,a),w=document.createElement(`style`);w.innerHTML=C,b.insertBefore(w,x);try{await g.renderer.draw(t,e,`11.15.0`,g)}catch(n){throw i.suppressErrorRendering?d():cXt.draw(t,e,`11.15.0`),n}let T=f.select(`${u} svg`),E=g.db.getAccTitle?.(),D=g.db.getAccDescription?.();AZt(y,T,E,D),f.select(`[id="${e}"]`).selectAll(`foreignobject > *`).attr(`xmlns`,sZt);let O=f.select(u).node().innerHTML;if(H.debug(`config.arrowMarkerAbsolute`,i.arrowMarkerAbsolute),O=SZt(O,p,WE(i.arrowMarkerAbsolute)),p){let e=f.select(u+` svg`).node();O=CZt(O,e)}else m||(O=aS.sanitize(O,{ADD_TAGS:mZt,ADD_ATTR:hZt,HTML_INTEGRATION_POINTS:{foreignobject:!0}}));if(qXt(),_)throw _;return d(),{diagramType:y,svg:O,bindFunctions:g.db.bindFunctions}},`render`);function OZt(e={}){let t=jE({},e);t?.fontFamily&&!t.themeVariables?.fontFamily&&(t.themeVariables||={},t.themeVariables.fontFamily=t.fontFamily),Dje(t),t?.theme&&t.theme in IE?t.themeVariables=IE[t.theme].getThemeVariables(t.themeVariables):t&&(t.themeVariables=IE.default.getThemeVariables(t.themeVariables)),Gb((typeof t==`object`?Eje(t):XE()).logLevel),q9()}V(OZt,`initialize`);var kZt=V((e,t={})=>{let{code:n}=$Xt(e);return GXt.fromText(n,t)},`getDiagramFromText`);function AZt(e,t,n,r){UXt(t,e),WXt(t,n,r,t.attr(`id`))}V(AZt,`addA11yInfo`);var J9=Object.freeze({render:DZt,parse:_Zt,getDiagramFromText:kZt,initialize:OZt,getConfig:QE,setConfig:ZE,getSiteConfig:XE,updateSiteConfig:Oje,reset:V(()=>{eD()},`reset`),globalReset:V(()=>{eD(UE)},`globalReset`),defaultConfig:UE});Gb(QE().logLevel),eD(QE());var jZt=V((e,t,n)=>{H.warn(e),Mj(e)?(n&&n(e.str,e.hash),t.push({...e,message:e.str,error:e})):(n&&n(e),e instanceof Error&&t.push({str:e.message,message:e.message,hash:e.name,error:e}))},`handleError`),MZt=V(async function(e={querySelector:`.mermaid`}){try{await NZt(e)}catch(t){if(Mj(t)&&H.error(t.str),X9.parseError&&X9.parseError(t),!e.suppressErrors)throw H.error(`Use the suppressErrors option to suppress these errors`),t}},`run`),NZt=V(async function({postRenderCallback:e,querySelector:t,nodes:n}={querySelector:`.mermaid`}){let r=J9.getConfig();H.debug(`${e?``:`No `}Callback function found`);let i;if(n)i=n;else if(t)i=document.querySelectorAll(t);else throw Error(`Nodes and querySelector are both undefined`);H.debug(`Found ${i.length} diagrams`),r?.startOnLoad!==void 0&&(H.debug(`Start On Load: `+r?.startOnLoad),J9.updateSiteConfig({startOnLoad:r?.startOnLoad}));let a=new Gj.InitIDGenerator(r.deterministicIds,r.deterministicIDSeed),o,s=[];for(let t of Array.from(i)){if(H.info(`Rendering diagram: `+t.id),t.getAttribute(`data-processed`))continue;t.setAttribute(`data-processed`,`true`);let n=`mermaid-${a.next()}`;o=t.innerHTML,o=WHe(Gj.entityDecode(o)).trim().replace(/<br\s*\/?>/gi,`<br/>`);let r=Gj.detectInit(o);r&&H.debug(`Detected early reinit: `,r);try{let{svg:r,bindFunctions:i}=await HZt(n,o,t);t.innerHTML=r,e&&await e(n),i&&i(t)}catch(e){jZt(e,s,X9.parseError)}}if(s.length>0)throw s[0]},`runThrowsErrors`),PZt=V(function(e){J9.initialize(e)},`initialize`),FZt=V(async function(e,t,n){H.warn(`mermaid.init is deprecated. Please use run instead.`),e&&PZt(e);let r={postRenderCallback:n,querySelector:`.mermaid`};typeof t==`string`?r.querySelector=t:t&&(t instanceof HTMLElement?r.nodes=[t]:r.nodes=t),await MZt(r)},`init`),IZt=V(async(e,{lazyLoad:t=!0}={})=>{q9(),OE(...e),t===!1&&await VXt()},`registerExternalDiagrams`),LZt=V(function(){if(X9.startOnLoad){let{startOnLoad:e}=J9.getConfig();e&&X9.run().catch(e=>H.error(`Mermaid failed to initialize`,e))}},`contentLoaded`);typeof document<`u`&&window.addEventListener(`load`,LZt,!1);var RZt=V(function(e){X9.parseError=e},`setParseErrorHandler`),Y9=[],zZt=!1,BZt=V(async()=>{if(!zZt){for(zZt=!0;Y9.length>0;){let e=Y9.shift();if(e)try{await e()}catch(e){H.error(`Error executing queue`,e)}}zZt=!1}},`executeQueue`),VZt=V(async(e,t)=>new Promise((n,r)=>{let i=V(()=>new Promise((i,a)=>{J9.parse(e,t).then(e=>{i(e),n(e)},e=>{H.error(`Error parsing`,e),X9.parseError?.(e),a(e),r(e)})}),`performCall`);Y9.push(i),BZt().catch(r)}),`parse`),HZt=V((e,t,n)=>new Promise((r,i)=>{let a=V(()=>new Promise((a,o)=>{J9.render(e,t,n).then(e=>{a(e),r(e)},e=>{H.error(`Error parsing`,e),X9.parseError?.(e),o(e),i(e)})}),`performCall`);Y9.push(a),BZt().catch(i)}),`render`),X9={startOnLoad:!0,mermaidAPI:J9,parse:VZt,render:HZt,init:FZt,run:MZt,registerExternalDiagrams:IZt,registerLayoutLoaders:sJ,initialize:PZt,parseError:void 0,contentLoaded:LZt,setParseErrorHandler:RZt,detectType:DE,registerIconPacks:aN,getRegisteredDiagramsMetadata:V(()=>Object.keys(EE).map(e=>({id:e})),`getRegisteredDiagramsMetadata`)},UZt=X9;function WZt({document:e,staticArtifacts:t}){return(0,B.jsx)(`div`,{className:`agent-md-document`,children:e.nodes.map((n,r)=>(0,B.jsx)(GZt,{node:n,document:e,staticArtifacts:t},r))})}function GZt({node:e,document:t,staticArtifacts:n}){return e.type===`markdown`?(0,B.jsx)(eo,{children:e.value}):e.type===`error`?(0,B.jsx)(Z9,{message:e.message,raw:e.raw,diagnostic:pQt(t,e)}):e.type===`metric`?(0,B.jsx)(KZt,{node:e,dataSources:t.dataSources}):e.type===`chart`?(0,B.jsx)(qZt,{node:e,dataSources:t.dataSources}):e.type===`table`?(0,B.jsx)(YZt,{node:e,dataSources:t.dataSources}):e.type===`callout`?(0,B.jsx)(QZt,{node:e,document:t,staticArtifacts:n}):e.type===`tabs`?(0,B.jsx)($Zt,{node:e,document:t,staticArtifacts:n}):e.type===`query`?(0,B.jsx)(XZt,{node:e,dataSources:t.dataSources}):e.type===`timeline`?(0,B.jsx)(eQt,{node:e}):e.type===`diagram`?(0,B.jsx)(tQt,{node:e,document:t,staticArtifacts:n}):e.type===`map`?(0,B.jsx)(oQt,{node:e,dataSources:t.dataSources}):e.type===`embed`?(0,B.jsx)(nQt,{node:e,document:t,staticArtifacts:n}):e.type===`form`?(0,B.jsx)(lQt,{node:e}):e.type===`component`?(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-component-placeholder`,children:[(0,B.jsxs)(`strong`,{children:[`Registered component: `,e.name]}),(0,B.jsx)(`p`,{children:`Custom rendering is disabled by the current security config, so this safe placeholder is expected.`})]}):null}function Z9({message:e,raw:t,diagnostic:n,suggestion:r}){let i=r??n?.suggestion??`Check this block's fields and data references, then run agent-md validate again.`;return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-error`,children:[(0,B.jsx)(`strong`,{children:e}),(0,B.jsx)(`p`,{children:i}),n?.line?(0,B.jsxs)(`small`,{children:[`Source line `,n.line]}):null,n?.field?(0,B.jsxs)(`small`,{children:[` Field: `,n.field]}):null,n?.example?(0,B.jsx)(`pre`,{children:n.example}):t?(0,B.jsx)(`pre`,{children:t}):null]})}function KZt({node:e,dataSources:t}){let n=(0,E.useMemo)(()=>{if(e.value!=null)return e.value;let n=e.data?t[e.data]?.rows??[]:[];if(!e.field)return``;let r=n.map(t=>Number(t[e.field])).filter(Number.isFinite);return e.aggregate===`count`?n.length:e.aggregate===`avg`?r.reduce((e,t)=>e+t,0)/Math.max(r.length,1):e.aggregate===`min`?Math.min(...r):e.aggregate===`max`?Math.max(...r):r.reduce((e,t)=>e+t,0)},[e,t]);return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-metric`,children:[(0,B.jsx)(`span`,{children:e.label}),(0,B.jsx)(`strong`,{children:fQt(n,e.format)}),e.delta?(0,B.jsx)(`small`,{children:e.delta}):null,e.description?(0,B.jsx)(`p`,{children:e.description}):null]})}function qZt({node:e,dataSources:t}){let n=t[e.data]?.rows??[],r=e.height??320;if(n.length===0)return(0,B.jsx)(Z9,{message:`No rows available for ${e.data}`,raw:`[Chart: ${e.chartType}]`,suggestion:`Confirm the chart's data source exists and contains rows before sharing this report.`});let i={data:n};return(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e.title??dQt(e)}),e.description?(0,B.jsx)(`p`,{children:e.description}):null,(0,B.jsx)(jre,{width:`100%`,height:r,children:JZt(e,i)})]})}function JZt(e,t){let n=Array.isArray(e.y)?e.y:e.y?[e.y]:[];return e.chartType===`bar`?(0,B.jsxs)(PDe,{...t,children:[(0,B.jsx)(Cb,{dataKey:e.x}),(0,B.jsx)(wb,{}),(0,B.jsx)(xy,{}),e.legend===!1?null:(0,B.jsx)(fm,{}),n.map((e,t)=>(0,B.jsx)(sTe,{dataKey:e,fill:Q9(t)},e))]}):e.chartType===`area`?(0,B.jsxs)(iOe,{...t,children:[(0,B.jsx)(Cb,{dataKey:e.x}),(0,B.jsx)(wb,{}),(0,B.jsx)(xy,{}),n.map((e,t)=>(0,B.jsx)(dwe,{dataKey:e,fill:Q9(t),stroke:Q9(t)},e))]}):e.chartType===`scatter`?(0,B.jsxs)(nOe,{children:[(0,B.jsx)(Cb,{dataKey:e.x}),(0,B.jsx)(wb,{dataKey:typeof e.y==`string`?e.y:void 0}),(0,B.jsx)(xy,{}),(0,B.jsx)(PTe,{data:t.data,fill:Q9(0)})]}):e.chartType===`pie`?(0,B.jsxs)(eOe,{children:[(0,B.jsx)(xy,{}),(0,B.jsx)(Jbe,{data:t.data,dataKey:e.value,nameKey:e.label,fill:Q9(0)})]}):(0,B.jsxs)(MDe,{...t,children:[(0,B.jsx)(Cb,{dataKey:e.x}),(0,B.jsx)(wb,{}),(0,B.jsx)(xy,{}),e.legend===!1?null:(0,B.jsx)(fm,{}),n.map((e,t)=>(0,B.jsx)(jCe,{dataKey:e,stroke:Q9(t)},e))]})}function Q9(e){return`var(--agent-md-chart-${e+1}, var(--agent-md-chart-1, #2563eb))`}function YZt({node:e,dataSources:t}){return(0,B.jsx)(ZZt,{title:e.title,rows:t[e.data]?.rows??[],columns:e.columns,pageSize:e.pageSize??25})}function XZt({node:e,dataSources:t}){let n=t[e.data],r=n?jQt(n.rows??[],e):[];return e.view===`json`?(0,B.jsx)(`pre`,{children:JSON.stringify(r,null,2)}):(0,B.jsx)(ZZt,{title:`Query`,rows:r,columns:e.select,pageSize:25})}function ZZt({title:e,rows:t,columns:n,pageSize:r}){let[i,a]=(0,E.useState)(``),[o,s]=(0,E.useState)(),l=n?.length?n:Object.keys(t[0]??{}),u=t.filter(e=>JSON.stringify(e).toLowerCase().includes(i.toLowerCase())),d=o?[...u].sort((e,t)=>String(e[o]).localeCompare(String(t[o]))):u;return(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e??`Table`}),(0,B.jsx)(`input`,{placeholder:`Search`,value:i,onChange:e=>a(e.target.value)}),(0,B.jsxs)(`table`,{children:[(0,B.jsx)(`thead`,{children:(0,B.jsx)(`tr`,{children:l.map(e=>(0,B.jsx)(`th`,{onClick:()=>s(e),children:e},e))})}),(0,B.jsx)(`tbody`,{children:d.slice(0,r).map((e,t)=>(0,B.jsx)(`tr`,{children:l.map(t=>(0,B.jsx)(`td`,{children:String(e[t]??``)},t))},t))})]}),d.length>r?(0,B.jsxs)(`small`,{children:[`Showing `,r,` of `,d.length,` rows`]}):null]})}function QZt({node:e,document:t,staticArtifacts:n}){let r=e.body?[]:e.children??[];return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-callout agent-md-${e.calloutType}`,children:[(0,B.jsx)(`strong`,{children:e.title??e.calloutType}),e.body?(0,B.jsx)(eo,{children:e.body}):null,r.map((e,r)=>(0,B.jsx)(GZt,{node:e,document:t,staticArtifacts:n},r))]})}function $Zt({node:e,document:t,staticArtifacts:n}){let[r,i]=(0,E.useState)(Math.max(0,e.tabs.findIndex(t=>t.label===e.default))),a=e.tabs[r];return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-tabs agent-md-tabs-${e.variant??`line`}`,children:[(0,B.jsx)(`div`,{children:e.tabs.map((e,t)=>(0,B.jsx)(`button`,{className:t===r?`active`:void 0,"aria-selected":t===r,onClick:()=>i(t),children:e.label},e.label))}),a?.children.map((e,r)=>(0,B.jsx)(GZt,{node:e,document:t,staticArtifacts:n},r))]})}function eQt({node:e}){let t=[...e.events??[]].sort((t,n)=>{let r=Date.parse(t.date)-Date.parse(n.date);return e.sort===`desc`?-r:r});return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-timeline agent-md-timeline-${e.layout??`vertical`}`,children:[(0,B.jsx)(`h3`,{children:`Timeline`}),t.map(e=>(0,B.jsxs)(`article`,{className:`agent-md-timeline-event`,children:[e.group?(0,B.jsx)(`small`,{className:`agent-md-timeline-group`,children:e.group}):null,(0,B.jsxs)(`p`,{children:[(0,B.jsx)(`strong`,{children:e.date}),` `,e.title]}),e.description?(0,B.jsx)(`p`,{className:`agent-md-timeline-description`,children:e.description}):null]},`${e.date}-${e.title}`))]})}function tQt({node:e,document:t,staticArtifacts:n}){let[r,i]=(0,E.useState)(),[a,o]=(0,E.useState)();return(0,E.useEffect)(()=>{let r=!1;async function a(){try{let a=e.source??_Qt(n,e.src)??(e.src&&mQt()?await gQt(t.sourcePath,e.src,`diagram source`):``);if(!a.trim())throw Error(`No diagram source available for ${e.title??e.diagramType}.`);let o=bQt(e,a),s=e.diagramType===`flowchart`?SQt(o,e.direction??`TB`):void 0;if(s){r||i(s);return}UZt.initialize({startOnLoad:!1,securityLevel:`loose`,theme:`default`});let l=AQt((await UZt.render(`agent-md-diagram-${xQt(o)}`,o)).svg);if(!l)throw Error(`Unable to safely render diagram SVG.`);r||i(l)}catch(e){r||o(e instanceof Error?e.message:`Unable to render diagram`)}}return a(),()=>{r=!0}},[t.sourcePath,e,n]),a?(0,B.jsx)(Z9,{message:a,raw:e.source??e.src,suggestion:`Fix the diagram source or open the report in the local viewer if it references a local file.`}):(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e.title??`Diagram`}),r?(0,B.jsx)(`div`,{dangerouslySetInnerHTML:{__html:r}}):(0,B.jsx)(`p`,{children:`Rendering diagram...`})]})}function nQt({node:e,document:t,staticArtifacts:n}){let r=e.mode??`preview`,i=n?.[e.src],a=hQt(t.sourcePath,e.src),o=vQt(e.src),s=i?.kind===`data`?i.dataUrl:a,l=!!(i||a)&&r!==`link`;return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-embed`,children:[(0,B.jsxs)(`div`,{className:`agent-md-embed-header`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{children:e.title??e.src}),(0,B.jsx)(`small`,{children:e.src})]}),s?(0,B.jsx)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,children:r===`link`?`Open artifact`:`Open`}):null]}),e.caption?(0,B.jsx)(`p`,{className:`agent-md-embed-caption`,children:e.caption}):null,l?(0,B.jsx)(rQt,{node:e,url:a,artifact:i,kind:o}):(0,B.jsx)(aQt,{mode:r,hasUrl:!!s,kind:o})]})}function rQt({node:e,url:t,artifact:n,kind:r}){return r===`image`&&n?.kind===`data`?(0,B.jsx)(`img`,{className:`agent-md-embed-image`,src:n.dataUrl,alt:e.title??e.src,style:{maxHeight:e.height,maxWidth:e.width}}):r===`image`&&t?(0,B.jsx)(`img`,{className:`agent-md-embed-image`,src:t,alt:e.title??e.src,style:{maxHeight:e.height,maxWidth:e.width}}):r===`markdown`||r===`text`||r===`json`||r===`csv`?(0,B.jsx)(iQt,{node:e,url:t,artifact:n,kind:r}):r===`video`&&n?.kind===`data`?(0,B.jsx)(`video`,{className:`agent-md-embed-media`,src:n.dataUrl,controls:!0,style:{maxHeight:e.height,maxWidth:e.width}}):r===`video`&&t?(0,B.jsx)(`video`,{className:`agent-md-embed-media`,src:t,controls:!0,style:{maxHeight:e.height,maxWidth:e.width}}):(0,B.jsx)(aQt,{mode:e.mode??`preview`,hasUrl:!0,kind:r})}function iQt({node:e,url:t,artifact:n,kind:r}){let[i,a]=(0,E.useState)(),[o,s]=(0,E.useState)();return(0,E.useEffect)(()=>{let e=!1;return n?.kind===`text`?(a(r===`json`?yQt(n.content):n.content),()=>{e=!0}):t?(fetch(t).then(async e=>{if(!e.ok)throw Error(`Unable to load artifact: ${e.status}`);return e.text()}).then(t=>{e||a(r===`json`?yQt(t):t)}).catch(t=>{e||s(t instanceof Error?t.message:`Unable to load artifact`)}),()=>{e=!0}):(s(`No artifact URL is available.`),()=>{e=!0})},[n,r,t]),o?(0,B.jsx)(Z9,{message:o,raw:e.src,suggestion:`Open this report from the local viewer and confirm the artifact exists inside the project.`}):i==null?(0,B.jsx)(`p`,{className:`agent-md-embed-loading`,children:`Loading artifact...`}):r===`markdown`&&(e.mode??`preview`)===`preview`?(0,B.jsx)(`div`,{className:`agent-md-embed-markdown`,children:(0,B.jsx)(eo,{children:i})}):(0,B.jsx)(`pre`,{className:`agent-md-embed-text`,children:i})}function aQt({mode:e,hasUrl:t,kind:n}){return t?e===`link`?null:(0,B.jsx)(`p`,{className:`agent-md-embed-caption`,children:n===`html`?`HTML embeds are opened as links and are not executed inline.`:`This artifact type opens as a link.`}):(0,B.jsx)(`p`,{className:`agent-md-embed-caption`,children:`Preview this artifact from the local browser viewer to load project files safely.`})}function oQt({node:e,dataSources:t}){let n=t[e.data],r=e.height??360;if(!n)return(0,B.jsx)(Z9,{message:`No data available for ${e.data}`,raw:`[Map: ${e.title??e.data}]`,suggestion:`Add the referenced map data source or update the map's data field.`});if(n.object&&TQt(n.object))return(0,B.jsx)(sQt,{title:e.title,geojson:n.object,height:r});let i=n.rows??[];if(!e.lat||!e.lon||i.length===0)return(0,B.jsx)(Z9,{message:`Map requires row data plus lat/lon fields.`,raw:e.title??e.data,suggestion:`Provide lat and lon fields that point to numeric coordinate columns.`});let a=i.map(t=>({row:t,lat:Number(t[e.lat]),lon:Number(t[e.lon])})).filter(e=>Number.isFinite(e.lat)&&Number.isFinite(e.lon));if(a.length===0)return(0,B.jsx)(Z9,{message:`Map has no valid numeric coordinates.`,raw:e.title??e.data,suggestion:`Fix the coordinate columns so at least one row has valid numeric latitude and longitude values.`});let o=a.map(e=>e.lat),s=a.map(e=>e.lon),l=EQt({minLat:Math.min(...o),maxLat:Math.max(...o),minLon:Math.min(...s),maxLon:Math.max(...s)});return(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e.title??`Map`}),(0,B.jsxs)(`svg`,{viewBox:`0 0 1000 520`,width:`100%`,height:r,role:`img`,"aria-label":e.title??`Map`,children:[(0,B.jsx)(`rect`,{x:`0`,y:`0`,width:`1000`,height:`520`,rx:`18`,fill:`#f8fafc`,stroke:`#dbeafe`}),(0,B.jsx)(cQt,{}),a.map((t,n)=>{let{x:r,y:i}=DQt(t.lat,t.lon,l),a=e.label?String(t.row[e.label]??``):``,o=e.value?Number(t.row[e.value]):0,s=o>0?Math.max(7,Math.min(24,Math.sqrt(o)/45)):10;return(0,B.jsxs)(`g`,{children:[(0,B.jsx)(`circle`,{cx:r,cy:i,r:s,fill:`#2563eb`,opacity:`0.82`,stroke:`#1e3a8a`,strokeWidth:`2`}),(0,B.jsx)(`text`,{x:r+s+6,y:i+4,fontSize:`24`,fill:`#0f172a`,children:a})]},n)})]})]})}function sQt({title:e,geojson:t,height:n}){let r=OQt(t);if(r.length===0)return(0,B.jsx)(Z9,{message:`GeoJSON has no drawable coordinates.`,raw:e??`GeoJSON map`,suggestion:`Check the GeoJSON geometry and use a FeatureCollection with drawable coordinates.`});let i=EQt({minLat:Math.min(...r.map(e=>e[1])),maxLat:Math.max(...r.map(e=>e[1])),minLon:Math.min(...r.map(e=>e[0])),maxLon:Math.max(...r.map(e=>e[0]))});return(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e??`GeoJSON map`}),(0,B.jsxs)(`svg`,{viewBox:`0 0 1000 520`,width:`100%`,height:n,role:`img`,"aria-label":e??`GeoJSON map`,children:[(0,B.jsx)(`rect`,{x:`0`,y:`0`,width:`1000`,height:`520`,rx:`18`,fill:`#f8fafc`,stroke:`#dbeafe`}),(0,B.jsx)(cQt,{}),t.features.map((e,t)=>(0,B.jsx)(`path`,{d:kQt(e,i),fill:`#93c5fd`,opacity:`0.55`,stroke:`#1d4ed8`,strokeWidth:`3`},t))]})]})}function cQt(){return(0,B.jsxs)(`g`,{opacity:`0.35`,children:[[1,2,3,4].map(e=>(0,B.jsx)(`line`,{x1:e*200,x2:e*200,y1:`30`,y2:`490`,stroke:`#bfdbfe`},`v-${e}`)),[1,2,3,4].map(e=>(0,B.jsx)(`line`,{y1:e*100,y2:e*100,x1:`30`,x2:`970`,stroke:`#bfdbfe`},`h-${e}`))]})}function lQt({node:e}){return(0,B.jsxs)(`form`,{className:`agent-md-card agent-md-form`,onSubmit:e=>e.preventDefault(),children:[(0,B.jsx)(`h3`,{children:e.title??`Form`}),e.description?(0,B.jsx)(`p`,{children:e.description}):null,(0,B.jsx)(`div`,{className:`agent-md-form-fields`,children:e.fields.map(e=>(0,B.jsxs)(`label`,{className:`agent-md-form-field agent-md-form-field-${e.fieldType}`,children:[(0,B.jsx)(`span`,{children:e.label??e.name}),uQt(e)]},e.name))}),e.submitLabel?(0,B.jsx)(`button`,{type:`submit`,className:`agent-md-form-submit`,children:e.submitLabel}):null]})}function uQt(e){if(e.fieldType===`select`)return(0,B.jsx)(`select`,{name:e.name,defaultValue:String(e.default??``),children:e.options?.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))});if(e.fieldType===`checkbox`)return(0,B.jsx)(`input`,{name:e.name,type:`checkbox`,defaultChecked:!!e.default});let t=e.fieldType===`date`?`date`:e.fieldType===`number`?`number`:`text`;return(0,B.jsx)(`input`,{name:e.name,type:t,defaultValue:String(e.default??``),placeholder:e.placeholder,required:e.required,min:e.min,max:e.max,step:e.step})}function dQt(e){return`[Chart: ${e.chartType} chart of ${e.y??e.value??`value`} by ${e.x??e.label??`label`}]`}function fQt(e,t){return t===`currency`&&typeof e==`number`?new Intl.NumberFormat(void 0,{style:`currency`,currency:`USD`}).format(e):String(e)}function pQt(e,t){return e.diagnostics.find(e=>e.line===t.line&&e.severity===`error`)??e.diagnostics.find(e=>e.line===t.line)}function mQt(){return typeof window<`u`&&window.location.protocol.startsWith(`http`)}function hQt(e,t){if(mQt())return`/artifact?file=${encodeURIComponent(e)}&src=${encodeURIComponent(t)}`}async function gQt(e,t,n=`artifact`){let r=await fetch(`/artifact?file=${encodeURIComponent(e)}&src=${encodeURIComponent(t)}`);if(!r.ok)throw Error(`Unable to load ${n}: ${r.status}`);return r.text()}function _Qt(e,t){if(!t)return;let n=e?.[t];return n?.kind===`text`?n.content:void 0}function vQt(e){let t=e.split(/[?#]/)[0]?.toLowerCase().split(`.`).pop()??``;return[`md`,`mmd`,`mermaid`,`txt`].includes(t)?t===`md`?`markdown`:`text`:[`csv`,`tsv`].includes(t)?`csv`:t===`json`?`json`:[`png`,`jpg`,`jpeg`,`gif`,`svg`].includes(t)?`image`:[`webm`,`mp4`].includes(t)?`video`:t===`pdf`?`pdf`:t===`html`?`html`:`unknown`}function yQt(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function bQt(e,t){return e.diagramType===`flowchart`&&!t.trim().startsWith(`flowchart`)&&!t.trim().startsWith(`graph`)?`flowchart ${e.direction??`TD`}
3404
+ </iframe>`,`putIntoIFrame`),wZt=V((e,t,n,r,i)=>{let a=e.append(`div`);a.attr(`id`,n),r&&a.attr(`style`,r);let o=a.append(`svg`).attr(`id`,t).attr(`width`,`100%`).attr(`xmlns`,aZt);return i&&o.attr(`xmlns:xlink`,i),o.append(`g`),e},`appendDivSvgG`);function TZt(e,t){return e.append(`iframe`).attr(`id`,t).attr(`style`,`width: 100%; height: 100%;`).attr(`sandbox`,``)}V(TZt,`sandboxedIframe`);var EZt=V((e,t,n,r)=>{e.getElementById(t)?.remove(),e.getElementById(n)?.remove(),e.getElementById(r)?.remove()},`removeExistingElements`),DZt=V(async function(e,t,n){q9();let r=gZt(t);t=r.code;let i=QE();H.debug(i),t.length>(i?.maxTextSize??tZt)&&(t=nZt);let a=`#${e}`,o=`i`+e,s=`#`+o,l=`d`+e,u=`#`+l,d=V(()=>{let e=fO(p?s:u).node();e&&`remove`in e&&e.remove()},`removeTempElements`),f=fO(document.body),p=i.securityLevel===rZt,m=i.securityLevel===iZt,h=i.fontFamily;n===void 0?(EZt(document,e,l,o),p?(f=fO(TZt(fO(document.body),o).nodes()[0].contentDocument.body),f.node().style.margin=`0`):f=fO(`body`),wZt(f,e,l)):(n&&(n.innerHTML=``),p?(f=fO(TZt(fO(n),o).nodes()[0].contentDocument.body),f.node().style.margin=`0`):f=fO(n),wZt(f,e,l,`font-family: ${h}`,oZt));let g,_;try{g=await GXt.fromText(t,{title:r.title})}catch(e){if(i.suppressErrorRendering)throw d(),e;g=await GXt.fromText(`error`),_=e}let v=f.select(u).node(),y=g.type,b=v.firstChild,x=b.firstChild,S=g.renderer.getClasses?.(t,g),C=xZt(i,y,S,a),w=document.createElement(`style`);w.innerHTML=C,b.insertBefore(w,x);try{await g.renderer.draw(t,e,`11.15.0`,g)}catch(n){throw i.suppressErrorRendering?d():cXt.draw(t,e,`11.15.0`),n}let T=f.select(`${u} svg`),E=g.db.getAccTitle?.(),D=g.db.getAccDescription?.();AZt(y,T,E,D),f.select(`[id="${e}"]`).selectAll(`foreignobject > *`).attr(`xmlns`,sZt);let O=f.select(u).node().innerHTML;if(H.debug(`config.arrowMarkerAbsolute`,i.arrowMarkerAbsolute),O=SZt(O,p,WE(i.arrowMarkerAbsolute)),p){let e=f.select(u+` svg`).node();O=CZt(O,e)}else m||(O=aS.sanitize(O,{ADD_TAGS:mZt,ADD_ATTR:hZt,HTML_INTEGRATION_POINTS:{foreignobject:!0}}));if(qXt(),_)throw _;return d(),{diagramType:y,svg:O,bindFunctions:g.db.bindFunctions}},`render`);function OZt(e={}){let t=jE({},e);t?.fontFamily&&!t.themeVariables?.fontFamily&&(t.themeVariables||={},t.themeVariables.fontFamily=t.fontFamily),Dje(t),t?.theme&&t.theme in IE?t.themeVariables=IE[t.theme].getThemeVariables(t.themeVariables):t&&(t.themeVariables=IE.default.getThemeVariables(t.themeVariables)),Gb((typeof t==`object`?Eje(t):XE()).logLevel),q9()}V(OZt,`initialize`);var kZt=V((e,t={})=>{let{code:n}=$Xt(e);return GXt.fromText(n,t)},`getDiagramFromText`);function AZt(e,t,n,r){UXt(t,e),WXt(t,n,r,t.attr(`id`))}V(AZt,`addA11yInfo`);var J9=Object.freeze({render:DZt,parse:_Zt,getDiagramFromText:kZt,initialize:OZt,getConfig:QE,setConfig:ZE,getSiteConfig:XE,updateSiteConfig:Oje,reset:V(()=>{eD()},`reset`),globalReset:V(()=>{eD(UE)},`globalReset`),defaultConfig:UE});Gb(QE().logLevel),eD(QE());var jZt=V((e,t,n)=>{H.warn(e),Mj(e)?(n&&n(e.str,e.hash),t.push({...e,message:e.str,error:e})):(n&&n(e),e instanceof Error&&t.push({str:e.message,message:e.message,hash:e.name,error:e}))},`handleError`),MZt=V(async function(e={querySelector:`.mermaid`}){try{await NZt(e)}catch(t){if(Mj(t)&&H.error(t.str),X9.parseError&&X9.parseError(t),!e.suppressErrors)throw H.error(`Use the suppressErrors option to suppress these errors`),t}},`run`),NZt=V(async function({postRenderCallback:e,querySelector:t,nodes:n}={querySelector:`.mermaid`}){let r=J9.getConfig();H.debug(`${e?``:`No `}Callback function found`);let i;if(n)i=n;else if(t)i=document.querySelectorAll(t);else throw Error(`Nodes and querySelector are both undefined`);H.debug(`Found ${i.length} diagrams`),r?.startOnLoad!==void 0&&(H.debug(`Start On Load: `+r?.startOnLoad),J9.updateSiteConfig({startOnLoad:r?.startOnLoad}));let a=new Gj.InitIDGenerator(r.deterministicIds,r.deterministicIDSeed),o,s=[];for(let t of Array.from(i)){if(H.info(`Rendering diagram: `+t.id),t.getAttribute(`data-processed`))continue;t.setAttribute(`data-processed`,`true`);let n=`mermaid-${a.next()}`;o=t.innerHTML,o=WHe(Gj.entityDecode(o)).trim().replace(/<br\s*\/?>/gi,`<br/>`);let r=Gj.detectInit(o);r&&H.debug(`Detected early reinit: `,r);try{let{svg:r,bindFunctions:i}=await HZt(n,o,t);t.innerHTML=r,e&&await e(n),i&&i(t)}catch(e){jZt(e,s,X9.parseError)}}if(s.length>0)throw s[0]},`runThrowsErrors`),PZt=V(function(e){J9.initialize(e)},`initialize`),FZt=V(async function(e,t,n){H.warn(`mermaid.init is deprecated. Please use run instead.`),e&&PZt(e);let r={postRenderCallback:n,querySelector:`.mermaid`};typeof t==`string`?r.querySelector=t:t&&(t instanceof HTMLElement?r.nodes=[t]:r.nodes=t),await MZt(r)},`init`),IZt=V(async(e,{lazyLoad:t=!0}={})=>{q9(),OE(...e),t===!1&&await VXt()},`registerExternalDiagrams`),LZt=V(function(){if(X9.startOnLoad){let{startOnLoad:e}=J9.getConfig();e&&X9.run().catch(e=>H.error(`Mermaid failed to initialize`,e))}},`contentLoaded`);typeof document<`u`&&window.addEventListener(`load`,LZt,!1);var RZt=V(function(e){X9.parseError=e},`setParseErrorHandler`),Y9=[],zZt=!1,BZt=V(async()=>{if(!zZt){for(zZt=!0;Y9.length>0;){let e=Y9.shift();if(e)try{await e()}catch(e){H.error(`Error executing queue`,e)}}zZt=!1}},`executeQueue`),VZt=V(async(e,t)=>new Promise((n,r)=>{let i=V(()=>new Promise((i,a)=>{J9.parse(e,t).then(e=>{i(e),n(e)},e=>{H.error(`Error parsing`,e),X9.parseError?.(e),a(e),r(e)})}),`performCall`);Y9.push(i),BZt().catch(r)}),`parse`),HZt=V((e,t,n)=>new Promise((r,i)=>{let a=V(()=>new Promise((a,o)=>{J9.render(e,t,n).then(e=>{a(e),r(e)},e=>{H.error(`Error parsing`,e),X9.parseError?.(e),o(e),i(e)})}),`performCall`);Y9.push(a),BZt().catch(i)}),`render`),X9={startOnLoad:!0,mermaidAPI:J9,parse:VZt,render:HZt,init:FZt,run:MZt,registerExternalDiagrams:IZt,registerLayoutLoaders:sJ,initialize:PZt,parseError:void 0,contentLoaded:LZt,setParseErrorHandler:RZt,detectType:DE,registerIconPacks:aN,getRegisteredDiagramsMetadata:V(()=>Object.keys(EE).map(e=>({id:e})),`getRegisteredDiagramsMetadata`)},UZt=X9;function WZt({document:e,staticArtifacts:t}){return(0,B.jsx)(`div`,{className:`agent-md-document`,children:e.nodes.map((n,r)=>(0,B.jsx)(GZt,{node:n,document:e,staticArtifacts:t},r))})}function GZt({node:e,document:t,staticArtifacts:n}){return e.type===`markdown`?(0,B.jsx)(eo,{children:e.value}):e.type===`error`?(0,B.jsx)(Z9,{message:e.message,raw:e.raw,diagnostic:hQt(t,e)}):e.type===`metric`?(0,B.jsx)(KZt,{node:e,dataSources:t.dataSources}):e.type===`chart`?(0,B.jsx)(qZt,{node:e,dataSources:t.dataSources}):e.type===`table`?(0,B.jsx)(ZZt,{node:e,dataSources:t.dataSources}):e.type===`callout`?(0,B.jsx)(eQt,{node:e,document:t,staticArtifacts:n}):e.type===`tabs`?(0,B.jsx)(tQt,{node:e,document:t,staticArtifacts:n}):e.type===`query`?(0,B.jsx)(QZt,{node:e,dataSources:t.dataSources}):e.type===`timeline`?(0,B.jsx)(nQt,{node:e}):e.type===`diagram`?(0,B.jsx)(rQt,{node:e,document:t,staticArtifacts:n}):e.type===`map`?(0,B.jsx)(cQt,{node:e,dataSources:t.dataSources}):e.type===`embed`?(0,B.jsx)(iQt,{node:e,document:t,staticArtifacts:n}):e.type===`form`?(0,B.jsx)(dQt,{node:e}):e.type===`component`?(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-component-placeholder`,children:[(0,B.jsxs)(`strong`,{children:[`Registered component: `,e.name]}),(0,B.jsx)(`p`,{children:`Custom rendering is disabled by the current security config, so this safe placeholder is expected.`})]}):null}function Z9({message:e,raw:t,diagnostic:n,suggestion:r}){let i=r??n?.suggestion??`Check this block's fields and data references, then run agent-md validate again.`;return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-error`,children:[(0,B.jsx)(`strong`,{children:e}),(0,B.jsx)(`p`,{children:i}),n?.line?(0,B.jsxs)(`small`,{children:[`Source line `,n.line]}):null,n?.field?(0,B.jsxs)(`small`,{children:[` Field: `,n.field]}):null,n?.example?(0,B.jsx)(`pre`,{children:n.example}):t?(0,B.jsx)(`pre`,{children:t}):null]})}function KZt({node:e,dataSources:t}){let n=(0,E.useMemo)(()=>{if(e.value!=null)return e.value;let n=e.data?t[e.data]?.rows??[]:[];if(!e.field)return``;let r=n.map(t=>Number(t[e.field])).filter(Number.isFinite);return e.aggregate===`count`?n.length:e.aggregate===`avg`?r.reduce((e,t)=>e+t,0)/Math.max(r.length,1):e.aggregate===`min`?Math.min(...r):e.aggregate===`max`?Math.max(...r):r.reduce((e,t)=>e+t,0)},[e,t]);return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-metric`,children:[(0,B.jsx)(`span`,{children:e.label}),(0,B.jsx)(`strong`,{children:mQt(n,e.format)}),e.delta?(0,B.jsx)(`small`,{children:e.delta}):null,e.description?(0,B.jsx)(`p`,{children:e.description}):null]})}function qZt({node:e,dataSources:t}){let n=t[e.data]?.rows??[],r=e.height??320;if(n.length===0)return(0,B.jsx)(Z9,{message:`No rows available for ${e.data}`,raw:`[Chart: ${e.chartType}]`,suggestion:`Confirm the chart's data source exists and contains rows before sharing this report.`});let i={data:n};return(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e.title??pQt(e)}),e.description?(0,B.jsx)(`p`,{children:e.description}):null,(0,B.jsx)(jre,{width:`100%`,height:r,children:JZt(e,i)})]})}function JZt(e,t){let n=Array.isArray(e.y)?e.y:e.y?[e.y]:[];return e.chartType===`bar`?(0,B.jsxs)(PDe,{...t,children:[(0,B.jsx)(Cb,{dataKey:e.x}),(0,B.jsx)(wb,{}),(0,B.jsx)(xy,{}),e.legend===!1?null:(0,B.jsx)(fm,{}),n.map((e,t)=>(0,B.jsx)(sTe,{dataKey:e,fill:Q9(t)},e))]}):e.chartType===`area`?(0,B.jsxs)(iOe,{...t,children:[(0,B.jsx)(Cb,{dataKey:e.x}),(0,B.jsx)(wb,{}),(0,B.jsx)(xy,{}),n.map((e,t)=>(0,B.jsx)(dwe,{dataKey:e,fill:Q9(t),stroke:Q9(t)},e))]}):e.chartType===`scatter`?(0,B.jsxs)(nOe,{children:[(0,B.jsx)(Cb,{dataKey:e.x}),(0,B.jsx)(wb,{dataKey:typeof e.y==`string`?e.y:void 0}),(0,B.jsx)(xy,{}),(0,B.jsx)(PTe,{data:t.data,fill:Q9(0)})]}):e.chartType===`pie`?(0,B.jsxs)(eOe,{children:[(0,B.jsx)(xy,{}),e.legend===!1?null:(0,B.jsx)(fm,{}),(0,B.jsx)(Jbe,{data:t.data,dataKey:YZt(e),nameKey:XZt(e),children:t.data.map((e,t)=>(0,B.jsx)(Sy,{fill:Q9(t)},`slice-${t}`))})]}):(0,B.jsxs)(MDe,{...t,children:[(0,B.jsx)(Cb,{dataKey:e.x}),(0,B.jsx)(wb,{}),(0,B.jsx)(xy,{}),e.legend===!1?null:(0,B.jsx)(fm,{}),n.map((e,t)=>(0,B.jsx)(jCe,{dataKey:e,stroke:Q9(t)},e))]})}function Q9(e){return`var(--agent-md-chart-${e+1}, var(--agent-md-chart-1, #2563eb))`}function YZt(e){return e.value??(typeof e.y==`string`?e.y:e.y?.[0])}function XZt(e){return e.label??e.x}function ZZt({node:e,dataSources:t}){return(0,B.jsx)($Zt,{title:e.title,rows:t[e.data]?.rows??[],columns:e.columns,pageSize:e.pageSize??25})}function QZt({node:e,dataSources:t}){let n=t[e.data],r=n?NQt(n.rows??[],e):[];return e.view===`json`?(0,B.jsx)(`pre`,{children:JSON.stringify(r,null,2)}):(0,B.jsx)($Zt,{title:`Query`,rows:r,columns:e.select,pageSize:25})}function $Zt({title:e,rows:t,columns:n,pageSize:r}){let[i,a]=(0,E.useState)(``),[o,s]=(0,E.useState)(),l=n?.length?n:Object.keys(t[0]??{}),u=t.filter(e=>JSON.stringify(e).toLowerCase().includes(i.toLowerCase())),d=o?[...u].sort((e,t)=>String(e[o]).localeCompare(String(t[o]))):u;return(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e??`Table`}),(0,B.jsx)(`input`,{placeholder:`Search`,value:i,onChange:e=>a(e.target.value)}),(0,B.jsxs)(`table`,{children:[(0,B.jsx)(`thead`,{children:(0,B.jsx)(`tr`,{children:l.map(e=>(0,B.jsx)(`th`,{onClick:()=>s(e),children:e},e))})}),(0,B.jsx)(`tbody`,{children:d.slice(0,r).map((e,t)=>(0,B.jsx)(`tr`,{children:l.map(t=>(0,B.jsx)(`td`,{children:String(e[t]??``)},t))},t))})]}),d.length>r?(0,B.jsxs)(`small`,{children:[`Showing `,r,` of `,d.length,` rows`]}):null]})}function eQt({node:e,document:t,staticArtifacts:n}){let r=e.body?[]:e.children??[];return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-callout agent-md-${e.calloutType}`,children:[(0,B.jsx)(`strong`,{children:e.title??e.calloutType}),e.body?(0,B.jsx)(eo,{children:e.body}):null,r.map((e,r)=>(0,B.jsx)(GZt,{node:e,document:t,staticArtifacts:n},r))]})}function tQt({node:e,document:t,staticArtifacts:n}){let[r,i]=(0,E.useState)(Math.max(0,e.tabs.findIndex(t=>t.label===e.default))),a=e.tabs[r];return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-tabs agent-md-tabs-${e.variant??`line`}`,children:[(0,B.jsx)(`div`,{children:e.tabs.map((e,t)=>(0,B.jsx)(`button`,{className:t===r?`active`:void 0,"aria-selected":t===r,onClick:()=>i(t),children:e.label},e.label))}),a?.children.map((e,r)=>(0,B.jsx)(GZt,{node:e,document:t,staticArtifacts:n},r))]})}function nQt({node:e}){let t=[...e.events??[]].sort((t,n)=>{let r=Date.parse(t.date)-Date.parse(n.date);return e.sort===`desc`?-r:r});return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-timeline agent-md-timeline-${e.layout??`vertical`}`,children:[(0,B.jsx)(`h3`,{children:`Timeline`}),t.map(e=>(0,B.jsxs)(`article`,{className:`agent-md-timeline-event`,children:[e.group?(0,B.jsx)(`small`,{className:`agent-md-timeline-group`,children:e.group}):null,(0,B.jsxs)(`p`,{children:[(0,B.jsx)(`strong`,{children:e.date}),` `,e.title]}),e.description?(0,B.jsx)(`p`,{className:`agent-md-timeline-description`,children:e.description}):null]},`${e.date}-${e.title}`))]})}function rQt({node:e,document:t,staticArtifacts:n}){let[r,i]=(0,E.useState)(),[a,o]=(0,E.useState)();return(0,E.useEffect)(()=>{let r=!1;async function a(){try{let a=e.source??yQt(n,e.src)??(e.src&&gQt()?await vQt(t.sourcePath,e.src,`diagram source`):``);if(!a.trim())throw Error(`No diagram source available for ${e.title??e.diagramType}.`);let o=SQt(e,a),s=e.diagramType===`flowchart`?wQt(o,e.direction??`TB`):void 0;if(s){r||i(s);return}UZt.initialize({startOnLoad:!1,securityLevel:`loose`,theme:`default`});let l=MQt((await UZt.render(`agent-md-diagram-${CQt(o)}`,o)).svg);if(!l)throw Error(`Unable to safely render diagram SVG.`);r||i(l)}catch(e){r||o(e instanceof Error?e.message:`Unable to render diagram`)}}return a(),()=>{r=!0}},[t.sourcePath,e,n]),a?(0,B.jsx)(Z9,{message:a,raw:e.source??e.src,suggestion:`Fix the diagram source or open the report in the local viewer if it references a local file.`}):(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e.title??`Diagram`}),r?(0,B.jsx)(`div`,{dangerouslySetInnerHTML:{__html:r}}):(0,B.jsx)(`p`,{children:`Rendering diagram...`})]})}function iQt({node:e,document:t,staticArtifacts:n}){let r=e.mode??`preview`,i=n?.[e.src],a=_Qt(t.sourcePath,e.src),o=bQt(e.src),s=i?.kind===`data`?i.dataUrl:a,l=!!(i||a)&&r!==`link`;return(0,B.jsxs)(`div`,{className:`agent-md-card agent-md-embed`,children:[(0,B.jsxs)(`div`,{className:`agent-md-embed-header`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{children:e.title??e.src}),(0,B.jsx)(`small`,{children:e.src})]}),s?(0,B.jsx)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,children:r===`link`?`Open artifact`:`Open`}):null]}),e.caption?(0,B.jsx)(`p`,{className:`agent-md-embed-caption`,children:e.caption}):null,l?(0,B.jsx)(aQt,{node:e,url:a,artifact:i,kind:o}):(0,B.jsx)(sQt,{mode:r,hasUrl:!!s,kind:o})]})}function aQt({node:e,url:t,artifact:n,kind:r}){return r===`image`&&n?.kind===`data`?(0,B.jsx)(`img`,{className:`agent-md-embed-image`,src:n.dataUrl,alt:e.title??e.src,style:{maxHeight:e.height,maxWidth:e.width}}):r===`image`&&t?(0,B.jsx)(`img`,{className:`agent-md-embed-image`,src:t,alt:e.title??e.src,style:{maxHeight:e.height,maxWidth:e.width}}):r===`markdown`||r===`text`||r===`json`||r===`csv`?(0,B.jsx)(oQt,{node:e,url:t,artifact:n,kind:r}):r===`video`&&n?.kind===`data`?(0,B.jsx)(`video`,{className:`agent-md-embed-media`,src:n.dataUrl,controls:!0,style:{maxHeight:e.height,maxWidth:e.width}}):r===`video`&&t?(0,B.jsx)(`video`,{className:`agent-md-embed-media`,src:t,controls:!0,style:{maxHeight:e.height,maxWidth:e.width}}):(0,B.jsx)(sQt,{mode:e.mode??`preview`,hasUrl:!0,kind:r})}function oQt({node:e,url:t,artifact:n,kind:r}){let[i,a]=(0,E.useState)(n?.kind===`text`?r===`json`?xQt(n.content):n.content:void 0),[o,s]=(0,E.useState)();return(0,E.useEffect)(()=>{let e=!1;return n?.kind===`text`?(a(r===`json`?xQt(n.content):n.content),()=>{e=!0}):t?(fetch(t).then(async e=>{if(!e.ok)throw Error(`Unable to load artifact: ${e.status}`);return e.text()}).then(t=>{e||a(r===`json`?xQt(t):t)}).catch(t=>{e||s(t instanceof Error?t.message:`Unable to load artifact`)}),()=>{e=!0}):(s(`No artifact URL is available.`),()=>{e=!0})},[n,r,t]),o?(0,B.jsx)(Z9,{message:o,raw:e.src,suggestion:`Open this report from the local viewer and confirm the artifact exists inside the project.`}):i==null?(0,B.jsx)(`p`,{className:`agent-md-embed-loading`,children:`Loading artifact...`}):r===`markdown`&&(e.mode??`preview`)===`preview`?(0,B.jsx)(`div`,{className:`agent-md-embed-markdown`,children:(0,B.jsx)(eo,{children:i})}):(0,B.jsx)(`pre`,{className:`agent-md-embed-text`,children:i})}function sQt({mode:e,hasUrl:t,kind:n}){return t?e===`link`?null:(0,B.jsx)(`p`,{className:`agent-md-embed-caption`,children:n===`html`?`HTML embeds are opened as links and are not executed inline.`:`This artifact type opens as a link.`}):(0,B.jsx)(`p`,{className:`agent-md-embed-caption`,children:`Preview this artifact from the local browser viewer to load project files safely.`})}function cQt({node:e,dataSources:t}){let n=t[e.data],r=e.height??360;if(!n)return(0,B.jsx)(Z9,{message:`No data available for ${e.data}`,raw:`[Map: ${e.title??e.data}]`,suggestion:`Add the referenced map data source or update the map's data field.`});if(n.object&&DQt(n.object))return(0,B.jsx)(lQt,{title:e.title,geojson:n.object,height:r});let i=n.rows??[];if(!e.lat||!e.lon||i.length===0)return(0,B.jsx)(Z9,{message:`Map requires row data plus lat/lon fields.`,raw:e.title??e.data,suggestion:`Provide lat and lon fields that point to numeric coordinate columns.`});let a=i.map(t=>({row:t,lat:Number(t[e.lat]),lon:Number(t[e.lon])})).filter(e=>Number.isFinite(e.lat)&&Number.isFinite(e.lon));if(a.length===0)return(0,B.jsx)(Z9,{message:`Map has no valid numeric coordinates.`,raw:e.title??e.data,suggestion:`Fix the coordinate columns so at least one row has valid numeric latitude and longitude values.`});let o=a.map(e=>e.lat),s=a.map(e=>e.lon),l=OQt({minLat:Math.min(...o),maxLat:Math.max(...o),minLon:Math.min(...s),maxLon:Math.max(...s)});return(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e.title??`Map`}),(0,B.jsxs)(`svg`,{viewBox:`0 0 1000 520`,width:`100%`,height:r,role:`img`,"aria-label":e.title??`Map`,children:[(0,B.jsx)(`rect`,{x:`0`,y:`0`,width:`1000`,height:`520`,rx:`18`,fill:`#f8fafc`,stroke:`#dbeafe`}),(0,B.jsx)(uQt,{}),a.map((t,n)=>{let{x:r,y:i}=kQt(t.lat,t.lon,l),a=e.label?String(t.row[e.label]??``):``,o=e.value?Number(t.row[e.value]):0,s=o>0?Math.max(7,Math.min(24,Math.sqrt(o)/45)):10;return(0,B.jsxs)(`g`,{children:[(0,B.jsx)(`circle`,{cx:r,cy:i,r:s,fill:`#2563eb`,opacity:`0.82`,stroke:`#1e3a8a`,strokeWidth:`2`}),(0,B.jsx)(`text`,{x:r+s+6,y:i+4,fontSize:`24`,fill:`#0f172a`,children:a})]},n)})]})]})}function lQt({title:e,geojson:t,height:n}){let r=AQt(t);if(r.length===0)return(0,B.jsx)(Z9,{message:`GeoJSON has no drawable coordinates.`,raw:e??`GeoJSON map`,suggestion:`Check the GeoJSON geometry and use a FeatureCollection with drawable coordinates.`});let i=OQt({minLat:Math.min(...r.map(e=>e[1])),maxLat:Math.max(...r.map(e=>e[1])),minLon:Math.min(...r.map(e=>e[0])),maxLon:Math.max(...r.map(e=>e[0]))});return(0,B.jsxs)(`div`,{className:`agent-md-card`,children:[(0,B.jsx)(`h3`,{children:e??`GeoJSON map`}),(0,B.jsxs)(`svg`,{viewBox:`0 0 1000 520`,width:`100%`,height:n,role:`img`,"aria-label":e??`GeoJSON map`,children:[(0,B.jsx)(`rect`,{x:`0`,y:`0`,width:`1000`,height:`520`,rx:`18`,fill:`#f8fafc`,stroke:`#dbeafe`}),(0,B.jsx)(uQt,{}),t.features.map((e,t)=>(0,B.jsx)(`path`,{d:jQt(e,i),fill:`#93c5fd`,opacity:`0.55`,stroke:`#1d4ed8`,strokeWidth:`3`},t))]})]})}function uQt(){return(0,B.jsxs)(`g`,{opacity:`0.35`,children:[[1,2,3,4].map(e=>(0,B.jsx)(`line`,{x1:e*200,x2:e*200,y1:`30`,y2:`490`,stroke:`#bfdbfe`},`v-${e}`)),[1,2,3,4].map(e=>(0,B.jsx)(`line`,{y1:e*100,y2:e*100,x1:`30`,x2:`970`,stroke:`#bfdbfe`},`h-${e}`))]})}function dQt({node:e}){return(0,B.jsxs)(`form`,{className:`agent-md-card agent-md-form`,onSubmit:e=>e.preventDefault(),children:[(0,B.jsx)(`h3`,{children:e.title??`Form`}),e.description?(0,B.jsx)(`p`,{children:e.description}):null,(0,B.jsx)(`div`,{className:`agent-md-form-fields`,children:e.fields.map(e=>(0,B.jsxs)(`label`,{className:`agent-md-form-field agent-md-form-field-${e.fieldType}`,children:[(0,B.jsx)(`span`,{children:e.label??e.name}),fQt(e)]},e.name))}),e.submitLabel?(0,B.jsx)(`button`,{type:`submit`,className:`agent-md-form-submit`,children:e.submitLabel}):null]})}function fQt(e){if(e.fieldType===`select`)return(0,B.jsx)(`select`,{name:e.name,defaultValue:String(e.default??``),children:e.options?.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))});if(e.fieldType===`checkbox`)return(0,B.jsx)(`input`,{name:e.name,type:`checkbox`,defaultChecked:!!e.default});let t=e.fieldType===`date`?`date`:e.fieldType===`number`?`number`:`text`;return(0,B.jsx)(`input`,{name:e.name,type:t,defaultValue:String(e.default??``),placeholder:e.placeholder,required:e.required,min:e.min,max:e.max,step:e.step})}function pQt(e){return`[Chart: ${e.chartType} chart of ${e.y??e.value??`value`} by ${e.x??e.label??`label`}]`}function mQt(e,t){return t===`currency`&&typeof e==`number`?new Intl.NumberFormat(void 0,{style:`currency`,currency:`USD`}).format(e):String(e)}function hQt(e,t){return e.diagnostics.find(e=>e.line===t.line&&e.severity===`error`)??e.diagnostics.find(e=>e.line===t.line)}function gQt(){return typeof window<`u`&&window.location.protocol.startsWith(`http`)}function _Qt(e,t){if(gQt())return`/artifact?file=${encodeURIComponent(e)}&src=${encodeURIComponent(t)}`}async function vQt(e,t,n=`artifact`){let r=await fetch(`/artifact?file=${encodeURIComponent(e)}&src=${encodeURIComponent(t)}`);if(!r.ok)throw Error(`Unable to load ${n}: ${r.status}`);return r.text()}function yQt(e,t){if(!t)return;let n=e?.[t];return n?.kind===`text`?n.content:void 0}function bQt(e){let t=e.split(/[?#]/)[0]?.toLowerCase().split(`.`).pop()??``;return[`md`,`mmd`,`mermaid`,`txt`].includes(t)?t===`md`?`markdown`:`text`:[`csv`,`tsv`].includes(t)?`csv`:t===`json`?`json`:[`png`,`jpg`,`jpeg`,`gif`,`svg`].includes(t)?`image`:[`webm`,`mp4`].includes(t)?`video`:t===`pdf`?`pdf`:t===`html`?`html`:`unknown`}function xQt(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function SQt(e,t){return e.diagramType===`flowchart`&&!t.trim().startsWith(`flowchart`)&&!t.trim().startsWith(`graph`)?`flowchart ${e.direction??`TD`}
3405
3405
  ${t}`:e.diagramType===`sequence`&&!t.trim().startsWith(`sequenceDiagram`)?`sequenceDiagram
3406
3406
  ${t}`:e.diagramType===`tree`&&!t.trim().startsWith(`graph`)?`graph TD
3407
- ${t}`:t}function xQt(e){let t=0;for(let n=0;n<e.length;n++)t=Math.imul(31,t)+e.charCodeAt(n)|0;return Math.abs(t).toString(36)}function SQt(e,t){let n=e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e&&!e.startsWith(`flowchart`)&&!e.startsWith(`graph`)),r=new Map,i=[],a=/([A-Za-z0-9_]+)(?:\["([^"]+)"\]|\[([^\]]+)\])?/g;for(let e of n){if(!e.includes(`-->`))return;let[t,n]=e.split(/-->/).map(e=>e.trim()),o=CQt(t,a),s=CQt(n,a);if(!o||!s)return;(!r.has(o.id)||o.label!==o.id)&&r.set(o.id,o.label),(!r.has(s.id)||s.label!==s.id)&&r.set(s.id,s.label),i.push([o.id,s.id])}if(r.size===0||i.length===0)return;let o=t===`LR`||t===`RL`,s=[...r.keys()].map(e=>`<div class="agent-md-simple-flow-node">${wQt(r.get(e)??e)}</div>`),l=`<div class="agent-md-simple-flow-arrow" aria-hidden="true">${o?`->`:`↓`}</div>`;return`<div class="agent-md-simple-flow agent-md-simple-flow-${o?`horizontal`:`vertical`}" role="img" aria-label="Flowchart">${s.map((e,t)=>`${t>0?l:``}${e}`).join(``)}</div>`}function CQt(e,t){t.lastIndex=0;let n=t.exec(e);if(n)return{id:n[1],label:n[2]??n[3]??n[1]}}function wQt(e){return e.replace(/[&<>"]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`})[e])}function TQt(e){return!!e&&typeof e==`object`&&e.type===`FeatureCollection`&&Array.isArray(e.features)}function EQt(e){let t=Math.max((e.maxLat-e.minLat)*.15,.5),n=Math.max((e.maxLon-e.minLon)*.15,.5);return{minLat:e.minLat-t,maxLat:e.maxLat+t,minLon:e.minLon-n,maxLon:e.maxLon+n}}function DQt(e,t,n){return{x:50+(t-n.minLon)/(n.maxLon-n.minLon||1)*900,y:490-(e-n.minLat)/(n.maxLat-n.minLat||1)*460}}function OQt(e){return e.features.flatMap(e=>$9(e.geometry?.coordinates))}function $9(e){return Array.isArray(e)?typeof e[0]==`number`&&typeof e[1]==`number`?[[e[0],e[1]]]:e.flatMap($9):[]}function kQt(e,t){return(e.geometry?.type===`Polygon`?e.geometry.coordinates:e.geometry?.type===`MultiPolygon`?e.geometry.coordinates.flat():[]).map(e=>$9(e).map(([e,n],r)=>{let{x:i,y:a}=DQt(n,e,t);return`${r===0?`M`:`L`}${i.toFixed(1)},${a.toFixed(1)}`}).join(` `)+` Z`).join(` `)}function AQt(e){if(typeof DOMParser>`u`||typeof XMLSerializer>`u`)return``;let t=new DOMParser().parseFromString(e,`image/svg+xml`);if(t.querySelector(`parsererror`))return``;let n=new Set([`script`,`iframe`,`object`,`embed`]),r=Array.from(t.querySelectorAll(`*`));for(let e of r){if(n.has(e.tagName.toLowerCase())){e.remove();continue}for(let t of Array.from(e.attributes)){let n=t.name.toLowerCase(),r=t.value.trim().toLowerCase();(n.startsWith(`on`)||(n===`href`||n===`xlink:href`)&&!r.startsWith(`#`)||(n===`style`||n===`class`)&&(r.includes(`javascript:`)||r.includes(`expression(`)))&&e.removeAttribute(t.name)}}return new XMLSerializer().serializeToString(t.documentElement)}function jQt(e,t){let n=e.filter(e=>Object.entries(t.where??{}).every(([t,n])=>{let r=e[t];return typeof n!=`object`||!n||Array.isArray(n)?r===n:!(`eq`in n&&r!==n.eq||`neq`in n&&r===n.neq||`gt`in n&&!(Number(r)>n.gt)||`gte`in n&&!(Number(r)>=n.gte)||`lt`in n&&!(Number(r)<n.lt)||`lte`in n&&!(Number(r)<=n.lte)||`contains`in n&&!String(r).includes(n.contains)||`in`in n&&!n.in.includes(r))}));return t.select?.length&&(n=n.map(e=>Object.fromEntries(t.select.map(t=>[t,e[t]])))),t.sort&&(n=[...n].sort((e,n)=>MQt(e[t.sort.by],n[t.sort.by],t.sort.direction??`asc`))),t.limit?n.slice(0,t.limit):n}function MQt(e,t,n){let r=e===t?0:e==null?-1:t==null||e>t?1:-1;return n===`asc`?r:-r}function NQt(){let e=window.__AGENT_MD_STATIC__;return e?(0,B.jsx)(FQt,{payload:e}):(0,B.jsx)(PQt,{})}function PQt(){let[e,t]=(0,E.useState)([]),[n,r]=(0,E.useState)(),[i,a]=(0,E.useState)(),[o,s]=(0,E.useState)(),[l,u]=(0,E.useState)(`rendered`),[d,f]=(0,E.useState)(!0),[p,m]=(0,E.useState)(!1),h=(0,E.useMemo)(()=>RQt(e),[e]);(0,E.useEffect)(()=>{g();let e=new WebSocket(`ws://${location.host}/ws`);return e.onmessage=()=>{g(),n&&_(n)},()=>e.close()},[n]);async function g(){f(!0);let e=await fetch(`/api/files`).then(e=>e.json());t(e.files),f(!1),!n&&e.files[0]&&_(e.files[0].path),n&&!e.files.some(e=>e.path===n)&&e.files[0]&&_(e.files[0].path)}async function _(e){r(e),u(`rendered`),m(!0),a(void 0),s(void 0);let[t,n]=await Promise.all([fetch(`/api/document?file=${encodeURIComponent(e)}`).then(e=>e.json()),fetch(`/api/source?file=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>e.source)]);a(t),s(n),m(!1)}return(0,B.jsx)(`div`,{className:`app-frame`,children:(0,B.jsxs)(`div`,{className:`browser-shell`,children:[(0,B.jsxs)(`aside`,{className:`file-sidebar`,"aria-label":`Project files`,children:[(0,B.jsx)(`div`,{className:`sidebar-strip`,children:d?`Loading files...`:`Files (${e.length})`}),(0,B.jsx)(`div`,{className:`file-tree`,children:d&&e.length===0?(0,B.jsx)(`p`,{className:`empty-state`,children:`Scanning Agent Markdown files...`}):h.map(e=>(0,B.jsxs)(`section`,{className:`folder-group`,children:[(0,B.jsxs)(`div`,{className:`folder-row`,children:[(0,B.jsx)(P,{"aria-hidden":!0,className:`tree-icon folder-icon`}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`folder-name`,children:e.folder}),(0,B.jsxs)(`div`,{className:`folder-count`,children:[e.files.length,` files`]})]})]}),(0,B.jsx)(`ul`,{children:e.files.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,title:e.path,className:e.path===n?`file-row active`:`file-row`,onClick:()=>_(e.path),children:[(0,B.jsx)(VQt,{path:e.path}),(0,B.jsx)(`span`,{children:zQt(e.path)}),(0,B.jsx)(HQt,{diagnostics:e.diagnostics})]})},e.path))})]},e.folder))})]}),(0,B.jsxs)(`main`,{className:`preview-pane`,children:[(0,B.jsxs)(`div`,{className:`preview-header`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{children:n??`Select a file`}),i?(0,B.jsx)(`p`,{children:BQt(i)}):(0,B.jsx)(`p`,{children:p?`Loading document...`:`Agent Markdown preview`})]}),(0,B.jsx)(`button`,{className:`mode-button`,type:`button`,onClick:()=>u(l===`rendered`?`source`:`rendered`),disabled:!i&&!o,children:l===`rendered`?`Source`:`Rendered`})]}),(0,B.jsx)(`div`,{className:`preview-body`,children:p?(0,B.jsx)(`p`,{className:`empty-state`,children:`Loading document...`}):l===`source`?(0,B.jsx)(`pre`,{children:o}):i?(0,B.jsx)(WZt,{document:i}):(0,B.jsx)(`p`,{className:`empty-state`,children:`Choose a file from the tree.`})}),i?.diagnostics.length?(0,B.jsx)(IQt,{diagnostics:i.diagnostics}):null]})]})})}function FQt({payload:e}){let[t,n]=(0,E.useState)(`rendered`),{document:r,source:i,artifacts:a}=e;return(0,B.jsx)(`div`,{className:`app-frame`,children:(0,B.jsx)(`div`,{className:`browser-shell static-shell`,children:(0,B.jsxs)(`main`,{className:`preview-pane`,children:[(0,B.jsxs)(`div`,{className:`preview-header`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{children:e.title??(typeof r.frontmatter?.title==`string`?r.frontmatter.title:`Agent Markdown`)}),(0,B.jsxs)(`p`,{children:[e.sourcePathLabel??r.sourcePath,` · `,BQt(r)]})]}),i==null?null:(0,B.jsx)(`button`,{className:`mode-button`,type:`button`,onClick:()=>n(t===`rendered`?`source`:`rendered`),children:t===`rendered`?`Source`:`Rendered`})]}),(0,B.jsx)(`div`,{className:`preview-body`,children:t===`source`?(0,B.jsx)(`pre`,{children:i}):(0,B.jsx)(WZt,{document:r,staticArtifacts:a})}),r.diagnostics.length?(0,B.jsx)(IQt,{diagnostics:r.diagnostics}):null]})})})}function IQt({diagnostics:e}){return(0,B.jsx)(`div`,{className:`diagnostics-panel`,"aria-label":`Diagnostics`,children:LQt(e).map(([e,t])=>(0,B.jsxs)(`section`,{children:[(0,B.jsxs)(`h4`,{children:[e,` (`,t.length,`)`]}),t.map((e,t)=>(0,B.jsxs)(`article`,{className:e.severity,children:[(0,B.jsx)(`strong`,{children:e.message}),(0,B.jsxs)(`p`,{children:[e.code,e.line?` · line ${e.line}`:``,e.blockType?` · ::${e.blockType}`:``,e.field?` · ${e.field}`:``]}),e.suggestion?(0,B.jsxs)(`p`,{children:[`Suggestion: `,e.suggestion]}):null,e.example?(0,B.jsx)(`pre`,{children:e.example}):null]},`${e.code}-${e.line??`file`}-${t}`))]},e))})}function LQt(e){return[`error`,`warning`,`info`].map(t=>[t,e.filter(e=>e.severity===t)]).filter(([,e])=>e.length>0)}function RQt(e){let t=new Map;for(let n of e){let e=n.path.includes(`/`)&&n.path.split(`/`)[0]||`Root`;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].map(([e,t])=>({folder:e,files:t}))}function zQt(e){return e.includes(`/`)?e.split(`/`).slice(1).join(`/`):e}function BQt(e){let t=e.diagnostics.filter(e=>e.severity===`error`).length,n=e.diagnostics.filter(e=>e.severity===`warning`).length,r=e.diagnostics.filter(e=>e.severity===`info`).length,i=[t?`${t} errors`:``,n?`${n} warnings`:``].filter(Boolean).join(` · `);return`${e.nodes.length} nodes${i?` · ${i}`:``}${r?` · ${r} info`:``}`}function VQt({path:e}){let t=e.split(`.`).pop(),n=`tree-icon file-icon`;return t===`json`||t===`geojson`?(0,B.jsx)(j,{"aria-hidden":!0,className:n}):t===`csv`||t===`tsv`?(0,B.jsx)(F,{"aria-hidden":!0,className:n}):t===`md`?(0,B.jsx)(N,{"aria-hidden":!0,className:n}):(0,B.jsx)(M,{"aria-hidden":!0,className:n})}function HQt({diagnostics:e}){return e.some(e=>e.severity===`error`)?(0,B.jsx)(`span`,{className:`status error-dot`,"aria-label":`Has errors`}):e.some(e=>e.severity===`warning`)?(0,B.jsx)(`span`,{className:`status warning-dot`,"aria-label":`Has warnings`}):(0,B.jsx)(`span`,{className:`status ok-dot`,"aria-label":`Valid`})}typeof document<`u`&&(0,EYt.createRoot)(document.getElementById(`root`)).render((0,B.jsx)(NQt,{}));
3407
+ ${t}`:t}function CQt(e){let t=0;for(let n=0;n<e.length;n++)t=Math.imul(31,t)+e.charCodeAt(n)|0;return Math.abs(t).toString(36)}function wQt(e,t){let n=e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e&&!e.startsWith(`flowchart`)&&!e.startsWith(`graph`)),r=new Map,i=[],a=/([A-Za-z0-9_]+)(?:\["([^"]+)"\]|\[([^\]]+)\])?/g;for(let e of n){if(!e.includes(`-->`))return;let[t,n]=e.split(/-->/).map(e=>e.trim()),o=TQt(t,a),s=TQt(n,a);if(!o||!s)return;(!r.has(o.id)||o.label!==o.id)&&r.set(o.id,o.label),(!r.has(s.id)||s.label!==s.id)&&r.set(s.id,s.label),i.push([o.id,s.id])}if(r.size===0||i.length===0)return;let o=t===`LR`||t===`RL`,s=[...r.keys()].map(e=>`<div class="agent-md-simple-flow-node">${EQt(r.get(e)??e)}</div>`),l=`<div class="agent-md-simple-flow-arrow" aria-hidden="true">${o?`->`:`↓`}</div>`;return`<div class="agent-md-simple-flow agent-md-simple-flow-${o?`horizontal`:`vertical`}" role="img" aria-label="Flowchart">${s.map((e,t)=>`${t>0?l:``}${e}`).join(``)}</div>`}function TQt(e,t){t.lastIndex=0;let n=t.exec(e);if(n)return{id:n[1],label:n[2]??n[3]??n[1]}}function EQt(e){return e.replace(/[&<>"]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`})[e])}function DQt(e){return!!e&&typeof e==`object`&&e.type===`FeatureCollection`&&Array.isArray(e.features)}function OQt(e){let t=Math.max((e.maxLat-e.minLat)*.15,.5),n=Math.max((e.maxLon-e.minLon)*.15,.5);return{minLat:e.minLat-t,maxLat:e.maxLat+t,minLon:e.minLon-n,maxLon:e.maxLon+n}}function kQt(e,t,n){return{x:50+(t-n.minLon)/(n.maxLon-n.minLon||1)*900,y:490-(e-n.minLat)/(n.maxLat-n.minLat||1)*460}}function AQt(e){return e.features.flatMap(e=>$9(e.geometry?.coordinates))}function $9(e){return Array.isArray(e)?typeof e[0]==`number`&&typeof e[1]==`number`?[[e[0],e[1]]]:e.flatMap($9):[]}function jQt(e,t){return(e.geometry?.type===`Polygon`?e.geometry.coordinates:e.geometry?.type===`MultiPolygon`?e.geometry.coordinates.flat():[]).map(e=>$9(e).map(([e,n],r)=>{let{x:i,y:a}=kQt(n,e,t);return`${r===0?`M`:`L`}${i.toFixed(1)},${a.toFixed(1)}`}).join(` `)+` Z`).join(` `)}function MQt(e){if(typeof DOMParser>`u`||typeof XMLSerializer>`u`)return``;let t=new DOMParser().parseFromString(e,`image/svg+xml`);if(t.querySelector(`parsererror`))return``;let n=new Set([`script`,`iframe`,`object`,`embed`]),r=Array.from(t.querySelectorAll(`*`));for(let e of r){if(n.has(e.tagName.toLowerCase())){e.remove();continue}for(let t of Array.from(e.attributes)){let n=t.name.toLowerCase(),r=t.value.trim().toLowerCase();(n.startsWith(`on`)||(n===`href`||n===`xlink:href`)&&!r.startsWith(`#`)||(n===`style`||n===`class`)&&(r.includes(`javascript:`)||r.includes(`expression(`)))&&e.removeAttribute(t.name)}}return new XMLSerializer().serializeToString(t.documentElement)}function NQt(e,t){let n=e.filter(e=>Object.entries(t.where??{}).every(([t,n])=>{let r=e[t];return typeof n!=`object`||!n||Array.isArray(n)?r===n:!(`eq`in n&&r!==n.eq||`neq`in n&&r===n.neq||`gt`in n&&!(Number(r)>n.gt)||`gte`in n&&!(Number(r)>=n.gte)||`lt`in n&&!(Number(r)<n.lt)||`lte`in n&&!(Number(r)<=n.lte)||`contains`in n&&!String(r).includes(n.contains)||`in`in n&&!n.in.includes(r))}));return t.select?.length&&(n=n.map(e=>Object.fromEntries(t.select.map(t=>[t,e[t]])))),t.sort&&(n=[...n].sort((e,n)=>PQt(e[t.sort.by],n[t.sort.by],t.sort.direction??`asc`))),t.limit?n.slice(0,t.limit):n}function PQt(e,t,n){let r=e===t?0:e==null?-1:t==null||e>t?1:-1;return n===`asc`?r:-r}function FQt(){let e=window.__AGENT_MD_STATIC__;return e?(0,B.jsx)(LQt,{payload:e}):(0,B.jsx)(IQt,{})}function IQt(){let[e,t]=(0,E.useState)([]),[n,r]=(0,E.useState)(),[i,a]=(0,E.useState)(),[o,s]=(0,E.useState)(),[l,u]=(0,E.useState)(`rendered`),[d,f]=(0,E.useState)(!0),[p,m]=(0,E.useState)(!1),h=(0,E.useMemo)(()=>BQt(e),[e]);(0,E.useEffect)(()=>{g();let e=new WebSocket(`ws://${location.host}/ws`);return e.onmessage=()=>{g(),n&&_(n)},()=>e.close()},[n]);async function g(){f(!0);let e=await fetch(`/api/files`).then(e=>e.json());t(e.files),f(!1),!n&&e.files[0]&&_(e.files[0].path),n&&!e.files.some(e=>e.path===n)&&e.files[0]&&_(e.files[0].path)}async function _(e){r(e),u(`rendered`),m(!0),a(void 0),s(void 0);let[t,n]=await Promise.all([fetch(`/api/document?file=${encodeURIComponent(e)}`).then(e=>e.json()),fetch(`/api/source?file=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>e.source)]);a(t),s(n),m(!1)}return(0,B.jsx)(`div`,{className:`app-frame`,children:(0,B.jsxs)(`div`,{className:`browser-shell`,children:[(0,B.jsxs)(`aside`,{className:`file-sidebar`,"aria-label":`Project files`,children:[(0,B.jsx)(`div`,{className:`sidebar-strip`,children:d?`Loading files...`:`Files (${e.length})`}),(0,B.jsx)(`div`,{className:`file-tree`,children:d&&e.length===0?(0,B.jsx)(`p`,{className:`empty-state`,children:`Scanning Agent Markdown files...`}):h.map(e=>(0,B.jsxs)(`section`,{className:`folder-group`,children:[(0,B.jsxs)(`div`,{className:`folder-row`,children:[(0,B.jsx)(P,{"aria-hidden":!0,className:`tree-icon folder-icon`}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`folder-name`,children:e.folder}),(0,B.jsxs)(`div`,{className:`folder-count`,children:[e.files.length,` files`]})]})]}),(0,B.jsx)(`ul`,{children:e.files.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,title:e.path,className:e.path===n?`file-row active`:`file-row`,onClick:()=>_(e.path),children:[(0,B.jsx)(UQt,{path:e.path}),(0,B.jsx)(`span`,{children:VQt(e.path)}),(0,B.jsx)(WQt,{diagnostics:e.diagnostics})]})},e.path))})]},e.folder))})]}),(0,B.jsxs)(`main`,{className:`preview-pane`,children:[(0,B.jsxs)(`div`,{className:`preview-header`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{children:n??`Select a file`}),i?(0,B.jsx)(`p`,{children:HQt(i)}):(0,B.jsx)(`p`,{children:p?`Loading document...`:`Agent Markdown preview`})]}),(0,B.jsx)(`button`,{className:`mode-button`,type:`button`,onClick:()=>u(l===`rendered`?`source`:`rendered`),disabled:!i&&!o,children:l===`rendered`?`Source`:`Rendered`})]}),(0,B.jsx)(`div`,{className:`preview-body`,children:p?(0,B.jsx)(`p`,{className:`empty-state`,children:`Loading document...`}):l===`source`?(0,B.jsx)(`pre`,{children:o}):i?(0,B.jsx)(WZt,{document:i}):(0,B.jsx)(`p`,{className:`empty-state`,children:`Choose a file from the tree.`})}),i?.diagnostics.length?(0,B.jsx)(RQt,{diagnostics:i.diagnostics}):null]})]})})}function LQt({payload:e}){let[t,n]=(0,E.useState)(`rendered`),{document:r,source:i,artifacts:a}=e;return(0,B.jsx)(`div`,{className:`app-frame`,children:(0,B.jsx)(`div`,{className:`browser-shell static-shell`,children:(0,B.jsxs)(`main`,{className:`preview-pane`,children:[(0,B.jsxs)(`div`,{className:`preview-header`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{children:e.title??(typeof r.frontmatter?.title==`string`?r.frontmatter.title:`Agent Markdown`)}),(0,B.jsxs)(`p`,{children:[e.sourcePathLabel??r.sourcePath,` · `,HQt(r)]})]}),i==null?null:(0,B.jsx)(`button`,{className:`mode-button`,type:`button`,onClick:()=>n(t===`rendered`?`source`:`rendered`),children:t===`rendered`?`Source`:`Rendered`})]}),(0,B.jsx)(`div`,{className:`preview-body`,children:t===`source`?(0,B.jsx)(`pre`,{children:i}):(0,B.jsx)(WZt,{document:r,staticArtifacts:a})}),r.diagnostics.length?(0,B.jsx)(RQt,{diagnostics:r.diagnostics}):null]})})})}function RQt({diagnostics:e}){return(0,B.jsx)(`div`,{className:`diagnostics-panel`,"aria-label":`Diagnostics`,children:zQt(e).map(([e,t])=>(0,B.jsxs)(`section`,{children:[(0,B.jsxs)(`h4`,{children:[e,` (`,t.length,`)`]}),t.map((e,t)=>(0,B.jsxs)(`article`,{className:e.severity,children:[(0,B.jsx)(`strong`,{children:e.message}),(0,B.jsxs)(`p`,{children:[e.code,e.line?` · line ${e.line}`:``,e.blockType?` · ::${e.blockType}`:``,e.field?` · ${e.field}`:``]}),e.suggestion?(0,B.jsxs)(`p`,{children:[`Suggestion: `,e.suggestion]}):null,e.example?(0,B.jsx)(`pre`,{children:e.example}):null]},`${e.code}-${e.line??`file`}-${t}`))]},e))})}function zQt(e){return[`error`,`warning`,`info`].map(t=>[t,e.filter(e=>e.severity===t)]).filter(([,e])=>e.length>0)}function BQt(e){let t=new Map;for(let n of e){let e=n.path.includes(`/`)&&n.path.split(`/`)[0]||`Root`;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].map(([e,t])=>({folder:e,files:t}))}function VQt(e){return e.includes(`/`)?e.split(`/`).slice(1).join(`/`):e}function HQt(e){let t=e.diagnostics.filter(e=>e.severity===`error`).length,n=e.diagnostics.filter(e=>e.severity===`warning`).length,r=e.diagnostics.filter(e=>e.severity===`info`).length,i=[t?`${t} errors`:``,n?`${n} warnings`:``].filter(Boolean).join(` · `);return`${e.nodes.length} nodes${i?` · ${i}`:``}${r?` · ${r} info`:``}`}function UQt({path:e}){let t=e.split(`.`).pop(),n=`tree-icon file-icon`;return t===`json`||t===`geojson`?(0,B.jsx)(j,{"aria-hidden":!0,className:n}):t===`csv`||t===`tsv`?(0,B.jsx)(F,{"aria-hidden":!0,className:n}):t===`md`?(0,B.jsx)(N,{"aria-hidden":!0,className:n}):(0,B.jsx)(M,{"aria-hidden":!0,className:n})}function WQt({diagnostics:e}){return e.some(e=>e.severity===`error`)?(0,B.jsx)(`span`,{className:`status error-dot`,"aria-label":`Has errors`}):e.some(e=>e.severity===`warning`)?(0,B.jsx)(`span`,{className:`status warning-dot`,"aria-label":`Has warnings`}):(0,B.jsx)(`span`,{className:`status ok-dot`,"aria-label":`Valid`})}typeof document<`u`&&(0,EYt.createRoot)(document.getElementById(`root`)).render((0,B.jsx)(FQt,{}));
@@ -1,4 +1,4 @@
1
1
  <!doctype html>
2
- <html><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Agent Markdown Viewer</title> <script type="module" crossorigin src="/assets/index-LKKPT-gN.js"></script>
2
+ <html><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Agent Markdown Viewer</title> <script type="module" crossorigin src="/assets/index-FYSpjwTy.js"></script>
3
3
  <link rel="stylesheet" crossorigin href="/assets/index-CtGGcFUm.css">
4
4
  </head><body><div id="root"></div></body></html>