@damn-dev/cli 0.9.13 → 0.9.14

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.
@@ -128,7 +128,7 @@ Your target audience...
128
128
  `))+1))}const o="#".repeat(i),l=n.enter("headingAtx"),c=n.enter("phrasing");a.move(o+" ");let d=n.containerPhrasing(e,{before:"# ",after:`
129
129
  `,...a.current()});return/^[\t ]/.test(d)&&(d=Bp(d.charCodeAt(0))+d.slice(1)),d=d?o+" "+d:o,n.options.closeAtx&&(d+=" "+o),c(),l(),d}n$.peek=bve;function n$(e){return e.value||""}function bve(){return"<"}s$.peek=vve;function s$(e,t,n,s){const i=Rj(n),a=i==='"'?"Quote":"Apostrophe",o=n.enter("image");let l=n.enter("label");const c=n.createTracker(s);let d=c.move("![");return d+=c.move(n.safe(e.alt,{before:d,after:"]",...c.current()})),d+=c.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=n.enter("destinationLiteral"),d+=c.move("<"),d+=c.move(n.safe(e.url,{before:d,after:">",...c.current()})),d+=c.move(">")):(l=n.enter("destinationRaw"),d+=c.move(n.safe(e.url,{before:d,after:e.title?" ":")",...c.current()}))),l(),e.title&&(l=n.enter(`title${a}`),d+=c.move(" "+i),d+=c.move(n.safe(e.title,{before:d,after:i,...c.current()})),d+=c.move(i),l()),d+=c.move(")"),o(),d}function vve(){return"!"}i$.peek=yve;function i$(e,t,n,s){const i=e.referenceType,a=n.enter("imageReference");let o=n.enter("label");const l=n.createTracker(s);let c=l.move("![");const d=n.safe(e.alt,{before:c,after:"]",...l.current()});c+=l.move(d+"]["),o();const f=n.stack;n.stack=[],o=n.enter("reference");const p=n.safe(n.associationId(e),{before:c,after:"]",...l.current()});return o(),n.stack=f,a(),i==="full"||!d||d!==p?c+=l.move(p+"]"):i==="shortcut"?c=c.slice(0,-1):c+=l.move("]"),c}function yve(){return"!"}r$.peek=_ve;function r$(e,t,n){let s=e.value||"",i="`",a=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(s);)i+="`";for(/[^ \r\n]/.test(s)&&(/^[ \r\n]/.test(s)&&/[ \r\n]$/.test(s)||/^`|`$/.test(s))&&(s=" "+s+" ");++a<n.unsafe.length;){const o=n.unsafe[a],l=n.compilePattern(o);let c;if(o.atBreak)for(;c=l.exec(s);){let d=c.index;s.charCodeAt(d)===10&&s.charCodeAt(d-1)===13&&d--,s=s.slice(0,d)+" "+s.slice(c.index+1)}}return i+s+i}function _ve(){return"`"}function a$(e,t){const n=Sj(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}o$.peek=wve;function o$(e,t,n,s){const i=Rj(n),a=i==='"'?"Quote":"Apostrophe",o=n.createTracker(s);let l,c;if(a$(e,n)){const f=n.stack;n.stack=[],l=n.enter("autolink");let p=o.move("<");return p+=o.move(n.containerPhrasing(e,{before:p,after:">",...o.current()})),p+=o.move(">"),l(),n.stack=f,p}l=n.enter("link"),c=n.enter("label");let d=o.move("[");return d+=o.move(n.containerPhrasing(e,{before:d,after:"](",...o.current()})),d+=o.move("]("),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=n.enter("destinationLiteral"),d+=o.move("<"),d+=o.move(n.safe(e.url,{before:d,after:">",...o.current()})),d+=o.move(">")):(c=n.enter("destinationRaw"),d+=o.move(n.safe(e.url,{before:d,after:e.title?" ":")",...o.current()}))),c(),e.title&&(c=n.enter(`title${a}`),d+=o.move(" "+i),d+=o.move(n.safe(e.title,{before:d,after:i,...o.current()})),d+=o.move(i),c()),d+=o.move(")"),l(),d}function wve(e,t,n){return a$(e,n)?"<":"["}l$.peek=Ave;function l$(e,t,n,s){const i=e.referenceType,a=n.enter("linkReference");let o=n.enter("label");const l=n.createTracker(s);let c=l.move("[");const d=n.containerPhrasing(e,{before:c,after:"]",...l.current()});c+=l.move(d+"]["),o();const f=n.stack;n.stack=[],o=n.enter("reference");const p=n.safe(n.associationId(e),{before:c,after:"]",...l.current()});return o(),n.stack=f,a(),i==="full"||!d||d!==p?c+=l.move(p+"]"):i==="shortcut"?c=c.slice(0,-1):c+=l.move("]"),c}function Ave(){return"["}function Dj(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function Sve(e){const t=Dj(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function Cve(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function c$(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function jve(e,t,n,s){const i=n.enter("list"),a=n.bulletCurrent;let o=e.ordered?Cve(n):Dj(n);const l=e.ordered?o==="."?")":".":Sve(n);let c=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){const f=e.children?e.children[0]:void 0;if((o==="*"||o==="-")&&f&&(!f.children||!f.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(c=!0),c$(n)===o&&f){let p=-1;for(;++p<e.children.length;){const m=e.children[p];if(m&&m.type==="listItem"&&m.children&&m.children[0]&&m.children[0].type==="thematicBreak"){c=!0;break}}}}c&&(o=l),n.bulletCurrent=o;const d=n.containerFlow(e,s);return n.bulletLastUsed=o,n.bulletCurrent=a,i(),d}function Nve(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function kve(e,t,n,s){const i=Nve(n);let a=n.bulletCurrent||Dj(n);t&&t.type==="list"&&t.ordered&&(a=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+a);let o=a.length+1;(i==="tab"||i==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);const l=n.createTracker(s);l.move(a+" ".repeat(o-a.length)),l.shift(o);const c=n.enter("listItem"),d=n.indentLines(n.containerFlow(e,l.current()),f);return c(),d;function f(p,m,g){return m?(g?"":" ".repeat(o))+p:(g?a:a+" ".repeat(o-a.length))+p}}function Eve(e,t,n,s){const i=n.enter("paragraph"),a=n.enter("phrasing"),o=n.containerPhrasing(e,s);return a(),i(),o}const Fve=Wv(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function Tve(e,t,n,s){return(e.children.some(function(o){return Fve(o)})?n.containerPhrasing:n.containerFlow).call(n,e,s)}function Mve(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}u$.peek=Rve;function u$(e,t,n,s){const i=Mve(n),a=n.enter("strong"),o=n.createTracker(s),l=o.move(i+i);let c=o.move(n.containerPhrasing(e,{after:i,before:l,...o.current()}));const d=c.charCodeAt(0),f=C0(s.before.charCodeAt(s.before.length-1),d,i);f.inside&&(c=Bp(d)+c.slice(1));const p=c.charCodeAt(c.length-1),m=C0(s.after.charCodeAt(0),p,i);m.inside&&(c=c.slice(0,-1)+Bp(p));const g=o.move(i+i);return a(),n.attentionEncodeSurroundingInfo={after:m.outside,before:f.outside},l+c+g}function Rve(e,t,n){return n.options.strong||"*"}function Dve(e,t,n,s){return n.safe(e.value,s)}function Ove(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function Pve(e,t,n){const s=(c$(n)+(n.options.ruleSpaces?" ":"")).repeat(Ove(n));return n.options.ruleSpaces?s.slice(0,-1):s}const d$={blockquote:rve,break:sR,code:dve,definition:fve,emphasis:t$,hardBreak:sR,heading:gve,html:n$,image:s$,imageReference:i$,inlineCode:r$,link:o$,linkReference:l$,list:jve,listItem:kve,paragraph:Eve,root:Tve,strong:u$,text:Dve,thematicBreak:Pve};function Ive(){return{enter:{table:Lve,tableData:iR,tableHeader:iR,tableRow:zve},exit:{codeText:$ve,table:Bve,tableData:xA,tableHeader:xA,tableRow:xA}}}function Lve(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function Bve(e){this.exit(e),this.data.inTable=void 0}function zve(e){this.enter({type:"tableRow",children:[]},e)}function xA(e){this.exit(e)}function iR(e){this.enter({type:"tableCell",children:[]},e)}function $ve(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,Vve));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function Vve(e,t){return t==="|"?t:e}function Uve(e){const t=e||{},n=t.tableCellPadding,s=t.tablePipeAlign,i=t.stringLength,a=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
130
130
  `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:m,table:o,tableCell:c,tableRow:l}};function o(g,b,_,w){return d(f(g,_,w),g.align)}function l(g,b,_,w){const A=p(g,_,w),S=d([A]);return S.slice(0,S.indexOf(`
131
- `))}function c(g,b,_,w){const A=_.enter("tableCell"),S=_.enter("phrasing"),C=_.containerPhrasing(g,{...w,before:a,after:a});return S(),A(),C}function d(g,b){return nve(g,{align:b,alignDelimiters:s,padding:n,stringLength:i})}function f(g,b,_){const w=g.children;let A=-1;const S=[],C=b.enter("table");for(;++A<w.length;)S[A]=p(w[A],b,_);return C(),S}function p(g,b,_){const w=g.children;let A=-1;const S=[],C=b.enter("tableRow");for(;++A<w.length;)S[A]=c(w[A],g,b,_);return C(),S}function m(g,b,_){let w=d$.inlineCode(g,b,_);return _.stack.includes("tableCell")&&(w=w.replace(/\|/g,"\\$&")),w}}function Hve(){return{exit:{taskListCheckValueChecked:rR,taskListCheckValueUnchecked:rR,paragraph:qve}}}function Wve(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:Gve}}}function rR(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function qve(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const s=n.children[0];if(s&&s.type==="text"){const i=t.children;let a=-1,o;for(;++a<i.length;){const l=i[a];if(l.type==="paragraph"){o=l;break}}o===n&&(s.value=s.value.slice(1),s.value.length===0?n.children.shift():n.position&&s.position&&typeof s.position.start.offset=="number"&&(s.position.start.column++,s.position.start.offset++,n.position.start=Object.assign({},s.position.start)))}}this.exit(e)}function Gve(e,t,n,s){const i=e.children[0],a=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",l=n.createTracker(s);a&&l.move(o);let c=d$.listItem(e,t,n,{...s,...l.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,d)),c;function d(f){return f+o}}function Kve(){return[C0e(),q0e(),Q0e(),Ive(),Hve()]}function Yve(e){return{extensions:[j0e(),G0e(e),X0e(),Uve(e),Wve()]}}const Qve={tokenize:nye,partial:!0},h$={tokenize:sye,partial:!0},f$={tokenize:iye,partial:!0},p$={tokenize:rye,partial:!0},Xve={tokenize:aye,partial:!0},m$={name:"wwwAutolink",tokenize:eye,previous:g$},x$={name:"protocolAutolink",tokenize:tye,previous:b$},Ho={name:"emailAutolink",tokenize:Zve,previous:v$},Ga={};function Jve(){return{text:Ga}}let Ec=48;for(;Ec<123;)Ga[Ec]=Ho,Ec++,Ec===58?Ec=65:Ec===91&&(Ec=97);Ga[43]=Ho;Ga[45]=Ho;Ga[46]=Ho;Ga[95]=Ho;Ga[72]=[Ho,x$];Ga[104]=[Ho,x$];Ga[87]=[Ho,m$];Ga[119]=[Ho,m$];function Zve(e,t,n){const s=this;let i,a;return o;function o(p){return!XS(p)||!v$.call(s,s.previous)||Oj(s.events)?n(p):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(p))}function l(p){return XS(p)?(e.consume(p),l):p===64?(e.consume(p),c):n(p)}function c(p){return p===46?e.check(Xve,f,d)(p):p===45||p===95||Hs(p)?(a=!0,e.consume(p),c):f(p)}function d(p){return e.consume(p),i=!0,c}function f(p){return a&&i&&ii(s.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(p)):n(p)}}function eye(e,t,n){const s=this;return i;function i(o){return o!==87&&o!==119||!g$.call(s,s.previous)||Oj(s.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Qve,e.attempt(h$,e.attempt(f$,a),n),n)(o))}function a(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function tye(e,t,n){const s=this;let i="",a=!1;return o;function o(p){return(p===72||p===104)&&b$.call(s,s.previous)&&!Oj(s.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(p),e.consume(p),l):n(p)}function l(p){if(ii(p)&&i.length<5)return i+=String.fromCodePoint(p),e.consume(p),l;if(p===58){const m=i.toLowerCase();if(m==="http"||m==="https")return e.consume(p),c}return n(p)}function c(p){return p===47?(e.consume(p),a?d:(a=!0,c)):n(p)}function d(p){return p===null||_0(p)||Wt(p)||cu(p)||Vv(p)?n(p):e.attempt(h$,e.attempt(f$,f),n)(p)}function f(p){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(p)}}function nye(e,t,n){let s=0;return i;function i(o){return(o===87||o===119)&&s<3?(s++,e.consume(o),i):o===46&&s===3?(e.consume(o),a):n(o)}function a(o){return o===null?n(o):t(o)}}function sye(e,t,n){let s,i,a;return o;function o(d){return d===46||d===95?e.check(p$,c,l)(d):d===null||Wt(d)||cu(d)||d!==45&&Vv(d)?c(d):(a=!0,e.consume(d),o)}function l(d){return d===95?s=!0:(i=s,s=void 0),e.consume(d),o}function c(d){return i||s||!a?n(d):t(d)}}function iye(e,t){let n=0,s=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&s<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(p$,t,a)(o):o===null||Wt(o)||cu(o)?t(o):(e.consume(o),i)}function a(o){return o===41&&s++,e.consume(o),i}}function rye(e,t,n){return s;function s(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),s):l===38?(e.consume(l),a):l===93?(e.consume(l),i):l===60||l===null||Wt(l)||cu(l)?t(l):n(l)}function i(l){return l===null||l===40||l===91||Wt(l)||cu(l)?t(l):s(l)}function a(l){return ii(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),s):ii(l)?(e.consume(l),o):n(l)}}function aye(e,t,n){return s;function s(a){return e.consume(a),i}function i(a){return Hs(a)?n(a):t(a)}}function g$(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Wt(e)}function b$(e){return!ii(e)}function v$(e){return!(e===47||XS(e))}function XS(e){return e===43||e===45||e===46||e===95||Hs(e)}function Oj(e){let t=e.length,n=!1;for(;t--;){const s=e[t][1];if((s.type==="labelLink"||s.type==="labelImage")&&!s._balanced){n=!0;break}if(s._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const oye={tokenize:mye,partial:!0};function lye(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:hye,continuation:{tokenize:fye},exit:pye}},text:{91:{name:"gfmFootnoteCall",tokenize:dye},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:cye,resolveTo:uye}}}}function cye(e,t,n){const s=this;let i=s.events.length;const a=s.parser.gfmFootnotes||(s.parser.gfmFootnotes=[]);let o;for(;i--;){const c=s.events[i][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const d=ea(s.sliceSerialize({start:o.end,end:s.now()}));return d.codePointAt(0)!==94||!a.includes(d.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function uye(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const s={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},l=[e[n+1],e[n+2],["enter",s,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",a,t],["enter",o,t],["exit",o,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",s,t]];return e.splice(n,e.length-n+1,...l),e}function dye(e,t,n){const s=this,i=s.parser.gfmFootnotes||(s.parser.gfmFootnotes=[]);let a=0,o;return l;function l(p){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),c}function c(p){return p!==94?n(p):(e.enter("gfmFootnoteCallMarker"),e.consume(p),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",d)}function d(p){if(a>999||p===93&&!o||p===null||p===91||Wt(p))return n(p);if(p===93){e.exit("chunkString");const m=e.exit("gfmFootnoteCallString");return i.includes(ea(s.sliceSerialize(m)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(p)}return Wt(p)||(o=!0),a++,e.consume(p),p===92?f:d}function f(p){return p===91||p===92||p===93?(e.consume(p),a++,d):d(p)}}function hye(e,t,n){const s=this,i=s.parser.gfmFootnotes||(s.parser.gfmFootnotes=[]);let a,o=0,l;return c;function c(b){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),d}function d(b){return b===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",f):n(b)}function f(b){if(o>999||b===93&&!l||b===null||b===91||Wt(b))return n(b);if(b===93){e.exit("chunkString");const _=e.exit("gfmFootnoteDefinitionLabelString");return a=ea(s.sliceSerialize(_)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),m}return Wt(b)||(l=!0),o++,e.consume(b),b===92?p:f}function p(b){return b===91||b===92||b===93?(e.consume(b),o++,f):f(b)}function m(b){return b===58?(e.enter("definitionMarker"),e.consume(b),e.exit("definitionMarker"),i.includes(a)||i.push(a),vt(e,g,"gfmFootnoteDefinitionWhitespace")):n(b)}function g(b){return t(b)}}function fye(e,t,n){return e.check(Pm,t,e.attempt(oye,t,n))}function pye(e){e.exit("gfmFootnoteDefinition")}function mye(e,t,n){const s=this;return vt(e,i,"gfmFootnoteDefinitionIndent",5);function i(a){const o=s.events[s.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(a):n(a)}}function xye(e){let n=(e||{}).singleTilde;const s={name:"strikethrough",tokenize:a,resolveAll:i};return n==null&&(n=!0),{text:{126:s},insideSpan:{null:[s]},attentionMarkers:{null:[126]}};function i(o,l){let c=-1;for(;++c<o.length;)if(o[c][0]==="enter"&&o[c][1].type==="strikethroughSequenceTemporary"&&o[c][1]._close){let d=c;for(;d--;)if(o[d][0]==="exit"&&o[d][1].type==="strikethroughSequenceTemporary"&&o[d][1]._open&&o[c][1].end.offset-o[c][1].start.offset===o[d][1].end.offset-o[d][1].start.offset){o[c][1].type="strikethroughSequence",o[d][1].type="strikethroughSequence";const f={type:"strikethrough",start:Object.assign({},o[d][1].start),end:Object.assign({},o[c][1].end)},p={type:"strikethroughText",start:Object.assign({},o[d][1].end),end:Object.assign({},o[c][1].start)},m=[["enter",f,l],["enter",o[d][1],l],["exit",o[d][1],l],["enter",p,l]],g=l.parser.constructs.insideSpan.null;g&&tr(m,m.length,0,Uv(g,o.slice(d+1,c),l)),tr(m,m.length,0,[["exit",p,l],["enter",o[c][1],l],["exit",o[c][1],l],["exit",f,l]]),tr(o,d-1,c-d+3,m),c=d+m.length-2;break}}for(c=-1;++c<o.length;)o[c][1].type==="strikethroughSequenceTemporary"&&(o[c][1].type="data");return o}function a(o,l,c){const d=this.previous,f=this.events;let p=0;return m;function m(b){return d===126&&f[f.length-1][1].type!=="characterEscape"?c(b):(o.enter("strikethroughSequenceTemporary"),g(b))}function g(b){const _=Yd(d);if(b===126)return p>1?c(b):(o.consume(b),p++,g);if(p<2&&!n)return c(b);const w=o.exit("strikethroughSequenceTemporary"),A=Yd(b);return w._open=!A||A===2&&!!_,w._close=!_||_===2&&!!A,l(b)}}}class gye{constructor(){this.map=[]}add(t,n,s){bye(this,t,n,s)}consume(t){if(this.map.sort(function(a,o){return a[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const s=[];for(;n>0;)n-=1,s.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];s.push(t.slice()),t.length=0;let i=s.pop();for(;i;){for(const a of i)t.push(a);i=s.pop()}this.map.length=0}}function bye(e,t,n,s){let i=0;if(!(n===0&&s.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...s);return}i+=1}e.map.push([t,n,s])}}function vye(e,t){let n=!1;const s=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&s.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const a=s.length-1;s[a]=s[a]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return s}function yye(){return{flow:{null:{name:"table",tokenize:_ye,resolveAll:wye}}}}function _ye(e,t,n){const s=this;let i=0,a=0,o;return l;function l(R){let H=s.events.length-1;for(;H>-1;){const q=s.events[H][1].type;if(q==="lineEnding"||q==="linePrefix")H--;else break}const V=H>-1?s.events[H][1].type:null,K=V==="tableHead"||V==="tableRow"?T:c;return K===T&&s.parser.lazy[s.now().line]?n(R):K(R)}function c(R){return e.enter("tableHead"),e.enter("tableRow"),d(R)}function d(R){return R===124||(o=!0,a+=1),f(R)}function f(R){return R===null?n(R):qe(R)?a>1?(a=0,s.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(R),e.exit("lineEnding"),g):n(R):ht(R)?vt(e,f,"whitespace")(R):(a+=1,o&&(o=!1,i+=1),R===124?(e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),o=!0,f):(e.enter("data"),p(R)))}function p(R){return R===null||R===124||Wt(R)?(e.exit("data"),f(R)):(e.consume(R),R===92?m:p)}function m(R){return R===92||R===124?(e.consume(R),p):p(R)}function g(R){return s.interrupt=!1,s.parser.lazy[s.now().line]?n(R):(e.enter("tableDelimiterRow"),o=!1,ht(R)?vt(e,b,"linePrefix",s.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(R):b(R))}function b(R){return R===45||R===58?w(R):R===124?(o=!0,e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),_):k(R)}function _(R){return ht(R)?vt(e,w,"whitespace")(R):w(R)}function w(R){return R===58?(a+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(R),e.exit("tableDelimiterMarker"),A):R===45?(a+=1,A(R)):R===null||qe(R)?E(R):k(R)}function A(R){return R===45?(e.enter("tableDelimiterFiller"),S(R)):k(R)}function S(R){return R===45?(e.consume(R),S):R===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(R),e.exit("tableDelimiterMarker"),C):(e.exit("tableDelimiterFiller"),C(R))}function C(R){return ht(R)?vt(e,E,"whitespace")(R):E(R)}function E(R){return R===124?b(R):R===null||qe(R)?!o||i!==a?k(R):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(R)):k(R)}function k(R){return n(R)}function T(R){return e.enter("tableRow"),F(R)}function F(R){return R===124?(e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),F):R===null||qe(R)?(e.exit("tableRow"),t(R)):ht(R)?vt(e,F,"whitespace")(R):(e.enter("data"),M(R))}function M(R){return R===null||R===124||Wt(R)?(e.exit("data"),F(R)):(e.consume(R),R===92?I:M)}function I(R){return R===92||R===124?(e.consume(R),M):M(R)}}function wye(e,t){let n=-1,s=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],l=!1,c=0,d,f,p;const m=new gye;for(;++n<e.length;){const g=e[n],b=g[1];g[0]==="enter"?b.type==="tableHead"?(l=!1,c!==0&&(aR(m,t,c,d,f),f=void 0,c=0),d={type:"table",start:Object.assign({},b.start),end:Object.assign({},b.end)},m.add(n,0,[["enter",d,t]])):b.type==="tableRow"||b.type==="tableDelimiterRow"?(s=!0,p=void 0,a=[0,0,0,0],o=[0,n+1,0,0],l&&(l=!1,f={type:"tableBody",start:Object.assign({},b.start),end:Object.assign({},b.end)},m.add(n,0,[["enter",f,t]])),i=b.type==="tableDelimiterRow"?2:f?3:1):i&&(b.type==="data"||b.type==="tableDelimiterMarker"||b.type==="tableDelimiterFiller")?(s=!1,o[2]===0&&(a[1]!==0&&(o[0]=o[1],p=zg(m,t,a,i,void 0,p),a=[0,0,0,0]),o[2]=n)):b.type==="tableCellDivider"&&(s?s=!1:(a[1]!==0&&(o[0]=o[1],p=zg(m,t,a,i,void 0,p)),a=o,o=[a[1],n,0,0])):b.type==="tableHead"?(l=!0,c=n):b.type==="tableRow"||b.type==="tableDelimiterRow"?(c=n,a[1]!==0?(o[0]=o[1],p=zg(m,t,a,i,n,p)):o[1]!==0&&(p=zg(m,t,o,i,n,p)),i=0):i&&(b.type==="data"||b.type==="tableDelimiterMarker"||b.type==="tableDelimiterFiller")&&(o[3]=n)}for(c!==0&&aR(m,t,c,d,f),m.consume(t.events),n=-1;++n<t.events.length;){const g=t.events[n];g[0]==="enter"&&g[1].type==="table"&&(g[1]._align=vye(t.events,n))}return e}function zg(e,t,n,s,i,a){const o=s===1?"tableHeader":s===2?"tableDelimiter":"tableData",l="tableContent";n[0]!==0&&(a.end=Object.assign({},_d(t.events,n[0])),e.add(n[0],0,[["exit",a,t]]));const c=_d(t.events,n[1]);if(a={type:o,start:Object.assign({},c),end:Object.assign({},c)},e.add(n[1],0,[["enter",a,t]]),n[2]!==0){const d=_d(t.events,n[2]),f=_d(t.events,n[3]),p={type:l,start:Object.assign({},d),end:Object.assign({},f)};if(e.add(n[2],0,[["enter",p,t]]),s!==2){const m=t.events[n[2]],g=t.events[n[3]];if(m[1].end=Object.assign({},g[1].end),m[1].type="chunkText",m[1].contentType="text",n[3]>n[2]+1){const b=n[2]+1,_=n[3]-n[2]-1;e.add(b,_,[])}}e.add(n[3]+1,0,[["exit",p,t]])}return i!==void 0&&(a.end=Object.assign({},_d(t.events,i)),e.add(i,0,[["exit",a,t]]),a=void 0),a}function aR(e,t,n,s,i){const a=[],o=_d(t.events,n);i&&(i.end=Object.assign({},o),a.push(["exit",i,t])),s.end=Object.assign({},o),a.push(["exit",s,t]),e.add(n+1,0,a)}function _d(e,t){const n=e[t],s=n[0]==="enter"?"start":"end";return n[1][s]}const Aye={name:"tasklistCheck",tokenize:Cye};function Sye(){return{text:{91:Aye}}}function Cye(e,t,n){const s=this;return i;function i(c){return s.previous!==null||!s._gfmTasklistFirstContentOfListItem?n(c):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),a)}function a(c){return Wt(c)?(e.enter("taskListCheckValueUnchecked"),e.consume(c),e.exit("taskListCheckValueUnchecked"),o):c===88||c===120?(e.enter("taskListCheckValueChecked"),e.consume(c),e.exit("taskListCheckValueChecked"),o):n(c)}function o(c){return c===93?(e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),l):n(c)}function l(c){return qe(c)?t(c):ht(c)?e.check({tokenize:jye},t,n)(c):n(c)}}function jye(e,t,n){return vt(e,s,"whitespace");function s(i){return i===null?n(i):t(i)}}function Nye(e){return Fz([Jve(),lye(),xye(e),yye(),Sye()])}const kye={};function Fi(e){const t=this,n=e||kye,s=t.data(),i=s.micromarkExtensions||(s.micromarkExtensions=[]),a=s.fromMarkdownExtensions||(s.fromMarkdownExtensions=[]),o=s.toMarkdownExtensions||(s.toMarkdownExtensions=[]);i.push(Nye(n)),a.push(Kve()),o.push(Yve(n))}const Eye={"MEMORY.md":"Written by the agent. Edits may be overwritten.","KNOWLEDGE.md":"Distilled learning. Edits may be overwritten by reflection.","REFLEXION.md":"Earned constraints from failures. Edits may be overwritten.","HEARTBEAT.md":"Controls periodic agent behavior.","TOOLS.md":"Your local environment notes.","USER.md":"What the agent knows about you."},Fye={"CONTEXT.md":"Injected into every agent call in this channel.","NOTES.md":"Your notes. Not shared with agents."};function Tye({agentId:e,filename:t,onClose:n}){const{data:s}=pj(e),i=L.useUtils(),{data:a,isLoading:o,error:l}=L.agents.getFile.useQuery({agentId:e,filename:t},{retry:!1}),[c,d]=y.useState(!1),[f,p]=y.useState(""),[m,g]=y.useState(!1),[b,_]=y.useState(!1),[w,A]=y.useState(!1),S=y.useRef(null);y.useEffect(()=>{a&&a.content===""&&(p(""),d(!0))},[a]);const C=L.agents.setFile.useMutation({onSuccess:()=>{_(!0),setTimeout(()=>_(!1),1500),i.agents.getFile.invalidate({agentId:e,filename:t}),i.agents.listFiles.invalidate({agentId:e}),d(!1)}}),E=L.agents.resetFile.useMutation({onSuccess:V=>{i.agents.getFile.invalidate({agentId:e,filename:t}),A(!0),g(!1),setTimeout(()=>A(!1),1500),p(V.content),d(!1)}});function k(){p(a?.content??""),d(!0),setTimeout(()=>S.current?.focus(),50)}function T(){C.mutate({agentId:e,filename:t,content:f})}function F(){d(!1),p("")}function M(){if(!m){g(!0);return}E.mutate({agentId:e,filename:t})}const I=Eye[t],R=a?.hasDefault??!1,H=a?.content??"";return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35] flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s&&r.jsx("span",{className:"text-base flex-shrink-0",children:s.emoji}),r.jsxs("span",{className:"text-[13px] font-semibold text-[#F0F0F5] truncate",children:[s?.name??e," — ",t]})]}),r.jsx("button",{onClick:n,className:"w-6 h-6 flex items-center justify-center rounded text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors flex-shrink-0 ml-2",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),I&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:I})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[o&&r.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-4 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]}),l&&r.jsx("p",{className:"px-4 py-4 text-[13px] text-[#EF4444] italic",children:"Failed to load file."}),!o&&!l&&!c&&r.jsx("div",{className:"px-4 py-4 prose-message text-[13px]",children:H?r.jsx(Ei,{remarkPlugins:[Fi],children:H}):r.jsx("p",{className:"text-[#5A5A6E] italic",children:"Empty file."})}),!o&&!l&&c&&r.jsx("textarea",{ref:S,value:f,onChange:V=>p(V.target.value),onKeyDown:V=>{V.key==="Enter"&&V.metaKey&&(V.preventDefault(),T())},className:"w-full h-full min-h-[300px] bg-[#13131A] text-[#F0F0F5] text-[13px] font-mono px-4 py-4 resize-none outline-none border-none",spellCheck:!1})]}),r.jsxs("div",{className:"px-4 py-3 border-t border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsx("div",{className:"flex items-center gap-2",children:r.jsxs(Me,{mode:"wait",children:[b&&r.jsxs(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[12px] text-[#10B981] flex items-center gap-1",children:[r.jsx(Fe,{className:"w-3 h-3"})," Saved"]},"saved"),w&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[12px] text-[#F59E0B]",children:"Reset"},"reset")]})}),r.jsxs("div",{className:"flex items-center gap-2",children:[!c&&R&&!m&&r.jsxs("button",{onClick:M,disabled:E.isPending,className:"flex items-center gap-1 px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors disabled:opacity-40",children:[r.jsx(lh,{className:"w-3 h-3"}),"Reset"]}),m&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:["Reset ",t,"?"]}),r.jsx("button",{onClick:M,disabled:E.isPending,className:"px-2.5 py-1.5 rounded text-[12px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-40",children:"Confirm"}),r.jsx("button",{onClick:()=>g(!1),className:"px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:"Cancel"})]}),!c&&!m&&r.jsxs("button",{onClick:k,className:"flex items-center gap-1 px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:[r.jsx(oh,{className:"w-3 h-3"}),"Edit"]}),c&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:F,className:"px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:"Cancel"}),r.jsx("button",{onClick:T,disabled:C.isPending,className:"px-3 py-1.5 rounded text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5558E8] transition-colors disabled:opacity-40",children:C.isPending?"Saving...":"Save"}),r.jsx("kbd",{className:"text-[10px] bg-white/5 border border-[#2A2A35] px-1.5 py-0.5 rounded text-[#5A5A6E]",children:"⌘↵"})]})]})]})]})}function Mye({channelId:e,filename:t,onClose:n}){const{data:s}=ez(e),i=L.useUtils(),{data:a,isLoading:o,error:l}=L.channels.getFile.useQuery({channelId:e,filename:t},{retry:!1}),[c,d]=y.useState(!1),[f,p]=y.useState(""),[m,g]=y.useState(!1),b=y.useRef(null);y.useEffect(()=>{a!==void 0&&a.content===""&&(p(""),d(!0))},[a]);const _=L.channels.setFile.useMutation({onSuccess:()=>{g(!0),setTimeout(()=>g(!1),1500),i.channels.getFile.invalidate({channelId:e,filename:t}),i.channels.listFiles.invalidate({channelId:e}),d(!1)}});function w(){p(a?.content??""),d(!0),setTimeout(()=>b.current?.focus(),50)}function A(){_.mutate({channelId:e,filename:t,content:f})}function S(){d(!1),p("")}const C=Fye[t],E=a?.content??"";return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35] flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(Tp,{className:"w-3.5 h-3.5 text-[#8A8A99] flex-shrink-0"}),r.jsxs("span",{className:"text-[13px] font-semibold text-[#F0F0F5] truncate",children:[s?.name??e," — ",t]})]}),r.jsx("button",{onClick:n,className:"w-6 h-6 flex items-center justify-center rounded text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors flex-shrink-0 ml-2",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),C&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:C})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[o&&r.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-4 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]}),l&&r.jsx("p",{className:"px-4 py-4 text-[13px] text-[#EF4444] italic",children:"Failed to load file."}),!o&&!l&&!c&&r.jsx("div",{className:"px-4 py-4 prose-message text-[13px]",children:E?r.jsx(Ei,{remarkPlugins:[Fi],children:E}):r.jsx("p",{className:"text-[#5A5A6E] italic",children:"Empty file."})}),!o&&!l&&c&&r.jsx("textarea",{ref:b,value:f,onChange:k=>p(k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.metaKey&&(k.preventDefault(),A())},className:"w-full h-full min-h-[300px] bg-[#13131A] text-[#F0F0F5] text-[13px] font-mono px-4 py-4 resize-none outline-none border-none",spellCheck:!1})]}),r.jsxs("div",{className:"px-4 py-3 border-t border-[#2A2A35] flex items-center justify-end flex-shrink-0 gap-2",children:[r.jsx(Me,{mode:"wait",children:m&&r.jsxs(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[12px] text-[#10B981] flex items-center gap-1 mr-auto",children:[r.jsx(Fe,{className:"w-3 h-3"})," Saved"]},"saved")}),!c&&r.jsxs("button",{onClick:w,className:"flex items-center gap-1 px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:[r.jsx(oh,{className:"w-3 h-3"}),"Edit"]}),c&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:S,className:"px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:"Cancel"}),r.jsx("button",{onClick:A,disabled:_.isPending,className:"px-3 py-1.5 rounded text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5558E8] transition-colors disabled:opacity-40",children:_.isPending?"Saving...":"Save"}),r.jsx("kbd",{className:"text-[10px] bg-white/5 border border-[#2A2A35] px-1.5 py-0.5 rounded text-[#5A5A6E]",children:"⌘↵"})]})]})]})}function Rye(){const{agentId:e,channelId:t,entityType:n,filename:s,close:i}=y0(),a=!!s&&!!n;return y.useEffect(()=>{if(!a)return;function o(l){l.key==="Escape"&&i()}return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[a,i]),r.jsx(Me,{children:a&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-[55]",onClick:i}),r.jsxs(ne.div,{initial:{x:-380},animate:{x:0},exit:{x:-380},transition:{duration:.15,ease:"easeOut"},className:"fixed top-0 h-screen w-[380px] bg-[#1C1C24] border-r border-[#2A2A35] flex flex-col z-[55] shadow-xl",style:{left:240},onClick:o=>o.stopPropagation(),children:[n==="agent"&&e&&s&&r.jsx(Tye,{agentId:e,filename:s,onClose:i}),n==="channel"&&t&&s&&r.jsx(Mye,{channelId:t,filename:s,onClose:i})]})]})})}const Dye={high:"#EF4444",normal:"#F59E0B",low:"#6366F1"},Oye={shell_exec:Ti,trust_config:Wl,skill_install:vL,file_edit:li,delegation_rule:Wl,generic:yL};function Pye({priority:e}){return r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:Dye[e]??"#5A5A6E"}})}function Iye({expiresAt:e}){if(!e)return null;const t=new Date(e).getTime()-Date.now();if(t<=0)return r.jsx("span",{className:"text-[10px] text-[#EF4444]",children:"Expired"});const n=Math.floor(t/36e5),s=Math.floor(t%36e5/6e4),i=n>0?`${n}h ${s}m`:`${s}m`;return r.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-[#5A5A6E]",children:[r.jsx(bm,{className:"w-2.5 h-2.5"}),i]})}const Pj={pending:"#F59E0B",working:"#6366F1",input_needed:"#8B5CF6",completed:"#10B981",failed:"#EF4444",cancelled:"#5A5A6E"},y$={pending:"○",working:"⏳",input_needed:"❓",completed:"✅",failed:"⚠️",cancelled:"🛑",blocked:"🚫"};function Lye(e,t){const n=e??t,s=Date.now()-new Date(n).getTime(),i=Math.floor(s/1e3);if(i<60)return`${i}s`;const a=Math.floor(i/60);return a<60?`${a}m`:`${Math.floor(a/60)}h ${a%60}m`}function _$(e){const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function w$({node:e,navigate:t,depth:n=0}){const s=e.children.length>1,i=Pj[e.status]??"#5A5A6E";return r.jsxs("div",{className:n>0?"ml-4 border-l border-[#2A2A35] pl-3":"",children:[r.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[r.jsx("span",{className:"text-[12px]",children:y$[e.status]??"•"}),r.jsxs("div",{className:"flex items-center gap-1",children:[e.toAgent&&r.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] flex-shrink-0",style:{backgroundColor:`${e.toAgent.color}26`},children:e.toAgent.emoji}),r.jsx("span",{className:"text-[11px] font-medium text-[#F0F0F5]",children:e.toAgent?.name??e.toAgentId})]}),r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:i}}),e.crossInstance&&r.jsx(Xt,{className:"w-2.5 h-2.5 text-[#A78BFA] flex-shrink-0"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:e.status.replace("_"," ")}),e.targetChannelId&&r.jsx("button",{onClick:()=>t(`/channels/${e.targetChannelId}`),className:"opacity-0 group-hover:opacity-100 transition-opacity text-[#5A5A6E] hover:text-[#8A8A99]",children:r.jsx(cs,{className:"w-2.5 h-2.5"})})]}),r.jsx("p",{className:"text-[10px] text-[#8A8A99] line-clamp-1 ml-6 mb-1",children:e.task}),e.crossInstance&&e.status==="failed"&&e.task.includes("cross-instance")&&r.jsx("p",{className:"text-[10px] text-[#A78BFA] ml-6 mb-1",children:"(cross-instance disabled)"}),s&&r.jsx("div",{className:"ml-6 mb-1",children:r.jsx("span",{className:"text-[9px] text-[#5A5A6E] uppercase tracking-wider",children:"parallel"})}),e.children.map(a=>r.jsx(w$,{node:a,navigate:t,depth:n+1},a.id))]})}function A$({taskId:e,navigate:t}){const{data:n,isLoading:s}=L.agentTasks.getChain.useQuery({taskId:e});return s?r.jsx("div",{className:"py-2 text-[11px] text-[#5A5A6E]",children:"Loading chain..."}):n?r.jsxs("div",{className:"py-2 px-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Zl,{className:"w-3 h-3 text-[#6366F1]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99]",children:"Task Chain"})]}),r.jsx(w$,{node:n,navigate:t})]}):r.jsx("div",{className:"py-2 text-[11px] text-[#5A5A6E]",children:"Chain not found"})}function Bye(){const{data:e}=L.agentTasks.stats.useQuery(void 0,{staleTime:3e4});return!e||e.totalTasks===0?null:r.jsxs("div",{className:"px-5 py-3 border-b border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(M5,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Delegation Stats"})]}),r.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[r.jsxs("div",{className:"bg-[#1C1C24] rounded-lg px-2.5 py-2 border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[16px] font-semibold text-[#F0F0F5]",children:e.totalTasks}),r.jsx("p",{className:"text-[9px] text-[#5A5A6E] uppercase",children:"Total"})]}),r.jsxs("div",{className:"bg-[#1C1C24] rounded-lg px-2.5 py-2 border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[16px] font-semibold text-[#6366F1]",children:e.activeTasks}),r.jsx("p",{className:"text-[9px] text-[#5A5A6E] uppercase",children:"Active"})]}),r.jsxs("div",{className:"bg-[#1C1C24] rounded-lg px-2.5 py-2 border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[16px] font-semibold text-[#10B981]",children:e.completedTasks}),r.jsx("p",{className:"text-[9px] text-[#5A5A6E] uppercase",children:"Done"})]}),r.jsxs("div",{className:"bg-[#1C1C24] rounded-lg px-2.5 py-2 border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[16px] font-semibold text-[#EF4444]",children:e.failedTasks}),r.jsx("p",{className:"text-[9px] text-[#5A5A6E] uppercase",children:"Failed"})]})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[10px] text-[#5A5A6E]",children:[e.avgDurationMs!=null&&r.jsxs("span",{children:["Avg: ",_$(e.avgDurationMs)]}),e.totalTokensUsed>0&&r.jsxs("span",{children:[e.totalTokensUsed.toLocaleString()," tokens"]}),e.crossInstanceTasks.total>0&&r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx(Xt,{className:"w-2.5 h-2.5"}),e.crossInstanceTasks.total," cross-instance"]})]})]})}function zye({navigate:e}){const{data:t=[],isLoading:n}=L.agentTasks.active.useQuery(void 0,{refetchInterval:5e3}),s=L.agentTasks.cancel.useMutation(),[i,a]=y.useState(new Set);if(n||t.length===0)return null;function o(l){a(c=>{const d=new Set(c);return d.has(l)?d.delete(l):d.add(l),d})}return r.jsxs("div",{className:"border-b border-[#2A2A35]",children:[r.jsxs("div",{className:"px-5 py-3 flex items-center gap-2",children:[r.jsx(cse,{className:"w-3.5 h-3.5 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] font-semibold text-[#F0F0F5]",children:"Active Tasks"}),r.jsx("span",{className:"bg-[#6366F1] text-white text-[10px] font-bold rounded-full min-w-[18px] h-[18px] flex items-center justify-center px-1 leading-none",children:t.length})]}),t.map(l=>r.jsxs("div",{className:"px-5 py-2.5 hover:bg-white/[0.02] transition-colors border-t border-[#2A2A35]/30",children:[r.jsxs("div",{className:"flex items-start gap-2.5",children:[r.jsxs("div",{className:"flex -space-x-1.5 flex-shrink-0 mt-0.5",children:[l.fromAgent&&r.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center text-[11px] border border-[#13131A]",style:{backgroundColor:`${l.fromAgent.color}26`},title:l.fromAgent.name,children:l.fromAgent.emoji}),l.toAgent&&r.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center text-[11px] border border-[#13131A]",style:{backgroundColor:`${l.toAgent.color}26`},title:l.toAgent.name,children:l.toAgent.emoji})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[r.jsxs("span",{className:"text-[11px] font-medium text-[#F0F0F5] truncate",children:[l.fromAgent?.name??l.fromAgentId," → ",l.toAgent?.name??l.toAgentId]}),r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:Pj[l.status]??"#5A5A6E"}}),l.crossInstance&&r.jsx(Xt,{className:"w-2.5 h-2.5 text-[#A78BFA] flex-shrink-0"})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] line-clamp-1",children:l.task}),r.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:[Lye(l.startedAt,l.createdAt)," · depth ",l.depth," · ",l.status.replace("_"," ")]}),l.parentTaskId&&r.jsxs("button",{onClick:c=>{c.stopPropagation(),o(l.id)},className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors",children:[r.jsx(Zl,{className:"w-2.5 h-2.5"}),"Chain"]}),r.jsxs("button",{onClick:c=>{c.stopPropagation(),s.mutate({taskId:l.id})},disabled:s.isPending,className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-40 ml-auto",children:[r.jsx(L5,{className:"w-2.5 h-2.5"}),"Cancel"]}),l.channelId&&r.jsx("button",{onClick:()=>e(`/channels/${l.channelId}`),className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/[0.04] transition-colors",children:r.jsx(cs,{className:"w-2.5 h-2.5"})})]})]})]}),r.jsx(Me,{children:i.has(l.id)&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden ml-8 mt-1 border-l border-[#2A2A35] pl-3",children:r.jsx(A$,{taskId:l.id,navigate:e})})})]},l.id))]})}function $ye({navigate:e}){const[t,n]=y.useState(!1),[s,i]=y.useState(new Set),{data:a}=L.agentTasks.list.useQuery({status:"completed",limit:10},{staleTime:3e4}),{data:o}=L.agentTasks.list.useQuery({status:"failed",limit:10},{staleTime:3e4}),l=a?.items??[],d=[...o?.items??[],...l].sort((p,m)=>m.createdAt.localeCompare(p.createdAt)).slice(0,10);if(d.length===0)return null;function f(p){i(m=>{const g=new Set(m);return g.has(p)?g.delete(p):g.add(p),g})}return r.jsxs("div",{className:"border-b border-[#2A2A35]",children:[r.jsxs("button",{onClick:()=>n(p=>!p),className:"w-full px-5 py-2.5 flex items-center gap-2 hover:bg-white/[0.02] transition-colors",children:[t?r.jsx(ah,{className:"w-3 h-3 text-[#5A5A6E]"}):r.jsx(ft,{className:"w-3 h-3 text-[#5A5A6E]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:"Recent Completed/Failed"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:d.length})]}),r.jsx(Me,{children:t&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:d.map(p=>r.jsxs("div",{className:"px-5 py-2 hover:bg-white/[0.02] transition-colors border-t border-[#2A2A35]/30",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[10px]",children:y$[p.status]??"•"}),r.jsxs("div",{className:"flex -space-x-1.5 flex-shrink-0",children:[p.fromAgent&&r.jsx("span",{className:"text-[10px]",children:p.fromAgent.emoji}),r.jsx("span",{className:"text-[9px] text-[#5A5A6E] mx-0.5",children:"→"}),p.toAgent&&r.jsx("span",{className:"text-[10px]",children:p.toAgent.emoji})]}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] flex-1 truncate",children:p.task}),p.crossInstance&&r.jsx(Xt,{className:"w-2.5 h-2.5 text-[#A78BFA] flex-shrink-0"}),p.completedAt&&p.startedAt&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:_$(new Date(p.completedAt).getTime()-new Date(p.startedAt).getTime())}),p.parentTaskId&&r.jsx("button",{onClick:m=>{m.stopPropagation(),f(p.id)},className:"text-[#6366F1] hover:bg-[#6366F1]/10 rounded p-0.5 transition-colors",children:r.jsx(Zl,{className:"w-2.5 h-2.5"})}),p.channelId&&r.jsx("button",{onClick:()=>e(`/channels/${p.channelId}`),className:"text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:r.jsx(cs,{className:"w-2.5 h-2.5"})})]}),r.jsx(Me,{children:s.has(p.id)&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden ml-6 mt-1",children:r.jsx(A$,{taskId:p.id,navigate:e})})})]},p.id))})})]})}function Vye(){const[e,t]=y.useState(!1),[n,s]=y.useState("all"),{data:i=[]}=L.agentTasks.crossInstanceAudit.useQuery({limit:50,decision:n==="all"?void 0:n},{staleTime:3e4});return i.length===0&&n==="all"?null:r.jsxs("div",{className:"border-b border-[#2A2A35]",children:[r.jsxs("button",{onClick:()=>t(a=>!a),className:"w-full px-5 py-2.5 flex items-center gap-2 hover:bg-white/[0.02] transition-colors",children:[e?r.jsx(ah,{className:"w-3 h-3 text-[#A78BFA]"}):r.jsx(ft,{className:"w-3 h-3 text-[#A78BFA]"}),r.jsx(Xt,{className:"w-3 h-3 text-[#A78BFA]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#A78BFA] uppercase tracking-widest",children:"Cross-Instance Audit"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:i.length})]}),r.jsx(Me,{children:e&&r.jsxs(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:[r.jsx("div",{className:"flex gap-1 px-5 py-1.5",children:["all","allowed","blocked"].map(a=>r.jsx("button",{onClick:()=>s(a),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${n===a?"bg-[#A78BFA] text-white":"bg-white/5 text-[#8A8A99] hover:text-[#C8C8D4]"}`,children:a},a))}),i.map(a=>r.jsxs("div",{className:"px-5 py-2 hover:bg-white/[0.02] transition-colors border-t border-[#2A2A35]/30",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-medium ${a.decision==="allowed"?"bg-[#10B981]/10 text-[#10B981]":"bg-[#EF4444]/10 text-[#EF4444]"}`,children:a.decision}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a.fromAgent&&r.jsx("span",{className:"text-[10px]",children:a.fromAgent.emoji}),r.jsx("span",{className:"text-[9px] text-[#5A5A6E]",children:"→"}),a.toAgent&&r.jsx("span",{className:"text-[10px]",children:a.toAgent.emoji})]}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] flex-1 truncate",children:a.taskSummary}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] flex-shrink-0",children:Ir(a.timestamp)}),a.status!=="blocked"&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:Pj[a.status]??"#5A5A6E"}})]}),r.jsxs("div",{className:"flex items-center gap-1 mt-0.5 ml-14",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:a.fromAgent?.name??a.fromAgentId}),r.jsx("span",{className:"text-[9px] text-[#5A5A6E]",children:"→"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:a.toAgent?.name??a.toAgentId})]})]},a.id)),i.length===0&&r.jsx("p",{className:"px-5 py-3 text-[11px] text-[#5A5A6E] italic",children:"No cross-instance delegations found."})]})})]})}function Uye({onClose:e}){const t=an(),n=L.useUtils(),[s,i]=y.useState(new Set),[a,o]=y.useState(null),[l,c]=y.useState(""),[d,f]=y.useState(!1),[p,m]=y.useState(""),[g,b]=y.useState(new Set),{data:_,isLoading:w}=L.approvals.list.useQuery({status:"pending"},{refetchInterval:1e4}),A=L.approvals.decide.useMutation({onSuccess:()=>{n.approvals.list.invalidate(),n.approvals.pendingCount.invalidate()}}),S=L.approvals.batchApprove.useMutation({onSuccess:()=>{i(new Set),n.approvals.list.invalidate(),n.approvals.pendingCount.invalidate()}}),C=L.approvals.batchReject.useMutation({onSuccess:()=>{i(new Set),f(!1),m(""),n.approvals.list.invalidate(),n.approvals.pendingCount.invalidate()}}),E=[..._?.items??[]].sort(($,B)=>B.createdAt.localeCompare($.createdAt)),k=E.filter($=>$.messageId).map($=>$.messageId),T=[...s].filter($=>k.includes($));function F($){i(B=>{const Y=new Set(B);return Y.has($)?Y.delete($):Y.add($),Y})}function M(){s.size===k.length?i(new Set):i(new Set(k))}function I($){A.mutate({messageId:$,decision:"approved"})}function R($){A.mutate({messageId:$,decision:"rejected",rejectionNote:l||void 0}),o(null),c("")}function H(){T.length!==0&&S.mutate({messageIds:T})}function V(){T.length!==0&&C.mutate({messageIds:T,rejectionNote:p||void 0})}function K($){b(B=>{const Y=new Set(B);return Y.has($)?Y.delete($):Y.add($),Y})}function q($){t(`/channels/${$}`),e()}return r.jsxs(r.Fragment,{children:[r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-40",style:{backdropFilter:"blur(2px)",backgroundColor:"rgba(0,0,0,0.25)"},onClick:e}),r.jsxs(ne.div,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.3,ease:[.16,1,.3,1]},className:"fixed right-0 top-0 h-screen w-[420px] bg-[#13131A] border-l border-[#2A2A35] flex flex-col z-50 shadow-2xl",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2.5",children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Pending Approvals"}),E.length>0&&r.jsx("span",{className:"bg-[#EF4444] text-white text-[10px] font-bold rounded-full min-w-[18px] h-[18px] flex items-center justify-center px-1 leading-none",children:E.length})]}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),T.length>0&&r.jsx("div",{className:"px-5 py-3 border-b border-[#2A2A35]/50 flex flex-col gap-2 flex-shrink-0",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-[12px] text-[#8A8A99]",children:[T.length," selected"]}),r.jsxs("button",{onClick:H,disabled:S.isPending,className:"flex items-center gap-1 px-2.5 py-1 rounded-md bg-[#10B981]/15 text-[#10B981] text-[11px] font-medium hover:bg-[#10B981]/25 transition-colors disabled:opacity-40",children:[r.jsx(Fe,{className:"w-3 h-3"}),"Approve ",T.length]}),d?r.jsxs("div",{className:"flex items-center gap-1.5 flex-1",children:[r.jsx("input",{value:p,onChange:$=>m($.target.value),placeholder:"Reason (optional)",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-md px-2 py-1 text-[11px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#EF4444]/40",onKeyDown:$=>{$.key==="Enter"&&V()},autoFocus:!0}),r.jsx("button",{onClick:V,disabled:C.isPending,className:"px-2 py-1 rounded-md bg-[#EF4444]/15 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/25 transition-colors disabled:opacity-40",children:"Reject"}),r.jsx("button",{onClick:()=>{f(!1),m("")},className:"text-[11px] text-[#5A5A6E] hover:text-[#8A8A99]",children:"Cancel"})]}):r.jsxs("button",{onClick:()=>f(!0),className:"flex items-center gap-1 px-2.5 py-1 rounded-md bg-[#EF4444]/15 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/25 transition-colors",children:[r.jsx(Te,{className:"w-3 h-3"}),"Reject ",T.length]})]})}),r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[r.jsx(Bye,{}),r.jsx(zye,{navigate:t}),r.jsx($ye,{navigate:t}),r.jsx(Vye,{}),w?r.jsx("div",{className:"flex items-center justify-center py-16",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):E.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-white/[0.03] border border-[#2A2A35] flex items-center justify-center mb-3",children:r.jsx(Fe,{className:"w-4 h-4 text-[#5A5A6E]"})}),r.jsx("p",{className:"text-[13px] text-[#5A5A6E]",children:"No pending approvals"})]}):r.jsxs(r.Fragment,{children:[k.length>1&&r.jsx("div",{className:"px-5 py-2 sticky top-0 z-10 bg-[#13131A]",children:r.jsxs("label",{className:"flex items-center gap-2 text-[11px] text-[#5A5A6E] cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:s.size>0&&s.size===k.length,onChange:M,className:"accent-[#6366F1] w-3.5 h-3.5"}),"Select all"]})}),r.jsx(Me,{initial:!1,children:E.map($=>{const B=Oye[$.type]??yL,Y=a===($.messageId??$.id),U=g.has($.id);return r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:{duration:.15},className:"border-b border-[#2A2A35]/40",children:r.jsx("div",{className:"px-5 py-3 hover:bg-white/[0.02] transition-colors",children:r.jsxs("div",{className:"flex items-start gap-2.5",children:[$.messageId&&r.jsx("input",{type:"checkbox",checked:s.has($.messageId),onChange:()=>F($.messageId),className:"accent-[#6366F1] w-3.5 h-3.5 mt-1 flex-shrink-0"}),r.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center flex-shrink-0",style:{backgroundColor:$.agentColor?`${$.agentColor}15`:"rgba(99, 102, 241, 0.1)"},children:$.agentEmoji?r.jsx("span",{className:"text-xs",children:$.agentEmoji}):r.jsx(B,{className:"w-3.5 h-3.5 text-[#8A8A99]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5] truncate",children:$.agentName??"Agent"}),r.jsx(Pye,{priority:$.priority}),r.jsx(Iye,{expiresAt:$.expiresAt}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] ml-auto flex-shrink-0",children:Ir($.createdAt)})]}),$.type==="delegation_rule"&&$.payload?(()=>{try{const W=JSON.parse($.payload);return r.jsxs("div",{className:"mb-1.5",children:[r.jsxs("p",{className:"text-[12px] text-[#C8C8D4] leading-relaxed mb-1",children:["COO wants to create a delegation rule: Auto-approve ",r.jsx("code",{className:"text-[#6366F1] bg-[#6366F1]/10 px-1 rounded text-[11px]",children:W.pattern})," for ",r.jsx("span",{className:"text-[#F0F0F5] font-medium",children:W.agentId})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] italic mb-1",children:W.reason}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] leading-relaxed",children:["Future ",r.jsx("code",{className:"text-[#5A5A6E]",children:W.pattern})," actions from ",W.agentId," will be automatically approved without your review."]})]})}catch{return null}})():r.jsxs(r.Fragment,{children:[r.jsx("p",{className:`text-[12px] text-[#C8C8D4] leading-relaxed mb-1 whitespace-pre-wrap ${U?"":"line-clamp-2"}`,children:$.content}),$.content.length>100&&r.jsxs("button",{onClick:()=>K($.id),className:"flex items-center gap-0.5 text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors mb-1.5",children:[U?r.jsx(ah,{className:"w-2.5 h-2.5"}):r.jsx(ft,{className:"w-2.5 h-2.5"}),U?"Less":"More"]})]}),Y?r.jsxs(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},className:"flex items-center gap-1.5 mb-1",children:[r.jsx("input",{value:l,onChange:W=>c(W.target.value),placeholder:"Reason (optional)",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-md px-2 py-1 text-[11px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#EF4444]/40",onKeyDown:W=>{W.key==="Enter"&&R($.messageId)},autoFocus:!0}),r.jsx("button",{onClick:()=>R($.messageId),className:"px-2 py-1 rounded-md bg-[#EF4444]/15 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/25 transition-colors",children:"Reject"}),r.jsx("button",{onClick:()=>{o(null),c("")},className:"text-[11px] text-[#5A5A6E] hover:text-[#8A8A99]",children:"Cancel"})]}):r.jsxs("div",{className:"flex items-center gap-1.5",children:[$.messageId&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>I($.messageId),disabled:A.isPending,className:"flex items-center gap-1 px-2 py-0.5 rounded-md bg-[#10B981]/12 text-[#10B981] text-[11px] font-medium hover:bg-[#10B981]/22 transition-colors disabled:opacity-40",children:[r.jsx(Fe,{className:"w-3 h-3"}),"Approve"]}),r.jsxs("button",{onClick:()=>o($.messageId),className:"flex items-center gap-1 px-2 py-0.5 rounded-md bg-[#EF4444]/12 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/22 transition-colors",children:[r.jsx(Te,{className:"w-3 h-3"}),"Reject"]})]}),r.jsxs("button",{onClick:()=>q($.channelId),className:"flex items-center gap-0.5 ml-auto px-1.5 py-0.5 rounded text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/[0.04] transition-colors",children:[r.jsx(cs,{className:"w-2.5 h-2.5"}),"View"]})]})]})]})})},$.id)})})]})]})]})]})}function Hye(){const e=an(),{data:t}=L.onboarding.getState.useQuery(void 0,{refetchOnWindowFocus:!1}),{data:n}=L.onboarding.pollOpenClaw.useQuery(void 0,{refetchInterval:1e4,refetchOnWindowFocus:!1}),s=L.onboarding.skipOpenClaw.useMutation(),i=L.useUtils();if(!t?.skippedOpenClaw||n?.running)return null;async function a(){await s.mutateAsync(),i.onboarding.getState.invalidate()}return r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-[#1C1410] border-b border-[#F59E0B]/20 text-[12px] flex-shrink-0",children:[r.jsxs("span",{className:"text-[#F59E0B]",children:["OpenClaw not connected —"," ",r.jsx("button",{onClick:()=>e("/onboarding"),className:"underline underline-offset-2 hover:text-[#FBBF24] transition-colors",children:"set up now"})]}),r.jsx("button",{onClick:a,className:"text-[#F59E0B]/60 hover:text-[#F59E0B] transition-colors ml-4",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]})}function Wye(){const{data:e}=L.settings.getTestMode.useQuery(void 0,{refetchOnWindowFocus:!1,refetchInterval:15e3}),t=L.useUtils(),n=L.settings.setTestMode.useMutation({onSuccess:()=>{t.settings.getTestMode.invalidate()}});return e?.enabled?r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-[#1C1A0F] border-b border-[#F59E0B]/30 text-[12px] flex-shrink-0",children:[r.jsxs("span",{className:"flex items-center gap-2 text-[#FBBF24]",children:[r.jsx(oL,{className:"w-3.5 h-3.5"}),"Test mode active — no memory, knowledge, or reflection will be recorded."]}),r.jsx("button",{onClick:()=>n.mutate({enabled:!1}),disabled:n.isPending,className:"text-[#FBBF24]/80 hover:text-[#FBBF24] underline underline-offset-2 transition-colors ml-4 disabled:opacity-50",children:"disable"})]}):null}function qye({children:e}){const[t,n]=y.useState(!1);return r.jsxs("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col",children:[r.jsx(Hye,{}),r.jsx(Wye,{}),r.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[r.jsx(lme,{onOpenApprovals:()=>n(s=>!s)}),r.jsxs("main",{className:"flex flex-1 overflow-hidden relative",children:[e,r.jsx(Afe,{})]}),r.jsx(Rye,{})]}),r.jsx(Me,{children:t&&r.jsx(Uye,{onClose:()=>n(!1)})})]})}function Gye({label:e,emoji:t,color:n,typeBadge:s,onRemove:i}){return r.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-md group",children:[r.jsx("span",{className:"w-6 h-6 rounded-full flex items-center justify-center text-xs flex-shrink-0",style:{backgroundColor:`${n}26`},children:t??e[0]?.toUpperCase()}),r.jsx("span",{className:"text-[13px] text-[#C8C8D4] flex-1 truncate",children:e}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] bg-white/5 px-1.5 py-0.5 rounded",children:s}),i&&r.jsx("button",{onClick:i,className:"w-5 h-5 flex items-center justify-center rounded text-[#5A5A6E] opacity-0 group-hover:opacity-100 hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-all",children:r.jsx(Te,{className:"w-3 h-3"})})]})}function Kye({channelId:e,existingIds:t,agents:n,workspaceMembers:s}){const[i,a]=y.useState(!1),[o,l]=y.useState(""),c=L.useUtils(),d=L.channels.addParticipant.useMutation({onSuccess:()=>{c.channels.list.invalidate(),l(""),a(!1)}}),f=n.filter(_=>!t.has(_.id)),p=s.filter(_=>!t.has(_.userId)),m=o.toLowerCase(),g=m?f.filter(_=>_.name.toLowerCase().includes(m)):f,b=m?p.filter(_=>_.name.toLowerCase().includes(m)):p;return i?r.jsxs("div",{className:"px-1",children:[r.jsx("input",{autoFocus:!0,value:o,onChange:_=>l(_.target.value),placeholder:"Search people and agents...",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-md px-2 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors mb-1",onKeyDown:_=>{_.key==="Escape"&&(a(!1),l(""))}}),r.jsxs("div",{className:"max-h-[180px] overflow-y-auto",children:[g.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[10px] text-[#5A5A6E] px-2 py-1 uppercase tracking-widest font-semibold",children:"Agents"}),g.map(_=>r.jsxs("button",{onClick:()=>d.mutate({channelId:e,participantId:_.id,participantType:"agent"}),disabled:d.isPending,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-[12px] text-[#C8C8D4] hover:bg-white/5 transition-colors",children:[r.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[11px] flex-shrink-0",style:{backgroundColor:`${_.color}26`},children:_.emoji}),r.jsx("span",{className:"flex-1 text-left truncate",children:_.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:_.role})]},_.id))]}),b.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[10px] text-[#5A5A6E] px-2 py-1 uppercase tracking-widest font-semibold",children:"People"}),b.map(_=>{const w=_.name.split(" ").map(A=>A[0]).join("").slice(0,2).toUpperCase();return r.jsxs("button",{onClick:()=>d.mutate({channelId:e,participantId:_.userId,participantType:"human"}),disabled:d.isPending,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-[12px] text-[#C8C8D4] hover:bg-white/5 transition-colors",children:[_.image?r.jsx("img",{src:_.image,className:"w-5 h-5 rounded-full flex-shrink-0",alt:""}):r.jsx("span",{className:"w-5 h-5 rounded-full bg-gradient-to-br from-[#6366F1] to-[#8B5CF6] flex items-center justify-center text-[9px] font-semibold text-white flex-shrink-0",children:w}),r.jsx("span",{className:"flex-1 text-left truncate",children:_.name})]},_.userId)})]}),g.length===0&&b.length===0&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] px-2 py-1.5",children:"No participants available"})]})]}):r.jsxs("button",{onClick:()=>a(!0),className:"flex items-center gap-1.5 px-2 py-1.5 rounded-md text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5 transition-colors w-full",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),r.jsx("span",{children:"Add participant"})]})}function S$({channel:e}){const{data:t=[]}=Vo(),{data:n}=Mi(),{data:s=[]}=L.workspace.listMembers.useQuery(void 0,{staleTime:3e4}),i=L.useUtils(),a=L.channels.removeParticipant.useMutation({onSuccess:()=>{i.channels.list.invalidate()}}),o=new Set(e.participants.map(c=>c.participantId)),l=e.participants.length;return r.jsxs(Ys,{children:[r.jsx(ci,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-transparent hover:border-[#2A2A35]",children:[r.jsx(wm,{className:"w-3.5 h-3.5"}),r.jsx("span",{children:l})]})}),r.jsx(Qs,{children:r.jsxs(Xs,{align:"end",sideOffset:6,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl w-[260px] z-50",children:[r.jsx("div",{className:"px-3 py-2 border-b border-[#2A2A35]",children:r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Members"})}),r.jsx("div",{className:"py-1 px-1 max-h-[200px] overflow-y-auto",children:e.participants.map(c=>{const d=t.find(A=>A.id===c.participantId),f=c.participantType==="human",m=(f?s.find(A=>A.userId===c.participantId):void 0)?.name??n?.user?.name??n?.user?.email??"User",g=f?m:d?.name??c.participantId,b=f?void 0:d?.emoji,_=f?"#6366F1":d?.color??"#8A8A99",w=e.participants.length>1;return r.jsx(Gye,{label:g,emoji:b,color:_,typeBadge:f?"Human":"Agent",onRemove:w?()=>a.mutate({channelId:e.id,participantId:c.participantId}):void 0},c.id)})}),r.jsx("div",{className:"border-t border-[#2A2A35] py-1.5 px-1",children:r.jsx(Kye,{channelId:e.id,existingIds:o,agents:t,workspaceMembers:s})}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]})}function Ij(e){const t=e+"CollectionProvider",[n,s]=Wa(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=_=>{const{scope:w,children:A}=_,S=be.useRef(null),C=be.useRef(new Map).current;return r.jsx(i,{scope:w,itemMap:C,collectionRef:S,children:A})};o.displayName=t;const l=e+"CollectionSlot",c=iu(l),d=be.forwardRef((_,w)=>{const{scope:A,children:S}=_,C=a(l,A),E=At(w,C.collectionRef);return r.jsx(c,{ref:E,children:S})});d.displayName=l;const f=e+"CollectionItemSlot",p="data-radix-collection-item",m=iu(f),g=be.forwardRef((_,w)=>{const{scope:A,children:S,...C}=_,E=be.useRef(null),k=At(w,E),T=a(f,A);return be.useEffect(()=>(T.itemMap.set(E,{ref:E,...C}),()=>{T.itemMap.delete(E)})),r.jsx(m,{[p]:"",ref:k,children:S})});g.displayName=f;function b(_){const w=a(e+"CollectionConsumer",_);return be.useCallback(()=>{const S=w.collectionRef.current;if(!S)return[];const C=Array.from(S.querySelectorAll(`[${p}]`));return Array.from(w.itemMap.values()).sort((T,F)=>C.indexOf(T.ref.current)-C.indexOf(F.ref.current))},[w.collectionRef,w.itemMap])}return[{Provider:o,Slot:d,ItemSlot:g},b,s]}var Yye=y.createContext(void 0);function Lj(e){const t=y.useContext(Yye);return e||t||"ltr"}var gA="rovingFocusGroup.onEntryFocus",Qye={bubbles:!1,cancelable:!0},Lm="RovingFocusGroup",[JS,C$,Xye]=Ij(Lm),[Jye,j$]=Wa(Lm,[Xye]),[Zye,e1e]=Jye(Lm),N$=y.forwardRef((e,t)=>r.jsx(JS.Provider,{scope:e.__scopeRovingFocusGroup,children:r.jsx(JS.Slot,{scope:e.__scopeRovingFocusGroup,children:r.jsx(t1e,{...e,ref:t})})}));N$.displayName=Lm;var t1e=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:s,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:c,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...p}=e,m=y.useRef(null),g=At(t,m),b=Lj(a),[_,w]=Fo({prop:o,defaultProp:l??null,onChange:c,caller:Lm}),[A,S]=y.useState(!1),C=ia(d),E=C$(n),k=y.useRef(!1),[T,F]=y.useState(0);return y.useEffect(()=>{const M=m.current;if(M)return M.addEventListener(gA,C),()=>M.removeEventListener(gA,C)},[C]),r.jsx(Zye,{scope:n,orientation:s,dir:b,loop:i,currentTabStopId:_,onItemFocus:y.useCallback(M=>w(M),[w]),onItemShiftTab:y.useCallback(()=>S(!0),[]),onFocusableItemAdd:y.useCallback(()=>F(M=>M+1),[]),onFocusableItemRemove:y.useCallback(()=>F(M=>M-1),[]),children:r.jsx(lt.div,{tabIndex:A||T===0?-1:0,"data-orientation":s,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:Oe(e.onMouseDown,()=>{k.current=!0}),onFocus:Oe(e.onFocus,M=>{const I=!k.current;if(M.target===M.currentTarget&&I&&!A){const R=new CustomEvent(gA,Qye);if(M.currentTarget.dispatchEvent(R),!R.defaultPrevented){const H=E().filter(B=>B.focusable),V=H.find(B=>B.active),K=H.find(B=>B.id===_),$=[V,K,...H].filter(Boolean).map(B=>B.ref.current);F$($,f)}}k.current=!1}),onBlur:Oe(e.onBlur,()=>S(!1))})})}),k$="RovingFocusGroupItem",E$=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:s=!0,active:i=!1,tabStopId:a,children:o,...l}=e,c=Zi(),d=a||c,f=e1e(k$,n),p=f.currentTabStopId===d,m=C$(n),{onFocusableItemAdd:g,onFocusableItemRemove:b,currentTabStopId:_}=f;return y.useEffect(()=>{if(s)return g(),()=>b()},[s,g,b]),r.jsx(JS.ItemSlot,{scope:n,id:d,focusable:s,active:i,children:r.jsx(lt.span,{tabIndex:p?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:Oe(e.onMouseDown,w=>{s?f.onItemFocus(d):w.preventDefault()}),onFocus:Oe(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:Oe(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){f.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const A=i1e(w,f.orientation,f.dir);if(A!==void 0){if(w.metaKey||w.ctrlKey||w.altKey||w.shiftKey)return;w.preventDefault();let C=m().filter(E=>E.focusable).map(E=>E.ref.current);if(A==="last")C.reverse();else if(A==="prev"||A==="next"){A==="prev"&&C.reverse();const E=C.indexOf(w.currentTarget);C=f.loop?r1e(C,E+1):C.slice(E+1)}setTimeout(()=>F$(C))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:_!=null}):o})})});E$.displayName=k$;var n1e={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function s1e(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function i1e(e,t,n){const s=s1e(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(s))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(s)))return n1e[s]}function F$(e,t=!1){const n=document.activeElement;for(const s of e)if(s===n||(s.focus({preventScroll:t}),document.activeElement!==n))return}function r1e(e,t){return e.map((n,s)=>e[(t+s)%e.length])}var a1e=N$,o1e=E$,ZS=["Enter"," "],l1e=["ArrowDown","PageUp","Home"],T$=["ArrowUp","PageDown","End"],c1e=[...l1e,...T$],u1e={ltr:[...ZS,"ArrowRight"],rtl:[...ZS,"ArrowLeft"]},d1e={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Bm="Menu",[zp,h1e,f1e]=Ij(Bm),[_u,M$]=Wa(Bm,[f1e,tc,j$]),zm=tc(),R$=j$(),[D$,ic]=_u(Bm),[p1e,$m]=_u(Bm),O$=e=>{const{__scopeMenu:t,open:n=!1,children:s,dir:i,onOpenChange:a,modal:o=!0}=e,l=zm(t),[c,d]=y.useState(null),f=y.useRef(!1),p=ia(a),m=Lj(i);return y.useEffect(()=>{const g=()=>{f.current=!0,document.addEventListener("pointerdown",b,{capture:!0,once:!0}),document.addEventListener("pointermove",b,{capture:!0,once:!0})},b=()=>f.current=!1;return document.addEventListener("keydown",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),r.jsx(jm,{...l,children:r.jsx(D$,{scope:t,open:n,onOpenChange:p,content:c,onContentChange:d,children:r.jsx(p1e,{scope:t,onClose:y.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:f,dir:m,modal:o,children:s})})})};O$.displayName=Bm;var m1e="MenuAnchor",Bj=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e,i=zm(n);return r.jsx(Nm,{...i,...s,ref:t})});Bj.displayName=m1e;var zj="MenuPortal",[x1e,P$]=_u(zj,{forceMount:void 0}),I$=e=>{const{__scopeMenu:t,forceMount:n,children:s,container:i}=e,a=ic(zj,t);return r.jsx(x1e,{scope:t,forceMount:n,children:r.jsx(zr,{present:n||a.open,children:r.jsx(hh,{asChild:!0,container:i,children:s})})})};I$.displayName=zj;var Or="MenuContent",[g1e,$j]=_u(Or),L$=y.forwardRef((e,t)=>{const n=P$(Or,e.__scopeMenu),{forceMount:s=n.forceMount,...i}=e,a=ic(Or,e.__scopeMenu),o=$m(Or,e.__scopeMenu);return r.jsx(zp.Provider,{scope:e.__scopeMenu,children:r.jsx(zr,{present:s||a.open,children:r.jsx(zp.Slot,{scope:e.__scopeMenu,children:o.modal?r.jsx(b1e,{...i,ref:t}):r.jsx(v1e,{...i,ref:t})})})})}),b1e=y.forwardRef((e,t)=>{const n=ic(Or,e.__scopeMenu),s=y.useRef(null),i=At(t,s);return y.useEffect(()=>{const a=s.current;if(a)return Av(a)},[]),r.jsx(Vj,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Oe(e.onFocusOutside,a=>a.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),v1e=y.forwardRef((e,t)=>{const n=ic(Or,e.__scopeMenu);return r.jsx(Vj,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),y1e=iu("MenuContent.ScrollLock"),Vj=y.forwardRef((e,t)=>{const{__scopeMenu:n,loop:s=!1,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:c,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:m,onDismiss:g,disableOutsideScroll:b,..._}=e,w=ic(Or,n),A=$m(Or,n),S=zm(n),C=R$(n),E=h1e(n),[k,T]=y.useState(null),F=y.useRef(null),M=At(t,F,w.onContentChange),I=y.useRef(0),R=y.useRef(""),H=y.useRef(0),V=y.useRef(null),K=y.useRef("right"),q=y.useRef(0),$=b?Sm:y.Fragment,B=b?{as:y1e,allowPinchZoom:!0}:void 0,Y=W=>{const O=R.current+W,D=E().filter(oe=>!oe.disabled),Q=document.activeElement,z=D.find(oe=>oe.ref.current===Q)?.textValue,J=D.map(oe=>oe.textValue),ee=M1e(J,O,z),re=D.find(oe=>oe.textValue===ee)?.ref.current;(function oe(se){R.current=se,window.clearTimeout(I.current),se!==""&&(I.current=window.setTimeout(()=>oe(""),1e3))})(O),re&&setTimeout(()=>re.focus())};y.useEffect(()=>()=>window.clearTimeout(I.current),[]),_v();const U=y.useCallback(W=>K.current===V.current?.side&&D1e(W,V.current?.area),[]);return r.jsx(g1e,{scope:n,searchRef:R,onItemEnter:y.useCallback(W=>{U(W)&&W.preventDefault()},[U]),onItemLeave:y.useCallback(W=>{U(W)||(F.current?.focus(),T(null))},[U]),onTriggerLeave:y.useCallback(W=>{U(W)&&W.preventDefault()},[U]),pointerGraceTimerRef:H,onPointerGraceIntentChange:y.useCallback(W=>{V.current=W},[]),children:r.jsx($,{...B,children:r.jsx(Am,{asChild:!0,trapped:i,onMountAutoFocus:Oe(a,W=>{W.preventDefault(),F.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:r.jsx(dh,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:m,onDismiss:g,children:r.jsx(a1e,{asChild:!0,...C,dir:A.dir,orientation:"vertical",loop:s,currentTabStopId:k,onCurrentTabStopIdChange:T,onEntryFocus:Oe(c,W=>{A.isUsingKeyboardRef.current||W.preventDefault()}),preventScrollOnEntryFocus:!0,children:r.jsx(Fv,{role:"menu","aria-orientation":"vertical","data-state":t7(w.open),"data-radix-menu-content":"",dir:A.dir,...S,..._,ref:M,style:{outline:"none",..._.style},onKeyDown:Oe(_.onKeyDown,W=>{const D=W.target.closest("[data-radix-menu-content]")===W.currentTarget,Q=W.ctrlKey||W.altKey||W.metaKey,z=W.key.length===1;D&&(W.key==="Tab"&&W.preventDefault(),!Q&&z&&Y(W.key));const J=F.current;if(W.target!==J||!c1e.includes(W.key))return;W.preventDefault();const re=E().filter(oe=>!oe.disabled).map(oe=>oe.ref.current);T$.includes(W.key)&&re.reverse(),F1e(re)}),onBlur:Oe(e.onBlur,W=>{W.currentTarget.contains(W.target)||(window.clearTimeout(I.current),R.current="")}),onPointerMove:Oe(e.onPointerMove,$p(W=>{const O=W.target,D=q.current!==W.clientX;if(W.currentTarget.contains(O)&&D){const Q=W.clientX>q.current?"right":"left";K.current=Q,q.current=W.clientX}}))})})})})})})});L$.displayName=Or;var _1e="MenuGroup",Uj=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e;return r.jsx(lt.div,{role:"group",...s,ref:t})});Uj.displayName=_1e;var w1e="MenuLabel",B$=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e;return r.jsx(lt.div,{...s,ref:t})});B$.displayName=w1e;var j0="MenuItem",oR="menu.itemSelect",Gv=y.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:s,...i}=e,a=y.useRef(null),o=$m(j0,e.__scopeMenu),l=$j(j0,e.__scopeMenu),c=At(t,a),d=y.useRef(!1),f=()=>{const p=a.current;if(!n&&p){const m=new CustomEvent(oR,{bubbles:!0,cancelable:!0});p.addEventListener(oR,g=>s?.(g),{once:!0}),BL(p,m),m.defaultPrevented?d.current=!1:o.onClose()}};return r.jsx(z$,{...i,ref:c,disabled:n,onClick:Oe(e.onClick,f),onPointerDown:p=>{e.onPointerDown?.(p),d.current=!0},onPointerUp:Oe(e.onPointerUp,p=>{d.current||p.currentTarget?.click()}),onKeyDown:Oe(e.onKeyDown,p=>{const m=l.searchRef.current!=="";n||m&&p.key===" "||ZS.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Gv.displayName=j0;var z$=y.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:s=!1,textValue:i,...a}=e,o=$j(j0,n),l=R$(n),c=y.useRef(null),d=At(t,c),[f,p]=y.useState(!1),[m,g]=y.useState("");return y.useEffect(()=>{const b=c.current;b&&g((b.textContent??"").trim())},[a.children]),r.jsx(zp.ItemSlot,{scope:n,disabled:s,textValue:i??m,children:r.jsx(o1e,{asChild:!0,...l,focusable:!s,children:r.jsx(lt.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":s||void 0,"data-disabled":s?"":void 0,...a,ref:d,onPointerMove:Oe(e.onPointerMove,$p(b=>{s?o.onItemLeave(b):(o.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Oe(e.onPointerLeave,$p(b=>o.onItemLeave(b))),onFocus:Oe(e.onFocus,()=>p(!0)),onBlur:Oe(e.onBlur,()=>p(!1))})})})}),A1e="MenuCheckboxItem",$$=y.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:s,...i}=e;return r.jsx(q$,{scope:e.__scopeMenu,checked:n,children:r.jsx(Gv,{role:"menuitemcheckbox","aria-checked":N0(n)?"mixed":n,...i,ref:t,"data-state":qj(n),onSelect:Oe(i.onSelect,()=>s?.(N0(n)?!0:!n),{checkForDefaultPrevented:!1})})})});$$.displayName=A1e;var V$="MenuRadioGroup",[S1e,C1e]=_u(V$,{value:void 0,onValueChange:()=>{}}),U$=y.forwardRef((e,t)=>{const{value:n,onValueChange:s,...i}=e,a=ia(s);return r.jsx(S1e,{scope:e.__scopeMenu,value:n,onValueChange:a,children:r.jsx(Uj,{...i,ref:t})})});U$.displayName=V$;var H$="MenuRadioItem",W$=y.forwardRef((e,t)=>{const{value:n,...s}=e,i=C1e(H$,e.__scopeMenu),a=n===i.value;return r.jsx(q$,{scope:e.__scopeMenu,checked:a,children:r.jsx(Gv,{role:"menuitemradio","aria-checked":a,...s,ref:t,"data-state":qj(a),onSelect:Oe(s.onSelect,()=>i.onValueChange?.(n),{checkForDefaultPrevented:!1})})})});W$.displayName=H$;var Hj="MenuItemIndicator",[q$,j1e]=_u(Hj,{checked:!1}),G$=y.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:s,...i}=e,a=j1e(Hj,n);return r.jsx(zr,{present:s||N0(a.checked)||a.checked===!0,children:r.jsx(lt.span,{...i,ref:t,"data-state":qj(a.checked)})})});G$.displayName=Hj;var N1e="MenuSeparator",K$=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e;return r.jsx(lt.div,{role:"separator","aria-orientation":"horizontal",...s,ref:t})});K$.displayName=N1e;var k1e="MenuArrow",Y$=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e,i=zm(n);return r.jsx(Tv,{...i,...s,ref:t})});Y$.displayName=k1e;var Wj="MenuSub",[E1e,Q$]=_u(Wj),X$=e=>{const{__scopeMenu:t,children:n,open:s=!1,onOpenChange:i}=e,a=ic(Wj,t),o=zm(t),[l,c]=y.useState(null),[d,f]=y.useState(null),p=ia(i);return y.useEffect(()=>(a.open===!1&&p(!1),()=>p(!1)),[a.open,p]),r.jsx(jm,{...o,children:r.jsx(D$,{scope:t,open:s,onOpenChange:p,content:d,onContentChange:f,children:r.jsx(E1e,{scope:t,contentId:Zi(),triggerId:Zi(),trigger:l,onTriggerChange:c,children:n})})})};X$.displayName=Wj;var Xf="MenuSubTrigger",J$=y.forwardRef((e,t)=>{const n=ic(Xf,e.__scopeMenu),s=$m(Xf,e.__scopeMenu),i=Q$(Xf,e.__scopeMenu),a=$j(Xf,e.__scopeMenu),o=y.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:c}=a,d={__scopeMenu:e.__scopeMenu},f=y.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return y.useEffect(()=>f,[f]),y.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),c(null)}},[l,c]),r.jsx(Bj,{asChild:!0,...d,children:r.jsx(z$,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":t7(n.open),...e,ref:yv(t,i.onTriggerChange),onClick:p=>{e.onClick?.(p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:Oe(e.onPointerMove,$p(p=>{a.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(a.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:Oe(e.onPointerLeave,$p(p=>{f();const m=n.content?.getBoundingClientRect();if(m){const g=n.content?.dataset.side,b=g==="right",_=b?-5:5,w=m[b?"left":"right"],A=m[b?"right":"left"];a.onPointerGraceIntentChange({area:[{x:p.clientX+_,y:p.clientY},{x:w,y:m.top},{x:A,y:m.top},{x:A,y:m.bottom},{x:w,y:m.bottom}],side:g}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>a.onPointerGraceIntentChange(null),300)}else{if(a.onTriggerLeave(p),p.defaultPrevented)return;a.onPointerGraceIntentChange(null)}})),onKeyDown:Oe(e.onKeyDown,p=>{const m=a.searchRef.current!=="";e.disabled||m&&p.key===" "||u1e[s.dir].includes(p.key)&&(n.onOpenChange(!0),n.content?.focus(),p.preventDefault())})})})});J$.displayName=Xf;var Z$="MenuSubContent",e7=y.forwardRef((e,t)=>{const n=P$(Or,e.__scopeMenu),{forceMount:s=n.forceMount,...i}=e,a=ic(Or,e.__scopeMenu),o=$m(Or,e.__scopeMenu),l=Q$(Z$,e.__scopeMenu),c=y.useRef(null),d=At(t,c);return r.jsx(zp.Provider,{scope:e.__scopeMenu,children:r.jsx(zr,{present:s||a.open,children:r.jsx(zp.Slot,{scope:e.__scopeMenu,children:r.jsx(Vj,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:f=>{o.isUsingKeyboardRef.current&&c.current?.focus(),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:Oe(e.onFocusOutside,f=>{f.target!==l.trigger&&a.onOpenChange(!1)}),onEscapeKeyDown:Oe(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:Oe(e.onKeyDown,f=>{const p=f.currentTarget.contains(f.target),m=d1e[o.dir].includes(f.key);p&&m&&(a.onOpenChange(!1),l.trigger?.focus(),f.preventDefault())})})})})})});e7.displayName=Z$;function t7(e){return e?"open":"closed"}function N0(e){return e==="indeterminate"}function qj(e){return N0(e)?"indeterminate":e?"checked":"unchecked"}function F1e(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function T1e(e,t){return e.map((n,s)=>e[(t+s)%e.length])}function M1e(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,a=n?e.indexOf(n):-1;let o=T1e(e,Math.max(a,0));i.length===1&&(o=o.filter(d=>d!==n));const c=o.find(d=>d.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function R1e(e,t){const{x:n,y:s}=e;let i=!1;for(let a=0,o=t.length-1;a<t.length;o=a++){const l=t[a],c=t[o],d=l.x,f=l.y,p=c.x,m=c.y;f>s!=m>s&&n<(p-d)*(s-f)/(m-f)+d&&(i=!i)}return i}function D1e(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return R1e(n,t)}function $p(e){return t=>t.pointerType==="mouse"?e(t):void 0}var O1e=O$,P1e=Bj,I1e=I$,L1e=L$,B1e=Uj,z1e=B$,$1e=Gv,V1e=$$,U1e=U$,H1e=W$,W1e=G$,q1e=K$,G1e=Y$,K1e=X$,Y1e=J$,Q1e=e7,Kv="DropdownMenu",[X1e]=Wa(Kv,[M$]),ei=M$(),[J1e,n7]=X1e(Kv),s7=e=>{const{__scopeDropdownMenu:t,children:n,dir:s,open:i,defaultOpen:a,onOpenChange:o,modal:l=!0}=e,c=ei(t),d=y.useRef(null),[f,p]=Fo({prop:i,defaultProp:a??!1,onChange:o,caller:Kv});return r.jsx(J1e,{scope:t,triggerId:Zi(),triggerRef:d,contentId:Zi(),open:f,onOpenChange:p,onOpenToggle:y.useCallback(()=>p(m=>!m),[p]),modal:l,children:r.jsx(O1e,{...c,open:f,onOpenChange:p,dir:s,modal:l,children:n})})};s7.displayName=Kv;var i7="DropdownMenuTrigger",r7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:s=!1,...i}=e,a=n7(i7,n),o=ei(n);return r.jsx(P1e,{asChild:!0,...o,children:r.jsx(lt.button,{type:"button",id:a.triggerId,"aria-haspopup":"menu","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?"open":"closed","data-disabled":s?"":void 0,disabled:s,...i,ref:yv(t,a.triggerRef),onPointerDown:Oe(e.onPointerDown,l=>{!s&&l.button===0&&l.ctrlKey===!1&&(a.onOpenToggle(),a.open||l.preventDefault())}),onKeyDown:Oe(e.onKeyDown,l=>{s||(["Enter"," "].includes(l.key)&&a.onOpenToggle(),l.key==="ArrowDown"&&a.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});r7.displayName=i7;var Z1e="DropdownMenuPortal",a7=e=>{const{__scopeDropdownMenu:t,...n}=e,s=ei(t);return r.jsx(I1e,{...s,...n})};a7.displayName=Z1e;var o7="DropdownMenuContent",l7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=n7(o7,n),a=ei(n),o=y.useRef(!1);return r.jsx(L1e,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...s,ref:t,onCloseAutoFocus:Oe(e.onCloseAutoFocus,l=>{o.current||i.triggerRef.current?.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:Oe(e.onInteractOutside,l=>{const c=l.detail.originalEvent,d=c.button===0&&c.ctrlKey===!0,f=c.button===2||d;(!i.modal||f)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});l7.displayName=o7;var e_e="DropdownMenuGroup",c7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(B1e,{...i,...s,ref:t})});c7.displayName=e_e;var t_e="DropdownMenuLabel",u7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(z1e,{...i,...s,ref:t})});u7.displayName=t_e;var n_e="DropdownMenuItem",d7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx($1e,{...i,...s,ref:t})});d7.displayName=n_e;var s_e="DropdownMenuCheckboxItem",i_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(V1e,{...i,...s,ref:t})});i_e.displayName=s_e;var r_e="DropdownMenuRadioGroup",a_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(U1e,{...i,...s,ref:t})});a_e.displayName=r_e;var o_e="DropdownMenuRadioItem",l_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(H1e,{...i,...s,ref:t})});l_e.displayName=o_e;var c_e="DropdownMenuItemIndicator",u_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(W1e,{...i,...s,ref:t})});u_e.displayName=c_e;var d_e="DropdownMenuSeparator",h7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(q1e,{...i,...s,ref:t})});h7.displayName=d_e;var h_e="DropdownMenuArrow",f_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(G1e,{...i,...s,ref:t})});f_e.displayName=h_e;var p_e=e=>{const{__scopeDropdownMenu:t,children:n,open:s,onOpenChange:i,defaultOpen:a}=e,o=ei(t),[l,c]=Fo({prop:s,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return r.jsx(K1e,{...o,open:l,onOpenChange:c,children:n})},m_e="DropdownMenuSubTrigger",f7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(Y1e,{...i,...s,ref:t})});f7.displayName=m_e;var x_e="DropdownMenuSubContent",p7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(Q1e,{...i,...s,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});p7.displayName=x_e;var Yv=s7,Qv=r7,Od=a7,Xv=l7,g_e=c7,b_e=u7,Bl=d7,v_e=h7,lR=p_e,cR=f7,uR=p7;function dR(e,[t,n]){return Math.min(n,Math.max(t,e))}function m7(e){const t=y.useRef({value:e,previous:e});return y.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var y_e=[" ","Enter","ArrowUp","ArrowDown"],__e=[" ","Enter"],uu="Select",[Jv,Zv,w_e]=Ij(uu),[vh]=Wa(uu,[w_e,tc]),ey=tc(),[A_e,rc]=vh(uu),[S_e,C_e]=vh(uu),x7=e=>{const{__scopeSelect:t,children:n,open:s,defaultOpen:i,onOpenChange:a,value:o,defaultValue:l,onValueChange:c,dir:d,name:f,autoComplete:p,disabled:m,required:g,form:b}=e,_=ey(t),[w,A]=y.useState(null),[S,C]=y.useState(null),[E,k]=y.useState(!1),T=Lj(d),[F,M]=Fo({prop:s,defaultProp:i??!1,onChange:a,caller:uu}),[I,R]=Fo({prop:o,defaultProp:l,onChange:c,caller:uu}),H=y.useRef(null),V=w?b||!!w.closest("form"):!0,[K,q]=y.useState(new Set),$=Array.from(K).map(B=>B.props.value).join(";");return r.jsx(jm,{..._,children:r.jsxs(A_e,{required:g,scope:t,trigger:w,onTriggerChange:A,valueNode:S,onValueNodeChange:C,valueNodeHasChildren:E,onValueNodeHasChildrenChange:k,contentId:Zi(),value:I,onValueChange:R,open:F,onOpenChange:M,dir:T,triggerPointerDownPosRef:H,disabled:m,children:[r.jsx(Jv.Provider,{scope:t,children:r.jsx(S_e,{scope:e.__scopeSelect,onNativeOptionAdd:y.useCallback(B=>{q(Y=>new Set(Y).add(B))},[]),onNativeOptionRemove:y.useCallback(B=>{q(Y=>{const U=new Set(Y);return U.delete(B),U})},[]),children:n})}),V?r.jsxs(L7,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:p,value:I,onChange:B=>R(B.target.value),disabled:m,form:b,children:[I===void 0?r.jsx("option",{value:""}):null,Array.from(K)]},$):null]})})};x7.displayName=uu;var g7="SelectTrigger",b7=y.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:s=!1,...i}=e,a=ey(n),o=rc(g7,n),l=o.disabled||s,c=At(t,o.onTriggerChange),d=Zv(n),f=y.useRef("touch"),[p,m,g]=z7(_=>{const w=d().filter(C=>!C.disabled),A=w.find(C=>C.value===o.value),S=$7(w,_,A);S!==void 0&&o.onValueChange(S.value)}),b=_=>{l||(o.onOpenChange(!0),g()),_&&(o.triggerPointerDownPosRef.current={x:Math.round(_.pageX),y:Math.round(_.pageY)})};return r.jsx(Nm,{asChild:!0,...a,children:r.jsx(lt.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":B7(o.value)?"":void 0,...i,ref:c,onClick:Oe(i.onClick,_=>{_.currentTarget.focus(),f.current!=="mouse"&&b(_)}),onPointerDown:Oe(i.onPointerDown,_=>{f.current=_.pointerType;const w=_.target;w.hasPointerCapture(_.pointerId)&&w.releasePointerCapture(_.pointerId),_.button===0&&_.ctrlKey===!1&&_.pointerType==="mouse"&&(b(_),_.preventDefault())}),onKeyDown:Oe(i.onKeyDown,_=>{const w=p.current!=="";!(_.ctrlKey||_.altKey||_.metaKey)&&_.key.length===1&&m(_.key),!(w&&_.key===" ")&&y_e.includes(_.key)&&(b(),_.preventDefault())})})})});b7.displayName=g7;var v7="SelectValue",y7=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:s,style:i,children:a,placeholder:o="",...l}=e,c=rc(v7,n),{onValueNodeHasChildrenChange:d}=c,f=a!==void 0,p=At(t,c.onValueNodeChange);return Ks(()=>{d(f)},[d,f]),r.jsx(lt.span,{...l,ref:p,style:{pointerEvents:"none"},children:B7(c.value)?r.jsx(r.Fragment,{children:o}):a})});y7.displayName=v7;var j_e="SelectIcon",_7=y.forwardRef((e,t)=>{const{__scopeSelect:n,children:s,...i}=e;return r.jsx(lt.span,{"aria-hidden":!0,...i,ref:t,children:s||"▼"})});_7.displayName=j_e;var N_e="SelectPortal",w7=e=>r.jsx(hh,{asChild:!0,...e});w7.displayName=N_e;var du="SelectContent",A7=y.forwardRef((e,t)=>{const n=rc(du,e.__scopeSelect),[s,i]=y.useState();if(Ks(()=>{i(new DocumentFragment)},[]),!n.open){const a=s;return a?Xr.createPortal(r.jsx(S7,{scope:e.__scopeSelect,children:r.jsx(Jv.Slot,{scope:e.__scopeSelect,children:r.jsx("div",{children:e.children})})}),a):null}return r.jsx(C7,{...e,ref:t})});A7.displayName=du;var Kr=10,[S7,ac]=vh(du),k_e="SelectContentImpl",E_e=iu("SelectContent.RemoveScroll"),C7=y.forwardRef((e,t)=>{const{__scopeSelect:n,position:s="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:l,sideOffset:c,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:g,sticky:b,hideWhenDetached:_,avoidCollisions:w,...A}=e,S=rc(du,n),[C,E]=y.useState(null),[k,T]=y.useState(null),F=At(t,oe=>E(oe)),[M,I]=y.useState(null),[R,H]=y.useState(null),V=Zv(n),[K,q]=y.useState(!1),$=y.useRef(!1);y.useEffect(()=>{if(C)return Av(C)},[C]),_v();const B=y.useCallback(oe=>{const[se,...ae]=V().map(je=>je.ref.current),[le]=ae.slice(-1),ge=document.activeElement;for(const je of oe)if(je===ge||(je?.scrollIntoView({block:"nearest"}),je===se&&k&&(k.scrollTop=0),je===le&&k&&(k.scrollTop=k.scrollHeight),je?.focus(),document.activeElement!==ge))return},[V,k]),Y=y.useCallback(()=>B([M,C]),[B,M,C]);y.useEffect(()=>{K&&Y()},[K,Y]);const{onOpenChange:U,triggerPointerDownPosRef:W}=S;y.useEffect(()=>{if(C){let oe={x:0,y:0};const se=le=>{oe={x:Math.abs(Math.round(le.pageX)-(W.current?.x??0)),y:Math.abs(Math.round(le.pageY)-(W.current?.y??0))}},ae=le=>{oe.x<=10&&oe.y<=10?le.preventDefault():C.contains(le.target)||U(!1),document.removeEventListener("pointermove",se),W.current=null};return W.current!==null&&(document.addEventListener("pointermove",se),document.addEventListener("pointerup",ae,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",se),document.removeEventListener("pointerup",ae,{capture:!0})}}},[C,U,W]),y.useEffect(()=>{const oe=()=>U(!1);return window.addEventListener("blur",oe),window.addEventListener("resize",oe),()=>{window.removeEventListener("blur",oe),window.removeEventListener("resize",oe)}},[U]);const[O,D]=z7(oe=>{const se=V().filter(ge=>!ge.disabled),ae=se.find(ge=>ge.ref.current===document.activeElement),le=$7(se,oe,ae);le&&setTimeout(()=>le.ref.current.focus())}),Q=y.useCallback((oe,se,ae)=>{const le=!$.current&&!ae;(S.value!==void 0&&S.value===se||le)&&(I(oe),le&&($.current=!0))},[S.value]),z=y.useCallback(()=>C?.focus(),[C]),J=y.useCallback((oe,se,ae)=>{const le=!$.current&&!ae;(S.value!==void 0&&S.value===se||le)&&H(oe)},[S.value]),ee=s==="popper"?eC:j7,re=ee===eC?{side:l,sideOffset:c,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:g,sticky:b,hideWhenDetached:_,avoidCollisions:w}:{};return r.jsx(S7,{scope:n,content:C,viewport:k,onViewportChange:T,itemRefCallback:Q,selectedItem:M,onItemLeave:z,itemTextRefCallback:J,focusSelectedItem:Y,selectedItemText:R,position:s,isPositioned:K,searchRef:O,children:r.jsx(Sm,{as:E_e,allowPinchZoom:!0,children:r.jsx(Am,{asChild:!0,trapped:S.open,onMountAutoFocus:oe=>{oe.preventDefault()},onUnmountAutoFocus:Oe(i,oe=>{S.trigger?.focus({preventScroll:!0}),oe.preventDefault()}),children:r.jsx(dh,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:oe=>oe.preventDefault(),onDismiss:()=>S.onOpenChange(!1),children:r.jsx(ee,{role:"listbox",id:S.contentId,"data-state":S.open?"open":"closed",dir:S.dir,onContextMenu:oe=>oe.preventDefault(),...A,...re,onPlaced:()=>q(!0),ref:F,style:{display:"flex",flexDirection:"column",outline:"none",...A.style},onKeyDown:Oe(A.onKeyDown,oe=>{const se=oe.ctrlKey||oe.altKey||oe.metaKey;if(oe.key==="Tab"&&oe.preventDefault(),!se&&oe.key.length===1&&D(oe.key),["ArrowUp","ArrowDown","Home","End"].includes(oe.key)){let le=V().filter(ge=>!ge.disabled).map(ge=>ge.ref.current);if(["ArrowUp","End"].includes(oe.key)&&(le=le.slice().reverse()),["ArrowUp","ArrowDown"].includes(oe.key)){const ge=oe.target,je=le.indexOf(ge);le=le.slice(je+1)}setTimeout(()=>B(le)),oe.preventDefault()}})})})})})})});C7.displayName=k_e;var F_e="SelectItemAlignedPosition",j7=y.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:s,...i}=e,a=rc(du,n),o=ac(du,n),[l,c]=y.useState(null),[d,f]=y.useState(null),p=At(t,F=>f(F)),m=Zv(n),g=y.useRef(!1),b=y.useRef(!0),{viewport:_,selectedItem:w,selectedItemText:A,focusSelectedItem:S}=o,C=y.useCallback(()=>{if(a.trigger&&a.valueNode&&l&&d&&_&&w&&A){const F=a.trigger.getBoundingClientRect(),M=d.getBoundingClientRect(),I=a.valueNode.getBoundingClientRect(),R=A.getBoundingClientRect();if(a.dir!=="rtl"){const ge=R.left-M.left,je=I.left-ge,Ee=F.left-je,de=F.width+Ee,me=Math.max(de,M.width),$e=window.innerWidth-Kr,nt=dR(je,[Kr,Math.max(Kr,$e-me)]);l.style.minWidth=de+"px",l.style.left=nt+"px"}else{const ge=M.right-R.right,je=window.innerWidth-I.right-ge,Ee=window.innerWidth-F.right-je,de=F.width+Ee,me=Math.max(de,M.width),$e=window.innerWidth-Kr,nt=dR(je,[Kr,Math.max(Kr,$e-me)]);l.style.minWidth=de+"px",l.style.right=nt+"px"}const H=m(),V=window.innerHeight-Kr*2,K=_.scrollHeight,q=window.getComputedStyle(d),$=parseInt(q.borderTopWidth,10),B=parseInt(q.paddingTop,10),Y=parseInt(q.borderBottomWidth,10),U=parseInt(q.paddingBottom,10),W=$+B+K+U+Y,O=Math.min(w.offsetHeight*5,W),D=window.getComputedStyle(_),Q=parseInt(D.paddingTop,10),z=parseInt(D.paddingBottom,10),J=F.top+F.height/2-Kr,ee=V-J,re=w.offsetHeight/2,oe=w.offsetTop+re,se=$+B+oe,ae=W-se;if(se<=J){const ge=H.length>0&&w===H[H.length-1].ref.current;l.style.bottom="0px";const je=d.clientHeight-_.offsetTop-_.offsetHeight,Ee=Math.max(ee,re+(ge?z:0)+je+Y),de=se+Ee;l.style.height=de+"px"}else{const ge=H.length>0&&w===H[0].ref.current;l.style.top="0px";const Ee=Math.max(J,$+_.offsetTop+(ge?Q:0)+re)+ae;l.style.height=Ee+"px",_.scrollTop=se-J+_.offsetTop}l.style.margin=`${Kr}px 0`,l.style.minHeight=O+"px",l.style.maxHeight=V+"px",s?.(),requestAnimationFrame(()=>g.current=!0)}},[m,a.trigger,a.valueNode,l,d,_,w,A,a.dir,s]);Ks(()=>C(),[C]);const[E,k]=y.useState();Ks(()=>{d&&k(window.getComputedStyle(d).zIndex)},[d]);const T=y.useCallback(F=>{F&&b.current===!0&&(C(),S?.(),b.current=!1)},[C,S]);return r.jsx(M_e,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:T,children:r.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:E},children:r.jsx(lt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});j7.displayName=F_e;var T_e="SelectPopperPosition",eC=y.forwardRef((e,t)=>{const{__scopeSelect:n,align:s="start",collisionPadding:i=Kr,...a}=e,o=ey(n);return r.jsx(Fv,{...o,...a,ref:t,align:s,collisionPadding:i,style:{boxSizing:"border-box",...a.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});eC.displayName=T_e;var[M_e,Gj]=vh(du,{}),tC="SelectViewport",N7=y.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:s,...i}=e,a=ac(tC,n),o=Gj(tC,n),l=At(t,a.onViewportChange),c=y.useRef(0);return r.jsxs(r.Fragment,{children:[r.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:s}),r.jsx(Jv.Slot,{scope:n,children:r.jsx(lt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:Oe(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:m}=o;if(m?.current&&p){const g=Math.abs(c.current-f.scrollTop);if(g>0){const b=window.innerHeight-Kr*2,_=parseFloat(p.style.minHeight),w=parseFloat(p.style.height),A=Math.max(_,w);if(A<b){const S=A+g,C=Math.min(b,S),E=S-C;p.style.height=C+"px",p.style.bottom==="0px"&&(f.scrollTop=E>0?E:0,p.style.justifyContent="flex-end")}}}c.current=f.scrollTop})})})]})});N7.displayName=tC;var k7="SelectGroup",[R_e,D_e]=vh(k7),E7=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e,i=Zi();return r.jsx(R_e,{scope:n,id:i,children:r.jsx(lt.div,{role:"group","aria-labelledby":i,...s,ref:t})})});E7.displayName=k7;var F7="SelectLabel",T7=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e,i=D_e(F7,n);return r.jsx(lt.div,{id:i.id,...s,ref:t})});T7.displayName=F7;var k0="SelectItem",[O_e,M7]=vh(k0),R7=y.forwardRef((e,t)=>{const{__scopeSelect:n,value:s,disabled:i=!1,textValue:a,...o}=e,l=rc(k0,n),c=ac(k0,n),d=l.value===s,[f,p]=y.useState(a??""),[m,g]=y.useState(!1),b=At(t,S=>c.itemRefCallback?.(S,s,i)),_=Zi(),w=y.useRef("touch"),A=()=>{i||(l.onValueChange(s),l.onOpenChange(!1))};if(s==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return r.jsx(O_e,{scope:n,value:s,disabled:i,textId:_,isSelected:d,onItemTextChange:y.useCallback(S=>{p(C=>C||(S?.textContent??"").trim())},[]),children:r.jsx(Jv.ItemSlot,{scope:n,value:s,disabled:i,textValue:f,children:r.jsx(lt.div,{role:"option","aria-labelledby":_,"data-highlighted":m?"":void 0,"aria-selected":d&&m,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:b,onFocus:Oe(o.onFocus,()=>g(!0)),onBlur:Oe(o.onBlur,()=>g(!1)),onClick:Oe(o.onClick,()=>{w.current!=="mouse"&&A()}),onPointerUp:Oe(o.onPointerUp,()=>{w.current==="mouse"&&A()}),onPointerDown:Oe(o.onPointerDown,S=>{w.current=S.pointerType}),onPointerMove:Oe(o.onPointerMove,S=>{w.current=S.pointerType,i?c.onItemLeave?.():w.current==="mouse"&&S.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Oe(o.onPointerLeave,S=>{S.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:Oe(o.onKeyDown,S=>{c.searchRef?.current!==""&&S.key===" "||(__e.includes(S.key)&&A(),S.key===" "&&S.preventDefault())})})})})});R7.displayName=k0;var Jf="SelectItemText",D7=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:s,style:i,...a}=e,o=rc(Jf,n),l=ac(Jf,n),c=M7(Jf,n),d=C_e(Jf,n),[f,p]=y.useState(null),m=At(t,A=>p(A),c.onItemTextChange,A=>l.itemTextRefCallback?.(A,c.value,c.disabled)),g=f?.textContent,b=y.useMemo(()=>r.jsx("option",{value:c.value,disabled:c.disabled,children:g},c.value),[c.disabled,c.value,g]),{onNativeOptionAdd:_,onNativeOptionRemove:w}=d;return Ks(()=>(_(b),()=>w(b)),[_,w,b]),r.jsxs(r.Fragment,{children:[r.jsx(lt.span,{id:c.textId,...a,ref:m}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Xr.createPortal(a.children,o.valueNode):null]})});D7.displayName=Jf;var O7="SelectItemIndicator",P7=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e;return M7(O7,n).isSelected?r.jsx(lt.span,{"aria-hidden":!0,...s,ref:t}):null});P7.displayName=O7;var nC="SelectScrollUpButton",P_e=y.forwardRef((e,t)=>{const n=ac(nC,e.__scopeSelect),s=Gj(nC,e.__scopeSelect),[i,a]=y.useState(!1),o=At(t,s.onScrollButtonChange);return Ks(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=c.scrollTop>0;a(d)};const c=n.viewport;return l(),c.addEventListener("scroll",l),()=>c.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?r.jsx(I7,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:c}=n;l&&c&&(l.scrollTop=l.scrollTop-c.offsetHeight)}}):null});P_e.displayName=nC;var sC="SelectScrollDownButton",I_e=y.forwardRef((e,t)=>{const n=ac(sC,e.__scopeSelect),s=Gj(sC,e.__scopeSelect),[i,a]=y.useState(!1),o=At(t,s.onScrollButtonChange);return Ks(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=c.scrollHeight-c.clientHeight,f=Math.ceil(c.scrollTop)<d;a(f)};const c=n.viewport;return l(),c.addEventListener("scroll",l),()=>c.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?r.jsx(I7,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:c}=n;l&&c&&(l.scrollTop=l.scrollTop+c.offsetHeight)}}):null});I_e.displayName=sC;var I7=y.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:s,...i}=e,a=ac("SelectScrollButton",n),o=y.useRef(null),l=Zv(n),c=y.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return y.useEffect(()=>()=>c(),[c]),Ks(()=>{l().find(f=>f.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[l]),r.jsx(lt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Oe(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(s,50))}),onPointerMove:Oe(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(s,50))}),onPointerLeave:Oe(i.onPointerLeave,()=>{c()})})}),L_e="SelectSeparator",B_e=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e;return r.jsx(lt.div,{"aria-hidden":!0,...s,ref:t})});B_e.displayName=L_e;var iC="SelectArrow",z_e=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e,i=ey(n),a=rc(iC,n),o=ac(iC,n);return a.open&&o.position==="popper"?r.jsx(Tv,{...i,...s,ref:t}):null});z_e.displayName=iC;var $_e="SelectBubbleInput",L7=y.forwardRef(({__scopeSelect:e,value:t,...n},s)=>{const i=y.useRef(null),a=At(s,i),o=m7(t);return y.useEffect(()=>{const l=i.current;if(!l)return;const c=window.HTMLSelectElement.prototype,f=Object.getOwnPropertyDescriptor(c,"value").set;if(o!==t&&f){const p=new Event("change",{bubbles:!0});f.call(l,t),l.dispatchEvent(p)}},[o,t]),r.jsx(lt.select,{...n,style:{...G9,...n.style},ref:a,defaultValue:t})});L7.displayName=$_e;function B7(e){return e===""||e===void 0}function z7(e){const t=ia(e),n=y.useRef(""),s=y.useRef(0),i=y.useCallback(o=>{const l=n.current+o;t(l),(function c(d){n.current=d,window.clearTimeout(s.current),d!==""&&(s.current=window.setTimeout(()=>c(""),1e3))})(l)},[t]),a=y.useCallback(()=>{n.current="",window.clearTimeout(s.current)},[]);return y.useEffect(()=>()=>window.clearTimeout(s.current),[]),[n,i,a]}function $7(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,a=n?e.indexOf(n):-1;let o=V_e(e,Math.max(a,0));i.length===1&&(o=o.filter(d=>d!==n));const c=o.find(d=>d.textValue.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function V_e(e,t){return e.map((n,s)=>e[(t+s)%e.length])}var ss=x7,is=b7,Ds=y7,Yl=_7,rs=w7,as=A7,os=N7,Ro=E7,Do=T7,vn=R7,yn=D7,ui=P7;function bt({label:e,side:t="top",children:n}){return r.jsx(sj,{delayDuration:300,children:r.jsxs(iB,{children:[r.jsx(rB,{asChild:!0,children:n}),r.jsx(aB,{children:r.jsxs(oB,{side:t,sideOffset:6,className:"px-2 py-1 rounded-md bg-[#2A2A35] border border-[#3A3A48] text-[#F0F0F5] text-[11px] font-medium shadow-lg z-[9999] select-none",children:[e,r.jsx(lB,{className:"fill-[#2A2A35]"})]})})]})})}const Vp=[{label:"Local",tag:"local",models:[]},{label:"OpenRouter Free",tag:"free",provider:"openrouter",models:[{id:"openrouter/meta-llama/llama-3.3-70b-instruct:free",label:"Llama 3.3 70B"},{id:"openrouter/google/gemma-3-27b-it:free",label:"Gemma 3 27B"},{id:"openrouter/mistralai/mistral-7b-instruct:free",label:"Mistral 7B"}]},{label:"OpenRouter Paid",tag:"paid",provider:"openrouter",models:[{id:"openrouter/anthropic/claude-haiku-4.5",label:"Haiku 4.5"},{id:"openrouter/anthropic/claude-sonnet-4.6",label:"Sonnet 4.6"},{id:"openrouter/anthropic/claude-opus-4.7",label:"Opus 4.7"},{id:"openrouter/openai/gpt-5.4-mini",label:"GPT-5.4 mini"},{id:"openrouter/openai/gpt-5.4",label:"GPT-5.4"},{id:"openrouter/google/gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"openrouter/google/gemini-2.5-pro",label:"Gemini 2.5 Pro"}]},{label:"Anthropic",tag:"paid",provider:"anthropic",models:[{id:"anthropic/claude-haiku-4.5",label:"Haiku 4.5"},{id:"anthropic/claude-sonnet-4.6",label:"Sonnet 4.6"},{id:"anthropic/claude-opus-4.7",label:"Opus 4.7"}]},{label:"OpenAI",tag:"paid",provider:"openai",models:[{id:"openai/gpt-5.4-nano",label:"GPT-5.4 nano"},{id:"openai/gpt-5.4-mini",label:"GPT-5.4 mini"},{id:"openai/gpt-5.4",label:"GPT-5.4"}]},{label:"Google",tag:"paid",provider:"google",models:[{id:"google/gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro"}]}],jo={local:"text-[#10B981] bg-[#10B981]/10",free:"text-[#8B5CF6] bg-[#8B5CF6]/10",paid:"text-[#F59E0B] bg-[#F59E0B]/10",custom:"text-[#6366F1] bg-[#6366F1]/10"},U_e=["vllm/","ollama/","openrouter/","anthropic/","openai/","google/","claude-code/"];function E0(e){for(const t of U_e)if(e.startsWith(t))return e.slice(t.length);return e}function ta(e){if(!e)return"";for(const n of Vp){const s=n.models.find(i=>i.id===e);if(s)return s.label}const t=E0(e);for(const n of Vp){const s=n.models.find(i=>E0(i.id)===t);if(s)return s.label}return t}function Up(e){if(!e)return"custom";if(e.startsWith("vllm/")||e.startsWith("ollama/"))return"local";for(const n of Vp)if(n.models.some(s=>s.id===e))return n.tag;const t=E0(e);for(const n of Vp)if(n.models.some(s=>E0(s.id)===t))return n.tag;return e.startsWith("openrouter/")||e.startsWith("anthropic/")||e.startsWith("openai/")||e.startsWith("google/")||e.startsWith("claude-code/")?"paid":"custom"}function Vm(){const{data:e}=L.agents.discoverLocalModels.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),{data:t}=L.onboarding.providersConfigured.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),n=(e??[]).map(o=>({id:o.id,label:o.parameterSize?`${o.name} (${o.parameterSize})`:o.name})),s=Vp.map(o=>o.tag==="local"?{...o,models:n}:o).filter(o=>o.models.length===0?!1:!o.provider||t===void 0?!0:!!t[o.provider]),i=!!t&&(t.openrouter||t.anthropic||t.openai||t.google),a=t!==void 0&&!i;return{groups:s,needsHostedProviderSetup:a,needsOpenRouterSetup:a}}const H_e=8;function ty({value:e,onChange:t,onSubmit:n,placeholder:s="Add model ID...",className:i="",autoFocus:a=!1}){const{data:o}=L.agents.discoverLocalModels.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),{data:l}=L.onboarding.discoverProviderModels.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),c=y.useMemo(()=>{const w=(o??[]).map(S=>({id:S.id,label:S.parameterSize?`${S.name} (${S.parameterSize})`:S.name})),A=[...l?.openrouter??[],...l?.anthropic??[],...l?.openai??[],...l?.google??[]];return[...w,...A]},[o,l]),[d,f]=y.useState(!1),[p,m]=y.useState(0),g=y.useMemo(()=>{const w=e.trim().toLowerCase();return w?c.filter(A=>A.id.toLowerCase().includes(w)||A.label.toLowerCase().includes(w)).slice(0,H_e):[]},[e,c]);y.useEffect(()=>{m(0)},[e]);function b(w){if(w.key==="ArrowDown"){g.length>0&&(w.preventDefault(),f(!0),m(A=>Math.min(A+1,g.length-1)));return}if(w.key==="ArrowUp"){g.length>0&&(w.preventDefault(),f(!0),m(A=>Math.max(A-1,0)));return}if(w.key==="Tab"){if(d&&g[p]){w.preventDefault(),t(g[p].id);return}return}if(w.key==="Escape"){d&&(w.preventDefault(),f(!1));return}if(w.key==="Enter"){w.preventDefault();const A=d&&g[p]?g[p].id:e.trim();if(!A)return;n(A),f(!1)}}const _=y.useRef(null);return r.jsxs("div",{className:`relative ${i}`,children:[r.jsx("input",{ref:_,autoFocus:a,value:e,placeholder:s,onChange:w=>{t(w.target.value),f(!0)},onFocus:()=>{e&&f(!0)},onBlur:()=>{setTimeout(()=>f(!1),120)},onKeyDown:b,className:"w-full bg-[#13131A] border border-[#2A2A35] rounded px-2 py-1.5 text-[11px] text-[#C8C8D4] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] transition-colors"}),d&&g.length>0&&r.jsx("div",{className:"absolute left-0 right-0 top-full mt-1 bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 z-[10000] max-h-[240px] overflow-y-auto",children:g.map((w,A)=>r.jsxs("button",{type:"button",onMouseDown:S=>{S.preventDefault(),n(w.id),f(!1)},onMouseEnter:()=>m(A),className:`block w-full text-left px-3 py-1.5 text-[11px] outline-none transition-colors ${A===p?"bg-white/10 text-[#F0F0F5]":"text-[#C8C8D4] hover:bg-white/5"}`,children:[r.jsx("div",{className:"truncate",children:w.id}),w.label!==w.id&&r.jsx("div",{className:"truncate text-[10px] text-[#5A5A6E]",children:w.label})]},w.id))})]})}const hR={sessionTokensIn:0,sessionTokensOut:0,sessionCostUsd:0,contextWindow:null},ny=$o(e=>({stats:{},setStats:(t,n)=>e(s=>({stats:{...s.stats,[t]:n}})),updateFromWs:(t,n)=>e(s=>({stats:{...s.stats,[t]:{...s.stats[t]??hR,...n}}})),clearStats:t=>e(n=>({stats:{...n.stats,[t]:hR}}))}));function bA(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function fR(e){return e<.005?"$0.00":e<1?`$${e.toFixed(2)}`:`$${e.toFixed(2)}`}const W_e=1e5;function q_e({channelId:e}){const t=L.useUtils(),{data:n}=L.channels.sessionStats.useQuery({channelId:e}),{stats:s,setStats:i,clearStats:a}=ny(),o=L.channels.resetSessionStats.useMutation({onSuccess:()=>{a(e),t.channels.sessionStats.invalidate({channelId:e})}});y.useEffect(()=>{n&&i(e,n)},[n,e,i]);const l=s[e];if(!l)return null;const c=l.sessionTokensIn+l.sessionTokensOut;if(c===0)return null;const d=l.contextWindow??W_e,f=l.sessionTokensIn/d,p=f>.8?"text-red-400":f>.5?"text-amber-400":"text-[#5A5A6E]";return r.jsxs(Ys,{children:[r.jsx(ci,{asChild:!0,children:r.jsxs("button",{className:`flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium transition-colors hover:bg-white/5 ${p}`,children:[r.jsx("span",{children:bA(c)}),r.jsx("span",{className:"opacity-50",children:"·"}),r.jsx("span",{children:fR(l.sessionCostUsd)})]})}),r.jsx(Qs,{children:r.jsxs(Xs,{align:"end",sideOffset:6,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl w-[220px] z-50 p-3",children:[r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Input tokens"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] font-medium",children:bA(l.sessionTokensIn)})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Output tokens"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] font-medium",children:bA(l.sessionTokensOut)})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Total cost"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] font-medium",children:fR(l.sessionCostUsd)})]}),r.jsxs("div",{className:"pt-1",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Context usage"}),r.jsxs("span",{className:"text-[11px] text-[#5A5A6E]",children:[Math.round(f*100),"%"]})]}),r.jsx("div",{className:"h-1.5 bg-[#2A2A35] rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full rounded-full transition-all ${f>.8?"bg-red-400":f>.5?"bg-amber-400":"bg-[#6366F1]"}`,style:{width:`${Math.min(f*100,100)}%`}})})]}),r.jsx("button",{onClick:()=>o.mutate({channelId:e}),disabled:o.isPending,className:"w-full mt-1 px-2 py-1.5 rounded-md text-[11px] text-[#8A8A99] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors border border-[#2A2A35]",children:o.isPending?"Resetting...":"Reset counters"})]}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]})}const V7=$o()(gj(e=>({lastTab:{},setLast:(t,n)=>e(s=>({lastTab:{...s.lastTab,[t]:n}})),clearLast:t=>e(n=>{const s={...n.lastTab};return delete s[t],{lastTab:s}})}),{name:"damn-dev-last-active-tab"}));function pR(e,t){return e.tabName&&e.tabName.trim().length>0?e.tabName:t?"Main":`Tab ${e.tabOrder+1}`}function G_e({baseChannelId:e,activeTabId:t,agentColor:n}){const s=an(),i=L.useUtils(),{data:a=[]}=dfe(e),[o,l]=y.useState(null),[c,d]=y.useState(""),[f,p]=y.useState(null),m=y.useRef(null),g=y.useCallback(()=>{i.channels.get.invalidate({channelId:e}),i.channels.list.invalidate()},[i,e]),b=L.channels.createTab.useMutation({onSuccess:k=>{g(),s(`/channels/${k.id}`)}}),_=L.channels.renameTab.useMutation({onSuccess:g}),w=L.channels.deleteTab.useMutation({onSuccess:(k,T)=>{g(),p(null),T.channelId===t&&s(`/channels/${e}`)}});if(y.useEffect(()=>{o&&m.current&&(m.current.focus(),m.current.select())},[o]),e==="chan_coo")return null;const A=(k,T)=>{l(k),d(T)},S=()=>{if(!o)return;const k=c.trim(),T=a.find(F=>F.id===o);T&&k&&k!==pR(T,T.id===e)&&_.mutate({channelId:o,name:k}),l(null)},C=()=>{l(null),d("")},E=n??"#6366F1";return r.jsxs("div",{className:"flex items-center gap-1 px-3 h-9 border-t border-[#2A2A35] bg-[#0F0F11] overflow-x-auto scrollbar-none",children:[a.map(k=>{const T=k.id===t,F=k.id===e,M=k.unreadCount>0&&!T,I=o===k.id,R=pR(k,F),H=()=>{I||(T?A(k.id,R):(F&&V7.getState().clearLast(e),s(`/channels/${k.id}`)))};return r.jsx("div",{className:ye("group relative flex items-center gap-1.5 px-2.5 h-7 rounded-md text-[12px] transition-colors select-none flex-shrink-0",T?"bg-[#1A1A22] text-[#F0F0F5]":"text-[#8A8A99] hover:bg-[#15151B] hover:text-[#C0C0CC] cursor-pointer",T&&!I&&"cursor-text"),style:T?{boxShadow:`inset 0 -2px 0 ${E}`}:void 0,onClick:H,onDoubleClick:V=>{V.stopPropagation(),I||A(k.id,R)},children:I?r.jsx("input",{ref:m,value:c,onChange:V=>d(V.target.value),onBlur:S,onKeyDown:V=>{V.key==="Enter"?S():V.key==="Escape"&&C()},onClick:V=>V.stopPropagation(),onDoubleClick:V=>V.stopPropagation(),maxLength:80,className:"bg-transparent outline-none text-[12px] text-[#F0F0F5] w-[120px]"}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"truncate max-w-[140px]",title:R,children:R}),M&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:E}}),!F&&r.jsxs(Ys,{open:f===k.id,onOpenChange:V=>p(V?k.id:null),children:[r.jsx(ci,{asChild:!0,children:r.jsx("button",{onClick:V=>{V.stopPropagation(),p(k.id)},className:ye("transition-opacity text-[#6A6A78] hover:text-[#F0F0F5] ml-0.5",T||f===k.id?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":"Close tab",children:r.jsx(Te,{className:"w-3 h-3"})})}),r.jsx(Qs,{children:r.jsxs(Xs,{className:"bg-[#15151B] border border-[#2A2A35] rounded-lg shadow-xl p-3 w-[220px] z-50",sideOffset:8,onOpenAutoFocus:V=>V.preventDefault(),children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium mb-1",children:"Delete this tab?"}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99] mb-3 leading-snug",children:["All messages in “",R,"” will be permanently removed."]}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx("button",{onClick:V=>{V.stopPropagation(),p(null)},className:"px-2.5 h-6 rounded text-[11px] text-[#8A8A99] hover:bg-[#1A1A22] hover:text-[#F0F0F5] transition-colors",children:"Cancel"}),r.jsx("button",{onClick:V=>{V.stopPropagation(),w.mutate({channelId:k.id})},disabled:w.isPending,className:"px-2.5 h-6 rounded text-[11px] bg-red-500/10 text-red-400 hover:bg-red-500/20 transition-colors disabled:opacity-50",children:"Delete"})]}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]})]})},k.id)}),r.jsx("button",{onClick:()=>b.mutate({parentChannelId:e}),disabled:b.isPending,className:"flex items-center justify-center w-6 h-6 rounded-md text-[#6A6A78] hover:bg-[#15151B] hover:text-[#F0F0F5] transition-colors flex-shrink-0 disabled:opacity-50","aria-label":"New tab",children:r.jsx(wt,{className:"w-3.5 h-3.5"})})]})}function K_e(e){const t=Date.now()-e.getTime(),n=Math.floor(t/6e4);if(n<1)return"Last seen just now";if(n<60)return`Last seen ${n}m ago`;const s=Math.floor(n/60);return s<24?`Last seen ${s}h ago`:`Last seen ${Math.floor(s/24)}d ago`}function Y_e({userId:e}){const t=Sfe(e);return t?r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"relative flex items-center justify-center w-2 h-2",children:r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:t.online?"#10B981":"#3A3A45"}})}),r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:t.online?"Online":t.lastSeenAt?K_e(new Date(t.lastSeenAt)):"Offline"})]}):null}function Q_e({channelId:e,agentId:t,defaultModel:n,agentColor:s,customModels:i=[]}){const[a,o]=y.useState(""),{data:l}=L.agents.getConversationModel.useQuery({channelId:e}),c=L.agents.setConversationModel.useMutation(),d=L.agents.update.useMutation(),f=L.agents.addCustomModel.useMutation(),p=L.useUtils(),{groups:m,needsHostedProviderSetup:g}=Vm(),b=l?.model??null,_=b!==null,w=b??n,A=Up(w);function S(C){C==="__reset__"?c.mutate({channelId:e,model:null},{onSuccess:()=>p.agents.getConversationModel.invalidate({channelId:e})}):(c.mutate({channelId:e,model:C},{onSuccess:()=>p.agents.getConversationModel.invalidate({channelId:e})}),d.mutate({agentId:t,model:C},{onSuccess:()=>p.agents.list.invalidate()}))}return r.jsxs(ss,{value:w,onValueChange:S,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] border transition-colors outline-none border-opacity-40",style:{color:s,backgroundColor:`${s}15`,borderColor:`${s}40`},children:[r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[A]}`,children:A}),r.jsx(Ds,{children:ta(w)}),r.jsx(ft,{className:"w-3 h-3 opacity-60"})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:6,align:"end",className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] z-50",children:[r.jsxs(os,{children:[m.map(C=>r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:C.label}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo[C.tag]}`,children:C.tag})]}),C.models.map(E=>r.jsxs(vn,{value:E.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:E.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},E.id))]},C.label)),i.length>0&&r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:"Custom"}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo.custom}`,children:"custom"})]}),i.map(C=>r.jsxs(vn,{value:C,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:C}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},C))]}),_&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"my-1 border-t border-[#2A2A35]"}),r.jsx(vn,{value:"__reset__",className:"flex items-center px-3 py-1.5 text-[12px] text-[#8A8A99] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:r.jsx(yn,{children:"Reset to default"})})]})]}),g&&r.jsx(gn,{to:"/settings?tab=runtime",className:"block px-3 py-1.5 text-[11px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 border-t border-[#2A2A35] mt-1 transition-colors",children:"+ Configure providers →"}),r.jsx("div",{className:"px-2 pt-1 pb-2 border-t border-[#2A2A35] mt-1",children:r.jsx(ty,{value:a,onChange:o,onSubmit:C=>{f.mutate({agentId:t,modelId:C},{onSuccess:()=>p.agents.list.invalidate()}),S(C),o("")}})})]})})]})}function X_e({color:e}){return r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("span",{className:"relative flex items-center justify-center w-2 h-2",children:[r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:e,opacity:.5},animate:{scale:[1,2.2,1],opacity:[.5,0,.5]},transition:{duration:1.4,repeat:1/0}}),r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e}})]}),r.jsx("span",{className:"text-[12px]",style:{color:e},children:"Waiting for your approval"})]})}function J_e({status:e,color:t}){const n={thinking:"thinking",executing:"executing",idle:"idle",offline:"offline"},s=e==="thinking"||e==="executing";return r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("span",{className:"relative flex items-center justify-center w-2 h-2",children:[s&&r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:t,opacity:.5},animate:{scale:[1,2,1],opacity:[.5,0,.5]},transition:{duration:1.8,repeat:1/0}}),r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e==="offline"?"#3A3A45":t,opacity:e==="idle"?.5:1}})]}),r.jsx("span",{className:"text-[12px] text-[#8A8A99] capitalize",children:n[e]})]})}function Z_e({channelId:e,color:t}){const[n,s]=y.useState(!1),i=L.useUtils(),a=L.messages.resetSession.useMutation({onSuccess:()=>{s(!0),setTimeout(()=>s(!1),2e3),ny.getState().clearStats(e),i.channels.sessionStats.invalidate({channelId:e})}});return r.jsx(bt,{label:"Reset context",children:r.jsx("button",{onClick:()=>a.mutate({channelId:e}),className:"w-8 h-8 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",style:n?{color:t}:{},children:r.jsx(lh,{className:ye("w-4 h-4",a.isPending&&"animate-spin")})})})}function ewe({channelId:e,onCleared:t}){const[n,s]=y.useState(!1),i=L.useUtils(),a=L.messages.clearConversation.useMutation({onSuccess:()=>{s(!1),t?.(),ny.getState().clearStats(e),i.channels.sessionStats.invalidate({channelId:e})}});return n?r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{onClick:()=>a.mutate({channelId:e}),disabled:a.isPending,className:"px-2 py-1 rounded-md text-[11px] font-medium text-[#EF4444] bg-[#EF4444]/10 hover:bg-[#EF4444]/20 transition-colors",children:a.isPending?"Clearing...":"Confirm"}),r.jsx("button",{onClick:()=>s(!1),className:"px-2 py-1 rounded-md text-[11px] text-[#8A8A99] hover:bg-white/5 transition-colors",children:"Cancel"})]}):r.jsx(bt,{label:"Clear conversation",children:r.jsx("button",{onClick:()=>s(!0),className:"w-8 h-8 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors",children:r.jsx(Dn,{className:"w-4 h-4"})})})}function twe({channelId:e,color:t,onJump:n}){const{data:s=[]}=L.messages.pinned.useQuery({channelId:e});return s.length===0?null:r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-transparent hover:border-[#2A2A35]",children:[r.jsx(P5,{className:"w-3.5 h-3.5",style:{color:t}}),r.jsxs("span",{children:[s.length," pinned"]})]})}),r.jsx(Od,{children:r.jsxs(Xv,{align:"end",sideOffset:6,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 w-[300px] z-50",children:[r.jsx("div",{className:"px-3 py-2 border-b border-[#2A2A35]",children:r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Pinned Messages"})}),s.map(i=>r.jsxs(Bl,{onSelect:()=>n(i.id),className:"flex flex-col gap-0.5 px-3 py-2.5 cursor-pointer hover:bg-white/5 outline-none transition-colors",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#C8C8D4] truncate",children:i.sender.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] shrink-0",children:Ir(i.timestamp)})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] truncate",children:i.content}),r.jsx("span",{className:"text-[11px] text-[#6366F1] mt-0.5",children:"Jump to message"})]},i.id))]})})]})}function nwe({channelId:e}){const t=L.useUtils(),{data:n}=L.channelPreferences.get.useQuery({channelId:e}),s=n?.muted??!1,i=L.channelPreferences.set.useMutation({onMutate:async({muted:a})=>{await t.channelPreferences.get.cancel({channelId:e});const o=t.channelPreferences.get.getData({channelId:e});return t.channelPreferences.get.setData({channelId:e},l=>({...l,channelId:e,muted:a??!1,notifyOnMention:l?.notifyOnMention??!0})),{prev:o}},onError:(a,o,l)=>{l?.prev&&t.channelPreferences.get.setData({channelId:e},l.prev)},onSettled:()=>{t.channelPreferences.get.invalidate({channelId:e}),t.channelPreferences.listMuted.invalidate()}});return r.jsx(bt,{label:s?"Unmute channel":"Mute channel",children:r.jsx("button",{onClick:()=>i.mutate({channelId:e,muted:!s}),className:ye("w-8 h-8 flex items-center justify-center rounded-md transition-colors",s?"text-[#F59E0B] hover:bg-[#F59E0B]/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5"),children:s?r.jsx(tL,{className:"w-4 h-4"}):r.jsx(Ase,{className:"w-4 h-4"})})})}function swe({channel:e,agent:t,agentColor:n,hasPendingApproval:s=!1,rightPanelOpen:i,memoryPanelOpen:a,activeOverride:o,humanDmName:l,humanDmUserId:c,onToggleRightPanel:d,onToggleMemoryPanel:f,onAgentClick:p,onClearOverride:m,onClearConversation:g,onJumpToMessage:b}){const _=n??t?.color??"#6366F1",w=!!t&&e.channelType==="dm",A=e.channelType==="dm"&&!e.agentId,S=e.channelType==="topic",C=e.channelType==="group"||e.channelType==="topic",E=Uo(),k=L.channels.setResponseMode.useMutation(),T=L.useUtils();return r.jsxs("div",{className:"flex flex-col border-b border-[#2A2A35] bg-[#0F0F11] flex-shrink-0",style:w&&!S?{borderLeftColor:_,borderLeftWidth:3,borderLeftStyle:"solid"}:{},children:[r.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[A?r.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-[#6366F1] to-[#8B5CF6] flex items-center justify-center text-[11px] font-semibold text-white flex-shrink-0",children:(l??"U").split(" ").map(F=>F[0]).join("").slice(0,2).toUpperCase()}):t&&!S?r.jsx("button",{onClick:p,className:"w-8 h-8 rounded-full flex items-center justify-center text-lg flex-shrink-0 transition-opacity hover:opacity-80",style:{backgroundColor:`${_}26`},children:t.emoji}):r.jsx("div",{className:"w-8 h-8 rounded-full bg-[#2A2A35] flex items-center justify-center",children:r.jsx("span",{className:"text-[#8A8A99] text-sm",children:"#"})}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[A?r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:l??"User"}):t&&!S?r.jsx("button",{onClick:p,className:"text-[15px] font-semibold text-[#F0F0F5] hover:underline decoration-dashed underline-offset-2 transition-colors",children:t.name}):r.jsxs("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:["#",e.name]}),t&&!S&&r.jsx("span",{className:"text-[11px] text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded",children:t.role}),S&&r.jsxs("span",{className:"text-[11px] text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded border border-[#2A2A35] flex items-center gap-1",children:[e.visibility==="public"?r.jsx(Xt,{className:"w-3 h-3"}):r.jsx(Eo,{className:"w-3 h-3"}),"Topic"]})]}),t&&!S&&!s&&r.jsx(J_e,{status:t.status,color:_}),t&&!S&&s&&r.jsx(X_e,{color:_}),S&&e.description&&r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:e.description}),A&&r.jsx(Y_e,{userId:c}),!t&&!S&&!A&&r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:["#",e.name]})]})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[E&&t&&!S&&r.jsx(Q_e,{channelId:e.id,agentId:t.id,defaultModel:t.defaultModel,agentColor:_,customModels:(()=>{try{return t.customModels?JSON.parse(t.customModels):[]}catch{return[]}})()}),w&&!S&&r.jsx(q_e,{channelId:e.id}),w&&!S&&r.jsx(Z_e,{channelId:e.id,color:_}),w&&!S&&r.jsx(ewe,{channelId:e.id,onCleared:g}),S&&r.jsx(S$,{channel:e}),C&&r.jsx(bt,{label:e.responseMode==="mention"?"Agents respond only when @mentioned":"Agents respond to every message",children:r.jsxs("button",{onClick:()=>{const F=e.responseMode==="always"?"mention":"always";k.mutate({channelId:e.id,responseMode:F},{onSuccess:()=>T.channels.list.invalidate()})},className:ye("flex items-center gap-1 px-2 py-1 rounded-md text-[12px] border transition-colors",e.responseMode==="mention"?"text-[#A78BFA] bg-[#8B5CF6]/10 border-[#8B5CF6]/30":"text-[#8A8A99] border-transparent hover:border-[#2A2A35] hover:bg-white/5"),children:[e.responseMode==="mention"?r.jsx(eL,{className:"w-3.5 h-3.5"}):r.jsx(pL,{className:"w-3.5 h-3.5"}),r.jsx("span",{children:e.responseMode==="mention"?"mention":"auto"})]})}),r.jsx(nwe,{channelId:e.id}),r.jsx(twe,{channelId:e.id,color:S?"#8A8A99":_,onJump:b??(F=>{document.getElementById(`msg-${F}`)?.scrollIntoView({behavior:"smooth",block:"center"})})}),t&&!S&&r.jsx(bt,{label:a?"Close memory":"View memory",children:r.jsx("button",{onClick:f,className:ye("w-8 h-8 flex items-center justify-center rounded-md transition-colors",a?"text-[#F0F0F5] bg-white/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5"),children:r.jsx(Cse,{className:"w-4 h-4"})})}),r.jsx(bt,{label:i?"Close panel":"Open panel",children:r.jsx("button",{onClick:d,className:ye("w-8 h-8 flex items-center justify-center rounded-md transition-colors",i?"text-[#F0F0F5] bg-white/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5"),children:i?r.jsx(mL,{className:"w-4 h-4"}):r.jsx(xL,{className:"w-4 h-4"})})})]})]}),o&&r.jsxs(ne.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.25},className:"flex items-center justify-between px-5 py-2 bg-amber-500/10 border-t border-amber-500/20",children:[r.jsxs("p",{className:"text-[12px] text-amber-400 truncate",children:[r.jsx("span",{className:"font-medium",children:"Override active:"})," ",o.length>60?`${o.slice(0,60)}...`:o]}),r.jsx("button",{onClick:m,className:"ml-3 flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-amber-400/70 hover:text-amber-300 hover:bg-amber-500/10 transition-colors",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),e.channelType!=="terminal"&&e.id!=="chan_coo"&&r.jsx(G_e,{baseChannelId:e.parentChannelId??e.id,activeTabId:e.id,agentColor:_})]})}function U7({agent:e}){return r.jsxs("div",{className:"flex items-start gap-3 px-4 py-2.5",children:[r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-base flex-shrink-0 mt-0.5",style:{backgroundColor:`${e.color}26`},children:e.emoji}),r.jsxs("div",{className:"flex flex-col gap-1 pt-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[13px] font-semibold",style:{color:e.color},children:e.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:e.status==="thinking"?"thinking...":"executing..."})]}),r.jsx("div",{className:"flex items-center gap-1 px-3 py-2 rounded-lg rounded-tl-sm",style:{backgroundColor:`${e.color}0D`,border:`1px solid ${e.color}26`},children:[0,1,2].map(t=>r.jsx(ne.span,{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:e.color},animate:{opacity:[.3,1,.3],scale:[.8,1.1,.8]},transition:{duration:1.4,repeat:1/0,delay:t*.2,ease:"easeInOut"}},t))})]})]})}function iwe(e){return new Promise((t,n)=>{const s=new FileReader;s.onload=()=>t(s.result.split(",")[1]),s.onerror=n,s.readAsDataURL(e)})}function rwe({staged:e,onRemove:t}){const n=e.file.type.startsWith("image/"),s=Math.round(e.file.size/1024);return r.jsxs(ne.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{duration:.15},className:"relative group/card flex-shrink-0",children:[r.jsx("button",{onClick:t,className:"absolute -top-1.5 -right-1.5 w-4 h-4 bg-[#2A2A35] border border-[#3A3A45] rounded-full flex items-center justify-center text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-[#EF4444]/20 transition-colors z-10 opacity-0 group-hover/card:opacity-100",children:r.jsx(Te,{className:"w-2.5 h-2.5"})}),n&&e.preview?r.jsx("div",{className:"w-[60px] h-[60px] rounded-lg overflow-hidden border border-[#2A2A35]",children:r.jsx("img",{src:e.preview,alt:e.file.name,className:"w-full h-full object-cover"})}):r.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2 bg-[#1C1C24] border border-[#2A2A35] rounded-lg max-w-[160px]",children:[r.jsx("div",{className:"w-6 h-6 rounded bg-[#2A2A35] flex items-center justify-center flex-shrink-0",children:r.jsx("span",{className:"text-[9px] font-semibold text-[#8A8A99] uppercase",children:e.file.name.split(".").pop()?.slice(0,3)??"file"})}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-[11px] text-[#C8C8D4] font-medium truncate",children:e.file.name}),r.jsxs("div",{className:"text-[10px] text-[#8A8A99]",children:[s,"KB"]})]})]}),e.uploadedId===void 0&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center rounded-lg bg-black/40",children:r.jsx("div",{className:"w-3 h-3 border-2 border-white/30 border-t-white rounded-full animate-spin"})})]})}function H7({channelId:e,channelName:t,agent:n,agentColor:s,onSend:i,disabled:a,placeholder:o,mentionableParticipants:l=[]}){const[c,d]=y.useState(""),[f,p]=y.useState(!1),[m,g]=y.useState([]),[b,_]=y.useState(!1),[w,A]=y.useState(null),[S,C]=y.useState(0),[E,k]=y.useState(-1),[T,F]=y.useState(!1),M=y.useRef(null),I=y.useRef(null),R=s??n?.color,H=!!n&&(n.status==="thinking"||n.status==="executing"),V=Uo(),K=L.agents.cancelThinking.useMutation(),q=L.attachments.upload.useMutation(),$=y.useMemo(()=>{if(w===null||l.length===0)return[];const se=w.toLowerCase();return l.filter(ae=>ae.name.toLowerCase().startsWith(se))},[w,l]);y.useEffect(()=>{const se=w!==null&&$.length>0;F(se),se&&C(0)},[w,$.length]);function B(se,ae){if(l.length===0){A(null);return}const le=se.slice(0,ae),ge=le.lastIndexOf("@");if(ge===-1||ge>0&&le[ge-1]!==" "&&le[ge-1]!==`
131
+ `))}function c(g,b,_,w){const A=_.enter("tableCell"),S=_.enter("phrasing"),C=_.containerPhrasing(g,{...w,before:a,after:a});return S(),A(),C}function d(g,b){return nve(g,{align:b,alignDelimiters:s,padding:n,stringLength:i})}function f(g,b,_){const w=g.children;let A=-1;const S=[],C=b.enter("table");for(;++A<w.length;)S[A]=p(w[A],b,_);return C(),S}function p(g,b,_){const w=g.children;let A=-1;const S=[],C=b.enter("tableRow");for(;++A<w.length;)S[A]=c(w[A],g,b,_);return C(),S}function m(g,b,_){let w=d$.inlineCode(g,b,_);return _.stack.includes("tableCell")&&(w=w.replace(/\|/g,"\\$&")),w}}function Hve(){return{exit:{taskListCheckValueChecked:rR,taskListCheckValueUnchecked:rR,paragraph:qve}}}function Wve(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:Gve}}}function rR(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function qve(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const s=n.children[0];if(s&&s.type==="text"){const i=t.children;let a=-1,o;for(;++a<i.length;){const l=i[a];if(l.type==="paragraph"){o=l;break}}o===n&&(s.value=s.value.slice(1),s.value.length===0?n.children.shift():n.position&&s.position&&typeof s.position.start.offset=="number"&&(s.position.start.column++,s.position.start.offset++,n.position.start=Object.assign({},s.position.start)))}}this.exit(e)}function Gve(e,t,n,s){const i=e.children[0],a=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",l=n.createTracker(s);a&&l.move(o);let c=d$.listItem(e,t,n,{...s,...l.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,d)),c;function d(f){return f+o}}function Kve(){return[C0e(),q0e(),Q0e(),Ive(),Hve()]}function Yve(e){return{extensions:[j0e(),G0e(e),X0e(),Uve(e),Wve()]}}const Qve={tokenize:nye,partial:!0},h$={tokenize:sye,partial:!0},f$={tokenize:iye,partial:!0},p$={tokenize:rye,partial:!0},Xve={tokenize:aye,partial:!0},m$={name:"wwwAutolink",tokenize:eye,previous:g$},x$={name:"protocolAutolink",tokenize:tye,previous:b$},Ho={name:"emailAutolink",tokenize:Zve,previous:v$},Ga={};function Jve(){return{text:Ga}}let Ec=48;for(;Ec<123;)Ga[Ec]=Ho,Ec++,Ec===58?Ec=65:Ec===91&&(Ec=97);Ga[43]=Ho;Ga[45]=Ho;Ga[46]=Ho;Ga[95]=Ho;Ga[72]=[Ho,x$];Ga[104]=[Ho,x$];Ga[87]=[Ho,m$];Ga[119]=[Ho,m$];function Zve(e,t,n){const s=this;let i,a;return o;function o(p){return!XS(p)||!v$.call(s,s.previous)||Oj(s.events)?n(p):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(p))}function l(p){return XS(p)?(e.consume(p),l):p===64?(e.consume(p),c):n(p)}function c(p){return p===46?e.check(Xve,f,d)(p):p===45||p===95||Hs(p)?(a=!0,e.consume(p),c):f(p)}function d(p){return e.consume(p),i=!0,c}function f(p){return a&&i&&ii(s.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(p)):n(p)}}function eye(e,t,n){const s=this;return i;function i(o){return o!==87&&o!==119||!g$.call(s,s.previous)||Oj(s.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Qve,e.attempt(h$,e.attempt(f$,a),n),n)(o))}function a(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function tye(e,t,n){const s=this;let i="",a=!1;return o;function o(p){return(p===72||p===104)&&b$.call(s,s.previous)&&!Oj(s.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(p),e.consume(p),l):n(p)}function l(p){if(ii(p)&&i.length<5)return i+=String.fromCodePoint(p),e.consume(p),l;if(p===58){const m=i.toLowerCase();if(m==="http"||m==="https")return e.consume(p),c}return n(p)}function c(p){return p===47?(e.consume(p),a?d:(a=!0,c)):n(p)}function d(p){return p===null||_0(p)||Wt(p)||cu(p)||Vv(p)?n(p):e.attempt(h$,e.attempt(f$,f),n)(p)}function f(p){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(p)}}function nye(e,t,n){let s=0;return i;function i(o){return(o===87||o===119)&&s<3?(s++,e.consume(o),i):o===46&&s===3?(e.consume(o),a):n(o)}function a(o){return o===null?n(o):t(o)}}function sye(e,t,n){let s,i,a;return o;function o(d){return d===46||d===95?e.check(p$,c,l)(d):d===null||Wt(d)||cu(d)||d!==45&&Vv(d)?c(d):(a=!0,e.consume(d),o)}function l(d){return d===95?s=!0:(i=s,s=void 0),e.consume(d),o}function c(d){return i||s||!a?n(d):t(d)}}function iye(e,t){let n=0,s=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&s<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(p$,t,a)(o):o===null||Wt(o)||cu(o)?t(o):(e.consume(o),i)}function a(o){return o===41&&s++,e.consume(o),i}}function rye(e,t,n){return s;function s(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),s):l===38?(e.consume(l),a):l===93?(e.consume(l),i):l===60||l===null||Wt(l)||cu(l)?t(l):n(l)}function i(l){return l===null||l===40||l===91||Wt(l)||cu(l)?t(l):s(l)}function a(l){return ii(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),s):ii(l)?(e.consume(l),o):n(l)}}function aye(e,t,n){return s;function s(a){return e.consume(a),i}function i(a){return Hs(a)?n(a):t(a)}}function g$(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Wt(e)}function b$(e){return!ii(e)}function v$(e){return!(e===47||XS(e))}function XS(e){return e===43||e===45||e===46||e===95||Hs(e)}function Oj(e){let t=e.length,n=!1;for(;t--;){const s=e[t][1];if((s.type==="labelLink"||s.type==="labelImage")&&!s._balanced){n=!0;break}if(s._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const oye={tokenize:mye,partial:!0};function lye(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:hye,continuation:{tokenize:fye},exit:pye}},text:{91:{name:"gfmFootnoteCall",tokenize:dye},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:cye,resolveTo:uye}}}}function cye(e,t,n){const s=this;let i=s.events.length;const a=s.parser.gfmFootnotes||(s.parser.gfmFootnotes=[]);let o;for(;i--;){const c=s.events[i][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const d=ea(s.sliceSerialize({start:o.end,end:s.now()}));return d.codePointAt(0)!==94||!a.includes(d.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function uye(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const s={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},l=[e[n+1],e[n+2],["enter",s,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",a,t],["enter",o,t],["exit",o,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",s,t]];return e.splice(n,e.length-n+1,...l),e}function dye(e,t,n){const s=this,i=s.parser.gfmFootnotes||(s.parser.gfmFootnotes=[]);let a=0,o;return l;function l(p){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),c}function c(p){return p!==94?n(p):(e.enter("gfmFootnoteCallMarker"),e.consume(p),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",d)}function d(p){if(a>999||p===93&&!o||p===null||p===91||Wt(p))return n(p);if(p===93){e.exit("chunkString");const m=e.exit("gfmFootnoteCallString");return i.includes(ea(s.sliceSerialize(m)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(p)}return Wt(p)||(o=!0),a++,e.consume(p),p===92?f:d}function f(p){return p===91||p===92||p===93?(e.consume(p),a++,d):d(p)}}function hye(e,t,n){const s=this,i=s.parser.gfmFootnotes||(s.parser.gfmFootnotes=[]);let a,o=0,l;return c;function c(b){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),d}function d(b){return b===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",f):n(b)}function f(b){if(o>999||b===93&&!l||b===null||b===91||Wt(b))return n(b);if(b===93){e.exit("chunkString");const _=e.exit("gfmFootnoteDefinitionLabelString");return a=ea(s.sliceSerialize(_)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),m}return Wt(b)||(l=!0),o++,e.consume(b),b===92?p:f}function p(b){return b===91||b===92||b===93?(e.consume(b),o++,f):f(b)}function m(b){return b===58?(e.enter("definitionMarker"),e.consume(b),e.exit("definitionMarker"),i.includes(a)||i.push(a),vt(e,g,"gfmFootnoteDefinitionWhitespace")):n(b)}function g(b){return t(b)}}function fye(e,t,n){return e.check(Pm,t,e.attempt(oye,t,n))}function pye(e){e.exit("gfmFootnoteDefinition")}function mye(e,t,n){const s=this;return vt(e,i,"gfmFootnoteDefinitionIndent",5);function i(a){const o=s.events[s.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(a):n(a)}}function xye(e){let n=(e||{}).singleTilde;const s={name:"strikethrough",tokenize:a,resolveAll:i};return n==null&&(n=!0),{text:{126:s},insideSpan:{null:[s]},attentionMarkers:{null:[126]}};function i(o,l){let c=-1;for(;++c<o.length;)if(o[c][0]==="enter"&&o[c][1].type==="strikethroughSequenceTemporary"&&o[c][1]._close){let d=c;for(;d--;)if(o[d][0]==="exit"&&o[d][1].type==="strikethroughSequenceTemporary"&&o[d][1]._open&&o[c][1].end.offset-o[c][1].start.offset===o[d][1].end.offset-o[d][1].start.offset){o[c][1].type="strikethroughSequence",o[d][1].type="strikethroughSequence";const f={type:"strikethrough",start:Object.assign({},o[d][1].start),end:Object.assign({},o[c][1].end)},p={type:"strikethroughText",start:Object.assign({},o[d][1].end),end:Object.assign({},o[c][1].start)},m=[["enter",f,l],["enter",o[d][1],l],["exit",o[d][1],l],["enter",p,l]],g=l.parser.constructs.insideSpan.null;g&&tr(m,m.length,0,Uv(g,o.slice(d+1,c),l)),tr(m,m.length,0,[["exit",p,l],["enter",o[c][1],l],["exit",o[c][1],l],["exit",f,l]]),tr(o,d-1,c-d+3,m),c=d+m.length-2;break}}for(c=-1;++c<o.length;)o[c][1].type==="strikethroughSequenceTemporary"&&(o[c][1].type="data");return o}function a(o,l,c){const d=this.previous,f=this.events;let p=0;return m;function m(b){return d===126&&f[f.length-1][1].type!=="characterEscape"?c(b):(o.enter("strikethroughSequenceTemporary"),g(b))}function g(b){const _=Yd(d);if(b===126)return p>1?c(b):(o.consume(b),p++,g);if(p<2&&!n)return c(b);const w=o.exit("strikethroughSequenceTemporary"),A=Yd(b);return w._open=!A||A===2&&!!_,w._close=!_||_===2&&!!A,l(b)}}}class gye{constructor(){this.map=[]}add(t,n,s){bye(this,t,n,s)}consume(t){if(this.map.sort(function(a,o){return a[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const s=[];for(;n>0;)n-=1,s.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];s.push(t.slice()),t.length=0;let i=s.pop();for(;i;){for(const a of i)t.push(a);i=s.pop()}this.map.length=0}}function bye(e,t,n,s){let i=0;if(!(n===0&&s.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...s);return}i+=1}e.map.push([t,n,s])}}function vye(e,t){let n=!1;const s=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&s.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const a=s.length-1;s[a]=s[a]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return s}function yye(){return{flow:{null:{name:"table",tokenize:_ye,resolveAll:wye}}}}function _ye(e,t,n){const s=this;let i=0,a=0,o;return l;function l(R){let H=s.events.length-1;for(;H>-1;){const q=s.events[H][1].type;if(q==="lineEnding"||q==="linePrefix")H--;else break}const V=H>-1?s.events[H][1].type:null,K=V==="tableHead"||V==="tableRow"?T:c;return K===T&&s.parser.lazy[s.now().line]?n(R):K(R)}function c(R){return e.enter("tableHead"),e.enter("tableRow"),d(R)}function d(R){return R===124||(o=!0,a+=1),f(R)}function f(R){return R===null?n(R):qe(R)?a>1?(a=0,s.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(R),e.exit("lineEnding"),g):n(R):ht(R)?vt(e,f,"whitespace")(R):(a+=1,o&&(o=!1,i+=1),R===124?(e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),o=!0,f):(e.enter("data"),p(R)))}function p(R){return R===null||R===124||Wt(R)?(e.exit("data"),f(R)):(e.consume(R),R===92?m:p)}function m(R){return R===92||R===124?(e.consume(R),p):p(R)}function g(R){return s.interrupt=!1,s.parser.lazy[s.now().line]?n(R):(e.enter("tableDelimiterRow"),o=!1,ht(R)?vt(e,b,"linePrefix",s.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(R):b(R))}function b(R){return R===45||R===58?w(R):R===124?(o=!0,e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),_):k(R)}function _(R){return ht(R)?vt(e,w,"whitespace")(R):w(R)}function w(R){return R===58?(a+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(R),e.exit("tableDelimiterMarker"),A):R===45?(a+=1,A(R)):R===null||qe(R)?E(R):k(R)}function A(R){return R===45?(e.enter("tableDelimiterFiller"),S(R)):k(R)}function S(R){return R===45?(e.consume(R),S):R===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(R),e.exit("tableDelimiterMarker"),C):(e.exit("tableDelimiterFiller"),C(R))}function C(R){return ht(R)?vt(e,E,"whitespace")(R):E(R)}function E(R){return R===124?b(R):R===null||qe(R)?!o||i!==a?k(R):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(R)):k(R)}function k(R){return n(R)}function T(R){return e.enter("tableRow"),F(R)}function F(R){return R===124?(e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),F):R===null||qe(R)?(e.exit("tableRow"),t(R)):ht(R)?vt(e,F,"whitespace")(R):(e.enter("data"),M(R))}function M(R){return R===null||R===124||Wt(R)?(e.exit("data"),F(R)):(e.consume(R),R===92?I:M)}function I(R){return R===92||R===124?(e.consume(R),M):M(R)}}function wye(e,t){let n=-1,s=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],l=!1,c=0,d,f,p;const m=new gye;for(;++n<e.length;){const g=e[n],b=g[1];g[0]==="enter"?b.type==="tableHead"?(l=!1,c!==0&&(aR(m,t,c,d,f),f=void 0,c=0),d={type:"table",start:Object.assign({},b.start),end:Object.assign({},b.end)},m.add(n,0,[["enter",d,t]])):b.type==="tableRow"||b.type==="tableDelimiterRow"?(s=!0,p=void 0,a=[0,0,0,0],o=[0,n+1,0,0],l&&(l=!1,f={type:"tableBody",start:Object.assign({},b.start),end:Object.assign({},b.end)},m.add(n,0,[["enter",f,t]])),i=b.type==="tableDelimiterRow"?2:f?3:1):i&&(b.type==="data"||b.type==="tableDelimiterMarker"||b.type==="tableDelimiterFiller")?(s=!1,o[2]===0&&(a[1]!==0&&(o[0]=o[1],p=zg(m,t,a,i,void 0,p),a=[0,0,0,0]),o[2]=n)):b.type==="tableCellDivider"&&(s?s=!1:(a[1]!==0&&(o[0]=o[1],p=zg(m,t,a,i,void 0,p)),a=o,o=[a[1],n,0,0])):b.type==="tableHead"?(l=!0,c=n):b.type==="tableRow"||b.type==="tableDelimiterRow"?(c=n,a[1]!==0?(o[0]=o[1],p=zg(m,t,a,i,n,p)):o[1]!==0&&(p=zg(m,t,o,i,n,p)),i=0):i&&(b.type==="data"||b.type==="tableDelimiterMarker"||b.type==="tableDelimiterFiller")&&(o[3]=n)}for(c!==0&&aR(m,t,c,d,f),m.consume(t.events),n=-1;++n<t.events.length;){const g=t.events[n];g[0]==="enter"&&g[1].type==="table"&&(g[1]._align=vye(t.events,n))}return e}function zg(e,t,n,s,i,a){const o=s===1?"tableHeader":s===2?"tableDelimiter":"tableData",l="tableContent";n[0]!==0&&(a.end=Object.assign({},_d(t.events,n[0])),e.add(n[0],0,[["exit",a,t]]));const c=_d(t.events,n[1]);if(a={type:o,start:Object.assign({},c),end:Object.assign({},c)},e.add(n[1],0,[["enter",a,t]]),n[2]!==0){const d=_d(t.events,n[2]),f=_d(t.events,n[3]),p={type:l,start:Object.assign({},d),end:Object.assign({},f)};if(e.add(n[2],0,[["enter",p,t]]),s!==2){const m=t.events[n[2]],g=t.events[n[3]];if(m[1].end=Object.assign({},g[1].end),m[1].type="chunkText",m[1].contentType="text",n[3]>n[2]+1){const b=n[2]+1,_=n[3]-n[2]-1;e.add(b,_,[])}}e.add(n[3]+1,0,[["exit",p,t]])}return i!==void 0&&(a.end=Object.assign({},_d(t.events,i)),e.add(i,0,[["exit",a,t]]),a=void 0),a}function aR(e,t,n,s,i){const a=[],o=_d(t.events,n);i&&(i.end=Object.assign({},o),a.push(["exit",i,t])),s.end=Object.assign({},o),a.push(["exit",s,t]),e.add(n+1,0,a)}function _d(e,t){const n=e[t],s=n[0]==="enter"?"start":"end";return n[1][s]}const Aye={name:"tasklistCheck",tokenize:Cye};function Sye(){return{text:{91:Aye}}}function Cye(e,t,n){const s=this;return i;function i(c){return s.previous!==null||!s._gfmTasklistFirstContentOfListItem?n(c):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),a)}function a(c){return Wt(c)?(e.enter("taskListCheckValueUnchecked"),e.consume(c),e.exit("taskListCheckValueUnchecked"),o):c===88||c===120?(e.enter("taskListCheckValueChecked"),e.consume(c),e.exit("taskListCheckValueChecked"),o):n(c)}function o(c){return c===93?(e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),l):n(c)}function l(c){return qe(c)?t(c):ht(c)?e.check({tokenize:jye},t,n)(c):n(c)}}function jye(e,t,n){return vt(e,s,"whitespace");function s(i){return i===null?n(i):t(i)}}function Nye(e){return Fz([Jve(),lye(),xye(e),yye(),Sye()])}const kye={};function Fi(e){const t=this,n=e||kye,s=t.data(),i=s.micromarkExtensions||(s.micromarkExtensions=[]),a=s.fromMarkdownExtensions||(s.fromMarkdownExtensions=[]),o=s.toMarkdownExtensions||(s.toMarkdownExtensions=[]);i.push(Nye(n)),a.push(Kve()),o.push(Yve(n))}const Eye={"MEMORY.md":"Written by the agent. Edits may be overwritten.","KNOWLEDGE.md":"Distilled learning. Edits may be overwritten by reflection.","REFLEXION.md":"Earned constraints from failures. Edits may be overwritten.","HEARTBEAT.md":"Controls periodic agent behavior.","TOOLS.md":"Your local environment notes.","USER.md":"What the agent knows about you."},Fye={"CONTEXT.md":"Injected into every agent call in this channel.","NOTES.md":"Your notes. Not shared with agents."};function Tye({agentId:e,filename:t,onClose:n}){const{data:s}=pj(e),i=L.useUtils(),{data:a,isLoading:o,error:l}=L.agents.getFile.useQuery({agentId:e,filename:t},{retry:!1}),[c,d]=y.useState(!1),[f,p]=y.useState(""),[m,g]=y.useState(!1),[b,_]=y.useState(!1),[w,A]=y.useState(!1),S=y.useRef(null);y.useEffect(()=>{a&&a.content===""&&(p(""),d(!0))},[a]);const C=L.agents.setFile.useMutation({onSuccess:()=>{_(!0),setTimeout(()=>_(!1),1500),i.agents.getFile.invalidate({agentId:e,filename:t}),i.agents.listFiles.invalidate({agentId:e}),d(!1)}}),E=L.agents.resetFile.useMutation({onSuccess:V=>{i.agents.getFile.invalidate({agentId:e,filename:t}),A(!0),g(!1),setTimeout(()=>A(!1),1500),p(V.content),d(!1)}});function k(){p(a?.content??""),d(!0),setTimeout(()=>S.current?.focus(),50)}function T(){C.mutate({agentId:e,filename:t,content:f})}function F(){d(!1),p("")}function M(){if(!m){g(!0);return}E.mutate({agentId:e,filename:t})}const I=Eye[t],R=a?.hasDefault??!1,H=a?.content??"";return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35] flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s&&r.jsx("span",{className:"text-base flex-shrink-0",children:s.emoji}),r.jsxs("span",{className:"text-[13px] font-semibold text-[#F0F0F5] truncate",children:[s?.name??e," — ",t]})]}),r.jsx("button",{onClick:n,className:"w-6 h-6 flex items-center justify-center rounded text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors flex-shrink-0 ml-2",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),I&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:I})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[o&&r.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-4 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]}),l&&r.jsx("p",{className:"px-4 py-4 text-[13px] text-[#EF4444] italic",children:"Failed to load file."}),!o&&!l&&!c&&r.jsx("div",{className:"px-4 py-4 prose-message text-[13px]",children:H?r.jsx(Ei,{remarkPlugins:[Fi],children:H}):r.jsx("p",{className:"text-[#5A5A6E] italic",children:"Empty file."})}),!o&&!l&&c&&r.jsx("textarea",{ref:S,value:f,onChange:V=>p(V.target.value),onKeyDown:V=>{V.key==="Enter"&&V.metaKey&&(V.preventDefault(),T())},className:"w-full h-full min-h-[300px] bg-[#13131A] text-[#F0F0F5] text-[13px] font-mono px-4 py-4 resize-none outline-none border-none",spellCheck:!1})]}),r.jsxs("div",{className:"px-4 py-3 border-t border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsx("div",{className:"flex items-center gap-2",children:r.jsxs(Me,{mode:"wait",children:[b&&r.jsxs(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[12px] text-[#10B981] flex items-center gap-1",children:[r.jsx(Fe,{className:"w-3 h-3"})," Saved"]},"saved"),w&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[12px] text-[#F59E0B]",children:"Reset"},"reset")]})}),r.jsxs("div",{className:"flex items-center gap-2",children:[!c&&R&&!m&&r.jsxs("button",{onClick:M,disabled:E.isPending,className:"flex items-center gap-1 px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors disabled:opacity-40",children:[r.jsx(lh,{className:"w-3 h-3"}),"Reset"]}),m&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:["Reset ",t,"?"]}),r.jsx("button",{onClick:M,disabled:E.isPending,className:"px-2.5 py-1.5 rounded text-[12px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-40",children:"Confirm"}),r.jsx("button",{onClick:()=>g(!1),className:"px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:"Cancel"})]}),!c&&!m&&r.jsxs("button",{onClick:k,className:"flex items-center gap-1 px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:[r.jsx(oh,{className:"w-3 h-3"}),"Edit"]}),c&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:F,className:"px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:"Cancel"}),r.jsx("button",{onClick:T,disabled:C.isPending,className:"px-3 py-1.5 rounded text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5558E8] transition-colors disabled:opacity-40",children:C.isPending?"Saving...":"Save"}),r.jsx("kbd",{className:"text-[10px] bg-white/5 border border-[#2A2A35] px-1.5 py-0.5 rounded text-[#5A5A6E]",children:"⌘↵"})]})]})]})]})}function Mye({channelId:e,filename:t,onClose:n}){const{data:s}=ez(e),i=L.useUtils(),{data:a,isLoading:o,error:l}=L.channels.getFile.useQuery({channelId:e,filename:t},{retry:!1}),[c,d]=y.useState(!1),[f,p]=y.useState(""),[m,g]=y.useState(!1),b=y.useRef(null);y.useEffect(()=>{a!==void 0&&a.content===""&&(p(""),d(!0))},[a]);const _=L.channels.setFile.useMutation({onSuccess:()=>{g(!0),setTimeout(()=>g(!1),1500),i.channels.getFile.invalidate({channelId:e,filename:t}),i.channels.listFiles.invalidate({channelId:e}),d(!1)}});function w(){p(a?.content??""),d(!0),setTimeout(()=>b.current?.focus(),50)}function A(){_.mutate({channelId:e,filename:t,content:f})}function S(){d(!1),p("")}const C=Fye[t],E=a?.content??"";return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35] flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(Tp,{className:"w-3.5 h-3.5 text-[#8A8A99] flex-shrink-0"}),r.jsxs("span",{className:"text-[13px] font-semibold text-[#F0F0F5] truncate",children:[s?.name??e," — ",t]})]}),r.jsx("button",{onClick:n,className:"w-6 h-6 flex items-center justify-center rounded text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors flex-shrink-0 ml-2",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),C&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:C})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[o&&r.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-4 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]}),l&&r.jsx("p",{className:"px-4 py-4 text-[13px] text-[#EF4444] italic",children:"Failed to load file."}),!o&&!l&&!c&&r.jsx("div",{className:"px-4 py-4 prose-message text-[13px]",children:E?r.jsx(Ei,{remarkPlugins:[Fi],children:E}):r.jsx("p",{className:"text-[#5A5A6E] italic",children:"Empty file."})}),!o&&!l&&c&&r.jsx("textarea",{ref:b,value:f,onChange:k=>p(k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.metaKey&&(k.preventDefault(),A())},className:"w-full h-full min-h-[300px] bg-[#13131A] text-[#F0F0F5] text-[13px] font-mono px-4 py-4 resize-none outline-none border-none",spellCheck:!1})]}),r.jsxs("div",{className:"px-4 py-3 border-t border-[#2A2A35] flex items-center justify-end flex-shrink-0 gap-2",children:[r.jsx(Me,{mode:"wait",children:m&&r.jsxs(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[12px] text-[#10B981] flex items-center gap-1 mr-auto",children:[r.jsx(Fe,{className:"w-3 h-3"})," Saved"]},"saved")}),!c&&r.jsxs("button",{onClick:w,className:"flex items-center gap-1 px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:[r.jsx(oh,{className:"w-3 h-3"}),"Edit"]}),c&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:S,className:"px-2.5 py-1.5 rounded text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:"Cancel"}),r.jsx("button",{onClick:A,disabled:_.isPending,className:"px-3 py-1.5 rounded text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5558E8] transition-colors disabled:opacity-40",children:_.isPending?"Saving...":"Save"}),r.jsx("kbd",{className:"text-[10px] bg-white/5 border border-[#2A2A35] px-1.5 py-0.5 rounded text-[#5A5A6E]",children:"⌘↵"})]})]})]})}function Rye(){const{agentId:e,channelId:t,entityType:n,filename:s,close:i}=y0(),a=!!s&&!!n;return y.useEffect(()=>{if(!a)return;function o(l){l.key==="Escape"&&i()}return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[a,i]),r.jsx(Me,{children:a&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-[55]",onClick:i}),r.jsxs(ne.div,{initial:{x:-380},animate:{x:0},exit:{x:-380},transition:{duration:.15,ease:"easeOut"},className:"fixed top-0 h-screen w-[380px] bg-[#1C1C24] border-r border-[#2A2A35] flex flex-col z-[55] shadow-xl",style:{left:240},onClick:o=>o.stopPropagation(),children:[n==="agent"&&e&&s&&r.jsx(Tye,{agentId:e,filename:s,onClose:i}),n==="channel"&&t&&s&&r.jsx(Mye,{channelId:t,filename:s,onClose:i})]})]})})}const Dye={high:"#EF4444",normal:"#F59E0B",low:"#6366F1"},Oye={shell_exec:Ti,trust_config:Wl,skill_install:vL,file_edit:li,delegation_rule:Wl,generic:yL};function Pye({priority:e}){return r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:Dye[e]??"#5A5A6E"}})}function Iye({expiresAt:e}){if(!e)return null;const t=new Date(e).getTime()-Date.now();if(t<=0)return r.jsx("span",{className:"text-[10px] text-[#EF4444]",children:"Expired"});const n=Math.floor(t/36e5),s=Math.floor(t%36e5/6e4),i=n>0?`${n}h ${s}m`:`${s}m`;return r.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-[#5A5A6E]",children:[r.jsx(bm,{className:"w-2.5 h-2.5"}),i]})}const Pj={pending:"#F59E0B",working:"#6366F1",input_needed:"#8B5CF6",completed:"#10B981",failed:"#EF4444",cancelled:"#5A5A6E"},y$={pending:"○",working:"⏳",input_needed:"❓",completed:"✅",failed:"⚠️",cancelled:"🛑",blocked:"🚫"};function Lye(e,t){const n=e??t,s=Date.now()-new Date(n).getTime(),i=Math.floor(s/1e3);if(i<60)return`${i}s`;const a=Math.floor(i/60);return a<60?`${a}m`:`${Math.floor(a/60)}h ${a%60}m`}function _$(e){const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function w$({node:e,navigate:t,depth:n=0}){const s=e.children.length>1,i=Pj[e.status]??"#5A5A6E";return r.jsxs("div",{className:n>0?"ml-4 border-l border-[#2A2A35] pl-3":"",children:[r.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[r.jsx("span",{className:"text-[12px]",children:y$[e.status]??"•"}),r.jsxs("div",{className:"flex items-center gap-1",children:[e.toAgent&&r.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] flex-shrink-0",style:{backgroundColor:`${e.toAgent.color}26`},children:e.toAgent.emoji}),r.jsx("span",{className:"text-[11px] font-medium text-[#F0F0F5]",children:e.toAgent?.name??e.toAgentId})]}),r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:i}}),e.crossInstance&&r.jsx(Xt,{className:"w-2.5 h-2.5 text-[#A78BFA] flex-shrink-0"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:e.status.replace("_"," ")}),e.targetChannelId&&r.jsx("button",{onClick:()=>t(`/channels/${e.targetChannelId}`),className:"opacity-0 group-hover:opacity-100 transition-opacity text-[#5A5A6E] hover:text-[#8A8A99]",children:r.jsx(cs,{className:"w-2.5 h-2.5"})})]}),r.jsx("p",{className:"text-[10px] text-[#8A8A99] line-clamp-1 ml-6 mb-1",children:e.task}),e.crossInstance&&e.status==="failed"&&e.task.includes("cross-instance")&&r.jsx("p",{className:"text-[10px] text-[#A78BFA] ml-6 mb-1",children:"(cross-instance disabled)"}),s&&r.jsx("div",{className:"ml-6 mb-1",children:r.jsx("span",{className:"text-[9px] text-[#5A5A6E] uppercase tracking-wider",children:"parallel"})}),e.children.map(a=>r.jsx(w$,{node:a,navigate:t,depth:n+1},a.id))]})}function A$({taskId:e,navigate:t}){const{data:n,isLoading:s}=L.agentTasks.getChain.useQuery({taskId:e});return s?r.jsx("div",{className:"py-2 text-[11px] text-[#5A5A6E]",children:"Loading chain..."}):n?r.jsxs("div",{className:"py-2 px-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Zl,{className:"w-3 h-3 text-[#6366F1]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99]",children:"Task Chain"})]}),r.jsx(w$,{node:n,navigate:t})]}):r.jsx("div",{className:"py-2 text-[11px] text-[#5A5A6E]",children:"Chain not found"})}function Bye(){const{data:e}=L.agentTasks.stats.useQuery(void 0,{staleTime:3e4});return!e||e.totalTasks===0?null:r.jsxs("div",{className:"px-5 py-3 border-b border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(M5,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Delegation Stats"})]}),r.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[r.jsxs("div",{className:"bg-[#1C1C24] rounded-lg px-2.5 py-2 border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[16px] font-semibold text-[#F0F0F5]",children:e.totalTasks}),r.jsx("p",{className:"text-[9px] text-[#5A5A6E] uppercase",children:"Total"})]}),r.jsxs("div",{className:"bg-[#1C1C24] rounded-lg px-2.5 py-2 border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[16px] font-semibold text-[#6366F1]",children:e.activeTasks}),r.jsx("p",{className:"text-[9px] text-[#5A5A6E] uppercase",children:"Active"})]}),r.jsxs("div",{className:"bg-[#1C1C24] rounded-lg px-2.5 py-2 border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[16px] font-semibold text-[#10B981]",children:e.completedTasks}),r.jsx("p",{className:"text-[9px] text-[#5A5A6E] uppercase",children:"Done"})]}),r.jsxs("div",{className:"bg-[#1C1C24] rounded-lg px-2.5 py-2 border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[16px] font-semibold text-[#EF4444]",children:e.failedTasks}),r.jsx("p",{className:"text-[9px] text-[#5A5A6E] uppercase",children:"Failed"})]})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[10px] text-[#5A5A6E]",children:[e.avgDurationMs!=null&&r.jsxs("span",{children:["Avg: ",_$(e.avgDurationMs)]}),e.totalTokensUsed>0&&r.jsxs("span",{children:[e.totalTokensUsed.toLocaleString()," tokens"]}),e.crossInstanceTasks.total>0&&r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx(Xt,{className:"w-2.5 h-2.5"}),e.crossInstanceTasks.total," cross-instance"]})]})]})}function zye({navigate:e}){const{data:t=[],isLoading:n}=L.agentTasks.active.useQuery(void 0,{refetchInterval:5e3}),s=L.agentTasks.cancel.useMutation(),[i,a]=y.useState(new Set);if(n||t.length===0)return null;function o(l){a(c=>{const d=new Set(c);return d.has(l)?d.delete(l):d.add(l),d})}return r.jsxs("div",{className:"border-b border-[#2A2A35]",children:[r.jsxs("div",{className:"px-5 py-3 flex items-center gap-2",children:[r.jsx(cse,{className:"w-3.5 h-3.5 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] font-semibold text-[#F0F0F5]",children:"Active Tasks"}),r.jsx("span",{className:"bg-[#6366F1] text-white text-[10px] font-bold rounded-full min-w-[18px] h-[18px] flex items-center justify-center px-1 leading-none",children:t.length})]}),t.map(l=>r.jsxs("div",{className:"px-5 py-2.5 hover:bg-white/[0.02] transition-colors border-t border-[#2A2A35]/30",children:[r.jsxs("div",{className:"flex items-start gap-2.5",children:[r.jsxs("div",{className:"flex -space-x-1.5 flex-shrink-0 mt-0.5",children:[l.fromAgent&&r.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center text-[11px] border border-[#13131A]",style:{backgroundColor:`${l.fromAgent.color}26`},title:l.fromAgent.name,children:l.fromAgent.emoji}),l.toAgent&&r.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center text-[11px] border border-[#13131A]",style:{backgroundColor:`${l.toAgent.color}26`},title:l.toAgent.name,children:l.toAgent.emoji})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[r.jsxs("span",{className:"text-[11px] font-medium text-[#F0F0F5] truncate",children:[l.fromAgent?.name??l.fromAgentId," → ",l.toAgent?.name??l.toAgentId]}),r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:Pj[l.status]??"#5A5A6E"}}),l.crossInstance&&r.jsx(Xt,{className:"w-2.5 h-2.5 text-[#A78BFA] flex-shrink-0"})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] line-clamp-1",children:l.task}),r.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:[Lye(l.startedAt,l.createdAt)," · depth ",l.depth," · ",l.status.replace("_"," ")]}),l.parentTaskId&&r.jsxs("button",{onClick:c=>{c.stopPropagation(),o(l.id)},className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors",children:[r.jsx(Zl,{className:"w-2.5 h-2.5"}),"Chain"]}),r.jsxs("button",{onClick:c=>{c.stopPropagation(),s.mutate({taskId:l.id})},disabled:s.isPending,className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-40 ml-auto",children:[r.jsx(L5,{className:"w-2.5 h-2.5"}),"Cancel"]}),l.channelId&&r.jsx("button",{onClick:()=>e(`/channels/${l.channelId}`),className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/[0.04] transition-colors",children:r.jsx(cs,{className:"w-2.5 h-2.5"})})]})]})]}),r.jsx(Me,{children:i.has(l.id)&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden ml-8 mt-1 border-l border-[#2A2A35] pl-3",children:r.jsx(A$,{taskId:l.id,navigate:e})})})]},l.id))]})}function $ye({navigate:e}){const[t,n]=y.useState(!1),[s,i]=y.useState(new Set),{data:a}=L.agentTasks.list.useQuery({status:"completed",limit:10},{staleTime:3e4}),{data:o}=L.agentTasks.list.useQuery({status:"failed",limit:10},{staleTime:3e4}),l=a?.items??[],d=[...o?.items??[],...l].sort((p,m)=>m.createdAt.localeCompare(p.createdAt)).slice(0,10);if(d.length===0)return null;function f(p){i(m=>{const g=new Set(m);return g.has(p)?g.delete(p):g.add(p),g})}return r.jsxs("div",{className:"border-b border-[#2A2A35]",children:[r.jsxs("button",{onClick:()=>n(p=>!p),className:"w-full px-5 py-2.5 flex items-center gap-2 hover:bg-white/[0.02] transition-colors",children:[t?r.jsx(ah,{className:"w-3 h-3 text-[#5A5A6E]"}):r.jsx(ft,{className:"w-3 h-3 text-[#5A5A6E]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:"Recent Completed/Failed"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:d.length})]}),r.jsx(Me,{children:t&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:d.map(p=>r.jsxs("div",{className:"px-5 py-2 hover:bg-white/[0.02] transition-colors border-t border-[#2A2A35]/30",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[10px]",children:y$[p.status]??"•"}),r.jsxs("div",{className:"flex -space-x-1.5 flex-shrink-0",children:[p.fromAgent&&r.jsx("span",{className:"text-[10px]",children:p.fromAgent.emoji}),r.jsx("span",{className:"text-[9px] text-[#5A5A6E] mx-0.5",children:"→"}),p.toAgent&&r.jsx("span",{className:"text-[10px]",children:p.toAgent.emoji})]}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] flex-1 truncate",children:p.task}),p.crossInstance&&r.jsx(Xt,{className:"w-2.5 h-2.5 text-[#A78BFA] flex-shrink-0"}),p.completedAt&&p.startedAt&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:_$(new Date(p.completedAt).getTime()-new Date(p.startedAt).getTime())}),p.parentTaskId&&r.jsx("button",{onClick:m=>{m.stopPropagation(),f(p.id)},className:"text-[#6366F1] hover:bg-[#6366F1]/10 rounded p-0.5 transition-colors",children:r.jsx(Zl,{className:"w-2.5 h-2.5"})}),p.channelId&&r.jsx("button",{onClick:()=>e(`/channels/${p.channelId}`),className:"text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:r.jsx(cs,{className:"w-2.5 h-2.5"})})]}),r.jsx(Me,{children:s.has(p.id)&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden ml-6 mt-1",children:r.jsx(A$,{taskId:p.id,navigate:e})})})]},p.id))})})]})}function Vye(){const[e,t]=y.useState(!1),[n,s]=y.useState("all"),{data:i=[]}=L.agentTasks.crossInstanceAudit.useQuery({limit:50,decision:n==="all"?void 0:n},{staleTime:3e4});return i.length===0&&n==="all"?null:r.jsxs("div",{className:"border-b border-[#2A2A35]",children:[r.jsxs("button",{onClick:()=>t(a=>!a),className:"w-full px-5 py-2.5 flex items-center gap-2 hover:bg-white/[0.02] transition-colors",children:[e?r.jsx(ah,{className:"w-3 h-3 text-[#A78BFA]"}):r.jsx(ft,{className:"w-3 h-3 text-[#A78BFA]"}),r.jsx(Xt,{className:"w-3 h-3 text-[#A78BFA]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#A78BFA] uppercase tracking-widest",children:"Cross-Instance Audit"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:i.length})]}),r.jsx(Me,{children:e&&r.jsxs(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:[r.jsx("div",{className:"flex gap-1 px-5 py-1.5",children:["all","allowed","blocked"].map(a=>r.jsx("button",{onClick:()=>s(a),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${n===a?"bg-[#A78BFA] text-white":"bg-white/5 text-[#8A8A99] hover:text-[#C8C8D4]"}`,children:a},a))}),i.map(a=>r.jsxs("div",{className:"px-5 py-2 hover:bg-white/[0.02] transition-colors border-t border-[#2A2A35]/30",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-medium ${a.decision==="allowed"?"bg-[#10B981]/10 text-[#10B981]":"bg-[#EF4444]/10 text-[#EF4444]"}`,children:a.decision}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a.fromAgent&&r.jsx("span",{className:"text-[10px]",children:a.fromAgent.emoji}),r.jsx("span",{className:"text-[9px] text-[#5A5A6E]",children:"→"}),a.toAgent&&r.jsx("span",{className:"text-[10px]",children:a.toAgent.emoji})]}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] flex-1 truncate",children:a.taskSummary}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] flex-shrink-0",children:Ir(a.timestamp)}),a.status!=="blocked"&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:Pj[a.status]??"#5A5A6E"}})]}),r.jsxs("div",{className:"flex items-center gap-1 mt-0.5 ml-14",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:a.fromAgent?.name??a.fromAgentId}),r.jsx("span",{className:"text-[9px] text-[#5A5A6E]",children:"→"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:a.toAgent?.name??a.toAgentId})]})]},a.id)),i.length===0&&r.jsx("p",{className:"px-5 py-3 text-[11px] text-[#5A5A6E] italic",children:"No cross-instance delegations found."})]})})]})}function Uye({onClose:e}){const t=an(),n=L.useUtils(),[s,i]=y.useState(new Set),[a,o]=y.useState(null),[l,c]=y.useState(""),[d,f]=y.useState(!1),[p,m]=y.useState(""),[g,b]=y.useState(new Set),{data:_,isLoading:w}=L.approvals.list.useQuery({status:"pending"},{refetchInterval:1e4}),A=L.approvals.decide.useMutation({onSuccess:()=>{n.approvals.list.invalidate(),n.approvals.pendingCount.invalidate()}}),S=L.approvals.batchApprove.useMutation({onSuccess:()=>{i(new Set),n.approvals.list.invalidate(),n.approvals.pendingCount.invalidate()}}),C=L.approvals.batchReject.useMutation({onSuccess:()=>{i(new Set),f(!1),m(""),n.approvals.list.invalidate(),n.approvals.pendingCount.invalidate()}}),E=[..._?.items??[]].sort(($,B)=>B.createdAt.localeCompare($.createdAt)),k=E.filter($=>$.messageId).map($=>$.messageId),T=[...s].filter($=>k.includes($));function F($){i(B=>{const Y=new Set(B);return Y.has($)?Y.delete($):Y.add($),Y})}function M(){s.size===k.length?i(new Set):i(new Set(k))}function I($){A.mutate({messageId:$,decision:"approved"})}function R($){A.mutate({messageId:$,decision:"rejected",rejectionNote:l||void 0}),o(null),c("")}function H(){T.length!==0&&S.mutate({messageIds:T})}function V(){T.length!==0&&C.mutate({messageIds:T,rejectionNote:p||void 0})}function K($){b(B=>{const Y=new Set(B);return Y.has($)?Y.delete($):Y.add($),Y})}function q($){t(`/channels/${$}`),e()}return r.jsxs(r.Fragment,{children:[r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-40",style:{backdropFilter:"blur(2px)",backgroundColor:"rgba(0,0,0,0.25)"},onClick:e}),r.jsxs(ne.div,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.3,ease:[.16,1,.3,1]},className:"fixed right-0 top-0 h-screen w-[420px] bg-[#13131A] border-l border-[#2A2A35] flex flex-col z-50 shadow-2xl",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2.5",children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Pending Approvals"}),E.length>0&&r.jsx("span",{className:"bg-[#EF4444] text-white text-[10px] font-bold rounded-full min-w-[18px] h-[18px] flex items-center justify-center px-1 leading-none",children:E.length})]}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),T.length>0&&r.jsx("div",{className:"px-5 py-3 border-b border-[#2A2A35]/50 flex flex-col gap-2 flex-shrink-0",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-[12px] text-[#8A8A99]",children:[T.length," selected"]}),r.jsxs("button",{onClick:H,disabled:S.isPending,className:"flex items-center gap-1 px-2.5 py-1 rounded-md bg-[#10B981]/15 text-[#10B981] text-[11px] font-medium hover:bg-[#10B981]/25 transition-colors disabled:opacity-40",children:[r.jsx(Fe,{className:"w-3 h-3"}),"Approve ",T.length]}),d?r.jsxs("div",{className:"flex items-center gap-1.5 flex-1",children:[r.jsx("input",{value:p,onChange:$=>m($.target.value),placeholder:"Reason (optional)",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-md px-2 py-1 text-[11px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#EF4444]/40",onKeyDown:$=>{$.key==="Enter"&&V()},autoFocus:!0}),r.jsx("button",{onClick:V,disabled:C.isPending,className:"px-2 py-1 rounded-md bg-[#EF4444]/15 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/25 transition-colors disabled:opacity-40",children:"Reject"}),r.jsx("button",{onClick:()=>{f(!1),m("")},className:"text-[11px] text-[#5A5A6E] hover:text-[#8A8A99]",children:"Cancel"})]}):r.jsxs("button",{onClick:()=>f(!0),className:"flex items-center gap-1 px-2.5 py-1 rounded-md bg-[#EF4444]/15 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/25 transition-colors",children:[r.jsx(Te,{className:"w-3 h-3"}),"Reject ",T.length]})]})}),r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[r.jsx(Bye,{}),r.jsx(zye,{navigate:t}),r.jsx($ye,{navigate:t}),r.jsx(Vye,{}),w?r.jsx("div",{className:"flex items-center justify-center py-16",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):E.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-white/[0.03] border border-[#2A2A35] flex items-center justify-center mb-3",children:r.jsx(Fe,{className:"w-4 h-4 text-[#5A5A6E]"})}),r.jsx("p",{className:"text-[13px] text-[#5A5A6E]",children:"No pending approvals"})]}):r.jsxs(r.Fragment,{children:[k.length>1&&r.jsx("div",{className:"px-5 py-2 sticky top-0 z-10 bg-[#13131A]",children:r.jsxs("label",{className:"flex items-center gap-2 text-[11px] text-[#5A5A6E] cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:s.size>0&&s.size===k.length,onChange:M,className:"accent-[#6366F1] w-3.5 h-3.5"}),"Select all"]})}),r.jsx(Me,{initial:!1,children:E.map($=>{const B=Oye[$.type]??yL,Y=a===($.messageId??$.id),U=g.has($.id);return r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:{duration:.15},className:"border-b border-[#2A2A35]/40",children:r.jsx("div",{className:"px-5 py-3 hover:bg-white/[0.02] transition-colors",children:r.jsxs("div",{className:"flex items-start gap-2.5",children:[$.messageId&&r.jsx("input",{type:"checkbox",checked:s.has($.messageId),onChange:()=>F($.messageId),className:"accent-[#6366F1] w-3.5 h-3.5 mt-1 flex-shrink-0"}),r.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center flex-shrink-0",style:{backgroundColor:$.agentColor?`${$.agentColor}15`:"rgba(99, 102, 241, 0.1)"},children:$.agentEmoji?r.jsx("span",{className:"text-xs",children:$.agentEmoji}):r.jsx(B,{className:"w-3.5 h-3.5 text-[#8A8A99]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5] truncate",children:$.agentName??"Agent"}),r.jsx(Pye,{priority:$.priority}),r.jsx(Iye,{expiresAt:$.expiresAt}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] ml-auto flex-shrink-0",children:Ir($.createdAt)})]}),$.type==="delegation_rule"&&$.payload?(()=>{try{const W=JSON.parse($.payload);return r.jsxs("div",{className:"mb-1.5",children:[r.jsxs("p",{className:"text-[12px] text-[#C8C8D4] leading-relaxed mb-1",children:["COO wants to create a delegation rule: Auto-approve ",r.jsx("code",{className:"text-[#6366F1] bg-[#6366F1]/10 px-1 rounded text-[11px]",children:W.pattern})," for ",r.jsx("span",{className:"text-[#F0F0F5] font-medium",children:W.agentId})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] italic mb-1",children:W.reason}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] leading-relaxed",children:["Future ",r.jsx("code",{className:"text-[#5A5A6E]",children:W.pattern})," actions from ",W.agentId," will be automatically approved without your review."]})]})}catch{return null}})():r.jsxs(r.Fragment,{children:[r.jsx("p",{className:`text-[12px] text-[#C8C8D4] leading-relaxed mb-1 whitespace-pre-wrap ${U?"":"line-clamp-2"}`,children:$.content}),$.content.length>100&&r.jsxs("button",{onClick:()=>K($.id),className:"flex items-center gap-0.5 text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors mb-1.5",children:[U?r.jsx(ah,{className:"w-2.5 h-2.5"}):r.jsx(ft,{className:"w-2.5 h-2.5"}),U?"Less":"More"]})]}),Y?r.jsxs(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},className:"flex items-center gap-1.5 mb-1",children:[r.jsx("input",{value:l,onChange:W=>c(W.target.value),placeholder:"Reason (optional)",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-md px-2 py-1 text-[11px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#EF4444]/40",onKeyDown:W=>{W.key==="Enter"&&R($.messageId)},autoFocus:!0}),r.jsx("button",{onClick:()=>R($.messageId),className:"px-2 py-1 rounded-md bg-[#EF4444]/15 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/25 transition-colors",children:"Reject"}),r.jsx("button",{onClick:()=>{o(null),c("")},className:"text-[11px] text-[#5A5A6E] hover:text-[#8A8A99]",children:"Cancel"})]}):r.jsxs("div",{className:"flex items-center gap-1.5",children:[$.messageId&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>I($.messageId),disabled:A.isPending,className:"flex items-center gap-1 px-2 py-0.5 rounded-md bg-[#10B981]/12 text-[#10B981] text-[11px] font-medium hover:bg-[#10B981]/22 transition-colors disabled:opacity-40",children:[r.jsx(Fe,{className:"w-3 h-3"}),"Approve"]}),r.jsxs("button",{onClick:()=>o($.messageId),className:"flex items-center gap-1 px-2 py-0.5 rounded-md bg-[#EF4444]/12 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/22 transition-colors",children:[r.jsx(Te,{className:"w-3 h-3"}),"Reject"]})]}),r.jsxs("button",{onClick:()=>q($.channelId),className:"flex items-center gap-0.5 ml-auto px-1.5 py-0.5 rounded text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/[0.04] transition-colors",children:[r.jsx(cs,{className:"w-2.5 h-2.5"}),"View"]})]})]})]})})},$.id)})})]})]})]})]})}function Hye(){const e=an(),{data:t}=L.onboarding.getState.useQuery(void 0,{refetchOnWindowFocus:!1}),{data:n}=L.onboarding.pollOpenClaw.useQuery(void 0,{refetchInterval:1e4,refetchOnWindowFocus:!1}),s=L.onboarding.skipOpenClaw.useMutation(),i=L.useUtils();if(!t?.skippedOpenClaw||n?.running)return null;async function a(){await s.mutateAsync(),i.onboarding.getState.invalidate()}return r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-[#1C1410] border-b border-[#F59E0B]/20 text-[12px] flex-shrink-0",children:[r.jsxs("span",{className:"text-[#F59E0B]",children:["OpenClaw not connected —"," ",r.jsx("button",{onClick:()=>e("/onboarding"),className:"underline underline-offset-2 hover:text-[#FBBF24] transition-colors",children:"set up now"})]}),r.jsx("button",{onClick:a,className:"text-[#F59E0B]/60 hover:text-[#F59E0B] transition-colors ml-4",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]})}function Wye(){const{data:e}=L.settings.getTestMode.useQuery(void 0,{refetchOnWindowFocus:!1,refetchInterval:15e3}),t=L.useUtils(),n=L.settings.setTestMode.useMutation({onSuccess:()=>{t.settings.getTestMode.invalidate()}});return e?.enabled?r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-[#1C1A0F] border-b border-[#F59E0B]/30 text-[12px] flex-shrink-0",children:[r.jsxs("span",{className:"flex items-center gap-2 text-[#FBBF24]",children:[r.jsx(oL,{className:"w-3.5 h-3.5"}),"Test mode active — no memory, knowledge, or reflection will be recorded."]}),r.jsx("button",{onClick:()=>n.mutate({enabled:!1}),disabled:n.isPending,className:"text-[#FBBF24]/80 hover:text-[#FBBF24] underline underline-offset-2 transition-colors ml-4 disabled:opacity-50",children:"disable"})]}):null}function qye({children:e}){const[t,n]=y.useState(!1);return r.jsxs("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col",children:[r.jsx(Hye,{}),r.jsx(Wye,{}),r.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[r.jsx(lme,{onOpenApprovals:()=>n(s=>!s)}),r.jsxs("main",{className:"flex flex-1 overflow-hidden relative",children:[e,r.jsx(Afe,{})]}),r.jsx(Rye,{})]}),r.jsx(Me,{children:t&&r.jsx(Uye,{onClose:()=>n(!1)})})]})}function Gye({label:e,emoji:t,color:n,typeBadge:s,onRemove:i}){return r.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-md group",children:[r.jsx("span",{className:"w-6 h-6 rounded-full flex items-center justify-center text-xs flex-shrink-0",style:{backgroundColor:`${n}26`},children:t??e[0]?.toUpperCase()}),r.jsx("span",{className:"text-[13px] text-[#C8C8D4] flex-1 truncate",children:e}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] bg-white/5 px-1.5 py-0.5 rounded",children:s}),i&&r.jsx("button",{onClick:i,className:"w-5 h-5 flex items-center justify-center rounded text-[#5A5A6E] opacity-0 group-hover:opacity-100 hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-all",children:r.jsx(Te,{className:"w-3 h-3"})})]})}function Kye({channelId:e,existingIds:t,agents:n,workspaceMembers:s}){const[i,a]=y.useState(!1),[o,l]=y.useState(""),c=L.useUtils(),d=L.channels.addParticipant.useMutation({onSuccess:()=>{c.channels.list.invalidate(),l(""),a(!1)}}),f=n.filter(_=>!t.has(_.id)),p=s.filter(_=>!t.has(_.userId)),m=o.toLowerCase(),g=m?f.filter(_=>_.name.toLowerCase().includes(m)):f,b=m?p.filter(_=>_.name.toLowerCase().includes(m)):p;return i?r.jsxs("div",{className:"px-1",children:[r.jsx("input",{autoFocus:!0,value:o,onChange:_=>l(_.target.value),placeholder:"Search people and agents...",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-md px-2 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors mb-1",onKeyDown:_=>{_.key==="Escape"&&(a(!1),l(""))}}),r.jsxs("div",{className:"max-h-[180px] overflow-y-auto",children:[g.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[10px] text-[#5A5A6E] px-2 py-1 uppercase tracking-widest font-semibold",children:"Agents"}),g.map(_=>r.jsxs("button",{onClick:()=>d.mutate({channelId:e,participantId:_.id,participantType:"agent"}),disabled:d.isPending,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-[12px] text-[#C8C8D4] hover:bg-white/5 transition-colors",children:[r.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[11px] flex-shrink-0",style:{backgroundColor:`${_.color}26`},children:_.emoji}),r.jsx("span",{className:"flex-1 text-left truncate",children:_.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:_.role})]},_.id))]}),b.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[10px] text-[#5A5A6E] px-2 py-1 uppercase tracking-widest font-semibold",children:"People"}),b.map(_=>{const w=_.name.split(" ").map(A=>A[0]).join("").slice(0,2).toUpperCase();return r.jsxs("button",{onClick:()=>d.mutate({channelId:e,participantId:_.userId,participantType:"human"}),disabled:d.isPending,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-[12px] text-[#C8C8D4] hover:bg-white/5 transition-colors",children:[_.image?r.jsx("img",{src:_.image,className:"w-5 h-5 rounded-full flex-shrink-0",alt:""}):r.jsx("span",{className:"w-5 h-5 rounded-full bg-gradient-to-br from-[#6366F1] to-[#8B5CF6] flex items-center justify-center text-[9px] font-semibold text-white flex-shrink-0",children:w}),r.jsx("span",{className:"flex-1 text-left truncate",children:_.name})]},_.userId)})]}),g.length===0&&b.length===0&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] px-2 py-1.5",children:"No participants available"})]})]}):r.jsxs("button",{onClick:()=>a(!0),className:"flex items-center gap-1.5 px-2 py-1.5 rounded-md text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5 transition-colors w-full",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),r.jsx("span",{children:"Add participant"})]})}function S$({channel:e}){const{data:t=[]}=Vo(),{data:n}=Mi(),{data:s=[]}=L.workspace.listMembers.useQuery(void 0,{staleTime:3e4}),i=L.useUtils(),a=L.channels.removeParticipant.useMutation({onSuccess:()=>{i.channels.list.invalidate()}}),o=new Set(e.participants.map(c=>c.participantId)),l=e.participants.length;return r.jsxs(Ys,{children:[r.jsx(ci,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-transparent hover:border-[#2A2A35]",children:[r.jsx(wm,{className:"w-3.5 h-3.5"}),r.jsx("span",{children:l})]})}),r.jsx(Qs,{children:r.jsxs(Xs,{align:"end",sideOffset:6,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl w-[260px] z-50",children:[r.jsx("div",{className:"px-3 py-2 border-b border-[#2A2A35]",children:r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Members"})}),r.jsx("div",{className:"py-1 px-1 max-h-[200px] overflow-y-auto",children:e.participants.map(c=>{const d=t.find(A=>A.id===c.participantId),f=c.participantType==="human",m=(f?s.find(A=>A.userId===c.participantId):void 0)?.name??n?.user?.name??n?.user?.email??"User",g=f?m:d?.name??c.participantId,b=f?void 0:d?.emoji,_=f?"#6366F1":d?.color??"#8A8A99",w=e.participants.length>1;return r.jsx(Gye,{label:g,emoji:b,color:_,typeBadge:f?"Human":"Agent",onRemove:w?()=>a.mutate({channelId:e.id,participantId:c.participantId}):void 0},c.id)})}),r.jsx("div",{className:"border-t border-[#2A2A35] py-1.5 px-1",children:r.jsx(Kye,{channelId:e.id,existingIds:o,agents:t,workspaceMembers:s})}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]})}function Ij(e){const t=e+"CollectionProvider",[n,s]=Wa(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=_=>{const{scope:w,children:A}=_,S=be.useRef(null),C=be.useRef(new Map).current;return r.jsx(i,{scope:w,itemMap:C,collectionRef:S,children:A})};o.displayName=t;const l=e+"CollectionSlot",c=iu(l),d=be.forwardRef((_,w)=>{const{scope:A,children:S}=_,C=a(l,A),E=At(w,C.collectionRef);return r.jsx(c,{ref:E,children:S})});d.displayName=l;const f=e+"CollectionItemSlot",p="data-radix-collection-item",m=iu(f),g=be.forwardRef((_,w)=>{const{scope:A,children:S,...C}=_,E=be.useRef(null),k=At(w,E),T=a(f,A);return be.useEffect(()=>(T.itemMap.set(E,{ref:E,...C}),()=>{T.itemMap.delete(E)})),r.jsx(m,{[p]:"",ref:k,children:S})});g.displayName=f;function b(_){const w=a(e+"CollectionConsumer",_);return be.useCallback(()=>{const S=w.collectionRef.current;if(!S)return[];const C=Array.from(S.querySelectorAll(`[${p}]`));return Array.from(w.itemMap.values()).sort((T,F)=>C.indexOf(T.ref.current)-C.indexOf(F.ref.current))},[w.collectionRef,w.itemMap])}return[{Provider:o,Slot:d,ItemSlot:g},b,s]}var Yye=y.createContext(void 0);function Lj(e){const t=y.useContext(Yye);return e||t||"ltr"}var gA="rovingFocusGroup.onEntryFocus",Qye={bubbles:!1,cancelable:!0},Lm="RovingFocusGroup",[JS,C$,Xye]=Ij(Lm),[Jye,j$]=Wa(Lm,[Xye]),[Zye,e1e]=Jye(Lm),N$=y.forwardRef((e,t)=>r.jsx(JS.Provider,{scope:e.__scopeRovingFocusGroup,children:r.jsx(JS.Slot,{scope:e.__scopeRovingFocusGroup,children:r.jsx(t1e,{...e,ref:t})})}));N$.displayName=Lm;var t1e=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:s,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:c,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...p}=e,m=y.useRef(null),g=At(t,m),b=Lj(a),[_,w]=Fo({prop:o,defaultProp:l??null,onChange:c,caller:Lm}),[A,S]=y.useState(!1),C=ia(d),E=C$(n),k=y.useRef(!1),[T,F]=y.useState(0);return y.useEffect(()=>{const M=m.current;if(M)return M.addEventListener(gA,C),()=>M.removeEventListener(gA,C)},[C]),r.jsx(Zye,{scope:n,orientation:s,dir:b,loop:i,currentTabStopId:_,onItemFocus:y.useCallback(M=>w(M),[w]),onItemShiftTab:y.useCallback(()=>S(!0),[]),onFocusableItemAdd:y.useCallback(()=>F(M=>M+1),[]),onFocusableItemRemove:y.useCallback(()=>F(M=>M-1),[]),children:r.jsx(lt.div,{tabIndex:A||T===0?-1:0,"data-orientation":s,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:Oe(e.onMouseDown,()=>{k.current=!0}),onFocus:Oe(e.onFocus,M=>{const I=!k.current;if(M.target===M.currentTarget&&I&&!A){const R=new CustomEvent(gA,Qye);if(M.currentTarget.dispatchEvent(R),!R.defaultPrevented){const H=E().filter(B=>B.focusable),V=H.find(B=>B.active),K=H.find(B=>B.id===_),$=[V,K,...H].filter(Boolean).map(B=>B.ref.current);F$($,f)}}k.current=!1}),onBlur:Oe(e.onBlur,()=>S(!1))})})}),k$="RovingFocusGroupItem",E$=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:s=!0,active:i=!1,tabStopId:a,children:o,...l}=e,c=Zi(),d=a||c,f=e1e(k$,n),p=f.currentTabStopId===d,m=C$(n),{onFocusableItemAdd:g,onFocusableItemRemove:b,currentTabStopId:_}=f;return y.useEffect(()=>{if(s)return g(),()=>b()},[s,g,b]),r.jsx(JS.ItemSlot,{scope:n,id:d,focusable:s,active:i,children:r.jsx(lt.span,{tabIndex:p?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:Oe(e.onMouseDown,w=>{s?f.onItemFocus(d):w.preventDefault()}),onFocus:Oe(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:Oe(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){f.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const A=i1e(w,f.orientation,f.dir);if(A!==void 0){if(w.metaKey||w.ctrlKey||w.altKey||w.shiftKey)return;w.preventDefault();let C=m().filter(E=>E.focusable).map(E=>E.ref.current);if(A==="last")C.reverse();else if(A==="prev"||A==="next"){A==="prev"&&C.reverse();const E=C.indexOf(w.currentTarget);C=f.loop?r1e(C,E+1):C.slice(E+1)}setTimeout(()=>F$(C))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:_!=null}):o})})});E$.displayName=k$;var n1e={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function s1e(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function i1e(e,t,n){const s=s1e(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(s))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(s)))return n1e[s]}function F$(e,t=!1){const n=document.activeElement;for(const s of e)if(s===n||(s.focus({preventScroll:t}),document.activeElement!==n))return}function r1e(e,t){return e.map((n,s)=>e[(t+s)%e.length])}var a1e=N$,o1e=E$,ZS=["Enter"," "],l1e=["ArrowDown","PageUp","Home"],T$=["ArrowUp","PageDown","End"],c1e=[...l1e,...T$],u1e={ltr:[...ZS,"ArrowRight"],rtl:[...ZS,"ArrowLeft"]},d1e={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Bm="Menu",[zp,h1e,f1e]=Ij(Bm),[_u,M$]=Wa(Bm,[f1e,tc,j$]),zm=tc(),R$=j$(),[D$,ic]=_u(Bm),[p1e,$m]=_u(Bm),O$=e=>{const{__scopeMenu:t,open:n=!1,children:s,dir:i,onOpenChange:a,modal:o=!0}=e,l=zm(t),[c,d]=y.useState(null),f=y.useRef(!1),p=ia(a),m=Lj(i);return y.useEffect(()=>{const g=()=>{f.current=!0,document.addEventListener("pointerdown",b,{capture:!0,once:!0}),document.addEventListener("pointermove",b,{capture:!0,once:!0})},b=()=>f.current=!1;return document.addEventListener("keydown",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),r.jsx(jm,{...l,children:r.jsx(D$,{scope:t,open:n,onOpenChange:p,content:c,onContentChange:d,children:r.jsx(p1e,{scope:t,onClose:y.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:f,dir:m,modal:o,children:s})})})};O$.displayName=Bm;var m1e="MenuAnchor",Bj=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e,i=zm(n);return r.jsx(Nm,{...i,...s,ref:t})});Bj.displayName=m1e;var zj="MenuPortal",[x1e,P$]=_u(zj,{forceMount:void 0}),I$=e=>{const{__scopeMenu:t,forceMount:n,children:s,container:i}=e,a=ic(zj,t);return r.jsx(x1e,{scope:t,forceMount:n,children:r.jsx(zr,{present:n||a.open,children:r.jsx(hh,{asChild:!0,container:i,children:s})})})};I$.displayName=zj;var Or="MenuContent",[g1e,$j]=_u(Or),L$=y.forwardRef((e,t)=>{const n=P$(Or,e.__scopeMenu),{forceMount:s=n.forceMount,...i}=e,a=ic(Or,e.__scopeMenu),o=$m(Or,e.__scopeMenu);return r.jsx(zp.Provider,{scope:e.__scopeMenu,children:r.jsx(zr,{present:s||a.open,children:r.jsx(zp.Slot,{scope:e.__scopeMenu,children:o.modal?r.jsx(b1e,{...i,ref:t}):r.jsx(v1e,{...i,ref:t})})})})}),b1e=y.forwardRef((e,t)=>{const n=ic(Or,e.__scopeMenu),s=y.useRef(null),i=At(t,s);return y.useEffect(()=>{const a=s.current;if(a)return Av(a)},[]),r.jsx(Vj,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Oe(e.onFocusOutside,a=>a.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),v1e=y.forwardRef((e,t)=>{const n=ic(Or,e.__scopeMenu);return r.jsx(Vj,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),y1e=iu("MenuContent.ScrollLock"),Vj=y.forwardRef((e,t)=>{const{__scopeMenu:n,loop:s=!1,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:c,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:m,onDismiss:g,disableOutsideScroll:b,..._}=e,w=ic(Or,n),A=$m(Or,n),S=zm(n),C=R$(n),E=h1e(n),[k,T]=y.useState(null),F=y.useRef(null),M=At(t,F,w.onContentChange),I=y.useRef(0),R=y.useRef(""),H=y.useRef(0),V=y.useRef(null),K=y.useRef("right"),q=y.useRef(0),$=b?Sm:y.Fragment,B=b?{as:y1e,allowPinchZoom:!0}:void 0,Y=W=>{const O=R.current+W,D=E().filter(oe=>!oe.disabled),Q=document.activeElement,z=D.find(oe=>oe.ref.current===Q)?.textValue,J=D.map(oe=>oe.textValue),ee=M1e(J,O,z),re=D.find(oe=>oe.textValue===ee)?.ref.current;(function oe(se){R.current=se,window.clearTimeout(I.current),se!==""&&(I.current=window.setTimeout(()=>oe(""),1e3))})(O),re&&setTimeout(()=>re.focus())};y.useEffect(()=>()=>window.clearTimeout(I.current),[]),_v();const U=y.useCallback(W=>K.current===V.current?.side&&D1e(W,V.current?.area),[]);return r.jsx(g1e,{scope:n,searchRef:R,onItemEnter:y.useCallback(W=>{U(W)&&W.preventDefault()},[U]),onItemLeave:y.useCallback(W=>{U(W)||(F.current?.focus(),T(null))},[U]),onTriggerLeave:y.useCallback(W=>{U(W)&&W.preventDefault()},[U]),pointerGraceTimerRef:H,onPointerGraceIntentChange:y.useCallback(W=>{V.current=W},[]),children:r.jsx($,{...B,children:r.jsx(Am,{asChild:!0,trapped:i,onMountAutoFocus:Oe(a,W=>{W.preventDefault(),F.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:r.jsx(dh,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:m,onDismiss:g,children:r.jsx(a1e,{asChild:!0,...C,dir:A.dir,orientation:"vertical",loop:s,currentTabStopId:k,onCurrentTabStopIdChange:T,onEntryFocus:Oe(c,W=>{A.isUsingKeyboardRef.current||W.preventDefault()}),preventScrollOnEntryFocus:!0,children:r.jsx(Fv,{role:"menu","aria-orientation":"vertical","data-state":t7(w.open),"data-radix-menu-content":"",dir:A.dir,...S,..._,ref:M,style:{outline:"none",..._.style},onKeyDown:Oe(_.onKeyDown,W=>{const D=W.target.closest("[data-radix-menu-content]")===W.currentTarget,Q=W.ctrlKey||W.altKey||W.metaKey,z=W.key.length===1;D&&(W.key==="Tab"&&W.preventDefault(),!Q&&z&&Y(W.key));const J=F.current;if(W.target!==J||!c1e.includes(W.key))return;W.preventDefault();const re=E().filter(oe=>!oe.disabled).map(oe=>oe.ref.current);T$.includes(W.key)&&re.reverse(),F1e(re)}),onBlur:Oe(e.onBlur,W=>{W.currentTarget.contains(W.target)||(window.clearTimeout(I.current),R.current="")}),onPointerMove:Oe(e.onPointerMove,$p(W=>{const O=W.target,D=q.current!==W.clientX;if(W.currentTarget.contains(O)&&D){const Q=W.clientX>q.current?"right":"left";K.current=Q,q.current=W.clientX}}))})})})})})})});L$.displayName=Or;var _1e="MenuGroup",Uj=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e;return r.jsx(lt.div,{role:"group",...s,ref:t})});Uj.displayName=_1e;var w1e="MenuLabel",B$=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e;return r.jsx(lt.div,{...s,ref:t})});B$.displayName=w1e;var j0="MenuItem",oR="menu.itemSelect",Gv=y.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:s,...i}=e,a=y.useRef(null),o=$m(j0,e.__scopeMenu),l=$j(j0,e.__scopeMenu),c=At(t,a),d=y.useRef(!1),f=()=>{const p=a.current;if(!n&&p){const m=new CustomEvent(oR,{bubbles:!0,cancelable:!0});p.addEventListener(oR,g=>s?.(g),{once:!0}),BL(p,m),m.defaultPrevented?d.current=!1:o.onClose()}};return r.jsx(z$,{...i,ref:c,disabled:n,onClick:Oe(e.onClick,f),onPointerDown:p=>{e.onPointerDown?.(p),d.current=!0},onPointerUp:Oe(e.onPointerUp,p=>{d.current||p.currentTarget?.click()}),onKeyDown:Oe(e.onKeyDown,p=>{const m=l.searchRef.current!=="";n||m&&p.key===" "||ZS.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Gv.displayName=j0;var z$=y.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:s=!1,textValue:i,...a}=e,o=$j(j0,n),l=R$(n),c=y.useRef(null),d=At(t,c),[f,p]=y.useState(!1),[m,g]=y.useState("");return y.useEffect(()=>{const b=c.current;b&&g((b.textContent??"").trim())},[a.children]),r.jsx(zp.ItemSlot,{scope:n,disabled:s,textValue:i??m,children:r.jsx(o1e,{asChild:!0,...l,focusable:!s,children:r.jsx(lt.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":s||void 0,"data-disabled":s?"":void 0,...a,ref:d,onPointerMove:Oe(e.onPointerMove,$p(b=>{s?o.onItemLeave(b):(o.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Oe(e.onPointerLeave,$p(b=>o.onItemLeave(b))),onFocus:Oe(e.onFocus,()=>p(!0)),onBlur:Oe(e.onBlur,()=>p(!1))})})})}),A1e="MenuCheckboxItem",$$=y.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:s,...i}=e;return r.jsx(q$,{scope:e.__scopeMenu,checked:n,children:r.jsx(Gv,{role:"menuitemcheckbox","aria-checked":N0(n)?"mixed":n,...i,ref:t,"data-state":qj(n),onSelect:Oe(i.onSelect,()=>s?.(N0(n)?!0:!n),{checkForDefaultPrevented:!1})})})});$$.displayName=A1e;var V$="MenuRadioGroup",[S1e,C1e]=_u(V$,{value:void 0,onValueChange:()=>{}}),U$=y.forwardRef((e,t)=>{const{value:n,onValueChange:s,...i}=e,a=ia(s);return r.jsx(S1e,{scope:e.__scopeMenu,value:n,onValueChange:a,children:r.jsx(Uj,{...i,ref:t})})});U$.displayName=V$;var H$="MenuRadioItem",W$=y.forwardRef((e,t)=>{const{value:n,...s}=e,i=C1e(H$,e.__scopeMenu),a=n===i.value;return r.jsx(q$,{scope:e.__scopeMenu,checked:a,children:r.jsx(Gv,{role:"menuitemradio","aria-checked":a,...s,ref:t,"data-state":qj(a),onSelect:Oe(s.onSelect,()=>i.onValueChange?.(n),{checkForDefaultPrevented:!1})})})});W$.displayName=H$;var Hj="MenuItemIndicator",[q$,j1e]=_u(Hj,{checked:!1}),G$=y.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:s,...i}=e,a=j1e(Hj,n);return r.jsx(zr,{present:s||N0(a.checked)||a.checked===!0,children:r.jsx(lt.span,{...i,ref:t,"data-state":qj(a.checked)})})});G$.displayName=Hj;var N1e="MenuSeparator",K$=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e;return r.jsx(lt.div,{role:"separator","aria-orientation":"horizontal",...s,ref:t})});K$.displayName=N1e;var k1e="MenuArrow",Y$=y.forwardRef((e,t)=>{const{__scopeMenu:n,...s}=e,i=zm(n);return r.jsx(Tv,{...i,...s,ref:t})});Y$.displayName=k1e;var Wj="MenuSub",[E1e,Q$]=_u(Wj),X$=e=>{const{__scopeMenu:t,children:n,open:s=!1,onOpenChange:i}=e,a=ic(Wj,t),o=zm(t),[l,c]=y.useState(null),[d,f]=y.useState(null),p=ia(i);return y.useEffect(()=>(a.open===!1&&p(!1),()=>p(!1)),[a.open,p]),r.jsx(jm,{...o,children:r.jsx(D$,{scope:t,open:s,onOpenChange:p,content:d,onContentChange:f,children:r.jsx(E1e,{scope:t,contentId:Zi(),triggerId:Zi(),trigger:l,onTriggerChange:c,children:n})})})};X$.displayName=Wj;var Xf="MenuSubTrigger",J$=y.forwardRef((e,t)=>{const n=ic(Xf,e.__scopeMenu),s=$m(Xf,e.__scopeMenu),i=Q$(Xf,e.__scopeMenu),a=$j(Xf,e.__scopeMenu),o=y.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:c}=a,d={__scopeMenu:e.__scopeMenu},f=y.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return y.useEffect(()=>f,[f]),y.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),c(null)}},[l,c]),r.jsx(Bj,{asChild:!0,...d,children:r.jsx(z$,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":t7(n.open),...e,ref:yv(t,i.onTriggerChange),onClick:p=>{e.onClick?.(p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:Oe(e.onPointerMove,$p(p=>{a.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(a.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:Oe(e.onPointerLeave,$p(p=>{f();const m=n.content?.getBoundingClientRect();if(m){const g=n.content?.dataset.side,b=g==="right",_=b?-5:5,w=m[b?"left":"right"],A=m[b?"right":"left"];a.onPointerGraceIntentChange({area:[{x:p.clientX+_,y:p.clientY},{x:w,y:m.top},{x:A,y:m.top},{x:A,y:m.bottom},{x:w,y:m.bottom}],side:g}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>a.onPointerGraceIntentChange(null),300)}else{if(a.onTriggerLeave(p),p.defaultPrevented)return;a.onPointerGraceIntentChange(null)}})),onKeyDown:Oe(e.onKeyDown,p=>{const m=a.searchRef.current!=="";e.disabled||m&&p.key===" "||u1e[s.dir].includes(p.key)&&(n.onOpenChange(!0),n.content?.focus(),p.preventDefault())})})})});J$.displayName=Xf;var Z$="MenuSubContent",e7=y.forwardRef((e,t)=>{const n=P$(Or,e.__scopeMenu),{forceMount:s=n.forceMount,...i}=e,a=ic(Or,e.__scopeMenu),o=$m(Or,e.__scopeMenu),l=Q$(Z$,e.__scopeMenu),c=y.useRef(null),d=At(t,c);return r.jsx(zp.Provider,{scope:e.__scopeMenu,children:r.jsx(zr,{present:s||a.open,children:r.jsx(zp.Slot,{scope:e.__scopeMenu,children:r.jsx(Vj,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:f=>{o.isUsingKeyboardRef.current&&c.current?.focus(),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:Oe(e.onFocusOutside,f=>{f.target!==l.trigger&&a.onOpenChange(!1)}),onEscapeKeyDown:Oe(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:Oe(e.onKeyDown,f=>{const p=f.currentTarget.contains(f.target),m=d1e[o.dir].includes(f.key);p&&m&&(a.onOpenChange(!1),l.trigger?.focus(),f.preventDefault())})})})})})});e7.displayName=Z$;function t7(e){return e?"open":"closed"}function N0(e){return e==="indeterminate"}function qj(e){return N0(e)?"indeterminate":e?"checked":"unchecked"}function F1e(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function T1e(e,t){return e.map((n,s)=>e[(t+s)%e.length])}function M1e(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,a=n?e.indexOf(n):-1;let o=T1e(e,Math.max(a,0));i.length===1&&(o=o.filter(d=>d!==n));const c=o.find(d=>d.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function R1e(e,t){const{x:n,y:s}=e;let i=!1;for(let a=0,o=t.length-1;a<t.length;o=a++){const l=t[a],c=t[o],d=l.x,f=l.y,p=c.x,m=c.y;f>s!=m>s&&n<(p-d)*(s-f)/(m-f)+d&&(i=!i)}return i}function D1e(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return R1e(n,t)}function $p(e){return t=>t.pointerType==="mouse"?e(t):void 0}var O1e=O$,P1e=Bj,I1e=I$,L1e=L$,B1e=Uj,z1e=B$,$1e=Gv,V1e=$$,U1e=U$,H1e=W$,W1e=G$,q1e=K$,G1e=Y$,K1e=X$,Y1e=J$,Q1e=e7,Kv="DropdownMenu",[X1e]=Wa(Kv,[M$]),ei=M$(),[J1e,n7]=X1e(Kv),s7=e=>{const{__scopeDropdownMenu:t,children:n,dir:s,open:i,defaultOpen:a,onOpenChange:o,modal:l=!0}=e,c=ei(t),d=y.useRef(null),[f,p]=Fo({prop:i,defaultProp:a??!1,onChange:o,caller:Kv});return r.jsx(J1e,{scope:t,triggerId:Zi(),triggerRef:d,contentId:Zi(),open:f,onOpenChange:p,onOpenToggle:y.useCallback(()=>p(m=>!m),[p]),modal:l,children:r.jsx(O1e,{...c,open:f,onOpenChange:p,dir:s,modal:l,children:n})})};s7.displayName=Kv;var i7="DropdownMenuTrigger",r7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:s=!1,...i}=e,a=n7(i7,n),o=ei(n);return r.jsx(P1e,{asChild:!0,...o,children:r.jsx(lt.button,{type:"button",id:a.triggerId,"aria-haspopup":"menu","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?"open":"closed","data-disabled":s?"":void 0,disabled:s,...i,ref:yv(t,a.triggerRef),onPointerDown:Oe(e.onPointerDown,l=>{!s&&l.button===0&&l.ctrlKey===!1&&(a.onOpenToggle(),a.open||l.preventDefault())}),onKeyDown:Oe(e.onKeyDown,l=>{s||(["Enter"," "].includes(l.key)&&a.onOpenToggle(),l.key==="ArrowDown"&&a.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});r7.displayName=i7;var Z1e="DropdownMenuPortal",a7=e=>{const{__scopeDropdownMenu:t,...n}=e,s=ei(t);return r.jsx(I1e,{...s,...n})};a7.displayName=Z1e;var o7="DropdownMenuContent",l7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=n7(o7,n),a=ei(n),o=y.useRef(!1);return r.jsx(L1e,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...s,ref:t,onCloseAutoFocus:Oe(e.onCloseAutoFocus,l=>{o.current||i.triggerRef.current?.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:Oe(e.onInteractOutside,l=>{const c=l.detail.originalEvent,d=c.button===0&&c.ctrlKey===!0,f=c.button===2||d;(!i.modal||f)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});l7.displayName=o7;var e_e="DropdownMenuGroup",c7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(B1e,{...i,...s,ref:t})});c7.displayName=e_e;var t_e="DropdownMenuLabel",u7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(z1e,{...i,...s,ref:t})});u7.displayName=t_e;var n_e="DropdownMenuItem",d7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx($1e,{...i,...s,ref:t})});d7.displayName=n_e;var s_e="DropdownMenuCheckboxItem",i_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(V1e,{...i,...s,ref:t})});i_e.displayName=s_e;var r_e="DropdownMenuRadioGroup",a_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(U1e,{...i,...s,ref:t})});a_e.displayName=r_e;var o_e="DropdownMenuRadioItem",l_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(H1e,{...i,...s,ref:t})});l_e.displayName=o_e;var c_e="DropdownMenuItemIndicator",u_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(W1e,{...i,...s,ref:t})});u_e.displayName=c_e;var d_e="DropdownMenuSeparator",h7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(q1e,{...i,...s,ref:t})});h7.displayName=d_e;var h_e="DropdownMenuArrow",f_e=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(G1e,{...i,...s,ref:t})});f_e.displayName=h_e;var p_e=e=>{const{__scopeDropdownMenu:t,children:n,open:s,onOpenChange:i,defaultOpen:a}=e,o=ei(t),[l,c]=Fo({prop:s,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return r.jsx(K1e,{...o,open:l,onOpenChange:c,children:n})},m_e="DropdownMenuSubTrigger",f7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(Y1e,{...i,...s,ref:t})});f7.displayName=m_e;var x_e="DropdownMenuSubContent",p7=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...s}=e,i=ei(n);return r.jsx(Q1e,{...i,...s,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});p7.displayName=x_e;var Yv=s7,Qv=r7,Od=a7,Xv=l7,g_e=c7,b_e=u7,Bl=d7,v_e=h7,lR=p_e,cR=f7,uR=p7;function dR(e,[t,n]){return Math.min(n,Math.max(t,e))}function m7(e){const t=y.useRef({value:e,previous:e});return y.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var y_e=[" ","Enter","ArrowUp","ArrowDown"],__e=[" ","Enter"],uu="Select",[Jv,Zv,w_e]=Ij(uu),[vh]=Wa(uu,[w_e,tc]),ey=tc(),[A_e,rc]=vh(uu),[S_e,C_e]=vh(uu),x7=e=>{const{__scopeSelect:t,children:n,open:s,defaultOpen:i,onOpenChange:a,value:o,defaultValue:l,onValueChange:c,dir:d,name:f,autoComplete:p,disabled:m,required:g,form:b}=e,_=ey(t),[w,A]=y.useState(null),[S,C]=y.useState(null),[E,k]=y.useState(!1),T=Lj(d),[F,M]=Fo({prop:s,defaultProp:i??!1,onChange:a,caller:uu}),[I,R]=Fo({prop:o,defaultProp:l,onChange:c,caller:uu}),H=y.useRef(null),V=w?b||!!w.closest("form"):!0,[K,q]=y.useState(new Set),$=Array.from(K).map(B=>B.props.value).join(";");return r.jsx(jm,{..._,children:r.jsxs(A_e,{required:g,scope:t,trigger:w,onTriggerChange:A,valueNode:S,onValueNodeChange:C,valueNodeHasChildren:E,onValueNodeHasChildrenChange:k,contentId:Zi(),value:I,onValueChange:R,open:F,onOpenChange:M,dir:T,triggerPointerDownPosRef:H,disabled:m,children:[r.jsx(Jv.Provider,{scope:t,children:r.jsx(S_e,{scope:e.__scopeSelect,onNativeOptionAdd:y.useCallback(B=>{q(Y=>new Set(Y).add(B))},[]),onNativeOptionRemove:y.useCallback(B=>{q(Y=>{const U=new Set(Y);return U.delete(B),U})},[]),children:n})}),V?r.jsxs(L7,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:p,value:I,onChange:B=>R(B.target.value),disabled:m,form:b,children:[I===void 0?r.jsx("option",{value:""}):null,Array.from(K)]},$):null]})})};x7.displayName=uu;var g7="SelectTrigger",b7=y.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:s=!1,...i}=e,a=ey(n),o=rc(g7,n),l=o.disabled||s,c=At(t,o.onTriggerChange),d=Zv(n),f=y.useRef("touch"),[p,m,g]=z7(_=>{const w=d().filter(C=>!C.disabled),A=w.find(C=>C.value===o.value),S=$7(w,_,A);S!==void 0&&o.onValueChange(S.value)}),b=_=>{l||(o.onOpenChange(!0),g()),_&&(o.triggerPointerDownPosRef.current={x:Math.round(_.pageX),y:Math.round(_.pageY)})};return r.jsx(Nm,{asChild:!0,...a,children:r.jsx(lt.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":B7(o.value)?"":void 0,...i,ref:c,onClick:Oe(i.onClick,_=>{_.currentTarget.focus(),f.current!=="mouse"&&b(_)}),onPointerDown:Oe(i.onPointerDown,_=>{f.current=_.pointerType;const w=_.target;w.hasPointerCapture(_.pointerId)&&w.releasePointerCapture(_.pointerId),_.button===0&&_.ctrlKey===!1&&_.pointerType==="mouse"&&(b(_),_.preventDefault())}),onKeyDown:Oe(i.onKeyDown,_=>{const w=p.current!=="";!(_.ctrlKey||_.altKey||_.metaKey)&&_.key.length===1&&m(_.key),!(w&&_.key===" ")&&y_e.includes(_.key)&&(b(),_.preventDefault())})})})});b7.displayName=g7;var v7="SelectValue",y7=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:s,style:i,children:a,placeholder:o="",...l}=e,c=rc(v7,n),{onValueNodeHasChildrenChange:d}=c,f=a!==void 0,p=At(t,c.onValueNodeChange);return Ks(()=>{d(f)},[d,f]),r.jsx(lt.span,{...l,ref:p,style:{pointerEvents:"none"},children:B7(c.value)?r.jsx(r.Fragment,{children:o}):a})});y7.displayName=v7;var j_e="SelectIcon",_7=y.forwardRef((e,t)=>{const{__scopeSelect:n,children:s,...i}=e;return r.jsx(lt.span,{"aria-hidden":!0,...i,ref:t,children:s||"▼"})});_7.displayName=j_e;var N_e="SelectPortal",w7=e=>r.jsx(hh,{asChild:!0,...e});w7.displayName=N_e;var du="SelectContent",A7=y.forwardRef((e,t)=>{const n=rc(du,e.__scopeSelect),[s,i]=y.useState();if(Ks(()=>{i(new DocumentFragment)},[]),!n.open){const a=s;return a?Xr.createPortal(r.jsx(S7,{scope:e.__scopeSelect,children:r.jsx(Jv.Slot,{scope:e.__scopeSelect,children:r.jsx("div",{children:e.children})})}),a):null}return r.jsx(C7,{...e,ref:t})});A7.displayName=du;var Kr=10,[S7,ac]=vh(du),k_e="SelectContentImpl",E_e=iu("SelectContent.RemoveScroll"),C7=y.forwardRef((e,t)=>{const{__scopeSelect:n,position:s="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:l,sideOffset:c,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:g,sticky:b,hideWhenDetached:_,avoidCollisions:w,...A}=e,S=rc(du,n),[C,E]=y.useState(null),[k,T]=y.useState(null),F=At(t,oe=>E(oe)),[M,I]=y.useState(null),[R,H]=y.useState(null),V=Zv(n),[K,q]=y.useState(!1),$=y.useRef(!1);y.useEffect(()=>{if(C)return Av(C)},[C]),_v();const B=y.useCallback(oe=>{const[se,...ae]=V().map(je=>je.ref.current),[le]=ae.slice(-1),ge=document.activeElement;for(const je of oe)if(je===ge||(je?.scrollIntoView({block:"nearest"}),je===se&&k&&(k.scrollTop=0),je===le&&k&&(k.scrollTop=k.scrollHeight),je?.focus(),document.activeElement!==ge))return},[V,k]),Y=y.useCallback(()=>B([M,C]),[B,M,C]);y.useEffect(()=>{K&&Y()},[K,Y]);const{onOpenChange:U,triggerPointerDownPosRef:W}=S;y.useEffect(()=>{if(C){let oe={x:0,y:0};const se=le=>{oe={x:Math.abs(Math.round(le.pageX)-(W.current?.x??0)),y:Math.abs(Math.round(le.pageY)-(W.current?.y??0))}},ae=le=>{oe.x<=10&&oe.y<=10?le.preventDefault():C.contains(le.target)||U(!1),document.removeEventListener("pointermove",se),W.current=null};return W.current!==null&&(document.addEventListener("pointermove",se),document.addEventListener("pointerup",ae,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",se),document.removeEventListener("pointerup",ae,{capture:!0})}}},[C,U,W]),y.useEffect(()=>{const oe=()=>U(!1);return window.addEventListener("blur",oe),window.addEventListener("resize",oe),()=>{window.removeEventListener("blur",oe),window.removeEventListener("resize",oe)}},[U]);const[O,D]=z7(oe=>{const se=V().filter(ge=>!ge.disabled),ae=se.find(ge=>ge.ref.current===document.activeElement),le=$7(se,oe,ae);le&&setTimeout(()=>le.ref.current.focus())}),Q=y.useCallback((oe,se,ae)=>{const le=!$.current&&!ae;(S.value!==void 0&&S.value===se||le)&&(I(oe),le&&($.current=!0))},[S.value]),z=y.useCallback(()=>C?.focus(),[C]),J=y.useCallback((oe,se,ae)=>{const le=!$.current&&!ae;(S.value!==void 0&&S.value===se||le)&&H(oe)},[S.value]),ee=s==="popper"?eC:j7,re=ee===eC?{side:l,sideOffset:c,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:g,sticky:b,hideWhenDetached:_,avoidCollisions:w}:{};return r.jsx(S7,{scope:n,content:C,viewport:k,onViewportChange:T,itemRefCallback:Q,selectedItem:M,onItemLeave:z,itemTextRefCallback:J,focusSelectedItem:Y,selectedItemText:R,position:s,isPositioned:K,searchRef:O,children:r.jsx(Sm,{as:E_e,allowPinchZoom:!0,children:r.jsx(Am,{asChild:!0,trapped:S.open,onMountAutoFocus:oe=>{oe.preventDefault()},onUnmountAutoFocus:Oe(i,oe=>{S.trigger?.focus({preventScroll:!0}),oe.preventDefault()}),children:r.jsx(dh,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:oe=>oe.preventDefault(),onDismiss:()=>S.onOpenChange(!1),children:r.jsx(ee,{role:"listbox",id:S.contentId,"data-state":S.open?"open":"closed",dir:S.dir,onContextMenu:oe=>oe.preventDefault(),...A,...re,onPlaced:()=>q(!0),ref:F,style:{display:"flex",flexDirection:"column",outline:"none",...A.style},onKeyDown:Oe(A.onKeyDown,oe=>{const se=oe.ctrlKey||oe.altKey||oe.metaKey;if(oe.key==="Tab"&&oe.preventDefault(),!se&&oe.key.length===1&&D(oe.key),["ArrowUp","ArrowDown","Home","End"].includes(oe.key)){let le=V().filter(ge=>!ge.disabled).map(ge=>ge.ref.current);if(["ArrowUp","End"].includes(oe.key)&&(le=le.slice().reverse()),["ArrowUp","ArrowDown"].includes(oe.key)){const ge=oe.target,je=le.indexOf(ge);le=le.slice(je+1)}setTimeout(()=>B(le)),oe.preventDefault()}})})})})})})});C7.displayName=k_e;var F_e="SelectItemAlignedPosition",j7=y.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:s,...i}=e,a=rc(du,n),o=ac(du,n),[l,c]=y.useState(null),[d,f]=y.useState(null),p=At(t,F=>f(F)),m=Zv(n),g=y.useRef(!1),b=y.useRef(!0),{viewport:_,selectedItem:w,selectedItemText:A,focusSelectedItem:S}=o,C=y.useCallback(()=>{if(a.trigger&&a.valueNode&&l&&d&&_&&w&&A){const F=a.trigger.getBoundingClientRect(),M=d.getBoundingClientRect(),I=a.valueNode.getBoundingClientRect(),R=A.getBoundingClientRect();if(a.dir!=="rtl"){const ge=R.left-M.left,je=I.left-ge,Ee=F.left-je,de=F.width+Ee,me=Math.max(de,M.width),$e=window.innerWidth-Kr,nt=dR(je,[Kr,Math.max(Kr,$e-me)]);l.style.minWidth=de+"px",l.style.left=nt+"px"}else{const ge=M.right-R.right,je=window.innerWidth-I.right-ge,Ee=window.innerWidth-F.right-je,de=F.width+Ee,me=Math.max(de,M.width),$e=window.innerWidth-Kr,nt=dR(je,[Kr,Math.max(Kr,$e-me)]);l.style.minWidth=de+"px",l.style.right=nt+"px"}const H=m(),V=window.innerHeight-Kr*2,K=_.scrollHeight,q=window.getComputedStyle(d),$=parseInt(q.borderTopWidth,10),B=parseInt(q.paddingTop,10),Y=parseInt(q.borderBottomWidth,10),U=parseInt(q.paddingBottom,10),W=$+B+K+U+Y,O=Math.min(w.offsetHeight*5,W),D=window.getComputedStyle(_),Q=parseInt(D.paddingTop,10),z=parseInt(D.paddingBottom,10),J=F.top+F.height/2-Kr,ee=V-J,re=w.offsetHeight/2,oe=w.offsetTop+re,se=$+B+oe,ae=W-se;if(se<=J){const ge=H.length>0&&w===H[H.length-1].ref.current;l.style.bottom="0px";const je=d.clientHeight-_.offsetTop-_.offsetHeight,Ee=Math.max(ee,re+(ge?z:0)+je+Y),de=se+Ee;l.style.height=de+"px"}else{const ge=H.length>0&&w===H[0].ref.current;l.style.top="0px";const Ee=Math.max(J,$+_.offsetTop+(ge?Q:0)+re)+ae;l.style.height=Ee+"px",_.scrollTop=se-J+_.offsetTop}l.style.margin=`${Kr}px 0`,l.style.minHeight=O+"px",l.style.maxHeight=V+"px",s?.(),requestAnimationFrame(()=>g.current=!0)}},[m,a.trigger,a.valueNode,l,d,_,w,A,a.dir,s]);Ks(()=>C(),[C]);const[E,k]=y.useState();Ks(()=>{d&&k(window.getComputedStyle(d).zIndex)},[d]);const T=y.useCallback(F=>{F&&b.current===!0&&(C(),S?.(),b.current=!1)},[C,S]);return r.jsx(M_e,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:T,children:r.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:E},children:r.jsx(lt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});j7.displayName=F_e;var T_e="SelectPopperPosition",eC=y.forwardRef((e,t)=>{const{__scopeSelect:n,align:s="start",collisionPadding:i=Kr,...a}=e,o=ey(n);return r.jsx(Fv,{...o,...a,ref:t,align:s,collisionPadding:i,style:{boxSizing:"border-box",...a.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});eC.displayName=T_e;var[M_e,Gj]=vh(du,{}),tC="SelectViewport",N7=y.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:s,...i}=e,a=ac(tC,n),o=Gj(tC,n),l=At(t,a.onViewportChange),c=y.useRef(0);return r.jsxs(r.Fragment,{children:[r.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:s}),r.jsx(Jv.Slot,{scope:n,children:r.jsx(lt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:Oe(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:m}=o;if(m?.current&&p){const g=Math.abs(c.current-f.scrollTop);if(g>0){const b=window.innerHeight-Kr*2,_=parseFloat(p.style.minHeight),w=parseFloat(p.style.height),A=Math.max(_,w);if(A<b){const S=A+g,C=Math.min(b,S),E=S-C;p.style.height=C+"px",p.style.bottom==="0px"&&(f.scrollTop=E>0?E:0,p.style.justifyContent="flex-end")}}}c.current=f.scrollTop})})})]})});N7.displayName=tC;var k7="SelectGroup",[R_e,D_e]=vh(k7),E7=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e,i=Zi();return r.jsx(R_e,{scope:n,id:i,children:r.jsx(lt.div,{role:"group","aria-labelledby":i,...s,ref:t})})});E7.displayName=k7;var F7="SelectLabel",T7=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e,i=D_e(F7,n);return r.jsx(lt.div,{id:i.id,...s,ref:t})});T7.displayName=F7;var k0="SelectItem",[O_e,M7]=vh(k0),R7=y.forwardRef((e,t)=>{const{__scopeSelect:n,value:s,disabled:i=!1,textValue:a,...o}=e,l=rc(k0,n),c=ac(k0,n),d=l.value===s,[f,p]=y.useState(a??""),[m,g]=y.useState(!1),b=At(t,S=>c.itemRefCallback?.(S,s,i)),_=Zi(),w=y.useRef("touch"),A=()=>{i||(l.onValueChange(s),l.onOpenChange(!1))};if(s==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return r.jsx(O_e,{scope:n,value:s,disabled:i,textId:_,isSelected:d,onItemTextChange:y.useCallback(S=>{p(C=>C||(S?.textContent??"").trim())},[]),children:r.jsx(Jv.ItemSlot,{scope:n,value:s,disabled:i,textValue:f,children:r.jsx(lt.div,{role:"option","aria-labelledby":_,"data-highlighted":m?"":void 0,"aria-selected":d&&m,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:b,onFocus:Oe(o.onFocus,()=>g(!0)),onBlur:Oe(o.onBlur,()=>g(!1)),onClick:Oe(o.onClick,()=>{w.current!=="mouse"&&A()}),onPointerUp:Oe(o.onPointerUp,()=>{w.current==="mouse"&&A()}),onPointerDown:Oe(o.onPointerDown,S=>{w.current=S.pointerType}),onPointerMove:Oe(o.onPointerMove,S=>{w.current=S.pointerType,i?c.onItemLeave?.():w.current==="mouse"&&S.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Oe(o.onPointerLeave,S=>{S.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:Oe(o.onKeyDown,S=>{c.searchRef?.current!==""&&S.key===" "||(__e.includes(S.key)&&A(),S.key===" "&&S.preventDefault())})})})})});R7.displayName=k0;var Jf="SelectItemText",D7=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:s,style:i,...a}=e,o=rc(Jf,n),l=ac(Jf,n),c=M7(Jf,n),d=C_e(Jf,n),[f,p]=y.useState(null),m=At(t,A=>p(A),c.onItemTextChange,A=>l.itemTextRefCallback?.(A,c.value,c.disabled)),g=f?.textContent,b=y.useMemo(()=>r.jsx("option",{value:c.value,disabled:c.disabled,children:g},c.value),[c.disabled,c.value,g]),{onNativeOptionAdd:_,onNativeOptionRemove:w}=d;return Ks(()=>(_(b),()=>w(b)),[_,w,b]),r.jsxs(r.Fragment,{children:[r.jsx(lt.span,{id:c.textId,...a,ref:m}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Xr.createPortal(a.children,o.valueNode):null]})});D7.displayName=Jf;var O7="SelectItemIndicator",P7=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e;return M7(O7,n).isSelected?r.jsx(lt.span,{"aria-hidden":!0,...s,ref:t}):null});P7.displayName=O7;var nC="SelectScrollUpButton",P_e=y.forwardRef((e,t)=>{const n=ac(nC,e.__scopeSelect),s=Gj(nC,e.__scopeSelect),[i,a]=y.useState(!1),o=At(t,s.onScrollButtonChange);return Ks(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=c.scrollTop>0;a(d)};const c=n.viewport;return l(),c.addEventListener("scroll",l),()=>c.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?r.jsx(I7,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:c}=n;l&&c&&(l.scrollTop=l.scrollTop-c.offsetHeight)}}):null});P_e.displayName=nC;var sC="SelectScrollDownButton",I_e=y.forwardRef((e,t)=>{const n=ac(sC,e.__scopeSelect),s=Gj(sC,e.__scopeSelect),[i,a]=y.useState(!1),o=At(t,s.onScrollButtonChange);return Ks(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=c.scrollHeight-c.clientHeight,f=Math.ceil(c.scrollTop)<d;a(f)};const c=n.viewport;return l(),c.addEventListener("scroll",l),()=>c.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?r.jsx(I7,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:c}=n;l&&c&&(l.scrollTop=l.scrollTop+c.offsetHeight)}}):null});I_e.displayName=sC;var I7=y.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:s,...i}=e,a=ac("SelectScrollButton",n),o=y.useRef(null),l=Zv(n),c=y.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return y.useEffect(()=>()=>c(),[c]),Ks(()=>{l().find(f=>f.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[l]),r.jsx(lt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Oe(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(s,50))}),onPointerMove:Oe(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(s,50))}),onPointerLeave:Oe(i.onPointerLeave,()=>{c()})})}),L_e="SelectSeparator",B_e=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e;return r.jsx(lt.div,{"aria-hidden":!0,...s,ref:t})});B_e.displayName=L_e;var iC="SelectArrow",z_e=y.forwardRef((e,t)=>{const{__scopeSelect:n,...s}=e,i=ey(n),a=rc(iC,n),o=ac(iC,n);return a.open&&o.position==="popper"?r.jsx(Tv,{...i,...s,ref:t}):null});z_e.displayName=iC;var $_e="SelectBubbleInput",L7=y.forwardRef(({__scopeSelect:e,value:t,...n},s)=>{const i=y.useRef(null),a=At(s,i),o=m7(t);return y.useEffect(()=>{const l=i.current;if(!l)return;const c=window.HTMLSelectElement.prototype,f=Object.getOwnPropertyDescriptor(c,"value").set;if(o!==t&&f){const p=new Event("change",{bubbles:!0});f.call(l,t),l.dispatchEvent(p)}},[o,t]),r.jsx(lt.select,{...n,style:{...G9,...n.style},ref:a,defaultValue:t})});L7.displayName=$_e;function B7(e){return e===""||e===void 0}function z7(e){const t=ia(e),n=y.useRef(""),s=y.useRef(0),i=y.useCallback(o=>{const l=n.current+o;t(l),(function c(d){n.current=d,window.clearTimeout(s.current),d!==""&&(s.current=window.setTimeout(()=>c(""),1e3))})(l)},[t]),a=y.useCallback(()=>{n.current="",window.clearTimeout(s.current)},[]);return y.useEffect(()=>()=>window.clearTimeout(s.current),[]),[n,i,a]}function $7(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,a=n?e.indexOf(n):-1;let o=V_e(e,Math.max(a,0));i.length===1&&(o=o.filter(d=>d!==n));const c=o.find(d=>d.textValue.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function V_e(e,t){return e.map((n,s)=>e[(t+s)%e.length])}var ss=x7,is=b7,Ds=y7,Yl=_7,rs=w7,as=A7,os=N7,Ro=E7,Do=T7,vn=R7,yn=D7,ui=P7;function bt({label:e,side:t="top",children:n}){return r.jsx(sj,{delayDuration:300,children:r.jsxs(iB,{children:[r.jsx(rB,{asChild:!0,children:n}),r.jsx(aB,{children:r.jsxs(oB,{side:t,sideOffset:6,className:"px-2 py-1 rounded-md bg-[#2A2A35] border border-[#3A3A48] text-[#F0F0F5] text-[11px] font-medium shadow-lg z-[9999] select-none",children:[e,r.jsx(lB,{className:"fill-[#2A2A35]"})]})})]})})}const Vp=[{label:"Local",tag:"local",models:[]},{label:"OpenRouter Free",tag:"free",provider:"openrouter",models:[{id:"openrouter/meta-llama/llama-3.3-70b-instruct:free",label:"Llama 3.3 70B"},{id:"openrouter/google/gemma-3-27b-it:free",label:"Gemma 3 27B"},{id:"openrouter/mistralai/mistral-7b-instruct:free",label:"Mistral 7B"}]},{label:"OpenRouter Paid",tag:"paid",provider:"openrouter",models:[{id:"openrouter/anthropic/claude-haiku-4.5",label:"Haiku 4.5"},{id:"openrouter/anthropic/claude-sonnet-4.6",label:"Sonnet 4.6"},{id:"openrouter/anthropic/claude-opus-4.7",label:"Opus 4.7"},{id:"openrouter/openai/gpt-5.4-mini",label:"GPT-5.4 mini"},{id:"openrouter/openai/gpt-5.4",label:"GPT-5.4"},{id:"openrouter/google/gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"openrouter/google/gemini-2.5-pro",label:"Gemini 2.5 Pro"}]},{label:"Anthropic",tag:"paid",provider:"anthropic",models:[{id:"anthropic/claude-haiku-4.5",label:"Haiku 4.5"},{id:"anthropic/claude-sonnet-4.6",label:"Sonnet 4.6"},{id:"anthropic/claude-opus-4.7",label:"Opus 4.7"}]},{label:"OpenAI",tag:"paid",provider:"openai",models:[{id:"openai/gpt-5.4-nano",label:"GPT-5.4 nano"},{id:"openai/gpt-5.4-mini",label:"GPT-5.4 mini"},{id:"openai/gpt-5.4",label:"GPT-5.4"}]},{label:"Google",tag:"paid",provider:"google",models:[{id:"google/gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro"}]}],jo={local:"text-[#10B981] bg-[#10B981]/10",free:"text-[#8B5CF6] bg-[#8B5CF6]/10",paid:"text-[#F59E0B] bg-[#F59E0B]/10",custom:"text-[#6366F1] bg-[#6366F1]/10"},U_e=["vllm/","ollama/","openrouter/","anthropic/","openai/","google/","claude-code/"];function E0(e){for(const t of U_e)if(e.startsWith(t))return e.slice(t.length);return e}function ta(e){if(!e)return"";for(const n of Vp){const s=n.models.find(i=>i.id===e);if(s)return s.label}const t=E0(e);for(const n of Vp){const s=n.models.find(i=>E0(i.id)===t);if(s)return s.label}return t}function Up(e){if(!e)return"custom";if(e.startsWith("vllm/")||e.startsWith("ollama/"))return"local";for(const n of Vp)if(n.models.some(s=>s.id===e))return n.tag;const t=E0(e);for(const n of Vp)if(n.models.some(s=>E0(s.id)===t))return n.tag;return e.startsWith("openrouter/")||e.startsWith("anthropic/")||e.startsWith("openai/")||e.startsWith("google/")||e.startsWith("claude-code/")?"paid":"custom"}function Vm(){const{data:e}=L.agents.discoverLocalModels.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),{data:t}=L.onboarding.providersConfigured.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),n=(e??[]).map(o=>({id:o.id,label:o.parameterSize?`${o.name} (${o.parameterSize})`:o.name})),s=Vp.map(o=>o.tag==="local"?{...o,models:n}:o).filter(o=>o.models.length===0?!1:!o.provider||t===void 0?!0:!!t[o.provider]),i=!!t&&(t.openrouter||t.anthropic||t.openai||t.google),a=t!==void 0&&!i;return{groups:s,needsHostedProviderSetup:a,needsOpenRouterSetup:a}}const H_e=8;function ty({value:e,onChange:t,onSubmit:n,placeholder:s="Add model ID...",className:i="",autoFocus:a=!1}){const{data:o}=L.agents.discoverLocalModels.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),{data:l}=L.onboarding.discoverProviderModels.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),c=y.useMemo(()=>{const w=(o??[]).map(S=>({id:S.id,label:S.parameterSize?`${S.name} (${S.parameterSize})`:S.name})),A=[...l?.openrouter??[],...l?.anthropic??[],...l?.openai??[],...l?.google??[]];return[...w,...A]},[o,l]),[d,f]=y.useState(!1),[p,m]=y.useState(0),g=y.useMemo(()=>{const w=e.trim().toLowerCase();return w?c.filter(A=>A.id.toLowerCase().includes(w)||A.label.toLowerCase().includes(w)).slice(0,H_e):[]},[e,c]);y.useEffect(()=>{m(0)},[e]);function b(w){if(w.stopPropagation(),w.key==="ArrowDown"){g.length>0&&(w.preventDefault(),f(!0),m(A=>Math.min(A+1,g.length-1)));return}if(w.key==="ArrowUp"){g.length>0&&(w.preventDefault(),f(!0),m(A=>Math.max(A-1,0)));return}if(w.key==="Tab"){if(d&&g[p]){w.preventDefault(),t(g[p].id);return}return}if(w.key==="Escape"){d&&(w.preventDefault(),f(!1));return}if(w.key==="Enter"){w.preventDefault();const A=d&&g[p]?g[p].id:e.trim();if(!A)return;n(A),f(!1)}}const _=y.useRef(null);return r.jsxs("div",{className:`relative ${i}`,children:[r.jsx("input",{ref:_,autoFocus:a,value:e,placeholder:s,onChange:w=>{t(w.target.value),f(!0)},onFocus:()=>{e&&f(!0)},onBlur:()=>{setTimeout(()=>f(!1),120)},onKeyDown:b,className:"w-full bg-[#13131A] border border-[#2A2A35] rounded px-2 py-1.5 text-[11px] text-[#C8C8D4] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] transition-colors"}),d&&g.length>0&&r.jsx("div",{className:"absolute left-0 right-0 top-full mt-1 bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 z-[10000] max-h-[240px] overflow-y-auto",children:g.map((w,A)=>r.jsxs("button",{type:"button",onMouseDown:S=>{S.preventDefault(),n(w.id),f(!1)},onMouseEnter:()=>m(A),className:`block w-full text-left px-3 py-1.5 text-[11px] outline-none transition-colors ${A===p?"bg-white/10 text-[#F0F0F5]":"text-[#C8C8D4] hover:bg-white/5"}`,children:[r.jsx("div",{className:"truncate",children:w.id}),w.label!==w.id&&r.jsx("div",{className:"truncate text-[10px] text-[#5A5A6E]",children:w.label})]},w.id))})]})}const hR={sessionTokensIn:0,sessionTokensOut:0,sessionCostUsd:0,contextWindow:null},ny=$o(e=>({stats:{},setStats:(t,n)=>e(s=>({stats:{...s.stats,[t]:n}})),updateFromWs:(t,n)=>e(s=>({stats:{...s.stats,[t]:{...s.stats[t]??hR,...n}}})),clearStats:t=>e(n=>({stats:{...n.stats,[t]:hR}}))}));function bA(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function fR(e){return e<.005?"$0.00":e<1?`$${e.toFixed(2)}`:`$${e.toFixed(2)}`}const W_e=1e5;function q_e({channelId:e}){const t=L.useUtils(),{data:n}=L.channels.sessionStats.useQuery({channelId:e}),{stats:s,setStats:i,clearStats:a}=ny(),o=L.channels.resetSessionStats.useMutation({onSuccess:()=>{a(e),t.channels.sessionStats.invalidate({channelId:e})}});y.useEffect(()=>{n&&i(e,n)},[n,e,i]);const l=s[e];if(!l)return null;const c=l.sessionTokensIn+l.sessionTokensOut;if(c===0)return null;const d=l.contextWindow??W_e,f=l.sessionTokensIn/d,p=f>.8?"text-red-400":f>.5?"text-amber-400":"text-[#5A5A6E]";return r.jsxs(Ys,{children:[r.jsx(ci,{asChild:!0,children:r.jsxs("button",{className:`flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium transition-colors hover:bg-white/5 ${p}`,children:[r.jsx("span",{children:bA(c)}),r.jsx("span",{className:"opacity-50",children:"·"}),r.jsx("span",{children:fR(l.sessionCostUsd)})]})}),r.jsx(Qs,{children:r.jsxs(Xs,{align:"end",sideOffset:6,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl w-[220px] z-50 p-3",children:[r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Input tokens"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] font-medium",children:bA(l.sessionTokensIn)})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Output tokens"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] font-medium",children:bA(l.sessionTokensOut)})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Total cost"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] font-medium",children:fR(l.sessionCostUsd)})]}),r.jsxs("div",{className:"pt-1",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Context usage"}),r.jsxs("span",{className:"text-[11px] text-[#5A5A6E]",children:[Math.round(f*100),"%"]})]}),r.jsx("div",{className:"h-1.5 bg-[#2A2A35] rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full rounded-full transition-all ${f>.8?"bg-red-400":f>.5?"bg-amber-400":"bg-[#6366F1]"}`,style:{width:`${Math.min(f*100,100)}%`}})})]}),r.jsx("button",{onClick:()=>o.mutate({channelId:e}),disabled:o.isPending,className:"w-full mt-1 px-2 py-1.5 rounded-md text-[11px] text-[#8A8A99] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors border border-[#2A2A35]",children:o.isPending?"Resetting...":"Reset counters"})]}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]})}const V7=$o()(gj(e=>({lastTab:{},setLast:(t,n)=>e(s=>({lastTab:{...s.lastTab,[t]:n}})),clearLast:t=>e(n=>{const s={...n.lastTab};return delete s[t],{lastTab:s}})}),{name:"damn-dev-last-active-tab"}));function pR(e,t){return e.tabName&&e.tabName.trim().length>0?e.tabName:t?"Main":`Tab ${e.tabOrder+1}`}function G_e({baseChannelId:e,activeTabId:t,agentColor:n}){const s=an(),i=L.useUtils(),{data:a=[]}=dfe(e),[o,l]=y.useState(null),[c,d]=y.useState(""),[f,p]=y.useState(null),m=y.useRef(null),g=y.useCallback(()=>{i.channels.get.invalidate({channelId:e}),i.channels.list.invalidate()},[i,e]),b=L.channels.createTab.useMutation({onSuccess:k=>{g(),s(`/channels/${k.id}`)}}),_=L.channels.renameTab.useMutation({onSuccess:g}),w=L.channels.deleteTab.useMutation({onSuccess:(k,T)=>{g(),p(null),T.channelId===t&&s(`/channels/${e}`)}});if(y.useEffect(()=>{o&&m.current&&(m.current.focus(),m.current.select())},[o]),e==="chan_coo")return null;const A=(k,T)=>{l(k),d(T)},S=()=>{if(!o)return;const k=c.trim(),T=a.find(F=>F.id===o);T&&k&&k!==pR(T,T.id===e)&&_.mutate({channelId:o,name:k}),l(null)},C=()=>{l(null),d("")},E=n??"#6366F1";return r.jsxs("div",{className:"flex items-center gap-1 px-3 h-9 border-t border-[#2A2A35] bg-[#0F0F11] overflow-x-auto scrollbar-none",children:[a.map(k=>{const T=k.id===t,F=k.id===e,M=k.unreadCount>0&&!T,I=o===k.id,R=pR(k,F),H=()=>{I||(T?A(k.id,R):(F&&V7.getState().clearLast(e),s(`/channels/${k.id}`)))};return r.jsx("div",{className:ye("group relative flex items-center gap-1.5 px-2.5 h-7 rounded-md text-[12px] transition-colors select-none flex-shrink-0",T?"bg-[#1A1A22] text-[#F0F0F5]":"text-[#8A8A99] hover:bg-[#15151B] hover:text-[#C0C0CC] cursor-pointer",T&&!I&&"cursor-text"),style:T?{boxShadow:`inset 0 -2px 0 ${E}`}:void 0,onClick:H,onDoubleClick:V=>{V.stopPropagation(),I||A(k.id,R)},children:I?r.jsx("input",{ref:m,value:c,onChange:V=>d(V.target.value),onBlur:S,onKeyDown:V=>{V.key==="Enter"?S():V.key==="Escape"&&C()},onClick:V=>V.stopPropagation(),onDoubleClick:V=>V.stopPropagation(),maxLength:80,className:"bg-transparent outline-none text-[12px] text-[#F0F0F5] w-[120px]"}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"truncate max-w-[140px]",title:R,children:R}),M&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:E}}),!F&&r.jsxs(Ys,{open:f===k.id,onOpenChange:V=>p(V?k.id:null),children:[r.jsx(ci,{asChild:!0,children:r.jsx("button",{onClick:V=>{V.stopPropagation(),p(k.id)},className:ye("transition-opacity text-[#6A6A78] hover:text-[#F0F0F5] ml-0.5",T||f===k.id?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":"Close tab",children:r.jsx(Te,{className:"w-3 h-3"})})}),r.jsx(Qs,{children:r.jsxs(Xs,{className:"bg-[#15151B] border border-[#2A2A35] rounded-lg shadow-xl p-3 w-[220px] z-50",sideOffset:8,onOpenAutoFocus:V=>V.preventDefault(),children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium mb-1",children:"Delete this tab?"}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99] mb-3 leading-snug",children:["All messages in “",R,"” will be permanently removed."]}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx("button",{onClick:V=>{V.stopPropagation(),p(null)},className:"px-2.5 h-6 rounded text-[11px] text-[#8A8A99] hover:bg-[#1A1A22] hover:text-[#F0F0F5] transition-colors",children:"Cancel"}),r.jsx("button",{onClick:V=>{V.stopPropagation(),w.mutate({channelId:k.id})},disabled:w.isPending,className:"px-2.5 h-6 rounded text-[11px] bg-red-500/10 text-red-400 hover:bg-red-500/20 transition-colors disabled:opacity-50",children:"Delete"})]}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]})]})},k.id)}),r.jsx("button",{onClick:()=>b.mutate({parentChannelId:e}),disabled:b.isPending,className:"flex items-center justify-center w-6 h-6 rounded-md text-[#6A6A78] hover:bg-[#15151B] hover:text-[#F0F0F5] transition-colors flex-shrink-0 disabled:opacity-50","aria-label":"New tab",children:r.jsx(wt,{className:"w-3.5 h-3.5"})})]})}function K_e(e){const t=Date.now()-e.getTime(),n=Math.floor(t/6e4);if(n<1)return"Last seen just now";if(n<60)return`Last seen ${n}m ago`;const s=Math.floor(n/60);return s<24?`Last seen ${s}h ago`:`Last seen ${Math.floor(s/24)}d ago`}function Y_e({userId:e}){const t=Sfe(e);return t?r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"relative flex items-center justify-center w-2 h-2",children:r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:t.online?"#10B981":"#3A3A45"}})}),r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:t.online?"Online":t.lastSeenAt?K_e(new Date(t.lastSeenAt)):"Offline"})]}):null}function Q_e({channelId:e,agentId:t,defaultModel:n,agentColor:s,customModels:i=[]}){const[a,o]=y.useState(""),{data:l}=L.agents.getConversationModel.useQuery({channelId:e}),c=L.agents.setConversationModel.useMutation(),d=L.agents.update.useMutation(),f=L.agents.addCustomModel.useMutation(),p=L.useUtils(),{groups:m,needsHostedProviderSetup:g}=Vm(),b=l?.model??null,_=b!==null,w=b??n,A=Up(w);function S(C){C==="__reset__"?c.mutate({channelId:e,model:null},{onSuccess:()=>p.agents.getConversationModel.invalidate({channelId:e})}):(c.mutate({channelId:e,model:C},{onSuccess:()=>p.agents.getConversationModel.invalidate({channelId:e})}),d.mutate({agentId:t,model:C},{onSuccess:()=>p.agents.list.invalidate()}))}return r.jsxs(ss,{value:w,onValueChange:S,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] border transition-colors outline-none border-opacity-40",style:{color:s,backgroundColor:`${s}15`,borderColor:`${s}40`},children:[r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[A]}`,children:A}),r.jsx(Ds,{children:ta(w)}),r.jsx(ft,{className:"w-3 h-3 opacity-60"})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:6,align:"end",className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] z-50",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:a,onChange:o,onSubmit:C=>{f.mutate({agentId:t,modelId:C},{onSuccess:()=>p.agents.list.invalidate()}),S(C),o("")}})}),r.jsxs(os,{children:[m.map(C=>r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:C.label}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo[C.tag]}`,children:C.tag})]}),C.models.map(E=>r.jsxs(vn,{value:E.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:E.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},E.id))]},C.label)),i.length>0&&r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:"Custom"}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo.custom}`,children:"custom"})]}),i.map(C=>r.jsxs(vn,{value:C,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:C}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},C))]}),_&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"my-1 border-t border-[#2A2A35]"}),r.jsx(vn,{value:"__reset__",className:"flex items-center px-3 py-1.5 text-[12px] text-[#8A8A99] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:r.jsx(yn,{children:"Reset to default"})})]})]}),g&&r.jsx(gn,{to:"/settings?tab=runtime",className:"block px-3 py-1.5 text-[11px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 border-t border-[#2A2A35] mt-1 transition-colors",children:"+ Configure providers →"})]})})]})}function X_e({color:e}){return r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("span",{className:"relative flex items-center justify-center w-2 h-2",children:[r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:e,opacity:.5},animate:{scale:[1,2.2,1],opacity:[.5,0,.5]},transition:{duration:1.4,repeat:1/0}}),r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e}})]}),r.jsx("span",{className:"text-[12px]",style:{color:e},children:"Waiting for your approval"})]})}function J_e({status:e,color:t}){const n={thinking:"thinking",executing:"executing",idle:"idle",offline:"offline"},s=e==="thinking"||e==="executing";return r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs("span",{className:"relative flex items-center justify-center w-2 h-2",children:[s&&r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:t,opacity:.5},animate:{scale:[1,2,1],opacity:[.5,0,.5]},transition:{duration:1.8,repeat:1/0}}),r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e==="offline"?"#3A3A45":t,opacity:e==="idle"?.5:1}})]}),r.jsx("span",{className:"text-[12px] text-[#8A8A99] capitalize",children:n[e]})]})}function Z_e({channelId:e,color:t}){const[n,s]=y.useState(!1),i=L.useUtils(),a=L.messages.resetSession.useMutation({onSuccess:()=>{s(!0),setTimeout(()=>s(!1),2e3),ny.getState().clearStats(e),i.channels.sessionStats.invalidate({channelId:e})}});return r.jsx(bt,{label:"Reset context",children:r.jsx("button",{onClick:()=>a.mutate({channelId:e}),className:"w-8 h-8 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",style:n?{color:t}:{},children:r.jsx(lh,{className:ye("w-4 h-4",a.isPending&&"animate-spin")})})})}function ewe({channelId:e,onCleared:t}){const[n,s]=y.useState(!1),i=L.useUtils(),a=L.messages.clearConversation.useMutation({onSuccess:()=>{s(!1),t?.(),ny.getState().clearStats(e),i.channels.sessionStats.invalidate({channelId:e})}});return n?r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{onClick:()=>a.mutate({channelId:e}),disabled:a.isPending,className:"px-2 py-1 rounded-md text-[11px] font-medium text-[#EF4444] bg-[#EF4444]/10 hover:bg-[#EF4444]/20 transition-colors",children:a.isPending?"Clearing...":"Confirm"}),r.jsx("button",{onClick:()=>s(!1),className:"px-2 py-1 rounded-md text-[11px] text-[#8A8A99] hover:bg-white/5 transition-colors",children:"Cancel"})]}):r.jsx(bt,{label:"Clear conversation",children:r.jsx("button",{onClick:()=>s(!0),className:"w-8 h-8 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors",children:r.jsx(Dn,{className:"w-4 h-4"})})})}function twe({channelId:e,color:t,onJump:n}){const{data:s=[]}=L.messages.pinned.useQuery({channelId:e});return s.length===0?null:r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-transparent hover:border-[#2A2A35]",children:[r.jsx(P5,{className:"w-3.5 h-3.5",style:{color:t}}),r.jsxs("span",{children:[s.length," pinned"]})]})}),r.jsx(Od,{children:r.jsxs(Xv,{align:"end",sideOffset:6,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 w-[300px] z-50",children:[r.jsx("div",{className:"px-3 py-2 border-b border-[#2A2A35]",children:r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Pinned Messages"})}),s.map(i=>r.jsxs(Bl,{onSelect:()=>n(i.id),className:"flex flex-col gap-0.5 px-3 py-2.5 cursor-pointer hover:bg-white/5 outline-none transition-colors",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#C8C8D4] truncate",children:i.sender.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] shrink-0",children:Ir(i.timestamp)})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] truncate",children:i.content}),r.jsx("span",{className:"text-[11px] text-[#6366F1] mt-0.5",children:"Jump to message"})]},i.id))]})})]})}function nwe({channelId:e}){const t=L.useUtils(),{data:n}=L.channelPreferences.get.useQuery({channelId:e}),s=n?.muted??!1,i=L.channelPreferences.set.useMutation({onMutate:async({muted:a})=>{await t.channelPreferences.get.cancel({channelId:e});const o=t.channelPreferences.get.getData({channelId:e});return t.channelPreferences.get.setData({channelId:e},l=>({...l,channelId:e,muted:a??!1,notifyOnMention:l?.notifyOnMention??!0})),{prev:o}},onError:(a,o,l)=>{l?.prev&&t.channelPreferences.get.setData({channelId:e},l.prev)},onSettled:()=>{t.channelPreferences.get.invalidate({channelId:e}),t.channelPreferences.listMuted.invalidate()}});return r.jsx(bt,{label:s?"Unmute channel":"Mute channel",children:r.jsx("button",{onClick:()=>i.mutate({channelId:e,muted:!s}),className:ye("w-8 h-8 flex items-center justify-center rounded-md transition-colors",s?"text-[#F59E0B] hover:bg-[#F59E0B]/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5"),children:s?r.jsx(tL,{className:"w-4 h-4"}):r.jsx(Ase,{className:"w-4 h-4"})})})}function swe({channel:e,agent:t,agentColor:n,hasPendingApproval:s=!1,rightPanelOpen:i,memoryPanelOpen:a,activeOverride:o,humanDmName:l,humanDmUserId:c,onToggleRightPanel:d,onToggleMemoryPanel:f,onAgentClick:p,onClearOverride:m,onClearConversation:g,onJumpToMessage:b}){const _=n??t?.color??"#6366F1",w=!!t&&e.channelType==="dm",A=e.channelType==="dm"&&!e.agentId,S=e.channelType==="topic",C=e.channelType==="group"||e.channelType==="topic",E=Uo(),k=L.channels.setResponseMode.useMutation(),T=L.useUtils();return r.jsxs("div",{className:"flex flex-col border-b border-[#2A2A35] bg-[#0F0F11] flex-shrink-0",style:w&&!S?{borderLeftColor:_,borderLeftWidth:3,borderLeftStyle:"solid"}:{},children:[r.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[A?r.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-[#6366F1] to-[#8B5CF6] flex items-center justify-center text-[11px] font-semibold text-white flex-shrink-0",children:(l??"U").split(" ").map(F=>F[0]).join("").slice(0,2).toUpperCase()}):t&&!S?r.jsx("button",{onClick:p,className:"w-8 h-8 rounded-full flex items-center justify-center text-lg flex-shrink-0 transition-opacity hover:opacity-80",style:{backgroundColor:`${_}26`},children:t.emoji}):r.jsx("div",{className:"w-8 h-8 rounded-full bg-[#2A2A35] flex items-center justify-center",children:r.jsx("span",{className:"text-[#8A8A99] text-sm",children:"#"})}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[A?r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:l??"User"}):t&&!S?r.jsx("button",{onClick:p,className:"text-[15px] font-semibold text-[#F0F0F5] hover:underline decoration-dashed underline-offset-2 transition-colors",children:t.name}):r.jsxs("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:["#",e.name]}),t&&!S&&r.jsx("span",{className:"text-[11px] text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded",children:t.role}),S&&r.jsxs("span",{className:"text-[11px] text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded border border-[#2A2A35] flex items-center gap-1",children:[e.visibility==="public"?r.jsx(Xt,{className:"w-3 h-3"}):r.jsx(Eo,{className:"w-3 h-3"}),"Topic"]})]}),t&&!S&&!s&&r.jsx(J_e,{status:t.status,color:_}),t&&!S&&s&&r.jsx(X_e,{color:_}),S&&e.description&&r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:e.description}),A&&r.jsx(Y_e,{userId:c}),!t&&!S&&!A&&r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:["#",e.name]})]})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[E&&t&&!S&&r.jsx(Q_e,{channelId:e.id,agentId:t.id,defaultModel:t.defaultModel,agentColor:_,customModels:(()=>{try{return t.customModels?JSON.parse(t.customModels):[]}catch{return[]}})()}),w&&!S&&r.jsx(q_e,{channelId:e.id}),w&&!S&&r.jsx(Z_e,{channelId:e.id,color:_}),w&&!S&&r.jsx(ewe,{channelId:e.id,onCleared:g}),S&&r.jsx(S$,{channel:e}),C&&r.jsx(bt,{label:e.responseMode==="mention"?"Agents respond only when @mentioned":"Agents respond to every message",children:r.jsxs("button",{onClick:()=>{const F=e.responseMode==="always"?"mention":"always";k.mutate({channelId:e.id,responseMode:F},{onSuccess:()=>T.channels.list.invalidate()})},className:ye("flex items-center gap-1 px-2 py-1 rounded-md text-[12px] border transition-colors",e.responseMode==="mention"?"text-[#A78BFA] bg-[#8B5CF6]/10 border-[#8B5CF6]/30":"text-[#8A8A99] border-transparent hover:border-[#2A2A35] hover:bg-white/5"),children:[e.responseMode==="mention"?r.jsx(eL,{className:"w-3.5 h-3.5"}):r.jsx(pL,{className:"w-3.5 h-3.5"}),r.jsx("span",{children:e.responseMode==="mention"?"mention":"auto"})]})}),r.jsx(nwe,{channelId:e.id}),r.jsx(twe,{channelId:e.id,color:S?"#8A8A99":_,onJump:b??(F=>{document.getElementById(`msg-${F}`)?.scrollIntoView({behavior:"smooth",block:"center"})})}),t&&!S&&r.jsx(bt,{label:a?"Close memory":"View memory",children:r.jsx("button",{onClick:f,className:ye("w-8 h-8 flex items-center justify-center rounded-md transition-colors",a?"text-[#F0F0F5] bg-white/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5"),children:r.jsx(Cse,{className:"w-4 h-4"})})}),r.jsx(bt,{label:i?"Close panel":"Open panel",children:r.jsx("button",{onClick:d,className:ye("w-8 h-8 flex items-center justify-center rounded-md transition-colors",i?"text-[#F0F0F5] bg-white/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5"),children:i?r.jsx(mL,{className:"w-4 h-4"}):r.jsx(xL,{className:"w-4 h-4"})})})]})]}),o&&r.jsxs(ne.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.25},className:"flex items-center justify-between px-5 py-2 bg-amber-500/10 border-t border-amber-500/20",children:[r.jsxs("p",{className:"text-[12px] text-amber-400 truncate",children:[r.jsx("span",{className:"font-medium",children:"Override active:"})," ",o.length>60?`${o.slice(0,60)}...`:o]}),r.jsx("button",{onClick:m,className:"ml-3 flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-amber-400/70 hover:text-amber-300 hover:bg-amber-500/10 transition-colors",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),e.channelType!=="terminal"&&e.id!=="chan_coo"&&r.jsx(G_e,{baseChannelId:e.parentChannelId??e.id,activeTabId:e.id,agentColor:_})]})}function U7({agent:e}){return r.jsxs("div",{className:"flex items-start gap-3 px-4 py-2.5",children:[r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-base flex-shrink-0 mt-0.5",style:{backgroundColor:`${e.color}26`},children:e.emoji}),r.jsxs("div",{className:"flex flex-col gap-1 pt-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[13px] font-semibold",style:{color:e.color},children:e.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:e.status==="thinking"?"thinking...":"executing..."})]}),r.jsx("div",{className:"flex items-center gap-1 px-3 py-2 rounded-lg rounded-tl-sm",style:{backgroundColor:`${e.color}0D`,border:`1px solid ${e.color}26`},children:[0,1,2].map(t=>r.jsx(ne.span,{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:e.color},animate:{opacity:[.3,1,.3],scale:[.8,1.1,.8]},transition:{duration:1.4,repeat:1/0,delay:t*.2,ease:"easeInOut"}},t))})]})]})}function iwe(e){return new Promise((t,n)=>{const s=new FileReader;s.onload=()=>t(s.result.split(",")[1]),s.onerror=n,s.readAsDataURL(e)})}function rwe({staged:e,onRemove:t}){const n=e.file.type.startsWith("image/"),s=Math.round(e.file.size/1024);return r.jsxs(ne.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{duration:.15},className:"relative group/card flex-shrink-0",children:[r.jsx("button",{onClick:t,className:"absolute -top-1.5 -right-1.5 w-4 h-4 bg-[#2A2A35] border border-[#3A3A45] rounded-full flex items-center justify-center text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-[#EF4444]/20 transition-colors z-10 opacity-0 group-hover/card:opacity-100",children:r.jsx(Te,{className:"w-2.5 h-2.5"})}),n&&e.preview?r.jsx("div",{className:"w-[60px] h-[60px] rounded-lg overflow-hidden border border-[#2A2A35]",children:r.jsx("img",{src:e.preview,alt:e.file.name,className:"w-full h-full object-cover"})}):r.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2 bg-[#1C1C24] border border-[#2A2A35] rounded-lg max-w-[160px]",children:[r.jsx("div",{className:"w-6 h-6 rounded bg-[#2A2A35] flex items-center justify-center flex-shrink-0",children:r.jsx("span",{className:"text-[9px] font-semibold text-[#8A8A99] uppercase",children:e.file.name.split(".").pop()?.slice(0,3)??"file"})}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-[11px] text-[#C8C8D4] font-medium truncate",children:e.file.name}),r.jsxs("div",{className:"text-[10px] text-[#8A8A99]",children:[s,"KB"]})]})]}),e.uploadedId===void 0&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center rounded-lg bg-black/40",children:r.jsx("div",{className:"w-3 h-3 border-2 border-white/30 border-t-white rounded-full animate-spin"})})]})}function H7({channelId:e,channelName:t,agent:n,agentColor:s,onSend:i,disabled:a,placeholder:o,mentionableParticipants:l=[]}){const[c,d]=y.useState(""),[f,p]=y.useState(!1),[m,g]=y.useState([]),[b,_]=y.useState(!1),[w,A]=y.useState(null),[S,C]=y.useState(0),[E,k]=y.useState(-1),[T,F]=y.useState(!1),M=y.useRef(null),I=y.useRef(null),R=s??n?.color,H=!!n&&(n.status==="thinking"||n.status==="executing"),V=Uo(),K=L.agents.cancelThinking.useMutation(),q=L.attachments.upload.useMutation(),$=y.useMemo(()=>{if(w===null||l.length===0)return[];const se=w.toLowerCase();return l.filter(ae=>ae.name.toLowerCase().startsWith(se))},[w,l]);y.useEffect(()=>{const se=w!==null&&$.length>0;F(se),se&&C(0)},[w,$.length]);function B(se,ae){if(l.length===0){A(null);return}const le=se.slice(0,ae),ge=le.lastIndexOf("@");if(ge===-1||ge>0&&le[ge-1]!==" "&&le[ge-1]!==`
132
132
  `){A(null),k(-1);return}const je=le.slice(ge+1);if(je.includes(" ")&&!l.some(Ee=>Ee.name.toLowerCase().startsWith(je.toLowerCase()))){A(null),k(-1);return}A(je),k(ge)}function Y(se){if(E===-1)return;const ae=c.slice(0,E),le=M.current?.selectionStart??c.length,ge=c.slice(le),je=`${ae}@${se} ${ge}`;d(je),A(null),k(-1),requestAnimationFrame(()=>{const Ee=ae.length+se.length+2;M.current?.setSelectionRange(Ee,Ee),M.current?.focus()})}const U=y.useCallback(async se=>{for(const ae of se){const le=`${Date.now()}-${Math.random()}`,ge=ae.type.startsWith("image/")?URL.createObjectURL(ae):void 0;g(je=>[...je,{file:ae,preview:ge,id:le,uploadedId:void 0}]);try{const je=await iwe(ae),Ee=await q.mutateAsync({filename:ae.name,mimeType:ae.type,dataBase64:je});g(de=>de.map(me=>me.id===le?{...me,uploadedId:Ee.id}:me))}catch{g(je=>je.filter(Ee=>Ee.id!==le))}}},[q]);y.useEffect(()=>{function se(ae){if(!document.activeElement?.closest("[data-message-input]"))return;const le=Array.from(ae.clipboardData?.files??[]);le.length>0&&(ae.preventDefault(),U(le))}return window.addEventListener("paste",se),()=>window.removeEventListener("paste",se)},[U]);function W(se){se.preventDefault(),_(!0)}function O(se){se.currentTarget.contains(se.relatedTarget)||_(!1)}function D(se){se.preventDefault(),_(!1);const ae=Array.from(se.dataTransfer.files);ae.length>0&&U(ae)}function Q(se){if(T&&$.length>0){if(se.key==="ArrowDown"){se.preventDefault(),C(ae=>(ae+1)%$.length);return}if(se.key==="ArrowUp"){se.preventDefault(),C(ae=>(ae-1+$.length)%$.length);return}if(se.key==="Enter"||se.key==="Tab"){se.preventDefault();const ae=$[S];ae&&Y(ae.name);return}if(se.key==="Escape"){se.preventDefault(),F(!1);return}}se.key==="Enter"&&!se.shiftKey&&(se.preventDefault(),J())}function z(se){const ae=se.target.value;d(ae),B(ae,se.target.selectionStart??ae.length)}function J(){const se=c.trim(),ae=m.filter(ge=>ge.uploadedId!==void 0).map(ge=>ge.uploadedId);!se&&ae.length===0||a||m.some(ge=>ge.uploadedId===void 0)||(i?.(se||".",ae.length>0?ae:void 0),d(""),g([]),A(null),k(-1),F(!1),M.current&&(M.current.style.height="auto"))}const ee=o??(n?`Message ${n.name}... (/ for commands)`:`Message #${t}... (/ for commands)`),re=m.some(se=>se.uploadedId===void 0),oe=(c.trim()||m.length>0)&&!a&&!re&&!H;return r.jsxs("div",{className:"px-4 pb-4 pt-2 flex-shrink-0 relative","data-message-input":!0,onDragOver:W,onDragLeave:O,onDrop:D,children:[r.jsx(Me,{children:b&&r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 z-20 mx-4 mb-4 mt-2 rounded-xl flex items-center justify-center border-2 border-dashed",style:{backgroundColor:`${R??"#6366F1"}10`,borderColor:R??"#6366F1"},children:r.jsx("p",{className:"text-[14px] font-medium",style:{color:R??"#6366F1"},children:"Drop to attach"})})}),m.length>0&&r.jsx("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:r.jsx(Me,{children:m.map(se=>r.jsx(rwe,{staged:se,onRemove:()=>{se.preview&&URL.revokeObjectURL(se.preview),g(ae=>ae.filter(le=>le.id!==se.id))}},se.id))})}),r.jsxs("div",{className:"relative",children:[r.jsx(Me,{children:T&&r.jsx(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:4},transition:{duration:.12},className:"absolute bottom-full mb-1 left-0 w-[220px] bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 z-30 max-h-[180px] overflow-y-auto",children:$.map((se,ae)=>r.jsxs("button",{onMouseDown:le=>{le.preventDefault(),Y(se.name)},className:ye("flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors",ae===S?"bg-white/8":"hover:bg-white/5"),children:[se.type==="human"?r.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] font-semibold flex-shrink-0 bg-gradient-to-br from-[#4A4A5E] to-[#2A2A3E] text-[#A5A5C5] border border-[#3A3A4E]",children:se.name[0]}):r.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[11px] flex-shrink-0",style:{backgroundColor:`${se.color}26`},children:se.emoji}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5] truncate",children:se.name})]},se.id))})}),r.jsxs("div",{className:"flex items-end gap-2 bg-[#1C1C21] border rounded-xl px-3 py-2.5 transition-colors duration-150",style:{borderColor:f&&R?`${R}60`:"#2A2A35",boxShadow:f&&R?`0 0 0 1px ${R}30`:void 0},children:[r.jsx(bt,{label:"Commands",children:r.jsx("button",{className:"text-[#8A8A99] hover:text-[#F0F0F5] transition-colors mb-0.5 flex-shrink-0",onClick:()=>{},children:r.jsx(Nre,{className:"w-4 h-4"})})}),r.jsx("textarea",{ref:M,value:c,onChange:z,onKeyDown:Q,onFocus:()=>p(!0),onBlur:()=>p(!1),placeholder:ee,disabled:a||H,rows:1,className:"flex-1 bg-transparent text-[14px] text-[#F0F0F5] placeholder:text-[#8A8A99]/60 resize-none outline-none leading-relaxed max-h-[120px] overflow-y-auto disabled:opacity-50",style:{minHeight:"22px"},onInput:se=>{const ae=se.currentTarget;ae.style.height="auto",ae.style.height=`${Math.min(ae.scrollHeight,120)}px`}}),r.jsx("input",{ref:I,type:"file",multiple:!0,accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.xls,.xlsx,.txt,.csv,.zip,.json",tabIndex:-1,style:{position:"absolute",width:1,height:1,opacity:0,pointerEvents:"none",overflow:"hidden"},onChange:se=>{const ae=Array.from(se.target.files??[]);ae.length>0&&U(ae),se.target.value=""}}),r.jsx(bt,{label:"Attach file",children:r.jsx("button",{type:"button",onClick:()=>I.current?.click(),className:ye("transition-colors mb-0.5 flex-shrink-0",m.length>0?"text-[#6366F1]":"text-[#8A8A99] hover:text-[#F0F0F5]"),children:r.jsx(sre,{className:"w-4 h-4"})})}),V&&H?r.jsx(bt,{label:"Stop",children:r.jsx("button",{onClick:()=>n&&K.mutate({agentId:n.id,channelId:e}),className:"transition-colors mb-0.5 flex-shrink-0 text-[#F0F0F5] hover:text-[#EF4444]",children:r.jsx(L5,{className:"w-4 h-4 fill-current"})})}):r.jsx("button",{onClick:J,disabled:!oe,className:"text-[#8A8A99] hover:text-[#F0F0F5] disabled:opacity-30 transition-colors mb-0.5 flex-shrink-0",children:r.jsx(Ji,{className:"w-4 h-4"})})]})]}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]/40 mt-1.5 px-1",children:["Enter to send · Shift+Enter for newline",l.length>0?" · @ to mention":"",m.length>0?` · ${m.length} file${m.length>1?"s":""}`:""]})]})}function W7(e){const{setMessages:t,hasChannel:n,messagesByChannel:s,prependMessages:i}=Je(),a=!n(e),o=L.useUtils(),l=L.messages.list.useQuery({channelId:e,limit:50},{enabled:!!e&&a});y.useEffect(()=>{l.data&&a&&t(e,l.data.messages)},[l.data,e,a,t]);const c=s[e]??l.data?.messages??[],d=c[0]?.id,f=y.useCallback(async()=>{if(!d)return!1;const p=await o.messages.list.fetch({channelId:e,cursor:d,limit:50,direction:"before"});return p.messages.length>0&&i(e,p.messages),p.hasMore},[e,d,i,o]);return{data:c,isLoading:a&&l.isLoading,loadMore:f}}function q7(){const e=Je(n=>n.appendMessage);return L.messages.send.useMutation({onSuccess:n=>{e(n)}})}function awe({channelId:e}){const[t,n]=y.useState(!1),s=L.messages.resetSession.useMutation({onSuccess:()=>{n(!0),setTimeout(()=>n(!1),2e3)}});return r.jsx(bt,{label:"Reset context",children:r.jsx("button",{onClick:()=>s.mutate({channelId:e}),className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",style:t?{color:"#10B981"}:{},children:r.jsx(lh,{className:`w-3.5 h-3.5 ${s.isPending?"animate-spin":""}`})})})}function owe({channel:e}){const t=L.channels.setResponseMode.useMutation(),n=L.useUtils();return r.jsx(bt,{label:e.responseMode==="mention"?"Agents respond only when @mentioned":"Agents respond to every message",children:r.jsxs("button",{onClick:()=>{const s=e.responseMode==="always"?"mention":"always";t.mutate({channelId:e.id,responseMode:s},{onSuccess:()=>n.channels.list.invalidate()})},className:ye("flex items-center gap-1 px-2 py-1 rounded-md text-[12px] border transition-colors",e.responseMode==="mention"?"text-[#A78BFA] bg-[#8B5CF6]/10 border-[#8B5CF6]/30":"text-[#8A8A99] border-transparent hover:border-[#2A2A35] hover:bg-white/5"),children:[e.responseMode==="mention"?r.jsx(eL,{className:"w-3.5 h-3.5"}):r.jsx(pL,{className:"w-3.5 h-3.5"}),r.jsx("span",{children:e.responseMode==="mention"?"mention":"auto"})]})})}function lwe({channel:e,agents:t}){const n=e.participants.filter(i=>i.participantType==="agent").map(i=>t.find(a=>a.id===i.participantId)).filter(i=>!!i),s=n.map(i=>i.name).join(" and ");return r.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[#2A2A35] bg-[#0F0F11] flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex -space-x-2",children:n.map(i=>r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-base border-2 border-[#0F0F11]",style:{backgroundColor:`${i.color}30`},children:i.emoji},i.id))}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:e.name}),e.isActive?r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[s," are talking"]}):r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"Ready — send a message to continue"})]})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(owe,{channel:e}),r.jsx(S$,{channel:e}),r.jsx(awe,{channelId:e.id})]})]})}function mR(e,t){let n=e;for(const s of t){const i=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(`@(${i})\\b`,"gi");n=n.replace(a,"**@$1**")}return n}const xR={strong:({children:e,...t})=>{const n=typeof e=="string"?e:Array.isArray(e)?e.join(""):"";return typeof n=="string"&&n.startsWith("@")?r.jsx("span",{className:"text-blue-400 font-medium",...t,children:n}):r.jsx("strong",{...t,children:e})}};function cwe({message:e,agents:t,mentionNames:n}){if(e.sender.type==="context_reset")return r.jsxs("div",{className:"flex items-center gap-3 py-2 px-4",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"new context"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]});if(e.sender.type==="human")return r.jsx("div",{className:"flex flex-col items-center py-2 px-4",children:r.jsxs("div",{className:"max-w-[480px] w-full",children:[r.jsxs("div",{className:"flex items-center justify-center gap-2 mb-1",children:[r.jsx("div",{className:"h-px flex-1 bg-[#2A2A35]"}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] shrink-0",children:"You"}),r.jsx("div",{className:"h-px flex-1 bg-[#2A2A35]"})]}),r.jsx("div",{className:"bg-white/[0.03] border border-[#2A2A35] rounded-xl px-4 py-2.5 text-[14px] text-[#C8C8D4]",children:r.jsx(Ei,{remarkPlugins:[Fi],components:xR,children:mR(e.content,n)})})]})});const i=t.find(l=>l.id===e.sender.id),a=i?.color??e.sender.agentColor??"#8A8A99",o=i?.emoji??"🤖";return r.jsxs("div",{className:"flex items-start gap-3 px-4 py-2",children:[r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-base flex-shrink-0 mt-0.5",style:{backgroundColor:`${a}26`},children:o}),r.jsxs("div",{className:"flex-1 min-w-0 max-w-[70%]",children:[r.jsx("span",{className:"text-[12px] font-semibold block mb-1",style:{color:a},children:e.sender.name}),r.jsx("div",{className:"bg-[#1C1C28] border border-[#2A2A35] rounded-xl rounded-tl-sm px-4 py-2.5 text-[14px] text-[#C8C8D4] leading-relaxed prose prose-invert prose-sm max-w-none",children:r.jsx(Ei,{remarkPlugins:[Fi],components:xR,children:mR(e.content,n)})})]})]})}function uwe({entries:e,open:t,onToggle:n}){const s=y.useRef(null);return y.useEffect(()=>{t&&s.current&&(s.current.scrollTop=s.current.scrollHeight)},[t,e.length]),r.jsxs("div",{className:"flex-shrink-0 border-t border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-2",children:[r.jsxs("button",{onClick:n,className:"flex items-center gap-1.5 text-[11px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:[r.jsx(Ti,{className:"w-3 h-3"}),r.jsx("span",{children:"System log"}),e.length>0&&r.jsx("span",{className:"text-[10px] bg-[#2A2A35] px-1.5 py-0.5 rounded-full",children:e.length})]}),r.jsx(ne.div,{animate:{rotate:t?0:-90},transition:{duration:.15},children:r.jsx("button",{onClick:n,className:"text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:r.jsx(ft,{className:"w-3.5 h-3.5"})})})]}),r.jsx(Me,{children:t&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:160,opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:"easeOut"},className:"overflow-hidden",children:r.jsx("div",{ref:s,className:"h-[160px] overflow-y-auto px-4 pb-3 font-mono text-[11px] leading-5 text-[#5A5A6E] scrollbar-agent",children:e.length===0?r.jsx("p",{className:"italic text-[#3A3A4E] mt-1",children:"No events yet."}):e.map(i=>r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-[#3A3A4E] flex-shrink-0 tabular-nums",children:new Date(i.ts).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}),r.jsx("span",{className:"text-[#6A6A7E]",children:i.text})]},i.id))})})})]})}function dwe({channel:e,agents:t}){const{data:n,isLoading:s,loadMore:i}=W7(e.id),a=Je(O=>O.agentStatuses),o=L.readReceipts.markRead.useMutation(),l=Je(O=>O.setUnreadCount),{mutate:c,isPending:d}=q7(),{data:f}=Mi(),{data:p=[]}=L.workspace.listMembers.useQuery(),m=y.useRef(null),g=y.useRef(null),[b,_]=y.useState(!1),[w,A]=y.useState(!0),S=y.useRef(0),[C,E]=y.useState([]),[k,T]=y.useState(!1),F=y.useRef(0),M=y.useRef({}),I=y.useRef(e.isActive),R=y.useRef({}),H=y.useMemo(()=>[...t.map(O=>O.name),...p.map(O=>O.name)],[t,p]),V=e.participants.filter(O=>O.participantType==="agent").map(O=>t.find(D=>D.id===O.participantId)).filter(O=>!!O),K=y.useCallback(O=>{const D=++F.current;E(Q=>[...Q,{id:D,text:O,ts:Date.now()}])},[]),[q,$]=y.useState(e.id);e.id!==q&&($(e.id),E([]),M.current={},I.current=e.isActive,R.current={},F.current=0),y.useEffect(()=>{const O=V.map(D=>D.id);for(const D of O){const Q=M.current[D],z=a[D];if(!z||z===Q)continue;const ee=V.find(re=>re.id===D)?.name??D;if(z==="thinking"||z==="executing"){const re=R.current;re[D]=(re[D]??0)+1;const oe=re[D];K(`Turn ${oe}: [${ee}] thinking...`)}else z==="idle"&&(Q==="thinking"||Q==="executing")&&K(`[${ee}] responded`);M.current[D]=z}},[a,V,K]),y.useEffect(()=>{const O=I.current,D=!e.isActive;if(O&&D){const Q=n.filter(J=>J.sender.type==="agent");Q[Q.length-1]?.content?.trimEnd().includes("##DONE##")?K("Conversation closed — ##DONE## signaled"):e.maxTurns!=null?K(`Ceiling reached (${e.maxTurns} turns)`):K("Conversation closed")}I.current=e.isActive},[e.isActive,e.maxTurns,n,K]),y.useEffect(()=>{m.current?.scrollIntoView({behavior:"instant"})},[e.id]);const B=n.length>0?n[n.length-1]?.id:null;y.useEffect(()=>{m.current?.scrollIntoView({behavior:"smooth"})},[B]),y.useEffect(()=>{n.length!==0&&(o.mutate({channelId:e.id}),l(e.id,0))},[e.id,n.length]);const Y=y.useCallback(async()=>{const O=g.current;if(!(!O||!i||b||!w)&&O.scrollTop<100){_(!0),S.current=O.scrollHeight;const D=await i();A(D??!1),_(!1),requestAnimationFrame(()=>{const Q=O.scrollHeight;O.scrollTop=Q-S.current})}},[i,b,w]),U=V.filter(O=>{const D=a[O.id]??O.status;return D==="thinking"||D==="executing"}),W=y.useCallback((O,D)=>{c({channelId:e.id,content:O,attachmentIds:D})},[e.id,c]);return s?r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsxs("div",{className:"flex items-center gap-2 text-[#8A8A99]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.4s]"})]})}):r.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden min-h-0",children:[r.jsx(lwe,{channel:e,agents:t}),r.jsxs("div",{ref:g,onScroll:Y,className:"flex-1 overflow-y-auto py-2 scrollbar-agent",children:[b&&r.jsx("div",{className:"flex justify-center py-3",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99]",children:[r.jsx("div",{className:"w-1 h-1 rounded-full bg-[#8A8A99] animate-pulse"}),r.jsx("div",{className:"w-1 h-1 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.15s]"}),r.jsx("div",{className:"w-1 h-1 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.3s]"})]})}),r.jsx(Me,{initial:!1,children:n.map(O=>r.jsx(ne.div,{id:`msg-${O.id}`,initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.2},children:r.jsx(cwe,{message:O,agents:t,mentionNames:H})},O.id))}),U.map(O=>r.jsx(U7,{agent:O},`thinking-${O.id}`)),r.jsx("div",{ref:m,className:"h-4"})]}),r.jsx(uwe,{entries:C,open:k,onToggle:()=>T(O=>!O)}),r.jsx(H7,{channelName:e.name,onSend:W,disabled:d,placeholder:e.isActive?"Message the conversation...":"Start a new topic...",mentionableParticipants:[...e.participants.filter(O=>O.participantType==="agent").map(O=>t.find(D=>D.id===O.participantId)).filter(O=>!!O).map(O=>({id:O.id,name:O.name,emoji:O.emoji,color:O.color,type:"agent"})),...e.participants.filter(O=>O.participantType==="human"&&O.participantId!==f?.user?.id).map(O=>{const D=p.find(Q=>Q.userId===O.participantId);return D?{id:D.userId,name:D.name,emoji:null,color:"#6366F1",type:"human"}:null}).filter(O=>!!O)]})]})}const hwe=[{id:"axiom",name:"Axiom",emoji:"⚡",role:"Chief of Staff",color:"#6366F1",status:"executing",soulExcerpt:"I operate at the intersection of strategy and execution. I don't just advise — I move. Every decision I surface comes with a recommended path forward, already stress-tested against your goals.",model:"claude-opus-4-5",defaultModel:"claude-opus-4-5",modelRules:null,customModels:null,fallbackModel:null,gatewayId:null,activeSince:"2024-01-15T09:00:00Z",lastAction:new Date(Date.now()-1e3*60*3).toISOString(),soul:`# Axiom — Chief of Staff
133
133
 
134
134
  I operate at the intersection of strategy and execution. I don't just advise — I move. Every decision I surface comes with a recommended path forward, already stress-tested against your goals.
@@ -424,7 +424,7 @@ Any required environment variables or binaries.
424
424
  requires_approval: false
425
425
  auth:
426
426
  type: bearer
427
- value: \${EXAMPLE_API_KEY}`}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-2 leading-relaxed",children:["Auth types: ",r.jsx("code",{className:"text-[#8A8A99]",children:"bearer"}),", ",r.jsx("code",{className:"text-[#8A8A99]",children:"header"})," (add ",r.jsx("code",{className:"text-[#8A8A99]",children:"header: X-Name"}),"), ",r.jsx("code",{className:"text-[#8A8A99]",children:"query"})," (add ",r.jsx("code",{className:"text-[#8A8A99]",children:"query: api_key"}),"). Set ",r.jsx("code",{className:"text-[#8A8A99]",children:"requires_approval: true"})," for destructive calls."]})]})})]})}function CRe({onClose:e,onSuccess:t}){const[n,s]=y.useState("pick"),[i,a]=y.useState(null),[o,l]=y.useState(null),[c,d]=y.useState(null),f=y.useRef(null),p=L.skillPackImport.preview.useMutation(),m=L.skillPackImport.confirm.useMutation(),g=y.useCallback(async _=>{if(!_.name.endsWith(".damnpack")){l("Please select a .damnpack file"),s("error");return}if(_.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const w=new FormData;w.append("file",_);const A=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:w,credentials:"include"});if(!A.ok){const E=await A.json().catch(()=>({error:"Upload failed"}));throw new Error(E.error||`Upload failed (${A.status})`)}const{uploadId:S}=await A.json(),C=await p.mutateAsync({uploadId:S});a(C),s("preview")}catch(w){l(w instanceof Error?w.message:"Upload failed"),s("error")}},[p]);async function b(){if(i){s("confirming");try{const _=await m.mutateAsync({previewId:i.previewId});d(_),s("done")}catch(_){l(_ instanceof Error?_.message:"Install failed"),s("error")}}}return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:e,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},onClick:_=>_.stopPropagation(),className:"relative w-full max-w-md bg-[#16161A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:n==="done"?"Skills installed":"Import skill pack"}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"p-5",children:[n==="pick"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("button",{onClick:()=>f.current?.click(),className:"w-full py-10 rounded-xl border-2 border-dashed border-[#2A2A35] hover:border-[#6366F1]/50 transition-colors flex flex-col items-center gap-3 group",children:[r.jsx(su,{className:"w-8 h-8 text-[#5A5A6E] group-hover:text-[#6366F1] transition-colors"}),r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-medium",children:"Choose .damnpack skill pack"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Max 100MB"})]})]}),r.jsx("input",{ref:f,type:"file",accept:".damnpack",className:"hidden",onChange:_=>{const w=_.target.files?.[0];w&&g(w)}})]}),(n==="uploading"||n==="confirming")&&r.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[r.jsx(Pe,{className:"w-8 h-8 text-[#6366F1] animate-spin"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:n==="uploading"?"Scanning skill pack...":"Installing skills..."})]}),n==="error"&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-4 py-3",children:r.jsx("p",{className:"text-[13px] text-[#FCA5A5]",children:o})}),r.jsx("button",{onClick:()=>{s("pick"),l(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),n==="preview"&&i&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#6366F1]/15 border border-[#6366F1]/25 flex items-center justify-center",children:r.jsx(vv,{className:"w-5 h-5 text-[#818CF8]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.version," by"," ",i.publisherUrl?r.jsxs("a",{href:i.publisherUrl,target:"_blank",rel:"noopener noreferrer",className:"text-[#818CF8] hover:underline inline-flex items-center gap-0.5",children:[i.publisher,r.jsx(cs,{className:"w-2.5 h-2.5"})]}):i.publisher]})]})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.summary}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:[i.skills.length," skill",i.skills.length!==1?"s":""]}),r.jsx("div",{className:"space-y-2",children:i.skills.map(_=>r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] px-3 py-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-0.5",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:_.name}),r.jsxs("div",{className:"flex items-center gap-2",children:[_.toolCount>0&&r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:[_.toolCount," tool",_.toolCount!==1?"s":""]}),_.exists&&r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20",children:"Update"})]})]}),r.jsx("p",{className:"text-[11px] text-[#6A6A7A] line-clamp-2",children:_.description})]},_.slug))})]}),i.missingSecrets.length>0&&(()=>{const _=i.missingSecrets.filter(A=>!A.default),w=i.missingSecrets.filter(A=>!!A.default);return r.jsxs("div",{className:"space-y-2",children:[w.length>0&&r.jsxs("div",{className:"rounded-lg bg-emerald-500/10 border border-emerald-500/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-emerald-400 flex items-center gap-1.5",children:[r.jsx(Fe,{className:"w-3.5 h-3.5"}),"Auto-configured"]}),r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:w.map(A=>r.jsx("code",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono text-emerald-400 bg-emerald-500/15 border border-emerald-500/20",children:A.key},A.key))})]}),_.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1.5",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(Eo,{className:"w-3.5 h-3.5"}),"Required workspace secrets"]}),r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80",children:"You'll need to add these in Settings after installing:"}),r.jsx("div",{className:"space-y-1 mt-1.5",children:_.map(A=>r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("code",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono text-[#FCD34D] bg-[#F59E0B]/15 border border-[#F59E0B]/20 flex-shrink-0",children:A.key}),r.jsx("span",{className:"text-[10px] text-[#FCD34D]/60 leading-tight",children:A.description})]},A.key))})]})]})})(),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsx("button",{onClick:b,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Install All"}),r.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),n==="done"&&c&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-emerald-500/15 border border-emerald-500/25 flex items-center justify-center",children:r.jsx(Fe,{className:"w-5 h-5 text-emerald-400"})}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:[c.total," skill",c.total!==1?"s":""," installed"]}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c.installed.length>0&&`${c.installed.length} new`,c.installed.length>0&&c.updated.length>0&&", ",c.updated.length>0&&`${c.updated.length} updated`]})]})]}),c.autoPopulated.length>0&&r.jsx("div",{className:"rounded-lg bg-emerald-500/10 border border-emerald-500/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-emerald-400",children:["Auto-configured: ",c.autoPopulated.join(", ")]})}),i&&i.missingSecrets.some(_=>!_.default)&&r.jsxs(gn,{to:"/settings?tab=secrets",className:"flex items-center justify-center gap-1.5 w-full py-2 rounded-lg text-[12px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] hover:bg-[#F59E0B]/20 border border-[#F59E0B]/30 transition-colors",children:[r.jsx(Eo,{className:"w-3.5 h-3.5"}),"Add missing secrets in Settings"]}),r.jsx("button",{onClick:()=>{t(),e()},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}const jRe={secretsoss:"#6366F1",lifelog:"#10B981",chut:"#F59E0B",custom:"#6B7280",clawhub:"#8B5CF6"};function NRe(e){return jRe[e]??"#6B7280"}function yW({provider:e}){const t=NRe(e),n=e==="secretsoss"?"SecretSoss":e==="lifelog"?"Lifelog":e==="chut"?"Chut.co":e;return r.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-md text-[11px] font-medium",style:{backgroundColor:`${t}20`,color:t,border:`1px solid ${t}40`},children:n})}function nO({onConfirm:e,onRemove:t}){const[n,s]=y.useState(!1);return r.jsxs(Ys,{open:n,onOpenChange:s,children:[r.jsx(ci,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-white/5 text-[#8A8A99] hover:bg-red-500/10 hover:text-red-400 border border-[#2A2A35] hover:border-red-500/30 transition-colors",children:"Uninstall"})}),r.jsx(Qs,{children:r.jsxs(Xs,{side:"top",align:"end",sideOffset:6,className:ye("z-50 bg-[#1C1C24] border border-[#2A2A35] rounded-xl p-4 shadow-2xl",t?"w-64":"w-56"),children:[r.jsx("p",{className:"text-[12px] text-[#C8C8D4] mb-3 leading-relaxed",children:t?"Uninstall from agents, or remove entirely?":"This will remove the skill from all agents. Continue?"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>s(!1),className:"flex-1 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"}),r.jsx("button",{onClick:()=>{e(),s(!1)},className:"flex-1 py-1.5 rounded-lg text-[12px] text-amber-400 hover:text-amber-300 bg-amber-500/10 hover:bg-amber-500/20 border border-amber-500/30 transition-colors",children:"Uninstall"}),t&&r.jsxs("button",{onClick:()=>{t(),s(!1)},className:"py-1.5 px-2.5 rounded-lg text-[12px] text-red-400 hover:text-red-300 bg-red-500/10 hover:bg-red-500/20 border border-red-500/30 transition-colors flex items-center gap-1",children:[r.jsx(Dn,{className:"w-3 h-3"}),"Remove"]})]}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]})}function kRe({skill:e,isInstalled:t,onInstall:n,onUninstall:s,onRemove:i,onEdit:a,onDelete:o,onClick:l,selected:c,canManage:d=!0}){return r.jsxs(ne.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},onClick:l,className:ye("bg-[#16161A] border rounded-2xl p-5 cursor-pointer transition-colors relative overflow-hidden",c?"border-[#6366F1]/50 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] hover:border-[#3A3A45]"),children:[r.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx(yW,{provider:e.source==="custom"||e.source==="authored"?"custom":e.provider}),e.requiresApproval&&r.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/30",children:[r.jsx(_m,{className:"w-3 h-3"}),"Approval required"]})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[d&&(e.source==="custom"||e.source==="authored")&&a&&r.jsx("button",{onClick:f=>{f.stopPropagation(),a()},className:"w-6 h-6 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(O5,{className:"w-3 h-3"})}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:["v",e.version]})]})]}),r.jsx("h3",{className:"text-[14px] font-semibold text-[#F0F0F5] mb-1",children:e.name}),r.jsx("p",{className:"text-[12px] text-[#6A6A7A] leading-relaxed line-clamp-2 mb-4",children:e.description}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:t?"Installed":"Not installed"}),d&&r.jsxs("div",{className:"flex items-center gap-2",onClick:f=>f.stopPropagation(),children:[(e.source==="custom"||e.source==="authored")&&o&&r.jsx(nO,{onConfirm:o}),t?e.source!=="custom"&&r.jsx(nO,{onConfirm:s,onRemove:i}):r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:n,className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 border border-[#6366F1]/30 transition-colors",children:"Install"}),i&&r.jsx("button",{onClick:i,className:"w-7 h-7 flex items-center justify-center rounded-lg text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 border border-[#2A2A35] hover:border-red-500/30 transition-colors",children:r.jsx(Dn,{className:"w-3 h-3"})})]})]})]})]})}function ERe({agent:e,skillId:t,agentSkill:n}){const s=L.useUtils(),i=L.skills.toggleAgentSkill.useMutation({onSuccess:()=>{s.skills.getAgentSkills.invalidate()}});return r.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-base flex-shrink-0",style:{backgroundColor:`${e.color}26`},children:e.emoji}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:e.name}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:e.role})]})]}),r.jsx(Sh,{checked:n?.enabled??!1,onCheckedChange:a=>i.mutate({agentId:e.id,skillId:t,enabled:a}),className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35] disabled:opacity-40 disabled:cursor-not-allowed",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]})}function FRe(e,t){const n=e.map(s=>L.skills.getAgentSkills.useQuery({agentId:s.id}));return e.map((s,i)=>({agent:s,agentSkill:n[i].data?.find(a=>a.skillId===t)}))}function TRe({varName:e}){const t=L.useUtils(),{data:n=[]}=L.settings.getEnvVars.useQuery(),{data:s=[]}=L.secrets.listKeys.useQuery(),{data:i=[]}=L.settings.getKnownKeys.useQuery(),a=i.find(k=>k.key===e)?.kind,o=a===void 0||a==="secret",l=L.settings.setEnvVar.useMutation({onSuccess:()=>{t.settings.getEnvVars.invalidate()}}),c=L.settings.deleteEnvVar.useMutation({onSuccess:()=>{t.settings.getEnvVars.invalidate()}}),d=L.secrets.set.useMutation({onSuccess:()=>{t.secrets.listKeys.invalidate(),t.secrets.list.invalidate()}}),f=n.find(k=>k.key===e),p=s.includes(e),m=!!f||p,[g,b]=y.useState(!1),[_,w]=y.useState(""),[A,S]=y.useState(!1);function C(){const k=_.trim();k&&(o?(d.mutate({key:e,value:k}),f&&c.mutate({key:e})):l.mutate({key:e,value:k}),b(!1),w(""))}const E=l.isPending||d.isPending;return r.jsxs("div",{className:"py-3 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("span",{className:"text-[12px] font-mono text-[#C8C8D4]",children:e}),m?r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[#10B981]",children:[r.jsx(Fe,{className:"w-3 h-3"}),"Configured"]}):r.jsx("span",{className:"text-[11px] text-[#F87171]",children:"Missing"})]}),g?r.jsxs("div",{className:"flex gap-2 mt-2",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx("input",{type:A?"text":"password",value:_,onChange:k=>w(k.target.value),onKeyDown:k=>{k.key==="Enter"&&C()},placeholder:`Enter ${e}...`,autoFocus:!0,className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-1.5 pr-8 text-[12px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors font-mono"}),r.jsx("button",{onClick:()=>S(!A),className:"absolute right-2 top-1/2 -translate-y-1/2 text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:A?r.jsx(R5,{className:"w-3.5 h-3.5"}):r.jsx(xv,{className:"w-3.5 h-3.5"})})]}),r.jsx("button",{onClick:C,disabled:!_.trim()||E,className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 border border-[#6366F1]/30 transition-colors disabled:opacity-40",children:"Save"}),r.jsx("button",{onClick:()=>{b(!1),w("")},className:"px-2 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}):r.jsx("button",{onClick:()=>b(!0),className:"text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors mt-1",children:m?"Update":"Set value"})]})}function MRe({skill:e,agents:t,onClose:n}){const[s,i]=y.useState("info"),a=L.useUtils(),o=FRe(t,e.id),l=L.skills.toggleAgentSkill.useMutation({onMutate:async({agentId:m,skillId:g,enabled:b})=>{await a.skills.getAgentSkills.cancel({agentId:m});const _=a.skills.getAgentSkills.getData({agentId:m});return a.skills.getAgentSkills.setData({agentId:m},w=>w?.map(A=>A.agentId===m&&A.skillId===g?{...A,enabled:b}:A)),{prev:_}},onError:(m,{agentId:g},b)=>{b?.prev&&a.skills.getAgentSkills.setData({agentId:g},b.prev)}}),{data:c=[]}=L.skills.getSkillEnvVars.useQuery({skillId:e.id}),{data:d}=L.skills.getSkillContent.useQuery({skillId:e.id}),f=o.length>0&&o.every(m=>m.agentSkill?.enabled);function p(){const m=!f;o.forEach(({agent:g})=>{l.mutate({agentId:g.id,skillId:e.id,enabled:m})})}return r.jsxs(r.Fragment,{children:[r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-40",style:{backdropFilter:"blur(2px)",backgroundColor:"rgba(0,0,0,0.25)"},onClick:n}),r.jsxs(ne.div,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.3,ease:[.16,1,.3,1]},className:"fixed right-0 top-0 h-screen w-[380px] bg-[#13131A] border-l border-[#2A2A35] flex flex-col z-50 shadow-2xl",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{children:[r.jsx("div",{className:"mb-0.5",children:r.jsx(yW,{provider:e.provider})}),r.jsx("p",{className:"text-[15px] font-semibold text-[#F0F0F5] mt-1",children:e.name})]}),r.jsx("button",{onClick:n,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex border-b border-[#2A2A35] flex-shrink-0",children:[r.jsx("button",{onClick:()=>i("info"),className:ye("flex-1 py-2.5 text-[12px] font-medium transition-colors border-b-2 -mb-px",s==="info"?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:"Info"}),r.jsx("button",{onClick:()=>i("agents"),className:ye("flex-1 py-2.5 text-[12px] font-medium transition-colors border-b-2 -mb-px",s==="agents"?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:"Agents"}),r.jsxs("button",{onClick:()=>i("keys"),className:ye("flex-1 py-2.5 text-[12px] font-medium transition-colors border-b-2 -mb-px",s==="keys"?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:["Secrets",c.length>0?` (${c.length})`:""]})]}),e.requiresApproval&&s==="agents"&&r.jsxs("div",{className:"mx-5 mt-4 px-3 py-2.5 rounded-lg bg-amber-500/[0.08] border border-amber-500/20 flex items-start gap-2",children:[r.jsx(_m,{className:"w-3.5 h-3.5 text-amber-400 flex-shrink-0 mt-0.5"}),r.jsx("p",{className:"text-[12px] text-amber-300/80 leading-relaxed",children:"Agent will ask for your approval before executing this skill."})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[s==="info"&&r.jsxs("div",{className:"space-y-5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Description"}),r.jsx("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:e.description})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Version"}),r.jsxs("p",{className:"text-[13px] text-[#F0F0F5] font-mono",children:["v",e.version]})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Source"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5] capitalize",children:e.source})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Provider"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:e.provider})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Endpoint"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-mono truncate",title:e.endpoint,children:e.endpoint||"—"})]})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Slug"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-mono",children:e.slug})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Installed"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:new Date(e.installedAt).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})})]}),d?.content&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"SKILL.md"}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] font-mono whitespace-pre-wrap leading-relaxed bg-[#0F0F11] border border-[#2A2A35] rounded-lg p-3 max-h-[300px] overflow-y-auto",children:d.content})]})]}),s==="agents"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Agent access"}),o.length>0&&r.jsx("button",{onClick:p,className:"text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:f?"Disable all":"Enable all"})]}),t.length===0&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No agents found."}),o.map(({agent:m,agentSkill:g})=>r.jsx(ERe,{agent:m,skillId:e.id,agentSkill:g},m.id))]}),s==="keys"&&r.jsx(r.Fragment,{children:c.length===0?r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"This skill has no required secrets."}):c.map(m=>r.jsx(TRe,{varName:m},m))})]})]})]})}function RRe(e){const t=e.map(s=>L.skills.getAgentSkills.useQuery({agentId:s.id}));return new Set(t.flatMap(s=>(s.data??[]).map(i=>i.skillId)))}function DRe({skills:e,agents:t,selectedSkillId:n,onInstall:s,onUninstall:i,onRemove:a,onSelect:o,onEditCustom:l,onDeleteCustom:c,canManage:d=!0}){const f=RRe(t);return r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:e.map(p=>r.jsx(kRe,{skill:p,isInstalled:f.has(p.id),onInstall:()=>s(p.id),onUninstall:()=>i(p.id),onRemove:p.source!=="custom"&&p.source!=="authored"?()=>a(p.id):void 0,onEdit:p.source==="custom"||p.source==="authored"?()=>l(p):void 0,onDelete:p.source==="custom"||p.source==="authored"?()=>c(p.id):void 0,onClick:()=>o(n===p.id?null:p),selected:n===p.id,canManage:d},p.id))})}function ORe({result:e,onClose:t,onInstall:n,inspectData:s}){const{data:i,isLoading:a,isError:o}=L.skills.getClawHubSkillContent.useQuery({slug:e.slug},{staleTime:1/0}),l=i?.content?.includes("shell://")||i?.content?.includes("shell_exec")||i?.content?.includes("exec:"),[c,d]=y.useState(!1),f=!a&&!o&&(!l||c);return r.jsx(ji,{open:!0,onOpenChange:p=>{p||t()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-40"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[640px] max-h-[80vh] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl z-50 flex flex-col",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[r.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-md text-[11px] font-medium",style:{backgroundColor:"#8B5CF620",color:"#8B5CF6",border:"1px solid #8B5CF640"},children:e.publisher||"Unknown publisher"}),i?.hasSecurityWarning&&r.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/30",children:[r.jsx(_m,{className:"w-3 h-3"}),"Network activity detected"]})]}),r.jsx(nr,{className:"text-[15px] font-semibold text-[#F0F0F5]",children:e.displayName}),r.jsxs("div",{className:"flex items-center gap-3 mt-1.5",children:[s?.downloads!=null&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[#5A5A6E]",children:[r.jsx(nu,{className:"w-3 h-3"}),s.downloads.toLocaleString()]}),s?.stars!=null&&s.stars>0&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[#5A5A6E]",children:[r.jsx(Ire,{className:"w-3 h-3"}),s.stars]}),e.version&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E]",children:["v",e.version]}),!s?.downloads&&!s?.stars&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E] italic",children:"Unknown — review SKILL.md before installing"})]})]}),r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 min-h-0",children:[a&&r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}),o&&r.jsx("p",{className:"text-[13px] text-red-400",children:"Could not load SKILL.md — check your internet connection."}),i&&r.jsx("pre",{className:"text-[12px] text-[#C8C8D4] font-mono whitespace-pre-wrap leading-relaxed",children:i.content})]}),l&&!c&&r.jsxs("div",{className:"mx-5 mb-3 p-3 rounded-lg bg-red-500/[0.08] border border-red-500/30 flex items-start gap-2.5",children:[r.jsx(Ti,{className:"w-4 h-4 text-red-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[12px] text-red-300 leading-relaxed mb-2",children:"This skill will execute commands on your machine. Only install if you trust the publisher."}),r.jsx("button",{onClick:()=>d(!0),className:"px-3 py-1 rounded-md text-[11px] font-medium bg-red-500/20 text-red-300 hover:bg-red-500/30 border border-red-500/30 transition-colors",children:"I understand the risks"})]})]}),r.jsxs("div",{className:"px-5 py-3 border-t border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Review the skill before installing."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-lg text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})}),r.jsxs("button",{onClick:n,disabled:!f,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-lg bg-[#8B5CF6] text-white text-[13px] font-medium hover:bg-[#7C3AED] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:[r.jsx(nu,{className:"w-3.5 h-3.5"}),"Install"]})]})]})]})]})})}function PRe({result:e,onReviewInstall:t}){return r.jsxs(ne.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 hover:border-[#3A3A45] transition-colors",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[r.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-md text-[11px] font-medium",style:{backgroundColor:"#8B5CF620",color:"#8B5CF6",border:"1px solid #8B5CF640"},children:e.publisher}),e.hasSecurityWarning&&r.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/30",children:[r.jsx(_m,{className:"w-2.5 h-2.5"}),"Network"]}),e.source==="github"&&r.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-white/5 text-[#5A5A6E] border border-[#2A2A35]",children:"archive"})]}),e.installed&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[#10B981] flex-shrink-0",children:[r.jsx(sa,{className:"w-3 h-3"}),"Installed"]})]}),r.jsx("h3",{className:"text-[14px] font-semibold text-[#F0F0F5] mb-1",children:e.displayName}),r.jsx("p",{className:"text-[12px] text-[#6A6A7A] leading-relaxed line-clamp-2 mb-4",children:e.summary||e.slug}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#5A5A6E] font-mono",children:e.slug}),e.installed?r.jsx("span",{className:"px-3 py-1.5 rounded-lg text-[12px] font-medium text-[#10B981] bg-[#10B981]/10 border border-[#10B981]/30",children:"Installed"}):r.jsxs("button",{onClick:()=>t(e),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#8B5CF6]/10 text-[#8B5CF6] hover:bg-[#8B5CF6]/20 border border-[#8B5CF6]/30 transition-colors",children:[r.jsx(cs,{className:"w-3 h-3"}),"Review & Install"]})]})]})}function IRe({requiredEnvVars:e,requiredBins:t,skillName:n,hasSecurityWarning:s,onClose:i}){return y.useEffect(()=>{const a=setTimeout(i,8e3);return()=>clearTimeout(a)},[i]),r.jsxs(ne.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},exit:{opacity:0,y:16},className:"fixed bottom-6 right-6 z-50 w-[380px] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl p-4",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(sa,{className:"w-4 h-4 text-[#10B981] flex-shrink-0"}),r.jsxs("span",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:[n," installed"]})]}),r.jsx("button",{onClick:i,className:"text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),e.length>0&&r.jsxs("div",{className:"mb-2 p-2.5 rounded-lg bg-amber-500/[0.08] border border-amber-500/20 flex items-start gap-2",children:[r.jsx(Rs,{className:"w-3.5 h-3.5 text-amber-400 flex-shrink-0 mt-0.5"}),r.jsx("div",{children:r.jsxs("p",{className:"text-[12px] text-amber-300/80 leading-relaxed",children:["Requires ",e.join(", "),"."," ",r.jsx(gn,{to:"/settings?tab=secrets",onClick:i,className:"underline hover:text-amber-300 transition-colors",children:"Configure in Settings → Secrets"})]})})]}),t.length>0&&r.jsx("div",{className:"p-2.5 rounded-lg bg-blue-500/[0.08] border border-blue-500/20",children:r.jsxs("p",{className:"text-[12px] text-blue-300/80 leading-relaxed",children:["Requires: ",r.jsx("span",{className:"font-mono",children:t.join(", ")})]})}),s&&r.jsxs("div",{className:"p-2.5 rounded-lg bg-amber-500/[0.08] border border-amber-500/20 flex items-start gap-2",children:[r.jsx(_m,{className:"w-3.5 h-3.5 text-amber-400 flex-shrink-0 mt-0.5"}),r.jsx("p",{className:"text-[12px] text-amber-300/80 leading-relaxed",children:"This skill contains network activity patterns. Review the SKILL.md before enabling for agents."})]})]})}function LRe({skills:e}){const[t,n]=y.useState(""),[s,i]=y.useState(""),[a,o]=y.useState(null),[l,c]=y.useState(null),d=y.useRef(null),f=L.useUtils(),p=new Set(e.filter(C=>C.source==="clawhub").map(C=>C.slug));function m(C){n(C),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>i(C),300)}const{data:g=[],isLoading:b,isFetching:_}=L.skills.searchClawHub.useQuery({query:s},{enabled:s.length>0,staleTime:5*6e4}),w=g.map(C=>({...C,installed:p.has(C.slug)})),A=L.skills.inspectClawHub.useQuery({slug:a?.slug??""},{enabled:!!a,staleTime:5*6e4}),S=L.skills.installFromClawHub.useMutation({onSuccess:C=>{f.skills.list.invalidate(),f.skills.getAgentSkills.invalidate(),o(null),c({name:C.skill.name,envVars:C.requiredEnvVars,bins:C.requiredBins,hasSecurityWarning:C.hasSecurityWarning})}});return r.jsxs("div",{children:[r.jsxs("div",{className:"relative mb-6",children:[r.jsx(Io,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[#5A5A6E]"}),r.jsx("input",{value:t,onChange:C=>m(C.target.value),placeholder:"Search ClawHub skills...",className:"w-full bg-[#16161A] border border-[#2A2A35] rounded-xl pl-9 pr-4 py-2.5 text-[13px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#8B5CF6]/60 transition-colors"}),_&&r.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:r.jsx("div",{className:"w-4 h-4 border-2 border-[#8B5CF6]/30 border-t-[#8B5CF6] rounded-full animate-spin"})})]}),b&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[1,2,3,4,5,6].map(C=>r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 animate-pulse h-[180px]"},C))}),!b&&w.length===0&&s&&r.jsx("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:r.jsxs("p",{className:"text-[14px] text-[#8A8A99]",children:['No skills found for "',s,'".']})}),!b&&w.length>0&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:w.map(C=>r.jsx(PRe,{result:C,onReviewInstall:o},`${C.publisher}/${C.slug}`))}),a&&r.jsx(ORe,{result:{...a,publisher:A.data?.publisher??a.publisher??"",version:A.data?.version,hasSecurityWarning:A.data?.hasSecurityWarning??a.hasSecurityWarning},inspectData:A.data?{downloads:A.data.downloads,stars:A.data.stars,tags:A.data.tags}:void 0,onClose:()=>o(null),onInstall:()=>S.mutate({slug:a.slug,publisher:A.data?.publisher??a.publisher??"",displayName:A.data?.displayName??a.displayName,version:A.data?.version??"1.0.0"})}),r.jsx(Me,{children:l&&r.jsx(IRe,{skillName:l.name,requiredEnvVars:l.envVars,requiredBins:l.bins,hasSecurityWarning:l.hasSecurityWarning,onClose:()=>c(null)})})]})}function BRe(){const[e,t]=y.useState("my-skills"),[n,s]=y.useState(""),[i,a]=y.useState(null),[o,l]=y.useState(!1),[c,d]=y.useState(null),[f,p]=y.useState(!1),[m,g]=y.useState(null),[b,_]=y.useState(!1),{data:w=[]}=Vo(),A=L.useUtils(),S=Uo(),{data:C=[],isLoading:E}=L.skills.list.useQuery(),k=L.skills.installForAllAgents.useMutation({onSuccess:()=>A.skills.getAgentSkills.invalidate()}),T=L.skills.uninstallFromAllAgents.useMutation({onSuccess:()=>{A.skills.getAgentSkills.invalidate(),a(null)}}),F=L.skills.uninstallClawHub.useMutation({onSettled:async()=>{await A.skills.list.invalidate(),await A.skills.getAgentSkills.invalidate(),a(null)}}),M=L.skills.deleteCustom.useMutation({onSuccess:()=>{A.skills.list.invalidate(),A.skills.getAgentSkills.invalidate(),a(null)}});function I(V){V.source==="authored"?(g(V.id),p(!0)):(d(V.id),l(!0))}const R=e==="my-skills"?C.filter(V=>{if(!n.trim())return!0;const K=n.toLowerCase();return V.name.toLowerCase().includes(K)||V.slug.toLowerCase().includes(K)||V.description.toLowerCase().includes(K)}):C,H=e==="clawhub";return r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11]",children:[r.jsxs("div",{className:"max-w-5xl mx-auto px-8 py-10",children:[r.jsxs("div",{className:"mb-8 flex items-start justify-between",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"Skills"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mt-0.5",children:"Capabilities your agents can execute. Install a skill to make it available, then assign it per agent."})]}),S&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("button",{onClick:()=>{g(null),p(!0)},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 border border-[#6366F1]/30 transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"New Skill"]}),r.jsxs("button",{onClick:()=>_(!0),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:[r.jsx(su,{className:"w-3.5 h-3.5"}),"Import"]}),r.jsxs(gn,{to:"/settings?tab=secrets",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:[r.jsx(Eo,{className:"w-3.5 h-3.5"}),"Secrets"]})]})]}),r.jsxs("div",{className:"flex items-center gap-1 mb-6 border-b border-[#2A2A35]",children:[r.jsx("button",{onClick:()=>t("my-skills"),className:ye("px-4 py-2.5 text-[13px] font-medium transition-colors border-b-2 -mb-px",e==="my-skills"?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:"My Skills"}),S&&r.jsx("button",{onClick:()=>t("clawhub"),className:ye("px-4 py-2.5 text-[13px] font-medium transition-colors border-b-2 -mb-px",e==="clawhub"?"text-[#F0F0F5] border-[#8B5CF6]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:"Browse ClawHub"})]}),e==="my-skills"&&r.jsxs("div",{className:"relative mb-6",children:[r.jsx(Io,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[#5A5A6E]"}),r.jsx("input",{value:n,onChange:V=>s(V.target.value),placeholder:"Search skills...",className:"w-full bg-[#16161A] border border-[#2A2A35] rounded-xl pl-9 pr-4 py-2.5 text-[13px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"})]}),H?r.jsx(LRe,{skills:C}):r.jsxs(r.Fragment,{children:[E&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[1,2,3,4,5,6].map(V=>r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 animate-pulse h-[180px]"},V))}),!E&&R.length===0&&r.jsx("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:"No skills for this provider yet."})}),!E&&R.length>0&&r.jsx(DRe,{skills:R,agents:w,selectedSkillId:i?.id??null,onInstall:V=>k.mutate({skillId:V}),onUninstall:V=>T.mutate({skillId:V}),onRemove:async V=>{await F.mutateAsync({skillId:V}).catch(()=>{})},onSelect:S?a:()=>{},onEditCustom:I,onDeleteCustom:V=>M.mutate({skillId:V}),canManage:S})]})]}),r.jsx(Me,{children:S&&i&&r.jsx(MRe,{skill:i,agents:w,onClose:()=>a(null)},i.id)}),r.jsx(Me,{children:S&&o&&r.jsx(yRe,{open:o,onClose:()=>{l(!1),d(null)},editSkillId:c,editSkillSlug:c?C.find(V=>V.id===c)?.slug:void 0})}),S&&r.jsx(wRe,{open:f,onClose:()=>{p(!1),g(null)},editSkillId:m}),r.jsx(Me,{children:S&&b&&r.jsx(CRe,{onClose:()=>_(!1),onSuccess:()=>{A.skills.list.invalidate()}})})]})}const zRe=$o()(gj(e=>({model:"anthropic/claude-sonnet-4-6",setModel:t=>e({model:t})}),{name:"damn-dev-coo"})),Hf="chan_coo",zd="#F59E0B";function $Re(e){try{return JSON.parse(e)}catch{return null}}function VRe(e){try{return JSON.parse(e)}catch{return null}}function URe({messageId:e,trustData:t,decided:n,onApprove:s,onReject:i,isApproving:a,isRejecting:o}){return r.jsxs(ne.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"mx-4 mb-2 rounded-xl border border-[#6366F1]/30 bg-[#6366F1]/5 overflow-hidden",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#6366F1]/20",children:[r.jsx("p",{className:"text-[12px] font-semibold text-[#818CF8] uppercase tracking-wide",children:"Trust configuration proposal"}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:["Agent: ",r.jsx("span",{className:"text-[#A5A5C5]",children:t.agentId})]})]}),r.jsxs("div",{className:"px-4 py-3 space-y-2",children:[typeof t.autoApprove=="boolean"&&r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Auto-approve"}),r.jsx("span",{className:t.autoApprove?"text-[#F87171]":"text-[#34D399]",children:t.autoApprove?"Enable":"Disable"})]}),t.sandboxMode&&r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Sandbox"}),r.jsx("span",{className:"text-[#A5A5C5]",children:t.sandboxMode})]}),t.shellAllowlist!==void 0&&r.jsxs("div",{className:"text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Shell allowlist"}),r.jsx("p",{className:"text-[#A5A5C5] mt-0.5",children:t.shellAllowlist?t.shellAllowlist.join(", "):"unrestricted"})]}),t.mounts&&t.mounts.length>0&&r.jsxs("div",{className:"text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Mounts"}),t.mounts.map((l,c)=>r.jsxs("p",{className:"text-[#A5A5C5] mt-0.5 font-mono",children:[l.hostPath," → ",l.agentPath]},c))]})]}),n?r.jsx("div",{className:`px-4 py-2.5 text-[12px] font-medium ${n==="approved"?"text-[#34D399] bg-[#10B981]/5":"text-[#F87171] bg-[#EF4444]/5"}`,children:n==="approved"?"✓ Applied":"✗ Rejected"}):r.jsxs("div",{className:"flex border-t border-[#6366F1]/20",children:[r.jsx(ne.button,{whileHover:{backgroundColor:"rgba(16,185,129,0.12)"},whileTap:{scale:.98},onClick:()=>s(e),disabled:a||o,className:"flex-1 py-2.5 text-[12px] font-medium text-[#34D399] border-r border-[#6366F1]/20 transition-colors disabled:opacity-50",children:a?"Applying…":"Apply"}),r.jsx(ne.button,{whileHover:{backgroundColor:"rgba(239,68,68,0.08)"},whileTap:{scale:.98},onClick:()=>i(e),disabled:a||o,className:"flex-1 py-2.5 text-[12px] font-medium text-[#F87171] transition-colors disabled:opacity-50",children:"Reject"})]})]})}function HRe(e){try{const t=JSON.parse(e);return typeof t.agentId=="string"&&typeof t.pattern=="string"&&typeof t.autoApprove=="boolean"&&typeof t.reason=="string"?t:null}catch{return null}}function WRe({messageId:e,rule:t,decided:n,onApprove:s,onReject:i,isPending:a}){return r.jsxs(ne.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"mx-4 mb-2 rounded-xl border border-[#F59E0B]/30 bg-[#F59E0B]/5 overflow-hidden",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#F59E0B]/20 flex items-center gap-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}),r.jsx("p",{className:"text-[12px] font-semibold text-[#FBBF24] uppercase tracking-wide",children:"Delegation rule proposal"})]}),r.jsxs("div",{className:"px-4 py-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Agent"}),r.jsx("span",{className:"text-[#A5A5C5] font-medium",children:t.agentId})]}),r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Pattern"}),r.jsx("code",{className:"text-[#FBBF24] bg-[#F59E0B]/10 px-1.5 py-0.5 rounded text-[11px] font-mono",children:t.pattern})]}),r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Auto-approve"}),r.jsx("span",{className:t.autoApprove?"text-[#F87171]":"text-[#34D399]",children:t.autoApprove?"Yes":"No"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] italic leading-relaxed pt-1",children:t.reason})]}),n?r.jsx("div",{className:`px-4 py-2.5 text-[12px] font-medium ${n==="approved"?"text-[#34D399] bg-[#10B981]/5":"text-[#F87171] bg-[#EF4444]/5"}`,children:n==="approved"?"✓ Rule created":"✗ Rejected"}):r.jsxs("div",{className:"flex border-t border-[#F59E0B]/20",children:[r.jsx(ne.button,{whileHover:{backgroundColor:"rgba(16,185,129,0.12)"},whileTap:{scale:.98},onClick:()=>s(e),disabled:a,className:"flex-1 py-2.5 text-[12px] font-medium text-[#34D399] border-r border-[#F59E0B]/20 transition-colors disabled:opacity-50",children:a?"Creating…":"Create Rule"}),r.jsx(ne.button,{whileHover:{backgroundColor:"rgba(239,68,68,0.08)"},whileTap:{scale:.98},onClick:()=>i(e),disabled:a,className:"flex-1 py-2.5 text-[12px] font-medium text-[#F87171] transition-colors disabled:opacity-50",children:"Reject"})]})]})}function qRe({proposal:e,proposalId:t,onApprove:n,onReject:s,isApproving:i,isRejecting:a,decided:o,progressSteps:l,completionResult:c}){const d=an(),[f,p]=y.useState(!1),m=o?!f:f,g=_=>p(o?!_:_),b=e.skillAssignments?.some(_=>_.skills.some(w=>w.includes("approval")));return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>g(!m),className:"w-full px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between hover:bg-white/[0.02] transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Ia,{className:"w-4 h-4 text-[#F59E0B]"}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Workspace Proposal"}),o&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",o==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:o})]}),r.jsx(ft,{className:ye("w-4 h-4 text-[#5A5A6E] transition-transform",m&&"-rotate-90")})]}),!m&&e.agents?.length>0&&r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50",children:[r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Agents to create"}),r.jsx("div",{className:"mt-3 space-y-2.5",children:e.agents.map(_=>r.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-[#13131A] border border-[#2A2A35]",children:[r.jsx("span",{className:"w-8 h-8 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`${_.color}26`},children:_.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-2",children:[r.jsx("span",{className:"text-[13px] font-semibold",style:{color:_.color},children:_.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:_.role})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mt-1 line-clamp-2",children:_.soulDescription}),(e.skillAssignments??[]).filter(w=>w.agentName===_.name).map(w=>r.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:w.skills.map(A=>r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-white/5 border border-[#2A2A35] text-[#C8C8D4]",children:A},A))},w.agentName))]})]},_.name))})]}),!m&&e.channels?.length>0&&r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50",children:[r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Channels to create"}),r.jsx("div",{className:"mt-3 space-y-1.5",children:e.channels.map(_=>r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-lg bg-[#13131A] border border-[#2A2A35]",children:[r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:"#"}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5] font-medium",children:_.name}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E] px-1.5 py-0.5 rounded bg-white/5",children:_.type}),_.description&&r.jsx("span",{className:"text-[11px] text-[#8A8A99] truncate flex-1",children:_.description})]},_.name))})]}),!m&&b&&r.jsxs("div",{className:"px-5 py-3 bg-[#F59E0B]/5 border-b border-[#F59E0B]/10 flex items-center gap-2",children:[r.jsx(ql,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}),r.jsx("span",{className:"text-[12px] text-[#F59E0B]",children:"Some skills will require your approval before execution"})]}),r.jsx(Me,{mode:"wait",children:!m&&l.length>0&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},className:"px-5 py-3 border-b border-[#2A2A35]/50 bg-[#13131A]",children:r.jsx("div",{className:"space-y-1.5",children:l.map((_,w)=>r.jsxs(ne.div,{initial:{opacity:0,x:-10},animate:{opacity:1,x:0},className:"flex items-center gap-2 text-[12px]",children:[r.jsx(Fe,{className:"w-3 h-3 text-[#10B981] flex-shrink-0"}),r.jsxs("span",{className:"text-[#8A8A99]",children:[_.step,":"]}),r.jsx("span",{className:"text-[#C8C8D4]",children:_.detail})]},w))})})}),!m&&c&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"px-5 py-4 bg-[#10B981]/5 border-b border-[#10B981]/10",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(Fe,{className:"w-4 h-4 text-[#10B981]"}),r.jsx("span",{className:"text-[13px] font-semibold text-[#10B981]",children:"Your team is ready"})]}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c.agentsCreated," agent",c.agentsCreated!==1?"s":""," created,"," ",c.channelsCreated," channel",c.channelsCreated!==1?"s":""," created."]}),c.firstChannelId&&r.jsxs("button",{onClick:()=>d(`/channels/${c.firstChannelId}`),className:"mt-2 flex items-center gap-1.5 text-[12px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Go to first agent",r.jsx(tu,{className:"w-3 h-3"})]})]}),!m&&!o&&!c&&r.jsxs("div",{className:"px-5 py-4 flex gap-2",children:[r.jsxs("button",{onClick:()=>t&&n(t),disabled:!t||i||a,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-[#10B981]/10 text-[#34D399] border border-[#10B981]/30 text-[13px] font-medium hover:bg-[#10B981]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:[i?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Fe,{className:"w-3.5 h-3.5"}),i?"Creating...":"Approve & Create"]}),r.jsx("button",{onClick:()=>t&&s(t),disabled:!t||i||a,className:"px-4 py-2.5 rounded-lg bg-[#EF4444]/10 text-[#F87171] border border-[#EF4444]/30 text-[13px] font-medium hover:bg-[#EF4444]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),!m&&o==="rejected"&&r.jsx("div",{className:"px-5 py-3 bg-[#EF4444]/5",children:r.jsx("span",{className:"text-[12px] text-[#F87171]",children:"Proposal rejected"})})]})}function GRe({status:e}){return e==="done"?r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"}):e==="failed"?r.jsx(Te,{className:"w-3.5 h-3.5 text-[#EF4444]"}):r.jsx(Pe,{className:"w-3.5 h-3.5 text-[#F59E0B] animate-spin"})}function KRe({goal:e,dispatches:t,groupChannelId:n}){const s=an(),i=!!n&&t.every(a=>a.channelId===n);return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsx("div",{className:"px-5 py-4 border-b border-[#2A2A35]",children:r.jsx("p",{className:"text-[13px] text-[#8A8A99] leading-relaxed",children:e})}),r.jsx("div",{className:"px-5 py-3 space-y-2",children:t.map((a,o)=>r.jsxs(ne.div,{initial:{opacity:0,x:-12},animate:{opacity:1,x:0},transition:{delay:o*.08,duration:.25},className:"flex items-start gap-3 p-3 rounded-lg bg-[#13131A] border border-[#2A2A35]",children:[r.jsx("span",{className:"w-7 h-7 rounded-full bg-[#F59E0B]/15 flex items-center justify-center text-[12px] flex-shrink-0 mt-0.5",children:a.agentName.charAt(0)}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:a.agentName}),r.jsx(GRe,{status:a.status})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mt-0.5 line-clamp-2",children:a.instruction}),!i&&a.channelId&&r.jsxs("button",{onClick:()=>s(`/channels/${a.channelId}`),className:"mt-1.5 flex items-center gap-1 text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(tu,{className:"w-3 h-3"}),"View in channel"]})]})]},`${a.agentId}-${o}`))}),r.jsxs("div",{className:"px-5 py-3 border-t border-[#2A2A35]/50 flex items-center justify-between",children:[r.jsxs("span",{className:"text-[12px] text-[#10B981]/80",children:[t.length," task",t.length!==1?"s":""," dispatched",i?" (group)":""]}),n&&r.jsxs("button",{onClick:()=>s(`/channels/${n}`),className:"flex items-center gap-1 text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(tu,{className:"w-3 h-3"}),"View group channel"]})]})]})}function YRe({message:e,isLast:t,proposalStatuses:n,progressSteps:s,completionResult:i,onApprove:a,onReject:o,isApproving:l,isRejecting:c,onApproveTrust:d,onRejectTrust:f,isTrustApproving:p,isTrustRejecting:m,onApproveDelegation:g,onRejectDelegation:b,isDelegationPending:_,dispatchStatuses:w}){const A=e.sender.type==="human",{stripped:S,proposal:C}=A?{stripped:e.content,proposal:null}:K7(e.content),E=e.metadata?.proposalId,k=e.metadata?.proposalJson,T=k?$Re(k):null,F=E?n[E]:void 0,M=F==="approved"||F==="rejected"?F:null,I=e.metadata?.trustUpdate,R=I?VRe(I):null,H=e.status==="approved"?"approved":e.status==="rejected"?"rejected":null,V=e.metadata?.delegationRule,K=typeof V=="object"?V:typeof V=="string"?HRe(V):null,q=K?e.status==="approved"?"approved":e.status==="rejected"?"rejected":null:null,$=e.metadata?.dispatch,B=w.get(e.id),Y=e.metadata?.nodeSpawnProposalId,U=e.metadata?.nodeSpawnJson;let W=null;if(U)try{const le=JSON.parse(U);typeof le.name=="string"&&typeof le.reason=="string"&&(W={name:le.name,reason:le.reason})}catch{}const O=e.status==="approved"?"approved":e.status==="rejected"?"rejected":null,D=e.metadata?.federationGrantProposalId,Q=e.metadata?.federationGrantJson;let z=null;if(Q)try{const le=JSON.parse(Q);typeof le.nodeName=="string"&&typeof le.grantAgentId=="string"&&typeof le.reason=="string"&&(z={nodeName:le.nodeName,grantAgentId:le.grantAgentId,reason:le.reason})}catch{}const J=e.metadata?.cloudSpawnProposalId,ee=e.metadata?.cloudSpawnJson;let re=null;if(ee)try{const le=JSON.parse(ee);typeof le.name=="string"&&typeof le.provider=="string"&&typeof le.region=="string"&&typeof le.size=="string"&&typeof le.reason=="string"&&(re={name:le.name,provider:le.provider,region:le.region,size:le.size,reason:le.reason})}catch{}const se=(e.metadata?.remoteAgentProposals??[]).map(le=>{try{const ge=JSON.parse(le.json);if(typeof ge.nodeName=="string"&&typeof ge.name=="string"&&typeof ge.emoji=="string"&&typeof ge.color=="string"&&typeof ge.role=="string"&&typeof ge.soul=="string")return{proposalId:le.id,nodeName:ge.nodeName,name:ge.name,emoji:ge.emoji,color:ge.color,role:ge.role,soul:ge.soul}}catch{}return null}).filter(le=>le!==null),ae=(()=>{const le=new Map;for(const ge of se){const je=le.get(ge.nodeName);je?je.push(ge):le.set(ge.nodeName,[ge])}return Array.from(le.entries()).map(([ge,je])=>({nodeName:ge,agents:je}))})();return r.jsxs("div",{children:[r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2},className:ye("flex items-start gap-3 px-4 py-2",A?"":"border-l-[3px] border-l-[#F59E0B]"),children:[r.jsx("div",{className:"flex-shrink-0 mt-0.5",children:A?r.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-[#4A4A5E] to-[#2A2A3E] flex items-center justify-center border border-[#3A3A4E]",children:r.jsx("span",{className:"text-[11px] font-semibold text-[#A5A5C5]",children:"A"})}):r.jsx("div",{className:"w-8 h-8 rounded-full bg-[#F59E0B]/15 flex items-center justify-center",children:r.jsx(Ia,{className:"w-4 h-4 text-[#F59E0B]"})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[r.jsx("span",{className:ye("text-[13px] font-semibold",A?"text-[#F0F0F5]":"text-[#F59E0B]"),children:A?e.sender.name:"COO"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:Ir(e.timestamp)})]}),r.jsx("div",{className:"text-[14px] text-[#C8C8D4] leading-relaxed prose-message",children:r.jsx(Ei,{remarkPlugins:[Fi],children:S})}),C!==null&&r.jsx(G7,{proposal:C,messageId:e.id,metadata:e.metadata}),e.metadata?.skillWriteProposal?r.jsx(Q7,{message:e,proposal:e.metadata.skillWriteProposal}):null,e.metadata?.skillInstallProposal?r.jsx(Y7,{proposal:e.metadata.skillInstallProposal,messageId:e.id,metadata:e.metadata}):null,e.status==="pending_approval"&&!e.metadata?.missionPlan&&!e.metadata?.nodeSpawnProposalId&&se.length===0&&r.jsx(J7,{message:e})]})]}),T&&r.jsx(qRe,{proposal:T,proposalId:E,onApprove:a,onReject:o,isApproving:l,isRejecting:c,decided:M,progressSteps:t?s:[],completionResult:t?i:null}),R&&r.jsx(URe,{messageId:e.id,trustData:R,decided:H,onApprove:d,onReject:f,isApproving:p,isRejecting:m}),K&&r.jsx(WRe,{messageId:e.id,rule:K,decided:q,onApprove:g,onReject:b,isPending:_}),$&&B&&B.length>0&&r.jsx(KRe,{goal:$.goal,dispatches:B}),W&&Y&&r.jsx(XRe,{proposalId:Y,name:W.name,reason:W.reason,decided:O,serverStatus:n[Y]}),ae.map(le=>r.jsx(QRe,{nodeName:le.nodeName,agents:le.agents,serverStatuses:n},le.nodeName)),z&&D&&r.jsx(tDe,{proposalId:D,data:z,serverStatus:n[D]}),re&&J&&r.jsx(nDe,{proposalId:J,data:re,serverStatus:n[J]}),e.metadata?.missionPlan?r.jsx(sDe,{plan:e.metadata.missionPlan,messageId:e.id,decided:e.status==="approved"?"approved":e.status==="rejected"?"rejected":null}):null]})}function QRe({nodeName:e,agents:t,serverStatuses:n}){const s=t.map(F=>{const M=n[F.proposalId];return M==="approved"?"approved":M==="rejected"?"rejected":M==="failed"?"failed":"pending"}),i=s.every(F=>F!=="pending"),a=s.every(F=>F==="rejected"),o=s.some(F=>F==="approved"||F==="failed"),l=i&&a?"rejected":i&&o?"approved":null,c=s.filter(F=>F==="approved").length,d=s.filter(F=>F==="failed").length,[f,p]=y.useState(!1),m=l?!f:f,g=F=>p(l?!F:F),b=L.useUtils(),_=L.coo.approveRemoteAgent.useMutation(),w=L.coo.rejectRemoteAgent.useMutation(),[A,S]=y.useState(null),[C,E]=y.useState(null),k=async()=>{S("approving"),E(null);try{for(const F of t)n[F.proposalId]&&n[F.proposalId]!=="pending"||await _.mutateAsync({proposalId:F.proposalId})}catch(F){E(F instanceof Error?F.message:"Failed to approve one or more agents")}finally{S(null),b.federation.listNodes.invalidate(),b.coo.listProposals.invalidate()}},T=async()=>{S("rejecting"),E(null);try{for(const F of t)n[F.proposalId]&&n[F.proposalId]!=="pending"||await w.mutateAsync({proposalId:F.proposalId})}catch(F){E(F instanceof Error?F.message:"Failed to reject one or more agents")}finally{S(null),b.coo.listProposals.invalidate()}};return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>g(!m),className:"w-full px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between hover:bg-white/[0.02] transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(Mp,{className:"w-4 h-4 text-[#6366F1] flex-shrink-0"}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Remote Team Proposal"}),r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:"on"}),r.jsx("span",{className:"text-[12px] font-mono px-2 py-0.5 rounded bg-[#6366F1]/15 text-[#818CF8] font-semibold",children:e}),l&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",l==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:l})]}),r.jsx(ft,{className:ye("w-4 h-4 text-[#5A5A6E] transition-transform flex-shrink-0",m&&"-rotate-90")})]}),!m&&t.length>0&&r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50",children:[r.jsxs("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:["Agents to create on ",r.jsx("span",{className:"text-[#818CF8] font-mono",children:e})]}),r.jsx("div",{className:"mt-3 space-y-2.5",children:t.map((F,M)=>{const I=s[M];return r.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-[#13131A] border border-[#2A2A35]",children:[r.jsx("span",{className:"w-8 h-8 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`${F.color}26`},children:F.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[r.jsx("span",{className:"text-[13px] font-semibold",style:{color:F.color},children:F.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:F.role}),I==="approved"&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium bg-[#10B981]/10 text-[#34D399] uppercase tracking-wider",children:"created"}),I==="failed"&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium bg-[#EF4444]/10 text-[#F87171] uppercase tracking-wider",children:"failed"}),I==="rejected"&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium bg-[#8A8A99]/10 text-[#8A8A99] uppercase tracking-wider",children:"rejected"}),I==="pending"&&A==="approving"&&r.jsx(Pe,{className:"w-3 h-3 animate-spin text-[#6366F1]"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mt-1 line-clamp-2",children:F.soul})]})]},F.proposalId)})})]}),!m&&l==="approved"&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"px-5 py-4 bg-[#10B981]/5 border-b border-[#10B981]/10",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(Fe,{className:"w-4 h-4 text-[#10B981]"}),r.jsxs("span",{className:"text-[13px] font-semibold text-[#10B981]",children:["Remote team ready on ",r.jsx("span",{className:"font-mono",children:e})]})]}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c," agent",c!==1?"s":""," created",d>0?`, ${d} failed`:"",". You can now delegate to them using ",r.jsx("code",{className:"text-[11px] px-1 py-0.5 rounded bg-[#0F0F11] text-[#C8C8D4]",children:"<slug>@"+e})," in delegate blocks."]})]}),!m&&C&&r.jsxs("div",{className:"px-5 py-3 bg-[#EF4444]/5 border-b border-[#EF4444]/20 flex items-start gap-2 text-[12px] text-[#F87171]",children:[r.jsx("span",{className:"mt-0.5",children:"⚠"}),r.jsx("span",{className:"break-all",children:C})]}),!m&&!l&&r.jsxs("div",{className:"px-5 py-4 flex gap-2",children:[r.jsxs("button",{onClick:k,disabled:A!==null,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-[#10B981]/10 text-[#34D399] border border-[#10B981]/30 text-[13px] font-medium hover:bg-[#10B981]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:[A==="approving"?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Fe,{className:"w-3.5 h-3.5"}),A==="approving"?`Creating ${c+d+1}/${t.length}…`:`Approve & Create ${t.length>1?`all ${t.length}`:""}`]}),r.jsx("button",{onClick:T,disabled:A!==null,className:"px-4 py-2.5 rounded-lg bg-[#EF4444]/10 text-[#F87171] border border-[#EF4444]/30 text-[13px] font-medium hover:bg-[#EF4444]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:A==="rejecting"?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),!m&&l==="rejected"&&r.jsx("div",{className:"px-5 py-3 bg-[#EF4444]/5",children:r.jsx("span",{className:"text-[12px] text-[#F87171]",children:"Remote team proposal rejected"})})]})}function XRe({proposalId:e,name:t,reason:n,decided:s,serverStatus:i}){const[a,o]=y.useState(null),c=a??(i==="approved"||i==="failed"?"approved":i==="rejected"?"rejected":null)??s,[d,f]=y.useState(!1),p=c?!d:d,m=C=>f(c?!C:C),g=L.useUtils(),b=L.coo.approveNodeSpawn.useMutation({onSuccess:()=>{o("approved"),g.federation.listNodes.invalidate(),g.coo.listProposals.invalidate()}}),_=L.coo.rejectNodeSpawn.useMutation({onSuccess:()=>{o("rejected"),g.coo.listProposals.invalidate()}}),A=L.federation.getSpawnDefaults.useQuery().data?.defaultNodeSpawnPolicy??"coo-only",S=b.isPending||_.isPending;return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#6366F1]/25 rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>m(!p),className:"w-full px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between hover:bg-white/[0.02] transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"w-6 h-6 rounded-lg bg-[#6366F1]/15 flex items-center justify-center",children:r.jsx("span",{className:"text-[13px]",children:"⚡"})}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Spawn Isolated Node"}),r.jsx("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded bg-[#6366F1]/15 text-[#818CF8]",children:t}),c&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",c==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:c})]}),r.jsx(ft,{className:ye("w-4 h-4 text-[#5A5A6E] transition-transform",p&&"-rotate-90")})]}),!p&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50",children:[r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Why"}),r.jsx("p",{className:"mt-2 text-[13px] text-[#C8C8D4] leading-relaxed",children:n})]}),r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50 space-y-2",children:[r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"What will happen"}),r.jsxs("div",{className:"space-y-1.5 text-[12px] text-[#8A8A99]",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-[#6366F1] mt-0.5",children:"•"}),r.jsx("span",{children:"A brand-new isolated damn.dev container (backend + OpenClaw) will start on this machine"})]}),r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-[#6366F1] mt-0.5",children:"•"}),r.jsxs("span",{children:["Its own SQLite DB and OpenClaw workspace at ",r.jsxs("code",{className:"text-[11px] px-1 py-0.5 rounded bg-[#0F0F11] text-[#C8C8D4]",children:["~/.damn-dev/nodes/",t,"/"]})]})]}),r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-[#6366F1] mt-0.5",children:"•"}),r.jsxs("span",{children:["Default delegation policy: ",r.jsx("strong",{className:"text-[#F0F0F5]",children:A})," — adjustable from Settings → Federation"]})]}),r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-[#6366F1] mt-0.5",children:"•"}),r.jsxs("span",{children:["Auto-federated: the COO will be able to dispatch to any agents you later create on this node using ",r.jsx("code",{className:"text-[11px] px-1 py-0.5 rounded bg-[#0F0F11] text-[#C8C8D4]",children:"<agent>@"+t})," syntax"]})]})]})]}),b.isError&&r.jsxs("div",{className:"px-5 py-3 bg-[#EF4444]/5 border-b border-[#EF4444]/20 flex items-start gap-2 text-[12px] text-[#F87171]",children:[r.jsx("span",{className:"mt-0.5",children:"⚠"}),r.jsx("span",{children:b.error?.message})]}),_.isError&&r.jsxs("div",{className:"px-5 py-3 bg-[#EF4444]/5 border-b border-[#EF4444]/20 flex items-start gap-2 text-[12px] text-[#F87171]",children:[r.jsx("span",{className:"mt-0.5",children:"⚠"}),r.jsx("span",{children:_.error?.message})]}),!c&&r.jsxs("div",{className:"px-5 py-4 flex gap-2",children:[r.jsxs("button",{onClick:()=>b.mutate({proposalId:e}),disabled:S,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-[#10B981]/10 text-[#34D399] border border-[#10B981]/30 text-[13px] font-medium hover:bg-[#10B981]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:[b.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Fe,{className:"w-3.5 h-3.5"}),b.isPending?"Spawning…":"Approve & Spawn"]}),r.jsx("button",{onClick:()=>_.mutate({proposalId:e}),disabled:S,className:"flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-[#2A2A35] text-[#8A8A99] border border-[#2A2A35] text-[13px] font-medium hover:bg-[#3A3A45] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:_.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):"Reject"})]})]})]})}function JRe(){const e=L.useUtils(),{data:t}=L.agents.list.useQuery(),n=t?.find(f=>f.id==="coo"),s=n?.model??n?.defaultModel??"",i=L.agents.update.useMutation({onSuccess:()=>e.agents.list.invalidate()}),a=f=>i.mutate({agentId:"coo",model:f}),o=Up(s),[l,c]=y.useState(""),{groups:d}=Vm();return r.jsxs(ss,{value:s,onValueChange:a,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] border transition-colors outline-none",style:{color:zd,backgroundColor:`${zd}15`,borderColor:`${zd}40`},children:[r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[o]}`,children:o}),r.jsx(Ds,{children:ta(s)}),r.jsx(ft,{className:"w-3 h-3 opacity-60"})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:6,align:"end",className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] z-50",children:[r.jsx(os,{children:d.map(f=>r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:f.label}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo[f.tag]}`,children:f.tag})]}),f.models.map(p=>r.jsxs(vn,{value:p.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:p.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},p.id))]},f.label))}),r.jsx("div",{className:"px-2 pt-1 pb-2 border-t border-[#2A2A35] mt-1",children:r.jsx(ty,{value:l,onChange:c,onSubmit:f=>{a(f),c("")}})})]})})]})}function ZRe(){if(!Uo())return r.jsx(lm,{to:"/channels/direction",replace:!0});const{data:t,isLoading:n}=L.agents.list.useQuery(void 0,{refetchInterval:a=>a.state.data?.some(l=>l.id==="coo")?!1:3e3}),s=L.onboarding.seedCOO.useMutation(),i=t?.some(a=>a.id==="coo");return n?r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Pe,{className:"w-5 h-5 animate-spin text-[#F59E0B]"})}):i?r.jsx(eDe,{}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center px-8",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-[#F59E0B]/10 border border-[#F59E0B]/20 flex items-center justify-center mb-4",children:r.jsx(Ia,{className:"w-7 h-7 text-[#F59E0B]"})}),r.jsx("h2",{className:"text-[18px] font-semibold text-[#F0F0F5] mb-2",children:"Your COO"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] max-w-md leading-relaxed mb-6",children:"The COO is your workspace architect. It can design agent teams, assign skills, and manage your workspace structure."}),r.jsxs("button",{onClick:()=>s.mutate(),disabled:s.isPending,className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#F59E0B] text-[#0F0F11] hover:bg-[#FBBF24] disabled:opacity-60 transition-colors",children:[s.isPending&&r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),"Create COO"]}),s.isError&&r.jsx("p",{className:"mt-3 text-[12px] text-red-400",children:"Failed to create COO. Try again."})]})}function eDe(){const{model:e}=zRe(),[t,n]=y.useState(""),[s,i]=y.useState(!1),[a,o]=y.useState(!1),[l,c]=y.useState([]),[d,f]=y.useState(null),p=y.useRef(null),m=y.useRef(null),[g,b]=y.useState(new Map),_=y.useRef(null),{data:w}=pj("coo");bW(Hf);const A=Je(ee=>ee.messagesByChannel[Hf]),S=y.useMemo(()=>A??[],[A]),C=L.messages.list.useQuery({channelId:Hf,limit:100},{staleTime:0}),E=L.coo.listProposals.useQuery(void 0,{staleTime:5e3}),k=E.data??{};y.useEffect(()=>{C.data&&Je.getState().setMessages(Hf,C.data.messages)},[C.data]);const T=L.coo.getLatestTask.useQuery(void 0,{staleTime:5e3});y.useEffect(()=>{const ee=[...S].reverse().find(le=>le.sender.type==="agent"&&le.metadata?.dispatch);if(!ee)return;_.current=ee.id;const re=T.data;if(re&&re.dispatches.length>0){const le=re.dispatches.map(ge=>({agentId:ge.agentId,agentName:ge.agentName??ge.agentId,channelId:ge.channelId,instruction:ge.instruction,status:ge.status??"sent"}));b(ge=>new Map(ge).set(ee.id,le));return}if(g.has(ee.id))return;const oe=ee.metadata?.dispatch,se=[],ae=oe?.groups??(oe?.group?[oe.group]:[]);for(const le of ae)for(const ge of le.agents)se.push({agentId:ge,agentName:ge,channelId:"",instruction:le.goal,status:"sent"});if(oe?.assignments)for(const le of oe.assignments)se.push({agentId:le.agent,agentName:le.agent,channelId:"",instruction:le.instruction,status:"sent"});se.length>0&&b(le=>new Map(le).set(ee.id,se))},[S,T.data]);const F=L.coo.chat.useMutation(),M=L.coo.approveProposal.useMutation(),I=L.coo.rejectProposal.useMutation(),R=L.coo.approveTrustUpdate.useMutation(),H=L.coo.rejectTrustUpdate.useMutation(),V=L.approvals.decide.useMutation(),K=L.messages.resetSession.useMutation(),q=L.useUtils();y.useEffect(()=>{p.current?.scrollIntoView({behavior:"smooth"})},[S.length,l.length]),y.useEffect(()=>{const ee=new WebSocket("ws://localhost:3001/ws");return ee.onmessage=re=>{try{const oe=JSON.parse(re.data);if(oe.type==="coo.progress"){const se=oe.payload;c(ae=>[...ae,se])}else if(oe.type==="coo.complete"){const se=oe.payload;f(se),B.current()}else if(oe.type==="coo.dispatch.sent"){const se=oe.payload;_.current&&b(ae=>{const le=new Map(ae),ge=le.get(_.current)??[],je=ge.findIndex(Ee=>Ee.agentId===se.agentId);return je>=0?ge[je]={...ge[je],...se,status:"sent"}:ge.push({...se,status:"sent"}),le.set(_.current,[...ge]),le})}else if(oe.type==="coo.dispatch.agent.done"){const se=oe.payload;_.current&&b(ae=>{const le=new Map(ae),ge=le.get(_.current)??[];return le.set(_.current,ge.map(je=>je.agentId===se.agentId?{...je,status:se.status}:je)),le})}}catch{}},()=>ee.close()},[]);const $=y.useRef(!1),B=y.useRef(E.refetch);B.current=E.refetch;const Y=y.useCallback(async()=>{const ee=t.trim();if(!ee||F.isPending||$.current)return;$.current=!0;const re=S.map(oe=>({role:oe.sender.type==="human"?"user":"assistant",content:oe.content}));n(""),m.current&&(m.current.style.height="auto");try{await F.mutateAsync({message:ee,history:re,model:e}),C.refetch(),B.current()}catch{}finally{$.current=!1}},[t,F,S,e]);function U(ee){c([]),M.mutate({proposalId:ee},{onSuccess:()=>{q.agents.list.invalidate(),q.channels.list.invalidate(),E.refetch()}})}function W(ee){I.mutate({proposalId:ee},{onSuccess:()=>{E.refetch()}})}function O(ee){R.mutate({messageId:ee},{onSuccess:()=>{q.agents.getTrust.invalidate(),q.agents.getSandboxOverride.invalidate(),q.agents.getMounts.invalidate(),C.refetch()}})}function D(ee){H.mutate({messageId:ee},{onSuccess:()=>{C.refetch()}})}function Q(ee){V.mutate({messageId:ee,decision:"approved"},{onSuccess:()=>{C.refetch()}})}function z(ee){V.mutate({messageId:ee,decision:"rejected"},{onSuccess:()=>{C.refetch()}})}function J(){K.mutate({channelId:Hf}),c([]),f(null)}return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[#2A2A35] bg-[#0F0F11] flex-shrink-0",style:{borderLeftColor:zd,borderLeftWidth:3,borderLeftStyle:"solid"},children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:()=>o(ee=>!ee),className:"w-8 h-8 rounded-full bg-[#F59E0B]/15 flex items-center justify-center transition-opacity hover:opacity-80",children:r.jsx(Ia,{className:"w-4 h-4 text-[#F59E0B]"})}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:()=>o(ee=>!ee),className:"text-[15px] font-semibold text-[#F0F0F5] hover:underline decoration-dashed underline-offset-2 transition-colors",children:"COO"}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded",children:"Workspace Architect"})]}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"relative flex items-center justify-center w-2 h-2",children:r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:zd,opacity:.5}})}),r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:"ready"})]})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(JRe,{}),r.jsx(bt,{label:"Reset context",children:r.jsx("button",{onClick:J,className:"w-8 h-8 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:r.jsx(lh,{className:"w-4 h-4"})})}),r.jsx(bt,{label:a?"Close panel":"Open panel",children:r.jsx("button",{onClick:()=>o(ee=>!ee),className:ye("w-8 h-8 flex items-center justify-center rounded-md transition-colors",a?"text-[#F0F0F5] bg-white/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5"),children:a?r.jsx(mL,{className:"w-4 h-4"}):r.jsx(xL,{className:"w-4 h-4"})})})]})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto py-2",children:[S.length===0&&!C.isLoading&&r.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center px-8",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-[#F59E0B]/10 border border-[#F59E0B]/20 flex items-center justify-center mb-4",children:r.jsx(Ia,{className:"w-7 h-7 text-[#F59E0B]"})}),r.jsx("h2",{className:"text-[18px] font-semibold text-[#F0F0F5] mb-2",children:"Talk to your COO"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] max-w-md leading-relaxed",children:"Design your team, dispatch tasks, manage skills, update trust settings — all through natural conversation."})]}),r.jsx(Me,{initial:!1,children:S.map((ee,re)=>ee.sender.type==="context_reset"?r.jsxs("div",{className:"flex items-center gap-3 py-2 px-4",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"new context"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]},ee.id):r.jsx(YRe,{message:ee,isLast:re===S.length-1,proposalStatuses:k,progressSteps:l,completionResult:d,onApprove:U,onReject:W,isApproving:M.isPending,isRejecting:I.isPending,onApproveTrust:O,onRejectTrust:D,isTrustApproving:R.isPending,isTrustRejecting:H.isPending,onApproveDelegation:Q,onRejectDelegation:z,isDelegationPending:V.isPending,dispatchStatuses:g},ee.id))}),F.isPending&&r.jsxs("div",{className:"flex items-start gap-3 px-4 py-2 border-l-[3px] border-l-[#F59E0B]",children:[r.jsx("div",{className:"w-8 h-8 rounded-full bg-[#F59E0B]/15 flex items-center justify-center flex-shrink-0",children:r.jsx(Ia,{className:"w-4 h-4 text-[#F59E0B]"})}),r.jsx("div",{className:"flex items-center gap-1 pt-3",children:[0,1,2].map(ee=>r.jsx(ne.span,{className:"w-1.5 h-1.5 rounded-full bg-[#F59E0B]",animate:{opacity:[.3,1,.3],scale:[.8,1.1,.8]},transition:{duration:1.4,repeat:1/0,delay:ee*.2,ease:"easeInOut"}},ee))})]}),r.jsx("div",{ref:p,className:"h-4"})]}),r.jsxs("div",{className:"px-4 pb-4 pt-2 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-end gap-2 bg-[#1C1C21] border rounded-xl px-3 py-2.5 transition-colors duration-150",style:{borderColor:s?"#F59E0B60":"#2A2A35",boxShadow:s?"0 0 0 1px #F59E0B30":void 0},children:[r.jsx("textarea",{ref:m,value:t,onChange:ee=>n(ee.target.value),onKeyDown:ee=>{ee.key==="Enter"&&!ee.shiftKey&&(ee.preventDefault(),Y())},onFocus:()=>i(!0),onBlur:()=>i(!1),placeholder:"Talk to your COO...",disabled:F.isPending,rows:1,className:"flex-1 bg-transparent text-[14px] text-[#F0F0F5] placeholder:text-[#8A8A99]/60 resize-none outline-none leading-relaxed max-h-[120px] overflow-y-auto disabled:opacity-50",style:{minHeight:"22px"},onInput:ee=>{const re=ee.currentTarget;re.style.height="auto",re.style.height=`${Math.min(re.scrollHeight,120)}px`}}),r.jsx("button",{onClick:()=>{Y()},disabled:!t.trim()||F.isPending,className:"text-[#8A8A99] hover:text-[#F0F0F5] disabled:opacity-30 transition-colors mb-0.5 flex-shrink-0",children:r.jsx(Ji,{className:"w-4 h-4"})})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]/40 mt-1.5 px-1",children:"Enter to send · Shift+Enter for newline"})]})]}),r.jsx(Me,{children:a&&w&&r.jsx($N,{agent:w,agentColor:zd,onClose:()=>o(!1),onOverrideSet:()=>{}})})]})}function tDe({proposalId:e,data:t,serverStatus:n}){const[s,i]=y.useState(null),o=s??(n==="approved"||n==="failed"?"approved":n==="rejected"?"rejected":null),l=L.useUtils(),c=L.coo.approveFederationGrant.useMutation({onSuccess:()=>{i("approved"),l.federation.listNodes.invalidate(),l.coo.listProposals.invalidate()}}),d=L.coo.rejectFederationGrant.useMutation({onSuccess:()=>{i("rejected"),l.coo.listProposals.invalidate()}}),f=c.isPending||d.isPending;return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#6366F1]/25 rounded-xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center gap-2",children:[r.jsx("div",{className:"w-6 h-6 rounded-lg bg-[#6366F1]/15 flex items-center justify-center",children:r.jsx(Wl,{className:"w-3 h-3 text-[#6366F1]"})}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Federation Grant"}),r.jsxs("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded bg-[#6366F1]/15 text-[#818CF8]",children:[t.grantAgentId," → ",t.nodeName]}),o&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",o==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:o})]}),r.jsx("div",{className:"px-5 py-3 border-b border-[#2A2A35]/50 text-[13px] text-[#C8C8D4] leading-relaxed",children:t.reason}),!o&&r.jsxs("div",{className:"px-5 py-3 flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>d.mutate({proposalId:e}),disabled:f,className:"px-4 py-1.5 rounded text-[12px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors disabled:opacity-50",children:"Reject"}),r.jsxs("button",{onClick:()=>c.mutate({proposalId:e}),disabled:f,className:"px-4 py-1.5 rounded bg-[#10B981] text-white text-[12px] font-medium hover:bg-[#0EA472] transition-colors disabled:opacity-50 flex items-center gap-1.5",children:[c.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Fe,{className:"w-3 h-3"}),"Grant Access"]})]})]})}function nDe({proposalId:e,data:t,serverStatus:n}){const[s,i]=y.useState(null),o=s??(n==="approved"||n==="failed"?"approved":n==="rejected"?"rejected":null),l=L.useUtils(),c=L.coo.approveCloudSpawn.useMutation({onSuccess:()=>{i("approved"),l.federation.listNodes.invalidate(),l.coo.listProposals.invalidate()}}),d=L.coo.rejectCloudSpawn.useMutation({onSuccess:()=>{i("rejected"),l.coo.listProposals.invalidate()}}),f=c.isPending||d.isPending;return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#10B981]/25 rounded-xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center gap-2",children:[r.jsx("div",{className:"w-6 h-6 rounded-lg bg-[#10B981]/15 flex items-center justify-center",children:r.jsx(Xt,{className:"w-3 h-3 text-[#10B981]"})}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Spawn Cloud Node"}),r.jsx("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded bg-[#10B981]/15 text-[#34D399]",children:t.name}),r.jsxs("span",{className:"text-[10px] text-[#8A8A99]",children:[t.provider," · ",t.region," · ",t.size]}),o&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",o==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:o})]}),r.jsx("div",{className:"px-5 py-3 border-b border-[#2A2A35]/50 text-[13px] text-[#C8C8D4] leading-relaxed",children:t.reason}),!o&&r.jsxs("div",{className:"px-5 py-3 flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#10B981]",children:"This will provision a Hetzner VPS (billable)"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>d.mutate({proposalId:e}),disabled:f,className:"px-4 py-1.5 rounded text-[12px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors disabled:opacity-50",children:"Reject"}),r.jsxs("button",{onClick:()=>c.mutate({proposalId:e}),disabled:f,className:"px-4 py-1.5 rounded bg-[#10B981] text-white text-[12px] font-medium hover:bg-[#0EA472] transition-colors disabled:opacity-50 flex items-center gap-1.5",children:[c.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Xt,{className:"w-3 h-3"}),"Approve & Provision"]})]})]})]})}function sDe({plan:e,messageId:t,decided:n}){const s=an(),i=L.useUtils(),a=L.coo.approveMissionPlan.useMutation({onSuccess:()=>{i.missions.list.invalidate(),i.missions.stats.invalidate(),s("/missions")}}),o=L.coo.rejectMissionPlan.useMutation(),c={low:"#5A5A6E",normal:"#8A8A99",high:"#F59E0B",critical:"#EF4444"}[e.priority??"normal"]??"#8A8A99";return r.jsxs("div",{className:"mt-3 rounded-lg border border-[#2A2A35] bg-[#13131A] overflow-hidden",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35]/50 flex items-center gap-3",children:[r.jsx(a0,{className:"w-4 h-4 text-[#6366F1]"}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5] flex-1",children:e.title}),r.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-medium",style:{color:c,backgroundColor:c+"15"},children:e.priority??"normal"})]}),e.description&&r.jsx("p",{className:"px-4 py-2 text-[12px] text-[#8A8A99] border-b border-[#2A2A35]/30",children:e.description}),r.jsx("div",{className:"px-4 py-2 space-y-1.5",children:e.tasks.map((d,f)=>r.jsxs("div",{className:"flex items-center gap-2.5 py-1 px-2.5 rounded bg-[#0F0F11]/50",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] font-mono w-4 text-right",children:d.order}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#3A3A45]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] flex-1 truncate",children:d.title}),d.agentId&&r.jsx("span",{className:"text-[11px] text-[#8A8A99] bg-[#1E1E28] px-1.5 py-0.5 rounded",children:d.agentId}),d.dependsOn&&d.dependsOn.length>0&&r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:["after ",d.dependsOn.join(", ")]})]},f))}),r.jsx("div",{className:"px-4 py-3 border-t border-[#2A2A35]/50 flex items-center gap-2",children:n==="approved"?r.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] text-[#10B981]",children:[r.jsx(Fe,{className:"w-3.5 h-3.5"})," Mission created"]}):n==="rejected"?r.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] text-[#EF4444]",children:[r.jsx(Te,{className:"w-3.5 h-3.5"})," Plan rejected"]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>a.mutate({messageId:t}),disabled:a.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E6] transition-colors disabled:opacity-50",children:[a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Fe,{className:"w-3 h-3"}),"Create Mission"]}),r.jsx("button",{onClick:()=>o.mutate({messageId:t}),disabled:o.isPending,className:"px-3 py-1.5 rounded-md text-[12px] text-[#8A8A99] hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors",children:"Reject"})]})})]})}function _W({text:e}){const[t,n]=y.useState(!1);return r.jsx(bt,{label:t?"Copied":"Copy",children:r.jsx("button",{onClick:()=>{navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)},className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5 transition-colors",children:t?r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"}):r.jsx(Po,{className:"w-3.5 h-3.5"})})})}function fb({code:e,label:t}){return r.jsxs("div",{className:"mt-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99] font-medium",children:t}),r.jsx(_W,{text:e})]}),r.jsx("pre",{className:"bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[11px] font-mono text-[#C8C8D4] overflow-x-auto whitespace-pre-wrap break-all",children:e})]})}function iDe(){const[e,t]=y.useState(!1),{data:n,isLoading:s}=L.mcp.getToken.useQuery(),i=L.useUtils(),a=L.mcp.regenerateToken.useMutation({onSuccess:()=>{i.mcp.getToken.invalidate()}});if(s||!n)return r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4",children:"Loading..."});const{token:o,serverPath:l}=n,c=o.slice(0,8)+"•".repeat(24)+o.slice(-8);return r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-[14px] font-semibold text-[#F0F0F5] mb-1",children:"MCP Server"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Connect external AI harnesses (Claude Code, Codex, Cursor) to your agent's identity, memory, and governance."})]}),r.jsxs("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-xl p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(Ti,{className:"w-4 h-4 text-[#6366F1]"}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Auth Token"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("code",{className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[12px] font-mono text-[#8A8A99] overflow-hidden",children:e?o:c}),r.jsx(bt,{label:e?"Hide":"Reveal",children:r.jsx("button",{onClick:()=>t(d=>!d),className:"w-8 h-8 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5 transition-colors",children:e?r.jsx(R5,{className:"w-4 h-4"}):r.jsx(xv,{className:"w-4 h-4"})})}),r.jsx(_W,{text:o}),r.jsx(bt,{label:"Regenerate",children:r.jsx("button",{onClick:()=>a.mutate(),disabled:a.isPending,className:"w-8 h-8 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#F59E0B] hover:bg-[#F59E0B]/10 transition-colors disabled:opacity-50",children:r.jsx(Xi,{className:`w-4 h-4 ${a.isPending?"animate-spin":""}`})})})]}),a.isSuccess&&r.jsx("p",{className:"text-[11px] text-[#F59E0B] mt-2",children:"Token regenerated. Update your harness configs."})]}),r.jsxs("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-xl p-4",children:[r.jsx("h4",{className:"text-[13px] font-medium text-[#F0F0F5] mb-3",children:"Setup Instructions"}),r.jsx(fb,{label:"Claude Code",code:`claude mcp add damn-dev -e DAMNDEV_TOKEN=${o} -- node ${l}`}),r.jsx(fb,{label:"Codex",code:`codex mcp add damn-dev --env DAMNDEV_TOKEN=${o} -- node ${l}`}),r.jsx(fb,{label:"Cursor (.cursor/mcp.json)",code:JSON.stringify({mcpServers:{"damn-dev":{command:"node",args:[l],env:{DAMNDEV_TOKEN:o}}}},null,2)})]}),r.jsxs("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-xl p-4",children:[r.jsx("h4",{className:"text-[13px] font-medium text-[#F0F0F5] mb-2",children:"Project Binding"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99] mb-3",children:["Create a ",r.jsx("code",{className:"text-[#C8C8D4] bg-[#0F0F11] px-1 rounded",children:".damndev.json"})," in your project root to auto-bind an agent:"]}),r.jsx(fb,{label:".damndev.json",code:JSON.stringify({agent:"your-agent-id",workspace:"default"},null,2)})]})]})}function rDe({entry:e,onDelete:t,onSave:n,onMoveToSecrets:s}){const[i,a]=y.useState(!1),[o,l]=y.useState(!1),[c,d]=y.useState(e.value),[f,p]=y.useState(!1);function m(){n(e.key,c.trim()),l(!1),p(!0),setTimeout(()=>p(!1),1500)}return r.jsxs("div",{className:"flex items-start gap-4 py-4 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:e.key}),e.label!==e.key&&r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:e.label}),f&&r.jsxs(ne.span,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0},className:"flex items-center gap-1 text-[11px] text-[#10B981]",children:[r.jsx(Fe,{className:"w-3 h-3"}),"Saved"]})]}),o?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{autoFocus:!0,type:"text",value:c,onChange:g=>d(g.target.value),onKeyDown:g=>{g.key==="Enter"&&m(),g.key==="Escape"&&(l(!1),d(e.value))},className:"flex-1 bg-[#13131A] border border-[#6366F1]/40 rounded-lg px-3 py-1.5 text-[13px] text-[#F0F0F5] font-mono outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("button",{onClick:m,className:"px-3 py-1.5 rounded-lg bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E8] transition-colors",children:"Save"}),r.jsx("button",{onClick:()=>{l(!1),d(e.value)},className:"px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})]}):r.jsx("button",{onClick:()=>l(!0),className:"flex items-center gap-2 group",children:r.jsx("code",{className:"text-[12px] font-mono text-[#8A8A99] group-hover:text-[#C8C8D4] transition-colors",children:i?e.value:e.masked})})]}),e.key==="GITHUB_TOKEN"&&r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://github.com/settings/tokens/new?scopes=repo&description=damn.dev",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Generate a token on GitHub ",r.jsx(cs,{className:"w-3 h-3"})]}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Scopes are pre-filled — just click Generate and paste it here."}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Set expiration to 'No expiration' for uninterrupted access."})]}),e.key==="GITLAB_TOKEN"&&r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://gitlab.com/-/user_settings/personal_access_tokens?name=damn.dev&scopes=api",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Generate a token on GitLab ",r.jsx(cs,{className:"w-3 h-3"})]}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Scopes are pre-filled — just click Create and paste it here."})]}),r.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.misplaced&&s&&r.jsx(bt,{label:"This is a credential — encrypt it in Secrets. The env copy stays in place as a mirror so nothing breaks.",children:r.jsx("button",{onClick:()=>s(e.key),className:"flex items-center gap-1 px-2 h-7 rounded-md text-[11px] font-medium bg-amber-500/10 text-amber-300 hover:bg-amber-500/20 border border-amber-500/20 transition-colors",children:"Encrypt"})}),r.jsx(bt,{label:i?"Hide":"Reveal",children:r.jsx("button",{onClick:()=>a(g=>!g),className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5 transition-colors",children:i?r.jsx(R5,{className:"w-3.5 h-3.5"}):r.jsx(xv,{className:"w-3.5 h-3.5"})})}),r.jsx(bt,{label:"Delete",children:r.jsx("button",{onClick:()=>t(e.key),className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]})]})}function aDe({knownKeys:e,existingKeys:t,onAdd:n,onClose:s}){const[i,a]=y.useState(""),[o,l]=y.useState(""),[c,d]=y.useState(""),f=i==="__custom__",p=f?o.trim():i;function m(){!p||!c.trim()||(n(p,c.trim()),s())}const g=e.filter(b=>!t.includes(b.key));return r.jsxs(ne.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"bg-[#16161A] border border-[#2A2A35] rounded-xl p-5 mb-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-4",children:"Add API Key"}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Key name"}),r.jsxs(ss,{value:i,onValueChange:a,children:[r.jsxs(is,{className:"flex items-center justify-between w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/60 transition-colors",children:[r.jsx(Ds,{placeholder:"Select a key..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl z-50 overflow-hidden",children:r.jsxs(os,{className:"p-1",children:[g.map(b=>r.jsx(vn,{value:b.key,className:"flex items-center px-3 py-2 text-[13px] text-[#C8C8D4] rounded-md cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:r.jsx(yn,{children:b.key})},b.key)),r.jsx(vn,{value:"__custom__",className:"flex items-center px-3 py-2 text-[13px] text-[#8A8A99] rounded-md cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:r.jsx(yn,{children:"Custom key..."})})]})})})]})]}),f&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Custom key name"}),r.jsx("input",{autoFocus:!0,value:o,onChange:b=>l(b.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")),placeholder:"MY_API_KEY",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Value"}),r.jsx("input",{value:c,onChange:b=>d(b.target.value),onKeyDown:b=>{b.key==="Enter"&&m()},placeholder:"Paste your key...",type:"password",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"}),p==="GITHUB_TOKEN"&&r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://github.com/settings/tokens/new?scopes=repo&description=damn.dev",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Generate a token on GitHub ",r.jsx(cs,{className:"w-3 h-3"})]}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Scopes are pre-filled — just click Generate and paste it here."}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Set expiration to 'No expiration' for uninterrupted access."})]}),p==="GITLAB_TOKEN"&&r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://gitlab.com/-/user_settings/personal_access_tokens?name=damn.dev&scopes=api",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Generate a token on GitLab ",r.jsx(cs,{className:"w-3 h-3"})]}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Scopes are pre-filled — just click Create and paste it here."})]})]}),r.jsxs("div",{className:"flex gap-2 pt-1",children:[r.jsx("button",{onClick:m,disabled:!p||!c.trim(),className:"flex-1 px-4 py-2 rounded-lg bg-[#6366F1] text-white text-[13px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:"Add key"}),r.jsx("button",{onClick:s,className:"px-4 py-2 rounded-lg text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})]})]})]})}function wW({onSelect:e}){const{data:t=[],isLoading:n,refetch:s}=L.settings.detectObsidianVaults.useQuery(void 0,{staleTime:1/0,enabled:!1}),[i,a]=y.useState(!1);function o(){s().then(()=>a(!0))}return r.jsx("div",{className:"mt-3",children:i?t.length===0?r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"No Obsidian vaults detected."}):r.jsx("div",{className:"flex flex-wrap gap-2",children:t.map(l=>r.jsx("button",{onClick:()=>e(l.path),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] bg-white/[0.03] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:l.name},l.path))}):r.jsxs("button",{onClick:o,disabled:n,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:[r.jsx(lh,{className:`w-3 h-3 ${n?"animate-spin":""}`}),"Detect Obsidian vaults"]})})}function oDe({open:e,onClose:t,onSelect:n}){const[s,i]=y.useState(void 0),{data:a,isLoading:o}=L.settings.listDirectory.useQuery({path:s},{enabled:e}),l=a?.entries??[],c=a?.error,d=s?.split("/").filter(Boolean)??[];function f(g){i(g)}function p(g){const b="/"+d.slice(0,g+1).join("/");i(b)}function m(){s&&(n(s),t())}return r.jsx(ji,{open:e,onOpenChange:g=>{g||t()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-40"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[520px] max-h-[70vh] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl z-50 flex flex-col",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsx(nr,{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Browse folders"}),r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})})]}),r.jsxs("div",{className:"px-5 py-2 border-b border-[#2A2A35] flex items-center gap-1 text-[12px] overflow-x-auto flex-shrink-0",children:[r.jsx("button",{onClick:()=>i(void 0),className:"text-[#6366F1] hover:text-[#818CF8] transition-colors flex-shrink-0",children:"Home"}),d.map((g,b)=>r.jsxs("span",{className:"flex items-center gap-1 flex-shrink-0",children:[r.jsx(Jt,{className:"w-3 h-3 text-[#5A5A6E]"}),r.jsx("button",{onClick:()=>p(b),className:"text-[#6366F1] hover:text-[#818CF8] transition-colors",children:g})]},b))]}),s&&r.jsx("div",{className:"px-5 py-1.5 border-b border-[#2A2A35] flex-shrink-0",children:r.jsx("code",{className:"text-[11px] font-mono text-[#5A5A6E]",children:s})}),r.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2 min-h-[200px]",children:o?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(Pe,{className:"w-5 h-5 text-[#6366F1] animate-spin"})}):c&&l.length===0?r.jsx("div",{className:"flex items-center justify-center py-12 text-[12px] text-[#5A5A6E]",children:c}):l.length===0?r.jsx("div",{className:"flex items-center justify-center py-12 text-[12px] text-[#5A5A6E]",children:"No folders found"}):r.jsxs("div",{className:"space-y-0.5",children:[l.map(g=>r.jsxs("button",{onClick:()=>f(g.path),className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-left hover:bg-white/5 transition-colors group",children:[r.jsx(vm,{className:"w-4 h-4 text-[#6366F1]/70 group-hover:text-[#6366F1] flex-shrink-0"}),r.jsx("span",{className:"text-[13px] text-[#C8C8D4] group-hover:text-[#F0F0F5] truncate",children:g.name})]},g.path)),c&&l.length>0&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] px-3 pt-2",children:c})]})}),r.jsxs("div",{className:"px-5 py-3 border-t border-[#2A2A35] flex items-center justify-end gap-2 flex-shrink-0",children:[r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})}),r.jsx("button",{onClick:m,disabled:!s,className:"px-3 py-1.5 rounded-lg bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:"Select this folder"})]})]})]})})}const sO=[{hostPath:"~/Documents",mountPath:"/host/documents",label:"Documents"},{hostPath:"~/Desktop",mountPath:"/host/desktop",label:"Desktop"},{hostPath:"~/Downloads",mountPath:"/host/downloads",label:"Downloads"},{hostPath:"~/Projects",mountPath:"/host/projects",label:"Projects"}];function lDe(){const[e,t]=y.useState(!1),[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(""),[c,d]=y.useState(!1),[f,p]=y.useState(!1),[m,g]=y.useState(""),[b,_]=y.useState(!1),[w,A]=y.useState(!1),[S,C]=y.useState(!1),[E,k]=y.useState(""),T=L.useUtils(),{data:F}=L.settings.getVolumeMounts.useQuery(),{data:M}=L.settings.getDockerComposeSnippet.useQuery(),{data:I}=L.settings.getRunMode.useQuery(),R=L.settings.addVolumeMount.useMutation({onSuccess:D=>{if(!D.ok&&D.error){g(D.error);return}T.settings.getVolumeMounts.invalidate(),T.settings.getDockerComposeSnippet.invalidate(),t(!1),s(""),a(""),l(""),g(""),_(!0)}}),H=L.settings.removeVolumeMount.useMutation({onSuccess:()=>{T.settings.getVolumeMounts.invalidate(),T.settings.getDockerComposeSnippet.invalidate(),_(!0)}}),V=L.settings.applyMountsAndRestart.useMutation({onSuccess:D=>{D.success?(_(!1),C(!0),k(!D.containerFound||!D.composeEdited?D.reason:""),setTimeout(()=>C(!1),3e3)):k(D.reason)}}),K=F?.mounts??[],q=I?.backendIsNative??!1,$=M?.snippet??"";function B(D){s(D),g("");const Q=D.split("/").pop()?.toLowerCase().replace(/[^a-z0-9_-]/g,"")??"";Q&&(a(`/host/${Q}`),l(D.split("/").pop()??Q)),t(!0)}function Y(D){s(D),g("");const Q=D.replace(/^~\//,"").split("/").pop()?.toLowerCase().replace(/[^a-z0-9_-]/g,"")??"";Q&&(a(`/host/${Q}`),l(D.replace(/^~\//,"").split("/").pop()??Q))}function U(){!n.trim()||!i.trim()||!o.trim()||(g(""),R.mutate({hostPath:n.trim(),mountPath:i.trim(),label:o.trim()}))}function W(){navigator.clipboard.writeText($.replace(/\\n/g,`
427
+ value: \${EXAMPLE_API_KEY}`}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-2 leading-relaxed",children:["Auth types: ",r.jsx("code",{className:"text-[#8A8A99]",children:"bearer"}),", ",r.jsx("code",{className:"text-[#8A8A99]",children:"header"})," (add ",r.jsx("code",{className:"text-[#8A8A99]",children:"header: X-Name"}),"), ",r.jsx("code",{className:"text-[#8A8A99]",children:"query"})," (add ",r.jsx("code",{className:"text-[#8A8A99]",children:"query: api_key"}),"). Set ",r.jsx("code",{className:"text-[#8A8A99]",children:"requires_approval: true"})," for destructive calls."]})]})})]})}function CRe({onClose:e,onSuccess:t}){const[n,s]=y.useState("pick"),[i,a]=y.useState(null),[o,l]=y.useState(null),[c,d]=y.useState(null),f=y.useRef(null),p=L.skillPackImport.preview.useMutation(),m=L.skillPackImport.confirm.useMutation(),g=y.useCallback(async _=>{if(!_.name.endsWith(".damnpack")){l("Please select a .damnpack file"),s("error");return}if(_.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const w=new FormData;w.append("file",_);const A=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:w,credentials:"include"});if(!A.ok){const E=await A.json().catch(()=>({error:"Upload failed"}));throw new Error(E.error||`Upload failed (${A.status})`)}const{uploadId:S}=await A.json(),C=await p.mutateAsync({uploadId:S});a(C),s("preview")}catch(w){l(w instanceof Error?w.message:"Upload failed"),s("error")}},[p]);async function b(){if(i){s("confirming");try{const _=await m.mutateAsync({previewId:i.previewId});d(_),s("done")}catch(_){l(_ instanceof Error?_.message:"Install failed"),s("error")}}}return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:e,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},onClick:_=>_.stopPropagation(),className:"relative w-full max-w-md bg-[#16161A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:n==="done"?"Skills installed":"Import skill pack"}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"p-5",children:[n==="pick"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("button",{onClick:()=>f.current?.click(),className:"w-full py-10 rounded-xl border-2 border-dashed border-[#2A2A35] hover:border-[#6366F1]/50 transition-colors flex flex-col items-center gap-3 group",children:[r.jsx(su,{className:"w-8 h-8 text-[#5A5A6E] group-hover:text-[#6366F1] transition-colors"}),r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-medium",children:"Choose .damnpack skill pack"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Max 100MB"})]})]}),r.jsx("input",{ref:f,type:"file",accept:".damnpack",className:"hidden",onChange:_=>{const w=_.target.files?.[0];w&&g(w)}})]}),(n==="uploading"||n==="confirming")&&r.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[r.jsx(Pe,{className:"w-8 h-8 text-[#6366F1] animate-spin"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:n==="uploading"?"Scanning skill pack...":"Installing skills..."})]}),n==="error"&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-4 py-3",children:r.jsx("p",{className:"text-[13px] text-[#FCA5A5]",children:o})}),r.jsx("button",{onClick:()=>{s("pick"),l(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),n==="preview"&&i&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#6366F1]/15 border border-[#6366F1]/25 flex items-center justify-center",children:r.jsx(vv,{className:"w-5 h-5 text-[#818CF8]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.version," by"," ",i.publisherUrl?r.jsxs("a",{href:i.publisherUrl,target:"_blank",rel:"noopener noreferrer",className:"text-[#818CF8] hover:underline inline-flex items-center gap-0.5",children:[i.publisher,r.jsx(cs,{className:"w-2.5 h-2.5"})]}):i.publisher]})]})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.summary}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:[i.skills.length," skill",i.skills.length!==1?"s":""]}),r.jsx("div",{className:"space-y-2",children:i.skills.map(_=>r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] px-3 py-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-0.5",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:_.name}),r.jsxs("div",{className:"flex items-center gap-2",children:[_.toolCount>0&&r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:[_.toolCount," tool",_.toolCount!==1?"s":""]}),_.exists&&r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20",children:"Update"})]})]}),r.jsx("p",{className:"text-[11px] text-[#6A6A7A] line-clamp-2",children:_.description})]},_.slug))})]}),i.missingSecrets.length>0&&(()=>{const _=i.missingSecrets.filter(A=>!A.default),w=i.missingSecrets.filter(A=>!!A.default);return r.jsxs("div",{className:"space-y-2",children:[w.length>0&&r.jsxs("div",{className:"rounded-lg bg-emerald-500/10 border border-emerald-500/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-emerald-400 flex items-center gap-1.5",children:[r.jsx(Fe,{className:"w-3.5 h-3.5"}),"Auto-configured"]}),r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:w.map(A=>r.jsx("code",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono text-emerald-400 bg-emerald-500/15 border border-emerald-500/20",children:A.key},A.key))})]}),_.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1.5",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(Eo,{className:"w-3.5 h-3.5"}),"Required workspace secrets"]}),r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80",children:"You'll need to add these in Settings after installing:"}),r.jsx("div",{className:"space-y-1 mt-1.5",children:_.map(A=>r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("code",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono text-[#FCD34D] bg-[#F59E0B]/15 border border-[#F59E0B]/20 flex-shrink-0",children:A.key}),r.jsx("span",{className:"text-[10px] text-[#FCD34D]/60 leading-tight",children:A.description})]},A.key))})]})]})})(),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsx("button",{onClick:b,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Install All"}),r.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),n==="done"&&c&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-emerald-500/15 border border-emerald-500/25 flex items-center justify-center",children:r.jsx(Fe,{className:"w-5 h-5 text-emerald-400"})}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:[c.total," skill",c.total!==1?"s":""," installed"]}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c.installed.length>0&&`${c.installed.length} new`,c.installed.length>0&&c.updated.length>0&&", ",c.updated.length>0&&`${c.updated.length} updated`]})]})]}),c.autoPopulated.length>0&&r.jsx("div",{className:"rounded-lg bg-emerald-500/10 border border-emerald-500/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-emerald-400",children:["Auto-configured: ",c.autoPopulated.join(", ")]})}),i&&i.missingSecrets.some(_=>!_.default)&&r.jsxs(gn,{to:"/settings?tab=secrets",className:"flex items-center justify-center gap-1.5 w-full py-2 rounded-lg text-[12px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] hover:bg-[#F59E0B]/20 border border-[#F59E0B]/30 transition-colors",children:[r.jsx(Eo,{className:"w-3.5 h-3.5"}),"Add missing secrets in Settings"]}),r.jsx("button",{onClick:()=>{t(),e()},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}const jRe={secretsoss:"#6366F1",lifelog:"#10B981",chut:"#F59E0B",custom:"#6B7280",clawhub:"#8B5CF6"};function NRe(e){return jRe[e]??"#6B7280"}function yW({provider:e}){const t=NRe(e),n=e==="secretsoss"?"SecretSoss":e==="lifelog"?"Lifelog":e==="chut"?"Chut.co":e;return r.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-md text-[11px] font-medium",style:{backgroundColor:`${t}20`,color:t,border:`1px solid ${t}40`},children:n})}function nO({onConfirm:e,onRemove:t}){const[n,s]=y.useState(!1);return r.jsxs(Ys,{open:n,onOpenChange:s,children:[r.jsx(ci,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-white/5 text-[#8A8A99] hover:bg-red-500/10 hover:text-red-400 border border-[#2A2A35] hover:border-red-500/30 transition-colors",children:"Uninstall"})}),r.jsx(Qs,{children:r.jsxs(Xs,{side:"top",align:"end",sideOffset:6,className:ye("z-50 bg-[#1C1C24] border border-[#2A2A35] rounded-xl p-4 shadow-2xl",t?"w-64":"w-56"),children:[r.jsx("p",{className:"text-[12px] text-[#C8C8D4] mb-3 leading-relaxed",children:t?"Uninstall from agents, or remove entirely?":"This will remove the skill from all agents. Continue?"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>s(!1),className:"flex-1 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"}),r.jsx("button",{onClick:()=>{e(),s(!1)},className:"flex-1 py-1.5 rounded-lg text-[12px] text-amber-400 hover:text-amber-300 bg-amber-500/10 hover:bg-amber-500/20 border border-amber-500/30 transition-colors",children:"Uninstall"}),t&&r.jsxs("button",{onClick:()=>{t(),s(!1)},className:"py-1.5 px-2.5 rounded-lg text-[12px] text-red-400 hover:text-red-300 bg-red-500/10 hover:bg-red-500/20 border border-red-500/30 transition-colors flex items-center gap-1",children:[r.jsx(Dn,{className:"w-3 h-3"}),"Remove"]})]}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]})}function kRe({skill:e,isInstalled:t,onInstall:n,onUninstall:s,onRemove:i,onEdit:a,onDelete:o,onClick:l,selected:c,canManage:d=!0}){return r.jsxs(ne.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},onClick:l,className:ye("bg-[#16161A] border rounded-2xl p-5 cursor-pointer transition-colors relative overflow-hidden",c?"border-[#6366F1]/50 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] hover:border-[#3A3A45]"),children:[r.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx(yW,{provider:e.source==="custom"||e.source==="authored"?"custom":e.provider}),e.requiresApproval&&r.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/30",children:[r.jsx(_m,{className:"w-3 h-3"}),"Approval required"]})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[d&&(e.source==="custom"||e.source==="authored")&&a&&r.jsx("button",{onClick:f=>{f.stopPropagation(),a()},className:"w-6 h-6 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(O5,{className:"w-3 h-3"})}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:["v",e.version]})]})]}),r.jsx("h3",{className:"text-[14px] font-semibold text-[#F0F0F5] mb-1",children:e.name}),r.jsx("p",{className:"text-[12px] text-[#6A6A7A] leading-relaxed line-clamp-2 mb-4",children:e.description}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:t?"Installed":"Not installed"}),d&&r.jsxs("div",{className:"flex items-center gap-2",onClick:f=>f.stopPropagation(),children:[(e.source==="custom"||e.source==="authored")&&o&&r.jsx(nO,{onConfirm:o}),t?e.source!=="custom"&&r.jsx(nO,{onConfirm:s,onRemove:i}):r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:n,className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 border border-[#6366F1]/30 transition-colors",children:"Install"}),i&&r.jsx("button",{onClick:i,className:"w-7 h-7 flex items-center justify-center rounded-lg text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 border border-[#2A2A35] hover:border-red-500/30 transition-colors",children:r.jsx(Dn,{className:"w-3 h-3"})})]})]})]})]})}function ERe({agent:e,skillId:t,agentSkill:n}){const s=L.useUtils(),i=L.skills.toggleAgentSkill.useMutation({onSuccess:()=>{s.skills.getAgentSkills.invalidate()}});return r.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-base flex-shrink-0",style:{backgroundColor:`${e.color}26`},children:e.emoji}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:e.name}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:e.role})]})]}),r.jsx(Sh,{checked:n?.enabled??!1,onCheckedChange:a=>i.mutate({agentId:e.id,skillId:t,enabled:a}),className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35] disabled:opacity-40 disabled:cursor-not-allowed",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]})}function FRe(e,t){const n=e.map(s=>L.skills.getAgentSkills.useQuery({agentId:s.id}));return e.map((s,i)=>({agent:s,agentSkill:n[i].data?.find(a=>a.skillId===t)}))}function TRe({varName:e}){const t=L.useUtils(),{data:n=[]}=L.settings.getEnvVars.useQuery(),{data:s=[]}=L.secrets.listKeys.useQuery(),{data:i=[]}=L.settings.getKnownKeys.useQuery(),a=i.find(k=>k.key===e)?.kind,o=a===void 0||a==="secret",l=L.settings.setEnvVar.useMutation({onSuccess:()=>{t.settings.getEnvVars.invalidate()}}),c=L.settings.deleteEnvVar.useMutation({onSuccess:()=>{t.settings.getEnvVars.invalidate()}}),d=L.secrets.set.useMutation({onSuccess:()=>{t.secrets.listKeys.invalidate(),t.secrets.list.invalidate()}}),f=n.find(k=>k.key===e),p=s.includes(e),m=!!f||p,[g,b]=y.useState(!1),[_,w]=y.useState(""),[A,S]=y.useState(!1);function C(){const k=_.trim();k&&(o?(d.mutate({key:e,value:k}),f&&c.mutate({key:e})):l.mutate({key:e,value:k}),b(!1),w(""))}const E=l.isPending||d.isPending;return r.jsxs("div",{className:"py-3 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("span",{className:"text-[12px] font-mono text-[#C8C8D4]",children:e}),m?r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[#10B981]",children:[r.jsx(Fe,{className:"w-3 h-3"}),"Configured"]}):r.jsx("span",{className:"text-[11px] text-[#F87171]",children:"Missing"})]}),g?r.jsxs("div",{className:"flex gap-2 mt-2",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx("input",{type:A?"text":"password",value:_,onChange:k=>w(k.target.value),onKeyDown:k=>{k.key==="Enter"&&C()},placeholder:`Enter ${e}...`,autoFocus:!0,className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-1.5 pr-8 text-[12px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors font-mono"}),r.jsx("button",{onClick:()=>S(!A),className:"absolute right-2 top-1/2 -translate-y-1/2 text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:A?r.jsx(R5,{className:"w-3.5 h-3.5"}):r.jsx(xv,{className:"w-3.5 h-3.5"})})]}),r.jsx("button",{onClick:C,disabled:!_.trim()||E,className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 border border-[#6366F1]/30 transition-colors disabled:opacity-40",children:"Save"}),r.jsx("button",{onClick:()=>{b(!1),w("")},className:"px-2 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}):r.jsx("button",{onClick:()=>b(!0),className:"text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors mt-1",children:m?"Update":"Set value"})]})}function MRe({skill:e,agents:t,onClose:n}){const[s,i]=y.useState("info"),a=L.useUtils(),o=FRe(t,e.id),l=L.skills.toggleAgentSkill.useMutation({onMutate:async({agentId:m,skillId:g,enabled:b})=>{await a.skills.getAgentSkills.cancel({agentId:m});const _=a.skills.getAgentSkills.getData({agentId:m});return a.skills.getAgentSkills.setData({agentId:m},w=>w?.map(A=>A.agentId===m&&A.skillId===g?{...A,enabled:b}:A)),{prev:_}},onError:(m,{agentId:g},b)=>{b?.prev&&a.skills.getAgentSkills.setData({agentId:g},b.prev)}}),{data:c=[]}=L.skills.getSkillEnvVars.useQuery({skillId:e.id}),{data:d}=L.skills.getSkillContent.useQuery({skillId:e.id}),f=o.length>0&&o.every(m=>m.agentSkill?.enabled);function p(){const m=!f;o.forEach(({agent:g})=>{l.mutate({agentId:g.id,skillId:e.id,enabled:m})})}return r.jsxs(r.Fragment,{children:[r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-40",style:{backdropFilter:"blur(2px)",backgroundColor:"rgba(0,0,0,0.25)"},onClick:n}),r.jsxs(ne.div,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.3,ease:[.16,1,.3,1]},className:"fixed right-0 top-0 h-screen w-[380px] bg-[#13131A] border-l border-[#2A2A35] flex flex-col z-50 shadow-2xl",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{children:[r.jsx("div",{className:"mb-0.5",children:r.jsx(yW,{provider:e.provider})}),r.jsx("p",{className:"text-[15px] font-semibold text-[#F0F0F5] mt-1",children:e.name})]}),r.jsx("button",{onClick:n,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex border-b border-[#2A2A35] flex-shrink-0",children:[r.jsx("button",{onClick:()=>i("info"),className:ye("flex-1 py-2.5 text-[12px] font-medium transition-colors border-b-2 -mb-px",s==="info"?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:"Info"}),r.jsx("button",{onClick:()=>i("agents"),className:ye("flex-1 py-2.5 text-[12px] font-medium transition-colors border-b-2 -mb-px",s==="agents"?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:"Agents"}),r.jsxs("button",{onClick:()=>i("keys"),className:ye("flex-1 py-2.5 text-[12px] font-medium transition-colors border-b-2 -mb-px",s==="keys"?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:["Secrets",c.length>0?` (${c.length})`:""]})]}),e.requiresApproval&&s==="agents"&&r.jsxs("div",{className:"mx-5 mt-4 px-3 py-2.5 rounded-lg bg-amber-500/[0.08] border border-amber-500/20 flex items-start gap-2",children:[r.jsx(_m,{className:"w-3.5 h-3.5 text-amber-400 flex-shrink-0 mt-0.5"}),r.jsx("p",{className:"text-[12px] text-amber-300/80 leading-relaxed",children:"Agent will ask for your approval before executing this skill."})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[s==="info"&&r.jsxs("div",{className:"space-y-5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Description"}),r.jsx("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:e.description})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Version"}),r.jsxs("p",{className:"text-[13px] text-[#F0F0F5] font-mono",children:["v",e.version]})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Source"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5] capitalize",children:e.source})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Provider"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:e.provider})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Endpoint"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-mono truncate",title:e.endpoint,children:e.endpoint||"—"})]})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Slug"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-mono",children:e.slug})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-1",children:"Installed"}),r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:new Date(e.installedAt).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})})]}),d?.content&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"SKILL.md"}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] font-mono whitespace-pre-wrap leading-relaxed bg-[#0F0F11] border border-[#2A2A35] rounded-lg p-3 max-h-[300px] overflow-y-auto",children:d.content})]})]}),s==="agents"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Agent access"}),o.length>0&&r.jsx("button",{onClick:p,className:"text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:f?"Disable all":"Enable all"})]}),t.length===0&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No agents found."}),o.map(({agent:m,agentSkill:g})=>r.jsx(ERe,{agent:m,skillId:e.id,agentSkill:g},m.id))]}),s==="keys"&&r.jsx(r.Fragment,{children:c.length===0?r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"This skill has no required secrets."}):c.map(m=>r.jsx(TRe,{varName:m},m))})]})]})]})}function RRe(e){const t=e.map(s=>L.skills.getAgentSkills.useQuery({agentId:s.id}));return new Set(t.flatMap(s=>(s.data??[]).map(i=>i.skillId)))}function DRe({skills:e,agents:t,selectedSkillId:n,onInstall:s,onUninstall:i,onRemove:a,onSelect:o,onEditCustom:l,onDeleteCustom:c,canManage:d=!0}){const f=RRe(t);return r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:e.map(p=>r.jsx(kRe,{skill:p,isInstalled:f.has(p.id),onInstall:()=>s(p.id),onUninstall:()=>i(p.id),onRemove:p.source!=="custom"&&p.source!=="authored"?()=>a(p.id):void 0,onEdit:p.source==="custom"||p.source==="authored"?()=>l(p):void 0,onDelete:p.source==="custom"||p.source==="authored"?()=>c(p.id):void 0,onClick:()=>o(n===p.id?null:p),selected:n===p.id,canManage:d},p.id))})}function ORe({result:e,onClose:t,onInstall:n,inspectData:s}){const{data:i,isLoading:a,isError:o}=L.skills.getClawHubSkillContent.useQuery({slug:e.slug},{staleTime:1/0}),l=i?.content?.includes("shell://")||i?.content?.includes("shell_exec")||i?.content?.includes("exec:"),[c,d]=y.useState(!1),f=!a&&!o&&(!l||c);return r.jsx(ji,{open:!0,onOpenChange:p=>{p||t()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-40"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[640px] max-h-[80vh] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl z-50 flex flex-col",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[r.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-md text-[11px] font-medium",style:{backgroundColor:"#8B5CF620",color:"#8B5CF6",border:"1px solid #8B5CF640"},children:e.publisher||"Unknown publisher"}),i?.hasSecurityWarning&&r.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/30",children:[r.jsx(_m,{className:"w-3 h-3"}),"Network activity detected"]})]}),r.jsx(nr,{className:"text-[15px] font-semibold text-[#F0F0F5]",children:e.displayName}),r.jsxs("div",{className:"flex items-center gap-3 mt-1.5",children:[s?.downloads!=null&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[#5A5A6E]",children:[r.jsx(nu,{className:"w-3 h-3"}),s.downloads.toLocaleString()]}),s?.stars!=null&&s.stars>0&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[#5A5A6E]",children:[r.jsx(Ire,{className:"w-3 h-3"}),s.stars]}),e.version&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E]",children:["v",e.version]}),!s?.downloads&&!s?.stars&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E] italic",children:"Unknown — review SKILL.md before installing"})]})]}),r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 min-h-0",children:[a&&r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}),o&&r.jsx("p",{className:"text-[13px] text-red-400",children:"Could not load SKILL.md — check your internet connection."}),i&&r.jsx("pre",{className:"text-[12px] text-[#C8C8D4] font-mono whitespace-pre-wrap leading-relaxed",children:i.content})]}),l&&!c&&r.jsxs("div",{className:"mx-5 mb-3 p-3 rounded-lg bg-red-500/[0.08] border border-red-500/30 flex items-start gap-2.5",children:[r.jsx(Ti,{className:"w-4 h-4 text-red-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[12px] text-red-300 leading-relaxed mb-2",children:"This skill will execute commands on your machine. Only install if you trust the publisher."}),r.jsx("button",{onClick:()=>d(!0),className:"px-3 py-1 rounded-md text-[11px] font-medium bg-red-500/20 text-red-300 hover:bg-red-500/30 border border-red-500/30 transition-colors",children:"I understand the risks"})]})]}),r.jsxs("div",{className:"px-5 py-3 border-t border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Review the skill before installing."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-lg text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})}),r.jsxs("button",{onClick:n,disabled:!f,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-lg bg-[#8B5CF6] text-white text-[13px] font-medium hover:bg-[#7C3AED] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:[r.jsx(nu,{className:"w-3.5 h-3.5"}),"Install"]})]})]})]})]})})}function PRe({result:e,onReviewInstall:t}){return r.jsxs(ne.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 hover:border-[#3A3A45] transition-colors",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[r.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-md text-[11px] font-medium",style:{backgroundColor:"#8B5CF620",color:"#8B5CF6",border:"1px solid #8B5CF640"},children:e.publisher}),e.hasSecurityWarning&&r.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/30",children:[r.jsx(_m,{className:"w-2.5 h-2.5"}),"Network"]}),e.source==="github"&&r.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-white/5 text-[#5A5A6E] border border-[#2A2A35]",children:"archive"})]}),e.installed&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[#10B981] flex-shrink-0",children:[r.jsx(sa,{className:"w-3 h-3"}),"Installed"]})]}),r.jsx("h3",{className:"text-[14px] font-semibold text-[#F0F0F5] mb-1",children:e.displayName}),r.jsx("p",{className:"text-[12px] text-[#6A6A7A] leading-relaxed line-clamp-2 mb-4",children:e.summary||e.slug}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#5A5A6E] font-mono",children:e.slug}),e.installed?r.jsx("span",{className:"px-3 py-1.5 rounded-lg text-[12px] font-medium text-[#10B981] bg-[#10B981]/10 border border-[#10B981]/30",children:"Installed"}):r.jsxs("button",{onClick:()=>t(e),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#8B5CF6]/10 text-[#8B5CF6] hover:bg-[#8B5CF6]/20 border border-[#8B5CF6]/30 transition-colors",children:[r.jsx(cs,{className:"w-3 h-3"}),"Review & Install"]})]})]})}function IRe({requiredEnvVars:e,requiredBins:t,skillName:n,hasSecurityWarning:s,onClose:i}){return y.useEffect(()=>{const a=setTimeout(i,8e3);return()=>clearTimeout(a)},[i]),r.jsxs(ne.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},exit:{opacity:0,y:16},className:"fixed bottom-6 right-6 z-50 w-[380px] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl p-4",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(sa,{className:"w-4 h-4 text-[#10B981] flex-shrink-0"}),r.jsxs("span",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:[n," installed"]})]}),r.jsx("button",{onClick:i,className:"text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),e.length>0&&r.jsxs("div",{className:"mb-2 p-2.5 rounded-lg bg-amber-500/[0.08] border border-amber-500/20 flex items-start gap-2",children:[r.jsx(Rs,{className:"w-3.5 h-3.5 text-amber-400 flex-shrink-0 mt-0.5"}),r.jsx("div",{children:r.jsxs("p",{className:"text-[12px] text-amber-300/80 leading-relaxed",children:["Requires ",e.join(", "),"."," ",r.jsx(gn,{to:"/settings?tab=secrets",onClick:i,className:"underline hover:text-amber-300 transition-colors",children:"Configure in Settings → Secrets"})]})})]}),t.length>0&&r.jsx("div",{className:"p-2.5 rounded-lg bg-blue-500/[0.08] border border-blue-500/20",children:r.jsxs("p",{className:"text-[12px] text-blue-300/80 leading-relaxed",children:["Requires: ",r.jsx("span",{className:"font-mono",children:t.join(", ")})]})}),s&&r.jsxs("div",{className:"p-2.5 rounded-lg bg-amber-500/[0.08] border border-amber-500/20 flex items-start gap-2",children:[r.jsx(_m,{className:"w-3.5 h-3.5 text-amber-400 flex-shrink-0 mt-0.5"}),r.jsx("p",{className:"text-[12px] text-amber-300/80 leading-relaxed",children:"This skill contains network activity patterns. Review the SKILL.md before enabling for agents."})]})]})}function LRe({skills:e}){const[t,n]=y.useState(""),[s,i]=y.useState(""),[a,o]=y.useState(null),[l,c]=y.useState(null),d=y.useRef(null),f=L.useUtils(),p=new Set(e.filter(C=>C.source==="clawhub").map(C=>C.slug));function m(C){n(C),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>i(C),300)}const{data:g=[],isLoading:b,isFetching:_}=L.skills.searchClawHub.useQuery({query:s},{enabled:s.length>0,staleTime:5*6e4}),w=g.map(C=>({...C,installed:p.has(C.slug)})),A=L.skills.inspectClawHub.useQuery({slug:a?.slug??""},{enabled:!!a,staleTime:5*6e4}),S=L.skills.installFromClawHub.useMutation({onSuccess:C=>{f.skills.list.invalidate(),f.skills.getAgentSkills.invalidate(),o(null),c({name:C.skill.name,envVars:C.requiredEnvVars,bins:C.requiredBins,hasSecurityWarning:C.hasSecurityWarning})}});return r.jsxs("div",{children:[r.jsxs("div",{className:"relative mb-6",children:[r.jsx(Io,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[#5A5A6E]"}),r.jsx("input",{value:t,onChange:C=>m(C.target.value),placeholder:"Search ClawHub skills...",className:"w-full bg-[#16161A] border border-[#2A2A35] rounded-xl pl-9 pr-4 py-2.5 text-[13px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#8B5CF6]/60 transition-colors"}),_&&r.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:r.jsx("div",{className:"w-4 h-4 border-2 border-[#8B5CF6]/30 border-t-[#8B5CF6] rounded-full animate-spin"})})]}),b&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[1,2,3,4,5,6].map(C=>r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 animate-pulse h-[180px]"},C))}),!b&&w.length===0&&s&&r.jsx("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:r.jsxs("p",{className:"text-[14px] text-[#8A8A99]",children:['No skills found for "',s,'".']})}),!b&&w.length>0&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:w.map(C=>r.jsx(PRe,{result:C,onReviewInstall:o},`${C.publisher}/${C.slug}`))}),a&&r.jsx(ORe,{result:{...a,publisher:A.data?.publisher??a.publisher??"",version:A.data?.version,hasSecurityWarning:A.data?.hasSecurityWarning??a.hasSecurityWarning},inspectData:A.data?{downloads:A.data.downloads,stars:A.data.stars,tags:A.data.tags}:void 0,onClose:()=>o(null),onInstall:()=>S.mutate({slug:a.slug,publisher:A.data?.publisher??a.publisher??"",displayName:A.data?.displayName??a.displayName,version:A.data?.version??"1.0.0"})}),r.jsx(Me,{children:l&&r.jsx(IRe,{skillName:l.name,requiredEnvVars:l.envVars,requiredBins:l.bins,hasSecurityWarning:l.hasSecurityWarning,onClose:()=>c(null)})})]})}function BRe(){const[e,t]=y.useState("my-skills"),[n,s]=y.useState(""),[i,a]=y.useState(null),[o,l]=y.useState(!1),[c,d]=y.useState(null),[f,p]=y.useState(!1),[m,g]=y.useState(null),[b,_]=y.useState(!1),{data:w=[]}=Vo(),A=L.useUtils(),S=Uo(),{data:C=[],isLoading:E}=L.skills.list.useQuery(),k=L.skills.installForAllAgents.useMutation({onSuccess:()=>A.skills.getAgentSkills.invalidate()}),T=L.skills.uninstallFromAllAgents.useMutation({onSuccess:()=>{A.skills.getAgentSkills.invalidate(),a(null)}}),F=L.skills.uninstallClawHub.useMutation({onSettled:async()=>{await A.skills.list.invalidate(),await A.skills.getAgentSkills.invalidate(),a(null)}}),M=L.skills.deleteCustom.useMutation({onSuccess:()=>{A.skills.list.invalidate(),A.skills.getAgentSkills.invalidate(),a(null)}});function I(V){V.source==="authored"?(g(V.id),p(!0)):(d(V.id),l(!0))}const R=e==="my-skills"?C.filter(V=>{if(!n.trim())return!0;const K=n.toLowerCase();return V.name.toLowerCase().includes(K)||V.slug.toLowerCase().includes(K)||V.description.toLowerCase().includes(K)}):C,H=e==="clawhub";return r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11]",children:[r.jsxs("div",{className:"max-w-5xl mx-auto px-8 py-10",children:[r.jsxs("div",{className:"mb-8 flex items-start justify-between",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"Skills"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mt-0.5",children:"Capabilities your agents can execute. Install a skill to make it available, then assign it per agent."})]}),S&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("button",{onClick:()=>{g(null),p(!0)},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 border border-[#6366F1]/30 transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"New Skill"]}),r.jsxs("button",{onClick:()=>_(!0),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:[r.jsx(su,{className:"w-3.5 h-3.5"}),"Import"]}),r.jsxs(gn,{to:"/settings?tab=secrets",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:[r.jsx(Eo,{className:"w-3.5 h-3.5"}),"Secrets"]})]})]}),r.jsxs("div",{className:"flex items-center gap-1 mb-6 border-b border-[#2A2A35]",children:[r.jsx("button",{onClick:()=>t("my-skills"),className:ye("px-4 py-2.5 text-[13px] font-medium transition-colors border-b-2 -mb-px",e==="my-skills"?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:"My Skills"}),S&&r.jsx("button",{onClick:()=>t("clawhub"),className:ye("px-4 py-2.5 text-[13px] font-medium transition-colors border-b-2 -mb-px",e==="clawhub"?"text-[#F0F0F5] border-[#8B5CF6]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"),children:"Browse ClawHub"})]}),e==="my-skills"&&r.jsxs("div",{className:"relative mb-6",children:[r.jsx(Io,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[#5A5A6E]"}),r.jsx("input",{value:n,onChange:V=>s(V.target.value),placeholder:"Search skills...",className:"w-full bg-[#16161A] border border-[#2A2A35] rounded-xl pl-9 pr-4 py-2.5 text-[13px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"})]}),H?r.jsx(LRe,{skills:C}):r.jsxs(r.Fragment,{children:[E&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[1,2,3,4,5,6].map(V=>r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 animate-pulse h-[180px]"},V))}),!E&&R.length===0&&r.jsx("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:"No skills for this provider yet."})}),!E&&R.length>0&&r.jsx(DRe,{skills:R,agents:w,selectedSkillId:i?.id??null,onInstall:V=>k.mutate({skillId:V}),onUninstall:V=>T.mutate({skillId:V}),onRemove:async V=>{await F.mutateAsync({skillId:V}).catch(()=>{})},onSelect:S?a:()=>{},onEditCustom:I,onDeleteCustom:V=>M.mutate({skillId:V}),canManage:S})]})]}),r.jsx(Me,{children:S&&i&&r.jsx(MRe,{skill:i,agents:w,onClose:()=>a(null)},i.id)}),r.jsx(Me,{children:S&&o&&r.jsx(yRe,{open:o,onClose:()=>{l(!1),d(null)},editSkillId:c,editSkillSlug:c?C.find(V=>V.id===c)?.slug:void 0})}),S&&r.jsx(wRe,{open:f,onClose:()=>{p(!1),g(null)},editSkillId:m}),r.jsx(Me,{children:S&&b&&r.jsx(CRe,{onClose:()=>_(!1),onSuccess:()=>{A.skills.list.invalidate()}})})]})}const zRe=$o()(gj(e=>({model:"anthropic/claude-sonnet-4-6",setModel:t=>e({model:t})}),{name:"damn-dev-coo"})),Hf="chan_coo",zd="#F59E0B";function $Re(e){try{return JSON.parse(e)}catch{return null}}function VRe(e){try{return JSON.parse(e)}catch{return null}}function URe({messageId:e,trustData:t,decided:n,onApprove:s,onReject:i,isApproving:a,isRejecting:o}){return r.jsxs(ne.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"mx-4 mb-2 rounded-xl border border-[#6366F1]/30 bg-[#6366F1]/5 overflow-hidden",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#6366F1]/20",children:[r.jsx("p",{className:"text-[12px] font-semibold text-[#818CF8] uppercase tracking-wide",children:"Trust configuration proposal"}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:["Agent: ",r.jsx("span",{className:"text-[#A5A5C5]",children:t.agentId})]})]}),r.jsxs("div",{className:"px-4 py-3 space-y-2",children:[typeof t.autoApprove=="boolean"&&r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Auto-approve"}),r.jsx("span",{className:t.autoApprove?"text-[#F87171]":"text-[#34D399]",children:t.autoApprove?"Enable":"Disable"})]}),t.sandboxMode&&r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Sandbox"}),r.jsx("span",{className:"text-[#A5A5C5]",children:t.sandboxMode})]}),t.shellAllowlist!==void 0&&r.jsxs("div",{className:"text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Shell allowlist"}),r.jsx("p",{className:"text-[#A5A5C5] mt-0.5",children:t.shellAllowlist?t.shellAllowlist.join(", "):"unrestricted"})]}),t.mounts&&t.mounts.length>0&&r.jsxs("div",{className:"text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Mounts"}),t.mounts.map((l,c)=>r.jsxs("p",{className:"text-[#A5A5C5] mt-0.5 font-mono",children:[l.hostPath," → ",l.agentPath]},c))]})]}),n?r.jsx("div",{className:`px-4 py-2.5 text-[12px] font-medium ${n==="approved"?"text-[#34D399] bg-[#10B981]/5":"text-[#F87171] bg-[#EF4444]/5"}`,children:n==="approved"?"✓ Applied":"✗ Rejected"}):r.jsxs("div",{className:"flex border-t border-[#6366F1]/20",children:[r.jsx(ne.button,{whileHover:{backgroundColor:"rgba(16,185,129,0.12)"},whileTap:{scale:.98},onClick:()=>s(e),disabled:a||o,className:"flex-1 py-2.5 text-[12px] font-medium text-[#34D399] border-r border-[#6366F1]/20 transition-colors disabled:opacity-50",children:a?"Applying…":"Apply"}),r.jsx(ne.button,{whileHover:{backgroundColor:"rgba(239,68,68,0.08)"},whileTap:{scale:.98},onClick:()=>i(e),disabled:a||o,className:"flex-1 py-2.5 text-[12px] font-medium text-[#F87171] transition-colors disabled:opacity-50",children:"Reject"})]})]})}function HRe(e){try{const t=JSON.parse(e);return typeof t.agentId=="string"&&typeof t.pattern=="string"&&typeof t.autoApprove=="boolean"&&typeof t.reason=="string"?t:null}catch{return null}}function WRe({messageId:e,rule:t,decided:n,onApprove:s,onReject:i,isPending:a}){return r.jsxs(ne.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"mx-4 mb-2 rounded-xl border border-[#F59E0B]/30 bg-[#F59E0B]/5 overflow-hidden",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#F59E0B]/20 flex items-center gap-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}),r.jsx("p",{className:"text-[12px] font-semibold text-[#FBBF24] uppercase tracking-wide",children:"Delegation rule proposal"})]}),r.jsxs("div",{className:"px-4 py-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Agent"}),r.jsx("span",{className:"text-[#A5A5C5] font-medium",children:t.agentId})]}),r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Pattern"}),r.jsx("code",{className:"text-[#FBBF24] bg-[#F59E0B]/10 px-1.5 py-0.5 rounded text-[11px] font-mono",children:t.pattern})]}),r.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Auto-approve"}),r.jsx("span",{className:t.autoApprove?"text-[#F87171]":"text-[#34D399]",children:t.autoApprove?"Yes":"No"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] italic leading-relaxed pt-1",children:t.reason})]}),n?r.jsx("div",{className:`px-4 py-2.5 text-[12px] font-medium ${n==="approved"?"text-[#34D399] bg-[#10B981]/5":"text-[#F87171] bg-[#EF4444]/5"}`,children:n==="approved"?"✓ Rule created":"✗ Rejected"}):r.jsxs("div",{className:"flex border-t border-[#F59E0B]/20",children:[r.jsx(ne.button,{whileHover:{backgroundColor:"rgba(16,185,129,0.12)"},whileTap:{scale:.98},onClick:()=>s(e),disabled:a,className:"flex-1 py-2.5 text-[12px] font-medium text-[#34D399] border-r border-[#F59E0B]/20 transition-colors disabled:opacity-50",children:a?"Creating…":"Create Rule"}),r.jsx(ne.button,{whileHover:{backgroundColor:"rgba(239,68,68,0.08)"},whileTap:{scale:.98},onClick:()=>i(e),disabled:a,className:"flex-1 py-2.5 text-[12px] font-medium text-[#F87171] transition-colors disabled:opacity-50",children:"Reject"})]})]})}function qRe({proposal:e,proposalId:t,onApprove:n,onReject:s,isApproving:i,isRejecting:a,decided:o,progressSteps:l,completionResult:c}){const d=an(),[f,p]=y.useState(!1),m=o?!f:f,g=_=>p(o?!_:_),b=e.skillAssignments?.some(_=>_.skills.some(w=>w.includes("approval")));return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>g(!m),className:"w-full px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between hover:bg-white/[0.02] transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Ia,{className:"w-4 h-4 text-[#F59E0B]"}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Workspace Proposal"}),o&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",o==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:o})]}),r.jsx(ft,{className:ye("w-4 h-4 text-[#5A5A6E] transition-transform",m&&"-rotate-90")})]}),!m&&e.agents?.length>0&&r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50",children:[r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Agents to create"}),r.jsx("div",{className:"mt-3 space-y-2.5",children:e.agents.map(_=>r.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-[#13131A] border border-[#2A2A35]",children:[r.jsx("span",{className:"w-8 h-8 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`${_.color}26`},children:_.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-2",children:[r.jsx("span",{className:"text-[13px] font-semibold",style:{color:_.color},children:_.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:_.role})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mt-1 line-clamp-2",children:_.soulDescription}),(e.skillAssignments??[]).filter(w=>w.agentName===_.name).map(w=>r.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:w.skills.map(A=>r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-white/5 border border-[#2A2A35] text-[#C8C8D4]",children:A},A))},w.agentName))]})]},_.name))})]}),!m&&e.channels?.length>0&&r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50",children:[r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Channels to create"}),r.jsx("div",{className:"mt-3 space-y-1.5",children:e.channels.map(_=>r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-lg bg-[#13131A] border border-[#2A2A35]",children:[r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:"#"}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5] font-medium",children:_.name}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E] px-1.5 py-0.5 rounded bg-white/5",children:_.type}),_.description&&r.jsx("span",{className:"text-[11px] text-[#8A8A99] truncate flex-1",children:_.description})]},_.name))})]}),!m&&b&&r.jsxs("div",{className:"px-5 py-3 bg-[#F59E0B]/5 border-b border-[#F59E0B]/10 flex items-center gap-2",children:[r.jsx(ql,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}),r.jsx("span",{className:"text-[12px] text-[#F59E0B]",children:"Some skills will require your approval before execution"})]}),r.jsx(Me,{mode:"wait",children:!m&&l.length>0&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},className:"px-5 py-3 border-b border-[#2A2A35]/50 bg-[#13131A]",children:r.jsx("div",{className:"space-y-1.5",children:l.map((_,w)=>r.jsxs(ne.div,{initial:{opacity:0,x:-10},animate:{opacity:1,x:0},className:"flex items-center gap-2 text-[12px]",children:[r.jsx(Fe,{className:"w-3 h-3 text-[#10B981] flex-shrink-0"}),r.jsxs("span",{className:"text-[#8A8A99]",children:[_.step,":"]}),r.jsx("span",{className:"text-[#C8C8D4]",children:_.detail})]},w))})})}),!m&&c&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"px-5 py-4 bg-[#10B981]/5 border-b border-[#10B981]/10",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(Fe,{className:"w-4 h-4 text-[#10B981]"}),r.jsx("span",{className:"text-[13px] font-semibold text-[#10B981]",children:"Your team is ready"})]}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c.agentsCreated," agent",c.agentsCreated!==1?"s":""," created,"," ",c.channelsCreated," channel",c.channelsCreated!==1?"s":""," created."]}),c.firstChannelId&&r.jsxs("button",{onClick:()=>d(`/channels/${c.firstChannelId}`),className:"mt-2 flex items-center gap-1.5 text-[12px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Go to first agent",r.jsx(tu,{className:"w-3 h-3"})]})]}),!m&&!o&&!c&&r.jsxs("div",{className:"px-5 py-4 flex gap-2",children:[r.jsxs("button",{onClick:()=>t&&n(t),disabled:!t||i||a,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-[#10B981]/10 text-[#34D399] border border-[#10B981]/30 text-[13px] font-medium hover:bg-[#10B981]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:[i?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Fe,{className:"w-3.5 h-3.5"}),i?"Creating...":"Approve & Create"]}),r.jsx("button",{onClick:()=>t&&s(t),disabled:!t||i||a,className:"px-4 py-2.5 rounded-lg bg-[#EF4444]/10 text-[#F87171] border border-[#EF4444]/30 text-[13px] font-medium hover:bg-[#EF4444]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),!m&&o==="rejected"&&r.jsx("div",{className:"px-5 py-3 bg-[#EF4444]/5",children:r.jsx("span",{className:"text-[12px] text-[#F87171]",children:"Proposal rejected"})})]})}function GRe({status:e}){return e==="done"?r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"}):e==="failed"?r.jsx(Te,{className:"w-3.5 h-3.5 text-[#EF4444]"}):r.jsx(Pe,{className:"w-3.5 h-3.5 text-[#F59E0B] animate-spin"})}function KRe({goal:e,dispatches:t,groupChannelId:n}){const s=an(),i=!!n&&t.every(a=>a.channelId===n);return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsx("div",{className:"px-5 py-4 border-b border-[#2A2A35]",children:r.jsx("p",{className:"text-[13px] text-[#8A8A99] leading-relaxed",children:e})}),r.jsx("div",{className:"px-5 py-3 space-y-2",children:t.map((a,o)=>r.jsxs(ne.div,{initial:{opacity:0,x:-12},animate:{opacity:1,x:0},transition:{delay:o*.08,duration:.25},className:"flex items-start gap-3 p-3 rounded-lg bg-[#13131A] border border-[#2A2A35]",children:[r.jsx("span",{className:"w-7 h-7 rounded-full bg-[#F59E0B]/15 flex items-center justify-center text-[12px] flex-shrink-0 mt-0.5",children:a.agentName.charAt(0)}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:a.agentName}),r.jsx(GRe,{status:a.status})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mt-0.5 line-clamp-2",children:a.instruction}),!i&&a.channelId&&r.jsxs("button",{onClick:()=>s(`/channels/${a.channelId}`),className:"mt-1.5 flex items-center gap-1 text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(tu,{className:"w-3 h-3"}),"View in channel"]})]})]},`${a.agentId}-${o}`))}),r.jsxs("div",{className:"px-5 py-3 border-t border-[#2A2A35]/50 flex items-center justify-between",children:[r.jsxs("span",{className:"text-[12px] text-[#10B981]/80",children:[t.length," task",t.length!==1?"s":""," dispatched",i?" (group)":""]}),n&&r.jsxs("button",{onClick:()=>s(`/channels/${n}`),className:"flex items-center gap-1 text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(tu,{className:"w-3 h-3"}),"View group channel"]})]})]})}function YRe({message:e,isLast:t,proposalStatuses:n,progressSteps:s,completionResult:i,onApprove:a,onReject:o,isApproving:l,isRejecting:c,onApproveTrust:d,onRejectTrust:f,isTrustApproving:p,isTrustRejecting:m,onApproveDelegation:g,onRejectDelegation:b,isDelegationPending:_,dispatchStatuses:w}){const A=e.sender.type==="human",{stripped:S,proposal:C}=A?{stripped:e.content,proposal:null}:K7(e.content),E=e.metadata?.proposalId,k=e.metadata?.proposalJson,T=k?$Re(k):null,F=E?n[E]:void 0,M=F==="approved"||F==="rejected"?F:null,I=e.metadata?.trustUpdate,R=I?VRe(I):null,H=e.status==="approved"?"approved":e.status==="rejected"?"rejected":null,V=e.metadata?.delegationRule,K=typeof V=="object"?V:typeof V=="string"?HRe(V):null,q=K?e.status==="approved"?"approved":e.status==="rejected"?"rejected":null:null,$=e.metadata?.dispatch,B=w.get(e.id),Y=e.metadata?.nodeSpawnProposalId,U=e.metadata?.nodeSpawnJson;let W=null;if(U)try{const le=JSON.parse(U);typeof le.name=="string"&&typeof le.reason=="string"&&(W={name:le.name,reason:le.reason})}catch{}const O=e.status==="approved"?"approved":e.status==="rejected"?"rejected":null,D=e.metadata?.federationGrantProposalId,Q=e.metadata?.federationGrantJson;let z=null;if(Q)try{const le=JSON.parse(Q);typeof le.nodeName=="string"&&typeof le.grantAgentId=="string"&&typeof le.reason=="string"&&(z={nodeName:le.nodeName,grantAgentId:le.grantAgentId,reason:le.reason})}catch{}const J=e.metadata?.cloudSpawnProposalId,ee=e.metadata?.cloudSpawnJson;let re=null;if(ee)try{const le=JSON.parse(ee);typeof le.name=="string"&&typeof le.provider=="string"&&typeof le.region=="string"&&typeof le.size=="string"&&typeof le.reason=="string"&&(re={name:le.name,provider:le.provider,region:le.region,size:le.size,reason:le.reason})}catch{}const se=(e.metadata?.remoteAgentProposals??[]).map(le=>{try{const ge=JSON.parse(le.json);if(typeof ge.nodeName=="string"&&typeof ge.name=="string"&&typeof ge.emoji=="string"&&typeof ge.color=="string"&&typeof ge.role=="string"&&typeof ge.soul=="string")return{proposalId:le.id,nodeName:ge.nodeName,name:ge.name,emoji:ge.emoji,color:ge.color,role:ge.role,soul:ge.soul}}catch{}return null}).filter(le=>le!==null),ae=(()=>{const le=new Map;for(const ge of se){const je=le.get(ge.nodeName);je?je.push(ge):le.set(ge.nodeName,[ge])}return Array.from(le.entries()).map(([ge,je])=>({nodeName:ge,agents:je}))})();return r.jsxs("div",{children:[r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2},className:ye("flex items-start gap-3 px-4 py-2",A?"":"border-l-[3px] border-l-[#F59E0B]"),children:[r.jsx("div",{className:"flex-shrink-0 mt-0.5",children:A?r.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-[#4A4A5E] to-[#2A2A3E] flex items-center justify-center border border-[#3A3A4E]",children:r.jsx("span",{className:"text-[11px] font-semibold text-[#A5A5C5]",children:"A"})}):r.jsx("div",{className:"w-8 h-8 rounded-full bg-[#F59E0B]/15 flex items-center justify-center",children:r.jsx(Ia,{className:"w-4 h-4 text-[#F59E0B]"})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[r.jsx("span",{className:ye("text-[13px] font-semibold",A?"text-[#F0F0F5]":"text-[#F59E0B]"),children:A?e.sender.name:"COO"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:Ir(e.timestamp)})]}),r.jsx("div",{className:"text-[14px] text-[#C8C8D4] leading-relaxed prose-message",children:r.jsx(Ei,{remarkPlugins:[Fi],children:S})}),C!==null&&r.jsx(G7,{proposal:C,messageId:e.id,metadata:e.metadata}),e.metadata?.skillWriteProposal?r.jsx(Q7,{message:e,proposal:e.metadata.skillWriteProposal}):null,e.metadata?.skillInstallProposal?r.jsx(Y7,{proposal:e.metadata.skillInstallProposal,messageId:e.id,metadata:e.metadata}):null,e.status==="pending_approval"&&!e.metadata?.missionPlan&&!e.metadata?.nodeSpawnProposalId&&se.length===0&&r.jsx(J7,{message:e})]})]}),T&&r.jsx(qRe,{proposal:T,proposalId:E,onApprove:a,onReject:o,isApproving:l,isRejecting:c,decided:M,progressSteps:t?s:[],completionResult:t?i:null}),R&&r.jsx(URe,{messageId:e.id,trustData:R,decided:H,onApprove:d,onReject:f,isApproving:p,isRejecting:m}),K&&r.jsx(WRe,{messageId:e.id,rule:K,decided:q,onApprove:g,onReject:b,isPending:_}),$&&B&&B.length>0&&r.jsx(KRe,{goal:$.goal,dispatches:B}),W&&Y&&r.jsx(XRe,{proposalId:Y,name:W.name,reason:W.reason,decided:O,serverStatus:n[Y]}),ae.map(le=>r.jsx(QRe,{nodeName:le.nodeName,agents:le.agents,serverStatuses:n},le.nodeName)),z&&D&&r.jsx(tDe,{proposalId:D,data:z,serverStatus:n[D]}),re&&J&&r.jsx(nDe,{proposalId:J,data:re,serverStatus:n[J]}),e.metadata?.missionPlan?r.jsx(sDe,{plan:e.metadata.missionPlan,messageId:e.id,decided:e.status==="approved"?"approved":e.status==="rejected"?"rejected":null}):null]})}function QRe({nodeName:e,agents:t,serverStatuses:n}){const s=t.map(F=>{const M=n[F.proposalId];return M==="approved"?"approved":M==="rejected"?"rejected":M==="failed"?"failed":"pending"}),i=s.every(F=>F!=="pending"),a=s.every(F=>F==="rejected"),o=s.some(F=>F==="approved"||F==="failed"),l=i&&a?"rejected":i&&o?"approved":null,c=s.filter(F=>F==="approved").length,d=s.filter(F=>F==="failed").length,[f,p]=y.useState(!1),m=l?!f:f,g=F=>p(l?!F:F),b=L.useUtils(),_=L.coo.approveRemoteAgent.useMutation(),w=L.coo.rejectRemoteAgent.useMutation(),[A,S]=y.useState(null),[C,E]=y.useState(null),k=async()=>{S("approving"),E(null);try{for(const F of t)n[F.proposalId]&&n[F.proposalId]!=="pending"||await _.mutateAsync({proposalId:F.proposalId})}catch(F){E(F instanceof Error?F.message:"Failed to approve one or more agents")}finally{S(null),b.federation.listNodes.invalidate(),b.coo.listProposals.invalidate()}},T=async()=>{S("rejecting"),E(null);try{for(const F of t)n[F.proposalId]&&n[F.proposalId]!=="pending"||await w.mutateAsync({proposalId:F.proposalId})}catch(F){E(F instanceof Error?F.message:"Failed to reject one or more agents")}finally{S(null),b.coo.listProposals.invalidate()}};return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>g(!m),className:"w-full px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between hover:bg-white/[0.02] transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(Mp,{className:"w-4 h-4 text-[#6366F1] flex-shrink-0"}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Remote Team Proposal"}),r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:"on"}),r.jsx("span",{className:"text-[12px] font-mono px-2 py-0.5 rounded bg-[#6366F1]/15 text-[#818CF8] font-semibold",children:e}),l&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",l==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:l})]}),r.jsx(ft,{className:ye("w-4 h-4 text-[#5A5A6E] transition-transform flex-shrink-0",m&&"-rotate-90")})]}),!m&&t.length>0&&r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50",children:[r.jsxs("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:["Agents to create on ",r.jsx("span",{className:"text-[#818CF8] font-mono",children:e})]}),r.jsx("div",{className:"mt-3 space-y-2.5",children:t.map((F,M)=>{const I=s[M];return r.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-[#13131A] border border-[#2A2A35]",children:[r.jsx("span",{className:"w-8 h-8 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`${F.color}26`},children:F.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[r.jsx("span",{className:"text-[13px] font-semibold",style:{color:F.color},children:F.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:F.role}),I==="approved"&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium bg-[#10B981]/10 text-[#34D399] uppercase tracking-wider",children:"created"}),I==="failed"&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium bg-[#EF4444]/10 text-[#F87171] uppercase tracking-wider",children:"failed"}),I==="rejected"&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium bg-[#8A8A99]/10 text-[#8A8A99] uppercase tracking-wider",children:"rejected"}),I==="pending"&&A==="approving"&&r.jsx(Pe,{className:"w-3 h-3 animate-spin text-[#6366F1]"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mt-1 line-clamp-2",children:F.soul})]})]},F.proposalId)})})]}),!m&&l==="approved"&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"px-5 py-4 bg-[#10B981]/5 border-b border-[#10B981]/10",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(Fe,{className:"w-4 h-4 text-[#10B981]"}),r.jsxs("span",{className:"text-[13px] font-semibold text-[#10B981]",children:["Remote team ready on ",r.jsx("span",{className:"font-mono",children:e})]})]}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c," agent",c!==1?"s":""," created",d>0?`, ${d} failed`:"",". You can now delegate to them using ",r.jsx("code",{className:"text-[11px] px-1 py-0.5 rounded bg-[#0F0F11] text-[#C8C8D4]",children:"<slug>@"+e})," in delegate blocks."]})]}),!m&&C&&r.jsxs("div",{className:"px-5 py-3 bg-[#EF4444]/5 border-b border-[#EF4444]/20 flex items-start gap-2 text-[12px] text-[#F87171]",children:[r.jsx("span",{className:"mt-0.5",children:"⚠"}),r.jsx("span",{className:"break-all",children:C})]}),!m&&!l&&r.jsxs("div",{className:"px-5 py-4 flex gap-2",children:[r.jsxs("button",{onClick:k,disabled:A!==null,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-[#10B981]/10 text-[#34D399] border border-[#10B981]/30 text-[13px] font-medium hover:bg-[#10B981]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:[A==="approving"?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Fe,{className:"w-3.5 h-3.5"}),A==="approving"?`Creating ${c+d+1}/${t.length}…`:`Approve & Create ${t.length>1?`all ${t.length}`:""}`]}),r.jsx("button",{onClick:T,disabled:A!==null,className:"px-4 py-2.5 rounded-lg bg-[#EF4444]/10 text-[#F87171] border border-[#EF4444]/30 text-[13px] font-medium hover:bg-[#EF4444]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:A==="rejecting"?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),!m&&l==="rejected"&&r.jsx("div",{className:"px-5 py-3 bg-[#EF4444]/5",children:r.jsx("span",{className:"text-[12px] text-[#F87171]",children:"Remote team proposal rejected"})})]})}function XRe({proposalId:e,name:t,reason:n,decided:s,serverStatus:i}){const[a,o]=y.useState(null),c=a??(i==="approved"||i==="failed"?"approved":i==="rejected"?"rejected":null)??s,[d,f]=y.useState(!1),p=c?!d:d,m=C=>f(c?!C:C),g=L.useUtils(),b=L.coo.approveNodeSpawn.useMutation({onSuccess:()=>{o("approved"),g.federation.listNodes.invalidate(),g.coo.listProposals.invalidate()}}),_=L.coo.rejectNodeSpawn.useMutation({onSuccess:()=>{o("rejected"),g.coo.listProposals.invalidate()}}),A=L.federation.getSpawnDefaults.useQuery().data?.defaultNodeSpawnPolicy??"coo-only",S=b.isPending||_.isPending;return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#6366F1]/25 rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>m(!p),className:"w-full px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between hover:bg-white/[0.02] transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"w-6 h-6 rounded-lg bg-[#6366F1]/15 flex items-center justify-center",children:r.jsx("span",{className:"text-[13px]",children:"⚡"})}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Spawn Isolated Node"}),r.jsx("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded bg-[#6366F1]/15 text-[#818CF8]",children:t}),c&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",c==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:c})]}),r.jsx(ft,{className:ye("w-4 h-4 text-[#5A5A6E] transition-transform",p&&"-rotate-90")})]}),!p&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50",children:[r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Why"}),r.jsx("p",{className:"mt-2 text-[13px] text-[#C8C8D4] leading-relaxed",children:n})]}),r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35]/50 space-y-2",children:[r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"What will happen"}),r.jsxs("div",{className:"space-y-1.5 text-[12px] text-[#8A8A99]",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-[#6366F1] mt-0.5",children:"•"}),r.jsx("span",{children:"A brand-new isolated damn.dev container (backend + OpenClaw) will start on this machine"})]}),r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-[#6366F1] mt-0.5",children:"•"}),r.jsxs("span",{children:["Its own SQLite DB and OpenClaw workspace at ",r.jsxs("code",{className:"text-[11px] px-1 py-0.5 rounded bg-[#0F0F11] text-[#C8C8D4]",children:["~/.damn-dev/nodes/",t,"/"]})]})]}),r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-[#6366F1] mt-0.5",children:"•"}),r.jsxs("span",{children:["Default delegation policy: ",r.jsx("strong",{className:"text-[#F0F0F5]",children:A})," — adjustable from Settings → Federation"]})]}),r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-[#6366F1] mt-0.5",children:"•"}),r.jsxs("span",{children:["Auto-federated: the COO will be able to dispatch to any agents you later create on this node using ",r.jsx("code",{className:"text-[11px] px-1 py-0.5 rounded bg-[#0F0F11] text-[#C8C8D4]",children:"<agent>@"+t})," syntax"]})]})]})]}),b.isError&&r.jsxs("div",{className:"px-5 py-3 bg-[#EF4444]/5 border-b border-[#EF4444]/20 flex items-start gap-2 text-[12px] text-[#F87171]",children:[r.jsx("span",{className:"mt-0.5",children:"⚠"}),r.jsx("span",{children:b.error?.message})]}),_.isError&&r.jsxs("div",{className:"px-5 py-3 bg-[#EF4444]/5 border-b border-[#EF4444]/20 flex items-start gap-2 text-[12px] text-[#F87171]",children:[r.jsx("span",{className:"mt-0.5",children:"⚠"}),r.jsx("span",{children:_.error?.message})]}),!c&&r.jsxs("div",{className:"px-5 py-4 flex gap-2",children:[r.jsxs("button",{onClick:()=>b.mutate({proposalId:e}),disabled:S,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-[#10B981]/10 text-[#34D399] border border-[#10B981]/30 text-[13px] font-medium hover:bg-[#10B981]/20 transition-colors disabled:opacity-40 disabled:pointer-events-none",children:[b.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Fe,{className:"w-3.5 h-3.5"}),b.isPending?"Spawning…":"Approve & Spawn"]}),r.jsx("button",{onClick:()=>_.mutate({proposalId:e}),disabled:S,className:"flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-[#2A2A35] text-[#8A8A99] border border-[#2A2A35] text-[13px] font-medium hover:bg-[#3A3A45] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:_.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):"Reject"})]})]})]})}function JRe(){const e=L.useUtils(),{data:t}=L.agents.list.useQuery(),n=t?.find(f=>f.id==="coo"),s=n?.model??n?.defaultModel??"",i=L.agents.update.useMutation({onSuccess:()=>e.agents.list.invalidate()}),a=f=>i.mutate({agentId:"coo",model:f}),o=Up(s),[l,c]=y.useState(""),{groups:d}=Vm();return r.jsxs(ss,{value:s,onValueChange:a,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[12px] border transition-colors outline-none",style:{color:zd,backgroundColor:`${zd}15`,borderColor:`${zd}40`},children:[r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[o]}`,children:o}),r.jsx(Ds,{children:ta(s)}),r.jsx(ft,{className:"w-3 h-3 opacity-60"})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:6,align:"end",className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] z-50",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:l,onChange:c,onSubmit:f=>{a(f),c("")}})}),r.jsx(os,{children:d.map(f=>r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:f.label}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo[f.tag]}`,children:f.tag})]}),f.models.map(p=>r.jsxs(vn,{value:p.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:p.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},p.id))]},f.label))})]})})]})}function ZRe(){if(!Uo())return r.jsx(lm,{to:"/channels/direction",replace:!0});const{data:t,isLoading:n}=L.agents.list.useQuery(void 0,{refetchInterval:a=>a.state.data?.some(l=>l.id==="coo")?!1:3e3}),s=L.onboarding.seedCOO.useMutation(),i=t?.some(a=>a.id==="coo");return n?r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Pe,{className:"w-5 h-5 animate-spin text-[#F59E0B]"})}):i?r.jsx(eDe,{}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center px-8",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-[#F59E0B]/10 border border-[#F59E0B]/20 flex items-center justify-center mb-4",children:r.jsx(Ia,{className:"w-7 h-7 text-[#F59E0B]"})}),r.jsx("h2",{className:"text-[18px] font-semibold text-[#F0F0F5] mb-2",children:"Your COO"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] max-w-md leading-relaxed mb-6",children:"The COO is your workspace architect. It can design agent teams, assign skills, and manage your workspace structure."}),r.jsxs("button",{onClick:()=>s.mutate(),disabled:s.isPending,className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#F59E0B] text-[#0F0F11] hover:bg-[#FBBF24] disabled:opacity-60 transition-colors",children:[s.isPending&&r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),"Create COO"]}),s.isError&&r.jsx("p",{className:"mt-3 text-[12px] text-red-400",children:"Failed to create COO. Try again."})]})}function eDe(){const{model:e}=zRe(),[t,n]=y.useState(""),[s,i]=y.useState(!1),[a,o]=y.useState(!1),[l,c]=y.useState([]),[d,f]=y.useState(null),p=y.useRef(null),m=y.useRef(null),[g,b]=y.useState(new Map),_=y.useRef(null),{data:w}=pj("coo");bW(Hf);const A=Je(ee=>ee.messagesByChannel[Hf]),S=y.useMemo(()=>A??[],[A]),C=L.messages.list.useQuery({channelId:Hf,limit:100},{staleTime:0}),E=L.coo.listProposals.useQuery(void 0,{staleTime:5e3}),k=E.data??{};y.useEffect(()=>{C.data&&Je.getState().setMessages(Hf,C.data.messages)},[C.data]);const T=L.coo.getLatestTask.useQuery(void 0,{staleTime:5e3});y.useEffect(()=>{const ee=[...S].reverse().find(le=>le.sender.type==="agent"&&le.metadata?.dispatch);if(!ee)return;_.current=ee.id;const re=T.data;if(re&&re.dispatches.length>0){const le=re.dispatches.map(ge=>({agentId:ge.agentId,agentName:ge.agentName??ge.agentId,channelId:ge.channelId,instruction:ge.instruction,status:ge.status??"sent"}));b(ge=>new Map(ge).set(ee.id,le));return}if(g.has(ee.id))return;const oe=ee.metadata?.dispatch,se=[],ae=oe?.groups??(oe?.group?[oe.group]:[]);for(const le of ae)for(const ge of le.agents)se.push({agentId:ge,agentName:ge,channelId:"",instruction:le.goal,status:"sent"});if(oe?.assignments)for(const le of oe.assignments)se.push({agentId:le.agent,agentName:le.agent,channelId:"",instruction:le.instruction,status:"sent"});se.length>0&&b(le=>new Map(le).set(ee.id,se))},[S,T.data]);const F=L.coo.chat.useMutation(),M=L.coo.approveProposal.useMutation(),I=L.coo.rejectProposal.useMutation(),R=L.coo.approveTrustUpdate.useMutation(),H=L.coo.rejectTrustUpdate.useMutation(),V=L.approvals.decide.useMutation(),K=L.messages.resetSession.useMutation(),q=L.useUtils();y.useEffect(()=>{p.current?.scrollIntoView({behavior:"smooth"})},[S.length,l.length]),y.useEffect(()=>{const ee=new WebSocket("ws://localhost:3001/ws");return ee.onmessage=re=>{try{const oe=JSON.parse(re.data);if(oe.type==="coo.progress"){const se=oe.payload;c(ae=>[...ae,se])}else if(oe.type==="coo.complete"){const se=oe.payload;f(se),B.current()}else if(oe.type==="coo.dispatch.sent"){const se=oe.payload;_.current&&b(ae=>{const le=new Map(ae),ge=le.get(_.current)??[],je=ge.findIndex(Ee=>Ee.agentId===se.agentId);return je>=0?ge[je]={...ge[je],...se,status:"sent"}:ge.push({...se,status:"sent"}),le.set(_.current,[...ge]),le})}else if(oe.type==="coo.dispatch.agent.done"){const se=oe.payload;_.current&&b(ae=>{const le=new Map(ae),ge=le.get(_.current)??[];return le.set(_.current,ge.map(je=>je.agentId===se.agentId?{...je,status:se.status}:je)),le})}}catch{}},()=>ee.close()},[]);const $=y.useRef(!1),B=y.useRef(E.refetch);B.current=E.refetch;const Y=y.useCallback(async()=>{const ee=t.trim();if(!ee||F.isPending||$.current)return;$.current=!0;const re=S.map(oe=>({role:oe.sender.type==="human"?"user":"assistant",content:oe.content}));n(""),m.current&&(m.current.style.height="auto");try{await F.mutateAsync({message:ee,history:re,model:e}),C.refetch(),B.current()}catch{}finally{$.current=!1}},[t,F,S,e]);function U(ee){c([]),M.mutate({proposalId:ee},{onSuccess:()=>{q.agents.list.invalidate(),q.channels.list.invalidate(),E.refetch()}})}function W(ee){I.mutate({proposalId:ee},{onSuccess:()=>{E.refetch()}})}function O(ee){R.mutate({messageId:ee},{onSuccess:()=>{q.agents.getTrust.invalidate(),q.agents.getSandboxOverride.invalidate(),q.agents.getMounts.invalidate(),C.refetch()}})}function D(ee){H.mutate({messageId:ee},{onSuccess:()=>{C.refetch()}})}function Q(ee){V.mutate({messageId:ee,decision:"approved"},{onSuccess:()=>{C.refetch()}})}function z(ee){V.mutate({messageId:ee,decision:"rejected"},{onSuccess:()=>{C.refetch()}})}function J(){K.mutate({channelId:Hf}),c([]),f(null)}return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[#2A2A35] bg-[#0F0F11] flex-shrink-0",style:{borderLeftColor:zd,borderLeftWidth:3,borderLeftStyle:"solid"},children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:()=>o(ee=>!ee),className:"w-8 h-8 rounded-full bg-[#F59E0B]/15 flex items-center justify-center transition-opacity hover:opacity-80",children:r.jsx(Ia,{className:"w-4 h-4 text-[#F59E0B]"})}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:()=>o(ee=>!ee),className:"text-[15px] font-semibold text-[#F0F0F5] hover:underline decoration-dashed underline-offset-2 transition-colors",children:"COO"}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded",children:"Workspace Architect"})]}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"relative flex items-center justify-center w-2 h-2",children:r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:zd,opacity:.5}})}),r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:"ready"})]})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(JRe,{}),r.jsx(bt,{label:"Reset context",children:r.jsx("button",{onClick:J,className:"w-8 h-8 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5 transition-colors",children:r.jsx(lh,{className:"w-4 h-4"})})}),r.jsx(bt,{label:a?"Close panel":"Open panel",children:r.jsx("button",{onClick:()=>o(ee=>!ee),className:ye("w-8 h-8 flex items-center justify-center rounded-md transition-colors",a?"text-[#F0F0F5] bg-white/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/5"),children:a?r.jsx(mL,{className:"w-4 h-4"}):r.jsx(xL,{className:"w-4 h-4"})})})]})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto py-2",children:[S.length===0&&!C.isLoading&&r.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center px-8",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-[#F59E0B]/10 border border-[#F59E0B]/20 flex items-center justify-center mb-4",children:r.jsx(Ia,{className:"w-7 h-7 text-[#F59E0B]"})}),r.jsx("h2",{className:"text-[18px] font-semibold text-[#F0F0F5] mb-2",children:"Talk to your COO"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] max-w-md leading-relaxed",children:"Design your team, dispatch tasks, manage skills, update trust settings — all through natural conversation."})]}),r.jsx(Me,{initial:!1,children:S.map((ee,re)=>ee.sender.type==="context_reset"?r.jsxs("div",{className:"flex items-center gap-3 py-2 px-4",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"new context"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]},ee.id):r.jsx(YRe,{message:ee,isLast:re===S.length-1,proposalStatuses:k,progressSteps:l,completionResult:d,onApprove:U,onReject:W,isApproving:M.isPending,isRejecting:I.isPending,onApproveTrust:O,onRejectTrust:D,isTrustApproving:R.isPending,isTrustRejecting:H.isPending,onApproveDelegation:Q,onRejectDelegation:z,isDelegationPending:V.isPending,dispatchStatuses:g},ee.id))}),F.isPending&&r.jsxs("div",{className:"flex items-start gap-3 px-4 py-2 border-l-[3px] border-l-[#F59E0B]",children:[r.jsx("div",{className:"w-8 h-8 rounded-full bg-[#F59E0B]/15 flex items-center justify-center flex-shrink-0",children:r.jsx(Ia,{className:"w-4 h-4 text-[#F59E0B]"})}),r.jsx("div",{className:"flex items-center gap-1 pt-3",children:[0,1,2].map(ee=>r.jsx(ne.span,{className:"w-1.5 h-1.5 rounded-full bg-[#F59E0B]",animate:{opacity:[.3,1,.3],scale:[.8,1.1,.8]},transition:{duration:1.4,repeat:1/0,delay:ee*.2,ease:"easeInOut"}},ee))})]}),r.jsx("div",{ref:p,className:"h-4"})]}),r.jsxs("div",{className:"px-4 pb-4 pt-2 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-end gap-2 bg-[#1C1C21] border rounded-xl px-3 py-2.5 transition-colors duration-150",style:{borderColor:s?"#F59E0B60":"#2A2A35",boxShadow:s?"0 0 0 1px #F59E0B30":void 0},children:[r.jsx("textarea",{ref:m,value:t,onChange:ee=>n(ee.target.value),onKeyDown:ee=>{ee.key==="Enter"&&!ee.shiftKey&&(ee.preventDefault(),Y())},onFocus:()=>i(!0),onBlur:()=>i(!1),placeholder:"Talk to your COO...",disabled:F.isPending,rows:1,className:"flex-1 bg-transparent text-[14px] text-[#F0F0F5] placeholder:text-[#8A8A99]/60 resize-none outline-none leading-relaxed max-h-[120px] overflow-y-auto disabled:opacity-50",style:{minHeight:"22px"},onInput:ee=>{const re=ee.currentTarget;re.style.height="auto",re.style.height=`${Math.min(re.scrollHeight,120)}px`}}),r.jsx("button",{onClick:()=>{Y()},disabled:!t.trim()||F.isPending,className:"text-[#8A8A99] hover:text-[#F0F0F5] disabled:opacity-30 transition-colors mb-0.5 flex-shrink-0",children:r.jsx(Ji,{className:"w-4 h-4"})})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]/40 mt-1.5 px-1",children:"Enter to send · Shift+Enter for newline"})]})]}),r.jsx(Me,{children:a&&w&&r.jsx($N,{agent:w,agentColor:zd,onClose:()=>o(!1),onOverrideSet:()=>{}})})]})}function tDe({proposalId:e,data:t,serverStatus:n}){const[s,i]=y.useState(null),o=s??(n==="approved"||n==="failed"?"approved":n==="rejected"?"rejected":null),l=L.useUtils(),c=L.coo.approveFederationGrant.useMutation({onSuccess:()=>{i("approved"),l.federation.listNodes.invalidate(),l.coo.listProposals.invalidate()}}),d=L.coo.rejectFederationGrant.useMutation({onSuccess:()=>{i("rejected"),l.coo.listProposals.invalidate()}}),f=c.isPending||d.isPending;return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#6366F1]/25 rounded-xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center gap-2",children:[r.jsx("div",{className:"w-6 h-6 rounded-lg bg-[#6366F1]/15 flex items-center justify-center",children:r.jsx(Wl,{className:"w-3 h-3 text-[#6366F1]"})}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Federation Grant"}),r.jsxs("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded bg-[#6366F1]/15 text-[#818CF8]",children:[t.grantAgentId," → ",t.nodeName]}),o&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",o==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:o})]}),r.jsx("div",{className:"px-5 py-3 border-b border-[#2A2A35]/50 text-[13px] text-[#C8C8D4] leading-relaxed",children:t.reason}),!o&&r.jsxs("div",{className:"px-5 py-3 flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>d.mutate({proposalId:e}),disabled:f,className:"px-4 py-1.5 rounded text-[12px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors disabled:opacity-50",children:"Reject"}),r.jsxs("button",{onClick:()=>c.mutate({proposalId:e}),disabled:f,className:"px-4 py-1.5 rounded bg-[#10B981] text-white text-[12px] font-medium hover:bg-[#0EA472] transition-colors disabled:opacity-50 flex items-center gap-1.5",children:[c.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Fe,{className:"w-3 h-3"}),"Grant Access"]})]})]})}function nDe({proposalId:e,data:t,serverStatus:n}){const[s,i]=y.useState(null),o=s??(n==="approved"||n==="failed"?"approved":n==="rejected"?"rejected":null),l=L.useUtils(),c=L.coo.approveCloudSpawn.useMutation({onSuccess:()=>{i("approved"),l.federation.listNodes.invalidate(),l.coo.listProposals.invalidate()}}),d=L.coo.rejectCloudSpawn.useMutation({onSuccess:()=>{i("rejected"),l.coo.listProposals.invalidate()}}),f=c.isPending||d.isPending;return r.jsxs(ne.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:300,damping:30},className:"mx-4 mb-4 bg-[#1C1C24] border border-[#10B981]/25 rounded-xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center gap-2",children:[r.jsx("div",{className:"w-6 h-6 rounded-lg bg-[#10B981]/15 flex items-center justify-center",children:r.jsx(Xt,{className:"w-3 h-3 text-[#10B981]"})}),r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Spawn Cloud Node"}),r.jsx("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded bg-[#10B981]/15 text-[#34D399]",children:t.name}),r.jsxs("span",{className:"text-[10px] text-[#8A8A99]",children:[t.provider," · ",t.region," · ",t.size]}),o&&r.jsx("span",{className:ye("text-[11px] px-1.5 py-0.5 rounded font-medium",o==="approved"?"bg-[#10B981]/10 text-[#34D399]":"bg-[#EF4444]/10 text-[#F87171]"),children:o})]}),r.jsx("div",{className:"px-5 py-3 border-b border-[#2A2A35]/50 text-[13px] text-[#C8C8D4] leading-relaxed",children:t.reason}),!o&&r.jsxs("div",{className:"px-5 py-3 flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#10B981]",children:"This will provision a Hetzner VPS (billable)"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>d.mutate({proposalId:e}),disabled:f,className:"px-4 py-1.5 rounded text-[12px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors disabled:opacity-50",children:"Reject"}),r.jsxs("button",{onClick:()=>c.mutate({proposalId:e}),disabled:f,className:"px-4 py-1.5 rounded bg-[#10B981] text-white text-[12px] font-medium hover:bg-[#0EA472] transition-colors disabled:opacity-50 flex items-center gap-1.5",children:[c.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Xt,{className:"w-3 h-3"}),"Approve & Provision"]})]})]})]})}function sDe({plan:e,messageId:t,decided:n}){const s=an(),i=L.useUtils(),a=L.coo.approveMissionPlan.useMutation({onSuccess:()=>{i.missions.list.invalidate(),i.missions.stats.invalidate(),s("/missions")}}),o=L.coo.rejectMissionPlan.useMutation(),c={low:"#5A5A6E",normal:"#8A8A99",high:"#F59E0B",critical:"#EF4444"}[e.priority??"normal"]??"#8A8A99";return r.jsxs("div",{className:"mt-3 rounded-lg border border-[#2A2A35] bg-[#13131A] overflow-hidden",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35]/50 flex items-center gap-3",children:[r.jsx(a0,{className:"w-4 h-4 text-[#6366F1]"}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5] flex-1",children:e.title}),r.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-medium",style:{color:c,backgroundColor:c+"15"},children:e.priority??"normal"})]}),e.description&&r.jsx("p",{className:"px-4 py-2 text-[12px] text-[#8A8A99] border-b border-[#2A2A35]/30",children:e.description}),r.jsx("div",{className:"px-4 py-2 space-y-1.5",children:e.tasks.map((d,f)=>r.jsxs("div",{className:"flex items-center gap-2.5 py-1 px-2.5 rounded bg-[#0F0F11]/50",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] font-mono w-4 text-right",children:d.order}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#3A3A45]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] flex-1 truncate",children:d.title}),d.agentId&&r.jsx("span",{className:"text-[11px] text-[#8A8A99] bg-[#1E1E28] px-1.5 py-0.5 rounded",children:d.agentId}),d.dependsOn&&d.dependsOn.length>0&&r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:["after ",d.dependsOn.join(", ")]})]},f))}),r.jsx("div",{className:"px-4 py-3 border-t border-[#2A2A35]/50 flex items-center gap-2",children:n==="approved"?r.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] text-[#10B981]",children:[r.jsx(Fe,{className:"w-3.5 h-3.5"})," Mission created"]}):n==="rejected"?r.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] text-[#EF4444]",children:[r.jsx(Te,{className:"w-3.5 h-3.5"})," Plan rejected"]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>a.mutate({messageId:t}),disabled:a.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E6] transition-colors disabled:opacity-50",children:[a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Fe,{className:"w-3 h-3"}),"Create Mission"]}),r.jsx("button",{onClick:()=>o.mutate({messageId:t}),disabled:o.isPending,className:"px-3 py-1.5 rounded-md text-[12px] text-[#8A8A99] hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors",children:"Reject"})]})})]})}function _W({text:e}){const[t,n]=y.useState(!1);return r.jsx(bt,{label:t?"Copied":"Copy",children:r.jsx("button",{onClick:()=>{navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)},className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5 transition-colors",children:t?r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"}):r.jsx(Po,{className:"w-3.5 h-3.5"})})})}function fb({code:e,label:t}){return r.jsxs("div",{className:"mt-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99] font-medium",children:t}),r.jsx(_W,{text:e})]}),r.jsx("pre",{className:"bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[11px] font-mono text-[#C8C8D4] overflow-x-auto whitespace-pre-wrap break-all",children:e})]})}function iDe(){const[e,t]=y.useState(!1),{data:n,isLoading:s}=L.mcp.getToken.useQuery(),i=L.useUtils(),a=L.mcp.regenerateToken.useMutation({onSuccess:()=>{i.mcp.getToken.invalidate()}});if(s||!n)return r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4",children:"Loading..."});const{token:o,serverPath:l}=n,c=o.slice(0,8)+"•".repeat(24)+o.slice(-8);return r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-[14px] font-semibold text-[#F0F0F5] mb-1",children:"MCP Server"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Connect external AI harnesses (Claude Code, Codex, Cursor) to your agent's identity, memory, and governance."})]}),r.jsxs("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-xl p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(Ti,{className:"w-4 h-4 text-[#6366F1]"}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Auth Token"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("code",{className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[12px] font-mono text-[#8A8A99] overflow-hidden",children:e?o:c}),r.jsx(bt,{label:e?"Hide":"Reveal",children:r.jsx("button",{onClick:()=>t(d=>!d),className:"w-8 h-8 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5 transition-colors",children:e?r.jsx(R5,{className:"w-4 h-4"}):r.jsx(xv,{className:"w-4 h-4"})})}),r.jsx(_W,{text:o}),r.jsx(bt,{label:"Regenerate",children:r.jsx("button",{onClick:()=>a.mutate(),disabled:a.isPending,className:"w-8 h-8 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#F59E0B] hover:bg-[#F59E0B]/10 transition-colors disabled:opacity-50",children:r.jsx(Xi,{className:`w-4 h-4 ${a.isPending?"animate-spin":""}`})})})]}),a.isSuccess&&r.jsx("p",{className:"text-[11px] text-[#F59E0B] mt-2",children:"Token regenerated. Update your harness configs."})]}),r.jsxs("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-xl p-4",children:[r.jsx("h4",{className:"text-[13px] font-medium text-[#F0F0F5] mb-3",children:"Setup Instructions"}),r.jsx(fb,{label:"Claude Code",code:`claude mcp add damn-dev -e DAMNDEV_TOKEN=${o} -- node ${l}`}),r.jsx(fb,{label:"Codex",code:`codex mcp add damn-dev --env DAMNDEV_TOKEN=${o} -- node ${l}`}),r.jsx(fb,{label:"Cursor (.cursor/mcp.json)",code:JSON.stringify({mcpServers:{"damn-dev":{command:"node",args:[l],env:{DAMNDEV_TOKEN:o}}}},null,2)})]}),r.jsxs("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-xl p-4",children:[r.jsx("h4",{className:"text-[13px] font-medium text-[#F0F0F5] mb-2",children:"Project Binding"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99] mb-3",children:["Create a ",r.jsx("code",{className:"text-[#C8C8D4] bg-[#0F0F11] px-1 rounded",children:".damndev.json"})," in your project root to auto-bind an agent:"]}),r.jsx(fb,{label:".damndev.json",code:JSON.stringify({agent:"your-agent-id",workspace:"default"},null,2)})]})]})}function rDe({entry:e,onDelete:t,onSave:n,onMoveToSecrets:s}){const[i,a]=y.useState(!1),[o,l]=y.useState(!1),[c,d]=y.useState(e.value),[f,p]=y.useState(!1);function m(){n(e.key,c.trim()),l(!1),p(!0),setTimeout(()=>p(!1),1500)}return r.jsxs("div",{className:"flex items-start gap-4 py-4 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:e.key}),e.label!==e.key&&r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:e.label}),f&&r.jsxs(ne.span,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0},className:"flex items-center gap-1 text-[11px] text-[#10B981]",children:[r.jsx(Fe,{className:"w-3 h-3"}),"Saved"]})]}),o?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{autoFocus:!0,type:"text",value:c,onChange:g=>d(g.target.value),onKeyDown:g=>{g.key==="Enter"&&m(),g.key==="Escape"&&(l(!1),d(e.value))},className:"flex-1 bg-[#13131A] border border-[#6366F1]/40 rounded-lg px-3 py-1.5 text-[13px] text-[#F0F0F5] font-mono outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("button",{onClick:m,className:"px-3 py-1.5 rounded-lg bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E8] transition-colors",children:"Save"}),r.jsx("button",{onClick:()=>{l(!1),d(e.value)},className:"px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})]}):r.jsx("button",{onClick:()=>l(!0),className:"flex items-center gap-2 group",children:r.jsx("code",{className:"text-[12px] font-mono text-[#8A8A99] group-hover:text-[#C8C8D4] transition-colors",children:i?e.value:e.masked})})]}),e.key==="GITHUB_TOKEN"&&r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://github.com/settings/tokens/new?scopes=repo&description=damn.dev",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Generate a token on GitHub ",r.jsx(cs,{className:"w-3 h-3"})]}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Scopes are pre-filled — just click Generate and paste it here."}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Set expiration to 'No expiration' for uninterrupted access."})]}),e.key==="GITLAB_TOKEN"&&r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://gitlab.com/-/user_settings/personal_access_tokens?name=damn.dev&scopes=api",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Generate a token on GitLab ",r.jsx(cs,{className:"w-3 h-3"})]}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Scopes are pre-filled — just click Create and paste it here."})]}),r.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.misplaced&&s&&r.jsx(bt,{label:"This is a credential — encrypt it in Secrets. The env copy stays in place as a mirror so nothing breaks.",children:r.jsx("button",{onClick:()=>s(e.key),className:"flex items-center gap-1 px-2 h-7 rounded-md text-[11px] font-medium bg-amber-500/10 text-amber-300 hover:bg-amber-500/20 border border-amber-500/20 transition-colors",children:"Encrypt"})}),r.jsx(bt,{label:i?"Hide":"Reveal",children:r.jsx("button",{onClick:()=>a(g=>!g),className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5 transition-colors",children:i?r.jsx(R5,{className:"w-3.5 h-3.5"}):r.jsx(xv,{className:"w-3.5 h-3.5"})})}),r.jsx(bt,{label:"Delete",children:r.jsx("button",{onClick:()=>t(e.key),className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]})]})}function aDe({knownKeys:e,existingKeys:t,onAdd:n,onClose:s}){const[i,a]=y.useState(""),[o,l]=y.useState(""),[c,d]=y.useState(""),f=i==="__custom__",p=f?o.trim():i;function m(){!p||!c.trim()||(n(p,c.trim()),s())}const g=e.filter(b=>!t.includes(b.key));return r.jsxs(ne.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"bg-[#16161A] border border-[#2A2A35] rounded-xl p-5 mb-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-4",children:"Add API Key"}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Key name"}),r.jsxs(ss,{value:i,onValueChange:a,children:[r.jsxs(is,{className:"flex items-center justify-between w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/60 transition-colors",children:[r.jsx(Ds,{placeholder:"Select a key..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl z-50 overflow-hidden",children:r.jsxs(os,{className:"p-1",children:[g.map(b=>r.jsx(vn,{value:b.key,className:"flex items-center px-3 py-2 text-[13px] text-[#C8C8D4] rounded-md cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:r.jsx(yn,{children:b.key})},b.key)),r.jsx(vn,{value:"__custom__",className:"flex items-center px-3 py-2 text-[13px] text-[#8A8A99] rounded-md cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:r.jsx(yn,{children:"Custom key..."})})]})})})]})]}),f&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Custom key name"}),r.jsx("input",{autoFocus:!0,value:o,onChange:b=>l(b.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")),placeholder:"MY_API_KEY",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Value"}),r.jsx("input",{value:c,onChange:b=>d(b.target.value),onKeyDown:b=>{b.key==="Enter"&&m()},placeholder:"Paste your key...",type:"password",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"}),p==="GITHUB_TOKEN"&&r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://github.com/settings/tokens/new?scopes=repo&description=damn.dev",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Generate a token on GitHub ",r.jsx(cs,{className:"w-3 h-3"})]}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Scopes are pre-filled — just click Generate and paste it here."}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Set expiration to 'No expiration' for uninterrupted access."})]}),p==="GITLAB_TOKEN"&&r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://gitlab.com/-/user_settings/personal_access_tokens?name=damn.dev&scopes=api",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:["Generate a token on GitLab ",r.jsx(cs,{className:"w-3 h-3"})]}),r.jsx("span",{className:"block text-[11px] text-[#8A8A99] mt-0.5",children:"Scopes are pre-filled — just click Create and paste it here."})]})]}),r.jsxs("div",{className:"flex gap-2 pt-1",children:[r.jsx("button",{onClick:m,disabled:!p||!c.trim(),className:"flex-1 px-4 py-2 rounded-lg bg-[#6366F1] text-white text-[13px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:"Add key"}),r.jsx("button",{onClick:s,className:"px-4 py-2 rounded-lg text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})]})]})]})}function wW({onSelect:e}){const{data:t=[],isLoading:n,refetch:s}=L.settings.detectObsidianVaults.useQuery(void 0,{staleTime:1/0,enabled:!1}),[i,a]=y.useState(!1);function o(){s().then(()=>a(!0))}return r.jsx("div",{className:"mt-3",children:i?t.length===0?r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"No Obsidian vaults detected."}):r.jsx("div",{className:"flex flex-wrap gap-2",children:t.map(l=>r.jsx("button",{onClick:()=>e(l.path),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] bg-white/[0.03] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:l.name},l.path))}):r.jsxs("button",{onClick:o,disabled:n,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:[r.jsx(lh,{className:`w-3 h-3 ${n?"animate-spin":""}`}),"Detect Obsidian vaults"]})})}function oDe({open:e,onClose:t,onSelect:n}){const[s,i]=y.useState(void 0),{data:a,isLoading:o}=L.settings.listDirectory.useQuery({path:s},{enabled:e}),l=a?.entries??[],c=a?.error,d=s?.split("/").filter(Boolean)??[];function f(g){i(g)}function p(g){const b="/"+d.slice(0,g+1).join("/");i(b)}function m(){s&&(n(s),t())}return r.jsx(ji,{open:e,onOpenChange:g=>{g||t()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-40"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[520px] max-h-[70vh] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl z-50 flex flex-col",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsx(nr,{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Browse folders"}),r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})})]}),r.jsxs("div",{className:"px-5 py-2 border-b border-[#2A2A35] flex items-center gap-1 text-[12px] overflow-x-auto flex-shrink-0",children:[r.jsx("button",{onClick:()=>i(void 0),className:"text-[#6366F1] hover:text-[#818CF8] transition-colors flex-shrink-0",children:"Home"}),d.map((g,b)=>r.jsxs("span",{className:"flex items-center gap-1 flex-shrink-0",children:[r.jsx(Jt,{className:"w-3 h-3 text-[#5A5A6E]"}),r.jsx("button",{onClick:()=>p(b),className:"text-[#6366F1] hover:text-[#818CF8] transition-colors",children:g})]},b))]}),s&&r.jsx("div",{className:"px-5 py-1.5 border-b border-[#2A2A35] flex-shrink-0",children:r.jsx("code",{className:"text-[11px] font-mono text-[#5A5A6E]",children:s})}),r.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2 min-h-[200px]",children:o?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(Pe,{className:"w-5 h-5 text-[#6366F1] animate-spin"})}):c&&l.length===0?r.jsx("div",{className:"flex items-center justify-center py-12 text-[12px] text-[#5A5A6E]",children:c}):l.length===0?r.jsx("div",{className:"flex items-center justify-center py-12 text-[12px] text-[#5A5A6E]",children:"No folders found"}):r.jsxs("div",{className:"space-y-0.5",children:[l.map(g=>r.jsxs("button",{onClick:()=>f(g.path),className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-left hover:bg-white/5 transition-colors group",children:[r.jsx(vm,{className:"w-4 h-4 text-[#6366F1]/70 group-hover:text-[#6366F1] flex-shrink-0"}),r.jsx("span",{className:"text-[13px] text-[#C8C8D4] group-hover:text-[#F0F0F5] truncate",children:g.name})]},g.path)),c&&l.length>0&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] px-3 pt-2",children:c})]})}),r.jsxs("div",{className:"px-5 py-3 border-t border-[#2A2A35] flex items-center justify-end gap-2 flex-shrink-0",children:[r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})}),r.jsx("button",{onClick:m,disabled:!s,className:"px-3 py-1.5 rounded-lg bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:"Select this folder"})]})]})]})})}const sO=[{hostPath:"~/Documents",mountPath:"/host/documents",label:"Documents"},{hostPath:"~/Desktop",mountPath:"/host/desktop",label:"Desktop"},{hostPath:"~/Downloads",mountPath:"/host/downloads",label:"Downloads"},{hostPath:"~/Projects",mountPath:"/host/projects",label:"Projects"}];function lDe(){const[e,t]=y.useState(!1),[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(""),[c,d]=y.useState(!1),[f,p]=y.useState(!1),[m,g]=y.useState(""),[b,_]=y.useState(!1),[w,A]=y.useState(!1),[S,C]=y.useState(!1),[E,k]=y.useState(""),T=L.useUtils(),{data:F}=L.settings.getVolumeMounts.useQuery(),{data:M}=L.settings.getDockerComposeSnippet.useQuery(),{data:I}=L.settings.getRunMode.useQuery(),R=L.settings.addVolumeMount.useMutation({onSuccess:D=>{if(!D.ok&&D.error){g(D.error);return}T.settings.getVolumeMounts.invalidate(),T.settings.getDockerComposeSnippet.invalidate(),t(!1),s(""),a(""),l(""),g(""),_(!0)}}),H=L.settings.removeVolumeMount.useMutation({onSuccess:()=>{T.settings.getVolumeMounts.invalidate(),T.settings.getDockerComposeSnippet.invalidate(),_(!0)}}),V=L.settings.applyMountsAndRestart.useMutation({onSuccess:D=>{D.success?(_(!1),C(!0),k(!D.containerFound||!D.composeEdited?D.reason:""),setTimeout(()=>C(!1),3e3)):k(D.reason)}}),K=F?.mounts??[],q=I?.backendIsNative??!1,$=M?.snippet??"";function B(D){s(D),g("");const Q=D.split("/").pop()?.toLowerCase().replace(/[^a-z0-9_-]/g,"")??"";Q&&(a(`/host/${Q}`),l(D.split("/").pop()??Q)),t(!0)}function Y(D){s(D),g("");const Q=D.replace(/^~\//,"").split("/").pop()?.toLowerCase().replace(/[^a-z0-9_-]/g,"")??"";Q&&(a(`/host/${Q}`),l(D.replace(/^~\//,"").split("/").pop()??Q))}function U(){!n.trim()||!i.trim()||!o.trim()||(g(""),R.mutate({hostPath:n.trim(),mountPath:i.trim(),label:o.trim()}))}function W(){navigator.clipboard.writeText($.replace(/\\n/g,`
428
428
  `)),d(!0),setTimeout(()=>d(!1),1500)}function O(D){K.some(Q=>Q.mountPath===D.mountPath)||R.mutate(D)}return r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6",children:[r.jsxs("div",{className:"flex items-start justify-between mb-5",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(bv,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"File Access"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:"Expose host directories to agents — both gateway and sandbox containers."}),r.jsx("p",{className:"text-[11px] text-[#3E3E4E] mt-1",children:"Note: file access requires OpenClaw to support allowedRoots (coming soon). Mounts are configured and ready — agents will gain access automatically when OpenClaw enables this feature."})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[q&&r.jsxs("button",{onClick:()=>A(!0),className:"flex items-center gap-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(vm,{className:"w-3 h-3"}),"Browse"]}),r.jsxs("button",{onClick:()=>t(D=>!D),className:"flex items-center gap-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(wt,{className:"w-3 h-3"}),"Add folder"]})]})]}),q&&r.jsx(oDe,{open:w,onClose:()=>A(!1),onSelect:B}),r.jsx(Me,{children:e&&r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"mb-4 overflow-hidden",children:r.jsxs("div",{className:"space-y-3 bg-[#13131A] border border-[#2A2A35] rounded-xl p-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Host path"}),r.jsx("input",{autoFocus:!0,value:n,onChange:D=>Y(D.target.value),placeholder:"/Users/you/Documents",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"})]}),r.jsxs("div",{className:"flex gap-3",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Mount path (in container)"}),r.jsx("input",{value:i,onChange:D=>a(D.target.value),placeholder:"/host/documents",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Label"}),r.jsx("input",{value:o,onChange:D=>l(D.target.value),onKeyDown:D=>{D.key==="Enter"&&U()},placeholder:"Documents",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"})]})]}),m&&r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-red-400",children:[r.jsx(Rs,{className:"w-3 h-3"}),m]}),r.jsxs("div",{className:"flex gap-2 pt-1",children:[r.jsx("button",{onClick:U,disabled:!n.trim()||!i.trim()||!o.trim()||R.isPending,className:"px-3 py-1.5 rounded-lg bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:"Add"}),r.jsx("button",{onClick:()=>{t(!1),s(""),a(""),l(""),g("")},className:"px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})]})]})})}),!e&&K.length===0&&r.jsxs("div",{className:"mb-4",children:[r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mb-3",children:"No folders mounted. Quick add:"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:sO.map(D=>r.jsx("button",{onClick:()=>O(D),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] bg-white/[0.03] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:D.label},D.hostPath))})]}),K.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"space-y-1 mb-4",children:K.map(D=>r.jsxs("div",{className:"flex items-center justify-between py-2 px-3 rounded-md bg-white/[0.02] border border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4] truncate",children:D.hostPath}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"→"}),r.jsx("code",{className:"text-[12px] font-mono text-[#8A8A99] truncate",children:D.mountPath}),D.exists?r.jsx("span",{className:"flex items-center gap-1 text-[10px] text-emerald-400 flex-shrink-0",children:r.jsx(Fe,{className:"w-2.5 h-2.5"})}):r.jsx("span",{className:"flex items-center gap-1 text-[10px] text-amber-400 flex-shrink-0",children:r.jsx(Rs,{className:"w-2.5 h-2.5"})})]}),r.jsx(bt,{label:"Remove",children:r.jsx("button",{onClick:()=>H.mutate({hostPath:D.hostPath}),disabled:H.isPending,className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors",children:r.jsx(Dn,{className:"w-3 h-3"})})})]},D.hostPath))}),!e&&r.jsx("div",{className:"flex flex-wrap gap-2 mb-4",children:sO.filter(D=>!K.some(Q=>Q.mountPath===D.mountPath)).map(D=>r.jsxs("button",{onClick:()=>O(D),className:"flex items-center gap-1 px-2 py-1 rounded text-[11px] text-[#5A5A6E] hover:text-[#8A8A99] bg-white/[0.02] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:[r.jsx(wt,{className:"w-2.5 h-2.5"}),D.label]},D.hostPath))}),r.jsxs("div",{className:"border-t border-[#2A2A35] pt-4",children:[b&&r.jsxs("div",{className:"mb-4",children:[r.jsxs(Me,{children:[S&&r.jsxs(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"mb-3 px-3 py-2 rounded-lg bg-emerald-500/10 border border-emerald-500/20 text-[12px] text-emerald-400 flex items-center gap-2",children:[r.jsx(Fe,{className:"w-3 h-3"}),"OpenClaw restarted — agents can now access your files"]}),E&&r.jsxs(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"mb-3 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-[12px] text-amber-400 flex items-center gap-2",children:[r.jsx(Rs,{className:"w-3 h-3 flex-shrink-0"}),r.jsx("span",{className:"truncate",children:E})]})]}),r.jsx("button",{onClick:()=>V.mutate(),disabled:V.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-60",children:V.isPending?r.jsxs(r.Fragment,{children:[r.jsx(Pe,{className:"w-3 h-3 animate-spin"})," Restarting OpenClaw..."]}):r.jsxs(r.Fragment,{children:[r.jsx(Xi,{className:"w-3 h-3"})," Apply & restart OpenClaw"]})})]}),$&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:b?"Or copy snippet manually":"docker-compose snippet"}),r.jsx("button",{onClick:W,className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium transition-colors ${c?"text-emerald-400 bg-emerald-500/10":"text-[#8A8A99] hover:text-[#C8C8D4] bg-white/[0.03] border border-[#2A2A35] hover:border-[#3A3A45]"}`,children:c?r.jsxs(r.Fragment,{children:[r.jsx(Fe,{className:"w-3 h-3"})," Copied!"]}):r.jsxs(r.Fragment,{children:[r.jsx(Po,{className:"w-3 h-3"})," Copy snippet"]})})]}),r.jsx("pre",{className:"bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-4 py-3 text-[12px] font-mono text-[#8A8A99] overflow-x-auto whitespace-pre",children:$.replace(/\\n/g,`
429
429
  `)}),r.jsxs("div",{className:"mt-3",children:[r.jsxs("button",{onClick:()=>p(D=>!D),className:"flex items-center gap-1 text-[11px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:[r.jsx(Jt,{className:`w-3 h-3 transition-transform ${f?"rotate-90":""}`}),"How to apply"]}),r.jsx(Me,{children:f&&r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"overflow-hidden",children:r.jsxs("ol",{className:"mt-2 space-y-1 text-[11px] text-[#5A5A6E] list-decimal list-inside",children:[r.jsxs("li",{children:["Open your ",r.jsx("code",{className:"text-[#8A8A99]",children:"docker-compose.yml"})]}),r.jsxs("li",{children:["Find the ",r.jsx("code",{className:"text-[#8A8A99]",children:"openclaw"})," service"]}),r.jsxs("li",{children:["Paste the snippet above under its ",r.jsx("code",{className:"text-[#8A8A99]",children:"volumes:"})," key"]}),r.jsxs("li",{children:["Run ",r.jsx("code",{className:"text-[#8A8A99]",children:"docker compose up -d"})," to restart"]})]})})})]})]})]})]})]})}function cDe(){const e=L.useUtils(),[t,n]=y.useState(""),[s,i]=y.useState(!1),{data:a}=L.shellExec.getConfig.useQuery(),{data:o=[]}=L.shellExec.getHistory.useQuery({limit:20}),l=L.shellExec.setEnabled.useMutation({onSuccess:()=>{e.shellExec.getConfig.invalidate()}}),c=L.shellExec.addWorkdir.useMutation({onSuccess:()=>{e.shellExec.getConfig.invalidate(),n(""),i(!1)}}),d=L.shellExec.removeWorkdir.useMutation({onSuccess:()=>{e.shellExec.getConfig.invalidate()}}),f=a?.enabled??!0,p=a?.workdirAllowlist??[];return r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6",children:[r.jsxs("div",{className:"flex items-start justify-between mb-5",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Ti,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Shell Execution"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:"Allow agents to run shell commands with an approval gate."})]})]}),r.jsx("button",{onClick:()=>l.mutate({enabled:!f}),disabled:l.isPending,className:`relative w-10 h-5 rounded-full transition-colors duration-200 focus:outline-none ${f?"bg-[#6366F1]":"bg-[#2A2A35]"}`,children:r.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform duration-200 ${f?"translate-x-5":"translate-x-0"}`})})]}),r.jsxs("div",{className:"mb-5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#C8C8D4]",children:"Working directory allowlist"}),r.jsxs("button",{onClick:()=>i(m=>!m),className:"flex items-center gap-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(wt,{className:"w-3 h-3"}),"Add path"]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mb-2",children:"Default: ~/.openclaw, ~/Desktop, ~/Documents, any damn-dev path"}),r.jsx(Me,{children:s&&r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"mb-2 overflow-hidden",children:r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{autoFocus:!0,value:t,onChange:m=>n(m.target.value),onKeyDown:m=>{m.key==="Enter"&&t.trim()&&c.mutate({path:t.trim()}),m.key==="Escape"&&(i(!1),n(""))},placeholder:"/Users/you/projects/my-app",className:"flex-1 bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-1.5 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"}),r.jsx("button",{onClick:()=>{t.trim()&&c.mutate({path:t.trim()})},className:"px-3 py-1.5 rounded-lg bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E8] transition-colors",children:"Add"})]})})}),p.length===0?r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"No custom paths added."}):r.jsx("div",{className:"space-y-1",children:p.map(m=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded-md bg-white/[0.02] border border-[#2A2A35]",children:[r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4]",children:m}),r.jsx(bt,{label:"Remove",children:r.jsx("button",{onClick:()=>d.mutate({path:m}),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors",children:r.jsx(Dn,{className:"w-3 h-3"})})})]},m))})]}),o.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[12px] font-medium text-[#C8C8D4] mb-2",children:"Recent commands"}),r.jsx("div",{className:"space-y-1 max-h-[240px] overflow-y-auto",children:o.map(m=>r.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-2 rounded-md bg-white/[0.02] border border-[#2A2A35]",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${m.success?"bg-[#10B981]":"bg-[#EF4444]"}`}),r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4] flex-1 truncate",children:m.command??"—"}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider flex-shrink-0",children:m.tier??""}),r.jsx("span",{className:"text-[11px] text-[#8A8A99] flex-shrink-0",children:m.durationMs?`${m.durationMs}ms`:""})]},m.id))})]})]})}function uDe(){return iz()?r.jsx(vDe,{}):r.jsx(lm,{to:"/channels/direction",replace:!0})}const iO=[{id:"workspace",label:"Workspace",icon:bv},{id:"integrations",label:"Integrations",icon:bL},{id:"secrets",label:"Secrets",icon:Eo},{id:"runtime",label:"AI & Models",icon:sL},{id:"security",label:"Security",icon:ch},{id:"network",label:"Network",icon:B5},{id:"federation",label:"Federation",icon:Xt},{id:"desktop",label:"Desktop App",icon:Qie,desktopOnly:!0},{id:"mcp",label:"MCP Server",icon:Ti},{id:"keys",label:"Environment",icon:fL,advanced:!0}];function dDe(){const[e,t]=y.useState(""),[n,s]=y.useState(!1),[i,a]=y.useState(!1),[o,l]=y.useState(""),c=L.workspace.getMyMembership.useQuery(),d=L.workspace.listMembers.useQuery(),f=L.useUtils(),p=L.workspace.update.useMutation({onSuccess:()=>{s(!1),f.workspace.getMyMembership.invalidate(),f.workspace.list.invalidate()}}),m=L.workspace.delete.useMutation({onSuccess:()=>{a(!1),l(""),f.invalidate(),window.location.reload()}}),g=c.data,b=d.data??[],_=g?.role==="owner";return r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5] mb-1",children:"Workspace"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Manage your workspace identity and membership."})]}),r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#16161A] p-4 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-[12px] font-semibold text-[#F0F0F5]",children:"Name"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Displayed in the sidebar and workspace switcher."})]}),_&&!n&&r.jsx("button",{onClick:()=>{t(g?.workspaceName??""),s(!0)},className:"text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"Edit"})]}),n?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{autoFocus:!0,value:e,onChange:w=>t(w.target.value),onKeyDown:w=>{w.key==="Enter"&&e.trim()&&p.mutate({name:e.trim()}),w.key==="Escape"&&s(!1)},className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/40"}),r.jsx("button",{onClick:()=>{e.trim()&&p.mutate({name:e.trim()})},disabled:!e.trim()||p.isPending,className:"px-3 py-1.5 rounded bg-[#6366F1]/10 text-[#6366F1] text-[11px] font-medium hover:bg-[#6366F1]/20 transition-colors disabled:opacity-30",children:"Save"}),r.jsx("button",{onClick:()=>s(!1),className:"text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}):r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:g?.workspaceName??"..."})]}),r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#16161A] p-4 space-y-3",children:[r.jsx("h3",{className:"text-[12px] font-semibold text-[#F0F0F5]",children:"Members"}),r.jsx("div",{className:"space-y-1.5",children:b.map(w=>r.jsxs("div",{className:"flex items-center gap-2 py-1",children:[r.jsx("div",{className:"w-6 h-6 rounded-full bg-[#2A2A35] flex items-center justify-center flex-shrink-0",children:r.jsx("span",{className:"text-[10px] text-[#8A8A99]",children:(w.name??w.email).charAt(0).toUpperCase()})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[12px] text-[#F0F0F5] truncate block",children:w.name??w.email}),w.name&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:w.email})]}),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-[#2A2A35] text-[#8A8A99]",children:w.role})]},w.id))})]}),_&&r.jsxs("div",{className:"rounded-lg border border-[#EF4444]/20 bg-[#16161A] p-4 space-y-3",children:[r.jsx("h3",{className:"text-[12px] font-semibold text-[#EF4444]",children:"Danger Zone"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Permanently delete this workspace and all its data. This cannot be undone."}),i?r.jsxs("div",{className:"space-y-2",children:[r.jsxs("p",{className:"text-[11px] text-[#EF4444]",children:["Type ",r.jsx("span",{className:"font-mono font-bold",children:"DELETE"})," to confirm."]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{autoFocus:!0,value:o,onChange:w=>l(w.target.value),onKeyDown:w=>{w.key==="Enter"&&o==="DELETE"&&m.mutate({confirmation:"DELETE"}),w.key==="Escape"&&(a(!1),l(""))},className:"flex-1 bg-[#0F0F11] border border-[#EF4444]/30 rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] outline-none focus:border-[#EF4444]/60"}),r.jsx("button",{onClick:()=>m.mutate({confirmation:"DELETE"}),disabled:o!=="DELETE"||m.isPending,className:"px-3 py-1.5 rounded bg-[#EF4444] text-white text-[11px] font-medium hover:bg-[#DC2626] transition-colors disabled:opacity-30",children:m.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):"Confirm delete"}),r.jsx("button",{onClick:()=>{a(!1),l("")},className:"text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),m.isError&&r.jsx("p",{className:"text-[10px] text-[#EF4444]",children:m.error.message})]}):r.jsx("button",{onClick:()=>a(!0),className:"px-3 py-1.5 rounded bg-[#EF4444]/10 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/20 transition-colors",children:"Delete workspace"})]})]})}function hDe(){const e=L.useUtils(),{data:t,isLoading:n}=L.settings.getTestMode.useQuery(),s=L.settings.setTestMode.useMutation({onSuccess:()=>e.settings.getTestMode.invalidate()}),i=t?.enabled??!1,a=t?.setAt?new Date(t.setAt):null;return r.jsx("div",{className:"rounded-lg border border-[#2A2A35] bg-[#16161A] p-4 space-y-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-9 h-9 rounded-lg bg-[#F59E0B]/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:r.jsx(oL,{className:"w-4.5 h-4.5 text-[#F59E0B]"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:"Test mode"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5 max-w-md",children:"Turn on while stress-testing agents. Disables MEMORY, KNOWLEDGE, and REFLEXION writes across every agent. Nothing from this session will become a durable memory."}),i&&a&&r.jsxs("p",{className:"text-[11px] text-[#FBBF24] mt-1.5",children:["Active since ",a.toLocaleString()]})]})]}),r.jsx("button",{onClick:()=>s.mutate({enabled:!i}),disabled:n||s.isPending,className:ye("relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus:outline-none",i?"bg-[#F59E0B]":"bg-[#2A2A35]",(n||s.isPending)&&"opacity-50"),"aria-pressed":i,"aria-label":"Toggle test mode",children:r.jsx("span",{className:ye("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",i?"translate-x-[18px]":"translate-x-[3px]")})})]})})}function fDe(){const[e,t]=y.useState(""),[n,s]=y.useState(!1),[i,a]=y.useState(new Set),[o,l]=y.useState(null),c=L.memoryInvalidate.scan.useQuery({pattern:e},{enabled:!1,retry:!1}),d=L.memoryInvalidate.invalidate.useMutation({onSuccess:A=>{l(A),a(new Set),s(!1),t("")}});async function f(){e.trim()&&(l(null),a(new Set),await c.refetch(),s(!0))}const p=c.data?.matches??[],m=new Map;for(const A of p){const S=m.get(A.agentId)??[];S.push(A),m.set(A.agentId,S)}function g(){i.size===p.length?a(new Set):a(new Set(p.map(A=>A.id)))}function b(A){const S=new Set(i);S.has(A)?S.delete(A):S.add(A),a(S)}function _(){i.size!==0&&d.mutate({matchIds:Array.from(i)})}const w={REFLEXION:"text-[#F59E0B]",KNOWLEDGE:"text-[#60A5FA]",MEMORY:"text-[#A78BFA]"};return r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#16161A] p-4 space-y-4",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-9 h-9 rounded-lg bg-[#EF4444]/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:r.jsx(Io,{className:"w-4.5 h-4.5 text-[#EF4444]"})}),r.jsxs("div",{className:"flex-1",children:[r.jsx("h3",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:"Purge agent memories"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5 max-w-md",children:"Grep MEMORY, KNOWLEDGE, and REFLEXION across every agent. Preview matches, pick what to remove, apply. Atomic writes — matched entries gone, everything else untouched."})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{value:e,onChange:A=>t(A.target.value),onKeyDown:A=>A.key==="Enter"&&f(),placeholder:"Pattern (plain text or regex)",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/40"}),r.jsx("button",{onClick:f,disabled:!e.trim()||c.isFetching,className:"px-3 py-1.5 rounded bg-[#6366F1]/10 text-[#6366F1] text-[11px] font-medium hover:bg-[#6366F1]/20 transition-colors disabled:opacity-30",children:c.isFetching?"Scanning…":"Scan"})]}),o&&r.jsxs("div",{className:"text-[11px] text-emerald-400",children:["Removed ",o.removed," ",o.removed===1?"entry":"entries",".",o.errors.length>0&&r.jsxs("span",{className:"text-[#EF4444] ml-2",children:[o.errors.length," error",o.errors.length===1?"":"s","."]})]}),n&&!c.isFetching&&p.length===0&&r.jsx("div",{className:"text-[11px] text-[#5A5A6E]",children:"No matches."}),p.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between text-[11px] text-[#8A8A99]",children:[r.jsx("button",{onClick:g,className:"hover:text-[#F0F0F5] transition-colors",children:i.size===p.length?"Deselect all":`Select all (${p.length})`}),r.jsx("button",{onClick:_,disabled:i.size===0||d.isPending,className:"px-3 py-1 rounded bg-[#EF4444]/10 text-[#EF4444] text-[11px] font-medium hover:bg-[#EF4444]/20 transition-colors disabled:opacity-30",children:d.isPending?"Removing…":`Remove selected (${i.size})`})]}),r.jsx("div",{className:"max-h-96 overflow-y-auto space-y-3 pr-1",children:Array.from(m.entries()).map(([A,S])=>r.jsxs("div",{className:"space-y-1",children:[r.jsx("div",{className:"text-[11px] font-semibold text-[#8A8A99]",children:A}),S.map(C=>r.jsxs("label",{className:"flex items-start gap-2 py-1.5 px-2 rounded hover:bg-[#0F0F11] cursor-pointer transition-colors",children:[r.jsx("input",{type:"checkbox",checked:i.has(C.id),onChange:()=>b(C.id),className:"mt-0.5"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[r.jsx("span",{className:ye("font-mono",w[C.file]),children:C.file}),r.jsxs("span",{className:"text-[#5A5A6E]",children:["line ",C.startLine+1]})]}),r.jsx("div",{className:"text-[12px] text-[#D0D0D8] truncate",children:C.preview})]})]},C.id))]},A))})]})]})}function pDe(){const[e,t]=y.useState(!1),[n,s]=y.useState(!1),[i,a]=y.useState(null),[o,l]=y.useState(null),c=L.useUtils(),d=L.settings.restartOpenClaw.useMutation({onSuccess:S=>{l(S),S.kind==="restarted"&&setTimeout(()=>{s(!1),l(null)},4e3)},onError:S=>{l({kind:"failed",method:"rpc-error",error:S.message})}}),{data:f=[],isLoading:p}=L.settings.getEnvVars.useQuery(),{data:m=[]}=L.settings.getKnownKeys.useQuery(),g=L.settings.setEnvVar.useMutation({onSuccess:(S,C)=>{c.settings.getEnvVars.invalidate(),S.restartRequired&&(s(!0),a(C.key))}}),b=L.settings.deleteEnvVar.useMutation({onSuccess:()=>{c.settings.getEnvVars.invalidate()}}),_=L.settings.moveKeyToSecrets.useMutation({onSuccess:()=>{c.settings.getEnvVars.invalidate(),c.settings.getKeyDrift.invalidate(),c.secrets.list.invalidate()}}),w=f.map(S=>S.key),A=f.some(S=>S.key==="OBSIDIAN_VAULT_PATH");return r.jsxs(r.Fragment,{children:[r.jsx(Me,{children:n&&r.jsxs(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:ye("mb-6 px-4 py-3 rounded-xl border flex items-start gap-3",o?.kind==="restarted"?"bg-emerald-500/[0.08] border-emerald-500/20":o?.kind==="failed"?"bg-red-500/[0.08] border-red-500/20":"bg-amber-500/[0.08] border-amber-500/20"),children:[o?.kind==="restarted"?r.jsx(Fe,{className:"w-4 h-4 text-emerald-400 flex-shrink-0 mt-0.5"}):r.jsx(Rs,{className:ye("w-4 h-4 flex-shrink-0 mt-0.5",o?.kind==="failed"?"text-red-400":"text-amber-400")}),r.jsx("div",{className:"flex-1 min-w-0",children:o?.kind==="restarted"?r.jsxs(r.Fragment,{children:[r.jsxs("p",{className:"text-[13px] text-emerald-300/90 font-medium",children:["OpenClaw restarted"," ",r.jsxs("span",{className:"text-emerald-300/60 font-normal",children:["via ",o.method," · ",Math.round(o.durationMs/100)/10,"s"]})]}),o.envVerified&&r.jsx("p",{className:"text-[12px] text-emerald-300/70 mt-0.5",children:o.envVerified.matched?r.jsxs(r.Fragment,{children:["✓ ",r.jsx("code",{className:"font-mono",children:o.envVerified.key})," is live in the container."]}):r.jsxs(r.Fragment,{children:["⚠ ",r.jsx("code",{className:"font-mono",children:o.envVerified.key})," still didn't show inside the container — something else is caching it."]})})]}):o?.kind==="skipped"?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[13px] text-amber-300/90 font-medium",children:"Restart skipped"}),r.jsx("p",{className:"text-[12px] text-amber-300/70 mt-0.5",children:o.reason}),o.detail&&r.jsx("p",{className:"text-[11px] text-amber-300/50 mt-1 leading-relaxed",children:o.detail})]}):o?.kind==="failed"?r.jsxs(r.Fragment,{children:[r.jsxs("p",{className:"text-[13px] text-red-300/90 font-medium",children:["Restart failed"," ",r.jsxs("span",{className:"text-red-300/60 font-normal",children:["(",o.method,")"]})]}),r.jsx("p",{className:"text-[12px] text-red-300/70 mt-0.5",children:o.error}),o.stderr&&r.jsx("pre",{className:"text-[11px] text-red-300/50 mt-1 whitespace-pre-wrap font-mono bg-red-500/[0.05] px-2 py-1 rounded max-h-32 overflow-auto",children:o.stderr}),o.container&&r.jsxs("p",{className:"text-[11px] text-red-300/50 mt-1",children:["Fallback: ",r.jsxs("code",{className:"font-mono",children:["docker restart ",o.container]})]})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[13px] text-amber-300/90 font-medium",children:"OpenClaw restart required"}),r.jsx("p",{className:"text-[12px] text-amber-300/60 mt-0.5",children:"New env vars won't take effect until OpenClaw restarts."})]})}),r.jsx("button",{onClick:()=>d.mutate(i?{verifyKey:i}:void 0),disabled:d.isPending,className:ye("flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium border transition-colors disabled:opacity-50 flex-shrink-0",o?.kind==="restarted"?"bg-emerald-500/10 text-emerald-300 hover:bg-emerald-500/20 border-emerald-500/20":o?.kind==="failed"?"bg-red-500/10 text-red-300 hover:bg-red-500/20 border-red-500/20":"bg-amber-500/10 text-amber-300 hover:bg-amber-500/20 border-amber-500/20"),children:o?.kind==="restarted"?r.jsxs(r.Fragment,{children:[r.jsx(Fe,{className:"w-3.5 h-3.5"})," Restarted"]}):r.jsxs(r.Fragment,{children:[r.jsx(Xi,{className:ye("w-3.5 h-3.5",d.isPending&&"animate-spin")})," ",o?"Retry":"Restart now"]})})]})}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Environment"}),r.jsxs("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:["Low-level env vars read by the backend and agent containers. Most users want"," ",r.jsx("button",{onClick:()=>{const S=new URLSearchParams(window.location.search);S.set("tab","secrets"),window.history.replaceState(null,"",`?${S}`),window.location.reload()},className:"text-[#6366F1] hover:text-[#818CF8] transition-colors underline underline-offset-2",children:"Secrets"})," ","for API keys instead."]})]}),r.jsxs("button",{onClick:()=>t(S=>!S),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 border border-[#6366F1]/30 transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add variable"]})]}),r.jsx(Me,{children:e&&r.jsx(aDe,{knownKeys:m,existingKeys:w,onAdd:(S,C)=>g.mutate({key:S,value:C}),onClose:()=>t(!1)})}),p&&r.jsx("div",{className:"py-8 flex justify-center",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}),!p&&f.length===0&&!e&&r.jsxs("div",{className:"py-8 text-center",children:[r.jsx("p",{className:"text-[13px] text-[#5A5A6E]",children:"No API keys configured yet."}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-1",children:"Add your first key to get started."})]}),f.map(S=>r.jsx(rDe,{entry:S,onDelete:C=>b.mutate({key:C}),onSave:(C,E)=>g.mutate({key:C,value:E}),onMoveToSecrets:C=>_.mutate({key:C})},S.key)),!A&&!e&&r.jsxs("div",{className:"pt-4 mt-2 border-t border-[#2A2A35]",children:[r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mb-2",children:"Obsidian not configured"}),r.jsx(wW,{onSelect:S=>g.mutate({key:"OBSIDIAN_VAULT_PATH",value:S})})]})]})]})}function mDe(){const e=L.useUtils(),{data:t=[],isLoading:n}=L.secrets.list.useQuery(),{data:s=[]}=L.settings.getKnownKeys.useQuery(),[i,a]=y.useState(!1),[o,l]=y.useState(""),[c,d]=y.useState(""),[f,p]=y.useState(""),[m,g]=y.useState(null),b=L.secrets.set.useMutation({onSuccess:()=>{e.secrets.list.invalidate(),e.settings.getKeyDrift.invalidate(),a(!1),l(""),d(""),p(""),g(null)},onError:E=>g(E.message)}),_=L.secrets.delete.useMutation({onSuccess:()=>{e.secrets.list.invalidate(),e.settings.getKeyDrift.invalidate()}}),w=L.secrets.moveKeyToEnvironment.useMutation({onSuccess:()=>{e.secrets.list.invalidate(),e.settings.getEnvVars.invalidate(),e.settings.getKeyDrift.invalidate()}}),A=new Map(s.map(E=>[E.key,E])),S=new Map(t.map(E=>[E.key,A.get(E.key)?.kind]));function C(){const E=o.trim(),k=c;!E||!k||b.mutate({key:E,value:k,description:f.trim()||void 0})}return r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6",children:[r.jsxs("div",{className:"flex items-start justify-between mb-5",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Eo,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Workspace Secrets"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:"Encrypted API keys skills use to authenticate with external services. Never shown to agents or humans after save."})]})]}),r.jsxs("button",{onClick:()=>{a(E=>!E),g(null)},className:"flex items-center gap-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(wt,{className:"w-3 h-3"}),"Add secret"]})]}),r.jsx(Me,{children:i&&r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"mb-4 overflow-hidden",children:r.jsxs("div",{className:"space-y-3 bg-[#13131A] border border-[#2A2A35] rounded-xl p-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Key"}),r.jsx("input",{autoFocus:!0,value:o,onChange:E=>l(E.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")),placeholder:"MY_API_KEY",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Uppercase, letters/digits/underscore, starts with a letter, max 64 chars."})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Value"}),r.jsx("input",{type:"password",value:c,onChange:E=>d(E.target.value),onKeyDown:E=>{E.key==="Enter"&&C()},placeholder:"Paste your secret...",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1.5",children:"Description (optional)"}),r.jsx("input",{value:f,onChange:E=>p(E.target.value),placeholder:"Used by the X skill for API calls",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60 transition-colors"})]}),m&&r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-red-400",children:[r.jsx(Rs,{className:"w-3 h-3"}),m]}),r.jsxs("div",{className:"flex gap-2 pt-1",children:[r.jsx("button",{onClick:C,disabled:!o.trim()||!c||b.isPending,className:"px-3 py-1.5 rounded-lg bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:"Save secret"}),r.jsx("button",{onClick:()=>{a(!1),l(""),d(""),p(""),g(null)},className:"px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Cancel"})]})]})})}),n&&r.jsx("div",{className:"py-8 flex justify-center",children:r.jsx(Pe,{className:"w-5 h-5 text-[#6366F1] animate-spin"})}),!n&&t.length===0&&!i&&r.jsxs("div",{className:"py-8 text-center",children:[r.jsx("p",{className:"text-[13px] text-[#5A5A6E]",children:"No secrets configured yet."}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-1",children:"Skills that need authenticated API access will ask you to add the secrets they need."})]}),t.map(E=>{const k=S.get(E.key),T=k==="env"||k==="path";return r.jsxs("div",{className:"flex items-start gap-4 py-4 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx("code",{className:"text-[13px] font-mono font-medium text-[#F0F0F5]",children:E.key}),E.description&&r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:E.description})]}),E.hasValue&&r.jsx("code",{className:"text-[12px] font-mono text-[#8A8A99]",children:"••••••••"}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-1",children:["Updated ",new Date(E.updatedAt).toLocaleDateString()]})]}),T&&r.jsx(bt,{label:k==="path"?"This is a filesystem path, not a credential — move it to Environment":"This is infra config, not a credential — move it to Environment",children:r.jsx("button",{onClick:()=>w.mutate({key:E.key}),disabled:w.isPending,className:"flex items-center gap-1 px-2 h-7 rounded-md text-[11px] font-medium bg-amber-500/10 text-amber-300 hover:bg-amber-500/20 border border-amber-500/20 transition-colors disabled:opacity-50",children:"Move to Environment"})}),r.jsx(bt,{label:"Delete secret",children:r.jsx("button",{onClick:()=>_.mutate({key:E.key}),className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]},E.key)})]})}function xDe(){return r.jsxs("div",{className:"space-y-6",children:[r.jsx(cDe,{}),r.jsx(lDe,{}),r.jsx(kDe,{})]})}function gDe(){const e=L.useUtils(),{data:t,isLoading:n}=L.integrations.obsidian.status.useQuery(),s=L.integrations.obsidian.enable.useMutation({onSuccess:()=>{e.integrations.obsidian.status.invalidate()}}),i=L.integrations.obsidian.disable.useMutation({onSuccess:()=>{e.integrations.obsidian.status.invalidate()}}),a=L.integrations.obsidian.updateMode.useMutation({onSuccess:()=>{e.integrations.obsidian.status.invalidate()}}),[o,l]=y.useState(""),[c,d]=y.useState(!1),[f,p]=y.useState(!1);return n||!t?r.jsx("div",{className:"rounded-xl border border-[#2A2A35] bg-[#16161A] p-5",children:r.jsx(Pe,{className:"w-4 h-4 animate-spin text-[#5A5A6E]"})}):r.jsxs("div",{className:"rounded-xl border border-[#2A2A35] bg-[#16161A] p-5 space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-9 h-9 rounded-lg bg-[#7C3AED]/10 flex items-center justify-center",children:r.jsx(li,{className:"w-4.5 h-4.5 text-[#7C3AED]"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:"Obsidian"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Give agents access to your vault notes"})]})]}),t.enabled&&!f&&r.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-emerald-400",children:[r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-400"}),"Active"]})]}),t.enabled&&!f?r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"space-y-2 text-[12px]",children:[r.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Vault"}),r.jsx("span",{className:"text-[#C8C8D4] font-mono text-[11px]",children:t.vaultPath})]}),r.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Mount"}),r.jsxs("span",{className:"text-[#C8C8D4] font-mono text-[11px]",children:[t.mountPath," (",t.writable?"read & write":"read-only",")"]})]}),r.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Agents"}),r.jsxs("span",{className:"text-[#C8C8D4]",children:[t.agentCount," of ",t.totalAgents," with skill active"]})]})]}),r.jsxs("div",{className:"flex items-center gap-3 pt-1",children:[r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"radio",name:"obsidian-mode",checked:!t.writable,onChange:()=>a.mutate({writable:!1}),className:"accent-[#6366F1]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:"Read-only"})]}),r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"radio",name:"obsidian-mode",checked:t.writable,onChange:()=>a.mutate({writable:!0}),className:"accent-[#6366F1]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:"Read & write"})]})]}),r.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[r.jsx("button",{onClick:()=>p(!0),className:"px-3 py-1.5 rounded-lg text-[11px] text-[#8A8A99] hover:text-[#C8C8D4] border border-[#2A2A35] hover:border-[#3A3A45] transition-colors",children:"Change vault"}),r.jsx("button",{onClick:()=>i.mutate(),disabled:i.isPending,className:"px-3 py-1.5 rounded-lg text-[11px] text-red-400/70 hover:text-red-400 border border-red-500/20 hover:border-red-500/30 transition-colors disabled:opacity-50",children:i.isPending?"Disabling...":"Disable"})]})]}):r.jsxs("div",{className:"space-y-3",children:[o?r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-white/[0.03] border border-[#2A2A35]",children:[r.jsx(vm,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] font-mono flex-1 truncate",children:o}),r.jsx("button",{onClick:()=>l(""),className:"text-[#5A5A6E] hover:text-[#8A8A99]",children:r.jsx(Te,{className:"w-3 h-3"})})]}):r.jsx(wW,{onSelect:m=>l(m)}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"radio",name:"obsidian-setup-mode",checked:!c,onChange:()=>d(!1),className:"accent-[#6366F1]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:"Read-only"})]}),r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"radio",name:"obsidian-setup-mode",checked:c,onChange:()=>d(!0),className:"accent-[#6366F1]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:"Read & write"})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:()=>{o&&(s.mutate({vaultPath:o,writable:c}),p(!1))},disabled:!o||s.isPending,className:"px-4 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 transition-colors disabled:opacity-30",children:s.isPending?"Enabling...":"Enable"}),f&&r.jsx("button",{onClick:()=>{p(!1),l("")},className:"px-3 py-1.5 rounded-lg text-[11px] text-[#8A8A99] hover:text-[#C8C8D4] transition-colors",children:"Cancel"})]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed pt-1",children:"Only agents with the obsidian-builtin skill enabled can see vault guidance. Toggle per-agent in Settings → Agents → Skills."})]})}function bDe(){return r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5] mb-1",children:"Integrations"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Connect external tools and services to your workspace agents."})]}),r.jsx(gDe,{})]})}function vDe(){const[e]=kO(),t=e.get("tab"),[n,s]=y.useState(t&&iO.some(f=>f.id===t)?t:"secrets"),[i,a]=y.useState(n==="keys"),o=iO.filter(f=>!f.desktopOnly||Va),l=o.filter(f=>!f.advanced),c=o.filter(f=>f.advanced);function d(f){const p=f.icon;return r.jsxs("button",{onClick:()=>s(f.id),className:ye("w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-[13px] transition-colors",n===f.id?"bg-white/[0.07] text-[#F0F0F5] font-medium":"text-[#8A8A99] hover:text-[#C8C8D4] hover:bg-white/[0.03]"),children:[r.jsx(p,{className:"w-4 h-4 flex-shrink-0"}),f.label]},f.id)}return r.jsxs("div",{className:"flex-1 flex bg-[#0F0F11] overflow-hidden",children:[r.jsxs("nav",{className:"w-[200px] flex-shrink-0 border-r border-[#2A2A35] py-8 px-3 overflow-y-auto",children:[r.jsx("h1",{className:"text-[15px] font-semibold text-[#F0F0F5] px-3 mb-6",children:"Settings"}),r.jsx("div",{className:"space-y-0.5",children:l.map(d)}),c.length>0&&r.jsxs("div",{className:"mt-6",children:[r.jsxs("button",{onClick:()=>a(f=>!f),className:"w-full flex items-center gap-2 px-3 py-2 rounded-lg text-[11px] uppercase tracking-wider text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:[r.jsx(Jt,{className:ye("w-3 h-3 transition-transform",i&&"rotate-90")}),"Advanced"]}),i&&r.jsx("div",{className:"space-y-0.5 mt-0.5",children:c.map(d)})]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto py-8 px-10",children:r.jsxs("div",{className:"max-w-2xl",children:[r.jsx(yDe,{onOpenTab:s}),n==="workspace"&&r.jsxs(r.Fragment,{children:[r.jsx(dDe,{}),r.jsx(hDe,{}),r.jsx(fDe,{})]}),n==="integrations"&&r.jsx(bDe,{}),n==="keys"&&r.jsx(pDe,{}),n==="secrets"&&r.jsx(mDe,{}),n==="runtime"&&r.jsxs(r.Fragment,{children:[r.jsx(wDe,{}),r.jsx(SDe,{}),r.jsx(CDe,{}),r.jsx(jDe,{})]}),n==="security"&&r.jsx(xDe,{}),n==="network"&&r.jsx(NDe,{}),n==="federation"&&r.jsx(FDe,{}),n==="desktop"&&r.jsx(EDe,{}),n==="mcp"&&r.jsx(iDe,{})]})})]})}function yDe({onOpenTab:e}){const t=L.useUtils(),{data:n}=L.settings.getKeyDrift.useQuery(void 0,{staleTime:3e4}),s=L.settings.moveKeyToSecrets.useMutation({onSuccess:()=>{t.settings.getKeyDrift.invalidate(),t.settings.getEnvVars.invalidate(),t.secrets.list.invalidate()}}),i=L.secrets.moveKeyToEnvironment.useMutation({onSuccess:()=>{t.settings.getKeyDrift.invalidate(),t.settings.getEnvVars.invalidate(),t.secrets.list.invalidate()}}),a=n?.issues??[];if(a.length===0)return null;const o=a.filter(d=>d.kind==="misplaced-in-env"),l=a.filter(d=>d.kind==="misplaced-in-secrets"),c=a.filter(d=>d.kind==="value-mismatch");return r.jsx("div",{className:"mb-6 px-4 py-3 rounded-xl bg-amber-500/[0.08] border border-amber-500/20",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Rs,{className:"w-4 h-4 text-amber-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[r.jsxs("p",{className:"text-[13px] text-amber-300/90 font-medium",children:[a.length," credential",a.length===1?"":"s"," in the wrong place"]}),o.length>0&&r.jsxs("div",{className:"text-[12px] text-amber-300/70 space-y-1",children:[r.jsx("p",{children:"These API credentials are stored as plain env vars. Encrypt them in Secrets (the env copy stays in place as a mirror so nothing breaks):"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:o.map(d=>r.jsxs("button",{onClick:()=>s.mutate({key:d.key}),disabled:s.isPending,className:"font-mono text-[11px] px-2 py-0.5 rounded bg-amber-500/10 text-amber-300 hover:bg-amber-500/20 border border-amber-500/20 transition-colors disabled:opacity-50",children:["Encrypt ",d.key]},d.key))})]}),l.length>0&&r.jsxs("div",{className:"text-[12px] text-amber-300/70 space-y-1",children:[r.jsx("p",{children:"These are infra or paths stored in Secrets. Move them to Environment where they belong:"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:l.map(d=>r.jsxs("button",{onClick:()=>i.mutate({key:d.key}),disabled:i.isPending,className:"font-mono text-[11px] px-2 py-0.5 rounded bg-amber-500/10 text-amber-300 hover:bg-amber-500/20 border border-amber-500/20 transition-colors disabled:opacity-50",children:[d.key," → Environment"]},d.key))})]}),c.length>0&&r.jsxs("div",{className:"text-[12px] text-amber-300/70 space-y-1",children:[r.jsx("p",{children:"These keys exist in both stores with different values — a skill might read one, an agent another. Pick the authoritative value:"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:c.map(d=>r.jsx("button",{onClick:()=>e("secrets"),className:"font-mono text-[11px] px-2 py-0.5 rounded bg-amber-500/10 text-amber-300 hover:bg-amber-500/20 border border-amber-500/20 transition-colors",children:d.key},d.key))})]})]})]})})}const rO={openclaw:"OpenClaw",anthropic:"Anthropic","claude-code":"Claude Code",ollama:"Ollama",openrouter:"OpenRouter"},_De=["openclaw","anthropic","claude-code","ollama","openrouter"];function wDe(){const{data:e}=L.onboarding.getGatewayConfig.useQuery(),{data:t,refetch:n}=L.onboarding.getGatewayHealth.useQuery(void 0,{refetchInterval:3e4}),s=L.useUtils(),i=L.onboarding.setGatewayConfig.useMutation({onSuccess:()=>{s.onboarding.getGatewayConfig.invalidate(),n()}}),[a,o]=y.useState(!1),[l,c]=y.useState("anthropic"),[d,f]=y.useState(""),p=e?.gatewayType??"openclaw";function m(b){const _=e?.gatewayConfig?JSON.parse(e.gatewayConfig):{};i.mutate({gatewayType:b,gatewayConfig:JSON.stringify(_)})}function g(){const b={};l!=="openclaw"&&l!=="ollama"&&(b.apiKey=d),i.mutate({gatewayType:l,gatewayConfig:JSON.stringify(b)}),o(!1),f("")}return r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6",children:[r.jsxs("div",{className:"flex items-start justify-between mb-5",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Xi,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"AI Runtime"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:"Configure which AI gateway agents use by default."})]})]}),r.jsxs("button",{onClick:()=>o(!a),className:"flex items-center gap-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Switch runtime"]})]}),r.jsx("div",{className:"space-y-2",children:t?.map(b=>r.jsxs("div",{className:`flex items-center justify-between px-3 py-2.5 rounded-lg border ${b.isDefault?"border-[#6366F1]/30 bg-[#6366F1]/5":"border-[#2A2A35] bg-[#1C1C21]"}`,children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:`w-2 h-2 rounded-full ${b.ok?"bg-[#10B981]":"bg-[#EF4444]"}`}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5]",children:b.name}),b.isDefault&&r.jsx("span",{className:"text-[10px] text-[#6366F1] bg-[#6366F1]/10 px-1.5 py-0.5 rounded",children:"default"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[b.latencyMs!==void 0&&r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[b.latencyMs,"ms"]}),!b.isDefault&&r.jsx("button",{onClick:()=>m(b.id),className:"text-[11px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:"Set default"})]})]},b.id))??r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 rounded-lg border border-[#2A2A35] bg-[#1C1C21]",children:[r.jsx("div",{className:"w-2 h-2 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("span",{className:"text-[13px] text-[#5A5A6E]",children:"Loading..."})]})}),r.jsx(Me,{children:a&&r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"overflow-hidden",children:r.jsxs("div",{className:"pt-4 mt-4 border-t border-[#2A2A35] space-y-3",children:[r.jsxs(ss,{value:l,onValueChange:c,children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#1C1C21] text-[13px] text-[#F0F0F5]",children:[r.jsx(Ds,{}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{className:"bg-[#1C1C21] border border-[#2A2A35] rounded-lg shadow-xl z-[9999] overflow-hidden",children:r.jsx(os,{className:"p-1",children:_De.map(b=>r.jsxs(vn,{value:b,className:"flex items-center gap-2 px-3 py-2 rounded text-[13px] text-[#F0F0F5] cursor-pointer outline-none data-[highlighted]:bg-[#2A2A35]",children:[r.jsx(yn,{children:rO[b]}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"})})]},b))})})})]}),l!=="openclaw"&&l!=="ollama"&&r.jsx("input",{type:"password",placeholder:"API key",value:d,onChange:b=>f(b.target.value),className:"w-full px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#1C1C21] text-[13px] text-[#F0F0F5] placeholder:text-[#3E3E4E] outline-none focus:border-[#6366F1]/50"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:g,disabled:i.isPending||l!=="openclaw"&&l!=="ollama"&&!d,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#818CF8] disabled:opacity-50 transition-colors",children:i.isPending?"Saving...":"Set as default"}),r.jsx("button",{onClick:()=>o(!1),className:"px-4 py-2 rounded-lg text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3E3E4E] transition-colors",children:"Cancel"})]})]})})}),r.jsxs("p",{className:"text-[10px] text-[#3E3E4E] mt-3",children:["Current: ",rO[p]??p,". Agents can override this in their Model tab."]})]})}const ADe=[{id:"openrouter",label:"OpenRouter",description:"Multi-provider gateway. Free + paid models from Anthropic, OpenAI, Google, Meta and many more."},{id:"anthropic",label:"Anthropic",description:"Direct API. Claude Haiku, Sonnet, Opus."},{id:"openai",label:"OpenAI",description:"Direct API. GPT-4o, GPT-4o mini, o1."},{id:"google",label:"Google",description:"Direct Gemini API. Gemini 2.5 Pro, Flash."}];function aO(e){return e==="google"?"gemini":e}function SDe(){const e=L.useUtils(),{data:t}=L.onboarding.providersConfigured.useQuery(),{data:n}=L.onboarding.discoverProviderModels.useQuery(),s=L.onboarding.validateApiKey.useMutation(),i=L.onboarding.removeProviderKey.useMutation({onSuccess:()=>{e.onboarding.providersConfigured.invalidate(),e.onboarding.discoverProviderModels.invalidate()}}),[a,o]=y.useState(null),[l,c]=y.useState(""),[d,f]=y.useState(null);function p(b){o(b),c(""),f(null)}function m(){o(null),c(""),f(null)}async function g(b){const _=l.trim();if(!_)return;if(f(null),!(await s.mutateAsync({provider:aO(b),key:_})).valid){f({provider:b,msg:"Key validation failed. Check that the key is correct and active."});return}o(null),c(""),e.onboarding.providersConfigured.invalidate(),e.onboarding.discoverProviderModels.invalidate()}return r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6 mt-4",children:[r.jsxs("div",{className:"flex items-start gap-3 mb-5",children:[r.jsx(fL,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Model Providers"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:"API keys the OpenClaw gateway uses to route to hosted providers. Keys are validated on save and never shown after."})]})]}),r.jsx("div",{className:"space-y-2",children:ADe.map(({id:b,label:_,description:w})=>{const A=!!t?.[b],S=n?.[b]?.length??0,C=a===b,E=s.isPending&&s.variables?.provider===aO(b),k=i.isPending&&i.variables?.provider===b;return r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] px-4 py-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:_}),A?r.jsxs("span",{className:"text-[10px] text-[#10B981] bg-[#10B981]/10 px-1.5 py-0.5 rounded",children:["configured · ",S," model",S===1?"":"s"]}):r.jsx("span",{className:"text-[10px] text-[#5A5A6E] bg-[#5A5A6E]/10 px-1.5 py-0.5 rounded",children:"not configured"})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:w})]}),!C&&r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[r.jsx("button",{onClick:()=>p(b),className:"text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:A?"Update":"Add key"}),A&&r.jsx("button",{onClick:()=>i.mutate({provider:b}),disabled:k,className:"text-[11px] text-[#8A8A99] hover:text-[#F87171] transition-colors disabled:opacity-50",children:k?"Removing...":"Remove"})]})]}),r.jsx(Me,{children:C&&r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"overflow-hidden",children:r.jsxs("div",{className:"pt-3 mt-3 border-t border-[#2A2A35] space-y-2",children:[r.jsx("input",{type:"password",autoFocus:!0,placeholder:`${_} API key`,value:l,onChange:T=>c(T.target.value),onKeyDown:T=>{T.key==="Enter"&&g(b),T.key==="Escape"&&m()},className:"w-full px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#13131A] text-[12px] text-[#F0F0F5] placeholder:text-[#3E3E4E] outline-none focus:border-[#6366F1]/50"}),d?.provider===b&&r.jsx("p",{className:"text-[11px] text-[#F87171]",children:d.msg}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>g(b),disabled:E||!l.trim(),className:"flex-1 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#818CF8] disabled:opacity-50 transition-colors",children:E?"Validating...":"Save"}),r.jsx("button",{onClick:m,className:"px-4 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] hover:border-[#3E3E4E] transition-colors",children:"Cancel"})]})]})})})]},b)})})]})}function CDe(){const{data:e,refetch:t}=L.settings.getOpenClawVersion.useQuery(void 0,{refetchInterval:6e4}),n=L.settings.updateOpenClaw.useMutation({onSuccess:()=>{setTimeout(()=>t(),5e3)}});return e?.current?r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6 mt-4",children:[r.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[r.jsx(Xi,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"OpenClaw Version"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:"Runtime version and updates."})]})]}),r.jsxs("div",{className:"flex items-center justify-between px-3 py-2.5 rounded-lg border border-[#2A2A35] bg-[#1C1C21]",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:`w-2 h-2 rounded-full ${e.updateAvailable?"bg-amber-400":"bg-[#10B981]"}`}),r.jsxs("span",{className:"text-[13px] text-[#F0F0F5]",children:["v",e.current]}),e.updateAvailable&&r.jsxs("span",{className:"text-[10px] text-amber-400 bg-amber-400/10 px-1.5 py-0.5 rounded",children:["update available — minimum v",e.minimum]}),!e.updateAvailable&&r.jsx("span",{className:"text-[10px] text-[#10B981] bg-[#10B981]/10 px-1.5 py-0.5 rounded",children:"up to date"})]}),e.updateAvailable&&r.jsx("button",{onClick:()=>n.mutate(),disabled:n.isPending,className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium bg-[#6366F1]/20 text-[#818CF8] hover:bg-[#6366F1]/30 disabled:opacity-50 transition-colors",children:n.isPending?r.jsxs(r.Fragment,{children:[r.jsx(Pe,{className:"w-3 h-3 animate-spin"}),"Updating..."]}):"Update now"})]}),n.isSuccess&&n.data.ok&&r.jsxs("p",{className:"text-[11px] text-[#10B981] mt-2",children:["Updated",n.data.newVersion?` to v${n.data.newVersion}`:"",". OpenClaw is restarting."]}),n.isSuccess&&!n.data.ok&&r.jsxs("p",{className:"text-[11px] text-[#F87171] mt-2",children:["Update failed: ",n.data.error]}),n.isError&&r.jsxs("p",{className:"text-[11px] text-[#F87171] mt-2",children:["Update failed: ",n.error.message]})]}):null}function jDe(){const{data:e}=L.onboarding.getState.useQuery(),t=L.useUtils(),n=L.onboarding.setDefaultModels.useMutation({onSuccess:()=>t.onboarding.getState.invalidate()}),{groups:s}=Vm(),[i,a]=y.useState(""),[o,l]=y.useState(""),[c,d]=y.useState(!1);y.useEffect(()=>{e?.defaultReasoningModel&&!i&&a(e.defaultReasoningModel),e?.defaultFastModel&&!o&&l(e.defaultFastModel)},[e?.defaultReasoningModel,e?.defaultFastModel]);function f(){!i||!o||n.mutate({reasoningModel:i,fastModel:o},{onSuccess:()=>d(!1)})}return r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6 mt-4",children:[r.jsxs("div",{className:"flex items-start gap-3 mb-5",children:[r.jsx(sL,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Default Models"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:"Applies to new agents. Existing agents keep their current model."})]})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Primary (reasoning)"}),r.jsxs(ss,{value:i,onValueChange:p=>{a(p),d(!0)},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#1C1C21] text-[13px] text-[#F0F0F5] outline-none",children:[r.jsx(Ds,{placeholder:"Not set",children:i?ta(i):"Not set"}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[280px] max-h-[240px] z-[9999]",children:r.jsx(os,{children:s.map(p=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:p.label}),p.models.map(m=>r.jsxs(vn,{value:m.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:m.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},m.id))]},p.label))})})})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Fast (quick tasks)"}),r.jsxs(ss,{value:o,onValueChange:p=>{l(p),d(!0)},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#1C1C21] text-[13px] text-[#F0F0F5] outline-none",children:[r.jsx(Ds,{placeholder:"Not set",children:o?ta(o):"Not set"}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[280px] max-h-[240px] z-[9999]",children:r.jsx(os,{children:s.map(p=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:p.label}),p.models.map(m=>r.jsxs(vn,{value:m.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:m.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},m.id))]},p.label))})})})]})]}),c&&r.jsx("button",{onClick:f,disabled:n.isPending||!i||!o,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#818CF8] disabled:opacity-50 transition-colors",children:n.isPending?"Saving...":"Save defaults"})]})]})}function NDe(){const[e,t]=y.useState(!1),[n,s]=y.useState(!1),[i,a]=y.useState(!1),o=L.useUtils(),{data:l,isLoading:c}=L.network.getStatus.useQuery(void 0,{refetchOnWindowFocus:!1}),d=L.network.activate.useMutation({onSuccess:()=>{o.network.getStatus.invalidate(),a(!1)}}),f=L.network.deactivate.useMutation({onSuccess:()=>{o.network.getStatus.invalidate(),a(!1)}});function p(w){navigator.clipboard.writeText(w),s(!0),setTimeout(()=>s(!1),1500)}const m=l?.mode==="tailscale"||l?.mode==="custom",b=!!l?.storedTailscaleHostname&&!e;function _(){i||(a(!0),m?f.mutate():d.mutate({hostname:l.storedTailscaleHostname}))}return r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6",children:[r.jsxs("div",{className:"flex items-start gap-3 mb-5",children:[r.jsx(B5,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Network & Sharing"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:"Share your workspace with teammates over a private network."})]})]}),c?r.jsx("div",{className:"py-4 flex justify-center",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):b?r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:"Tailscale:"}),r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4]",children:l.storedTailscaleHostname})]}),r.jsx("button",{onClick:_,disabled:i,className:`relative w-9 h-5 rounded-full transition-colors duration-200 ${m?"bg-[#6366F1]":"bg-[#2A2A35]"} ${i?"opacity-60":""}`,children:r.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white transition-transform duration-200 ${m?"translate-x-4":"translate-x-0"}`})})]}),m&&l.shareUrl?r.jsxs("div",{children:[r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:"Workspace URL:"}),r.jsxs("div",{className:"flex items-center justify-between bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 mt-1",children:[r.jsx("span",{className:"font-mono text-[12px] text-[#C8C8D4] truncate",children:l.shareUrl}),r.jsx("button",{onClick:()=>p(l.shareUrl),className:`ml-3 flex-shrink-0 transition-colors ${n?"text-emerald-400":"text-[#5A5A6E] hover:text-[#C8C8D4]"}`,children:n?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Po,{className:"w-3.5 h-3.5"})})]})]}):m?null:r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"Local only — teammates cannot reach this workspace."}),(d.isSuccess||f.isSuccess)&&r.jsx("p",{className:"text-[11px] text-amber-300/80",children:"Restart damn.dev to apply network changes."}),r.jsx("button",{onClick:()=>t(!0),className:"text-[11px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Change hostname..."})]}):r.jsxs("div",{children:[!e&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx("span",{className:"text-[12px] text-[#8A8A99]",children:"Network:"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6E]",children:"Local only"})]}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mb-3",children:"Your workspace is only accessible on this machine."}),r.jsx("button",{onClick:()=>t(!0),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 border border-[#6366F1]/30 transition-colors",children:"Set up team sharing"})]}),e&&r.jsx(V5,{onComplete:()=>{o.network.getStatus.invalidate(),t(!1)},onSkip:()=>t(!1)})]})]})}function kDe(){const e=L.useUtils(),[t,n]=y.useState(!1),[s,i]=y.useState(""),[a,o]=y.useState(""),{data:l=[]}=L.delegations.list.useQuery(),{data:c=[]}=L.agents.list.useQuery(),d=L.delegations.create.useMutation({onSuccess:()=>{e.delegations.list.invalidate(),n(!1),i(""),o("")}}),f=L.delegations.delete.useMutation({onSuccess:()=>{e.delegations.list.invalidate()}});function p(){!s||!a.trim()||d.mutate({agentId:s,pattern:a.trim()})}return r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6",children:[r.jsxs("div",{className:"flex items-start justify-between mb-5",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(ch,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Delegation Rules"}),r.jsxs("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:["Auto-approve matching actions. Patterns: ",r.jsx("code",{className:"text-[#8A8A99]",children:"shell:*"}),", ",r.jsx("code",{className:"text-[#8A8A99]",children:"soul:*"}),", ",r.jsx("code",{className:"text-[#8A8A99]",children:"trust:*"}),", ",r.jsx("code",{className:"text-[#8A8A99]",children:"skill:*"})]})]})]}),r.jsxs("button",{onClick:()=>n(m=>!m),className:"flex items-center gap-1 text-[11px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(wt,{className:"w-3 h-3"}),"Add rule"]})]}),r.jsx(Me,{children:t&&r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"mb-4 overflow-hidden",children:r.jsxs("div",{className:"flex gap-2 items-end",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1",children:"Agent"}),r.jsxs("select",{value:s,onChange:m=>i(m.target.value),className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-1.5 text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/60",children:[r.jsx("option",{value:"",children:"Select agent"}),c.map(m=>r.jsxs("option",{value:m.id,children:[m.emoji," ",m.name]},m.id)),r.jsx("option",{value:"coo",children:"COO"})]})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-[11px] text-[#8A8A99] mb-1",children:"Pattern"}),r.jsx("input",{value:a,onChange:m=>o(m.target.value),onKeyDown:m=>{m.key==="Enter"&&p()},placeholder:"shell:ls*",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-1.5 text-[13px] text-[#F0F0F5] font-mono placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]/60"})]}),r.jsx("button",{onClick:p,disabled:!s||!a.trim()||d.isPending,className:"px-3 py-1.5 rounded-lg bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40",children:"Add"}),r.jsx("button",{onClick:()=>{n(!1),i(""),o("")},className:"px-3 py-1.5 rounded-lg text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] border border-[#2A2A35] transition-colors",children:"Cancel"})]})})}),l.length===0?r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"No delegation rules. All actions require manual approval."}):r.jsx("div",{className:"space-y-1",children:l.map(m=>{const g=c.find(b=>b.id===m.agentId);return r.jsxs("div",{className:"flex items-center justify-between py-2 px-3 rounded-md bg-white/[0.02] border border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm",children:g?.emoji??(m.agentId==="coo"?"👑":"?")}),r.jsx("span",{className:"text-[13px] text-[#C8C8D4]",children:g?.name??(m.agentId==="coo"?"COO":m.agentId)}),r.jsx("code",{className:"text-[12px] font-mono text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded",children:m.pattern})]}),r.jsx(bt,{label:"Remove rule",children:r.jsx("button",{onClick:()=>f.mutate({id:m.id}),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors",children:r.jsx(Dn,{className:"w-3 h-3"})})})]},m.id)})})]})}function EDe(){const[e,t]=y.useState(!1),[n,s]=y.useState(!1);y.useEffect(()=>{X(async()=>{const{isEnabled:a}=await import("./index-CdilBaXC.js");return{isEnabled:a}},__vite__mapDeps([104,1])).then(({isEnabled:a})=>{a().then(o=>{t(o),s(!0)})}).catch(()=>s(!0))},[]);async function i(){try{const{enable:a,disable:o}=await X(async()=>{const{enable:l,disable:c}=await import("./index-CdilBaXC.js");return{enable:l,disable:c}},__vite__mapDeps([104,1]));e?(await o(),t(!1)):(await a(),t(!0))}catch{}}return n?r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6",children:[r.jsxs("div",{className:"flex items-start gap-3 mb-5",children:[r.jsx(bv,{className:"w-4 h-4 text-[#8A8A99] mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"Desktop App"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] mt-0.5",children:"Settings for the native desktop application."})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Launch on startup"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Start damn.dev hidden in the system tray when you log in."})]}),r.jsx("button",{onClick:i,className:`relative w-10 h-5 rounded-full transition-colors duration-200 focus:outline-none ${e?"bg-[#6366F1]":"bg-[#2A2A35]"}`,children:r.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform duration-200 ${e?"translate-x-5":"translate-x-0"}`})})]})]}):null}function FDe(){const[e,t]=y.useState("nodes");return r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-[15px] font-semibold text-[#F0F0F5] mb-1",children:"Federation"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Connect remote damn.dev instances or spawn isolated agent teams as Docker containers on this machine."})]}),r.jsx("div",{className:"flex gap-1 border-b border-[#2A2A35] mb-4",children:["nodes","activity"].map(n=>r.jsx("button",{onClick:()=>t(n),className:ye("px-3 py-1.5 text-[12px] font-medium border-b-2 -mb-px transition-colors",e===n?"border-[#6366F1] text-[#F0F0F5]":"border-transparent text-[#5A5A6E] hover:text-[#8A8A99]"),children:n==="nodes"?"Nodes":"Activity"},n))}),e==="nodes"&&r.jsx(RDe,{}),e==="activity"&&r.jsx(TDe,{})]})}function TDe(){const[e,t]=y.useState(null),n=L.federation.activityFeed.useQuery(void 0,{refetchInterval:1e4}),s=n.data?.entries??[];return n.isLoading?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(Pe,{className:"w-4 h-4 animate-spin text-[#5A5A6E]"})}):s.length===0?r.jsxs("div",{className:"py-12 text-center",children:[r.jsx(Xt,{className:"w-8 h-8 text-[#2A2A35] mx-auto mb-2"}),r.jsx("p",{className:"text-[13px] text-[#5A5A6E]",children:"No cross-instance activity yet"}),r.jsx("p",{className:"text-[11px] text-[#3A3A45] mt-1",children:"Activity will appear here when tasks are dispatched to or received from federated nodes"})]}):r.jsx("div",{className:"space-y-1.5",children:s.map(i=>{const a=e===i.id,o=i.status==="completed",l=i.status==="failed",c=o?"#10B981":l?"#EF4444":i.status==="working"?"#6366F1":"#F59E0B";return r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#16161A] overflow-hidden",children:[r.jsxs("button",{onClick:()=>t(a?null:i.id),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-left hover:bg-[#1A1A22] transition-colors",children:[r.jsx("span",{className:"text-[11px] flex-shrink-0",style:{color:c},children:o||i.result?"←":"→"}),i.nodeName&&r.jsxs("span",{className:"flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded bg-[#6366F1]/10 text-[#818CF8] flex-shrink-0",children:[r.jsx(Xt,{className:"w-2.5 h-2.5"}),i.nodeName]}),i.toAgent&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[#8A8A99] flex-shrink-0",children:[r.jsx("span",{children:i.toAgent.emoji}),r.jsx("span",{children:i.toAgent.name})]}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E] truncate flex-1",children:i.taskSnippet}),r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded flex-shrink-0",style:{color:c,backgroundColor:c+"15"},children:i.status}),r.jsx("span",{className:"text-[10px] text-[#3A3A45] flex-shrink-0",children:MDe(i.createdAt)}),r.jsx(Jt,{className:ye("w-3 h-3 text-[#3A3A45] transition-transform flex-shrink-0",a&&"rotate-90")})]}),a&&r.jsxs("div",{className:"px-3 pb-3 space-y-2 border-t border-[#2A2A35]/50",children:[r.jsxs("div",{className:"mt-2",children:[r.jsx("span",{className:"text-[9px] text-[#5A5A6E] uppercase tracking-wider",children:"Task"}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap break-words mt-1 font-mono leading-relaxed",children:i.fullTask})]}),i.result&&r.jsxs("div",{children:[r.jsx("span",{className:"text-[9px] text-[#5A5A6E] uppercase tracking-wider",children:"Result"}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap break-words mt-1 font-mono leading-relaxed bg-[#0F0F11] rounded p-2 border border-[#2A2A35]/50",children:i.result})]})]})]},i.id)})})}function MDe(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return"just now";const s=Math.floor(n/60);if(s<60)return`${s}m ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function RDe(){const[e,t]=y.useState(""),[n,s]=y.useState(""),[i,a]=y.useState(null),[o,l]=y.useState(!1),[c,d]=y.useState(""),[f,p]=y.useState(""),[m,g]=y.useState(null),[b,_]=y.useState(null),[w,A]=y.useState(null),S=L.federation.listNodes.useQuery(void 0,{refetchInterval:Ae=>Ae.state.data?.some(Ut=>Ut.status==="pending")?3e3:!1}),C=L.federation.spawnAvailability.useQuery(),E=L.federation.registerNode.useMutation({onSuccess:Ae=>{a(Ae.authToken),t(""),s(""),S.refetch()}}),k=L.federation.syncAgents.useMutation({onSuccess:()=>S.refetch()}),T=L.federation.removeNode.useMutation({onSuccess:()=>S.refetch()}),F=L.federation.spawnLocal.useMutation({onSuccess:()=>{d(""),p(""),g(null),S.refetch()},onError:Ae=>g(Ae.message)}),M=L.federation.destroyLocal.useMutation({onSuccess:()=>S.refetch()}),I=L.federation.stopLocal.useMutation({onSuccess:()=>S.refetch()}),R=L.federation.startLocal.useMutation({onSuccess:()=>S.refetch()}),H=L.federation.setDelegationPolicy.useMutation({onSuccess:()=>S.refetch()}),V=L.federation.getSpawnDefaults.useQuery(),K=L.federation.setSpawnDefaults.useMutation({onSuccess:()=>V.refetch()}),[q,$]=y.useState(""),[B,Y]=y.useState("nbg1"),[U,W]=y.useState("cx22"),[O,D]=y.useState(null),Q=L.federation.cloudAvailability.useQuery(),z=L.federation.cloudCatalog.useQuery(),J=L.federation.spawnCloud.useMutation({onSuccess:()=>{$(""),D(null),S.refetch()},onError:Ae=>D(Ae.message)}),ee=L.federation.destroyCloud.useMutation({onSuccess:()=>S.refetch()}),re=L.federation.addToAllowlist.useMutation({onSuccess:()=>S.refetch()}),oe=L.federation.removeFromAllowlist.useMutation({onSuccess:()=>S.refetch()}),[se,ae]=y.useState(null),{data:le=[]}=L.agents.list.useQuery(),ge=S.data??[],je=C.data?.ok===!0,Ee={active:"#10B981",pending:"#F59E0B",unreachable:"#EF4444",revoked:"#5A5A6E"},de=()=>{g(null);const Ae=c.trim();if(!Ae){g("Name is required");return}const ct=f.trim()?Number(f.trim()):void 0;if(f.trim()&&(!Number.isInteger(ct)||ct<1024||ct>65535)){g("Port must be 1024–65535");return}F.mutate({name:Ae,port:ct})},me=V.data,$e=me?.defaultNodeSpawnPolicy??"coo-only",nt=me?.cooAutoApproveNodeSpawn??!1;return r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#16161A] p-4 space-y-3",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-7 h-7 rounded-lg bg-[#8A8A99]/15 flex items-center justify-center flex-shrink-0",children:r.jsx(ch,{className:"w-3.5 h-3.5 text-[#8A8A99]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h3",{className:"text-[12px] font-semibold text-[#F0F0F5]",children:"Spawn Defaults"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Policies applied to every newly spawned node — whether from this UI or from the COO."})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("label",{className:"text-[10px] text-[#8A8A99] uppercase tracking-wider block",children:"Default delegation policy for new spawns"}),r.jsxs(ss,{value:$e,onValueChange:Ae=>K.mutate({defaultNodeSpawnPolicy:Ae}),children:[r.jsxs(is,{disabled:K.isPending,className:"w-full flex items-center justify-between bg-[#0F0F11] border border-[#2A2A35] rounded px-3 py-2 text-[12px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/40 disabled:opacity-50",children:[r.jsxs(Ds,{children:[r.jsx("span",{style:{color:$d[$e]?.color??"#8A8A99"},children:$d[$e]?.label??$e}),r.jsxs("span",{className:"text-[#5A5A6E] ml-2",children:[$e==="closed"&&"— no cross-instance dispatch until you opt in",$e==="coo-only"&&"— only the COO can dispatch (safest default)",$e==="approval-required"&&"— every dispatch requires user approval",$e==="open"&&"— any agent can dispatch (trusted compute)"]})]}),r.jsx(ft,{className:"w-3 h-3 text-[#8A8A99]"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"z-50 bg-[#0F0F11] border border-[#2A2A35] rounded-lg shadow-2xl py-1 min-w-[var(--radix-select-trigger-width)]",children:r.jsx(os,{children:["closed","coo-only","approval-required","open"].map(Ae=>{const ct=$d[Ae];return r.jsx(vn,{value:Ae,className:"px-3 py-2 text-[11px] cursor-pointer outline-none hover:bg-[#16161A] data-[state=checked]:bg-[#16161A]",children:r.jsx(yn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:ct.color}}),r.jsx("span",{style:{color:ct.color},children:ct.label})]})})},Ae)})})})})]})]}),r.jsxs("label",{className:"flex items-start gap-2 cursor-pointer group",children:[r.jsx("input",{type:"checkbox",checked:nt,onChange:Ae=>K.mutate({cooAutoApproveNodeSpawn:Ae.target.checked}),disabled:K.isPending,className:"mt-0.5 accent-[#6366F1]"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("div",{className:"text-[12px] text-[#F0F0F5]",children:"Auto-approve COO node-spawn requests"}),r.jsxs("div",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:["When on, the COO can spawn new isolated nodes without waiting for your explicit approval. Safer default is ",r.jsx("strong",{className:"text-[#F0F0F5]",children:"off"})," — you review each spawn before it fires."]})]})]})]}),r.jsxs("div",{className:"rounded-lg border border-[#6366F1]/20 bg-gradient-to-br from-[#6366F1]/5 to-transparent p-4 space-y-3",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#6366F1]/15 flex items-center justify-center flex-shrink-0",children:r.jsx(Mp,{className:"w-4 h-4 text-[#6366F1]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h3",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:"Spawn Local Node"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mt-0.5",children:"One click → isolated damn.dev container on this machine, auto-federated. Each node gets its own DB, agents, and OpenClaw workspace."})]})]}),!je&&C.data?r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded bg-[#F59E0B]/10 border border-[#F59E0B]/20 text-[11px] text-[#F59E0B]",children:[r.jsx(Rs,{className:"w-3.5 h-3.5 flex-shrink-0"}),r.jsx("span",{children:C.data.reason})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:c,onChange:Ae=>d(Ae.target.value),placeholder:"Node name (e.g. client-a)",className:"flex-1 bg-[#16161A] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"}),r.jsx("input",{value:f,onChange:Ae=>p(Ae.target.value),placeholder:"Port (auto)",className:"w-32 bg-[#16161A] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"}),r.jsxs("button",{onClick:de,disabled:!c.trim()||F.isPending||!je,className:"px-4 py-1.5 rounded bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E6] transition-colors disabled:opacity-50 flex items-center gap-1.5",children:[F.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Mp,{className:"w-3 h-3"}),"Spawn"]})]}),F.isPending&&r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:"Building image (first time only, ~3 min), starting containers, waiting for health check…"}),m&&r.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded bg-[#EF4444]/10 border border-[#EF4444]/20 text-[11px] text-[#EF4444]",children:[r.jsx(Rs,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),r.jsx("span",{className:"break-all",children:m})]})]})]}),r.jsxs("div",{className:"rounded-lg border border-[#10B981]/20 bg-gradient-to-br from-[#10B981]/5 to-transparent p-4 space-y-3",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#10B981]/15 flex items-center justify-center flex-shrink-0",children:r.jsx(Xt,{className:"w-4 h-4 text-[#10B981]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h3",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:"Spawn Cloud Node"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mt-0.5",children:"Provision a VPS on Hetzner. Auto-installs damn.dev and federates with this hub. Takes 2–4 minutes."})]})]}),Q.data&&!Q.data.ok?r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded bg-[#F59E0B]/10 border border-[#F59E0B]/20 text-[11px] text-[#F59E0B]",children:[r.jsx(Rs,{className:"w-3.5 h-3.5 flex-shrink-0"}),r.jsx("span",{children:Q.data.reason})]}):Q.data?.ok?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex gap-2",children:r.jsx("input",{value:q,onChange:Ae=>$(Ae.target.value),placeholder:"Node name (e.g. prod-eu)",className:"flex-1 bg-[#16161A] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#10B981]/40"})}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs(ss,{value:B,onValueChange:Y,children:[r.jsxs(is,{className:"flex-1 flex items-center justify-between bg-[#16161A] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] outline-none focus:border-[#10B981]/40",children:[r.jsxs(Ds,{children:[z.data?.hetzner.regions.find(Ae=>Ae.id===B)?.flag," ",z.data?.hetzner.regions.find(Ae=>Ae.id===B)?.label??B]}),r.jsx(ft,{className:"w-3 h-3 text-[#8A8A99]"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"z-50 bg-[#0F0F11] border border-[#2A2A35] rounded-lg shadow-2xl py-1 min-w-[var(--radix-select-trigger-width)]",children:r.jsx(os,{children:(z.data?.hetzner.regions??[]).map(Ae=>r.jsx(vn,{value:Ae.id,className:"px-3 py-2 text-[11px] cursor-pointer outline-none hover:bg-[#16161A] data-[state=checked]:bg-[#16161A]",children:r.jsxs(yn,{children:[Ae.flag," ",Ae.label," (",Ae.country,")"]})},Ae.id))})})})]}),r.jsxs(ss,{value:U,onValueChange:W,children:[r.jsxs(is,{className:"flex-1 flex items-center justify-between bg-[#16161A] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] outline-none focus:border-[#10B981]/40",children:[r.jsx(Ds,{children:z.data?.hetzner.sizes.find(Ae=>Ae.id===U)?.label??U}),r.jsx(ft,{className:"w-3 h-3 text-[#8A8A99]"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"z-50 bg-[#0F0F11] border border-[#2A2A35] rounded-lg shadow-2xl py-1 min-w-[var(--radix-select-trigger-width)]",children:r.jsx(os,{children:(z.data?.hetzner.sizes??[]).map(Ae=>r.jsx(vn,{value:Ae.id,className:"px-3 py-2 text-[11px] cursor-pointer outline-none hover:bg-[#16161A] data-[state=checked]:bg-[#16161A]",children:r.jsxs(yn,{children:[Ae.label," — $",Ae.monthlyCost,"/mo"]})},Ae.id))})})})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("span",{className:"text-[11px] text-[#10B981]",children:["Est. ~$",z.data?.hetzner.sizes.find(Ae=>Ae.id===U)?.monthlyCost??"?","/mo"]}),r.jsxs("button",{onClick:()=>J.mutate({name:q.trim(),provider:"hetzner",region:B,size:U}),disabled:!q.trim()||J.isPending,className:"px-4 py-1.5 rounded bg-[#10B981] text-white text-[12px] font-medium hover:bg-[#0EA472] transition-colors disabled:opacity-50 flex items-center gap-1.5",children:[J.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Xt,{className:"w-3 h-3"}),"Provision"]})]}),r.jsx("p",{className:"text-[10px] text-[#F59E0B]",children:"Federation traffic over HTTP (unencrypted). Cloudflare DNS + TLS planned for a future update."}),J.isPending&&r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:"Creating server, installing damn.dev, waiting for health check… (2–4 minutes)"}),O&&r.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded bg-[#EF4444]/10 border border-[#EF4444]/20 text-[11px] text-[#EF4444]",children:[r.jsx(Rs,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),r.jsx("span",{className:"break-all",children:O})]})]}):null]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider",children:"Add Remote Node"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:e,onChange:Ae=>t(Ae.target.value),placeholder:"Node name (e.g. vps-eu)",className:"flex-1 bg-[#16161A] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"}),r.jsx("input",{value:n,onChange:Ae=>s(Ae.target.value),placeholder:"https://node.example.com:3001",className:"flex-1 bg-[#16161A] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"}),r.jsx("button",{onClick:()=>E.mutate({name:e.trim(),url:n.trim()}),disabled:!e.trim()||!n.trim()||E.isPending,className:"px-3 py-1.5 rounded bg-[#2A2A35] text-[#F0F0F5] text-[12px] font-medium hover:bg-[#3A3A45] transition-colors disabled:opacity-50",children:E.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(wt,{className:"w-3 h-3"})})]}),n.trim()&&(n.includes("localhost")||n.includes("127.0.0.1"))&&r.jsxs("p",{className:"text-[10px] text-[#6366F1]/70 mt-1 flex items-center gap-1",children:[r.jsx(Xt,{className:"w-2.5 h-2.5"}),"Federating two workspaces on the same instance — agents stay isolated but can dispatch tasks to each other."]})]}),i&&r.jsxs("div",{className:"p-3 rounded-lg bg-[#10B981]/10 border border-[#10B981]/20",children:[r.jsx("p",{className:"text-[12px] text-[#10B981] font-medium mb-1",children:"Node registered. Copy the auth token — it won't be shown again."}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("code",{className:"flex-1 text-[11px] font-mono text-[#10B981] bg-[#0F0F11] px-2 py-1 rounded truncate",children:i}),r.jsx("button",{onClick:()=>{navigator.clipboard.writeText(i),l(!0),setTimeout(()=>l(!1),2e3)},className:"px-2 py-1 rounded text-[11px] text-[#10B981] hover:bg-[#10B981]/10 transition-colors",children:o?r.jsx(Fe,{className:"w-3 h-3"}):r.jsx(Po,{className:"w-3 h-3"})})]}),r.jsx("p",{className:"text-[10px] text-[#8A8A99] mt-2",children:"Configure this token on the remote node, then sync agents."})]}),ge.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider",children:"Nodes"}),ge.map(Ae=>{const ct=Ae.isLocal===!0,Ut=Ae.spawnType==="cloud",Os=Ae.delegationPolicy??"closed",qt=ct&&Ae.status==="unreachable",Gt=(I.isPending||R.isPending||M.isPending||ee.isPending||k.isPending)&&(I.variables?.nodeId===Ae.id||R.variables?.nodeId===Ae.id||M.variables?.nodeId===Ae.id||ee.variables?.nodeId===Ae.id||k.variables?.nodeId===Ae.id),on=(()=>{try{return JSON.parse(Ae.delegationAllowlist??"[]")}catch{return[]}})(),$r=se===Ae.id;return r.jsxs("div",{className:"rounded-lg bg-[#16161A] border border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[r.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:Ee[Ae.status]??"#5A5A6E"}}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[13px] text-[#F0F0F5] font-medium truncate",children:Ae.name}),r.jsx("span",{className:ye("text-[9px] px-1.5 py-0.5 rounded font-medium uppercase tracking-wider",Ut?"bg-[#10B981]/15 text-[#10B981]":ct?"bg-[#6366F1]/15 text-[#6366F1]":"bg-[#2A2A35] text-[#8A8A99]"),children:Ut?"cloud":ct?"local":"remote"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:Ae.status}),r.jsx(DDe,{policy:Os,onChange:fe=>H.mutate({nodeId:Ae.id,policy:fe}),pending:H.isPending&&H.variables?.nodeId===Ae.id}),Ut&&Ae.monthlyCost&&r.jsxs("span",{className:"text-[9px] text-[#10B981]",children:["$",Ae.monthlyCost,"/mo"]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[11px] text-[#5A5A6E] truncate",children:Ae.url}),Ut&&Ae.cloudRegion&&r.jsx("span",{className:"text-[9px] text-[#5A5A6E]",children:Ae.cloudRegion})]})]}),r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[Ae.agentCount," agent",Ae.agentCount!==1?"s":""]}),Ae.remoteAgents.length>0&&r.jsx("div",{className:"flex -space-x-1",children:Ae.remoteAgents.slice(0,4).map(fe=>r.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] border border-[#16161A]",style:{backgroundColor:fe.color+"20"},title:fe.name,children:fe.emoji},fe.id))}),r.jsx("button",{onClick:()=>ae($r?null:Ae.id),className:"px-1 py-1 rounded text-[11px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors",title:"Expand",children:r.jsx(ft,{className:ye("w-3 h-3 transition-transform",$r&&"rotate-180")})}),r.jsx("div",{className:"flex items-center gap-1",children:ct?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>A(Ae.id),disabled:Gt||qt,className:"px-2 py-1 rounded text-[11px] text-[#10B981] hover:bg-[#10B981]/10 transition-colors disabled:opacity-50",title:"Create agent",children:r.jsx(V2,{className:"w-3 h-3"})}),r.jsx("button",{onClick:()=>_(Ae.id),disabled:Gt,className:"px-2 py-1 rounded text-[11px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors disabled:opacity-50",title:"Logs",children:r.jsx(li,{className:"w-3 h-3"})}),qt?r.jsx("button",{onClick:()=>R.mutate({nodeId:Ae.id}),disabled:Gt,className:"px-2 py-1 rounded text-[11px] text-[#10B981] hover:bg-[#10B981]/10 transition-colors disabled:opacity-50",title:"Start",children:Gt&&R.variables?.nodeId===Ae.id?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(I5,{className:"w-3 h-3"})}):r.jsx("button",{onClick:()=>I.mutate({nodeId:Ae.id}),disabled:Gt,className:"px-2 py-1 rounded text-[11px] text-[#F59E0B] hover:bg-[#F59E0B]/10 transition-colors disabled:opacity-50",title:"Stop",children:Gt&&I.variables?.nodeId===Ae.id?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(L5,{className:"w-3 h-3"})}),r.jsx("button",{onClick:()=>k.mutate({nodeId:Ae.id}),disabled:Gt||qt,className:"px-2 py-1 rounded text-[11px] text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors disabled:opacity-50",title:"Sync",children:Gt&&k.variables?.nodeId===Ae.id?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Xi,{className:"w-3 h-3"})}),r.jsx("button",{onClick:()=>{confirm(`Destroy node "${Ae.name}"? This removes the container and all data.`)&&M.mutate({nodeId:Ae.id})},disabled:Gt,className:"px-2 py-1 rounded text-[11px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-50",title:"Destroy",children:Gt&&M.variables?.nodeId===Ae.id?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Dn,{className:"w-3 h-3"})})]}):Ut?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>k.mutate({nodeId:Ae.id}),disabled:Gt||Ae.status==="revoked",className:"px-2 py-1 rounded text-[11px] text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors disabled:opacity-50",title:"Sync",children:k.isPending&&k.variables?.nodeId===Ae.id?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Xi,{className:"w-3 h-3"})}),r.jsx("button",{onClick:()=>{confirm(`Destroy cloud node "${Ae.name}"? This DELETES the Hetzner server permanently.`)&&ee.mutate({nodeId:Ae.id})},disabled:Gt,className:"px-2 py-1 rounded text-[11px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-50",title:"Destroy",children:ee.isPending&&ee.variables?.nodeId===Ae.id?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Dn,{className:"w-3 h-3"})})]}):r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>k.mutate({nodeId:Ae.id}),disabled:k.isPending||Ae.status==="revoked",className:"px-2 py-1 rounded text-[11px] text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors disabled:opacity-50",children:k.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Xi,{className:"w-3 h-3"})}),r.jsx("button",{onClick:()=>T.mutate({nodeId:Ae.id}),disabled:T.isPending,className:"px-2 py-1 rounded text-[11px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-50",children:r.jsx(Dn,{className:"w-3 h-3"})})]})})]}),$r&&r.jsxs("div",{className:"px-3 pb-3 pt-1 border-t border-[#2A2A35]",children:[r.jsx("label",{className:"text-[10px] text-[#8A8A99] uppercase tracking-wider block mb-1.5",children:"Delegation Allowlist"}),r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mb-2",children:"Agents on this list bypass the node's delegation policy (additive grant)."}),r.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[on.length===0&&r.jsx("span",{className:"text-[10px] text-[#3A3A45] italic",children:"No agents in allowlist"}),on.map(fe=>{const Ce=le.find(Ue=>Ue.id===fe);return r.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-[#6366F1]/10 text-[10px] text-[#6366F1]",children:[Ce?`${Ce.emoji??""} ${Ce.name}`:fe,r.jsx("button",{onClick:()=>oe.mutate({nodeId:Ae.id,agentId:fe}),className:"hover:text-[#EF4444] transition-colors",children:r.jsx(Te,{className:"w-2.5 h-2.5"})})]},fe)})]}),r.jsxs(ss,{onValueChange:fe=>re.mutate({nodeId:Ae.id,agentId:fe}),children:[r.jsxs(is,{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-[#2A2A35] text-[10px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-2.5 h-2.5"}),r.jsx(Ds,{placeholder:"Add agent"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"z-50 bg-[#0F0F11] border border-[#2A2A35] rounded-lg shadow-2xl py-1 max-h-48 overflow-auto",children:r.jsx(os,{children:le.filter(fe=>!on.includes(fe.id)).map(fe=>r.jsx(vn,{value:fe.id,className:"px-3 py-1.5 text-[11px] cursor-pointer outline-none hover:bg-[#16161A] text-[#F0F0F5]",children:r.jsxs(yn,{children:[fe.emoji??""," ",fe.name]})},fe.id))})})})]})]})]},Ae.id)})]}),ge.length===0&&!S.isLoading&&r.jsxs("div",{className:"py-8 text-center",children:[r.jsx(vre,{className:"w-8 h-8 text-[#2A2A35] mx-auto mb-2"}),r.jsx("p",{className:"text-[13px] text-[#5A5A6E]",children:"No federation nodes"}),r.jsx("p",{className:"text-[11px] text-[#3A3A45] mt-1",children:"Spawn a local node above, or add a remote damn.dev instance"})]}),r.jsx(PDe,{nodeId:b,onClose:()=>_(null)}),r.jsx(ODe,{nodeId:w,nodeName:ge.find(Ae=>Ae.id===w)?.name??"",onClose:()=>A(null),onCreated:()=>{A(null),S.refetch()}})]})}const $d={closed:{label:"closed",color:"#EF4444",bg:"#EF4444"},"coo-only":{label:"COO only",color:"#6366F1",bg:"#6366F1"},"approval-required":{label:"approval",color:"#F59E0B",bg:"#F59E0B"},open:{label:"open",color:"#10B981",bg:"#10B981"}};function DDe({policy:e,onChange:t,pending:n}){const s=$d[e]??$d.closed;return r.jsxs(ss,{value:e,onValueChange:i=>t(i),children:[r.jsxs(is,{disabled:n,className:"inline-flex items-center gap-1 text-[9px] uppercase tracking-wider px-1.5 py-0.5 rounded font-medium transition-colors disabled:opacity-50",style:{backgroundColor:s.bg+"20",color:s.color},title:"Cross-instance dispatch policy: who on this hub may delegate INTO this node",children:[r.jsx(Ds,{children:n?"…":s.label}),r.jsx(ft,{className:"w-2.5 h-2.5"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"z-50 bg-[#0F0F11] border border-[#2A2A35] rounded-lg shadow-2xl py-1 min-w-[180px]",children:r.jsx(os,{children:["closed","coo-only","approval-required","open"].map(i=>{const a=$d[i];return r.jsx(vn,{value:i,className:"px-3 py-2 text-[11px] cursor-pointer outline-none hover:bg-[#16161A] data-[state=checked]:bg-[#16161A]",children:r.jsx(yn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.color}}),r.jsx("span",{style:{color:a.color},children:a.label})]})})},i)})})})})]})}function ODe({nodeId:e,nodeName:t,onClose:n,onCreated:s}){const[i,a]=y.useState(""),[o,l]=y.useState("🤖"),[c,d]=y.useState("#6366F1"),[f,p]=y.useState(""),[m,g]=y.useState("openrouter/anthropic/claude-sonnet-4.6"),[b,_]=y.useState(""),[w,A]=y.useState(null),S=L.federation.createRemoteAgent.useMutation({onSuccess:()=>{a(""),l("🤖"),d("#6366F1"),p(""),_(""),A(null),s()},onError:E=>A(E.message)}),C=()=>{if(A(null),!i.trim()||!o.trim()||!f.trim()||!b.trim()||!e){A("All fields are required");return}S.mutate({nodeId:e,name:i.trim(),emoji:o.trim(),color:c.trim(),role:f.trim(),model:m.trim(),soul:b.trim()})};return r.jsx(ji,{open:!!e,onOpenChange:E=>{E||(A(null),n())},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-50"}),r.jsxs(ki,{className:"fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-[min(560px,90vw)] max-h-[85vh] bg-[#0F0F11] border border-[#2A2A35] rounded-lg shadow-2xl z-50 flex flex-col",children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[#2A2A35]",children:[r.jsxs(nr,{className:"text-[13px] font-semibold text-[#F0F0F5] flex items-center gap-2",children:[r.jsx(V2,{className:"w-4 h-4 text-[#10B981]"}),"Create agent on ",r.jsx("span",{className:"text-[#6366F1]",children:t})]}),r.jsx(Gs,{className:"px-2 py-1 rounded text-[11px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors",children:r.jsx(Te,{className:"w-3 h-3"})})]}),r.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-[80px_1fr] gap-2",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] text-[#8A8A99] uppercase tracking-wider block mb-1",children:"Emoji"}),r.jsx("input",{value:o,onChange:E=>l(E.target.value),maxLength:4,className:"w-full bg-[#16161A] border border-[#2A2A35] rounded px-2 py-1.5 text-[14px] text-center text-[#F0F0F5] outline-none focus:border-[#6366F1]/40"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] text-[#8A8A99] uppercase tracking-wider block mb-1",children:"Name"}),r.jsx("input",{value:i,onChange:E=>a(E.target.value),placeholder:"Researcher",maxLength:50,className:"w-full bg-[#16161A] border border-[#2A2A35] rounded px-2 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] text-[#8A8A99] uppercase tracking-wider block mb-1",children:"Role"}),r.jsx("input",{value:f,onChange:E=>p(E.target.value),placeholder:"e.g. Market researcher and competitive analysis",maxLength:120,className:"w-full bg-[#16161A] border border-[#2A2A35] rounded px-2 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] text-[#8A8A99] uppercase tracking-wider block mb-1",children:"Color"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:c,onChange:E=>d(E.target.value),className:"flex-1 bg-[#16161A] border border-[#2A2A35] rounded px-2 py-1.5 text-[12px] font-mono text-[#F0F0F5] outline-none focus:border-[#6366F1]/40"}),r.jsx("span",{className:"w-8 h-8 rounded border border-[#2A2A35]",style:{backgroundColor:c}})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] text-[#8A8A99] uppercase tracking-wider block mb-1",children:"Model"}),r.jsx("input",{value:m,onChange:E=>g(E.target.value),className:"w-full bg-[#16161A] border border-[#2A2A35] rounded px-2 py-1.5 text-[11px] font-mono text-[#F0F0F5] outline-none focus:border-[#6366F1]/40"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] text-[#8A8A99] uppercase tracking-wider block mb-1",children:"Soul (system prompt)"}),r.jsx("textarea",{value:b,onChange:E=>_(E.target.value),placeholder:"You are a market researcher. You produce concise, evidence-based competitive analyses...",rows:8,className:"w-full bg-[#16161A] border border-[#2A2A35] rounded px-2 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40 font-mono leading-relaxed resize-none"})]}),w&&r.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded bg-[#EF4444]/10 border border-[#EF4444]/20 text-[11px] text-[#EF4444]",children:[r.jsx(Rs,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),r.jsx("span",{className:"break-all",children:w})]})]}),r.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-[#2A2A35]",children:[r.jsx("button",{onClick:n,disabled:S.isPending,className:"px-3 py-1.5 rounded text-[12px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors disabled:opacity-50",children:"Cancel"}),r.jsxs("button",{onClick:C,disabled:S.isPending||!i.trim()||!f.trim()||!b.trim(),className:"px-3 py-1.5 rounded bg-[#10B981] text-white text-[12px] font-medium hover:bg-[#059669] transition-colors disabled:opacity-50 flex items-center gap-1.5",children:[S.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(V2,{className:"w-3 h-3"}),"Create"]})]})]})]})})}function PDe({nodeId:e,onClose:t}){const n=L.federation.nodeLogs.useQuery({nodeId:e??"",lines:200},{enabled:!!e,refetchInterval:e?5e3:!1});return r.jsx(ji,{open:!!e,onOpenChange:s=>{s||t()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-50"}),r.jsxs(ki,{className:"fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-[min(900px,90vw)] max-h-[80vh] bg-[#0F0F11] border border-[#2A2A35] rounded-lg shadow-2xl z-50 flex flex-col",children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[#2A2A35]",children:[r.jsxs(nr,{className:"text-[13px] font-semibold text-[#F0F0F5] flex items-center gap-2",children:[r.jsx(li,{className:"w-4 h-4 text-[#6366F1]"}),"Node Logs"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:()=>n.refetch(),disabled:n.isFetching,className:"px-2 py-1 rounded text-[11px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors disabled:opacity-50",children:n.isFetching?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Xi,{className:"w-3 h-3"})}),r.jsx(Gs,{className:"px-2 py-1 rounded text-[11px] text-[#8A8A99] hover:bg-[#2A2A35] transition-colors",children:r.jsx(Te,{className:"w-3 h-3"})})]})]}),r.jsx("div",{className:"flex-1 overflow-auto p-4",children:n.isLoading?r.jsxs("div",{className:"flex items-center justify-center py-8 text-[12px] text-[#5A5A6E]",children:[r.jsx(Pe,{className:"w-4 h-4 animate-spin mr-2"}),"Fetching logs…"]}):n.error?r.jsx("div",{className:"text-[12px] text-[#EF4444]",children:n.error.message}):r.jsx("pre",{className:"text-[10px] font-mono text-[#A5A5B5] whitespace-pre-wrap break-all leading-relaxed",children:n.data?.logs??"(no output)"})})]})]})})}function IDe(){const{nodeId:e,agentId:t}=am(),n=an(),[s,i]=y.useState(""),a=y.useRef(null),o=y.useRef(0),l=L.federation.listNodes.useQuery(),c=l.data?.find(A=>A.id===e),d=c?.remoteAgents.find(A=>A.remoteAgentId===t),f=L.federation.remoteMessages.useQuery({nodeId:e,agentId:t,limit:80},{enabled:!!e&&!!t,refetchInterval:A=>A.state.status==="error"?!1:3e3,retry:1}),p=L.federation.remoteSend.useMutation({onSuccess:()=>{i(""),f.refetch()}}),g=(f.data?.messages??[]).map(A=>({id:A.id,channelId:`federation:${e}:${t}`,sender:{type:A.senderType,id:A.senderId,name:A.senderName,agentColor:A.agentColor??void 0},content:A.content,timestamp:A.timestamp}));y.useEffect(()=>{g.length>o.current&&a.current?.scrollIntoView({behavior:"smooth"}),o.current=g.length},[g.length]);function b(){const A=s.trim();!A||!e||!t||p.mutate({nodeId:e,agentId:t,message:A})}const _=f.isError,w=c?.status==="unreachable"||c?.status==="revoked";return r.jsxs("div",{className:"flex flex-col flex-1 overflow-hidden bg-[#0C0C0E]",children:[r.jsxs("div",{className:"flex items-center gap-3 px-5 py-3 border-b border-[#1E1E28] bg-[#0F0F11]",children:[r.jsx("button",{onClick:()=>n(-1),className:"text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:r.jsx(gm,{className:"w-4 h-4"})}),d&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-[18px]",children:d.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:d.name}),c&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-[#6366F1]/10 text-[#818CF8]",children:[r.jsx(Xt,{className:"w-2.5 h-2.5"}),c.name]}),c&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:c.status==="active"?"#10B981":c.status==="pending"?"#F59E0B":"#EF4444"}})]}),d.role&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:d.role})]})]}),!d&&!l.isLoading&&r.jsx("span",{className:"text-[13px] text-[#5A5A6E]",children:"Agent not found"})]}),r.jsxs("div",{className:"flex items-center gap-2 px-5 py-1.5 bg-[#6366F1]/5 border-b border-[#6366F1]/10",children:[r.jsx(Xt,{className:"w-3 h-3 text-[#6366F1]/60"}),r.jsxs("span",{className:"text-[10px] text-[#6366F1]/60",children:["Remote channel on ",c?.name??"unknown node"," — messages polled every 3s"]})]}),(_||w)&&r.jsxs("div",{className:"flex items-center gap-2 px-5 py-2 bg-[#EF4444]/5 border-b border-[#EF4444]/10",children:[r.jsx(ql,{className:"w-3.5 h-3.5 text-[#EF4444]"}),r.jsx("span",{className:"text-[11px] text-[#EF4444]",children:w?`Node "${c?.name}" is ${c?.status} — cannot fetch messages`:"Failed to fetch messages from remote node"})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-1",children:[f.isLoading&&!_&&g.length===0&&r.jsx("div",{className:"flex items-center justify-center py-16",children:r.jsx(Pe,{className:"w-5 h-5 animate-spin text-[#5A5A6E]"})}),!f.isLoading&&g.length===0&&!_&&r.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[r.jsx(Xt,{className:"w-10 h-10 text-[#2A2A35] mb-3"}),r.jsx("p",{className:"text-[13px] text-[#5A5A6E]",children:"No messages yet"}),r.jsx("p",{className:"text-[11px] text-[#3A3A45] mt-1",children:"Send a message to start a conversation with this remote agent"})]}),g.map(A=>r.jsx(Z7,{message:A,agentColor:d?.color},A.id)),r.jsx("div",{ref:a})]}),r.jsxs("div",{className:"px-5 py-3 border-t border-[#1E1E28] bg-[#0F0F11]",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{value:s,onChange:A=>i(A.target.value),onKeyDown:A=>{A.key==="Enter"&&!A.shiftKey&&(A.preventDefault(),b())},placeholder:d?`Message ${d.name} on ${c?.name??"remote node"}...`:"Send message...",disabled:w,className:"flex-1 bg-[#13131A] border border-[#2A2A35] rounded-lg px-4 py-2.5 text-[13px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40 disabled:opacity-40 transition-colors"}),r.jsx("button",{onClick:b,disabled:!s.trim()||p.isPending||w,className:"px-4 py-2.5 rounded-lg bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 transition-colors disabled:opacity-30",children:p.isPending?r.jsx(Pe,{className:"w-4 h-4 animate-spin"}):r.jsx(Ji,{className:"w-4 h-4"})})]}),p.isError&&r.jsx("p",{className:"text-[10px] text-[#EF4444] mt-1 px-1",children:p.error.message})]})]})}const AW=new Set([".png",".jpg",".jpeg",".gif",".bmp",".webp",".svg"]);function Ty(e){const t=e.match(/\.(kanban|chart|table|board)\.json$/);return t?t[1]:null}function LDe(e){const t=Ty(e);return t?{kanban:"Kanban Board",chart:"Chart",table:"Data Table",board:"Card Grid"}[t]??"":""}const BDe={kanban:nL,chart:M5,table:wL,board:ym},zDe={kanban:"#6366F1",chart:"#10B981",table:"#3B82F6",board:"#8B5CF6"},$De={structured:ym,code:rL,images:hL,documents:li,other:gv};function VDe({file:e}){const t=Ty(e.name);if(t){const s=BDe[t],i=zDe[t];return r.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center flex-shrink-0",style:{backgroundColor:`${i}15`},children:r.jsx(s,{className:"w-5 h-5",style:{color:i}})})}if(AW.has(e.ext))return r.jsx("div",{className:"w-10 h-10 rounded-lg overflow-hidden flex-shrink-0 bg-[#1C1C24]",children:r.jsx("img",{src:`${oi}/api/files/serve/${e.agentId}/${e.path}`,alt:e.name,className:"w-full h-full object-cover",loading:"lazy"})});const n=$De[e.category]??gv;return r.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center flex-shrink-0 bg-white/[0.04]",children:r.jsx(n,{className:"w-5 h-5 text-[#5A5A6E]"})})}function UDe({file:e,agentEmoji:t,agentName:n,agentColor:s,onClick:i}){const o=Ty(e.name)?LDe(e.name):null,l=Math.round(e.size/1024);return r.jsxs(ne.button,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,scale:.97},transition:{duration:.15},onClick:i,className:"flex items-start gap-3 p-3 rounded-xl border border-[#2A2A35] bg-[#16161A] hover:bg-[#1C1C24] hover:border-[#3A3A48] transition-all duration-100 text-left w-full group",children:[r.jsx(VDe,{file:e}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"flex items-center gap-1.5 mb-0.5",children:r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5] truncate",children:e.name})}),o&&r.jsx("span",{className:"text-[11px] text-[#8A8A99] block",children:o}),r.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[t&&n&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full",style:{backgroundColor:`${s??"#6366F1"}12`,color:s??"#818CF8"},children:[r.jsx("span",{className:"text-[10px] leading-none",children:t}),n]}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:l>0?`${l}KB`:"<1KB"}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:new Date(e.modified).toLocaleDateString()})]})]})]})}function HDe({file:e,onClose:t}){return Ty(e.name)?r.jsx(yN,{agentId:e.agentId,filePath:e.path,onClose:t}):AW.has(e.ext)?r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70",onClick:t,children:r.jsx(ne.img,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},src:`${oi}/api/files/serve/${e.agentId}/${e.path}`,alt:e.name,className:"max-w-[90vw] max-h-[85vh] rounded-xl shadow-2xl",onClick:s=>s.stopPropagation()})}):r.jsx(WDe,{file:e,onClose:t})}function WDe({file:e,onClose:t}){const{data:n,isLoading:s}=L.files.read.useQuery({agentId:e.agentId,filePath:e.path},{retry:!1});return r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:t,children:r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},className:"w-[700px] max-h-[80vh] bg-[#13131A] border border-[#2A2A35] rounded-xl shadow-2xl flex flex-col overflow-hidden",onClick:i=>i.stopPropagation(),children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsx("span",{className:"text-[13px] font-semibold text-[#F0F0F5] truncate",children:e.name}),r.jsx("button",{onClick:t,className:"text-[#5A5A6E] hover:text-[#C8C8D4] transition-colors text-[18px] leading-none",children:"×"})]}),r.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[s&&r.jsx("div",{className:"flex items-center justify-center py-12 text-[#5A5A6E] text-[12px]",children:"Loading..."}),!s&&n?.content&&r.jsxs("pre",{className:"p-4 text-[12px] font-mono text-[#C8C8D4] leading-relaxed whitespace-pre-wrap break-all",children:[n.content.slice(0,5e3),n.content.length>5e3&&r.jsxs("span",{className:"text-[#5A5A6E]",children:[`
430
430