@agentprojectcontext/apx 1.49.0 → 1.50.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)}},Eh=a,E
647
647
  The chosen QR Code version cannot contain this amount of data.
648
648
  Minimum version required to store current data is: `+H+`.
649
649
  `);const I=E(M,z,D),B=e.getSymbolSize(M),V=new o(B);return k(V,M),N(V),j(V,M),S(V,z,0),M>=7&&y(V,M),C(V,I),isNaN(L)&&(L=u.getBestMask(V,S.bind(null,V,z))),u.applyMask(L,V),S(V,z,L),{modules:V,version:M,errorCorrectionLevel:z,maskPattern:L,segments:D}}return dh.create=function(M,z){if(typeof M>"u"||M==="")throw new Error("No input text");let L=t.M,D,H;return typeof z<"u"&&(L=t.from(z.errorCorrectionLevel,t.M),D=g.from(z.version),H=u.from(z.maskPattern),z.toSJISFunc&&e.setToSJISFunction(z.toSJISFunc)),A(M,D,L,H)},dh}var Th={},Ah={},Bw;function MN(){return Bw||(Bw=1,(function(e){function t(a){if(typeof a=="number"&&(a=a.toString()),typeof a!="string")throw new Error("Color should be defined as hex string");let o=a.slice().replace("#","").split("");if(o.length<3||o.length===5||o.length>8)throw new Error("Invalid hex color: "+a);(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 v=0;v<g;v++)for(let k=0;k<g;k++){let N=(v*g+k)*4,j=c.color.light;if(v>=h&&k>=h&&v<g-h&&k<g-h){const y=Math.floor((v-h)/m),S=Math.floor((k-h)/m);j=b[p[y*u+S]?1:0]}o[N++]=j.r,o[N++]=j.g,o[N++]=j.b,o[N]=j.a}}})(Ah)),Ah}var Uw;function l7(){return Uw||(Uw=1,(function(e){const t=MN();function a(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"),v=b.createImageData(h,h);return t.qrToImageData(v.data,c,m),a(b,g,h),b.putImageData(v,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)}})(Th)),Th}var Mh={},Hw;function i7(){if(Hw)return Mh;Hw=1;const e=MN();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 a(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 v=Math.floor(b%c),k=Math.floor(b/c);!v&&!g&&(g=!0),l[b]?(h++,b>0&&v>0&&l[b-1]||(p+=g?a("M",v+u,.5+k+u):a("m",m,0),m=0,g=!1),v+1<c&&l[b+1]||(p+=a("h",h),h=0)):m++}return p}return Mh.render=function(c,u,p){const m=e.getOptions(u),g=c.modules.size,h=c.modules.data,b=g+m.margin*2,v=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+'"',y='<svg xmlns="http://www.w3.org/2000/svg" '+(m.width?'width="'+m.width+'" height="'+m.width+'" ':"")+N+' shape-rendering="crispEdges">'+v+k+`</svg>
