@agentprojectcontext/apx 1.45.0 → 1.46.0

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.
@@ -647,10 +647,10 @@ Make sure your charset is UTF-8`);c=(c>>>8&255)*192+(c&255),o.put(c,13)}},kh=s,k
647
647
  The chosen QR Code version cannot contain this amount of data.
648
648
  Minimum version required to store current data is: `+U+`.
649
649
  `);const I=E(O,z,D),V=e.getSymbolSize(O),H=new o(V);return k(H,O),N(H),y(H,O),S(H,z,0),O>=7&&w(H,O),C(H,I),isNaN(L)&&(L=u.getBestMask(H,S.bind(null,H,z))),u.applyMask(L,H),S(H,z,L),{modules:H,version:O,errorCorrectionLevel:z,maskPattern:L,segments:D}}return lh.create=function(O,z){if(typeof O>"u"||O==="")throw new Error("No input text");let L=t.M,D,U;return typeof z<"u"&&(L=t.from(z.errorCorrectionLevel,t.M),D=g.from(z.version),U=u.from(z.maskPattern),z.toSJISFunc&&e.setToSJISFunction(z.toSJISFunc)),A(O,D,L,U)},lh}var Ch={},Nh={},Lw;function EN(){return Lw||(Lw=1,(function(e){function t(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let o=s.slice().replace("#","").split("");if(o.length<3||o.length===5||o.length>8)throw new Error("Invalid hex color: "+s);(o.length===3||o.length===4)&&(o=Array.prototype.concat.apply([],o.map(function(c){return[c,c]}))),o.length===6&&o.push("F","F");const l=parseInt(o.join(""),16);return{r:l>>24&255,g:l>>16&255,b:l>>8&255,a:l&255,hex:"#"+o.slice(0,6).join("")}}e.getOptions=function(o){o||(o={}),o.color||(o.color={});const l=typeof o.margin>"u"||o.margin===null||o.margin<0?4:o.margin,c=o.width&&o.width>=21?o.width:void 0,u=o.scale||4;return{width:c,scale:c?4:u,margin:l,color:{dark:t(o.color.dark||"#000000ff"),light:t(o.color.light||"#ffffffff")},type:o.type,rendererOpts:o.rendererOpts||{}}},e.getScale=function(o,l){return l.width&&l.width>=o+l.margin*2?l.width/(o+l.margin*2):l.scale},e.getImageWidth=function(o,l){const c=e.getScale(o,l);return Math.floor((o+l.margin*2)*c)},e.qrToImageData=function(o,l,c){const u=l.modules.size,p=l.modules.data,m=e.getScale(u,c),g=Math.floor((u+c.margin*2)*m),h=c.margin*m,b=[c.color.light,c.color.dark];for(let _=0;_<g;_++)for(let k=0;k<g;k++){let N=(_*g+k)*4,y=c.color.light;if(_>=h&&k>=h&&_<g-h&&k<g-h){const w=Math.floor((_-h)/m),S=Math.floor((k-h)/m);y=b[p[w*u+S]?1:0]}o[N++]=y.r,o[N++]=y.g,o[N++]=y.b,o[N]=y.a}}})(Nh)),Nh}var Iw;function a7(){return Iw||(Iw=1,(function(e){const t=EN();function s(l,c,u){l.clearRect(0,0,c.width,c.height),c.style||(c.style={}),c.height=u,c.width=u,c.style.height=u+"px",c.style.width=u+"px"}function o(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(c,u,p){let m=p,g=u;typeof m>"u"&&(!u||!u.getContext)&&(m=u,u=void 0),u||(g=o()),m=t.getOptions(m);const h=t.getImageWidth(c.modules.size,m),b=g.getContext("2d"),_=b.createImageData(h,h);return t.qrToImageData(_.data,c,m),s(b,g,h),b.putImageData(_,0,0),g},e.renderToDataURL=function(c,u,p){let m=p;typeof m>"u"&&(!u||!u.getContext)&&(m=u,u=void 0),m||(m={});const g=e.render(c,u,m),h=m.type||"image/png",b=m.rendererOpts||{};return g.toDataURL(h,b.quality)}})(Ch)),Ch}var Eh={},Bw;function s7(){if(Bw)return Eh;Bw=1;const e=EN();function t(l,c){const u=l.a/255,p=c+'="'+l.hex+'"';return u<1?p+" "+c+'-opacity="'+u.toFixed(2).slice(1)+'"':p}function s(l,c,u){let p=l+c;return typeof u<"u"&&(p+=" "+u),p}function o(l,c,u){let p="",m=0,g=!1,h=0;for(let b=0;b<l.length;b++){const _=Math.floor(b%c),k=Math.floor(b/c);!_&&!g&&(g=!0),l[b]?(h++,b>0&&_>0&&l[b-1]||(p+=g?s("M",_+u,.5+k+u):s("m",m,0),m=0,g=!1),_+1<c&&l[b+1]||(p+=s("h",h),h=0)):m++}return p}return Eh.render=function(c,u,p){const m=e.getOptions(u),g=c.modules.size,h=c.modules.data,b=g+m.margin*2,_=m.color.light.a?"<path "+t(m.color.light,"fill")+' d="M0 0h'+b+"v"+b+'H0z"/>':"",k="<path "+t(m.color.dark,"stroke")+' d="'+o(h,g,m.margin)+'"/>',N='viewBox="0 0 '+b+" "+b+'"',w='<svg xmlns="http://www.w3.org/2000/svg" '+(m.width?'width="'+m.width+'" height="'+m.width+'" ':"")+N+' shape-rendering="crispEdges">'+_+k+`</svg>
650
- `;return typeof p=="function"&&p(null,w),w},Eh}var Uw;function r7(){if(Uw)return _l;Uw=1;const e=B8(),t=n7(),s=a7(),o=s7();function l(c,u,p,m,g){const h=[].slice.call(arguments,1),b=h.length,_=typeof h[b-1]=="function";if(!_&&!e())throw new Error("Callback required as last argument");if(_){if(b<2)throw new Error("Too few arguments provided");b===2?(g=p,p=u,u=m=void 0):b===3&&(u.getContext&&typeof g>"u"?(g=m,m=void 0):(g=m,m=p,p=u,u=void 0))}else{if(b<1)throw new Error("Too few arguments provided");return b===1?(p=u,u=m=void 0):b===2&&!u.getContext&&(m=p,p=u,u=void 0),new Promise(function(k,N){try{const y=t.create(p,m);k(c(y,u,m))}catch(y){N(y)}})}try{const k=t.create(p,m);g(null,c(k,u,m))}catch(k){g(k)}}return _l.create=t.create,_l.toCanvas=l.bind(null,s.render),_l.toDataURL=l.bind(null,s.renderToDataURL),_l.toString=l.bind(null,function(c,u,p){return o.render(c,p)}),_l}var o7=r7();const l7=kx(o7);function i7({value:e,size:t=200}){const[s,o]=x.useState(null);return x.useEffect(()=>{let l=!0;return l7.toDataURL(e,{margin:2,width:t*2,errorCorrectionLevel:"M"}).then(c=>{l&&o(c)}).catch(()=>{l&&o(null)}),()=>{l=!1}},[e,t]),r.jsx("div",{className:"grid place-items-center rounded-lg bg-white p-3",style:{width:t+24,height:t+24},children:s?r.jsx("img",{src:s,width:t,height:t,alt:"QR"}):r.jsx("div",{className:"size-full animate-pulse rounded bg-muted"})})}function c7(e){return e.find(t=>!t.includes("127.0.0.1")&&!t.includes("localhost"))||e[0]||window.location.origin}function u7({open:e,onClose:t,onPaired:s}){const o=lt(),[l,c]=x.useState(null),[u,p]=x.useState(null),[m,g]=x.useState(0),[h,b]=x.useState(!1),_=x.useRef(null),k=x.useCallback(async()=>{c(null),p(null),b(!1);try{const C=await $l.init();c(C),g(Math.round((C.ttl_ms||9e4)/1e3))}catch(C){C instanceof Fc&&C.status===403?p(f("settings.devices_pair_localhost_only")):p(C.message)}},[]);x.useEffect(()=>{e?k():(c(null),p(null),b(!1))},[e,k]),x.useEffect(()=>{if(!l||h||m<=0)return;const C=window.setTimeout(()=>g(E=>E-1),1e3);return()=>window.clearTimeout(C)},[l,m,h]),x.useEffect(()=>{if(!e||!l||h)return;let C=!0;const E=async()=>{try{const R=await $l.status(l.pairing_id);if(!C)return;if(R.status==="confirmed"){b(!0),o.success(f("settings.devices_pair_done")),s(),window.setTimeout(()=>{C&&t()},900);return}if(R.status==="expired"||R.status==="unknown"){g(0);return}}catch{}_.current=window.setTimeout(E,1500)};return _.current=window.setTimeout(E,1500),()=>{C=!1,_.current&&window.clearTimeout(_.current)}},[e,l,h,t,s,o]);const N=!!l&&!h&&m<=0,y=l?c7(l.lan_urls):"",w=l?`${y}/#pair=${l.pairing_id}`:"",S=async(C,E)=>{try{await navigator.clipboard.writeText(C),o.success(E)}catch{o.error(C)}};return r.jsxs(An,{open:e,onClose:t,title:f("settings.devices_pair_title"),description:f("settings.devices_pair_desc"),footer:r.jsx(me,{variant:"secondary",onClick:t,children:f("common.close")}),children:[u&&r.jsx("p",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:u}),!u&&!l&&r.jsxs("div",{className:"flex items-center gap-2 py-8 text-sm text-muted-fg",children:[r.jsx(va,{})," ",f("common.loading")]}),!u&&l&&r.jsxs("div",{className:"flex flex-col items-center gap-4",children:[r.jsx("div",{className:N?"opacity-40":"",children:r.jsx(i7,{value:w,size:196})}),h?r.jsx("p",{className:"text-sm font-medium text-emerald-500",children:f("settings.devices_pair_done")}):N?r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("p",{className:"text-sm text-muted-fg",children:f("settings.devices_pair_expired")}),r.jsx(me,{variant:"primary",onClick:()=>void k(),children:f("settings.devices_pair_regen")})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-center text-xs text-muted-fg",children:f("settings.devices_pair_scan")}),r.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-fg",children:[r.jsx(va,{size:12}),r.jsx("span",{children:f("settings.devices_pair_waiting")}),r.jsxs("span",{className:"tabular-nums",children:["· ",f("settings.devices_pair_expires",{s:m})]})]}),r.jsxs("div",{className:"w-full space-y-3 border-t border-border pt-3",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-xs text-muted-fg",children:f("settings.devices_pair_link")}),r.jsxs("div",{className:"flex items-stretch gap-2",children:[r.jsx("code",{className:"min-w-0 flex-1 break-all rounded-md bg-muted px-3 py-2 text-xs",children:w}),r.jsx(et,{content:f("settings.devices_pair_copy"),children:r.jsx(me,{size:"sm",variant:"secondary",onClick:()=>S(w,f("settings.devices_pair_copied")),children:r.jsx(Fd,{size:14})})})]})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-xs text-muted-fg",children:f("settings.devices_pair_code")}),r.jsxs("div",{className:"flex items-stretch gap-2",children:[r.jsx("code",{className:"min-w-0 flex-1 break-all rounded-md bg-muted px-3 py-2 text-center text-sm",children:l.pairing_id}),r.jsx(et,{content:f("settings.devices_pair_copy"),children:r.jsx(me,{size:"sm",variant:"secondary",onClick:()=>S(l.pairing_id,f("settings.devices_pair_copied_code")),children:r.jsx(Fd,{size:14})})})]})]})]})]})]})]})}function d7(){const e=lt(),{clients:t,isLoading:s,mutate:o}=I8(),[l,c]=x.useState(!1),u=async p=>{if(confirm(f("settings.devices_revoke_confirm",{id:p})))try{await $l.revoke(p),e.success(f("settings.devices_revoke_success")),o()}catch(m){e.error(m.message)}};return r.jsxs(Ye,{title:f("settings.devices"),description:f("settings.devices_sub"),action:r.jsxs(me,{size:"sm",variant:"primary",onClick:()=>c(!0),children:[r.jsx(LM,{size:14})," ",f("settings.devices_pair_btn")]}),children:[s&&r.jsx(ot,{}),!s&&t.length===0&&r.jsx(xt,{children:f("settings.devices_empty")}),t.length>0&&r.jsx("ul",{className:"space-y-2 text-sm",children:t.map(p=>r.jsxs("li",{className:"flex items-center gap-3 rounded-md border border-border bg-muted/30 px-3 py-2",children:[r.jsx("span",{className:"font-medium",children:p.label||p.id}),r.jsx(Fe,{tone:p.kind==="web"?"info":p.kind==="deck"?"success":"muted",children:p.kind}),r.jsxs("span",{className:"font-mono text-xs text-muted-fg",children:["…",p.token_suffix]}),r.jsxs("span",{className:"ml-auto text-xs text-muted-fg",children:[f("settings.devices_last_seen")," ",p.last_seen?new Date(p.last_seen).toLocaleString():f("settings.devices_never")]}),r.jsx(me,{size:"sm",variant:"destructive",onClick:()=>u(p.id),children:f("settings.devices_revoke")})]},p.id))}),r.jsx(u7,{open:l,onClose:()=>c(!1),onPaired:()=>o()})]})}const f7=[{key:"daemon",label:"Daemon",description:"~/.apx/config.json. General APX config.",fields:[{path:"port",label:"Port",kind:"number",placeholder:"7430"},{path:"host",label:"Host",placeholder:"127.0.0.1"},{path:"log_level",label:"Log level",placeholder:"info"},{path:"user.language",label:"Language",placeholder:"en"},{path:"user.locale",label:"Locale",placeholder:"en-US"},{path:"user.timezone",label:"Timezone",placeholder:"America/Argentina/Salta"}]},{key:"super-agent",label:"Super-agent",fields:[{path:"super_agent.enabled",label:"Super-agent enabled",kind:"boolean"},{path:"super_agent.model",label:"Model",placeholder:"gemini:gemini-2.5-flash"},{path:"super_agent.permission_mode",label:"Permission mode",kind:"select",options:Vx.map(e=>({value:e,label:e}))},{path:"super_agent.system",label:"Extra prompt",kind:"textarea"}]},{key:"telegram",label:"Telegram",fields:[{path:"telegram.enabled",label:"Polling enabled",kind:"boolean"},{path:"telegram.poll_interval_ms",label:"Poll interval ms",kind:"number",placeholder:"1500"},{path:"telegram.respond_with_engine",label:"Respond with engine",kind:"boolean"},{path:"telegram.route_to_agent",label:"Route to agent",placeholder:"master"},{path:"telegram.channels.0.chat_id",label:"Default chat ID"},{path:"telegram.channels.0.bot_token",label:"Default bot token",kind:"password"}]},{key:"engines",label:"Engines",fields:[{path:"engines.anthropic.api_key",label:"Anthropic API key",kind:"password"},{path:"engines.openai.api_key",label:"OpenAI API key",kind:"password"},{path:"engines.openai.base_url",label:"OpenAI base URL",placeholder:"https://api.openai.com/v1"},{path:"engines.groq.api_key",label:"Groq API key",kind:"password"},{path:"engines.groq.base_url",label:"Groq base URL",placeholder:"https://api.groq.com/openai/v1"},{path:"engines.openrouter.api_key",label:"OpenRouter API key",kind:"password"},{path:"engines.openrouter.base_url",label:"OpenRouter base URL",placeholder:"https://openrouter.ai/api/v1"},{path:"engines.gemini.api_key",label:"Gemini API key",kind:"password"},{path:"engines.ollama.base_url",label:"Ollama URL",placeholder:"http://localhost:11434"}]}];function p7(){const{config:e,isLoading:t,patch:s,mutate:o}=Vr();if(t)return r.jsx(ot,{});const l=async c=>{const u={};for(const[p,m]of Object.entries(rv(c)))oa(m)||(u[p]=m);await s(u),o()};return r.jsx(Ye,{title:f("global_config.title"),description:f("settings_ui.global_config_desc"),children:r.jsx(px,{sections:f7,source:e,jsonTitle:"~/.apx/config.json",jsonDescription:f("settings_ui.global_json_desc"),onSaveFields:async(c,u)=>{await s(c,u),o()},onSaveJson:l})})}function m7(){const e=lt(),{health:t,isUp:s}=NC(),o=async()=>{try{await ql.reload(),e.success(f("settings.advanced.reload_success"))}catch(l){e.error(l.message)}};return r.jsxs("div",{className:"space-y-6",children:[r.jsx(Ye,{title:f("daemon.version"),action:r.jsx(me,{size:"sm",onClick:o,children:f("common.reload")}),children:r.jsxs("div",{className:"grid grid-cols-3 gap-3 text-sm",children:[r.jsx(Rh,{label:f("daemon.version"),value:t?.version||"—"}),r.jsx(Rh,{label:f("daemon.uptime"),value:t?`${t.uptime_s}s`:"—"}),r.jsx(Rh,{label:f("daemon.status"),value:f(s?"daemon.running":"daemon.down"),ok:s})]})}),r.jsx(p7,{})]})}function Rh({label:e,value:t,ok:s}){return r.jsxs("div",{className:"rounded-md border border-border bg-muted/30 p-3",children:[r.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-fg",children:e}),r.jsxs("div",{className:"mt-1 flex items-center gap-2 text-base font-medium",children:[s!==void 0&&r.jsx(Yc,{ok:s}),r.jsx("span",{children:t})]})]})}function g7(){const e=lt(),{theme:t,set:s}=qx(),[o,l]=x.useState(""),[c,u]=x.useState(eC()),p=()=>{const g=o.trim();if(g){fo(g);try{localStorage.setItem(Rn.token,g)}catch{}l(""),e.success(f("settings.token_saved"))}},m=g=>{W2(g),u(g),window.location.reload()};return r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2 xl:items-start",children:[r.jsx(Ye,{title:f("settings.appearance"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(me,{variant:t==="light"?"primary":"secondary",onClick:()=>s("light"),children:f("settings.light_mode")}),r.jsx(me,{variant:t==="dark"?"primary":"secondary",onClick:()=>s("dark"),children:f("settings.dark_mode")})]})}),r.jsx(Ye,{title:f("settings.language"),children:r.jsx("div",{className:"flex items-center gap-2",children:J2.map(g=>r.jsx(me,{variant:c===g.value?"primary":"secondary",onClick:()=>m(g.value),children:g.label},g.value))})}),r.jsxs(Ye,{title:f("settings.token"),description:f("settings.token_sub"),children:[r.jsx(fe,{label:f("settings_ui.bearer_label"),children:r.jsx(Ae,{type:"password",placeholder:Hb()?f("settings.token_active"):f("settings.token_paste"),value:o,onChange:g=>l(g.target.value),className:"font-mono",onKeyDown:g=>{g.key==="Enter"&&p()}})}),r.jsx("div",{className:"mt-2",children:r.jsx(me,{variant:"primary",onClick:p,children:f("common.save")})})]})]})}function h7({className:e,...t}){return r.jsx("kbd",{"data-slot":"kbd",className:St("pointer-events-none inline-flex h-5 w-fit min-w-5 items-center justify-center gap-1 rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground select-none in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background dark:in-data-[slot=tooltip-content]:bg-background/10 [&_svg:not([class*='size-'])]:size-3",e),...t})}const _x=typeof navigator<"u"&&/mac/i.test(navigator.platform||"");function x7(e){return(_x?{CommandOrControl:"⌘ Cmd",CmdOrCtrl:"⌘ Cmd",Command:"⌘ Cmd",Cmd:"⌘ Cmd",Super:"⌘ Cmd",Meta:"⌘ Cmd",Control:"⌃ Ctrl",Ctrl:"⌃ Ctrl",Option:"⌥ Opt",Alt:"⌥ Opt",Shift:"⇧ Shift"}:{CommandOrControl:"Ctrl",CmdOrCtrl:"Ctrl",Control:"Ctrl",Ctrl:"Ctrl",Command:"Win",Cmd:"Win",Super:"Win",Meta:"Win",Option:"Alt",Alt:"Alt",Shift:"Shift"})[e]??e}function b7(e){return(e||"").split("+").map(t=>t.trim()).filter(Boolean)}function v7(e){const t=e.code;if(/^(Shift|Control|Alt|Meta|OS)(Left|Right)?$/.test(t))return null;let s;if((s=t.match(/^Key([A-Z])$/))||(s=t.match(/^Digit(\d)$/))||(s=t.match(/^Numpad(\d)$/))||(s=t.match(/^(F\d{1,2})$/))||(s=t.match(/^Arrow(Up|Down|Left|Right)$/)))return s[1];const o={Space:"Space",Enter:"Enter",Tab:"Tab",Backspace:"Backspace",Delete:"Delete",Home:"Home",End:"End",PageUp:"PageUp",PageDown:"PageDown",Insert:"Insert",Minus:"-",Equal:"=",BracketLeft:"[",BracketRight:"]",Backslash:"\\",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backquote:"`"};return o[t]?o[t]:e.key&&e.key.length===1?e.key.toUpperCase():null}function _7(e){const t=v7(e);if(!t)return null;const s=[];(_x?e.metaKey:e.ctrlKey)&&s.push("CommandOrControl"),_x&&e.ctrlKey&&s.push("Control"),e.altKey&&s.push("Alt"),e.shiftKey&&s.push("Shift");const o=s.length>0,l=/^F\d{1,2}$/.test(t);return!o&&!l?null:(s.push(t),s.join("+"))}function y7({value:e,onChange:t,disabled:s,className:o,trailing:l}){const[c,u]=x.useState(!1),p=x.useRef(null);x.useEffect(()=>{if(!c)return;const g=h=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"){u(!1);return}const b=_7(h);b&&(t(b),u(!1))};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[c,t]);const m=b7(e);return r.jsxs("div",{className:ze("flex h-9 w-full max-w-md items-center rounded-md border border-border bg-transparent transition",c&&"ring-2 ring-ring",s&&"opacity-50",o),children:[r.jsxs("button",{ref:p,type:"button",disabled:s,onClick:()=>u(g=>!g),onBlur:()=>u(!1),"aria-label":f("modules_ui.desktop_shortcut_record"),className:"flex h-full min-w-0 flex-1 items-center gap-1.5 rounded-l-md px-3 text-sm outline-none hover:bg-muted/40 focus-visible:bg-muted/40",children:[c?r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.desktop_shortcut_recording")}):m.length?r.jsx("span",{className:"flex min-w-0 flex-wrap items-center gap-1",children:m.map((g,h)=>r.jsxs("span",{className:"flex items-center gap-1",children:[h>0&&r.jsx("span",{className:"text-xs text-muted-fg",children:"+"}),r.jsx(h7,{className:"h-6 min-w-6 border border-border bg-muted px-1.5 text-[13px] font-semibold text-fg shadow-sm",children:x7(g)})]},h))}):r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.desktop_shortcut_record")}),r.jsx("span",{className:"ml-auto whitespace-nowrap pl-2 text-xs text-muted-fg",children:f(c?"modules_ui.desktop_shortcut_esc":"modules_ui.desktop_shortcut_change")})]}),l?r.jsx("div",{className:"flex h-full items-center border-l border-border px-1",children:l}):null]})}const wl={status:()=>ge.get("/desktop/status"),start:()=>ge.post("/desktop/start",{}),stop:()=>ge.post("/desktop/stop",{}),restart:()=>ge.post("/desktop/restart",{}),autostartGet:()=>ge.get("/desktop/autostart"),autostartSet:e=>ge.post("/desktop/autostart",{enable:e})};function j7(e=30){return ge.get(`/messages/global?channel=desktop&limit=${e}`)}function RN({showConfigLink:e=!1}){const t=lt(),{data:s,isLoading:o,mutate:l}=Qe("/desktop/status",()=>wl.status(),{refreshInterval:5e3}),c=!!s?.running,[u,p]=x.useState(null),m=async(_,k)=>{p(_);try{await k()}catch(N){t.error(N.message)}finally{p(null),setTimeout(()=>l(),1200)}},g=()=>m("start",async()=>{const _=await wl.start();t.success(_.already?f("modules_ui.desktop_start_already"):f("modules_ui.desktop_start_done"))}),h=()=>m("stop",async()=>{const _=await wl.stop();t.success(_.stopped?f("modules_ui.desktop_stop_done"):f("modules_ui.desktop_stop_none"))}),b=()=>m("restart",async()=>{(await wl.restart()).reloaded>0?t.success(f("modules_ui.desktop_restart_done")):t.info(f("modules_ui.desktop_restart_none"))});return r.jsx(Ye,{title:f("desktop_screen.status_title"),description:f("modules_ui.desktop_status_desc"),action:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(me,{variant:"primary",size:"sm",onClick:g,loading:u==="start",disabled:c||u!==null&&u!=="start",children:f("modules_ui.desktop_start")}),r.jsx(me,{variant:"secondary",size:"sm",onClick:h,loading:u==="stop",disabled:!c||u!==null&&u!=="stop",children:f("modules_ui.desktop_stop")}),r.jsx(me,{variant:"secondary",size:"sm",onClick:b,loading:u==="restart",disabled:!c||u!==null&&u!=="restart",title:f("modules_ui.desktop_restart_hint"),children:f("modules_ui.desktop_restart")}),e&&r.jsx(wf,{to:"/settings/desktop",children:r.jsxs(me,{size:"sm",variant:"ghost",children:[r.jsx(Cc,{size:14})," ",f("desktop_screen.open_config")]})})]}),children:o?r.jsx(ot,{}):r.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-sm",children:[r.jsx(Yc,{ok:c}),r.jsx("span",{className:"font-medium",children:f(c?"modules_ui.desktop_running":"modules_ui.desktop_stopped")}),r.jsx("button",{type:"button",onClick:()=>l(),className:"text-xs text-muted-fg underline-offset-2 hover:underline",children:f("modules_ui.desktop_refresh")}),r.jsxs("span",{className:"text-xs text-muted-fg",children:["(",f("modules_ui.desktop_from_terminal")," ",r.jsx(zj,{children:"apx desktop start"})," · ",r.jsx(zj,{children:"apx desktop --debug"}),")"]})]})})}const w7="CommandOrControl+G",k7=()=>[{value:"left",label:f("modules_ui.desktop_pos_left")},{value:"center",label:f("modules_ui.desktop_pos_center")},{value:"right",label:f("modules_ui.desktop_pos_right")}],S7=()=>[{value:"system",label:f("modules_ui.desktop_theme_system")},{value:"light",label:f("modules_ui.desktop_theme_light")},{value:"dark",label:f("modules_ui.desktop_theme_dark")}];function C7(){const e=lt(),{config:t,isLoading:s,patch:o}=Vr(),l=t,c=l.desktop?.shortcut||l.overlay?.shortcut||w7,u=l.desktop?.enabled!==!1,p=l.desktop?.theme||"system",m=l.desktop?.position||"right",{data:g,mutate:h}=Qe("/desktop/autostart",()=>wl.autostartGet()),[b,_]=x.useState(c),[k,N]=x.useState(!1),[y,w]=x.useState(!1);x.useEffect(()=>_(c),[c]);const S=async()=>{const R=b.trim();if(!(!R||R===c)){N(!0);try{await o({"desktop.shortcut":R}),e.success(f("modules_ui.desktop_shortcut_saved"))}catch(A){e.error(A.message)}finally{N(!1)}}},C=async(R,A,T)=>{N(!0);try{await o({[R]:A}),e.success(T)}catch(O){e.error(O.message)}finally{N(!1)}},E=async R=>{w(!0);try{await wl.autostartSet(R),await h(),e.success(f(R?"modules_ui.desktop_autostart_on":"modules_ui.desktop_autostart_off"))}catch(A){e.error(A.message)}finally{w(!1)}};return r.jsxs("div",{className:"space-y-6","data-testid":"settings-desktop",children:[r.jsx(RN,{}),r.jsx(Ye,{title:f("desktop_screen.autostart_title"),description:f("modules_ui.desktop_autostart_desc"),children:g?r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx(Qt,{checked:g.enabled,onChange:E,disabled:y,label:g.enabled?f("common.enabled"):f("common.disabled")}),r.jsx("span",{className:"text-xs text-muted-fg",children:f("modules_ui.desktop_platform",{platform:g.platform})})]}):r.jsx(ot,{})}),r.jsx(Ye,{title:f("desktop_screen.shortcut_title"),description:f("modules_ui.desktop_shortcut_desc"),children:s?r.jsx(ot,{}):r.jsx(fe,{label:f("modules_ui.desktop_accelerator"),hint:f("modules_ui.desktop_accelerator_hint"),children:r.jsx(y7,{value:b,onChange:_,disabled:k,trailing:r.jsx(me,{variant:"primary",size:"sm",onClick:S,loading:k,disabled:!b.trim()||b.trim()===c,children:f("common.save")})})})}),r.jsx(Ye,{title:f("desktop_screen.appearance_title"),description:f("modules_ui.desktop_appearance_desc"),children:s?r.jsx(ot,{}):r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("modules_ui.desktop_theme"),hint:f("modules_ui.desktop_restart_apply"),children:r.jsx(_t,{value:p,onChange:R=>C("desktop.theme",R,f("modules_ui.desktop_theme_set",{value:R})),options:S7(),disabled:k})}),r.jsx(fe,{label:f("modules_ui.desktop_position"),hint:f("modules_ui.desktop_position_hint"),children:r.jsx(_t,{value:m,onChange:R=>C("desktop.position",R,f("modules_ui.desktop_position_set",{value:R})),options:k7(),disabled:k})})]})}),r.jsx(Ye,{title:f("desktop_screen.activation_title"),description:f("modules_ui.desktop_activation_desc"),children:s?r.jsx(ot,{}):r.jsxs("div",{className:"space-y-3",children:[r.jsx(Qt,{checked:u,onChange:R=>C("desktop.enabled",R,f(R?"modules_ui.desktop_enabled_toast":"modules_ui.desktop_disabled_toast")),disabled:k,label:f(u?"modules_ui.desktop_plugin_on":"modules_ui.desktop_plugin_off")}),r.jsxs("p",{className:"text-xs text-muted-fg",children:[f("modules_ui.desktop_stt_engine")," ",r.jsx(wf,{to:"/settings/voice",className:"font-medium text-fg underline underline-offset-2",children:f("nav.modules.voice")})," ",f("modules_ui.desktop_stt_engine_suffix")]})]})})]})}function N7({engines:e,order:t,mode:s,configuredProvider:o,onSetMode:l,onSetDefault:c,onToggleEnabled:u,onReorder:p,onConfigure:m,busy:g}){const h=new Map(e.map(N=>[N.id,N])),b=[...t.filter(N=>h.has(N)),...e.map(N=>N.id).filter(N=>!t.includes(N))],_=s==="chain",k=(N,y)=>{const w=b.indexOf(N),S=w+y;if(w<0||S<0||S>=b.length)return;const C=[...b];[C[w],C[S]]=[C[S],C[w]],p(C)};return r.jsxs("div",{className:"space-y-3",children:[r.jsx("div",{className:"rounded-lg border border-border p-3",children:r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-sm font-medium",children:f("voice_ui.selection_mode")}),r.jsx("div",{className:"text-xs text-muted-fg",children:f(_?"voice_ui.mode_chain_desc":"voice_ui.mode_single_desc")})]}),r.jsxs("div",{className:"flex shrink-0 overflow-hidden rounded-md border border-border",role:"group",children:[r.jsx("button",{type:"button",onClick:()=>l("chain"),disabled:g,"data-testid":"voice-mode-chain",className:ze("px-3 py-1.5 text-xs font-medium transition-colors",_?"bg-emerald-500/15 text-emerald-300":"text-muted-fg hover:text-fg"),children:f("voice_ui.mode_chain_btn")}),r.jsx("button",{type:"button",onClick:()=>l("single"),disabled:g,"data-testid":"voice-mode-single",className:ze("border-l border-border px-3 py-1.5 text-xs font-medium transition-colors",_?"text-muted-fg hover:text-fg":"bg-emerald-500/15 text-emerald-300"),children:f("voice_ui.mode_single_btn")})]})]})}),r.jsx("div",{className:"space-y-2",children:b.map((N,y)=>{const w=h.get(N),S=pf[N]||{name:N,note:""},C=!_&&o===N,E=N==="mock";return r.jsxs("div",{"data-testid":`voice-provider-${N}`,className:ze("flex items-center gap-3 rounded-lg border px-3 py-2.5",C?"border-emerald-500/50 bg-emerald-500/10":"border-border",_&&!E&&!w.enabled&&"opacity-60"),children:[_&&r.jsxs("div",{className:"flex flex-col",children:[r.jsx("button",{type:"button",onClick:()=>k(N,-1),disabled:g||y===0,"aria-label":f("voice_ui.move_up"),"data-testid":`voice-provider-${N}-up`,className:"text-muted-fg hover:text-fg disabled:opacity-30",children:r.jsx(Pk,{className:"size-3.5"})}),r.jsx("button",{type:"button",onClick:()=>k(N,1),disabled:g||y===b.length-1,"aria-label":f("voice_ui.move_down"),"data-testid":`voice-provider-${N}-down`,className:"text-muted-fg hover:text-fg disabled:opacity-30",children:r.jsx(Zs,{className:"size-3.5"})})]}),r.jsx(Yc,{ok:w.available?!0:w.configured?!1:null}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm font-medium",children:S.name}),S.local&&r.jsx(Fe,{tone:"info",children:f("voice_ui.badge_local")}),w.available?r.jsx(Fe,{tone:"success",children:f("voice_ui.badge_available")}):w.configured?r.jsx(Fe,{tone:"warning",children:f("voice_ui.badge_unavailable")}):r.jsx(Fe,{tone:"muted",children:f("voice_ui.badge_not_configured")}),C&&r.jsx(Fe,{tone:"success",children:f("voice_ui.badge_default")})]}),r.jsx("div",{className:"truncate text-xs text-muted-fg",children:S.note})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[_?r.jsx(Qt,{checked:E?!0:w.enabled,onChange:R=>u(N,R),disabled:g||E}):!C&&r.jsxs(me,{size:"sm",variant:"ghost",onClick:()=>c(N),disabled:g,"data-testid":`voice-provider-${N}-default`,children:[r.jsx(aM,{className:"size-3.5"})," ",f("voice_ui.set_as_default")]}),C&&r.jsx(Ox,{className:"size-4 text-emerald-400"}),r.jsxs(me,{size:"sm",variant:"secondary",onClick:()=>m(N),"data-testid":`voice-provider-${N}-config`,children:[r.jsx(IM,{className:"size-3.5"})," ",f("voice_ui.configure")]})]})]},N)})})]})}function Oa(e){return typeof e=="string"?e:e==null?"":String(e)}function E7({open:e,providerId:t,config:s,onClose:o,onSave:l}){const[c,u]=x.useState(!1),[p,m]=x.useState(null),[g,h]=x.useState(""),[b,_]=x.useState({});if(x.useEffect(()=>{if(!e||!t)return;m(null),h("");const R=s||{};if(t==="piper"){const A=R;_({bin:Oa(A.bin),model:Oa(A.model),speaker:Oa(A.speaker)})}else if(t==="elevenlabs"){const A=R;_({model:Oa(A.model),voice_id:Oa(A.voice_id),output_format:Oa(A.output_format)})}else if(t==="openai"){const A=R;_({model:Oa(A.model)||"tts-1",voice:Oa(A.voice)||"alloy",format:Oa(A.format)||"mp3"})}else if(t==="gemini"){const A=R;_({model:Oa(A.model),voice:Oa(A.voice)||"Kore",style:Oa(A.style)})}else _({})},[e,t,s]),!t)return null;const k=pf[t],N=`voice.tts.${t}`,y=R=>_(A=>({...A,...R})),w=t!=="piper"&&t!=="mock",S=w&&oa(s?.api_key),C=S?f("voice_ui.api_key_set",{suffix:jo(s?.api_key)??""}):f("voice_ui.api_key_label"),E=async()=>{u(!0),m(null);try{const R={},A=[],T=(O,z)=>{z.trim()?R[`${N}.${O}`]=z.trim():A.push(`${N}.${O}`)};t==="piper"?(T("bin",b.bin),T("model",b.model),b.speaker.trim()?R[`${N}.speaker`]=b.speaker.trim():A.push(`${N}.speaker`)):t==="elevenlabs"?(T("model",b.model),T("voice_id",b.voice_id),T("output_format",b.output_format)):t==="openai"?(T("model",b.model),T("voice",b.voice),T("format",b.format)):t==="gemini"&&(T("model",b.model),T("voice",b.voice),T("style",b.style)),w&&g.trim()&&(R[`${N}.api_key`]=g.trim()),await l({set:R,unset:A}),o()}catch(R){m(R.message||f("voice_ui.err_save"))}finally{u(!1)}};return r.jsx(An,{open:e,onClose:o,title:f("voice_screen.configure_provider",{name:k?.name||t||""}),description:k?.note,size:"md",footer:r.jsxs(r.Fragment,{children:[r.jsx(me,{variant:"ghost",onClick:o,disabled:c,children:f("common.cancel")}),r.jsx(me,{variant:"primary",onClick:E,loading:c,"data-testid":"voice-provider-save",children:f("common.save")})]}),children:r.jsxs("div",{className:"space-y-3",children:[t==="piper"&&r.jsxs(r.Fragment,{children:[r.jsx(fe,{label:f("voice_ui.piper_bin_label"),hint:f("voice_ui.piper_bin_hint"),children:r.jsx(Ae,{value:b.bin,onChange:R=>y({bin:R.target.value}),placeholder:"piper"})}),r.jsx(fe,{label:f("voice_ui.piper_model_label"),hint:f("voice_ui.piper_model_hint"),children:r.jsx(Ae,{value:b.model,onChange:R=>y({model:R.target.value}),placeholder:"/abs/path/voice.onnx"})}),r.jsx(fe,{label:f("voice_ui.piper_speaker_label"),hint:f("voice_ui.piper_speaker_hint"),children:r.jsx(Ae,{value:b.speaker,onChange:R=>y({speaker:R.target.value}),placeholder:"0"})})]}),t==="elevenlabs"&&r.jsxs(r.Fragment,{children:[r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:S?f("voice_ui.api_key_keep_hint"):f("voice_ui.api_key_secret_hint",{env:"ELEVENLABS_API_KEY"}),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(fe,{label:f("voice_ui.model_label"),children:r.jsx(_t,{value:b.model||"",onChange:R=>y({model:R}),options:PD.map(R=>({value:R,label:R})),placeholder:"eleven_multilingual_v2"})}),r.jsx(fe,{label:f("voice_ui.voice_id_label"),hint:f("voice_ui.voice_id_hint"),children:r.jsx(Ae,{value:b.voice_id,onChange:R=>y({voice_id:R.target.value}),placeholder:"EXAVITQu4vr4xnSDxMaL"})}),r.jsx(fe,{label:f("voice_ui.output_format_label"),children:r.jsx(Ae,{value:b.output_format,onChange:R=>y({output_format:R.target.value}),placeholder:"mp3_44100_128"})})]}),t==="openai"&&r.jsxs(r.Fragment,{children:[r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:S?f("voice_ui.api_key_keep_hint"):f("voice_ui.api_key_reuse_hint",{engine:"engines.openai.api_key",env:"OPENAI_API_KEY"}),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(fe,{label:f("voice_ui.model_label"),children:r.jsx(_t,{value:b.model||"tts-1",onChange:R=>y({model:R}),options:LD.map(R=>({value:R,label:R}))})}),r.jsx(fe,{label:f("voice_ui.voice_label"),children:r.jsx(_t,{value:b.voice||"alloy",onChange:R=>y({voice:R}),options:zD.map(R=>({value:R,label:R}))})}),r.jsx(fe,{label:f("voice_ui.format_label"),children:r.jsx(_t,{value:b.format||"mp3",onChange:R=>y({format:R}),options:["mp3","opus","aac","flac","wav"].map(R=>({value:R,label:R}))})})]}),t==="gemini"&&r.jsxs(r.Fragment,{children:[r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:S?f("voice_ui.api_key_keep_hint"):f("voice_ui.api_key_reuse_hint",{engine:"engines.gemini.api_key",env:"GEMINI_API_KEY"}),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(fe,{label:f("voice_ui.model_label"),hint:f("voice_ui.gemini_model_hint"),children:r.jsx(Ae,{value:b.model,onChange:R=>y({model:R.target.value}),placeholder:"gemini-2.5-flash-preview-tts"})}),r.jsx(fe,{label:f("voice_ui.voice_label"),children:r.jsx(_t,{value:b.voice||"Kore",onChange:R=>y({voice:R}),options:DD.map(R=>({value:R,label:R}))})}),r.jsx(fe,{label:f("voice_ui.style_label"),hint:f("voice_ui.style_hint"),children:r.jsx(Un,{rows:2,value:b.style||"",onChange:R=>y({style:R.target.value}),placeholder:f("voice_ui.style_ph")})})]}),t==="mock"&&r.jsx("p",{className:"text-sm text-muted-fg",children:f("voice_ui.mock_desc")}),p&&r.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:p})]})})}function R7(){const e=x.useRef(null),t=x.useRef(null),[s,o]=x.useState(!1),[l,c]=x.useState(!1),u=x.useCallback(()=>{t.current&&(URL.revokeObjectURL(t.current),t.current=null)},[]);x.useEffect(()=>()=>{e.current&&(e.current.pause(),e.current=null),u()},[u]);const p=x.useCallback(async g=>{c(!0);try{u();const h=await BD(g);t.current=h,e.current||(e.current=new Audio);const b=e.current;b.src=h,b.onended=()=>o(!1),b.onerror=()=>o(!1),await b.play(),o(!0)}finally{c(!1)}},[u]),m=x.useCallback(()=>{e.current&&(e.current.pause(),e.current.currentTime=0),o(!1)},[]);return{play:p,stop:m,playing:s,loading:l}}function T7({engines:e,defaultProvider:t,mode:s}){const o=lt(),{play:l,stop:c,playing:u,loading:p}=R7(),[m,g]=x.useState(f("voice_ui.test_default_text")),[h,b]=x.useState(""),[_,k]=x.useState(""),[N,y]=x.useState(!1),[w,S]=x.useState(null),E=[{value:"",label:s==="single"&&t&&t!=="auto"?f("voice_ui.test_default_engine",{name:pf[t]?.name||t}):f("voice_ui.test_default_chain")},...e.map(A=>({value:A.id,label:`${pf[A.id]?.name||A.id}${A.available?"":f("voice_ui.test_unavailable_suffix")}`}))],R=async()=>{const A=m.trim();if(!A){o.error(f("voice_ui.test_empty_error"));return}y(!0);try{const T=await pC.say({text:A,provider:h||void 0,style:_.trim()||void 0});S(T),await l(T.audio_path)}catch(T){o.error(T.message||f("voice_ui.test_synth_error"))}finally{y(!1)}};return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("voice_ui.test_engine_label"),hint:f("voice_ui.test_engine_hint"),children:r.jsx(_t,{value:h,onChange:b,options:E})}),r.jsx(fe,{label:f("voice_ui.test_style_label"),hint:f("voice_ui.test_style_hint"),children:r.jsx(Ae,{value:_,onChange:A=>k(A.target.value),placeholder:f("voice_ui.style_ph"),"data-testid":"voice-test-style"})})]}),r.jsx(fe,{label:f("voice_ui.test_text_label"),children:r.jsx(Un,{rows:2,value:m,onChange:A=>g(A.target.value),placeholder:f("voice_ui.test_text_ph"),"data-testid":"voice-test-input"})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(me,{variant:"primary",onClick:R,loading:N,disabled:p,"data-testid":"voice-test-say",children:[r.jsx($M,{className:"size-4"})," ",f("voice_ui.say_this")]}),u?r.jsxs(me,{variant:"secondary",onClick:c,"data-testid":"voice-test-stop",children:[r.jsx(Fk,{className:"size-4"})," ",f("voice_ui.stop")]}):w?r.jsxs(me,{variant:"secondary",onClick:()=>l(w.audio_path),loading:p,"data-testid":"voice-test-replay",children:[r.jsx(Bx,{className:"size-4"})," ",f("voice_ui.replay")]}):null,w&&r.jsxs("span",{className:"text-xs text-muted-fg",children:[f("voice_ui.engine_result"),": ",r.jsx("strong",{children:w.provider}),w.duration_s?` · ${w.duration_s.toFixed(1)}s`:""]})]})]})}const A7=()=>[{value:"auto",label:f("voice_ui.stt_provider_auto")},{value:"local",label:f("voice_ui.stt_provider_local")},{value:"openai",label:f("voice_ui.stt_provider_openai")},{value:"custom",label:f("voice_ui.stt_provider_custom")}],Hw=()=>[{value:"auto",label:f("voice_ui.lang_auto")},{value:"es",label:f("voice_ui.lang_es")},{value:"en",label:f("voice_ui.lang_en")},{value:"pt",label:f("voice_ui.lang_pt")},{value:"fr",label:f("voice_ui.lang_fr")},{value:"it",label:f("voice_ui.lang_it")},{value:"de",label:f("voice_ui.lang_de")}];function M7({config:e,onPatch:t,busy:s}){const o=e.provider||"auto",l=e.local||{},c=e.openai||{},u=e.custom||{},p=l.model||"small",m=l.language||"auto",g=o==="auto"||o==="local",h=(k,N,y)=>{const w=y.trim();w!==(N||"").trim()&&t({[k]:w})},b=(k,N)=>{const y=N.trim();!y||oa(y)||t({[k]:y})},_=k=>oa(k)?f("voice_ui.api_key_set",{suffix:jo(k)??""}):f("voice_ui.api_key_label");return r.jsxs("div",{className:"space-y-3",children:[r.jsx(fe,{label:f("voice_ui.stt_engine_label"),hint:f("voice_ui.stt_engine_hint"),children:r.jsx(_t,{value:o,onChange:k=>t({"transcription.provider":k}),options:A7(),disabled:s,className:"max-w-md"})}),g&&r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("voice_ui.stt_model_label"),hint:f("voice_ui.stt_model_hint"),children:r.jsx(_t,{value:p,onChange:k=>t({"transcription.local.model":k}),options:ID.map(k=>({value:k,label:k})),disabled:s})}),r.jsx(fe,{label:f("voice_ui.stt_language_label"),hint:f("voice_ui.stt_language_hint"),children:r.jsx(_t,{value:m,onChange:k=>t({"transcription.local.language":k}),options:Hw(),disabled:s})})]}),o==="openai"&&r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:oa(c.api_key)?f("voice_ui.api_key_keep_hint"):f("voice_ui.api_key_reuse_hint",{engine:"engines.openai.api_key",env:"OPENAI_API_KEY"}),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",defaultValue:"",placeholder:_(c.api_key),onBlur:k=>b("transcription.openai.api_key",k.target.value),disabled:s})}),r.jsx(fe,{label:f("voice_ui.stt_openai_model_label"),hint:f("voice_ui.stt_openai_model_hint"),children:r.jsx(Ae,{defaultValue:c.model||"",placeholder:"whisper-1",onBlur:k=>h("transcription.openai.model",c.model,k.target.value),disabled:s})})]}),o==="custom"&&r.jsxs("div",{className:"space-y-3",children:[r.jsx(fe,{label:f("voice_ui.stt_custom_baseurl_label"),hint:f("voice_ui.stt_custom_baseurl_hint"),children:r.jsx(Ae,{defaultValue:u.base_url||"",placeholder:"http://localhost:8000/v1",onBlur:k=>h("transcription.custom.base_url",u.base_url,k.target.value),disabled:s})}),r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("voice_ui.stt_custom_model_label"),hint:f("voice_ui.stt_custom_model_hint"),children:r.jsx(Ae,{defaultValue:u.model||"",placeholder:"mlx-community/whisper-large-v3-turbo",onBlur:k=>h("transcription.custom.model",u.model,k.target.value),disabled:s})}),r.jsx(fe,{label:f("voice_ui.stt_language_label"),hint:f("voice_ui.stt_language_hint"),children:r.jsx(_t,{value:u.language||"auto",onChange:k=>t({"transcription.custom.language":k}),options:Hw(),disabled:s})})]}),r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:f("voice_ui.stt_custom_key_hint"),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",defaultValue:"",placeholder:_(u.api_key),onBlur:k=>b("transcription.custom.api_key",k.target.value),disabled:s})})]})]})}function O7(){const e=lt(),{config:t,isLoading:s,patch:o,mutate:l}=Vr(),{data:c,isLoading:u,error:p,mutate:m}=Qe("/tts/providers",()=>pC.providers()),[g,h]=x.useState(null),[b,_]=x.useState(!1),k=t,N=k.voice?.tts||{},y=k.transcription||{},w=c?.configured_provider||N.provider||"auto",S=c?.mode||N.mode||"chain",C=c?.engines||[],E=c?.order||[],R=x.useMemo(()=>g?N[g]||{}:{},[g,N]),A=async U=>{_(!0);try{await o({"voice.tts.provider":U,"voice.tts.mode":"single"}),await m(),e.success(f("voice_ui.toast_default_engine",{id:U}))}catch(I){e.error(I.message)}finally{_(!1)}},T=async U=>{_(!0);try{const I={"voice.tts.mode":U};if(U==="single"&&(w==="auto"||!w)){const V=C.find(H=>H.available)?.id||E[0]||"mock";I["voice.tts.provider"]=V}await o(I),await m(),e.success(f(U==="chain"?"voice_ui.toast_mode_chain":"voice_ui.toast_mode_single"))}catch(I){e.error(I.message)}finally{_(!1)}},O=async(U,I)=>{_(!0);try{await o({[`voice.tts.${U}.enabled`]:I}),await m()}catch(V){e.error(V.message)}finally{_(!1)}},z=async U=>{_(!0);try{await o({"voice.tts.order":U}),await m()}catch(I){e.error(I.message)}finally{_(!1)}},L=async({set:U,unset:I})=>{await o(U,I.length?I:void 0),await m(),await l(),e.success(f("voice_ui.toast_config_saved"))},D=async(U,I)=>{try{await o(U,I),e.success(f("voice_ui.toast_transcription_updated"))}catch(V){e.error(V.message)}};return r.jsxs("div",{"data-testid":"screen-voice",children:[r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[r.jsx(Ye,{title:f("voice_screen.providers_title"),description:f("voice_ui.providers_desc"),children:u||s?r.jsx(ot,{}):p?r.jsx(xt,{children:f("voice_ui.providers_load_error",{msg:p.message})}):r.jsx(N7,{engines:C,order:E,mode:S,configuredProvider:w,onSetMode:T,onSetDefault:A,onToggleEnabled:O,onReorder:z,onConfigure:U=>h(U),busy:b})}),r.jsxs("div",{className:"space-y-6",children:[r.jsx(Ye,{title:f("voice_screen.test_title"),description:f("voice_ui.test_desc"),children:r.jsx(T7,{engines:C,defaultProvider:w,mode:S})}),r.jsx(Ye,{title:f("voice_screen.stt_title"),description:f("voice_ui.stt_desc"),children:s?r.jsx(ot,{}):r.jsx(M7,{config:y,onPatch:D})})]})]}),r.jsx(E7,{open:!!g,providerId:g,config:R,onClose:()=>h(null),onSave:L})]})}function z7(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function D7({manifest:e}){const t=e.daemon,s=e.safety;return r.jsxs("div",{"data-testid":"deck-daemon-card",className:"rounded-xl border border-border bg-muted/10 px-4 py-3 text-xs",children:[r.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-2",children:[r.jsxs("span",{className:"font-semibold text-foreground",children:[t.name," ",r.jsxs("span",{className:"font-normal text-muted-fg",children:["v",t.version]})]}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"size-2 rounded-full bg-emerald-500"}),r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.deck_daemon_active",{uptime:z7(t.uptime_s)})})]})]}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsxs("span",{className:"text-muted-fg",children:[t.host,":",t.port]}),r.jsx("span",{className:"text-muted-fg",children:"·"}),r.jsxs("span",{className:"text-muted-fg",children:[f("modules_ui.deck_daemon_started")," ",new Date(t.started_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]}),r.jsxs("div",{className:"mt-2.5 flex flex-wrap gap-1.5",children:[s.direct_shell===!1&&r.jsx(Fe,{tone:"success",children:f("modules_ui.deck_safety_no_shell")}),s.arbitrary_commands===!1&&r.jsx(Fe,{tone:"success",children:f("modules_ui.deck_safety_no_arbitrary")}),s.dangerous_actions_require_confirmation&&r.jsx(Fe,{tone:"info",children:f("modules_ui.deck_safety_confirm")})]})]})}function P7(e){return e==="available"?"success":e==="configured"?"info":"muted"}function L7(e){return e==="available"?"activo":e==="configured"?"configurado":e==="disabled"?"deshabilitado":"sin configurar"}function I7(e){return e==="voice"?"warning":e==="plugin"?"info":"muted"}function B7({widget:e,onToggle:t}){const s=e.source==="external",[o,l]=x.useState(!1),c=e.user_enabled===!0,u=async p=>{if(!(!t||o)){l(!0);try{await t(p)}finally{l(!1)}}};return r.jsxs("li",{"data-testid":`deck-widget-${e.id}`,className:ze("flex items-center gap-3 rounded-lg border px-3 py-2.5 text-sm transition-colors",s?"border-border bg-muted/20 hover:border-muted-fg/30":"border-border/50 bg-muted/10"),children:[r.jsx(et,{content:e.source==="apx"?f("deck_screen.widget_native"):f("deck_screen.widget_external"),children:r.jsx("span",{className:ze("size-2 shrink-0 rounded-full",e.source==="apx"?"bg-emerald-500":"bg-sky-400")})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"font-medium",children:e.title}),r.jsx("span",{className:"ml-2 text-xs text-muted-fg",children:e.desktop})]}),r.jsx(Fe,{tone:I7(e.kind),children:e.kind}),r.jsx(Fe,{tone:P7(e.status),children:L7(e.status)}),s?r.jsx("span",{"data-testid":`deck-widget-toggle-${e.id}`,children:r.jsx(Qt,{checked:c,onChange:u,disabled:o||!t})}):r.jsx("span",{className:"w-9 shrink-0","aria-hidden":!0})]})}function U7({desktop:e,widgets:t,onToggle:s}){return t.length===0?null:r.jsxs("div",{"data-testid":`deck-desktop-${e.id}`,className:"space-y-1.5",children:[r.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-fg",children:e.title}),r.jsx("ul",{className:"space-y-1.5",children:t.map(o=>r.jsx(B7,{widget:o,onToggle:o.source==="external"?l=>s(o.id,l):void 0},o.id))})]})}function H7(){lt();const{data:e,error:t,isLoading:s,mutate:o}=Qe("/deck/manifest",()=>UD.manifest(),{refreshInterval:3e4}),l=async(h,b)=>{},c=e?.deck.desktops??[],u=e?.deck.widgets??[],p=c.map(h=>({desktop:h,widgets:u.filter(b=>b.desktop===h.id)})),g=u.filter(h=>h.source==="external").filter(h=>h.user_enabled===!0).length;return r.jsxs("div",{className:"relative min-h-full","data-testid":"screen-deck",children:[r.jsxs("div",{className:"mx-auto max-w-4xl space-y-6 p-6 pointer-events-none select-none blur-[2px] opacity-60","aria-hidden":!0,inert:!0,children:[e&&r.jsx(D7,{manifest:e}),r.jsxs(Ye,{title:f("deck_screen.widgets_title"),description:s?f("modules_ui.deck_loading_manifest"):t?f("modules_ui.deck_manifest_error"):f("modules_ui.deck_widgets_summary",{count:u.length,enabled:g}),action:r.jsx(et,{content:f("deck_screen.reload_manifest"),children:r.jsx(me,{size:"sm",variant:"ghost",onClick:()=>o(),disabled:s,"aria-label":f("deck_screen.reload_manifest"),children:r.jsx(cs,{size:14,className:s?"animate-spin":""})})}),children:[s&&r.jsx(ot,{label:f("modules_ui.deck_loading_manifest_full")}),!s&&t&&r.jsxs(xt,{children:[f("modules_ui.deck_manifest_load_failed")," ",r.jsx("button",{type:"button",className:"ml-1 underline",onClick:()=>o(),children:f("modules_ui.deck_retry")})]}),!s&&!t&&u.length===0&&r.jsx(xt,{children:f("modules_ui.deck_no_widgets")}),!s&&!t&&u.length>0&&r.jsx("div",{className:"space-y-5","data-testid":"deck-desktop-list",children:p.filter(h=>h.widgets.length>0).map(h=>r.jsx(U7,{desktop:h.desktop,widgets:h.widgets,onToggle:l},h.desktop.id))})]}),e?.apx&&r.jsx(Ye,{title:f("deck_screen.context_title"),description:f("modules_ui.deck_context_desc"),children:r.jsxs("div",{className:"space-y-2 text-sm","data-testid":"deck-apx-context",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.deck_active_project")}),r.jsx("span",{className:"font-medium",children:e.apx.active_project?e.apx.active_project.name:f("modules_ui.deck_none")})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.deck_registered_projects")}),r.jsx("span",{className:"font-medium",children:e.apx.projects.length})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.deck_active_plugins")}),r.jsx("span",{className:"font-medium",children:Object.keys(e.apx.plugins).join(", ")||"—"})]})]})})]}),r.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center p-6 backdrop-blur-[1px]",role:"dialog","aria-modal":"true","aria-labelledby":"deck-coming-soon-title","data-testid":"deck-coming-soon",children:r.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-border bg-card/95 p-8 text-center shadow-2xl",children:[r.jsx("div",{className:"mx-auto mb-4 flex size-12 items-center justify-center rounded-full bg-muted",children:r.jsx(lM,{className:"size-6 text-muted-fg"})}),r.jsx("span",{className:"inline-block rounded-full bg-muted px-2.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-muted-fg",children:f("deck_screen.preview_badge")}),r.jsx("h2",{id:"deck-coming-soon-title",className:"mt-3 text-lg font-semibold",children:f("deck_screen.preview_title")}),r.jsx("p",{className:"mt-2 text-sm text-muted-fg",children:f("deck_screen.preview_body")})]})})]})}const V7=[{title:f("settings.account_section"),items:[{key:"identity",label:f("settings.tabs.identity"),icon:Hx},{key:"appearance",label:f("settings.appearance"),icon:zM}]},{title:f("settings.agents_section"),items:[{key:"super_agent",label:f("settings.tabs.super_agent"),icon:hn},{key:"engines",label:f("settings.tabs.engines"),icon:zx},{key:"memory",label:"Memory (RAG)",icon:Lk},{key:"skills",label:"Skills (RAG)",icon:fs}]},{title:f("settings.channels_section"),items:[{key:"telegram",label:f("settings.tabs.telegram"),icon:Fa},{key:"devices",label:f("settings.tabs.devices"),icon:BM}]},{title:f("settings.modules_section"),items:[{key:"voice",label:f("nav.modules.voice"),icon:Vk},{key:"deck",label:f("nav.modules.deck"),icon:RM},{key:"desktop",label:f("nav.modules.desktop"),icon:Ix}]},{title:f("settings.advanced_section"),items:[{key:"advanced",label:f("settings.tabs.advanced"),icon:Xd}]}],q7=new Set(["engines","telegram","memory","skills","appearance","voice"]),$7={identity:()=>r.jsx(C8,{}),super_agent:()=>r.jsx(N8,{}),engines:()=>r.jsx(JC,{}),memory:()=>r.jsx(T8,{}),skills:()=>r.jsx(M8,{}),telegram:()=>r.jsx(L8,{}),devices:()=>r.jsx(d7,{}),voice:()=>r.jsx(O7,{}),deck:()=>r.jsx(H7,{}),desktop:()=>r.jsx(C7,{}),appearance:()=>r.jsx(g7,{}),advanced:()=>r.jsx(m7,{})};function F7(){const e=Qn(),t=Kn(),s=G7(t.pathname),o=$7[s],{collapsed:l,toggle:c}=Ib(Rn.sidebarCollapsed+".settings");return r.jsx(LC,{sections:V7,active:s,onChange:u=>e(u==="identity"?"/settings":`/settings/${Y7(u)}`),collapsed:l,onToggleCollapse:c,contentClassName:`w-full ${q7.has(s)?"":"mx-auto max-w-3xl"} space-y-6 p-6 pt-3`,testId:`settings-tab-${s}`,children:r.jsx(o,{})})}function G7(e){switch(e.split("/").filter(Boolean)[1]||"identity"){case"super-agent":return"super_agent";case"engines":return"engines";case"memory":return"memory";case"skills":return"skills";case"telegram":return"telegram";case"devices":return"devices";case"voice":return"voice";case"deck":return"deck";case"desktop":return"desktop";case"appearance":return"appearance";case"config":case"advanced":return"advanced";default:return"identity"}}function Y7(e){return e==="super_agent"?"super-agent":e==="advanced"?"config":e}function X7(){const{data:e,isLoading:t,mutate:s}=Qe("/messages/global?channel=desktop",()=>j7(40),{refreshInterval:8e3});return r.jsx("div",{className:"mx-auto max-w-6xl space-y-6 p-6","data-testid":"screen-desktop",children:r.jsxs("div",{className:"grid gap-6 xl:grid-cols-[1fr_1fr]",children:[r.jsx("div",{children:r.jsx(RN,{showConfigLink:!0})}),r.jsx("div",{children:r.jsx(Ye,{title:f("desktop_screen.last_conv_title"),description:f("modules_ui.desktop_last_conv_desc"),action:r.jsx("button",{type:"button",onClick:()=>s(),className:"text-xs text-muted-fg underline-offset-2 hover:underline",children:f("modules_ui.desktop_refresh")}),children:r.jsx(K7,{messages:e||[],loading:t})})})]})})}function K7({messages:e,loading:t}){const s=x.useMemo(()=>Z7(e),[e]);return t?r.jsx(ot,{}):e.length?r.jsx("div",{className:"space-y-3 max-h-[560px] overflow-y-auto pr-1",children:s.slice().reverse().map((o,l)=>r.jsx("div",{className:"rounded-lg border border-border bg-card/40 p-3",children:o.map((c,u)=>r.jsx(Q7,{m:c},u))},l))}):r.jsx(xt,{children:f("modules_ui.desktop_no_messages")})}function Q7({m:e}){const t=e.direction==="in",s=W7(e.ts);return r.jsxs("div",{className:"py-1",children:[r.jsxs("div",{className:"flex items-baseline gap-2 text-[11px] text-muted-fg",children:[r.jsx("span",{className:"font-semibold",children:f(t?"modules_ui.desktop_you":"modules_ui.desktop_roby")}),r.jsx("span",{children:s})]}),r.jsx("div",{className:"mt-0.5 text-sm leading-snug whitespace-pre-wrap "+(t?"text-muted-fg":"text-fg"),children:(e.body||"").trim()||r.jsx("span",{className:"italic opacity-50",children:f("modules_ui.desktop_empty_msg")})})]})}function Z7(e){const t=[];for(const s of e)s.direction==="in"||!t.length?t.push([s]):t[t.length-1].push(s);return t}function W7(e){try{const t=new Date(e);return t.toDateString()===new Date().toDateString()?t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):t.toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return""}}function J7(e,t){const s=getComputedStyle(e),o=parseFloat(s.fontSize);return t*o}function eB(e,t){const s=getComputedStyle(e.ownerDocument.documentElement),o=parseFloat(s.fontSize);return t*o}function tB(e){return e/100*window.innerHeight}function nB(e){return e/100*window.innerWidth}function aB(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function xc({groupSize:e,panelElement:t,styleProp:s}){let o;const[l,c]=aB(s);switch(c){case"%":{o=l/100*e;break}case"px":{o=l;break}case"rem":{o=eB(t,l);break}case"em":{o=J7(t,l);break}case"vh":{o=tB(l);break}case"vw":{o=nB(l);break}}return o}function Yn(e){return parseFloat(e.toFixed(3))}function Gl({group:e}){const{orientation:t,panels:s}=e;return s.reduce((o,l)=>(o+=t==="horizontal"?l.element.offsetWidth:l.element.offsetHeight,o),0)}function yx(e){const{panels:t}=e,s=Gl({group:e});return s===0?t.map(o=>({groupResizeBehavior:o.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:o.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:o.panelConstraints.disabled,minSize:0,maxSize:100,panelId:o.id})):t.map(o=>{const{element:l,panelConstraints:c}=o;let u=0;if(c.collapsedSize!==void 0){const h=xc({groupSize:s,panelElement:l,styleProp:c.collapsedSize});u=Yn(h/s*100)}let p;if(c.defaultSize!==void 0){const h=xc({groupSize:s,panelElement:l,styleProp:c.defaultSize});p=Yn(h/s*100)}let m=0;if(c.minSize!==void 0){const h=xc({groupSize:s,panelElement:l,styleProp:c.minSize});m=Yn(h/s*100)}let g=100;if(c.maxSize!==void 0){const h=xc({groupSize:s,panelElement:l,styleProp:c.maxSize});g=Yn(h/s*100)}return{groupResizeBehavior:c.groupResizeBehavior,collapsedSize:u,collapsible:c.collapsible===!0,defaultSize:p,disabled:c.disabled,minSize:m,maxSize:g,panelId:o.id}})}function Bt(e,t="Assertion error"){if(!e)throw Error(t)}function jx(e,t){return Array.from(t).sort(e==="horizontal"?sB:rB)}function sB(e,t){const s=e.element.offsetLeft-t.element.offsetLeft;return s!==0?s:e.element.offsetWidth-t.element.offsetWidth}function rB(e,t){const s=e.element.offsetTop-t.element.offsetTop;return s!==0?s:e.element.offsetHeight-t.element.offsetHeight}function TN(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function AN(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function oB({orientation:e,rects:t,targetRect:s}){const o={x:s.x+s.width/2,y:s.y+s.height/2};let l,c=Number.MAX_VALUE;for(const u of t){const{x:p,y:m}=AN(o,u),g=e==="horizontal"?p:m;g<c&&(c=g,l=u)}return Bt(l,"No rect found"),l}let Ad;function lB(){return Ad===void 0&&(typeof matchMedia=="function"?Ad=!!matchMedia("(pointer:coarse)").matches:Ad=!1),Ad}function MN(e){const{element:t,orientation:s,panels:o,separators:l}=e,c=jx(s,Array.from(t.children).filter(TN).map(N=>({element:N}))).map(({element:N})=>N),u=[];let p=!1,m=!1,g=-1,h=-1,b=0,_,k=[];{let N=-1;for(const y of c)y.hasAttribute("data-panel")&&(N++,y.hasAttribute("data-disabled")||(b++,g===-1&&(g=N),h=N))}if(b>1){let N=-1;for(const y of c)if(y.hasAttribute("data-panel")){N++;const w=o.find(S=>S.element===y);if(w){if(_){const S=_.element.getBoundingClientRect(),C=y.getBoundingClientRect();let E;if(m){const R=s==="horizontal"?new DOMRect(S.right,S.top,0,S.height):new DOMRect(S.left,S.bottom,S.width,0),A=s==="horizontal"?new DOMRect(C.left,C.top,0,C.height):new DOMRect(C.left,C.top,C.width,0);switch(k.length){case 0:{E=[R,A];break}case 1:{const T=k[0],O=oB({orientation:s,rects:[S,C],targetRect:T.element.getBoundingClientRect()});E=[T,O===S?A:R];break}default:{E=k;break}}}else k.length?E=k:E=[s==="horizontal"?new DOMRect(S.right,C.top,C.left-S.right,C.height):new DOMRect(C.left,S.bottom,C.width,C.top-S.bottom)];for(const R of E){let A="width"in R?R:R.element.getBoundingClientRect();const T=lB()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(A.width<T){const z=T-A.width;A=new DOMRect(A.x-z/2,A.y,A.width+z,A.height)}if(A.height<T){const z=T-A.height;A=new DOMRect(A.x,A.y-z/2,A.width,A.height+z)}const O=N<=g||N>h;!p&&!O&&u.push({group:e,groupSize:Gl({group:e}),panels:[_,w],separator:"width"in R?void 0:R,rect:A}),p=!1}}m=!1,_=w,k=[]}}else if(y.hasAttribute("data-separator")){y.ariaDisabled!==null&&(p=!0);const w=l.find(S=>S.element===y);w?k.push(w):(_=void 0,k=[])}else m=!0}return u}class ON{#e={};addListener(t,s){const o=this.#e[t];return o===void 0?this.#e[t]=[s]:o.includes(s)||o.push(s),()=>{this.removeListener(t,s)}}emit(t,s){const o=this.#e[t];if(o!==void 0)if(o.length===1)o[0].call(null,s);else{let l=!1,c=null;const u=Array.from(o);for(let p=0;p<u.length;p++){const m=u[p];try{m.call(null,s)}catch(g){c===null&&(l=!0,c=g)}}if(l)throw c}}removeAllListeners(){this.#e={}}removeListener(t,s){const o=this.#e[t];if(o!==void 0){const l=o.indexOf(s);l>=0&&o.splice(l,1)}}}let ss=new Map;const zN=new ON;function iB(e){ss=new Map(ss),ss.delete(e)}function Vw(e,t){for(const[s]of ss)if(s.id===e)return s}function Ar(e,t){for(const[s,o]of ss)if(s.id===e)return o;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Oo(){return ss}function gv(e,t){return zN.addListener("groupChange",s=>{s.group.id===e&&t(s)})}function Qs(e,t,s){const o=ss.get(e);ss=new Map(ss),ss.set(e,t),zN.emit("groupChange",{group:e,isUserInteraction:s?.isUserInteraction===!0,prev:o,next:t})}function cB(e,t,s){let o,l={x:1/0,y:1/0};for(const c of t){const u=AN(s,c.rect);switch(e){case"horizontal":{u.x<=l.x&&(o=c,l=u);break}case"vertical":{u.y<=l.y&&(o=c,l=u);break}}}return o?{distance:l,hitRegion:o}:void 0}function uB(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function dB(e,t){if(e===t)throw new Error("Cannot compare node with itself");const s={a:Fw(e),b:Fw(t)};let o;for(;s.a.at(-1)===s.b.at(-1);)o=s.a.pop(),s.b.pop();Bt(o,"Stacking order can only be calculated for elements with a common ancestor");const l={a:$w(qw(s.a)),b:$w(qw(s.b))};if(l.a===l.b){const c=o.childNodes,u={a:s.a.at(-1),b:s.b.at(-1)};let p=c.length;for(;p--;){const m=c[p];if(m===u.a)return 1;if(m===u.b)return-1}}return Math.sign(l.a-l.b)}const fB=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function pB(e){const t=getComputedStyle(DN(e)??e).display;return t==="flex"||t==="inline-flex"}function mB(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||pB(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||fB.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function qw(e){let t=e.length;for(;t--;){const s=e[t];if(Bt(s,"Missing node"),mB(s))return s}return null}function $w(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Fw(e){const t=[];for(;e;)t.push(e),e=DN(e);return t}function DN(e){const{parentNode:t}=e;return uB(t)?t.host:t}function gB(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function hB({groupElement:e,hitRegion:t,pointerEventTarget:s}){if(!TN(s)||s.contains(e)||e.contains(s))return!0;if(dB(s,e)>0){let o=s;for(;o;){if(o.contains(e))return!0;if(gB(o.getBoundingClientRect(),t))return!1;o=o.parentElement}}return!0}function hv(e,t){const s=[];return t.forEach((o,l)=>{if(l.disabled)return;const c=MN(l),u=cB(l.orientation,c,{x:e.clientX,y:e.clientY});u&&u.distance.x<=0&&u.distance.y<=0&&hB({groupElement:l.element,hitRegion:u.hitRegion.rect,pointerEventTarget:e.target})&&s.push(u.hitRegion)}),s}function xB(e,t){if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(e[s]!=t[s])return!1;return!0}function qn(e,t,s=0){return Math.abs(Yn(e)-Yn(t))<=s}function es(e,t){return qn(e,t)?0:e>t?1:-1}function kl({overrideDisabledPanels:e,panelConstraints:t,prevSize:s,size:o}){const{collapsedSize:l=0,collapsible:c,disabled:u,maxSize:p=100,minSize:m=0}=t;if(u&&!e)return s;if(es(o,m)<0)if(c){const g=(l+m)/2;es(o,g)<0?o=l:o=m}else o=m;return o=Math.min(p,o),o=Yn(o),o}function Dc({delta:e,initialLayout:t,panelConstraints:s,pivotIndices:o,prevLayout:l,trigger:c}){if(qn(e,0))return t;const u=c==="imperative-api",p=Object.values(t),m=Object.values(l),g=[...p],[h,b]=o;Bt(h!=null,"Invalid first pivot index"),Bt(b!=null,"Invalid second pivot index");let _=0;switch(c){case"keyboard":{{const y=e<0?b:h,w=s[y];Bt(w,`Panel constraints not found for index ${y}`);const{collapsedSize:S=0,collapsible:C,minSize:E=0}=w;if(C){const R=p[y];if(Bt(R!=null,`Previous layout not found for panel index ${y}`),qn(R,S)){const A=E-R;es(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}{const y=e<0?h:b,w=s[y];Bt(w,`No panel constraints found for index ${y}`);const{collapsedSize:S=0,collapsible:C,minSize:E=0}=w;if(C){const R=p[y];if(Bt(R!=null,`Previous layout not found for panel index ${y}`),qn(R,E)){const A=R-S;es(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}break}default:{const y=e<0?b:h,w=s[y];Bt(w,`Panel constraints not found for index ${y}`);const S=p[y],{collapsible:C,collapsedSize:E,minSize:R}=w;if(C&&es(S,R)<0)if(e>0){const A=R-E,T=A/2,O=S+e;es(O,R)<0&&(e=es(e,T)<=0?0:A)}else{const A=R-E,T=100-A/2,O=S-e;es(O,R)<0&&(e=es(100+e,T)>0?0:-A)}break}}{const y=e<0?1:-1;let w=e<0?b:h,S=0;for(;;){const E=p[w];Bt(E!=null,`Previous layout not found for panel index ${w}`);const R=kl({overrideDisabledPanels:u,panelConstraints:s[w],prevSize:E,size:100})-E;if(S+=R,w+=y,w<0||w>=s.length)break}const C=Math.min(Math.abs(e),Math.abs(S));e=e<0?0-C:C}{let y=e<0?h:b;for(;y>=0&&y<s.length;){const w=Math.abs(e)-Math.abs(_),S=p[y];Bt(S!=null,`Previous layout not found for panel index ${y}`);const C=S-w,E=kl({overrideDisabledPanels:u,panelConstraints:s[y],prevSize:S,size:C});if(!qn(S,E)&&(_+=S-E,g[y]=E,_.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?y--:y++}}if(xB(m,g))return l;{const y=e<0?b:h,w=p[y];Bt(w!=null,`Previous layout not found for panel index ${y}`);const S=w+_,C=kl({overrideDisabledPanels:u,panelConstraints:s[y],prevSize:w,size:S});if(g[y]=C,!qn(C,S)){let E=S-C,R=e<0?b:h;for(;R>=0&&R<s.length;){const A=g[R];Bt(A!=null,`Previous layout not found for panel index ${R}`);const T=A+E,O=kl({overrideDisabledPanels:u,panelConstraints:s[R],prevSize:A,size:T});if(qn(A,O)||(E-=O-A,g[R]=O),qn(E,0))break;e>0?R--:R++}}}const k=Object.values(g).reduce((y,w)=>w+y,0);if(!qn(k,100,.1))return l;const N=Object.keys(l);return g.reduce((y,w,S)=>(y[N[S]]=w,y),{})}function So(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const s in e)if(t[s]===void 0||es(e[s],t[s])!==0)return!1;return!0}function Co({layout:e,panelConstraints:t}){const s=Object.values(e),o=[...s],l=o.reduce((p,m)=>p+m,0);if(o.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${o.map(p=>`${p}%`).join(", ")}`);if(!qn(l,100)&&o.length>0)for(let p=0;p<t.length;p++){const m=o[p];Bt(m!=null,`No layout data found for index ${p}`);const g=100/l*m;o[p]=g}let c=0;for(let p=0;p<t.length;p++){const m=s[p];Bt(m!=null,`No layout data found for index ${p}`);const g=o[p];Bt(g!=null,`No layout data found for index ${p}`);const h=kl({overrideDisabledPanels:!0,panelConstraints:t[p],prevSize:m,size:g});g!=h&&(c+=g-h,o[p]=h)}if(!qn(c,0))for(let p=0;p<t.length;p++){const m=o[p];Bt(m!=null,`No layout data found for index ${p}`);const g=m+c,h=kl({overrideDisabledPanels:!0,panelConstraints:t[p],prevSize:m,size:g});if(m!==h&&(c-=h-m,o[p]=h,qn(c,0)))break}const u=Object.keys(e);return o.reduce((p,m,g)=>(p[u[g]]=m,p),{})}function PN({groupId:e,panelId:t}){const s=()=>{const m=Oo();for(const[g,{defaultLayoutDeferred:h,derivedPanelConstraints:b,layout:_,groupSize:k,separatorToPanels:N}]of m)if(g.id===e)return{defaultLayoutDeferred:h,derivedPanelConstraints:b,group:g,groupSize:k,layout:_,separatorToPanels:N};throw Error(`Group ${e} not found`)},o=()=>{const m=s().derivedPanelConstraints.find(g=>g.panelId===t);if(m!==void 0)return m;throw Error(`Panel constraints not found for Panel ${t}`)},l=()=>{const m=s().group.panels.find(g=>g.id===t);if(m!==void 0)return m;throw Error(`Layout not found for Panel ${t}`)},c=()=>{const m=s().layout[t];if(m!==void 0)return m;throw Error(`Layout not found for Panel ${t}`)},u=({nextSize:m,panels:g,prevLayout:h,derivedPanelConstraints:b})=>{const _=c(),k=g.findIndex(w=>w.id===t),N=k===0,y=k===g.length-1;if(y&&m<_&&(N||g.slice(0,k).every((w,S)=>{const C=b[S];return C?.collapsible&&qn(C.collapsedSize,h[C.panelId])}))){const w=g.slice(0,k).reduce((S,C)=>S+h[C.id],0);return{...h,[t]:Yn(100-w)}}return Dc({delta:y?_-m:m-_,initialLayout:h,panelConstraints:b,pivotIndices:y?[k-1,k]:[k,k+1],prevLayout:h,trigger:"imperative-api"})},p=m=>{const g=c();if(m===g)return;const{defaultLayoutDeferred:h,derivedPanelConstraints:b,group:_,groupSize:k,layout:N,separatorToPanels:y}=s(),w=u({nextSize:m,panels:_.panels,prevLayout:N,derivedPanelConstraints:b}),S=Co({layout:w,panelConstraints:b});So(N,S)||Qs(_,{defaultLayoutDeferred:h,derivedPanelConstraints:b,groupSize:k,layout:S,separatorToPanels:y})};return{collapse:()=>{const{collapsible:m,collapsedSize:g}=o(),{mutableValues:h}=l(),b=c();m&&b!==g&&(h.expandToSize=b,p(g))},expand:()=>{const{collapsible:m,collapsedSize:g,minSize:h}=o(),{mutableValues:b}=l(),_=c();if(m&&_===g){let k=b.expandToSize??h;k===0&&(k=1),p(k)}},getSize:()=>{const{group:m}=s(),g=c(),{element:h}=l(),b=m.orientation==="horizontal"?h.offsetWidth:h.offsetHeight;return{asPercentage:g,inPixels:b}},isCollapsed:()=>{const{collapsible:m,collapsedSize:g}=o(),h=c();return m&&qn(g,h)},resize:m=>{const{group:g}=s(),{element:h}=l(),b=Gl({group:g}),_=xc({groupSize:b,panelElement:h,styleProp:m}),k=Yn(_/b*100);p(k)}}}function Gw(e){if(e.defaultPrevented)return;const t=Oo();hv(e,t).forEach(s=>{if(s.separator&&!s.separator.disableDoubleClick){const o=s.panels.find(l=>l.panelConstraints.defaultSize!==void 0);if(o){const l=o.panelConstraints.defaultSize,c=PN({groupId:s.group.id,panelId:o.id});c&&l!==void 0&&(c.resize(l),e.preventDefault())}}})}function Hd(e){const t=Oo();for(const[s]of t)if(s.separators.some(o=>o.element===e))return s;throw Error("Could not find parent Group for separator element")}function LN({groupId:e}){const t=()=>{const s=Oo();for(const[o,l]of s)if(o.id===e)return{group:o,...l};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:s,layout:o}=t();return s?{}:o},setLayout(s){const{defaultLayoutDeferred:o,derivedPanelConstraints:l,group:c,groupSize:u,layout:p,separatorToPanels:m}=t(),g=Co({layout:s,panelConstraints:l});return o?p:(So(p,g)||Qs(c,{defaultLayoutDeferred:o,derivedPanelConstraints:l,groupSize:u,layout:g,separatorToPanels:m}),g)}}}function io(e,t){const s=Hd(e),o=Ar(s.id,!0),l=s.separators.find(h=>h.element===e);Bt(l,"Matching separator not found");const c=o.separatorToPanels.get(l);Bt(c,"Matching panels not found");const u=c.map(h=>s.panels.indexOf(h)),p=LN({groupId:s.id}).getLayout(),m=Dc({delta:t,initialLayout:p,panelConstraints:o.derivedPanelConstraints,pivotIndices:u,prevLayout:p,trigger:"keyboard"}),g=Co({layout:m,panelConstraints:o.derivedPanelConstraints});So(p,g)||Qs(s,{defaultLayoutDeferred:o.defaultLayoutDeferred,derivedPanelConstraints:o.derivedPanelConstraints,groupSize:o.groupSize,layout:g,separatorToPanels:o.separatorToPanels},{isUserInteraction:!0})}function Yw(e){if(e.defaultPrevented)return;const t=e.currentTarget,s=Hd(t);if(!s.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),s.orientation==="vertical"&&io(t,5);break}case"ArrowLeft":{e.preventDefault(),s.orientation==="horizontal"&&io(t,-5);break}case"ArrowRight":{e.preventDefault(),s.orientation==="horizontal"&&io(t,5);break}case"ArrowUp":{e.preventDefault(),s.orientation==="vertical"&&io(t,-5);break}case"End":{e.preventDefault(),io(t,100);break}case"Enter":{e.preventDefault();const o=Hd(t),l=Ar(o.id,!0),{derivedPanelConstraints:c,layout:u,separatorToPanels:p}=l,m=o.separators.find(_=>_.element===t);Bt(m,"Matching separator not found");const g=p.get(m);Bt(g,"Matching panels not found");const h=g[0],b=c.find(_=>_.panelId===h.id);if(Bt(b,"Panel metadata not found"),b.collapsible){const _=u[h.id],k=b.collapsedSize===_?o.mutableState.expandedPanelSizes[h.id]??b.minSize:b.collapsedSize;io(t,k-_)}break}case"F6":{e.preventDefault();const o=Hd(t).separators.map(u=>u.element),l=Array.from(o).findIndex(u=>u===e.currentTarget);Bt(l!==null,"Index not found");const c=e.shiftKey?l>0?l-1:o.length-1:l+1<o.length?l+1:0;o[c].focus({preventScroll:!0});break}case"Home":{e.preventDefault(),io(t,-100);break}}}let Ml={cursorFlags:0,state:"inactive"};const xv=new ON;function No(){return Ml}function bB(e){return xv.addListener("change",e)}function vB(e){const t=Ml,s={...Ml};s.cursorFlags=e,Ml=s,xv.emit("change",{prev:t,next:s})}function Ol(e){const t=Ml;Ml=e,xv.emit("change",{prev:t,next:e})}function Xw(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Oo(),s=hv(e,t),o=new Map;let l=!1;s.forEach(c=>{c.separator&&(l||(l=!0,c.separator.element.focus({focusVisible:!1,preventScroll:!0})));const u=t.get(c.group);u&&o.set(c.group,u.layout)}),Ol({cursorFlags:0,hitRegions:s,initialLayoutMap:o,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),s.length&&e.preventDefault()}const _B=e=>e,Th=()=>{},IN=1,BN=2,UN=4,HN=8,Kw=3,Qw=12;let Md;function Zw(){return Md===void 0&&(Md=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Md=!0)),Md}function yB({cursorFlags:e,groups:t,state:s}){let o=0,l=0;switch(s){case"active":case"hover":t.forEach(c=>{if(!c.mutableState.disableCursor)switch(c.orientation){case"horizontal":{o++;break}case"vertical":{l++;break}}})}if(!(o===0&&l===0)){switch(s){case"active":{if(e&&Zw()){const c=(e&IN)!==0,u=(e&BN)!==0,p=(e&UN)!==0,m=(e&HN)!==0;if(c)return p?"se-resize":m?"ne-resize":"e-resize";if(u)return p?"sw-resize":m?"nw-resize":"w-resize";if(p)return"s-resize";if(m)return"n-resize"}break}}return Zw()?o>0&&l>0?"move":o>0?"ew-resize":"ns-resize":o>0&&l>0?"grab":o>0?"col-resize":"row-resize"}}const Ww=new WeakMap;function bv(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:s}=Ww.get(e)??{};s===void 0&&(s=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(s):e.adoptedStyleSheets=[...e.adoptedStyleSheets,s]));const o=No();switch(o.state){case"active":case"hover":{const l=yB({cursorFlags:o.cursorFlags,groups:o.hitRegions.map(u=>u.group),state:o.state}),c=`*, *:hover {cursor: ${l} !important; }`;if(t===c)return;t=c,l?s.cssRules.length===0?s.insertRule(c):s.replaceSync(c):s.cssRules.length===1&&s.deleteRule(0);break}case"inactive":{t=void 0,s.cssRules.length===1&&s.deleteRule(0);break}}Ww.set(e,{prevStyle:t,styleSheet:s})}function VN({document:e,event:t,hitRegions:s,initialLayoutMap:o,mountedGroups:l,pointerDownAtPoint:c,prevCursorFlags:u}){let p=0;s.forEach(g=>{const{group:h,groupSize:b}=g,{orientation:_,panels:k}=h,{disableCursor:N}=h.mutableState;let y=0;c?_==="horizontal"?y=(t.clientX-c.x)/b*100:y=(t.clientY-c.y)/b*100:_==="horizontal"?y=t.clientX<0?-100:100:y=t.clientY<0?-100:100;const w=o.get(h),S=l.get(h);if(!w||!S)return;const{defaultLayoutDeferred:C,derivedPanelConstraints:E,groupSize:R,layout:A,separatorToPanels:T}=S;if(E&&A&&T){const O=Dc({delta:y,initialLayout:w,panelConstraints:E,pivotIndices:g.panels.map(z=>k.indexOf(z)),prevLayout:A,trigger:"mouse-or-touch"});if(So(O,A)){if(y!==0&&!N)switch(_){case"horizontal":{p|=y<0?IN:BN;break}case"vertical":{p|=y<0?UN:HN;break}}}else Qs(g.group,{defaultLayoutDeferred:C,derivedPanelConstraints:E,groupSize:R,layout:O,separatorToPanels:T})}});let m=0;t.movementX===0?m|=u&Kw:m|=p&Kw,t.movementY===0?m|=u&Qw:m|=p&Qw,vB(m),bv(e)}function Jw(e){const t=Oo(),s=No();switch(s.state){case"active":VN({document:e.currentTarget,event:e,hitRegions:s.hitRegions,initialLayoutMap:s.initialLayoutMap,mountedGroups:t,prevCursorFlags:s.cursorFlags})}}function ek(e){if(e.defaultPrevented)return;const t=No(),s=Oo();switch(t.state){case"active":{if(e.buttons===0){Ol({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(o=>{const l=Ar(o.group.id,!0);Qs(o.group,l,{isUserInteraction:!0})});return}for(const o of t.hitRegions)if(o.separator){const{element:l}=o.separator;l.hasPointerCapture?.(e.pointerId)||l.setPointerCapture?.(e.pointerId)}VN({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:s,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const o=hv(e,s);o.length===0?t.state!=="inactive"&&Ol({cursorFlags:0,state:"inactive"}):Ol({cursorFlags:0,hitRegions:o,state:"hover"}),bv(e.currentTarget);break}}}function tk(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(No().state){case"hover":Ol({cursorFlags:0,state:"inactive"})}}function nk(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=No();switch(t.state){case"active":Ol({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(bv(e.currentTarget),t.hitRegions.forEach(s=>{const o=Ar(s.group.id,!0);Qs(s.group,o,{isUserInteraction:!0})}),e.preventDefault())}}function ak(e){let t=0,s=0;const o={};for(const c of e)if(c.defaultSize!==void 0){t++;const u=Yn(c.defaultSize);s+=u,o[c.panelId]=u}else o[c.panelId]=void 0;const l=e.length-t;if(l!==0){const c=Yn((100-s)/l);for(const u of e)u.defaultSize===void 0&&(o[u.panelId]=c)}return o}function jB(e,t,s){if(!s[0])return;const o=e.panels.find(m=>m.element===t);if(!o||!o.onResize)return;const l=Gl({group:e}),c=e.orientation==="horizontal"?o.element.offsetWidth:o.element.offsetHeight,u=o.mutableValues.prevSize,p={asPercentage:Yn(c/l*100),inPixels:c};o.mutableValues.prevSize=p,o.onResize(p,o.id,u)}function wB(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const s in e)if(e[s]!==t[s])return!1;return!0}function kB({group:e,nextGroupSize:t,prevGroupSize:s,prevLayout:o}){if(s<=0||t<=0||s===t)return o;let l=0,c=0,u=!1;const p=new Map,m=[];for(const b of e.panels){const _=o[b.id]??0;switch(b.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{u=!0;const k=_/100*s,N=Yn(k/t*100);p.set(b.id,N),l+=N;break}case"preserve-relative-size":default:{m.push(b.id),c+=_;break}}}if(!u||m.length===0)return o;const g=100-l,h={...o};if(p.forEach((b,_)=>{h[_]=b}),c>0)for(const b of m){const _=o[b]??0;h[b]=Yn(_/c*g)}else{const b=Yn(g/m.length);for(const _ of m)h[_]=b}return h}function SB(e,t){const s=e.map(l=>l.id),o=Object.keys(t);if(s.length!==o.length)return!1;for(const l of s)if(!o.includes(l))return!1;return!0}const yl=new Map;function CB(e){let t=!0;Bt(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const s=e.element.ownerDocument.defaultView.ResizeObserver,o=new Set,l=new Set,c=new s(N=>{for(const y of N){const{borderBoxSize:w,target:S}=y;if(S===e.element){if(t){const C=Gl({group:e});if(C===0)return;const E=Ar(e.id);if(!E)return;const R=yx(e),A=E.defaultLayoutDeferred?ak(R):E.layout,T=kB({group:e,nextGroupSize:C,prevGroupSize:E.groupSize,prevLayout:A}),O=Co({layout:T,panelConstraints:R});if(!E.defaultLayoutDeferred&&So(E.layout,O)&&wB(E.derivedPanelConstraints,R)&&E.groupSize===C)return;Qs(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:R,groupSize:C,layout:O,separatorToPanels:E.separatorToPanels})}}else jB(e,S,w)}});c.observe(e.element),e.panels.forEach(N=>{Bt(!o.has(N.id),`Panel ids must be unique; id "${N.id}" was used more than once`),o.add(N.id),N.onResize&&c.observe(N.element)});const u=Gl({group:e}),p=yx(e),m=e.panels.map(({id:N})=>N).join(",");let g=e.mutableState.defaultLayout;g&&(SB(e.panels,g)||(g=void 0));const h=e.mutableState.layouts[m]??g??ak(p),b=Co({layout:h,panelConstraints:p}),_=e.element.ownerDocument;yl.set(_,(yl.get(_)??0)+1);const k=new Map;return MN(e).forEach(N=>{N.separator&&k.set(N.separator,N.panels)}),Qs(e,{defaultLayoutDeferred:u===0,derivedPanelConstraints:p,groupSize:u,layout:b,separatorToPanels:k}),e.separators.forEach(N=>{Bt(!l.has(N.id),`Separator ids must be unique; id "${N.id}" was used more than once`),l.add(N.id),N.element.addEventListener("keydown",Yw)}),yl.get(_)===1&&(_.addEventListener("dblclick",Gw,!0),_.addEventListener("pointerdown",Xw,!0),_.addEventListener("pointerleave",Jw),_.addEventListener("pointermove",ek),_.addEventListener("pointerout",tk),_.addEventListener("pointerup",nk,!0)),function(){t=!1,yl.set(_,Math.max(0,(yl.get(_)??0)-1)),iB(e),e.separators.forEach(N=>{N.element.removeEventListener("keydown",Yw)}),yl.get(_)||(_.removeEventListener("dblclick",Gw,!0),_.removeEventListener("pointerdown",Xw,!0),_.removeEventListener("pointerleave",Jw),_.removeEventListener("pointermove",ek),_.removeEventListener("pointerout",tk),_.removeEventListener("pointerup",nk,!0)),c.disconnect()}}function NB(){const[e,t]=x.useState({}),s=x.useCallback(()=>t({}),[]);return[e,s]}function vv(e){const t=x.useId();return`${e??t}`}const zo=typeof window<"u"?x.useLayoutEffect:x.useEffect;function kc(e){const t=x.useRef(e);return zo(()=>{t.current=e},[e]),x.useCallback((...s)=>t.current?.(...s),[t])}function _v(...e){return kc(t=>{e.forEach(s=>{if(s)switch(typeof s){case"function":{s(t);break}case"object":{s.current=t;break}}})})}function yv(e){const t=x.useRef({...e});return zo(()=>{for(const s in e)t.current[s]=e[s]},[e]),t.current}const qN=x.createContext(null);function EB(e,t){const s=x.useRef({getLayout:()=>({}),setLayout:_B});x.useImperativeHandle(t,()=>s.current,[]),zo(()=>{Object.assign(s.current,LN({groupId:e}))})}function wx({children:e,className:t,defaultLayout:s,disableCursor:o,disabled:l,elementRef:c,groupRef:u,id:p,onLayoutChange:m,onLayoutChanged:g,orientation:h="horizontal",resizeTargetMinimumSize:b={coarse:20,fine:10},style:_,...k}){const N=x.useRef({onLayoutChange:{},onLayoutChanged:{}}),y=kc(U=>{So(N.current.onLayoutChange,U)||(N.current.onLayoutChange=U,m?.(U))}),w=kc((U,I)=>{So(N.current.onLayoutChanged,U)||(N.current.onLayoutChanged=U,g?.(U,{isUserInteraction:I}))}),S=vv(p),C=x.useRef(null),[E,R]=NB(),A=x.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:b,separators:[]}),T=_v(C,c);EB(S,u);const O=kc((U,I)=>{const V=No(),H=Vw(U),G=Ar(U);if(G){let q=!1;switch(V.state){case"active":{q=V.hitRegions.some(Y=>Y.group===H);break}}return{flexGrow:G.layout[I]??1,pointerEvents:q?"none":void 0}}if(s?.[I])return{flexGrow:s?.[I]}}),z=yv({defaultLayout:s,disableCursor:o}),L=x.useMemo(()=>({get disableCursor(){return!!z.disableCursor},getPanelStyles:O,id:S,orientation:h,registerPanel:U=>{const I=A.current;return I.panels=jx(h,[...I.panels,U]),R(),()=>{I.panels=I.panels.filter(V=>V!==U),R()}},registerSeparator:U=>{const I=A.current;return I.separators=jx(h,[...I.separators,U]),R(),()=>{I.separators=I.separators.filter(V=>V!==U),R()}},updatePanelProps:(U,{disabled:I})=>{const V=A.current.panels.find(q=>q.id===U);V&&(V.panelConstraints.disabled=I);const H=Vw(S),G=Ar(S);H&&G&&Qs(H,{...G,derivedPanelConstraints:yx(H)})},updateSeparatorProps:(U,{disabled:I,disableDoubleClick:V})=>{const H=A.current.separators.find(G=>G.id===U);H&&(H.disabled=I,H.disableDoubleClick=V)}}),[O,S,R,h,z]),D=x.useRef(null);return zo(()=>{const U=C.current;if(U===null)return;const I=A.current;let V;if(z.defaultLayout!==void 0&&Object.keys(z.defaultLayout).length===I.panels.length){V={};for(const K of I.panels){const P=z.defaultLayout[K.id];P!==void 0&&(V[K.id]=P)}}const H={disabled:!!l,element:U,id:S,mutableState:{defaultLayout:V,disableCursor:!!z.disableCursor,expandedPanelSizes:A.current.lastExpandedPanelSizes,layouts:A.current.layouts},orientation:h,panels:I.panels,resizeTargetMinimumSize:I.resizeTargetMinimumSize,separators:I.separators};D.current=H;const G=CB(H),{defaultLayoutDeferred:q,derivedPanelConstraints:Y,layout:X}=Ar(H.id,!0);!q&&Y.length>0&&(y(X),w(X,!1));const $=gv(S,K=>{const{defaultLayoutDeferred:P,derivedPanelConstraints:F,layout:W}=K.next;if(P||F.length===0)return;const ee=H.panels.map(({id:ue})=>ue).join(",");H.mutableState.layouts[ee]=W,F.forEach(ue=>{if(ue.collapsible){const{layout:se}=K.prev??{};if(se){const oe=qn(ue.collapsedSize,W[ue.panelId]),pe=qn(ue.collapsedSize,se[ue.panelId]);oe&&!pe&&(H.mutableState.expandedPanelSizes[ue.panelId]=se[ue.panelId])}}});const ce=No().state!=="active";y(W),ce&&w(W,K.isUserInteraction)});return()=>{D.current=null,G(),$()}},[l,S,w,y,h,E,z]),x.useEffect(()=>{const U=D.current;U&&(U.mutableState.defaultLayout=s,U.mutableState.disableCursor=!!o)}),r.jsx(qN.Provider,{value:L,children:r.jsx("div",{...k,className:t,"data-group":!0,"data-testid":S,id:S,ref:T,style:{height:"100%",width:"100%",overflow:"hidden",..._,display:"flex",flexDirection:h==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:h==="horizontal"?"pan-y":"pan-x"},children:e})})}wx.displayName="Group";function jv(){const e=x.useContext(qN);return Bt(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function RB(e,t){const{id:s}=jv(),o=x.useRef({collapse:Th,expand:Th,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:Th});x.useImperativeHandle(t,()=>o.current,[]),zo(()=>{Object.assign(o.current,PN({groupId:s,panelId:e}))})}function uo({children:e,className:t,collapsedSize:s="0%",collapsible:o=!1,defaultSize:l,disabled:c,elementRef:u,groupResizeBehavior:p="preserve-relative-size",id:m,maxSize:g="100%",minSize:h="0%",onResize:b,panelRef:_,style:k,...N}){const y=!!m,w=vv(m),S=yv({disabled:c}),C=x.useRef(null),E=_v(C,u),{getPanelStyles:R,id:A,orientation:T,registerPanel:O,updatePanelProps:z}=jv(),L=b!==null,D=kc((H,G,q)=>{b?.(H,m,q)});zo(()=>{const H=C.current;if(H!==null){const G={element:H,id:w,idIsStable:y,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:L?D:void 0,panelConstraints:{groupResizeBehavior:p,collapsedSize:s,collapsible:o,defaultSize:l,disabled:S.disabled,maxSize:g,minSize:h}};return O(G)}},[p,s,o,l,L,w,y,g,h,D,O,S]),x.useEffect(()=>{z(w,{disabled:c})},[c,w,z]),RB(w,_);const U=()=>{const H=R(A,w);if(H)return JSON.stringify(H)},I=x.useSyncExternalStore(H=>gv(A,H),U,U);let V;return I?V=JSON.parse(I):l!==void 0?V={flexGrow:void 0,flexShrink:void 0,flexBasis:l}:V={flexGrow:1},r.jsx("div",{...N,"data-disabled":c||void 0,"data-panel":!0,"data-testid":w,id:w,ref:E,style:{...TB,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...V},children:r.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...k,touchAction:T==="horizontal"?"pan-y":"pan-x"},children:e})})}uo.displayName="Panel";const TB={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function AB({layout:e,panelConstraints:t,panelId:s,panelIndex:o}){let l,c;const u=e[s],p=t.find(m=>m.panelId===s);if(p){const m=p.maxSize,g=p.collapsible?p.collapsedSize:p.minSize,h=[o,o+1];c=Co({layout:Dc({delta:g-u,initialLayout:e,panelConstraints:t,pivotIndices:h,prevLayout:e}),panelConstraints:t})[s],l=Co({layout:Dc({delta:m-u,initialLayout:e,panelConstraints:t,pivotIndices:h,prevLayout:e}),panelConstraints:t})[s]}return{valueControls:s,valueMax:l,valueMin:c,valueNow:u}}function wv({children:e,className:t,disabled:s,disableDoubleClick:o,elementRef:l,id:c,style:u,...p}){const m=vv(c),g=yv({disabled:s,disableDoubleClick:o}),[h,b]=x.useState({}),[_,k]=x.useState("inactive"),[N,y]=x.useState(!1),w=x.useRef(null),S=_v(w,l),{disableCursor:C,id:E,orientation:R,registerSeparator:A,updateSeparatorProps:T}=jv(),O=R==="horizontal"?"vertical":"horizontal";zo(()=>{const D=w.current;if(D!==null){const U={disabled:g.disabled,disableDoubleClick:g.disableDoubleClick,element:D,id:m},I=A(U),V=bB(G=>{k(G.next.state!=="inactive"&&G.next.hitRegions.some(q=>q.separator===U)?G.next.state:"inactive")}),H=gv(E,G=>{const{derivedPanelConstraints:q,layout:Y,separatorToPanels:X}=G.next,$=X.get(U);if($){const K=$[0],P=$.indexOf(K);b(AB({layout:Y,panelConstraints:q,panelId:K.id,panelIndex:P}))}});return()=>{V(),H(),I()}}},[E,m,A,g]),x.useEffect(()=>{T(m,{disabled:s,disableDoubleClick:o})},[s,o,m,T]);let z;s&&!C&&(z="not-allowed");let L;if(s)L="disabled";else switch(_){case"active":{L="active";break}default:N?L="focus":L=_}return r.jsx("div",{...p,"aria-controls":h.valueControls,"aria-disabled":s||void 0,"aria-orientation":O,"aria-valuemax":h.valueMax,"aria-valuemin":h.valueMin,"aria-valuenow":h.valueNow,children:e,className:t,"data-separator":L,"data-testid":m,id:m,onBlur:()=>y(!1),onFocus:()=>y(!0),ref:S,role:"separator",style:{flexBasis:"auto",cursor:z,...u,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:s?void 0:0})}wv.displayName="Separator";function MB({projects:e,value:t,onChange:s,disabled:o}){const l=e.map(c=>{const u=c.path?.split("/").filter(Boolean).pop()||f("modules_ui.code_project_fallback",{id:c.id});return{value:String(c.id),label:c.name||u,icon:bM,description:c.path}});return r.jsx("div",{className:"w-full","data-testid":"code-project-select",children:r.jsx(_t,{value:t,onChange:s,options:l,placeholder:f("modules_ui.code_pick_project_ph"),disabled:o})})}function OB({sessions:e,activeId:t,busy:s,onSelect:o,onCreate:l,onRename:c,onDelete:u}){return r.jsxs("div",{className:"flex h-full flex-col","data-testid":"code-session-list",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3 py-2",children:[r.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:f("code_module.sessions")}),r.jsx(et,{content:f("code_module.new_session"),children:r.jsxs("button",{type:"button",onClick:l,disabled:s,"data-testid":"code-new-session",className:"flex items-center gap-1 rounded-md border border-border px-1.5 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50",children:[r.jsx(rn,{className:"size-3"})," ",f("code_module.new_session")]})})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:e.length===0?r.jsx("div",{className:"p-2",children:r.jsx(xt,{children:f("code_module.no_sessions")})}):r.jsx("ul",{className:"space-y-0.5",children:e.map(p=>r.jsxs("li",{className:"group/item relative",children:[r.jsxs("button",{type:"button",onClick:()=>o(p.id),className:ze("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-xs transition-colors",p.id===t?"bg-accent text-accent-fg":"text-foreground/80 hover:bg-accent/50"),children:[r.jsx(Lx,{className:"mt-0.5 size-3.5 shrink-0 opacity-60"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate font-medium",children:p.title}),r.jsxs("span",{className:"block truncate text-[10px] text-muted-foreground",children:[p.mode," · ",p.messageCount," msg",p.model?` · ${p.model}`:""]})]})]}),r.jsxs("div",{className:"absolute right-1 top-1 hidden items-center gap-0.5 group-hover/item:flex",children:[r.jsx(et,{content:f("code_module.rename"),children:r.jsx("button",{type:"button",onClick:()=>c(p.id,p.title),className:"rounded p-1 text-muted-foreground hover:bg-background hover:text-foreground",children:r.jsx(Eo,{className:"size-3"})})}),r.jsx(et,{content:f("code_module.delete"),children:r.jsx("button",{type:"button",onClick:()=>u(p.id),className:"rounded p-1 text-muted-foreground hover:bg-background hover:text-rose-500",children:r.jsx(ca,{className:"size-3"})})})]})]},p.id))})})]})}function zB({mode:e,onChange:t,disabled:s}){const o=(l,c,u,p)=>r.jsx(et,{content:u,children:r.jsxs("button",{type:"button",disabled:s,"data-testid":`code-mode-${l}`,"aria-pressed":e===l,onClick:()=>t(l),className:ze("flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors disabled:opacity-50",e===l?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[r.jsx(p,{className:"size-3.5"})," ",c]})});return r.jsxs("div",{className:"flex items-center gap-0.5 rounded-lg border border-border bg-muted/60 p-0.5",children:[o("build",f("code_module.mode_build"),f("code_module.mode_build_hint"),wM),o("plan",f("code_module.mode_plan"),f("code_module.mode_plan_hint"),sM)]})}function DB({value:e,onValueChange:t,onSubmit:s,onStop:o,busy:l,disabled:c,mode:u,onModeChange:p,model:m,onModelChange:g}){return r.jsx(iv,{value:e,onValueChange:t,onSubmit:s,onStop:o,busy:l,disabled:c,placeholder:f("code_module.placeholder"),minRows:1,maxRows:6,footer:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(zB,{mode:u,onChange:p,disabled:l}),r.jsx(cv,{value:m,onChange:g,disabled:l})]})})}function Ah(e,t){let s=0;for(const o of e.parts||[])o.kind==="text"&&t.text&&(s+=o.text.length),o.kind==="tool"&&t.tool&&(o.args&&(s+=JSON.stringify(o.args).length),o.result!==void 0&&(s+=JSON.stringify(o.result).length));return Math.ceil(s/4)}function PB(e){let t=null,s=0,o=0;for(const u of e)u.role==="user"?s++:o++,u.role==="assistant"&&u.usage&&(t={input:u.usage.input_tokens,output:u.usage.output_tokens,model:u.model});const l=t?.input??0,c=t?.output??0;return{model:t?.model??null,input:l,output:c,total:l+c,hasUsage:!!t,messages:e.length,userMsgs:s,assistantMsgs:o}}function LB(e){let t=0,s=0,o=0;for(const u of e)u.role==="user"?t+=Ah(u,{text:!0}):s+=Ah(u,{text:!0}),o+=Ah(u,{tool:!0});const l=t+s+o||1,c=(u,p)=>({key:u,tokens:p,percent:Math.round(p/l*100)});return[c("user",t),c("assistant",s),c("tool",o)].filter(u=>u.tokens>0)}const sk={user:"bg-emerald-500",assistant:"bg-sky-500",tool:"bg-amber-500"};function Bs({label:e,value:t}){return r.jsxs("div",{className:"flex items-baseline justify-between gap-2 py-0.5",children:[r.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-muted-foreground",children:e}),r.jsx("span",{className:"min-w-0 truncate text-right font-mono text-xs text-foreground",children:t})]})}function rk(e){if(!e)return"";const t=new Date(e),s=o=>String(o).padStart(2,"0");return`${s(t.getDate())} ${t.toLocaleString("es",{month:"short"})} ${t.getFullYear()}, ${s(t.getHours())}:${s(t.getMinutes())}`}function IB({turns:e,session:t}){const s=x.useMemo(()=>PB(e),[e]),o=x.useMemo(()=>LB(e),[e]);return e.length===0?r.jsx("div",{className:"p-3",children:r.jsx(xt,{children:f("code_module.ctx_none")})}):r.jsxs("div",{className:"space-y-1 p-3","data-testid":"code-context-tab",children:[r.jsx(Bs,{label:f("code_module.ctx_model"),value:s.model||f("modules_ui.code_ctx_auto")}),t?.mode&&r.jsx(Bs,{label:f("modules_ui.code_ctx_mode"),value:t.mode}),t?.agentSlug&&r.jsx(Bs,{label:f("modules_ui.code_ctx_agent"),value:t.agentSlug}),r.jsx(Bs,{label:f("code_module.ctx_messages"),value:f("modules_ui.code_ctx_msgs_value",{user:s.userMsgs,assistant:s.assistantMsgs})}),r.jsx(Bs,{label:f("code_module.ctx_input"),value:s.input.toLocaleString()}),r.jsx(Bs,{label:f("code_module.ctx_output"),value:s.output.toLocaleString()}),r.jsx(Bs,{label:f("modules_ui.code_ctx_tokens_total"),value:(s.input+s.output).toLocaleString()}),t?.createdAt&&r.jsx(Bs,{label:f("modules_ui.code_ctx_created"),value:rk(t.createdAt)}),t?.updatedAt&&r.jsx(Bs,{label:f("modules_ui.code_ctx_activity"),value:rk(t.updatedAt)}),r.jsx("hr",{className:"border-border my-2"}),r.jsxs("div",{children:[r.jsx("div",{className:"mb-1 text-[11px] font-semibold text-muted-foreground",children:f("code_module.ctx_breakdown")}),o.length>0?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex h-2.5 w-full overflow-hidden rounded-full bg-muted",children:o.map(l=>r.jsx(et,{content:`${l.key}: ${l.tokens} (${l.percent}%)`,children:r.jsx("div",{className:sk[l.key],style:{width:`${l.percent}%`}})},l.key))}),r.jsx("ul",{className:"mt-2 space-y-1",children:o.map(l=>r.jsxs("li",{className:"flex items-center gap-2 text-[11px]",children:[r.jsx("span",{className:`size-2 rounded-full ${sk[l.key]}`}),r.jsx("span",{className:"flex-1 text-foreground/80",children:f(`code_module.seg_${l.key}`)}),r.jsxs("span",{className:"font-mono text-muted-foreground",children:[l.tokens," · ",l.percent,"%"]})]},l.key))})]}):r.jsx("p",{className:"text-[11px] text-muted-foreground",children:f("code_module.ctx_none")})]})]})}function BB(e){const t=[];for(const s of(e||"").split(`
650
+ `;return typeof p=="function"&&p(null,w),w},Eh}var Uw;function r7(){if(Uw)return _l;Uw=1;const e=B8(),t=n7(),s=a7(),o=s7();function l(c,u,p,m,g){const h=[].slice.call(arguments,1),b=h.length,_=typeof h[b-1]=="function";if(!_&&!e())throw new Error("Callback required as last argument");if(_){if(b<2)throw new Error("Too few arguments provided");b===2?(g=p,p=u,u=m=void 0):b===3&&(u.getContext&&typeof g>"u"?(g=m,m=void 0):(g=m,m=p,p=u,u=void 0))}else{if(b<1)throw new Error("Too few arguments provided");return b===1?(p=u,u=m=void 0):b===2&&!u.getContext&&(m=p,p=u,u=void 0),new Promise(function(k,N){try{const y=t.create(p,m);k(c(y,u,m))}catch(y){N(y)}})}try{const k=t.create(p,m);g(null,c(k,u,m))}catch(k){g(k)}}return _l.create=t.create,_l.toCanvas=l.bind(null,s.render),_l.toDataURL=l.bind(null,s.renderToDataURL),_l.toString=l.bind(null,function(c,u,p){return o.render(c,p)}),_l}var o7=r7();const l7=kx(o7);function i7({value:e,size:t=200}){const[s,o]=x.useState(null);return x.useEffect(()=>{let l=!0;return l7.toDataURL(e,{margin:2,width:t*2,errorCorrectionLevel:"M"}).then(c=>{l&&o(c)}).catch(()=>{l&&o(null)}),()=>{l=!1}},[e,t]),r.jsx("div",{className:"grid place-items-center rounded-lg bg-white p-3",style:{width:t+24,height:t+24},children:s?r.jsx("img",{src:s,width:t,height:t,alt:"QR"}):r.jsx("div",{className:"size-full animate-pulse rounded bg-muted"})})}function c7(e){return e.find(t=>!t.includes("127.0.0.1")&&!t.includes("localhost"))||e[0]||window.location.origin}function u7({open:e,onClose:t,onPaired:s}){const o=lt(),[l,c]=x.useState(null),[u,p]=x.useState(null),[m,g]=x.useState(0),[h,b]=x.useState(!1),_=x.useRef(null),k=x.useCallback(async()=>{c(null),p(null),b(!1);try{const C=await $l.init();c(C),g(Math.round((C.ttl_ms||9e4)/1e3))}catch(C){C instanceof Fc&&C.status===403?p(f("settings.devices_pair_localhost_only")):p(C.message)}},[]);x.useEffect(()=>{e?k():(c(null),p(null),b(!1))},[e,k]),x.useEffect(()=>{if(!l||h||m<=0)return;const C=window.setTimeout(()=>g(E=>E-1),1e3);return()=>window.clearTimeout(C)},[l,m,h]),x.useEffect(()=>{if(!e||!l||h)return;let C=!0;const E=async()=>{try{const R=await $l.status(l.pairing_id);if(!C)return;if(R.status==="confirmed"){b(!0),o.success(f("settings.devices_pair_done")),s(),window.setTimeout(()=>{C&&t()},900);return}if(R.status==="expired"||R.status==="unknown"){g(0);return}}catch{}_.current=window.setTimeout(E,1500)};return _.current=window.setTimeout(E,1500),()=>{C=!1,_.current&&window.clearTimeout(_.current)}},[e,l,h,t,s,o]);const N=!!l&&!h&&m<=0,y=l?c7(l.lan_urls):"",w=l?`${y}/#pair=${l.pairing_id}`:"",S=async(C,E)=>{try{await navigator.clipboard.writeText(C),o.success(E)}catch{o.error(C)}};return r.jsxs(An,{open:e,onClose:t,title:f("settings.devices_pair_title"),description:f("settings.devices_pair_desc"),footer:r.jsx(me,{variant:"secondary",onClick:t,children:f("common.close")}),children:[u&&r.jsx("p",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:u}),!u&&!l&&r.jsxs("div",{className:"flex items-center gap-2 py-8 text-sm text-muted-fg",children:[r.jsx(va,{})," ",f("common.loading")]}),!u&&l&&r.jsxs("div",{className:"flex flex-col items-center gap-4",children:[r.jsx("div",{className:N?"opacity-40":"",children:r.jsx(i7,{value:w,size:196})}),h?r.jsx("p",{className:"text-sm font-medium text-emerald-500",children:f("settings.devices_pair_done")}):N?r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("p",{className:"text-sm text-muted-fg",children:f("settings.devices_pair_expired")}),r.jsx(me,{variant:"primary",onClick:()=>void k(),children:f("settings.devices_pair_regen")})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-center text-xs text-muted-fg",children:f("settings.devices_pair_scan")}),r.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-fg",children:[r.jsx(va,{size:12}),r.jsx("span",{children:f("settings.devices_pair_waiting")}),r.jsxs("span",{className:"tabular-nums",children:["· ",f("settings.devices_pair_expires",{s:m})]})]}),r.jsxs("div",{className:"w-full space-y-3 border-t border-border pt-3",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-xs text-muted-fg",children:f("settings.devices_pair_link")}),r.jsxs("div",{className:"flex items-stretch gap-2",children:[r.jsx("code",{className:"min-w-0 flex-1 break-all rounded-md bg-muted px-3 py-2 text-xs",children:w}),r.jsx(et,{content:f("settings.devices_pair_copy"),children:r.jsx(me,{size:"sm",variant:"secondary",onClick:()=>S(w,f("settings.devices_pair_copied")),children:r.jsx(Fd,{size:14})})})]})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-xs text-muted-fg",children:f("settings.devices_pair_code")}),r.jsxs("div",{className:"flex items-stretch gap-2",children:[r.jsx("code",{className:"min-w-0 flex-1 break-all rounded-md bg-muted px-3 py-2 text-center text-sm",children:l.pairing_id}),r.jsx(et,{content:f("settings.devices_pair_copy"),children:r.jsx(me,{size:"sm",variant:"secondary",onClick:()=>S(l.pairing_id,f("settings.devices_pair_copied_code")),children:r.jsx(Fd,{size:14})})})]})]})]})]})]})]})}function d7(){const e=lt(),{clients:t,isLoading:s,mutate:o}=I8(),[l,c]=x.useState(!1),u=async p=>{if(confirm(f("settings.devices_revoke_confirm",{id:p})))try{await $l.revoke(p),e.success(f("settings.devices_revoke_success")),o()}catch(m){e.error(m.message)}};return r.jsxs(Ye,{title:f("settings.devices"),description:f("settings.devices_sub"),action:r.jsxs(me,{size:"sm",variant:"primary",onClick:()=>c(!0),children:[r.jsx(LM,{size:14})," ",f("settings.devices_pair_btn")]}),children:[s&&r.jsx(ot,{}),!s&&t.length===0&&r.jsx(xt,{children:f("settings.devices_empty")}),t.length>0&&r.jsx("ul",{className:"space-y-2 text-sm",children:t.map(p=>r.jsxs("li",{className:"flex items-center gap-3 rounded-md border border-border bg-muted/30 px-3 py-2",children:[r.jsx("span",{className:"font-medium",children:p.label||p.id}),r.jsx(Fe,{tone:p.kind==="web"?"info":p.kind==="deck"?"success":"muted",children:p.kind}),r.jsxs("span",{className:"font-mono text-xs text-muted-fg",children:["…",p.token_suffix]}),r.jsxs("span",{className:"ml-auto text-xs text-muted-fg",children:[f("settings.devices_last_seen")," ",p.last_seen?new Date(p.last_seen).toLocaleString():f("settings.devices_never")]}),r.jsx(me,{size:"sm",variant:"destructive",onClick:()=>u(p.id),children:f("settings.devices_revoke")})]},p.id))}),r.jsx(u7,{open:l,onClose:()=>c(!1),onPaired:()=>o()})]})}const f7=[{key:"daemon",label:"Daemon",description:"~/.apx/config.json. General APX config.",fields:[{path:"port",label:"Port",kind:"number",placeholder:"7430"},{path:"host",label:"Host",placeholder:"127.0.0.1"},{path:"log_level",label:"Log level",placeholder:"info"},{path:"user.language",label:"Language",placeholder:"en"},{path:"user.locale",label:"Locale",placeholder:"en-US"},{path:"user.timezone",label:"Timezone",placeholder:"America/Argentina/Salta"}]},{key:"super-agent",label:"Super-agent",fields:[{path:"super_agent.enabled",label:"Super-agent enabled",kind:"boolean"},{path:"super_agent.model",label:"Model",placeholder:"gemini:gemini-2.5-flash"},{path:"super_agent.permission_mode",label:"Permission mode",kind:"select",options:Vx.map(e=>({value:e,label:e}))},{path:"super_agent.system",label:"Extra prompt",kind:"textarea"}]},{key:"telegram",label:"Telegram",fields:[{path:"telegram.enabled",label:"Polling enabled",kind:"boolean"},{path:"telegram.poll_interval_ms",label:"Poll interval ms",kind:"number",placeholder:"1500"},{path:"telegram.respond_with_engine",label:"Respond with engine",kind:"boolean"},{path:"telegram.route_to_agent",label:"Route to agent",placeholder:"master"},{path:"telegram.channels.0.chat_id",label:"Default chat ID"},{path:"telegram.channels.0.bot_token",label:"Default bot token",kind:"password"}]},{key:"engines",label:"Engines",fields:[{path:"engines.anthropic.api_key",label:"Anthropic API key",kind:"password"},{path:"engines.openai.api_key",label:"OpenAI API key",kind:"password"},{path:"engines.openai.base_url",label:"OpenAI base URL",placeholder:"https://api.openai.com/v1"},{path:"engines.groq.api_key",label:"Groq API key",kind:"password"},{path:"engines.groq.base_url",label:"Groq base URL",placeholder:"https://api.groq.com/openai/v1"},{path:"engines.openrouter.api_key",label:"OpenRouter API key",kind:"password"},{path:"engines.openrouter.base_url",label:"OpenRouter base URL",placeholder:"https://openrouter.ai/api/v1"},{path:"engines.gemini.api_key",label:"Gemini API key",kind:"password"},{path:"engines.ollama.base_url",label:"Ollama URL",placeholder:"http://localhost:11434"}]}];function p7(){const{config:e,isLoading:t,patch:s,mutate:o}=Vr();if(t)return r.jsx(ot,{});const l=async c=>{const u={};for(const[p,m]of Object.entries(rv(c)))oa(m)||(u[p]=m);await s(u),o()};return r.jsx(Ye,{title:f("global_config.title"),description:f("settings_ui.global_config_desc"),children:r.jsx(px,{sections:f7,source:e,jsonTitle:"~/.apx/config.json",jsonDescription:f("settings_ui.global_json_desc"),onSaveFields:async(c,u)=>{await s(c,u),o()},onSaveJson:l})})}function m7(){const e=lt(),{health:t,isUp:s}=NC(),o=async()=>{try{await ql.reload(),e.success(f("settings.advanced.reload_success"))}catch(l){e.error(l.message)}};return r.jsxs("div",{className:"space-y-6",children:[r.jsx(Ye,{title:f("daemon.version"),action:r.jsx(me,{size:"sm",onClick:o,children:f("common.reload")}),children:r.jsxs("div",{className:"grid grid-cols-3 gap-3 text-sm",children:[r.jsx(Rh,{label:f("daemon.version"),value:t?.version||"—"}),r.jsx(Rh,{label:f("daemon.uptime"),value:t?`${t.uptime_s}s`:"—"}),r.jsx(Rh,{label:f("daemon.status"),value:f(s?"daemon.running":"daemon.down"),ok:s})]})}),r.jsx(p7,{})]})}function Rh({label:e,value:t,ok:s}){return r.jsxs("div",{className:"rounded-md border border-border bg-muted/30 p-3",children:[r.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-fg",children:e}),r.jsxs("div",{className:"mt-1 flex items-center gap-2 text-base font-medium",children:[s!==void 0&&r.jsx(Yc,{ok:s}),r.jsx("span",{children:t})]})]})}function g7(){const e=lt(),{theme:t,set:s}=qx(),[o,l]=x.useState(""),[c,u]=x.useState(eC()),p=()=>{const g=o.trim();if(g){fo(g);try{localStorage.setItem(Rn.token,g)}catch{}l(""),e.success(f("settings.token_saved"))}},m=g=>{W2(g),u(g),window.location.reload()};return r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2 xl:items-start",children:[r.jsx(Ye,{title:f("settings.appearance"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(me,{variant:t==="light"?"primary":"secondary",onClick:()=>s("light"),children:f("settings.light_mode")}),r.jsx(me,{variant:t==="dark"?"primary":"secondary",onClick:()=>s("dark"),children:f("settings.dark_mode")})]})}),r.jsx(Ye,{title:f("settings.language"),children:r.jsx("div",{className:"flex items-center gap-2",children:J2.map(g=>r.jsx(me,{variant:c===g.value?"primary":"secondary",onClick:()=>m(g.value),children:g.label},g.value))})}),r.jsxs(Ye,{title:f("settings.token"),description:f("settings.token_sub"),children:[r.jsx(fe,{label:f("settings_ui.bearer_label"),children:r.jsx(Ae,{type:"password",placeholder:Hb()?f("settings.token_active"):f("settings.token_paste"),value:o,onChange:g=>l(g.target.value),className:"font-mono",onKeyDown:g=>{g.key==="Enter"&&p()}})}),r.jsx("div",{className:"mt-2",children:r.jsx(me,{variant:"primary",onClick:p,children:f("common.save")})})]})]})}function h7({className:e,...t}){return r.jsx("kbd",{"data-slot":"kbd",className:St("pointer-events-none inline-flex h-5 w-fit min-w-5 items-center justify-center gap-1 rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground select-none in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background dark:in-data-[slot=tooltip-content]:bg-background/10 [&_svg:not([class*='size-'])]:size-3",e),...t})}const _x=typeof navigator<"u"&&/mac/i.test(navigator.platform||"");function x7(e){return(_x?{CommandOrControl:"⌘ Cmd",CmdOrCtrl:"⌘ Cmd",Command:"⌘ Cmd",Cmd:"⌘ Cmd",Super:"⌘ Cmd",Meta:"⌘ Cmd",Control:"⌃ Ctrl",Ctrl:"⌃ Ctrl",Option:"⌥ Opt",Alt:"⌥ Opt",Shift:"⇧ Shift"}:{CommandOrControl:"Ctrl",CmdOrCtrl:"Ctrl",Control:"Ctrl",Ctrl:"Ctrl",Command:"Win",Cmd:"Win",Super:"Win",Meta:"Win",Option:"Alt",Alt:"Alt",Shift:"Shift"})[e]??e}function b7(e){return(e||"").split("+").map(t=>t.trim()).filter(Boolean)}function v7(e){const t=e.code;if(/^(Shift|Control|Alt|Meta|OS)(Left|Right)?$/.test(t))return null;let s;if((s=t.match(/^Key([A-Z])$/))||(s=t.match(/^Digit(\d)$/))||(s=t.match(/^Numpad(\d)$/))||(s=t.match(/^(F\d{1,2})$/))||(s=t.match(/^Arrow(Up|Down|Left|Right)$/)))return s[1];const o={Space:"Space",Enter:"Enter",Tab:"Tab",Backspace:"Backspace",Delete:"Delete",Home:"Home",End:"End",PageUp:"PageUp",PageDown:"PageDown",Insert:"Insert",Minus:"-",Equal:"=",BracketLeft:"[",BracketRight:"]",Backslash:"\\",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backquote:"`"};return o[t]?o[t]:e.key&&e.key.length===1?e.key.toUpperCase():null}function _7(e){const t=v7(e);if(!t)return null;const s=[];(_x?e.metaKey:e.ctrlKey)&&s.push("CommandOrControl"),_x&&e.ctrlKey&&s.push("Control"),e.altKey&&s.push("Alt"),e.shiftKey&&s.push("Shift");const o=s.length>0,l=/^F\d{1,2}$/.test(t);return!o&&!l?null:(s.push(t),s.join("+"))}function y7({value:e,onChange:t,disabled:s,className:o,trailing:l}){const[c,u]=x.useState(!1),p=x.useRef(null);x.useEffect(()=>{if(!c)return;const g=h=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"){u(!1);return}const b=_7(h);b&&(t(b),u(!1))};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[c,t]);const m=b7(e);return r.jsxs("div",{className:ze("flex h-9 w-full max-w-md items-center rounded-md border border-border bg-transparent transition",c&&"ring-2 ring-ring",s&&"opacity-50",o),children:[r.jsxs("button",{ref:p,type:"button",disabled:s,onClick:()=>u(g=>!g),onBlur:()=>u(!1),"aria-label":f("modules_ui.desktop_shortcut_record"),className:"flex h-full min-w-0 flex-1 items-center gap-1.5 rounded-l-md px-3 text-sm outline-none hover:bg-muted/40 focus-visible:bg-muted/40",children:[c?r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.desktop_shortcut_recording")}):m.length?r.jsx("span",{className:"flex min-w-0 flex-wrap items-center gap-1",children:m.map((g,h)=>r.jsxs("span",{className:"flex items-center gap-1",children:[h>0&&r.jsx("span",{className:"text-xs text-muted-fg",children:"+"}),r.jsx(h7,{className:"h-6 min-w-6 border border-border bg-muted px-1.5 text-[13px] font-semibold text-fg shadow-sm",children:x7(g)})]},h))}):r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.desktop_shortcut_record")}),r.jsx("span",{className:"ml-auto whitespace-nowrap pl-2 text-xs text-muted-fg",children:f(c?"modules_ui.desktop_shortcut_esc":"modules_ui.desktop_shortcut_change")})]}),l?r.jsx("div",{className:"flex h-full items-center border-l border-border px-1",children:l}):null]})}const wl={status:()=>ge.get("/desktop/status"),start:()=>ge.post("/desktop/start",{}),stop:()=>ge.post("/desktop/stop",{}),restart:()=>ge.post("/desktop/restart",{}),autostartGet:()=>ge.get("/desktop/autostart"),autostartSet:e=>ge.post("/desktop/autostart",{enable:e})};function j7(e=30){return ge.get(`/messages/global?channel=desktop&limit=${e}`)}function RN({showConfigLink:e=!1}){const t=lt(),{data:s,isLoading:o,mutate:l}=Qe("/desktop/status",()=>wl.status(),{refreshInterval:5e3}),c=!!s?.running,[u,p]=x.useState(null),m=async(_,k)=>{p(_);try{await k()}catch(N){t.error(N.message)}finally{p(null),setTimeout(()=>l(),1200)}},g=()=>m("start",async()=>{const _=await wl.start();t.success(_.already?f("modules_ui.desktop_start_already"):f("modules_ui.desktop_start_done"))}),h=()=>m("stop",async()=>{const _=await wl.stop();t.success(_.stopped?f("modules_ui.desktop_stop_done"):f("modules_ui.desktop_stop_none"))}),b=()=>m("restart",async()=>{(await wl.restart()).reloaded>0?t.success(f("modules_ui.desktop_restart_done")):t.info(f("modules_ui.desktop_restart_none"))});return r.jsx(Ye,{title:f("desktop_screen.status_title"),description:f("modules_ui.desktop_status_desc"),action:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(me,{variant:"primary",size:"sm",onClick:g,loading:u==="start",disabled:c||u!==null&&u!=="start",children:f("modules_ui.desktop_start")}),r.jsx(me,{variant:"secondary",size:"sm",onClick:h,loading:u==="stop",disabled:!c||u!==null&&u!=="stop",children:f("modules_ui.desktop_stop")}),r.jsx(me,{variant:"secondary",size:"sm",onClick:b,loading:u==="restart",disabled:!c||u!==null&&u!=="restart",title:f("modules_ui.desktop_restart_hint"),children:f("modules_ui.desktop_restart")}),e&&r.jsx(wf,{to:"/settings/desktop",children:r.jsxs(me,{size:"sm",variant:"ghost",children:[r.jsx(Cc,{size:14})," ",f("desktop_screen.open_config")]})})]}),children:o?r.jsx(ot,{}):r.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-sm",children:[r.jsx(Yc,{ok:c}),r.jsx("span",{className:"font-medium",children:f(c?"modules_ui.desktop_running":"modules_ui.desktop_stopped")}),r.jsx("button",{type:"button",onClick:()=>l(),className:"text-xs text-muted-fg underline-offset-2 hover:underline",children:f("modules_ui.desktop_refresh")}),r.jsxs("span",{className:"text-xs text-muted-fg",children:["(",f("modules_ui.desktop_from_terminal")," ",r.jsx(zj,{children:"apx desktop start"})," · ",r.jsx(zj,{children:"apx desktop --debug"}),")"]})]})})}const w7="CommandOrControl+G",k7=()=>[{value:"left",label:f("modules_ui.desktop_pos_left")},{value:"center",label:f("modules_ui.desktop_pos_center")},{value:"right",label:f("modules_ui.desktop_pos_right")}],S7=()=>[{value:"system",label:f("modules_ui.desktop_theme_system")},{value:"light",label:f("modules_ui.desktop_theme_light")},{value:"dark",label:f("modules_ui.desktop_theme_dark")}];function C7(){const e=lt(),{config:t,isLoading:s,patch:o}=Vr(),l=t,c=l.desktop?.shortcut||l.overlay?.shortcut||w7,u=l.desktop?.enabled!==!1,p=l.desktop?.theme||"system",m=l.desktop?.position||"right",{data:g,mutate:h}=Qe("/desktop/autostart",()=>wl.autostartGet()),[b,_]=x.useState(c),[k,N]=x.useState(!1),[y,w]=x.useState(!1);x.useEffect(()=>_(c),[c]);const S=async()=>{const R=b.trim();if(!(!R||R===c)){N(!0);try{await o({"desktop.shortcut":R}),e.success(f("modules_ui.desktop_shortcut_saved"))}catch(A){e.error(A.message)}finally{N(!1)}}},C=async(R,A,T)=>{N(!0);try{await o({[R]:A}),e.success(T)}catch(O){e.error(O.message)}finally{N(!1)}},E=async R=>{w(!0);try{await wl.autostartSet(R),await h(),e.success(f(R?"modules_ui.desktop_autostart_on":"modules_ui.desktop_autostart_off"))}catch(A){e.error(A.message)}finally{w(!1)}};return r.jsxs("div",{className:"space-y-6","data-testid":"settings-desktop",children:[r.jsx(RN,{}),r.jsx(Ye,{title:f("desktop_screen.autostart_title"),description:f("modules_ui.desktop_autostart_desc"),children:g?r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx(Qt,{checked:g.enabled,onChange:E,disabled:y,label:g.enabled?f("common.enabled"):f("common.disabled")}),r.jsx("span",{className:"text-xs text-muted-fg",children:f("modules_ui.desktop_platform",{platform:g.platform})})]}):r.jsx(ot,{})}),r.jsx(Ye,{title:f("desktop_screen.shortcut_title"),description:f("modules_ui.desktop_shortcut_desc"),children:s?r.jsx(ot,{}):r.jsx(fe,{label:f("modules_ui.desktop_accelerator"),hint:f("modules_ui.desktop_accelerator_hint"),children:r.jsx(y7,{value:b,onChange:_,disabled:k,trailing:r.jsx(me,{variant:"primary",size:"sm",onClick:S,loading:k,disabled:!b.trim()||b.trim()===c,children:f("common.save")})})})}),r.jsx(Ye,{title:f("desktop_screen.appearance_title"),description:f("modules_ui.desktop_appearance_desc"),children:s?r.jsx(ot,{}):r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("modules_ui.desktop_theme"),hint:f("modules_ui.desktop_restart_apply"),children:r.jsx(_t,{value:p,onChange:R=>C("desktop.theme",R,f("modules_ui.desktop_theme_set",{value:R})),options:S7(),disabled:k})}),r.jsx(fe,{label:f("modules_ui.desktop_position"),hint:f("modules_ui.desktop_position_hint"),children:r.jsx(_t,{value:m,onChange:R=>C("desktop.position",R,f("modules_ui.desktop_position_set",{value:R})),options:k7(),disabled:k})})]})}),r.jsx(Ye,{title:f("desktop_screen.activation_title"),description:f("modules_ui.desktop_activation_desc"),children:s?r.jsx(ot,{}):r.jsxs("div",{className:"space-y-3",children:[r.jsx(Qt,{checked:u,onChange:R=>C("desktop.enabled",R,f(R?"modules_ui.desktop_enabled_toast":"modules_ui.desktop_disabled_toast")),disabled:k,label:f(u?"modules_ui.desktop_plugin_on":"modules_ui.desktop_plugin_off")}),r.jsxs("p",{className:"text-xs text-muted-fg",children:[f("modules_ui.desktop_stt_engine")," ",r.jsx(wf,{to:"/settings/voice",className:"font-medium text-fg underline underline-offset-2",children:f("nav.modules.voice")})," ",f("modules_ui.desktop_stt_engine_suffix")]})]})})]})}function N7({engines:e,order:t,mode:s,configuredProvider:o,onSetMode:l,onSetDefault:c,onToggleEnabled:u,onReorder:p,onConfigure:m,busy:g}){const h=new Map(e.map(N=>[N.id,N])),b=[...t.filter(N=>h.has(N)),...e.map(N=>N.id).filter(N=>!t.includes(N))],_=s==="chain",k=(N,y)=>{const w=b.indexOf(N),S=w+y;if(w<0||S<0||S>=b.length)return;const C=[...b];[C[w],C[S]]=[C[S],C[w]],p(C)};return r.jsxs("div",{className:"space-y-3",children:[r.jsx("div",{className:"rounded-lg border border-border p-3",children:r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-sm font-medium",children:f("voice_ui.selection_mode")}),r.jsx("div",{className:"text-xs text-muted-fg",children:f(_?"voice_ui.mode_chain_desc":"voice_ui.mode_single_desc")})]}),r.jsxs("div",{className:"flex shrink-0 overflow-hidden rounded-md border border-border",role:"group",children:[r.jsx("button",{type:"button",onClick:()=>l("chain"),disabled:g,"data-testid":"voice-mode-chain",className:ze("px-3 py-1.5 text-xs font-medium transition-colors",_?"bg-emerald-500/15 text-emerald-300":"text-muted-fg hover:text-fg"),children:f("voice_ui.mode_chain_btn")}),r.jsx("button",{type:"button",onClick:()=>l("single"),disabled:g,"data-testid":"voice-mode-single",className:ze("border-l border-border px-3 py-1.5 text-xs font-medium transition-colors",_?"text-muted-fg hover:text-fg":"bg-emerald-500/15 text-emerald-300"),children:f("voice_ui.mode_single_btn")})]})]})}),r.jsx("div",{className:"space-y-2",children:b.map((N,y)=>{const w=h.get(N),S=pf[N]||{name:N,note:""},C=!_&&o===N,E=N==="mock";return r.jsxs("div",{"data-testid":`voice-provider-${N}`,className:ze("flex items-center gap-3 rounded-lg border px-3 py-2.5",C?"border-emerald-500/50 bg-emerald-500/10":"border-border",_&&!E&&!w.enabled&&"opacity-60"),children:[_&&r.jsxs("div",{className:"flex flex-col",children:[r.jsx("button",{type:"button",onClick:()=>k(N,-1),disabled:g||y===0,"aria-label":f("voice_ui.move_up"),"data-testid":`voice-provider-${N}-up`,className:"text-muted-fg hover:text-fg disabled:opacity-30",children:r.jsx(Pk,{className:"size-3.5"})}),r.jsx("button",{type:"button",onClick:()=>k(N,1),disabled:g||y===b.length-1,"aria-label":f("voice_ui.move_down"),"data-testid":`voice-provider-${N}-down`,className:"text-muted-fg hover:text-fg disabled:opacity-30",children:r.jsx(Zs,{className:"size-3.5"})})]}),r.jsx(Yc,{ok:w.available?!0:w.configured?!1:null}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm font-medium",children:S.name}),S.local&&r.jsx(Fe,{tone:"info",children:f("voice_ui.badge_local")}),w.available?r.jsx(Fe,{tone:"success",children:f("voice_ui.badge_available")}):w.configured?r.jsx(Fe,{tone:"warning",children:f("voice_ui.badge_unavailable")}):r.jsx(Fe,{tone:"muted",children:f("voice_ui.badge_not_configured")}),C&&r.jsx(Fe,{tone:"success",children:f("voice_ui.badge_default")})]}),r.jsx("div",{className:"truncate text-xs text-muted-fg",children:S.note})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[_?r.jsx(Qt,{checked:E?!0:w.enabled,onChange:R=>u(N,R),disabled:g||E}):!C&&r.jsxs(me,{size:"sm",variant:"ghost",onClick:()=>c(N),disabled:g,"data-testid":`voice-provider-${N}-default`,children:[r.jsx(aM,{className:"size-3.5"})," ",f("voice_ui.set_as_default")]}),C&&r.jsx(Ox,{className:"size-4 text-emerald-400"}),r.jsxs(me,{size:"sm",variant:"secondary",onClick:()=>m(N),"data-testid":`voice-provider-${N}-config`,children:[r.jsx(IM,{className:"size-3.5"})," ",f("voice_ui.configure")]})]})]},N)})})]})}function Oa(e){return typeof e=="string"?e:e==null?"":String(e)}function E7({open:e,providerId:t,config:s,onClose:o,onSave:l}){const[c,u]=x.useState(!1),[p,m]=x.useState(null),[g,h]=x.useState(""),[b,_]=x.useState({});if(x.useEffect(()=>{if(!e||!t)return;m(null),h("");const R=s||{};if(t==="piper"){const A=R;_({bin:Oa(A.bin),model:Oa(A.model),speaker:Oa(A.speaker)})}else if(t==="elevenlabs"){const A=R;_({model:Oa(A.model),voice_id:Oa(A.voice_id),output_format:Oa(A.output_format)})}else if(t==="openai"){const A=R;_({model:Oa(A.model)||"tts-1",voice:Oa(A.voice)||"alloy",format:Oa(A.format)||"mp3"})}else if(t==="gemini"){const A=R;_({model:Oa(A.model),voice:Oa(A.voice)||"Kore",style:Oa(A.style)})}else _({})},[e,t,s]),!t)return null;const k=pf[t],N=`voice.tts.${t}`,y=R=>_(A=>({...A,...R})),w=t!=="piper"&&t!=="mock",S=w&&oa(s?.api_key),C=S?f("voice_ui.api_key_set",{suffix:jo(s?.api_key)??""}):f("voice_ui.api_key_label"),E=async()=>{u(!0),m(null);try{const R={},A=[],T=(O,z)=>{z.trim()?R[`${N}.${O}`]=z.trim():A.push(`${N}.${O}`)};t==="piper"?(T("bin",b.bin),T("model",b.model),b.speaker.trim()?R[`${N}.speaker`]=b.speaker.trim():A.push(`${N}.speaker`)):t==="elevenlabs"?(T("model",b.model),T("voice_id",b.voice_id),T("output_format",b.output_format)):t==="openai"?(T("model",b.model),T("voice",b.voice),T("format",b.format)):t==="gemini"&&(T("model",b.model),T("voice",b.voice),T("style",b.style)),w&&g.trim()&&(R[`${N}.api_key`]=g.trim()),await l({set:R,unset:A}),o()}catch(R){m(R.message||f("voice_ui.err_save"))}finally{u(!1)}};return r.jsx(An,{open:e,onClose:o,title:f("voice_screen.configure_provider",{name:k?.name||t||""}),description:k?.note,size:"md",footer:r.jsxs(r.Fragment,{children:[r.jsx(me,{variant:"ghost",onClick:o,disabled:c,children:f("common.cancel")}),r.jsx(me,{variant:"primary",onClick:E,loading:c,"data-testid":"voice-provider-save",children:f("common.save")})]}),children:r.jsxs("div",{className:"space-y-3",children:[t==="piper"&&r.jsxs(r.Fragment,{children:[r.jsx(fe,{label:f("voice_ui.piper_bin_label"),hint:f("voice_ui.piper_bin_hint"),children:r.jsx(Ae,{value:b.bin,onChange:R=>y({bin:R.target.value}),placeholder:"piper"})}),r.jsx(fe,{label:f("voice_ui.piper_model_label"),hint:f("voice_ui.piper_model_hint"),children:r.jsx(Ae,{value:b.model,onChange:R=>y({model:R.target.value}),placeholder:"/abs/path/voice.onnx"})}),r.jsx(fe,{label:f("voice_ui.piper_speaker_label"),hint:f("voice_ui.piper_speaker_hint"),children:r.jsx(Ae,{value:b.speaker,onChange:R=>y({speaker:R.target.value}),placeholder:"0"})})]}),t==="elevenlabs"&&r.jsxs(r.Fragment,{children:[r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:S?f("voice_ui.api_key_keep_hint"):f("voice_ui.api_key_secret_hint",{env:"ELEVENLABS_API_KEY"}),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(fe,{label:f("voice_ui.model_label"),children:r.jsx(_t,{value:b.model||"",onChange:R=>y({model:R}),options:PD.map(R=>({value:R,label:R})),placeholder:"eleven_multilingual_v2"})}),r.jsx(fe,{label:f("voice_ui.voice_id_label"),hint:f("voice_ui.voice_id_hint"),children:r.jsx(Ae,{value:b.voice_id,onChange:R=>y({voice_id:R.target.value}),placeholder:"EXAVITQu4vr4xnSDxMaL"})}),r.jsx(fe,{label:f("voice_ui.output_format_label"),children:r.jsx(Ae,{value:b.output_format,onChange:R=>y({output_format:R.target.value}),placeholder:"mp3_44100_128"})})]}),t==="openai"&&r.jsxs(r.Fragment,{children:[r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:S?f("voice_ui.api_key_keep_hint"):f("voice_ui.api_key_reuse_hint",{engine:"engines.openai.api_key",env:"OPENAI_API_KEY"}),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(fe,{label:f("voice_ui.model_label"),children:r.jsx(_t,{value:b.model||"tts-1",onChange:R=>y({model:R}),options:LD.map(R=>({value:R,label:R}))})}),r.jsx(fe,{label:f("voice_ui.voice_label"),children:r.jsx(_t,{value:b.voice||"alloy",onChange:R=>y({voice:R}),options:zD.map(R=>({value:R,label:R}))})}),r.jsx(fe,{label:f("voice_ui.format_label"),children:r.jsx(_t,{value:b.format||"mp3",onChange:R=>y({format:R}),options:["mp3","opus","aac","flac","wav"].map(R=>({value:R,label:R}))})})]}),t==="gemini"&&r.jsxs(r.Fragment,{children:[r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:S?f("voice_ui.api_key_keep_hint"):f("voice_ui.api_key_reuse_hint",{engine:"engines.gemini.api_key",env:"GEMINI_API_KEY"}),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(fe,{label:f("voice_ui.model_label"),hint:f("voice_ui.gemini_model_hint"),children:r.jsx(Ae,{value:b.model,onChange:R=>y({model:R.target.value}),placeholder:"gemini-2.5-flash-preview-tts"})}),r.jsx(fe,{label:f("voice_ui.voice_label"),children:r.jsx(_t,{value:b.voice||"Kore",onChange:R=>y({voice:R}),options:DD.map(R=>({value:R,label:R}))})}),r.jsx(fe,{label:f("voice_ui.style_label"),hint:f("voice_ui.style_hint"),children:r.jsx(Un,{rows:2,value:b.style||"",onChange:R=>y({style:R.target.value}),placeholder:f("voice_ui.style_ph")})})]}),t==="mock"&&r.jsx("p",{className:"text-sm text-muted-fg",children:f("voice_ui.mock_desc")}),p&&r.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:p})]})})}function R7(){const e=x.useRef(null),t=x.useRef(null),[s,o]=x.useState(!1),[l,c]=x.useState(!1),u=x.useCallback(()=>{t.current&&(URL.revokeObjectURL(t.current),t.current=null)},[]);x.useEffect(()=>()=>{e.current&&(e.current.pause(),e.current=null),u()},[u]);const p=x.useCallback(async g=>{c(!0);try{u();const h=await BD(g);t.current=h,e.current||(e.current=new Audio);const b=e.current;b.src=h,b.onended=()=>o(!1),b.onerror=()=>o(!1),await b.play(),o(!0)}finally{c(!1)}},[u]),m=x.useCallback(()=>{e.current&&(e.current.pause(),e.current.currentTime=0),o(!1)},[]);return{play:p,stop:m,playing:s,loading:l}}function T7({engines:e,defaultProvider:t,mode:s}){const o=lt(),{play:l,stop:c,playing:u,loading:p}=R7(),[m,g]=x.useState(f("voice_ui.test_default_text")),[h,b]=x.useState(""),[_,k]=x.useState(""),[N,y]=x.useState(!1),[w,S]=x.useState(null),E=[{value:"",label:s==="single"&&t&&t!=="auto"?f("voice_ui.test_default_engine",{name:pf[t]?.name||t}):f("voice_ui.test_default_chain")},...e.map(A=>({value:A.id,label:`${pf[A.id]?.name||A.id}${A.available?"":f("voice_ui.test_unavailable_suffix")}`}))],R=async()=>{const A=m.trim();if(!A){o.error(f("voice_ui.test_empty_error"));return}y(!0);try{const T=await pC.say({text:A,provider:h||void 0,style:_.trim()||void 0});S(T),await l(T.audio_path)}catch(T){o.error(T.message||f("voice_ui.test_synth_error"))}finally{y(!1)}};return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("voice_ui.test_engine_label"),hint:f("voice_ui.test_engine_hint"),children:r.jsx(_t,{value:h,onChange:b,options:E})}),r.jsx(fe,{label:f("voice_ui.test_style_label"),hint:f("voice_ui.test_style_hint"),children:r.jsx(Ae,{value:_,onChange:A=>k(A.target.value),placeholder:f("voice_ui.style_ph"),"data-testid":"voice-test-style"})})]}),r.jsx(fe,{label:f("voice_ui.test_text_label"),children:r.jsx(Un,{rows:2,value:m,onChange:A=>g(A.target.value),placeholder:f("voice_ui.test_text_ph"),"data-testid":"voice-test-input"})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(me,{variant:"primary",onClick:R,loading:N,disabled:p,"data-testid":"voice-test-say",children:[r.jsx($M,{className:"size-4"})," ",f("voice_ui.say_this")]}),u?r.jsxs(me,{variant:"secondary",onClick:c,"data-testid":"voice-test-stop",children:[r.jsx(Fk,{className:"size-4"})," ",f("voice_ui.stop")]}):w?r.jsxs(me,{variant:"secondary",onClick:()=>l(w.audio_path),loading:p,"data-testid":"voice-test-replay",children:[r.jsx(Bx,{className:"size-4"})," ",f("voice_ui.replay")]}):null,w&&r.jsxs("span",{className:"text-xs text-muted-fg",children:[f("voice_ui.engine_result"),": ",r.jsx("strong",{children:w.provider}),w.duration_s?` · ${w.duration_s.toFixed(1)}s`:""]})]})]})}const A7=()=>[{value:"auto",label:f("voice_ui.stt_provider_auto")},{value:"local",label:f("voice_ui.stt_provider_local")},{value:"openai",label:f("voice_ui.stt_provider_openai")},{value:"custom",label:f("voice_ui.stt_provider_custom")}],Hw=()=>[{value:"auto",label:f("voice_ui.lang_auto")},{value:"es",label:f("voice_ui.lang_es")},{value:"en",label:f("voice_ui.lang_en")},{value:"pt",label:f("voice_ui.lang_pt")},{value:"fr",label:f("voice_ui.lang_fr")},{value:"it",label:f("voice_ui.lang_it")},{value:"de",label:f("voice_ui.lang_de")}];function M7({config:e,onPatch:t,busy:s}){const o=e.provider||"auto",l=e.local||{},c=e.openai||{},u=e.custom||{},p=l.model||"small",m=l.language||"auto",g=o==="auto"||o==="local",h=(k,N,y)=>{const w=y.trim();w!==(N||"").trim()&&t({[k]:w})},b=(k,N)=>{const y=N.trim();!y||oa(y)||t({[k]:y})},_=k=>oa(k)?f("voice_ui.api_key_set",{suffix:jo(k)??""}):f("voice_ui.api_key_label");return r.jsxs("div",{className:"space-y-3",children:[r.jsx(fe,{label:f("voice_ui.stt_engine_label"),hint:f("voice_ui.stt_engine_hint"),children:r.jsx(_t,{value:o,onChange:k=>t({"transcription.provider":k}),options:A7(),disabled:s,className:"max-w-md"})}),g&&r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("voice_ui.stt_model_label"),hint:f("voice_ui.stt_model_hint"),children:r.jsx(_t,{value:p,onChange:k=>t({"transcription.local.model":k}),options:ID.map(k=>({value:k,label:k})),disabled:s})}),r.jsx(fe,{label:f("voice_ui.stt_language_label"),hint:f("voice_ui.stt_language_hint"),children:r.jsx(_t,{value:m,onChange:k=>t({"transcription.local.language":k}),options:Hw(),disabled:s})})]}),o==="openai"&&r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:oa(c.api_key)?f("voice_ui.api_key_keep_hint"):f("voice_ui.api_key_reuse_hint",{engine:"engines.openai.api_key",env:"OPENAI_API_KEY"}),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",defaultValue:"",placeholder:_(c.api_key),onBlur:k=>b("transcription.openai.api_key",k.target.value),disabled:s})}),r.jsx(fe,{label:f("voice_ui.stt_openai_model_label"),hint:f("voice_ui.stt_openai_model_hint"),children:r.jsx(Ae,{defaultValue:c.model||"",placeholder:"whisper-1",onBlur:k=>h("transcription.openai.model",c.model,k.target.value),disabled:s})})]}),o==="custom"&&r.jsxs("div",{className:"space-y-3",children:[r.jsx(fe,{label:f("voice_ui.stt_custom_baseurl_label"),hint:f("voice_ui.stt_custom_baseurl_hint"),children:r.jsx(Ae,{defaultValue:u.base_url||"",placeholder:"http://localhost:8000/v1",onBlur:k=>h("transcription.custom.base_url",u.base_url,k.target.value),disabled:s})}),r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(fe,{label:f("voice_ui.stt_custom_model_label"),hint:f("voice_ui.stt_custom_model_hint"),children:r.jsx(Ae,{defaultValue:u.model||"",placeholder:"mlx-community/whisper-large-v3-turbo",onBlur:k=>h("transcription.custom.model",u.model,k.target.value),disabled:s})}),r.jsx(fe,{label:f("voice_ui.stt_language_label"),hint:f("voice_ui.stt_language_hint"),children:r.jsx(_t,{value:u.language||"auto",onChange:k=>t({"transcription.custom.language":k}),options:Hw(),disabled:s})})]}),r.jsx(fe,{label:f("voice_ui.api_key_label"),hint:f("voice_ui.stt_custom_key_hint"),children:r.jsx(Ae,{type:"password",autoComplete:"new-password",defaultValue:"",placeholder:_(u.api_key),onBlur:k=>b("transcription.custom.api_key",k.target.value),disabled:s})})]})]})}function O7(){const e=lt(),{config:t,isLoading:s,patch:o,mutate:l}=Vr(),{data:c,isLoading:u,error:p,mutate:m}=Qe("/tts/providers",()=>pC.providers()),[g,h]=x.useState(null),[b,_]=x.useState(!1),k=t,N=k.voice?.tts||{},y=k.transcription||{},w=c?.configured_provider||N.provider||"auto",S=c?.mode||N.mode||"chain",C=c?.engines||[],E=c?.order||[],R=x.useMemo(()=>g?N[g]||{}:{},[g,N]),A=async U=>{_(!0);try{await o({"voice.tts.provider":U,"voice.tts.mode":"single"}),await m(),e.success(f("voice_ui.toast_default_engine",{id:U}))}catch(I){e.error(I.message)}finally{_(!1)}},T=async U=>{_(!0);try{const I={"voice.tts.mode":U};if(U==="single"&&(w==="auto"||!w)){const V=C.find(H=>H.available)?.id||E[0]||"mock";I["voice.tts.provider"]=V}await o(I),await m(),e.success(f(U==="chain"?"voice_ui.toast_mode_chain":"voice_ui.toast_mode_single"))}catch(I){e.error(I.message)}finally{_(!1)}},O=async(U,I)=>{_(!0);try{await o({[`voice.tts.${U}.enabled`]:I}),await m()}catch(V){e.error(V.message)}finally{_(!1)}},z=async U=>{_(!0);try{await o({"voice.tts.order":U}),await m()}catch(I){e.error(I.message)}finally{_(!1)}},L=async({set:U,unset:I})=>{await o(U,I.length?I:void 0),await m(),await l(),e.success(f("voice_ui.toast_config_saved"))},D=async(U,I)=>{try{await o(U,I),e.success(f("voice_ui.toast_transcription_updated"))}catch(V){e.error(V.message)}};return r.jsxs("div",{"data-testid":"screen-voice",children:[r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[r.jsx(Ye,{title:f("voice_screen.providers_title"),description:f("voice_ui.providers_desc"),children:u||s?r.jsx(ot,{}):p?r.jsx(xt,{children:f("voice_ui.providers_load_error",{msg:p.message})}):r.jsx(N7,{engines:C,order:E,mode:S,configuredProvider:w,onSetMode:T,onSetDefault:A,onToggleEnabled:O,onReorder:z,onConfigure:U=>h(U),busy:b})}),r.jsxs("div",{className:"space-y-6",children:[r.jsx(Ye,{title:f("voice_screen.test_title"),description:f("voice_ui.test_desc"),children:r.jsx(T7,{engines:C,defaultProvider:w,mode:S})}),r.jsx(Ye,{title:f("voice_screen.stt_title"),description:f("voice_ui.stt_desc"),children:s?r.jsx(ot,{}):r.jsx(M7,{config:y,onPatch:D})})]})]}),r.jsx(E7,{open:!!g,providerId:g,config:R,onClose:()=>h(null),onSave:L})]})}function z7(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function D7({manifest:e}){const t=e.daemon,s=e.safety;return r.jsxs("div",{"data-testid":"deck-daemon-card",className:"rounded-xl border border-border bg-muted/10 px-4 py-3 text-xs",children:[r.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-2",children:[r.jsxs("span",{className:"font-semibold text-foreground",children:[t.name," ",r.jsxs("span",{className:"font-normal text-muted-fg",children:["v",t.version]})]}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"size-2 rounded-full bg-emerald-500"}),r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.deck_daemon_active",{uptime:z7(t.uptime_s)})})]})]}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsxs("span",{className:"text-muted-fg",children:[t.host,":",t.port]}),r.jsx("span",{className:"text-muted-fg",children:"·"}),r.jsxs("span",{className:"text-muted-fg",children:[f("modules_ui.deck_daemon_started")," ",new Date(t.started_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]}),r.jsxs("div",{className:"mt-2.5 flex flex-wrap gap-1.5",children:[s.direct_shell===!1&&r.jsx(Fe,{tone:"success",children:f("modules_ui.deck_safety_no_shell")}),s.arbitrary_commands===!1&&r.jsx(Fe,{tone:"success",children:f("modules_ui.deck_safety_no_arbitrary")}),s.dangerous_actions_require_confirmation&&r.jsx(Fe,{tone:"info",children:f("modules_ui.deck_safety_confirm")})]})]})}function P7(e){return e==="available"?"success":e==="configured"?"info":"muted"}function L7(e){return e==="available"?"activo":e==="configured"?"configurado":e==="disabled"?"deshabilitado":"sin configurar"}function I7(e){return e==="voice"?"warning":e==="plugin"?"info":"muted"}function B7({widget:e,onToggle:t}){const s=e.source==="external",[o,l]=x.useState(!1),c=e.user_enabled===!0,u=async p=>{if(!(!t||o)){l(!0);try{await t(p)}finally{l(!1)}}};return r.jsxs("li",{"data-testid":`deck-widget-${e.id}`,className:ze("flex items-center gap-3 rounded-lg border px-3 py-2.5 text-sm transition-colors",s?"border-border bg-muted/20 hover:border-muted-fg/30":"border-border/50 bg-muted/10"),children:[r.jsx(et,{content:e.source==="apx"?f("deck_screen.widget_native"):f("deck_screen.widget_external"),children:r.jsx("span",{className:ze("size-2 shrink-0 rounded-full",e.source==="apx"?"bg-emerald-500":"bg-sky-400")})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"font-medium",children:e.title}),r.jsx("span",{className:"ml-2 text-xs text-muted-fg",children:e.desktop})]}),r.jsx(Fe,{tone:I7(e.kind),children:e.kind}),r.jsx(Fe,{tone:P7(e.status),children:L7(e.status)}),s?r.jsx("span",{"data-testid":`deck-widget-toggle-${e.id}`,children:r.jsx(Qt,{checked:c,onChange:u,disabled:o||!t})}):r.jsx("span",{className:"w-9 shrink-0","aria-hidden":!0})]})}function U7({desktop:e,widgets:t,onToggle:s}){return t.length===0?null:r.jsxs("div",{"data-testid":`deck-desktop-${e.id}`,className:"space-y-1.5",children:[r.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-fg",children:e.title}),r.jsx("ul",{className:"space-y-1.5",children:t.map(o=>r.jsx(B7,{widget:o,onToggle:o.source==="external"?l=>s(o.id,l):void 0},o.id))})]})}function H7(){lt();const{data:e,error:t,isLoading:s,mutate:o}=Qe("/deck/manifest",()=>UD.manifest(),{refreshInterval:3e4}),l=async(h,b)=>{},c=e?.deck.desktops??[],u=e?.deck.widgets??[],p=c.map(h=>({desktop:h,widgets:u.filter(b=>b.desktop===h.id)})),g=u.filter(h=>h.source==="external").filter(h=>h.user_enabled===!0).length;return r.jsxs("div",{className:"relative min-h-full","data-testid":"screen-deck",children:[r.jsxs("div",{className:"mx-auto max-w-4xl space-y-6 p-6 pointer-events-none select-none blur-[2px] opacity-60","aria-hidden":!0,inert:!0,children:[e&&r.jsx(D7,{manifest:e}),r.jsxs(Ye,{title:f("deck_screen.widgets_title"),description:s?f("modules_ui.deck_loading_manifest"):t?f("modules_ui.deck_manifest_error"):f("modules_ui.deck_widgets_summary",{count:u.length,enabled:g}),action:r.jsx(et,{content:f("deck_screen.reload_manifest"),children:r.jsx(me,{size:"sm",variant:"ghost",onClick:()=>o(),disabled:s,"aria-label":f("deck_screen.reload_manifest"),children:r.jsx(cs,{size:14,className:s?"animate-spin":""})})}),children:[s&&r.jsx(ot,{label:f("modules_ui.deck_loading_manifest_full")}),!s&&t&&r.jsxs(xt,{children:[f("modules_ui.deck_manifest_load_failed")," ",r.jsx("button",{type:"button",className:"ml-1 underline",onClick:()=>o(),children:f("modules_ui.deck_retry")})]}),!s&&!t&&u.length===0&&r.jsx(xt,{children:f("modules_ui.deck_no_widgets")}),!s&&!t&&u.length>0&&r.jsx("div",{className:"space-y-5","data-testid":"deck-desktop-list",children:p.filter(h=>h.widgets.length>0).map(h=>r.jsx(U7,{desktop:h.desktop,widgets:h.widgets,onToggle:l},h.desktop.id))})]}),e?.apx&&r.jsx(Ye,{title:f("deck_screen.context_title"),description:f("modules_ui.deck_context_desc"),children:r.jsxs("div",{className:"space-y-2 text-sm","data-testid":"deck-apx-context",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.deck_active_project")}),r.jsx("span",{className:"font-medium",children:e.apx.active_project?e.apx.active_project.name:f("modules_ui.deck_none")})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.deck_registered_projects")}),r.jsx("span",{className:"font-medium",children:e.apx.projects.length})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-muted-fg",children:f("modules_ui.deck_active_plugins")}),r.jsx("span",{className:"font-medium",children:Object.keys(e.apx.plugins).join(", ")||"—"})]})]})})]}),r.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center p-6 backdrop-blur-[1px]",role:"dialog","aria-modal":"true","aria-labelledby":"deck-coming-soon-title","data-testid":"deck-coming-soon",children:r.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-border bg-card/95 p-8 text-center shadow-2xl",children:[r.jsx("div",{className:"mx-auto mb-4 flex size-12 items-center justify-center rounded-full bg-muted",children:r.jsx(lM,{className:"size-6 text-muted-fg"})}),r.jsx("span",{className:"inline-block rounded-full bg-muted px-2.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-muted-fg",children:f("deck_screen.preview_badge")}),r.jsx("h2",{id:"deck-coming-soon-title",className:"mt-3 text-lg font-semibold",children:f("deck_screen.preview_title")}),r.jsx("p",{className:"mt-2 text-sm text-muted-fg",children:f("deck_screen.preview_body")})]})})]})}const V7=[{title:f("settings.account_section"),items:[{key:"identity",label:f("settings.tabs.identity"),icon:Hx},{key:"appearance",label:f("settings.appearance"),icon:zM}]},{title:f("settings.agents_section"),items:[{key:"super_agent",label:f("settings.tabs.super_agent"),icon:hn},{key:"engines",label:f("settings.tabs.engines"),icon:zx},{key:"memory",label:"Memory (RAG)",icon:Lk},{key:"skills",label:"Skills (RAG)",icon:fs}]},{title:f("settings.channels_section"),items:[{key:"telegram",label:f("settings.tabs.telegram"),icon:Fa},{key:"devices",label:f("settings.tabs.devices"),icon:BM}]},{title:f("settings.modules_section"),items:[{key:"voice",label:f("nav.modules.voice"),icon:Vk},{key:"deck",label:f("nav.modules.deck"),icon:RM},{key:"desktop",label:f("nav.modules.desktop"),icon:Ix}]},{title:f("settings.advanced_section"),items:[{key:"advanced",label:f("settings.tabs.advanced"),icon:Xd}]}],q7=new Set(["engines","telegram","memory","skills","appearance","voice"]),$7={identity:()=>r.jsx(C8,{}),super_agent:()=>r.jsx(N8,{}),engines:()=>r.jsx(JC,{}),memory:()=>r.jsx(T8,{}),skills:()=>r.jsx(M8,{}),telegram:()=>r.jsx(L8,{}),devices:()=>r.jsx(d7,{}),voice:()=>r.jsx(O7,{}),deck:()=>r.jsx(H7,{}),desktop:()=>r.jsx(C7,{}),appearance:()=>r.jsx(g7,{}),advanced:()=>r.jsx(m7,{})};function F7(){const e=Qn(),t=Kn(),s=G7(t.pathname),o=$7[s],{collapsed:l,toggle:c}=Ib(Rn.sidebarCollapsed+".settings");return r.jsx(LC,{sections:V7,active:s,onChange:u=>e(u==="identity"?"/settings":`/settings/${Y7(u)}`),collapsed:l,onToggleCollapse:c,contentClassName:`w-full ${q7.has(s)?"":"mx-auto max-w-3xl"} space-y-6 p-6 pt-3`,testId:`settings-tab-${s}`,children:r.jsx(o,{})})}function G7(e){switch(e.split("/").filter(Boolean)[1]||"identity"){case"super-agent":return"super_agent";case"engines":return"engines";case"memory":return"memory";case"skills":return"skills";case"telegram":return"telegram";case"devices":return"devices";case"voice":return"voice";case"deck":return"deck";case"desktop":return"desktop";case"appearance":return"appearance";case"config":case"advanced":return"advanced";default:return"identity"}}function Y7(e){return e==="super_agent"?"super-agent":e==="advanced"?"config":e}function X7(){const{data:e,isLoading:t,mutate:s}=Qe("/messages/global?channel=desktop",()=>j7(40),{refreshInterval:8e3});return r.jsx("div",{className:"mx-auto max-w-3xl space-y-6 p-6","data-testid":"screen-desktop",children:r.jsxs("div",{className:"space-y-6",children:[r.jsx("div",{children:r.jsx(RN,{showConfigLink:!0})}),r.jsx("div",{children:r.jsx(Ye,{title:f("desktop_screen.last_conv_title"),description:f("modules_ui.desktop_last_conv_desc"),action:r.jsx("button",{type:"button",onClick:()=>s(),className:"text-xs text-muted-fg underline-offset-2 hover:underline",children:f("modules_ui.desktop_refresh")}),children:r.jsx(K7,{messages:e||[],loading:t})})})]})})}function K7({messages:e,loading:t}){const s=x.useMemo(()=>Z7(e),[e]);return t?r.jsx(ot,{}):e.length?r.jsx("div",{className:"space-y-3 max-h-[560px] overflow-y-auto pr-1",children:s.slice().reverse().map((o,l)=>r.jsx("div",{className:"rounded-lg border border-border bg-card/40 p-3",children:o.map((c,u)=>r.jsx(Q7,{m:c},u))},l))}):r.jsx(xt,{children:f("modules_ui.desktop_no_messages")})}function Q7({m:e}){const t=e.direction==="in",s=W7(e.ts);return r.jsxs("div",{className:"py-1",children:[r.jsxs("div",{className:"flex items-baseline gap-2 text-[11px] text-muted-fg",children:[r.jsx("span",{className:"font-semibold",children:f(t?"modules_ui.desktop_you":"modules_ui.desktop_roby")}),r.jsx("span",{children:s})]}),r.jsx("div",{className:"mt-0.5 text-sm leading-snug whitespace-pre-wrap "+(t?"text-muted-fg":"text-fg"),children:(e.body||"").trim()||r.jsx("span",{className:"italic opacity-50",children:f("modules_ui.desktop_empty_msg")})})]})}function Z7(e){const t=[];for(const s of e)s.direction==="in"||!t.length?t.push([s]):t[t.length-1].push(s);return t}function W7(e){try{const t=new Date(e);return t.toDateString()===new Date().toDateString()?t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):t.toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return""}}function J7(e,t){const s=getComputedStyle(e),o=parseFloat(s.fontSize);return t*o}function eB(e,t){const s=getComputedStyle(e.ownerDocument.documentElement),o=parseFloat(s.fontSize);return t*o}function tB(e){return e/100*window.innerHeight}function nB(e){return e/100*window.innerWidth}function aB(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function xc({groupSize:e,panelElement:t,styleProp:s}){let o;const[l,c]=aB(s);switch(c){case"%":{o=l/100*e;break}case"px":{o=l;break}case"rem":{o=eB(t,l);break}case"em":{o=J7(t,l);break}case"vh":{o=tB(l);break}case"vw":{o=nB(l);break}}return o}function Yn(e){return parseFloat(e.toFixed(3))}function Gl({group:e}){const{orientation:t,panels:s}=e;return s.reduce((o,l)=>(o+=t==="horizontal"?l.element.offsetWidth:l.element.offsetHeight,o),0)}function yx(e){const{panels:t}=e,s=Gl({group:e});return s===0?t.map(o=>({groupResizeBehavior:o.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:o.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:o.panelConstraints.disabled,minSize:0,maxSize:100,panelId:o.id})):t.map(o=>{const{element:l,panelConstraints:c}=o;let u=0;if(c.collapsedSize!==void 0){const h=xc({groupSize:s,panelElement:l,styleProp:c.collapsedSize});u=Yn(h/s*100)}let p;if(c.defaultSize!==void 0){const h=xc({groupSize:s,panelElement:l,styleProp:c.defaultSize});p=Yn(h/s*100)}let m=0;if(c.minSize!==void 0){const h=xc({groupSize:s,panelElement:l,styleProp:c.minSize});m=Yn(h/s*100)}let g=100;if(c.maxSize!==void 0){const h=xc({groupSize:s,panelElement:l,styleProp:c.maxSize});g=Yn(h/s*100)}return{groupResizeBehavior:c.groupResizeBehavior,collapsedSize:u,collapsible:c.collapsible===!0,defaultSize:p,disabled:c.disabled,minSize:m,maxSize:g,panelId:o.id}})}function Bt(e,t="Assertion error"){if(!e)throw Error(t)}function jx(e,t){return Array.from(t).sort(e==="horizontal"?sB:rB)}function sB(e,t){const s=e.element.offsetLeft-t.element.offsetLeft;return s!==0?s:e.element.offsetWidth-t.element.offsetWidth}function rB(e,t){const s=e.element.offsetTop-t.element.offsetTop;return s!==0?s:e.element.offsetHeight-t.element.offsetHeight}function TN(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function AN(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function oB({orientation:e,rects:t,targetRect:s}){const o={x:s.x+s.width/2,y:s.y+s.height/2};let l,c=Number.MAX_VALUE;for(const u of t){const{x:p,y:m}=AN(o,u),g=e==="horizontal"?p:m;g<c&&(c=g,l=u)}return Bt(l,"No rect found"),l}let Ad;function lB(){return Ad===void 0&&(typeof matchMedia=="function"?Ad=!!matchMedia("(pointer:coarse)").matches:Ad=!1),Ad}function MN(e){const{element:t,orientation:s,panels:o,separators:l}=e,c=jx(s,Array.from(t.children).filter(TN).map(N=>({element:N}))).map(({element:N})=>N),u=[];let p=!1,m=!1,g=-1,h=-1,b=0,_,k=[];{let N=-1;for(const y of c)y.hasAttribute("data-panel")&&(N++,y.hasAttribute("data-disabled")||(b++,g===-1&&(g=N),h=N))}if(b>1){let N=-1;for(const y of c)if(y.hasAttribute("data-panel")){N++;const w=o.find(S=>S.element===y);if(w){if(_){const S=_.element.getBoundingClientRect(),C=y.getBoundingClientRect();let E;if(m){const R=s==="horizontal"?new DOMRect(S.right,S.top,0,S.height):new DOMRect(S.left,S.bottom,S.width,0),A=s==="horizontal"?new DOMRect(C.left,C.top,0,C.height):new DOMRect(C.left,C.top,C.width,0);switch(k.length){case 0:{E=[R,A];break}case 1:{const T=k[0],O=oB({orientation:s,rects:[S,C],targetRect:T.element.getBoundingClientRect()});E=[T,O===S?A:R];break}default:{E=k;break}}}else k.length?E=k:E=[s==="horizontal"?new DOMRect(S.right,C.top,C.left-S.right,C.height):new DOMRect(C.left,S.bottom,C.width,C.top-S.bottom)];for(const R of E){let A="width"in R?R:R.element.getBoundingClientRect();const T=lB()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(A.width<T){const z=T-A.width;A=new DOMRect(A.x-z/2,A.y,A.width+z,A.height)}if(A.height<T){const z=T-A.height;A=new DOMRect(A.x,A.y-z/2,A.width,A.height+z)}const O=N<=g||N>h;!p&&!O&&u.push({group:e,groupSize:Gl({group:e}),panels:[_,w],separator:"width"in R?void 0:R,rect:A}),p=!1}}m=!1,_=w,k=[]}}else if(y.hasAttribute("data-separator")){y.ariaDisabled!==null&&(p=!0);const w=l.find(S=>S.element===y);w?k.push(w):(_=void 0,k=[])}else m=!0}return u}class ON{#e={};addListener(t,s){const o=this.#e[t];return o===void 0?this.#e[t]=[s]:o.includes(s)||o.push(s),()=>{this.removeListener(t,s)}}emit(t,s){const o=this.#e[t];if(o!==void 0)if(o.length===1)o[0].call(null,s);else{let l=!1,c=null;const u=Array.from(o);for(let p=0;p<u.length;p++){const m=u[p];try{m.call(null,s)}catch(g){c===null&&(l=!0,c=g)}}if(l)throw c}}removeAllListeners(){this.#e={}}removeListener(t,s){const o=this.#e[t];if(o!==void 0){const l=o.indexOf(s);l>=0&&o.splice(l,1)}}}let ss=new Map;const zN=new ON;function iB(e){ss=new Map(ss),ss.delete(e)}function Vw(e,t){for(const[s]of ss)if(s.id===e)return s}function Ar(e,t){for(const[s,o]of ss)if(s.id===e)return o;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Oo(){return ss}function gv(e,t){return zN.addListener("groupChange",s=>{s.group.id===e&&t(s)})}function Qs(e,t,s){const o=ss.get(e);ss=new Map(ss),ss.set(e,t),zN.emit("groupChange",{group:e,isUserInteraction:s?.isUserInteraction===!0,prev:o,next:t})}function cB(e,t,s){let o,l={x:1/0,y:1/0};for(const c of t){const u=AN(s,c.rect);switch(e){case"horizontal":{u.x<=l.x&&(o=c,l=u);break}case"vertical":{u.y<=l.y&&(o=c,l=u);break}}}return o?{distance:l,hitRegion:o}:void 0}function uB(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function dB(e,t){if(e===t)throw new Error("Cannot compare node with itself");const s={a:Fw(e),b:Fw(t)};let o;for(;s.a.at(-1)===s.b.at(-1);)o=s.a.pop(),s.b.pop();Bt(o,"Stacking order can only be calculated for elements with a common ancestor");const l={a:$w(qw(s.a)),b:$w(qw(s.b))};if(l.a===l.b){const c=o.childNodes,u={a:s.a.at(-1),b:s.b.at(-1)};let p=c.length;for(;p--;){const m=c[p];if(m===u.a)return 1;if(m===u.b)return-1}}return Math.sign(l.a-l.b)}const fB=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function pB(e){const t=getComputedStyle(DN(e)??e).display;return t==="flex"||t==="inline-flex"}function mB(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||pB(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||fB.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function qw(e){let t=e.length;for(;t--;){const s=e[t];if(Bt(s,"Missing node"),mB(s))return s}return null}function $w(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Fw(e){const t=[];for(;e;)t.push(e),e=DN(e);return t}function DN(e){const{parentNode:t}=e;return uB(t)?t.host:t}function gB(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function hB({groupElement:e,hitRegion:t,pointerEventTarget:s}){if(!TN(s)||s.contains(e)||e.contains(s))return!0;if(dB(s,e)>0){let o=s;for(;o;){if(o.contains(e))return!0;if(gB(o.getBoundingClientRect(),t))return!1;o=o.parentElement}}return!0}function hv(e,t){const s=[];return t.forEach((o,l)=>{if(l.disabled)return;const c=MN(l),u=cB(l.orientation,c,{x:e.clientX,y:e.clientY});u&&u.distance.x<=0&&u.distance.y<=0&&hB({groupElement:l.element,hitRegion:u.hitRegion.rect,pointerEventTarget:e.target})&&s.push(u.hitRegion)}),s}function xB(e,t){if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(e[s]!=t[s])return!1;return!0}function qn(e,t,s=0){return Math.abs(Yn(e)-Yn(t))<=s}function es(e,t){return qn(e,t)?0:e>t?1:-1}function kl({overrideDisabledPanels:e,panelConstraints:t,prevSize:s,size:o}){const{collapsedSize:l=0,collapsible:c,disabled:u,maxSize:p=100,minSize:m=0}=t;if(u&&!e)return s;if(es(o,m)<0)if(c){const g=(l+m)/2;es(o,g)<0?o=l:o=m}else o=m;return o=Math.min(p,o),o=Yn(o),o}function Dc({delta:e,initialLayout:t,panelConstraints:s,pivotIndices:o,prevLayout:l,trigger:c}){if(qn(e,0))return t;const u=c==="imperative-api",p=Object.values(t),m=Object.values(l),g=[...p],[h,b]=o;Bt(h!=null,"Invalid first pivot index"),Bt(b!=null,"Invalid second pivot index");let _=0;switch(c){case"keyboard":{{const y=e<0?b:h,w=s[y];Bt(w,`Panel constraints not found for index ${y}`);const{collapsedSize:S=0,collapsible:C,minSize:E=0}=w;if(C){const R=p[y];if(Bt(R!=null,`Previous layout not found for panel index ${y}`),qn(R,S)){const A=E-R;es(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}{const y=e<0?h:b,w=s[y];Bt(w,`No panel constraints found for index ${y}`);const{collapsedSize:S=0,collapsible:C,minSize:E=0}=w;if(C){const R=p[y];if(Bt(R!=null,`Previous layout not found for panel index ${y}`),qn(R,E)){const A=R-S;es(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}break}default:{const y=e<0?b:h,w=s[y];Bt(w,`Panel constraints not found for index ${y}`);const S=p[y],{collapsible:C,collapsedSize:E,minSize:R}=w;if(C&&es(S,R)<0)if(e>0){const A=R-E,T=A/2,O=S+e;es(O,R)<0&&(e=es(e,T)<=0?0:A)}else{const A=R-E,T=100-A/2,O=S-e;es(O,R)<0&&(e=es(100+e,T)>0?0:-A)}break}}{const y=e<0?1:-1;let w=e<0?b:h,S=0;for(;;){const E=p[w];Bt(E!=null,`Previous layout not found for panel index ${w}`);const R=kl({overrideDisabledPanels:u,panelConstraints:s[w],prevSize:E,size:100})-E;if(S+=R,w+=y,w<0||w>=s.length)break}const C=Math.min(Math.abs(e),Math.abs(S));e=e<0?0-C:C}{let y=e<0?h:b;for(;y>=0&&y<s.length;){const w=Math.abs(e)-Math.abs(_),S=p[y];Bt(S!=null,`Previous layout not found for panel index ${y}`);const C=S-w,E=kl({overrideDisabledPanels:u,panelConstraints:s[y],prevSize:S,size:C});if(!qn(S,E)&&(_+=S-E,g[y]=E,_.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?y--:y++}}if(xB(m,g))return l;{const y=e<0?b:h,w=p[y];Bt(w!=null,`Previous layout not found for panel index ${y}`);const S=w+_,C=kl({overrideDisabledPanels:u,panelConstraints:s[y],prevSize:w,size:S});if(g[y]=C,!qn(C,S)){let E=S-C,R=e<0?b:h;for(;R>=0&&R<s.length;){const A=g[R];Bt(A!=null,`Previous layout not found for panel index ${R}`);const T=A+E,O=kl({overrideDisabledPanels:u,panelConstraints:s[R],prevSize:A,size:T});if(qn(A,O)||(E-=O-A,g[R]=O),qn(E,0))break;e>0?R--:R++}}}const k=Object.values(g).reduce((y,w)=>w+y,0);if(!qn(k,100,.1))return l;const N=Object.keys(l);return g.reduce((y,w,S)=>(y[N[S]]=w,y),{})}function So(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const s in e)if(t[s]===void 0||es(e[s],t[s])!==0)return!1;return!0}function Co({layout:e,panelConstraints:t}){const s=Object.values(e),o=[...s],l=o.reduce((p,m)=>p+m,0);if(o.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${o.map(p=>`${p}%`).join(", ")}`);if(!qn(l,100)&&o.length>0)for(let p=0;p<t.length;p++){const m=o[p];Bt(m!=null,`No layout data found for index ${p}`);const g=100/l*m;o[p]=g}let c=0;for(let p=0;p<t.length;p++){const m=s[p];Bt(m!=null,`No layout data found for index ${p}`);const g=o[p];Bt(g!=null,`No layout data found for index ${p}`);const h=kl({overrideDisabledPanels:!0,panelConstraints:t[p],prevSize:m,size:g});g!=h&&(c+=g-h,o[p]=h)}if(!qn(c,0))for(let p=0;p<t.length;p++){const m=o[p];Bt(m!=null,`No layout data found for index ${p}`);const g=m+c,h=kl({overrideDisabledPanels:!0,panelConstraints:t[p],prevSize:m,size:g});if(m!==h&&(c-=h-m,o[p]=h,qn(c,0)))break}const u=Object.keys(e);return o.reduce((p,m,g)=>(p[u[g]]=m,p),{})}function PN({groupId:e,panelId:t}){const s=()=>{const m=Oo();for(const[g,{defaultLayoutDeferred:h,derivedPanelConstraints:b,layout:_,groupSize:k,separatorToPanels:N}]of m)if(g.id===e)return{defaultLayoutDeferred:h,derivedPanelConstraints:b,group:g,groupSize:k,layout:_,separatorToPanels:N};throw Error(`Group ${e} not found`)},o=()=>{const m=s().derivedPanelConstraints.find(g=>g.panelId===t);if(m!==void 0)return m;throw Error(`Panel constraints not found for Panel ${t}`)},l=()=>{const m=s().group.panels.find(g=>g.id===t);if(m!==void 0)return m;throw Error(`Layout not found for Panel ${t}`)},c=()=>{const m=s().layout[t];if(m!==void 0)return m;throw Error(`Layout not found for Panel ${t}`)},u=({nextSize:m,panels:g,prevLayout:h,derivedPanelConstraints:b})=>{const _=c(),k=g.findIndex(w=>w.id===t),N=k===0,y=k===g.length-1;if(y&&m<_&&(N||g.slice(0,k).every((w,S)=>{const C=b[S];return C?.collapsible&&qn(C.collapsedSize,h[C.panelId])}))){const w=g.slice(0,k).reduce((S,C)=>S+h[C.id],0);return{...h,[t]:Yn(100-w)}}return Dc({delta:y?_-m:m-_,initialLayout:h,panelConstraints:b,pivotIndices:y?[k-1,k]:[k,k+1],prevLayout:h,trigger:"imperative-api"})},p=m=>{const g=c();if(m===g)return;const{defaultLayoutDeferred:h,derivedPanelConstraints:b,group:_,groupSize:k,layout:N,separatorToPanels:y}=s(),w=u({nextSize:m,panels:_.panels,prevLayout:N,derivedPanelConstraints:b}),S=Co({layout:w,panelConstraints:b});So(N,S)||Qs(_,{defaultLayoutDeferred:h,derivedPanelConstraints:b,groupSize:k,layout:S,separatorToPanels:y})};return{collapse:()=>{const{collapsible:m,collapsedSize:g}=o(),{mutableValues:h}=l(),b=c();m&&b!==g&&(h.expandToSize=b,p(g))},expand:()=>{const{collapsible:m,collapsedSize:g,minSize:h}=o(),{mutableValues:b}=l(),_=c();if(m&&_===g){let k=b.expandToSize??h;k===0&&(k=1),p(k)}},getSize:()=>{const{group:m}=s(),g=c(),{element:h}=l(),b=m.orientation==="horizontal"?h.offsetWidth:h.offsetHeight;return{asPercentage:g,inPixels:b}},isCollapsed:()=>{const{collapsible:m,collapsedSize:g}=o(),h=c();return m&&qn(g,h)},resize:m=>{const{group:g}=s(),{element:h}=l(),b=Gl({group:g}),_=xc({groupSize:b,panelElement:h,styleProp:m}),k=Yn(_/b*100);p(k)}}}function Gw(e){if(e.defaultPrevented)return;const t=Oo();hv(e,t).forEach(s=>{if(s.separator&&!s.separator.disableDoubleClick){const o=s.panels.find(l=>l.panelConstraints.defaultSize!==void 0);if(o){const l=o.panelConstraints.defaultSize,c=PN({groupId:s.group.id,panelId:o.id});c&&l!==void 0&&(c.resize(l),e.preventDefault())}}})}function Hd(e){const t=Oo();for(const[s]of t)if(s.separators.some(o=>o.element===e))return s;throw Error("Could not find parent Group for separator element")}function LN({groupId:e}){const t=()=>{const s=Oo();for(const[o,l]of s)if(o.id===e)return{group:o,...l};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:s,layout:o}=t();return s?{}:o},setLayout(s){const{defaultLayoutDeferred:o,derivedPanelConstraints:l,group:c,groupSize:u,layout:p,separatorToPanels:m}=t(),g=Co({layout:s,panelConstraints:l});return o?p:(So(p,g)||Qs(c,{defaultLayoutDeferred:o,derivedPanelConstraints:l,groupSize:u,layout:g,separatorToPanels:m}),g)}}}function io(e,t){const s=Hd(e),o=Ar(s.id,!0),l=s.separators.find(h=>h.element===e);Bt(l,"Matching separator not found");const c=o.separatorToPanels.get(l);Bt(c,"Matching panels not found");const u=c.map(h=>s.panels.indexOf(h)),p=LN({groupId:s.id}).getLayout(),m=Dc({delta:t,initialLayout:p,panelConstraints:o.derivedPanelConstraints,pivotIndices:u,prevLayout:p,trigger:"keyboard"}),g=Co({layout:m,panelConstraints:o.derivedPanelConstraints});So(p,g)||Qs(s,{defaultLayoutDeferred:o.defaultLayoutDeferred,derivedPanelConstraints:o.derivedPanelConstraints,groupSize:o.groupSize,layout:g,separatorToPanels:o.separatorToPanels},{isUserInteraction:!0})}function Yw(e){if(e.defaultPrevented)return;const t=e.currentTarget,s=Hd(t);if(!s.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),s.orientation==="vertical"&&io(t,5);break}case"ArrowLeft":{e.preventDefault(),s.orientation==="horizontal"&&io(t,-5);break}case"ArrowRight":{e.preventDefault(),s.orientation==="horizontal"&&io(t,5);break}case"ArrowUp":{e.preventDefault(),s.orientation==="vertical"&&io(t,-5);break}case"End":{e.preventDefault(),io(t,100);break}case"Enter":{e.preventDefault();const o=Hd(t),l=Ar(o.id,!0),{derivedPanelConstraints:c,layout:u,separatorToPanels:p}=l,m=o.separators.find(_=>_.element===t);Bt(m,"Matching separator not found");const g=p.get(m);Bt(g,"Matching panels not found");const h=g[0],b=c.find(_=>_.panelId===h.id);if(Bt(b,"Panel metadata not found"),b.collapsible){const _=u[h.id],k=b.collapsedSize===_?o.mutableState.expandedPanelSizes[h.id]??b.minSize:b.collapsedSize;io(t,k-_)}break}case"F6":{e.preventDefault();const o=Hd(t).separators.map(u=>u.element),l=Array.from(o).findIndex(u=>u===e.currentTarget);Bt(l!==null,"Index not found");const c=e.shiftKey?l>0?l-1:o.length-1:l+1<o.length?l+1:0;o[c].focus({preventScroll:!0});break}case"Home":{e.preventDefault(),io(t,-100);break}}}let Ml={cursorFlags:0,state:"inactive"};const xv=new ON;function No(){return Ml}function bB(e){return xv.addListener("change",e)}function vB(e){const t=Ml,s={...Ml};s.cursorFlags=e,Ml=s,xv.emit("change",{prev:t,next:s})}function Ol(e){const t=Ml;Ml=e,xv.emit("change",{prev:t,next:e})}function Xw(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Oo(),s=hv(e,t),o=new Map;let l=!1;s.forEach(c=>{c.separator&&(l||(l=!0,c.separator.element.focus({focusVisible:!1,preventScroll:!0})));const u=t.get(c.group);u&&o.set(c.group,u.layout)}),Ol({cursorFlags:0,hitRegions:s,initialLayoutMap:o,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),s.length&&e.preventDefault()}const _B=e=>e,Th=()=>{},IN=1,BN=2,UN=4,HN=8,Kw=3,Qw=12;let Md;function Zw(){return Md===void 0&&(Md=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Md=!0)),Md}function yB({cursorFlags:e,groups:t,state:s}){let o=0,l=0;switch(s){case"active":case"hover":t.forEach(c=>{if(!c.mutableState.disableCursor)switch(c.orientation){case"horizontal":{o++;break}case"vertical":{l++;break}}})}if(!(o===0&&l===0)){switch(s){case"active":{if(e&&Zw()){const c=(e&IN)!==0,u=(e&BN)!==0,p=(e&UN)!==0,m=(e&HN)!==0;if(c)return p?"se-resize":m?"ne-resize":"e-resize";if(u)return p?"sw-resize":m?"nw-resize":"w-resize";if(p)return"s-resize";if(m)return"n-resize"}break}}return Zw()?o>0&&l>0?"move":o>0?"ew-resize":"ns-resize":o>0&&l>0?"grab":o>0?"col-resize":"row-resize"}}const Ww=new WeakMap;function bv(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:s}=Ww.get(e)??{};s===void 0&&(s=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(s):e.adoptedStyleSheets=[...e.adoptedStyleSheets,s]));const o=No();switch(o.state){case"active":case"hover":{const l=yB({cursorFlags:o.cursorFlags,groups:o.hitRegions.map(u=>u.group),state:o.state}),c=`*, *:hover {cursor: ${l} !important; }`;if(t===c)return;t=c,l?s.cssRules.length===0?s.insertRule(c):s.replaceSync(c):s.cssRules.length===1&&s.deleteRule(0);break}case"inactive":{t=void 0,s.cssRules.length===1&&s.deleteRule(0);break}}Ww.set(e,{prevStyle:t,styleSheet:s})}function VN({document:e,event:t,hitRegions:s,initialLayoutMap:o,mountedGroups:l,pointerDownAtPoint:c,prevCursorFlags:u}){let p=0;s.forEach(g=>{const{group:h,groupSize:b}=g,{orientation:_,panels:k}=h,{disableCursor:N}=h.mutableState;let y=0;c?_==="horizontal"?y=(t.clientX-c.x)/b*100:y=(t.clientY-c.y)/b*100:_==="horizontal"?y=t.clientX<0?-100:100:y=t.clientY<0?-100:100;const w=o.get(h),S=l.get(h);if(!w||!S)return;const{defaultLayoutDeferred:C,derivedPanelConstraints:E,groupSize:R,layout:A,separatorToPanels:T}=S;if(E&&A&&T){const O=Dc({delta:y,initialLayout:w,panelConstraints:E,pivotIndices:g.panels.map(z=>k.indexOf(z)),prevLayout:A,trigger:"mouse-or-touch"});if(So(O,A)){if(y!==0&&!N)switch(_){case"horizontal":{p|=y<0?IN:BN;break}case"vertical":{p|=y<0?UN:HN;break}}}else Qs(g.group,{defaultLayoutDeferred:C,derivedPanelConstraints:E,groupSize:R,layout:O,separatorToPanels:T})}});let m=0;t.movementX===0?m|=u&Kw:m|=p&Kw,t.movementY===0?m|=u&Qw:m|=p&Qw,vB(m),bv(e)}function Jw(e){const t=Oo(),s=No();switch(s.state){case"active":VN({document:e.currentTarget,event:e,hitRegions:s.hitRegions,initialLayoutMap:s.initialLayoutMap,mountedGroups:t,prevCursorFlags:s.cursorFlags})}}function ek(e){if(e.defaultPrevented)return;const t=No(),s=Oo();switch(t.state){case"active":{if(e.buttons===0){Ol({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(o=>{const l=Ar(o.group.id,!0);Qs(o.group,l,{isUserInteraction:!0})});return}for(const o of t.hitRegions)if(o.separator){const{element:l}=o.separator;l.hasPointerCapture?.(e.pointerId)||l.setPointerCapture?.(e.pointerId)}VN({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:s,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const o=hv(e,s);o.length===0?t.state!=="inactive"&&Ol({cursorFlags:0,state:"inactive"}):Ol({cursorFlags:0,hitRegions:o,state:"hover"}),bv(e.currentTarget);break}}}function tk(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(No().state){case"hover":Ol({cursorFlags:0,state:"inactive"})}}function nk(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=No();switch(t.state){case"active":Ol({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(bv(e.currentTarget),t.hitRegions.forEach(s=>{const o=Ar(s.group.id,!0);Qs(s.group,o,{isUserInteraction:!0})}),e.preventDefault())}}function ak(e){let t=0,s=0;const o={};for(const c of e)if(c.defaultSize!==void 0){t++;const u=Yn(c.defaultSize);s+=u,o[c.panelId]=u}else o[c.panelId]=void 0;const l=e.length-t;if(l!==0){const c=Yn((100-s)/l);for(const u of e)u.defaultSize===void 0&&(o[u.panelId]=c)}return o}function jB(e,t,s){if(!s[0])return;const o=e.panels.find(m=>m.element===t);if(!o||!o.onResize)return;const l=Gl({group:e}),c=e.orientation==="horizontal"?o.element.offsetWidth:o.element.offsetHeight,u=o.mutableValues.prevSize,p={asPercentage:Yn(c/l*100),inPixels:c};o.mutableValues.prevSize=p,o.onResize(p,o.id,u)}function wB(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const s in e)if(e[s]!==t[s])return!1;return!0}function kB({group:e,nextGroupSize:t,prevGroupSize:s,prevLayout:o}){if(s<=0||t<=0||s===t)return o;let l=0,c=0,u=!1;const p=new Map,m=[];for(const b of e.panels){const _=o[b.id]??0;switch(b.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{u=!0;const k=_/100*s,N=Yn(k/t*100);p.set(b.id,N),l+=N;break}case"preserve-relative-size":default:{m.push(b.id),c+=_;break}}}if(!u||m.length===0)return o;const g=100-l,h={...o};if(p.forEach((b,_)=>{h[_]=b}),c>0)for(const b of m){const _=o[b]??0;h[b]=Yn(_/c*g)}else{const b=Yn(g/m.length);for(const _ of m)h[_]=b}return h}function SB(e,t){const s=e.map(l=>l.id),o=Object.keys(t);if(s.length!==o.length)return!1;for(const l of s)if(!o.includes(l))return!1;return!0}const yl=new Map;function CB(e){let t=!0;Bt(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const s=e.element.ownerDocument.defaultView.ResizeObserver,o=new Set,l=new Set,c=new s(N=>{for(const y of N){const{borderBoxSize:w,target:S}=y;if(S===e.element){if(t){const C=Gl({group:e});if(C===0)return;const E=Ar(e.id);if(!E)return;const R=yx(e),A=E.defaultLayoutDeferred?ak(R):E.layout,T=kB({group:e,nextGroupSize:C,prevGroupSize:E.groupSize,prevLayout:A}),O=Co({layout:T,panelConstraints:R});if(!E.defaultLayoutDeferred&&So(E.layout,O)&&wB(E.derivedPanelConstraints,R)&&E.groupSize===C)return;Qs(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:R,groupSize:C,layout:O,separatorToPanels:E.separatorToPanels})}}else jB(e,S,w)}});c.observe(e.element),e.panels.forEach(N=>{Bt(!o.has(N.id),`Panel ids must be unique; id "${N.id}" was used more than once`),o.add(N.id),N.onResize&&c.observe(N.element)});const u=Gl({group:e}),p=yx(e),m=e.panels.map(({id:N})=>N).join(",");let g=e.mutableState.defaultLayout;g&&(SB(e.panels,g)||(g=void 0));const h=e.mutableState.layouts[m]??g??ak(p),b=Co({layout:h,panelConstraints:p}),_=e.element.ownerDocument;yl.set(_,(yl.get(_)??0)+1);const k=new Map;return MN(e).forEach(N=>{N.separator&&k.set(N.separator,N.panels)}),Qs(e,{defaultLayoutDeferred:u===0,derivedPanelConstraints:p,groupSize:u,layout:b,separatorToPanels:k}),e.separators.forEach(N=>{Bt(!l.has(N.id),`Separator ids must be unique; id "${N.id}" was used more than once`),l.add(N.id),N.element.addEventListener("keydown",Yw)}),yl.get(_)===1&&(_.addEventListener("dblclick",Gw,!0),_.addEventListener("pointerdown",Xw,!0),_.addEventListener("pointerleave",Jw),_.addEventListener("pointermove",ek),_.addEventListener("pointerout",tk),_.addEventListener("pointerup",nk,!0)),function(){t=!1,yl.set(_,Math.max(0,(yl.get(_)??0)-1)),iB(e),e.separators.forEach(N=>{N.element.removeEventListener("keydown",Yw)}),yl.get(_)||(_.removeEventListener("dblclick",Gw,!0),_.removeEventListener("pointerdown",Xw,!0),_.removeEventListener("pointerleave",Jw),_.removeEventListener("pointermove",ek),_.removeEventListener("pointerout",tk),_.removeEventListener("pointerup",nk,!0)),c.disconnect()}}function NB(){const[e,t]=x.useState({}),s=x.useCallback(()=>t({}),[]);return[e,s]}function vv(e){const t=x.useId();return`${e??t}`}const zo=typeof window<"u"?x.useLayoutEffect:x.useEffect;function kc(e){const t=x.useRef(e);return zo(()=>{t.current=e},[e]),x.useCallback((...s)=>t.current?.(...s),[t])}function _v(...e){return kc(t=>{e.forEach(s=>{if(s)switch(typeof s){case"function":{s(t);break}case"object":{s.current=t;break}}})})}function yv(e){const t=x.useRef({...e});return zo(()=>{for(const s in e)t.current[s]=e[s]},[e]),t.current}const qN=x.createContext(null);function EB(e,t){const s=x.useRef({getLayout:()=>({}),setLayout:_B});x.useImperativeHandle(t,()=>s.current,[]),zo(()=>{Object.assign(s.current,LN({groupId:e}))})}function wx({children:e,className:t,defaultLayout:s,disableCursor:o,disabled:l,elementRef:c,groupRef:u,id:p,onLayoutChange:m,onLayoutChanged:g,orientation:h="horizontal",resizeTargetMinimumSize:b={coarse:20,fine:10},style:_,...k}){const N=x.useRef({onLayoutChange:{},onLayoutChanged:{}}),y=kc(U=>{So(N.current.onLayoutChange,U)||(N.current.onLayoutChange=U,m?.(U))}),w=kc((U,I)=>{So(N.current.onLayoutChanged,U)||(N.current.onLayoutChanged=U,g?.(U,{isUserInteraction:I}))}),S=vv(p),C=x.useRef(null),[E,R]=NB(),A=x.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:b,separators:[]}),T=_v(C,c);EB(S,u);const O=kc((U,I)=>{const V=No(),H=Vw(U),G=Ar(U);if(G){let q=!1;switch(V.state){case"active":{q=V.hitRegions.some(Y=>Y.group===H);break}}return{flexGrow:G.layout[I]??1,pointerEvents:q?"none":void 0}}if(s?.[I])return{flexGrow:s?.[I]}}),z=yv({defaultLayout:s,disableCursor:o}),L=x.useMemo(()=>({get disableCursor(){return!!z.disableCursor},getPanelStyles:O,id:S,orientation:h,registerPanel:U=>{const I=A.current;return I.panels=jx(h,[...I.panels,U]),R(),()=>{I.panels=I.panels.filter(V=>V!==U),R()}},registerSeparator:U=>{const I=A.current;return I.separators=jx(h,[...I.separators,U]),R(),()=>{I.separators=I.separators.filter(V=>V!==U),R()}},updatePanelProps:(U,{disabled:I})=>{const V=A.current.panels.find(q=>q.id===U);V&&(V.panelConstraints.disabled=I);const H=Vw(S),G=Ar(S);H&&G&&Qs(H,{...G,derivedPanelConstraints:yx(H)})},updateSeparatorProps:(U,{disabled:I,disableDoubleClick:V})=>{const H=A.current.separators.find(G=>G.id===U);H&&(H.disabled=I,H.disableDoubleClick=V)}}),[O,S,R,h,z]),D=x.useRef(null);return zo(()=>{const U=C.current;if(U===null)return;const I=A.current;let V;if(z.defaultLayout!==void 0&&Object.keys(z.defaultLayout).length===I.panels.length){V={};for(const K of I.panels){const P=z.defaultLayout[K.id];P!==void 0&&(V[K.id]=P)}}const H={disabled:!!l,element:U,id:S,mutableState:{defaultLayout:V,disableCursor:!!z.disableCursor,expandedPanelSizes:A.current.lastExpandedPanelSizes,layouts:A.current.layouts},orientation:h,panels:I.panels,resizeTargetMinimumSize:I.resizeTargetMinimumSize,separators:I.separators};D.current=H;const G=CB(H),{defaultLayoutDeferred:q,derivedPanelConstraints:Y,layout:X}=Ar(H.id,!0);!q&&Y.length>0&&(y(X),w(X,!1));const $=gv(S,K=>{const{defaultLayoutDeferred:P,derivedPanelConstraints:F,layout:W}=K.next;if(P||F.length===0)return;const ee=H.panels.map(({id:ue})=>ue).join(",");H.mutableState.layouts[ee]=W,F.forEach(ue=>{if(ue.collapsible){const{layout:se}=K.prev??{};if(se){const oe=qn(ue.collapsedSize,W[ue.panelId]),pe=qn(ue.collapsedSize,se[ue.panelId]);oe&&!pe&&(H.mutableState.expandedPanelSizes[ue.panelId]=se[ue.panelId])}}});const ce=No().state!=="active";y(W),ce&&w(W,K.isUserInteraction)});return()=>{D.current=null,G(),$()}},[l,S,w,y,h,E,z]),x.useEffect(()=>{const U=D.current;U&&(U.mutableState.defaultLayout=s,U.mutableState.disableCursor=!!o)}),r.jsx(qN.Provider,{value:L,children:r.jsx("div",{...k,className:t,"data-group":!0,"data-testid":S,id:S,ref:T,style:{height:"100%",width:"100%",overflow:"hidden",..._,display:"flex",flexDirection:h==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:h==="horizontal"?"pan-y":"pan-x"},children:e})})}wx.displayName="Group";function jv(){const e=x.useContext(qN);return Bt(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function RB(e,t){const{id:s}=jv(),o=x.useRef({collapse:Th,expand:Th,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:Th});x.useImperativeHandle(t,()=>o.current,[]),zo(()=>{Object.assign(o.current,PN({groupId:s,panelId:e}))})}function uo({children:e,className:t,collapsedSize:s="0%",collapsible:o=!1,defaultSize:l,disabled:c,elementRef:u,groupResizeBehavior:p="preserve-relative-size",id:m,maxSize:g="100%",minSize:h="0%",onResize:b,panelRef:_,style:k,...N}){const y=!!m,w=vv(m),S=yv({disabled:c}),C=x.useRef(null),E=_v(C,u),{getPanelStyles:R,id:A,orientation:T,registerPanel:O,updatePanelProps:z}=jv(),L=b!==null,D=kc((H,G,q)=>{b?.(H,m,q)});zo(()=>{const H=C.current;if(H!==null){const G={element:H,id:w,idIsStable:y,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:L?D:void 0,panelConstraints:{groupResizeBehavior:p,collapsedSize:s,collapsible:o,defaultSize:l,disabled:S.disabled,maxSize:g,minSize:h}};return O(G)}},[p,s,o,l,L,w,y,g,h,D,O,S]),x.useEffect(()=>{z(w,{disabled:c})},[c,w,z]),RB(w,_);const U=()=>{const H=R(A,w);if(H)return JSON.stringify(H)},I=x.useSyncExternalStore(H=>gv(A,H),U,U);let V;return I?V=JSON.parse(I):l!==void 0?V={flexGrow:void 0,flexShrink:void 0,flexBasis:l}:V={flexGrow:1},r.jsx("div",{...N,"data-disabled":c||void 0,"data-panel":!0,"data-testid":w,id:w,ref:E,style:{...TB,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...V},children:r.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...k,touchAction:T==="horizontal"?"pan-y":"pan-x"},children:e})})}uo.displayName="Panel";const TB={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function AB({layout:e,panelConstraints:t,panelId:s,panelIndex:o}){let l,c;const u=e[s],p=t.find(m=>m.panelId===s);if(p){const m=p.maxSize,g=p.collapsible?p.collapsedSize:p.minSize,h=[o,o+1];c=Co({layout:Dc({delta:g-u,initialLayout:e,panelConstraints:t,pivotIndices:h,prevLayout:e}),panelConstraints:t})[s],l=Co({layout:Dc({delta:m-u,initialLayout:e,panelConstraints:t,pivotIndices:h,prevLayout:e}),panelConstraints:t})[s]}return{valueControls:s,valueMax:l,valueMin:c,valueNow:u}}function wv({children:e,className:t,disabled:s,disableDoubleClick:o,elementRef:l,id:c,style:u,...p}){const m=vv(c),g=yv({disabled:s,disableDoubleClick:o}),[h,b]=x.useState({}),[_,k]=x.useState("inactive"),[N,y]=x.useState(!1),w=x.useRef(null),S=_v(w,l),{disableCursor:C,id:E,orientation:R,registerSeparator:A,updateSeparatorProps:T}=jv(),O=R==="horizontal"?"vertical":"horizontal";zo(()=>{const D=w.current;if(D!==null){const U={disabled:g.disabled,disableDoubleClick:g.disableDoubleClick,element:D,id:m},I=A(U),V=bB(G=>{k(G.next.state!=="inactive"&&G.next.hitRegions.some(q=>q.separator===U)?G.next.state:"inactive")}),H=gv(E,G=>{const{derivedPanelConstraints:q,layout:Y,separatorToPanels:X}=G.next,$=X.get(U);if($){const K=$[0],P=$.indexOf(K);b(AB({layout:Y,panelConstraints:q,panelId:K.id,panelIndex:P}))}});return()=>{V(),H(),I()}}},[E,m,A,g]),x.useEffect(()=>{T(m,{disabled:s,disableDoubleClick:o})},[s,o,m,T]);let z;s&&!C&&(z="not-allowed");let L;if(s)L="disabled";else switch(_){case"active":{L="active";break}default:N?L="focus":L=_}return r.jsx("div",{...p,"aria-controls":h.valueControls,"aria-disabled":s||void 0,"aria-orientation":O,"aria-valuemax":h.valueMax,"aria-valuemin":h.valueMin,"aria-valuenow":h.valueNow,children:e,className:t,"data-separator":L,"data-testid":m,id:m,onBlur:()=>y(!1),onFocus:()=>y(!0),ref:S,role:"separator",style:{flexBasis:"auto",cursor:z,...u,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:s?void 0:0})}wv.displayName="Separator";function MB({projects:e,value:t,onChange:s,disabled:o}){const l=e.map(c=>{const u=c.path?.split("/").filter(Boolean).pop()||f("modules_ui.code_project_fallback",{id:c.id});return{value:String(c.id),label:c.name||u,icon:bM,description:c.path}});return r.jsx("div",{className:"w-full","data-testid":"code-project-select",children:r.jsx(_t,{value:t,onChange:s,options:l,placeholder:f("modules_ui.code_pick_project_ph"),disabled:o})})}function OB({sessions:e,activeId:t,busy:s,onSelect:o,onCreate:l,onRename:c,onDelete:u}){return r.jsxs("div",{className:"flex h-full flex-col","data-testid":"code-session-list",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3 py-2",children:[r.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:f("code_module.sessions")}),r.jsx(et,{content:f("code_module.new_session"),children:r.jsxs("button",{type:"button",onClick:l,disabled:s,"data-testid":"code-new-session",className:"flex items-center gap-1 rounded-md border border-border px-1.5 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50",children:[r.jsx(rn,{className:"size-3"})," ",f("code_module.new_session")]})})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:e.length===0?r.jsx("div",{className:"p-2",children:r.jsx(xt,{children:f("code_module.no_sessions")})}):r.jsx("ul",{className:"space-y-0.5",children:e.map(p=>r.jsxs("li",{className:"group/item relative",children:[r.jsxs("button",{type:"button",onClick:()=>o(p.id),className:ze("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-xs transition-colors",p.id===t?"bg-accent text-accent-fg":"text-foreground/80 hover:bg-accent/50"),children:[r.jsx(Lx,{className:"mt-0.5 size-3.5 shrink-0 opacity-60"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate font-medium",children:p.title}),r.jsxs("span",{className:"block truncate text-[10px] text-muted-foreground",children:[p.mode," · ",p.messageCount," msg",p.model?` · ${p.model}`:""]})]})]}),r.jsxs("div",{className:"absolute right-1 top-1 hidden items-center gap-0.5 group-hover/item:flex",children:[r.jsx(et,{content:f("code_module.rename"),children:r.jsx("button",{type:"button",onClick:()=>c(p.id,p.title),className:"rounded p-1 text-muted-foreground hover:bg-background hover:text-foreground",children:r.jsx(Eo,{className:"size-3"})})}),r.jsx(et,{content:f("code_module.delete"),children:r.jsx("button",{type:"button",onClick:()=>u(p.id),className:"rounded p-1 text-muted-foreground hover:bg-background hover:text-rose-500",children:r.jsx(ca,{className:"size-3"})})})]})]},p.id))})})]})}function zB({mode:e,onChange:t,disabled:s}){const o=(l,c,u,p)=>r.jsx(et,{content:u,children:r.jsxs("button",{type:"button",disabled:s,"data-testid":`code-mode-${l}`,"aria-pressed":e===l,onClick:()=>t(l),className:ze("flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors disabled:opacity-50",e===l?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[r.jsx(p,{className:"size-3.5"})," ",c]})});return r.jsxs("div",{className:"flex items-center gap-0.5 rounded-lg border border-border bg-muted/60 p-0.5",children:[o("build",f("code_module.mode_build"),f("code_module.mode_build_hint"),wM),o("plan",f("code_module.mode_plan"),f("code_module.mode_plan_hint"),sM)]})}function DB({value:e,onValueChange:t,onSubmit:s,onStop:o,busy:l,disabled:c,mode:u,onModeChange:p,model:m,onModelChange:g}){return r.jsx(iv,{value:e,onValueChange:t,onSubmit:s,onStop:o,busy:l,disabled:c,placeholder:f("code_module.placeholder"),minRows:1,maxRows:6,footer:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(zB,{mode:u,onChange:p,disabled:l}),r.jsx(cv,{value:m,onChange:g,disabled:l})]})})}function Ah(e,t){let s=0;for(const o of e.parts||[])o.kind==="text"&&t.text&&(s+=o.text.length),o.kind==="tool"&&t.tool&&(o.args&&(s+=JSON.stringify(o.args).length),o.result!==void 0&&(s+=JSON.stringify(o.result).length));return Math.ceil(s/4)}function PB(e){let t=null,s=0,o=0;for(const u of e)u.role==="user"?s++:o++,u.role==="assistant"&&u.usage&&(t={input:u.usage.input_tokens,output:u.usage.output_tokens,model:u.model});const l=t?.input??0,c=t?.output??0;return{model:t?.model??null,input:l,output:c,total:l+c,hasUsage:!!t,messages:e.length,userMsgs:s,assistantMsgs:o}}function LB(e){let t=0,s=0,o=0;for(const u of e)u.role==="user"?t+=Ah(u,{text:!0}):s+=Ah(u,{text:!0}),o+=Ah(u,{tool:!0});const l=t+s+o||1,c=(u,p)=>({key:u,tokens:p,percent:Math.round(p/l*100)});return[c("user",t),c("assistant",s),c("tool",o)].filter(u=>u.tokens>0)}const sk={user:"bg-emerald-500",assistant:"bg-sky-500",tool:"bg-amber-500"};function Bs({label:e,value:t}){return r.jsxs("div",{className:"flex items-baseline justify-between gap-2 py-0.5",children:[r.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-muted-foreground",children:e}),r.jsx("span",{className:"min-w-0 truncate text-right font-mono text-xs text-foreground",children:t})]})}function rk(e){if(!e)return"";const t=new Date(e),s=o=>String(o).padStart(2,"0");return`${s(t.getDate())} ${t.toLocaleString("es",{month:"short"})} ${t.getFullYear()}, ${s(t.getHours())}:${s(t.getMinutes())}`}function IB({turns:e,session:t}){const s=x.useMemo(()=>PB(e),[e]),o=x.useMemo(()=>LB(e),[e]);return e.length===0?r.jsx("div",{className:"p-3",children:r.jsx(xt,{children:f("code_module.ctx_none")})}):r.jsxs("div",{className:"space-y-1 p-3","data-testid":"code-context-tab",children:[r.jsx(Bs,{label:f("code_module.ctx_model"),value:s.model||f("modules_ui.code_ctx_auto")}),t?.mode&&r.jsx(Bs,{label:f("modules_ui.code_ctx_mode"),value:t.mode}),t?.agentSlug&&r.jsx(Bs,{label:f("modules_ui.code_ctx_agent"),value:t.agentSlug}),r.jsx(Bs,{label:f("code_module.ctx_messages"),value:f("modules_ui.code_ctx_msgs_value",{user:s.userMsgs,assistant:s.assistantMsgs})}),r.jsx(Bs,{label:f("code_module.ctx_input"),value:s.input.toLocaleString()}),r.jsx(Bs,{label:f("code_module.ctx_output"),value:s.output.toLocaleString()}),r.jsx(Bs,{label:f("modules_ui.code_ctx_tokens_total"),value:(s.input+s.output).toLocaleString()}),t?.createdAt&&r.jsx(Bs,{label:f("modules_ui.code_ctx_created"),value:rk(t.createdAt)}),t?.updatedAt&&r.jsx(Bs,{label:f("modules_ui.code_ctx_activity"),value:rk(t.updatedAt)}),r.jsx("hr",{className:"border-border my-2"}),r.jsxs("div",{children:[r.jsx("div",{className:"mb-1 text-[11px] font-semibold text-muted-foreground",children:f("code_module.ctx_breakdown")}),o.length>0?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex h-2.5 w-full overflow-hidden rounded-full bg-muted",children:o.map(l=>r.jsx(et,{content:`${l.key}: ${l.tokens} (${l.percent}%)`,children:r.jsx("div",{className:sk[l.key],style:{width:`${l.percent}%`}})},l.key))}),r.jsx("ul",{className:"mt-2 space-y-1",children:o.map(l=>r.jsxs("li",{className:"flex items-center gap-2 text-[11px]",children:[r.jsx("span",{className:`size-2 rounded-full ${sk[l.key]}`}),r.jsx("span",{className:"flex-1 text-foreground/80",children:f(`code_module.seg_${l.key}`)}),r.jsxs("span",{className:"font-mono text-muted-foreground",children:[l.tokens," · ",l.percent,"%"]})]},l.key))})]}):r.jsx("p",{className:"text-[11px] text-muted-foreground",children:f("code_module.ctx_none")})]})]})}function BB(e){const t=[];for(const s of(e||"").split(`
651
651
  `))s.startsWith("diff --git")||s.startsWith("index ")||s.startsWith("--- ")||s.startsWith("+++ ")||s.startsWith("new file")||s.startsWith("deleted file")||s.startsWith("similarity index")||s.startsWith("rename ")||(s.startsWith("@@")?t.push({kind:"hunk",text:s}):s.startsWith("+")?t.push({kind:"add",text:s.slice(1)}):s.startsWith("-")?t.push({kind:"del",text:s.slice(1)}):t.push({kind:"ctx",text:s.replace(/^ /,"")}));for(;t.length&&t[t.length-1].kind==="ctx"&&t[t.length-1].text==="";)t.pop();return t}function UB({patch:e}){const t=x.useMemo(()=>BB(e),[e]);return t.length?r.jsx("pre",{className:"overflow-x-auto rounded-md border border-border bg-background/60 font-mono text-[11px] leading-relaxed",children:r.jsx("code",{className:"block",children:t.map((s,o)=>r.jsxs("div",{className:ze("px-2 whitespace-pre",s.kind==="add"&&"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",s.kind==="del"&&"bg-rose-500/10 text-rose-600 dark:text-rose-400",s.kind==="hunk"&&"bg-muted/60 text-muted-foreground",s.kind==="ctx"&&"text-foreground/70"),children:[r.jsx("span",{className:"select-none opacity-50",children:s.kind==="add"?"+":s.kind==="del"?"-":" "}),s.text]},o))})}):null}const HB={added:pM,modified:Gd,deleted:hM},VB={added:"text-emerald-600 dark:text-emerald-400",modified:"text-amber-600 dark:text-amber-400",deleted:"text-rose-600 dark:text-rose-400"};function qB({file:e}){const[t,s]=x.useState(!1),o=HB[e.status];return r.jsxs("li",{className:"rounded-md border border-border",children:[r.jsxs("button",{type:"button",onClick:()=>s(l=>!l),className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs hover:bg-accent/40",children:[r.jsx(Ql,{className:ze("size-3 shrink-0 transition-transform",t&&"rotate-90")}),r.jsx(o,{className:ze("size-3.5 shrink-0",VB[e.status])}),r.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:e.path}),r.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground",children:[e.additions!=null&&r.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["+",e.additions]}),e.deletions!=null&&r.jsxs("span",{className:"ml-1 text-rose-600 dark:text-rose-400",children:["-",e.deletions]})]})]}),t&&r.jsx("div",{className:"border-t border-border p-1.5",children:r.jsx(UB,{patch:e.patch})})]})}function $B({changes:e,loading:t,onRefresh:s}){const o=e?.files||[];return r.jsxs("div",{className:"flex h-full flex-col","data-testid":"code-changes-tab",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3 py-2",children:[r.jsx("span",{className:"text-[11px] text-muted-foreground",children:o.length>0?f("code_module.changes_files",{n:o.length}):""}),r.jsx(et,{content:f("code_module.reload"),children:r.jsx("button",{type:"button",onClick:s,className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground",children:t?r.jsx(va,{size:12}):r.jsx(cs,{className:"size-3"})})})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 pb-3",children:e&&!e.git?r.jsx(xt,{children:f("code_module.changes_no_git")}):o.length===0?r.jsx(xt,{children:f("code_module.changes_none")}):r.jsx("ul",{className:"space-y-1.5",children:o.map(l=>r.jsx(qB,{file:l},l.path))})})]})}function FB({pid:e,entry:t,onDeleted:s,onRenamed:o,onRunInTerminal:l,onEditArtifact:c}){const[u,p]=x.useState(!1),[m,g]=x.useState(null),h=lt(),[b,_]=x.useState(!1),[k,N]=x.useState(t.name),y=x.useRef(null),[w,S]=x.useState(!1),[C,E]=x.useState(!1),[R,A]=x.useState(!1),T=w?["artifact",e,t.name]:null,O=Qe(T,()=>Al.read(e,t.name),{revalidateOnFocus:!1}),z=!O.data?.content||O.data.content.startsWith("#!"),L=async V=>{try{await navigator.clipboard.writeText(V),h.info(f("modules_ui.code_copied"))}catch{}},D=async()=>{A(!0);try{await Al.remove(e,t.name),E(!1),s()}catch(V){h.error(V.message)}finally{A(!1)}},U=()=>{N(t.name),_(!0),requestAnimationFrame(()=>y.current?.select())},I=async()=>{const V=k.trim();if(_(!1),!(!V||V===t.name))try{await Al.rename(e,t.name,V),o()}catch(H){h.error(H.message)}};return r.jsxs("li",{className:"rounded-md border border-border",children:[r.jsxs("div",{className:"flex w-full items-center gap-2 px-2 py-1.5 text-xs",children:[r.jsx(fM,{className:"size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"}),b?r.jsx("input",{ref:y,value:k,onChange:V=>N(V.target.value),onBlur:()=>void I(),onKeyDown:V=>{V.key==="Enter"&&I(),V.key==="Escape"&&_(!1)},autoFocus:!0,className:"min-w-0 flex-1 rounded border border-border bg-background px-1 py-0.5 font-mono text-xs outline-none focus:ring-1 focus:ring-ring"}):r.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:t.name}),r.jsx(et,{content:f("code_module.artifacts_rename"),children:r.jsx("button",{type:"button",onClick:U,className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground",children:r.jsx(Eo,{className:"size-3"})})}),r.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground",children:[t.size,"b"]})]}),r.jsxs("div",{className:"space-y-2 border-t border-border p-2",children:[r.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1 rounded bg-muted px-1.5 py-0.5",children:[r.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-[10px] text-muted-foreground",children:t.path}),r.jsx(et,{content:f("code_module.artifacts_copy_path"),children:r.jsx("button",{type:"button",onClick:()=>void L(t.path),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground",children:r.jsx(Fd,{className:"size-3"})})})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-1",children:[r.jsxs(lx,{open:w,onOpenChange:S,children:[r.jsx(et,{content:f("code_module.artifacts_view"),children:r.jsxs("button",{type:"button",onClick:()=>S(!0),className:"inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] font-medium bg-blue-500/15 text-blue-700 hover:bg-blue-500/25 dark:text-blue-300",children:[r.jsx(Sf,{className:"size-3"}),f("modules_ui.code_artifact_view_short")]})}),r.jsxs(ix,{className:"sm:max-w-lg",children:[r.jsx(cx,{children:r.jsx(ux,{className:"font-mono text-sm",children:t.name})}),O.isLoading?r.jsx("div",{className:"flex justify-center py-6",children:r.jsx(va,{size:16})}):r.jsx("pre",{className:"max-h-96 overflow-auto rounded bg-muted/50 p-3 font-mono text-[11px] leading-tight whitespace-pre-wrap break-all",children:O.data?.content??""}),r.jsx(Bj,{showCloseButton:!0})]})]}),r.jsx(et,{content:f("code_module.artifacts_edit"),children:r.jsxs("button",{type:"button",onClick:()=>c?.(t.name),className:"inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] font-medium bg-violet-500/15 text-violet-700 hover:bg-violet-500/25 dark:text-violet-300",children:[r.jsx(UM,{className:"size-3"}),f("modules_ui.code_artifact_edit_short")]})}),z&&r.jsx(et,{content:f("code_module.artifacts_run"),children:r.jsxs("button",{type:"button",onClick:()=>l?.(`apx artifact run ${t.name}`),className:"inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] font-medium bg-emerald-500/15 text-emerald-700 hover:bg-emerald-500/25 dark:text-emerald-300",children:[r.jsx(Bx,{className:"size-3"}),f("code_module.artifacts_run")]})}),r.jsxs(lx,{open:C,onOpenChange:E,children:[r.jsx(et,{content:f("code_module.artifacts_delete"),children:r.jsx("button",{type:"button",onClick:()=>E(!0),className:"ml-auto rounded p-1 text-rose-600 hover:bg-rose-50 dark:text-rose-400 dark:hover:bg-rose-950",children:r.jsx(ca,{className:"size-3"})})}),r.jsxs(ix,{className:"sm:max-w-sm",children:[r.jsx(cx,{children:r.jsxs(ux,{className:"font-mono text-sm",children:[f("code_module.artifacts_delete")," — ",t.name]})}),r.jsx("p",{className:"px-1 text-sm text-muted-foreground",children:f("code_module.artifacts_delete_confirm")}),r.jsxs(Bj,{children:[r.jsx(kP,{render:r.jsx("button",{type:"button",className:"rounded px-3 py-1.5 text-xs font-medium hover:bg-accent"}),children:f("common.cancel")}),r.jsxs("button",{type:"button",onClick:()=>void D(),disabled:R,className:ze("inline-flex items-center gap-1.5 rounded px-3 py-1.5 text-xs font-medium",R?"bg-muted text-muted-foreground":"bg-rose-500/15 text-rose-700 hover:bg-rose-500/25 dark:text-rose-300"),children:[R&&r.jsx(va,{size:10}),f("code_module.delete")]})]})]})]})]}),r.jsxs("div",{className:"mt-1 text-[10px] text-muted-foreground",children:[f("code_module.artifacts_run_hint")," ",r.jsxs("code",{className:"rounded bg-muted px-1 font-mono",children:["apx artifact run ",t.name]})]}),m&&r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"flex items-center gap-2 text-[10px]",children:[r.jsx("span",{className:ze("rounded px-1.5 py-0.5 font-mono",m.ok?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-rose-500/15 text-rose-700 dark:text-rose-300"),children:f("modules_ui.code_artifact_exit_badge",{code:m.exitCode??m.signal??"?"})}),m.timedOut&&r.jsx("span",{className:"rounded bg-amber-500/15 px-1.5 py-0.5 font-mono text-amber-700 dark:text-amber-300",children:f("modules_ui.code_artifact_timeout")}),m.truncated&&r.jsx("span",{className:"rounded bg-amber-500/15 px-1.5 py-0.5 font-mono text-amber-700 dark:text-amber-300",children:f("modules_ui.code_artifact_truncated")}),r.jsxs("span",{className:"font-mono text-muted-foreground",children:[m.durationMs,"ms"]})]}),m.stdout&&r.jsx("pre",{className:"max-h-32 overflow-auto rounded bg-background/60 p-2 text-[10px] leading-tight",children:m.stdout}),m.stderr&&r.jsx("pre",{className:"max-h-32 overflow-auto rounded bg-rose-500/5 p-2 text-[10px] leading-tight text-rose-700 dark:text-rose-300",children:m.stderr})]})]})]})}function GB({pid:e,onRunInTerminal:t,onEditArtifact:s}){const o=Qe(e?["artifacts",e]:null,()=>Al.list(e)),l=o.data||[];return r.jsxs("div",{className:"flex h-full flex-col","data-testid":"code-artifacts-tab",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3 py-2",children:[r.jsx("span",{className:"text-[11px] text-muted-foreground",children:l.length>0?f("code_module.artifacts_count",{n:l.length}):""}),r.jsx(et,{content:f("code_module.reload"),children:r.jsx("button",{type:"button",onClick:()=>void o.mutate(),className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground",children:o.isLoading?r.jsx(va,{size:12}):r.jsx(cs,{className:"size-3"})})})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 pb-3",children:l.length===0?r.jsx(xt,{children:f("code_module.artifacts_none")}):r.jsx("ul",{className:"space-y-1.5",children:l.map(c=>r.jsx(FB,{pid:e,entry:c,onDeleted:()=>void o.mutate(),onRenamed:()=>void o.mutate(),onRunInTerminal:t,onEditArtifact:s},c.name))})})]})}const YB=[{value:"context",icon:Cf,label:"tab_context"},{value:"changes",icon:jM,label:"tab_changes"},{value:"artifacts",icon:OM,label:"tab_artifacts"}];function XB({pid:e,turns:t,changes:s,changesLoading:o,onRefreshChanges:l,session:c,onRunInTerminal:u,onEditArtifact:p}){const[m,g]=x.useState("context"),h=s?.files.length||0;return r.jsxs(op,{value:m,onValueChange:g,className:"flex h-full flex-col gap-0","data-testid":"code-side-panel",children:[r.jsx("div",{className:"shrink-0 border-b border-border px-2 py-2",children:r.jsx(lp,{variant:"line",className:"w-full",children:YB.map(({value:b,icon:_,label:k})=>{const N=m===b,y=f(`code_module.${k}`);return r.jsx(et,{content:y,children:r.jsxs(as,{value:b,className:N?"flex-1 min-w-0":"w-8 shrink-0",children:[r.jsx(_,{className:"size-3.5 shrink-0"}),N&&r.jsx("span",{className:"truncate text-xs",children:y}),b==="changes"&&h>0&&r.jsx("span",{className:"ml-0.5 rounded-full bg-muted px-1 text-[10px] text-muted-foreground leading-none py-0.5",children:h})]})},b)})})}),r.jsx(Da,{value:"context",className:"min-h-0 flex-1 overflow-y-auto",children:r.jsx(IB,{turns:t,session:c})}),r.jsx(Da,{value:"changes",className:"min-h-0 flex-1 overflow-hidden",children:r.jsx($B,{changes:s,loading:o,onRefresh:l})}),r.jsx(Da,{value:"artifacts",className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(GB,{pid:e,onRunInTerminal:u,onEditArtifact:p})})]})}function KB(e){const t=[];for(const o of e){const l=o.split("/").filter(Boolean);let c=t,u="";for(let p=0;p<l.length;p++){u=u?`${u}/${l[p]}`:l[p];const m=p===l.length-1;let g=c.find(h=>h.name===l[p]);g||(g={name:l[p],path:u,type:m?"file":"dir",children:m?void 0:[]},c.push(g)),m||(c=g.children)}}const s=o=>(o.forEach(l=>{l.children&&(l.children=s(l.children))}),o.sort((l,c)=>l.type!==c.type?l.type==="dir"?-1:1:l.name.localeCompare(c.name)));return s(t)}function $N({node:e,depth:t,onOpenFile:s,openDirs:o,toggleDir:l}){const c=e.type==="dir",u=c&&o.has(e.path);return r.jsxs("li",{children:[r.jsxs("button",{type:"button",onClick:()=>c?l(e.path):s(e.path),style:{paddingLeft:`${t*12+6}px`},className:ze("flex w-full items-center gap-1.5 py-0.5 pr-2 text-left text-[11px] rounded transition-colors","hover:bg-accent/40",c?"text-foreground/80":"text-foreground/70"),children:[c?r.jsxs(r.Fragment,{children:[r.jsx(Ql,{className:ze("size-3 shrink-0 transition-transform",u&&"rotate-90")}),u?r.jsx(Dx,{className:"size-3.5 shrink-0 text-amber-400"}):r.jsx(vM,{className:"size-3.5 shrink-0 text-amber-400"})]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"size-3 shrink-0"}),r.jsx(xM,{className:"size-3.5 shrink-0 text-sky-400"})]}),r.jsx("span",{className:"truncate",children:e.name})]}),c&&u&&e.children&&e.children.length>0&&r.jsx("ul",{children:e.children.map(p=>r.jsx($N,{node:p,depth:t+1,onOpenFile:s,openDirs:o,toggleDir:l},p.path))})]})}function QB({pid:e,projectPath:t,className:s,onOpenFile:o}){const[l,c]=x.useState([]),[u,p]=x.useState(!1),[m,g]=x.useState(!1),[h,b]=x.useState(()=>new Set),_=x.useCallback(async()=>{p(!0);try{const C=(await ge.post("/run",{cmd:"find . -type f -not -path '*/node_modules/*' -not -path '*/.git/*' -not -path '*/dist/*' -not -path '*/.claude/*' | sed 's|^\\./||' | sort | head -500",project:e})).stdout.split(`
