archbyte 0.2.9 → 0.3.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/dist/agents/index.d.ts +0 -1
- package/dist/agents/index.js +0 -1
- package/dist/agents/pipeline/agents/component-identifier.js +67 -8
- package/dist/agents/pipeline/agents/connection-mapper.js +33 -8
- package/dist/agents/pipeline/agents/flow-detector.js +61 -8
- package/dist/agents/pipeline/agents/service-describer.js +36 -8
- package/dist/agents/pipeline/agents/validator.js +38 -9
- package/dist/agents/pipeline/index.d.ts +1 -0
- package/dist/agents/pipeline/index.js +123 -7
- package/dist/agents/pipeline/types.d.ts +11 -0
- package/dist/agents/providers/openai.js +6 -6
- package/dist/agents/runtime/types.d.ts +1 -1
- package/dist/agents/runtime/types.js +2 -7
- package/dist/cli/analyze.js +73 -29
- package/dist/cli/auth.js +2 -2
- package/dist/cli/config.js +1 -1
- package/dist/cli/incremental.d.ts +21 -0
- package/dist/cli/incremental.js +117 -1
- package/dist/cli/serve.js +89 -13
- package/dist/cli/setup.js +49 -27
- package/dist/cli/yaml-io.d.ts +2 -0
- package/package.json +1 -1
- package/ui/dist/assets/{index-pYTLuCyK.js → index-Bdr9FnaA.js} +1 -1
- package/ui/dist/index.html +1 -1
- package/dist/agents/providers/ollama.d.ts +0 -9
- package/dist/agents/providers/ollama.js +0 -162
package/dist/cli/setup.js
CHANGED
|
@@ -10,26 +10,27 @@ import { CONFIG_DIR, CONFIG_PATH } from "./constants.js";
|
|
|
10
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
11
|
const __dirname = path.dirname(__filename);
|
|
12
12
|
const PROVIDERS = [
|
|
13
|
-
{ name: "anthropic", label: "Anthropic", hint: "Claude
|
|
14
|
-
{ name: "openai", label: "OpenAI", hint: "GPT-5.2 /
|
|
15
|
-
{ name: "google", label: "Google", hint: "Gemini
|
|
13
|
+
{ name: "anthropic", label: "Anthropic", hint: "Claude Opus 4.6 / Sonnet 4.5" },
|
|
14
|
+
{ name: "openai", label: "OpenAI", hint: "GPT-5.2 / GPT-5 mini" },
|
|
15
|
+
{ name: "google", label: "Google", hint: "Gemini 2.5 Pro / Flash" },
|
|
16
16
|
];
|
|
17
17
|
const PROVIDER_MODELS = {
|
|
18
18
|
anthropic: [
|
|
19
|
-
{ id: "", label: "Default (recommended)", hint: "
|
|
20
|
-
{ id: "claude-haiku-4-5-20251001", label: "Claude Haiku 4.5", hint: "Fastest, cheapest" },
|
|
21
|
-
{ id: "claude-sonnet-4-5-20250929", label: "Claude Sonnet 4.5", hint: "Balanced, great quality" },
|
|
19
|
+
{ id: "", label: "Default (recommended)", hint: "Opus for all agents" },
|
|
22
20
|
{ id: "claude-opus-4-6", label: "Claude Opus 4.6", hint: "Most capable" },
|
|
21
|
+
{ id: "claude-sonnet-4-5-20250929", label: "Claude Sonnet 4.5", hint: "Fast, great quality" },
|
|
22
|
+
{ id: "claude-haiku-4-5-20251001", label: "Claude Haiku 4.5", hint: "Fastest, cheapest" },
|
|
23
23
|
],
|
|
24
24
|
openai: [
|
|
25
25
|
{ id: "", label: "Default (recommended)", hint: "GPT-5.2 for all agents" },
|
|
26
|
-
{ id: "gpt-5.2", label: "GPT-5.2", hint: "
|
|
27
|
-
{ id: "
|
|
26
|
+
{ id: "gpt-5.2", label: "GPT-5.2", hint: "Most capable" },
|
|
27
|
+
{ id: "gpt-5-mini", label: "GPT-5 mini", hint: "Fast, cost-efficient" },
|
|
28
|
+
{ id: "gpt-4.1", label: "GPT-4.1", hint: "1M context, great for large codebases" },
|
|
28
29
|
],
|
|
29
30
|
google: [
|
|
30
|
-
{ id: "", label: "Default (recommended)", hint: "
|
|
31
|
-
{ id: "gemini-2.5-
|
|
32
|
-
{ id: "gemini-2.5-
|
|
31
|
+
{ id: "", label: "Default (recommended)", hint: "Gemini 2.5 Pro for all agents" },
|
|
32
|
+
{ id: "gemini-2.5-pro", label: "Gemini 2.5 Pro", hint: "Most capable, 1M context" },
|
|
33
|
+
{ id: "gemini-2.5-flash", label: "Gemini 2.5 Flash", hint: "Fast, cheapest, 1M context" },
|
|
33
34
|
],
|
|
34
35
|
};
|
|
35
36
|
function loadConfig() {
|
|
@@ -191,7 +192,6 @@ export async function handleSetup() {
|
|
|
191
192
|
// Clean up legacy flat keys regardless
|
|
192
193
|
delete config.apiKey;
|
|
193
194
|
delete config.model;
|
|
194
|
-
delete config.ollamaBaseUrl;
|
|
195
195
|
if (!validNames.includes(legacy)) {
|
|
196
196
|
delete config.provider;
|
|
197
197
|
}
|
|
@@ -292,8 +292,15 @@ export async function handleSetup() {
|
|
|
292
292
|
console.log(chalk.green(` ✓ Model: ${chosen.label}`));
|
|
293
293
|
}
|
|
294
294
|
else {
|
|
295
|
-
|
|
296
|
-
|
|
295
|
+
// Save the actual default model so config is explicit
|
|
296
|
+
const defaultModels = {
|
|
297
|
+
anthropic: "claude-opus-4-6",
|
|
298
|
+
openai: "gpt-5.2",
|
|
299
|
+
google: "gemini-2.5-pro",
|
|
300
|
+
};
|
|
301
|
+
const defaultModel = defaultModels[provider] ?? resolveModel(provider, "standard");
|
|
302
|
+
profiles[provider].model = defaultModel;
|
|
303
|
+
console.log(chalk.green(` ✓ Model: ${defaultModel} (default)`));
|
|
297
304
|
}
|
|
298
305
|
}
|
|
299
306
|
config.profiles = profiles;
|
|
@@ -326,16 +333,13 @@ export async function handleSetup() {
|
|
|
326
333
|
// Clean up legacy top-level keys
|
|
327
334
|
delete config.apiKey;
|
|
328
335
|
delete config.model;
|
|
329
|
-
delete config.ollamaBaseUrl;
|
|
330
336
|
// Save config
|
|
331
337
|
saveConfig(config);
|
|
332
|
-
console.log(chalk.gray(`\n Config saved to ${CONFIG_PATH}`));
|
|
333
|
-
console.log(chalk.gray(" Your API key is stored locally on this machine and never sent to ArchByte."));
|
|
334
|
-
console.log(chalk.gray(" All model calls go directly from your machine to your provider."));
|
|
335
338
|
// Generate archbyte.yaml in .archbyte/ if it doesn't exist
|
|
336
339
|
const projectDir = process.cwd();
|
|
337
340
|
const archbyteDir = path.join(projectDir, ".archbyte");
|
|
338
341
|
const yamlPath = path.join(archbyteDir, "archbyte.yaml");
|
|
342
|
+
let yamlCreated = false;
|
|
339
343
|
if (!fs.existsSync(yamlPath)) {
|
|
340
344
|
if (!fs.existsSync(archbyteDir)) {
|
|
341
345
|
fs.mkdirSync(archbyteDir, { recursive: true });
|
|
@@ -355,21 +359,39 @@ export async function handleSetup() {
|
|
|
355
359
|
let template = fs.readFileSync(templatePath, "utf-8");
|
|
356
360
|
template = template.replace("name: my-project", `name: ${projectName}`);
|
|
357
361
|
fs.writeFileSync(yamlPath, template, "utf-8");
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
console.log(chalk.gray(` .archbyte/archbyte.yaml already exists`));
|
|
362
|
+
yamlCreated = true;
|
|
362
363
|
}
|
|
363
364
|
// Generate README.md in .archbyte/
|
|
364
365
|
writeArchbyteReadme(archbyteDir);
|
|
366
|
+
// ─── Summary ───
|
|
367
|
+
const dim = chalk.gray;
|
|
368
|
+
const sep = dim(" ───");
|
|
369
|
+
console.log();
|
|
370
|
+
console.log(chalk.bold.green(" ✓ Setup complete"));
|
|
371
|
+
console.log();
|
|
372
|
+
console.log(sep);
|
|
373
|
+
console.log();
|
|
374
|
+
console.log(dim(" ~/.archbyte/") + " API keys, login, config " + dim("(global)"));
|
|
375
|
+
console.log(dim(" .archbyte/") + " Analysis, diagrams " + dim("(per project)"));
|
|
365
376
|
console.log();
|
|
366
|
-
console.log(
|
|
377
|
+
console.log(dim(" Your keys never leave this machine."));
|
|
378
|
+
console.log(dim(" All model calls go directly to your provider."));
|
|
367
379
|
console.log();
|
|
368
|
-
console.log(
|
|
369
|
-
console.log(
|
|
380
|
+
console.log(sep);
|
|
381
|
+
console.log();
|
|
382
|
+
if (yamlCreated) {
|
|
383
|
+
console.log(chalk.green(" + ") + "Created " + chalk.cyan(".archbyte/archbyte.yaml"));
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
console.log(dim(" .archbyte/archbyte.yaml already exists"));
|
|
387
|
+
}
|
|
388
|
+
console.log();
|
|
389
|
+
console.log(sep);
|
|
390
|
+
console.log();
|
|
391
|
+
console.log(" " + chalk.bold("Next"));
|
|
392
|
+
console.log(" " + chalk.cyan("archbyte run") + " Analyze your codebase");
|
|
370
393
|
if (hasClaude || hasCodex) {
|
|
371
|
-
console.log();
|
|
372
|
-
console.log(chalk.bold(" MCP: ") + chalk.cyan("archbyte mcp install") + chalk.bold(" to use ArchByte from your AI tool."));
|
|
394
|
+
console.log(" " + chalk.cyan("archbyte mcp install") + " Use from your AI tool");
|
|
373
395
|
}
|
|
374
396
|
console.log();
|
|
375
397
|
}
|
package/dist/cli/yaml-io.d.ts
CHANGED
|
@@ -71,6 +71,8 @@ export interface ScanMetadata {
|
|
|
71
71
|
};
|
|
72
72
|
validation?: unknown;
|
|
73
73
|
gaps?: unknown;
|
|
74
|
+
incrementalMode?: boolean;
|
|
75
|
+
skippedAgents?: string[];
|
|
74
76
|
}
|
|
75
77
|
export declare function loadSpec(rootDir: string): ArchbyteSpec | null;
|
|
76
78
|
export declare function writeSpec(rootDir: string, spec: ArchbyteSpec): void;
|
package/package.json
CHANGED
|
@@ -62,7 +62,7 @@ Error generating stack: `+p.message+`
|
|
|
62
62
|
M${q.x},${q.y}h${q.width}v${q.height}h${-q.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}vg.displayName="MiniMap";b.memo(vg);const fE=t=>r=>t?`${Math.max(1/r.transform[2],1)}`:void 0,hE={[Eo.Line]:"right",[Eo.Handle]:"bottom-right"};function pE({nodeId:t,position:r,variant:o=Eo.Handle,className:s,style:a=void 0,children:u,color:c,minWidth:h=10,minHeight:m=10,maxWidth:y=Number.MAX_VALUE,maxHeight:x=Number.MAX_VALUE,keepAspectRatio:g=!1,resizeDirection:v,autoScale:C=!0,shouldResize:E,onResizeStart:N,onResize:k,onResizeEnd:S}){const I=Ym(),_=typeof t=="string"?t:I,j=et(),O=b.useRef(null),A=o===Eo.Handle,H=$e(b.useCallback(fE(A&&C),[A,C]),Je),q=b.useRef(null),J=r??hE[o];b.useEffect(()=>{if(!(!O.current||!_))return q.current||(q.current=W1({domNode:O.current,nodeId:_,getStoreItems:()=>{const{nodeLookup:U,transform:X,snapGrid:re,snapToGrid:P,nodeOrigin:K,domNode:V}=j.getState();return{nodeLookup:U,transform:X,snapGrid:re,snapToGrid:P,nodeOrigin:K,paneDomNode:V}},onChange:(U,X)=>{const{triggerNodeChanges:re,nodeLookup:P,parentLookup:K,nodeOrigin:V}=j.getState(),G=[],R={x:U.x,y:U.y},z=P.get(_);if(z&&z.expandParent&&z.parentId){const B=z.origin??V,M=U.width??z.measured.width??0,D=U.height??z.measured.height??0,ie={id:z.id,parentId:z.parentId,rect:{width:M,height:D,...hm({x:U.x??z.position.x,y:U.y??z.position.y},{width:M,height:D},z.parentId,P,B)}},oe=Rc([ie],P,K,V);G.push(...oe),R.x=U.x?Math.max(B[0]*M,U.x):void 0,R.y=U.y?Math.max(B[1]*D,U.y):void 0}if(R.x!==void 0&&R.y!==void 0){const B={id:_,type:"position",position:{...R}};G.push(B)}if(U.width!==void 0&&U.height!==void 0){const M={id:_,type:"dimensions",resizing:!0,setAttributes:v?v==="horizontal"?"width":"height":!0,dimensions:{width:U.width,height:U.height}};G.push(M)}for(const B of X){const M={...B,type:"position"};G.push(M)}re(G)},onEnd:({width:U,height:X})=>{const re={id:_,type:"dimensions",resizing:!1,dimensions:{width:U,height:X}};j.getState().triggerNodeChanges([re])}})),q.current.update({controlPosition:J,boundaries:{minWidth:h,minHeight:m,maxWidth:y,maxHeight:x},keepAspectRatio:g,resizeDirection:v,onResizeStart:N,onResize:k,onResizeEnd:S,shouldResize:E}),()=>{var U;(U=q.current)==null||U.destroy()}},[J,h,m,y,x,g,N,k,S,E]);const ee=J.split("-");return f.jsx("div",{className:at(["react-flow__resize-control","nodrag",...ee,o,s]),ref:O,style:{...a,scale:H,...c&&{[A?"backgroundColor":"borderColor"]:c}},children:u})}const pp=b.memo(pE);function mE({nodeId:t,isVisible:r=!0,handleClassName:o,handleStyle:s,lineClassName:a,lineStyle:u,color:c,minWidth:h=10,minHeight:m=10,maxWidth:y=Number.MAX_VALUE,maxHeight:x=Number.MAX_VALUE,keepAspectRatio:g=!1,autoScale:v=!0,shouldResize:C,onResizeStart:E,onResize:N,onResizeEnd:k}){return r?f.jsxs(f.Fragment,{children:[$1.map(S=>f.jsx(pp,{className:a,style:u,nodeId:t,position:S,variant:Eo.Line,color:c,minWidth:h,minHeight:m,maxWidth:y,maxHeight:x,onResizeStart:E,keepAspectRatio:g,autoScale:v,shouldResize:C,onResize:N,onResizeEnd:k},S)),D1.map(S=>f.jsx(pp,{className:o,style:s,nodeId:t,position:S,color:c,minWidth:h,minHeight:m,maxWidth:y,maxHeight:x,onResizeStart:E,keepAspectRatio:g,autoScale:v,shouldResize:C,onResize:N,onResizeEnd:k},S))]}):null}function gE(t,r){if(t.match(/^[a-z]+:\/\//i))return t;if(t.match(/^\/\//))return window.location.protocol+t;if(t.match(/^[a-z]+:/i))return t;const o=document.implementation.createHTMLDocument(),s=o.createElement("base"),a=o.createElement("a");return o.head.appendChild(s),o.body.appendChild(a),r&&(s.href=r),a.href=t,a.href}const yE=(()=>{let t=0;const r=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(t+=1,`u${r()}${t}`)})();function Vr(t){const r=[];for(let o=0,s=t.length;o<s;o++)r.push(t[o]);return r}let Jo=null;function xg(t={}){return Jo||(t.includeStyleProperties?(Jo=t.includeStyleProperties,Jo):(Jo=Vr(window.getComputedStyle(document.documentElement)),Jo))}function Xl(t,r){const s=(t.ownerDocument.defaultView||window).getComputedStyle(t).getPropertyValue(r);return s?parseFloat(s.replace("px","")):0}function vE(t){const r=Xl(t,"border-left-width"),o=Xl(t,"border-right-width");return t.clientWidth+r+o}function xE(t){const r=Xl(t,"border-top-width"),o=Xl(t,"border-bottom-width");return t.clientHeight+r+o}function wg(t,r={}){const o=r.width||vE(t),s=r.height||xE(t);return{width:o,height:s}}function wE(){let t,r;try{r=process}catch{}const o=r&&r.env?r.env.devicePixelRatio:null;return o&&(t=parseInt(o,10),Number.isNaN(t)&&(t=1)),t||window.devicePixelRatio||1}const Qt=16384;function SE(t){(t.width>Qt||t.height>Qt)&&(t.width>Qt&&t.height>Qt?t.width>t.height?(t.height*=Qt/t.width,t.width=Qt):(t.width*=Qt/t.height,t.height=Qt):t.width>Qt?(t.height*=Qt/t.width,t.width=Qt):(t.width*=Qt/t.height,t.height=Qt))}function Gl(t){return new Promise((r,o)=>{const s=new Image;s.onload=()=>{s.decode().then(()=>{requestAnimationFrame(()=>r(s))})},s.onerror=o,s.crossOrigin="anonymous",s.decoding="async",s.src=t})}async function kE(t){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(t)).then(encodeURIComponent).then(r=>`data:image/svg+xml;charset=utf-8,${r}`)}async function EE(t,r,o){const s="http://www.w3.org/2000/svg",a=document.createElementNS(s,"svg"),u=document.createElementNS(s,"foreignObject");return a.setAttribute("width",`${r}`),a.setAttribute("height",`${o}`),a.setAttribute("viewBox",`0 0 ${r} ${o}`),u.setAttribute("width","100%"),u.setAttribute("height","100%"),u.setAttribute("x","0"),u.setAttribute("y","0"),u.setAttribute("externalResourcesRequired","true"),a.appendChild(u),u.appendChild(t),kE(a)}const Ht=(t,r)=>{if(t instanceof r)return!0;const o=Object.getPrototypeOf(t);return o===null?!1:o.constructor.name===r.name||Ht(o,r)};function NE(t){const r=t.getPropertyValue("content");return`${t.cssText} content: '${r.replace(/'|"/g,"")}';`}function CE(t,r){return xg(r).map(o=>{const s=t.getPropertyValue(o),a=t.getPropertyPriority(o);return`${o}: ${s}${a?" !important":""};`}).join(" ")}function _E(t,r,o,s){const a=`.${t}:${r}`,u=o.cssText?NE(o):CE(o,s);return document.createTextNode(`${a}{${u}}`)}function mp(t,r,o,s){const a=window.getComputedStyle(t,o),u=a.getPropertyValue("content");if(u===""||u==="none")return;const c=yE();try{r.className=`${r.className} ${c}`}catch{return}const h=document.createElement("style");h.appendChild(_E(c,o,a,s)),r.appendChild(h)}function jE(t,r,o){mp(t,r,":before",o),mp(t,r,":after",o)}const gp="application/font-woff",yp="image/jpeg",bE={woff:gp,woff2:gp,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:yp,jpeg:yp,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function PE(t){const r=/\.([^./]*?)$/g.exec(t);return r?r[1]:""}function Lc(t){const r=PE(t).toLowerCase();return bE[r]||""}function ME(t){return t.split(/,/)[1]}function gc(t){return t.search(/^(data:)/)!==-1}function IE(t,r){return`data:${r};base64,${t}`}async function Sg(t,r,o){const s=await fetch(t,r);if(s.status===404)throw new Error(`Resource "${s.url}" not found`);const a=await s.blob();return new Promise((u,c)=>{const h=new FileReader;h.onerror=c,h.onloadend=()=>{try{u(o({res:s,result:h.result}))}catch(m){c(m)}},h.readAsDataURL(a)})}const tc={};function TE(t,r,o){let s=t.replace(/\?.*/,"");return o&&(s=t),/ttf|otf|eot|woff2?/i.test(s)&&(s=s.replace(/.*\//,"")),r?`[${r}]${s}`:s}async function Dc(t,r,o){const s=TE(t,r,o.includeQueryParams);if(tc[s]!=null)return tc[s];o.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+new Date().getTime());let a;try{const u=await Sg(t,o.fetchRequestInit,({res:c,result:h})=>(r||(r=c.headers.get("Content-Type")||""),ME(h)));a=IE(u,r)}catch(u){a=o.imagePlaceholder||"";let c=`Failed to fetch resource: ${t}`;u&&(c=typeof u=="string"?u:u.message),c&&console.warn(c)}return tc[s]=a,a}async function RE(t){const r=t.toDataURL();return r==="data:,"?t.cloneNode(!1):Gl(r)}async function zE(t,r){if(t.currentSrc){const u=document.createElement("canvas"),c=u.getContext("2d");u.width=t.clientWidth,u.height=t.clientHeight,c==null||c.drawImage(t,0,0,u.width,u.height);const h=u.toDataURL();return Gl(h)}const o=t.poster,s=Lc(o),a=await Dc(o,s,r);return Gl(a)}async function AE(t,r){var o;try{if(!((o=t==null?void 0:t.contentDocument)===null||o===void 0)&&o.body)return await la(t.contentDocument.body,r,!0)}catch{}return t.cloneNode(!1)}async function LE(t,r){return Ht(t,HTMLCanvasElement)?RE(t):Ht(t,HTMLVideoElement)?zE(t,r):Ht(t,HTMLIFrameElement)?AE(t,r):t.cloneNode(kg(t))}const DE=t=>t.tagName!=null&&t.tagName.toUpperCase()==="SLOT",kg=t=>t.tagName!=null&&t.tagName.toUpperCase()==="SVG";async function $E(t,r,o){var s,a;if(kg(r))return r;let u=[];return DE(t)&&t.assignedNodes?u=Vr(t.assignedNodes()):Ht(t,HTMLIFrameElement)&&(!((s=t.contentDocument)===null||s===void 0)&&s.body)?u=Vr(t.contentDocument.body.childNodes):u=Vr(((a=t.shadowRoot)!==null&&a!==void 0?a:t).childNodes),u.length===0||Ht(t,HTMLVideoElement)||await u.reduce((c,h)=>c.then(()=>la(h,o)).then(m=>{m&&r.appendChild(m)}),Promise.resolve()),r}function OE(t,r,o){const s=r.style;if(!s)return;const a=window.getComputedStyle(t);a.cssText?(s.cssText=a.cssText,s.transformOrigin=a.transformOrigin):xg(o).forEach(u=>{let c=a.getPropertyValue(u);u==="font-size"&&c.endsWith("px")&&(c=`${Math.floor(parseFloat(c.substring(0,c.length-2)))-.1}px`),Ht(t,HTMLIFrameElement)&&u==="display"&&c==="inline"&&(c="block"),u==="d"&&r.getAttribute("d")&&(c=`path(${r.getAttribute("d")})`),s.setProperty(u,c,a.getPropertyPriority(u))})}function FE(t,r){Ht(t,HTMLTextAreaElement)&&(r.innerHTML=t.value),Ht(t,HTMLInputElement)&&r.setAttribute("value",t.value)}function HE(t,r){if(Ht(t,HTMLSelectElement)){const s=Array.from(r.children).find(a=>t.value===a.getAttribute("value"));s&&s.setAttribute("selected","")}}function VE(t,r,o){return Ht(r,Element)&&(OE(t,r,o),jE(t,r,o),FE(t,r),HE(t,r)),r}async function BE(t,r){const o=t.querySelectorAll?t.querySelectorAll("use"):[];if(o.length===0)return t;const s={};for(let u=0;u<o.length;u++){const h=o[u].getAttribute("xlink:href");if(h){const m=t.querySelector(h),y=document.querySelector(h);!m&&y&&!s[h]&&(s[h]=await la(y,r,!0))}}const a=Object.values(s);if(a.length){const u="http://www.w3.org/1999/xhtml",c=document.createElementNS(u,"svg");c.setAttribute("xmlns",u),c.style.position="absolute",c.style.width="0",c.style.height="0",c.style.overflow="hidden",c.style.display="none";const h=document.createElementNS(u,"defs");c.appendChild(h);for(let m=0;m<a.length;m++)h.appendChild(a[m]);t.appendChild(c)}return t}async function la(t,r,o){return!o&&r.filter&&!r.filter(t)?null:Promise.resolve(t).then(s=>LE(s,r)).then(s=>$E(t,s,r)).then(s=>VE(t,s,r)).then(s=>BE(s,r))}const Eg=/url\((['"]?)([^'"]+?)\1\)/g,WE=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,UE=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function YE(t){const r=t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${r})(['"]?\\))`,"g")}function XE(t){const r=[];return t.replace(Eg,(o,s,a)=>(r.push(a),o)),r.filter(o=>!gc(o))}async function GE(t,r,o,s,a){try{const u=o?gE(r,o):r,c=Lc(r);let h;return a||(h=await Dc(u,c,s)),t.replace(YE(r),`$1${h}$3`)}catch{}return t}function KE(t,{preferredFontFormat:r}){return r?t.replace(UE,o=>{for(;;){const[s,,a]=WE.exec(o)||[];if(!a)return"";if(a===r)return`src: ${s};`}}):t}function Ng(t){return t.search(Eg)!==-1}async function Cg(t,r,o){if(!Ng(t))return t;const s=KE(t,o);return XE(s).reduce((u,c)=>u.then(h=>GE(h,c,r,o)),Promise.resolve(s))}async function ei(t,r,o){var s;const a=(s=r.style)===null||s===void 0?void 0:s.getPropertyValue(t);if(a){const u=await Cg(a,null,o);return r.style.setProperty(t,u,r.style.getPropertyPriority(t)),!0}return!1}async function QE(t,r){await ei("background",t,r)||await ei("background-image",t,r),await ei("mask",t,r)||await ei("-webkit-mask",t,r)||await ei("mask-image",t,r)||await ei("-webkit-mask-image",t,r)}async function qE(t,r){const o=Ht(t,HTMLImageElement);if(!(o&&!gc(t.src))&&!(Ht(t,SVGImageElement)&&!gc(t.href.baseVal)))return;const s=o?t.src:t.href.baseVal,a=await Dc(s,Lc(s),r);await new Promise((u,c)=>{t.onload=u,t.onerror=r.onImageErrorHandler?(...m)=>{try{u(r.onImageErrorHandler(...m))}catch(y){c(y)}}:c;const h=t;h.decode&&(h.decode=u),h.loading==="lazy"&&(h.loading="eager"),o?(t.srcset="",t.src=a):t.href.baseVal=a})}async function ZE(t,r){const s=Vr(t.childNodes).map(a=>_g(a,r));await Promise.all(s).then(()=>t)}async function _g(t,r){Ht(t,Element)&&(await QE(t,r),await qE(t,r),await ZE(t,r))}function JE(t,r){const{style:o}=t;r.backgroundColor&&(o.backgroundColor=r.backgroundColor),r.width&&(o.width=`${r.width}px`),r.height&&(o.height=`${r.height}px`);const s=r.style;return s!=null&&Object.keys(s).forEach(a=>{o[a]=s[a]}),t}const vp={};async function xp(t){let r=vp[t];if(r!=null)return r;const s=await(await fetch(t)).text();return r={url:t,cssText:s},vp[t]=r,r}async function wp(t,r){let o=t.cssText;const s=/url\(["']?([^"')]+)["']?\)/g,u=(o.match(/url\([^)]+\)/g)||[]).map(async c=>{let h=c.replace(s,"$1");return h.startsWith("https://")||(h=new URL(h,t.url).href),Sg(h,r.fetchRequestInit,({result:m})=>(o=o.replace(c,`url(${m})`),[c,m]))});return Promise.all(u).then(()=>o)}function Sp(t){if(t==null)return[];const r=[],o=/(\/\*[\s\S]*?\*\/)/gi;let s=t.replace(o,"");const a=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const m=a.exec(s);if(m===null)break;r.push(m[0])}s=s.replace(a,"");const u=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,c="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",h=new RegExp(c,"gi");for(;;){let m=u.exec(s);if(m===null){if(m=h.exec(s),m===null)break;u.lastIndex=h.lastIndex}else h.lastIndex=u.lastIndex;r.push(m[0])}return r}async function eN(t,r){const o=[],s=[];return t.forEach(a=>{if("cssRules"in a)try{Vr(a.cssRules||[]).forEach((u,c)=>{if(u.type===CSSRule.IMPORT_RULE){let h=c+1;const m=u.href,y=xp(m).then(x=>wp(x,r)).then(x=>Sp(x).forEach(g=>{try{a.insertRule(g,g.startsWith("@import")?h+=1:a.cssRules.length)}catch(v){console.error("Error inserting rule from remote css",{rule:g,error:v})}})).catch(x=>{console.error("Error loading remote css",x.toString())});s.push(y)}})}catch(u){const c=t.find(h=>h.href==null)||document.styleSheets[0];a.href!=null&&s.push(xp(a.href).then(h=>wp(h,r)).then(h=>Sp(h).forEach(m=>{c.insertRule(m,c.cssRules.length)})).catch(h=>{console.error("Error loading remote stylesheet",h)})),console.error("Error inlining remote css file",u)}}),Promise.all(s).then(()=>(t.forEach(a=>{if("cssRules"in a)try{Vr(a.cssRules||[]).forEach(u=>{o.push(u)})}catch(u){console.error(`Error while reading CSS rules from ${a.href}`,u)}}),o))}function tN(t){return t.filter(r=>r.type===CSSRule.FONT_FACE_RULE).filter(r=>Ng(r.style.getPropertyValue("src")))}async function nN(t,r){if(t.ownerDocument==null)throw new Error("Provided element is not within a Document");const o=Vr(t.ownerDocument.styleSheets),s=await eN(o,r);return tN(s)}function jg(t){return t.trim().replace(/["']/g,"")}function rN(t){const r=new Set;function o(s){(s.style.fontFamily||getComputedStyle(s).fontFamily).split(",").forEach(u=>{r.add(jg(u))}),Array.from(s.children).forEach(u=>{u instanceof HTMLElement&&o(u)})}return o(t),r}async function oN(t,r){const o=await nN(t,r),s=rN(t);return(await Promise.all(o.filter(u=>s.has(jg(u.style.fontFamily))).map(u=>{const c=u.parentStyleSheet?u.parentStyleSheet.href:null;return Cg(u.cssText,c,r)}))).join(`
|
|
63
63
|
`)}async function iN(t,r){const o=r.fontEmbedCSS!=null?r.fontEmbedCSS:r.skipFonts?null:await oN(t,r);if(o){const s=document.createElement("style"),a=document.createTextNode(o);s.appendChild(a),t.firstChild?t.insertBefore(s,t.firstChild):t.appendChild(s)}}async function bg(t,r={}){const{width:o,height:s}=wg(t,r),a=await la(t,r,!0);return await iN(a,r),await _g(a,r),JE(a,r),await EE(a,o,s)}async function sN(t,r={}){const{width:o,height:s}=wg(t,r),a=await bg(t,r),u=await Gl(a),c=document.createElement("canvas"),h=c.getContext("2d"),m=r.pixelRatio||wE(),y=r.canvasWidth||o,x=r.canvasHeight||s;return c.width=y*m,c.height=x*m,r.skipAutoScale||SE(c),c.style.width=`${y}`,c.style.height=`${x}`,r.backgroundColor&&(h.fillStyle=r.backgroundColor,h.fillRect(0,0,c.width,c.height)),h.drawImage(u,0,0,c.width,c.height),c}async function lN(t,r={}){return(await sN(t,r)).toDataURL()}function aN({feature:t,onClose:r}){return f.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},onClick:r,children:f.jsxs("div",{style:{background:"#1e1e2e",border:"1px solid #444",borderRadius:12,padding:"32px 40px",maxWidth:420,textAlign:"center"},onClick:o=>o.stopPropagation(),children:[f.jsx("div",{style:{fontSize:32,marginBottom:12},children:"🔒"}),f.jsxs("h2",{style:{color:"#fff",margin:"0 0 8px",fontSize:20},children:[t," is a Pro feature"]}),f.jsxs("p",{style:{color:"#aaa",margin:"0 0 24px",fontSize:14,lineHeight:1.5},children:["Upgrade to Pro for ",t.toLowerCase(),", drift detection, premium agents, and more."]}),f.jsx("a",{href:"https://heartbyte.io/archbyte/pricing",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",background:"#7c3aed",color:"#fff",padding:"10px 28px",borderRadius:8,textDecoration:"none",fontWeight:600,fontSize:14},children:"Upgrade to Pro"}),f.jsx("button",{onClick:r,style:{display:"block",margin:"16px auto 0",background:"none",border:"none",color:"#888",cursor:"pointer",fontSize:13},children:"Maybe later"})]})})}function kp({trigger:t,triggerClassName:r,contentClassName:o,children:s,disabled:a}){const[u,c]=b.useState(!1),h=b.useRef(null);return b.useEffect(()=>{if(!u)return;const m=x=>{h.current&&!h.current.contains(x.target)&&c(!1)},y=()=>c(!1);return document.addEventListener("mousedown",m),document.addEventListener("dropdown:closeall",y),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("dropdown:closeall",y)}},[u]),f.jsxs("div",{ref:h,className:"dropdown-wrapper",children:[f.jsx("button",{className:r,onClick:()=>!a&&c(!u),disabled:a,children:t}),u&&f.jsx("div",{className:`dropdown-menu ${o||""}`,onClick:()=>c(!1),children:s})]})}const uN={presentation:"#1971c2",application:"#e67700",data:"#2f9e44",external:"#9c36b5",deployment:"#c92a2a"},Ep={frontend:"■",backend:"⬡",service:"⬡",worker:"⚙",gateway:"⬥",database:"⎕",external:"☁",component:"●",cli:"❯",library:"≡"};function cN({data:t,selected:r}){const o=t,s=o.label.split(`
|
|
64
64
|
`),a=s[0],u=s.slice(1).join(`
|
|
65
|
-
`),c=["arch-node",o.layer,o.active?"active":"",o.highlighted?"highlighted":"",o.locked?"locked":"",o.isConnected===!0?"connected":"",o.isConnected===!1?"dimmed":"",o.isSearchMatch===!0?"search-match":"",o.isSearchMatch===!1?"search-no-match":""].filter(Boolean).join(" "),h=uN[o.layer]||"#868e96",m=Ep[o.nodeType]||Ep.component;return f.jsxs(f.Fragment,{children:[f.jsx(mE,{color:h,isVisible:r,minWidth:100,minHeight:60}),f.jsxs("div",{className:c,style:{minWidth:o.width||130,width:"100%",height:"100%"},children:[f.jsx(Hr,{type:"target",position:Ne.Top}),f.jsx(Hr,{type:"target",position:Ne.Left}),f.jsx("div",{className:"node-type-icon",children:m}),f.jsxs("div",{className:"node-content",children:[f.jsx("div",{className:"label",children:a}),u&&f.jsx("div",{className:"sublabel",children:u}),o.description&&f.jsx("div",{className:"node-desc",children:o.description})]}),o.techStack&&o.techStack.length>0&&f.jsx("div",{className:"node-tech-row",children:o.techStack.slice(0,3).map((y,x)=>f.jsx("span",{className:"node-tech-pill",children:y},x))}),f.jsx(Hr,{type:"source",position:Ne.Bottom}),f.jsx(Hr,{type:"source",position:Ne.Right})]})]})}const Pg=b.memo(cN),dN={develop:"#2f9e44",development:"#2f9e44",dev:"#2f9e44",staging:"#e67700",stage:"#e67700",production:"#c92a2a",prod:"#c92a2a"};function fN({selectedEnvironment:t,environments:r,onSelectEnvironment:o}){if(!r||Object.keys(r).length===0)return null;const s=Object.keys(r);return f.jsx("div",{className:"environment-tabs",children:s.map(a=>{var y;const u=t===a,c=r==null?void 0:r[a],h=(c==null?void 0:c.color)||dN[a]||"#6b7280",m=(c==null?void 0:c.label)||a.charAt(0).toUpperCase()+a.slice(1);return f.jsxs("button",{className:`env-tab ${u?"selected":""}`,onClick:()=>o(a),style:{"--env-color":h},children:[f.jsx("span",{className:"env-indicator"}),f.jsx("span",{className:"env-label",children:m}),u&&c&&f.jsx("span",{className:"env-meta",children:[c.deployment,c.scaling,(y=c.urlPatterns||c.urls)==null?void 0:y[0]].filter(Boolean).join(" | ")})]},a)})})}const hN=b.memo(fN);function di({children:t,className:r,style:o}){const s=b.useRef(null),[a,u]=b.useState({x:0,y:0}),c=b.useRef(!1),h=b.useRef({x:0,y:0}),m=b.useRef({x:0,y:0}),y=b.useCallback(x=>{const g=x.target;if(!g.closest("[data-drag-handle]")||g.closest("button"))return;c.current=!0,h.current={x:x.clientX,y:x.clientY},m.current={...a},x.preventDefault();const C=N=>{c.current&&u({x:m.current.x+(N.clientX-h.current.x),y:m.current.y+(N.clientY-h.current.y)})},E=()=>{c.current=!1,document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",E)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",E)},[a]);return f.jsx("div",{ref:s,className:r,style:{...o,transform:`translate(${a.x}px, ${a.y}px)`},onMouseDown:y,children:t})}function pN(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function mN(t){return new Date(t).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function gN({visible:t,onClose:r}){const[o,s]=b.useState(null),a=b.useCallback(async()=>{try{const u=await fetch("/api/stats");u.ok&&s(await u.json())}catch{}},[]);return b.useEffect(()=>{t&&a()},[t,a]),!t||!o?null:f.jsxs(di,{className:"stats-overlay",children:[f.jsxs("div",{className:"stats-overlay-header","data-drag-handle":!0,children:[f.jsx("span",{className:"stats-overlay-title",children:"Architecture Stats"}),f.jsx("button",{className:"panel-close-btn",onClick:r,children:"x"})]}),(o.durationMs||o.filesScanned||o.analyzedAt)&&f.jsxs("div",{className:"stats-scan-info",children:[o.durationMs!=null&&f.jsx("span",{className:"scan-info-item",children:pN(o.durationMs)}),o.filesScanned!=null&&f.jsxs("span",{className:"scan-info-item",children:[o.filesScanned.toLocaleString()," files"]}),o.tokenUsage&&f.jsxs("span",{className:"scan-info-item",children:[(o.tokenUsage.input+o.tokenUsage.output).toLocaleString()," tokens"]}),o.analyzedAt&&f.jsx("span",{className:"scan-info-item",children:mN(o.analyzedAt)})]}),f.jsxs("div",{className:"stats-grid",children:[f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.components}),f.jsx("div",{className:"stat-label",children:"Components"})]}),f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.totalConnections}),f.jsx("div",{className:"stat-label",children:"Connections"})]}),f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.databases}),f.jsx("div",{className:"stat-label",children:"Databases"})]}),f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.externalServices}),f.jsx("div",{className:"stat-label",children:"External"})]}),f.jsxs("div",{className:`stat-card ${o.orphans>0?"highlight":""}`,children:[f.jsx("div",{className:"stat-value",children:o.orphans}),f.jsx("div",{className:"stat-label",children:"Orphans"})]}),f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.flows}),f.jsx("div",{className:"stat-label",children:"Flows"})]})]})]})}const yN=b.memo(gN);function vN({visible:t,onClose:r,onHighlightNode:o}){const[s,a]=b.useState(null),[u,c]=b.useState(!1),h=b.useCallback(async()=>{c(!0);try{const m=await fetch("/api/validate");m.ok&&a(await m.json())}catch{}c(!1)},[]);return b.useEffect(()=>{t&&h()},[t,h]),!t||!s&&!u?null:f.jsxs(di,{className:"validation-panel",children:[f.jsxs("div",{className:"validation-header","data-drag-handle":!0,children:[f.jsx("span",{className:"validation-title",children:"Validation"}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx("button",{className:"panel-btn cyan small",onClick:h,disabled:u,children:u?"...":"Re-validate"}),s&&f.jsx("span",{className:`validation-badge ${s.passed?"pass":"fail"}`,children:s.passed?"PASS":"FAIL"}),f.jsx("button",{className:"panel-close-btn",onClick:r,children:"x"})]})]}),u&&!s?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,textAlign:"center",padding:12},children:"Validating..."}):s&&s.violations.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,textAlign:"center",padding:12},children:"No violations found"}):s?f.jsx("div",{children:s.violations.map((m,y)=>f.jsxs("div",{className:`violation-item ${m.level}`,onClick:()=>{m.nodeIds&&m.nodeIds.length>0&&o(m.nodeIds[0])},children:[f.jsx("div",{className:"violation-rule",children:m.rule}),f.jsx("div",{className:"violation-message",children:m.message})]},y))}):null,s&&f.jsxs("div",{style:{marginTop:8,fontSize:10,color:"var(--text-muted)",textAlign:"center"},children:[s.errors," error",s.errors!==1?"s":"",", ",s.warnings," warning",s.warnings!==1?"s":""]})]})}const xN=b.memo(vN);function wN({visible:t}){const[r,o]=b.useState(null),[s,a]=b.useState([]),[u,c]=b.useState(!0),[h,m]=b.useState(!1),y=b.useCallback(async()=>{try{const[k,S]=await Promise.all([fetch("/api/patrol/latest"),fetch("/api/patrol/history")]);k.ok&&o(await k.json()),S.ok&&a(await S.json())}catch{}c(!1)},[]),x=b.useCallback(async()=>{try{const k=await fetch("/api/patrol/running");if(k.ok){const S=await k.json();m(S.running)}}catch{}},[]);b.useEffect(()=>{if(t){y(),x();const k=setInterval(y,h?5e3:1e4),S=setInterval(x,5e3);return()=>{clearInterval(k),clearInterval(S)}}},[t,y,x,h]);const g=async()=>{try{(await fetch("/api/patrol/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({interval:30})})).ok&&m(!0)}catch{}},v=async()=>{try{(await fetch("/api/patrol/stop",{method:"POST"})).ok&&m(!1)}catch{}};if(!t)return null;if(u)return f.jsx("div",{className:"ops-section",children:f.jsx("div",{className:"ops-empty",children:"Loading..."})});if(!r&&s.length===0)return f.jsxs("div",{className:"ops-section",children:[f.jsxs("div",{className:"ops-empty",children:["No patrol data yet.",f.jsx("span",{className:"ops-hint",children:"Start patrol to begin monitoring"})]}),f.jsx("div",{className:"patrol-actions",children:f.jsx("button",{className:"panel-btn green",onClick:g,disabled:h,children:h?"Running...":"Start Patrol"})})]});const C=s.slice(-20),E=C.filter(k=>k.passed).length,N=C.length>0?Math.round(E/C.length*100):0;return f.jsxs("div",{className:"ops-section",children:[f.jsx("div",{className:"patrol-actions",children:h?f.jsx("button",{className:"panel-btn red",onClick:v,children:"Stop Patrol"}):f.jsx("button",{className:"panel-btn green",onClick:g,children:"Start Patrol"})}),C.length>0&&f.jsxs("div",{className:"patrol-sparkline-row",children:[f.jsx("div",{className:"patrol-sparkline",children:C.map((k,S)=>f.jsx("div",{className:`spark-dot ${k.passed?"healthy":"violation"}`,title:`${new Date(k.timestamp).toLocaleTimeString()} — ${k.passed?"Healthy":"Violation"}`},S))}),f.jsxs("span",{className:"patrol-health-pct",children:[N,"%"]})]}),r&&f.jsxs("div",{className:`patrol-status-card ${r.passed?"healthy":"violation"}`,children:[f.jsxs("div",{className:"patrol-status-row",children:[f.jsx("span",{className:`patrol-badge ${r.passed?"healthy":"violation"}`,children:r.passed?"HEALTHY":"VIOLATION"}),f.jsx("span",{className:"patrol-time",children:new Date(r.timestamp).toLocaleTimeString()})]}),f.jsxs("div",{className:"patrol-counts",children:[r.errors>0&&f.jsxs("span",{className:"patrol-count error",children:[r.errors," err"]}),r.warnings>0&&f.jsxs("span",{className:"patrol-count warn",children:[r.warnings," warn"]}),r.errors===0&&r.warnings===0&&f.jsx("span",{className:"patrol-count ok",children:"All clear"})]})]}),r&&r.newViolations.length>0&&f.jsxs("div",{className:"patrol-violations",children:[f.jsx("div",{className:"patrol-violations-label",children:"New violations"}),r.newViolations.slice(0,5).map((k,S)=>f.jsxs("div",{className:`patrol-violation-item ${k.level}`,children:[f.jsx("span",{className:"patrol-v-rule",children:k.rule}),f.jsx("span",{className:"patrol-v-msg",children:k.message})]},S))]}),r&&r.resolvedViolations.length>0&&f.jsxs("div",{className:"patrol-violations resolved",children:[f.jsx("div",{className:"patrol-violations-label",children:"Resolved"}),r.resolvedViolations.slice(0,3).map((k,S)=>f.jsxs("div",{className:"patrol-violation-item resolved",children:[f.jsx("span",{className:"patrol-v-rule",children:k.rule}),f.jsx("span",{className:"patrol-v-msg",children:k.message})]},S))]}),f.jsxs("div",{className:"patrol-summary",children:[s.length," patrols total"]})]})}const SN=b.memo(wN);function kN({visible:t}){const[r,o]=b.useState([]),[s,a]=b.useState(null),[u,c]=b.useState(null),[h,m]=b.useState(!0),[y,x]=b.useState(null),[g,v]=b.useState(null),C=b.useRef(null),E=b.useCallback(async()=>{try{const I=await fetch("/api/workflow/list");I.ok&&o(await I.json())}catch{}m(!1)},[]),N=b.useCallback(async I=>{try{const _=await fetch(`/api/workflow/status/${I}`);if(_.ok){const j=await _.json();c(j),j&&y===I&&(j.status==="completed"||j.status==="failed")&&(x(null),E())}}catch{}},[y,E]);b.useEffect(()=>{if(t){E();const I=setInterval(E,y?3e3:1e4);return()=>clearInterval(I)}},[t,E,y]),b.useEffect(()=>(C.current&&clearInterval(C.current),s&&(N(s),C.current=setInterval(()=>N(s),y?3e3:1e4)),()=>{C.current&&clearInterval(C.current)}),[s,N,y]);const k=async I=>{v(null);try{const _=await fetch(`/api/workflow/run/${I}`,{method:"POST"});if(_.ok)x(I);else{const j=await _.json();v(j.error||"Failed to start workflow")}}catch{v("Failed to connect to server")}},S=async I=>{v(null);try{(await fetch("/api/workflow/reset",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:I})})).ok&&(c(null),E())}catch{}};return t?h?f.jsx("div",{className:"ops-section",children:f.jsx("div",{className:"ops-empty",children:"Loading..."})}):r.length===0?f.jsx("div",{className:"ops-section",children:f.jsxs("div",{className:"ops-empty",children:["No workflows available.",f.jsx("span",{className:"ops-hint",children:"Run: archbyte workflow --list"})]})}):f.jsxs("div",{className:"ops-section",children:[g&&f.jsx("div",{className:"wf-error",children:g}),r.map(I=>{const _=s===I.id,j=y===I.id;return f.jsxs("div",{className:"wf-item",children:[f.jsxs("div",{className:"wf-header",onClick:()=>a(_?null:I.id),children:[f.jsxs("div",{className:"wf-header-left",children:[f.jsx("span",{className:"wf-expand",children:_?"−":"+"}),f.jsx("span",{className:"wf-name",children:I.name}),I.builtin&&f.jsx("span",{className:"wf-tag",children:"built-in"})]}),(j||I.status)&&f.jsx("span",{className:`wf-status ${j?"running":I.status}`,children:j?"running":I.status==="completed"?"done":I.status})]}),_&&f.jsxs("div",{className:"wf-detail",children:[f.jsx("div",{className:"wf-desc",children:I.description}),u&&u.workflowId===I.id?f.jsxs("div",{className:"wf-steps",children:[Object.entries(u.steps).map(([O,A])=>f.jsxs("div",{className:`wf-step ${A.status}`,children:[f.jsx("span",{className:"wf-step-icon",children:A.status==="completed"?"✓":A.status==="running"?"▶":A.status==="failed"?"✗":"○"}),f.jsx("span",{className:"wf-step-id",children:O})]},O)),(()=>{const O=Object.keys(u.steps).length,A=Object.values(u.steps).filter(q=>q.status==="completed").length,H=O>0?Math.round(A/O*100):0;return f.jsxs("div",{className:"wf-progress",children:[f.jsx("div",{className:"wf-progress-bar",children:f.jsx("div",{className:"wf-progress-fill",style:{width:`${H}%`}})}),f.jsxs("span",{className:"wf-progress-label",children:[H,"%"]})]})})()]}):f.jsx("div",{className:"wf-steps-preview",children:I.steps.length>0?I.steps.join(" → "):"No state yet"}),f.jsxs("div",{className:"wf-actions",children:[f.jsx("button",{className:"panel-btn cyan",disabled:j,onClick:()=>k(I.id),children:j?"Running...":"Run"}),(I.status==="completed"||I.status==="failed")&&!j&&f.jsx("button",{className:"panel-btn amber",onClick:()=>S(I.id),children:"Reset"})]})]})]},I.id)})]}):null}const EN=b.memo(kN);function NN({projectInfo:t}){const[r,o]=b.useState(!1),s=b.useRef(null);return b.useEffect(()=>{if(!r)return;const a=u=>{s.current&&!s.current.contains(u.target)&&o(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[r]),t?f.jsxs("div",{className:"project-info-wrapper",ref:s,children:[f.jsx("button",{className:"project-info-trigger",onClick:()=>o(!r),children:t.name}),r&&f.jsxs("div",{className:"project-info-popup",children:[f.jsxs("div",{className:"project-info-header",children:[f.jsx("span",{className:"project-info-name",children:t.name}),t.primaryLanguage&&f.jsx("span",{className:"project-info-lang",children:t.primaryLanguage})]}),t.description&&f.jsx("p",{className:"project-info-desc",children:t.description}),t.isMonorepo&&f.jsx("div",{className:"project-info-badge",children:"Monorepo"}),t.workspacePath&&f.jsxs("a",{className:"project-info-vscode",href:`vscode://file${t.workspacePath}`,title:"Open folder in VS Code",children:[f.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M17.583 2.214L12.52 6.768 7.84 3.96 2.4 5.88v12.24l5.44 1.92 4.68-2.808 5.063 4.554L21.6 19.8V4.2l-4.017-1.986zM7.84 15.12V8.88l4.68 3.12-4.68 3.12zm9.743 2.544l-3.96-3.564 3.96-3.564v7.128z"})}),"Open in VS Code"]})]})]}):null}const CN={architecture:Pg},_N=1500;function jN({flow:t,architecture:r,onClose:o}){var C;const[s,a]=b.useState(0),[u,c]=b.useState(new Set([(C=t.steps[0])==null?void 0:C.edge])),[h,m]=b.useState(!0),{flowNodeIds:y,flowEdges:x}=b.useMemo(()=>{const E=new Set(t.steps.map(S=>S.edge)),N=r.edges.filter(S=>E.has(S.id)),k=new Set;return N.forEach(S=>{k.add(S.source),k.add(S.target)}),{flowNodeIds:k,flowEdges:N}},[t,r]),g=b.useMemo(()=>{const E=r.nodes.filter(ee=>y.has(ee.id)),N=320,k=140,S=80,I=80,_=new Map,j=new Map;y.forEach(ee=>{_.set(ee,0),j.set(ee,[])}),x.forEach(ee=>{y.has(ee.source)&&y.has(ee.target)&&(j.get(ee.source).push(ee.target),_.set(ee.target,(_.get(ee.target)||0)+1))});const O=new Map,A=[];for(_.forEach((ee,U)=>{ee===0&&(A.push(U),O.set(U,0))});A.length>0;){const ee=A.shift(),U=O.get(ee);for(const X of j.get(ee)||[]){const re=U+1;(!O.has(X)||O.get(X)<re)&&O.set(X,re),_.set(X,_.get(X)-1),_.get(X)===0&&A.push(X)}}E.forEach(ee=>{O.has(ee.id)||O.set(ee.id,0)});const H=new Map;E.forEach(ee=>{const U=O.get(ee.id);H.has(U)||H.set(U,[]),H.get(U).push(ee)});const q=[...H.keys()].sort((ee,U)=>ee-U),J=new Map;return q.forEach((ee,U)=>{H.get(ee).forEach((re,P)=>{J.set(re.id,{x:S+U*N,y:I+P*k})})}),E.map(ee=>{const U=J.get(ee.id)||{x:S,y:I};return{id:ee.id,type:"architecture",position:U,data:{label:ee.label,layer:ee.layer,nodeType:ee.type,width:ee.width,height:ee.height,path:ee.path,techStack:ee.techStack,description:ee.description},style:{width:ee.width,zIndex:1}}})},[r,y,x]);b.useEffect(()=>{if(!h)return;const E=setInterval(()=>{a(N=>{const k=N+1;if(k>=t.steps.length)return c(new Set([t.steps[0].edge])),0;const S=new Set;for(let I=0;I<=k;I++)S.add(t.steps[I].edge);return c(S),k})},_N);return()=>clearInterval(E)},[h,t]);const v=b.useMemo(()=>{const E=new Map;return t.steps.forEach((N,k)=>{E.has(N.edge)||E.set(N.edge,k+1)}),x.map(N=>{const k=u.has(N.id),S=E.get(N.id);return{id:N.id,source:N.source,target:N.target,label:k&&S?`${S}`:void 0,labelStyle:k&&S?{fill:"#fff",fontWeight:700,fontSize:13,fontFamily:"'JetBrains Mono', monospace",transform:"translateY(-22px)"}:void 0,labelBgStyle:k&&S?{fill:t.color,fillOpacity:.95,rx:10,ry:10,transform:"translateY(-22px)"}:void 0,labelBgPadding:[6,4],style:{stroke:k?t.color:N.color||"var(--border-color)",strokeWidth:k?5:2,opacity:k?1:.3,filter:k?"brightness(0.85) saturate(1.4)":void 0},animated:k,type:"smoothstep"}})},[x,u,t]);return f.jsx("div",{className:"flow-hud-overlay",children:f.jsxs(di,{className:"flow-hud-panel",children:[f.jsxs("div",{className:"flow-hud-header","data-drag-handle":!0,children:[f.jsxs("div",{className:"flow-hud-title",children:[f.jsx("span",{className:"flow-hud-dot",style:{background:t.color}}),f.jsx("span",{children:t.name})]}),f.jsxs("div",{className:"flow-hud-controls",children:[h?f.jsx("button",{className:"flow-hud-btn",onClick:()=>m(!1),title:"Pause",children:"⏸"}):f.jsx("button",{className:"flow-hud-btn",onClick:()=>m(!0),title:"Play",children:"▶"}),f.jsx("button",{className:"flow-hud-close",onClick:o,title:"Close",children:"✕"})]})]}),f.jsx("div",{className:"flow-hud-description",children:t.description}),f.jsx("div",{className:"flow-hud-canvas",children:f.jsxs(hg,{nodes:g,edges:v,nodeTypes:CN,fitView:!0,fitViewOptions:{padding:.3},nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,panOnDrag:!0,zoomOnScroll:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},children:[f.jsx(mg,{variant:Yn.Dots,gap:20,size:1,color:"var(--grid-color)"}),f.jsx(yg,{showInteractive:!1})]})}),f.jsx("div",{className:"flow-hud-steps",children:t.steps.map((E,N)=>f.jsxs("div",{className:`flow-hud-step ${N<=s?"active":""} ${N===s?"current":""}`,style:{borderColor:N<=s?t.color:void 0},children:[f.jsx("span",{className:"flow-hud-step-num",style:{background:N<=s?t.color:void 0},children:N+1}),E.label]},N))})]})})}function bN(t){return f.jsx(fg,{children:f.jsx(jN,{...t})})}const PN=b.memo(bN),MN=[{key:"anthropic",name:"Anthropic",icon:"A",models:"Claude 3.5 Sonnet, Claude 3 Opus",description:"Advanced reasoning and code analysis",requiresKey:!0},{key:"openai",name:"OpenAI",icon:"O",models:"GPT-4o, GPT-4 Turbo",description:"Versatile general-purpose models",requiresKey:!0},{key:"google",name:"Google",icon:"G",models:"Gemini 1.5 Pro, Gemini 1.5 Flash",description:"Fast multimodal analysis",requiresKey:!0},{key:"ollama",name:"Ollama",icon:"L",models:"Llama 3, CodeLlama, Mistral",description:"Local models, no API key needed",requiresKey:!1}];function IN({onComplete:t}){const[r,o]=b.useState(1),[s,a]=b.useState(null),[u,c]=b.useState(""),[h,m]=b.useState(!1),[y,x]=b.useState(null),g=N=>{a(N),c(""),x(null),N.requiresKey?o(2):o(3)},v=()=>{if(!u.trim()){x("API key is required");return}x(null),o(3)},C=async()=>{if(s){m(!0),x(null);try{const N={provider:s.key};s.requiresKey&&u.trim()&&(N.apiKey=u.trim());const k=await fetch("/api/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)});if(!k.ok){const S=await k.json();throw new Error(S.error||"Failed to save configuration")}t()}catch(N){x(N instanceof Error?N.message:"Failed to save configuration"),m(!1)}}},E=()=>{x(null),r===3&&(s!=null&&s.requiresKey)?o(2):r===3&&!(s!=null&&s.requiresKey)?o(1):(o(1),a(null),c(""))};return f.jsx("div",{style:Te.overlay,onClick:N=>N.stopPropagation(),children:f.jsxs("div",{style:Te.modal,children:[f.jsxs("div",{style:Te.header,children:[f.jsx("div",{style:Te.headerIcon,children:"⚙"}),f.jsx("h2",{style:Te.title,children:"Set Up Your AI Provider"}),f.jsx("p",{style:Te.subtitle,children:"ArchByte uses AI to analyze your codebase and generate architecture diagrams. Choose a provider to get started."})]}),f.jsx("div",{style:Te.stepIndicator,children:[1,2,3].map(N=>f.jsxs("div",{style:Te.stepRow,children:[f.jsx("div",{style:{...Te.stepDot,background:N<=r?"#7c3aed":"#3a3a4a",color:N<=r?"#fff":"#888"},children:N}),f.jsx("span",{style:{...Te.stepLabel,color:N<=r?"#ccc":"#666"},children:N===1?"Provider":N===2?"API Key":"Confirm"}),N<3&&f.jsx("div",{style:{...Te.stepLine,background:N<r?"#7c3aed":"#3a3a4a"}})]},N))}),r===1&&f.jsx("div",{style:Te.stepContent,children:f.jsx("div",{style:Te.providerGrid,children:MN.map(N=>f.jsxs("button",{style:{...Te.providerCard,borderColor:(s==null?void 0:s.key)===N.key?"#7c3aed":"#5a5a7a"},onClick:()=>g(N),onMouseEnter:k=>{k.currentTarget.style.borderColor="#7c3aed",k.currentTarget.style.background="#2a2a3e"},onMouseLeave:k=>{(s==null?void 0:s.key)!==N.key&&(k.currentTarget.style.borderColor="#5a5a7a"),k.currentTarget.style.background="#252536"},children:[f.jsx("div",{style:Te.providerIcon,children:N.icon}),f.jsx("div",{style:Te.providerName,children:N.name}),f.jsx("div",{style:Te.providerModels,children:N.models}),f.jsx("div",{style:Te.providerDesc,children:N.description}),!N.requiresKey&&f.jsx("div",{style:Te.noKeyBadge,children:"No API key needed"})]},N.key))})}),r===2&&s&&f.jsx("div",{style:Te.stepContent,children:f.jsxs("div",{style:Te.keySection,children:[f.jsxs("div",{style:Te.selectedProviderBadge,children:[f.jsx("span",{style:Te.providerIconSmall,children:s.icon}),f.jsx("span",{children:s.name})]}),f.jsx("label",{style:Te.label,children:"API Key"}),f.jsx("input",{type:"password",value:u,onChange:N=>{c(N.target.value),x(null)},placeholder:`Enter your ${s.name} API key`,style:Te.input,autoFocus:!0,onKeyDown:N=>{N.key==="Enter"&&v()}}),f.jsxs("p",{style:Te.keyHint,children:["Your key is stored locally in ",f.jsx("code",{style:Te.code,children:".archbyte/config.json"})," and never sent to external servers."]}),y&&f.jsx("div",{style:Te.error,children:y}),f.jsxs("div",{style:Te.buttonRow,children:[f.jsx("button",{style:Te.backBtn,onClick:E,children:"Back"}),f.jsx("button",{style:{...Te.primaryBtn,opacity:u.trim()?1:.5,cursor:u.trim()?"pointer":"not-allowed"},onClick:v,disabled:!u.trim(),children:"Continue"})]})]})}),r===3&&s&&f.jsx("div",{style:Te.stepContent,children:f.jsxs("div",{style:Te.confirmSection,children:[f.jsx("div",{style:Te.confirmIcon,children:"✓"}),f.jsx("h3",{style:Te.confirmTitle,children:"Ready to Analyze"}),f.jsxs("div",{style:Te.confirmDetails,children:[f.jsxs("div",{style:Te.confirmRow,children:[f.jsx("span",{style:Te.confirmLabel,children:"Provider"}),f.jsxs("span",{style:Te.confirmValue,children:[f.jsx("span",{style:Te.providerIconSmall,children:s.icon}),s.name]})]}),f.jsxs("div",{style:Te.confirmRow,children:[f.jsx("span",{style:Te.confirmLabel,children:"Models"}),f.jsx("span",{style:Te.confirmValue,children:s.models})]}),s.requiresKey&&f.jsxs("div",{style:Te.confirmRow,children:[f.jsx("span",{style:Te.confirmLabel,children:"API Key"}),f.jsxs("span",{style:Te.confirmValue,children:["*".repeat(Math.min(u.length,8)),"...",u.slice(-4)]})]})]}),y&&f.jsx("div",{style:Te.error,children:y}),f.jsxs("div",{style:Te.buttonRow,children:[f.jsx("button",{style:Te.backBtn,onClick:E,children:"Back"}),f.jsx("button",{style:{...Te.runBtn,opacity:h?.6:1,cursor:h?"wait":"pointer"},onClick:C,disabled:h,children:h?"Saving...":"Run First Analysis"})]})]})})]})})}const Te={overlay:{position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.7)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,backdropFilter:"blur(4px)"},modal:{background:"#1e1e2e",border:"1px solid #5a5a7a",borderRadius:16,padding:"36px 40px",maxWidth:600,width:"90vw",maxHeight:"90vh",overflowY:"auto"},header:{textAlign:"center",marginBottom:24},headerIcon:{fontSize:36,marginBottom:8,color:"#7c3aed"},title:{color:"#fff",margin:"0 0 8px",fontSize:22,fontWeight:700},subtitle:{color:"#999",margin:0,fontSize:14,lineHeight:1.5},stepIndicator:{display:"flex",alignItems:"center",justifyContent:"center",gap:0,marginBottom:28},stepRow:{display:"flex",alignItems:"center",gap:6},stepDot:{width:26,height:26,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:12,fontWeight:700,flexShrink:0},stepLabel:{fontSize:12,fontWeight:500},stepLine:{width:40,height:2,marginLeft:6,marginRight:6,borderRadius:1},stepContent:{minHeight:200},providerGrid:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:14},providerCard:{background:"#252536",border:"1px solid #5a5a7a",borderRadius:12,padding:"20px 16px",cursor:"pointer",textAlign:"left",transition:"border-color 0.15s, background 0.15s",display:"flex",flexDirection:"column",gap:6},providerIcon:{width:40,height:40,borderRadius:10,background:"#3a3a5a",display:"flex",alignItems:"center",justifyContent:"center",fontSize:20,fontWeight:800,color:"#7c3aed",marginBottom:4},providerName:{color:"#fff",fontSize:16,fontWeight:600},providerModels:{color:"#aaa",fontSize:12,lineHeight:1.4},providerDesc:{color:"#777",fontSize:11,lineHeight:1.4},noKeyBadge:{marginTop:4,fontSize:10,color:"#4ade80",fontWeight:600,textTransform:"uppercase",letterSpacing:.5},keySection:{display:"flex",flexDirection:"column",gap:14},selectedProviderBadge:{display:"inline-flex",alignItems:"center",gap:8,background:"#2a2a3e",border:"1px solid #5a5a7a",borderRadius:8,padding:"8px 14px",color:"#ccc",fontSize:14,fontWeight:500,alignSelf:"flex-start"},providerIconSmall:{width:22,height:22,borderRadius:6,background:"#3a3a5a",display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:12,fontWeight:800,color:"#7c3aed"},label:{color:"#ccc",fontSize:13,fontWeight:600},input:{width:"100%",padding:"12px 14px",background:"#161622",border:"1px solid #5a5a7a",borderRadius:8,color:"#fff",fontSize:14,outline:"none",fontFamily:"'JetBrains Mono', monospace",boxSizing:"border-box"},keyHint:{color:"#777",fontSize:12,margin:0,lineHeight:1.4},code:{background:"#2a2a3e",padding:"2px 6px",borderRadius:4,fontSize:11,color:"#aaa"},error:{color:"#f87171",fontSize:13,padding:"8px 12px",background:"rgba(248, 113, 113, 0.1)",border:"1px solid rgba(248, 113, 113, 0.3)",borderRadius:8},buttonRow:{display:"flex",justifyContent:"flex-end",gap:10,marginTop:8},backBtn:{padding:"10px 20px",background:"transparent",border:"1px solid #5a5a7a",borderRadius:8,color:"#aaa",fontSize:14,cursor:"pointer",fontWeight:500},primaryBtn:{padding:"10px 24px",background:"#7c3aed",border:"none",borderRadius:8,color:"#fff",fontSize:14,cursor:"pointer",fontWeight:600},confirmSection:{textAlign:"center",display:"flex",flexDirection:"column",alignItems:"center",gap:12},confirmIcon:{width:52,height:52,borderRadius:"50%",background:"rgba(124, 58, 237, 0.15)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:26,color:"#7c3aed"},confirmTitle:{color:"#fff",fontSize:18,fontWeight:600,margin:0},confirmDetails:{width:"100%",maxWidth:360,background:"#252536",border:"1px solid #5a5a7a",borderRadius:10,padding:"14px 18px",display:"flex",flexDirection:"column",gap:10,textAlign:"left"},confirmRow:{display:"flex",justifyContent:"space-between",alignItems:"center"},confirmLabel:{color:"#888",fontSize:13},confirmValue:{color:"#ddd",fontSize:13,fontWeight:500,display:"inline-flex",alignItems:"center",gap:6},runBtn:{padding:"12px 28px",background:"linear-gradient(135deg, #7c3aed, #6d28d9)",border:"none",borderRadius:8,color:"#fff",fontSize:15,cursor:"pointer",fontWeight:700,letterSpacing:.3}},TN={"security-audit":{label:"Security Audit",icon:"⚠",color:"var(--accent-red)"},compliance:{label:"Compliance",icon:"☑",color:"var(--accent-cyan)"},performance:{label:"Performance",icon:"⚡",color:"var(--accent-amber)"},"dependency-risk":{label:"Dependency Risk",icon:"⬢",color:"#c084fc"},migration:{label:"Migration Plan",icon:"→",color:"var(--accent-green)"},"api-contracts":{label:"API Contracts",icon:"↔",color:"#60a5fa"},"drift-detection":{label:"Drift Detection",icon:"◎",color:"#f472b6"}},Br={critical:0,high:1,medium:2,low:3};function ws({severity:t}){const r={critical:"var(--accent-red)",high:"hsl(25 95% 53%)",medium:"var(--accent-amber)",low:"var(--accent-green)"},o={critical:"hsl(0 90% 55% / 0.15)",high:"hsl(25 95% 53% / 0.15)",medium:"hsl(38 92% 50% / 0.15)",low:"hsl(142 76% 42% / 0.15)"},s={critical:"hsl(0 90% 55% / 0.3)",high:"hsl(25 95% 53% / 0.3)",medium:"hsl(38 92% 50% / 0.3)",low:"hsl(142 76% 42% / 0.3)"};return f.jsx("span",{style:{fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",padding:"1px 6px",borderRadius:3,color:r[t],background:o[t],border:`1px solid ${s[t]}`,whiteSpace:"nowrap"},children:t})}function RN({value:t}){const r=Math.round(t*100);return f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[f.jsx("div",{style:{flex:1,height:3,borderRadius:2,background:"var(--bg-hover)"},children:f.jsx("div",{style:{width:`${r}%`,height:"100%",borderRadius:2,background:r>=80?"var(--accent-green)":r>=50?"var(--accent-amber)":"var(--accent-red)"}})}),f.jsxs("span",{style:{fontSize:9,color:"var(--text-muted)",fontWeight:600,minWidth:28},children:[r,"%"]})]})}function zN({status:t}){const o={compliant:{color:"var(--accent-green)",bg:"hsl(142 76% 42% / 0.15)",border:"hsl(142 76% 42% / 0.3)"},partial:{color:"var(--accent-amber)",bg:"hsl(38 92% 50% / 0.15)",border:"hsl(38 92% 50% / 0.3)"},"non-compliant":{color:"var(--accent-red)",bg:"hsl(0 90% 55% / 0.15)",border:"hsl(0 90% 55% / 0.3)"}}[t];return f.jsx("span",{style:{fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",padding:"1px 6px",borderRadius:3,color:o.color,background:o.bg,border:`1px solid ${o.border}`},children:t})}function AN({status:t}){const o={completed:{color:"var(--accent-green)",bg:"hsl(142 76% 42% / 0.15)",border:"hsl(142 76% 42% / 0.3)"},"in-progress":{color:"var(--accent-amber)",bg:"hsl(38 92% 50% / 0.15)",border:"hsl(38 92% 50% / 0.3)"},pending:{color:"var(--text-muted)",bg:"var(--bg-tertiary)",border:"var(--border-color)"}}[t];return f.jsx("span",{style:{fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",padding:"1px 6px",borderRadius:3,color:o.color,background:o.bg,border:`1px solid ${o.border}`},children:t})}function LN({driftType:t}){const o={added:{color:"var(--accent-green)",bg:"hsl(142 76% 42% / 0.15)",border:"hsl(142 76% 42% / 0.3)"},removed:{color:"var(--accent-red)",bg:"hsl(0 90% 55% / 0.15)",border:"hsl(0 90% 55% / 0.3)"},modified:{color:"var(--accent-amber)",bg:"hsl(38 92% 50% / 0.15)",border:"hsl(38 92% 50% / 0.3)"}}[t];return f.jsx("span",{style:{fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",padding:"1px 6px",borderRadius:3,color:o.color,background:o.bg,border:`1px solid ${o.border}`},children:t})}function DN({data:t}){const r=[...t.findings].sort((o,s)=>Br[o.severity]-Br[s.severity]);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No findings"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.severity==="critical"?"var(--accent-red)":o.severity==="high"?"hsl(25 95% 53%)":o.severity==="medium"?"var(--accent-amber)":"var(--accent-green)"}`},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)",fontFamily:"'JetBrains Mono', monospace"},children:o.owaspId}),f.jsx(ws,{severity:o.severity})]}),f.jsx("div",{style:{fontSize:11,color:"var(--text-primary)",fontWeight:500,marginBottom:2},children:o.title}),f.jsx("div",{style:{fontSize:10,color:"var(--text-secondary)",lineHeight:1.4},children:o.description}),o.affectedComponent&&f.jsxs("div",{style:{fontSize:9,color:"var(--text-muted)",marginTop:4,fontFamily:"'JetBrains Mono', monospace"},children:["Component: ",o.affectedComponent]})]},s))})}function $N({data:t}){return t.statuses.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No compliance data"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.statuses.map((r,o)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6},children:[f.jsx("span",{style:{fontSize:12,fontWeight:600,color:"var(--text-primary)"},children:r.framework}),f.jsx(zN,{status:r.status})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[f.jsx("div",{style:{flex:1,height:4,borderRadius:2,background:"var(--bg-hover)"},children:f.jsx("div",{style:{width:r.controls>0?`${Math.round(r.passing/r.controls*100)}%`:"0%",height:"100%",borderRadius:2,background:r.status==="compliant"?"var(--accent-green)":r.status==="partial"?"var(--accent-amber)":"var(--accent-red)",transition:"width 0.3s"}})}),f.jsxs("span",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:500,minWidth:40,textAlign:"right"},children:[r.passing,"/",r.controls]})]}),r.findings.length>0&&f.jsx("div",{style:{marginTop:4},children:r.findings.map((s,a)=>f.jsxs("div",{style:{fontSize:10,color:"var(--text-secondary)",padding:"2px 0",lineHeight:1.4},children:["- ",s]},a))})]},o))})}function ON({data:t}){const r=[...t.bottlenecks].sort((o,s)=>Br[o.severity]-Br[s.severity]);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No bottlenecks detected"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.severity==="critical"?"var(--accent-red)":o.severity==="high"?"hsl(25 95% 53%)":o.severity==="medium"?"var(--accent-amber)":"var(--accent-green)"}`},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)",fontFamily:"'JetBrains Mono', monospace"},children:o.component}),f.jsx(ws,{severity:o.severity})]}),f.jsx("div",{style:{fontSize:11,color:"var(--text-primary)",fontWeight:500,marginBottom:2},children:o.metric}),f.jsx("div",{style:{fontSize:10,color:"var(--text-secondary)",lineHeight:1.4},children:o.description}),o.recommendation&&f.jsx("div",{style:{fontSize:10,color:"var(--accent-cyan)",marginTop:4,fontStyle:"italic"},children:o.recommendation})]},s))})}function FN({data:t}){const r=[...t.risks].sort((o,s)=>s.riskScore-o.riskScore);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No risks identified"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsxs("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-primary)",fontFamily:"'JetBrains Mono', monospace"},children:[o.package,f.jsxs("span",{style:{fontSize:9,color:"var(--text-muted)",marginLeft:4},children:["@",o.version]})]}),f.jsx(ws,{severity:o.severity})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[f.jsx("span",{style:{fontSize:9,color:"var(--text-muted)",fontWeight:600},children:"Risk"}),f.jsx("div",{style:{flex:1,height:4,borderRadius:2,background:"var(--bg-hover)"},children:f.jsx("div",{style:{width:`${o.riskScore}%`,height:"100%",borderRadius:2,background:o.riskScore>=75?"var(--accent-red)":o.riskScore>=50?"var(--accent-amber)":"var(--accent-green)",transition:"width 0.3s"}})}),f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)",minWidth:28},children:o.riskScore})]}),o.reasons.length>0&&f.jsx("div",{style:{marginTop:2},children:o.reasons.map((a,u)=>f.jsxs("div",{style:{fontSize:10,color:"var(--text-secondary)",padding:"1px 0",lineHeight:1.4},children:["- ",a]},u))})]},s))})}function HN({data:t}){const r=[...t.steps].sort((o,s)=>o.order-s.order);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No migration plan"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.status==="completed"?"var(--accent-green)":o.status==="in-progress"?"var(--accent-amber)":"var(--border-color)"}`,opacity:o.status==="completed"?.7:1},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsxs("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)"},children:["Step ",o.order]}),f.jsx(AN,{status:o.status})]}),f.jsx("div",{style:{fontSize:11,color:"var(--text-primary)",fontWeight:500,marginBottom:2},children:o.title}),f.jsx("div",{style:{fontSize:10,color:"var(--text-secondary)",lineHeight:1.4},children:o.description}),o.estimatedEffort&&f.jsxs("div",{style:{fontSize:9,color:"var(--text-muted)",marginTop:4,fontFamily:"'JetBrains Mono', monospace"},children:["Effort: ",o.estimatedEffort]})]},s))})}function VN({data:t}){const r=[...t.mismatches].sort((o,s)=>Br[o.severity]-Br[s.severity]);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No mismatches found"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.severity==="critical"?"var(--accent-red)":o.severity==="high"?"hsl(25 95% 53%)":o.severity==="medium"?"var(--accent-amber)":"var(--accent-green)"}`},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--accent-cyan)",fontFamily:"'JetBrains Mono', monospace"},children:o.endpoint}),f.jsx(ws,{severity:o.severity})]}),f.jsx("div",{style:{fontSize:11,color:"var(--text-primary)",fontWeight:500,marginBottom:4},children:o.field}),f.jsxs("div",{style:{display:"flex",gap:8,fontSize:10},children:[f.jsxs("div",{style:{flex:1},children:[f.jsx("div",{style:{color:"var(--text-muted)",fontSize:9,marginBottom:2},children:"Spec"}),f.jsx("div",{style:{color:"var(--accent-green)",fontFamily:"'JetBrains Mono', monospace",fontSize:10,padding:"3px 6px",background:"hsl(142 76% 42% / 0.08)",borderRadius:3},children:o.specValue})]}),f.jsxs("div",{style:{flex:1},children:[f.jsx("div",{style:{color:"var(--text-muted)",fontSize:9,marginBottom:2},children:"Impl"}),f.jsx("div",{style:{color:"var(--accent-red)",fontFamily:"'JetBrains Mono', monospace",fontSize:10,padding:"3px 6px",background:"hsl(0 90% 55% / 0.08)",borderRadius:3},children:o.implValue})]})]})]},s))})}function BN({data:t}){const r=[...t.detections].sort((o,s)=>Br[o.severity]-Br[s.severity]);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No drift detected"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.severity==="critical"?"var(--accent-red)":o.severity==="high"?"hsl(25 95% 53%)":o.severity==="medium"?"var(--accent-amber)":"var(--accent-green)"}`},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)",fontFamily:"'JetBrains Mono', monospace"},children:o.component}),f.jsxs("div",{style:{display:"flex",gap:4,alignItems:"center"},children:[f.jsx(LN,{driftType:o.driftType}),f.jsx(ws,{severity:o.severity})]})]}),f.jsx("div",{style:{fontSize:10,color:"var(--text-secondary)",lineHeight:1.4},children:o.description}),f.jsx("div",{style:{fontSize:9,color:"var(--text-muted)",marginTop:4,fontFamily:"'JetBrains Mono', monospace"},children:new Date(o.detectedAt).toLocaleString()})]},s))})}function WN({visible:t,onClose:r,results:o}){const[s,a]=b.useState(new Set),[u,c]=b.useState(!1),[h,m]=b.useState([]),y=b.useCallback(k=>{a(S=>{const I=new Set(S);return I.has(k)?I.delete(k):I.add(k),I})},[]),x=b.useCallback(async()=>{c(!0);try{const k=await fetch("/api/premium-agents/results");if(k.ok){const S=await k.json();Array.isArray(S)&&m(S)}}catch{}c(!1)},[]);b.useEffect(()=>{t&&x()},[t,x]);const g=o.length>0?o:h,v=new Map;g.forEach(k=>{v.set(k.agentId,k)});const C=["security-audit","compliance","performance","dependency-risk","migration","api-contracts","drift-detection"];function E(k){const S=k.data;switch(S.agentId){case"security-audit":return S.findings.length;case"compliance":return S.statuses.length;case"performance":return S.bottlenecks.length;case"dependency-risk":return S.risks.length;case"migration":return S.steps.length;case"api-contracts":return S.mismatches.length;case"drift-detection":return S.detections.length}}function N(k){const S=k.data;switch(S.agentId){case"security-audit":return f.jsx(DN,{data:S});case"compliance":return f.jsx($N,{data:S});case"performance":return f.jsx(ON,{data:S});case"dependency-risk":return f.jsx(FN,{data:S});case"migration":return f.jsx(HN,{data:S});case"api-contracts":return f.jsx(VN,{data:S});case"drift-detection":return f.jsx(BN,{data:S})}}return t?f.jsxs(di,{style:{position:"absolute",top:60,right:16,background:"var(--bg-secondary)",backdropFilter:"blur(12px)",borderRadius:12,border:"1px solid var(--border-color)",zIndex:10,width:320,maxHeight:"calc(100vh - 200px)",overflowY:"auto",boxShadow:"0 2px 12px var(--shadow-color)"},children:[f.jsxs("div",{"data-drag-handle":!0,style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 14px 8px",borderBottom:"1px solid var(--border-color)",cursor:"grab"},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"1px",color:"var(--text-muted)"},children:"Pro Agents"}),f.jsx("span",{style:{fontSize:9,fontWeight:600,padding:"1px 6px",borderRadius:3,background:"#7c3aed",color:"#fff"},children:"PRO"})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[f.jsx("button",{className:"panel-btn cyan small",onClick:x,disabled:u,children:u?"...":"Refresh"}),f.jsx("button",{className:"panel-close-btn",onClick:r,children:"x"})]})]}),f.jsx("div",{style:{padding:"8px 10px 12px"},children:u&&g.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,textAlign:"center",padding:20},children:"Loading agent results..."}):g.length===0?f.jsxs("div",{style:{color:"var(--text-muted)",fontSize:11,textAlign:"center",padding:20},children:["No premium agent results yet.",f.jsx("span",{style:{display:"block",marginTop:6,fontSize:10,color:"var(--accent-cyan)",opacity:.7,fontFamily:"'JetBrains Mono', monospace"},children:"Run agents to see results here"})]}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:C.map(k=>{const S=v.get(k);if(!S)return null;const I=TN[k],_=s.has(k),j=E(S);return f.jsxs("div",{style:{borderRadius:8,border:"1px solid var(--border-color)",overflow:"hidden"},children:[f.jsxs("div",{onClick:()=>y(k),style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"8px 10px",background:_?"var(--bg-tertiary)":"transparent",cursor:"pointer",transition:"background 0.15s",userSelect:"none"},onMouseEnter:O=>{_||(O.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:O=>{_||(O.currentTarget.style.background="transparent")},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx("span",{style:{fontSize:12},children:I.icon}),f.jsx("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-primary)"},children:I.label}),j>0&&f.jsx("span",{style:{fontSize:9,fontWeight:600,padding:"0px 5px",borderRadius:8,background:"var(--bg-hover)",color:"var(--text-secondary)"},children:j})]}),f.jsx("div",{style:{display:"flex",alignItems:"center",gap:6},children:f.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"'JetBrains Mono', monospace",transition:"transform 0.2s",transform:_?"rotate(90deg)":"rotate(0deg)",display:"inline-block"},children:"▶"})})]}),_&&f.jsxs("div",{style:{padding:"6px 10px 10px"},children:[f.jsxs("div",{style:{marginBottom:8},children:[f.jsx("div",{style:{fontSize:9,color:"var(--text-muted)",marginBottom:3,fontWeight:500},children:"Confidence"}),f.jsx(RN,{value:S.confidence})]}),N(S),f.jsx("div",{style:{fontSize:9,color:"var(--text-muted)",marginTop:8,textAlign:"right",fontFamily:"'JetBrains Mono', monospace"},children:new Date(S.timestamp).toLocaleString()})]})]},k)})})}),g.length>0&&f.jsxs("div",{style:{padding:"8px 14px",borderTop:"1px solid var(--border-color)",fontSize:10,color:"var(--text-muted)",textAlign:"center"},children:[g.length," of ",C.length," agents reporting"]})]}):null}const UN=b.memo(WN);function ti(t,r){return!t||t.length===0?!0:t.includes(r)}const YN=1500,XN={architecture:Pg};function GN(t,r,o){if(o)return t.map(g=>({id:g.id,type:"architecture",position:{x:g.x,y:g.y},data:{label:g.label,layer:g.layer,nodeType:g.type,width:g.width,height:g.height,path:g.path,techStack:g.techStack,description:g.description},style:{width:g.width,zIndex:1}}));const h=["presentation","application","data","external","deployment"],m={};t.forEach(g=>{const v=g.layer||"application";m[v]||(m[v]=[]),m[v].push(g)});const y=new Map;let x=100;return h.forEach(g=>{const v=m[g]||[];v.forEach((C,E)=>{y.set(C.id,{x:100+E*250,y:x})}),v.length>0&&(x+=180)}),Object.entries(m).forEach(([g,v])=>{h.includes(g)||(v.forEach((C,E)=>{y.set(C.id,{x:100+E*250,y:x})}),x+=180)}),t.map(g=>{const v=y.get(g.id)||{x:100,y:100};return{id:g.id,type:"architecture",position:v,data:{label:g.label,layer:g.layer,nodeType:g.type,width:g.width,height:g.height,path:g.path,techStack:g.techStack,description:g.description},style:{width:g.width,zIndex:1}}})}function Np(t,r="#64748b"){return t.map(o=>({id:o.id,source:o.source,target:o.target,label:o.label||void 0,labelStyle:o.label?{fill:"var(--text-secondary)",fontSize:10,fontWeight:500,fontFamily:"'JetBrains Mono', monospace"}:void 0,labelBgStyle:o.label?{fill:"var(--bg-secondary)",fillOpacity:.85,rx:4,ry:4}:void 0,labelBgPadding:[4,3],style:{stroke:o.color||r,strokeWidth:2,...o.style==="dashed"&&{strokeDasharray:"8 4"}},animated:o.animated||!1,type:"smoothstep",markerEnd:{type:us.ArrowClosed,width:16,height:16,color:o.color||r}}))}function KN(){var wn,Sn,kn;const[t,r,o]=Vk([]),[s,a,u]=Bk([]),[c,h]=b.useState(null),[m,y]=b.useState(!1),[x,g]=b.useState(null),[v]=b.useState([]),[C,E]=b.useState(!0),[N,k]=b.useState(null),[S,I]=b.useState({loggedIn:!1,email:null,tier:"free",features:{analyze:!0,validate:!1,patrol:!1,workflows:!1,chat:!1,premiumAgents:!1}}),[_,j]=b.useState(!1),[O,A]=b.useState(null),[H,q]=b.useState(!1),[J,ee]=b.useState(null),[,U]=b.useState(null),[X,re]=b.useState(null),[P,K]=b.useState(null),[V,G]=b.useState(-1),[R,z]=b.useState(!1),[B,M]=b.useState(new Set),[D,ie]=b.useState(!1),[oe,de]=b.useState(new Set),[he,me]=b.useState(new Set),[ne,pe]=b.useState(null),[be,_e]=b.useState("layer"),[Ce,Ee]=b.useState(!1),[ze,He]=b.useState(!1),[Ae,Ge]=b.useState(!1),[Ct,ft]=b.useState(!1),[yt,ht]=b.useState(!1),[hn,zn]=b.useState([]),[vt,An]=b.useState("develop"),[,Jt]=b.useState([]),[pn,Ln]=b.useState(),[Wr,en]=b.useState(null),[_t,fi]=b.useState(null),[mn,Vt]=b.useState(new Map),[Ur,pr]=b.useState(!1),tn=b.useRef([]),[Kn,Yr]=b.useState([]),Xr=50,[,nn]=b.useState([]),[,rn]=b.useState([]),[on,No]=b.useState(new Set),[jt,Gr]=b.useState(new Set),[ut,Kr]=b.useState(()=>{const $=localStorage.getItem("archbyte-theme");return $==="dark"||$==="light"?$:"light"});b.useEffect(()=>{document.documentElement.setAttribute("data-theme",ut),localStorage.setItem("archbyte-theme",ut)},[ut]);const[Qr,It]=b.useState(!1),[gn,Dn]=b.useState(""),[Qn,yn]=b.useState(new Set),[mr,vn]=b.useState(!1),[tt,hi]=b.useState(null),qn=ut==="dark"?"#64748b":"#94a3b8",Co="#fff",Bt=20,Tt=10,xn=b.useCallback(async()=>{try{await mi()}catch($){console.error("Failed to load architecture:",$),k("Failed to connect to server"),Ue()}finally{E(!1)}},[]),pi=async()=>{try{const $=await fetch("/api/tools-git");if($.ok){const W=await $.json();fi(W)}}catch{}},_o=async()=>{try{const $=await fetch("/api/config");if($.ok){const W=await $.json();if(U(W),W.environments){Ln(W.environments);const te=Object.keys(W.environments);te.length>0&&!te.includes(vt)&&An(te[0])}}}catch{}},jo=async()=>{try{const $=await fetch("/api/license");if($.ok){const W=await $.json();I(W),j(!0)}}catch{j(!0)}},bo=async()=>{try{const $=await fetch("/api/project");if($.ok){const W=await $.json();W&&re(W)}}catch{}},Po=async()=>{try{const $=await fetch("/api/analysis-status");if($.ok){const W=await $.json();(W==null?void 0:W.status)==="error"&&W.error?ee(W.error):ee(null)}}catch{}},mi=async()=>{const $="/events",W="/api/architecture";pi(),_o(),bo(),jo(),Po();try{const te=new EventSource($);return te.onopen=()=>{console.log("SSE connected"),y(!0),k(null)},te.onmessage=se=>{try{const ae=JSON.parse(se.data);console.log("SSE message:",ae.type),ae.architecture&&Zr(ae.architecture),ae.type==="git_update"&&ae.gitInfo&&Jt(ae.gitInfo),ae.type==="premium_agent_result"&&ae.premiumResults&&zn(ae.premiumResults)}catch(ae){console.error("Failed to parse SSE message:",ae)}},te.onerror=se=>{console.error("SSE error:",se),te.close(),y(!1),qr(W)},()=>te.close()}catch{qr(W)}},qr=async $=>{try{const W=await fetch($);if(W.ok){const te=await W.json();Zr(te),y(!0)}else Ue()}catch{Ue()}},Ue=()=>{const $={nodes:[{id:"frontend",type:"component",label:`Frontend
|
|
65
|
+
`),c=["arch-node",o.layer,o.active?"active":"",o.highlighted?"highlighted":"",o.locked?"locked":"",o.isConnected===!0?"connected":"",o.isConnected===!1?"dimmed":"",o.isSearchMatch===!0?"search-match":"",o.isSearchMatch===!1?"search-no-match":""].filter(Boolean).join(" "),h=uN[o.layer]||"#868e96",m=Ep[o.nodeType]||Ep.component;return f.jsxs(f.Fragment,{children:[f.jsx(mE,{color:h,isVisible:r,minWidth:100,minHeight:60}),f.jsxs("div",{className:c,style:{minWidth:o.width||130,width:"100%",height:"100%"},children:[f.jsx(Hr,{type:"target",position:Ne.Top}),f.jsx(Hr,{type:"target",position:Ne.Left}),f.jsx("div",{className:"node-type-icon",children:m}),f.jsxs("div",{className:"node-content",children:[f.jsx("div",{className:"label",children:a}),u&&f.jsx("div",{className:"sublabel",children:u}),o.description&&f.jsx("div",{className:"node-desc",children:o.description})]}),o.techStack&&o.techStack.length>0&&f.jsx("div",{className:"node-tech-row",children:o.techStack.slice(0,3).map((y,x)=>f.jsx("span",{className:"node-tech-pill",children:y},x))}),f.jsx(Hr,{type:"source",position:Ne.Bottom}),f.jsx(Hr,{type:"source",position:Ne.Right})]})]})}const Pg=b.memo(cN),dN={develop:"#2f9e44",development:"#2f9e44",dev:"#2f9e44",staging:"#e67700",stage:"#e67700",production:"#c92a2a",prod:"#c92a2a"};function fN({selectedEnvironment:t,environments:r,onSelectEnvironment:o}){if(!r||Object.keys(r).length===0)return null;const s=Object.keys(r);return f.jsx("div",{className:"environment-tabs",children:s.map(a=>{var y;const u=t===a,c=r==null?void 0:r[a],h=(c==null?void 0:c.color)||dN[a]||"#6b7280",m=(c==null?void 0:c.label)||a.charAt(0).toUpperCase()+a.slice(1);return f.jsxs("button",{className:`env-tab ${u?"selected":""}`,onClick:()=>o(a),style:{"--env-color":h},children:[f.jsx("span",{className:"env-indicator"}),f.jsx("span",{className:"env-label",children:m}),u&&c&&f.jsx("span",{className:"env-meta",children:[c.deployment,c.scaling,(y=c.urlPatterns||c.urls)==null?void 0:y[0]].filter(Boolean).join(" | ")})]},a)})})}const hN=b.memo(fN);function di({children:t,className:r,style:o}){const s=b.useRef(null),[a,u]=b.useState({x:0,y:0}),c=b.useRef(!1),h=b.useRef({x:0,y:0}),m=b.useRef({x:0,y:0}),y=b.useCallback(x=>{const g=x.target;if(!g.closest("[data-drag-handle]")||g.closest("button"))return;c.current=!0,h.current={x:x.clientX,y:x.clientY},m.current={...a},x.preventDefault();const C=N=>{c.current&&u({x:m.current.x+(N.clientX-h.current.x),y:m.current.y+(N.clientY-h.current.y)})},E=()=>{c.current=!1,document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",E)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",E)},[a]);return f.jsx("div",{ref:s,className:r,style:{...o,transform:`translate(${a.x}px, ${a.y}px)`},onMouseDown:y,children:t})}function pN(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function mN(t){return new Date(t).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function gN({visible:t,onClose:r}){const[o,s]=b.useState(null),a=b.useCallback(async()=>{try{const u=await fetch("/api/stats");u.ok&&s(await u.json())}catch{}},[]);return b.useEffect(()=>{t&&a()},[t,a]),!t||!o?null:f.jsxs(di,{className:"stats-overlay",children:[f.jsxs("div",{className:"stats-overlay-header","data-drag-handle":!0,children:[f.jsx("span",{className:"stats-overlay-title",children:"Architecture Stats"}),f.jsx("button",{className:"panel-close-btn",onClick:r,children:"x"})]}),(o.durationMs||o.filesScanned||o.analyzedAt)&&f.jsxs("div",{className:"stats-scan-info",children:[o.durationMs!=null&&f.jsx("span",{className:"scan-info-item",children:pN(o.durationMs)}),o.filesScanned!=null&&f.jsxs("span",{className:"scan-info-item",children:[o.filesScanned.toLocaleString()," files"]}),o.tokenUsage&&f.jsxs("span",{className:"scan-info-item",children:[(o.tokenUsage.input+o.tokenUsage.output).toLocaleString()," tokens"]}),o.analyzedAt&&f.jsx("span",{className:"scan-info-item",children:mN(o.analyzedAt)})]}),f.jsxs("div",{className:"stats-grid",children:[f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.components}),f.jsx("div",{className:"stat-label",children:"Components"})]}),f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.totalConnections}),f.jsx("div",{className:"stat-label",children:"Connections"})]}),f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.databases}),f.jsx("div",{className:"stat-label",children:"Databases"})]}),f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.externalServices}),f.jsx("div",{className:"stat-label",children:"External"})]}),f.jsxs("div",{className:`stat-card ${o.orphans>0?"highlight":""}`,children:[f.jsx("div",{className:"stat-value",children:o.orphans}),f.jsx("div",{className:"stat-label",children:"Orphans"})]}),f.jsxs("div",{className:"stat-card",children:[f.jsx("div",{className:"stat-value",children:o.flows}),f.jsx("div",{className:"stat-label",children:"Flows"})]})]})]})}const yN=b.memo(gN);function vN({visible:t,onClose:r,onHighlightNode:o}){const[s,a]=b.useState(null),[u,c]=b.useState(!1),h=b.useCallback(async()=>{c(!0);try{const m=await fetch("/api/validate");m.ok&&a(await m.json())}catch{}c(!1)},[]);return b.useEffect(()=>{t&&h()},[t,h]),!t||!s&&!u?null:f.jsxs(di,{className:"validation-panel",children:[f.jsxs("div",{className:"validation-header","data-drag-handle":!0,children:[f.jsx("span",{className:"validation-title",children:"Validation"}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx("button",{className:"panel-btn cyan small",onClick:h,disabled:u,children:u?"...":"Re-validate"}),s&&f.jsx("span",{className:`validation-badge ${s.passed?"pass":"fail"}`,children:s.passed?"PASS":"FAIL"}),f.jsx("button",{className:"panel-close-btn",onClick:r,children:"x"})]})]}),u&&!s?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,textAlign:"center",padding:12},children:"Validating..."}):s&&s.violations.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,textAlign:"center",padding:12},children:"No violations found"}):s?f.jsx("div",{children:s.violations.map((m,y)=>f.jsxs("div",{className:`violation-item ${m.level}`,onClick:()=>{m.nodeIds&&m.nodeIds.length>0&&o(m.nodeIds[0])},children:[f.jsx("div",{className:"violation-rule",children:m.rule}),f.jsx("div",{className:"violation-message",children:m.message})]},y))}):null,s&&f.jsxs("div",{style:{marginTop:8,fontSize:10,color:"var(--text-muted)",textAlign:"center"},children:[s.errors," error",s.errors!==1?"s":"",", ",s.warnings," warning",s.warnings!==1?"s":""]})]})}const xN=b.memo(vN);function wN({visible:t}){const[r,o]=b.useState(null),[s,a]=b.useState([]),[u,c]=b.useState(!0),[h,m]=b.useState(!1),y=b.useCallback(async()=>{try{const[k,S]=await Promise.all([fetch("/api/patrol/latest"),fetch("/api/patrol/history")]);k.ok&&o(await k.json()),S.ok&&a(await S.json())}catch{}c(!1)},[]),x=b.useCallback(async()=>{try{const k=await fetch("/api/patrol/running");if(k.ok){const S=await k.json();m(S.running)}}catch{}},[]);b.useEffect(()=>{if(t){y(),x();const k=setInterval(y,h?5e3:1e4),S=setInterval(x,5e3);return()=>{clearInterval(k),clearInterval(S)}}},[t,y,x,h]);const g=async()=>{try{(await fetch("/api/patrol/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({interval:30})})).ok&&m(!0)}catch{}},v=async()=>{try{(await fetch("/api/patrol/stop",{method:"POST"})).ok&&m(!1)}catch{}};if(!t)return null;if(u)return f.jsx("div",{className:"ops-section",children:f.jsx("div",{className:"ops-empty",children:"Loading..."})});if(!r&&s.length===0)return f.jsxs("div",{className:"ops-section",children:[f.jsxs("div",{className:"ops-empty",children:["No patrol data yet.",f.jsx("span",{className:"ops-hint",children:"Start patrol to begin monitoring"})]}),f.jsx("div",{className:"patrol-actions",children:f.jsx("button",{className:"panel-btn green",onClick:g,disabled:h,children:h?"Running...":"Start Patrol"})})]});const C=s.slice(-20),E=C.filter(k=>k.passed).length,N=C.length>0?Math.round(E/C.length*100):0;return f.jsxs("div",{className:"ops-section",children:[f.jsx("div",{className:"patrol-actions",children:h?f.jsx("button",{className:"panel-btn red",onClick:v,children:"Stop Patrol"}):f.jsx("button",{className:"panel-btn green",onClick:g,children:"Start Patrol"})}),C.length>0&&f.jsxs("div",{className:"patrol-sparkline-row",children:[f.jsx("div",{className:"patrol-sparkline",children:C.map((k,S)=>f.jsx("div",{className:`spark-dot ${k.passed?"healthy":"violation"}`,title:`${new Date(k.timestamp).toLocaleTimeString()} — ${k.passed?"Healthy":"Violation"}`},S))}),f.jsxs("span",{className:"patrol-health-pct",children:[N,"%"]})]}),r&&f.jsxs("div",{className:`patrol-status-card ${r.passed?"healthy":"violation"}`,children:[f.jsxs("div",{className:"patrol-status-row",children:[f.jsx("span",{className:`patrol-badge ${r.passed?"healthy":"violation"}`,children:r.passed?"HEALTHY":"VIOLATION"}),f.jsx("span",{className:"patrol-time",children:new Date(r.timestamp).toLocaleTimeString()})]}),f.jsxs("div",{className:"patrol-counts",children:[r.errors>0&&f.jsxs("span",{className:"patrol-count error",children:[r.errors," err"]}),r.warnings>0&&f.jsxs("span",{className:"patrol-count warn",children:[r.warnings," warn"]}),r.errors===0&&r.warnings===0&&f.jsx("span",{className:"patrol-count ok",children:"All clear"})]})]}),r&&r.newViolations.length>0&&f.jsxs("div",{className:"patrol-violations",children:[f.jsx("div",{className:"patrol-violations-label",children:"New violations"}),r.newViolations.slice(0,5).map((k,S)=>f.jsxs("div",{className:`patrol-violation-item ${k.level}`,children:[f.jsx("span",{className:"patrol-v-rule",children:k.rule}),f.jsx("span",{className:"patrol-v-msg",children:k.message})]},S))]}),r&&r.resolvedViolations.length>0&&f.jsxs("div",{className:"patrol-violations resolved",children:[f.jsx("div",{className:"patrol-violations-label",children:"Resolved"}),r.resolvedViolations.slice(0,3).map((k,S)=>f.jsxs("div",{className:"patrol-violation-item resolved",children:[f.jsx("span",{className:"patrol-v-rule",children:k.rule}),f.jsx("span",{className:"patrol-v-msg",children:k.message})]},S))]}),f.jsxs("div",{className:"patrol-summary",children:[s.length," patrols total"]})]})}const SN=b.memo(wN);function kN({visible:t}){const[r,o]=b.useState([]),[s,a]=b.useState(null),[u,c]=b.useState(null),[h,m]=b.useState(!0),[y,x]=b.useState(null),[g,v]=b.useState(null),C=b.useRef(null),E=b.useCallback(async()=>{try{const I=await fetch("/api/workflow/list");I.ok&&o(await I.json())}catch{}m(!1)},[]),N=b.useCallback(async I=>{try{const _=await fetch(`/api/workflow/status/${I}`);if(_.ok){const j=await _.json();c(j),j&&y===I&&(j.status==="completed"||j.status==="failed")&&(x(null),E())}}catch{}},[y,E]);b.useEffect(()=>{if(t){E();const I=setInterval(E,y?3e3:1e4);return()=>clearInterval(I)}},[t,E,y]),b.useEffect(()=>(C.current&&clearInterval(C.current),s&&(N(s),C.current=setInterval(()=>N(s),y?3e3:1e4)),()=>{C.current&&clearInterval(C.current)}),[s,N,y]);const k=async I=>{v(null);try{const _=await fetch(`/api/workflow/run/${I}`,{method:"POST"});if(_.ok)x(I);else{const j=await _.json();v(j.error||"Failed to start workflow")}}catch{v("Failed to connect to server")}},S=async I=>{v(null);try{(await fetch("/api/workflow/reset",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:I})})).ok&&(c(null),E())}catch{}};return t?h?f.jsx("div",{className:"ops-section",children:f.jsx("div",{className:"ops-empty",children:"Loading..."})}):r.length===0?f.jsx("div",{className:"ops-section",children:f.jsxs("div",{className:"ops-empty",children:["No workflows available.",f.jsx("span",{className:"ops-hint",children:"Run: archbyte workflow --list"})]})}):f.jsxs("div",{className:"ops-section",children:[g&&f.jsx("div",{className:"wf-error",children:g}),r.map(I=>{const _=s===I.id,j=y===I.id;return f.jsxs("div",{className:"wf-item",children:[f.jsxs("div",{className:"wf-header",onClick:()=>a(_?null:I.id),children:[f.jsxs("div",{className:"wf-header-left",children:[f.jsx("span",{className:"wf-expand",children:_?"−":"+"}),f.jsx("span",{className:"wf-name",children:I.name}),I.builtin&&f.jsx("span",{className:"wf-tag",children:"built-in"})]}),(j||I.status)&&f.jsx("span",{className:`wf-status ${j?"running":I.status}`,children:j?"running":I.status==="completed"?"done":I.status})]}),_&&f.jsxs("div",{className:"wf-detail",children:[f.jsx("div",{className:"wf-desc",children:I.description}),u&&u.workflowId===I.id?f.jsxs("div",{className:"wf-steps",children:[Object.entries(u.steps).map(([O,A])=>f.jsxs("div",{className:`wf-step ${A.status}`,children:[f.jsx("span",{className:"wf-step-icon",children:A.status==="completed"?"✓":A.status==="running"?"▶":A.status==="failed"?"✗":"○"}),f.jsx("span",{className:"wf-step-id",children:O})]},O)),(()=>{const O=Object.keys(u.steps).length,A=Object.values(u.steps).filter(q=>q.status==="completed").length,H=O>0?Math.round(A/O*100):0;return f.jsxs("div",{className:"wf-progress",children:[f.jsx("div",{className:"wf-progress-bar",children:f.jsx("div",{className:"wf-progress-fill",style:{width:`${H}%`}})}),f.jsxs("span",{className:"wf-progress-label",children:[H,"%"]})]})})()]}):f.jsx("div",{className:"wf-steps-preview",children:I.steps.length>0?I.steps.join(" → "):"No state yet"}),f.jsxs("div",{className:"wf-actions",children:[f.jsx("button",{className:"panel-btn cyan",disabled:j,onClick:()=>k(I.id),children:j?"Running...":"Run"}),(I.status==="completed"||I.status==="failed")&&!j&&f.jsx("button",{className:"panel-btn amber",onClick:()=>S(I.id),children:"Reset"})]})]})]},I.id)})]}):null}const EN=b.memo(kN);function NN({projectInfo:t}){const[r,o]=b.useState(!1),s=b.useRef(null);return b.useEffect(()=>{if(!r)return;const a=u=>{s.current&&!s.current.contains(u.target)&&o(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[r]),t?f.jsxs("div",{className:"project-info-wrapper",ref:s,children:[f.jsx("button",{className:"project-info-trigger",onClick:()=>o(!r),children:t.name}),r&&f.jsxs("div",{className:"project-info-popup",children:[f.jsxs("div",{className:"project-info-header",children:[f.jsx("span",{className:"project-info-name",children:t.name}),t.primaryLanguage&&f.jsx("span",{className:"project-info-lang",children:t.primaryLanguage})]}),t.description&&f.jsx("p",{className:"project-info-desc",children:t.description}),t.isMonorepo&&f.jsx("div",{className:"project-info-badge",children:"Monorepo"}),t.workspacePath&&f.jsxs("a",{className:"project-info-vscode",href:`vscode://file${t.workspacePath}`,title:"Open folder in VS Code",children:[f.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M17.583 2.214L12.52 6.768 7.84 3.96 2.4 5.88v12.24l5.44 1.92 4.68-2.808 5.063 4.554L21.6 19.8V4.2l-4.017-1.986zM7.84 15.12V8.88l4.68 3.12-4.68 3.12zm9.743 2.544l-3.96-3.564 3.96-3.564v7.128z"})}),"Open in VS Code"]})]})]}):null}const CN={architecture:Pg},_N=1500;function jN({flow:t,architecture:r,onClose:o}){var C;const[s,a]=b.useState(0),[u,c]=b.useState(new Set([(C=t.steps[0])==null?void 0:C.edge])),[h,m]=b.useState(!0),{flowNodeIds:y,flowEdges:x}=b.useMemo(()=>{const E=new Set(t.steps.map(S=>S.edge)),N=r.edges.filter(S=>E.has(S.id)),k=new Set;return N.forEach(S=>{k.add(S.source),k.add(S.target)}),{flowNodeIds:k,flowEdges:N}},[t,r]),g=b.useMemo(()=>{const E=r.nodes.filter(ee=>y.has(ee.id)),N=320,k=140,S=80,I=80,_=new Map,j=new Map;y.forEach(ee=>{_.set(ee,0),j.set(ee,[])}),x.forEach(ee=>{y.has(ee.source)&&y.has(ee.target)&&(j.get(ee.source).push(ee.target),_.set(ee.target,(_.get(ee.target)||0)+1))});const O=new Map,A=[];for(_.forEach((ee,U)=>{ee===0&&(A.push(U),O.set(U,0))});A.length>0;){const ee=A.shift(),U=O.get(ee);for(const X of j.get(ee)||[]){const re=U+1;(!O.has(X)||O.get(X)<re)&&O.set(X,re),_.set(X,_.get(X)-1),_.get(X)===0&&A.push(X)}}E.forEach(ee=>{O.has(ee.id)||O.set(ee.id,0)});const H=new Map;E.forEach(ee=>{const U=O.get(ee.id);H.has(U)||H.set(U,[]),H.get(U).push(ee)});const q=[...H.keys()].sort((ee,U)=>ee-U),J=new Map;return q.forEach((ee,U)=>{H.get(ee).forEach((re,P)=>{J.set(re.id,{x:S+U*N,y:I+P*k})})}),E.map(ee=>{const U=J.get(ee.id)||{x:S,y:I};return{id:ee.id,type:"architecture",position:U,data:{label:ee.label,layer:ee.layer,nodeType:ee.type,width:ee.width,height:ee.height,path:ee.path,techStack:ee.techStack,description:ee.description},style:{width:ee.width,zIndex:1}}})},[r,y,x]);b.useEffect(()=>{if(!h)return;const E=setInterval(()=>{a(N=>{const k=N+1;if(k>=t.steps.length)return c(new Set([t.steps[0].edge])),0;const S=new Set;for(let I=0;I<=k;I++)S.add(t.steps[I].edge);return c(S),k})},_N);return()=>clearInterval(E)},[h,t]);const v=b.useMemo(()=>{const E=new Map;return t.steps.forEach((N,k)=>{E.has(N.edge)||E.set(N.edge,k+1)}),x.map(N=>{const k=u.has(N.id),S=E.get(N.id);return{id:N.id,source:N.source,target:N.target,label:k&&S?`${S}`:void 0,labelStyle:k&&S?{fill:"#fff",fontWeight:700,fontSize:13,fontFamily:"'JetBrains Mono', monospace",transform:"translateY(-22px)"}:void 0,labelBgStyle:k&&S?{fill:t.color,fillOpacity:.95,rx:10,ry:10,transform:"translateY(-22px)"}:void 0,labelBgPadding:[6,4],style:{stroke:k?t.color:N.color||"var(--border-color)",strokeWidth:k?5:2,opacity:k?1:.3,filter:k?"brightness(0.85) saturate(1.4)":void 0},animated:k,type:"smoothstep"}})},[x,u,t]);return f.jsx("div",{className:"flow-hud-overlay",children:f.jsxs(di,{className:"flow-hud-panel",children:[f.jsxs("div",{className:"flow-hud-header","data-drag-handle":!0,children:[f.jsxs("div",{className:"flow-hud-title",children:[f.jsx("span",{className:"flow-hud-dot",style:{background:t.color}}),f.jsx("span",{children:t.name})]}),f.jsxs("div",{className:"flow-hud-controls",children:[h?f.jsx("button",{className:"flow-hud-btn",onClick:()=>m(!1),title:"Pause",children:"⏸"}):f.jsx("button",{className:"flow-hud-btn",onClick:()=>m(!0),title:"Play",children:"▶"}),f.jsx("button",{className:"flow-hud-close",onClick:o,title:"Close",children:"✕"})]})]}),f.jsx("div",{className:"flow-hud-description",children:t.description}),f.jsx("div",{className:"flow-hud-canvas",children:f.jsxs(hg,{nodes:g,edges:v,nodeTypes:CN,fitView:!0,fitViewOptions:{padding:.3},nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,panOnDrag:!0,zoomOnScroll:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},children:[f.jsx(mg,{variant:Yn.Dots,gap:20,size:1,color:"var(--grid-color)"}),f.jsx(yg,{showInteractive:!1})]})}),f.jsx("div",{className:"flow-hud-steps",children:t.steps.map((E,N)=>f.jsxs("div",{className:`flow-hud-step ${N<=s?"active":""} ${N===s?"current":""}`,style:{borderColor:N<=s?t.color:void 0},children:[f.jsx("span",{className:"flow-hud-step-num",style:{background:N<=s?t.color:void 0},children:N+1}),E.label]},N))})]})})}function bN(t){return f.jsx(fg,{children:f.jsx(jN,{...t})})}const PN=b.memo(bN),MN=[{key:"anthropic",name:"Anthropic",icon:"A",models:"Claude 3.5 Sonnet, Claude 3 Opus",description:"Advanced reasoning and code analysis",requiresKey:!0},{key:"openai",name:"OpenAI",icon:"O",models:"GPT-4o, GPT-4 Turbo",description:"Versatile general-purpose models",requiresKey:!0},{key:"google",name:"Google",icon:"G",models:"Gemini 1.5 Pro, Gemini 1.5 Flash",description:"Fast multimodal analysis",requiresKey:!0}];function IN({onComplete:t}){const[r,o]=b.useState(1),[s,a]=b.useState(null),[u,c]=b.useState(""),[h,m]=b.useState(!1),[y,x]=b.useState(null),g=N=>{a(N),c(""),x(null),N.requiresKey?o(2):o(3)},v=()=>{if(!u.trim()){x("API key is required");return}x(null),o(3)},C=async()=>{if(s){m(!0),x(null);try{const N={provider:s.key};s.requiresKey&&u.trim()&&(N.apiKey=u.trim());const k=await fetch("/api/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)});if(!k.ok){const S=await k.json();throw new Error(S.error||"Failed to save configuration")}t()}catch(N){x(N instanceof Error?N.message:"Failed to save configuration"),m(!1)}}},E=()=>{x(null),r===3&&(s!=null&&s.requiresKey)?o(2):r===3&&!(s!=null&&s.requiresKey)?o(1):(o(1),a(null),c(""))};return f.jsx("div",{style:Te.overlay,onClick:N=>N.stopPropagation(),children:f.jsxs("div",{style:Te.modal,children:[f.jsxs("div",{style:Te.header,children:[f.jsx("div",{style:Te.headerIcon,children:"⚙"}),f.jsx("h2",{style:Te.title,children:"Set Up Your AI Provider"}),f.jsx("p",{style:Te.subtitle,children:"ArchByte uses AI to analyze your codebase and generate architecture diagrams. Choose a provider to get started."})]}),f.jsx("div",{style:Te.stepIndicator,children:[1,2,3].map(N=>f.jsxs("div",{style:Te.stepRow,children:[f.jsx("div",{style:{...Te.stepDot,background:N<=r?"#7c3aed":"#3a3a4a",color:N<=r?"#fff":"#888"},children:N}),f.jsx("span",{style:{...Te.stepLabel,color:N<=r?"#ccc":"#666"},children:N===1?"Provider":N===2?"API Key":"Confirm"}),N<3&&f.jsx("div",{style:{...Te.stepLine,background:N<r?"#7c3aed":"#3a3a4a"}})]},N))}),r===1&&f.jsx("div",{style:Te.stepContent,children:f.jsx("div",{style:Te.providerGrid,children:MN.map(N=>f.jsxs("button",{style:{...Te.providerCard,borderColor:(s==null?void 0:s.key)===N.key?"#7c3aed":"#5a5a7a"},onClick:()=>g(N),onMouseEnter:k=>{k.currentTarget.style.borderColor="#7c3aed",k.currentTarget.style.background="#2a2a3e"},onMouseLeave:k=>{(s==null?void 0:s.key)!==N.key&&(k.currentTarget.style.borderColor="#5a5a7a"),k.currentTarget.style.background="#252536"},children:[f.jsx("div",{style:Te.providerIcon,children:N.icon}),f.jsx("div",{style:Te.providerName,children:N.name}),f.jsx("div",{style:Te.providerModels,children:N.models}),f.jsx("div",{style:Te.providerDesc,children:N.description}),!N.requiresKey&&f.jsx("div",{style:Te.noKeyBadge,children:"No API key needed"})]},N.key))})}),r===2&&s&&f.jsx("div",{style:Te.stepContent,children:f.jsxs("div",{style:Te.keySection,children:[f.jsxs("div",{style:Te.selectedProviderBadge,children:[f.jsx("span",{style:Te.providerIconSmall,children:s.icon}),f.jsx("span",{children:s.name})]}),f.jsx("label",{style:Te.label,children:"API Key"}),f.jsx("input",{type:"password",value:u,onChange:N=>{c(N.target.value),x(null)},placeholder:`Enter your ${s.name} API key`,style:Te.input,autoFocus:!0,onKeyDown:N=>{N.key==="Enter"&&v()}}),f.jsxs("p",{style:Te.keyHint,children:["Your key is stored locally in ",f.jsx("code",{style:Te.code,children:".archbyte/config.json"})," and never sent to external servers."]}),y&&f.jsx("div",{style:Te.error,children:y}),f.jsxs("div",{style:Te.buttonRow,children:[f.jsx("button",{style:Te.backBtn,onClick:E,children:"Back"}),f.jsx("button",{style:{...Te.primaryBtn,opacity:u.trim()?1:.5,cursor:u.trim()?"pointer":"not-allowed"},onClick:v,disabled:!u.trim(),children:"Continue"})]})]})}),r===3&&s&&f.jsx("div",{style:Te.stepContent,children:f.jsxs("div",{style:Te.confirmSection,children:[f.jsx("div",{style:Te.confirmIcon,children:"✓"}),f.jsx("h3",{style:Te.confirmTitle,children:"Ready to Analyze"}),f.jsxs("div",{style:Te.confirmDetails,children:[f.jsxs("div",{style:Te.confirmRow,children:[f.jsx("span",{style:Te.confirmLabel,children:"Provider"}),f.jsxs("span",{style:Te.confirmValue,children:[f.jsx("span",{style:Te.providerIconSmall,children:s.icon}),s.name]})]}),f.jsxs("div",{style:Te.confirmRow,children:[f.jsx("span",{style:Te.confirmLabel,children:"Models"}),f.jsx("span",{style:Te.confirmValue,children:s.models})]}),s.requiresKey&&f.jsxs("div",{style:Te.confirmRow,children:[f.jsx("span",{style:Te.confirmLabel,children:"API Key"}),f.jsxs("span",{style:Te.confirmValue,children:["*".repeat(Math.min(u.length,8)),"...",u.slice(-4)]})]})]}),y&&f.jsx("div",{style:Te.error,children:y}),f.jsxs("div",{style:Te.buttonRow,children:[f.jsx("button",{style:Te.backBtn,onClick:E,children:"Back"}),f.jsx("button",{style:{...Te.runBtn,opacity:h?.6:1,cursor:h?"wait":"pointer"},onClick:C,disabled:h,children:h?"Saving...":"Run First Analysis"})]})]})})]})})}const Te={overlay:{position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.7)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,backdropFilter:"blur(4px)"},modal:{background:"#1e1e2e",border:"1px solid #5a5a7a",borderRadius:16,padding:"36px 40px",maxWidth:600,width:"90vw",maxHeight:"90vh",overflowY:"auto"},header:{textAlign:"center",marginBottom:24},headerIcon:{fontSize:36,marginBottom:8,color:"#7c3aed"},title:{color:"#fff",margin:"0 0 8px",fontSize:22,fontWeight:700},subtitle:{color:"#999",margin:0,fontSize:14,lineHeight:1.5},stepIndicator:{display:"flex",alignItems:"center",justifyContent:"center",gap:0,marginBottom:28},stepRow:{display:"flex",alignItems:"center",gap:6},stepDot:{width:26,height:26,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:12,fontWeight:700,flexShrink:0},stepLabel:{fontSize:12,fontWeight:500},stepLine:{width:40,height:2,marginLeft:6,marginRight:6,borderRadius:1},stepContent:{minHeight:200},providerGrid:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:14},providerCard:{background:"#252536",border:"1px solid #5a5a7a",borderRadius:12,padding:"20px 16px",cursor:"pointer",textAlign:"left",transition:"border-color 0.15s, background 0.15s",display:"flex",flexDirection:"column",gap:6},providerIcon:{width:40,height:40,borderRadius:10,background:"#3a3a5a",display:"flex",alignItems:"center",justifyContent:"center",fontSize:20,fontWeight:800,color:"#7c3aed",marginBottom:4},providerName:{color:"#fff",fontSize:16,fontWeight:600},providerModels:{color:"#aaa",fontSize:12,lineHeight:1.4},providerDesc:{color:"#777",fontSize:11,lineHeight:1.4},noKeyBadge:{marginTop:4,fontSize:10,color:"#4ade80",fontWeight:600,textTransform:"uppercase",letterSpacing:.5},keySection:{display:"flex",flexDirection:"column",gap:14},selectedProviderBadge:{display:"inline-flex",alignItems:"center",gap:8,background:"#2a2a3e",border:"1px solid #5a5a7a",borderRadius:8,padding:"8px 14px",color:"#ccc",fontSize:14,fontWeight:500,alignSelf:"flex-start"},providerIconSmall:{width:22,height:22,borderRadius:6,background:"#3a3a5a",display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:12,fontWeight:800,color:"#7c3aed"},label:{color:"#ccc",fontSize:13,fontWeight:600},input:{width:"100%",padding:"12px 14px",background:"#161622",border:"1px solid #5a5a7a",borderRadius:8,color:"#fff",fontSize:14,outline:"none",fontFamily:"'JetBrains Mono', monospace",boxSizing:"border-box"},keyHint:{color:"#777",fontSize:12,margin:0,lineHeight:1.4},code:{background:"#2a2a3e",padding:"2px 6px",borderRadius:4,fontSize:11,color:"#aaa"},error:{color:"#f87171",fontSize:13,padding:"8px 12px",background:"rgba(248, 113, 113, 0.1)",border:"1px solid rgba(248, 113, 113, 0.3)",borderRadius:8},buttonRow:{display:"flex",justifyContent:"flex-end",gap:10,marginTop:8},backBtn:{padding:"10px 20px",background:"transparent",border:"1px solid #5a5a7a",borderRadius:8,color:"#aaa",fontSize:14,cursor:"pointer",fontWeight:500},primaryBtn:{padding:"10px 24px",background:"#7c3aed",border:"none",borderRadius:8,color:"#fff",fontSize:14,cursor:"pointer",fontWeight:600},confirmSection:{textAlign:"center",display:"flex",flexDirection:"column",alignItems:"center",gap:12},confirmIcon:{width:52,height:52,borderRadius:"50%",background:"rgba(124, 58, 237, 0.15)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:26,color:"#7c3aed"},confirmTitle:{color:"#fff",fontSize:18,fontWeight:600,margin:0},confirmDetails:{width:"100%",maxWidth:360,background:"#252536",border:"1px solid #5a5a7a",borderRadius:10,padding:"14px 18px",display:"flex",flexDirection:"column",gap:10,textAlign:"left"},confirmRow:{display:"flex",justifyContent:"space-between",alignItems:"center"},confirmLabel:{color:"#888",fontSize:13},confirmValue:{color:"#ddd",fontSize:13,fontWeight:500,display:"inline-flex",alignItems:"center",gap:6},runBtn:{padding:"12px 28px",background:"linear-gradient(135deg, #7c3aed, #6d28d9)",border:"none",borderRadius:8,color:"#fff",fontSize:15,cursor:"pointer",fontWeight:700,letterSpacing:.3}},TN={"security-audit":{label:"Security Audit",icon:"⚠",color:"var(--accent-red)"},compliance:{label:"Compliance",icon:"☑",color:"var(--accent-cyan)"},performance:{label:"Performance",icon:"⚡",color:"var(--accent-amber)"},"dependency-risk":{label:"Dependency Risk",icon:"⬢",color:"#c084fc"},migration:{label:"Migration Plan",icon:"→",color:"var(--accent-green)"},"api-contracts":{label:"API Contracts",icon:"↔",color:"#60a5fa"},"drift-detection":{label:"Drift Detection",icon:"◎",color:"#f472b6"}},Br={critical:0,high:1,medium:2,low:3};function ws({severity:t}){const r={critical:"var(--accent-red)",high:"hsl(25 95% 53%)",medium:"var(--accent-amber)",low:"var(--accent-green)"},o={critical:"hsl(0 90% 55% / 0.15)",high:"hsl(25 95% 53% / 0.15)",medium:"hsl(38 92% 50% / 0.15)",low:"hsl(142 76% 42% / 0.15)"},s={critical:"hsl(0 90% 55% / 0.3)",high:"hsl(25 95% 53% / 0.3)",medium:"hsl(38 92% 50% / 0.3)",low:"hsl(142 76% 42% / 0.3)"};return f.jsx("span",{style:{fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",padding:"1px 6px",borderRadius:3,color:r[t],background:o[t],border:`1px solid ${s[t]}`,whiteSpace:"nowrap"},children:t})}function RN({value:t}){const r=Math.round(t*100);return f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[f.jsx("div",{style:{flex:1,height:3,borderRadius:2,background:"var(--bg-hover)"},children:f.jsx("div",{style:{width:`${r}%`,height:"100%",borderRadius:2,background:r>=80?"var(--accent-green)":r>=50?"var(--accent-amber)":"var(--accent-red)"}})}),f.jsxs("span",{style:{fontSize:9,color:"var(--text-muted)",fontWeight:600,minWidth:28},children:[r,"%"]})]})}function zN({status:t}){const o={compliant:{color:"var(--accent-green)",bg:"hsl(142 76% 42% / 0.15)",border:"hsl(142 76% 42% / 0.3)"},partial:{color:"var(--accent-amber)",bg:"hsl(38 92% 50% / 0.15)",border:"hsl(38 92% 50% / 0.3)"},"non-compliant":{color:"var(--accent-red)",bg:"hsl(0 90% 55% / 0.15)",border:"hsl(0 90% 55% / 0.3)"}}[t];return f.jsx("span",{style:{fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",padding:"1px 6px",borderRadius:3,color:o.color,background:o.bg,border:`1px solid ${o.border}`},children:t})}function AN({status:t}){const o={completed:{color:"var(--accent-green)",bg:"hsl(142 76% 42% / 0.15)",border:"hsl(142 76% 42% / 0.3)"},"in-progress":{color:"var(--accent-amber)",bg:"hsl(38 92% 50% / 0.15)",border:"hsl(38 92% 50% / 0.3)"},pending:{color:"var(--text-muted)",bg:"var(--bg-tertiary)",border:"var(--border-color)"}}[t];return f.jsx("span",{style:{fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",padding:"1px 6px",borderRadius:3,color:o.color,background:o.bg,border:`1px solid ${o.border}`},children:t})}function LN({driftType:t}){const o={added:{color:"var(--accent-green)",bg:"hsl(142 76% 42% / 0.15)",border:"hsl(142 76% 42% / 0.3)"},removed:{color:"var(--accent-red)",bg:"hsl(0 90% 55% / 0.15)",border:"hsl(0 90% 55% / 0.3)"},modified:{color:"var(--accent-amber)",bg:"hsl(38 92% 50% / 0.15)",border:"hsl(38 92% 50% / 0.3)"}}[t];return f.jsx("span",{style:{fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",padding:"1px 6px",borderRadius:3,color:o.color,background:o.bg,border:`1px solid ${o.border}`},children:t})}function DN({data:t}){const r=[...t.findings].sort((o,s)=>Br[o.severity]-Br[s.severity]);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No findings"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.severity==="critical"?"var(--accent-red)":o.severity==="high"?"hsl(25 95% 53%)":o.severity==="medium"?"var(--accent-amber)":"var(--accent-green)"}`},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)",fontFamily:"'JetBrains Mono', monospace"},children:o.owaspId}),f.jsx(ws,{severity:o.severity})]}),f.jsx("div",{style:{fontSize:11,color:"var(--text-primary)",fontWeight:500,marginBottom:2},children:o.title}),f.jsx("div",{style:{fontSize:10,color:"var(--text-secondary)",lineHeight:1.4},children:o.description}),o.affectedComponent&&f.jsxs("div",{style:{fontSize:9,color:"var(--text-muted)",marginTop:4,fontFamily:"'JetBrains Mono', monospace"},children:["Component: ",o.affectedComponent]})]},s))})}function $N({data:t}){return t.statuses.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No compliance data"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.statuses.map((r,o)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6},children:[f.jsx("span",{style:{fontSize:12,fontWeight:600,color:"var(--text-primary)"},children:r.framework}),f.jsx(zN,{status:r.status})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[f.jsx("div",{style:{flex:1,height:4,borderRadius:2,background:"var(--bg-hover)"},children:f.jsx("div",{style:{width:r.controls>0?`${Math.round(r.passing/r.controls*100)}%`:"0%",height:"100%",borderRadius:2,background:r.status==="compliant"?"var(--accent-green)":r.status==="partial"?"var(--accent-amber)":"var(--accent-red)",transition:"width 0.3s"}})}),f.jsxs("span",{style:{fontSize:10,color:"var(--text-muted)",fontWeight:500,minWidth:40,textAlign:"right"},children:[r.passing,"/",r.controls]})]}),r.findings.length>0&&f.jsx("div",{style:{marginTop:4},children:r.findings.map((s,a)=>f.jsxs("div",{style:{fontSize:10,color:"var(--text-secondary)",padding:"2px 0",lineHeight:1.4},children:["- ",s]},a))})]},o))})}function ON({data:t}){const r=[...t.bottlenecks].sort((o,s)=>Br[o.severity]-Br[s.severity]);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No bottlenecks detected"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.severity==="critical"?"var(--accent-red)":o.severity==="high"?"hsl(25 95% 53%)":o.severity==="medium"?"var(--accent-amber)":"var(--accent-green)"}`},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)",fontFamily:"'JetBrains Mono', monospace"},children:o.component}),f.jsx(ws,{severity:o.severity})]}),f.jsx("div",{style:{fontSize:11,color:"var(--text-primary)",fontWeight:500,marginBottom:2},children:o.metric}),f.jsx("div",{style:{fontSize:10,color:"var(--text-secondary)",lineHeight:1.4},children:o.description}),o.recommendation&&f.jsx("div",{style:{fontSize:10,color:"var(--accent-cyan)",marginTop:4,fontStyle:"italic"},children:o.recommendation})]},s))})}function FN({data:t}){const r=[...t.risks].sort((o,s)=>s.riskScore-o.riskScore);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No risks identified"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsxs("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-primary)",fontFamily:"'JetBrains Mono', monospace"},children:[o.package,f.jsxs("span",{style:{fontSize:9,color:"var(--text-muted)",marginLeft:4},children:["@",o.version]})]}),f.jsx(ws,{severity:o.severity})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[f.jsx("span",{style:{fontSize:9,color:"var(--text-muted)",fontWeight:600},children:"Risk"}),f.jsx("div",{style:{flex:1,height:4,borderRadius:2,background:"var(--bg-hover)"},children:f.jsx("div",{style:{width:`${o.riskScore}%`,height:"100%",borderRadius:2,background:o.riskScore>=75?"var(--accent-red)":o.riskScore>=50?"var(--accent-amber)":"var(--accent-green)",transition:"width 0.3s"}})}),f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)",minWidth:28},children:o.riskScore})]}),o.reasons.length>0&&f.jsx("div",{style:{marginTop:2},children:o.reasons.map((a,u)=>f.jsxs("div",{style:{fontSize:10,color:"var(--text-secondary)",padding:"1px 0",lineHeight:1.4},children:["- ",a]},u))})]},s))})}function HN({data:t}){const r=[...t.steps].sort((o,s)=>o.order-s.order);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No migration plan"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.status==="completed"?"var(--accent-green)":o.status==="in-progress"?"var(--accent-amber)":"var(--border-color)"}`,opacity:o.status==="completed"?.7:1},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsxs("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)"},children:["Step ",o.order]}),f.jsx(AN,{status:o.status})]}),f.jsx("div",{style:{fontSize:11,color:"var(--text-primary)",fontWeight:500,marginBottom:2},children:o.title}),f.jsx("div",{style:{fontSize:10,color:"var(--text-secondary)",lineHeight:1.4},children:o.description}),o.estimatedEffort&&f.jsxs("div",{style:{fontSize:9,color:"var(--text-muted)",marginTop:4,fontFamily:"'JetBrains Mono', monospace"},children:["Effort: ",o.estimatedEffort]})]},s))})}function VN({data:t}){const r=[...t.mismatches].sort((o,s)=>Br[o.severity]-Br[s.severity]);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No mismatches found"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.severity==="critical"?"var(--accent-red)":o.severity==="high"?"hsl(25 95% 53%)":o.severity==="medium"?"var(--accent-amber)":"var(--accent-green)"}`},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--accent-cyan)",fontFamily:"'JetBrains Mono', monospace"},children:o.endpoint}),f.jsx(ws,{severity:o.severity})]}),f.jsx("div",{style:{fontSize:11,color:"var(--text-primary)",fontWeight:500,marginBottom:4},children:o.field}),f.jsxs("div",{style:{display:"flex",gap:8,fontSize:10},children:[f.jsxs("div",{style:{flex:1},children:[f.jsx("div",{style:{color:"var(--text-muted)",fontSize:9,marginBottom:2},children:"Spec"}),f.jsx("div",{style:{color:"var(--accent-green)",fontFamily:"'JetBrains Mono', monospace",fontSize:10,padding:"3px 6px",background:"hsl(142 76% 42% / 0.08)",borderRadius:3},children:o.specValue})]}),f.jsxs("div",{style:{flex:1},children:[f.jsx("div",{style:{color:"var(--text-muted)",fontSize:9,marginBottom:2},children:"Impl"}),f.jsx("div",{style:{color:"var(--accent-red)",fontFamily:"'JetBrains Mono', monospace",fontSize:10,padding:"3px 6px",background:"hsl(0 90% 55% / 0.08)",borderRadius:3},children:o.implValue})]})]})]},s))})}function BN({data:t}){const r=[...t.detections].sort((o,s)=>Br[o.severity]-Br[s.severity]);return r.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,padding:"8px 0"},children:"No drift detected"}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map((o,s)=>f.jsxs("div",{style:{padding:"8px 10px",background:"var(--bg-tertiary)",borderRadius:6,borderLeft:`3px solid ${o.severity==="critical"?"var(--accent-red)":o.severity==="high"?"hsl(25 95% 53%)":o.severity==="medium"?"var(--accent-amber)":"var(--accent-green)"}`},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-muted)",fontFamily:"'JetBrains Mono', monospace"},children:o.component}),f.jsxs("div",{style:{display:"flex",gap:4,alignItems:"center"},children:[f.jsx(LN,{driftType:o.driftType}),f.jsx(ws,{severity:o.severity})]})]}),f.jsx("div",{style:{fontSize:10,color:"var(--text-secondary)",lineHeight:1.4},children:o.description}),f.jsx("div",{style:{fontSize:9,color:"var(--text-muted)",marginTop:4,fontFamily:"'JetBrains Mono', monospace"},children:new Date(o.detectedAt).toLocaleString()})]},s))})}function WN({visible:t,onClose:r,results:o}){const[s,a]=b.useState(new Set),[u,c]=b.useState(!1),[h,m]=b.useState([]),y=b.useCallback(k=>{a(S=>{const I=new Set(S);return I.has(k)?I.delete(k):I.add(k),I})},[]),x=b.useCallback(async()=>{c(!0);try{const k=await fetch("/api/premium-agents/results");if(k.ok){const S=await k.json();Array.isArray(S)&&m(S)}}catch{}c(!1)},[]);b.useEffect(()=>{t&&x()},[t,x]);const g=o.length>0?o:h,v=new Map;g.forEach(k=>{v.set(k.agentId,k)});const C=["security-audit","compliance","performance","dependency-risk","migration","api-contracts","drift-detection"];function E(k){const S=k.data;switch(S.agentId){case"security-audit":return S.findings.length;case"compliance":return S.statuses.length;case"performance":return S.bottlenecks.length;case"dependency-risk":return S.risks.length;case"migration":return S.steps.length;case"api-contracts":return S.mismatches.length;case"drift-detection":return S.detections.length}}function N(k){const S=k.data;switch(S.agentId){case"security-audit":return f.jsx(DN,{data:S});case"compliance":return f.jsx($N,{data:S});case"performance":return f.jsx(ON,{data:S});case"dependency-risk":return f.jsx(FN,{data:S});case"migration":return f.jsx(HN,{data:S});case"api-contracts":return f.jsx(VN,{data:S});case"drift-detection":return f.jsx(BN,{data:S})}}return t?f.jsxs(di,{style:{position:"absolute",top:60,right:16,background:"var(--bg-secondary)",backdropFilter:"blur(12px)",borderRadius:12,border:"1px solid var(--border-color)",zIndex:10,width:320,maxHeight:"calc(100vh - 200px)",overflowY:"auto",boxShadow:"0 2px 12px var(--shadow-color)"},children:[f.jsxs("div",{"data-drag-handle":!0,style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 14px 8px",borderBottom:"1px solid var(--border-color)",cursor:"grab"},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"1px",color:"var(--text-muted)"},children:"Pro Agents"}),f.jsx("span",{style:{fontSize:9,fontWeight:600,padding:"1px 6px",borderRadius:3,background:"#7c3aed",color:"#fff"},children:"PRO"})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[f.jsx("button",{className:"panel-btn cyan small",onClick:x,disabled:u,children:u?"...":"Refresh"}),f.jsx("button",{className:"panel-close-btn",onClick:r,children:"x"})]})]}),f.jsx("div",{style:{padding:"8px 10px 12px"},children:u&&g.length===0?f.jsx("div",{style:{color:"var(--text-muted)",fontSize:11,textAlign:"center",padding:20},children:"Loading agent results..."}):g.length===0?f.jsxs("div",{style:{color:"var(--text-muted)",fontSize:11,textAlign:"center",padding:20},children:["No premium agent results yet.",f.jsx("span",{style:{display:"block",marginTop:6,fontSize:10,color:"var(--accent-cyan)",opacity:.7,fontFamily:"'JetBrains Mono', monospace"},children:"Run agents to see results here"})]}):f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:C.map(k=>{const S=v.get(k);if(!S)return null;const I=TN[k],_=s.has(k),j=E(S);return f.jsxs("div",{style:{borderRadius:8,border:"1px solid var(--border-color)",overflow:"hidden"},children:[f.jsxs("div",{onClick:()=>y(k),style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"8px 10px",background:_?"var(--bg-tertiary)":"transparent",cursor:"pointer",transition:"background 0.15s",userSelect:"none"},onMouseEnter:O=>{_||(O.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:O=>{_||(O.currentTarget.style.background="transparent")},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx("span",{style:{fontSize:12},children:I.icon}),f.jsx("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-primary)"},children:I.label}),j>0&&f.jsx("span",{style:{fontSize:9,fontWeight:600,padding:"0px 5px",borderRadius:8,background:"var(--bg-hover)",color:"var(--text-secondary)"},children:j})]}),f.jsx("div",{style:{display:"flex",alignItems:"center",gap:6},children:f.jsx("span",{style:{fontSize:10,color:"var(--text-muted)",fontFamily:"'JetBrains Mono', monospace",transition:"transform 0.2s",transform:_?"rotate(90deg)":"rotate(0deg)",display:"inline-block"},children:"▶"})})]}),_&&f.jsxs("div",{style:{padding:"6px 10px 10px"},children:[f.jsxs("div",{style:{marginBottom:8},children:[f.jsx("div",{style:{fontSize:9,color:"var(--text-muted)",marginBottom:3,fontWeight:500},children:"Confidence"}),f.jsx(RN,{value:S.confidence})]}),N(S),f.jsx("div",{style:{fontSize:9,color:"var(--text-muted)",marginTop:8,textAlign:"right",fontFamily:"'JetBrains Mono', monospace"},children:new Date(S.timestamp).toLocaleString()})]})]},k)})})}),g.length>0&&f.jsxs("div",{style:{padding:"8px 14px",borderTop:"1px solid var(--border-color)",fontSize:10,color:"var(--text-muted)",textAlign:"center"},children:[g.length," of ",C.length," agents reporting"]})]}):null}const UN=b.memo(WN);function ti(t,r){return!t||t.length===0?!0:t.includes(r)}const YN=1500,XN={architecture:Pg};function GN(t,r,o){if(o)return t.map(g=>({id:g.id,type:"architecture",position:{x:g.x,y:g.y},data:{label:g.label,layer:g.layer,nodeType:g.type,width:g.width,height:g.height,path:g.path,techStack:g.techStack,description:g.description},style:{width:g.width,zIndex:1}}));const h=["presentation","application","data","external","deployment"],m={};t.forEach(g=>{const v=g.layer||"application";m[v]||(m[v]=[]),m[v].push(g)});const y=new Map;let x=100;return h.forEach(g=>{const v=m[g]||[];v.forEach((C,E)=>{y.set(C.id,{x:100+E*250,y:x})}),v.length>0&&(x+=180)}),Object.entries(m).forEach(([g,v])=>{h.includes(g)||(v.forEach((C,E)=>{y.set(C.id,{x:100+E*250,y:x})}),x+=180)}),t.map(g=>{const v=y.get(g.id)||{x:100,y:100};return{id:g.id,type:"architecture",position:v,data:{label:g.label,layer:g.layer,nodeType:g.type,width:g.width,height:g.height,path:g.path,techStack:g.techStack,description:g.description},style:{width:g.width,zIndex:1}}})}function Np(t,r="#64748b"){return t.map(o=>({id:o.id,source:o.source,target:o.target,label:o.label||void 0,labelStyle:o.label?{fill:"var(--text-secondary)",fontSize:10,fontWeight:500,fontFamily:"'JetBrains Mono', monospace"}:void 0,labelBgStyle:o.label?{fill:"var(--bg-secondary)",fillOpacity:.85,rx:4,ry:4}:void 0,labelBgPadding:[4,3],style:{stroke:o.color||r,strokeWidth:2,...o.style==="dashed"&&{strokeDasharray:"8 4"}},animated:o.animated||!1,type:"smoothstep",markerEnd:{type:us.ArrowClosed,width:16,height:16,color:o.color||r}}))}function KN(){var wn,Sn,kn;const[t,r,o]=Vk([]),[s,a,u]=Bk([]),[c,h]=b.useState(null),[m,y]=b.useState(!1),[x,g]=b.useState(null),[v]=b.useState([]),[C,E]=b.useState(!0),[N,k]=b.useState(null),[S,I]=b.useState({loggedIn:!1,email:null,tier:"free",features:{analyze:!0,validate:!1,patrol:!1,workflows:!1,chat:!1,premiumAgents:!1}}),[_,j]=b.useState(!1),[O,A]=b.useState(null),[H,q]=b.useState(!1),[J,ee]=b.useState(null),[,U]=b.useState(null),[X,re]=b.useState(null),[P,K]=b.useState(null),[V,G]=b.useState(-1),[R,z]=b.useState(!1),[B,M]=b.useState(new Set),[D,ie]=b.useState(!1),[oe,de]=b.useState(new Set),[he,me]=b.useState(new Set),[ne,pe]=b.useState(null),[be,_e]=b.useState("layer"),[Ce,Ee]=b.useState(!1),[ze,He]=b.useState(!1),[Ae,Ge]=b.useState(!1),[Ct,ft]=b.useState(!1),[yt,ht]=b.useState(!1),[hn,zn]=b.useState([]),[vt,An]=b.useState("develop"),[,Jt]=b.useState([]),[pn,Ln]=b.useState(),[Wr,en]=b.useState(null),[_t,fi]=b.useState(null),[mn,Vt]=b.useState(new Map),[Ur,pr]=b.useState(!1),tn=b.useRef([]),[Kn,Yr]=b.useState([]),Xr=50,[,nn]=b.useState([]),[,rn]=b.useState([]),[on,No]=b.useState(new Set),[jt,Gr]=b.useState(new Set),[ut,Kr]=b.useState(()=>{const $=localStorage.getItem("archbyte-theme");return $==="dark"||$==="light"?$:"light"});b.useEffect(()=>{document.documentElement.setAttribute("data-theme",ut),localStorage.setItem("archbyte-theme",ut)},[ut]);const[Qr,It]=b.useState(!1),[gn,Dn]=b.useState(""),[Qn,yn]=b.useState(new Set),[mr,vn]=b.useState(!1),[tt,hi]=b.useState(null),qn=ut==="dark"?"#64748b":"#94a3b8",Co="#fff",Bt=20,Tt=10,xn=b.useCallback(async()=>{try{await mi()}catch($){console.error("Failed to load architecture:",$),k("Failed to connect to server"),Ue()}finally{E(!1)}},[]),pi=async()=>{try{const $=await fetch("/api/tools-git");if($.ok){const W=await $.json();fi(W)}}catch{}},_o=async()=>{try{const $=await fetch("/api/config");if($.ok){const W=await $.json();if(U(W),W.environments){Ln(W.environments);const te=Object.keys(W.environments);te.length>0&&!te.includes(vt)&&An(te[0])}}}catch{}},jo=async()=>{try{const $=await fetch("/api/license");if($.ok){const W=await $.json();I(W),j(!0)}}catch{j(!0)}},bo=async()=>{try{const $=await fetch("/api/project");if($.ok){const W=await $.json();W&&re(W)}}catch{}},Po=async()=>{try{const $=await fetch("/api/analysis-status");if($.ok){const W=await $.json();(W==null?void 0:W.status)==="error"&&W.error?ee(W.error):ee(null)}}catch{}},mi=async()=>{const $="/events",W="/api/architecture";pi(),_o(),bo(),jo(),Po();try{const te=new EventSource($);return te.onopen=()=>{console.log("SSE connected"),y(!0),k(null)},te.onmessage=se=>{try{const ae=JSON.parse(se.data);console.log("SSE message:",ae.type),ae.architecture&&Zr(ae.architecture),ae.type==="git_update"&&ae.gitInfo&&Jt(ae.gitInfo),ae.type==="premium_agent_result"&&ae.premiumResults&&zn(ae.premiumResults)}catch(ae){console.error("Failed to parse SSE message:",ae)}},te.onerror=se=>{console.error("SSE error:",se),te.close(),y(!1),qr(W)},()=>te.close()}catch{qr(W)}},qr=async $=>{try{const W=await fetch($);if(W.ok){const te=await W.json();Zr(te),y(!0)}else Ue()}catch{Ue()}},Ue=()=>{const $={nodes:[{id:"frontend",type:"component",label:`Frontend
|
|
66
66
|
(Web App)`,layer:"presentation",x:150,y:170,width:200,height:100,color:"#d0ebff"},{id:"backend",type:"service",label:`Backend
|
|
67
67
|
(API)`,layer:"application",x:150,y:370,width:200,height:100,color:"#ffe8cc"},{id:"database",type:"database",label:"Database",layer:"data",x:150,y:570,width:200,height:80,color:"#b2f2bb"}],edges:[{id:"e1",source:"frontend",target:"backend",color:"#1971c2"},{id:"e2",source:"backend",target:"database",color:"#2f9e44"}],flows:[],lastUpdated:new Date().toISOString(),version:1};Zr($)},Zr=$=>{h($),g($.lastUpdated),$.gitInfo&&Jt($.gitInfo),$.environments&&Ln($.environments)};b.useEffect(()=>{if(!c)return;const $=c.nodes.filter(se=>ti(se.environments,vt)&&!oe.has(se.id)&&!he.has(se.layer)),W=new Set($.map(se=>se.id)),te=c.edges.filter(se=>ti(se.environments,vt)&&W.has(se.source)&&W.has(se.target));r(GN($,te,c.layoutSaved)),a(Np(te,qn))},[c,vt,oe,he,qn]),b.useEffect(()=>{xn()},[xn]),b.useEffect(()=>{if(!R||!P)return;const $=setInterval(()=>{G(W=>{const te=W+1;if(te>=P.steps.length)return M(new Set([P.steps[0].edge])),0;const se=new Set;for(let ae=0;ae<=te;ae++)se.add(P.steps[ae].edge);return M(se),te})},YN);return()=>clearInterval($)},[R,P]),b.useEffect(()=>{if(!c)return;const $=c.nodes.filter(ge=>ti(ge.environments,vt)),W=new Set($.map(ge=>ge.id)),te=c.edges.filter(ge=>ti(ge.environments,vt)&&W.has(ge.source)&&W.has(ge.target)),se=new Map;P&&P.steps.forEach((ge,je)=>{se.has(ge.edge)||se.set(ge.edge,je+1)});const ae=te.map(ge=>{const je=B.has(ge.id),Se=P==null?void 0:P.steps.some(Be=>Be.edge===ge.id),Pe=se.get(ge.id);return{id:ge.id,source:ge.source,target:ge.target,label:je&&Pe?`${Pe}`:void 0,labelStyle:je&&Pe?{fill:Co,fontWeight:700,fontSize:12,fontFamily:"'JetBrains Mono', monospace",transform:"translateY(-22px)"}:void 0,labelBgStyle:je&&Pe?{fill:(P==null?void 0:P.color)||"#3b82f6",fillOpacity:.95,rx:10,ry:10,transform:"translateY(-22px)"}:void 0,labelBgPadding:[6,4],style:{stroke:je?(P==null?void 0:P.color)||ge.color:ge.color||qn,strokeWidth:je?6:3,opacity:P?Se?1:.15:1,filter:je?"brightness(0.85) saturate(1.4)":void 0},animated:je,type:"smoothstep"}});a(ae)},[B,P,c,vt,qn,Co]);const gr=$=>{K($),G(0),M(new Set([$.steps[0].edge])),z(!0),ie(!0)},$n=()=>{if(z(!1),K(null),G(-1),M(new Set),ie(!1),c){const $=c.nodes.filter(se=>ti(se.environments,vt)),W=new Set($.map(se=>se.id)),te=c.edges.filter(se=>ti(se.environments,vt)&&W.has(se.source)&&W.has(se.target));a(Np(te,qn))}},yr=()=>{z(!1)},gi=()=>{P&&z(!0)},Zn=b.useRef(oe);b.useEffect(()=>{Zn.current=oe},[oe]);const We=b.useCallback(()=>{nn($=>{const W={nodes:[...tn.current],edges:[...s],hiddenNodeIds:new Set(Zn.current)},te=[...$,W];return te.length>Xr&&te.shift(),te}),rn([])},[s]),Rt=b.useCallback($=>{en($),setTimeout(()=>en(null),3e3)},[]),yi=b.useCallback($=>{We(),de(W=>new Set([...W,$])),pe(null)},[We]),bt=b.useCallback($=>{de(W=>{const te=new Set(W);return te.delete($),te})},[]),vi=b.useCallback(()=>{de(new Set)},[]);b.useCallback($=>{me(W=>{const te=new Set(W);return te.has($)?te.delete($):te.add($),te})},[]);const xi=b.useCallback(($,W)=>{pe(W.id)},[]),wi=b.useCallback(()=>{pe(null)},[]);b.useEffect(()=>{tn.current=t},[t]);const vr=b.useCallback($=>{o($);const W=$.some(se=>se.type==="position"&&se.dragging===!1&&se.position),te=$.some(se=>se.type==="dimensions"&&se.dimensions&&se.resizing===!1);(W||te)&&We(),$.forEach(se=>{if(se.type==="position"&&se.dragging===!1&&se.position){const ae=tn.current.find(ge=>ge.id===se.id);ae&&Vt(ge=>{var Pe,Be,Ye,ot;const je=new Map(ge),Se=je.get(se.id);return je.set(se.id,{id:se.id,x:se.position.x,y:se.position.y,width:(Se==null?void 0:Se.width)??((Pe=ae.style)==null?void 0:Pe.width)??((Be=ae.data)==null?void 0:Be.width)??100,height:(Se==null?void 0:Se.height)??((Ye=ae.style)==null?void 0:Ye.height)??((ot=ae.data)==null?void 0:ot.height)??60}),je})}if(se.type==="dimensions"&&se.dimensions&&se.resizing===!1){const ae=tn.current.find(ge=>ge.id===se.id);ae&&Vt(ge=>{const je=new Map(ge),Se=je.get(se.id);return je.set(se.id,{id:se.id,x:(Se==null?void 0:Se.x)??ae.position.x,y:(Se==null?void 0:Se.y)??ae.position.y,width:se.dimensions.width,height:se.dimensions.height}),je})}})},[o,We]),On=b.useCallback(async()=>{if(mn.size!==0){pr(!0);try{const $=Array.from(mn.values()),W=await fetch("/api/update-positions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:$})});if(W.ok)Vt(new Map),console.log("Changes saved successfully");else{const te=await W.json();console.error("Failed to save changes:",te)}}catch($){console.error("Error saving changes:",$)}finally{pr(!1)}}},[mn]),sn=b.useCallback(()=>{Vt(new Map),xn()},[xn]),Jn=b.useCallback(()=>{nn($=>{if($.length===0)return $;const W=[...$],te=W.pop();if(rn(se=>[...se,{nodes:[...tn.current],edges:[...s],hiddenNodeIds:new Set(Zn.current)}]),r(te.nodes),a(te.edges),de(te.hiddenNodeIds),c){const se=new Map;te.nodes.forEach(ae=>{var je,Se,Pe,Be;const ge=c.nodes.find(Ye=>Ye.id===ae.id);if(ge){const Ye=ae.position.x,ot=ae.position.y,Le=((je=ae.style)==null?void 0:je.width)??((Se=ae.data)==null?void 0:Se.width)??100,Ke=((Pe=ae.style)==null?void 0:Pe.height)??((Be=ae.data)==null?void 0:Be.height)??60;(Ye!==ge.x||ot!==ge.y||Le!==ge.width||Ke!==ge.height)&&se.set(ae.id,{id:ae.id,x:Ye,y:ot,width:Le,height:Ke})}}),Vt(se)}return W})},[s,r,a,c]),Jr=b.useCallback(()=>{rn($=>{if($.length===0)return $;const W=[...$],te=W.pop();if(nn(se=>[...se,{nodes:[...tn.current],edges:[...s],hiddenNodeIds:new Set(Zn.current)}]),r(te.nodes),a(te.edges),de(te.hiddenNodeIds),c){const se=new Map;te.nodes.forEach(ae=>{var je,Se,Pe,Be;const ge=c.nodes.find(Ye=>Ye.id===ae.id);if(ge){const Ye=ae.position.x,ot=ae.position.y,Le=((je=ae.style)==null?void 0:je.width)??((Se=ae.data)==null?void 0:Se.width)??100,Ke=((Pe=ae.style)==null?void 0:Pe.height)??((Be=ae.data)==null?void 0:Be.height)??60;(Ye!==ge.x||ot!==ge.y||Le!==ge.width||Ke!==ge.height)&&se.set(ae.id,{id:ae.id,x:Ye,y:ot,width:Le,height:Ke})}}),Vt(se)}return W})},[s,r,a,c]),Si=b.useCallback(({nodes:$})=>{Gr(new Set($.map(W=>W.id))),$.length===1?pe($[0].id):$.length===0&&pe(null)},[]),xr=b.useCallback(()=>{if(jt.size===0&&!ne)return;We();const $=jt.size>0?jt:new Set([ne]);de(W=>new Set([...W,...$])),Gr(new Set),pe(null)},[jt,ne,We]),er=b.useCallback(()=>{const $=jt.size>0?jt:ne?new Set([ne]):new Set;if($.size===0)return;const W=t.filter(te=>$.has(te.id));Yr(W)},[t,jt,ne]),wr=b.useCallback(()=>{if(Kn.length===0)return;We();const $=50,W=Kn.map((te,se)=>{var ae;return{...te,id:`${te.id}-copy-${Date.now()}-${se}`,position:{x:te.position.x+$,y:te.position.y+$},selected:!0,data:{...te.data,label:`${((ae=te.data)==null?void 0:ae.label)||te.id} (copy)`}}});r(te=>[...te.map(se=>({...se,selected:!1})),...W]),W.forEach(te=>{Vt(se=>{var ge,je,Se,Pe;const ae=new Map(se);return ae.set(te.id,{id:te.id,x:te.position.x,y:te.position.y,width:((ge=te.style)==null?void 0:ge.width)||((je=te.data)==null?void 0:je.width)||100,height:((Se=te.style)==null?void 0:Se.height)||((Pe=te.data)==null?void 0:Pe.height)||60}),ae})})},[Kn,r,We]),Wt=b.useCallback(($,W)=>{const te=jt.size>0?jt:ne?new Set([ne]):new Set;te.size!==0&&(We(),r(se=>se.map(ae=>{if(te.has(ae.id)&&!on.has(ae.id)){const ge={x:ae.position.x+$,y:ae.position.y+W};return Vt(je=>{var Pe,Be,Ye,ot;const Se=new Map(je);return Se.set(ae.id,{id:ae.id,x:ge.x,y:ge.y,width:((Pe=ae.style)==null?void 0:Pe.width)||((Be=ae.data)==null?void 0:Be.width)||100,height:((Ye=ae.style)==null?void 0:Ye.height)||((ot=ae.data)==null?void 0:ot.height)||60}),Se}),{...ae,position:ge}}return ae})))},[jt,ne,on,r,We]),Sr=b.useCallback($=>{No(W=>{const te=new Set(W);return te.has($)?te.delete($):te.add($),te})},[]),ki=b.useCallback($=>{const W={id:`edge-${$.source}-${$.target}-${Date.now()}`,source:$.source,target:$.target,type:"smoothstep",animated:!0,style:{stroke:ut==="dark"?"#868e96":"#6b7280",strokeWidth:2}};a(te=>Sm(W,te))},[a,ut]),Ve=b.useCallback(($,W)=>{We(),a(te=>s1($,W,te))},[a,We]),Ss=b.useCallback(async()=>{const $=document.querySelector(".react-flow");if($){It(!0);try{const W=await lN($,{backgroundColor:ut==="dark"?"hsl(222, 47%, 5%)":"hsl(220, 20%, 97%)",quality:1,pixelRatio:2}),te=document.createElement("a");te.download=`architecture-diagram-${new Date().toISOString().split("T")[0]}.png`,te.href=W,te.click()}catch(W){console.error("Failed to export PNG:",W)}finally{It(!1)}}},[ut]),ks=b.useCallback(async()=>{const $=document.querySelector(".react-flow");if($){It(!0);try{const W=await bg($,{backgroundColor:ut==="dark"?"hsl(222, 47%, 5%)":"hsl(220, 20%, 97%)"}),te=document.createElement("a");te.download=`architecture-diagram-${new Date().toISOString().split("T")[0]}.svg`,te.href=W,te.click()}catch(W){console.error("Failed to export SVG:",W)}finally{It(!1)}}},[ut]),tr=b.useCallback(async $=>{It(!0);try{const W=await fetch(`/api/export?format=${$}`);if(!W.ok)throw new Error("Export failed");const te=await W.blob(),se=$==="mermaid"?"mmd":$==="plantuml"?"puml":$==="markdown"?"md":$,ae=document.createElement("a");ae.download=`architecture.${se}`,ae.href=URL.createObjectURL(te),ae.click(),URL.revokeObjectURL(ae.href)}catch(W){console.error(`Failed to export ${$}:`,W)}finally{It(!1)}},[]);b.useCallback(()=>{if(!c)return;We();const $=250,W=100,te=100,se=t.map((ae,ge)=>({...ae,position:{x:W+ge*$,y:te}}));r(se),_e("horizontal")},[c,t,r,We]),b.useCallback(()=>{if(!c)return;We();const $=150,W=100,te=100,se=t.map((ae,ge)=>({...ae,position:{x:W,y:te+ge*$}}));r(se),_e("vertical")},[c,t,r,We]),b.useCallback(()=>{if(!c)return;We();const $=280,W=180,te=100,se=100,ae=Math.ceil(Math.sqrt(t.length)),ge=t.map((je,Se)=>({...je,position:{x:te+Se%ae*$,y:se+Math.floor(Se/ae)*W}}));r(ge),_e("grid")},[c,t,r,We]),b.useCallback(()=>{if(!c)return;We();const $=320,W=160,te=100,se=100,ae=new Set(t.map(Le=>Le.id)),ge=new Map,je=new Map;ae.forEach(Le=>{ge.set(Le,0),je.set(Le,[])}),s.forEach(Le=>{ae.has(Le.source)&&ae.has(Le.target)&&(je.get(Le.source).push(Le.target),ge.set(Le.target,(ge.get(Le.target)||0)+1))});const Se=new Map,Pe=[];for(ge.forEach((Le,Ke)=>{Le===0&&(Pe.push(Ke),Se.set(Ke,0))});Pe.length>0;){const Le=Pe.shift(),Ke=Se.get(Le);for(const Ut of je.get(Le)||[]){const Mo=Ke+1;(!Se.has(Ut)||Se.get(Ut)<Mo)&&Se.set(Ut,Mo),ge.set(Ut,ge.get(Ut)-1),ge.get(Ut)===0&&Pe.push(Ut)}}t.forEach(Le=>{Se.has(Le.id)||Se.set(Le.id,0)});const Be=new Map;t.forEach(Le=>{const Ke=Se.get(Le.id);Be.has(Ke)||Be.set(Ke,[]),Be.get(Ke).push(Le)});const Ye=[];[...Be.keys()].sort((Le,Ke)=>Le-Ke).forEach((Le,Ke)=>{Be.get(Le).forEach((Mo,aa)=>{Ye.push({...Mo,position:{x:te+Ke*$,y:se+aa*W}})})}),r(Ye),_e("flow")},[c,t,s,r,We]),b.useCallback(()=>{if(!c)return;We();const $=250,W=180,te=100,se=100,ae={};t.forEach(Pe=>{var Ye;const Be=((Ye=Pe.data)==null?void 0:Ye.layer)||"application";ae[Be]||(ae[Be]=[]),ae[Be].push(Pe)});const ge=["presentation","application","data","external","deployment"];let je=se;const Se=[];ge.forEach(Pe=>{const Be=ae[Pe]||[];Be.forEach((Ye,ot)=>{Se.push({...Ye,position:{x:te+ot*$,y:je}})}),Be.length>0&&(je+=W)}),Object.entries(ae).forEach(([Pe,Be])=>{ge.includes(Pe)||(Be.forEach((Ye,ot)=>{Se.push({...Ye,position:{x:te+ot*$,y:je}})}),je+=W)}),r(Se),_e("layer")},[c,t,r,We]);const eo=b.useCallback($=>{if(!$||!c){yn(new Set);return}const W=new Set;W.add($),c.edges.forEach(te=>{te.source===$&&(W.add(te.target),W.add(te.id)),te.target===$&&(W.add(te.source),W.add(te.id))}),yn(W)},[c]),Es=b.useMemo(()=>{if(!gn.trim())return new Set;const $=gn.toLowerCase(),W=new Set;return t.forEach(te=>{var ae;(((ae=te.data)==null?void 0:ae.label)||"").toLowerCase().includes($)&&W.add(te.id)}),W},[gn,t]),Ns=b.useCallback(async $=>{try{await fetch("/api/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:$})})}catch(W){console.error("Failed to open file:",W)}},[]),Ei=b.useCallback(($,W)=>{if(!c)return;const te=c.nodes.find(se=>se.id===W.id);te&&(hi(te),vn(!0))},[c]);b.useEffect(()=>{const $=W=>{if(W.target instanceof HTMLInputElement||W.target instanceof HTMLTextAreaElement)return;const se=navigator.platform.toUpperCase().indexOf("MAC")>=0?W.metaKey:W.ctrlKey;if(W.key==="Backspace"||W.key==="Delete"){W.preventDefault(),xr();return}if(se&&W.key==="c"){W.preventDefault(),er();return}if(se&&W.key==="v"){W.preventDefault(),wr();return}if(se&&W.shiftKey&&W.key==="z"){W.preventDefault(),Jr();return}if(se&&W.key==="z"){W.preventDefault(),Jn();return}if(se&&W.key==="s"){W.preventDefault(),On();return}if(W.key==="Escape"){Dn(""),yn(new Set),vn(!1);return}if(W.key==="ArrowUp"){W.preventDefault(),Wt(0,W.shiftKey?-Tt*5:-Tt);return}if(W.key==="ArrowDown"){W.preventDefault(),Wt(0,W.shiftKey?Tt*5:Tt);return}if(W.key==="ArrowLeft"){W.preventDefault(),Wt(W.shiftKey?-Tt*5:-Tt,0);return}if(W.key==="ArrowRight"){W.preventDefault(),Wt(W.shiftKey?Tt*5:Tt,0);return}if(se&&W.key==="l"&&ne){W.preventDefault(),Sr(ne);return}};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[xr,er,wr,On,Wt,Sr,ne,Jn,Jr]);const kr=b.useMemo(()=>c?c.nodes.filter($=>oe.has($.id)):[],[c,oe]);return b.useEffect(()=>{c&&r($=>$.map(W=>({...W,data:{...W.data,highlighted:W.id===Wr}})))},[Wr,c]),C?f.jsx("div",{className:"app",children:f.jsxs("div",{className:"loading",children:[f.jsx("div",{className:"loading-spinner"}),"Loading architecture..."]})}):f.jsxs("div",{className:"app",children:[f.jsxs("div",{className:"branding-header",children:[f.jsxs("div",{className:"archbyte-brand",children:[f.jsx("span",{className:"archbyte-name",children:"ArchByte"}),X?f.jsx(NN,{projectInfo:X}):f.jsx("span",{className:"archbyte-tagline",children:"See what agents build. As they build it."})]}),S.loggedIn&&f.jsx("div",{className:"branding-account",children:S.email&&f.jsxs("span",{className:"account-email",children:[S.email,S.tier==="premium"&&f.jsx("span",{className:"account-pro-tag",children:"PRO"})]})})]}),f.jsxs("div",{className:"toolbar",children:[f.jsxs("div",{className:"toolbar-left",children:[f.jsxs("div",{className:"toolbar-section",children:[f.jsx("span",{className:"toolbar-section-label",children:"View"}),f.jsx("div",{className:"toolbar-section-items",children:f.jsx("input",{type:"text",placeholder:"Filter nodes...",value:gn,onChange:$=>Dn($.target.value),className:"toolbar-search"})})]}),f.jsxs("div",{className:"toolbar-section",children:[f.jsx("span",{className:"toolbar-section-label",children:"Analyze"}),f.jsxs("div",{className:"toolbar-section-items",children:[f.jsxs(kp,{trigger:P?f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"flow-dot-inline",style:{background:P.color}}),P.name]}):"▶ Flows ▾",triggerClassName:`toolbar-btn ${P?"has-active-flow":""}`,children:[P&&f.jsxs(f.Fragment,{children:[f.jsx("button",{className:"dropdown-item flow-clear",onClick:$n,children:"⏹ Clear active flow"}),f.jsx("div",{className:"dropdown-separator"})]}),c!=null&&c.flows&&c.flows.length>0?(()=>{const $=["user-journey","data-pipeline","system","deployment","error-recovery"],W={"user-journey":"User Journey","data-pipeline":"Data Pipeline",system:"System",deployment:"Deployment","error-recovery":"Error / Recovery"},te={"user-journey":"#3b82f6","data-pipeline":"#22c55e",system:"#f59e0b",deployment:"#a855f7","error-recovery":"#ef4444"},se={};for(const je of c.flows){const Se=je.category||"system";se[Se]||(se[Se]=[]),se[Se].push(je)}const ae=[];for(const je of $){const Se=se[je];if(Se!=null&&Se.length){ae.push(f.jsxs("div",{className:"flow-category-header",children:[f.jsx("span",{className:"flow-dot-inline",style:{background:te[je]}}),W[je]||je]},`cat-${je}`));for(const Pe of Se)ae.push(f.jsxs("button",{className:`dropdown-item flow-dropdown-item ${(P==null?void 0:P.id)===Pe.id?"active":""}`,onClick:()=>{(P==null?void 0:P.id)===Pe.id?$n():gr(Pe)},children:[f.jsx("span",{className:"flow-dot-inline",style:{background:Pe.color}}),f.jsx("span",{className:"flow-dropdown-name",children:Pe.name}),(P==null?void 0:P.id)===Pe.id&&f.jsx("span",{className:"active-badge",children:"ACTIVE"})]},Pe.id))}}const ge=new Set($);for(const[je,Se]of Object.entries(se))if(!ge.has(je)&&Se!=null&&Se.length){ae.push(f.jsxs("div",{className:"flow-category-header",children:[f.jsx("span",{className:"flow-dot-inline",style:{background:"#6b7280"}}),je]},`cat-${je}`));for(const Pe of Se)ae.push(f.jsxs("button",{className:`dropdown-item flow-dropdown-item ${(P==null?void 0:P.id)===Pe.id?"active":""}`,onClick:()=>{(P==null?void 0:P.id)===Pe.id?$n():gr(Pe)},children:[f.jsx("span",{className:"flow-dot-inline",style:{background:Pe.color}}),f.jsx("span",{className:"flow-dropdown-name",children:Pe.name}),(P==null?void 0:P.id)===Pe.id&&f.jsx("span",{className:"active-badge",children:"ACTIVE"})]},Pe.id))}return ae})():f.jsx("span",{className:"dropdown-item disabled",children:"No flows defined"})]}),f.jsx("button",{className:`toolbar-btn premium-btn ${S.features.validate?"":"premium-locked"} ${ze?"active":""}`,onClick:()=>{if(!S.features.validate){A("Validate");return}He(!ze)},children:"Validate"})]})]}),f.jsxs("div",{className:"toolbar-section",children:[f.jsx("span",{className:"toolbar-section-label",children:"Ops"}),f.jsxs("div",{className:"toolbar-section-items",children:[f.jsx("button",{className:`toolbar-btn premium-btn ${S.features.patrol?"":"premium-locked"} ${Ae?"active":""}`,title:S.features.patrol?"":"Available in Pro",onClick:()=>{if(!S.features.patrol){A("Patrol");return}Ge(!Ae),ft(!1),ht(!1)},children:"Patrol"}),f.jsx("button",{className:`toolbar-btn premium-btn ${S.features.patrol?"":"premium-locked"} ${Ct?"active":""}`,title:S.features.patrol?"":"Available in Pro",onClick:()=>{if(!S.features.patrol){A("Workflows");return}ft(!Ct),Ge(!1),ht(!1)},children:"Workflows"}),f.jsx("button",{className:`toolbar-btn premium-btn ${S.features.premiumAgents?"":"premium-locked"} ${yt?"active":""}`,title:S.features.premiumAgents?"":"Available in Pro",onClick:()=>{if(!S.features.premiumAgents){A("Pro Agents");return}yt?ht(!1):(ht(!0),Ge(!1),ft(!1))},children:"Agents"})]})]})]}),f.jsxs("div",{className:"toolbar-right",children:[J&&f.jsx("button",{className:"toolbar-btn toolbar-error-btn",onClick:()=>ee(null),title:J,children:"Analysis failed"}),f.jsx("button",{className:`toolbar-btn ${Ce?"active":""}`,onClick:()=>Ee(!Ce),children:"Stats"}),f.jsxs(kp,{trigger:Qr?"Exporting...":"↓ Export ▾",triggerClassName:"toolbar-btn",disabled:Qr,children:[f.jsx("div",{className:"dropdown-label",children:"Image"}),f.jsx("button",{className:"dropdown-item",onClick:Ss,children:"PNG — Raster image"}),f.jsx("button",{className:"dropdown-item",onClick:ks,children:"SVG — Vector image"}),f.jsx("div",{className:"dropdown-separator"}),f.jsx("div",{className:"dropdown-label",children:"Diagram"}),f.jsx("button",{className:"dropdown-item",onClick:()=>tr("mermaid"),children:"Mermaid — .mmd"}),f.jsx("button",{className:"dropdown-item",onClick:()=>tr("plantuml"),children:"PlantUML — .puml"}),f.jsx("button",{className:"dropdown-item",onClick:()=>tr("dot"),children:"Graphviz DOT — .dot"}),f.jsx("div",{className:"dropdown-separator"}),f.jsx("div",{className:"dropdown-label",children:"Document"}),f.jsx("button",{className:"dropdown-item",onClick:()=>tr("markdown"),children:"Markdown — .md"}),f.jsx("button",{className:"dropdown-item",onClick:()=>tr("json"),children:"JSON — .json"})]}),f.jsx("button",{className:"toolbar-btn-icon",onClick:()=>Kr(ut==="dark"?"light":"dark"),title:`Switch to ${ut==="dark"?"light":"dark"} mode`,children:ut==="dark"?"☀":"☽"})]})]}),f.jsx(hN,{selectedEnvironment:vt,environments:pn,onSelectEnvironment:An}),f.jsxs("div",{className:"canvas-container",children:[f.jsx("div",{className:"watermark",children:"archbyte"}),f.jsxs(hg,{nodes:t.map($=>({...$,draggable:!on.has($.id),data:{...$.data,locked:on.has($.id),isConnected:Qn.size>0?Qn.has($.id):null,isSearchMatch:gn?Es.has($.id):null}})),edges:s.map($=>{var W;return{...$,style:{...$.style,opacity:Qn.size>0?Qn.has($.id)?1:.15:1,strokeWidth:Qn.has($.id)?3:((W=$.style)==null?void 0:W.strokeWidth)||2}}}),onNodesChange:vr,onEdgesChange:u,onNodeClick:($,W)=>{xi($,W),eo(W.id)},onNodeDoubleClick:Ei,onPaneClick:()=>{wi(),eo(null),document.dispatchEvent(new Event("dropdown:closeall"))},onConnect:ki,onReconnect:Ve,edgesReconnectable:!0,onSelectionChange:Si,nodeTypes:XN,connectionMode:wo.Loose,snapToGrid:!0,snapGrid:[Bt,Bt],selectionOnDrag:!0,selectNodesOnDrag:!1,fitView:!0,fitViewOptions:{padding:.2},minZoom:.1,maxZoom:2,attributionPosition:"bottom-left",deleteKeyCode:null,children:[f.jsx(mg,{color:ut==="dark"?"hsl(220 25% 15%)":"hsl(220 15% 82%)",gap:20,variant:Yn.Dots}),f.jsx(yg,{})]}),ne&&f.jsxs("div",{className:"node-actions-panel",children:[f.jsxs("div",{className:"node-actions-title",children:[on.has(ne)&&f.jsx("span",{className:"lock-icon",children:"🔒"}),((Sn=(wn=t.find($=>$.id===ne))==null?void 0:wn.data)==null?void 0:Sn.label)||ne]}),f.jsxs("div",{className:"node-actions-buttons",children:[f.jsx("button",{className:`panel-btn ${on.has(ne)?"amber":"cyan"}`,onClick:()=>Sr(ne),title:"Lock/Unlock (Cmd+L)",children:on.has(ne)?"🔓 Unlock":"🔒 Lock"}),f.jsx("button",{className:"panel-btn red",onClick:()=>yi(ne),title:"Hide (Delete key)",children:"Hide"})]}),f.jsx("div",{className:"node-actions-hint",children:"Arrow keys to move • Shift for faster"})]}),mr&&tt&&f.jsxs("div",{className:"node-details-panel",children:[f.jsxs("div",{className:"node-details-header",children:[f.jsxs("div",{children:[f.jsx("div",{className:"node-details-title",children:tt.label.split(`
|
|
68
68
|
`)[0]}),f.jsxs("div",{className:"node-details-type",children:[tt.layer," • ",tt.type]})]}),f.jsx("button",{className:"panel-close-btn",onClick:()=>vn(!1),children:"×"})]}),tt.path&&f.jsxs("div",{className:"node-details-section",children:[f.jsx("div",{className:"node-details-section-title",children:"Path"}),f.jsx("div",{className:"node-details-path",children:tt.path})]}),tt.techStack&&tt.techStack.length>0&&f.jsxs("div",{className:"node-details-section",children:[f.jsx("div",{className:"node-details-section-title",children:"Tech Stack"}),f.jsx("div",{className:"node-details-tech-stack",children:tt.techStack.map(($,W)=>f.jsx("span",{className:"tech-badge",children:$},W))})]}),f.jsxs("div",{className:"node-details-section",children:[f.jsx("div",{className:"node-details-section-title",children:"Connections"}),f.jsxs("div",{className:"node-details-connections",children:[c==null?void 0:c.edges.filter($=>$.source===tt.id||$.target===tt.id).map($=>{const W=$.source===tt.id,te=W?$.target:$.source,se=c==null?void 0:c.nodes.find(ae=>ae.id===te);return f.jsxs("div",{className:"connection-item-detailed",children:[f.jsxs("div",{className:"connection-header",children:[f.jsx("span",{className:"connection-arrow",children:W?"→":"←"}),f.jsx("span",{className:"connection-target",children:(se==null?void 0:se.label.split(`
|
package/ui/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<title>ArchByte</title>
|
|
7
7
|
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png">
|
|
8
8
|
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16.png">
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-Bdr9FnaA.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-0_XpUUZQ.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { LLMProvider, ChatParams, LLMResponse, LLMChunk } from "../runtime/types.js";
|
|
2
|
-
export declare class OllamaProvider implements LLMProvider {
|
|
3
|
-
name: "ollama";
|
|
4
|
-
private baseUrl;
|
|
5
|
-
constructor(baseUrl?: string);
|
|
6
|
-
chat(params: ChatParams): Promise<LLMResponse>;
|
|
7
|
-
stream(params: ChatParams): AsyncIterable<LLMChunk>;
|
|
8
|
-
private toOllamaMessage;
|
|
9
|
-
}
|