groove-dev 0.27.63 → 0.27.64

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.
@@ -8601,7 +8601,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${a.do
8601
8601
  `);c=r<0?s:s.slice(0,r)}return a+c.length>this.to?c.slice(0,this.to-a):c}prevLineEnd(){return this.atEnd?this.lineStart:this.lineStart-1}startContext(a,s,c=0){this.block=bQ.create(a,c,this.lineStart+s,this.block.hash,this.lineStart+this.line.text.length),this.stack.push(this.block)}startComposite(a,s,c=0){this.startContext(this.parser.getNodeType(a),s,c)}addNode(a,s,c){typeof a=="number"&&(a=new bn(this.parser.nodeSet.types[a],a0,a0,(c??this.prevLineEnd())-s)),this.block.addChild(a,s-this.block.from)}addElement(a){this.block.addChild(a.toTree(this.parser.nodeSet),a.from-this.block.from)}addLeafElement(a,s){this.addNode(this.buffer.writeElements(vP(s.children,a.marks),-s.from).finish(s.type,s.to-s.from),s.from)}finishContext(){let a=this.stack.pop(),s=this.stack[this.stack.length-1];s.addChild(a.toTree(this.parser.nodeSet),a.from-s.from),this.block=s}finish(){for(;this.stack.length>1;)this.finishContext();return this.addGaps(this.block.toTree(this.parser.nodeSet,this.lineStart))}addGaps(a){return this.ranges.length>1?bH(this.ranges,0,a.topNode,this.ranges[0].from,this.reusePlaceholders):a}finishLeaf(a){for(let c of a.parsers)if(c.finish(this,a))return;let s=vP(this.parser.parseInline(a.content,a.start),a.marks);this.addNode(this.buffer.writeElements(s,-a.start).finish(me.Paragraph,a.content.length),a.start)}elt(a,s,c,r){return typeof a=="string"?Ue(this.parser.getNodeType(a),s,c,r):new jH(a,s)}get buffer(){return new MH(this.parser.nodeSet)}}function bH(t,a,s,c,r){let l=t[a].to,u=[],p=[],f=s.from+c;function x(g,y){for(;y?g>=l:g>l;){let k=t[a+1].from-l;c+=k,g+=k,a++,l=t[a].to}}for(let g=s.firstChild;g;g=g.nextSibling){x(g.from+c,!0);let y=g.from+c,k,b=r.get(g.tree);b?k=b:g.to+c>l?(k=bH(t,a,g,c,r),x(g.to+c,!1)):k=g.toTree(),u.push(k),p.push(y-f)}return x(s.to+c,!1),new bn(s.type,u,p,s.to+c-f,s.tree?s.tree.propValues:void 0)}class GQ extends CX{constructor(a,s,c,r,l,u,p,f,x){super(),this.nodeSet=a,this.blockParsers=s,this.leafBlockParsers=c,this.blockNames=r,this.endLeafBlock=l,this.skipContextMarkup=u,this.inlineParsers=p,this.inlineNames=f,this.wrappers=x,this.nodeTypes=Object.create(null);for(let g of a.types)this.nodeTypes[g.name]=g.id}createParse(a,s,c){let r=new zNe(this,a,s,c);for(let l of this.wrappers)r=l(r,a,s,c);return r}configure(a){let s=kP(a);if(!s)return this;let{nodeSet:c,skipContextMarkup:r}=this,l=this.blockParsers.slice(),u=this.leafBlockParsers.slice(),p=this.blockNames.slice(),f=this.inlineParsers.slice(),x=this.inlineNames.slice(),g=this.endLeafBlock.slice(),y=this.wrappers;if(s2(s.defineNodes)){r=Object.assign({},r);let k=c.types.slice(),b;for(let j of s.defineNodes){let{name:w,block:S,composite:M,style:$}=typeof j=="string"?{name:j}:j;if(k.some(P=>P.name==w))continue;M&&(r[k.length]=(P,L,A)=>M(L,A,P.value));let C=k.length,_=M?["Block","BlockContext"]:S?C>=me.ATXHeading1&&C<=me.SetextHeading2?["Block","LeafBlock","Heading"]:["Block","LeafBlock"]:void 0;k.push(eu.define({id:C,name:w,props:_&&[[Hs.group,_]]})),$&&(b||(b={}),Array.isArray($)||$ instanceof WW?b[w]=$:Object.assign(b,$))}c=new NP(k),b&&(c=c.extend(L1(b)))}if(s2(s.props)&&(c=c.extend(...s.props)),s2(s.remove))for(let k of s.remove){let b=this.blockNames.indexOf(k),j=this.inlineNames.indexOf(k);b>-1&&(l[b]=u[b]=void 0),j>-1&&(f[j]=void 0)}if(s2(s.parseBlock))for(let k of s.parseBlock){let b=p.indexOf(k.name);if(b>-1)l[b]=k.parse,u[b]=k.leaf;else{let j=k.before?Ih(p,k.before):k.after?Ih(p,k.after)+1:p.length-1;l.splice(j,0,k.parse),u.splice(j,0,k.leaf),p.splice(j,0,k.name)}k.endLeaf&&g.push(k.endLeaf)}if(s2(s.parseInline))for(let k of s.parseInline){let b=x.indexOf(k.name);if(b>-1)f[b]=k.parse;else{let j=k.before?Ih(x,k.before):k.after?Ih(x,k.after)+1:x.length-1;f.splice(j,0,k.parse),x.splice(j,0,k.name)}}return s.wrap&&(y=y.concat(s.wrap)),new GQ(c,l,u,p,g,r,f,x,y)}getNodeType(a){let s=this.nodeTypes[a];if(s==null)throw new RangeError(`Unknown node type '${a}'`);return s}parseInline(a,s){let c=new gA(this,a,s);e:for(let r=s;r<c.end;){let l=c.char(r);for(let u of this.inlineParsers)if(u){let p=u(c,l,r);if(p>=0){r=p;continue e}}r++}return c.resolveMarkers(0)}}function s2(t){return t!=null&&t.length>0}function kP(t){if(!Array.isArray(t))return t;if(t.length==0)return null;let a=kP(t[0]);if(t.length==1)return a;let s=kP(t.slice(1));if(!s||!a)return a||s;let c=(u,p)=>(u||a0).concat(p||a0),r=a.wrap,l=s.wrap;return{props:c(a.props,s.props),defineNodes:c(a.defineNodes,s.defineNodes),parseBlock:c(a.parseBlock,s.parseBlock),parseInline:c(a.parseInline,s.parseInline),remove:c(a.remove,s.remove),wrap:r?l?(u,p,f,x)=>r(l(u,p,f,x),p,f,x):r:l}}function Ih(t,a){let s=t.indexOf(a);if(s<0)throw new RangeError(`Position specified relative to unknown parser ${a}`);return s}let wH=[eu.none];for(let t=1,a;a=me[t];t++)wH[t]=eu.define({id:t,name:a,props:t>=me.Escape?[]:[[Hs.group,t in hH?["Block","BlockContext"]:["Block","LeafBlock"]]],top:a=="Document"});const a0=[];class MH{constructor(a){this.nodeSet=a,this.content=[],this.nodes=[]}write(a,s,c,r=0){return this.content.push(a,s,c,4+r*4),this}writeElements(a,s=0){for(let c of a)c.writeTo(this,s);return this}finish(a,s){return bn.build({buffer:this.content,nodeSet:this.nodeSet,reused:this.nodes,topID:a,length:s})}}let F2=class{constructor(a,s,c,r=a0){this.type=a,this.from=s,this.to=c,this.children=r}writeTo(a,s){let c=a.content.length;a.writeElements(this.children,s),a.content.push(this.type,this.from+s,this.to+s,a.content.length+4-c)}toTree(a){return new MH(a).writeElements(this.children,-this.from).finish(this.type,this.to-this.from)}};class jH{constructor(a,s){this.tree=a,this.from=s}get to(){return this.from+this.tree.length}get type(){return this.tree.type.id}get children(){return a0}writeTo(a,s){a.nodes.push(this.tree),a.content.push(a.nodes.length-1,this.from+s,this.to+s,-1)}toTree(){return this.tree}}function Ue(t,a,s,c){return new F2(t,a,s,c)}const SH={resolve:"Emphasis",mark:"EmphasisMark"},NH={resolve:"Emphasis",mark:"EmphasisMark"},d1={},wQ={};class Ta{constructor(a,s,c,r){this.type=a,this.from=s,this.to=c,this.side=r}}const WE="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";let K2=/[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;try{K2=new RegExp("[\\p{S}|\\p{P}]","u")}catch{}const XT={Escape(t,a,s){if(a!=92||s==t.end-1)return-1;let c=t.char(s+1);for(let r=0;r<WE.length;r++)if(WE.charCodeAt(r)==c)return t.append(Ue(me.Escape,s,s+2));return-1},Entity(t,a,s){if(a!=38)return-1;let c=/^(?:#\d+|#x[a-f\d]+|\w+);/i.exec(t.slice(s+1,s+31));return c?t.append(Ue(me.Entity,s,s+1+c[0].length)):-1},InlineCode(t,a,s){if(a!=96||s&&t.char(s-1)==96)return-1;let c=s+1;for(;c<t.end&&t.char(c)==96;)c++;let r=c-s,l=0;for(;c<t.end;c++)if(t.char(c)==96){if(l++,l==r&&t.char(c+1)!=96)return t.append(Ue(me.InlineCode,s,c+1,[Ue(me.CodeMark,s,s+r),Ue(me.CodeMark,c+1-r,c+1)]))}else l=0;return-1},HTMLTag(t,a,s){if(a!=60||s==t.end-1)return-1;let c=t.slice(s+1,t.end),r=/^(?:[a-z][-\w+.]+:[^\s>]+|[a-z\d.!#$%&'*+/=?^_`{|}~-]+@[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?)*)>/i.exec(c);if(r)return t.append(Ue(me.Autolink,s,s+1+r[0].length,[Ue(me.LinkMark,s,s+1),Ue(me.URL,s+1,s+r[0].length),Ue(me.LinkMark,s+r[0].length,s+1+r[0].length)]));let l=/^!--[^>](?:-[^-]|[^-])*?-->/i.exec(c);if(l)return t.append(Ue(me.Comment,s,s+1+l[0].length));let u=/^\?[^]*?\?>/.exec(c);if(u)return t.append(Ue(me.ProcessingInstruction,s,s+1+u[0].length));let p=/^(?:![A-Z][^]*?>|!\[CDATA\[[^]*?\]\]>|\/\s*[a-zA-Z][\w-]*\s*>|\s*[a-zA-Z][\w-]*(\s+[a-zA-Z:_][\w-.:]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*(\/\s*)?>)/.exec(c);return p?t.append(Ue(me.HTMLTag,s,s+1+p[0].length)):-1},Emphasis(t,a,s){if(a!=95&&a!=42)return-1;let c=s+1;for(;t.char(c)==a;)c++;let r=t.slice(s-1,s),l=t.slice(c,c+1),u=K2.test(r),p=K2.test(l),f=/\s|^$/.test(r),x=/\s|^$/.test(l),g=!x&&(!p||f||u),y=!f&&(!u||x||p),k=g&&(a==42||!y||u),b=y&&(a==42||!g||p);return t.append(new Ta(a==95?SH:NH,s,c,(k?1:0)|(b?2:0)))},HardBreak(t,a,s){if(a==92&&t.char(s+1)==10)return t.append(Ue(me.HardBreak,s,s+2));if(a==32){let c=s+1;for(;t.char(c)==32;)c++;if(t.char(c)==10&&c>=s+2)return t.append(Ue(me.HardBreak,s,c+1))}return-1},Link(t,a,s){return a==91?t.append(new Ta(d1,s,s+1,1)):-1},Image(t,a,s){return a==33&&t.char(s+1)==91?t.append(new Ta(wQ,s,s+2,1)):-1},LinkEnd(t,a,s){if(a!=93)return-1;for(let c=t.parts.length-1;c>=0;c--){let r=t.parts[c];if(r instanceof Ta&&(r.type==d1||r.type==wQ)){if(!r.side||t.skipSpace(r.to)==s&&!/[(\[]/.test(t.slice(s+1,s+2)))return t.parts[c]=null,-1;let l=t.takeContent(c),u=t.parts[c]=TNe(t,l,r.type==d1?me.Link:me.Image,r.from,s+1);if(r.type==d1)for(let p=0;p<c;p++){let f=t.parts[p];f instanceof Ta&&f.type==d1&&(f.side=0)}return u.to}}return-1}};function TNe(t,a,s,c,r){let{text:l}=t,u=t.char(r),p=r;if(a.unshift(Ue(me.LinkMark,c,c+(s==me.Image?2:1))),a.push(Ue(me.LinkMark,r-1,r)),u==40){let f=t.skipSpace(r+1),x=_H(l,f-t.offset,t.offset),g;x&&(f=t.skipSpace(x.to),f!=x.to&&(g=$H(l,f-t.offset,t.offset),g&&(f=t.skipSpace(g.to)))),t.char(f)==41&&(a.push(Ue(me.LinkMark,r,r+1)),p=f+1,x&&a.push(x),g&&a.push(g),a.push(Ue(me.LinkMark,f,p)))}else if(u==91){let f=CH(l,r-t.offset,t.offset,!1);f&&(a.push(f),p=f.to)}return Ue(s,c,p,a)}function _H(t,a,s){if(t.charCodeAt(a)==60){for(let r=a+1;r<t.length;r++){let l=t.charCodeAt(r);if(l==62)return Ue(me.URL,a+s,r+1+s);if(l==60||l==10)return!1}return null}else{let r=0,l=a;for(let u=!1;l<t.length;l++){let p=t.charCodeAt(l);if(ln(p))break;if(u)u=!1;else if(p==40)r++;else if(p==41){if(!r)break;r--}else p==92&&(u=!0)}return l>a?Ue(me.URL,a+s,l+s):l==t.length?null:!1}}function $H(t,a,s){let c=t.charCodeAt(a);if(c!=39&&c!=34&&c!=40)return!1;let r=c==40?41:c;for(let l=a+1,u=!1;l<t.length;l++){let p=t.charCodeAt(l);if(u)u=!1;else{if(p==r)return Ue(me.LinkTitle,a+s,l+1+s);p==92&&(u=!0)}}return null}function CH(t,a,s,c){for(let r=!1,l=a+1,u=Math.min(t.length,l+999);l<u;l++){let p=t.charCodeAt(l);if(r)r=!1;else{if(p==93)return c?!1:Ue(me.LinkLabel,a+s,l+1+s);if(c&&!ln(p)&&(c=!1),p==91)return!1;p==92&&(r=!0)}}return null}class gA{constructor(a,s,c){this.parser=a,this.text=s,this.offset=c,this.parts=[]}char(a){return a>=this.end?-1:this.text.charCodeAt(a-this.offset)}get end(){return this.offset+this.text.length}slice(a,s){return this.text.slice(a-this.offset,s-this.offset)}append(a){return this.parts.push(a),a.to}addDelimiter(a,s,c,r,l){return this.append(new Ta(a,s,c,(r?1:0)|(l?2:0)))}get hasOpenLink(){for(let a=this.parts.length-1;a>=0;a--){let s=this.parts[a];if(s instanceof Ta&&(s.type==d1||s.type==wQ))return!0}return!1}addElement(a){return this.append(a)}resolveMarkers(a){for(let c=a;c<this.parts.length;c++){let r=this.parts[c];if(!(r instanceof Ta&&r.type.resolve&&r.side&2))continue;let l=r.type==SH||r.type==NH,u=r.to-r.from,p,f=c-1;for(;f>=a;f--){let w=this.parts[f];if(w instanceof Ta&&w.side&1&&w.type==r.type&&!(l&&(r.side&1||w.side&2)&&(w.to-w.from+u)%3==0&&((w.to-w.from)%3||u%3))){p=w;break}}if(!p)continue;let x=r.type.resolve,g=[],y=p.from,k=r.to;if(l){let w=Math.min(2,p.to-p.from,u);y=p.to-w,k=r.from+w,x=w==1?"Emphasis":"StrongEmphasis"}p.type.mark&&g.push(this.elt(p.type.mark,y,p.to));for(let w=f+1;w<c;w++)this.parts[w]instanceof F2&&g.push(this.parts[w]),this.parts[w]=null;r.type.mark&&g.push(this.elt(r.type.mark,r.from,k));let b=this.elt(x,y,k,g);this.parts[f]=l&&p.from!=y?new Ta(p.type,p.from,y,p.side):null,(this.parts[c]=l&&r.to!=k?new Ta(r.type,k,r.to,r.side):null)?this.parts.splice(c,0,b):this.parts[c]=b}let s=[];for(let c=a;c<this.parts.length;c++){let r=this.parts[c];r instanceof F2&&s.push(r)}return s}findOpeningDelimiter(a){for(let s=this.parts.length-1;s>=0;s--){let c=this.parts[s];if(c instanceof Ta&&c.type==a&&c.side&1)return s}return null}takeContent(a){let s=this.resolveMarkers(a);return this.parts.length=a,s}getDelimiterAt(a){let s=this.parts[a];return s instanceof Ta?s:null}skipSpace(a){return E2(this.text,a-this.offset)+this.offset}elt(a,s,c,r){return typeof a=="string"?Ue(this.parser.getNodeType(a),s,c,r):new jH(a,s)}}gA.linkStart=d1;gA.imageStart=wQ;function vP(t,a){if(!a.length)return t;if(!t.length)return a;let s=t.slice(),c=0;for(let r of a){for(;c<s.length&&s[c].to<r.to;)c++;if(c<s.length&&s[c].from<r.from){let l=s[c];l instanceof F2&&(s[c]=new F2(l.type,l.from,l.to,vP(l.children,[r])))}else s.splice(c++,0,r)}return s}const PNe=[me.CodeBlock,me.ListItem,me.OrderedList,me.BulletList];class ANe{constructor(a,s){this.fragments=a,this.input=s,this.i=0,this.fragment=null,this.fragmentEnd=-1,this.cursor=null,a.length&&(this.fragment=a[this.i++])}nextFragment(){this.fragment=this.i<this.fragments.length?this.fragments[this.i++]:null,this.cursor=null,this.fragmentEnd=-1}moveTo(a,s){for(;this.fragment&&this.fragment.to<=a;)this.nextFragment();if(!this.fragment||this.fragment.from>(a?a-1:0))return!1;if(this.fragmentEnd<0){let l=this.fragment.to;for(;l>0&&this.input.read(l-1,l)!=`
8602
8602
  `;)l--;this.fragmentEnd=l?l-1:0}let c=this.cursor;c||(c=this.cursor=this.fragment.tree.cursor(),c.firstChild());let r=a+this.fragment.offset;for(;c.to<=r;)if(!c.parent())return!1;for(;;){if(c.from>=r)return this.fragment.from<=s;if(!c.childAfter(r))return!1}}matches(a){let s=this.cursor.tree;return s&&s.prop(Hs.contextHash)==a}takeNodes(a){let s=this.cursor,c=this.fragment.offset,r=this.fragmentEnd-(this.fragment.openEnd?1:0),l=a.absoluteLineStart,u=l,p=a.block.children.length,f=u,x=p;for(;;){if(s.to-c>r){if(s.type.isAnonymous&&s.firstChild())continue;break}let g=QH(s.from-c,a.ranges);if(s.to-c<=a.ranges[a.rangeI].to)a.addNode(s.tree,g);else{let y=new bn(a.parser.nodeSet.types[me.Paragraph],[],[],0,a.block.hashProp);a.reusePlaceholders.set(y,s.tree),a.addNode(y,g)}if(s.type.is("Block")&&(PNe.indexOf(s.type.id)<0?(u=s.to-c,p=a.block.children.length):(u=f,p=x),f=s.to-c,x=a.block.children.length),!s.nextSibling())break}for(;a.block.children.length>p;)a.block.children.pop(),a.block.positions.pop();return u-l}}function QH(t,a){let s=t;for(let c=1;c<a.length;c++){let r=a[c-1].to,l=a[c].from;r<t&&(s-=l-r)}return s}const qNe=L1({"Blockquote/...":B.quote,HorizontalRule:B.contentSeparator,"ATXHeading1/... SetextHeading1/...":B.heading1,"ATXHeading2/... SetextHeading2/...":B.heading2,"ATXHeading3/...":B.heading3,"ATXHeading4/...":B.heading4,"ATXHeading5/...":B.heading5,"ATXHeading6/...":B.heading6,"Comment CommentBlock":B.comment,Escape:B.escape,Entity:B.character,"Emphasis/...":B.emphasis,"StrongEmphasis/...":B.strong,"Link/... Image/...":B.link,"OrderedList/... BulletList/...":B.list,"BlockQuote/...":B.quote,"InlineCode CodeText":B.monospace,"URL Autolink":B.url,"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark":B.processingInstruction,"CodeInfo LinkLabel":B.labelName,LinkTitle:B.string,Paragraph:B.content}),INe=new GQ(new NP(wH).extend(qNe),Object.keys(qh).map(t=>qh[t]),Object.keys(qh).map(t=>vH[t]),Object.keys(qh),QNe,hH,Object.keys(XT).map(t=>XT[t]),Object.keys(XT),[]);function RNe(t,a,s){let c=[];for(let r=t.firstChild,l=a;;r=r.nextSibling){let u=r?r.from:s;if(u>l&&c.push({from:l,to:u}),!r)break;l=r.to}return c}function VNe(t){let{codeParser:a,htmlParser:s}=t;return{wrap:PX((r,l)=>{let u=r.type.id;if(a&&(u==me.CodeBlock||u==me.FencedCode)){let p="";if(u==me.FencedCode){let x=r.node.getChild(me.CodeInfo);x&&(p=l.read(x.from,x.to))}let f=a(p);if(f)return{parser:f,overlay:x=>x.type.id==me.CodeText,bracketed:u==me.FencedCode}}else if(s&&(u==me.HTMLBlock||u==me.HTMLTag||u==me.CommentBlock))return{parser:s,overlay:RNe(r.node,r.from,r.to)};return null})}}const ENe={resolve:"Strikethrough",mark:"StrikethroughMark"},XNe={defineNodes:[{name:"Strikethrough",style:{"Strikethrough/...":B.strikethrough}},{name:"StrikethroughMark",style:B.processingInstruction}],parseInline:[{name:"Strikethrough",parse(t,a,s){if(a!=126||t.char(s+1)!=126||t.char(s+2)==126)return-1;let c=t.slice(s-1,s),r=t.slice(s+2,s+3),l=/\s|^$/.test(c),u=/\s|^$/.test(r),p=K2.test(c),f=K2.test(r);return t.addDelimiter(ENe,s,s+2,!u&&(!f||l||p),!l&&(!p||u||f))},after:"Emphasis"}]};function X2(t,a,s=0,c,r=0){let l=0,u=!0,p=-1,f=-1,x=!1,g=()=>{c.push(t.elt("TableCell",r+p,r+f,t.parser.parseInline(a.slice(p,f),r+p)))};for(let y=s;y<a.length;y++){let k=a.charCodeAt(y);k==124&&!x?((!u||p>-1)&&l++,u=!1,c&&(p>-1&&g(),c.push(t.elt("TableDelimiter",y+r,y+r+1))),p=f=-1):(x||k!=32&&k!=9)&&(p<0&&(p=y),f=y+1),x=!x&&k==92}return p>-1&&(l++,c&&g()),l}function YE(t,a){for(let s=a;s<t.length;s++){let c=t.charCodeAt(s);if(c==124)return!0;c==92&&s++}return!1}const LH=/^\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/;class FE{constructor(){this.rows=null}nextLine(a,s,c){if(this.rows==null){this.rows=!1;let r;if((s.next==45||s.next==58||s.next==124)&&LH.test(r=s.text.slice(s.pos))){let l=[];X2(a,c.content,0,l,c.start)==X2(a,r,s.pos)&&(this.rows=[a.elt("TableHeader",c.start,c.start+c.content.length,l),a.elt("TableDelimiter",a.lineStart+s.pos,a.lineStart+s.text.length)])}}else if(this.rows){let r=[];X2(a,s.text,s.pos,r,a.lineStart),this.rows.push(a.elt("TableRow",a.lineStart+s.pos,a.lineStart+s.text.length,r))}return!1}finish(a,s){return this.rows?(a.addLeafElement(s,a.elt("Table",s.start,s.start+s.content.length,this.rows)),!0):!1}}const ZNe={defineNodes:[{name:"Table",block:!0},{name:"TableHeader",style:{"TableHeader/...":B.heading}},"TableRow",{name:"TableCell",style:B.content},{name:"TableDelimiter",style:B.processingInstruction}],parseBlock:[{name:"Table",leaf(t,a){return YE(a.content,0)?new FE:null},endLeaf(t,a,s){if(s.parsers.some(r=>r instanceof FE)||!YE(a.text,a.basePos))return!1;let c=t.peekLine();return LH.test(c)&&X2(t,a.text,a.basePos)==X2(t,c,a.basePos)},before:"SetextHeading"}]};class DNe{nextLine(){return!1}finish(a,s){return a.addLeafElement(s,a.elt("Task",s.start,s.start+s.content.length,[a.elt("TaskMarker",s.start,s.start+3),...a.parser.parseInline(s.content.slice(3),s.start+3)])),!0}}const UNe={defineNodes:[{name:"Task",block:!0,style:B.list},{name:"TaskMarker",style:B.atom}],parseBlock:[{name:"TaskList",leaf(t,a){return/^\[[ xX]\][ \t]/.test(a.content)&&t.parentType().name=="ListItem"?new DNe:null},after:"SetextHeading"}]},KE=/(www\.)|(https?:\/\/)|([\w.+-]{1,100}@)|(mailto:|xmpp:)/gy,JE=/[\w-]+(\.[\w-]+)+(\/[^\s<]*)?/gy,HNe=/[\w-]+\.[\w-]+($|\/)/,eX=/[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy,tX=/\/[a-zA-Z\d@.]+/gy;function aX(t,a,s,c){let r=0;for(let l=a;l<s;l++)t[l]==c&&r++;return r}function BNe(t,a){JE.lastIndex=a;let s=JE.exec(t);if(!s||HNe.exec(s[0])[0].indexOf("_")>-1)return-1;let c=a+s[0].length;for(;;){let r=t[c-1],l;if(/[?!.,:*_~]/.test(r)||r==")"&&aX(t,a,c,")")>aX(t,a,c,"("))c--;else if(r==";"&&(l=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(t.slice(a,c))))c=a+l.index;else break}return c}function nX(t,a){eX.lastIndex=a;let s=eX.exec(t);if(!s)return-1;let c=s[0][s[0].length-1];return c=="_"||c=="-"?-1:a+s[0].length-(c=="."?1:0)}const GNe={parseInline:[{name:"Autolink",parse(t,a,s){let c=s-t.offset;if(c&&/\w/.test(t.text[c-1]))return-1;KE.lastIndex=c;let r=KE.exec(t.text),l=-1;if(!r)return-1;if(r[1]||r[2]){if(l=BNe(t.text,c+r[0].length),l>-1&&t.hasOpenLink){let u=/([^\[\]]|\[[^\]]*\])*/.exec(t.text.slice(c,l));l=c+u[0].length}}else r[3]?l=nX(t.text,c):(l=nX(t.text,c+r[0].length),l>-1&&r[0]=="xmpp:"&&(tX.lastIndex=l,r=tX.exec(t.text),r&&(l=r.index+r[0].length)));return l<0?-1:(t.addElement(t.elt("URL",s,l+t.offset)),l+t.offset)}}]},WNe=[ZNe,UNe,XNe,GNe];function zH(t,a,s){return(c,r,l)=>{if(r!=t||c.char(l+1)==t)return-1;let u=[c.elt(s,l,l+1)];for(let p=l+1;p<c.end;p++){let f=c.char(p);if(f==t)return c.addElement(c.elt(a,l,p+1,u.concat(c.elt(s,p,p+1))));if(f==92&&u.push(c.elt("Escape",p,p+++2)),ln(f))break}return-1}}const YNe={defineNodes:[{name:"Superscript",style:B.special(B.content)},{name:"SuperscriptMark",style:B.processingInstruction}],parseInline:[{name:"Superscript",parse:zH(94,"Superscript","SuperscriptMark")}]},FNe={defineNodes:[{name:"Subscript",style:B.special(B.content)},{name:"SubscriptMark",style:B.processingInstruction}],parseInline:[{name:"Subscript",parse:zH(126,"Subscript","SubscriptMark")}]},KNe={defineNodes:[{name:"Emoji",style:B.character}],parseInline:[{name:"Emoji",parse(t,a,s){let c;return a!=58||!(c=/^[a-zA-Z_0-9]+:/.exec(t.slice(s+1,t.end)))?-1:t.addElement(t.elt("Emoji",s,s+1+c[0].length))}}]},TH=TX({commentTokens:{block:{open:"<!--",close:"-->"}}}),PH=new Hs,AH=INe.configure({props:[z1.add(t=>!t.is("Block")||t.is("Document")||bP(t)!=null||JNe(t)?void 0:(a,s)=>({from:s.doc.lineAt(a.from).to,to:a.to})),PH.add(bP),s0.add({Document:()=>null}),tY.add({Document:TH})]});function bP(t){let a=/^(?:ATX|Setext)Heading(\d)$/.exec(t.name);return a?+a[1]:void 0}function JNe(t){return t.name=="OrderedList"||t.name=="BulletList"}function e_e(t,a){let s=t;for(;;){let c=s.nextSibling,r;if(!c||(r=bP(c.type))!=null&&r<=a)break;s=c}return s.to}const t_e=FW.of((t,a,s)=>{for(let c=Cn(t).resolveInner(s,-1);c&&!(c.from<a);c=c.parent){let r=c.type.prop(PH);if(r==null)continue;let l=e_e(c,r);if(l>s)return{from:s,to:l}}return null});function OA(t){return new KW(TH,t,[],"markdown")}const a_e=OA(AH),n_e=AH.configure([WNe,FNe,YNe,KNe,{props:[z1.add({Table:(t,a)=>({from:a.doc.lineAt(t.from).to,to:t.to})})]}]),MQ=OA(n_e);function s_e(t,a){return s=>{if(s&&t){let c=null;if(s=/\S*/.exec(s)[0],typeof t=="function"?c=t(s):c=SV.matchLanguageName(t,s,!0),c instanceof SV)return c.support?c.support.language.parser:aY.getSkippingParser(c.load());if(c)return c.parser}return a?a.parser:null}}let ZT=class{constructor(a,s,c,r,l,u,p){this.node=a,this.from=s,this.to=c,this.spaceBefore=r,this.spaceAfter=l,this.type=u,this.item=p}blank(a,s=!0){let c=this.spaceBefore+(this.node.name=="Blockquote"?">":"");if(a!=null){for(;c.length<a;)c+=" ";return c}else{for(let r=this.to-this.from-c.length-this.spaceAfter.length;r>0;r--)c+=" ";return c+(s?this.spaceAfter:"")}}marker(a,s){let c=this.node.name=="OrderedList"?String(+IH(this.item,a)[2]+s):"";return this.spaceBefore+c+this.type+this.spaceAfter}};function qH(t,a){let s=[],c=[];for(let r=t;r;r=r.parent){if(r.name=="FencedCode")return c;(r.name=="ListItem"||r.name=="Blockquote")&&s.push(r)}for(let r=s.length-1;r>=0;r--){let l=s[r],u,p=a.lineAt(l.from),f=l.from-p.from;if(l.name=="Blockquote"&&(u=/^ *>( ?)/.exec(p.text.slice(f))))c.push(new ZT(l,f,f+u[0].length,"",u[1],">",null));else if(l.name=="ListItem"&&l.parent.name=="OrderedList"&&(u=/^( *)\d+([.)])( *)/.exec(p.text.slice(f)))){let x=u[3],g=u[0].length;x.length>=4&&(x=x.slice(0,x.length-4),g-=4),c.push(new ZT(l.parent,f,f+g,u[1],x,u[2],l))}else if(l.name=="ListItem"&&l.parent.name=="BulletList"&&(u=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(p.text.slice(f)))){let x=u[4],g=u[0].length;x.length>4&&(x=x.slice(0,x.length-4),g-=4);let y=u[2];u[3]&&(y+=u[3].replace(/[xX]/," ")),c.push(new ZT(l.parent,f,f+g,u[1],x,y,l))}}return c}function IH(t,a){return/^(\s*)(\d+)(?=[.)])/.exec(a.sliceString(t.from,t.from+10))}function DT(t,a,s,c=0){for(let r=-1,l=t;;){if(l.name=="ListItem"){let p=IH(l,a),f=+p[2];if(r>=0){if(f!=r+1)return;s.push({from:l.from+p[1].length,to:l.from+p[0].length,insert:String(r+2+c)})}r=f}let u=l.nextSibling;if(!u)break;l=u}}function kA(t,a){let s=/^[ \t]*/.exec(t)[0].length;if(!s||a.facet(JW)!=" ")return t;let c=Z2(t,4,s),r="";for(let l=c;l>0;)l>=4?(r+=" ",l-=4):(r+=" ",l--);return r+t.slice(s)}const o_e=(t={})=>({state:a,dispatch:s})=>{let c=Cn(a),{doc:r}=a,l=null,u=a.changeByRange(p=>{if(!p.empty||!MQ.isActiveAt(a,p.from,-1)&&!MQ.isActiveAt(a,p.from,1))return l={range:p};let f=p.from,x=r.lineAt(f),g=qH(c.resolveInner(f,-1),r);for(;g.length&&g[g.length-1].from>f-x.from;)g.pop();if(!g.length)return l={range:p};let y=g[g.length-1];if(y.to-y.spaceAfter.length>f-x.from)return l={range:p};let k=f>=y.to-y.spaceAfter.length&&!/\S/.test(x.text.slice(y.to));if(y.item&&k){let M=y.node.firstChild,$=y.node.getChild("ListItem","ListItem");if(M.to>=f||$&&$.to<f||x.from>0&&!/[^\s>]/.test(r.lineAt(x.from-1).text)||t.nonTightLists===!1){let C=g.length>1?g[g.length-2]:null,_,P="";C&&C.item?(_=x.from+C.from,P=C.marker(r,1)):_=x.from+(C?C.to:0);let L=[{from:_,to:f,insert:P}];return y.node.name=="OrderedList"&&DT(y.item,r,L,-2),C&&C.node.name=="OrderedList"&&DT(C.item,r,L),{range:Io.cursor(_+P.length),changes:L}}else{let C=oX(g,a,x);return{range:Io.cursor(f+C.length+1),changes:{from:x.from,insert:C+a.lineBreak}}}}if(y.node.name=="Blockquote"&&k&&x.from){let M=r.lineAt(x.from-1),$=/>\s*$/.exec(M.text);if($&&$.index==y.from){let C=a.changes([{from:M.from+$.index,to:M.to},{from:x.from+y.from,to:x.to}]);return{range:p.map(C),changes:C}}}let b=[];y.node.name=="OrderedList"&&DT(y.item,r,b);let j=y.item&&y.item.from<x.from,w="";if(!j||/^[\s\d.)\-+*>]*/.exec(x.text)[0].length>=y.to)for(let M=0,$=g.length-1;M<=$;M++)w+=M==$&&!j?g[M].marker(r,1):g[M].blank(M<$?Z2(x.text,4,g[M+1].from)-w.length:null);let S=f;for(;S>x.from&&/\s/.test(x.text.charAt(S-x.from-1));)S--;return w=kA(w,a),r_e(y.node,a.doc)&&(w=oX(g,a,x)+a.lineBreak+w),b.push({from:S,to:f,insert:a.lineBreak+w}),{range:Io.cursor(S+w.length+1),changes:b}});return l?!1:(s(a.update(u,{scrollIntoView:!0,userEvent:"input"})),!0)},c_e=o_e();function sX(t){return t.name=="QuoteMark"||t.name=="ListMark"}function r_e(t,a){if(t.name!="OrderedList"&&t.name!="BulletList")return!1;let s=t.firstChild,c=t.getChild("ListItem","ListItem");if(!c)return!1;let r=a.lineAt(s.to),l=a.lineAt(c.from),u=/^[\s>]*$/.test(r.text);return r.number+(u?0:1)<l.number}function oX(t,a,s){let c="";for(let r=0,l=t.length-2;r<=l;r++)c+=t[r].blank(r<l?Z2(s.text,4,t[r+1].from)-c.length:null,r<l);return kA(c,a)}function i_e(t,a){let s=t.resolveInner(a,-1),c=a;sX(s)&&(c=s.from,s=s.parent);for(let r;r=s.childBefore(c);)if(sX(r))c=r.from;else if(r.name=="OrderedList"||r.name=="BulletList")s=r.lastChild,c=s.to;else break;return s}const l_e=({state:t,dispatch:a})=>{let s=Cn(t),c=null,r=t.changeByRange(l=>{let u=l.from,{doc:p}=t;if(l.empty&&MQ.isActiveAt(t,l.from)){let f=p.lineAt(u),x=qH(i_e(s,u),p);if(x.length){let g=x[x.length-1],y=g.to-g.spaceAfter.length+(g.spaceAfter?1:0);if(u-f.from>y&&!/\S/.test(f.text.slice(y,u-f.from)))return{range:Io.cursor(f.from+y),changes:{from:f.from+y,to:u}};if(u-f.from==y&&(!g.item||f.from<=g.item.from||!/\S/.test(f.text.slice(0,g.to)))){let k=f.from+g.from;if(g.item&&g.node.from<g.item.from&&/\S/.test(f.text.slice(g.from,g.to))){let b=g.blank(Z2(f.text,4,g.to)-Z2(f.text,4,g.from));return k==f.from&&(b=kA(b,t)),{range:Io.cursor(k+b.length),changes:{from:k,to:f.from+g.to,insert:b}}}if(k<u)return{range:Io.cursor(k),changes:{from:k,to:u}}}}}return c={range:l}});return c?!1:(a(t.update(r,{scrollIntoView:!0,userEvent:"delete"})),!0)},d_e=[{key:"Enter",run:c_e},{key:"Backspace",run:l_e}],RH=uH({matchClosingTags:!1});function u_e(t={}){let{codeLanguages:a,defaultCodeLanguage:s,addKeymap:c=!0,base:{parser:r}=a_e,completeHTMLTags:l=!0,pasteURLAsLink:u=!0,htmlTagLanguage:p=RH}=t;if(!(r instanceof GQ))throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");let f=t.extensions?[t.extensions]:[],x=[p.support,t_e],g;u&&x.push(x_e),s instanceof N1?(x.push(s.support),g=s.language):s&&(g=s);let y=a||g?s_e(a,g):void 0;f.push(VNe({codeParser:y,htmlParser:p.language.parser})),c&&x.push(YW.high(aP.of(d_e)));let k=OA(r.configure(f));return l&&x.push(k.data.of({autocomplete:h_e})),new N1(k,x)}function h_e(t){let{state:a,pos:s}=t,c=/<[:\-\.\w\u00b7-\uffff]*$/.exec(a.sliceDoc(s-25,s));if(!c)return null;let r=Cn(a).resolveInner(s,-1);for(;r&&!r.type.isTop;){if(r.name=="CodeBlock"||r.name=="FencedCode"||r.name=="ProcessingInstructionBlock"||r.name=="CommentBlock"||r.name=="Link"||r.name=="Image")return null;r=r.parent}return{from:s-c[0].length,to:s,options:p_e(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}let UT=null;function p_e(){if(UT)return UT;let t=ONe(new eY(AX.create({extensions:RH}),0,!0));return UT=t?t.options:[]}const f_e=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,x_e=Yd.domEventHandlers({paste:(t,a)=>{var s;let{main:c}=a.state.selection;if(c.empty)return!1;let r=(s=t.clipboardData)===null||s===void 0?void 0:s.getData("text/plain");if(!r||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(r)||(/^www\./.test(r)&&(r="https://"+r),!MQ.isActiveAt(a.state,c.from,1)))return!1;let l=Cn(a.state),u=!1;return l.iterate({from:c.from,to:c.to,enter:p=>{(p.from>c.from||f_e.test(p.name))&&(u=!0)},leave:p=>{p.to<c.to&&(u=!0)}}),u?!1:(a.dispatch({changes:[{from:c.from,insert:"["},{from:c.to,insert:`](${r})`}],userEvent:"input.paste",scrollIntoView:!0}),!0)}}),m_e=1,VH=194,EH=195,y_e=196,cX=197,g_e=198,O_e=199,k_e=200,v_e=2,XH=3,rX=201,b_e=24,w_e=25,M_e=49,j_e=50,S_e=55,N_e=56,__e=57,$_e=59,C_e=60,Q_e=61,L_e=62,z_e=63,T_e=65,P_e=238,A_e=71,q_e=241,I_e=242,R_e=243,V_e=244,E_e=245,X_e=246,Z_e=247,D_e=248,ZH=72,U_e=249,H_e=250,B_e=251,G_e=252,W_e=253,Y_e=254,F_e=255,K_e=256,J_e=73,e$e=77,t$e=263,a$e=112,n$e=130,s$e=151,o$e=152,c$e=155,Q1=10,J2=13,vA=32,WQ=9,bA=35,r$e=40,i$e=46,wP=123,iX=125,DH=39,UH=34,lX=92,l$e=111,d$e=120,u$e=78,h$e=117,p$e=85,f$e=new Set([w_e,M_e,j_e,t$e,T_e,n$e,N_e,__e,P_e,L_e,z_e,ZH,J_e,e$e,C_e,Q_e,s$e,o$e,c$e,a$e]);function HT(t){return t==Q1||t==J2}function BT(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}const x$e=new Ft((t,a)=>{let s;if(t.next<0)t.acceptToken(O_e);else if(a.context.flags&aQ)HT(t.next)&&t.acceptToken(g_e,1);else if(((s=t.peek(-1))<0||HT(s))&&a.canShift(cX)){let c=0;for(;t.next==vA||t.next==WQ;)t.advance(),c++;(t.next==Q1||t.next==J2||t.next==bA)&&t.acceptToken(cX,-c)}else HT(t.next)&&t.acceptToken(y_e,1)},{contextual:!0}),m$e=new Ft((t,a)=>{let s=a.context;if(s.flags)return;let c=t.peek(-1);if(c==Q1||c==J2){let r=0,l=0;for(;;){if(t.next==vA)r++;else if(t.next==WQ)r+=8-r%8;else break;t.advance(),l++}r!=s.indent&&t.next!=Q1&&t.next!=J2&&t.next!=bA&&(r<s.indent?t.acceptToken(EH,-l):t.acceptToken(VH))}}),aQ=1,HH=2,$s=4,Cs=8,Qs=16,Ls=32;function nQ(t,a,s){this.parent=t,this.indent=a,this.flags=s,this.hash=(t?t.hash+t.hash<<8:0)+a+(a<<4)+s+(s<<6)}const y$e=new nQ(null,0,0);function g$e(t){let a=0;for(let s=0;s<t.length;s++)a+=t.charCodeAt(s)==WQ?8-a%8:1;return a}const dX=new Map([[q_e,0],[I_e,$s],[R_e,Cs],[V_e,Cs|$s],[E_e,Qs],[X_e,Qs|$s],[Z_e,Qs|Cs],[D_e,Qs|Cs|$s],[U_e,Ls],[H_e,Ls|$s],[B_e,Ls|Cs],[G_e,Ls|Cs|$s],[W_e,Ls|Qs],[Y_e,Ls|Qs|$s],[F_e,Ls|Qs|Cs],[K_e,Ls|Qs|Cs|$s]].map(([t,a])=>[t,a|HH])),O$e=new lA({start:y$e,reduce(t,a,s,c){return t.flags&aQ&&f$e.has(a)||(a==A_e||a==ZH)&&t.flags&HH?t.parent:t},shift(t,a,s,c){return a==VH?new nQ(t,g$e(c.read(c.pos,s.pos)),0):a==EH?t.parent:a==b_e||a==S_e||a==$_e||a==XH?new nQ(t,0,aQ):dX.has(a)?new nQ(t,0,dX.get(a)|t.flags&aQ):t},hash(t){return t.hash}}),k$e=new Ft(t=>{for(let a=0;a<5;a++){if(t.next!="print".charCodeAt(a))return;t.advance()}if(!/\w/.test(String.fromCharCode(t.next)))for(let a=0;;a++){let s=t.peek(a);if(!(s==vA||s==WQ)){s!=r$e&&s!=i$e&&s!=Q1&&s!=J2&&s!=bA&&t.acceptToken(m_e);return}}}),v$e=new Ft((t,a)=>{let{flags:s}=a.context,c=s&$s?UH:DH,r=(s&Cs)>0,l=!(s&Qs),u=(s&Ls)>0,p=t.pos;for(;!(t.next<0);)if(u&&t.next==wP)if(t.peek(1)==wP)t.advance(2);else{if(t.pos==p){t.acceptToken(XH,1);return}break}else if(l&&t.next==lX){if(t.pos==p){t.advance();let f=t.next;f>=0&&(t.advance(),b$e(t,f)),t.acceptToken(v_e);return}break}else if(t.next==lX&&!l&&t.peek(1)>-1)t.advance(2);else if(t.next==c&&(!r||t.peek(1)==c&&t.peek(2)==c)){if(t.pos==p){t.acceptToken(rX,r?3:1);return}break}else if(t.next==Q1){if(r)t.advance();else if(t.pos==p){t.acceptToken(rX);return}break}else t.advance();t.pos>p&&t.acceptToken(k_e)});function b$e(t,a){if(a==l$e)for(let s=0;s<2&&t.next>=48&&t.next<=55;s++)t.advance();else if(a==d$e)for(let s=0;s<2&&BT(t.next);s++)t.advance();else if(a==h$e)for(let s=0;s<4&&BT(t.next);s++)t.advance();else if(a==p$e)for(let s=0;s<8&&BT(t.next);s++)t.advance();else if(a==u$e&&t.next==wP){for(t.advance();t.next>=0&&t.next!=iX&&t.next!=DH&&t.next!=UH&&t.next!=Q1;)t.advance();t.next==iX&&t.advance()}}const w$e=L1({'async "*" "**" FormatConversion FormatSpec':B.modifier,"for while if elif else try except finally return raise break continue with pass assert await yield match case":B.controlKeyword,"in not and or is del":B.operatorKeyword,"from def class global nonlocal lambda":B.definitionKeyword,import:B.moduleKeyword,"with as print":B.keyword,Boolean:B.bool,None:B.null,VariableName:B.variableName,"CallExpression/VariableName":B.function(B.variableName),"FunctionDefinition/VariableName":B.function(B.definition(B.variableName)),"ClassDefinition/VariableName":B.definition(B.className),PropertyName:B.propertyName,"CallExpression/MemberExpression/PropertyName":B.function(B.propertyName),Comment:B.lineComment,Number:B.number,String:B.string,FormatString:B.special(B.string),Escape:B.escape,UpdateOp:B.updateOperator,"ArithOp!":B.arithmeticOperator,BitOp:B.bitwiseOperator,CompareOp:B.compareOperator,AssignOp:B.definitionOperator,Ellipsis:B.punctuation,At:B.meta,"( )":B.paren,"[ ]":B.squareBracket,"{ }":B.brace,".":B.derefOperator,", ;":B.separator}),M$e={__proto__:null,await:44,or:54,and:56,in:60,not:62,is:64,if:70,else:72,lambda:76,yield:94,from:96,async:102,for:104,None:162,True:164,False:164,del:178,pass:182,break:186,continue:190,return:194,raise:202,import:206,as:208,global:212,nonlocal:214,assert:218,type:223,elif:236,while:240,try:246,except:248,finally:250,with:254,def:258,class:268,match:279,case:285},j$e=Fo.deserialize({version:14,states:"##jO`QeOOP$}OSOOO&WQtO'#HUOOQS'#Co'#CoOOQS'#Cp'#CpO'vQdO'#CnO*UQtO'#HTOOQS'#HU'#HUOOQS'#DU'#DUOOQS'#HT'#HTO*rQdO'#D_O+VQdO'#DfO+gQdO'#DjO+zOWO'#DuO,VOWO'#DvO.[QtO'#GuOOQS'#Gu'#GuO'vQdO'#GtO0ZQtO'#GtOOQS'#Eb'#EbO0rQdO'#EcOOQS'#Gs'#GsO0|QdO'#GrOOQV'#Gr'#GrO1XQdO'#FYOOQS'#G^'#G^O1^QdO'#FXOOQV'#IS'#ISOOQV'#Gq'#GqOOQV'#Fq'#FqQ`QeOOO'vQdO'#CqO1lQdO'#C}O1sQdO'#DRO2RQdO'#HYO2cQtO'#EVO'vQdO'#EWOOQS'#EY'#EYOOQS'#E['#E[OOQS'#E^'#E^O2wQdO'#E`O3_QdO'#EdO3rQdO'#EfO3zQtO'#EfO1XQdO'#EiO0rQdO'#ElO1XQdO'#EnO0rQdO'#EtO0rQdO'#EwO4VQdO'#EyO4^QdO'#FOO4iQdO'#EzO0rQdO'#FOO1XQdO'#FQO1XQdO'#FVO4nQdO'#F[P4uOdO'#GpPOOO)CBd)CBdOOQS'#Ce'#CeOOQS'#Cf'#CfOOQS'#Cg'#CgOOQS'#Ch'#ChOOQS'#Ci'#CiOOQS'#Cj'#CjOOQS'#Cl'#ClO'vQdO,59OO'vQdO,59OO'vQdO,59OO'vQdO,59OO'vQdO,59OO'vQdO,59OO5TQdO'#DoOOQS,5:Y,5:YO5hQdO'#HdOOQS,5:],5:]O5uQ!fO,5:]O5zQtO,59YO1lQdO,59bO1lQdO,59bO1lQdO,59bO8jQdO,59bO8oQdO,59bO8vQdO,59jO8}QdO'#HTO:TQdO'#HSOOQS'#HS'#HSOOQS'#D['#D[O:lQdO,59aO'vQdO,59aO:zQdO,59aOOQS,59y,59yO;PQdO,5:RO'vQdO,5:ROOQS,5:Q,5:QO;_QdO,5:QO;dQdO,5:XO'vQdO,5:XO'vQdO,5:VOOQS,5:U,5:UO;uQdO,5:UO;zQdO,5:WOOOW'#Fy'#FyO<POWO,5:aOOQS,5:a,5:aO<[QdO'#HwOOOW'#Dw'#DwOOOW'#Fz'#FzO<lOWO,5:bOOQS,5:b,5:bOOQS'#F}'#F}O<zQtO,5:iO?lQtO,5=`O@VQ#xO,5=`O@vQtO,5=`OOQS,5:},5:}OA_QeO'#GWOBqQdO,5;^OOQV,5=^,5=^OB|QtO'#IPOCkQdO,5;tOOQS-E:[-E:[OOQV,5;s,5;sO4dQdO'#FQOOQV-E9o-E9oOCsQtO,59]OEzQtO,59iOFeQdO'#HVOFpQdO'#HVO1XQdO'#HVOF{QdO'#DTOGTQdO,59mOGYQdO'#HZO'vQdO'#HZO0rQdO,5=tOOQS,5=t,5=tO0rQdO'#EROOQS'#ES'#ESOGwQdO'#GPOHXQdO,58|OHXQdO,58|O*xQdO,5:oOHgQtO'#H]OOQS,5:r,5:rOOQS,5:z,5:zOHzQdO,5;OOI]QdO'#IOO1XQdO'#H}OOQS,5;Q,5;QOOQS'#GT'#GTOIqQtO,5;QOJPQdO,5;QOJUQdO'#IQOOQS,5;T,5;TOJdQdO'#H|OOQS,5;W,5;WOJuQdO,5;YO4iQdO,5;`O4iQdO,5;cOJ}QtO'#ITO'vQdO'#ITOKXQdO,5;eO4VQdO,5;eO0rQdO,5;jO1XQdO,5;lOK^QeO'#EuOLjQgO,5;fO!!kQdO'#IUO4iQdO,5;jO!!vQdO,5;lO!#OQdO,5;qO!#ZQtO,5;vO'vQdO,5;vPOOO,5=[,5=[P!#bOSO,5=[P!#jOdO,5=[O!&bQtO1G.jO!&iQtO1G.jO!)YQtO1G.jO!)dQtO1G.jO!+}QtO1G.jO!,bQtO1G.jO!,uQdO'#HcO!-TQtO'#GuO0rQdO'#HcO!-_QdO'#HbOOQS,5:Z,5:ZO!-gQdO,5:ZO!-lQdO'#HeO!-wQdO'#HeO!.[QdO,5>OOOQS'#Ds'#DsOOQS1G/w1G/wOOQS1G.|1G.|O!/[QtO1G.|O!/cQtO1G.|O1lQdO1G.|O!0OQdO1G/UOOQS'#DZ'#DZO0rQdO,59tOOQS1G.{1G.{O!0VQdO1G/eO!0gQdO1G/eO!0oQdO1G/fO'vQdO'#H[O!0tQdO'#H[O!0yQtO1G.{O!1ZQdO,59iO!2aQdO,5=zO!2qQdO,5=zO!2yQdO1G/mO!3OQtO1G/mOOQS1G/l1G/lO!3`QdO,5=uO!4VQdO,5=uO0rQdO1G/qO!4tQdO1G/sO!4yQtO1G/sO!5ZQtO1G/qOOQS1G/p1G/pOOQS1G/r1G/rOOOW-E9w-E9wOOQS1G/{1G/{O!5kQdO'#HxO0rQdO'#HxO!5|QdO,5>cOOOW-E9x-E9xOOQS1G/|1G/|OOQS-E9{-E9{O!6[Q#xO1G2zO!6{QtO1G2zO'vQdO,5<jOOQS,5<j,5<jOOQS-E9|-E9|OOQS,5<r,5<rOOQS-E:U-E:UOOQV1G0x1G0xO1XQdO'#GRO!7dQtO,5>kOOQS1G1`1G1`O!8RQdO1G1`OOQS'#DV'#DVO0rQdO,5=qOOQS,5=q,5=qO!8WQdO'#FrO!8cQdO,59oO!8kQdO1G/XO!8uQtO,5=uOOQS1G3`1G3`OOQS,5:m,5:mO!9fQdO'#GtOOQS,5<k,5<kOOQS-E9}-E9}O!9wQdO1G.hOOQS1G0Z1G0ZO!:VQdO,5=wO!:gQdO,5=wO0rQdO1G0jO0rQdO1G0jO!:xQdO,5>jO!;ZQdO,5>jO1XQdO,5>jO!;lQdO,5>iOOQS-E:R-E:RO!;qQdO1G0lO!;|QdO1G0lO!<RQdO,5>lO!<aQdO,5>lO!<oQdO,5>hO!=VQdO,5>hO!=hQdO'#EpO0rQdO1G0tO!=sQdO1G0tO!=xQgO1G0zO!AvQgO1G0}O!EqQdO,5>oO!E{QdO,5>oO!FTQtO,5>oO0rQdO1G1PO!F_QdO1G1PO4iQdO1G1UO!!vQdO1G1WOOQV,5;a,5;aO!FdQfO,5;aO!FiQgO1G1QO!JjQdO'#GZO4iQdO1G1QO4iQdO1G1QO!JzQdO,5>pO!KXQdO,5>pO1XQdO,5>pOOQV1G1U1G1UO!KaQdO'#FSO!KrQ!fO1G1WO!KzQdO1G1WOOQV1G1]1G1]O4iQdO1G1]O!LPQdO1G1]O!LXQdO'#F^OOQV1G1b1G1bO!#ZQtO1G1bPOOO1G2v1G2vP!L^OSO1G2vOOQS,5=},5=}OOQS'#Dp'#DpO0rQdO,5=}O!LfQdO,5=|O!LyQdO,5=|OOQS1G/u1G/uO!MRQdO,5>PO!McQdO,5>PO!MkQdO,5>PO!NOQdO,5>PO!N`QdO,5>POOQS1G3j1G3jOOQS7+$h7+$hO!8kQdO7+$pO#!RQdO1G.|O#!YQdO1G.|OOQS1G/`1G/`OOQS,5<`,5<`O'vQdO,5<`OOQS7+%P7+%PO#!aQdO7+%POOQS-E9r-E9rOOQS7+%Q7+%QO#!qQdO,5=vO'vQdO,5=vOOQS7+$g7+$gO#!vQdO7+%PO##OQdO7+%QO##TQdO1G3fOOQS7+%X7+%XO##eQdO1G3fO##mQdO7+%XOOQS,5<_,5<_O'vQdO,5<_O##rQdO1G3aOOQS-E9q-E9qO#$iQdO7+%]OOQS7+%_7+%_O#$wQdO1G3aO#%fQdO7+%_O#%kQdO1G3gO#%{QdO1G3gO#&TQdO7+%]O#&YQdO,5>dO#&sQdO,5>dO#&sQdO,5>dOOQS'#Dx'#DxO#'UO&jO'#DzO#'aO`O'#HyOOOW1G3}1G3}O#'fQdO1G3}O#'nQdO1G3}O#'yQ#xO7+(fO#(jQtO1G2UP#)TQdO'#GOOOQS,5<m,5<mOOQS-E:P-E:POOQS7+&z7+&zOOQS1G3]1G3]OOQS,5<^,5<^OOQS-E9p-E9pOOQS7+$s7+$sO#)bQdO,5=`O#){QdO,5=`O#*^QtO,5<aO#*qQdO1G3cOOQS-E9s-E9sOOQS7+&U7+&UO#+RQdO7+&UO#+aQdO,5<nO#+uQdO1G4UOOQS-E:Q-E:QO#,WQdO1G4UOOQS1G4T1G4TOOQS7+&W7+&WO#,iQdO7+&WOOQS,5<p,5<pO#,tQdO1G4WOOQS-E:S-E:SOOQS,5<l,5<lO#-SQdO1G4SOOQS-E:O-E:OO1XQdO'#EqO#-jQdO'#EqO#-uQdO'#IRO#-}QdO,5;[OOQS7+&`7+&`O0rQdO7+&`O#.SQgO7+&fO!JmQdO'#GXO4iQdO7+&fO4iQdO7+&iO#2QQtO,5<tO'vQdO,5<tO#2[QdO1G4ZOOQS-E:W-E:WO#2fQdO1G4ZO4iQdO7+&kO0rQdO7+&kOOQV7+&p7+&pO!KrQ!fO7+&rO!KzQdO7+&rO`QeO1G0{OOQV-E:X-E:XO4iQdO7+&lO4iQdO7+&lOOQV,5<u,5<uO#2nQdO,5<uO!JmQdO,5<uOOQV7+&l7+&lO#2yQgO7+&lO#6tQdO,5<vO#7PQdO1G4[OOQS-E:Y-E:YO#7^QdO1G4[O#7fQdO'#IWO#7tQdO'#IWO1XQdO'#IWOOQS'#IW'#IWO#8PQdO'#IVOOQS,5;n,5;nO#8XQdO,5;nO0rQdO'#FUOOQV7+&r7+&rO4iQdO7+&rOOQV7+&w7+&wO4iQdO7+&wO#8^QfO,5;xOOQV7+&|7+&|POOO7+(b7+(bO#8cQdO1G3iOOQS,5<c,5<cO#8qQdO1G3hOOQS-E9u-E9uO#9UQdO,5<dO#9aQdO,5<dO#9tQdO1G3kOOQS-E9v-E9vO#:UQdO1G3kO#:^QdO1G3kO#:nQdO1G3kO#:UQdO1G3kOOQS<<H[<<H[O#:yQtO1G1zOOQS<<Hk<<HkP#;WQdO'#FtO8vQdO1G3bO#;eQdO1G3bO#;jQdO<<HkOOQS<<Hl<<HlO#;zQdO7+)QOOQS<<Hs<<HsO#<[QtO1G1yP#<{QdO'#FsO#=YQdO7+)RO#=jQdO7+)RO#=rQdO<<HwO#=wQdO7+({OOQS<<Hy<<HyO#>nQdO,5<bO'vQdO,5<bOOQS-E9t-E9tOOQS<<Hw<<HwOOQS,5<g,5<gO0rQdO,5<gO#>sQdO1G4OOOQS-E9y-E9yO#?^QdO1G4OO<[QdO'#H{OOOO'#D{'#D{OOOO'#F|'#F|O#?oO&jO,5:fOOOW,5>e,5>eOOOW7+)i7+)iO#?zQdO7+)iO#@SQdO1G2zO#@mQdO1G2zP'vQdO'#FuO0rQdO<<IpO1XQdO1G2YP1XQdO'#GSO#AOQdO7+)pO#AaQdO7+)pOOQS<<Ir<<IrP1XQdO'#GUP0rQdO'#GQOOQS,5;],5;]O#ArQdO,5>mO#BQQdO,5>mOOQS1G0v1G0vOOQS<<Iz<<IzOOQV-E:V-E:VO4iQdO<<JQOOQV,5<s,5<sO4iQdO,5<sOOQV<<JQ<<JQOOQV<<JT<<JTO#BYQtO1G2`P#BdQdO'#GYO#BkQdO7+)uO#BuQgO<<JVO4iQdO<<JVOOQV<<J^<<J^O4iQdO<<J^O!KrQ!fO<<J^O#FpQgO7+&gOOQV<<JW<<JWO#FzQgO<<JWOOQV1G2a1G2aO1XQdO1G2aO#JuQdO1G2aO4iQdO<<JWO1XQdO1G2bP0rQdO'#G[O#KQQdO7+)vO#K_QdO7+)vOOQS'#FT'#FTO0rQdO,5>rO#KgQdO,5>rO#KrQdO,5>rO#K}QdO,5>qO#L`QdO,5>qOOQS1G1Y1G1YOOQS,5;p,5;pOOQV<<Jc<<JcO#LhQdO1G1dOOQS7+)T7+)TP#LmQdO'#FwO#L}QdO1G2OO#MbQdO1G2OO#MrQdO1G2OP#M}QdO'#FxO#N[QdO7+)VO#NlQdO7+)VO#NlQdO7+)VO#NtQdO7+)VO$ UQdO7+(|O8vQdO7+(|OOQSAN>VAN>VO$ oQdO<<LmOOQSAN>cAN>cO0rQdO1G1|O$!PQtO1G1|P$!ZQdO'#FvOOQS1G2R1G2RP$!hQdO'#F{O$!uQdO7+)jO$#`QdO,5>gOOOO-E9z-E9zOOOW<<MT<<MTO$#nQdO7+(fOOQSAN?[AN?[OOQS7+'t7+'tO$$XQdO<<M[OOQS,5<q,5<qO$$jQdO1G4XOOQS-E:T-E:TOOQVAN?lAN?lOOQV1G2_1G2_O4iQdOAN?qO$$xQgOAN?qOOQVAN?xAN?xO4iQdOAN?xOOQV<<JR<<JRO4iQdOAN?rO4iQdO7+'{OOQV7+'{7+'{O1XQdO7+'{OOQVAN?rAN?rOOQS7+'|7+'|O$(sQdO<<MbOOQS1G4^1G4^O0rQdO1G4^OOQS,5<w,5<wO$)QQdO1G4]OOQS-E:Z-E:ZOOQU'#G_'#G_O$)cQfO7+'OO$)nQdO'#F_O$*uQdO7+'jO$+VQdO7+'jOOQS7+'j7+'jO$+bQdO<<LqO$+rQdO<<LqO$+rQdO<<LqO$+zQdO'#H^OOQS<<Lh<<LhO$,UQdO<<LhOOQS7+'h7+'hOOQS'#D|'#D|OOOO1G4R1G4RO$,oQdO1G4RO$,wQdO1G4RP!=hQdO'#GVOOQVG25]G25]O4iQdOG25]OOQVG25dG25dOOQVG25^G25^OOQV<<Kg<<KgO4iQdO<<KgOOQS7+)x7+)xP$-SQdO'#G]OOQU-E:]-E:]OOQV<<Jj<<JjO$-vQtO'#FaOOQS'#Fc'#FcO$.WQdO'#FbO$.xQdO'#FbOOQS'#Fb'#FbO$.}QdO'#IYO$)nQdO'#FiO$)nQdO'#FiO$/fQdO'#FjO$)nQdO'#FkO$/mQdO'#IZOOQS'#IZ'#IZO$0[QdO,5;yOOQS<<KU<<KUO$0dQdO<<KUO$0tQdOANB]O$1UQdOANB]O$1^QdO'#H_OOQS'#H_'#H_O1sQdO'#DcO$1wQdO,5=xOOQSANBSANBSOOOO7+)m7+)mO$2`QdO7+)mOOQVLD*wLD*wOOQVANARANARO5uQ!fO'#GaO$2hQtO,5<SO$)nQdO'#FmOOQS,5<W,5<WOOQS'#Fd'#FdO$3YQdO,5;|O$3_QdO,5;|OOQS'#Fg'#FgO$)nQdO'#G`O$4PQdO,5<QO$4kQdO,5>tO$4{QdO,5>tO1XQdO,5<PO$5^QdO,5<TO$5cQdO,5<TO$)nQdO'#I[O$5hQdO'#I[O$5mQdO,5<UOOQS,5<V,5<VO0rQdO'#FpOOQU1G1e1G1eO4iQdO1G1eOOQSAN@pAN@pO$5rQdOG27wO$6SQdO,59}OOQS1G3d1G3dOOOO<<MX<<MXOOQS,5<{,5<{OOQS-E:_-E:_O$6XQtO'#FaO$6`QdO'#I]O$6nQdO'#I]O$6vQdO,5<XOOQS1G1h1G1hO$6{QdO1G1hO$7QQdO,5<zOOQS-E:^-E:^O$7lQdO,5=OO$8TQdO1G4`OOQS-E:b-E:bOOQS1G1k1G1kOOQS1G1o1G1oO$8eQdO,5>vO$)nQdO,5>vOOQS1G1p1G1pOOQS,5<[,5<[OOQU7+'P7+'PO$+zQdO1G/iO$)nQdO,5<YO$8sQdO,5>wO$8zQdO,5>wOOQS1G1s1G1sOOQS7+'S7+'SP$)nQdO'#GdO$9SQdO1G4bO$9^QdO1G4bO$9fQdO1G4bOOQS7+%T7+%TO$9tQdO1G1tO$:SQtO'#FaO$:ZQdO,5<}OOQS,5<},5<}O$:iQdO1G4cOOQS-E:a-E:aO$)nQdO,5<|O$:pQdO,5<|O$:uQdO7+)|OOQS-E:`-E:`O$;PQdO7+)|O$)nQdO,5<ZP$)nQdO'#GcO$;XQdO1G2hO$)nQdO1G2hP$;gQdO'#GbO$;nQdO<<MhO$;xQdO1G1uO$<WQdO7+(SO8vQdO'#C}O8vQdO,59bO8vQdO,59bO8vQdO,59bO$<fQtO,5=`O8vQdO1G.|O0rQdO1G/XO0rQdO7+$pP$<yQdO'#GOO'vQdO'#GtO$=WQdO,59bO$=]QdO,59bO$=dQdO,59mO$=iQdO1G/UO1sQdO'#DRO8vQdO,59j",stateData:"$>S~O%cOS%^OSSOS%]PQ~OPdOVaOfoOhYOopOs!POvqO!PrO!Q{O!T!SO!U!RO!XZO!][O!h`O!r`O!s`O!t`O!{tO!}uO#PvO#RwO#TxO#XyO#ZzO#^|O#_|O#a}O#c!OO#l!QO#o!TO#s!UO#u!VO#z!WO#}hO$P!XO%oRO%pRO%tSO%uWO&Z]O&[]O&]]O&^]O&_]O&`]O&a]O&b]O&c^O&d^O&e^O&f^O&g^O&h^O&i^O&j^O~O%]!YO~OV!aO_!aOa!bOh!iO!X!kO!f!mO%j![O%k!]O%l!^O%m!_O%n!_O%o!`O%p!`O%q!aO%r!aO%s!aO~Ok%xXl%xXm%xXn%xXo%xXp%xXs%xXz%xX{%xX!x%xX#g%xX%[%xX%_%xX%z%xXg%xX!T%xX!U%xX%{%xX!W%xX![%xX!Q%xX#[%xXt%xX!m%xX~P%SOfoOhYO!XZO!][O!h`O!r`O!s`O!t`O%oRO%pRO%tSO%uWO&Z]O&[]O&]]O&^]O&_]O&`]O&a]O&b]O&c^O&d^O&e^O&f^O&g^O&h^O&i^O&j^O~Oz%wX{%wX#g%wX%[%wX%_%wX%z%wX~Ok!pOl!qOm!oOn!oOo!rOp!sOs!tO!x%wX~P)pOV!zOg!|Oo0cOv0qO!PrO~P'vOV#OOo0cOv0qO!W#PO~P'vOV#SOa#TOo0cOv0qO![#UO~P'vOQ#XO%`#XO%a#ZO~OQ#^OR#[O%`#^O%a#`O~OV%iX_%iXa%iXh%iXk%iXl%iXm%iXn%iXo%iXp%iXs%iXz%iX!X%iX!f%iX%j%iX%k%iX%l%iX%m%iX%n%iX%o%iX%p%iX%q%iX%r%iX%s%iXg%iX!T%iX!U%iX~O&Z]O&[]O&]]O&^]O&_]O&`]O&a]O&b]O&c^O&d^O&e^O&f^O&g^O&h^O&i^O&j^O{%iX!x%iX#g%iX%[%iX%_%iX%z%iX%{%iX!W%iX![%iX!Q%iX#[%iXt%iX!m%iX~P,eOz#dO{%hX!x%hX#g%hX%[%hX%_%hX%z%hX~Oo0cOv0qO~P'vO#g#gO%[#iO%_#iO~O%uWO~O!T#nO#u!VO#z!WO#}hO~OopO~P'vOV#sOa#tO%uWO{wP~OV#xOo0cOv0qO!Q#yO~P'vO{#{O!x$QO%z#|O#g!yX%[!yX%_!yX~OV#xOo0cOv0qO#g#SX%[#SX%_#SX~P'vOo0cOv0qO#g#WX%[#WX%_#WX~P'vOh$WO%uWO~O!f$YO!r$YO%uWO~OV$eO~P'vO!U$gO#s$hO#u$iO~O{$jO~OV$qO~P'vOS$sO%[$rO%_$rO%c$tO~OV$}Oa$}Og%POo0cOv0qO~P'vOo0cOv0qO{%SO~P'vO&Y%UO~Oa!bOh!iO!X!kO!f!mOVba_bakbalbambanbaobapbasbazba{ba!xba#gba%[ba%_ba%jba%kba%lba%mba%nba%oba%pba%qba%rba%sba%zbagba!Tba!Uba%{ba!Wba![ba!Qba#[batba!mba~On%ZO~Oo%ZO~P'vOo0cO~P'vOk0eOl0fOm0dOn0dOo0mOp0nOs0rOg%wX!T%wX!U%wX%{%wX!W%wX![%wX!Q%wX#[%wX!m%wX~P)pO%{%]Og%vXz%vX!T%vX!U%vX!W%vX{%vX~Og%_Oz%`O!T%dO!U%cO~Og%_O~Oz%gO!T%dO!U%cO!W&SX~O!W%kO~Oz%lO{%nO!T%dO!U%cO![%}X~O![%rO~O![%sO~OQ#XO%`#XO%a%uO~OV%wOo0cOv0qO!PrO~P'vOQ#^OR#[O%`#^O%a%zO~OV!qa_!qaa!qah!qak!qal!qam!qan!qao!qap!qas!qaz!qa{!qa!X!qa!f!qa!x!qa#g!qa%[!qa%_!qa%j!qa%k!qa%l!qa%m!qa%n!qa%o!qa%p!qa%q!qa%r!qa%s!qa%z!qag!qa!T!qa!U!qa%{!qa!W!qa![!qa!Q!qa#[!qat!qa!m!qa~P#yOz%|O{%ha!x%ha#g%ha%[%ha%_%ha%z%ha~P%SOV&OOopOvqO{%ha!x%ha#g%ha%[%ha%_%ha%z%ha~P'vOz%|O{%ha!x%ha#g%ha%[%ha%_%ha%z%ha~OPdOVaOopOvqO!PrO!Q{O!{tO!}uO#PvO#RwO#TxO#XyO#ZzO#^|O#_|O#a}O#c!OO#g$zX%[$zX%_$zX~P'vO#g#gO%[&TO%_&TO~O!f&UOh&sX%[&sXz&sX#[&sX#g&sX%_&sX#Z&sXg&sX~Oh!iO%[&WO~Okealeameaneaoeapeaseazea{ea!xea#gea%[ea%_ea%zeagea!Tea!Uea%{ea!Wea![ea!Qea#[eatea!mea~P%SOsqazqa{qa#gqa%[qa%_qa%zqa~Ok!pOl!qOm!oOn!oOo!rOp!sO!xqa~PEcO%z&YOz%yX{%yX~O%uWOz%yX{%yX~Oz&]O{wX~O{&_O~Oz%lO#g%}X%[%}X%_%}Xg%}X{%}X![%}X!m%}X%z%}X~OV0lOo0cOv0qO!PrO~P'vO%z#|O#gUa%[Ua%_Ua~Oz&hO#g&PX%[&PX%_&PXn&PX~P%SOz&kO!Q&jO#g#Wa%[#Wa%_#Wa~Oz&lO#[&nO#g&rX%[&rX%_&rXg&rX~O!f$YO!r$YO#Z&qO%uWO~O#Z&qO~Oz&sO#g&tX%[&tX%_&tX~Oz&uO#g&pX%[&pX%_&pX{&pX~O!X&wO%z&xO~Oz&|On&wX~P%SOn'PO~OPdOVaOopOvqO!PrO!Q{O!{tO!}uO#PvO#RwO#TxO#XyO#ZzO#^|O#_|O#a}O#c!OO%['UO~P'vOt'YO#p'WO#q'XOP#naV#naf#nah#nao#nas#nav#na!P#na!Q#na!T#na!U#na!X#na!]#na!h#na!r#na!s#na!t#na!{#na!}#na#P#na#R#na#T#na#X#na#Z#na#^#na#_#na#a#na#c#na#l#na#o#na#s#na#u#na#z#na#}#na$P#na%X#na%o#na%p#na%t#na%u#na&Z#na&[#na&]#na&^#na&_#na&`#na&a#na&b#na&c#na&d#na&e#na&f#na&g#na&h#na&i#na&j#na%Z#na%_#na~Oz'ZO#[']O{&xX~Oh'_O!X&wO~Oh!iO{$jO!X&wO~O{'eO~P%SO%['hO%_'hO~OS'iO%['hO%_'hO~OV!aO_!aOa!bOh!iO!X!kO!f!mO%l!^O%m!_O%n!_O%o!`O%p!`O%q!aO%r!aO%s!aOkWilWimWinWioWipWisWizWi{Wi!xWi#gWi%[Wi%_Wi%jWi%zWigWi!TWi!UWi%{Wi!WWi![Wi!QWi#[WitWi!mWi~O%k!]O~P!#uO%kWi~P!#uOV!aO_!aOa!bOh!iO!X!kO!f!mO%o!`O%p!`O%q!aO%r!aO%s!aOkWilWimWinWioWipWisWizWi{Wi!xWi#gWi%[Wi%_Wi%jWi%kWi%lWi%zWigWi!TWi!UWi%{Wi!WWi![Wi!QWi#[WitWi!mWi~O%m!_O%n!_O~P!&pO%mWi%nWi~P!&pOa!bOh!iO!X!kO!f!mOkWilWimWinWioWipWisWizWi{Wi!xWi#gWi%[Wi%_Wi%jWi%kWi%lWi%mWi%nWi%oWi%pWi%zWigWi!TWi!UWi%{Wi!WWi![Wi!QWi#[WitWi!mWi~OV!aO_!aO%q!aO%r!aO%s!aO~P!)nOVWi_Wi%qWi%rWi%sWi~P!)nO!T%dO!U%cOg&VXz&VX~O%z'kO%{'kO~P,eOz'mOg&UX~Og'oO~Oz'pO{'rO!W&XX~Oo0cOv0qOz'pO{'sO!W&XX~P'vO!W'uO~Om!oOn!oOo!rOp!sOkjisjizji{ji!xji#gji%[ji%_ji%zji~Ol!qO~P!.aOlji~P!.aOk0eOl0fOm0dOn0dOo0mOp0nO~Ot'wO~P!/jOV'|Og'}Oo0cOv0qO~P'vOg'}Oz(OO~Og(QO~O!U(SO~Og(TOz(OO!T%dO!U%cO~P%SOk0eOl0fOm0dOn0dOo0mOp0nOgqa!Tqa!Uqa%{qa!Wqa![qa!Qqa#[qatqa!mqa~PEcOV'|Oo0cOv0qO!W&Sa~P'vOz(WO!W&Sa~O!W(XO~Oz(WO!T%dO!U%cO!W&Sa~P%SOV(]Oo0cOv0qO![%}a#g%}a%[%}a%_%}ag%}a{%}a!m%}a%z%}a~P'vOz(^O![%}a#g%}a%[%}a%_%}ag%}a{%}a!m%}a%z%}a~O![(aO~Oz(^O!T%dO!U%cO![%}a~P%SOz(dO!T%dO!U%cO![&Ta~P%SOz(gO{&lX![&lX!m&lX%z&lX~O{(kO![(mO!m(nO%z(jO~OV&OOopOvqO{%hi!x%hi#g%hi%[%hi%_%hi%z%hi~P'vOz(pO{%hi!x%hi#g%hi%[%hi%_%hi%z%hi~O!f&UOh&sa%[&saz&sa#[&sa#g&sa%_&sa#Z&sag&sa~O%[(uO~OV#sOa#tO%uWO~Oz&]O{wa~OopOvqO~P'vOz(^O#g%}a%[%}a%_%}ag%}a{%}a![%}a!m%}a%z%}a~P%SOz(zO#g%hX%[%hX%_%hX%z%hX~O%z#|O#gUi%[Ui%_Ui~O#g&Pa%[&Pa%_&Pan&Pa~P'vOz(}O#g&Pa%[&Pa%_&Pan&Pa~O%uWO#g&ra%[&ra%_&rag&ra~Oz)SO#g&ra%[&ra%_&rag&ra~Og)VO~OV)WOh$WO%uWO~O#Z)XO~O%uWO#g&ta%[&ta%_&ta~Oz)ZO#g&ta%[&ta%_&ta~Oo0cOv0qO#g&pa%[&pa%_&pa{&pa~P'vOz)^O#g&pa%[&pa%_&pa{&pa~OV)`Oa)`O%uWO~O%z)eO~Ot)hO#j)gOP#hiV#hif#hih#hio#his#hiv#hi!P#hi!Q#hi!T#hi!U#hi!X#hi!]#hi!h#hi!r#hi!s#hi!t#hi!{#hi!}#hi#P#hi#R#hi#T#hi#X#hi#Z#hi#^#hi#_#hi#a#hi#c#hi#l#hi#o#hi#s#hi#u#hi#z#hi#}#hi$P#hi%X#hi%o#hi%p#hi%t#hi%u#hi&Z#hi&[#hi&]#hi&^#hi&_#hi&`#hi&a#hi&b#hi&c#hi&d#hi&e#hi&f#hi&g#hi&h#hi&i#hi&j#hi%Z#hi%_#hi~Ot)iOP#kiV#kif#kih#kio#kis#kiv#ki!P#ki!Q#ki!T#ki!U#ki!X#ki!]#ki!h#ki!r#ki!s#ki!t#ki!{#ki!}#ki#P#ki#R#ki#T#ki#X#ki#Z#ki#^#ki#_#ki#a#ki#c#ki#l#ki#o#ki#s#ki#u#ki#z#ki#}#ki$P#ki%X#ki%o#ki%p#ki%t#ki%u#ki&Z#ki&[#ki&]#ki&^#ki&_#ki&`#ki&a#ki&b#ki&c#ki&d#ki&e#ki&f#ki&g#ki&h#ki&i#ki&j#ki%Z#ki%_#ki~OV)kOn&wa~P'vOz)lOn&wa~Oz)lOn&wa~P%SOn)pO~O%Y)tO~Ot)wO#p'WO#q)vOP#niV#nif#nih#nio#nis#niv#ni!P#ni!Q#ni!T#ni!U#ni!X#ni!]#ni!h#ni!r#ni!s#ni!t#ni!{#ni!}#ni#P#ni#R#ni#T#ni#X#ni#Z#ni#^#ni#_#ni#a#ni#c#ni#l#ni#o#ni#s#ni#u#ni#z#ni#}#ni$P#ni%X#ni%o#ni%p#ni%t#ni%u#ni&Z#ni&[#ni&]#ni&^#ni&_#ni&`#ni&a#ni&b#ni&c#ni&d#ni&e#ni&f#ni&g#ni&h#ni&i#ni&j#ni%Z#ni%_#ni~OV)zOo0cOv0qO{$jO~P'vOo0cOv0qO{&xa~P'vOz*OO{&xa~OV*SOa*TOg*WO%q*UO%uWO~O{$jO&{*YO~Oh'_O~Oh!iO{$jO~O%[*_O~O%[*aO%_*aO~OV$}Oa$}Oo0cOv0qOg&Ua~P'vOz*dOg&Ua~Oo0cOv0qO{*gO!W&Xa~P'vOz*hO!W&Xa~Oo0cOv0qOz*hO{*kO!W&Xa~P'vOo0cOv0qOz*hO!W&Xa~P'vOz*hO{*kO!W&Xa~Om0dOn0dOo0mOp0nOgjikjisjizji!Tji!Uji%{ji!Wji{ji![ji#gji%[ji%_ji!Qji#[jitji!mji%zji~Ol0fO~P!NkOlji~P!NkOV'|Og*pOo0cOv0qO~P'vOn*rO~Og*pOz*tO~Og*uO~OV'|Oo0cOv0qO!W&Si~P'vOz*vO!W&Si~O!W*wO~OV(]Oo0cOv0qO![%}i#g%}i%[%}i%_%}ig%}i{%}i!m%}i%z%}i~P'vOz*zO!T%dO!U%cO![&Ti~Oz*}O![%}i#g%}i%[%}i%_%}ig%}i{%}i!m%}i%z%}i~O![+OO~Oa+QOo0cOv0qO![&Ti~P'vOz*zO![&Ti~O![+SO~OV+UOo0cOv0qO{&la![&la!m&la%z&la~P'vOz+VO{&la![&la!m&la%z&la~O!]+YO&n+[O![!nX~O![+^O~O{(kO![+_O~O{(kO![+_O!m+`O~OV&OOopOvqO{%hq!x%hq#g%hq%[%hq%_%hq%z%hq~P'vOz$ri{$ri!x$ri#g$ri%[$ri%_$ri%z$ri~P%SOV&OOopOvqO~P'vOV&OOo0cOv0qO#g%ha%[%ha%_%ha%z%ha~P'vOz+aO#g%ha%[%ha%_%ha%z%ha~Oz$ia#g$ia%[$ia%_$ian$ia~P%SO#g&Pi%[&Pi%_&Pin&Pi~P'vOz+dO#g#Wq%[#Wq%_#Wq~O#[+eOz$va#g$va%[$va%_$vag$va~O%uWO#g&ri%[&ri%_&rig&ri~Oz+gO#g&ri%[&ri%_&rig&ri~OV+iOh$WO%uWO~O%uWO#g&ti%[&ti%_&ti~Oo0cOv0qO#g&pi%[&pi%_&pi{&pi~P'vO{#{Oz#eX!W#eX~Oz+mO!W&uX~O!W+oO~Ot+rO#j)gOP#hqV#hqf#hqh#hqo#hqs#hqv#hq!P#hq!Q#hq!T#hq!U#hq!X#hq!]#hq!h#hq!r#hq!s#hq!t#hq!{#hq!}#hq#P#hq#R#hq#T#hq#X#hq#Z#hq#^#hq#_#hq#a#hq#c#hq#l#hq#o#hq#s#hq#u#hq#z#hq#}#hq$P#hq%X#hq%o#hq%p#hq%t#hq%u#hq&Z#hq&[#hq&]#hq&^#hq&_#hq&`#hq&a#hq&b#hq&c#hq&d#hq&e#hq&f#hq&g#hq&h#hq&i#hq&j#hq%Z#hq%_#hq~On$|az$|a~P%SOV)kOn&wi~P'vOz+yOn&wi~Oz,TO{$jO#[,TO~O#q,VOP#nqV#nqf#nqh#nqo#nqs#nqv#nq!P#nq!Q#nq!T#nq!U#nq!X#nq!]#nq!h#nq!r#nq!s#nq!t#nq!{#nq!}#nq#P#nq#R#nq#T#nq#X#nq#Z#nq#^#nq#_#nq#a#nq#c#nq#l#nq#o#nq#s#nq#u#nq#z#nq#}#nq$P#nq%X#nq%o#nq%p#nq%t#nq%u#nq&Z#nq&[#nq&]#nq&^#nq&_#nq&`#nq&a#nq&b#nq&c#nq&d#nq&e#nq&f#nq&g#nq&h#nq&i#nq&j#nq%Z#nq%_#nq~O#[,WOz%Oa{%Oa~Oo0cOv0qO{&xi~P'vOz,YO{&xi~O{#{O%z,[Og&zXz&zX~O%uWOg&zXz&zX~Oz,`Og&yX~Og,bO~O%Y,eO~O!T%dO!U%cOg&Viz&Vi~OV$}Oa$}Oo0cOv0qOg&Ui~P'vO{,hOz$la!W$la~Oo0cOv0qO{,iOz$la!W$la~P'vOo0cOv0qO{*gO!W&Xi~P'vOz,lO!W&Xi~Oo0cOv0qOz,lO!W&Xi~P'vOz,lO{,oO!W&Xi~Og$hiz$hi!W$hi~P%SOV'|Oo0cOv0qO~P'vOn,qO~OV'|Og,rOo0cOv0qO~P'vOV'|Oo0cOv0qO!W&Sq~P'vOz$gi![$gi#g$gi%[$gi%_$gig$gi{$gi!m$gi%z$gi~P%SOV(]Oo0cOv0qO~P'vOa+QOo0cOv0qO![&Tq~P'vOz,sO![&Tq~O![,tO~OV(]Oo0cOv0qO![%}q#g%}q%[%}q%_%}qg%}q{%}q!m%}q%z%}q~P'vO{,uO~OV+UOo0cOv0qO{&li![&li!m&li%z&li~P'vOz,zO{&li![&li!m&li%z&li~O!]+YO&n+[O![!na~O{(kO![,}O~OV&OOo0cOv0qO#g%hi%[%hi%_%hi%z%hi~P'vOz-OO#g%hi%[%hi%_%hi%z%hi~O%uWO#g&rq%[&rq%_&rqg&rq~Oz-RO#g&rq%[&rq%_&rqg&rq~OV)`Oa)`O%uWO!W&ua~Oz-TO!W&ua~On$|iz$|i~P%SOV)kO~P'vOV)kOn&wq~P'vOt-XOP#myV#myf#myh#myo#mys#myv#my!P#my!Q#my!T#my!U#my!X#my!]#my!h#my!r#my!s#my!t#my!{#my!}#my#P#my#R#my#T#my#X#my#Z#my#^#my#_#my#a#my#c#my#l#my#o#my#s#my#u#my#z#my#}#my$P#my%X#my%o#my%p#my%t#my%u#my&Z#my&[#my&]#my&^#my&_#my&`#my&a#my&b#my&c#my&d#my&e#my&f#my&g#my&h#my&i#my&j#my%Z#my%_#my~O%Z-]O%_-]O~P`O#q-^OP#nyV#nyf#nyh#nyo#nys#nyv#ny!P#ny!Q#ny!T#ny!U#ny!X#ny!]#ny!h#ny!r#ny!s#ny!t#ny!{#ny!}#ny#P#ny#R#ny#T#ny#X#ny#Z#ny#^#ny#_#ny#a#ny#c#ny#l#ny#o#ny#s#ny#u#ny#z#ny#}#ny$P#ny%X#ny%o#ny%p#ny%t#ny%u#ny&Z#ny&[#ny&]#ny&^#ny&_#ny&`#ny&a#ny&b#ny&c#ny&d#ny&e#ny&f#ny&g#ny&h#ny&i#ny&j#ny%Z#ny%_#ny~Oz-aO{$jO#[-aO~Oo0cOv0qO{&xq~P'vOz-dO{&xq~O%z,[Og&zaz&za~O{#{Og&zaz&za~OV*SOa*TO%q*UO%uWOg&ya~Oz-hOg&ya~O$S-lO~OV$}Oa$}Oo0cOv0qO~P'vOo0cOv0qO{-mOz$li!W$li~P'vOo0cOv0qOz$li!W$li~P'vO{-mOz$li!W$li~Oo0cOv0qO{*gO~P'vOo0cOv0qO{*gO!W&Xq~P'vOz-pO!W&Xq~Oo0cOv0qOz-pO!W&Xq~P'vOs-sO!T%dO!U%cOg&Oq!W&Oq![&Oqz&Oq~P!/jOa+QOo0cOv0qO![&Ty~P'vOz$ji![$ji~P%SOa+QOo0cOv0qO~P'vOV+UOo0cOv0qO~P'vOV+UOo0cOv0qO{&lq![&lq!m&lq%z&lq~P'vO{(kO![-xO!m-yO%z-wO~OV&OOo0cOv0qO#g%hq%[%hq%_%hq%z%hq~P'vO%uWO#g&ry%[&ry%_&ryg&ry~OV)`Oa)`O%uWO!W&ui~Ot-}OP#m!RV#m!Rf#m!Rh#m!Ro#m!Rs#m!Rv#m!R!P#m!R!Q#m!R!T#m!R!U#m!R!X#m!R!]#m!R!h#m!R!r#m!R!s#m!R!t#m!R!{#m!R!}#m!R#P#m!R#R#m!R#T#m!R#X#m!R#Z#m!R#^#m!R#_#m!R#a#m!R#c#m!R#l#m!R#o#m!R#s#m!R#u#m!R#z#m!R#}#m!R$P#m!R%X#m!R%o#m!R%p#m!R%t#m!R%u#m!R&Z#m!R&[#m!R&]#m!R&^#m!R&_#m!R&`#m!R&a#m!R&b#m!R&c#m!R&d#m!R&e#m!R&f#m!R&g#m!R&h#m!R&i#m!R&j#m!R%Z#m!R%_#m!R~Oo0cOv0qO{&xy~P'vOV*SOa*TO%q*UO%uWOg&yi~O$S-lO%Z.VO%_.VO~OV.aOh._O!X.^O!].`O!h.YO!s.[O!t.[O%p.XO%uWO&Z]O&[]O&]]O&^]O&_]O&`]O&a]O&b]O~Oo0cOv0qOz$lq!W$lq~P'vO{.fOz$lq!W$lq~Oo0cOv0qO{*gO!W&Xy~P'vOz.gO!W&Xy~Oo0cOv.kO~P'vOs-sO!T%dO!U%cOg&Oy!W&Oy![&Oyz&Oy~P!/jO{(kO![.nO~O{(kO![.nO!m.oO~OV*SOa*TO%q*UO%uWO~Oh.tO!f.rOz$TX#[$TX%j$TXg$TX~Os$TX{$TX!W$TX![$TX~P$-bO%o.vO%p.vOs$UXz$UX{$UX#[$UX%j$UX!W$UXg$UX![$UX~O!h.xO~Oz.|O#[/OO%j.yOs&|X{&|X!W&|Xg&|X~Oa/RO~P$)zOh.tOs&}Xz&}X{&}X#[&}X%j&}X!W&}Xg&}X![&}X~Os/VO{$jO~Oo0cOv0qOz$ly!W$ly~P'vOo0cOv0qO{*gO!W&X!R~P'vOz/ZO!W&X!R~Og&RXs&RX!T&RX!U&RX!W&RX![&RXz&RX~P!/jOs-sO!T%dO!U%cOg&Qa!W&Qa![&Qaz&Qa~O{(kO![/^O~O!f.rOh$[as$[az$[a{$[a#[$[a%j$[a!W$[ag$[a![$[a~O!h/eO~O%o.vO%p.vOs$Uaz$Ua{$Ua#[$Ua%j$Ua!W$Uag$Ua![$Ua~O%j.yOs$Yaz$Ya{$Ya#[$Ya!W$Yag$Ya![$Ya~Os&|a{&|a!W&|ag&|a~P$)nOz/jOs&|a{&|a!W&|ag&|a~O!W/mO~Og/mO~O{/oO~O![/pO~Oo0cOv0qO{*gO!W&X!Z~P'vO{/sO~O%z/tO~P$-bOz/uO#[/OO%j.yOg'PX~Oz/uOg'PX~Og/wO~O!h/xO~O#[/OOs%Saz%Sa{%Sa%j%Sa!W%Sag%Sa![%Sa~O#[/OO%j.yOs%Waz%Wa{%Wa!W%Wag%Wa~Os&|i{&|i!W&|ig&|i~P$)nOz/zO#[/OO%j.yO!['Oa~Og'Pa~P$)nOz0SOg'Pa~Oa0UO!['Oi~P$)zOz0WO!['Oi~Oz0WO#[/OO%j.yO!['Oi~O#[/OO%j.yOg$biz$bi~O%z0ZO~P$-bO#[/OO%j.yOg%Vaz%Va~Og'Pi~P$)nO{0^O~Oa0UO!['Oq~P$)zOz0`O!['Oq~O#[/OO%j.yOz%Ui![%Ui~Oa0UO~P$)zOa0UO!['Oy~P$)zO#[/OO%j.yOg$ciz$ci~O#[/OO%j.yOz%Uq![%Uq~Oz+aO#g%ha%[%ha%_%ha%z%ha~P%SOV&OOo0cOv0qO~P'vOn0hO~Oo0hO~P'vO{0iO~Ot0jO~P!/jO&]&Z&j&h&i&g&f&d&e&c&b&`&a&_&^&[%u~",goto:"!=j'QPPPPPP'RP'Z*s+[+t,_,y-fP.SP'Z.r.r'ZPPP'Z2[PPPPPP2[5PPP5PP7b7k=sPP=v>h>kPP'Z'ZPP>zPP'Z'ZPP'Z'Z'Z'Z'Z?O?w'ZP?zP@QDXGuGyPG|HWH['ZPPPH_Hk'RP'R'RP'RP'RP'RP'RP'R'R'RP'RPP'RPP'RP'RPHqH}IVPI^IdPI^PI^I^PPPI^PKrPK{LVL]KrPI^LfPI^PLmLsPLwM]MzNeLwLwNkNxLwLwLwLw! ^! d! g! l! o! y!!P!!]!!o!!u!#P!#V!#s!#y!$P!$Z!$a!$g!$y!%T!%Z!%a!%k!%q!%w!%}!&T!&Z!&e!&k!&u!&{!'U!'[!'k!'s!'}!(UPPPPPPPPPPP!([!(_!(e!(n!(x!)TPPPPPPPPPPPP!-u!/Z!3^!6oPP!6w!7W!7a!8Y!8P!8c!8i!8l!8o!8r!8z!9jPPPPPPPPPPPPPPPPP!9m!9q!9wP!:]!:a!:m!:v!;S!;j!;m!;p!;v!;|!<S!<VP!<_!<h!=d!=g]eOn#g$j)t,P'}`OTYZ[adnoprtxy}!P!Q!R!U!X!c!d!e!f!g!h!i!k!o!p!q!s!t!z#O#S#T#[#d#g#x#y#{#}$Q$e$g$h$j$q$}%S%Z%^%`%c%g%l%n%w%|&O&Z&_&h&j&k&u&x&|'P'W'Z'l'm'p'r's'w'|(O(S(W(](^(d(g(p(r(z(})^)e)g)k)l)p)t)z*O*Y*d*g*h*k*q*r*t*v*y*z*}+Q+U+V+Y+a+c+d+k+x+y,P,X,Y,],g,h,i,k,l,o,q,s,u,w,y,z-O-d-f-m-p-s.f.g/V/Z/s0c0d0e0f0h0i0j0k0l0n0r{!cQ#c#p$R$d$p%e%j%p%q&`'O'g(q(|)j*o*x+w,v0g}!dQ#c#p$R$d$p$u%e%j%p%q&`'O'g(q(|)j*o*x+w,v0g!P!eQ#c#p$R$d$p$u$v%e%j%p%q&`'O'g(q(|)j*o*x+w,v0g!R!fQ#c#p$R$d$p$u$v$w%e%j%p%q&`'O'g(q(|)j*o*x+w,v0g!T!gQ#c#p$R$d$p$u$v$w$x%e%j%p%q&`'O'g(q(|)j*o*x+w,v0g!V!hQ#c#p$R$d$p$u$v$w$x$y%e%j%p%q&`'O'g(q(|)j*o*x+w,v0g!Z!hQ!n#c#p$R$d$p$u$v$w$x$y$z%e%j%p%q&`'O'g(q(|)j*o*x+w,v0g'}TOTYZ[adnoprtxy}!P!Q!R!U!X!c!d!e!f!g!h!i!k!o!p!q!s!t!z#O#S#T#[#d#g#x#y#{#}$Q$e$g$h$j$q$}%S%Z%^%`%c%g%l%n%w%|&O&Z&_&h&j&k&u&x&|'P'W'Z'l'm'p'r's'w'|(O(S(W(](^(d(g(p(r(z(})^)e)g)k)l)p)t)z*O*Y*d*g*h*k*q*r*t*v*y*z*}+Q+U+V+Y+a+c+d+k+x+y,P,X,Y,],g,h,i,k,l,o,q,s,u,w,y,z-O-d-f-m-p-s.f.g/V/Z/s0c0d0e0f0h0i0j0k0l0n0r&eVOYZ[dnprxy}!P!Q!U!i!k!o!p!q!s!t#[#d#g#y#{#}$Q$h$j$}%S%Z%^%`%g%l%n%w%|&Z&_&j&k&u&x'P'W'Z'l'm'p'r's'w(O(W(^(d(g(p(r(z)^)e)g)p)t)z*O*Y*d*g*h*k*q*r*t*v*y*z*}+U+V+Y+a+d+k,P,X,Y,],g,h,i,k,l,o,q,s,u,w,y,z-O-d-f-m-p-s.f.g/V/Z/s0c0d0e0f0h0i0j0k0n0r%oXOYZ[dnrxy}!P!Q!U!i!k#[#d#g#y#{#}$Q$h$j$}%S%^%`%g%l%n%w%|&Z&_&j&k&u&x'P'W'Z'l'm'p'r's'w(O(W(^(d(g(p(r(z)^)e)g)p)t)z*O*Y*d*g*h*k*q*t*v*y*z*}+U+V+Y+a+d+k,P,X,Y,],g,h,i,k,l,o,s,u,w,y,z-O-d-f-m-p.f.g/V/Z0i0j0kQ#vqQ/[.kR0o0q't`OTYZ[adnoprtxy}!P!Q!R!U!X!c!d!e!f!g!h!k!o!p!q!s!t!z#O#S#T#[#d#g#x#y#{#}$Q$e$g$h$j$q$}%S%Z%^%`%c%g%l%n%w%|&O&Z&_&h&j&k&u&x&|'P'W'Z'l'p'r's'w'|(O(S(W(](^(d(g(p(r(z(})^)e)g)k)l)p)t)z*O*Y*g*h*k*q*r*t*v*y*z*}+Q+U+V+Y+a+c+d+k+x+y,P,X,Y,],h,i,k,l,o,q,s,u,w,y,z-O-d-f-m-p-s.f.g/V/Z/s0c0d0e0f0h0i0j0k0l0n0rh#jhz{$W$Z&l&q)S)X+f+g-RW#rq&].k0qQ$]|Q$a!OQ$n!VQ$o!WW$|!i'm*d,gS&[#s#tQ'S$iQ(s&UQ)U&nU)Y&s)Z+jW)a&w+m-T-{Q*Q']W*R'_,`-h.TQ+l)`S,_*S*TQ-Q+eQ-_,TQ-c,WQ.R-al.W-l.^._.a.z.|/R/j/o/t/y0U0Z0^Q/S.`Q/a.tQ/l/OU0P/u0S0[X0V/z0W0_0`R&Z#r!_!wYZ!P!Q!k%S%`%g'p'r's(O(W)g*g*h*k*q*t*v,h,i,k,l,o-m-p.f.g/ZR%^!vQ!{YQ%x#[Q&d#}Q&g$QR,{+YT.j-s/s!Y!jQ!n#c#p$R$d$p$u$v$w$x$y$z%e%j%p%q&`'O'g(q(|)j*o*x+w,v0gQ&X#kQ'c$oR*^'dR'l$|Q%V!mR/_.r'|_OTYZ[adnoprtxy}!P!Q!R!U!X!c!d!e!f!g!h!i!k!o!p!q!s!t!z#O#S#T#[#d#g#x#y#{#}$Q$e$g$h$j$q$}%S%Z%^%`%c%g%l%n%w%|&O&Z&_&h&j&k&u&x&|'P'W'Z'l'm'p'r's'w'|(O(S(W(](^(d(g(p(r(z(})^)e)g)k)l)p)t)z*O*Y*d*g*h*k*q*r*t*v*y*z*}+Q+U+V+Y+a+c+d+k+x+y,P,X,Y,],g,h,i,k,l,o,q,s,u,w,y,z-O-d-f-m-p-s.f.g/V/Z/s0c0d0e0f0h0i0j0k0l0n0rS#a_#b!P.[-l.^._.`.a.t.z.|/R/j/o/t/u/y/z0S0U0W0Z0[0^0_0`'|_OTYZ[adnoprtxy}!P!Q!R!U!X!c!d!e!f!g!h!i!k!o!p!q!s!t!z#O#S#T#[#d#g#x#y#{#}$Q$e$g$h$j$q$}%S%Z%^%`%c%g%l%n%w%|&O&Z&_&h&j&k&u&x&|'P'W'Z'l'm'p'r's'w'|(O(S(W(](^(d(g(p(r(z(})^)e)g)k)l)p)t)z*O*Y*d*g*h*k*q*r*t*v*y*z*}+Q+U+V+Y+a+c+d+k+x+y,P,X,Y,],g,h,i,k,l,o,q,s,u,w,y,z-O-d-f-m-p-s.f.g/V/Z/s0c0d0e0f0h0i0j0k0l0n0rT#a_#bT#^^#_R(o%xa(l%x(n(o+`,{-y-z.oT+[(k+]R-z,{Q$PsQ+l)aQ,^*RR-e,_X#}s$O$P&fQ&y$aQ'a$nQ'd$oR)s'SQ)b&wV-S+m-T-{ZgOn$j)t,PXkOn)t,PQ$k!TQ&z$bQ&{$cQ'^$mQ'b$oQ)q'RQ)x'WQ){'XQ)|'YQ*Z'`S*]'c'dQ+s)gQ+u)hQ+v)iQ+z)oS+|)r*[Q,Q)vQ,R)wS,S)y)zQ,d*^Q-V+rQ-W+tQ-Y+{S-Z+},OQ-`,UQ-b,VQ-|-XQ.O-[Q.P-^Q.Q-_Q.p-}Q.q.RQ/W.dR/r/XWkOn)t,PR#mjQ'`$nS)r'S'aR,O)sQ,]*RR-f,^Q*['`Q+})rR-[,OZiOjn)t,PQ'f$pR*`'gT-j,e-ku.c-l.^._.a.t.z.|/R/j/o/t/u/y0S0U0Z0[0^t.c-l.^._.a.t.z.|/R/j/o/t/u/y0S0U0Z0[0^Q/S.`X0V/z0W0_0`!P.Z-l.^._.`.a.t.z.|/R/j/o/t/u/y/z0S0U0W0Z0[0^0_0`Q.w.YR/f.xg.z.].{/b/i/n/|0O0Q0]0a0bu.b-l.^._.a.t.z.|/R/j/o/t/u/y0S0U0Z0[0^X.u.W.b/a0PR/c.tV0R/u0S0[R/X.dQnOS#on,PR,P)tQ&^#uR(x&^S%m#R#wS(_%m(bT(b%p&`Q%a!yQ%h!}W(P%a%h(U(YQ(U%eR(Y%jQ&i$RR)O&iQ(e%qQ*{(`T+R(e*{Q'n%OR*e'nS'q%R%SY*i'q*j,m-q.hU*j'r's'tU,m*k*l*mS-q,n,oR.h-rQ#Y]R%t#YQ#_^R%y#_Q(h%vS+W(h+XR+X(iQ+](kR,|+]Q#b_R%{#bQ#ebQ%}#cW&Q#e%}({+bQ({&cR+b0gQ$OsS&e$O&fR&f$PQ&v$_R)_&vQ&V#jR(t&VQ&m$VS)T&m+hR+h)UQ$Z{R&p$ZQ&t$]R)[&tQ+n)bR-U+nQ#hfR&S#hQ)f&zR+q)fQ&}$dS)m&})nR)n'OQ'V$kR)u'VQ'[$lS*P'[,ZR,Z*QQ,a*VR-i,aWjOn)t,PR#ljQ-k,eR.U-kd.{.]/b/i/n/|0O0Q0]0a0bR/h.{U.s.W/a0PR/`.sQ/{/nS0X/{0YR0Y/|S/v/b/cR0T/vQ.}.]R/k.}R!ZPXmOn)t,PWlOn)t,PR'T$jYfOn$j)t,PR&R#g[sOn#g$j)t,PR&d#}&dQOYZ[dnprxy}!P!Q!U!i!k!o!p!q!s!t#[#d#g#y#{#}$Q$h$j$}%S%Z%^%`%g%l%n%w%|&Z&_&j&k&u&x'P'W'Z'l'm'p'r's'w(O(W(^(d(g(p(r(z)^)e)g)p)t)z*O*Y*d*g*h*k*q*r*t*v*y*z*}+U+V+Y+a+d+k,P,X,Y,],g,h,i,k,l,o,q,s,u,w,y,z-O-d-f-m-p-s.f.g/V/Z/s0c0d0e0f0h0i0j0k0n0rQ!nTQ#caQ#poU$Rt%c(SS$d!R$gQ$p!XQ$u!cQ$v!dQ$w!eQ$x!fQ$y!gQ$z!hQ%e!zQ%j#OQ%p#SQ%q#TQ&`#xQ'O$eQ'g$qQ(q&OU(|&h(}+cW)j&|)l+x+yQ*o'|Q*x(]Q+w)kQ,v+QR0g0lQ!yYQ!}ZQ$b!PQ$c!QQ%R!kQ't%S^'{%`%g(O(W*q*t*v^*f'p*h,k,l-p.g/ZQ*l'rQ*m'sQ+t)gQ,j*gQ,n*kQ-n,hQ-o,iQ-r,oQ.e-mR/Y.f[bOn#g$j)t,P!^!vYZ!P!Q!k%S%`%g'p'r's(O(W)g*g*h*k*q*t*v,h,i,k,l,o-m-p.f.g/ZQ#R[Q#fdS#wrxQ$UyW$_}$Q'P)pS$l!U$hW${!i'm*d,gS%v#[+Y`&P#d%|(p(r(z+a-O0kQ&a#yQ&b#{Q&c#}Q'j$}Q'z%^W([%l(^*y*}Q(`%nQ(i%wQ(v&ZS(y&_0iQ)P&jQ)Q&kU)]&u)^+kQ)d&xQ)y'WY)}'Z*O,X,Y-dQ*b'lS*n'w0jW+P(d*z,s,wW+T(g+V,y,zQ+p)eQ,U)zQ,c*YQ,x+UQ-P+dQ-e,]Q-v,uQ.S-fR/q/VhUOn#d#g$j%|&_'w(p(r)t,P%U!uYZ[drxy}!P!Q!U!i!k#[#y#{#}$Q$h$}%S%^%`%g%l%n%w&Z&j&k&u&x'P'W'Z'l'm'p'r's(O(W(^(d(g(z)^)e)g)p)z*O*Y*d*g*h*k*q*t*v*y*z*}+U+V+Y+a+d+k,X,Y,],g,h,i,k,l,o,s,u,w,y,z-O-d-f-m-p.f.g/V/Z0i0j0kQ#qpW%W!o!s0d0nQ%X!pQ%Y!qQ%[!tQ%f0cS'v%Z0hQ'x0eQ'y0fQ,p*rQ-u,qS.i-s/sR0p0rU#uq.k0qR(w&][cOn#g$j)t,PZ!xY#[#}$Q+YQ#W[Q#zrR$TxQ%b!yQ%i!}Q%o#RQ'j${Q(V%eQ(Z%jQ(c%pQ(f%qQ*|(`Q,f*bQ-t,pQ.m-uR/].lQ$StQ(R%cR*s(SQ.l-sR/}/sR#QZR#V[R%Q!iQ%O!iV*c'm*d,g!Z!lQ!n#c#p$R$d$p$u$v$w$x$y$z%e%j%p%q&`'O'g(q(|)j*o*x+w,v0gR%T!kT#]^#_Q%x#[R,{+YQ(m%xS+_(n(oQ,}+`Q-x,{S.n-y-zR/^.oT+Z(k+]Q$`}Q&g$QQ)o'PR+{)pQ$XzQ)W&qR+i)XQ$XzQ&o$WQ)W&qR+i)XQ#khW$Vz$W&q)XQ$[{Q&r$ZZ)R&l)S+f+g-RR$^|R)c&wXlOn)t,PQ$f!RR'Q$gQ$m!UR'R$hR*X'_Q*V'_V-g,`-h.TQ.d-lQ/P.^R/Q._U.]-l.^._Q/U.aQ/b.tQ/g.zU/i.|/j/yQ/n/RQ/|/oQ0O/tU0Q/u0S0[Q0]0UQ0a0ZR0b0^R/T.`R/d.t",nodeNames:"⚠ print Escape { Comment Script AssignStatement * BinaryExpression BitOp BitOp BitOp BitOp ArithOp ArithOp @ ArithOp ** UnaryExpression ArithOp BitOp AwaitExpression await ) ( ParenthesizedExpression BinaryExpression or and CompareOp in not is UnaryExpression ConditionalExpression if else LambdaExpression lambda ParamList VariableName AssignOp , : NamedExpression AssignOp YieldExpression yield from TupleExpression ComprehensionExpression async for LambdaExpression ] [ ArrayExpression ArrayComprehensionExpression } { DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression CallExpression ArgList AssignOp MemberExpression . PropertyName Number String FormatString FormatReplacement FormatSelfDoc FormatConversion FormatSpec FormatReplacement FormatSelfDoc ContinuedString Ellipsis None Boolean TypeDef AssignOp UpdateStatement UpdateOp ExpressionStatement DeleteStatement del PassStatement pass BreakStatement break ContinueStatement continue ReturnStatement return YieldStatement PrintStatement RaiseStatement raise ImportStatement import as ScopeStatement global nonlocal AssertStatement assert TypeDefinition type TypeParamList TypeParam StatementGroup ; IfStatement Body elif WhileStatement while ForStatement TryStatement try except finally WithStatement with FunctionDefinition def ParamList AssignOp TypeDef ClassDefinition class DecoratedStatement Decorator At MatchStatement match MatchBody MatchClause case CapturePattern LiteralPattern ArithOp ArithOp AsPattern OrPattern LogicOp AttributePattern SequencePattern MappingPattern StarPattern ClassPattern PatternArgList KeywordPattern KeywordPattern Guard",maxTerm:277,context:O$e,nodeProps:[["isolate",-5,4,71,72,73,77,""],["group",-15,6,85,87,88,90,92,94,96,98,99,100,102,105,108,110,"Statement Statement",-22,8,18,21,25,40,49,50,56,57,60,61,62,63,64,67,70,71,72,79,80,81,82,"Expression",-10,114,116,119,121,122,126,128,133,135,138,"Statement",-9,143,144,147,148,150,151,152,153,154,"Pattern"],["openedBy",23,"(",54,"[",58,"{"],["closedBy",24,")",55,"]",59,"}"]],propSources:[w$e],skippedNodes:[0,4],repeatNodeCount:34,tokenData:"!2|~R!`OX%TXY%oY[%T[]%o]p%Tpq%oqr'ars)Yst*xtu%Tuv,dvw-hwx.Uxy/tyz0[z{0r{|2S|}2p}!O3W!O!P4_!P!Q:Z!Q!R;k!R![>_![!]Do!]!^Es!^!_FZ!_!`Gk!`!aHX!a!b%T!b!cIf!c!dJU!d!eK^!e!hJU!h!i!#f!i!tJU!t!u!,|!u!wJU!w!x!.t!x!}JU!}#O!0S#O#P&o#P#Q!0j#Q#R!1Q#R#SJU#S#T%T#T#UJU#U#VK^#V#YJU#Y#Z!#f#Z#fJU#f#g!,|#g#iJU#i#j!.t#j#oJU#o#p!1n#p#q!1s#q#r!2a#r#s!2f#s$g%T$g;'SJU;'S;=`KW<%lOJU`%YT&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%T`%lP;=`<%l%To%v]&n`%c_OX%TXY%oY[%T[]%o]p%Tpq%oq#O%T#O#P&o#P#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%To&tX&n`OY%TYZ%oZ]%T]^%o^#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tc'f[&n`O!_%T!_!`([!`#T%T#T#U(r#U#f%T#f#g(r#g#h(r#h#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tc(cTmR&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tc(yT!mR&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk)aV&n`&[ZOr%Trs)vs#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk){V&n`Or%Trs*bs#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk*iT&n`&^ZO#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%To+PZS_&n`OY*xYZ%TZ]*x]^%T^#o*x#o#p+r#p#q*x#q#r+r#r;'S*x;'S;=`,^<%lO*x_+wTS_OY+rZ]+r^;'S+r;'S;=`,W<%lO+r_,ZP;=`<%l+ro,aP;=`<%l*xj,kV%rQ&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tj-XT!xY&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tj-oV%lQ&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk.]V&n`&ZZOw%Twx.rx#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk.wV&n`Ow%Twx/^x#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk/eT&n`&]ZO#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk/{ThZ&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tc0cTgR&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk0yXVZ&n`Oz%Tz{1f{!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk1mVaR&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk2ZV%oZ&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tc2wTzR&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%To3_W%pZ&n`O!_%T!_!`-Q!`!a3w!a#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Td4OT&{S&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk4fX!fQ&n`O!O%T!O!P5R!P!Q%T!Q![6T![#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk5WV&n`O!O%T!O!P5m!P#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk5tT!rZ&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti6[a!hX&n`O!Q%T!Q![6T![!g%T!g!h7a!h!l%T!l!m9s!m#R%T#R#S6T#S#X%T#X#Y7a#Y#^%T#^#_9s#_#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti7fZ&n`O{%T{|8X|}%T}!O8X!O!Q%T!Q![8s![#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti8^V&n`O!Q%T!Q![8s![#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti8z]!hX&n`O!Q%T!Q![8s![!l%T!l!m9s!m#R%T#R#S8s#S#^%T#^#_9s#_#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti9zT!hX&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk:bX%qR&n`O!P%T!P!Q:}!Q!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tj;UV%sQ&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti;ro!hX&n`O!O%T!O!P=s!P!Q%T!Q![>_![!d%T!d!e?q!e!g%T!g!h7a!h!l%T!l!m9s!m!q%T!q!rA]!r!z%T!z!{Bq!{#R%T#R#S>_#S#U%T#U#V?q#V#X%T#X#Y7a#Y#^%T#^#_9s#_#c%T#c#dA]#d#l%T#l#mBq#m#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti=xV&n`O!Q%T!Q![6T![#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti>fc!hX&n`O!O%T!O!P=s!P!Q%T!Q![>_![!g%T!g!h7a!h!l%T!l!m9s!m#R%T#R#S>_#S#X%T#X#Y7a#Y#^%T#^#_9s#_#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti?vY&n`O!Q%T!Q!R@f!R!S@f!S#R%T#R#S@f#S#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Ti@mY!hX&n`O!Q%T!Q!R@f!R!S@f!S#R%T#R#S@f#S#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TiAbX&n`O!Q%T!Q!YA}!Y#R%T#R#SA}#S#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TiBUX!hX&n`O!Q%T!Q!YA}!Y#R%T#R#SA}#S#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TiBv]&n`O!Q%T!Q![Co![!c%T!c!iCo!i#R%T#R#SCo#S#T%T#T#ZCo#Z#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TiCv]!hX&n`O!Q%T!Q![Co![!c%T!c!iCo!i#R%T#R#SCo#S#T%T#T#ZCo#Z#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%ToDvV{_&n`O!_%T!_!`E]!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TcEdT%{R&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TkEzT#gZ&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TkFbXmR&n`O!^%T!^!_F}!_!`([!`!a([!a#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TjGUV%mQ&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TkGrV%zZ&n`O!_%T!_!`([!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TkH`WmR&n`O!_%T!_!`([!`!aHx!a#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TjIPV%nQ&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TkIoV_Q#}P&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%ToJ_]&n`&YS%uZO!Q%T!Q![JU![!c%T!c!}JU!}#R%T#R#SJU#S#T%T#T#oJU#p#q%T#r$g%T$g;'SJU;'S;=`KW<%lOJUoKZP;=`<%lJUoKge&n`&YS%uZOr%Trs)Ysw%Twx.Ux!Q%T!Q![JU![!c%T!c!tJU!t!uLx!u!}JU!}#R%T#R#SJU#S#T%T#T#fJU#f#gLx#g#oJU#p#q%T#r$g%T$g;'SJU;'S;=`KW<%lOJUoMRa&n`&YS%uZOr%TrsNWsw%Twx! vx!Q%T!Q![JU![!c%T!c!}JU!}#R%T#R#SJU#S#T%T#T#oJU#p#q%T#r$g%T$g;'SJU;'S;=`KW<%lOJUkN_V&n`&`ZOr%TrsNts#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%TkNyV&n`Or%Trs! `s#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk! gT&n`&bZO#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk! }V&n`&_ZOw%Twx!!dx#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!!iV&n`Ow%Twx!#Ox#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!#VT&n`&aZO#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%To!#oe&n`&YS%uZOr%Trs!%Qsw%Twx!&px!Q%T!Q![JU![!c%T!c!tJU!t!u!(`!u!}JU!}#R%T#R#SJU#S#T%T#T#fJU#f#g!(`#g#oJU#p#q%T#r$g%T$g;'SJU;'S;=`KW<%lOJUk!%XV&n`&dZOr%Trs!%ns#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!%sV&n`Or%Trs!&Ys#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!&aT&n`&fZO#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!&wV&n`&cZOw%Twx!'^x#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!'cV&n`Ow%Twx!'xx#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!(PT&n`&eZO#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%To!(ia&n`&YS%uZOr%Trs!)nsw%Twx!+^x!Q%T!Q![JU![!c%T!c!}JU!}#R%T#R#SJU#S#T%T#T#oJU#p#q%T#r$g%T$g;'SJU;'S;=`KW<%lOJUk!)uV&n`&hZOr%Trs!*[s#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!*aV&n`Or%Trs!*vs#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!*}T&n`&jZO#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!+eV&n`&gZOw%Twx!+zx#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!,PV&n`Ow%Twx!,fx#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tk!,mT&n`&iZO#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%To!-Vi&n`&YS%uZOr%TrsNWsw%Twx! vx!Q%T!Q![JU![!c%T!c!dJU!d!eLx!e!hJU!h!i!(`!i!}JU!}#R%T#R#SJU#S#T%T#T#UJU#U#VLx#V#YJU#Y#Z!(`#Z#oJU#p#q%T#r$g%T$g;'SJU;'S;=`KW<%lOJUo!.}a&n`&YS%uZOr%Trs)Ysw%Twx.Ux!Q%T!Q![JU![!c%T!c!}JU!}#R%T#R#SJU#S#T%T#T#oJU#p#q%T#r$g%T$g;'SJU;'S;=`KW<%lOJUk!0ZT!XZ&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tc!0qT!WR&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%Tj!1XV%kQ&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%T~!1sO!]~k!1zV%jR&n`O!_%T!_!`-Q!`#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%T~!2fO![~i!2mT%tX&n`O#o%T#p#q%T#r;'S%T;'S;=`%i<%lO%T",tokenizers:[k$e,m$e,x$e,v$e,0,1,2,3,4],topRules:{Script:[0,5]},specialized:[{term:221,get:t=>M$e[t]||-1}],tokenPrec:7668}),uX=new _P,BH=new Set(["Script","Body","FunctionDefinition","ClassDefinition","LambdaExpression","ForStatement","MatchClause"]);function Rh(t){return(a,s,c)=>{if(c)return!1;let r=a.node.getChild("VariableName");return r&&s(r,t),!0}}const S$e={FunctionDefinition:Rh("function"),ClassDefinition:Rh("class"),ForStatement(t,a,s){if(s){for(let c=t.node.firstChild;c;c=c.nextSibling)if(c.name=="VariableName")a(c,"variable");else if(c.name=="in")break}},ImportStatement(t,a){var s,c;let{node:r}=t,l=((s=r.firstChild)===null||s===void 0?void 0:s.name)=="from";for(let u=r.getChild("import");u;u=u.nextSibling)u.name=="VariableName"&&((c=u.nextSibling)===null||c===void 0?void 0:c.name)!="as"&&a(u,l?"variable":"namespace")},AssignStatement(t,a){for(let s=t.node.firstChild;s;s=s.nextSibling)if(s.name=="VariableName")a(s,"variable");else if(s.name==":"||s.name=="AssignOp")break},ParamList(t,a){for(let s=null,c=t.node.firstChild;c;c=c.nextSibling)c.name=="VariableName"&&(!s||!/\*|AssignOp/.test(s.name))&&a(c,"variable"),s=c},CapturePattern:Rh("variable"),AsPattern:Rh("variable"),__proto__:null};function GH(t,a){let s=uX.get(a);if(s)return s;let c=[],r=!0;function l(u,p){let f=t.sliceString(u.from,u.to);c.push({label:f,type:p})}return a.cursor(_Q.IncludeAnonymous).iterate(u=>{if(u.name){let p=S$e[u.name];if(p&&p(u,l,r)||!r&&BH.has(u.name))return!1;r=!1}else if(u.to-u.from>8192){for(let p of GH(t,u.node))c.push(p);return!1}}),uX.set(a,c),c}const hX=/^[\w\xa1-\uffff][\w\d\xa1-\uffff]*$/,WH=["String","FormatString","Comment","PropertyName"];function N$e(t){let a=Cn(t.state).resolveInner(t.pos,-1);if(WH.indexOf(a.name)>-1)return null;let s=a.name=="VariableName"||a.to-a.from<20&&hX.test(t.state.sliceDoc(a.from,a.to));if(!s&&!t.explicit)return null;let c=[];for(let r=a;r;r=r.parent)BH.has(r.name)&&(c=c.concat(GH(t.state.doc,r)));return{options:c,from:s?a.from:t.pos,validFor:hX}}const _$e=["__annotations__","__builtins__","__debug__","__doc__","__import__","__name__","__loader__","__package__","__spec__","False","None","True"].map(t=>({label:t,type:"constant"})).concat(["ArithmeticError","AssertionError","AttributeError","BaseException","BlockingIOError","BrokenPipeError","BufferError","BytesWarning","ChildProcessError","ConnectionAbortedError","ConnectionError","ConnectionRefusedError","ConnectionResetError","DeprecationWarning","EOFError","Ellipsis","EncodingWarning","EnvironmentError","Exception","FileExistsError","FileNotFoundError","FloatingPointError","FutureWarning","GeneratorExit","IOError","ImportError","ImportWarning","IndentationError","IndexError","InterruptedError","IsADirectoryError","KeyError","KeyboardInterrupt","LookupError","MemoryError","ModuleNotFoundError","NameError","NotADirectoryError","NotImplemented","NotImplementedError","OSError","OverflowError","PendingDeprecationWarning","PermissionError","ProcessLookupError","RecursionError","ReferenceError","ResourceWarning","RuntimeError","RuntimeWarning","StopAsyncIteration","StopIteration","SyntaxError","SyntaxWarning","SystemError","SystemExit","TabError","TimeoutError","TypeError","UnboundLocalError","UnicodeDecodeError","UnicodeEncodeError","UnicodeError","UnicodeTranslateError","UnicodeWarning","UserWarning","ValueError","Warning","ZeroDivisionError"].map(t=>({label:t,type:"type"}))).concat(["bool","bytearray","bytes","classmethod","complex","float","frozenset","int","list","map","memoryview","object","range","set","staticmethod","str","super","tuple","type"].map(t=>({label:t,type:"class"}))).concat(["abs","aiter","all","anext","any","ascii","bin","breakpoint","callable","chr","compile","delattr","dict","dir","divmod","enumerate","eval","exec","exit","filter","format","getattr","globals","hasattr","hash","help","hex","id","input","isinstance","issubclass","iter","len","license","locals","max","min","next","oct","open","ord","pow","print","property","quit","repr","reversed","round","setattr","slice","sorted","sum","vars","zip"].map(t=>({label:t,type:"function"}))),$$e=[xt("def ${name}(${params}):\n ${}",{label:"def",detail:"function",type:"keyword"}),xt("for ${name} in ${collection}:\n ${}",{label:"for",detail:"loop",type:"keyword"}),xt("while ${}:\n ${}",{label:"while",detail:"loop",type:"keyword"}),xt("try:\n ${}\nexcept ${error}:\n ${}",{label:"try",detail:"/ except block",type:"keyword"}),xt(`if \${}:
8603
8603
 
8604
- `,{label:"if",detail:"block",type:"keyword"}),xt("if ${}:\n ${}\nelse:\n ${}",{label:"if",detail:"/ else block",type:"keyword"}),xt("class ${name}:\n def __init__(self, ${params}):\n ${}",{label:"class",detail:"definition",type:"keyword"}),xt("import ${module}",{label:"import",detail:"statement",type:"keyword"}),xt("from ${module} import ${names}",{label:"from",detail:"import",type:"keyword"})],C$e=QX(WH,LX(_$e.concat($$e)));function GT(t){let{node:a,pos:s}=t,c=t.lineIndent(s,-1),r=null;for(;;){let l=a.childBefore(s);if(l)if(l.name=="Comment")s=l.from;else if(l.name=="Body"||l.name=="MatchBody")t.baseIndentFor(l)+t.unit<=c&&(r=l),a=l;else if(l.name=="MatchClause")a=l;else if(l.type.is("Statement"))a=l;else break;else break}return r}function WT(t,a){let s=t.baseIndentFor(a),c=t.lineAt(t.pos,-1),r=c.from+c.text.length;return/^\s*($|#)/.test(c.text)&&t.node.to<r+100&&!/\S/.test(t.state.sliceDoc(r,t.node.to))&&t.lineIndent(t.pos,-1)<=s||/^\s*(else:|elif |except |finally:|case\s+[^=:]+:)/.test(t.textAfter)&&t.lineIndent(t.pos,-1)>s?null:s+t.unit}const YT=tu.define({name:"python",parser:j$e.configure({props:[s0.add({Body:t=>{var a;let s=/^\s*(#|$)/.test(t.textAfter)&&GT(t)||t.node;return(a=WT(t,s))!==null&&a!==void 0?a:t.continue()},MatchBody:t=>{var a;let s=GT(t);return(a=WT(t,s||t.node))!==null&&a!==void 0?a:t.continue()},IfStatement:t=>/^\s*(else:|elif )/.test(t.textAfter)?t.baseIndent:t.continue(),"ForStatement WhileStatement":t=>/^\s*else:/.test(t.textAfter)?t.baseIndent:t.continue(),TryStatement:t=>/^\s*(except[ :]|finally:|else:)/.test(t.textAfter)?t.baseIndent:t.continue(),MatchStatement:t=>/^\s*case /.test(t.textAfter)?t.baseIndent+t.unit:t.continue(),"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression":Dh({closing:")"}),"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression":Dh({closing:"}"}),"ArrayExpression ArrayComprehensionExpression":Dh({closing:"]"}),MemberExpression:t=>t.baseIndent+t.unit,"String FormatString":()=>null,Script:t=>{var a;let s=GT(t);return(a=s&&WT(t,s))!==null&&a!==void 0?a:t.continue()}}),z1.add({"ArrayExpression DictionaryExpression SetExpression TupleExpression":$Q,Body:(t,a)=>({from:t.from+1,to:t.to-(t.to==a.doc.length?0:1)}),"String FormatString":(t,a)=>({from:a.doc.lineAt(t.from).to,to:t.to})})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"'''",'"""'],stringPrefixes:["f","fr","rf","r","u","b","br","rb","F","FR","RF","R","U","B","BR","RB"]},commentTokens:{line:"#"},indentOnInput:/^\s*([\}\]\)]|else:|elif |except |finally:|case\s+[^:]*:?)$/}});function Q$e(){return new N1(YT,[YT.data.of({autocomplete:N$e}),YT.data.of({autocomplete:C$e})])}const Vh={javascript:()=>xP({jsx:!0,typescript:!1}),typescript:()=>xP({jsx:!0,typescript:!0}),css:()=>HU(),html:()=>uH(),json:()=>SNe(),markdown:()=>u_e(),python:()=>Q$e()},L$e=Yd.theme({"&":{backgroundColor:"#24282f",color:"#bcc2cd",fontFamily:"var(--font-mono)",fontSize:"13px",height:"100%"},".cm-scroller":{overflow:"auto"},".cm-content":{caretColor:"#33afbc"},".cm-cursor":{borderLeftColor:"#33afbc"},".cm-gutters":{backgroundColor:"#24282f",borderRight:"1px solid #2c313a",color:"#505862"},".cm-activeLineGutter":{backgroundColor:"#2c313a"},".cm-activeLine":{backgroundColor:"rgba(44, 49, 58, 0.5)"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground":{backgroundColor:"rgba(51, 175, 188, 0.15)"},".cm-panels":{backgroundColor:"#24282f",borderBottom:"1px solid #3e4451"},".cm-panels.cm-panels-top":{borderBottom:"1px solid #3e4451"},".cm-panels.cm-panels-bottom":{borderTop:"1px solid #3e4451"},".cm-search":{padding:"6px 8px",gap:"4px",fontFamily:"var(--font-sans)",fontSize:"12px",display:"flex",flexWrap:"wrap",alignItems:"center"},".cm-search label":{display:"flex",alignItems:"center",gap:"4px",color:"#8b929e",fontSize:"11px"},".cm-search input, .cm-search .cm-textfield":{backgroundColor:"#1a1e25",border:"1px solid #2c313a",borderRadius:"4px",color:"#e6e6e6",padding:"2px 6px",fontSize:"12px",fontFamily:"var(--font-mono)",outline:"none"},".cm-search input:focus, .cm-search .cm-textfield:focus":{borderColor:"#33afbc"},".cm-search .cm-button, .cm-button":{backgroundColor:"#2c313a",border:"1px solid #3e4451",borderRadius:"4px",color:"#bcc2cd",padding:"2px 8px",fontSize:"11px",fontFamily:"var(--font-sans)",cursor:"pointer",backgroundImage:"none"},".cm-search .cm-button:hover, .cm-button:hover":{backgroundColor:"#333842",color:"#e6e6e6"},".cm-search .cm-button:active":{backgroundColor:"#3a3f4b"},".cm-search br":{display:"none"},".cm-panel.cm-search [name=close]":{color:"#6e7681",cursor:"pointer",padding:"0 4px"},".cm-panel.cm-search [name=close]:hover":{color:"#e6e6e6"},".cm-searchMatch":{backgroundColor:"rgba(51, 175, 188, 0.2)",outline:"1px solid rgba(51, 175, 188, 0.4)"},".cm-searchMatch-selected":{backgroundColor:"rgba(51, 175, 188, 0.35)"}},{dark:!0});function pX({content:t,language:a,onChange:s,onSave:c,onCursorChange:r,viewRef:l}){const u=O.useRef(null),p=O.useRef(null),f=O.useRef(new nY),x=O.useRef(s),g=O.useRef(c),y=O.useRef(r);return x.current=s,g.current=c,y.current=r,O.useEffect(()=>{if(!u.current)return;const k=Vh[a]||Vh.javascript,b=aP.of([{key:"Mod-s",run:()=>{var S;return(S=g.current)==null||S.call(g),!0}}]),j=AX.create({doc:t||"",extensions:[oY(),cY(),rY(),iY(),lY(),dY(),uY(),aP.of([...hY,...pY,...fY]),b,sY,L$e,f.current.of(k()),Yd.updateListener.of(S=>{var M,$;if(S.docChanged&&((M=x.current)==null||M.call(x,S.state.doc.toString())),S.selectionSet||S.docChanged){const C=S.state.selection.main.head,_=S.state.doc.lineAt(C);($=y.current)==null||$.call(y,{line:_.number,col:C-_.from+1})}})]}),w=new Yd({state:j,parent:u.current});return p.current=w,l&&(l.current=w),()=>{w.destroy(),p.current=null,l&&(l.current=null)}},[]),O.useEffect(()=>{const k=p.current;if(!k)return;const b=k.state.doc.toString();t!==b&&k.dispatch({changes:{from:0,to:b.length,insert:t||""}})},[t]),O.useEffect(()=>{const k=p.current;if(!k)return;const b=Vh[a]||Vh.javascript;k.dispatch({effects:f.current.reconfigure(b())})},[a]),e.jsx("div",{ref:u,className:"w-full h-full overflow-hidden"})}const z$e=["png","jpg","jpeg","gif","svg","webp","ico","bmp","avif"],YH=["mp4","webm","mov","avi","mkv","ogv"];function T$e(t){var s;const a=(s=t.split(".").pop())==null?void 0:s.toLowerCase();return z$e.includes(a)||YH.includes(a)}function P$e({path:t}){var l;const a=(l=t.split(".").pop())==null?void 0:l.toLowerCase(),s=`/api/files/raw?path=${encodeURIComponent(t)}`,c=t.split("/").pop(),r=YH.includes(a);return e.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center bg-surface-0 p-8 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-3 font-sans",children:[e.jsx(ge,{children:a==null?void 0:a.toUpperCase()}),e.jsx("span",{className:"font-mono",children:c}),e.jsx("a",{href:s,target:"_blank",rel:"noopener",className:"text-accent hover:text-accent/80 transition-colors",children:e.jsx(Pt,{size:12})})]}),r?e.jsx("video",{src:s,controls:!0,className:"max-w-full max-h-[70vh] rounded-md border border-border"}):e.jsx("img",{src:s,alt:c,className:"max-w-full max-h-[70vh] rounded-md border border-border object-contain"})]})}const A$e={javascript:"JavaScript",typescript:"TypeScript",css:"CSS",html:"HTML",json:"JSON",markdown:"Markdown",python:"Python"};function q$e({cursorPos:t,language:a}){return e.jsxs("div",{className:"flex items-center justify-between h-6 px-3 bg-surface-1 border-t border-border-subtle text-2xs font-sans text-text-3 flex-shrink-0 select-none",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("span",{children:["Ln ",t.line,", Col ",t.col]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"cursor-default",children:A$e[a]||a||"Plain Text"}),e.jsx("span",{children:"Spaces: 2"}),e.jsx("span",{children:"UTF-8"})]})]})}function I$e({currentLine:t,onGoto:a,onClose:s}){const[c,r]=O.useState(""),l=O.useRef(null);O.useEffect(()=>{var p;(p=l.current)==null||p.focus()},[]);function u(p){if(p.key==="Enter"){const f=parseInt(c,10);f>0&&a(f),s()}p.key==="Escape"&&s()}return e.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20 flex items-center gap-2 bg-surface-2 border border-border rounded-lg shadow-xl p-2",children:[e.jsx("label",{className:"text-2xs font-sans text-text-3 whitespace-nowrap",children:"Go to Line:"}),e.jsx("input",{ref:l,value:c,onChange:p=>r(p.target.value),onKeyDown:u,onBlur:s,placeholder:String(t),className:"w-20 h-6 px-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-mono focus:outline-none focus:border-accent"})]})}function R$e({path:t}){if(!t)return null;const a=t.split("/").filter(Boolean);return e.jsx("div",{className:"flex items-center h-7 px-3 bg-surface-2 border-b border-border-subtle text-2xs font-sans text-text-3 overflow-hidden flex-shrink-0 select-none",children:a.map((s,c)=>{const r=c===a.length-1;return e.jsxs("span",{className:"flex items-center min-w-0",children:[c>0&&e.jsx(Xt,{size:10,className:"mx-0.5 flex-shrink-0 text-text-4"}),e.jsx("span",{className:r?"text-text-1 font-medium truncate":"hover:text-text-1 cursor-pointer truncate transition-colors",children:s})]},c)})})}function V$e(t){var s;const a=(s=t==null?void 0:t.split(".").pop())==null?void 0:s.toLowerCase();return a==="html"||a==="htm"}const E$e=240,X$e=160,Z$e=400;function D$e(){const t=q(oe=>oe.editorActiveFile),a=q(oe=>oe.editorFiles),s=q(oe=>oe.editorChangedFiles),c=q(oe=>oe.updateFileContent),r=q(oe=>oe.saveFile),l=q(oe=>oe.reloadFile),u=q(oe=>oe.dismissFileChange),p=q(oe=>oe.editorSidebarWidth),f=q(oe=>oe.setEditorSidebarWidth),[x,g]=O.useState(""),[y,k]=O.useState(!1),[b,j]=O.useState(0),[w,S]=O.useState({line:1,col:1}),[M,$]=O.useState(!1),C=O.useRef(null),_=O.useRef(!1),P=O.useRef(0),L=O.useRef(0);O.useEffect(()=>{X.get("/files/root").then(oe=>g(oe.root||"")).catch(()=>{})},[]),O.useEffect(()=>{k(!1)},[t]),O.useEffect(()=>{function oe(R){(R.metaKey||R.ctrlKey)&&R.key==="g"&&(R.preventDefault(),$(!0))}return document.addEventListener("keydown",oe),()=>document.removeEventListener("keydown",oe)},[]);const A=O.useCallback(oe=>{oe.preventDefault(),_.current=!0,P.current=oe.clientX,L.current=p;function R(T){if(!_.current)return;const Z=T.clientX-P.current,J=Math.min(Math.max(L.current+Z,X$e),Z$e);f(J)}function I(){_.current=!1,document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",I)}document.addEventListener("mousemove",R),document.addEventListener("mouseup",I)},[p,f]);function z(oe){const R=C.current;if(!R)return;const I=R.state.doc.line(Math.min(oe,R.state.doc.lines));R.dispatch({selection:{anchor:I.from},scrollIntoView:!0}),R.focus()}const Y=t?a[t]:null,V=t&&T$e(t),se=t&&V$e(t),ne=t&&s[t];return e.jsxs("div",{className:"flex h-full",children:[e.jsxs("div",{className:"flex-shrink-0 border-r border-border relative",style:{width:p},children:[e.jsx(tje,{rootDir:x}),e.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:A,onDoubleClick:()=>f(E$e)})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsx(aje,{}),t&&!V&&e.jsx(R$e,{path:t}),e.jsxs("div",{className:"flex-1 relative min-h-0",children:[M&&e.jsx(I$e,{currentLine:w.line,onGoto:z,onClose:()=>$(!1)}),ne&&e.jsxs("div",{className:"absolute top-0 left-0 right-0 z-10 flex items-center gap-2 px-4 py-2 bg-warning/10 border-b border-warning/20",children:[e.jsx(Et,{size:14,className:"text-warning"}),e.jsx("span",{className:"text-xs text-warning font-sans flex-1",children:"File modified externally"}),e.jsxs(he,{variant:"ghost",size:"sm",onClick:()=>l(t),children:[e.jsx(ia,{size:12})," Reload"]}),e.jsxs(he,{variant:"ghost",size:"sm",onClick:()=>u(t),children:[e.jsx(st,{size:12})," Dismiss"]})]}),!t&&e.jsx("div",{className:"w-full h-full flex items-center justify-center text-text-4 font-sans",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(ra,{size:32,className:"mx-auto"}),e.jsx("p",{className:"text-sm",children:"Open a file from the tree"})]})}),t&&V&&e.jsx(P$e,{path:t}),t&&!V&&se&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"absolute top-0 right-4 z-10 flex items-center gap-0.5 mt-2 bg-surface-2 border border-border-subtle rounded-md p-0.5",children:[e.jsxs("button",{onClick:()=>k(!1),className:K("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",y?"text-text-3 hover:text-text-1":"bg-surface-4 text-text-0 font-medium"),children:[e.jsx(g2,{size:12})," Code"]}),e.jsxs("button",{onClick:()=>{k(!0),j(oe=>oe+1)},className:K("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",y?"bg-surface-4 text-text-0 font-medium":"text-text-3 hover:text-text-1"),children:[e.jsx(ka,{size:12})," Preview"]})]}),y?e.jsx("iframe",{src:`/api/files/raw?path=${encodeURIComponent(t)}`,className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin",title:"HTML Preview"},b):Y&&e.jsx(pX,{content:Y.content,language:Y.language,onChange:oe=>c(t,oe),onSave:()=>r(t),onCursorChange:S,viewRef:C})]}),t&&!V&&!se&&Y&&e.jsx(pX,{content:Y.content,language:Y.language,onChange:oe=>c(t,oe),onSave:()=>r(t),onCursorChange:S,viewRef:C})]}),t&&!V&&e.jsx(q$e,{cursorPos:w,language:Y==null?void 0:Y.language})]})]})}function U$e(){var C;const t=q(_=>_.connected),a=q(_=>_.agents),[s,c]=O.useState(null),[r,l]=O.useState([]),[u,p]=O.useState({constraints:[],discoveries:[],roles:[],specializations:null}),[f,x]=O.useState(!0),[g,y]=O.useState({tokens:[],cost:[],saved:[],efficiency:[],cache:[],inputOutput:[],agents:[],turns:[]}),k=O.useRef(0);O.useEffect(()=>{if(!t)return;let _=!0;async function P(){try{const[A,z,Y,V,se,ne]=await Promise.all([X.get("/dashboard"),X.get("/tokens/by-team").catch(()=>({teams:[]})),X.get("/memory/constraints").catch(()=>({constraints:[]})),X.get("/memory/discoveries?limit=20").catch(()=>({discoveries:[]})),X.get("/memory/handoff-chain").catch(()=>({roles:[]})),X.get("/memory/specializations").catch(()=>({perAgent:{},perProjectRole:{}}))]);if(!_)return;c(A),l((z==null?void 0:z.teams)||[]),p({constraints:(Y==null?void 0:Y.constraints)||[],discoveries:(V==null?void 0:V.discoveries)||[],roles:(se==null?void 0:se.roles)||[],specializations:ne||{perAgent:{},perProjectRole:{}}}),x(!1),k.current=Date.now(),y(oe=>{var pe,fe,Oe,Se,ue,ve,it,Le,Mt;const R=Date.now(),I=(lt,pt)=>[...lt.slice(-59),{t:R,v:pt||0}],T=((pe=A.tokens)==null?void 0:pe.totalTokens)||0,Z=((fe=A.tokens)==null?void 0:fe.totalInputTokens)||0,J=((Oe=A.tokens)==null?void 0:Oe.totalOutputTokens)||0,U=(((Se=A.agents)==null?void 0:Se.breakdown)||[]).filter(lt=>{var pt;return((pt=lt.quality)==null?void 0:pt.score)!=null}),xe=U.length>0?U.reduce((lt,pt)=>lt+pt.quality.score,0)/U.length:0;return{tokens:I(oe.tokens,T),cost:I(oe.cost,(ue=A.tokens)==null?void 0:ue.totalCostUsd),saved:I(oe.saved,xe),efficiency:I(oe.efficiency,((ve=A.rotation)==null?void 0:ve.totalRotations)||0),cache:I(oe.cache,(it=A.tokens)==null?void 0:it.cacheHitRate),inputOutput:I(oe.inputOutput,J>0?Z/J:0),agents:I(oe.agents,((Le=A.agents)==null?void 0:Le.running)||0),turns:I(oe.turns,(Mt=A.tokens)==null?void 0:Mt.totalTurns)}})}catch{_&&x(!1)}}P();const L=setInterval(P,4e3);return()=>{_=!1,clearInterval(L)}},[t]);const b=((C=s==null?void 0:s.agents)==null?void 0:C.breakdown)||[],j=(s==null?void 0:s.routing)||null,w=(s==null?void 0:s.rotation)||null,S=(s==null?void 0:s.adaptive)||[],M=(s==null?void 0:s.journalist)||null,$=(w==null?void 0:w.rotating)||[];return{data:s,loading:f,agents:a,connected:t,kpiHistory:g,lastFetch:k.current,agentBreakdown:b,routing:j,rotation:w,adaptive:S,journalist:M,rotating:$,teamBurn:r,memory:u}}const fX=O.memo(function({connected:a,runningCount:s,totalCount:c,uptime:r,lastFetch:l,activeTeam:u}){return e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border",children:[e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Command Center"}),u&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-xs font-mono text-text-2",children:u.name})]}),e.jsx("div",{className:"flex-1"}),a&&e.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-text-1",children:s}),e.jsxs("span",{className:"text-text-3",children:["/",c]}),e.jsx("span",{className:"ml-1 text-text-3",children:"agents"})]}),r>0&&e.jsxs("span",{className:"text-text-3",children:["Up ",su(r)]}),l>0&&e.jsxs("span",{className:"flex items-center gap-1 text-text-4",children:[e.jsx(ia,{size:9}),e.jsx("span",{children:gt(l)})]})]}),e.jsx(aa,{status:a?"running":"crashed",size:"sm"})]})});function ct(t,a){const s=parseInt(t.slice(1,3),16),c=parseInt(t.slice(3,5),16),r=parseInt(t.slice(5,7),16);return`rgba(${s},${c},${r},${a})`}const ce={surface0:"#1a1e25",surface3:"#282c34",surface4:"#2c313a",surface5:"#333842",text0:"#e6e6e6",text1:"#bcc2cd",text2:"#8b929e",text3:"#6e7681",text4:"#505862",accent:"#33afbc",success:"#4ae168",warning:"#e5c07b",danger:"#e06c75",info:"#61afef",purple:"#c678dd",orange:"#d19a66"};function H$e({data:t,color:a=ce.accent,width:s=72,height:c=22}){if(!t||t.length<2)return e.jsx("div",{style:{width:s,height:c}});const r=t.map(g=>g.v),l=Math.min(...r),p=Math.max(...r)-l||1,f=t.map((g,y)=>{const k=y/(t.length-1)*s,b=c-(g.v-l)/p*(c-2)-1;return`${k},${b}`}).join(" "),x=`kpi-${a.replace("#","")}`;return e.jsxs("svg",{width:s,height:c,className:"flex-shrink-0",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:x,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:a,stopOpacity:"0.2"}),e.jsx("stop",{offset:"100%",stopColor:a,stopOpacity:"0"})]})}),e.jsx("polygon",{points:`0,${c} ${f} ${s},${c}`,fill:`url(#${x})`}),e.jsx("polyline",{points:f,fill:"none",stroke:a,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}const B$e=O.memo(function({label:a,value:s,sparkData:c,color:r=ce.accent,hint:l,className:u}){return e.jsxs("div",{className:K("flex items-center gap-2.5 px-3 py-2.5 min-w-0","bg-surface-1",u),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5 truncate flex items-center gap-1",children:[a,l&&e.jsx($1,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:l}),side:"bottom",children:e.jsx(Wt,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),e.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:s})]}),e.jsx(H$e,{data:c,color:r})]})});function G$e({kpis:t}){return e.jsx("div",{className:"flex flex-wrap border-b border-border",style:{background:"var(--color-surface-0)"},children:t.map(a=>e.jsx(B$e,{label:a.label,value:a.value,sparkData:a.sparkData,color:a.color,hint:a.hint,className:K("flex-1 basis-[12.5%] min-w-[140px]","border-b border-r border-border")},a.label))})}const W$e={actual:"ACT",estimated:"EST",local:"LOC"};function Y$e(t){if(!t||t==="auto"||t==="default")return"default";const a=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return a?`${a[1][0].toUpperCase()}${a[1].slice(1)} ${a[2]}.${a[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gem ").replace("-preview",""):t.length>12?t.slice(0,12)+"...":t}const F$e=O.memo(function({agent:a,isRotating:s}){const c=a.status==="running"||a.status==="starting",r=Math.round((a.contextUsage||0)*100),l=s?"#c678dd":XP(a.status),u=a.quality,p=(u==null?void 0:u.toolSuccessRate)!=null?Math.round(u.toolSuccessRate*100):null,f=a.rotationThreshold?Math.round(a.rotationThreshold*100):null,x=Bo(a.role),g=r>80?ce.danger:r>60?ce.warning:ce.accent;return e.jsxs("div",{className:"px-3 pl-6 py-2 hover:bg-[rgba(51,175,188,0.06)] transition-colors space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:l}}),c&&e.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:l,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate leading-none flex-shrink-0 max-w-[80px]",children:a.name}),e.jsx("span",{className:"text-2xs font-mono font-semibold px-1.5 py-px rounded-sm flex-shrink-0 capitalize",style:{background:x.bg,color:x.text},children:(a.role||"").toLowerCase()}),e.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1 py-px rounded-sm flex-shrink-0 truncate max-w-[72px]",children:Y$e(a.model)}),e.jsx("div",{className:"flex-1"}),p!=null&&e.jsxs("span",{className:"text-2xs font-mono font-bold px-1 py-px rounded-sm flex-shrink-0",style:{color:p>=90?"#4ae168":p>=70?"#e5c07b":"#e06c75",background:p>=90?"rgba(74,225,104,0.1)":p>=70?"rgba(229,192,123,0.1)":"rgba(224,108,117,0.1)"},children:[p,"%"]}),a.costSource&&a.costSource!=="actual"&&e.jsx("span",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex-shrink-0",children:W$e[a.costSource]||""}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[e.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums leading-none",children:Fe(a.tokens||0)}),(a.costUsd||0)>0&&e.jsx("div",{className:"text-2xs font-mono text-text-3 mt-0.5",children:Jo(a.costUsd)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 h-0.5 rounded-sm overflow-visible",style:{background:ct(ce.accent,.12)},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 rounded-sm transition-all duration-700",style:{width:`${Math.max(r,1)}%`,background:g}}),f&&e.jsx("div",{className:"absolute top-[-1px] w-px h-[4px]",style:{left:`${f}%`,background:ce.purple},title:`Rotation at ${f}%`})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums flex-shrink-0 w-7 text-right",children:[r,"%"]})]})]})});function K$e({team:t,members:a,rotatingSet:s}){const[c,r]=O.useState(!0),l=a.filter(x=>x.status==="running"||x.status==="starting").length,u=l>0,p=a.reduce((x,g)=>x+(g.tokens||0),0),f=a.reduce((x,g)=>x+(g.costUsd||0),0);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>r(x=>!x),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-[rgba(51,175,188,0.08)] bg-[rgba(51,175,188,0.05)]",style:{borderLeft:u?`2px solid ${ce.accent}`:"2px solid transparent"},children:[c?e.jsx(zt,{size:10,className:"text-text-4 flex-shrink-0"}):e.jsx(Xt,{size:10,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-mono font-semibold text-text-2 uppercase tracking-widest flex-1 truncate",children:t}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:Fe(p)}),f>0&&e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums ml-1",children:Jo(f)}),e.jsxs("span",{className:"text-2xs font-mono tabular-nums flex-shrink-0 ml-1.5",style:{color:u?ce.accent:void 0},children:[l,"/",a.length]})]}),c&&a.map(x=>e.jsx(F$e,{agent:x,isRotating:s.has(x.id)},x.id))]})}const J$e=O.memo(function({agentBreakdown:a,rotating:s=[],teams:c=[]}){if(!(a!=null&&a.length))return e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono p-4",children:"No agents"});const r={};for(const p of c)r[p.id]=p.name;const l={};for(const p of a){const f=p.teamId||"ungrouped";l[f]||(l[f]=[]),l[f].push(p)}const u=new Set(s);return e.jsx(It,{className:"flex-1",children:e.jsx("div",{className:"py-1",children:Object.entries(l).map(([p,f])=>e.jsx(K$e,{team:r[p]||(p==="ungrouped"?"Ungrouped":p),members:f,rotatingSet:u},p))})})}),eCe=O.memo(function({data:a}){const s=O.useRef(null),c=O.useRef(null),[r,l]=O.useState({width:0,height:0}),[u,p]=O.useState(null),{width:f,height:x}=r,g={top:28,right:12,bottom:8,left:12},y=Math.max(f-g.left-g.right,0),k=Math.max(x-g.top-g.bottom,0),b=O.useMemo(()=>!a||a.length<2?[]:a.slice(1).map((S,M)=>{const $=a[M],C=(S.t-$.t)/6e4,_=Math.max((S.tokens||0)-($.tokens||0),0);return{burnRate:C>0?Math.round(_/C):0,cacheHitRate:S.cacheHitRate||0,running:S.running||0,agents:S.agents||0,t:S.t}}),[a]);O.useEffect(()=>{const S=s.current;if(!S)return;const M=new ResizeObserver($=>{const{width:C,height:_}=$[0].contentRect;C>0&&_>0&&l({width:Math.floor(C),height:Math.floor(_)})});return M.observe(S),()=>M.disconnect()},[]);const j=O.useCallback(S=>{const M=c.current;if(!M||!b.length||y<=0)return;const $=M.getBoundingClientRect(),C=S.clientX-$.left-g.left;if(C<0||C>y){p(null);return}const _=Math.round(C/y*(b.length-1));p({x:g.left+_/Math.max(b.length-1,1)*y,index:_})},[b,y,g.left]),w=O.useCallback(()=>p(null),[]);return O.useEffect(()=>{const S=c.current;if(!S||!b.length||f<=0||x<=0||y<=0||k<=0)return;const M=S.getContext("2d"),$=window.devicePixelRatio||1;S.width=f*$,S.height=x*$,M.scale($,$),M.clearRect(0,0,f,x);const C=b.map(T=>T.burnRate),_=b.map(T=>T.cacheHitRate),P=b.map(T=>T.running),L=Math.max(...C,100),A=Math.max(...P,1),z=T=>g.left+T/Math.max(b.length-1,1)*y,Y=T=>g.top+k-T/L*k,V=T=>g.top+k-T*k,se=Math.max(y/b.length-1,2);for(let T=0;T<b.length;T++){const Z=P[T];if(Z<=0)continue;const J=Z/A*k*.3,W=z(T)-se/2,U=g.top+k-J;M.fillStyle=ct(ce.surface5,.5),M.fillRect(W,U,se,J)}M.setLineDash([2,4]),M.strokeStyle=ct(ce.text4,.2),M.lineWidth=1;for(let T=1;T<=3;T++){const Z=g.top+k/4*T;M.beginPath(),M.moveTo(g.left,Z),M.lineTo(g.left+y,Z),M.stroke()}M.setLineDash([]),M.font="9px 'JetBrains Mono Variable', monospace",M.textAlign="left",M.fillStyle=ct(ce.text3,.5),M.fillText(`${Fe(L)}/m`,g.left+4,g.top+10),M.fillText(`${Fe(Math.round(L/2))}/m`,g.left+4,g.top+k/2+4),M.beginPath(),M.moveTo(g.left,g.top+k);for(let T=0;T<b.length;T++)M.lineTo(z(T),Y(C[T]));M.lineTo(z(b.length-1),g.top+k),M.closePath();const ne=M.createLinearGradient(0,g.top,0,g.top+k);ne.addColorStop(0,ct(ce.accent,.2)),ne.addColorStop(.7,ct(ce.accent,.04)),ne.addColorStop(1,ct(ce.accent,0)),M.fillStyle=ne,M.fill(),M.beginPath(),M.strokeStyle=ce.accent,M.lineWidth=1.5,M.lineJoin="round";for(let T=0;T<b.length;T++){const Z=z(T),J=Y(C[T]);T===0?M.moveTo(Z,J):M.lineTo(Z,J)}M.stroke();const oe=_.some(T=>T>0);if(oe){M.beginPath(),M.strokeStyle=ct(ce.info,.45),M.lineWidth=1,M.lineJoin="round",M.setLineDash([2,3]);for(let T=0;T<b.length;T++){const Z=z(T),J=V(_[T]);T===0?M.moveTo(Z,J):M.lineTo(Z,J)}M.stroke(),M.setLineDash([])}M.font="9px 'Inter Variable', sans-serif",M.textAlign="right";let R=f-g.right-4;const I=14;if(oe&&(M.fillStyle=ct(ce.info,.5),M.fillText("Cache %",R,I),R-=M.measureText("Cache %").width+4,M.beginPath(),M.arc(R,I-3,2.5,0,Math.PI*2),M.fill(),R-=14),M.fillStyle=ct(ce.surface5,.7),M.fillText("Agents",R,I),R-=M.measureText("Agents").width+4,M.beginPath(),M.arc(R,I-3,2.5,0,Math.PI*2),M.fill(),R-=14,M.fillStyle=ce.accent,M.fillText("Burn Rate",R,I),R-=M.measureText("Burn Rate").width+4,M.beginPath(),M.arc(R,I-3,2.5,0,Math.PI*2),M.fill(),u&&u.index>=0&&u.index<b.length){const T=u.x,Z=b[u.index];M.beginPath(),M.moveTo(T,g.top),M.lineTo(T,g.top+k),M.strokeStyle=ct(ce.text1,.15),M.lineWidth=1,M.stroke();const J=Y(Z.burnRate);M.beginPath(),M.arc(T,J,3,0,Math.PI*2),M.fillStyle=ce.accent,M.fill();const W=[{label:"Burn",value:`${Fe(Z.burnRate)}/m`,color:ce.accent},{label:"Cache",value:xn(Z.cacheHitRate*100),color:ce.info},{label:"Agents",value:`${Z.running}/${Z.agents}`,color:ce.text2}],U=104,xe=W.length*16+12;let pe=T+12;pe+U>f-8&&(pe=T-U-12);const fe=Math.max(g.top,J-xe/2);M.fillStyle=ct(ce.surface0,.92),M.beginPath(),M.roundRect(pe,fe,U,xe,4),M.fill(),M.strokeStyle=ct(ce.text4,.2),M.lineWidth=1,M.stroke(),M.textAlign="left",W.forEach((Oe,Se)=>{const ue=fe+14+Se*16;M.beginPath(),M.arc(pe+8,ue-3,2,0,Math.PI*2),M.fillStyle=Oe.color,M.fill(),M.font="8px 'Inter Variable', sans-serif",M.fillStyle=ce.text3,M.fillText(Oe.label,pe+14,ue),M.font="9px 'JetBrains Mono Variable', monospace",M.fillStyle=ce.text0,M.textAlign="right",M.fillText(Oe.value,pe+U-8,ue),M.textAlign="left"})}},[b,f,x,u,y,k,g]),e.jsx("div",{ref:s,className:"absolute inset-0",children:f>0&&x>0&&e.jsx("canvas",{ref:c,style:{width:f,height:x},className:"block cursor-crosshair",onMouseMove:j,onMouseLeave:w})})}),tCe=O.memo(function({cacheRead:a=0,cacheCreation:s=0,totalInput:c=0,size:r=140}){const l=O.useRef(null),u=a+s,p=u,f=u>0?a/u*100:0;return O.useEffect(()=>{const x=l.current;if(!x)return;const g=window.devicePixelRatio||1;x.width=r*g,x.height=r*g;const y=x.getContext("2d");y.scale(g,g),y.clearRect(0,0,r,r);const k=r/2,b=r/2,j=(r-12)/2,w=5,S=135*Math.PI/180,M=405*Math.PI/180,$=M-S;if(y.beginPath(),y.arc(k,b,j,S,M),y.strokeStyle=ce.surface4,y.lineWidth=w,y.lineCap="round",y.stroke(),p>0){const C=a/p,_=s/p;if(C>0){const P=S+$*C;y.beginPath(),y.arc(k,b,j,S,P),y.strokeStyle=ce.accent,y.lineWidth=w,y.lineCap="round",y.stroke()}if(_>0){const P=S+$*C,L=P+$*_;y.beginPath(),y.arc(k,b,j,P,L),y.strokeStyle=ce.purple,y.lineWidth=w,y.lineCap="butt",y.stroke()}}y.textAlign="center",y.textBaseline="middle",y.font=`600 ${r*.2}px 'JetBrains Mono Variable', monospace`,y.fillStyle=ce.text0,y.fillText(`${Math.round(f)}%`,k,b-3),y.font=`500 ${r*.08}px 'JetBrains Mono Variable', monospace`,y.fillStyle=ce.text3,y.fillText("CACHE",k,b+r*.13)},[a,s,c,r,p,f]),e.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-3 py-3",children:[e.jsx("canvas",{ref:l,className:"flex-shrink-0",style:{width:r,height:r}}),e.jsxs("div",{className:"w-full mt-3 space-y-1.5 max-w-[160px]",children:[e.jsx(FT,{color:ce.accent,label:"Read",value:Fe(a)}),e.jsx(FT,{color:ce.purple,label:"Create",value:Fe(s)}),e.jsx(FT,{color:ce.surface5,label:"Miss",value:Fe(Math.max(c-a-s,0))})]})]})});function FT({color:t,label:a,value:s}){return e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:t}}),e.jsx("span",{className:"text-text-3 uppercase tracking-wider flex-1",children:a}),e.jsx("span",{className:"text-text-1 tabular-nums",children:s})]})}const xX={heavy:ce.danger,medium:ce.warning,light:ce.success},mX={heavy:"Heavy",medium:"Medium",light:"Light"},aCe=O.memo(function({routing:a,agentBreakdown:s}){if(!a)return null;const{byTier:c={},totalDecisions:r=0,autoRoutedCount:l=0}=a,u=["heavy","medium","light"],p=u.reduce((y,k)=>y+(c[k]||0),0),f={};for(const y of s||[]){const k=y.model||"default";f[k]||(f[k]={tokens:0,agents:0}),f[k].tokens+=y.tokens||0,f[k].agents+=1}const x=Object.entries(f).sort((y,k)=>k[1].tokens-y[1].tokens),g=x.length>0?x[0][1].tokens:0;return e.jsxs("div",{className:"flex flex-col h-full px-3 py-3 overflow-y-auto",children:[p>0&&e.jsxs("div",{className:"space-y-1.5 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Tier Distribution"}),e.jsxs("span",{className:"text-2xs font-mono text-text-4 ml-auto tabular-nums",children:[Fe(p)," decisions"]})]}),e.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden flex",children:u.map(y=>{const k=c[y]||0;if(k===0)return null;const b=k/p*100;return e.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${b}%`,background:xX[y]},title:`${mX[y]}: ${k} (${Math.round(b)}%)`},y)})}),e.jsx("div",{className:"flex items-center gap-3",children:u.map(y=>{const k=c[y]||0;if(k===0)return null;const b=p>0?k/p*100:0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:xX[y]}}),e.jsx("span",{className:"text-2xs font-mono text-text-2",children:mX[y]}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums",children:xn(b)})]},y)})})]}),x.length>0&&e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Models in Use"}),l>0&&e.jsxs("span",{className:"text-2xs font-mono text-text-4 ml-auto",children:[l," auto"]})]}),e.jsx("div",{className:"space-y-1.5",children:x.map(([y,k])=>{const b=g>0?k.tokens/g*100:0;return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 flex-1 truncate",children:nCe(y)}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[k.agents," agent",k.agents!==1?"s":""]}),e.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:Fe(k.tokens)})]}),e.jsx("div",{className:"h-0.5 bg-surface-4 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.max(b,2)}%`,background:ce.accent}})})]},y)})})]}),p===0&&x.length===0&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono",children:"No routing data"})]})});function nCe(t){if(!t||t==="auto"||t==="default")return"Default";const a=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return a?`${a[1][0].toUpperCase()}${a[1].slice(1)} ${a[2]}.${a[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gemini ").replace("-preview",""):t}var YQ="Tabs",[sCe]=Ys(YQ,[ZQ]),FH=ZQ(),[oCe,wA]=sCe(YQ),KH=O.forwardRef((t,a)=>{const{__scopeTabs:s,value:c,onValueChange:r,defaultValue:l,orientation:u="horizontal",dir:p,activationMode:f="automatic",...x}=t,g=XQ(p),[y,k]=qQ({prop:c,onChange:r,defaultProp:l??"",caller:YQ});return e.jsx(oCe,{scope:s,baseId:$d(),value:y,onValueChange:k,orientation:u,dir:g,activationMode:f,children:e.jsx(Ye.div,{dir:g,"data-orientation":u,...x,ref:a})})});KH.displayName=YQ;var JH="TabsList",eB=O.forwardRef((t,a)=>{const{__scopeTabs:s,loop:c=!0,...r}=t,l=wA(JH,s),u=FH(s);return e.jsx(zD,{asChild:!0,...u,orientation:l.orientation,dir:l.dir,loop:c,children:e.jsx(Ye.div,{role:"tablist","aria-orientation":l.orientation,...r,ref:a})})});eB.displayName=JH;var tB="TabsTrigger",aB=O.forwardRef((t,a)=>{const{__scopeTabs:s,value:c,disabled:r=!1,...l}=t,u=wA(tB,s),p=FH(s),f=oB(u.baseId,c),x=cB(u.baseId,c),g=c===u.value;return e.jsx(TD,{asChild:!0,...p,focusable:!r,active:g,children:e.jsx(Ye.button,{type:"button",role:"tab","aria-selected":g,"aria-controls":x,"data-state":g?"active":"inactive","data-disabled":r?"":void 0,disabled:r,id:f,...l,ref:a,onMouseDown:$e(t.onMouseDown,y=>{!r&&y.button===0&&y.ctrlKey===!1?u.onValueChange(c):y.preventDefault()}),onKeyDown:$e(t.onKeyDown,y=>{[" ","Enter"].includes(y.key)&&u.onValueChange(c)}),onFocus:$e(t.onFocus,()=>{const y=u.activationMode!=="manual";!g&&!r&&y&&u.onValueChange(c)})})})});aB.displayName=tB;var nB="TabsContent",sB=O.forwardRef((t,a)=>{const{__scopeTabs:s,value:c,forceMount:r,children:l,...u}=t,p=wA(nB,s),f=oB(p.baseId,c),x=cB(p.baseId,c),g=c===p.value,y=O.useRef(g);return O.useEffect(()=>{const k=requestAnimationFrame(()=>y.current=!1);return()=>cancelAnimationFrame(k)},[]),e.jsx(la,{present:r||g,children:({present:k})=>e.jsx(Ye.div,{"data-state":g?"active":"inactive","data-orientation":p.orientation,role:"tabpanel","aria-labelledby":f,hidden:!k,id:x,tabIndex:0,...u,ref:a,style:{...t.style,animationDuration:y.current?"0s":void 0},children:k&&l})})});sB.displayName=nB;function oB(t,a){return`${t}-trigger-${a}`}function cB(t,a){return`${t}-content-${a}`}var cCe=KH,rCe=eB,iCe=aB,lCe=sB;function MA({children:t,...a}){return e.jsx(cCe,{...a,children:t})}function jA({children:t,className:a,...s}){return e.jsx(rCe,{className:K("flex items-center gap-0 border-b border-border-subtle",a),...s,children:t})}function kn({children:t,className:a,...s}){return e.jsx(iCe,{className:K("px-3 py-2 text-sm font-medium font-sans text-text-2","border-b-2 border-transparent","hover:text-text-0 hover:bg-surface-5/50","data-[state=active]:text-text-0 data-[state=active]:border-accent","transition-colors duration-100 cursor-pointer select-none","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a),...s,children:t})}function vn({children:t,className:a,...s}){return e.jsx(lCe,{className:K("flex-1 min-h-0",a),...s,children:t})}function yX({data:t,color:a=ce.accent,width:s=60,height:c=16}){if(!t||t.length<2)return e.jsx("div",{style:{width:s,height:c}});const r=Array.isArray(t[0])?t:t.map(x=>typeof x=="number"?x:x.v),l=Math.min(...r),p=Math.max(...r)-l||1,f=r.map((x,g)=>{const y=g/(r.length-1)*s,k=c-(x-l)/p*(c-2)-1;return`${y},${k}`}).join(" ");return e.jsx("svg",{width:s,height:c,className:"flex-shrink-0",children:e.jsx("polyline",{points:f,fill:"none",stroke:a,strokeWidth:"1",strokeLinejoin:"round",strokeOpacity:"0.7"})})}function Wn({text:t,side:a="bottom"}){return e.jsx($1,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:t}),side:a,children:e.jsx(Wt,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors inline-block ml-1"})})}function SA(t){return t==null?ce.text3:t>=70?"#4ae168":t>=40?"#e5c07b":"#e06c75"}function Po({label:t,value:a,danger:s}){return a==null||a===0?null:e.jsxs("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3",children:[t,": ",e.jsx("span",{style:{color:s?"#e06c75":ce.text1},children:a})]})}function dCe({score:t}){const a=Math.max(0,Math.min(100,t||0)),s=SA(t);return e.jsx("div",{className:"h-0.5 rounded-sm overflow-hidden flex-1",style:{background:"rgba(51,175,188,0.08)"},children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-700",style:{width:`${a}%`,background:s}})})}function KT({label:t,value:a,total:s,color:c}){const r=s>0?a/s*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-mono text-text-2",children:t}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs font-mono font-semibold tabular-nums",style:{color:c},children:[r>=1?Math.round(r):r>0?r.toFixed(1):0,"%"]}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums w-10 text-right",children:Fe(a)})]})]}),e.jsx("div",{className:"h-0.5 rounded-sm overflow-hidden",style:{background:"rgba(51,175,188,0.08)"},children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.min(r,100)}%`,background:c}})})]})}function uCe({tokens:t,rotation:a,agentBreakdown:s}){var k,b,j;const c=((a==null?void 0:a.history)||[]).slice(-10).reverse(),r=(a==null?void 0:a.liveScores)||{},l=(s||[]).filter(w=>w.status==="running"),u=s||[],p=u.filter(w=>{var S;return((S=w.quality)==null?void 0:S.score)!=null}),f=p.length>0?Math.round(p.reduce((w,S)=>w+S.quality.score,0)/p.length):null,x=u.filter(w=>w.status==="completed"||w.status==="stopped").length,g=u.filter(w=>w.status==="crashed").length,y=x+g>0?Math.round(x/(x+g)*100):100;return e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Quality",e.jsx(Wn,{text:"Average session quality score (0-100). Based on error rate, tool failures, repetitions, and file churn. Below 40 triggers auto-rotation to prevent wasted tokens."})]}),e.jsx("div",{className:"text-base font-mono font-bold text-text-1 tabular-nums leading-none",children:f??"—"})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Rotations",e.jsx(Wn,{text:"Context rotations: quality-based (q), context threshold (c), and natural compactions (n) from provider-managed context resets. Each rotation preserves progress via a journalist handoff brief."})]}),e.jsx("div",{className:"text-base font-mono font-bold text-text-1 tabular-nums leading-none",children:(a==null?void 0:a.totalRotations)||0}),((a==null?void 0:a.qualityRotations)>0||(a==null?void 0:a.contextRotations)>0||(a==null?void 0:a.naturalCompactions)>0)&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:[a.qualityRotations||0,"q / ",a.contextRotations||0,"c / ",a.naturalCompactions||0,"n"]})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Cache",e.jsx(Wn,{text:"Prompt cache hit rate. Cache reads are ~90% cheaper than regular input tokens. Managed by your AI provider — GROOVE tracks it, doesn't control it."})]}),e.jsx("div",{className:"text-base font-mono font-bold text-text-1 tabular-nums leading-none",children:xn(((t==null?void 0:t.cacheHitRate)||0)*100)})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Success",e.jsx(Wn,{text:"Agent completion rate. Completed agents vs. crashed agents. High success rate means agents are finishing tasks without errors."})]}),e.jsxs("div",{className:"text-base font-mono font-bold text-text-1 tabular-nums leading-none",children:[y,"%"]})]})]}),l.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Live Agent Quality"}),e.jsx("div",{className:"space-y-2",children:l.map(w=>{const S=w.quality||{},M=r[w.id],$=(M==null?void 0:M.score)??S.score,C=Bo(w.role);return e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("span",{className:"text-2xs font-mono font-semibold capitalize px-1.5 py-px rounded-sm",style:{background:C.bg,color:C.text},children:w.role}),e.jsx("span",{className:"text-xs font-mono text-text-1 truncate flex-1",children:w.name}),e.jsx("span",{className:"text-sm font-mono font-bold tabular-nums",style:{color:SA($)},children:$??"—"})]}),e.jsx(dCe,{score:$}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:[e.jsx(Po,{label:"Errors",value:S.errorCount,danger:!0}),e.jsx(Po,{label:"Reps",value:S.repetitions,danger:!0}),e.jsx(Po,{label:"Churn",value:S.fileChurn,danger:!0}),e.jsx(Po,{label:"Tools",value:S.toolCalls}),e.jsx(Po,{label:"Files",value:S.filesWritten}),S.toolCalls>0&&e.jsxs("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3",children:["Success: ",e.jsxs("span",{style:{color:S.toolSuccessRate>=.8?"#4ae168":"#e5c07b"},children:[Math.round(S.toolSuccessRate*100),"%"]})]}),S.eventCount>0&&e.jsxs("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3",children:["Events: ",e.jsx("span",{className:"text-text-2",children:S.eventCount})]})]})]},w.id)})})]}),((k=t==null?void 0:t.internalOverhead)==null?void 0:k.tokens)>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider flex items-center",children:["GROOVE Overhead",e.jsx(Wn,{text:"Tokens consumed by GROOVE's own coordination: the Journalist (synthesis), PM (approval gates), Planner, Task Negotiator, Gateway, and user Q&A. Previously invisible — now tracked for honest ROI."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums",children:[Fe(t.internalOverhead.tokens)," tokens"]}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:Jo(t.internalOverhead.costUsd||0)}),t.totalTokens>0&&e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums",style:{color:ce.purple},children:[Math.round(t.internalOverhead.tokens/t.totalTokens*100),"%"]})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:Object.entries(t.internalOverhead.components||{}).sort((w,S)=>(S[1].tokens||0)-(w[1].tokens||0)).slice(0,6).map(([w,S])=>{const M=w.replace(/^__|__$/g,"").replace(/_/g," ");return e.jsxs("div",{className:"bg-surface-0 rounded px-2 py-1.5",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider truncate",children:M}),e.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums font-semibold",children:Fe(S.tokens||0)})]},w)})})]}),(((b=t==null?void 0:t.savings)==null?void 0:b.total)||0)>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider flex items-center",children:["Coordination Savings",e.jsx(Wn,{text:"Tokens saved vs. uncoordinated agents. Rotation savings are estimated from context degradation (pre/post velocity measurement underway). Conflict prevention and cold-start skip use fixed-overhead models. Compare against GROOVE Overhead above for honest ROI."})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums",children:[Fe(t.savings.total)," tokens"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(KT,{label:"Cold-start skip",value:t.savings.fromColdStartSkip||0,total:t.savings.total||1,color:ce.info}),e.jsxs("div",{className:"text-2xs font-mono text-text-4 pl-2",children:["estimated · ",(((j=t==null?void 0:t.savings)==null?void 0:j.fromColdStartSkip)||0)>0?"fixed overhead per skip":""]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(KT,{label:"Rotation",value:t.savings.fromRotation||0,total:t.savings.total||1,color:ce.accent}),e.jsx("div",{className:"text-2xs font-mono text-text-4 pl-2",children:"estimated · velocity measurement accumulating"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(KT,{label:"Conflict prevention",value:t.savings.fromConflictPrevention||0,total:t.savings.total||1,color:"#4ec9d4"}),e.jsx("div",{className:"text-2xs font-mono text-text-4 pl-2",children:"estimated · fixed overhead per conflict"})]})]})]}),c.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2.5",children:"Recent Rotations"}),e.jsx("div",{className:"space-y-0",children:c.map((w,S)=>{var L,A;const M=w.reason==="quality_degradation",$=w.reason==="natural_compaction",C=w.reason==="token_limit_exceeded",_=w.reason==="runaway_velocity",P=C?"#e06c75":_?"#ff8c42":M?"#e5c07b":$?"#c678dd":"#33afbc";return e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsxs("div",{className:"flex flex-col items-center flex-shrink-0",children:[e.jsx("div",{className:"h-1.5"}),e.jsx("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:S===0?P:`${P}25`,border:`1px solid ${P}80`,boxShadow:S===0?`0 0 6px ${P}60`:"none"}}),S<c.length-1&&e.jsx("div",{className:"w-px flex-1 mt-1",style:{background:"rgba(51,175,188,0.15)",minHeight:"12px"}})]}),e.jsx("div",{className:K("flex-1 bg-surface-0 rounded px-2 py-1.5",S<c.length-1&&"mb-2"),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 font-medium capitalize truncate flex-1",children:w.agentName||w.role}),C?e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums flex-shrink-0",style:{color:"#e06c75"},title:`Auto-rotated: agent burned ${(L=w.instanceTokens)==null?void 0:L.toLocaleString()} tokens in one session`,children:["T:",xn((w.instanceTokens||0)/1e6*100).replace("%","M")]}):_?e.jsxs("span",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums",style:{color:"#ff8c42"},title:`Auto-rotated: runaway velocity (${(A=w.velocity)==null?void 0:A.toLocaleString()} tokens in recent window)`,children:["V:",xn((w.velocity||0)/1e6*100).replace("%","M")]}),w.velocityDelta!=null&&w.velocityDelta>0&&e.jsxs("span",{className:"text-2xs font-mono tabular-nums",style:{color:"#4ae168"},title:`Post-rotation velocity dropped by ${w.velocityDelta.toLocaleString()} tokens — rotation worked`,children:["↓",xn(w.velocityDelta/1e6*100).replace("%","M")]})]}):M?e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums flex-shrink-0",style:{color:"#e5c07b"},children:["Q:",w.qualityScore]}):$?e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums flex-shrink-0",style:{color:"#c678dd"},children:[xn((w.contextUsage||0)*100)," → ",xn((w.contextAfter||0)*100)]}):e.jsx("span",{className:"text-2xs font-mono font-semibold tabular-nums flex-shrink-0",style:{color:(w.contextUsage||0)>.8?"#e06c75":"#33afbc"},children:xn((w.contextUsage||0)*100)}),e.jsx("span",{className:"text-2xs font-mono text-text-4 flex-shrink-0",children:gt(w.timestamp)})]})})]},S)})})]}):e.jsxs("div",{className:"bg-surface-0 rounded p-3 text-center space-y-1.5",children:[e.jsx("div",{className:"text-xs font-mono text-text-2 font-semibold",children:"Monitoring for degradation"}),e.jsx("div",{className:"text-2xs font-mono text-text-3 leading-relaxed",children:"Auto-rotation triggers when session quality drops below 40 (errors, repetitions, file churn) or context exceeds the adaptive threshold."})]})]})}function hCe({adaptive:t}){if(!(t!=null&&t.length))return e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"bg-surface-0 rounded p-4 text-center space-y-2",children:[e.jsx("div",{className:"text-xs font-mono text-text-2 font-semibold",children:"No adaptive profiles yet"}),e.jsx("div",{className:"text-2xs font-mono text-text-3 leading-relaxed",children:"Adaptive thresholds learn when each agent role benefits from rotation. GROOVE tracks quality scores and adjusts rotation triggers automatically — converging to the optimal threshold per role and provider."})]})});function a(s){const c=s.split(":");return{provider:c[0]||s,role:c[1]||""}}return e.jsx("div",{className:"p-3 space-y-3",children:t.map(s=>{var g,y;const{provider:c,role:r}=a(s.key),l=r||c,u=((g=s.thresholdHistory)==null?void 0:g.length)>1,p=((y=s.recentScores)==null?void 0:y.length)>1,f=Bo(l),x=s.lastSignals;return e.jsxs("div",{className:"rounded overflow-hidden",style:{background:"rgba(51,175,188,0.04)",borderLeft:s.converged?"2px solid #33afbc":"2px solid rgba(229,192,123,0.35)"},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1.5",children:[e.jsx("span",{className:"text-xs font-mono font-semibold capitalize px-1.5 py-px rounded-sm",style:{background:f.bg,color:f.text},children:l}),r&&e.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1.5 py-px rounded-sm",children:c}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"flex items-center gap-1 text-2xs font-mono font-bold px-2 py-px rounded-full",style:{background:s.converged?"rgba(74,225,104,0.12)":"rgba(229,192,123,0.12)",color:s.converged?"#4ae168":"#e5c07b"},children:[!s.converged&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:"#e5c07b",animation:"node-pulse-bar 1.5s ease-in-out infinite"}}),s.converged?"Converged":"Learning"]})]}),e.jsxs("div",{className:"flex items-end gap-5 px-3 pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-0.5",children:"Threshold"}),e.jsx("div",{className:"text-3xl font-mono font-bold tabular-nums leading-none",style:{color:s.converged?"#33afbc":"#e5c07b"},children:xn(s.threshold*100)})]}),e.jsxs("div",{className:"pb-0.5",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-0.5",children:"Adj."}),e.jsx("div",{className:"text-lg font-mono font-semibold text-text-1 tabular-nums",children:s.adjustments})]})]}),(u||p)&&e.jsxs("div",{className:"px-3 pb-2 space-y-2 overflow-hidden",children:[u&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-0.5",children:"Threshold history"}),e.jsx(yX,{data:s.thresholdHistory.map(k=>k.v),color:s.converged?ce.accent:ce.warning,width:240,height:32})]}),p&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-0.5",children:"Quality score"}),e.jsx(yX,{data:s.recentScores,color:ce.warning,width:240,height:24})]})]}),x&&e.jsxs("div",{className:"flex flex-wrap gap-1.5 px-3 pb-2.5",children:[e.jsx(Po,{label:"Errors",value:x.errorCount,danger:!0}),e.jsx(Po,{label:"Reps",value:x.repetitions,danger:!0}),e.jsx(Po,{label:"Churn",value:x.fileChurn,danger:!0}),x.toolSuccessRate!=null&&e.jsxs("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3",children:["Tools: ",e.jsxs("span",{className:"text-text-1",children:[Math.round(x.toolSuccessRate*100),"%"]})]})]})]},s.key)})})}function pCe({journalist:t}){var a;return t?e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5",children:"Cycles"}),e.jsx("div",{className:"text-lg font-mono font-semibold text-text-0 tabular-nums leading-none",children:t.cycleCount||0})]}),t.lastCycleAt&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5",children:"Last"}),e.jsx("div",{className:"text-xs font-mono text-text-2",children:gt(t.lastCycleAt)})]}),t.synthesizing&&e.jsx("span",{className:"text-2xs font-mono font-bold text-accent uppercase tracking-wider animate-pulse",children:"Synthesizing"})]}),t.lastSummary&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1",children:"Summary"}),e.jsx("div",{className:"text-xs font-sans text-text-2 leading-relaxed",children:t.lastSummary})]}),t.projectMap&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1",children:"Project Map"}),e.jsx("div",{className:"text-xs font-mono text-text-2 leading-relaxed whitespace-pre-wrap",children:t.projectMap})]}),t.decisions&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1",children:"Decisions"}),e.jsx("div",{className:"text-xs font-mono text-text-2 leading-relaxed whitespace-pre-wrap",children:t.decisions})]}),((a=t.recentHistory)==null?void 0:a.length)>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1.5",children:"History"}),e.jsx("div",{className:"space-y-1",children:t.recentHistory.slice().reverse().map((s,c)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono px-2 py-1 bg-surface-0 rounded",children:[e.jsxs("span",{className:"text-text-3",children:["#",s.cycle]}),e.jsxs("span",{className:"text-text-2 flex-1 truncate",children:[s.agentCount," agents"]}),e.jsx("span",{className:"text-text-4",children:gt(s.timestamp)})]},c))})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono p-4",children:"Journalist inactive"})}function fCe({memory:t}){var x,g;const a=(t==null?void 0:t.constraints)||[],s=(t==null?void 0:t.discoveries)||[],c=(t==null?void 0:t.roles)||[],r=((x=t==null?void 0:t.specializations)==null?void 0:x.perAgent)||{},l=((g=t==null?void 0:t.specializations)==null?void 0:g.perProjectRole)||{},u=Object.keys(r).length,p=Object.keys(l).length;return a.length+s.length+c.length===0&&u===0?e.jsxs("div",{className:"p-6 text-center text-xs font-mono text-text-3",children:[e.jsx(Ro,{size:24,className:"mx-auto mb-2 text-text-4"}),e.jsx("div",{children:"No memory accumulated yet"}),e.jsx("div",{className:"text-2xs text-text-4 mt-1",children:"Constraints, handoff chains, and discoveries populate as agents work"})]}):e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Constraints",e.jsx(Wn,{text:"Project rules discovered by agents or set by the user. Every new agent reads these on spawn to avoid rediscovering them."})]}),e.jsx("div",{className:"text-2xl font-mono font-bold tabular-nums leading-none",style:{color:ce.accent},children:a.length})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Discoveries",e.jsx(Wn,{text:"Error→fix pairs successful agents have recorded. Injected into future agent context so they don't rediscover known solutions."})]}),e.jsx("div",{className:"text-2xl font-mono font-bold tabular-nums leading-none",style:{color:ce.success},children:s.length})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Handoff Chains",e.jsx(Wn,{text:"Cumulative rotation briefs per role. Agent #50 knows what agent #1 struggled with. Each role keeps its last 10 rotation briefs."})]}),e.jsx("div",{className:"text-2xl font-mono font-bold tabular-nums leading-none",style:{color:ce.purple},children:c.length})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Specializations",e.jsx(Wn,{text:"Per-agent quality profiles: session counts, average quality, file touches, preferred thresholds."})]}),e.jsx("div",{className:"text-2xl font-mono font-bold tabular-nums leading-none",style:{color:ce.info},children:u}),p>0&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:["across ",p," roles"]})]})]}),a.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Project Constraints"}),e.jsxs("div",{className:"space-y-1",children:[a.slice(0,10).map(y=>e.jsxs("div",{className:"flex items-start gap-2 bg-surface-0 rounded px-2 py-1.5",children:[e.jsx("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3 uppercase tracking-wider flex-shrink-0 mt-0.5",children:y.category}),e.jsx("span",{className:"text-xs font-mono text-text-2 leading-relaxed flex-1",children:y.text})]},y.hash)),a.length>10&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 px-2",children:["+",a.length-10," more"]})]})]}),s.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Recent Discoveries"}),e.jsx("div",{className:"space-y-1.5",children:s.slice(0,8).map((y,k)=>{const b=Bo(y.role);return e.jsxs("div",{className:"bg-surface-0 rounded px-2 py-1.5 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xs font-mono font-semibold capitalize px-1.5 py-px rounded-sm",style:{background:b.bg,color:b.text},children:y.role}),e.jsx("span",{className:"text-2xs font-mono text-text-4 flex-1",children:gt(y.ts)})]}),e.jsxs("div",{className:"text-xs font-mono text-text-2 leading-relaxed",children:[e.jsx("span",{className:"text-text-4",children:"When:"})," ",e.jsx("span",{className:"text-text-1",children:y.trigger})]}),e.jsxs("div",{className:"text-xs font-mono text-text-2 leading-relaxed",children:[e.jsx("span",{className:"text-text-4",children:"Fix:"})," ",e.jsx("span",{style:{color:ce.success},children:y.fix})]})]},k)})})]}),c.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Active Role Chains"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:c.map(y=>{const k=Bo(y);return e.jsx("span",{className:"text-2xs font-mono font-semibold capitalize px-2 py-1 rounded",style:{background:k.bg,color:k.text},children:y},y)})})]}),p>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Role Quality Profiles"}),e.jsx("div",{className:"space-y-1",children:Object.entries(l).map(([y,k])=>{const b=Bo(y);return e.jsxs("div",{className:"flex items-center gap-2 bg-surface-0 rounded px-2 py-1.5",children:[e.jsx("span",{className:"text-2xs font-mono font-semibold capitalize px-1.5 py-px rounded-sm",style:{background:b.bg,color:b.text},children:y}),e.jsxs("span",{className:"text-xs font-mono text-text-3 flex-1",children:[k.sessionCount," sessions"]}),e.jsxs("span",{className:"text-xs font-mono font-semibold tabular-nums",style:{color:SA(k.avgQualityScore)},children:["Q:",k.avgQualityScore]})]},y)})})]})]})}const xCe=O.memo(function({tokens:a,rotation:s,adaptive:c,journalist:r,agentBreakdown:l,memory:u}){return e.jsxs(MA,{defaultValue:"health",className:"flex flex-col h-full",children:[e.jsxs(jA,{className:"flex-shrink-0 px-1",children:[e.jsxs(kn,{value:"health",className:"text-xs px-2.5 py-1.5 inline-flex items-center gap-1.5",children:[e.jsx(Rs,{size:11}),"Health"]}),e.jsxs(kn,{value:"memory",className:"text-xs px-2.5 py-1.5 inline-flex items-center gap-1.5",children:[e.jsx(Ro,{size:11}),"Memory"]}),e.jsxs(kn,{value:"adaptive",className:"text-xs px-2.5 py-1.5 inline-flex items-center gap-1.5",children:[e.jsx(p2,{size:11}),"Adaptive"]}),e.jsxs(kn,{value:"journalist",className:"text-xs px-2.5 py-1.5 inline-flex items-center gap-1.5",children:[e.jsx(an,{size:11}),"Journalist"]})]}),e.jsx(vn,{value:"health",className:"flex-1 min-h-0 relative",children:e.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:e.jsx(uCe,{tokens:a,rotation:s,agentBreakdown:l})})}),e.jsx(vn,{value:"memory",className:"flex-1 min-h-0 relative",children:e.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:e.jsx(fCe,{memory:u})})}),e.jsx(vn,{value:"adaptive",className:"flex-1 min-h-0 relative",children:e.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:e.jsx(hCe,{adaptive:c})})}),e.jsx(vn,{value:"journalist",className:"flex-1 min-h-0 relative",children:e.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:e.jsx(pCe,{journalist:r})})})]})}),mCe=O.memo(function({teams:a=[]}){const s=a.reduce((r,l)=>r+(l.totalTokens||0),0),c=a.reduce((r,l)=>Math.max(r,l.totalTokens||0),0);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Team Burn"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:[Fe(s)," total"]})]}),e.jsx(It,{className:"flex-1 min-h-0",children:a.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-text-3 font-mono",children:"No team activity yet"}):e.jsx("div",{className:"px-3 py-3 space-y-3",children:a.map(r=>{const l=c>0?r.totalTokens/c*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:r.teamName}),r.isDefault&&e.jsx("span",{className:"text-[9px] font-mono text-text-3 uppercase tracking-wider",children:"default"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 flex-shrink-0",children:[r.agentCount," ",r.agentCount===1?"agent":"agents"]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 font-mono text-2xs",children:[e.jsx("span",{className:"text-text-1",children:Fe(r.totalTokens)}),e.jsx("span",{className:"text-text-3",children:Jo(r.totalCostUsd)})]})]}),e.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all",style:{width:`${l}%`,background:ce.accent}})})]},r.teamId)})})})]})}),yCe={spawn:I2,complete:ca,crash:Et,kill:yn,rotate:Xs,error:v1},gCe={spawn:"text-accent",complete:"text-success",crash:"text-danger",kill:"text-text-3",rotate:"text-purple",error:"text-danger"};function OCe(t){const a=t.agentName||t.role||"";switch(t.type){case"spawn":return`${a} spawned`;case"complete":return`${a} completed`;case"crash":return`${a} crashed`;case"kill":return`${a} killed`;case"rotate":return`${a} rotated`;default:return t.text||t.type||"event"}}const kCe=O.memo(function({events:a=[]}){return a.length?e.jsx("div",{className:"flex items-center gap-3 overflow-x-auto py-2 px-3",children:a.slice(-15).reverse().map((s,c)=>{const r=yCe[s.type]||qt,l=gCe[s.type]||"text-text-3",u=OCe(s);return e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(r,{size:11,className:l}),e.jsx("span",{className:"text-xs font-sans text-text-2 whitespace-nowrap",children:u}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:gt(s.t||s.timestamp)})]},c)})}):e.jsx("div",{className:"text-xs text-text-3 font-mono py-2.5 text-center",children:"No recent activity"})});function en({className:t,...a}){return e.jsx("div",{className:K("rounded-md bg-surface-4","bg-gradient-to-r from-surface-4 via-surface-5 to-surface-4","bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]",t),...a})}function vCe(){return e.jsxs("div",{className:"flex-1 grid gap-px p-0",style:{gridTemplateRows:"auto minmax(0, 1fr) minmax(0, 1fr)",gridTemplateColumns:"2fr 2.5fr 1.5fr",background:"#282c34"},children:[e.jsx("div",{className:"col-span-3",children:e.jsx(en,{className:"h-[72px] rounded-none"})}),e.jsx(en,{className:"rounded-none"}),e.jsx(en,{className:"rounded-none"}),e.jsx(en,{className:"rounded-none"}),e.jsx(en,{className:"rounded-none"}),e.jsx("div",{className:"col-span-2",children:e.jsx(en,{className:"h-full rounded-none"})})]})}function bCe(){const{data:t,loading:a,agents:s,connected:c,kpiHistory:r,lastFetch:l,agentBreakdown:u,routing:p,rotation:f,adaptive:x,journalist:g,rotating:y,teamBurn:k,memory:b}=U$e(),j=q(V=>V.teams),w=s.filter(V=>V.status==="running").length;if(!c)return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2 text-text-3 font-mono",children:[e.jsx(zs,{size:28,className:"mx-auto"}),e.jsx("p",{className:"text-xs",children:"Connecting to daemon..."})]})});if(a||!t)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(fX,{connected:c,runningCount:0,totalCount:0,uptime:0,lastFetch:0}),e.jsx(vCe,{})]});const S=t.tokens||{},M={totalTokens:S.totalTokens||0,totalCostUsd:S.totalCostUsd||0,totalInputTokens:S.totalInputTokens||0,totalOutputTokens:S.totalOutputTokens||0,cacheReadTokens:S.cacheReadTokens||0,cacheCreationTokens:S.cacheCreationTokens||0,cacheHitRate:S.cacheHitRate||0,totalTurns:S.totalTurns||0,agentCount:S.agentCount||0,savings:S.savings||{},internalOverhead:S.internalOverhead||{tokens:0,costUsd:0,components:{}}},$=M.totalOutputTokens>0?(M.totalInputTokens/M.totalOutputTokens).toFixed(1):"—",C=(f==null?void 0:f.totalRotations)||0,_=(u||[]).filter(V=>{var se;return((se=V.quality)==null?void 0:se.score)!=null}),P=_.length>0?Math.round(_.reduce((V,se)=>V+se.quality.score,0)/_.length):null,L=t.timeline||{},A=L.snapshots||[],z=L.events||t.events||[],Y=[{label:"Tokens Used",value:Fe(M.totalTokens),sparkData:r.tokens,color:ce.accent,hint:"Total tokens consumed across all agents — input, output, and cache tokens combined."},{label:"Total Cost",value:Jo(M.totalCostUsd),sparkData:r.cost,color:ce.warning,hint:"Actual cost reported by providers. Claude Code reports real billing; other providers use estimated rates."},{label:"Quality",value:P!=null?`${P}`:"—",sparkData:r.saved,color:P>=70?ce.success:P>=40?ce.warning:ce.danger,hint:"Average session quality score (0-100) across running agents. Based on error rate, repetitions, file churn, and tool success. Below 40 triggers auto-rotation."},{label:"Cache Rate",value:xn(M.cacheHitRate*100),sparkData:r.cache,color:ce.info,hint:"Percentage of input tokens served from prompt cache. Higher = faster responses and lower cost. Managed by your AI provider."},{label:"Rotations",value:`${C}`,sparkData:r.efficiency,color:ce.purple,hint:"Total context rotations — includes quality-based (auto), context threshold, natural compaction (provider-managed), and manual rotations."},{label:"I/O Ratio",value:`${$}:1`,sparkData:r.inputOutput,color:ce.orange,hint:"Ratio of input to output tokens. High ratios mean agents are reading more than writing — common for analysis tasks."},{label:"Agents",value:`${w}/${s.length}`,sparkData:r.agents,color:ce.accent,hint:"Running agents out of total spawned this session (including completed and crashed)."},{label:"Turns",value:Fe(M.totalTurns),sparkData:r.turns,color:ce.text2,hint:"Total conversation turns across all agents. Each turn is one request-response cycle with the AI provider."}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(fX,{connected:c,runningCount:w,totalCount:s.length,uptime:t.uptime||0,lastFetch:l,activeTeam:t.activeTeam}),e.jsx(G$e,{kpis:Y}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",style:{background:"#282c34",gap:"1px"},children:[e.jsxs("div",{className:"min-h-0 flex-1 grid",style:{gridTemplateColumns:"3fr 1.5fr 1.5fr",gap:"0 1px"},children:[e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 relative",children:e.jsx(eCe,{data:A})}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Cache Performance"})}),e.jsx(tCe,{cacheRead:M.cacheReadTokens,cacheCreation:M.cacheCreationTokens,totalInput:M.totalInputTokens})]}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Model Routing"})}),e.jsx(aCe,{routing:p,agentBreakdown:u})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 grid",style:{gridTemplateColumns:"2fr 2.5fr 1.5fr",gap:"0 1px"},children:[e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Agent Fleet"})}),e.jsx(J$e,{agentBreakdown:u,rotating:y,teams:j})]}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx(xCe,{tokens:M,rotation:f,adaptive:x,journalist:g,agentBreakdown:u,memory:b})}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx(mCe,{teams:k})})]})]}),e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-t border-border",children:e.jsx(kCe,{events:z})})]})}const gX={sm:12,md:16,lg:20};function wCe({fill:t="full",size:a,color:s="#fbbf24",emptyColor:c="rgba(255,255,255,0.4)"}){const r=`star-${Math.random().toString(36).slice(2,8)}`;return e.jsxs("svg",{width:a,height:a,viewBox:"0 0 20 20",fill:"none",children:[t==="half"&&e.jsx("defs",{children:e.jsxs("linearGradient",{id:r,children:[e.jsx("stop",{offset:"50%",stopColor:s}),e.jsx("stop",{offset:"50%",stopColor:c})]})}),e.jsx("path",{d:"M10 1.5l2.47 5.01 5.53.8-4 3.9.94 5.49L10 14.27 5.06 16.7 6 11.21l-4-3.9 5.53-.8L10 1.5z",fill:t==="full"?s:t==="half"?`url(#${r})`:c})]})}function rB({rating:t=0,count:a,size:s="sm"}){const c=gX[s]||gX.sm,r=[];for(let l=1;l<=5;l++)t>=l?r.push("full"):t>=l-.5?r.push("half"):r.push("empty");return e.jsxs("span",{className:"inline-flex items-center",style:{gap:1},children:[r.map((l,u)=>e.jsx(wCe,{fill:l,size:c},u)),a!=null&&e.jsxs("span",{className:"ml-1 text-[11px] text-[var(--text-dim,#6b7f95)] font-sans",children:["(",a,")"]})]})}const OX={design:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},quality:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},devtools:{color:"#33afbc",bg:"rgba(51,175,188,0.14)"},workflow:{color:"#fbbf24",bg:"rgba(251,191,36,0.12)"},security:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},specialized:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},verified:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},anthropic:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},published:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},draft:{color:"#6b7f95",bg:"rgba(255,255,255,0.06)"},review:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},rejected:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},free:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"}};function iB({label:t,variant:a,className:s}){const c=OX[a]||OX.draft;return e.jsx("span",{className:K("inline-flex items-center whitespace-nowrap font-sans select-none",s),style:{padding:"3px 8px",borderRadius:4,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",lineHeight:1.4,color:c.color,background:c.bg},children:t})}function lB({price:t=0,size:a="sm"}){const s=!t||t===0,c={sm:"text-2xs px-2 py-0.5",md:"text-xs px-2.5 py-0.5",lg:"text-xs px-3 py-1"};return e.jsx("span",{className:`inline-flex items-center font-mono font-semibold rounded whitespace-nowrap ${c[a]||c.sm} ${s?"bg-success/12 text-success":"bg-white/8 text-text-1"}`,children:s?"Free":`$${t.toFixed(2)}`})}function dB({type:t="verified",size:a=12}){const s=t==="claude-official"||t==="anthropic"?"#f59e0b":"#4ade80";return e.jsxs("svg",{width:a,height:a,viewBox:"0 0 20 20",fill:"none",className:"inline-block flex-shrink-0",children:[e.jsx("path",{d:"M10 0l2.36 3.15L16.18 2l.68 3.93L20.8 7.1l-1.87 3.52L20.8 14.14l-3.94 1.17-.68 3.93-3.82-1.15L10 21.24l-2.36-3.15-3.82 1.15-.68-3.93-3.94-1.17 1.87-3.52L-.8 7.1l3.94-1.17.68-3.93 3.82 1.15L10 0z",fill:s}),e.jsx("path",{d:"M7 10.5l2 2 4-4.5",fill:"none",stroke:"#24282f",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}const uB="groove_favorites";function NA(){try{return JSON.parse(localStorage.getItem(uB)||"[]")}catch{return[]}}function MCe(t){return NA().includes(t)}function jCe(t){const a=NA(),s=a.indexOf(t);return s>=0?a.splice(s,1):a.push(t),localStorage.setItem(uB,JSON.stringify(a)),s<0}function SCe(t){const a=new Set(NA());return t.map(s=>({...s,favorited:a.has(s.id)}))}function NCe({filled:t,size:a=16}){return e.jsx("svg",{width:a,height:a,viewBox:"0 0 24 24",fill:t?"#f87171":"none",stroke:t?"#f87171":"rgba(255,255,255,0.3)",strokeWidth:"2",children:e.jsx("path",{d:"M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"})})}function _Ce(){return e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}function $Ce({skill:t,onClick:a}){var l,u;const[s,c]=O.useState(()=>MCe(t.id));function r(p){p.stopPropagation(),c(jCe(t.id))}return e.jsxs("div",{onClick:()=>a==null?void 0:a(t),className:K("flex flex-col cursor-pointer group","bg-surface-1 border border-border-subtle rounded-md","hover:border-accent/30 hover:bg-surface-2","transition-all duration-150"),style:{padding:20,minHeight:280},children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 bg-accent/12 text-[20px]",children:t.icon||((u=(l=t.name)==null?void 0:l[0])==null?void 0:u.toUpperCase())||"?"}),e.jsx("button",{onClick:r,className:"opacity-40 group-hover:opacity-80 hover:!opacity-100 transition-opacity cursor-pointer bg-transparent border-0 p-0",children:e.jsx(NCe,{filled:s})})]}),e.jsx("div",{className:"mt-3 text-[15px] font-semibold text-text-0 font-sans line-clamp-2 leading-snug",children:t.name}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-xs text-text-3 font-sans",children:[e.jsxs("span",{children:["by ",t.author||"Community"]}),(t.source==="claude-official"||t.verified)&&e.jsx(dB,{type:t.source,size:12})]}),e.jsx("div",{className:"mt-2.5 text-xs text-text-2 font-sans line-clamp-3 flex-1 leading-relaxed",children:t.description}),e.jsx("div",{className:"mt-3",children:e.jsx(iB,{label:t.category||"general",variant:t.category||"draft"})}),e.jsx("div",{className:"h-px bg-border-subtle my-3"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(rB,{rating:t.rating||0,count:t.rating_count||t.ratingCount||0,size:"sm"}),e.jsxs("span",{className:"flex items-center gap-1 text-xs text-text-3 font-mono",children:[e.jsx(_Ce,{}),Fe(t.downloads||0)]}),e.jsx(lB,{price:t.price||0,size:"sm"})]})]})}function hB(){return e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md animate-pulse",style:{padding:20,minHeight:280},children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-surface-4"}),e.jsx("div",{className:"mt-3 h-4 w-[70%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-2 h-3 w-[40%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-3 w-full rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[90%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[60%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-5 w-[50px] rounded bg-surface-4"}),e.jsx("div",{className:"h-px bg-surface-4 my-3"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("div",{className:"h-3 w-16 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-12 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-10 rounded bg-surface-4"})]})]})}const S1={"google-workspace":"https://cdn.simpleicons.org/google/white",slack:"https://cdn.simpleicons.org/slack/E01E5A",discord:"https://cdn.simpleicons.org/discord/5865F2",github:"https://cdn.simpleicons.org/github/white",stripe:"https://cdn.simpleicons.org/stripe/635BFF",gmail:"https://cdn.simpleicons.org/gmail/EA4335","google-calendar":"https://cdn.simpleicons.org/googlecalendar/4285F4","google-drive":"https://cdn.simpleicons.org/googledrive/4285F4","google-docs":"https://cdn.simpleicons.org/googledocs/4285F4","google-sheets":"https://cdn.simpleicons.org/googlesheets/34A853","google-slides":"https://cdn.simpleicons.org/googleslides/FBBC04","google-maps":"https://cdn.simpleicons.org/googlemaps/4285F4",postgres:"https://cdn.simpleicons.org/postgresql/4169E1",notion:"https://cdn.simpleicons.org/notion/white",linear:"https://cdn.simpleicons.org/linear/5E6AD2","brave-search":"https://cdn.simpleicons.org/brave/FB542B","home-assistant":"https://cdn.simpleicons.org/homeassistant/18BCF2",sentry:"https://cdn.simpleicons.org/sentry/362D59",elevenlabs:"https://cdn.simpleicons.org/elevenlabs/white",hubspot:"https://cdn.simpleicons.org/hubspot/FF7A59",jira:"https://cdn.simpleicons.org/jira/0052CC",sendgrid:"https://cdn.simpleicons.org/sendgrid/1A82E2",resend:"https://cdn.simpleicons.org/resend/white",replicate:"https://cdn.simpleicons.org/replicate/white",vercel:"https://cdn.simpleicons.org/vercel/white",supabase:"https://cdn.simpleicons.org/supabase/3FCF8E",mixpanel:"https://cdn.simpleicons.org/mixpanel/7856FF",datadog:"https://cdn.simpleicons.org/datadog/632CA6",airtable:"https://cdn.simpleicons.org/airtable/18BFFF",zendesk:"https://cdn.simpleicons.org/zendesk/03363D",intercom:"https://cdn.simpleicons.org/intercom/6AFDEF",twilio:"https://cdn.simpleicons.org/twilio/F22F46",telnyx:"https://cdn.simpleicons.org/telnyx/00C08B",aws:"https://cdn.simpleicons.org/amazonaws/FF9900",plaid:"https://cdn.simpleicons.org/plaid/white"};function CCe({item:t,size:a=40}){const s=S1[t.id];if(s)return e.jsxs("div",{className:"rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:a,height:a},children:[e.jsx("img",{src:s,alt:t.name,className:"w-5 h-5",onError:l=>{l.target.style.display="none",l.target.nextSibling.style.display="flex"}}),e.jsx("div",{className:"hidden items-center justify-center w-full h-full text-lg font-bold font-sans text-text-1",children:(t.name||"?")[0]})]});const c=(t.name||"?")[0].toUpperCase(),r=t.name?t.name.charCodeAt(0)*37%360:200;return e.jsx("div",{className:"rounded-md flex items-center justify-center flex-shrink-0 text-lg font-bold font-sans",style:{width:a,height:a,background:`hsl(${r}, 40%, 18%)`,color:`hsl(${r}, 60%, 65%)`},children:c})}function jQ({item:t,onClick:a,className:s,statusBadge:c}){var l;const r=t.installed;return e.jsxs("button",{onClick:()=>a(t),className:K("flex flex-col p-5 rounded-md border border-border-subtle bg-surface-1 text-left","hover:border-accent/30 hover:bg-surface-2","transition-all duration-150 cursor-pointer group",s),style:{minHeight:200},children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(CCe,{item:t,size:36}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-0 font-sans truncate",children:t.name}),(t.verified||t.verified==="mcp-official")&&e.jsx(ca,{size:11,className:"text-accent flex-shrink-0"})]}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.author||"Community"})]})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans line-clamp-3 mb-3 flex-1 leading-relaxed",children:t.description}),e.jsx("div",{className:"h-px bg-border-subtle my-2"}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Oa,{size:10}),Fe(t.downloads||0)]}),(t.rating||0)>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(b1,{size:10,className:"text-warning",fill:"currentColor"}),(l=t.rating)==null?void 0:l.toFixed(1)]}),e.jsx("span",{className:"flex-1"}),c||r&&e.jsx(ge,{variant:"accent",className:"text-2xs",children:t._installedCount?`${t._installedCount} active`:"Installed"})]})]})}function _A({value:t,onChange:a,placeholder:s="Search skills, tags, authors...",large:c}){const[r,l]=O.useState(t||""),u=O.useRef(null);O.useEffect(()=>{l(t||"")},[t]);function p(f){const x=f.target.value;l(x),clearTimeout(u.current),u.current=setTimeout(()=>a(x),300)}return e.jsxs("div",{className:"relative w-full",children:[e.jsx(Zt,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{value:r,onChange:p,placeholder:s,className:K("w-full font-sans outline-none","bg-surface-0 border border-border text-text-0 placeholder:text-text-4","focus:border-accent/40 transition-colors",c?"py-3 pl-11 pr-12 text-[15px] rounded-lg":"py-2.5 pl-10 pr-3 text-sm rounded-md")}),c&&e.jsx("kbd",{className:"absolute right-3.5 top-1/2 -translate-y-1/2 bg-surface-4 text-text-4 px-2 py-0.5 rounded text-xs font-mono",children:"/"})]})}const QCe=[{id:"",label:"All"},{id:"design",label:"Design"},{id:"quality",label:"Quality"},{id:"devtools",label:"Dev Tools"},{id:"workflow",label:"Workflow"},{id:"security",label:"Security"},{id:"specialized",label:"Specialized"}];function LCe({selected:t="",categories:a=QCe,onSelect:s}){return e.jsx("div",{className:"flex gap-2 overflow-x-auto",style:{scrollbarWidth:"none"},children:a.map(c=>{const r=t===c.id;return e.jsx("button",{onClick:()=>s(c.id),className:K("whitespace-nowrap font-sans cursor-pointer select-none transition-all text-[13px] rounded-full border",r?"bg-accent text-surface-0 border-accent font-semibold":"bg-surface-1 text-text-3 border-border-subtle hover:text-text-1 hover:border-border font-medium"),style:{padding:"7px 16px"},children:c.label},c.id)})})}function va(){const t=q(a=>a.addToast);return{success:(a,s)=>t("success",a,s),error:(a,s)=>t("error",a,s),info:(a,s)=>t("info",a,s),warning:(a,s)=>t("warning",a,s)}}const ns=O.forwardRef(({className:t,label:a,error:s,mono:c,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[a&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:a}),e.jsx("input",{ref:l,className:K("h-8 w-full rounded-md px-3 text-sm","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",c?"font-mono":"font-sans",s&&"border-danger focus:ring-danger",t),...r}),s&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:s})]}));ns.displayName="Input";const zCe=O.forwardRef(({className:t,label:a,error:s,mono:c,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[a&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:a}),e.jsx("textarea",{ref:l,className:K("w-full rounded-md px-3 py-2 text-sm resize-none","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",c?"font-mono":"font-sans",s&&"border-danger focus:ring-danger",t),...r}),s&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:s})]}));zCe.displayName="Textarea";function $A({item:t,size:a=48}){const s=S1[t.id];if(s)return e.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:a,height:a},children:e.jsx("img",{src:s,alt:t.name,className:"w-6 h-6",onError:l=>{l.target.style.display="none"}})});const c=(t.name||"?")[0].toUpperCase(),r=t.name?t.name.charCodeAt(0)*37%360:200;return e.jsx("div",{className:"rounded-lg flex items-center justify-center flex-shrink-0 text-xl font-bold font-sans",style:{width:a,height:a,background:`hsl(${r}, 40%, 18%)`,color:`hsl(${r}, 60%, 65%)`},children:c})}function MP({value:t,onChange:a,placeholder:s,disabled:c}){const[r,l]=O.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsx(ns,{type:r?"text":"password",value:t,onChange:u=>a(u.target.value),placeholder:s,disabled:c,mono:!0,className:"pr-9"}),e.jsx("button",{type:"button",onClick:()=>l(u=>!u),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded text-text-4 hover:text-text-1 transition-colors cursor-pointer",tabIndex:-1,children:r?e.jsx(Jn,{size:14}):e.jsx(ka,{size:14})})]})}function TCe({integrationId:t,envKey:a,onSaved:s}){const c=va(),[r,l]=O.useState(""),[u,p]=O.useState(!1),[f,x]=O.useState(a.set),[g,y]=O.useState(!1);async function k(){if(r.trim()){p(!0);try{await X.post(`/integrations/${t}/credentials`,{key:a.key,value:r.trim()}),x(!0),l(""),c.success(`${a.label} saved`),s==null||s()}catch(j){c.error("Failed to save",j.message)}p(!1)}}async function b(){y(!0);try{await X.delete(`/integrations/${t}/credentials/${a.key}`),x(!1),c.success(`${a.label} removed`),s==null||s()}catch(j){c.error("Failed to remove",j.message)}y(!1)}return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(jn,{size:11,className:"text-text-4"}),a.label,a.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),f&&e.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[e.jsx(Ve,{size:10})," Set"]})]}),f?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:e.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),e.jsx(he,{variant:"ghost",size:"sm",onClick:b,disabled:g,className:"text-text-3 hover:text-danger",children:g?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(wt,{size:12})})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx(MP,{value:r,onChange:l,placeholder:a.placeholder||`Enter ${a.label.toLowerCase()}...`,disabled:u})}),e.jsx(he,{variant:"primary",size:"sm",onClick:k,disabled:u||!r.trim(),children:u?e.jsx(ze,{size:12,className:"animate-spin"}):"Save"})]})]})}function PCe({item:t,status:a,installing:s,onInstall:c,onUninstall:r,onNext:l}){var p;const u=a==null?void 0:a.installed;return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx($A,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:t.name}),(t.verified==="mcp-official"||t.verified==="verified")&&e.jsxs(ge,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(nn,{size:9})," Verified"]})]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:t.author||"Community"}),t.category&&e.jsx(ge,{variant:"default",className:"text-2xs mt-2",children:t.category})]})]}),e.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((p=t.tags)==null?void 0:p.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map(f=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:f},f))}),e.jsx("div",{className:"h-px bg-border-subtle"}),u?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsx(ca,{size:16,className:"text-success"}),e.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),e.jsxs(he,{variant:"ghost",size:"sm",onClick:r,className:"text-text-3 hover:text-danger gap-1.5",children:[e.jsx(wt,{size:12})," Uninstall"]}),e.jsxs(he,{variant:"primary",size:"sm",onClick:l,className:"gap-1",children:["Configure ",e.jsx(Xt,{size:12})]})]}):e.jsx(he,{variant:"primary",size:"lg",onClick:c,disabled:s,className:"w-full gap-2",children:s?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),s&&e.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}const ACe={gmail:"Gmail API","google-calendar":"Google Calendar API","google-drive":"Google Drive API","google-docs":"Google Docs API","google-sheets":"Google Sheets API","google-slides":"Google Slides API"};function pB({integrationId:t,onConfigured:a}){const s=va(),[c,r]=O.useState(""),[l,u]=O.useState(""),[p,f]=O.useState(!1),x=ACe[t]||"the relevant Google API";async function g(){if(!(!c.trim()||!l.trim())){f(!0);try{await X.post("/integrations/google-oauth/setup",{clientId:c.trim(),clientSecret:l.trim()}),s.success("Google OAuth credentials saved"),a()}catch(k){s.error("Failed to save",k.message)}f(!1)}}const y=[{text:"Go to the Google Cloud Console and sign in with your Google account",link:{url:"https://console.cloud.google.com",label:"Open Google Cloud Console"}},{text:"Create a new project (or select an existing one). Any name is fine — this is just a container for your credentials."},{text:e.jsxs(e.Fragment,{children:["Enable the ",e.jsx("strong",{children:x})," — search for it in the API Library and click ",e.jsx("strong",{children:"Enable"})]}),link:{url:"https://console.cloud.google.com/apis/library",label:"Open API Library"}},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Credentials"})," and click ",e.jsx("strong",{children:"Create Credentials"})," → ",e.jsx("strong",{children:"OAuth client ID"})]}),link:{url:"https://console.cloud.google.com/apis/credentials",label:"Open Credentials page"}},{text:e.jsxs(e.Fragment,{children:["If prompted to configure the consent screen, choose ",e.jsx("strong",{children:"External"}),', fill in an app name (e.g. "Groove"), your email, and save. You can skip optional fields.']})},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Audience"})," and click ",e.jsx("strong",{children:"Publish App"}),". Then scroll down to ",e.jsx("strong",{children:"Test users"}),", click ",e.jsx("strong",{children:"Add Users"}),", enter your Google email address, and save."]})},{text:e.jsxs(e.Fragment,{children:["For Application type, choose ",e.jsx("strong",{children:"Desktop app"})," (not Web application). Give it any name."]})},{text:e.jsxs(e.Fragment,{children:["Click ",e.jsx("strong",{children:"Create"}),", then copy the ",e.jsx("strong",{children:"Client ID"})," and ",e.jsx("strong",{children:"Client Secret"})," and paste them below."]})}];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-3",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"How to get your Google credentials"}),e.jsx("ol",{className:"space-y-2.5",children:y.map((k,b)=>e.jsxs("li",{className:"flex gap-2.5 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono font-bold flex-shrink-0 w-4 text-right",children:[b+1,"."]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{children:k.text}),k.link&&e.jsxs("a",{href:k.link.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-2xs text-accent font-sans hover:underline mt-0.5",children:[e.jsx(Pt,{size:9}),k.link.label]}),k.copyable&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("code",{className:"flex-1 min-w-0 text-2xs font-mono text-accent bg-surface-4 px-2.5 py-1.5 rounded select-all break-all",children:k.copyable}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(k.copyable)},className:"flex-shrink-0 p-1.5 rounded text-text-3 hover:text-accent hover:bg-accent/10 transition-colors cursor-pointer",title:"Copy to clipboard",children:e.jsx(Mn,{size:12})})]})]})]},b))})]}),e.jsx("div",{className:"bg-accent/8 border border-accent/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsx("strong",{className:"text-text-1",children:"One-time setup"})," — these same credentials work for Gmail, Calendar, Drive, Docs, Sheets, and Slides. You only need to do this once. For each integration, just enable the matching API in your Google Cloud project."]})}),e.jsx("div",{className:"bg-warning/8 border border-warning/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsx("strong",{className:"text-text-1",children:'Google "unverified app" warning'})," — when signing in, Google may show a warning that the app isn't verified. This is normal for personal OAuth apps. Click ",e.jsx("strong",{children:"Advanced"}),", then ",e.jsx("strong",{children:"Go to [your app name] (unsafe)"})," to continue. Your credentials stay local and are never sent to Groove servers."]})}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(jn,{size:11,className:"text-text-4"}),"Client ID ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(MP,{value:c,onChange:r,placeholder:"123456789.apps.googleusercontent.com",disabled:p})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(jn,{size:11,className:"text-text-4"}),"Client Secret ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(MP,{value:l,onChange:u,placeholder:"GOCSPX-...",disabled:p})]})]}),e.jsx(he,{variant:"primary",size:"lg",onClick:g,disabled:p||!c.trim()||!l.trim(),className:"w-full gap-2",children:p?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"})," Saving..."]}):"Save Credentials"})]})}function qCe({item:t,status:a,onDone:s,onRefreshStatus:c}){var S;const r=va(),[l,u]=O.useState(!1),[p,f]=O.useState(null),x=t.authType,g=x==="google-autoauth"||x==="oauth-google";O.useEffect(()=>{g&&X.get("/integrations/google-oauth/status").then(M=>f(M.configured)).catch(()=>f(!1))},[g]);const y=O.useRef(null);O.useEffect(()=>()=>{y.current&&clearInterval(y.current)},[]);async function k(){u(!0);try{const M=await X.post(`/integrations/${t.id}/oauth/start`);if(M.url){const $=await RX(M.url);if($!=null&&$.error){r.error("Sign-in failed",$.error),u(!1);return}r.success("Browser opened — complete sign-in there");let C=0;y.current&&clearInterval(y.current),y.current=setInterval(async()=>{if(C+=2e3,C>6e4){clearInterval(y.current),y.current=null,u(!1);return}try{const _=await X.get(`/integrations/${t.id}/status`);((_==null?void 0:_.envKeys)||[]).some(A=>A.key==="GOOGLE_REFRESH_TOKEN"&&A.set)&&(clearInterval(y.current),y.current=null,r.success("Connected!",`${t.name} is now authenticated`),c(),u(!1))}catch{}},2e3)}}catch(M){r.error("Sign-in failed",M.message),u(!1)}}const b=(a==null?void 0:a.envKeys)||[],j=b.filter(M=>M.required&&!M.hidden),w=j.length===0||j.every(M=>M.set);return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx($A,{item:t,size:36}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",t.name]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((S=t.setupSteps)==null?void 0:S.length)>0&&!(g&&p===!1)&&e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),e.jsx("ol",{className:"space-y-1.5",children:t.setupSteps.map((M,$)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[$+1,"."]}),e.jsx("span",{children:M})]},$))}),t.setupUrl&&e.jsxs("a",{href:t.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[e.jsx(Pt,{size:11}),new URL(t.setupUrl).hostname]})]}),!(g&&p===!1)&&e.jsx("div",{className:"h-px bg-border-subtle"}),x==="api-key"&&e.jsx("div",{className:"space-y-4",children:b.filter(M=>!M.hidden).map(M=>e.jsx(TCe,{integrationId:t.id,envKey:M,onSaved:c},M.key))}),g&&p===!1&&e.jsx(pB,{integrationId:t.id,onConfigured:()=>f(!0)}),g&&p&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{variant:"primary",size:"lg",onClick:k,disabled:l,className:"w-full gap-2",children:l?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"}),"Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["A browser window will open — sign in and allow access to your ",t.name]}),e.jsx("button",{type:"button",onClick:()=>f(!1),className:"w-full text-2xs text-text-4 font-sans hover:text-text-2 transition-colors cursor-pointer py-1",children:"Reconfigure Google OAuth credentials"})]}),g&&p===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(ze,{size:16,className:"animate-spin text-text-4"})}),e.jsx(he,{variant:w?"primary":"secondary",size:"lg",onClick:s,className:"w-full gap-1.5",children:w?e.jsxs(e.Fragment,{children:[e.jsx(Ve,{size:14}),"Done"]}):"Skip for now"})]})}function ICe({item:t,onClose:a}){return e.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(ca,{size:28,className:"text-success"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),e.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[t.name," is installed and configured. Agents can now use it."]})]}),e.jsx(he,{variant:"primary",size:"lg",onClick:a,className:"mt-2",children:"Close"})]})}function fB({integration:t,open:a,onClose:s}){const c=va(),[r,l]=O.useState("overview"),[u,p]=O.useState(null),[f,x]=O.useState(!1),[g,y]=O.useState(!0),k=t==null?void 0:t.id,b=O.useCallback(async()=>{if(k){try{const $=await X.get(`/integrations/${k}/status`);p($)}catch{p(null)}y(!1)}},[k]);O.useEffect(()=>{a&&t&&(l("overview"),y(!0),b())},[a,t,b]);async function j(){x(!0);try{await X.post(`/integrations/${t.id}/install`),c.success(`${t.name} installed`),await b(),l("configure")}catch($){c.error("Install failed",$.message)}x(!1)}async function w(){try{await X.delete(`/integrations/${t.id}`),c.success(`${t.name} uninstalled`),await b()}catch($){c.error("Uninstall failed",$.message)}}function S(){l("configure")}function M(){l("done")}return t?e.jsx(qa,{open:a,onOpenChange:$=>{$||s()},children:e.jsx(Ia,{title:r==="overview"?t.name:r==="configure"?"Configure":"Complete",description:`Setup wizard for ${t.name}`,className:"max-w-md",children:g?e.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:e.jsx(ze,{size:20,className:"animate-spin text-text-4"})}):r==="overview"?e.jsx(PCe,{item:t,status:u,installing:f,onInstall:j,onUninstall:w,onNext:S}):r==="configure"?e.jsx(qCe,{item:t,status:u,onDone:M,onRefreshStatus:b}):e.jsx(ICe,{item:t,onClose:s})})}):null}const RCe=["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"];function VCe({item:t,status:a,onInstall:s,onUninstall:c,busy:r}){const l=a==null?void 0:a.installed,u=a==null?void 0:a.authenticated;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-2 border border-border-subtle",children:[e.jsx($A,{item:t,size:32}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:t.description})]}),l&&u&&!(a!=null&&a.needsReauth)&&e.jsxs(ge,{variant:"success",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Ve,{size:8})," Ready"]}),l&&u&&(a==null?void 0:a.needsReauth)&&e.jsxs(ge,{variant:"warning",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(ia,{size:8})," Update"]}),l&&!u&&e.jsx(ge,{variant:"warning",className:"text-2xs flex-shrink-0",children:"Needs sign-in"}),e.jsx(he,{variant:l?"ghost":"primary",size:"sm",onClick:()=>l?c(t.id):s(t.id),disabled:r===t.id,className:l?"text-text-3 hover:text-danger":"",children:r===t.id?e.jsx(ze,{size:12,className:"animate-spin"}):l?e.jsx(wt,{size:12}):"Install"})]})}function ECe({integrations:t,open:a,onClose:s}){const c=va(),[r,l]=O.useState(null),[u,p]=O.useState({}),[f,x]=O.useState(null),[g,y]=O.useState(!1),[k,b]=O.useState(!0),j=O.useRef(null),w=t.filter(A=>RCe.includes(A.id)),S=O.useCallback(async()=>{const A={};await Promise.all(w.map(async z=>{try{A[z.id]=await X.get(`/integrations/${z.id}/status`)}catch{A[z.id]=null}})),p(A),b(!1)},[w.map(A=>A.id).join(",")]);O.useEffect(()=>(a&&(b(!0),X.get("/integrations/google-oauth/status").then(A=>l(A.configured)).catch(()=>l(!1)),S()),()=>{j.current&&clearInterval(j.current)}),[a]);const M=Object.entries(u).filter(([,A])=>A==null?void 0:A.installed).map(([A])=>A),$=M.length>0&&M.every(A=>{var z;return(z=u[A])==null?void 0:z.authenticated});M.some(A=>{var z;return!((z=u[A])!=null&&z.authenticated)});const C=$&&M.some(A=>{var z;return(z=u[A])==null?void 0:z.needsReauth});async function _(A){var z;x(A);try{await X.post(`/integrations/${A}/install`),c.success(`${(z=w.find(Y=>Y.id===A))==null?void 0:z.name} installed`),await S()}catch(Y){c.error("Install failed",Y.message)}x(null)}async function P(A){var z;x(A);try{await X.delete(`/integrations/${A}`),c.success(`${(z=w.find(Y=>Y.id===A))==null?void 0:z.name} removed`),await S()}catch(Y){c.error("Uninstall failed",Y.message)}x(null)}async function L(){if(!M.length){c.error("Install at least one service first");return}y(!0);try{const A=await X.post("/integrations/google-workspace/oauth/start",{integrationIds:M});if(A.url){const z=await RX(A.url);if(z!=null&&z.error){c.error("Sign-in failed",z.error),y(!1);return}c.success("Browser opened — complete sign-in there"),j.current&&clearInterval(j.current),j.current=setInterval(async()=>{await S()},3e3),setTimeout(()=>{j.current&&clearInterval(j.current)},18e4)}}catch(A){c.error("Sign-in failed",A.message)}y(!1)}return O.useEffect(()=>{$&&j.current&&(clearInterval(j.current),j.current=null)},[$]),a?e.jsx(qa,{open:a,onOpenChange:A=>{A||s()},children:e.jsx(Ia,{title:"Google Workspace",description:"Connect your Google services",className:"max-w-md",children:e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"Google",className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Google Workspace"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"One set of credentials for all Google services"})]})]}),r===!1&&e.jsx(pB,{integrationId:"gmail",onConfigured:()=>l(!0)}),r===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(ze,{size:16,className:"animate-spin text-text-4"})}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans",children:"Services"}),e.jsx("div",{className:"space-y-1.5",children:k?Array.from({length:4}).map((A,z)=>e.jsx("div",{className:"h-14 rounded-md bg-surface-2 animate-pulse"},z)):w.map(A=>e.jsx(VCe,{item:A,status:u[A.id],onInstall:_,onUninstall:P,busy:f},A.id))})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),M.length>0&&!$&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{variant:"primary",size:"lg",onClick:L,disabled:g,className:"w-full gap-2",children:g?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Connects ",M.length," service",M.length!==1?"s":""," with one sign-in"]})]}),$&&M.length>0&&e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(ca,{size:20,className:"text-success"})}),e.jsx("p",{className:"text-sm font-medium text-success font-sans",children:"All services connected"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Your agents can now use these Google integrations."}),C?e.jsxs("div",{className:"w-full space-y-2 pt-2",children:[e.jsx("p",{className:"text-2xs text-warning font-sans",children:"New permissions available — re-authenticate to enable all features."}),e.jsx(he,{variant:"secondary",size:"sm",onClick:L,disabled:g,className:"w-full gap-2",children:g?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:12,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ia,{size:12})," Re-authenticate"]})})]}):e.jsx("button",{onClick:L,disabled:g,className:"text-2xs text-text-4 hover:text-text-2 font-sans underline underline-offset-2 transition-colors mt-1",children:g?"Opening browser...":"Re-authenticate"})]}),M.length===0&&!k&&e.jsx("p",{className:"text-xs text-text-4 font-sans text-center py-2",children:"Install at least one service above, then connect with Google."})]}),e.jsx(he,{variant:"secondary",size:"lg",onClick:s,className:"w-full",children:$&&M.length>0?"Done":"Close"})]})})}):null}const JT=/github\.com\/([^/]+)\/([^/\s#?]+)/;function XCe(){const[t,a]=O.useState("input"),[s,c]=O.useState(""),[r,l]=O.useState(!1),[u,p]=O.useState(null),[f,x]=O.useState("standalone"),[g,y]=O.useState(""),[k,b]=O.useState(!0),[j,w]=O.useState(""),S=q(A=>A.previewRepo),M=q(A=>A.importRepo),$=q(A=>A.importInProgress),C=va(),_=O.useCallback(async A=>{const z=A.match(JT);if(z){l(!0);try{const Y=await S(A);p(Y),w(Y.name||z[2]),a("preview")}catch(Y){C.error("Preview failed",Y.message)}finally{l(!1)}}},[S,C]),P=O.useCallback(A=>{const z=A.target.value;c(z),JT.test(z)&&t==="input"&&_(z)},[t,_]),L=O.useCallback(async()=>{if(!u)return;let A;f==="standalone"?A=`~/Projects/${u.name}`:f==="subdirectory"?A=`./packages/${u.name}`:A=g;try{await M(s,A,k,j),C.success(`Importing ${u.name}`,"Setup agent will handle the rest"),a("input"),c(""),p(null)}catch(z){C.error("Import failed",z.message)}},[u,f,g,s,k,j,M,C]);if(t==="input")return e.jsxs("div",{className:"relative",children:[e.jsx(Zt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{type:"text",value:s,onChange:P,placeholder:"Paste a GitHub URL...",className:K("w-full h-9 rounded-lg pl-9 pr-20 text-sm font-sans","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors duration-100")}),e.jsx(he,{variant:"primary",size:"sm",className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:()=>_(s),disabled:!JT.test(s)||r,children:r?e.jsx(ze,{size:12,className:"animate-spin"}):"Preview"})]});if(t==="preview"&&u)return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(es,{size:22,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx("span",{className:"text-lg font-bold text-text-0 font-sans",children:u.name}),e.jsx("span",{className:"text-xs text-text-4 font-sans",children:u.owner})]}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[u.language&&e.jsx(ge,{variant:"outline",className:"text-2xs",children:u.language}),u.stars!=null&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(b1,{size:10,className:"text-warning",fill:"currentColor"}),Fe(u.stars)]}),u.license&&e.jsx("span",{children:u.license})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>a("configure"),className:"h-8 text-xs gap-1.5 px-4",children:[e.jsx(ta,{size:13}),"Clone & Setup"]}),e.jsxs(he,{variant:"ghost",size:"sm",onClick:()=>{try{const A=s.startsWith("http")?s:`https://${s}`,z=new URL(A);(z.protocol==="https:"||z.protocol==="http:")&&window.open(A,"_blank")}catch{}},className:"h-8 text-xs gap-1.5",children:[e.jsx(Pt,{size:12}),"GitHub"]}),e.jsx("button",{onClick:()=>{a("input"),p(null)},className:"text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 ml-1",children:"Cancel"})]})]})}),u.description&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2",children:"About"}),e.jsx("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:u.description})]}),u.readmePreview&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-3",children:"README"}),e.jsx("div",{className:"text-sm text-text-2 font-sans leading-relaxed whitespace-pre-wrap",children:u.readmePreview})]})]});if(t==="configure"&&u){const A=[{id:"standalone",icon:Xo,title:"Standalone project",description:"Clone to its own directory, separate from this workspace",path:`~/Projects/${u.name}`},{id:"subdirectory",icon:Zd,title:"Workspace package",description:"Add as a package inside this project's monorepo",path:`./packages/${u.name}`},{id:"custom",icon:zo,title:"Custom location",description:"Choose your own path",path:null}];return e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-border-subtle bg-surface-3/50",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(Oa,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:["Clone ",u.name]}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:[u.owner,"/",u.name," — configure where to install"]})]})]})}),e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2.5 block",children:"Install location"}),e.jsx("div",{className:"space-y-2",children:A.map(z=>{const Y=z.icon,V=f===z.id;return e.jsx("button",{onClick:()=>x(z.id),className:K("w-full text-left rounded-lg border p-3.5 transition-all duration-150 cursor-pointer",V?"border-accent bg-accent/5 ring-1 ring-accent/30":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-1/80"),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:K("w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0 mt-0.5",V?"bg-accent/15 text-accent":"bg-surface-3 text-text-4"),children:e.jsx(Y,{size:15})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:K("text-xs font-semibold font-sans",V?"text-text-0":"text-text-2"),children:z.title}),V&&e.jsx("div",{className:"w-4 h-4 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Ve,{size:10,className:"text-white"})})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5 leading-relaxed",children:z.description}),z.path&&V&&e.jsx("code",{className:"text-2xs text-accent/80 font-mono mt-1.5 block truncate",children:z.path})]})]})},z.id)})}),f==="custom"&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:g,onChange:z=>y(z.target.value),placeholder:"/path/to/clone",autoFocus:!0,className:K("w-full h-9 px-3 text-xs font-mono rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-3 flex items-center justify-center",children:e.jsx(sn,{size:14,className:"text-text-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans block",children:"Create a team"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Organize agents working on this repo into their own team"})]})]}),e.jsx("button",{onClick:()=>b(!k),className:K("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer flex-shrink-0",k?"bg-accent":"bg-surface-5"),children:e.jsx("div",{className:K("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",k?"translate-x-4":"translate-x-0")})})]}),k&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:j,onChange:z=>w(z.target.value),placeholder:"Team name",className:K("w-full h-9 px-3 text-xs font-sans rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle bg-surface-3/30 flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>a("preview"),className:"flex items-center gap-1.5 text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 transition-colors",children:[e.jsx(Qd,{size:11}),"Back"]}),e.jsx(he,{variant:"primary",size:"sm",onClick:L,disabled:$||f==="custom"&&!g.trim(),className:"h-8 text-xs gap-1.5 px-5",children:$?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:12,className:"animate-spin"})," Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Oa,{size:12})," Clone & Setup"]})})]})]})}return null}function ZCe({repo:t,onRemove:a,onNuke:s,onOpen:c}){return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:t.repoName||t.name}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.repoOwner||t.owner})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.language&&e.jsx(ge,{variant:"outline",className:"text-2xs",children:t.language}),e.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-[180px]",children:t.clonedTo||t.path})]}),e.jsx("span",{className:"text-2xs text-text-4 font-sans mt-0.5 block",children:t.clonedAt?`Imported ${gt(t.clonedAt)}`:t.status||""})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[c&&e.jsxs("button",{onClick:()=>c(t),className:K("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-accent bg-accent/10 hover:bg-accent/20 border-0 transition-colors"),children:[e.jsx(ta,{size:11}),"Open"]}),a&&e.jsxs("button",{onClick:()=>a(t),className:K("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-text-3 hover:text-text-1 hover:bg-surface-4 bg-transparent border-0 transition-colors"),children:[e.jsx(wt,{size:11}),"Remove"]}),s&&e.jsxs("button",{onClick:()=>s(t),className:K("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-danger bg-danger/10 hover:bg-danger/20 border-0 transition-colors"),children:[e.jsx(h2,{size:11}),"Nuke"]})]})]})}function DCe({repo:t,open:a,onClose:s,onConfirm:c}){var g,y,k;const[r,l]=O.useState(!0);if(!t)return null;const u=((g=t.agents)==null?void 0:g.length)||0,p=((y=t.processes)==null?void 0:y.length)||0,f=((k=t.credentialKeys)==null?void 0:k.length)||0,x=t.fileCount||0;return e.jsx(qa,{open:a,onOpenChange:b=>{b||s()},children:e.jsx(Ia,{title:`Nuke ${t.repoName||t.name}?`,description:"Confirm destructive removal of imported repo",children:e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Et,{size:16,className:"text-danger flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-text-1 font-sans",children:"This cannot be undone."})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-text-2 font-sans",children:[u>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Kill ",u," agent",u!==1?"s":""]}),p>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Stop ",p," process",p!==1?"es":""]}),f>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Remove ",f," credential",f!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"}),' Delete team "',t.teamId||t.repoName||t.name,'"']}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Clean all .groove state"]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:b=>l(b.target.checked),className:"accent-[var(--color-danger)]"}),e.jsxs("span",{className:"text-xs text-text-1 font-sans",children:["Delete repo files",x>0?` (${x} files)`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(he,{variant:"danger",size:"sm",onClick:()=>c(r),children:"Nuke Everything"}),e.jsx(he,{variant:"ghost",size:"sm",onClick:s,children:"Cancel"})]})]})})})}function xB({skill:t,onBack:a}){var P,L,A;const s=va(),[c,r]=O.useState(""),[l,u]=O.useState(!1),[p,f]=O.useState(!1),[x,g]=O.useState(!1),[y,k]=O.useState(!1),[b,j]=O.useState(t.installed),[w,S]=O.useState(!0);O.useEffect(()=>{S(!0),X.get(`/skills/${t.id}/content`).then(z=>{r(z.content||""),u(z.requiresPurchase||!1)}).catch(()=>{}).finally(()=>S(!1))},[t.id]);async function M(){f(!0);try{await X.post(`/skills/${t.id}/install`),j(!0),s.success(`${t.name} installed`)}catch(z){s.error("Install failed",z.message)}f(!1)}async function $(){g(!0);try{await X.post(`/skills/${t.id}/update`),s.success(`${t.name} updated to latest`);const z=await X.get(`/skills/${t.id}/content`);z.content&&r(z.content)}catch(z){s.error("Update failed",z.message)}g(!1)}async function C(){k(!0);try{await X.delete(`/skills/${t.id}`),j(!1),s.success(`${t.name} uninstalled`)}catch(z){s.error("Uninstall failed",z.message)}k(!1)}async function _(){const{marketplaceAuthenticated:z,marketplaceLogin:Y,marketplaceCheckout:V}=q.getState();if(!z){Y();return}try{await V(t.id)}catch{}}return e.jsx(It,{className:"h-full",children:e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("button",{onClick:a,className:"flex items-center gap-1 text-xs text-text-3 font-sans hover:text-text-0 cursor-pointer bg-transparent border-0 mb-4",children:[e.jsx(Vs,{size:14})," Back"]}),e.jsxs("div",{className:"flex gap-8",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-[22px]",children:t.icon||((L=(P=t.name)==null?void 0:P[0])==null?void 0:L.toUpperCase())}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[e.jsx("span",{children:t.author||"Community"}),(t.source==="claude-official"||t.verified)&&e.jsx(dB,{type:t.source,size:13})]})]})]}),e.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((A=t.tags)==null?void 0:A.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:t.tags.map(z=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:z},z))}),e.jsx("div",{className:"h-px bg-border-subtle my-5"}),w?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):c?e.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:c})]}):l?e.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[e.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):e.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),e.jsx("div",{className:"w-[240px] flex-shrink-0",children:e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[e.jsx(lB,{price:t.price||0,size:"md"}),l&&!b?e.jsxs("button",{onClick:_,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 flex items-center justify-center gap-2 border bg-warning/15 text-warning border-warning/20 hover:bg-warning/25",children:["Buy $",(t.price||0).toFixed(2)]}):b?e.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[e.jsxs("button",{onClick:$,disabled:x,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:[e.jsx(ia,{size:12,className:x?"animate-spin":""}),x?"Updating...":"Pull Latest"]}),e.jsxs("button",{onClick:C,disabled:y,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-error/10 text-error border-error/20 hover:bg-error/15",children:[e.jsx(wt,{size:12}),y?"Removing...":"Uninstall"]})]}):e.jsx("button",{onClick:M,disabled:p,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:p?"Installing...":"Install"}),e.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",e.jsx("span",{className:"font-mono text-text-0",children:Fe(t.downloads||0)},"d")],["Rating",e.jsx(rB,{rating:t.rating||0,count:t.rating_count||t.ratingCount,size:"sm"},"r")],["Version",e.jsx("span",{className:"font-mono text-text-0",children:t.version||"1.0.0"},"v")],["Category",e.jsx(iB,{label:t.category||"general",variant:t.category||"draft"},"c")],["Source",e.jsx("span",{className:"text-text-0",children:t.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([z,Y])=>e.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:z}),Y]},z))})]})})]})]})})}function UCe(){const[t,a]=O.useState([]),[s,c]=O.useState(!0),[r,l]=O.useState(""),[u,p]=O.useState(""),[f,x]=O.useState("popular"),[g,y]=O.useState(null);return O.useEffect(()=>{c(!0);const k=new URLSearchParams;r&&k.set("search",r),u&&k.set("category",u),f&&k.set("sort",f),X.get(`/skills/registry?${k}`).then(b=>a(SCe(b.skills||b.items||(Array.isArray(b)?b:[])))).catch(()=>a([])).finally(()=>c(!1))},[r,u,f]),g?e.jsx(xB,{skill:g,onBack:()=>y(null)}):e.jsx(It,{className:"h-full",children:e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-72",children:e.jsx(_A,{value:r,onChange:l})}),e.jsx(LCe,{selected:u,onSelect:p}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsxs("select",{value:f,onChange:k=>x(k.target.value),className:"appearance-none font-sans cursor-pointer pr-7 py-2 pl-3 text-xs bg-surface-0 border border-border-subtle rounded text-text-1 focus:outline-none",children:[e.jsx("option",{value:"popular",children:"Popular"}),e.jsx("option",{value:"rating",children:"Top Rated"}),e.jsx("option",{value:"newest",children:"Newest"}),e.jsx("option",{value:"name",children:"A-Z"})]}),e.jsx(zt,{size:12,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:t.length})]}),e.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:s?Array.from({length:8}).map((k,b)=>e.jsx(hB,{},b)):t.map(k=>e.jsx($Ce,{skill:k,onClick:y},k.id))}),!s&&t.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No skills found."})]})})}const kX=new Set(["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"]);function HCe(){const[t,a]=O.useState([]),[s,c]=O.useState(!0),[r,l]=O.useState(""),[u,p]=O.useState(null),[f,x]=O.useState(!1),[g,y]=O.useState(!1),k=()=>{c(!0),X.get(`/integrations/registry?search=${encodeURIComponent(r)}`).then(C=>a(C.integrations||C.items||(Array.isArray(C)?C:[]))).catch(()=>a([])).finally(()=>c(!1))};O.useEffect(()=>{k()},[r]);const b=t.filter(C=>kX.has(C.id)),j=t.filter(C=>!kX.has(C.id)),w=b.filter(C=>C.installed).length;function S(C){p(C),x(!0)}function M(){x(!1),p(null),k()}const $=!r||"google workspace gmail calendar drive docs sheets slides".includes(r.toLowerCase());return e.jsxs(It,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-72",children:e.jsx(_A,{value:r,onChange:l,placeholder:"Search integrations..."})}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:j.length+(b.length>0?1:0)})]}),e.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:s?Array.from({length:6}).map((C,_)=>e.jsx(hB,{},_)):e.jsxs(e.Fragment,{children:[b.length>0&&$&&e.jsx(jQ,{item:{id:"google-workspace",name:"Google Workspace",description:"Gmail, Calendar, Drive, Docs, Sheets, Slides — one sign-in for all",category:"productivity",tags:["google","email","calendar","drive","docs"],verified:"mcp-official",installed:w>0,_installedCount:w},onClick:()=>y(!0)},"google-workspace"),j.map(C=>e.jsx(jQ,{item:C,onClick:()=>S(C)},C.id))]})}),!s&&j.length===0&&b.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No integrations found."})]}),e.jsx(fB,{integration:u,open:f,onClose:M}),e.jsx(ECe,{integrations:t,open:g,onClose:()=>{y(!1),k()}})]})}function BCe(){const t=q(R=>R.marketplaceAuthenticated),a=q(R=>R.marketplaceLogin),[s,c]=O.useState([]),[r,l]=O.useState([]),[u,p]=O.useState([]),[f,x]=O.useState(!0),[g,y]=O.useState("all"),[k,b]=O.useState(""),[j,w]=O.useState(null),[S,M]=O.useState(null),[$,C]=O.useState(!1),_=va(),P=O.useRef(null),L=async()=>{const[R,I]=await Promise.all([X.get("/skills/installed").catch(()=>[]),X.get("/integrations/installed").catch(()=>[])]);l(Array.isArray(R)?R:R.skills||[]),p(Array.isArray(I)?I:I.integrations||[])};O.useEffect(()=>{x(!0),Promise.all([t?X.get("/auth/purchases").then(R=>R.purchases||[]).catch(()=>[]):Promise.resolve([]),X.get("/skills/installed").then(R=>Array.isArray(R)?R:R.skills||[]).catch(()=>[]),X.get("/integrations/installed").then(R=>Array.isArray(R)?R:R.integrations||[]).catch(()=>[])]).then(([R,I,T])=>{c(R),l(I),p(T)}).finally(()=>x(!1))},[t]);async function A(R){var T;const I=(T=R.target.files)==null?void 0:T[0];if(I){try{const Z=await I.text(),J=I.name.replace(/\.md$/i,"");await X.post("/skills/import",{name:J,content:Z}),_.success(`Imported "${J}"`),await L()}catch(Z){_.error("Import failed",Z.message)}R.target.value=""}}if(j)return e.jsx(xB,{skill:j,onBack:()=>w(null)});const z=k.toLowerCase(),Y=g==="all"||g==="skills"?r.filter(R=>!z||(R.name||R.id||"").toLowerCase().includes(z)||(R.description||"").toLowerCase().includes(z)):[],V=g==="all"||g==="integrations"?u.filter(R=>!z||(R.name||R.id||"").toLowerCase().includes(z)||(R.description||"").toLowerCase().includes(z)):[],se=[...Y.map(R=>({...R,_type:"skill"})),...V.map(R=>({...R,_type:"integration"}))],ne=[{id:"all",label:"All"},{id:"skills",label:"Skills"},{id:"integrations",label:"Integrations"}],oe={all:"No skills or integrations installed yet. Visit the Marketplace to get started.",skills:"No skills installed.",integrations:"No integrations installed."};return f?e.jsx("div",{className:"p-5 space-y-3",children:[...Array(4)].map((R,I)=>e.jsx(en,{className:"h-14 rounded-md"},I))}):e.jsxs(It,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("div",{className:"w-72",children:e.jsx(_A,{value:k,onChange:b,placeholder:"Search library..."})}),e.jsx("div",{className:"flex items-center gap-1",children:ne.map(R=>e.jsx("button",{onClick:()=>y(R.id),className:`px-3 py-1.5 text-xs font-semibold font-sans rounded-full cursor-pointer select-none transition-colors ${g===R.id?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1 border border-transparent hover:border-border-subtle"}`,children:R.label},R.id))}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{ref:P,type:"file",accept:".md",onChange:A,className:"hidden"}),e.jsxs(he,{variant:"secondary",size:"md",onClick:()=>{var R;return(R=P.current)==null?void 0:R.click()},className:"gap-1.5",children:[e.jsx(A2,{size:13}),"Import .md"]}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:se.length})]}),t&&s.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[e.jsx(k1,{size:12}),"Purchases (",s.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:s.map(R=>{var I,T;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center text-sm flex-shrink-0",children:R.skill_icon||((T=(I=R.skill_name)==null?void 0:I[0])==null?void 0:T.toUpperCase())||"?"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:R.skill_name||R.skill_id}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:["$",(R.amount||0).toFixed(2)," · ",gt(R.created_at)]})]}),e.jsx(ge,{variant:"success",className:"text-2xs flex-shrink-0",children:"Owned"})]},R.id||R.skill_id)})})]}),t&&s.length===0&&e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[e.jsx(k1,{size:20,className:"mx-auto text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No purchases yet"})]}),!t&&e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[e.jsx(k1,{size:20,className:"mx-auto text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-2 font-sans mb-3",children:"Sign in to see your purchases"}),e.jsxs(he,{variant:"primary",size:"sm",onClick:a,className:"gap-1.5 mx-auto",children:[e.jsx(Do,{size:12})," Sign in"]})]}),se.length>0?e.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:se.map(R=>R._type==="skill"?e.jsx(jQ,{item:{...R,installed:!0},onClick:()=>w(R)},`skill-${R.id}`):e.jsx(jQ,{item:{...R,installed:!0},onClick:()=>{M(R),C(!0)},statusBadge:e.jsx(ge,{variant:R.configured?"success":"warning",className:"text-2xs",children:R.configured?"Active":"Not configured"})},`int-${R.id}`))}):e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:oe[g]})]}),e.jsx(fB,{integration:S,open:$,onClose:()=>{C(!1),M(null),L()}})]})}function GCe(){const t=q(x=>x.importedRepos),a=q(x=>x.fetchImportedRepos),s=q(x=>x.softRemoveRepo),c=q(x=>x.hardNukeRepo),r=va(),[l,u]=O.useState(null);O.useEffect(()=>{a()},[]);async function p(x){try{await s(x.id),r.success(`Removed ${x.repoName||x.name}`)}catch(g){r.error("Remove failed",g.message)}}async function f(x){if(l){try{x?await c(l.id):await s(l.id),r.success(`${x?"Nuked":"Removed"} ${l.name||l.repo}`)}catch(g){r.error("Nuke failed",g.message)}u(null)}}return e.jsxs(It,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsx(XCe,{}),t.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3",children:"Recently Imported"}),e.jsx("div",{className:"space-y-2",children:(Array.isArray(t)?t:[]).map(x=>e.jsx(ZCe,{repo:x,onRemove:()=>p(x),onNuke:()=>u(x)},x.id))})]}),t.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No repos imported yet. Paste a GitHub URL above to get started."})]}),e.jsx(DCe,{repo:l,open:!!l,onClose:()=>u(null),onConfirm:f})]})}function WCe(){const[t,a]=O.useState("skills"),s=[{id:"skills",label:"Skills",icon:bt},{id:"integrations",label:"Integrations",icon:Lt},{id:"github",label:"GitHub",icon:es},{id:"library",label:"My Library",icon:Zd}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-b border-border-subtle",children:e.jsxs("div",{className:"flex items-center px-5 h-11",children:[e.jsx("div",{className:"flex items-center",children:s.map(c=>{const r=c.icon;return e.jsxs("button",{onClick:()=>a(c.id),className:`flex items-center gap-1.5 px-3 py-2.5 text-xs font-semibold font-sans cursor-pointer select-none border-b-2 -mb-px transition-colors ${t===c.id?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"}`,children:[e.jsx(r,{size:12}),c.label]},c.id)})}),e.jsx("div",{className:"flex-1"})]})}),e.jsxs("div",{className:"flex-1 min-h-0",children:[t==="skills"&&e.jsx(UCe,{}),t==="integrations"&&e.jsx(HCe,{}),t==="github"&&e.jsx(GCe,{}),t==="library"&&e.jsx(BCe,{})]})]})}function YCe(){const t=q(l=>l.teams),a=q(l=>l.agents),s=q(l=>l.activeTeamId),c=q(l=>l.deleteTeam),r=q(l=>l.addToast);return t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(sn,{size:28,className:"mx-auto text-text-4"}),e.jsx("p",{className:"text-xs font-sans text-text-3",children:"No teams yet"}),e.jsx("p",{className:"text-2xs font-sans text-text-4",children:"Teams are created when you spawn agents or launch a planner"})]})}):e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx("div",{className:"p-4 space-y-3",children:t.map(l=>{const u=a.filter(b=>b.teamId===l.id),p=u.filter(b=>b.status==="running"||b.status==="starting"),f=u.filter(b=>b.status==="completed"),x=u.filter(b=>b.status==="crashed"),g=u.reduce((b,j)=>b+(j.tokensUsed||0),0),y=u.reduce((b,j)=>b+(j.costUsd||0),0),k=l.id===s;return e.jsxs("div",{className:K("rounded-md border bg-surface-1 overflow-hidden transition-colors",k?"border-accent/30":"border-border-subtle"),children:[e.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans",children:l.name}),k&&e.jsx(ge,{variant:"accent",className:"text-2xs",children:"Active"})]}),l.workingDir&&e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(Ad,{size:10,className:"text-text-4"}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:l.workingDir})]})]}),e.jsx("button",{onClick:()=>{if(u.some(b=>b.status==="running")){r("error","Stop running agents first");return}c(l.id)},className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Delete team",children:e.jsx(wt,{size:13})})]}),e.jsxs("div",{className:"px-4 py-2.5 border-t border-border-subtle bg-surface-0 flex items-center gap-4",children:[e.jsx(jd,{label:"Agents",value:u.length}),e.jsx(jd,{label:"Running",value:p.length,color:p.length>0?"text-success":void 0}),e.jsx(jd,{label:"Done",value:f.length}),e.jsx(jd,{label:"Crashed",value:x.length,color:x.length>0?"text-danger":void 0}),e.jsx("div",{className:"flex-1"}),e.jsx(jd,{label:"Tokens",value:Fe(g)}),y>0&&e.jsx(jd,{label:"Cost",value:Jo(y)})]}),u.length>0&&e.jsx("div",{className:"border-t border-border-subtle",children:u.map(b=>e.jsxs("div",{className:"flex items-center gap-2 px-4 py-1.5 border-b border-border-subtle last:border-b-0",children:[e.jsx(aa,{status:b.status,size:"sm"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:b.name}),e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase",children:b.role}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-2xs font-mono text-text-2 tabular-nums",children:Fe(b.tokensUsed||0)})]},b.id))})]},l.id)})})})}function jd({label:t,value:a,color:s}){return e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:K("text-xs font-mono tabular-nums",s||"text-text-1"),children:a}),e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:t})]})}function FCe(){const t=q(c=>c.pendingApprovals),a=q(c=>c.approveRequest),s=q(c=>c.rejectRequest);return t.length===0?null:e.jsxs("div",{className:"px-4 pt-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Et,{size:12,className:"text-warning"}),e.jsxs("span",{className:"text-2xs font-mono text-warning uppercase tracking-wider",children:["Pending (",t.length,")"]})]}),t.map(c=>{var r,l,u;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs text-text-0 font-sans font-medium truncate",children:[c.agentName,": ",((r=c.action)==null?void 0:r.description)||((l=c.action)==null?void 0:l.type)||"action"]}),((u=c.action)==null?void 0:u.filePath)&&e.jsx("div",{className:"text-2xs font-mono text-text-3 truncate mt-0.5",children:c.action.filePath}),e.jsx("div",{className:"text-2xs text-text-4 font-mono mt-0.5",children:gt(c.requestedAt)})]}),e.jsxs("div",{className:"flex gap-1.5 flex-shrink-0",children:[e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>a(c.id),className:"h-7 px-2.5 gap-1 text-2xs",children:[e.jsx(O1,{size:10})," Approve"]}),e.jsxs(he,{variant:"danger",size:"sm",onClick:()=>s(c.id),className:"h-7 px-2.5 gap-1 text-2xs",children:[e.jsx(qs,{size:10})," Reject"]})]})]},c.id)})]})}function KCe(){const t=q(f=>f.resolvedApprovals),[a,s]=O.useState([]),[c,r]=O.useState(!0);O.useEffect(()=>{const f=setInterval(l,4e3);return l(),()=>clearInterval(f)},[]);async function l(){try{const f=await X.get("/pm/history");s(f.history||f||[])}catch{}r(!1)}const u=new Set,p=[...t,...a].filter(f=>{const x=f.id||`${f.agentName}-${f.timestamp}`;return u.has(x)?!1:(u.add(x),!0)});return e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsx(FCe,{}),e.jsxs("div",{className:"p-4 space-y-1.5",children:[c&&p.length===0&&e.jsx("div",{className:"text-center py-12 text-text-4 font-mono text-xs",children:"Loading..."}),!c&&p.length===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ca,{size:24,className:"mx-auto mb-2 text-text-4"}),e.jsx("p",{className:"text-xs font-sans text-text-3",children:"No approval history"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Approvals appear when agents use Auto permission mode"})]}),p.map((f,x)=>{var y;const g=f.status==="approved"||f.verdict==="approved";return e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-0 border border-border-subtle",children:[g?e.jsx(ca,{size:12,className:"text-success flex-shrink-0"}):e.jsx(yn,{size:12,className:"text-danger flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs text-text-1 font-sans truncate",children:[e.jsx("span",{className:"font-medium text-text-0",children:f.agentName}),e.jsx("span",{className:"text-text-3 mx-1",children:"·"}),e.jsx("span",{children:((y=f.action)==null?void 0:y.description)||f.action||"action"})]}),f.reason&&e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate mt-0.5",children:f.reason})]}),e.jsx("span",{className:"text-2xs font-mono text-text-4 flex-shrink-0",children:gt(f.resolvedAt||f.timestamp)})]},f.id||x)})]})]})}function JCe(){const[t,a]=O.useState([]),[s,c]=O.useState(!0),r=va();O.useEffect(()=>{const p=setInterval(l,1e4);return l(),()=>clearInterval(p)},[]);async function l(){try{const p=await X.get("/schedules");a(p.schedules||p||[])}catch{}c(!1)}async function u(p,f){try{await X.post(`/schedules/${p}/${f?"disable":"enable"}`),l()}catch(x){r.error("Failed to toggle schedule",x.message)}}return e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("div",{className:"p-4 space-y-2",children:[s&&t.length===0&&e.jsx("div",{className:"text-center py-12 text-text-4 font-mono text-xs",children:"Loading..."}),!s&&t.length===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Vo,{size:24,className:"mx-auto mb-2 text-text-4"}),e.jsx("p",{className:"text-xs font-sans text-text-3",children:"No schedules configured"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Use the CLI to create agent schedules"})]}),t.map(p=>e.jsxs("div",{className:"rounded-md border border-border-subtle bg-surface-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:p.name}),e.jsx(ge,{variant:p.enabled?"success":"default",className:"text-2xs",children:p.enabled?"Active":"Paused"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:"text-2xs font-mono text-text-2",children:p.cron}),e.jsx("span",{className:"text-2xs text-text-4",children:"·"}),e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase",children:p.role}),p.teamId&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xs text-text-4",children:"·"}),e.jsx("span",{className:"text-2xs font-sans text-text-3",children:p.teamName||p.teamId})]})]}),p.prompt&&e.jsx("div",{className:"text-2xs font-sans text-text-4 mt-1 truncate",children:p.prompt})]}),e.jsx(he,{variant:"secondary",size:"sm",onClick:()=>u(p.id,p.enabled),className:"h-7 px-2.5 gap-1 text-2xs",children:p.enabled?e.jsxs(e.Fragment,{children:[e.jsx(L2,{size:10})," Pause"]}):e.jsxs(e.Fragment,{children:[e.jsx(z2,{size:10})," Enable"]})})]}),p.lastRunAt&&e.jsxs("div",{className:"px-4 py-1.5 border-t border-border-subtle bg-surface-1 text-2xs font-mono text-text-4",children:["Last run: ",gt(p.lastRunAt),p.nextRunAt&&e.jsxs("span",{className:"ml-3",children:["Next: ",gt(p.nextRunAt)]})]})]},p.id))]})})}function eQe(){return e.jsxs(MA,{defaultValue:"dashboard",className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-4 pt-3 bg-surface-1 border-b border-border",children:[e.jsx("div",{className:"flex items-center gap-4 mb-0",children:e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Management"})}),e.jsxs(jA,{className:"border-b-0",children:[e.jsxs(kn,{value:"dashboard",className:"inline-flex items-center gap-1.5",children:[e.jsx(j2,{size:12}),"Teams"]}),e.jsxs(kn,{value:"approvals",className:"inline-flex items-center gap-1.5",children:[e.jsx(S2,{size:12}),"Approvals"]}),e.jsxs(kn,{value:"schedules",className:"inline-flex items-center gap-1.5",children:[e.jsx(Vo,{size:12}),"Schedules"]})]})]}),e.jsx(vn,{value:"dashboard",className:"flex flex-col min-h-0",children:e.jsx(YCe,{})}),e.jsx(vn,{value:"approvals",className:"flex flex-col min-h-0",children:e.jsx(KCe,{})}),e.jsx(vn,{value:"schedules",className:"flex flex-col min-h-0",children:e.jsx(JCe,{})})]})}const tQe={code:"Code",general:"General"},aQe={light:"text-success",medium:"text-accent",heavy:"text-warning"};function nQe(t){return t<1?`${Math.round(t*1024)} MB`:`${t} GB`}function mB({hardware:t}){if(!t)return null;const{totalRamGb:a,gpu:s,isAppleSilicon:c}=t;return e.jsxs("div",{className:"flex items-center gap-3 bg-surface-0 rounded-lg border border-border-subtle px-3 py-2.5",children:[e.jsx(Uo,{size:14,className:"text-text-3 flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs font-sans",children:[e.jsxs("span",{className:"text-text-0 font-semibold",children:[a," GB RAM"]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{className:"text-text-2",children:s.name})]}),c&&e.jsx(ge,{variant:"accent",className:"text-2xs",children:"Unified Memory"})]})})]})}function sQe({onRecheck:t}){const[a,s]=O.useState(null),[c,r]=O.useState(!1),[l,u]=O.useState(!1),[p,f]=O.useState(!1),x=q(_=>_.addToast);O.useEffect(()=>{X.post("/providers/ollama/check").then(s).catch(()=>{})},[]);async function g(){r(!0);try{const _=await X.post("/providers/ollama/check");s(_),_.installed&&_.serverRunning?(x("success","Ollama is ready!"),t()):_.installed?x("info","Ollama installed — server needs to start"):x("info","Ollama not found — install and try again")}catch{}r(!1)}async function y(){u(!0);try{if((await X.post("/providers/ollama/serve")).ok){x("success","Ollama server started!");let P=!1;for(let L=0;L<5;L++){await new Promise(z=>setTimeout(z,2e3));const A=await X.post("/providers/ollama/check");if(s(A),A.serverRunning){P=!0;break}}P&&t()}}catch(_){x("error","Could not start server",_.message)}u(!1)}function k(_){navigator.clipboard.writeText(_),f(!0),setTimeout(()=>f(!1),2e3)}if(!a)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{hardware:b,install:j,requirements:w,installed:S,serverRunning:M}=a,$=b.totalRamGb>=w.minRAM,C=b.recommended;return e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsx(mB,{hardware:b}),$?e.jsxs("div",{className:"flex items-start gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2.5",children:[e.jsx(Ve,{size:14,className:"text-success flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans",children:[e.jsx("span",{className:"text-success font-semibold",children:"Your system is ready."}),e.jsx("span",{className:"text-text-2 ml-1",children:C.code?`Recommended: ${C.code}`:`${b.totalRamGb} GB RAM available`})]})]}):e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(vt,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsxs("span",{className:"text-warning font-semibold",children:[b.totalRamGb," GB RAM detected."]})," ","Minimum ",w.minRAM," GB needed. Smallest models may still work."]})]}),S&&!M&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(vt,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama installed but server not running."})," ","The server needs to be running to pull and use models."]})]}),e.jsxs(he,{variant:"primary",size:"md",onClick:y,disabled:l,className:"w-full gap-1.5",children:[e.jsx(qt,{size:12}),l?"Starting...":"Start Ollama Server"]})]}),!S&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold text-text-1 font-sans",children:"Install Ollama"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 bg-surface-0 border border-border-subtle rounded-md px-3 py-2 text-xs font-mono text-text-1 truncate",children:j.command}),e.jsxs(he,{variant:"secondary",size:"sm",onClick:()=>k(j.command),className:"h-8 px-2.5 gap-1 flex-shrink-0",children:[p?e.jsx(Ve,{size:12}):e.jsx(Mn,{size:12}),p?"Copied":"Copy"]})]}),j.alt&&e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:j.alt})]}),e.jsxs(he,{variant:"secondary",size:"md",onClick:g,disabled:c,className:"w-full gap-1.5",children:[e.jsx(ia,{size:12,className:c?"animate-spin":""}),c?"Checking...":S?"Check again":"I installed it — check again"]})]})}function oQe({model:t,isInstalled:a,isRecommended:s,canRun:c,onPull:r,onDelete:l,pulling:u}){const p=u===t.id;return e.jsxs("div",{className:K("flex items-center gap-2 px-3 py-2 border-t border-border-subtle transition-colors",!c&&"opacity-40"),children:[a?e.jsx(Ve,{size:12,className:"text-success flex-shrink-0"}):e.jsx("div",{className:"w-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 truncate",children:t.name}),s&&e.jsx(b1,{size:10,className:"text-warning flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:K("text-2xs font-semibold font-sans",aQe[t.tier]),children:t.tier}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:nQe(t.sizeGb)}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["· ",t.ramGb," GB RAM"]})]})]}),a?e.jsx("button",{onClick:()=>l(t.id),className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Remove model",children:e.jsx(wt,{size:12})}):c?e.jsx(he,{variant:"secondary",size:"sm",onClick:()=>r(t.id),disabled:!!u,className:"h-7 px-2 text-2xs gap-1",children:p?e.jsxs(e.Fragment,{children:[e.jsx(ia,{size:10,className:"animate-spin"})," Pulling..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Oa,{size:10})," Pull"]})}):e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["Needs ",t.ramGb," GB"]})]})}function cQe({onStopped:t}){const[a,s]=O.useState(null),c=q(u=>u.addToast);async function r(){s("stopping");try{(await X.post("/providers/ollama/stop")).ok?(c("info","Ollama server stopped"),t&&t()):c("error","Could not stop server")}catch(u){c("error","Stop failed",u.message)}s(null)}async function l(){s("restarting");try{(await X.post("/providers/ollama/restart")).ok?c("success","Ollama server restarted"):c("error","Restart failed")}catch(u){c("error","Restart failed",u.message)}s(null)}return e.jsxs("div",{className:"flex items-center gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-success"}),e.jsx("span",{className:"absolute inset-[-2px] rounded-full bg-success opacity-20 animate-pulse"})]}),e.jsx("span",{className:"text-xs font-sans text-success font-semibold",children:"Server Running"}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:":11434"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:l,disabled:!!a,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-accent cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(ia,{size:10,className:a==="restarting"?"animate-spin":""}),a==="restarting"?"Restarting...":"Restart"]}),e.jsxs("button",{onClick:r,disabled:!!a,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-danger cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(vt,{size:10}),a==="stopping"?"Stopping...":"Stop"]})]})}function rQe({onModelChange:t}){var z,Y;const[a,s]=O.useState(null),[c,r]=O.useState(null),[l,u]=O.useState("code"),[p,f]=O.useState(!1),[x,g]=O.useState(!1),y=q(V=>V.addToast),k=O.useRef(!1);function b(){X.get("/providers/ollama/models").then(V=>{var se;s(V),!k.current&&((se=V.installed)==null?void 0:se.length)===0&&(k.current=!0,setTimeout(b,2e3))}).catch(()=>{})}O.useEffect(()=>{b()},[]);async function j(V){r(V);try{await X.post("/providers/ollama/pull",{model:V}),y("success",`Pulled ${V}`),b(),t&&t()}catch(se){y("error",`Pull failed: ${se.message}`)}r(null)}async function w(V){try{await X.delete(`/providers/ollama/models/${encodeURIComponent(V)}`),y("info",`Removed ${V}`),b(),t&&t()}catch(se){y("error",`Delete failed: ${se.message}`)}}if(!a)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{installed:S,catalog:M,hardware:$}=a,C=new Set(S.map(V=>V.id)),_=$.totalRamGb,P=[(z=$.recommended)==null?void 0:z.code,(Y=$.recommended)==null?void 0:Y.general].filter(Boolean),L=M.filter(V=>V.category===l),A=p?L:L.filter(V=>V.ramGb<=_);return x?e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(vt,{size:14,className:"text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama server stopped."})," ","Start it again to pull and use models."]})]}),e.jsxs(he,{variant:"primary",size:"md",onClick:async()=>{try{(await X.post("/providers/ollama/serve")).ok&&(y("success","Ollama server started!"),g(!1),k.current=!1,setTimeout(b,2e3))}catch(V){y("error","Could not start server",V.message)}},className:"w-full gap-1.5",children:[e.jsx(qt,{size:12}),"Start Ollama Server"]})]}):e.jsxs("div",{className:"space-y-2 p-3",children:[e.jsx(cQe,{onStopped:()=>g(!0)}),e.jsx(mB,{hardware:$}),S.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-sans text-text-2",children:[e.jsx(Xo,{size:12,className:"text-text-3"}),e.jsx("span",{className:"font-semibold",children:S.length})," model",S.length!==1?"s":""," installed"]}),e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:Object.entries(tQe).map(([V,se])=>e.jsx("button",{onClick:()=>u(V),className:K("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",l===V?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:se},V))}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[A.map(V=>e.jsx(oQe,{model:V,isInstalled:C.has(V.id),isRecommended:P.includes(V.id),canRun:V.ramGb<=_,onPull:j,onDelete:w,pulling:c},V.id)),A.length===0&&e.jsxs("div",{className:"px-3 py-4 text-center text-xs text-text-4 font-sans",children:["No ",l," models available for your hardware"]})]}),!p&&L.length>A.length&&e.jsxs("button",{onClick:()=>f(!0),className:"flex items-center gap-1 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(zt,{size:10}),"Show ",L.length-A.length," more (exceed your RAM)"]})]})}function yB({isInstalled:t,onModelChange:a}){const[s,c]=O.useState(!1),[r,l]=O.useState(!1);return O.useEffect(()=>{t?X.post("/providers/ollama/check").then(u=>{c(u.installed&&u.serverRunning),l(!0)}).catch(()=>l(!0)):l(!0)},[t]),r?s?e.jsx(rQe,{onModelChange:a}):e.jsx(sQe,{onRecheck:()=>{c(!0),a&&a()}}):e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Checking Ollama..."})}function FQ({children:t,...a}){return e.jsx(yD,{...a,children:t})}function KQ({children:t,className:a,title:s,side:c="right",width:r=400,...l}){return e.jsxs(gD,{children:[e.jsx(OD,{className:"fixed inset-0 z-40 bg-black/30"}),e.jsxs(kD,{className:K("fixed top-0 z-50 h-full overflow-y-auto","bg-surface-1 border-l border-border shadow-2xl","data-[state=open]:animate-in data-[state=closed]:animate-out",c==="right"&&"right-0 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",c==="left"&&"left-0 data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",a),style:{width:r},...l,children:[s&&e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle sticky top-0 bg-surface-1 z-10",children:[e.jsx(vD,{className:"text-base font-semibold text-text-0 font-sans",children:s}),e.jsx(wD,{className:"p-1 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-5 transition-colors cursor-pointer",children:e.jsx(st,{size:16})})]}),e.jsx(bD,{className:"sr-only",children:"Panel"}),t]})]})}function iQe({value:t,onChange:a}){return e.jsx("button",{onClick:()=>a(!t),className:K("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer",t?"bg-accent":"bg-surface-5"),children:e.jsx("div",{className:K("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",t?"translate-x-4":"translate-x-0")})})}function lQe({provider:t,onKeyChange:a}){var S,M,$,C;const[s,c]=O.useState(!1),[r,l]=O.useState(""),[u,p]=O.useState(!1),[f,x]=O.useState(!1),g=q(_=>_.addToast),y=t.authType==="local",k=t.authType==="subscription",b=y?t.installed:k?t.installed||((S=t.authStatus)==null?void 0:S.authenticated):t.installed&&t.hasKey;async function j(){if(r.trim())try{await X.post(`/credentials/${encodeURIComponent(t.id)}`,{key:r.trim()}),g("success",`API key set for ${t.name}`),l(""),c(!1),a&&a()}catch(_){g("error","Failed to set key",_.message)}}async function w(){try{await X.delete(`/credentials/${encodeURIComponent(t.id)}`),g("info",`Removed ${t.name} key`),a&&a()}catch(_){g("error","Remove failed",_.message)}}if(y){const _=(($=(M=t.models)==null?void 0:M.filter(L=>!L.disabled))==null?void 0:$.length)||0,P=()=>q.getState().setActiveView("models");return e.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[e.jsx(aa,{status:b&&_>0?"running":"crashed",size:"sm"}),e.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"flex-1"}),b&&_>0?e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(Ve,{size:8})," ",_," models"]}):b?e.jsx(ge,{variant:"warning",className:"text-2xs",children:"No models pulled"}):e.jsx(ge,{variant:"default",className:"text-2xs",children:"Not set up"})]}),e.jsx("div",{className:"flex-1",children:f?e.jsxs(e.Fragment,{children:[e.jsx(yB,{isInstalled:b,onModelChange:a}),e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle flex gap-2",children:[e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>x(!1),className:"flex-1 h-7 text-2xs",children:"Back"}),e.jsx(he,{variant:"secondary",size:"sm",onClick:()=>{x(!1),P()},className:"flex-1 h-7 text-2xs gap-1",children:"Models Tab"})]})]}):e.jsxs("div",{className:"px-4 py-3 flex flex-col h-full",children:[e.jsx("div",{className:"text-xs text-text-3 font-sans flex-1",children:b&&_>0?"Full agentic runtime — tool calling, context rotation, zero cloud cost":b?"Ollama is running. Pull a model to start using local agents.":"Run any open-source model locally — free, private, fully offline. Requires Ollama."}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[b?e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>x(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[e.jsx(tn,{size:11})," ",_>0?"Manage":"Pull Models"]}):e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>x(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[e.jsx(tn,{size:11})," Set Up Ollama"]}),e.jsx(he,{variant:"secondary",size:"sm",onClick:P,className:"flex-1 h-7 text-2xs gap-1.5",children:"Models Tab"})]})]})})]})}return e.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[e.jsx(aa,{status:b?"running":"crashed",size:"sm"}),e.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"flex-1"}),b?e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(Ve,{size:8})," Ready"]}):e.jsx(ge,{variant:"default",className:"text-2xs",children:t.installed?k?"Not authenticated":"No key":"Not installed"})]}),e.jsxs("div",{className:"flex-1 flex flex-col px-4 py-3 min-h-[120px]",children:[((C=t.models)==null?void 0:C.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mb-3",children:t.models.map(_=>e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-surface-4 text-2xs font-mono text-text-3",children:_.name||_.id},_.id))}),k&&b&&!t.hasKey&&!s&&e.jsxs("div",{className:"flex items-center gap-1.5 h-8 px-2.5 bg-accent/8 border border-accent/20 rounded-md text-2xs font-sans text-accent mb-3",children:[e.jsx(Ve,{size:10})," Subscription active"]}),t.hasKey&&!s&&e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-1.5 h-8 px-2.5 bg-success/8 border border-success/20 rounded-md text-2xs font-sans text-success",children:[e.jsx(Ve,{size:10})," API Connected"]}),e.jsx("button",{onClick:()=>{c(!0),p(!1),l("")},className:"text-2xs text-text-4 hover:text-accent cursor-pointer font-sans",children:"Edit"}),e.jsx("button",{onClick:w,className:"text-2xs text-text-4 hover:text-danger cursor-pointer font-sans",children:"Remove"})]}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("div",{className:"space-y-2.5 pt-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:t.hasKey?"Update API Key":`${t.name} API Key`}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:r,onChange:_=>l(_.target.value),onKeyDown:_=>_.key==="Enter"&&j(),type:u?"text":"password",placeholder:"sk-...",className:"w-full h-9 px-3 pr-9 text-xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:()=>p(!u),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:u?e.jsx(Jn,{size:12}):e.jsx(ka,{size:12})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(he,{variant:"primary",size:"sm",onClick:j,disabled:!r.trim(),className:"flex-1 h-8 text-xs",children:"Save Key"}),e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>{c(!1),l("")},className:"h-8 text-xs px-3",children:"Cancel"})]})]}),!s&&!t.hasKey&&e.jsxs(he,{variant:k?"secondary":"primary",size:"sm",onClick:()=>{c(!0),p(!1),l("")},className:"w-full h-8 text-2xs gap-1.5 mt-2",children:[e.jsx(jn,{size:11}),k?"Add API key for headless mode":"Add API Key"]})]})]})}function Oc({icon:t,label:a,description:s,children:c}){return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(t,{size:12,className:"text-accent"})}),e.jsx("div",{className:"text-[13px] font-medium text-text-0 font-sans leading-tight",children:a})]}),e.jsx("div",{className:"text-2xs text-text-4 font-sans leading-relaxed",children:s}),e.jsx("div",{className:"mt-auto pt-1",children:c})]})}const gB={telegram:Zs,discord:Nn,slack:Sn},u1={telegram:"Telegram",discord:"Discord",slack:"Slack"},dQe={telegram:"Bot token from @BotFather",discord:"Bot token from Developer Portal",slack:"Bot token (xoxb-...)"},uQe=["critical","lifecycle","all"];function hQe({type:t,open:a,onOpenChange:s}){if(!t)return null;const r={telegram:{title:"Set Up Telegram",icon:Zs,intro:"Create a Telegram bot and connect it to Groove in under 2 minutes. No dependencies required.",sections:[{title:"Create Your Bot",steps:[{text:"Open Telegram on any device and search for",link:"https://t.me/BotFather",linkText:"@BotFather"},{text:"Send /newbot to start the setup"},{text:"Choose a display name — we suggest GroovePilot"},{text:'Choose a username (must end in "bot") — e.g. GroovePilot_bot'},{text:"BotFather will reply with your bot token — copy it"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Telegram card"},{text:"Paste your bot token and click Save"},{text:"The gateway will connect automatically"}]},{title:"Link a Chat",steps:[{text:"Open a chat with your new bot in Telegram"},{text:'Send any message (e.g. "hello") — Groove captures the chat ID automatically'},{text:"Click Test in the gateway card to verify"}]},{title:"Commands",note:"All commands use / prefix in Telegram:",commands:["/instruct <team> <msg>","/query <team> <question>","/plan <description>","/log <team>","/brief","/tokens","/status","/agents","/help"]}]},discord:{title:"Set Up Discord",icon:Nn,intro:"Create a Discord bot and add it to your server. Requires discord.js (installed automatically with Groove).",sections:[{title:"Create the Application",steps:[{text:"Go to the",link:"https://discord.com/developers/applications",linkText:"Discord Developer Portal"},{text:"Click New Application and name it GroovePilot"},{text:"Go to the Bot tab in the left sidebar"},{text:"Click Reset Token and copy the bot token"}]},{title:"Set Permissions & Invite",steps:[{text:"Go to OAuth2 > URL Generator"},{text:"Under Scopes, check bot"},{text:"Under Bot Permissions, check:"}],scopes:["Send Messages","Read Message History","Embed Links","Use External Emojis"],after:[{text:"Copy the generated URL at the bottom and open it in your browser"},{text:"Select your server and click Authorize"}]},{title:"Enable Message Content Intent",steps:[{text:"Go back to the Bot tab in the Developer Portal"},{text:"Scroll to Privileged Gateway Intents"},{text:"Enable Message Content Intent — required for the bot to read commands"},{text:"Click Save Changes"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Discord card"},{text:"Paste your bot token and click Save"},{text:"Send a message in any channel where the bot is — Groove captures the channel automatically"}]},{title:"Commands",note:"All commands use / prefix in Discord:",commands:["/instruct <team> <msg>","/query <team> <question>","/plan <description>","/log <team>","/brief","/tokens","/status","/agents","/help"]}]},slack:{title:"Set Up Slack",icon:Sn,intro:"Create a Slack app with Socket Mode — no public URL needed. Requires @slack/bolt (installed automatically with Groove).",sections:[{title:"Create the App",steps:[{text:"Go to",link:"https://api.slack.com/apps",linkText:"api.slack.com/apps"},{text:"Click Create New App > From scratch"},{text:"Name it GroovePilot and select your workspace"}]},{title:"Enable Socket Mode",steps:[{text:"In the left sidebar, go to Settings > Socket Mode"},{text:"Toggle Enable Socket Mode to on"},{text:"It will ask you to create an App-Level Token"},{text:'Name it "groove", add the connections:write scope'},{text:"Click Generate — copy the xapp-... token (this is your App Token)"}],important:"Save this token now — you can't view it again after closing the dialog."},{title:"Set Bot Token Scopes",steps:[{text:"Go to Features > OAuth & Permissions"},{text:"Scroll to Bot Token Scopes and add all of these:"}],scopes:["chat:write","channels:read","channels:history","groups:read","groups:history","im:history","app_mentions:read"],after:[{text:"Scroll up and click Install to Workspace"},{text:"Click Allow to grant permissions"},{text:"Copy the Bot User OAuth Token (xoxb-...) — this is your Bot Token"}]},{title:"Enable Events",steps:[{text:"Go to Features > Event Subscriptions"},{text:"Toggle Enable Events to on"},{text:"Under Subscribe to bot events, add:"}],scopes:["message.channels","message.im","app_mention"],after:[{text:"Click Save Changes at the bottom"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Slack card"},{text:"Paste your Bot Token (xoxb-...) in the first field"},{text:"Paste your App Token (xapp-...) in the second field"},{text:"Click Save — Groove will auto-connect"}]},{title:"Link a Channel",steps:[{text:"Invite the bot to a channel: /invite @GroovePilot"},{text:"Select the channel from the dropdown in the gateway card"},{text:"Or @mention the bot — it will auto-capture the channel"},{text:"Click Test to verify"}],important:"For private channels, make sure you added the groups:read scope."},{title:"Commands",note:"In Slack, use plain text commands (no / prefix) or @mention the bot:",commands:["instruct <team> <msg>","query <team> <question>","plan <description>","log <team>","brief","tokens","status","agents","help","@GroovePilot status"]}]}}[t];if(!r)return null;const l=r.icon;return e.jsx(FQ,{open:a,onOpenChange:s,children:e.jsx(KQ,{title:r.title,width:480,children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-accent/5 border border-accent/15 rounded-lg",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(l,{size:16,className:"text-accent"})}),e.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed",children:r.intro})]}),r.sections.map((u,p)=>{var f;return e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xs font-semibold text-text-0 font-sans mb-2.5 flex items-center gap-2",children:[e.jsx("span",{className:"w-5 h-5 rounded-full bg-accent/10 flex items-center justify-center text-2xs font-bold text-accent",children:p+1}),u.title]}),u.note&&e.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:u.note}),u.steps&&e.jsx("ol",{className:"space-y-2 mb-2",children:u.steps.map((x,g)=>e.jsxs("li",{className:"flex gap-2 text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono w-4 flex-shrink-0 pt-px",children:[g+1,"."]}),e.jsxs("span",{children:[x.text,x.link&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:x.link,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-0.5 font-medium",children:[x.linkText,e.jsx(Pt,{size:9})]})]})]})]},g))}),u.scopes&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2 ml-6",children:u.scopes.map(x=>e.jsx("code",{className:"px-2 py-0.5 rounded bg-surface-4 text-2xs font-mono text-accent",children:x},x))}),u.after&&e.jsx("ol",{className:"space-y-2 mb-2",start:(((f=u.steps)==null?void 0:f.length)||0)+1,children:u.after.map((x,g)=>{var y;return e.jsxs("li",{className:"flex gap-2 text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono w-4 flex-shrink-0 pt-px",children:[(((y=u.steps)==null?void 0:y.length)||0)+g+1,"."]}),e.jsx("span",{children:x.text})]},g)})}),u.important&&e.jsx("div",{className:"ml-6 p-2 bg-warning/8 border border-warning/20 rounded-md text-2xs text-warning font-sans",children:u.important}),u.commands&&e.jsx("div",{className:"ml-6 p-2.5 bg-surface-0 border border-border-subtle rounded-md space-y-1",children:u.commands.map(x=>e.jsx("code",{className:"block text-2xs font-mono text-text-1",children:x},x))})]},p)}),e.jsxs("a",{href:"https://docs.groovedev.ai/guide/gateways",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium mt-2",children:[e.jsx(Pt,{size:10}),"Full documentation at docs.groovedev.ai"]})]})})})}function pQe({gateway:t,onRefresh:a}){var oe,R;const[s,c]=O.useState(!1),[r,l]=O.useState(""),[u,p]=O.useState(""),[f,x]=O.useState(!1),[g,y]=O.useState(!1),[k,b]=O.useState(!1),[j,w]=O.useState([]),[S,M]=O.useState(!1),$=q(I=>I.addToast);O.useEffect(()=>{t.connected&&!t.chatId&&t.type==="slack"&&X.get(`/gateways/${encodeURIComponent(t.id)}/channels`).then(I=>w(Array.isArray(I)?I:[])).catch(()=>{})},[t.connected,t.chatId,t.id,t.type]);const C=gB[t.type]||an,_=t.type==="slack";async function P(){if(r.trim())try{await X.post(`/gateways/${encodeURIComponent(t.id)}/credentials`,{key:"bot_token",value:r.trim()}),_&&u.trim()&&await X.post(`/gateways/${encodeURIComponent(t.id)}/credentials`,{key:"app_token",value:u.trim()}),$("success","Token saved — connecting..."),l(""),p(""),c(!1);try{await X.post(`/gateways/${encodeURIComponent(t.id)}/connect`),$("success",`${u1[t.type]} connected!`)}catch(I){$("error","Token saved but connect failed",I.message)}a()}catch(I){$("error","Failed to save token",I.message)}}async function L(){y(!0);try{await X.post(`/gateways/${encodeURIComponent(t.id)}/test`),$("success","Test message sent!")}catch(I){$("error","Test failed",I.message)}y(!1)}async function A(){b(!0);try{t.connected?(await X.post(`/gateways/${encodeURIComponent(t.id)}/disconnect`),$("info",`${u1[t.type]} disconnected`)):(await X.post(`/gateways/${encodeURIComponent(t.id)}/connect`),$("success",`${u1[t.type]} connected!`)),a()}catch(I){$("error",t.connected?"Disconnect failed":"Connect failed",I.message)}b(!1)}async function z(I){try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{enabled:I}),a()}catch(T){$("error","Update failed",T.message)}}async function Y(I){try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{notifications:{preset:I}}),a()}catch(T){$("error","Update failed",T.message)}}async function V(I){try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{commandPermission:I}),a()}catch(T){$("error","Update failed",T.message)}}async function se(){try{await X.delete(`/gateways/${encodeURIComponent(t.id)}`),$("info",`${u1[t.type]} gateway removed`),a()}catch(I){$("error","Delete failed",I.message)}}const ne=((oe=t.notifications)==null?void 0:oe.preset)||"critical";return e.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[e.jsx(aa,{status:t.connected?"running":"crashed",size:"sm"}),e.jsx(C,{size:13,className:"text-text-2"}),e.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:u1[t.type]}),e.jsx("div",{className:"flex-1"}),t.connected?e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(As,{size:8})," Connected"]}):t.enabled?e.jsx(ge,{variant:"warning",className:"text-2xs",children:"Disconnected"}):e.jsx(ge,{variant:"default",className:"text-2xs",children:"Disabled"})]}),e.jsxs("div",{className:"flex-1 flex flex-col px-4 py-3 min-h-[140px]",children:[t.connected&&!s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 h-8 px-2.5 bg-success/8 border border-success/20 rounded-md text-2xs font-sans text-success mb-3",children:[e.jsx(Ve,{size:10})," Gateway active",t.botUsername&&e.jsxs("span",{className:"text-text-4 ml-1",children:["@",t.botUsername]}),t.botTag&&e.jsx("span",{className:"text-text-4 ml-1",children:t.botTag})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:t.type==="slack"?"Channel":"Chat ID"}),t.chatId?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 flex items-center h-7 px-2 bg-surface-0 border border-border-subtle rounded-md text-2xs font-mono text-text-2",children:t.type==="slack"&&j.length>0?`#${((R=j.find(I=>I.id===t.chatId))==null?void 0:R.name)||t.chatId}`:t.chatId}),e.jsx("button",{onClick:async()=>{try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{chatId:null}),a()}catch(I){$("error","Failed",I.message)}},className:"text-2xs text-text-4 hover:text-text-1 cursor-pointer font-sans",children:"Change"})]}):t.type==="slack"&&j.length>0?e.jsxs("select",{onChange:async I=>{if(I.target.value)try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{chatId:I.target.value}),a()}catch(T){$("error","Failed to set channel",T.message)}},className:"w-full h-7 px-2 text-2xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",defaultValue:"",children:[e.jsx("option",{value:"",disabled:!0,children:"Select a channel..."}),j.map(I=>e.jsxs("option",{value:I.id,children:["#",I.name]},I.id))]}):e.jsxs("div",{className:"text-2xs text-warning font-sans",children:[t.type==="slack"?"No channels found — invite the bot to a channel first.":"Send a message to the bot to auto-capture, or enter manually:",e.jsx("input",{placeholder:t.type==="slack"?"C0123456789":"Chat ID",className:"mt-1 w-full h-7 px-2 text-2xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",onKeyDown:async I=>{if(I.key==="Enter"&&I.target.value.trim())try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{chatId:I.target.value.trim()}),a()}catch(T){$("error","Failed to set channel",T.message)}}})]})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:"Notifications"}),e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:uQe.map(I=>e.jsx("button",{onClick:()=>Y(I),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer capitalize",ne===I?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:I},I))})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:"Commands"}),e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:["full","read-only"].map(I=>e.jsx("button",{onClick:()=>V(I),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer capitalize",(t.commandPermission||"full")===I?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:I==="full"?"Full Access":"Read Only"},I))})]})]}),!t.connected&&!s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-text-3 font-sans mb-2",children:t.enabled?t.hasCredentials?"Tokens saved — click Connect.":"Configure bot token to connect.":"Gateway is disabled."}),!t.hasCredentials&&e.jsxs("button",{onClick:()=>M(!0),className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer mb-2",children:[e.jsx(Wt,{size:11}),"How to set up",e.jsx(Pt,{size:9})]})]}),e.jsx(hQe,{type:t.type,open:S,onOpenChange:M}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("div",{className:"space-y-2.5 pt-1",children:[e.jsxs("button",{onClick:()=>M(!0),className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer",children:[e.jsx(Wt,{size:11}),"Where do I get these?"]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:"Bot Token"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:r,onChange:I=>l(I.target.value),onKeyDown:I=>I.key==="Enter"&&!_&&P(),type:f?"text":"password",placeholder:dQe[t.type],className:"w-full h-9 px-3 pr-9 text-xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:()=>x(!f),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:f?e.jsx(Jn,{size:12}):e.jsx(ka,{size:12})})]})]}),_&&e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:"App Token (Socket Mode)"}),e.jsx("input",{value:u,onChange:I=>p(I.target.value),onKeyDown:I=>I.key==="Enter"&&P(),type:f?"text":"password",placeholder:"xapp-...",className:"w-full h-9 px-3 text-xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(he,{variant:"primary",size:"sm",onClick:P,disabled:!r.trim(),className:"flex-1 h-8 text-xs",children:"Save Token"}),e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>{c(!1),l(""),p("")},className:"h-8 text-xs px-3",children:"Cancel"})]})]}),!s&&e.jsxs("div",{className:"flex gap-2 mt-2",children:[!t.connected&&e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>c(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[e.jsx(jn,{size:11}),t.enabled?"Set Token":"Configure"]}),t.connected&&e.jsxs(e.Fragment,{children:[e.jsxs(he,{variant:"secondary",size:"sm",onClick:L,disabled:g,className:"flex-1 h-7 text-2xs gap-1.5",children:[e.jsx(w1,{size:11}),g?"Sending...":"Test"]}),e.jsx(he,{variant:"secondary",size:"sm",onClick:()=>c(!0),className:"h-7 text-2xs px-2.5",children:e.jsx(jn,{size:11})})]}),e.jsx(he,{variant:"ghost",size:"sm",onClick:A,disabled:k,className:"h-7 text-2xs px-2.5",title:t.connected?"Disconnect":"Connect",children:t.connected?e.jsx(Lt,{size:11}):e.jsx(As,{size:11})}),e.jsx(iQe,{value:t.enabled,onChange:z}),e.jsx("button",{onClick:se,className:"text-text-4 hover:text-danger cursor-pointer p-1",title:"Remove gateway",children:e.jsx(wt,{size:11})})]})]})]})}function fQe({existingTypes:t,onAdd:a}){const[s,c]=O.useState(!1),r=["telegram","discord","slack"].filter(l=>!t.includes(l));return r.length===0?null:s?e.jsxs("div",{className:"flex flex-col rounded-lg border border-accent/30 bg-surface-1 overflow-hidden min-w-[220px]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[e.jsx(an,{size:13,className:"text-accent"}),e.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:"Add Gateway"}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>c(!1),className:"text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(st,{size:12})})]}),e.jsx("div",{className:"p-3 space-y-2",children:r.map(l=>{const u=gB[l];return e.jsxs("button",{onClick:()=>{a(l),c(!1)},className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-0 hover:bg-accent/8 border border-border-subtle hover:border-accent/20 cursor-pointer transition-all group",children:[e.jsx(u,{size:14,className:"text-text-3 group-hover:text-accent"}),e.jsx("span",{className:"text-xs font-medium text-text-1 group-hover:text-accent font-sans",children:u1[l]})]},l)})})]}):e.jsxs("button",{onClick:()=>c(!0),className:"flex flex-col items-center justify-center rounded-lg border border-dashed border-border-subtle bg-surface-1/50 hover:bg-surface-1 hover:border-accent/30 min-h-[140px] min-w-[220px] cursor-pointer transition-all group",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-accent/8 group-hover:bg-accent/15 flex items-center justify-center mb-2 transition-colors",children:e.jsx(rt,{size:14,className:"text-accent"})}),e.jsx("span",{className:"text-2xs font-semibold text-text-3 group-hover:text-text-1 font-sans transition-colors",children:"Add Gateway"})]})}function xQe(){const t=q(y=>y.networkUnlocked),a=q(y=>y.activateBeta),s=q(y=>y.deactivateBeta),[c,r]=O.useState(""),[l,u]=O.useState(!1),[p,f]=O.useState("");O.useEffect(()=>{if(!p)return;const y=setTimeout(()=>f(""),3e3);return()=>clearTimeout(y)},[p]);async function x(){const y=c.trim();if(!(!y||l)){u(!0),f("");try{await a(y),r("")}catch(k){f(k.message||"Invalid code")}finally{u(!1)}}}async function g(){try{await s()}catch{}}return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Early Access"}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"})]}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5 max-w-md",children:[t?e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-success/10 flex items-center justify-center flex-shrink-0",children:e.jsx(Ve,{size:12,className:"text-success"})}),e.jsx("div",{className:"flex-1 text-xs font-sans text-text-1",children:"Early access enabled"}),e.jsx("button",{onClick:g,className:"text-2xs text-text-4 hover:text-danger cursor-pointer font-sans",children:"Deactivate"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Vd,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("input",{value:c,onChange:y=>r(y.target.value),onKeyDown:y=>y.key==="Enter"&&x(),type:"text",placeholder:"Enter invite code",className:"flex-1 h-8 px-2.5 text-xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsx(he,{variant:"primary",size:"sm",onClick:x,disabled:!c.trim()||l,className:"h-8 text-xs px-3",children:l?"...":"Submit"})]}),p&&!t&&e.jsx("div",{className:"mt-2 text-2xs text-danger font-sans",children:p})]})]})}function mQe(){var _;const[t,a]=O.useState([]),[s,c]=O.useState(null),[r,l]=O.useState(null),[u,p]=O.useState([]),[f,x]=O.useState(!0),[g,y]=O.useState(!1),k=q(P=>P.addToast);function b(){X.get("/providers").then(P=>a(Array.isArray(P)?P:[])).catch(()=>{})}function j(){X.get("/gateways").then(P=>p(Array.isArray(P)?P:[])).catch(()=>{})}O.useEffect(()=>{Promise.all([X.get("/providers"),X.get("/config"),X.get("/status"),X.get("/gateways")]).then(([P,L,A,z])=>{a(Array.isArray(P)?P:[]),c(L),l(A),p(Array.isArray(z)?z:[]),x(!1)}).catch(()=>x(!1))},[]);async function w(P){try{await X.post("/gateways",{type:P}),k("success",`${u1[P]} gateway added`),j()}catch(L){k("error","Failed to add gateway",L.message)}}async function S(P,L){try{const A=await X.patch("/config",{[P]:L});c(A)}catch(A){k("error","Update failed",A.message)}}if(f)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"h-12 bg-surface-1 border-b border-border"}),e.jsxs("div",{className:"flex-1 p-4 space-y-4",children:[e.jsx("div",{className:"grid grid-cols-4 gap-3",children:[...Array(4)].map((P,L)=>e.jsx(en,{className:"h-40 rounded-lg"},L))}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[...Array(6)].map((P,L)=>e.jsx(en,{className:"h-28 rounded-lg"},L))})]})]});const M=t.filter(P=>P.id!=="groove-network"),$=M.filter(P=>P.authType==="local"||P.authType==="subscription"?P.installed:P.installed&&P.hasKey).length,C=(s==null?void 0:s.rotationThreshold)||0;return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2.5 bg-surface-1 border-b border-border flex-shrink-0",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 font-sans",children:"Settings"}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center gap-4 text-2xs text-text-3 font-sans",children:[(r==null?void 0:r.version)&&e.jsxs("span",{children:["v",r.version]}),(r==null?void 0:r.port)&&e.jsxs("span",{children:[":",r.port]}),(r==null?void 0:r.uptime)>0&&e.jsxs("span",{children:["Up ",su(r.uptime)]})]}),e.jsx(aa,{status:"running",size:"sm"})]}),e.jsx(It,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Providers"}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:[$,"/",M.length," connected"]})]}),e.jsx("div",{className:"grid grid-cols-4 gap-3",children:M.map(P=>e.jsx(lQe,{provider:P,onKeyChange:b},P.id))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Gateways"}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:[u.filter(P=>P.connected).length,"/",u.length," connected"]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[u.map(P=>e.jsx(pQe,{gateway:P,onRefresh:j},P.id)),e.jsx(fQe,{existingTypes:u.map(P=>P.type),onAdd:w})]})]}),s&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Configuration"}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Auto-saves"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(Oc,{icon:tn,label:"Default Provider",description:"Provider used when spawning new agents.",children:e.jsx("select",{value:s.defaultProvider||"claude-code",onChange:P=>S("defaultProvider",P.target.value),className:"w-full h-8 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",children:M.filter(P=>P.installed&&(P.authType==="local"||P.authType==="subscription"||P.hasKey)).map(P=>e.jsx("option",{value:P.id,children:P.name},P.id))})}),e.jsx(Oc,{icon:tn,label:"Default Model",description:"Model used for new agents. Auto routes by role.",children:e.jsxs("select",{value:s.defaultModel||"",onChange:P=>S("defaultModel",P.target.value||null),className:"w-full h-8 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",children:[e.jsx("option",{value:"",children:"Auto (route by role)"}),(((_=t.find(P=>P.id===(s.defaultProvider||"claude-code")))==null?void 0:_.models)||[]).map(P=>e.jsx("option",{value:P.id,children:P.name},P.id))]})}),e.jsx(Oc,{icon:ta,label:"Working Directory",description:"Default root directory for new agents.",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("code",{className:"flex-1 h-8 px-2 flex items-center bg-surface-0 border border-border-subtle rounded-md text-2xs font-mono text-text-2 truncate min-w-0",children:s.defaultWorkingDir||"Project root"}),e.jsx(he,{variant:"secondary",size:"sm",onClick:async()=>{var P,L;if((L=(P=window.groove)==null?void 0:P.folders)!=null&&L.select){const A=await window.groove.folders.select({title:"Select Working Directory",defaultPath:(s==null?void 0:s.defaultWorkingDir)||void 0});A&&S("defaultWorkingDir",A)}else y(!0)},className:"h-8 px-2 flex-shrink-0",children:e.jsx(x1,{size:12})})]})}),e.jsx(Oc,{icon:qd,label:"Rotation Threshold",description:"Context usage that triggers auto-rotation.",children:e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:["auto","50%","65%","75%","85%"].map(P=>{const L=P==="auto"?0:parseInt(P,10)/100,A=C===L;return e.jsx("button",{onClick:()=>S("rotationThreshold",L),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",A?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:P==="auto"?"Auto":P},P)})})}),e.jsx(Oc,{icon:O1,label:"QC Threshold",description:"Running agents count that triggers auto-QC.",children:e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[2,3,4,6,8].map(P=>{const L=(s.qcThreshold||2)===P;return e.jsx("button",{onClick:()=>S("qcThreshold",P),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",L?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:P},P)})})}),e.jsx(Oc,{icon:sn,label:"Max Agents",description:"Concurrent agent limit. 0 = unlimited.",children:e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[0,4,8,12,20].map(P=>{const L=(s.maxAgents||0)===P;return e.jsx("button",{onClick:()=>S("maxAgents",P),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",L?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:P===0?"∞":P},P)})})}),e.jsx(Oc,{icon:Es,label:"Journalist Interval",description:"Seconds between synthesis cycles.",children:e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[60,120,300,600].map(P=>{const L=(s.journalistInterval||120)===P,A=P<60?`${P}s`:`${P/60}m`;return e.jsx("button",{onClick:()=>S("journalistInterval",P),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",L?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:A},P)})})})]})]}),e.jsx(xQe,{})]})}),e.jsx(ou,{open:g,onOpenChange:y,currentPath:(s==null?void 0:s.defaultWorkingDir)||"/",onSelect:P=>S("defaultWorkingDir",P)})]})}function SQ(t){return t?t<1024*1024?`${(t/1024).toFixed(0)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`:"—"}function yQe(t){return t?t<1024*1024?`${(t/1024).toFixed(0)} KB/s`:`${(t/(1024*1024)).toFixed(1)} MB/s`:""}function gQe({hardware:t}){var a;return t?e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2.5 bg-surface-1 border border-border-subtle rounded-lg text-xs font-sans text-text-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx($2,{size:14,className:"text-text-3"}),e.jsxs("span",{children:[t.totalRamGb," GB RAM"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(tn,{size:14,className:"text-text-3"}),e.jsxs("span",{children:[t.cores," cores"]})]}),t.gpu&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Xo,{size:14,className:"text-text-3"}),e.jsxs("span",{children:[t.gpu.name,t.gpu.vram?` (${t.gpu.vram} GB)`:""]})]}),((a=t.recommended)==null?void 0:a.code)&&e.jsxs("div",{className:"ml-auto text-accent",children:["Recommended: ",t.recommended.code]})]}):null}function OQe({download:t}){const a=Math.round((t.percent||0)*100);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans text-text-3",children:[e.jsx("span",{children:t.filename}),e.jsxs("span",{children:[a,"% ",yQe(t.speed)]})]}),e.jsx("div",{className:"h-1.5 bg-surface-3 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent rounded-full transition-all",style:{width:`${a}%`}})}),e.jsxs("div",{className:"text-2xs text-text-4",children:[SQ(t.downloaded)," / ",SQ(t.totalBytes)]})]})}function kQe({model:t,onDelete:a}){const[s,c]=O.useState(!1),r={light:"text-green-400",medium:"text-blue-400",heavy:"text-orange-400"};return e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-surface-1 border border-border-subtle rounded-lg",children:[e.jsx(wn,{size:18,className:"text-accent flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate",children:t.id}),t.quantization&&e.jsx(ge,{variant:"subtle",className:"text-2xs",children:t.quantization}),t.parameters&&e.jsx(ge,{variant:"subtle",className:"text-2xs",children:t.parameters}),e.jsx("span",{className:K("text-2xs font-medium capitalize",r[t.tier]||"text-text-3"),children:t.tier})]}),e.jsxs("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:[SQ(t.sizeBytes)," · ctx ",(t.contextWindow||0).toLocaleString()," · ",t.category,t.repoId&&e.jsxs("span",{className:"text-text-4",children:[" · ",t.repoId]})]})]}),e.jsx("button",{onClick:async()=>{c(!0),await a(t.id),c(!1)},disabled:s,className:"p-1.5 rounded-md text-text-4 hover:text-red-400 hover:bg-red-400/10 transition-colors",children:s?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(wt,{size:14})})]})}function vQe({result:t,onExpand:a,expanded:s}){var c;return e.jsxs("button",{onClick:()=>a(s?null:t.id),className:"w-full text-left px-4 py-3 bg-surface-1 border border-border-subtle rounded-lg hover:border-accent/30 transition-colors cursor-pointer",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate flex-1",children:t.name}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:t.author}),s?e.jsx(zt,{size:14,className:"text-text-3"}):e.jsx(Xt,{size:14,className:"text-text-3"})]}),e.jsxs("div",{className:"text-2xs text-text-3 font-sans mt-0.5 flex gap-3",children:[e.jsxs("span",{children:[(c=t.downloads)==null?void 0:c.toLocaleString()," downloads"]}),e.jsxs("span",{children:[t.likes," likes"]})]})]})}function bQe({repoId:t,onDownload:a,systemRamGb:s}){const[c,r]=O.useState(null),[l,u]=O.useState(!0),[p,f]=O.useState(null),x=va();O.useEffect(()=>{u(!0),X.get(`/models/${t}/files`).then(y=>r(y.files||[])).catch(()=>x.error("Failed to load model files")).finally(()=>u(!1))},[t]);async function g(y){f(y.filename);try{await X.post("/models/download",{repoId:t,filename:y.filename}),x.success(`Downloading ${y.filename}`),a==null||a(y.filename)}catch(k){x.error(k.message)}f(null)}return l?e.jsx("div",{className:"py-3 px-4 text-2xs text-text-4 font-sans",children:"Loading quantization variants..."}):c!=null&&c.length?e.jsx("div",{className:"pl-6 pr-4 pb-2 space-y-1.5",children:c.map(y=>{const k=!y.estimatedRamGb||!s||y.estimatedRamGb<=s,b=y.estimatedRamGb&&s&&y.estimatedRamGb>s*.8&&k;return e.jsxs("div",{className:K("flex items-center gap-2 py-1.5 px-3 rounded-md text-xs font-sans",k?"bg-surface-2":"bg-red-500/5 border border-red-500/15"),children:[e.jsx("span",{className:"font-mono text-text-1 truncate flex-1",children:y.filename}),y.quantization&&e.jsx(ge,{variant:"subtle",className:"text-2xs",children:y.quantization}),e.jsx("span",{className:"text-text-2 text-2xs w-16 text-right",children:SQ(y.size)}),y.estimatedRamGb&&e.jsxs("span",{className:K("text-2xs w-20 text-right font-medium",k?b?"text-yellow-400":"text-green-400":"text-red-400"),children:["~",y.estimatedRamGb," GB RAM"]}),!k&&e.jsx("span",{className:"text-2xs text-red-400 font-medium",children:"too large"}),e.jsx("button",{onClick:()=>g(y),disabled:p===y.filename||!k,className:K("p-1 rounded transition-colors",k?"text-accent hover:bg-accent/10":"text-text-4 cursor-not-allowed","disabled:opacity-40"),children:p===y.filename?e.jsx(ze,{size:13,className:"animate-spin"}):e.jsx(Oa,{size:13})})]},y.filename)})}):e.jsx("div",{className:"py-3 px-4 text-2xs text-text-4 font-sans",children:"No GGUF files found in this repo."})}function wQe({model:t,systemRamGb:a,onPull:s,pulling:c,isInstalled:r}){const l={light:"text-green-400",medium:"text-blue-400",heavy:"text-orange-400"},u={code:"{}",general:"AI"},p=a?Math.round((1-t.ramGb/a)*100):null;return e.jsxs("div",{className:K("flex items-center gap-3 px-4 py-3 border rounded-lg transition-colors",r?"bg-success/5 border-success/20":"bg-surface-1 border-border-subtle hover:border-accent/20"),children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-surface-3 flex items-center justify-center text-xs font-mono text-text-2 flex-shrink-0",children:u[t.category]||"AI"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate",children:t.name}),e.jsx("span",{className:K("text-2xs font-semibold capitalize",l[t.tier]),children:t.tier}),r&&e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(Ve,{size:8})," Installed"]})]}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:t.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-1 text-2xs font-sans",children:[e.jsxs("span",{className:"text-text-2",children:[t.sizeGb," GB download"]}),e.jsxs("span",{className:"text-green-400 font-medium",children:[t.ramGb," GB RAM"]}),p!==null&&e.jsxs("span",{className:"text-text-4",children:[p,"% headroom"]})]})]}),r?e.jsx("span",{className:"text-xs text-success font-sans font-medium px-3 py-1.5",children:"Ready"}):e.jsxs("button",{onClick:()=>s(t.id),disabled:c===t.id,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-sans font-medium bg-accent/10 text-accent hover:bg-accent/20 transition-colors cursor-pointer disabled:opacity-40",children:[c===t.id?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(Oa,{size:12}),"Pull"]})]})}function MQe(){const[t,a]=O.useState("recommended"),[s,c]=O.useState(""),[r,l]=O.useState([]),[u,p]=O.useState(!1),[f,x]=O.useState([]),[g,y]=O.useState([]),[k,b]=O.useState([]),[j,w]=O.useState(null),[S,M]=O.useState(null),[$,C]=O.useState(null),[_,P]=O.useState([]),L=va(),A=O.useCallback(()=>{X.get("/models/installed").then(ne=>{x(ne.models||[])}).catch(()=>{})},[]),z=O.useCallback(()=>{X.get("/providers/ollama/models").then(ne=>{P((ne.installed||[]).map(oe=>oe.id))}).catch(()=>{})},[]);O.useEffect(()=>{X.get("/providers/ollama/hardware").then(w).catch(()=>{}),X.get("/models/recommended").then(ne=>{y(ne.models||[]),!j&&ne.hardware&&w(ne.hardware)}).catch(()=>{}),A(),z()},[A,z]);async function Y(ne){C(ne);try{await X.post("/providers/ollama/pull",{model:ne}),L.success(`${ne} ready to use`),A(),z(),P(oe=>[...oe,ne])}catch(oe){L.error(`Pull failed: ${oe.message}`)}C(null)}O.useEffect(()=>{const ne=q.subscribe((R,I)=>{}),oe=setInterval(()=>{X.get("/models/downloads").then(b).catch(()=>{})},2e3);return()=>{ne(),clearInterval(oe)}},[]),O.useEffect(()=>{function ne(R){try{const I=JSON.parse(R.data);I.type==="model:download:progress"&&b(T=>{const Z=T.findIndex(J=>J.filename===I.data.filename);if(Z>=0){const J=[...T];return J[Z]=I.data,J}return[...T,I.data]}),I.type==="model:download:complete"&&(b(T=>T.filter(Z=>Z.filename!==I.data.filename)),A(),L.success(`${I.data.filename} downloaded`)),I.type==="model:download:error"&&(b(T=>T.filter(Z=>Z.filename!==I.data.filename)),L.error(`Download failed: ${I.data.error}`))}catch{}}const oe=q.getState()._ws;return oe&&oe.addEventListener("message",ne),()=>{oe&&oe.removeEventListener("message",ne)}},[A,L]);async function V(){if(s.trim()){p(!0),a("search");try{const ne=await X.get(`/models/search?q=${encodeURIComponent(s.trim())}`);l(ne)}catch(ne){L.error(ne.message)}p(!1)}}async function se(ne){try{await X.delete(`/models/${ne}`),x(oe=>oe.filter(R=>R.id!==ne)),L.success("Model deleted")}catch(oe){L.error(oe.message)}}return e.jsxs("div",{className:"h-full flex flex-col bg-surface-0",children:[e.jsxs("div",{className:"flex-shrink-0 px-5 pt-4 pb-3 border-b border-border space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-base font-bold font-sans text-text-0",children:"Local Models"}),e.jsxs(ge,{variant:"subtle",className:"text-2xs",children:[f.length," installed"]})]}),e.jsx(gQe,{hardware:j}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Zt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:s,onChange:ne=>c(ne.target.value),onKeyDown:ne=>ne.key==="Enter"&&V(),placeholder:"Search HuggingFace for GGUF models...",className:"w-full h-8 pl-9 pr-3 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsx(he,{onClick:V,disabled:u,size:"sm",variant:"accent",children:u?e.jsx(ze,{size:14,className:"animate-spin"}):"Search"})]}),e.jsx("div",{className:"flex gap-1",children:[{id:"recommended",label:`Recommended (${g.length})`},{id:"installed",label:`Installed (${f.length})`},{id:"search",label:`Search (${r.length})`}].map(ne=>e.jsx("button",{onClick:()=>a(ne.id),className:K("px-3 py-1 rounded-md text-xs font-sans font-medium transition-colors cursor-pointer",t===ne.id?"bg-accent/12 text-accent":"text-text-3 hover:text-text-1 hover:bg-surface-3"),children:ne.label},ne.id))})]}),k.length>0&&e.jsxs("div",{className:"px-5 py-3 border-b border-border space-y-2",children:[e.jsx("div",{className:"text-xs font-sans font-semibold text-text-2",children:"Downloading"}),k.map(ne=>e.jsx(OQe,{download:ne},ne.filename))]}),e.jsx(It,{className:"flex-1",children:e.jsxs("div",{className:"px-5 py-4 space-y-2",children:[t==="recommended"&&e.jsx(e.Fragment,{children:g.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(tn,{size:40,className:"mx-auto text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"Detecting hardware..."}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Make sure Ollama is installed so we can check your system."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs text-text-3 font-sans mb-2",children:["Top models for your system (",(j==null?void 0:j.totalRamGb)||"?"," GB RAM). Click Pull to download via Ollama."]}),g.map(ne=>{const oe=ne.id.split(":")[0],R=_.some(I=>I===ne.id||I.startsWith(oe+":")||I===oe);return e.jsx(wQe,{model:ne,systemRamGb:j==null?void 0:j.totalRamGb,onPull:Y,pulling:$,isInstalled:R},ne.id)})]})}),t==="installed"&&e.jsx(e.Fragment,{children:f.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(wn,{size:40,className:"mx-auto text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"No local models yet"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Search HuggingFace to download GGUF models, or pull models via Ollama."})]}):f.map(ne=>e.jsx(kQe,{model:ne,onDelete:se},ne.id))}),t==="search"&&e.jsx(e.Fragment,{children:u?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ze,{size:24,className:"mx-auto text-accent animate-spin mb-3"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Searching HuggingFace..."})]}):r.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Zt,{size:40,className:"mx-auto text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"Search for GGUF models"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:'Try "qwen coder", "deepseek", "codestral", "llama"'})]}):r.map(ne=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(vQe,{result:ne,expanded:S===ne.id,onExpand:M}),S===ne.id&&e.jsx(bQe,{repoId:ne.id,onDownload:()=>A(),systemRamGb:j==null?void 0:j.totalRamGb})]},ne.id))})]})})]})}function jQe(t){switch(t){case"established":return e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(aa,{status:"running",size:"sm"})," Connected"]});case"connecting":return e.jsx(ge,{variant:"warning",className:"text-2xs",dot:"pulse",children:"Connecting"});case"error":return e.jsx(ge,{variant:"danger",className:"text-2xs",children:"Error"});default:return e.jsx(ge,{variant:"default",className:"text-2xs",children:"Unknown"})}}function SQe({onOpenWizard:t}){const a=q(f=>f.federation.connections),s=q(f=>f.federation.peers),c=q(f=>f.sendPouch),[r,l]=O.useState(null),u=s.length>0?s:a;async function p(f){l(f);try{await c(f,{type:"ping"})}catch{}l(null)}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Tt,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Connected Peers"}),u.length>0&&e.jsx(ge,{variant:"success",className:"text-2xs",children:u.length})]}),e.jsxs(he,{size:"sm",variant:"primary",onClick:t,className:"h-7 text-2xs gap-1.5",children:[e.jsx(rt,{size:11}),"Pair New Peer"]})]}),u.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-8 text-center",children:[e.jsx(Zo,{size:20,className:"text-text-4 mx-auto mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mb-1",children:"No peers connected"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mb-3",children:"Pair with a remote Groove daemon to share agents and coordinate work."}),e.jsxs(he,{size:"sm",variant:"outline",onClick:t,className:"h-7 text-2xs gap-1.5",children:[e.jsx(rt,{size:11}),"Pair Your First Peer"]})]}):e.jsx("div",{className:"grid gap-2",children:u.map(f=>{const x=f.peerId||f.ip||f.id,g=f.name||f.peerId||"Unknown Peer",y=f.state||f.status||"unknown",k=f.ip||f.address||"",b=f.latency;return e.jsxs("div",{className:"rounded-md border border-border-subtle bg-surface-1 p-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-accent/10 flex-shrink-0 mt-0.5",children:e.jsx(Tt,{size:14,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:g}),jQe(y)]}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3",children:[k&&e.jsxs("span",{className:"font-mono truncate",children:[k,f.port?`:${f.port}`:""]}),b!=null&&e.jsxs("span",{className:"flex items-center gap-1 font-sans",children:[e.jsx(j1,{size:9,className:K(b<100?"text-success":b<300?"text-warning":"text-danger")}),b,"ms"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-3 pt-2.5 border-t border-border-subtle",children:[e.jsxs(he,{size:"sm",variant:"ghost",className:"h-6 text-2xs gap-1 text-text-2",children:[e.jsx(ka,{size:10}),"Details"]}),e.jsxs(he,{size:"sm",variant:"ghost",className:"h-6 text-2xs gap-1 text-text-2",disabled:r===x,onClick:()=>p(x),children:[e.jsx(Zs,{size:10}),"Send Pouch"]}),e.jsxs(he,{size:"sm",variant:"ghost",className:"h-6 text-2xs gap-1 text-danger/70 hover:text-danger ml-auto",children:[e.jsx(M1,{size:10}),"Disconnect"]})]})]},x)})})]})}const NQe=["All","Sent","Received"];function _Qe(){const t=q(l=>l.federation.pouchLog),[a,s]=O.useState("All"),r=[...a==="All"?t:t.filter(l=>l.direction===a.toLowerCase())].reverse().slice(0,200);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Nn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Activity"}),t.length>0&&e.jsx(ge,{variant:"default",className:"text-2xs",children:t.length})]}),e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:NQe.map(l=>e.jsx("button",{onClick:()=>s(l),className:K("px-2.5 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",a===l?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:l},l))})]}),r.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-6 text-center",children:[e.jsx(Nn,{size:18,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:a==="All"?"No diplomatic pouches exchanged yet.":`No ${a.toLowerCase()} pouches.`})]}):e.jsx(It,{className:"max-h-80",children:e.jsxs("div",{className:"relative pl-5",children:[e.jsx("div",{className:"absolute left-[7px] top-2 bottom-2 w-px bg-border-subtle"}),r.map((l,u)=>{const p=l.direction==="sent";return e.jsxs("div",{className:"relative flex items-start gap-3 pb-3 last:pb-0",children:[e.jsx("div",{className:K("absolute left-[-13px] top-1.5 w-2.5 h-2.5 rounded-full border-2 border-surface-2 z-10",p?"bg-accent":"bg-success")}),e.jsxs("div",{className:"flex items-center gap-2 flex-1 rounded-md bg-surface-1 px-3 py-2 min-w-0",children:[p?e.jsx(d2,{size:11,className:"text-accent flex-shrink-0"}):e.jsx(l2,{size:11,className:"text-success flex-shrink-0"}),e.jsx("span",{className:"text-2xs text-text-1 font-sans truncate flex-1",children:l.contractType||l.type||"message"}),e.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-24",children:l.peerId||""}),e.jsx("span",{className:"text-2xs text-text-3 font-sans flex-shrink-0",children:gt(l.timestamp||l.ts)})]})]},l.id||u)})]})})]})}const $Qe=[{label:"Connect",icon:Zo},{label:"Verify",icon:Tt},{label:"Paired",icon:Ve}];function CQe({current:t}){return e.jsx("div",{className:"flex items-center justify-center gap-2 mb-6",children:$Qe.map((a,s)=>{const c=s<t,r=s===t,l=a.icon;return e.jsxs("div",{className:"flex items-center gap-2",children:[s>0&&e.jsx("div",{className:K("w-8 h-px",c?"bg-accent":"bg-border-subtle")}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:K("w-6 h-6 rounded-full flex items-center justify-center transition-colors",c?"bg-accent text-white":r?"bg-accent/15 text-accent border border-accent/30":"bg-surface-3 text-text-4"),children:c?e.jsx(Ve,{size:12}):e.jsx(l,{size:12})}),e.jsx("span",{className:K("text-2xs font-semibold font-sans",r?"text-text-0":c?"text-accent":"text-text-4"),children:a.label})]})]},a.label)})})}function QQe({open:t,onOpenChange:a}){const s=q(V=>V.addToWhitelist),c=q(V=>V.fetchFederationStatus),[r,l]=O.useState(0),[u,p]=O.useState(""),[f,x]=O.useState("31415"),[g,y]=O.useState(""),[k,b]=O.useState(!1),[j,w]=O.useState(null),[S,M]=O.useState(!1),[$,C]=O.useState(null),[_,P]=O.useState(null);function L(){l(0),p(""),x("31415"),y(""),b(!1),w(null),M(!1),C(null),P(null)}function A(V){V||L(),a(V)}async function z(){b(!0),w(null),C(null);try{const V=`${u.trim()}:${f||"31415"}`,se=await fetch(`http://localhost:31415/api/federation/test?target=${encodeURIComponent(V)}`);if(se.ok){const ne=await se.json();w("reachable"),P(ne)}else w("unreachable")}catch{w("unreachable")}b(!1)}async function Y(){M(!0),C(null);try{await s(u.trim(),parseInt(f,10)||31415,g.trim()||void 0),await c(),l(2)}catch(V){C(V.message||"Failed to pair with peer")}M(!1)}return e.jsx(qa,{open:t,onOpenChange:A,children:e.jsx(Ia,{title:"Pair New Peer",description:"Connect to a remote Groove daemon",children:e.jsxs("div",{className:"px-5 py-5",children:[e.jsx(CQe,{current:r}),r===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(ns,{label:"Friendly Name",placeholder:"e.g. Production Server",value:g,onChange:V=>y(V.target.value)}),e.jsxs("div",{className:"grid grid-cols-[1fr,100px] gap-2",children:[e.jsx(ns,{label:"IP / Hostname",placeholder:"192.168.1.100",value:u,onChange:V=>p(V.target.value),mono:!0}),e.jsx(ns,{label:"Port",placeholder:"31415",value:f,onChange:V=>x(V.target.value),mono:!0})]}),j==="reachable"&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-success/10 border border-success/20 px-3 py-2",children:[e.jsx(j1,{size:13,className:"text-success"}),e.jsx("span",{className:"text-2xs text-success font-sans font-medium",children:"Peer is reachable"})]}),j==="unreachable"&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-danger/10 border border-danger/20 px-3 py-2",children:[e.jsx(vt,{size:13,className:"text-danger"}),e.jsx("span",{className:"text-2xs text-danger font-sans font-medium",children:"Could not reach peer — check IP and port"})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxs(he,{size:"sm",variant:"ghost",disabled:!u.trim()||k,onClick:z,className:"h-8 text-xs gap-1.5",children:[k?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(j1,{size:12}),"Test Reachability"]}),e.jsxs(he,{size:"sm",variant:"primary",disabled:!u.trim(),onClick:()=>l(1),className:"h-8 text-xs gap-1.5 ml-auto",children:["Continue",e.jsx(h1,{size:12})]})]})]}),r===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-md border border-border-subtle bg-surface-0 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-md bg-accent/10",children:e.jsx(Tt,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-text-0 font-sans",children:g||"Remote Peer"}),e.jsxs("p",{className:"text-2xs text-text-3 font-mono",children:[u,":",f||"31415"]})]})]}),_&&e.jsxs("div",{className:"space-y-1.5 pt-2 border-t border-border-subtle",children:[_.version&&e.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:"Version"}),e.jsx("span",{className:"text-text-1 font-mono",children:_.version})]}),_.peerId&&e.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:"Peer ID"}),e.jsx("span",{className:"text-text-1 font-mono truncate max-w-40",children:_.peerId})]}),_.agents!=null&&e.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:"Active Agents"}),e.jsx("span",{className:"text-text-1",children:_.agents})]})]})]}),$&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-danger/10 border border-danger/20 px-3 py-2",children:[e.jsx(vt,{size:13,className:"text-danger"}),e.jsx("span",{className:"text-2xs text-danger font-sans",children:$})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx(he,{size:"sm",variant:"ghost",onClick:()=>l(0),className:"h-8 text-xs",children:"Back"}),e.jsxs(he,{size:"sm",variant:"primary",disabled:S,onClick:Y,className:"h-8 text-xs gap-1.5 ml-auto",children:[S?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(Zo,{size:12}),"Confirm Pairing"]})]})]}),r===2&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-success/15 mx-auto",children:e.jsx(Ve,{size:20,className:"text-success"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans mb-1",children:"Peer Paired Successfully"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:[g||u," has been added to your federation whitelist."]})]}),e.jsx("div",{className:"rounded-md border border-border-subtle bg-surface-0 p-3 text-left",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-accent/10",children:e.jsx(Tt,{size:14,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans block truncate",children:g||"Remote Peer"}),e.jsxs("span",{className:"text-2xs text-text-3 font-mono",children:[u,":",f||"31415"]})]}),e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(aa,{status:"running",size:"sm"}),"Whitelisted"]})]})}),e.jsx(he,{size:"sm",variant:"primary",onClick:()=>A(!1),className:"h-8 text-xs",children:"Done"})]})]})})})}function LQe(t){switch(t){case"mutual":return e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(aa,{status:"running",size:"sm"})," Mutual"]});case"connected":return e.jsx(ge,{variant:"info",className:"text-2xs",children:"Connected"});default:return e.jsx(ge,{variant:"default",className:"text-2xs",children:"Waiting"})}}function zQe(){const t=q(M=>M.federation.whitelist),a=q(M=>M.addToWhitelist),s=q(M=>M.removeFromWhitelist),[c,r]=O.useState(!1),[l,u]=O.useState(""),[p,f]=O.useState("31415"),[x,g]=O.useState(""),[y,k]=O.useState(!1),[b,j]=O.useState("");async function w(M){if(M.preventDefault(),!!l.trim()){k(!0);try{await a(l.trim(),parseInt(p,10)||31415,x.trim()||void 0),u(""),f("31415"),g(""),r(!1)}catch{}k(!1)}}const S=O.useMemo(()=>{if(!b.trim())return t;const M=b.toLowerCase();return t.filter($=>{const C=typeof $=="string"?$:$.ip,_=typeof $=="object"?$.name:"";return(C==null?void 0:C.toLowerCase().includes(M))||(_==null?void 0:_.toLowerCase().includes(M))})},[t,b]);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(nn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Whitelist"}),t.length>0&&e.jsx(ge,{variant:"default",className:"text-2xs",children:t.length})]}),e.jsx(he,{size:"sm",variant:c?"ghost":"primary",onClick:()=>r(!c),className:"h-7 text-2xs gap-1.5",children:c?e.jsxs(e.Fragment,{children:[e.jsx(x2,{size:11})," Hide"]}):e.jsxs(e.Fragment,{children:[e.jsx(rt,{size:11})," Add Server"]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c&&e.jsxs("form",{onSubmit:w,className:"rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(rt,{size:12,className:"text-accent"})}),e.jsx("span",{className:"text-[13px] font-medium text-text-0 font-sans",children:"New Server"})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1 block",children:"Name"}),e.jsx(ns,{placeholder:"Server name",value:x,onChange:M=>g(M.target.value),className:"h-7 text-xs"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1 block",children:"IP Address"}),e.jsx(ns,{placeholder:"100.64.0.2",value:l,onChange:M=>u(M.target.value),mono:!0,className:"h-7 text-xs"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1 block",children:"Port"}),e.jsx(ns,{placeholder:"31415",value:p,onChange:M=>f(M.target.value),mono:!0,className:"h-7 text-xs w-28"})]}),e.jsx("div",{className:"pt-1",children:e.jsxs(he,{type:"submit",variant:"primary",size:"sm",disabled:y||!l.trim(),className:"h-7 text-2xs gap-1",children:[y?e.jsx(ze,{size:11,className:"animate-spin"}):e.jsx(rt,{size:11}),"Add to Whitelist"]})})]})]}),e.jsxs("div",{className:K("rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5",!c&&"col-span-2"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(At,{size:12,className:"text-accent"})}),e.jsx("span",{className:"text-[13px] font-medium text-text-0 font-sans",children:"Servers"}),t.length>=5&&e.jsxs("div",{className:"relative ml-auto",children:[e.jsx(Zt,{size:10,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"text",placeholder:"Filter…",value:b,onChange:M=>j(M.target.value),className:"h-6 pl-6 pr-2 w-32 text-2xs font-sans bg-surface-0 border border-border-subtle rounded-md text-text-0 placeholder:text-text-4 focus:outline-none focus:border-accent"})]})]}),S.length===0&&t.length===0?e.jsxs("div",{className:"px-2 py-4 text-center",children:[e.jsx(At,{size:16,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"No peers whitelisted yet."})]}):S.length===0?e.jsx("div",{className:"text-2xs text-text-4 font-sans py-3 text-center",children:"No servers match your filter."}):e.jsx("div",{className:"space-y-1.5",children:S.map(M=>{const $=typeof M=="string"?M:M.ip,C=typeof M=="object"?M.name:null,_=typeof M=="object"?M.status:"waiting",P=typeof M=="object"?M.port:null;return e.jsxs("div",{className:"flex items-center gap-2.5 px-2.5 py-2 rounded-md bg-surface-0 border border-border-subtle",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[C&&e.jsx("span",{className:"text-xs font-sans font-medium text-text-0 block truncate",children:C}),e.jsxs("span",{className:K("font-mono truncate block",C?"text-2xs text-text-3":"text-xs text-text-1"),children:[$,P?`:${P}`:""]})]}),LQe(_),e.jsx("button",{onClick:()=>s($),className:"p-1 rounded text-text-4 hover:text-danger hover:bg-danger/10 cursor-pointer transition-colors flex-shrink-0",title:"Remove",children:e.jsx(wt,{size:11})})]},$)})})]})]})]})}function TQe(){const t=q(a=>a.federation.ambassadors);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(sn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Ambassadors"}),t.length>0&&e.jsx(ge,{variant:"info",className:"text-2xs",children:t.length})]}),t.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-6 text-center",children:[e.jsx(sn,{size:18,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"No active ambassadors. Ambassadors appear when agents are shared across federated peers."})]}):e.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(a=>e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(aa,{status:a.status==="active"?"running":"stopped",size:"sm"}),e.jsx("span",{className:"text-xs font-sans font-medium text-text-0 truncate flex-1",children:a.name||a.agentId||a.id}),a.role&&e.jsx(ge,{variant:"purple",className:"text-2xs",children:a.role})]}),e.jsxs("div",{className:"flex items-center justify-between text-2xs",children:[a.peerId?e.jsx("span",{className:"text-text-3 font-mono truncate max-w-28",children:a.peerId}):e.jsx("span",{className:"text-text-4 font-sans",children:"Local"}),e.jsx(ge,{variant:a.status==="active"?"success":"default",className:"text-2xs",children:a.status||"idle"})]})]},a.id||a.agentId))})]})}function PQe(){const t=q(r=>r.fetchFederationStatus),a=q(r=>r.fetchPouchLog),[s,c]=O.useState(!1);return O.useEffect(()=>{t(),a()},[]),e.jsxs("div",{children:[e.jsxs(MA,{defaultValue:"whitelist",children:[e.jsxs(jA,{className:"mb-4",children:[e.jsx(kn,{value:"whitelist",className:"text-xs px-3 py-1.5",children:"Whitelist"}),e.jsx(kn,{value:"peers",className:"text-xs px-3 py-1.5",children:"Peers"}),e.jsx(kn,{value:"ambassadors",className:"text-xs px-3 py-1.5",children:"Ambassadors"}),e.jsx(kn,{value:"activity",className:"text-xs px-3 py-1.5",children:"Activity"})]}),e.jsx(vn,{value:"whitelist",children:e.jsx(zQe,{})}),e.jsx(vn,{value:"peers",children:e.jsx(SQe,{onOpenWizard:()=>c(!0)})}),e.jsx(vn,{value:"ambassadors",children:e.jsx(TQe,{})}),e.jsx(vn,{value:"activity",children:e.jsx(_Qe,{})})]}),e.jsx(QQe,{open:s,onOpenChange:c})]})}const vX={community:{heading:"Get Groove Desktop",cta:"Download",icon:Oa,action:()=>sQ("https://groovedev.ai/download")},"community-electron":{heading:"Pro Feature",cta:"Upgrade to Pro",icon:bt,action:()=>q.getState().setUpgradeModalOpen(!0)},"sign-in":{heading:"Sign in to unlock",cta:"Sign in",icon:Do,action:()=>q.getState().marketplaceLogin()},subscribe:{heading:"Pro Feature",cta:"Upgrade to Pro",icon:bt,action:()=>q.getState().setUpgradeModalOpen(!0)}};function Eh({feature:t,description:a,variant:s="community"}){const c=s==="community"&&Go()?"community-electron":s,r=vX[c]||vX.community,l=r.icon;return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1/50 px-5 py-6 text-center",children:[e.jsx("div",{className:"mx-auto mb-3 flex h-10 w-10 items-center justify-center rounded-full bg-accent/10",children:e.jsx(Vd,{size:18,className:"text-accent"})}),e.jsx("h3",{className:"text-sm font-semibold text-text-1 font-sans",children:r.heading}),e.jsx("p",{className:"mt-1.5 text-2xs text-text-3 font-sans",children:t}),e.jsx("p",{className:"mt-1 text-2xs text-text-4 font-sans max-w-xs mx-auto",children:a}),e.jsxs("button",{onClick:r.action,className:"mt-4 inline-flex items-center gap-1.5 h-7 px-4 rounded-full bg-accent/15 text-accent text-xs font-semibold font-sans hover:bg-accent/25 transition-colors cursor-pointer",children:[e.jsx(l,{size:13}),r.cta]})]})}function AQe({feature:t,featureKey:a,description:s,children:c}){const r=q(p=>p.marketplaceAuthenticated),l=q(p=>p.subscription);if(q(p=>p.edition)!=="pro"){const p=Go()?"community-electron":"community";return e.jsx(Eh,{feature:t,description:s,variant:p})}return r?l!=null&&l.active?a&&(l==null?void 0:l.plan)!=="pro"&&!(l.features||[]).includes(a)?e.jsx(Eh,{feature:t,description:s,variant:"subscribe"}):c:e.jsx(Eh,{feature:t,description:s,variant:"subscribe"}):e.jsx(Eh,{feature:t,description:s,variant:"sign-in"})}function qQe(){const t=q(a=>a.fetchFederationStatus);return O.useEffect(()=>{t()},[]),e.jsxs("div",{className:"flex flex-col h-full bg-surface-0",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-border",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center",children:e.jsx(At,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-sm font-semibold text-text-0 font-sans",children:"Federation"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Connect to remote Groove daemons"})]})]}),e.jsx(It,{className:"flex-1",children:e.jsx("div",{className:"max-w-2xl mx-auto px-6 py-5",children:e.jsx(AQe,{feature:"Federation",featureKey:"federation",description:"Daemon-to-daemon federation over Tailscale mesh for multi-machine agent coordination",children:e.jsx(PQe,{})})})})]})}function OB({children:t,className:a,hover:s,...c}){return e.jsx("div",{className:K("rounded-md border border-border bg-surface-1",s&&"hover:border-accent/50 hover:bg-surface-2 transition-all duration-150 cursor-pointer",a),...c,children:t})}const IQe={beginner:"success",intermediate:"warning",advanced:"danger"};function RQe(t){if(!t)return wn;const a=t.replace(/(^|-)(\w)/g,(s,c,r)=>r.toUpperCase());return dQ[a]||dQ[t]||wn}function VQe({toy:t,onClick:a}){const s=RQe(t.icon);return e.jsxs(OB,{hover:!0,className:"group flex flex-col p-4 gap-3 transition-all duration-150 hover:scale-[1.02] hover:shadow-lg hover:shadow-black/20",onClick:()=>a(t),children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-accent",children:e.jsx(s,{size:20})}),e.jsx("div",{className:"flex-1 min-w-0 pt-0.5",children:e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans truncate pr-1",children:t.name})}),e.jsx(ge,{variant:"default",className:"flex-shrink-0 mt-0.5",children:t.category})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed line-clamp-2",children:t.description}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-auto flex-wrap",children:[t.custom&&e.jsx(ge,{variant:"accent",children:"Custom"}),e.jsx(ge,{variant:IQe[t.difficulty]||"default",children:t.difficulty||"beginner"}),e.jsx(ge,{variant:t.authType==="none"?"success":"warning",children:t.authType==="none"?"No Key Required":"API Key Required"})]})]})}function EQe(){return e.jsxs(OB,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-surface-4 animate-pulse"}),e.jsx("div",{className:"flex-1 space-y-2 pt-1",children:e.jsx("div",{className:"h-3.5 w-24 bg-surface-4 rounded animate-pulse"})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("div",{className:"h-5 w-16 bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-5 w-24 bg-surface-4 rounded animate-pulse"})]})]})}function XQe(t){if(!t)return wn;const a=t.replace(/(^|-)(\w)/g,(s,c,r)=>r.toUpperCase());return dQ[a]||dQ[t]||wn}function ZQe({toy:t,open:a,onClose:s}){var S,M;const[c,r]=O.useState(""),[l,u]=O.useState(!1),[p,f]=O.useState(null),[x,g]=O.useState(!1),y=va(),k=q($=>$.setActiveView);if(!t)return null;const b=XQe(t.icon),j=t.authType!=="none";async function w(){if(j&&!c.trim()){y.warning("API key required",`${t.name} needs an API key to work.`);return}g(!0);try{await X.post(`/toys/${t.id}/launch`,{apiKey:j?c.trim():void 0,starterPrompt:p||void 0}),y.success(`${t.name} launched`,"Team is spinning up — switching to agents view."),k("agents"),s()}catch($){y.error("Launch failed",$.message)}g(!1)}return e.jsx(FQ,{open:a,onOpenChange:$=>!$&&s(),children:e.jsxs(KQ,{title:t.name,width:440,children:[e.jsx(It,{className:"h-[calc(100%-65px)]",children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-accent",children:e.jsx(b,{size:24})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ge,{variant:t.authType==="none"?"success":"warning",children:t.authType==="none"?"Free":"Key Required"}),e.jsx(ge,{variant:"default",children:t.category})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed mt-2",children:t.description})]})]}),t.baseUrl&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"Base URL"}),e.jsx("code",{className:"text-xs text-accent font-mono bg-surface-3 px-2.5 py-1.5 rounded block truncate",children:t.baseUrl})]}),((S=t.sampleEndpoints)==null?void 0:S.length)>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"Endpoints"}),e.jsx("div",{className:"space-y-1",children:t.sampleEndpoints.map(($,C)=>{const _=typeof $=="string"?$:`${$.method||"GET"} ${$.path||""}`,P=_.indexOf(" "),L=P>0?_.slice(0,P):"GET",A=P>0?_.slice(P+1):_;return e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono text-text-2 bg-surface-3 px-2.5 py-1.5 rounded",children:[e.jsx(ge,{variant:"accent",className:"text-[9px] px-1 py-0",children:L}),e.jsx("span",{className:"truncate",children:A})]},C)})})]}),((M=t.starterPrompts)==null?void 0:M.length)>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"Starter Ideas"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.starterPrompts.map(($,C)=>e.jsx("button",{onClick:()=>f(p===$?null:$),className:`px-3 py-1.5 text-xs font-sans rounded-full cursor-pointer select-none transition-colors border ${p===$?"bg-accent/15 text-accent border-accent/25":"text-text-2 bg-surface-3 border-border-subtle hover:text-text-0 hover:border-border"}`,children:$},C))})]}),j&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:l?"text":"password",value:c,onChange:$=>r($.target.value),placeholder:`Enter your ${t.name} API key`,className:"w-full bg-surface-3 border border-border-subtle rounded px-3 py-2 text-xs text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:border-accent/50 pr-9"}),e.jsx("button",{onClick:()=>u(!l),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-1 cursor-pointer bg-transparent border-0 p-0.5",children:l?e.jsx(Jn,{size:14}):e.jsx(ka,{size:14})})]})]}),t.docsUrl&&e.jsxs("a",{href:t.docsUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-accent font-sans hover:underline",children:[e.jsx(Pt,{size:12}),"View Documentation"]})]})}),e.jsx("div",{className:"px-5 py-3 border-t border-border-subtle bg-surface-1",children:e.jsx(he,{variant:"primary",size:"lg",className:"w-full gap-2",onClick:w,disabled:x||j&&!c.trim(),children:x?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"}),"Launching..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ho,{size:14}),"Launch Team"]})})})]})})}const _s={input:"input",researching:"researching"};function DQe({open:t,onClose:a,onCreated:s}){const[c,r]=O.useState(""),[l,u]=O.useState(""),[p,f]=O.useState(_s.input),x=va();function g(){r(""),u(""),f(_s.input)}function y(){p!==_s.researching&&(g(),a())}async function k(){const b=c.trim();if(!b){x.warning("URL required","Paste an API documentation or reference URL.");return}f(_s.researching);try{const j=await X.post("/toys",{docsUrl:b,name:l.trim()||void 0});x.success("Toy created",`${j.name||"New toy"} is ready to launch.`),s==null||s(j),g(),a()}catch(j){x.error("Research failed",j.message),f(_s.input)}}return e.jsx(FQ,{open:t,onOpenChange:b=>!b&&y(),children:e.jsxs(KQ,{title:"New Toy",width:440,children:[e.jsx(It,{className:"h-[calc(100%-65px)]",children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[p===_s.input&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-accent/5 border border-accent/10",children:[e.jsx(bt,{size:16,className:"text-accent mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed",children:"Paste a docs URL and Groove's AI will research the API — endpoints, auth, data structures, rate limits — and build a reusable toy card you can launch anytime."})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"API Docs URL"}),e.jsxs("div",{className:"relative",children:[e.jsx(Zo,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"url",value:c,onChange:b=>r(b.target.value),placeholder:"https://api.example.com/docs",className:"w-full bg-surface-3 border border-border-subtle rounded pl-8 pr-3 py-2 text-xs text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:border-accent/50",onKeyDown:b=>b.key==="Enter"&&k(),autoFocus:!0})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:["Name ",e.jsx("span",{className:"text-text-4 normal-case tracking-normal",children:"(optional)"})]}),e.jsx("input",{type:"text",value:l,onChange:b=>u(b.target.value),placeholder:"Auto-detected from docs",className:"w-full bg-surface-3 border border-border-subtle rounded px-3 py-2 text-xs text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:border-accent/50",onKeyDown:b=>b.key==="Enter"&&k()})]})]}),p===_s.researching&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-accent/10 border border-accent/20 flex items-center justify-center",children:e.jsx(At,{size:24,className:"text-accent animate-pulse"})}),e.jsxs("div",{className:"text-center space-y-1.5",children:[e.jsx("p",{className:"text-sm font-semibold text-text-0 font-sans",children:"Researching API..."}),e.jsx("p",{className:"text-xs text-text-3 font-sans max-w-[260px]",children:"Reading documentation, mapping endpoints, and building your toy card. This takes 15–30 seconds."})]}),e.jsx(ze,{size:16,className:"text-accent animate-spin"})]})]})}),e.jsxs("div",{className:"px-5 py-3 border-t border-border-subtle bg-surface-1",children:[p===_s.input&&e.jsxs(he,{variant:"primary",size:"lg",className:"w-full gap-2",onClick:k,disabled:!c.trim(),children:[e.jsx(bt,{size:14}),"Research & Create"]}),p===_s.researching&&e.jsxs(he,{variant:"ghost",size:"lg",className:"w-full",disabled:!0,children:[e.jsx(ze,{size:14,className:"animate-spin mr-2"}),"AI is analyzing..."]})]})]})})}const UQe=["All","Space","Weather","Finance","Fun","Maps","Data"];function HQe(){const[t,a]=O.useState([]),[s,c]=O.useState(!0),[r,l]=O.useState(""),[u,p]=O.useState("All"),[f,x]=O.useState(null),[g,y]=O.useState(!1),k=q(M=>M.teams),b=O.useCallback(()=>{c(!0),X.get("/toys").then(M=>a(M.toys||M.items||(Array.isArray(M)?M:[]))).catch(()=>a([])).finally(()=>c(!1))},[]);O.useEffect(()=>{b()},[b]);const j=r.toLowerCase(),w=t.filter(M=>{var $,C,_;return!(u!=="All"&&(($=M.category)==null?void 0:$.toLowerCase())!==u.toLowerCase()||j&&!((C=M.name)!=null&&C.toLowerCase().includes(j))&&!((_=M.description)!=null&&_.toLowerCase().includes(j)))}),S=(k||[]).filter(M=>(M.name||"").startsWith("Toy:"));return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-shrink-0 px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx(m1,{size:18,className:"text-accent"}),e.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:"Toys"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:()=>y(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold font-sans rounded-full cursor-pointer select-none transition-colors bg-accent/15 text-accent border border-accent/25 hover:bg-accent/25",children:[e.jsx(rt,{size:13}),"New"]})]}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"Plug in an API and start building"})]}),e.jsxs("div",{className:"flex-shrink-0 px-5 pb-4 space-y-3",children:[e.jsxs("div",{className:"relative w-full max-w-sm",children:[e.jsx(Zt,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"text",value:r,onChange:M=>l(M.target.value),placeholder:"Search toys...",className:"w-full bg-surface-1 border border-border-subtle rounded pl-8 pr-3 py-1.5 text-xs text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:border-accent/50"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[UQe.map(M=>e.jsx("button",{onClick:()=>p(M),className:`px-3 py-1.5 text-xs font-semibold font-sans rounded-full cursor-pointer select-none transition-colors ${u===M?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1 border border-transparent hover:border-border-subtle"}`,children:M},M)),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-2xs text-text-4 font-mono",children:w.length})]})]}),e.jsx(It,{className:"flex-1 min-h-0",children:e.jsxs("div",{className:"px-5 pt-1 pb-5",children:[e.jsx("div",{className:"grid gap-3 grid-cols-[repeat(auto-fill,minmax(260px,1fr))]",children:s?Array.from({length:6}).map((M,$)=>e.jsx(EQe,{},$)):e.jsxs(e.Fragment,{children:[w.map(M=>e.jsx(VQe,{toy:M,onClick:x},M.id)),e.jsxs("button",{onClick:()=>y(!0),className:"flex flex-col items-center justify-center gap-2 p-4 rounded-xl border-2 border-dashed border-border-subtle text-text-4 hover:text-accent hover:border-accent/30 hover:bg-accent/5 transition-colors cursor-pointer min-h-[140px]",children:[e.jsx(rt,{size:20}),e.jsx("span",{className:"text-xs font-semibold font-sans",children:"Add API"})]})]})}),!s&&w.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No toys found. Try a different search or category."}),S.length>0&&e.jsxs("div",{className:"mt-8",children:[e.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[e.jsx(Ho,{size:12}),"Recent Toys (",S.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:S.map(M=>{var $;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(m1,{size:14,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:M.name}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:[(($=M.agents)==null?void 0:$.length)||0," agents"]})]}),e.jsx(ge,{variant:"accent",children:"Active"})]},M.id)})})]})]})}),e.jsx(ZQe,{toy:f,open:!!f,onClose:()=>x(null)}),e.jsx(DQe,{open:g,onClose:()=>y(!1),onCreated:()=>b()})]})}const bX=28;function BQe(t){return t>.9?ce.danger:t>.7?ce.warning:ce.success}function NQ(t){return t?(t/1024).toFixed(1):"0"}function o2({label:t,value:a,max:s,unit:c,nodeCount:r}){const l=s>0?Math.min(1,Math.max(0,a/s)):0,u=Math.round(l*bX),p=bX-u,f="│".repeat(u)+"─".repeat(p),x=BQe(l);let g,y;return c==="GB"?(g=NQ(a),y=NQ(s)):c==="cores"||c==="Mbps"?(g=Math.round(a),y=Math.round(s)):(g=a.toFixed(1),y=s.toFixed(1)),e.jsxs("div",{className:"flex items-center gap-2 font-mono text-xs leading-tight",children:[e.jsx("span",{className:"w-[40px] text-right text-text-3 uppercase text-2xs tracking-wider flex-shrink-0",children:t}),e.jsx("span",{className:"text-text-4",children:"["}),e.jsx("span",{style:{color:l>0?x:void 0},className:K("whitespace-pre",!l&&"text-text-4"),children:f}),e.jsx("span",{className:"text-text-4",children:"]"}),e.jsxs("span",{className:"text-text-1 tabular-nums whitespace-nowrap text-2xs",children:[g," / ",y," ",c]}),r!=null&&e.jsxs("span",{className:"text-text-4 text-2xs whitespace-nowrap",children:["(",r," nodes)"]})]})}function GQe({data:t,color:a=ce.accent,width:s=72,height:c=22}){if(!t||t.length<2)return e.jsx("div",{style:{width:s,height:c}});const r=t.map(g=>typeof g=="number"?g:g.v),l=Math.min(...r),p=Math.max(...r)-l||1,f=r.map((g,y)=>{const k=y/(r.length-1)*s,b=c-(g-l)/p*(c-2)-1;return`${k},${b}`}).join(" "),x=`net-${a.replace("#","")}`;return e.jsxs("svg",{width:s,height:c,className:"flex-shrink-0",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:x,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:a,stopOpacity:"0.2"}),e.jsx("stop",{offset:"100%",stopColor:a,stopOpacity:"0"})]})}),e.jsx("polygon",{points:`0,${c} ${f} ${s},${c}`,fill:`url(#${x})`}),e.jsx("polyline",{points:f,fill:"none",stroke:a,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}function WQe({label:t,value:a,color:s=ce.accent,hint:c,className:r}){return e.jsx("div",{className:K("flex items-center gap-2.5 px-3 py-2.5 min-w-0 bg-surface-1",r),children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5 truncate flex items-center gap-1",children:[t,c&&e.jsx($1,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:c}),side:"bottom",children:e.jsx(Wt,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),e.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:a})]})})}const YQe=256*1024,FQe=128*1024,KQe=128,JQe=4,eLe=[{key:"globalSessions",label:"Sessions",color:ce.accent},{key:"mySessions",label:"My Sessions",color:ce.info},{key:"nodeCount",label:"Nodes",color:ce.purple},{key:"avgLoad",label:"Load",color:ce.warning},{key:"myLoad",label:"My Load",color:ce.success}];function tLe({snapshots:t}){const a=t&&t.length>=2;return e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5",children:"Trends"}),a?eLe.map(s=>{const c=t.map(u=>({v:u[s.key]??0})),r=c[c.length-1].v,l=Number.isInteger(r)?r:r.toFixed(2);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-[72px] text-2xs font-mono text-text-3 uppercase truncate flex-shrink-0",children:s.label}),e.jsx(GQe,{data:c,color:s.color,width:140,height:24}),e.jsx("span",{className:"text-2xs font-mono text-text-1 tabular-nums flex-shrink-0",children:l})]},s.key)}):e.jsx("div",{className:"text-2xs font-mono text-text-4",children:"Collecting data…"})]})}function aLe({node:t,compute:a}){var f;if(!t||!t.active)return e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5",children:"Your Node"}),e.jsx("div",{className:"text-2xs font-mono text-text-4",children:"Node idle"})]});const s=t.layers?`Layers ${t.layers} / 36`:"Unassigned",c=t.model||"Qwen/Qwen3-4B",r=a.totalBandwidthMbps?`${Math.round(a.totalBandwidthMbps)} Mbps`:"— Mbps",l=(f=t.hardware)==null?void 0:f.memory,u=l&&a.totalRamMb>0?`${(l/a.totalRamMb*100).toFixed(1)}%`:"—",p=[{label:"Layers",value:s},{label:"Model",value:c},{label:"Sessions",value:t.sessions??0},{label:"Bandwidth",value:r},{label:"RAM Share",value:u}];return e.jsxs("div",{className:"flex flex-col gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5",children:"Your Node"}),p.map(x=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider leading-none",children:x.label}),e.jsx("div",{className:"text-xs font-mono text-text-1 truncate leading-tight",children:x.value})]},x.label))]})}function nLe({compute:t,allZero:a,avgGpuUtil:s}){const c=q(l=>l.networkSnapshots),r=q(l=>l.networkNode);return e.jsxs("div",{className:"bg-surface-1 border-b border-border px-4 py-2.5",style:{display:"grid",gridTemplateColumns:"1fr 1.4fr 1fr",gap:"1.5rem"},children:[e.jsx("div",{className:"flex flex-col gap-0.5 min-w-0",children:a?e.jsx("div",{className:"text-2xs font-mono text-text-4",children:"Waiting for network data..."}):e.jsxs(e.Fragment,{children:[e.jsx(o2,{label:"RAM",value:t.totalRamMb,max:YQe,unit:"GB",nodeCount:t.totalNodes}),e.jsx(o2,{label:"VRAM",value:t.totalVramMb,max:FQe,unit:"GB",nodeCount:t.totalNodes}),e.jsx(o2,{label:"CPU",value:t.totalCpuCores,max:KQe,unit:"cores"}),e.jsx(o2,{label:"GPU%",value:s,max:100,unit:"%"}),e.jsx(o2,{label:"LOAD",value:t.avgLoad,max:JQe,unit:""})]})}),e.jsx(tLe,{snapshots:c}),e.jsx(aLe,{node:r,compute:t})]})}const sLe=O.memo(function(){const a=q(y=>y.networkCompute),s=q(y=>y.networkStatus.nodes||[]),c=q(y=>y.networkStatus.models||[]),r=!a.totalRamMb&&!a.totalVramMb&&!a.totalCpuCores,l=s.filter(y=>y.status==="active"),u=l.length>0?l.reduce((y,k)=>y+(k.gpu_utilization_pct||0),0)/l.length:0,p=u>80?ce.danger:u>50?ce.warning:ce.success,f=a.avgLoad>2?ce.danger:a.avgLoad>1?ce.warning:ce.success,x=c.length>0?typeof c[0]=="string"?c[0]:c[0].name:"Qwen/Qwen3-4B",g=[{label:"RAM",value:`${NQ(a.totalRamMb)} GB`,color:ce.accent,hint:"Total RAM across all network nodes."},{label:"VRAM",value:`${NQ(a.totalVramMb)} GB`,color:ce.info,hint:"Total GPU VRAM across all network nodes."},{label:"CPU Cores",value:`${a.totalCpuCores}`,color:ce.purple,hint:"Total CPU cores across all network nodes."},{label:"GPU Util",value:u>0?`${Math.round(u)}%`:"--",color:p,hint:"Average GPU utilization across active nodes. Green <50%, yellow 50-80%, red >80%."},{label:"Nodes",value:`${a.activeNodes}/${a.totalNodes}`,color:ce.accent,hint:"Active nodes out of total registered."},{label:"Load",value:a.avgLoad>0?a.avgLoad.toFixed(2):"0.00",color:f,hint:"Average load across active nodes. Green <1.0, yellow 1.0-2.0, red >2.0."},{label:"Model",value:x,color:ce.info,hint:"Active inference model on the network."}];return e.jsxs("div",{className:"flex-shrink-0",children:[e.jsx("div",{className:"flex flex-wrap border-b border-border",style:{background:"var(--color-surface-0)"},children:g.map(y=>e.jsx(WQe,{label:y.label,value:y.value,color:y.color,hint:y.hint,className:K("flex-1 basis-[14.2%] min-w-[110px]","border-b border-r border-border")},y.label))}),e.jsx(nLe,{compute:a,allZero:r,avgGpuUtil:u})]})});function oLe(t){return!t||typeof t!="string"?"—":t.length<14?t:`${t.slice(0,6)}…${t.slice(-4)}`}const cLe=O.memo(function(){const a=q(C=>C.networkSnapshots),s=q(C=>C.networkStatus.nodes||[]),c=q(C=>C.networkNode.nodeId),r=O.useRef(null),l=O.useRef(null),[u,p]=O.useState({width:0,height:0}),[f,x]=O.useState(null),{width:g,height:y}=u,k={top:28,right:12,bottom:8,left:12},b=Math.max(g-k.left-k.right,0),j=Math.max(y-k.top-k.bottom,0),w=O.useMemo(()=>!a||a.length<2?[]:a,[a]);O.useEffect(()=>{const C=r.current;if(!C)return;const _=new ResizeObserver(P=>{const{width:L,height:A}=P[0].contentRect;L>0&&A>0&&p({width:Math.floor(L),height:Math.floor(A)})});return _.observe(C),()=>_.disconnect()},[]);const S=O.useCallback(C=>{const _=l.current;if(!_||!w.length||b<=0)return;const P=_.getBoundingClientRect(),L=C.clientX-P.left-k.left;if(L<0||L>b){x(null);return}const A=Math.round(L/b*(w.length-1));x({x:k.left+A/Math.max(w.length-1,1)*b,index:A})},[w,b,k.left]),M=O.useCallback(()=>x(null),[]);O.useEffect(()=>{const C=l.current;if(!C||!w.length||g<=0||y<=0||b<=0||j<=0)return;const _=C.getContext("2d"),P=window.devicePixelRatio||1;C.width=g*P,C.height=y*P,_.scale(P,P),_.clearRect(0,0,g,y);const L=w.map(R=>R.globalSessions),A=w.map(R=>R.mySessions),z=Math.max(...L,...A,1),Y=R=>k.left+R/Math.max(w.length-1,1)*b,V=R=>k.top+j-R/z*j;_.setLineDash([2,4]),_.strokeStyle=ct(ce.text4,.2),_.lineWidth=1;for(let R=1;R<=3;R++){const I=k.top+j/4*R;_.beginPath(),_.moveTo(k.left,I),_.lineTo(k.left+b,I),_.stroke()}_.setLineDash([]),_.font="9px 'JetBrains Mono Variable', monospace",_.textAlign="left",_.fillStyle=ct(ce.text3,.5),_.fillText(String(z),k.left+4,k.top+10),_.fillText(String(Math.round(z/2)),k.left+4,k.top+j/2+4),_.beginPath(),_.moveTo(k.left,k.top+j);for(let R=0;R<w.length;R++)_.lineTo(Y(R),V(L[R]));_.lineTo(Y(w.length-1),k.top+j),_.closePath();const se=_.createLinearGradient(0,k.top,0,k.top+j);se.addColorStop(0,ct(ce.purple,.2)),se.addColorStop(.7,ct(ce.purple,.04)),se.addColorStop(1,ct(ce.purple,0)),_.fillStyle=se,_.fill(),_.beginPath(),_.strokeStyle=ce.purple,_.lineWidth=1.5,_.lineJoin="round";for(let R=0;R<w.length;R++){const I=Y(R),T=V(L[R]);R===0?_.moveTo(I,T):_.lineTo(I,T)}_.stroke(),_.beginPath(),_.strokeStyle=ce.accent,_.lineWidth=1.5,_.lineJoin="round";for(let R=0;R<w.length;R++){const I=Y(R),T=V(A[R]);R===0?_.moveTo(I,T):_.lineTo(I,T)}_.stroke(),_.font="9px 'Inter Variable', sans-serif",_.textAlign="right";let ne=g-k.right-4;const oe=14;if(_.fillStyle=ce.accent,_.fillText("Your Node",ne,oe),ne-=_.measureText("Your Node").width+4,_.beginPath(),_.arc(ne,oe-3,2.5,0,Math.PI*2),_.fill(),ne-=14,_.fillStyle=ce.purple,_.fillText("Network",ne,oe),ne-=_.measureText("Network").width+4,_.beginPath(),_.arc(ne,oe-3,2.5,0,Math.PI*2),_.fill(),f&&f.index>=0&&f.index<w.length){const R=f.x,I=w[f.index];_.beginPath(),_.moveTo(R,k.top),_.lineTo(R,k.top+j),_.strokeStyle=ct(ce.text1,.15),_.lineWidth=1,_.stroke(),_.beginPath(),_.arc(R,V(I.globalSessions),3,0,Math.PI*2),_.fillStyle=ce.purple,_.fill(),_.beginPath(),_.arc(R,V(I.mySessions),3,0,Math.PI*2),_.fillStyle=ce.accent,_.fill();const T=[{label:"Network",value:String(I.globalSessions),color:ce.purple},{label:"Your Node",value:String(I.mySessions),color:ce.accent},{label:"Nodes",value:String(I.nodeCount),color:ce.text2}],Z=104,J=T.length*16+12;let W=R+12;W+Z>g-8&&(W=R-Z-12);const U=Math.max(k.top,V(I.globalSessions)-J/2);_.fillStyle=ct(ce.surface0,.92),_.beginPath(),_.roundRect(W,U,Z,J,4),_.fill(),_.strokeStyle=ct(ce.text4,.2),_.lineWidth=1,_.stroke(),_.textAlign="left",T.forEach((xe,pe)=>{const fe=U+14+pe*16;_.beginPath(),_.arc(W+8,fe-3,2,0,Math.PI*2),_.fillStyle=xe.color,_.fill(),_.font="8px 'Inter Variable', sans-serif",_.fillStyle=ce.text3,_.fillText(xe.label,W+14,fe),_.font="9px 'JetBrains Mono Variable', monospace",_.fillStyle=ce.text0,_.textAlign="right",_.fillText(xe.value,W+Z-8,fe),_.textAlign="left"})}},[w,g,y,f,b,j,k]);const $=s.filter(C=>C.status==="active");return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Network Activity"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[$.length," nodes"]})]}),e.jsx("div",{className:"relative flex-1 min-h-0",children:w.length<2?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("span",{className:"text-xs font-mono text-text-3",children:"Collecting network data…"})}):e.jsx("div",{ref:r,className:"absolute inset-0",children:g>0&&y>0&&e.jsx("canvas",{ref:l,style:{width:g,height:y},className:"block cursor-crosshair",onMouseMove:S,onMouseLeave:M})})}),e.jsxs("div",{className:"px-3 py-1.5 border-t border-border-subtle flex items-center gap-2 flex-shrink-0 font-mono text-2xs",style:{background:ct(ce.accent,.04)},children:[e.jsxs("span",{className:"text-text-3",children:[$.length," node",$.length!==1?"s":""," online"]}),$.map(C=>{const _=C.node_id||C.nodeId||"",P=c&&_===c,L=Array.isArray(C.layers)?`${C.layers[0]}-${C.layers[1]}`:"";return e.jsxs("span",{className:P?"text-accent":"text-text-2",children:[oLe(_),P?" (You":"(",L?` · ${L}`:"",")"]},_)})]})]})}),rLe=["All","Sessions","Errors","Connections"],iLe={Sessions:["session"],Errors:["error","warning"],Connections:["connected","disconnected"]},lLe={info:ce.text3,success:ce.success,warning:ce.warning,error:ce.danger,connected:ce.success,disconnected:ce.warning,session:ce.accent};function dLe(t){return t?new Date(t).toLocaleTimeString("en-GB",{hour12:!1}):"--:--:--"}function uLe(t){return{info:"info",success:" ok ",warning:"warn",error:"ERR!",connected:"conn",disconnected:"disc",session:"sess"}[t]||t||"info"}const hLe=O.memo(function(){const a=q(p=>p.networkEvents),[s,c]=O.useState("All"),r=O.useRef(null),u=(s==="All"?a:a.filter(p=>{const f=p.level||p.type||"info";return(iLe[s]||[]).includes(f)})).slice(-200);return O.useEffect(()=>{var p;(p=r.current)==null||p.scrollIntoView({behavior:"smooth"})},[u.length]),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1 flex-shrink-0",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Activity"}),e.jsx("div",{className:"flex-1"}),e.jsx("div",{className:"flex items-center gap-0.5",children:rLe.map(p=>e.jsx("button",{onClick:()=>c(p),className:K("px-2 py-0.5 text-2xs font-mono rounded-sm transition-colors cursor-pointer",s===p?"bg-[rgba(51,175,188,0.15)] text-accent":"bg-surface-4 text-text-3 hover:text-text-2"),children:p},p))})]}),e.jsx(It,{className:"flex-1 min-h-0",children:u.length===0?e.jsx("div",{className:"px-3 py-6 text-2xs font-mono text-text-4 text-center",children:"No events yet — toggle your node on to start."}):e.jsxs("div",{className:"px-2 py-1",children:[u.map((p,f)=>{const x=p.level||p.type||"info",g=lLe[x]||ce.text3;return e.jsxs("div",{className:"flex items-start gap-0 font-mono text-2xs leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 flex-shrink-0 w-[62px]",children:["[",dLe(p.timestamp||p.ts),"]"]}),e.jsx("span",{className:"flex-shrink-0 w-[36px]",style:{color:g},children:uLe(x)}),e.jsx("span",{className:"text-text-2 break-words min-w-0",children:p.msg||p.message||p.text||"event"})]},f)}),e.jsx("div",{ref:r})]})})]})});function pLe(t,a){const s=t/a;return s>=1?{color:ce.success,label:"Full coverage"}:s>=.5?{color:ce.warning,label:"Partial"}:{color:ce.danger,label:"Insufficient"}}const fLe=O.memo(function(){const a=q(x=>x.networkStatus),s=q(x=>x.networkStatusReachable),c=q(x=>x.networkNode);Array.isArray(a.nodes)&&a.nodes;const r=a.totalLayers||36,l=a.coverage||0,u=pLe(l,r),p=Math.min(100,l/r*100),f=Array.isArray(a.models)?a.models:[];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Network Health"})}),e.jsx(It,{className:"flex-1 min-h-0",children:e.jsxs("div",{className:"px-3 py-2 space-y-3",children:[e.jsx("div",{className:"bg-surface-0 rounded p-2.5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:s?ce.success:ce.danger}}),s&&e.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:ce.success,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),e.jsx("span",{className:"text-2xs font-mono text-text-3",children:"Signal"}),e.jsx("span",{className:"text-2xs font-mono text-text-1",children:"signal.groovedev.ai"}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-2xs font-mono",style:{color:s?ce.success:ce.danger},children:s?"Connected":"Unreachable"})]})}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Layer Coverage"}),e.jsxs("span",{className:"text-2xs font-mono tabular-nums",style:{color:u.color},children:[l,"/",r]})]}),e.jsx("div",{className:"h-0.5 rounded-sm overflow-hidden",style:{background:ct(ce.accent,.08)},children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-700",style:{width:`${p}%`,background:u.color}})}),e.jsx("div",{className:"mt-1 text-2xs font-mono text-text-4",children:u.label})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Sessions"}),e.jsx("span",{className:"text-base font-mono font-semibold text-text-0 tabular-nums leading-none",children:Fe(a.activeSessions||0)})]}),e.jsx("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:"Active streams"})]}),c.active&&e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Node Status"}),e.jsx("span",{className:"text-2xs font-mono capitalize",style:{color:c.status==="connected"?ce.success:ce.warning},children:c.status||"disconnected"})]}),c.sessions>0&&e.jsxs("div",{className:"flex items-center justify-between mt-1.5",children:[e.jsx("span",{className:"text-2xs font-mono text-text-4",children:"Local Sessions"}),e.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:c.sessions})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1.5",children:"Models"}),f.length===0?e.jsx("div",{className:"text-2xs font-mono text-text-4",children:"No models available"}):e.jsx("div",{className:"space-y-1",children:f.map((x,g)=>{const y=typeof x=="string"?x:x.name,k=typeof x=="string"?!0:!!x.available;return e.jsxs("div",{className:"flex items-center gap-2 bg-surface-0 rounded px-2.5 py-1.5",children:[e.jsx("span",{className:"relative flex-shrink-0 w-[5px] h-[5px]",children:e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:k?ce.success:ce.text4}})}),e.jsx("span",{className:"text-xs font-mono text-text-1 truncate flex-1",children:y}),e.jsx("span",{className:"text-2xs font-mono",style:{color:k?ce.success:ce.text3},children:k?"Online":"Offline"})]},g)})})]})]})})]})}),xLe=["Python 3.10 or higher","~2 GB disk space for model shards","8 GB+ RAM recommended"];function mLe({progress:t}){const a=Math.max(0,Math.min(100,Number.isFinite(t.percent)?t.percent:0));return e.jsxs("div",{className:"w-full flex flex-col gap-3",children:[e.jsx("div",{className:"h-2 w-full rounded-full bg-surface-3 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-accent transition-all duration-500 ease-out",style:{width:`${a}%`}})}),e.jsxs("div",{className:"flex items-center justify-between text-2xs font-mono text-text-3 tabular-nums",children:[e.jsxs("div",{className:"flex items-center gap-2 text-text-2 font-sans",children:[e.jsx(ze,{size:12,className:"animate-spin text-accent"}),e.jsx("span",{className:"truncate",children:t.message||"Installing…"})]}),e.jsxs("span",{children:[a,"%"]})]})]})}function yLe({message:t,onRetry:a}){return e.jsxs("div",{className:"w-full flex flex-col gap-3",children:[e.jsxs("div",{className:"rounded-md border border-danger/40 bg-danger/10 px-4 py-3 flex items-start gap-2.5 text-left",children:[e.jsx(vt,{size:14,className:"text-danger flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-danger font-sans mb-0.5",children:"Install failed"}),e.jsx("div",{className:"text-xs text-text-1 font-sans break-words",children:t})]})]}),e.jsxs(he,{variant:"primary",size:"lg",onClick:a,className:"w-full",children:[e.jsx(Oa,{size:14}),"Retry Install"]})]})}function gLe(){const t=q(r=>r.installNetworkPackage),a=q(r=>r.networkInstallProgress),{installing:s,error:c}=a;return e.jsx("div",{className:"flex flex-col items-center justify-center min-h-full px-6 py-12",children:e.jsxs("div",{className:"w-full max-w-md flex flex-col items-center text-center",children:[e.jsx("div",{className:"mb-5 rounded-full bg-surface-2 border border-border-subtle p-5",children:e.jsx(At,{size:48,className:"text-text-3",strokeWidth:1.25})}),e.jsx("h3",{className:"text-base font-semibold text-text-0 font-sans mb-2",children:"Install Groove Network"}),e.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed mb-6",children:"The network package enables decentralized LLM inference. Contribute your compute power or run models across the Groove network."}),e.jsxs("div",{className:"w-full rounded-md border border-border-subtle bg-surface-1 px-4 py-3 mb-6",children:[e.jsx("div",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2 text-left",children:"Requirements"}),e.jsx("ul",{className:"flex flex-col gap-1.5",children:xLe.map(r=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-sans text-text-1 text-left",children:[e.jsx(Ve,{size:12,className:"text-accent flex-shrink-0"}),e.jsx("span",{children:r})]},r))})]}),s?e.jsx(mLe,{progress:a}):c?e.jsx(yLe,{message:c,onRetry:()=>t()}):e.jsxs(e.Fragment,{children:[e.jsxs(he,{variant:"primary",size:"lg",onClick:()=>t(),className:"w-full",children:[e.jsx(Oa,{size:14}),"Install Network Package"]}),e.jsx("p",{className:"text-2xs font-sans text-text-3 mt-3",children:"This will download and set up the Groove Network runtime (~500 MB)"})]})]})})}function OLe({progress:t}){const a=Math.max(0,Math.min(100,Number.isFinite(t.percent)?t.percent:0));return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md border border-border-subtle bg-surface-0",children:[e.jsx(ze,{size:11,className:"animate-spin text-accent flex-shrink-0"}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("span",{className:"text-2xs font-sans text-text-1 truncate",children:t.message||"Updating…"}),e.jsx("div",{className:"h-1 w-32 rounded-full bg-surface-3 overflow-hidden mt-0.5",children:e.jsx("div",{className:"h-full rounded-full bg-accent transition-all duration-500 ease-out",style:{width:`${a}%`}})})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[a,"%"]})]})}function kLe(){const[t,a]=O.useState(!1),s=q(u=>u.networkVersion),c=q(u=>u.networkUpdateProgress),r=q(u=>u.updateNetworkPackage);if(c.updating)return e.jsx(OLe,{progress:c});if(!s.updateAvailable)return null;const l=async()=>{try{await r(),a(!1)}catch{}};return e.jsxs(qa,{open:t,onOpenChange:a,children:[e.jsx(MD,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex items-center gap-1",title:`Update to ${s.latest}`,children:e.jsxs(ge,{variant:"warning",className:"cursor-pointer",children:[e.jsx(Ja,{size:10}),"Update Available"]})})}),e.jsxs(Ia,{title:"Update Network Package",description:"Confirm update",children:[e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[e.jsxs("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:["Update to ",e.jsx("span",{className:"font-mono text-accent",children:s.latest}),"?"]}),e.jsxs("p",{className:"text-xs text-text-3 font-sans leading-relaxed",children:["You are currently running ",e.jsx("span",{className:"font-mono",children:s.installed||"unknown"}),". Your node will be stopped during the update and restarted after."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3 border-t border-border-subtle bg-surface-0",children:[e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>a(!1),children:"Cancel"}),e.jsxs(he,{variant:"primary",size:"sm",onClick:l,children:[e.jsx(Ja,{size:12}),"Update"]})]})]})]})}function vLe(){const[t,a]=O.useState(!1),s=q(u=>u.uninstallNetworkPackage),[c,r]=O.useState(!1),l=async()=>{r(!0);try{await s(),a(!1)}catch{}finally{r(!1)}};return e.jsxs(qa,{open:t,onOpenChange:a,children:[e.jsx(MD,{asChild:!0,children:e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 text-2xs font-sans text-text-3 hover:text-danger transition-colors",children:[e.jsx(wt,{size:11}),"Uninstall"]})}),e.jsxs(Ia,{title:"Uninstall Network Package",description:"Confirm uninstall",children:[e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[e.jsxs("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:["This will stop your node and remove the network package from ",e.jsx("span",{className:"font-mono text-text-2",children:"~/.groove/network"}),"."]}),e.jsxs("p",{className:"text-xs text-text-3 font-sans leading-relaxed",children:["Your identity (",e.jsx("span",{className:"font-mono",children:"~/.groove/node_key.json"}),") will be preserved — you can reinstall later without losing your wallet."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3 border-t border-border-subtle bg-surface-0",children:[e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>a(!1),disabled:c,children:"Cancel"}),e.jsxs(he,{variant:"danger",size:"sm",onClick:l,disabled:c,children:[c?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(wt,{size:12}),"Uninstall"]})]})]})]})}function bLe({value:t,onChange:a,disabled:s}){return e.jsx("button",{onClick:()=>!s&&a(!t),disabled:s,className:K("relative inline-flex h-5 w-9 rounded-full p-0.5 transition-colors flex-shrink-0",s?"opacity-50 cursor-not-allowed":"cursor-pointer",t?"bg-accent":"bg-surface-5"),children:e.jsx("span",{className:K("inline-block h-4 w-4 rounded-full bg-white shadow-sm transition-transform",t?"translate-x-4":"translate-x-0")})})}function jP(){const t=q(x=>x.networkNode),a=q(x=>x.networkInstalled),s=q(x=>x.networkVersion),c=q(x=>x.networkStatusReachable),r=q(x=>x.startNetworkNode),l=q(x=>x.stopNetworkNode),[u,p]=O.useState(!1);async function f(x){p(!0);try{x?await r():await l()}catch{}p(!1)}return e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border flex-shrink-0",children:[e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Network Command Center"}),a&&s.installed&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"/"}),e.jsxs("span",{className:"text-xs font-mono text-text-2 tabular-nums",children:["v",String(s.installed).replace(/^v/,"")]})]}),a&&e.jsx(kLe,{}),e.jsx("div",{className:"flex-1"}),a&&e.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(bLe,{value:!!t.active,onChange:f,disabled:u}),e.jsx("span",{className:"text-text-3",children:t.active?"Contributing":"Idle"})]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"relative flex-shrink-0 w-[5px] h-[5px]",children:e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:c?ce.accent:ce.danger}})}),e.jsx("span",{className:"text-text-3",children:"Signal"})]})]}),a&&e.jsx(vLe,{}),e.jsx(aa,{status:a&&t.active?"running":a?"stopped":"crashed",size:"sm"})]})}function wLe(){const t=q(x=>x.networkNode),a=q(x=>x.networkStatus),s=q(x=>x.startNetworkNode),[c,r]=O.useState(!1),l=t.hardware||{},u=(a.nodes||[]).filter(x=>x.status==="active").length,p=a.activeSessions||0;async function f(){r(!0);try{await s()}catch{}r(!1)}return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(jP,{}),e.jsx("div",{className:"flex-1 flex items-center justify-center bg-surface-0",style:{background:`radial-gradient(ellipse at 50% 40%, ${ct(ce.accent,.06)} 0%, transparent 70%) ${ce.surface0}`},children:e.jsxs("div",{className:"max-w-lg w-full px-6 flex flex-col items-center text-center",children:[e.jsx("div",{className:"w-24 h-24 rounded-full flex items-center justify-center mb-6 mx-auto",style:{background:ct(ce.accent,.08),border:`1px solid ${ct(ce.accent,.15)}`,boxShadow:`0 0 40px ${ct(ce.accent,.1)}`},children:e.jsx(At,{size:56,className:"text-accent",strokeWidth:1.25})}),e.jsx("h2",{className:"text-xl font-semibold text-text-0 font-sans text-center",children:"Join the Groove Network"}),e.jsx("p",{className:"text-sm text-text-2 font-sans text-center leading-relaxed mt-2 max-w-sm mx-auto",children:"Contribute your compute to power decentralized AI inference. Your hardware runs model shards alongside other nodes in the network."}),e.jsxs("div",{className:"mt-8 w-full",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest mb-2 text-left",children:"Your Hardware"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"bg-surface-1 rounded-sm border border-border-subtle px-4 py-3",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:"Device"}),e.jsx("div",{className:"text-sm font-mono text-text-0 mt-1 truncate",children:l.device||"auto"})]}),e.jsxs("div",{className:"bg-surface-1 rounded-sm border border-border-subtle px-4 py-3",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:"Memory"}),e.jsx("div",{className:"text-sm font-mono text-text-0 mt-1 truncate",children:l.memory||"—"})]}),e.jsxs("div",{className:"bg-surface-1 rounded-sm border border-border-subtle px-4 py-3",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:"GPU"}),e.jsx("div",{className:"text-sm font-mono text-text-0 mt-1 truncate",children:l.gpu||"None"})]})]})]}),e.jsx("div",{className:"mt-6 w-full max-w-sm mx-auto",children:e.jsx(he,{variant:"primary",size:"lg",onClick:f,disabled:c,className:"w-full",children:c?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"})," Connecting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(qt,{size:14})," Start Contributing"]})})}),e.jsx("div",{className:"mt-4 text-center text-2xs font-mono text-text-3",children:u>0||p>0?e.jsxs("span",{children:[e.jsx("span",{className:"text-accent",children:u})," node",u!==1?"s":""," online · ",p," active session",p!==1?"s":""]}):e.jsx("span",{children:"Checking network status…"})}),t.nodeId&&e.jsxs("div",{className:"mt-6 text-center text-2xs font-mono text-text-4",children:["Node identity: ",t.nodeId.length>14?`${t.nodeId.slice(0,6)}…${t.nodeId.slice(-4)}`:t.nodeId]})]})})]})}function MLe(){const t=q(l=>l.fetchNetworkNodeStatus),a=q(l=>l.fetchNetworkStatus),s=q(l=>l.checkNetworkUpdate),c=q(l=>l.networkInstalled),r=q(l=>l.networkNode.active);return O.useEffect(()=>{if(t(),c){a(),s();const l=setInterval(()=>{a()},1e4);return()=>clearInterval(l)}},[t,a,s,c]),c?r?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(jP,{}),e.jsx(sLe,{}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",style:{background:ce.surface3,gap:"1px"},children:[e.jsxs("div",{className:"min-h-0 flex-1 grid",style:{gridTemplateColumns:"3fr 1.5fr",gap:"0 1px"},children:[e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1",children:e.jsx(cLe,{})}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1",children:e.jsx(fLe,{})})]}),e.jsx("div",{className:"min-h-0 flex-[0.6] bg-surface-1",children:e.jsx(hLe,{})})]})]}):e.jsx(wLe,{}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(jP,{}),e.jsx(It,{className:"flex-1",children:e.jsx(gLe,{})})]})}function kB(t){return t?t.replace(/^claude-/,"").replace(/-(\d)/," $1").split("-").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "):""}const jLe={frontier:{label:"Frontier",variant:"purple",icon:bt},mid:{label:"Mid",variant:"accent",icon:qt},fast:{label:"Fast",variant:"success",icon:qt}};function SLe(t){const a=(t||"").toLowerCase();return a.includes("opus")||a.includes("pro")||a.includes("o3")||a.includes("gpt-4o")?"frontier":a.includes("sonnet")||a.includes("flash")||a.includes("o4-mini")?"mid":"fast"}function NLe(t){const a=(t||"").toLowerCase();return a.includes("opus")||a.includes("sonnet")||a.includes("haiku")?"200k":a.includes("pro")||a.includes("flash")?"1M":(a.includes("o3")||a.includes("o4"),"128k")}function _Le({value:t,onChange:a,disabled:s}){const[c,r]=O.useState(!1),[l,u]=O.useState([]),p=q(b=>b.fetchProviders),f=O.useRef(null);O.useEffect(()=>{p().then(b=>{Array.isArray(b)?u(b):b!=null&&b.providers&&u(b.providers)}).catch(()=>{})},[p]),O.useEffect(()=>{if(!c)return;function b(j){f.current&&!f.current.contains(j.target)&&r(!1)}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[c]);const x=(t==null?void 0:t.model)||"",g=x?kB(x):"Select model",y=(t==null?void 0:t.provider)||"",k=y==="groove-network";return e.jsxs("div",{ref:f,className:"relative",children:[e.jsxs("button",{onClick:()=>!s&&r(!c),disabled:s,className:K("flex items-center gap-1.5 h-8 px-2.5 rounded-lg text-xs font-medium font-sans transition-colors cursor-pointer","bg-surface-4 border border-border-subtle hover:bg-surface-5","disabled:opacity-40 disabled:cursor-not-allowed",k&&"border-purple/30 bg-purple/8"),children:[k?e.jsx(At,{size:12,className:"text-purple"}):e.jsx(tn,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-text-1 max-w-[120px] truncate",children:g}),e.jsx(zt,{size:12,className:"text-text-4"})]}),c&&e.jsxs("div",{className:"absolute top-full right-0 mt-1 w-72 max-h-80 overflow-y-auto rounded-lg border border-border bg-surface-1 shadow-xl z-50",children:[l.length===0&&e.jsx("div",{className:"px-4 py-6 text-center text-xs text-text-3 font-sans",children:"No providers available"}),l.map(b=>{const j=b.models||[];if(j.length===0)return null;const w=b.id==="groove-network";return e.jsxs("div",{children:[e.jsxs("div",{className:"px-3 py-1.5 text-2xs font-semibold text-text-3 uppercase tracking-wider font-sans bg-surface-2 border-b border-border-subtle flex items-center gap-1.5",children:[w&&e.jsx(At,{size:10,className:"text-purple"}),b.name||b.id]}),j.map(S=>{const M=typeof S=="string"?S:S.id||S.name,$=typeof S=="string"?S:S.name||S.id,C=SLe(M),_=jLe[C],P=_.icon,L=x===M&&y===b.id;return e.jsxs("button",{onClick:()=>{a({provider:b.id,model:M}),r(!1)},className:K("w-full flex items-center gap-2 px-3 py-2 text-left transition-colors cursor-pointer",L?"bg-accent/10 text-text-0":"hover:bg-surface-3 text-text-1"),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium font-sans truncate",children:$}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:[NLe(M)," context"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[w&&e.jsxs(ge,{variant:"purple",className:"text-[9px]",children:[e.jsx(At,{size:8})," Decentralized"]}),e.jsxs(ge,{variant:_.variant,className:"text-[9px]",children:[e.jsx(P,{size:8})," ",_.label]})]})]},M)})]},b.id)})]})]})}function $Le(t){const a=new Date,s=new Date(a.getFullYear(),a.getMonth(),a.getDate()),c=new Date(s);c.setDate(s.getDate()-1);const r=new Date(s);r.setDate(s.getDate()-7);const l={pinned:[],today:[],yesterday:[],week:[],older:[]};for(const u of t){if(u.pinned){l.pinned.push(u);continue}const p=new Date(u.updatedAt||u.createdAt);p>=s?l.today.push(u):p>=c?l.yesterday.push(u):p>=r?l.week.push(u):l.older.push(u)}return l}function CLe({label:t}){return e.jsx("div",{className:"px-3 pt-4 pb-1.5",children:e.jsx("span",{className:"text-2xs font-semibold text-text-4 uppercase tracking-wider font-sans",children:t})})}function QLe({conv:t,isActive:a,onSelect:s,onRename:c,onPin:r,onDelete:l}){return e.jsxs(aA,{children:[e.jsx(nA,{asChild:!0,children:e.jsxs("button",{onClick:()=>s(t.id),className:K("w-full flex items-center gap-2 px-3 py-2 text-left rounded-md transition-colors cursor-pointer group",a?"bg-accent/10 text-text-0":"text-text-2 hover:bg-surface-4 hover:text-text-1"),children:[e.jsx(Sn,{size:13,className:K("flex-shrink-0",a?"text-accent":"text-text-4 group-hover:text-text-3")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium font-sans truncate",children:t.title||"New Chat"}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.mode==="agent"?e.jsx(Ld,{size:9,className:"text-purple flex-shrink-0"}):e.jsx(qt,{size:9,className:"text-accent flex-shrink-0"}),t.model&&e.jsx(ge,{variant:"default",className:"text-[8px] px-1 py-0",children:kB(t.model)}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:gt(t.updatedAt||t.createdAt)})]})]}),t.pinned&&e.jsx(y1,{size:10,className:"text-accent flex-shrink-0"})]})}),e.jsxs(sA,{children:[e.jsxs(gn,{onSelect:()=>c(t),children:[e.jsx(ts,{size:12})," Rename"]}),e.jsxs(gn,{onSelect:()=>r(t),children:[t.pinned?e.jsx(Ud,{size:12}):e.jsx(y1,{size:12}),t.pinned?"Unpin":"Pin"]}),e.jsx(oA,{}),e.jsxs(gn,{danger:!0,onSelect:()=>l(t.id),children:[e.jsx(wt,{size:12})," Delete"]})]})]})}function LLe({onNewChat:t}){const a=q(y=>y.conversations),s=q(y=>y.activeConversationId),c=q(y=>y.setActiveConversation),r=q(y=>y.renameConversation),l=q(y=>y.pinConversation),u=q(y=>y.deleteConversation),p=O.useMemo(()=>$Le(a),[a]);function f(y){const k=prompt("Rename conversation:",y.title||"");k&&k.trim()&&r(y.id,k.trim())}function x(y){l(y.id,!y.pinned)}const g=(y,k)=>k.length===0?null:e.jsxs("div",{children:[e.jsx(CLe,{label:y}),k.map(b=>e.jsx(QLe,{conv:b,isActive:b.id===s,onSelect:c,onRename:f,onPin:x,onDelete:u},b.id))]},y);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 overflow-y-auto px-1.5 pt-3 pb-3 space-y-0.5",children:a.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center px-4",children:[e.jsx(Sn,{size:24,className:"text-text-4 mb-3"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No conversations yet"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Start a new chat to begin"})]}):e.jsxs(e.Fragment,{children:[g("Pinned",p.pinned),g("Today",p.today),g("Yesterday",p.yesterday),g("Previous 7 Days",p.week),g("Older",p.older)]})}),e.jsx("div",{className:"p-3 border-t border-border-subtle",children:e.jsxs("button",{onClick:t,className:"w-full flex items-center justify-center gap-2 h-9 rounded-lg bg-accent/15 text-accent text-xs font-semibold font-sans hover:bg-accent/25 transition-colors cursor-pointer border border-accent/20",children:[e.jsx(rt,{size:14}),"New Chat"]})})]})}function zLe({conversation:t,model:a,onModelChange:s,onModeChange:c}){const r=q(C=>C.renameConversation),l=q(C=>C.pinConversation),u=q(C=>C.deleteConversation),[p,f]=O.useState(!1),[x,g]=O.useState(t.title||""),[y,k]=O.useState(!1),b=O.useRef(null),j=O.useRef(null);O.useEffect(()=>{g(t.title||""),f(!1)},[t.id,t.title]),O.useEffect(()=>{p&&b.current&&b.current.focus()},[p]),O.useEffect(()=>{if(!y)return;function C(_){j.current&&!j.current.contains(_.target)&&k(!1)}return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[y]);function w(){const C=x.trim();C&&C!==t.title?r(t.id,C):g(t.title||""),f(!1)}const S=q(C=>C.agents.find(_=>_.id===t.agentId)),M=(S==null?void 0:S.tokensUsed)||0,$=t.mode||"api";return e.jsxs("div",{className:"h-11 flex items-center gap-3 px-4 border-b border-border-subtle bg-surface-0/80 flex-shrink-0",children:[e.jsx(b2,{size:14,className:"text-text-4 flex-shrink-0"}),p?e.jsx("input",{ref:b,value:x,onChange:C=>g(C.target.value),onKeyDown:C=>{C.key==="Enter"&&w(),C.key==="Escape"&&(g(t.title||""),f(!1))},onBlur:w,className:"flex-1 min-w-0 bg-transparent text-sm font-semibold text-text-0 font-sans outline-none border-b border-accent",maxLength:100}):e.jsx("button",{onClick:()=>f(!0),className:"flex-1 min-w-0 text-left text-sm font-semibold text-text-0 font-sans truncate hover:text-accent transition-colors cursor-pointer",children:t.title||"New Chat"}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center h-7 rounded-lg bg-surface-3 border border-border-subtle p-0.5",children:[e.jsx($1,{content:"Lightweight — fast and cheap, no tools",side:"bottom",children:e.jsxs("button",{onClick:()=>c==null?void 0:c("api"),className:`flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-semibold font-sans transition-colors cursor-pointer ${$==="api"?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1"}`,children:[e.jsx(qt,{size:11})," Chat"]})}),e.jsx($1,{content:"Full agent — tools, files, session resume",side:"bottom",children:e.jsxs("button",{onClick:()=>c==null?void 0:c("agent"),className:`flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-semibold font-sans transition-colors cursor-pointer ${$==="agent"?"bg-purple/15 text-purple border border-purple/25":"text-text-3 hover:text-text-1"}`,children:[e.jsx(Ld,{size:11})," Agent"]})})]}),e.jsx(_Le,{value:a||{provider:t.provider,model:t.model},onChange:s,disabled:!1}),M>0&&e.jsxs("span",{className:"text-2xs text-text-3 font-mono",children:[Fe(M)," tokens"]}),e.jsxs("div",{ref:j,className:"relative",children:[e.jsx("button",{onClick:()=>k(!y),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-3 hover:text-text-1 hover:bg-surface-3 transition-colors cursor-pointer",children:e.jsx(Qo,{size:14})}),y&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-40 rounded-md border border-border bg-surface-1 shadow-xl z-50 py-1",children:[e.jsxs("button",{onClick:()=>{f(!0),k(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm text-text-1 hover:bg-surface-5 cursor-pointer font-sans",children:[e.jsx(ts,{size:12})," Rename"]}),e.jsxs("button",{onClick:()=>{l(t.id,!t.pinned),k(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm text-text-1 hover:bg-surface-5 cursor-pointer font-sans",children:[t.pinned?e.jsx(Ud,{size:12}):e.jsx(y1,{size:12}),t.pinned?"Unpin":"Pin"]}),e.jsx("div",{className:"h-px my-1 bg-border-subtle"}),e.jsxs("button",{onClick:()=>{u(t.id),k(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm text-danger hover:bg-danger/10 cursor-pointer font-sans",children:[e.jsx(wt,{size:12})," Delete"]})]})]})]})]})}const wX=["Reading through the codebase...","Thinking through your request...","Planning the approach...","Running tool calls...","Working through the problem...","Reasoning step by step...","Reviewing context...","Considering options...","Analyzing the code...","Making progress..."];function vB({agent:t,className:a}){const[s,c]=O.useState(0),[r,l]=O.useState(!0);return O.useEffect(()=>{const u=setInterval(()=>{l(!1),setTimeout(()=>{c(p=>(p+1)%wX.length),l(!0)},250)},2800);return()=>clearInterval(u)},[]),e.jsxs("div",{className:`${a||""}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-1 font-sans",children:(t==null?void 0:t.name)||"Agent"}),e.jsx("span",{className:"text-2xs text-accent font-mono",children:"thinking"})]}),e.jsxs("div",{className:"border-l border-accent/40 pl-3.5 py-1 flex items-center gap-2.5",children:[e.jsx("div",{className:"relative w-3.5 h-3.5 flex-shrink-0",children:e.jsx("span",{className:"absolute inset-0 rounded-full border border-transparent border-t-accent animate-spin",style:{animationDuration:"0.9s"}})}),e.jsx("span",{className:"text-[12px] font-sans text-text-3 transition-opacity duration-[250ms]",style:{opacity:r?1:0},children:wX[s]})]})]})}const MX=["Generating response...","Processing...","Thinking...","Almost there..."];function TLe({text:t}){const[a,s]=O.useState(!1);function c(){navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)})}return e.jsxs("button",{onClick:c,className:"flex items-center gap-1 px-2 py-1 text-2xs font-sans text-text-3 hover:text-text-1 transition-colors cursor-pointer",children:[a?e.jsx(Ve,{size:12,className:"text-success"}):e.jsx(Mn,{size:12}),a?"Copied":"Copy"]})}function PLe({language:t,code:a}){return e.jsxs("div",{className:"my-3 rounded-lg border border-border-subtle overflow-hidden bg-surface-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-3 border-b border-border-subtle",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3",children:t||"code"}),e.jsx(TLe,{text:a})]}),e.jsx("pre",{className:"px-4 py-3 overflow-x-auto",children:e.jsx("code",{className:"text-xs font-mono text-text-1 leading-relaxed whitespace-pre",children:a})})]})}function ALe(t){if(!t)return[];const a=t.split(`
8604
+ `,{label:"if",detail:"block",type:"keyword"}),xt("if ${}:\n ${}\nelse:\n ${}",{label:"if",detail:"/ else block",type:"keyword"}),xt("class ${name}:\n def __init__(self, ${params}):\n ${}",{label:"class",detail:"definition",type:"keyword"}),xt("import ${module}",{label:"import",detail:"statement",type:"keyword"}),xt("from ${module} import ${names}",{label:"from",detail:"import",type:"keyword"})],C$e=QX(WH,LX(_$e.concat($$e)));function GT(t){let{node:a,pos:s}=t,c=t.lineIndent(s,-1),r=null;for(;;){let l=a.childBefore(s);if(l)if(l.name=="Comment")s=l.from;else if(l.name=="Body"||l.name=="MatchBody")t.baseIndentFor(l)+t.unit<=c&&(r=l),a=l;else if(l.name=="MatchClause")a=l;else if(l.type.is("Statement"))a=l;else break;else break}return r}function WT(t,a){let s=t.baseIndentFor(a),c=t.lineAt(t.pos,-1),r=c.from+c.text.length;return/^\s*($|#)/.test(c.text)&&t.node.to<r+100&&!/\S/.test(t.state.sliceDoc(r,t.node.to))&&t.lineIndent(t.pos,-1)<=s||/^\s*(else:|elif |except |finally:|case\s+[^=:]+:)/.test(t.textAfter)&&t.lineIndent(t.pos,-1)>s?null:s+t.unit}const YT=tu.define({name:"python",parser:j$e.configure({props:[s0.add({Body:t=>{var a;let s=/^\s*(#|$)/.test(t.textAfter)&&GT(t)||t.node;return(a=WT(t,s))!==null&&a!==void 0?a:t.continue()},MatchBody:t=>{var a;let s=GT(t);return(a=WT(t,s||t.node))!==null&&a!==void 0?a:t.continue()},IfStatement:t=>/^\s*(else:|elif )/.test(t.textAfter)?t.baseIndent:t.continue(),"ForStatement WhileStatement":t=>/^\s*else:/.test(t.textAfter)?t.baseIndent:t.continue(),TryStatement:t=>/^\s*(except[ :]|finally:|else:)/.test(t.textAfter)?t.baseIndent:t.continue(),MatchStatement:t=>/^\s*case /.test(t.textAfter)?t.baseIndent+t.unit:t.continue(),"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression":Dh({closing:")"}),"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression":Dh({closing:"}"}),"ArrayExpression ArrayComprehensionExpression":Dh({closing:"]"}),MemberExpression:t=>t.baseIndent+t.unit,"String FormatString":()=>null,Script:t=>{var a;let s=GT(t);return(a=s&&WT(t,s))!==null&&a!==void 0?a:t.continue()}}),z1.add({"ArrayExpression DictionaryExpression SetExpression TupleExpression":$Q,Body:(t,a)=>({from:t.from+1,to:t.to-(t.to==a.doc.length?0:1)}),"String FormatString":(t,a)=>({from:a.doc.lineAt(t.from).to,to:t.to})})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"'''",'"""'],stringPrefixes:["f","fr","rf","r","u","b","br","rb","F","FR","RF","R","U","B","BR","RB"]},commentTokens:{line:"#"},indentOnInput:/^\s*([\}\]\)]|else:|elif |except |finally:|case\s+[^:]*:?)$/}});function Q$e(){return new N1(YT,[YT.data.of({autocomplete:N$e}),YT.data.of({autocomplete:C$e})])}const Vh={javascript:()=>xP({jsx:!0,typescript:!1}),typescript:()=>xP({jsx:!0,typescript:!0}),css:()=>HU(),html:()=>uH(),json:()=>SNe(),markdown:()=>u_e(),python:()=>Q$e()},L$e=Yd.theme({"&":{backgroundColor:"#24282f",color:"#bcc2cd",fontFamily:"var(--font-mono)",fontSize:"13px",height:"100%"},".cm-scroller":{overflow:"auto"},".cm-content":{caretColor:"#33afbc"},".cm-cursor":{borderLeftColor:"#33afbc"},".cm-gutters":{backgroundColor:"#24282f",borderRight:"1px solid #2c313a",color:"#505862"},".cm-activeLineGutter":{backgroundColor:"#2c313a"},".cm-activeLine":{backgroundColor:"rgba(44, 49, 58, 0.5)"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground":{backgroundColor:"rgba(51, 175, 188, 0.15)"},".cm-panels":{backgroundColor:"#24282f",borderBottom:"1px solid #3e4451"},".cm-panels.cm-panels-top":{borderBottom:"1px solid #3e4451"},".cm-panels.cm-panels-bottom":{borderTop:"1px solid #3e4451"},".cm-search":{padding:"6px 8px",gap:"4px",fontFamily:"var(--font-sans)",fontSize:"12px",display:"flex",flexWrap:"wrap",alignItems:"center"},".cm-search label":{display:"flex",alignItems:"center",gap:"4px",color:"#8b929e",fontSize:"11px"},".cm-search input, .cm-search .cm-textfield":{backgroundColor:"#1a1e25",border:"1px solid #2c313a",borderRadius:"4px",color:"#e6e6e6",padding:"2px 6px",fontSize:"12px",fontFamily:"var(--font-mono)",outline:"none"},".cm-search input:focus, .cm-search .cm-textfield:focus":{borderColor:"#33afbc"},".cm-search .cm-button, .cm-button":{backgroundColor:"#2c313a",border:"1px solid #3e4451",borderRadius:"4px",color:"#bcc2cd",padding:"2px 8px",fontSize:"11px",fontFamily:"var(--font-sans)",cursor:"pointer",backgroundImage:"none"},".cm-search .cm-button:hover, .cm-button:hover":{backgroundColor:"#333842",color:"#e6e6e6"},".cm-search .cm-button:active":{backgroundColor:"#3a3f4b"},".cm-search br":{display:"none"},".cm-panel.cm-search [name=close]":{color:"#6e7681",cursor:"pointer",padding:"0 4px"},".cm-panel.cm-search [name=close]:hover":{color:"#e6e6e6"},".cm-searchMatch":{backgroundColor:"rgba(51, 175, 188, 0.2)",outline:"1px solid rgba(51, 175, 188, 0.4)"},".cm-searchMatch-selected":{backgroundColor:"rgba(51, 175, 188, 0.35)"}},{dark:!0});function pX({content:t,language:a,onChange:s,onSave:c,onCursorChange:r,viewRef:l}){const u=O.useRef(null),p=O.useRef(null),f=O.useRef(new nY),x=O.useRef(s),g=O.useRef(c),y=O.useRef(r);return x.current=s,g.current=c,y.current=r,O.useEffect(()=>{if(!u.current)return;const k=Vh[a]||Vh.javascript,b=aP.of([{key:"Mod-s",run:()=>{var S;return(S=g.current)==null||S.call(g),!0}}]),j=AX.create({doc:t||"",extensions:[oY(),cY(),rY(),iY(),lY(),dY(),uY(),aP.of([...hY,...pY,...fY]),b,sY,L$e,f.current.of(k()),Yd.updateListener.of(S=>{var M,$;if(S.docChanged&&((M=x.current)==null||M.call(x,S.state.doc.toString())),S.selectionSet||S.docChanged){const C=S.state.selection.main.head,_=S.state.doc.lineAt(C);($=y.current)==null||$.call(y,{line:_.number,col:C-_.from+1})}})]}),w=new Yd({state:j,parent:u.current});return p.current=w,l&&(l.current=w),()=>{w.destroy(),p.current=null,l&&(l.current=null)}},[]),O.useEffect(()=>{const k=p.current;if(!k)return;const b=k.state.doc.toString();t!==b&&k.dispatch({changes:{from:0,to:b.length,insert:t||""}})},[t]),O.useEffect(()=>{const k=p.current;if(!k)return;const b=Vh[a]||Vh.javascript;k.dispatch({effects:f.current.reconfigure(b())})},[a]),e.jsx("div",{ref:u,className:"w-full h-full overflow-hidden"})}const z$e=["png","jpg","jpeg","gif","svg","webp","ico","bmp","avif"],YH=["mp4","webm","mov","avi","mkv","ogv"];function T$e(t){var s;const a=(s=t.split(".").pop())==null?void 0:s.toLowerCase();return z$e.includes(a)||YH.includes(a)}function P$e({path:t}){var l;const a=(l=t.split(".").pop())==null?void 0:l.toLowerCase(),s=`/api/files/raw?path=${encodeURIComponent(t)}`,c=t.split("/").pop(),r=YH.includes(a);return e.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center bg-surface-0 p-8 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-3 font-sans",children:[e.jsx(ge,{children:a==null?void 0:a.toUpperCase()}),e.jsx("span",{className:"font-mono",children:c}),e.jsx("a",{href:s,target:"_blank",rel:"noopener",className:"text-accent hover:text-accent/80 transition-colors",children:e.jsx(Pt,{size:12})})]}),r?e.jsx("video",{src:s,controls:!0,className:"max-w-full max-h-[70vh] rounded-md border border-border"}):e.jsx("img",{src:s,alt:c,className:"max-w-full max-h-[70vh] rounded-md border border-border object-contain"})]})}const A$e={javascript:"JavaScript",typescript:"TypeScript",css:"CSS",html:"HTML",json:"JSON",markdown:"Markdown",python:"Python"};function q$e({cursorPos:t,language:a}){return e.jsxs("div",{className:"flex items-center justify-between h-6 px-3 bg-surface-1 border-t border-border-subtle text-2xs font-sans text-text-3 flex-shrink-0 select-none",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("span",{children:["Ln ",t.line,", Col ",t.col]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"cursor-default",children:A$e[a]||a||"Plain Text"}),e.jsx("span",{children:"Spaces: 2"}),e.jsx("span",{children:"UTF-8"})]})]})}function I$e({currentLine:t,onGoto:a,onClose:s}){const[c,r]=O.useState(""),l=O.useRef(null);O.useEffect(()=>{var p;(p=l.current)==null||p.focus()},[]);function u(p){if(p.key==="Enter"){const f=parseInt(c,10);f>0&&a(f),s()}p.key==="Escape"&&s()}return e.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20 flex items-center gap-2 bg-surface-2 border border-border rounded-lg shadow-xl p-2",children:[e.jsx("label",{className:"text-2xs font-sans text-text-3 whitespace-nowrap",children:"Go to Line:"}),e.jsx("input",{ref:l,value:c,onChange:p=>r(p.target.value),onKeyDown:u,onBlur:s,placeholder:String(t),className:"w-20 h-6 px-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-mono focus:outline-none focus:border-accent"})]})}function R$e({path:t}){if(!t)return null;const a=t.split("/").filter(Boolean);return e.jsx("div",{className:"flex items-center h-7 px-3 bg-surface-2 border-b border-border-subtle text-2xs font-sans text-text-3 overflow-hidden flex-shrink-0 select-none",children:a.map((s,c)=>{const r=c===a.length-1;return e.jsxs("span",{className:"flex items-center min-w-0",children:[c>0&&e.jsx(Xt,{size:10,className:"mx-0.5 flex-shrink-0 text-text-4"}),e.jsx("span",{className:r?"text-text-1 font-medium truncate":"hover:text-text-1 cursor-pointer truncate transition-colors",children:s})]},c)})})}function V$e(t){var s;const a=(s=t==null?void 0:t.split(".").pop())==null?void 0:s.toLowerCase();return a==="html"||a==="htm"}const E$e=240,X$e=160,Z$e=400;function D$e(){const t=q(oe=>oe.editorActiveFile),a=q(oe=>oe.editorFiles),s=q(oe=>oe.editorChangedFiles),c=q(oe=>oe.updateFileContent),r=q(oe=>oe.saveFile),l=q(oe=>oe.reloadFile),u=q(oe=>oe.dismissFileChange),p=q(oe=>oe.editorSidebarWidth),f=q(oe=>oe.setEditorSidebarWidth),[x,g]=O.useState(""),[y,k]=O.useState(!1),[b,j]=O.useState(0),[w,S]=O.useState({line:1,col:1}),[M,$]=O.useState(!1),C=O.useRef(null),_=O.useRef(!1),P=O.useRef(0),L=O.useRef(0);O.useEffect(()=>{X.get("/files/root").then(oe=>g(oe.root||"")).catch(()=>{})},[]),O.useEffect(()=>{k(!1)},[t]),O.useEffect(()=>{function oe(R){(R.metaKey||R.ctrlKey)&&R.key==="g"&&(R.preventDefault(),$(!0))}return document.addEventListener("keydown",oe),()=>document.removeEventListener("keydown",oe)},[]);const A=O.useCallback(oe=>{oe.preventDefault(),_.current=!0,P.current=oe.clientX,L.current=p;function R(T){if(!_.current)return;const Z=T.clientX-P.current,J=Math.min(Math.max(L.current+Z,X$e),Z$e);f(J)}function I(){_.current=!1,document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",I)}document.addEventListener("mousemove",R),document.addEventListener("mouseup",I)},[p,f]);function z(oe){const R=C.current;if(!R)return;const I=R.state.doc.line(Math.min(oe,R.state.doc.lines));R.dispatch({selection:{anchor:I.from},scrollIntoView:!0}),R.focus()}const Y=t?a[t]:null,V=t&&T$e(t),se=t&&V$e(t),ne=t&&s[t];return e.jsxs("div",{className:"flex h-full",children:[e.jsxs("div",{className:"flex-shrink-0 border-r border-border relative",style:{width:p},children:[e.jsx(tje,{rootDir:x}),e.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:A,onDoubleClick:()=>f(E$e)})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsx(aje,{}),t&&!V&&e.jsx(R$e,{path:t}),e.jsxs("div",{className:"flex-1 relative min-h-0",children:[M&&e.jsx(I$e,{currentLine:w.line,onGoto:z,onClose:()=>$(!1)}),ne&&e.jsxs("div",{className:"absolute top-0 left-0 right-0 z-10 flex items-center gap-2 px-4 py-2 bg-warning/10 border-b border-warning/20",children:[e.jsx(Et,{size:14,className:"text-warning"}),e.jsx("span",{className:"text-xs text-warning font-sans flex-1",children:"File modified externally"}),e.jsxs(he,{variant:"ghost",size:"sm",onClick:()=>l(t),children:[e.jsx(ia,{size:12})," Reload"]}),e.jsxs(he,{variant:"ghost",size:"sm",onClick:()=>u(t),children:[e.jsx(st,{size:12})," Dismiss"]})]}),!t&&e.jsx("div",{className:"w-full h-full flex items-center justify-center text-text-4 font-sans",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(ra,{size:32,className:"mx-auto"}),e.jsx("p",{className:"text-sm",children:"Open a file from the tree"})]})}),t&&V&&e.jsx(P$e,{path:t}),t&&!V&&se&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"absolute top-0 right-4 z-10 flex items-center gap-0.5 mt-2 bg-surface-2 border border-border-subtle rounded-md p-0.5",children:[e.jsxs("button",{onClick:()=>k(!1),className:K("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",y?"text-text-3 hover:text-text-1":"bg-surface-4 text-text-0 font-medium"),children:[e.jsx(g2,{size:12})," Code"]}),e.jsxs("button",{onClick:()=>{k(!0),j(oe=>oe+1)},className:K("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",y?"bg-surface-4 text-text-0 font-medium":"text-text-3 hover:text-text-1"),children:[e.jsx(ka,{size:12})," Preview"]})]}),y?e.jsx("iframe",{src:`/api/files/raw?path=${encodeURIComponent(t)}`,className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin",title:"HTML Preview"},b):Y&&e.jsx(pX,{content:Y.content,language:Y.language,onChange:oe=>c(t,oe),onSave:()=>r(t),onCursorChange:S,viewRef:C})]}),t&&!V&&!se&&Y&&e.jsx(pX,{content:Y.content,language:Y.language,onChange:oe=>c(t,oe),onSave:()=>r(t),onCursorChange:S,viewRef:C})]}),t&&!V&&e.jsx(q$e,{cursorPos:w,language:Y==null?void 0:Y.language})]})]})}function U$e(){var C;const t=q(_=>_.connected),a=q(_=>_.agents),[s,c]=O.useState(null),[r,l]=O.useState([]),[u,p]=O.useState({constraints:[],discoveries:[],roles:[],specializations:null}),[f,x]=O.useState(!0),[g,y]=O.useState({tokens:[],cost:[],saved:[],efficiency:[],cache:[],inputOutput:[],agents:[],turns:[]}),k=O.useRef(0);O.useEffect(()=>{if(!t)return;let _=!0;async function P(){try{const[A,z,Y,V,se,ne]=await Promise.all([X.get("/dashboard"),X.get("/tokens/by-team").catch(()=>({teams:[]})),X.get("/memory/constraints").catch(()=>({constraints:[]})),X.get("/memory/discoveries?limit=20").catch(()=>({discoveries:[]})),X.get("/memory/handoff-chain").catch(()=>({roles:[]})),X.get("/memory/specializations").catch(()=>({perAgent:{},perProjectRole:{}}))]);if(!_)return;c(A),l((z==null?void 0:z.teams)||[]),p({constraints:(Y==null?void 0:Y.constraints)||[],discoveries:(V==null?void 0:V.discoveries)||[],roles:(se==null?void 0:se.roles)||[],specializations:ne||{perAgent:{},perProjectRole:{}}}),x(!1),k.current=Date.now(),y(oe=>{var pe,fe,Oe,Se,ue,ve,it,Le,Mt;const R=Date.now(),I=(lt,pt)=>[...lt.slice(-59),{t:R,v:pt||0}],T=((pe=A.tokens)==null?void 0:pe.totalTokens)||0,Z=((fe=A.tokens)==null?void 0:fe.totalInputTokens)||0,J=((Oe=A.tokens)==null?void 0:Oe.totalOutputTokens)||0,U=(((Se=A.agents)==null?void 0:Se.breakdown)||[]).filter(lt=>{var pt;return((pt=lt.quality)==null?void 0:pt.score)!=null}),xe=U.length>0?U.reduce((lt,pt)=>lt+pt.quality.score,0)/U.length:0;return{tokens:I(oe.tokens,T),cost:I(oe.cost,(ue=A.tokens)==null?void 0:ue.totalCostUsd),saved:I(oe.saved,xe),efficiency:I(oe.efficiency,((ve=A.rotation)==null?void 0:ve.totalRotations)||0),cache:I(oe.cache,(it=A.tokens)==null?void 0:it.cacheHitRate),inputOutput:I(oe.inputOutput,J>0?Z/J:0),agents:I(oe.agents,((Le=A.agents)==null?void 0:Le.running)||0),turns:I(oe.turns,(Mt=A.tokens)==null?void 0:Mt.totalTurns)}})}catch{_&&x(!1)}}P();const L=setInterval(P,4e3);return()=>{_=!1,clearInterval(L)}},[t]);const b=((C=s==null?void 0:s.agents)==null?void 0:C.breakdown)||[],j=(s==null?void 0:s.routing)||null,w=(s==null?void 0:s.rotation)||null,S=(s==null?void 0:s.adaptive)||[],M=(s==null?void 0:s.journalist)||null,$=(w==null?void 0:w.rotating)||[];return{data:s,loading:f,agents:a,connected:t,kpiHistory:g,lastFetch:k.current,agentBreakdown:b,routing:j,rotation:w,adaptive:S,journalist:M,rotating:$,teamBurn:r,memory:u}}const fX=O.memo(function({connected:a,runningCount:s,totalCount:c,uptime:r,lastFetch:l,activeTeam:u}){return e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border",children:[e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Command Center"}),u&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-xs font-mono text-text-2",children:u.name})]}),e.jsx("div",{className:"flex-1"}),a&&e.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-text-1",children:s}),e.jsxs("span",{className:"text-text-3",children:["/",c]}),e.jsx("span",{className:"ml-1 text-text-3",children:"agents"})]}),r>0&&e.jsxs("span",{className:"text-text-3",children:["Up ",su(r)]}),l>0&&e.jsxs("span",{className:"flex items-center gap-1 text-text-4",children:[e.jsx(ia,{size:9}),e.jsx("span",{children:gt(l)})]})]}),e.jsx(aa,{status:a?"running":"crashed",size:"sm"})]})});function ct(t,a){const s=parseInt(t.slice(1,3),16),c=parseInt(t.slice(3,5),16),r=parseInt(t.slice(5,7),16);return`rgba(${s},${c},${r},${a})`}const ce={surface0:"#1a1e25",surface3:"#282c34",surface4:"#2c313a",surface5:"#333842",text0:"#e6e6e6",text1:"#bcc2cd",text2:"#8b929e",text3:"#6e7681",text4:"#505862",accent:"#33afbc",success:"#4ae168",warning:"#e5c07b",danger:"#e06c75",info:"#61afef",purple:"#c678dd",orange:"#d19a66"};function H$e({data:t,color:a=ce.accent,width:s=72,height:c=22}){if(!t||t.length<2)return e.jsx("div",{style:{width:s,height:c}});const r=t.map(g=>g.v),l=Math.min(...r),p=Math.max(...r)-l||1,f=t.map((g,y)=>{const k=y/(t.length-1)*s,b=c-(g.v-l)/p*(c-2)-1;return`${k},${b}`}).join(" "),x=`kpi-${a.replace("#","")}`;return e.jsxs("svg",{width:s,height:c,className:"flex-shrink-0",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:x,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:a,stopOpacity:"0.2"}),e.jsx("stop",{offset:"100%",stopColor:a,stopOpacity:"0"})]})}),e.jsx("polygon",{points:`0,${c} ${f} ${s},${c}`,fill:`url(#${x})`}),e.jsx("polyline",{points:f,fill:"none",stroke:a,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}const B$e=O.memo(function({label:a,value:s,sparkData:c,color:r=ce.accent,hint:l,className:u}){return e.jsxs("div",{className:K("flex items-center gap-2.5 px-3 py-2.5 min-w-0","bg-surface-1",u),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5 truncate flex items-center gap-1",children:[a,l&&e.jsx($1,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:l}),side:"bottom",children:e.jsx(Wt,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),e.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:s})]}),e.jsx(H$e,{data:c,color:r})]})});function G$e({kpis:t}){return e.jsx("div",{className:"flex flex-wrap border-b border-border",style:{background:"var(--color-surface-0)"},children:t.map(a=>e.jsx(B$e,{label:a.label,value:a.value,sparkData:a.sparkData,color:a.color,hint:a.hint,className:K("flex-1 basis-[12.5%] min-w-[140px]","border-b border-r border-border")},a.label))})}const W$e={actual:"ACT",estimated:"EST",local:"LOC"};function Y$e(t){if(!t||t==="auto"||t==="default")return"default";const a=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return a?`${a[1][0].toUpperCase()}${a[1].slice(1)} ${a[2]}.${a[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gem ").replace("-preview",""):t.length>12?t.slice(0,12)+"...":t}const F$e=O.memo(function({agent:a,isRotating:s}){const c=a.status==="running"||a.status==="starting",r=Math.round((a.contextUsage||0)*100),l=s?"#c678dd":XP(a.status),u=a.quality,p=(u==null?void 0:u.toolSuccessRate)!=null?Math.round(u.toolSuccessRate*100):null,f=a.rotationThreshold?Math.round(a.rotationThreshold*100):null,x=Bo(a.role),g=r>80?ce.danger:r>60?ce.warning:ce.accent;return e.jsxs("div",{className:"px-3 pl-6 py-2 hover:bg-[rgba(51,175,188,0.06)] transition-colors space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:l}}),c&&e.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:l,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate leading-none flex-shrink-0 max-w-[80px]",children:a.name}),e.jsx("span",{className:"text-2xs font-mono font-semibold px-1.5 py-px rounded-sm flex-shrink-0 capitalize",style:{background:x.bg,color:x.text},children:(a.role||"").toLowerCase()}),e.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1 py-px rounded-sm flex-shrink-0 truncate max-w-[72px]",children:Y$e(a.model)}),e.jsx("div",{className:"flex-1"}),p!=null&&e.jsxs("span",{className:"text-2xs font-mono font-bold px-1 py-px rounded-sm flex-shrink-0",style:{color:p>=90?"#4ae168":p>=70?"#e5c07b":"#e06c75",background:p>=90?"rgba(74,225,104,0.1)":p>=70?"rgba(229,192,123,0.1)":"rgba(224,108,117,0.1)"},children:[p,"%"]}),a.costSource&&a.costSource!=="actual"&&e.jsx("span",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex-shrink-0",children:W$e[a.costSource]||""}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[e.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums leading-none",children:Fe(a.tokens||0)}),(a.costUsd||0)>0&&e.jsx("div",{className:"text-2xs font-mono text-text-3 mt-0.5",children:Jo(a.costUsd)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 h-0.5 rounded-sm overflow-visible",style:{background:ct(ce.accent,.12)},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 rounded-sm transition-all duration-700",style:{width:`${Math.max(r,1)}%`,background:g}}),f&&e.jsx("div",{className:"absolute top-[-1px] w-px h-[4px]",style:{left:`${f}%`,background:ce.purple},title:`Rotation at ${f}%`})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums flex-shrink-0 w-7 text-right",children:[r,"%"]})]})]})});function K$e({team:t,members:a,rotatingSet:s}){const[c,r]=O.useState(!0),l=a.filter(x=>x.status==="running"||x.status==="starting").length,u=l>0,p=a.reduce((x,g)=>x+(g.tokens||0),0),f=a.reduce((x,g)=>x+(g.costUsd||0),0);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>r(x=>!x),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-[rgba(51,175,188,0.08)] bg-[rgba(51,175,188,0.05)]",style:{borderLeft:u?`2px solid ${ce.accent}`:"2px solid transparent"},children:[c?e.jsx(zt,{size:10,className:"text-text-4 flex-shrink-0"}):e.jsx(Xt,{size:10,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-mono font-semibold text-text-2 uppercase tracking-widest flex-1 truncate",children:t}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:Fe(p)}),f>0&&e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums ml-1",children:Jo(f)}),e.jsxs("span",{className:"text-2xs font-mono tabular-nums flex-shrink-0 ml-1.5",style:{color:u?ce.accent:void 0},children:[l,"/",a.length]})]}),c&&a.map(x=>e.jsx(F$e,{agent:x,isRotating:s.has(x.id)},x.id))]})}const J$e=O.memo(function({agentBreakdown:a,rotating:s=[],teams:c=[]}){if(!(a!=null&&a.length))return e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono p-4",children:"No agents"});const r={};for(const p of c)r[p.id]=p.name;const l={};for(const p of a){const f=p.teamId||"ungrouped";l[f]||(l[f]=[]),l[f].push(p)}const u=new Set(s);return e.jsx(It,{className:"flex-1",children:e.jsx("div",{className:"py-1",children:Object.entries(l).map(([p,f])=>e.jsx(K$e,{team:r[p]||(p==="ungrouped"?"Ungrouped":p),members:f,rotatingSet:u},p))})})}),eCe=O.memo(function({data:a}){const s=O.useRef(null),c=O.useRef(null),[r,l]=O.useState({width:0,height:0}),[u,p]=O.useState(null),{width:f,height:x}=r,g={top:28,right:12,bottom:8,left:12},y=Math.max(f-g.left-g.right,0),k=Math.max(x-g.top-g.bottom,0),b=O.useMemo(()=>!a||a.length<2?[]:a.slice(1).map((S,M)=>{const $=a[M],C=(S.t-$.t)/6e4,_=Math.max((S.tokens||0)-($.tokens||0),0);return{burnRate:C>0?Math.round(_/C):0,cacheHitRate:S.cacheHitRate||0,running:S.running||0,agents:S.agents||0,t:S.t}}),[a]);O.useEffect(()=>{const S=s.current;if(!S)return;const M=new ResizeObserver($=>{const{width:C,height:_}=$[0].contentRect;C>0&&_>0&&l({width:Math.floor(C),height:Math.floor(_)})});return M.observe(S),()=>M.disconnect()},[]);const j=O.useCallback(S=>{const M=c.current;if(!M||!b.length||y<=0)return;const $=M.getBoundingClientRect(),C=S.clientX-$.left-g.left;if(C<0||C>y){p(null);return}const _=Math.round(C/y*(b.length-1));p({x:g.left+_/Math.max(b.length-1,1)*y,index:_})},[b,y,g.left]),w=O.useCallback(()=>p(null),[]);return O.useEffect(()=>{const S=c.current;if(!S||!b.length||f<=0||x<=0||y<=0||k<=0)return;const M=S.getContext("2d"),$=window.devicePixelRatio||1;S.width=f*$,S.height=x*$,M.scale($,$),M.clearRect(0,0,f,x);const C=b.map(T=>T.burnRate),_=b.map(T=>T.cacheHitRate),P=b.map(T=>T.running),L=Math.max(...C,100),A=Math.max(...P,1),z=T=>g.left+T/Math.max(b.length-1,1)*y,Y=T=>g.top+k-T/L*k,V=T=>g.top+k-T*k,se=Math.max(y/b.length-1,2);for(let T=0;T<b.length;T++){const Z=P[T];if(Z<=0)continue;const J=Z/A*k*.3,W=z(T)-se/2,U=g.top+k-J;M.fillStyle=ct(ce.surface5,.5),M.fillRect(W,U,se,J)}M.setLineDash([2,4]),M.strokeStyle=ct(ce.text4,.2),M.lineWidth=1;for(let T=1;T<=3;T++){const Z=g.top+k/4*T;M.beginPath(),M.moveTo(g.left,Z),M.lineTo(g.left+y,Z),M.stroke()}M.setLineDash([]),M.font="9px 'JetBrains Mono Variable', monospace",M.textAlign="left",M.fillStyle=ct(ce.text3,.5),M.fillText(`${Fe(L)}/m`,g.left+4,g.top+10),M.fillText(`${Fe(Math.round(L/2))}/m`,g.left+4,g.top+k/2+4),M.beginPath(),M.moveTo(g.left,g.top+k);for(let T=0;T<b.length;T++)M.lineTo(z(T),Y(C[T]));M.lineTo(z(b.length-1),g.top+k),M.closePath();const ne=M.createLinearGradient(0,g.top,0,g.top+k);ne.addColorStop(0,ct(ce.accent,.2)),ne.addColorStop(.7,ct(ce.accent,.04)),ne.addColorStop(1,ct(ce.accent,0)),M.fillStyle=ne,M.fill(),M.beginPath(),M.strokeStyle=ce.accent,M.lineWidth=1.5,M.lineJoin="round";for(let T=0;T<b.length;T++){const Z=z(T),J=Y(C[T]);T===0?M.moveTo(Z,J):M.lineTo(Z,J)}M.stroke();const oe=_.some(T=>T>0);if(oe){M.beginPath(),M.strokeStyle=ct(ce.info,.45),M.lineWidth=1,M.lineJoin="round",M.setLineDash([2,3]);for(let T=0;T<b.length;T++){const Z=z(T),J=V(_[T]);T===0?M.moveTo(Z,J):M.lineTo(Z,J)}M.stroke(),M.setLineDash([])}M.font="9px 'Inter Variable', sans-serif",M.textAlign="right";let R=f-g.right-4;const I=14;if(oe&&(M.fillStyle=ct(ce.info,.5),M.fillText("Cache %",R,I),R-=M.measureText("Cache %").width+4,M.beginPath(),M.arc(R,I-3,2.5,0,Math.PI*2),M.fill(),R-=14),M.fillStyle=ct(ce.surface5,.7),M.fillText("Agents",R,I),R-=M.measureText("Agents").width+4,M.beginPath(),M.arc(R,I-3,2.5,0,Math.PI*2),M.fill(),R-=14,M.fillStyle=ce.accent,M.fillText("Burn Rate",R,I),R-=M.measureText("Burn Rate").width+4,M.beginPath(),M.arc(R,I-3,2.5,0,Math.PI*2),M.fill(),u&&u.index>=0&&u.index<b.length){const T=u.x,Z=b[u.index];M.beginPath(),M.moveTo(T,g.top),M.lineTo(T,g.top+k),M.strokeStyle=ct(ce.text1,.15),M.lineWidth=1,M.stroke();const J=Y(Z.burnRate);M.beginPath(),M.arc(T,J,3,0,Math.PI*2),M.fillStyle=ce.accent,M.fill();const W=[{label:"Burn",value:`${Fe(Z.burnRate)}/m`,color:ce.accent},{label:"Cache",value:xn(Z.cacheHitRate*100),color:ce.info},{label:"Agents",value:`${Z.running}/${Z.agents}`,color:ce.text2}],U=104,xe=W.length*16+12;let pe=T+12;pe+U>f-8&&(pe=T-U-12);const fe=Math.max(g.top,J-xe/2);M.fillStyle=ct(ce.surface0,.92),M.beginPath(),M.roundRect(pe,fe,U,xe,4),M.fill(),M.strokeStyle=ct(ce.text4,.2),M.lineWidth=1,M.stroke(),M.textAlign="left",W.forEach((Oe,Se)=>{const ue=fe+14+Se*16;M.beginPath(),M.arc(pe+8,ue-3,2,0,Math.PI*2),M.fillStyle=Oe.color,M.fill(),M.font="8px 'Inter Variable', sans-serif",M.fillStyle=ce.text3,M.fillText(Oe.label,pe+14,ue),M.font="9px 'JetBrains Mono Variable', monospace",M.fillStyle=ce.text0,M.textAlign="right",M.fillText(Oe.value,pe+U-8,ue),M.textAlign="left"})}},[b,f,x,u,y,k,g]),e.jsx("div",{ref:s,className:"absolute inset-0",children:f>0&&x>0&&e.jsx("canvas",{ref:c,style:{width:f,height:x},className:"block cursor-crosshair",onMouseMove:j,onMouseLeave:w})})}),tCe=O.memo(function({cacheRead:a=0,cacheCreation:s=0,totalInput:c=0,size:r=140}){const l=O.useRef(null),u=a+s,p=u,f=u>0?a/u*100:0;return O.useEffect(()=>{const x=l.current;if(!x)return;const g=window.devicePixelRatio||1;x.width=r*g,x.height=r*g;const y=x.getContext("2d");y.scale(g,g),y.clearRect(0,0,r,r);const k=r/2,b=r/2,j=(r-12)/2,w=5,S=135*Math.PI/180,M=405*Math.PI/180,$=M-S;if(y.beginPath(),y.arc(k,b,j,S,M),y.strokeStyle=ce.surface4,y.lineWidth=w,y.lineCap="round",y.stroke(),p>0){const C=a/p,_=s/p;if(C>0){const P=S+$*C;y.beginPath(),y.arc(k,b,j,S,P),y.strokeStyle=ce.accent,y.lineWidth=w,y.lineCap="round",y.stroke()}if(_>0){const P=S+$*C,L=P+$*_;y.beginPath(),y.arc(k,b,j,P,L),y.strokeStyle=ce.purple,y.lineWidth=w,y.lineCap="butt",y.stroke()}}y.textAlign="center",y.textBaseline="middle",y.font=`600 ${r*.2}px 'JetBrains Mono Variable', monospace`,y.fillStyle=ce.text0,y.fillText(`${Math.round(f)}%`,k,b-3),y.font=`500 ${r*.08}px 'JetBrains Mono Variable', monospace`,y.fillStyle=ce.text3,y.fillText("CACHE",k,b+r*.13)},[a,s,c,r,p,f]),e.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-3 py-3",children:[e.jsx("canvas",{ref:l,className:"flex-shrink-0",style:{width:r,height:r}}),e.jsxs("div",{className:"w-full mt-3 space-y-1.5 max-w-[160px]",children:[e.jsx(FT,{color:ce.accent,label:"Read",value:Fe(a)}),e.jsx(FT,{color:ce.purple,label:"Create",value:Fe(s)}),e.jsx(FT,{color:ce.surface5,label:"Miss",value:Fe(Math.max(c-a-s,0))})]})]})});function FT({color:t,label:a,value:s}){return e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:t}}),e.jsx("span",{className:"text-text-3 uppercase tracking-wider flex-1",children:a}),e.jsx("span",{className:"text-text-1 tabular-nums",children:s})]})}const xX={heavy:ce.danger,medium:ce.warning,light:ce.success},mX={heavy:"Heavy",medium:"Medium",light:"Light"},aCe=O.memo(function({routing:a,agentBreakdown:s}){if(!a)return null;const{byTier:c={},totalDecisions:r=0,autoRoutedCount:l=0}=a,u=["heavy","medium","light"],p=u.reduce((y,k)=>y+(c[k]||0),0),f={};for(const y of s||[]){const k=y.model||"default";f[k]||(f[k]={tokens:0,agents:0}),f[k].tokens+=y.tokens||0,f[k].agents+=1}const x=Object.entries(f).sort((y,k)=>k[1].tokens-y[1].tokens),g=x.length>0?x[0][1].tokens:0;return e.jsxs("div",{className:"flex flex-col h-full px-3 py-3 overflow-y-auto",children:[p>0&&e.jsxs("div",{className:"space-y-1.5 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Tier Distribution"}),e.jsxs("span",{className:"text-2xs font-mono text-text-4 ml-auto tabular-nums",children:[Fe(p)," decisions"]})]}),e.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden flex",children:u.map(y=>{const k=c[y]||0;if(k===0)return null;const b=k/p*100;return e.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${b}%`,background:xX[y]},title:`${mX[y]}: ${k} (${Math.round(b)}%)`},y)})}),e.jsx("div",{className:"flex items-center gap-3",children:u.map(y=>{const k=c[y]||0;if(k===0)return null;const b=p>0?k/p*100:0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:xX[y]}}),e.jsx("span",{className:"text-2xs font-mono text-text-2",children:mX[y]}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums",children:xn(b)})]},y)})})]}),x.length>0&&e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Models in Use"}),l>0&&e.jsxs("span",{className:"text-2xs font-mono text-text-4 ml-auto",children:[l," auto"]})]}),e.jsx("div",{className:"space-y-1.5",children:x.map(([y,k])=>{const b=g>0?k.tokens/g*100:0;return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 flex-1 truncate",children:nCe(y)}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[k.agents," agent",k.agents!==1?"s":""]}),e.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:Fe(k.tokens)})]}),e.jsx("div",{className:"h-0.5 bg-surface-4 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.max(b,2)}%`,background:ce.accent}})})]},y)})})]}),p===0&&x.length===0&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono",children:"No routing data"})]})});function nCe(t){if(!t||t==="auto"||t==="default")return"Default";const a=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return a?`${a[1][0].toUpperCase()}${a[1].slice(1)} ${a[2]}.${a[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gemini ").replace("-preview",""):t}var YQ="Tabs",[sCe]=Ys(YQ,[ZQ]),FH=ZQ(),[oCe,wA]=sCe(YQ),KH=O.forwardRef((t,a)=>{const{__scopeTabs:s,value:c,onValueChange:r,defaultValue:l,orientation:u="horizontal",dir:p,activationMode:f="automatic",...x}=t,g=XQ(p),[y,k]=qQ({prop:c,onChange:r,defaultProp:l??"",caller:YQ});return e.jsx(oCe,{scope:s,baseId:$d(),value:y,onValueChange:k,orientation:u,dir:g,activationMode:f,children:e.jsx(Ye.div,{dir:g,"data-orientation":u,...x,ref:a})})});KH.displayName=YQ;var JH="TabsList",eB=O.forwardRef((t,a)=>{const{__scopeTabs:s,loop:c=!0,...r}=t,l=wA(JH,s),u=FH(s);return e.jsx(zD,{asChild:!0,...u,orientation:l.orientation,dir:l.dir,loop:c,children:e.jsx(Ye.div,{role:"tablist","aria-orientation":l.orientation,...r,ref:a})})});eB.displayName=JH;var tB="TabsTrigger",aB=O.forwardRef((t,a)=>{const{__scopeTabs:s,value:c,disabled:r=!1,...l}=t,u=wA(tB,s),p=FH(s),f=oB(u.baseId,c),x=cB(u.baseId,c),g=c===u.value;return e.jsx(TD,{asChild:!0,...p,focusable:!r,active:g,children:e.jsx(Ye.button,{type:"button",role:"tab","aria-selected":g,"aria-controls":x,"data-state":g?"active":"inactive","data-disabled":r?"":void 0,disabled:r,id:f,...l,ref:a,onMouseDown:$e(t.onMouseDown,y=>{!r&&y.button===0&&y.ctrlKey===!1?u.onValueChange(c):y.preventDefault()}),onKeyDown:$e(t.onKeyDown,y=>{[" ","Enter"].includes(y.key)&&u.onValueChange(c)}),onFocus:$e(t.onFocus,()=>{const y=u.activationMode!=="manual";!g&&!r&&y&&u.onValueChange(c)})})})});aB.displayName=tB;var nB="TabsContent",sB=O.forwardRef((t,a)=>{const{__scopeTabs:s,value:c,forceMount:r,children:l,...u}=t,p=wA(nB,s),f=oB(p.baseId,c),x=cB(p.baseId,c),g=c===p.value,y=O.useRef(g);return O.useEffect(()=>{const k=requestAnimationFrame(()=>y.current=!1);return()=>cancelAnimationFrame(k)},[]),e.jsx(la,{present:r||g,children:({present:k})=>e.jsx(Ye.div,{"data-state":g?"active":"inactive","data-orientation":p.orientation,role:"tabpanel","aria-labelledby":f,hidden:!k,id:x,tabIndex:0,...u,ref:a,style:{...t.style,animationDuration:y.current?"0s":void 0},children:k&&l})})});sB.displayName=nB;function oB(t,a){return`${t}-trigger-${a}`}function cB(t,a){return`${t}-content-${a}`}var cCe=KH,rCe=eB,iCe=aB,lCe=sB;function MA({children:t,...a}){return e.jsx(cCe,{...a,children:t})}function jA({children:t,className:a,...s}){return e.jsx(rCe,{className:K("flex items-center gap-0 border-b border-border-subtle",a),...s,children:t})}function kn({children:t,className:a,...s}){return e.jsx(iCe,{className:K("px-3 py-2 text-sm font-medium font-sans text-text-2","border-b-2 border-transparent","hover:text-text-0 hover:bg-surface-5/50","data-[state=active]:text-text-0 data-[state=active]:border-accent","transition-colors duration-100 cursor-pointer select-none","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a),...s,children:t})}function vn({children:t,className:a,...s}){return e.jsx(lCe,{className:K("flex-1 min-h-0",a),...s,children:t})}function yX({data:t,color:a=ce.accent,width:s=60,height:c=16}){if(!t||t.length<2)return e.jsx("div",{style:{width:s,height:c}});const r=Array.isArray(t[0])?t:t.map(x=>typeof x=="number"?x:x.v),l=Math.min(...r),p=Math.max(...r)-l||1,f=r.map((x,g)=>{const y=g/(r.length-1)*s,k=c-(x-l)/p*(c-2)-1;return`${y},${k}`}).join(" ");return e.jsx("svg",{width:s,height:c,className:"flex-shrink-0",children:e.jsx("polyline",{points:f,fill:"none",stroke:a,strokeWidth:"1",strokeLinejoin:"round",strokeOpacity:"0.7"})})}function Wn({text:t,side:a="bottom"}){return e.jsx($1,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:t}),side:a,children:e.jsx(Wt,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors inline-block ml-1"})})}function SA(t){return t==null?ce.text3:t>=70?"#4ae168":t>=40?"#e5c07b":"#e06c75"}function Po({label:t,value:a,danger:s}){return a==null||a===0?null:e.jsxs("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3",children:[t,": ",e.jsx("span",{style:{color:s?"#e06c75":ce.text1},children:a})]})}function dCe({score:t}){const a=Math.max(0,Math.min(100,t||0)),s=SA(t);return e.jsx("div",{className:"h-0.5 rounded-sm overflow-hidden flex-1",style:{background:"rgba(51,175,188,0.08)"},children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-700",style:{width:`${a}%`,background:s}})})}function KT({label:t,value:a,total:s,color:c}){const r=s>0?a/s*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-mono text-text-2",children:t}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs font-mono font-semibold tabular-nums",style:{color:c},children:[r>=1?Math.round(r):r>0?r.toFixed(1):0,"%"]}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums w-10 text-right",children:Fe(a)})]})]}),e.jsx("div",{className:"h-0.5 rounded-sm overflow-hidden",style:{background:"rgba(51,175,188,0.08)"},children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.min(r,100)}%`,background:c}})})]})}function uCe({tokens:t,rotation:a,agentBreakdown:s}){var k,b,j;const c=((a==null?void 0:a.history)||[]).slice(-10).reverse(),r=(a==null?void 0:a.liveScores)||{},l=(s||[]).filter(w=>w.status==="running"),u=s||[],p=u.filter(w=>{var S;return((S=w.quality)==null?void 0:S.score)!=null}),f=p.length>0?Math.round(p.reduce((w,S)=>w+S.quality.score,0)/p.length):null,x=u.filter(w=>w.status==="completed"||w.status==="stopped").length,g=u.filter(w=>w.status==="crashed").length,y=x+g>0?Math.round(x/(x+g)*100):100;return e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Quality",e.jsx(Wn,{text:"Average session quality score (0-100). Based on error rate, tool failures, repetitions, and file churn. Below 40 triggers auto-rotation to prevent wasted tokens."})]}),e.jsx("div",{className:"text-base font-mono font-bold text-text-1 tabular-nums leading-none",children:f??"—"})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Rotations",e.jsx(Wn,{text:"Context rotations: quality-based (q), context threshold (c), and natural compactions (n) from provider-managed context resets. Each rotation preserves progress via a journalist handoff brief."})]}),e.jsx("div",{className:"text-base font-mono font-bold text-text-1 tabular-nums leading-none",children:(a==null?void 0:a.totalRotations)||0}),((a==null?void 0:a.qualityRotations)>0||(a==null?void 0:a.contextRotations)>0||(a==null?void 0:a.naturalCompactions)>0)&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:[a.qualityRotations||0,"q / ",a.contextRotations||0,"c / ",a.naturalCompactions||0,"n"]})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Cache",e.jsx(Wn,{text:"Prompt cache hit rate. Cache reads are ~90% cheaper than regular input tokens. Managed by your AI provider — GROOVE tracks it, doesn't control it."})]}),e.jsx("div",{className:"text-base font-mono font-bold text-text-1 tabular-nums leading-none",children:xn(((t==null?void 0:t.cacheHitRate)||0)*100)})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Success",e.jsx(Wn,{text:"Agent completion rate. Completed agents vs. crashed agents. High success rate means agents are finishing tasks without errors."})]}),e.jsxs("div",{className:"text-base font-mono font-bold text-text-1 tabular-nums leading-none",children:[y,"%"]})]})]}),l.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Live Agent Quality"}),e.jsx("div",{className:"space-y-2",children:l.map(w=>{const S=w.quality||{},M=r[w.id],$=(M==null?void 0:M.score)??S.score,C=Bo(w.role);return e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("span",{className:"text-2xs font-mono font-semibold capitalize px-1.5 py-px rounded-sm",style:{background:C.bg,color:C.text},children:w.role}),e.jsx("span",{className:"text-xs font-mono text-text-1 truncate flex-1",children:w.name}),e.jsx("span",{className:"text-sm font-mono font-bold tabular-nums",style:{color:SA($)},children:$??"—"})]}),e.jsx(dCe,{score:$}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:[e.jsx(Po,{label:"Errors",value:S.errorCount,danger:!0}),e.jsx(Po,{label:"Reps",value:S.repetitions,danger:!0}),e.jsx(Po,{label:"Churn",value:S.fileChurn,danger:!0}),e.jsx(Po,{label:"Tools",value:S.toolCalls}),e.jsx(Po,{label:"Files",value:S.filesWritten}),S.toolCalls>0&&e.jsxs("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3",children:["Success: ",e.jsxs("span",{style:{color:S.toolSuccessRate>=.8?"#4ae168":"#e5c07b"},children:[Math.round(S.toolSuccessRate*100),"%"]})]}),S.eventCount>0&&e.jsxs("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3",children:["Events: ",e.jsx("span",{className:"text-text-2",children:S.eventCount})]})]})]},w.id)})})]}),((k=t==null?void 0:t.internalOverhead)==null?void 0:k.tokens)>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider flex items-center",children:["GROOVE Overhead",e.jsx(Wn,{text:"Tokens consumed by GROOVE's own coordination: the Journalist (synthesis), PM (approval gates), Planner, Task Negotiator, Gateway, and user Q&A. Previously invisible — now tracked for honest ROI."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums",children:[Fe(t.internalOverhead.tokens)," tokens"]}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:Jo(t.internalOverhead.costUsd||0)}),t.totalTokens>0&&e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums",style:{color:ce.purple},children:[Math.round(t.internalOverhead.tokens/t.totalTokens*100),"%"]})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:Object.entries(t.internalOverhead.components||{}).sort((w,S)=>(S[1].tokens||0)-(w[1].tokens||0)).slice(0,6).map(([w,S])=>{const M=w.replace(/^__|__$/g,"").replace(/_/g," ");return e.jsxs("div",{className:"bg-surface-0 rounded px-2 py-1.5",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider truncate",children:M}),e.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums font-semibold",children:Fe(S.tokens||0)})]},w)})})]}),(((b=t==null?void 0:t.savings)==null?void 0:b.total)||0)>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider flex items-center",children:["Coordination Savings",e.jsx(Wn,{text:"Tokens saved vs. uncoordinated agents. Rotation savings are estimated from context degradation (pre/post velocity measurement underway). Conflict prevention and cold-start skip use fixed-overhead models. Compare against GROOVE Overhead above for honest ROI."})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums",children:[Fe(t.savings.total)," tokens"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(KT,{label:"Cold-start skip",value:t.savings.fromColdStartSkip||0,total:t.savings.total||1,color:ce.info}),e.jsxs("div",{className:"text-2xs font-mono text-text-4 pl-2",children:["estimated · ",(((j=t==null?void 0:t.savings)==null?void 0:j.fromColdStartSkip)||0)>0?"fixed overhead per skip":""]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(KT,{label:"Rotation",value:t.savings.fromRotation||0,total:t.savings.total||1,color:ce.accent}),e.jsx("div",{className:"text-2xs font-mono text-text-4 pl-2",children:"estimated · velocity measurement accumulating"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(KT,{label:"Conflict prevention",value:t.savings.fromConflictPrevention||0,total:t.savings.total||1,color:"#4ec9d4"}),e.jsx("div",{className:"text-2xs font-mono text-text-4 pl-2",children:"estimated · fixed overhead per conflict"})]})]})]}),c.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2.5",children:"Recent Rotations"}),e.jsx("div",{className:"space-y-0",children:c.map((w,S)=>{var L,A;const M=w.reason==="quality_degradation",$=w.reason==="natural_compaction",C=w.reason==="token_limit_exceeded",_=w.reason==="runaway_velocity",P=C?"#e06c75":_?"#ff8c42":M?"#e5c07b":$?"#c678dd":"#33afbc";return e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsxs("div",{className:"flex flex-col items-center flex-shrink-0",children:[e.jsx("div",{className:"h-1.5"}),e.jsx("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:S===0?P:`${P}25`,border:`1px solid ${P}80`,boxShadow:S===0?`0 0 6px ${P}60`:"none"}}),S<c.length-1&&e.jsx("div",{className:"w-px flex-1 mt-1",style:{background:"rgba(51,175,188,0.15)",minHeight:"12px"}})]}),e.jsx("div",{className:K("flex-1 bg-surface-0 rounded px-2 py-1.5",S<c.length-1&&"mb-2"),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 font-medium capitalize truncate flex-1",children:w.agentName||w.role}),C?e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums flex-shrink-0",style:{color:"#e06c75"},title:`Auto-rotated: agent burned ${(L=w.instanceTokens)==null?void 0:L.toLocaleString()} tokens in one session`,children:["T:",xn((w.instanceTokens||0)/1e6*100).replace("%","M")]}):_?e.jsxs("span",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums",style:{color:"#ff8c42"},title:`Auto-rotated: runaway velocity (${(A=w.velocity)==null?void 0:A.toLocaleString()} tokens in recent window)`,children:["V:",xn((w.velocity||0)/1e6*100).replace("%","M")]}),w.velocityDelta!=null&&w.velocityDelta>0&&e.jsxs("span",{className:"text-2xs font-mono tabular-nums",style:{color:"#4ae168"},title:`Post-rotation velocity dropped by ${w.velocityDelta.toLocaleString()} tokens — rotation worked`,children:["↓",xn(w.velocityDelta/1e6*100).replace("%","M")]})]}):M?e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums flex-shrink-0",style:{color:"#e5c07b"},children:["Q:",w.qualityScore]}):$?e.jsxs("span",{className:"text-2xs font-mono font-semibold tabular-nums flex-shrink-0",style:{color:"#c678dd"},children:[xn((w.contextUsage||0)*100)," → ",xn((w.contextAfter||0)*100)]}):e.jsx("span",{className:"text-2xs font-mono font-semibold tabular-nums flex-shrink-0",style:{color:(w.contextUsage||0)>.8?"#e06c75":"#33afbc"},children:xn((w.contextUsage||0)*100)}),e.jsx("span",{className:"text-2xs font-mono text-text-4 flex-shrink-0",children:gt(w.timestamp)})]})})]},S)})})]}):e.jsxs("div",{className:"bg-surface-0 rounded p-3 text-center space-y-1.5",children:[e.jsx("div",{className:"text-xs font-mono text-text-2 font-semibold",children:"Monitoring for degradation"}),e.jsx("div",{className:"text-2xs font-mono text-text-3 leading-relaxed",children:"Auto-rotation triggers when session quality drops below 40 (errors, repetitions, file churn) or context exceeds the adaptive threshold."})]})]})}function hCe({adaptive:t}){if(!(t!=null&&t.length))return e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"bg-surface-0 rounded p-4 text-center space-y-2",children:[e.jsx("div",{className:"text-xs font-mono text-text-2 font-semibold",children:"No adaptive profiles yet"}),e.jsx("div",{className:"text-2xs font-mono text-text-3 leading-relaxed",children:"Adaptive thresholds learn when each agent role benefits from rotation. GROOVE tracks quality scores and adjusts rotation triggers automatically — converging to the optimal threshold per role and provider."})]})});function a(s){const c=s.split(":");return{provider:c[0]||s,role:c[1]||""}}return e.jsx("div",{className:"p-3 space-y-3",children:t.map(s=>{var g,y;const{provider:c,role:r}=a(s.key),l=r||c,u=((g=s.thresholdHistory)==null?void 0:g.length)>1,p=((y=s.recentScores)==null?void 0:y.length)>1,f=Bo(l),x=s.lastSignals;return e.jsxs("div",{className:"rounded overflow-hidden",style:{background:"rgba(51,175,188,0.04)",borderLeft:s.converged?"2px solid #33afbc":"2px solid rgba(229,192,123,0.35)"},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1.5",children:[e.jsx("span",{className:"text-xs font-mono font-semibold capitalize px-1.5 py-px rounded-sm",style:{background:f.bg,color:f.text},children:l}),r&&e.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1.5 py-px rounded-sm",children:c}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"flex items-center gap-1 text-2xs font-mono font-bold px-2 py-px rounded-full",style:{background:s.converged?"rgba(74,225,104,0.12)":"rgba(229,192,123,0.12)",color:s.converged?"#4ae168":"#e5c07b"},children:[!s.converged&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:"#e5c07b",animation:"node-pulse-bar 1.5s ease-in-out infinite"}}),s.converged?"Converged":"Learning"]})]}),e.jsxs("div",{className:"flex items-end gap-5 px-3 pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-0.5",children:"Threshold"}),e.jsx("div",{className:"text-3xl font-mono font-bold tabular-nums leading-none",style:{color:s.converged?"#33afbc":"#e5c07b"},children:xn(s.threshold*100)})]}),e.jsxs("div",{className:"pb-0.5",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-0.5",children:"Adj."}),e.jsx("div",{className:"text-lg font-mono font-semibold text-text-1 tabular-nums",children:s.adjustments})]})]}),(u||p)&&e.jsxs("div",{className:"px-3 pb-2 space-y-2 overflow-hidden",children:[u&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-0.5",children:"Threshold history"}),e.jsx(yX,{data:s.thresholdHistory.map(k=>k.v),color:s.converged?ce.accent:ce.warning,width:240,height:32})]}),p&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-0.5",children:"Quality score"}),e.jsx(yX,{data:s.recentScores,color:ce.warning,width:240,height:24})]})]}),x&&e.jsxs("div",{className:"flex flex-wrap gap-1.5 px-3 pb-2.5",children:[e.jsx(Po,{label:"Errors",value:x.errorCount,danger:!0}),e.jsx(Po,{label:"Reps",value:x.repetitions,danger:!0}),e.jsx(Po,{label:"Churn",value:x.fileChurn,danger:!0}),x.toolSuccessRate!=null&&e.jsxs("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3",children:["Tools: ",e.jsxs("span",{className:"text-text-1",children:[Math.round(x.toolSuccessRate*100),"%"]})]})]})]},s.key)})})}function pCe({journalist:t}){var a;return t?e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5",children:"Cycles"}),e.jsx("div",{className:"text-lg font-mono font-semibold text-text-0 tabular-nums leading-none",children:t.cycleCount||0})]}),t.lastCycleAt&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5",children:"Last"}),e.jsx("div",{className:"text-xs font-mono text-text-2",children:gt(t.lastCycleAt)})]}),t.synthesizing&&e.jsx("span",{className:"text-2xs font-mono font-bold text-accent uppercase tracking-wider animate-pulse",children:"Synthesizing"})]}),t.lastSummary&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1",children:"Summary"}),e.jsx("div",{className:"text-xs font-sans text-text-2 leading-relaxed",children:t.lastSummary})]}),t.projectMap&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1",children:"Project Map"}),e.jsx("div",{className:"text-xs font-mono text-text-2 leading-relaxed whitespace-pre-wrap",children:t.projectMap})]}),t.decisions&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1",children:"Decisions"}),e.jsx("div",{className:"text-xs font-mono text-text-2 leading-relaxed whitespace-pre-wrap",children:t.decisions})]}),((a=t.recentHistory)==null?void 0:a.length)>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1.5",children:"History"}),e.jsx("div",{className:"space-y-1",children:t.recentHistory.slice().reverse().map((s,c)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono px-2 py-1 bg-surface-0 rounded",children:[e.jsxs("span",{className:"text-text-3",children:["#",s.cycle]}),e.jsxs("span",{className:"text-text-2 flex-1 truncate",children:[s.agentCount," agents"]}),e.jsx("span",{className:"text-text-4",children:gt(s.timestamp)})]},c))})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono p-4",children:"Journalist inactive"})}function fCe({memory:t}){var x,g;const a=(t==null?void 0:t.constraints)||[],s=(t==null?void 0:t.discoveries)||[],c=(t==null?void 0:t.roles)||[],r=((x=t==null?void 0:t.specializations)==null?void 0:x.perAgent)||{},l=((g=t==null?void 0:t.specializations)==null?void 0:g.perProjectRole)||{},u=Object.keys(r).length,p=Object.keys(l).length;return a.length+s.length+c.length===0&&u===0?e.jsxs("div",{className:"p-6 text-center text-xs font-mono text-text-3",children:[e.jsx(Ro,{size:24,className:"mx-auto mb-2 text-text-4"}),e.jsx("div",{children:"No memory accumulated yet"}),e.jsx("div",{className:"text-2xs text-text-4 mt-1",children:"Constraints, handoff chains, and discoveries populate as agents work"})]}):e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Constraints",e.jsx(Wn,{text:"Project rules discovered by agents or set by the user. Every new agent reads these on spawn to avoid rediscovering them."})]}),e.jsx("div",{className:"text-2xl font-mono font-bold tabular-nums leading-none",style:{color:ce.accent},children:a.length})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Discoveries",e.jsx(Wn,{text:"Error→fix pairs successful agents have recorded. Injected into future agent context so they don't rediscover known solutions."})]}),e.jsx("div",{className:"text-2xl font-mono font-bold tabular-nums leading-none",style:{color:ce.success},children:s.length})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Handoff Chains",e.jsx(Wn,{text:"Cumulative rotation briefs per role. Agent #50 knows what agent #1 struggled with. Each role keeps its last 10 rotation briefs."})]}),e.jsx("div",{className:"text-2xl font-mono font-bold tabular-nums leading-none",style:{color:ce.purple},children:c.length})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1 flex items-center",children:["Specializations",e.jsx(Wn,{text:"Per-agent quality profiles: session counts, average quality, file touches, preferred thresholds."})]}),e.jsx("div",{className:"text-2xl font-mono font-bold tabular-nums leading-none",style:{color:ce.info},children:u}),p>0&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:["across ",p," roles"]})]})]}),a.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Project Constraints"}),e.jsxs("div",{className:"space-y-1",children:[a.slice(0,10).map(y=>e.jsxs("div",{className:"flex items-start gap-2 bg-surface-0 rounded px-2 py-1.5",children:[e.jsx("span",{className:"text-2xs font-mono px-1.5 py-px rounded-sm bg-surface-4 text-text-3 uppercase tracking-wider flex-shrink-0 mt-0.5",children:y.category}),e.jsx("span",{className:"text-xs font-mono text-text-2 leading-relaxed flex-1",children:y.text})]},y.hash)),a.length>10&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 px-2",children:["+",a.length-10," more"]})]})]}),s.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Recent Discoveries"}),e.jsx("div",{className:"space-y-1.5",children:s.slice(0,8).map((y,k)=>{const b=Bo(y.role);return e.jsxs("div",{className:"bg-surface-0 rounded px-2 py-1.5 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xs font-mono font-semibold capitalize px-1.5 py-px rounded-sm",style:{background:b.bg,color:b.text},children:y.role}),e.jsx("span",{className:"text-2xs font-mono text-text-4 flex-1",children:gt(y.ts)})]}),e.jsxs("div",{className:"text-xs font-mono text-text-2 leading-relaxed",children:[e.jsx("span",{className:"text-text-4",children:"When:"})," ",e.jsx("span",{className:"text-text-1",children:y.trigger})]}),e.jsxs("div",{className:"text-xs font-mono text-text-2 leading-relaxed",children:[e.jsx("span",{className:"text-text-4",children:"Fix:"})," ",e.jsx("span",{style:{color:ce.success},children:y.fix})]})]},k)})})]}),c.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Active Role Chains"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:c.map(y=>{const k=Bo(y);return e.jsx("span",{className:"text-2xs font-mono font-semibold capitalize px-2 py-1 rounded",style:{background:k.bg,color:k.text},children:y},y)})})]}),p>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-2",children:"Role Quality Profiles"}),e.jsx("div",{className:"space-y-1",children:Object.entries(l).map(([y,k])=>{const b=Bo(y);return e.jsxs("div",{className:"flex items-center gap-2 bg-surface-0 rounded px-2 py-1.5",children:[e.jsx("span",{className:"text-2xs font-mono font-semibold capitalize px-1.5 py-px rounded-sm",style:{background:b.bg,color:b.text},children:y}),e.jsxs("span",{className:"text-xs font-mono text-text-3 flex-1",children:[k.sessionCount," sessions"]}),e.jsxs("span",{className:"text-xs font-mono font-semibold tabular-nums",style:{color:SA(k.avgQualityScore)},children:["Q:",k.avgQualityScore]})]},y)})})]})]})}const xCe=O.memo(function({tokens:a,rotation:s,adaptive:c,journalist:r,agentBreakdown:l,memory:u}){return e.jsxs(MA,{defaultValue:"health",className:"flex flex-col h-full",children:[e.jsxs(jA,{className:"flex-shrink-0 px-1",children:[e.jsxs(kn,{value:"health",className:"text-xs px-2.5 py-1.5 inline-flex items-center gap-1.5",children:[e.jsx(Rs,{size:11}),"Health"]}),e.jsxs(kn,{value:"memory",className:"text-xs px-2.5 py-1.5 inline-flex items-center gap-1.5",children:[e.jsx(Ro,{size:11}),"Memory"]}),e.jsxs(kn,{value:"adaptive",className:"text-xs px-2.5 py-1.5 inline-flex items-center gap-1.5",children:[e.jsx(p2,{size:11}),"Adaptive"]}),e.jsxs(kn,{value:"journalist",className:"text-xs px-2.5 py-1.5 inline-flex items-center gap-1.5",children:[e.jsx(an,{size:11}),"Journalist"]})]}),e.jsx(vn,{value:"health",className:"flex-1 min-h-0 relative",children:e.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:e.jsx(uCe,{tokens:a,rotation:s,agentBreakdown:l})})}),e.jsx(vn,{value:"memory",className:"flex-1 min-h-0 relative",children:e.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:e.jsx(fCe,{memory:u})})}),e.jsx(vn,{value:"adaptive",className:"flex-1 min-h-0 relative",children:e.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:e.jsx(hCe,{adaptive:c})})}),e.jsx(vn,{value:"journalist",className:"flex-1 min-h-0 relative",children:e.jsx("div",{className:"absolute inset-0 overflow-y-auto",children:e.jsx(pCe,{journalist:r})})})]})}),mCe=O.memo(function({teams:a=[]}){const s=a.reduce((r,l)=>r+(l.totalTokens||0),0),c=a.reduce((r,l)=>Math.max(r,l.totalTokens||0),0);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Team Burn"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:[Fe(s)," total"]})]}),e.jsx(It,{className:"flex-1 min-h-0",children:a.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-text-3 font-mono",children:"No team activity yet"}):e.jsx("div",{className:"px-3 py-3 space-y-3",children:a.map(r=>{const l=c>0?r.totalTokens/c*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:r.teamName}),r.isDefault&&e.jsx("span",{className:"text-[9px] font-mono text-text-3 uppercase tracking-wider",children:"default"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 flex-shrink-0",children:[r.agentCount," ",r.agentCount===1?"agent":"agents"]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 font-mono text-2xs",children:[e.jsx("span",{className:"text-text-1",children:Fe(r.totalTokens)}),e.jsx("span",{className:"text-text-3",children:Jo(r.totalCostUsd)})]})]}),e.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all",style:{width:`${l}%`,background:ce.accent}})})]},r.teamId)})})})]})}),yCe={spawn:I2,complete:ca,crash:Et,kill:yn,rotate:Xs,error:v1},gCe={spawn:"text-accent",complete:"text-success",crash:"text-danger",kill:"text-text-3",rotate:"text-purple",error:"text-danger"};function OCe(t){const a=t.agentName||t.role||"";switch(t.type){case"spawn":return`${a} spawned`;case"complete":return`${a} completed`;case"crash":return`${a} crashed`;case"kill":return`${a} killed`;case"rotate":return`${a} rotated`;default:return t.text||t.type||"event"}}const kCe=O.memo(function({events:a=[]}){return a.length?e.jsx("div",{className:"flex items-center gap-3 overflow-x-auto py-2 px-3",children:a.slice(-15).reverse().map((s,c)=>{const r=yCe[s.type]||qt,l=gCe[s.type]||"text-text-3",u=OCe(s);return e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(r,{size:11,className:l}),e.jsx("span",{className:"text-xs font-sans text-text-2 whitespace-nowrap",children:u}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:gt(s.t||s.timestamp)})]},c)})}):e.jsx("div",{className:"text-xs text-text-3 font-mono py-2.5 text-center",children:"No recent activity"})});function en({className:t,...a}){return e.jsx("div",{className:K("rounded-md bg-surface-4","bg-gradient-to-r from-surface-4 via-surface-5 to-surface-4","bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]",t),...a})}function vCe(){return e.jsxs("div",{className:"flex-1 grid gap-px p-0",style:{gridTemplateRows:"auto minmax(0, 1fr) minmax(0, 1fr)",gridTemplateColumns:"2fr 2.5fr 1.5fr",background:"#282c34"},children:[e.jsx("div",{className:"col-span-3",children:e.jsx(en,{className:"h-[72px] rounded-none"})}),e.jsx(en,{className:"rounded-none"}),e.jsx(en,{className:"rounded-none"}),e.jsx(en,{className:"rounded-none"}),e.jsx(en,{className:"rounded-none"}),e.jsx("div",{className:"col-span-2",children:e.jsx(en,{className:"h-full rounded-none"})})]})}function bCe(){const{data:t,loading:a,agents:s,connected:c,kpiHistory:r,lastFetch:l,agentBreakdown:u,routing:p,rotation:f,adaptive:x,journalist:g,rotating:y,teamBurn:k,memory:b}=U$e(),j=q(V=>V.teams),w=s.filter(V=>V.status==="running").length;if(!c)return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2 text-text-3 font-mono",children:[e.jsx(zs,{size:28,className:"mx-auto"}),e.jsx("p",{className:"text-xs",children:"Connecting to daemon..."})]})});if(a||!t)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(fX,{connected:c,runningCount:0,totalCount:0,uptime:0,lastFetch:0}),e.jsx(vCe,{})]});const S=t.tokens||{},M={totalTokens:S.totalTokens||0,totalCostUsd:S.totalCostUsd||0,totalInputTokens:S.totalInputTokens||0,totalOutputTokens:S.totalOutputTokens||0,cacheReadTokens:S.cacheReadTokens||0,cacheCreationTokens:S.cacheCreationTokens||0,cacheHitRate:S.cacheHitRate||0,totalTurns:S.totalTurns||0,agentCount:S.agentCount||0,savings:S.savings||{},internalOverhead:S.internalOverhead||{tokens:0,costUsd:0,components:{}}},$=M.totalOutputTokens>0?(M.totalInputTokens/M.totalOutputTokens).toFixed(1):"—",C=(f==null?void 0:f.totalRotations)||0,_=(u||[]).filter(V=>{var se;return((se=V.quality)==null?void 0:se.score)!=null}),P=_.length>0?Math.round(_.reduce((V,se)=>V+se.quality.score,0)/_.length):null,L=t.timeline||{},A=L.snapshots||[],z=L.events||t.events||[],Y=[{label:"Tokens Used",value:Fe(M.totalTokens),sparkData:r.tokens,color:ce.accent,hint:"Total tokens consumed across all agents — input, output, and cache tokens combined."},{label:"Total Cost",value:Jo(M.totalCostUsd),sparkData:r.cost,color:ce.warning,hint:"Actual cost reported by providers. Claude Code reports real billing; other providers use estimated rates."},{label:"Quality",value:P!=null?`${P}`:"—",sparkData:r.saved,color:P>=70?ce.success:P>=40?ce.warning:ce.danger,hint:"Average session quality score (0-100) across running agents. Based on error rate, repetitions, file churn, and tool success. Below 40 triggers auto-rotation."},{label:"Cache Rate",value:xn(M.cacheHitRate*100),sparkData:r.cache,color:ce.info,hint:"Percentage of input tokens served from prompt cache. Higher = faster responses and lower cost. Managed by your AI provider."},{label:"Rotations",value:`${C}`,sparkData:r.efficiency,color:ce.purple,hint:"Total context rotations — includes quality-based (auto), context threshold, natural compaction (provider-managed), and manual rotations."},{label:"I/O Ratio",value:`${$}:1`,sparkData:r.inputOutput,color:ce.orange,hint:"Ratio of input to output tokens. High ratios mean agents are reading more than writing — common for analysis tasks."},{label:"Agents",value:`${w}/${s.length}`,sparkData:r.agents,color:ce.accent,hint:"Running agents out of total spawned this session (including completed and crashed)."},{label:"Turns",value:Fe(M.totalTurns),sparkData:r.turns,color:ce.text2,hint:"Total conversation turns across all agents. Each turn is one request-response cycle with the AI provider."}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(fX,{connected:c,runningCount:w,totalCount:s.length,uptime:t.uptime||0,lastFetch:l,activeTeam:t.activeTeam}),e.jsx(G$e,{kpis:Y}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",style:{background:"#282c34",gap:"1px"},children:[e.jsxs("div",{className:"min-h-0 flex-1 grid",style:{gridTemplateColumns:"3fr 1.5fr 1.5fr",gap:"0 1px"},children:[e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 relative",children:e.jsx(eCe,{data:A})}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Cache Performance"})}),e.jsx(tCe,{cacheRead:M.cacheReadTokens,cacheCreation:M.cacheCreationTokens,totalInput:M.totalInputTokens})]}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Model Routing"})}),e.jsx(aCe,{routing:p,agentBreakdown:u})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 grid",style:{gridTemplateColumns:"2fr 2.5fr 1.5fr",gap:"0 1px"},children:[e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Agent Fleet"})}),e.jsx(J$e,{agentBreakdown:u,rotating:y,teams:j})]}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx(xCe,{tokens:M,rotation:f,adaptive:x,journalist:g,agentBreakdown:u,memory:b})}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx(mCe,{teams:k})})]})]}),e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-t border-border",children:e.jsx(kCe,{events:z})})]})}const gX={sm:12,md:16,lg:20};function wCe({fill:t="full",size:a,color:s="#fbbf24",emptyColor:c="rgba(255,255,255,0.4)"}){const r=`star-${Math.random().toString(36).slice(2,8)}`;return e.jsxs("svg",{width:a,height:a,viewBox:"0 0 20 20",fill:"none",children:[t==="half"&&e.jsx("defs",{children:e.jsxs("linearGradient",{id:r,children:[e.jsx("stop",{offset:"50%",stopColor:s}),e.jsx("stop",{offset:"50%",stopColor:c})]})}),e.jsx("path",{d:"M10 1.5l2.47 5.01 5.53.8-4 3.9.94 5.49L10 14.27 5.06 16.7 6 11.21l-4-3.9 5.53-.8L10 1.5z",fill:t==="full"?s:t==="half"?`url(#${r})`:c})]})}function rB({rating:t=0,count:a,size:s="sm"}){const c=gX[s]||gX.sm,r=[];for(let l=1;l<=5;l++)t>=l?r.push("full"):t>=l-.5?r.push("half"):r.push("empty");return e.jsxs("span",{className:"inline-flex items-center",style:{gap:1},children:[r.map((l,u)=>e.jsx(wCe,{fill:l,size:c},u)),a!=null&&e.jsxs("span",{className:"ml-1 text-[11px] text-[var(--text-dim,#6b7f95)] font-sans",children:["(",a,")"]})]})}const OX={design:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},quality:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},devtools:{color:"#33afbc",bg:"rgba(51,175,188,0.14)"},workflow:{color:"#fbbf24",bg:"rgba(251,191,36,0.12)"},security:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},specialized:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},verified:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},anthropic:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},published:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},draft:{color:"#6b7f95",bg:"rgba(255,255,255,0.06)"},review:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},rejected:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},free:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"}};function iB({label:t,variant:a,className:s}){const c=OX[a]||OX.draft;return e.jsx("span",{className:K("inline-flex items-center whitespace-nowrap font-sans select-none",s),style:{padding:"3px 8px",borderRadius:4,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",lineHeight:1.4,color:c.color,background:c.bg},children:t})}function lB({price:t=0,size:a="sm"}){const s=!t||t===0,c={sm:"text-2xs px-2 py-0.5",md:"text-xs px-2.5 py-0.5",lg:"text-xs px-3 py-1"};return e.jsx("span",{className:`inline-flex items-center font-mono font-semibold rounded whitespace-nowrap ${c[a]||c.sm} ${s?"bg-success/12 text-success":"bg-white/8 text-text-1"}`,children:s?"Free":`$${t.toFixed(2)}`})}function dB({type:t="verified",size:a=12}){const s=t==="claude-official"||t==="anthropic"?"#f59e0b":"#4ade80";return e.jsxs("svg",{width:a,height:a,viewBox:"0 0 20 20",fill:"none",className:"inline-block flex-shrink-0",children:[e.jsx("path",{d:"M10 0l2.36 3.15L16.18 2l.68 3.93L20.8 7.1l-1.87 3.52L20.8 14.14l-3.94 1.17-.68 3.93-3.82-1.15L10 21.24l-2.36-3.15-3.82 1.15-.68-3.93-3.94-1.17 1.87-3.52L-.8 7.1l3.94-1.17.68-3.93 3.82 1.15L10 0z",fill:s}),e.jsx("path",{d:"M7 10.5l2 2 4-4.5",fill:"none",stroke:"#24282f",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}const uB="groove_favorites";function NA(){try{return JSON.parse(localStorage.getItem(uB)||"[]")}catch{return[]}}function MCe(t){return NA().includes(t)}function jCe(t){const a=NA(),s=a.indexOf(t);return s>=0?a.splice(s,1):a.push(t),localStorage.setItem(uB,JSON.stringify(a)),s<0}function SCe(t){const a=new Set(NA());return t.map(s=>({...s,favorited:a.has(s.id)}))}function NCe({filled:t,size:a=16}){return e.jsx("svg",{width:a,height:a,viewBox:"0 0 24 24",fill:t?"#f87171":"none",stroke:t?"#f87171":"rgba(255,255,255,0.3)",strokeWidth:"2",children:e.jsx("path",{d:"M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"})})}function _Ce(){return e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}function $Ce({skill:t,onClick:a}){var l,u;const[s,c]=O.useState(()=>MCe(t.id));function r(p){p.stopPropagation(),c(jCe(t.id))}return e.jsxs("div",{onClick:()=>a==null?void 0:a(t),className:K("flex flex-col cursor-pointer group","bg-surface-1 border border-border-subtle rounded-md","hover:border-accent/30 hover:bg-surface-2","transition-all duration-150"),style:{padding:20,minHeight:280},children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 bg-accent/12 text-[20px]",children:t.icon||((u=(l=t.name)==null?void 0:l[0])==null?void 0:u.toUpperCase())||"?"}),e.jsx("button",{onClick:r,className:"opacity-40 group-hover:opacity-80 hover:!opacity-100 transition-opacity cursor-pointer bg-transparent border-0 p-0",children:e.jsx(NCe,{filled:s})})]}),e.jsx("div",{className:"mt-3 text-[15px] font-semibold text-text-0 font-sans line-clamp-2 leading-snug",children:t.name}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-xs text-text-3 font-sans",children:[e.jsxs("span",{children:["by ",t.author||"Community"]}),(t.source==="claude-official"||t.verified)&&e.jsx(dB,{type:t.source,size:12})]}),e.jsx("div",{className:"mt-2.5 text-xs text-text-2 font-sans line-clamp-3 flex-1 leading-relaxed",children:t.description}),e.jsx("div",{className:"mt-3",children:e.jsx(iB,{label:t.category||"general",variant:t.category||"draft"})}),e.jsx("div",{className:"h-px bg-border-subtle my-3"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(rB,{rating:t.rating||0,count:t.rating_count||t.ratingCount||0,size:"sm"}),e.jsxs("span",{className:"flex items-center gap-1 text-xs text-text-3 font-mono",children:[e.jsx(_Ce,{}),Fe(t.downloads||0)]}),e.jsx(lB,{price:t.price||0,size:"sm"})]})]})}function hB(){return e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md animate-pulse",style:{padding:20,minHeight:280},children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-surface-4"}),e.jsx("div",{className:"mt-3 h-4 w-[70%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-2 h-3 w-[40%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-3 w-full rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[90%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[60%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-5 w-[50px] rounded bg-surface-4"}),e.jsx("div",{className:"h-px bg-surface-4 my-3"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("div",{className:"h-3 w-16 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-12 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-10 rounded bg-surface-4"})]})]})}const S1={"google-workspace":"https://cdn.simpleicons.org/google/white",slack:"https://cdn.simpleicons.org/slack/E01E5A",discord:"https://cdn.simpleicons.org/discord/5865F2",github:"https://cdn.simpleicons.org/github/white",stripe:"https://cdn.simpleicons.org/stripe/635BFF",gmail:"https://cdn.simpleicons.org/gmail/EA4335","google-calendar":"https://cdn.simpleicons.org/googlecalendar/4285F4","google-drive":"https://cdn.simpleicons.org/googledrive/4285F4","google-docs":"https://cdn.simpleicons.org/googledocs/4285F4","google-sheets":"https://cdn.simpleicons.org/googlesheets/34A853","google-slides":"https://cdn.simpleicons.org/googleslides/FBBC04","google-maps":"https://cdn.simpleicons.org/googlemaps/4285F4",postgres:"https://cdn.simpleicons.org/postgresql/4169E1",notion:"https://cdn.simpleicons.org/notion/white",linear:"https://cdn.simpleicons.org/linear/5E6AD2","brave-search":"https://cdn.simpleicons.org/brave/FB542B","home-assistant":"https://cdn.simpleicons.org/homeassistant/18BCF2",sentry:"https://cdn.simpleicons.org/sentry/362D59",elevenlabs:"https://cdn.simpleicons.org/elevenlabs/white",hubspot:"https://cdn.simpleicons.org/hubspot/FF7A59",jira:"https://cdn.simpleicons.org/jira/0052CC",sendgrid:"https://cdn.simpleicons.org/sendgrid/1A82E2",resend:"https://cdn.simpleicons.org/resend/white",replicate:"https://cdn.simpleicons.org/replicate/white",vercel:"https://cdn.simpleicons.org/vercel/white",supabase:"https://cdn.simpleicons.org/supabase/3FCF8E",mixpanel:"https://cdn.simpleicons.org/mixpanel/7856FF",datadog:"https://cdn.simpleicons.org/datadog/632CA6",airtable:"https://cdn.simpleicons.org/airtable/18BFFF",zendesk:"https://cdn.simpleicons.org/zendesk/03363D",intercom:"https://cdn.simpleicons.org/intercom/6AFDEF",twilio:"https://cdn.simpleicons.org/twilio/F22F46",telnyx:"https://cdn.simpleicons.org/telnyx/00C08B",aws:"https://cdn.simpleicons.org/amazonaws/FF9900",plaid:"https://cdn.simpleicons.org/plaid/white"};function CCe({item:t,size:a=40}){const s=S1[t.id];if(s)return e.jsxs("div",{className:"rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:a,height:a},children:[e.jsx("img",{src:s,alt:t.name,className:"w-5 h-5",onError:l=>{l.target.style.display="none",l.target.nextSibling.style.display="flex"}}),e.jsx("div",{className:"hidden items-center justify-center w-full h-full text-lg font-bold font-sans text-text-1",children:(t.name||"?")[0]})]});const c=(t.name||"?")[0].toUpperCase(),r=t.name?t.name.charCodeAt(0)*37%360:200;return e.jsx("div",{className:"rounded-md flex items-center justify-center flex-shrink-0 text-lg font-bold font-sans",style:{width:a,height:a,background:`hsl(${r}, 40%, 18%)`,color:`hsl(${r}, 60%, 65%)`},children:c})}function jQ({item:t,onClick:a,className:s,statusBadge:c}){var l;const r=t.installed;return e.jsxs("button",{onClick:()=>a(t),className:K("flex flex-col p-5 rounded-md border border-border-subtle bg-surface-1 text-left","hover:border-accent/30 hover:bg-surface-2","transition-all duration-150 cursor-pointer group",s),style:{minHeight:200},children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(CCe,{item:t,size:36}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-0 font-sans truncate",children:t.name}),(t.verified||t.verified==="mcp-official")&&e.jsx(ca,{size:11,className:"text-accent flex-shrink-0"})]}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.author||"Community"})]})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans line-clamp-3 mb-3 flex-1 leading-relaxed",children:t.description}),e.jsx("div",{className:"h-px bg-border-subtle my-2"}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Oa,{size:10}),Fe(t.downloads||0)]}),(t.rating||0)>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(b1,{size:10,className:"text-warning",fill:"currentColor"}),(l=t.rating)==null?void 0:l.toFixed(1)]}),e.jsx("span",{className:"flex-1"}),c||r&&e.jsx(ge,{variant:"accent",className:"text-2xs",children:t._installedCount?`${t._installedCount} active`:"Installed"})]})]})}function _A({value:t,onChange:a,placeholder:s="Search skills, tags, authors...",large:c}){const[r,l]=O.useState(t||""),u=O.useRef(null);O.useEffect(()=>{l(t||"")},[t]);function p(f){const x=f.target.value;l(x),clearTimeout(u.current),u.current=setTimeout(()=>a(x),300)}return e.jsxs("div",{className:"relative w-full",children:[e.jsx(Zt,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{value:r,onChange:p,placeholder:s,className:K("w-full font-sans outline-none","bg-surface-0 border border-border text-text-0 placeholder:text-text-4","focus:border-accent/40 transition-colors",c?"py-3 pl-11 pr-12 text-[15px] rounded-lg":"py-2.5 pl-10 pr-3 text-sm rounded-md")}),c&&e.jsx("kbd",{className:"absolute right-3.5 top-1/2 -translate-y-1/2 bg-surface-4 text-text-4 px-2 py-0.5 rounded text-xs font-mono",children:"/"})]})}const QCe=[{id:"",label:"All"},{id:"design",label:"Design"},{id:"quality",label:"Quality"},{id:"devtools",label:"Dev Tools"},{id:"workflow",label:"Workflow"},{id:"security",label:"Security"},{id:"specialized",label:"Specialized"}];function LCe({selected:t="",categories:a=QCe,onSelect:s}){return e.jsx("div",{className:"flex gap-2 overflow-x-auto",style:{scrollbarWidth:"none"},children:a.map(c=>{const r=t===c.id;return e.jsx("button",{onClick:()=>s(c.id),className:K("whitespace-nowrap font-sans cursor-pointer select-none transition-all text-[13px] rounded-full border",r?"bg-accent text-surface-0 border-accent font-semibold":"bg-surface-1 text-text-3 border-border-subtle hover:text-text-1 hover:border-border font-medium"),style:{padding:"7px 16px"},children:c.label},c.id)})})}function va(){const t=q(a=>a.addToast);return{success:(a,s)=>t("success",a,s),error:(a,s)=>t("error",a,s),info:(a,s)=>t("info",a,s),warning:(a,s)=>t("warning",a,s)}}const ns=O.forwardRef(({className:t,label:a,error:s,mono:c,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[a&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:a}),e.jsx("input",{ref:l,className:K("h-8 w-full rounded-md px-3 text-sm","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",c?"font-mono":"font-sans",s&&"border-danger focus:ring-danger",t),...r}),s&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:s})]}));ns.displayName="Input";const zCe=O.forwardRef(({className:t,label:a,error:s,mono:c,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[a&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:a}),e.jsx("textarea",{ref:l,className:K("w-full rounded-md px-3 py-2 text-sm resize-none","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",c?"font-mono":"font-sans",s&&"border-danger focus:ring-danger",t),...r}),s&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:s})]}));zCe.displayName="Textarea";function $A({item:t,size:a=48}){const s=S1[t.id];if(s)return e.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:a,height:a},children:e.jsx("img",{src:s,alt:t.name,className:"w-6 h-6",onError:l=>{l.target.style.display="none"}})});const c=(t.name||"?")[0].toUpperCase(),r=t.name?t.name.charCodeAt(0)*37%360:200;return e.jsx("div",{className:"rounded-lg flex items-center justify-center flex-shrink-0 text-xl font-bold font-sans",style:{width:a,height:a,background:`hsl(${r}, 40%, 18%)`,color:`hsl(${r}, 60%, 65%)`},children:c})}function MP({value:t,onChange:a,placeholder:s,disabled:c}){const[r,l]=O.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsx(ns,{type:r?"text":"password",value:t,onChange:u=>a(u.target.value),placeholder:s,disabled:c,mono:!0,className:"pr-9"}),e.jsx("button",{type:"button",onClick:()=>l(u=>!u),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded text-text-4 hover:text-text-1 transition-colors cursor-pointer",tabIndex:-1,children:r?e.jsx(Jn,{size:14}):e.jsx(ka,{size:14})})]})}function TCe({integrationId:t,envKey:a,onSaved:s}){const c=va(),[r,l]=O.useState(""),[u,p]=O.useState(!1),[f,x]=O.useState(a.set),[g,y]=O.useState(!1);async function k(){if(r.trim()){p(!0);try{await X.post(`/integrations/${t}/credentials`,{key:a.key,value:r.trim()}),x(!0),l(""),c.success(`${a.label} saved`),s==null||s()}catch(j){c.error("Failed to save",j.message)}p(!1)}}async function b(){y(!0);try{await X.delete(`/integrations/${t}/credentials/${a.key}`),x(!1),c.success(`${a.label} removed`),s==null||s()}catch(j){c.error("Failed to remove",j.message)}y(!1)}return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(jn,{size:11,className:"text-text-4"}),a.label,a.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),f&&e.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[e.jsx(Ve,{size:10})," Set"]})]}),f?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:e.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),e.jsx(he,{variant:"ghost",size:"sm",onClick:b,disabled:g,className:"text-text-3 hover:text-danger",children:g?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(wt,{size:12})})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx(MP,{value:r,onChange:l,placeholder:a.placeholder||`Enter ${a.label.toLowerCase()}...`,disabled:u})}),e.jsx(he,{variant:"primary",size:"sm",onClick:k,disabled:u||!r.trim(),children:u?e.jsx(ze,{size:12,className:"animate-spin"}):"Save"})]})]})}function PCe({item:t,status:a,installing:s,onInstall:c,onUninstall:r,onNext:l}){var p;const u=a==null?void 0:a.installed;return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx($A,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:t.name}),(t.verified==="mcp-official"||t.verified==="verified")&&e.jsxs(ge,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(nn,{size:9})," Verified"]})]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:t.author||"Community"}),t.category&&e.jsx(ge,{variant:"default",className:"text-2xs mt-2",children:t.category})]})]}),e.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((p=t.tags)==null?void 0:p.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map(f=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:f},f))}),e.jsx("div",{className:"h-px bg-border-subtle"}),u?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsx(ca,{size:16,className:"text-success"}),e.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),e.jsxs(he,{variant:"ghost",size:"sm",onClick:r,className:"text-text-3 hover:text-danger gap-1.5",children:[e.jsx(wt,{size:12})," Uninstall"]}),e.jsxs(he,{variant:"primary",size:"sm",onClick:l,className:"gap-1",children:["Configure ",e.jsx(Xt,{size:12})]})]}):e.jsx(he,{variant:"primary",size:"lg",onClick:c,disabled:s,className:"w-full gap-2",children:s?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),s&&e.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}const ACe={gmail:"Gmail API","google-calendar":"Google Calendar API","google-drive":"Google Drive API","google-docs":"Google Docs API","google-sheets":"Google Sheets API","google-slides":"Google Slides API"};function pB({integrationId:t,onConfigured:a}){const s=va(),[c,r]=O.useState(""),[l,u]=O.useState(""),[p,f]=O.useState(!1),x=ACe[t]||"the relevant Google API";async function g(){if(!(!c.trim()||!l.trim())){f(!0);try{await X.post("/integrations/google-oauth/setup",{clientId:c.trim(),clientSecret:l.trim()}),s.success("Google OAuth credentials saved"),a()}catch(k){s.error("Failed to save",k.message)}f(!1)}}const y=[{text:"Go to the Google Cloud Console and sign in with your Google account",link:{url:"https://console.cloud.google.com",label:"Open Google Cloud Console"}},{text:"Create a new project (or select an existing one). Any name is fine — this is just a container for your credentials."},{text:e.jsxs(e.Fragment,{children:["Enable the ",e.jsx("strong",{children:x})," — search for it in the API Library and click ",e.jsx("strong",{children:"Enable"})]}),link:{url:"https://console.cloud.google.com/apis/library",label:"Open API Library"}},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Credentials"})," and click ",e.jsx("strong",{children:"Create Credentials"})," → ",e.jsx("strong",{children:"OAuth client ID"})]}),link:{url:"https://console.cloud.google.com/apis/credentials",label:"Open Credentials page"}},{text:e.jsxs(e.Fragment,{children:["If prompted to configure the consent screen, choose ",e.jsx("strong",{children:"External"}),', fill in an app name (e.g. "Groove"), your email, and save. You can skip optional fields.']})},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Audience"})," and click ",e.jsx("strong",{children:"Publish App"}),". Then scroll down to ",e.jsx("strong",{children:"Test users"}),", click ",e.jsx("strong",{children:"Add Users"}),", enter your Google email address, and save."]})},{text:e.jsxs(e.Fragment,{children:["For Application type, choose ",e.jsx("strong",{children:"Desktop app"})," (not Web application). Give it any name."]})},{text:e.jsxs(e.Fragment,{children:["Click ",e.jsx("strong",{children:"Create"}),", then copy the ",e.jsx("strong",{children:"Client ID"})," and ",e.jsx("strong",{children:"Client Secret"})," and paste them below."]})}];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-3",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"How to get your Google credentials"}),e.jsx("ol",{className:"space-y-2.5",children:y.map((k,b)=>e.jsxs("li",{className:"flex gap-2.5 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono font-bold flex-shrink-0 w-4 text-right",children:[b+1,"."]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{children:k.text}),k.link&&e.jsxs("a",{href:k.link.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-2xs text-accent font-sans hover:underline mt-0.5",children:[e.jsx(Pt,{size:9}),k.link.label]}),k.copyable&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("code",{className:"flex-1 min-w-0 text-2xs font-mono text-accent bg-surface-4 px-2.5 py-1.5 rounded select-all break-all",children:k.copyable}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(k.copyable)},className:"flex-shrink-0 p-1.5 rounded text-text-3 hover:text-accent hover:bg-accent/10 transition-colors cursor-pointer",title:"Copy to clipboard",children:e.jsx(Mn,{size:12})})]})]})]},b))})]}),e.jsx("div",{className:"bg-accent/8 border border-accent/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsx("strong",{className:"text-text-1",children:"One-time setup"})," — these same credentials work for Gmail, Calendar, Drive, Docs, Sheets, and Slides. You only need to do this once. For each integration, just enable the matching API in your Google Cloud project."]})}),e.jsx("div",{className:"bg-warning/8 border border-warning/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsx("strong",{className:"text-text-1",children:'Google "unverified app" warning'})," — when signing in, Google may show a warning that the app isn't verified. This is normal for personal OAuth apps. Click ",e.jsx("strong",{children:"Advanced"}),", then ",e.jsx("strong",{children:"Go to [your app name] (unsafe)"})," to continue. Your credentials stay local and are never sent to Groove servers."]})}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(jn,{size:11,className:"text-text-4"}),"Client ID ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(MP,{value:c,onChange:r,placeholder:"123456789.apps.googleusercontent.com",disabled:p})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(jn,{size:11,className:"text-text-4"}),"Client Secret ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(MP,{value:l,onChange:u,placeholder:"GOCSPX-...",disabled:p})]})]}),e.jsx(he,{variant:"primary",size:"lg",onClick:g,disabled:p||!c.trim()||!l.trim(),className:"w-full gap-2",children:p?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"})," Saving..."]}):"Save Credentials"})]})}function qCe({item:t,status:a,onDone:s,onRefreshStatus:c}){var S;const r=va(),[l,u]=O.useState(!1),[p,f]=O.useState(null),x=t.authType,g=x==="google-autoauth"||x==="oauth-google";O.useEffect(()=>{g&&X.get("/integrations/google-oauth/status").then(M=>f(M.configured)).catch(()=>f(!1))},[g]);const y=O.useRef(null);O.useEffect(()=>()=>{y.current&&clearInterval(y.current)},[]);async function k(){u(!0);try{const M=await X.post(`/integrations/${t.id}/oauth/start`);if(M.url){const $=await RX(M.url);if($!=null&&$.error){r.error("Sign-in failed",$.error),u(!1);return}r.success("Browser opened — complete sign-in there");let C=0;y.current&&clearInterval(y.current),y.current=setInterval(async()=>{if(C+=2e3,C>6e4){clearInterval(y.current),y.current=null,u(!1);return}try{const _=await X.get(`/integrations/${t.id}/status`);((_==null?void 0:_.envKeys)||[]).some(A=>A.key==="GOOGLE_REFRESH_TOKEN"&&A.set)&&(clearInterval(y.current),y.current=null,r.success("Connected!",`${t.name} is now authenticated`),c(),u(!1))}catch{}},2e3)}}catch(M){r.error("Sign-in failed",M.message),u(!1)}}const b=(a==null?void 0:a.envKeys)||[],j=b.filter(M=>M.required&&!M.hidden),w=j.length===0||j.every(M=>M.set);return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx($A,{item:t,size:36}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",t.name]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((S=t.setupSteps)==null?void 0:S.length)>0&&!(g&&p===!1)&&e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),e.jsx("ol",{className:"space-y-1.5",children:t.setupSteps.map((M,$)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[$+1,"."]}),e.jsx("span",{children:M})]},$))}),t.setupUrl&&e.jsxs("a",{href:t.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[e.jsx(Pt,{size:11}),new URL(t.setupUrl).hostname]})]}),!(g&&p===!1)&&e.jsx("div",{className:"h-px bg-border-subtle"}),x==="api-key"&&e.jsx("div",{className:"space-y-4",children:b.filter(M=>!M.hidden).map(M=>e.jsx(TCe,{integrationId:t.id,envKey:M,onSaved:c},M.key))}),g&&p===!1&&e.jsx(pB,{integrationId:t.id,onConfigured:()=>f(!0)}),g&&p&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{variant:"primary",size:"lg",onClick:k,disabled:l,className:"w-full gap-2",children:l?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"}),"Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["A browser window will open — sign in and allow access to your ",t.name]}),e.jsx("button",{type:"button",onClick:()=>f(!1),className:"w-full text-2xs text-text-4 font-sans hover:text-text-2 transition-colors cursor-pointer py-1",children:"Reconfigure Google OAuth credentials"})]}),g&&p===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(ze,{size:16,className:"animate-spin text-text-4"})}),e.jsx(he,{variant:w?"primary":"secondary",size:"lg",onClick:s,className:"w-full gap-1.5",children:w?e.jsxs(e.Fragment,{children:[e.jsx(Ve,{size:14}),"Done"]}):"Skip for now"})]})}function ICe({item:t,onClose:a}){return e.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(ca,{size:28,className:"text-success"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),e.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[t.name," is installed and configured. Agents can now use it."]})]}),e.jsx(he,{variant:"primary",size:"lg",onClick:a,className:"mt-2",children:"Close"})]})}function fB({integration:t,open:a,onClose:s}){const c=va(),[r,l]=O.useState("overview"),[u,p]=O.useState(null),[f,x]=O.useState(!1),[g,y]=O.useState(!0),k=t==null?void 0:t.id,b=O.useCallback(async()=>{if(k){try{const $=await X.get(`/integrations/${k}/status`);p($)}catch{p(null)}y(!1)}},[k]);O.useEffect(()=>{a&&t&&(l("overview"),y(!0),b())},[a,t,b]);async function j(){x(!0);try{await X.post(`/integrations/${t.id}/install`),c.success(`${t.name} installed`),await b(),l("configure")}catch($){c.error("Install failed",$.message)}x(!1)}async function w(){try{await X.delete(`/integrations/${t.id}`),c.success(`${t.name} uninstalled`),await b()}catch($){c.error("Uninstall failed",$.message)}}function S(){l("configure")}function M(){l("done")}return t?e.jsx(qa,{open:a,onOpenChange:$=>{$||s()},children:e.jsx(Ia,{title:r==="overview"?t.name:r==="configure"?"Configure":"Complete",description:`Setup wizard for ${t.name}`,className:"max-w-md",children:g?e.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:e.jsx(ze,{size:20,className:"animate-spin text-text-4"})}):r==="overview"?e.jsx(PCe,{item:t,status:u,installing:f,onInstall:j,onUninstall:w,onNext:S}):r==="configure"?e.jsx(qCe,{item:t,status:u,onDone:M,onRefreshStatus:b}):e.jsx(ICe,{item:t,onClose:s})})}):null}const RCe=["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"];function VCe({item:t,status:a,onInstall:s,onUninstall:c,busy:r}){const l=a==null?void 0:a.installed,u=a==null?void 0:a.authenticated;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-2 border border-border-subtle",children:[e.jsx($A,{item:t,size:32}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:t.description})]}),l&&u&&!(a!=null&&a.needsReauth)&&e.jsxs(ge,{variant:"success",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Ve,{size:8})," Ready"]}),l&&u&&(a==null?void 0:a.needsReauth)&&e.jsxs(ge,{variant:"warning",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(ia,{size:8})," Update"]}),l&&!u&&e.jsx(ge,{variant:"warning",className:"text-2xs flex-shrink-0",children:"Needs sign-in"}),e.jsx(he,{variant:l?"ghost":"primary",size:"sm",onClick:()=>l?c(t.id):s(t.id),disabled:r===t.id,className:l?"text-text-3 hover:text-danger":"",children:r===t.id?e.jsx(ze,{size:12,className:"animate-spin"}):l?e.jsx(wt,{size:12}):"Install"})]})}function ECe({integrations:t,open:a,onClose:s}){const c=va(),[r,l]=O.useState(null),[u,p]=O.useState({}),[f,x]=O.useState(null),[g,y]=O.useState(!1),[k,b]=O.useState(!0),j=O.useRef(null),w=t.filter(A=>RCe.includes(A.id)),S=O.useCallback(async()=>{const A={};await Promise.all(w.map(async z=>{try{A[z.id]=await X.get(`/integrations/${z.id}/status`)}catch{A[z.id]=null}})),p(A),b(!1)},[w.map(A=>A.id).join(",")]);O.useEffect(()=>(a&&(b(!0),X.get("/integrations/google-oauth/status").then(A=>l(A.configured)).catch(()=>l(!1)),S()),()=>{j.current&&clearInterval(j.current)}),[a]);const M=Object.entries(u).filter(([,A])=>A==null?void 0:A.installed).map(([A])=>A),$=M.length>0&&M.every(A=>{var z;return(z=u[A])==null?void 0:z.authenticated});M.some(A=>{var z;return!((z=u[A])!=null&&z.authenticated)});const C=$&&M.some(A=>{var z;return(z=u[A])==null?void 0:z.needsReauth});async function _(A){var z;x(A);try{await X.post(`/integrations/${A}/install`),c.success(`${(z=w.find(Y=>Y.id===A))==null?void 0:z.name} installed`),await S()}catch(Y){c.error("Install failed",Y.message)}x(null)}async function P(A){var z;x(A);try{await X.delete(`/integrations/${A}`),c.success(`${(z=w.find(Y=>Y.id===A))==null?void 0:z.name} removed`),await S()}catch(Y){c.error("Uninstall failed",Y.message)}x(null)}async function L(){if(!M.length){c.error("Install at least one service first");return}y(!0);try{const A=await X.post("/integrations/google-workspace/oauth/start",{integrationIds:M});if(A.url){const z=await RX(A.url);if(z!=null&&z.error){c.error("Sign-in failed",z.error),y(!1);return}c.success("Browser opened — complete sign-in there"),j.current&&clearInterval(j.current),j.current=setInterval(async()=>{await S()},3e3),setTimeout(()=>{j.current&&clearInterval(j.current)},18e4)}}catch(A){c.error("Sign-in failed",A.message)}y(!1)}return O.useEffect(()=>{$&&j.current&&(clearInterval(j.current),j.current=null)},[$]),a?e.jsx(qa,{open:a,onOpenChange:A=>{A||s()},children:e.jsx(Ia,{title:"Google Workspace",description:"Connect your Google services",className:"max-w-md",children:e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"Google",className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Google Workspace"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"One set of credentials for all Google services"})]})]}),r===!1&&e.jsx(pB,{integrationId:"gmail",onConfigured:()=>l(!0)}),r===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(ze,{size:16,className:"animate-spin text-text-4"})}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans",children:"Services"}),e.jsx("div",{className:"space-y-1.5",children:k?Array.from({length:4}).map((A,z)=>e.jsx("div",{className:"h-14 rounded-md bg-surface-2 animate-pulse"},z)):w.map(A=>e.jsx(VCe,{item:A,status:u[A.id],onInstall:_,onUninstall:P,busy:f},A.id))})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),M.length>0&&!$&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{variant:"primary",size:"lg",onClick:L,disabled:g,className:"w-full gap-2",children:g?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Connects ",M.length," service",M.length!==1?"s":""," with one sign-in"]})]}),$&&M.length>0&&e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(ca,{size:20,className:"text-success"})}),e.jsx("p",{className:"text-sm font-medium text-success font-sans",children:"All services connected"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Your agents can now use these Google integrations."}),C?e.jsxs("div",{className:"w-full space-y-2 pt-2",children:[e.jsx("p",{className:"text-2xs text-warning font-sans",children:"New permissions available — re-authenticate to enable all features."}),e.jsx(he,{variant:"secondary",size:"sm",onClick:L,disabled:g,className:"w-full gap-2",children:g?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:12,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ia,{size:12})," Re-authenticate"]})})]}):e.jsx("button",{onClick:L,disabled:g,className:"text-2xs text-text-4 hover:text-text-2 font-sans underline underline-offset-2 transition-colors mt-1",children:g?"Opening browser...":"Re-authenticate"})]}),M.length===0&&!k&&e.jsx("p",{className:"text-xs text-text-4 font-sans text-center py-2",children:"Install at least one service above, then connect with Google."})]}),e.jsx(he,{variant:"secondary",size:"lg",onClick:s,className:"w-full",children:$&&M.length>0?"Done":"Close"})]})})}):null}const JT=/github\.com\/([^/]+)\/([^/\s#?]+)/;function XCe(){const[t,a]=O.useState("input"),[s,c]=O.useState(""),[r,l]=O.useState(!1),[u,p]=O.useState(null),[f,x]=O.useState("standalone"),[g,y]=O.useState(""),[k,b]=O.useState(!0),[j,w]=O.useState(""),S=q(A=>A.previewRepo),M=q(A=>A.importRepo),$=q(A=>A.importInProgress),C=va(),_=O.useCallback(async A=>{const z=A.match(JT);if(z){l(!0);try{const Y=await S(A);p(Y),w(Y.name||z[2]),a("preview")}catch(Y){C.error("Preview failed",Y.message)}finally{l(!1)}}},[S,C]),P=O.useCallback(A=>{const z=A.target.value;c(z),JT.test(z)&&t==="input"&&_(z)},[t,_]),L=O.useCallback(async()=>{if(!u)return;let A;f==="standalone"?A=`~/Projects/${u.name}`:f==="subdirectory"?A=`./packages/${u.name}`:A=g;try{await M(s,A,k,j),C.success(`Importing ${u.name}`,"Setup agent will handle the rest"),a("input"),c(""),p(null)}catch(z){C.error("Import failed",z.message)}},[u,f,g,s,k,j,M,C]);if(t==="input")return e.jsxs("div",{className:"relative",children:[e.jsx(Zt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{type:"text",value:s,onChange:P,placeholder:"Paste a GitHub URL...",className:K("w-full h-9 rounded-lg pl-9 pr-20 text-sm font-sans","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors duration-100")}),e.jsx(he,{variant:"primary",size:"sm",className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:()=>_(s),disabled:!JT.test(s)||r,children:r?e.jsx(ze,{size:12,className:"animate-spin"}):"Preview"})]});if(t==="preview"&&u)return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(es,{size:22,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx("span",{className:"text-lg font-bold text-text-0 font-sans",children:u.name}),e.jsx("span",{className:"text-xs text-text-4 font-sans",children:u.owner})]}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[u.language&&e.jsx(ge,{variant:"outline",className:"text-2xs",children:u.language}),u.stars!=null&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(b1,{size:10,className:"text-warning",fill:"currentColor"}),Fe(u.stars)]}),u.license&&e.jsx("span",{children:u.license})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>a("configure"),className:"h-8 text-xs gap-1.5 px-4",children:[e.jsx(ta,{size:13}),"Clone & Setup"]}),e.jsxs(he,{variant:"ghost",size:"sm",onClick:()=>{try{const A=s.startsWith("http")?s:`https://${s}`,z=new URL(A);(z.protocol==="https:"||z.protocol==="http:")&&window.open(A,"_blank")}catch{}},className:"h-8 text-xs gap-1.5",children:[e.jsx(Pt,{size:12}),"GitHub"]}),e.jsx("button",{onClick:()=>{a("input"),p(null)},className:"text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 ml-1",children:"Cancel"})]})]})}),u.description&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2",children:"About"}),e.jsx("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:u.description})]}),u.readmePreview&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-3",children:"README"}),e.jsx("div",{className:"text-sm text-text-2 font-sans leading-relaxed whitespace-pre-wrap",children:u.readmePreview})]})]});if(t==="configure"&&u){const A=[{id:"standalone",icon:Xo,title:"Standalone project",description:"Clone to its own directory, separate from this workspace",path:`~/Projects/${u.name}`},{id:"subdirectory",icon:Zd,title:"Workspace package",description:"Add as a package inside this project's monorepo",path:`./packages/${u.name}`},{id:"custom",icon:zo,title:"Custom location",description:"Choose your own path",path:null}];return e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-border-subtle bg-surface-3/50",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(Oa,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:["Clone ",u.name]}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:[u.owner,"/",u.name," — configure where to install"]})]})]})}),e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2.5 block",children:"Install location"}),e.jsx("div",{className:"space-y-2",children:A.map(z=>{const Y=z.icon,V=f===z.id;return e.jsx("button",{onClick:()=>x(z.id),className:K("w-full text-left rounded-lg border p-3.5 transition-all duration-150 cursor-pointer",V?"border-accent bg-accent/5 ring-1 ring-accent/30":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-1/80"),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:K("w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0 mt-0.5",V?"bg-accent/15 text-accent":"bg-surface-3 text-text-4"),children:e.jsx(Y,{size:15})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:K("text-xs font-semibold font-sans",V?"text-text-0":"text-text-2"),children:z.title}),V&&e.jsx("div",{className:"w-4 h-4 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Ve,{size:10,className:"text-white"})})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5 leading-relaxed",children:z.description}),z.path&&V&&e.jsx("code",{className:"text-2xs text-accent/80 font-mono mt-1.5 block truncate",children:z.path})]})]})},z.id)})}),f==="custom"&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:g,onChange:z=>y(z.target.value),placeholder:"/path/to/clone",autoFocus:!0,className:K("w-full h-9 px-3 text-xs font-mono rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-3 flex items-center justify-center",children:e.jsx(sn,{size:14,className:"text-text-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans block",children:"Create a team"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Organize agents working on this repo into their own team"})]})]}),e.jsx("button",{onClick:()=>b(!k),className:K("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer flex-shrink-0",k?"bg-accent":"bg-surface-5"),children:e.jsx("div",{className:K("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",k?"translate-x-4":"translate-x-0")})})]}),k&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:j,onChange:z=>w(z.target.value),placeholder:"Team name",className:K("w-full h-9 px-3 text-xs font-sans rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle bg-surface-3/30 flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>a("preview"),className:"flex items-center gap-1.5 text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 transition-colors",children:[e.jsx(Qd,{size:11}),"Back"]}),e.jsx(he,{variant:"primary",size:"sm",onClick:L,disabled:$||f==="custom"&&!g.trim(),className:"h-8 text-xs gap-1.5 px-5",children:$?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:12,className:"animate-spin"})," Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Oa,{size:12})," Clone & Setup"]})})]})]})}return null}function ZCe({repo:t,onRemove:a,onNuke:s,onOpen:c}){return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:t.repoName||t.name}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.repoOwner||t.owner})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.language&&e.jsx(ge,{variant:"outline",className:"text-2xs",children:t.language}),e.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-[180px]",children:t.clonedTo||t.path})]}),e.jsx("span",{className:"text-2xs text-text-4 font-sans mt-0.5 block",children:t.clonedAt?`Imported ${gt(t.clonedAt)}`:t.status||""})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[c&&e.jsxs("button",{onClick:()=>c(t),className:K("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-accent bg-accent/10 hover:bg-accent/20 border-0 transition-colors"),children:[e.jsx(ta,{size:11}),"Open"]}),a&&e.jsxs("button",{onClick:()=>a(t),className:K("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-text-3 hover:text-text-1 hover:bg-surface-4 bg-transparent border-0 transition-colors"),children:[e.jsx(wt,{size:11}),"Remove"]}),s&&e.jsxs("button",{onClick:()=>s(t),className:K("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-danger bg-danger/10 hover:bg-danger/20 border-0 transition-colors"),children:[e.jsx(h2,{size:11}),"Nuke"]})]})]})}function DCe({repo:t,open:a,onClose:s,onConfirm:c}){var g,y,k;const[r,l]=O.useState(!0);if(!t)return null;const u=((g=t.agents)==null?void 0:g.length)||0,p=((y=t.processes)==null?void 0:y.length)||0,f=((k=t.credentialKeys)==null?void 0:k.length)||0,x=t.fileCount||0;return e.jsx(qa,{open:a,onOpenChange:b=>{b||s()},children:e.jsx(Ia,{title:`Nuke ${t.repoName||t.name}?`,description:"Confirm destructive removal of imported repo",children:e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Et,{size:16,className:"text-danger flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-text-1 font-sans",children:"This cannot be undone."})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-text-2 font-sans",children:[u>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Kill ",u," agent",u!==1?"s":""]}),p>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Stop ",p," process",p!==1?"es":""]}),f>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Remove ",f," credential",f!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"}),' Delete team "',t.teamId||t.repoName||t.name,'"']}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Clean all .groove state"]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:b=>l(b.target.checked),className:"accent-[var(--color-danger)]"}),e.jsxs("span",{className:"text-xs text-text-1 font-sans",children:["Delete repo files",x>0?` (${x} files)`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(he,{variant:"danger",size:"sm",onClick:()=>c(r),children:"Nuke Everything"}),e.jsx(he,{variant:"ghost",size:"sm",onClick:s,children:"Cancel"})]})]})})})}function xB({skill:t,onBack:a}){var P,L,A;const s=va(),[c,r]=O.useState(""),[l,u]=O.useState(!1),[p,f]=O.useState(!1),[x,g]=O.useState(!1),[y,k]=O.useState(!1),[b,j]=O.useState(t.installed),[w,S]=O.useState(!0);O.useEffect(()=>{S(!0),X.get(`/skills/${t.id}/content`).then(z=>{r(z.content||""),u(z.requiresPurchase||!1)}).catch(()=>{}).finally(()=>S(!1))},[t.id]);async function M(){f(!0);try{await X.post(`/skills/${t.id}/install`),j(!0),s.success(`${t.name} installed`)}catch(z){s.error("Install failed",z.message)}f(!1)}async function $(){g(!0);try{await X.post(`/skills/${t.id}/update`),s.success(`${t.name} updated to latest`);const z=await X.get(`/skills/${t.id}/content`);z.content&&r(z.content)}catch(z){s.error("Update failed",z.message)}g(!1)}async function C(){k(!0);try{await X.delete(`/skills/${t.id}`),j(!1),s.success(`${t.name} uninstalled`)}catch(z){s.error("Uninstall failed",z.message)}k(!1)}async function _(){const{marketplaceAuthenticated:z,marketplaceLogin:Y,marketplaceCheckout:V}=q.getState();if(!z){Y();return}try{await V(t.id)}catch{}}return e.jsx(It,{className:"h-full",children:e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("button",{onClick:a,className:"flex items-center gap-1 text-xs text-text-3 font-sans hover:text-text-0 cursor-pointer bg-transparent border-0 mb-4",children:[e.jsx(Vs,{size:14})," Back"]}),e.jsxs("div",{className:"flex gap-8",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-[22px]",children:t.icon||((L=(P=t.name)==null?void 0:P[0])==null?void 0:L.toUpperCase())}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[e.jsx("span",{children:t.author||"Community"}),(t.source==="claude-official"||t.verified)&&e.jsx(dB,{type:t.source,size:13})]})]})]}),e.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((A=t.tags)==null?void 0:A.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:t.tags.map(z=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:z},z))}),e.jsx("div",{className:"h-px bg-border-subtle my-5"}),w?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):c?e.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:c})]}):l?e.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[e.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):e.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),e.jsx("div",{className:"w-[240px] flex-shrink-0",children:e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[e.jsx(lB,{price:t.price||0,size:"md"}),l&&!b?e.jsxs("button",{onClick:_,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 flex items-center justify-center gap-2 border bg-warning/15 text-warning border-warning/20 hover:bg-warning/25",children:["Buy $",(t.price||0).toFixed(2)]}):b?e.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[e.jsxs("button",{onClick:$,disabled:x,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:[e.jsx(ia,{size:12,className:x?"animate-spin":""}),x?"Updating...":"Pull Latest"]}),e.jsxs("button",{onClick:C,disabled:y,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-error/10 text-error border-error/20 hover:bg-error/15",children:[e.jsx(wt,{size:12}),y?"Removing...":"Uninstall"]})]}):e.jsx("button",{onClick:M,disabled:p,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:p?"Installing...":"Install"}),e.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",e.jsx("span",{className:"font-mono text-text-0",children:Fe(t.downloads||0)},"d")],["Rating",e.jsx(rB,{rating:t.rating||0,count:t.rating_count||t.ratingCount,size:"sm"},"r")],["Version",e.jsx("span",{className:"font-mono text-text-0",children:t.version||"1.0.0"},"v")],["Category",e.jsx(iB,{label:t.category||"general",variant:t.category||"draft"},"c")],["Source",e.jsx("span",{className:"text-text-0",children:t.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([z,Y])=>e.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:z}),Y]},z))})]})})]})]})})}function UCe(){const[t,a]=O.useState([]),[s,c]=O.useState(!0),[r,l]=O.useState(""),[u,p]=O.useState(""),[f,x]=O.useState("popular"),[g,y]=O.useState(null);return O.useEffect(()=>{c(!0);const k=new URLSearchParams;r&&k.set("search",r),u&&k.set("category",u),f&&k.set("sort",f),X.get(`/skills/registry?${k}`).then(b=>a(SCe(b.skills||b.items||(Array.isArray(b)?b:[])))).catch(()=>a([])).finally(()=>c(!1))},[r,u,f]),g?e.jsx(xB,{skill:g,onBack:()=>y(null)}):e.jsx(It,{className:"h-full",children:e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-72",children:e.jsx(_A,{value:r,onChange:l})}),e.jsx(LCe,{selected:u,onSelect:p}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsxs("select",{value:f,onChange:k=>x(k.target.value),className:"appearance-none font-sans cursor-pointer pr-7 py-2 pl-3 text-xs bg-surface-0 border border-border-subtle rounded text-text-1 focus:outline-none",children:[e.jsx("option",{value:"popular",children:"Popular"}),e.jsx("option",{value:"rating",children:"Top Rated"}),e.jsx("option",{value:"newest",children:"Newest"}),e.jsx("option",{value:"name",children:"A-Z"})]}),e.jsx(zt,{size:12,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:t.length})]}),e.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:s?Array.from({length:8}).map((k,b)=>e.jsx(hB,{},b)):t.map(k=>e.jsx($Ce,{skill:k,onClick:y},k.id))}),!s&&t.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No skills found."})]})})}const kX=new Set(["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"]);function HCe(){const[t,a]=O.useState([]),[s,c]=O.useState(!0),[r,l]=O.useState(""),[u,p]=O.useState(null),[f,x]=O.useState(!1),[g,y]=O.useState(!1),k=()=>{c(!0),X.get(`/integrations/registry?search=${encodeURIComponent(r)}`).then(C=>a(C.integrations||C.items||(Array.isArray(C)?C:[]))).catch(()=>a([])).finally(()=>c(!1))};O.useEffect(()=>{k()},[r]);const b=t.filter(C=>kX.has(C.id)),j=t.filter(C=>!kX.has(C.id)),w=b.filter(C=>C.installed).length;function S(C){p(C),x(!0)}function M(){x(!1),p(null),k()}const $=!r||"google workspace gmail calendar drive docs sheets slides".includes(r.toLowerCase());return e.jsxs(It,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-72",children:e.jsx(_A,{value:r,onChange:l,placeholder:"Search integrations..."})}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:j.length+(b.length>0?1:0)})]}),e.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:s?Array.from({length:6}).map((C,_)=>e.jsx(hB,{},_)):e.jsxs(e.Fragment,{children:[b.length>0&&$&&e.jsx(jQ,{item:{id:"google-workspace",name:"Google Workspace",description:"Gmail, Calendar, Drive, Docs, Sheets, Slides — one sign-in for all",category:"productivity",tags:["google","email","calendar","drive","docs"],verified:"mcp-official",installed:w>0,_installedCount:w},onClick:()=>y(!0)},"google-workspace"),j.map(C=>e.jsx(jQ,{item:C,onClick:()=>S(C)},C.id))]})}),!s&&j.length===0&&b.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No integrations found."})]}),e.jsx(fB,{integration:u,open:f,onClose:M}),e.jsx(ECe,{integrations:t,open:g,onClose:()=>{y(!1),k()}})]})}function BCe(){const t=q(R=>R.marketplaceAuthenticated),a=q(R=>R.marketplaceLogin),[s,c]=O.useState([]),[r,l]=O.useState([]),[u,p]=O.useState([]),[f,x]=O.useState(!0),[g,y]=O.useState("all"),[k,b]=O.useState(""),[j,w]=O.useState(null),[S,M]=O.useState(null),[$,C]=O.useState(!1),_=va(),P=O.useRef(null),L=async()=>{const[R,I]=await Promise.all([X.get("/skills/installed").catch(()=>[]),X.get("/integrations/installed").catch(()=>[])]);l(Array.isArray(R)?R:R.skills||[]),p(Array.isArray(I)?I:I.integrations||[])};O.useEffect(()=>{x(!0),Promise.all([t?X.get("/auth/purchases").then(R=>R.purchases||[]).catch(()=>[]):Promise.resolve([]),X.get("/skills/installed").then(R=>Array.isArray(R)?R:R.skills||[]).catch(()=>[]),X.get("/integrations/installed").then(R=>Array.isArray(R)?R:R.integrations||[]).catch(()=>[])]).then(([R,I,T])=>{c(R),l(I),p(T)}).finally(()=>x(!1))},[t]);async function A(R){var T;const I=(T=R.target.files)==null?void 0:T[0];if(I){try{const Z=await I.text(),J=I.name.replace(/\.md$/i,"");await X.post("/skills/import",{name:J,content:Z}),_.success(`Imported "${J}"`),await L()}catch(Z){_.error("Import failed",Z.message)}R.target.value=""}}if(j)return e.jsx(xB,{skill:j,onBack:()=>w(null)});const z=k.toLowerCase(),Y=g==="all"||g==="skills"?r.filter(R=>!z||(R.name||R.id||"").toLowerCase().includes(z)||(R.description||"").toLowerCase().includes(z)):[],V=g==="all"||g==="integrations"?u.filter(R=>!z||(R.name||R.id||"").toLowerCase().includes(z)||(R.description||"").toLowerCase().includes(z)):[],se=[...Y.map(R=>({...R,_type:"skill"})),...V.map(R=>({...R,_type:"integration"}))],ne=[{id:"all",label:"All"},{id:"skills",label:"Skills"},{id:"integrations",label:"Integrations"}],oe={all:"No skills or integrations installed yet. Visit the Marketplace to get started.",skills:"No skills installed.",integrations:"No integrations installed."};return f?e.jsx("div",{className:"p-5 space-y-3",children:[...Array(4)].map((R,I)=>e.jsx(en,{className:"h-14 rounded-md"},I))}):e.jsxs(It,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("div",{className:"w-72",children:e.jsx(_A,{value:k,onChange:b,placeholder:"Search library..."})}),e.jsx("div",{className:"flex items-center gap-1",children:ne.map(R=>e.jsx("button",{onClick:()=>y(R.id),className:`px-3 py-1.5 text-xs font-semibold font-sans rounded-full cursor-pointer select-none transition-colors ${g===R.id?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1 border border-transparent hover:border-border-subtle"}`,children:R.label},R.id))}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{ref:P,type:"file",accept:".md",onChange:A,className:"hidden"}),e.jsxs(he,{variant:"secondary",size:"md",onClick:()=>{var R;return(R=P.current)==null?void 0:R.click()},className:"gap-1.5",children:[e.jsx(A2,{size:13}),"Import .md"]}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:se.length})]}),t&&s.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[e.jsx(k1,{size:12}),"Purchases (",s.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:s.map(R=>{var I,T;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center text-sm flex-shrink-0",children:R.skill_icon||((T=(I=R.skill_name)==null?void 0:I[0])==null?void 0:T.toUpperCase())||"?"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:R.skill_name||R.skill_id}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:["$",(R.amount||0).toFixed(2)," · ",gt(R.created_at)]})]}),e.jsx(ge,{variant:"success",className:"text-2xs flex-shrink-0",children:"Owned"})]},R.id||R.skill_id)})})]}),t&&s.length===0&&e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[e.jsx(k1,{size:20,className:"mx-auto text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No purchases yet"})]}),!t&&e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[e.jsx(k1,{size:20,className:"mx-auto text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-2 font-sans mb-3",children:"Sign in to see your purchases"}),e.jsxs(he,{variant:"primary",size:"sm",onClick:a,className:"gap-1.5 mx-auto",children:[e.jsx(Do,{size:12})," Sign in"]})]}),se.length>0?e.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:se.map(R=>R._type==="skill"?e.jsx(jQ,{item:{...R,installed:!0},onClick:()=>w(R)},`skill-${R.id}`):e.jsx(jQ,{item:{...R,installed:!0},onClick:()=>{M(R),C(!0)},statusBadge:e.jsx(ge,{variant:R.configured?"success":"warning",className:"text-2xs",children:R.configured?"Active":"Not configured"})},`int-${R.id}`))}):e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:oe[g]})]}),e.jsx(fB,{integration:S,open:$,onClose:()=>{C(!1),M(null),L()}})]})}function GCe(){const t=q(x=>x.importedRepos),a=q(x=>x.fetchImportedRepos),s=q(x=>x.softRemoveRepo),c=q(x=>x.hardNukeRepo),r=va(),[l,u]=O.useState(null);O.useEffect(()=>{a()},[]);async function p(x){try{await s(x.id),r.success(`Removed ${x.repoName||x.name}`)}catch(g){r.error("Remove failed",g.message)}}async function f(x){if(l){try{x?await c(l.id):await s(l.id),r.success(`${x?"Nuked":"Removed"} ${l.name||l.repo}`)}catch(g){r.error("Nuke failed",g.message)}u(null)}}return e.jsxs(It,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsx(XCe,{}),t.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3",children:"Recently Imported"}),e.jsx("div",{className:"space-y-2",children:(Array.isArray(t)?t:[]).map(x=>e.jsx(ZCe,{repo:x,onRemove:()=>p(x),onNuke:()=>u(x)},x.id))})]}),t.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No repos imported yet. Paste a GitHub URL above to get started."})]}),e.jsx(DCe,{repo:l,open:!!l,onClose:()=>u(null),onConfirm:f})]})}function WCe(){const[t,a]=O.useState("skills"),s=[{id:"skills",label:"Skills",icon:bt},{id:"integrations",label:"Integrations",icon:Lt},{id:"github",label:"GitHub",icon:es},{id:"library",label:"My Library",icon:Zd}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-b border-border-subtle",children:e.jsxs("div",{className:"flex items-center px-5 h-11",children:[e.jsx("div",{className:"flex items-center",children:s.map(c=>{const r=c.icon;return e.jsxs("button",{onClick:()=>a(c.id),className:`flex items-center gap-1.5 px-3 py-2.5 text-xs font-semibold font-sans cursor-pointer select-none border-b-2 -mb-px transition-colors ${t===c.id?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"}`,children:[e.jsx(r,{size:12}),c.label]},c.id)})}),e.jsx("div",{className:"flex-1"})]})}),e.jsxs("div",{className:"flex-1 min-h-0",children:[t==="skills"&&e.jsx(UCe,{}),t==="integrations"&&e.jsx(HCe,{}),t==="github"&&e.jsx(GCe,{}),t==="library"&&e.jsx(BCe,{})]})]})}function YCe(){const t=q(l=>l.teams),a=q(l=>l.agents),s=q(l=>l.activeTeamId),c=q(l=>l.deleteTeam),r=q(l=>l.addToast);return t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(sn,{size:28,className:"mx-auto text-text-4"}),e.jsx("p",{className:"text-xs font-sans text-text-3",children:"No teams yet"}),e.jsx("p",{className:"text-2xs font-sans text-text-4",children:"Teams are created when you spawn agents or launch a planner"})]})}):e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx("div",{className:"p-4 space-y-3",children:t.map(l=>{const u=a.filter(b=>b.teamId===l.id),p=u.filter(b=>b.status==="running"||b.status==="starting"),f=u.filter(b=>b.status==="completed"),x=u.filter(b=>b.status==="crashed"),g=u.reduce((b,j)=>b+(j.tokensUsed||0),0),y=u.reduce((b,j)=>b+(j.costUsd||0),0),k=l.id===s;return e.jsxs("div",{className:K("rounded-md border bg-surface-1 overflow-hidden transition-colors",k?"border-accent/30":"border-border-subtle"),children:[e.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans",children:l.name}),k&&e.jsx(ge,{variant:"accent",className:"text-2xs",children:"Active"})]}),l.workingDir&&e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(Ad,{size:10,className:"text-text-4"}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:l.workingDir})]})]}),e.jsx("button",{onClick:()=>{if(u.some(b=>b.status==="running")){r("error","Stop running agents first");return}c(l.id)},className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Delete team",children:e.jsx(wt,{size:13})})]}),e.jsxs("div",{className:"px-4 py-2.5 border-t border-border-subtle bg-surface-0 flex items-center gap-4",children:[e.jsx(jd,{label:"Agents",value:u.length}),e.jsx(jd,{label:"Running",value:p.length,color:p.length>0?"text-success":void 0}),e.jsx(jd,{label:"Done",value:f.length}),e.jsx(jd,{label:"Crashed",value:x.length,color:x.length>0?"text-danger":void 0}),e.jsx("div",{className:"flex-1"}),e.jsx(jd,{label:"Tokens",value:Fe(g)}),y>0&&e.jsx(jd,{label:"Cost",value:Jo(y)})]}),u.length>0&&e.jsx("div",{className:"border-t border-border-subtle",children:u.map(b=>e.jsxs("div",{className:"flex items-center gap-2 px-4 py-1.5 border-b border-border-subtle last:border-b-0",children:[e.jsx(aa,{status:b.status,size:"sm"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:b.name}),e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase",children:b.role}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-2xs font-mono text-text-2 tabular-nums",children:Fe(b.tokensUsed||0)})]},b.id))})]},l.id)})})})}function jd({label:t,value:a,color:s}){return e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:K("text-xs font-mono tabular-nums",s||"text-text-1"),children:a}),e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:t})]})}function FCe(){const t=q(c=>c.pendingApprovals),a=q(c=>c.approveRequest),s=q(c=>c.rejectRequest);return t.length===0?null:e.jsxs("div",{className:"px-4 pt-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Et,{size:12,className:"text-warning"}),e.jsxs("span",{className:"text-2xs font-mono text-warning uppercase tracking-wider",children:["Pending (",t.length,")"]})]}),t.map(c=>{var r,l,u;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs text-text-0 font-sans font-medium truncate",children:[c.agentName,": ",((r=c.action)==null?void 0:r.description)||((l=c.action)==null?void 0:l.type)||"action"]}),((u=c.action)==null?void 0:u.filePath)&&e.jsx("div",{className:"text-2xs font-mono text-text-3 truncate mt-0.5",children:c.action.filePath}),e.jsx("div",{className:"text-2xs text-text-4 font-mono mt-0.5",children:gt(c.requestedAt)})]}),e.jsxs("div",{className:"flex gap-1.5 flex-shrink-0",children:[e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>a(c.id),className:"h-7 px-2.5 gap-1 text-2xs",children:[e.jsx(O1,{size:10})," Approve"]}),e.jsxs(he,{variant:"danger",size:"sm",onClick:()=>s(c.id),className:"h-7 px-2.5 gap-1 text-2xs",children:[e.jsx(qs,{size:10})," Reject"]})]})]},c.id)})]})}function KCe(){const t=q(f=>f.resolvedApprovals),[a,s]=O.useState([]),[c,r]=O.useState(!0);O.useEffect(()=>{const f=setInterval(l,4e3);return l(),()=>clearInterval(f)},[]);async function l(){try{const f=await X.get("/pm/history");s(f.history||f||[])}catch{}r(!1)}const u=new Set,p=[...t,...a].filter(f=>{const x=f.id||`${f.agentName}-${f.timestamp}`;return u.has(x)?!1:(u.add(x),!0)});return e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsx(FCe,{}),e.jsxs("div",{className:"p-4 space-y-1.5",children:[c&&p.length===0&&e.jsx("div",{className:"text-center py-12 text-text-4 font-mono text-xs",children:"Loading..."}),!c&&p.length===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ca,{size:24,className:"mx-auto mb-2 text-text-4"}),e.jsx("p",{className:"text-xs font-sans text-text-3",children:"No approval history"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Approvals appear when agents use Auto permission mode"})]}),p.map((f,x)=>{var y;const g=f.status==="approved"||f.verdict==="approved";return e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-0 border border-border-subtle",children:[g?e.jsx(ca,{size:12,className:"text-success flex-shrink-0"}):e.jsx(yn,{size:12,className:"text-danger flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs text-text-1 font-sans truncate",children:[e.jsx("span",{className:"font-medium text-text-0",children:f.agentName}),e.jsx("span",{className:"text-text-3 mx-1",children:"·"}),e.jsx("span",{children:((y=f.action)==null?void 0:y.description)||f.action||"action"})]}),f.reason&&e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate mt-0.5",children:f.reason})]}),e.jsx("span",{className:"text-2xs font-mono text-text-4 flex-shrink-0",children:gt(f.resolvedAt||f.timestamp)})]},f.id||x)})]})]})}function JCe(){const[t,a]=O.useState([]),[s,c]=O.useState(!0),r=va();O.useEffect(()=>{const p=setInterval(l,1e4);return l(),()=>clearInterval(p)},[]);async function l(){try{const p=await X.get("/schedules");a(p.schedules||p||[])}catch{}c(!1)}async function u(p,f){try{await X.post(`/schedules/${p}/${f?"disable":"enable"}`),l()}catch(x){r.error("Failed to toggle schedule",x.message)}}return e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("div",{className:"p-4 space-y-2",children:[s&&t.length===0&&e.jsx("div",{className:"text-center py-12 text-text-4 font-mono text-xs",children:"Loading..."}),!s&&t.length===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Vo,{size:24,className:"mx-auto mb-2 text-text-4"}),e.jsx("p",{className:"text-xs font-sans text-text-3",children:"No schedules configured"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Use the CLI to create agent schedules"})]}),t.map(p=>e.jsxs("div",{className:"rounded-md border border-border-subtle bg-surface-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:p.name}),e.jsx(ge,{variant:p.enabled?"success":"default",className:"text-2xs",children:p.enabled?"Active":"Paused"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:"text-2xs font-mono text-text-2",children:p.cron}),e.jsx("span",{className:"text-2xs text-text-4",children:"·"}),e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase",children:p.role}),p.teamId&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xs text-text-4",children:"·"}),e.jsx("span",{className:"text-2xs font-sans text-text-3",children:p.teamName||p.teamId})]})]}),p.prompt&&e.jsx("div",{className:"text-2xs font-sans text-text-4 mt-1 truncate",children:p.prompt})]}),e.jsx(he,{variant:"secondary",size:"sm",onClick:()=>u(p.id,p.enabled),className:"h-7 px-2.5 gap-1 text-2xs",children:p.enabled?e.jsxs(e.Fragment,{children:[e.jsx(L2,{size:10})," Pause"]}):e.jsxs(e.Fragment,{children:[e.jsx(z2,{size:10})," Enable"]})})]}),p.lastRunAt&&e.jsxs("div",{className:"px-4 py-1.5 border-t border-border-subtle bg-surface-1 text-2xs font-mono text-text-4",children:["Last run: ",gt(p.lastRunAt),p.nextRunAt&&e.jsxs("span",{className:"ml-3",children:["Next: ",gt(p.nextRunAt)]})]})]},p.id))]})})}function eQe(){return e.jsxs(MA,{defaultValue:"dashboard",className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-4 pt-3 bg-surface-1 border-b border-border",children:[e.jsx("div",{className:"flex items-center gap-4 mb-0",children:e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Management"})}),e.jsxs(jA,{className:"border-b-0",children:[e.jsxs(kn,{value:"dashboard",className:"inline-flex items-center gap-1.5",children:[e.jsx(j2,{size:12}),"Teams"]}),e.jsxs(kn,{value:"approvals",className:"inline-flex items-center gap-1.5",children:[e.jsx(S2,{size:12}),"Approvals"]}),e.jsxs(kn,{value:"schedules",className:"inline-flex items-center gap-1.5",children:[e.jsx(Vo,{size:12}),"Schedules"]})]})]}),e.jsx(vn,{value:"dashboard",className:"flex flex-col min-h-0",children:e.jsx(YCe,{})}),e.jsx(vn,{value:"approvals",className:"flex flex-col min-h-0",children:e.jsx(KCe,{})}),e.jsx(vn,{value:"schedules",className:"flex flex-col min-h-0",children:e.jsx(JCe,{})})]})}const tQe={code:"Code",general:"General"},aQe={light:"text-success",medium:"text-accent",heavy:"text-warning"};function nQe(t){return t<1?`${Math.round(t*1024)} MB`:`${t} GB`}function mB({hardware:t}){if(!t)return null;const{totalRamGb:a,gpu:s,isAppleSilicon:c}=t;return e.jsxs("div",{className:"flex items-center gap-3 bg-surface-0 rounded-lg border border-border-subtle px-3 py-2.5",children:[e.jsx(Uo,{size:14,className:"text-text-3 flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs font-sans",children:[e.jsxs("span",{className:"text-text-0 font-semibold",children:[a," GB RAM"]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{className:"text-text-2",children:s.name})]}),c&&e.jsx(ge,{variant:"accent",className:"text-2xs",children:"Unified Memory"})]})})]})}function sQe({onRecheck:t}){const[a,s]=O.useState(null),[c,r]=O.useState(!1),[l,u]=O.useState(!1),[p,f]=O.useState(!1),x=q(_=>_.addToast);O.useEffect(()=>{X.post("/providers/ollama/check").then(s).catch(()=>{})},[]);async function g(){r(!0);try{const _=await X.post("/providers/ollama/check");s(_),_.installed&&_.serverRunning?(x("success","Ollama is ready!"),t()):_.installed?x("info","Ollama installed — server needs to start"):x("info","Ollama not found — install and try again")}catch{}r(!1)}async function y(){u(!0);try{if((await X.post("/providers/ollama/serve")).ok){x("success","Ollama server started!");let P=!1;for(let L=0;L<5;L++){await new Promise(z=>setTimeout(z,2e3));const A=await X.post("/providers/ollama/check");if(s(A),A.serverRunning){P=!0;break}}P&&t()}}catch(_){x("error","Could not start server",_.message)}u(!1)}function k(_){navigator.clipboard.writeText(_),f(!0),setTimeout(()=>f(!1),2e3)}if(!a)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{hardware:b,install:j,requirements:w,installed:S,serverRunning:M}=a,$=b.totalRamGb>=w.minRAM,C=b.recommended;return e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsx(mB,{hardware:b}),$?e.jsxs("div",{className:"flex items-start gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2.5",children:[e.jsx(Ve,{size:14,className:"text-success flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans",children:[e.jsx("span",{className:"text-success font-semibold",children:"Your system is ready."}),e.jsx("span",{className:"text-text-2 ml-1",children:C.code?`Recommended: ${C.code}`:`${b.totalRamGb} GB RAM available`})]})]}):e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(vt,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsxs("span",{className:"text-warning font-semibold",children:[b.totalRamGb," GB RAM detected."]})," ","Minimum ",w.minRAM," GB needed. Smallest models may still work."]})]}),S&&!M&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(vt,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama installed but server not running."})," ","The server needs to be running to pull and use models."]})]}),e.jsxs(he,{variant:"primary",size:"md",onClick:y,disabled:l,className:"w-full gap-1.5",children:[e.jsx(qt,{size:12}),l?"Starting...":"Start Ollama Server"]})]}),!S&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold text-text-1 font-sans",children:"Install Ollama"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 bg-surface-0 border border-border-subtle rounded-md px-3 py-2 text-xs font-mono text-text-1 truncate",children:j.command}),e.jsxs(he,{variant:"secondary",size:"sm",onClick:()=>k(j.command),className:"h-8 px-2.5 gap-1 flex-shrink-0",children:[p?e.jsx(Ve,{size:12}):e.jsx(Mn,{size:12}),p?"Copied":"Copy"]})]}),j.alt&&e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:j.alt})]}),e.jsxs(he,{variant:"secondary",size:"md",onClick:g,disabled:c,className:"w-full gap-1.5",children:[e.jsx(ia,{size:12,className:c?"animate-spin":""}),c?"Checking...":S?"Check again":"I installed it — check again"]})]})}function oQe({model:t,isInstalled:a,isRecommended:s,canRun:c,onPull:r,onDelete:l,pulling:u}){const p=u===t.id;return e.jsxs("div",{className:K("flex items-center gap-2 px-3 py-2 border-t border-border-subtle transition-colors",!c&&"opacity-40"),children:[a?e.jsx(Ve,{size:12,className:"text-success flex-shrink-0"}):e.jsx("div",{className:"w-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 truncate",children:t.name}),s&&e.jsx(b1,{size:10,className:"text-warning flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:K("text-2xs font-semibold font-sans",aQe[t.tier]),children:t.tier}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:nQe(t.sizeGb)}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["· ",t.ramGb," GB RAM"]})]})]}),a?e.jsx("button",{onClick:()=>l(t.id),className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Remove model",children:e.jsx(wt,{size:12})}):c?e.jsx(he,{variant:"secondary",size:"sm",onClick:()=>r(t.id),disabled:!!u,className:"h-7 px-2 text-2xs gap-1",children:p?e.jsxs(e.Fragment,{children:[e.jsx(ia,{size:10,className:"animate-spin"})," Pulling..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Oa,{size:10})," Pull"]})}):e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["Needs ",t.ramGb," GB"]})]})}function cQe({onStopped:t}){const[a,s]=O.useState(null),c=q(u=>u.addToast);async function r(){s("stopping");try{(await X.post("/providers/ollama/stop")).ok?(c("info","Ollama server stopped"),t&&t()):c("error","Could not stop server")}catch(u){c("error","Stop failed",u.message)}s(null)}async function l(){s("restarting");try{(await X.post("/providers/ollama/restart")).ok?c("success","Ollama server restarted"):c("error","Restart failed")}catch(u){c("error","Restart failed",u.message)}s(null)}return e.jsxs("div",{className:"flex items-center gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-success"}),e.jsx("span",{className:"absolute inset-[-2px] rounded-full bg-success opacity-20 animate-pulse"})]}),e.jsx("span",{className:"text-xs font-sans text-success font-semibold",children:"Server Running"}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:":11434"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:l,disabled:!!a,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-accent cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(ia,{size:10,className:a==="restarting"?"animate-spin":""}),a==="restarting"?"Restarting...":"Restart"]}),e.jsxs("button",{onClick:r,disabled:!!a,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-danger cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(vt,{size:10}),a==="stopping"?"Stopping...":"Stop"]})]})}function rQe({onModelChange:t}){var z,Y;const[a,s]=O.useState(null),[c,r]=O.useState(null),[l,u]=O.useState("code"),[p,f]=O.useState(!1),[x,g]=O.useState(!1),y=q(V=>V.addToast),k=O.useRef(!1);function b(){X.get("/providers/ollama/models").then(V=>{var se;s(V),!k.current&&((se=V.installed)==null?void 0:se.length)===0&&(k.current=!0,setTimeout(b,2e3))}).catch(()=>{})}O.useEffect(()=>{b()},[]);async function j(V){r(V);try{await X.post("/providers/ollama/pull",{model:V}),y("success",`Pulled ${V}`),b(),t&&t()}catch(se){y("error",`Pull failed: ${se.message}`)}r(null)}async function w(V){try{await X.delete(`/providers/ollama/models/${encodeURIComponent(V)}`),y("info",`Removed ${V}`),b(),t&&t()}catch(se){y("error",`Delete failed: ${se.message}`)}}if(!a)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{installed:S,catalog:M,hardware:$}=a,C=new Set(S.map(V=>V.id)),_=$.totalRamGb,P=[(z=$.recommended)==null?void 0:z.code,(Y=$.recommended)==null?void 0:Y.general].filter(Boolean),L=M.filter(V=>V.category===l),A=p?L:L.filter(V=>V.ramGb<=_);return x?e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(vt,{size:14,className:"text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama server stopped."})," ","Start it again to pull and use models."]})]}),e.jsxs(he,{variant:"primary",size:"md",onClick:async()=>{try{(await X.post("/providers/ollama/serve")).ok&&(y("success","Ollama server started!"),g(!1),k.current=!1,setTimeout(b,2e3))}catch(V){y("error","Could not start server",V.message)}},className:"w-full gap-1.5",children:[e.jsx(qt,{size:12}),"Start Ollama Server"]})]}):e.jsxs("div",{className:"space-y-2 p-3",children:[e.jsx(cQe,{onStopped:()=>g(!0)}),e.jsx(mB,{hardware:$}),S.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-sans text-text-2",children:[e.jsx(Xo,{size:12,className:"text-text-3"}),e.jsx("span",{className:"font-semibold",children:S.length})," model",S.length!==1?"s":""," installed"]}),e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:Object.entries(tQe).map(([V,se])=>e.jsx("button",{onClick:()=>u(V),className:K("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",l===V?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:se},V))}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[A.map(V=>e.jsx(oQe,{model:V,isInstalled:C.has(V.id),isRecommended:P.includes(V.id),canRun:V.ramGb<=_,onPull:j,onDelete:w,pulling:c},V.id)),A.length===0&&e.jsxs("div",{className:"px-3 py-4 text-center text-xs text-text-4 font-sans",children:["No ",l," models available for your hardware"]})]}),!p&&L.length>A.length&&e.jsxs("button",{onClick:()=>f(!0),className:"flex items-center gap-1 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(zt,{size:10}),"Show ",L.length-A.length," more (exceed your RAM)"]})]})}function yB({isInstalled:t,onModelChange:a}){const[s,c]=O.useState(!1),[r,l]=O.useState(!1);return O.useEffect(()=>{t?X.post("/providers/ollama/check").then(u=>{c(u.installed&&u.serverRunning),l(!0)}).catch(()=>l(!0)):l(!0)},[t]),r?s?e.jsx(rQe,{onModelChange:a}):e.jsx(sQe,{onRecheck:()=>{c(!0),a&&a()}}):e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Checking Ollama..."})}function FQ({children:t,...a}){return e.jsx(yD,{...a,children:t})}function KQ({children:t,className:a,title:s,side:c="right",width:r=400,...l}){return e.jsxs(gD,{children:[e.jsx(OD,{className:"fixed inset-0 z-40 bg-black/30"}),e.jsxs(kD,{className:K("fixed top-0 z-50 h-full overflow-y-auto","bg-surface-1 border-l border-border shadow-2xl","data-[state=open]:animate-in data-[state=closed]:animate-out",c==="right"&&"right-0 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",c==="left"&&"left-0 data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",a),style:{width:r},...l,children:[s&&e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle sticky top-0 bg-surface-1 z-10",children:[e.jsx(vD,{className:"text-base font-semibold text-text-0 font-sans",children:s}),e.jsx(wD,{className:"p-1 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-5 transition-colors cursor-pointer",children:e.jsx(st,{size:16})})]}),e.jsx(bD,{className:"sr-only",children:"Panel"}),t]})]})}function iQe({value:t,onChange:a}){return e.jsx("button",{onClick:()=>a(!t),className:K("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer",t?"bg-accent":"bg-surface-5"),children:e.jsx("div",{className:K("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",t?"translate-x-4":"translate-x-0")})})}function lQe({provider:t,onKeyChange:a}){var S,M,$,C;const[s,c]=O.useState(!1),[r,l]=O.useState(""),[u,p]=O.useState(!1),[f,x]=O.useState(!1),g=q(_=>_.addToast),y=t.authType==="local",k=t.authType==="subscription",b=y?t.installed:k?t.installed||((S=t.authStatus)==null?void 0:S.authenticated):t.installed&&t.hasKey;async function j(){if(r.trim())try{await X.post(`/credentials/${encodeURIComponent(t.id)}`,{key:r.trim()}),g("success",`API key set for ${t.name}`),l(""),c(!1),a&&a()}catch(_){g("error","Failed to set key",_.message)}}async function w(){try{await X.delete(`/credentials/${encodeURIComponent(t.id)}`),g("info",`Removed ${t.name} key`),a&&a()}catch(_){g("error","Remove failed",_.message)}}if(y){const _=(($=(M=t.models)==null?void 0:M.filter(L=>!L.disabled))==null?void 0:$.length)||0,P=()=>q.getState().setActiveView("models");return e.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[e.jsx(aa,{status:b&&_>0?"running":"crashed",size:"sm"}),e.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"flex-1"}),b&&_>0?e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(Ve,{size:8})," ",_," models"]}):b?e.jsx(ge,{variant:"warning",className:"text-2xs",children:"No models pulled"}):e.jsx(ge,{variant:"default",className:"text-2xs",children:"Not set up"})]}),e.jsx("div",{className:"flex-1",children:f?e.jsxs(e.Fragment,{children:[e.jsx(yB,{isInstalled:b,onModelChange:a}),e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle flex gap-2",children:[e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>x(!1),className:"flex-1 h-7 text-2xs",children:"Back"}),e.jsx(he,{variant:"secondary",size:"sm",onClick:()=>{x(!1),P()},className:"flex-1 h-7 text-2xs gap-1",children:"Models Tab"})]})]}):e.jsxs("div",{className:"px-4 py-3 flex flex-col h-full",children:[e.jsx("div",{className:"text-xs text-text-3 font-sans flex-1",children:b&&_>0?"Full agentic runtime — tool calling, context rotation, zero cloud cost":b?"Ollama is running. Pull a model to start using local agents.":"Run any open-source model locally — free, private, fully offline. Requires Ollama."}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[b?e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>x(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[e.jsx(tn,{size:11})," ",_>0?"Manage":"Pull Models"]}):e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>x(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[e.jsx(tn,{size:11})," Set Up Ollama"]}),e.jsx(he,{variant:"secondary",size:"sm",onClick:P,className:"flex-1 h-7 text-2xs gap-1.5",children:"Models Tab"})]})]})})]})}return e.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[e.jsx(aa,{status:b?"running":"crashed",size:"sm"}),e.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"flex-1"}),b?e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(Ve,{size:8})," Ready"]}):e.jsx(ge,{variant:"default",className:"text-2xs",children:t.installed?k?"Not authenticated":"No key":"Not installed"})]}),e.jsxs("div",{className:"flex-1 flex flex-col px-4 py-3 min-h-[120px]",children:[((C=t.models)==null?void 0:C.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mb-3",children:t.models.map(_=>e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-surface-4 text-2xs font-mono text-text-3",children:_.name||_.id},_.id))}),k&&b&&!t.hasKey&&!s&&e.jsxs("div",{className:"flex items-center gap-1.5 h-8 px-2.5 bg-accent/8 border border-accent/20 rounded-md text-2xs font-sans text-accent mb-3",children:[e.jsx(Ve,{size:10})," Subscription active"]}),t.hasKey&&!s&&e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-1.5 h-8 px-2.5 bg-success/8 border border-success/20 rounded-md text-2xs font-sans text-success",children:[e.jsx(Ve,{size:10})," API Connected"]}),e.jsx("button",{onClick:()=>{c(!0),p(!1),l("")},className:"text-2xs text-text-4 hover:text-accent cursor-pointer font-sans",children:"Edit"}),e.jsx("button",{onClick:w,className:"text-2xs text-text-4 hover:text-danger cursor-pointer font-sans",children:"Remove"})]}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("div",{className:"space-y-2.5 pt-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:t.hasKey?"Update API Key":`${t.name} API Key`}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:r,onChange:_=>l(_.target.value),onKeyDown:_=>_.key==="Enter"&&j(),type:u?"text":"password",placeholder:"sk-...",className:"w-full h-9 px-3 pr-9 text-xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:()=>p(!u),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:u?e.jsx(Jn,{size:12}):e.jsx(ka,{size:12})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(he,{variant:"primary",size:"sm",onClick:j,disabled:!r.trim(),className:"flex-1 h-8 text-xs",children:"Save Key"}),e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>{c(!1),l("")},className:"h-8 text-xs px-3",children:"Cancel"})]})]}),!s&&!t.hasKey&&e.jsxs(he,{variant:k?"secondary":"primary",size:"sm",onClick:()=>{c(!0),p(!1),l("")},className:"w-full h-8 text-2xs gap-1.5 mt-2",children:[e.jsx(jn,{size:11}),k?"Add API key for headless mode":"Add API Key"]})]})]})}function Oc({icon:t,label:a,description:s,children:c}){return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(t,{size:12,className:"text-accent"})}),e.jsx("div",{className:"text-[13px] font-medium text-text-0 font-sans leading-tight",children:a})]}),e.jsx("div",{className:"text-2xs text-text-4 font-sans leading-relaxed",children:s}),e.jsx("div",{className:"mt-auto pt-1",children:c})]})}const gB={telegram:Zs,discord:Nn,slack:Sn},u1={telegram:"Telegram",discord:"Discord",slack:"Slack"},dQe={telegram:"Bot token from @BotFather",discord:"Bot token from Developer Portal",slack:"Bot token (xoxb-...)"},uQe=["critical","lifecycle","all"];function hQe({type:t,open:a,onOpenChange:s}){if(!t)return null;const r={telegram:{title:"Set Up Telegram",icon:Zs,intro:"Create a Telegram bot and connect it to Groove in under 2 minutes. No dependencies required.",sections:[{title:"Create Your Bot",steps:[{text:"Open Telegram on any device and search for",link:"https://t.me/BotFather",linkText:"@BotFather"},{text:"Send /newbot to start the setup"},{text:"Choose a display name — we suggest GroovePilot"},{text:'Choose a username (must end in "bot") — e.g. GroovePilot_bot'},{text:"BotFather will reply with your bot token — copy it"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Telegram card"},{text:"Paste your bot token and click Save"},{text:"The gateway will connect automatically"}]},{title:"Link a Chat",steps:[{text:"Open a chat with your new bot in Telegram"},{text:'Send any message (e.g. "hello") — Groove captures the chat ID automatically'},{text:"Click Test in the gateway card to verify"}]},{title:"Commands",note:"All commands use / prefix in Telegram:",commands:["/instruct <team> <msg>","/query <team> <question>","/plan <description>","/log <team>","/brief","/tokens","/status","/agents","/help"]}]},discord:{title:"Set Up Discord",icon:Nn,intro:"Create a Discord bot and add it to your server. Requires discord.js (installed automatically with Groove).",sections:[{title:"Create the Application",steps:[{text:"Go to the",link:"https://discord.com/developers/applications",linkText:"Discord Developer Portal"},{text:"Click New Application and name it GroovePilot"},{text:"Go to the Bot tab in the left sidebar"},{text:"Click Reset Token and copy the bot token"}]},{title:"Set Permissions & Invite",steps:[{text:"Go to OAuth2 > URL Generator"},{text:"Under Scopes, check bot"},{text:"Under Bot Permissions, check:"}],scopes:["Send Messages","Read Message History","Embed Links","Use External Emojis"],after:[{text:"Copy the generated URL at the bottom and open it in your browser"},{text:"Select your server and click Authorize"}]},{title:"Enable Message Content Intent",steps:[{text:"Go back to the Bot tab in the Developer Portal"},{text:"Scroll to Privileged Gateway Intents"},{text:"Enable Message Content Intent — required for the bot to read commands"},{text:"Click Save Changes"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Discord card"},{text:"Paste your bot token and click Save"},{text:"Send a message in any channel where the bot is — Groove captures the channel automatically"}]},{title:"Commands",note:"All commands use / prefix in Discord:",commands:["/instruct <team> <msg>","/query <team> <question>","/plan <description>","/log <team>","/brief","/tokens","/status","/agents","/help"]}]},slack:{title:"Set Up Slack",icon:Sn,intro:"Create a Slack app with Socket Mode — no public URL needed. Requires @slack/bolt (installed automatically with Groove).",sections:[{title:"Create the App",steps:[{text:"Go to",link:"https://api.slack.com/apps",linkText:"api.slack.com/apps"},{text:"Click Create New App > From scratch"},{text:"Name it GroovePilot and select your workspace"}]},{title:"Enable Socket Mode",steps:[{text:"In the left sidebar, go to Settings > Socket Mode"},{text:"Toggle Enable Socket Mode to on"},{text:"It will ask you to create an App-Level Token"},{text:'Name it "groove", add the connections:write scope'},{text:"Click Generate — copy the xapp-... token (this is your App Token)"}],important:"Save this token now — you can't view it again after closing the dialog."},{title:"Set Bot Token Scopes",steps:[{text:"Go to Features > OAuth & Permissions"},{text:"Scroll to Bot Token Scopes and add all of these:"}],scopes:["chat:write","channels:read","channels:history","groups:read","groups:history","im:history","app_mentions:read"],after:[{text:"Scroll up and click Install to Workspace"},{text:"Click Allow to grant permissions"},{text:"Copy the Bot User OAuth Token (xoxb-...) — this is your Bot Token"}]},{title:"Enable Events",steps:[{text:"Go to Features > Event Subscriptions"},{text:"Toggle Enable Events to on"},{text:"Under Subscribe to bot events, add:"}],scopes:["message.channels","message.im","app_mention"],after:[{text:"Click Save Changes at the bottom"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Slack card"},{text:"Paste your Bot Token (xoxb-...) in the first field"},{text:"Paste your App Token (xapp-...) in the second field"},{text:"Click Save — Groove will auto-connect"}]},{title:"Link a Channel",steps:[{text:"Invite the bot to a channel: /invite @GroovePilot"},{text:"Select the channel from the dropdown in the gateway card"},{text:"Or @mention the bot — it will auto-capture the channel"},{text:"Click Test to verify"}],important:"For private channels, make sure you added the groups:read scope."},{title:"Commands",note:"In Slack, use plain text commands (no / prefix) or @mention the bot:",commands:["instruct <team> <msg>","query <team> <question>","plan <description>","log <team>","brief","tokens","status","agents","help","@GroovePilot status"]}]}}[t];if(!r)return null;const l=r.icon;return e.jsx(FQ,{open:a,onOpenChange:s,children:e.jsx(KQ,{title:r.title,width:480,children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-accent/5 border border-accent/15 rounded-lg",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(l,{size:16,className:"text-accent"})}),e.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed",children:r.intro})]}),r.sections.map((u,p)=>{var f;return e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xs font-semibold text-text-0 font-sans mb-2.5 flex items-center gap-2",children:[e.jsx("span",{className:"w-5 h-5 rounded-full bg-accent/10 flex items-center justify-center text-2xs font-bold text-accent",children:p+1}),u.title]}),u.note&&e.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:u.note}),u.steps&&e.jsx("ol",{className:"space-y-2 mb-2",children:u.steps.map((x,g)=>e.jsxs("li",{className:"flex gap-2 text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono w-4 flex-shrink-0 pt-px",children:[g+1,"."]}),e.jsxs("span",{children:[x.text,x.link&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:x.link,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-0.5 font-medium",children:[x.linkText,e.jsx(Pt,{size:9})]})]})]})]},g))}),u.scopes&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2 ml-6",children:u.scopes.map(x=>e.jsx("code",{className:"px-2 py-0.5 rounded bg-surface-4 text-2xs font-mono text-accent",children:x},x))}),u.after&&e.jsx("ol",{className:"space-y-2 mb-2",start:(((f=u.steps)==null?void 0:f.length)||0)+1,children:u.after.map((x,g)=>{var y;return e.jsxs("li",{className:"flex gap-2 text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono w-4 flex-shrink-0 pt-px",children:[(((y=u.steps)==null?void 0:y.length)||0)+g+1,"."]}),e.jsx("span",{children:x.text})]},g)})}),u.important&&e.jsx("div",{className:"ml-6 p-2 bg-warning/8 border border-warning/20 rounded-md text-2xs text-warning font-sans",children:u.important}),u.commands&&e.jsx("div",{className:"ml-6 p-2.5 bg-surface-0 border border-border-subtle rounded-md space-y-1",children:u.commands.map(x=>e.jsx("code",{className:"block text-2xs font-mono text-text-1",children:x},x))})]},p)}),e.jsxs("a",{href:"https://docs.groovedev.ai/guide/gateways",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium mt-2",children:[e.jsx(Pt,{size:10}),"Full documentation at docs.groovedev.ai"]})]})})})}function pQe({gateway:t,onRefresh:a}){var oe,R;const[s,c]=O.useState(!1),[r,l]=O.useState(""),[u,p]=O.useState(""),[f,x]=O.useState(!1),[g,y]=O.useState(!1),[k,b]=O.useState(!1),[j,w]=O.useState([]),[S,M]=O.useState(!1),$=q(I=>I.addToast);O.useEffect(()=>{t.connected&&!t.chatId&&t.type==="slack"&&X.get(`/gateways/${encodeURIComponent(t.id)}/channels`).then(I=>w(Array.isArray(I)?I:[])).catch(()=>{})},[t.connected,t.chatId,t.id,t.type]);const C=gB[t.type]||an,_=t.type==="slack";async function P(){if(r.trim())try{await X.post(`/gateways/${encodeURIComponent(t.id)}/credentials`,{key:"bot_token",value:r.trim()}),_&&u.trim()&&await X.post(`/gateways/${encodeURIComponent(t.id)}/credentials`,{key:"app_token",value:u.trim()}),$("success","Token saved — connecting..."),l(""),p(""),c(!1);try{await X.post(`/gateways/${encodeURIComponent(t.id)}/connect`),$("success",`${u1[t.type]} connected!`)}catch(I){$("error","Token saved but connect failed",I.message)}a()}catch(I){$("error","Failed to save token",I.message)}}async function L(){y(!0);try{await X.post(`/gateways/${encodeURIComponent(t.id)}/test`),$("success","Test message sent!")}catch(I){$("error","Test failed",I.message)}y(!1)}async function A(){b(!0);try{t.connected?(await X.post(`/gateways/${encodeURIComponent(t.id)}/disconnect`),$("info",`${u1[t.type]} disconnected`)):(await X.post(`/gateways/${encodeURIComponent(t.id)}/connect`),$("success",`${u1[t.type]} connected!`)),a()}catch(I){$("error",t.connected?"Disconnect failed":"Connect failed",I.message)}b(!1)}async function z(I){try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{enabled:I}),a()}catch(T){$("error","Update failed",T.message)}}async function Y(I){try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{notifications:{preset:I}}),a()}catch(T){$("error","Update failed",T.message)}}async function V(I){try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{commandPermission:I}),a()}catch(T){$("error","Update failed",T.message)}}async function se(){try{await X.delete(`/gateways/${encodeURIComponent(t.id)}`),$("info",`${u1[t.type]} gateway removed`),a()}catch(I){$("error","Delete failed",I.message)}}const ne=((oe=t.notifications)==null?void 0:oe.preset)||"critical";return e.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[e.jsx(aa,{status:t.connected?"running":"crashed",size:"sm"}),e.jsx(C,{size:13,className:"text-text-2"}),e.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:u1[t.type]}),e.jsx("div",{className:"flex-1"}),t.connected?e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(As,{size:8})," Connected"]}):t.enabled?e.jsx(ge,{variant:"warning",className:"text-2xs",children:"Disconnected"}):e.jsx(ge,{variant:"default",className:"text-2xs",children:"Disabled"})]}),e.jsxs("div",{className:"flex-1 flex flex-col px-4 py-3 min-h-[140px]",children:[t.connected&&!s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 h-8 px-2.5 bg-success/8 border border-success/20 rounded-md text-2xs font-sans text-success mb-3",children:[e.jsx(Ve,{size:10})," Gateway active",t.botUsername&&e.jsxs("span",{className:"text-text-4 ml-1",children:["@",t.botUsername]}),t.botTag&&e.jsx("span",{className:"text-text-4 ml-1",children:t.botTag})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:t.type==="slack"?"Channel":"Chat ID"}),t.chatId?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 flex items-center h-7 px-2 bg-surface-0 border border-border-subtle rounded-md text-2xs font-mono text-text-2",children:t.type==="slack"&&j.length>0?`#${((R=j.find(I=>I.id===t.chatId))==null?void 0:R.name)||t.chatId}`:t.chatId}),e.jsx("button",{onClick:async()=>{try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{chatId:null}),a()}catch(I){$("error","Failed",I.message)}},className:"text-2xs text-text-4 hover:text-text-1 cursor-pointer font-sans",children:"Change"})]}):t.type==="slack"&&j.length>0?e.jsxs("select",{onChange:async I=>{if(I.target.value)try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{chatId:I.target.value}),a()}catch(T){$("error","Failed to set channel",T.message)}},className:"w-full h-7 px-2 text-2xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",defaultValue:"",children:[e.jsx("option",{value:"",disabled:!0,children:"Select a channel..."}),j.map(I=>e.jsxs("option",{value:I.id,children:["#",I.name]},I.id))]}):e.jsxs("div",{className:"text-2xs text-warning font-sans",children:[t.type==="slack"?"No channels found — invite the bot to a channel first.":"Send a message to the bot to auto-capture, or enter manually:",e.jsx("input",{placeholder:t.type==="slack"?"C0123456789":"Chat ID",className:"mt-1 w-full h-7 px-2 text-2xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",onKeyDown:async I=>{if(I.key==="Enter"&&I.target.value.trim())try{await X.patch(`/gateways/${encodeURIComponent(t.id)}`,{chatId:I.target.value.trim()}),a()}catch(T){$("error","Failed to set channel",T.message)}}})]})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:"Notifications"}),e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:uQe.map(I=>e.jsx("button",{onClick:()=>Y(I),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer capitalize",ne===I?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:I},I))})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:"Commands"}),e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:["full","read-only"].map(I=>e.jsx("button",{onClick:()=>V(I),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer capitalize",(t.commandPermission||"full")===I?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:I==="full"?"Full Access":"Read Only"},I))})]})]}),!t.connected&&!s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-text-3 font-sans mb-2",children:t.enabled?t.hasCredentials?"Tokens saved — click Connect.":"Configure bot token to connect.":"Gateway is disabled."}),!t.hasCredentials&&e.jsxs("button",{onClick:()=>M(!0),className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer mb-2",children:[e.jsx(Wt,{size:11}),"How to set up",e.jsx(Pt,{size:9})]})]}),e.jsx(hQe,{type:t.type,open:S,onOpenChange:M}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("div",{className:"space-y-2.5 pt-1",children:[e.jsxs("button",{onClick:()=>M(!0),className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer",children:[e.jsx(Wt,{size:11}),"Where do I get these?"]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:"Bot Token"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:r,onChange:I=>l(I.target.value),onKeyDown:I=>I.key==="Enter"&&!_&&P(),type:f?"text":"password",placeholder:dQe[t.type],className:"w-full h-9 px-3 pr-9 text-xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:()=>x(!f),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:f?e.jsx(Jn,{size:12}):e.jsx(ka,{size:12})})]})]}),_&&e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:"App Token (Socket Mode)"}),e.jsx("input",{value:u,onChange:I=>p(I.target.value),onKeyDown:I=>I.key==="Enter"&&P(),type:f?"text":"password",placeholder:"xapp-...",className:"w-full h-9 px-3 text-xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(he,{variant:"primary",size:"sm",onClick:P,disabled:!r.trim(),className:"flex-1 h-8 text-xs",children:"Save Token"}),e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>{c(!1),l(""),p("")},className:"h-8 text-xs px-3",children:"Cancel"})]})]}),!s&&e.jsxs("div",{className:"flex gap-2 mt-2",children:[!t.connected&&e.jsxs(he,{variant:"primary",size:"sm",onClick:()=>c(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[e.jsx(jn,{size:11}),t.enabled?"Set Token":"Configure"]}),t.connected&&e.jsxs(e.Fragment,{children:[e.jsxs(he,{variant:"secondary",size:"sm",onClick:L,disabled:g,className:"flex-1 h-7 text-2xs gap-1.5",children:[e.jsx(w1,{size:11}),g?"Sending...":"Test"]}),e.jsx(he,{variant:"secondary",size:"sm",onClick:()=>c(!0),className:"h-7 text-2xs px-2.5",children:e.jsx(jn,{size:11})})]}),e.jsx(he,{variant:"ghost",size:"sm",onClick:A,disabled:k,className:"h-7 text-2xs px-2.5",title:t.connected?"Disconnect":"Connect",children:t.connected?e.jsx(Lt,{size:11}):e.jsx(As,{size:11})}),e.jsx(iQe,{value:t.enabled,onChange:z}),e.jsx("button",{onClick:se,className:"text-text-4 hover:text-danger cursor-pointer p-1",title:"Remove gateway",children:e.jsx(wt,{size:11})})]})]})]})}function fQe({existingTypes:t,onAdd:a}){const[s,c]=O.useState(!1),r=["telegram","discord","slack"].filter(l=>!t.includes(l));return r.length===0?null:s?e.jsxs("div",{className:"flex flex-col rounded-lg border border-accent/30 bg-surface-1 overflow-hidden min-w-[220px]",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[e.jsx(an,{size:13,className:"text-accent"}),e.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:"Add Gateway"}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>c(!1),className:"text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(st,{size:12})})]}),e.jsx("div",{className:"p-3 space-y-2",children:r.map(l=>{const u=gB[l];return e.jsxs("button",{onClick:()=>{a(l),c(!1)},className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-0 hover:bg-accent/8 border border-border-subtle hover:border-accent/20 cursor-pointer transition-all group",children:[e.jsx(u,{size:14,className:"text-text-3 group-hover:text-accent"}),e.jsx("span",{className:"text-xs font-medium text-text-1 group-hover:text-accent font-sans",children:u1[l]})]},l)})})]}):e.jsxs("button",{onClick:()=>c(!0),className:"flex flex-col items-center justify-center rounded-lg border border-dashed border-border-subtle bg-surface-1/50 hover:bg-surface-1 hover:border-accent/30 min-h-[140px] min-w-[220px] cursor-pointer transition-all group",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-accent/8 group-hover:bg-accent/15 flex items-center justify-center mb-2 transition-colors",children:e.jsx(rt,{size:14,className:"text-accent"})}),e.jsx("span",{className:"text-2xs font-semibold text-text-3 group-hover:text-text-1 font-sans transition-colors",children:"Add Gateway"})]})}function xQe(){const t=q(y=>y.networkUnlocked),a=q(y=>y.activateBeta),s=q(y=>y.deactivateBeta),[c,r]=O.useState(""),[l,u]=O.useState(!1),[p,f]=O.useState("");O.useEffect(()=>{if(!p)return;const y=setTimeout(()=>f(""),3e3);return()=>clearTimeout(y)},[p]);async function x(){const y=c.trim();if(!(!y||l)){u(!0),f("");try{await a(y),r("")}catch(k){f(k.message||"Invalid code")}finally{u(!1)}}}async function g(){try{await s()}catch{}}return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Early Access"}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"})]}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5 max-w-md",children:[t?e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-success/10 flex items-center justify-center flex-shrink-0",children:e.jsx(Ve,{size:12,className:"text-success"})}),e.jsx("div",{className:"flex-1 text-xs font-sans text-text-1",children:"Early access enabled"}),e.jsx("button",{onClick:g,className:"text-2xs text-text-4 hover:text-danger cursor-pointer font-sans",children:"Deactivate"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Vd,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("input",{value:c,onChange:y=>r(y.target.value),onKeyDown:y=>y.key==="Enter"&&x(),type:"text",placeholder:"Enter invite code",className:"flex-1 h-8 px-2.5 text-xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsx(he,{variant:"primary",size:"sm",onClick:x,disabled:!c.trim()||l,className:"h-8 text-xs px-3",children:l?"...":"Submit"})]}),p&&!t&&e.jsx("div",{className:"mt-2 text-2xs text-danger font-sans",children:p})]})]})}function mQe(){var _;const[t,a]=O.useState([]),[s,c]=O.useState(null),[r,l]=O.useState(null),[u,p]=O.useState([]),[f,x]=O.useState(!0),[g,y]=O.useState(!1),k=q(P=>P.addToast);function b(){X.get("/providers").then(P=>a(Array.isArray(P)?P:[])).catch(()=>{})}function j(){X.get("/gateways").then(P=>p(Array.isArray(P)?P:[])).catch(()=>{})}O.useEffect(()=>{Promise.all([X.get("/providers"),X.get("/config"),X.get("/status"),X.get("/gateways")]).then(([P,L,A,z])=>{a(Array.isArray(P)?P:[]),c(L),l(A),p(Array.isArray(z)?z:[]),x(!1)}).catch(()=>x(!1))},[]);async function w(P){try{await X.post("/gateways",{type:P}),k("success",`${u1[P]} gateway added`),j()}catch(L){k("error","Failed to add gateway",L.message)}}async function S(P,L){try{const A=await X.patch("/config",{[P]:L});c(A)}catch(A){k("error","Update failed",A.message)}}if(f)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"h-12 bg-surface-1 border-b border-border"}),e.jsxs("div",{className:"flex-1 p-4 space-y-4",children:[e.jsx("div",{className:"grid grid-cols-4 gap-3",children:[...Array(4)].map((P,L)=>e.jsx(en,{className:"h-40 rounded-lg"},L))}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[...Array(6)].map((P,L)=>e.jsx(en,{className:"h-28 rounded-lg"},L))})]})]});const M=t.filter(P=>P.id!=="groove-network"),$=M.filter(P=>P.authType==="local"||P.authType==="subscription"?P.installed:P.installed&&P.hasKey).length,C=(s==null?void 0:s.rotationThreshold)||0;return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2.5 bg-surface-1 border-b border-border flex-shrink-0",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 font-sans",children:"Settings"}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center gap-4 text-2xs text-text-3 font-sans",children:[(r==null?void 0:r.version)&&e.jsxs("span",{children:["v",r.version]}),(r==null?void 0:r.port)&&e.jsxs("span",{children:[":",r.port]}),(r==null?void 0:r.uptime)>0&&e.jsxs("span",{children:["Up ",su(r.uptime)]})]}),e.jsx(aa,{status:"running",size:"sm"})]}),e.jsx(It,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Providers"}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:[$,"/",M.length," connected"]})]}),e.jsx("div",{className:"grid grid-cols-4 gap-3",children:M.map(P=>e.jsx(lQe,{provider:P,onKeyChange:b},P.id))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Gateways"}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:[u.filter(P=>P.connected).length,"/",u.length," connected"]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[u.map(P=>e.jsx(pQe,{gateway:P,onRefresh:j},P.id)),e.jsx(fQe,{existingTypes:u.map(P=>P.type),onAdd:w})]})]}),s&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Configuration"}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Auto-saves"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(Oc,{icon:tn,label:"Default Provider",description:"Provider used when spawning new agents.",children:e.jsx("select",{value:s.defaultProvider||"claude-code",onChange:P=>S("defaultProvider",P.target.value),className:"w-full h-8 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",children:M.filter(P=>P.installed&&(P.authType==="local"||P.authType==="subscription"||P.hasKey)).map(P=>e.jsx("option",{value:P.id,children:P.name},P.id))})}),e.jsx(Oc,{icon:tn,label:"Default Model",description:"Model used for new agents. Auto routes by role.",children:e.jsxs("select",{value:s.defaultModel||"",onChange:P=>S("defaultModel",P.target.value||null),className:"w-full h-8 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",children:[e.jsx("option",{value:"",children:"Auto (route by role)"}),(((_=t.find(P=>P.id===(s.defaultProvider||"claude-code")))==null?void 0:_.models)||[]).map(P=>e.jsx("option",{value:P.id,children:P.name},P.id))]})}),e.jsx(Oc,{icon:ta,label:"Working Directory",description:"Default root directory for new agents.",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("code",{className:"flex-1 h-8 px-2 flex items-center bg-surface-0 border border-border-subtle rounded-md text-2xs font-mono text-text-2 truncate min-w-0",children:s.defaultWorkingDir||"Project root"}),e.jsx(he,{variant:"secondary",size:"sm",onClick:async()=>{var P,L;if((L=(P=window.groove)==null?void 0:P.folders)!=null&&L.select){const A=await window.groove.folders.select({title:"Select Working Directory",defaultPath:(s==null?void 0:s.defaultWorkingDir)||void 0});A&&S("defaultWorkingDir",A)}else y(!0)},className:"h-8 px-2 flex-shrink-0",children:e.jsx(x1,{size:12})})]})}),e.jsx(Oc,{icon:qd,label:"Rotation Threshold",description:"Context usage that triggers auto-rotation.",children:e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:["auto","50%","65%","75%","85%"].map(P=>{const L=P==="auto"?0:parseInt(P,10)/100,A=C===L;return e.jsx("button",{onClick:()=>S("rotationThreshold",L),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",A?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:P==="auto"?"Auto":P},P)})})}),e.jsx(Oc,{icon:O1,label:"QC Threshold",description:"Running agents count that triggers auto-QC.",children:e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[2,3,4,6,8].map(P=>{const L=(s.qcThreshold||2)===P;return e.jsx("button",{onClick:()=>S("qcThreshold",P),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",L?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:P},P)})})}),e.jsx(Oc,{icon:sn,label:"Max Agents",description:"Concurrent agent limit. 0 = unlimited.",children:e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[0,4,8,12,20].map(P=>{const L=(s.maxAgents||0)===P;return e.jsx("button",{onClick:()=>S("maxAgents",P),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",L?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:P===0?"∞":P},P)})})}),e.jsx(Oc,{icon:Es,label:"Journalist Interval",description:"Seconds between synthesis cycles.",children:e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[60,120,300,600].map(P=>{const L=(s.journalistInterval||120)===P,A=P<60?`${P}s`:`${P/60}m`;return e.jsx("button",{onClick:()=>S("journalistInterval",P),className:K("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",L?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:A},P)})})})]})]}),e.jsx(xQe,{})]})}),e.jsx(ou,{open:g,onOpenChange:y,currentPath:(s==null?void 0:s.defaultWorkingDir)||"/",onSelect:P=>S("defaultWorkingDir",P)})]})}function SQ(t){return t?t<1024*1024?`${(t/1024).toFixed(0)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`:"—"}function yQe(t){return t?t<1024*1024?`${(t/1024).toFixed(0)} KB/s`:`${(t/(1024*1024)).toFixed(1)} MB/s`:""}function gQe({hardware:t}){var a;return t?e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2.5 bg-surface-1 border border-border-subtle rounded-lg text-xs font-sans text-text-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx($2,{size:14,className:"text-text-3"}),e.jsxs("span",{children:[t.totalRamGb," GB RAM"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(tn,{size:14,className:"text-text-3"}),e.jsxs("span",{children:[t.cores," cores"]})]}),t.gpu&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Xo,{size:14,className:"text-text-3"}),e.jsxs("span",{children:[t.gpu.name,t.gpu.vram?` (${t.gpu.vram} GB)`:""]})]}),((a=t.recommended)==null?void 0:a.code)&&e.jsxs("div",{className:"ml-auto text-accent",children:["Recommended: ",t.recommended.code]})]}):null}function OQe({download:t}){const a=Math.round((t.percent||0)*100);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans text-text-3",children:[e.jsx("span",{children:t.filename}),e.jsxs("span",{children:[a,"% ",yQe(t.speed)]})]}),e.jsx("div",{className:"h-1.5 bg-surface-3 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent rounded-full transition-all",style:{width:`${a}%`}})}),e.jsxs("div",{className:"text-2xs text-text-4",children:[SQ(t.downloaded)," / ",SQ(t.totalBytes)]})]})}function kQe({model:t,onDelete:a}){const[s,c]=O.useState(!1),r={light:"text-green-400",medium:"text-blue-400",heavy:"text-orange-400"};return e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-surface-1 border border-border-subtle rounded-lg",children:[e.jsx(wn,{size:18,className:"text-accent flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate",children:t.id}),t.quantization&&e.jsx(ge,{variant:"subtle",className:"text-2xs",children:t.quantization}),t.parameters&&e.jsx(ge,{variant:"subtle",className:"text-2xs",children:t.parameters}),e.jsx("span",{className:K("text-2xs font-medium capitalize",r[t.tier]||"text-text-3"),children:t.tier})]}),e.jsxs("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:[SQ(t.sizeBytes)," · ctx ",(t.contextWindow||0).toLocaleString()," · ",t.category,t.repoId&&e.jsxs("span",{className:"text-text-4",children:[" · ",t.repoId]})]})]}),e.jsx("button",{onClick:async()=>{c(!0),await a(t.id),c(!1)},disabled:s,className:"p-1.5 rounded-md text-text-4 hover:text-red-400 hover:bg-red-400/10 transition-colors",children:s?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(wt,{size:14})})]})}function vQe({result:t,onExpand:a,expanded:s}){var c;return e.jsxs("button",{onClick:()=>a(s?null:t.id),className:"w-full text-left px-4 py-3 bg-surface-1 border border-border-subtle rounded-lg hover:border-accent/30 transition-colors cursor-pointer",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate flex-1",children:t.name}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:t.author}),s?e.jsx(zt,{size:14,className:"text-text-3"}):e.jsx(Xt,{size:14,className:"text-text-3"})]}),e.jsxs("div",{className:"text-2xs text-text-3 font-sans mt-0.5 flex gap-3",children:[e.jsxs("span",{children:[(c=t.downloads)==null?void 0:c.toLocaleString()," downloads"]}),e.jsxs("span",{children:[t.likes," likes"]})]})]})}function bQe({repoId:t,onDownload:a,systemRamGb:s}){const[c,r]=O.useState(null),[l,u]=O.useState(!0),[p,f]=O.useState(null),x=va();O.useEffect(()=>{u(!0),X.get(`/models/${t}/files`).then(y=>r(y.files||[])).catch(()=>x.error("Failed to load model files")).finally(()=>u(!1))},[t]);async function g(y){f(y.filename);try{await X.post("/models/download",{repoId:t,filename:y.filename}),x.success(`Downloading ${y.filename}`),a==null||a(y.filename)}catch(k){x.error(k.message)}f(null)}return l?e.jsx("div",{className:"py-3 px-4 text-2xs text-text-4 font-sans",children:"Loading quantization variants..."}):c!=null&&c.length?e.jsx("div",{className:"pl-6 pr-4 pb-2 space-y-1.5",children:c.map(y=>{const k=!y.estimatedRamGb||!s||y.estimatedRamGb<=s,b=y.estimatedRamGb&&s&&y.estimatedRamGb>s*.8&&k;return e.jsxs("div",{className:K("flex items-center gap-2 py-1.5 px-3 rounded-md text-xs font-sans",k?"bg-surface-2":"bg-red-500/5 border border-red-500/15"),children:[e.jsx("span",{className:"font-mono text-text-1 truncate flex-1",children:y.filename}),y.quantization&&e.jsx(ge,{variant:"subtle",className:"text-2xs",children:y.quantization}),e.jsx("span",{className:"text-text-2 text-2xs w-16 text-right",children:SQ(y.size)}),y.estimatedRamGb&&e.jsxs("span",{className:K("text-2xs w-20 text-right font-medium",k?b?"text-yellow-400":"text-green-400":"text-red-400"),children:["~",y.estimatedRamGb," GB RAM"]}),!k&&e.jsx("span",{className:"text-2xs text-red-400 font-medium",children:"too large"}),e.jsx("button",{onClick:()=>g(y),disabled:p===y.filename||!k,className:K("p-1 rounded transition-colors",k?"text-accent hover:bg-accent/10":"text-text-4 cursor-not-allowed","disabled:opacity-40"),children:p===y.filename?e.jsx(ze,{size:13,className:"animate-spin"}):e.jsx(Oa,{size:13})})]},y.filename)})}):e.jsx("div",{className:"py-3 px-4 text-2xs text-text-4 font-sans",children:"No GGUF files found in this repo."})}function wQe({model:t,systemRamGb:a,onPull:s,pulling:c,isInstalled:r}){const l={light:"text-green-400",medium:"text-blue-400",heavy:"text-orange-400"},u={code:"{}",general:"AI"},p=a?Math.round((1-t.ramGb/a)*100):null;return e.jsxs("div",{className:K("flex items-center gap-3 px-4 py-3 border rounded-lg transition-colors",r?"bg-success/5 border-success/20":"bg-surface-1 border-border-subtle hover:border-accent/20"),children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-surface-3 flex items-center justify-center text-xs font-mono text-text-2 flex-shrink-0",children:u[t.category]||"AI"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate",children:t.name}),e.jsx("span",{className:K("text-2xs font-semibold capitalize",l[t.tier]),children:t.tier}),r&&e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(Ve,{size:8})," Installed"]})]}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:t.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-1 text-2xs font-sans",children:[e.jsxs("span",{className:"text-text-2",children:[t.sizeGb," GB download"]}),e.jsxs("span",{className:"text-green-400 font-medium",children:[t.ramGb," GB RAM"]}),p!==null&&e.jsxs("span",{className:"text-text-4",children:[p,"% headroom"]})]})]}),r?e.jsx("span",{className:"text-xs text-success font-sans font-medium px-3 py-1.5",children:"Ready"}):e.jsxs("button",{onClick:()=>s(t.id),disabled:c===t.id,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-sans font-medium bg-accent/10 text-accent hover:bg-accent/20 transition-colors cursor-pointer disabled:opacity-40",children:[c===t.id?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(Oa,{size:12}),"Pull"]})]})}function MQe(){const[t,a]=O.useState("recommended"),[s,c]=O.useState(""),[r,l]=O.useState([]),[u,p]=O.useState(!1),[f,x]=O.useState([]),[g,y]=O.useState([]),[k,b]=O.useState([]),[j,w]=O.useState(null),[S,M]=O.useState(null),[$,C]=O.useState(null),[_,P]=O.useState([]),L=va(),A=O.useCallback(()=>{X.get("/models/installed").then(ne=>{x(ne.models||[])}).catch(()=>{})},[]),z=O.useCallback(()=>{X.get("/providers/ollama/models").then(ne=>{P((ne.installed||[]).map(oe=>oe.id))}).catch(()=>{})},[]);O.useEffect(()=>{X.get("/providers/ollama/hardware").then(w).catch(()=>{}),X.get("/models/recommended").then(ne=>{y(ne.models||[]),!j&&ne.hardware&&w(ne.hardware)}).catch(()=>{}),A(),z()},[A,z]);async function Y(ne){C(ne);try{await X.post("/providers/ollama/pull",{model:ne}),L.success(`${ne} ready to use`),A(),z(),P(oe=>[...oe,ne])}catch(oe){L.error(`Pull failed: ${oe.message}`)}C(null)}O.useEffect(()=>{const ne=q.subscribe((R,I)=>{}),oe=setInterval(()=>{X.get("/models/downloads").then(b).catch(()=>{})},2e3);return()=>{ne(),clearInterval(oe)}},[]),O.useEffect(()=>{function ne(R){try{const I=JSON.parse(R.data);I.type==="model:download:progress"&&b(T=>{const Z=T.findIndex(J=>J.filename===I.data.filename);if(Z>=0){const J=[...T];return J[Z]=I.data,J}return[...T,I.data]}),I.type==="model:download:complete"&&(b(T=>T.filter(Z=>Z.filename!==I.data.filename)),A(),L.success(`${I.data.filename} downloaded`)),I.type==="model:download:error"&&(b(T=>T.filter(Z=>Z.filename!==I.data.filename)),L.error(`Download failed: ${I.data.error}`))}catch{}}const oe=q.getState()._ws;return oe&&oe.addEventListener("message",ne),()=>{oe&&oe.removeEventListener("message",ne)}},[A,L]);async function V(){if(s.trim()){p(!0),a("search");try{const ne=await X.get(`/models/search?q=${encodeURIComponent(s.trim())}`);l(ne)}catch(ne){L.error(ne.message)}p(!1)}}async function se(ne){try{await X.delete(`/models/${ne}`),x(oe=>oe.filter(R=>R.id!==ne)),L.success("Model deleted")}catch(oe){L.error(oe.message)}}return e.jsxs("div",{className:"h-full flex flex-col bg-surface-0",children:[e.jsxs("div",{className:"flex-shrink-0 px-5 pt-4 pb-3 border-b border-border space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-base font-bold font-sans text-text-0",children:"Local Models"}),e.jsxs(ge,{variant:"subtle",className:"text-2xs",children:[f.length," installed"]})]}),e.jsx(gQe,{hardware:j}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Zt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:s,onChange:ne=>c(ne.target.value),onKeyDown:ne=>ne.key==="Enter"&&V(),placeholder:"Search HuggingFace for GGUF models...",className:"w-full h-8 pl-9 pr-3 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsx(he,{onClick:V,disabled:u,size:"sm",variant:"accent",children:u?e.jsx(ze,{size:14,className:"animate-spin"}):"Search"})]}),e.jsx("div",{className:"flex gap-1",children:[{id:"recommended",label:`Recommended (${g.length})`},{id:"installed",label:`Installed (${f.length})`},{id:"search",label:`Search (${r.length})`}].map(ne=>e.jsx("button",{onClick:()=>a(ne.id),className:K("px-3 py-1 rounded-md text-xs font-sans font-medium transition-colors cursor-pointer",t===ne.id?"bg-accent/12 text-accent":"text-text-3 hover:text-text-1 hover:bg-surface-3"),children:ne.label},ne.id))})]}),k.length>0&&e.jsxs("div",{className:"px-5 py-3 border-b border-border space-y-2",children:[e.jsx("div",{className:"text-xs font-sans font-semibold text-text-2",children:"Downloading"}),k.map(ne=>e.jsx(OQe,{download:ne},ne.filename))]}),e.jsx(It,{className:"flex-1",children:e.jsxs("div",{className:"px-5 py-4 space-y-2",children:[t==="recommended"&&e.jsx(e.Fragment,{children:g.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(tn,{size:40,className:"mx-auto text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"Detecting hardware..."}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Make sure Ollama is installed so we can check your system."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs text-text-3 font-sans mb-2",children:["Top models for your system (",(j==null?void 0:j.totalRamGb)||"?"," GB RAM). Click Pull to download via Ollama."]}),g.map(ne=>{const oe=ne.id.split(":")[0],R=_.some(I=>I===ne.id||I.startsWith(oe+":")||I===oe);return e.jsx(wQe,{model:ne,systemRamGb:j==null?void 0:j.totalRamGb,onPull:Y,pulling:$,isInstalled:R},ne.id)})]})}),t==="installed"&&e.jsx(e.Fragment,{children:f.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(wn,{size:40,className:"mx-auto text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"No local models yet"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Search HuggingFace to download GGUF models, or pull models via Ollama."})]}):f.map(ne=>e.jsx(kQe,{model:ne,onDelete:se},ne.id))}),t==="search"&&e.jsx(e.Fragment,{children:u?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ze,{size:24,className:"mx-auto text-accent animate-spin mb-3"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Searching HuggingFace..."})]}):r.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Zt,{size:40,className:"mx-auto text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"Search for GGUF models"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:'Try "qwen coder", "deepseek", "codestral", "llama"'})]}):r.map(ne=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(vQe,{result:ne,expanded:S===ne.id,onExpand:M}),S===ne.id&&e.jsx(bQe,{repoId:ne.id,onDownload:()=>A(),systemRamGb:j==null?void 0:j.totalRamGb})]},ne.id))})]})})]})}function jQe(t){switch(t){case"established":return e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(aa,{status:"running",size:"sm"})," Connected"]});case"connecting":return e.jsx(ge,{variant:"warning",className:"text-2xs",dot:"pulse",children:"Connecting"});case"error":return e.jsx(ge,{variant:"danger",className:"text-2xs",children:"Error"});default:return e.jsx(ge,{variant:"default",className:"text-2xs",children:"Unknown"})}}function SQe({onOpenWizard:t}){const a=q(f=>f.federation.connections),s=q(f=>f.federation.peers),c=q(f=>f.sendPouch),[r,l]=O.useState(null),u=s.length>0?s:a;async function p(f){l(f);try{await c(f,{type:"ping"})}catch{}l(null)}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Tt,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Connected Peers"}),u.length>0&&e.jsx(ge,{variant:"success",className:"text-2xs",children:u.length})]}),e.jsxs(he,{size:"sm",variant:"primary",onClick:t,className:"h-7 text-2xs gap-1.5",children:[e.jsx(rt,{size:11}),"Pair New Peer"]})]}),u.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-8 text-center",children:[e.jsx(Zo,{size:20,className:"text-text-4 mx-auto mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mb-1",children:"No peers connected"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mb-3",children:"Pair with a remote Groove daemon to share agents and coordinate work."}),e.jsxs(he,{size:"sm",variant:"outline",onClick:t,className:"h-7 text-2xs gap-1.5",children:[e.jsx(rt,{size:11}),"Pair Your First Peer"]})]}):e.jsx("div",{className:"grid gap-2",children:u.map(f=>{const x=f.peerId||f.ip||f.id,g=f.name||f.peerId||"Unknown Peer",y=f.state||f.status||"unknown",k=f.ip||f.address||"",b=f.latency;return e.jsxs("div",{className:"rounded-md border border-border-subtle bg-surface-1 p-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-accent/10 flex-shrink-0 mt-0.5",children:e.jsx(Tt,{size:14,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:g}),jQe(y)]}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3",children:[k&&e.jsxs("span",{className:"font-mono truncate",children:[k,f.port?`:${f.port}`:""]}),b!=null&&e.jsxs("span",{className:"flex items-center gap-1 font-sans",children:[e.jsx(j1,{size:9,className:K(b<100?"text-success":b<300?"text-warning":"text-danger")}),b,"ms"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-3 pt-2.5 border-t border-border-subtle",children:[e.jsxs(he,{size:"sm",variant:"ghost",className:"h-6 text-2xs gap-1 text-text-2",children:[e.jsx(ka,{size:10}),"Details"]}),e.jsxs(he,{size:"sm",variant:"ghost",className:"h-6 text-2xs gap-1 text-text-2",disabled:r===x,onClick:()=>p(x),children:[e.jsx(Zs,{size:10}),"Send Pouch"]}),e.jsxs(he,{size:"sm",variant:"ghost",className:"h-6 text-2xs gap-1 text-danger/70 hover:text-danger ml-auto",children:[e.jsx(M1,{size:10}),"Disconnect"]})]})]},x)})})]})}const NQe=["All","Sent","Received"];function _Qe(){const t=q(l=>l.federation.pouchLog),[a,s]=O.useState("All"),r=[...a==="All"?t:t.filter(l=>l.direction===a.toLowerCase())].reverse().slice(0,200);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Nn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Activity"}),t.length>0&&e.jsx(ge,{variant:"default",className:"text-2xs",children:t.length})]}),e.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:NQe.map(l=>e.jsx("button",{onClick:()=>s(l),className:K("px-2.5 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",a===l?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:l},l))})]}),r.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-6 text-center",children:[e.jsx(Nn,{size:18,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:a==="All"?"No diplomatic pouches exchanged yet.":`No ${a.toLowerCase()} pouches.`})]}):e.jsx(It,{className:"max-h-80",children:e.jsxs("div",{className:"relative pl-5",children:[e.jsx("div",{className:"absolute left-[7px] top-2 bottom-2 w-px bg-border-subtle"}),r.map((l,u)=>{const p=l.direction==="sent";return e.jsxs("div",{className:"relative flex items-start gap-3 pb-3 last:pb-0",children:[e.jsx("div",{className:K("absolute left-[-13px] top-1.5 w-2.5 h-2.5 rounded-full border-2 border-surface-2 z-10",p?"bg-accent":"bg-success")}),e.jsxs("div",{className:"flex items-center gap-2 flex-1 rounded-md bg-surface-1 px-3 py-2 min-w-0",children:[p?e.jsx(d2,{size:11,className:"text-accent flex-shrink-0"}):e.jsx(l2,{size:11,className:"text-success flex-shrink-0"}),e.jsx("span",{className:"text-2xs text-text-1 font-sans truncate flex-1",children:l.contractType||l.type||"message"}),e.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-24",children:l.peerId||""}),e.jsx("span",{className:"text-2xs text-text-3 font-sans flex-shrink-0",children:gt(l.timestamp||l.ts)})]})]},l.id||u)})]})})]})}const $Qe=[{label:"Connect",icon:Zo},{label:"Verify",icon:Tt},{label:"Paired",icon:Ve}];function CQe({current:t}){return e.jsx("div",{className:"flex items-center justify-center gap-2 mb-6",children:$Qe.map((a,s)=>{const c=s<t,r=s===t,l=a.icon;return e.jsxs("div",{className:"flex items-center gap-2",children:[s>0&&e.jsx("div",{className:K("w-8 h-px",c?"bg-accent":"bg-border-subtle")}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:K("w-6 h-6 rounded-full flex items-center justify-center transition-colors",c?"bg-accent text-white":r?"bg-accent/15 text-accent border border-accent/30":"bg-surface-3 text-text-4"),children:c?e.jsx(Ve,{size:12}):e.jsx(l,{size:12})}),e.jsx("span",{className:K("text-2xs font-semibold font-sans",r?"text-text-0":c?"text-accent":"text-text-4"),children:a.label})]})]},a.label)})})}function QQe({open:t,onOpenChange:a}){const s=q(V=>V.addToWhitelist),c=q(V=>V.fetchFederationStatus),[r,l]=O.useState(0),[u,p]=O.useState(""),[f,x]=O.useState("31415"),[g,y]=O.useState(""),[k,b]=O.useState(!1),[j,w]=O.useState(null),[S,M]=O.useState(!1),[$,C]=O.useState(null),[_,P]=O.useState(null);function L(){l(0),p(""),x("31415"),y(""),b(!1),w(null),M(!1),C(null),P(null)}function A(V){V||L(),a(V)}async function z(){b(!0),w(null),C(null);try{const V=`${u.trim()}:${f||"31415"}`,se=await fetch(`http://localhost:31415/api/federation/test?target=${encodeURIComponent(V)}`);if(se.ok){const ne=await se.json();w("reachable"),P(ne)}else w("unreachable")}catch{w("unreachable")}b(!1)}async function Y(){M(!0),C(null);try{await s(u.trim(),parseInt(f,10)||31415,g.trim()||void 0),await c(),l(2)}catch(V){C(V.message||"Failed to pair with peer")}M(!1)}return e.jsx(qa,{open:t,onOpenChange:A,children:e.jsx(Ia,{title:"Pair New Peer",description:"Connect to a remote Groove daemon",children:e.jsxs("div",{className:"px-5 py-5",children:[e.jsx(CQe,{current:r}),r===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(ns,{label:"Friendly Name",placeholder:"e.g. Production Server",value:g,onChange:V=>y(V.target.value)}),e.jsxs("div",{className:"grid grid-cols-[1fr,100px] gap-2",children:[e.jsx(ns,{label:"IP / Hostname",placeholder:"192.168.1.100",value:u,onChange:V=>p(V.target.value),mono:!0}),e.jsx(ns,{label:"Port",placeholder:"31415",value:f,onChange:V=>x(V.target.value),mono:!0})]}),j==="reachable"&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-success/10 border border-success/20 px-3 py-2",children:[e.jsx(j1,{size:13,className:"text-success"}),e.jsx("span",{className:"text-2xs text-success font-sans font-medium",children:"Peer is reachable"})]}),j==="unreachable"&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-danger/10 border border-danger/20 px-3 py-2",children:[e.jsx(vt,{size:13,className:"text-danger"}),e.jsx("span",{className:"text-2xs text-danger font-sans font-medium",children:"Could not reach peer — check IP and port"})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxs(he,{size:"sm",variant:"ghost",disabled:!u.trim()||k,onClick:z,className:"h-8 text-xs gap-1.5",children:[k?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(j1,{size:12}),"Test Reachability"]}),e.jsxs(he,{size:"sm",variant:"primary",disabled:!u.trim(),onClick:()=>l(1),className:"h-8 text-xs gap-1.5 ml-auto",children:["Continue",e.jsx(h1,{size:12})]})]})]}),r===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-md border border-border-subtle bg-surface-0 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-md bg-accent/10",children:e.jsx(Tt,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-text-0 font-sans",children:g||"Remote Peer"}),e.jsxs("p",{className:"text-2xs text-text-3 font-mono",children:[u,":",f||"31415"]})]})]}),_&&e.jsxs("div",{className:"space-y-1.5 pt-2 border-t border-border-subtle",children:[_.version&&e.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:"Version"}),e.jsx("span",{className:"text-text-1 font-mono",children:_.version})]}),_.peerId&&e.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:"Peer ID"}),e.jsx("span",{className:"text-text-1 font-mono truncate max-w-40",children:_.peerId})]}),_.agents!=null&&e.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:"Active Agents"}),e.jsx("span",{className:"text-text-1",children:_.agents})]})]})]}),$&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-danger/10 border border-danger/20 px-3 py-2",children:[e.jsx(vt,{size:13,className:"text-danger"}),e.jsx("span",{className:"text-2xs text-danger font-sans",children:$})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx(he,{size:"sm",variant:"ghost",onClick:()=>l(0),className:"h-8 text-xs",children:"Back"}),e.jsxs(he,{size:"sm",variant:"primary",disabled:S,onClick:Y,className:"h-8 text-xs gap-1.5 ml-auto",children:[S?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(Zo,{size:12}),"Confirm Pairing"]})]})]}),r===2&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-success/15 mx-auto",children:e.jsx(Ve,{size:20,className:"text-success"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans mb-1",children:"Peer Paired Successfully"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:[g||u," has been added to your federation whitelist."]})]}),e.jsx("div",{className:"rounded-md border border-border-subtle bg-surface-0 p-3 text-left",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-accent/10",children:e.jsx(Tt,{size:14,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans block truncate",children:g||"Remote Peer"}),e.jsxs("span",{className:"text-2xs text-text-3 font-mono",children:[u,":",f||"31415"]})]}),e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(aa,{status:"running",size:"sm"}),"Whitelisted"]})]})}),e.jsx(he,{size:"sm",variant:"primary",onClick:()=>A(!1),className:"h-8 text-xs",children:"Done"})]})]})})})}function LQe(t){switch(t){case"mutual":return e.jsxs(ge,{variant:"success",className:"text-2xs gap-1",children:[e.jsx(aa,{status:"running",size:"sm"})," Mutual"]});case"connected":return e.jsx(ge,{variant:"info",className:"text-2xs",children:"Connected"});default:return e.jsx(ge,{variant:"default",className:"text-2xs",children:"Waiting"})}}function zQe(){const t=q(M=>M.federation.whitelist),a=q(M=>M.addToWhitelist),s=q(M=>M.removeFromWhitelist),[c,r]=O.useState(!1),[l,u]=O.useState(""),[p,f]=O.useState("31415"),[x,g]=O.useState(""),[y,k]=O.useState(!1),[b,j]=O.useState("");async function w(M){if(M.preventDefault(),!!l.trim()){k(!0);try{await a(l.trim(),parseInt(p,10)||31415,x.trim()||void 0),u(""),f("31415"),g(""),r(!1)}catch{}k(!1)}}const S=O.useMemo(()=>{if(!b.trim())return t;const M=b.toLowerCase();return t.filter($=>{const C=typeof $=="string"?$:$.ip,_=typeof $=="object"?$.name:"";return(C==null?void 0:C.toLowerCase().includes(M))||(_==null?void 0:_.toLowerCase().includes(M))})},[t,b]);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(nn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Whitelist"}),t.length>0&&e.jsx(ge,{variant:"default",className:"text-2xs",children:t.length})]}),e.jsx(he,{size:"sm",variant:c?"ghost":"primary",onClick:()=>r(!c),className:"h-7 text-2xs gap-1.5",children:c?e.jsxs(e.Fragment,{children:[e.jsx(x2,{size:11})," Hide"]}):e.jsxs(e.Fragment,{children:[e.jsx(rt,{size:11})," Add Server"]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c&&e.jsxs("form",{onSubmit:w,className:"rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(rt,{size:12,className:"text-accent"})}),e.jsx("span",{className:"text-[13px] font-medium text-text-0 font-sans",children:"New Server"})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1 block",children:"Name"}),e.jsx(ns,{placeholder:"Server name",value:x,onChange:M=>g(M.target.value),className:"h-7 text-xs"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1 block",children:"IP Address"}),e.jsx(ns,{placeholder:"100.64.0.2",value:l,onChange:M=>u(M.target.value),mono:!0,className:"h-7 text-xs"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1 block",children:"Port"}),e.jsx(ns,{placeholder:"31415",value:p,onChange:M=>f(M.target.value),mono:!0,className:"h-7 text-xs w-28"})]}),e.jsx("div",{className:"pt-1",children:e.jsxs(he,{type:"submit",variant:"primary",size:"sm",disabled:y||!l.trim(),className:"h-7 text-2xs gap-1",children:[y?e.jsx(ze,{size:11,className:"animate-spin"}):e.jsx(rt,{size:11}),"Add to Whitelist"]})})]})]}),e.jsxs("div",{className:K("rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5",!c&&"col-span-2"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(At,{size:12,className:"text-accent"})}),e.jsx("span",{className:"text-[13px] font-medium text-text-0 font-sans",children:"Servers"}),t.length>=5&&e.jsxs("div",{className:"relative ml-auto",children:[e.jsx(Zt,{size:10,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"text",placeholder:"Filter…",value:b,onChange:M=>j(M.target.value),className:"h-6 pl-6 pr-2 w-32 text-2xs font-sans bg-surface-0 border border-border-subtle rounded-md text-text-0 placeholder:text-text-4 focus:outline-none focus:border-accent"})]})]}),S.length===0&&t.length===0?e.jsxs("div",{className:"px-2 py-4 text-center",children:[e.jsx(At,{size:16,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"No peers whitelisted yet."})]}):S.length===0?e.jsx("div",{className:"text-2xs text-text-4 font-sans py-3 text-center",children:"No servers match your filter."}):e.jsx("div",{className:"space-y-1.5",children:S.map(M=>{const $=typeof M=="string"?M:M.ip,C=typeof M=="object"?M.name:null,_=typeof M=="object"?M.status:"waiting",P=typeof M=="object"?M.port:null;return e.jsxs("div",{className:"flex items-center gap-2.5 px-2.5 py-2 rounded-md bg-surface-0 border border-border-subtle",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[C&&e.jsx("span",{className:"text-xs font-sans font-medium text-text-0 block truncate",children:C}),e.jsxs("span",{className:K("font-mono truncate block",C?"text-2xs text-text-3":"text-xs text-text-1"),children:[$,P?`:${P}`:""]})]}),LQe(_),e.jsx("button",{onClick:()=>s($),className:"p-1 rounded text-text-4 hover:text-danger hover:bg-danger/10 cursor-pointer transition-colors flex-shrink-0",title:"Remove",children:e.jsx(wt,{size:11})})]},$)})})]})]})]})}function TQe(){const t=q(a=>a.federation.ambassadors);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(sn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Ambassadors"}),t.length>0&&e.jsx(ge,{variant:"info",className:"text-2xs",children:t.length})]}),t.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-6 text-center",children:[e.jsx(sn,{size:18,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"No active ambassadors. Ambassadors appear when agents are shared across federated peers."})]}):e.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(a=>e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(aa,{status:a.status==="active"?"running":"stopped",size:"sm"}),e.jsx("span",{className:"text-xs font-sans font-medium text-text-0 truncate flex-1",children:a.name||a.agentId||a.id}),a.role&&e.jsx(ge,{variant:"purple",className:"text-2xs",children:a.role})]}),e.jsxs("div",{className:"flex items-center justify-between text-2xs",children:[a.peerId?e.jsx("span",{className:"text-text-3 font-mono truncate max-w-28",children:a.peerId}):e.jsx("span",{className:"text-text-4 font-sans",children:"Local"}),e.jsx(ge,{variant:a.status==="active"?"success":"default",className:"text-2xs",children:a.status||"idle"})]})]},a.id||a.agentId))})]})}function PQe(){const t=q(r=>r.fetchFederationStatus),a=q(r=>r.fetchPouchLog),[s,c]=O.useState(!1);return O.useEffect(()=>{t(),a()},[]),e.jsxs("div",{children:[e.jsxs(MA,{defaultValue:"whitelist",children:[e.jsxs(jA,{className:"mb-4",children:[e.jsx(kn,{value:"whitelist",className:"text-xs px-3 py-1.5",children:"Whitelist"}),e.jsx(kn,{value:"peers",className:"text-xs px-3 py-1.5",children:"Peers"}),e.jsx(kn,{value:"ambassadors",className:"text-xs px-3 py-1.5",children:"Ambassadors"}),e.jsx(kn,{value:"activity",className:"text-xs px-3 py-1.5",children:"Activity"})]}),e.jsx(vn,{value:"whitelist",children:e.jsx(zQe,{})}),e.jsx(vn,{value:"peers",children:e.jsx(SQe,{onOpenWizard:()=>c(!0)})}),e.jsx(vn,{value:"ambassadors",children:e.jsx(TQe,{})}),e.jsx(vn,{value:"activity",children:e.jsx(_Qe,{})})]}),e.jsx(QQe,{open:s,onOpenChange:c})]})}const vX={community:{heading:"Get Groove Desktop",cta:"Download",icon:Oa,action:()=>sQ("https://groovedev.ai/download")},"community-electron":{heading:"Pro Feature",cta:"Upgrade to Pro",icon:bt,action:()=>q.getState().setUpgradeModalOpen(!0)},"sign-in":{heading:"Sign in to unlock",cta:"Sign in",icon:Do,action:()=>q.getState().marketplaceLogin()},subscribe:{heading:"Pro Feature",cta:"Upgrade to Pro",icon:bt,action:()=>q.getState().setUpgradeModalOpen(!0)}};function Eh({feature:t,description:a,variant:s="community"}){const c=s==="community"&&Go()?"community-electron":s,r=vX[c]||vX.community,l=r.icon;return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1/50 px-5 py-6 text-center",children:[e.jsx("div",{className:"mx-auto mb-3 flex h-10 w-10 items-center justify-center rounded-full bg-accent/10",children:e.jsx(Vd,{size:18,className:"text-accent"})}),e.jsx("h3",{className:"text-sm font-semibold text-text-1 font-sans",children:r.heading}),e.jsx("p",{className:"mt-1.5 text-2xs text-text-3 font-sans",children:t}),e.jsx("p",{className:"mt-1 text-2xs text-text-4 font-sans max-w-xs mx-auto",children:a}),e.jsxs("button",{onClick:r.action,className:"mt-4 inline-flex items-center gap-1.5 h-7 px-4 rounded-full bg-accent/15 text-accent text-xs font-semibold font-sans hover:bg-accent/25 transition-colors cursor-pointer",children:[e.jsx(l,{size:13}),r.cta]})]})}function AQe({feature:t,featureKey:a,description:s,children:c}){const r=q(p=>p.marketplaceAuthenticated),l=q(p=>p.subscription);if(q(p=>p.edition)!=="pro"){const p=Go()?"community-electron":"community";return e.jsx(Eh,{feature:t,description:s,variant:p})}return r?l!=null&&l.active?a&&(l==null?void 0:l.plan)!=="pro"&&!(l.features||[]).includes(a)?e.jsx(Eh,{feature:t,description:s,variant:"subscribe"}):c:e.jsx(Eh,{feature:t,description:s,variant:"subscribe"}):e.jsx(Eh,{feature:t,description:s,variant:"sign-in"})}function qQe(){const t=q(a=>a.fetchFederationStatus);return O.useEffect(()=>{t()},[]),e.jsxs("div",{className:"flex flex-col h-full bg-surface-0",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-border",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center",children:e.jsx(At,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-sm font-semibold text-text-0 font-sans",children:"Federation"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Connect to remote Groove daemons"})]})]}),e.jsx(It,{className:"flex-1",children:e.jsx("div",{className:"max-w-2xl mx-auto px-6 py-5",children:e.jsx(AQe,{feature:"Federation",featureKey:"federation",description:"Daemon-to-daemon federation over Tailscale mesh for multi-machine agent coordination",children:e.jsx(PQe,{})})})})]})}function OB({children:t,className:a,hover:s,...c}){return e.jsx("div",{className:K("rounded-md border border-border bg-surface-1",s&&"hover:border-accent/50 hover:bg-surface-2 transition-all duration-150 cursor-pointer",a),...c,children:t})}const IQe={beginner:"success",intermediate:"warning",advanced:"danger"};function RQe(t){if(!t)return wn;const a=t.replace(/(^|-)(\w)/g,(s,c,r)=>r.toUpperCase());return dQ[a]||dQ[t]||wn}function VQe({toy:t,onClick:a}){const s=RQe(t.icon);return e.jsxs(OB,{hover:!0,className:"group flex flex-col p-4 gap-3 transition-all duration-150 hover:scale-[1.02] hover:shadow-lg hover:shadow-black/20",onClick:()=>a(t),children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-accent",children:e.jsx(s,{size:20})}),e.jsx("div",{className:"flex-1 min-w-0 pt-0.5",children:e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans truncate pr-1",children:t.name})}),e.jsx(ge,{variant:"default",className:"flex-shrink-0 mt-0.5",children:t.category})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed line-clamp-2",children:t.description}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-auto flex-wrap",children:[t.custom&&e.jsx(ge,{variant:"accent",children:"Custom"}),e.jsx(ge,{variant:IQe[t.difficulty]||"default",children:t.difficulty||"beginner"}),e.jsx(ge,{variant:t.authType==="none"?"success":"warning",children:t.authType==="none"?"No Key Required":"API Key Required"})]})]})}function EQe(){return e.jsxs(OB,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-surface-4 animate-pulse"}),e.jsx("div",{className:"flex-1 space-y-2 pt-1",children:e.jsx("div",{className:"h-3.5 w-24 bg-surface-4 rounded animate-pulse"})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("div",{className:"h-5 w-16 bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-5 w-24 bg-surface-4 rounded animate-pulse"})]})]})}function XQe(t){if(!t)return wn;const a=t.replace(/(^|-)(\w)/g,(s,c,r)=>r.toUpperCase());return dQ[a]||dQ[t]||wn}function ZQe({toy:t,open:a,onClose:s}){var S,M;const[c,r]=O.useState(""),[l,u]=O.useState(!1),[p,f]=O.useState(null),[x,g]=O.useState(!1),y=va(),k=q($=>$.setActiveView);if(!t)return null;const b=XQe(t.icon),j=t.authType!=="none";async function w(){if(j&&!c.trim()){y.warning("API key required",`${t.name} needs an API key to work.`);return}g(!0);try{await X.post(`/toys/${t.id}/launch`,{apiKey:j?c.trim():void 0,starterPrompt:p||void 0}),y.success(`${t.name} launched`,"Team is spinning up — switching to agents view."),k("agents"),s()}catch($){y.error("Launch failed",$.message)}g(!1)}return e.jsx(FQ,{open:a,onOpenChange:$=>!$&&s(),children:e.jsxs(KQ,{title:t.name,width:440,children:[e.jsx(It,{className:"h-[calc(100%-65px)]",children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-accent",children:e.jsx(b,{size:24})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ge,{variant:t.authType==="none"?"success":"warning",children:t.authType==="none"?"Free":"Key Required"}),e.jsx(ge,{variant:"default",children:t.category})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed mt-2",children:t.description})]})]}),t.baseUrl&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"Base URL"}),e.jsx("code",{className:"text-xs text-accent font-mono bg-surface-3 px-2.5 py-1.5 rounded block truncate",children:t.baseUrl})]}),((S=t.sampleEndpoints)==null?void 0:S.length)>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"Endpoints"}),e.jsx("div",{className:"space-y-1",children:t.sampleEndpoints.map(($,C)=>{const _=typeof $=="string"?$:`${$.method||"GET"} ${$.path||""}`,P=_.indexOf(" "),L=P>0?_.slice(0,P):"GET",A=P>0?_.slice(P+1):_;return e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono text-text-2 bg-surface-3 px-2.5 py-1.5 rounded",children:[e.jsx(ge,{variant:"accent",className:"text-[9px] px-1 py-0",children:L}),e.jsx("span",{className:"truncate",children:A})]},C)})})]}),((M=t.starterPrompts)==null?void 0:M.length)>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"Starter Ideas"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.starterPrompts.map(($,C)=>e.jsx("button",{onClick:()=>f(p===$?null:$),className:`px-3 py-1.5 text-xs font-sans rounded-full cursor-pointer select-none transition-colors border ${p===$?"bg-accent/15 text-accent border-accent/25":"text-text-2 bg-surface-3 border-border-subtle hover:text-text-0 hover:border-border"}`,children:$},C))})]}),j&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:l?"text":"password",value:c,onChange:$=>r($.target.value),placeholder:`Enter your ${t.name} API key`,className:"w-full bg-surface-3 border border-border-subtle rounded px-3 py-2 text-xs text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:border-accent/50 pr-9"}),e.jsx("button",{onClick:()=>u(!l),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-1 cursor-pointer bg-transparent border-0 p-0.5",children:l?e.jsx(Jn,{size:14}):e.jsx(ka,{size:14})})]})]}),t.docsUrl&&e.jsxs("a",{href:t.docsUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-accent font-sans hover:underline",children:[e.jsx(Pt,{size:12}),"View Documentation"]})]})}),e.jsx("div",{className:"px-5 py-3 border-t border-border-subtle bg-surface-1",children:e.jsx(he,{variant:"primary",size:"lg",className:"w-full gap-2",onClick:w,disabled:x||j&&!c.trim(),children:x?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"}),"Launching..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ho,{size:14}),"Launch Team"]})})})]})})}const _s={input:"input",researching:"researching"};function DQe({open:t,onClose:a,onCreated:s}){const[c,r]=O.useState(""),[l,u]=O.useState(""),[p,f]=O.useState(_s.input),x=va();function g(){r(""),u(""),f(_s.input)}function y(){p!==_s.researching&&(g(),a())}async function k(){const b=c.trim();if(!b){x.warning("URL required","Paste an API documentation or reference URL.");return}f(_s.researching);try{const j=await X.post("/toys",{docsUrl:b,name:l.trim()||void 0});x.success("Toy created",`${j.name||"New toy"} is ready to launch.`),s==null||s(j),g(),a()}catch(j){x.error("Research failed",j.message),f(_s.input)}}return e.jsx(FQ,{open:t,onOpenChange:b=>!b&&y(),children:e.jsxs(KQ,{title:"New Toy",width:440,children:[e.jsx(It,{className:"h-[calc(100%-65px)]",children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[p===_s.input&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-accent/5 border border-accent/10",children:[e.jsx(bt,{size:16,className:"text-accent mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed",children:"Paste a docs URL and Groove's AI will research the API — endpoints, auth, data structures, rate limits — and build a reusable toy card you can launch anytime."})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:"API Docs URL"}),e.jsxs("div",{className:"relative",children:[e.jsx(Zo,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"url",value:c,onChange:b=>r(b.target.value),placeholder:"https://api.example.com/docs",className:"w-full bg-surface-3 border border-border-subtle rounded pl-8 pr-3 py-2 text-xs text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:border-accent/50",onKeyDown:b=>b.key==="Enter"&&k(),autoFocus:!0})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5",children:["Name ",e.jsx("span",{className:"text-text-4 normal-case tracking-normal",children:"(optional)"})]}),e.jsx("input",{type:"text",value:l,onChange:b=>u(b.target.value),placeholder:"Auto-detected from docs",className:"w-full bg-surface-3 border border-border-subtle rounded px-3 py-2 text-xs text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:border-accent/50",onKeyDown:b=>b.key==="Enter"&&k()})]})]}),p===_s.researching&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-accent/10 border border-accent/20 flex items-center justify-center",children:e.jsx(At,{size:24,className:"text-accent animate-pulse"})}),e.jsxs("div",{className:"text-center space-y-1.5",children:[e.jsx("p",{className:"text-sm font-semibold text-text-0 font-sans",children:"Researching API..."}),e.jsx("p",{className:"text-xs text-text-3 font-sans max-w-[260px]",children:"Reading documentation, mapping endpoints, and building your toy card. This takes 15–30 seconds."})]}),e.jsx(ze,{size:16,className:"text-accent animate-spin"})]})]})}),e.jsxs("div",{className:"px-5 py-3 border-t border-border-subtle bg-surface-1",children:[p===_s.input&&e.jsxs(he,{variant:"primary",size:"lg",className:"w-full gap-2",onClick:k,disabled:!c.trim(),children:[e.jsx(bt,{size:14}),"Research & Create"]}),p===_s.researching&&e.jsxs(he,{variant:"ghost",size:"lg",className:"w-full",disabled:!0,children:[e.jsx(ze,{size:14,className:"animate-spin mr-2"}),"AI is analyzing..."]})]})]})})}const UQe=["All","Space","Weather","Finance","Fun","Maps","Data"];function HQe(){const[t,a]=O.useState([]),[s,c]=O.useState(!0),[r,l]=O.useState(""),[u,p]=O.useState("All"),[f,x]=O.useState(null),[g,y]=O.useState(!1),k=q(M=>M.teams),b=O.useCallback(()=>{c(!0),X.get("/toys").then(M=>a(M.toys||M.items||(Array.isArray(M)?M:[]))).catch(()=>a([])).finally(()=>c(!1))},[]);O.useEffect(()=>{b()},[b]);const j=r.toLowerCase(),w=t.filter(M=>{var $,C,_;return!(u!=="All"&&(($=M.category)==null?void 0:$.toLowerCase())!==u.toLowerCase()||j&&!((C=M.name)!=null&&C.toLowerCase().includes(j))&&!((_=M.description)!=null&&_.toLowerCase().includes(j)))}),S=(k||[]).filter(M=>(M.name||"").startsWith("Toy:"));return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-shrink-0 px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx(m1,{size:18,className:"text-accent"}),e.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:"Toys"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:()=>y(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold font-sans rounded-full cursor-pointer select-none transition-colors bg-accent/15 text-accent border border-accent/25 hover:bg-accent/25",children:[e.jsx(rt,{size:13}),"New"]})]}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"Plug in an API and start building"})]}),e.jsxs("div",{className:"flex-shrink-0 px-5 pb-4 space-y-3",children:[e.jsxs("div",{className:"relative w-full max-w-sm",children:[e.jsx(Zt,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"text",value:r,onChange:M=>l(M.target.value),placeholder:"Search toys...",className:"w-full bg-surface-1 border border-border-subtle rounded pl-8 pr-3 py-1.5 text-xs text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:border-accent/50"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[UQe.map(M=>e.jsx("button",{onClick:()=>p(M),className:`px-3 py-1.5 text-xs font-semibold font-sans rounded-full cursor-pointer select-none transition-colors ${u===M?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1 border border-transparent hover:border-border-subtle"}`,children:M},M)),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-2xs text-text-4 font-mono",children:w.length})]})]}),e.jsx(It,{className:"flex-1 min-h-0",children:e.jsxs("div",{className:"px-5 pt-1 pb-5",children:[e.jsx("div",{className:"grid gap-3 grid-cols-[repeat(auto-fill,minmax(260px,1fr))]",children:s?Array.from({length:6}).map((M,$)=>e.jsx(EQe,{},$)):e.jsxs(e.Fragment,{children:[w.map(M=>e.jsx(VQe,{toy:M,onClick:x},M.id)),e.jsxs("button",{onClick:()=>y(!0),className:"flex flex-col items-center justify-center gap-2 p-4 rounded-xl border-2 border-dashed border-border-subtle text-text-4 hover:text-accent hover:border-accent/30 hover:bg-accent/5 transition-colors cursor-pointer min-h-[140px]",children:[e.jsx(rt,{size:20}),e.jsx("span",{className:"text-xs font-semibold font-sans",children:"Add API"})]})]})}),!s&&w.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No toys found. Try a different search or category."}),S.length>0&&e.jsxs("div",{className:"mt-8",children:[e.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[e.jsx(Ho,{size:12}),"Recent Toys (",S.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:S.map(M=>{var $;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(m1,{size:14,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:M.name}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:[(($=M.agents)==null?void 0:$.length)||0," agents"]})]}),e.jsx(ge,{variant:"accent",children:"Active"})]},M.id)})})]})]})}),e.jsx(ZQe,{toy:f,open:!!f,onClose:()=>x(null)}),e.jsx(DQe,{open:g,onClose:()=>y(!1),onCreated:()=>b()})]})}const bX=28;function BQe(t){return t>.9?ce.danger:t>.7?ce.warning:ce.success}function NQ(t){return t?(t/1024).toFixed(1):"0"}function o2({label:t,value:a,max:s,unit:c,nodeCount:r}){const l=s>0?Math.min(1,Math.max(0,a/s)):0,u=Math.round(l*bX),p=bX-u,f="│".repeat(u)+"─".repeat(p),x=BQe(l);let g,y;return c==="GB"?(g=NQ(a),y=NQ(s)):c==="cores"||c==="Mbps"?(g=Math.round(a),y=Math.round(s)):(g=a.toFixed(1),y=s.toFixed(1)),e.jsxs("div",{className:"flex items-center gap-2 font-mono text-xs leading-tight",children:[e.jsx("span",{className:"w-[40px] text-right text-text-3 uppercase text-2xs tracking-wider flex-shrink-0",children:t}),e.jsx("span",{className:"text-text-4",children:"["}),e.jsx("span",{style:{color:l>0?x:void 0},className:K("whitespace-pre",!l&&"text-text-4"),children:f}),e.jsx("span",{className:"text-text-4",children:"]"}),e.jsxs("span",{className:"text-text-1 tabular-nums whitespace-nowrap text-2xs",children:[g," / ",y," ",c]}),r!=null&&e.jsxs("span",{className:"text-text-4 text-2xs whitespace-nowrap",children:["(",r," nodes)"]})]})}function GQe({data:t,color:a=ce.accent,width:s=72,height:c=22}){if(!t||t.length<2)return e.jsx("div",{style:{width:s,height:c}});const r=t.map(g=>typeof g=="number"?g:g.v),l=Math.min(...r),p=Math.max(...r)-l||1,f=r.map((g,y)=>{const k=y/(r.length-1)*s,b=c-(g-l)/p*(c-2)-1;return`${k},${b}`}).join(" "),x=`net-${a.replace("#","")}`;return e.jsxs("svg",{width:s,height:c,className:"flex-shrink-0",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:x,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:a,stopOpacity:"0.2"}),e.jsx("stop",{offset:"100%",stopColor:a,stopOpacity:"0"})]})}),e.jsx("polygon",{points:`0,${c} ${f} ${s},${c}`,fill:`url(#${x})`}),e.jsx("polyline",{points:f,fill:"none",stroke:a,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}function WQe({label:t,value:a,color:s=ce.accent,hint:c,className:r}){return e.jsx("div",{className:K("flex items-center gap-2.5 px-3 py-2.5 min-w-0 bg-surface-1",r),children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5 truncate flex items-center gap-1",children:[t,c&&e.jsx($1,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:c}),side:"bottom",children:e.jsx(Wt,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),e.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:a})]})})}const YQe=256*1024,FQe=128*1024,KQe=128,JQe=4,eLe=[{key:"globalSessions",label:"Sessions",color:ce.accent},{key:"mySessions",label:"My Sessions",color:ce.info},{key:"nodeCount",label:"Nodes",color:ce.purple},{key:"avgLoad",label:"Load",color:ce.warning},{key:"myLoad",label:"My Load",color:ce.success}];function tLe({snapshots:t}){const a=t&&t.length>=2;return e.jsxs("div",{className:"flex flex-col gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest mb-1.5",children:"Trends"}),a?eLe.map(s=>{const c=t.map(u=>({v:u[s.key]??0})),r=c[c.length-1].v,l=Number.isInteger(r)?r:r.toFixed(2);return e.jsxs("div",{className:"flex items-center gap-2 bg-surface-1 rounded px-2 py-1",children:[e.jsx("span",{className:"w-[72px] text-2xs font-mono text-text-3 uppercase truncate flex-shrink-0",children:s.label}),e.jsx(GQe,{data:c,color:s.color,width:140,height:24}),e.jsx("span",{className:"text-2xs font-mono text-text-1 tabular-nums flex-shrink-0",children:l})]},s.key)}):e.jsx("div",{className:"text-2xs font-mono text-text-4",children:"Collecting data…"})]})}function aLe({node:t,compute:a}){var f;if(!t||!t.active)return e.jsxs("div",{className:"flex flex-col gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest mb-1.5",children:"Your Node"}),e.jsx("div",{className:"text-2xs font-mono text-text-4",children:"Node idle"})]});const s=t.layers?`Layers ${t.layers} / 36`:"Unassigned",c=t.model||"Qwen/Qwen3-4B",r=a.totalBandwidthMbps?`${Math.round(a.totalBandwidthMbps)} Mbps`:"— Mbps",l=(f=t.hardware)==null?void 0:f.memory,u=l&&a.totalRamMb>0?`${(l/a.totalRamMb*100).toFixed(1)}%`:"—",p=[{label:"Layers",value:s},{label:"Model",value:c},{label:"Sessions",value:t.sessions??0},{label:"Bandwidth",value:r},{label:"RAM Share",value:u}];return e.jsxs("div",{className:"flex flex-col gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest mb-1.5",children:"Your Node"}),p.map(x=>e.jsxs("div",{className:"bg-surface-1 rounded px-2.5 py-1.5 min-w-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider leading-none",children:x.label}),e.jsx("div",{className:"text-xs font-mono text-text-1 truncate leading-tight",children:x.value})]},x.label))]})}function nLe({compute:t,allZero:a,avgGpuUtil:s}){const c=q(l=>l.networkSnapshots),r=q(l=>l.networkNode);return e.jsxs("div",{className:"bg-surface-1 border-b border-border px-4 py-3",style:{display:"grid",gridTemplateColumns:"1fr 1.4fr 1fr",gap:"1.5rem"},children:[e.jsx("div",{className:"bg-surface-0 rounded border border-border-subtle px-3 py-2.5",children:e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest mb-1.5",children:"Resources"}),a?e.jsx("div",{className:"text-2xs font-mono text-text-4",children:"Waiting for network data..."}):e.jsxs(e.Fragment,{children:[e.jsx(o2,{label:"RAM",value:t.totalRamMb,max:YQe,unit:"GB",nodeCount:t.totalNodes}),e.jsx(o2,{label:"VRAM",value:t.totalVramMb,max:FQe,unit:"GB",nodeCount:t.totalNodes}),e.jsx(o2,{label:"CPU",value:t.totalCpuCores,max:KQe,unit:"cores"}),e.jsx(o2,{label:"GPU%",value:s,max:100,unit:"%"}),e.jsx(o2,{label:"LOAD",value:t.avgLoad,max:JQe,unit:""})]})]})}),e.jsx("div",{className:"bg-surface-0 rounded border border-border-subtle px-3 py-2.5",children:e.jsx(tLe,{snapshots:c})}),e.jsx("div",{className:"bg-surface-0 rounded border border-border-subtle px-3 py-2.5",children:e.jsx(aLe,{node:r,compute:t})})]})}const sLe=O.memo(function(){const a=q(y=>y.networkCompute),s=q(y=>y.networkStatus.nodes||[]),c=q(y=>y.networkStatus.models||[]),r=!a.totalRamMb&&!a.totalVramMb&&!a.totalCpuCores,l=s.filter(y=>y.status==="active"),u=l.length>0?l.reduce((y,k)=>y+(k.gpu_utilization_pct||0),0)/l.length:0,p=u>80?ce.danger:u>50?ce.warning:ce.success,f=a.avgLoad>2?ce.danger:a.avgLoad>1?ce.warning:ce.success,x=c.length>0?typeof c[0]=="string"?c[0]:c[0].name:"Qwen/Qwen3-4B",g=[{label:"RAM",value:`${NQ(a.totalRamMb)} GB`,color:ce.accent,hint:"Total RAM across all network nodes."},{label:"VRAM",value:`${NQ(a.totalVramMb)} GB`,color:ce.info,hint:"Total GPU VRAM across all network nodes."},{label:"CPU Cores",value:`${a.totalCpuCores}`,color:ce.purple,hint:"Total CPU cores across all network nodes."},{label:"GPU Util",value:u>0?`${Math.round(u)}%`:"--",color:p,hint:"Average GPU utilization across active nodes. Green <50%, yellow 50-80%, red >80%."},{label:"Nodes",value:`${a.activeNodes}/${a.totalNodes}`,color:ce.accent,hint:"Active nodes out of total registered."},{label:"Load",value:a.avgLoad>0?a.avgLoad.toFixed(2):"0.00",color:f,hint:"Average load across active nodes. Green <1.0, yellow 1.0-2.0, red >2.0."},{label:"Model",value:x,color:ce.info,hint:"Active inference model on the network."}];return e.jsxs("div",{className:"flex-shrink-0",children:[e.jsx("div",{className:"flex flex-wrap border-b border-border",style:{background:"var(--color-surface-0)"},children:g.map(y=>e.jsx(WQe,{label:y.label,value:y.value,color:y.color,hint:y.hint,className:K("flex-1 basis-[14.2%] min-w-[110px]","border-b border-r border-border")},y.label))}),e.jsx(nLe,{compute:a,allZero:r,avgGpuUtil:u})]})});function oLe(t){return!t||typeof t!="string"?"—":t.length<14?t:`${t.slice(0,6)}…${t.slice(-4)}`}const cLe=O.memo(function(){const a=q(C=>C.networkSnapshots),s=q(C=>C.networkStatus.nodes||[]),c=q(C=>C.networkNode.nodeId),r=O.useRef(null),l=O.useRef(null),[u,p]=O.useState({width:0,height:0}),[f,x]=O.useState(null),{width:g,height:y}=u,k={top:28,right:12,bottom:8,left:12},b=Math.max(g-k.left-k.right,0),j=Math.max(y-k.top-k.bottom,0),w=O.useMemo(()=>!a||a.length<2?[]:a,[a]);O.useEffect(()=>{const C=r.current;if(!C)return;const _=new ResizeObserver(P=>{const{width:L,height:A}=P[0].contentRect;L>0&&A>0&&p({width:Math.floor(L),height:Math.floor(A)})});return _.observe(C),()=>_.disconnect()},[]);const S=O.useCallback(C=>{const _=l.current;if(!_||!w.length||b<=0)return;const P=_.getBoundingClientRect(),L=C.clientX-P.left-k.left;if(L<0||L>b){x(null);return}const A=Math.round(L/b*(w.length-1));x({x:k.left+A/Math.max(w.length-1,1)*b,index:A})},[w,b,k.left]),M=O.useCallback(()=>x(null),[]);O.useEffect(()=>{const C=l.current;if(!C||!w.length||g<=0||y<=0||b<=0||j<=0)return;const _=C.getContext("2d"),P=window.devicePixelRatio||1;C.width=g*P,C.height=y*P,_.scale(P,P),_.clearRect(0,0,g,y);const L=w.map(R=>R.globalSessions),A=w.map(R=>R.mySessions),z=Math.max(...L,...A,1),Y=R=>k.left+R/Math.max(w.length-1,1)*b,V=R=>k.top+j-R/z*j;_.setLineDash([2,4]),_.strokeStyle=ct(ce.text4,.2),_.lineWidth=1;for(let R=1;R<=3;R++){const I=k.top+j/4*R;_.beginPath(),_.moveTo(k.left,I),_.lineTo(k.left+b,I),_.stroke()}_.setLineDash([]),_.font="9px 'JetBrains Mono Variable', monospace",_.textAlign="left",_.fillStyle=ct(ce.text3,.5),_.fillText(String(z),k.left+4,k.top+10),_.fillText(String(Math.round(z/2)),k.left+4,k.top+j/2+4),_.beginPath(),_.moveTo(k.left,k.top+j);for(let R=0;R<w.length;R++)_.lineTo(Y(R),V(L[R]));_.lineTo(Y(w.length-1),k.top+j),_.closePath();const se=_.createLinearGradient(0,k.top,0,k.top+j);se.addColorStop(0,ct(ce.purple,.2)),se.addColorStop(.7,ct(ce.purple,.04)),se.addColorStop(1,ct(ce.purple,0)),_.fillStyle=se,_.fill(),_.beginPath(),_.strokeStyle=ce.purple,_.lineWidth=1.5,_.lineJoin="round";for(let R=0;R<w.length;R++){const I=Y(R),T=V(L[R]);R===0?_.moveTo(I,T):_.lineTo(I,T)}_.stroke(),_.beginPath(),_.strokeStyle=ce.accent,_.lineWidth=1.5,_.lineJoin="round";for(let R=0;R<w.length;R++){const I=Y(R),T=V(A[R]);R===0?_.moveTo(I,T):_.lineTo(I,T)}_.stroke(),_.font="9px 'Inter Variable', sans-serif",_.textAlign="right";let ne=g-k.right-4;const oe=14;if(_.fillStyle=ce.accent,_.fillText("Your Node",ne,oe),ne-=_.measureText("Your Node").width+4,_.beginPath(),_.arc(ne,oe-3,2.5,0,Math.PI*2),_.fill(),ne-=14,_.fillStyle=ce.purple,_.fillText("Network",ne,oe),ne-=_.measureText("Network").width+4,_.beginPath(),_.arc(ne,oe-3,2.5,0,Math.PI*2),_.fill(),f&&f.index>=0&&f.index<w.length){const R=f.x,I=w[f.index];_.beginPath(),_.moveTo(R,k.top),_.lineTo(R,k.top+j),_.strokeStyle=ct(ce.text1,.15),_.lineWidth=1,_.stroke(),_.beginPath(),_.arc(R,V(I.globalSessions),3,0,Math.PI*2),_.fillStyle=ce.purple,_.fill(),_.beginPath(),_.arc(R,V(I.mySessions),3,0,Math.PI*2),_.fillStyle=ce.accent,_.fill();const T=[{label:"Network",value:String(I.globalSessions),color:ce.purple},{label:"Your Node",value:String(I.mySessions),color:ce.accent},{label:"Nodes",value:String(I.nodeCount),color:ce.text2}],Z=104,J=T.length*16+12;let W=R+12;W+Z>g-8&&(W=R-Z-12);const U=Math.max(k.top,V(I.globalSessions)-J/2);_.fillStyle=ct(ce.surface0,.92),_.beginPath(),_.roundRect(W,U,Z,J,4),_.fill(),_.strokeStyle=ct(ce.text4,.2),_.lineWidth=1,_.stroke(),_.textAlign="left",T.forEach((xe,pe)=>{const fe=U+14+pe*16;_.beginPath(),_.arc(W+8,fe-3,2,0,Math.PI*2),_.fillStyle=xe.color,_.fill(),_.font="8px 'Inter Variable', sans-serif",_.fillStyle=ce.text3,_.fillText(xe.label,W+14,fe),_.font="9px 'JetBrains Mono Variable', monospace",_.fillStyle=ce.text0,_.textAlign="right",_.fillText(xe.value,W+Z-8,fe),_.textAlign="left"})}},[w,g,y,f,b,j,k]);const $=s.filter(C=>C.status==="active");return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Network Activity"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[$.length," nodes"]})]}),e.jsx("div",{className:"relative flex-1 min-h-0",children:w.length<2?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("span",{className:"text-xs font-mono text-text-3",children:"Collecting network data…"})}):e.jsx("div",{ref:r,className:"absolute inset-0",children:g>0&&y>0&&e.jsx("canvas",{ref:l,style:{width:g,height:y},className:"block cursor-crosshair",onMouseMove:S,onMouseLeave:M})})}),e.jsxs("div",{className:"px-3 py-1.5 border-t border-border-subtle flex items-center gap-2 flex-shrink-0 font-mono text-2xs",style:{background:ct(ce.accent,.04)},children:[e.jsxs("span",{className:"text-text-3",children:[$.length," node",$.length!==1?"s":""," online"]}),$.map(C=>{const _=C.node_id||C.nodeId||"",P=c&&_===c,L=Array.isArray(C.layers)?`${C.layers[0]}-${C.layers[1]}`:"";return e.jsxs("span",{className:P?"text-accent":"text-text-2",children:[oLe(_),P?" (You":"(",L?` · ${L}`:"",")"]},_)})]})]})}),rLe=["All","Sessions","Errors","Connections"],iLe={Sessions:["session"],Errors:["error","warning"],Connections:["connected","disconnected"]},lLe={info:ce.text3,success:ce.success,warning:ce.warning,error:ce.danger,connected:ce.success,disconnected:ce.warning,session:ce.accent};function dLe(t){return t?new Date(t).toLocaleTimeString("en-GB",{hour12:!1}):"--:--:--"}function uLe(t){return{info:"info",success:" ok ",warning:"warn",error:"ERR!",connected:"conn",disconnected:"disc",session:"sess"}[t]||t||"info"}const hLe=O.memo(function(){const a=q(p=>p.networkEvents),[s,c]=O.useState("All"),r=O.useRef(null),u=(s==="All"?a:a.filter(p=>{const f=p.level||p.type||"info";return(iLe[s]||[]).includes(f)})).slice(-200);return O.useEffect(()=>{var p;(p=r.current)==null||p.scrollIntoView({behavior:"smooth"})},[u.length]),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1 flex-shrink-0",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Activity"}),e.jsx("div",{className:"flex-1"}),e.jsx("div",{className:"flex items-center gap-0.5",children:rLe.map(p=>e.jsx("button",{onClick:()=>c(p),className:K("px-2 py-0.5 text-2xs font-mono rounded-sm transition-colors cursor-pointer",s===p?"bg-[rgba(51,175,188,0.15)] text-accent":"bg-surface-4 text-text-3 hover:text-text-2"),children:p},p))})]}),e.jsx(It,{className:"flex-1 min-h-0",children:u.length===0?e.jsx("div",{className:"px-3 py-6 text-2xs font-mono text-text-4 text-center",children:"No events yet — toggle your node on to start."}):e.jsxs("div",{className:"px-2 py-1",children:[u.map((p,f)=>{const x=p.level||p.type||"info",g=lLe[x]||ce.text3;return e.jsxs("div",{className:"flex items-start gap-0 font-mono text-2xs leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 flex-shrink-0 w-[62px]",children:["[",dLe(p.timestamp||p.ts),"]"]}),e.jsx("span",{className:"flex-shrink-0 w-[36px]",style:{color:g},children:uLe(x)}),e.jsx("span",{className:"text-text-2 break-words min-w-0",children:p.msg||p.message||p.text||"event"})]},f)}),e.jsx("div",{ref:r})]})})]})});function pLe(t,a){const s=t/a;return s>=1?{color:ce.success,label:"Full coverage"}:s>=.5?{color:ce.warning,label:"Partial"}:{color:ce.danger,label:"Insufficient"}}const fLe=O.memo(function(){const a=q(x=>x.networkStatus),s=q(x=>x.networkStatusReachable),c=q(x=>x.networkNode);Array.isArray(a.nodes)&&a.nodes;const r=a.totalLayers||36,l=a.coverage||0,u=pLe(l,r),p=Math.min(100,l/r*100),f=Array.isArray(a.models)?a.models:[];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Network Health"})}),e.jsx(It,{className:"flex-1 min-h-0",children:e.jsxs("div",{className:"px-3 py-2 space-y-3",children:[e.jsx("div",{className:"bg-surface-0 rounded p-2.5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:s?ce.success:ce.danger}}),s&&e.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:ce.success,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),e.jsx("span",{className:"text-2xs font-mono text-text-3",children:"Signal"}),e.jsx("span",{className:"text-2xs font-mono text-text-1",children:"signal.groovedev.ai"}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-2xs font-mono",style:{color:s?ce.success:ce.danger},children:s?"Connected":"Unreachable"})]})}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Layer Coverage"}),e.jsxs("span",{className:"text-2xs font-mono tabular-nums",style:{color:u.color},children:[l,"/",r]})]}),e.jsx("div",{className:"h-0.5 rounded-sm overflow-hidden",style:{background:ct(ce.accent,.08)},children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-700",style:{width:`${p}%`,background:u.color}})}),e.jsx("div",{className:"mt-1 text-2xs font-mono text-text-4",children:u.label})]}),e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Sessions"}),e.jsx("span",{className:"text-base font-mono font-semibold text-text-0 tabular-nums leading-none",children:Fe(a.activeSessions||0)})]}),e.jsx("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:"Active streams"})]}),c.active&&e.jsxs("div",{className:"bg-surface-0 rounded p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Node Status"}),e.jsx("span",{className:"text-2xs font-mono capitalize",style:{color:c.status==="connected"?ce.success:ce.warning},children:c.status||"disconnected"})]}),c.sessions>0&&e.jsxs("div",{className:"flex items-center justify-between mt-1.5",children:[e.jsx("span",{className:"text-2xs font-mono text-text-4",children:"Local Sessions"}),e.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:c.sessions})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-1.5",children:"Models"}),f.length===0?e.jsx("div",{className:"text-2xs font-mono text-text-4",children:"No models available"}):e.jsx("div",{className:"space-y-1",children:f.map((x,g)=>{const y=typeof x=="string"?x:x.name,k=typeof x=="string"?!0:!!x.available;return e.jsxs("div",{className:"flex items-center gap-2 bg-surface-0 rounded px-2.5 py-1.5",children:[e.jsx("span",{className:"relative flex-shrink-0 w-[5px] h-[5px]",children:e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:k?ce.success:ce.text4}})}),e.jsx("span",{className:"text-xs font-mono text-text-1 truncate flex-1",children:y}),e.jsx("span",{className:"text-2xs font-mono",style:{color:k?ce.success:ce.text3},children:k?"Online":"Offline"})]},g)})})]})]})})]})}),xLe=["Python 3.10 or higher","~2 GB disk space for model shards","8 GB+ RAM recommended"];function mLe({progress:t}){const a=Math.max(0,Math.min(100,Number.isFinite(t.percent)?t.percent:0));return e.jsxs("div",{className:"w-full flex flex-col gap-3",children:[e.jsx("div",{className:"h-2 w-full rounded-full bg-surface-3 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-accent transition-all duration-500 ease-out",style:{width:`${a}%`}})}),e.jsxs("div",{className:"flex items-center justify-between text-2xs font-mono text-text-3 tabular-nums",children:[e.jsxs("div",{className:"flex items-center gap-2 text-text-2 font-sans",children:[e.jsx(ze,{size:12,className:"animate-spin text-accent"}),e.jsx("span",{className:"truncate",children:t.message||"Installing…"})]}),e.jsxs("span",{children:[a,"%"]})]})]})}function yLe({message:t,onRetry:a}){return e.jsxs("div",{className:"w-full flex flex-col gap-3",children:[e.jsxs("div",{className:"rounded-md border border-danger/40 bg-danger/10 px-4 py-3 flex items-start gap-2.5 text-left",children:[e.jsx(vt,{size:14,className:"text-danger flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-danger font-sans mb-0.5",children:"Install failed"}),e.jsx("div",{className:"text-xs text-text-1 font-sans break-words",children:t})]})]}),e.jsxs(he,{variant:"primary",size:"lg",onClick:a,className:"w-full",children:[e.jsx(Oa,{size:14}),"Retry Install"]})]})}function gLe(){const t=q(r=>r.installNetworkPackage),a=q(r=>r.networkInstallProgress),{installing:s,error:c}=a;return e.jsx("div",{className:"flex flex-col items-center justify-center min-h-full px-6 py-12",children:e.jsxs("div",{className:"w-full max-w-md flex flex-col items-center text-center",children:[e.jsx("div",{className:"mb-5 rounded-full bg-surface-2 border border-border-subtle p-5",children:e.jsx(At,{size:48,className:"text-text-3",strokeWidth:1.25})}),e.jsx("h3",{className:"text-base font-semibold text-text-0 font-sans mb-2",children:"Install Groove Network"}),e.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed mb-6",children:"The network package enables decentralized LLM inference. Contribute your compute power or run models across the Groove network."}),e.jsxs("div",{className:"w-full rounded-md border border-border-subtle bg-surface-1 px-4 py-3 mb-6",children:[e.jsx("div",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2 text-left",children:"Requirements"}),e.jsx("ul",{className:"flex flex-col gap-1.5",children:xLe.map(r=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-sans text-text-1 text-left",children:[e.jsx(Ve,{size:12,className:"text-accent flex-shrink-0"}),e.jsx("span",{children:r})]},r))})]}),s?e.jsx(mLe,{progress:a}):c?e.jsx(yLe,{message:c,onRetry:()=>t()}):e.jsxs(e.Fragment,{children:[e.jsxs(he,{variant:"primary",size:"lg",onClick:()=>t(),className:"w-full",children:[e.jsx(Oa,{size:14}),"Install Network Package"]}),e.jsx("p",{className:"text-2xs font-sans text-text-3 mt-3",children:"This will download and set up the Groove Network runtime (~500 MB)"})]})]})})}function OLe({progress:t}){const a=Math.max(0,Math.min(100,Number.isFinite(t.percent)?t.percent:0));return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md border border-border-subtle bg-surface-0",children:[e.jsx(ze,{size:11,className:"animate-spin text-accent flex-shrink-0"}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("span",{className:"text-2xs font-sans text-text-1 truncate",children:t.message||"Updating…"}),e.jsx("div",{className:"h-1 w-32 rounded-full bg-surface-3 overflow-hidden mt-0.5",children:e.jsx("div",{className:"h-full rounded-full bg-accent transition-all duration-500 ease-out",style:{width:`${a}%`}})})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[a,"%"]})]})}function kLe(){const[t,a]=O.useState(!1),s=q(u=>u.networkVersion),c=q(u=>u.networkUpdateProgress),r=q(u=>u.updateNetworkPackage);if(c.updating)return e.jsx(OLe,{progress:c});if(!s.updateAvailable)return null;const l=async()=>{try{await r(),a(!1)}catch{}};return e.jsxs(qa,{open:t,onOpenChange:a,children:[e.jsx(MD,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex items-center gap-1",title:`Update to ${s.latest}`,children:e.jsxs(ge,{variant:"warning",className:"cursor-pointer",children:[e.jsx(Ja,{size:10}),"Update Available"]})})}),e.jsxs(Ia,{title:"Update Network Package",description:"Confirm update",children:[e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[e.jsxs("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:["Update to ",e.jsx("span",{className:"font-mono text-accent",children:s.latest}),"?"]}),e.jsxs("p",{className:"text-xs text-text-3 font-sans leading-relaxed",children:["You are currently running ",e.jsx("span",{className:"font-mono",children:s.installed||"unknown"}),". Your node will be stopped during the update and restarted after."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3 border-t border-border-subtle bg-surface-0",children:[e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>a(!1),children:"Cancel"}),e.jsxs(he,{variant:"primary",size:"sm",onClick:l,children:[e.jsx(Ja,{size:12}),"Update"]})]})]})]})}function vLe(){const[t,a]=O.useState(!1),s=q(u=>u.uninstallNetworkPackage),[c,r]=O.useState(!1),l=async()=>{r(!0);try{await s(),a(!1)}catch{}finally{r(!1)}};return e.jsxs(qa,{open:t,onOpenChange:a,children:[e.jsx(MD,{asChild:!0,children:e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 text-2xs font-sans text-text-3 hover:text-danger transition-colors",children:[e.jsx(wt,{size:11}),"Uninstall"]})}),e.jsxs(Ia,{title:"Uninstall Network Package",description:"Confirm uninstall",children:[e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[e.jsxs("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:["This will stop your node and remove the network package from ",e.jsx("span",{className:"font-mono text-text-2",children:"~/.groove/network"}),"."]}),e.jsxs("p",{className:"text-xs text-text-3 font-sans leading-relaxed",children:["Your identity (",e.jsx("span",{className:"font-mono",children:"~/.groove/node_key.json"}),") will be preserved — you can reinstall later without losing your wallet."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3 border-t border-border-subtle bg-surface-0",children:[e.jsx(he,{variant:"ghost",size:"sm",onClick:()=>a(!1),disabled:c,children:"Cancel"}),e.jsxs(he,{variant:"danger",size:"sm",onClick:l,disabled:c,children:[c?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(wt,{size:12}),"Uninstall"]})]})]})]})}function bLe({value:t,onChange:a,disabled:s}){return e.jsx("button",{onClick:()=>!s&&a(!t),disabled:s,className:K("relative inline-flex h-5 w-9 rounded-full p-0.5 transition-colors flex-shrink-0",s?"opacity-50 cursor-not-allowed":"cursor-pointer",t?"bg-accent":"bg-surface-5"),children:e.jsx("span",{className:K("inline-block h-4 w-4 rounded-full bg-white shadow-sm transition-transform",t?"translate-x-4":"translate-x-0")})})}function jP(){const t=q(x=>x.networkNode),a=q(x=>x.networkInstalled),s=q(x=>x.networkVersion),c=q(x=>x.networkStatusReachable),r=q(x=>x.startNetworkNode),l=q(x=>x.stopNetworkNode),[u,p]=O.useState(!1);async function f(x){p(!0);try{x?await r():await l()}catch{}p(!1)}return e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border flex-shrink-0",children:[e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Network Command Center"}),a&&s.installed&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"/"}),e.jsxs("span",{className:"text-xs font-mono text-text-2 tabular-nums",children:["v",String(s.installed).replace(/^v/,"")]})]}),a&&e.jsx(kLe,{}),e.jsx("div",{className:"flex-1"}),a&&e.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(bLe,{value:!!t.active,onChange:f,disabled:u}),e.jsx("span",{className:"text-text-3",children:t.active?"Contributing":"Idle"})]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"relative flex-shrink-0 w-[5px] h-[5px]",children:e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:c?ce.accent:ce.danger}})}),e.jsx("span",{className:"text-text-3",children:"Signal"})]})]}),a&&e.jsx(vLe,{}),e.jsx(aa,{status:a&&t.active?"running":a?"stopped":"crashed",size:"sm"})]})}function wLe(){const t=q(x=>x.networkNode),a=q(x=>x.networkStatus),s=q(x=>x.startNetworkNode),[c,r]=O.useState(!1),l=t.hardware||{},u=(a.nodes||[]).filter(x=>x.status==="active").length,p=a.activeSessions||0;async function f(){r(!0);try{await s()}catch{}r(!1)}return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(jP,{}),e.jsx("div",{className:"flex-1 flex items-center justify-center bg-surface-0",style:{background:`radial-gradient(ellipse at 50% 40%, ${ct(ce.accent,.06)} 0%, transparent 70%) ${ce.surface0}`},children:e.jsxs("div",{className:"max-w-lg w-full px-6 flex flex-col items-center text-center",children:[e.jsx("div",{className:"w-24 h-24 rounded-full flex items-center justify-center mb-6 mx-auto",style:{background:ct(ce.accent,.08),border:`1px solid ${ct(ce.accent,.15)}`,boxShadow:`0 0 40px ${ct(ce.accent,.1)}`},children:e.jsx(At,{size:56,className:"text-accent",strokeWidth:1.25})}),e.jsx("h2",{className:"text-xl font-semibold text-text-0 font-sans text-center",children:"Join the Groove Network"}),e.jsx("p",{className:"text-sm text-text-2 font-sans text-center leading-relaxed mt-2 max-w-sm mx-auto",children:"Contribute your compute to power decentralized AI inference. Your hardware runs model shards alongside other nodes in the network."}),e.jsxs("div",{className:"mt-8 w-full",children:[e.jsx("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest mb-2 text-left",children:"Your Hardware"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"bg-surface-1 rounded-sm border border-border-subtle px-4 py-3",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:"Device"}),e.jsx("div",{className:"text-sm font-mono text-text-0 mt-1 truncate",children:l.device||"auto"})]}),e.jsxs("div",{className:"bg-surface-1 rounded-sm border border-border-subtle px-4 py-3",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:"Memory"}),e.jsx("div",{className:"text-sm font-mono text-text-0 mt-1 truncate",children:l.memory||"—"})]}),e.jsxs("div",{className:"bg-surface-1 rounded-sm border border-border-subtle px-4 py-3",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:"GPU"}),e.jsx("div",{className:"text-sm font-mono text-text-0 mt-1 truncate",children:l.gpu||"None"})]})]})]}),e.jsx("div",{className:"mt-6 w-full max-w-sm mx-auto",children:e.jsx(he,{variant:"primary",size:"lg",onClick:f,disabled:c,className:"w-full",children:c?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"})," Connecting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(qt,{size:14})," Start Contributing"]})})}),e.jsx("div",{className:"mt-4 text-center text-2xs font-mono text-text-3",children:u>0||p>0?e.jsxs("span",{children:[e.jsx("span",{className:"text-accent",children:u})," node",u!==1?"s":""," online · ",p," active session",p!==1?"s":""]}):e.jsx("span",{children:"Checking network status…"})}),t.nodeId&&e.jsxs("div",{className:"mt-6 text-center text-2xs font-mono text-text-4",children:["Node identity: ",t.nodeId.length>14?`${t.nodeId.slice(0,6)}…${t.nodeId.slice(-4)}`:t.nodeId]})]})})]})}function MLe(){const t=q(l=>l.fetchNetworkNodeStatus),a=q(l=>l.fetchNetworkStatus),s=q(l=>l.checkNetworkUpdate),c=q(l=>l.networkInstalled),r=q(l=>l.networkNode.active);return O.useEffect(()=>{if(t(),c){a(),s();const l=setInterval(()=>{a()},1e4);return()=>clearInterval(l)}},[t,a,s,c]),c?r?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(jP,{}),e.jsx(sLe,{}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",style:{background:ce.surface3,gap:"1px"},children:[e.jsxs("div",{className:"min-h-0 flex-1 grid",style:{gridTemplateColumns:"3fr 1.5fr",gap:"0 1px"},children:[e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1",children:e.jsx(cLe,{})}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1",children:e.jsx(fLe,{})})]}),e.jsx("div",{className:"min-h-0 flex-[0.6] bg-surface-1",children:e.jsx(hLe,{})})]})]}):e.jsx(wLe,{}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(jP,{}),e.jsx(It,{className:"flex-1",children:e.jsx(gLe,{})})]})}function kB(t){return t?t.replace(/^claude-/,"").replace(/-(\d)/," $1").split("-").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "):""}const jLe={frontier:{label:"Frontier",variant:"purple",icon:bt},mid:{label:"Mid",variant:"accent",icon:qt},fast:{label:"Fast",variant:"success",icon:qt}};function SLe(t){const a=(t||"").toLowerCase();return a.includes("opus")||a.includes("pro")||a.includes("o3")||a.includes("gpt-4o")?"frontier":a.includes("sonnet")||a.includes("flash")||a.includes("o4-mini")?"mid":"fast"}function NLe(t){const a=(t||"").toLowerCase();return a.includes("opus")||a.includes("sonnet")||a.includes("haiku")?"200k":a.includes("pro")||a.includes("flash")?"1M":(a.includes("o3")||a.includes("o4"),"128k")}function _Le({value:t,onChange:a,disabled:s}){const[c,r]=O.useState(!1),[l,u]=O.useState([]),p=q(b=>b.fetchProviders),f=O.useRef(null);O.useEffect(()=>{p().then(b=>{Array.isArray(b)?u(b):b!=null&&b.providers&&u(b.providers)}).catch(()=>{})},[p]),O.useEffect(()=>{if(!c)return;function b(j){f.current&&!f.current.contains(j.target)&&r(!1)}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[c]);const x=(t==null?void 0:t.model)||"",g=x?kB(x):"Select model",y=(t==null?void 0:t.provider)||"",k=y==="groove-network";return e.jsxs("div",{ref:f,className:"relative",children:[e.jsxs("button",{onClick:()=>!s&&r(!c),disabled:s,className:K("flex items-center gap-1.5 h-8 px-2.5 rounded-lg text-xs font-medium font-sans transition-colors cursor-pointer","bg-surface-4 border border-border-subtle hover:bg-surface-5","disabled:opacity-40 disabled:cursor-not-allowed",k&&"border-purple/30 bg-purple/8"),children:[k?e.jsx(At,{size:12,className:"text-purple"}):e.jsx(tn,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-text-1 max-w-[120px] truncate",children:g}),e.jsx(zt,{size:12,className:"text-text-4"})]}),c&&e.jsxs("div",{className:"absolute top-full right-0 mt-1 w-72 max-h-80 overflow-y-auto rounded-lg border border-border bg-surface-1 shadow-xl z-50",children:[l.length===0&&e.jsx("div",{className:"px-4 py-6 text-center text-xs text-text-3 font-sans",children:"No providers available"}),l.map(b=>{const j=b.models||[];if(j.length===0)return null;const w=b.id==="groove-network";return e.jsxs("div",{children:[e.jsxs("div",{className:"px-3 py-1.5 text-2xs font-semibold text-text-3 uppercase tracking-wider font-sans bg-surface-2 border-b border-border-subtle flex items-center gap-1.5",children:[w&&e.jsx(At,{size:10,className:"text-purple"}),b.name||b.id]}),j.map(S=>{const M=typeof S=="string"?S:S.id||S.name,$=typeof S=="string"?S:S.name||S.id,C=SLe(M),_=jLe[C],P=_.icon,L=x===M&&y===b.id;return e.jsxs("button",{onClick:()=>{a({provider:b.id,model:M}),r(!1)},className:K("w-full flex items-center gap-2 px-3 py-2 text-left transition-colors cursor-pointer",L?"bg-accent/10 text-text-0":"hover:bg-surface-3 text-text-1"),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium font-sans truncate",children:$}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:[NLe(M)," context"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[w&&e.jsxs(ge,{variant:"purple",className:"text-[9px]",children:[e.jsx(At,{size:8})," Decentralized"]}),e.jsxs(ge,{variant:_.variant,className:"text-[9px]",children:[e.jsx(P,{size:8})," ",_.label]})]})]},M)})]},b.id)})]})]})}function $Le(t){const a=new Date,s=new Date(a.getFullYear(),a.getMonth(),a.getDate()),c=new Date(s);c.setDate(s.getDate()-1);const r=new Date(s);r.setDate(s.getDate()-7);const l={pinned:[],today:[],yesterday:[],week:[],older:[]};for(const u of t){if(u.pinned){l.pinned.push(u);continue}const p=new Date(u.updatedAt||u.createdAt);p>=s?l.today.push(u):p>=c?l.yesterday.push(u):p>=r?l.week.push(u):l.older.push(u)}return l}function CLe({label:t}){return e.jsx("div",{className:"px-3 pt-4 pb-1.5",children:e.jsx("span",{className:"text-2xs font-semibold text-text-4 uppercase tracking-wider font-sans",children:t})})}function QLe({conv:t,isActive:a,onSelect:s,onRename:c,onPin:r,onDelete:l}){return e.jsxs(aA,{children:[e.jsx(nA,{asChild:!0,children:e.jsxs("button",{onClick:()=>s(t.id),className:K("w-full flex items-center gap-2 px-3 py-2 text-left rounded-md transition-colors cursor-pointer group",a?"bg-accent/10 text-text-0":"text-text-2 hover:bg-surface-4 hover:text-text-1"),children:[e.jsx(Sn,{size:13,className:K("flex-shrink-0",a?"text-accent":"text-text-4 group-hover:text-text-3")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium font-sans truncate",children:t.title||"New Chat"}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.mode==="agent"?e.jsx(Ld,{size:9,className:"text-purple flex-shrink-0"}):e.jsx(qt,{size:9,className:"text-accent flex-shrink-0"}),t.model&&e.jsx(ge,{variant:"default",className:"text-[8px] px-1 py-0",children:kB(t.model)}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:gt(t.updatedAt||t.createdAt)})]})]}),t.pinned&&e.jsx(y1,{size:10,className:"text-accent flex-shrink-0"})]})}),e.jsxs(sA,{children:[e.jsxs(gn,{onSelect:()=>c(t),children:[e.jsx(ts,{size:12})," Rename"]}),e.jsxs(gn,{onSelect:()=>r(t),children:[t.pinned?e.jsx(Ud,{size:12}):e.jsx(y1,{size:12}),t.pinned?"Unpin":"Pin"]}),e.jsx(oA,{}),e.jsxs(gn,{danger:!0,onSelect:()=>l(t.id),children:[e.jsx(wt,{size:12})," Delete"]})]})]})}function LLe({onNewChat:t}){const a=q(y=>y.conversations),s=q(y=>y.activeConversationId),c=q(y=>y.setActiveConversation),r=q(y=>y.renameConversation),l=q(y=>y.pinConversation),u=q(y=>y.deleteConversation),p=O.useMemo(()=>$Le(a),[a]);function f(y){const k=prompt("Rename conversation:",y.title||"");k&&k.trim()&&r(y.id,k.trim())}function x(y){l(y.id,!y.pinned)}const g=(y,k)=>k.length===0?null:e.jsxs("div",{children:[e.jsx(CLe,{label:y}),k.map(b=>e.jsx(QLe,{conv:b,isActive:b.id===s,onSelect:c,onRename:f,onPin:x,onDelete:u},b.id))]},y);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 overflow-y-auto px-1.5 pt-3 pb-3 space-y-0.5",children:a.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center px-4",children:[e.jsx(Sn,{size:24,className:"text-text-4 mb-3"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No conversations yet"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Start a new chat to begin"})]}):e.jsxs(e.Fragment,{children:[g("Pinned",p.pinned),g("Today",p.today),g("Yesterday",p.yesterday),g("Previous 7 Days",p.week),g("Older",p.older)]})}),e.jsx("div",{className:"p-3 border-t border-border-subtle",children:e.jsxs("button",{onClick:t,className:"w-full flex items-center justify-center gap-2 h-9 rounded-lg bg-accent/15 text-accent text-xs font-semibold font-sans hover:bg-accent/25 transition-colors cursor-pointer border border-accent/20",children:[e.jsx(rt,{size:14}),"New Chat"]})})]})}function zLe({conversation:t,model:a,onModelChange:s,onModeChange:c}){const r=q(C=>C.renameConversation),l=q(C=>C.pinConversation),u=q(C=>C.deleteConversation),[p,f]=O.useState(!1),[x,g]=O.useState(t.title||""),[y,k]=O.useState(!1),b=O.useRef(null),j=O.useRef(null);O.useEffect(()=>{g(t.title||""),f(!1)},[t.id,t.title]),O.useEffect(()=>{p&&b.current&&b.current.focus()},[p]),O.useEffect(()=>{if(!y)return;function C(_){j.current&&!j.current.contains(_.target)&&k(!1)}return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[y]);function w(){const C=x.trim();C&&C!==t.title?r(t.id,C):g(t.title||""),f(!1)}const S=q(C=>C.agents.find(_=>_.id===t.agentId)),M=(S==null?void 0:S.tokensUsed)||0,$=t.mode||"api";return e.jsxs("div",{className:"h-11 flex items-center gap-3 px-4 border-b border-border-subtle bg-surface-0/80 flex-shrink-0",children:[e.jsx(b2,{size:14,className:"text-text-4 flex-shrink-0"}),p?e.jsx("input",{ref:b,value:x,onChange:C=>g(C.target.value),onKeyDown:C=>{C.key==="Enter"&&w(),C.key==="Escape"&&(g(t.title||""),f(!1))},onBlur:w,className:"flex-1 min-w-0 bg-transparent text-sm font-semibold text-text-0 font-sans outline-none border-b border-accent",maxLength:100}):e.jsx("button",{onClick:()=>f(!0),className:"flex-1 min-w-0 text-left text-sm font-semibold text-text-0 font-sans truncate hover:text-accent transition-colors cursor-pointer",children:t.title||"New Chat"}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center h-7 rounded-lg bg-surface-3 border border-border-subtle p-0.5",children:[e.jsx($1,{content:"Lightweight — fast and cheap, no tools",side:"bottom",children:e.jsxs("button",{onClick:()=>c==null?void 0:c("api"),className:`flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-semibold font-sans transition-colors cursor-pointer ${$==="api"?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1"}`,children:[e.jsx(qt,{size:11})," Chat"]})}),e.jsx($1,{content:"Full agent — tools, files, session resume",side:"bottom",children:e.jsxs("button",{onClick:()=>c==null?void 0:c("agent"),className:`flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-semibold font-sans transition-colors cursor-pointer ${$==="agent"?"bg-purple/15 text-purple border border-purple/25":"text-text-3 hover:text-text-1"}`,children:[e.jsx(Ld,{size:11})," Agent"]})})]}),e.jsx(_Le,{value:a||{provider:t.provider,model:t.model},onChange:s,disabled:!1}),M>0&&e.jsxs("span",{className:"text-2xs text-text-3 font-mono",children:[Fe(M)," tokens"]}),e.jsxs("div",{ref:j,className:"relative",children:[e.jsx("button",{onClick:()=>k(!y),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-3 hover:text-text-1 hover:bg-surface-3 transition-colors cursor-pointer",children:e.jsx(Qo,{size:14})}),y&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-40 rounded-md border border-border bg-surface-1 shadow-xl z-50 py-1",children:[e.jsxs("button",{onClick:()=>{f(!0),k(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm text-text-1 hover:bg-surface-5 cursor-pointer font-sans",children:[e.jsx(ts,{size:12})," Rename"]}),e.jsxs("button",{onClick:()=>{l(t.id,!t.pinned),k(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm text-text-1 hover:bg-surface-5 cursor-pointer font-sans",children:[t.pinned?e.jsx(Ud,{size:12}):e.jsx(y1,{size:12}),t.pinned?"Unpin":"Pin"]}),e.jsx("div",{className:"h-px my-1 bg-border-subtle"}),e.jsxs("button",{onClick:()=>{u(t.id),k(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm text-danger hover:bg-danger/10 cursor-pointer font-sans",children:[e.jsx(wt,{size:12})," Delete"]})]})]})]})]})}const wX=["Reading through the codebase...","Thinking through your request...","Planning the approach...","Running tool calls...","Working through the problem...","Reasoning step by step...","Reviewing context...","Considering options...","Analyzing the code...","Making progress..."];function vB({agent:t,className:a}){const[s,c]=O.useState(0),[r,l]=O.useState(!0);return O.useEffect(()=>{const u=setInterval(()=>{l(!1),setTimeout(()=>{c(p=>(p+1)%wX.length),l(!0)},250)},2800);return()=>clearInterval(u)},[]),e.jsxs("div",{className:`${a||""}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-1 font-sans",children:(t==null?void 0:t.name)||"Agent"}),e.jsx("span",{className:"text-2xs text-accent font-mono",children:"thinking"})]}),e.jsxs("div",{className:"border-l border-accent/40 pl-3.5 py-1 flex items-center gap-2.5",children:[e.jsx("div",{className:"relative w-3.5 h-3.5 flex-shrink-0",children:e.jsx("span",{className:"absolute inset-0 rounded-full border border-transparent border-t-accent animate-spin",style:{animationDuration:"0.9s"}})}),e.jsx("span",{className:"text-[12px] font-sans text-text-3 transition-opacity duration-[250ms]",style:{opacity:r?1:0},children:wX[s]})]})]})}const MX=["Generating response...","Processing...","Thinking...","Almost there..."];function TLe({text:t}){const[a,s]=O.useState(!1);function c(){navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)})}return e.jsxs("button",{onClick:c,className:"flex items-center gap-1 px-2 py-1 text-2xs font-sans text-text-3 hover:text-text-1 transition-colors cursor-pointer",children:[a?e.jsx(Ve,{size:12,className:"text-success"}):e.jsx(Mn,{size:12}),a?"Copied":"Copy"]})}function PLe({language:t,code:a}){return e.jsxs("div",{className:"my-3 rounded-lg border border-border-subtle overflow-hidden bg-surface-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-3 border-b border-border-subtle",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3",children:t||"code"}),e.jsx(TLe,{text:a})]}),e.jsx("pre",{className:"px-4 py-3 overflow-x-auto",children:e.jsx("code",{className:"text-xs font-mono text-text-1 leading-relaxed whitespace-pre",children:a})})]})}function ALe(t){if(!t)return[];const a=t.split(`
8605
8605
  `),s=[];let c=0;for(;c<a.length;){const r=a[c];if(r.startsWith("```")){const p=r.slice(3).trim(),f=[];for(c++;c<a.length&&!a[c].startsWith("```");)f.push(a[c]),c++;c++,s.push({type:"code",language:p,code:f.join(`
8606
8606
  `)});continue}const l=r.match(/^(#{1,6})\s+(.+)/);if(l){s.push({type:"heading",level:l[1].length,text:l[2]}),c++;continue}if(/^(-{3,}|_{3,}|\*{3,})$/.test(r.trim())){s.push({type:"hr"}),c++;continue}if(r.startsWith("> ")){const p=[r.slice(2)];for(c++;c<a.length&&a[c].startsWith("> ");)p.push(a[c].slice(2)),c++;s.push({type:"blockquote",text:p.join(`
8607
8607
  `)});continue}if(/^[-*+]\s/.test(r)){const p=[r.replace(/^[-*+]\s/,"")];for(c++;c<a.length&&/^[-*+]\s/.test(a[c]);)p.push(a[c].replace(/^[-*+]\s/,"")),c++;s.push({type:"ul",items:p});continue}if(/^\d+\.\s/.test(r)){const p=[r.replace(/^\d+\.\s/,"")];for(c++;c<a.length&&/^\d+\.\s/.test(a[c]);)p.push(a[c].replace(/^\d+\.\s/,"")),c++;s.push({type:"ol",items:p});continue}if(r.includes("|")&&c+1<a.length&&/^\|?\s*[-:]+/.test(a[c+1])){const p=r.split("|").map(x=>x.trim()).filter(Boolean);c+=2;const f=[];for(;c<a.length&&a[c].includes("|");)f.push(a[c].split("|").map(x=>x.trim()).filter(Boolean)),c++;s.push({type:"table",headers:p,rows:f});continue}if(r.trim()===""){c++;continue}const u=[r];for(c++;c<a.length&&a[c].trim()!==""&&!a[c].startsWith("```")&&!a[c].startsWith("#")&&!/^[-*+]\s/.test(a[c])&&!/^\d+\.\s/.test(a[c])&&!a[c].startsWith("> ")&&!/^(-{3,}|_{3,}|\*{3,})$/.test(a[c].trim());)u.push(a[c]),c++;s.push({type:"paragraph",text:u.join(`