652
652
  `).map(E=>E.trim()).filter(Boolean);c(C),g(!0)}catch{g(!0)}finally{p(!1)}},[e]);x.useEffect(()=>{b(new Set),_()},[_]);const k=x.useCallback(S=>{b(C=>{const E=new Set(C);return E.has(S)?E.delete(S):E.add(S),E})},[]),N=x.useCallback(()=>{b(new Set)},[]),y=KB(l),w=h.size>0;return r.jsxs("div",{className:ze("flex h-full flex-col",s),"data-testid":"code-file-tree",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border px-3 py-2",children:[r.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Archivos"}),r.jsxs("div",{className:"flex items-center gap-0.5",children:[r.jsx(et,{content:f("code_module.tree_collapse_all"),children:r.jsx("button",{type:"button",onClick:N,disabled:!w,className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-40 disabled:hover:bg-transparent",children:r.jsx(tM,{className:"size-3"})})}),r.jsx(et,{content:f("code_module.reload"),children:r.jsx("button",{type:"button",onClick:()=>void _(),className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground",children:u?r.jsx(va,{size:12}):r.jsx(cs,{className:"size-3"})})})]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto py-1",children:m?y.length===0?r.jsx("div",{className:"p-3",children:r.jsx(xt,{children:"Sin archivos"})}):r.jsx("ul",{children:y.map(S=>r.jsx($N,{node:S,depth:0,onOpenFile:o??(()=>{}),openDirs:h,toggleDir:k},S.path))}):r.jsx("div",{className:"flex justify-center pt-6",children:r.jsx(va,{size:14})})})]})}function ZB({path:e,content:t,loading:s,onSave:o}){const l=typeof o=="function",[c,u]=x.useState(t),[p,m]=x.useState(!1);x.useEffect(()=>{u(t)},[t]);const g=l&&c!==t,h=async()=>{if(!(!o||!g)){m(!0);try{await o(c)}finally{m(!1)}}};return r.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/40","data-testid":"code-file-viewer",children:[r.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-1.5",children:[r.jsxs("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",children:[e,g&&r.jsx("span",{className:"ml-1 text-amber-400",children:"•"})]}),l&&r.jsxs(r.Fragment,{children:[r.jsx(et,{content:f("code_module.discard_changes"),children:r.jsxs("button",{type:"button",onClick:()=>u(t),disabled:!g||p,className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-40",children:[r.jsx(Ux,{className:"size-3"}),"Descartar"]})}),r.jsx(et,{content:f("code_module.save_shortcut_hint"),children:r.jsxs("button",{type:"button",onClick:()=>void h(),disabled:!g||p,className:ze("inline-flex items-center gap-1 rounded px-2 py-0.5 text-[10px] font-medium transition-colors",g&&!p?"bg-emerald-500/15 text-emerald-700 hover:bg-emerald-500/25 dark:text-emerald-300":"bg-muted text-muted-foreground"),children:[p?r.jsx(va,{size:10}):r.jsx(Ef,{className:"size-3"}),"Guardar"]})})]})]}),s?r.jsx("div",{className:"flex flex-1 items-center justify-center",children:r.jsx(va,{size:16})}):l?r.jsx("textarea",{value:c,onChange:b=>u(b.target.value),onKeyDown:b=>{(b.metaKey||b.ctrlKey)&&b.key==="s"&&(b.preventDefault(),h())},className:"min-h-0 flex-1 resize-none bg-transparent p-3 font-mono text-[12px] leading-[1.6] text-foreground/90 outline-none",spellCheck:!1}):r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:r.jsx("table",{className:"w-full border-collapse font-mono text-[12px] leading-[1.6]",children:r.jsx("tbody",{children:t.split(`