650
- `;return typeof p=="function"&&p(null,y),y},Mh}var Vw;function c7(){if(Vw)return vl;Vw=1;const e=q8(),t=o7(),a=l7(),o=i7();function l(c,u,p,m,g){const h=[].slice.call(arguments,1),b=h.length,v=typeof h[b-1]=="function";if(!v&&!e())throw new Error("Callback required as last argument");if(v){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 j=t.create(p,m);k(c(j,u,m))}catch(j){N(j)}})}try{const k=t.create(p,m);g(null,c(k,u,m))}catch(k){g(k)}}return vl.create=t.create,vl.toCanvas=l.bind(null,a.render),vl.toDataURL=l.bind(null,a.renderToDataURL),vl.toString=l.bind(null,function(c,u,p){return o.render(c,p)}),vl}var u7=c7();const d7=Ex(u7);function f7({value:e,size:t=200}){const[a,o]=x.useState(null);return x.useEffect(()=>{let l=!0;return d7.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:a?r.jsx("img",{src:a,width:t,height:t,alt:"QR"}):r.jsx("div",{className:"size-full animate-pulse rounded bg-muted"})})}function p7(e){return e.find(t=>!t.includes("127.0.0.1")&&!t.includes("localhost"))||e[0]||window.location.origin}function m7({open:e,onClose:t,onPaired:a}){const o=rt(),[l,c]=x.useState(null),[u,p]=x.useState(null),[m,g]=x.useState(0),[h,b]=x.useState(!1),v=x.useRef(null),k=x.useCallback(async()=>{c(null),p(null),b(!1);try{const C=await Fl.init();c(C),g(Math.round((C.ttl_ms||9e4)/1e3))}catch(C){C instanceof Kc&&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 Fl.status(l.pairing_id);if(!C)return;if(R.status==="confirmed"){b(!0),o.success(f("settings.devices_pair_done")),a(),window.setTimeout(()=>{C&&t()},900);return}if(R.status==="expired"||R.status==="unknown"){g(0);return}}catch{}v.current=window.setTimeout(E,1500)};return v.current=window.setTimeout(E,1500),()=>{C=!1,v.current&&window.clearTimeout(v.current)}},[e,l,h,t,a,o]);const N=!!l&&!h&&m<=0,j=l?p7(l.lan_urls):"",y=l?`${j}/#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(ie,{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(_s,{})," ",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(f7,{value:y,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(ie,{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(_s,{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:y}),r.jsx(Ye,{content:f("settings.devices_pair_copy"),children:r.jsx(ie,{size:"sm",variant:"secondary",onClick:()=>S(y,f("settings.devices_pair_copied")),children:r.jsx(Ec,{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(Ye,{content:f("settings.devices_pair_copy"),children:r.jsx(ie,{size:"sm",variant:"secondary",onClick:()=>S(l.pairing_id,f("settings.devices_pair_copied_code")),children:r.jsx(Ec,{size:14})})})]})]})]})]})]})]})}function g7(){const e=rt(),{clients:t,isLoading:a,mutate:o}=V8(),[l,c]=x.useState(!1),u=async p=>{if(confirm(f("settings.devices_revoke_confirm",{id:p})))try{await Fl.revoke(p),e.success(f("settings.devices_revoke_success")),o()}catch(m){e.error(m.message)}};return r.jsxs(Ke,{title:f("settings.devices"),description:f("settings.devices_sub"),action:r.jsxs(ie,{size:"sm",variant:"primary",onClick:()=>c(!0),children:[r.jsx(HM,{size:14})," ",f("settings.devices_pair_btn")]}),children:[a&&r.jsx(lt,{}),!a&&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(ie,{size:"sm",variant:"destructive",onClick:()=>u(p.id),children:f("settings.devices_revoke")})]},p.id))}),r.jsx(m7,{open:l,onClose:()=>c(!1),onPaired:()=>o()})]})}const h7=[{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:Fx.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 x7(){const{config:e,isLoading:t,patch:a,mutate:o}=Vr();if(t)return r.jsx(lt,{});const l=async c=>{const u={};for(const[p,m]of Object.entries(l_(c)))os(m)||(u[p]=m);await a(u),o()};return r.jsx(Ke,{title:f("global_config.title"),description:f("settings_ui.global_config_desc"),children:r.jsx(xx,{sections:h7,source:e,jsonTitle:"~/.apx/config.json",jsonDescription:f("settings_ui.global_json_desc"),onSaveFields:async(c,u)=>{await a(c,u),o()},onSaveJson:l})})}function b7(){const e=rt(),{health:t,isUp:a}=AC(),o=async()=>{try{await $l.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(Ke,{title:f("daemon.version"),action:r.jsx(ie,{size:"sm",onClick:o,children:f("common.reload")}),children:r.jsxs("div",{className:"grid grid-cols-3 gap-3 text-sm",children:[r.jsx(Oh,{label:f("daemon.version"),value:t?.version||"—"}),r.jsx(Oh,{label:f("daemon.uptime"),value:t?`${t.uptime_s}s`:"—"}),r.jsx(Oh,{label:f("daemon.status"),value:f(a?"daemon.running":"daemon.down"),ok:a})]})}),r.jsx(x7,{})]})}function Oh({label:e,value:t,ok:a}){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:[a!==void 0&&r.jsx(Qc,{ok:a}),r.jsx("span",{children:t})]})]})}function _7(){const e=rt(),{theme:t,set:a}=Gx(),[o,l]=x.useState(""),[c,u]=x.useState(aC()),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=>{nC(g),u(g),window.location.reload()};return r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2 xl:items-start",children:[r.jsx(Ke,{title:f("settings.appearance"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ie,{variant:t==="light"?"primary":"secondary",onClick:()=>a("light"),children:f("settings.light_mode")}),r.jsx(ie,{variant:t==="dark"?"primary":"secondary",onClick:()=>a("dark"),children:f("settings.dark_mode")})]})}),r.jsx(Ke,{title:f("settings.language"),children:r.jsx("div",{className:"flex items-center gap-2",children:sC.map(g=>r.jsx(ie,{variant:c===g.value?"primary":"secondary",onClick:()=>m(g.value),children:g.label},g.value))})}),r.jsxs(Ke,{title:f("settings.token"),description:f("settings.token_sub"),children:[r.jsx(ue,{label:f("settings_ui.bearer_label"),children:r.jsx(Re,{type:"password",placeholder:$b()?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(ie,{variant:"primary",onClick:p,children:f("common.save")})})]})]})}function v7({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 kx=typeof navigator<"u"&&/mac/i.test(navigator.platform||"");function y7(e){return(kx?{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 j7(e){return(e||"").split("+").map(t=>t.trim()).filter(Boolean)}function w7(e){const t=e.code;if(/^(Shift|Control|Alt|Meta|OS)(Left|Right)?$/.test(t))return null;let a;if((a=t.match(/^Key([A-Z])$/))||(a=t.match(/^Digit(\d)$/))||(a=t.match(/^Numpad(\d)$/))||(a=t.match(/^(F\d{1,2})$/))||(a=t.match(/^Arrow(Up|Down|Left|Right)$/)))return a[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 k7(e){const t=w7(e);if(!t)return null;const a=[];(kx?e.metaKey:e.ctrlKey)&&a.push("CommandOrControl"),kx&&e.ctrlKey&&a.push("Control"),e.altKey&&a.push("Alt"),e.shiftKey&&a.push("Shift");const o=a.length>0,l=/^F\d{1,2}$/.test(t);return!o&&!l?null:(a.push(t),a.join("+"))}function S7({value:e,onChange:t,disabled:a,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=k7(h);b&&(t(b),u(!1))};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[c,t]);const m=j7(e);return r.jsxs("div",{className:Me("flex h-9 w-full max-w-md items-center rounded-md border border-border bg-transparent transition",c&&"ring-2 ring-ring",a&&"opacity-50",o),children:[r.jsxs("button",{ref:p,type:"button",disabled:a,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(v7,{className:"h-6 min-w-6 border border-border bg-muted px-1.5 text-[13px] font-semibold text-fg shadow-sm",children:y7(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 kl={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 C7(e=30){return ge.get(`/messages/global?channel=desktop&limit=${e}`)}function ON({showConfigLink:e=!1}){const t=rt(),{data:a,isLoading:o,mutate:l}=et("/desktop/status",()=>kl.status(),{refreshInterval:5e3}),c=!!a?.running,[u,p]=x.useState(null),m=async(v,k)=>{p(v);try{await k()}catch(N){t.error(N.message)}finally{p(null),setTimeout(()=>l(),1200)}},g=()=>m("start",async()=>{const v=await kl.start();t.success(v.already?f("modules_ui.desktop_start_already"):f("modules_ui.desktop_start_done"))}),h=()=>m("stop",async()=>{const v=await kl.stop();t.success(v.stopped?f("modules_ui.desktop_stop_done"):f("modules_ui.desktop_stop_none"))}),b=()=>m("restart",async()=>{(await kl.restart()).reloaded>0?t.success(f("modules_ui.desktop_restart_done")):t.info(f("modules_ui.desktop_restart_none"))});return r.jsx(Ke,{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(ie,{variant:"primary",size:"sm",onClick:g,loading:u==="start",disabled:c||u!==null&&u!=="start",children:f("modules_ui.desktop_start")}),r.jsx(ie,{variant:"secondary",size:"sm",onClick:h,loading:u==="stop",disabled:!c||u!==null&&u!=="stop",children:f("modules_ui.desktop_stop")}),r.jsx(ie,{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(Sf,{to:"/settings/desktop",children:r.jsxs(ie,{size:"sm",variant:"ghost",children:[r.jsx(Rc,{size:14})," ",f("desktop_screen.open_config")]})})]}),children:o?r.jsx(lt,{}):r.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-sm",children:[r.jsx(Qc,{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(Pj,{children:"apx desktop start"})," · ",r.jsx(Pj,{children:"apx desktop --debug"}),")"]})]})})}const N7="CommandOrControl+G",E7=()=>[{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")}],R7=()=>[{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 T7(){const e=rt(),{config:t,isLoading:a,patch:o}=Vr(),l=t,c=l.desktop?.shortcut||l.overlay?.shortcut||N7,u=l.desktop?.enabled!==!1,p=l.desktop?.theme||"system",m=l.desktop?.position||"right",{data:g,mutate:h}=et("/desktop/autostart",()=>kl.autostartGet()),[b,v]=x.useState(c),[k,N]=x.useState(!1),[j,y]=x.useState(!1);x.useEffect(()=>v(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(M){e.error(M.message)}finally{N(!1)}},E=async R=>{y(!0);try{await kl.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{y(!1)}};return r.jsxs("div",{className:"space-y-6","data-testid":"settings-desktop",children:[r.jsx(ON,{}),r.jsx(Ke,{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:j,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(lt,{})}),r.jsx(Ke,{title:f("desktop_screen.shortcut_title"),description:f("modules_ui.desktop_shortcut_desc"),children:a?r.jsx(lt,{}):r.jsx(ue,{label:f("modules_ui.desktop_accelerator"),hint:f("modules_ui.desktop_accelerator_hint"),children:r.jsx(S7,{value:b,onChange:v,disabled:k,trailing:r.jsx(ie,{variant:"primary",size:"sm",onClick:S,loading:k,disabled:!b.trim()||b.trim()===c,children:f("common.save")})})})}),r.jsx(Ke,{title:f("desktop_screen.appearance_title"),description:f("modules_ui.desktop_appearance_desc"),children:a?r.jsx(lt,{}):r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("modules_ui.desktop_theme"),hint:f("modules_ui.desktop_restart_apply"),children:r.jsx(bt,{value:p,onChange:R=>C("desktop.theme",R,f("modules_ui.desktop_theme_set",{value:R})),options:R7(),disabled:k})}),r.jsx(ue,{label:f("modules_ui.desktop_position"),hint:f("modules_ui.desktop_position_hint"),children:r.jsx(bt,{value:m,onChange:R=>C("desktop.position",R,f("modules_ui.desktop_position_set",{value:R})),options:E7(),disabled:k})})]})}),r.jsx(Ke,{title:f("desktop_screen.activation_title"),description:f("modules_ui.desktop_activation_desc"),children:a?r.jsx(lt,{}):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(Sf,{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 A7({engines:e,order:t,mode:a,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))],v=a==="chain",k=(N,j)=>{const y=b.indexOf(N),S=y+j;if(y<0||S<0||S>=b.length)return;const C=[...b];[C[y],C[S]]=[C[S],C[y]],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(v?"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:Me("px-3 py-1.5 text-xs font-medium transition-colors",v?"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:Me("border-l border-border px-3 py-1.5 text-xs font-medium transition-colors",v?"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,j)=>{const y=h.get(N),S=mf[N]||{name:N,note:""},C=!v&&o===N,E=N==="mock";return r.jsxs("div",{"data-testid":`voice-provider-${N}`,className:Me("flex items-center gap-3 rounded-lg border px-3 py-2.5",C?"border-emerald-500/50 bg-emerald-500/10":"border-border",v&&!E&&!y.enabled&&"opacity-60"),children:[v&&r.jsxs("div",{className:"flex flex-col",children:[r.jsx("button",{type:"button",onClick:()=>k(N,-1),disabled:g||j===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(Uk,{className:"size-3.5"})}),r.jsx("button",{type:"button",onClick:()=>k(N,1),disabled:g||j===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(Wa,{className:"size-3.5"})})]}),r.jsx(Qc,{ok:y.available?!0:y.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")}),y.available?r.jsx(Fe,{tone:"success",children:f("voice_ui.badge_available")}):y.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:[v?r.jsx(Qt,{checked:E?!0:y.enabled,onChange:R=>u(N,R),disabled:g||E}):!C&&r.jsxs(ie,{size:"sm",variant:"ghost",onClick:()=>c(N),disabled:g,"data-testid":`voice-provider-${N}-default`,children:[r.jsx(lM,{className:"size-3.5"})," ",f("voice_ui.set_as_default")]}),C&&r.jsx(Lx,{className:"size-4 text-emerald-400"}),r.jsxs(ie,{size:"sm",variant:"secondary",onClick:()=>m(N),"data-testid":`voice-provider-${N}-config`,children:[r.jsx(VM,{className:"size-3.5"})," ",f("voice_ui.configure")]})]})]},N)})})]})}function Os(e){return typeof e=="string"?e:e==null?"":String(e)}function M7({open:e,providerId:t,config:a,onClose:o,onSave:l}){const[c,u]=x.useState(!1),[p,m]=x.useState(null),[g,h]=x.useState(""),[b,v]=x.useState({});if(x.useEffect(()=>{if(!e||!t)return;m(null),h("");const R=a||{};if(t==="piper"){const A=R;v({bin:Os(A.bin),model:Os(A.model),speaker:Os(A.speaker)})}else if(t==="elevenlabs"){const A=R;v({model:Os(A.model),voice_id:Os(A.voice_id),output_format:Os(A.output_format)})}else if(t==="openai"){const A=R;v({model:Os(A.model)||"tts-1",voice:Os(A.voice)||"alloy",format:Os(A.format)||"mp3"})}else if(t==="gemini"){const A=R;v({model:Os(A.model),voice:Os(A.voice)||"Kore",style:Os(A.style)})}else v({})},[e,t,a]),!t)return null;const k=mf[t],N=`voice.tts.${t}`,j=R=>v(A=>({...A,...R})),y=t!=="piper"&&t!=="mock",S=y&&os(a?.api_key),C=S?f("voice_ui.api_key_set",{suffix:jo(a?.api_key)??""}):f("voice_ui.api_key_label"),E=async()=>{u(!0),m(null);try{const R={},A=[],T=(M,z)=>{z.trim()?R[`${N}.${M}`]=z.trim():A.push(`${N}.${M}`)};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)),y&&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(ie,{variant:"ghost",onClick:o,disabled:c,children:f("common.cancel")}),r.jsx(ie,{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(ue,{label:f("voice_ui.piper_bin_label"),hint:f("voice_ui.piper_bin_hint"),children:r.jsx(Re,{value:b.bin,onChange:R=>j({bin:R.target.value}),placeholder:"piper"})}),r.jsx(ue,{label:f("voice_ui.piper_model_label"),hint:f("voice_ui.piper_model_hint"),children:r.jsx(Re,{value:b.model,onChange:R=>j({model:R.target.value}),placeholder:"/abs/path/voice.onnx"})}),r.jsx(ue,{label:f("voice_ui.piper_speaker_label"),hint:f("voice_ui.piper_speaker_hint"),children:r.jsx(Re,{value:b.speaker,onChange:R=>j({speaker:R.target.value}),placeholder:"0"})})]}),t==="elevenlabs"&&r.jsxs(r.Fragment,{children:[r.jsx(ue,{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(Re,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(ue,{label:f("voice_ui.model_label"),children:r.jsx(bt,{value:b.model||"",onChange:R=>j({model:R}),options:UD.map(R=>({value:R,label:R})),placeholder:"eleven_multilingual_v2"})}),r.jsx(ue,{label:f("voice_ui.voice_id_label"),hint:f("voice_ui.voice_id_hint"),children:r.jsx(Re,{value:b.voice_id,onChange:R=>j({voice_id:R.target.value}),placeholder:"EXAVITQu4vr4xnSDxMaL"})}),r.jsx(ue,{label:f("voice_ui.output_format_label"),children:r.jsx(Re,{value:b.output_format,onChange:R=>j({output_format:R.target.value}),placeholder:"mp3_44100_128"})})]}),t==="openai"&&r.jsxs(r.Fragment,{children:[r.jsx(ue,{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(Re,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(ue,{label:f("voice_ui.model_label"),children:r.jsx(bt,{value:b.model||"tts-1",onChange:R=>j({model:R}),options:HD.map(R=>({value:R,label:R}))})}),r.jsx(ue,{label:f("voice_ui.voice_label"),children:r.jsx(bt,{value:b.voice||"alloy",onChange:R=>j({voice:R}),options:ID.map(R=>({value:R,label:R}))})}),r.jsx(ue,{label:f("voice_ui.format_label"),children:r.jsx(bt,{value:b.format||"mp3",onChange:R=>j({format:R}),options:["mp3","opus","aac","flac","wav"].map(R=>({value:R,label:R}))})})]}),t==="gemini"&&r.jsxs(r.Fragment,{children:[r.jsx(ue,{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(Re,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(ue,{label:f("voice_ui.model_label"),hint:f("voice_ui.gemini_model_hint"),children:r.jsx(Re,{value:b.model,onChange:R=>j({model:R.target.value}),placeholder:"gemini-2.5-flash-preview-tts"})}),r.jsx(ue,{label:f("voice_ui.voice_label"),children:r.jsx(bt,{value:b.voice||"Kore",onChange:R=>j({voice:R}),options:BD.map(R=>({value:R,label:R}))})}),r.jsx(ue,{label:f("voice_ui.style_label"),hint:f("voice_ui.style_hint"),children:r.jsx(Un,{rows:2,value:b.style||"",onChange:R=>j({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 O7(){const e=x.useRef(null),t=x.useRef(null),[a,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 qD(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:a,loading:l}}function z7({engines:e,defaultProvider:t,mode:a}){const o=rt(),{play:l,stop:c,playing:u,loading:p}=O7(),[m,g]=x.useState(f("voice_ui.test_default_text")),[h,b]=x.useState(""),[v,k]=x.useState(""),[N,j]=x.useState(!1),[y,S]=x.useState(null),E=[{value:"",label:a==="single"&&t&&t!=="auto"?f("voice_ui.test_default_engine",{name:mf[t]?.name||t}):f("voice_ui.test_default_chain")},...e.map(A=>({value:A.id,label:`${mf[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}j(!0);try{const T=await gf.say({text:A,provider:h||void 0,style:v.trim()||void 0});S(T),await l(T.audio_path)}catch(T){o.error(T.message||f("voice_ui.test_synth_error"))}finally{j(!1)}};return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("voice_ui.test_engine_label"),hint:f("voice_ui.test_engine_hint"),children:r.jsx(bt,{value:h,onChange:b,options:E})}),r.jsx(ue,{label:f("voice_ui.test_style_label"),hint:f("voice_ui.test_style_hint"),children:r.jsx(Re,{value:v,onChange:A=>k(A.target.value),placeholder:f("voice_ui.style_ph"),"data-testid":"voice-test-style"})})]}),r.jsx(ue,{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(ie,{variant:"primary",onClick:R,loading:N,disabled:p,"data-testid":"voice-test-say",children:[r.jsx(KM,{className:"size-4"})," ",f("voice_ui.say_this")]}),u?r.jsxs(ie,{variant:"secondary",onClick:c,"data-testid":"voice-test-stop",children:[r.jsx(Xk,{className:"size-4"})," ",f("voice_ui.stop")]}):y?r.jsxs(ie,{variant:"secondary",onClick:()=>l(y.audio_path),loading:p,"data-testid":"voice-test-replay",children:[r.jsx(Vx,{className:"size-4"})," ",f("voice_ui.replay")]}):null,y&&r.jsxs("span",{className:"text-xs text-muted-fg",children:[f("voice_ui.engine_result"),": ",r.jsx("strong",{children:y.provider}),y.duration_s?` · ${y.duration_s.toFixed(1)}s`:""]})]})]})}const qw={metal:{label:"Metal",cls:"text-emerald-400 border-emerald-500/40 bg-emerald-500/10"},cuda:{label:"CUDA",cls:"text-lime-400 border-lime-500/40 bg-lime-500/10"},rocm:{label:"Vulkan / ROCm",cls:"text-orange-400 border-orange-500/40 bg-orange-500/10"},none:{label:"CPU",cls:"text-muted-fg border-border bg-muted"}};function $w({gpu:e}){const t=qw[e]??qw.none;return r.jsx("span",{className:`inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] font-medium ${t.cls}`,children:t.label})}function D7(e){return e.backend==="mlx"?"Metal · mlx-whisper":e.backend==="faster"?(e.device==="cuda"?"CUDA":"CPU")+" · faster-whisper":e.backend}const P7=()=>[{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")}],Fw=()=>[{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 L7({config:e,onPatch:t,busy:a}){const[o,l]=x.useState(null);x.useEffect(()=>{let B=!0;return gf.sttHardware().then(V=>{B&&l(V)}).catch(()=>{}),()=>{B=!1}},[]);const c=e.provider||"auto",u=e.local||{},p=e.openai||{},m=e.custom||{},g=u.model||"small",h=u.language||"auto",b=c==="auto"||c==="local",v=(B,V,G)=>{const q=G.trim();q!==(V||"").trim()&&t({[B]:q})},k=(B,V)=>{const G=V.trim();!G||os(G)||t({[B]:G})},N=B=>os(B)?f("voice_ui.api_key_set",{suffix:jo(B)??""}):f("voice_ui.api_key_label"),j=u.backend||"auto",y=o?.hardware.gpu||"none",S=j==="auto"?o?.recommended.backend||"faster":j,C=S==="mlx",E=C?"metal":S==="faster"&&y==="cuda"?"cuda":"none",R=()=>{const B=[{value:"auto",label:f("voice_ui.stt_backend_auto")}];return y==="metal"&&B.push({value:"mlx",label:"Metal — mlx-whisper"}),B.push({value:"faster",label:y==="cuda"?"CUDA — faster-whisper":"CPU — faster-whisper"}),B},[A,T]=x.useState([]);x.useEffect(()=>{let B=!0;return gf.sttModels(S).then(V=>{B&&T(V.models)}).catch(()=>{B&&T([])}),()=>{B=!1}},[S]);const M=B=>`${B.id} · ${B.downloaded?"✓ "+B.size:B.size}`,z=()=>A.length?A.map(B=>({value:C?B.repo:B.id,label:M(B)})):VD.map(B=>({value:B,label:B})),L=C?u.mlx_model||o?.recommended.model||"":g,D=C?"transcription.local.mlx_model":"transcription.local.model",H=A.find(B=>(C?B.repo:B.id)===L),I=!!H&&!H.downloaded;return r.jsxs("div",{className:"space-y-3",children:[o&&r.jsxs("div",{className:"rounded-lg border border-border bg-muted px-3 py-2 text-sm",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsxs("span",{className:"text-muted-fg",children:[f("voice_ui.stt_hw_label"),":"]}),r.jsx($w,{gpu:o.hardware.gpu}),r.jsx("span",{className:"font-medium text-fg",children:o.hardware.gpuName||o.hardware.platform}),o.hardware.mem_gb?r.jsxs("span",{className:"text-muted-fg",children:["· ",o.hardware.mem_gb," GB",o.hardware.unified_memory?" unified":""]}):null]}),r.jsxs("div",{className:"mt-1 text-xs text-muted-fg",children:[f("voice_ui.stt_hw_recommended"),":"," ",r.jsx("span",{className:"text-fg",children:o.recommended.model})," ","(",D7(o.recommended),")",o.recommended.limited?` — ${f("voice_ui.stt_hw_limited")}`:""]})]}),r.jsx(ue,{label:f("voice_ui.stt_engine_label"),hint:f("voice_ui.stt_engine_hint"),children:r.jsx(bt,{value:c,onChange:B=>t({"transcription.provider":B}),options:P7(),disabled:a,className:"max-w-md"})}),b&&r.jsxs("div",{className:"space-y-3",children:[r.jsx(ue,{label:f("voice_ui.stt_backend_label"),hint:f("voice_ui.stt_backend_hint"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(bt,{value:j,onChange:B=>t({"transcription.local.backend":B}),options:R(),disabled:a,className:"max-w-xs"}),r.jsx($w,{gpu:E})]})}),r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("voice_ui.stt_model_label"),hint:I?f("voice_ui.stt_model_needs_download",{size:H.size}):f("voice_ui.stt_model_hint"),children:r.jsx(bt,{value:L,onChange:B=>t({[D]:B}),options:z(),disabled:a})}),r.jsx(ue,{label:f("voice_ui.stt_language_label"),hint:f("voice_ui.stt_language_hint"),children:r.jsx(bt,{value:h,onChange:B=>t({"transcription.local.language":B}),options:Fw(),disabled:a})})]})]}),c==="openai"&&r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("voice_ui.api_key_label"),hint:os(p.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(Re,{type:"password",autoComplete:"new-password",defaultValue:"",placeholder:N(p.api_key),onBlur:B=>k("transcription.openai.api_key",B.target.value),disabled:a})}),r.jsx(ue,{label:f("voice_ui.stt_openai_model_label"),hint:f("voice_ui.stt_openai_model_hint"),children:r.jsx(Re,{defaultValue:p.model||"",placeholder:"whisper-1",onBlur:B=>v("transcription.openai.model",p.model,B.target.value),disabled:a})})]}),c==="custom"&&r.jsxs("div",{className:"space-y-3",children:[r.jsx(ue,{label:f("voice_ui.stt_custom_baseurl_label"),hint:f("voice_ui.stt_custom_baseurl_hint"),children:r.jsx(Re,{defaultValue:m.base_url||"",placeholder:"http://localhost:8000/v1",onBlur:B=>v("transcription.custom.base_url",m.base_url,B.target.value),disabled:a})}),r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("voice_ui.stt_custom_model_label"),hint:f("voice_ui.stt_custom_model_hint"),children:r.jsx(Re,{defaultValue:m.model||"",placeholder:"mlx-community/whisper-large-v3-turbo",onBlur:B=>v("transcription.custom.model",m.model,B.target.value),disabled:a})}),r.jsx(ue,{label:f("voice_ui.stt_language_label"),hint:f("voice_ui.stt_language_hint"),children:r.jsx(bt,{value:m.language||"auto",onChange:B=>t({"transcription.custom.language":B}),options:Fw(),disabled:a})})]}),r.jsx(ue,{label:f("voice_ui.api_key_label"),hint:f("voice_ui.stt_custom_key_hint"),children:r.jsx(Re,{type:"password",autoComplete:"new-password",defaultValue:"",placeholder:N(m.api_key),onBlur:B=>k("transcription.custom.api_key",B.target.value),disabled:a})})]})]})}function I7(){const e=rt(),{config:t,isLoading:a,patch:o,mutate:l}=Vr(),{data:c,isLoading:u,error:p,mutate:m}=et("/tts/providers",()=>gf.providers()),[g,h]=x.useState(null),[b,v]=x.useState(!1),k=t,N=k.voice?.tts||{},j=k.transcription||{},y=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 H=>{v(!0);try{await o({"voice.tts.provider":H,"voice.tts.mode":"single"}),await m(),e.success(f("voice_ui.toast_default_engine",{id:H}))}catch(I){e.error(I.message)}finally{v(!1)}},T=async H=>{v(!0);try{const I={"voice.tts.mode":H};if(H==="single"&&(y==="auto"||!y)){const B=C.find(V=>V.available)?.id||E[0]||"mock";I["voice.tts.provider"]=B}await o(I),await m(),e.success(f(H==="chain"?"voice_ui.toast_mode_chain":"voice_ui.toast_mode_single"))}catch(I){e.error(I.message)}finally{v(!1)}},M=async(H,I)=>{v(!0);try{await o({[`voice.tts.${H}.enabled`]:I}),await m()}catch(B){e.error(B.message)}finally{v(!1)}},z=async H=>{v(!0);try{await o({"voice.tts.order":H}),await m()}catch(I){e.error(I.message)}finally{v(!1)}},L=async({set:H,unset:I})=>{await o(H,I.length?I:void 0),await m(),await l(),e.success(f("voice_ui.toast_config_saved"))},D=async(H,I)=>{try{await o(H,I),e.success(f("voice_ui.toast_transcription_updated"))}catch(B){e.error(B.message)}};return r.jsxs("div",{"data-testid":"screen-voice",children:[r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[r.jsx(Ke,{title:f("voice_screen.providers_title"),description:f("voice_ui.providers_desc"),children:u||a?r.jsx(lt,{}):p?r.jsx(xt,{children:f("voice_ui.providers_load_error",{msg:p.message})}):r.jsx(A7,{engines:C,order:E,mode:S,configuredProvider:y,onSetMode:T,onSetDefault:A,onToggleEnabled:M,onReorder:z,onConfigure:H=>h(H),busy:b})}),r.jsxs("div",{className:"space-y-6",children:[r.jsx(Ke,{title:f("voice_screen.test_title"),description:f("voice_ui.test_desc"),children:r.jsx(z7,{engines:C,defaultProvider:y,mode:S})}),r.jsx(Ke,{title:f("voice_screen.stt_title"),description:f("voice_ui.stt_desc"),children:a?r.jsx(lt,{}):r.jsx(L7,{config:j,onPatch:D})})]})]}),r.jsx(M7,{open:!!g,providerId:g,config:R,onClose:()=>h(null),onSave:L})]})}function B7(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 U7({manifest:e}){const t=e.daemon,a=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:B7(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:[a.direct_shell===!1&&r.jsx(Fe,{tone:"success",children:f("modules_ui.deck_safety_no_shell")}),a.arbitrary_commands===!1&&r.jsx(Fe,{tone:"success",children:f("modules_ui.deck_safety_no_arbitrary")}),a.dangerous_actions_require_confirmation&&r.jsx(Fe,{tone:"info",children:f("modules_ui.deck_safety_confirm")})]})]})}function H7(e){return e==="available"?"success":e==="configured"?"info":"muted"}function V7(e){return e==="available"?"activo":e==="configured"?"configurado":e==="disabled"?"deshabilitado":"sin configurar"}function q7(e){return e==="voice"?"warning":e==="plugin"?"info":"muted"}function $7({widget:e,onToggle:t}){const a=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:Me("flex items-center gap-3 rounded-lg border px-3 py-2.5 text-sm transition-colors",a?"border-border bg-muted/20 hover:border-muted-fg/30":"border-border/50 bg-muted/10"),children:[r.jsx(Ye,{content:e.source==="apx"?f("deck_screen.widget_native"):f("deck_screen.widget_external"),children:r.jsx("span",{className:Me("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:q7(e.kind),children:e.kind}),r.jsx(Fe,{tone:H7(e.status),children:V7(e.status)}),a?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 F7({desktop:e,widgets:t,onToggle:a}){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($7,{widget:o,onToggle:o.source==="external"?l=>a(o.id,l):void 0},o.id))})]})}function G7(){rt();const{data:e,error:t,isLoading:a,mutate:o}=et("/deck/manifest",()=>xC.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(U7,{manifest:e}),r.jsxs(Ke,{title:f("deck_screen.widgets_title"),description:a?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(Ye,{content:f("deck_screen.reload_manifest"),children:r.jsx(ie,{size:"sm",variant:"ghost",onClick:()=>o(),disabled:a,"aria-label":f("deck_screen.reload_manifest"),children:r.jsx(ua,{size:14,className:a?"animate-spin":""})})}),children:[a&&r.jsx(lt,{label:f("modules_ui.deck_loading_manifest_full")}),!a&&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")})]}),!a&&!t&&u.length===0&&r.jsx(xt,{children:f("modules_ui.deck_no_widgets")}),!a&&!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(F7,{desktop:h.desktop,widgets:h.widgets,onToggle:l},h.desktop.id))})]}),e?.apx&&r.jsx(Ke,{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(dM,{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 Y7=[{title:f("settings.account_section"),items:[{key:"identity",label:f("settings.tabs.identity"),icon:$x},{key:"appearance",label:f("settings.appearance"),icon:IM}]},{title:f("settings.agents_section"),items:[{key:"super_agent",label:f("settings.tabs.super_agent"),icon:un},{key:"engines",label:f("settings.tabs.engines"),icon:Ix},{key:"memory",label:"Memory (RAG)",icon:Hk},{key:"skills",label:"Skills (RAG)",icon:pa}]},{title:f("settings.channels_section"),items:[{key:"telegram",label:f("settings.tabs.telegram"),icon:Fs},{key:"devices",label:f("settings.tabs.devices"),icon:qM}]},{title:f("settings.modules_section"),items:[{key:"voice",label:f("nav.modules.voice"),icon:Gk},{key:"deck",label:f("nav.modules.deck"),icon:OM},{key:"desktop",label:f("nav.modules.desktop"),icon:Hx}]},{title:f("settings.advanced_section"),items:[{key:"advanced",label:f("settings.tabs.advanced"),icon:Xd}]}],K7=new Set(["engines","telegram","memory","skills","appearance","voice"]),X7={identity:()=>r.jsx(T8,{}),super_agent:()=>r.jsx(A8,{}),engines:()=>r.jsx(sN,{}),memory:()=>r.jsx(z8,{}),skills:()=>r.jsx(P8,{}),telegram:()=>r.jsx(H8,{}),devices:()=>r.jsx(g7,{}),voice:()=>r.jsx(I7,{}),deck:()=>r.jsx(G7,{}),desktop:()=>r.jsx(T7,{}),appearance:()=>r.jsx(_7,{}),advanced:()=>r.jsx(b7,{})};function Q7(){const e=Qn(),t=Xn(),a=Z7(t.pathname),o=X7[a],{collapsed:l,toggle:c}=Hb(Rn.sidebarCollapsed+".settings");return r.jsx(HC,{sections:Y7,active:a,onChange:u=>e(u==="identity"?"/settings":`/settings/${W7(u)}`),collapsed:l,onToggleCollapse:c,contentClassName:`w-full ${K7.has(a)?"":"mx-auto max-w-3xl"} space-y-6 p-6 pt-3`,testId:`settings-tab-${a}`,children:r.jsx(o,{})})}function Z7(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 W7(e){return e==="super_agent"?"super-agent":e==="advanced"?"config":e}function J7(){const{data:e,isLoading:t,mutate:a}=et("/messages/global?channel=desktop",()=>C7(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(ON,{showConfigLink:!0})}),r.jsx("div",{children:r.jsx(Ke,{title:f("desktop_screen.last_conv_title"),description:f("modules_ui.desktop_last_conv_desc"),action:r.jsx("button",{type:"button",onClick:()=>a(),className:"text-xs text-muted-fg underline-offset-2 hover:underline",children:f("modules_ui.desktop_refresh")}),children:r.jsx(eB,{messages:e||[],loading:t})})})]})})}function eB({messages:e,loading:t}){const a=x.useMemo(()=>nB(e),[e]);return t?r.jsx(lt,{}):e.length?r.jsx("div",{className:"space-y-3 max-h-[560px] overflow-y-auto pr-1",children:a.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(tB,{m:c},u))},l))}):r.jsx(xt,{children:f("modules_ui.desktop_no_messages")})}function tB({m:e}){const t=e.direction==="in",a=sB(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:a})]}),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 nB(e){const t=[];for(const a of e)a.direction==="in"||!t.length?t.push([a]):t[t.length-1].push(a);return t}function sB(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 aB(e,t){const a=getComputedStyle(e),o=parseFloat(a.fontSize);return t*o}function rB(e,t){const a=getComputedStyle(e.ownerDocument.documentElement),o=parseFloat(a.fontSize);return t*o}function oB(e){return e/100*window.innerHeight}function lB(e){return e/100*window.innerWidth}function iB(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 bc({groupSize:e,panelElement:t,styleProp:a}){let o;const[l,c]=iB(a);switch(c){case"%":{o=l/100*e;break}case"px":{o=l;break}case"rem":{o=rB(t,l);break}case"em":{o=aB(t,l);break}case"vh":{o=oB(l);break}case"vw":{o=lB(l);break}}return o}function Yn(e){return parseFloat(e.toFixed(3))}function Yl({group:e}){const{orientation:t,panels:a}=e;return a.reduce((o,l)=>(o+=t==="horizontal"?l.element.offsetWidth:l.element.offsetHeight,o),0)}function Sx(e){const{panels:t}=e,a=Yl({group:e});return a===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=bc({groupSize:a,panelElement:l,styleProp:c.collapsedSize});u=Yn(h/a*100)}let p;if(c.defaultSize!==void 0){const h=bc({groupSize:a,panelElement:l,styleProp:c.defaultSize});p=Yn(h/a*100)}let m=0;if(c.minSize!==void 0){const h=bc({groupSize:a,panelElement:l,styleProp:c.minSize});m=Yn(h/a*100)}let g=100;if(c.maxSize!==void 0){const h=bc({groupSize:a,panelElement:l,styleProp:c.maxSize});g=Yn(h/a*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 Cx(e,t){return Array.from(t).sort(e==="horizontal"?cB:uB)}function cB(e,t){const a=e.element.offsetLeft-t.element.offsetLeft;return a!==0?a:e.element.offsetWidth-t.element.offsetWidth}function uB(e,t){const a=e.element.offsetTop-t.element.offsetTop;return a!==0?a:e.element.offsetHeight-t.element.offsetHeight}function zN(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function DN(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 dB({orientation:e,rects:t,targetRect:a}){const o={x:a.x+a.width/2,y:a.y+a.height/2};let l,c=Number.MAX_VALUE;for(const u of t){const{x:p,y:m}=DN(o,u),g=e==="horizontal"?p:m;g<c&&(c=g,l=u)}return Bt(l,"No rect found"),l}let zd;function fB(){return zd===void 0&&(typeof matchMedia=="function"?zd=!!matchMedia("(pointer:coarse)").matches:zd=!1),zd}function PN(e){const{element:t,orientation:a,panels:o,separators:l}=e,c=Cx(a,Array.from(t.children).filter(zN).map(N=>({element:N}))).map(({element:N})=>N),u=[];let p=!1,m=!1,g=-1,h=-1,b=0,v,k=[];{let N=-1;for(const j of c)j.hasAttribute("data-panel")&&(N++,j.hasAttribute("data-disabled")||(b++,g===-1&&(g=N),h=N))}if(b>1){let N=-1;for(const j of c)if(j.hasAttribute("data-panel")){N++;const y=o.find(S=>S.element===j);if(y){if(v){const S=v.element.getBoundingClientRect(),C=j.getBoundingClientRect();let E;if(m){const R=a==="horizontal"?new DOMRect(S.right,S.top,0,S.height):new DOMRect(S.left,S.bottom,S.width,0),A=a==="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],M=dB({orientation:a,rects:[S,C],targetRect:T.element.getBoundingClientRect()});E=[T,M===S?A:R];break}default:{E=k;break}}}else k.length?E=k:E=[a==="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=fB()?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 M=N<=g||N>h;!p&&!M&&u.push({group:e,groupSize:Yl({group:e}),panels:[v,y],separator:"width"in R?void 0:R,rect:A}),p=!1}}m=!1,v=y,k=[]}}else if(j.hasAttribute("data-separator")){j.ariaDisabled!==null&&(p=!0);const y=l.find(S=>S.element===j);y?k.push(y):(v=void 0,k=[])}else m=!0}return u}class LN{#e={};addListener(t,a){const o=this.#e[t];return o===void 0?this.#e[t]=[a]:o.includes(a)||o.push(a),()=>{this.removeListener(t,a)}}emit(t,a){const o=this.#e[t];if(o!==void 0)if(o.length===1)o[0].call(null,a);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,a)}catch(g){c===null&&(l=!0,c=g)}}if(l)throw c}}removeAllListeners(){this.#e={}}removeListener(t,a){const o=this.#e[t];if(o!==void 0){const l=o.indexOf(a);l>=0&&o.splice(l,1)}}}let ra=new Map;const IN=new LN;function pB(e){ra=new Map(ra),ra.delete(e)}function Gw(e,t){for(const[a]of ra)if(a.id===e)return a}function Mr(e,t){for(const[a,o]of ra)if(a.id===e)return o;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Oo(){return ra}function x_(e,t){return IN.addListener("groupChange",a=>{a.group.id===e&&t(a)})}function Za(e,t,a){const o=ra.get(e);ra=new Map(ra),ra.set(e,t),IN.emit("groupChange",{group:e,isUserInteraction:a?.isUserInteraction===!0,prev:o,next:t})}function mB(e,t,a){let o,l={x:1/0,y:1/0};for(const c of t){const u=DN(a,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 gB(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function hB(e,t){if(e===t)throw new Error("Cannot compare node with itself");const a={a:Xw(e),b:Xw(t)};let o;for(;a.a.at(-1)===a.b.at(-1);)o=a.a.pop(),a.b.pop();Bt(o,"Stacking order can only be calculated for elements with a common ancestor");const l={a:Kw(Yw(a.a)),b:Kw(Yw(a.b))};if(l.a===l.b){const c=o.childNodes,u={a:a.a.at(-1),b:a.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 xB=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function bB(e){const t=getComputedStyle(BN(e)??e).display;return t==="flex"||t==="inline-flex"}function _B(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||bB(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"||xB.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Yw(e){let t=e.length;for(;t--;){const a=e[t];if(Bt(a,"Missing node"),_B(a))return a}return null}function Kw(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Xw(e){const t=[];for(;e;)t.push(e),e=BN(e);return t}function BN(e){const{parentNode:t}=e;return gB(t)?t.host:t}function vB(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 yB({groupElement:e,hitRegion:t,pointerEventTarget:a}){if(!zN(a)||a.contains(e)||e.contains(a))return!0;if(hB(a,e)>0){let o=a;for(;o;){if(o.contains(e))return!0;if(vB(o.getBoundingClientRect(),t))return!1;o=o.parentElement}}return!0}function b_(e,t){const a=[];return t.forEach((o,l)=>{if(l.disabled)return;const c=PN(l),u=mB(l.orientation,c,{x:e.clientX,y:e.clientY});u&&u.distance.x<=0&&u.distance.y<=0&&yB({groupElement:l.element,hitRegion:u.hitRegion.rect,pointerEventTarget:e.target})&&a.push(u.hitRegion)}),a}function jB(e,t){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!=t[a])return!1;return!0}function qn(e,t,a=0){return Math.abs(Yn(e)-Yn(t))<=a}function ta(e,t){return qn(e,t)?0:e>t?1:-1}function Sl({overrideDisabledPanels:e,panelConstraints:t,prevSize:a,size:o}){const{collapsedSize:l=0,collapsible:c,disabled:u,maxSize:p=100,minSize:m=0}=t;if(u&&!e)return a;if(ta(o,m)<0)if(c){const g=(l+m)/2;ta(o,g)<0?o=l:o=m}else o=m;return o=Math.min(p,o),o=Yn(o),o}function Ic({delta:e,initialLayout:t,panelConstraints:a,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 v=0;switch(c){case"keyboard":{{const j=e<0?b:h,y=a[j];Bt(y,`Panel constraints not found for index ${j}`);const{collapsedSize:S=0,collapsible:C,minSize:E=0}=y;if(C){const R=p[j];if(Bt(R!=null,`Previous layout not found for panel index ${j}`),qn(R,S)){const A=E-R;ta(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}{const j=e<0?h:b,y=a[j];Bt(y,`No panel constraints found for index ${j}`);const{collapsedSize:S=0,collapsible:C,minSize:E=0}=y;if(C){const R=p[j];if(Bt(R!=null,`Previous layout not found for panel index ${j}`),qn(R,E)){const A=R-S;ta(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}break}default:{const j=e<0?b:h,y=a[j];Bt(y,`Panel constraints not found for index ${j}`);const S=p[j],{collapsible:C,collapsedSize:E,minSize:R}=y;if(C&&ta(S,R)<0)if(e>0){const A=R-E,T=A/2,M=S+e;ta(M,R)<0&&(e=ta(e,T)<=0?0:A)}else{const A=R-E,T=100-A/2,M=S-e;ta(M,R)<0&&(e=ta(100+e,T)>0?0:-A)}break}}{const j=e<0?1:-1;let y=e<0?b:h,S=0;for(;;){const E=p[y];Bt(E!=null,`Previous layout not found for panel index ${y}`);const R=Sl({overrideDisabledPanels:u,panelConstraints:a[y],prevSize:E,size:100})-E;if(S+=R,y+=j,y<0||y>=a.length)break}const C=Math.min(Math.abs(e),Math.abs(S));e=e<0?0-C:C}{let j=e<0?h:b;for(;j>=0&&j<a.length;){const y=Math.abs(e)-Math.abs(v),S=p[j];Bt(S!=null,`Previous layout not found for panel index ${j}`);const C=S-y,E=Sl({overrideDisabledPanels:u,panelConstraints:a[j],prevSize:S,size:C});if(!qn(S,E)&&(v+=S-E,g[j]=E,v.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?j--:j++}}if(jB(m,g))return l;{const j=e<0?b:h,y=p[j];Bt(y!=null,`Previous layout not found for panel index ${j}`);const S=y+v,C=Sl({overrideDisabledPanels:u,panelConstraints:a[j],prevSize:y,size:S});if(g[j]=C,!qn(C,S)){let E=S-C,R=e<0?b:h;for(;R>=0&&R<a.length;){const A=g[R];Bt(A!=null,`Previous layout not found for panel index ${R}`);const T=A+E,M=Sl({overrideDisabledPanels:u,panelConstraints:a[R],prevSize:A,size:T});if(qn(A,M)||(E-=M-A,g[R]=M),qn(E,0))break;e>0?R--:R++}}}const k=Object.values(g).reduce((j,y)=>y+j,0);if(!qn(k,100,.1))return l;const N=Object.keys(l);return g.reduce((j,y,S)=>(j[N[S]]=y,j),{})}function So(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const a in e)if(t[a]===void 0||ta(e[a],t[a])!==0)return!1;return!0}function Co({layout:e,panelConstraints:t}){const a=Object.values(e),o=[...a],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=a[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=Sl({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=Sl({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 UN({groupId:e,panelId:t}){const a=()=>{const m=Oo();for(const[g,{defaultLayoutDeferred:h,derivedPanelConstraints:b,layout:v,groupSize:k,separatorToPanels:N}]of m)if(g.id===e)return{defaultLayoutDeferred:h,derivedPanelConstraints:b,group:g,groupSize:k,layout:v,separatorToPanels:N};throw Error(`Group ${e} not found`)},o=()=>{const m=a().derivedPanelConstraints.find(g=>g.panelId===t);if(m!==void 0)return m;throw Error(`Panel constraints not found for Panel ${t}`)},l=()=>{const m=a().group.panels.find(g=>g.id===t);if(m!==void 0)return m;throw Error(`Layout not found for Panel ${t}`)},c=()=>{const m=a().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 v=c(),k=g.findIndex(y=>y.id===t),N=k===0,j=k===g.length-1;if(j&&m<v&&(N||g.slice(0,k).every((y,S)=>{const C=b[S];return C?.collapsible&&qn(C.collapsedSize,h[C.panelId])}))){const y=g.slice(0,k).reduce((S,C)=>S+h[C.id],0);return{...h,[t]:Yn(100-y)}}return Ic({delta:j?v-m:m-v,initialLayout:h,panelConstraints:b,pivotIndices:j?[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:v,groupSize:k,layout:N,separatorToPanels:j}=a(),y=u({nextSize:m,panels:v.panels,prevLayout:N,derivedPanelConstraints:b}),S=Co({layout:y,panelConstraints:b});So(N,S)||Za(v,{defaultLayoutDeferred:h,derivedPanelConstraints:b,groupSize:k,layout:S,separatorToPanels:j})};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(),v=c();if(m&&v===g){let k=b.expandToSize??h;k===0&&(k=1),p(k)}},getSize:()=>{const{group:m}=a(),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}=a(),{element:h}=l(),b=Yl({group:g}),v=bc({groupSize:b,panelElement:h,styleProp:m}),k=Yn(v/b*100);p(k)}}}function Qw(e){if(e.defaultPrevented)return;const t=Oo();b_(e,t).forEach(a=>{if(a.separator&&!a.separator.disableDoubleClick){const o=a.panels.find(l=>l.panelConstraints.defaultSize!==void 0);if(o){const l=o.panelConstraints.defaultSize,c=UN({groupId:a.group.id,panelId:o.id});c&&l!==void 0&&(c.resize(l),e.preventDefault())}}})}function qd(e){const t=Oo();for(const[a]of t)if(a.separators.some(o=>o.element===e))return a;throw Error("Could not find parent Group for separator element")}function HN({groupId:e}){const t=()=>{const a=Oo();for(const[o,l]of a)if(o.id===e)return{group:o,...l};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:a,layout:o}=t();return a?{}:o},setLayout(a){const{defaultLayoutDeferred:o,derivedPanelConstraints:l,group:c,groupSize:u,layout:p,separatorToPanels:m}=t(),g=Co({layout:a,panelConstraints:l});return o?p:(So(p,g)||Za(c,{defaultLayoutDeferred:o,derivedPanelConstraints:l,groupSize:u,layout:g,separatorToPanels:m}),g)}}}function io(e,t){const a=qd(e),o=Mr(a.id,!0),l=a.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=>a.panels.indexOf(h)),p=HN({groupId:a.id}).getLayout(),m=Ic({delta:t,initialLayout:p,panelConstraints:o.derivedPanelConstraints,pivotIndices:u,prevLayout:p,trigger:"keyboard"}),g=Co({layout:m,panelConstraints:o.derivedPanelConstraints});So(p,g)||Za(a,{defaultLayoutDeferred:o.defaultLayoutDeferred,derivedPanelConstraints:o.derivedPanelConstraints,groupSize:o.groupSize,layout:g,separatorToPanels:o.separatorToPanels},{isUserInteraction:!0})}function Zw(e){if(e.defaultPrevented)return;const t=e.currentTarget,a=qd(t);if(!a.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),a.orientation==="vertical"&&io(t,5);break}case"ArrowLeft":{e.preventDefault(),a.orientation==="horizontal"&&io(t,-5);break}case"ArrowRight":{e.preventDefault(),a.orientation==="horizontal"&&io(t,5);break}case"ArrowUp":{e.preventDefault(),a.orientation==="vertical"&&io(t,-5);break}case"End":{e.preventDefault(),io(t,100);break}case"Enter":{e.preventDefault();const o=qd(t),l=Mr(o.id,!0),{derivedPanelConstraints:c,layout:u,separatorToPanels:p}=l,m=o.separators.find(v=>v.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(v=>v.panelId===h.id);if(Bt(b,"Panel metadata not found"),b.collapsible){const v=u[h.id],k=b.collapsedSize===v?o.mutableState.expandedPanelSizes[h.id]??b.minSize:b.collapsedSize;io(t,k-v)}break}case"F6":{e.preventDefault();const o=qd(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 Ol={cursorFlags:0,state:"inactive"};const __=new LN;function No(){return Ol}function wB(e){return __.addListener("change",e)}function kB(e){const t=Ol,a={...Ol};a.cursorFlags=e,Ol=a,__.emit("change",{prev:t,next:a})}function zl(e){const t=Ol;Ol=e,__.emit("change",{prev:t,next:e})}function Ww(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Oo(),a=b_(e,t),o=new Map;let l=!1;a.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)}),zl({cursorFlags:0,hitRegions:a,initialLayoutMap:o,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),a.length&&e.preventDefault()}const SB=e=>e,zh=()=>{},VN=1,qN=2,$N=4,FN=8,Jw=3,ek=12;let Dd;function tk(){return Dd===void 0&&(Dd=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Dd=!0)),Dd}function CB({cursorFlags:e,groups:t,state:a}){let o=0,l=0;switch(a){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(a){case"active":{if(e&&tk()){const c=(e&VN)!==0,u=(e&qN)!==0,p=(e&$N)!==0,m=(e&FN)!==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 tk()?o>0&&l>0?"move":o>0?"ew-resize":"ns-resize":o>0&&l>0?"grab":o>0?"col-resize":"row-resize"}}const nk=new WeakMap;function v_(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:a}=nk.get(e)??{};a===void 0&&(a=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(a):e.adoptedStyleSheets=[...e.adoptedStyleSheets,a]));const o=No();switch(o.state){case"active":case"hover":{const l=CB({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?a.cssRules.length===0?a.insertRule(c):a.replaceSync(c):a.cssRules.length===1&&a.deleteRule(0);break}case"inactive":{t=void 0,a.cssRules.length===1&&a.deleteRule(0);break}}nk.set(e,{prevStyle:t,styleSheet:a})}function GN({document:e,event:t,hitRegions:a,initialLayoutMap:o,mountedGroups:l,pointerDownAtPoint:c,prevCursorFlags:u}){let p=0;a.forEach(g=>{const{group:h,groupSize:b}=g,{orientation:v,panels:k}=h,{disableCursor:N}=h.mutableState;let j=0;c?v==="horizontal"?j=(t.clientX-c.x)/b*100:j=(t.clientY-c.y)/b*100:v==="horizontal"?j=t.clientX<0?-100:100:j=t.clientY<0?-100:100;const y=o.get(h),S=l.get(h);if(!y||!S)return;const{defaultLayoutDeferred:C,derivedPanelConstraints:E,groupSize:R,layout:A,separatorToPanels:T}=S;if(E&&A&&T){const M=Ic({delta:j,initialLayout:y,panelConstraints:E,pivotIndices:g.panels.map(z=>k.indexOf(z)),prevLayout:A,trigger:"mouse-or-touch"});if(So(M,A)){if(j!==0&&!N)switch(v){case"horizontal":{p|=j<0?VN:qN;break}case"vertical":{p|=j<0?$N:FN;break}}}else Za(g.group,{defaultLayoutDeferred:C,derivedPanelConstraints:E,groupSize:R,layout:M,separatorToPanels:T})}});let m=0;t.movementX===0?m|=u&Jw:m|=p&Jw,t.movementY===0?m|=u&ek:m|=p&ek,kB(m),v_(e)}function sk(e){const t=Oo(),a=No();switch(a.state){case"active":GN({document:e.currentTarget,event:e,hitRegions:a.hitRegions,initialLayoutMap:a.initialLayoutMap,mountedGroups:t,prevCursorFlags:a.cursorFlags})}}function ak(e){if(e.defaultPrevented)return;const t=No(),a=Oo();switch(t.state){case"active":{if(e.buttons===0){zl({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(o=>{const l=Mr(o.group.id,!0);Za(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)}GN({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:a,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const o=b_(e,a);o.length===0?t.state!=="inactive"&&zl({cursorFlags:0,state:"inactive"}):zl({cursorFlags:0,hitRegions:o,state:"hover"}),v_(e.currentTarget);break}}}function rk(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(No().state){case"hover":zl({cursorFlags:0,state:"inactive"})}}function ok(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=No();switch(t.state){case"active":zl({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(v_(e.currentTarget),t.hitRegions.forEach(a=>{const o=Mr(a.group.id,!0);Za(a.group,o,{isUserInteraction:!0})}),e.preventDefault())}}function lk(e){let t=0,a=0;const o={};for(const c of e)if(c.defaultSize!==void 0){t++;const u=Yn(c.defaultSize);a+=u,o[c.panelId]=u}else o[c.panelId]=void 0;const l=e.length-t;if(l!==0){const c=Yn((100-a)/l);for(const u of e)u.defaultSize===void 0&&(o[u.panelId]=c)}return o}function NB(e,t,a){if(!a[0])return;const o=e.panels.find(m=>m.element===t);if(!o||!o.onResize)return;const l=Yl({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 EB(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const a in e)if(e[a]!==t[a])return!1;return!0}function RB({group:e,nextGroupSize:t,prevGroupSize:a,prevLayout:o}){if(a<=0||t<=0||a===t)return o;let l=0,c=0,u=!1;const p=new Map,m=[];for(const b of e.panels){const v=o[b.id]??0;switch(b.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{u=!0;const k=v/100*a,N=Yn(k/t*100);p.set(b.id,N),l+=N;break}case"preserve-relative-size":default:{m.push(b.id),c+=v;break}}}if(!u||m.length===0)return o;const g=100-l,h={...o};if(p.forEach((b,v)=>{h[v]=b}),c>0)for(const b of m){const v=o[b]??0;h[b]=Yn(v/c*g)}else{const b=Yn(g/m.length);for(const v of m)h[v]=b}return h}function TB(e,t){const a=e.map(l=>l.id),o=Object.keys(t);if(a.length!==o.length)return!1;for(const l of a)if(!o.includes(l))return!1;return!0}const yl=new Map;function AB(e){let t=!0;Bt(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const a=e.element.ownerDocument.defaultView.ResizeObserver,o=new Set,l=new Set,c=new a(N=>{for(const j of N){const{borderBoxSize:y,target:S}=j;if(S===e.element){if(t){const C=Yl({group:e});if(C===0)return;const E=Mr(e.id);if(!E)return;const R=Sx(e),A=E.defaultLayoutDeferred?lk(R):E.layout,T=RB({group:e,nextGroupSize:C,prevGroupSize:E.groupSize,prevLayout:A}),M=Co({layout:T,panelConstraints:R});if(!E.defaultLayoutDeferred&&So(E.layout,M)&&EB(E.derivedPanelConstraints,R)&&E.groupSize===C)return;Za(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:R,groupSize:C,layout:M,separatorToPanels:E.separatorToPanels})}}else NB(e,S,y)}});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=Yl({group:e}),p=Sx(e),m=e.panels.map(({id:N})=>N).join(",");let g=e.mutableState.defaultLayout;g&&(TB(e.panels,g)||(g=void 0));const h=e.mutableState.layouts[m]??g??lk(p),b=Co({layout:h,panelConstraints:p}),v=e.element.ownerDocument;yl.set(v,(yl.get(v)??0)+1);const k=new Map;return PN(e).forEach(N=>{N.separator&&k.set(N.separator,N.panels)}),Za(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",Zw)}),yl.get(v)===1&&(v.addEventListener("dblclick",Qw,!0),v.addEventListener("pointerdown",Ww,!0),v.addEventListener("pointerleave",sk),v.addEventListener("pointermove",ak),v.addEventListener("pointerout",rk),v.addEventListener("pointerup",ok,!0)),function(){t=!1,yl.set(v,Math.max(0,(yl.get(v)??0)-1)),pB(e),e.separators.forEach(N=>{N.element.removeEventListener("keydown",Zw)}),yl.get(v)||(v.removeEventListener("dblclick",Qw,!0),v.removeEventListener("pointerdown",Ww,!0),v.removeEventListener("pointerleave",sk),v.removeEventListener("pointermove",ak),v.removeEventListener("pointerout",rk),v.removeEventListener("pointerup",ok,!0)),c.disconnect()}}function MB(){const[e,t]=x.useState({}),a=x.useCallback(()=>t({}),[]);return[e,a]}function y_(e){const t=x.useId();return`${e??t}`}const zo=typeof window<"u"?x.useLayoutEffect:x.useEffect;function Cc(e){const t=x.useRef(e);return zo(()=>{t.current=e},[e]),x.useCallback((...a)=>t.current?.(...a),[t])}function j_(...e){return Cc(t=>{e.forEach(a=>{if(a)switch(typeof a){case"function":{a(t);break}case"object":{a.current=t;break}}})})}function w_(e){const t=x.useRef({...e});return zo(()=>{for(const a in e)t.current[a]=e[a]},[e]),t.current}const YN=x.createContext(null);function OB(e,t){const a=x.useRef({getLayout:()=>({}),setLayout:SB});x.useImperativeHandle(t,()=>a.current,[]),zo(()=>{Object.assign(a.current,HN({groupId:e}))})}function Nx({children:e,className:t,defaultLayout:a,disableCursor:o,disabled:l,elementRef:c,groupRef:u,id:p,onLayoutChange:m,onLayoutChanged:g,orientation:h="horizontal",resizeTargetMinimumSize:b={coarse:20,fine:10},style:v,...k}){const N=x.useRef({onLayoutChange:{},onLayoutChanged:{}}),j=Cc(H=>{So(N.current.onLayoutChange,H)||(N.current.onLayoutChange=H,m?.(H))}),y=Cc((H,I)=>{So(N.current.onLayoutChanged,H)||(N.current.onLayoutChanged=H,g?.(H,{isUserInteraction:I}))}),S=y_(p),C=x.useRef(null),[E,R]=MB(),A=x.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:b,separators:[]}),T=j_(C,c);OB(S,u);const M=Cc((H,I)=>{const B=No(),V=Gw(H),G=Mr(H);if(G){let q=!1;switch(B.state){case"active":{q=B.hitRegions.some(Y=>Y.group===V);break}}return{flexGrow:G.layout[I]??1,pointerEvents:q?"none":void 0}}if(a?.[I])return{flexGrow:a?.[I]}}),z=w_({defaultLayout:a,disableCursor:o}),L=x.useMemo(()=>({get disableCursor(){return!!z.disableCursor},getPanelStyles:M,id:S,orientation:h,registerPanel:H=>{const I=A.current;return I.panels=Cx(h,[...I.panels,H]),R(),()=>{I.panels=I.panels.filter(B=>B!==H),R()}},registerSeparator:H=>{const I=A.current;return I.separators=Cx(h,[...I.separators,H]),R(),()=>{I.separators=I.separators.filter(B=>B!==H),R()}},updatePanelProps:(H,{disabled:I})=>{const B=A.current.panels.find(q=>q.id===H);B&&(B.panelConstraints.disabled=I);const V=Gw(S),G=Mr(S);V&&G&&Za(V,{...G,derivedPanelConstraints:Sx(V)})},updateSeparatorProps:(H,{disabled:I,disableDoubleClick:B})=>{const V=A.current.separators.find(G=>G.id===H);V&&(V.disabled=I,V.disableDoubleClick=B)}}),[M,S,R,h,z]),D=x.useRef(null);return zo(()=>{const H=C.current;if(H===null)return;const I=A.current;let B;if(z.defaultLayout!==void 0&&Object.keys(z.defaultLayout).length===I.panels.length){B={};for(const X of I.panels){const P=z.defaultLayout[X.id];P!==void 0&&(B[X.id]=P)}}const V={disabled:!!l,element:H,id:S,mutableState:{defaultLayout:B,disableCursor:!!z.disableCursor,expandedPanelSizes:A.current.lastExpandedPanelSizes,layouts:A.current.layouts},orientation:h,panels:I.panels,resizeTargetMinimumSize:I.resizeTargetMinimumSize,separators:I.separators};D.current=V;const G=AB(V),{defaultLayoutDeferred:q,derivedPanelConstraints:Y,layout:K}=Mr(V.id,!0);!q&&Y.length>0&&(j(K),y(K,!1));const $=x_(S,X=>{const{defaultLayoutDeferred:P,derivedPanelConstraints:F,layout:W}=X.next;if(P||F.length===0)return;const ee=V.panels.map(({id:fe})=>fe).join(",");V.mutableState.layouts[ee]=W,F.forEach(fe=>{if(fe.collapsible){const{layout:ae}=X.prev??{};if(ae){const oe=qn(fe.collapsedSize,W[fe.panelId]),me=qn(fe.collapsedSize,ae[fe.panelId]);oe&&!me&&(V.mutableState.expandedPanelSizes[fe.panelId]=ae[fe.panelId])}}});const de=No().state!=="active";j(W),de&&y(W,X.isUserInteraction)});return()=>{D.current=null,G(),$()}},[l,S,y,j,h,E,z]),x.useEffect(()=>{const H=D.current;H&&(H.mutableState.defaultLayout=a,H.mutableState.disableCursor=!!o)}),r.jsx(YN.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",...v,display:"flex",flexDirection:h==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:h==="horizontal"?"pan-y":"pan-x"},children:e})})}Nx.displayName="Group";function k_(){const e=x.useContext(YN);return Bt(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function zB(e,t){const{id:a}=k_(),o=x.useRef({collapse:zh,expand:zh,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:zh});x.useImperativeHandle(t,()=>o.current,[]),zo(()=>{Object.assign(o.current,UN({groupId:a,panelId:e}))})}function uo({children:e,className:t,collapsedSize:a="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:v,style:k,...N}){const j=!!m,y=y_(m),S=w_({disabled:c}),C=x.useRef(null),E=j_(C,u),{getPanelStyles:R,id:A,orientation:T,registerPanel:M,updatePanelProps:z}=k_(),L=b!==null,D=Cc((V,G,q)=>{b?.(V,m,q)});zo(()=>{const V=C.current;if(V!==null){const G={element:V,id:y,idIsStable:j,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:L?D:void 0,panelConstraints:{groupResizeBehavior:p,collapsedSize:a,collapsible:o,defaultSize:l,disabled:S.disabled,maxSize:g,minSize:h}};return M(G)}},[p,a,o,l,L,y,j,g,h,D,M,S]),x.useEffect(()=>{z(y,{disabled:c})},[c,y,z]),zB(y,v);const H=()=>{const V=R(A,y);if(V)return JSON.stringify(V)},I=x.useSyncExternalStore(V=>x_(A,V),H,H);let B;return I?B=JSON.parse(I):l!==void 0?B={flexGrow:void 0,flexShrink:void 0,flexBasis:l}:B={flexGrow:1},r.jsx("div",{...N,"data-disabled":c||void 0,"data-panel":!0,"data-testid":y,id:y,ref:E,style:{...DB,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...B},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 DB={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function PB({layout:e,panelConstraints:t,panelId:a,panelIndex:o}){let l,c;const u=e[a],p=t.find(m=>m.panelId===a);if(p){const m=p.maxSize,g=p.collapsible?p.collapsedSize:p.minSize,h=[o,o+1];c=Co({layout:Ic({delta:g-u,initialLayout:e,panelConstraints:t,pivotIndices:h,prevLayout:e}),panelConstraints:t})[a],l=Co({layout:Ic({delta:m-u,initialLayout:e,panelConstraints:t,pivotIndices:h,prevLayout:e}),panelConstraints:t})[a]}return{valueControls:a,valueMax:l,valueMin:c,valueNow:u}}function S_({children:e,className:t,disabled:a,disableDoubleClick:o,elementRef:l,id:c,style:u,...p}){const m=y_(c),g=w_({disabled:a,disableDoubleClick:o}),[h,b]=x.useState({}),[v,k]=x.useState("inactive"),[N,j]=x.useState(!1),y=x.useRef(null),S=j_(y,l),{disableCursor:C,id:E,orientation:R,registerSeparator:A,updateSeparatorProps:T}=k_(),M=R==="horizontal"?"vertical":"horizontal";zo(()=>{const D=y.current;if(D!==null){const H={disabled:g.disabled,disableDoubleClick:g.disableDoubleClick,element:D,id:m},I=A(H),B=wB(G=>{k(G.next.state!=="inactive"&&G.next.hitRegions.some(q=>q.separator===H)?G.next.state:"inactive")}),V=x_(E,G=>{const{derivedPanelConstraints:q,layout:Y,separatorToPanels:K}=G.next,$=K.get(H);if($){const X=$[0],P=$.indexOf(X);b(PB({layout:Y,panelConstraints:q,panelId:X.id,panelIndex:P}))}});return()=>{B(),V(),I()}}},[E,m,A,g]),x.useEffect(()=>{T(m,{disabled:a,disableDoubleClick:o})},[a,o,m,T]);let z;a&&!C&&(z="not-allowed");let L;if(a)L="disabled";else switch(v){case"active":{L="active";break}default:N?L="focus":L=v}return r.jsx("div",{...p,"aria-controls":h.valueControls,"aria-disabled":a||void 0,"aria-orientation":M,"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:()=>j(!1),onFocus:()=>j(!0),ref:S,role:"separator",style:{flexBasis:"auto",cursor:z,...u,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:a?void 0:0})}S_.displayName="Separator";function LB({projects:e,value:t,onChange:a,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:jM,description:c.path}});return r.jsx("div",{className:"w-full","data-testid":"code-project-select",children:r.jsx(bt,{value:t,onChange:a,options:l,placeholder:f("modules_ui.code_pick_project_ph"),disabled:o})})}function IB({sessions:e,activeId:t,busy:a,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(Ye,{content:f("code_module.new_session"),children:r.jsxs("button",{type:"button",onClick:l,disabled:a,"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:Me("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(Ux,{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(Ye,{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(Ye,{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(cs,{className:"size-3"})})})]})]},p.id))})})]})}function BB({mode:e,onChange:t,disabled:a}){const o=(l,c,u,p)=>r.jsx(Ye,{content:u,children:r.jsxs("button",{type:"button",disabled:a,"data-testid":`code-mode-${l}`,"aria-pressed":e===l,onClick:()=>t(l),className:Me("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"),NM),o("plan",f("code_module.mode_plan"),f("code_module.mode_plan_hint"),iM)]})}function UB({value:e,onValueChange:t,onSubmit:a,onStop:o,busy:l,disabled:c,mode:u,onModeChange:p,model:m,onModelChange:g}){return r.jsx(u_,{value:e,onValueChange:t,onSubmit:a,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(BB,{mode:u,onChange:p,disabled:l}),r.jsx(d_,{value:m,onChange:g,disabled:l})]})})}function Dh(e,t){let a=0;for(const o of e.parts||[])o.kind==="text"&&t.text&&(a+=o.text.length),o.kind==="tool"&&t.tool&&(o.args&&(a+=JSON.stringify(o.args).length),o.result!==void 0&&(a+=JSON.stringify(o.result).length));return Math.ceil(a/4)}function HB(e){let t=null,a=0,o=0;for(const u of e)u.role==="user"?a++: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:a,assistantMsgs:o}}function VB(e){let t=0,a=0,o=0;for(const u of e)u.role==="user"?t+=Dh(u,{text:!0}):a+=Dh(u,{text:!0}),o+=Dh(u,{tool:!0});const l=t+a+o||1,c=(u,p)=>({key:u,tokens:p,percent:Math.round(p/l*100)});return[c("user",t),c("assistant",a),c("tool",o)].filter(u=>u.tokens>0)}const ik={user:"bg-emerald-500",assistant:"bg-sky-500",tool:"bg-amber-500"};function Ba({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 ck(e){if(!e)return"";const t=new Date(e),a=o=>String(o).padStart(2,"0");return`${a(t.getDate())} ${t.toLocaleString("es",{month:"short"})} ${t.getFullYear()}, ${a(t.getHours())}:${a(t.getMinutes())}`}function qB({turns:e,session:t}){const a=x.useMemo(()=>HB(e),[e]),o=x.useMemo(()=>VB(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(Ba,{label:f("code_module.ctx_model"),value:a.model||f("modules_ui.code_ctx_auto")}),t?.mode&&r.jsx(Ba,{label:f("modules_ui.code_ctx_mode"),value:t.mode}),t?.agentSlug&&r.jsx(Ba,{label:f("modules_ui.code_ctx_agent"),value:t.agentSlug}),r.jsx(Ba,{label:f("code_module.ctx_messages"),value:f("modules_ui.code_ctx_msgs_value",{user:a.userMsgs,assistant:a.assistantMsgs})}),r.jsx(Ba,{label:f("code_module.ctx_input"),value:a.input.toLocaleString()}),r.jsx(Ba,{label:f("code_module.ctx_output"),value:a.output.toLocaleString()}),r.jsx(Ba,{label:f("modules_ui.code_ctx_tokens_total"),value:(a.input+a.output).toLocaleString()}),t?.createdAt&&r.jsx(Ba,{label:f("modules_ui.code_ctx_created"),value:ck(t.createdAt)}),t?.updatedAt&&r.jsx(Ba,{label:f("modules_ui.code_ctx_activity"),value:ck(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(Ye,{content:`${l.key}: ${l.tokens} (${l.percent}%)`,children:r.jsx("div",{className:ik[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 ${ik[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 $B(e){const t=[];for(const a of(e||"").split(`
650
+ `;return typeof p=="function"&&p(null,y),y},Mh}var Vw;function c7(){if(Vw)return vl;Vw=1;const e=q8(),t=o7(),a=l7(),o=i7();function l(c,u,p,m,g){const h=[].slice.call(arguments,1),b=h.length,v=typeof h[b-1]=="function";if(!v&&!e())throw new Error("Callback required as last argument");if(v){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 j=t.create(p,m);k(c(j,u,m))}catch(j){N(j)}})}try{const k=t.create(p,m);g(null,c(k,u,m))}catch(k){g(k)}}return vl.create=t.create,vl.toCanvas=l.bind(null,a.render),vl.toDataURL=l.bind(null,a.renderToDataURL),vl.toString=l.bind(null,function(c,u,p){return o.render(c,p)}),vl}var u7=c7();const d7=Ex(u7);function f7({value:e,size:t=200}){const[a,o]=x.useState(null);return x.useEffect(()=>{let l=!0;return d7.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:a?r.jsx("img",{src:a,width:t,height:t,alt:"QR"}):r.jsx("div",{className:"size-full animate-pulse rounded bg-muted"})})}function p7(e){return e.find(t=>!t.includes("127.0.0.1")&&!t.includes("localhost"))||e[0]||window.location.origin}function m7({open:e,onClose:t,onPaired:a}){const o=rt(),[l,c]=x.useState(null),[u,p]=x.useState(null),[m,g]=x.useState(0),[h,b]=x.useState(!1),v=x.useRef(null),k=x.useCallback(async()=>{c(null),p(null),b(!1);try{const C=await Fl.init();c(C),g(Math.round((C.ttl_ms||9e4)/1e3))}catch(C){C instanceof Kc&&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 Fl.status(l.pairing_id);if(!C)return;if(R.status==="confirmed"){b(!0),o.success(f("settings.devices_pair_done")),a(),window.setTimeout(()=>{C&&t()},900);return}if(R.status==="expired"||R.status==="unknown"){g(0);return}}catch{}v.current=window.setTimeout(E,1500)};return v.current=window.setTimeout(E,1500),()=>{C=!1,v.current&&window.clearTimeout(v.current)}},[e,l,h,t,a,o]);const N=!!l&&!h&&m<=0,j=l?p7(l.lan_urls):"",y=l?`${j}/#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(ie,{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(_s,{})," ",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(f7,{value:y,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(ie,{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(_s,{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:y}),r.jsx(Ye,{content:f("settings.devices_pair_copy"),children:r.jsx(ie,{size:"sm",variant:"secondary",onClick:()=>S(y,f("settings.devices_pair_copied")),children:r.jsx(Ec,{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(Ye,{content:f("settings.devices_pair_copy"),children:r.jsx(ie,{size:"sm",variant:"secondary",onClick:()=>S(l.pairing_id,f("settings.devices_pair_copied_code")),children:r.jsx(Ec,{size:14})})})]})]})]})]})]})]})}function g7(){const e=rt(),{clients:t,isLoading:a,mutate:o}=V8(),[l,c]=x.useState(!1),u=async p=>{if(confirm(f("settings.devices_revoke_confirm",{id:p})))try{await Fl.revoke(p),e.success(f("settings.devices_revoke_success")),o()}catch(m){e.error(m.message)}};return r.jsxs(Ke,{title:f("settings.devices"),description:f("settings.devices_sub"),action:r.jsxs(ie,{size:"sm",variant:"primary",onClick:()=>c(!0),children:[r.jsx(HM,{size:14})," ",f("settings.devices_pair_btn")]}),children:[a&&r.jsx(lt,{}),!a&&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(ie,{size:"sm",variant:"destructive",onClick:()=>u(p.id),children:f("settings.devices_revoke")})]},p.id))}),r.jsx(m7,{open:l,onClose:()=>c(!1),onPaired:()=>o()})]})}const h7=[{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:Fx.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 x7(){const{config:e,isLoading:t,patch:a,mutate:o}=Vr();if(t)return r.jsx(lt,{});const l=async c=>{const u={};for(const[p,m]of Object.entries(l_(c)))os(m)||(u[p]=m);await a(u),o()};return r.jsx(Ke,{title:f("global_config.title"),description:f("settings_ui.global_config_desc"),children:r.jsx(xx,{sections:h7,source:e,jsonTitle:"~/.apx/config.json",jsonDescription:f("settings_ui.global_json_desc"),onSaveFields:async(c,u)=>{await a(c,u),o()},onSaveJson:l})})}function b7(){const e=rt(),{health:t,isUp:a}=AC(),o=async()=>{try{await $l.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(Ke,{title:f("daemon.version"),action:r.jsx(ie,{size:"sm",onClick:o,children:f("common.reload")}),children:r.jsxs("div",{className:"grid grid-cols-3 gap-3 text-sm",children:[r.jsx(Oh,{label:f("daemon.version"),value:t?.version||"—"}),r.jsx(Oh,{label:f("daemon.uptime"),value:t?`${t.uptime_s}s`:"—"}),r.jsx(Oh,{label:f("daemon.status"),value:f(a?"daemon.running":"daemon.down"),ok:a})]})}),r.jsx(x7,{})]})}function Oh({label:e,value:t,ok:a}){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:[a!==void 0&&r.jsx(Qc,{ok:a}),r.jsx("span",{children:t})]})]})}function _7(){const e=rt(),{theme:t,set:a}=Gx(),[o,l]=x.useState(""),[c,u]=x.useState(aC()),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=>{nC(g),u(g),window.location.reload()};return r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2 xl:items-start",children:[r.jsx(Ke,{title:f("settings.appearance"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ie,{variant:t==="light"?"primary":"secondary",onClick:()=>a("light"),children:f("settings.light_mode")}),r.jsx(ie,{variant:t==="dark"?"primary":"secondary",onClick:()=>a("dark"),children:f("settings.dark_mode")})]})}),r.jsx(Ke,{title:f("settings.language"),children:r.jsx("div",{className:"flex items-center gap-2",children:sC.map(g=>r.jsx(ie,{variant:c===g.value?"primary":"secondary",onClick:()=>m(g.value),children:g.label},g.value))})}),r.jsxs(Ke,{title:f("settings.token"),description:f("settings.token_sub"),children:[r.jsx(ue,{label:f("settings_ui.bearer_label"),children:r.jsx(Re,{type:"password",placeholder:$b()?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(ie,{variant:"primary",onClick:p,children:f("common.save")})})]})]})}function v7({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 kx=typeof navigator<"u"&&/mac/i.test(navigator.platform||"");function y7(e){return(kx?{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 j7(e){return(e||"").split("+").map(t=>t.trim()).filter(Boolean)}function w7(e){const t=e.code;if(/^(Shift|Control|Alt|Meta|OS)(Left|Right)?$/.test(t))return null;let a;if((a=t.match(/^Key([A-Z])$/))||(a=t.match(/^Digit(\d)$/))||(a=t.match(/^Numpad(\d)$/))||(a=t.match(/^(F\d{1,2})$/))||(a=t.match(/^Arrow(Up|Down|Left|Right)$/)))return a[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 k7(e){const t=w7(e);if(!t)return null;const a=[];(kx?e.metaKey:e.ctrlKey)&&a.push("CommandOrControl"),kx&&e.ctrlKey&&a.push("Control"),e.altKey&&a.push("Alt"),e.shiftKey&&a.push("Shift");const o=a.length>0,l=/^F\d{1,2}$/.test(t);return!o&&!l?null:(a.push(t),a.join("+"))}function S7({value:e,onChange:t,disabled:a,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=k7(h);b&&(t(b),u(!1))};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[c,t]);const m=j7(e);return r.jsxs("div",{className:Me("flex h-9 w-full max-w-md items-center rounded-md border border-border bg-transparent transition",c&&"ring-2 ring-ring",a&&"opacity-50",o),children:[r.jsxs("button",{ref:p,type:"button",disabled:a,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(v7,{className:"h-6 min-w-6 border border-border bg-muted px-1.5 text-[13px] font-semibold text-fg shadow-sm",children:y7(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 kl={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 C7(e=30){return ge.get(`/messages/global?channel=desktop&limit=${e}`)}function ON({showConfigLink:e=!1}){const t=rt(),{data:a,isLoading:o,mutate:l}=et("/desktop/status",()=>kl.status(),{refreshInterval:5e3}),c=!!a?.running,[u,p]=x.useState(null),m=async(v,k)=>{p(v);try{await k()}catch(N){t.error(N.message)}finally{p(null),setTimeout(()=>l(),1200)}},g=()=>m("start",async()=>{const v=await kl.start();t.success(v.already?f("modules_ui.desktop_start_already"):f("modules_ui.desktop_start_done"))}),h=()=>m("stop",async()=>{const v=await kl.stop();t.success(v.stopped?f("modules_ui.desktop_stop_done"):f("modules_ui.desktop_stop_none"))}),b=()=>m("restart",async()=>{(await kl.restart()).reloaded>0?t.success(f("modules_ui.desktop_restart_done")):t.info(f("modules_ui.desktop_restart_none"))});return r.jsx(Ke,{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(ie,{variant:"primary",size:"sm",onClick:g,loading:u==="start",disabled:c||u!==null&&u!=="start",children:f("modules_ui.desktop_start")}),r.jsx(ie,{variant:"secondary",size:"sm",onClick:h,loading:u==="stop",disabled:!c||u!==null&&u!=="stop",children:f("modules_ui.desktop_stop")}),r.jsx(ie,{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(Sf,{to:"/settings/desktop",children:r.jsxs(ie,{size:"sm",variant:"ghost",children:[r.jsx(Rc,{size:14})," ",f("desktop_screen.open_config")]})})]}),children:o?r.jsx(lt,{}):r.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-sm",children:[r.jsx(Qc,{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(Pj,{children:"apx desktop start"})," · ",r.jsx(Pj,{children:"apx desktop --debug"}),")"]})]})})}const N7="CommandOrControl+G",E7=()=>[{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")}],R7=()=>[{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 T7(){const e=rt(),{config:t,isLoading:a,patch:o}=Vr(),l=t,c=l.desktop?.shortcut||l.overlay?.shortcut||N7,u=l.desktop?.enabled!==!1,p=l.desktop?.theme||"system",m=l.desktop?.position||"right",{data:g,mutate:h}=et("/desktop/autostart",()=>kl.autostartGet()),[b,v]=x.useState(c),[k,N]=x.useState(!1),[j,y]=x.useState(!1);x.useEffect(()=>v(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(M){e.error(M.message)}finally{N(!1)}},E=async R=>{y(!0);try{await kl.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{y(!1)}};return r.jsxs("div",{className:"space-y-6","data-testid":"settings-desktop",children:[r.jsx(ON,{}),r.jsx(Ke,{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:j,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(lt,{})}),r.jsx(Ke,{title:f("desktop_screen.shortcut_title"),description:f("modules_ui.desktop_shortcut_desc"),children:a?r.jsx(lt,{}):r.jsx(ue,{label:f("modules_ui.desktop_accelerator"),hint:f("modules_ui.desktop_accelerator_hint"),children:r.jsx(S7,{value:b,onChange:v,disabled:k,trailing:r.jsx(ie,{variant:"primary",size:"sm",onClick:S,loading:k,disabled:!b.trim()||b.trim()===c,children:f("common.save")})})})}),r.jsx(Ke,{title:f("desktop_screen.appearance_title"),description:f("modules_ui.desktop_appearance_desc"),children:a?r.jsx(lt,{}):r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("modules_ui.desktop_theme"),hint:f("modules_ui.desktop_restart_apply"),children:r.jsx(bt,{value:p,onChange:R=>C("desktop.theme",R,f("modules_ui.desktop_theme_set",{value:R})),options:R7(),disabled:k})}),r.jsx(ue,{label:f("modules_ui.desktop_position"),hint:f("modules_ui.desktop_position_hint"),children:r.jsx(bt,{value:m,onChange:R=>C("desktop.position",R,f("modules_ui.desktop_position_set",{value:R})),options:E7(),disabled:k})})]})}),r.jsx(Ke,{title:f("desktop_screen.activation_title"),description:f("modules_ui.desktop_activation_desc"),children:a?r.jsx(lt,{}):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(Sf,{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 A7({engines:e,order:t,mode:a,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))],v=a==="chain",k=(N,j)=>{const y=b.indexOf(N),S=y+j;if(y<0||S<0||S>=b.length)return;const C=[...b];[C[y],C[S]]=[C[S],C[y]],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(v?"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:Me("px-3 py-1.5 text-xs font-medium transition-colors",v?"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:Me("border-l border-border px-3 py-1.5 text-xs font-medium transition-colors",v?"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,j)=>{const y=h.get(N),S=mf[N]||{name:N,note:""},C=!v&&o===N,E=N==="mock";return r.jsxs("div",{"data-testid":`voice-provider-${N}`,className:Me("flex items-center gap-3 rounded-lg border px-3 py-2.5",C?"border-emerald-500/50 bg-emerald-500/10":"border-border",v&&!E&&!y.enabled&&"opacity-60"),children:[v&&r.jsxs("div",{className:"flex flex-col",children:[r.jsx("button",{type:"button",onClick:()=>k(N,-1),disabled:g||j===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(Uk,{className:"size-3.5"})}),r.jsx("button",{type:"button",onClick:()=>k(N,1),disabled:g||j===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(Wa,{className:"size-3.5"})})]}),r.jsx(Qc,{ok:y.available?!0:y.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")}),y.available?r.jsx(Fe,{tone:"success",children:f("voice_ui.badge_available")}):y.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:[v?r.jsx(Qt,{checked:E?!0:y.enabled,onChange:R=>u(N,R),disabled:g||E}):!C&&r.jsxs(ie,{size:"sm",variant:"ghost",onClick:()=>c(N),disabled:g,"data-testid":`voice-provider-${N}-default`,children:[r.jsx(lM,{className:"size-3.5"})," ",f("voice_ui.set_as_default")]}),C&&r.jsx(Lx,{className:"size-4 text-emerald-400"}),r.jsxs(ie,{size:"sm",variant:"secondary",onClick:()=>m(N),"data-testid":`voice-provider-${N}-config`,children:[r.jsx(VM,{className:"size-3.5"})," ",f("voice_ui.configure")]})]})]},N)})})]})}function Os(e){return typeof e=="string"?e:e==null?"":String(e)}function M7({open:e,providerId:t,config:a,onClose:o,onSave:l}){const[c,u]=x.useState(!1),[p,m]=x.useState(null),[g,h]=x.useState(""),[b,v]=x.useState({});if(x.useEffect(()=>{if(!e||!t)return;m(null),h("");const R=a||{};if(t==="piper"){const A=R;v({bin:Os(A.bin),model:Os(A.model),speaker:Os(A.speaker)})}else if(t==="elevenlabs"){const A=R;v({model:Os(A.model),voice_id:Os(A.voice_id),output_format:Os(A.output_format)})}else if(t==="openai"){const A=R;v({model:Os(A.model)||"tts-1",voice:Os(A.voice)||"alloy",format:Os(A.format)||"mp3"})}else if(t==="gemini"){const A=R;v({model:Os(A.model),voice:Os(A.voice)||"Kore",style:Os(A.style)})}else v({})},[e,t,a]),!t)return null;const k=mf[t],N=`voice.tts.${t}`,j=R=>v(A=>({...A,...R})),y=t!=="piper"&&t!=="mock",S=y&&os(a?.api_key),C=S?f("voice_ui.api_key_set",{suffix:jo(a?.api_key)??""}):f("voice_ui.api_key_label"),E=async()=>{u(!0),m(null);try{const R={},A=[],T=(M,z)=>{z.trim()?R[`${N}.${M}`]=z.trim():A.push(`${N}.${M}`)};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)),y&&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(ie,{variant:"ghost",onClick:o,disabled:c,children:f("common.cancel")}),r.jsx(ie,{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(ue,{label:f("voice_ui.piper_bin_label"),hint:f("voice_ui.piper_bin_hint"),children:r.jsx(Re,{value:b.bin,onChange:R=>j({bin:R.target.value}),placeholder:"piper"})}),r.jsx(ue,{label:f("voice_ui.piper_model_label"),hint:f("voice_ui.piper_model_hint"),children:r.jsx(Re,{value:b.model,onChange:R=>j({model:R.target.value}),placeholder:"/abs/path/voice.onnx"})}),r.jsx(ue,{label:f("voice_ui.piper_speaker_label"),hint:f("voice_ui.piper_speaker_hint"),children:r.jsx(Re,{value:b.speaker,onChange:R=>j({speaker:R.target.value}),placeholder:"0"})})]}),t==="elevenlabs"&&r.jsxs(r.Fragment,{children:[r.jsx(ue,{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(Re,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(ue,{label:f("voice_ui.model_label"),children:r.jsx(bt,{value:b.model||"",onChange:R=>j({model:R}),options:UD.map(R=>({value:R,label:R})),placeholder:"eleven_multilingual_v2"})}),r.jsx(ue,{label:f("voice_ui.voice_id_label"),hint:f("voice_ui.voice_id_hint"),children:r.jsx(Re,{value:b.voice_id,onChange:R=>j({voice_id:R.target.value}),placeholder:"EXAVITQu4vr4xnSDxMaL"})}),r.jsx(ue,{label:f("voice_ui.output_format_label"),children:r.jsx(Re,{value:b.output_format,onChange:R=>j({output_format:R.target.value}),placeholder:"mp3_44100_128"})})]}),t==="openai"&&r.jsxs(r.Fragment,{children:[r.jsx(ue,{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(Re,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(ue,{label:f("voice_ui.model_label"),children:r.jsx(bt,{value:b.model||"tts-1",onChange:R=>j({model:R}),options:HD.map(R=>({value:R,label:R}))})}),r.jsx(ue,{label:f("voice_ui.voice_label"),children:r.jsx(bt,{value:b.voice||"alloy",onChange:R=>j({voice:R}),options:ID.map(R=>({value:R,label:R}))})}),r.jsx(ue,{label:f("voice_ui.format_label"),children:r.jsx(bt,{value:b.format||"mp3",onChange:R=>j({format:R}),options:["mp3","opus","aac","flac","wav"].map(R=>({value:R,label:R}))})})]}),t==="gemini"&&r.jsxs(r.Fragment,{children:[r.jsx(ue,{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(Re,{type:"password",autoComplete:"new-password",value:g,onChange:R=>h(R.target.value),placeholder:C})}),r.jsx(ue,{label:f("voice_ui.model_label"),hint:f("voice_ui.gemini_model_hint"),children:r.jsx(Re,{value:b.model,onChange:R=>j({model:R.target.value}),placeholder:"gemini-2.5-flash-preview-tts"})}),r.jsx(ue,{label:f("voice_ui.voice_label"),children:r.jsx(bt,{value:b.voice||"Kore",onChange:R=>j({voice:R}),options:BD.map(R=>({value:R,label:R}))})}),r.jsx(ue,{label:f("voice_ui.style_label"),hint:f("voice_ui.style_hint"),children:r.jsx(Un,{rows:2,value:b.style||"",onChange:R=>j({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 O7(){const e=x.useRef(null),t=x.useRef(null),[a,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 qD(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:a,loading:l}}function z7({engines:e,defaultProvider:t,mode:a}){const o=rt(),{play:l,stop:c,playing:u,loading:p}=O7(),[m,g]=x.useState(f("voice_ui.test_default_text")),[h,b]=x.useState(""),[v,k]=x.useState(""),[N,j]=x.useState(!1),[y,S]=x.useState(null),E=[{value:"",label:a==="single"&&t&&t!=="auto"?f("voice_ui.test_default_engine",{name:mf[t]?.name||t}):f("voice_ui.test_default_chain")},...e.map(A=>({value:A.id,label:`${mf[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}j(!0);try{const T=await gf.say({text:A,provider:h||void 0,style:v.trim()||void 0});S(T),await l(T.audio_path)}catch(T){o.error(T.message||f("voice_ui.test_synth_error"))}finally{j(!1)}};return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("voice_ui.test_engine_label"),hint:f("voice_ui.test_engine_hint"),children:r.jsx(bt,{value:h,onChange:b,options:E})}),r.jsx(ue,{label:f("voice_ui.test_style_label"),hint:f("voice_ui.test_style_hint"),children:r.jsx(Re,{value:v,onChange:A=>k(A.target.value),placeholder:f("voice_ui.style_ph"),"data-testid":"voice-test-style"})})]}),r.jsx(ue,{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(ie,{variant:"primary",onClick:R,loading:N,disabled:p,"data-testid":"voice-test-say",children:[r.jsx(KM,{className:"size-4"})," ",f("voice_ui.say_this")]}),u?r.jsxs(ie,{variant:"secondary",onClick:c,"data-testid":"voice-test-stop",children:[r.jsx(Xk,{className:"size-4"})," ",f("voice_ui.stop")]}):y?r.jsxs(ie,{variant:"secondary",onClick:()=>l(y.audio_path),loading:p,"data-testid":"voice-test-replay",children:[r.jsx(Vx,{className:"size-4"})," ",f("voice_ui.replay")]}):null,y&&r.jsxs("span",{className:"text-xs text-muted-fg",children:[f("voice_ui.engine_result"),": ",r.jsx("strong",{children:y.provider}),y.duration_s?` · ${y.duration_s.toFixed(1)}s`:""]})]})]})}const qw={metal:{label:"Metal",cls:"text-emerald-400 border-emerald-500/40 bg-emerald-500/10"},cuda:{label:"CUDA",cls:"text-lime-400 border-lime-500/40 bg-lime-500/10"},rocm:{label:"Vulkan / ROCm",cls:"text-orange-400 border-orange-500/40 bg-orange-500/10"},none:{label:"CPU",cls:"text-muted-fg border-border bg-muted"}};function $w({gpu:e}){const t=qw[e]??qw.none;return r.jsx("span",{className:`inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] font-medium ${t.cls}`,children:t.label})}function D7(e){return e.backend==="mlx"?"Metal · mlx-whisper":e.backend==="faster"?(e.device==="cuda"?"CUDA":"CPU")+" · faster-whisper":e.backend}const P7=()=>[{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")}],Fw=()=>[{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 L7({config:e,onPatch:t,busy:a}){const[o,l]=x.useState(null);x.useEffect(()=>{let B=!0;return gf.sttHardware().then(V=>{B&&l(V)}).catch(()=>{}),()=>{B=!1}},[]);const c=e.provider||"auto",u=e.local||{},p=e.openai||{},m=e.custom||{},g=u.model||"small",h=u.language||"auto",b=c==="auto"||c==="local",v=(B,V,G)=>{const q=G.trim();q!==(V||"").trim()&&t({[B]:q})},k=(B,V)=>{const G=V.trim();!G||os(G)||t({[B]:G})},N=B=>os(B)?f("voice_ui.api_key_set",{suffix:jo(B)??""}):f("voice_ui.api_key_label"),j=u.backend||"auto",y=o?.hardware.gpu||"none",S=j==="auto"?o?.recommended.backend||"faster":j,C=S==="mlx",E=C?"metal":S==="faster"&&y==="cuda"?"cuda":"none",R=()=>{const B=[{value:"auto",label:f("voice_ui.stt_backend_auto")}];return y==="metal"&&B.push({value:"mlx",label:"Metal — mlx-whisper"}),B.push({value:"faster",label:y==="cuda"?"CUDA — faster-whisper":"CPU — faster-whisper"}),B},[A,T]=x.useState([]);x.useEffect(()=>{let B=!0;return gf.sttModels(S).then(V=>{B&&T(V.models)}).catch(()=>{B&&T([])}),()=>{B=!1}},[S]);const M=B=>`${B.id} · ${B.downloaded?"✓ "+B.size:B.size}`,z=()=>A.length?A.map(B=>({value:C?B.repo:B.id,label:M(B)})):VD.map(B=>({value:B,label:B})),L=C?u.mlx_model||o?.recommended.model||"":g,D=C?"transcription.local.mlx_model":"transcription.local.model",H=A.find(B=>(C?B.repo:B.id)===L),I=!!H&&!H.downloaded;return r.jsxs("div",{className:"space-y-3",children:[o&&r.jsxs("div",{className:"rounded-lg border border-border bg-muted px-3 py-2 text-sm",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsxs("span",{className:"text-muted-fg",children:[f("voice_ui.stt_hw_label"),":"]}),r.jsx($w,{gpu:o.hardware.gpu}),r.jsx("span",{className:"font-medium text-fg",children:o.hardware.gpuName||o.hardware.platform}),o.hardware.mem_gb?r.jsxs("span",{className:"text-muted-fg",children:["· ",o.hardware.mem_gb," GB",o.hardware.unified_memory?" unified":""]}):null]}),r.jsxs("div",{className:"mt-1 text-xs text-muted-fg",children:[f("voice_ui.stt_hw_recommended"),":"," ",r.jsx("span",{className:"text-fg",children:o.recommended.model})," ","(",D7(o.recommended),")",o.recommended.limited?` — ${f("voice_ui.stt_hw_limited")}`:""]})]}),r.jsx(ue,{label:f("voice_ui.stt_engine_label"),hint:f("voice_ui.stt_engine_hint"),children:r.jsx(bt,{value:c,onChange:B=>t({"transcription.provider":B}),options:P7(),disabled:a,className:"max-w-md"})}),b&&r.jsxs("div",{className:"space-y-3",children:[r.jsx(ue,{label:f("voice_ui.stt_backend_label"),hint:f("voice_ui.stt_backend_hint"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(bt,{value:j,onChange:B=>t({"transcription.local.backend":B}),options:R(),disabled:a,className:"max-w-xs"}),r.jsx($w,{gpu:E})]})}),r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("voice_ui.stt_model_label"),hint:I?f("voice_ui.stt_model_needs_download",{size:H.size}):f("voice_ui.stt_model_hint"),children:r.jsx(bt,{value:L,onChange:B=>t({[D]:B}),options:z(),disabled:a})}),r.jsx(ue,{label:f("voice_ui.stt_language_label"),hint:f("voice_ui.stt_language_hint"),children:r.jsx(bt,{value:h,onChange:B=>t({"transcription.local.language":B}),options:Fw(),disabled:a})})]})]}),c==="openai"&&r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("voice_ui.api_key_label"),hint:os(p.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(Re,{type:"password",autoComplete:"new-password",defaultValue:"",placeholder:N(p.api_key),onBlur:B=>k("transcription.openai.api_key",B.target.value),disabled:a})}),r.jsx(ue,{label:f("voice_ui.stt_openai_model_label"),hint:f("voice_ui.stt_openai_model_hint"),children:r.jsx(Re,{defaultValue:p.model||"",placeholder:"whisper-1",onBlur:B=>v("transcription.openai.model",p.model,B.target.value),disabled:a})})]}),c==="custom"&&r.jsxs("div",{className:"space-y-3",children:[r.jsx(ue,{label:f("voice_ui.stt_custom_baseurl_label"),hint:f("voice_ui.stt_custom_baseurl_hint"),children:r.jsx(Re,{defaultValue:m.base_url||"",placeholder:"http://localhost:8000/v1",onBlur:B=>v("transcription.custom.base_url",m.base_url,B.target.value),disabled:a})}),r.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[r.jsx(ue,{label:f("voice_ui.stt_custom_model_label"),hint:f("voice_ui.stt_custom_model_hint"),children:r.jsx(Re,{defaultValue:m.model||"",placeholder:"mlx-community/whisper-large-v3-turbo",onBlur:B=>v("transcription.custom.model",m.model,B.target.value),disabled:a})}),r.jsx(ue,{label:f("voice_ui.stt_language_label"),hint:f("voice_ui.stt_language_hint"),children:r.jsx(bt,{value:m.language||"auto",onChange:B=>t({"transcription.custom.language":B}),options:Fw(),disabled:a})})]}),r.jsx(ue,{label:f("voice_ui.api_key_label"),hint:f("voice_ui.stt_custom_key_hint"),children:r.jsx(Re,{type:"password",autoComplete:"new-password",defaultValue:"",placeholder:N(m.api_key),onBlur:B=>k("transcription.custom.api_key",B.target.value),disabled:a})})]})]})}function I7(){const e=rt(),{config:t,isLoading:a,patch:o,mutate:l}=Vr(),{data:c,isLoading:u,error:p,mutate:m}=et("/tts/providers",()=>gf.providers()),[g,h]=x.useState(null),[b,v]=x.useState(!1),k=t,N=k.voice?.tts||{},j=k.transcription||{},y=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 H=>{v(!0);try{await o({"voice.tts.provider":H,"voice.tts.mode":"single"}),await m(),e.success(f("voice_ui.toast_default_engine",{id:H}))}catch(I){e.error(I.message)}finally{v(!1)}},T=async H=>{v(!0);try{const I={"voice.tts.mode":H};if(H==="single"&&(y==="auto"||!y)){const B=C.find(V=>V.available)?.id||E[0]||"mock";I["voice.tts.provider"]=B}await o(I),await m(),e.success(f(H==="chain"?"voice_ui.toast_mode_chain":"voice_ui.toast_mode_single"))}catch(I){e.error(I.message)}finally{v(!1)}},M=async(H,I)=>{v(!0);try{await o({[`voice.tts.${H}.enabled`]:I}),await m()}catch(B){e.error(B.message)}finally{v(!1)}},z=async H=>{v(!0);try{await o({"voice.tts.order":H}),await m()}catch(I){e.error(I.message)}finally{v(!1)}},L=async({set:H,unset:I})=>{await o(H,I.length?I:void 0),await m(),await l(),e.success(f("voice_ui.toast_config_saved"))},D=async(H,I)=>{try{await o(H,I),e.success(f("voice_ui.toast_transcription_updated"))}catch(B){e.error(B.message)}};return r.jsxs("div",{"data-testid":"screen-voice",children:[r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[r.jsx(Ke,{title:f("voice_screen.providers_title"),description:f("voice_ui.providers_desc"),children:u||a?r.jsx(lt,{}):p?r.jsx(xt,{children:f("voice_ui.providers_load_error",{msg:p.message})}):r.jsx(A7,{engines:C,order:E,mode:S,configuredProvider:y,onSetMode:T,onSetDefault:A,onToggleEnabled:M,onReorder:z,onConfigure:H=>h(H),busy:b})}),r.jsxs("div",{className:"space-y-6",children:[r.jsx(Ke,{title:f("voice_screen.test_title"),description:f("voice_ui.test_desc"),children:r.jsx(z7,{engines:C,defaultProvider:y,mode:S})}),r.jsx(Ke,{title:f("voice_screen.stt_title"),description:f("voice_ui.stt_desc"),children:a?r.jsx(lt,{}):r.jsx(L7,{config:j,onPatch:D})})]})]}),r.jsx(M7,{open:!!g,providerId:g,config:R,onClose:()=>h(null),onSave:L})]})}function B7(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 U7({manifest:e}){const t=e.daemon,a=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:B7(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:[a.direct_shell===!1&&r.jsx(Fe,{tone:"success",children:f("modules_ui.deck_safety_no_shell")}),a.arbitrary_commands===!1&&r.jsx(Fe,{tone:"success",children:f("modules_ui.deck_safety_no_arbitrary")}),a.dangerous_actions_require_confirmation&&r.jsx(Fe,{tone:"info",children:f("modules_ui.deck_safety_confirm")})]})]})}function H7(e){return e==="available"?"success":e==="configured"?"info":"muted"}function V7(e){return e==="available"?"activo":e==="configured"?"configurado":e==="disabled"?"deshabilitado":"sin configurar"}function q7(e){return e==="voice"?"warning":e==="plugin"?"info":"muted"}function $7({widget:e,onToggle:t}){const a=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:Me("flex items-center gap-3 rounded-lg border px-3 py-2.5 text-sm transition-colors",a?"border-border bg-muted/20 hover:border-muted-fg/30":"border-border/50 bg-muted/10"),children:[r.jsx(Ye,{content:e.source==="apx"?f("deck_screen.widget_native"):f("deck_screen.widget_external"),children:r.jsx("span",{className:Me("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:q7(e.kind),children:e.kind}),r.jsx(Fe,{tone:H7(e.status),children:V7(e.status)}),a?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 F7({desktop:e,widgets:t,onToggle:a}){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($7,{widget:o,onToggle:o.source==="external"?l=>a(o.id,l):void 0},o.id))})]})}function G7(){rt();const{data:e,error:t,isLoading:a,mutate:o}=et("/deck/manifest",()=>xC.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(U7,{manifest:e}),r.jsxs(Ke,{title:f("deck_screen.widgets_title"),description:a?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(Ye,{content:f("deck_screen.reload_manifest"),children:r.jsx(ie,{size:"sm",variant:"ghost",onClick:()=>o(),disabled:a,"aria-label":f("deck_screen.reload_manifest"),children:r.jsx(ua,{size:14,className:a?"animate-spin":""})})}),children:[a&&r.jsx(lt,{label:f("modules_ui.deck_loading_manifest_full")}),!a&&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")})]}),!a&&!t&&u.length===0&&r.jsx(xt,{children:f("modules_ui.deck_no_widgets")}),!a&&!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(F7,{desktop:h.desktop,widgets:h.widgets,onToggle:l},h.desktop.id))})]}),e?.apx&&r.jsx(Ke,{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(dM,{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 Y7=[{title:f("settings.account_section"),items:[{key:"identity",label:f("settings.tabs.identity"),icon:$x},{key:"appearance",label:f("settings.appearance"),icon:IM}]},{title:f("settings.agents_section"),items:[{key:"super_agent",label:f("settings.tabs.super_agent"),icon:un},{key:"engines",label:f("settings.tabs.engines"),icon:Ix},{key:"memory",label:"Memory (RAG)",icon:Hk},{key:"skills",label:"Skills (RAG)",icon:pa}]},{title:f("settings.channels_section"),items:[{key:"telegram",label:f("settings.tabs.telegram"),icon:Fs},{key:"devices",label:f("settings.tabs.devices"),icon:qM}]},{title:f("settings.modules_section"),items:[{key:"voice",label:f("nav.modules.voice"),icon:Gk},{key:"desktop",label:f("nav.modules.desktop"),icon:Hx},{key:"deck",label:f("nav.modules.deck"),icon:OM}]},{title:f("settings.advanced_section"),items:[{key:"advanced",label:f("settings.tabs.advanced"),icon:Xd}]}],K7=new Set(["engines","telegram","memory","skills","appearance","voice"]),X7={identity:()=>r.jsx(T8,{}),super_agent:()=>r.jsx(A8,{}),engines:()=>r.jsx(sN,{}),memory:()=>r.jsx(z8,{}),skills:()=>r.jsx(P8,{}),telegram:()=>r.jsx(H8,{}),devices:()=>r.jsx(g7,{}),voice:()=>r.jsx(I7,{}),deck:()=>r.jsx(G7,{}),desktop:()=>r.jsx(T7,{}),appearance:()=>r.jsx(_7,{}),advanced:()=>r.jsx(b7,{})};function Q7(){const e=Qn(),t=Xn(),a=Z7(t.pathname),o=X7[a],{collapsed:l,toggle:c}=Hb(Rn.sidebarCollapsed+".settings");return r.jsx(HC,{sections:Y7,active:a,onChange:u=>e(u==="identity"?"/settings":`/settings/${W7(u)}`),collapsed:l,onToggleCollapse:c,contentClassName:`w-full ${K7.has(a)?"":"mx-auto max-w-3xl"} space-y-6 p-6 pt-3`,testId:`settings-tab-${a}`,children:r.jsx(o,{})})}function Z7(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 W7(e){return e==="super_agent"?"super-agent":e==="advanced"?"config":e}function J7(){const{data:e,isLoading:t,mutate:a}=et("/messages/global?channel=desktop",()=>C7(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(ON,{showConfigLink:!0})}),r.jsx("div",{children:r.jsx(Ke,{title:f("desktop_screen.last_conv_title"),description:f("modules_ui.desktop_last_conv_desc"),action:r.jsx("button",{type:"button",onClick:()=>a(),className:"text-xs text-muted-fg underline-offset-2 hover:underline",children:f("modules_ui.desktop_refresh")}),children:r.jsx(eB,{messages:e||[],loading:t})})})]})})}function eB({messages:e,loading:t}){const a=x.useMemo(()=>nB(e),[e]);return t?r.jsx(lt,{}):e.length?r.jsx("div",{className:"space-y-3 max-h-[560px] overflow-y-auto pr-1",children:a.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(tB,{m:c},u))},l))}):r.jsx(xt,{children:f("modules_ui.desktop_no_messages")})}function tB({m:e}){const t=e.direction==="in",a=sB(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:a})]}),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 nB(e){const t=[];for(const a of e)a.direction==="in"||!t.length?t.push([a]):t[t.length-1].push(a);return t}function sB(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 aB(e,t){const a=getComputedStyle(e),o=parseFloat(a.fontSize);return t*o}function rB(e,t){const a=getComputedStyle(e.ownerDocument.documentElement),o=parseFloat(a.fontSize);return t*o}function oB(e){return e/100*window.innerHeight}function lB(e){return e/100*window.innerWidth}function iB(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 bc({groupSize:e,panelElement:t,styleProp:a}){let o;const[l,c]=iB(a);switch(c){case"%":{o=l/100*e;break}case"px":{o=l;break}case"rem":{o=rB(t,l);break}case"em":{o=aB(t,l);break}case"vh":{o=oB(l);break}case"vw":{o=lB(l);break}}return o}function Yn(e){return parseFloat(e.toFixed(3))}function Yl({group:e}){const{orientation:t,panels:a}=e;return a.reduce((o,l)=>(o+=t==="horizontal"?l.element.offsetWidth:l.element.offsetHeight,o),0)}function Sx(e){const{panels:t}=e,a=Yl({group:e});return a===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=bc({groupSize:a,panelElement:l,styleProp:c.collapsedSize});u=Yn(h/a*100)}let p;if(c.defaultSize!==void 0){const h=bc({groupSize:a,panelElement:l,styleProp:c.defaultSize});p=Yn(h/a*100)}let m=0;if(c.minSize!==void 0){const h=bc({groupSize:a,panelElement:l,styleProp:c.minSize});m=Yn(h/a*100)}let g=100;if(c.maxSize!==void 0){const h=bc({groupSize:a,panelElement:l,styleProp:c.maxSize});g=Yn(h/a*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 Cx(e,t){return Array.from(t).sort(e==="horizontal"?cB:uB)}function cB(e,t){const a=e.element.offsetLeft-t.element.offsetLeft;return a!==0?a:e.element.offsetWidth-t.element.offsetWidth}function uB(e,t){const a=e.element.offsetTop-t.element.offsetTop;return a!==0?a:e.element.offsetHeight-t.element.offsetHeight}function zN(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function DN(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 dB({orientation:e,rects:t,targetRect:a}){const o={x:a.x+a.width/2,y:a.y+a.height/2};let l,c=Number.MAX_VALUE;for(const u of t){const{x:p,y:m}=DN(o,u),g=e==="horizontal"?p:m;g<c&&(c=g,l=u)}return Bt(l,"No rect found"),l}let zd;function fB(){return zd===void 0&&(typeof matchMedia=="function"?zd=!!matchMedia("(pointer:coarse)").matches:zd=!1),zd}function PN(e){const{element:t,orientation:a,panels:o,separators:l}=e,c=Cx(a,Array.from(t.children).filter(zN).map(N=>({element:N}))).map(({element:N})=>N),u=[];let p=!1,m=!1,g=-1,h=-1,b=0,v,k=[];{let N=-1;for(const j of c)j.hasAttribute("data-panel")&&(N++,j.hasAttribute("data-disabled")||(b++,g===-1&&(g=N),h=N))}if(b>1){let N=-1;for(const j of c)if(j.hasAttribute("data-panel")){N++;const y=o.find(S=>S.element===j);if(y){if(v){const S=v.element.getBoundingClientRect(),C=j.getBoundingClientRect();let E;if(m){const R=a==="horizontal"?new DOMRect(S.right,S.top,0,S.height):new DOMRect(S.left,S.bottom,S.width,0),A=a==="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],M=dB({orientation:a,rects:[S,C],targetRect:T.element.getBoundingClientRect()});E=[T,M===S?A:R];break}default:{E=k;break}}}else k.length?E=k:E=[a==="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=fB()?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 M=N<=g||N>h;!p&&!M&&u.push({group:e,groupSize:Yl({group:e}),panels:[v,y],separator:"width"in R?void 0:R,rect:A}),p=!1}}m=!1,v=y,k=[]}}else if(j.hasAttribute("data-separator")){j.ariaDisabled!==null&&(p=!0);const y=l.find(S=>S.element===j);y?k.push(y):(v=void 0,k=[])}else m=!0}return u}class LN{#e={};addListener(t,a){const o=this.#e[t];return o===void 0?this.#e[t]=[a]:o.includes(a)||o.push(a),()=>{this.removeListener(t,a)}}emit(t,a){const o=this.#e[t];if(o!==void 0)if(o.length===1)o[0].call(null,a);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,a)}catch(g){c===null&&(l=!0,c=g)}}if(l)throw c}}removeAllListeners(){this.#e={}}removeListener(t,a){const o=this.#e[t];if(o!==void 0){const l=o.indexOf(a);l>=0&&o.splice(l,1)}}}let ra=new Map;const IN=new LN;function pB(e){ra=new Map(ra),ra.delete(e)}function Gw(e,t){for(const[a]of ra)if(a.id===e)return a}function Mr(e,t){for(const[a,o]of ra)if(a.id===e)return o;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Oo(){return ra}function x_(e,t){return IN.addListener("groupChange",a=>{a.group.id===e&&t(a)})}function Za(e,t,a){const o=ra.get(e);ra=new Map(ra),ra.set(e,t),IN.emit("groupChange",{group:e,isUserInteraction:a?.isUserInteraction===!0,prev:o,next:t})}function mB(e,t,a){let o,l={x:1/0,y:1/0};for(const c of t){const u=DN(a,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 gB(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function hB(e,t){if(e===t)throw new Error("Cannot compare node with itself");const a={a:Xw(e),b:Xw(t)};let o;for(;a.a.at(-1)===a.b.at(-1);)o=a.a.pop(),a.b.pop();Bt(o,"Stacking order can only be calculated for elements with a common ancestor");const l={a:Kw(Yw(a.a)),b:Kw(Yw(a.b))};if(l.a===l.b){const c=o.childNodes,u={a:a.a.at(-1),b:a.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 xB=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function bB(e){const t=getComputedStyle(BN(e)??e).display;return t==="flex"||t==="inline-flex"}function _B(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||bB(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"||xB.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Yw(e){let t=e.length;for(;t--;){const a=e[t];if(Bt(a,"Missing node"),_B(a))return a}return null}function Kw(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Xw(e){const t=[];for(;e;)t.push(e),e=BN(e);return t}function BN(e){const{parentNode:t}=e;return gB(t)?t.host:t}function vB(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 yB({groupElement:e,hitRegion:t,pointerEventTarget:a}){if(!zN(a)||a.contains(e)||e.contains(a))return!0;if(hB(a,e)>0){let o=a;for(;o;){if(o.contains(e))return!0;if(vB(o.getBoundingClientRect(),t))return!1;o=o.parentElement}}return!0}function b_(e,t){const a=[];return t.forEach((o,l)=>{if(l.disabled)return;const c=PN(l),u=mB(l.orientation,c,{x:e.clientX,y:e.clientY});u&&u.distance.x<=0&&u.distance.y<=0&&yB({groupElement:l.element,hitRegion:u.hitRegion.rect,pointerEventTarget:e.target})&&a.push(u.hitRegion)}),a}function jB(e,t){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!=t[a])return!1;return!0}function qn(e,t,a=0){return Math.abs(Yn(e)-Yn(t))<=a}function ta(e,t){return qn(e,t)?0:e>t?1:-1}function Sl({overrideDisabledPanels:e,panelConstraints:t,prevSize:a,size:o}){const{collapsedSize:l=0,collapsible:c,disabled:u,maxSize:p=100,minSize:m=0}=t;if(u&&!e)return a;if(ta(o,m)<0)if(c){const g=(l+m)/2;ta(o,g)<0?o=l:o=m}else o=m;return o=Math.min(p,o),o=Yn(o),o}function Ic({delta:e,initialLayout:t,panelConstraints:a,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 v=0;switch(c){case"keyboard":{{const j=e<0?b:h,y=a[j];Bt(y,`Panel constraints not found for index ${j}`);const{collapsedSize:S=0,collapsible:C,minSize:E=0}=y;if(C){const R=p[j];if(Bt(R!=null,`Previous layout not found for panel index ${j}`),qn(R,S)){const A=E-R;ta(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}{const j=e<0?h:b,y=a[j];Bt(y,`No panel constraints found for index ${j}`);const{collapsedSize:S=0,collapsible:C,minSize:E=0}=y;if(C){const R=p[j];if(Bt(R!=null,`Previous layout not found for panel index ${j}`),qn(R,E)){const A=R-S;ta(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}break}default:{const j=e<0?b:h,y=a[j];Bt(y,`Panel constraints not found for index ${j}`);const S=p[j],{collapsible:C,collapsedSize:E,minSize:R}=y;if(C&&ta(S,R)<0)if(e>0){const A=R-E,T=A/2,M=S+e;ta(M,R)<0&&(e=ta(e,T)<=0?0:A)}else{const A=R-E,T=100-A/2,M=S-e;ta(M,R)<0&&(e=ta(100+e,T)>0?0:-A)}break}}{const j=e<0?1:-1;let y=e<0?b:h,S=0;for(;;){const E=p[y];Bt(E!=null,`Previous layout not found for panel index ${y}`);const R=Sl({overrideDisabledPanels:u,panelConstraints:a[y],prevSize:E,size:100})-E;if(S+=R,y+=j,y<0||y>=a.length)break}const C=Math.min(Math.abs(e),Math.abs(S));e=e<0?0-C:C}{let j=e<0?h:b;for(;j>=0&&j<a.length;){const y=Math.abs(e)-Math.abs(v),S=p[j];Bt(S!=null,`Previous layout not found for panel index ${j}`);const C=S-y,E=Sl({overrideDisabledPanels:u,panelConstraints:a[j],prevSize:S,size:C});if(!qn(S,E)&&(v+=S-E,g[j]=E,v.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?j--:j++}}if(jB(m,g))return l;{const j=e<0?b:h,y=p[j];Bt(y!=null,`Previous layout not found for panel index ${j}`);const S=y+v,C=Sl({overrideDisabledPanels:u,panelConstraints:a[j],prevSize:y,size:S});if(g[j]=C,!qn(C,S)){let E=S-C,R=e<0?b:h;for(;R>=0&&R<a.length;){const A=g[R];Bt(A!=null,`Previous layout not found for panel index ${R}`);const T=A+E,M=Sl({overrideDisabledPanels:u,panelConstraints:a[R],prevSize:A,size:T});if(qn(A,M)||(E-=M-A,g[R]=M),qn(E,0))break;e>0?R--:R++}}}const k=Object.values(g).reduce((j,y)=>y+j,0);if(!qn(k,100,.1))return l;const N=Object.keys(l);return g.reduce((j,y,S)=>(j[N[S]]=y,j),{})}function So(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const a in e)if(t[a]===void 0||ta(e[a],t[a])!==0)return!1;return!0}function Co({layout:e,panelConstraints:t}){const a=Object.values(e),o=[...a],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=a[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=Sl({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=Sl({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 UN({groupId:e,panelId:t}){const a=()=>{const m=Oo();for(const[g,{defaultLayoutDeferred:h,derivedPanelConstraints:b,layout:v,groupSize:k,separatorToPanels:N}]of m)if(g.id===e)return{defaultLayoutDeferred:h,derivedPanelConstraints:b,group:g,groupSize:k,layout:v,separatorToPanels:N};throw Error(`Group ${e} not found`)},o=()=>{const m=a().derivedPanelConstraints.find(g=>g.panelId===t);if(m!==void 0)return m;throw Error(`Panel constraints not found for Panel ${t}`)},l=()=>{const m=a().group.panels.find(g=>g.id===t);if(m!==void 0)return m;throw Error(`Layout not found for Panel ${t}`)},c=()=>{const m=a().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 v=c(),k=g.findIndex(y=>y.id===t),N=k===0,j=k===g.length-1;if(j&&m<v&&(N||g.slice(0,k).every((y,S)=>{const C=b[S];return C?.collapsible&&qn(C.collapsedSize,h[C.panelId])}))){const y=g.slice(0,k).reduce((S,C)=>S+h[C.id],0);return{...h,[t]:Yn(100-y)}}return Ic({delta:j?v-m:m-v,initialLayout:h,panelConstraints:b,pivotIndices:j?[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:v,groupSize:k,layout:N,separatorToPanels:j}=a(),y=u({nextSize:m,panels:v.panels,prevLayout:N,derivedPanelConstraints:b}),S=Co({layout:y,panelConstraints:b});So(N,S)||Za(v,{defaultLayoutDeferred:h,derivedPanelConstraints:b,groupSize:k,layout:S,separatorToPanels:j})};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(),v=c();if(m&&v===g){let k=b.expandToSize??h;k===0&&(k=1),p(k)}},getSize:()=>{const{group:m}=a(),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}=a(),{element:h}=l(),b=Yl({group:g}),v=bc({groupSize:b,panelElement:h,styleProp:m}),k=Yn(v/b*100);p(k)}}}function Qw(e){if(e.defaultPrevented)return;const t=Oo();b_(e,t).forEach(a=>{if(a.separator&&!a.separator.disableDoubleClick){const o=a.panels.find(l=>l.panelConstraints.defaultSize!==void 0);if(o){const l=o.panelConstraints.defaultSize,c=UN({groupId:a.group.id,panelId:o.id});c&&l!==void 0&&(c.resize(l),e.preventDefault())}}})}function qd(e){const t=Oo();for(const[a]of t)if(a.separators.some(o=>o.element===e))return a;throw Error("Could not find parent Group for separator element")}function HN({groupId:e}){const t=()=>{const a=Oo();for(const[o,l]of a)if(o.id===e)return{group:o,...l};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:a,layout:o}=t();return a?{}:o},setLayout(a){const{defaultLayoutDeferred:o,derivedPanelConstraints:l,group:c,groupSize:u,layout:p,separatorToPanels:m}=t(),g=Co({layout:a,panelConstraints:l});return o?p:(So(p,g)||Za(c,{defaultLayoutDeferred:o,derivedPanelConstraints:l,groupSize:u,layout:g,separatorToPanels:m}),g)}}}function io(e,t){const a=qd(e),o=Mr(a.id,!0),l=a.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=>a.panels.indexOf(h)),p=HN({groupId:a.id}).getLayout(),m=Ic({delta:t,initialLayout:p,panelConstraints:o.derivedPanelConstraints,pivotIndices:u,prevLayout:p,trigger:"keyboard"}),g=Co({layout:m,panelConstraints:o.derivedPanelConstraints});So(p,g)||Za(a,{defaultLayoutDeferred:o.defaultLayoutDeferred,derivedPanelConstraints:o.derivedPanelConstraints,groupSize:o.groupSize,layout:g,separatorToPanels:o.separatorToPanels},{isUserInteraction:!0})}function Zw(e){if(e.defaultPrevented)return;const t=e.currentTarget,a=qd(t);if(!a.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),a.orientation==="vertical"&&io(t,5);break}case"ArrowLeft":{e.preventDefault(),a.orientation==="horizontal"&&io(t,-5);break}case"ArrowRight":{e.preventDefault(),a.orientation==="horizontal"&&io(t,5);break}case"ArrowUp":{e.preventDefault(),a.orientation==="vertical"&&io(t,-5);break}case"End":{e.preventDefault(),io(t,100);break}case"Enter":{e.preventDefault();const o=qd(t),l=Mr(o.id,!0),{derivedPanelConstraints:c,layout:u,separatorToPanels:p}=l,m=o.separators.find(v=>v.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(v=>v.panelId===h.id);if(Bt(b,"Panel metadata not found"),b.collapsible){const v=u[h.id],k=b.collapsedSize===v?o.mutableState.expandedPanelSizes[h.id]??b.minSize:b.collapsedSize;io(t,k-v)}break}case"F6":{e.preventDefault();const o=qd(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 Ol={cursorFlags:0,state:"inactive"};const __=new LN;function No(){return Ol}function wB(e){return __.addListener("change",e)}function kB(e){const t=Ol,a={...Ol};a.cursorFlags=e,Ol=a,__.emit("change",{prev:t,next:a})}function zl(e){const t=Ol;Ol=e,__.emit("change",{prev:t,next:e})}function Ww(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Oo(),a=b_(e,t),o=new Map;let l=!1;a.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)}),zl({cursorFlags:0,hitRegions:a,initialLayoutMap:o,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),a.length&&e.preventDefault()}const SB=e=>e,zh=()=>{},VN=1,qN=2,$N=4,FN=8,Jw=3,ek=12;let Dd;function tk(){return Dd===void 0&&(Dd=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Dd=!0)),Dd}function CB({cursorFlags:e,groups:t,state:a}){let o=0,l=0;switch(a){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(a){case"active":{if(e&&tk()){const c=(e&VN)!==0,u=(e&qN)!==0,p=(e&$N)!==0,m=(e&FN)!==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 tk()?o>0&&l>0?"move":o>0?"ew-resize":"ns-resize":o>0&&l>0?"grab":o>0?"col-resize":"row-resize"}}const nk=new WeakMap;function v_(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:a}=nk.get(e)??{};a===void 0&&(a=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(a):e.adoptedStyleSheets=[...e.adoptedStyleSheets,a]));const o=No();switch(o.state){case"active":case"hover":{const l=CB({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?a.cssRules.length===0?a.insertRule(c):a.replaceSync(c):a.cssRules.length===1&&a.deleteRule(0);break}case"inactive":{t=void 0,a.cssRules.length===1&&a.deleteRule(0);break}}nk.set(e,{prevStyle:t,styleSheet:a})}function GN({document:e,event:t,hitRegions:a,initialLayoutMap:o,mountedGroups:l,pointerDownAtPoint:c,prevCursorFlags:u}){let p=0;a.forEach(g=>{const{group:h,groupSize:b}=g,{orientation:v,panels:k}=h,{disableCursor:N}=h.mutableState;let j=0;c?v==="horizontal"?j=(t.clientX-c.x)/b*100:j=(t.clientY-c.y)/b*100:v==="horizontal"?j=t.clientX<0?-100:100:j=t.clientY<0?-100:100;const y=o.get(h),S=l.get(h);if(!y||!S)return;const{defaultLayoutDeferred:C,derivedPanelConstraints:E,groupSize:R,layout:A,separatorToPanels:T}=S;if(E&&A&&T){const M=Ic({delta:j,initialLayout:y,panelConstraints:E,pivotIndices:g.panels.map(z=>k.indexOf(z)),prevLayout:A,trigger:"mouse-or-touch"});if(So(M,A)){if(j!==0&&!N)switch(v){case"horizontal":{p|=j<0?VN:qN;break}case"vertical":{p|=j<0?$N:FN;break}}}else Za(g.group,{defaultLayoutDeferred:C,derivedPanelConstraints:E,groupSize:R,layout:M,separatorToPanels:T})}});let m=0;t.movementX===0?m|=u&Jw:m|=p&Jw,t.movementY===0?m|=u&ek:m|=p&ek,kB(m),v_(e)}function sk(e){const t=Oo(),a=No();switch(a.state){case"active":GN({document:e.currentTarget,event:e,hitRegions:a.hitRegions,initialLayoutMap:a.initialLayoutMap,mountedGroups:t,prevCursorFlags:a.cursorFlags})}}function ak(e){if(e.defaultPrevented)return;const t=No(),a=Oo();switch(t.state){case"active":{if(e.buttons===0){zl({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(o=>{const l=Mr(o.group.id,!0);Za(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)}GN({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:a,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const o=b_(e,a);o.length===0?t.state!=="inactive"&&zl({cursorFlags:0,state:"inactive"}):zl({cursorFlags:0,hitRegions:o,state:"hover"}),v_(e.currentTarget);break}}}function rk(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(No().state){case"hover":zl({cursorFlags:0,state:"inactive"})}}function ok(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=No();switch(t.state){case"active":zl({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(v_(e.currentTarget),t.hitRegions.forEach(a=>{const o=Mr(a.group.id,!0);Za(a.group,o,{isUserInteraction:!0})}),e.preventDefault())}}function lk(e){let t=0,a=0;const o={};for(const c of e)if(c.defaultSize!==void 0){t++;const u=Yn(c.defaultSize);a+=u,o[c.panelId]=u}else o[c.panelId]=void 0;const l=e.length-t;if(l!==0){const c=Yn((100-a)/l);for(const u of e)u.defaultSize===void 0&&(o[u.panelId]=c)}return o}function NB(e,t,a){if(!a[0])return;const o=e.panels.find(m=>m.element===t);if(!o||!o.onResize)return;const l=Yl({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 EB(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const a in e)if(e[a]!==t[a])return!1;return!0}function RB({group:e,nextGroupSize:t,prevGroupSize:a,prevLayout:o}){if(a<=0||t<=0||a===t)return o;let l=0,c=0,u=!1;const p=new Map,m=[];for(const b of e.panels){const v=o[b.id]??0;switch(b.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{u=!0;const k=v/100*a,N=Yn(k/t*100);p.set(b.id,N),l+=N;break}case"preserve-relative-size":default:{m.push(b.id),c+=v;break}}}if(!u||m.length===0)return o;const g=100-l,h={...o};if(p.forEach((b,v)=>{h[v]=b}),c>0)for(const b of m){const v=o[b]??0;h[b]=Yn(v/c*g)}else{const b=Yn(g/m.length);for(const v of m)h[v]=b}return h}function TB(e,t){const a=e.map(l=>l.id),o=Object.keys(t);if(a.length!==o.length)return!1;for(const l of a)if(!o.includes(l))return!1;return!0}const yl=new Map;function AB(e){let t=!0;Bt(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const a=e.element.ownerDocument.defaultView.ResizeObserver,o=new Set,l=new Set,c=new a(N=>{for(const j of N){const{borderBoxSize:y,target:S}=j;if(S===e.element){if(t){const C=Yl({group:e});if(C===0)return;const E=Mr(e.id);if(!E)return;const R=Sx(e),A=E.defaultLayoutDeferred?lk(R):E.layout,T=RB({group:e,nextGroupSize:C,prevGroupSize:E.groupSize,prevLayout:A}),M=Co({layout:T,panelConstraints:R});if(!E.defaultLayoutDeferred&&So(E.layout,M)&&EB(E.derivedPanelConstraints,R)&&E.groupSize===C)return;Za(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:R,groupSize:C,layout:M,separatorToPanels:E.separatorToPanels})}}else NB(e,S,y)}});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=Yl({group:e}),p=Sx(e),m=e.panels.map(({id:N})=>N).join(",");let g=e.mutableState.defaultLayout;g&&(TB(e.panels,g)||(g=void 0));const h=e.mutableState.layouts[m]??g??lk(p),b=Co({layout:h,panelConstraints:p}),v=e.element.ownerDocument;yl.set(v,(yl.get(v)??0)+1);const k=new Map;return PN(e).forEach(N=>{N.separator&&k.set(N.separator,N.panels)}),Za(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",Zw)}),yl.get(v)===1&&(v.addEventListener("dblclick",Qw,!0),v.addEventListener("pointerdown",Ww,!0),v.addEventListener("pointerleave",sk),v.addEventListener("pointermove",ak),v.addEventListener("pointerout",rk),v.addEventListener("pointerup",ok,!0)),function(){t=!1,yl.set(v,Math.max(0,(yl.get(v)??0)-1)),pB(e),e.separators.forEach(N=>{N.element.removeEventListener("keydown",Zw)}),yl.get(v)||(v.removeEventListener("dblclick",Qw,!0),v.removeEventListener("pointerdown",Ww,!0),v.removeEventListener("pointerleave",sk),v.removeEventListener("pointermove",ak),v.removeEventListener("pointerout",rk),v.removeEventListener("pointerup",ok,!0)),c.disconnect()}}function MB(){const[e,t]=x.useState({}),a=x.useCallback(()=>t({}),[]);return[e,a]}function y_(e){const t=x.useId();return`${e??t}`}const zo=typeof window<"u"?x.useLayoutEffect:x.useEffect;function Cc(e){const t=x.useRef(e);return zo(()=>{t.current=e},[e]),x.useCallback((...a)=>t.current?.(...a),[t])}function j_(...e){return Cc(t=>{e.forEach(a=>{if(a)switch(typeof a){case"function":{a(t);break}case"object":{a.current=t;break}}})})}function w_(e){const t=x.useRef({...e});return zo(()=>{for(const a in e)t.current[a]=e[a]},[e]),t.current}const YN=x.createContext(null);function OB(e,t){const a=x.useRef({getLayout:()=>({}),setLayout:SB});x.useImperativeHandle(t,()=>a.current,[]),zo(()=>{Object.assign(a.current,HN({groupId:e}))})}function Nx({children:e,className:t,defaultLayout:a,disableCursor:o,disabled:l,elementRef:c,groupRef:u,id:p,onLayoutChange:m,onLayoutChanged:g,orientation:h="horizontal",resizeTargetMinimumSize:b={coarse:20,fine:10},style:v,...k}){const N=x.useRef({onLayoutChange:{},onLayoutChanged:{}}),j=Cc(H=>{So(N.current.onLayoutChange,H)||(N.current.onLayoutChange=H,m?.(H))}),y=Cc((H,I)=>{So(N.current.onLayoutChanged,H)||(N.current.onLayoutChanged=H,g?.(H,{isUserInteraction:I}))}),S=y_(p),C=x.useRef(null),[E,R]=MB(),A=x.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:b,separators:[]}),T=j_(C,c);OB(S,u);const M=Cc((H,I)=>{const B=No(),V=Gw(H),G=Mr(H);if(G){let q=!1;switch(B.state){case"active":{q=B.hitRegions.some(Y=>Y.group===V);break}}return{flexGrow:G.layout[I]??1,pointerEvents:q?"none":void 0}}if(a?.[I])return{flexGrow:a?.[I]}}),z=w_({defaultLayout:a,disableCursor:o}),L=x.useMemo(()=>({get disableCursor(){return!!z.disableCursor},getPanelStyles:M,id:S,orientation:h,registerPanel:H=>{const I=A.current;return I.panels=Cx(h,[...I.panels,H]),R(),()=>{I.panels=I.panels.filter(B=>B!==H),R()}},registerSeparator:H=>{const I=A.current;return I.separators=Cx(h,[...I.separators,H]),R(),()=>{I.separators=I.separators.filter(B=>B!==H),R()}},updatePanelProps:(H,{disabled:I})=>{const B=A.current.panels.find(q=>q.id===H);B&&(B.panelConstraints.disabled=I);const V=Gw(S),G=Mr(S);V&&G&&Za(V,{...G,derivedPanelConstraints:Sx(V)})},updateSeparatorProps:(H,{disabled:I,disableDoubleClick:B})=>{const V=A.current.separators.find(G=>G.id===H);V&&(V.disabled=I,V.disableDoubleClick=B)}}),[M,S,R,h,z]),D=x.useRef(null);return zo(()=>{const H=C.current;if(H===null)return;const I=A.current;let B;if(z.defaultLayout!==void 0&&Object.keys(z.defaultLayout).length===I.panels.length){B={};for(const X of I.panels){const P=z.defaultLayout[X.id];P!==void 0&&(B[X.id]=P)}}const V={disabled:!!l,element:H,id:S,mutableState:{defaultLayout:B,disableCursor:!!z.disableCursor,expandedPanelSizes:A.current.lastExpandedPanelSizes,layouts:A.current.layouts},orientation:h,panels:I.panels,resizeTargetMinimumSize:I.resizeTargetMinimumSize,separators:I.separators};D.current=V;const G=AB(V),{defaultLayoutDeferred:q,derivedPanelConstraints:Y,layout:K}=Mr(V.id,!0);!q&&Y.length>0&&(j(K),y(K,!1));const $=x_(S,X=>{const{defaultLayoutDeferred:P,derivedPanelConstraints:F,layout:W}=X.next;if(P||F.length===0)return;const ee=V.panels.map(({id:fe})=>fe).join(",");V.mutableState.layouts[ee]=W,F.forEach(fe=>{if(fe.collapsible){const{layout:ae}=X.prev??{};if(ae){const oe=qn(fe.collapsedSize,W[fe.panelId]),me=qn(fe.collapsedSize,ae[fe.panelId]);oe&&!me&&(V.mutableState.expandedPanelSizes[fe.panelId]=ae[fe.panelId])}}});const de=No().state!=="active";j(W),de&&y(W,X.isUserInteraction)});return()=>{D.current=null,G(),$()}},[l,S,y,j,h,E,z]),x.useEffect(()=>{const H=D.current;H&&(H.mutableState.defaultLayout=a,H.mutableState.disableCursor=!!o)}),r.jsx(YN.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",...v,display:"flex",flexDirection:h==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:h==="horizontal"?"pan-y":"pan-x"},children:e})})}Nx.displayName="Group";function k_(){const e=x.useContext(YN);return Bt(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function zB(e,t){const{id:a}=k_(),o=x.useRef({collapse:zh,expand:zh,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:zh});x.useImperativeHandle(t,()=>o.current,[]),zo(()=>{Object.assign(o.current,UN({groupId:a,panelId:e}))})}function uo({children:e,className:t,collapsedSize:a="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:v,style:k,...N}){const j=!!m,y=y_(m),S=w_({disabled:c}),C=x.useRef(null),E=j_(C,u),{getPanelStyles:R,id:A,orientation:T,registerPanel:M,updatePanelProps:z}=k_(),L=b!==null,D=Cc((V,G,q)=>{b?.(V,m,q)});zo(()=>{const V=C.current;if(V!==null){const G={element:V,id:y,idIsStable:j,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:L?D:void 0,panelConstraints:{groupResizeBehavior:p,collapsedSize:a,collapsible:o,defaultSize:l,disabled:S.disabled,maxSize:g,minSize:h}};return M(G)}},[p,a,o,l,L,y,j,g,h,D,M,S]),x.useEffect(()=>{z(y,{disabled:c})},[c,y,z]),zB(y,v);const H=()=>{const V=R(A,y);if(V)return JSON.stringify(V)},I=x.useSyncExternalStore(V=>x_(A,V),H,H);let B;return I?B=JSON.parse(I):l!==void 0?B={flexGrow:void 0,flexShrink:void 0,flexBasis:l}:B={flexGrow:1},r.jsx("div",{...N,"data-disabled":c||void 0,"data-panel":!0,"data-testid":y,id:y,ref:E,style:{...DB,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...B},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 DB={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function PB({layout:e,panelConstraints:t,panelId:a,panelIndex:o}){let l,c;const u=e[a],p=t.find(m=>m.panelId===a);if(p){const m=p.maxSize,g=p.collapsible?p.collapsedSize:p.minSize,h=[o,o+1];c=Co({layout:Ic({delta:g-u,initialLayout:e,panelConstraints:t,pivotIndices:h,prevLayout:e}),panelConstraints:t})[a],l=Co({layout:Ic({delta:m-u,initialLayout:e,panelConstraints:t,pivotIndices:h,prevLayout:e}),panelConstraints:t})[a]}return{valueControls:a,valueMax:l,valueMin:c,valueNow:u}}function S_({children:e,className:t,disabled:a,disableDoubleClick:o,elementRef:l,id:c,style:u,...p}){const m=y_(c),g=w_({disabled:a,disableDoubleClick:o}),[h,b]=x.useState({}),[v,k]=x.useState("inactive"),[N,j]=x.useState(!1),y=x.useRef(null),S=j_(y,l),{disableCursor:C,id:E,orientation:R,registerSeparator:A,updateSeparatorProps:T}=k_(),M=R==="horizontal"?"vertical":"horizontal";zo(()=>{const D=y.current;if(D!==null){const H={disabled:g.disabled,disableDoubleClick:g.disableDoubleClick,element:D,id:m},I=A(H),B=wB(G=>{k(G.next.state!=="inactive"&&G.next.hitRegions.some(q=>q.separator===H)?G.next.state:"inactive")}),V=x_(E,G=>{const{derivedPanelConstraints:q,layout:Y,separatorToPanels:K}=G.next,$=K.get(H);if($){const X=$[0],P=$.indexOf(X);b(PB({layout:Y,panelConstraints:q,panelId:X.id,panelIndex:P}))}});return()=>{B(),V(),I()}}},[E,m,A,g]),x.useEffect(()=>{T(m,{disabled:a,disableDoubleClick:o})},[a,o,m,T]);let z;a&&!C&&(z="not-allowed");let L;if(a)L="disabled";else switch(v){case"active":{L="active";break}default:N?L="focus":L=v}return r.jsx("div",{...p,"aria-controls":h.valueControls,"aria-disabled":a||void 0,"aria-orientation":M,"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:()=>j(!1),onFocus:()=>j(!0),ref:S,role:"separator",style:{flexBasis:"auto",cursor:z,...u,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:a?void 0:0})}S_.displayName="Separator";function LB({projects:e,value:t,onChange:a,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:jM,description:c.path}});return r.jsx("div",{className:"w-full","data-testid":"code-project-select",children:r.jsx(bt,{value:t,onChange:a,options:l,placeholder:f("modules_ui.code_pick_project_ph"),disabled:o})})}function IB({sessions:e,activeId:t,busy:a,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(Ye,{content:f("code_module.new_session"),children:r.jsxs("button",{type:"button",onClick:l,disabled:a,"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:Me("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(Ux,{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(Ye,{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(Ye,{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(cs,{className:"size-3"})})})]})]},p.id))})})]})}function BB({mode:e,onChange:t,disabled:a}){const o=(l,c,u,p)=>r.jsx(Ye,{content:u,children:r.jsxs("button",{type:"button",disabled:a,"data-testid":`code-mode-${l}`,"aria-pressed":e===l,onClick:()=>t(l),className:Me("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"),NM),o("plan",f("code_module.mode_plan"),f("code_module.mode_plan_hint"),iM)]})}function UB({value:e,onValueChange:t,onSubmit:a,onStop:o,busy:l,disabled:c,mode:u,onModeChange:p,model:m,onModelChange:g}){return r.jsx(u_,{value:e,onValueChange:t,onSubmit:a,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(BB,{mode:u,onChange:p,disabled:l}),r.jsx(d_,{value:m,onChange:g,disabled:l})]})})}function Dh(e,t){let a=0;for(const o of e.parts||[])o.kind==="text"&&t.text&&(a+=o.text.length),o.kind==="tool"&&t.tool&&(o.args&&(a+=JSON.stringify(o.args).length),o.result!==void 0&&(a+=JSON.stringify(o.result).length));return Math.ceil(a/4)}function HB(e){let t=null,a=0,o=0;for(const u of e)u.role==="user"?a++: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:a,assistantMsgs:o}}function VB(e){let t=0,a=0,o=0;for(const u of e)u.role==="user"?t+=Dh(u,{text:!0}):a+=Dh(u,{text:!0}),o+=Dh(u,{tool:!0});const l=t+a+o||1,c=(u,p)=>({key:u,tokens:p,percent:Math.round(p/l*100)});return[c("user",t),c("assistant",a),c("tool",o)].filter(u=>u.tokens>0)}const ik={user:"bg-emerald-500",assistant:"bg-sky-500",tool:"bg-amber-500"};function Ba({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 ck(e){if(!e)return"";const t=new Date(e),a=o=>String(o).padStart(2,"0");return`${a(t.getDate())} ${t.toLocaleString("es",{month:"short"})} ${t.getFullYear()}, ${a(t.getHours())}:${a(t.getMinutes())}`}function qB({turns:e,session:t}){const a=x.useMemo(()=>HB(e),[e]),o=x.useMemo(()=>VB(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(Ba,{label:f("code_module.ctx_model"),value:a.model||f("modules_ui.code_ctx_auto")}),t?.mode&&r.jsx(Ba,{label:f("modules_ui.code_ctx_mode"),value:t.mode}),t?.agentSlug&&r.jsx(Ba,{label:f("modules_ui.code_ctx_agent"),value:t.agentSlug}),r.jsx(Ba,{label:f("code_module.ctx_messages"),value:f("modules_ui.code_ctx_msgs_value",{user:a.userMsgs,assistant:a.assistantMsgs})}),r.jsx(Ba,{label:f("code_module.ctx_input"),value:a.input.toLocaleString()}),r.jsx(Ba,{label:f("code_module.ctx_output"),value:a.output.toLocaleString()}),r.jsx(Ba,{label:f("modules_ui.code_ctx_tokens_total"),value:(a.input+a.output).toLocaleString()}),t?.createdAt&&r.jsx(Ba,{label:f("modules_ui.code_ctx_created"),value:ck(t.createdAt)}),t?.updatedAt&&r.jsx(Ba,{label:f("modules_ui.code_ctx_activity"),value:ck(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(Ye,{content:`${l.key}: ${l.tokens} (${l.percent}%)`,children:r.jsx("div",{className:ik[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 ${ik[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 $B(e){const t=[];for(const a of(e||"").split(`
651
651
  `))a.startsWith("diff --git")||a.startsWith("index ")||a.startsWith("--- ")||a.startsWith("+++ ")||a.startsWith("new file")||a.startsWith("deleted file")||a.startsWith("similarity index")||a.startsWith("rename ")||(a.startsWith("@@")?t.push({kind:"hunk",text:a}):a.startsWith("+")?t.push({kind:"add",text:a.slice(1)}):a.startsWith("-")?t.push({kind:"del",text:a.slice(1)}):t.push({kind:"ctx",text:a.replace(/^ /,"")}));for(;t.length&&t[t.length-1].kind==="ctx"&&t[t.length-1].text==="";)t.pop();return t}function FB({patch:e}){const t=x.useMemo(()=>$B(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((a,o)=>r.jsxs("div",{className:Me("px-2 whitespace-pre",a.kind==="add"&&"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",a.kind==="del"&&"bg-rose-500/10 text-rose-600 dark:text-rose-400",a.kind==="hunk"&&"bg-muted/60 text-muted-foreground",a.kind==="ctx"&&"text-foreground/70"),children:[r.jsx("span",{className:"select-none opacity-50",children:a.kind==="add"?"+":a.kind==="del"?"-":" "}),a.text]},o))})}):null}const GB={added:xM,modified:Yd,deleted:vM},YB={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 KB({file:e}){const[t,a]=x.useState(!1),o=GB[e.status];return r.jsxs("li",{className:"rounded-md border border-border",children:[r.jsxs("button",{type:"button",onClick:()=>a(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(Zl,{className:Me("size-3 shrink-0 transition-transform",t&&"rotate-90")}),r.jsx(o,{className:Me("size-3.5 shrink-0",YB[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(FB,{patch:e.patch})})]})}function XB({changes:e,loading:t,onRefresh:a}){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(Ye,{content:f("code_module.reload"),children:r.jsx("button",{type:"button",onClick:a,className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground",children:t?r.jsx(_s,{size:12}):r.jsx(ua,{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(KB,{file:l},l.path))})})]})}function QB({pid:e,entry:t,onDeleted:a,onRenamed:o,onRunInTerminal:l,onEditArtifact:c}){const[u,p]=x.useState(!1),[m,g]=x.useState(null),h=rt(),[b,v]=x.useState(!1),[k,N]=x.useState(t.name),j=x.useRef(null),[y,S]=x.useState(!1),[C,E]=x.useState(!1),[R,A]=x.useState(!1),T=y?["artifact",e,t.name]:null,M=et(T,()=>Ml.read(e,t.name),{revalidateOnFocus:!1}),z=!M.data?.content||M.data.content.startsWith("#!"),L=async B=>{try{await navigator.clipboard.writeText(B),h.info(f("modules_ui.code_copied"))}catch{}},D=async()=>{A(!0);try{await Ml.remove(e,t.name),E(!1),a()}catch(B){h.error(B.message)}finally{A(!1)}},H=()=>{N(t.name),v(!0),requestAnimationFrame(()=>j.current?.select())},I=async()=>{const B=k.trim();if(v(!1),!(!B||B===t.name))try{await Ml.rename(e,t.name,B),o()}catch(V){h.error(V.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(hM,{className:"size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"}),b?r.jsx("input",{ref:j,value:k,onChange:B=>N(B.target.value),onBlur:()=>void I(),onKeyDown:B=>{B.key==="Enter"&&I(),B.key==="Escape"&&v(!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(Ye,{content:f("code_module.artifacts_rename"),children:r.jsx("button",{type:"button",onClick:H,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(Ye,{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(Ec,{className:"size-3"})})})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-1",children:[r.jsxs(dx,{open:y,onOpenChange:S,children:[r.jsx(Ye,{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(Nf,{className:"size-3"}),f("modules_ui.code_artifact_view_short")]})}),r.jsxs(fx,{className:"sm:max-w-lg",children:[r.jsx(px,{children:r.jsx(mx,{className:"font-mono text-sm",children:t.name})}),M.isLoading?r.jsx("div",{className:"flex justify-center py-6",children:r.jsx(_s,{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:M.data?.content??""}),r.jsx(Hj,{showCloseButton:!0})]})]}),r.jsx(Ye,{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($M,{className:"size-3"}),f("modules_ui.code_artifact_edit_short")]})}),z&&r.jsx(Ye,{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(Vx,{className:"size-3"}),f("code_module.artifacts_run")]})}),r.jsxs(dx,{open:C,onOpenChange:E,children:[r.jsx(Ye,{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(cs,{className:"size-3"})})}),r.jsxs(fx,{className:"sm:max-w-sm",children:[r.jsx(px,{children:r.jsxs(mx,{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(Hj,{children:[r.jsx(NP,{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:Me("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(_s,{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:Me("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 ZB({pid:e,onRunInTerminal:t,onEditArtifact:a}){const o=et(e?["artifacts",e]:null,()=>Ml.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(Ye,{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(_s,{size:12}):r.jsx(ua,{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(QB,{pid:e,entry:c,onDeleted:()=>void o.mutate(),onRenamed:()=>void o.mutate(),onRunInTerminal:t,onEditArtifact:a},c.name))})})]})}const WB=[{value:"context",icon:Rf,label:"tab_context"},{value:"changes",icon:CM,label:"tab_changes"},{value:"artifacts",icon:LM,label:"tab_artifacts"}];function JB({pid:e,turns:t,changes:a,changesLoading:o,onRefreshChanges:l,session:c,onRunInTerminal:u,onEditArtifact:p}){const[m,g]=x.useState("context"),h=a?.files.length||0;return r.jsxs(up,{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(dp,{variant:"line",className:"w-full",children:WB.map(({value:b,icon:v,label:k})=>{const N=m===b,j=f(`code_module.${k}`);return r.jsx(Ye,{content:j,children:r.jsxs(aa,{value:b,className:N?"flex-1 min-w-0":"w-8 shrink-0",children:[r.jsx(v,{className:"size-3.5 shrink-0"}),N&&r.jsx("span",{className:"truncate text-xs",children:j}),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(Ds,{value:"context",className:"min-h-0 flex-1 overflow-y-auto",children:r.jsx(qB,{turns:t,session:c})}),r.jsx(Ds,{value:"changes",className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(XB,{changes:a,loading:o,onRefresh:l})}),r.jsx(Ds,{value:"artifacts",className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(ZB,{pid:e,onRunInTerminal:u,onEditArtifact:p})})]})}function e9(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 a=o=>(o.forEach(l=>{l.children&&(l.children=a(l.children))}),o.sort((l,c)=>l.type!==c.type?l.type==="dir"?-1:1:l.name.localeCompare(c.name)));return a(t)}function KN({node:e,depth:t,onOpenFile:a,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):a(e.path),style:{paddingLeft:`${t*12+6}px`},className:Me("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(Zl,{className:Me("size-3 shrink-0 transition-transform",u&&"rotate-90")}),u?r.jsx(Ef,{className:"size-3.5 shrink-0 text-amber-400"}):r.jsx(wM,{className:"size-3.5 shrink-0 text-amber-400"})]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"size-3 shrink-0"}),r.jsx(yM,{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(KN,{node:p,depth:t+1,onOpenFile:a,openDirs:o,toggleDir:l},p.path))})]})}function t9({pid:e,projectPath:t,className:a,onOpenFile:o}){const[l,c]=x.useState([]),[u,p]=x.useState(!1),[m,g]=x.useState(!1),[h,b]=x.useState(()=>new Set),v=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),v()},[v]);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)},[]),j=e9(l),y=h.size>0;return r.jsxs("div",{className:Me("flex h-full flex-col",a),"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(Ye,{content:f("code_module.tree_collapse_all"),children:r.jsx("button",{type:"button",onClick:N,disabled:!y,className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-40 disabled:hover:bg-transparent",children:r.jsx(rM,{className:"size-3"})})}),r.jsx(Ye,{content:f("code_module.reload"),children:r.jsx("button",{type:"button",onClick:()=>void v(),className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground",children:u?r.jsx(_s,{size:12}):r.jsx(ua,{className:"size-3"})})})]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto py-1",children:m?j.length===0?r.jsx("div",{className:"p-3",children:r.jsx(xt,{children:"Sin archivos"})}):r.jsx("ul",{children:j.map(S=>r.jsx(KN,{node:S,depth:0,onOpenFile:o??(()=>{}),openDirs:h,toggleDir:k},S.path))}):r.jsx("div",{className:"flex justify-center pt-6",children:r.jsx(_s,{size:14})})})]})}function n9({path:e,content:t,loading:a,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(Ye,{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(qx,{className:"size-3"}),"Descartar"]})}),r.jsx(Ye,{content:f("code_module.save_shortcut_hint"),children:r.jsxs("button",{type:"button",onClick:()=>void h(),disabled:!g||p,className:Me("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(_s,{size:10}):r.jsx(Af,{className:"size-3"}),"Guardar"]})})]})]}),a?r.jsx("div",{className:"flex flex-1 items-center justify-center",children:r.jsx(_s,{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,v)=>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:v+1}),r.jsx("td",{className:"px-4 py-0 align-top text-foreground/90 whitespace-pre",children:b||" "})]},v))})})})]})}function s9({pid:e,className:t,initCmd:a,onClose:o}){const[l,c]=x.useState([]),[u,p]=x.useState(""),[m,g]=x.useState(!1),[h,b]=x.useState([]),[v,k]=x.useState(-1),N=x.useRef(null),j=x.useRef(null);x.useEffect(()=>{N.current?.scrollIntoView({behavior:"smooth"})},[l]),x.useEffect(()=>{a&&(p(a),setTimeout(()=>j.current?.focus(),50))},[a]);const y=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")y(u),p("");else if(C.key==="ArrowUp"){C.preventDefault();const E=Math.min(v+1,h.length-1);k(E),p(h[E]??"")}else if(C.key==="ArrowDown"){C.preventDefault();const E=Math.max(v-1,-1);k(E),p(E===-1?"":h[E]??"")}};return r.jsxs("div",{className:Me("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(Ga,{className:"size-3 text-muted-foreground"}),r.jsx("span",{className:"flex-1 text-[11px] text-muted-foreground",children:"Terminal"}),r.jsx(Ye,{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(mM,{className:"size-3"})})}),r.jsx(Ye,{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(Gs,{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:()=>j.current?.focus(),children:[l.map((C,E)=>r.jsx("div",{className:Me("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:j,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 cc="super-agent";function Ph(){return r.jsx(S_,{className:"relative z-10 w-px shrink-0 cursor-col-resize bg-border transition-colors hover:bg-primary/50 active:bg-primary/70"})}function a9(){return r.jsx(S_,{className:"relative z-10 h-px shrink-0 cursor-row-resize bg-border transition-colors hover:bg-primary/50 active:bg-primary/70"})}function r9(){const e=rt(),t=et("/projects",()=>rs.list()),a=x.useMemo(()=>t.data||[],[t.data]),[o,l]=x.useState(""),[c,u]=x.useState(null),[p,m]=x.useState(cc),[g,h]=x.useState([]),[b,v]=x.useState(""),[k,N]=x.useState(!1),[j,y]=x.useState(!0),[S,C]=x.useState(!0),[E,R]=x.useState(!1),[A,T]=x.useState(""),[M,z]=x.useState(!1),L=x.useRef(null),[D,H]=x.useState([]),[I,B]=x.useState("chat"),V=x.useCallback(_e=>{R(!0),T(_e)},[]);x.useEffect(()=>{!o&&a.length&&l(String(a[0].id))},[o,a]);const G=et(o?["code-sessions",o]:null,()=>Ia.sessions.list(o)),q=et(o?["agents",o]:null,()=>an.list(o)),Y=et(o&&c?["code-session",o,c]:null,()=>Ia.sessions.get(o,c)),K=et(o&&c?["code-changes",o,c]:null,()=>Ia.changes(o,c));x.useEffect(()=>{const _e=G.data||[];!c&&_e.length&&u(_e[0].id),c&&_e.length&&!_e.some(Oe=>Oe.id===c)&&u(_e[0]?.id??null)},[G.data,c]),x.useEffect(()=>{Y.data&&m(Y.data.agentSlug||cc)},[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,X=$?.mode==="plan"?"plan":"build",P=$?.model||"",F=_e=>{_e===o||k||(l(_e),u(null),h([]))},W=_e=>{k||_e===c||(u(_e),h([]))},ee=async()=>{if(!(!o||k))try{const _e=await Ia.sessions.create(o,{title:f("code_module.untitled"),agentSlug:p!==cc?p:null});await G.mutate(),u(_e.id),h([])}catch(_e){e.error(_e.message)}},de=async(_e,Oe)=>{const He=window.prompt(f("code_module.rename"),Oe);if(!(!He||He===Oe))try{await Ia.sessions.update(o,_e,{title:He}),await G.mutate(),_e===c&&await Y.mutate()}catch(Xe){e.error(Xe.message)}},fe=async _e=>{if(!k&&window.confirm(f("code_module.delete_confirm")))try{await Ia.sessions.remove(o,_e),_e===c&&(u(null),h([])),await G.mutate()}catch(Oe){e.error(Oe.message)}},ae=async _e=>{if(m(_e),!!c)try{await Ia.sessions.update(o,c,{agentSlug:_e!==cc?_e:null}),await Promise.all([Y.mutate(),G.mutate()])}catch(Oe){e.error(Oe.message)}},oe=x.useCallback(async _e=>{if(c)try{await Ia.sessions.update(o,c,_e),await Promise.all([Y.mutate(),G.mutate()])}catch(Oe){e.error(Oe.message)}},[o,c,Y,G,e]),me=()=>{L.current?.abort(),N(!1)},Te=_e=>h(Oe=>{const He=[...Oe],Xe=He[He.length-1];return Xe&&Xe.role==="assistant"&&(He[He.length-1]=_e(Xe)),He}),le=async _e=>{const Oe=(_e??b).trim();if(!Oe||k||!o||!c)return;const He=new Date().toISOString();h(nn=>[...nn,{role:"user",parts:[{kind:"text",text:Oe}],ts:He},{role:"assistant",parts:[],ts:He,pending:!0}]),v(""),N(!0);const Xe=new AbortController;L.current=Xe;const ot=nn=>{if(nn.type==="error"){e.error(nn.error||f("modules_ui.code_stream_error"));return}Te(dn=>f_(dn,nn))};try{await Ia.stream(o,c,{prompt:Oe},ot,Xe.signal),Te(nn=>({...nn,pending:!1}))}catch(nn){Xe.signal.aborted?Te(dn=>({...dn,pending:!1,parts:[...dn.parts,{kind:"text",text:f("code_module.stopped")}]})):(e.error(nn.message),h(dn=>dn.filter((pt,Et)=>Et!==dn.length-1)))}finally{L.current===Xe&&(L.current=null),N(!1),Y.mutate(),G.mutate(),K.mutate()}},pe=async _e=>{try{await navigator.clipboard.writeText(_e),e.info(f("modules_ui.code_copied"))}catch{}},Se=x.useCallback(_e=>{B(_e),H(Oe=>Oe.some(He=>He.path===_e)?Oe:[...Oe,{path:_e,content:"",loading:!0}]),ge.post("/run",{cmd:`cat "${_e}"`,project:o}).then(Oe=>{const He=Oe.stdout||Oe.stderr||f("modules_ui.code_file_empty");H(Xe=>Xe.map(ot=>ot.path===_e?{...ot,content:He,loading:!1}:ot))}).catch(Oe=>{H(He=>He.map(Xe=>Xe.path===_e?{...Xe,content:f("modules_ui.code_file_error",{msg:Oe.message}),loading:!1}:Xe))})},[o]),je=x.useCallback(_e=>{H(Oe=>Oe.filter(He=>He.path!==_e)),B(Oe=>Oe===_e?"chat":Oe)},[]),Be=x.useCallback(_e=>{const Oe=`artifacts/${_e}`;B(Oe),H(He=>He.some(Xe=>Xe.path===Oe)?He:[...He,{path:Oe,content:"",loading:!0,artifactName:_e}]),Ml.read(o,_e).then(He=>{H(Xe=>Xe.map(ot=>ot.path===Oe?{...ot,content:He.content,loading:!1}:ot))}).catch(He=>{H(Xe=>Xe.map(ot=>ot.path===Oe?{...ot,content:f("modules_ui.code_file_error",{msg:He.message}),loading:!1}:ot))})},[o]),Ve=x.useCallback(async(_e,Oe)=>{const He=D.find(Xe=>Xe.path===_e);if(He?.artifactName)try{await Ml.write(o,He.artifactName,Oe),H(Xe=>Xe.map(ot=>ot.path===_e?{...ot,content:Oe}:ot)),e.info(f("modules_ui.code_saved"))}catch(Xe){e.error(Xe.message)}},[D,o,e]),we=!t.isLoading&&a.length>0,Ne=x.useMemo(()=>{const _e=[{value:cc,label:f("modules_ui.code_super_agent"),icon:un,description:f("modules_ui.code_super_agent_desc")}],Oe=(q.data||[]).map(He=>({value:He.slug,label:He.slug,icon:un,description:He.description||He.role||void 0}));return[..._e,...Oe]},[q.data]),ve=x.useMemo(()=>g,[g]),Ce=x.useMemo(()=>G.data?.find(_e=>_e.id===c)?.title||"",[G.data,c]),Pe=x.useMemo(()=>a.find(_e=>String(_e.id)===o),[a,o]);qP(Ce);const[Le,Ie]=x.useState(null),se=k?null:vN(g),be=se&&se.turnKey!==Le,$e=_e=>{le(_e)},Ee=x.useCallback(()=>y(_e=>!_e),[]),ze=x.useCallback(()=>z(_e=>!_e),[]),Ze=x.useCallback(()=>R(_e=>!_e),[]),at=x.useCallback(()=>C(_e=>!_e),[]),yt=x.useMemo(()=>c?r.jsx("div",{className:"flex items-center gap-0.5",children:[{Icon:Yk,open:j,toggle:Ee,title:f("modules_ui.code_panel_sessions")},{Icon:$k,open:M,toggle:ze,title:f("modules_ui.code_panel_tree")},{Icon:Ga,open:E,toggle:Ze,title:f("modules_ui.code_panel_terminal")},{Icon:BM,open:S,toggle:at,title:f("modules_ui.code_panel_context")}].map(({Icon:_e,open:Oe,toggle:He,title:Xe})=>r.jsx(Ye,{content:Xe,children:r.jsx("button",{type:"button",onClick:He,"data-active":Oe,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(_e,{className:"size-3.5"})})},Xe))}):null,[c,j,M,E,S,Ee,ze,Ze,at]);return FP(yt),r.jsx("div",{className:"flex h-full min-h-0 flex-col","data-testid":"screen-code",children:t.isLoading?r.jsx(lt,{}):we?r.jsxs(Nx,{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(Nx,{orientation:"horizontal",id:"code-layout",className:"h-full",children:[j&&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(LB,{projects:a,value:o,onChange:F,disabled:k})}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(IB,{sessions:G.data||[],activeId:c,busy:k,onSelect:W,onCreate:ee,onRename:de,onDelete:fe})}),r.jsx("div",{className:"shrink-0 border-t border-border p-2",children:r.jsx(bt,{value:p,onChange:ae,options:Ne,disabled:k,showIcon:!0})})]})}),r.jsx(Ph,{})]}),M&&r.jsxs(r.Fragment,{children:[r.jsx(uo,{id:"tree",defaultSize:"13%",minSize:"8%",children:r.jsx("div",{className:"h-full",children:r.jsx(t9,{pid:o,projectPath:Pe?.path,onOpenFile:Se})})}),r.jsx(Ph,{})]}),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:()=>B("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(Ux,{className:"size-3 shrink-0"}),f("modules_ui.code_chat_tab")]}),D.map(_e=>{const Oe=_e.path.split("/").pop()??_e.path,He=I===_e.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(Ye,{content:_e.path,children:r.jsx("button",{type:"button",onClick:()=>B(_e.path),className:"min-w-0 max-w-[140px] truncate font-mono",children:Oe})}),r.jsx(Ye,{content:f("code_module.close"),children:r.jsx("button",{type:"button",onClick:()=>je(_e.path),className:"shrink-0 rounded p-0.5 opacity-60 hover:bg-accent hover:opacity-100",children:r.jsx(Gs,{className:"size-2.5"})})})]},_e.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(p_,{msgs:g,onCopy:pe}):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&&se&&r.jsx(_N,{turnKey:se.turnKey,questions:se.questions,onSubmit:$e,onDismiss:()=>Ie(se.turnKey),disabled:k})]}):r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:(()=>{const _e=D.find(Oe=>Oe.path===I);return _e?r.jsx(n9,{path:_e.path,content:_e.content,loading:_e.loading,onSave:_e.artifactName?Oe=>Ve(_e.path,Oe):void 0}):null})()}),r.jsx("div",{className:"shrink-0 border-t border-border p-2","data-testid":"code-input",children:r.jsx(UB,{value:b,onValueChange:v,onSubmit:()=>void le(),onStop:me,busy:k,disabled:!c,mode:X,onModeChange:_e=>void oe({mode:_e}),model:P,onModelChange:_e=>void oe({model:_e||null})})})]})}),S&&r.jsxs(r.Fragment,{children:[r.jsx(Ph,{}),r.jsx(uo,{id:"right",defaultSize:"22%",minSize:"15%",children:r.jsx("aside",{className:"flex h-full flex-col",children:r.jsx(JB,{pid:o,turns:ve,changes:K.data,changesLoading:K.isLoading,onRefreshChanges:()=>void K.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:V,onEditArtifact:Be})})})]})]})}),E&&o&&r.jsxs(r.Fragment,{children:[r.jsx(a9,{}),r.jsx(uo,{id:"terminal",defaultSize:"45%",minSize:"10%",maxSize:"80%",children:r.jsx(s9,{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 o9({open:e,onClose:t}){const{mutate:a}=mC(),o=Qn(),l=rt(),[c,u]=x.useState(""),[p,m]=x.useState(!1),[g,h]=x.useState(""),[b,v]=x.useState([]),[k,N]=x.useState(null),[j,y]=x.useState(""),[S,C]=x.useState(!1),[E,R]=x.useState(!1),A=async(z,L=!1)=>{C(!0),y("");try{const D=await zj.dirs(z||"~");h(D.path),u(D.path),N(D.parent),v(D.entries)}catch(D){const H=D.message;y(H),L||l.error(H)}finally{C(!1)}};x.useEffect(()=>{e||(u(""),m(!1),h(""),v([]),N(null),y(""))},[e]);const T=async()=>{C(!0);try{const z=await zj.pickDir(f("add_project.picker_prompt"));if("cancelled"in z)return;u(z.path);return}catch{m(!0),await A(c||"~")}finally{C(!1)}},M=async()=>{const z=c.trim();if(!z){l.error(f("add_project.path_required"));return}R(!0);try{const L=await rs.register(z);l.success(f("add_project.registered",{id:L.id})),await a("/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(ie,{variant:"ghost",onClick:t,disabled:E,children:f("common.cancel")}),r.jsx(ie,{variant:"primary",onClick:M,loading:E,children:f("add_project.register")})]}),children:r.jsxs("div",{className:"space-y-3",children:[r.jsx(ue,{label:f("add_project.path_label"),hint:f("add_project.path_hint"),children:r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Re,{autoFocus:!0,placeholder:f("add_project.path_placeholder"),value:c,onChange:z=>u(z.target.value),onKeyDown:z=>{z.key==="Enter"&&M()}}),r.jsxs(ie,{onClick:T,disabled:S,children:[r.jsx(_c,{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(ie,{size:"sm",variant:"ghost",onClick:()=>A("~"),disabled:S,children:r.jsx(RM,{size:13})}),r.jsx(ie,{size:"sm",variant:"ghost",onClick:()=>k&&A(k),disabled:!k||S,children:".."}),r.jsx(ie,{size:"sm",variant:"ghost",onClick:()=>m(!1),disabled:S,children:r.jsx(Gs,{size:13})})]})]}),r.jsxs("div",{className:"max-h-64 overflow-y-auto p-2",children:[S&&r.jsx(lt,{}),!S&&j&&r.jsx(xt,{children:f("add_project.browser_unavailable")}),!S&&!j&&b.length===0&&r.jsx(xt,{children:f("add_project.no_folders")}),!S&&!j&&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(Ef,{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 l9({onPaired:e}){const[t,a]=x.useState(""),[o,l]=x.useState(i9()),[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 Fl.confirm({pairing_id:h,label:o.trim()||void 0});fo(b.token);try{localStorage.setItem(Rn.token,b.token)}catch{}e()}catch(b){m(c9(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(Uh,{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(ue,{label:f("pairing.code_label"),children:r.jsx(Re,{value:t,onChange:h=>a(h.target.value),placeholder:f("pairing.code_ph"),spellCheck:!1,autoComplete:"off"})}),r.jsx(ue,{label:f("pairing.label_label"),hint:f("pairing.revoke_hint"),children:r.jsx(Re,{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(ie,{type:"submit",variant:"primary",size:"md",loading:c,className:"w-full justify-center",children:f(c?"pairing.linking":"pairing.submit")})]})]})})}function i9(){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 c9(e){if(e instanceof Kc){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 u9({...e}){return r.jsx(EC,{"data-slot":"sheet",...e})}function d9({...e}){return r.jsx(NC,{"data-slot":"sheet-portal",...e})}function f9({className:e,...t}){return r.jsx(wC,{"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 p9({className:e,children:t,side:a="right",showCloseButton:o=!0,...l}){return r.jsxs(d9,{children:[r.jsx(f9,{}),r.jsxs(CC,{"data-slot":"sheet-content","data-side":a,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(ip,{"data-slot":"sheet-close",render:r.jsx(Qa,{variant:"ghost",className:"absolute top-3 right-3",size:"icon-sm"}),children:[r.jsx(Gs,{}),r.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function m9({className:e,...t}){return r.jsx("div",{"data-slot":"sheet-header",className:St("flex flex-col gap-0.5 p-4",e),...t})}function g9({className:e,...t}){return r.jsx(RC,{"data-slot":"sheet-title",className:St("font-heading text-base font-medium text-foreground",e),...t})}function h9({className:e,...t}){return r.jsx(kC,{"data-slot":"sheet-description",className:St("text-sm text-muted-foreground",e),...t})}function x9({value:e,projectPath:t,onPick:a}){const o=b9(e),l=o?_9(e):"",{data:c}=et(o?["/skills",t||""]:null,()=>fc.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:()=>a(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 b9(e){return!!e.match(/^\s*\/([A-Za-z0-9_-]*)$/)}function _9(e){const t=e.match(/^\s*\/([A-Za-z0-9_-]*)$/);return t?t[1]:""}function v9(){try{const e=localStorage.getItem(Rn.robyChat);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(a=>a&&Array.isArray(a.parts)&&!a.pending):[]}catch{return[]}}function y9({open:e,onOpenChange:t}){const a=rp(),o=rt(),[l,c]=x.useState(v9),[u,p]=x.useState(""),[m,g]=x.useState(!1),[h,b]=x.useState(""),v=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(()=>()=>v.current?.abort(),[]),x.useEffect(()=>{const C=E=>{const R=E.detail?.prompt;typeof R=="string"&&(t(!0),p(R))};return window.addEventListener("apx:roby-prompt",C),()=>window.removeEventListener("apx:roby-prompt",C)},[t]);const N=()=>{v.current?.abort(),g(!1)},j=C=>c(E=>{const R=[...E],A=R[R.length-1];return A?.role==="assistant"&&(R[R.length-1]=C(A)),R}),y=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:_x(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;v.current=A;let T=!1;const M=z=>{if(z?.type==="error"){T=!0,o.error(z.error||"error"),c(L=>{const D=[...L],H=D[D.length-1];return H?.role==="assistant"&&H.pending&&D.pop(),D});return}j(L=>f_(L,z))};try{await hC.stream(0,{prompt:C,previousMessages:R,model:h||void 0,channel:"web_sidebar"},M,A.signal),j(z=>({...z,pending:!1}))}catch(z){A.signal.aborted?j(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],H=D[D.length-1];return H?.role==="assistant"&&H.pending&&D.pop(),D}))}finally{v.current===A&&(v.current=null),g(!1)}},S=async C=>{try{await navigator.clipboard.writeText(C),o.info(f("project.chat.copied"))}catch{}};return r.jsx(u9,{open:e,onOpenChange:t,children:r.jsxs(p9,{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(m9,{className:"pr-12",children:[r.jsxs(g9,{className:"flex items-center gap-2",children:[r.jsx(un,{size:18})," ",f("superagent.title",{persona:a}),r.jsx("span",{className:"text-xs font-normal text-muted-fg",children:f("superagent.badge")})]}),r.jsx(h9,{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:a})}):r.jsx(p_,{msgs:l,onCopy:S})}),r.jsx(bN,{msgs:l}),r.jsxs("div",{className:"border-t border-border p-3",children:[r.jsx("div",{className:"mb-1.5",children:r.jsx(x9,{value:u,onPick:C=>p(`/${C} `)})}),r.jsx(u_,{value:u,onValueChange:p,onSubmit:()=>void y(),onStop:N,busy:m,placeholder:f("superagent.placeholder"),footer:r.jsx(d_,{value:h,onChange:b,disabled:m})}),r.jsx("div",{className:"mt-1.5 flex justify-end",children:r.jsxs(Qa,{size:"xs",variant:"ghost",onClick:k,disabled:m||l.length===0,children:[r.jsx(rn,{className:"size-3"})," ",f("superagent.new_chat")]})})]})]})})}function j9(){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 w9(){const[e,t]=x.useState({status:"loading"}),[a,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 Fl.confirm({pairing_id:m,label:j9(),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(!$b()){c||t({status:"unpaired"});return}try{await ge.get("/projects"),c||t({status:"ok"})}catch(h){if(h instanceof Kc&&(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}},[a]),{...e,reload:l}}function k9(){const e=w9();return e.status==="loading"?r.jsx(uk,{text:f("daemon.connecting")}):e.status==="error"?r.jsx(uk,{mood:"sad",text:f("daemon.unreachable"),sub:`${f("daemon.unreachable_hint")}
