@damn-dev/cli 0.9.15 → 0.9.17
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.
|
@@ -351,7 +351,7 @@ XID_Start XIDS`.split(/\s/).map(e=>[ky(e),e])),zFe=new Map([["s",ts(383)],[ts(38
|
|
|
351
351
|
?|[
|
|
352
352
|
\v\f
\u2028\u2029])`),t));else if(c==="posix")if(!i&&(f==="graph"||f==="print")){if(s==="strict")throw new Error(`POSIX class "${f}" requires min target ES2024 or non-strict accuracy`);let p={graph:"!-~",print:" -~"}[f];d&&(p=`\0-${ts(p.codePointAt(0)-1)}${ts(p.codePointAt(2)+1)}-`),n(Mn(go(`[${p}]`),t))}else n(Mn(ZA(go(UFe.get(f)),d),t));else if(c==="property")BN.has(ky(f))||(e.key="sc");else if(c==="space")n(El(Ad("space",{negate:d}),t));else if(c==="word")n(Mn(ZA(go(xo),d),t));else throw new Error(`Unexpected character set kind "${c}"`)},Directive({node:e,parent:t,root:n,remove:s,replaceWith:i,removeAllPrevSiblings:a,removeAllNextSiblings:o}){const{kind:l,flags:c}=e;if(l==="flags")if(!c.enable&&!c.disable)s();else{const d=Qr({flags:c});d.body[0].body=o(),i(Mn(d,t),{traverse:!0})}else if(l==="keep"){const d=n.body[0],p=n.body.length===1&&IH(d,{type:"Group"})&&d.body[0].body.length===1?d.body[0]:n;if(t.parent!==p||p.body.length>1)throw new Error(Xe`Uses "\K" in a way that's unsupported`);const m=zc({behind:!0});m.body[0].body=a(),i(Mn(m,t))}else throw new Error(`Unexpected directive kind "${l}"`)},Flags({node:e,parent:t}){if(e.posixIsAscii)throw new Error('Unsupported flag "P"');if(e.textSegmentMode==="word")throw new Error('Unsupported flag "y{w}"');["digitIsAscii","extended","posixIsAscii","spaceIsAscii","wordIsAscii","textSegmentMode"].forEach(n=>delete e[n]),Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;const{enable:t,disable:n}=e.flags;t?.extended&&delete t.extended,n?.extended&&delete n.extended,t?.dotAll&&n?.dotAll&&delete t.dotAll,t?.ignoreCase&&n?.ignoreCase&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable,n&&!Object.keys(n).length&&delete e.flags.disable,!e.flags.enable&&!e.flags.disable&&delete e.flags},LookaroundAssertion({node:e},t){const{kind:n}=e;n==="lookbehind"&&(t.passedLookbehind=!0)},NamedCallout({node:e,parent:t,replaceWith:n}){const{kind:s}=e;if(s==="fail")n(Mn(zc({negate:!0}),t));else throw new Error(`Unsupported named callout "(*${s.toUpperCase()}"`)},Quantifier({node:e}){if(e.body.type==="Quantifier"){const t=Qr();t.body[0].body.push(e.body),e.body=Mn(t,e)}},Regex:{enter({node:e},{supportedGNodes:t}){const n=[];let s=!1,i=!1;for(const a of e.body)if(a.body.length===1&&a.body[0].kind==="search_start")a.body.pop();else{const o=ZH(a.body);o?(s=!0,Array.isArray(o)?n.push(...o):n.push(o)):i=!0}s&&!i&&n.forEach(a=>t.add(a))},exit(e,{accuracy:t,passedLookbehind:n,strategy:s}){if(t==="strict"&&n&&s)throw new Error(Xe`Uses "\G" in a way that requires non-strict accuracy`)}},Subroutine({node:e},{jsGroupNameMap:t}){let{ref:n}=e;typeof n=="string"&&!JA(n)&&(n=XA(n,t),e.ref=n)}},GFe={Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByReferencer:n}){const{orphan:s,ref:i}=e;s||n.set(e,[...t.get(i).map(({node:a})=>a)])},CapturingGroup:{enter({node:e,parent:t,replaceWith:n,skip:s},{groupOriginByCopy:i,groupsByName:a,multiplexCapturesToLeftByRef:o,openRefs:l,reffedNodesByReferencer:c}){const d=i.get(e);if(d&&l.has(e.number)){const p=El(W8(e.number),t);c.set(p,l.get(e.number)),n(p);return}l.set(e.number,e),o.set(e.number,[]),e.name&&im(o,e.name,[]);const f=o.get(e.name??e.number);for(let p=0;p<f.length;p++){const m=f[p];if(d===m.node||d&&d===m.origin||e===m.origin){f.splice(p,1);break}}if(o.get(e.number).push({node:e,origin:d}),e.name&&o.get(e.name).push({node:e,origin:d}),e.name){const p=im(a,e.name,new Map);let m=!1;if(d)m=!0;else for(const g of p.values())if(!g.hasDuplicateNameToRemove){m=!0;break}a.get(e.name).set(e,{node:e,hasDuplicateNameToRemove:m})}},exit({node:e},{openRefs:t}){t.delete(e.number)}},Group:{enter({node:e},t){t.prevFlags=t.currentFlags,e.flags&&(t.currentFlags=tv(t.currentFlags,e.flags))},exit(e,t){t.currentFlags=t.prevFlags}},Subroutine({node:e,parent:t,replaceWith:n},s){const{isRecursive:i,ref:a}=e;if(i){let f=t;for(;(f=f.parent)&&!(f.type==="CapturingGroup"&&(f.name===a||f.number===a)););s.reffedNodesByReferencer.set(e,f);return}const o=s.subroutineRefMap.get(a),l=a===0,c=l?W8(0):QH(o,s.groupOriginByCopy,null);let d=c;if(!l){const f=XH(XFe(o,m=>m.type==="Group"&&!!m.flags)),p=f?tv(s.globalFlags,f):s.globalFlags;YFe(p,s.currentFlags)||(d=Qr({flags:JFe(p)}),d.body[0].body.push(c))}n(Mn(d,t),{traverse:!l})}},KFe={Backreference({node:e,parent:t,replaceWith:n},s){if(e.orphan){s.highestOrphanBackref=Math.max(s.highestOrphanBackref,e.ref);return}const a=s.reffedNodesByReferencer.get(e).filter(o=>QFe(o,e));if(!a.length)n(Mn(zc({negate:!0}),t));else if(a.length>1){const o=Qr({atomic:!0,body:a.reverse().map(l=>pu({body:[kC(l.number)]}))});n(Mn(o,t))}else e.ref=a[0].number},CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,e.name&&t.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove&&delete e.name},Regex:{exit({node:e},t){const n=Math.max(t.highestOrphanBackref-t.numCapturesToLeft,0);for(let s=0;s<n;s++){const i=BH();e.body.at(-1).body.push(i)}}},Subroutine({node:e},t){!e.isRecursive||e.ref===0||(e.ref=t.reffedNodesByReferencer.get(e).number)}};function YH(e){wp(e,{"*"({node:t,parent:n}){t.parent=n}})}function YFe(e,t){return e.dotAll===t.dotAll&&e.ignoreCase===t.ignoreCase}function QFe(e,t){let n=t;do{if(n.type==="Regex")return!1;if(n.type==="Alternative")continue;if(n===e)return!1;const s=JH(n.parent);for(const i of s){if(i===n)break;if(i===e||eW(i,e))return!0}}while(n=n.parent);throw new Error("Unexpected path")}function QH(e,t,n,s){const i=Array.isArray(e)?[]:{};for(const[a,o]of Object.entries(e))a==="parent"?i.parent=Array.isArray(n)?s:n:o&&typeof o=="object"?i[a]=QH(o,t,i,n):(a==="type"&&o==="CapturingGroup"&&t.set(i,t.get(e)??e),i[a]=o);return i}function W8(e){const t=$H(e);return t.isRecursive=!0,t}function XFe(e,t){const n=[];for(;e=e.parent;)(!t||t(e))&&n.push(e);return n}function XA(e,t){if(t.has(e))return t.get(e);const n=`$${t.size}_${e.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/ug,"_")}`;return t.set(e,n),n}function XH(e){const t=["dotAll","ignoreCase"],n={enable:{},disable:{}};return e.forEach(({flags:s})=>{t.forEach(i=>{s.enable?.[i]&&(delete n.disable[i],n.enable[i]=!0),s.disable?.[i]&&(n.disable[i]=!0)})}),Object.keys(n.enable).length||delete n.enable,Object.keys(n.disable).length||delete n.disable,n.enable||n.disable?n:null}function JFe({dotAll:e,ignoreCase:t}){const n={};return(e||t)&&(n.enable={},e&&(n.enable.dotAll=!0),t&&(n.enable.ignoreCase=!0)),(!e||!t)&&(n.disable={},!e&&(n.disable.dotAll=!0),!t&&(n.disable.ignoreCase=!0)),n}function JH(e){if(!e)throw new Error("Node expected");const{body:t}=e;return Array.isArray(t)?t:t?[t]:null}function ZH(e){const t=e.find(n=>n.kind==="search_start"||tTe(n,{negate:!1})||!ZFe(n));if(!t)return null;if(t.kind==="search_start")return t;if(t.type==="LookaroundAssertion")return t.body[0].body[0];if(t.type==="CapturingGroup"||t.type==="Group"){const n=[];for(const s of t.body){const i=ZH(s.body);if(!i)return null;Array.isArray(i)?n.push(...i):n.push(i)}return n}return null}function eW(e,t){const n=JH(e)??[];for(const s of n)if(s===t||eW(s,t))return!0;return!1}function ZFe({type:e}){return e==="Assertion"||e==="Directive"||e==="LookaroundAssertion"}function eTe(e){const t=["Character","CharacterClass","CharacterSet"];return t.includes(e.type)||e.type==="Quantifier"&&e.min&&t.includes(e.body.type)}function tTe(e,t){const n={negate:null,...t};return e.type==="LookaroundAssertion"&&(n.negate===null||e.negate===n.negate)&&e.body.length===1&&IH(e.body[0],{type:"Assertion",kind:"search_start"})}function JA(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function go(e,t){const s=LH(e,{...t,unicodePropertyMap:BN}).body;return s.length>1||s[0].body.length>1?Qr({body:s}):s[0].body[0]}function ZA(e,t){return e.negate=t,e}function El(e,t){return e.parent=t,e}function Mn(e,t){return YH(e),e.parent=t,e}function nTe(e,t){const n=qH(t),s=TC(n.target,"ES2024"),i=TC(n.target,"ES2025"),a=n.rules.recursionLimit;if(!Number.isInteger(a)||a<2||a>20)throw new Error("Invalid recursionLimit; use 2-20");let o=null,l=null;if(!i){const g=[e.flags.ignoreCase];wp(e,sTe,{getCurrentModI:()=>g.at(-1),popModI(){g.pop()},pushModI(b){g.push(b)},setHasCasedChar(){g.at(-1)?o=!0:l=!0}})}const c={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||o)&&!l)};let d=e;const f={accuracy:n.accuracy,appliedGlobalFlags:c,captureMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},inCharClass:!1,lastNode:d,originMap:e._originMap,recursionLimit:a,useAppliedIgnoreCase:!!(!i&&o&&l),useFlagMods:i,useFlagV:s,verbose:n.verbose};function p(g){return f.lastNode=d,d=g,PFe(iTe[g.type],`Unexpected node type "${g.type}"`)(g,f,p)}const m={pattern:e.body.map(p).join("|"),flags:p(e.flags),options:{...e.options}};return s||(delete m.options.force.v,m.options.disable.v=!0,m.options.unicodeSetsPlugin=null),m._captureTransfers=new Map,m._hiddenCaptures=[],f.captureMap.forEach((g,b)=>{g.hidden&&m._hiddenCaptures.push(b),g.transferTo&&im(m._captureTransfers,g.transferTo,[]).push(b)}),m}var sTe={"*":{enter({node:e},t){if(G8(e)){const n=t.getCurrentModI();t.pushModI(e.flags?tv({ignoreCase:n},e.flags).ignoreCase:n)}},exit({node:e},t){G8(e)&&t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){zN(ts(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},n){t(),tW(e,{firstOnly:!0}).length&&n.setHasCasedChar()},CharacterSet({node:e},t){e.kind==="property"&&KH.has(e.value)&&t.setHasCasedChar()}},iTe={Alternative({body:e},t,n){return e.map(n).join("")},Assertion({kind:e,negate:t}){if(e==="string_end")return"$";if(e==="string_start")return"^";if(e==="word_boundary")return t?Xe`\B`:Xe`\b`;throw new Error(`Unexpected assertion kind "${e}"`)},Backreference({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&t.accuracy==="strict"&&t.currentFlags.ignoreCase&&!t.captureMap.get(e).ignoreCase)throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");return"\\"+e},CapturingGroup(e,t,n){const{body:s,name:i,number:a}=e,o={ignoreCase:t.currentFlags.ignoreCase},l=t.originMap.get(e);return l&&(o.hidden=!0,a>l.number&&(o.transferTo=l.number)),t.captureMap.set(a,o),`(${i?`?<${i}>`:""}${s.map(n).join("|")})`},Character({value:e},t){const n=ts(e),s=vd(e,{escDigit:t.lastNode.type==="Backreference",inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(s!==n)return s;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&zN(n)){const i=GH(n);return t.inCharClass?i.join(""):i.length>1?`[${i.join("")}]`:i[0]}return n},CharacterClass(e,t,n){const{kind:s,negate:i,parent:a}=e;let{body:o}=e;if(s==="intersection"&&!t.useFlagV)throw new Error("Use of character class intersection requires min target ES2024");na.bugFlagVLiteralHyphenIsRange&&t.useFlagV&&o.some(K8)&&(o=[Ny(45),...o.filter(d=>!K8(d))]);const l=()=>`[${i?"^":""}${o.map(n).join(s==="intersection"?"&&":"")}]`;if(!t.inCharClass){if((!t.useFlagV||na.bugNestedClassIgnoresNegation)&&!i){const f=o.filter(p=>p.type==="CharacterClass"&&p.kind==="union"&&p.negate);if(f.length){const p=Qr(),m=p.body[0];return p.parent=a,m.parent=p,o=o.filter(g=>!f.includes(g)),e.body=o,o.length?(e.parent=m,m.body.push(e)):p.body.pop(),f.forEach(g=>{const b=pu({body:[g]});g.parent=b,b.parent=p,p.body.push(b)}),n(p)}}t.inCharClass=!0;const d=l();return t.inCharClass=!1,d}const c=o[0];if(s==="union"&&!i&&c&&((!t.useFlagV||!t.verbose)&&a.kind==="union"&&!(na.bugFlagVLiteralHyphenIsRange&&t.useFlagV)||!t.verbose&&a.kind==="intersection"&&o.length===1&&c.type!=="CharacterClassRange"))return o.map(n).join("");if(!t.useFlagV&&a.type==="CharacterClass")throw new Error("Uses nested character class in a way that requires min target ES2024");return l()},CharacterClassRange(e,t){const n=e.min.value,s=e.max.value,i={escDigit:!1,inCharClass:!0,useFlagV:t.useFlagV},a=vd(n,i),o=vd(s,i),l=new Set;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){const c=tW(e);cTe(c).forEach(f=>{l.add(Array.isArray(f)?`${vd(f[0],i)}-${vd(f[1],i)}`:vd(f,i))})}return`${a}-${o}${[...l].join("")}`},CharacterSet({kind:e,negate:t,value:n,key:s},i){if(e==="dot")return i.currentFlags.dotAll?i.appliedGlobalFlags.dotAll||i.useFlagMods?".":"[^]":Xe`[^\n]`;if(e==="digit")return t?Xe`\D`:Xe`\d`;if(e==="property"){if(i.useAppliedIgnoreCase&&i.currentFlags.ignoreCase&&KH.has(n))throw new Error(`Unicode property "${n}" can't be case-insensitive when other chars have specific case`);return`${t?Xe`\P`:Xe`\p`}{${s?`${s}=`:""}${n}}`}if(e==="word")return t?Xe`\W`:Xe`\w`;throw new Error(`Unexpected character set kind "${e}"`)},Flags(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")},Group({atomic:e,body:t,flags:n,parent:s},i,a){const o=i.currentFlags;n&&(i.currentFlags=tv(o,n));const l=t.map(a).join("|"),c=!i.verbose&&t.length===1&&s.type!=="Quantifier"&&!e&&(!i.useFlagMods||!n)?l:`(?${uTe(e,n,i.useFlagMods)}${l})`;return i.currentFlags=o,c},LookaroundAssertion({body:e,kind:t,negate:n},s,i){return`(?${`${t==="lookahead"?"":"<"}${n?"!":"="}`}${e.map(i).join("|")})`},Quantifier(e,t,n){return n(e.body)+dTe(e)},Subroutine({isRecursive:e,ref:t},n){if(!e)throw new Error("Unexpected non-recursive subroutine in transformed AST");const s=n.recursionLimit;return t===0?`(?R=${s})`:Xe`\g<${t}&R=${s}>`}},rTe=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),aTe=new Set(["-","\\","]","^","["]),oTe=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),q8=new Map([[9,Xe`\t`],[10,Xe`\n`],[11,Xe`\v`],[12,Xe`\f`],[13,Xe`\r`],[8232,Xe`\u2028`],[8233,Xe`\u2029`],[65279,Xe`\uFEFF`]]),lTe=new RegExp("^\\p{Cased}$","u");function zN(e){return lTe.test(e)}function tW(e,t){const n=!!t?.firstOnly,s=e.min.value,i=e.max.value,a=[];if(s<65&&(i===65535||i>=131071)||s===65536&&i>=131071)return a;for(let o=s;o<=i;o++){const l=ts(o);if(!zN(l))continue;const c=GH(l).filter(d=>{const f=d.codePointAt(0);return f<s||f>i});if(c.length&&(a.push(...c),n))break}return a}function vd(e,{escDigit:t,inCharClass:n,useFlagV:s}){if(q8.has(e))return q8.get(e);if(e<32||e>126&&e<160||e>262143||t&&hTe(e))return e>255?`\\u{${e.toString(16).toUpperCase()}}`:`\\x${e.toString(16).toUpperCase().padStart(2,"0")}`;const i=n?s?oTe:aTe:rTe,a=ts(e);return(i.has(a)?"\\":"")+a}function cTe(e){const t=e.map(i=>i.codePointAt(0)).sort((i,a)=>i-a),n=[];let s=null;for(let i=0;i<t.length;i++)t[i+1]===t[i]+1?s??=t[i]:s===null?n.push(t[i]):(n.push([s,t[i]]),s=null);return n}function uTe(e,t,n){if(e)return">";let s="";if(t&&n){const{enable:i,disable:a}=t;s=(i?.ignoreCase?"i":"")+(i?.dotAll?"s":"")+(a?"-":"")+(a?.ignoreCase?"i":"")+(a?.dotAll?"s":"")}return`${s}:`}function dTe({kind:e,max:t,min:n}){let s;return!n&&t===1?s="?":!n&&t===1/0?s="*":n===1&&t===1/0?s="+":n===t?s=`{${n}}`:s=`{${n},${t===1/0?"":t}}`,s+{greedy:"",lazy:"?",possessive:"+"}[e]}function G8({type:e}){return e==="CapturingGroup"||e==="Group"||e==="LookaroundAssertion"}function hTe(e){return e>47&&e<58}function K8({type:e,value:t}){return e==="Character"&&t===45}var fTe=class MC extends RegExp{#t=new Map;#e=null;#n;#i=null;#s=null;rawOptions={};get source(){return this.#n||"(?:)"}constructor(t,n,s){const i=!!s?.lazyCompile;if(t instanceof RegExp){if(s)throw new Error("Cannot provide options when copying a regexp");const a=t;super(a,n),this.#n=a.source,a instanceof MC&&(this.#t=a.#t,this.#i=a.#i,this.#s=a.#s,this.rawOptions=a.rawOptions)}else{const a={hiddenCaptures:[],strategy:null,transfers:[],...s};super(i?"":t,n),this.#n=t,this.#t=mTe(a.hiddenCaptures,a.transfers),this.#s=a.strategy,this.rawOptions=s??{}}i||(this.#e=this)}exec(t){if(!this.#e){const{lazyCompile:i,...a}=this.rawOptions;this.#e=new MC(this.#n,this.flags,a)}const n=this.global||this.sticky,s=this.lastIndex;if(this.#s==="clip_search"&&n&&s){this.lastIndex=0;const i=this.#r(t.slice(s));return i&&(pTe(i,s,t,this.hasIndices),this.lastIndex+=s),i}return this.#r(t)}#r(t){this.#e.lastIndex=this.lastIndex;const n=super.exec.call(this.#e,t);if(this.lastIndex=this.#e.lastIndex,!n||!this.#t.size)return n;const s=[...n];n.length=1;let i;this.hasIndices&&(i=[...n.indices],n.indices.length=1);const a=[0];for(let o=1;o<s.length;o++){const{hidden:l,transferTo:c}=this.#t.get(o)??{};if(l?a.push(null):(a.push(n.length),n.push(s[o]),this.hasIndices&&n.indices.push(i[o])),c&&s[o]!==void 0){const d=a[c];if(!d)throw new Error(`Invalid capture transfer to "${d}"`);if(n[d]=s[o],this.hasIndices&&(n.indices[d]=i[o]),n.groups){this.#i||(this.#i=xTe(this.source));const f=this.#i.get(c);f&&(n.groups[f]=s[o],this.hasIndices&&(n.indices.groups[f]=i[o]))}}}return n}};function pTe(e,t,n,s){if(e.index+=t,e.input=n,s){const i=e.indices;for(let o=0;o<i.length;o++){const l=i[o];l&&(i[o]=[l[0]+t,l[1]+t])}const a=i.groups;a&&Object.keys(a).forEach(o=>{const l=a[o];l&&(a[o]=[l[0]+t,l[1]+t])})}}function mTe(e,t){const n=new Map;for(const s of e)n.set(s,{hidden:!0});for(const[s,i]of t)for(const a of i)im(n,a,{}).transferTo=s;return n}function xTe(e){const t=/(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu,n=new Map;let s=0,i=0,a;for(;a=t.exec(e);){const{0:o,groups:{capture:l,name:c}}=a;o==="["?s++:s?o==="]"&&s--:l&&(i++,c&&n.set(i,c))}return n}function gTe(e,t){const n=bTe(e,t);return n.options?new fTe(n.pattern,n.flags,n.options):new RegExp(n.pattern,n.flags)}function bTe(e,t){const n=qH(t),s=LH(e,{flags:n.flags,normalizeUnknownPropertyNames:!0,rules:{captureGroup:n.rules.captureGroup,singleline:n.rules.singleline},skipBackrefValidation:n.rules.allowOrphanBackrefs,unicodePropertyMap:BN}),i=WFe(s,{accuracy:n.accuracy,asciiWordBoundaries:n.rules.asciiWordBoundaries,avoidSubclass:n.avoidSubclass,bestEffortTarget:n.target}),a=nTe(i,n),o=DFe(a.pattern,{captureTransfers:a._captureTransfers,hiddenCaptures:a._hiddenCaptures,mode:"external"}),l=MFe(o.pattern),c=TFe(l.pattern,{captureTransfers:o.captureTransfers,hiddenCaptures:o.hiddenCaptures}),d={pattern:c.pattern,flags:`${n.hasIndices?"d":""}${n.global?"g":""}${a.flags}${a.options.disable.v?"u":"v"}`};if(n.avoidSubclass){if(n.lazyCompileLength!==1/0)throw new Error("Lazy compilation requires subclass")}else{const f=c.hiddenCaptures.sort((b,_)=>b-_),p=Array.from(c.captureTransfers),m=i._strategy,g=d.pattern.length>=n.lazyCompileLength;(f.length||p.length||m||g)&&(d.options={...f.length&&{hiddenCaptures:f},...p.length&&{transfers:p},...m&&{strategy:m},...g&&{lazyCompile:g}})}return d}function nW(e,t){return gTe(e,{global:!0,hasIndices:!0,lazyCompileLength:3e3,rules:{allowOrphanBackrefs:!0,asciiWordBoundaries:!0,captureGroup:!0,recursionLimit:5,singleline:!0},...t})}function vTe(e={}){const t=Object.assign({target:"auto",cache:new Map},e);return t.regexConstructor||=n=>nW(n,{target:t.target}),{createScanner(n){return new O4e(n,t)},createString(n){return{content:n}}}}var yTe=_N({bundledLanguages:()=>SN,bundledLanguagesAlias:()=>AN,bundledLanguagesBase:()=>wN,bundledLanguagesInfo:()=>vy,bundledThemes:()=>jN,bundledThemesInfo:()=>CN,codeToHast:()=>jH,codeToHtml:()=>ON,codeToTokens:()=>NH,codeToTokensBase:()=>kH,codeToTokensWithThemes:()=>EH,createHighlighter:()=>DN,createJavaScriptRegexEngine:()=>vTe,createOnigurumaEngine:()=>qU,defaultJavaScriptRegexConstructor:()=>nW,getLastGrammarState:()=>TH,getSingletonHighlighter:()=>FH,loadWasm:()=>kN});UU(yTe,D4e);const _Te=new Set([".png",".jpg",".jpeg",".gif",".bmp",".ico",".webp",".svg"]),wTe=new Set([".mp3",".wav",".ogg"]),ATe=new Set([".mp4",".webm"]),STe=new Set([".ts",".tsx",".js",".jsx",".py",".rs",".go",".java",".c",".cpp",".h",".hpp",".cs",".rb",".php",".swift",".kt",".sh",".bash",".zsh",".fish",".sql",".graphql",".vue",".svelte",".css",".scss",".less",".html",".xml",".yaml",".yml",".toml",".prisma",".proto",".lua",".zig",".ex",".exs",".erl",".hrl",".clj",".cljs",".hs",".ml",".mli",".r",".jl",".dart",".tf",".jsonc"]),CTe={".ts":"typescript",".tsx":"tsx",".js":"javascript",".jsx":"jsx",".py":"python",".rs":"rust",".go":"go",".java":"java",".c":"c",".cpp":"cpp",".h":"c",".hpp":"cpp",".cs":"csharp",".rb":"ruby",".php":"php",".swift":"swift",".kt":"kotlin",".sh":"bash",".bash":"bash",".zsh":"bash",".fish":"bash",".sql":"sql",".graphql":"graphql",".vue":"vue",".svelte":"svelte",".css":"css",".scss":"scss",".less":"less",".html":"html",".xml":"xml",".yaml":"yaml",".yml":"yaml",".toml":"toml",".json":"json",".jsonc":"jsonc",".prisma":"prisma",".lua":"lua",".zig":"zig",".dart":"dart",".tf":"hcl",".r":"r",".md":"markdown"};function jTe(e){const t=e.lastIndexOf(".");return t>=0?e.slice(t).toLowerCase():""}function sW(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function NTe(e,t){return`${oi}/api/files/serve/${e}/${t}`}function kTe({src:e}){const[t,n]=y.useState(!1);return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"p-4 flex items-center justify-center",children:r.jsx("img",{src:e,alt:"",className:"max-w-full max-h-[400px] rounded-md border border-[#2A2A35] cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>n(!0)})}),t&&r.jsxs("div",{className:"fixed inset-0 z-50 bg-black/80 flex items-center justify-center cursor-pointer",onClick:()=>n(!1),children:[r.jsx("button",{onClick:()=>n(!1),className:"absolute top-4 right-4 w-8 h-8 flex items-center justify-center rounded-full bg-white/10 text-white hover:bg-white/20 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})}),r.jsx("img",{src:e,alt:"",className:"max-w-[90vw] max-h-[90vh] rounded-lg",onClick:s=>s.stopPropagation()})]})]})}function Y8({content:e,separator:t}){const[n,s]=y.useState(null),[i,a]=y.useState(!0),{headers:o,rows:l}=y.useMemo(()=>{const f=e.trim().split(`
|
|
353
353
|
`).filter(Boolean);if(f.length===0)return{headers:[],rows:[]};const p=f[0].split(t).map(g=>g.trim().replace(/^"|"$/g,"")),m=f.slice(1).map(g=>g.split(t).map(b=>b.trim().replace(/^"|"$/g,"")));return{headers:p,rows:m}},[e,t]),c=y.useMemo(()=>n===null?l:[...l].sort((f,p)=>{const m=f[n]??"",g=p[n]??"",b=Number(m),_=Number(g);return!isNaN(b)&&!isNaN(_)?i?b-_:_-b:i?m.localeCompare(g):g.localeCompare(m)}),[l,n,i]);function d(f){n===f?a(!i):(s(f),a(!0))}return o.length===0?r.jsx("p",{className:"p-4 text-[12px] text-[#5A5A6E]",children:"Empty CSV"}):r.jsx("div",{className:"overflow-auto",children:r.jsxs("table",{className:"w-full text-[11px]",children:[r.jsx("thead",{children:r.jsx("tr",{className:"border-b border-[#2A2A35]",children:o.map((f,p)=>r.jsxs("th",{onClick:()=>d(p),className:"px-3 py-2 text-left text-[#8A8A99] font-medium cursor-pointer hover:text-[#C8C8D4] transition-colors whitespace-nowrap select-none",children:[f,n===p&&r.jsx("span",{className:"ml-1 text-[#6366F1]",children:i?"↑":"↓"})]},p))})}),r.jsx("tbody",{children:c.map((f,p)=>r.jsx("tr",{className:"border-b border-[#2A2A35]/50 hover:bg-white/[0.02]",children:f.map((m,g)=>r.jsx("td",{className:"px-3 py-1.5 text-[#C8C8D4] whitespace-nowrap",children:m},g))},p))})]})})}function RC({data:e,depth:t=0}){const[n,s]=y.useState(t>2);if(e===null)return r.jsx("span",{className:"text-[#F59E0B]",children:"null"});if(typeof e=="boolean")return r.jsx("span",{className:"text-[#F59E0B]",children:String(e)});if(typeof e=="number")return r.jsx("span",{className:"text-[#10B981]",children:e});if(typeof e=="string")return r.jsxs("span",{className:"text-[#6366F1]",children:['"',e,'"']});if(Array.isArray(e))return e.length===0?r.jsx("span",{className:"text-[#5A5A6E]",children:"[]"}):r.jsxs("span",{children:[r.jsx("button",{onClick:()=>s(!n),className:"inline-flex items-center text-[#5A5A6E] hover:text-[#C8C8D4]",children:n?r.jsx(Jt,{className:"w-3 h-3"}):r.jsx(ft,{className:"w-3 h-3"})}),r.jsx("span",{className:"text-[#5A5A6E]",children:"["}),n?r.jsxs("span",{className:"text-[#5A5A6E] cursor-pointer",onClick:()=>s(!1),children:[e.length," items"]}):r.jsx("div",{style:{paddingLeft:16},children:e.map((i,a)=>r.jsxs("div",{children:[r.jsx(RC,{data:i,depth:t+1}),a<e.length-1&&r.jsx("span",{className:"text-[#5A5A6E]",children:","})]},a))}),r.jsx("span",{className:"text-[#5A5A6E]",children:"]"})]});if(typeof e=="object"){const i=Object.entries(e);return i.length===0?r.jsx("span",{className:"text-[#5A5A6E]",children:"{}"}):r.jsxs("span",{children:[r.jsx("button",{onClick:()=>s(!n),className:"inline-flex items-center text-[#5A5A6E] hover:text-[#C8C8D4]",children:n?r.jsx(Jt,{className:"w-3 h-3"}):r.jsx(ft,{className:"w-3 h-3"})}),r.jsx("span",{className:"text-[#5A5A6E]",children:"{"}),n?r.jsxs("span",{className:"text-[#5A5A6E] cursor-pointer",onClick:()=>s(!1),children:[i.length," keys"]}):r.jsx("div",{style:{paddingLeft:16},children:i.map(([a,o],l)=>r.jsxs("div",{children:[r.jsxs("span",{className:"text-[#EC4899]",children:['"',a,'"']}),r.jsx("span",{className:"text-[#5A5A6E]",children:": "}),r.jsx(RC,{data:o,depth:t+1}),l<i.length-1&&r.jsx("span",{className:"text-[#5A5A6E]",children:","})]},a))}),r.jsx("span",{className:"text-[#5A5A6E]",children:"}"})]})}return r.jsx("span",{className:"text-[#C8C8D4]",children:String(e)})}function iW({content:e,ext:t}){const[n,s]=y.useState(null);return y.useEffect(()=>{const i=CTe[t]??"text";let a=!1;return ON(e,{lang:i,theme:"github-dark-default"}).then(o=>{a||s(o)}).catch(()=>{a||s(null)}),()=>{a=!0}},[e,t]),n?r.jsx("div",{className:"px-1 py-1 text-[11px] leading-[1.6] [&_pre]:!bg-transparent [&_pre]:p-2 [&_code]:text-[11px] overflow-auto",dangerouslySetInnerHTML:{__html:n}}):r.jsx("pre",{className:"px-3 py-2 text-[11px] font-mono text-[#C8C8D4] leading-[1.6] whitespace-pre-wrap break-all",children:e})}function ETe({content:e,ext:t}){const n=y.useMemo(()=>{try{return JSON.parse(e)}catch{return null}},[e]);return n===null?r.jsx(iW,{content:e,ext:t}):r.jsx("div",{className:"px-3 py-2 text-[11px] font-mono leading-[1.6] overflow-auto",children:r.jsx(RC,{data:n})})}function FTe({agentId:e,filePath:t,content:n,binary:s,size:i,ext:a}){const o=t.split("/").pop()??t,l=a||jTe(o),c=NTe(e,t);return _Te.has(l)?r.jsxs("div",{children:[r.jsx(kTe,{src:c}),r.jsx(Uf,{url:c,filename:o,size:i})]}):wTe.has(l)?r.jsxs("div",{className:"p-4 space-y-3",children:[r.jsx("audio",{controls:!0,className:"w-full",preload:"metadata",children:r.jsx("source",{src:c})}),r.jsx(Uf,{url:c,filename:o,size:i})]}):ATe.has(l)?r.jsxs("div",{className:"p-4 space-y-3",children:[r.jsx("video",{controls:!0,className:"w-full max-h-[400px] rounded-md border border-[#2A2A35]",preload:"metadata",children:r.jsx("source",{src:c})}),r.jsx(Uf,{url:c,filename:o,size:i})]}):l===".pdf"?r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("iframe",{src:c,className:"flex-1 min-h-[400px] border-0",title:o}),r.jsx(Uf,{url:c,filename:o,size:i})]}):!n&&s?r.jsxs("div",{className:"p-4 text-center space-y-2",children:[r.jsxs("p",{className:"text-[12px] text-[#5A5A6E]",children:["Binary file (",l,")"]}),r.jsx(Uf,{url:c,filename:o,size:i})]}):n?l===".md"?r.jsx("div",{className:"px-4 py-3 prose-message text-[13px]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:n})}):l===".csv"?r.jsx(Y8,{content:n,separator:","}):l===".tsv"?r.jsx(Y8,{content:n,separator:"\\t"}):(l===".json"||l===".jsonc")&&CU(o)?r.jsx(jU,{agentId:e,filePath:t,content:n}):l===".json"||l===".jsonc"?r.jsx(ETe,{content:n,ext:l}):STe.has(l)?r.jsx(iW,{content:n,ext:l}):r.jsx("pre",{className:"px-3 py-2 text-[11px] font-mono text-[#C8C8D4] leading-[1.6] whitespace-pre-wrap break-all",children:n}):r.jsxs("div",{className:"p-4 text-center",children:[r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"No preview available"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:sW(i)})]})}function Uf({url:e,filename:t,size:n}){const s=y.useCallback(()=>{const i=document.createElement("a");i.href=e,i.download=t,i.click()},[e,t]);return r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t border-[#2A2A35]/50",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:sW(n)}),r.jsxs("button",{onClick:s,className:"flex items-center gap-1 text-[11px] text-[#8A8A99] hover:text-[#C8C8D4] transition-colors",children:[r.jsx(nu,{className:"w-3 h-3"}),"Download"]})]})}const rW=new Set([".ts",".tsx",".js",".jsx",".py",".rs",".go",".java",".c",".cpp",".h",".hpp",".cs",".rb",".php",".swift",".kt",".sh",".bash",".zsh",".fish",".sql",".graphql",".vue",".svelte",".css",".scss",".less",".html",".xml",".yaml",".yml",".toml",".json",".jsonc",".prisma",".proto",".lua",".zig",".ex",".exs",".erl",".hrl",".clj",".cljs",".hs",".ml",".mli",".r",".jl",".dart",".tf"]),aW=new Set([".png",".jpg",".jpeg",".gif",".bmp",".ico",".webp",".svg"]),oW=new Set([".mp3",".wav",".ogg"]),lW=new Set([".mp4",".webm"]),cW=new Set([".csv",".tsv",".json",".jsonc"]),TTe=new Set([".md",".txt",".pdf"]),MTe=new Set([...oW,...lW]),RTe=[{key:"all",label:"All"},{key:"documents",label:"Docs"},{key:"images",label:"Images"},{key:"code",label:"Code"},{key:"data",label:"Data"},{key:"media",label:"Media"}];function DTe(e){const t=e.includes(".")?`.${e.split(".").pop().toLowerCase()}`:"";return aW.has(t)?"images":rW.has(t)?"code":cW.has(t)?"data":MTe.has(t)?"media":(TTe.has(t),"documents")}function uW(e){const t=e.includes(".")?`.${e.split(".").pop().toLowerCase()}`:"";return aW.has(t)?r.jsx(fie,{className:"w-3.5 h-3.5 text-[#EC4899] flex-shrink-0"}):oW.has(t)?r.jsx(die,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}):lW.has(t)?r.jsx(mie,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}):cW.has(t)?r.jsx(gie,{className:"w-3.5 h-3.5 text-[#10B981] flex-shrink-0"}):rW.has(t)?r.jsx(aL,{className:"w-3.5 h-3.5 text-[#6366F1] flex-shrink-0"}):t===".md"?r.jsx(li,{className:"w-3.5 h-3.5 text-[#10B981] flex-shrink-0"}):r.jsx(gv,{className:"w-3.5 h-3.5 text-[#5A5A6E] flex-shrink-0"})}function DC(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function OTe(e){const t=new Date(e),s=new Date().getTime()-t.getTime(),i=Math.floor(s/6e4);if(i<1)return"just now";if(i<60)return`${i}m ago`;const a=Math.floor(i/60);if(a<24)return`${a}h ago`;const o=Math.floor(a/24);return o<30?`${o}d ago`:t.toLocaleDateString()}function dW(e,t,n){if(e.type==="file"){const s=!t||e.name.toLowerCase().includes(t.toLowerCase()),i=n==="all"||DTe(e.name)===n;return s&&i}return e.type==="dir"&&e.children?e.children.some(s=>dW(s,t,n)):!1}function hW(e,t,n){return!t&&n==="all"?e:e.filter(s=>dW(s,t,n)).map(s=>s.type==="dir"&&s.children?{...s,children:hW(s.children,t,n)}:s)}function fW(e){return[...e].sort((t,n)=>t.type==="dir"&&n.type!=="dir"?-1:t.type!=="dir"&&n.type==="dir"?1:new Date(n.modified).getTime()-new Date(t.modified).getTime()).map(t=>t.type==="dir"&&t.children?{...t,children:fW(t.children)}:t)}function pW({node:e,depth:t,agentId:n,mountSource:s,filter:i,onFileClick:a}){const o=e.type==="dir"&&(e.children?.length??0)>15,[l,c]=y.useState(()=>o?!1:t<1),d=i?!0:l,[f,p]=y.useState(!1),m=y.useCallback(()=>{e.type==="dir"?c(b=>!b):a(e.path,s)},[e,s,a]),g=e.type==="dir";return r.jsxs("div",{children:[r.jsxs("div",{onClick:m,onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),onContextMenu:b=>{b.preventDefault(),navigator.clipboard.writeText(e.path)},className:"flex items-center gap-1.5 py-[3px] pr-3 cursor-pointer hover:bg-white/[0.04] rounded-sm transition-colors group",style:{paddingLeft:`${12+t*16}px`},children:[g?r.jsxs(r.Fragment,{children:[r.jsx(ne.span,{animate:{rotate:d?90:0},transition:{duration:.1},className:"flex items-center justify-center w-3.5 h-3.5 flex-shrink-0",children:r.jsx(Jt,{className:"w-3 h-3 text-[#5A5A6E]"})}),d?r.jsx(vm,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}):r.jsx(cL,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"})]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"w-3.5 h-3.5 flex-shrink-0"}),uW(e.name)]}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] truncate flex-1",children:e.name}),f&&!g&&r.jsxs("span",{className:"text-[10px] text-[#5A5A6E] flex-shrink-0 whitespace-nowrap",children:[DC(e.size)," · ",OTe(e.modified)]})]}),g&&d&&e.children&&r.jsx(Me,{initial:!1,children:r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.1},className:"overflow-hidden",children:e.children.map(b=>r.jsx(pW,{node:b,depth:t+1,agentId:n,mountSource:s,filter:i,onFileClick:a},b.path))})})]})}function PTe({agentId:e,filePath:t,mountSource:n,onClose:s}){const{data:i,isLoading:a}=L.files.read.useQuery({agentId:e,filePath:t,mountSource:n},{retry:!1}),[o,l]=y.useState(!1);if(a)return r.jsx("div",{className:"border-t border-[#2A2A35] p-4",children:r.jsxs("div",{className:"flex items-center gap-1.5 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]"})]})});if(!i)return null;const c=t.split("/").pop()??t;return r.jsxs("div",{className:"border-t border-[#2A2A35] flex flex-col max-h-[60%] min-h-[120px]",children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[uW(c),r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5] truncate",children:c}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:DC(i.size)})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[i.content&&r.jsx("button",{onClick:()=>{navigator.clipboard.writeText(i.content),l(!0),setTimeout(()=>l(!1),1500)},className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors",children:o?r.jsx(Fe,{className:"w-3 h-3 text-[#10B981]"}):r.jsx(Po,{className:"w-3 h-3"})}),r.jsx("button",{onClick:s,className:"text-[11px] text-[#5A5A6E] hover:text-[#C8C8D4] px-1.5 transition-colors",children:"Close"})]})]}),r.jsx("div",{className:"flex-1 overflow-auto min-h-0",children:"tooLarge"in i&&i.tooLarge?r.jsxs("div",{className:"p-4 text-center",children:[r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"File too large to preview."}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:DC(i.size)})]}):r.jsx(FTe,{agentId:e,filePath:t,content:i.content,binary:i.binary,size:i.size,ext:i.ext})})]})}function ITe({agentId:e}){const[t,n]=y.useState(""),[s,i]=y.useState("all"),[a,o]=y.useState(null),[l,c]=y.useState(null),d=y.useRef(null),f=y0(_=>_.openAgentFile),p=y.useCallback((_,w)=>{const A=_.split("/").pop()??_;_.endsWith(".md")&&!w?f(e,_):!w&&CU(A)?c(_):o({path:_,mountSource:w})},[e,f]),{data:m,isLoading:g}=L.files.tree.useQuery({agentId:e},{staleTime:1e4}),b=y.useMemo(()=>m?.roots?m.roots.map(_=>({..._,nodes:fW(hW(_.nodes,t,s))})):[],[m,t,s]);return y.useEffect(()=>{function _(w){w.key==="f"&&(w.metaKey||w.ctrlKey)&&(w.preventDefault(),d.current?.focus())}return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[]),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[r.jsxs("div",{className:"px-3 py-2 flex-shrink-0 space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Io,{className:"w-3.5 h-3.5 text-[#5A5A6E] flex-shrink-0"}),r.jsx("input",{ref:d,value:t,onChange:_=>n(_.target.value),placeholder:"Filter files...",className:"flex-1 bg-transparent text-[12px] text-[#C8C8D4] placeholder-[#5A5A6E] outline-none"}),t&&r.jsx("button",{onClick:()=>n(""),className:"text-[10px] text-[#5A5A6E] hover:text-[#C8C8D4] transition-colors",children:"Clear"})]}),r.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:RTe.map(_=>r.jsx("button",{onClick:()=>i(_.key),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${s===_.key?"bg-[#6366F1]/20 text-[#818CF8] border border-[#6366F1]/30":"bg-white/[0.04] text-[#5A5A6E] border border-transparent hover:text-[#8A8A99] hover:bg-white/[0.06]"}`,children:_.label},_.key))})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[g&&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]"})]}),!g&&b.length===0&&r.jsx("p",{className:"px-4 py-4 text-[12px] text-[#5A5A6E] italic",children:"No files found."}),b.map((_,w)=>r.jsxs("div",{children:[b.length>1&&r.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-b border-[#2A2A35]/50",children:[r.jsx(bv,{className:"w-3 h-3 text-[#5A5A6E]"}),r.jsx("span",{className:"text-[11px] font-medium text-[#8A8A99]",children:_.label})]}),_.nodes.map(A=>r.jsx(pW,{node:A,depth:0,agentId:e,mountSource:b.length>1?_.source:void 0,filter:t,onFileClick:p},A.path)),_.nodes.length===0&&r.jsx("p",{className:"px-4 py-2 text-[11px] text-[#5A5A6E] italic",children:"Empty"})]},w))]}),a&&r.jsx(PTe,{agentId:e,filePath:a.path,mountSource:a.mountSource,onClose:()=>o(null)}),l&&r.jsx(yN,{agentId:e,filePath:l,onClose:()=>c(null)})]})}function LTe({agentId:e}){const{data:t=[],refetch:n}=L.git.worktreeList.useQuery({agentId:e}),{data:s=[]}=L.channels.list.useQuery(),a=s.find(c=>c.agentId===e)?.id??"",o=L.git.worktreeRemove.useMutation({onSuccess:()=>n()}),l=L.git.worktreeMerge.useMutation({onSuccess:()=>n()});return t.length===0?null:r.jsxs("div",{className:"mb-3",children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[r.jsx(Zl,{className:"w-3 h-3 text-[#8B5CF6]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wider",children:"Worktrees"})]}),r.jsx("div",{className:"space-y-1",children:r.jsx(Me,{children:t.map(c=>r.jsxs(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-[#1C1C24] border border-[#2A2A35]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8B5CF6] flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[12px] font-mono text-[#A78BFA] truncate block",children:c.branch}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] truncate block",children:c.worktreeDir})]}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[r.jsx("button",{onClick:()=>l.mutate({worktreeId:c.id,channelId:a}),disabled:l.isPending,className:"p-1 rounded text-[#34D399] hover:bg-[#10B981]/10 transition-colors disabled:opacity-50",title:"Merge back",children:r.jsx(D5,{className:"w-3 h-3"})}),r.jsx("button",{onClick:()=>o.mutate({worktreeId:c.id}),disabled:o.isPending,className:"p-1 rounded text-[#F87171] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-50",title:"Remove worktree",children:r.jsx(Dn,{className:"w-3 h-3"})})]})]},c.id))})})]})}function BTe({date:e}){const t=y.useMemo(()=>{const n=new Date(e),i=new Date().getTime()-n.getTime(),a=Math.floor(i/6e4);if(a<1)return"just now";if(a<60)return`${a}m ago`;const o=Math.floor(a/60);if(o<24)return`${o}h ago`;const l=Math.floor(o/24);return l<30?`${l}d ago`:n.toLocaleDateString()},[e]);return r.jsx("span",{children:t})}const zTe={modified:"text-[#F59E0B]",added:"text-[#10B981]",deleted:"text-[#EF4444]",renamed:"text-[#6366F1]",untracked:"text-[#5A5A6E]",staged:"text-[#10B981]"},$Te={modified:"M",added:"A",deleted:"D",renamed:"R",untracked:"?",staged:"S"};function e2({path:e,status:t,staged:n,selected:s,onSelect:i,onViewDiff:a}){const o=e.split("/").pop()??e,l=e.includes("/")?e.slice(0,e.lastIndexOf("/")+1):"";return r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 hover:bg-white/[0.04] transition-colors group",children:[r.jsx("button",{onClick:i,className:ye("w-4 h-4 rounded border flex items-center justify-center flex-shrink-0 transition-colors",s?"bg-[#6366F1] border-[#6366F1]":"border-[#3A3A4E] hover:border-[#5A5A6E]"),children:s&&r.jsx(Fe,{className:"w-2.5 h-2.5 text-white"})}),r.jsx("span",{className:ye("text-[10px] font-mono font-bold w-4 text-center flex-shrink-0",zTe[t]),children:$Te[t]??"?"}),r.jsxs("button",{onClick:a,className:"flex-1 min-w-0 text-left",children:[r.jsx("span",{className:"text-[12px] text-[#5A5A6E] font-mono",children:l}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] font-mono",children:o})]}),n&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-[#10B981]/10 text-[#10B981] font-medium flex-shrink-0",children:"staged"})]})}function VTe({agentId:e,selectedFiles:t,onCommitted:n}){const[s,i]=y.useState(""),a=L.git.commit.useMutation({onSuccess:()=>{i(""),n()}});return r.jsxs("div",{className:"px-3 py-2 border-t border-[#2A2A35]/50 space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{value:s,onChange:o=>i(o.target.value),placeholder:"Commit message...",className:"flex-1 bg-[#1C1C21] border border-[#2A2A35] rounded-md px-2.5 py-1.5 text-[12px] text-[#C8C8D4] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1] transition-colors",onKeyDown:o=>{o.key==="Enter"&&s.trim()&&t.length>0&&a.mutate({agentId:e,message:s.trim(),files:t})}}),r.jsxs("button",{onClick:()=>a.mutate({agentId:e,message:s.trim(),files:t}),disabled:!s.trim()||t.length===0||a.isPending,className:ye("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[11px] font-medium transition-colors",s.trim()&&t.length>0?"bg-[#6366F1] text-white hover:bg-[#5558E6]":"bg-[#2A2A35] text-[#5A5A6E] cursor-not-allowed"),children:[a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(jie,{className:"w-3 h-3"}),"Commit"]})]}),t.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:[t.length," file",t.length!==1?"s":""," selected"]}),a.isError&&r.jsx("p",{className:"text-[10px] text-[#EF4444]",children:a.error.message})]})}function UTe({agentId:e,currentBranch:t}){const[n,s]=y.useState(!1),[i,a]=y.useState(!1),[o,l]=y.useState(""),{data:c=[]}=L.git.branches.useQuery({agentId:e},{enabled:n}),d=L.useUtils(),f=L.git.checkout.useMutation({onSuccess:()=>{s(!1),d.git.status.invalidate({agentId:e}),d.git.log.invalidate({agentId:e})}}),p=L.git.branch.useMutation({onSuccess:()=>{a(!1),l(""),s(!1),d.git.status.invalidate({agentId:e}),d.git.log.invalidate({agentId:e})}});return r.jsxs("div",{className:"relative",children:[r.jsxs("button",{onClick:()=>s(m=>!m),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] font-medium bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] text-[#C8C8D4] transition-colors",children:[r.jsx(Zl,{className:"w-3.5 h-3.5 text-[#6366F1]"}),r.jsx("span",{className:"truncate max-w-[140px]",children:t}),r.jsx(ft,{className:"w-3 h-3 text-[#5A5A6E]"})]}),r.jsx(Me,{children:n&&r.jsxs(ne.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:"absolute top-full left-0 mt-1 w-56 bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl z-50 overflow-hidden",children:[r.jsx("div",{className:"max-h-[200px] overflow-y-auto py-1",children:c.map(m=>r.jsxs("button",{onClick:()=>{m!==t&&f.mutate({agentId:e,branch:m})},className:ye("w-full flex items-center gap-2 px-3 py-1.5 text-[12px] text-left hover:bg-white/5 transition-colors",m===t?"text-[#6366F1]":"text-[#C8C8D4]"),children:[m===t&&r.jsx(Fe,{className:"w-3 h-3 flex-shrink-0"}),m!==t&&r.jsx("span",{className:"w-3 flex-shrink-0"}),r.jsx("span",{className:"truncate",children:m})]},m))}),r.jsx("div",{className:"border-t border-[#2A2A35] p-2",children:i?r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("input",{value:o,onChange:m=>l(m.target.value),placeholder:"branch-name",autoFocus:!0,className:"flex-1 bg-[#13131A] border border-[#2A2A35] rounded px-2 py-1 text-[11px] text-[#C8C8D4] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]",onKeyDown:m=>{m.key==="Enter"&&o.trim()&&p.mutate({agentId:e,name:o.trim()}),m.key==="Escape"&&(a(!1),l(""))}}),r.jsx("button",{onClick:()=>{o.trim()&&p.mutate({agentId:e,name:o.trim()})},disabled:!o.trim()||p.isPending,className:"text-[#10B981] hover:text-[#34D399] transition-colors",children:p.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Fe,{className:"w-3.5 h-3.5"})}),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"})})]}):r.jsxs("button",{onClick:()=>a(!0),className:"flex items-center gap-1.5 w-full px-2 py-1 text-[11px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors rounded hover:bg-white/5",children:[r.jsx(wt,{className:"w-3 h-3"}),"New branch"]})})]})})]})}function HTe({agentId:e,filePath:t,onClose:n}){const{data:s,isLoading:i}=L.git.diff.useQuery({agentId:e,filePath:t},{retry:!1});return i?r.jsxs("div",{className:"border-t border-[#2A2A35] p-4 flex items-center gap-1.5 text-[#5A5A6E]",children:[r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),r.jsx("span",{className:"text-[11px]",children:"Loading diff..."})]}):s?r.jsxs("div",{className:"border-t border-[#2A2A35] flex flex-col max-h-[50%] min-h-[120px]",children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(li,{className:"w-3.5 h-3.5 text-[#5A5A6E] flex-shrink-0"}),r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4] truncate",children:t})]}),r.jsx("button",{onClick:n,className:"text-[11px] text-[#5A5A6E] hover:text-[#C8C8D4] px-1.5 transition-colors",children:"Close"})]}),r.jsx("div",{className:"flex-1 overflow-auto min-h-0",children:r.jsx("pre",{className:"px-3 py-2 text-[11px] font-mono leading-[1.6] whitespace-pre-wrap break-all",children:s.split(`
|
|
354
|
-
`).map((a,o)=>{let l="text-[#8A8A99]";return a.startsWith("+")&&!a.startsWith("+++")?l="text-[#34D399]":a.startsWith("-")&&!a.startsWith("---")?l="text-[#F87171]":a.startsWith("@@")&&(l="text-[#6366F1]"),r.jsx("div",{className:l,children:a||" "},o)})})})]}):r.jsxs("div",{className:"border-t border-[#2A2A35] p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4]",children:t}),r.jsx("button",{onClick:n,className:"text-[11px] text-[#5A5A6E] hover:text-[#C8C8D4] transition-colors",children:"Close"})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] italic",children:"No changes to display."})]})}function WTe({agentId:e}){const[t,n]=y.useState(new Set),[s,i]=y.useState(null),a=L.useUtils(),{data:o,isLoading:l}=L.git.hasRepo.useQuery({agentId:e}),{data:c,isLoading:d}=L.git.status.useQuery({agentId:e},{enabled:!!o?.hasRepo,refetchInterval:1e4}),{data:f=[]}=L.git.log.useQuery({agentId:e,limit:10},{enabled:!!o?.hasRepo,refetchInterval:3e4}),p=y.useMemo(()=>c?[...c.staged.map(w=>({...w,category:"staged"})),...c.modified.map(w=>({...w,category:"modified"})),...c.untracked.map(w=>({...w,category:"untracked"}))]:[],[c]),m=y.useCallback(w=>{n(A=>{const S=new Set(A);return S.has(w)?S.delete(w):S.add(w),S})},[]),g=y.useCallback(()=>{n(new Set(p.map(w=>w.path)))},[p]),b=y.useCallback(()=>{n(new Set)},[]),_=y.useCallback(()=>{a.git.status.invalidate({agentId:e}),a.git.log.invalidate({agentId:e})},[a,e]);return l?r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Pe,{className:"w-5 h-5 text-[#5A5A6E] animate-spin"})}):o?.hasRepo?r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:[c&&r.jsx(UTe,{agentId:e,currentBranch:c.branch}),r.jsx("button",{onClick:_,className:"p-1.5 rounded-md text-[#5A5A6E] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors",title:"Refresh",children:r.jsx(Xi,{className:ye("w-3.5 h-3.5",d&&"animate-spin")})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[r.jsx("div",{className:"px-3 pt-2",children:r.jsx(LTe,{agentId:e})}),d&&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]"})]}),!d&&p.length===0&&f.length===0&&r.jsx("p",{className:"px-4 py-4 text-[12px] text-[#5A5A6E] italic",children:"Working tree clean. No changes."}),p.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:["Changes (",p.length,")"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:g,className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"All"}),r.jsx("button",{onClick:b,className:"text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"None"})]})]}),c?.staged&&c.staged.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#10B981] uppercase tracking-widest",children:"Staged"}),c.staged.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!0,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`staged-${w.path}`))]}),c?.modified&&c.modified.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#F59E0B] uppercase tracking-widest",children:"Modified"}),c.modified.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!1,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`modified-${w.path}`))]}),c?.untracked&&c.untracked.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:"Untracked"}),c.untracked.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!1,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`untracked-${w.path}`))]})]}),f.length>0&&r.jsxs("div",{className:"mt-2",children:[r.jsx("p",{className:"px-3 py-1.5 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest border-t border-[#2A2A35]/50",children:"Recent commits"}),f.map(w=>r.jsxs("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-white/[0.02] transition-colors",children:[r.jsx(Hse,{className:"w-2 h-2 text-[#5A5A6E] mt-1 flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] text-[#C8C8D4] truncate",children:w.message}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:[r.jsx("code",{className:"text-[#6366F1]",children:w.shortHash}),r.jsx("span",{className:"mx-1",children:"·"}),w.author,r.jsx("span",{className:"mx-1",children:"·"}),r.jsx(BTe,{date:w.date})]})]})]},w.hash))]})]}),s&&r.jsx(HTe,{agentId:e,filePath:s,onClose:()=>i(null)}),p.length>0&&r.jsx(VTe,{agentId:e,selectedFiles:[...t],onCommitted:()=>{n(new Set),_()}})]}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-5 gap-2",children:[r.jsx(Zl,{className:"w-8 h-8 text-[#3A3A45]"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic text-center",children:"No git repository detected"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] text-center",children:"Mount a project directory with a git repo in Settings → File Access."})]})}function qTe(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const s=Math.floor(n/60);if(s<60)return`${s} min ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function GTe(e){return new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function KTe(e){const t=new Date(e).getTime()-Date.now();if(t<=0)return"eligible now";const n=Math.floor(t/(3600*1e3)),s=Math.floor(t%(3600*1e3)/(60*1e3));return n>0?`~${n}h ${s}m`:`~${s}m`}function YTe({agentId:e}){const{data:t}=L.dream.status.useQuery({agentId:e},{staleTime:3e4}),n=t?.[e];return n?r.jsxs("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(_L,{className:"w-3.5 h-3.5 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5]",children:"Dream Status"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-y-1.5 text-[11px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Last dream"}),r.jsx("span",{className:"text-[#C8C8D4]",children:qTe(n.lastDreamAt)}),r.jsx("span",{className:"text-[#8A8A99]",children:"Notes changed"}),r.jsx("span",{className:"text-[#C8C8D4]",children:n.lastDreamNotesChanged}),r.jsx("span",{className:"text-[#8A8A99]",children:"Cost"}),r.jsxs("span",{className:"text-[#10B981]",children:["$",n.lastDreamCostUsd.toFixed(4)]}),r.jsx("span",{className:"text-[#8A8A99]",children:"Next eligible"}),r.jsx("span",{className:"text-[#C8C8D4]",children:KTe(n.nextDreamEstimate)})]})]}):r.jsx("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:r.jsx("p",{className:"text-[12px] text-[#5A5A6E] italic",children:"No dream data yet. Trigger a dream to start memory consolidation."})})}function QTe({preferences:e}){return e.length===0?null:r.jsxs("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#F0F0F5] mb-2",children:"Routing Preferences"}),r.jsx("div",{className:"space-y-2",children:e.map((t,n)=>r.jsxs("div",{className:"flex items-start gap-2 text-[11px]",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[#C8C8D4]",children:t.taskPattern}),r.jsxs("p",{className:"text-[#5A5A6E] mt-0.5",children:["→ ",t.preferredAgentId," — ",t.reason]})]}),r.jsxs("span",{className:`flex-shrink-0 px-1.5 py-0.5 rounded text-[10px] font-medium ${t.confidence>=.8?"bg-[#10B981]/15 text-[#10B981]":t.confidence>=.5?"bg-[#F59E0B]/15 text-[#F59E0B]":"bg-[#EF4444]/15 text-[#EF4444]"}`,children:[(t.confidence*100).toFixed(0),"%"]})]},n))})]})}function XTe({entries:e}){return e.length===0?r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4 text-center italic",children:"No dream history."}):r.jsxs("div",{className:"relative",children:[e.length>0&&r.jsx("div",{className:"absolute left-[9px] top-0 bottom-0 w-px bg-[#2A2A35]"}),r.jsx("div",{className:"space-y-0",children:e.map(t=>r.jsxs("div",{className:"flex gap-3 py-2.5 relative",children:[r.jsx("div",{className:"w-5 h-5 rounded-full bg-[#1C1C24] border border-[#2A2A35] flex items-center justify-center text-[10px] flex-shrink-0 z-10 mt-0.5",children:"💤"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("p",{className:"text-[12px] text-[#C8C8D4] leading-snug",children:["+",t.notesAdded," added · ",t.notesMerged," merged · ",t.notesPruned," pruned",t.constraintsFlagged.length>0&&r.jsxs("span",{className:"text-[#F59E0B]",children:[" · ",t.constraintsFlagged.length," flagged"]})]}),t.constraintsFlagged.length>0&&r.jsx("div",{className:"mt-1 space-y-0.5",children:t.constraintsFlagged.map((n,s)=>r.jsxs("p",{className:"text-[10px] text-[#F59E0B]/80",children:["⚠ ",n]},s))}),t.agentHealthNotes&&t.agentHealthNotes.length>0&&r.jsx("div",{className:"mt-1 space-y-0.5",children:t.agentHealthNotes.map((n,s)=>r.jsxs("p",{className:"text-[10px] text-[#8A8A99]",children:[n.agentId,": ",n.observation]},s))}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:[GTe(t.ts),t.durationMs!=null&&` · ${Math.round(t.durationMs/1e3)}s`,t.costEstimateUsd>0&&` · $${t.costEstimateUsd.toFixed(4)}`]})]})]},t.id))})]})}function JTe({agentId:e}){const[t,n]=y.useState(!1),{data:s=[],isLoading:i}=L.dream.history.useQuery({agentId:e,limit:20},{refetchInterval:3e4}),a=L.useUtils(),o=y.useRef(0);o.current=s.length;const l=L.dream.trigger.useMutation({onSuccess:f=>{if(!f.started){n(!1);return}const p=o.current,m=setInterval(async()=>{await a.dream.history.invalidate({agentId:e}),await a.dream.status.invalidate({agentId:e});const g=a.dream.history.getData({agentId:e,limit:20});g&&g.length>p&&(clearInterval(m),n(!1))},4e3);setTimeout(()=>{clearInterval(m),n(!1)},12e4)},onError:()=>n(!1)}),c=e==="coo",d=c?s.find(f=>f.routingPreferences&&f.routingPreferences.length>0)?.routingPreferences??[]:[];return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[r.jsx(YTe,{agentId:e}),c&&d.length>0&&r.jsx(QTe,{preferences:d}),r.jsxs("div",{className:"px-4 mt-3 flex-shrink-0",children:[r.jsxs("button",{onClick:()=>{n(!0),l.mutate({agentId:e})},disabled:t||l.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#6366F1] text-white hover:bg-[#5558E6] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[t||l.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(_L,{className:"w-3 h-3"}),t?"Dreaming...":"Trigger Dream"]}),l.data&&!l.data.started&&r.jsx("p",{className:"text-[10px] text-[#F59E0B] mt-1",children:l.data.reason})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-4 mt-3",children:[i&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4 text-center",children:"Loading..."}),!i&&r.jsx(XTe,{entries:s})]})]})}const ZTe=["complexity:low","complexity:medium","complexity:high","task:code","task:creative","task:analysis","task:tool_use"];function Gb({value:e,onChange:t,customModels:n=[],agentId:s}){const[i,a]=y.useState(""),o=L.useUtils(),l=L.agents.addCustomModel.useMutation({onSuccess:()=>o.agents.list.invalidate()}),c=L.agents.removeCustomModel.useMutation({onSuccess:()=>o.agents.list.invalidate()}),{groups:d}=Vm(),f=Up(e);return r.jsxs(ss,{value:e,onValueChange:t,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors min-w-[140px]",children:[r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[f]}`,children:f}),r.jsx(Ds,{children:ta(e)}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] max-h-[280px] overflow-y-auto z-[9999]",children:[s&&r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:i,onChange:a,onSubmit:p=>{s&&(l.mutate({agentId:s,modelId:p}),t(p),a(""))},placeholder:"Type model ID..."})}),r.jsxs(os,{children:[d.map(p=>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:p.label}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo[p.tag]}`,children:p.tag})]}),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 hover:bg-white/5 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)),n.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"})]}),n.map(p=>r.jsxs(vn,{value:p,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}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})}),s&&r.jsx(bt,{label:"Remove model",children:r.jsx("button",{onClick:m=>{m.stopPropagation(),c.mutate({agentId:s,modelId:p})},className:"text-[#5A5A6E] hover:text-[#F87171] transition-colors",children:r.jsx(Te,{className:"w-3 h-3"})})})]})]},p))]})]})]})})]})}function eMe({value:e,onChange:t}){return r.jsxs(ss,{value:e,onValueChange:t,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors min-w-[150px]",children:[r.jsx(Ds,{children:e}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),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-[170px] z-[9999]",children:r.jsx(os,{children:ZTe.map(n=>r.jsxs(vn,{value:n,className:"flex items-center justify-between px-3 py-2 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:n}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},n))})})})]})}function tMe(e,t){if(t.length===0)return`Always uses ${ta(e)}.`;const n=t.map(s=>`For ${s.condition} → ${ta(s.model)}`);return n.push(`For everything else → ${ta(e)}`),n.join(". ")+"."}function nMe({fallbacks:e,onAdd:t,onRemove:n,customModels:s,agentId:i}){const[a,o]=y.useState(!1),[l,c]=y.useState("");function d(){l&&(t(l),c(""),o(!1))}return r.jsxs("div",{className:"space-y-2",children:[e.map((f,p)=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-[11px] text-[#5A5A6E] w-4 flex-shrink-0",children:[p+1,"."]}),r.jsx("span",{className:"flex-1 text-[12px] text-[#C8C8D4] truncate",children:ta(f)}),r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[Up(f)]}`,children:Up(f)}),r.jsx("button",{onClick:()=>n(p),className:"w-5 h-5 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Te,{className:"w-3 h-3"})})]},p)),a?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Gb,{value:l||"qwen3:14b",onChange:c,customModels:s,agentId:i}),r.jsx("button",{onClick:d,className:"text-[11px] text-[#10B981] hover:text-[#34D399] font-medium transition-colors",children:"Add"}),r.jsx("button",{onClick:()=>o(!1),className:"text-[11px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Cancel"})]}):r.jsxs("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add fallback"]})]})}const sMe=[{id:"__default__",label:"Workspace default"},{id:"openclaw",label:"OpenClaw"},{id:"anthropic",label:"Anthropic"},{id:"claude-code",label:"Claude Code"},{id:"ollama",label:"Ollama"},{id:"openrouter",label:"OpenRouter"}];function iMe({agentId:e}){const{data:t}=L.agents.getGateway.useQuery({agentId:e}),n=L.useUtils(),s=L.agents.setGateway.useMutation({onSuccess:()=>n.agents.getGateway.invalidate({agentId:e})}),i=t?.gatewayId||"__default__";return r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Runtime"}),r.jsxs(ss,{value:i,onValueChange:a=>s.mutate({agentId:e,gatewayId:a==="__default__"?null:a}),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] hover:bg-[#2A2A35] transition-colors",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:sMe.map(a=>r.jsxs(vn,{value:a.id,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:a.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"})})]},a.id))})})})]})]})}function rMe({agent:e,agentColor:t}){const{data:n}=L.onboarding.getState.useQuery(void 0,{staleTime:3e4,refetchOnWindowFocus:!1}),s=(()=>{try{return e.customModels?JSON.parse(e.customModels):[]}catch{return[]}})(),i=s[0]??null,a=n?.defaultReasoningModel??i??"qwen3:14b",o=!e.defaultModel&&!n?.defaultReasoningModel,[l,c]=y.useState(e.defaultModel??a),[d,f]=y.useState(()=>{try{return e.modelRules?JSON.parse(e.modelRules):[]}catch{return[]}}),p=s,[m,g]=y.useState("idle"),b=y.useRef(null),_=L.useUtils(),w=L.agents.setModelConfig.useMutation({onSuccess:()=>{_.agents.list.invalidate(),_.agents.getFallbackModels.invalidate({agentId:e.id})}}),A=e.gatewayId??n?.gatewayType??"openclaw",S=A==="openclaw"||A==="openrouter",{data:C}=L.agents.getFallbackModels.useQuery({agentId:e.id},{enabled:S}),[E,k]=y.useState(null),T=E??C?.agent??[],F=C?.defaults??[],M=T.length===0&&F.length>0,[I,R]=y.useState(e.fallbackModel??null);y.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const H=[{label:"Local",description:"Free · Fully offline",defaultModel:"qwen3:14b",rules:[{condition:"task:tool_use",model:"tomng/nanbeige4.1"}]},{label:"Hybrid",description:"Smart routing · Best bang for buck",defaultModel:"qwen3:14b",rules:[{condition:"task:tool_use",model:"tomng/nanbeige4.1"},{condition:"task:code",model:"claude-sonnet-4.6"},{condition:"complexity:high",model:"claude-opus-4.6"}]}];function V(W){c(W.defaultModel),f(W.rules)}function K(){f(W=>[...W,{condition:"complexity:high",model:"claude-sonnet-4.6"}])}function q(W){f(O=>O.filter((D,Q)=>Q!==W))}function $(W,O){f(D=>D.map((Q,z)=>z===W?{...Q,...O}:Q))}function B(W){k([...T,W])}function Y(W){k(T.filter((O,D)=>D!==W))}async function U(){g("saving"),await w.mutateAsync({agentId:e.id,defaultModel:l,modelRules:d,customModels:p,...S?{fallbackModels:E??void 0}:{fallbackModel:I}}),g("saved"),k(null),b.current=setTimeout(()=>g("idle"),2e3)}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-4 overflow-y-auto",children:[o&&r.jsx("div",{className:"flex items-start gap-2 px-3 py-2.5 rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20",children:r.jsx("span",{className:"text-[#F59E0B] text-[13px] leading-snug",children:"No model configured. Visit Settings → Models to set one."})}),r.jsx(iMe,{agentId:e.id}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Default Model"}),r.jsx(Gb,{value:l,onChange:c,customModels:p,agentId:e.id})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Presets"}),r.jsx("div",{className:"flex gap-2",children:H.map(W=>r.jsxs("button",{onClick:()=>V(W),className:"flex-1 rounded-lg border border-[#2A2A35] bg-[#1C1C21] hover:bg-[#2A2A35] transition-colors px-3 py-2 text-left",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#F0F0F5]",children:W.label}),r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:W.description})]},W.label))})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Routing Rules"}),r.jsx("div",{className:"space-y-2",children:d.map((W,O)=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(eMe,{value:W.condition,onChange:D=>$(O,{condition:D})}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E] flex-shrink-0",children:"→"}),r.jsx(Gb,{value:W.model,onChange:D=>$(O,{model:D}),customModels:p,agentId:e.id}),r.jsx(bt,{label:"Remove rule",children:r.jsx("button",{onClick:()=>q(O),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]},O))}),r.jsxs("button",{onClick:K,className:"mt-3 flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add rule"]})]}),S?r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Fallback Models"})]}),M&&T.length===0&&r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] mb-2",children:["Inheriting from defaults: ",F.map(ta).join(", ")]}),r.jsx(nMe,{fallbacks:T,onAdd:B,onRemove:Y,customModels:p,agentId:e.id}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-2",children:["Handled natively by ",A==="openclaw"?"OpenClaw":"OpenRouter","."]})]}):r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Fallback Model"})]}),I?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Gb,{value:I,onChange:W=>R(W),customModels:p,agentId:e.id}),r.jsx(bt,{label:"Remove fallback",children:r.jsx("button",{onClick:()=>R(null),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})})]}):r.jsxs("button",{onClick:()=>R(l),className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add fallback"]}),r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-2",children:"Used when the primary model is rate-limited or unavailable."})]}),r.jsx("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] px-3 py-2.5",children:r.jsx("p",{className:"text-[11px] text-[#8A8A99] italic leading-relaxed",children:tMe(l,d)})}),r.jsx("button",{onClick:U,disabled:w.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium transition-colors disabled:opacity-50",style:{backgroundColor:t,color:"#fff"},children:r.jsxs(Me,{mode:"wait",children:[m==="saving"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saving..."},"saving"),m==="saved"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved ✓"},"saved"),m==="idle"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")]})})]})}const aMe={"Be brief":"Keep all responses under 3 sentences. Be direct.","Be creative":"Be imaginative, use analogies, think laterally.","Be strict":"Only respond with facts. No speculation. Cite reasoning."};function mW(e,t=500){const[n,s]=y.useState("idle"),i=y.useRef(null),a=y.useRef(null);y.useEffect(()=>()=>{i.current&&clearTimeout(i.current),a.current&&clearTimeout(a.current)},[]);const o=y.useCallback(l=>{l!==void 0&&(i.current&&clearTimeout(i.current),a.current&&clearTimeout(a.current),s("saving"),i.current=setTimeout(async()=>{await e(l),s("saved"),a.current=setTimeout(()=>s("idle"),2e3)},t))},[e,t]);return{saveState:n,handleChange:o}}function xW({saveState:e}){return r.jsxs(Me,{mode:"wait",children:[e==="saving"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[11px] text-[#8A8A99]",children:"Saving..."},"saving"),e==="saved"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[11px] text-[#10B981]",children:"Saved ✓"},"saved")]})}const Q8={gateway:{label:"Gateway",color:"#3B82F6"},harness:{label:"Claude Code",color:"#8B5CF6"},terminal:{label:"Terminal",color:"#10B981"}};function oMe({agentId:e}){const{data:t}=L.events.activeRuntimes.useQuery({agentId:e},{staleTime:3e4,refetchInterval:3e4});return!t||t.length===0?null:r.jsx("div",{className:"flex items-center gap-1 ml-1",children:t.map(n=>{const s=Q8[n.source]??Q8.gateway,a=`Last active ${lMe(n.lastActiveAt)}${n.project?` via ${s.label} on ${n.project}`:` via ${s.label}`}`;return r.jsx(bt,{label:a,side:"bottom",children:r.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:s.color}})},n.source)})})}function lMe(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const s=Math.floor(n/60);if(s<60)return`${s} min ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function cMe({status:e,color:t}){const n=e==="thinking"||e==="executing";return r.jsxs("span",{className:"relative flex items-center justify-center w-2 h-2",children:[n&&r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:t,opacity:.5},animate:{scale:[1,2.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}})]})}function uMe({agentId:e}){const{data:t}=L.agents.getSoul.useQuery({agentId:e}),n=L.agents.saveSoul.useMutation(),{saveState:s,handleChange:i}=mW(y.useCallback(a=>n.mutateAsync({agentId:e,content:a}),[e,n]));return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-visible",children:[r.jsx("div",{className:"flex items-center justify-end h-7 px-3 flex-shrink-0",children:r.jsx(xW,{saveState:s})}),r.jsx("div",{className:"flex-1 min-h-0",children:t?.content!==void 0&&r.jsx(VU,{height:"100%",defaultLanguage:"markdown",defaultValue:t.content??"",theme:"vs-dark",onChange:i,options:{minimap:{enabled:!1},wordWrap:"on",lineNumbers:"off",fontSize:13,scrollBeyondLastLine:!1,padding:{top:8,bottom:16},automaticLayout:!0,fixedOverflowWidgets:!0}})})]})}function dMe({agentId:e}){const{data:t}=L.agents.getTeam.useQuery({agentId:e}),n=L.agents.saveTeam.useMutation(),{saveState:s,handleChange:i}=mW(y.useCallback(a=>n.mutateAsync({agentId:e,content:a}),[e,n]));return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-visible",children:[r.jsx("div",{className:"flex items-center justify-end h-7 px-3 flex-shrink-0",children:r.jsx(xW,{saveState:s})}),r.jsx("div",{className:"flex-1 min-h-0",children:t?.content!==void 0&&r.jsx(VU,{height:"100%",defaultLanguage:"markdown",defaultValue:t.content??"",theme:"vs-dark",onChange:i,options:{minimap:{enabled:!1},wordWrap:"on",lineNumbers:"off",fontSize:13,scrollBeyondLastLine:!1,padding:{top:8,bottom:16},automaticLayout:!0,fixedOverflowWidgets:!0}})})]})}const hMe={healthy:"#10B981",degraded:"#F59E0B",failing:"#EF4444"};function fMe({health:e,detail:t}){const[n,s]=y.useState(!1),i=hMe[e.health]??"#5A5A6E";return r.jsxs("span",{className:"relative",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[r.jsx("span",{className:"inline-block w-2 h-2 rounded-full",style:{backgroundColor:i}}),n&&r.jsx("span",{className:"absolute top-full left-0 mt-1.5 px-2 py-1 rounded bg-[#1C1C24] border border-[#2A2A35] text-[10px] text-[#C8C8D4] whitespace-nowrap z-50 shadow-lg",children:t})]})}function pMe({agentId:e}){const{data:t=[]}=L.skills.getAgentSkills.useQuery({agentId:e}),{data:n={}}=L.events.skillHealth.useQuery({agentId:e},{refetchInterval:3e4}),{data:s={}}=L.events.skillComposition.useQuery({agentId:e},{refetchInterval:6e4}),i=L.useUtils(),a=L.skills.toggleAgentSkill.useMutation({onMutate:async({agentId:d,skillId:f,enabled:p})=>{await i.skills.getAgentSkills.cancel({agentId:d});const m=i.skills.getAgentSkills.getData({agentId:d});return i.skills.getAgentSkills.setData({agentId:d},g=>g&&g.map(b=>b.skillId===f?{...b,enabled:p}:b)),{prev:m}},onError:(d,{agentId:f},p)=>{p?.prev&&i.skills.getAgentSkills.setData({agentId:f},p.prev)}});if(t.length===0)return r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-5 gap-2",children:[r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No skills installed for this agent."}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"Go to Skills to install and assign."})]});const o=t.every(d=>d.enabled);function l(){const d=!o;t.forEach(f=>a.mutate({agentId:e,skillId:f.skillId,enabled:d}))}const c=new Map(t.map(d=>[d.skill.slug,d.skill.name]));return r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:[t.length," skill",t.length!==1?"s":""]}),r.jsx("button",{onClick:l,className:"text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:o?"Disable all":"Enable all"})]}),t.map(d=>{const f=n[d.skill.id]??n[d.skill.slug]??n[d.skill.name],p=s[d.skill.id]??s[d.skill.slug]??s[d.skill.name],m=f?`${f.successCount}/${f.totalCount} succeeded${f.avgDurationMs!=null?` · avg ${f.avgDurationMs}ms`:""}`:void 0;return r.jsxs("div",{className:"py-2.5 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[f&&r.jsx(fMe,{health:f,detail:m}),r.jsx("span",{className:"text-[13px] transition-all",style:{color:d.enabled?"#C8C8D4":"#5A5A6E",textDecoration:d.enabled?"none":"line-through"},children:d.skill.name})]}),r.jsx(Sh,{checked:d.enabled,onCheckedChange:g=>a.mutate({agentId:e,skillId:d.skillId,enabled:g}),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]",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"})})]}),p&&p.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-1 ml-4",children:["Used together with ",p.map(g=>c.get(g)??g).join(", ")]})]},d.skillId)})]})}function mMe({agentId:e,onOverrideSet:t,onClose:n}){const{data:s}=L.agents.getOverride.useQuery({agentId:e}),i=L.agents.setOverride.useMutation(),[a,o]=y.useState("");y.useEffect(()=>{s?.override!==void 0&&o(s.override??"")},[s?.override]);async function l(){await i.mutateAsync({agentId:e,instruction:a}),t(a.trim()||null),n()}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-3",children:[r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[Object.entries(aMe).map(([c,d])=>r.jsx("button",{onClick:()=>o(d),className:"px-3 py-1 rounded-md text-[12px] bg-white/5 text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-[#2A2A35] hover:border-[#3A3A45]",children:c},c)),r.jsx("button",{onClick:()=>o(""),className:"px-3 py-1 rounded-md text-[12px] bg-white/5 text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-[#2A2A35] hover:border-[#3A3A45]",children:"Clear"})]}),r.jsx("textarea",{value:a,onChange:c=>o(c.target.value),rows:5,placeholder:"Add a temporary instruction for this session...",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2.5 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] resize-none outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("button",{onClick:l,disabled:i.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:"Set Override"})]})}const xMe=[{value:"15m",label:"Every 15 minutes"},{value:"30m",label:"Every 30 minutes"},{value:"1h",label:"Every hour"},{value:"3h",label:"Every 3 hours"},{value:"6h",label:"Every 6 hours"},{value:"12h",label:"Every 12 hours"},{value:"1d",label:"Daily"},{value:"2d",label:"Every 2 days"},{value:"7d",label:"Weekly"},{value:"custom",label:"Custom…"}];function gMe(e){return!e||e==="24h"?"1d@09:00":e==="48h"?"2d@09:00":e}function bMe(e){const t={preset:"1d",customValue:4,customUnit:"h",utcHour:9,utcMinute:0};if(e==="15m")return{...t,preset:"15m"};if(e==="30m")return{...t,preset:"30m"};const n=e.match(/^(\d+)h$/);if(n){const i=parseInt(n[1],10),a={1:"1h",3:"3h",6:"6h",12:"12h"};return a[i]?{...t,preset:a[i]}:{...t,preset:"custom",customValue:i,customUnit:"h"}}const s=e.match(/^(\d+)d@(\d{1,2}):(\d{2})$/);if(s){const i=parseInt(s[1],10),a=parseInt(s[2],10),o=parseInt(s[3],10);return{preset:{1:"1d",2:"2d",7:"7d"}[i]??"custom",customValue:i,customUnit:"d",utcHour:a,utcMinute:o}}return t}function vMe(e){return e.preset==="15m"||e.preset==="30m"||e.preset==="1h"||e.preset==="3h"||e.preset==="6h"||e.preset==="12h"?e.preset:e.preset==="1d"?`1d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="2d"?`2d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="7d"?`7d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="custom"?e.customUnit==="d"?`${e.customValue}d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:`${e.customValue}${e.customUnit}`:"1d@09:00"}function yMe(e,t){return e==="1d"||e==="2d"||e==="7d"||e==="custom"&&t==="d"}function gW(e,t){const n=new Date;return n.setUTCHours(e,t,0,0),{hour:n.getHours(),minute:n.getMinutes()}}function _Me(e,t){const n=new Date;return n.setHours(e,t,0,0),{hour:n.getUTCHours(),minute:n.getUTCMinutes()}}function wMe(e){if(e.preset==="custom"){if(e.customUnit==="m")return`Runs every ${e.customValue} minute${e.customValue===1?"":"s"}`;if(e.customUnit==="h")return`Runs every ${e.customValue} hour${e.customValue===1?"":"s"}`;const t=gW(e.utcHour,e.utcMinute);return`Runs every ${e.customValue} day${e.customValue===1?"":"s"} at ${String(t.hour).padStart(2,"0")}:${String(t.minute).padStart(2,"0")} local`}return""}function AMe({agentId:e}){const{data:t,refetch:n,isLoading:s}=L.agents.terminalInsights.useQuery({agentId:e}),i=L.agents.compactTerminalKnowledge.useMutation({onSuccess:()=>n()}),a=L.agents.clearTerminalKnowledge.useMutation({onSuccess:()=>n()}),o=t?.content??"";return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-4 overflow-auto",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Terminal Insights"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>i.mutate({agentId:e}),disabled:i.isPending,className:"px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:i.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):"Compact now"}),o&&r.jsx("button",{onClick:()=>a.mutate({agentId:e}),disabled:a.isPending,className:"px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#2A2A35] hover:bg-[#3A3A4E] text-[#C8C8D4] transition-colors disabled:opacity-50",children:a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):"Clear"})]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:"Terminal session summaries are stored in daily memory files. Compacting extracts lasting patterns into KNOWLEDGE.md."}),s?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Pe,{className:"w-5 h-5 animate-spin text-[#5A5A6E]"})}):o?r.jsx("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-lg p-4 text-[12px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap font-mono",children:o}):r.jsx("div",{className:"text-center py-8 text-[12px] text-[#5A5A6E]",children:"No terminal insights yet. Assign an agent to a terminal, run some commands, then compact."})]})}function SMe({agentId:e}){const{data:t}=L.agents.getHeartbeat.useQuery({agentId:e}),n=L.agents.setHeartbeat.useMutation(),[s,i]=y.useState(!1),[a,o]=y.useState("1d"),[l,c]=y.useState(4),[d,f]=y.useState("h"),[p,m]=y.useState(9),[g,b]=y.useState(0),[_,w]=y.useState("idle"),[A,S]=y.useState(null),C=y.useRef(null);y.useEffect(()=>{if(t){i(t.enabled);const I=bMe(gMe(t.every));o(I.preset),c(I.customValue),f(I.customUnit);const R=gW(I.utcHour,I.utcMinute);m(R.hour),b(R.minute)}},[t]),y.useEffect(()=>()=>{C.current&&clearTimeout(C.current)},[]);const E=yMe(a,d),k=y.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"local"}},[]),T=y.useMemo(()=>{const I=_Me(p,g),R={preset:a,customValue:l,customUnit:d,utcHour:I.hour,utcMinute:I.minute};return{every:vMe(R),description:wMe(R)}},[a,l,d,p,g]);async function F(){S(null);try{await n.mutateAsync({agentId:e,enabled:s,every:T.every}),w("saved"),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>w("idle"),2e3)}catch(I){w("error"),S(I instanceof Error?I.message:"Failed to save")}}const M=a!=="custom"||(d==="m"?l>=1&&l<=59:d==="h"?l>=1&&l<=23:l>=1&&l<=7);return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[13px] text-[#F0F0F5]",children:"Heartbeat"}),r.jsx(Sh,{checked:s,onCheckedChange:i,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]",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"})})]}),s&&r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Frequency"}),r.jsxs(ss,{value:a,onValueChange:I=>o(I),children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors w-full",children:[r.jsx(Ds,{}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),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-[200px] max-h-[280px] overflow-y-auto z-[9999]",children:r.jsx(os,{children:xMe.map(I=>r.jsxs(vn,{value:I.value,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:I.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},I.value))})})})]})]}),a==="custom"&&r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Every"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:1,max:d==="m"?59:d==="h"?23:7,value:l,onChange:I=>c(Math.max(1,parseInt(I.target.value||"1",10))),className:"w-20 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors"}),r.jsxs(ss,{value:d,onValueChange:I=>f(I),children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors flex-1",children:[r.jsx(Ds,{}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),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-[140px] z-[9999]",children:r.jsx(os,{children:[{v:"m",label:"minutes"},{v:"h",label:"hours"},{v:"d",label:"days"}].map(I=>r.jsxs(vn,{value:I.v,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:I.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},I.v))})})})]})]}),!M&&r.jsx("p",{className:"text-[11px] text-[#F25757]",children:d==="m"?"Minutes must be 1–59":d==="h"?"Hours must be 1–23":"Days must be 1–7"})]}),E&&r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Time of day"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:0,max:23,value:p,onChange:I=>m(Math.max(0,Math.min(23,parseInt(I.target.value||"0",10)))),className:"w-16 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors text-center"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6E]",children:":"}),r.jsx("input",{type:"number",min:0,max:59,value:g,onChange:I=>b(Math.max(0,Math.min(59,parseInt(I.target.value||"0",10)))),className:"w-16 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors text-center"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:k})]})]})]}),r.jsxs("p",{className:"text-[12px] text-[#5A5A6E] leading-relaxed",children:["When active, your agent runs its HEARTBEAT.md at this interval — reviewing memory, running research loops, and evolving over time.",E&&r.jsxs(r.Fragment,{children:[r.jsx("br",{}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"Note: time is stored in UTC. Daylight saving changes may shift local display by ±1 hour."})]})]}),A&&_==="error"&&r.jsx("p",{className:"text-[11px] text-[#F25757]",children:A}),r.jsx("button",{onClick:F,disabled:n.isPending||s&&!M,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:r.jsx(Me,{mode:"wait",children:_==="saved"?r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved ✓"},"saved"):r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")})})]})}function CMe({agentId:e}){const t=L.agents.getTrust.useQuery({agentId:e}),n=L.agents.getSandboxOverride.useQuery({agentId:e}),s=L.agents.getMounts.useQuery({agentId:e}),i=L.agents.setAutoApprove.useMutation({onSuccess:()=>t.refetch()}),a=L.agents.setShellAllowlist.useMutation({onSuccess:()=>t.refetch()}),o=L.agents.setSandboxOverride.useMutation({onSuccess:()=>n.refetch()}),l=L.agents.addMount.useMutation({onSuccess:()=>s.refetch()}),c=L.agents.removeMount.useMutation({onSuccess:()=>s.refetch()}),[d,f]=y.useState(!1),[p,m]=y.useState(!1),[g,b]=y.useState(""),[_,w]=y.useState(!1),[A,S]=y.useState(""),[C,E]=y.useState(""),T=L.agents.getRunMode.useQuery().data?.mode==="docker";y.useEffect(()=>{t.data&&(b(t.data.shellAllowlist?t.data.shellAllowlist.join(", "):""),w(!1))},[t.data]);const F=t.data?.autoApprove??!1;function M(B){B?(f(!0),m(!0)):i.mutate({agentId:e,enabled:!1})}function I(){i.mutate({agentId:e,enabled:!0}),m(!1),f(!1)}function R(){m(!1),f(!1)}function H(B){b(B),w(!0)}function V(){const B=g.trim(),Y=B?B.split(",").map(U=>U.trim()).filter(Boolean):null;a.mutate({agentId:e,allowlist:Y}),w(!1)}function K(B){B.preventDefault(),!(!A.trim()||!C.trim())&&(l.mutate({agentId:e,hostPath:A.trim(),agentPath:C.trim()}),S(""),E(""))}const q=n.data?.mode??"inherit",$=n.data?.globalDefault??"non-main";return r.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-6",children:[r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Auto-approve"}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:"Skip confirmation prompts"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Execute all actions without asking"})]}),r.jsx(Sh,{checked:d||F,onCheckedChange:M,disabled:i.isPending,className:"w-9 h-5 rounded-full bg-[#2A2A35] data-[state=checked]:bg-[#EF4444] transition-colors outline-none cursor-pointer",children:r.jsx(Ch,{className:"block w-4 h-4 bg-white rounded-full shadow transition-transform translate-x-0.5 data-[state=checked]:translate-x-[18px]"})})]}),r.jsx(Me,{children:p&&r.jsxs(ne.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:"rounded-lg border border-[#EF4444]/40 bg-[#EF4444]/10 p-3 space-y-3",children:[r.jsx("p",{className:"text-[12px] text-[#FCA5A5] leading-relaxed",children:"This agent will execute all actions without asking for confirmation. Only enable for read-only agents or dedicated machines you fully control."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:I,className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#EF4444] hover:bg-[#DC2626] text-white transition-colors",children:"Enable anyway"}),r.jsx("button",{onClick:R,className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]})})]}),r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Sandbox"}),r.jsx("div",{className:"flex gap-1.5",children:["inherit","on","off"].map(B=>r.jsx("button",{onClick:()=>o.mutate({agentId:e,mode:B}),disabled:o.isPending,className:`flex-1 py-1.5 rounded-md text-[12px] font-medium transition-colors ${q===B?"bg-[#6366F1] text-white":"bg-[#1C1C21] border border-[#2A2A35] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45]"}`,children:B==="inherit"?`Inherit (${$==="non-main"?"sandboxed":"off"})`:B==="on"?"Sandboxed":"Unsandboxed"},B))})]}),r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Shell allowlist"}),r.jsx("input",{type:"text",value:g,onChange:B=>H(B.target.value),placeholder:"All commands allowed",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Comma-separated command names, e.g. git, npm, ls"}),_&&r.jsx("button",{onClick:V,disabled:a.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:"Save allowlist"})]}),T&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Filesystem mounts"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Mounting a directory gives this agent read/write access to those files."}),s.data&&s.data.length>0&&r.jsx("div",{className:"space-y-1.5",children:s.data.map(B=>r.jsxs("div",{className:"flex items-center gap-2 bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] truncate",children:B.hostPath}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:["→ ",B.agentPath]})]}),r.jsx("button",{onClick:()=>c.mutate({mountId:B.id}),disabled:c.isPending,className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})]},B.id))}),r.jsxs("form",{onSubmit:K,className:"space-y-2",children:[r.jsx("input",{type:"text",value:A,onChange:B=>S(B.target.value),placeholder:"Host path (e.g. /Users/you/projects)",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("input",{type:"text",value:C,onChange:B=>E(B.target.value),placeholder:"Agent path (e.g. /workspace/projects)",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsxs("button",{type:"submit",disabled:l.isPending||!A.trim()||!C.trim(),className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add mount"]})]})]})]})]})}function OC({className:e}){return r.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",className:e,children:r.jsx("path",{d:"M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"})})}const jMe=[{id:"telegram",label:"Telegram",icon:OC,available:!0},{id:"whatsapp",label:"WhatsApp",icon:Ji,available:!1},{id:"discord",label:"Discord",icon:Ji,available:!1},{id:"slack",label:"Slack",icon:Ji,available:!1}];function NMe({externalChannelId:e,botUsername:t}){const{data:n=[],refetch:s}=L.externalChannels.listPairings.useQuery({externalChannelId:e}),{data:i=[]}=L.workspace.listMembers.useQuery(),a=L.externalChannels.generatePairingCode.useMutation({onSuccess:()=>s()}),o=L.externalChannels.generatePairingCodeForUser.useMutation({onSuccess:()=>s()}),l=L.externalChannels.revokePairing.useMutation({onSuccess:()=>s()}),[c,d]=y.useState(!1),[f,p]=y.useState(""),[m,g]=y.useState(null),[b,_]=y.useState(null),[w,A]=y.useState(!1),S=new Set(n.map(F=>F.userId)),C=i.filter(F=>!S.has(F.userId));async function E(){g(null);try{const F=await a.mutateAsync({externalChannelId:e});g(F.code),d(!0)}catch{}}async function k(){if(f){g(null);try{const F=await o.mutateAsync({externalChannelId:e,userId:f});g(F.code)}catch{}}}function T(){m&&(navigator.clipboard.writeText(m).catch(()=>{}),A(!0),setTimeout(()=>A(!1),2e3))}return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Paired Users"}),r.jsxs("div",{className:"flex gap-1.5",children:[r.jsx("button",{onClick:E,disabled:a.isPending,className:"px-2 py-1 rounded text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] hover:bg-[#6366F1]/20 transition-colors",children:"Pair your Telegram"}),r.jsxs("button",{onClick:()=>{d(!0),g(null),p("")},className:"px-2 py-1 rounded text-[11px] font-medium bg-[#2A2A35] text-[#F0F0F5] hover:bg-[#3A3A45] transition-colors",children:[r.jsx(wt,{className:"w-3 h-3 inline -mt-px"})," Pair user"]})]})]}),n.length===0&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"No users paired yet. Pair your Telegram account to enable secure multi-user access."}),n.map(F=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded-md bg-[#13131A]",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[12px] text-[#F0F0F5]",children:F.userName}),F.telegramUsername&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E] ml-1.5",children:["@",F.telegramUsername]}),r.jsx("span",{className:"text-[10px] text-[#3A3A45] ml-1.5",children:new Date(F.pairedAt).toLocaleDateString()})]}),b===F.id?r.jsxs("div",{className:"flex gap-1",children:[r.jsx("button",{onClick:()=>{l.mutate({pairingId:F.id}),_(null)},className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#EF4444] text-white",children:"Revoke"}),r.jsx("button",{onClick:()=>_(null),className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#2A2A35] text-[#F0F0F5]",children:"Cancel"})]}):r.jsx("button",{onClick:()=>_(F.id),className:"text-[10px] text-[#5A5A6E] hover:text-[#EF4444] transition-colors",children:r.jsx(Dn,{className:"w-3 h-3"})})]},F.id)),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:"rounded-lg border border-[#2A2A35] bg-[#13131A] p-3 space-y-3 overflow-hidden",children:m?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium",children:"Pairing code"}),r.jsx("div",{onClick:T,className:"flex items-center justify-center gap-2 py-3 rounded-lg bg-[#1C1C21] border border-[#2A2A35] cursor-pointer hover:border-[#6366F1] transition-colors",children:r.jsx("span",{className:"text-2xl font-mono font-bold tracking-[0.25em] text-[#F0F0F5]",children:m})}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:[w?"Copied!":"Click to copy."," Send this to the user. They should message it to"," ",t?`@${t}`:"the bot"," on Telegram. Expires in 10 minutes."]}),r.jsx("button",{onClick:()=>{d(!1),g(null),s()},className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Done"})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium",children:"Pair a workspace member"}),C.length>0?r.jsxs(r.Fragment,{children:[r.jsxs(ss,{value:f,onValueChange:p,children:[r.jsxs(is,{className:"w-full flex items-center justify-between bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[12px] text-[#F0F0F5] outline-none",children:[r.jsx(Ds,{placeholder:"Select member"}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3 h-3 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{className:"bg-[#1C1C21] border border-[#2A2A35] rounded-lg shadow-xl z-[100]",position:"popper",sideOffset:4,children:r.jsx(os,{className:"p-1",children:C.map(F=>r.jsxs(vn,{value:F.userId,className:"flex items-center px-3 py-2 text-[12px] text-[#F0F0F5] rounded cursor-pointer hover:bg-[#2A2A35] outline-none data-[highlighted]:bg-[#2A2A35]",children:[r.jsx(yn,{children:F.name}),r.jsx(ui,{className:"ml-auto",children:r.jsx(Fe,{className:"w-3 h-3"})})]},F.userId))})})})]}),r.jsx("button",{onClick:k,disabled:!f||o.isPending,className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:o.isPending?"Generating...":"Generate code"})]}):r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"All workspace members are already paired."}),r.jsx("button",{onClick:()=>d(!1),className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})})})]})}function kMe({agentId:e}){const{data:t=[],refetch:n}=L.externalChannels.list.useQuery({agentId:e}),s=L.externalChannels.configure.useMutation({onSuccess:()=>n()}),i=L.externalChannels.enable.useMutation({onSuccess:()=>n()}),a=L.externalChannels.disable.useMutation({onSuccess:()=>n()}),o=L.externalChannels.delete.useMutation({onSuccess:()=>n()}),[l,c]=y.useState(null),[d,f]=y.useState(""),[p,m]=y.useState(null),[g,b]=y.useState(null);async function _(){if(!(!d.trim()||!l)){m(null);try{await s.mutateAsync({agentId:e,provider:l,credentials:{botToken:d.trim()}}),f(""),c(null)}catch(A){m(A instanceof Error?A.message:"Connection failed")}}}const w=t.find(A=>A.provider==="telegram");return r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"External Channels"}),w&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] p-3 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:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:w.running?"#10B981":w.status==="error"?"#EF4444":"#5A5A6E"}}),r.jsx(OC,{className:"w-4 h-4 text-[#29B6F6]"}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5]",children:"Telegram"}),typeof w.metadata?.botUsername=="string"&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E]",children:["@",w.metadata.botUsername]})]}),r.jsx(Sh,{checked:w.enabled,onCheckedChange:A=>{A?i.mutate({agentId:e,provider:"telegram"}):a.mutate({agentId:e,provider:"telegram"})},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]",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"})})]}),w.status==="error"&&r.jsx("p",{className:"text-[11px] text-[#EF4444]",children:"Bridge failed to start. Check the bot token."}),r.jsx("div",{className:"flex gap-2",children:g===w.id?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{o.mutate({id:w.id}),b(null)},className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#EF4444] hover:bg-[#DC2626] text-white transition-colors",children:"Confirm disconnect"}),r.jsx("button",{onClick:()=>b(null),className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]}):r.jsx("button",{onClick:()=>b(w.id),className:"text-[11px] text-[#5A5A6E] hover:text-[#EF4444] transition-colors",children:"Disconnect"})})]}),w&&r.jsx(NMe,{externalChannelId:w.id,botUsername:typeof w.metadata?.botUsername=="string"?w.metadata.botUsername:void 0}),w&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35]/50 bg-[#1C1C21]/50 p-3 space-y-2",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"BotFather Setup"}),r.jsxs("div",{className:"text-[11px] text-[#5A5A6E] leading-relaxed space-y-1",children:[r.jsx("p",{children:"Open @BotFather on Telegram and run these for your bot:"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setjoingroups"}),r.jsx("p",{className:"pl-3",children:"Disable (bot is DM-only)"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setprivacy"}),r.jsx("p",{className:"pl-3",children:"Enable (default)"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setdescription"}),r.jsx("p",{className:"pl-3",children:'e.g. "damn.dev workspace agent"'})]})]}),!w&&!l&&r.jsx("div",{className:"space-y-2",children:jMe.map(A=>r.jsxs("button",{onClick:()=>A.available?c(A.id):void 0,disabled:!A.available,className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg border border-[#2A2A35] bg-[#1C1C21] hover:bg-[#2A2A35] transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[r.jsx(A.icon,{className:"w-4 h-4 text-[#8A8A99]"}),r.jsxs("span",{className:"text-[13px] text-[#F0F0F5]",children:["Connect ",A.label]}),!A.available&&r.jsx("span",{className:"ml-auto text-[10px] text-[#5A5A6E]",children:"Coming soon"})]},A.id))}),l==="telegram"&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] p-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(OC,{className:"w-4 h-4 text-[#29B6F6]"}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Connect Telegram Bot"})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:"Create a bot via @BotFather on Telegram, then paste the token below."}),r.jsx("input",{type:"password",value:d,onChange:A=>f(A.target.value),placeholder:"Bot token from @BotFather",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors",onKeyDown:A=>A.key==="Enter"&&_()}),p&&r.jsx("p",{className:"text-[11px] text-[#EF4444]",children:p}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{onClick:_,disabled:s.isPending||!d.trim(),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[s.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Ji,{className:"w-3.5 h-3.5"}),"Connect"]}),r.jsx("button",{onClick:()=>{c(null),f(""),m(null)},className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),!w&&!l&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] leading-relaxed",children:"Connect external messaging platforms to reach this agent outside of damn.dev. Messages flow through the same pipeline with full governance."})]})}function EMe({agentId:e}){const{data:t,refetch:n}=L.agents.getCapabilities.useQuery({agentId:e}),s=L.agents.setCapabilities.useMutation({onSuccess:()=>n()}),[i,a]=y.useState(""),[o,l]=y.useState(!0),[c,d]=y.useState("idle"),f=y.useRef(null);y.useEffect(()=>{t&&(a(t.capabilities.join(", ")),l(t.canReceiveDelegations))},[t]),y.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);async function p(){const m=i.split(",").map(g=>g.trim()).filter(Boolean);await s.mutateAsync({agentId:e,capabilities:m,canReceiveDelegations:o}),d("saved"),f.current=setTimeout(()=>d("idle"),2e3)}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-5 overflow-y-auto",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Capabilities"}),r.jsx("textarea",{value:i,onChange:m=>a(m.target.value),rows:3,placeholder:"write:code, exec:shell, analyze:data",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2.5 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] resize-none outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Comma-separated. Auto-inferred from skills and role when empty."})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:"Accept delegations"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Other agents can delegate tasks to this agent"})]}),r.jsx(Sh,{checked:o,onCheckedChange:l,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]",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"})})]}),t&&t.capabilities.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.capabilities.map(m=>r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] border border-[#6366F1]/20",children:m},m))}),r.jsx("button",{onClick:p,disabled:s.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:r.jsx(Me,{mode:"wait",children:c==="saved"?r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved"},"saved"):r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")})})]})}const t2=["identity","config","live"],FMe={identity:["soul","team","model"],config:["skills","channels","capabilities","trust"],live:["activity","dream","files","git","terminal","schedule","override"]},TMe={identity:[],config:[],live:["activity","dream","files","git","terminal","override"]};function MMe({tabs:e,active:t,onChange:n}){return e.length<=1?null:r.jsx("div",{className:"flex gap-1 px-5 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:e.map(s=>r.jsx("button",{onClick:()=>n(s),className:`px-2.5 py-1 rounded-md text-[11px] font-medium capitalize transition-colors ${t===s?"bg-white/10 text-[#F0F0F5]":"text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5"}`,children:s},s))})}function X8(e,t){const n=atob(e),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n.charCodeAt(l);const i=new Blob([s],{type:"application/zip"}),a=URL.createObjectURL(i),o=document.createElement("a");o.href=a,o.download=t,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}function RMe({warnings:e,onExport:t,onCancel:n}){return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[60] flex items-center justify-center p-4",onClick:n,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},onClick:s=>s.stopPropagation(),className:"relative bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 w-full max-w-sm space-y-4 shadow-2xl",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Export warnings"}),r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:e.map((s,i)=>r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2",children:[r.jsx("p",{className:"text-[12px] text-[#FCD34D] leading-relaxed",children:s.message}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:[s.file,":",s.line]})]},i))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:t,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#F59E0B] hover:bg-[#D97706] text-black transition-colors",children:"Export anyway"}),r.jsx("button",{onClick:n,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]})]})}const DMe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],OMe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16"];function $N({agent:e,agentColor:t,onClose:n,onOverrideSet:s,initialTab:i}){const a=Uo(),o=a?FMe:TMe,l=a?"identity":"live",c=i&&t2.includes(i.category)?i.category:l,d=i&&o[c]?.includes(i.subTab)?i.subTab:o[c][0]??"activity",[f,p]=y.useState(c),[m,g]=y.useState(d),[b,_]=y.useState(null),[w,A]=y.useState(null),S=L.useUtils(),[C,E]=y.useState(!1),[k,T]=y.useState(e.name),F=y.useRef(null),M=L.agents.update.useMutation({onSuccess:()=>{S.agents.list.invalidate(),S.channels.list.invalidate()}});function I(){E(!1);const $=k.trim();$&&$!==e.name?M.mutate({agentId:e.id,name:$}):T(e.name)}y.useEffect(()=>{C&&F.current?.select()},[C]),y.useEffect(()=>{T(e.name)},[e.name]);const R=L.agents.export.useMutation();async function H(){try{const $=await R.mutateAsync({agentId:e.id});$.warnings.length>0?(_($.warnings),A({buffer:$.buffer,filename:$.filename})):X8($.buffer,$.filename)}catch{}}function V(){w&&X8(w.buffer,w.filename),_(null),A(null)}function K($){p($),g(o[$][0]??"")}const q=a?t2:t2.filter($=>o[$].length>0);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",style:{background:`linear-gradient(135deg, rgba(${uh(t)}, 0.08) 0%, transparent 100%)`},children:[r.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[a&&e.id!=="coo"?r.jsxs(Ys,{children:[r.jsx(ci,{asChild:!0,children:r.jsx("button",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xl flex-shrink-0 hover:ring-2 hover:ring-white/20 transition-all",style:{backgroundColor:`${t}26`},children:e.emoji})}),r.jsx(Qs,{children:r.jsxs(Xs,{sideOffset:8,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Emoji"}),r.jsx("div",{className:"grid grid-cols-10 gap-1 mb-3",children:DMe.map($=>r.jsx("button",{onClick:()=>M.mutate({agentId:e.id,emoji:$}),className:`w-6 h-6 flex items-center justify-center rounded text-sm hover:bg-white/10 transition-colors ${e.emoji===$?"bg-white/15 ring-1 ring-white/20":""}`,children:$},$))}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Color"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:OMe.map($=>r.jsx("button",{onClick:()=>M.mutate({agentId:e.id,color:$}),className:`w-6 h-6 rounded-full transition-all ${e.color===$?"ring-2 ring-white/40 scale-110":"hover:scale-110"}`,style:{backgroundColor:$}},$))}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]}):r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xl flex-shrink-0",style:{backgroundColor:`${t}26`},children:e.emoji}),r.jsxs("div",{className:"min-w-0",children:[C?r.jsx("input",{ref:F,value:k,onChange:$=>T($.target.value),onBlur:I,onKeyDown:$=>{$.key==="Enter"&&F.current?.blur(),$.key==="Escape"&&(T(e.name),E(!1))},className:"bg-transparent text-[14px] font-semibold text-[#F0F0F5] outline-none border-b border-[#6366F1]/60 pb-px w-full"}):r.jsxs("p",{className:`text-[14px] font-semibold text-[#F0F0F5] truncate ${a&&e.id!=="coo"?"cursor-pointer hover:text-[#818CF8] transition-colors group/name":""}`,onClick:()=>{a&&e.id!=="coo"&&E(!0)},children:[e.name,a&&e.id!=="coo"&&r.jsx(oh,{className:"w-3 h-3 inline-block ml-1.5 opacity-0 group-hover/name:opacity-60 transition-opacity"})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] truncate",children:e.role})]}),r.jsx(cMe,{status:e.status,color:t}),r.jsx(oMe,{agentId:e.id})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[a&&e.id!=="coo"&&r.jsx(bt,{label:"Export agent",side:"left",children:r.jsx("button",{onClick:H,disabled:R.isPending,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors disabled:opacity-50",children:R.isPending?r.jsx(Pe,{className:"w-4 h-4 animate-spin"}):r.jsx(nu,{className:"w-4 h-4"})})}),r.jsx(bt,{label:"Close",side:"left",children: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.jsx("div",{className:"flex border-b border-[#2A2A35] flex-shrink-0 px-5",children:q.map($=>r.jsx("button",{onClick:()=>K($),className:`py-3 px-1 mr-4 text-[11px] font-medium capitalize border-b-2 transition-colors outline-none ${f===$?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"}`,children:$},$))}),r.jsx(MMe,{tabs:o[f],active:m,onChange:g}),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[a&&m==="soul"&&r.jsx(uMe,{agentId:e.id}),a&&m==="team"&&r.jsx(dMe,{agentId:e.id}),a&&m==="model"&&r.jsx(rMe,{agent:e,agentColor:t}),a&&m==="skills"&&r.jsx(pMe,{agentId:e.id}),a&&m==="channels"&&r.jsx(kMe,{agentId:e.id}),a&&m==="capabilities"&&r.jsx(EMe,{agentId:e.id}),a&&m==="trust"&&r.jsx(CMe,{agentId:e.id}),m==="activity"&&r.jsx(DEe,{agentId:e.id}),m==="dream"&&r.jsx(JTe,{agentId:e.id}),m==="files"&&r.jsx(ITe,{agentId:e.id}),m==="git"&&r.jsx(WTe,{agentId:e.id}),m==="terminal"&&r.jsx(AMe,{agentId:e.id}),a&&m==="schedule"&&r.jsx(SMe,{agentId:e.id}),m==="override"&&r.jsx(mMe,{agentId:e.id,onOverrideSet:s,onClose:n})]})]}),r.jsx(Me,{children:b&&r.jsx(RMe,{warnings:b,onExport:V,onCancel:()=>{_(null),A(null)}})})]})}async function PMe(e){if(Va)try{const{sendNotification:t,isPermissionGranted:n,requestPermission:s}=await X(async()=>{const{sendNotification:a,isPermissionGranted:o,requestPermission:l}=await import("./index-E-6oA41F.js");return{sendNotification:a,isPermissionGranted:o,requestPermission:l}},__vite__mapDeps([103,1]));let i=await n();if(i||(i=await s()==="granted"),!i)return;t({title:e.title,body:e.body})}catch{}}const IMe=/\.(kanban|chart|table|board)\.json$/,LMe=oi.replace(/^http/,"ws")+"/ws",BMe=25e3,zMe=3e3;function J8(e,t){if(Va){document.hidden&&PMe({title:e,body:t.slice(0,80)});return}!("Notification"in window)||Notification.permission!=="granted"||document.hidden&&new Notification(e,{body:t.slice(0,80),icon:"/favicon.ico"})}function $Me(e,t){return new RegExp(`@${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`,"i").test(e)}const Z8=new Set;function bW(e){const t=L.useUtils(),{data:n}=Mi(),s=y.useRef(n?.user?.name??"");y.useLayoutEffect(()=>{s.current=n?.user?.name??""});const{appendMessage:i,setAgentStatus:a,updateMessageStatus:o,updateMessage:l,removeMessage:c,updateReactions:d,setUnreadCount:f,addFileEditApproval:p,removeFileEditApproval:m}=Je(),g=y.useRef(null),b=y.useRef(null),_=y.useRef(e),w=y.useRef(!0),A=y.useRef(!1);y.useLayoutEffect(()=>{_.current=e});const S=y.useCallback(async C=>{const k=Je.getState().messagesByChannel[C];if(!k||k.length===0)return;const T=k[k.length-1];try{const F=await t.messages.list.fetch({channelId:C,cursor:T.id,limit:100,direction:"after"});if(F.messages.length>0)for(const M of F.messages)i(M)}catch{}},[t,i]);y.useEffect(()=>{w.current=!0;let C=null;function E(){if(!w.current)return;const k=new WebSocket(LMe);g.current=k,k.onopen=()=>{if(!w.current){k.close(1e3);return}const T=_.current;T&&k.send(JSON.stringify({type:"subscribe",channelId:T})),A.current&&(T&&S(T),t.messages.list.invalidate(),t.channels.list.invalidate(),t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate()),A.current=!0,b.current=setInterval(()=>{k.readyState===WebSocket.OPEN&&k.send(JSON.stringify({type:"ping"}))},BMe)},k.onmessage=T=>{if(w.current)try{const F=JSON.parse(T.data);if(F.type==="message.new"){const M=F;i(M.payload),M.payload.sender.type==="agent"&&M.payload.channelId!==_.current&&J8(M.payload.sender.name,M.payload.content)}else if(F.type==="message.edited"){const M=F;l(M.payload.channelId,M.payload.messageId,{content:M.payload.content,editedAt:M.payload.editedAt})}else if(F.type==="message.deleted"){const M=F;c(M.payload.channelId,M.payload.messageId)}else if(F.type==="message.pinned"){const M=F;l(M.payload.channelId,M.payload.messageId,{pinnedAt:M.payload.pinnedAt,pinnedBy:M.payload.pinnedBy})}else if(F.type==="message.unpinned"){const M=F;l(M.payload.channelId,M.payload.messageId,{pinnedAt:void 0,pinnedBy:void 0})}else if(F.type==="message.metadata_updated"){const M=F;l(M.payload.channelId,M.payload.messageId,{metadata:M.payload.metadata})}else if(F.type==="reaction.toggled"){const M=F;d(M.payload.channelId,M.payload.messageId,M.payload.reactions)}else if(F.type==="thread.message.new"){const M=F,R=(Je.getState().messagesByChannel[M.payload.channelId]??[]).find(H=>H.id===M.payload.parentMessageId);R&&l(M.payload.channelId,M.payload.parentMessageId,{replyCount:(R.replyCount??0)+1})}else if(F.type==="agent.status"){const M=F;a(M.payload.agentId,M.payload.status),M.payload.status==="thinking"?Mw("thinking"):Mw("idle")}else if(F.type==="approval.decided"){const M=F;o(M.payload.channelId,M.payload.messageId,M.payload.decision),t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate()}else if(F.type==="approval.file_edit.created")p(F.payload);else if(F.type==="approval.file_edit.decided"){const M=F;m(M.payload.channelId,M.payload.id)}else if(F.type==="conversation.cleared"){const M=F;Je.getState().setMessages(M.payload.channelId,[])}else if(F.type==="channel.created"||F.type==="channel.closed"||F.type==="channel.updated")t.channels.list.invalidate(),F.type==="channel.created"&&t.readReceipts.getUnread.invalidate();else if(F.type==="channel.tabs.updated"){const M=F;t.channels.get.invalidate({channelId:M.payload.parentChannelId}),t.channels.list.invalidate()}else if(F.type==="channel.tokenUpdate"){const M=F;ny.getState().updateFromWs(M.payload.channelId,M.payload)}else if(F.type==="channel.compacted"){const M=F;Je.getState().appendMessage({id:`compaction-${Date.now()}`,channelId:M.payload.channelId,sender:{type:"context_reset",id:"system",name:"system"},content:`compacted:${M.payload.summarizedCount}`,timestamp:new Date().toISOString()})}else if(F.type==="presence.changed"){const M=F;t.workspace.listPresence.setData(void 0,I=>I&&I.map(R=>R.userId===M.payload.userId?{...R,online:M.payload.online,lastSeenAt:M.payload.lastSeenAt??R.lastSeenAt}:R))}else if(F.type==="agent.fileChanged"){const M=F;t.fileChanges.list.invalidate({channelId:M.payload.channelId})}else if(F.type==="agent.filesChanged"){const M=F;if(t.files.tree.invalidate({agentId:M.payload.agentId}),M.payload.filename&&IMe.test(M.payload.filename)){const R=t.channels.list.getData()?.find(H=>H.channelType==="dm"&&H.agentId===M.payload.agentId);R&&NU.getState().addCard(R.id,{id:`sf-${M.payload.agentId}-${M.payload.filename}-${Date.now()}`,agentId:M.payload.agentId,filename:M.payload.filename,filePath:M.payload.filePath??M.payload.filename,timestamp:Date.now()})}}else if(F.type==="agent.created"||F.type==="agent.deleted")t.agents.list.invalidate(),t.channels.list.invalidate();else if(F.type==="approval.created"||F.type==="approval.expired"){if(t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate(),F.type==="approval.created"){const M=F.payload;M?.channelId&&S(M.channelId),Mw("badge"),J8("Action required",M?.agentName?`${M.agentName} wants to: ${M.description??"perform an action"}`:"An agent requires approval"),window.dispatchEvent(new CustomEvent("pwa-push-prompt"))}}else(F.type==="mission.task.updated"||F.type==="mission.task.dispatched"||F.type==="mission.created")&&(t.missions.list.invalidate(),t.federation.activityFeed.invalidate());if(F.type==="message.new"){const M=F;if(M.payload.channelId!==_.current&&!Z8.has(M.payload.id)){Z8.add(M.payload.id);const{mutedChannels:I,unreadCounts:R}=Je.getState(),H=I[M.payload.channelId];H?H.notifyOnMention&&s.current&&$Me(M.payload.content,s.current)&&f(M.payload.channelId,(R[M.payload.channelId]??0)+1):f(M.payload.channelId,(R[M.payload.channelId]??0)+1)}}}catch{}},k.onclose=T=>{b.current&&clearInterval(b.current),w.current&&T.code!==1e3&&(C=setTimeout(E,zMe))},k.onerror=()=>{k.close()}}return E(),()=>{w.current=!1,b.current&&clearInterval(b.current),C&&clearTimeout(C),g.current?.close(1e3)}},[i,a,o,l,c,d,f,p,m,t,S]),y.useEffect(()=>{const C=g.current;!C||C.readyState!==WebSocket.OPEN||e&&C.send(JSON.stringify({type:"subscribe",channelId:e}))},[e])}const VMe={orchestrator:"#6366F1","content-agent":"#8B5CF6","engagement-agent":"#10B981"};function UMe(){const{channelId:e}=am(),t=an(),n=tz(D=>D.setActiveChannelId);y.useEffect(()=>(n(e??null),()=>n(null)),[e,n]);const{data:s}=L.channels.get.useQuery({channelId:e??""},{enabled:!!e,retry:!1});y.useEffect(()=>{if(!s||!e)return;const D=s.channel,Q=s.tabs,z=V7.getState();if(D.parentChannelId==null){const J=z.lastTab[e];J&&J!==e&&(Q.some(ee=>ee.id===J)?t(`/channels/${J}`,{replace:!0}):z.clearLast(e))}else z.lastTab[D.parentChannelId]!==e&&z.setLast(D.parentChannelId,e)},[s,e,t]);const[i,a]=y.useState(!1),[o,l]=y.useState(void 0),[c,d]=y.useState(!1),[f,p]=y.useState(null);y.useEffect(()=>{function D(){l({category:"live",subTab:"files"}),a(!0)}return window.addEventListener("open-agent-files",D),()=>window.removeEventListener("open-agent-files",D)},[]);const{data:m}=ez(e??""),{data:g}=pj(m?.agentId??""),{data:b=[]}=Vo(),{data:_}=Mi(),w=m?.channelType==="dm"&&!m.agentId,A=m?.channelType==="group"||m?.channelType==="topic",{data:S=[]}=L.workspace.listMembers.useQuery(void 0,{enabled:w||A}),C=w?m.participants.find(D=>D.participantType==="human"&&D.participantId!==_?.user?.id):void 0,E=C?S.find(D=>D.userId===C.participantId)?.name??void 0:void 0,k=C?.participantId,{data:T,isLoading:F,loadMore:M}=W7(e??""),I=Je(D=>D.agentStatuses),R=Je(D=>D.openThreadMessageId),H=Je(D=>D.closeThread),V=Je(D=>D.unreadCounts),{mutate:K,isPending:q}=q7();bW(e);const $=!!g&&((I[g.id]??g.status)==="thinking"||(I[g.id]??g.status)==="executing"),B=T.some(D=>D.status==="pending_approval"),Y=g?VMe[g.id]??g.color:void 0,U=e?V[e]??0:0,W=U>0&&T.length>=U?T[T.length-U]?.id:void 0,O=y.useCallback((D,Q)=>{e&&K({channelId:e,content:D,attachmentIds:Q})},[e,K]);return!e||!m?r.jsx("div",{className:"flex-1 flex items-center justify-center text-[#8A8A99]",children:r.jsx("p",{className:"text-[14px]",children:"Channel not found"})}):m.channelType==="terminal"?r.jsx("div",{className:"flex-1"}):m.channelType==="group"?r.jsx(dwe,{channel:m,agents:b}):r.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[r.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[r.jsx(swe,{channel:m,agent:w?void 0:g,agentColor:w?void 0:Y,hasPendingApproval:w?!1:B,rightPanelOpen:i,memoryPanelOpen:c,activeOverride:f,humanDmName:E,humanDmUserId:k,onToggleRightPanel:()=>a(D=>!D),onToggleMemoryPanel:()=>d(D=>!D),onAgentClick:()=>a(D=>!D),onClearOverride:()=>p(null),onClearConversation:()=>Je.getState().setMessages(e,[])}),r.jsx(ike,{channelId:e,agentForChannel:m.channelType==="topic"||w?void 0:g,agentColor:m.channelType==="topic"||w?void 0:Y,messages:T,isThinking:m.channelType==="topic"||w?!1:$,isLoading:F,loadMore:M,firstUnreadId:W}),r.jsx(cke,{channelId:e}),r.jsx(H7,{channelId:e,channelName:w?E??"User":m.name,agent:m.channelType==="topic"||w?void 0:g,agentColor:m.channelType==="topic"||w?void 0:Y,onSend:O,disabled:q,mentionableParticipants:m.channelType==="topic"?[...m.participants.filter(D=>D.participantType==="agent").map(D=>b.find(Q=>Q.id===D.participantId)).filter(D=>!!D).map(D=>({id:D.id,name:D.name,emoji:D.emoji,color:D.color,type:"agent"})),...m.participants.filter(D=>D.participantType==="human"&&D.participantId!==_?.user?.id).map(D=>{const Q=S.find(z=>z.userId===D.participantId);return Q?{id:Q.userId,name:Q.name,emoji:null,color:"#6366F1",type:"human"}:null}).filter(D=>!!D)]:void 0})]}),r.jsx(Me,{children:c&&g&&r.jsx(hke,{agent:g,agentColor:Y,onClose:()=>d(!1)})}),r.jsx(Me,{children:R&&r.jsx(dke,{parentMessageId:R,agentColor:Y,onClose:H})}),r.jsx(Me,{children:i&&g&&Y&&r.jsx($N,{agent:g,agentColor:Y,onClose:()=>{a(!1),l(void 0)},onOverrideSet:D=>p(D),initialTab:o},o?.subTab)})]})}function HMe({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.agentImport.previewImport.useMutation(),m=L.agentImport.confirmImport.useMutation(),g=y.useCallback(async S=>{if(!S.name.endsWith(".damnpack")){l("Please select a .damnpack file"),s("error");return}if(S.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const C=new FormData;C.append("file",S);const E=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:C,credentials:"include"});if(!E.ok){const F=await E.json().catch(()=>({error:"Upload failed"}));throw new Error(F.error||`Upload failed (${E.status})`)}const{uploadId:k}=await E.json(),T=await p.mutateAsync({uploadId:k});if("kind"in T&&T.kind==="skill-pack"){s("skill-pack");return}a(T),s("preview")}catch(C){l(C instanceof Error?C.message:"Upload failed"),s("error")}},[p]);async function b(S){if(i){s("confirming");try{const C=await m.mutateAsync({previewId:i.previewId,mode:S});d(C),s("done")}catch(C){l(C instanceof Error?C.message:"Import failed"),s("error")}}}const _=i?.warnings.filter(S=>S.type==="credential")??[],w=i?.warnings.filter(S=>S.type==="url")??[],A=i?.warnings.filter(S=>S.type==="shell_exec")??[];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:S=>S.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"?"Import complete":n==="skill-pack"?"Skill pack":"Import agent"}),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 file"}),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:S=>{const C=S.target.files?.[0];C&&g(C)}})]}),(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 bundle...":"Importing agent..."})]}),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==="skill-pack"&&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-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",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Skill pack detected"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"This bundle contains skills, not an agent."})]})]}),r.jsx(gn,{to:"/skills",onClick:e,className:"flex items-center justify-center w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Go to Skills page to import"}),r.jsx("button",{onClick:e,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]}),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 text-lg",children:i.manifest.name.slice(0,2)}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.manifest.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.manifest.version," by ",i.manifest.author.name]})]}),i.isUpdate&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20",children:"Update"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.manifest.description}),r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] p-3",children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:"Soul excerpt"}),r.jsx("p",{className:"text-[12px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap line-clamp-6",children:i.soulExcerpt})]}),i.manifest.skills.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Skills"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:i.manifest.skills.map(S=>r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] border border-[#6366F1]/20",children:S},S))})]}),i.isUpdate&&i.diff&&r.jsx("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] px-3 py-2",children:r.jsxs("p",{className:"text-[12px] text-[#C8C8D4]",children:["SOUL.md: ",r.jsxs("span",{className:"text-emerald-400",children:["+",i.diff.added]})," / ",r.jsxs("span",{className:"text-red-400",children:["-",i.diff.removed]})," lines",i.skillFiles.length>0&&`. ${i.skillFiles.length} skill file(s).`]})}),i.modelWarnings.length>0&&r.jsx("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:i.modelWarnings.map((S,C)=>r.jsxs("p",{className:"text-[11px] text-[#FCD34D] flex items-start gap-1.5",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),S]},C))}),i.missingSecrets.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 missing"]}),r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80",children:"This bundle's skills reference secrets that aren't set in this workspace. You can still import now, but agents will fail to call these tools until you add the secrets in Settings → Secrets:"}),r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:i.missingSecrets.map(S=>r.jsx("code",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono text-[#FCD34D] bg-[#F59E0B]/15 border border-[#F59E0B]/20",children:S},S))})]}),A.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5] flex items-center gap-1.5",children:[r.jsx(Ti,{className:"w-3.5 h-3.5"}),"Shell execution patterns detected"]}),A.map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80 ml-5",children:[S.file,":",S.line," — ",S.message]},C))]}),_.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),"Possible credentials found"]}),_.map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:[S.file,":",S.line]},C))]}),w.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#2A2A35]/50 border border-[#2A2A35] px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#8A8A99] flex items-center gap-1.5",children:[r.jsx(Xt,{className:"w-3.5 h-3.5"}),"External URLs (",w.length,")"]}),w.slice(0,5).map((S,C)=>r.jsx("p",{className:"text-[10px] text-[#5A5A6E] ml-5 truncate",children:S.message.replace("External URL: ","")},C)),w.length>5&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] ml-5",children:["...and ",w.length-5," more"]})]}),i.hasHeartbeat&&r.jsx("div",{className:"rounded-lg bg-[#6366F1]/10 border border-[#6366F1]/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-[#818CF8] flex items-start gap-1.5",children:[r.jsx(bm,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),"This agent includes a scheduled task. It will be disabled by default."]})}),i.isUpdate&&r.jsxs("p",{className:"text-[11px] text-[#8A8A99] italic",children:["Updating existing agent: ",i.manifest.name,". Your memory and experience will be preserved."]}),i.strippedFiles.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:["Stripped from bundle: ",i.strippedFiles.join(", ")]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[i.isUpdate?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>b("update"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Update"}),r.jsx("button",{onClick:()=>b("new"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Import as copy"})]}):r.jsx("button",{onClick:()=>b("new"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Import"}),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.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:c.name}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:c.mode==="update"?"Agent updated successfully":"Agent imported successfully"})]})]}),c.heartbeatNote&&r.jsx("p",{className:"text-[11px] text-[#818CF8] bg-[#6366F1]/10 border border-[#6366F1]/20 rounded-lg px-3 py-2",children:c.heartbeatNote}),c.diff&&r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:c.diff}),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"})]})]})]})]})}function WMe({onClose:e}){const[t,n]=y.useState("select"),[s,i]=y.useState(new Set),[a,o]=y.useState(new Set),[l,c]=y.useState(null),[d,f]=y.useState([]),{data:p}=L.teamBundle.listExportable.useQuery(),m=L.teamBundle.exportTeam.useMutation(),g=p?.agents??[],b=p?.channels??[];function _(S){i(C=>{const E=new Set(C);return E.has(S)?E.delete(S):E.add(S),E})}function w(S){o(C=>{const E=new Set(C);return E.has(S)?E.delete(S):E.add(S),E})}async function A(){if(s.size!==0){n("exporting");try{const S=await m.mutateAsync({agentIds:[...s],channelIds:[...a]});f(S.warnings.map(M=>({file:M.file,message:M.message})));const C=atob(S.buffer),E=new Uint8Array(C.length);for(let M=0;M<C.length;M++)E[M]=C.charCodeAt(M);const k=new Blob([E],{type:"application/zip"}),T=URL.createObjectURL(k),F=document.createElement("a");F.href=T,F.download=S.filename,F.click(),URL.revokeObjectURL(T),n("done")}catch(S){c(S instanceof Error?S.message:"Export failed"),n("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:S=>S.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:t==="done"?"Export complete":"Export team"}),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:[t==="select"&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Agents (",s.size," selected)"]}),r.jsxs("div",{className:"space-y-1",children:[g.map(S=>r.jsxs("label",{className:"flex items-center gap-3 py-2 px-3 rounded-lg hover:bg-white/5 cursor-pointer transition-colors",children:[r.jsx("input",{type:"checkbox",checked:s.has(S.id),onChange:()=>_(S.id),className:"w-3.5 h-3.5 rounded border-[#2A2A35] text-[#6366F1] focus:ring-0 focus:ring-offset-0"}),r.jsx("span",{className:"text-sm",children:S.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:S.name}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:S.role})]})]},S.id)),g.length===0&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-2",children:"No agents available"})]})]}),b.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Channels (",a.size," selected)"]}),r.jsx("div",{className:"space-y-1",children:b.map(S=>r.jsxs("label",{className:"flex items-center gap-3 py-2 px-3 rounded-lg hover:bg-white/5 cursor-pointer transition-colors",children:[r.jsx("input",{type:"checkbox",checked:a.has(S.id),onChange:()=>w(S.id),className:"w-3.5 h-3.5 rounded border-[#2A2A35] text-[#6366F1] focus:ring-0 focus:ring-offset-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:S.name}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E]",children:[S.channelType," / ",S.visibility]})]})]},S.id))})]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsxs("button",{onClick:A,disabled:s.size===0,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-40 disabled:pointer-events-none flex items-center justify-center gap-2",children:[r.jsx(vv,{className:"w-4 h-4"}),"Export (",s.size," agents)"]}),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"})]})]}),t==="exporting"&&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:"Packaging team bundle..."})]}),t==="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:l})}),r.jsx("button",{onClick:()=>{n("select"),c(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),t==="done"&&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.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Team exported"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[s.size," agents, ",a.size," channels"]})]})]}),r.jsx(Me,{children:d.length>0&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),d.length," warning(s)"]}),d.slice(0,5).map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:[S.file,": ",S.message]},C))]})}),r.jsx("button",{onClick:e,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}function qMe({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,p]=y.useState(null),m=y.useRef(null),g=L.teamBundle.previewTeamImport.useMutation(),b=L.teamBundle.confirmTeamImport.useMutation(),_=y.useCallback(async C=>{if(!C.name.endsWith(".damnteam")){l("Please select a .damnteam file"),s("error");return}if(C.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const E=new FormData;E.append("file",C);const k=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:E,credentials:"include"});if(!k.ok){const M=await k.json().catch(()=>({error:"Upload failed"}));throw new Error(M.error||`Upload failed (${k.status})`)}const{uploadId:T}=await k.json(),F=await g.mutateAsync({uploadId:T});a(F),s("preview")}catch(E){l(E instanceof Error?E.message:"Upload failed"),s("error")}},[g]);async function w(){if(i){s("confirming");try{const C=await b.mutateAsync({previewId:i.previewId});d(C),s("done")}catch(C){l(C instanceof Error?C.message:"Import failed"),s("error")}}}const A=i?.warnings.filter(C=>C.type==="credential")??[],S=i?.warnings.filter(C=>C.type==="shell_exec")??[];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:C=>C.stopPropagation(),className:"relative w-full max-w-lg 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"?"Team imported":"Import team"}),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:()=>m.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 .damnteam file"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Max 100MB"})]})]}),r.jsx("input",{ref:m,type:"file",accept:".damnteam",className:"hidden",onChange:C=>{const E=C.target.files?.[0];E&&_(E)}})]}),(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 team bundle...":"Importing team..."})]}),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(wm,{className:"w-5 h-5 text-[#6366F1]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.teamManifest.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.teamManifest.version," by ",i.teamManifest.author.name]})]})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.teamManifest.description}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Agents (",i.agentPreviews.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.agentPreviews.map(C=>r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] overflow-hidden",children:[r.jsxs("button",{onClick:()=>p(f===C.slug?null:C.slug),className:"w-full flex items-center gap-3 px-3 py-2.5 text-left",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:C.manifest.name}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:C.manifest.description})]}),C.isUpdate&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20 flex-shrink-0",children:"Update"}),C.warnings.length>0&&r.jsx(ql,{className:"w-3.5 h-3.5 text-[#FCD34D] flex-shrink-0"}),r.jsx(ft,{className:`w-3.5 h-3.5 text-[#5A5A6E] transition-transform ${f===C.slug?"rotate-180":""}`})]}),r.jsx(Me,{children:f===C.slug&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:r.jsxs("div",{className:"px-3 pb-3 space-y-2 border-t border-[#2A2A35]",children:[r.jsx("p",{className:"text-[11px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap line-clamp-4 pt-2",children:C.soulExcerpt}),C.modelWarnings.length>0&&r.jsx("div",{className:"space-y-0.5",children:C.modelWarnings.map((E,k)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D] flex items-center gap-1",children:[r.jsx(Wl,{className:"w-3 h-3"}),E]},k))}),C.hasHeartbeat&&r.jsxs("p",{className:"text-[10px] text-[#818CF8] flex items-center gap-1",children:[r.jsx(bm,{className:"w-3 h-3"}),"Includes scheduled task (will be disabled)"]})]})})})]},C.slug))})]}),i.channelDefinitions.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Channels (",i.channelDefinitions.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.channelDefinitions.map((C,E)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Tp,{className:"w-3.5 h-3.5 text-[#5A5A6E]"}),r.jsx("p",{className:"text-[12px] text-[#C8C8D4] flex-1",children:C.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:C.channelType}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:[C.agentSlugs.length," agents"]})]},E))})]}),i.delegationRules.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Delegation rules (",i.delegationRules.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.delegationRules.map((C,E)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(ch,{className:"w-3.5 h-3.5 text-[#5A5A6E]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.agentSlug}),r.jsx("code",{className:"text-[11px] font-mono text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded",children:C.pattern}),r.jsx("span",{className:"ml-auto px-2 py-0.5 rounded-full text-[9px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/20",children:"Will require approval"})]},E))})]}),S.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5] flex items-center gap-1.5",children:[r.jsx(Ti,{className:"w-3.5 h-3.5"}),"Shell execution patterns detected"]}),S.slice(0,5).map((C,E)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80 ml-5",children:[C.file,": ",C.message]},E))]}),A.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),"Possible credentials found"]}),A.slice(0,5).map((C,E)=>r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:C.file},E))]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsx("button",{onClick:w,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Import 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.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Team imported"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c.importedAgents.length," agents, ",c.createdChannels.length," channels"]})]})]}),c.importedAgents.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Imported agents"}),r.jsx("div",{className:"space-y-1",children:c.importedAgents.map(C=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Fe,{className:"w-3 h-3 text-emerald-400"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:C.mode})]},C.agentId))})]}),c.createdChannels.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Created channels"}),r.jsx("div",{className:"space-y-1",children:c.createdChannels.map(C=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Tp,{className:"w-3 h-3 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.name})]},C.id))})]}),c.pendingRules.length>0&&r.jsx("div",{className:"rounded-lg bg-amber-500/10 border border-amber-500/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-amber-400",children:[c.pendingRules.length," delegation rule(s) pending approval"]})}),c.failures.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5]",children:["Failed (",c.failures.length,")"]}),c.failures.map((C,E)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80",children:[C.slug,": ",C.error]},E))]}),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"})]})]})]})]})}function GMe({status:e,color:t}){const n=e==="thinking"||e==="executing";return r.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3",children:[n&&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:2,repeat:1/0,ease:"easeInOut"}}),r.jsx("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{backgroundColor:e==="offline"?"#3A3A45":t,opacity:e==="idle"?.5:1}})]})}function KMe({agent:e,onClose:t}){const{data:n,isLoading:s}=L.agents.getMemory.useQuery({agentId:e.id});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:t,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},className:"relative w-full max-w-2xl bg-[#16161A] border border-[#2A2A35] rounded-2xl overflow-hidden shadow-2xl",onClick:i=>i.stopPropagation(),children:[r.jsxs("div",{className:"px-6 py-5 border-b border-[#2A2A35] flex items-center justify-between",style:{background:`linear-gradient(135deg, rgba(${uh(e.color)}, 0.08) 0%, transparent 100%)`},children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-2xl",children:e.emoji}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:e.name}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"MEMORY.md — read only"})]})]}),r.jsx("button",{onClick:t,className:"text-[#8A8A99] hover:text-[#F0F0F5] transition-colors text-[20px] leading-none w-8 h-8 flex items-center justify-center rounded-lg hover:bg-white/10",children:"×"})]}),r.jsxs("div",{className:"p-6 max-h-[60vh] overflow-y-auto",children:[s&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] animate-pulse",children:"Loading memory…"}),!s&&!n?.content&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No memory recorded yet."}),!s&&n?.content&&r.jsx("div",{className:"prose-message text-[13px]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:n.content})})]})]})]})}function YMe({agent:e,onConfirm:t,onCancel:n}){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:n,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},className:"relative w-full max-w-sm bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6 shadow-2xl",onClick:s=>s.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsx("span",{className:"text-3xl",children:e.emoji}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:["Delete ",e.name,"?"]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"This permanently removes the agent from OpenClaw, deletes all files (SOUL, MEMORY, TEAM), and removes the DM channel."})]})]}),r.jsxs("div",{className:"flex gap-2 mt-6",children:[r.jsx("button",{onClick:n,className:"flex-1 h-9 rounded-lg border border-[#2A2A35] text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45] transition-colors",children:"Cancel"}),r.jsx("button",{onClick:t,className:"flex-1 h-9 rounded-lg bg-red-500/10 border border-red-500/30 text-[13px] text-red-400 hover:bg-red-500/20 transition-colors",children:"Delete"})]})]})]})}function QMe({agent:e}){const[t,n]=y.useState(""),s=L.useUtils(),i=L.agents.update.useMutation({onSuccess:()=>s.agents.list.invalidate()}),{groups:a}=Vm();return r.jsxs(Yv,{onOpenChange:o=>{o||n("")},children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-white/5 hover:bg-white/10 transition-colors text-[12px] text-[#C8C8D4]",children:[r.jsx("span",{children:ta(e.model)}),r.jsx(Jt,{className:"w-3 h-3 rotate-90"})]})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-y-auto shadow-xl z-[9999] min-w-[160px] max-h-[280px]",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:t,onChange:n,onSubmit:o=>{i.mutate({agentId:e.id,model:o}),n("")},placeholder:"Type model ID..."})}),a.map(o=>r.jsxs(g_e,{children:[r.jsx(b_e,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-wider",children:o.label}),o.models.map(l=>r.jsx(Bl,{onSelect:()=>i.mutate({agentId:e.id,model:l.id}),className:ye("w-full text-left px-3 py-1.5 text-[12px] cursor-pointer outline-none hover:bg-white/10 transition-colors",e.model===l.id?"text-[#F0F0F5]":"text-[#8A8A99]"),children:l.label},l.id))]},o.label))]})})]})}function XMe(e,t){const n=atob(e),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n.charCodeAt(l);const i=new Blob([s],{type:"application/zip"}),a=URL.createObjectURL(i),o=document.createElement("a");o.href=a,o.download=t,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}const JMe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],ZMe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16"];function eRe({agent:e,onOpenPanel:t,canManage:n}){const[s,i]=y.useState(!1),[a,o]=y.useState(!1),[l,c]=y.useState(!1),[d,f]=y.useState(e.name),p=y.useRef(null),m=L.useUtils();y.useEffect(()=>{l&&p.current?.select()},[l]),y.useEffect(()=>{f(e.name)},[e.name]);const g=L.agents.update.useMutation({onSuccess:()=>{m.agents.list.invalidate(),m.channels.list.invalidate()}});function b(){c(!1);const C=d.trim();C&&C!==e.name?g.mutate({agentId:e.id,name:C}):f(e.name)}const _=L.agents.delete.useMutation({onSuccess:()=>m.agents.list.invalidate()}),w=L.agents.export.useMutation({onSuccess:C=>XMe(C.buffer,C.filename)}),A=e.status==="offline",S=uh(e.color);return r.jsxs(r.Fragment,{children:[r.jsxs(ne.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},onClick:()=>t(e),className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 hover:border-[#3A3A45] transition-colors group relative overflow-hidden cursor-pointer",children:[r.jsx("div",{className:"absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",style:{background:`radial-gradient(400px circle at 0% 0%, rgba(${S}, 0.04), transparent 60%)`}}),r.jsxs("div",{className:"flex items-start gap-4 mb-4",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center text-2xl flex-shrink-0",style:{backgroundColor:`rgba(${S}, 0.15)`,border:`1px solid rgba(${S}, 0.25)`},children:e.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[l?r.jsx("input",{ref:p,value:d,onChange:C=>f(C.target.value),onBlur:b,onKeyDown:C=>{C.key==="Enter"&&p.current?.blur(),C.key==="Escape"&&(f(e.name),c(!1))},onClick:C=>C.stopPropagation(),className:"bg-transparent text-[15px] font-semibold text-[#F0F0F5] outline-none border-b border-[#6366F1]/60 pb-px flex-1 min-w-0"}):r.jsx("h3",{className:"text-[15px] font-semibold text-[#F0F0F5] truncate",children:e.name}),r.jsx(GMe,{status:e.status,color:e.color})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] truncate",children:e.role}),e.lastAction&&r.jsx("p",{className:"text-[11px] text-[#5A5A6A] mt-1",children:Ir(e.lastAction)})]}),n&&e.id!=="coo"&&r.jsx("div",{onClick:C=>C.stopPropagation(),children:r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/10 transition-colors opacity-0 group-hover:opacity-100",children:r.jsx(iL,{className:"w-4 h-4"})})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,align:"end",className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-hidden shadow-xl z-[9999] min-w-[160px]",children:[r.jsxs(Bl,{onSelect:()=>c(!0),className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(oh,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Rename"]}),r.jsxs(lR,{children:[r.jsxs(cR,{className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors data-[state=open]:bg-white/10",children:[r.jsx(Tre,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Change emoji",r.jsx(Jt,{className:"w-3 h-3 ml-auto text-[#5A5A6E]"})]}),r.jsx(Od,{children:r.jsxs(uR,{sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Choose emoji"}),r.jsx("div",{className:"grid grid-cols-10 gap-1",children:JMe.map(C=>r.jsx(Bl,{onSelect:()=>g.mutate({agentId:e.id,emoji:C}),className:`w-6 h-6 flex items-center justify-center rounded text-sm cursor-pointer outline-none hover:bg-white/10 transition-colors ${e.emoji===C?"bg-white/15 ring-1 ring-white/20":""}`,children:C},C))})]})})]}),r.jsxs(lR,{children:[r.jsxs(cR,{className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors data-[state=open]:bg-white/10",children:[r.jsx(Zie,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Change color",r.jsx(Jt,{className:"w-3 h-3 ml-auto text-[#5A5A6E]"})]}),r.jsx(Od,{children:r.jsxs(uR,{sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Choose color"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:ZMe.map(C=>r.jsx(Bl,{onSelect:()=>g.mutate({agentId:e.id,color:C}),className:`w-7 h-7 rounded-full cursor-pointer outline-none transition-all ${e.color===C?"ring-2 ring-white/40 scale-110":"hover:scale-110"}`,style:{backgroundColor:C}},C))})]})})]})]})})]})})]}),r.jsxs("p",{className:"text-[12px] text-[#6A6A7A] leading-relaxed line-clamp-2 mb-4 italic",children:['"',e.soulExcerpt,'"']}),r.jsxs("div",{className:"flex items-center gap-2",onClick:C=>C.stopPropagation(),children:[n&&r.jsx(QMe,{agent:e}),n&&r.jsx(bt,{label:"Edit soul",children:r.jsx(gn,{to:`/agents/edit-soul/${e.id}`,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(Ese,{className:"w-3.5 h-3.5"})})}),r.jsx(bt,{label:"View memory",children:r.jsx("button",{onClick:()=>i(!0),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(eie,{className:"w-3.5 h-3.5"})})}),n&&r.jsx(bt,{label:A?"Resume":"Pause",children:r.jsx("button",{onClick:()=>g.mutate({agentId:e.id,status:A?"idle":"offline"}),className:ye("w-7 h-7 flex items-center justify-center rounded-md transition-colors",A?"text-emerald-400 hover:bg-emerald-500/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10"),children:A?r.jsx(I5,{className:"w-3.5 h-3.5"}):r.jsx(gL,{className:"w-3.5 h-3.5"})})}),n&&e.id!=="coo"&&r.jsx(bt,{label:"Export agent",children:r.jsx("button",{onClick:()=>w.mutate({agentId:e.id}),disabled:w.isPending,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/10 transition-colors opacity-0 group-hover:opacity-100 disabled:opacity-50",children:r.jsx(nu,{className:"w-3.5 h-3.5"})})}),n&&r.jsx(bt,{label:"Delete agent",children:r.jsx("button",{onClick:()=>o(!0),className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors opacity-0 group-hover:opacity-100",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]})]}),r.jsxs(Me,{children:[s&&r.jsx(KMe,{agent:e,onClose:()=>i(!1)}),a&&r.jsx(YMe,{agent:e,onCancel:()=>o(!1),onConfirm:()=>{_.mutate({agentId:e.id}),o(!1)}})]})]})}function tRe(){const[e,t]=y.useState(null),[n,s]=y.useState(!1),[i,a]=y.useState(!1),[o,l]=y.useState(!1),{data:c=[],isLoading:d}=L.agents.list.useQuery(),f=L.useUtils(),p=Uo();return r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11]",children:[r.jsxs("div",{className:"max-w-4xl mx-auto px-8 py-10",children:[r.jsxs("div",{className:"flex items-center justify-between mb-8",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"Agents"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mt-0.5",children:"Your team of AI collaborators"})]}),p&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-xl border border-[#2A2A35] text-[#C8C8D4] text-[13px] font-medium hover:bg-white/5 transition-colors",children:[r.jsx(su,{className:"w-4 h-4"}),"Import",r.jsx(Jt,{className:"w-3 h-3 rotate-90 text-[#5A5A6E]"})]})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,align:"end",className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-hidden shadow-xl z-[9999] min-w-[180px]",children:[r.jsxs(Bl,{onSelect:()=>s(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(su,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Import agent"]}),r.jsxs(Bl,{onSelect:()=>l(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(wm,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Import team"]}),r.jsx(v_e,{className:"h-px bg-[#2A2A35] my-1"}),r.jsxs(Bl,{onSelect:()=>a(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(vv,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Export team"]})]})})]}),r.jsxs(gn,{to:"/agents/new",className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium hover:opacity-90 transition-opacity shadow-lg shadow-[#6366F1]/20",children:[r.jsx(wt,{className:"w-4 h-4"}),"New agent"]})]})]}),d&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[1,2,3].map(m=>r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 animate-pulse h-[180px]"},m))}),!d&&c.length===0&&r.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mb-4 text-2xl",children:"🤖"}),r.jsx("h2",{className:"text-[16px] font-semibold text-[#F0F0F5] mb-2",children:"No agents yet"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mb-6 max-w-xs",children:"Create your first AI agent and it'll be live in under 60 seconds."}),p&&r.jsxs(gn,{to:"/agents/new",className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium hover:opacity-90 transition-opacity",children:[r.jsx(wt,{className:"w-4 h-4"}),"Create agent"]})]}),!d&&c.length>0&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:c.map(m=>r.jsx(eRe,{agent:m,onOpenPanel:t,canManage:p},m.id))})]}),r.jsxs(Me,{children:[e&&r.jsx($N,{agent:e,agentColor:e.color,onClose:()=>t(null),onOverrideSet:()=>t(null)},e.id),n&&r.jsx(HMe,{onClose:()=>s(!1),onSuccess:()=>f.agents.list.invalidate()}),i&&r.jsx(WMe,{onClose:()=>a(!1)}),o&&r.jsx(qMe,{onClose:()=>l(!1),onSuccess:()=>{f.agents.list.invalidate()}})]})]})}const nRe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],sRe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16","#6366F1"],iRe=[{id:"qwen3:14b",label:"Qwen 3 14B",note:"Fast · Local · Free"},{id:"tomng/nanbeige4.1",label:"NanBeige 4.1 · 3B",note:"Agentic · Local · Free"},{id:"anthropic/claude-sonnet-4.6",label:"Claude Sonnet",note:"Smart · Fast · $$$"},{id:"anthropic/claude-opus-4.6",label:"Claude Opus",note:"Best · Slow · $$$$"}];function rRe({color:e,name:t,emoji:n}){const s=uh(e),i=t||"Agent",a=n||"🤖";return r.jsxs("div",{className:"rounded-xl overflow-hidden border border-[#2A2A35] bg-[#0F0F11]",children:[r.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",style:{borderLeft:`3px solid ${e}`,background:`linear-gradient(90deg, rgba(${s}, 0.08) 0%, transparent 60%)`},children:[r.jsx("span",{className:"text-lg",children:a}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:i}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:"online"})]}),r.jsx("div",{className:"ml-auto w-2 h-2 rounded-full",style:{backgroundColor:e}})]}),r.jsx("div",{className:"px-4 py-3",children:r.jsx("div",{className:"rounded-xl px-3 py-2 max-w-[75%]",style:{backgroundColor:`rgba(${s}, 0.12)`,border:`1px solid rgba(${s}, 0.2)`},children:r.jsx("p",{className:"text-[12px] text-[#C8C8D4]",children:"Ready to help. What do you need?"})})})]})}function aRe({state:e,onChange:t,onNext:n}){const s=e.name.trim().length>0&&e.role.trim().length>0;return r.jsxs("div",{className:"flex gap-8 h-full",children:[r.jsxs("div",{className:"flex-1 space-y-6",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Name"}),r.jsx("input",{value:e.name,onChange:i=>t({name:i.target.value}),placeholder:"e.g. Nova, Relay, Axiom",className:"w-full h-10 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[14px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Role"}),r.jsx("input",{value:e.role,onChange:i=>t({role:i.target.value}),placeholder:"e.g. Content Strategist, Research Analyst",className:"w-full h-10 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[14px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Emoji"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:nRe.map(i=>r.jsx("button",{onClick:()=>t({emoji:i}),className:ye("w-9 h-9 rounded-lg text-lg transition-all",e.emoji===i?"bg-[#6366F1]/20 ring-2 ring-[#6366F1] scale-110":"bg-[#1E1E24] hover:bg-[#2A2A35]"),children:i},i))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Color"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:sRe.map(i=>r.jsx("button",{onClick:()=>t({color:i}),className:ye("w-7 h-7 rounded-full transition-all",e.color===i?"ring-2 ring-offset-2 ring-offset-[#0F0F11] scale-125":"hover:scale-110"),style:{backgroundColor:i,outlineColor:i}},i))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Model"}),r.jsx("div",{className:"space-y-2",children:iRe.map(i=>r.jsxs("button",{onClick:()=>t({model:i.id}),className:ye("w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all text-left",e.model===i.id?"bg-[#6366F1]/10 border-[#6366F1]/50 text-[#F0F0F5]":"bg-[#1E1E24] border-[#2A2A35] text-[#8A8A99] hover:border-[#3A3A45] hover:text-[#C8C8D4]"),children:[r.jsx("span",{className:"text-[13px] font-medium",children:i.label}),r.jsx("span",{className:"text-[11px] opacity-60",children:i.note})]},i.id))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Visibility"}),r.jsx("div",{className:"flex gap-2",children:[{value:"public",icon:Xt,label:"Public"},{value:"private",icon:Eo,label:"Private"},{value:"owner",icon:Ia,label:"Owner only"}].map(({value:i,icon:a,label:o})=>r.jsxs("button",{onClick:()=>t({visibility:i}),className:ye("flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-xl border transition-all text-[12px] font-medium",e.visibility===i?"bg-[#6366F1]/10 border-[#6366F1]/50 text-[#F0F0F5]":"bg-[#1E1E24] border-[#2A2A35] text-[#8A8A99] hover:border-[#3A3A45] hover:text-[#C8C8D4]"),children:[r.jsx(a,{className:"w-3 h-3"}),o]},i))})]})]}),r.jsxs("div",{className:"w-[260px] flex-shrink-0 space-y-4",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Preview"}),r.jsx(rRe,{color:e.color,name:e.name,emoji:e.emoji})]}),r.jsxs("button",{onClick:n,disabled:!s,className:"w-full h-10 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium flex items-center justify-center gap-2 hover:opacity-90 transition-opacity disabled:opacity-30 disabled:cursor-not-allowed shadow-lg shadow-[#6366F1]/20",children:["Continue",r.jsx(tu,{className:"w-4 h-4"})]})]})]})}function vW({state:e,soul:t,onSoulChange:n,onNext:s,onBack:i,editMode:a,initialSoul:o}){const[l,c]=y.useState(()=>a&&o?[{role:"assistant",content:`I've loaded ${e.name}'s current soul. What would you like to change? You can say things like "make it more direct", "add a section about how to handle conflicts", or just describe the vibe you want.`}]:[]),[d,f]=y.useState(""),[p,m]=y.useState(!1),[g,b]=y.useState(""),[_,w]=y.useState(a&&!!o),A=y.useRef(null),S=y.useRef(null);y.useEffect(()=>{A.current?.scrollIntoView({behavior:"smooth"})},[l,g]);const C=y.useCallback(async(T,F)=>{m(!0),b("");const M={description:T,agentName:e.name,agentRole:e.role};F&&(M.refinement=F),a&&o&&(M.currentSoul=o);try{const I=await fetch(`${oi}/api/agents/generate-soul`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)});if(!I.ok)throw new Error("Generation failed");const H=(await I.json()).text;n(H),b(""),w(!0),c(V=>[...V,{role:"assistant",content:"Here's the soul I've written. Take a look — you can refine it by telling me what to change, or proceed when you're happy."}])}catch{c(I=>[...I,{role:"assistant",content:"Something went wrong generating the soul. Please try again."}])}finally{m(!1)}},[e.name,e.role,n,a,o]);async function E(){const T=d.trim();if(!T||p)return;f("");const F={role:"user",content:T};c(M=>[...M,F]),_?await C(T,T):await C(T)}const k=uh(e.color);return r.jsxs("div",{className:"flex gap-6 h-full min-h-0",children:[r.jsxs("div",{className:"flex flex-col w-[320px] flex-shrink-0 min-h-0",children:[r.jsxs("div",{className:"flex-1 overflow-y-auto space-y-3 pr-1 min-h-0",children:[l.length===0&&r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`rgba(${k}, 0.2)`},children:e.emoji}),r.jsx("div",{className:"flex-1 bg-[#1E1E24] rounded-xl rounded-tl-sm px-3 py-2.5",children:r.jsxs("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:["I'm going to write ",e.name,"'s soul. Describe their personality in a few sentences. What do they care about? What makes them distinct? What won't they do?"]})})]}),l.map((T,F)=>r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:ye("flex items-start gap-3",T.role==="user"&&"flex-row-reverse"),children:[T.role==="assistant"&&r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`rgba(${k}, 0.2)`},children:e.emoji}),r.jsx("div",{className:ye("flex-1 rounded-xl px-3 py-2.5",T.role==="user"?"bg-[#6366F1]/15 rounded-tr-sm ml-8":"bg-[#1E1E24] rounded-tl-sm mr-8"),children:r.jsx("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:T.content})})]},F)),p&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"flex items-center gap-2 pl-10",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce [animation-delay:0.15s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce [animation-delay:0.3s]"})]}),r.jsx("div",{ref:A})]}),r.jsxs("div",{className:"mt-3 flex gap-2",children:[r.jsx("input",{ref:S,value:d,onChange:T=>f(T.target.value),onKeyDown:T=>T.key==="Enter"&&!T.shiftKey&&E(),placeholder:_?"Refine it…":"Describe their personality…",disabled:p,className:"flex-1 h-9 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors disabled:opacity-50"}),r.jsx("button",{onClick:E,disabled:!d.trim()||p,className:"w-9 h-9 rounded-xl flex items-center justify-center transition-all disabled:opacity-30",style:{backgroundColor:`rgba(${k}, 0.2)`,color:e.color},children:p?r.jsx(Xi,{className:"w-4 h-4 animate-spin"}):r.jsx(Ji,{className:"w-4 h-4"})})]})]}),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#8A8A99] uppercase tracking-wider",children:"SOUL.md preview"}),p&&r.jsx("p",{className:"text-[11px] text-[#8A8A99] animate-pulse",children:"Generating…"})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11] border border-[#2A2A35] rounded-xl p-4 min-h-0",children:[!t&&!g&&!p&&r.jsx("p",{className:"text-[13px] text-[#5A5A6A] italic",children:"The soul will appear here as it's generated…"}),(t||g)&&r.jsx("div",{className:"prose-message text-[12px] text-[#C8C8D4] leading-relaxed",children:r.jsx(Ei,{remarkPlugins:[Fi],children:g||t})})]}),r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 h-9 px-4 rounded-xl border border-[#2A2A35] text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45] transition-colors",children:[r.jsx(gm,{className:"w-4 h-4"}),"Back"]}),r.jsxs("button",{onClick:s,disabled:!t||p,className:"flex-1 h-9 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium flex items-center justify-center gap-2 hover:opacity-90 transition-opacity disabled:opacity-30 disabled:cursor-not-allowed",children:["Looks good",r.jsx(tu,{className:"w-4 h-4"})]})]})]})]})}function oRe({title:e,content:t}){const[n,s]=y.useState(e==="SOUL.md");return r.jsxs("div",{className:"border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>s(i=>!i),className:"w-full flex items-center justify-between px-4 py-3 bg-[#1E1E24] hover:bg-[#2A2A35] transition-colors text-left",children:[r.jsx("span",{className:"text-[13px] font-mono font-medium text-[#C8C8D4]",children:e}),r.jsx(ne.span,{animate:{rotate:n?90:0},transition:{duration:.15},children:r.jsx(tu,{className:"w-3.5 h-3.5 text-[#8A8A99]"})})]}),r.jsx(Me,{children:n&&r.jsx(ne.div,{initial:{height:0},animate:{height:"auto"},exit:{height:0},transition:{duration:.2},className:"overflow-hidden",children:r.jsx("div",{className:"p-4 max-h-48 overflow-y-auto bg-[#0F0F11]",children:r.jsx("div",{className:"prose-message text-[12px] text-[#8A8A99]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:t})})})})})]})}function lRe(e){return`# IDENTITY.md — ${e.name}
|
|
354
|
+
`).map((a,o)=>{let l="text-[#8A8A99]";return a.startsWith("+")&&!a.startsWith("+++")?l="text-[#34D399]":a.startsWith("-")&&!a.startsWith("---")?l="text-[#F87171]":a.startsWith("@@")&&(l="text-[#6366F1]"),r.jsx("div",{className:l,children:a||" "},o)})})})]}):r.jsxs("div",{className:"border-t border-[#2A2A35] p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4]",children:t}),r.jsx("button",{onClick:n,className:"text-[11px] text-[#5A5A6E] hover:text-[#C8C8D4] transition-colors",children:"Close"})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] italic",children:"No changes to display."})]})}function WTe({agentId:e}){const[t,n]=y.useState(new Set),[s,i]=y.useState(null),a=L.useUtils(),{data:o,isLoading:l}=L.git.hasRepo.useQuery({agentId:e}),{data:c,isLoading:d}=L.git.status.useQuery({agentId:e},{enabled:!!o?.hasRepo,refetchInterval:1e4}),{data:f=[]}=L.git.log.useQuery({agentId:e,limit:10},{enabled:!!o?.hasRepo,refetchInterval:3e4}),p=y.useMemo(()=>c?[...c.staged.map(w=>({...w,category:"staged"})),...c.modified.map(w=>({...w,category:"modified"})),...c.untracked.map(w=>({...w,category:"untracked"}))]:[],[c]),m=y.useCallback(w=>{n(A=>{const S=new Set(A);return S.has(w)?S.delete(w):S.add(w),S})},[]),g=y.useCallback(()=>{n(new Set(p.map(w=>w.path)))},[p]),b=y.useCallback(()=>{n(new Set)},[]),_=y.useCallback(()=>{a.git.status.invalidate({agentId:e}),a.git.log.invalidate({agentId:e})},[a,e]);return l?r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Pe,{className:"w-5 h-5 text-[#5A5A6E] animate-spin"})}):o?.hasRepo?r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:[c&&r.jsx(UTe,{agentId:e,currentBranch:c.branch}),r.jsx("button",{onClick:_,className:"p-1.5 rounded-md text-[#5A5A6E] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors",title:"Refresh",children:r.jsx(Xi,{className:ye("w-3.5 h-3.5",d&&"animate-spin")})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[r.jsx("div",{className:"px-3 pt-2",children:r.jsx(LTe,{agentId:e})}),d&&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]"})]}),!d&&p.length===0&&f.length===0&&r.jsx("p",{className:"px-4 py-4 text-[12px] text-[#5A5A6E] italic",children:"Working tree clean. No changes."}),p.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:["Changes (",p.length,")"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:g,className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"All"}),r.jsx("button",{onClick:b,className:"text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"None"})]})]}),c?.staged&&c.staged.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#10B981] uppercase tracking-widest",children:"Staged"}),c.staged.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!0,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`staged-${w.path}`))]}),c?.modified&&c.modified.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#F59E0B] uppercase tracking-widest",children:"Modified"}),c.modified.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!1,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`modified-${w.path}`))]}),c?.untracked&&c.untracked.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:"Untracked"}),c.untracked.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!1,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`untracked-${w.path}`))]})]}),f.length>0&&r.jsxs("div",{className:"mt-2",children:[r.jsx("p",{className:"px-3 py-1.5 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest border-t border-[#2A2A35]/50",children:"Recent commits"}),f.map(w=>r.jsxs("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-white/[0.02] transition-colors",children:[r.jsx(Hse,{className:"w-2 h-2 text-[#5A5A6E] mt-1 flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] text-[#C8C8D4] truncate",children:w.message}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:[r.jsx("code",{className:"text-[#6366F1]",children:w.shortHash}),r.jsx("span",{className:"mx-1",children:"·"}),w.author,r.jsx("span",{className:"mx-1",children:"·"}),r.jsx(BTe,{date:w.date})]})]})]},w.hash))]})]}),s&&r.jsx(HTe,{agentId:e,filePath:s,onClose:()=>i(null)}),p.length>0&&r.jsx(VTe,{agentId:e,selectedFiles:[...t],onCommitted:()=>{n(new Set),_()}})]}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-5 gap-2",children:[r.jsx(Zl,{className:"w-8 h-8 text-[#3A3A45]"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic text-center",children:"No git repository detected"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] text-center",children:"Mount a project directory with a git repo in Settings → File Access."})]})}function qTe(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const s=Math.floor(n/60);if(s<60)return`${s} min ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function GTe(e){return new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function KTe(e){const t=new Date(e).getTime()-Date.now();if(t<=0)return"eligible now";const n=Math.floor(t/(3600*1e3)),s=Math.floor(t%(3600*1e3)/(60*1e3));return n>0?`~${n}h ${s}m`:`~${s}m`}function YTe({agentId:e}){const{data:t}=L.dream.status.useQuery({agentId:e},{staleTime:3e4}),n=t?.[e];return n?r.jsxs("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(_L,{className:"w-3.5 h-3.5 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5]",children:"Dream Status"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-y-1.5 text-[11px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Last dream"}),r.jsx("span",{className:"text-[#C8C8D4]",children:qTe(n.lastDreamAt)}),r.jsx("span",{className:"text-[#8A8A99]",children:"Notes changed"}),r.jsx("span",{className:"text-[#C8C8D4]",children:n.lastDreamNotesChanged}),r.jsx("span",{className:"text-[#8A8A99]",children:"Cost"}),r.jsxs("span",{className:"text-[#10B981]",children:["$",n.lastDreamCostUsd.toFixed(4)]}),r.jsx("span",{className:"text-[#8A8A99]",children:"Next eligible"}),r.jsx("span",{className:"text-[#C8C8D4]",children:KTe(n.nextDreamEstimate)})]})]}):r.jsx("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:r.jsx("p",{className:"text-[12px] text-[#5A5A6E] italic",children:"No dream data yet. Trigger a dream to start memory consolidation."})})}function QTe({preferences:e}){return e.length===0?null:r.jsxs("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#F0F0F5] mb-2",children:"Routing Preferences"}),r.jsx("div",{className:"space-y-2",children:e.map((t,n)=>r.jsxs("div",{className:"flex items-start gap-2 text-[11px]",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[#C8C8D4]",children:t.taskPattern}),r.jsxs("p",{className:"text-[#5A5A6E] mt-0.5",children:["→ ",t.preferredAgentId," — ",t.reason]})]}),r.jsxs("span",{className:`flex-shrink-0 px-1.5 py-0.5 rounded text-[10px] font-medium ${t.confidence>=.8?"bg-[#10B981]/15 text-[#10B981]":t.confidence>=.5?"bg-[#F59E0B]/15 text-[#F59E0B]":"bg-[#EF4444]/15 text-[#EF4444]"}`,children:[(t.confidence*100).toFixed(0),"%"]})]},n))})]})}function XTe({entries:e}){return e.length===0?r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4 text-center italic",children:"No dream history."}):r.jsxs("div",{className:"relative",children:[e.length>0&&r.jsx("div",{className:"absolute left-[9px] top-0 bottom-0 w-px bg-[#2A2A35]"}),r.jsx("div",{className:"space-y-0",children:e.map(t=>r.jsxs("div",{className:"flex gap-3 py-2.5 relative",children:[r.jsx("div",{className:"w-5 h-5 rounded-full bg-[#1C1C24] border border-[#2A2A35] flex items-center justify-center text-[10px] flex-shrink-0 z-10 mt-0.5",children:"💤"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("p",{className:"text-[12px] text-[#C8C8D4] leading-snug",children:["+",t.notesAdded," added · ",t.notesMerged," merged · ",t.notesPruned," pruned",t.constraintsFlagged.length>0&&r.jsxs("span",{className:"text-[#F59E0B]",children:[" · ",t.constraintsFlagged.length," flagged"]})]}),t.constraintsFlagged.length>0&&r.jsx("div",{className:"mt-1 space-y-0.5",children:t.constraintsFlagged.map((n,s)=>r.jsxs("p",{className:"text-[10px] text-[#F59E0B]/80",children:["⚠ ",n]},s))}),t.agentHealthNotes&&t.agentHealthNotes.length>0&&r.jsx("div",{className:"mt-1 space-y-0.5",children:t.agentHealthNotes.map((n,s)=>r.jsxs("p",{className:"text-[10px] text-[#8A8A99]",children:[n.agentId,": ",n.observation]},s))}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:[GTe(t.ts),t.durationMs!=null&&` · ${Math.round(t.durationMs/1e3)}s`,t.costEstimateUsd>0&&` · $${t.costEstimateUsd.toFixed(4)}`]})]})]},t.id))})]})}function JTe({agentId:e}){const[t,n]=y.useState(!1),{data:s=[],isLoading:i}=L.dream.history.useQuery({agentId:e,limit:20},{refetchInterval:3e4}),a=L.useUtils(),o=y.useRef(0);o.current=s.length;const l=L.dream.trigger.useMutation({onSuccess:f=>{if(!f.started){n(!1);return}const p=o.current,m=setInterval(async()=>{await a.dream.history.invalidate({agentId:e}),await a.dream.status.invalidate({agentId:e});const g=a.dream.history.getData({agentId:e,limit:20});g&&g.length>p&&(clearInterval(m),n(!1))},4e3);setTimeout(()=>{clearInterval(m),n(!1)},12e4)},onError:()=>n(!1)}),c=e==="coo",d=c?s.find(f=>f.routingPreferences&&f.routingPreferences.length>0)?.routingPreferences??[]:[];return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[r.jsx(YTe,{agentId:e}),c&&d.length>0&&r.jsx(QTe,{preferences:d}),r.jsxs("div",{className:"px-4 mt-3 flex-shrink-0",children:[r.jsxs("button",{onClick:()=>{n(!0),l.mutate({agentId:e})},disabled:t||l.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#6366F1] text-white hover:bg-[#5558E6] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[t||l.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(_L,{className:"w-3 h-3"}),t?"Dreaming...":"Trigger Dream"]}),l.data&&!l.data.started&&r.jsx("p",{className:"text-[10px] text-[#F59E0B] mt-1",children:l.data.reason})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-4 mt-3",children:[i&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4 text-center",children:"Loading..."}),!i&&r.jsx(XTe,{entries:s})]})]})}const ZTe=["complexity:low","complexity:medium","complexity:high","task:code","task:creative","task:analysis","task:tool_use"];function Gb({value:e,onChange:t,customModels:n=[],agentId:s}){const[i,a]=y.useState(""),o=L.useUtils(),l=L.agents.addCustomModel.useMutation({onSuccess:()=>o.agents.list.invalidate()}),c=L.agents.removeCustomModel.useMutation({onSuccess:()=>o.agents.list.invalidate()}),{groups:d}=Vm(),f=Up(e);return r.jsxs(ss,{value:e,onValueChange:t,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors min-w-[140px]",children:[r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[f]}`,children:f}),r.jsx(Ds,{children:ta(e)}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] max-h-[280px] overflow-y-auto z-[9999]",children:[s&&r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:i,onChange:a,onSubmit:p=>{s&&(l.mutate({agentId:s,modelId:p}),t(p),a(""))},placeholder:"Type model ID..."})}),r.jsxs(os,{children:[d.map(p=>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:p.label}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo[p.tag]}`,children:p.tag})]}),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 hover:bg-white/5 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)),n.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"})]}),n.map(p=>r.jsxs(vn,{value:p,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}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})}),s&&r.jsx(bt,{label:"Remove model",children:r.jsx("button",{onClick:m=>{m.stopPropagation(),c.mutate({agentId:s,modelId:p})},className:"text-[#5A5A6E] hover:text-[#F87171] transition-colors",children:r.jsx(Te,{className:"w-3 h-3"})})})]})]},p))]})]})]})})]})}function eMe({value:e,onChange:t}){return r.jsxs(ss,{value:e,onValueChange:t,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors min-w-[150px]",children:[r.jsx(Ds,{children:e}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),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-[170px] z-[9999]",children:r.jsx(os,{children:ZTe.map(n=>r.jsxs(vn,{value:n,className:"flex items-center justify-between px-3 py-2 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:n}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},n))})})})]})}function tMe(e,t){if(t.length===0)return`Always uses ${ta(e)}.`;const n=t.map(s=>`For ${s.condition} → ${ta(s.model)}`);return n.push(`For everything else → ${ta(e)}`),n.join(". ")+"."}function nMe({fallbacks:e,onAdd:t,onRemove:n,customModels:s,agentId:i}){const[a,o]=y.useState(!1),[l,c]=y.useState("");function d(){l&&(t(l),c(""),o(!1))}return r.jsxs("div",{className:"space-y-2",children:[e.map((f,p)=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-[11px] text-[#5A5A6E] w-4 flex-shrink-0",children:[p+1,"."]}),r.jsx("span",{className:"flex-1 text-[12px] text-[#C8C8D4] truncate",children:ta(f)}),r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[Up(f)]}`,children:Up(f)}),r.jsx("button",{onClick:()=>n(p),className:"w-5 h-5 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Te,{className:"w-3 h-3"})})]},p)),a?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Gb,{value:l||"qwen3:14b",onChange:c,customModels:s,agentId:i}),r.jsx("button",{onClick:d,className:"text-[11px] text-[#10B981] hover:text-[#34D399] font-medium transition-colors",children:"Add"}),r.jsx("button",{onClick:()=>o(!1),className:"text-[11px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Cancel"})]}):r.jsxs("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add fallback"]})]})}const sMe=[{id:"__default__",label:"Workspace default"},{id:"openclaw",label:"OpenClaw"},{id:"anthropic",label:"Anthropic"},{id:"claude-code",label:"Claude Code"},{id:"ollama",label:"Ollama"},{id:"openrouter",label:"OpenRouter"}];function iMe({agentId:e}){const{data:t}=L.agents.getGateway.useQuery({agentId:e}),n=L.useUtils(),s=L.agents.setGateway.useMutation({onSuccess:()=>n.agents.getGateway.invalidate({agentId:e})}),i=t?.gatewayId||"__default__";return r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Runtime"}),r.jsxs(ss,{value:i,onValueChange:a=>s.mutate({agentId:e,gatewayId:a==="__default__"?null:a}),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] hover:bg-[#2A2A35] transition-colors",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:sMe.map(a=>r.jsxs(vn,{value:a.id,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:a.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"})})]},a.id))})})})]})]})}function rMe({agent:e,agentColor:t}){const{data:n}=L.onboarding.getState.useQuery(void 0,{staleTime:3e4,refetchOnWindowFocus:!1}),s=(()=>{try{return e.customModels?JSON.parse(e.customModels):[]}catch{return[]}})(),i=s[0]??null,a=n?.defaultReasoningModel??i??"qwen3:14b",o=!e.defaultModel&&!n?.defaultReasoningModel,[l,c]=y.useState(e.defaultModel??a),[d,f]=y.useState(()=>{try{return e.modelRules?JSON.parse(e.modelRules):[]}catch{return[]}}),p=s,[m,g]=y.useState("idle"),b=y.useRef(null),_=L.useUtils(),w=L.agents.setModelConfig.useMutation({onSuccess:()=>{_.agents.list.invalidate(),_.agents.getFallbackModels.invalidate({agentId:e.id})}}),A=e.gatewayId??n?.gatewayType??"openclaw",S=A==="openclaw"||A==="openrouter",{data:C}=L.agents.getFallbackModels.useQuery({agentId:e.id},{enabled:S}),[E,k]=y.useState(null),T=E??C?.agent??[],F=C?.defaults??[],M=T.length===0&&F.length>0,[I,R]=y.useState(e.fallbackModel??null);y.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const H=[{label:"Local",description:"Free · Fully offline",defaultModel:"qwen3:14b",rules:[{condition:"task:tool_use",model:"tomng/nanbeige4.1"}]},{label:"Hybrid",description:"Smart routing · Best bang for buck",defaultModel:"qwen3:14b",rules:[{condition:"task:tool_use",model:"tomng/nanbeige4.1"},{condition:"task:code",model:"claude-sonnet-4.6"},{condition:"complexity:high",model:"claude-opus-4.6"}]}];function V(W){c(W.defaultModel),f(W.rules)}function K(){f(W=>[...W,{condition:"complexity:high",model:"claude-sonnet-4.6"}])}function q(W){f(O=>O.filter((D,Q)=>Q!==W))}function $(W,O){f(D=>D.map((Q,z)=>z===W?{...Q,...O}:Q))}function B(W){k([...T,W])}function Y(W){k(T.filter((O,D)=>D!==W))}async function U(){g("saving"),await w.mutateAsync({agentId:e.id,defaultModel:l,modelRules:d,customModels:p,...S?{fallbackModels:E??void 0}:{fallbackModel:I}}),g("saved"),k(null),b.current=setTimeout(()=>g("idle"),2e3)}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-4 overflow-y-auto",children:[o&&r.jsx("div",{className:"flex items-start gap-2 px-3 py-2.5 rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20",children:r.jsx("span",{className:"text-[#F59E0B] text-[13px] leading-snug",children:"No model configured. Visit Settings → Models to set one."})}),r.jsx(iMe,{agentId:e.id}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Default Model"}),r.jsx(Gb,{value:l,onChange:c,customModels:p,agentId:e.id})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Presets"}),r.jsx("div",{className:"flex gap-2",children:H.map(W=>r.jsxs("button",{onClick:()=>V(W),className:"flex-1 rounded-lg border border-[#2A2A35] bg-[#1C1C21] hover:bg-[#2A2A35] transition-colors px-3 py-2 text-left",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#F0F0F5]",children:W.label}),r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:W.description})]},W.label))})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Routing Rules"}),r.jsx("div",{className:"space-y-2",children:d.map((W,O)=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(eMe,{value:W.condition,onChange:D=>$(O,{condition:D})}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E] flex-shrink-0",children:"→"}),r.jsx(Gb,{value:W.model,onChange:D=>$(O,{model:D}),customModels:p,agentId:e.id}),r.jsx(bt,{label:"Remove rule",children:r.jsx("button",{onClick:()=>q(O),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]},O))}),r.jsxs("button",{onClick:K,className:"mt-3 flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add rule"]})]}),S?r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Fallback Models"})]}),M&&T.length===0&&r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] mb-2",children:["Inheriting from defaults: ",F.map(ta).join(", ")]}),r.jsx(nMe,{fallbacks:T,onAdd:B,onRemove:Y,customModels:p,agentId:e.id}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-2",children:["Handled natively by ",A==="openclaw"?"OpenClaw":"OpenRouter","."]})]}):r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Fallback Model"})]}),I?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Gb,{value:I,onChange:W=>R(W),customModels:p,agentId:e.id}),r.jsx(bt,{label:"Remove fallback",children:r.jsx("button",{onClick:()=>R(null),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})})]}):r.jsxs("button",{onClick:()=>R(l),className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add fallback"]}),r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-2",children:"Used when the primary model is rate-limited or unavailable."})]}),r.jsx("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] px-3 py-2.5",children:r.jsx("p",{className:"text-[11px] text-[#8A8A99] italic leading-relaxed",children:tMe(l,d)})}),r.jsx("button",{onClick:U,disabled:w.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium transition-colors disabled:opacity-50",style:{backgroundColor:t,color:"#fff"},children:r.jsxs(Me,{mode:"wait",children:[m==="saving"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saving..."},"saving"),m==="saved"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved ✓"},"saved"),m==="idle"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")]})})]})}const aMe={"Be brief":"Keep all responses under 3 sentences. Be direct.","Be creative":"Be imaginative, use analogies, think laterally.","Be strict":"Only respond with facts. No speculation. Cite reasoning."};function mW(e,t=500){const[n,s]=y.useState("idle"),i=y.useRef(null),a=y.useRef(null);y.useEffect(()=>()=>{i.current&&clearTimeout(i.current),a.current&&clearTimeout(a.current)},[]);const o=y.useCallback(l=>{l!==void 0&&(i.current&&clearTimeout(i.current),a.current&&clearTimeout(a.current),s("saving"),i.current=setTimeout(async()=>{await e(l),s("saved"),a.current=setTimeout(()=>s("idle"),2e3)},t))},[e,t]);return{saveState:n,handleChange:o}}function xW({saveState:e}){return r.jsxs(Me,{mode:"wait",children:[e==="saving"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[11px] text-[#8A8A99]",children:"Saving..."},"saving"),e==="saved"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[11px] text-[#10B981]",children:"Saved ✓"},"saved")]})}const Q8={gateway:{label:"Gateway",color:"#3B82F6"},harness:{label:"Claude Code",color:"#8B5CF6"},terminal:{label:"Terminal",color:"#10B981"}};function oMe({agentId:e}){const{data:t}=L.events.activeRuntimes.useQuery({agentId:e},{staleTime:3e4,refetchInterval:3e4});return!t||t.length===0?null:r.jsx("div",{className:"flex items-center gap-1 ml-1",children:t.map(n=>{const s=Q8[n.source]??Q8.gateway,a=`Last active ${lMe(n.lastActiveAt)}${n.project?` via ${s.label} on ${n.project}`:` via ${s.label}`}`;return r.jsx(bt,{label:a,side:"bottom",children:r.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:s.color}})},n.source)})})}function lMe(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const s=Math.floor(n/60);if(s<60)return`${s} min ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function cMe({status:e,color:t}){const n=e==="thinking"||e==="executing";return r.jsxs("span",{className:"relative flex items-center justify-center w-2 h-2",children:[n&&r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:t,opacity:.5},animate:{scale:[1,2.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}})]})}function uMe({agentId:e}){const{data:t}=L.agents.getSoul.useQuery({agentId:e}),n=L.agents.saveSoul.useMutation(),{saveState:s,handleChange:i}=mW(y.useCallback(a=>n.mutateAsync({agentId:e,content:a}),[e,n]));return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-visible",children:[r.jsx("div",{className:"flex items-center justify-end h-7 px-3 flex-shrink-0",children:r.jsx(xW,{saveState:s})}),r.jsx("div",{className:"flex-1 min-h-0",children:t?.content!==void 0&&r.jsx(VU,{height:"100%",defaultLanguage:"markdown",defaultValue:t.content??"",theme:"vs-dark",onChange:i,options:{minimap:{enabled:!1},wordWrap:"on",lineNumbers:"off",fontSize:13,scrollBeyondLastLine:!1,padding:{top:8,bottom:16},automaticLayout:!0,fixedOverflowWidgets:!0}})})]})}function dMe({agentId:e}){const{data:t}=L.agents.getTeam.useQuery({agentId:e}),n=L.agents.saveTeam.useMutation(),{saveState:s,handleChange:i}=mW(y.useCallback(a=>n.mutateAsync({agentId:e,content:a}),[e,n]));return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-visible",children:[r.jsx("div",{className:"flex items-center justify-end h-7 px-3 flex-shrink-0",children:r.jsx(xW,{saveState:s})}),r.jsx("div",{className:"flex-1 min-h-0",children:t?.content!==void 0&&r.jsx(VU,{height:"100%",defaultLanguage:"markdown",defaultValue:t.content??"",theme:"vs-dark",onChange:i,options:{minimap:{enabled:!1},wordWrap:"on",lineNumbers:"off",fontSize:13,scrollBeyondLastLine:!1,padding:{top:8,bottom:16},automaticLayout:!0,fixedOverflowWidgets:!0}})})]})}const hMe={healthy:"#10B981",degraded:"#F59E0B",failing:"#EF4444"};function fMe({health:e,detail:t}){const[n,s]=y.useState(!1),i=hMe[e.health]??"#5A5A6E";return r.jsxs("span",{className:"relative",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[r.jsx("span",{className:"inline-block w-2 h-2 rounded-full",style:{backgroundColor:i}}),n&&r.jsx("span",{className:"absolute top-full left-0 mt-1.5 px-2 py-1 rounded bg-[#1C1C24] border border-[#2A2A35] text-[10px] text-[#C8C8D4] whitespace-nowrap z-50 shadow-lg",children:t})]})}function pMe({agentId:e}){const{data:t=[]}=L.skills.getAgentSkills.useQuery({agentId:e}),{data:n={}}=L.events.skillHealth.useQuery({agentId:e},{refetchInterval:3e4}),{data:s={}}=L.events.skillComposition.useQuery({agentId:e},{refetchInterval:6e4}),i=L.useUtils(),a=L.skills.toggleAgentSkill.useMutation({onMutate:async({agentId:d,skillId:f,enabled:p})=>{await i.skills.getAgentSkills.cancel({agentId:d});const m=i.skills.getAgentSkills.getData({agentId:d});return i.skills.getAgentSkills.setData({agentId:d},g=>g&&g.map(b=>b.skillId===f?{...b,enabled:p}:b)),{prev:m}},onError:(d,{agentId:f},p)=>{p?.prev&&i.skills.getAgentSkills.setData({agentId:f},p.prev)}});if(t.length===0)return r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-5 gap-2",children:[r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No skills installed for this agent."}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"Go to Skills to install and assign."})]});const o=t.every(d=>d.enabled);function l(){const d=!o;t.forEach(f=>a.mutate({agentId:e,skillId:f.skillId,enabled:d}))}const c=new Map(t.map(d=>[d.skill.slug,d.skill.name]));return r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:[t.length," skill",t.length!==1?"s":""]}),r.jsx("button",{onClick:l,className:"text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:o?"Disable all":"Enable all"})]}),t.map(d=>{const f=n[d.skill.id]??n[d.skill.slug]??n[d.skill.name],p=s[d.skill.id]??s[d.skill.slug]??s[d.skill.name],m=f?`${f.successCount}/${f.totalCount} succeeded${f.avgDurationMs!=null?` · avg ${f.avgDurationMs}ms`:""}`:void 0;return r.jsxs("div",{className:"py-2.5 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[f&&r.jsx(fMe,{health:f,detail:m}),r.jsx("span",{className:"text-[13px] transition-all",style:{color:d.enabled?"#C8C8D4":"#5A5A6E",textDecoration:d.enabled?"none":"line-through"},children:d.skill.name})]}),r.jsx(Sh,{checked:d.enabled,onCheckedChange:g=>a.mutate({agentId:e,skillId:d.skillId,enabled:g}),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]",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"})})]}),p&&p.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-1 ml-4",children:["Used together with ",p.map(g=>c.get(g)??g).join(", ")]})]},d.skillId)})]})}function mMe({agentId:e,onOverrideSet:t,onClose:n}){const{data:s}=L.agents.getOverride.useQuery({agentId:e}),i=L.agents.setOverride.useMutation(),[a,o]=y.useState("");y.useEffect(()=>{s?.override!==void 0&&o(s.override??"")},[s?.override]);async function l(){await i.mutateAsync({agentId:e,instruction:a}),t(a.trim()||null),n()}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-3",children:[r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[Object.entries(aMe).map(([c,d])=>r.jsx("button",{onClick:()=>o(d),className:"px-3 py-1 rounded-md text-[12px] bg-white/5 text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-[#2A2A35] hover:border-[#3A3A45]",children:c},c)),r.jsx("button",{onClick:()=>o(""),className:"px-3 py-1 rounded-md text-[12px] bg-white/5 text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-[#2A2A35] hover:border-[#3A3A45]",children:"Clear"})]}),r.jsx("textarea",{value:a,onChange:c=>o(c.target.value),rows:5,placeholder:"Add a temporary instruction for this session...",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2.5 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] resize-none outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("button",{onClick:l,disabled:i.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:"Set Override"})]})}const xMe=[{value:"15m",label:"Every 15 minutes"},{value:"30m",label:"Every 30 minutes"},{value:"1h",label:"Every hour"},{value:"3h",label:"Every 3 hours"},{value:"6h",label:"Every 6 hours"},{value:"12h",label:"Every 12 hours"},{value:"1d",label:"Daily"},{value:"2d",label:"Every 2 days"},{value:"7d",label:"Weekly"},{value:"custom",label:"Custom…"}];function gMe(e){return!e||e==="24h"?"1d@09:00":e==="48h"?"2d@09:00":e}function bMe(e){const t={preset:"1d",customValue:4,customUnit:"h",utcHour:9,utcMinute:0};if(e==="15m")return{...t,preset:"15m"};if(e==="30m")return{...t,preset:"30m"};const n=e.match(/^(\d+)h$/);if(n){const i=parseInt(n[1],10),a={1:"1h",3:"3h",6:"6h",12:"12h"};return a[i]?{...t,preset:a[i]}:{...t,preset:"custom",customValue:i,customUnit:"h"}}const s=e.match(/^(\d+)d@(\d{1,2}):(\d{2})$/);if(s){const i=parseInt(s[1],10),a=parseInt(s[2],10),o=parseInt(s[3],10);return{preset:{1:"1d",2:"2d",7:"7d"}[i]??"custom",customValue:i,customUnit:"d",utcHour:a,utcMinute:o}}return t}function vMe(e){return e.preset==="15m"||e.preset==="30m"||e.preset==="1h"||e.preset==="3h"||e.preset==="6h"||e.preset==="12h"?e.preset:e.preset==="1d"?`1d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="2d"?`2d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="7d"?`7d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="custom"?e.customUnit==="d"?`${e.customValue}d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:`${e.customValue}${e.customUnit}`:"1d@09:00"}function yMe(e,t){return e==="1d"||e==="2d"||e==="7d"||e==="custom"&&t==="d"}function gW(e,t){const n=new Date;return n.setUTCHours(e,t,0,0),{hour:n.getHours(),minute:n.getMinutes()}}function _Me(e,t){const n=new Date;return n.setHours(e,t,0,0),{hour:n.getUTCHours(),minute:n.getUTCMinutes()}}function wMe(e){if(e.preset==="custom"){if(e.customUnit==="m")return`Runs every ${e.customValue} minute${e.customValue===1?"":"s"}`;if(e.customUnit==="h")return`Runs every ${e.customValue} hour${e.customValue===1?"":"s"}`;const t=gW(e.utcHour,e.utcMinute);return`Runs every ${e.customValue} day${e.customValue===1?"":"s"} at ${String(t.hour).padStart(2,"0")}:${String(t.minute).padStart(2,"0")} local`}return""}function AMe({agentId:e}){const{data:t,refetch:n,isLoading:s}=L.agents.terminalInsights.useQuery({agentId:e}),i=L.agents.compactTerminalKnowledge.useMutation({onSuccess:()=>n()}),a=L.agents.clearTerminalKnowledge.useMutation({onSuccess:()=>n()}),o=t?.content??"";return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-4 overflow-auto",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Terminal Insights"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>i.mutate({agentId:e}),disabled:i.isPending,className:"px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:i.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):"Compact now"}),o&&r.jsx("button",{onClick:()=>a.mutate({agentId:e}),disabled:a.isPending,className:"px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#2A2A35] hover:bg-[#3A3A4E] text-[#C8C8D4] transition-colors disabled:opacity-50",children:a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):"Clear"})]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:"Terminal session summaries are stored in daily memory files. Compacting extracts lasting patterns into KNOWLEDGE.md."}),s?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Pe,{className:"w-5 h-5 animate-spin text-[#5A5A6E]"})}):o?r.jsx("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-lg p-4 text-[12px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap font-mono",children:o}):r.jsx("div",{className:"text-center py-8 text-[12px] text-[#5A5A6E]",children:"No terminal insights yet. Assign an agent to a terminal, run some commands, then compact."})]})}function SMe({agentId:e}){const{data:t}=L.agents.getHeartbeat.useQuery({agentId:e}),n=L.agents.setHeartbeat.useMutation(),[s,i]=y.useState(!1),[a,o]=y.useState("1d"),[l,c]=y.useState(4),[d,f]=y.useState("h"),[p,m]=y.useState(9),[g,b]=y.useState(0),[_,w]=y.useState("idle"),[A,S]=y.useState(null),C=y.useRef(null);y.useEffect(()=>{if(t){i(t.enabled);const I=bMe(gMe(t.every));o(I.preset),c(I.customValue),f(I.customUnit);const R=gW(I.utcHour,I.utcMinute);m(R.hour),b(R.minute)}},[t]),y.useEffect(()=>()=>{C.current&&clearTimeout(C.current)},[]);const E=yMe(a,d),k=y.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"local"}},[]),T=y.useMemo(()=>{const I=_Me(p,g),R={preset:a,customValue:l,customUnit:d,utcHour:I.hour,utcMinute:I.minute};return{every:vMe(R),description:wMe(R)}},[a,l,d,p,g]);async function F(){S(null);try{await n.mutateAsync({agentId:e,enabled:s,every:T.every}),w("saved"),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>w("idle"),2e3)}catch(I){w("error"),S(I instanceof Error?I.message:"Failed to save")}}const M=a!=="custom"||(d==="m"?l>=1&&l<=59:d==="h"?l>=1&&l<=23:l>=1&&l<=7);return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[13px] text-[#F0F0F5]",children:"Heartbeat"}),r.jsx(Sh,{checked:s,onCheckedChange:i,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]",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"})})]}),s&&r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Frequency"}),r.jsxs(ss,{value:a,onValueChange:I=>o(I),children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors w-full",children:[r.jsx(Ds,{}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),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-[200px] max-h-[280px] overflow-y-auto z-[9999]",children:r.jsx(os,{children:xMe.map(I=>r.jsxs(vn,{value:I.value,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:I.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},I.value))})})})]})]}),a==="custom"&&r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Every"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:1,max:d==="m"?59:d==="h"?23:7,value:l,onChange:I=>c(Math.max(1,parseInt(I.target.value||"1",10))),className:"w-20 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors"}),r.jsxs(ss,{value:d,onValueChange:I=>f(I),children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors flex-1",children:[r.jsx(Ds,{}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),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-[140px] z-[9999]",children:r.jsx(os,{children:[{v:"m",label:"minutes"},{v:"h",label:"hours"},{v:"d",label:"days"}].map(I=>r.jsxs(vn,{value:I.v,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:I.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},I.v))})})})]})]}),!M&&r.jsx("p",{className:"text-[11px] text-[#F25757]",children:d==="m"?"Minutes must be 1–59":d==="h"?"Hours must be 1–23":"Days must be 1–7"})]}),E&&r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Time of day"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:0,max:23,value:p,onChange:I=>m(Math.max(0,Math.min(23,parseInt(I.target.value||"0",10)))),className:"w-16 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors text-center"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6E]",children:":"}),r.jsx("input",{type:"number",min:0,max:59,value:g,onChange:I=>b(Math.max(0,Math.min(59,parseInt(I.target.value||"0",10)))),className:"w-16 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors text-center"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:k})]})]})]}),r.jsxs("p",{className:"text-[12px] text-[#5A5A6E] leading-relaxed",children:["When active, your agent runs its HEARTBEAT.md at this interval — reviewing memory, running research loops, and evolving over time.",E&&r.jsxs(r.Fragment,{children:[r.jsx("br",{}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"Note: time is stored in UTC. Daylight saving changes may shift local display by ±1 hour."})]})]}),A&&_==="error"&&r.jsx("p",{className:"text-[11px] text-[#F25757]",children:A}),r.jsx("button",{onClick:F,disabled:n.isPending||s&&!M,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:r.jsx(Me,{mode:"wait",children:_==="saved"?r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved ✓"},"saved"):r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")})})]})}function CMe({agentId:e}){const t=L.agents.getTrust.useQuery({agentId:e}),n=L.agents.getSandboxOverride.useQuery({agentId:e}),s=L.agents.getMounts.useQuery({agentId:e}),i=L.agents.setAutoApprove.useMutation({onSuccess:()=>t.refetch()}),a=L.agents.setShellAllowlist.useMutation({onSuccess:()=>t.refetch()}),o=L.agents.setSandboxOverride.useMutation({onSuccess:()=>n.refetch()}),l=L.agents.addMount.useMutation({onSuccess:()=>s.refetch()}),c=L.agents.removeMount.useMutation({onSuccess:()=>s.refetch()}),[d,f]=y.useState(!1),[p,m]=y.useState(!1),[g,b]=y.useState(""),[_,w]=y.useState(!1),[A,S]=y.useState(""),[C,E]=y.useState(""),T=L.agents.getRunMode.useQuery().data?.mode==="docker";y.useEffect(()=>{t.data&&(b(t.data.shellAllowlist?t.data.shellAllowlist.join(", "):""),w(!1))},[t.data]);const F=t.data?.autoApprove??!1;function M(B){B?(f(!0),m(!0)):i.mutate({agentId:e,enabled:!1})}function I(){i.mutate({agentId:e,enabled:!0}),m(!1),f(!1)}function R(){m(!1),f(!1)}function H(B){b(B),w(!0)}function V(){const B=g.trim(),Y=B?B.split(",").map(U=>U.trim()).filter(Boolean):null;a.mutate({agentId:e,allowlist:Y}),w(!1)}function K(B){B.preventDefault(),!(!A.trim()||!C.trim())&&(l.mutate({agentId:e,hostPath:A.trim(),agentPath:C.trim()}),S(""),E(""))}const q=n.data?.mode??"inherit",$=n.data?.globalDefault??"non-main";return r.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-6",children:[r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Auto-approve"}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:"Skip confirmation prompts"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Execute all actions without asking"})]}),r.jsx(Sh,{checked:d||F,onCheckedChange:M,disabled:i.isPending,className:"w-9 h-5 rounded-full bg-[#2A2A35] data-[state=checked]:bg-[#EF4444] transition-colors outline-none cursor-pointer",children:r.jsx(Ch,{className:"block w-4 h-4 bg-white rounded-full shadow transition-transform translate-x-0.5 data-[state=checked]:translate-x-[18px]"})})]}),r.jsx(Me,{children:p&&r.jsxs(ne.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:"rounded-lg border border-[#EF4444]/40 bg-[#EF4444]/10 p-3 space-y-3",children:[r.jsx("p",{className:"text-[12px] text-[#FCA5A5] leading-relaxed",children:"This agent will execute all actions without asking for confirmation. Only enable for read-only agents or dedicated machines you fully control."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:I,className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#EF4444] hover:bg-[#DC2626] text-white transition-colors",children:"Enable anyway"}),r.jsx("button",{onClick:R,className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]})})]}),r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Sandbox"}),r.jsx("div",{className:"flex gap-1.5",children:["inherit","on","off"].map(B=>r.jsx("button",{onClick:()=>o.mutate({agentId:e,mode:B}),disabled:o.isPending,className:`flex-1 py-1.5 rounded-md text-[12px] font-medium transition-colors ${q===B?"bg-[#6366F1] text-white":"bg-[#1C1C21] border border-[#2A2A35] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45]"}`,children:B==="inherit"?`Inherit (${$==="non-main"?"sandboxed":"off"})`:B==="on"?"Sandboxed":"Unsandboxed"},B))})]}),r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Shell allowlist"}),r.jsx("input",{type:"text",value:g,onChange:B=>H(B.target.value),placeholder:"All commands allowed",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Comma-separated command names, e.g. git, npm, ls"}),_&&r.jsx("button",{onClick:V,disabled:a.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:"Save allowlist"})]}),T&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Filesystem mounts"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Mounting a directory gives this agent read/write access to those files."}),s.data&&s.data.length>0&&r.jsx("div",{className:"space-y-1.5",children:s.data.map(B=>r.jsxs("div",{className:"flex items-center gap-2 bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] truncate",children:B.hostPath}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:["→ ",B.agentPath]})]}),r.jsx("button",{onClick:()=>c.mutate({mountId:B.id}),disabled:c.isPending,className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})]},B.id))}),r.jsxs("form",{onSubmit:K,className:"space-y-2",children:[r.jsx("input",{type:"text",value:A,onChange:B=>S(B.target.value),placeholder:"Host path (e.g. /Users/you/projects)",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("input",{type:"text",value:C,onChange:B=>E(B.target.value),placeholder:"Agent path (e.g. /workspace/projects)",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsxs("button",{type:"submit",disabled:l.isPending||!A.trim()||!C.trim(),className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add mount"]})]})]})]})]})}function OC({className:e}){return r.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",className:e,children:r.jsx("path",{d:"M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"})})}const jMe=[{id:"telegram",label:"Telegram",icon:OC,available:!0},{id:"whatsapp",label:"WhatsApp",icon:Ji,available:!1},{id:"discord",label:"Discord",icon:Ji,available:!1},{id:"slack",label:"Slack",icon:Ji,available:!1}];function NMe({externalChannelId:e,botUsername:t}){const{data:n=[],refetch:s}=L.externalChannels.listPairings.useQuery({externalChannelId:e}),{data:i=[]}=L.workspace.listMembers.useQuery(),a=L.externalChannels.generatePairingCode.useMutation({onSuccess:()=>s()}),o=L.externalChannels.generatePairingCodeForUser.useMutation({onSuccess:()=>s()}),l=L.externalChannels.revokePairing.useMutation({onSuccess:()=>s()}),[c,d]=y.useState(!1),[f,p]=y.useState(""),[m,g]=y.useState(null),[b,_]=y.useState(null),[w,A]=y.useState(!1),S=new Set(n.map(F=>F.userId)),C=i.filter(F=>!S.has(F.userId));async function E(){g(null);try{const F=await a.mutateAsync({externalChannelId:e});g(F.code),d(!0)}catch{}}async function k(){if(f){g(null);try{const F=await o.mutateAsync({externalChannelId:e,userId:f});g(F.code)}catch{}}}function T(){m&&(navigator.clipboard.writeText(m).catch(()=>{}),A(!0),setTimeout(()=>A(!1),2e3))}return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Paired Users"}),r.jsxs("div",{className:"flex gap-1.5",children:[r.jsx("button",{onClick:E,disabled:a.isPending,className:"px-2 py-1 rounded text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] hover:bg-[#6366F1]/20 transition-colors",children:"Pair your Telegram"}),r.jsxs("button",{onClick:()=>{d(!0),g(null),p("")},className:"px-2 py-1 rounded text-[11px] font-medium bg-[#2A2A35] text-[#F0F0F5] hover:bg-[#3A3A45] transition-colors",children:[r.jsx(wt,{className:"w-3 h-3 inline -mt-px"})," Pair user"]})]})]}),n.length===0&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"No users paired yet. Pair your Telegram account to enable secure multi-user access."}),n.map(F=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded-md bg-[#13131A]",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[12px] text-[#F0F0F5]",children:F.userName}),F.telegramUsername&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E] ml-1.5",children:["@",F.telegramUsername]}),r.jsx("span",{className:"text-[10px] text-[#3A3A45] ml-1.5",children:new Date(F.pairedAt).toLocaleDateString()})]}),b===F.id?r.jsxs("div",{className:"flex gap-1",children:[r.jsx("button",{onClick:()=>{l.mutate({pairingId:F.id}),_(null)},className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#EF4444] text-white",children:"Revoke"}),r.jsx("button",{onClick:()=>_(null),className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#2A2A35] text-[#F0F0F5]",children:"Cancel"})]}):r.jsx("button",{onClick:()=>_(F.id),className:"text-[10px] text-[#5A5A6E] hover:text-[#EF4444] transition-colors",children:r.jsx(Dn,{className:"w-3 h-3"})})]},F.id)),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:"rounded-lg border border-[#2A2A35] bg-[#13131A] p-3 space-y-3 overflow-hidden",children:m?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium",children:"Pairing code"}),r.jsx("div",{onClick:T,className:"flex items-center justify-center gap-2 py-3 rounded-lg bg-[#1C1C21] border border-[#2A2A35] cursor-pointer hover:border-[#6366F1] transition-colors",children:r.jsx("span",{className:"text-2xl font-mono font-bold tracking-[0.25em] text-[#F0F0F5]",children:m})}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:[w?"Copied!":"Click to copy."," Send this to the user. They should message it to"," ",t?`@${t}`:"the bot"," on Telegram. Expires in 10 minutes."]}),r.jsx("button",{onClick:()=>{d(!1),g(null),s()},className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Done"})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium",children:"Pair a workspace member"}),C.length>0?r.jsxs(r.Fragment,{children:[r.jsxs(ss,{value:f,onValueChange:p,children:[r.jsxs(is,{className:"w-full flex items-center justify-between bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[12px] text-[#F0F0F5] outline-none",children:[r.jsx(Ds,{placeholder:"Select member"}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3 h-3 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{className:"bg-[#1C1C21] border border-[#2A2A35] rounded-lg shadow-xl z-[100]",position:"popper",sideOffset:4,children:r.jsx(os,{className:"p-1",children:C.map(F=>r.jsxs(vn,{value:F.userId,className:"flex items-center px-3 py-2 text-[12px] text-[#F0F0F5] rounded cursor-pointer hover:bg-[#2A2A35] outline-none data-[highlighted]:bg-[#2A2A35]",children:[r.jsx(yn,{children:F.name}),r.jsx(ui,{className:"ml-auto",children:r.jsx(Fe,{className:"w-3 h-3"})})]},F.userId))})})})]}),r.jsx("button",{onClick:k,disabled:!f||o.isPending,className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:o.isPending?"Generating...":"Generate code"})]}):r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"All workspace members are already paired."}),r.jsx("button",{onClick:()=>d(!1),className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})})})]})}function kMe({agentId:e}){const{data:t=[],refetch:n}=L.externalChannels.list.useQuery({agentId:e}),s=L.externalChannels.configure.useMutation({onSuccess:()=>n()}),i=L.externalChannels.enable.useMutation({onSuccess:()=>n()}),a=L.externalChannels.disable.useMutation({onSuccess:()=>n()}),o=L.externalChannels.delete.useMutation({onSuccess:()=>n()}),[l,c]=y.useState(null),[d,f]=y.useState(""),[p,m]=y.useState(null),[g,b]=y.useState(null);async function _(){if(!(!d.trim()||!l)){m(null);try{await s.mutateAsync({agentId:e,provider:l,credentials:{botToken:d.trim()}}),f(""),c(null)}catch(A){m(A instanceof Error?A.message:"Connection failed")}}}const w=t.find(A=>A.provider==="telegram");return r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"External Channels"}),w&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] p-3 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:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:w.running?"#10B981":w.status==="error"?"#EF4444":"#5A5A6E"}}),r.jsx(OC,{className:"w-4 h-4 text-[#29B6F6]"}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5]",children:"Telegram"}),typeof w.metadata?.botUsername=="string"&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E]",children:["@",w.metadata.botUsername]})]}),r.jsx(Sh,{checked:w.enabled,onCheckedChange:A=>{A?i.mutate({agentId:e,provider:"telegram"}):a.mutate({agentId:e,provider:"telegram"})},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]",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"})})]}),w.status==="error"&&r.jsx("p",{className:"text-[11px] text-[#EF4444]",children:"Bridge failed to start. Check the bot token."}),r.jsx("div",{className:"flex gap-2",children:g===w.id?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{o.mutate({id:w.id}),b(null)},className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#EF4444] hover:bg-[#DC2626] text-white transition-colors",children:"Confirm disconnect"}),r.jsx("button",{onClick:()=>b(null),className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]}):r.jsx("button",{onClick:()=>b(w.id),className:"text-[11px] text-[#5A5A6E] hover:text-[#EF4444] transition-colors",children:"Disconnect"})})]}),w&&r.jsx(NMe,{externalChannelId:w.id,botUsername:typeof w.metadata?.botUsername=="string"?w.metadata.botUsername:void 0}),w&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35]/50 bg-[#1C1C21]/50 p-3 space-y-2",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"BotFather Setup"}),r.jsxs("div",{className:"text-[11px] text-[#5A5A6E] leading-relaxed space-y-1",children:[r.jsx("p",{children:"Open @BotFather on Telegram and run these for your bot:"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setjoingroups"}),r.jsx("p",{className:"pl-3",children:"Disable (bot is DM-only)"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setprivacy"}),r.jsx("p",{className:"pl-3",children:"Enable (default)"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setdescription"}),r.jsx("p",{className:"pl-3",children:'e.g. "damn.dev workspace agent"'})]})]}),!w&&!l&&r.jsx("div",{className:"space-y-2",children:jMe.map(A=>r.jsxs("button",{onClick:()=>A.available?c(A.id):void 0,disabled:!A.available,className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg border border-[#2A2A35] bg-[#1C1C21] hover:bg-[#2A2A35] transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[r.jsx(A.icon,{className:"w-4 h-4 text-[#8A8A99]"}),r.jsxs("span",{className:"text-[13px] text-[#F0F0F5]",children:["Connect ",A.label]}),!A.available&&r.jsx("span",{className:"ml-auto text-[10px] text-[#5A5A6E]",children:"Coming soon"})]},A.id))}),l==="telegram"&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] p-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(OC,{className:"w-4 h-4 text-[#29B6F6]"}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Connect Telegram Bot"})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:"Create a bot via @BotFather on Telegram, then paste the token below."}),r.jsx("input",{type:"password",value:d,onChange:A=>f(A.target.value),placeholder:"Bot token from @BotFather",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors",onKeyDown:A=>A.key==="Enter"&&_()}),p&&r.jsx("p",{className:"text-[11px] text-[#EF4444]",children:p}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{onClick:_,disabled:s.isPending||!d.trim(),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[s.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Ji,{className:"w-3.5 h-3.5"}),"Connect"]}),r.jsx("button",{onClick:()=>{c(null),f(""),m(null)},className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),!w&&!l&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] leading-relaxed",children:"Connect external messaging platforms to reach this agent outside of damn.dev. Messages flow through the same pipeline with full governance."})]})}function EMe({agentId:e}){const{data:t,refetch:n}=L.agents.getCapabilities.useQuery({agentId:e}),s=L.agents.setCapabilities.useMutation({onSuccess:()=>n()}),[i,a]=y.useState(""),[o,l]=y.useState(!0),[c,d]=y.useState("idle"),f=y.useRef(null);y.useEffect(()=>{t&&(a(t.capabilities.join(", ")),l(t.canReceiveDelegations))},[t]),y.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);async function p(){const m=i.split(",").map(g=>g.trim()).filter(Boolean);await s.mutateAsync({agentId:e,capabilities:m,canReceiveDelegations:o}),d("saved"),f.current=setTimeout(()=>d("idle"),2e3)}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-5 overflow-y-auto",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Capabilities"}),r.jsx("textarea",{value:i,onChange:m=>a(m.target.value),rows:3,placeholder:"write:code, exec:shell, analyze:data",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2.5 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] resize-none outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Comma-separated. Auto-inferred from skills and role when empty."})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:"Accept delegations"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Other agents can delegate tasks to this agent"})]}),r.jsx(Sh,{checked:o,onCheckedChange:l,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]",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"})})]}),t&&t.capabilities.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.capabilities.map(m=>r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] border border-[#6366F1]/20",children:m},m))}),r.jsx("button",{onClick:p,disabled:s.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:r.jsx(Me,{mode:"wait",children:c==="saved"?r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved"},"saved"):r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")})})]})}const t2=["identity","config","live"],FMe={identity:["soul","team","model"],config:["skills","channels","capabilities","trust"],live:["activity","dream","files","git","terminal","schedule","override"]},TMe={identity:[],config:[],live:["activity","dream","files","git","terminal","override"]};function MMe({tabs:e,active:t,onChange:n}){return e.length<=1?null:r.jsx("div",{className:"flex gap-1 px-5 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:e.map(s=>r.jsx("button",{onClick:()=>n(s),className:`px-2.5 py-1 rounded-md text-[11px] font-medium capitalize transition-colors ${t===s?"bg-white/10 text-[#F0F0F5]":"text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5"}`,children:s},s))})}function X8(e,t){const n=atob(e),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n.charCodeAt(l);const i=new Blob([s],{type:"application/zip"}),a=URL.createObjectURL(i),o=document.createElement("a");o.href=a,o.download=t,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}function RMe({warnings:e,onExport:t,onCancel:n}){return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[60] flex items-center justify-center p-4",onClick:n,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},onClick:s=>s.stopPropagation(),className:"relative bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 w-full max-w-sm space-y-4 shadow-2xl",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Export warnings"}),r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:e.map((s,i)=>r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2",children:[r.jsx("p",{className:"text-[12px] text-[#FCD34D] leading-relaxed",children:s.message}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:[s.file,":",s.line]})]},i))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:t,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#F59E0B] hover:bg-[#D97706] text-black transition-colors",children:"Export anyway"}),r.jsx("button",{onClick:n,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]})]})}const DMe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],OMe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16"];function $N({agent:e,agentColor:t,onClose:n,onOverrideSet:s,initialTab:i}){const a=Uo(),o=a?FMe:TMe,l=a?"identity":"live",c=i&&t2.includes(i.category)?i.category:l,d=i&&o[c]?.includes(i.subTab)?i.subTab:o[c][0]??"activity",[f,p]=y.useState(c),[m,g]=y.useState(d),[b,_]=y.useState(null),[w,A]=y.useState(null),S=L.useUtils(),[C,E]=y.useState(!1),[k,T]=y.useState(e.name),F=y.useRef(null),M=L.agents.update.useMutation({onSuccess:()=>{S.agents.list.invalidate(),S.channels.list.invalidate()}});function I(){E(!1);const $=k.trim();$&&$!==e.name?M.mutate({agentId:e.id,name:$}):T(e.name)}y.useEffect(()=>{C&&F.current?.select()},[C]),y.useEffect(()=>{T(e.name)},[e.name]);const R=L.agents.export.useMutation();async function H(){try{const $=await R.mutateAsync({agentId:e.id});$.warnings.length>0?(_($.warnings),A({buffer:$.buffer,filename:$.filename})):X8($.buffer,$.filename)}catch{}}function V(){w&&X8(w.buffer,w.filename),_(null),A(null)}function K($){p($),g(o[$][0]??"")}const q=a?t2:t2.filter($=>o[$].length>0);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",style:{background:`linear-gradient(135deg, rgba(${uh(t)}, 0.08) 0%, transparent 100%)`},children:[r.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[a&&e.id!=="coo"?r.jsxs(Ys,{children:[r.jsx(ci,{asChild:!0,children:r.jsx("button",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xl flex-shrink-0 hover:ring-2 hover:ring-white/20 transition-all",style:{backgroundColor:`${t}26`},children:e.emoji})}),r.jsx(Qs,{children:r.jsxs(Xs,{sideOffset:8,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Emoji"}),r.jsx("div",{className:"grid grid-cols-10 gap-1 mb-3",children:DMe.map($=>r.jsx("button",{onClick:()=>M.mutate({agentId:e.id,emoji:$}),className:`w-6 h-6 flex items-center justify-center rounded text-sm hover:bg-white/10 transition-colors ${e.emoji===$?"bg-white/15 ring-1 ring-white/20":""}`,children:$},$))}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Color"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:OMe.map($=>r.jsx("button",{onClick:()=>M.mutate({agentId:e.id,color:$}),className:`w-6 h-6 rounded-full transition-all ${e.color===$?"ring-2 ring-white/40 scale-110":"hover:scale-110"}`,style:{backgroundColor:$}},$))}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]}):r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xl flex-shrink-0",style:{backgroundColor:`${t}26`},children:e.emoji}),r.jsxs("div",{className:"min-w-0",children:[C?r.jsx("input",{ref:F,value:k,onChange:$=>T($.target.value),onBlur:I,onKeyDown:$=>{$.key==="Enter"&&F.current?.blur(),$.key==="Escape"&&(T(e.name),E(!1))},className:"bg-transparent text-[14px] font-semibold text-[#F0F0F5] outline-none border-b border-[#6366F1]/60 pb-px w-full"}):r.jsxs("p",{className:`text-[14px] font-semibold text-[#F0F0F5] truncate ${a&&e.id!=="coo"?"cursor-pointer hover:text-[#818CF8] transition-colors group/name":""}`,onClick:()=>{a&&e.id!=="coo"&&E(!0)},children:[e.name,a&&e.id!=="coo"&&r.jsx(oh,{className:"w-3 h-3 inline-block ml-1.5 opacity-0 group-hover/name:opacity-60 transition-opacity"})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] truncate",children:e.role})]}),r.jsx(cMe,{status:e.status,color:t}),r.jsx(oMe,{agentId:e.id})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[a&&e.id!=="coo"&&r.jsx(bt,{label:"Export agent",side:"left",children:r.jsx("button",{onClick:H,disabled:R.isPending,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors disabled:opacity-50",children:R.isPending?r.jsx(Pe,{className:"w-4 h-4 animate-spin"}):r.jsx(nu,{className:"w-4 h-4"})})}),r.jsx(bt,{label:"Close",side:"left",children: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.jsx("div",{className:"flex border-b border-[#2A2A35] flex-shrink-0 px-5",children:q.map($=>r.jsx("button",{onClick:()=>K($),className:`py-3 px-1 mr-4 text-[11px] font-medium capitalize border-b-2 transition-colors outline-none ${f===$?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"}`,children:$},$))}),r.jsx(MMe,{tabs:o[f],active:m,onChange:g}),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[a&&m==="soul"&&r.jsx(uMe,{agentId:e.id}),a&&m==="team"&&r.jsx(dMe,{agentId:e.id}),a&&m==="model"&&r.jsx(rMe,{agent:e,agentColor:t}),a&&m==="skills"&&r.jsx(pMe,{agentId:e.id}),a&&m==="channels"&&r.jsx(kMe,{agentId:e.id}),a&&m==="capabilities"&&r.jsx(EMe,{agentId:e.id}),a&&m==="trust"&&r.jsx(CMe,{agentId:e.id}),m==="activity"&&r.jsx(DEe,{agentId:e.id}),m==="dream"&&r.jsx(JTe,{agentId:e.id}),m==="files"&&r.jsx(ITe,{agentId:e.id}),m==="git"&&r.jsx(WTe,{agentId:e.id}),m==="terminal"&&r.jsx(AMe,{agentId:e.id}),a&&m==="schedule"&&r.jsx(SMe,{agentId:e.id}),m==="override"&&r.jsx(mMe,{agentId:e.id,onOverrideSet:s,onClose:n})]})]}),r.jsx(Me,{children:b&&r.jsx(RMe,{warnings:b,onExport:V,onCancel:()=>{_(null),A(null)}})})]})}async function PMe(e){if(Va)try{const{sendNotification:t,isPermissionGranted:n,requestPermission:s}=await X(async()=>{const{sendNotification:a,isPermissionGranted:o,requestPermission:l}=await import("./index-E-6oA41F.js");return{sendNotification:a,isPermissionGranted:o,requestPermission:l}},__vite__mapDeps([103,1]));let i=await n();if(i||(i=await s()==="granted"),!i)return;t({title:e.title,body:e.body})}catch{}}const IMe=/\.(kanban|chart|table|board)\.json$/,LMe=oi.replace(/^http/,"ws")+"/ws",BMe=25e3,zMe=3e3;function J8(e,t){if(Va){document.hidden&&PMe({title:e,body:t.slice(0,80)});return}!("Notification"in window)||Notification.permission!=="granted"||document.hidden&&new Notification(e,{body:t.slice(0,80),icon:"/favicon.ico"})}function $Me(e,t){return new RegExp(`@${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`,"i").test(e)}const Z8=new Set;function bW(e){const t=L.useUtils(),{data:n}=Mi(),s=y.useRef(n?.user?.name??"");y.useLayoutEffect(()=>{s.current=n?.user?.name??""});const{appendMessage:i,setAgentStatus:a,updateMessageStatus:o,updateMessage:l,removeMessage:c,updateReactions:d,setUnreadCount:f,addFileEditApproval:p,removeFileEditApproval:m}=Je(),g=y.useRef(null),b=y.useRef(null),_=y.useRef(e),w=y.useRef(!0),A=y.useRef(!1);y.useLayoutEffect(()=>{_.current=e});const S=y.useCallback(async C=>{const k=Je.getState().messagesByChannel[C];if(!k||k.length===0)return;const T=k[k.length-1];try{const F=await t.messages.list.fetch({channelId:C,cursor:T.id,limit:100,direction:"after"});if(F.messages.length>0)for(const M of F.messages)i(M)}catch{}},[t,i]);y.useEffect(()=>{w.current=!0;let C=null;function E(){if(!w.current)return;const k=new WebSocket(LMe);g.current=k,k.onopen=()=>{if(!w.current){k.close(1e3);return}const T=_.current;T&&k.send(JSON.stringify({type:"subscribe",channelId:T})),A.current&&(T&&S(T),t.messages.list.invalidate(),t.channels.list.invalidate(),t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate()),A.current=!0,b.current=setInterval(()=>{k.readyState===WebSocket.OPEN&&k.send(JSON.stringify({type:"ping"}))},BMe)},k.onmessage=T=>{if(w.current)try{const F=JSON.parse(T.data);if(F.type==="message.new"){const M=F;i(M.payload),M.payload.sender.type==="agent"&&M.payload.channelId!==_.current&&J8(M.payload.sender.name,M.payload.content)}else if(F.type==="message.edited"){const M=F;l(M.payload.channelId,M.payload.messageId,{content:M.payload.content,editedAt:M.payload.editedAt})}else if(F.type==="message.deleted"){const M=F;c(M.payload.channelId,M.payload.messageId)}else if(F.type==="message.pinned"){const M=F;l(M.payload.channelId,M.payload.messageId,{pinnedAt:M.payload.pinnedAt,pinnedBy:M.payload.pinnedBy})}else if(F.type==="message.unpinned"){const M=F;l(M.payload.channelId,M.payload.messageId,{pinnedAt:void 0,pinnedBy:void 0})}else if(F.type==="message.metadata_updated"){const M=F;l(M.payload.channelId,M.payload.messageId,{metadata:M.payload.metadata})}else if(F.type==="reaction.toggled"){const M=F;d(M.payload.channelId,M.payload.messageId,M.payload.reactions)}else if(F.type==="thread.message.new"){const M=F,R=(Je.getState().messagesByChannel[M.payload.channelId]??[]).find(H=>H.id===M.payload.parentMessageId);R&&l(M.payload.channelId,M.payload.parentMessageId,{replyCount:(R.replyCount??0)+1})}else if(F.type==="agent.status"){const M=F;a(M.payload.agentId,M.payload.status),M.payload.status==="thinking"?Mw("thinking"):Mw("idle")}else if(F.type==="approval.decided"){const M=F;o(M.payload.channelId,M.payload.messageId,M.payload.decision),t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate()}else if(F.type==="approval.file_edit.created")p(F.payload);else if(F.type==="approval.file_edit.decided"){const M=F;m(M.payload.channelId,M.payload.id)}else if(F.type==="conversation.cleared"){const M=F;Je.getState().setMessages(M.payload.channelId,[])}else if(F.type==="channel.created"||F.type==="channel.closed"||F.type==="channel.updated")t.channels.list.invalidate(),F.type==="channel.created"&&t.readReceipts.getUnread.invalidate();else if(F.type==="channel.tabs.updated"){const M=F;t.channels.get.invalidate({channelId:M.payload.parentChannelId}),t.channels.list.invalidate()}else if(F.type==="channel.tokenUpdate"){const M=F;ny.getState().updateFromWs(M.payload.channelId,M.payload)}else if(F.type==="channel.compacted"){const M=F;Je.getState().appendMessage({id:`compaction-${Date.now()}`,channelId:M.payload.channelId,sender:{type:"context_reset",id:"system",name:"system"},content:`compacted:${M.payload.summarizedCount}`,timestamp:new Date().toISOString()})}else if(F.type==="presence.changed"){const M=F;t.workspace.listPresence.setData(void 0,I=>I&&I.map(R=>R.userId===M.payload.userId?{...R,online:M.payload.online,lastSeenAt:M.payload.lastSeenAt??R.lastSeenAt}:R))}else if(F.type==="agent.fileChanged"){const M=F;t.fileChanges.list.invalidate({channelId:M.payload.channelId})}else if(F.type==="agent.filesChanged"){const M=F;if(t.files.tree.invalidate({agentId:M.payload.agentId}),M.payload.filename&&IMe.test(M.payload.filename)){const R=t.channels.list.getData()?.find(H=>H.channelType==="dm"&&H.agentId===M.payload.agentId);R&&NU.getState().addCard(R.id,{id:`sf-${M.payload.agentId}-${M.payload.filename}-${Date.now()}`,agentId:M.payload.agentId,filename:M.payload.filename,filePath:M.payload.filePath??M.payload.filename,timestamp:Date.now()})}}else if(F.type==="agent.created"||F.type==="agent.deleted")t.agents.list.invalidate(),t.channels.list.invalidate();else if(F.type==="approval.created"||F.type==="approval.expired"){if(t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate(),F.type==="approval.created"){const M=F.payload;M?.channelId&&S(M.channelId),Mw("badge"),J8("Action required",M?.agentName?`${M.agentName} wants to: ${M.description??"perform an action"}`:"An agent requires approval"),window.dispatchEvent(new CustomEvent("pwa-push-prompt"))}}else(F.type==="mission.task.updated"||F.type==="mission.task.dispatched"||F.type==="mission.created")&&(t.missions.list.invalidate(),t.federation.activityFeed.invalidate());if(F.type==="message.new"){const M=F;if(M.payload.channelId!==_.current&&!Z8.has(M.payload.id)){Z8.add(M.payload.id);const{mutedChannels:I,unreadCounts:R}=Je.getState(),H=I[M.payload.channelId];H?H.notifyOnMention&&s.current&&$Me(M.payload.content,s.current)&&f(M.payload.channelId,(R[M.payload.channelId]??0)+1):f(M.payload.channelId,(R[M.payload.channelId]??0)+1)}}}catch{}},k.onclose=T=>{b.current&&clearInterval(b.current),w.current&&T.code!==1e3&&(C=setTimeout(E,zMe))},k.onerror=()=>{k.close()}}return E(),()=>{w.current=!1,b.current&&clearInterval(b.current),C&&clearTimeout(C),g.current?.close(1e3)}},[i,a,o,l,c,d,f,p,m,t,S]),y.useEffect(()=>{const C=g.current;!C||C.readyState!==WebSocket.OPEN||e&&C.send(JSON.stringify({type:"subscribe",channelId:e}))},[e])}const VMe={orchestrator:"#6366F1","content-agent":"#8B5CF6","engagement-agent":"#10B981"};function UMe(){const{channelId:e}=am(),t=an(),n=tz(D=>D.setActiveChannelId);y.useEffect(()=>(n(e??null),()=>n(null)),[e,n]);const{data:s}=L.channels.get.useQuery({channelId:e??""},{enabled:!!e,retry:!1});y.useEffect(()=>{if(!s||!e)return;const D=s.channel,Q=s.tabs,z=V7.getState();if(D.parentChannelId==null){const J=z.lastTab[e];J&&J!==e&&(Q.some(ee=>ee.id===J)?t(`/channels/${J}`,{replace:!0}):z.clearLast(e))}else z.lastTab[D.parentChannelId]!==e&&z.setLast(D.parentChannelId,e)},[s,e,t]);const[i,a]=y.useState(!1),[o,l]=y.useState(void 0),[c,d]=y.useState(!1),[f,p]=y.useState(null);y.useEffect(()=>{function D(){l({category:"live",subTab:"files"}),a(!0)}return window.addEventListener("open-agent-files",D),()=>window.removeEventListener("open-agent-files",D)},[]);const{data:m}=ez(e??""),{data:g}=pj(m?.agentId??""),{data:b=[]}=Vo(),{data:_}=Mi(),w=m?.channelType==="dm"&&!m.agentId,A=m?.channelType==="group"||m?.channelType==="topic",{data:S=[]}=L.workspace.listMembers.useQuery(void 0,{enabled:w||A}),C=w?m.participants.find(D=>D.participantType==="human"&&D.participantId!==_?.user?.id):void 0,E=C?S.find(D=>D.userId===C.participantId)?.name??void 0:void 0,k=C?.participantId,{data:T,isLoading:F,loadMore:M}=W7(e??""),I=Je(D=>D.agentStatuses),R=Je(D=>D.openThreadMessageId),H=Je(D=>D.closeThread),V=Je(D=>D.unreadCounts),{mutate:K,isPending:q}=q7();bW(e);const $=!!g&&((I[g.id]??g.status)==="thinking"||(I[g.id]??g.status)==="executing"),B=T.some(D=>D.status==="pending_approval"),Y=g?VMe[g.id]??g.color:void 0,U=e?V[e]??0:0,W=U>0&&T.length>=U?T[T.length-U]?.id:void 0,O=y.useCallback((D,Q)=>{e&&K({channelId:e,content:D,attachmentIds:Q})},[e,K]);return!e||!m?r.jsx("div",{className:"flex-1 flex items-center justify-center text-[#8A8A99]",children:r.jsx("p",{className:"text-[14px]",children:"Channel not found"})}):m.channelType==="terminal"?r.jsx("div",{className:"flex-1"}):m.channelType==="group"?r.jsx(dwe,{channel:m,agents:b}):r.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[r.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[r.jsx(swe,{channel:m,agent:w?void 0:g,agentColor:w?void 0:Y,hasPendingApproval:w?!1:B,rightPanelOpen:i,memoryPanelOpen:c,activeOverride:f,humanDmName:E,humanDmUserId:k,onToggleRightPanel:()=>a(D=>!D),onToggleMemoryPanel:()=>d(D=>!D),onAgentClick:()=>a(D=>!D),onClearOverride:()=>p(null),onClearConversation:()=>Je.getState().setMessages(e,[])}),r.jsx(ike,{channelId:e,agentForChannel:m.channelType==="topic"||w?void 0:g,agentColor:m.channelType==="topic"||w?void 0:Y,messages:T,isThinking:m.channelType==="topic"||w?!1:$,isLoading:F,loadMore:M,firstUnreadId:W}),r.jsx(cke,{channelId:e}),r.jsx(H7,{channelId:e,channelName:w?E??"User":m.name,agent:m.channelType==="topic"||w?void 0:g,agentColor:m.channelType==="topic"||w?void 0:Y,onSend:O,disabled:q,mentionableParticipants:m.channelType==="topic"?[...m.participants.filter(D=>D.participantType==="agent").map(D=>b.find(Q=>Q.id===D.participantId)).filter(D=>!!D).map(D=>({id:D.id,name:D.name,emoji:D.emoji,color:D.color,type:"agent"})),...m.participants.filter(D=>D.participantType==="human"&&D.participantId!==_?.user?.id).map(D=>{const Q=S.find(z=>z.userId===D.participantId);return Q?{id:Q.userId,name:Q.name,emoji:null,color:"#6366F1",type:"human"}:null}).filter(D=>!!D)]:void 0})]}),r.jsx(Me,{children:c&&g&&r.jsx(hke,{agent:g,agentColor:Y,onClose:()=>d(!1)})}),r.jsx(Me,{children:R&&r.jsx(dke,{parentMessageId:R,agentColor:Y,onClose:H})}),r.jsx(Me,{children:i&&g&&Y&&r.jsx($N,{agent:g,agentColor:Y,onClose:()=>{a(!1),l(void 0)},onOverrideSet:D=>p(D),initialTab:o},o?.subTab)})]})}function HMe({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.agentImport.previewImport.useMutation(),m=L.agentImport.confirmImport.useMutation(),g=y.useCallback(async S=>{if(!S.name.endsWith(".damnpack")){l("Please select a .damnpack file"),s("error");return}if(S.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const C=new FormData;C.append("file",S);const E=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:C,credentials:"include"});if(!E.ok){const F=await E.json().catch(()=>({error:"Upload failed"}));throw new Error(F.error||`Upload failed (${E.status})`)}const{uploadId:k}=await E.json(),T=await p.mutateAsync({uploadId:k});if("kind"in T&&T.kind==="skill-pack"){s("skill-pack");return}a(T),s("preview")}catch(C){l(C instanceof Error?C.message:"Upload failed"),s("error")}},[p]);async function b(S){if(i){s("confirming");try{const C=await m.mutateAsync({previewId:i.previewId,mode:S});d(C),s("done")}catch(C){l(C instanceof Error?C.message:"Import failed"),s("error")}}}const _=i?.warnings.filter(S=>S.type==="credential")??[],w=i?.warnings.filter(S=>S.type==="url")??[],A=i?.warnings.filter(S=>S.type==="shell_exec")??[];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:S=>S.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"?"Import complete":n==="skill-pack"?"Skill pack":"Import agent"}),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 file"}),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:S=>{const C=S.target.files?.[0];C&&g(C)}})]}),(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 bundle...":"Importing agent..."})]}),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==="skill-pack"&&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-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",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Skill pack detected"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"This bundle contains skills, not an agent."})]})]}),r.jsx(gn,{to:"/skills",onClick:e,className:"flex items-center justify-center w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Go to Skills page to import"}),r.jsx("button",{onClick:e,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]}),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 text-lg",children:i.manifest.name.slice(0,2)}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.manifest.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.manifest.version," by ",i.manifest.author.name]})]}),i.isUpdate&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20",children:"Update"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.manifest.description}),r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] p-3",children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:"Soul excerpt"}),r.jsx("p",{className:"text-[12px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap line-clamp-6",children:i.soulExcerpt})]}),i.manifest.skills.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Skills"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:i.manifest.skills.map(S=>r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] border border-[#6366F1]/20",children:S},S))})]}),i.isUpdate&&i.diff&&r.jsx("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] px-3 py-2",children:r.jsxs("p",{className:"text-[12px] text-[#C8C8D4]",children:["SOUL.md: ",r.jsxs("span",{className:"text-emerald-400",children:["+",i.diff.added]})," / ",r.jsxs("span",{className:"text-red-400",children:["-",i.diff.removed]})," lines",i.skillFiles.length>0&&`. ${i.skillFiles.length} skill file(s).`]})}),i.modelWarnings.length>0&&r.jsx("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:i.modelWarnings.map((S,C)=>r.jsxs("p",{className:"text-[11px] text-[#FCD34D] flex items-start gap-1.5",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),S]},C))}),i.missingSecrets.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 missing"]}),r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80",children:"This bundle's skills reference secrets that aren't set in this workspace. You can still import now, but agents will fail to call these tools until you add the secrets in Settings → Secrets:"}),r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:i.missingSecrets.map(S=>r.jsx("code",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono text-[#FCD34D] bg-[#F59E0B]/15 border border-[#F59E0B]/20",children:S},S))})]}),A.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5] flex items-center gap-1.5",children:[r.jsx(Ti,{className:"w-3.5 h-3.5"}),"Shell execution patterns detected"]}),A.map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80 ml-5",children:[S.file,":",S.line," — ",S.message]},C))]}),_.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),"Possible credentials found"]}),_.map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:[S.file,":",S.line]},C))]}),w.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#2A2A35]/50 border border-[#2A2A35] px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#8A8A99] flex items-center gap-1.5",children:[r.jsx(Xt,{className:"w-3.5 h-3.5"}),"External URLs (",w.length,")"]}),w.slice(0,5).map((S,C)=>r.jsx("p",{className:"text-[10px] text-[#5A5A6E] ml-5 truncate",children:S.message.replace("External URL: ","")},C)),w.length>5&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] ml-5",children:["...and ",w.length-5," more"]})]}),i.hasHeartbeat&&r.jsx("div",{className:"rounded-lg bg-[#6366F1]/10 border border-[#6366F1]/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-[#818CF8] flex items-start gap-1.5",children:[r.jsx(bm,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),"This agent includes a scheduled task. It will be disabled by default."]})}),i.isUpdate&&r.jsxs("p",{className:"text-[11px] text-[#8A8A99] italic",children:["Updating existing agent: ",i.manifest.name,". Your memory and experience will be preserved."]}),i.strippedFiles.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:["Stripped from bundle: ",i.strippedFiles.join(", ")]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[i.isUpdate?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>b("update"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Update"}),r.jsx("button",{onClick:()=>b("new"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Import as copy"})]}):r.jsx("button",{onClick:()=>b("new"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Import"}),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.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:c.name}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:c.mode==="update"?"Agent updated successfully":"Agent imported successfully"})]})]}),c.heartbeatNote&&r.jsx("p",{className:"text-[11px] text-[#818CF8] bg-[#6366F1]/10 border border-[#6366F1]/20 rounded-lg px-3 py-2",children:c.heartbeatNote}),c.diff&&r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:c.diff}),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"})]})]})]})]})}function WMe({onClose:e}){const[t,n]=y.useState("select"),[s,i]=y.useState(new Set),[a,o]=y.useState(new Set),[l,c]=y.useState(null),[d,f]=y.useState([]),{data:p}=L.teamBundle.listExportable.useQuery(),m=L.teamBundle.exportTeam.useMutation(),g=p?.agents??[],b=p?.channels??[];function _(S){i(C=>{const E=new Set(C);return E.has(S)?E.delete(S):E.add(S),E})}function w(S){o(C=>{const E=new Set(C);return E.has(S)?E.delete(S):E.add(S),E})}async function A(){if(s.size!==0){n("exporting");try{const S=await m.mutateAsync({agentIds:[...s],channelIds:[...a]});f(S.warnings.map(M=>({file:M.file,message:M.message})));const C=atob(S.buffer),E=new Uint8Array(C.length);for(let M=0;M<C.length;M++)E[M]=C.charCodeAt(M);const k=new Blob([E],{type:"application/zip"}),T=URL.createObjectURL(k),F=document.createElement("a");F.href=T,F.download=S.filename,F.click(),URL.revokeObjectURL(T),n("done")}catch(S){c(S instanceof Error?S.message:"Export failed"),n("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:S=>S.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:t==="done"?"Export complete":"Export team"}),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:[t==="select"&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Agents (",s.size," selected)"]}),r.jsxs("div",{className:"space-y-1",children:[g.map(S=>r.jsxs("label",{className:"flex items-center gap-3 py-2 px-3 rounded-lg hover:bg-white/5 cursor-pointer transition-colors",children:[r.jsx("input",{type:"checkbox",checked:s.has(S.id),onChange:()=>_(S.id),className:"w-3.5 h-3.5 rounded border-[#2A2A35] text-[#6366F1] focus:ring-0 focus:ring-offset-0"}),r.jsx("span",{className:"text-sm",children:S.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:S.name}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:S.role})]})]},S.id)),g.length===0&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-2",children:"No agents available"})]})]}),b.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Channels (",a.size," selected)"]}),r.jsx("div",{className:"space-y-1",children:b.map(S=>r.jsxs("label",{className:"flex items-center gap-3 py-2 px-3 rounded-lg hover:bg-white/5 cursor-pointer transition-colors",children:[r.jsx("input",{type:"checkbox",checked:a.has(S.id),onChange:()=>w(S.id),className:"w-3.5 h-3.5 rounded border-[#2A2A35] text-[#6366F1] focus:ring-0 focus:ring-offset-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:S.name}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E]",children:[S.channelType," / ",S.visibility]})]})]},S.id))})]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsxs("button",{onClick:A,disabled:s.size===0,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-40 disabled:pointer-events-none flex items-center justify-center gap-2",children:[r.jsx(vv,{className:"w-4 h-4"}),"Export (",s.size," agents)"]}),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"})]})]}),t==="exporting"&&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:"Packaging team bundle..."})]}),t==="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:l})}),r.jsx("button",{onClick:()=>{n("select"),c(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),t==="done"&&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.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Team exported"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[s.size," agents, ",a.size," channels"]})]})]}),r.jsx(Me,{children:d.length>0&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),d.length," warning(s)"]}),d.slice(0,5).map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:[S.file,": ",S.message]},C))]})}),r.jsx("button",{onClick:e,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}function qMe({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,p]=y.useState(null),m=y.useRef(null),g=L.teamBundle.previewTeamImport.useMutation(),b=L.teamBundle.confirmTeamImport.useMutation(),_=y.useCallback(async C=>{if(!C.name.endsWith(".damnteam")){l("Please select a .damnteam file"),s("error");return}if(C.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const E=new FormData;E.append("file",C);const k=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:E,credentials:"include"});if(!k.ok){const M=await k.json().catch(()=>({error:"Upload failed"}));throw new Error(M.error||`Upload failed (${k.status})`)}const{uploadId:T}=await k.json(),F=await g.mutateAsync({uploadId:T});a(F),s("preview")}catch(E){l(E instanceof Error?E.message:"Upload failed"),s("error")}},[g]);async function w(){if(i){s("confirming");try{const C=await b.mutateAsync({previewId:i.previewId});d(C),s("done")}catch(C){l(C instanceof Error?C.message:"Import failed"),s("error")}}}const A=i?.warnings.filter(C=>C.type==="credential")??[],S=i?.warnings.filter(C=>C.type==="shell_exec")??[];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:C=>C.stopPropagation(),className:"relative w-full max-w-lg 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"?"Team imported":"Import team"}),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:()=>m.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 .damnteam file"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Max 100MB"})]})]}),r.jsx("input",{ref:m,type:"file",accept:".damnteam",className:"hidden",onChange:C=>{const E=C.target.files?.[0];E&&_(E)}})]}),(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 team bundle...":"Importing team..."})]}),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(wm,{className:"w-5 h-5 text-[#6366F1]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.teamManifest.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.teamManifest.version," by ",i.teamManifest.author.name]})]})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.teamManifest.description}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Agents (",i.agentPreviews.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.agentPreviews.map(C=>r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] overflow-hidden",children:[r.jsxs("button",{onClick:()=>p(f===C.slug?null:C.slug),className:"w-full flex items-center gap-3 px-3 py-2.5 text-left",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:C.manifest.name}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:C.manifest.description})]}),C.isUpdate&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20 flex-shrink-0",children:"Update"}),C.warnings.length>0&&r.jsx(ql,{className:"w-3.5 h-3.5 text-[#FCD34D] flex-shrink-0"}),r.jsx(ft,{className:`w-3.5 h-3.5 text-[#5A5A6E] transition-transform ${f===C.slug?"rotate-180":""}`})]}),r.jsx(Me,{children:f===C.slug&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:r.jsxs("div",{className:"px-3 pb-3 space-y-2 border-t border-[#2A2A35]",children:[r.jsx("p",{className:"text-[11px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap line-clamp-4 pt-2",children:C.soulExcerpt}),C.modelWarnings.length>0&&r.jsx("div",{className:"space-y-0.5",children:C.modelWarnings.map((E,k)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D] flex items-center gap-1",children:[r.jsx(Wl,{className:"w-3 h-3"}),E]},k))}),C.hasHeartbeat&&r.jsxs("p",{className:"text-[10px] text-[#818CF8] flex items-center gap-1",children:[r.jsx(bm,{className:"w-3 h-3"}),"Includes scheduled task (will be disabled)"]})]})})})]},C.slug))})]}),i.channelDefinitions.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Channels (",i.channelDefinitions.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.channelDefinitions.map((C,E)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Tp,{className:"w-3.5 h-3.5 text-[#5A5A6E]"}),r.jsx("p",{className:"text-[12px] text-[#C8C8D4] flex-1",children:C.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:C.channelType}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:[C.agentSlugs.length," agents"]})]},E))})]}),i.delegationRules.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Delegation rules (",i.delegationRules.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.delegationRules.map((C,E)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(ch,{className:"w-3.5 h-3.5 text-[#5A5A6E]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.agentSlug}),r.jsx("code",{className:"text-[11px] font-mono text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded",children:C.pattern}),r.jsx("span",{className:"ml-auto px-2 py-0.5 rounded-full text-[9px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/20",children:"Will require approval"})]},E))})]}),S.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5] flex items-center gap-1.5",children:[r.jsx(Ti,{className:"w-3.5 h-3.5"}),"Shell execution patterns detected"]}),S.slice(0,5).map((C,E)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80 ml-5",children:[C.file,": ",C.message]},E))]}),A.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),"Possible credentials found"]}),A.slice(0,5).map((C,E)=>r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:C.file},E))]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsx("button",{onClick:w,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Import 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.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Team imported"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c.importedAgents.length," agents, ",c.createdChannels.length," channels"]})]})]}),c.importedAgents.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Imported agents"}),r.jsx("div",{className:"space-y-1",children:c.importedAgents.map(C=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Fe,{className:"w-3 h-3 text-emerald-400"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:C.mode})]},C.agentId))})]}),c.createdChannels.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Created channels"}),r.jsx("div",{className:"space-y-1",children:c.createdChannels.map(C=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Tp,{className:"w-3 h-3 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.name})]},C.id))})]}),c.pendingRules.length>0&&r.jsx("div",{className:"rounded-lg bg-amber-500/10 border border-amber-500/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-amber-400",children:[c.pendingRules.length," delegation rule(s) pending approval"]})}),c.failures.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5]",children:["Failed (",c.failures.length,")"]}),c.failures.map((C,E)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80",children:[C.slug,": ",C.error]},E))]}),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"})]})]})]})]})}function GMe({status:e,color:t}){const n=e==="thinking"||e==="executing";return r.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3",children:[n&&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:2,repeat:1/0,ease:"easeInOut"}}),r.jsx("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{backgroundColor:e==="offline"?"#3A3A45":t,opacity:e==="idle"?.5:1}})]})}function KMe({agent:e,onClose:t}){const{data:n,isLoading:s}=L.agents.getMemory.useQuery({agentId:e.id});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:t,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},className:"relative w-full max-w-2xl bg-[#16161A] border border-[#2A2A35] rounded-2xl overflow-hidden shadow-2xl",onClick:i=>i.stopPropagation(),children:[r.jsxs("div",{className:"px-6 py-5 border-b border-[#2A2A35] flex items-center justify-between",style:{background:`linear-gradient(135deg, rgba(${uh(e.color)}, 0.08) 0%, transparent 100%)`},children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-2xl",children:e.emoji}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:e.name}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"MEMORY.md — read only"})]})]}),r.jsx("button",{onClick:t,className:"text-[#8A8A99] hover:text-[#F0F0F5] transition-colors text-[20px] leading-none w-8 h-8 flex items-center justify-center rounded-lg hover:bg-white/10",children:"×"})]}),r.jsxs("div",{className:"p-6 max-h-[60vh] overflow-y-auto",children:[s&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] animate-pulse",children:"Loading memory…"}),!s&&!n?.content&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No memory recorded yet."}),!s&&n?.content&&r.jsx("div",{className:"prose-message text-[13px]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:n.content})})]})]})]})}function YMe({agent:e,onConfirm:t,onCancel:n}){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:n,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},className:"relative w-full max-w-sm bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6 shadow-2xl",onClick:s=>s.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsx("span",{className:"text-3xl",children:e.emoji}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:["Delete ",e.name,"?"]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"This permanently removes the agent from OpenClaw, deletes all files (SOUL, MEMORY, TEAM), and removes the DM channel."})]})]}),r.jsxs("div",{className:"flex gap-2 mt-6",children:[r.jsx("button",{onClick:n,className:"flex-1 h-9 rounded-lg border border-[#2A2A35] text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45] transition-colors",children:"Cancel"}),r.jsx("button",{onClick:t,className:"flex-1 h-9 rounded-lg bg-red-500/10 border border-red-500/30 text-[13px] text-red-400 hover:bg-red-500/20 transition-colors",children:"Delete"})]})]})]})}function QMe({agent:e}){const[t,n]=y.useState(""),s=L.useUtils(),i=L.agents.update.useMutation({onSuccess:()=>s.agents.list.invalidate()}),{groups:a}=Vm();return r.jsxs(Yv,{onOpenChange:o=>{o||n("")},children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-white/5 hover:bg-white/10 transition-colors text-[12px] text-[#C8C8D4]",children:[r.jsx("span",{children:ta(e.model)}),r.jsx(Jt,{className:"w-3 h-3 rotate-90"})]})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-y-auto shadow-xl z-[9999] min-w-[160px] max-h-[280px]",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:t,onChange:n,onSubmit:o=>{i.mutate({agentId:e.id,model:o}),n("")},placeholder:"Type model ID..."})}),a.map(o=>r.jsxs(g_e,{children:[r.jsx(b_e,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-wider",children:o.label}),o.models.map(l=>r.jsx(Bl,{onSelect:()=>i.mutate({agentId:e.id,model:l.id}),className:ye("w-full text-left px-3 py-1.5 text-[12px] cursor-pointer outline-none hover:bg-white/10 transition-colors",e.model===l.id?"text-[#F0F0F5]":"text-[#8A8A99]"),children:l.label},l.id))]},o.label))]})})]})}function XMe(e,t){const n=atob(e),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n.charCodeAt(l);const i=new Blob([s],{type:"application/zip"}),a=URL.createObjectURL(i),o=document.createElement("a");o.href=a,o.download=t,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}const JMe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],ZMe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16"];function eRe({agent:e,onOpenPanel:t,canManage:n}){const[s,i]=y.useState(!1),[a,o]=y.useState(!1),[l,c]=y.useState(!1),[d,f]=y.useState(e.name),p=y.useRef(null),m=L.useUtils();y.useEffect(()=>{l&&p.current?.select()},[l]),y.useEffect(()=>{f(e.name)},[e.name]);const g=L.agents.update.useMutation({onSuccess:()=>{m.agents.list.invalidate(),m.channels.list.invalidate()}});function b(){c(!1);const C=d.trim();C&&C!==e.name?g.mutate({agentId:e.id,name:C}):f(e.name)}const _=L.agents.delete.useMutation({onSuccess:()=>m.agents.list.invalidate()}),w=L.agents.export.useMutation({onSuccess:C=>XMe(C.buffer,C.filename)}),A=e.status==="offline",S=uh(e.color);return r.jsxs(r.Fragment,{children:[r.jsxs(ne.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},onClick:()=>t(e),className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 hover:border-[#3A3A45] transition-colors group relative overflow-hidden cursor-pointer",children:[r.jsx("div",{className:"absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",style:{background:`radial-gradient(400px circle at 0% 0%, rgba(${S}, 0.04), transparent 60%)`}}),r.jsxs("div",{className:"flex items-start gap-4 mb-4",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center text-2xl flex-shrink-0",style:{backgroundColor:`rgba(${S}, 0.15)`,border:`1px solid rgba(${S}, 0.25)`},children:e.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[l?r.jsx("input",{ref:p,value:d,onChange:C=>f(C.target.value),onBlur:b,onKeyDown:C=>{C.key==="Enter"&&p.current?.blur(),C.key==="Escape"&&(f(e.name),c(!1))},onClick:C=>C.stopPropagation(),className:"bg-transparent text-[15px] font-semibold text-[#F0F0F5] outline-none border-b border-[#6366F1]/60 pb-px flex-1 min-w-0"}):r.jsx("h3",{className:"text-[15px] font-semibold text-[#F0F0F5] truncate",children:e.name}),r.jsx(GMe,{status:e.status,color:e.color})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] truncate",children:e.role}),e.lastAction&&r.jsx("p",{className:"text-[11px] text-[#5A5A6A] mt-1",children:Ir(e.lastAction)})]}),n&&e.id!=="coo"&&r.jsx("div",{onClick:C=>C.stopPropagation(),children:r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/10 transition-colors opacity-0 group-hover:opacity-100",children:r.jsx(iL,{className:"w-4 h-4"})})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,align:"end",className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-hidden shadow-xl z-[9999] min-w-[160px]",children:[r.jsxs(Bl,{onSelect:()=>c(!0),className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(oh,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Rename"]}),r.jsxs(lR,{children:[r.jsxs(cR,{className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors data-[state=open]:bg-white/10",children:[r.jsx(Tre,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Change emoji",r.jsx(Jt,{className:"w-3 h-3 ml-auto text-[#5A5A6E]"})]}),r.jsx(Od,{children:r.jsxs(uR,{sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Choose emoji"}),r.jsx("div",{className:"grid grid-cols-10 gap-1",children:JMe.map(C=>r.jsx(Bl,{onSelect:()=>g.mutate({agentId:e.id,emoji:C}),className:`w-6 h-6 flex items-center justify-center rounded text-sm cursor-pointer outline-none hover:bg-white/10 transition-colors ${e.emoji===C?"bg-white/15 ring-1 ring-white/20":""}`,children:C},C))})]})})]}),r.jsxs(lR,{children:[r.jsxs(cR,{className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors data-[state=open]:bg-white/10",children:[r.jsx(Zie,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Change color",r.jsx(Jt,{className:"w-3 h-3 ml-auto text-[#5A5A6E]"})]}),r.jsx(Od,{children:r.jsxs(uR,{sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Choose color"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:ZMe.map(C=>r.jsx(Bl,{onSelect:()=>g.mutate({agentId:e.id,color:C}),className:`w-7 h-7 rounded-full cursor-pointer outline-none transition-all ${e.color===C?"ring-2 ring-white/40 scale-110":"hover:scale-110"}`,style:{backgroundColor:C}},C))})]})})]})]})})]})})]}),r.jsxs("p",{className:"text-[12px] text-[#6A6A7A] leading-relaxed line-clamp-2 mb-4 italic",children:['"',e.soulExcerpt,'"']}),r.jsxs("div",{className:"flex items-center gap-2",onClick:C=>C.stopPropagation(),children:[n&&r.jsx(QMe,{agent:e}),n&&r.jsx(bt,{label:"Edit soul",children:r.jsx(gn,{to:`/agents/edit-soul/${e.id}`,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(Ese,{className:"w-3.5 h-3.5"})})}),r.jsx(bt,{label:"View memory",children:r.jsx("button",{onClick:()=>i(!0),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(eie,{className:"w-3.5 h-3.5"})})}),n&&r.jsx(bt,{label:A?"Resume":"Pause",children:r.jsx("button",{onClick:()=>g.mutate({agentId:e.id,status:A?"idle":"offline"}),className:ye("w-7 h-7 flex items-center justify-center rounded-md transition-colors",A?"text-emerald-400 hover:bg-emerald-500/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10"),children:A?r.jsx(I5,{className:"w-3.5 h-3.5"}):r.jsx(gL,{className:"w-3.5 h-3.5"})})}),n&&e.id!=="coo"&&r.jsx(bt,{label:"Export agent",children:r.jsx("button",{onClick:()=>w.mutate({agentId:e.id}),disabled:w.isPending,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/10 transition-colors opacity-0 group-hover:opacity-100 disabled:opacity-50",children:r.jsx(nu,{className:"w-3.5 h-3.5"})})}),n&&r.jsx(bt,{label:"Delete agent",children:r.jsx("button",{onClick:()=>o(!0),className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors opacity-0 group-hover:opacity-100",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]})]}),r.jsxs(Me,{children:[s&&r.jsx(KMe,{agent:e,onClose:()=>i(!1)}),a&&r.jsx(YMe,{agent:e,onCancel:()=>o(!1),onConfirm:()=>{_.mutate({agentId:e.id}),o(!1)}})]})]})}function tRe(){const[e,t]=y.useState(null),[n,s]=y.useState(!1),[i,a]=y.useState(!1),[o,l]=y.useState(!1),{data:c=[],isLoading:d}=L.agents.list.useQuery(),f=L.useUtils(),p=Uo();return r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11]",children:[r.jsxs("div",{className:"max-w-4xl mx-auto px-8 py-10",children:[r.jsxs("div",{className:"flex items-center justify-between mb-8",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"Agents"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mt-0.5",children:"Your team of AI collaborators"})]}),p&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-xl border border-[#2A2A35] text-[#C8C8D4] text-[13px] font-medium hover:bg-white/5 transition-colors",children:[r.jsx(su,{className:"w-4 h-4"}),"Import",r.jsx(Jt,{className:"w-3 h-3 rotate-90 text-[#5A5A6E]"})]})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,align:"end",className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-hidden shadow-xl z-[9999] min-w-[180px]",children:[r.jsxs(Bl,{onSelect:()=>s(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(su,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Import agent"]}),r.jsxs(Bl,{onSelect:()=>l(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(wm,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Import team"]}),r.jsx(v_e,{className:"h-px bg-[#2A2A35] my-1"}),r.jsxs(Bl,{onSelect:()=>a(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(vv,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Export team"]})]})})]}),r.jsxs(gn,{to:"/agents/new",className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium hover:opacity-90 transition-opacity shadow-lg shadow-[#6366F1]/20",children:[r.jsx(wt,{className:"w-4 h-4"}),"New agent"]})]})]}),d&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[1,2,3].map(m=>r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 animate-pulse h-[180px]"},m))}),!d&&c.length===0&&r.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mb-4 text-2xl",children:"🤖"}),r.jsx("h2",{className:"text-[16px] font-semibold text-[#F0F0F5] mb-2",children:"No agents yet"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mb-6 max-w-xs",children:"Create your first AI agent and it'll be live in under 60 seconds."}),p&&r.jsxs(gn,{to:"/agents/new",className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium hover:opacity-90 transition-opacity",children:[r.jsx(wt,{className:"w-4 h-4"}),"Create agent"]})]}),!d&&c.length>0&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:c.map(m=>r.jsx(eRe,{agent:m,onOpenPanel:t,canManage:p},m.id))})]}),r.jsxs(Me,{children:[e&&r.jsx($N,{agent:e,agentColor:e.color,onClose:()=>t(null),onOverrideSet:()=>t(null)},e.id),n&&r.jsx(HMe,{onClose:()=>s(!1),onSuccess:()=>f.agents.list.invalidate()}),i&&r.jsx(WMe,{onClose:()=>a(!1)}),o&&r.jsx(qMe,{onClose:()=>l(!1),onSuccess:()=>{f.agents.list.invalidate()}})]})]})}const nRe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],sRe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16","#6366F1"],iRe=[{id:"qwen3:14b",label:"Qwen 3 14B",note:"Fast · Local · Free"},{id:"tomng/nanbeige4.1",label:"NanBeige 4.1 · 3B",note:"Agentic · Local · Free"},{id:"openrouter/anthropic/claude-sonnet-4.6",label:"Claude Sonnet",note:"Smart · Fast · $$$"},{id:"openrouter/anthropic/claude-opus-4.6",label:"Claude Opus",note:"Best · Slow · $$$$"}];function rRe({color:e,name:t,emoji:n}){const s=uh(e),i=t||"Agent",a=n||"🤖";return r.jsxs("div",{className:"rounded-xl overflow-hidden border border-[#2A2A35] bg-[#0F0F11]",children:[r.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",style:{borderLeft:`3px solid ${e}`,background:`linear-gradient(90deg, rgba(${s}, 0.08) 0%, transparent 60%)`},children:[r.jsx("span",{className:"text-lg",children:a}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:i}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:"online"})]}),r.jsx("div",{className:"ml-auto w-2 h-2 rounded-full",style:{backgroundColor:e}})]}),r.jsx("div",{className:"px-4 py-3",children:r.jsx("div",{className:"rounded-xl px-3 py-2 max-w-[75%]",style:{backgroundColor:`rgba(${s}, 0.12)`,border:`1px solid rgba(${s}, 0.2)`},children:r.jsx("p",{className:"text-[12px] text-[#C8C8D4]",children:"Ready to help. What do you need?"})})})]})}function aRe({state:e,onChange:t,onNext:n}){const s=e.name.trim().length>0&&e.role.trim().length>0;return r.jsxs("div",{className:"flex gap-8 h-full",children:[r.jsxs("div",{className:"flex-1 space-y-6",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Name"}),r.jsx("input",{value:e.name,onChange:i=>t({name:i.target.value}),placeholder:"e.g. Nova, Relay, Axiom",className:"w-full h-10 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[14px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Role"}),r.jsx("input",{value:e.role,onChange:i=>t({role:i.target.value}),placeholder:"e.g. Content Strategist, Research Analyst",className:"w-full h-10 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[14px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Emoji"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:nRe.map(i=>r.jsx("button",{onClick:()=>t({emoji:i}),className:ye("w-9 h-9 rounded-lg text-lg transition-all",e.emoji===i?"bg-[#6366F1]/20 ring-2 ring-[#6366F1] scale-110":"bg-[#1E1E24] hover:bg-[#2A2A35]"),children:i},i))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Color"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:sRe.map(i=>r.jsx("button",{onClick:()=>t({color:i}),className:ye("w-7 h-7 rounded-full transition-all",e.color===i?"ring-2 ring-offset-2 ring-offset-[#0F0F11] scale-125":"hover:scale-110"),style:{backgroundColor:i,outlineColor:i}},i))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Model"}),r.jsx("div",{className:"space-y-2",children:iRe.map(i=>r.jsxs("button",{onClick:()=>t({model:i.id}),className:ye("w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all text-left",e.model===i.id?"bg-[#6366F1]/10 border-[#6366F1]/50 text-[#F0F0F5]":"bg-[#1E1E24] border-[#2A2A35] text-[#8A8A99] hover:border-[#3A3A45] hover:text-[#C8C8D4]"),children:[r.jsx("span",{className:"text-[13px] font-medium",children:i.label}),r.jsx("span",{className:"text-[11px] opacity-60",children:i.note})]},i.id))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Visibility"}),r.jsx("div",{className:"flex gap-2",children:[{value:"public",icon:Xt,label:"Public"},{value:"private",icon:Eo,label:"Private"},{value:"owner",icon:Ia,label:"Owner only"}].map(({value:i,icon:a,label:o})=>r.jsxs("button",{onClick:()=>t({visibility:i}),className:ye("flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-xl border transition-all text-[12px] font-medium",e.visibility===i?"bg-[#6366F1]/10 border-[#6366F1]/50 text-[#F0F0F5]":"bg-[#1E1E24] border-[#2A2A35] text-[#8A8A99] hover:border-[#3A3A45] hover:text-[#C8C8D4]"),children:[r.jsx(a,{className:"w-3 h-3"}),o]},i))})]})]}),r.jsxs("div",{className:"w-[260px] flex-shrink-0 space-y-4",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Preview"}),r.jsx(rRe,{color:e.color,name:e.name,emoji:e.emoji})]}),r.jsxs("button",{onClick:n,disabled:!s,className:"w-full h-10 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium flex items-center justify-center gap-2 hover:opacity-90 transition-opacity disabled:opacity-30 disabled:cursor-not-allowed shadow-lg shadow-[#6366F1]/20",children:["Continue",r.jsx(tu,{className:"w-4 h-4"})]})]})]})}function vW({state:e,soul:t,onSoulChange:n,onNext:s,onBack:i,editMode:a,initialSoul:o}){const[l,c]=y.useState(()=>a&&o?[{role:"assistant",content:`I've loaded ${e.name}'s current soul. What would you like to change? You can say things like "make it more direct", "add a section about how to handle conflicts", or just describe the vibe you want.`}]:[]),[d,f]=y.useState(""),[p,m]=y.useState(!1),[g,b]=y.useState(""),[_,w]=y.useState(a&&!!o),A=y.useRef(null),S=y.useRef(null);y.useEffect(()=>{A.current?.scrollIntoView({behavior:"smooth"})},[l,g]);const C=y.useCallback(async(T,F)=>{m(!0),b("");const M={description:T,agentName:e.name,agentRole:e.role};F&&(M.refinement=F),a&&o&&(M.currentSoul=o);try{const I=await fetch(`${oi}/api/agents/generate-soul`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)});if(!I.ok)throw new Error("Generation failed");const H=(await I.json()).text;n(H),b(""),w(!0),c(V=>[...V,{role:"assistant",content:"Here's the soul I've written. Take a look — you can refine it by telling me what to change, or proceed when you're happy."}])}catch{c(I=>[...I,{role:"assistant",content:"Something went wrong generating the soul. Please try again."}])}finally{m(!1)}},[e.name,e.role,n,a,o]);async function E(){const T=d.trim();if(!T||p)return;f("");const F={role:"user",content:T};c(M=>[...M,F]),_?await C(T,T):await C(T)}const k=uh(e.color);return r.jsxs("div",{className:"flex gap-6 h-full min-h-0",children:[r.jsxs("div",{className:"flex flex-col w-[320px] flex-shrink-0 min-h-0",children:[r.jsxs("div",{className:"flex-1 overflow-y-auto space-y-3 pr-1 min-h-0",children:[l.length===0&&r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`rgba(${k}, 0.2)`},children:e.emoji}),r.jsx("div",{className:"flex-1 bg-[#1E1E24] rounded-xl rounded-tl-sm px-3 py-2.5",children:r.jsxs("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:["I'm going to write ",e.name,"'s soul. Describe their personality in a few sentences. What do they care about? What makes them distinct? What won't they do?"]})})]}),l.map((T,F)=>r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:ye("flex items-start gap-3",T.role==="user"&&"flex-row-reverse"),children:[T.role==="assistant"&&r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`rgba(${k}, 0.2)`},children:e.emoji}),r.jsx("div",{className:ye("flex-1 rounded-xl px-3 py-2.5",T.role==="user"?"bg-[#6366F1]/15 rounded-tr-sm ml-8":"bg-[#1E1E24] rounded-tl-sm mr-8"),children:r.jsx("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:T.content})})]},F)),p&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"flex items-center gap-2 pl-10",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce [animation-delay:0.15s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce [animation-delay:0.3s]"})]}),r.jsx("div",{ref:A})]}),r.jsxs("div",{className:"mt-3 flex gap-2",children:[r.jsx("input",{ref:S,value:d,onChange:T=>f(T.target.value),onKeyDown:T=>T.key==="Enter"&&!T.shiftKey&&E(),placeholder:_?"Refine it…":"Describe their personality…",disabled:p,className:"flex-1 h-9 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors disabled:opacity-50"}),r.jsx("button",{onClick:E,disabled:!d.trim()||p,className:"w-9 h-9 rounded-xl flex items-center justify-center transition-all disabled:opacity-30",style:{backgroundColor:`rgba(${k}, 0.2)`,color:e.color},children:p?r.jsx(Xi,{className:"w-4 h-4 animate-spin"}):r.jsx(Ji,{className:"w-4 h-4"})})]})]}),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#8A8A99] uppercase tracking-wider",children:"SOUL.md preview"}),p&&r.jsx("p",{className:"text-[11px] text-[#8A8A99] animate-pulse",children:"Generating…"})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11] border border-[#2A2A35] rounded-xl p-4 min-h-0",children:[!t&&!g&&!p&&r.jsx("p",{className:"text-[13px] text-[#5A5A6A] italic",children:"The soul will appear here as it's generated…"}),(t||g)&&r.jsx("div",{className:"prose-message text-[12px] text-[#C8C8D4] leading-relaxed",children:r.jsx(Ei,{remarkPlugins:[Fi],children:g||t})})]}),r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 h-9 px-4 rounded-xl border border-[#2A2A35] text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45] transition-colors",children:[r.jsx(gm,{className:"w-4 h-4"}),"Back"]}),r.jsxs("button",{onClick:s,disabled:!t||p,className:"flex-1 h-9 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium flex items-center justify-center gap-2 hover:opacity-90 transition-opacity disabled:opacity-30 disabled:cursor-not-allowed",children:["Looks good",r.jsx(tu,{className:"w-4 h-4"})]})]})]})]})}function oRe({title:e,content:t}){const[n,s]=y.useState(e==="SOUL.md");return r.jsxs("div",{className:"border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>s(i=>!i),className:"w-full flex items-center justify-between px-4 py-3 bg-[#1E1E24] hover:bg-[#2A2A35] transition-colors text-left",children:[r.jsx("span",{className:"text-[13px] font-mono font-medium text-[#C8C8D4]",children:e}),r.jsx(ne.span,{animate:{rotate:n?90:0},transition:{duration:.15},children:r.jsx(tu,{className:"w-3.5 h-3.5 text-[#8A8A99]"})})]}),r.jsx(Me,{children:n&&r.jsx(ne.div,{initial:{height:0},animate:{height:"auto"},exit:{height:0},transition:{duration:.2},className:"overflow-hidden",children:r.jsx("div",{className:"p-4 max-h-48 overflow-y-auto bg-[#0F0F11]",children:r.jsx("div",{className:"prose-message text-[12px] text-[#8A8A99]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:t})})})})})]})}function lRe(e){return`# IDENTITY.md — ${e.name}
|
|
355
355
|
|
|
356
356
|
- **Name:** ${e.name}
|
|
357
357
|
- **Role:** ${e.role}
|
|
@@ -432,4 +432,4 @@ Any required environment variables or binaries.
|
|
|
432
432
|
${o.trim()}`:o.trim();f.mutate({id:e.id,description:m})}}return r.jsxs("div",{className:"px-6 pb-4 border-t border-[#1E1E28]/50",children:[e.description&&r.jsx("p",{className:"text-[12px] text-[#8A8A99] mt-3 mb-3",children:e.description}),r.jsx("div",{className:"mt-2 space-y-1",children:e.tasks.map(m=>r.jsx(CW,{task:m,missionId:e.id,missionTitle:e.title,agent:m.agent??(m.agentId?t[m.agentId]:null),agentChannel:m.agent??(m.agentId?t[m.agentId]:null)?s.find(g=>g.agentId===m.agentId&&g.channelType==="dm"):void 0},m.id))}),r.jsx(XDe,{missionId:e.id}),r.jsx(i8e,{missionId:e.id}),r.jsxs("div",{className:"flex items-center gap-2 mt-3",children:[r.jsx("input",{value:o,onChange:m=>l(m.target.value),onKeyDown:m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),p())},placeholder:d.length>0?`Message all ${d.length} active agent${d.length!==1?"s":""}...`:"Add context to this mission...",className:"flex-1 bg-[#0F0F11] 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:p,disabled:!o.trim()||c.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:c.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Ji,{className:"w-3 h-3"})})]}),i&&a.length>0&&r.jsx("div",{className:"flex items-center gap-2 mt-2",children:r.jsxs("button",{onClick:n,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-[#6366F1]/10 text-[#6366F1] text-[12px] font-medium hover:bg-[#6366F1]/20 transition-colors",children:[r.jsx(Ji,{className:"w-3 h-3"}),"Dispatch ",a.length," ready task",a.length!==1?"s":""]})})]})}function XDe({missionId:e}){const{data:t}=L.missions.worktreeStatus.useQuery({missionId:e}),n=L.useUtils(),s=L.missions.mergeWorktree.useMutation({onSuccess:()=>{n.missions.worktreeStatus.invalidate({missionId:e}),n.missions.list.invalidate()}}),i=L.missions.discardWorktree.useMutation({onSuccess:()=>{n.missions.worktreeStatus.invalidate({missionId:e}),n.missions.list.invalidate()}});return t?r.jsxs("div",{className:"mt-3 flex items-center gap-2.5 px-3 py-2 rounded-md bg-[#13131A] border border-[#2A2A35]/50",children:[r.jsx(Zl,{className:"w-3.5 h-3.5 text-[#8B5CF6] flex-shrink-0"}),r.jsx("span",{className:"text-[12px] font-mono text-[#A78BFA]",children:t.branch}),t.fileCount>0&&r.jsxs("span",{className:"text-[10px] text-[#8A8A99]",children:[t.fileCount," file",t.fileCount!==1?"s":""," changed"]}),r.jsx("div",{className:"flex-1"}),r.jsxs("button",{onClick:()=>s.mutate({missionId:e}),disabled:s.isPending,className:"flex items-center gap-1 px-2 py-1 rounded text-[11px] text-[#10B981] hover:bg-[#10B981]/10 transition-colors disabled:opacity-50",children:[s.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(D5,{className:"w-3 h-3"}),"Merge"]}),r.jsxs("button",{onClick:()=>i.mutate({missionId:e}),disabled:i.isPending,className:"flex items-center gap-1 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"}),"Discard"]})]}):null}function JDe({missions:e,agentMap:t}){const{data:n=[]}=L.channels.list.useQuery(),s=L.useUtils(),i=L.missions.update.useMutation({onSuccess:()=>s.missions.list.invalidate()}),[a,o]=y.useState(null),l=[{status:"planning",label:"Planning"},{status:"active",label:"Active"},{status:"paused",label:"Paused"},{status:"completed",label:"Completed"}];function c(m){o(m.active.id)}const d=L.missions.reorderMissions.useMutation({onSuccess:()=>s.missions.list.invalidate()});function f(m){o(null);const{active:g,over:b}=m;if(!b||!g)return;const _=g.id,w=b.id,A=e.find(E=>E.id===_);if(!A)return;const S=l.map(E=>E.status);let C;if(S.includes(w))C=w;else{const E=e.find(k=>k.id===w);if(!E)return;C=E.status}if(A.status!==C){i.mutate({id:_,status:C});return}if(!S.includes(w)&&w!==_){const k=e.filter(I=>I.status===C).map(I=>I.id),T=k.indexOf(_),F=k.indexOf(w);if(T===-1||F===-1)return;const M=[...k];M.splice(T,1),M.splice(F,0,_),d.mutate({missionIds:M})}}const p=a?e.find(m=>m.id===a):null;return r.jsxs(vV,{collisionDetection:sV,onDragStart:c,onDragEnd:f,children:[r.jsx("div",{className:"flex-1 overflow-x-auto overflow-y-hidden",children:r.jsx("div",{className:"flex gap-4 px-6 py-4 h-full min-w-max",children:l.map(m=>{const g=e.filter(b=>b.status===m.status);return r.jsx(ZDe,{status:m.status,label:m.label,count:g.length,children:r.jsx(sN,{items:g.map(b=>b.id),strategy:SV,children:g.map(b=>r.jsx(e8e,{mission:b,agentMap:t,channels:n},b.id))})},m.status)})})}),r.jsx(wV,{children:p&&r.jsxs("div",{className:"w-[280px] bg-[#16161A] border border-[#6366F1]/40 rounded-lg p-3 shadow-2xl rotate-2 opacity-90",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:My[p.priority]}}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5] font-medium truncate",children:p.title})]}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E] mt-1 block",children:[p.tasks.length," tasks"]})]})})]})}function ZDe({status:e,label:t,count:n,children:s}){const{setNodeRef:i,isOver:a}=_V({id:e});return r.jsxs("div",{ref:i,className:ye("w-[300px] flex flex-col flex-shrink-0 rounded-lg transition-colors",a&&"bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20"),children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 mb-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:Qi[e]}}),r.jsx("span",{className:"text-[12px] font-medium text-[#8A8A99] uppercase tracking-wider",children:t}),r.jsx("span",{className:"text-[10px] text-[#3A3A45] ml-1",children:n})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 px-1 min-h-[60px]",children:[s,n===0&&r.jsx("div",{className:"flex items-center justify-center py-8 text-[#2A2A35]",children:r.jsx("span",{className:"text-[11px]",children:"Drop here"})})]})]})}function e8e({mission:e,agentMap:t,channels:n}){const{attributes:s,listeners:i,setNodeRef:a,transform:o,transition:l,isDragging:c}=iN({id:e.id}),d={transform:Oo.Transform.toString(o),transition:l},[f,p]=y.useState(""),[m,g]=y.useState(!1),b=L.messages.send.useMutation({onSuccess:()=>p("")}),_=L.missions.update.useMutation({onSuccess:()=>L.useUtils().missions.list.invalidate()}),w=e.priority,A=e.tasks.length,S=e.tasks.filter(F=>F.status==="completed").length,C=e.tasks.filter(F=>F.status==="working"||F.status==="dispatched").length,E=[...new Set(e.tasks.map(F=>F.agentId).filter(Boolean))].map(F=>t[F]??e.tasks.find(M=>M.agentId===F)?.agent).filter(Boolean),k=[...new Set(e.tasks.filter(F=>F.status==="working"||F.status==="dispatched"||F.status==="completed").map(F=>F.agentId).filter(Boolean))];function T(){if(f.trim())if(k.length>0){const F=`[Mission: ${e.title}] ${f.trim()}`;for(const M of k){const I=n.find(R=>R.agentId===M&&R.channelType==="dm");I&&b.mutate({channelId:I.id,content:F})}p("")}else{const F=e.description?`${e.description}
|
|
433
433
|
${f.trim()}`:f.trim();_.mutate({id:e.id,description:F}),p("")}}return r.jsxs("div",{ref:a,style:d,...s,className:ye("bg-[#16161A] border border-[#2A2A35] rounded-lg hover:border-[#3A3A45] transition-colors",c&&"opacity-40 ring-2 ring-[#6366F1]/30"),children:[r.jsxs("div",{...i,className:"flex items-start gap-2 p-3 pb-0 cursor-grab active:cursor-grabbing group/header",children:[r.jsx(dL,{className:"w-3 h-3 mt-0.5 text-[#2A2A35] group-hover/header:text-[#5A5A6E] transition-colors flex-shrink-0"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-1.5 flex-shrink-0",style:{backgroundColor:My[w]}}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5] font-medium leading-tight flex-1",children:e.title}),e.ephemeralNodeId&&r.jsx("span",{className:"text-[8px] px-1 py-0.5 rounded bg-[#10B981]/15 text-[#10B981] font-medium uppercase tracking-wider flex-shrink-0",children:"ephemeral"})]}),r.jsxs("div",{className:"px-3 pb-3",children:[e.description&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1 mb-2 line-clamp-2 pl-6",children:e.description}),A>0&&r.jsxs("div",{className:"space-y-1 mt-2 mb-2",children:[(m?e.tasks:e.tasks.slice(0,3)).map(F=>{const M=F.agent??(F.agentId?t[F.agentId]:null),I=M?n.find(R=>R.agentId===M.id&&R.channelType==="dm"):void 0;return r.jsx(CW,{task:F,missionId:e.id,missionTitle:e.title,agent:M,agentChannel:I,compact:!0},F.id)}),e.tasks.length>3&&r.jsx("button",{onClick:()=>g(!m),className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] pl-5 transition-colors",children:m?"Show less":`+${e.tasks.length-3} more`}),(()=>{const F=e.tasks.filter(M=>M.status==="completed"&&M.agentTasks?.some(I=>I.result));return F.length===0?null:r.jsxs("div",{className:"flex items-center gap-1 pl-5 mt-0.5",children:[r.jsx(Fe,{className:"w-2.5 h-2.5 text-[#10B981]"}),r.jsxs("span",{className:"text-[10px] text-[#10B981]",children:[F.length," result",F.length!==1?"s":""," available"]})]})})()]}),r.jsxs("div",{className:"flex items-center gap-1.5 mt-2",children:[r.jsx("input",{value:f,onChange:F=>p(F.target.value),onKeyDown:F=>{F.key==="Enter"&&!F.shiftKey&&(F.preventDefault(),T())},placeholder:k.length>0?`Message ${k.length} agent${k.length!==1?"s":""}...`:"Add context...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded px-2 py-1 text-[10px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"}),r.jsx("button",{onClick:T,disabled:!f.trim()||b.isPending,className:"p-1 rounded text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors disabled:opacity-30",children:b.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Ji,{className:"w-3 h-3"})})]}),r.jsxs("div",{className:"flex items-center gap-2 pt-2 mt-2 border-t border-[#2A2A35]/50",children:[r.jsx("div",{className:"flex -space-x-1",children:E.slice(0,3).map((F,M)=>F&&r.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[9px] border border-[#16161A]",style:{backgroundColor:F.color+"20",zIndex:3-M},children:F.emoji},F.id))}),r.jsx("div",{className:"flex-1"}),A>0&&r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("div",{className:"w-12 h-1 bg-[#1E1E28] rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full",style:{width:`${S/A*100}%`,backgroundColor:Qi[e.status]}})}),r.jsxs("span",{className:"text-[9px] text-[#5A5A6E] tabular-nums",children:[S,"/",A]})]}),C>0&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[9px] text-[#6366F1]",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-[#6366F1] animate-pulse"}),C]})]})]})]})}function t8e({missions:e,agentMap:t}){return r.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:e.map(n=>r.jsx(n8e,{mission:n,agentMap:t},n.id))})}function n8e({mission:e,agentMap:t}){const{data:n}=L.dashboard.timeline.useQuery({missionId:e.id}),s=e.status;return r.jsxs("div",{className:"mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:Qi[s]}}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:e.title}),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{color:Qi[s],backgroundColor:Qi[s]+"15"},children:nv[s]})]}),r.jsx("div",{className:"space-y-1 pl-4 border-l-2 border-[#2A2A35]",children:(n?.tasks??e.tasks).map(i=>{const a=i.agent??(i.agentId?t[i.agentId]:null),o=i.status;return r.jsxs("div",{className:"flex items-center gap-2 py-1",children:[r.jsx(jW,{status:i.status}),a&&r.jsx("span",{className:"text-[11px]",children:a.emoji}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] flex-1 truncate",children:i.title}),"startedAt"in i&&i.startedAt&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E] font-mono",children:new Date(i.startedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),"completedAt"in i&&i.completedAt&&r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:["→ ",new Date(i.completedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]}),r.jsx("span",{className:"text-[10px] px-1 py-0.5 rounded",style:{color:Qi[o]??"#8A8A99",backgroundColor:(Qi[o]??"#8A8A99")+"10"},children:i.status})]},i.id)})}),n?.events&&n.events.length>0&&r.jsx("div",{className:"mt-2 pl-4 space-y-0.5",children:n.events.slice(-8).map((i,a)=>r.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-[#5A5A6E]",children:[r.jsx("span",{className:"font-mono",children:new Date(i.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}),r.jsx("span",{className:ye(i.type.includes("completed")?"text-[#10B981]":i.type.includes("failed")?"text-[#EF4444]":i.type.includes("dispatched")?"text-[#6366F1]":"text-[#8A8A99]"),children:i.type.replace(/_/g," ")}),i.agentEmoji&&r.jsx("span",{children:i.agentEmoji}),i.taskTitle&&r.jsx("span",{className:"text-[#8A8A99] truncate",children:i.taskTitle}),i.detail&&r.jsxs("span",{className:"text-[#5A5A6E]",children:["(",i.detail,")"]})]},a))})]})}function s8e({agentId:e,onClose:t}){const{data:n}=L.dashboard.agentPerformance.useQuery({agentId:e}),{data:s=[]}=L.agents.list.useQuery(),i=s.find(o=>o.id===e);if(!n||!i)return null;const a=n.successRate!==null?Math.round(n.successRate*100):null;return r.jsxs(ne.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"absolute right-4 top-16 w-[280px] bg-[#16161A] border border-[#2A2A35] rounded-xl shadow-2xl z-30 overflow-hidden",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35] flex items-center gap-2",children:[r.jsx("span",{className:"w-7 h-7 rounded-full flex items-center justify-center text-[14px]",style:{backgroundColor:i.color+"20"},children:i.emoji}),r.jsxs("div",{className:"flex-1",children:[r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:i.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:i.role})]}),r.jsx("button",{onClick:t,className:"text-[#5A5A6E] hover:text-[#C8C8D4]",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),r.jsxs("div",{className:"px-4 py-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Success rate"}),r.jsx("span",{className:ye("text-[13px] font-medium",a!==null&&a>=80?"text-[#10B981]":a!==null&&a>=50?"text-[#F59E0B]":"text-[#EF4444]"),children:a!==null?`${a}%`:"—"})]}),r.jsx("div",{className:"h-1.5 bg-[#1E1E28] rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${a??0}%`,backgroundColor:(a??0)>=80?"#10B981":(a??0)>=50?"#F59E0B":"#EF4444"}})}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsxs("div",{className:"bg-[#0F0F11] rounded-lg px-2.5 py-2",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:"Completed"}),r.jsx("span",{className:"text-[14px] font-medium text-[#F0F0F5]",children:n.delegationsCompleted})]}),r.jsxs("div",{className:"bg-[#0F0F11] rounded-lg px-2.5 py-2",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:"Failed"}),r.jsx("span",{className:"text-[14px] font-medium text-[#EF4444]",children:n.delegationsFailed})]}),r.jsxs("div",{className:"bg-[#0F0F11] rounded-lg px-2.5 py-2",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:"Avg time"}),r.jsx("span",{className:"text-[14px] font-medium text-[#F0F0F5]",children:n.avgCompletionMs?`${Math.round(n.avgCompletionMs/1e3)}s`:"—"})]}),r.jsxs("div",{className:"bg-[#0F0F11] rounded-lg px-2.5 py-2",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:"Cost (7d)"}),r.jsxs("span",{className:"text-[14px] font-medium text-[#F0F0F5]",children:["$",n.costWeek.toFixed(2)]})]})]}),r.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Last dream"}),r.jsx("span",{className:"text-[#C8C8D4]",children:n.lastDreamAt?new Date(n.lastDreamAt).toLocaleDateString():"Never"})]}),n.dreamInsights>0&&r.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Dream insights"}),r.jsxs("span",{className:"text-[#8B5CF6]",children:[n.dreamInsights," notes"]})]}),Object.keys(n.bySource).length>0&&r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block mb-1",children:"Sources (7d)"}),r.jsx("div",{className:"flex gap-2",children:Object.entries(n.bySource).map(([o,l])=>r.jsxs("span",{className:"text-[10px] text-[#8A8A99] bg-[#0F0F11] px-1.5 py-0.5 rounded",children:[o,": ",l.calls," calls · $",l.cost.toFixed(2)]},o))})]}),n.currentTasks.length>0&&r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block mb-1",children:"Active tasks"}),n.currentTasks.map(o=>r.jsx("div",{className:"text-[11px] text-[#C8C8D4] truncate py-0.5",children:o.task.slice(0,60)},o.id))]})]})]})}function i8e({missionId:e}){const{data:t}=L.files.listMissionDeliverables.useQuery({missionId:e}),n=t?.files??[];if(n.length===0)return null;const s={};for(const a of n)s[a.category]=(s[a.category]??0)+1;const i={structured:ym,code:rL,images:hL,documents:li};return r.jsx("div",{className:"mt-3 px-3 py-2 rounded-md bg-[#13131A] border border-[#2A2A35]/50",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(li,{className:"w-3.5 h-3.5 text-[#8A8A99] flex-shrink-0"}),r.jsxs("span",{className:"text-[12px] text-[#C8C8D4]",children:[n.length," deliverable",n.length!==1?"s":""]}),r.jsx("div",{className:"flex-1"}),r.jsx("div",{className:"flex items-center gap-2",children:Object.entries(s).map(([a,o])=>{const l=i[a]??li;return r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-[#5A5A6E]",children:[r.jsx(l,{className:"w-3 h-3"}),o]},a)})})]})})}function CW({task:e,missionId:t,missionTitle:n,agent:s,agentChannel:i,compact:a}){const o=an(),[l,c]=y.useState(!1),[d,f]=y.useState(""),p=e.status,m=L.useUtils(),g=L.missions.updateTask.useMutation({onSuccess:()=>{m.missions.list.invalidate(),f(""),c(!1)}}),b=L.messages.send.useMutation({onSuccess:()=>{f(""),c(!1)}});function _(){d.trim()&&(e.status==="pending"?g.mutate({missionTaskId:e.id,instruction:d.trim()}):i&&(e.status==="working"||e.status==="dispatched"||e.status==="completed")?b.mutate({channelId:i.id,content:`[Mission: ${n}] ${d.trim()}`}):e.status==="failed"&&e.agentId&&g.mutate({missionTaskId:e.id,instruction:d.trim(),status:"pending"}))}const w=e.status==="pending"?"Edit instruction before dispatch...":e.status==="failed"?"Fix instruction and retry...":e.status==="completed"?"Request revision...":"Send context to agent...",A=g.isPending||b.isPending;return r.jsxs("div",{className:"rounded-md bg-[#13131A]",children:[r.jsxs("div",{className:"flex items-center gap-2.5 py-1.5 px-3",children:[r.jsx(jW,{status:e.status}),r.jsx("button",{onClick:S=>{S.stopPropagation(),i&&o(`/channels/${i.id}`)},className:"text-[12px] text-[#C8C8D4] flex-1 truncate text-left hover:text-[#6366F1] transition-colors",title:i?"Open agent chat":e.title,children:e.title}),e.status==="completed"&&r.jsx("button",{onClick:S=>{S.stopPropagation(),o(`/deliverables?mission=${t}`)},className:"text-[#5A5A6E] hover:text-[#10B981] transition-colors",title:"View deliverables",children:r.jsx(lL,{className:"w-3 h-3"})}),r.jsx("button",{onClick:S=>{S.stopPropagation(),c(!l)},className:ye("transition-colors",l?"text-[#6366F1]":"text-[#3A3A45] hover:text-[#8A8A99]"),title:e.status==="pending"?"Edit instruction":e.status==="failed"?"Fix & retry":e.status==="completed"?"Request revision":"Send context to agent",children:r.jsx(Yse,{className:"w-3 h-3"})}),s&&r.jsxs("button",{onClick:S=>{S.stopPropagation(),i&&o(`/channels/${i.id}`)},className:"flex items-center gap-1 text-[11px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",title:`Open ${s.name}'s chat`,children:[r.jsx("span",{children:s.emoji}),!a&&r.jsx("span",{children:s.name})]}),!s&&e.status==="pending"&&!a&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E] italic",children:"unassigned"}),!a&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{color:Qi[p]??"#8A8A99",backgroundColor:(Qi[p]??"#8A8A99")+"10"},children:e.status}),!a&&r.jsx(a8e,{taskId:e.id,status:e.status,missionId:t})]}),r.jsx(Me,{children:l&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 pb-2 pt-1",children:[r.jsx("input",{autoFocus:!0,value:d,onChange:S=>f(S.target.value),onKeyDown:S=>{S.key==="Enter"&&!S.shiftKey&&(S.preventDefault(),_()),S.key==="Escape"&&c(!1)},placeholder:w,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded px-2.5 py-1.5 text-[11px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"}),r.jsx("button",{onClick:_,disabled:!d.trim()||A,className:"px-2 py-1.5 rounded bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 transition-colors disabled:opacity-30",children:A?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Ji,{className:"w-3 h-3"})}),e.status==="failed"&&d.trim()&&r.jsx("button",{onClick:()=>{g.mutate({missionTaskId:e.id,instruction:d.trim(),status:"pending"})},disabled:A,className:"px-2 py-1.5 rounded bg-[#F59E0B]/10 text-[#F59E0B] text-[10px] hover:bg-[#F59E0B]/20 transition-colors disabled:opacity-30",children:"Retry"})]})})}),!a&&r.jsx(r8e,{task:e,agent:s})]})}function r8e({task:e,agent:t}){const[n,s]=y.useState(!1),i=e.agentTasks?.find(d=>d.status==="completed"||d.status==="failed"),a=i?.result;if(e.status!=="completed"||!a)return null;const o=a.split(`
|
|
434
434
|
`),l=o.length>5,c=l&&!n?o.slice(0,5).join(`
|
|
435
|
-
`):a;return r.jsxs("div",{className:"mx-3 mb-2 rounded-md bg-[#0F0F11] border border-[#2A2A35]/50 p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-[#8A8A99]",children:[r.jsx("span",{children:t.emoji}),r.jsx("span",{children:t.name})]}),i?.crossInstance&&i.federationNodeName&&r.jsxs("span",{className:"flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded bg-[#6366F1]/10 text-[#818CF8]",children:[r.jsx(Xt,{className:"w-2.5 h-2.5"}),i.federationNodeName]}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:"Result"})]}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap break-words leading-relaxed font-mono",children:c}),l&&r.jsx("button",{onClick:()=>s(!n),className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] mt-1.5 transition-colors",children:n?"Collapse":`Show full result (${o.length} lines)`})]})}function a8e({taskId:e,status:t}){const[n,s]=y.useState(!1),i=L.useUtils(),a=L.missions.removeTask.useMutation({onSuccess:()=>{i.missions.list.invalidate(),s(!1)}}),o=L.missions.updateTask.useMutation({onSuccess:()=>{i.missions.list.invalidate(),s(!1)}});return r.jsxs("div",{className:"relative",children:[r.jsx("button",{onClick:l=>{l.stopPropagation(),s(!n)},className:"text-[#3A3A45] hover:text-[#8A8A99] transition-colors p-0.5",children:r.jsx(iL,{className:"w-3 h-3"})}),n&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-20",onClick:()=>s(!1)}),r.jsxs("div",{className:"absolute right-0 top-5 z-30 bg-[#1A1A24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[140px]",children:[t==="pending"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),s(!1)},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#C8C8D4] hover:bg-white/5 transition-colors",children:"Edit instruction"}),(t==="working"||t==="dispatched")&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"cancelled"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#F59E0B] hover:bg-[#F59E0B]/10 transition-colors",children:"Cancel task"}),t==="failed"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"pending"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors",children:"Retry task"}),t==="completed"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"pending"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#8A8A99] hover:bg-white/5 transition-colors",children:"Re-open"}),r.jsx("button",{onClick:l=>{l.stopPropagation(),a.mutate({missionTaskId:e})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors",children:"Remove"})]})]})]})}function jW({status:e}){switch(e){case"completed":return r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"});case"failed":return r.jsx(Te,{className:"w-3.5 h-3.5 text-[#EF4444]"});case"working":case"dispatched":return r.jsx(Pe,{className:"w-3.5 h-3.5 text-[#6366F1] animate-spin"});case"review":return r.jsx(ql,{className:"w-3.5 h-3.5 text-[#F59E0B]"});case"cancelled":return r.jsx(Te,{className:"w-3.5 h-3.5 text-[#5A5A6E]"});default:return r.jsx("div",{className:"w-3.5 h-3.5 rounded-full border border-[#3A3A45]"})}}function o8e({open:e,onClose:t,onCreated:n}){const[s,i]=y.useState(""),[a,o]=y.useState(""),[l,c]=y.useState("normal"),d=L.missions.create.useMutation({onSuccess:()=>n()});return r.jsx(ji,{open:e,onOpenChange:f=>{f||t()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-50"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[460px] bg-[#16161A] border border-[#2A2A35] rounded-xl p-6 z-50 shadow-2xl",children:[r.jsx(nr,{className:"text-[15px] font-medium text-[#F0F0F5] mb-4",children:"New Mission"}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Title"}),r.jsx("input",{autoFocus:!0,value:s,onChange:f=>i(f.target.value),placeholder:"What needs to be done?",className:"w-full px-3 py-2 bg-[#0F0F11] border border-[#2A2A35] rounded-md text-[13px] text-[#F0F0F5] placeholder-[#3A3A45] focus:outline-none focus:border-[#6366F1]",onKeyDown:f=>{f.key==="Enter"&&s.trim()&&d.mutate({title:s.trim(),description:a.trim()||void 0,priority:l})}})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Description"}),r.jsx("textarea",{value:a,onChange:f=>o(f.target.value),placeholder:"Optional details...",rows:3,className:"w-full px-3 py-2 bg-[#0F0F11] border border-[#2A2A35] rounded-md text-[13px] text-[#F0F0F5] placeholder-[#3A3A45] focus:outline-none focus:border-[#6366F1] resize-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Priority"}),r.jsx("div",{className:"flex gap-2",children:["low","normal","high","critical"].map(f=>r.jsx("button",{onClick:()=>c(f),className:ye("px-3 py-1.5 rounded-md text-[12px] font-medium transition-colors",l===f?"text-white":"text-[#5A5A6E] bg-[#1E1E28] hover:text-[#8A8A99]"),style:l===f?{backgroundColor:My[f]}:void 0,children:SW[f]},f))})]})]}),r.jsxs("div",{className:"flex items-center justify-end gap-2 mt-5",children:[r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-md text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] transition-colors",children:"Cancel"})}),r.jsxs("button",{onClick:()=>{s.trim()&&d.mutate({title:s.trim(),description:a.trim()||void 0,priority:l})},disabled:!s.trim()||d.isPending,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-md bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E6] transition-colors disabled:opacity-50",children:[d.isPending&&r.jsx(Pe,{className:"w-3 h-3 animate-spin"}),"Create Mission"]})]})]})]})})}const l8e=4;function c8e({current:e}){return r.jsx("div",{className:"flex items-center gap-2",children:Array.from({length:l8e}).map((t,n)=>r.jsx("div",{className:ye("rounded-full transition-all duration-300",n<e?"w-2 h-2 bg-[#6366F1]":n===e?"w-6 h-2 bg-[#6366F1]":"w-2 h-2 bg-[#2A2A35]")},n))})}function Vd({children:e}){return r.jsx(ne.div,{initial:{opacity:0,x:24},animate:{opacity:1,x:0},exit:{opacity:0,x:-24},transition:{duration:.22,ease:[.16,1,.3,1]},className:"w-full max-w-lg mx-auto",children:e})}function lO({onDetected:e,alreadyRunning:t}){const[n,s]=y.useState("."),i=L.onboarding.pollOpenClaw.useQuery(void 0,{refetchInterval:3e3,refetchOnWindowFocus:!1,retry:!1});return y.useEffect(()=>{t||i.data?.running&&e()},[i.data?.running]),y.useEffect(()=>{const a=setInterval(()=>s(o=>o.length>=3?".":o+"."),500);return()=>clearInterval(a)},[]),i.data?.running?r.jsxs("div",{className:"flex items-center gap-2 mt-4 text-[12px] text-emerald-400",children:[r.jsx(sa,{className:"w-3.5 h-3.5"}),"OpenClaw detected — advancing…"]}):r.jsxs("div",{className:"flex items-center gap-2 mt-4 text-[12px] text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),"Waiting for OpenClaw",n]})}function IC({code:e}){const[t,n]=y.useState(!1);function s(){navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)}return r.jsxs("div",{className:"flex items-center justify-between bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 font-mono text-[12px] text-[#C8C8D4]",children:[r.jsx("span",{children:e}),r.jsx("button",{onClick:s,className:ye("ml-3 flex-shrink-0 transition-colors",t?"text-emerald-400":"text-[#5A5A6E] hover:text-[#C8C8D4]"),children:t?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Po,{className:"w-3.5 h-3.5"})})]})}function u8e({onNext:e,onSkip:t}){const{data:n,isLoading:s}=L.onboarding.checkOpenClaw.useQuery(void 0,{refetchOnWindowFocus:!1,retry:!1}),i=L.onboarding.skipOpenClaw.useMutation(),[a,o]=y.useState(!1),[l,c]=y.useState("docker"),[d,f]=y.useState(void 0);n?.runMode&&n.runMode!==d&&(f(n.runMode),n.runMode==="docker"?c("npm"):n.runMode==="npm"&&c("docker"));const[p,m]=y.useState(""),[g,b]=y.useState(!1),[_,w]=y.useState(""),[A,S]=y.useState(""),[C,E]=y.useState("idle"),k=L.onboarding.saveWaitlistEmail.useMutation(),T=L.onboarding.testConnection.useMutation();if(s)return r.jsx(Vd,{children:r.jsxs("div",{className:"flex items-center gap-3 py-8",children:[r.jsx(Pe,{className:"w-4 h-4 animate-spin text-[#6366F1]"}),r.jsx("span",{className:"text-[14px] text-[#8A8A99]",children:"Checking OpenClaw…"})]})});async function F(){await i.mutateAsync(),t()}async function M(){if(!_.trim()||!A.trim())return;E("testing");const q=await T.mutateAsync({url:_.trim(),token:A.trim()});E(q.ok?"ok":"fail"),q.ok&&setTimeout(()=>e(),1e3)}async function I(){p.trim()&&(await k.mutateAsync({email:p.trim()}),b(!0))}const R=n?.running===!0,H=n?.runMode??null,K=[{id:"docker",label:"Docker",sub:"Agents run isolated",badge:"Recommended"},{id:"npm",label:"Local (npm)",sub:"Best for dedicated machines",badge:null},{id:"cloud",label:"Cloud (VPS)",sub:"Always-on, team access",badge:null}].filter(q=>q.id!==H);return R&&!a?r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Connect OpenClaw"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"damn.dev runs agents through OpenClaw, the local AI gateway."}),r.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-6",children:[r.jsx(sa,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("p",{className:"text-[13px] font-medium text-emerald-400",children:["OpenClaw detected",H==="docker"?" via Docker":H==="cloud"?" via Cloud":H==="npm"?" locally":""]}),(n.agentCount??0)>0&&r.jsxs("p",{className:"text-[11px] text-emerald-400/70",children:[n.agentCount," agent",n.agentCount!==1?"s":""," detected"]})]})]}),r.jsxs("button",{onClick:e,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] transition-colors mb-4",children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),r.jsx("button",{onClick:()=>o(!0),className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Want to connect to a different instance?"})]}):r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Connect OpenClaw"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"damn.dev runs agents through OpenClaw, the local AI gateway."}),R&&a&&r.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-4",children:[r.jsx(sa,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),r.jsx("div",{className:"flex-1",children:r.jsxs("p",{className:"text-[13px] font-medium text-emerald-400",children:["OpenClaw is running",H==="docker"?" via Docker":H==="cloud"?" via Cloud":H==="npm"?" locally":""]})}),r.jsxs("button",{onClick:e,className:"ml-auto flex items-center gap-1 text-[12px] font-medium text-emerald-400 hover:text-emerald-300 transition-colors flex-shrink-0",children:["Continue ",r.jsx(Jt,{className:"w-3 h-3"})]})]}),r.jsx("div",{className:ye("grid gap-3 mb-4",K.length===2?"grid-cols-2":"grid-cols-3"),children:K.map(q=>r.jsxs("button",{onClick:()=>c(q.id),className:ye("relative text-left rounded-2xl p-4 border transition-all",l===q.id?"border-[#6366F1]/50 bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] bg-[#16161A] hover:border-[#3A3A45]"),children:[q.badge&&r.jsx("span",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[9px] font-semibold bg-[#6366F1] text-white tracking-wide",children:q.badge}),r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mt-1",children:q.label}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:q.sub})]},q.id))}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 mb-4",children:[l==="docker"&&r.jsxs("div",{children:[r.jsxs("a",{href:"https://www.docker.com/products/docker-desktop/",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg border border-[#2A2A35] text-[13px] text-[#C8C8D4] hover:border-[#3A3A45] hover:text-[#F0F0F5] transition-colors mb-3",children:[r.jsx(cs,{className:"w-3.5 h-3.5"}),"Download Docker Desktop"]}),r.jsx("button",{onClick:()=>window.open("http://localhost:3001/setup/docker-compose.yml","_blank"),className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg bg-[#6366F1]/10 border border-[#6366F1]/30 text-[13px] text-[#6366F1] hover:bg-[#6366F1]/20 transition-colors mb-4",children:"Download docker-compose.yml"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] leading-relaxed",children:"Open Docker Desktop → Compose → Open File → Run"}),r.jsx(lO,{onDetected:e,alreadyRunning:R})]}),l==="npm"&&r.jsxs("div",{children:[r.jsxs("div",{className:"space-y-2 mb-4",children:[r.jsx(IC,{code:"npm install -g openclaw"}),r.jsx(IC,{code:"openclaw start"})]}),r.jsx(lO,{onDetected:e,alreadyRunning:R})]}),l==="cloud"&&r.jsxs("div",{className:"space-y-5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4] mb-1",children:"Want OpenClaw fully managed in the cloud?"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mb-3",children:"Join the waitlist for cloud.damn.dev."}),g?r.jsx("p",{className:"text-[12px] text-emerald-400",children:"You're on the list. We'll notify you when cloud.damn.dev launches."}):r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"email",value:p,onChange:q=>m(q.target.value),placeholder:"you@example.com",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:I,disabled:!p.trim()||k.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:k.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):"Join waitlist"})]})]}),r.jsxs("div",{className:"border-t border-[#2A2A35] pt-5",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4] mb-3",children:"Already running on a VPS?"}),r.jsxs("div",{className:"space-y-2 mb-3",children:[r.jsx("input",{type:"url",value:_,onChange:q=>{w(q.target.value),E("idle")},placeholder:"https://openclaw.myserver.com",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("input",{type:"password",value:A,onChange:q=>{S(q.target.value),E("idle")},placeholder:"Bearer token",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"})]}),r.jsxs("button",{onClick:M,disabled:!_.trim()||!A.trim()||C==="testing"||C==="ok",className:"flex items-center gap-2 px-4 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors",children:[C==="testing"&&r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),C==="ok"&&r.jsx(Fe,{className:"w-3.5 h-3.5 text-emerald-400"}),C==="fail"&&r.jsx(Te,{className:"w-3.5 h-3.5 text-red-400"}),C==="ok"?"Connected":"Test connection"]})]})]})]}),r.jsx("button",{onClick:F,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"I'll connect OpenClaw later →"})]})}function d8e({onDetected:e}){const[t,n]=y.useState("."),s=L.onboarding.pollOllama.useQuery(void 0,{refetchInterval:3e3,refetchOnWindowFocus:!1,retry:!1});return y.useEffect(()=>{s.data?.running&&s.data.models.length>0&&e(s.data.models)},[s.data?.running]),y.useEffect(()=>{const i=setInterval(()=>n(a=>a.length>=3?".":a+"."),500);return()=>clearInterval(i)},[]),s.data?.running?r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-[12px] text-emerald-400",children:[r.jsx(sa,{className:"w-3.5 h-3.5"}),"Ollama detected"]}):r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-[12px] text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),"Waiting for Ollama",t]})}function h8e({onNext:e,onSkip:t}){const[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(""),[c,d]=y.useState(""),[f,p]=y.useState(null),[m,g]=y.useState(null),[b,_]=y.useState(!1),[w,A]=y.useState(null),[S,C]=y.useState(null),[E,k]=y.useState(""),[T,F]=y.useState(""),[M,I]=y.useState(""),[R,H]=y.useState(""),[V,K]=y.useState([]),[q,$]=y.useState(!1),B=y.useRef(null),{data:Y,isLoading:U}=L.onboarding.checkModels.useQuery(void 0,{refetchOnWindowFocus:!1,retry:!1}),{data:W}=L.onboarding.getState.useQuery(void 0,{refetchOnWindowFocus:!1});y.useEffect(()=>{Y?.envOpenRouterConfigured&&!w&&(A({valid:!0,modelCount:Y.openRouterModelCount??0,suggestedReasoningModel:W?.defaultReasoningModel??null,suggestedFastModel:W?.defaultFastModel??null}),s("sk-or-v1-••••••••••••••••••••••••••••••••"),W?.defaultReasoningModel&&!E&&k(W.defaultReasoningModel),W?.defaultFastModel&&!T&&F(W.defaultFastModel)),(Y?.ollamaModels?.length??0)>0&&K(Y.ollamaModels)},[Y?.envOpenRouterConfigured,Y?.ollamaModels?.length,W?.defaultReasoningModel]);const O=L.onboarding.validateApiKey.useMutation(),D=L.onboarding.setDefaultModels.useMutation();function Q(me){me.suggestedReasoningModel&&!E&&k(me.suggestedReasoningModel),me.suggestedFastModel&&!T&&F(me.suggestedFastModel)}async function z(){if(!n.trim())return;const me=await O.mutateAsync({provider:"openrouter",key:n.trim()});A(me),me.valid&&Q(me)}async function J(){if(!i.trim())return;const me=await O.mutateAsync({provider:"anthropic",key:i.trim()});C(me),me.valid&&Q(me)}async function ee(){if(!o.trim())return;const me=await O.mutateAsync({provider:"openai",key:o.trim()});p(me),me.valid&&Q(me)}async function re(){if(!c.trim())return;const me=await O.mutateAsync({provider:"gemini",key:c.trim()});g(me),me.valid&&Q(me)}const oe=V.length>0,se=oe||w?.valid===!0||S?.valid===!0||f?.valid===!0||m?.valid===!0||Y?.envOpenRouterConfigured===!0,ae=[];if(oe)for(const me of V)ae.push({id:me,label:me,group:"Ollama"});if(w?.valid){const me=[{id:"anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6"},{id:"anthropic/claude-opus-4.6",label:"Claude Opus 4.6"},{id:"anthropic/claude-haiku-4.5",label:"Claude Haiku 4.5"},{id:"openai/gpt-4o",label:"GPT-4o"},{id:"openai/gpt-4o-mini",label:"GPT-4o mini"},{id:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro"},{id:"google/gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"meta-llama/llama-3.3-70b-instruct:free",label:"Llama 3.3 70B (free)"}];for(const $e of me)ae.push({...$e,group:"OpenRouter"})}if(S?.valid){const me=[{id:"anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6"},{id:"anthropic/claude-opus-4.6",label:"Claude Opus 4.6"},{id:"anthropic/claude-haiku-4.5",label:"Claude Haiku 4.5"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"Anthropic"})}if(f?.valid){const me=[{id:"openai/gpt-4o",label:"GPT-4o"},{id:"openai/gpt-4o-mini",label:"GPT-4o mini"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"OpenAI"})}if(m?.valid){const me=[{id:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro"},{id:"google/gemini-2.5-flash",label:"Gemini 2.5 Flash"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"Google"})}const le=se&&ae.length>0,je=(Y?.ramGb??0)>=8,Ee=Y?.recommendedLocalModel??null,de=Y?.recommendedModelSize??null;return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-1",children:"Configure models"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-4 leading-relaxed",children:"Connect at least one model source for your agents to use."}),r.jsxs("div",{className:"space-y-2.5 mb-4",children:[r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Ollama (local)"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mt-0.5",children:"Free, runs on your machine"})]}),U?r.jsx("div",{className:"w-4 h-4 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):oe?r.jsxs("span",{className:"text-[11px] text-emerald-400 font-medium",children:[V.length," model",V.length!==1?"s":""]}):r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"Not detected"})]}),oe?r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[V.slice(0,6).map(me=>r.jsx("span",{className:"px-2 py-0.5 rounded-md text-[11px] font-medium bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:me},me)),V.length>6&&r.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[11px] text-[#8A8A99]",children:["+",V.length-6," more"]})]}):!U&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"rounded-xl border border-[#2A2A35] bg-[#0F0F11] p-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4]",children:"Get started with OpenRouter"}),r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-semibold bg-[#6366F1]/15 text-[#6366F1] border border-[#6366F1]/20",children:"No install needed"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mb-2",children:"Free models available. The fastest way to get running."}),r.jsx("button",{onClick:()=>B.current?.focus(),className:"text-[12px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"Go to OpenRouter section ↓"})]}),r.jsx("button",{onClick:()=>$(me=>!me),className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:q?"Hide local install ↑":"Prefer fully local? →"}),q&&r.jsx("div",{className:"rounded-xl border border-[#2A2A35] bg-[#0F0F11] p-3 space-y-3",children:je?r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://ollama.com",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg border border-[#2A2A35] text-[13px] text-[#C8C8D4] hover:border-[#3A3A45] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(cs,{className:"w-3.5 h-3.5"}),"Download Ollama"]}),Ee&&r.jsxs("div",{className:"space-y-1.5",children:[r.jsx(IC,{code:`ollama pull ${Ee}`}),de&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:de})]}),r.jsx(d8e,{onDetected:me=>K(me)})]}):r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Local models require at least 8GB RAM. We recommend OpenRouter instead."})})]})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"OpenRouter"}),Y?.envOpenRouterConfigured&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-emerald-400",children:[r.jsx(Fe,{className:"w-3 h-3"})," Configured via .env"]})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Access 200+ models via one API key"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:n,onChange:me=>{s(me.target.value),A(null)},placeholder:"sk-or-v1-...",ref:B,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:z,disabled:!n.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),w&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",w.valid?"text-emerald-400":"text-red-400"),children:[w.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),w.valid?`Valid — ${w.modelCount} models available`:"Invalid key"]}),w?.valid&&w.suggestedReasoningModel&&r.jsx("div",{className:"mt-3 pt-3 border-t border-[#2A2A35]",children:r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-1",children:"Models available via OpenRouter"})})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Anthropic"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Claude models (Haiku, Sonnet, Opus)"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:i,onChange:me=>{a(me.target.value),C(null)},placeholder:"sk-ant-...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:J,disabled:!i.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),S&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",S.valid?"text-emerald-400":"text-red-400"),children:[S.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),S.valid?"Valid":"Invalid key"]})]}),r.jsxs("button",{onClick:()=>_(me=>!me),className:"flex items-center gap-1.5 text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors w-full py-0.5",children:[r.jsx("span",{children:b?"↑ Hide":"↓ More providers"}),r.jsx("span",{className:"text-[#3A3A45]",children:"(OpenAI, Gemini)"})]}),b&&r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"OpenAI"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"GPT-4o, o1, o3-mini"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:o,onChange:me=>{l(me.target.value),p(null)},placeholder:"sk-...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:ee,disabled:!o.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),f&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",f.valid?"text-emerald-400":"text-red-400"),children:[f.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),f.valid?"Valid":"Invalid key"]})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Google Gemini"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Gemini 2.0, Flash, Pro"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:c,onChange:me=>{d(me.target.value),g(null)},placeholder:"AIza...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:re,disabled:!c.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),m&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",m.valid?"text-emerald-400":"text-red-400"),children:[m.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),m.valid?"Valid":"Invalid key"]})]})]})]}),le&&r.jsxs("div",{className:"bg-[#16161A] border border-[#6366F1]/20 rounded-2xl p-4 mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Default models"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-3",children:"Pre-selected for you. Change anytime in Settings."}),r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Primary (reasoning)"}),r.jsxs(ss,{value:E,onValueChange:me=>{k(me),I("")},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#0F0F11] text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/50 transition-colors",children:[r.jsx("span",{className:"truncate",children:(ae.find(me=>me.id===E)?.label??E)||"Select model..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsxs(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("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx("input",{value:M,onChange:me=>I(me.target.value),onKeyDown:me=>{me.key==="Enter"&&M.trim()&&k(M.trim())},placeholder:"Type model ID...",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"})}),r.jsx(os,{children:Object.entries(ae.reduce((me,$e)=>((me[$e.group]??=[]).push($e),me),{})).map(([me,$e])=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:me}),$e.map(nt=>r.jsxs(vn,{value:nt.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:nt.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},nt.id))]},me))})]})})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Fast (quick tasks)"}),r.jsxs(ss,{value:T,onValueChange:me=>{F(me),H("")},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#0F0F11] text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/50 transition-colors",children:[r.jsx("span",{className:"truncate",children:(ae.find(me=>me.id===T)?.label??T)||"Select model..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsxs(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("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx("input",{value:R,onChange:me=>H(me.target.value),onKeyDown:me=>{me.key==="Enter"&&R.trim()&&F(R.trim())},placeholder:"Type model ID...",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"})}),r.jsx(os,{children:Object.entries(ae.reduce((me,$e)=>((me[$e.group]??=[]).push($e),me),{})).map(([me,$e])=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:me}),$e.map(nt=>r.jsxs(vn,{value:nt.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:nt.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},nt.id))]},me))})]})})]})]})]})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[r.jsx("button",{onClick:async()=>{E&&T&&await D.mutateAsync({reasoningModel:E,fastModel:T}),e()},disabled:!se||D.isPending,className:ye("flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium transition-colors",se?"bg-[#6366F1] text-white hover:bg-[#5254CC]":"bg-white/5 text-[#5A5A6E] border border-[#2A2A35] cursor-not-allowed"),children:D.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"}):r.jsxs(r.Fragment,{children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]})}),r.jsx("button",{onClick:t,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip for now"})]})]})}function f8e({onNext:e}){const[t,n]=y.useState(null);return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Share your workspace"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"How will you use damn.dev?"}),r.jsx("div",{className:"grid grid-cols-2 gap-3 mb-6",children:["solo","team"].map(s=>r.jsxs("button",{onClick:()=>n(s),className:ye("text-left rounded-2xl p-4 border transition-all",t===s?"border-[#6366F1]/50 bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] bg-[#16161A] hover:border-[#3A3A45]"),children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mt-1",children:s==="solo"?"Just me":"With my team"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:s==="solo"?"Default":"Share access via Tailscale"})]},s))}),t==="team"&&r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 mb-6",children:r.jsx(V5,{onComplete:()=>e(),onSkip:e})}),t!=="team"&&r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsxs("button",{onClick:e,disabled:t===null,className:ye("flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium transition-colors",t!==null?"bg-[#6366F1] text-white hover:bg-[#5254CC]":"bg-white/5 text-[#5A5A6E] border border-[#2A2A35] cursor-not-allowed"),children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),r.jsx("button",{onClick:e,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip"})]})]})}function p8e({onComplete:e}){const t=an(),n=L.useUtils(),s=L.onboarding.complete.useMutation(),i=L.onboarding.cooOnboardingChat.useMutation(),a=L.onboarding.setWorkspaceContext.useMutation(),[o,l]=y.useState([]),[c,d]=y.useState(""),[f,p]=y.useState(null),[m,g]=y.useState(!1),[b,_]=y.useState(!0),[w,A]=y.useState(null),S=y.useRef(null),C=y.useRef(null);y.useEffect(()=>{let M=!1;return i.mutateAsync({message:"Hello",history:[]}).then(I=>{M||(l([{role:"assistant",content:I.reply}]),_(!1))}).catch(()=>{M||(_(!1),A("Could not reach COO. You can skip this step and set workspace context later."))}),()=>{M=!0}},[]),y.useEffect(()=>{S.current?.scrollTo({top:S.current.scrollHeight,behavior:"smooth"})},[o,f]);async function E(){const M=c.trim();if(!M||i.isPending)return;d(""),A(null);const I=[...o,{role:"user",content:M}];l(I);try{const R=await i.mutateAsync({message:M,history:I});l([...I,{role:"assistant",content:R.reply}]),R.workspaceContext&&p(R.workspaceContext)}catch{A("COO failed to respond. Try again or skip this step.")}C.current?.focus()}async function k(){f&&(await a.mutateAsync({context:f}),g(!0))}async function T(){await s.mutateAsync(),await n.onboarding.getState.refetch(),t("/channels/chan_coo",{replace:!0}),e()}async function F(){await s.mutateAsync(),await n.onboarding.getState.refetch(),t("/channels/chan_coo",{replace:!0}),e()}return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-1",children:"Meet your COO"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-4 leading-relaxed",children:"A few questions to set up your workspace context."}),r.jsxs("div",{ref:S,className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4 mb-3 space-y-3 max-h-[320px] overflow-y-auto",children:[b&&r.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-[#5A5A6E]",children:[r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),"COO is thinking..."]}),w&&r.jsx("div",{className:"text-[13px] text-red-400/80 leading-relaxed",children:w}),o.map((M,I)=>r.jsx("div",{className:ye("flex",M.role==="user"?"justify-end":"justify-start"),children:r.jsx("div",{className:ye("rounded-xl px-3 py-2 text-[13px] leading-relaxed max-w-[85%]",M.role==="user"?"bg-[#6366F1] text-white":"bg-[#1E1E28] text-[#C8C8D4] border border-[#2A2A35]"),children:M.content})},I)),i.isPending&&o.length>0&&r.jsx("div",{className:"flex justify-start",children:r.jsx("div",{className:"rounded-xl px-3 py-2 bg-[#1E1E28] border border-[#2A2A35]",children:r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin text-[#5A5A6E]"})})})]}),f&&!m&&r.jsxs("div",{className:"bg-[#0F0F11] border border-[#6366F1]/30 rounded-xl p-3 mb-3",children:[r.jsx("p",{className:"text-[11px] font-medium text-[#6366F1] mb-2",children:"Proposed workspace context"}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap leading-relaxed max-h-[160px] overflow-y-auto mb-2",children:f}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{onClick:k,disabled:a.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Fe,{className:"w-3 h-3"}),"Approve"]}),r.jsx("button",{onClick:()=>p(null),className:"px-3 py-1.5 rounded-lg text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Revise"})]})]}),m&&r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-3",children:[r.jsx(sa,{className:"w-3.5 h-3.5 text-emerald-400"}),r.jsx("span",{className:"text-[12px] text-emerald-400",children:"Workspace context saved"})]}),!m&&!b&&r.jsxs("div",{className:"flex gap-2 mb-3",children:[r.jsx("input",{ref:C,type:"text",value:c,onChange:M=>d(M.target.value),onKeyDown:M=>M.key==="Enter"&&E(),placeholder:"Type your answer...",disabled:i.isPending,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors disabled:opacity-50"}),r.jsx("button",{onClick:E,disabled:!c.trim()||i.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-50 transition-colors flex-shrink-0",children:"Send"})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[m&&r.jsxs("button",{onClick:T,disabled:s.isPending,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[s.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):null,"Open damn.dev",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),!m&&r.jsx("button",{onClick:F,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip this step"})]})]})}function m8e(){const e=an(),[t,n]=y.useState(0),s=L.onboarding.skip.useMutation();async function i(){await s.mutateAsync(),e("/",{replace:!0})}return r.jsx("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col items-center justify-center",children:r.jsxs("div",{className:"w-full max-w-lg px-6 flex flex-col",style:{maxHeight:"100vh"},children:[r.jsxs("div",{className:"flex items-center justify-between mb-8 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[18px]",children:"⚡"}),r.jsx("span",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"damn.dev"})]}),r.jsx(c8e,{current:t}),r.jsx("button",{onClick:i,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip setup"})]}),r.jsx("div",{className:"overflow-y-auto flex-1 pb-6",children:r.jsxs(Me,{mode:"wait",children:[t===0&&r.jsx(u8e,{onNext:()=>n(1),onSkip:()=>n(1)},"step0"),t===1&&r.jsx(h8e,{onNext:()=>n(2),onSkip:()=>n(2)},"step1"),t===2&&r.jsx(f8e,{onNext:()=>n(3)},"step2"),t===3&&r.jsx(p8e,{onComplete:()=>{}},"step3")]})})]})})}function x8e(){const e=an(),{data:t}=L.workspace.getMyMembership.useQuery(),{data:n=[]}=L.channels.list.useQuery(),s=L.workspace.completeOnboarding.useMutation();async function i(){await s.mutateAsync();const a=n.find(o=>o.name==="general"&&o.visibility==="public"&&o.channelType==="topic");e(a?`/channels/${a.id}`:"/channels/direction",{replace:!0})}return r.jsx("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col items-center justify-center",children:r.jsxs(ne.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,ease:[.16,1,.3,1]},className:"w-full max-w-md px-6 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mx-auto mb-6",children:r.jsx("span",{className:"text-3xl",children:"👋"})}),r.jsxs("h1",{className:"text-[24px] font-semibold text-[#F0F0F5] mb-3",children:["Welcome to ",t?.workspaceName??"the workspace"]}),t?.ownerName&&r.jsxs("p",{className:"text-[14px] text-[#8A8A99] mb-8 leading-relaxed",children:["You've been invited by ",t.ownerName]}),r.jsxs("button",{onClick:i,disabled:s.isPending,className:"inline-flex items-center gap-2 px-6 py-3 rounded-xl text-[14px] font-semibold bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[s.isPending?r.jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}):null,"Explore your workspace",r.jsx(Jt,{className:"w-4 h-4"})]})]})})}function g8e(){const[e,t]=y.useState("signin"),[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(!1),[c,d]=y.useState(null),[f,p]=y.useState(!1),{data:m}=L.onboarding.hasGoogleAuth.useQuery(),{data:g}=L.onboarding.signupAllowed.useQuery(),b=g?.allowed??!1,_=g?.registrationMode??"closed";y.useEffect(()=>{!b&&e==="signup"&&t("signin")},[b,e]);async function w(A){if(A.preventDefault(),d(null),e==="signup"&&!b){d("This workspace requires an invitation to join.");return}if(i.length<12){d("Password must be at least 12 characters.");return}p(!0);try{if(e==="signup"){const S=await cz.email({email:n,password:i,name:n.split("@")[0]});S.error&&d(S.error.message??"Sign up failed.")}else{const S=await v0.email({email:n,password:i});S.error&&d(S.error.message??"Invalid credentials.")}}catch{d("Something went wrong. Please try again.")}finally{p(!1)}}return r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-6 max-w-sm w-full px-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center",children:r.jsx("span",{className:"text-2xl font-bold text-[#6366F1]",children:"d"})}),r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"damn.dev"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:e==="signin"?"Sign in to your workspace":"Create your workspace"})]}),r.jsxs("form",{onSubmit:w,className:"flex flex-col gap-3 w-full",children:[r.jsx("input",{type:"email",placeholder:"Email",value:n,onChange:A=>s(A.target.value),required:!0,className:"w-full rounded-lg bg-[#1A1A20] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:o?"text":"password",placeholder:"Password (min 12 characters)",value:i,onChange:A=>a(A.target.value),required:!0,minLength:12,className:"w-full rounded-lg bg-[#1A1A20] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 pr-11 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("button",{type:"button",onClick:()=>l(A=>!A),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[#5A5A6A] hover:text-[#8A8A99] transition-colors",tabIndex:-1,children:o?r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 4.411m0 0L21 21"})}):r.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]}),c&&r.jsx("p",{className:"text-[13px] text-red-400",children:c}),r.jsx("button",{type:"submit",disabled:f,className:"w-full rounded-lg bg-[#6366F1] text-white px-5 py-3 text-[14px] font-medium hover:bg-[#5254CC] disabled:opacity-50 transition-colors",children:f?"...":e==="signin"?"Sign in":"Create account"})]}),b?r.jsx("button",{type:"button",onClick:()=>{t(e==="signin"?"signup":"signin"),d(null)},className:"text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:e==="signin"?"Don't have an account? Create one":"Already have an account? Sign in"}):_==="invite"?r.jsx("p",{className:"text-[13px] text-[#5A5A6E] text-center",children:"Need an account? Ask the workspace admin for an invite link."}):r.jsx("p",{className:"text-[13px] text-[#5A5A6E] text-center",children:"Registration is closed."}),m?.enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-3 w-full",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6A]",children:"or"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]}),r.jsxs("button",{onClick:()=>v0.social({provider:"google",callbackURL:window.location.origin+"/"}),className:"flex items-center gap-3 w-full justify-center rounded-lg bg-white text-[#1a1a1a] px-5 py-3 text-[14px] font-medium hover:bg-[#f0f0f0] transition-colors",children:[r.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[r.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),r.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),r.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),r.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Continue with Google"]})]})]})})}function b8e(e){if(!e||typeof e!="object")return!1;const t=String(e.message??"");return t.includes("Failed to fetch")||t.includes("NetworkError")||t.includes("ERR_CONNECTION_REFUSED")||t.includes("ECONNREFUSED")||t.includes("Load failed")||t.includes("fetch failed")}function v8e(){const[e,t]=y.useState(!1);function n(){t(!0),setTimeout(()=>window.location.reload(),500)}return r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-5 max-w-md text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-amber-500/10 border border-amber-500/20 flex items-center justify-center",children:r.jsx("span",{className:"text-amber-400 text-xl",children:"!"})}),r.jsx("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:"Can't reach this workspace"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] leading-relaxed",children:"This is a private workspace running on someone's machine. You need to be on their private network to access it."}),r.jsxs("div",{className:"w-full bg-[#16161A] border border-[#2A2A35] rounded-xl p-5 text-left space-y-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4]",children:"If they shared a Tailscale link:"}),r.jsxs("div",{className:"space-y-2 text-[12px] text-[#8A8A99]",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"1."}),r.jsxs("div",{children:["Install Tailscale on your device",r.jsxs("a",{href:"https://tailscale.com/download",target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 mt-1 text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(cs,{className:"w-3 h-3"}),"tailscale.com/download"]})]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"2."}),r.jsx("span",{children:"Ask them to add you to their Tailnet at tailscale.com/admin"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"3."}),r.jsx("span",{children:"Once connected, refresh this page"})]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Already have Tailscale? Make sure it's running and you're on the same Tailnet as the workspace host."})]}),r.jsxs("button",{onClick:n,disabled:e,className:"flex items-center gap-2 px-4 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 transition-colors disabled:opacity-50",children:[r.jsx(Xi,{className:`w-3.5 h-3.5 ${e?"animate-spin":""}`}),"Retry connection"]})]})})}function y8e(){const{token:e}=am(),t=an(),{data:n}=Mi(),[s,i]=y.useState("signup"),[a,o]=y.useState(""),[l,c]=y.useState(""),[d,f]=y.useState(null),[p,m]=y.useState(!1),{data:g,isLoading:b,error:_}=L.workspace.getInvitation.useQuery({token:e},{enabled:!!e,retry:!1}),w=L.workspace.acceptInvitation.useMutation({onSuccess:()=>{setTimeout(()=>t("/"),2e3)}});y.useEffect(()=>{if(w.isSuccess){const S=setTimeout(()=>t("/"),2e3);return()=>clearTimeout(S)}},[w.isSuccess,t]);async function A(S){if(S.preventDefault(),f(null),l.length<12){f("Password must be at least 12 characters.");return}m(!0);try{if(s==="signup"){const C=await cz.email({email:a,password:l,name:a.split("@")[0],fetchOptions:{headers:{"x-invite-token":e}}});C.error&&f(C.error.message??"Sign up failed.")}else{const C=await v0.email({email:a,password:l});C.error&&f(C.error.message??"Invalid credentials.")}}catch{f("Something went wrong. Please try again.")}finally{m(!1)}}return b?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):_&&b8e(_)?r.jsx(v8e,{}):_||!g?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 max-w-sm text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-[#EF4444]/10 border border-[#EF4444]/20 flex items-center justify-center",children:r.jsx("span",{className:"text-[#EF4444] text-xl",children:"✕"})}),r.jsx("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:"Invitation not valid"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:"This invitation is no longer valid or has expired."}),r.jsx(gn,{to:"/",className:"text-[13px] text-[#6366F1] hover:underline",children:"Go to workspace"})]})}):w.isSuccess?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 max-w-sm text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-[#10B981]/10 border border-[#10B981]/20 flex items-center justify-center",children:r.jsx("span",{className:"text-[#10B981] text-xl",children:"✓"})}),r.jsxs("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:["You've joined ",g.workspaceName,"!"]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Redirecting you to your workspace..."}),r.jsx("div",{className:"w-4 h-4 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})]})}):r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"w-[400px] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl p-8 flex flex-col items-center gap-5",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center",children:r.jsx("span",{className:"text-2xl font-bold text-[#6366F1]",children:"d"})}),r.jsxs("div",{className:"text-center",children:[r.jsx("h1",{className:"text-[20px] font-semibold text-[#F0F0F5]",children:g.workspaceName}),r.jsxs("p",{className:"text-[13px] text-[#8A8A99] mt-1",children:[g.inviterName," invited you to join as"," ",r.jsx("span",{className:"text-[#C8C8D4]",children:g.role})]})]}),w.error&&r.jsx("p",{className:"text-[12px] text-[#EF4444] text-center",children:w.error.message}),n?r.jsx("button",{onClick:()=>w.mutate({token:e}),disabled:w.isPending,className:"w-full px-4 py-2.5 rounded-lg bg-[#6366F1] text-white text-[14px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:w.isPending?"Joining...":"Join Workspace"}):r.jsxs("div",{className:"w-full flex flex-col gap-3",children:[r.jsxs("form",{onSubmit:A,className:"flex flex-col gap-3 w-full",children:[r.jsx("input",{type:"email",placeholder:"Email",value:a,onChange:S=>o(S.target.value),required:!0,className:"w-full rounded-lg bg-[#13131A] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("input",{type:"password",placeholder:"Password (min 12 characters)",value:l,onChange:S=>c(S.target.value),required:!0,minLength:12,className:"w-full rounded-lg bg-[#13131A] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),d&&r.jsx("p",{className:"text-[12px] text-red-400",children:d}),r.jsx("button",{type:"submit",disabled:p,className:"w-full rounded-lg bg-[#6366F1] text-white px-5 py-3 text-[14px] font-medium hover:bg-[#5254CC] disabled:opacity-50 transition-colors",children:p?"...":s==="signup"?"Create account & join":"Sign in & join"})]}),r.jsx("button",{type:"button",onClick:()=>{i(s==="signin"?"signup":"signin"),f(null)},className:"text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:s==="signup"?"Already have an account? Sign in":"Don't have an account? Create one"}),r.jsxs("div",{className:"flex items-center gap-3 w-full",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6A]",children:"or"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]}),r.jsxs("button",{onClick:()=>v0.social({provider:"google",callbackURL:`${window.location.origin}/invite/${e}`}),className:"flex items-center gap-3 w-full justify-center rounded-lg bg-white text-[#1a1a1a] px-5 py-3 text-[14px] font-medium hover:bg-[#f0f0f0] transition-colors",children:[r.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[r.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),r.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),r.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),r.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Continue with Google"]})]})]})})}function _8e({open:e,onClose:t}){const[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(0),c=y.useRef(null),d=an(),[f,p]=y.useState(e);e&&!f&&(s(""),a(""),l(0)),e!==f&&p(e),y.useEffect(()=>{e&&setTimeout(()=>c.current?.focus(),50)},[e]),y.useEffect(()=>{const A=setTimeout(()=>a(n),200);return()=>clearTimeout(A)},[n]);const{data:m=[]}=L.messages.search.useQuery({query:i},{enabled:i.length>=2}),g=m.reduce((A,S)=>{const C=A[S.channelName]??[];return C.push(S),A[S.channelName]=C,A},{}),b=m;function _(A){d(`/channels/${A.channelId}`),t(),setTimeout(()=>{document.getElementById(`msg-${A.messageId}`)?.scrollIntoView({behavior:"smooth",block:"center"})},300)}function w(A){A.key==="Escape"?t():A.key==="ArrowDown"?(A.preventDefault(),l(S=>Math.min(S+1,b.length-1))):A.key==="ArrowUp"?(A.preventDefault(),l(S=>Math.max(S-1,0))):A.key==="Enter"&&b[o]&&_(b[o])}return r.jsx(Me,{children:e&&r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"fixed inset-0 z-[100] flex items-start justify-center pt-[15vh]",style:{backdropFilter:"blur(8px)",backgroundColor:"rgba(0,0,0,0.6)"},onClick:A=>{A.target===A.currentTarget&&t()},children:r.jsxs(ne.div,{initial:{opacity:0,y:-12,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.97},transition:{duration:.2,ease:[.16,1,.3,1]},className:"w-full max-w-[600px] mx-4 bg-[#13131A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-[#2A2A35]",children:[r.jsx(Io,{className:"w-5 h-5 text-[#8A8A99] flex-shrink-0"}),r.jsx("input",{ref:c,value:n,onChange:A=>{s(A.target.value),l(0)},onKeyDown:w,placeholder:"Search messages...",className:"flex-1 bg-transparent text-[20px] text-[#F0F0F5] placeholder:text-[#8A8A99]/50 outline-none"}),r.jsx("kbd",{className:"text-[11px] text-[#8A8A99] bg-white/5 border border-[#2A2A35] px-1.5 py-0.5 rounded-md",children:"esc"})]}),i.length>=2&&r.jsx("div",{className:"max-h-[420px] overflow-y-auto py-2",children:m.length===0?r.jsx("div",{className:"px-5 py-8 text-center",children:r.jsxs("p",{className:"text-[14px] text-[#8A8A99]",children:['No messages found for "',i,'"']})}):Object.entries(g).map(([A,S])=>r.jsxs("div",{children:[r.jsx("div",{className:"px-4 py-1.5 sticky top-0 bg-[#13131A]",children:r.jsxs("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:["#",A]})}),S.map(C=>{const E=b.indexOf(C),k=E===o;return r.jsxs("button",{onClick:()=>_(C),onMouseEnter:()=>l(E),className:"w-full text-left px-4 py-3 transition-colors",style:{backgroundColor:k?"rgba(255,255,255,0.04)":"transparent"},children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-0.5",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#C8C8D4]",children:"Message"}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:Ir(C.createdAt)})]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] leading-relaxed",children:w8e(C.snippet,i)})]},C.messageId)})]},A))}),i.length<2&&r.jsx("div",{className:"px-5 py-6 text-center",children:r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Type at least 2 characters to search"})}),r.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 border-t border-[#2A2A35]",children:[r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[r.jsx("kbd",{className:"bg-white/5 border border-[#2A2A35] px-1 py-0.5 rounded text-[10px] mr-1",children:"↑↓"}),"navigate"]}),r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[r.jsx("kbd",{className:"bg-white/5 border border-[#2A2A35] px-1 py-0.5 rounded text-[10px] mr-1",children:"↵"}),"jump"]})]})]})})})}function w8e(e,t){return e.split(new RegExp(`(${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi")).map((s,i)=>s.toLowerCase()===t.toLowerCase()?r.jsx("mark",{className:"bg-[#6366F1]/30 text-[#A5B4FC] rounded-sm px-0.5",children:s},i):s)}function A8e(){return/iPad|iPhone|iPod/.test(navigator.userAgent)&&!("MSStream"in window)}function S8e(){return window.matchMedia("(display-mode: standalone)").matches||"standalone"in navigator&&navigator.standalone===!0}function C8e(){const[e,t]=y.useState(!1),[n,s]=y.useState(!1),[i,a]=y.useState(null);y.useEffect(()=>{if(S8e())return;if(A8e()){localStorage.getItem("pwa-install-dismissed")||t(!0);return}function d(f){f.preventDefault(),a(f),sessionStorage.getItem("pwa-install-dismissed")||s(!0)}return window.addEventListener("beforeinstallprompt",d),()=>window.removeEventListener("beforeinstallprompt",d)},[]);const o=y.useCallback(()=>{localStorage.setItem("pwa-install-dismissed","1"),t(!1)},[]),l=y.useCallback(()=>{sessionStorage.setItem("pwa-install-dismissed","1"),s(!1)},[]),c=y.useCallback(async()=>{i&&(await i.prompt(),s(!1),a(null))},[i]);return r.jsxs(Me,{children:[e&&r.jsxs(ne.div,{initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:"fixed bottom-4 left-4 right-4 z-50 rounded-xl bg-[#1A1A2E] border border-[#2A2A35] p-4 shadow-2xl max-w-md mx-auto",children:[r.jsxs("p",{className:"text-[13px] text-[#C0C0CC] leading-relaxed",children:["For the best experience, add damn.dev to your Home Screen: tap"," ",r.jsx("span",{className:"inline-flex items-center align-middle mx-0.5",children:r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#6366F1]",children:[r.jsx("path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"}),r.jsx("polyline",{points:"16 6 12 2 8 6"}),r.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"15"})]})})," ","Share → Add to Home Screen"]}),r.jsx("button",{onClick:o,className:"mt-3 text-[12px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"Got it"})]}),n&&r.jsxs(ne.div,{initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:"fixed bottom-4 left-4 right-4 z-50 rounded-xl bg-[#1A1A2E] border border-[#2A2A35] p-4 shadow-2xl max-w-md mx-auto flex items-center justify-between gap-3",children:[r.jsx("p",{className:"text-[13px] text-[#C0C0CC]",children:"Install damn.dev for a native experience"}),r.jsxs("div",{className:"flex gap-2 shrink-0",children:[r.jsx("button",{onClick:l,className:"text-[12px] text-[#8A8A99] hover:text-[#C0C0CC] transition-colors px-2 py-1",children:"Not now"}),r.jsx("button",{onClick:c,className:"text-[12px] font-medium bg-[#6366F1] text-white rounded-lg px-3 py-1.5 hover:bg-[#5558E6] transition-colors",children:"Install"})]})]})]})}function j8e(e){const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),s=atob(n),i=new Uint8Array(s.length);for(let a=0;a<s.length;a++)i[a]=s.charCodeAt(a);return i}const cO="pwa-push-retry-after";function N8e(){const e=y.useRef(!1),{data:t}=L.notifications.getVapidKey.useQuery(void 0,{enabled:!Va}),n=L.notifications.registerToken.useMutation(),s=y.useCallback(async()=>{if(!t?.vapidKey||!("serviceWorker"in navigator)||!("PushManager"in window))return;const a=await navigator.serviceWorker.ready;let o=await a.pushManager.getSubscription();o||(o=await a.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:j8e(t.vapidKey).buffer})),n.mutate({token:JSON.stringify(o.toJSON()),platform:"web"})},[t?.vapidKey,n]),i=y.useCallback(async()=>{if(e.current)return;e.current=!0;const a=localStorage.getItem(cO);if(!(a&&Date.now()<Number(a))){if(Notification.permission==="granted"){await s();return}Notification.permission==="default"&&(await Notification.requestPermission()==="granted"?await s():localStorage.setItem(cO,String(Date.now()+1440*60*1e3)))}},[s]);return y.useEffect(()=>{t?.vapidKey&&Notification.permission==="granted"&&s()},[t?.vapidKey,s]),y.useEffect(()=>{if(!t?.vapidKey||Notification.permission!=="default")return;function a(){i()}return window.addEventListener("pwa-push-prompt",a,{once:!0}),()=>window.removeEventListener("pwa-push-prompt",a)},[t?.vapidKey,i]),{promptForPermission:i}}function k8e(){const[e,t]=y.useState(null),[n,s]=y.useState(!1),[i,a]=y.useState("idle"),[o,l]=y.useState(null),[c,d]=y.useState(!1);y.useEffect(()=>{fetch(`${oi}/api/version`,{credentials:"include"}).then(b=>b.json()).then(b=>{if(b.updateAvailable&&b.latest){const _=`dismissed_update_${b.latest}`;localStorage.getItem(_)||t(b)}}).catch(()=>{})},[]);const f=y.useCallback(()=>{const b=Date.now(),_=setInterval(async()=>{if(Date.now()-b>3e5){clearInterval(_),a("error"),l("Update may have failed. Check server logs.");return}try{(await fetch(`${oi}/health`)).ok&&(clearInterval(_),a("done"),setTimeout(()=>window.location.reload(),1e3))}catch{a("restarting")}},2e3)},[]),p=y.useCallback(async()=>{if(!e)return;if(typeof window<"u"&&"__TAURI__"in window){try{const{check:_}=await X(async()=>{const{check:A}=await import("./index-Cpew6ait.js");return{check:A}},__vite__mapDeps([105,1])),w=await _();if(w){a("updating"),await w.downloadAndInstall();const{relaunch:A}=await X(async()=>{const{relaunch:S}=await import("./index-CO34o7br.js");return{relaunch:S}},__vite__mapDeps([106,1]));await A()}}catch{a("error"),l("Download the latest version from damn.dev")}return}a("updating");try{const _=await fetch(`${oi}/api/update`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}});if(_.status===403){a("error"),l("Only the workspace owner can trigger updates");return}const w=await _.json();if(w.error==="use_native_updater"){a("error"),l("Download the latest version from damn.dev");return}if(!w.ok){a("error"),l(w.error??"Update failed");return}f()}catch{a("error"),l("Failed to start update. Check server logs.")}},[e,f]);if(!e||n)return null;function m(){e?.latest&&localStorage.setItem(`dismissed_update_${e.latest}`,"1"),s(!0)}const g={"docker-vps":"SSH into your server and re-run your install script.",tauri:"Download the latest version from damn.dev."};return r.jsxs("div",{className:"bg-[#1A1A2E] border-b border-[#2A2A35] text-[#9090A0] text-[12px] py-1.5 px-4 flex flex-col flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:["damn.dev ",e.latest," is available"]}),e.canAutoUpdate?r.jsx("button",{onClick:p,className:"px-2 py-0.5 rounded bg-[#6366F1]/20 text-[#818CF8] hover:bg-[#6366F1]/30 transition-colors text-[11px] font-medium",children:"Update now"}):r.jsx("span",{className:"text-[#707080]",children:g[e.installPath]??"Re-run your install script to update."}),e.releaseNotes&&r.jsx("button",{onClick:()=>d(b=>!b),className:"text-[#707080] hover:text-[#9090A0] transition-colors text-[11px]",children:c?"Hide":"What's new"})]}),i==="updating"&&r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Updating..."]}),i==="restarting"&&r.jsxs("span",{className:"flex items-center gap-2 animate-pulse",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Restarting..."]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E]",children:"Updated!"}),i==="error"&&r.jsx("span",{className:"text-[#F87171]",children:o})]}),(i==="idle"||i==="error")&&r.jsx("button",{onClick:m,className:"ml-4 text-[#9090A0] hover:text-[#F0F0F5] transition-colors",children:"×"})]}),c&&e.releaseNotes&&r.jsx("div",{className:"mt-1.5 pt-1.5 border-t border-[#2A2A35] text-[11px] text-[#707080] whitespace-pre-wrap max-h-40 overflow-y-auto",children:e.releaseNotes})]})}function E8e(){const{data:e,refetch:t}=L.settings.getOpenClawVersion.useQuery(void 0,{refetchInterval:6e4,retry:!1}),[n,s]=y.useState(!1),[i,a]=y.useState("idle"),[o,l]=y.useState(null),c=L.settings.updateOpenClaw.useMutation();if(!e?.updateAvailable||n)return null;async function d(){a("updating");try{const f=await c.mutateAsync();f.ok?(a("done"),setTimeout(()=>{t(),s(!0)},3e3)):(a("error"),l(f.error??"Update failed"))}catch{a("error"),l("Failed to start update. Check server logs.")}}return r.jsxs("div",{className:"bg-[#1A1A2E] border-b border-[#2A2A35] text-[#9090A0] text-[12px] py-1.5 px-4 flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:["OpenClaw ",e.minimum," required (current: ",e.current,")"]}),r.jsx("button",{onClick:d,className:"px-2 py-0.5 rounded bg-[#6366F1]/20 text-[#818CF8] hover:bg-[#6366F1]/30 transition-colors text-[11px] font-medium",children:"Update now"})]}),i==="updating"&&r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Updating OpenClaw..."]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E]",children:"OpenClaw updated!"}),i==="error"&&r.jsx("span",{className:"text-[#F87171]",children:o})]}),(i==="idle"||i==="error")&&r.jsx("button",{onClick:()=>s(!0),className:"ml-4 text-[#9090A0] hover:text-[#F0F0F5] transition-colors",children:"×"})]})}function F8e(){const{data:e,refetch:t,isFetching:n}=L.settings.getOpenClawHealth.useQuery(void 0,{refetchInterval:15e3,retry:!1,refetchOnWindowFocus:!0}),s=L.settings.restartOpenClaw.useMutation(),[i,a]=y.useState("idle"),[o,l]=y.useState(null),c=e?.checkedAt&&e.checkedAt!==new Date(0).toISOString();if(!e||e.healthy||!c)return null;async function d(){a("restarting"),l(null);try{const p=await s.mutateAsync(void 0);p.kind==="restarted"?(a("done"),setTimeout(()=>{a("idle"),t()},1500)):p.kind==="skipped"?(a("skipped"),l(p.detail??p.reason)):(a("failed"),l(p.error))}catch(p){a("failed"),l(p instanceof Error?p.message:"Restart request failed.")}}const f=e.installPath==="docker-local"?"The backend will restart OpenClaw via `docker compose up -d`.":e.installPath==="tauri"?"The sidecar backend will restart OpenClaw via `docker compose up -d`.":e.installPath==="docker-vps"?e.canRestartFromBackend?"The backend will restart OpenClaw via the docker-socket-proxy sidecar.":"This backend runs inside a container without a docker-socket-proxy sidecar. SSH into the host and run `docker compose restart openclaw` — or redeploy to pick up the proxy service.":"OpenClaw runs as a native process on this install. Restart it from the terminal (e.g. `openclaw start`).";return r.jsxs("div",{className:"bg-[#2A1414] border-b border-[#F87171]/30 text-[#FCA5A5] text-[12px] py-1.5 px-4 flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[r.jsx("span",{className:"font-medium",children:"OpenClaw unreachable"}),r.jsxs("span",{className:"text-[#F87171]/70",children:["· ",f]}),e.lastError&&r.jsxs("span",{className:"text-[#F87171]/50 text-[11px]",children:["(",e.lastError,")"]})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{t()},disabled:n,className:"px-2 py-0.5 rounded bg-[#F87171]/10 text-[#FCA5A5] hover:bg-[#F87171]/20 transition-colors text-[11px] font-medium disabled:opacity-50",children:n?"Checking…":"Retry"}),e.canRestartFromBackend&&r.jsx("button",{onClick:d,className:"px-2 py-0.5 rounded bg-[#F87171]/20 text-[#FCA5A5] hover:bg-[#F87171]/30 transition-colors text-[11px] font-medium",children:"Restart OpenClaw"})]}),i==="restarting"&&r.jsxs("span",{className:"flex items-center gap-2 text-[11px]",children:[r.jsx("span",{className:"w-3 h-3 border border-[#F87171]/40 border-t-[#F87171] rounded-full animate-spin"}),"Restarting…"]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E] text-[11px]",children:"Restart succeeded"}),i==="skipped"&&r.jsx("span",{className:"text-[#F59E0B] text-[11px]",title:o??void 0,children:"Skipped — hover for details"}),i==="failed"&&r.jsx("span",{className:"text-[#F87171] text-[11px]",title:o??void 0,children:"Failed — hover for details"})]})]})}function T8e(){return 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-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mb-4",children:r.jsx("span",{className:"text-2xl",children:"⚡"})}),r.jsx("h2",{className:"text-[18px] font-semibold text-[#F0F0F5] mb-2",children:"Select a channel"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] max-w-xs leading-relaxed",children:"Choose a channel from the sidebar to start working with your team."})]})}function M8e({children:e}){const t=an(),{data:n,isLoading:s}=L.workspace.getMyMembership.useQuery(void 0,{staleTime:0,refetchOnWindowFocus:!1,retry:!1}),i=n?.role==="owner",{data:a,isLoading:o}=L.onboarding.getState.useQuery(void 0,{staleTime:0,refetchOnWindowFocus:!1,retry:!1,enabled:i});return y.useEffect(()=>{if(!(s||!n)){if(n.role!=="owner"){n.onboardedAt||t("/welcome",{replace:!0});return}o||!a||!a.completed&&!a.skippedAt&&t("/onboarding",{replace:!0})}},[a,o,n,s,t]),s||i&&o?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):r.jsx(r.Fragment,{children:e})}function R8e({children:e}){const{data:t,isPending:n}=Mi();return n?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):t?r.jsx(r.Fragment,{children:e}):r.jsx(g8e,{})}function D8e({children:e}){const{isPending:t}=Mi();return t?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):r.jsx(r.Fragment,{children:e})}function O8e(){const[e,t]=y.useState(!1),n=Je(a=>a.setUnreadCounts),{data:s}=Mi(),{data:i}=L.readReceipts.getUnread.useQuery(void 0,{staleTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,enabled:!!s});return y.useEffect(()=>{i&&n(i)},[i,n]),y.useEffect(()=>{function a(o){(o.metaKey||o.ctrlKey)&&o.key==="k"&&(o.preventDefault(),t(l=>!l))}return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[]),N8e(),r.jsxs("div",{className:"flex flex-col h-screen",children:[r.jsx(k8e,{}),r.jsx(E8e,{}),r.jsx(F8e,{}),r.jsxs(Q_,{children:[r.jsx(ms,{path:"/invite/:token",element:r.jsx(D8e,{children:r.jsx(y8e,{})})}),r.jsx(ms,{path:"*",element:r.jsxs(R8e,{children:[r.jsxs(Q_,{children:[r.jsx(ms,{path:"/onboarding",element:r.jsx(m8e,{})}),r.jsx(ms,{path:"/welcome",element:r.jsx(x8e,{})}),r.jsx(ms,{path:"*",element:r.jsx(M8e,{children:r.jsx(qye,{children:r.jsxs(Q_,{children:[r.jsx(ms,{path:"/",element:r.jsx(lm,{to:"/channels/direction",replace:!0})}),r.jsx(ms,{path:"/channels/:channelId",element:r.jsx(UMe,{})}),r.jsx(ms,{path:"/agents",element:r.jsx(tRe,{})}),r.jsx(ms,{path:"/agents/new",element:r.jsx(pRe,{})}),r.jsx(ms,{path:"/agents/edit-soul/:agentId",element:r.jsx(xRe,{})}),r.jsx(ms,{path:"/skills",element:r.jsx(BRe,{})}),r.jsx(ms,{path:"/deliverables",element:r.jsx(qDe,{})}),r.jsx(ms,{path:"/missions",element:r.jsx(GDe,{})}),r.jsx(ms,{path:"/coo",element:r.jsx(ZRe,{})}),r.jsx(ms,{path:"/settings",element:r.jsx(uDe,{})}),r.jsx(ms,{path:"/federation/:nodeId/:agentId",element:r.jsx(IDe,{})}),r.jsx(ms,{path:"*",element:r.jsx(T8e,{})})]})})})})]}),r.jsx(_8e,{open:e,onClose:()=>t(!1)})]})})]}),r.jsx(C8e,{})]})}GG.createRoot(document.getElementById("root")).render(r.jsx(y.StrictMode,{children:r.jsx(aJ,{children:r.jsxs(pY,{children:[r.jsx(O8e,{}),r.jsx(QY,{position:"bottom-right",toastOptions:{style:{background:"#1C1C24",border:"1px solid #2A2A35",color:"#C8C8D4",fontSize:"12px"}}})]})})}));
|
|
435
|
+
`):a;return r.jsxs("div",{className:"mx-3 mb-2 rounded-md bg-[#0F0F11] border border-[#2A2A35]/50 p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-[#8A8A99]",children:[r.jsx("span",{children:t.emoji}),r.jsx("span",{children:t.name})]}),i?.crossInstance&&i.federationNodeName&&r.jsxs("span",{className:"flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded bg-[#6366F1]/10 text-[#818CF8]",children:[r.jsx(Xt,{className:"w-2.5 h-2.5"}),i.federationNodeName]}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:"Result"})]}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap break-words leading-relaxed font-mono",children:c}),l&&r.jsx("button",{onClick:()=>s(!n),className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] mt-1.5 transition-colors",children:n?"Collapse":`Show full result (${o.length} lines)`})]})}function a8e({taskId:e,status:t}){const[n,s]=y.useState(!1),i=L.useUtils(),a=L.missions.removeTask.useMutation({onSuccess:()=>{i.missions.list.invalidate(),s(!1)}}),o=L.missions.updateTask.useMutation({onSuccess:()=>{i.missions.list.invalidate(),s(!1)}});return r.jsxs("div",{className:"relative",children:[r.jsx("button",{onClick:l=>{l.stopPropagation(),s(!n)},className:"text-[#3A3A45] hover:text-[#8A8A99] transition-colors p-0.5",children:r.jsx(iL,{className:"w-3 h-3"})}),n&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-20",onClick:()=>s(!1)}),r.jsxs("div",{className:"absolute right-0 top-5 z-30 bg-[#1A1A24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[140px]",children:[t==="pending"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),s(!1)},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#C8C8D4] hover:bg-white/5 transition-colors",children:"Edit instruction"}),(t==="working"||t==="dispatched")&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"cancelled"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#F59E0B] hover:bg-[#F59E0B]/10 transition-colors",children:"Cancel task"}),t==="failed"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"pending"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors",children:"Retry task"}),t==="completed"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"pending"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#8A8A99] hover:bg-white/5 transition-colors",children:"Re-open"}),r.jsx("button",{onClick:l=>{l.stopPropagation(),a.mutate({missionTaskId:e})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors",children:"Remove"})]})]})]})}function jW({status:e}){switch(e){case"completed":return r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"});case"failed":return r.jsx(Te,{className:"w-3.5 h-3.5 text-[#EF4444]"});case"working":case"dispatched":return r.jsx(Pe,{className:"w-3.5 h-3.5 text-[#6366F1] animate-spin"});case"review":return r.jsx(ql,{className:"w-3.5 h-3.5 text-[#F59E0B]"});case"cancelled":return r.jsx(Te,{className:"w-3.5 h-3.5 text-[#5A5A6E]"});default:return r.jsx("div",{className:"w-3.5 h-3.5 rounded-full border border-[#3A3A45]"})}}function o8e({open:e,onClose:t,onCreated:n}){const[s,i]=y.useState(""),[a,o]=y.useState(""),[l,c]=y.useState("normal"),d=L.missions.create.useMutation({onSuccess:()=>n()});return r.jsx(ji,{open:e,onOpenChange:f=>{f||t()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-50"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[460px] bg-[#16161A] border border-[#2A2A35] rounded-xl p-6 z-50 shadow-2xl",children:[r.jsx(nr,{className:"text-[15px] font-medium text-[#F0F0F5] mb-4",children:"New Mission"}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Title"}),r.jsx("input",{autoFocus:!0,value:s,onChange:f=>i(f.target.value),placeholder:"What needs to be done?",className:"w-full px-3 py-2 bg-[#0F0F11] border border-[#2A2A35] rounded-md text-[13px] text-[#F0F0F5] placeholder-[#3A3A45] focus:outline-none focus:border-[#6366F1]",onKeyDown:f=>{f.key==="Enter"&&s.trim()&&d.mutate({title:s.trim(),description:a.trim()||void 0,priority:l})}})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Description"}),r.jsx("textarea",{value:a,onChange:f=>o(f.target.value),placeholder:"Optional details...",rows:3,className:"w-full px-3 py-2 bg-[#0F0F11] border border-[#2A2A35] rounded-md text-[13px] text-[#F0F0F5] placeholder-[#3A3A45] focus:outline-none focus:border-[#6366F1] resize-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Priority"}),r.jsx("div",{className:"flex gap-2",children:["low","normal","high","critical"].map(f=>r.jsx("button",{onClick:()=>c(f),className:ye("px-3 py-1.5 rounded-md text-[12px] font-medium transition-colors",l===f?"text-white":"text-[#5A5A6E] bg-[#1E1E28] hover:text-[#8A8A99]"),style:l===f?{backgroundColor:My[f]}:void 0,children:SW[f]},f))})]})]}),r.jsxs("div",{className:"flex items-center justify-end gap-2 mt-5",children:[r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-md text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] transition-colors",children:"Cancel"})}),r.jsxs("button",{onClick:()=>{s.trim()&&d.mutate({title:s.trim(),description:a.trim()||void 0,priority:l})},disabled:!s.trim()||d.isPending,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-md bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E6] transition-colors disabled:opacity-50",children:[d.isPending&&r.jsx(Pe,{className:"w-3 h-3 animate-spin"}),"Create Mission"]})]})]})]})})}const l8e=4;function c8e({current:e}){return r.jsx("div",{className:"flex items-center gap-2",children:Array.from({length:l8e}).map((t,n)=>r.jsx("div",{className:ye("rounded-full transition-all duration-300",n<e?"w-2 h-2 bg-[#6366F1]":n===e?"w-6 h-2 bg-[#6366F1]":"w-2 h-2 bg-[#2A2A35]")},n))})}function Vd({children:e}){return r.jsx(ne.div,{initial:{opacity:0,x:24},animate:{opacity:1,x:0},exit:{opacity:0,x:-24},transition:{duration:.22,ease:[.16,1,.3,1]},className:"w-full max-w-lg mx-auto",children:e})}function lO({onDetected:e,alreadyRunning:t}){const[n,s]=y.useState("."),i=L.onboarding.pollOpenClaw.useQuery(void 0,{refetchInterval:3e3,refetchOnWindowFocus:!1,retry:!1});return y.useEffect(()=>{t||i.data?.running&&e()},[i.data?.running]),y.useEffect(()=>{const a=setInterval(()=>s(o=>o.length>=3?".":o+"."),500);return()=>clearInterval(a)},[]),i.data?.running?r.jsxs("div",{className:"flex items-center gap-2 mt-4 text-[12px] text-emerald-400",children:[r.jsx(sa,{className:"w-3.5 h-3.5"}),"OpenClaw detected — advancing…"]}):r.jsxs("div",{className:"flex items-center gap-2 mt-4 text-[12px] text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),"Waiting for OpenClaw",n]})}function IC({code:e}){const[t,n]=y.useState(!1);function s(){navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)}return r.jsxs("div",{className:"flex items-center justify-between bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 font-mono text-[12px] text-[#C8C8D4]",children:[r.jsx("span",{children:e}),r.jsx("button",{onClick:s,className:ye("ml-3 flex-shrink-0 transition-colors",t?"text-emerald-400":"text-[#5A5A6E] hover:text-[#C8C8D4]"),children:t?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Po,{className:"w-3.5 h-3.5"})})]})}function u8e({onNext:e,onSkip:t}){const{data:n,isLoading:s}=L.onboarding.checkOpenClaw.useQuery(void 0,{refetchOnWindowFocus:!1,retry:!1}),i=L.onboarding.skipOpenClaw.useMutation(),[a,o]=y.useState(!1),[l,c]=y.useState("docker"),[d,f]=y.useState(void 0);n?.runMode&&n.runMode!==d&&(f(n.runMode),n.runMode==="docker"?c("npm"):n.runMode==="npm"&&c("docker"));const[p,m]=y.useState(""),[g,b]=y.useState(!1),[_,w]=y.useState(""),[A,S]=y.useState(""),[C,E]=y.useState("idle"),k=L.onboarding.saveWaitlistEmail.useMutation(),T=L.onboarding.testConnection.useMutation();if(s)return r.jsx(Vd,{children:r.jsxs("div",{className:"flex items-center gap-3 py-8",children:[r.jsx(Pe,{className:"w-4 h-4 animate-spin text-[#6366F1]"}),r.jsx("span",{className:"text-[14px] text-[#8A8A99]",children:"Checking OpenClaw…"})]})});async function F(){await i.mutateAsync(),t()}async function M(){if(!_.trim()||!A.trim())return;E("testing");const q=await T.mutateAsync({url:_.trim(),token:A.trim()});E(q.ok?"ok":"fail"),q.ok&&setTimeout(()=>e(),1e3)}async function I(){p.trim()&&(await k.mutateAsync({email:p.trim()}),b(!0))}const R=n?.running===!0,H=n?.runMode??null,K=[{id:"docker",label:"Docker",sub:"Agents run isolated",badge:"Recommended"},{id:"npm",label:"Local (npm)",sub:"Best for dedicated machines",badge:null},{id:"cloud",label:"Cloud (VPS)",sub:"Always-on, team access",badge:null}].filter(q=>q.id!==H);return R&&!a?r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Connect OpenClaw"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"damn.dev runs agents through OpenClaw, the local AI gateway."}),r.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-6",children:[r.jsx(sa,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("p",{className:"text-[13px] font-medium text-emerald-400",children:["OpenClaw detected",H==="docker"?" via Docker":H==="cloud"?" via Cloud":H==="npm"?" locally":""]}),(n.agentCount??0)>0&&r.jsxs("p",{className:"text-[11px] text-emerald-400/70",children:[n.agentCount," agent",n.agentCount!==1?"s":""," detected"]})]})]}),r.jsxs("button",{onClick:e,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] transition-colors mb-4",children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),r.jsx("button",{onClick:()=>o(!0),className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Want to connect to a different instance?"})]}):r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Connect OpenClaw"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"damn.dev runs agents through OpenClaw, the local AI gateway."}),R&&a&&r.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-4",children:[r.jsx(sa,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),r.jsx("div",{className:"flex-1",children:r.jsxs("p",{className:"text-[13px] font-medium text-emerald-400",children:["OpenClaw is running",H==="docker"?" via Docker":H==="cloud"?" via Cloud":H==="npm"?" locally":""]})}),r.jsxs("button",{onClick:e,className:"ml-auto flex items-center gap-1 text-[12px] font-medium text-emerald-400 hover:text-emerald-300 transition-colors flex-shrink-0",children:["Continue ",r.jsx(Jt,{className:"w-3 h-3"})]})]}),r.jsx("div",{className:ye("grid gap-3 mb-4",K.length===2?"grid-cols-2":"grid-cols-3"),children:K.map(q=>r.jsxs("button",{onClick:()=>c(q.id),className:ye("relative text-left rounded-2xl p-4 border transition-all",l===q.id?"border-[#6366F1]/50 bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] bg-[#16161A] hover:border-[#3A3A45]"),children:[q.badge&&r.jsx("span",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[9px] font-semibold bg-[#6366F1] text-white tracking-wide",children:q.badge}),r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mt-1",children:q.label}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:q.sub})]},q.id))}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 mb-4",children:[l==="docker"&&r.jsxs("div",{children:[r.jsxs("a",{href:"https://www.docker.com/products/docker-desktop/",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg border border-[#2A2A35] text-[13px] text-[#C8C8D4] hover:border-[#3A3A45] hover:text-[#F0F0F5] transition-colors mb-3",children:[r.jsx(cs,{className:"w-3.5 h-3.5"}),"Download Docker Desktop"]}),r.jsx("button",{onClick:()=>window.open("http://localhost:3001/setup/docker-compose.yml","_blank"),className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg bg-[#6366F1]/10 border border-[#6366F1]/30 text-[13px] text-[#6366F1] hover:bg-[#6366F1]/20 transition-colors mb-4",children:"Download docker-compose.yml"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] leading-relaxed",children:"Open Docker Desktop → Compose → Open File → Run"}),r.jsx(lO,{onDetected:e,alreadyRunning:R})]}),l==="npm"&&r.jsxs("div",{children:[r.jsxs("div",{className:"space-y-2 mb-4",children:[r.jsx(IC,{code:"npm install -g openclaw"}),r.jsx(IC,{code:"openclaw start"})]}),r.jsx(lO,{onDetected:e,alreadyRunning:R})]}),l==="cloud"&&r.jsxs("div",{className:"space-y-5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4] mb-1",children:"Want OpenClaw fully managed in the cloud?"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mb-3",children:"Join the waitlist for cloud.damn.dev."}),g?r.jsx("p",{className:"text-[12px] text-emerald-400",children:"You're on the list. We'll notify you when cloud.damn.dev launches."}):r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"email",value:p,onChange:q=>m(q.target.value),placeholder:"you@example.com",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:I,disabled:!p.trim()||k.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:k.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):"Join waitlist"})]})]}),r.jsxs("div",{className:"border-t border-[#2A2A35] pt-5",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4] mb-3",children:"Already running on a VPS?"}),r.jsxs("div",{className:"space-y-2 mb-3",children:[r.jsx("input",{type:"url",value:_,onChange:q=>{w(q.target.value),E("idle")},placeholder:"https://openclaw.myserver.com",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("input",{type:"password",value:A,onChange:q=>{S(q.target.value),E("idle")},placeholder:"Bearer token",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"})]}),r.jsxs("button",{onClick:M,disabled:!_.trim()||!A.trim()||C==="testing"||C==="ok",className:"flex items-center gap-2 px-4 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors",children:[C==="testing"&&r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),C==="ok"&&r.jsx(Fe,{className:"w-3.5 h-3.5 text-emerald-400"}),C==="fail"&&r.jsx(Te,{className:"w-3.5 h-3.5 text-red-400"}),C==="ok"?"Connected":"Test connection"]})]})]})]}),r.jsx("button",{onClick:F,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"I'll connect OpenClaw later →"})]})}function d8e({onDetected:e}){const[t,n]=y.useState("."),s=L.onboarding.pollOllama.useQuery(void 0,{refetchInterval:3e3,refetchOnWindowFocus:!1,retry:!1});return y.useEffect(()=>{s.data?.running&&s.data.models.length>0&&e(s.data.models)},[s.data?.running]),y.useEffect(()=>{const i=setInterval(()=>n(a=>a.length>=3?".":a+"."),500);return()=>clearInterval(i)},[]),s.data?.running?r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-[12px] text-emerald-400",children:[r.jsx(sa,{className:"w-3.5 h-3.5"}),"Ollama detected"]}):r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-[12px] text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),"Waiting for Ollama",t]})}function h8e({onNext:e,onSkip:t}){const[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(""),[c,d]=y.useState(""),[f,p]=y.useState(null),[m,g]=y.useState(null),[b,_]=y.useState(!1),[w,A]=y.useState(null),[S,C]=y.useState(null),[E,k]=y.useState(""),[T,F]=y.useState(""),[M,I]=y.useState(""),[R,H]=y.useState(""),[V,K]=y.useState([]),[q,$]=y.useState(!1),B=y.useRef(null),{data:Y,isLoading:U}=L.onboarding.checkModels.useQuery(void 0,{refetchOnWindowFocus:!1,retry:!1}),{data:W}=L.onboarding.getState.useQuery(void 0,{refetchOnWindowFocus:!1});y.useEffect(()=>{Y?.envOpenRouterConfigured&&!w&&(A({valid:!0,modelCount:Y.openRouterModelCount??0,suggestedReasoningModel:W?.defaultReasoningModel??null,suggestedFastModel:W?.defaultFastModel??null}),s("sk-or-v1-••••••••••••••••••••••••••••••••"),W?.defaultReasoningModel&&!E&&k(W.defaultReasoningModel),W?.defaultFastModel&&!T&&F(W.defaultFastModel)),(Y?.ollamaModels?.length??0)>0&&K(Y.ollamaModels)},[Y?.envOpenRouterConfigured,Y?.ollamaModels?.length,W?.defaultReasoningModel]);const O=L.onboarding.validateApiKey.useMutation(),D=L.onboarding.setDefaultModels.useMutation();function Q(me){me.suggestedReasoningModel&&!E&&k(me.suggestedReasoningModel),me.suggestedFastModel&&!T&&F(me.suggestedFastModel)}async function z(){if(!n.trim())return;const me=await O.mutateAsync({provider:"openrouter",key:n.trim()});A(me),me.valid&&Q(me)}async function J(){if(!i.trim())return;const me=await O.mutateAsync({provider:"anthropic",key:i.trim()});C(me),me.valid&&Q(me)}async function ee(){if(!o.trim())return;const me=await O.mutateAsync({provider:"openai",key:o.trim()});p(me),me.valid&&Q(me)}async function re(){if(!c.trim())return;const me=await O.mutateAsync({provider:"gemini",key:c.trim()});g(me),me.valid&&Q(me)}const oe=V.length>0,se=oe||w?.valid===!0||S?.valid===!0||f?.valid===!0||m?.valid===!0||Y?.envOpenRouterConfigured===!0,ae=[];if(oe)for(const me of V)ae.push({id:me,label:me,group:"Ollama"});if(w?.valid){const me=[{id:"openrouter/anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6"},{id:"openrouter/anthropic/claude-opus-4.6",label:"Claude Opus 4.6"},{id:"openrouter/anthropic/claude-haiku-4.5",label:"Claude Haiku 4.5"},{id:"openrouter/openai/gpt-4o",label:"GPT-4o"},{id:"openrouter/openai/gpt-4o-mini",label:"GPT-4o mini"},{id:"openrouter/google/gemini-2.5-pro",label:"Gemini 2.5 Pro"},{id:"openrouter/google/gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"openrouter/meta-llama/llama-3.3-70b-instruct:free",label:"Llama 3.3 70B (free)"}];for(const $e of me)ae.push({...$e,group:"OpenRouter"})}if(S?.valid){const me=[{id:"anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6"},{id:"anthropic/claude-opus-4.6",label:"Claude Opus 4.6"},{id:"anthropic/claude-haiku-4.5",label:"Claude Haiku 4.5"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"Anthropic"})}if(f?.valid){const me=[{id:"openai/gpt-4o",label:"GPT-4o"},{id:"openai/gpt-4o-mini",label:"GPT-4o mini"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"OpenAI"})}if(m?.valid){const me=[{id:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro"},{id:"google/gemini-2.5-flash",label:"Gemini 2.5 Flash"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"Google"})}const le=se&&ae.length>0,je=(Y?.ramGb??0)>=8,Ee=Y?.recommendedLocalModel??null,de=Y?.recommendedModelSize??null;return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-1",children:"Configure models"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-4 leading-relaxed",children:"Connect at least one model source for your agents to use."}),r.jsxs("div",{className:"space-y-2.5 mb-4",children:[r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Ollama (local)"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mt-0.5",children:"Free, runs on your machine"})]}),U?r.jsx("div",{className:"w-4 h-4 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):oe?r.jsxs("span",{className:"text-[11px] text-emerald-400 font-medium",children:[V.length," model",V.length!==1?"s":""]}):r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"Not detected"})]}),oe?r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[V.slice(0,6).map(me=>r.jsx("span",{className:"px-2 py-0.5 rounded-md text-[11px] font-medium bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:me},me)),V.length>6&&r.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[11px] text-[#8A8A99]",children:["+",V.length-6," more"]})]}):!U&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"rounded-xl border border-[#2A2A35] bg-[#0F0F11] p-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4]",children:"Get started with OpenRouter"}),r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-semibold bg-[#6366F1]/15 text-[#6366F1] border border-[#6366F1]/20",children:"No install needed"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mb-2",children:"Free models available. The fastest way to get running."}),r.jsx("button",{onClick:()=>B.current?.focus(),className:"text-[12px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"Go to OpenRouter section ↓"})]}),r.jsx("button",{onClick:()=>$(me=>!me),className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:q?"Hide local install ↑":"Prefer fully local? →"}),q&&r.jsx("div",{className:"rounded-xl border border-[#2A2A35] bg-[#0F0F11] p-3 space-y-3",children:je?r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://ollama.com",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg border border-[#2A2A35] text-[13px] text-[#C8C8D4] hover:border-[#3A3A45] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(cs,{className:"w-3.5 h-3.5"}),"Download Ollama"]}),Ee&&r.jsxs("div",{className:"space-y-1.5",children:[r.jsx(IC,{code:`ollama pull ${Ee}`}),de&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:de})]}),r.jsx(d8e,{onDetected:me=>K(me)})]}):r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Local models require at least 8GB RAM. We recommend OpenRouter instead."})})]})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"OpenRouter"}),Y?.envOpenRouterConfigured&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-emerald-400",children:[r.jsx(Fe,{className:"w-3 h-3"})," Configured via .env"]})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Access 200+ models via one API key"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:n,onChange:me=>{s(me.target.value),A(null)},placeholder:"sk-or-v1-...",ref:B,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:z,disabled:!n.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),w&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",w.valid?"text-emerald-400":"text-red-400"),children:[w.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),w.valid?`Valid — ${w.modelCount} models available`:"Invalid key"]}),w?.valid&&w.suggestedReasoningModel&&r.jsx("div",{className:"mt-3 pt-3 border-t border-[#2A2A35]",children:r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-1",children:"Models available via OpenRouter"})})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Anthropic"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Claude models (Haiku, Sonnet, Opus)"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:i,onChange:me=>{a(me.target.value),C(null)},placeholder:"sk-ant-...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:J,disabled:!i.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),S&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",S.valid?"text-emerald-400":"text-red-400"),children:[S.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),S.valid?"Valid":"Invalid key"]})]}),r.jsxs("button",{onClick:()=>_(me=>!me),className:"flex items-center gap-1.5 text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors w-full py-0.5",children:[r.jsx("span",{children:b?"↑ Hide":"↓ More providers"}),r.jsx("span",{className:"text-[#3A3A45]",children:"(OpenAI, Gemini)"})]}),b&&r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"OpenAI"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"GPT-4o, o1, o3-mini"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:o,onChange:me=>{l(me.target.value),p(null)},placeholder:"sk-...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:ee,disabled:!o.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),f&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",f.valid?"text-emerald-400":"text-red-400"),children:[f.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),f.valid?"Valid":"Invalid key"]})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Google Gemini"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Gemini 2.0, Flash, Pro"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:c,onChange:me=>{d(me.target.value),g(null)},placeholder:"AIza...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:re,disabled:!c.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),m&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",m.valid?"text-emerald-400":"text-red-400"),children:[m.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),m.valid?"Valid":"Invalid key"]})]})]})]}),le&&r.jsxs("div",{className:"bg-[#16161A] border border-[#6366F1]/20 rounded-2xl p-4 mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Default models"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-3",children:"Pre-selected for you. Change anytime in Settings."}),r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Primary (reasoning)"}),r.jsxs(ss,{value:E,onValueChange:me=>{k(me),I("")},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#0F0F11] text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/50 transition-colors",children:[r.jsx("span",{className:"truncate",children:(ae.find(me=>me.id===E)?.label??E)||"Select model..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsxs(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("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx("input",{value:M,onChange:me=>I(me.target.value),onKeyDown:me=>{me.key==="Enter"&&M.trim()&&k(M.trim())},placeholder:"Type model ID...",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"})}),r.jsx(os,{children:Object.entries(ae.reduce((me,$e)=>((me[$e.group]??=[]).push($e),me),{})).map(([me,$e])=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:me}),$e.map(nt=>r.jsxs(vn,{value:nt.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:nt.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},nt.id))]},me))})]})})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Fast (quick tasks)"}),r.jsxs(ss,{value:T,onValueChange:me=>{F(me),H("")},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#0F0F11] text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/50 transition-colors",children:[r.jsx("span",{className:"truncate",children:(ae.find(me=>me.id===T)?.label??T)||"Select model..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsxs(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("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx("input",{value:R,onChange:me=>H(me.target.value),onKeyDown:me=>{me.key==="Enter"&&R.trim()&&F(R.trim())},placeholder:"Type model ID...",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"})}),r.jsx(os,{children:Object.entries(ae.reduce((me,$e)=>((me[$e.group]??=[]).push($e),me),{})).map(([me,$e])=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:me}),$e.map(nt=>r.jsxs(vn,{value:nt.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:nt.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},nt.id))]},me))})]})})]})]})]})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[r.jsx("button",{onClick:async()=>{E&&T&&await D.mutateAsync({reasoningModel:E,fastModel:T}),e()},disabled:!se||D.isPending,className:ye("flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium transition-colors",se?"bg-[#6366F1] text-white hover:bg-[#5254CC]":"bg-white/5 text-[#5A5A6E] border border-[#2A2A35] cursor-not-allowed"),children:D.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"}):r.jsxs(r.Fragment,{children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]})}),r.jsx("button",{onClick:t,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip for now"})]})]})}function f8e({onNext:e}){const[t,n]=y.useState(null);return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Share your workspace"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"How will you use damn.dev?"}),r.jsx("div",{className:"grid grid-cols-2 gap-3 mb-6",children:["solo","team"].map(s=>r.jsxs("button",{onClick:()=>n(s),className:ye("text-left rounded-2xl p-4 border transition-all",t===s?"border-[#6366F1]/50 bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] bg-[#16161A] hover:border-[#3A3A45]"),children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mt-1",children:s==="solo"?"Just me":"With my team"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:s==="solo"?"Default":"Share access via Tailscale"})]},s))}),t==="team"&&r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 mb-6",children:r.jsx(V5,{onComplete:()=>e(),onSkip:e})}),t!=="team"&&r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsxs("button",{onClick:e,disabled:t===null,className:ye("flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium transition-colors",t!==null?"bg-[#6366F1] text-white hover:bg-[#5254CC]":"bg-white/5 text-[#5A5A6E] border border-[#2A2A35] cursor-not-allowed"),children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),r.jsx("button",{onClick:e,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip"})]})]})}function p8e({onComplete:e}){const t=an(),n=L.useUtils(),s=L.onboarding.complete.useMutation(),i=L.onboarding.cooOnboardingChat.useMutation(),a=L.onboarding.setWorkspaceContext.useMutation(),[o,l]=y.useState([]),[c,d]=y.useState(""),[f,p]=y.useState(null),[m,g]=y.useState(!1),[b,_]=y.useState(!0),[w,A]=y.useState(null),S=y.useRef(null),C=y.useRef(null);y.useEffect(()=>{let M=!1;return i.mutateAsync({message:"Hello",history:[]}).then(I=>{M||(l([{role:"assistant",content:I.reply}]),_(!1))}).catch(()=>{M||(_(!1),A("Could not reach COO. You can skip this step and set workspace context later."))}),()=>{M=!0}},[]),y.useEffect(()=>{S.current?.scrollTo({top:S.current.scrollHeight,behavior:"smooth"})},[o,f]);async function E(){const M=c.trim();if(!M||i.isPending)return;d(""),A(null);const I=[...o,{role:"user",content:M}];l(I);try{const R=await i.mutateAsync({message:M,history:I});l([...I,{role:"assistant",content:R.reply}]),R.workspaceContext&&p(R.workspaceContext)}catch{A("COO failed to respond. Try again or skip this step.")}C.current?.focus()}async function k(){f&&(await a.mutateAsync({context:f}),g(!0))}async function T(){await s.mutateAsync(),await n.onboarding.getState.refetch(),t("/channels/chan_coo",{replace:!0}),e()}async function F(){await s.mutateAsync(),await n.onboarding.getState.refetch(),t("/channels/chan_coo",{replace:!0}),e()}return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-1",children:"Meet your COO"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-4 leading-relaxed",children:"A few questions to set up your workspace context."}),r.jsxs("div",{ref:S,className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4 mb-3 space-y-3 max-h-[320px] overflow-y-auto",children:[b&&r.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-[#5A5A6E]",children:[r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),"COO is thinking..."]}),w&&r.jsx("div",{className:"text-[13px] text-red-400/80 leading-relaxed",children:w}),o.map((M,I)=>r.jsx("div",{className:ye("flex",M.role==="user"?"justify-end":"justify-start"),children:r.jsx("div",{className:ye("rounded-xl px-3 py-2 text-[13px] leading-relaxed max-w-[85%]",M.role==="user"?"bg-[#6366F1] text-white":"bg-[#1E1E28] text-[#C8C8D4] border border-[#2A2A35]"),children:M.content})},I)),i.isPending&&o.length>0&&r.jsx("div",{className:"flex justify-start",children:r.jsx("div",{className:"rounded-xl px-3 py-2 bg-[#1E1E28] border border-[#2A2A35]",children:r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin text-[#5A5A6E]"})})})]}),f&&!m&&r.jsxs("div",{className:"bg-[#0F0F11] border border-[#6366F1]/30 rounded-xl p-3 mb-3",children:[r.jsx("p",{className:"text-[11px] font-medium text-[#6366F1] mb-2",children:"Proposed workspace context"}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap leading-relaxed max-h-[160px] overflow-y-auto mb-2",children:f}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{onClick:k,disabled:a.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Fe,{className:"w-3 h-3"}),"Approve"]}),r.jsx("button",{onClick:()=>p(null),className:"px-3 py-1.5 rounded-lg text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Revise"})]})]}),m&&r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-3",children:[r.jsx(sa,{className:"w-3.5 h-3.5 text-emerald-400"}),r.jsx("span",{className:"text-[12px] text-emerald-400",children:"Workspace context saved"})]}),!m&&!b&&r.jsxs("div",{className:"flex gap-2 mb-3",children:[r.jsx("input",{ref:C,type:"text",value:c,onChange:M=>d(M.target.value),onKeyDown:M=>M.key==="Enter"&&E(),placeholder:"Type your answer...",disabled:i.isPending,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors disabled:opacity-50"}),r.jsx("button",{onClick:E,disabled:!c.trim()||i.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-50 transition-colors flex-shrink-0",children:"Send"})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[m&&r.jsxs("button",{onClick:T,disabled:s.isPending,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[s.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):null,"Open damn.dev",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),!m&&r.jsx("button",{onClick:F,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip this step"})]})]})}function m8e(){const e=an(),[t,n]=y.useState(0),s=L.onboarding.skip.useMutation();async function i(){await s.mutateAsync(),e("/",{replace:!0})}return r.jsx("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col items-center justify-center",children:r.jsxs("div",{className:"w-full max-w-lg px-6 flex flex-col",style:{maxHeight:"100vh"},children:[r.jsxs("div",{className:"flex items-center justify-between mb-8 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[18px]",children:"⚡"}),r.jsx("span",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"damn.dev"})]}),r.jsx(c8e,{current:t}),r.jsx("button",{onClick:i,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip setup"})]}),r.jsx("div",{className:"overflow-y-auto flex-1 pb-6",children:r.jsxs(Me,{mode:"wait",children:[t===0&&r.jsx(u8e,{onNext:()=>n(1),onSkip:()=>n(1)},"step0"),t===1&&r.jsx(h8e,{onNext:()=>n(2),onSkip:()=>n(2)},"step1"),t===2&&r.jsx(f8e,{onNext:()=>n(3)},"step2"),t===3&&r.jsx(p8e,{onComplete:()=>{}},"step3")]})})]})})}function x8e(){const e=an(),{data:t}=L.workspace.getMyMembership.useQuery(),{data:n=[]}=L.channels.list.useQuery(),s=L.workspace.completeOnboarding.useMutation();async function i(){await s.mutateAsync();const a=n.find(o=>o.name==="general"&&o.visibility==="public"&&o.channelType==="topic");e(a?`/channels/${a.id}`:"/channels/direction",{replace:!0})}return r.jsx("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col items-center justify-center",children:r.jsxs(ne.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,ease:[.16,1,.3,1]},className:"w-full max-w-md px-6 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mx-auto mb-6",children:r.jsx("span",{className:"text-3xl",children:"👋"})}),r.jsxs("h1",{className:"text-[24px] font-semibold text-[#F0F0F5] mb-3",children:["Welcome to ",t?.workspaceName??"the workspace"]}),t?.ownerName&&r.jsxs("p",{className:"text-[14px] text-[#8A8A99] mb-8 leading-relaxed",children:["You've been invited by ",t.ownerName]}),r.jsxs("button",{onClick:i,disabled:s.isPending,className:"inline-flex items-center gap-2 px-6 py-3 rounded-xl text-[14px] font-semibold bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[s.isPending?r.jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}):null,"Explore your workspace",r.jsx(Jt,{className:"w-4 h-4"})]})]})})}function g8e(){const[e,t]=y.useState("signin"),[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(!1),[c,d]=y.useState(null),[f,p]=y.useState(!1),{data:m}=L.onboarding.hasGoogleAuth.useQuery(),{data:g}=L.onboarding.signupAllowed.useQuery(),b=g?.allowed??!1,_=g?.registrationMode??"closed";y.useEffect(()=>{!b&&e==="signup"&&t("signin")},[b,e]);async function w(A){if(A.preventDefault(),d(null),e==="signup"&&!b){d("This workspace requires an invitation to join.");return}if(i.length<12){d("Password must be at least 12 characters.");return}p(!0);try{if(e==="signup"){const S=await cz.email({email:n,password:i,name:n.split("@")[0]});S.error&&d(S.error.message??"Sign up failed.")}else{const S=await v0.email({email:n,password:i});S.error&&d(S.error.message??"Invalid credentials.")}}catch{d("Something went wrong. Please try again.")}finally{p(!1)}}return r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-6 max-w-sm w-full px-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center",children:r.jsx("span",{className:"text-2xl font-bold text-[#6366F1]",children:"d"})}),r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"damn.dev"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:e==="signin"?"Sign in to your workspace":"Create your workspace"})]}),r.jsxs("form",{onSubmit:w,className:"flex flex-col gap-3 w-full",children:[r.jsx("input",{type:"email",placeholder:"Email",value:n,onChange:A=>s(A.target.value),required:!0,className:"w-full rounded-lg bg-[#1A1A20] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:o?"text":"password",placeholder:"Password (min 12 characters)",value:i,onChange:A=>a(A.target.value),required:!0,minLength:12,className:"w-full rounded-lg bg-[#1A1A20] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 pr-11 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("button",{type:"button",onClick:()=>l(A=>!A),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[#5A5A6A] hover:text-[#8A8A99] transition-colors",tabIndex:-1,children:o?r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 4.411m0 0L21 21"})}):r.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]}),c&&r.jsx("p",{className:"text-[13px] text-red-400",children:c}),r.jsx("button",{type:"submit",disabled:f,className:"w-full rounded-lg bg-[#6366F1] text-white px-5 py-3 text-[14px] font-medium hover:bg-[#5254CC] disabled:opacity-50 transition-colors",children:f?"...":e==="signin"?"Sign in":"Create account"})]}),b?r.jsx("button",{type:"button",onClick:()=>{t(e==="signin"?"signup":"signin"),d(null)},className:"text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:e==="signin"?"Don't have an account? Create one":"Already have an account? Sign in"}):_==="invite"?r.jsx("p",{className:"text-[13px] text-[#5A5A6E] text-center",children:"Need an account? Ask the workspace admin for an invite link."}):r.jsx("p",{className:"text-[13px] text-[#5A5A6E] text-center",children:"Registration is closed."}),m?.enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-3 w-full",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6A]",children:"or"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]}),r.jsxs("button",{onClick:()=>v0.social({provider:"google",callbackURL:window.location.origin+"/"}),className:"flex items-center gap-3 w-full justify-center rounded-lg bg-white text-[#1a1a1a] px-5 py-3 text-[14px] font-medium hover:bg-[#f0f0f0] transition-colors",children:[r.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[r.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),r.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),r.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),r.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Continue with Google"]})]})]})})}function b8e(e){if(!e||typeof e!="object")return!1;const t=String(e.message??"");return t.includes("Failed to fetch")||t.includes("NetworkError")||t.includes("ERR_CONNECTION_REFUSED")||t.includes("ECONNREFUSED")||t.includes("Load failed")||t.includes("fetch failed")}function v8e(){const[e,t]=y.useState(!1);function n(){t(!0),setTimeout(()=>window.location.reload(),500)}return r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-5 max-w-md text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-amber-500/10 border border-amber-500/20 flex items-center justify-center",children:r.jsx("span",{className:"text-amber-400 text-xl",children:"!"})}),r.jsx("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:"Can't reach this workspace"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] leading-relaxed",children:"This is a private workspace running on someone's machine. You need to be on their private network to access it."}),r.jsxs("div",{className:"w-full bg-[#16161A] border border-[#2A2A35] rounded-xl p-5 text-left space-y-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4]",children:"If they shared a Tailscale link:"}),r.jsxs("div",{className:"space-y-2 text-[12px] text-[#8A8A99]",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"1."}),r.jsxs("div",{children:["Install Tailscale on your device",r.jsxs("a",{href:"https://tailscale.com/download",target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 mt-1 text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(cs,{className:"w-3 h-3"}),"tailscale.com/download"]})]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"2."}),r.jsx("span",{children:"Ask them to add you to their Tailnet at tailscale.com/admin"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"3."}),r.jsx("span",{children:"Once connected, refresh this page"})]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Already have Tailscale? Make sure it's running and you're on the same Tailnet as the workspace host."})]}),r.jsxs("button",{onClick:n,disabled:e,className:"flex items-center gap-2 px-4 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 transition-colors disabled:opacity-50",children:[r.jsx(Xi,{className:`w-3.5 h-3.5 ${e?"animate-spin":""}`}),"Retry connection"]})]})})}function y8e(){const{token:e}=am(),t=an(),{data:n}=Mi(),[s,i]=y.useState("signup"),[a,o]=y.useState(""),[l,c]=y.useState(""),[d,f]=y.useState(null),[p,m]=y.useState(!1),{data:g,isLoading:b,error:_}=L.workspace.getInvitation.useQuery({token:e},{enabled:!!e,retry:!1}),w=L.workspace.acceptInvitation.useMutation({onSuccess:()=>{setTimeout(()=>t("/"),2e3)}});y.useEffect(()=>{if(w.isSuccess){const S=setTimeout(()=>t("/"),2e3);return()=>clearTimeout(S)}},[w.isSuccess,t]);async function A(S){if(S.preventDefault(),f(null),l.length<12){f("Password must be at least 12 characters.");return}m(!0);try{if(s==="signup"){const C=await cz.email({email:a,password:l,name:a.split("@")[0],fetchOptions:{headers:{"x-invite-token":e}}});C.error&&f(C.error.message??"Sign up failed.")}else{const C=await v0.email({email:a,password:l});C.error&&f(C.error.message??"Invalid credentials.")}}catch{f("Something went wrong. Please try again.")}finally{m(!1)}}return b?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):_&&b8e(_)?r.jsx(v8e,{}):_||!g?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 max-w-sm text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-[#EF4444]/10 border border-[#EF4444]/20 flex items-center justify-center",children:r.jsx("span",{className:"text-[#EF4444] text-xl",children:"✕"})}),r.jsx("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:"Invitation not valid"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:"This invitation is no longer valid or has expired."}),r.jsx(gn,{to:"/",className:"text-[13px] text-[#6366F1] hover:underline",children:"Go to workspace"})]})}):w.isSuccess?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 max-w-sm text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-[#10B981]/10 border border-[#10B981]/20 flex items-center justify-center",children:r.jsx("span",{className:"text-[#10B981] text-xl",children:"✓"})}),r.jsxs("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:["You've joined ",g.workspaceName,"!"]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Redirecting you to your workspace..."}),r.jsx("div",{className:"w-4 h-4 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})]})}):r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"w-[400px] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl p-8 flex flex-col items-center gap-5",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center",children:r.jsx("span",{className:"text-2xl font-bold text-[#6366F1]",children:"d"})}),r.jsxs("div",{className:"text-center",children:[r.jsx("h1",{className:"text-[20px] font-semibold text-[#F0F0F5]",children:g.workspaceName}),r.jsxs("p",{className:"text-[13px] text-[#8A8A99] mt-1",children:[g.inviterName," invited you to join as"," ",r.jsx("span",{className:"text-[#C8C8D4]",children:g.role})]})]}),w.error&&r.jsx("p",{className:"text-[12px] text-[#EF4444] text-center",children:w.error.message}),n?r.jsx("button",{onClick:()=>w.mutate({token:e}),disabled:w.isPending,className:"w-full px-4 py-2.5 rounded-lg bg-[#6366F1] text-white text-[14px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:w.isPending?"Joining...":"Join Workspace"}):r.jsxs("div",{className:"w-full flex flex-col gap-3",children:[r.jsxs("form",{onSubmit:A,className:"flex flex-col gap-3 w-full",children:[r.jsx("input",{type:"email",placeholder:"Email",value:a,onChange:S=>o(S.target.value),required:!0,className:"w-full rounded-lg bg-[#13131A] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("input",{type:"password",placeholder:"Password (min 12 characters)",value:l,onChange:S=>c(S.target.value),required:!0,minLength:12,className:"w-full rounded-lg bg-[#13131A] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),d&&r.jsx("p",{className:"text-[12px] text-red-400",children:d}),r.jsx("button",{type:"submit",disabled:p,className:"w-full rounded-lg bg-[#6366F1] text-white px-5 py-3 text-[14px] font-medium hover:bg-[#5254CC] disabled:opacity-50 transition-colors",children:p?"...":s==="signup"?"Create account & join":"Sign in & join"})]}),r.jsx("button",{type:"button",onClick:()=>{i(s==="signin"?"signup":"signin"),f(null)},className:"text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:s==="signup"?"Already have an account? Sign in":"Don't have an account? Create one"}),r.jsxs("div",{className:"flex items-center gap-3 w-full",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6A]",children:"or"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]}),r.jsxs("button",{onClick:()=>v0.social({provider:"google",callbackURL:`${window.location.origin}/invite/${e}`}),className:"flex items-center gap-3 w-full justify-center rounded-lg bg-white text-[#1a1a1a] px-5 py-3 text-[14px] font-medium hover:bg-[#f0f0f0] transition-colors",children:[r.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[r.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),r.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),r.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),r.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Continue with Google"]})]})]})})}function _8e({open:e,onClose:t}){const[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(0),c=y.useRef(null),d=an(),[f,p]=y.useState(e);e&&!f&&(s(""),a(""),l(0)),e!==f&&p(e),y.useEffect(()=>{e&&setTimeout(()=>c.current?.focus(),50)},[e]),y.useEffect(()=>{const A=setTimeout(()=>a(n),200);return()=>clearTimeout(A)},[n]);const{data:m=[]}=L.messages.search.useQuery({query:i},{enabled:i.length>=2}),g=m.reduce((A,S)=>{const C=A[S.channelName]??[];return C.push(S),A[S.channelName]=C,A},{}),b=m;function _(A){d(`/channels/${A.channelId}`),t(),setTimeout(()=>{document.getElementById(`msg-${A.messageId}`)?.scrollIntoView({behavior:"smooth",block:"center"})},300)}function w(A){A.key==="Escape"?t():A.key==="ArrowDown"?(A.preventDefault(),l(S=>Math.min(S+1,b.length-1))):A.key==="ArrowUp"?(A.preventDefault(),l(S=>Math.max(S-1,0))):A.key==="Enter"&&b[o]&&_(b[o])}return r.jsx(Me,{children:e&&r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"fixed inset-0 z-[100] flex items-start justify-center pt-[15vh]",style:{backdropFilter:"blur(8px)",backgroundColor:"rgba(0,0,0,0.6)"},onClick:A=>{A.target===A.currentTarget&&t()},children:r.jsxs(ne.div,{initial:{opacity:0,y:-12,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.97},transition:{duration:.2,ease:[.16,1,.3,1]},className:"w-full max-w-[600px] mx-4 bg-[#13131A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-[#2A2A35]",children:[r.jsx(Io,{className:"w-5 h-5 text-[#8A8A99] flex-shrink-0"}),r.jsx("input",{ref:c,value:n,onChange:A=>{s(A.target.value),l(0)},onKeyDown:w,placeholder:"Search messages...",className:"flex-1 bg-transparent text-[20px] text-[#F0F0F5] placeholder:text-[#8A8A99]/50 outline-none"}),r.jsx("kbd",{className:"text-[11px] text-[#8A8A99] bg-white/5 border border-[#2A2A35] px-1.5 py-0.5 rounded-md",children:"esc"})]}),i.length>=2&&r.jsx("div",{className:"max-h-[420px] overflow-y-auto py-2",children:m.length===0?r.jsx("div",{className:"px-5 py-8 text-center",children:r.jsxs("p",{className:"text-[14px] text-[#8A8A99]",children:['No messages found for "',i,'"']})}):Object.entries(g).map(([A,S])=>r.jsxs("div",{children:[r.jsx("div",{className:"px-4 py-1.5 sticky top-0 bg-[#13131A]",children:r.jsxs("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:["#",A]})}),S.map(C=>{const E=b.indexOf(C),k=E===o;return r.jsxs("button",{onClick:()=>_(C),onMouseEnter:()=>l(E),className:"w-full text-left px-4 py-3 transition-colors",style:{backgroundColor:k?"rgba(255,255,255,0.04)":"transparent"},children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-0.5",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#C8C8D4]",children:"Message"}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:Ir(C.createdAt)})]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] leading-relaxed",children:w8e(C.snippet,i)})]},C.messageId)})]},A))}),i.length<2&&r.jsx("div",{className:"px-5 py-6 text-center",children:r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Type at least 2 characters to search"})}),r.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 border-t border-[#2A2A35]",children:[r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[r.jsx("kbd",{className:"bg-white/5 border border-[#2A2A35] px-1 py-0.5 rounded text-[10px] mr-1",children:"↑↓"}),"navigate"]}),r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[r.jsx("kbd",{className:"bg-white/5 border border-[#2A2A35] px-1 py-0.5 rounded text-[10px] mr-1",children:"↵"}),"jump"]})]})]})})})}function w8e(e,t){return e.split(new RegExp(`(${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi")).map((s,i)=>s.toLowerCase()===t.toLowerCase()?r.jsx("mark",{className:"bg-[#6366F1]/30 text-[#A5B4FC] rounded-sm px-0.5",children:s},i):s)}function A8e(){return/iPad|iPhone|iPod/.test(navigator.userAgent)&&!("MSStream"in window)}function S8e(){return window.matchMedia("(display-mode: standalone)").matches||"standalone"in navigator&&navigator.standalone===!0}function C8e(){const[e,t]=y.useState(!1),[n,s]=y.useState(!1),[i,a]=y.useState(null);y.useEffect(()=>{if(S8e())return;if(A8e()){localStorage.getItem("pwa-install-dismissed")||t(!0);return}function d(f){f.preventDefault(),a(f),sessionStorage.getItem("pwa-install-dismissed")||s(!0)}return window.addEventListener("beforeinstallprompt",d),()=>window.removeEventListener("beforeinstallprompt",d)},[]);const o=y.useCallback(()=>{localStorage.setItem("pwa-install-dismissed","1"),t(!1)},[]),l=y.useCallback(()=>{sessionStorage.setItem("pwa-install-dismissed","1"),s(!1)},[]),c=y.useCallback(async()=>{i&&(await i.prompt(),s(!1),a(null))},[i]);return r.jsxs(Me,{children:[e&&r.jsxs(ne.div,{initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:"fixed bottom-4 left-4 right-4 z-50 rounded-xl bg-[#1A1A2E] border border-[#2A2A35] p-4 shadow-2xl max-w-md mx-auto",children:[r.jsxs("p",{className:"text-[13px] text-[#C0C0CC] leading-relaxed",children:["For the best experience, add damn.dev to your Home Screen: tap"," ",r.jsx("span",{className:"inline-flex items-center align-middle mx-0.5",children:r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#6366F1]",children:[r.jsx("path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"}),r.jsx("polyline",{points:"16 6 12 2 8 6"}),r.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"15"})]})})," ","Share → Add to Home Screen"]}),r.jsx("button",{onClick:o,className:"mt-3 text-[12px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"Got it"})]}),n&&r.jsxs(ne.div,{initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:"fixed bottom-4 left-4 right-4 z-50 rounded-xl bg-[#1A1A2E] border border-[#2A2A35] p-4 shadow-2xl max-w-md mx-auto flex items-center justify-between gap-3",children:[r.jsx("p",{className:"text-[13px] text-[#C0C0CC]",children:"Install damn.dev for a native experience"}),r.jsxs("div",{className:"flex gap-2 shrink-0",children:[r.jsx("button",{onClick:l,className:"text-[12px] text-[#8A8A99] hover:text-[#C0C0CC] transition-colors px-2 py-1",children:"Not now"}),r.jsx("button",{onClick:c,className:"text-[12px] font-medium bg-[#6366F1] text-white rounded-lg px-3 py-1.5 hover:bg-[#5558E6] transition-colors",children:"Install"})]})]})]})}function j8e(e){const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),s=atob(n),i=new Uint8Array(s.length);for(let a=0;a<s.length;a++)i[a]=s.charCodeAt(a);return i}const cO="pwa-push-retry-after";function N8e(){const e=y.useRef(!1),{data:t}=L.notifications.getVapidKey.useQuery(void 0,{enabled:!Va}),n=L.notifications.registerToken.useMutation(),s=y.useCallback(async()=>{if(!t?.vapidKey||!("serviceWorker"in navigator)||!("PushManager"in window))return;const a=await navigator.serviceWorker.ready;let o=await a.pushManager.getSubscription();o||(o=await a.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:j8e(t.vapidKey).buffer})),n.mutate({token:JSON.stringify(o.toJSON()),platform:"web"})},[t?.vapidKey,n]),i=y.useCallback(async()=>{if(e.current)return;e.current=!0;const a=localStorage.getItem(cO);if(!(a&&Date.now()<Number(a))){if(Notification.permission==="granted"){await s();return}Notification.permission==="default"&&(await Notification.requestPermission()==="granted"?await s():localStorage.setItem(cO,String(Date.now()+1440*60*1e3)))}},[s]);return y.useEffect(()=>{t?.vapidKey&&Notification.permission==="granted"&&s()},[t?.vapidKey,s]),y.useEffect(()=>{if(!t?.vapidKey||Notification.permission!=="default")return;function a(){i()}return window.addEventListener("pwa-push-prompt",a,{once:!0}),()=>window.removeEventListener("pwa-push-prompt",a)},[t?.vapidKey,i]),{promptForPermission:i}}function k8e(){const[e,t]=y.useState(null),[n,s]=y.useState(!1),[i,a]=y.useState("idle"),[o,l]=y.useState(null),[c,d]=y.useState(!1);y.useEffect(()=>{fetch(`${oi}/api/version`,{credentials:"include"}).then(b=>b.json()).then(b=>{if(b.updateAvailable&&b.latest){const _=`dismissed_update_${b.latest}`;localStorage.getItem(_)||t(b)}}).catch(()=>{})},[]);const f=y.useCallback(()=>{const b=Date.now(),_=setInterval(async()=>{if(Date.now()-b>3e5){clearInterval(_),a("error"),l("Update may have failed. Check server logs.");return}try{(await fetch(`${oi}/health`)).ok&&(clearInterval(_),a("done"),setTimeout(()=>window.location.reload(),1e3))}catch{a("restarting")}},2e3)},[]),p=y.useCallback(async()=>{if(!e)return;if(typeof window<"u"&&"__TAURI__"in window){try{const{check:_}=await X(async()=>{const{check:A}=await import("./index-Cpew6ait.js");return{check:A}},__vite__mapDeps([105,1])),w=await _();if(w){a("updating"),await w.downloadAndInstall();const{relaunch:A}=await X(async()=>{const{relaunch:S}=await import("./index-CO34o7br.js");return{relaunch:S}},__vite__mapDeps([106,1]));await A()}}catch{a("error"),l("Download the latest version from damn.dev")}return}a("updating");try{const _=await fetch(`${oi}/api/update`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}});if(_.status===403){a("error"),l("Only the workspace owner can trigger updates");return}const w=await _.json();if(w.error==="use_native_updater"){a("error"),l("Download the latest version from damn.dev");return}if(!w.ok){a("error"),l(w.error??"Update failed");return}f()}catch{a("error"),l("Failed to start update. Check server logs.")}},[e,f]);if(!e||n)return null;function m(){e?.latest&&localStorage.setItem(`dismissed_update_${e.latest}`,"1"),s(!0)}const g={"docker-vps":"SSH into your server and re-run your install script.",tauri:"Download the latest version from damn.dev."};return r.jsxs("div",{className:"bg-[#1A1A2E] border-b border-[#2A2A35] text-[#9090A0] text-[12px] py-1.5 px-4 flex flex-col flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:["damn.dev ",e.latest," is available"]}),e.canAutoUpdate?r.jsx("button",{onClick:p,className:"px-2 py-0.5 rounded bg-[#6366F1]/20 text-[#818CF8] hover:bg-[#6366F1]/30 transition-colors text-[11px] font-medium",children:"Update now"}):r.jsx("span",{className:"text-[#707080]",children:g[e.installPath]??"Re-run your install script to update."}),e.releaseNotes&&r.jsx("button",{onClick:()=>d(b=>!b),className:"text-[#707080] hover:text-[#9090A0] transition-colors text-[11px]",children:c?"Hide":"What's new"})]}),i==="updating"&&r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Updating..."]}),i==="restarting"&&r.jsxs("span",{className:"flex items-center gap-2 animate-pulse",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Restarting..."]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E]",children:"Updated!"}),i==="error"&&r.jsx("span",{className:"text-[#F87171]",children:o})]}),(i==="idle"||i==="error")&&r.jsx("button",{onClick:m,className:"ml-4 text-[#9090A0] hover:text-[#F0F0F5] transition-colors",children:"×"})]}),c&&e.releaseNotes&&r.jsx("div",{className:"mt-1.5 pt-1.5 border-t border-[#2A2A35] text-[11px] text-[#707080] whitespace-pre-wrap max-h-40 overflow-y-auto",children:e.releaseNotes})]})}function E8e(){const{data:e,refetch:t}=L.settings.getOpenClawVersion.useQuery(void 0,{refetchInterval:6e4,retry:!1}),[n,s]=y.useState(!1),[i,a]=y.useState("idle"),[o,l]=y.useState(null),c=L.settings.updateOpenClaw.useMutation();if(!e?.updateAvailable||n)return null;async function d(){a("updating");try{const f=await c.mutateAsync();f.ok?(a("done"),setTimeout(()=>{t(),s(!0)},3e3)):(a("error"),l(f.error??"Update failed"))}catch{a("error"),l("Failed to start update. Check server logs.")}}return r.jsxs("div",{className:"bg-[#1A1A2E] border-b border-[#2A2A35] text-[#9090A0] text-[12px] py-1.5 px-4 flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:["OpenClaw ",e.minimum," required (current: ",e.current,")"]}),r.jsx("button",{onClick:d,className:"px-2 py-0.5 rounded bg-[#6366F1]/20 text-[#818CF8] hover:bg-[#6366F1]/30 transition-colors text-[11px] font-medium",children:"Update now"})]}),i==="updating"&&r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Updating OpenClaw..."]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E]",children:"OpenClaw updated!"}),i==="error"&&r.jsx("span",{className:"text-[#F87171]",children:o})]}),(i==="idle"||i==="error")&&r.jsx("button",{onClick:()=>s(!0),className:"ml-4 text-[#9090A0] hover:text-[#F0F0F5] transition-colors",children:"×"})]})}function F8e(){const{data:e,refetch:t,isFetching:n}=L.settings.getOpenClawHealth.useQuery(void 0,{refetchInterval:15e3,retry:!1,refetchOnWindowFocus:!0}),s=L.settings.restartOpenClaw.useMutation(),[i,a]=y.useState("idle"),[o,l]=y.useState(null),c=e?.checkedAt&&e.checkedAt!==new Date(0).toISOString();if(!e||e.healthy||!c)return null;async function d(){a("restarting"),l(null);try{const p=await s.mutateAsync(void 0);p.kind==="restarted"?(a("done"),setTimeout(()=>{a("idle"),t()},1500)):p.kind==="skipped"?(a("skipped"),l(p.detail??p.reason)):(a("failed"),l(p.error))}catch(p){a("failed"),l(p instanceof Error?p.message:"Restart request failed.")}}const f=e.installPath==="docker-local"?"The backend will restart OpenClaw via `docker compose up -d`.":e.installPath==="tauri"?"The sidecar backend will restart OpenClaw via `docker compose up -d`.":e.installPath==="docker-vps"?e.canRestartFromBackend?"The backend will restart OpenClaw via the docker-socket-proxy sidecar.":"This backend runs inside a container without a docker-socket-proxy sidecar. SSH into the host and run `docker compose restart openclaw` — or redeploy to pick up the proxy service.":"OpenClaw runs as a native process on this install. Restart it from the terminal (e.g. `openclaw start`).";return r.jsxs("div",{className:"bg-[#2A1414] border-b border-[#F87171]/30 text-[#FCA5A5] text-[12px] py-1.5 px-4 flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[r.jsx("span",{className:"font-medium",children:"OpenClaw unreachable"}),r.jsxs("span",{className:"text-[#F87171]/70",children:["· ",f]}),e.lastError&&r.jsxs("span",{className:"text-[#F87171]/50 text-[11px]",children:["(",e.lastError,")"]})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{t()},disabled:n,className:"px-2 py-0.5 rounded bg-[#F87171]/10 text-[#FCA5A5] hover:bg-[#F87171]/20 transition-colors text-[11px] font-medium disabled:opacity-50",children:n?"Checking…":"Retry"}),e.canRestartFromBackend&&r.jsx("button",{onClick:d,className:"px-2 py-0.5 rounded bg-[#F87171]/20 text-[#FCA5A5] hover:bg-[#F87171]/30 transition-colors text-[11px] font-medium",children:"Restart OpenClaw"})]}),i==="restarting"&&r.jsxs("span",{className:"flex items-center gap-2 text-[11px]",children:[r.jsx("span",{className:"w-3 h-3 border border-[#F87171]/40 border-t-[#F87171] rounded-full animate-spin"}),"Restarting…"]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E] text-[11px]",children:"Restart succeeded"}),i==="skipped"&&r.jsx("span",{className:"text-[#F59E0B] text-[11px]",title:o??void 0,children:"Skipped — hover for details"}),i==="failed"&&r.jsx("span",{className:"text-[#F87171] text-[11px]",title:o??void 0,children:"Failed — hover for details"})]})]})}function T8e(){return 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-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mb-4",children:r.jsx("span",{className:"text-2xl",children:"⚡"})}),r.jsx("h2",{className:"text-[18px] font-semibold text-[#F0F0F5] mb-2",children:"Select a channel"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] max-w-xs leading-relaxed",children:"Choose a channel from the sidebar to start working with your team."})]})}function M8e({children:e}){const t=an(),{data:n,isLoading:s}=L.workspace.getMyMembership.useQuery(void 0,{staleTime:0,refetchOnWindowFocus:!1,retry:!1}),i=n?.role==="owner",{data:a,isLoading:o}=L.onboarding.getState.useQuery(void 0,{staleTime:0,refetchOnWindowFocus:!1,retry:!1,enabled:i});return y.useEffect(()=>{if(!(s||!n)){if(n.role!=="owner"){n.onboardedAt||t("/welcome",{replace:!0});return}o||!a||!a.completed&&!a.skippedAt&&t("/onboarding",{replace:!0})}},[a,o,n,s,t]),s||i&&o?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):r.jsx(r.Fragment,{children:e})}function R8e({children:e}){const{data:t,isPending:n}=Mi();return n?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):t?r.jsx(r.Fragment,{children:e}):r.jsx(g8e,{})}function D8e({children:e}){const{isPending:t}=Mi();return t?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):r.jsx(r.Fragment,{children:e})}function O8e(){const[e,t]=y.useState(!1),n=Je(a=>a.setUnreadCounts),{data:s}=Mi(),{data:i}=L.readReceipts.getUnread.useQuery(void 0,{staleTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,enabled:!!s});return y.useEffect(()=>{i&&n(i)},[i,n]),y.useEffect(()=>{function a(o){(o.metaKey||o.ctrlKey)&&o.key==="k"&&(o.preventDefault(),t(l=>!l))}return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[]),N8e(),r.jsxs("div",{className:"flex flex-col h-screen",children:[r.jsx(k8e,{}),r.jsx(E8e,{}),r.jsx(F8e,{}),r.jsxs(Q_,{children:[r.jsx(ms,{path:"/invite/:token",element:r.jsx(D8e,{children:r.jsx(y8e,{})})}),r.jsx(ms,{path:"*",element:r.jsxs(R8e,{children:[r.jsxs(Q_,{children:[r.jsx(ms,{path:"/onboarding",element:r.jsx(m8e,{})}),r.jsx(ms,{path:"/welcome",element:r.jsx(x8e,{})}),r.jsx(ms,{path:"*",element:r.jsx(M8e,{children:r.jsx(qye,{children:r.jsxs(Q_,{children:[r.jsx(ms,{path:"/",element:r.jsx(lm,{to:"/channels/direction",replace:!0})}),r.jsx(ms,{path:"/channels/:channelId",element:r.jsx(UMe,{})}),r.jsx(ms,{path:"/agents",element:r.jsx(tRe,{})}),r.jsx(ms,{path:"/agents/new",element:r.jsx(pRe,{})}),r.jsx(ms,{path:"/agents/edit-soul/:agentId",element:r.jsx(xRe,{})}),r.jsx(ms,{path:"/skills",element:r.jsx(BRe,{})}),r.jsx(ms,{path:"/deliverables",element:r.jsx(qDe,{})}),r.jsx(ms,{path:"/missions",element:r.jsx(GDe,{})}),r.jsx(ms,{path:"/coo",element:r.jsx(ZRe,{})}),r.jsx(ms,{path:"/settings",element:r.jsx(uDe,{})}),r.jsx(ms,{path:"/federation/:nodeId/:agentId",element:r.jsx(IDe,{})}),r.jsx(ms,{path:"*",element:r.jsx(T8e,{})})]})})})})]}),r.jsx(_8e,{open:e,onClose:()=>t(!1)})]})})]}),r.jsx(C8e,{})]})}GG.createRoot(document.getElementById("root")).render(r.jsx(y.StrictMode,{children:r.jsx(aJ,{children:r.jsxs(pY,{children:[r.jsx(O8e,{}),r.jsx(QY,{position:"bottom-right",toastOptions:{style:{background:"#1C1C24",border:"1px solid #2A2A35",color:"#C8C8D4",fontSize:"12px"}}})]})})}));
|