653
653
  `).map((b,_)=>r.jsxs("tr",{className:"hover:bg-accent/20",children:[r.jsx("td",{className:"w-12 select-none border-r border-border/30 px-3 py-0 text-right align-top text-[10px] text-muted-foreground/40","aria-hidden":"true",children:_+1}),r.jsx("td",{className:"px-4 py-0 align-top text-foreground/90 whitespace-pre",children:b||" "})]},_))})})})]})}function WB({pid:e,className:t,initCmd:s,onClose:o}){const[l,c]=x.useState([]),[u,p]=x.useState(""),[m,g]=x.useState(!1),[h,b]=x.useState([]),[_,k]=x.useState(-1),N=x.useRef(null),y=x.useRef(null);x.useEffect(()=>{N.current?.scrollIntoView({behavior:"smooth"})},[l]),x.useEffect(()=>{s&&(p(s),setTimeout(()=>y.current?.focus(),50))},[s]);const w=async C=>{const E=C.trim();if(E){b(R=>[E,...R.slice(0,49)]),k(-1),c(R=>[...R,{type:"cmd",text:`$ ${E}`}]),g(!0);try{const R=await ge.post("/run",{cmd:E,project:e});R.stdout&&c(A=>[...A,{type:"out",text:R.stdout}]),R.stderr&&c(A=>[...A,{type:"err",text:R.stderr}])}catch(R){c(A=>[...A,{type:"err",text:String(R.message)}])}finally{g(!1)}}},S=C=>{if(C.key==="Enter")w(u),p("");else if(C.key==="ArrowUp"){C.preventDefault();const E=Math.min(_+1,h.length-1);k(E),p(h[E]??"")}else if(C.key==="ArrowDown"){C.preventDefault();const E=Math.max(_-1,-1);k(E),p(E===-1?"":h[E]??"")}};return r.jsxs("div",{className:ze("flex h-full min-h-0 flex-col bg-card/60",t),"data-testid":"code-terminal",children:[r.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-1",children:[r.jsx(Mr,{className:"size-3 text-muted-foreground"}),r.jsx("span",{className:"flex-1 text-[11px] text-muted-foreground",children:"Terminal"}),r.jsx(et,{content:f("code_module.terminal_clear"),children:r.jsx("button",{type:"button",onClick:()=>c([]),className:"rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground",children:r.jsx(uM,{className:"size-3"})})}),r.jsx(et,{content:f("code_module.terminal_close"),children:r.jsx("button",{type:"button",onClick:()=>o?.(),className:"rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground",children:r.jsx(ps,{className:"size-3"})})})]}),r.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 py-1 font-mono text-[11px] leading-snug cursor-text",onClick:()=>y.current?.focus(),children:[l.map((C,E)=>r.jsx("div",{className:ze("whitespace-pre-wrap break-all",C.type==="cmd"&&"text-emerald-400",C.type==="err"&&"text-rose-400",C.type==="out"&&"text-foreground/90"),children:C.text},E)),r.jsx("div",{ref:N})]}),r.jsxs("div",{className:"flex shrink-0 items-center border-t border-border px-3 py-1",children:[r.jsx("span",{className:"mr-2 text-[11px] text-emerald-400 font-mono",children:"$"}),r.jsx("input",{ref:y,value:u,onChange:C=>p(C.target.value),onKeyDown:S,disabled:m,placeholder:m?"ejecutando…":"comando…",className:"flex-1 bg-transparent font-mono text-[11px] text-foreground outline-none placeholder:text-muted-foreground/50 disabled:opacity-50",spellCheck:!1,autoComplete:"off"})]})]})}const ic="super-agent";function Mh(){return r.jsx(wv,{className:"relative z-10 w-px shrink-0 cursor-col-resize bg-border transition-colors hover:bg-primary/50 active:bg-primary/70"})}function JB(){return r.jsx(wv,{className:"relative z-10 h-px shrink-0 cursor-row-resize bg-border transition-colors hover:bg-primary/50 active:bg-primary/70"})}function e9(){const e=lt(),t=Qe("/projects",()=>ra.list()),s=x.useMemo(()=>t.data||[],[t.data]),[o,l]=x.useState(""),[c,u]=x.useState(null),[p,m]=x.useState(ic),[g,h]=x.useState([]),[b,_]=x.useState(""),[k,N]=x.useState(!1),[y,w]=x.useState(!0),[S,C]=x.useState(!0),[E,R]=x.useState(!1),[A,T]=x.useState(""),[O,z]=x.useState(!1),L=x.useRef(null),[D,U]=x.useState([]),[I,V]=x.useState("chat"),H=x.useCallback(ve=>{R(!0),T(ve)},[]);x.useEffect(()=>{!o&&s.length&&l(String(s[0].id))},[o,s]);const G=Qe(o?["code-sessions",o]:null,()=>Is.sessions.list(o)),q=Qe(o?["agents",o]:null,()=>sn.list(o)),Y=Qe(o&&c?["code-session",o,c]:null,()=>Is.sessions.get(o,c)),X=Qe(o&&c?["code-changes",o,c]:null,()=>Is.changes(o,c));x.useEffect(()=>{const ve=G.data||[];!c&&ve.length&&u(ve[0].id),c&&ve.length&&!ve.some(Me=>Me.id===c)&&u(ve[0]?.id??null)},[G.data,c]),x.useEffect(()=>{Y.data&&m(Y.data.agentSlug||ic)},[Y.data]),x.useEffect(()=>{k||(Y.data?h(Y.data.messages||[]):c||h([]))},[Y.data,c,k]),x.useEffect(()=>()=>L.current?.abort(),[]);const $=Y.data,K=$?.mode==="plan"?"plan":"build",P=$?.model||"",F=ve=>{ve===o||k||(l(ve),u(null),h([]))},W=ve=>{k||ve===c||(u(ve),h([]))},ee=async()=>{if(!(!o||k))try{const ve=await Is.sessions.create(o,{title:f("code_module.untitled"),agentSlug:p!==ic?p:null});await G.mutate(),u(ve.id),h([])}catch(ve){e.error(ve.message)}},ce=async(ve,Me)=>{const He=window.prompt(f("code_module.rename"),Me);if(!(!He||He===Me))try{await Is.sessions.update(o,ve,{title:He}),await G.mutate(),ve===c&&await Y.mutate()}catch(Xe){e.error(Xe.message)}},ue=async ve=>{if(!k&&window.confirm(f("code_module.delete_confirm")))try{await Is.sessions.remove(o,ve),ve===c&&(u(null),h([])),await G.mutate()}catch(Me){e.error(Me.message)}},se=async ve=>{if(m(ve),!!c)try{await Is.sessions.update(o,c,{agentSlug:ve!==ic?ve:null}),await Promise.all([Y.mutate(),G.mutate()])}catch(Me){e.error(Me.message)}},oe=x.useCallback(async ve=>{if(c)try{await Is.sessions.update(o,c,ve),await Promise.all([Y.mutate(),G.mutate()])}catch(Me){e.error(Me.message)}},[o,c,Y,G,e]),pe=()=>{L.current?.abort(),N(!1)},Re=ve=>h(Me=>{const He=[...Me],Xe=He[He.length-1];return Xe&&Xe.role==="assistant"&&(He[He.length-1]=ve(Xe)),He}),le=async ve=>{const Me=(ve??b).trim();if(!Me||k||!o||!c)return;const He=new Date().toISOString();h(nn=>[...nn,{role:"user",parts:[{kind:"text",text:Me}],ts:He},{role:"assistant",parts:[],ts:He,pending:!0}]),_(""),N(!0);const Xe=new AbortController;L.current=Xe;const rt=nn=>{if(nn.type==="error"){e.error(nn.error||f("modules_ui.code_stream_error"));return}Re(un=>uv(un,nn))};try{await Is.stream(o,c,{prompt:Me},rt,Xe.signal),Re(nn=>({...nn,pending:!1}))}catch(nn){Xe.signal.aborted?Re(un=>({...un,pending:!1,parts:[...un.parts,{kind:"text",text:f("code_module.stopped")}]})):(e.error(nn.message),h(un=>un.filter((pt,Et)=>Et!==un.length-1)))}finally{L.current===Xe&&(L.current=null),N(!1),Y.mutate(),G.mutate(),X.mutate()}},de=async ve=>{try{await navigator.clipboard.writeText(ve),e.info(f("modules_ui.code_copied"))}catch{}},Se=x.useCallback(ve=>{V(ve),U(Me=>Me.some(He=>He.path===ve)?Me:[...Me,{path:ve,content:"",loading:!0}]),ge.post("/run",{cmd:`cat "${ve}"`,project:o}).then(Me=>{const He=Me.stdout||Me.stderr||f("modules_ui.code_file_empty");U(Xe=>Xe.map(rt=>rt.path===ve?{...rt,content:He,loading:!1}:rt))}).catch(Me=>{U(He=>He.map(Xe=>Xe.path===ve?{...Xe,content:f("modules_ui.code_file_error",{msg:Me.message}),loading:!1}:Xe))})},[o]),je=x.useCallback(ve=>{U(Me=>Me.filter(He=>He.path!==ve)),V(Me=>Me===ve?"chat":Me)},[]),Be=x.useCallback(ve=>{const Me=`artifacts/${ve}`;V(Me),U(He=>He.some(Xe=>Xe.path===Me)?He:[...He,{path:Me,content:"",loading:!0,artifactName:ve}]),Al.read(o,ve).then(He=>{U(Xe=>Xe.map(rt=>rt.path===Me?{...rt,content:He.content,loading:!1}:rt))}).catch(He=>{U(Xe=>Xe.map(rt=>rt.path===Me?{...rt,content:f("modules_ui.code_file_error",{msg:He.message}),loading:!1}:rt))})},[o]),Ve=x.useCallback(async(ve,Me)=>{const He=D.find(Xe=>Xe.path===ve);if(He?.artifactName)try{await Al.write(o,He.artifactName,Me),U(Xe=>Xe.map(rt=>rt.path===ve?{...rt,content:Me}:rt)),e.info(f("modules_ui.code_saved"))}catch(Xe){e.error(Xe.message)}},[D,o,e]),we=!t.isLoading&&s.length>0,Ne=x.useMemo(()=>{const ve=[{value:ic,label:f("modules_ui.code_super_agent"),icon:hn,description:f("modules_ui.code_super_agent_desc")}],Me=(q.data||[]).map(He=>({value:He.slug,label:He.slug,icon:hn,description:He.description||He.role||void 0}));return[...ve,...Me]},[q.data]),_e=x.useMemo(()=>g,[g]),Ce=x.useMemo(()=>G.data?.find(ve=>ve.id===c)?.title||"",[G.data,c]),Pe=x.useMemo(()=>s.find(ve=>String(ve.id)===o),[s,o]);UP(Ce);const[Le,Ie]=x.useState(null),ae=k?null:hN(g),be=ae&&ae.turnKey!==Le,$e=ve=>{le(ve)},Ee=x.useCallback(()=>w(ve=>!ve),[]),Oe=x.useCallback(()=>z(ve=>!ve),[]),Ze=x.useCallback(()=>R(ve=>!ve),[]),st=x.useCallback(()=>C(ve=>!ve),[]),yt=x.useMemo(()=>c?r.jsx("div",{className:"flex items-center gap-0.5",children:[{Icon:qk,open:y,toggle:Ee,title:f("modules_ui.code_panel_sessions")},{Icon:Uk,open:O,toggle:Oe,title:f("modules_ui.code_panel_tree")},{Icon:Mr,open:E,toggle:Ze,title:f("modules_ui.code_panel_terminal")},{Icon:DM,open:S,toggle:st,title:f("modules_ui.code_panel_context")}].map(({Icon:ve,open:Me,toggle:He,title:Xe})=>r.jsx(et,{content:Xe,children:r.jsx("button",{type:"button",onClick:He,"data-active":Me,className:"rounded p-1 text-muted-fg transition-colors hover:bg-accent hover:text-accent-fg data-[active=true]:bg-accent data-[active=true]:text-accent-fg",children:r.jsx(ve,{className:"size-3.5"})})},Xe))}):null,[c,y,O,E,S,Ee,Oe,Ze,st]);return VP(yt),r.jsx("div",{className:"flex h-full min-h-0 flex-col","data-testid":"screen-code",children:t.isLoading?r.jsx(ot,{}):we?r.jsxs(wx,{orientation:"vertical",id:"code-layout-v",className:"min-h-0 flex-1",children:[r.jsx(uo,{id:"top",defaultSize:E?"55%":"100%",minSize:"20%",children:r.jsxs(wx,{orientation:"horizontal",id:"code-layout",className:"h-full",children:[y&&r.jsxs(r.Fragment,{children:[r.jsx(uo,{id:"left",defaultSize:"14%",minSize:"8%",children:r.jsxs("aside",{className:"flex h-full flex-col",children:[r.jsx("div",{className:"shrink-0 border-b border-border p-2",children:r.jsx(MB,{projects:s,value:o,onChange:F,disabled:k})}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(OB,{sessions:G.data||[],activeId:c,busy:k,onSelect:W,onCreate:ee,onRename:ce,onDelete:ue})}),r.jsx("div",{className:"shrink-0 border-t border-border p-2",children:r.jsx(_t,{value:p,onChange:se,options:Ne,disabled:k,showIcon:!0})})]})}),r.jsx(Mh,{})]}),O&&r.jsxs(r.Fragment,{children:[r.jsx(uo,{id:"tree",defaultSize:"13%",minSize:"8%",children:r.jsx("div",{className:"h-full",children:r.jsx(QB,{pid:o,projectPath:Pe?.path,onOpenFile:Se})})}),r.jsx(Mh,{})]}),r.jsx(uo,{id:"main",defaultSize:"50%",minSize:"20%",children:r.jsxs("div",{className:"flex h-full flex-col",children:[D.length>0&&r.jsxs("div",{className:"flex shrink-0 items-center gap-0 overflow-x-auto border-b border-border",children:[r.jsxs("button",{type:"button",onClick:()=>V("chat"),"data-active":I==="chat",className:"flex shrink-0 items-center gap-1.5 border-r border-border px-3 py-2 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-accent/40 data-[active=true]:text-foreground",children:[r.jsx(Lx,{className:"size-3 shrink-0"}),f("modules_ui.code_chat_tab")]}),D.map(ve=>{const Me=ve.path.split("/").pop()??ve.path,He=I===ve.path;return r.jsxs("div",{"data-active":He,className:"group flex shrink-0 items-center gap-1 border-r border-border px-2 py-2 text-[11px] text-muted-foreground transition-colors hover:bg-accent/40 data-[active=true]:text-foreground",children:[r.jsx(et,{content:ve.path,children:r.jsx("button",{type:"button",onClick:()=>V(ve.path),className:"min-w-0 max-w-[140px] truncate font-mono",children:Me})}),r.jsx(et,{content:f("code_module.close"),children:r.jsx("button",{type:"button",onClick:()=>je(ve.path),className:"shrink-0 rounded p-0.5 opacity-60 hover:bg-accent hover:opacity-100",children:r.jsx(ps,{className:"size-2.5"})})})]},ve.path)})]}),I==="chat"?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"code-transcript",children:c?g.length?r.jsx(dv,{msgs:g,onCopy:de}):r.jsx("div",{className:"grid h-full place-items-center p-6",children:r.jsx(xt,{children:f("code_module.empty_chat")})}):r.jsx("div",{className:"grid h-full place-items-center p-6",children:r.jsx(xt,{children:f("code_module.pick_project")})})}),be&&ae&&r.jsx(gN,{turnKey:ae.turnKey,questions:ae.questions,onSubmit:$e,onDismiss:()=>Ie(ae.turnKey),disabled:k})]}):r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:(()=>{const ve=D.find(Me=>Me.path===I);return ve?r.jsx(ZB,{path:ve.path,content:ve.content,loading:ve.loading,onSave:ve.artifactName?Me=>Ve(ve.path,Me):void 0}):null})()}),r.jsx("div",{className:"shrink-0 border-t border-border p-2","data-testid":"code-input",children:r.jsx(DB,{value:b,onValueChange:_,onSubmit:()=>void le(),onStop:pe,busy:k,disabled:!c,mode:K,onModeChange:ve=>void oe({mode:ve}),model:P,onModelChange:ve=>void oe({model:ve||null})})})]})}),S&&r.jsxs(r.Fragment,{children:[r.jsx(Mh,{}),r.jsx(uo,{id:"right",defaultSize:"22%",minSize:"15%",children:r.jsx("aside",{className:"flex h-full flex-col",children:r.jsx(XB,{pid:o,turns:_e,changes:X.data,changesLoading:X.isLoading,onRefreshChanges:()=>void X.mutate(),session:Y.data?{title:Y.data.title,mode:Y.data.mode,createdAt:Y.data.createdAt,updatedAt:Y.data.updatedAt,agentSlug:Y.data.agentSlug??null}:null,onRunInTerminal:H,onEditArtifact:Be})})})]})]})}),E&&o&&r.jsxs(r.Fragment,{children:[r.jsx(JB,{}),r.jsx(uo,{id:"terminal",defaultSize:"45%",minSize:"10%",maxSize:"80%",children:r.jsx(WB,{pid:o,initCmd:A,onClose:Ze,className:"h-full"})})]})]}):r.jsx("div",{className:"grid flex-1 place-items-center",children:r.jsx(xt,{children:f("code_module.no_projects")})})})}function t9({open:e,onClose:t}){const{mutate:s}=uC(),o=Qn(),l=lt(),[c,u]=x.useState(""),[p,m]=x.useState(!1),[g,h]=x.useState(""),[b,_]=x.useState([]),[k,N]=x.useState(null),[y,w]=x.useState(""),[S,C]=x.useState(!1),[E,R]=x.useState(!1),A=async(z,L=!1)=>{C(!0),w("");try{const D=await Mj.dirs(z||"~");h(D.path),u(D.path),N(D.parent),_(D.entries)}catch(D){const U=D.message;w(U),L||l.error(U)}finally{C(!1)}};x.useEffect(()=>{e||(u(""),m(!1),h(""),_([]),N(null),w(""))},[e]);const T=async()=>{C(!0);try{const z=await Mj.pickDir(f("add_project.picker_prompt"));if("cancelled"in z)return;u(z.path);return}catch{m(!0),await A(c||"~")}finally{C(!1)}},O=async()=>{const z=c.trim();if(!z){l.error(f("add_project.path_required"));return}R(!0);try{const L=await ra.register(z);l.success(f("add_project.registered",{id:L.id})),await s("/projects"),t(),o(`/p/${L.id}`)}catch(L){l.error(L.message)}finally{R(!1)}};return r.jsx(An,{open:e,onClose:t,title:f("add_project.title"),description:f("add_project.subtitle"),footer:r.jsxs(r.Fragment,{children:[r.jsx(me,{variant:"ghost",onClick:t,disabled:E,children:f("common.cancel")}),r.jsx(me,{variant:"primary",onClick:O,loading:E,children:f("add_project.register")})]}),children:r.jsxs("div",{className:"space-y-3",children:[r.jsx(fe,{label:f("add_project.path_label"),hint:f("add_project.path_hint"),children:r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Ae,{autoFocus:!0,placeholder:f("add_project.path_placeholder"),value:c,onChange:z=>u(z.target.value),onKeyDown:z=>{z.key==="Enter"&&O()}}),r.jsxs(me,{onClick:T,disabled:S,children:[r.jsx(Dd,{size:14})," ",f("add_project.search_btn")]})]})}),p&&r.jsxs("div",{className:"rounded-md border border-border bg-muted/20",children:[r.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[r.jsx("span",{className:"truncate font-mono text-xs text-muted-fg",children:g||c||"~"}),r.jsxs("div",{className:"flex gap-1",children:[r.jsx(me,{size:"sm",variant:"ghost",onClick:()=>A("~"),disabled:S,children:r.jsx(SM,{size:13})}),r.jsx(me,{size:"sm",variant:"ghost",onClick:()=>k&&A(k),disabled:!k||S,children:".."}),r.jsx(me,{size:"sm",variant:"ghost",onClick:()=>m(!1),disabled:S,children:r.jsx(ps,{size:13})})]})]}),r.jsxs("div",{className:"max-h-64 overflow-y-auto p-2",children:[S&&r.jsx(ot,{}),!S&&y&&r.jsx(xt,{children:f("add_project.browser_unavailable")}),!S&&!y&&b.length===0&&r.jsx(xt,{children:f("add_project.no_folders")}),!S&&!y&&b.map(z=>r.jsxs("button",{type:"button",onClick:()=>A(z),className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent",children:[r.jsx(Dx,{size:14,className:"text-muted-fg"}),r.jsx("span",{className:"truncate",children:z.split("/").pop()}),r.jsx("span",{className:"ml-auto truncate font-mono text-[10px] text-muted-fg",children:z})]},z))]})]})]})})}function n9({onPaired:e}){const[t,s]=x.useState(""),[o,l]=x.useState(a9()),[c,u]=x.useState(!1),[p,m]=x.useState(null);async function g(){const h=t.trim();if(!h){m(f("pairing.err_required"));return}u(!0),m(null);try{const b=await $l.confirm({pairing_id:h,label:o.trim()||void 0});fo(b.token);try{localStorage.setItem(Rn.token,b.token)}catch{}e()}catch(b){m(s9(b)),u(!1)}}return r.jsx("div",{className:"flex min-h-[100dvh] w-full items-center justify-center overflow-y-auto bg-background p-4 text-foreground",children:r.jsxs("div",{className:"my-auto w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-sm",children:[r.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[r.jsx("div",{className:"grid size-10 place-items-center rounded-lg bg-primary/10 text-primary",children:r.jsx(Ph,{size:20})}),r.jsxs("div",{children:[r.jsx("h1",{className:"text-base font-semibold",children:f("pairing.title")}),r.jsx("p",{className:"text-xs text-muted-fg",children:f("pairing.subtitle")})]})]}),r.jsxs("ol",{className:"mb-5 space-y-1.5 rounded-lg bg-muted/50 p-3 text-xs text-muted-fg",children:[r.jsx("li",{className:"font-medium text-foreground",children:f("pairing.steps_title")}),r.jsxs("li",{children:["1. ",f("pairing.step_1")]}),r.jsxs("li",{children:["2. ",f("pairing.step_2")]}),r.jsxs("li",{children:["3. ",f("pairing.step_3")]})]}),r.jsxs("form",{className:"space-y-3",onSubmit:h=>{h.preventDefault(),g()},children:[r.jsx(fe,{label:f("pairing.code_label"),children:r.jsx(Ae,{value:t,onChange:h=>s(h.target.value),placeholder:f("pairing.code_ph"),spellCheck:!1,autoComplete:"off"})}),r.jsx(fe,{label:f("pairing.label_label"),hint:f("pairing.revoke_hint"),children:r.jsx(Ae,{value:o,onChange:h=>l(h.target.value),placeholder:f("pairing.label_ph")})}),p&&r.jsx("p",{className:"rounded-md bg-destructive/10 px-3 py-2 text-xs text-destructive",children:p}),r.jsx(me,{type:"submit",variant:"primary",size:"md",loading:c,className:"w-full justify-center",children:f(c?"pairing.linking":"pairing.submit")})]})]})})}function a9(){const e=navigator.userAgent;return/iPhone|iPad/.test(e)?"iPhone":/Android/.test(e)?"Android":/Mac/.test(e)?"Mac":/Windows/.test(e)?"Windows PC":/Linux/.test(e)?"Linux":"browser"}function s9(e){if(e instanceof Fc){if(e.status===410)return f("pairing.err_expired");if(e.status===404||e.status===409)return f("pairing.err_unknown")}return f("pairing.err_generic")}function r9({...e}){return r.jsx(kC,{"data-slot":"sheet",...e})}function o9({...e}){return r.jsx(wC,{"data-slot":"sheet-portal",...e})}function l9({className:e,...t}){return r.jsx(vC,{"data-slot":"sheet-overlay",className:St("fixed inset-0 z-50 bg-black/10 transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs",e),...t})}function i9({className:e,children:t,side:s="right",showCloseButton:o=!0,...l}){return r.jsxs(o9,{children:[r.jsx(l9,{}),r.jsxs(jC,{"data-slot":"sheet-content","data-side":s,className:St("fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg transition duration-200 ease-in-out data-ending-style:opacity-0 data-starting-style:opacity-0 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=bottom]:data-ending-style:translate-y-[2.5rem] data-[side=bottom]:data-starting-style:translate-y-[2.5rem] data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=left]:data-ending-style:translate-x-[-2.5rem] data-[side=left]:data-starting-style:translate-x-[-2.5rem] data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=right]:data-ending-style:translate-x-[2.5rem] data-[side=right]:data-starting-style:translate-x-[2.5rem] data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=top]:data-ending-style:translate-y-[-2.5rem] data-[side=top]:data-starting-style:translate-y-[-2.5rem] data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm",e),...l,children:[t,o&&r.jsxs(sp,{"data-slot":"sheet-close",render:r.jsx(Ks,{variant:"ghost",className:"absolute top-3 right-3",size:"icon-sm"}),children:[r.jsx(ps,{}),r.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function c9({className:e,...t}){return r.jsx("div",{"data-slot":"sheet-header",className:St("flex flex-col gap-0.5 p-4",e),...t})}function u9({className:e,...t}){return r.jsx(SC,{"data-slot":"sheet-title",className:St("font-heading text-base font-medium text-foreground",e),...t})}function d9({className:e,...t}){return r.jsx(_C,{"data-slot":"sheet-description",className:St("text-sm text-muted-foreground",e),...t})}function f9({value:e,projectPath:t,onPick:s}){const o=p9(e),l=o?m9(e):"",{data:c}=Qe(o?["/skills",t||""]:null,()=>dc.list(t)),u=c?.skills||[],p=x.useMemo(()=>{const m=l.toLowerCase();return m?u.filter(g=>g.slug.toLowerCase().includes(m)).slice(0,8):u.slice(0,8)},[u,l]);return!o||p.length===0?null:r.jsxs("div",{className:"rounded-xl border border-border bg-popover/95 text-sm shadow-md backdrop-blur",children:[r.jsx("ul",{role:"listbox",className:"max-h-64 overflow-y-auto py-1",children:p.map(m=>r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>s(m.slug),className:"flex w-full items-start gap-2 px-3 py-1.5 text-left hover:bg-accent hover:text-accent-foreground",children:[r.jsxs("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[11px]",children:["/",m.slug]}),r.jsx("span",{className:"truncate text-xs text-muted-foreground",children:m.description})]})},m.slug))}),r.jsx("div",{className:"border-t border-border px-3 py-1.5 text-[10px] text-muted-foreground",children:"Type a name to filter · click to insert · the skill body will be loaded for this turn."})]})}function p9(e){return!!e.match(/^\s*\/([A-Za-z0-9_-]*)$/)}function m9(e){const t=e.match(/^\s*\/([A-Za-z0-9_-]*)$/);return t?t[1]:""}function g9(){try{const e=localStorage.getItem(Rn.robyChat);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>s&&Array.isArray(s.parts)&&!s.pending):[]}catch{return[]}}function h9({open:e,onOpenChange:t}){const s=Fb(),o=lt(),[l,c]=x.useState(g9),[u,p]=x.useState(""),[m,g]=x.useState(!1),[h,b]=x.useState(""),_=x.useRef(null);x.useEffect(()=>{const C=l.filter(E=>!E.pending);try{C.length?localStorage.setItem(Rn.robyChat,JSON.stringify(C)):localStorage.removeItem(Rn.robyChat)}catch{}},[l]);const k=()=>{if(!m){c([]),p("");try{localStorage.removeItem(Rn.robyChat)}catch{}}};x.useEffect(()=>()=>_.current?.abort(),[]);const N=()=>{_.current?.abort(),g(!1)},y=C=>c(E=>{const R=[...E],A=R[R.length-1];return A?.role==="assistant"&&(R[R.length-1]=C(A)),R}),w=async()=>{const C=u.trim();if(!C||m)return;const E=new Date().toISOString(),R=l.filter(z=>!z.pending).map(z=>({role:z.role,content:gx(z)}));c(z=>[...z,{role:"user",parts:[{kind:"text",text:C}],ts:E},{role:"assistant",parts:[],ts:E,pending:!0}]),p(""),g(!0);const A=new AbortController;_.current=A;let T=!1;const O=z=>{if(z?.type==="error"){T=!0,o.error(z.error||"error"),c(L=>{const D=[...L],U=D[D.length-1];return U?.role==="assistant"&&U.pending&&D.pop(),D});return}y(L=>uv(L,z))};try{await fC.stream(0,{prompt:C,previousMessages:R,model:h||void 0,channel:"web_sidebar"},O,A.signal),y(z=>({...z,pending:!1}))}catch(z){A.signal.aborted?y(L=>({...L,pending:!1,parts:[...L.parts,{kind:"text",text:f("project.chat.stopped_marker")}]})):T||(o.error(z.message),c(L=>{const D=[...L],U=D[D.length-1];return U?.role==="assistant"&&U.pending&&D.pop(),D}))}finally{_.current===A&&(_.current=null),g(!1)}},S=async C=>{try{await navigator.clipboard.writeText(C),o.info(f("project.chat.copied"))}catch{}};return r.jsx(r9,{open:e,onOpenChange:t,children:r.jsxs(i9,{side:"right",className:"flex w-full flex-col gap-0 p-0 sm:max-w-xl data-[side=right]:sm:max-w-xl",children:[r.jsxs(c9,{className:"pr-12",children:[r.jsxs(u9,{className:"flex items-center gap-2",children:[r.jsx(hn,{size:18})," ",f("superagent.title",{persona:s}),r.jsx("span",{className:"text-xs font-normal text-muted-fg",children:f("superagent.badge")})]}),r.jsx(d9,{children:f("superagent.desc")})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:l.length===0?r.jsx("p",{className:"mt-6 text-center text-sm text-muted-fg",children:f("superagent.empty",{persona:s})}):r.jsx(dv,{msgs:l,onCopy:S})}),r.jsx(mN,{msgs:l}),r.jsxs("div",{className:"border-t border-border p-3",children:[r.jsx("div",{className:"mb-1.5",children:r.jsx(f9,{value:u,onPick:C=>p(`/${C} `)})}),r.jsx(iv,{value:u,onValueChange:p,onSubmit:()=>void w(),onStop:N,busy:m,placeholder:f("superagent.placeholder"),footer:r.jsx(cv,{value:h,onChange:b,disabled:m})}),r.jsx("div",{className:"mt-1.5 flex justify-end",children:r.jsxs(Ks,{size:"xs",variant:"ghost",onClick:k,disabled:m||l.length===0,children:[r.jsx(rn,{className:"size-3"})," ",f("superagent.new_chat")]})})]})]})})}function x9(){const e=navigator.userAgent;return/iPhone|iPad/.test(e)?"iPhone":/Android/.test(e)?"Android":/Mac/.test(e)?"Mac":/Windows/.test(e)?"Windows PC":/Linux/.test(e)?"Linux":"browser"}function b9(){const[e,t]=x.useState({status:"loading"}),[s,o]=x.useState(0),l=x.useCallback(()=>{t({status:"loading"}),o(c=>c+1)},[]);return x.useEffect(()=>{let c=!1;return(async()=>{try{const h=await fetch("/health");if(!h.ok)throw new Error(`HTTP ${h.status}`)}catch(h){c||t({status:"error",reason:String(h)});return}const u=window.location.hash.replace(/^#/,""),p=new URLSearchParams(u),m=p.get("pair");if(m){history.replaceState(null,"",window.location.pathname+window.location.search);try{const h=await $l.confirm({pairing_id:m,label:x9(),kind:"web"});fo(h.token);try{localStorage.setItem(Rn.token,h.token)}catch{}c||t({status:"ok"});return}catch{}}const g=p.get("token");if(g){fo(g);try{localStorage.setItem(Rn.token,g)}catch{}history.replaceState(null,"",window.location.pathname+window.location.search)}else try{const h=localStorage.getItem(Rn.token);h&&fo(h)}catch{}try{const h=await fetch("/admin/web-token");if(h.ok){const b=await h.json();if(b?.token){fo(b.token);try{localStorage.setItem(Rn.token,b.token)}catch{}}}}catch{}if(!Hb()){c||t({status:"unpaired"});return}try{await ge.get("/projects"),c||t({status:"ok"})}catch(h){if(h instanceof Fc&&(h.status===401||h.status===403)){fo(null);try{localStorage.removeItem(Rn.token)}catch{}c||t({status:"unpaired"})}else c||t({status:"error",reason:String(h)})}})(),()=>{c=!0}},[s]),{...e,reload:l}}function v9(){const e=b9();return e.status==="loading"?r.jsx(ok,{text:f("daemon.connecting")}):e.status==="error"?r.jsx(ok,{mood:"sad",text:f("daemon.unreachable"),sub:`${f("daemon.unreachable_hint")}