654
654
 
655
655
  ${e.reason}`}):e.status==="unpaired"?r.jsx(l9,{onPaired:e.reload}):r.jsx(zP,{children:r.jsx(K4,{delay:0,children:r.jsx(S9,{})})})}function S9(){const e=Qn(),t=Xn(),[a,o]=Cf(),{theme:l,toggle:c}=Gx(),u=a.get("action")==="add-project",[p,m]=x.useState(!1),g=()=>{const b=new URLSearchParams(a);b.delete("action"),o(b,{replace:!0})},h=()=>{const b=new URLSearchParams(a);b.set("action","add-project"),o(b)};return r.jsx(BP,{children:r.jsxs("div",{className:"flex h-screen w-screen overflow-hidden bg-background text-foreground","data-testid":"app-shell",children:[r.jsx(GD,{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(C9,{onToggleTheme:c,isDark:l==="dark",pathname:t.pathname}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsxs(Ak,{children:[r.jsx(Xt,{path:"/",element:r.jsx(IP,{})}),r.jsx(Xt,{path:"/settings/*",element:r.jsx(Q7,{})}),r.jsx(Xt,{path:"/m/desktop/*",element:r.jsx(J7,{})}),r.jsx(Xt,{path:"/m/code/*",element:r.jsx(r9,{})}),r.jsx(Xt,{path:"/p/:pid/*",element:r.jsx(E8,{})}),r.jsx(Xt,{path:"*",element:r.jsx(A9,{})})]})})]}),r.jsx(o9,{open:u,onClose:g}),r.jsx(y9,{open:p,onOpenChange:m})]})})}function C9({onToggleTheme:e,isDark:t,pathname:a}){const{projects:o}=Xc(),l=VP(),c=a.split("/").filter(Boolean),u=c[0]==="p"?o.find(N=>String(N.id)===c[1]):void 0,p=c[0]==="settings"?R9(c[1]):c[0]==="p"?T9(c[2]):"",m=c[0]==="p"&&c[1]==="0",g=u?.name||u?.path?.split("/").pop()||f("nav.project"),h=a==="/"?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"),E9(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=a==="/"?"":c[0]==="settings"?f("settings.subtitle"):c[0]==="p"?m?f("base.subtitle"):u?`${bC(u.kind)} · ${u.path}`:"":"",v=UP(),k=$P();return r.jsxs("header",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-border/50 px-3",children:[v&&r.jsx(rD,{collapsed:v.collapsed,onToggle:v.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(N9,{}),r.jsx(Ye,{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(FM,{size:14}):r.jsx(PM,{size:14})})})]})}function N9(){const e=aC(),t=a=>{a!==e&&(nC(a),window.location.reload())};return r.jsxs(J2,{children:[r.jsxs(eC,{"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(AM,{size:14}),r.jsx("span",{className:"text-[11px] font-medium uppercase",children:e})]}),r.jsx(tC,{align:"end",children:r.jsx(Zz,{value:e,onValueChange:a=>t(a),children:sC.map(a=>r.jsx(Wz,{value:a.value,children:a.label},a.value))})})]})}function E9(e){switch(e){case"desktop":return f("nav.modules.desktop");case"code":return f("nav.modules.code");default:return e||""}}function R9(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 T9(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 uk({text:e,sub:t,mood:a="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(VC,{mood:a,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 A9(){const e=Qn();return r.jsx(qC,{testId:"screen-not-found",mood:"confused",title:f("not_found.title"),titleClassName:"text-7xl",message:f("not_found.message"),action:r.jsx(Qa,{variant:"outline",onClick:()=>e("/"),children:f("not_found.home")})})}hT.createRoot(document.getElementById("root")).render(r.jsx(Uc.StrictMode,{children:r.jsx(UA,{children:r.jsx(WM,{children:r.jsx(k9,{})})})}));
656
- //# sourceMappingURL=index-lu6lfr1N.js.map
656
+ //# sourceMappingURL=index--24yvYc5.js.map