@markus-global/cli 0.9.0 → 0.9.2
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.
- package/dist/commands/start.js +25 -0
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +211 -24
- package/dist/web-ui/assets/{CommentInput-Ccv0KCzc.js → CommentInput-D3jx82c7.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-BbN7QT3E.js → ContentRenderer-CQ9uMng0.js} +2 -2
- package/dist/web-ui/assets/{Deliverables-Dzfujlqv.js → Deliverables-DKy2_HPY.js} +1 -1
- package/dist/web-ui/assets/Notifications-1YKMlJ91.js +1 -0
- package/dist/web-ui/assets/{Search-Va12fH-V.js → Search-D5P2V5tM.js} +1 -1
- package/dist/web-ui/assets/{Settings-D_0MEUGb.js → Settings-C86a_mG8.js} +6 -6
- package/dist/web-ui/assets/{Store-dRlOlppM.js → Store-Ca8mvyTT.js} +1 -1
- package/dist/web-ui/assets/Team-DHmWU23x.js +40 -0
- package/dist/web-ui/assets/{Work-C6pfFbRU.js → Work-zJLJ6A3I.js} +5 -5
- package/dist/web-ui/assets/{arc-w52qYN0j.js → arc-s5quZ9MF.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-Dq5t04Vy.js → architectureDiagram-3BPJPVTR-iZhZ9wDV.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-dMSQ7RYP.js → blockDiagram-GPEHLZMM-lYMBEpQb.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-yG4K-xPW.js → c4Diagram-AAUBKEIU-C8vbScKq.js} +1 -1
- package/dist/web-ui/assets/channel-D2RoSw08.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-BMCCyFP7.js → chunk-2J33WTMH-DhvC5Teh.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-DrZE__0f.js → chunk-4BX2VUAB-Do4f1QNX.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-BHAPJ9Eo.js → chunk-55IACEB6-BCDgVda5.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-Ctfjl9vK.js → chunk-727SXJPM-n9W-gHJL.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-SVZPGzSA.js → chunk-AQP2D5EJ-joCNa2WM.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-DeTpOrnv.js → chunk-FMBD7UC4-Cp9QtfEA.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-CudW1r3G.js → chunk-ND2GUHAM-Dt_ZkR0s.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-CJSQIoVy.js → chunk-QZHKN3VN-CVGCkc4k.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-DGebyJZN.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-DGebyJZN.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-CcCOSPt7.js → cose-bilkent-S5V4N54A-B4Q2AELl.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-F3l9565T.js → dagre-BM42HDAG-DoazhTnM.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-B5Ep5hBX.js → diagram-2AECGRRQ-C7KY67Fn.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-Ba-Xi40Z.js → diagram-5GNKFQAL-dPjx6DBc.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-nq3nvV52.js → diagram-KO2AKTUF-D4BEU7N2.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-BLQG5suI.js → diagram-LMA3HP47-D9PLmyge.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-BZwEfL_A.js → diagram-OG6HWLK6-Dg6SRSYN.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-x0d6Urzc.js → erDiagram-TEJ5UH35-D97ueERw.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-Bps4iInm.js → flowDiagram-I6XJVG4X-Cm-sRIL_.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-BQhqabZG.js → ganttDiagram-6RSMTGT7-CXq6jqCz.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-CZsFUtiG.js → gitGraphDiagram-PVQCEYII-CJ50_J0p.js} +1 -1
- package/dist/web-ui/assets/{index-BVZKeNvh.js → index-CHkb08MZ.js} +55 -55
- package/dist/web-ui/assets/index-CPULIfuW.css +1 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-bUkRpixn.js → infoDiagram-5YYISTIA-CbTpYpwF.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-C71uSHjN.js → ishikawaDiagram-YF4QCWOH-CUt9Btxt.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-CH4cq7H3.js → journeyDiagram-JHISSGLW-F9zmJizG.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-B1plHCmn.js → kanban-definition-UN3LZRKU-jNs9ezLz.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-BtKFJxef.js → mermaid.core-Cxm0p7KD.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-BRinAMnx.js → mindmap-definition-RKZ34NQL-BuW2AA71.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-B8r7cm8D.js → pieDiagram-4H26LBE5-BKrViKGj.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-BlYE_3Bv.js → quadrantDiagram-W4KKPZXB-Hh0Kzhcb.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-XHqns5Oh.js → requirementDiagram-4Y6WPE33-B1ga-7j9.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP--WceN9u7.js → sankeyDiagram-5OEKKPKP-2uQ075vI.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-NXQDJA2d.js → sequenceDiagram-3UESZ5HK-97k-cDlv.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-Cs8Vl8wX.js → stateDiagram-AJRCARHV-PTiMHe-8.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-CNP7uL0K.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-V9TBhcGA.js → timeline-definition-PNZ67QCA-Gji5tIlk.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-BkrjAkwE.js → vennDiagram-CIIHVFJN-B91fyhQC.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-DnYl7xFk.js → wardley-L42UT6IY-C9MIuW9C.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-Bgjk8gUy.js → wardleyDiagram-YWT4CUSO-CtXjrE4d.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-DVv-I1Er.js → xychartDiagram-2RQKCTM6-BgVdUlxT.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/package.json +1 -1
- package/dist/web-ui/assets/Notifications-DMI9cmK5.js +0 -1
- package/dist/web-ui/assets/Team-D8m98W3b.js +0 -40
- package/dist/web-ui/assets/channel-0x_SxlyN.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-D4o-x8Tr.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-D4o-x8Tr.js +0 -1
- package/dist/web-ui/assets/index-BDWvYwl1.css +0 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-Cmof_fUq.js +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{u as me,r as l,j as e,J as bn,F as ta,f as F,a as sa,as as kr,n as ss,P as rs,at as ra,au as Cr,h as Fe,av as yn,w as na,aw as ns,ax as Rs,_ as aa}from"./index-BVZKeNvh.js";function oa(s,r){for(var o=0;o<r.length;o++){const n=r[o];if(typeof n!="string"&&!Array.isArray(n)){for(const a in n)if(a!=="default"&&!(a in s)){const t=Object.getOwnPropertyDescriptor(n,a);t&&Object.defineProperty(s,a,t.get?t:{enumerable:!0,get:()=>n[a]})}}}return Object.freeze(Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}))}function ia(s){return s>=1e6?`${(s/1e6).toFixed(s%1e6===0?0:1)}M`:s>=1e3?`${(s/1e3).toFixed((s%1e3===0,0))}K`:String(s)}function la(s){return s.maxInputTokens>0||s.inputCostPer1MTokens>0||s.outputCostPer1MTokens>0}function as(s){if(s.tier)return s.tier;const r=s.id.toLowerCase(),o=/opus|5\.4|o3-(?!mini)|o1-(?!mini)|gemini.*ultra|sonnet-4-20/,n=/haiku|flash|nano|lite|small|fast|free|8b|7b|1b|3b/;return/o4-mini|o3-mini|o1-mini|gpt-4o-mini/.test(r)?"pro":o.test(r)?"max":n.test(r)?"base":"pro"}const Sr={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30"};function vn({models:s,selectedModel:r,onSelect:o,loading:n,compact:a,maxVisible:t,showTiers:d}){const{t:c}=me("settings"),[u,p]=l.useState(""),[y,T]=l.useState(!1),[x,v]=l.useState(""),w=l.useMemo(()=>{let g=s;if(u){const h=u.toLowerCase();g=g.filter(N=>N.id.toLowerCase().includes(h))}return x&&(g=g.filter(h=>as(h)===x)),g},[s,u,x]),A=l.useMemo(()=>{const g={max:0,pro:0,base:0};for(const h of s)g[as(h)]++;return g},[s]),K=t??(a?5:10),j=y?w:w.slice(0,K),S=w.length>K;return n?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-tertiary",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),c("modelPicker.loading")]}):s.length===0?e.jsx("div",{className:"py-3 text-sm text-fg-tertiary",children:c("modelPicker.empty")}):e.jsxs("div",{className:"space-y-2",children:[d&&s.length>3&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>v(""),className:`px-2 py-0.5 rounded text-[10px] transition-colors ${x?"bg-surface-overlay text-fg-tertiary hover:text-fg-secondary":"bg-brand-500/20 text-brand-500"}`,children:c("modelPicker.allCount",{count:s.length})}),["max","pro","base"].filter(g=>A[g]>0).map(g=>e.jsx("button",{onClick:()=>v(x===g?"":g),className:`px-2 py-0.5 rounded text-[10px] font-medium uppercase transition-colors border ${x===g?Sr[g]:"border-transparent bg-surface-overlay text-fg-tertiary hover:text-fg-secondary"}`,children:c("modelPicker.tierCount",{tier:c(`modelRouting.tier.${g}`),count:A[g]})},g))]}),s.length>5&&e.jsx("input",{type:"text",value:u,onChange:g=>{p(g.target.value),T(!1)},placeholder:c("modelPicker.filterPlaceholder"),className:"w-full px-3 py-1.5 bg-surface-overlay border border-border-default rounded-lg text-xs text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:border-brand-500"}),e.jsx("div",{className:`space-y-1 ${a?"max-h-[280px] overflow-y-auto":""}`,children:j.map(g=>{const h=g.id===r,N=as(g);return e.jsxs("button",{type:"button",onClick:()=>o(g.id),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${h?"bg-brand-500/10 border border-brand-500/30":"hover:bg-surface-overlay border border-transparent"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${h?"border-brand-500":"border-border-default"}`,children:h&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),e.jsx("span",{className:`text-xs font-medium ${h?"text-brand-500":"text-fg-primary"}`,children:g.id}),d&&e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-semibold uppercase border ${Sr[N]}`,children:c(`modelRouting.tier.${N}`)})]}),e.jsx("div",{className:"flex items-center gap-2",children:h&&e.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:c("modelPicker.active")})})]}),la(g)&&g.maxInputTokens>0&&e.jsx("div",{className:"ml-5 mt-0.5 flex items-center gap-2 text-[10px] text-fg-tertiary flex-wrap",children:e.jsxs("span",{children:[ia(g.maxInputTokens)," ",c("modelPicker.ctx")]})}),!a&&e.jsxs("div",{className:"ml-5 mt-1 flex items-center gap-1.5 flex-wrap",children:[g.capabilities.functionCalling&&e.jsx(nt,{label:c("modelPicker.capabilities.tools")}),g.capabilities.vision&&e.jsx(nt,{label:c("modelPicker.capabilities.vision")}),g.capabilities.reasoning&&e.jsx(nt,{label:c("modelPicker.capabilities.reasoning")}),g.capabilities.promptCaching&&e.jsx(nt,{label:c("modelPicker.capabilities.caching")}),g.capabilities.webSearch&&e.jsx(nt,{label:c("modelPicker.capabilities.search")})]})]},g.id)})}),S&&!y&&e.jsx("button",{type:"button",onClick:()=>T(!0),className:"text-xs text-brand-500 hover:text-brand-400 px-3",children:c("modelPicker.showAll",{count:w.length})}),y&&S&&e.jsx("button",{type:"button",onClick:()=>T(!1),className:"text-xs text-fg-tertiary hover:text-fg-secondary px-3",children:c("modelPicker.showLess")})]})}function nt({label:s}){return e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] bg-surface-overlay text-fg-tertiary border border-border-default",children:s})}function Os({value:s,options:r,placeholder:o,onChange:n}){const{t:a}=me("settings"),[t,d]=l.useState(!1),[c,u]=l.useState(""),p=l.useRef(null),y=l.useRef(null),T=l.useRef(null),[x,v]=l.useState(-1);l.useEffect(()=>{function g(h){p.current&&!p.current.contains(h.target)&&d(!1)}return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[]),l.useEffect(()=>{t&&y.current&&y.current.focus()},[t]);const w=l.useMemo(()=>{if(!c.trim())return r;const g=c.toLowerCase();return r.filter(h=>h.modelId.toLowerCase().includes(g)||h.modelName.toLowerCase().includes(g)||h.provider.toLowerCase().includes(g)||h.providerLabel.toLowerCase().includes(g)||h.tier&&h.tier.toLowerCase().includes(g))},[r,c]),A=l.useMemo(()=>{const g=new Map;for(const N of w){const E=N.providerLabel;g.has(E)||g.set(E,[]),g.get(E).push(N)}const h={max:0,pro:1,base:2};for(const N of g.values())N.sort((E,O)=>(h[E.tier??"base"]??9)-(h[O.tier??"base"]??9));return g},[w]),K=l.useMemo(()=>{const g=[];for(const h of A.values())g.push(...h);return g},[A]),j=l.useMemo(()=>{if(!s)return o??a("modelRouting.auto");const g=r.find(h=>`${h.provider}/${h.modelId}`===s);return g?`${g.providerLabel}/${g.modelName}`:s},[s,r,o,a]);function S(g){if(!t){(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),d(!0));return}switch(g.key){case"ArrowDown":g.preventDefault(),v(h=>Math.min(h+1,K.length-1));break;case"ArrowUp":g.preventDefault(),v(h=>Math.max(h-1,-1));break;case"Enter":g.preventDefault(),x===-1?n(""):K[x]&&n(`${K[x].provider}/${K[x].modelId}`),d(!1),u("");break;case"Escape":d(!1),u("");break}}return l.useEffect(()=>{T.current&&x>=0&&T.current.querySelector(`[data-focus-index="${x}"]`)?.scrollIntoView({block:"nearest"})},[x]),e.jsxs("div",{ref:p,className:"relative",onKeyDown:S,children:[e.jsx("button",{type:"button",onClick:()=>{d(!t),u(""),v(-1)},className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary text-left truncate focus:outline-none focus:border-brand-500",children:j}),t&&e.jsxs("div",{className:"absolute z-50 mt-1 w-full min-w-[240px] max-h-[280px] bg-surface-elevated border border-border-default rounded-lg shadow-xl overflow-hidden flex flex-col",children:[e.jsx("div",{className:"p-1.5 border-b border-border-default",children:e.jsx("input",{ref:y,type:"text",value:c,onChange:g=>{u(g.target.value),v(-1)},placeholder:a("modelPicker.searchPlaceholder")||"Search models...",className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary focus:outline-none focus:border-brand-500"})}),e.jsxs("div",{ref:T,className:"overflow-y-auto flex-1",children:[e.jsx("div",{className:`px-3 py-1.5 text-xs cursor-pointer ${x===-1?"bg-brand-500/20 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,onClick:()=>{n(""),d(!1),u("")},children:o??a("modelRouting.auto")}),[...A.entries()].map(([g,h])=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider bg-surface-overlay/50 sticky top-0",children:g}),h.map(N=>{const E=K.indexOf(N),O=`${N.provider}/${N.modelId}`===s;return e.jsxs("div",{"data-focus-index":E,className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${E===x?"bg-brand-500/20":O?"bg-surface-overlay":"hover:bg-surface-overlay/50"}`,onClick:()=>{n(`${N.provider}/${N.modelId}`),d(!1),u("")},children:[e.jsx("span",{className:"flex-1 truncate text-fg-primary",children:N.modelName}),N.tier&&e.jsx(da,{tier:N.tier}),N.costTier&&e.jsx("span",{className:"text-[9px] text-fg-tertiary",children:N.costTier})]},`${N.provider}/${N.modelId}`)})]},g)),K.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:a("modelPicker.empty")})]})]})]})}function da({tier:s}){const r={max:"bg-purple-500/20 text-purple-400",pro:"bg-blue-500/20 text-blue-400",base:"bg-gray-500/20 text-gray-400"};return e.jsx("span",{className:`px-1 py-0.5 rounded text-[8px] font-bold uppercase ${r[s]??r.base}`,children:s})}const ca=500,Pr=[{groupKey:"image",capabilities:["image_recognition","image_generation"]},{groupKey:"audio",capabilities:["audio_tts","audio_stt"]},{groupKey:"video",capabilities:["video_generation"]}];function ua({onSave:s,configuredProviders:r}){const{t:o}=me(["settings","common"]),[n,a]=l.useState({}),[t,d]=l.useState(null),[c,u]=l.useState(!1),[p,y]=l.useState(null),[T,x]=l.useState("idle"),[v,w]=l.useState(null),[A,K]=l.useState({}),[j,S]=l.useState(!1),[g,h]=l.useState("idle"),[N,E]=l.useState(null),[O,U]=l.useState(!1),_=l.useRef(null),D=l.useRef(null),R=l.useMemo(()=>r.map(I=>I.name).sort().join(","),[r]);l.useEffect(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(I=>{if(!I.ok)throw new Error(`HTTP ${I.status}`);return I.json()}).then(I=>{a(I.capabilityRouting?.assignments??{}),d(I.routingDefaultModel??null),u(!0)}).catch(I=>{y(String(I)),u(!0)})},[R]),l.useEffect(()=>{fetch("/api/models/routing-candidates",{credentials:"include"}).then(I=>{if(!I.ok)throw new Error(`HTTP ${I.status}`);return I.json()}).then(I=>{const H=[];for(const q of I.providers)for(const m of q.models)H.push({provider:q.provider,providerLabel:q.displayName,modelId:m.id,modelName:m.name,mode:m.mode,tier:m.tier,costTier:m.costTier,capabilities:m.capabilities});w(H)}).catch(()=>w(null))},[R]),l.useEffect(()=>{fetch("/api/models/suggested-assignments",{credentials:"include"}).then(I=>{if(!I.ok)throw new Error(`HTTP ${I.status}`);return I.json()}).then(I=>{K(I.suggestions),S(!0)}).catch(()=>S(!0))},[R]);const P=l.useCallback(I=>{x("saving"),s(I).then(()=>{x("saved"),setTimeout(()=>x(H=>H==="saved"?"idle":H),2e3)}).catch(()=>{x("error"),setTimeout(()=>x(H=>H==="error"?"idle":H),3e3)})},[s]),f=l.useCallback((I,H)=>{D.current={capabilityRouting:I!==void 0?{assignments:I}:D.current?.capabilityRouting,routingDefaultModel:H!==void 0?H:D.current?.routingDefaultModel},_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{const q=D.current;D.current=null,q&&P(q)},ca)},[P]),k=l.useMemo(()=>r.flatMap(I=>(I.models??[{id:I.model,name:I.model}]).map(H=>({provider:I.name,providerLabel:I.displayName??I.name,modelId:H.id,modelName:H.name}))),[r]),$=v??k,J=l.useMemo(()=>Object.entries(n).map(([I,H])=>`${I}:${H?.provider??""}/${H?.model??""}`).sort().join("|"),[n]);l.useEffect(()=>{!c||!v||v.length===0||v.some(I=>!!I.modelId)&&a(I=>{let H=!1;const q={...I};for(const m of Pr)for(const L of m.capabilities){const V=q[L];if(!V?.model)continue;const X=jn(v,L);if(X.length===0)continue;X.some(Q=>Q.provider===V.provider&&Q.modelId===V.model)||(delete q[L],H=!0)}return H?(f(q),q):I})},[c,v,R,f,J]);const Z=l.useCallback(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(I=>{if(!I.ok)throw new Error(`HTTP ${I.status}`);return I.json()}).then(I=>{a(I.capabilityRouting?.assignments??{}),d(I.routingDefaultModel??null)}).catch(()=>{}),fetch("/api/models/routing-candidates",{credentials:"include"}).then(I=>{if(!I.ok)throw new Error(`HTTP ${I.status}`);return I.json()}).then(I=>{const H=[];for(const q of I.providers)for(const m of q.models)H.push({provider:q.provider,providerLabel:q.displayName,modelId:m.id,modelName:m.name,mode:m.mode,tier:m.tier,costTier:m.costTier,capabilities:m.capabilities});w(H)}).catch(()=>{})},[]),ne=l.useCallback(async()=>{if(g!=="working"){h("working"),E(null);try{const I=await fetch("/api/settings/llm/restore-recommended",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}}),H=await I.json().catch(()=>({}));if(!I.ok||!H.ok)throw new Error(H.error??`HTTP ${I.status}`);H.capabilityRouting&&a(H.capabilityRouting.assignments??{}),H.routingDefaultModel!==void 0&&d(H.routingDefaultModel),Z(),h("idle"),x("saved"),setTimeout(()=>x(q=>q==="saved"?"idle":q),2e3)}catch(I){h("error"),E(I instanceof Error?I.message:String(I)),setTimeout(()=>h("idle"),4e3)}}},[g,Z]);return c?p?e.jsx("div",{className:"bg-red-500/10 border border-red-500/30 rounded-xl p-4 text-xs text-red-400",children:o("modelRouting.loadError",{error:p})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(ga,{status:T,t:o}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>U(!0),disabled:g==="working",className:"text-xs px-3 py-1.5 rounded-lg border border-border-default text-fg-secondary hover:text-fg-primary hover:border-brand-500/40 disabled:opacity-50 transition-colors",children:o(g==="working"?"modelRouting.restoreWorking":"modelRouting.restoreRecommended")}),N&&e.jsx("span",{className:"text-[10px] text-red-400 max-w-xs text-right",children:N})]})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:o("modelRouting.defaultModelTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:o("modelRouting.defaultModelDesc")})]}),e.jsx("div",{className:"max-w-md",children:e.jsx(Os,{value:t?`${t.provider}/${t.model}`:"",options:$,placeholder:o("modelRouting.defaultModelPlaceholder"),onChange:I=>{if(!I)d(null),f(void 0,null);else{const[H,...q]=I.split("/"),m={provider:H,model:q.join("/")};if(d(m),n.text){const L={...n};delete L.text,a(L),f(L,m)}else f(void 0,m)}}})})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:o("modelRouting.capabilityAssignTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:o("modelRouting.capabilityAssignDesc")})]}),r.length===0&&e.jsx("div",{className:"p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg text-xs text-yellow-400",children:o("modelRouting.noProvidersHint")}),r.length>0&&e.jsx("div",{className:"space-y-4",children:Pr.map(I=>e.jsx(xa,{groupKey:I.groupKey,capabilities:I.capabilities,assignments:n,suggestions:A,allModels:$,configuredProviderNames:new Set(r.map(H=>H.name)),t:o,onAssign:(H,q)=>{const m={...n};q?m[H]=q:delete m[H],a(m),f(m)}},I.groupKey))})]}),O&&e.jsx(bn,{variant:"primary",title:o("modelRouting.restoreRecommended"),message:o("modelRouting.restoreConfirm"),confirmLabel:o("common:confirm"),onConfirm:()=>{U(!1),ne()},onCancel:()=>U(!1)})]}):e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 animate-pulse",children:[e.jsx("div",{className:"h-4 bg-surface-overlay rounded w-1/3 mb-3"}),e.jsx("div",{className:"h-3 bg-surface-overlay rounded w-2/3 mb-4"}),e.jsx("div",{className:"space-y-2",children:[1,2,3,4,5].map(I=>e.jsx("div",{className:"h-10 bg-surface-overlay rounded-lg"},I))})]})})}function xa({groupKey:s,capabilities:r,assignments:o,suggestions:n,allModels:a,configuredProviderNames:t,t:d,onAssign:c}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 px-1",children:d(`modelRouting.capabilityGroups.${s}`)}),e.jsx("div",{className:"space-y-1",children:r.map(u=>{const p=o[u],y=n[u],T=p?`${p.provider}/${p.model}`:"",x=jn(a,u),v=y?x.find(S=>S.provider===y.provider&&S.modelId===y.model)?.modelName??y.model:void 0,w=x.length>0,A=p?ma(a,p.provider,p.model):void 0,K=p&&!t.has(p.provider),j=!!(p&&w&&u!=="text"&&!x.some(S=>S.provider===p.provider&&S.modelId===p.model));return e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2 rounded-lg ${j?"bg-red-500/10 border border-red-500/30":K?"bg-yellow-500/10 border border-yellow-500/30":!w&&!p?"bg-amber-500/5 border border-amber-500/20":"bg-surface-overlay/40"}`,children:[e.jsx("div",{className:"w-28 shrink-0",children:e.jsx("span",{className:"text-xs text-fg-primary",children:d(`modelRouting.capabilities.${u}`)})}),e.jsx("div",{className:"flex-1 min-w-0",children:j?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-xs text-red-400",children:["⚠ ",p.model]}),e.jsx("span",{className:"text-[10px] text-red-400/70",children:d("modelRouting.mismatchHint")})]}),e.jsx(Os,{value:"",options:x,placeholder:d("modelRouting.selectModel"),onChange:S=>{if(!S)c(u,null);else{const[g,...h]=S.split("/");c(u,{provider:g,model:h.join("/")})}}})]}):w?e.jsx(Os,{value:T,options:x,placeholder:v?`${v} (${d("modelRouting.suggested")})`:d("modelRouting.selectModel"),onChange:S=>{if(!S)c(u,null);else{const[g,...h]=S.split("/");c(u,{provider:g,model:h.join("/")})}}}):e.jsxs("span",{className:"text-xs text-amber-400",children:[d("modelRouting.noModelAvailable"),e.jsxs("span",{className:"text-fg-tertiary ml-1",children:["— ",d("modelRouting.addProviderHint")]})]})}),e.jsxs("div",{className:"w-14 shrink-0 flex justify-end",children:[j&&e.jsx("span",{className:"text-[10px] text-red-400 font-medium",title:d("modelRouting.mismatchHint"),children:"⚠"}),!j&&K&&e.jsx("span",{className:"text-[10px] text-yellow-400 font-medium",title:d("modelRouting.staleProvider"),children:"⚠"}),!j&&!K&&A&&e.jsx(Ar,{tier:A}),!j&&!K&&!A&&p&&e.jsx(Ar,{tier:"unknown"})]}),e.jsx("div",{className:"w-8 shrink-0 flex justify-end",children:p&&e.jsx("button",{onClick:()=>c(u,null),className:"text-fg-tertiary hover:text-red-400 transition-colors",title:d("modelRouting.clear"),children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]},u)})})]})}function ma(s,r,o){return s.find(a=>a.provider===r&&a.modelId===o)?.tier}function ga({status:s,t:r}){if(s==="idle")return null;const o={idle:"",saving:"text-fg-tertiary",saved:"text-green-400",error:"text-red-400"},n={idle:"",saving:r("modelRouting.saving"),saved:r("modelRouting.saved"),error:r("modelRouting.saveError")};return e.jsx("div",{className:`text-xs font-medium transition-opacity ${o[s]}`,children:n[s]})}function Ar({tier:s}){const r={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30",unknown:"bg-gray-500/10 text-fg-tertiary border-border-default"};return e.jsx("span",{className:`px-1.5 py-0.5 text-[9px] rounded font-semibold uppercase border ${r[s]??r.unknown}`,children:s==="unknown"?"—":s})}const fa=new Set(["imageGeneration","tts","stt","videoGeneration","audioOutput","audioInput"]);function jn(s,r){if(r==="text")return s.filter(d=>!(d.capabilities&&d.capabilities.some(c=>fa.has(c))||d.mode&&d.mode!=="chat"));const o={image_generation:["image_generation"],audio_tts:["audio_speech"],audio_stt:["audio_transcription"],video_generation:["video_generation"]},n={image_recognition:["vision"],image_generation:["imageGeneration"],audio_tts:["tts"],audio_stt:["stt"],video_generation:["videoGeneration"]},a=o[r],t=n[r];return s.filter(d=>!!(d.capabilities&&d.capabilities.length>0&&t&&t.some(c=>d.capabilities.includes(c))||a&&d.mode&&a.includes(d.mode)))}const Ct=[{id:"markus",label:"Markus Cloud AI",envKey:"MARKUS_SUBSCRIPTION_KEY",defaultModel:""},{id:"anthropic",label:"Anthropic",envKey:"ANTHROPIC_API_KEY",defaultModel:"claude-opus-4-6"},{id:"openai",label:"OpenAI",envKey:"OPENAI_API_KEY",defaultModel:"gpt-5.4"},{id:"google",label:"Google Gemini",envKey:"GOOGLE_API_KEY",defaultModel:"gemini-3-1-pro"},{id:"deepseek",label:"DeepSeek",envKey:"DEEPSEEK_API_KEY",baseUrl:"https://api.deepseek.com",defaultModel:"deepseek-v4-flash"},{id:"siliconflow",label:"SiliconFlow (中国)",envKey:"SILICONFLOW_API_KEY",baseUrl:"https://api.siliconflow.cn/v1",defaultModel:"Qwen/Qwen3.5-35B-A3B"},{id:"siliconflow-intl",label:"SiliconFlow (Global)",envKey:"SILICONFLOW_INTL_API_KEY",baseUrl:"https://api-st.siliconflow.cn/v1",defaultModel:"Qwen/Qwen3.5-35B-A3B"},{id:"minimax",label:"MiniMax (Global)",envKey:"MINIMAX_API_KEY",baseUrl:"https://api.minimax.io/v1",defaultModel:"MiniMax-M3"},{id:"minimax-cn",label:"MiniMax (中国)",envKey:"MINIMAX_CN_API_KEY",baseUrl:"https://api.minimaxi.com/v1",defaultModel:"MiniMax-M3"},{id:"openrouter",label:"OpenRouter",envKey:"OPENROUTER_API_KEY",baseUrl:"https://openrouter.ai/api/v1",defaultModel:"xiaomi/mimo-v2-pro:free"},{id:"zai",label:"ZAI (GLM)",envKey:"ZAI_API_KEY",baseUrl:"https://api.z.ai/api/paas/v4",defaultModel:"glm-5.1"},{id:"xai",label:"xAI (Grok)",envKey:"XAI_API_KEY",baseUrl:"https://api.x.ai/v1",defaultModel:"grok-3"},{id:"mistral",label:"Mistral AI",envKey:"MISTRAL_API_KEY",baseUrl:"https://api.mistral.ai/v1",defaultModel:"mistral-large-latest"},{id:"groq",label:"Groq",envKey:"GROQ_API_KEY",baseUrl:"https://api.groq.com/openai/v1",defaultModel:"llama-3.3-70b-versatile"},{id:"perplexity",label:"Perplexity",envKey:"PERPLEXITY_API_KEY",baseUrl:"https://api.perplexity.ai",defaultModel:"sonar-pro"},{id:"cohere",label:"Cohere",envKey:"COHERE_API_KEY",baseUrl:"https://api.cohere.ai/compatibility/v1",defaultModel:"command-r-plus"},{id:"together_ai",label:"Together AI",envKey:"TOGETHER_API_KEY",baseUrl:"https://api.together.xyz/v1",defaultModel:"meta-llama/Llama-3.3-70B-Instruct-Turbo"},{id:"fireworks_ai",label:"Fireworks AI",envKey:"FIREWORKS_API_KEY",baseUrl:"https://api.fireworks.ai/inference/v1",defaultModel:"accounts/fireworks/models/llama-v3p3-70b-instruct"},{id:"moonshot",label:"Moonshot (Kimi)",envKey:"MOONSHOT_API_KEY",baseUrl:"https://api.moonshot.cn/v1",defaultModel:"moonshot-v1-auto"},{id:"volcengine",label:"Volcengine (Doubao)",envKey:"VOLCENGINE_API_KEY",baseUrl:"https://ark.cn-beijing.volces.com/api/v3",defaultModel:"doubao-1.5-pro-32k"},{id:"dashscope",label:"DashScope (Qwen)",envKey:"DASHSCOPE_API_KEY",baseUrl:"https://dashscope.aliyuncs.com/compatible-mode/v1",defaultModel:"qwen-max"},{id:"ollama",label:"Ollama (Local)",envKey:"OLLAMA_BASE_URL",baseUrl:"http://localhost:11434/v1",defaultModel:"llama3"},{id:"atlascloud",label:"Atlas Cloud (Full-Modal)",envKey:"ATLASCLOUD_API_KEY",baseUrl:"https://api.atlascloud.ai/v1",defaultModel:"claude-sonnet-4-6"},{id:"strongly",label:"Strongly.AI (Full-Modal)",envKey:"STRONGLY_API_KEY",baseUrl:"https://api.strongly.ai/v1",defaultModel:"claude-sonnet-4-6"}];var Ye={},os,Mr;function pa(){return Mr||(Mr=1,os=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),os}var is={},De={},Tr;function $e(){if(Tr)return De;Tr=1;let s;const r=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return De.getSymbolSize=function(n){if(!n)throw new Error('"version" cannot be null or undefined');if(n<1||n>40)throw new Error('"version" should be in range from 1 to 40');return n*4+17},De.getSymbolTotalCodewords=function(n){return r[n]},De.getBCHDigit=function(o){let n=0;for(;o!==0;)n++,o>>>=1;return n},De.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');s=n},De.isKanjiModeEnabled=function(){return typeof s<"u"},De.toSJIS=function(n){return s(n)},De}var ls={},Er;function _s(){return Er||(Er=1,(function(s){s.L={bit:1},s.M={bit:0},s.Q={bit:3},s.H={bit:2};function r(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"l":case"low":return s.L;case"m":case"medium":return s.M;case"q":case"quartile":return s.Q;case"h":case"high":return s.H;default:throw new Error("Unknown EC Level: "+o)}}s.isValid=function(n){return n&&typeof n.bit<"u"&&n.bit>=0&&n.bit<4},s.from=function(n,a){if(s.isValid(n))return n;try{return r(n)}catch{return a}}})(ls)),ls}var ds,Ir;function ha(){if(Ir)return ds;Ir=1;function s(){this.buffer=[],this.length=0}return s.prototype={get:function(r){const o=Math.floor(r/8);return(this.buffer[o]>>>7-r%8&1)===1},put:function(r,o){for(let n=0;n<o;n++)this.putBit((r>>>o-n-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(r){const o=Math.floor(this.length/8);this.buffer.length<=o&&this.buffer.push(0),r&&(this.buffer[o]|=128>>>this.length%8),this.length++}},ds=s,ds}var cs,Lr;function ba(){if(Lr)return cs;Lr=1;function s(r){if(!r||r<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=r,this.data=new Uint8Array(r*r),this.reservedBit=new Uint8Array(r*r)}return s.prototype.set=function(r,o,n,a){const t=r*this.size+o;this.data[t]=n,a&&(this.reservedBit[t]=!0)},s.prototype.get=function(r,o){return this.data[r*this.size+o]},s.prototype.xor=function(r,o,n){this.data[r*this.size+o]^=n},s.prototype.isReserved=function(r,o){return this.reservedBit[r*this.size+o]},cs=s,cs}var us={},Rr;function ya(){return Rr||(Rr=1,(function(s){const r=$e().getSymbolSize;s.getRowColCoords=function(n){if(n===1)return[];const a=Math.floor(n/7)+2,t=r(n),d=t===145?26:Math.ceil((t-13)/(2*a-2))*2,c=[t-7];for(let u=1;u<a-1;u++)c[u]=c[u-1]-d;return c.push(6),c.reverse()},s.getPositions=function(n){const a=[],t=s.getRowColCoords(n),d=t.length;for(let c=0;c<d;c++)for(let u=0;u<d;u++)c===0&&u===0||c===0&&u===d-1||c===d-1&&u===0||a.push([t[c],t[u]]);return a}})(us)),us}var xs={},Or;function va(){if(Or)return xs;Or=1;const s=$e().getSymbolSize,r=7;return xs.getPositions=function(n){const a=s(n);return[[0,0],[a-r,0],[0,a-r]]},xs}var ms={},Br;function ja(){return Br||(Br=1,(function(s){s.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const r={N1:3,N2:3,N3:40,N4:10};s.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},s.from=function(a){return s.isValid(a)?parseInt(a,10):void 0},s.getPenaltyN1=function(a){const t=a.size;let d=0,c=0,u=0,p=null,y=null;for(let T=0;T<t;T++){c=u=0,p=y=null;for(let x=0;x<t;x++){let v=a.get(T,x);v===p?c++:(c>=5&&(d+=r.N1+(c-5)),p=v,c=1),v=a.get(x,T),v===y?u++:(u>=5&&(d+=r.N1+(u-5)),y=v,u=1)}c>=5&&(d+=r.N1+(c-5)),u>=5&&(d+=r.N1+(u-5))}return d},s.getPenaltyN2=function(a){const t=a.size;let d=0;for(let c=0;c<t-1;c++)for(let u=0;u<t-1;u++){const p=a.get(c,u)+a.get(c,u+1)+a.get(c+1,u)+a.get(c+1,u+1);(p===4||p===0)&&d++}return d*r.N2},s.getPenaltyN3=function(a){const t=a.size;let d=0,c=0,u=0;for(let p=0;p<t;p++){c=u=0;for(let y=0;y<t;y++)c=c<<1&2047|a.get(p,y),y>=10&&(c===1488||c===93)&&d++,u=u<<1&2047|a.get(y,p),y>=10&&(u===1488||u===93)&&d++}return d*r.N3},s.getPenaltyN4=function(a){let t=0;const d=a.data.length;for(let u=0;u<d;u++)t+=a.data[u];return Math.abs(Math.ceil(t*100/d/5)-10)*r.N4};function o(n,a,t){switch(n){case s.Patterns.PATTERN000:return(a+t)%2===0;case s.Patterns.PATTERN001:return a%2===0;case s.Patterns.PATTERN010:return t%3===0;case s.Patterns.PATTERN011:return(a+t)%3===0;case s.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(t/3))%2===0;case s.Patterns.PATTERN101:return a*t%2+a*t%3===0;case s.Patterns.PATTERN110:return(a*t%2+a*t%3)%2===0;case s.Patterns.PATTERN111:return(a*t%3+(a+t)%2)%2===0;default:throw new Error("bad maskPattern:"+n)}}s.applyMask=function(a,t){const d=t.size;for(let c=0;c<d;c++)for(let u=0;u<d;u++)t.isReserved(u,c)||t.xor(u,c,o(a,u,c))},s.getBestMask=function(a,t){const d=Object.keys(s.Patterns).length;let c=0,u=1/0;for(let p=0;p<d;p++){t(p),s.applyMask(p,a);const y=s.getPenaltyN1(a)+s.getPenaltyN2(a)+s.getPenaltyN3(a)+s.getPenaltyN4(a);s.applyMask(p,a),y<u&&(u=y,c=p)}return c}})(ms)),ms}var St={},_r;function Nn(){if(_r)return St;_r=1;const s=_s(),r=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],o=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return St.getBlocksCount=function(a,t){switch(t){case s.L:return r[(a-1)*4+0];case s.M:return r[(a-1)*4+1];case s.Q:return r[(a-1)*4+2];case s.H:return r[(a-1)*4+3];default:return}},St.getTotalCodewordsCount=function(a,t){switch(t){case s.L:return o[(a-1)*4+0];case s.M:return o[(a-1)*4+1];case s.Q:return o[(a-1)*4+2];case s.H:return o[(a-1)*4+3];default:return}},St}var gs={},at={},Dr;function Na(){if(Dr)return at;Dr=1;const s=new Uint8Array(512),r=new Uint8Array(256);return(function(){let n=1;for(let a=0;a<255;a++)s[a]=n,r[n]=a,n<<=1,n&256&&(n^=285);for(let a=255;a<512;a++)s[a]=s[a-255]})(),at.log=function(n){if(n<1)throw new Error("log("+n+")");return r[n]},at.exp=function(n){return s[n]},at.mul=function(n,a){return n===0||a===0?0:s[r[n]+r[a]]},at}var Kr;function wa(){return Kr||(Kr=1,(function(s){const r=Na();s.mul=function(n,a){const t=new Uint8Array(n.length+a.length-1);for(let d=0;d<n.length;d++)for(let c=0;c<a.length;c++)t[d+c]^=r.mul(n[d],a[c]);return t},s.mod=function(n,a){let t=new Uint8Array(n);for(;t.length-a.length>=0;){const d=t[0];for(let u=0;u<a.length;u++)t[u]^=r.mul(a[u],d);let c=0;for(;c<t.length&&t[c]===0;)c++;t=t.slice(c)}return t},s.generateECPolynomial=function(n){let a=new Uint8Array([1]);for(let t=0;t<n;t++)a=s.mul(a,new Uint8Array([1,r.exp(t)]));return a}})(gs)),gs}var fs,Ur;function ka(){if(Ur)return fs;Ur=1;const s=wa();function r(o){this.genPoly=void 0,this.degree=o,this.degree&&this.initialize(this.degree)}return r.prototype.initialize=function(n){this.degree=n,this.genPoly=s.generateECPolynomial(this.degree)},r.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const a=new Uint8Array(n.length+this.degree);a.set(n);const t=s.mod(a,this.genPoly),d=this.degree-t.length;if(d>0){const c=new Uint8Array(this.degree);return c.set(t,d),c}return t},fs=r,fs}var ps={},hs={},bs={},Fr;function wn(){return Fr||(Fr=1,bs.isValid=function(r){return!isNaN(r)&&r>=1&&r<=40}),bs}var Pe={},$r;function kn(){if($r)return Pe;$r=1;const s="[0-9]+",r="[A-Z $%*+\\-./:]+";let o="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";o=o.replace(/u/g,"\\u");const n="(?:(?![A-Z0-9 $%*+\\-./:]|"+o+`)(?:.|[\r
|
|
2
|
-
]))+`;Pe.KANJI=new RegExp(o,"g"),Pe.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Pe.BYTE=new RegExp(n,"g"),Pe.NUMERIC=new RegExp(s,"g"),Pe.ALPHANUMERIC=new RegExp(r,"g");const a=new RegExp("^"+o+"$"),t=new RegExp("^"+s+"$"),d=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return Pe.testKanji=function(u){return a.test(u)},Pe.testNumeric=function(u){return t.test(u)},Pe.testAlphanumeric=function(u){return d.test(u)},Pe}var Vr;function Ve(){return Vr||(Vr=1,(function(s){const r=wn(),o=kn();s.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},s.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},s.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},s.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},s.MIXED={bit:-1},s.getCharCountIndicator=function(t,d){if(!t.ccBits)throw new Error("Invalid mode: "+t);if(!r.isValid(d))throw new Error("Invalid version: "+d);return d>=1&&d<10?t.ccBits[0]:d<27?t.ccBits[1]:t.ccBits[2]},s.getBestModeForData=function(t){return o.testNumeric(t)?s.NUMERIC:o.testAlphanumeric(t)?s.ALPHANUMERIC:o.testKanji(t)?s.KANJI:s.BYTE},s.toString=function(t){if(t&&t.id)return t.id;throw new Error("Invalid mode")},s.isValid=function(t){return t&&t.bit&&t.ccBits};function n(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return s.NUMERIC;case"alphanumeric":return s.ALPHANUMERIC;case"kanji":return s.KANJI;case"byte":return s.BYTE;default:throw new Error("Unknown mode: "+a)}}s.from=function(t,d){if(s.isValid(t))return t;try{return n(t)}catch{return d}}})(hs)),hs}var Hr;function Ca(){return Hr||(Hr=1,(function(s){const r=$e(),o=Nn(),n=_s(),a=Ve(),t=wn(),d=7973,c=r.getBCHDigit(d);function u(x,
|
|
3
|
-
Make sure your charset is UTF-8`);t=(t>>>8&255)*192+(t&255),n.put(t,13)}},ks=o,ks}var Cs={exports:{}},Jr;function Ea(){return Jr||(Jr=1,(function(s){var r={single_source_shortest_paths:function(o,n,a){var t={},d={};d[n]=0;var c=r.PriorityQueue.make();c.push(n,0);for(var u,
|
|
4
|
-
Suggested mode is: `+r.toString(
|
|
1
|
+
import{u as me,r as l,j as e,J as bn,F as ta,f as $,a as sa,at as kr,n as ss,P as rs,au as ra,av as Cr,h as Fe,aw as yn,w as na,ax as ns,ay as Rs,_ as aa}from"./index-CHkb08MZ.js";function oa(s,r){for(var o=0;o<r.length;o++){const n=r[o];if(typeof n!="string"&&!Array.isArray(n)){for(const a in n)if(a!=="default"&&!(a in s)){const t=Object.getOwnPropertyDescriptor(n,a);t&&Object.defineProperty(s,a,t.get?t:{enumerable:!0,get:()=>n[a]})}}}return Object.freeze(Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}))}function ia(s){return s>=1e6?`${(s/1e6).toFixed(s%1e6===0?0:1)}M`:s>=1e3?`${(s/1e3).toFixed((s%1e3===0,0))}K`:String(s)}function la(s){return s.maxInputTokens>0||s.inputCostPer1MTokens>0||s.outputCostPer1MTokens>0}function as(s){if(s.tier)return s.tier;const r=s.id.toLowerCase(),o=/opus|5\.4|o3-(?!mini)|o1-(?!mini)|gemini.*ultra|sonnet-4-20/,n=/haiku|flash|nano|lite|small|fast|free|8b|7b|1b|3b/;return/o4-mini|o3-mini|o1-mini|gpt-4o-mini/.test(r)?"pro":o.test(r)?"max":n.test(r)?"base":"pro"}const Sr={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30"};function vn({models:s,selectedModel:r,onSelect:o,loading:n,compact:a,maxVisible:t,showTiers:d}){const{t:c}=me("settings"),[u,f]=l.useState(""),[v,M]=l.useState(!1),[x,b]=l.useState(""),w=l.useMemo(()=>{let g=s;if(u){const p=u.toLowerCase();g=g.filter(N=>N.id.toLowerCase().includes(p))}return x&&(g=g.filter(p=>as(p)===x)),g},[s,u,x]),P=l.useMemo(()=>{const g={max:0,pro:0,base:0};for(const p of s)g[as(p)]++;return g},[s]),U=t??(a?5:10),j=v?w:w.slice(0,U),C=w.length>U;return n?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-tertiary",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),c("modelPicker.loading")]}):s.length===0?e.jsx("div",{className:"py-3 text-sm text-fg-tertiary",children:c("modelPicker.empty")}):e.jsxs("div",{className:"space-y-2",children:[d&&s.length>3&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>b(""),className:`px-2 py-0.5 rounded text-[10px] transition-colors ${x?"bg-surface-overlay text-fg-tertiary hover:text-fg-secondary":"bg-brand-500/20 text-brand-500"}`,children:c("modelPicker.allCount",{count:s.length})}),["max","pro","base"].filter(g=>P[g]>0).map(g=>e.jsx("button",{onClick:()=>b(x===g?"":g),className:`px-2 py-0.5 rounded text-[10px] font-medium uppercase transition-colors border ${x===g?Sr[g]:"border-transparent bg-surface-overlay text-fg-tertiary hover:text-fg-secondary"}`,children:c("modelPicker.tierCount",{tier:c(`modelRouting.tier.${g}`),count:P[g]})},g))]}),s.length>5&&e.jsx("input",{type:"text",value:u,onChange:g=>{f(g.target.value),M(!1)},placeholder:c("modelPicker.filterPlaceholder"),className:"w-full px-3 py-1.5 bg-surface-overlay border border-border-default rounded-lg text-xs text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:border-brand-500"}),e.jsx("div",{className:`space-y-1 ${a?"max-h-[280px] overflow-y-auto":""}`,children:j.map(g=>{const p=g.id===r,N=as(g);return e.jsxs("button",{type:"button",onClick:()=>o(g.id),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${p?"bg-brand-500/10 border border-brand-500/30":"hover:bg-surface-overlay border border-transparent"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${p?"border-brand-500":"border-border-default"}`,children:p&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),e.jsx("span",{className:`text-xs font-medium ${p?"text-brand-500":"text-fg-primary"}`,children:g.id}),d&&e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-semibold uppercase border ${Sr[N]}`,children:c(`modelRouting.tier.${N}`)})]}),e.jsx("div",{className:"flex items-center gap-2",children:p&&e.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:c("modelPicker.active")})})]}),la(g)&&g.maxInputTokens>0&&e.jsx("div",{className:"ml-5 mt-0.5 flex items-center gap-2 text-[10px] text-fg-tertiary flex-wrap",children:e.jsxs("span",{children:[ia(g.maxInputTokens)," ",c("modelPicker.ctx")]})}),!a&&e.jsxs("div",{className:"ml-5 mt-1 flex items-center gap-1.5 flex-wrap",children:[g.capabilities.functionCalling&&e.jsx(nt,{label:c("modelPicker.capabilities.tools")}),g.capabilities.vision&&e.jsx(nt,{label:c("modelPicker.capabilities.vision")}),g.capabilities.reasoning&&e.jsx(nt,{label:c("modelPicker.capabilities.reasoning")}),g.capabilities.promptCaching&&e.jsx(nt,{label:c("modelPicker.capabilities.caching")}),g.capabilities.webSearch&&e.jsx(nt,{label:c("modelPicker.capabilities.search")})]})]},g.id)})}),C&&!v&&e.jsx("button",{type:"button",onClick:()=>M(!0),className:"text-xs text-brand-500 hover:text-brand-400 px-3",children:c("modelPicker.showAll",{count:w.length})}),v&&C&&e.jsx("button",{type:"button",onClick:()=>M(!1),className:"text-xs text-fg-tertiary hover:text-fg-secondary px-3",children:c("modelPicker.showLess")})]})}function nt({label:s}){return e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] bg-surface-overlay text-fg-tertiary border border-border-default",children:s})}function Os({value:s,options:r,placeholder:o,onChange:n}){const{t:a}=me("settings"),[t,d]=l.useState(!1),[c,u]=l.useState(""),f=l.useRef(null),v=l.useRef(null),M=l.useRef(null),[x,b]=l.useState(-1);l.useEffect(()=>{function g(p){f.current&&!f.current.contains(p.target)&&d(!1)}return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[]),l.useEffect(()=>{t&&v.current&&v.current.focus()},[t]);const w=l.useMemo(()=>{if(!c.trim())return r;const g=c.toLowerCase();return r.filter(p=>p.modelId.toLowerCase().includes(g)||p.modelName.toLowerCase().includes(g)||p.provider.toLowerCase().includes(g)||p.providerLabel.toLowerCase().includes(g)||p.tier&&p.tier.toLowerCase().includes(g))},[r,c]),P=l.useMemo(()=>{const g=new Map;for(const N of w){const I=N.providerLabel;g.has(I)||g.set(I,[]),g.get(I).push(N)}const p={max:0,pro:1,base:2};for(const N of g.values())N.sort((I,B)=>(p[I.tier??"base"]??9)-(p[B.tier??"base"]??9));return g},[w]),U=l.useMemo(()=>{const g=[];for(const p of P.values())g.push(...p);return g},[P]),j=l.useMemo(()=>{if(!s)return o??a("modelRouting.auto");const g=r.find(p=>`${p.provider}/${p.modelId}`===s);return g?`${g.providerLabel}/${g.modelName}`:s},[s,r,o,a]);function C(g){if(!t){(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),d(!0));return}switch(g.key){case"ArrowDown":g.preventDefault(),b(p=>Math.min(p+1,U.length-1));break;case"ArrowUp":g.preventDefault(),b(p=>Math.max(p-1,-1));break;case"Enter":g.preventDefault(),x===-1?n(""):U[x]&&n(`${U[x].provider}/${U[x].modelId}`),d(!1),u("");break;case"Escape":d(!1),u("");break}}return l.useEffect(()=>{M.current&&x>=0&&M.current.querySelector(`[data-focus-index="${x}"]`)?.scrollIntoView({block:"nearest"})},[x]),e.jsxs("div",{ref:f,className:"relative",onKeyDown:C,children:[e.jsx("button",{type:"button",onClick:()=>{d(!t),u(""),b(-1)},className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary text-left truncate focus:outline-none focus:border-brand-500",children:j}),t&&e.jsxs("div",{className:"absolute z-50 mt-1 w-full min-w-[240px] max-h-[280px] bg-surface-elevated border border-border-default rounded-lg shadow-xl overflow-hidden flex flex-col",children:[e.jsx("div",{className:"p-1.5 border-b border-border-default",children:e.jsx("input",{ref:v,type:"text",value:c,onChange:g=>{u(g.target.value),b(-1)},placeholder:a("modelPicker.searchPlaceholder")||"Search models...",className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary focus:outline-none focus:border-brand-500"})}),e.jsxs("div",{ref:M,className:"overflow-y-auto flex-1",children:[e.jsx("div",{className:`px-3 py-1.5 text-xs cursor-pointer ${x===-1?"bg-brand-500/20 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,onClick:()=>{n(""),d(!1),u("")},children:o??a("modelRouting.auto")}),[...P.entries()].map(([g,p])=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider bg-surface-overlay/50 sticky top-0",children:g}),p.map(N=>{const I=U.indexOf(N),B=`${N.provider}/${N.modelId}`===s;return e.jsxs("div",{"data-focus-index":I,className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${I===x?"bg-brand-500/20":B?"bg-surface-overlay":"hover:bg-surface-overlay/50"}`,onClick:()=>{n(`${N.provider}/${N.modelId}`),d(!1),u("")},children:[e.jsx("span",{className:"flex-1 truncate text-fg-primary",children:N.modelName}),N.tier&&e.jsx(da,{tier:N.tier}),N.costTier&&e.jsx("span",{className:"text-[9px] text-fg-tertiary",children:N.costTier})]},`${N.provider}/${N.modelId}`)})]},g)),U.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:a("modelPicker.empty")})]})]})]})}function da({tier:s}){const r={max:"bg-purple-500/20 text-purple-400",pro:"bg-blue-500/20 text-blue-400",base:"bg-gray-500/20 text-gray-400"};return e.jsx("span",{className:`px-1 py-0.5 rounded text-[8px] font-bold uppercase ${r[s]??r.base}`,children:s})}const ca=500,Pr=[{groupKey:"image",capabilities:["image_recognition","image_generation"]},{groupKey:"audio",capabilities:["audio_tts","audio_stt"]},{groupKey:"video",capabilities:["video_generation"]}];function ua({onSave:s,configuredProviders:r}){const{t:o}=me(["settings","common"]),[n,a]=l.useState({}),[t,d]=l.useState(null),[c,u]=l.useState(!1),[f,v]=l.useState(null),[M,x]=l.useState("idle"),[b,w]=l.useState(null),[P,U]=l.useState({}),[j,C]=l.useState(!1),[g,p]=l.useState("idle"),[N,I]=l.useState(null),[B,F]=l.useState(!1),K=l.useRef(null),O=l.useRef(null),R=l.useMemo(()=>r.map(T=>T.name).sort().join(","),[r]);l.useEffect(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{a(T.capabilityRouting?.assignments??{}),d(T.routingDefaultModel??null),u(!0)}).catch(T=>{v(String(T)),u(!0)})},[R]),l.useEffect(()=>{fetch("/api/models/routing-candidates",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{const q=[];for(const V of T.providers)for(const m of V.models)q.push({provider:V.provider,providerLabel:V.displayName,modelId:m.id,modelName:m.name,mode:m.mode,tier:m.tier,costTier:m.costTier,capabilities:m.capabilities});w(q)}).catch(()=>w(null))},[R]),l.useEffect(()=>{fetch("/api/models/suggested-assignments",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{U(T.suggestions),C(!0)}).catch(()=>C(!0))},[R]);const L=l.useCallback(T=>{x("saving"),s(T).then(()=>{x("saved"),setTimeout(()=>x(q=>q==="saved"?"idle":q),2e3)}).catch(()=>{x("error"),setTimeout(()=>x(q=>q==="error"?"idle":q),3e3)})},[s]),h=l.useCallback((T,q)=>{O.current={capabilityRouting:T!==void 0?{assignments:T}:O.current?.capabilityRouting,routingDefaultModel:q!==void 0?q:O.current?.routingDefaultModel},K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{const V=O.current;O.current=null,V&&L(V)},ca)},[L]),S=l.useMemo(()=>r.flatMap(T=>(T.models??[{id:T.model,name:T.model}]).map(q=>({provider:T.name,providerLabel:T.displayName??T.name,modelId:q.id,modelName:q.name}))),[r]),_=b??S,z=l.useMemo(()=>Object.entries(n).map(([T,q])=>`${T}:${q?.provider??""}/${q?.model??""}`).sort().join("|"),[n]);l.useEffect(()=>{!c||!b||b.length===0||b.some(T=>!!T.modelId)&&(a(T=>{let q=!1;const V={...T};for(const m of Pr)for(const E of m.capabilities){const H=V[E];if(!H?.model)continue;const Z=jn(b,E);if(Z.length===0)continue;Z.some(X=>X.provider===H.provider&&X.modelId===H.model)||(delete V[E],q=!0)}return q?(h(V),V):T}),d(T=>{if(!T?.model||b.some(E=>E.provider===T.provider&&E.modelId===T.model))return T;const V=b.find(E=>E.provider==="markus"),m=V?{provider:V.provider,model:V.modelId}:{provider:b[0].provider,model:b[0].modelId};return s({routingDefaultModel:m}),m}))},[c,b,R,h,z]);const G=l.useCallback(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{a(T.capabilityRouting?.assignments??{}),d(T.routingDefaultModel??null)}).catch(()=>{}),fetch("/api/models/routing-candidates",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{const q=[];for(const V of T.providers)for(const m of V.models)q.push({provider:V.provider,providerLabel:V.displayName,modelId:m.id,modelName:m.name,mode:m.mode,tier:m.tier,costTier:m.costTier,capabilities:m.capabilities});w(q)}).catch(()=>{})},[]),ne=l.useCallback(async()=>{if(g!=="working"){p("working"),I(null);try{const T=await fetch("/api/settings/llm/restore-recommended",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}}),q=await T.json().catch(()=>({}));if(!T.ok||!q.ok)throw new Error(q.error??`HTTP ${T.status}`);q.capabilityRouting&&a(q.capabilityRouting.assignments??{}),q.routingDefaultModel!==void 0&&d(q.routingDefaultModel),G(),p("idle"),x("saved"),setTimeout(()=>x(V=>V==="saved"?"idle":V),2e3)}catch(T){p("error"),I(T instanceof Error?T.message:String(T)),setTimeout(()=>p("idle"),4e3)}}},[g,G]);return c?f?e.jsx("div",{className:"bg-red-500/10 border border-red-500/30 rounded-xl p-4 text-xs text-red-400",children:o("modelRouting.loadError",{error:f})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(ga,{status:M,t:o}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>F(!0),disabled:g==="working",className:"text-xs px-3 py-1.5 rounded-lg border border-border-default text-fg-secondary hover:text-fg-primary hover:border-brand-500/40 disabled:opacity-50 transition-colors",children:o(g==="working"?"modelRouting.restoreWorking":"modelRouting.restoreRecommended")}),N&&e.jsx("span",{className:"text-[10px] text-red-400 max-w-xs text-right",children:N})]})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:o("modelRouting.defaultModelTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:o("modelRouting.defaultModelDesc")})]}),e.jsx("div",{className:"max-w-md",children:e.jsx(Os,{value:t?`${t.provider}/${t.model}`:"",options:_,placeholder:o("modelRouting.defaultModelPlaceholder"),onChange:T=>{if(!T)d(null),h(void 0,null);else{const[q,...V]=T.split("/"),m={provider:q,model:V.join("/")};if(d(m),n.text){const E={...n};delete E.text,a(E),h(E,m)}else h(void 0,m)}}})})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:o("modelRouting.capabilityAssignTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:o("modelRouting.capabilityAssignDesc")})]}),r.length===0&&e.jsx("div",{className:"p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg text-xs text-yellow-400",children:o("modelRouting.noProvidersHint")}),r.length>0&&e.jsx("div",{className:"space-y-4",children:Pr.map(T=>e.jsx(xa,{groupKey:T.groupKey,capabilities:T.capabilities,assignments:n,suggestions:P,allModels:_,configuredProviderNames:new Set(r.map(q=>q.name)),t:o,onAssign:(q,V)=>{const m={...n};V?m[q]=V:delete m[q],a(m),h(m)}},T.groupKey))})]}),B&&e.jsx(bn,{variant:"primary",title:o("modelRouting.restoreRecommended"),message:o("modelRouting.restoreConfirm"),confirmLabel:o("common:confirm"),onConfirm:()=>{F(!1),ne()},onCancel:()=>F(!1)})]}):e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 animate-pulse",children:[e.jsx("div",{className:"h-4 bg-surface-overlay rounded w-1/3 mb-3"}),e.jsx("div",{className:"h-3 bg-surface-overlay rounded w-2/3 mb-4"}),e.jsx("div",{className:"space-y-2",children:[1,2,3,4,5].map(T=>e.jsx("div",{className:"h-10 bg-surface-overlay rounded-lg"},T))})]})})}function xa({groupKey:s,capabilities:r,assignments:o,suggestions:n,allModels:a,configuredProviderNames:t,t:d,onAssign:c}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 px-1",children:d(`modelRouting.capabilityGroups.${s}`)}),e.jsx("div",{className:"space-y-1",children:r.map(u=>{const f=o[u],v=n[u],M=f?`${f.provider}/${f.model}`:"",x=jn(a,u),b=v?x.find(C=>C.provider===v.provider&&C.modelId===v.model)?.modelName??v.model:void 0,w=x.length>0,P=f?ma(a,f.provider,f.model):void 0,U=f&&!t.has(f.provider),j=!!(f&&w&&u!=="text"&&!x.some(C=>C.provider===f.provider&&C.modelId===f.model));return e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2 rounded-lg ${j?"bg-red-500/10 border border-red-500/30":U?"bg-yellow-500/10 border border-yellow-500/30":!w&&!f?"bg-amber-500/5 border border-amber-500/20":"bg-surface-overlay/40"}`,children:[e.jsx("div",{className:"w-28 shrink-0",children:e.jsx("span",{className:"text-xs text-fg-primary",children:d(`modelRouting.capabilities.${u}`)})}),e.jsx("div",{className:"flex-1 min-w-0",children:j?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-xs text-red-400",children:["⚠ ",f.model]}),e.jsx("span",{className:"text-[10px] text-red-400/70",children:d("modelRouting.mismatchHint")})]}),e.jsx(Os,{value:"",options:x,placeholder:d("modelRouting.selectModel"),onChange:C=>{if(!C)c(u,null);else{const[g,...p]=C.split("/");c(u,{provider:g,model:p.join("/")})}}})]}):w?e.jsx(Os,{value:M,options:x,placeholder:b?`${b} (${d("modelRouting.suggested")})`:d("modelRouting.selectModel"),onChange:C=>{if(!C)c(u,null);else{const[g,...p]=C.split("/");c(u,{provider:g,model:p.join("/")})}}}):e.jsxs("span",{className:"text-xs text-amber-400",children:[d("modelRouting.noModelAvailable"),e.jsxs("span",{className:"text-fg-tertiary ml-1",children:["— ",d("modelRouting.addProviderHint")]})]})}),e.jsxs("div",{className:"w-14 shrink-0 flex justify-end",children:[j&&e.jsx("span",{className:"text-[10px] text-red-400 font-medium",title:d("modelRouting.mismatchHint"),children:"⚠"}),!j&&U&&e.jsx("span",{className:"text-[10px] text-yellow-400 font-medium",title:d("modelRouting.staleProvider"),children:"⚠"}),!j&&!U&&P&&e.jsx(Ar,{tier:P}),!j&&!U&&!P&&f&&e.jsx(Ar,{tier:"unknown"})]}),e.jsx("div",{className:"w-8 shrink-0 flex justify-end",children:f&&e.jsx("button",{onClick:()=>c(u,null),className:"text-fg-tertiary hover:text-red-400 transition-colors",title:d("modelRouting.clear"),children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]},u)})})]})}function ma(s,r,o){return s.find(a=>a.provider===r&&a.modelId===o)?.tier}function ga({status:s,t:r}){if(s==="idle")return null;const o={idle:"",saving:"text-fg-tertiary",saved:"text-green-400",error:"text-red-400"},n={idle:"",saving:r("modelRouting.saving"),saved:r("modelRouting.saved"),error:r("modelRouting.saveError")};return e.jsx("div",{className:`text-xs font-medium transition-opacity ${o[s]}`,children:n[s]})}function Ar({tier:s}){const r={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30",unknown:"bg-gray-500/10 text-fg-tertiary border-border-default"};return e.jsx("span",{className:`px-1.5 py-0.5 text-[9px] rounded font-semibold uppercase border ${r[s]??r.unknown}`,children:s==="unknown"?"—":s})}const fa=new Set(["imageGeneration","tts","stt","videoGeneration","audioOutput","audioInput"]);function jn(s,r){if(r==="text")return s.filter(d=>!(d.capabilities&&d.capabilities.some(c=>fa.has(c))||d.mode&&d.mode!=="chat"));const o={image_generation:["image_generation"],audio_tts:["audio_speech"],audio_stt:["audio_transcription"],video_generation:["video_generation"]},n={image_recognition:["vision"],image_generation:["imageGeneration"],audio_tts:["tts"],audio_stt:["stt"],video_generation:["videoGeneration"]},a=o[r],t=n[r];return s.filter(d=>!!(d.capabilities&&d.capabilities.length>0&&t&&t.some(c=>d.capabilities.includes(c))||a&&d.mode&&a.includes(d.mode)))}const Ct=[{id:"markus",label:"Markus Cloud AI",envKey:"MARKUS_SUBSCRIPTION_KEY",defaultModel:""},{id:"anthropic",label:"Anthropic",envKey:"ANTHROPIC_API_KEY",defaultModel:"claude-opus-4-6"},{id:"openai",label:"OpenAI",envKey:"OPENAI_API_KEY",defaultModel:"gpt-5.4"},{id:"google",label:"Google Gemini",envKey:"GOOGLE_API_KEY",defaultModel:"gemini-3-1-pro"},{id:"deepseek",label:"DeepSeek",envKey:"DEEPSEEK_API_KEY",baseUrl:"https://api.deepseek.com",defaultModel:"deepseek-v4-flash"},{id:"siliconflow",label:"SiliconFlow (中国)",envKey:"SILICONFLOW_API_KEY",baseUrl:"https://api.siliconflow.cn/v1",defaultModel:"Qwen/Qwen3.5-35B-A3B"},{id:"siliconflow-intl",label:"SiliconFlow (Global)",envKey:"SILICONFLOW_INTL_API_KEY",baseUrl:"https://api-st.siliconflow.cn/v1",defaultModel:"Qwen/Qwen3.5-35B-A3B"},{id:"minimax",label:"MiniMax (Global)",envKey:"MINIMAX_API_KEY",baseUrl:"https://api.minimax.io/v1",defaultModel:"MiniMax-M3"},{id:"minimax-cn",label:"MiniMax (中国)",envKey:"MINIMAX_CN_API_KEY",baseUrl:"https://api.minimaxi.com/v1",defaultModel:"MiniMax-M3"},{id:"openrouter",label:"OpenRouter",envKey:"OPENROUTER_API_KEY",baseUrl:"https://openrouter.ai/api/v1",defaultModel:"xiaomi/mimo-v2-pro:free"},{id:"zai",label:"ZAI (GLM)",envKey:"ZAI_API_KEY",baseUrl:"https://api.z.ai/api/paas/v4",defaultModel:"glm-5.1"},{id:"xai",label:"xAI (Grok)",envKey:"XAI_API_KEY",baseUrl:"https://api.x.ai/v1",defaultModel:"grok-3"},{id:"mistral",label:"Mistral AI",envKey:"MISTRAL_API_KEY",baseUrl:"https://api.mistral.ai/v1",defaultModel:"mistral-large-latest"},{id:"groq",label:"Groq",envKey:"GROQ_API_KEY",baseUrl:"https://api.groq.com/openai/v1",defaultModel:"llama-3.3-70b-versatile"},{id:"perplexity",label:"Perplexity",envKey:"PERPLEXITY_API_KEY",baseUrl:"https://api.perplexity.ai",defaultModel:"sonar-pro"},{id:"cohere",label:"Cohere",envKey:"COHERE_API_KEY",baseUrl:"https://api.cohere.ai/compatibility/v1",defaultModel:"command-r-plus"},{id:"together_ai",label:"Together AI",envKey:"TOGETHER_API_KEY",baseUrl:"https://api.together.xyz/v1",defaultModel:"meta-llama/Llama-3.3-70B-Instruct-Turbo"},{id:"fireworks_ai",label:"Fireworks AI",envKey:"FIREWORKS_API_KEY",baseUrl:"https://api.fireworks.ai/inference/v1",defaultModel:"accounts/fireworks/models/llama-v3p3-70b-instruct"},{id:"moonshot",label:"Moonshot (Kimi)",envKey:"MOONSHOT_API_KEY",baseUrl:"https://api.moonshot.cn/v1",defaultModel:"moonshot-v1-auto"},{id:"volcengine",label:"Volcengine (Doubao)",envKey:"VOLCENGINE_API_KEY",baseUrl:"https://ark.cn-beijing.volces.com/api/v3",defaultModel:"doubao-1.5-pro-32k"},{id:"dashscope",label:"DashScope (Qwen)",envKey:"DASHSCOPE_API_KEY",baseUrl:"https://dashscope.aliyuncs.com/compatible-mode/v1",defaultModel:"qwen-max"},{id:"ollama",label:"Ollama (Local)",envKey:"OLLAMA_BASE_URL",baseUrl:"http://localhost:11434/v1",defaultModel:"llama3"},{id:"atlascloud",label:"Atlas Cloud (Full-Modal)",envKey:"ATLASCLOUD_API_KEY",baseUrl:"https://api.atlascloud.ai/v1",defaultModel:"claude-sonnet-4-6"},{id:"strongly",label:"Strongly.AI (Full-Modal)",envKey:"STRONGLY_API_KEY",baseUrl:"https://api.strongly.ai/v1",defaultModel:"claude-sonnet-4-6"}];var Ye={},os,Mr;function pa(){return Mr||(Mr=1,os=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),os}var is={},De={},Tr;function $e(){if(Tr)return De;Tr=1;let s;const r=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return De.getSymbolSize=function(n){if(!n)throw new Error('"version" cannot be null or undefined');if(n<1||n>40)throw new Error('"version" should be in range from 1 to 40');return n*4+17},De.getSymbolTotalCodewords=function(n){return r[n]},De.getBCHDigit=function(o){let n=0;for(;o!==0;)n++,o>>>=1;return n},De.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');s=n},De.isKanjiModeEnabled=function(){return typeof s<"u"},De.toSJIS=function(n){return s(n)},De}var ls={},Er;function _s(){return Er||(Er=1,(function(s){s.L={bit:1},s.M={bit:0},s.Q={bit:3},s.H={bit:2};function r(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"l":case"low":return s.L;case"m":case"medium":return s.M;case"q":case"quartile":return s.Q;case"h":case"high":return s.H;default:throw new Error("Unknown EC Level: "+o)}}s.isValid=function(n){return n&&typeof n.bit<"u"&&n.bit>=0&&n.bit<4},s.from=function(n,a){if(s.isValid(n))return n;try{return r(n)}catch{return a}}})(ls)),ls}var ds,Ir;function ha(){if(Ir)return ds;Ir=1;function s(){this.buffer=[],this.length=0}return s.prototype={get:function(r){const o=Math.floor(r/8);return(this.buffer[o]>>>7-r%8&1)===1},put:function(r,o){for(let n=0;n<o;n++)this.putBit((r>>>o-n-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(r){const o=Math.floor(this.length/8);this.buffer.length<=o&&this.buffer.push(0),r&&(this.buffer[o]|=128>>>this.length%8),this.length++}},ds=s,ds}var cs,Lr;function ba(){if(Lr)return cs;Lr=1;function s(r){if(!r||r<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=r,this.data=new Uint8Array(r*r),this.reservedBit=new Uint8Array(r*r)}return s.prototype.set=function(r,o,n,a){const t=r*this.size+o;this.data[t]=n,a&&(this.reservedBit[t]=!0)},s.prototype.get=function(r,o){return this.data[r*this.size+o]},s.prototype.xor=function(r,o,n){this.data[r*this.size+o]^=n},s.prototype.isReserved=function(r,o){return this.reservedBit[r*this.size+o]},cs=s,cs}var us={},Rr;function ya(){return Rr||(Rr=1,(function(s){const r=$e().getSymbolSize;s.getRowColCoords=function(n){if(n===1)return[];const a=Math.floor(n/7)+2,t=r(n),d=t===145?26:Math.ceil((t-13)/(2*a-2))*2,c=[t-7];for(let u=1;u<a-1;u++)c[u]=c[u-1]-d;return c.push(6),c.reverse()},s.getPositions=function(n){const a=[],t=s.getRowColCoords(n),d=t.length;for(let c=0;c<d;c++)for(let u=0;u<d;u++)c===0&&u===0||c===0&&u===d-1||c===d-1&&u===0||a.push([t[c],t[u]]);return a}})(us)),us}var xs={},Or;function va(){if(Or)return xs;Or=1;const s=$e().getSymbolSize,r=7;return xs.getPositions=function(n){const a=s(n);return[[0,0],[a-r,0],[0,a-r]]},xs}var ms={},Br;function ja(){return Br||(Br=1,(function(s){s.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const r={N1:3,N2:3,N3:40,N4:10};s.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},s.from=function(a){return s.isValid(a)?parseInt(a,10):void 0},s.getPenaltyN1=function(a){const t=a.size;let d=0,c=0,u=0,f=null,v=null;for(let M=0;M<t;M++){c=u=0,f=v=null;for(let x=0;x<t;x++){let b=a.get(M,x);b===f?c++:(c>=5&&(d+=r.N1+(c-5)),f=b,c=1),b=a.get(x,M),b===v?u++:(u>=5&&(d+=r.N1+(u-5)),v=b,u=1)}c>=5&&(d+=r.N1+(c-5)),u>=5&&(d+=r.N1+(u-5))}return d},s.getPenaltyN2=function(a){const t=a.size;let d=0;for(let c=0;c<t-1;c++)for(let u=0;u<t-1;u++){const f=a.get(c,u)+a.get(c,u+1)+a.get(c+1,u)+a.get(c+1,u+1);(f===4||f===0)&&d++}return d*r.N2},s.getPenaltyN3=function(a){const t=a.size;let d=0,c=0,u=0;for(let f=0;f<t;f++){c=u=0;for(let v=0;v<t;v++)c=c<<1&2047|a.get(f,v),v>=10&&(c===1488||c===93)&&d++,u=u<<1&2047|a.get(v,f),v>=10&&(u===1488||u===93)&&d++}return d*r.N3},s.getPenaltyN4=function(a){let t=0;const d=a.data.length;for(let u=0;u<d;u++)t+=a.data[u];return Math.abs(Math.ceil(t*100/d/5)-10)*r.N4};function o(n,a,t){switch(n){case s.Patterns.PATTERN000:return(a+t)%2===0;case s.Patterns.PATTERN001:return a%2===0;case s.Patterns.PATTERN010:return t%3===0;case s.Patterns.PATTERN011:return(a+t)%3===0;case s.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(t/3))%2===0;case s.Patterns.PATTERN101:return a*t%2+a*t%3===0;case s.Patterns.PATTERN110:return(a*t%2+a*t%3)%2===0;case s.Patterns.PATTERN111:return(a*t%3+(a+t)%2)%2===0;default:throw new Error("bad maskPattern:"+n)}}s.applyMask=function(a,t){const d=t.size;for(let c=0;c<d;c++)for(let u=0;u<d;u++)t.isReserved(u,c)||t.xor(u,c,o(a,u,c))},s.getBestMask=function(a,t){const d=Object.keys(s.Patterns).length;let c=0,u=1/0;for(let f=0;f<d;f++){t(f),s.applyMask(f,a);const v=s.getPenaltyN1(a)+s.getPenaltyN2(a)+s.getPenaltyN3(a)+s.getPenaltyN4(a);s.applyMask(f,a),v<u&&(u=v,c=f)}return c}})(ms)),ms}var St={},_r;function Nn(){if(_r)return St;_r=1;const s=_s(),r=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],o=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return St.getBlocksCount=function(a,t){switch(t){case s.L:return r[(a-1)*4+0];case s.M:return r[(a-1)*4+1];case s.Q:return r[(a-1)*4+2];case s.H:return r[(a-1)*4+3];default:return}},St.getTotalCodewordsCount=function(a,t){switch(t){case s.L:return o[(a-1)*4+0];case s.M:return o[(a-1)*4+1];case s.Q:return o[(a-1)*4+2];case s.H:return o[(a-1)*4+3];default:return}},St}var gs={},at={},Dr;function Na(){if(Dr)return at;Dr=1;const s=new Uint8Array(512),r=new Uint8Array(256);return(function(){let n=1;for(let a=0;a<255;a++)s[a]=n,r[n]=a,n<<=1,n&256&&(n^=285);for(let a=255;a<512;a++)s[a]=s[a-255]})(),at.log=function(n){if(n<1)throw new Error("log("+n+")");return r[n]},at.exp=function(n){return s[n]},at.mul=function(n,a){return n===0||a===0?0:s[r[n]+r[a]]},at}var Kr;function wa(){return Kr||(Kr=1,(function(s){const r=Na();s.mul=function(n,a){const t=new Uint8Array(n.length+a.length-1);for(let d=0;d<n.length;d++)for(let c=0;c<a.length;c++)t[d+c]^=r.mul(n[d],a[c]);return t},s.mod=function(n,a){let t=new Uint8Array(n);for(;t.length-a.length>=0;){const d=t[0];for(let u=0;u<a.length;u++)t[u]^=r.mul(a[u],d);let c=0;for(;c<t.length&&t[c]===0;)c++;t=t.slice(c)}return t},s.generateECPolynomial=function(n){let a=new Uint8Array([1]);for(let t=0;t<n;t++)a=s.mul(a,new Uint8Array([1,r.exp(t)]));return a}})(gs)),gs}var fs,Ur;function ka(){if(Ur)return fs;Ur=1;const s=wa();function r(o){this.genPoly=void 0,this.degree=o,this.degree&&this.initialize(this.degree)}return r.prototype.initialize=function(n){this.degree=n,this.genPoly=s.generateECPolynomial(this.degree)},r.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const a=new Uint8Array(n.length+this.degree);a.set(n);const t=s.mod(a,this.genPoly),d=this.degree-t.length;if(d>0){const c=new Uint8Array(this.degree);return c.set(t,d),c}return t},fs=r,fs}var ps={},hs={},bs={},Fr;function wn(){return Fr||(Fr=1,bs.isValid=function(r){return!isNaN(r)&&r>=1&&r<=40}),bs}var Pe={},$r;function kn(){if($r)return Pe;$r=1;const s="[0-9]+",r="[A-Z $%*+\\-./:]+";let o="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";o=o.replace(/u/g,"\\u");const n="(?:(?![A-Z0-9 $%*+\\-./:]|"+o+`)(?:.|[\r
|
|
2
|
+
]))+`;Pe.KANJI=new RegExp(o,"g"),Pe.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Pe.BYTE=new RegExp(n,"g"),Pe.NUMERIC=new RegExp(s,"g"),Pe.ALPHANUMERIC=new RegExp(r,"g");const a=new RegExp("^"+o+"$"),t=new RegExp("^"+s+"$"),d=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return Pe.testKanji=function(u){return a.test(u)},Pe.testNumeric=function(u){return t.test(u)},Pe.testAlphanumeric=function(u){return d.test(u)},Pe}var Vr;function Ve(){return Vr||(Vr=1,(function(s){const r=wn(),o=kn();s.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},s.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},s.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},s.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},s.MIXED={bit:-1},s.getCharCountIndicator=function(t,d){if(!t.ccBits)throw new Error("Invalid mode: "+t);if(!r.isValid(d))throw new Error("Invalid version: "+d);return d>=1&&d<10?t.ccBits[0]:d<27?t.ccBits[1]:t.ccBits[2]},s.getBestModeForData=function(t){return o.testNumeric(t)?s.NUMERIC:o.testAlphanumeric(t)?s.ALPHANUMERIC:o.testKanji(t)?s.KANJI:s.BYTE},s.toString=function(t){if(t&&t.id)return t.id;throw new Error("Invalid mode")},s.isValid=function(t){return t&&t.bit&&t.ccBits};function n(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return s.NUMERIC;case"alphanumeric":return s.ALPHANUMERIC;case"kanji":return s.KANJI;case"byte":return s.BYTE;default:throw new Error("Unknown mode: "+a)}}s.from=function(t,d){if(s.isValid(t))return t;try{return n(t)}catch{return d}}})(hs)),hs}var Hr;function Ca(){return Hr||(Hr=1,(function(s){const r=$e(),o=Nn(),n=_s(),a=Ve(),t=wn(),d=7973,c=r.getBCHDigit(d);function u(x,b,w){for(let P=1;P<=40;P++)if(b<=s.getCapacity(P,w,x))return P}function f(x,b){return a.getCharCountIndicator(x,b)+4}function v(x,b){let w=0;return x.forEach(function(P){const U=f(P.mode,b);w+=U+P.getBitsLength()}),w}function M(x,b){for(let w=1;w<=40;w++)if(v(x,w)<=s.getCapacity(w,b,a.MIXED))return w}s.from=function(b,w){return t.isValid(b)?parseInt(b,10):w},s.getCapacity=function(b,w,P){if(!t.isValid(b))throw new Error("Invalid QR Code version");typeof P>"u"&&(P=a.BYTE);const U=r.getSymbolTotalCodewords(b),j=o.getTotalCodewordsCount(b,w),C=(U-j)*8;if(P===a.MIXED)return C;const g=C-f(P,b);switch(P){case a.NUMERIC:return Math.floor(g/10*3);case a.ALPHANUMERIC:return Math.floor(g/11*2);case a.KANJI:return Math.floor(g/13);case a.BYTE:default:return Math.floor(g/8)}},s.getBestVersionForData=function(b,w){let P;const U=n.from(w,n.M);if(Array.isArray(b)){if(b.length>1)return M(b,U);if(b.length===0)return 1;P=b[0]}else P=b;return u(P.mode,P.getLength(),U)},s.getEncodedBits=function(b){if(!t.isValid(b)||b<7)throw new Error("Invalid QR Code version");let w=b<<12;for(;r.getBCHDigit(w)-c>=0;)w^=d<<r.getBCHDigit(w)-c;return b<<12|w}})(ps)),ps}var ys={},qr;function Sa(){if(qr)return ys;qr=1;const s=$e(),r=1335,o=21522,n=s.getBCHDigit(r);return ys.getEncodedBits=function(t,d){const c=t.bit<<3|d;let u=c<<10;for(;s.getBCHDigit(u)-n>=0;)u^=r<<s.getBCHDigit(u)-n;return(c<<10|u)^o},ys}var vs={},js,zr;function Pa(){if(zr)return js;zr=1;const s=Ve();function r(o){this.mode=s.NUMERIC,this.data=o.toString()}return r.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(n){let a,t,d;for(a=0;a+3<=this.data.length;a+=3)t=this.data.substr(a,3),d=parseInt(t,10),n.put(d,10);const c=this.data.length-a;c>0&&(t=this.data.substr(a),d=parseInt(t,10),n.put(d,c*3+1))},js=r,js}var Ns,Wr;function Aa(){if(Wr)return Ns;Wr=1;const s=Ve(),r=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function o(n){this.mode=s.ALPHANUMERIC,this.data=n}return o.getBitsLength=function(a){return 11*Math.floor(a/2)+6*(a%2)},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(a){let t;for(t=0;t+2<=this.data.length;t+=2){let d=r.indexOf(this.data[t])*45;d+=r.indexOf(this.data[t+1]),a.put(d,11)}this.data.length%2&&a.put(r.indexOf(this.data[t]),6)},Ns=o,Ns}var ws,Gr;function Ma(){if(Gr)return ws;Gr=1;const s=Ve();function r(o){this.mode=s.BYTE,typeof o=="string"?this.data=new TextEncoder().encode(o):this.data=new Uint8Array(o)}return r.getBitsLength=function(n){return n*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(o){for(let n=0,a=this.data.length;n<a;n++)o.put(this.data[n],8)},ws=r,ws}var ks,Yr;function Ta(){if(Yr)return ks;Yr=1;const s=Ve(),r=$e();function o(n){this.mode=s.KANJI,this.data=n}return o.getBitsLength=function(a){return a*13},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(n){let a;for(a=0;a<this.data.length;a++){let t=r.toSJIS(this.data[a]);if(t>=33088&&t<=40956)t-=33088;else if(t>=57408&&t<=60351)t-=49472;else throw new Error("Invalid SJIS character: "+this.data[a]+`
|
|
3
|
+
Make sure your charset is UTF-8`);t=(t>>>8&255)*192+(t&255),n.put(t,13)}},ks=o,ks}var Cs={exports:{}},Jr;function Ea(){return Jr||(Jr=1,(function(s){var r={single_source_shortest_paths:function(o,n,a){var t={},d={};d[n]=0;var c=r.PriorityQueue.make();c.push(n,0);for(var u,f,v,M,x,b,w,P,U;!c.empty();){u=c.pop(),f=u.value,M=u.cost,x=o[f]||{};for(v in x)x.hasOwnProperty(v)&&(b=x[v],w=M+b,P=d[v],U=typeof d[v]>"u",(U||P>w)&&(d[v]=w,c.push(v,w),t[v]=f))}if(typeof a<"u"&&typeof d[a]>"u"){var j=["Could not find a path from ",n," to ",a,"."].join("");throw new Error(j)}return t},extract_shortest_path_from_predecessor_list:function(o,n){for(var a=[],t=n;t;)a.push(t),o[t],t=o[t];return a.reverse(),a},find_path:function(o,n,a){var t=r.single_source_shortest_paths(o,n,a);return r.extract_shortest_path_from_predecessor_list(t,a)},PriorityQueue:{make:function(o){var n=r.PriorityQueue,a={},t;o=o||{};for(t in n)n.hasOwnProperty(t)&&(a[t]=n[t]);return a.queue=[],a.sorter=o.sorter||n.default_sorter,a},default_sorter:function(o,n){return o.cost-n.cost},push:function(o,n){var a={value:o,cost:n};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};s.exports=r})(Cs)),Cs.exports}var Qr;function Ia(){return Qr||(Qr=1,(function(s){const r=Ve(),o=Pa(),n=Aa(),a=Ma(),t=Ta(),d=kn(),c=$e(),u=Ea();function f(j){return unescape(encodeURIComponent(j)).length}function v(j,C,g){const p=[];let N;for(;(N=j.exec(g))!==null;)p.push({data:N[0],index:N.index,mode:C,length:N[0].length});return p}function M(j){const C=v(d.NUMERIC,r.NUMERIC,j),g=v(d.ALPHANUMERIC,r.ALPHANUMERIC,j);let p,N;return c.isKanjiModeEnabled()?(p=v(d.BYTE,r.BYTE,j),N=v(d.KANJI,r.KANJI,j)):(p=v(d.BYTE_KANJI,r.BYTE,j),N=[]),C.concat(g,p,N).sort(function(B,F){return B.index-F.index}).map(function(B){return{data:B.data,mode:B.mode,length:B.length}})}function x(j,C){switch(C){case r.NUMERIC:return o.getBitsLength(j);case r.ALPHANUMERIC:return n.getBitsLength(j);case r.KANJI:return t.getBitsLength(j);case r.BYTE:return a.getBitsLength(j)}}function b(j){return j.reduce(function(C,g){const p=C.length-1>=0?C[C.length-1]:null;return p&&p.mode===g.mode?(C[C.length-1].data+=g.data,C):(C.push(g),C)},[])}function w(j){const C=[];for(let g=0;g<j.length;g++){const p=j[g];switch(p.mode){case r.NUMERIC:C.push([p,{data:p.data,mode:r.ALPHANUMERIC,length:p.length},{data:p.data,mode:r.BYTE,length:p.length}]);break;case r.ALPHANUMERIC:C.push([p,{data:p.data,mode:r.BYTE,length:p.length}]);break;case r.KANJI:C.push([p,{data:p.data,mode:r.BYTE,length:f(p.data)}]);break;case r.BYTE:C.push([{data:p.data,mode:r.BYTE,length:f(p.data)}])}}return C}function P(j,C){const g={},p={start:{}};let N=["start"];for(let I=0;I<j.length;I++){const B=j[I],F=[];for(let K=0;K<B.length;K++){const O=B[K],R=""+I+K;F.push(R),g[R]={node:O,lastCount:0},p[R]={};for(let L=0;L<N.length;L++){const h=N[L];g[h]&&g[h].node.mode===O.mode?(p[h][R]=x(g[h].lastCount+O.length,O.mode)-x(g[h].lastCount,O.mode),g[h].lastCount+=O.length):(g[h]&&(g[h].lastCount=O.length),p[h][R]=x(O.length,O.mode)+4+r.getCharCountIndicator(O.mode,C))}}N=F}for(let I=0;I<N.length;I++)p[N[I]].end=0;return{map:p,table:g}}function U(j,C){let g;const p=r.getBestModeForData(j);if(g=r.from(C,p),g!==r.BYTE&&g.bit<p.bit)throw new Error('"'+j+'" cannot be encoded with mode '+r.toString(g)+`.
|
|
4
|
+
Suggested mode is: `+r.toString(p));switch(g===r.KANJI&&!c.isKanjiModeEnabled()&&(g=r.BYTE),g){case r.NUMERIC:return new o(j);case r.ALPHANUMERIC:return new n(j);case r.KANJI:return new t(j);case r.BYTE:return new a(j)}}s.fromArray=function(C){return C.reduce(function(g,p){return typeof p=="string"?g.push(U(p,null)):p.data&&g.push(U(p.data,p.mode)),g},[])},s.fromString=function(C,g){const p=M(C,c.isKanjiModeEnabled()),N=w(p),I=P(N,g),B=u.find_path(I.map,"start","end"),F=[];for(let K=1;K<B.length-1;K++)F.push(I.table[B[K]].node);return s.fromArray(b(F))},s.rawSplit=function(C){return s.fromArray(M(C,c.isKanjiModeEnabled()))}})(vs)),vs}var Xr;function La(){if(Xr)return is;Xr=1;const s=$e(),r=_s(),o=ha(),n=ba(),a=ya(),t=va(),d=ja(),c=Nn(),u=ka(),f=Ca(),v=Sa(),M=Ve(),x=Ia();function b(I,B){const F=I.size,K=t.getPositions(B);for(let O=0;O<K.length;O++){const R=K[O][0],L=K[O][1];for(let h=-1;h<=7;h++)if(!(R+h<=-1||F<=R+h))for(let S=-1;S<=7;S++)L+S<=-1||F<=L+S||(h>=0&&h<=6&&(S===0||S===6)||S>=0&&S<=6&&(h===0||h===6)||h>=2&&h<=4&&S>=2&&S<=4?I.set(R+h,L+S,!0,!0):I.set(R+h,L+S,!1,!0))}}function w(I){const B=I.size;for(let F=8;F<B-8;F++){const K=F%2===0;I.set(F,6,K,!0),I.set(6,F,K,!0)}}function P(I,B){const F=a.getPositions(B);for(let K=0;K<F.length;K++){const O=F[K][0],R=F[K][1];for(let L=-2;L<=2;L++)for(let h=-2;h<=2;h++)L===-2||L===2||h===-2||h===2||L===0&&h===0?I.set(O+L,R+h,!0,!0):I.set(O+L,R+h,!1,!0)}}function U(I,B){const F=I.size,K=f.getEncodedBits(B);let O,R,L;for(let h=0;h<18;h++)O=Math.floor(h/3),R=h%3+F-8-3,L=(K>>h&1)===1,I.set(O,R,L,!0),I.set(R,O,L,!0)}function j(I,B,F){const K=I.size,O=v.getEncodedBits(B,F);let R,L;for(R=0;R<15;R++)L=(O>>R&1)===1,R<6?I.set(R,8,L,!0):R<8?I.set(R+1,8,L,!0):I.set(K-15+R,8,L,!0),R<8?I.set(8,K-R-1,L,!0):R<9?I.set(8,15-R-1+1,L,!0):I.set(8,15-R-1,L,!0);I.set(K-8,8,1,!0)}function C(I,B){const F=I.size;let K=-1,O=F-1,R=7,L=0;for(let h=F-1;h>0;h-=2)for(h===6&&h--;;){for(let S=0;S<2;S++)if(!I.isReserved(O,h-S)){let _=!1;L<B.length&&(_=(B[L]>>>R&1)===1),I.set(O,h-S,_),R--,R===-1&&(L++,R=7)}if(O+=K,O<0||F<=O){O-=K,K=-K;break}}}function g(I,B,F){const K=new o;F.forEach(function(S){K.put(S.mode.bit,4),K.put(S.getLength(),M.getCharCountIndicator(S.mode,I)),S.write(K)});const O=s.getSymbolTotalCodewords(I),R=c.getTotalCodewordsCount(I,B),L=(O-R)*8;for(K.getLengthInBits()+4<=L&&K.put(0,4);K.getLengthInBits()%8!==0;)K.putBit(0);const h=(L-K.getLengthInBits())/8;for(let S=0;S<h;S++)K.put(S%2?17:236,8);return p(K,I,B)}function p(I,B,F){const K=s.getSymbolTotalCodewords(B),O=c.getTotalCodewordsCount(B,F),R=K-O,L=c.getBlocksCount(B,F),h=K%L,S=L-h,_=Math.floor(K/L),z=Math.floor(R/L),G=z+1,ne=_-z,T=new u(ne);let q=0;const V=new Array(L),m=new Array(L);let E=0;const H=new Uint8Array(I.buffer);for(let le=0;le<L;le++){const Ee=le<S?z:G;V[le]=H.slice(q,q+Ee),m[le]=T.encode(V[le]),q+=Ee,E=Math.max(E,Ee)}const Z=new Uint8Array(K);let ee=0,X,Q;for(X=0;X<E;X++)for(Q=0;Q<L;Q++)X<V[Q].length&&(Z[ee++]=V[Q][X]);for(X=0;X<ne;X++)for(Q=0;Q<L;Q++)Z[ee++]=m[Q][X];return Z}function N(I,B,F,K){let O;if(Array.isArray(I))O=x.fromArray(I);else if(typeof I=="string"){let _=B;if(!_){const z=x.rawSplit(I);_=f.getBestVersionForData(z,F)}O=x.fromString(I,_||40)}else throw new Error("Invalid data");const R=f.getBestVersionForData(O,F);if(!R)throw new Error("The amount of data is too big to be stored in a QR Code");if(!B)B=R;else if(B<R)throw new Error(`
|
|
5
5
|
The chosen QR Code version cannot contain this amount of data.
|
|
6
6
|
Minimum version required to store current data is: `+R+`.
|
|
7
|
-
`);const
|
|
8
|
-
`;return typeof c=="function"&&c(null,K),K},As}var sn;function Ba(){if(sn)return Ye;sn=1;const s=pa(),r=La(),o=Ra(),n=Oa();function a(t,d,c,u,p){const y=[].slice.call(arguments,1),T=y.length,x=typeof y[T-1]=="function";if(!x&&!s())throw new Error("Callback required as last argument");if(x){if(T<2)throw new Error("Too few arguments provided");T===2?(p=c,c=d,d=u=void 0):T===3&&(d.getContext&&typeof p>"u"?(p=u,u=void 0):(p=u,u=c,c=d,d=void 0))}else{if(T<1)throw new Error("Too few arguments provided");return T===1?(c=d,d=u=void 0):T===2&&!d.getContext&&(u=c,c=d,d=void 0),new Promise(function(v,w){try{const A=r.create(c,u);v(t(A,d,u))}catch(A){w(A)}})}try{const v=r.create(c,u);p(null,t(v,d,u))}catch(v){p(v)}}return Ye.create=r.create,Ye.toCanvas=a.bind(null,o.render),Ye.toDataURL=a.bind(null,o.renderToDataURL),Ye.toString=a.bind(null,function(t,d,c){return n.render(t,c)}),Ye}var Sn=Ba();const Pn=ta(Sn),_a=oa({__proto__:null,default:Pn},[Sn]),rn={appId:"",appSecret:"",enabled:!1,connected:!1,notifyChatId:"",notifyOnApproval:!0,notifyOnNotification:!1,notifyPriority:["high","urgent"]},Da=[{value:"normal",color:"bg-green-400"},{value:"low",color:"bg-gray-400"},{value:"medium",color:"bg-blue-400"},{value:"high",color:"bg-amber-400"},{value:"urgent",color:"bg-red-400"}];function Ka({connected:s}){return e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${s?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-gray-500/10 text-gray-500 border border-gray-500/30"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${s?"bg-green-500 animate-pulse":"bg-gray-400"}`}),s?"Connected":"Disconnected"]})}function ot({title:s,children:r}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary uppercase tracking-wider",children:s}),r]})}function nn({type:s,text:r}){return e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${s==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-600 border border-red-500/30"}`,children:[s==="ok"?e.jsx("svg",{className:"w-4 h-4 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):e.jsx("svg",{className:"w-4 h-4 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),r]})}function Ua(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(rn),[n,a]=l.useState(!0),[t,d]=l.useState(!1),[c,u]=l.useState(!1),[p,y]=l.useState(!1),[T,x]=l.useState(null),[v,w]=l.useState(""),[A,K]=l.useState([]),[j,S]=l.useState(!1),[g,h]=l.useState("idle"),[N,E]=l.useState(null),[O,U]=l.useState(null),[_,D]=l.useState(0),R=l.useRef(null),P=l.useRef(null),[f,k]=l.useState(!1),[$,J]=l.useState(!1),Z=l.useRef(null),ne=l.useRef(r);ne.current=r;const I=l.useRef(!1),H=l.useCallback(async()=>{S(!0);try{const M=await F.settings.listFeishuChats();K(M.chats??[])}catch{}finally{S(!1)}},[]),q=l.useCallback(async()=>{a(!0);try{const M=await F.settings.getFeishuIntegration();M&&(o({appId:M.appId??"",appSecret:M.appSecret??"",enabled:M.enabled??!1,connected:M.connected??!1,notifyChatId:M.notifyChatId??"",notifyOnApproval:M.notifyOnApproval??!0,notifyOnNotification:M.notifyOnNotification??!1,notifyPriority:M.notifyPriority??["high","urgent"]}),M.appId&&M.appSecret&&H())}catch{}finally{a(!1),I.current=!0}},[]);l.useEffect(()=>{q()},[q]),l.useEffect(()=>()=>{R.current&&clearInterval(R.current)},[]);const m=l.useCallback(async M=>{if(!(!M.appId||!M.appSecret)){d(!0);try{const ie=await F.settings.saveFeishuIntegration({appId:M.appId,appSecret:M.appSecret,enabled:M.enabled,notifyChatId:M.notifyChatId||void 0,notifyOnApproval:M.notifyOnApproval,notifyOnNotification:M.notifyOnNotification,notifyPriority:M.notifyPriority});ie.connected!==void 0&&o(ue=>({...ue,connected:ie.connected})),x({type:"ok",text:s("settings:feishu.saved",{defaultValue:"Saved"})}),setTimeout(()=>x(ue=>ue?.type==="ok"?null:ue),2e3)}catch(ie){x({type:"err",text:String(ie instanceof Error?ie.message:ie)})}finally{d(!1)}}},[s]),L=l.useCallback(()=>{I.current&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{m(ne.current)},600))},[m]),V=(M,ie)=>{o(ue=>({...ue,[M]:ie})),x(null),L()},X=(M,ie)=>{o(ue=>{const Ke={...ue,[M]:ie};return ne.current=Ke,Ke}),x(null),Z.current&&clearTimeout(Z.current),m({...ne.current,[M]:ie})},ee=M=>{o(ie=>{const ue=ie.notifyPriority,Ke=ue.includes(M)?ue.filter(Se=>Se!==M):[...ue,M],qe={...ie,notifyPriority:Ke};return ne.current=qe,qe}),x(null),Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{m(ne.current)},300)},Q=async()=>{h("waiting_qr"),E(null),U(null),x(null),R.current=setInterval(async()=>{try{const M=await F.settings.getFeishuRegisterStatus();if(M.active&&M.url){E(M.url),D(M.expireIn??300),h("scanning");try{const ie=await Pn.toDataURL(M.url,{width:200,margin:2,color:{dark:"#000000",light:"#ffffff"}});U(ie)}catch{}}}catch{}},1e3);try{const M=await F.settings.registerFeishuApp();R.current&&(clearInterval(R.current),R.current=null),M.success&&M.appId?(h("done"),x({type:"ok",text:s("settings:feishu.registerSuccess",{defaultValue:"App created successfully! Integration is now active."})}),await q()):(h("error"),x({type:"err",text:M.message||s("settings:feishu.registerFailed",{defaultValue:"Registration failed"})}))}catch(M){R.current&&(clearInterval(R.current),R.current=null),h("error"),x({type:"err",text:String(M instanceof Error?M.message:M)})}},Y=()=>{R.current&&(clearInterval(R.current),R.current=null),P.current&&P.current.abort(),h("idle"),E(null),U(null)},le=async()=>{if(!r.appId||!r.appSecret){x({type:"err",text:s("settings:feishu.fillRequired",{defaultValue:"Please fill in App ID and App Secret first"})});return}u(!0),x(null);try{const M=await F.settings.testFeishuConnection({appId:r.appId,appSecret:r.appSecret});M.success?(o(ie=>({...ie,connected:!0})),x({type:"ok",text:M.message||s("settings:feishu.testSuccess",{defaultValue:"Connection successful"})})):x({type:"err",text:M.message||s("settings:feishu.testFailed",{defaultValue:"Connection failed"})})}catch(M){x({type:"err",text:String(M instanceof Error?M.message:M)})}finally{u(!1)}},Ee=async()=>{if(!v.trim()){x({type:"err",text:s("settings:feishu.chatIdRequired",{defaultValue:"Please select a group chat"})});return}y(!0),x(null);try{const M=await F.settings.sendFeishuTestMessage({chatId:v.trim()});M.success?x({type:"ok",text:M.message||s("settings:feishu.testMsgSent",{defaultValue:"Test message sent"})}):x({type:"err",text:M.message||s("settings:feishu.testMsgFailed",{defaultValue:"Failed to send test message"})})}catch(M){x({type:"err",text:String(M instanceof Error?M.message:M)})}finally{y(!1)}},dt=async()=>{d(!0),x(null);try{await F.settings.deleteFeishuIntegration(),I.current=!1,o(rn),I.current=!0,k(!1),x({type:"ok",text:s("settings:feishu.disconnected",{defaultValue:"Disconnected from Feishu"})})}catch(M){x({type:"err",text:String(M instanceof Error?M.message:M)})}finally{d(!1)}},[pe,Xe]=l.useState(!1),He=!!(r.appId&&r.appSecret),ct=e.jsxs("button",{type:"button",onClick:()=>Xe(M=>!M),className:"w-full flex items-center gap-3 px-4 py-3 hover:bg-white/[0.02] transition-colors text-left",children:[e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${pe?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})}),e.jsx("div",{className:"w-8 h-8 rounded-lg bg-blue-500/10 flex items-center justify-center shrink-0",children:e.jsx("svg",{className:"w-5 h-5 text-blue-500",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M6.3 10.5c-.8 0-1.5-.3-2-.9-.6-.6-.9-1.3-.9-2 0-.8.3-1.5.9-2 .6-.5 1.3-.8 2-.8.8 0 1.5.3 2 .9.6.6.9 1.3.9 2 0 .8-.3 1.5-.9 2-.5.5-1.2.8-2 .8zm12.4 0c-.8 0-1.5-.3-2-.9-.6-.6-.9-1.3-.9-2 0-.8.3-1.5.9-2 .6-.5 1.3-.8 2-.8.8 0 1.5.3 2 .9.6.6.9 1.3.9 2 0 .8-.3 1.5-.9 2-.5.5-1.2.8-2 .8zm-6.2 10c-.8 0-1.5-.3-2-.9-.6-.6-.9-1.3-.9-2 0-.8.3-1.5.9-2 .6-.5 1.3-.8 2-.8.8 0 1.5.3 2 .9.6.6.9 1.3.9 2 0 .8-.3 1.5-.9 2-.5.5-1.2.8-2 .8z"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:"飞书 (Feishu / Lark)"}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 hidden sm:inline",children:s("settings:feishu.description",{defaultValue:"Configure Feishu integration for notifications and approvals"})})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[n&&e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t&&e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),e.jsx(Ka,{connected:r.connected&&r.enabled})]})]});return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[ct,pe&&e.jsxs("div",{className:"px-6 pb-6 pt-2 space-y-8 border-t border-border-default",children:[n&&e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"ml-2 text-sm text-fg-tertiary",children:s("common:loading",{defaultValue:"Loading..."})})]}),!n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-blue-500/5 border border-blue-500/20",children:[e.jsx("svg",{className:"w-4 h-4 text-blue-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{className:"text-xs text-fg-secondary",children:s("settings:feishu.longConnectionMode",{defaultValue:"Using long connection mode (WebSocket) — no public IP required"})})]}),He?e.jsxs(e.Fragment,{children:[e.jsx(ot,{title:s("settings:feishu.appInfo",{defaultValue:"App Information"}),children:e.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 space-y-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:"App ID:"}),e.jsx("code",{className:"text-xs font-mono text-fg-primary bg-surface-primary px-2 py-0.5 rounded",children:r.appId})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:"App Secret:"}),e.jsx("code",{className:"text-xs font-mono text-fg-primary bg-surface-primary px-2 py-0.5 rounded",children:"•".repeat(Math.min(r.appSecret.length,20))})]})]}),e.jsxs("button",{onClick:dt,disabled:t,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),s("settings:feishu.removeApp",{defaultValue:"Remove"})]})]})})}),e.jsx(ot,{title:s("settings:feishu.integrationState",{defaultValue:"Integration State"}),children:e.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("settings:feishu.enableIntegration",{defaultValue:"Enable Feishu Integration"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("settings:feishu.enableHint",{defaultValue:"When enabled, Markus will establish a long connection to Feishu and start processing events"})})]}),e.jsx("button",{onClick:()=>X("enabled",!r.enabled),className:`relative w-12 h-6 rounded-full transition-colors duration-200 ${r.enabled?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} cursor-pointer`,children:e.jsx("span",{className:`block w-5 h-5 bg-white rounded-full shadow transform transition-transform duration-200 ${r.enabled?"translate-x-6":"translate-x-0.5"}`})})]})})}),e.jsxs(ot,{title:s("settings:feishu.actions",{defaultValue:"Actions"}),children:[e.jsx("div",{className:"flex flex-wrap items-center gap-3",children:e.jsxs("button",{onClick:le,disabled:c,className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium bg-surface-primary border border-border-default rounded-lg text-fg-primary hover:bg-surface-overlay disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[c?e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}):e.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})]}),s("settings:feishu.testConnection",{defaultValue:"Test Connection"})]})}),r.connected&&r.enabled&&e.jsxs("div",{className:"mt-4 p-4 bg-surface-secondary border border-border-default rounded-xl space-y-3",children:[e.jsx("label",{className:"block text-xs font-medium text-fg-secondary",children:s("settings:feishu.sendTestMessage",{defaultValue:"Send Test Message"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsxs("select",{value:v,onChange:M=>w(M.target.value),className:"w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors appearance-none pr-8",children:[e.jsx("option",{value:"",children:s("settings:feishu.selectTestChat",{defaultValue:"— Select a group chat —"})}),A.map(M=>e.jsx("option",{value:M.chatId,children:M.name||M.chatId},M.chatId))]}),e.jsx("svg",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-fg-tertiary pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsxs("button",{onClick:Ee,disabled:p||!v.trim(),className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium bg-surface-primary border border-border-default rounded-lg text-fg-primary hover:bg-surface-overlay disabled:opacity-50 disabled:cursor-not-allowed transition-colors whitespace-nowrap",children:[p?e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}):e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})}),s("settings:feishu.send",{defaultValue:"Send"})]})]})]}),T&&e.jsx(nn,{type:T.type,text:T.text})]}),e.jsx(ot,{title:s("settings:feishu.notificationForwarding",{defaultValue:"Notification Forwarding"}),children:e.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"block text-xs font-medium text-fg-secondary",children:s("settings:feishu.notifyChatId",{defaultValue:"Notification Target Group"})}),e.jsxs("button",{onClick:H,disabled:j,className:"inline-flex items-center gap-1 text-[11px] text-brand-600 hover:text-brand-700 disabled:opacity-50 transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 ${j?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),s("settings:feishu.refreshChats",{defaultValue:"Refresh"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:r.notifyChatId,onChange:M=>X("notifyChatId",M.target.value),className:"w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors appearance-none pr-8",children:[e.jsx("option",{value:"",children:j?s("settings:feishu.loadingChats",{defaultValue:"Loading groups..."}):s("settings:feishu.selectChat",{defaultValue:"— Private message (default) —"})}),A.map(M=>e.jsx("option",{value:M.chatId,children:M.name||M.chatId},M.chatId))]}),e.jsx("svg",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-fg-tertiary pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),!r.notifyChatId&&!j&&e.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1",children:s("settings:feishu.noChatFallbackHint",{defaultValue:"No group selected — notifications will be sent to you as private messages."})}),A.length===0&&!j&&r.notifyChatId===""&&e.jsx("p",{className:"text-[11px] text-amber-600 dark:text-amber-400 mt-0.5",children:s("settings:feishu.noChatHint",{defaultValue:"No groups found. Add the bot to a group chat to enable group notifications."})}),r.notifyChatId&&e.jsxs("p",{className:"text-[11px] text-fg-tertiary mt-1 font-mono",children:["ID: ",r.notifyChatId]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary",children:s("settings:feishu.forwardApprovals",{defaultValue:"Forward Approval Requests"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("settings:feishu.forwardApprovalsHint",{defaultValue:"Send approval requests to Feishu as interactive cards"})})]}),e.jsx("button",{onClick:()=>X("notifyOnApproval",!r.notifyOnApproval),className:`relative w-10 h-5 rounded-full transition-colors duration-200 ${r.notifyOnApproval?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} cursor-pointer`,children:e.jsx("span",{className:`block w-4 h-4 bg-white rounded-full shadow transform transition-transform duration-200 ${r.notifyOnApproval?"translate-x-5":"translate-x-0.5"}`})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary",children:s("settings:feishu.forwardNotifications",{defaultValue:"Forward General Notifications"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("settings:feishu.forwardNotificationsHint",{defaultValue:"Send system notifications to Feishu chat"})})]}),e.jsx("button",{onClick:()=>X("notifyOnNotification",!r.notifyOnNotification),className:`relative w-10 h-5 rounded-full transition-colors duration-200 ${r.notifyOnNotification?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} cursor-pointer`,children:e.jsx("span",{className:`block w-4 h-4 bg-white rounded-full shadow transform transition-transform duration-200 ${r.notifyOnNotification?"translate-x-5":"translate-x-0.5"}`})})]})]}),(r.notifyOnApproval||r.notifyOnNotification)&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-fg-secondary mb-2",children:s("settings:feishu.notifyPriority",{defaultValue:"Minimum Notification Priority"})}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Da.map(({value:M,color:ie})=>{const ue=r.notifyPriority.includes(M);return e.jsxs("button",{onClick:()=>ee(M),className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border transition-colors ${ue?"bg-brand-500/10 border-brand-500/30 text-brand-600":"bg-surface-primary border-border-default text-fg-tertiary hover:border-fg-tertiary"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${ie}`}),M.charAt(0).toUpperCase()+M.slice(1)]},M)})}),e.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1.5",children:s("settings:feishu.priorityHint",{defaultValue:"Only notifications with the selected priority levels will be forwarded"})})]})]})})]}):e.jsxs(ot,{title:s("settings:feishu.quickSetup",{defaultValue:"Quick Setup"}),children:[e.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 space-y-5",children:g==="idle"||g==="error"||g==="done"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"w-16 h-16 mx-auto rounded-2xl bg-gradient-to-br from-blue-500/20 to-indigo-500/20 border border-blue-500/30 flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-blue-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm12 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"})})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:s("settings:feishu.oneClickTitle",{defaultValue:"One-Click Feishu Integration"})}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1 max-w-sm mx-auto",children:s("settings:feishu.oneClickDesc",{defaultValue:"Scan a QR code with Feishu to automatically create and configure the app. No manual setup needed."})})]}),e.jsxs("button",{onClick:Q,disabled:g==="done",className:"inline-flex items-center gap-2 px-6 py-2.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shadow-sm",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm12 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"})}),s("settings:feishu.scanToCreate",{defaultValue:"Scan QR Code to Create App"})]})]}),e.jsx("div",{className:"border-t border-border-default pt-4",children:e.jsx("p",{className:"text-[11px] text-fg-tertiary text-center",children:s("settings:feishu.oneClickPermissions",{defaultValue:"The app will be created with permissions: bot messaging, message receiving, user info reading, and group chat management."})})})]}):e.jsxs("div",{className:"text-center space-y-4",children:[g==="waiting_qr"&&!N&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[e.jsx("div",{className:"w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-fg-secondary",children:s("settings:feishu.generatingQR",{defaultValue:"Generating QR code..."})})]}),N&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"inline-block p-4 bg-white rounded-xl shadow-sm border border-gray-200",children:O?e.jsx("img",{src:O,alt:"Feishu QR Code",className:"w-48 h-48"}):e.jsx("div",{className:"w-48 h-48 flex items-center justify-center",children:e.jsx("div",{className:"w-5 h-5 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"})})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-fg-primary",children:s("settings:feishu.scanWithFeishu",{defaultValue:"Scan with Feishu app"})}),e.jsx("p",{className:"text-xs text-fg-tertiary",children:s("settings:feishu.scanHint",{defaultValue:"Use your Feishu mobile app to scan and authorize. The app will be created in your organization."})}),_>0&&e.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("settings:feishu.qrExpire",{defaultValue:`QR code expires in ${Math.floor(_/60)} minutes`,minutes:Math.floor(_/60)})})]}),e.jsx("button",{onClick:Y,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs text-fg-tertiary hover:text-fg-secondary border border-border-default rounded-lg hover:bg-surface-overlay transition-colors",children:s("common:cancel",{defaultValue:"Cancel"})})]})]})}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{onClick:()=>k(!f),className:"inline-flex items-center gap-1.5 text-xs text-fg-tertiary hover:text-fg-secondary transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${f?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),s("settings:feishu.manualConfig",{defaultValue:"Manual configuration (advanced)"})]}),f&&e.jsxs("div",{className:"mt-3 bg-surface-secondary border border-border-default rounded-xl p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-fg-secondary mb-1.5",children:["App ID ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:r.appId,onChange:M=>V("appId",M.target.value),onBlur:()=>{r.appId&&r.appSecret&&(Z.current&&clearTimeout(Z.current),m(ne.current))},placeholder:"cli_xxxxxxxxxxxxxx",className:"w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors font-mono"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-fg-secondary mb-1.5",children:["App Secret ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:$?"text":"password",value:r.appSecret,onChange:M=>V("appSecret",M.target.value),onBlur:()=>{r.appId&&r.appSecret&&(Z.current&&clearTimeout(Z.current),m(ne.current))},placeholder:"Enter your Feishu app secret",className:"w-full px-3 py-2 pr-10 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors font-mono"}),e.jsx("button",{type:"button",onClick:()=>J(!$),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-fg-tertiary hover:text-fg-secondary transition-colors",children:$?e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"})}):e.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]})]})]})]})]}),T&&!He&&e.jsx(nn,{type:T.type,text:T.text})]})]})]})}const Qe=["claude-code","codex","cursor-agent"],An=10;function an(s){const r={};for(const o of Qe){const n=s.tools[o],a=n?.timeoutMs??An*6e4;r[o]={enabled:n?.enabled??!0,binaryPath:n?.binaryPath??"",defaultArgs:(n?.defaultArgs??[]).join(" "),timeoutMin:String(Math.round(a/6e4)),defaultModel:n?.defaultModel??"",maxBudgetPerSessionUsd:n?.maxBudgetPerSessionUsd?String(n.maxBudgetPerSessionUsd):"",approvalRequired:n?.approvalRequired??!1}}return r}function Ms({checked:s,onChange:r,disabled:o}){return e.jsx("button",{type:"button",onClick:r,disabled:o,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${s?"bg-green-500":"bg-gray-600"} ${o?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${s?"translate-x-4":"translate-x-1"}`})})}function Bs({type:s,text:r}){return e.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${s==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:r})}function lt({className:s="w-3 h-3"}){return e.jsxs("svg",{className:`animate-spin ${s}`,viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function on({children:s}){return e.jsx("div",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider",children:s})}function Fa({expanded:s}){return e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${s?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})}function $a({info:s}){const{t:r}=me("settings"),o=s?.available&&s?.authenticated,n=s?.available,a=r(o?"codingTools.ready":n?"codingTools.needsAuth":"codingTools.notInstalled"),t=o?"bg-green-500/15 text-green-500":n?"bg-amber-500/15 text-amber-500":"bg-gray-600/20 text-fg-tertiary",d=o?"bg-green-400":n?"bg-amber-400":"bg-gray-500";return e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${t}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${d}`}),a]})}const Va=new Set(["cursor-agent","claude-code"]),Ha={"cursor-agent":"CURSOR_API_KEY","claude-code":"ANTHROPIC_API_KEY",codex:"CODEX_API_KEY"},qa=15e3,za=12;function Wa({name:s,onAuthDone:r}){const{t:o}=me(["settings","common"]),[n,a]=l.useState("idle"),[t,d]=l.useState(!1),[c,u]=l.useState(!1),[p,y]=l.useState(""),[T,x]=l.useState(null),v=l.useRef(null),w=l.useRef(0),A=Va.has(s),K=Ha[s]??"",j=l.useCallback(()=>{v.current&&(clearInterval(v.current),v.current=null),w.current=0,u(!1)},[]);l.useEffect(()=>()=>j(),[j]);const S=l.useCallback(()=>{j(),w.current=0,u(!0),v.current=setInterval(async()=>{w.current++;try{(await F.settings.detectCodingTool(s))?.authenticated&&(j(),x({ok:!0,text:o("codingTools.authSuccess")}),d(!1),r())}catch{}w.current>=za&&(j(),d(!1),x({ok:!1,text:o("codingTools.authPollTimeout")}))},qa)},[s,r,j,o]),g=async()=>{d(!0),x(null);try{const N=await F.settings.authCodingTool(s,"cli_login");N.success&&N.authenticated?(x({ok:!0,text:o("codingTools.authSuccess")}),r(),d(!1)):N.success?(x({ok:!1,text:o("codingTools.authBrowserHint")}),S()):(x({ok:!1,text:N.error??o("codingTools.authFailed")}),d(!1))}catch{x({ok:!1,text:o("codingTools.authFailed")}),d(!1)}},h=async()=>{if(p.trim()){d(!0),x(null);try{const N=await F.settings.authCodingTool(s,"api_key",p.trim());N.success?(x({ok:!0,text:o("codingTools.apiKeySaved",{envVar:N.envVar??K})}),y(""),r()):x({ok:!1,text:o("codingTools.authFailed")})}catch{x({ok:!1,text:o("codingTools.authFailed")})}finally{d(!1)}}};return n==="idle"?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[A&&e.jsx("button",{type:"button",onClick:()=>{a("login"),g()},className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors",children:o("codingTools.loginBtn")}),e.jsx("button",{type:"button",onClick:()=>a("key"),className:"px-2.5 py-1 text-[10px] font-medium border border-border-default text-fg-secondary rounded-md hover:text-fg-primary hover:border-gray-600 transition-colors",children:o("codingTools.apiKeyBtn")})]}):n==="login"?e.jsxs("div",{className:"space-y-1.5",children:[(t||c)&&e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-brand-500",children:[e.jsx(lt,{}),e.jsx("span",{children:o(c?"codingTools.authPolling":"codingTools.loginWaiting")})]}),T&&e.jsx(Bs,{type:T.ok?"ok":"err",text:T.text}),!t&&!c&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>{x(null),r()},className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors",children:o("codingTools.recheckAuth")}),e.jsx("button",{type:"button",onClick:()=>{a("idle"),x(null),j()},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary",children:o("common:cancel")})]}),c&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{j(),d(!1),x(null),r()},className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors",children:o("codingTools.recheckAuth")}),e.jsx("button",{type:"button",onClick:()=>{j(),d(!1),x(null),a("idle")},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary",children:o("common:cancel")})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[s==="cursor-agent"&&e.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[o("codingTools.cursorApiKeyNote")," ",e.jsx("a",{href:o("codingTools.cursorDashboardUrl"),target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:underline",children:"↗"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"password",value:p,onChange:N=>y(N.target.value),placeholder:K,className:"flex-1 px-2.5 py-1 text-[10px] bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono min-w-0",onKeyDown:N=>{N.key==="Enter"&&h()}}),e.jsx("button",{type:"button",onClick:()=>{h()},disabled:t||!p.trim(),className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors disabled:opacity-40 shrink-0",children:t?"...":o("common:save")}),e.jsx("button",{type:"button",onClick:()=>{a("idle"),x(null),y("")},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0",children:o("common:cancel")})]}),T&&e.jsx(Bs,{type:T.ok?"ok":"err",text:T.text})]})}function Ga({source:s}){const{t:r}=me("settings");if(!s)return null;const o=r(s==="api"?"codingTools.modelSourceApi":s==="static"?"codingTools.modelSourceStatic":"codingTools.modelSourceCli"),n=s==="api"?"bg-green-500/15 text-green-500":s==="static"?"bg-blue-500/15 text-blue-400":"bg-amber-500/15 text-amber-500";return e.jsx("span",{className:`text-[9px] font-medium px-1.5 py-0.5 rounded-full ${n}`,children:o})}function Ya({name:s,value:r,onChange:o}){const{t:n}=me("settings"),[a,t]=l.useState([]),[d,c]=l.useState(!1),[u,p]=l.useState(null),[y,T]=l.useState(),[x,v]=l.useState(!1),[w,A]=l.useState(""),K=l.useRef(null),j=l.useRef(!1),S=l.useCallback(async(N=!1)=>{if(!(j.current&&!N)){j.current=!0,c(!0),p(null);try{const E=await F.settings.listCodingToolModels(s),O=E.models??[];t(O),T(E.source),O.length===0&&p(n("codingTools.modelsEmpty"))}catch{p(n("codingTools.modelsFetchError"))}c(!1)}},[s,n]);l.useEffect(()=>{S()},[S]),l.useEffect(()=>{const N=E=>{K.current&&!K.current.contains(E.target)&&v(!1)};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);const g=a.filter(N=>!w||N.id.toLowerCase().includes(w.toLowerCase())||N.name.toLowerCase().includes(w.toLowerCase())),h=s==="cursor-agent"?"codingTools.modelGuidanceCursor":s==="claude-code"?"codingTools.modelGuidanceClaude":s==="codex"?"codingTools.modelGuidanceCodex":null;return e.jsxs("div",{ref:K,className:"relative",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:x?w:r,onChange:N=>{A(N.target.value),o(N.target.value)},onFocus:()=>{v(!0),A(r)},placeholder:n("codingTools.modelPlaceholder"),className:"flex-1 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"}),!d&&y&&e.jsx(Ga,{source:y}),d&&e.jsx(lt,{className:"w-3.5 h-3.5 text-fg-tertiary shrink-0"}),!d&&u&&e.jsx("button",{type:"button",onClick:()=>{j.current=!1,S(!0)},title:n("codingTools.modelsRetry"),className:"text-[10px] text-amber-500 hover:text-amber-400 shrink-0",children:"↻"})]}),u&&!d&&e.jsx("div",{className:"text-[10px] text-amber-500 mt-0.5",children:u}),h&&!d&&e.jsx("div",{className:"text-[10px] mt-1 text-fg-tertiary",children:n(h)}),x&&e.jsx("div",{className:"absolute z-50 mt-1 w-full bg-surface-secondary border border-border-default rounded-lg shadow-xl max-h-48 overflow-y-auto",children:d?e.jsxs("div",{className:"px-3 py-2 text-[10px] text-fg-tertiary flex items-center gap-2",children:[e.jsx(lt,{}),n("codingTools.modelsLoading")]}):g.length===0&&!w?e.jsx("div",{className:"px-3 py-2 text-[10px] text-fg-tertiary",children:n("codingTools.noModelsFound")}):e.jsxs(e.Fragment,{children:[r&&e.jsx("button",{type:"button",onClick:()=>{o(""),A(""),v(!1)},className:"w-full text-left px-3 py-1.5 text-xs text-fg-tertiary hover:bg-surface-elevated transition-colors italic",children:n("codingTools.useToolDefault")}),g.map(N=>e.jsxs("button",{type:"button",onClick:()=>{o(N.id),A(N.id),v(!1)},className:`w-full text-left px-3 py-1.5 text-xs hover:bg-surface-elevated transition-colors ${N.id===r?"bg-brand-500/10 text-brand-500":"text-fg-primary"}`,children:[e.jsx("span",{className:"font-mono",children:N.id}),N.name!==N.id&&e.jsx("span",{className:"text-fg-tertiary ml-2",children:N.name}),N.isDefault&&e.jsx("span",{className:"text-[9px] text-fg-tertiary ml-1.5 bg-surface-primary px-1.5 py-0.5 rounded",children:"default"})]},N.id))]})})]})}const At="markus_coding_tool_detect",Ja=1440*60*1e3;function Qa(){const s={"claude-code":{status:"idle"},codex:{status:"idle"},"cursor-agent":{status:"idle"}};try{const r=localStorage.getItem(At);if(!r)return s;const o=JSON.parse(r),n={...s};for(const a of Qe){const t=o[a];if(!t)continue;const d="data"in t&&"ts"in t?t.data:t;n[a]={status:"done",data:d}}return n}catch{return s}}function Xa(s){try{const r=localStorage.getItem(At);return r?!!JSON.parse(r)[s]:!1}catch{return!1}}function Za(s){try{const r=localStorage.getItem(At);if(!r)return!0;const n=JSON.parse(r)[s];return n&&"ts"in n&&typeof n.ts=="number"?Date.now()-n.ts>Ja:!0}catch{return!0}}function Ts(s){try{const r={},o=Date.now();for(const n of Qe){const a=s[n];a.status==="done"&&(r[n]={data:a.data,ts:o})}localStorage.setItem(At,JSON.stringify(r))}catch{}}const eo=800;function to(s,r){const o={};for(const n of Qe){const a=r[n],t=a.defaultArgs.trim()?a.defaultArgs.trim().split(/\s+/).filter(Boolean):void 0,d=parseFloat(a.timeoutMin),c=Number.isFinite(d)&&d>0?Math.round(d*6e4):An*6e4,u=parseFloat(a.maxBudgetPerSessionUsd);o[n]={tool:n,enabled:a.enabled,binaryPath:a.binaryPath.trim()||void 0,defaultArgs:t,timeoutMs:c,defaultModel:a.defaultModel.trim()||void 0,maxBudgetPerSessionUsd:n==="claude-code"&&Number.isFinite(u)&&u>0?u:void 0,approvalRequired:a.approvalRequired||void 0}}return{enabled:s,tools:o}}function so(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(!0),[n,a]=l.useState(!1),[t,d]=l.useState(!1),[c,u]=l.useState(Qa),[p,y]=l.useState(()=>an({tools:{}})),[T,x]=l.useState(null),[v,w]=l.useState(new Set),[A,K]=l.useState(null),[j,S]=l.useState({}),g=l.useRef(null),h=l.useRef(!1),N=l.useCallback(async(f,k=!1)=>{k||u($=>({...$,[f]:{status:"loading"}}));try{const $=await F.settings.detectCodingTool(f);u(J=>{const Z={...J,[f]:{status:"done",data:$}};return Ts(Z),Z})}catch{k||u($=>({...$,[f]:{status:"idle"}}))}},[]),E=l.useCallback(async f=>{K(f),S(k=>({...k,[f]:null}));try{const k=await F.settings.testCodingTool(f);let $;if(k.success){const J=[s("codingTools.testSuccess")];k.model&&J.push(s("codingTools.testModel",{model:k.model})),k.apiKeySource&&!k.apiKeySource.includes("@")?J.push(s("codingTools.testAuthVia",{source:k.apiKeySource})):k.apiKeySource?.includes("@")&&J.push(k.apiKeySource),$=J.join(" · ")}else $=k.error?`${s("codingTools.testFailed")}:${k.error}`:s("codingTools.testFailed");S(J=>({...J,[f]:{success:k.success,detail:$}})),k.success&&u(J=>{const Z=J[f];if(Z.status==="done"&&!Z.data.authenticated){const ne={...J,[f]:{status:"done",data:{...Z.data,authenticated:!0}}};return Ts(ne),ne}return J})}catch{S($=>({...$,[f]:{success:!1,detail:s("codingTools.testFailed")}}))}finally{K(null)}},[s]),O=l.useCallback(f=>{w(k=>{const $=new Set(k);return $.has(f)?$.delete(f):$.add(f),$.has(f)&&c[f].status==="idle"&&N(f),$})},[c,N]),U=l.useCallback(async()=>{o(!0),x(null);try{const f=await F.settings.getCodingTools();if(d(f.enabled),y(an(f)),h.current=!0,f.enabled)for(const k of Qe)f.tools[k]?.enabled&&Za(k)&&N(k,Xa(k))}catch{x({type:"err",text:s("codingTools.failedToLoad")})}finally{o(!1)}},[s,N]);l.useEffect(()=>{U()},[U]),l.useEffect(()=>{if(h.current)return g.current&&clearTimeout(g.current),g.current=setTimeout(async()=>{x(null);try{await F.settings.updateCodingTools(to(t,p)),x({type:"ok",text:s("codingTools.saved")})}catch{x({type:"err",text:s("codingTools.failedToSave")})}},eo),()=>{g.current&&clearTimeout(g.current)}},[t,p,s]);const _=async()=>{a(!0),x(null);try{const f=await F.settings.detectCodingTools(),k={"claude-code":{status:"idle"},codex:{status:"idle"},"cursor-agent":{status:"idle"}};for(const $ of f.tools)k[$.name]={status:"done",data:$};u(k),Ts(k)}catch{x({type:"err",text:s("codingTools.detectionFailed")})}finally{a(!1)}},D=(f,k)=>{y($=>({...$,[f]:{...$[f],...k}}))},R=f=>{const k=c[f];return k.status==="done"?k.data:void 0},P=f=>c[f].status==="loading";return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:s("codingTools.title")}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-fg-tertiary",children:s("codingTools.description")}),e.jsx("div",{className:"bg-surface-elevated rounded-xl px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("codingTools.globalEnable")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("codingTools.globalEnableDesc")})]}),e.jsx(Ms,{checked:t,onChange:()=>d(f=>!f),disabled:r})]})}),r?e.jsx("div",{className:"text-sm text-fg-tertiary py-8 text-center",children:s("common:loading")}):Qe.map(f=>{const k=R(f),$=p[f],J=P(f),Z={"claude-code":"Claude Code",codex:"Codex","cursor-agent":"Cursor Agent"},ne=k?.displayName??Z[f]??f,I=v.has(f),H=k&&!k.available,q=k?.available&&!k?.authenticated,m=k?!k.available:!1;return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>O(f),className:"w-full flex items-center gap-3 px-4 py-3 hover:bg-white/[0.02] transition-colors text-left",children:[e.jsx(Fa,{expanded:I}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:ne}),J?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[10px] font-medium bg-gray-600/20 text-fg-tertiary",children:[e.jsx(lt,{}),s("codingTools.detectingTool")]}):e.jsx($a,{info:k}),k?.version&&e.jsx("span",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:k.version})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",onClick:L=>L.stopPropagation(),children:e.jsx(Ms,{checked:$.enabled,onChange:()=>D(f,{enabled:!$.enabled})})})]}),I&&e.jsxs("div",{className:"px-4 pb-4 border-t border-border-default",children:[k?.path&&e.jsx("div",{className:"text-[10px] text-fg-tertiary font-mono mt-3 truncate",title:k.path,children:k.path}),H&&k&&e.jsxs("div",{className:"mt-3 p-3 bg-amber-500/5 border border-amber-500/20 rounded-lg",children:[e.jsx("div",{className:"text-xs text-amber-500 font-medium mb-1",children:s("codingTools.stepInstall")}),k.installHint&&e.jsx("code",{className:"text-[10px] bg-surface-primary px-2 py-1 rounded block text-fg-secondary",children:k.installHint})]}),q&&e.jsxs("div",{className:"mt-3 p-3 bg-amber-500/5 border border-amber-500/20 rounded-lg",children:[e.jsx("div",{className:"text-xs text-amber-500 font-medium mb-2",children:s("codingTools.stepAuth")}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mb-2",children:s("codingTools.authHint")}),e.jsx(Wa,{name:f,onAuthDone:()=>{N(f)}})]}),e.jsxs("div",{className:"grid gap-4 mt-4",children:[m&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.binaryPath")}),e.jsx("input",{type:"text",value:$.binaryPath,onChange:L=>D(f,{binaryPath:L.target.value}),placeholder:s("codingTools.binaryPathPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"})]}),e.jsx(on,{children:s("codingTools.sectionModelExec")}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.defaultModel")}),e.jsx(Ya,{name:f,value:$.defaultModel,onChange:L=>D(f,{defaultModel:L})}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:s("codingTools.defaultModelHint")})]}),f==="claude-code"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.budgetCap")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-tertiary",children:"$"}),e.jsx("input",{type:"number",min:0,step:.5,value:$.maxBudgetPerSessionUsd,onChange:L=>D(f,{maxBudgetPerSessionUsd:L.target.value}),placeholder:"5.00",className:"w-32 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none tabular-nums"}),e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"USD"})]}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:s("codingTools.budgetCapHint")})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-fg-secondary",children:s("codingTools.approvalRequired")}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:s("codingTools.approvalRequiredHint")})]}),e.jsx(Ms,{checked:$.approvalRequired,onChange:()=>D(f,{approvalRequired:!$.approvalRequired})})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.timeout")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:1,step:1,value:$.timeoutMin,onChange:L=>D(f,{timeoutMin:L.target.value}),className:"w-24 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:border-brand-500 outline-none tabular-nums"}),e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s("codingTools.timeoutUnit")})]})]})}),e.jsx(on,{children:s("codingTools.sectionAdvanced")}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.defaultArgs")}),e.jsx("input",{type:"text",value:$.defaultArgs,onChange:L=>D(f,{defaultArgs:L.target.value}),placeholder:s("codingTools.defaultArgsPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"})]}),e.jsxs("div",{className:"pt-3 border-t border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{type:"button",disabled:A===f,onClick:()=>E(f),className:"px-3 py-1.5 text-xs font-medium bg-brand-500 text-white rounded-lg hover:bg-brand-600 disabled:opacity-50 transition-colors flex items-center gap-1.5 shrink-0",children:[A===f&&e.jsx(lt,{className:"w-3 h-3"}),s(A===f?"codingTools.testing":"codingTools.testConfig")]}),!j[f]&&e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s("codingTools.testConfigHint")})]}),j[f]&&e.jsx("div",{className:`mt-2 px-3 py-2 rounded-lg text-xs ${j[f].success?"bg-green-500/10 border border-green-500/20 text-green-600":"bg-red-500/10 border border-red-500/20 text-red-500"}`,children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"shrink-0 mt-0.5",children:j[f].success?"✓":"✗"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{children:j[f].detail}),!j[f].success&&e.jsx("div",{className:"text-[10px] mt-1 opacity-80",children:s("codingTools.testFailedHint")})]})]})})]})]})]})]},f)}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:T&&e.jsx(Bs,{type:T.type,text:T.text})}),e.jsx("button",{type:"button",onClick:()=>{_()},disabled:n||r,className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:text-fg-primary hover:border-gray-600 rounded-lg transition-colors disabled:opacity-40",children:s(n?"codingTools.detecting":"codingTools.redetect")})]})]})]})}const it=[{id:"serper",labelKey:"searchApi.serper",hintKey:"searchApi.serperHint",field:"serperApiKey"},{id:"tavily",labelKey:"searchApi.tavily",hintKey:"searchApi.tavilyHint",field:"tavilyApiKey"},{id:"google",labelKey:"searchApi.google",hintKey:"searchApi.googleHint",field:"googleSearchApiKey",extraField:"googleSearchCx",extraPlaceholderKey:"searchApi.googleCxPlaceholder"},{id:"bing",labelKey:"searchApi.bing",hintKey:"searchApi.bingHint",field:"bingApiKey"},{id:"brave",labelKey:"searchApi.brave",hintKey:"searchApi.braveHint",field:"braveApiKey"},{id:"serpapi",labelKey:"searchApi.serpapi",hintKey:"searchApi.serpapiHint",field:"serpApiKey"},{id:"exa",labelKey:"searchApi.exa",hintKey:"searchApi.exaHint",field:"exaApiKey"},{id:"bocha",labelKey:"searchApi.bocha",hintKey:"searchApi.bochaHint",field:"bochaApiKey"}],ro=800,ln=[{id:"perplexity/sonar",labelKey:"searchApi.modelSonar"},{id:"perplexity/sonar-pro",labelKey:"searchApi.modelSonarPro"}];function dn({expanded:s}){return e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${s?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})}function Pt({className:s="w-3 h-3"}){return e.jsxs("svg",{className:`${s} animate-spin`,viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function no(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(null),[n,a]=l.useState(!0),[t,d]=l.useState(new Set),[c,u]=l.useState({}),[p,y]=l.useState({}),[T,x]=l.useState(!1),[v,w]=l.useState(!1),[A,K]=l.useState({}),[j,S]=l.useState({}),[g,h]=l.useState({}),[N,E]=l.useState({}),O=l.useRef({}),U=l.useCallback(async()=>{a(!0);try{const m=await F.settings.getSearch();m&&(o(m),it.some(V=>!!m[V.id]?.configured)&&w(!0))}catch{}a(!1)},[]);l.useEffect(()=>{U()},[U]),l.useEffect(()=>()=>{Object.values(O.current).forEach(clearTimeout)},[]);const _=m=>{d(L=>{const V=new Set(L);return V.has(m)?V.delete(m):V.add(m),V})},D=(m,L,V)=>{u(X=>({...X,[L]:V})),O.current[m]&&clearTimeout(O.current[m]),O.current[m]=setTimeout(()=>{R(m)},ro)},R=async m=>{const L=it.find(ee=>ee.id===m);if(!L)return;const V=c[L.field]?.trim(),X=L.extraField?c[L.extraField]?.trim():void 0;if(!(!V&&!X)){y(ee=>({...ee,[m]:!0})),K(ee=>{const Q={...ee};return delete Q[m],Q});try{const ee={};V&&(ee[L.field]=V),X&&L.extraField&&(ee[L.extraField]=X);const Q=await F.settings.updateSearch(ee);o(Q),u(Y=>{const le={...Y};return delete le[L.field],L.extraField&&delete le[L.extraField],le}),K(Y=>({...Y,[m]:{type:"ok",text:s("searchApi.saved")}})),setTimeout(()=>K(Y=>{const le={...Y};return delete le[m],le}),3e3)}catch{K(ee=>({...ee,[m]:{type:"err",text:s("searchApi.failedToSave")}}))}y(ee=>({...ee,[m]:!1}))}},P=m=>r?.[m],f=m=>P(m)?.configured??!1,k=m=>P(m)?.enabled!==!1,$=async(m,L)=>{E(V=>({...V,[m]:!0}));try{const V={[`${m}Enabled`]:L},X=await F.settings.updateSearch(V);o(X)}catch{}E(V=>({...V,[m]:!1}))},J=async m=>{O.current[m]&&(clearTimeout(O.current[m]),delete O.current[m],await R(m)),S(L=>({...L,[m]:!0})),h(L=>{const V={...L};return delete V[m],V});try{const L=await F.settings.testSearch(m);if(L.ok){const V=[s("searchApi.testOk",{count:L.count??0})];L.latencyMs!=null&&V.push(`${L.latencyMs}ms`),L.sample?.title&&V.push(L.sample.title.slice(0,48)),h(X=>({...X,[m]:{ok:!0,text:V.join(" · ")}}))}else h(V=>({...V,[m]:{ok:!1,text:L.error||s("searchApi.testFailed")}}))}catch{h(L=>({...L,[m]:{ok:!1,text:s("searchApi.testFailed")}}))}S(L=>({...L,[m]:!1}))},Z=async m=>{x(!0);try{const L=await F.settings.updateSearch(m);o(L)}catch{}x(!1)},ne=({id:m,disabled:L})=>{const V=j[m];return e.jsxs("button",{type:"button",onClick:()=>{J(m)},disabled:V||L,className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium bg-surface-primary border border-border-default text-fg-secondary hover:text-fg-primary hover:border-brand-500 disabled:opacity-50 transition-colors",children:[V?e.jsx(Pt,{}):e.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.5 2a6.5 6.5 0 104.096 11.553l3.925 3.925a.75.75 0 101.06-1.06l-3.925-3.925A6.5 6.5 0 008.5 2zM3.5 8.5a5 5 0 1110 0 5 5 0 01-10 0z",clipRule:"evenodd"})}),s(V?"searchApi.testing":"searchApi.test")]})},I=({id:m})=>{const L=g[m];return L?e.jsxs("div",{className:`text-[11px] flex items-start gap-1.5 ${L.ok?"text-green-500":"text-red-500"}`,children:[e.jsx("span",{className:"shrink-0 mt-px",children:L.ok?"✓":"✕"}),e.jsx("span",{className:"break-all",children:L.text})]}):null},H=({id:m})=>{const L=k(m),V=N[m];return e.jsxs("label",{className:"inline-flex items-center gap-2 cursor-pointer shrink-0",onClick:X=>X.stopPropagation(),title:s(L?"searchApi.enabled":"searchApi.disabled"),children:[V&&e.jsx(Pt,{className:"w-3 h-3 text-fg-tertiary"}),e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:L,disabled:V,onChange:X=>{$(m,X.target.checked)}}),e.jsx("span",{className:"relative w-9 h-5 rounded-full bg-gray-500/40 peer-checked:bg-brand-500 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:transition-transform peer-checked:after:translate-x-4"})]})},q=r?.markus;return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:s("searchApi.title")}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-fg-tertiary",children:s("searchApi.description")}),n?e.jsx("div",{className:"text-sm text-fg-tertiary py-8 text-center",children:s("common:loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-border-default px-4 py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:s("searchApi.markus")}),e.jsx("span",{className:"text-[10px] font-medium text-brand-400",children:s("searchApi.markusBadge")})]}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 truncate",children:s("searchApi.markusHint")})]}),q?.available&&q.enabled&&e.jsx(ne,{id:"markus"}),q?.available?e.jsxs("label",{className:"inline-flex items-center gap-2 cursor-pointer shrink-0",children:[T&&e.jsx(Pt,{className:"w-3 h-3 text-fg-tertiary"}),e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:q.enabled,disabled:T,onChange:m=>{Z({useMarkusHosted:m.target.checked})}}),e.jsx("span",{className:"relative w-9 h-5 rounded-full bg-gray-500/40 peer-checked:bg-brand-500 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:transition-transform peer-checked:after:translate-x-4"})]}):e.jsx("span",{className:"text-[11px] text-amber-500 shrink-0",children:s("searchApi.markusUnavailable")})]}),!q?.available&&e.jsx("div",{className:"text-[11px] text-amber-500/90",children:s("searchApi.markusUnavailableHint")}),q?.available&&q.enabled&&e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary shrink-0",htmlFor:"markus-search-model",children:s("searchApi.modelLabel")}),e.jsxs("select",{id:"markus-search-model",value:q.markusSearchModel||"perplexity/sonar",disabled:T,onChange:m=>{Z({markusSearchModel:m.target.value})},className:"flex-1 min-w-0 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary outline-none focus:border-brand-500",children:[ln.map(m=>e.jsx("option",{value:m.id,children:s(m.labelKey)},m.id)),q.markusSearchModel&&!ln.some(m=>m.id===q.markusSearchModel)&&e.jsx("option",{value:q.markusSearchModel,children:q.markusSearchModel})]})]}),e.jsx("div",{className:"text-[11px] text-fg-tertiary",children:s("searchApi.modelHint")}),e.jsx(I,{id:"markus"})]}),e.jsxs("div",{className:"rounded-xl border border-border-default overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>w(m=>!m),className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-white/[0.02] transition-colors text-left",children:[e.jsx(dn,{expanded:v}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-2 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:s("searchApi.ownKeysTitle")}),e.jsx("span",{className:"text-xs text-fg-tertiary truncate",children:s("searchApi.ownKeysHint")})]}),e.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0 tabular-nums",children:[it.filter(m=>f(m.id)).length,"/",it.length]})]}),v&&e.jsx("div",{className:"border-t border-border-default px-2 pb-2 space-y-1",children:it.map(m=>{const L=f(m.id),V=t.has(m.id),X=A[m.id],ee=p[m.id];return e.jsxs("div",{className:"rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsxs("button",{type:"button",onClick:()=>_(m.id),className:`flex-1 min-w-0 flex items-center gap-3 px-3 py-2.5 hover:bg-white/[0.02] transition-colors text-left ${L&&!k(m.id)?"opacity-50":""}`,children:[e.jsx(dn,{expanded:V}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:s(m.labelKey)}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 hidden sm:inline",children:s(m.hintKey)})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:L?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-400"}),e.jsx("span",{className:"text-[10px] font-medium text-green-500",children:s("searchApi.configured")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-gray-500"}),e.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary",children:s("searchApi.notConfigured")})]})})]}),e.jsx("div",{className:"shrink-0 pr-3 pl-2 border-l border-border-default self-stretch flex items-center",children:e.jsx(H,{id:m.id})})]}),V&&e.jsx("div",{className:"px-3 pb-3",children:e.jsxs("div",{className:"mt-1 space-y-2",children:[e.jsx("input",{type:"password",value:c[m.field]??"",onChange:Q=>D(m.id,m.field,Q.target.value),placeholder:s(L?"modelProviders.apiKeyPlaceholder":"searchApi.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"}),m.extraField&&e.jsx("input",{type:"text",value:c[m.extraField]??"",onChange:Q=>D(m.id,m.extraField,Q.target.value),placeholder:m.extraPlaceholderKey?s(m.extraPlaceholderKey):"",className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"}),e.jsxs("div",{className:"flex items-center gap-2 min-h-[28px] flex-wrap",children:[e.jsx(ne,{id:m.id,disabled:!L&&!c[m.field]?.trim()}),ee&&e.jsxs("span",{className:"text-[10px] text-fg-tertiary flex items-center gap-1",children:[e.jsx(Pt,{}),s("common:saving")]}),X&&e.jsx("span",{className:`text-[10px] ${X.type==="ok"?"text-green-500":"text-red-500"}`,children:X.text})]}),e.jsx(I,{id:m.id})]})})]},m.id)})})]})]})]})]})}const ao=new Set(["claude-opus-4-6","claude-sonnet-4-20250514","claude-3-5-haiku-20241022","gpt-5.4","gpt-4o","o4-mini","gemini-3-1-pro","gemini-2.5-flash","MiniMax-M2.7","MiniMax-M2.5","xiaomi/mimo-v2-pro","anthropic/claude-opus-4-6","openai/gpt-5.4","google/gemini-3-1-pro","deepseek-v4-flash","deepseek-v4-pro","deepseek-chat","deepseek-reasoner"]),Mn=[{id:"appearance",labelKey:"nav.appearance"},{id:"storage",labelKey:"nav.storage",adminOnly:!0},{id:"providers",labelKey:"nav.providers",adminOnly:!0},{id:"execution",labelKey:"nav.execution",adminOnly:!0},{id:"browser",labelKey:"nav.browser",adminOnly:!0},{id:"coding-tools",labelKey:"nav.codingTools",adminOnly:!0},{id:"search",labelKey:"nav.search",adminOnly:!0},{id:"integrations",labelKey:"nav.integrations",adminOnly:!0},{id:"account",labelKey:"nav.account"}],cn=[{labelKey:"nav.group.general",tabs:["appearance","storage"]},{labelKey:"nav.group.aiConfig",tabs:["providers","execution"]},{labelKey:"nav.group.tools",tabs:["browser","coding-tools","search"]},{labelKey:"nav.group.connections",tabs:["integrations"]},{labelKey:"nav.group.account",tabs:["account"]}],oo={Database:"database",Agents:"agents",Skills:"skills","LLM Logs":"llmLogs","Builder Artifacts":"builderArtifacts",Teams:"teams",Shared:"shared",Knowledge:"knowledge"},Es={Database:"keep",Agents:"keep",Skills:"caution","LLM Logs":"safe","Builder Artifacts":"caution",Teams:"keep",Shared:"caution",Knowledge:"caution"},un={appearance:"M21 4H14 M10 4H3 M21 12H12 M8 12H3 M21 20H16 M12 20H3 M14 2v4 M8 10v4 M16 18v4",storage:"M12 8c4.418 0 8-1.343 8-3s-3.582-3-8-3-8 1.343-8 3 3.582 3 8 3Z M4 5v6c0 1.657 3.582 3 8 3s8-1.343 8-3V5 M4 11v6c0 1.657 3.582 3 8 3s8-1.343 8-3v-6",providers:"M9 2v3 M15 2v3 M9 19v3 M15 19v3 M2 9h3 M2 15h3 M19 9h3 M19 15h3 M6 6h12v12H6z M9 9h6v6H9z",execution:"M12 8V4H8 M4 8h16a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2z M2 14h2 M20 14h2 M15 13v2 M9 13v2",browser:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20z M2 12h20 M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z","coding-tools":"M16 18l6-6-6-6 M8 6l-6 6 6 6",search:"M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16z M21 21l-4.3-4.3",integrations:"M9 17H7A5 5 0 0 1 7 7h2 M15 7h2a5 5 0 1 1 0 10h-2 M8 12h8",account:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2 M12 7a4 4 0 1 0 0 8 4 4 0 0 0 0-8Z",_default:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"};function xn({id:s,className:r}){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 ${r??""}`,children:e.jsx("path",{d:un[s]??un._default})})}const io={users:"account",organization:"account",license:"account",remote:"account"};function mn(){const r=window.location.hash.slice(1).split("/");if(r[0]==="settings"&&r[1]){const o=r[1],a=io[o]??o;if(Mn.some(t=>t.id===a))return a}return null}function Ao({theme:s,onThemeChange:r,authUser:o,onLogout:n,onUserUpdated:a}={}){const{t,i18n:d}=me(["settings","common"]),c=sa(),[u,p]=l.useState(mn);l.useEffect(()=>{const i=()=>p(mn());return window.addEventListener("hashchange",i),()=>window.removeEventListener("hashchange",i)},[]);const y=l.useCallback(i=>{p(i),history.pushState(null,"",`#settings/${i}`)},[]),T=l.useCallback(()=>{p(null),history.pushState(null,"","#settings")},[]),x=u??(c?null:"appearance"),[v,w]=l.useState(!1),[A,K]=l.useState(!1);l.useEffect(()=>{!kr()||!window.markusDesktop?.getLoginItemSettings||window.markusDesktop.getLoginItemSettings().then(i=>w(!!i.openAtLogin)).catch(()=>{})},[]);const j=l.useCallback(async()=>{if(!window.markusDesktop?.setLoginItemSettings||A)return;const i=!v;K(!0),w(i);try{const b=await window.markusDesktop.setLoginItemSettings(i);w(!!b.openAtLogin)}catch{w(!i)}finally{K(!1)}},[v,A]),[S,g]=l.useState(null),[h,N]=l.useState(null),[E,O]=l.useState(""),[U,_]=l.useState(!1),[D,R]=l.useState(null),[P,f]=l.useState(null),[k,$]=l.useState(null),[J,Z]=l.useState({}),[ne,I]=l.useState(null),[H,q]=l.useState(null),[m,L]=l.useState(null),[V,X]=l.useState(!1),[ee,Q]=l.useState(null),[Y,le]=l.useState({}),[Ee,dt]=l.useState(!1),[pe,Xe]=l.useState(null),[He,ct]=l.useState(!1),[M,ie]=l.useState(""),[ue,Ke]=l.useState(!1),[qe,Se]=l.useState(null),[Ds,Ks]=l.useState(""),[Ie,Mt]=l.useState(!0),[Ne,Tn]=l.useState(null),[Us,Fs]=l.useState(!1),[Tt,ut]=l.useState(null),[$s,En]=l.useState([]),[Vs,Et]=l.useState([]),[Ze,ze]=l.useState(null),[It,ge]=l.useState(null),[xt,Hs]=l.useState(""),[In,et]=l.useState(null),[tt,Lt]=l.useState(null),xe=l.useRef(null),qs=l.useRef(!1),[zs,Rt]=l.useState(200),[Ws,Gs]=l.useState(!1),[Ot,mt]=l.useState(null),[gt,Bt]=l.useState(!1),[Ys,_t]=l.useState(1),[Js,Qs]=l.useState(!1),[Dt,st]=l.useState(null),[Kt,ft]=l.useState(!1),[Le,Ut]=l.useState(0),[Ft,pt]=l.useState(!0),[Re,ht]=l.useState(!1),[be,Xs]=l.useState(!1),[ko,Ln]=l.useState(9333),[ye,he]=l.useState(!1),[$t,de]=l.useState(null),[Me,Rn]=l.useState(null),[Vt,Zs]=l.useState(!1),[bt,On]=l.useState(null),[Co,So]=l.useState(!1),ae=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`}),er=l.useRef(new Set),tr=l.useCallback(()=>{F.health().then(g).catch(()=>{})},[]),Oe=l.useCallback(()=>{fetch("/api/settings/llm").then(i=>i.ok?i.json():Promise.reject(i.status)).then(i=>{i&&typeof i=="object"&&"providers"in i&&(N(i),O(i.defaultProvider))}).catch(()=>{})},[]),rt=l.useCallback(()=>{fetch("/api/settings/network").then(i=>i.ok?i.json():Promise.reject(i.status)).then(i=>{Ks(i.network?.proxy??""),Mt(i.network?.proxyEnabled!==!1),Tn(i.effective)}).catch(()=>{})},[]),sr=l.useCallback(()=>{fetch("/api/settings/oauth/providers").then(i=>i.ok?i.json():Promise.reject(i.status)).then(i=>En(i.providers??[])).catch(()=>{})},[]),yt=l.useCallback((i=!1)=>{fetch(`/api/settings/oauth/profiles${i?"?validate=1":""}`,{headers:ae()}).then(B=>B.ok?B.json():Promise.reject(B.status)).then(B=>Et(B.profiles??[])).catch(()=>{})},[]),rr=l.useCallback(()=>{F.settings.getAgent().then(i=>{i&&typeof i.maxToolIterations=="number"&&Rt(i.maxToolIterations),i?.cognitive&&(Bt(i.cognitive.enabled??!1),_t(i.cognitive.maxDepth??1))}).catch(()=>{})},[]),nr=l.useCallback(()=>{F.settings.getBrowser().then(i=>{i&&(ft(i.bringToFront??!1),Ut(i.remoteDebuggingPort??0),pt(i.autoCloseTabs??!0),ht(i.autoClickAllowDialog??!1),Xs(i.extensionConnected??!1),Ln(i.extensionBridgePort??9333))}).catch(()=>{})},[]),We=l.useCallback(()=>{Zs(!0),F.system.storage().then(Rn).catch(()=>{}).finally(()=>Zs(!1)),F.system.orphans().then(On).catch(()=>{})},[]);l.useEffect(()=>{tr()},[tr]),l.useEffect(()=>{if(x&&!er.current.has(x))switch(er.current.add(x),x){case"providers":Oe(),rt(),sr(),yt(!0);break;case"execution":rr();break;case"browser":nr();break;case"storage":We();break}},[x,Oe,rt,sr,yt,rr,nr,We]),l.useEffect(()=>{const i=()=>We();return window.addEventListener("markus:data-changed",i),()=>window.removeEventListener("markus:data-changed",i)},[We]),l.useEffect(()=>{!P||J[P]||(I(P),P==="markus"&&q(null),F.modelCatalog.getLive(P).then(i=>{Z(b=>({...b,[P]:i.models})),P==="markus"&&(i.error&&q(String(i.error)),Oe())}).catch(i=>{P==="markus"&&q(i instanceof Error?i.message:String(i)),F.modelCatalog.getByProvider(P).then(b=>{Z(B=>({...B,[P]:b.models}))}).catch(()=>{})}).finally(()=>I(null)))},[P]);const Ht=l.useCallback(async()=>{X(!0),Q(null),L(null),le({});try{const i=await fetch("/api/settings/env-models",{headers:ae()});if(!i.ok){Q({type:"err",text:t("envConfig.detectionFailedHttp",{status:i.status})});return}const b=await i.json();if(L(b),b.detected.length===0)Q({type:"err",text:t("envConfig.noKeysFound")});else{const B={};for(const G of b.detected)B[G.provider]=!0;le(B)}}catch{Q({type:"err",text:t("envConfig.failedToDetect")})}finally{X(!1)}},[t]),qt=l.useCallback(async()=>{ct(!0),Se(null),Xe(null);try{const i=await fetch("/api/settings/detect-ollama",{headers:ae()});if(!i.ok){Se({type:"err",text:t("ollama.detectFailed")});return}const b=await i.json();Xe(b),b.found&&b.models&&b.models.length>0?ie(b.models[0].name):b.found||Se({type:"err",text:b.error||t("ollama.notRunning")})}catch{Se({type:"err",text:t("ollama.detectFailed")})}finally{ct(!1)}},[t]),ar=h?Object.values(h.providers).some(i=>i.configured):!1;l.useEffect(()=>{h&&!ar&&!qs.current&&(qs.current=!0,Ht(),qt())},[h,ar,Ht,qt]);const Bn=async()=>{if(!(!E||E===h?.defaultProvider)){_(!0),R(null);try{const i=await fetch("/api/settings/llm",{method:"POST",headers:ae(),body:JSON.stringify({defaultProvider:E})}),b=await i.json();i.ok?(N(b),R({type:"ok",text:t("defaultProvider.updated",{name:b.defaultProvider})})):R({type:"err",text:b.error??t("modelProviders.saveFailed")})}catch{R({type:"err",text:t("common:networkError")})}finally{_(!1)}}},_n=async(i,b)=>{$(i);try{const B=await fetch(`/api/settings/llm/providers/${i}/toggle`,{method:"POST",headers:ae(),body:JSON.stringify({enabled:b})});if(B.ok){const G=await B.json();N(G)}}catch{}finally{$(null)}},Dn=async()=>{if(!m)return;const i=m.detected.filter(b=>Y[b.provider]);if(i.length===0){Q({type:"err",text:t("envConfig.selectAtLeastOne")});return}dt(!0),Q(null);try{const b=await fetch("/api/settings/env-models",{method:"POST",headers:ae(),body:JSON.stringify({providers:i.map(G=>({provider:G.provider,model:G.model,baseUrl:G.baseUrl,enabled:!0}))})});if(!b.ok){Q({type:"err",text:t("envConfig.applyFailed",{status:b.status})});return}const B=await b.json();Q({type:"ok",text:B.message}),L(null),le({}),Oe()}catch{Q({type:"err",text:t("envConfig.failedToApply")})}finally{dt(!1)}},Kn=async()=>{if(!(!pe?.found||!M)){Ke(!0),Se(null);try{const i=await fetch("/api/settings/llm/providers",{method:"POST",headers:ae(),body:JSON.stringify({name:"ollama",model:M,baseUrl:pe.baseUrl||"http://localhost:11434"})});if(i.ok){const b=await i.json();N(b),Se({type:"ok",text:t("ollama.configured",{model:M})}),Xe(null)}else{const b=await i.json();Se({type:"err",text:b.error||t("ollama.applyFailed")})}}catch{Se({type:"err",text:t("ollama.applyFailed")})}finally{Ke(!1)}}},or=async i=>{ze(i),ge(null);try{const b=await fetch("/api/settings/oauth/login",{method:"POST",headers:ae(),body:JSON.stringify({provider:i})}),B=await b.json();if(!b.ok||B.error){ge({type:"err",text:B.error??t("oauth.loginFailed")});return}B.authorizeUrl&&(window.open(B.authorizeUrl,"_blank","noopener"),et(i),ge({type:"ok",text:t("browserOpened")}),xe.current&&clearInterval(xe.current),xe.current=setInterval(async()=>{try{const re=await(await fetch(`/api/settings/oauth/status?provider=${i}`,{headers:ae()})).json();!re.pending&&re.profiles.some(W=>W.provider===i&&W.hasOAuth)&&(xe.current&&clearInterval(xe.current),xe.current=null,et(null),Et(re.profiles),ge({type:"ok",text:t("oauthConnected",{provider:i})}),Oe())}catch{}},2e3))}catch{ge({type:"err",text:t("oauth.networkErrorDuringLogin")})}finally{ze(null)}},Un=async i=>{ze(i),ge(null),Lt(null);try{const b=await fetch("/api/settings/oauth/device-code",{method:"POST",headers:ae(),body:JSON.stringify({provider:i})}),B=await b.json();if(!b.ok||B.error){ge({type:"err",text:B.error??t("oauthAuth.deviceCodeFailed")});return}B.userCode&&B.verificationUri&&(Lt({userCode:B.userCode,verificationUri:B.verificationUri,provider:i}),et(i),ge({type:"ok",text:t("oauthAuth.deviceInstructions")}),xe.current&&clearInterval(xe.current),xe.current=setInterval(async()=>{try{const re=await(await fetch(`/api/settings/oauth/status?provider=${i}`,{headers:ae()})).json();!re.pending&&re.profiles.some(W=>W.provider===i&&W.hasOAuth)&&(xe.current&&clearInterval(xe.current),xe.current=null,et(null),Lt(null),Et(re.profiles),ge({type:"ok",text:t("oauthConnected",{provider:i})}),Oe())}catch{}},3e3))}catch{ge({type:"err",text:t("oauth.networkErrorDuringLogin")})}finally{ze(null)}},Fn=async()=>{if(xt.trim()){ze("manual"),ge(null);try{const i=await fetch("/api/settings/oauth/callback",{method:"POST",headers:ae(),body:JSON.stringify({callbackUrl:xt})}),b=await i.json();if(!i.ok||b.error){ge({type:"err",text:b.error??t("oauth.callbackFailed")});return}ge({type:"ok",text:t("oauthConnected",{provider:b.profile?.provider??t("common:unknown")})}),Hs(""),et(null),xe.current&&(clearInterval(xe.current),xe.current=null),yt(),Oe()}catch{ge({type:"err",text:t("common:networkError")})}finally{ze(null)}}},$n=async i=>{try{(await fetch(`/api/settings/oauth/profiles/${encodeURIComponent(i)}`,{method:"DELETE",headers:ae()})).ok&&(yt(),Oe(),ge({type:"ok",text:t("authProfileDeleted")}))}catch{}};l.useEffect(()=>()=>{xe.current&&clearInterval(xe.current)},[]),l.useEffect(()=>{if(x!=="browser"||be)return;const i=setInterval(async()=>{try{(await F.settings.getBrowser()).extensionConnected&&(Xs(!0),clearInterval(i))}catch{}},5e3);return()=>clearInterval(i)},[x,be]);const[Vn,zt]=l.useState(!1),[te,Be]=l.useState({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),[vt,ir]=l.useState(!1),[Wt,lr]=l.useState(null),[Gt,Ue]=l.useState([]),[Hn,dr]=l.useState(!1),[qn,Yt]=l.useState(null),[ce,Jt]=l.useState({apiKey:"",baseUrl:"",model:"",contextWindow:0,maxOutputTokens:0,costInput:0,costOutput:0}),[cr,ur]=l.useState(!1),[xr,mr]=l.useState(null),[Qt,Xt]=l.useState(null),[Te,Ge]=l.useState(""),[gr,fr]=l.useState(!1),[Zt,ve]=l.useState(null),[pr,jt]=l.useState(null),[we,Nt]=l.useState({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1}),[zn,hr]=l.useState(!1),br=async(i,b)=>{if(!i||i==="__custom__")return;dr(!0),ve(null);const B=Ct.find(re=>re.id===i),G=te.baseUrl||B?.baseUrl;try{if(b){const re=await F.modelCatalog.validateKey(i,b,G||void 0);!re.valid&&re.error&&ve({type:"err",text:re.error}),Ue(re.models)}else{const re=await F.modelCatalog.getByProvider(i);Ue(re.models)}}catch{Ue([])}finally{dr(!1)}},yr=async()=>{if(!(!te.name||!te.model)){ir(!0),lr(null),ve(null);try{const i=await fetch("/api/settings/llm/providers",{method:"POST",headers:ae(),body:JSON.stringify({name:te.name,apiKey:te.apiKey||void 0,baseUrl:te.baseUrl||void 0,model:te.model,contextWindow:te.contextWindow||void 0,maxOutputTokens:te.maxOutputTokens||void 0,cost:te.costInput||te.costOutput?{input:te.costInput,output:te.costOutput}:void 0})}),b=await i.json();i.ok?(N(b),zt(!1),Ge(""),Ue([]),Be({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),ve({type:"ok",text:t("modelProviders.providerAdded",{name:te.name})})):ve({type:"err",text:b.error??t("modelProviders.failedToAdd")})}catch{ve({type:"err",text:t("common:networkError")})}finally{ir(!1)}}},Wn=async(i,b)=>{if(!Te.trim())return;fr(!0),ve(null);const B=Ct.find(W=>W.id===i),G=B?.defaultModel??i,re=B?.baseUrl;try{const W=await fetch("/api/settings/llm/providers",{method:"POST",headers:ae(),body:JSON.stringify({name:i,apiKey:Te.trim(),model:G,baseUrl:re})}),fe=await W.json();W.ok?(N(fe),Ge(""),Ue([]),ve({type:"ok",text:t("modelProviders.quickSetupSuccess",{name:B?.label??i})})):ve({type:"err",text:fe.error??t("modelProviders.failedToAdd")})}catch{ve({type:"err",text:t("common:networkError")})}finally{fr(!1)}},Gn=(i,b)=>{Yt(i),Jt({apiKey:"",baseUrl:b.baseUrl??"",model:b.model,contextWindow:b.contextWindow??0,maxOutputTokens:b.maxOutputTokens??0,costInput:b.cost?.input??0,costOutput:b.cost?.output??0})},Yn=async i=>{ur(!0);try{const b={};ce.apiKey&&(b.apiKey=ce.apiKey),ce.baseUrl!==void 0&&(b.baseUrl=ce.baseUrl),ce.model&&(b.model=ce.model),ce.contextWindow&&(b.contextWindow=ce.contextWindow),ce.maxOutputTokens&&(b.maxOutputTokens=ce.maxOutputTokens),(ce.costInput||ce.costOutput)&&(b.cost={input:ce.costInput,output:ce.costOutput});const B=await fetch(`/api/settings/llm/providers/${i}`,{method:"PUT",headers:ae(),body:JSON.stringify(b)});if(B.ok){const G=await B.json();N(G),Yt(null)}}catch{}finally{ur(!1)}},Jn=async i=>{mr(i);try{const b=await fetch(`/api/settings/llm/providers/${i}`,{method:"DELETE",headers:ae()});if(b.ok){const B=await b.json();N(B),O(B.defaultProvider)}}catch{}finally{mr(null)}},Qn=async i=>{if(!(!we.id||!we.name)){hr(!0);try{const b=await fetch(`/api/settings/llm/providers/${i}/models`,{method:"POST",headers:ae(),body:JSON.stringify({id:we.id,name:we.name,contextWindow:we.contextWindow,maxOutputTokens:we.maxOutputTokens,cost:{input:we.costInput,output:we.costOutput},reasoning:we.reasoning||void 0,inputTypes:we.vision?["text","image"]:["text"]})});if(b.ok){const B=await b.json();N(B),jt(null),Nt({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})}}catch{}finally{hr(!1)}}},Xn=async(i,b)=>{try{const B=await fetch(`/api/settings/llm/providers/${i}/models/${encodeURIComponent(b)}`,{method:"DELETE",headers:ae()});if(B.ok){const G=await B.json();N(G)}}catch{}},[vr,jr]=l.useState(null),[se,wt]=l.useState({}),Zn=async i=>{jr(i),wt(b=>{const B={...b};return delete B[i],B});try{const b=await fetch(`/api/settings/llm/providers/${i}/test`,{method:"POST",headers:ae()});if(!b.ok){const G=await b.json().catch(()=>({}));wt(re=>({...re,[i]:{ok:!1,error:G.error??`HTTP ${b.status}`,errorCode:b.status}}));return}const B=await b.json();wt(G=>({...G,[i]:B}))}catch{wt(b=>({...b,[i]:{ok:!1,error:t("common:networkError")}}))}finally{jr(null)}},Nr=h?.providers?Object.entries(h.providers).filter(([,i])=>i.configured&&i.enabled).map(([i])=>i):[],wr=o?.role==="owner"||o?.role==="admin",es=Mn.filter(i=>!i.adminOnly||wr);return e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsxs("aside",{className:"hidden md:flex flex-col w-56 shrink-0 border-r border-border-default bg-surface-secondary overflow-y-auto",children:[e.jsx("div",{"data-electron-drag":!0,className:"electron-mac-top-safe px-3 pt-4 pb-2",children:e.jsxs("button",{"data-no-drag":!0,onClick:()=>{ss.navigate(rs.HOME)},className:"flex items-center gap-2 px-2 py-1.5 rounded-lg text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-overlay transition-colors",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 12H5"}),e.jsx("polyline",{points:"12 19 5 12 12 5"})]}),t("common:back",{defaultValue:"Back"})]})}),e.jsx("div",{className:"px-5 pb-4",children:e.jsx("h2",{className:"text-base font-semibold text-fg-primary",children:t("title")})}),e.jsx("nav",{className:"flex-1 px-3 pb-4 space-y-3",children:cn.map(i=>{const b=i.tabs.map(B=>es.find(G=>G.id===B)).filter(B=>!!B);return b.length===0?null:e.jsxs("div",{children:[e.jsx("div",{className:"px-3 pb-1 pt-1 text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary",children:t(`settings:${i.labelKey}`)}),e.jsx("div",{className:"space-y-0.5",children:b.map(B=>e.jsxs("button",{onClick:()=>y(B.id),className:`w-full flex items-center gap-2.5 text-left px-3 py-2 rounded-lg text-sm font-medium transition-colors text-fg-primary ${x===B.id?"bg-surface-overlay":"hover:bg-surface-overlay/60"}`,children:[e.jsx(xn,{id:B.id,className:x===B.id?"text-fg-secondary":"text-fg-tertiary"}),e.jsx("span",{className:"truncate",children:t(`settings:${B.labelKey}`)})]},B.id))})]},i.labelKey)})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[c&&x===null&&e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary",children:[e.jsx("button",{onClick:()=>ss.navigate(rs.HOME),className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 12H5"}),e.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),e.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:t("title")})]}),e.jsx("nav",{className:"flex-1 overflow-y-auto py-2 px-3",children:cn.map((i,b)=>{const B=i.tabs.map(G=>es.find(re=>re.id===G)).filter(G=>!!G);return B.length===0?null:e.jsxs("div",{children:[b>0&&e.jsx("div",{className:"border-t border-border-default my-2 mx-2"}),e.jsx("div",{className:"px-4 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary",children:t(`settings:${i.labelKey}`)}),B.map(G=>e.jsxs("button",{onClick:()=>y(G.id),className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg text-sm text-fg-primary hover:bg-surface-overlay transition-colors",children:[e.jsx(xn,{id:G.id,className:"text-fg-tertiary"}),e.jsx("span",{className:"flex-1 text-left",children:t(`settings:${G.labelKey}`)}),e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:e.jsx("polyline",{points:"9 18 15 12 9 6"})})]},G.id))]},i.labelKey)})})]}),c&&x!==null&&e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary sticky top-0 z-10",children:[e.jsx("button",{onClick:T,className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 12H5"}),e.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),e.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:t(`settings:${es.find(i=>i.id===x)?.labelKey||"title"}`)})]}),x!==null&&e.jsxs("div",{className:"p-7 space-y-10 max-w-4xl mx-auto w-full",children:[x==="appearance"&&e.jsxs(e.Fragment,{children:[e.jsx(Ce,{title:t("systemStatus.title"),children:S?e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(Ls,{label:t("systemStatus.status"),value:S.status==="ok"?t("systemStatus.healthy"):S.status,color:"green"}),e.jsx(Ls,{label:t("systemStatus.version"),value:S.version,color:"indigo"}),e.jsx(Ls,{label:t("systemStatus.activeAgents"),value:String(S.agents),color:"purple"})]}):e.jsx("div",{className:"text-sm text-fg-tertiary",children:t("common:loading")})}),e.jsx(Ce,{title:t("appearance.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("appearance.theme")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("appearance.themeDesc")})]}),e.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:ra.map(({value:i})=>e.jsx("button",{onClick:()=>r?.(i),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${s===i?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:t(`appearance.modes.${i}`)},i))})]}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between mt-5 pt-5 border-t border-border-default/50",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("appearance.language")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("appearance.languageDesc")})]}),e.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:Cr.map(({code:i,label:b})=>e.jsx("button",{onClick:()=>{d.changeLanguage(i),F.settings.updateSearch({language:i}).catch(()=>{})},className:`px-3 py-1.5 text-xs rounded-md transition-colors ${d.language===i||i==="en"&&!Cr.some(B=>B.code===d.language)?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:b},i))})]}),kr()&&e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between mt-5 pt-5 border-t border-border-default/50",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("appearance.launchAtLogin")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("appearance.launchAtLoginDesc")})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":v,disabled:A,onClick:()=>{j()},className:`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors disabled:opacity-50 ${v?"bg-brand-600":"bg-surface-elevated border border-border-default"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow transition-transform ${v?"translate-x-6":"translate-x-1"}`})})]})]})})]}),wr&&e.jsxs(e.Fragment,{children:[x==="providers"&&e.jsxs(e.Fragment,{children:[h&&(()=>{const i=[],b=new Set,B=[],G=[];for(const[C,z]of Object.entries(h.providers))z.configured?B.push([C,z]):C!=="markus"&&G.push([C,z]),b.add(C);for(const C of Ct)!b.has(C.id)&&C.id!=="markus"&&(G.push([C.id,{name:C.id,displayName:C.label,model:C.defaultModel,configured:!1,enabled:!1}]),b.add(C.id));B.sort((C,z)=>(z[1].enabled?1:0)-(C[1].enabled?1:0)),i.push(...B,...G);const re=B.length>0,fe=h.providers.markus?.configured??!1;return e.jsxs(e.Fragment,{children:[!fe&&e.jsx(Ce,{title:"Markus Cloud AI",children:e.jsxs("div",{className:"bg-surface-secondary border border-brand-500/30 rounded-xl overflow-hidden transition-colors hover:border-brand-500/50",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer",onClick:()=>{f(P==="markus"?null:"markus"),Ge(""),ve(null)},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-brand-500 shadow-[0_0_6px_rgba(99,102,241,0.4)]"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Markus Cloud AI"}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("modelProviders.markusHint")})]})]}),e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${P==="markus"?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),P==="markus"&&e.jsxs("div",{className:"px-5 pb-5 space-y-3 border-t border-border-default/50",children:[e.jsx("p",{className:"text-xs text-fg-tertiary pt-3",children:t("modelProviders.markusSetupLogin")}),e.jsx("button",{onClick:()=>ss.navigate(rs.SETTINGS,{tab:"account"}),className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-lg transition-colors",children:t("modelProviders.goToAccount")})]})]})}),e.jsxs(fo,{title:t("modelProviders.title"),defaultCollapsed:re,configuredProviders:B,t,onBadgeClick:C=>{f(C),Ge(""),ve(null),setTimeout(()=>{document.querySelector(`[data-provider-id="${C}"]`)?.scrollIntoView({behavior:"smooth",block:"center"})},80)},children:[e.jsxs("div",{className:"space-y-3",children:[re&&e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider px-1",children:t("modelProviders.groupConfigured",{count:B.length})}),i.map(([C,z],kt)=>{const ts=!z.configured&&(kt===0||i[kt-1][1].configured);return e.jsxs("div",{"data-provider-id":C,children:[ts&&re&&e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider px-1 mt-4 mb-2",children:t("modelProviders.groupUnconfigured")}),e.jsxs("div",{className:`bg-surface-secondary border rounded-xl overflow-hidden transition-colors ${z.configured?"border-border-default hover:border-gray-600":"border-border-default/50 hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer",onClick:()=>{f(P===C?null:C),Ge(""),ve(null),Ue([]),Be(oe=>({...oe,name:"",model:""}))},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${z.configured&&z.enabled?"bg-green-400":z.configured?"bg-amber-400":"bg-gray-600"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:z.displayName??C}),C===h.defaultProvider&&e.jsx("span",{className:"text-[10px] bg-brand-500/15 text-brand-500 px-1.5 py-0.5 rounded",children:t("modelProviders.badgeDefault")}),z.configured&&!z.enabled&&e.jsx("span",{className:"text-[10px] bg-amber-500/15 text-amber-600 px-1.5 py-0.5 rounded",children:t("modelProviders.disabled")}),z.oauthConnected&&e.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:t("modelProviders.badgeOAuth")}),se[C]?.ok===!0&&e.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:t("modelProviders.testOk",{ms:se[C].durationMs})}),se[C]?.ok===!1&&e.jsx("span",{className:"text-[10px] bg-red-500/15 text-red-500 px-1.5 py-0.5 rounded",title:se[C].error,children:se[C].errorCode?t("modelProviders.testFailedCode",{code:se[C].errorCode}):t("modelProviders.testFailed")})]}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:z.configured?e.jsxs(e.Fragment,{children:[z.models&&z.models.length>0?t("modelProviders.modelsAvailable",{count:z.models.length}):"",C!=="markus"&&z.apiKeyPreview&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:"text-fg-secondary",children:z.apiKeyPreview})]})]}):t("modelProviders.notConfigured")})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[z.configured&&e.jsx("button",{onClick:oe=>{oe.stopPropagation(),_n(C,!z.enabled)},disabled:k===C,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${z.enabled?"bg-green-500":"bg-gray-600"} ${k===C?"opacity-50":""}`,title:z.enabled?t("modelProviders.clickToDisable"):t("modelProviders.clickToEnable"),children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${z.enabled?"translate-x-4":"translate-x-1"}`})}),e.jsx("span",{className:"text-fg-tertiary text-xs",children:P===C?"▲":"▼"})]})]}),P===C&&e.jsxs("div",{className:"px-5 pb-4 border-t border-border-default pt-4 space-y-4",children:[z.configured&&e.jsxs(e.Fragment,{children:[qn===C?e.jsxs("div",{className:"bg-surface-elevated/40 rounded-lg p-4 space-y-3",children:[e.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("modelProviders.editProvider")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.apiKey")}),e.jsx("input",{type:"password",value:ce.apiKey,onChange:oe=>Jt({...ce,apiKey:oe.target.value}),placeholder:t("modelProviders.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.baseUrl")}),e.jsx("input",{type:"text",value:ce.baseUrl,onChange:oe=>Jt({...ce,baseUrl:oe.target.value}),placeholder:t("modelProviders.baseUrlDisplayDefault"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{Yn(C)},disabled:cr,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(cr?"common:saving":"common:save")}),e.jsx("button",{onClick:()=>Yt(null),className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:t("common:cancel")})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:oe=>{oe.stopPropagation(),Zn(C)},disabled:vr===C,className:"px-3 py-1.5 text-xs border border-green-500/30 text-green-500 hover:bg-green-500/10 rounded-lg transition-colors disabled:opacity-40 flex items-center gap-1.5",children:vr===C?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}),t("modelProviders.testing")]}):t("modelProviders.test")}),C!=="markus"&&e.jsx("button",{onClick:oe=>{oe.stopPropagation(),Gn(C,z)},className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:t("common:edit")}),C!=="markus"&&e.jsx("button",{onClick:oe=>{oe.stopPropagation(),Xt({name:C,label:z.displayName??C})},disabled:xr===C,className:"px-3 py-1.5 text-xs border border-red-500/30 text-red-400 hover:bg-red-500/10 rounded-lg transition-colors disabled:opacity-40",children:t(xr===C?"common:deleting":"common:delete")})]}),se[C]&&e.jsxs("details",{className:`text-xs rounded-lg border ${se[C].ok?"bg-green-500/10 border-green-500/30":"bg-red-500/10 border-red-500/30"}`,children:[e.jsx("summary",{className:`px-3 py-2 cursor-pointer select-none ${se[C].ok?"text-green-600":"text-red-500"}`,children:se[C].ok?t("modelProviders.testSuccess",{ms:se[C].durationMs,reply:se[C].reply}):se[C].error}),e.jsxs("div",{className:"px-3 pb-2 pt-1 space-y-1 text-[11px] text-fg-muted border-t border-current/10",children:[C!=="markus"&&se[C].requestUrl&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.requestUrl"),":"]})," ",e.jsx("code",{className:"font-mono text-fg-primary",children:se[C].requestUrl})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.model"),":"]})," ",e.jsx("code",{className:"font-mono text-fg-primary",children:se[C].model??z.model})]}),!!se[C].requestBody&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.requestBody"),":"]}),e.jsx("pre",{className:"mt-0.5 p-1.5 rounded bg-surface-primary/50 font-mono overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(se[C].requestBody,null,2)})]}),se[C].ok&&se[C].reply&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.response"),":"]})," ",se[C].reply]}),se[C].usage&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.tokens"),":"]})," ",t("modelProviders.testDetail.inputTokens")," ",se[C].usage.inputTokens??se[C].usage.prompt_tokens??"-"," / ",t("modelProviders.testDetail.outputTokens")," ",se[C].usage.outputTokens??se[C].usage.completion_tokens??"-"]}),se[C].durationMs!=null&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.duration"),":"]})," ",se[C].durationMs,"ms"]})]})]})]}),C==="markus"&&z.configured&&e.jsxs("div",{className:"bg-green-500/5 border border-green-500/20 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400 shadow-[0_0_4px_rgba(74,222,128,0.4)]"}),e.jsx("span",{className:"text-sm font-medium text-green-400",children:t("modelProviders.markusConnected")})]}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-2",children:t("modelProviders.markusConnectedHint")})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("modelProviders.availableModels")}),z.configured&&C!=="markus"&&pr!==C&&e.jsx("button",{onClick:()=>{jt(C),Nt({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})},className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:t("modelProviders.addModel")})]}),pr===C&&e.jsx("div",{className:"bg-surface-elevated/40 rounded-lg p-3 mb-2 space-y-2",children:e.jsx(go,{providerName:C,addModelForm:we,setAddModelForm:Nt,addModelSaving:zn,onAdd:()=>{Qn(C)},onCancel:()=>jt(null),t})}),C==="markus"&&z.configured&&(!z.models||z.models.length===0)&&(ne===C?e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-xs text-fg-tertiary",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t("modelProviders.loadingHubCatalog")]}):e.jsx("div",{className:"mt-1 text-xs text-amber-400/90",children:H?t("modelProviders.hubCatalogError",{error:H}):t("modelProviders.hubCatalogEmpty")})),z.models&&z.models.length>0&&e.jsx(xo,{models:z.models,providerName:C,activeModelId:z.model,t,onDeleteCustom:oe=>{Xn(C,oe)}}),z.configured&&ne===C&&e.jsxs("div",{className:"flex items-center gap-2 mt-2 text-xs text-fg-tertiary",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t("modelProviders.loadingCatalog")]}),z.configured&&J[C]&&J[C].length>0&&(()=>{const oe=new Set(z.models?.map(je=>je.id)??[]),_e=J[C].filter(je=>!oe.has(String(je.id??"")));return _e.length===0?null:e.jsx(mo,{models:_e,providerName:C,t,onAdd:je=>{const ke=_e.find(ea=>String(ea.id??"")===je);ke&&(jt(C),Nt({id:String(ke.id??""),name:String(ke.id??""),contextWindow:ke.maxInputTokens??128e3,maxOutputTokens:ke.maxOutputTokens??16384,costInput:ke.inputCostPer1MTokens??1,costOutput:ke.outputCostPer1MTokens??5,reasoning:ke.capabilities?.reasoning??!1,vision:ke.capabilities?.vision??!1}))}})})()]}),!z.configured&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-fg-secondary",children:t("modelProviders.quickSetupHint")}),C==="markus"&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 rounded-lg bg-brand-600/8 border border-brand-500/15 text-xs text-fg-secondary",children:[e.jsx("svg",{className:"w-4 h-4 shrink-0 text-brand-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("span",{children:[t("modelProviders.markusKeyHint")," ",e.jsx("a",{href:`${Fe.getUrl()}/settings`,target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-400 underline underline-offset-2",children:t("modelProviders.markusKeyLink")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.apiKey")}),e.jsx("input",{type:"password",value:P===C?Te:"",onChange:oe=>Ge(oe.target.value),placeholder:t("modelProviders.quickSetupPlaceholder"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none",onBlur:()=>{Te.trim().length>=8&&P===C&&br(C,Te.trim())},onKeyDown:oe=>{oe.key==="Enter"&&Te.trim().length>=8&&br(C,Te.trim())}}),Hn&&P===C&&e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-xs text-fg-tertiary",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t("modelProviders.validatingKey")]})]}),P===C&&Gt.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-2",children:t("modelProviders.selectModel")}),e.jsx(vn,{provider:C,models:Gt,selectedModel:te.model,showTiers:!0,onSelect:oe=>{const _e=Gt.find(je=>je.id===oe);Be(je=>({...je,name:C,model:oe,apiKey:Te.trim(),baseUrl:Ct.find(ke=>ke.id===C)?.baseUrl??"",contextWindow:_e?.maxInputTokens??je.contextWindow,maxOutputTokens:_e?.maxOutputTokens??je.maxOutputTokens,costInput:_e?.inputCostPer1MTokens??je.costInput,costOutput:_e?.outputCostPer1MTokens??je.costOutput}))},compact:!0,maxVisible:8})]}),P===C&&Te.trim()&&e.jsx("button",{onClick:()=>{te.model&&te.name===C?yr():Wn(C)},disabled:gr||vt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(gr||vt?"modelProviders.quickSetupSaving":"modelProviders.quickSetupSubmit")}),Zt&&P===C&&e.jsx(Ae,{type:Zt.type,text:Zt.text})]})]})]})]},C)})]}),Vn?e.jsxs("div",{className:"mt-3 bg-surface-secondary border border-brand-500/30 rounded-xl p-4 space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-fg-primary",children:t("modelProviders.customProvider")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.providerName")}),e.jsx("input",{type:"text",value:te.name==="__custom__"?"":te.name,onChange:C=>Be(z=>({...z,name:C.target.value||"__custom__"})),placeholder:"my-provider",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.baseUrl")}),e.jsx("input",{type:"text",value:te.baseUrl,onChange:C=>Be({...te,baseUrl:C.target.value}),placeholder:"https://api.example.com/v1",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.apiKey")}),e.jsx("input",{type:"password",value:te.apiKey,onChange:C=>Be({...te,apiKey:C.target.value}),placeholder:t("modelProviders.placeholderApiKeySk"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.defaultModel")}),e.jsx("input",{type:"text",value:te.model,onChange:C=>Be({...te,model:C.target.value}),placeholder:"gpt-4o",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{yr()},disabled:vt||!te.name||te.name==="__custom__"||!te.model,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(vt?"modelProviders.adding":"modelProviders.addProviderSubmit")}),e.jsx("button",{onClick:()=>{zt(!1),lr(null),Ue([]),Be({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5})},className:"px-4 py-2 text-sm border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:t("common:cancel")})]}),Wt&&e.jsx(Ae,{type:Wt.type,text:Wt.text})]}):e.jsxs("button",{onClick:()=>zt(!0),className:"w-full mt-3 px-4 py-2.5 border border-dashed border-border-default hover:border-brand-500/50 hover:bg-brand-500/5 rounded-xl text-xs text-fg-tertiary hover:text-brand-500 transition-colors",children:["+ ",t("modelProviders.customProvider")]})]})]})})(),e.jsx(Is,{title:t("autoDetect.title"),defaultOpen:!1,children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[e.jsx("div",{className:"text-sm text-fg-secondary",children:t("autoDetect.description")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:t("envConfig.title")}),e.jsxs("button",{onClick:()=>{Ht()},disabled:V,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${V?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),t(V?"common:detecting":"envConfig.refreshEnv")]})]}),m&&m.detected.length>0&&e.jsxs("div",{className:"space-y-2",children:[m.detected.map(i=>e.jsxs("label",{className:"flex items-center justify-between bg-surface-elevated/30 rounded-lg px-4 py-3 cursor-pointer hover:bg-surface-elevated/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:Y[i.provider]??!1,onChange:b=>le({...Y,[i.provider]:b.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary font-medium",children:i.displayName}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[t("envConfig.keyLabel")," ",e.jsx("code",{className:"text-fg-secondary",children:i.apiKeyPreview})," / ",t("envConfig.modelLabel")," ",e.jsx("code",{className:"text-fg-secondary",children:i.model}),i.baseUrl&&e.jsxs(e.Fragment,{children:[" / ",t("envConfig.urlLabel")," ",e.jsx("code",{className:"text-fg-secondary",children:i.baseUrl})]})]})]})]}),e.jsx("div",{className:"text-xs text-fg-tertiary",children:Object.keys(i.envVars).map(b=>e.jsx("div",{children:e.jsx("code",{children:b})},b))})]},i.provider)),m.timeoutMs&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("envConfig.llmTimeout",{ms:m.timeoutMs})}),e.jsx("button",{onClick:()=>{Dn()},disabled:Ee||Object.values(Y).filter(Boolean).length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:Ee?t("common:applying"):t("envConfig.applyToConfig",{count:Object.values(Y).filter(Boolean).length})})]}),ee&&e.jsx(Ae,{type:ee.type,text:ee.text})]}),e.jsx("div",{className:"border-t border-border-default"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:t("ollama.title")}),e.jsxs("button",{onClick:()=>{qt()},disabled:He,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${He?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),t(He?"common:detecting":"ollama.detect")]})]}),pe?.found&&pe.models&&pe.models.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-green-600",children:t("ollama.foundModels",{count:pe.models.length,url:pe.baseUrl})}),e.jsx("div",{className:"space-y-1",children:pe.models.map(i=>e.jsx("label",{className:`flex items-center justify-between rounded-lg px-4 py-3 cursor-pointer transition-colors ${M===i.name?"bg-brand-500/15 border border-brand-500/40":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"radio",name:"ollama-model",value:i.name,checked:M===i.name,onChange:()=>ie(i.name),className:"w-4 h-4 text-brand-500 focus:ring-brand-500"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary font-medium",children:i.name}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[i.parameterSize&&e.jsx("span",{children:i.parameterSize}),i.family&&e.jsx("span",{className:"ml-2",children:i.family}),i.quantization&&e.jsx("span",{className:"ml-2",children:i.quantization}),i.size&&e.jsx("span",{className:"ml-2",children:Je(i.size)})]})]})]})},i.name))}),e.jsx("button",{onClick:()=>{Kn()},disabled:ue||!M,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:ue?t("common:applying"):t("ollama.useModel",{model:M})})]}),pe&&!pe.found&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:pe.error||t("ollama.notRunning")}),qe&&e.jsx(Ae,{type:qe.type,text:qe.text})]})]})}),e.jsx(Is,{title:t("oauthAuth.title"),defaultOpen:!1,children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.description")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[$s.map(i=>e.jsxs("div",{className:"flex",children:[e.jsx("button",{onClick:()=>or(i.name),disabled:!!Ze,className:"px-3 py-2 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-l-lg transition-colors",children:Ze===i.name?t("oauthAuth.connecting"):t("oauthAuth.signInWith",{name:i.displayName})}),e.jsx("button",{onClick:()=>Un(i.name),disabled:!!Ze,title:t("oauthAuth.deviceTitle"),className:"px-2.5 py-2 text-xs bg-surface-secondary text-fg-secondary border border-border-default border-l-0 rounded-r-lg hover:bg-surface-tertiary disabled:opacity-40 transition-colors",children:t("oauthAuth.device")})]},i.name)),$s.length===0&&e.jsx("span",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.noProviders")})]}),tt&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-secondary border border-border-default space-y-2",children:[e.jsx("p",{className:"text-xs text-fg-primary font-medium",children:t("oauthAuth.deviceCodeTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.deviceInstructions")}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("a",{href:tt.verificationUri,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-brand-500 underline hover:text-brand-400",children:tt.verificationUri}),e.jsx("code",{className:"px-2.5 py-1 text-sm font-mono font-bold bg-surface-elevated border border-border-default rounded-lg text-fg-primary select-all",children:tt.userCode})]}),e.jsx("p",{className:"text-[10px] text-fg-muted",children:t("oauthAuth.deviceWaiting")})]}),In&&!tt&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-secondary border border-border-default space-y-2",children:[e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.manualCallbackHint")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:xt,onChange:i=>Hs(i.target.value),placeholder:t("oauthAuth.manualPlaceholder"),className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-muted/50 focus:border-brand-500 outline-none"}),e.jsx("button",{onClick:Fn,disabled:!xt.trim()||Ze==="manual",className:"px-3 py-2 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t("oauthAuth.submit")})]})]}),It&&e.jsx(Ae,{type:It.type,text:It.text}),Vs.filter(i=>i.hasOAuth).length>0&&e.jsxs("div",{className:"space-y-2 border-t border-border-default pt-4",children:[e.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:t("oauthAuth.connectedAccounts")}),Vs.filter(i=>i.hasOAuth).map(i=>e.jsxs("div",{className:`flex items-center justify-between px-4 py-3 rounded-lg border ${i.oauthExpired?"bg-amber-500/5 border-amber-500/20":"bg-surface-secondary border-border-default"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${i.oauthExpired?"bg-amber-400":"bg-green-400"}`}),e.jsx("span",{className:"text-xs text-fg-primary font-medium",children:i.label??i.provider}),i.accountId&&e.jsxs("span",{className:"text-[10px] text-fg-muted",children:["(",i.accountId.slice(0,12),"...)"]}),i.oauthExpired&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md bg-amber-500/15 text-amber-600 font-medium",children:t("oauthAuth.expired")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[i.oauthExpired&&e.jsx("button",{onClick:()=>or(i.provider),disabled:!!Ze,className:"text-[10px] px-2 py-1 rounded-md text-brand-500 hover:text-brand-400 hover:bg-brand-500/10 transition-colors",children:t("oauthAuth.reconnect")}),e.jsx("button",{onClick:()=>$n(i.id),className:"text-[10px] px-2 py-1 rounded-md text-red-400 hover:text-red-300 hover:bg-red-500/10 transition-colors",children:t("oauthAuth.disconnect")})]})]},i.id))]})]})}),e.jsx(Ce,{title:t("defaultProvider.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("defaultProvider.primaryProvider")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("defaultProvider.primaryProviderDesc")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[h?e.jsx("select",{value:E,onChange:i=>{O(i.target.value),R(null)},className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm w-48 focus:border-brand-500 outline-none",children:Nr.length>0?Nr.map(i=>e.jsx("option",{value:i,children:h.providers[i]?.displayName??i},i)):e.jsx("option",{value:"",children:t("defaultProvider.noProviders")})}):e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("common:loading")}),E!==h?.defaultProvider&&e.jsx("button",{onClick:()=>{Bn()},disabled:U,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(U?"common:saving":"common:save")})]})]}),D&&e.jsx(Ae,{type:D.type,text:D.text}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("defaultProvider.autoFallback")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("defaultProvider.autoFallbackDesc")})]}),e.jsx("button",{onClick:async()=>{const i=!(h?.autoFallback??!1);try{const b=await fetch("/api/settings/llm",{method:"POST",headers:ae(),body:JSON.stringify({autoFallback:i})});if(b.ok){const B=await b.json();N(B)}}catch{}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${h?.autoFallback??!1?"bg-green-500":"bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${h?.autoFallback??!1?"translate-x-4":"translate-x-1"}`})})]})]})}),e.jsx(Ce,{title:t("modelRouting.title"),children:e.jsx(ua,{configuredProviders:Object.entries(h?.providers??{}).filter(([,i])=>i.configured&&i.enabled).map(([i,b])=>({name:i,displayName:b.displayName,model:b.model,models:b.models?.map(B=>({id:B.id,name:B.name}))})),onSave:async i=>{const b=await fetch("/api/settings/llm",{method:"POST",headers:ae(),body:JSON.stringify(i)});if(!b.ok)throw new Error(`HTTP ${b.status}`)}},h?.defaultProvider??"no-default")}),e.jsx(Is,{title:t("networkProxy.title"),defaultOpen:!1,children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{children:e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("networkProxy.description")})}),e.jsx("button",{onClick:async()=>{const i=!Ie;Mt(i);try{await fetch("/api/settings/network",{method:"POST",headers:ae(),body:JSON.stringify({proxyEnabled:i})}),rt()}catch{Mt(!i)}},className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors ${Ie?"bg-green-500":"bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Ie?"translate-x-4":"translate-x-1"}`})})]}),Ne&&e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2.5 rounded-lg bg-surface-secondary border border-border-default transition-opacity ${Ie?"":"opacity-50"}`,children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${Ie&&Ne.proxy?"bg-green-400":"bg-gray-600"}`}),e.jsx("span",{className:"text-xs text-fg-secondary",children:Ie?Ne.proxy?e.jsxs(e.Fragment,{children:[t("networkProxy.active")," ",e.jsx("code",{className:"text-fg-primary font-mono",children:Ne.proxy})]}):t("networkProxy.noProxy"):t("networkProxy.disabled")}),Ie&&Ne.source!=="none"&&Ne.source!=="disabled"&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md font-medium ${Ne.source==="config"?"bg-brand-500/15 text-brand-500":Ne.source==="env"?"bg-amber-500/15 text-amber-600":Ne.source==="system"?"bg-blue-500/15 text-blue-500":"bg-gray-500/15 text-fg-muted"}`,children:Ne.source==="config"?t("networkProxy.sourceConfig"):Ne.source==="env"?t("networkProxy.sourceEnv"):Ne.source==="system"?t("networkProxy.sourceSystem"):""}),e.jsxs("button",{onClick:()=>rt(),className:"ml-auto text-[10px] px-1.5 py-0.5 rounded-md text-fg-muted hover:text-fg-secondary hover:bg-surface-tertiary transition-colors",title:t("networkProxy.refresh"),children:["↻ ",t("networkProxy.refresh")]})]}),e.jsxs("div",{className:`flex gap-2 items-center transition-opacity ${Ie?"":"opacity-50 pointer-events-none"}`,children:[e.jsx("input",{type:"text",value:Ds,onChange:i=>Ks(i.target.value),placeholder:t("networkProxy.placeholder"),className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-muted/50 focus:border-brand-500 outline-none"}),e.jsx("button",{onClick:async()=>{Fs(!0),ut(null);try{const i=await fetch("/api/settings/network",{method:"POST",headers:ae(),body:JSON.stringify({proxy:Ds.trim()})});if(i.ok)ut({type:"ok",text:t("networkProxy.saved")}),rt();else{const b=await i.json();ut({type:"err",text:b.error??t("networkProxy.saveFailed")})}}catch{ut({type:"err",text:t("networkProxy.networkError")})}finally{Fs(!1)}},disabled:Us,className:"px-3 py-2 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(Us?"networkProxy.saving":"networkProxy.save")})]}),Tt&&e.jsx(Ae,{type:Tt.type,text:Tt.text})]})})]}),x==="execution"&&e.jsxs(e.Fragment,{children:[e.jsx(Ce,{title:t("agentExecution.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("agentExecution.maxToolIterations")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("agentExecution.maxToolIterationsDesc")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:0,value:zs,onChange:i=>{Rt(Number(i.target.value)),mt(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right"}),e.jsx("button",{disabled:Ws,onClick:async()=>{Gs(!0),mt(null);try{const i=await F.settings.updateAgent({maxToolIterations:zs});Rt(i.maxToolIterations),mt({type:"ok",text:t("agentExecution.saved")})}catch{mt({type:"err",text:t("agentExecution.failedToSave")})}Gs(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:t(Ws?"common:saving":"common:save")})]})]}),Ot&&e.jsx(Ae,{type:Ot.type,text:Ot.text})]})}),e.jsx(Ce,{title:t("cognitive.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("cognitive.description")}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("cognitive.enabled")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("cognitive.enabledDesc")})]}),e.jsx("button",{onClick:()=>{Bt(!gt),st(null)},className:`relative w-10 h-5 rounded-full transition-colors ${gt?"bg-brand-500":"bg-fg-quaternary"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform ${gt?"translate-x-5":""}`})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("cognitive.maxDepth")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("cognitive.maxDepthDesc")})]}),e.jsxs("select",{value:Ys,onChange:i=>{_t(Number(i.target.value)),st(null)},className:"px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary",children:[e.jsxs("option",{value:1,children:["D1 — ",t("cognitive.depthD1")]}),e.jsxs("option",{value:2,children:["D2 — ",t("cognitive.depthD2")]}),e.jsxs("option",{value:3,children:["D3 — ",t("cognitive.depthD3")]})]})]}),e.jsx("div",{className:"flex items-center justify-end gap-2",children:e.jsx("button",{disabled:Js,onClick:async()=>{Qs(!0),st(null);try{const i=await F.settings.updateAgent({cognitive:{enabled:gt,maxDepth:Ys}});Bt(i.cognitive.enabled),_t(i.cognitive.maxDepth??1),st({type:"ok",text:t("cognitive.saved")})}catch{st({type:"err",text:t("cognitive.failedToSave")})}Qs(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:t(Js?"common:saving":"common:save")})}),Dt&&e.jsx(Ae,{type:Dt.type,text:Dt.text})]})})]}),x==="browser"&&e.jsxs(e.Fragment,{children:[e.jsxs(Ce,{title:t("browserAutomation.title"),children:[e.jsxs("div",{className:`rounded-xl p-4 mb-4 flex items-start gap-3 ${be?"bg-green-500/10 border border-green-500/20":Le>0?"bg-blue-500/10 border border-blue-500/20":Re?"bg-amber-500/10 border border-amber-500/20":"bg-surface-elevated border border-border-default"}`,children:[e.jsx("div",{className:`mt-0.5 w-2.5 h-2.5 rounded-full shrink-0 ${be?"bg-green-400":Le>0?"bg-blue-400":Re?"bg-amber-400":"bg-gray-400"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:`text-sm font-semibold ${be?"text-green-400":Le>0?"text-blue-400":Re?"text-amber-400":"text-fg-secondary"}`,children:be?t("browserAutomation.modeExtension"):Le>0?t("browserAutomation.modeDebuggingPort",{port:Le}):t(Re?"browserAutomation.modeAutoClick":"browserAutomation.modeManual")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:be?t("browserAutomation.modeExtensionDesc"):Le>0?t("browserAutomation.modeDebuggingPortDesc"):t(Re?"browserAutomation.modeAutoClickDesc":"browserAutomation.modeManualDesc")})]})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4 mb-4",children:[e.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:t("browserAutomation.generalSettings")}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.bringToFront")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.bringToFrontDesc")})]}),e.jsx("button",{onClick:async()=>{const i=!Kt;ft(i),he(!0),de(null);try{const b=await F.settings.updateBrowser({bringToFront:i});ft(b.bringToFront),de({type:"ok",text:t(i?"browserAutomation.tabsForeground":"browserAutomation.tabsBackground")})}catch{de({type:"err",text:t("agentExecution.failedToSave")}),ft(!i)}he(!1)},disabled:ye,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Kt?"bg-green-500":"bg-gray-600"} ${ye?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Kt?"translate-x-4":"translate-x-1"}`})})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.autoCloseTabs")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.autoCloseTabsDesc")})]}),e.jsx("button",{onClick:async()=>{const i=!Ft;pt(i),he(!0),de(null);try{const b=await F.settings.updateBrowser({autoCloseTabs:i});pt(b.autoCloseTabs),de({type:"ok",text:t("agentExecution.saved")})}catch{de({type:"err",text:t("agentExecution.failedToSave")}),pt(!i)}he(!1)},disabled:ye,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Ft?"bg-green-500":"bg-gray-600"} ${ye?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Ft?"translate-x-4":"translate-x-1"}`})})]})]}),e.jsxs("div",{className:`rounded-xl p-5 mb-4 transition-colors ${be?"bg-green-500/5 border border-green-500/20":"bg-surface-elevated"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStatus")}),e.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",t("browserAutomation.modeRecommended"),")"]})]}),e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${be?"bg-green-500/20 text-green-400":"bg-gray-600/20 text-gray-400"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${be?"bg-green-400":"bg-gray-400"}`}),t(be?"browserAutomation.extensionConnected":"browserAutomation.extensionDisconnected")]})]}),e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("browserAutomation.extensionStatusDesc")}),be?e.jsxs("div",{className:"mt-3 flex items-center gap-1.5 text-xs text-green-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),t("browserAutomation.extensionActiveNote")]}):e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:t("browserAutomation.extensionSetupTitle")}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[e.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStep1")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.extensionStep1Desc")}),e.jsxs("button",{disabled:ye,onClick:async()=>{he(!0),de(null);try{await F.settings.downloadExtensionZip()}catch{de({type:"err",text:t("browserAutomation.extensionDownloadError")})}he(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),t(ye?"browserAutomation.extensionStep1Downloading":"browserAutomation.extensionStep1Btn")]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[e.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"2"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStep2")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.extensionStep2Desc")}),navigator.platform.toUpperCase().includes("WIN")?e.jsxs("div",{className:"mt-2 text-xs text-fg-secondary",children:[t("browserAutomation.extensionStep2Desc"),":",e.jsx("code",{className:"ml-1.5 px-1.5 py-0.5 bg-surface-elevated rounded text-fg-primary font-mono text-[11px] select-all",children:"chrome://extensions"})]}):e.jsxs("button",{disabled:ye,onClick:async()=>{he(!0),de(null);try{await F.settings.openExtensionsPage()}catch{de({type:"err",text:t("browserAutomation.extensionOpenError")})}he(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),t("browserAutomation.extensionStep2Btn")]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[e.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStep3")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.extensionStep3Desc")})]})]})]})]}),!be&&e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:t("browserAutomation.fallbackModes")}),e.jsx("div",{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 mr-4",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.autoClickAllowDialog")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.autoClickAllowDialogDesc")}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-2 space-y-0.5",children:[e.jsx("div",{children:t("browserAutomation.autoClickAllowDialogMacNote")}),e.jsx("div",{children:t("browserAutomation.autoClickAllowDialogWinNote")}),e.jsx("div",{children:t("browserAutomation.autoClickAllowDialogLinuxNote")})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{disabled:ye,onClick:async()=>{he(!0),de(null);try{const i=await F.settings.testAutoClick(),b={success:{type:"ok",text:t("browserAutomation.autoClickTestSuccess",{title:i.pageTitle||"example.com"})},no_permission:{type:"err",text:t("browserAutomation.autoClickTestNoPermission")},chrome_not_running:{type:"err",text:t("browserAutomation.autoClickTestChromeNotRunning")},unsupported:{type:"err",text:t("browserAutomation.autoClickTestUnsupported")},error:{type:"err",text:t("browserAutomation.autoClickTestError",{error:i.error||"unknown"})}};de(b[i.clickResult]??{type:"err",text:i.clickResult})}catch{de({type:"err",text:t("browserAutomation.autoClickTestError",{error:"request failed"})})}he(!1)},className:"px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:t(ye?"browserAutomation.autoClickTesting":"browserAutomation.autoClickTest")}),e.jsx("button",{onClick:async()=>{const i=!Re;ht(i),he(!0),de(null);try{const b=await F.settings.updateBrowser({autoClickAllowDialog:i});ht(b.autoClickAllowDialog),de({type:"ok",text:t("agentExecution.saved")})}catch{de({type:"err",text:t("agentExecution.failedToSave")}),ht(!i)}he(!1)},disabled:ye,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Re?"bg-green-500":"bg-gray-600"} ${ye?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Re?"translate-x-4":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"border-t border-border-default pt-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.remoteDebuggingPort")}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[t("browserAutomation.remoteDebuggingPortDescLead")," ",e.jsx("code",{className:"text-fg-secondary bg-surface-primary px-1 rounded",children:"--remote-debugging-port=9222"})," ",t("browserAutomation.remoteDebuggingPortDescTail")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:0,max:65535,value:Le,onChange:i=>{Ut(Number(i.target.value)),de(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right",placeholder:"0"}),e.jsx("button",{disabled:ye,onClick:async()=>{he(!0),de(null);try{const i=await F.settings.updateBrowser({remoteDebuggingPort:Le});Ut(i.remoteDebuggingPort),de({type:"ok",text:i.remoteDebuggingPort>0?t("browserAutomation.usingPort",{port:i.remoteDebuggingPort}):t("browserAutomation.usingAutoConnect")})}catch{de({type:"err",text:t("agentExecution.failedToSave")})}he(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:t(ye?"common:saving":"common:save")})]})]})})]}),$t&&e.jsx("div",{className:"mt-4",children:e.jsx(Ae,{type:$t.type,text:$t.text})})]}),!1]}),x==="search"&&e.jsx(no,{}),x==="storage"&&e.jsx(e.Fragment,{children:e.jsx(Ce,{title:t("dataStorage.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[Vt&&!Me&&e.jsx("div",{className:"text-sm text-fg-tertiary",children:t("dataStorage.scanning")}),Me&&(()=>{const i=[...Me.breakdown].filter(W=>W.size>0).sort((W,fe)=>fe.size-W.size),b=Math.max(Me.totalSize,1),G=i.filter(W=>Es[W.name]==="safe").reduce((W,fe)=>W+fe.size,0),re=W=>W==="safe"?"bg-fg-secondary/55":W==="caution"?"bg-fg-tertiary/45":"bg-fg-primary/25";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-2xl font-semibold tracking-tight text-fg-primary tabular-nums",children:Je(Me.totalSize,t)}),e.jsx("div",{className:"text-xs text-fg-tertiary font-mono mt-1 truncate",title:Me.dataDir,children:Me.dataDir})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>We(),disabled:Vt,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-primary/60 rounded-lg text-fg-secondary transition-colors disabled:opacity-40",children:t(Vt?"dataStorage.scanning":"common:refresh")}),e.jsx("button",{onClick:()=>{F.system.openPath(Me.dataDir)},className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-primary/60 rounded-lg text-fg-secondary transition-colors",children:t("dataStorage.openInFinder")})]})]}),e.jsx("div",{className:"h-2 rounded-full bg-surface-primary overflow-hidden flex","aria-hidden":!0,children:i.map(W=>{const fe=Es[W.name]??"caution",C=Math.max(W.size/b*100,W.size>0?.8:0);return e.jsx("div",{className:`h-full ${re(fe)}`,style:{width:`${C}%`},title:`${W.name}: ${Je(W.size,t)}`},W.name)})}),G>0&&e.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:t("dataStorage.clearableHint",{size:Je(G,t),percent:Math.round(G/b*100)})})]}),e.jsxs("div",{className:"border-t border-border-default pt-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-3",children:[e.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:t("dataStorage.storageBreakdown")}),e.jsx("span",{className:"text-[11px] text-fg-tertiary",children:t("dataStorage.sortedBySize")})]}),e.jsx("div",{className:"divide-y divide-border-default/70 rounded-xl border border-border-default/70 overflow-hidden",children:i.map(W=>{const fe=oo[W.name],C=Es[W.name]??"caution",z=fe?t(`dataStorage.items.${fe}.label`):W.name,kt=fe?t(`dataStorage.items.${fe}.blurb`):W.description,ts=Math.round(W.size/b*100);return e.jsxs("div",{className:"flex items-center gap-3 px-3.5 py-3 bg-surface-primary/25 hover:bg-surface-primary/45 transition-colors",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:z}),C==="safe"&&e.jsx("span",{className:"shrink-0 text-[10px] px-1.5 py-0.5 rounded-md bg-surface-elevated text-fg-secondary border border-border-default/80",children:t("dataStorage.safetyLevel.safe")})]}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 leading-relaxed",children:kt})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary tabular-nums",children:Je(W.size,t)}),e.jsxs("div",{className:"text-[11px] text-fg-tertiary tabular-nums mt-0.5",children:[ts,"%"]})]}),e.jsx("button",{type:"button",onClick:()=>{F.system.openPath(W.path)},className:"shrink-0 px-2.5 py-1 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",title:W.path,children:t("dataStorage.openFolder")})]},W.name)})})]}),bt&&(bt.orphanAgents.length>0||bt.orphanTeams.length>0)&&e.jsx(po,{orphanInfo:bt,dataDir:Me.dataDir,onPurged:We,formatBytes:W=>Je(W,t)})]})})()]})})}),(x==="account"||x==="users"||x==="organization"||x==="license")&&e.jsx(vo,{authUser:o}),x==="remote"&&e.jsx(ho,{}),x==="integrations"&&e.jsx(e.Fragment,{children:e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:t("nav.integrations")}),e.jsx("div",{className:"space-y-3",children:e.jsx(Ua,{})})]})}),x==="coding-tools"&&e.jsx(so,{})]}),e.jsx("div",{className:"h-8"})]}),Qt&&e.jsx(bn,{title:t("common:delete"),message:t("modelProviders.deleteConfirm",{name:Qt.label}),confirmLabel:t("common:delete"),onConfirm:()=>{const i=Qt.name;Xt(null),Jn(i)},onCancel:()=>Xt(null)})]})]})}const gn=["owner","admin","member","guest"],lo={owner:"bg-amber-500/10 text-amber-600 border-amber-500/30",admin:"bg-brand-500/10 text-brand-500 border-brand-500/30",member:"bg-green-500/10 text-green-600 border-green-500/30",guest:"bg-gray-500/10 text-gray-500 border-gray-500/30"};function co({authUser:s}){const{t:r}=me(["settings","common"]),[o,n]=l.useState([]),[a,t]=l.useState(null),[d,c]=l.useState(""),[u,p]=l.useState(""),[y,T]=l.useState(""),[x,v]=l.useState(null),[w,A]=l.useState(""),[K,j]=l.useState(null),[S,g]=l.useState(null),[h,N]=l.useState(null),[E,O]=l.useState(!1),[U,_]=l.useState(""),[D,R]=l.useState(""),[P,f]=l.useState("member"),[k,$]=l.useState(""),J=l.useCallback(()=>{F.users.list(s?.orgId).then(m=>n(m.users)).catch(()=>{})},[s?.orgId]);l.useEffect(()=>{J()},[J]);const Z=m=>{t(m.id),c(m.name),p(m.role),T(m.email??""),N(null)},ne=async()=>{if(a)try{await F.users.update(a,{name:d,role:u,email:y||void 0}),t(null),N({type:"ok",text:r("settings:userManagement.updateSuccess")}),J()}catch(m){N({type:"err",text:`${r("settings:userManagement.error")}: ${String(m)}`})}},I=async()=>{if(!(!x||!w))try{await F.users.resetPassword(x,w),v(null),A(""),N({type:"ok",text:r("settings:userManagement.resetSuccess")})}catch(m){N({type:"err",text:`${r("settings:userManagement.error")}: ${String(m)}`})}},H=async m=>{if(m===s?.id){N({type:"err",text:r("settings:userManagement.cannotDeleteSelf")}),j(null);return}if(o.find(V=>V.id===m)?.role==="owner"){N({type:"err",text:r("settings:userManagement.cannotDeleteOwner")}),j(null);return}try{await F.users.remove(m),j(null),N({type:"ok",text:r("settings:userManagement.deleteSuccess")}),J()}catch(V){N({type:"err",text:`${r("settings:userManagement.error")}: ${String(V)}`})}},q=async()=>{if(U.trim())try{const m=await F.users.create(U.trim(),P,void 0,D.trim()||void 0,k||void 0);O(!1),_(""),R(""),f("member"),$(""),N({type:"ok",text:r("settings:userManagement.addSuccess",{defaultValue:"User created"})}),m.inviteToken&&g(`${window.location.origin}/#invite?token=${m.inviteToken}`),J()}catch(m){N({type:"err",text:`${r("settings:userManagement.error")}: ${m instanceof Error?m.message:String(m)}`})}};return e.jsxs(Ce,{title:r("settings:userManagement.title"),children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("settings:userManagement.sharedInstanceDesc")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:r("settings:userManagement.orgHint")})]}),E?e.jsxs("div",{className:"mb-3 p-4 rounded-lg border border-border-default space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.name")}),e.jsx("input",{value:U,onChange:m=>_(m.target.value),autoFocus:!0,className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.email")}),e.jsx("input",{value:D,onChange:m=>R(m.target.value),type:"email",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.role")}),e.jsx("select",{value:P,onChange:m=>f(m.target.value),className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary",children:gn.map(m=>e.jsx("option",{value:m,children:r(`settings:userManagement.roles.${m}`)},m))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.password",{defaultValue:"Password"})}),e.jsx("input",{value:k,onChange:m=>$(m.target.value),type:"password",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>{O(!1),_(""),R(""),f("member"),$("")},className:"px-3 py-1.5 text-xs text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:q,disabled:!U.trim(),className:"px-4 py-1.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-xs font-medium rounded-lg",children:r("settings:userManagement.save")})]})]}):e.jsx("button",{onClick:()=>O(!0),className:"mb-3 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors",children:r("settings:userManagement.addUser",{defaultValue:"Add User"})}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[h&&e.jsx("div",{className:`px-4 py-2 text-xs border-b ${h.type==="ok"?"bg-green-500/10 text-green-600 border-green-500/20":"bg-red-500/10 text-red-500 border-red-500/20"}`,children:h.text}),S&&e.jsxs("div",{className:"px-4 py-3 bg-brand-500/5 border-b border-brand-500/20 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[11px] text-fg-tertiary mb-1",children:r("settings:userManagement.copyInviteLink")}),e.jsx("code",{className:"text-[10px] text-brand-500 bg-surface-elevated px-2 py-1 rounded block truncate",children:S})]}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(S),N({type:"ok",text:r("settings:userManagement.linkCopied")})},className:"shrink-0 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:r("settings:userManagement.copy")}),e.jsx("button",{onClick:()=>g(null),className:"shrink-0 text-fg-tertiary hover:text-fg-secondary text-sm",children:"×"})]}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border-default/60 text-fg-tertiary text-[11px] uppercase tracking-wider",children:[e.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:r("settings:userManagement.name")}),e.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:r("settings:userManagement.email")}),e.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:r("settings:userManagement.role")}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:r("settings:userManagement.actions")})]})}),e.jsxs("tbody",{children:[o.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-4 py-6 text-center text-fg-tertiary text-xs",children:r("settings:userManagement.noUsers")})}),o.map(m=>{const L=a===m.id,V=x===m.id,X=K===m.id,ee=m.id===s?.id,Q=m.role==="owner";return e.jsxs("tr",{className:"border-b border-border-default/40 last:border-b-0 hover:bg-surface-elevated/40 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5",children:L?e.jsx("input",{value:d,onChange:Y=>c(Y.target.value),className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-primary font-medium text-xs",children:m.name}),ee&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-500",children:"you"})]})}),e.jsx("td",{className:"px-4 py-2.5",children:L?e.jsx("input",{value:y,onChange:Y=>T(Y.target.value),placeholder:"email@example.com",className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):e.jsx("span",{className:"text-fg-secondary text-xs",children:m.email||"—"})}),e.jsx("td",{className:"px-4 py-2.5",children:L?e.jsx("select",{value:u,onChange:Y=>p(Y.target.value),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50",children:gn.map(Y=>e.jsx("option",{value:Y,children:r(`settings:userManagement.roles.${Y}`)},Y))}):e.jsx("span",{className:`inline-block text-[10px] px-2 py-0.5 rounded-full border font-medium ${lo[m.role]??""}`,children:r(`settings:userManagement.roles.${m.role}`)})}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:L?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>t(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:ne,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium",children:r("settings:userManagement.save")})]}):V?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("input",{type:"password",value:w,onChange:Y=>A(Y.target.value),placeholder:r("settings:userManagement.newPassword"),autoFocus:!0,className:"w-32 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),e.jsx("button",{onClick:()=>{v(null),A("")},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:I,disabled:w.length<6,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium disabled:opacity-40",children:r("settings:userManagement.confirmReset")})]}):X?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("span",{className:"text-[10px] text-red-500",children:r("settings:userManagement.confirmDelete")}),e.jsx("button",{onClick:()=>j(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:()=>H(m.id),className:"text-[11px] text-red-500 hover:text-red-400 font-medium",children:r("settings:userManagement.deleteUser")})]}):e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[e.jsx("button",{onClick:()=>Z(m),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:r("settings:userManagement.editUser")}),m.email&&e.jsx("button",{onClick:()=>{v(m.id),A(""),N(null)},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:r("settings:userManagement.resetPassword")}),m.email&&!Q&&!m.hasJoined&&e.jsx("button",{onClick:async()=>{try{const{inviteToken:Y}=await F.users.reinvite(m.id),le=`${window.location.origin}/#invite?token=${Y}`;g(le),N({type:"ok",text:r("settings:userManagement.inviteLinkGenerated")})}catch(Y){N({type:"err",text:String(Y)})}},className:"text-[11px] text-brand-400 hover:text-brand-500 px-1.5 py-0.5 rounded hover:bg-brand-500/10",children:r("settings:userManagement.inviteLink")}),!Q&&!ee&&e.jsx("button",{onClick:()=>{j(m.id),N(null)},className:"text-[11px] text-red-400 hover:text-red-500 px-1.5 py-0.5 rounded hover:bg-red-500/10",children:r("settings:userManagement.deleteUser")})]})})]},m.id)})]})]})]})]})}const uo={audio_speech:{label:"TTS",color:"bg-purple-500/20 text-purple-400"},image_generation:{label:"Image",color:"bg-blue-500/20 text-blue-400"},video_generation:{label:"Video",color:"bg-pink-500/20 text-pink-400"},audio_transcription:{label:"STT",color:"bg-teal-500/20 text-teal-400"},ocr:{label:"OCR",color:"bg-orange-500/20 text-orange-400"}},fn={chat:0,image_generation:1,video_generation:2,audio_speech:3,audio_transcription:4,ocr:5},pn=5;function xo({models:s,providerName:r,activeModelId:o,t:n,onDeleteCustom:a}){const t=s.length>pn,[d,c]=l.useState(!t),[u,p]=l.useState(""),y=l.useMemo(()=>{const x=u.trim().toLowerCase();return x?s.filter(v=>v.id.toLowerCase().includes(x)||v.name.toLowerCase().includes(x)):s},[s,u]),T=d?y:y.slice(0,pn);return e.jsxs("div",{className:"space-y-1",children:[t&&e.jsxs("div",{className:"flex items-center justify-between gap-2 px-1 mb-1",children:[e.jsxs("button",{type:"button",onClick:()=>c(x=>!x),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${d?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),d?n("modelProviders.collapseModels"):n("modelProviders.showAllModels",{count:s.length})]}),d&&e.jsx("input",{value:u,onChange:x=>p(x.target.value),placeholder:n("modelProviders.filterModels"),className:"flex-1 max-w-[220px] px-2 py-1 text-[10px] rounded-md bg-surface-overlay/50 border border-border-default text-fg-secondary placeholder:text-fg-tertiary"})]}),e.jsx("div",{className:d&&t?"max-h-64 overflow-y-auto space-y-1 pr-0.5":"space-y-1",children:T.map(x=>{const v=!ao.has(x.id),w=x.capabilities??[],A=o===x.id;return e.jsxs("div",{className:`flex items-center justify-between px-3 py-1.5 rounded-lg text-xs ${A?"bg-brand-500/10 border border-brand-500/20":"bg-surface-elevated/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[e.jsx("span",{className:"text-fg-secondary truncate",children:x.name}),A&&e.jsx("span",{className:"text-[9px] bg-brand-500/15 text-brand-500 px-1 py-0.5 rounded shrink-0",children:n("modelProviders.badgeDefault")}),e.jsx(wo,{modelId:x.id,tier:x.tier}),x.reasoning&&e.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:n("modelProviders.reasoning")}),(x.inputTypes?.includes("image")||w.includes("vision"))&&e.jsx("span",{className:"text-[9px] bg-blue-500/15 text-blue-600 px-1 py-0.5 rounded",children:n("modelProviders.vision")}),w.includes("imageGeneration")&&e.jsx("span",{className:"text-[9px] bg-cyan-500/15 text-cyan-600 px-1 py-0.5 rounded",children:n("modelProviders.capImageGen")}),(w.includes("tts")||w.includes("audioOutput"))&&e.jsx("span",{className:"text-[9px] bg-emerald-500/15 text-emerald-600 px-1 py-0.5 rounded",children:n("modelProviders.capTts")}),(w.includes("stt")||w.includes("audioInput"))&&e.jsx("span",{className:"text-[9px] bg-teal-500/15 text-teal-600 px-1 py-0.5 rounded",children:n("modelProviders.capStt")}),w.includes("videoGeneration")&&e.jsx("span",{className:"text-[9px] bg-orange-500/15 text-orange-600 px-1 py-0.5 rounded",children:n("modelProviders.capVideo")}),v&&r!=="markus"&&e.jsx("span",{className:"text-[9px] bg-purple-500/15 text-purple-400 px-1 py-0.5 rounded",children:n("modelProviders.custom")})]}),e.jsxs("div",{className:"flex items-center gap-3 text-fg-tertiary shrink-0",children:[(x.contextWindow??0)>0&&e.jsx("span",{children:n("modelProviders.ctxTokens",{size:((x.contextWindow??0)/1e3).toFixed(0)})}),v&&r!=="markus"&&e.jsx("button",{onClick:K=>{K.stopPropagation(),a(x.id)},className:"text-red-400 hover:text-red-300 transition-colors",title:n("modelProviders.deleteCustomModelTitle"),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},x.id)})}),t&&!d&&e.jsx("button",{type:"button",onClick:()=>c(!0),className:"w-full text-[10px] text-fg-tertiary hover:text-brand-500 transition-colors py-1.5",children:n("modelProviders.showAllModels",{count:s.length})}),d&&u&&y.length===0&&e.jsx("div",{className:"text-[10px] text-fg-tertiary px-1 py-2",children:n("modelProviders.noFilterMatches")})]})}function mo({models:s,providerName:r,t:o,onAdd:n}){const[a,t]=l.useState(!1),d=l.useMemo(()=>[...s].sort((c,u)=>{const p=fn[c.mode??"chat"]??99,y=fn[u.mode??"chat"]??99;return p!==y?p-y:String(c.id??"").localeCompare(String(u.id??""))}),[s]);return e.jsxs("div",{className:"mt-2",children:[e.jsxs("button",{onClick:()=>t(!a),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors px-1",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${a?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),o("modelProviders.catalogModelsAvailable",{count:s.length})]}),a&&e.jsx("div",{className:"mt-1 space-y-0.5 pl-1 max-h-64 overflow-y-auto",children:d.map(c=>{const u=String(c.id??""),p=c.mode??"chat",y=uo[p];return e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded hover:bg-surface-overlay/60 group",children:[e.jsx("span",{className:"text-[11px] text-fg-secondary flex-1 truncate",children:u}),y&&e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full shrink-0 ${y.color}`,children:y.label}),e.jsx("button",{onClick:()=>n(u),className:"text-[9px] text-brand-500 hover:text-brand-400 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:o("modelProviders.addModel")})]},u)})})]})}function go({providerName:s,addModelForm:r,setAddModelForm:o,addModelSaving:n,onAdd:a,onCancel:t,t:d}){const[c,u]=l.useState([]),[p,y]=l.useState(!1),[T,x]=l.useState(!1),v=async()=>{y(!0);try{const w=await F.modelCatalog.getByProvider(s);u(w.models),x(!0)}catch{u([])}finally{y(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-[10px] text-fg-secondary",children:d("modelProviders.addModelTitle")}),e.jsx("button",{onClick:()=>{v()},disabled:p,className:"text-[10px] text-brand-500 hover:text-brand-400 disabled:opacity-40 transition-colors",children:p?"...":d("modelProviders.browseFromCatalog")})]}),T&&c.length>0&&e.jsx("div",{className:"border border-border-default rounded-lg p-2 mb-2",children:e.jsx(vn,{provider:s,models:c,selectedModel:r.id,showTiers:!0,onSelect:w=>{const A=c.find(K=>K.id===w);A&&o(K=>({...K,id:A.id,name:A.id,contextWindow:A.maxInputTokens,maxOutputTokens:A.maxOutputTokens,costInput:A.inputCostPer1MTokens,costOutput:A.outputCostPer1MTokens,reasoning:A.capabilities.reasoning,vision:A.capabilities.vision}))},compact:!0,maxVisible:5})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[e.jsx("input",{type:"text",placeholder:d("modelProviders.modelId"),value:r.id,onChange:w=>o({...r,id:w.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),e.jsx("input",{type:"text",placeholder:d("modelProviders.displayName"),value:r.name,onChange:w=>o({...r,name:w.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),e.jsx("input",{type:"number",placeholder:d("modelProviders.placeholderContextTokens"),value:r.contextWindow,onChange:w=>o({...r,contextWindow:Number(w.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"}),e.jsx("input",{type:"number",placeholder:d("modelProviders.maxOutput"),value:r.maxOutputTokens,onChange:w=>o({...r,maxOutputTokens:Number(w.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d("modelProviders.costPerMillionIn")}),e.jsx("input",{type:"number",step:"0.01",value:r.costInput,onChange:w=>o({...r,costInput:Number(w.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d("modelProviders.costPerMillionOut")}),e.jsx("input",{type:"number",step:"0.01",value:r.costOutput,onChange:w=>o({...r,costOutput:Number(w.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.reasoning,onChange:w=>o({...r,reasoning:w.target.checked}),className:"rounded"}),d("modelProviders.reasoning")]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.vision,onChange:w=>o({...r,vision:w.target.checked}),className:"rounded"}),d("modelProviders.vision")]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:a,disabled:n||!r.id||!r.name,className:"px-2 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded transition-colors",children:d(n?"modelProviders.adding":"common:create")}),e.jsx("button",{onClick:t,className:"px-2 py-1 text-[10px] border border-border-default text-fg-secondary hover:bg-surface-elevated rounded transition-colors",children:d("common:cancel")})]})]})}function Ae({type:s,text:r}){return e.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${s==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:r})}function fo({title:s,defaultCollapsed:r,configuredProviders:o,t:n,children:a,onBadgeClick:t}){const[d,c]=l.useState(r);return e.jsxs("section",{children:[e.jsxs("button",{type:"button",onClick:()=>c(!d),className:"flex items-center justify-between w-full group mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:s}),d&&o.length>0&&e.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",o.length," ",n("modelProviders.configuredCount"),")"]})]}),e.jsx("span",{className:`text-fg-tertiary text-xs transition-transform group-hover:text-fg-secondary ${d?"-rotate-90":""}`,children:"▼"})]}),d&&o.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:o.map(([u,p])=>e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),c(!1),t?.(u)},className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-lg border cursor-pointer transition-colors ${p.enabled?"bg-green-500/10 border-green-500/30 text-green-400 hover:bg-green-500/20":"bg-surface-elevated border-border-default text-fg-tertiary hover:border-gray-500"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${p.enabled?"bg-green-400":"bg-gray-500"}`}),p.displayName??u]},u))}),!d&&e.jsx("div",{className:"space-y-4",children:a})]})}function Ce({title:s,children:r}){return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:s}),e.jsx("div",{className:"space-y-4",children:r})]})}function Is({title:s,children:r,defaultOpen:o=!0}){const[n,a]=l.useState(o);return e.jsxs("section",{children:[e.jsxs("button",{type:"button",onClick:()=>a(!n),className:"flex items-center justify-between w-full group mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:s}),e.jsx("span",{className:`text-fg-tertiary text-xs transition-transform group-hover:text-fg-secondary ${n?"":"-rotate-90"}`,children:"▼"})]}),n&&e.jsx("div",{className:"space-y-4",children:r})]})}function Ls({label:s,value:r,color:o}){const n=o==="green"?"bg-green-500/10 text-green-600":"bg-brand-500/10 text-brand-500";return e.jsxs("div",{className:`rounded-xl px-5 py-4 ${n}`,children:[e.jsx("div",{className:"text-2xl font-bold",children:r}),e.jsx("div",{className:"text-xs mt-1 opacity-70",children:s})]})}function Je(s,r){if(s===0)return r?r("dataStorage.bytesZero"):"0 B";const o=r?[r("dataStorage.unitB"),r("dataStorage.unitKB"),r("dataStorage.unitMB"),r("dataStorage.unitGB")]:["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(s)/Math.log(1024)),o.length-1),a=s/Math.pow(1024,n);return`${a<10?a.toFixed(1):Math.round(a)} ${o[n]}`}function po({orphanInfo:s,dataDir:r,onPurged:o,formatBytes:n}){const{t:a}=me(["settings","common"]),t=[...s.orphanAgents.map(j=>({...j,kind:"agent"})),...s.orphanTeams.map(j=>({...j,kind:"team"}))],[d,c]=l.useState(new Set),[u,p]=l.useState(!1),[y,T]=l.useState(null),x=j=>c(S=>{const g=new Set(S);return g.has(j)?g.delete(j):g.add(j),g}),v=d.size===t.length&&t.length>0,w=()=>c(v?new Set:new Set(t.map(j=>j.id))),A=t.filter(j=>d.has(j.id)).reduce((j,S)=>j+S.size,0),K=async j=>{p(!0),T(null);try{const S=await F.system.purgeOrphans(j),g=S.purgedAgents.length+S.purgedTeams.length,h=a("dataStorage.cleaned",{count:g,size:n(S.freedBytes)});T(S.failures.length?a("dataStorage.cleanedWithFailureNote",{base:h,count:S.failures.length}):h),c(new Set),o()}catch{T(a("dataStorage.cleanupFailed"))}finally{p(!1)}};return e.jsxs("div",{className:"border-t border-border-default pt-4",children:[e.jsx("h4",{className:"text-xs font-semibold text-amber-500 mb-2",children:a("dataStorage.orphanedDirectories")}),e.jsxs("p",{className:"text-xs text-fg-tertiary mb-3",children:[a("dataStorage.orphanedDesc")," ",a("dataStorage.orphanedTotal",{size:n(s.totalOrphanSize),count:t.length})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:v,onChange:w,className:"rounded"}),a("common:selectAll")]}),d.size>0&&e.jsx("span",{className:"text-[10px] text-fg-secondary",children:a("dataStorage.selectedWithSize",{count:d.size,size:n(A)})})]}),e.jsx("div",{className:"space-y-0.5 mb-3 max-h-52 overflow-y-auto",children:t.map(j=>e.jsxs("div",{className:`flex items-center gap-2 text-xs py-1.5 px-2 rounded transition-colors ${d.has(j.id)?"bg-amber-500/10":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:[e.jsx("input",{type:"checkbox",checked:d.has(j.id),onChange:()=>x(j.id),className:"rounded shrink-0"}),j.kind==="team"&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:a("dataStorage.teamKind")}),e.jsx("span",{className:"text-fg-tertiary font-mono truncate min-w-0 flex-1",children:j.id}),e.jsx("span",{className:"text-fg-secondary tabular-nums shrink-0",children:n(j.size)}),e.jsx("button",{onClick:()=>{F.system.openPath(j.path)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0 underline",children:a("common:open")})]},j.id))}),e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[d.size>0&&e.jsx("button",{disabled:u,onClick:()=>{K([...d])},className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanSelected",{size:n(A)})}),e.jsx("button",{disabled:u,onClick:()=>{K()},className:"px-3 py-1.5 text-xs border border-amber-600/50 hover:bg-amber-600/10 text-amber-500 rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanAll",{size:n(s.totalOrphanSize)})})]}),y&&e.jsx("div",{className:"text-xs text-fg-tertiary mt-2",children:y})]})}function ho(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(null),[n,a]=l.useState(!0),[t,d]=l.useState(!1),[c,u]=l.useState(null),[p,y]=l.useState(!1),T=yn(),x=l.useCallback(async()=>{try{const S=await F.settings.getRemote();o(S)}catch{o(null)}finally{a(!1)}},[]);l.useEffect(()=>{x()},[x]),l.useEffect(()=>na.on("remote:status",S=>{const g=S.payload;g&&(o(g),d(!1))}),[]);const v=async()=>{d(!0),u(null);try{r?.enabled?(await F.settings.disableRemote(),await x(),d(!1)):(Fe.isAuthenticated()||await Rs(),await F.settings.enableRemote())}catch(S){u(String(S instanceof Error?S.message:S)),d(!1)}},w=async()=>{try{await Rs(),await x()}catch{}},A=()=>{r?.remoteUrl&&(navigator.clipboard.writeText(r.remoteUrl),y(!0),setTimeout(()=>y(!1),2e3))},K=t||r?.enabled&&!r?.connected&&r?.state!=="idle",j=r?.remoteUrl??null;return e.jsx(Ce,{title:s("settings:remoteAccess.title"),children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-content-secondary",children:s("settings:remoteAccess.description")}),Fe.isAuthenticated()?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-content-secondary",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),s("settings:remoteAccess.signedInAs")," ",e.jsx("strong",{children:T?.username??T?.displayName})]}):e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[e.jsx("svg",{className:"w-5 h-5 text-amber-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("span",{className:"text-sm text-amber-600 dark:text-amber-400",children:s("settings:remoteAccess.loginRequired")}),e.jsx("button",{onClick:w,className:"ml-auto px-3 py-1.5 text-xs font-medium bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors",children:s("settings:remoteAccess.signIn")})]}),Fe.isAuthenticated()&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:v,disabled:t||n,className:`relative w-12 h-6 rounded-full transition-colors duration-200 ${r?.enabled?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} ${t||n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:e.jsx("span",{className:`block w-5 h-5 bg-white rounded-full shadow transform transition-transform duration-200 ${r?.enabled?"translate-x-6":"translate-x-0.5"}`})}),e.jsx("span",{className:"text-sm font-medium",children:K?s("settings:remoteAccess.connecting"):r?.enabled?s("settings:remoteAccess.enabled"):s("settings:remoteAccess.disabled")}),K&&e.jsx(hn,{})]}),r?.enabled&&e.jsxs("div",{className:`flex items-center gap-1.5 text-xs ${r.connected?"text-green-600 dark:text-green-400":r.state==="registering"||r.state==="connecting"?"text-blue-600 dark:text-blue-400":"text-amber-600 dark:text-amber-400"}`,children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${r.connected?"bg-green-500 animate-pulse":r.state==="registering"||r.state==="connecting"?"bg-blue-500 animate-pulse":"bg-amber-500"}`}),r.connected?s("settings:remoteAccess.connected"):r.state==="registering"?s("settings:remoteAccess.registering"):r.state==="connecting"?s("settings:remoteAccess.connecting"):s("settings:remoteAccess.disconnected"),r.connected&&r.peerCount>0&&e.jsxs(e.Fragment,{children:[" · ",s("settings:remoteAccess.peerCount",{count:r.peerCount})]}),(r.state==="registering"||r.state==="connecting")&&e.jsx(hn,{})]})]}),c&&e.jsx("div",{className:"p-2 rounded-lg bg-red-500/10 text-red-500 text-sm",children:c}),r?.enabled&&r.peers&&r.peers.length>0&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-2",children:[e.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:s("settings:remoteAccess.connectedPeers")}),e.jsx("div",{className:"space-y-2 mt-1",children:r.peers.map(S=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg bg-surface-inset",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${S.transport==="p2p"?"bg-green-500":S.transport==="relay"?"bg-blue-500":"bg-amber-500 animate-pulse"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-sm font-mono text-content-primary truncate",children:[S.peerId.slice(0,8),"..."]}),e.jsx("div",{className:"text-xs text-content-tertiary",children:s("settings:remoteAccess.connectedSince",{time:new Date(S.connectedAt).toLocaleTimeString()})})]}),e.jsx("span",{className:`px-2 py-0.5 text-xs font-medium rounded-full ${S.transport==="p2p"?"bg-green-500/10 text-green-600 dark:text-green-400":S.transport==="relay"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"}`,children:S.transport==="p2p"?"P2P":S.transport==="relay"?"Relay":s("settings:remoteAccess.peerConnecting")})]},S.peerId))})]}),r?.enabled&&r.remoteUrl&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:s("settings:remoteAccess.url")}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("code",{className:"flex-1 px-3 py-1.5 text-sm bg-surface-inset rounded font-mono truncate",children:r.remoteUrl}),e.jsx("button",{onClick:A,className:`px-2 py-1.5 text-xs border rounded transition-colors ${p?"border-green-500 text-green-600 dark:text-green-400":"border-border-default hover:bg-surface-elevated"}`,children:s(p?"settings:remoteAccess.copied":"settings:remoteAccess.copy")})]})]}),j&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:s("settings:remoteAccess.qrCode")}),e.jsx("p",{className:"text-xs text-content-secondary mt-0.5 mb-2",children:s("settings:remoteAccess.scanQr")}),e.jsx(bo,{url:j})]})]})]})]})})}function hn(){return e.jsxs("svg",{className:"w-4 h-4 animate-spin text-content-secondary",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function bo({url:s}){const r=l.useRef(null),[o,n]=l.useState(!1);return l.useEffect(()=>{const a=r.current;a&&(n(!1),aa(()=>Promise.resolve().then(()=>_a),void 0).then(t=>{t.toCanvas(a,s,{width:200,margin:2,color:{dark:"#000000",light:"#ffffff"},errorCorrectionLevel:"M"})}).catch(()=>n(!0)))},[s]),o?e.jsx("a",{href:s,target:"_blank",rel:"noopener",className:"text-sm text-brand-500 underline",children:s}):e.jsx("div",{className:"inline-block p-2 bg-white rounded-lg",children:e.jsx("canvas",{ref:r,className:"block",style:{width:160,height:160}})})}const yo={multi_user:"👥",sso:"🔐",audit_enhanced:"📋",multi_instance:"🌐",offline_license:"📡"};function vo({authUser:s}){const{t:r}=me(["settings","common"]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-fg-primary mb-1",children:r("account.title")}),e.jsx("p",{className:"text-xs text-fg-tertiary",children:r("account.subtitle")})]}),e.jsx(jo,{}),e.jsx(co,{authUser:s})]})}function jo(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(null),[n,a]=l.useState(!0),[t,d]=l.useState([]),[c,u]=l.useState([]),[p,y]=l.useState(null),[T,x]=l.useState(!0),[v,w]=l.useState(!1),[A,K]=l.useState(null),[j,S]=l.useState(!1),g=l.useCallback((P=!1)=>{x(!0),F.hubOrgs.mine().catch(f=>(P&&y({type:"err",text:f instanceof Error?f.message:s("org.loadFailed")}),{orgs:[]})).then(f=>{d(f.orgs),F.hubOrgs.invitations().then(k=>u(k.invitations)).catch(()=>{})}).finally(()=>x(!1))},[s]);l.useEffect(()=>{if(!yn()&&!ns()){x(!1),a(!1);return}g(),Fe.user.plan().then(P=>o(P)).catch(()=>{}).finally(()=>a(!1))},[g]);const h=l.useCallback((P=!1)=>{S(!0),(P?F.license.refresh():F.license.get()).then(k=>K(k)).catch(()=>{}).finally(()=>setTimeout(()=>S(!1),400))},[]);l.useEffect(()=>{h(!0)},[h]);const N=A?.plan==="enterprise",E=async P=>{try{await F.hubOrgs.acceptInvitation(P),u(f=>f.filter(k=>k.orgId!==P)),g()}catch(f){y({type:"err",text:f instanceof Error?f.message:"Failed"})}},O=A?.validUntil?Math.max(0,Math.ceil((new Date(A.validUntil).getTime()-Date.now())/864e5)):null,U=["multi_user","multi_instance"],_={multi_user:s("license.featureMultiUser"),multi_instance:s("license.featureMultiInstance")},D=t.find(P=>P.id===r?.orgId)??t[0],R=r?(r.monthlyQuotaCu??0)+(r.bonusCu??0)+(r.purchasedCu??0):0;return T||n?e.jsx("div",{className:"text-center py-8 text-fg-tertiary text-sm",children:s("common:loading")}):e.jsxs("div",{className:"space-y-6",children:[p&&e.jsxs("div",{className:`flex items-center gap-2 text-sm px-4 py-3 rounded-lg ${p.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/20":"bg-red-500/10 text-red-500 border border-red-500/20"}`,children:[e.jsx("span",{children:p.type==="ok"?"✓":"✕"}),e.jsx("span",{children:p.text})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-3",children:s("account.cloudAiTitle")}),e.jsxs("div",{className:"rounded-lg border border-border-default bg-gradient-to-r from-brand-600/5 to-transparent px-5 py-4 space-y-3",children:[r?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-tertiary",children:s("account.currentPlan")}),e.jsx("span",{className:"px-2 py-0.5 rounded text-xs font-semibold capitalize bg-brand-600/10 text-brand-500 border border-brand-500/15",children:r.planType})]}),(R>0||r.memberCuLimit!=null&&r.memberCuLimit>0)&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:r.memberCuLimit!=null&&r.memberCuLimit>0?s("account.personalLimit"):s("account.credits")}),e.jsx("span",{className:"font-medium text-fg-primary tabular-nums",children:r.memberCuLimit!=null&&r.memberCuLimit>0?`${Math.round(r.memberCuUsed??0).toLocaleString()} / ${r.memberCuLimit.toLocaleString()}`:`${Math.round(r.cuUsed).toLocaleString()} / ${R.toLocaleString()}`})]})]}):e.jsx("p",{className:"text-xs text-fg-secondary",children:s("license.cloudAiDesc")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("a",{href:`${Fe.getUrl()}/settings?tab=billing`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors no-underline",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),s("account.manageBilling")]})})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-3",children:s("account.orgSection")}),c.length>0&&e.jsx("div",{className:"space-y-2 mb-3",children:c.map(P=>e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 rounded-lg border border-amber-500/20 bg-amber-500/5",children:[e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium text-fg-primary",children:P.orgName}),e.jsxs("span",{className:"text-fg-tertiary ml-1",children:["— ",s("org.invitedBy")," ",P.invitedBy]})]}),e.jsx("button",{onClick:()=>{E(P.orgId)},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors",children:s("org.accept")})]},P.orgId))}),D?e.jsxs("div",{className:"rounded-lg border border-border-default px-5 py-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s("org.nameLabel")}),e.jsx("span",{className:"font-medium text-fg-primary",children:D.name})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s("account.memberCount")}),e.jsx("span",{className:"font-medium text-fg-primary",children:D.memberCount})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s("org.orgId")}),e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-surface-elevated text-fg-secondary text-[11px]",children:D.id})]}),e.jsxs("a",{href:`${Fe.getUrl()}/settings?tab=organization`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-4 py-2 border border-border-default text-fg-secondary hover:bg-surface-elevated text-xs font-medium rounded-lg transition-colors no-underline",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),s("account.manageOrg")]})]}):e.jsxs("div",{className:"rounded-lg border border-border-default px-5 py-6 text-center space-y-3",children:[e.jsx("div",{className:"text-sm text-fg-tertiary",children:s("org.noOrg")}),!!ns()&&e.jsx("div",{className:"text-xs text-amber-500/90",children:s("org.staleSessionHint")}),e.jsxs("button",{disabled:v,onClick:()=>{y(null),w(!0),Rs({force:!0}).then(()=>g(!0)).catch(P=>{const f=P instanceof Error?P.message:String(P),k=f.includes("Popup blocked")?s("org.popupBlocked"):f.includes("cancelled")?s("org.loginCancelled"):f;y({type:"err",text:k})}).finally(()=>w(!1))},className:"px-5 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-60 text-white text-sm font-medium rounded-lg transition-colors inline-flex items-center gap-2",children:[v&&e.jsx("svg",{className:"w-4 h-4 animate-spin",viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeDasharray:"30 70",strokeLinecap:"round"})}),v?s("org.connecting"):ns()?s("org.reconnectHub"):s("org.connectHub")]})]})]}),N&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:s("license.title")}),e.jsxs("button",{onClick:()=>h(!0),disabled:j,className:"ml-auto flex items-center gap-1.5 text-xs text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${j?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h5M20 20v-5h-5M4.05 11A8 8 0 0119.95 9M19.95 13A8 8 0 014.05 15"})}),s("license.refresh")]})]}),e.jsx(No,{isEnterprise:!0,licenseInfo:A,daysRemaining:O,effectiveValidUntil:A?.validUntil,effectiveMaxSeats:A?.maxSeats,effectiveUsedSeats:D?.memberCount??A?.usedSeats??0,effectiveOrgName:D?.name??A?.orgName,featureKeys:U,featureI18n:_,t:s})]}),e.jsxs("div",{className:"flex items-center gap-4 text-[11px] text-fg-tertiary pt-1",children:[e.jsx("a",{href:"https://markus.global",target:"_blank",rel:"noopener noreferrer",className:"hover:text-fg-secondary transition-colors",children:s("license.website")}),e.jsx("a",{href:`mailto:${s("license.salesEmail")}`,className:"hover:text-fg-secondary transition-colors",children:s("license.salesEmail")})]})]})}function No({isEnterprise:s,licenseInfo:r,daysRemaining:o,effectiveValidUntil:n,effectiveMaxSeats:a,effectiveUsedSeats:t,effectiveOrgName:d,featureKeys:c,featureI18n:u,t:p}){return s?e.jsx("div",{className:"rounded-lg border border-brand-500/20 overflow-hidden",children:e.jsxs("div",{className:"px-5 py-4 bg-gradient-to-r from-brand-600/5 to-transparent",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-base font-semibold text-fg-primary",children:p("license.planEnterprise")}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-green-500/12 text-green-600 border border-green-500/15",children:p("license.statusActive")}),r?.isTrial&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-amber-500/12 text-amber-600 border border-amber-500/15",children:p("license.trial")})]}),o!==null&&e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:`text-sm font-semibold tabular-nums ${o===0?"text-red-500":o<=7?"text-amber-500":o<=60?"text-amber-600":"text-fg-primary"}`,children:o>0?p("license.daysRemaining",{count:o}):p("license.expired")}),e.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:p("license.expiresOn",{date:new Date(n).toLocaleDateString()})})]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:c.map(y=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium text-brand-500 bg-brand-600/6 border border-brand-500/10",children:[yo[y]," ",u[y]]},y))}),d&&e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-surface-primary/40 border border-border-default/30",children:[e.jsx("span",{className:"text-fg-tertiary",children:p("license.organization")}),e.jsx("span",{className:"font-medium text-fg-primary",children:d})]}),a!=null&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-surface-primary/40 border border-border-default/30",children:[e.jsx("span",{className:"text-fg-tertiary",children:p("license.seats")}),e.jsxs("span",{className:"font-medium text-fg-primary",children:[t," / ",a]})]})]})]})}):null}function wo({modelId:s,tier:r}){const{t:o}=me("settings");let n;if(r==="max"||r==="pro"||r==="base")n=r;else{const t=s.toLowerCase(),d=/opus|5\.4|o3-(?!mini)|o1-(?!mini)|gemini.*ultra|sonnet-4-20/,c=/haiku|flash|nano|lite|small|fast|free|8b|7b|1b|3b/;/o4-mini|o3-mini|o1-mini|gpt-4o-mini/.test(t)?n="pro":d.test(t)?n="max":c.test(t)?n="base":n="pro"}const a={max:"bg-purple-500/15 text-purple-400",pro:"bg-blue-500/15 text-blue-400",base:"bg-gray-500/15 text-gray-400"};return e.jsx("span",{className:`text-[9px] px-1 py-0.5 rounded font-semibold uppercase ${a[n]}`,children:o(`modelRouting.tier.${n}`)})}export{Ao as Settings};
|
|
7
|
+
`);const L=g(B,F,O),h=s.getSymbolSize(B),S=new n(h);return b(S,B),w(S),P(S,B),j(S,F,0),B>=7&&U(S,B),C(S,L),isNaN(K)&&(K=d.getBestMask(S,j.bind(null,S,F))),d.applyMask(K,S),j(S,F,K),{modules:S,version:B,errorCorrectionLevel:F,maskPattern:K,segments:O}}return is.create=function(B,F){if(typeof B>"u"||B==="")throw new Error("No input text");let K=r.M,O,R;return typeof F<"u"&&(K=r.from(F.errorCorrectionLevel,r.M),O=f.from(F.version),R=d.from(F.maskPattern),F.toSJISFunc&&s.setToSJISFunction(F.toSJISFunc)),N(B,O,K,R)},is}var Ss={},Ps={},Zr;function Cn(){return Zr||(Zr=1,(function(s){function r(o){if(typeof o=="number"&&(o=o.toString()),typeof o!="string")throw new Error("Color should be defined as hex string");let n=o.slice().replace("#","").split("");if(n.length<3||n.length===5||n.length>8)throw new Error("Invalid hex color: "+o);(n.length===3||n.length===4)&&(n=Array.prototype.concat.apply([],n.map(function(t){return[t,t]}))),n.length===6&&n.push("F","F");const a=parseInt(n.join(""),16);return{r:a>>24&255,g:a>>16&255,b:a>>8&255,a:a&255,hex:"#"+n.slice(0,6).join("")}}s.getOptions=function(n){n||(n={}),n.color||(n.color={});const a=typeof n.margin>"u"||n.margin===null||n.margin<0?4:n.margin,t=n.width&&n.width>=21?n.width:void 0,d=n.scale||4;return{width:t,scale:t?4:d,margin:a,color:{dark:r(n.color.dark||"#000000ff"),light:r(n.color.light||"#ffffffff")},type:n.type,rendererOpts:n.rendererOpts||{}}},s.getScale=function(n,a){return a.width&&a.width>=n+a.margin*2?a.width/(n+a.margin*2):a.scale},s.getImageWidth=function(n,a){const t=s.getScale(n,a);return Math.floor((n+a.margin*2)*t)},s.qrToImageData=function(n,a,t){const d=a.modules.size,c=a.modules.data,u=s.getScale(d,t),f=Math.floor((d+t.margin*2)*u),v=t.margin*u,M=[t.color.light,t.color.dark];for(let x=0;x<f;x++)for(let b=0;b<f;b++){let w=(x*f+b)*4,P=t.color.light;if(x>=v&&b>=v&&x<f-v&&b<f-v){const U=Math.floor((x-v)/u),j=Math.floor((b-v)/u);P=M[c[U*d+j]?1:0]}n[w++]=P.r,n[w++]=P.g,n[w++]=P.b,n[w]=P.a}}})(Ps)),Ps}var en;function Ra(){return en||(en=1,(function(s){const r=Cn();function o(a,t,d){a.clearRect(0,0,t.width,t.height),t.style||(t.style={}),t.height=d,t.width=d,t.style.height=d+"px",t.style.width=d+"px"}function n(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}s.render=function(t,d,c){let u=c,f=d;typeof u>"u"&&(!d||!d.getContext)&&(u=d,d=void 0),d||(f=n()),u=r.getOptions(u);const v=r.getImageWidth(t.modules.size,u),M=f.getContext("2d"),x=M.createImageData(v,v);return r.qrToImageData(x.data,t,u),o(M,f,v),M.putImageData(x,0,0),f},s.renderToDataURL=function(t,d,c){let u=c;typeof u>"u"&&(!d||!d.getContext)&&(u=d,d=void 0),u||(u={});const f=s.render(t,d,u),v=u.type||"image/png",M=u.rendererOpts||{};return f.toDataURL(v,M.quality)}})(Ss)),Ss}var As={},tn;function Oa(){if(tn)return As;tn=1;const s=Cn();function r(a,t){const d=a.a/255,c=t+'="'+a.hex+'"';return d<1?c+" "+t+'-opacity="'+d.toFixed(2).slice(1)+'"':c}function o(a,t,d){let c=a+t;return typeof d<"u"&&(c+=" "+d),c}function n(a,t,d){let c="",u=0,f=!1,v=0;for(let M=0;M<a.length;M++){const x=Math.floor(M%t),b=Math.floor(M/t);!x&&!f&&(f=!0),a[M]?(v++,M>0&&x>0&&a[M-1]||(c+=f?o("M",x+d,.5+b+d):o("m",u,0),u=0,f=!1),x+1<t&&a[M+1]||(c+=o("h",v),v=0)):u++}return c}return As.render=function(t,d,c){const u=s.getOptions(d),f=t.modules.size,v=t.modules.data,M=f+u.margin*2,x=u.color.light.a?"<path "+r(u.color.light,"fill")+' d="M0 0h'+M+"v"+M+'H0z"/>':"",b="<path "+r(u.color.dark,"stroke")+' d="'+n(v,f,u.margin)+'"/>',w='viewBox="0 0 '+M+" "+M+'"',U='<svg xmlns="http://www.w3.org/2000/svg" '+(u.width?'width="'+u.width+'" height="'+u.width+'" ':"")+w+' shape-rendering="crispEdges">'+x+b+`</svg>
|
|
8
|
+
`;return typeof c=="function"&&c(null,U),U},As}var sn;function Ba(){if(sn)return Ye;sn=1;const s=pa(),r=La(),o=Ra(),n=Oa();function a(t,d,c,u,f){const v=[].slice.call(arguments,1),M=v.length,x=typeof v[M-1]=="function";if(!x&&!s())throw new Error("Callback required as last argument");if(x){if(M<2)throw new Error("Too few arguments provided");M===2?(f=c,c=d,d=u=void 0):M===3&&(d.getContext&&typeof f>"u"?(f=u,u=void 0):(f=u,u=c,c=d,d=void 0))}else{if(M<1)throw new Error("Too few arguments provided");return M===1?(c=d,d=u=void 0):M===2&&!d.getContext&&(u=c,c=d,d=void 0),new Promise(function(b,w){try{const P=r.create(c,u);b(t(P,d,u))}catch(P){w(P)}})}try{const b=r.create(c,u);f(null,t(b,d,u))}catch(b){f(b)}}return Ye.create=r.create,Ye.toCanvas=a.bind(null,o.render),Ye.toDataURL=a.bind(null,o.renderToDataURL),Ye.toString=a.bind(null,function(t,d,c){return n.render(t,c)}),Ye}var Sn=Ba();const Pn=ta(Sn),_a=oa({__proto__:null,default:Pn},[Sn]),rn={appId:"",appSecret:"",enabled:!1,connected:!1,notifyChatId:"",notifyOnApproval:!0,notifyOnNotification:!1,notifyPriority:["high","urgent"]},Da=[{value:"normal",color:"bg-green-400"},{value:"low",color:"bg-gray-400"},{value:"medium",color:"bg-blue-400"},{value:"high",color:"bg-amber-400"},{value:"urgent",color:"bg-red-400"}];function Ka({connected:s}){return e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${s?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-gray-500/10 text-gray-500 border border-gray-500/30"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${s?"bg-green-500 animate-pulse":"bg-gray-400"}`}),s?"Connected":"Disconnected"]})}function ot({title:s,children:r}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary uppercase tracking-wider",children:s}),r]})}function nn({type:s,text:r}){return e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${s==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-600 border border-red-500/30"}`,children:[s==="ok"?e.jsx("svg",{className:"w-4 h-4 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):e.jsx("svg",{className:"w-4 h-4 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),r]})}function Ua(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(rn),[n,a]=l.useState(!0),[t,d]=l.useState(!1),[c,u]=l.useState(!1),[f,v]=l.useState(!1),[M,x]=l.useState(null),[b,w]=l.useState(""),[P,U]=l.useState([]),[j,C]=l.useState(!1),[g,p]=l.useState("idle"),[N,I]=l.useState(null),[B,F]=l.useState(null),[K,O]=l.useState(0),R=l.useRef(null),L=l.useRef(null),[h,S]=l.useState(!1),[_,z]=l.useState(!1),G=l.useRef(null),ne=l.useRef(r);ne.current=r;const T=l.useRef(!1),q=l.useCallback(async()=>{C(!0);try{const A=await $.settings.listFeishuChats();U(A.chats??[])}catch{}finally{C(!1)}},[]),V=l.useCallback(async()=>{a(!0);try{const A=await $.settings.getFeishuIntegration();A&&(o({appId:A.appId??"",appSecret:A.appSecret??"",enabled:A.enabled??!1,connected:A.connected??!1,notifyChatId:A.notifyChatId??"",notifyOnApproval:A.notifyOnApproval??!0,notifyOnNotification:A.notifyOnNotification??!1,notifyPriority:A.notifyPriority??["high","urgent"]}),A.appId&&A.appSecret&&q())}catch{}finally{a(!1),T.current=!0}},[]);l.useEffect(()=>{V()},[V]),l.useEffect(()=>()=>{R.current&&clearInterval(R.current)},[]);const m=l.useCallback(async A=>{if(!(!A.appId||!A.appSecret)){d(!0);try{const ie=await $.settings.saveFeishuIntegration({appId:A.appId,appSecret:A.appSecret,enabled:A.enabled,notifyChatId:A.notifyChatId||void 0,notifyOnApproval:A.notifyOnApproval,notifyOnNotification:A.notifyOnNotification,notifyPriority:A.notifyPriority});ie.connected!==void 0&&o(ue=>({...ue,connected:ie.connected})),x({type:"ok",text:s("settings:feishu.saved",{defaultValue:"Saved"})}),setTimeout(()=>x(ue=>ue?.type==="ok"?null:ue),2e3)}catch(ie){x({type:"err",text:String(ie instanceof Error?ie.message:ie)})}finally{d(!1)}}},[s]),E=l.useCallback(()=>{T.current&&(G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{m(ne.current)},600))},[m]),H=(A,ie)=>{o(ue=>({...ue,[A]:ie})),x(null),E()},Z=(A,ie)=>{o(ue=>{const Ke={...ue,[A]:ie};return ne.current=Ke,Ke}),x(null),G.current&&clearTimeout(G.current),m({...ne.current,[A]:ie})},ee=A=>{o(ie=>{const ue=ie.notifyPriority,Ke=ue.includes(A)?ue.filter(Se=>Se!==A):[...ue,A],qe={...ie,notifyPriority:Ke};return ne.current=qe,qe}),x(null),G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{m(ne.current)},300)},X=async()=>{p("waiting_qr"),I(null),F(null),x(null),R.current=setInterval(async()=>{try{const A=await $.settings.getFeishuRegisterStatus();if(A.active&&A.url){I(A.url),O(A.expireIn??300),p("scanning");try{const ie=await Pn.toDataURL(A.url,{width:200,margin:2,color:{dark:"#000000",light:"#ffffff"}});F(ie)}catch{}}}catch{}},1e3);try{const A=await $.settings.registerFeishuApp();R.current&&(clearInterval(R.current),R.current=null),A.success&&A.appId?(p("done"),x({type:"ok",text:s("settings:feishu.registerSuccess",{defaultValue:"App created successfully! Integration is now active."})}),await V()):(p("error"),x({type:"err",text:A.message||s("settings:feishu.registerFailed",{defaultValue:"Registration failed"})}))}catch(A){R.current&&(clearInterval(R.current),R.current=null),p("error"),x({type:"err",text:String(A instanceof Error?A.message:A)})}},Q=()=>{R.current&&(clearInterval(R.current),R.current=null),L.current&&L.current.abort(),p("idle"),I(null),F(null)},le=async()=>{if(!r.appId||!r.appSecret){x({type:"err",text:s("settings:feishu.fillRequired",{defaultValue:"Please fill in App ID and App Secret first"})});return}u(!0),x(null);try{const A=await $.settings.testFeishuConnection({appId:r.appId,appSecret:r.appSecret});A.success?(o(ie=>({...ie,connected:!0})),x({type:"ok",text:A.message||s("settings:feishu.testSuccess",{defaultValue:"Connection successful"})})):x({type:"err",text:A.message||s("settings:feishu.testFailed",{defaultValue:"Connection failed"})})}catch(A){x({type:"err",text:String(A instanceof Error?A.message:A)})}finally{u(!1)}},Ee=async()=>{if(!b.trim()){x({type:"err",text:s("settings:feishu.chatIdRequired",{defaultValue:"Please select a group chat"})});return}v(!0),x(null);try{const A=await $.settings.sendFeishuTestMessage({chatId:b.trim()});A.success?x({type:"ok",text:A.message||s("settings:feishu.testMsgSent",{defaultValue:"Test message sent"})}):x({type:"err",text:A.message||s("settings:feishu.testMsgFailed",{defaultValue:"Failed to send test message"})})}catch(A){x({type:"err",text:String(A instanceof Error?A.message:A)})}finally{v(!1)}},dt=async()=>{d(!0),x(null);try{await $.settings.deleteFeishuIntegration(),T.current=!1,o(rn),T.current=!0,S(!1),x({type:"ok",text:s("settings:feishu.disconnected",{defaultValue:"Disconnected from Feishu"})})}catch(A){x({type:"err",text:String(A instanceof Error?A.message:A)})}finally{d(!1)}},[pe,Xe]=l.useState(!1),He=!!(r.appId&&r.appSecret),ct=e.jsxs("button",{type:"button",onClick:()=>Xe(A=>!A),className:"w-full flex items-center gap-3 px-4 py-3 hover:bg-white/[0.02] transition-colors text-left",children:[e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${pe?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})}),e.jsx("div",{className:"w-8 h-8 rounded-lg bg-blue-500/10 flex items-center justify-center shrink-0",children:e.jsx("svg",{className:"w-5 h-5 text-blue-500",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M6.3 10.5c-.8 0-1.5-.3-2-.9-.6-.6-.9-1.3-.9-2 0-.8.3-1.5.9-2 .6-.5 1.3-.8 2-.8.8 0 1.5.3 2 .9.6.6.9 1.3.9 2 0 .8-.3 1.5-.9 2-.5.5-1.2.8-2 .8zm12.4 0c-.8 0-1.5-.3-2-.9-.6-.6-.9-1.3-.9-2 0-.8.3-1.5.9-2 .6-.5 1.3-.8 2-.8.8 0 1.5.3 2 .9.6.6.9 1.3.9 2 0 .8-.3 1.5-.9 2-.5.5-1.2.8-2 .8zm-6.2 10c-.8 0-1.5-.3-2-.9-.6-.6-.9-1.3-.9-2 0-.8.3-1.5.9-2 .6-.5 1.3-.8 2-.8.8 0 1.5.3 2 .9.6.6.9 1.3.9 2 0 .8-.3 1.5-.9 2-.5.5-1.2.8-2 .8z"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:"飞书 (Feishu / Lark)"}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 hidden sm:inline",children:s("settings:feishu.description",{defaultValue:"Configure Feishu integration for notifications and approvals"})})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[n&&e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t&&e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),e.jsx(Ka,{connected:r.connected&&r.enabled})]})]});return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[ct,pe&&e.jsxs("div",{className:"px-6 pb-6 pt-2 space-y-8 border-t border-border-default",children:[n&&e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"ml-2 text-sm text-fg-tertiary",children:s("common:loading",{defaultValue:"Loading..."})})]}),!n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-blue-500/5 border border-blue-500/20",children:[e.jsx("svg",{className:"w-4 h-4 text-blue-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{className:"text-xs text-fg-secondary",children:s("settings:feishu.longConnectionMode",{defaultValue:"Using long connection mode (WebSocket) — no public IP required"})})]}),He?e.jsxs(e.Fragment,{children:[e.jsx(ot,{title:s("settings:feishu.appInfo",{defaultValue:"App Information"}),children:e.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 space-y-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:"App ID:"}),e.jsx("code",{className:"text-xs font-mono text-fg-primary bg-surface-primary px-2 py-0.5 rounded",children:r.appId})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:"App Secret:"}),e.jsx("code",{className:"text-xs font-mono text-fg-primary bg-surface-primary px-2 py-0.5 rounded",children:"•".repeat(Math.min(r.appSecret.length,20))})]})]}),e.jsxs("button",{onClick:dt,disabled:t,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),s("settings:feishu.removeApp",{defaultValue:"Remove"})]})]})})}),e.jsx(ot,{title:s("settings:feishu.integrationState",{defaultValue:"Integration State"}),children:e.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("settings:feishu.enableIntegration",{defaultValue:"Enable Feishu Integration"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("settings:feishu.enableHint",{defaultValue:"When enabled, Markus will establish a long connection to Feishu and start processing events"})})]}),e.jsx("button",{onClick:()=>Z("enabled",!r.enabled),className:`relative w-12 h-6 rounded-full transition-colors duration-200 ${r.enabled?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} cursor-pointer`,children:e.jsx("span",{className:`block w-5 h-5 bg-white rounded-full shadow transform transition-transform duration-200 ${r.enabled?"translate-x-6":"translate-x-0.5"}`})})]})})}),e.jsxs(ot,{title:s("settings:feishu.actions",{defaultValue:"Actions"}),children:[e.jsx("div",{className:"flex flex-wrap items-center gap-3",children:e.jsxs("button",{onClick:le,disabled:c,className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium bg-surface-primary border border-border-default rounded-lg text-fg-primary hover:bg-surface-overlay disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[c?e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}):e.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})]}),s("settings:feishu.testConnection",{defaultValue:"Test Connection"})]})}),r.connected&&r.enabled&&e.jsxs("div",{className:"mt-4 p-4 bg-surface-secondary border border-border-default rounded-xl space-y-3",children:[e.jsx("label",{className:"block text-xs font-medium text-fg-secondary",children:s("settings:feishu.sendTestMessage",{defaultValue:"Send Test Message"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsxs("select",{value:b,onChange:A=>w(A.target.value),className:"w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors appearance-none pr-8",children:[e.jsx("option",{value:"",children:s("settings:feishu.selectTestChat",{defaultValue:"— Select a group chat —"})}),P.map(A=>e.jsx("option",{value:A.chatId,children:A.name||A.chatId},A.chatId))]}),e.jsx("svg",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-fg-tertiary pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsxs("button",{onClick:Ee,disabled:f||!b.trim(),className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium bg-surface-primary border border-border-default rounded-lg text-fg-primary hover:bg-surface-overlay disabled:opacity-50 disabled:cursor-not-allowed transition-colors whitespace-nowrap",children:[f?e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}):e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})}),s("settings:feishu.send",{defaultValue:"Send"})]})]})]}),M&&e.jsx(nn,{type:M.type,text:M.text})]}),e.jsx(ot,{title:s("settings:feishu.notificationForwarding",{defaultValue:"Notification Forwarding"}),children:e.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"block text-xs font-medium text-fg-secondary",children:s("settings:feishu.notifyChatId",{defaultValue:"Notification Target Group"})}),e.jsxs("button",{onClick:q,disabled:j,className:"inline-flex items-center gap-1 text-[11px] text-brand-600 hover:text-brand-700 disabled:opacity-50 transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 ${j?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),s("settings:feishu.refreshChats",{defaultValue:"Refresh"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:r.notifyChatId,onChange:A=>Z("notifyChatId",A.target.value),className:"w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors appearance-none pr-8",children:[e.jsx("option",{value:"",children:j?s("settings:feishu.loadingChats",{defaultValue:"Loading groups..."}):s("settings:feishu.selectChat",{defaultValue:"— Private message (default) —"})}),P.map(A=>e.jsx("option",{value:A.chatId,children:A.name||A.chatId},A.chatId))]}),e.jsx("svg",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-fg-tertiary pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),!r.notifyChatId&&!j&&e.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1",children:s("settings:feishu.noChatFallbackHint",{defaultValue:"No group selected — notifications will be sent to you as private messages."})}),P.length===0&&!j&&r.notifyChatId===""&&e.jsx("p",{className:"text-[11px] text-amber-600 dark:text-amber-400 mt-0.5",children:s("settings:feishu.noChatHint",{defaultValue:"No groups found. Add the bot to a group chat to enable group notifications."})}),r.notifyChatId&&e.jsxs("p",{className:"text-[11px] text-fg-tertiary mt-1 font-mono",children:["ID: ",r.notifyChatId]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary",children:s("settings:feishu.forwardApprovals",{defaultValue:"Forward Approval Requests"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("settings:feishu.forwardApprovalsHint",{defaultValue:"Send approval requests to Feishu as interactive cards"})})]}),e.jsx("button",{onClick:()=>Z("notifyOnApproval",!r.notifyOnApproval),className:`relative w-10 h-5 rounded-full transition-colors duration-200 ${r.notifyOnApproval?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} cursor-pointer`,children:e.jsx("span",{className:`block w-4 h-4 bg-white rounded-full shadow transform transition-transform duration-200 ${r.notifyOnApproval?"translate-x-5":"translate-x-0.5"}`})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary",children:s("settings:feishu.forwardNotifications",{defaultValue:"Forward General Notifications"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("settings:feishu.forwardNotificationsHint",{defaultValue:"Send system notifications to Feishu chat"})})]}),e.jsx("button",{onClick:()=>Z("notifyOnNotification",!r.notifyOnNotification),className:`relative w-10 h-5 rounded-full transition-colors duration-200 ${r.notifyOnNotification?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} cursor-pointer`,children:e.jsx("span",{className:`block w-4 h-4 bg-white rounded-full shadow transform transition-transform duration-200 ${r.notifyOnNotification?"translate-x-5":"translate-x-0.5"}`})})]})]}),(r.notifyOnApproval||r.notifyOnNotification)&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-fg-secondary mb-2",children:s("settings:feishu.notifyPriority",{defaultValue:"Minimum Notification Priority"})}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Da.map(({value:A,color:ie})=>{const ue=r.notifyPriority.includes(A);return e.jsxs("button",{onClick:()=>ee(A),className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border transition-colors ${ue?"bg-brand-500/10 border-brand-500/30 text-brand-600":"bg-surface-primary border-border-default text-fg-tertiary hover:border-fg-tertiary"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${ie}`}),A.charAt(0).toUpperCase()+A.slice(1)]},A)})}),e.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1.5",children:s("settings:feishu.priorityHint",{defaultValue:"Only notifications with the selected priority levels will be forwarded"})})]})]})})]}):e.jsxs(ot,{title:s("settings:feishu.quickSetup",{defaultValue:"Quick Setup"}),children:[e.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 space-y-5",children:g==="idle"||g==="error"||g==="done"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"w-16 h-16 mx-auto rounded-2xl bg-gradient-to-br from-blue-500/20 to-indigo-500/20 border border-blue-500/30 flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-blue-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm12 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"})})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:s("settings:feishu.oneClickTitle",{defaultValue:"One-Click Feishu Integration"})}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1 max-w-sm mx-auto",children:s("settings:feishu.oneClickDesc",{defaultValue:"Scan a QR code with Feishu to automatically create and configure the app. No manual setup needed."})})]}),e.jsxs("button",{onClick:X,disabled:g==="done",className:"inline-flex items-center gap-2 px-6 py-2.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shadow-sm",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm12 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"})}),s("settings:feishu.scanToCreate",{defaultValue:"Scan QR Code to Create App"})]})]}),e.jsx("div",{className:"border-t border-border-default pt-4",children:e.jsx("p",{className:"text-[11px] text-fg-tertiary text-center",children:s("settings:feishu.oneClickPermissions",{defaultValue:"The app will be created with permissions: bot messaging, message receiving, user info reading, and group chat management."})})})]}):e.jsxs("div",{className:"text-center space-y-4",children:[g==="waiting_qr"&&!N&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[e.jsx("div",{className:"w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-fg-secondary",children:s("settings:feishu.generatingQR",{defaultValue:"Generating QR code..."})})]}),N&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"inline-block p-4 bg-white rounded-xl shadow-sm border border-gray-200",children:B?e.jsx("img",{src:B,alt:"Feishu QR Code",className:"w-48 h-48"}):e.jsx("div",{className:"w-48 h-48 flex items-center justify-center",children:e.jsx("div",{className:"w-5 h-5 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"})})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-fg-primary",children:s("settings:feishu.scanWithFeishu",{defaultValue:"Scan with Feishu app"})}),e.jsx("p",{className:"text-xs text-fg-tertiary",children:s("settings:feishu.scanHint",{defaultValue:"Use your Feishu mobile app to scan and authorize. The app will be created in your organization."})}),K>0&&e.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("settings:feishu.qrExpire",{defaultValue:`QR code expires in ${Math.floor(K/60)} minutes`,minutes:Math.floor(K/60)})})]}),e.jsx("button",{onClick:Q,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs text-fg-tertiary hover:text-fg-secondary border border-border-default rounded-lg hover:bg-surface-overlay transition-colors",children:s("common:cancel",{defaultValue:"Cancel"})})]})]})}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{onClick:()=>S(!h),className:"inline-flex items-center gap-1.5 text-xs text-fg-tertiary hover:text-fg-secondary transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${h?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),s("settings:feishu.manualConfig",{defaultValue:"Manual configuration (advanced)"})]}),h&&e.jsxs("div",{className:"mt-3 bg-surface-secondary border border-border-default rounded-xl p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-fg-secondary mb-1.5",children:["App ID ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:r.appId,onChange:A=>H("appId",A.target.value),onBlur:()=>{r.appId&&r.appSecret&&(G.current&&clearTimeout(G.current),m(ne.current))},placeholder:"cli_xxxxxxxxxxxxxx",className:"w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors font-mono"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-fg-secondary mb-1.5",children:["App Secret ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:_?"text":"password",value:r.appSecret,onChange:A=>H("appSecret",A.target.value),onBlur:()=>{r.appId&&r.appSecret&&(G.current&&clearTimeout(G.current),m(ne.current))},placeholder:"Enter your Feishu app secret",className:"w-full px-3 py-2 pr-10 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors font-mono"}),e.jsx("button",{type:"button",onClick:()=>z(!_),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-fg-tertiary hover:text-fg-secondary transition-colors",children:_?e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"})}):e.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]})]})]})]})]}),M&&!He&&e.jsx(nn,{type:M.type,text:M.text})]})]})]})}const Qe=["claude-code","codex","cursor-agent"],An=10;function an(s){const r={};for(const o of Qe){const n=s.tools[o],a=n?.timeoutMs??An*6e4;r[o]={enabled:n?.enabled??!0,binaryPath:n?.binaryPath??"",defaultArgs:(n?.defaultArgs??[]).join(" "),timeoutMin:String(Math.round(a/6e4)),defaultModel:n?.defaultModel??"",maxBudgetPerSessionUsd:n?.maxBudgetPerSessionUsd?String(n.maxBudgetPerSessionUsd):"",approvalRequired:n?.approvalRequired??!1}}return r}function Ms({checked:s,onChange:r,disabled:o}){return e.jsx("button",{type:"button",onClick:r,disabled:o,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${s?"bg-green-500":"bg-gray-600"} ${o?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${s?"translate-x-4":"translate-x-1"}`})})}function Bs({type:s,text:r}){return e.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${s==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:r})}function lt({className:s="w-3 h-3"}){return e.jsxs("svg",{className:`animate-spin ${s}`,viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function on({children:s}){return e.jsx("div",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider",children:s})}function Fa({expanded:s}){return e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${s?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})}function $a({info:s}){const{t:r}=me("settings"),o=s?.available&&s?.authenticated,n=s?.available,a=r(o?"codingTools.ready":n?"codingTools.needsAuth":"codingTools.notInstalled"),t=o?"bg-green-500/15 text-green-500":n?"bg-amber-500/15 text-amber-500":"bg-gray-600/20 text-fg-tertiary",d=o?"bg-green-400":n?"bg-amber-400":"bg-gray-500";return e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${t}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${d}`}),a]})}const Va=new Set(["cursor-agent","claude-code"]),Ha={"cursor-agent":"CURSOR_API_KEY","claude-code":"ANTHROPIC_API_KEY",codex:"CODEX_API_KEY"},qa=15e3,za=12;function Wa({name:s,onAuthDone:r}){const{t:o}=me(["settings","common"]),[n,a]=l.useState("idle"),[t,d]=l.useState(!1),[c,u]=l.useState(!1),[f,v]=l.useState(""),[M,x]=l.useState(null),b=l.useRef(null),w=l.useRef(0),P=Va.has(s),U=Ha[s]??"",j=l.useCallback(()=>{b.current&&(clearInterval(b.current),b.current=null),w.current=0,u(!1)},[]);l.useEffect(()=>()=>j(),[j]);const C=l.useCallback(()=>{j(),w.current=0,u(!0),b.current=setInterval(async()=>{w.current++;try{(await $.settings.detectCodingTool(s))?.authenticated&&(j(),x({ok:!0,text:o("codingTools.authSuccess")}),d(!1),r())}catch{}w.current>=za&&(j(),d(!1),x({ok:!1,text:o("codingTools.authPollTimeout")}))},qa)},[s,r,j,o]),g=async()=>{d(!0),x(null);try{const N=await $.settings.authCodingTool(s,"cli_login");N.success&&N.authenticated?(x({ok:!0,text:o("codingTools.authSuccess")}),r(),d(!1)):N.success?(x({ok:!1,text:o("codingTools.authBrowserHint")}),C()):(x({ok:!1,text:N.error??o("codingTools.authFailed")}),d(!1))}catch{x({ok:!1,text:o("codingTools.authFailed")}),d(!1)}},p=async()=>{if(f.trim()){d(!0),x(null);try{const N=await $.settings.authCodingTool(s,"api_key",f.trim());N.success?(x({ok:!0,text:o("codingTools.apiKeySaved",{envVar:N.envVar??U})}),v(""),r()):x({ok:!1,text:o("codingTools.authFailed")})}catch{x({ok:!1,text:o("codingTools.authFailed")})}finally{d(!1)}}};return n==="idle"?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[P&&e.jsx("button",{type:"button",onClick:()=>{a("login"),g()},className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors",children:o("codingTools.loginBtn")}),e.jsx("button",{type:"button",onClick:()=>a("key"),className:"px-2.5 py-1 text-[10px] font-medium border border-border-default text-fg-secondary rounded-md hover:text-fg-primary hover:border-gray-600 transition-colors",children:o("codingTools.apiKeyBtn")})]}):n==="login"?e.jsxs("div",{className:"space-y-1.5",children:[(t||c)&&e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-brand-500",children:[e.jsx(lt,{}),e.jsx("span",{children:o(c?"codingTools.authPolling":"codingTools.loginWaiting")})]}),M&&e.jsx(Bs,{type:M.ok?"ok":"err",text:M.text}),!t&&!c&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>{x(null),r()},className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors",children:o("codingTools.recheckAuth")}),e.jsx("button",{type:"button",onClick:()=>{a("idle"),x(null),j()},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary",children:o("common:cancel")})]}),c&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{j(),d(!1),x(null),r()},className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors",children:o("codingTools.recheckAuth")}),e.jsx("button",{type:"button",onClick:()=>{j(),d(!1),x(null),a("idle")},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary",children:o("common:cancel")})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[s==="cursor-agent"&&e.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[o("codingTools.cursorApiKeyNote")," ",e.jsx("a",{href:o("codingTools.cursorDashboardUrl"),target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:underline",children:"↗"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"password",value:f,onChange:N=>v(N.target.value),placeholder:U,className:"flex-1 px-2.5 py-1 text-[10px] bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono min-w-0",onKeyDown:N=>{N.key==="Enter"&&p()}}),e.jsx("button",{type:"button",onClick:()=>{p()},disabled:t||!f.trim(),className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors disabled:opacity-40 shrink-0",children:t?"...":o("common:save")}),e.jsx("button",{type:"button",onClick:()=>{a("idle"),x(null),v("")},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0",children:o("common:cancel")})]}),M&&e.jsx(Bs,{type:M.ok?"ok":"err",text:M.text})]})}function Ga({source:s}){const{t:r}=me("settings");if(!s)return null;const o=r(s==="api"?"codingTools.modelSourceApi":s==="static"?"codingTools.modelSourceStatic":"codingTools.modelSourceCli"),n=s==="api"?"bg-green-500/15 text-green-500":s==="static"?"bg-blue-500/15 text-blue-400":"bg-amber-500/15 text-amber-500";return e.jsx("span",{className:`text-[9px] font-medium px-1.5 py-0.5 rounded-full ${n}`,children:o})}function Ya({name:s,value:r,onChange:o}){const{t:n}=me("settings"),[a,t]=l.useState([]),[d,c]=l.useState(!1),[u,f]=l.useState(null),[v,M]=l.useState(),[x,b]=l.useState(!1),[w,P]=l.useState(""),U=l.useRef(null),j=l.useRef(!1),C=l.useCallback(async(N=!1)=>{if(!(j.current&&!N)){j.current=!0,c(!0),f(null);try{const I=await $.settings.listCodingToolModels(s),B=I.models??[];t(B),M(I.source),B.length===0&&f(n("codingTools.modelsEmpty"))}catch{f(n("codingTools.modelsFetchError"))}c(!1)}},[s,n]);l.useEffect(()=>{C()},[C]),l.useEffect(()=>{const N=I=>{U.current&&!U.current.contains(I.target)&&b(!1)};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);const g=a.filter(N=>!w||N.id.toLowerCase().includes(w.toLowerCase())||N.name.toLowerCase().includes(w.toLowerCase())),p=s==="cursor-agent"?"codingTools.modelGuidanceCursor":s==="claude-code"?"codingTools.modelGuidanceClaude":s==="codex"?"codingTools.modelGuidanceCodex":null;return e.jsxs("div",{ref:U,className:"relative",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:x?w:r,onChange:N=>{P(N.target.value),o(N.target.value)},onFocus:()=>{b(!0),P(r)},placeholder:n("codingTools.modelPlaceholder"),className:"flex-1 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"}),!d&&v&&e.jsx(Ga,{source:v}),d&&e.jsx(lt,{className:"w-3.5 h-3.5 text-fg-tertiary shrink-0"}),!d&&u&&e.jsx("button",{type:"button",onClick:()=>{j.current=!1,C(!0)},title:n("codingTools.modelsRetry"),className:"text-[10px] text-amber-500 hover:text-amber-400 shrink-0",children:"↻"})]}),u&&!d&&e.jsx("div",{className:"text-[10px] text-amber-500 mt-0.5",children:u}),p&&!d&&e.jsx("div",{className:"text-[10px] mt-1 text-fg-tertiary",children:n(p)}),x&&e.jsx("div",{className:"absolute z-50 mt-1 w-full bg-surface-secondary border border-border-default rounded-lg shadow-xl max-h-48 overflow-y-auto",children:d?e.jsxs("div",{className:"px-3 py-2 text-[10px] text-fg-tertiary flex items-center gap-2",children:[e.jsx(lt,{}),n("codingTools.modelsLoading")]}):g.length===0&&!w?e.jsx("div",{className:"px-3 py-2 text-[10px] text-fg-tertiary",children:n("codingTools.noModelsFound")}):e.jsxs(e.Fragment,{children:[r&&e.jsx("button",{type:"button",onClick:()=>{o(""),P(""),b(!1)},className:"w-full text-left px-3 py-1.5 text-xs text-fg-tertiary hover:bg-surface-elevated transition-colors italic",children:n("codingTools.useToolDefault")}),g.map(N=>e.jsxs("button",{type:"button",onClick:()=>{o(N.id),P(N.id),b(!1)},className:`w-full text-left px-3 py-1.5 text-xs hover:bg-surface-elevated transition-colors ${N.id===r?"bg-brand-500/10 text-brand-500":"text-fg-primary"}`,children:[e.jsx("span",{className:"font-mono",children:N.id}),N.name!==N.id&&e.jsx("span",{className:"text-fg-tertiary ml-2",children:N.name}),N.isDefault&&e.jsx("span",{className:"text-[9px] text-fg-tertiary ml-1.5 bg-surface-primary px-1.5 py-0.5 rounded",children:"default"})]},N.id))]})})]})}const At="markus_coding_tool_detect",Ja=1440*60*1e3;function Qa(){const s={"claude-code":{status:"idle"},codex:{status:"idle"},"cursor-agent":{status:"idle"}};try{const r=localStorage.getItem(At);if(!r)return s;const o=JSON.parse(r),n={...s};for(const a of Qe){const t=o[a];if(!t)continue;const d="data"in t&&"ts"in t?t.data:t;n[a]={status:"done",data:d}}return n}catch{return s}}function Xa(s){try{const r=localStorage.getItem(At);return r?!!JSON.parse(r)[s]:!1}catch{return!1}}function Za(s){try{const r=localStorage.getItem(At);if(!r)return!0;const n=JSON.parse(r)[s];return n&&"ts"in n&&typeof n.ts=="number"?Date.now()-n.ts>Ja:!0}catch{return!0}}function Ts(s){try{const r={},o=Date.now();for(const n of Qe){const a=s[n];a.status==="done"&&(r[n]={data:a.data,ts:o})}localStorage.setItem(At,JSON.stringify(r))}catch{}}const eo=800;function to(s,r){const o={};for(const n of Qe){const a=r[n],t=a.defaultArgs.trim()?a.defaultArgs.trim().split(/\s+/).filter(Boolean):void 0,d=parseFloat(a.timeoutMin),c=Number.isFinite(d)&&d>0?Math.round(d*6e4):An*6e4,u=parseFloat(a.maxBudgetPerSessionUsd);o[n]={tool:n,enabled:a.enabled,binaryPath:a.binaryPath.trim()||void 0,defaultArgs:t,timeoutMs:c,defaultModel:a.defaultModel.trim()||void 0,maxBudgetPerSessionUsd:n==="claude-code"&&Number.isFinite(u)&&u>0?u:void 0,approvalRequired:a.approvalRequired||void 0}}return{enabled:s,tools:o}}function so(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(!0),[n,a]=l.useState(!1),[t,d]=l.useState(!1),[c,u]=l.useState(Qa),[f,v]=l.useState(()=>an({tools:{}})),[M,x]=l.useState(null),[b,w]=l.useState(new Set),[P,U]=l.useState(null),[j,C]=l.useState({}),g=l.useRef(null),p=l.useRef(!1),N=l.useCallback(async(h,S=!1)=>{S||u(_=>({..._,[h]:{status:"loading"}}));try{const _=await $.settings.detectCodingTool(h);u(z=>{const G={...z,[h]:{status:"done",data:_}};return Ts(G),G})}catch{S||u(_=>({..._,[h]:{status:"idle"}}))}},[]),I=l.useCallback(async h=>{U(h),C(S=>({...S,[h]:null}));try{const S=await $.settings.testCodingTool(h);let _;if(S.success){const z=[s("codingTools.testSuccess")];S.model&&z.push(s("codingTools.testModel",{model:S.model})),S.apiKeySource&&!S.apiKeySource.includes("@")?z.push(s("codingTools.testAuthVia",{source:S.apiKeySource})):S.apiKeySource?.includes("@")&&z.push(S.apiKeySource),_=z.join(" · ")}else _=S.error?`${s("codingTools.testFailed")}:${S.error}`:s("codingTools.testFailed");C(z=>({...z,[h]:{success:S.success,detail:_}})),S.success&&u(z=>{const G=z[h];if(G.status==="done"&&!G.data.authenticated){const ne={...z,[h]:{status:"done",data:{...G.data,authenticated:!0}}};return Ts(ne),ne}return z})}catch{C(_=>({..._,[h]:{success:!1,detail:s("codingTools.testFailed")}}))}finally{U(null)}},[s]),B=l.useCallback(h=>{w(S=>{const _=new Set(S);return _.has(h)?_.delete(h):_.add(h),_.has(h)&&c[h].status==="idle"&&N(h),_})},[c,N]),F=l.useCallback(async()=>{o(!0),x(null);try{const h=await $.settings.getCodingTools();if(d(h.enabled),v(an(h)),p.current=!0,h.enabled)for(const S of Qe)h.tools[S]?.enabled&&Za(S)&&N(S,Xa(S))}catch{x({type:"err",text:s("codingTools.failedToLoad")})}finally{o(!1)}},[s,N]);l.useEffect(()=>{F()},[F]),l.useEffect(()=>{if(p.current)return g.current&&clearTimeout(g.current),g.current=setTimeout(async()=>{x(null);try{await $.settings.updateCodingTools(to(t,f)),x({type:"ok",text:s("codingTools.saved")})}catch{x({type:"err",text:s("codingTools.failedToSave")})}},eo),()=>{g.current&&clearTimeout(g.current)}},[t,f,s]);const K=async()=>{a(!0),x(null);try{const h=await $.settings.detectCodingTools(),S={"claude-code":{status:"idle"},codex:{status:"idle"},"cursor-agent":{status:"idle"}};for(const _ of h.tools)S[_.name]={status:"done",data:_};u(S),Ts(S)}catch{x({type:"err",text:s("codingTools.detectionFailed")})}finally{a(!1)}},O=(h,S)=>{v(_=>({..._,[h]:{..._[h],...S}}))},R=h=>{const S=c[h];return S.status==="done"?S.data:void 0},L=h=>c[h].status==="loading";return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:s("codingTools.title")}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-fg-tertiary",children:s("codingTools.description")}),e.jsx("div",{className:"bg-surface-elevated rounded-xl px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("codingTools.globalEnable")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("codingTools.globalEnableDesc")})]}),e.jsx(Ms,{checked:t,onChange:()=>d(h=>!h),disabled:r})]})}),r?e.jsx("div",{className:"text-sm text-fg-tertiary py-8 text-center",children:s("common:loading")}):Qe.map(h=>{const S=R(h),_=f[h],z=L(h),G={"claude-code":"Claude Code",codex:"Codex","cursor-agent":"Cursor Agent"},ne=S?.displayName??G[h]??h,T=b.has(h),q=S&&!S.available,V=S?.available&&!S?.authenticated,m=S?!S.available:!1;return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>B(h),className:"w-full flex items-center gap-3 px-4 py-3 hover:bg-white/[0.02] transition-colors text-left",children:[e.jsx(Fa,{expanded:T}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:ne}),z?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[10px] font-medium bg-gray-600/20 text-fg-tertiary",children:[e.jsx(lt,{}),s("codingTools.detectingTool")]}):e.jsx($a,{info:S}),S?.version&&e.jsx("span",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:S.version})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",onClick:E=>E.stopPropagation(),children:e.jsx(Ms,{checked:_.enabled,onChange:()=>O(h,{enabled:!_.enabled})})})]}),T&&e.jsxs("div",{className:"px-4 pb-4 border-t border-border-default",children:[S?.path&&e.jsx("div",{className:"text-[10px] text-fg-tertiary font-mono mt-3 truncate",title:S.path,children:S.path}),q&&S&&e.jsxs("div",{className:"mt-3 p-3 bg-amber-500/5 border border-amber-500/20 rounded-lg",children:[e.jsx("div",{className:"text-xs text-amber-500 font-medium mb-1",children:s("codingTools.stepInstall")}),S.installHint&&e.jsx("code",{className:"text-[10px] bg-surface-primary px-2 py-1 rounded block text-fg-secondary",children:S.installHint})]}),V&&e.jsxs("div",{className:"mt-3 p-3 bg-amber-500/5 border border-amber-500/20 rounded-lg",children:[e.jsx("div",{className:"text-xs text-amber-500 font-medium mb-2",children:s("codingTools.stepAuth")}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mb-2",children:s("codingTools.authHint")}),e.jsx(Wa,{name:h,onAuthDone:()=>{N(h)}})]}),e.jsxs("div",{className:"grid gap-4 mt-4",children:[m&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.binaryPath")}),e.jsx("input",{type:"text",value:_.binaryPath,onChange:E=>O(h,{binaryPath:E.target.value}),placeholder:s("codingTools.binaryPathPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"})]}),e.jsx(on,{children:s("codingTools.sectionModelExec")}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.defaultModel")}),e.jsx(Ya,{name:h,value:_.defaultModel,onChange:E=>O(h,{defaultModel:E})}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:s("codingTools.defaultModelHint")})]}),h==="claude-code"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.budgetCap")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-tertiary",children:"$"}),e.jsx("input",{type:"number",min:0,step:.5,value:_.maxBudgetPerSessionUsd,onChange:E=>O(h,{maxBudgetPerSessionUsd:E.target.value}),placeholder:"5.00",className:"w-32 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none tabular-nums"}),e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"USD"})]}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:s("codingTools.budgetCapHint")})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-fg-secondary",children:s("codingTools.approvalRequired")}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:s("codingTools.approvalRequiredHint")})]}),e.jsx(Ms,{checked:_.approvalRequired,onChange:()=>O(h,{approvalRequired:!_.approvalRequired})})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.timeout")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:1,step:1,value:_.timeoutMin,onChange:E=>O(h,{timeoutMin:E.target.value}),className:"w-24 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:border-brand-500 outline-none tabular-nums"}),e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s("codingTools.timeoutUnit")})]})]})}),e.jsx(on,{children:s("codingTools.sectionAdvanced")}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.defaultArgs")}),e.jsx("input",{type:"text",value:_.defaultArgs,onChange:E=>O(h,{defaultArgs:E.target.value}),placeholder:s("codingTools.defaultArgsPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"})]}),e.jsxs("div",{className:"pt-3 border-t border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{type:"button",disabled:P===h,onClick:()=>I(h),className:"px-3 py-1.5 text-xs font-medium bg-brand-500 text-white rounded-lg hover:bg-brand-600 disabled:opacity-50 transition-colors flex items-center gap-1.5 shrink-0",children:[P===h&&e.jsx(lt,{className:"w-3 h-3"}),s(P===h?"codingTools.testing":"codingTools.testConfig")]}),!j[h]&&e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s("codingTools.testConfigHint")})]}),j[h]&&e.jsx("div",{className:`mt-2 px-3 py-2 rounded-lg text-xs ${j[h].success?"bg-green-500/10 border border-green-500/20 text-green-600":"bg-red-500/10 border border-red-500/20 text-red-500"}`,children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"shrink-0 mt-0.5",children:j[h].success?"✓":"✗"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{children:j[h].detail}),!j[h].success&&e.jsx("div",{className:"text-[10px] mt-1 opacity-80",children:s("codingTools.testFailedHint")})]})]})})]})]})]})]},h)}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:M&&e.jsx(Bs,{type:M.type,text:M.text})}),e.jsx("button",{type:"button",onClick:()=>{K()},disabled:n||r,className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:text-fg-primary hover:border-gray-600 rounded-lg transition-colors disabled:opacity-40",children:s(n?"codingTools.detecting":"codingTools.redetect")})]})]})]})}const it=[{id:"serper",labelKey:"searchApi.serper",hintKey:"searchApi.serperHint",field:"serperApiKey"},{id:"tavily",labelKey:"searchApi.tavily",hintKey:"searchApi.tavilyHint",field:"tavilyApiKey"},{id:"google",labelKey:"searchApi.google",hintKey:"searchApi.googleHint",field:"googleSearchApiKey",extraField:"googleSearchCx",extraPlaceholderKey:"searchApi.googleCxPlaceholder"},{id:"bing",labelKey:"searchApi.bing",hintKey:"searchApi.bingHint",field:"bingApiKey"},{id:"brave",labelKey:"searchApi.brave",hintKey:"searchApi.braveHint",field:"braveApiKey"},{id:"serpapi",labelKey:"searchApi.serpapi",hintKey:"searchApi.serpapiHint",field:"serpApiKey"},{id:"exa",labelKey:"searchApi.exa",hintKey:"searchApi.exaHint",field:"exaApiKey"},{id:"bocha",labelKey:"searchApi.bocha",hintKey:"searchApi.bochaHint",field:"bochaApiKey"}],ro=800,ln=[{id:"perplexity/sonar",labelKey:"searchApi.modelSonar"},{id:"perplexity/sonar-pro",labelKey:"searchApi.modelSonarPro"}];function dn({expanded:s}){return e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${s?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})}function Pt({className:s="w-3 h-3"}){return e.jsxs("svg",{className:`${s} animate-spin`,viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function no(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(null),[n,a]=l.useState(!0),[t,d]=l.useState(new Set),[c,u]=l.useState({}),[f,v]=l.useState({}),[M,x]=l.useState(!1),[b,w]=l.useState(!1),[P,U]=l.useState({}),[j,C]=l.useState({}),[g,p]=l.useState({}),[N,I]=l.useState({}),B=l.useRef({}),F=l.useCallback(async()=>{a(!0);try{const m=await $.settings.getSearch();m&&(o(m),it.some(H=>!!m[H.id]?.configured)&&w(!0))}catch{}a(!1)},[]);l.useEffect(()=>{F()},[F]),l.useEffect(()=>()=>{Object.values(B.current).forEach(clearTimeout)},[]);const K=m=>{d(E=>{const H=new Set(E);return H.has(m)?H.delete(m):H.add(m),H})},O=(m,E,H)=>{u(Z=>({...Z,[E]:H})),B.current[m]&&clearTimeout(B.current[m]),B.current[m]=setTimeout(()=>{R(m)},ro)},R=async m=>{const E=it.find(ee=>ee.id===m);if(!E)return;const H=c[E.field]?.trim(),Z=E.extraField?c[E.extraField]?.trim():void 0;if(!(!H&&!Z)){v(ee=>({...ee,[m]:!0})),U(ee=>{const X={...ee};return delete X[m],X});try{const ee={};H&&(ee[E.field]=H),Z&&E.extraField&&(ee[E.extraField]=Z);const X=await $.settings.updateSearch(ee);o(X),u(Q=>{const le={...Q};return delete le[E.field],E.extraField&&delete le[E.extraField],le}),U(Q=>({...Q,[m]:{type:"ok",text:s("searchApi.saved")}})),setTimeout(()=>U(Q=>{const le={...Q};return delete le[m],le}),3e3)}catch{U(ee=>({...ee,[m]:{type:"err",text:s("searchApi.failedToSave")}}))}v(ee=>({...ee,[m]:!1}))}},L=m=>r?.[m],h=m=>L(m)?.configured??!1,S=m=>L(m)?.enabled!==!1,_=async(m,E)=>{I(H=>({...H,[m]:!0}));try{const H={[`${m}Enabled`]:E},Z=await $.settings.updateSearch(H);o(Z)}catch{}I(H=>({...H,[m]:!1}))},z=async m=>{B.current[m]&&(clearTimeout(B.current[m]),delete B.current[m],await R(m)),C(E=>({...E,[m]:!0})),p(E=>{const H={...E};return delete H[m],H});try{const E=await $.settings.testSearch(m);if(E.ok){const H=[s("searchApi.testOk",{count:E.count??0})];E.latencyMs!=null&&H.push(`${E.latencyMs}ms`),E.sample?.title&&H.push(E.sample.title.slice(0,48)),p(Z=>({...Z,[m]:{ok:!0,text:H.join(" · ")}}))}else p(H=>({...H,[m]:{ok:!1,text:E.error||s("searchApi.testFailed")}}))}catch{p(E=>({...E,[m]:{ok:!1,text:s("searchApi.testFailed")}}))}C(E=>({...E,[m]:!1}))},G=async m=>{x(!0);try{const E=await $.settings.updateSearch(m);o(E)}catch{}x(!1)},ne=({id:m,disabled:E})=>{const H=j[m];return e.jsxs("button",{type:"button",onClick:()=>{z(m)},disabled:H||E,className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium bg-surface-primary border border-border-default text-fg-secondary hover:text-fg-primary hover:border-brand-500 disabled:opacity-50 transition-colors",children:[H?e.jsx(Pt,{}):e.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.5 2a6.5 6.5 0 104.096 11.553l3.925 3.925a.75.75 0 101.06-1.06l-3.925-3.925A6.5 6.5 0 008.5 2zM3.5 8.5a5 5 0 1110 0 5 5 0 01-10 0z",clipRule:"evenodd"})}),s(H?"searchApi.testing":"searchApi.test")]})},T=({id:m})=>{const E=g[m];return E?e.jsxs("div",{className:`text-[11px] flex items-start gap-1.5 ${E.ok?"text-green-500":"text-red-500"}`,children:[e.jsx("span",{className:"shrink-0 mt-px",children:E.ok?"✓":"✕"}),e.jsx("span",{className:"break-all",children:E.text})]}):null},q=({id:m})=>{const E=S(m),H=N[m];return e.jsxs("label",{className:"inline-flex items-center gap-2 cursor-pointer shrink-0",onClick:Z=>Z.stopPropagation(),title:s(E?"searchApi.enabled":"searchApi.disabled"),children:[H&&e.jsx(Pt,{className:"w-3 h-3 text-fg-tertiary"}),e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:E,disabled:H,onChange:Z=>{_(m,Z.target.checked)}}),e.jsx("span",{className:"relative w-9 h-5 rounded-full bg-gray-500/40 peer-checked:bg-brand-500 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:transition-transform peer-checked:after:translate-x-4"})]})},V=r?.markus;return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:s("searchApi.title")}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-fg-tertiary",children:s("searchApi.description")}),n?e.jsx("div",{className:"text-sm text-fg-tertiary py-8 text-center",children:s("common:loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-border-default px-4 py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:s("searchApi.markus")}),e.jsx("span",{className:"text-[10px] font-medium text-brand-400",children:s("searchApi.markusBadge")})]}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 truncate",children:s("searchApi.markusHint")})]}),V?.available&&V.enabled&&e.jsx(ne,{id:"markus"}),V?.available?e.jsxs("label",{className:"inline-flex items-center gap-2 cursor-pointer shrink-0",children:[M&&e.jsx(Pt,{className:"w-3 h-3 text-fg-tertiary"}),e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:V.enabled,disabled:M,onChange:m=>{G({useMarkusHosted:m.target.checked})}}),e.jsx("span",{className:"relative w-9 h-5 rounded-full bg-gray-500/40 peer-checked:bg-brand-500 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:transition-transform peer-checked:after:translate-x-4"})]}):e.jsx("span",{className:"text-[11px] text-amber-500 shrink-0",children:s("searchApi.markusUnavailable")})]}),!V?.available&&e.jsx("div",{className:"text-[11px] text-amber-500/90",children:s("searchApi.markusUnavailableHint")}),V?.available&&V.enabled&&e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary shrink-0",htmlFor:"markus-search-model",children:s("searchApi.modelLabel")}),e.jsxs("select",{id:"markus-search-model",value:V.markusSearchModel||"perplexity/sonar",disabled:M,onChange:m=>{G({markusSearchModel:m.target.value})},className:"flex-1 min-w-0 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary outline-none focus:border-brand-500",children:[ln.map(m=>e.jsx("option",{value:m.id,children:s(m.labelKey)},m.id)),V.markusSearchModel&&!ln.some(m=>m.id===V.markusSearchModel)&&e.jsx("option",{value:V.markusSearchModel,children:V.markusSearchModel})]})]}),e.jsx("div",{className:"text-[11px] text-fg-tertiary",children:s("searchApi.modelHint")}),e.jsx(T,{id:"markus"})]}),e.jsxs("div",{className:"rounded-xl border border-border-default overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>w(m=>!m),className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-white/[0.02] transition-colors text-left",children:[e.jsx(dn,{expanded:b}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-2 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:s("searchApi.ownKeysTitle")}),e.jsx("span",{className:"text-xs text-fg-tertiary truncate",children:s("searchApi.ownKeysHint")})]}),e.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0 tabular-nums",children:[it.filter(m=>h(m.id)).length,"/",it.length]})]}),b&&e.jsx("div",{className:"border-t border-border-default px-2 pb-2 space-y-1",children:it.map(m=>{const E=h(m.id),H=t.has(m.id),Z=P[m.id],ee=f[m.id];return e.jsxs("div",{className:"rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsxs("button",{type:"button",onClick:()=>K(m.id),className:`flex-1 min-w-0 flex items-center gap-3 px-3 py-2.5 hover:bg-white/[0.02] transition-colors text-left ${E&&!S(m.id)?"opacity-50":""}`,children:[e.jsx(dn,{expanded:H}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:s(m.labelKey)}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 hidden sm:inline",children:s(m.hintKey)})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:E?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-400"}),e.jsx("span",{className:"text-[10px] font-medium text-green-500",children:s("searchApi.configured")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-gray-500"}),e.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary",children:s("searchApi.notConfigured")})]})})]}),e.jsx("div",{className:"shrink-0 pr-3 pl-2 border-l border-border-default self-stretch flex items-center",children:e.jsx(q,{id:m.id})})]}),H&&e.jsx("div",{className:"px-3 pb-3",children:e.jsxs("div",{className:"mt-1 space-y-2",children:[e.jsx("input",{type:"password",value:c[m.field]??"",onChange:X=>O(m.id,m.field,X.target.value),placeholder:s(E?"modelProviders.apiKeyPlaceholder":"searchApi.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"}),m.extraField&&e.jsx("input",{type:"text",value:c[m.extraField]??"",onChange:X=>O(m.id,m.extraField,X.target.value),placeholder:m.extraPlaceholderKey?s(m.extraPlaceholderKey):"",className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"}),e.jsxs("div",{className:"flex items-center gap-2 min-h-[28px] flex-wrap",children:[e.jsx(ne,{id:m.id,disabled:!E&&!c[m.field]?.trim()}),ee&&e.jsxs("span",{className:"text-[10px] text-fg-tertiary flex items-center gap-1",children:[e.jsx(Pt,{}),s("common:saving")]}),Z&&e.jsx("span",{className:`text-[10px] ${Z.type==="ok"?"text-green-500":"text-red-500"}`,children:Z.text})]}),e.jsx(T,{id:m.id})]})})]},m.id)})})]})]})]})]})}const ao=new Set(["claude-opus-4-6","claude-sonnet-4-20250514","claude-3-5-haiku-20241022","gpt-5.4","gpt-4o","o4-mini","gemini-3-1-pro","gemini-2.5-flash","MiniMax-M2.7","MiniMax-M2.5","xiaomi/mimo-v2-pro","anthropic/claude-opus-4-6","openai/gpt-5.4","google/gemini-3-1-pro","deepseek-v4-flash","deepseek-v4-pro","deepseek-chat","deepseek-reasoner"]),Mn=[{id:"appearance",labelKey:"nav.appearance"},{id:"storage",labelKey:"nav.storage",adminOnly:!0},{id:"providers",labelKey:"nav.providers",adminOnly:!0},{id:"execution",labelKey:"nav.execution",adminOnly:!0},{id:"browser",labelKey:"nav.browser",adminOnly:!0},{id:"coding-tools",labelKey:"nav.codingTools",adminOnly:!0},{id:"search",labelKey:"nav.search",adminOnly:!0},{id:"integrations",labelKey:"nav.integrations",adminOnly:!0},{id:"account",labelKey:"nav.account"}],cn=[{labelKey:"nav.group.general",tabs:["appearance","storage"]},{labelKey:"nav.group.aiConfig",tabs:["providers","execution"]},{labelKey:"nav.group.tools",tabs:["browser","coding-tools","search"]},{labelKey:"nav.group.connections",tabs:["integrations"]},{labelKey:"nav.group.account",tabs:["account"]}],oo={Database:"database",Agents:"agents",Skills:"skills","LLM Logs":"llmLogs","Builder Artifacts":"builderArtifacts",Teams:"teams",Shared:"shared",Knowledge:"knowledge"},Es={Database:"keep",Agents:"keep",Skills:"caution","LLM Logs":"safe","Builder Artifacts":"caution",Teams:"keep",Shared:"caution",Knowledge:"caution"},un={appearance:"M21 4H14 M10 4H3 M21 12H12 M8 12H3 M21 20H16 M12 20H3 M14 2v4 M8 10v4 M16 18v4",storage:"M12 8c4.418 0 8-1.343 8-3s-3.582-3-8-3-8 1.343-8 3 3.582 3 8 3Z M4 5v6c0 1.657 3.582 3 8 3s8-1.343 8-3V5 M4 11v6c0 1.657 3.582 3 8 3s8-1.343 8-3v-6",providers:"M9 2v3 M15 2v3 M9 19v3 M15 19v3 M2 9h3 M2 15h3 M19 9h3 M19 15h3 M6 6h12v12H6z M9 9h6v6H9z",execution:"M12 8V4H8 M4 8h16a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2z M2 14h2 M20 14h2 M15 13v2 M9 13v2",browser:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20z M2 12h20 M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z","coding-tools":"M16 18l6-6-6-6 M8 6l-6 6 6 6",search:"M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16z M21 21l-4.3-4.3",integrations:"M9 17H7A5 5 0 0 1 7 7h2 M15 7h2a5 5 0 1 1 0 10h-2 M8 12h8",account:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2 M12 7a4 4 0 1 0 0 8 4 4 0 0 0 0-8Z",_default:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"};function xn({id:s,className:r}){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 ${r??""}`,children:e.jsx("path",{d:un[s]??un._default})})}const io={users:"account",organization:"account",license:"account",remote:"account"};function mn(){const r=window.location.hash.slice(1).split("/");if(r[0]==="settings"&&r[1]){const o=r[1],a=io[o]??o;if(Mn.some(t=>t.id===a))return a}return null}function Ao({theme:s,onThemeChange:r,authUser:o,onLogout:n,onUserUpdated:a}={}){const{t,i18n:d}=me(["settings","common"]),c=sa(),[u,f]=l.useState(mn);l.useEffect(()=>{const i=()=>f(mn());return window.addEventListener("hashchange",i),()=>window.removeEventListener("hashchange",i)},[]);const v=l.useCallback(i=>{f(i),history.pushState(null,"",`#settings/${i}`)},[]),M=l.useCallback(()=>{f(null),history.pushState(null,"","#settings")},[]),x=u??(c?null:"appearance"),[b,w]=l.useState(!1),[P,U]=l.useState(!1);l.useEffect(()=>{!kr()||!window.markusDesktop?.getLoginItemSettings||window.markusDesktop.getLoginItemSettings().then(i=>w(!!i.openAtLogin)).catch(()=>{})},[]);const j=l.useCallback(async()=>{if(!window.markusDesktop?.setLoginItemSettings||P)return;const i=!b;U(!0),w(i);try{const y=await window.markusDesktop.setLoginItemSettings(i);w(!!y.openAtLogin)}catch{w(!i)}finally{U(!1)}},[b,P]),[C,g]=l.useState(null),[p,N]=l.useState(null),[I,B]=l.useState(""),[F,K]=l.useState(!1),[O,R]=l.useState(null),[L,h]=l.useState(null),[S,_]=l.useState(null),[z,G]=l.useState({}),[ne,T]=l.useState(null),[q,V]=l.useState(null),[m,E]=l.useState(null),[H,Z]=l.useState(!1),[ee,X]=l.useState(null),[Q,le]=l.useState({}),[Ee,dt]=l.useState(!1),[pe,Xe]=l.useState(null),[He,ct]=l.useState(!1),[A,ie]=l.useState(""),[ue,Ke]=l.useState(!1),[qe,Se]=l.useState(null),[Ds,Ks]=l.useState(""),[Ie,Mt]=l.useState(!0),[Ne,Tn]=l.useState(null),[Us,Fs]=l.useState(!1),[Tt,ut]=l.useState(null),[$s,En]=l.useState([]),[Vs,Et]=l.useState([]),[Ze,ze]=l.useState(null),[It,ge]=l.useState(null),[xt,Hs]=l.useState(""),[In,et]=l.useState(null),[tt,Lt]=l.useState(null),xe=l.useRef(null),qs=l.useRef(!1),[zs,Rt]=l.useState(200),[Ws,Gs]=l.useState(!1),[Ot,mt]=l.useState(null),[gt,Bt]=l.useState(!1),[Ys,_t]=l.useState(1),[Js,Qs]=l.useState(!1),[Dt,st]=l.useState(null),[Kt,ft]=l.useState(!1),[Le,Ut]=l.useState(0),[Ft,pt]=l.useState(!0),[Re,ht]=l.useState(!1),[be,Xs]=l.useState(!1),[ko,Ln]=l.useState(9333),[ye,he]=l.useState(!1),[$t,de]=l.useState(null),[Me,Rn]=l.useState(null),[Vt,Zs]=l.useState(!1),[bt,On]=l.useState(null),[Co,So]=l.useState(!1),ae=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`}),er=l.useRef(new Set),tr=l.useCallback(()=>{$.health().then(g).catch(()=>{})},[]),Oe=l.useCallback(()=>{fetch("/api/settings/llm").then(i=>i.ok?i.json():Promise.reject(i.status)).then(i=>{i&&typeof i=="object"&&"providers"in i&&(N(i),B(i.defaultProvider))}).catch(()=>{})},[]),rt=l.useCallback(()=>{fetch("/api/settings/network").then(i=>i.ok?i.json():Promise.reject(i.status)).then(i=>{Ks(i.network?.proxy??""),Mt(i.network?.proxyEnabled!==!1),Tn(i.effective)}).catch(()=>{})},[]),sr=l.useCallback(()=>{fetch("/api/settings/oauth/providers").then(i=>i.ok?i.json():Promise.reject(i.status)).then(i=>En(i.providers??[])).catch(()=>{})},[]),yt=l.useCallback((i=!1)=>{fetch(`/api/settings/oauth/profiles${i?"?validate=1":""}`,{headers:ae()}).then(D=>D.ok?D.json():Promise.reject(D.status)).then(D=>Et(D.profiles??[])).catch(()=>{})},[]),rr=l.useCallback(()=>{$.settings.getAgent().then(i=>{i&&typeof i.maxToolIterations=="number"&&Rt(i.maxToolIterations),i?.cognitive&&(Bt(i.cognitive.enabled??!1),_t(i.cognitive.maxDepth??1))}).catch(()=>{})},[]),nr=l.useCallback(()=>{$.settings.getBrowser().then(i=>{i&&(ft(i.bringToFront??!1),Ut(i.remoteDebuggingPort??0),pt(i.autoCloseTabs??!0),ht(i.autoClickAllowDialog??!1),Xs(i.extensionConnected??!1),Ln(i.extensionBridgePort??9333))}).catch(()=>{})},[]),We=l.useCallback(()=>{Zs(!0),$.system.storage().then(Rn).catch(()=>{}).finally(()=>Zs(!1)),$.system.orphans().then(On).catch(()=>{})},[]);l.useEffect(()=>{tr()},[tr]),l.useEffect(()=>{if(x&&!er.current.has(x))switch(er.current.add(x),x){case"providers":Oe(),rt(),sr(),yt(!0);break;case"execution":rr();break;case"browser":nr();break;case"storage":We();break}},[x,Oe,rt,sr,yt,rr,nr,We]),l.useEffect(()=>{const i=()=>We();return window.addEventListener("markus:data-changed",i),()=>window.removeEventListener("markus:data-changed",i)},[We]),l.useEffect(()=>{!L||z[L]||(T(L),L==="markus"&&V(null),$.modelCatalog.getLive(L).then(i=>{G(y=>({...y,[L]:i.models})),L==="markus"&&(i.error&&V(String(i.error)),Oe())}).catch(i=>{L==="markus"&&V(i instanceof Error?i.message:String(i)),$.modelCatalog.getByProvider(L).then(y=>{G(D=>({...D,[L]:y.models}))}).catch(()=>{})}).finally(()=>T(null)))},[L]);const Ht=l.useCallback(async()=>{Z(!0),X(null),E(null),le({});try{const i=await fetch("/api/settings/env-models",{headers:ae()});if(!i.ok){X({type:"err",text:t("envConfig.detectionFailedHttp",{status:i.status})});return}const y=await i.json();if(E(y),y.detected.length===0)X({type:"err",text:t("envConfig.noKeysFound")});else{const D={};for(const J of y.detected)D[J.provider]=!0;le(D)}}catch{X({type:"err",text:t("envConfig.failedToDetect")})}finally{Z(!1)}},[t]),qt=l.useCallback(async()=>{ct(!0),Se(null),Xe(null);try{const i=await fetch("/api/settings/detect-ollama",{headers:ae()});if(!i.ok){Se({type:"err",text:t("ollama.detectFailed")});return}const y=await i.json();Xe(y),y.found&&y.models&&y.models.length>0?ie(y.models[0].name):y.found||Se({type:"err",text:y.error||t("ollama.notRunning")})}catch{Se({type:"err",text:t("ollama.detectFailed")})}finally{ct(!1)}},[t]),ar=p?Object.values(p.providers).some(i=>i.configured):!1;l.useEffect(()=>{p&&!ar&&!qs.current&&(qs.current=!0,Ht(),qt())},[p,ar,Ht,qt]);const Bn=async()=>{if(!(!I||I===p?.defaultProvider)){K(!0),R(null);try{const i=await fetch("/api/settings/llm",{method:"POST",headers:ae(),body:JSON.stringify({defaultProvider:I})}),y=await i.json();i.ok?(N(y),R({type:"ok",text:t("defaultProvider.updated",{name:y.defaultProvider})})):R({type:"err",text:y.error??t("modelProviders.saveFailed")})}catch{R({type:"err",text:t("common:networkError")})}finally{K(!1)}}},_n=async(i,y)=>{_(i);try{const D=await fetch(`/api/settings/llm/providers/${i}/toggle`,{method:"POST",headers:ae(),body:JSON.stringify({enabled:y})});if(D.ok){const J=await D.json();N(J)}}catch{}finally{_(null)}},Dn=async()=>{if(!m)return;const i=m.detected.filter(y=>Q[y.provider]);if(i.length===0){X({type:"err",text:t("envConfig.selectAtLeastOne")});return}dt(!0),X(null);try{const y=await fetch("/api/settings/env-models",{method:"POST",headers:ae(),body:JSON.stringify({providers:i.map(J=>({provider:J.provider,model:J.model,baseUrl:J.baseUrl,enabled:!0}))})});if(!y.ok){X({type:"err",text:t("envConfig.applyFailed",{status:y.status})});return}const D=await y.json();X({type:"ok",text:D.message}),E(null),le({}),Oe()}catch{X({type:"err",text:t("envConfig.failedToApply")})}finally{dt(!1)}},Kn=async()=>{if(!(!pe?.found||!A)){Ke(!0),Se(null);try{const i=await fetch("/api/settings/llm/providers",{method:"POST",headers:ae(),body:JSON.stringify({name:"ollama",model:A,baseUrl:pe.baseUrl||"http://localhost:11434"})});if(i.ok){const y=await i.json();N(y),Se({type:"ok",text:t("ollama.configured",{model:A})}),Xe(null)}else{const y=await i.json();Se({type:"err",text:y.error||t("ollama.applyFailed")})}}catch{Se({type:"err",text:t("ollama.applyFailed")})}finally{Ke(!1)}}},or=async i=>{ze(i),ge(null);try{const y=await fetch("/api/settings/oauth/login",{method:"POST",headers:ae(),body:JSON.stringify({provider:i})}),D=await y.json();if(!y.ok||D.error){ge({type:"err",text:D.error??t("oauth.loginFailed")});return}D.authorizeUrl&&(window.open(D.authorizeUrl,"_blank","noopener"),et(i),ge({type:"ok",text:t("browserOpened")}),xe.current&&clearInterval(xe.current),xe.current=setInterval(async()=>{try{const re=await(await fetch(`/api/settings/oauth/status?provider=${i}`,{headers:ae()})).json();!re.pending&&re.profiles.some(Y=>Y.provider===i&&Y.hasOAuth)&&(xe.current&&clearInterval(xe.current),xe.current=null,et(null),Et(re.profiles),ge({type:"ok",text:t("oauthConnected",{provider:i})}),Oe())}catch{}},2e3))}catch{ge({type:"err",text:t("oauth.networkErrorDuringLogin")})}finally{ze(null)}},Un=async i=>{ze(i),ge(null),Lt(null);try{const y=await fetch("/api/settings/oauth/device-code",{method:"POST",headers:ae(),body:JSON.stringify({provider:i})}),D=await y.json();if(!y.ok||D.error){ge({type:"err",text:D.error??t("oauthAuth.deviceCodeFailed")});return}D.userCode&&D.verificationUri&&(Lt({userCode:D.userCode,verificationUri:D.verificationUri,provider:i}),et(i),ge({type:"ok",text:t("oauthAuth.deviceInstructions")}),xe.current&&clearInterval(xe.current),xe.current=setInterval(async()=>{try{const re=await(await fetch(`/api/settings/oauth/status?provider=${i}`,{headers:ae()})).json();!re.pending&&re.profiles.some(Y=>Y.provider===i&&Y.hasOAuth)&&(xe.current&&clearInterval(xe.current),xe.current=null,et(null),Lt(null),Et(re.profiles),ge({type:"ok",text:t("oauthConnected",{provider:i})}),Oe())}catch{}},3e3))}catch{ge({type:"err",text:t("oauth.networkErrorDuringLogin")})}finally{ze(null)}},Fn=async()=>{if(xt.trim()){ze("manual"),ge(null);try{const i=await fetch("/api/settings/oauth/callback",{method:"POST",headers:ae(),body:JSON.stringify({callbackUrl:xt})}),y=await i.json();if(!i.ok||y.error){ge({type:"err",text:y.error??t("oauth.callbackFailed")});return}ge({type:"ok",text:t("oauthConnected",{provider:y.profile?.provider??t("common:unknown")})}),Hs(""),et(null),xe.current&&(clearInterval(xe.current),xe.current=null),yt(),Oe()}catch{ge({type:"err",text:t("common:networkError")})}finally{ze(null)}}},$n=async i=>{try{(await fetch(`/api/settings/oauth/profiles/${encodeURIComponent(i)}`,{method:"DELETE",headers:ae()})).ok&&(yt(),Oe(),ge({type:"ok",text:t("authProfileDeleted")}))}catch{}};l.useEffect(()=>()=>{xe.current&&clearInterval(xe.current)},[]),l.useEffect(()=>{if(x!=="browser"||be)return;const i=setInterval(async()=>{try{(await $.settings.getBrowser()).extensionConnected&&(Xs(!0),clearInterval(i))}catch{}},5e3);return()=>clearInterval(i)},[x,be]);const[Vn,zt]=l.useState(!1),[te,Be]=l.useState({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),[vt,ir]=l.useState(!1),[Wt,lr]=l.useState(null),[Gt,Ue]=l.useState([]),[Hn,dr]=l.useState(!1),[qn,Yt]=l.useState(null),[ce,Jt]=l.useState({apiKey:"",baseUrl:"",model:"",contextWindow:0,maxOutputTokens:0,costInput:0,costOutput:0}),[cr,ur]=l.useState(!1),[xr,mr]=l.useState(null),[Qt,Xt]=l.useState(null),[Te,Ge]=l.useState(""),[gr,fr]=l.useState(!1),[Zt,ve]=l.useState(null),[pr,jt]=l.useState(null),[we,Nt]=l.useState({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1}),[zn,hr]=l.useState(!1),br=async(i,y)=>{if(!i||i==="__custom__")return;dr(!0),ve(null);const D=Ct.find(re=>re.id===i),J=te.baseUrl||D?.baseUrl;try{if(y){const re=await $.modelCatalog.validateKey(i,y,J||void 0);!re.valid&&re.error&&ve({type:"err",text:re.error}),Ue(re.models)}else{const re=await $.modelCatalog.getByProvider(i);Ue(re.models)}}catch{Ue([])}finally{dr(!1)}},yr=async()=>{if(!(!te.name||!te.model)){ir(!0),lr(null),ve(null);try{const i=await fetch("/api/settings/llm/providers",{method:"POST",headers:ae(),body:JSON.stringify({name:te.name,apiKey:te.apiKey||void 0,baseUrl:te.baseUrl||void 0,model:te.model,contextWindow:te.contextWindow||void 0,maxOutputTokens:te.maxOutputTokens||void 0,cost:te.costInput||te.costOutput?{input:te.costInput,output:te.costOutput}:void 0})}),y=await i.json();i.ok?(N(y),zt(!1),Ge(""),Ue([]),Be({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),ve({type:"ok",text:t("modelProviders.providerAdded",{name:te.name})})):ve({type:"err",text:y.error??t("modelProviders.failedToAdd")})}catch{ve({type:"err",text:t("common:networkError")})}finally{ir(!1)}}},Wn=async(i,y)=>{if(!Te.trim())return;fr(!0),ve(null);const D=Ct.find(Y=>Y.id===i),J=D?.defaultModel??i,re=D?.baseUrl;try{const Y=await fetch("/api/settings/llm/providers",{method:"POST",headers:ae(),body:JSON.stringify({name:i,apiKey:Te.trim(),model:J,baseUrl:re})}),fe=await Y.json();Y.ok?(N(fe),Ge(""),Ue([]),ve({type:"ok",text:t("modelProviders.quickSetupSuccess",{name:D?.label??i})})):ve({type:"err",text:fe.error??t("modelProviders.failedToAdd")})}catch{ve({type:"err",text:t("common:networkError")})}finally{fr(!1)}},Gn=(i,y)=>{Yt(i),Jt({apiKey:"",baseUrl:y.baseUrl??"",model:y.model,contextWindow:y.contextWindow??0,maxOutputTokens:y.maxOutputTokens??0,costInput:y.cost?.input??0,costOutput:y.cost?.output??0})},Yn=async i=>{ur(!0);try{const y={};ce.apiKey&&(y.apiKey=ce.apiKey),ce.baseUrl!==void 0&&(y.baseUrl=ce.baseUrl),ce.model&&(y.model=ce.model),ce.contextWindow&&(y.contextWindow=ce.contextWindow),ce.maxOutputTokens&&(y.maxOutputTokens=ce.maxOutputTokens),(ce.costInput||ce.costOutput)&&(y.cost={input:ce.costInput,output:ce.costOutput});const D=await fetch(`/api/settings/llm/providers/${i}`,{method:"PUT",headers:ae(),body:JSON.stringify(y)});if(D.ok){const J=await D.json();N(J),Yt(null)}}catch{}finally{ur(!1)}},Jn=async i=>{mr(i);try{const y=await fetch(`/api/settings/llm/providers/${i}`,{method:"DELETE",headers:ae()});if(y.ok){const D=await y.json();N(D),B(D.defaultProvider)}}catch{}finally{mr(null)}},Qn=async i=>{if(!(!we.id||!we.name)){hr(!0);try{const y=await fetch(`/api/settings/llm/providers/${i}/models`,{method:"POST",headers:ae(),body:JSON.stringify({id:we.id,name:we.name,contextWindow:we.contextWindow,maxOutputTokens:we.maxOutputTokens,cost:{input:we.costInput,output:we.costOutput},reasoning:we.reasoning||void 0,inputTypes:we.vision?["text","image"]:["text"]})});if(y.ok){const D=await y.json();N(D),jt(null),Nt({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})}}catch{}finally{hr(!1)}}},Xn=async(i,y)=>{try{const D=await fetch(`/api/settings/llm/providers/${i}/models/${encodeURIComponent(y)}`,{method:"DELETE",headers:ae()});if(D.ok){const J=await D.json();N(J)}}catch{}},[vr,jr]=l.useState(null),[se,wt]=l.useState({}),Zn=async i=>{jr(i),wt(y=>{const D={...y};return delete D[i],D});try{const y=await fetch(`/api/settings/llm/providers/${i}/test`,{method:"POST",headers:ae()});if(!y.ok){const J=await y.json().catch(()=>({}));wt(re=>({...re,[i]:{ok:!1,error:J.error??`HTTP ${y.status}`,errorCode:y.status}}));return}const D=await y.json();wt(J=>({...J,[i]:D}))}catch{wt(y=>({...y,[i]:{ok:!1,error:t("common:networkError")}}))}finally{jr(null)}},Nr=p?.providers?Object.entries(p.providers).filter(([,i])=>i.configured&&i.enabled).map(([i])=>i):[],wr=o?.role==="owner"||o?.role==="admin",es=Mn.filter(i=>!i.adminOnly||wr);return e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsxs("aside",{className:"hidden md:flex flex-col w-56 shrink-0 border-r border-border-default bg-surface-secondary overflow-y-auto",children:[e.jsx("div",{"data-electron-drag":!0,className:"electron-mac-top-safe px-3 pt-4 pb-2",children:e.jsxs("button",{"data-no-drag":!0,onClick:()=>{ss.navigate(rs.HOME)},className:"flex items-center gap-2 px-2 py-1.5 rounded-lg text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-overlay transition-colors",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 12H5"}),e.jsx("polyline",{points:"12 19 5 12 12 5"})]}),t("common:back",{defaultValue:"Back"})]})}),e.jsx("div",{className:"px-5 pb-4",children:e.jsx("h2",{className:"text-base font-semibold text-fg-primary",children:t("title")})}),e.jsx("nav",{className:"flex-1 px-3 pb-4 space-y-3",children:cn.map(i=>{const y=i.tabs.map(D=>es.find(J=>J.id===D)).filter(D=>!!D);return y.length===0?null:e.jsxs("div",{children:[e.jsx("div",{className:"px-3 pb-1 pt-1 text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary",children:t(`settings:${i.labelKey}`)}),e.jsx("div",{className:"space-y-0.5",children:y.map(D=>e.jsxs("button",{onClick:()=>v(D.id),className:`w-full flex items-center gap-2.5 text-left px-3 py-2 rounded-lg text-sm font-medium transition-colors text-fg-primary ${x===D.id?"bg-surface-overlay":"hover:bg-surface-overlay/60"}`,children:[e.jsx(xn,{id:D.id,className:x===D.id?"text-fg-secondary":"text-fg-tertiary"}),e.jsx("span",{className:"truncate",children:t(`settings:${D.labelKey}`)})]},D.id))})]},i.labelKey)})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[c&&x===null&&e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary",children:[e.jsx("button",{onClick:()=>ss.navigate(rs.HOME),className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 12H5"}),e.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),e.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:t("title")})]}),e.jsx("nav",{className:"flex-1 overflow-y-auto py-2 px-3",children:cn.map((i,y)=>{const D=i.tabs.map(J=>es.find(re=>re.id===J)).filter(J=>!!J);return D.length===0?null:e.jsxs("div",{children:[y>0&&e.jsx("div",{className:"border-t border-border-default my-2 mx-2"}),e.jsx("div",{className:"px-4 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary",children:t(`settings:${i.labelKey}`)}),D.map(J=>e.jsxs("button",{onClick:()=>v(J.id),className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg text-sm text-fg-primary hover:bg-surface-overlay transition-colors",children:[e.jsx(xn,{id:J.id,className:"text-fg-tertiary"}),e.jsx("span",{className:"flex-1 text-left",children:t(`settings:${J.labelKey}`)}),e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:e.jsx("polyline",{points:"9 18 15 12 9 6"})})]},J.id))]},i.labelKey)})})]}),c&&x!==null&&e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary sticky top-0 z-10",children:[e.jsx("button",{onClick:M,className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 12H5"}),e.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),e.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:t(`settings:${es.find(i=>i.id===x)?.labelKey||"title"}`)})]}),x!==null&&e.jsxs("div",{className:"p-7 space-y-10 max-w-4xl mx-auto w-full",children:[x==="appearance"&&e.jsxs(e.Fragment,{children:[e.jsx(Ce,{title:t("systemStatus.title"),children:C?e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(Ls,{label:t("systemStatus.status"),value:C.status==="ok"?t("systemStatus.healthy"):C.status,color:"green"}),e.jsx(Ls,{label:t("systemStatus.version"),value:C.version,color:"indigo"}),e.jsx(Ls,{label:t("systemStatus.activeAgents"),value:String(C.agents),color:"purple"})]}):e.jsx("div",{className:"text-sm text-fg-tertiary",children:t("common:loading")})}),e.jsx(Ce,{title:t("appearance.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("appearance.theme")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("appearance.themeDesc")})]}),e.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:ra.map(({value:i})=>e.jsx("button",{onClick:()=>r?.(i),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${s===i?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:t(`appearance.modes.${i}`)},i))})]}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between mt-5 pt-5 border-t border-border-default/50",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("appearance.language")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("appearance.languageDesc")})]}),e.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:Cr.map(({code:i,label:y})=>e.jsx("button",{onClick:()=>{d.changeLanguage(i),$.settings.updateSearch({language:i}).catch(()=>{})},className:`px-3 py-1.5 text-xs rounded-md transition-colors ${d.language===i||i==="en"&&!Cr.some(D=>D.code===d.language)?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:y},i))})]}),kr()&&e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between mt-5 pt-5 border-t border-border-default/50",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("appearance.launchAtLogin")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("appearance.launchAtLoginDesc")})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":b,disabled:P,onClick:()=>{j()},className:`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors disabled:opacity-50 ${b?"bg-brand-600":"bg-surface-elevated border border-border-default"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow transition-transform ${b?"translate-x-6":"translate-x-1"}`})})]})]})})]}),wr&&e.jsxs(e.Fragment,{children:[x==="providers"&&e.jsxs(e.Fragment,{children:[p&&(()=>{const i=[],y=new Set,D=[],J=[];for(const[k,W]of Object.entries(p.providers))W.configured?D.push([k,W]):k!=="markus"&&J.push([k,W]),y.add(k);for(const k of Ct)!y.has(k.id)&&k.id!=="markus"&&(J.push([k.id,{name:k.id,displayName:k.label,model:k.defaultModel,configured:!1,enabled:!1}]),y.add(k.id));D.sort((k,W)=>(W[1].enabled?1:0)-(k[1].enabled?1:0)),i.push(...D,...J);const re=D.length>0,fe=p.providers.markus?.configured??!1;return e.jsxs(e.Fragment,{children:[!fe&&e.jsx(Ce,{title:"Markus Cloud AI",children:e.jsxs("div",{className:"bg-surface-secondary border border-brand-500/30 rounded-xl overflow-hidden transition-colors hover:border-brand-500/50",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer",onClick:()=>{h(L==="markus"?null:"markus"),Ge(""),ve(null)},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-brand-500 shadow-[0_0_6px_rgba(99,102,241,0.4)]"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Markus Cloud AI"}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("modelProviders.markusHint")})]})]}),e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${L==="markus"?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),L==="markus"&&e.jsxs("div",{className:"px-5 pb-5 space-y-3 border-t border-border-default/50",children:[e.jsx("p",{className:"text-xs text-fg-tertiary pt-3",children:t("modelProviders.markusSetupLogin")}),e.jsx("button",{onClick:()=>ss.navigate(rs.SETTINGS,{tab:"account"}),className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-lg transition-colors",children:t("modelProviders.goToAccount")})]})]})}),e.jsxs(fo,{title:t("modelProviders.title"),defaultCollapsed:re,configuredProviders:D,t,onBadgeClick:k=>{h(k),Ge(""),ve(null),setTimeout(()=>{document.querySelector(`[data-provider-id="${k}"]`)?.scrollIntoView({behavior:"smooth",block:"center"})},80)},children:[e.jsxs("div",{className:"space-y-3",children:[re&&e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider px-1",children:t("modelProviders.groupConfigured",{count:D.length})}),i.map(([k,W],kt)=>{const ts=!W.configured&&(kt===0||i[kt-1][1].configured);return e.jsxs("div",{"data-provider-id":k,children:[ts&&re&&e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider px-1 mt-4 mb-2",children:t("modelProviders.groupUnconfigured")}),e.jsxs("div",{className:`bg-surface-secondary border rounded-xl overflow-hidden transition-colors ${W.configured?"border-border-default hover:border-gray-600":"border-border-default/50 hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer",onClick:()=>{h(L===k?null:k),Ge(""),ve(null),Ue([]),Be(oe=>({...oe,name:"",model:""}))},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${W.configured&&W.enabled?"bg-green-400":W.configured?"bg-amber-400":"bg-gray-600"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:W.displayName??k}),k===p.defaultProvider&&e.jsx("span",{className:"text-[10px] bg-brand-500/15 text-brand-500 px-1.5 py-0.5 rounded",children:t("modelProviders.badgeDefault")}),W.configured&&!W.enabled&&e.jsx("span",{className:"text-[10px] bg-amber-500/15 text-amber-600 px-1.5 py-0.5 rounded",children:t("modelProviders.disabled")}),W.oauthConnected&&e.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:t("modelProviders.badgeOAuth")}),se[k]?.ok===!0&&e.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:t("modelProviders.testOk",{ms:se[k].durationMs})}),se[k]?.ok===!1&&e.jsx("span",{className:"text-[10px] bg-red-500/15 text-red-500 px-1.5 py-0.5 rounded",title:se[k].error,children:se[k].errorCode?t("modelProviders.testFailedCode",{code:se[k].errorCode}):t("modelProviders.testFailed")})]}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:W.configured?e.jsxs(e.Fragment,{children:[W.models&&W.models.length>0?t("modelProviders.modelsAvailable",{count:W.models.length}):"",k!=="markus"&&W.apiKeyPreview&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:"text-fg-secondary",children:W.apiKeyPreview})]})]}):t("modelProviders.notConfigured")})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[W.configured&&e.jsx("button",{onClick:oe=>{oe.stopPropagation(),_n(k,!W.enabled)},disabled:S===k,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${W.enabled?"bg-green-500":"bg-gray-600"} ${S===k?"opacity-50":""}`,title:W.enabled?t("modelProviders.clickToDisable"):t("modelProviders.clickToEnable"),children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${W.enabled?"translate-x-4":"translate-x-1"}`})}),e.jsx("span",{className:"text-fg-tertiary text-xs",children:L===k?"▲":"▼"})]})]}),L===k&&e.jsxs("div",{className:"px-5 pb-4 border-t border-border-default pt-4 space-y-4",children:[W.configured&&e.jsxs(e.Fragment,{children:[qn===k?e.jsxs("div",{className:"bg-surface-elevated/40 rounded-lg p-4 space-y-3",children:[e.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("modelProviders.editProvider")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.apiKey")}),e.jsx("input",{type:"password",value:ce.apiKey,onChange:oe=>Jt({...ce,apiKey:oe.target.value}),placeholder:t("modelProviders.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.baseUrl")}),e.jsx("input",{type:"text",value:ce.baseUrl,onChange:oe=>Jt({...ce,baseUrl:oe.target.value}),placeholder:t("modelProviders.baseUrlDisplayDefault"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{Yn(k)},disabled:cr,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(cr?"common:saving":"common:save")}),e.jsx("button",{onClick:()=>Yt(null),className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:t("common:cancel")})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:oe=>{oe.stopPropagation(),Zn(k)},disabled:vr===k,className:"px-3 py-1.5 text-xs border border-green-500/30 text-green-500 hover:bg-green-500/10 rounded-lg transition-colors disabled:opacity-40 flex items-center gap-1.5",children:vr===k?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}),t("modelProviders.testing")]}):t("modelProviders.test")}),k!=="markus"&&e.jsx("button",{onClick:oe=>{oe.stopPropagation(),Gn(k,W)},className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:t("common:edit")}),k!=="markus"&&e.jsx("button",{onClick:oe=>{oe.stopPropagation(),Xt({name:k,label:W.displayName??k})},disabled:xr===k,className:"px-3 py-1.5 text-xs border border-red-500/30 text-red-400 hover:bg-red-500/10 rounded-lg transition-colors disabled:opacity-40",children:t(xr===k?"common:deleting":"common:delete")})]}),se[k]&&e.jsxs("details",{className:`text-xs rounded-lg border ${se[k].ok?"bg-green-500/10 border-green-500/30":"bg-red-500/10 border-red-500/30"}`,children:[e.jsx("summary",{className:`px-3 py-2 cursor-pointer select-none ${se[k].ok?"text-green-600":"text-red-500"}`,children:se[k].ok?t("modelProviders.testSuccess",{ms:se[k].durationMs,reply:se[k].reply}):se[k].error}),e.jsxs("div",{className:"px-3 pb-2 pt-1 space-y-1 text-[11px] text-fg-muted border-t border-current/10",children:[k!=="markus"&&se[k].requestUrl&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.requestUrl"),":"]})," ",e.jsx("code",{className:"font-mono text-fg-primary",children:se[k].requestUrl})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.model"),":"]})," ",e.jsx("code",{className:"font-mono text-fg-primary",children:se[k].model??W.model})]}),!!se[k].requestBody&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.requestBody"),":"]}),e.jsx("pre",{className:"mt-0.5 p-1.5 rounded bg-surface-primary/50 font-mono overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(se[k].requestBody,null,2)})]}),se[k].ok&&se[k].reply&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.response"),":"]})," ",se[k].reply]}),se[k].usage&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.tokens"),":"]})," ",t("modelProviders.testDetail.inputTokens")," ",se[k].usage.inputTokens??se[k].usage.prompt_tokens??"-"," / ",t("modelProviders.testDetail.outputTokens")," ",se[k].usage.outputTokens??se[k].usage.completion_tokens??"-"]}),se[k].durationMs!=null&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.duration"),":"]})," ",se[k].durationMs,"ms"]})]})]})]}),k==="markus"&&W.configured&&e.jsxs("div",{className:"bg-green-500/5 border border-green-500/20 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400 shadow-[0_0_4px_rgba(74,222,128,0.4)]"}),e.jsx("span",{className:"text-sm font-medium text-green-400",children:t("modelProviders.markusConnected")})]}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-2",children:t("modelProviders.markusConnectedHint")})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("modelProviders.availableModels")}),W.configured&&k!=="markus"&&pr!==k&&e.jsx("button",{onClick:()=>{jt(k),Nt({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})},className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:t("modelProviders.addModel")})]}),pr===k&&e.jsx("div",{className:"bg-surface-elevated/40 rounded-lg p-3 mb-2 space-y-2",children:e.jsx(go,{providerName:k,addModelForm:we,setAddModelForm:Nt,addModelSaving:zn,onAdd:()=>{Qn(k)},onCancel:()=>jt(null),t})}),k==="markus"&&W.configured&&(!W.models||W.models.length===0)&&(ne===k?e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-xs text-fg-tertiary",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t("modelProviders.loadingHubCatalog")]}):e.jsx("div",{className:"mt-1 text-xs text-amber-400/90",children:q?t("modelProviders.hubCatalogError",{error:q}):t("modelProviders.hubCatalogEmpty")})),W.models&&W.models.length>0&&e.jsx(xo,{models:W.models,providerName:k,activeModelId:W.model,t,onDeleteCustom:oe=>{Xn(k,oe)}}),W.configured&&ne===k&&e.jsxs("div",{className:"flex items-center gap-2 mt-2 text-xs text-fg-tertiary",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t("modelProviders.loadingCatalog")]}),W.configured&&z[k]&&z[k].length>0&&(()=>{const oe=new Set(W.models?.map(je=>je.id)??[]),_e=z[k].filter(je=>!oe.has(String(je.id??"")));return _e.length===0?null:e.jsx(mo,{models:_e,providerName:k,t,onAdd:je=>{const ke=_e.find(ea=>String(ea.id??"")===je);ke&&(jt(k),Nt({id:String(ke.id??""),name:String(ke.id??""),contextWindow:ke.maxInputTokens??128e3,maxOutputTokens:ke.maxOutputTokens??16384,costInput:ke.inputCostPer1MTokens??1,costOutput:ke.outputCostPer1MTokens??5,reasoning:ke.capabilities?.reasoning??!1,vision:ke.capabilities?.vision??!1}))}})})()]}),!W.configured&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-fg-secondary",children:t("modelProviders.quickSetupHint")}),k==="markus"&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 rounded-lg bg-brand-600/8 border border-brand-500/15 text-xs text-fg-secondary",children:[e.jsx("svg",{className:"w-4 h-4 shrink-0 text-brand-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("span",{children:[t("modelProviders.markusKeyHint")," ",e.jsx("a",{href:`${Fe.getUrl()}/settings`,target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-400 underline underline-offset-2",children:t("modelProviders.markusKeyLink")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.apiKey")}),e.jsx("input",{type:"password",value:L===k?Te:"",onChange:oe=>Ge(oe.target.value),placeholder:t("modelProviders.quickSetupPlaceholder"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none",onBlur:()=>{Te.trim().length>=8&&L===k&&br(k,Te.trim())},onKeyDown:oe=>{oe.key==="Enter"&&Te.trim().length>=8&&br(k,Te.trim())}}),Hn&&L===k&&e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-xs text-fg-tertiary",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t("modelProviders.validatingKey")]})]}),L===k&&Gt.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-2",children:t("modelProviders.selectModel")}),e.jsx(vn,{provider:k,models:Gt,selectedModel:te.model,showTiers:!0,onSelect:oe=>{const _e=Gt.find(je=>je.id===oe);Be(je=>({...je,name:k,model:oe,apiKey:Te.trim(),baseUrl:Ct.find(ke=>ke.id===k)?.baseUrl??"",contextWindow:_e?.maxInputTokens??je.contextWindow,maxOutputTokens:_e?.maxOutputTokens??je.maxOutputTokens,costInput:_e?.inputCostPer1MTokens??je.costInput,costOutput:_e?.outputCostPer1MTokens??je.costOutput}))},compact:!0,maxVisible:8})]}),L===k&&Te.trim()&&e.jsx("button",{onClick:()=>{te.model&&te.name===k?yr():Wn(k)},disabled:gr||vt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(gr||vt?"modelProviders.quickSetupSaving":"modelProviders.quickSetupSubmit")}),Zt&&L===k&&e.jsx(Ae,{type:Zt.type,text:Zt.text})]})]})]})]},k)})]}),Vn?e.jsxs("div",{className:"mt-3 bg-surface-secondary border border-brand-500/30 rounded-xl p-4 space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-fg-primary",children:t("modelProviders.customProvider")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.providerName")}),e.jsx("input",{type:"text",value:te.name==="__custom__"?"":te.name,onChange:k=>Be(W=>({...W,name:k.target.value||"__custom__"})),placeholder:"my-provider",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.baseUrl")}),e.jsx("input",{type:"text",value:te.baseUrl,onChange:k=>Be({...te,baseUrl:k.target.value}),placeholder:"https://api.example.com/v1",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.apiKey")}),e.jsx("input",{type:"password",value:te.apiKey,onChange:k=>Be({...te,apiKey:k.target.value}),placeholder:t("modelProviders.placeholderApiKeySk"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.defaultModel")}),e.jsx("input",{type:"text",value:te.model,onChange:k=>Be({...te,model:k.target.value}),placeholder:"gpt-4o",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{yr()},disabled:vt||!te.name||te.name==="__custom__"||!te.model,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(vt?"modelProviders.adding":"modelProviders.addProviderSubmit")}),e.jsx("button",{onClick:()=>{zt(!1),lr(null),Ue([]),Be({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5})},className:"px-4 py-2 text-sm border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:t("common:cancel")})]}),Wt&&e.jsx(Ae,{type:Wt.type,text:Wt.text})]}):e.jsxs("button",{onClick:()=>zt(!0),className:"w-full mt-3 px-4 py-2.5 border border-dashed border-border-default hover:border-brand-500/50 hover:bg-brand-500/5 rounded-xl text-xs text-fg-tertiary hover:text-brand-500 transition-colors",children:["+ ",t("modelProviders.customProvider")]})]})]})})(),e.jsx(Is,{title:t("autoDetect.title"),defaultOpen:!1,children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[e.jsx("div",{className:"text-sm text-fg-secondary",children:t("autoDetect.description")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:t("envConfig.title")}),e.jsxs("button",{onClick:()=>{Ht()},disabled:H,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${H?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),t(H?"common:detecting":"envConfig.refreshEnv")]})]}),m&&m.detected.length>0&&e.jsxs("div",{className:"space-y-2",children:[m.detected.map(i=>e.jsxs("label",{className:"flex items-center justify-between bg-surface-elevated/30 rounded-lg px-4 py-3 cursor-pointer hover:bg-surface-elevated/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:Q[i.provider]??!1,onChange:y=>le({...Q,[i.provider]:y.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary font-medium",children:i.displayName}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[t("envConfig.keyLabel")," ",e.jsx("code",{className:"text-fg-secondary",children:i.apiKeyPreview})," / ",t("envConfig.modelLabel")," ",e.jsx("code",{className:"text-fg-secondary",children:i.model}),i.baseUrl&&e.jsxs(e.Fragment,{children:[" / ",t("envConfig.urlLabel")," ",e.jsx("code",{className:"text-fg-secondary",children:i.baseUrl})]})]})]})]}),e.jsx("div",{className:"text-xs text-fg-tertiary",children:Object.keys(i.envVars).map(y=>e.jsx("div",{children:e.jsx("code",{children:y})},y))})]},i.provider)),m.timeoutMs&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("envConfig.llmTimeout",{ms:m.timeoutMs})}),e.jsx("button",{onClick:()=>{Dn()},disabled:Ee||Object.values(Q).filter(Boolean).length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:Ee?t("common:applying"):t("envConfig.applyToConfig",{count:Object.values(Q).filter(Boolean).length})})]}),ee&&e.jsx(Ae,{type:ee.type,text:ee.text})]}),e.jsx("div",{className:"border-t border-border-default"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:t("ollama.title")}),e.jsxs("button",{onClick:()=>{qt()},disabled:He,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${He?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),t(He?"common:detecting":"ollama.detect")]})]}),pe?.found&&pe.models&&pe.models.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-green-600",children:t("ollama.foundModels",{count:pe.models.length,url:pe.baseUrl})}),e.jsx("div",{className:"space-y-1",children:pe.models.map(i=>e.jsx("label",{className:`flex items-center justify-between rounded-lg px-4 py-3 cursor-pointer transition-colors ${A===i.name?"bg-brand-500/15 border border-brand-500/40":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"radio",name:"ollama-model",value:i.name,checked:A===i.name,onChange:()=>ie(i.name),className:"w-4 h-4 text-brand-500 focus:ring-brand-500"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary font-medium",children:i.name}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[i.parameterSize&&e.jsx("span",{children:i.parameterSize}),i.family&&e.jsx("span",{className:"ml-2",children:i.family}),i.quantization&&e.jsx("span",{className:"ml-2",children:i.quantization}),i.size&&e.jsx("span",{className:"ml-2",children:Je(i.size)})]})]})]})},i.name))}),e.jsx("button",{onClick:()=>{Kn()},disabled:ue||!A,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:ue?t("common:applying"):t("ollama.useModel",{model:A})})]}),pe&&!pe.found&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:pe.error||t("ollama.notRunning")}),qe&&e.jsx(Ae,{type:qe.type,text:qe.text})]})]})}),e.jsx(Is,{title:t("oauthAuth.title"),defaultOpen:!1,children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.description")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[$s.map(i=>e.jsxs("div",{className:"flex",children:[e.jsx("button",{onClick:()=>or(i.name),disabled:!!Ze,className:"px-3 py-2 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-l-lg transition-colors",children:Ze===i.name?t("oauthAuth.connecting"):t("oauthAuth.signInWith",{name:i.displayName})}),e.jsx("button",{onClick:()=>Un(i.name),disabled:!!Ze,title:t("oauthAuth.deviceTitle"),className:"px-2.5 py-2 text-xs bg-surface-secondary text-fg-secondary border border-border-default border-l-0 rounded-r-lg hover:bg-surface-tertiary disabled:opacity-40 transition-colors",children:t("oauthAuth.device")})]},i.name)),$s.length===0&&e.jsx("span",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.noProviders")})]}),tt&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-secondary border border-border-default space-y-2",children:[e.jsx("p",{className:"text-xs text-fg-primary font-medium",children:t("oauthAuth.deviceCodeTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.deviceInstructions")}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("a",{href:tt.verificationUri,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-brand-500 underline hover:text-brand-400",children:tt.verificationUri}),e.jsx("code",{className:"px-2.5 py-1 text-sm font-mono font-bold bg-surface-elevated border border-border-default rounded-lg text-fg-primary select-all",children:tt.userCode})]}),e.jsx("p",{className:"text-[10px] text-fg-muted",children:t("oauthAuth.deviceWaiting")})]}),In&&!tt&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-secondary border border-border-default space-y-2",children:[e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.manualCallbackHint")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:xt,onChange:i=>Hs(i.target.value),placeholder:t("oauthAuth.manualPlaceholder"),className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-muted/50 focus:border-brand-500 outline-none"}),e.jsx("button",{onClick:Fn,disabled:!xt.trim()||Ze==="manual",className:"px-3 py-2 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t("oauthAuth.submit")})]})]}),It&&e.jsx(Ae,{type:It.type,text:It.text}),Vs.filter(i=>i.hasOAuth).length>0&&e.jsxs("div",{className:"space-y-2 border-t border-border-default pt-4",children:[e.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:t("oauthAuth.connectedAccounts")}),Vs.filter(i=>i.hasOAuth).map(i=>e.jsxs("div",{className:`flex items-center justify-between px-4 py-3 rounded-lg border ${i.oauthExpired?"bg-amber-500/5 border-amber-500/20":"bg-surface-secondary border-border-default"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${i.oauthExpired?"bg-amber-400":"bg-green-400"}`}),e.jsx("span",{className:"text-xs text-fg-primary font-medium",children:i.label??i.provider}),i.accountId&&e.jsxs("span",{className:"text-[10px] text-fg-muted",children:["(",i.accountId.slice(0,12),"...)"]}),i.oauthExpired&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md bg-amber-500/15 text-amber-600 font-medium",children:t("oauthAuth.expired")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[i.oauthExpired&&e.jsx("button",{onClick:()=>or(i.provider),disabled:!!Ze,className:"text-[10px] px-2 py-1 rounded-md text-brand-500 hover:text-brand-400 hover:bg-brand-500/10 transition-colors",children:t("oauthAuth.reconnect")}),e.jsx("button",{onClick:()=>$n(i.id),className:"text-[10px] px-2 py-1 rounded-md text-red-400 hover:text-red-300 hover:bg-red-500/10 transition-colors",children:t("oauthAuth.disconnect")})]})]},i.id))]})]})}),e.jsx(Ce,{title:t("defaultProvider.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("defaultProvider.primaryProvider")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("defaultProvider.primaryProviderDesc")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[p?e.jsx("select",{value:I,onChange:i=>{B(i.target.value),R(null)},className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm w-48 focus:border-brand-500 outline-none",children:Nr.length>0?Nr.map(i=>e.jsx("option",{value:i,children:p.providers[i]?.displayName??i},i)):e.jsx("option",{value:"",children:t("defaultProvider.noProviders")})}):e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("common:loading")}),I!==p?.defaultProvider&&e.jsx("button",{onClick:()=>{Bn()},disabled:F,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(F?"common:saving":"common:save")})]})]}),O&&e.jsx(Ae,{type:O.type,text:O.text}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("defaultProvider.autoFallback")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("defaultProvider.autoFallbackDesc")})]}),e.jsx("button",{onClick:async()=>{const i=!(p?.autoFallback??!1);try{const y=await fetch("/api/settings/llm",{method:"POST",headers:ae(),body:JSON.stringify({autoFallback:i})});if(y.ok){const D=await y.json();N(D)}}catch{}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${p?.autoFallback??!1?"bg-green-500":"bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${p?.autoFallback??!1?"translate-x-4":"translate-x-1"}`})})]})]})}),e.jsx(Ce,{title:t("modelRouting.title"),children:e.jsx(ua,{configuredProviders:Object.entries(p?.providers??{}).filter(([,i])=>i.configured&&i.enabled).map(([i,y])=>({name:i,displayName:y.displayName,model:y.model,models:y.models?.map(D=>({id:D.id,name:D.name}))})),onSave:async i=>{const y=await fetch("/api/settings/llm",{method:"POST",headers:ae(),body:JSON.stringify(i)});if(!y.ok)throw new Error(`HTTP ${y.status}`)}},p?.defaultProvider??"no-default")}),e.jsx(Is,{title:t("networkProxy.title"),defaultOpen:!1,children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{children:e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("networkProxy.description")})}),e.jsx("button",{onClick:async()=>{const i=!Ie;Mt(i);try{await fetch("/api/settings/network",{method:"POST",headers:ae(),body:JSON.stringify({proxyEnabled:i})}),rt()}catch{Mt(!i)}},className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors ${Ie?"bg-green-500":"bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Ie?"translate-x-4":"translate-x-1"}`})})]}),Ne&&e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2.5 rounded-lg bg-surface-secondary border border-border-default transition-opacity ${Ie?"":"opacity-50"}`,children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${Ie&&Ne.proxy?"bg-green-400":"bg-gray-600"}`}),e.jsx("span",{className:"text-xs text-fg-secondary",children:Ie?Ne.proxy?e.jsxs(e.Fragment,{children:[t("networkProxy.active")," ",e.jsx("code",{className:"text-fg-primary font-mono",children:Ne.proxy})]}):t("networkProxy.noProxy"):t("networkProxy.disabled")}),Ie&&Ne.source!=="none"&&Ne.source!=="disabled"&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md font-medium ${Ne.source==="config"?"bg-brand-500/15 text-brand-500":Ne.source==="env"?"bg-amber-500/15 text-amber-600":Ne.source==="system"?"bg-blue-500/15 text-blue-500":"bg-gray-500/15 text-fg-muted"}`,children:Ne.source==="config"?t("networkProxy.sourceConfig"):Ne.source==="env"?t("networkProxy.sourceEnv"):Ne.source==="system"?t("networkProxy.sourceSystem"):""}),e.jsxs("button",{onClick:()=>rt(),className:"ml-auto text-[10px] px-1.5 py-0.5 rounded-md text-fg-muted hover:text-fg-secondary hover:bg-surface-tertiary transition-colors",title:t("networkProxy.refresh"),children:["↻ ",t("networkProxy.refresh")]})]}),e.jsxs("div",{className:`flex gap-2 items-center transition-opacity ${Ie?"":"opacity-50 pointer-events-none"}`,children:[e.jsx("input",{type:"text",value:Ds,onChange:i=>Ks(i.target.value),placeholder:t("networkProxy.placeholder"),className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-muted/50 focus:border-brand-500 outline-none"}),e.jsx("button",{onClick:async()=>{Fs(!0),ut(null);try{const i=await fetch("/api/settings/network",{method:"POST",headers:ae(),body:JSON.stringify({proxy:Ds.trim()})});if(i.ok)ut({type:"ok",text:t("networkProxy.saved")}),rt();else{const y=await i.json();ut({type:"err",text:y.error??t("networkProxy.saveFailed")})}}catch{ut({type:"err",text:t("networkProxy.networkError")})}finally{Fs(!1)}},disabled:Us,className:"px-3 py-2 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(Us?"networkProxy.saving":"networkProxy.save")})]}),Tt&&e.jsx(Ae,{type:Tt.type,text:Tt.text})]})})]}),x==="execution"&&e.jsxs(e.Fragment,{children:[e.jsx(Ce,{title:t("agentExecution.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("agentExecution.maxToolIterations")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("agentExecution.maxToolIterationsDesc")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:0,value:zs,onChange:i=>{Rt(Number(i.target.value)),mt(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right"}),e.jsx("button",{disabled:Ws,onClick:async()=>{Gs(!0),mt(null);try{const i=await $.settings.updateAgent({maxToolIterations:zs});Rt(i.maxToolIterations),mt({type:"ok",text:t("agentExecution.saved")})}catch{mt({type:"err",text:t("agentExecution.failedToSave")})}Gs(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:t(Ws?"common:saving":"common:save")})]})]}),Ot&&e.jsx(Ae,{type:Ot.type,text:Ot.text})]})}),e.jsx(Ce,{title:t("cognitive.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("cognitive.description")}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("cognitive.enabled")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("cognitive.enabledDesc")})]}),e.jsx("button",{onClick:()=>{Bt(!gt),st(null)},className:`relative w-10 h-5 rounded-full transition-colors ${gt?"bg-brand-500":"bg-fg-quaternary"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform ${gt?"translate-x-5":""}`})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("cognitive.maxDepth")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("cognitive.maxDepthDesc")})]}),e.jsxs("select",{value:Ys,onChange:i=>{_t(Number(i.target.value)),st(null)},className:"px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary",children:[e.jsxs("option",{value:1,children:["D1 — ",t("cognitive.depthD1")]}),e.jsxs("option",{value:2,children:["D2 — ",t("cognitive.depthD2")]}),e.jsxs("option",{value:3,children:["D3 — ",t("cognitive.depthD3")]})]})]}),e.jsx("div",{className:"flex items-center justify-end gap-2",children:e.jsx("button",{disabled:Js,onClick:async()=>{Qs(!0),st(null);try{const i=await $.settings.updateAgent({cognitive:{enabled:gt,maxDepth:Ys}});Bt(i.cognitive.enabled),_t(i.cognitive.maxDepth??1),st({type:"ok",text:t("cognitive.saved")})}catch{st({type:"err",text:t("cognitive.failedToSave")})}Qs(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:t(Js?"common:saving":"common:save")})}),Dt&&e.jsx(Ae,{type:Dt.type,text:Dt.text})]})})]}),x==="browser"&&e.jsxs(e.Fragment,{children:[e.jsxs(Ce,{title:t("browserAutomation.title"),children:[e.jsxs("div",{className:`rounded-xl p-4 mb-4 flex items-start gap-3 ${be?"bg-green-500/10 border border-green-500/20":Le>0?"bg-blue-500/10 border border-blue-500/20":Re?"bg-amber-500/10 border border-amber-500/20":"bg-surface-elevated border border-border-default"}`,children:[e.jsx("div",{className:`mt-0.5 w-2.5 h-2.5 rounded-full shrink-0 ${be?"bg-green-400":Le>0?"bg-blue-400":Re?"bg-amber-400":"bg-gray-400"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:`text-sm font-semibold ${be?"text-green-400":Le>0?"text-blue-400":Re?"text-amber-400":"text-fg-secondary"}`,children:be?t("browserAutomation.modeExtension"):Le>0?t("browserAutomation.modeDebuggingPort",{port:Le}):t(Re?"browserAutomation.modeAutoClick":"browserAutomation.modeManual")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:be?t("browserAutomation.modeExtensionDesc"):Le>0?t("browserAutomation.modeDebuggingPortDesc"):t(Re?"browserAutomation.modeAutoClickDesc":"browserAutomation.modeManualDesc")})]})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4 mb-4",children:[e.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:t("browserAutomation.generalSettings")}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.bringToFront")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.bringToFrontDesc")})]}),e.jsx("button",{onClick:async()=>{const i=!Kt;ft(i),he(!0),de(null);try{const y=await $.settings.updateBrowser({bringToFront:i});ft(y.bringToFront),de({type:"ok",text:t(i?"browserAutomation.tabsForeground":"browserAutomation.tabsBackground")})}catch{de({type:"err",text:t("agentExecution.failedToSave")}),ft(!i)}he(!1)},disabled:ye,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Kt?"bg-green-500":"bg-gray-600"} ${ye?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Kt?"translate-x-4":"translate-x-1"}`})})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.autoCloseTabs")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.autoCloseTabsDesc")})]}),e.jsx("button",{onClick:async()=>{const i=!Ft;pt(i),he(!0),de(null);try{const y=await $.settings.updateBrowser({autoCloseTabs:i});pt(y.autoCloseTabs),de({type:"ok",text:t("agentExecution.saved")})}catch{de({type:"err",text:t("agentExecution.failedToSave")}),pt(!i)}he(!1)},disabled:ye,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Ft?"bg-green-500":"bg-gray-600"} ${ye?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Ft?"translate-x-4":"translate-x-1"}`})})]})]}),e.jsxs("div",{className:`rounded-xl p-5 mb-4 transition-colors ${be?"bg-green-500/5 border border-green-500/20":"bg-surface-elevated"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStatus")}),e.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",t("browserAutomation.modeRecommended"),")"]})]}),e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${be?"bg-green-500/20 text-green-400":"bg-gray-600/20 text-gray-400"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${be?"bg-green-400":"bg-gray-400"}`}),t(be?"browserAutomation.extensionConnected":"browserAutomation.extensionDisconnected")]})]}),e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("browserAutomation.extensionStatusDesc")}),be?e.jsxs("div",{className:"mt-3 flex items-center gap-1.5 text-xs text-green-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),t("browserAutomation.extensionActiveNote")]}):e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:t("browserAutomation.extensionSetupTitle")}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[e.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStep1")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.extensionStep1Desc")}),e.jsxs("button",{disabled:ye,onClick:async()=>{he(!0),de(null);try{await $.settings.downloadExtensionZip()}catch{de({type:"err",text:t("browserAutomation.extensionDownloadError")})}he(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),t(ye?"browserAutomation.extensionStep1Downloading":"browserAutomation.extensionStep1Btn")]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[e.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"2"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStep2")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.extensionStep2Desc")}),navigator.platform.toUpperCase().includes("WIN")?e.jsxs("div",{className:"mt-2 text-xs text-fg-secondary",children:[t("browserAutomation.extensionStep2Desc"),":",e.jsx("code",{className:"ml-1.5 px-1.5 py-0.5 bg-surface-elevated rounded text-fg-primary font-mono text-[11px] select-all",children:"chrome://extensions"})]}):e.jsxs("button",{disabled:ye,onClick:async()=>{he(!0),de(null);try{await $.settings.openExtensionsPage()}catch{de({type:"err",text:t("browserAutomation.extensionOpenError")})}he(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),t("browserAutomation.extensionStep2Btn")]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[e.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStep3")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.extensionStep3Desc")})]})]})]})]}),!be&&e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:t("browserAutomation.fallbackModes")}),e.jsx("div",{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 mr-4",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.autoClickAllowDialog")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.autoClickAllowDialogDesc")}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-2 space-y-0.5",children:[e.jsx("div",{children:t("browserAutomation.autoClickAllowDialogMacNote")}),e.jsx("div",{children:t("browserAutomation.autoClickAllowDialogWinNote")}),e.jsx("div",{children:t("browserAutomation.autoClickAllowDialogLinuxNote")})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{disabled:ye,onClick:async()=>{he(!0),de(null);try{const i=await $.settings.testAutoClick(),y={success:{type:"ok",text:t("browserAutomation.autoClickTestSuccess",{title:i.pageTitle||"example.com"})},no_permission:{type:"err",text:t("browserAutomation.autoClickTestNoPermission")},chrome_not_running:{type:"err",text:t("browserAutomation.autoClickTestChromeNotRunning")},unsupported:{type:"err",text:t("browserAutomation.autoClickTestUnsupported")},error:{type:"err",text:t("browserAutomation.autoClickTestError",{error:i.error||"unknown"})}};de(y[i.clickResult]??{type:"err",text:i.clickResult})}catch{de({type:"err",text:t("browserAutomation.autoClickTestError",{error:"request failed"})})}he(!1)},className:"px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:t(ye?"browserAutomation.autoClickTesting":"browserAutomation.autoClickTest")}),e.jsx("button",{onClick:async()=>{const i=!Re;ht(i),he(!0),de(null);try{const y=await $.settings.updateBrowser({autoClickAllowDialog:i});ht(y.autoClickAllowDialog),de({type:"ok",text:t("agentExecution.saved")})}catch{de({type:"err",text:t("agentExecution.failedToSave")}),ht(!i)}he(!1)},disabled:ye,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Re?"bg-green-500":"bg-gray-600"} ${ye?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Re?"translate-x-4":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"border-t border-border-default pt-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.remoteDebuggingPort")}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[t("browserAutomation.remoteDebuggingPortDescLead")," ",e.jsx("code",{className:"text-fg-secondary bg-surface-primary px-1 rounded",children:"--remote-debugging-port=9222"})," ",t("browserAutomation.remoteDebuggingPortDescTail")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:0,max:65535,value:Le,onChange:i=>{Ut(Number(i.target.value)),de(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right",placeholder:"0"}),e.jsx("button",{disabled:ye,onClick:async()=>{he(!0),de(null);try{const i=await $.settings.updateBrowser({remoteDebuggingPort:Le});Ut(i.remoteDebuggingPort),de({type:"ok",text:i.remoteDebuggingPort>0?t("browserAutomation.usingPort",{port:i.remoteDebuggingPort}):t("browserAutomation.usingAutoConnect")})}catch{de({type:"err",text:t("agentExecution.failedToSave")})}he(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:t(ye?"common:saving":"common:save")})]})]})})]}),$t&&e.jsx("div",{className:"mt-4",children:e.jsx(Ae,{type:$t.type,text:$t.text})})]}),!1]}),x==="search"&&e.jsx(no,{}),x==="storage"&&e.jsx(e.Fragment,{children:e.jsx(Ce,{title:t("dataStorage.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[Vt&&!Me&&e.jsx("div",{className:"text-sm text-fg-tertiary",children:t("dataStorage.scanning")}),Me&&(()=>{const i=[...Me.breakdown].filter(Y=>Y.size>0).sort((Y,fe)=>fe.size-Y.size),y=Math.max(Me.totalSize,1),J=i.filter(Y=>Es[Y.name]==="safe").reduce((Y,fe)=>Y+fe.size,0),re=Y=>Y==="safe"?"bg-fg-secondary/55":Y==="caution"?"bg-fg-tertiary/45":"bg-fg-primary/25";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-2xl font-semibold tracking-tight text-fg-primary tabular-nums",children:Je(Me.totalSize,t)}),e.jsx("div",{className:"text-xs text-fg-tertiary font-mono mt-1 truncate",title:Me.dataDir,children:Me.dataDir})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>We(),disabled:Vt,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-primary/60 rounded-lg text-fg-secondary transition-colors disabled:opacity-40",children:t(Vt?"dataStorage.scanning":"common:refresh")}),e.jsx("button",{onClick:()=>{$.system.openPath(Me.dataDir)},className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-primary/60 rounded-lg text-fg-secondary transition-colors",children:t("dataStorage.openInFinder")})]})]}),e.jsx("div",{className:"h-2 rounded-full bg-surface-primary overflow-hidden flex","aria-hidden":!0,children:i.map(Y=>{const fe=Es[Y.name]??"caution",k=Math.max(Y.size/y*100,Y.size>0?.8:0);return e.jsx("div",{className:`h-full ${re(fe)}`,style:{width:`${k}%`},title:`${Y.name}: ${Je(Y.size,t)}`},Y.name)})}),J>0&&e.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:t("dataStorage.clearableHint",{size:Je(J,t),percent:Math.round(J/y*100)})})]}),e.jsxs("div",{className:"border-t border-border-default pt-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-3",children:[e.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:t("dataStorage.storageBreakdown")}),e.jsx("span",{className:"text-[11px] text-fg-tertiary",children:t("dataStorage.sortedBySize")})]}),e.jsx("div",{className:"divide-y divide-border-default/70 rounded-xl border border-border-default/70 overflow-hidden",children:i.map(Y=>{const fe=oo[Y.name],k=Es[Y.name]??"caution",W=fe?t(`dataStorage.items.${fe}.label`):Y.name,kt=fe?t(`dataStorage.items.${fe}.blurb`):Y.description,ts=Math.round(Y.size/y*100);return e.jsxs("div",{className:"flex items-center gap-3 px-3.5 py-3 bg-surface-primary/25 hover:bg-surface-primary/45 transition-colors",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:W}),k==="safe"&&e.jsx("span",{className:"shrink-0 text-[10px] px-1.5 py-0.5 rounded-md bg-surface-elevated text-fg-secondary border border-border-default/80",children:t("dataStorage.safetyLevel.safe")})]}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 leading-relaxed",children:kt})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary tabular-nums",children:Je(Y.size,t)}),e.jsxs("div",{className:"text-[11px] text-fg-tertiary tabular-nums mt-0.5",children:[ts,"%"]})]}),e.jsx("button",{type:"button",onClick:()=>{$.system.openPath(Y.path)},className:"shrink-0 px-2.5 py-1 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",title:Y.path,children:t("dataStorage.openFolder")})]},Y.name)})})]}),bt&&(bt.orphanAgents.length>0||bt.orphanTeams.length>0)&&e.jsx(po,{orphanInfo:bt,dataDir:Me.dataDir,onPurged:We,formatBytes:Y=>Je(Y,t)})]})})()]})})}),(x==="account"||x==="users"||x==="organization"||x==="license")&&e.jsx(vo,{authUser:o}),x==="remote"&&e.jsx(ho,{}),x==="integrations"&&e.jsx(e.Fragment,{children:e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:t("nav.integrations")}),e.jsx("div",{className:"space-y-3",children:e.jsx(Ua,{})})]})}),x==="coding-tools"&&e.jsx(so,{})]}),e.jsx("div",{className:"h-8"})]}),Qt&&e.jsx(bn,{title:t("common:delete"),message:t("modelProviders.deleteConfirm",{name:Qt.label}),confirmLabel:t("common:delete"),onConfirm:()=>{const i=Qt.name;Xt(null),Jn(i)},onCancel:()=>Xt(null)})]})]})}const gn=["owner","admin","member","guest"],lo={owner:"bg-amber-500/10 text-amber-600 border-amber-500/30",admin:"bg-brand-500/10 text-brand-500 border-brand-500/30",member:"bg-green-500/10 text-green-600 border-green-500/30",guest:"bg-gray-500/10 text-gray-500 border-gray-500/30"};function co({authUser:s}){const{t:r}=me(["settings","common"]),[o,n]=l.useState([]),[a,t]=l.useState(null),[d,c]=l.useState(""),[u,f]=l.useState(""),[v,M]=l.useState(""),[x,b]=l.useState(null),[w,P]=l.useState(""),[U,j]=l.useState(null),[C,g]=l.useState(null),[p,N]=l.useState(null),[I,B]=l.useState(!1),[F,K]=l.useState(""),[O,R]=l.useState(""),[L,h]=l.useState("member"),[S,_]=l.useState(""),z=l.useCallback(()=>{$.users.list(s?.orgId).then(m=>n(m.users)).catch(()=>{})},[s?.orgId]);l.useEffect(()=>{z()},[z]);const G=m=>{t(m.id),c(m.name),f(m.role),M(m.email??""),N(null)},ne=async()=>{if(a)try{await $.users.update(a,{name:d,role:u,email:v||void 0}),t(null),N({type:"ok",text:r("settings:userManagement.updateSuccess")}),z()}catch(m){N({type:"err",text:`${r("settings:userManagement.error")}: ${String(m)}`})}},T=async()=>{if(!(!x||!w))try{await $.users.resetPassword(x,w),b(null),P(""),N({type:"ok",text:r("settings:userManagement.resetSuccess")})}catch(m){N({type:"err",text:`${r("settings:userManagement.error")}: ${String(m)}`})}},q=async m=>{if(m===s?.id){N({type:"err",text:r("settings:userManagement.cannotDeleteSelf")}),j(null);return}if(o.find(H=>H.id===m)?.role==="owner"){N({type:"err",text:r("settings:userManagement.cannotDeleteOwner")}),j(null);return}try{await $.users.remove(m),j(null),N({type:"ok",text:r("settings:userManagement.deleteSuccess")}),z()}catch(H){N({type:"err",text:`${r("settings:userManagement.error")}: ${String(H)}`})}},V=async()=>{if(F.trim())try{const m=await $.users.create(F.trim(),L,void 0,O.trim()||void 0,S||void 0);B(!1),K(""),R(""),h("member"),_(""),N({type:"ok",text:r("settings:userManagement.addSuccess",{defaultValue:"User created"})}),m.inviteToken&&g(`${window.location.origin}/#invite?token=${m.inviteToken}`),z()}catch(m){N({type:"err",text:`${r("settings:userManagement.error")}: ${m instanceof Error?m.message:String(m)}`})}};return e.jsxs(Ce,{title:r("settings:userManagement.title"),children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("settings:userManagement.sharedInstanceDesc")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:r("settings:userManagement.orgHint")})]}),I?e.jsxs("div",{className:"mb-3 p-4 rounded-lg border border-border-default space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.name")}),e.jsx("input",{value:F,onChange:m=>K(m.target.value),autoFocus:!0,className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.email")}),e.jsx("input",{value:O,onChange:m=>R(m.target.value),type:"email",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.role")}),e.jsx("select",{value:L,onChange:m=>h(m.target.value),className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary",children:gn.map(m=>e.jsx("option",{value:m,children:r(`settings:userManagement.roles.${m}`)},m))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.password",{defaultValue:"Password"})}),e.jsx("input",{value:S,onChange:m=>_(m.target.value),type:"password",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>{B(!1),K(""),R(""),h("member"),_("")},className:"px-3 py-1.5 text-xs text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:V,disabled:!F.trim(),className:"px-4 py-1.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-xs font-medium rounded-lg",children:r("settings:userManagement.save")})]})]}):e.jsx("button",{onClick:()=>B(!0),className:"mb-3 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors",children:r("settings:userManagement.addUser",{defaultValue:"Add User"})}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[p&&e.jsx("div",{className:`px-4 py-2 text-xs border-b ${p.type==="ok"?"bg-green-500/10 text-green-600 border-green-500/20":"bg-red-500/10 text-red-500 border-red-500/20"}`,children:p.text}),C&&e.jsxs("div",{className:"px-4 py-3 bg-brand-500/5 border-b border-brand-500/20 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[11px] text-fg-tertiary mb-1",children:r("settings:userManagement.copyInviteLink")}),e.jsx("code",{className:"text-[10px] text-brand-500 bg-surface-elevated px-2 py-1 rounded block truncate",children:C})]}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(C),N({type:"ok",text:r("settings:userManagement.linkCopied")})},className:"shrink-0 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:r("settings:userManagement.copy")}),e.jsx("button",{onClick:()=>g(null),className:"shrink-0 text-fg-tertiary hover:text-fg-secondary text-sm",children:"×"})]}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border-default/60 text-fg-tertiary text-[11px] uppercase tracking-wider",children:[e.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:r("settings:userManagement.name")}),e.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:r("settings:userManagement.email")}),e.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:r("settings:userManagement.role")}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:r("settings:userManagement.actions")})]})}),e.jsxs("tbody",{children:[o.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-4 py-6 text-center text-fg-tertiary text-xs",children:r("settings:userManagement.noUsers")})}),o.map(m=>{const E=a===m.id,H=x===m.id,Z=U===m.id,ee=m.id===s?.id,X=m.role==="owner";return e.jsxs("tr",{className:"border-b border-border-default/40 last:border-b-0 hover:bg-surface-elevated/40 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5",children:E?e.jsx("input",{value:d,onChange:Q=>c(Q.target.value),className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-primary font-medium text-xs",children:m.name}),ee&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-500",children:"you"})]})}),e.jsx("td",{className:"px-4 py-2.5",children:E?e.jsx("input",{value:v,onChange:Q=>M(Q.target.value),placeholder:"email@example.com",className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):e.jsx("span",{className:"text-fg-secondary text-xs",children:m.email||"—"})}),e.jsx("td",{className:"px-4 py-2.5",children:E?e.jsx("select",{value:u,onChange:Q=>f(Q.target.value),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50",children:gn.map(Q=>e.jsx("option",{value:Q,children:r(`settings:userManagement.roles.${Q}`)},Q))}):e.jsx("span",{className:`inline-block text-[10px] px-2 py-0.5 rounded-full border font-medium ${lo[m.role]??""}`,children:r(`settings:userManagement.roles.${m.role}`)})}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:E?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>t(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:ne,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium",children:r("settings:userManagement.save")})]}):H?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("input",{type:"password",value:w,onChange:Q=>P(Q.target.value),placeholder:r("settings:userManagement.newPassword"),autoFocus:!0,className:"w-32 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),e.jsx("button",{onClick:()=>{b(null),P("")},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:T,disabled:w.length<6,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium disabled:opacity-40",children:r("settings:userManagement.confirmReset")})]}):Z?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("span",{className:"text-[10px] text-red-500",children:r("settings:userManagement.confirmDelete")}),e.jsx("button",{onClick:()=>j(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:()=>q(m.id),className:"text-[11px] text-red-500 hover:text-red-400 font-medium",children:r("settings:userManagement.deleteUser")})]}):e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[e.jsx("button",{onClick:()=>G(m),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:r("settings:userManagement.editUser")}),m.email&&e.jsx("button",{onClick:()=>{b(m.id),P(""),N(null)},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:r("settings:userManagement.resetPassword")}),m.email&&!X&&!m.hasJoined&&e.jsx("button",{onClick:async()=>{try{const{inviteToken:Q}=await $.users.reinvite(m.id),le=`${window.location.origin}/#invite?token=${Q}`;g(le),N({type:"ok",text:r("settings:userManagement.inviteLinkGenerated")})}catch(Q){N({type:"err",text:String(Q)})}},className:"text-[11px] text-brand-400 hover:text-brand-500 px-1.5 py-0.5 rounded hover:bg-brand-500/10",children:r("settings:userManagement.inviteLink")}),!X&&!ee&&e.jsx("button",{onClick:()=>{j(m.id),N(null)},className:"text-[11px] text-red-400 hover:text-red-500 px-1.5 py-0.5 rounded hover:bg-red-500/10",children:r("settings:userManagement.deleteUser")})]})})]},m.id)})]})]})]})]})}const uo={audio_speech:{label:"TTS",color:"bg-purple-500/20 text-purple-400"},image_generation:{label:"Image",color:"bg-blue-500/20 text-blue-400"},video_generation:{label:"Video",color:"bg-pink-500/20 text-pink-400"},audio_transcription:{label:"STT",color:"bg-teal-500/20 text-teal-400"},ocr:{label:"OCR",color:"bg-orange-500/20 text-orange-400"}},fn={chat:0,image_generation:1,video_generation:2,audio_speech:3,audio_transcription:4,ocr:5},pn=5;function xo({models:s,providerName:r,activeModelId:o,t:n,onDeleteCustom:a}){const t=s.length>pn,[d,c]=l.useState(!t),[u,f]=l.useState(""),v=l.useMemo(()=>{const x=u.trim().toLowerCase();return x?s.filter(b=>b.id.toLowerCase().includes(x)||b.name.toLowerCase().includes(x)):s},[s,u]),M=d?v:v.slice(0,pn);return e.jsxs("div",{className:"space-y-1",children:[t&&e.jsxs("div",{className:"flex items-center justify-between gap-2 px-1 mb-1",children:[e.jsxs("button",{type:"button",onClick:()=>c(x=>!x),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${d?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),d?n("modelProviders.collapseModels"):n("modelProviders.showAllModels",{count:s.length})]}),d&&e.jsx("input",{value:u,onChange:x=>f(x.target.value),placeholder:n("modelProviders.filterModels"),className:"flex-1 max-w-[220px] px-2 py-1 text-[10px] rounded-md bg-surface-overlay/50 border border-border-default text-fg-secondary placeholder:text-fg-tertiary"})]}),e.jsx("div",{className:d&&t?"max-h-64 overflow-y-auto space-y-1 pr-0.5":"space-y-1",children:M.map(x=>{const b=!ao.has(x.id),w=x.capabilities??[],P=o===x.id;return e.jsxs("div",{className:`flex items-center justify-between px-3 py-1.5 rounded-lg text-xs ${P?"bg-brand-500/10 border border-brand-500/20":"bg-surface-elevated/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[e.jsx("span",{className:"text-fg-secondary truncate",children:x.name}),P&&e.jsx("span",{className:"text-[9px] bg-brand-500/15 text-brand-500 px-1 py-0.5 rounded shrink-0",children:n("modelProviders.badgeDefault")}),e.jsx(wo,{modelId:x.id,tier:x.tier}),x.reasoning&&e.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:n("modelProviders.reasoning")}),(x.inputTypes?.includes("image")||w.includes("vision"))&&e.jsx("span",{className:"text-[9px] bg-blue-500/15 text-blue-600 px-1 py-0.5 rounded",children:n("modelProviders.vision")}),w.includes("imageGeneration")&&e.jsx("span",{className:"text-[9px] bg-cyan-500/15 text-cyan-600 px-1 py-0.5 rounded",children:n("modelProviders.capImageGen")}),(w.includes("tts")||w.includes("audioOutput"))&&e.jsx("span",{className:"text-[9px] bg-emerald-500/15 text-emerald-600 px-1 py-0.5 rounded",children:n("modelProviders.capTts")}),(w.includes("stt")||w.includes("audioInput"))&&e.jsx("span",{className:"text-[9px] bg-teal-500/15 text-teal-600 px-1 py-0.5 rounded",children:n("modelProviders.capStt")}),w.includes("videoGeneration")&&e.jsx("span",{className:"text-[9px] bg-orange-500/15 text-orange-600 px-1 py-0.5 rounded",children:n("modelProviders.capVideo")}),b&&r!=="markus"&&e.jsx("span",{className:"text-[9px] bg-purple-500/15 text-purple-400 px-1 py-0.5 rounded",children:n("modelProviders.custom")})]}),e.jsxs("div",{className:"flex items-center gap-3 text-fg-tertiary shrink-0",children:[(x.contextWindow??0)>0&&e.jsx("span",{children:n("modelProviders.ctxTokens",{size:((x.contextWindow??0)/1e3).toFixed(0)})}),b&&r!=="markus"&&e.jsx("button",{onClick:U=>{U.stopPropagation(),a(x.id)},className:"text-red-400 hover:text-red-300 transition-colors",title:n("modelProviders.deleteCustomModelTitle"),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},x.id)})}),t&&!d&&e.jsx("button",{type:"button",onClick:()=>c(!0),className:"w-full text-[10px] text-fg-tertiary hover:text-brand-500 transition-colors py-1.5",children:n("modelProviders.showAllModels",{count:s.length})}),d&&u&&v.length===0&&e.jsx("div",{className:"text-[10px] text-fg-tertiary px-1 py-2",children:n("modelProviders.noFilterMatches")})]})}function mo({models:s,providerName:r,t:o,onAdd:n}){const[a,t]=l.useState(!1),d=l.useMemo(()=>[...s].sort((c,u)=>{const f=fn[c.mode??"chat"]??99,v=fn[u.mode??"chat"]??99;return f!==v?f-v:String(c.id??"").localeCompare(String(u.id??""))}),[s]);return e.jsxs("div",{className:"mt-2",children:[e.jsxs("button",{onClick:()=>t(!a),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors px-1",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${a?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),o("modelProviders.catalogModelsAvailable",{count:s.length})]}),a&&e.jsx("div",{className:"mt-1 space-y-0.5 pl-1 max-h-64 overflow-y-auto",children:d.map(c=>{const u=String(c.id??""),f=c.mode??"chat",v=uo[f];return e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded hover:bg-surface-overlay/60 group",children:[e.jsx("span",{className:"text-[11px] text-fg-secondary flex-1 truncate",children:u}),v&&e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full shrink-0 ${v.color}`,children:v.label}),e.jsx("button",{onClick:()=>n(u),className:"text-[9px] text-brand-500 hover:text-brand-400 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:o("modelProviders.addModel")})]},u)})})]})}function go({providerName:s,addModelForm:r,setAddModelForm:o,addModelSaving:n,onAdd:a,onCancel:t,t:d}){const[c,u]=l.useState([]),[f,v]=l.useState(!1),[M,x]=l.useState(!1),b=async()=>{v(!0);try{const w=await $.modelCatalog.getByProvider(s);u(w.models),x(!0)}catch{u([])}finally{v(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-[10px] text-fg-secondary",children:d("modelProviders.addModelTitle")}),e.jsx("button",{onClick:()=>{b()},disabled:f,className:"text-[10px] text-brand-500 hover:text-brand-400 disabled:opacity-40 transition-colors",children:f?"...":d("modelProviders.browseFromCatalog")})]}),M&&c.length>0&&e.jsx("div",{className:"border border-border-default rounded-lg p-2 mb-2",children:e.jsx(vn,{provider:s,models:c,selectedModel:r.id,showTiers:!0,onSelect:w=>{const P=c.find(U=>U.id===w);P&&o(U=>({...U,id:P.id,name:P.id,contextWindow:P.maxInputTokens,maxOutputTokens:P.maxOutputTokens,costInput:P.inputCostPer1MTokens,costOutput:P.outputCostPer1MTokens,reasoning:P.capabilities.reasoning,vision:P.capabilities.vision}))},compact:!0,maxVisible:5})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[e.jsx("input",{type:"text",placeholder:d("modelProviders.modelId"),value:r.id,onChange:w=>o({...r,id:w.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),e.jsx("input",{type:"text",placeholder:d("modelProviders.displayName"),value:r.name,onChange:w=>o({...r,name:w.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),e.jsx("input",{type:"number",placeholder:d("modelProviders.placeholderContextTokens"),value:r.contextWindow,onChange:w=>o({...r,contextWindow:Number(w.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"}),e.jsx("input",{type:"number",placeholder:d("modelProviders.maxOutput"),value:r.maxOutputTokens,onChange:w=>o({...r,maxOutputTokens:Number(w.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d("modelProviders.costPerMillionIn")}),e.jsx("input",{type:"number",step:"0.01",value:r.costInput,onChange:w=>o({...r,costInput:Number(w.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d("modelProviders.costPerMillionOut")}),e.jsx("input",{type:"number",step:"0.01",value:r.costOutput,onChange:w=>o({...r,costOutput:Number(w.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.reasoning,onChange:w=>o({...r,reasoning:w.target.checked}),className:"rounded"}),d("modelProviders.reasoning")]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.vision,onChange:w=>o({...r,vision:w.target.checked}),className:"rounded"}),d("modelProviders.vision")]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:a,disabled:n||!r.id||!r.name,className:"px-2 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded transition-colors",children:d(n?"modelProviders.adding":"common:create")}),e.jsx("button",{onClick:t,className:"px-2 py-1 text-[10px] border border-border-default text-fg-secondary hover:bg-surface-elevated rounded transition-colors",children:d("common:cancel")})]})]})}function Ae({type:s,text:r}){return e.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${s==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:r})}function fo({title:s,defaultCollapsed:r,configuredProviders:o,t:n,children:a,onBadgeClick:t}){const[d,c]=l.useState(r);return e.jsxs("section",{children:[e.jsxs("button",{type:"button",onClick:()=>c(!d),className:"flex items-center justify-between w-full group mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:s}),d&&o.length>0&&e.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",o.length," ",n("modelProviders.configuredCount"),")"]})]}),e.jsx("span",{className:`text-fg-tertiary text-xs transition-transform group-hover:text-fg-secondary ${d?"-rotate-90":""}`,children:"▼"})]}),d&&o.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:o.map(([u,f])=>e.jsxs("button",{type:"button",onClick:v=>{v.stopPropagation(),c(!1),t?.(u)},className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-lg border cursor-pointer transition-colors ${f.enabled?"bg-green-500/10 border-green-500/30 text-green-400 hover:bg-green-500/20":"bg-surface-elevated border-border-default text-fg-tertiary hover:border-gray-500"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${f.enabled?"bg-green-400":"bg-gray-500"}`}),f.displayName??u]},u))}),!d&&e.jsx("div",{className:"space-y-4",children:a})]})}function Ce({title:s,children:r}){return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:s}),e.jsx("div",{className:"space-y-4",children:r})]})}function Is({title:s,children:r,defaultOpen:o=!0}){const[n,a]=l.useState(o);return e.jsxs("section",{children:[e.jsxs("button",{type:"button",onClick:()=>a(!n),className:"flex items-center justify-between w-full group mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:s}),e.jsx("span",{className:`text-fg-tertiary text-xs transition-transform group-hover:text-fg-secondary ${n?"":"-rotate-90"}`,children:"▼"})]}),n&&e.jsx("div",{className:"space-y-4",children:r})]})}function Ls({label:s,value:r,color:o}){const n=o==="green"?"bg-green-500/10 text-green-600":"bg-brand-500/10 text-brand-500";return e.jsxs("div",{className:`rounded-xl px-5 py-4 ${n}`,children:[e.jsx("div",{className:"text-2xl font-bold",children:r}),e.jsx("div",{className:"text-xs mt-1 opacity-70",children:s})]})}function Je(s,r){if(s===0)return r?r("dataStorage.bytesZero"):"0 B";const o=r?[r("dataStorage.unitB"),r("dataStorage.unitKB"),r("dataStorage.unitMB"),r("dataStorage.unitGB")]:["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(s)/Math.log(1024)),o.length-1),a=s/Math.pow(1024,n);return`${a<10?a.toFixed(1):Math.round(a)} ${o[n]}`}function po({orphanInfo:s,dataDir:r,onPurged:o,formatBytes:n}){const{t:a}=me(["settings","common"]),t=[...s.orphanAgents.map(j=>({...j,kind:"agent"})),...s.orphanTeams.map(j=>({...j,kind:"team"}))],[d,c]=l.useState(new Set),[u,f]=l.useState(!1),[v,M]=l.useState(null),x=j=>c(C=>{const g=new Set(C);return g.has(j)?g.delete(j):g.add(j),g}),b=d.size===t.length&&t.length>0,w=()=>c(b?new Set:new Set(t.map(j=>j.id))),P=t.filter(j=>d.has(j.id)).reduce((j,C)=>j+C.size,0),U=async j=>{f(!0),M(null);try{const C=await $.system.purgeOrphans(j),g=C.purgedAgents.length+C.purgedTeams.length,p=a("dataStorage.cleaned",{count:g,size:n(C.freedBytes)});M(C.failures.length?a("dataStorage.cleanedWithFailureNote",{base:p,count:C.failures.length}):p),c(new Set),o()}catch{M(a("dataStorage.cleanupFailed"))}finally{f(!1)}};return e.jsxs("div",{className:"border-t border-border-default pt-4",children:[e.jsx("h4",{className:"text-xs font-semibold text-amber-500 mb-2",children:a("dataStorage.orphanedDirectories")}),e.jsxs("p",{className:"text-xs text-fg-tertiary mb-3",children:[a("dataStorage.orphanedDesc")," ",a("dataStorage.orphanedTotal",{size:n(s.totalOrphanSize),count:t.length})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:b,onChange:w,className:"rounded"}),a("common:selectAll")]}),d.size>0&&e.jsx("span",{className:"text-[10px] text-fg-secondary",children:a("dataStorage.selectedWithSize",{count:d.size,size:n(P)})})]}),e.jsx("div",{className:"space-y-0.5 mb-3 max-h-52 overflow-y-auto",children:t.map(j=>e.jsxs("div",{className:`flex items-center gap-2 text-xs py-1.5 px-2 rounded transition-colors ${d.has(j.id)?"bg-amber-500/10":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:[e.jsx("input",{type:"checkbox",checked:d.has(j.id),onChange:()=>x(j.id),className:"rounded shrink-0"}),j.kind==="team"&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:a("dataStorage.teamKind")}),e.jsx("span",{className:"text-fg-tertiary font-mono truncate min-w-0 flex-1",children:j.id}),e.jsx("span",{className:"text-fg-secondary tabular-nums shrink-0",children:n(j.size)}),e.jsx("button",{onClick:()=>{$.system.openPath(j.path)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0 underline",children:a("common:open")})]},j.id))}),e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[d.size>0&&e.jsx("button",{disabled:u,onClick:()=>{U([...d])},className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanSelected",{size:n(P)})}),e.jsx("button",{disabled:u,onClick:()=>{U()},className:"px-3 py-1.5 text-xs border border-amber-600/50 hover:bg-amber-600/10 text-amber-500 rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanAll",{size:n(s.totalOrphanSize)})})]}),v&&e.jsx("div",{className:"text-xs text-fg-tertiary mt-2",children:v})]})}function ho(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(null),[n,a]=l.useState(!0),[t,d]=l.useState(!1),[c,u]=l.useState(null),[f,v]=l.useState(!1),M=yn(),x=l.useCallback(async()=>{try{const C=await $.settings.getRemote();o(C)}catch{o(null)}finally{a(!1)}},[]);l.useEffect(()=>{x()},[x]),l.useEffect(()=>na.on("remote:status",C=>{const g=C.payload;g&&(o(g),d(!1))}),[]);const b=async()=>{d(!0),u(null);try{r?.enabled?(await $.settings.disableRemote(),await x(),d(!1)):(Fe.isAuthenticated()||await Rs(),await $.settings.enableRemote())}catch(C){u(String(C instanceof Error?C.message:C)),d(!1)}},w=async()=>{try{await Rs(),await x()}catch{}},P=()=>{r?.remoteUrl&&(navigator.clipboard.writeText(r.remoteUrl),v(!0),setTimeout(()=>v(!1),2e3))},U=t||r?.enabled&&!r?.connected&&r?.state!=="idle",j=r?.remoteUrl??null;return e.jsx(Ce,{title:s("settings:remoteAccess.title"),children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-content-secondary",children:s("settings:remoteAccess.description")}),Fe.isAuthenticated()?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-content-secondary",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),s("settings:remoteAccess.signedInAs")," ",e.jsx("strong",{children:M?.username??M?.displayName})]}):e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[e.jsx("svg",{className:"w-5 h-5 text-amber-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("span",{className:"text-sm text-amber-600 dark:text-amber-400",children:s("settings:remoteAccess.loginRequired")}),e.jsx("button",{onClick:w,className:"ml-auto px-3 py-1.5 text-xs font-medium bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors",children:s("settings:remoteAccess.signIn")})]}),Fe.isAuthenticated()&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:b,disabled:t||n,className:`relative w-12 h-6 rounded-full transition-colors duration-200 ${r?.enabled?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} ${t||n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:e.jsx("span",{className:`block w-5 h-5 bg-white rounded-full shadow transform transition-transform duration-200 ${r?.enabled?"translate-x-6":"translate-x-0.5"}`})}),e.jsx("span",{className:"text-sm font-medium",children:U?s("settings:remoteAccess.connecting"):r?.enabled?s("settings:remoteAccess.enabled"):s("settings:remoteAccess.disabled")}),U&&e.jsx(hn,{})]}),r?.enabled&&e.jsxs("div",{className:`flex items-center gap-1.5 text-xs ${r.connected?"text-green-600 dark:text-green-400":r.state==="registering"||r.state==="connecting"?"text-blue-600 dark:text-blue-400":"text-amber-600 dark:text-amber-400"}`,children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${r.connected?"bg-green-500 animate-pulse":r.state==="registering"||r.state==="connecting"?"bg-blue-500 animate-pulse":"bg-amber-500"}`}),r.connected?s("settings:remoteAccess.connected"):r.state==="registering"?s("settings:remoteAccess.registering"):r.state==="connecting"?s("settings:remoteAccess.connecting"):s("settings:remoteAccess.disconnected"),r.connected&&r.peerCount>0&&e.jsxs(e.Fragment,{children:[" · ",s("settings:remoteAccess.peerCount",{count:r.peerCount})]}),(r.state==="registering"||r.state==="connecting")&&e.jsx(hn,{})]})]}),c&&e.jsx("div",{className:"p-2 rounded-lg bg-red-500/10 text-red-500 text-sm",children:c}),r?.enabled&&r.peers&&r.peers.length>0&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-2",children:[e.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:s("settings:remoteAccess.connectedPeers")}),e.jsx("div",{className:"space-y-2 mt-1",children:r.peers.map(C=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg bg-surface-inset",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${C.transport==="p2p"?"bg-green-500":C.transport==="relay"?"bg-blue-500":"bg-amber-500 animate-pulse"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-sm font-mono text-content-primary truncate",children:[C.peerId.slice(0,8),"..."]}),e.jsx("div",{className:"text-xs text-content-tertiary",children:s("settings:remoteAccess.connectedSince",{time:new Date(C.connectedAt).toLocaleTimeString()})})]}),e.jsx("span",{className:`px-2 py-0.5 text-xs font-medium rounded-full ${C.transport==="p2p"?"bg-green-500/10 text-green-600 dark:text-green-400":C.transport==="relay"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"}`,children:C.transport==="p2p"?"P2P":C.transport==="relay"?"Relay":s("settings:remoteAccess.peerConnecting")})]},C.peerId))})]}),r?.enabled&&r.remoteUrl&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:s("settings:remoteAccess.url")}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("code",{className:"flex-1 px-3 py-1.5 text-sm bg-surface-inset rounded font-mono truncate",children:r.remoteUrl}),e.jsx("button",{onClick:P,className:`px-2 py-1.5 text-xs border rounded transition-colors ${f?"border-green-500 text-green-600 dark:text-green-400":"border-border-default hover:bg-surface-elevated"}`,children:s(f?"settings:remoteAccess.copied":"settings:remoteAccess.copy")})]})]}),j&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:s("settings:remoteAccess.qrCode")}),e.jsx("p",{className:"text-xs text-content-secondary mt-0.5 mb-2",children:s("settings:remoteAccess.scanQr")}),e.jsx(bo,{url:j})]})]})]})]})})}function hn(){return e.jsxs("svg",{className:"w-4 h-4 animate-spin text-content-secondary",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function bo({url:s}){const r=l.useRef(null),[o,n]=l.useState(!1);return l.useEffect(()=>{const a=r.current;a&&(n(!1),aa(()=>Promise.resolve().then(()=>_a),void 0).then(t=>{t.toCanvas(a,s,{width:200,margin:2,color:{dark:"#000000",light:"#ffffff"},errorCorrectionLevel:"M"})}).catch(()=>n(!0)))},[s]),o?e.jsx("a",{href:s,target:"_blank",rel:"noopener",className:"text-sm text-brand-500 underline",children:s}):e.jsx("div",{className:"inline-block p-2 bg-white rounded-lg",children:e.jsx("canvas",{ref:r,className:"block",style:{width:160,height:160}})})}const yo={multi_user:"👥",sso:"🔐",audit_enhanced:"📋",multi_instance:"🌐",offline_license:"📡"};function vo({authUser:s}){const{t:r}=me(["settings","common"]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-fg-primary mb-1",children:r("account.title")}),e.jsx("p",{className:"text-xs text-fg-tertiary",children:r("account.subtitle")})]}),e.jsx(jo,{}),e.jsx(co,{authUser:s})]})}function jo(){const{t:s}=me(["settings","common"]),[r,o]=l.useState(null),[n,a]=l.useState(!0),[t,d]=l.useState([]),[c,u]=l.useState([]),[f,v]=l.useState(null),[M,x]=l.useState(!0),[b,w]=l.useState(!1),[P,U]=l.useState(null),[j,C]=l.useState(!1),g=l.useCallback((_=!1)=>{x(!0),$.hubOrgs.mine().catch(z=>(_&&v({type:"err",text:z instanceof Error?z.message:s("org.loadFailed")}),{orgs:[]})).then(z=>{d(z.orgs),$.hubOrgs.invitations().then(G=>u(G.invitations)).catch(()=>{})}).finally(()=>x(!1))},[s]);l.useEffect(()=>{if(!yn()&&!ns()){x(!1),a(!1);return}g(),Fe.user.plan().then(_=>o(_)).catch(()=>{}).finally(()=>a(!1))},[g]);const p=l.useCallback((_=!1)=>{C(!0),(_?$.license.refresh():$.license.get()).then(G=>U(G)).catch(()=>{}).finally(()=>setTimeout(()=>C(!1),400))},[]);l.useEffect(()=>{p(!0)},[p]);const N=P?.plan==="enterprise",I=async _=>{try{await $.hubOrgs.acceptInvitation(_),u(z=>z.filter(G=>G.orgId!==_)),g()}catch(z){v({type:"err",text:z instanceof Error?z.message:"Failed"})}},B=P?.validUntil?Math.max(0,Math.ceil((new Date(P.validUntil).getTime()-Date.now())/864e5)):null,F=["multi_user","multi_instance"],K={multi_user:s("license.featureMultiUser"),multi_instance:s("license.featureMultiInstance")},O=t.find(_=>_.id===r?.orgId)??t[0],R=r?r.creditsBudgetCu??(r.monthlyQuotaCu??0)+(r.bonusCu??0)+(r.purchasedCu??0):0,L=!!(r?.memberCuLimit!=null&&r.memberCuLimit>0&&O&&O.role!=="owner"&&O.role!=="admin"&&O.memberCount>1),h=Math.round(L?r?.memberCuUsed??0:r?.totalConsumedThisPeriod??r?.cuUsed??0),S=L?r?.memberCuLimit??0:R;return M||n?e.jsx("div",{className:"text-center py-8 text-fg-tertiary text-sm",children:s("common:loading")}):e.jsxs("div",{className:"space-y-6",children:[f&&e.jsxs("div",{className:`flex items-center gap-2 text-sm px-4 py-3 rounded-lg ${f.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/20":"bg-red-500/10 text-red-500 border border-red-500/20"}`,children:[e.jsx("span",{children:f.type==="ok"?"✓":"✕"}),e.jsx("span",{children:f.text})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-3",children:s("account.cloudAiTitle")}),e.jsxs("div",{className:"rounded-lg border border-border-default bg-gradient-to-r from-brand-600/5 to-transparent px-5 py-4 space-y-3",children:[r?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-tertiary",children:s("account.currentPlan")}),e.jsx("span",{className:"px-2 py-0.5 rounded text-xs font-semibold capitalize bg-brand-600/10 text-brand-500 border border-brand-500/15",children:r.planType})]}),S>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s(L?"account.personalLimit":"account.credits")}),e.jsxs("span",{className:"font-medium text-fg-primary tabular-nums",children:[h.toLocaleString()," / ",S.toLocaleString()]})]})]}):e.jsx("p",{className:"text-xs text-fg-secondary",children:s("license.cloudAiDesc")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("a",{href:`${Fe.getUrl()}/settings?tab=billing`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors no-underline",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),s("account.manageBilling")]})})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-3",children:s("account.orgSection")}),c.length>0&&e.jsx("div",{className:"space-y-2 mb-3",children:c.map(_=>e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 rounded-lg border border-amber-500/20 bg-amber-500/5",children:[e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium text-fg-primary",children:_.orgName}),e.jsxs("span",{className:"text-fg-tertiary ml-1",children:["— ",s("org.invitedBy")," ",_.invitedBy]})]}),e.jsx("button",{onClick:()=>{I(_.orgId)},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors",children:s("org.accept")})]},_.orgId))}),O?e.jsxs("div",{className:"rounded-lg border border-border-default px-5 py-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s("org.nameLabel")}),e.jsx("span",{className:"font-medium text-fg-primary",children:O.name})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s("account.memberCount")}),e.jsx("span",{className:"font-medium text-fg-primary",children:O.memberCount})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s("org.orgId")}),e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-surface-elevated text-fg-secondary text-[11px]",children:O.id})]}),e.jsxs("a",{href:`${Fe.getUrl()}/settings?tab=organization`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-4 py-2 border border-border-default text-fg-secondary hover:bg-surface-elevated text-xs font-medium rounded-lg transition-colors no-underline",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),s("account.manageOrg")]})]}):e.jsxs("div",{className:"rounded-lg border border-border-default px-5 py-6 text-center space-y-3",children:[e.jsx("div",{className:"text-sm text-fg-tertiary",children:s("org.noOrg")}),!!ns()&&e.jsx("div",{className:"text-xs text-amber-500/90",children:s("org.staleSessionHint")}),e.jsxs("button",{disabled:b,onClick:()=>{v(null),w(!0),Rs({force:!0}).then(()=>g(!0)).catch(_=>{const z=_ instanceof Error?_.message:String(_),G=z.includes("Popup blocked")?s("org.popupBlocked"):z.includes("cancelled")?s("org.loginCancelled"):z;v({type:"err",text:G})}).finally(()=>w(!1))},className:"px-5 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-60 text-white text-sm font-medium rounded-lg transition-colors inline-flex items-center gap-2",children:[b&&e.jsx("svg",{className:"w-4 h-4 animate-spin",viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeDasharray:"30 70",strokeLinecap:"round"})}),b?s("org.connecting"):ns()?s("org.reconnectHub"):s("org.connectHub")]})]})]}),N&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:s("license.title")}),e.jsxs("button",{onClick:()=>p(!0),disabled:j,className:"ml-auto flex items-center gap-1.5 text-xs text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${j?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h5M20 20v-5h-5M4.05 11A8 8 0 0119.95 9M19.95 13A8 8 0 014.05 15"})}),s("license.refresh")]})]}),e.jsx(No,{isEnterprise:!0,licenseInfo:P,daysRemaining:B,effectiveValidUntil:P?.validUntil,effectiveMaxSeats:P?.maxSeats,effectiveUsedSeats:O?.memberCount??P?.usedSeats??0,effectiveOrgName:O?.name??P?.orgName,featureKeys:F,featureI18n:K,t:s})]}),e.jsxs("div",{className:"flex items-center gap-4 text-[11px] text-fg-tertiary pt-1",children:[e.jsx("a",{href:"https://markus.global",target:"_blank",rel:"noopener noreferrer",className:"hover:text-fg-secondary transition-colors",children:s("license.website")}),e.jsx("a",{href:`mailto:${s("license.salesEmail")}`,className:"hover:text-fg-secondary transition-colors",children:s("license.salesEmail")})]})]})}function No({isEnterprise:s,licenseInfo:r,daysRemaining:o,effectiveValidUntil:n,effectiveMaxSeats:a,effectiveUsedSeats:t,effectiveOrgName:d,featureKeys:c,featureI18n:u,t:f}){return s?e.jsx("div",{className:"rounded-lg border border-brand-500/20 overflow-hidden",children:e.jsxs("div",{className:"px-5 py-4 bg-gradient-to-r from-brand-600/5 to-transparent",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-base font-semibold text-fg-primary",children:f("license.planEnterprise")}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-green-500/12 text-green-600 border border-green-500/15",children:f("license.statusActive")}),r?.isTrial&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-amber-500/12 text-amber-600 border border-amber-500/15",children:f("license.trial")})]}),o!==null&&e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:`text-sm font-semibold tabular-nums ${o===0?"text-red-500":o<=7?"text-amber-500":o<=60?"text-amber-600":"text-fg-primary"}`,children:o>0?f("license.daysRemaining",{count:o}):f("license.expired")}),e.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:f("license.expiresOn",{date:new Date(n).toLocaleDateString()})})]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:c.map(v=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium text-brand-500 bg-brand-600/6 border border-brand-500/10",children:[yo[v]," ",u[v]]},v))}),d&&e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-surface-primary/40 border border-border-default/30",children:[e.jsx("span",{className:"text-fg-tertiary",children:f("license.organization")}),e.jsx("span",{className:"font-medium text-fg-primary",children:d})]}),a!=null&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-surface-primary/40 border border-border-default/30",children:[e.jsx("span",{className:"text-fg-tertiary",children:f("license.seats")}),e.jsxs("span",{className:"font-medium text-fg-primary",children:[t," / ",a]})]})]})]})}):null}function wo({modelId:s,tier:r}){const{t:o}=me("settings");let n;if(r==="max"||r==="pro"||r==="base")n=r;else{const t=s.toLowerCase(),d=/opus|5\.4|o3-(?!mini)|o1-(?!mini)|gemini.*ultra|sonnet-4-20/,c=/haiku|flash|nano|lite|small|fast|free|8b|7b|1b|3b/;/o4-mini|o3-mini|o1-mini|gpt-4o-mini/.test(t)?n="pro":d.test(t)?n="max":c.test(t)?n="base":n="pro"}const a={max:"bg-purple-500/15 text-purple-400",pro:"bg-blue-500/15 text-blue-400",base:"bg-gray-500/15 text-gray-400"};return e.jsx("span",{className:`text-[9px] px-1 py-0.5 rounded font-semibold uppercase ${a[n]}`,children:o(`modelRouting.tier.${n}`)})}export{Ao as Settings};
|