654
654
 
655
655
  ${e.reason}`}):e.status==="unpaired"?r.jsx(n9,{onPaired:e.reload}):r.jsx(AP,{children:r.jsx($4,{delay:0,children:r.jsx(_9,{})})})}function _9(){const e=Qn(),t=Kn(),[s,o]=kf(),{theme:l,toggle:c}=qx(),u=s.get("action")==="add-project",[p,m]=x.useState(!1),g=()=>{const b=new URLSearchParams(s);b.delete("action"),o(b,{replace:!0})},h=()=>{const b=new URLSearchParams(s);b.set("action","add-project"),o(b)};return r.jsx(PP,{children:r.jsxs("div",{className:"flex h-screen w-screen overflow-hidden bg-background text-foreground","data-testid":"app-shell",children:[r.jsx(qD,{onSelect:b=>e(b),onOpenRoby:()=>m(!0),onOpenAddProject:h}),r.jsxs("main",{className:"m-2 ml-0 flex min-w-0 flex-1 flex-col overflow-hidden rounded-xl border border-border bg-card shadow-sm",children:[r.jsx(y9,{onToggleTheme:c,isDark:l==="dark",pathname:t.pathname}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsxs(Nk,{children:[r.jsx(Kt,{path:"/",element:r.jsx(DP,{})}),r.jsx(Kt,{path:"/settings/*",element:r.jsx(F7,{})}),r.jsx(Kt,{path:"/m/desktop/*",element:r.jsx(X7,{})}),r.jsx(Kt,{path:"/m/code/*",element:r.jsx(e9,{})}),r.jsx(Kt,{path:"/p/:pid/*",element:r.jsx(k8,{})}),r.jsx(Kt,{path:"*",element:r.jsx(C9,{})})]})})]}),r.jsx(t9,{open:u,onClose:g}),r.jsx(h9,{open:p,onOpenChange:m})]})})}function y9({onToggleTheme:e,isDark:t,pathname:s}){const{projects:o}=Gc(),l=BP(),c=s.split("/").filter(Boolean),u=c[0]==="p"?o.find(N=>String(N.id)===c[1]):void 0,p=c[0]==="settings"?k9(c[1]):c[0]==="p"?S9(c[2]):"",m=c[0]==="p"&&c[1]==="0",g=u?.name||u?.path?.split("/").pop()||f("nav.project"),h=s==="/"?f("topbar.breadcrumb_root"):c[0]==="settings"?[f("topbar.breadcrumb_root"),f("nav.settings"),p].filter(Boolean).join(" › "):c[0]==="m"?[f("topbar.breadcrumb_root"),w9(c[1]),l].filter(Boolean).join(" › "):c[0]==="p"?m?[f("topbar.breadcrumb_root"),f("topbar.breadcrumb_base"),p].filter(Boolean).join(" › "):[f("topbar.breadcrumb_root"),f("topbar.breadcrumb_projects"),g,p].filter(Boolean).join(" › "):f("topbar.breadcrumb_root"),b=s==="/"?"":c[0]==="settings"?f("settings.subtitle"):c[0]==="p"?m?f("base.subtitle"):u?`${mC(u.kind)} · ${u.path}`:"":"",_=LP(),k=HP();return r.jsxs("header",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-border/50 px-3",children:[_&&r.jsx(tD,{collapsed:_.collapsed,onToggle:_.toggle}),r.jsxs("span",{className:"min-w-0 flex-1 truncate text-[11px] tracking-wide text-muted-fg",children:[h,b&&r.jsxs("span",{className:"text-muted-fg/50",children:[" · ",b]})]}),k,r.jsx(j9,{}),r.jsx(et,{content:f(t?"topbar.light":"topbar.dark"),children:r.jsx("button",{type:"button","data-testid":"theme-toggle",onClick:e,className:"shrink-0 rounded-md p-1.5 text-muted-fg hover:bg-accent hover:text-accent-fg",children:t?r.jsx(HM,{size:14}):r.jsx(MM,{size:14})})})]})}function j9(){const e=eC(),t=s=>{s!==e&&(W2(s),window.location.reload())};return r.jsxs(K2,{children:[r.jsxs(Q2,{"data-testid":"lang-menu",title:f("topbar.lang_toggle"),className:"flex shrink-0 items-center gap-1 rounded-md p-1.5 text-muted-fg hover:bg-accent hover:text-accent-fg",children:[r.jsx(NM,{size:14}),r.jsx("span",{className:"text-[11px] font-medium uppercase",children:e})]}),r.jsx(Z2,{align:"end",children:r.jsx(Yz,{value:e,onValueChange:s=>t(s),children:J2.map(s=>r.jsx(Xz,{value:s.value,children:s.label},s.value))})})]})}function w9(e){switch(e){case"desktop":return f("nav.modules.desktop");case"code":return f("nav.modules.code");default:return e||""}}function k9(e){switch(e){case"super-agent":return f("settings.tabs.super_agent");case"engines":return f("settings.tabs.engines");case"telegram":return f("settings.tabs.telegram");case"devices":return f("settings.tabs.devices");case"voice":return f("nav.modules.voice");case"deck":return f("nav.modules.deck");case"desktop":return f("nav.modules.desktop");case"appearance":return f("settings.appearance");case"config":case"advanced":return f("settings.tabs.advanced");case"identity":default:return e||""}}function S9(e){switch(e){case"chat":return f("project.nav.chat");case"telegram":return f("project.nav.telegram");case"agents":return f("project.nav.agents");case"routines":return f("project.nav.routines");case"tasks":return f("project.nav.tasks");case"mcps":return f("project.nav.mcps");case"config":return f("project.nav.config");case"workspaces":return f("base.workspaces_title");case"models":return f("settings.tabs.engines");case"agent-defaults":return f("base.defaults_title");case"sessions":return f("base.sessions_title");case"logs":return f("project.nav.logs");case"memories":return f("project.nav.memories");default:return""}}function ok({text:e,sub:t,mood:s="happy"}){return r.jsx("div",{className:"grid h-screen w-screen place-items-center bg-background text-foreground",children:r.jsxs("div",{className:"flex flex-col items-center text-center",children:[r.jsx(IC,{mood:s,className:"mb-4 text-xs"}),r.jsx("div",{className:"text-foreground",children:e}),t&&r.jsx("pre",{className:"mt-2 max-w-xl whitespace-pre-wrap text-sm text-muted-fg",children:t})]})})}function C9(){const e=Qn();return r.jsx(BC,{testId:"screen-not-found",mood:"confused",title:f("not_found.title"),titleClassName:"text-7xl",message:f("not_found.message"),action:r.jsx(Ks,{variant:"outline",onClick:()=>e("/"),children:f("not_found.home")})})}fT.createRoot(document.getElementById("root")).render(r.jsx(Lc.StrictMode,{children:r.jsx(PA,{children:r.jsx(XM,{children:r.jsx(v9,{})})})}));
656
- //# sourceMappingURL=index-D7px5xcy.js.map
656
+ //# sourceMappingURL=index-oOjZZktw.js.map