@kimicode/cli 1.0.39 → 1.0.40

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.
Files changed (120) hide show
  1. package/LICENSE.md +12 -0
  2. package/README.md +427 -31
  3. package/bin/stt/requirements.txt +32 -0
  4. package/bin/stt/stt_server.py +619 -0
  5. package/bin/tts/requirements.txt +21 -0
  6. package/bin/tts/tts_server.py +404 -0
  7. package/cli-wrapper.cjs +4 -0
  8. package/llms.txt +88 -0
  9. package/package.json +30 -11
  10. package/web/dist/assets/AssistantsView-BiUiWjhF.js +1 -0
  11. package/web/dist/assets/AutomationView-Dcf_yNaI.js +1 -0
  12. package/web/dist/assets/ChannelConfigView-BLnxsMGm.js +8 -0
  13. package/web/dist/assets/ConnectorsView-CX3E6X6c.js +1 -0
  14. package/web/dist/assets/DesignSystemView--x-P-lpD.js +1 -0
  15. package/web/dist/assets/Drawer-CjAgqH3B.js +1 -0
  16. package/web/dist/assets/{FileTreeView-hBtHBbAV.js → FileTreeView-Chb_fzTK.js} +3 -3
  17. package/web/dist/assets/HookConfigView-EafYlWdN.js +1 -0
  18. package/web/dist/assets/InputArea-BbHslX7b.js +50 -0
  19. package/web/dist/assets/ModelsView-CGN5Nljr.js +1 -0
  20. package/web/dist/assets/PluginsView-CDiJgvI8.js +2 -0
  21. package/web/dist/assets/ProjectsView-C5Usmwqy.js +1 -0
  22. package/web/dist/assets/SessionGrid-Drxg0r_u.js +4 -0
  23. package/web/dist/assets/SettingsModal-Cmts6aBG.js +10 -0
  24. package/web/dist/assets/Skeleton-Dsk6B0U3.js +1 -0
  25. package/web/dist/assets/SkillsView-TEDR_3XX.js +1 -0
  26. package/web/dist/assets/TemplatesTab-DtN5Kdgh.js +1 -0
  27. package/web/dist/assets/ToolsView-VukZnIt1.js +1 -0
  28. package/web/dist/assets/VizCardsSkeleton-C_GaEfXd.js +1 -0
  29. package/web/dist/assets/abnfDiagram-YUKMZFIV-BIFw6B_N.js +1 -0
  30. package/web/dist/assets/arc-BZQ951h9.js +1 -0
  31. package/web/dist/assets/architectureDiagram-47P4ROYG-BP5qiXzf.js +36 -0
  32. package/web/dist/assets/blockDiagram-E7TT5TSB-DtRpcE7F.js +140 -0
  33. package/web/dist/assets/c4Diagram-CRA5TL53-Gdzn8UBh.js +38 -0
  34. package/web/dist/assets/channel-BND6_KSH.js +1 -0
  35. package/web/dist/assets/chunk-2Q5K7J3B-3U6HMlsm.js +1 -0
  36. package/web/dist/assets/chunk-5VM5RSS4-CYl9mwa-.js +15 -0
  37. package/web/dist/assets/chunk-7TKQ45FW-Dn6ktcY5.js +1 -0
  38. package/web/dist/assets/chunk-AW2ZBBNX-De0QX6p1.js +88 -0
  39. package/web/dist/assets/chunk-FVRAUYC3-CpXDfvz4.js +2 -0
  40. package/web/dist/assets/chunk-HTAEGDNF-D1KDvcDd.js +1 -0
  41. package/web/dist/assets/chunk-JWPE2WC7-umm4A-fq.js +1 -0
  42. package/web/dist/assets/chunk-KQW6MTUR-JYH94hpE.js +1 -0
  43. package/web/dist/assets/chunk-XXDRQBXY-CSlCFByc.js +1 -0
  44. package/web/dist/assets/classDiagram-v2-K4WV4PDN-DnFwS0qN.js +217 -0
  45. package/web/dist/assets/cose-bilkent-JH36ORCC-BxUTUyep.js +1 -0
  46. package/web/dist/assets/cynefin-EF2NZ3EQ-CiMvulJr.js +141 -0
  47. package/web/dist/assets/cynefinDiagram-3GCD6N5R-DuXFORdW.js +62 -0
  48. package/web/dist/assets/cytoscape.esm-Ix0LnXOy.js +331 -0
  49. package/web/dist/assets/dagre-W4DXFKR2-DzMZHXci.js +4 -0
  50. package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
  51. package/web/dist/assets/diagram-2UJZ2QOL-B6tO5G1v.js +200 -0
  52. package/web/dist/assets/diagram-OVF4WLC6-DRZt8tGc.js +24 -0
  53. package/web/dist/assets/diagram-PFPMY2P6-DGh6IecR.js +30 -0
  54. package/web/dist/assets/diagram-UMYRVEAY-BLbnt0yT.js +24 -0
  55. package/web/dist/assets/diagram-YEKJPTXX-C-S5DVhj.js +41 -0
  56. package/web/dist/assets/diagram-ZIFT7M5P-JrGHTWbo.js +3 -0
  57. package/web/dist/assets/ebnfDiagram-VR2GEFS7-DPXA-YOi.js +1 -0
  58. package/web/dist/assets/elk-IJKZMXRS-CINeWt2W.js +27 -0
  59. package/web/dist/assets/erDiagram-O2IAPWRE-PPaHmqA1.js +99 -0
  60. package/web/dist/assets/flowDiagram-OXPTDLAJ-t-u0QXEA.js +213 -0
  61. package/web/dist/assets/ganttDiagram-R7TSEDQI-Bw49ZD_b.js +292 -0
  62. package/web/dist/assets/gitGraphDiagram-XJZIOB7I-BAfOqeeg.js +106 -0
  63. package/web/dist/assets/graph-Bn3Yngep.js +1 -0
  64. package/web/dist/assets/{icons-BxNxyk-c.js → icons-Bm_ZzSAy.js} +320 -160
  65. package/web/dist/assets/index-CeeLdENM.js +677 -0
  66. package/web/dist/assets/index-Ceez9lYk.css +1 -0
  67. package/web/dist/assets/infoDiagram-5W2HQ5XZ-Bv4RBxYW.js +2 -0
  68. package/web/dist/assets/init-Gi6I4Gst.js +1 -0
  69. package/web/dist/assets/ishikawaDiagram-K3B6WC7H-DEpj0bRp.js +70 -0
  70. package/web/dist/assets/journeyDiagram-COXZFDF6-MJu84Iiz.js +139 -0
  71. package/web/dist/assets/kanban-definition-P3RFRI5V-mlYSRALK.js +89 -0
  72. package/web/dist/assets/linear-5j9gt8MV.js +1 -0
  73. package/web/dist/assets/{markdown-B2L4Mq-x.js → markdown-BWXjRrSw.js} +8 -8
  74. package/web/dist/assets/mermaid.core-DLb6eAON.js +314 -0
  75. package/web/dist/assets/mindmap-definition-LZFPQGKD-C9v_57Ex.js +96 -0
  76. package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
  77. package/web/dist/assets/{panels-P_I7Q72_.js → panels-BQOvnbWH.js} +1 -1
  78. package/web/dist/assets/pegDiagram-BGZESJAR-KQP26s3-.js +1 -0
  79. package/web/dist/assets/pieDiagram-CAPJLFHJ-DN3RQ_ih.js +39 -0
  80. package/web/dist/assets/profileChange-B7TaQ18u.js +1 -0
  81. package/web/dist/assets/quadrantDiagram-GDMTTRAM-BpL_ZL76.js +7 -0
  82. package/web/dist/assets/railroadDiagram-SM67HX2B-DZ-fPU85.js +1 -0
  83. package/web/dist/assets/{react-vendor-B2V_5iSS.js → react-vendor-C0HIWSpf.js} +1 -1
  84. package/web/dist/assets/requirementDiagram-X7JNWC4A-mKPGj64L.js +84 -0
  85. package/web/dist/assets/sankeyDiagram-UM26HJRW-Bs4xfjQP.js +40 -0
  86. package/web/dist/assets/sequenceDiagram-ZO4K6R2Y-BjUmzZaO.js +169 -0
  87. package/web/dist/assets/sizeCapture-INFHLROL-BXBM3j_Q.js +1 -0
  88. package/web/dist/assets/{state-0T92JV0u.js → state-Kfon1nTr.js} +1 -1
  89. package/web/dist/assets/stateDiagram-v2-TBUQTH76-FGgFDGUU.js +291 -0
  90. package/web/dist/assets/sttLanguages-C7kVulzY.js +1 -0
  91. package/web/dist/assets/swimlanes-N4OXWK64-wkd_n4HU.js +1 -0
  92. package/web/dist/assets/swimlanesDiagram-K3J5GTZL-CKnwEuq_.js +8 -0
  93. package/web/dist/assets/timeline-definition-YOQAKGHF-DyBln1jw.js +120 -0
  94. package/web/dist/assets/usecaseDiagram-VIAY4XPW-Cqis3XHX.js +370 -0
  95. package/web/dist/assets/vennDiagram-BLWOH2XV-BaiFLOVS.js +34 -0
  96. package/web/dist/assets/wardleyDiagram-YMQ3BMBF-C4CzpJto.js +78 -0
  97. package/web/dist/assets/xychartDiagram-TAQBALBS-Dp1hfe3-.js +7 -0
  98. package/web/dist/figma-demo/product-1.jpg +0 -0
  99. package/web/dist/figma-demo/product-2.jpg +0 -0
  100. package/web/dist/figma-demo/trail-1.jpg +0 -0
  101. package/web/dist/figma-demo/trail-2.jpg +0 -0
  102. package/web/dist/figma-demo/trail-3.jpg +0 -0
  103. package/web/dist/index.html +8 -8
  104. package/web/dist/assets/AssistantsView-0aLB_cG6.js +0 -1
  105. package/web/dist/assets/AutomationView-CAMjPhJ2.js +0 -1
  106. package/web/dist/assets/ChannelConfigView-FcioeeYb.js +0 -8
  107. package/web/dist/assets/ConnectorsView-DERP7zAW.js +0 -1
  108. package/web/dist/assets/HookConfigView-NModtSB8.js +0 -1
  109. package/web/dist/assets/ModelsView-BPpO50C_.js +0 -1
  110. package/web/dist/assets/PluginsView-D0NE7zrt.js +0 -1
  111. package/web/dist/assets/ProjectsView-PIv7Gx4q.js +0 -1
  112. package/web/dist/assets/SessionGrid-BsDL3lov.js +0 -47
  113. package/web/dist/assets/SettingsModal-DdebvEmv.js +0 -10
  114. package/web/dist/assets/SkillsView-BNoigImJ.js +0 -1
  115. package/web/dist/assets/TemplatesTab-D8Pa68fj.js +0 -1
  116. package/web/dist/assets/ToolsView-NY-yk5YX.js +0 -1
  117. package/web/dist/assets/WorkspaceDirPicker-C5knnArH.js +0 -6
  118. package/web/dist/assets/index-DaiVo1RY.css +0 -1
  119. package/web/dist/assets/index-RB5ffy32.js +0 -620
  120. package/web/dist/assets/profileChange-C7Jg9C61.js +0 -1
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-BWXjRrSw.js";import{a as o,d as ne,a0 as Vs,s as ke,S as de,X as Fe,a1 as se,w as ze,a2 as ps,a3 as Ws,z as Ys,a4 as Qs,a5 as Js,D as Xs,q as Zs,a6 as hs,A as et,a7 as st}from"./icons-Bm_ZzSAy.js";import{a as j,u as tt,t as M,B as bs,g as ce,M as fs,P as at}from"./index-CeeLdENM.js";import{S as lt,a as Ne}from"./Skeleton-Dsk6B0U3.js";import"./react-vendor-C0HIWSpf.js";import"./state-Kfon1nTr.js";import"./panels-BQOvnbWH.js";function rt(){const[k,v]=o.useState([]),[C,t]=o.useState("1.0"),[P,Te]=o.useState(!0),[g,ie]=o.useState(!0),[Se,X]=o.useState(null),Z=o.useCallback(async()=>{ie(!0),X(null);try{const N=await j.providers.presets();N.success&&N.data?(v(Array.isArray(N.data.providers)?N.data.providers:[]),t(N.data.version||"1.0"),Te(N.data.customSupported!==!1)):X(N.error||"获取 Provider 列表失败")}catch(N){X(N instanceof Error?N.message:"未知错误")}finally{ie(!1)}},[]);return o.useEffect(()=>{Z()},[Z]),{presets:k,loading:g,error:Se,version:C,customSupported:P,reload:Z}}const ot=[{key:"global",labelKey:"chat.globalDefault",color:"text-accent-red",bg:"bg-accent-red/20"},{key:"goal",labelKey:"chat.goalDefault",color:"text-accent-purple",bg:"bg-accent-purple/20"}],nt={providerKey:"",apiKeys:[],modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!1,modelOverrides:{}},gs=at,we={"openai-chat-completions":"OpenAI Chat","openai-completions":"OpenAI Compatible","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages","codex-responses":"Codex (本机登录)","claude-code":"Claude Code (本机登录)"};function te(k){return k.trim().split("|")[0].trim()}function dt(k){const v=k.toLowerCase();return v.startsWith("claude-code://")||v.includes("/backend-api/codex")?v.startsWith("claude-code://")?"claude-code":"codex-responses":v.includes("/anthropic")||v.includes("/coding")||v.includes("/claude")||v.includes("/messages")?"anthropic-messages":v.includes("/responses")?"openai-responses":"openai-completions"}function Ee(k){if(!k)return{};const v={};for(const C of k.models){const t={};C.apiType&&C.apiType!==k.apiType&&(t.apiType=C.apiType),C.baseUrl&&(t.baseUrl=C.baseUrl),Object.keys(t).length>0&&(v[C.id]=t)}return v}const Ce={"opencode-free":5,"opencode-go":6,commandcode:7,deepseek:10,moonshotai:20,"moonshotai-cn":21,"kimi-for-coding":22,zhipuai:30,zai:31,"alibaba-cn":40,alibaba:41,minimax:50,"minimax-cn":51,moark:60,siliconflow:70,"siliconflow-cn":71,"stepfun-ai":80,stepfun:81,modelscope:90,openai:100,anthropic:110,google:120,"google-vertex":121,meta:130,mistral:140,groq:150,xai:160,cohere:170,openrouter:180,huggingface:190};function bt(){var rs,os,ns,ds,cs,is,us;const{presets:k,loading:v,reload:C}=rt(),{t}=tt(),[P,Te]=o.useState([]),[g,ie]=o.useState(null),[Se,X]=o.useState(!0),[Z,N]=o.useState(null),[Le,Re]=o.useState(null),[n,vs]=o.useState(null),[$,ys]=o.useState([]),[js,V]=o.useState(!1),[Oe,W]=o.useState("select"),[T,B]=o.useState(null),[i,f]=o.useState(nt),[ks,L]=o.useState(""),[Ns,Be]=o.useState(!1),[He,R]=o.useState(null),[Me,ae]=o.useState(!1),[ue,Ge]=o.useState(!1),[le,me]=o.useState(""),[Ke,qe]=o.useState(!1),[K,Y]=o.useState([]),[xe,F]=o.useState(new Set),[_e,H]=o.useState(null),[pe,re]=o.useState(""),[ws,Ve]=o.useState(!1),[De,We]=o.useState(!1),[he,G]=o.useState(null),Ye=o.useMemo(()=>{const s=pe.trim().toLowerCase();return s?K.filter(a=>a.id.toLowerCase().includes(s)||a.name.toLowerCase().includes(s)):K},[K,pe]),Q=o.useCallback(async()=>{try{const s=await j.config.provider.get();s.success&&s.data&&(vs(s.data),ys(Array.isArray(s.data.entries)?s.data.entries:[]))}catch{}},[]),D=o.useCallback(async()=>{X(!0),N(null);try{const[s,a]=await Promise.all([j.models.list(),j.system.status()]);if(await Q(),s.success&&s.data&&Array.isArray(s.data.models)&&Te(s.data.models),a.success&&a.data){const l=a.data.models||{total:0,online:0,offline:0};ie({overallStatus:l.offline===0?"healthy":l.online>0?"degraded":"unhealthy",healthRate:l.total>0?l.online/l.total:0,healthyInstances:l.online,totalInstances:l.total,totalRequests:0})}}catch{N(t("models.loadFailed"))}finally{X(!1)}},[Q,t]);o.useEffect(()=>{D()},[D]),o.useEffect(()=>{const s=()=>{D(),Q()};return window.addEventListener("models-updated",s),()=>window.removeEventListener("models-updated",s)},[D,Q]);const be=o.useCallback(s=>`${s.provider}:${s.id}`,[]),U=o.useMemo(()=>{const s=[...k];return s.find(a=>a.key==="custom")||s.push({key:"custom",name:"Custom",baseUrl:"",apiType:"openai-completions",defaultModel:"",isCustom:!0}),s},[k]),fe=o.useMemo(()=>[...U].sort((s,a)=>{if(s.isCustom)return-1;if(a.isCustom)return 1;const l=Ce[s.key],d=Ce[a.key];return l!==void 0&&d!==void 0?l-d:l!==void 0?-1:d!==void 0?1:s.name.localeCompare(a.name)}),[U]),Qe=o.useMemo(()=>{const s=le.trim().toLowerCase();return s?fe.filter(a=>a.name.toLowerCase().includes(s)||a.key.toLowerCase().includes(s)||(a.defaultModel||"").toLowerCase().includes(s)||(a.baseUrl||"").toLowerCase().includes(s)||(a.models||[]).some(l=>String(l).toLowerCase().includes(s))):fe},[fe,le]),O=o.useMemo(()=>{var d,r,c,u;const s=(n==null?void 0:n.providers)||{},a=new Set(U.map(m=>m.key)),l=Object.entries(s).filter(([m])=>!a.has(m));if(l.length!==0)return{keys:l.map(([m])=>m),modelCount:l.reduce((m,[,b])=>m+(b.modelCount||0),0),hasApiKey:l.some(([,m])=>m.hasApiKey),baseUrl:((r=(d=l.find(([,m])=>m.baseUrl))==null?void 0:d[1])==null?void 0:r.baseUrl)||"",apiType:((u=(c=l.find(([,m])=>m.apiType))==null?void 0:c[1])==null?void 0:u.apiType)||"openai-completions"}},[n,U]),J=T==="custom"?i.providerKey.trim():T||"",Ue=o.useMemo(()=>J?P.filter(s=>s.provider===J):[],[P,J]),Cs=o.useMemo(()=>{const s=new Map;for(const l of P)s.has(l.provider)||s.set(l.provider,[]),s.get(l.provider).push(l);for(const l of $)s.has(l.key)||s.set(l.key,[]);const a=[...s.keys()];return a.sort((l,d)=>{const r=Ce[l],c=Ce[d];return r!==void 0&&c!==void 0?r-c:r!==void 0?-1:c!==void 0?1:l.localeCompare(d)}),a.map(l=>({provider:l,models:s.get(l)||[]}))},[P,$]),Je=o.useCallback(s=>{var u,m;const a=(u=n==null?void 0:n.providers)==null?void 0:u[s.key],l=$.find(b=>b.key===s.key),d=P.filter(b=>b.provider===s.key).map(b=>b.id),r=((m=s.models)==null?void 0:m.slice(0,3).join(", "))||s.defaultModel,c=d.length>0?d.join(", "):r;B(s.key),L(""),f({providerKey:s.key,apiKeys:[""],modelIds:c,baseUrl:(a==null?void 0:a.baseUrl)||s.baseUrl,apiType:(a==null?void 0:a.apiType)||s.apiType,fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s.key,modelOverrides:Ee(l)}),W("form"),V(!0),R(null),ae(!1),Y([]),F(new Set),H(null),re("")},[P,n,$]),Ps=o.useCallback(s=>{var r;const a=(r=n==null?void 0:n.providers)==null?void 0:r[s],l=$.find(c=>c.key===s),d=P.filter(c=>c.provider===s).map(c=>c.id).join(", ");B("custom"),L(s),f({providerKey:s,apiKeys:[""],modelIds:d,baseUrl:(a==null?void 0:a.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:Ee(l)}),R(null),ae(!1),Y([]),F(new Set),H(null),re("")},[n,P,$]),Ie=o.useCallback(()=>{B("custom"),L(""),f({providerKey:"",apiKeys:[""],modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!(n!=null&&n.configured),modelOverrides:{}}),W("form"),V(!0),R(null),ae(!1),Y([]),F(new Set),H(null),re("")},[n]),Ts=o.useCallback(async()=>{var d;const s=i.baseUrl;if(!s){H(t("models.baseUrlRequired"));return}qe(!0),H(null),Y([]),F(new Set);const a=U.find(r=>r.key===T)||null,l=!!a&&!a.isCustom&&(i.baseUrl||"")===a.baseUrl&&i.fullPath!==!0;try{const r=(i.apiKeys||[]).map(m=>m.trim()).filter(Boolean)[0]||"",c=r.replace(/[^\x00-\xFF]/g,"");c!==r&&M.warning(t("models.apiKeySanitized"));const u=await j.models.fetch(s,c,i.fullPath===!0,l?a.key:void 0);if(u.success&&((d=u.data)!=null&&d.models)){const m=u.data.models;Y(m),Ve(!0);const b={};for(const h of m)h.protocol&&h.protocol!==i.apiType&&(b[h.id]={apiType:h.protocol});Object.keys(b).length>0&&f(h=>{var x;const S={...h.modelOverrides};for(const[E,y]of Object.entries(b))(x=S[E])!=null&&x.apiType||(S[E]={...S[E]||{},...y});return{...h,modelOverrides:S}});const I=new Set(m.map(h=>h.id)),z=i.modelIds.split(",").map(h=>h.trim()).filter(Boolean),p=z.filter(h=>I.has(h.split("|")[0].trim())),q=z.filter(h=>!I.has(h.split("|")[0].trim()));if(F(new Set(p.map(h=>h.split("|")[0].trim()))),q.length>0){const h=q.map(S=>S.split("|")[0].trim());f(S=>({...S,modelIds:p.join(", ")})),M.warning(t("models.autoRemovedMissingModels",{models:h.join(", ")}))}M.success(t("models.fetchedCount",{n:m.length}))}else H(u.error||t("models.fetchFailed"))}catch(r){H(r instanceof Error?r.message:t("models.requestFailed"))}finally{qe(!1)}},[i.baseUrl,i.apiKeys,i.modelIds,i.apiType,i.fullPath,T,U,t]),Ss=o.useCallback(async()=>{var a,l;const s=i.baseUrl;if(!s){G({ok:!1,message:t("models.baseUrlRequired")});return}We(!0),G(null);try{const d=(i.apiKeys||[]).map(u=>u.trim()).filter(Boolean)[0]||"",r=d.replace(/[^\x00-\xFF]/g,"");r!==d&&M.warning(t("models.apiKeySanitized"));const c=await j.providers.testConnection(s,r);if(c.success&&((a=c.data)!=null&&a.reachable)){const u=c.data,m={};u.resolvedBaseUrl&&u.resolvedBaseUrl!==i.baseUrl&&(m.baseUrl=u.resolvedBaseUrl),u.detectedApiType&&i.apiType===""&&(m.apiType=u.detectedApiType),Object.keys(m).length>0&&f(z=>({...z,...m}));const b=[];m.baseUrl&&b.push(t("models.baseUrlAutoCompleted",{url:m.baseUrl})),m.apiType&&b.push(t("models.apiTypeAutoSelected",{type:we[m.apiType]}));const I=u.message||t("models.connectionSuccess");G({ok:!0,message:b.length>0?t("models.connectionSuccessWithHints",{message:I,hints:b.join(t("models.hintJoiner"))}):I})}else G({ok:!1,message:((l=c.data)==null?void 0:l.message)||c.error||t("models.connectionFailed")})}catch(d){G({ok:!1,message:d instanceof Error?d.message:t("models.requestFailed")})}finally{We(!1)}},[i.baseUrl,i.apiKeys,i.apiType,t]),Ms=o.useCallback(s=>{const a=new Set(xe);a.has(s)?a.delete(s):a.add(s),F(a),f(l=>({...l,modelIds:Array.from(a).join(", ")}))},[xe]),Ks=o.useCallback(s=>{const a=i.modelIds.split(",").map(c=>c.trim()).filter(Boolean),d=a.some(c=>te(c)===s.id)?a.filter(c=>te(c)!==s.id):[...a,s.name&&s.name!==s.id?`${s.id}|${s.name}`:s.id];f(c=>({...c,modelIds:d.join(", ")}));const r=new Set(K.map(c=>c.id));F(new Set(d.map(te).filter(c=>r.has(c))))},[i.modelIds,K]),[Ds,Xe]=o.useState(!1),[Ae,Ze]=o.useState(""),[es,ge]=o.useState([]),[Us,ss]=o.useState(!1),[ts,ve]=o.useState(null),[ye,Is]=o.useState(!1),[je,As]=o.useState(!0),$s=o.useCallback(()=>{Ze(""),ge([]),ve(null),Xe(!0),oe("",{reason:!1,tool:!0})},[]),oe=o.useCallback(async(s,a)=>{ss(!0),ve(null);try{const l=await j.models.catalogSearch({q:s,reasoning:(a==null?void 0:a.reason)??!1,toolCall:(a==null?void 0:a.tool)??!0,limit:30});l.success&&l.data?ge(l.data.hits||[]):(ve(l.error||t("models.catalogSearchFailed")),ge([]))}catch(l){ve(l instanceof Error?l.message:t("models.requestFailed")),ge([])}finally{ss(!1)}},[t]),Fs=o.useCallback(s=>{f(a=>{const l=a.modelIds.split(",").map(d=>d.trim()).filter(Boolean);return l.includes(s.model.id)?a:{...a,modelIds:[...l,s.model.id].join(", ")}}),M.success(t("models.addedModel",{id:s.model.id}))},[t]),[$e,zs]=o.useState(null),Es=o.useCallback(s=>{Ze(s),$e&&clearTimeout($e),zs(setTimeout(()=>{oe(s,{reason:ye,tool:je})},300))},[$e,ye,je,oe]),Ls=async s=>{const a=s.provider,l=s.id,d=s.enabled!==!1,r=s.name||l,c=u=>d&&/default model/i.test(u);try{const u=await j.models.toggle(a,l);if(u.success){await D();return}const m=u.error||"";c(m)?M.error(t("models.defaultModelDisableBlocked",{name:r})):M.error(m||t("models.operationFailed"))}catch(u){const m=u instanceof Error?u.message:"";c(m)?M.error(t("models.defaultModelDisableBlocked",{name:r})):M.error(m||t("models.operationFailed"))}},Rs=async s=>{const a=be(s);Re(a);try{await j.models.test(s.id),await D()}finally{Re(null)}},Os=async(s,a)=>{if(confirm(t("models.deleteModelConfirm",{id:a})))try{(await j.models.delete(s,a)).success&&await D()}catch{}},as=o.useCallback(s=>{var c;const a=$.find(u=>u.key===s),l=U.find(u=>u.key===s),d=!l||l.isCustom,r=(c=n==null?void 0:n.providers)==null?void 0:c[s];B(d?"custom":s),L(d?s:""),f({providerKey:s,apiKeys:[""],modelIds:(a==null?void 0:a.models.map(u=>u.name&&u.name!==u.id?`${u.id}|${u.name}`:u.id).join(", "))||"",baseUrl:(a==null?void 0:a.baseUrl)||(r==null?void 0:r.baseUrl)||(l==null?void 0:l.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||(r==null?void 0:r.apiType)||(l==null?void 0:l.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0||(r==null?void 0:r.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:Ee(a)}),W("form"),V(!0),R(null),ae(!1),Y([]),F(new Set),H(null),re("")},[$,U,n]),Bs=s=>{as(s.provider)},Hs=async()=>{var h,S;const s=U.find(x=>x.key===T)||null,a=T==="custom"?i.providerKey.trim():(s==null?void 0:s.key)||"";if(!a){R(t("models.providerNameRequired"));return}const l=(i.apiKeys||[]).map(x=>x.trim()).filter(Boolean),d=!!((S=(h=n==null?void 0:n.providers)==null?void 0:h[a])!=null&&S.hasApiKey);if(l.length===0&&!d){R(t("models.apiKeyRequired"));return}const r=s||{baseUrl:"",apiType:"openai-completions",defaultModel:""},c=l.map(x=>x.replace(/[^\x00-\xFF]/g,"")).filter(Boolean),u=K.length>0?new Set(K.map(x=>x.id)):null,m=(i.modelIds||r.defaultModel||"").split(",").map(x=>x.trim()).filter(Boolean),b=u?m.filter(x=>u.has(x.split("|")[0].trim())):m,I=u?m.filter(x=>!u.has(x.split("|")[0].trim())):[];I.length>0&&M.warning(t("models.autoSkippedMissingModels",{models:I.map(x=>x.split("|")[0].trim()).join(", ")}));const z=b.map(te).filter(Boolean),p=new Set;for(const x of P)x.provider!==a||z.includes(x.id)||(x.isGlobalDefault&&p.add("global"),x.isGoalDefault&&p.add("goal"));const q={provider:a,name:a,baseUrl:i.baseUrl||r.baseUrl,fullPath:i.fullPath===!0,apiType:i.apiType||dt(i.baseUrl||r.baseUrl)||r.apiType,models:b.map((x,E)=>{var xs;const y=x.trim().split("|").map(_s=>_s.trim()).filter(Boolean),A=y[0]||"",w=i.modelOverrides[A],ms=(w==null?void 0:w.apiType)||((xs=s==null?void 0:s.modelApiTypes)==null?void 0:xs[A]);return{id:A,name:y[1]||A,aliases:y.length>2?y.slice(2):void 0,enabled:!0,priority:10+E,...ms?{apiType:ms}:{},...w!=null&&w.baseUrl?{baseUrl:w.baseUrl}:{}}}).filter(x=>x.id.length>0)};c.length>0&&(q.apiKeys=c),(!(n!=null&&n.configured)||i.setDefault)&&(q.setDefault=!0),Be(!0),R(null);try{const x=await j.config.provider.save(q);if(x.success){if(p.size>0){const E=z[0]||"",y={};if(E){const A=`${a}:${E}`;for(const w of p)y[w]=A}else{const A=P.find(w=>w.provider!==a);for(const w of p)w==="goal"?y[w]=null:A&&(y[w]=`${A.provider}:${A.id}`)}Object.keys(y).length>0&&(await j.models.setDefaults(y)).success&&M.success(t("models.defaultsAutoUpdated"))}V(!1),W("select"),B(null),L(""),await Q(),await D()}else R(x.error||t("models.saveFailed"))}catch(x){R(x instanceof Error?x.message:t("models.unknownError"))}finally{Be(!1)}},ls=async s=>{if(confirm(t("models.removeConfirm",{providerKey:s})))try{await j.config.provider.delete(s),await Q(),await D()}catch{}},Gs=s=>{switch(s){case"online":return"text-accent-green";case"offline":return"text-dark-muted";case"error":return"text-accent-red";default:return"text-dark-muted"}},qs=s=>{switch(s){case"online":return e.jsx(st,{size:14});case"offline":return e.jsx(hs,{size:14});case"error":return e.jsx(et,{size:14});default:return e.jsx(hs,{size:14})}},ee=o.useMemo(()=>U.find(s=>s.key===T)||null,[T,U]);return Se?e.jsx("div",{className:"h-64 overflow-y-auto p-4",role:"status","aria-label":t("models.loading"),children:e.jsx(lt,{count:4})}):Z?e.jsx("div",{className:"flex h-64 items-center justify-center text-accent-red",children:Z}):e.jsx("div",{className:"ui-page flex-1 min-h-0",children:e.jsxs("div",{className:"ui-page-inner space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-base font-semibold",children:t("models.providerConfig")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:async()=>{try{await j.providers.refresh(),M.success(t("models.providerListRefreshed")),Ge(!0),await C(),setTimeout(()=>{C()},3e3)}catch{M.error(t("models.refreshFailed"))}},className:"btn btn-secondary px-3 py-2 text-xs",title:t("models.refreshListTitle"),children:[e.jsx(ne,{size:12}),t("models.refreshList")]}),e.jsxs("button",{onClick:()=>{ue&&me(""),Ge(s=>!s)},className:"btn btn-accent px-3 py-2 text-xs",children:[ue?e.jsx(Vs,{size:12}):e.jsx(ke,{size:12}),t(ue?"models.collapse":"models.addProvider")]})]})]}),ue&&e.jsxs("div",{children:[e.jsxs("div",{className:"relative mb-3 max-w-md",children:[e.jsx(de,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:le,onChange:s=>me(s.target.value),className:"w-full pl-8 pr-8 py-1.5 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",placeholder:t("models.providerSearchPlaceholder")}),le&&e.jsx("button",{onClick:()=>me(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-dark-text",title:t("models.clear"),"aria-label":t("models.clearSearch"),children:e.jsx(Fe,{size:13})})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3 max-h-[420px] overflow-y-auto custom-scrollbar pr-1",children:v?Array.from({length:10}).map((s,a)=>e.jsxs("div",{className:"ui-card p-4","aria-hidden":"true",children:[e.jsx(Ne,{variant:"text",width:"45%",height:16,className:"mb-2"}),e.jsx(Ne,{variant:"text",width:"85%",height:11,className:"mb-1.5"}),e.jsx(Ne,{variant:"text",width:"70%",height:11,className:"mb-1.5"}),e.jsx(Ne,{variant:"text",width:"55%",height:11})]},`preset-skeleton-${a}`)):Qe.length===0?e.jsxs("div",{className:"col-span-full border border-accent-red/30 bg-accent-red/10 rounded-lg p-4 text-center",children:[e.jsx("div",{className:"text-sm text-accent-red font-medium mb-1",children:t("models.noMatchingProviders")}),e.jsx("div",{className:"text-xs text-dark-muted mb-3",children:t("models.noMatchingProvidersHint",{query:le})}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsxs("button",{onClick:()=>me(""),className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-dark-border rounded hover:bg-dark-hover",children:[e.jsx(Fe,{size:12}),t("models.clearSearch")]}),e.jsx(bs,{variant:"accent",size:"sm",leftIcon:e.jsx(ke,{size:12}),onClick:Ie,children:t("models.addCustomProvider")})]})]}):Qe.map(s=>{var c,u;const a=s.key==="custom",l=a?O:(c=n==null?void 0:n.providers)==null?void 0:c[s.key],d=l==null?void 0:l.hasApiKey,r=a?!!(n!=null&&n.defaultProvider)&&((O==null?void 0:O.keys)||[]).includes(n.defaultProvider):(n==null?void 0:n.defaultProvider)===s.key;return e.jsxs("div",{className:`reveal-on-scroll ui-card-interactive text-left p-4 relative ${d?"border-accent-green/30 bg-dark-surface hover:border-accent-green/50":"border-dark-border bg-dark-surface hover:border-dark-hover"}`,children:[e.jsxs("div",{onClick:()=>s.key==="custom"?Ie():Je(s),className:"cursor-pointer",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),d&&e.jsx(se,{size:14,className:"text-accent-green"})]}),e.jsxs("div",{className:"text-badge text-dark-muted space-y-0.5",children:[e.jsx("div",{className:"truncate",children:a?(l==null?void 0:l.baseUrl)||t("models.customBaseUrl"):s.baseUrl||t("models.customBaseUrl")}),e.jsx("div",{className:"truncate",children:a&&O?`${O.keys.join(", ")}`:s.defaultModel||t("models.noDefaultModel")}),e.jsxs("div",{children:[l?t("models.configuredCount",{n:l.modelCount}):t("models.availableCount",{n:((u=s.models)==null?void 0:u.length)||0}),s.models&&s.models.length>0&&!l&&e.jsx("span",{className:"text-accent-blue",children:" ✓"})]})]}),r&&e.jsx("div",{className:"mt-1 text-badge text-accent-red",children:t("models.defaultProviderBadge")})]}),d&&s.key!=="custom"&&e.jsx("button",{onClick:m=>{m.stopPropagation(),ls(s.key)},className:"absolute top-1.5 right-1.5 p-1 rounded text-dark-muted hover:bg-accent-red/10 hover:text-accent-red transition-colors",title:t("models.deleteProvider"),"aria-label":t("models.deleteProviderNamed",{name:s.name}),children:e.jsx(ze,{size:13})})]},s.key)})})]})]}),g&&e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsx(Pe,{title:t("models.overallStatus"),value:g.totalInstances===0?t("models.notConfigured"):g.overallStatus==="healthy"?t("models.healthy"):g.overallStatus==="degraded"?t("models.degraded"):t("models.abnormal"),color:g.totalInstances===0?"blue":g.overallStatus==="healthy"?"green":g.overallStatus==="degraded"?"yellow":"red"}),e.jsx(Pe,{title:t("models.healthRate"),value:g.totalInstances===0?"N/A":`${(g.healthRate*100).toFixed(0)}%`,color:g.totalInstances===0?"blue":g.healthRate>.8?"green":g.healthRate>.5?"yellow":"red"}),e.jsx(Pe,{title:t("models.onlineInstances"),value:g.totalInstances===0?t("models.none"):`${g.healthyInstances}/${g.totalInstances}`,color:g.healthyInstances>0?"green":"red"}),e.jsx(Pe,{title:t("models.totalRequests"),value:g.totalRequests>0?g.totalRequests.toLocaleString():"0",color:"blue"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("models.configuredModels")}),e.jsx("span",{className:"text-badge text-dark-muted",title:t("models.actIsGlobalHint"),children:t("models.actIsGlobalHint")})]}),e.jsxs("div",{className:"space-y-4 max-h-[640px] overflow-y-auto custom-scrollbar pr-1",children:[Cs.map(s=>{var d;const a=$.find(r=>r.key===s.provider),l=(d=n==null?void 0:n.providers)==null?void 0:d[s.provider];return e.jsxs("div",{className:"rounded-lg border border-dark-border overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 bg-dark-bg border-b border-dark-border",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[e.jsx("span",{className:"text-xs font-semibold whitespace-nowrap text-accent-purple",children:s.provider}),(n==null?void 0:n.defaultProvider)===s.provider&&e.jsx("span",{className:"text-avatar px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red whitespace-nowrap",children:t("models.defaultShort")}),e.jsx("span",{className:"text-badge text-dark-muted truncate",children:(l==null?void 0:l.baseUrl)||(a==null?void 0:a.baseUrl)||""}),e.jsx("span",{className:"text-badge text-dark-muted whitespace-nowrap",children:(a==null?void 0:a.apiType)||(l==null?void 0:l.apiType)||""}),l!=null&&l.hasApiKey||a!=null&&a.hasApiKey?e.jsx("span",{className:"text-avatar px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green whitespace-nowrap",children:t("models.hasKey")}):e.jsx("span",{className:"text-avatar px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red whitespace-nowrap",children:t("models.noKey")})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>as(s.provider),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editProviderNamed",{name:s.provider}),children:e.jsx(ps,{size:13})}),e.jsx("button",{onClick:()=>ls(s.provider),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteProviderNamed",{name:s.provider}),children:e.jsx(ze,{size:13})})]})]}),e.jsxs("div",{className:"space-y-2 p-2 bg-dark-surface/40",children:[s.models.map(r=>{var m,b,I,z;const c=a==null?void 0:a.models.find(p=>p.id===r.id),u=!!(c!=null&&c.apiType&&c.apiType!==(a==null?void 0:a.apiType));return e.jsx("div",{className:`bg-dark-surface border rounded-lg p-3 ${r.status==="online"?"border-accent-green":"border-dark-border"} ${r.enabled===!1?"opacity-60":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:Gs(r.status),children:qs(r.status)}),e.jsx("span",{className:"font-medium text-sm text-accent-blue",children:r.name}),e.jsx("span",{className:"text-badge text-accent-purple px-1.5 py-0.5 bg-accent-purple/10 rounded",children:r.provider}),r.apiType&&e.jsx("span",{className:`text-badge px-1.5 py-0.5 rounded ${r.apiType==="anthropic-messages"||r.apiType==="openai-responses"?"bg-accent-purple/20 text-accent-purple":"bg-accent-blue/20 text-accent-blue"}`,children:we[r.apiType]||r.apiType}),u&&e.jsx("span",{className:"text-avatar px-1 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",title:t("models.overrideTitle"),children:t("models.overrideBadge")}),r.isGlobalDefault&&e.jsx("span",{className:"text-badge px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red font-medium",title:t("models.globalDefaultUnsettable"),children:t("chat.globalDefault")}),r.isActDefault&&!r.isGlobalDefault&&e.jsx("span",{className:"text-badge px-1.5 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",children:t("chat.actDefault")}),r.isGoalDefault&&e.jsx("span",{className:"text-badge px-1.5 py-0.5 rounded bg-accent-purple/20 text-accent-purple font-medium",children:t("chat.goalDefault")})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[e.jsx(_,{label:t("models.loadLabel"),value:`${r.load}/${r.maxLoad}`}),e.jsx(_,{label:t("models.tokenUsageLabel"),value:`${ce(r.tokens)}/${ce(r.maxTokens)}`}),e.jsx(_,{label:t("models.inputPrice"),value:`$${r.price.input}/M`}),e.jsx(_,{label:t("models.outputPrice"),value:`$${r.price.output}/M`})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[e.jsx(_,{label:t("models.inputTokensLabel"),value:ce(((m=r.usage)==null?void 0:m.input)??0)}),e.jsx(_,{label:t("models.outputTokensLabel"),value:ce(((b=r.usage)==null?void 0:b.output)??0)}),e.jsx(_,{label:t("models.totalTokensLabel"),value:ce(((I=r.usage)==null?void 0:I.total)??0)}),e.jsx(_,{label:t("models.usageRequestsLabel"),value:String(((z=r.usage)==null?void 0:z.requests)??0)})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[ot.map(p=>{const q=p.key==="global"?r.isGlobalDefault:r.isGoalDefault,h=p.key==="global"?t("models.setGlobalDefaultTitle"):t("models.setGoalDefaultTitle"),S=t("models.unsetGoalDefaultTitle"),x=t("models.unsetGoalDefaultFailed"),E=t("models.setGoalDefaultFailed");return q?p.key==="global"?e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded text-badge border ${p.bg} ${p.color} font-medium`,title:t("chat.globalDefault"),children:[e.jsx(se,{size:11}),t(p.labelKey)]},p.key):e.jsxs("button",{onClick:async()=>{try{await j.models.setDefaults({[p.key]:null}),await D()}catch(y){N(y instanceof Error?y.message:x)}},className:`inline-flex items-center gap-1 px-2 py-1 rounded text-badge border ${p.bg} ${p.color} font-medium cursor-pointer hover:opacity-80`,title:S,children:[e.jsx(se,{size:11}),t(p.labelKey)]},p.key):r.enabled===!1?null:e.jsx("button",{onClick:async()=>{try{await j.models.setDefaults({[p.key]:`${r.provider}:${r.id}`}),await D()}catch(y){N(y instanceof Error?y.message:E)}},className:"px-2 py-1 rounded text-badge border border-dark-border text-dark-muted hover:text-dark-text hover:border-dark-hover",title:h,children:t(p.labelKey)},p.key)}),e.jsx("button",{onClick:()=>Bs(r),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editModel"),children:e.jsx(ps,{size:13})}),e.jsx("button",{onClick:()=>Os(r.provider,r.id),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteModel"),children:e.jsx(ze,{size:13})}),e.jsx("button",{onClick:()=>Rs(r),disabled:Le===be(r),className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:t("models.refresh"),children:e.jsx(ne,{size:13,className:Le===be(r)?"animate-spin":""})}),e.jsx("button",{onClick:()=>Ls(r),className:`px-2 py-0.5 rounded text-xs transition-colors ${r.enabled===!1?"bg-accent-green/20 text-accent-green hover:bg-accent-green/30":"bg-accent-red/20 text-accent-red hover:bg-accent-red/30"}`,children:r.enabled===!1?t("models.enable"):t("models.disable")})]})]})},be(r))}),s.models.length===0&&e.jsx("div",{className:"text-center text-meta text-dark-muted py-3",children:t("models.noModelsInProvider")})]})]},s.provider)}),P.length===0&&$.length===0&&e.jsxs("div",{className:"text-center text-dark-muted py-6",children:[e.jsx(Ws,{size:36,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:t("models.emptyHint")})]})]})]}),e.jsx(fs,{isOpen:js,onClose:()=>{V(!1),W("select"),B(null),L("")},title:Oe==="select"?t("chat.selectProvider"):(ee==null?void 0:ee.name)||t("models.providerConfig"),size:"xl",children:Oe==="select"?e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[fe.filter(s=>s.key!=="custom").map(s=>e.jsxs("button",{onClick:()=>Je(s),className:"text-left p-3 rounded-lg border border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(se,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:s.name})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:s.defaultModel})]},s.key)),e.jsxs("button",{onClick:Ie,className:"text-left p-3 rounded-lg border border-dashed border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ys,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:t("models.customProvider")})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("models.customProviderDesc")})]})]})}):e.jsxs("div",{className:"space-y-3",children:[T==="custom"&&e.jsxs("div",{className:"space-y-3",children:[O&&O.keys.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.editExistingConfig")}),e.jsxs("select",{value:ks,onChange:s=>{const a=s.target.value;a?Ps(a):(L(""),f(l=>({...l,providerKey:"",modelIds:"",baseUrl:"",apiType:"",apiKeys:[""]})))},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:t("models.newCustomProviderOption")}),O.keys.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsx("div",{className:"text-meta text-dark-muted/60 mt-1",children:t("models.editExistingConfigHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.providerNameLabel")}),e.jsx("input",{value:i.providerKey,onChange:s=>f(a=>({...a,providerKey:s.target.value})),className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:t("models.providerNamePlaceholder")})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:["API Keys",(os=(rs=n==null?void 0:n.providers)==null?void 0:rs[T==="custom"?i.providerKey.trim():T||""])!=null&&os.hasApiKey?"":" *",e.jsx("span",{className:"text-dark-muted/60 text-xs",children:(ds=(ns=n==null?void 0:n.providers)==null?void 0:ns[T==="custom"?i.providerKey.trim():T||""])!=null&&ds.hasApiKey?t("models.apiKeysHintConfigured"):t("models.apiKeysHintNew")})]}),e.jsx("div",{className:"space-y-1.5",children:((cs=i.apiKeys)!=null&&cs.length?i.apiKeys:[""]).map((s,a)=>e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:Me?"text":"password",value:s,autoComplete:"off",spellCheck:!1,onChange:l=>f(d=>({...d,apiKeys:d.apiKeys.map((r,c)=>c===a?l.target.value:r)})),className:"w-full px-3 py-2 pr-9 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:t("models.apiKeyDefaultPlaceholder")}),e.jsx("button",{type:"button",onClick:()=>ae(l=>!l),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-dark-text",title:t(Me?"models.hideKeyTitle":"models.showKeyTitle"),children:Me?e.jsx(Qs,{size:14}):e.jsx(Js,{size:14})})]}),a===0?e.jsxs("button",{type:"button",onClick:()=>f(l=>({...l,apiKeys:[...l.apiKeys,""]})),className:"shrink-0 inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-dashed border-dark-border text-dark-muted hover:text-accent-blue hover:border-accent-blue/50 transition-colors",title:t("models.addApiKeyTitle"),children:[e.jsx(ke,{size:14}),e.jsx("span",{className:"hidden sm:inline",children:t("models.addApiKey")})]}):e.jsx("button",{type:"button",onClick:()=>f(l=>({...l,apiKeys:l.apiKeys.filter((d,r)=>r!==a)})),className:"shrink-0 inline-flex items-center px-3 py-2 rounded text-sm text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors",title:t("models.removeApiKeyTitle"),children:e.jsx(Fe,{size:14})})]},a))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.modelIdLabel")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i.modelIds,onChange:s=>{const a=s.target.value;f(l=>({...l,modelIds:a})),F(()=>{const l=new Set;for(const d of a.split(",")){const r=d.trim().split("|")[0].trim();r&&K.some(c=>c.id===r)&&l.add(r)}return l})},className:"flex-1 px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:(ee==null?void 0:ee.defaultModel)||t("models.modelIdPlaceholder")}),e.jsxs("button",{onClick:Ts,disabled:Ke||!i.baseUrl,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-blue/30 text-accent-blue hover:bg-accent-blue/10 disabled:opacity-50 whitespace-nowrap",title:t("models.fetchModelsTitle"),children:[Ke?e.jsx(ne,{size:13,className:"animate-spin"}):e.jsx(Xs,{size:13}),t(Ke?"models.fetchingModels":"models.fetchModels")]}),e.jsxs("button",{onClick:Ss,disabled:De||!i.baseUrl,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-yellow/30 text-accent-yellow hover:bg-accent-yellow/10 disabled:opacity-50 whitespace-nowrap",title:t("models.testConnectionTitle"),children:[De?e.jsx(ne,{size:13,className:"animate-spin"}):e.jsx(Zs,{size:13}),t(De?"models.testingConnection":"models.testConnection")]}),e.jsxs("button",{onClick:$s,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-green/30 text-accent-green hover:bg-accent-green/10 whitespace-nowrap",title:t("models.catalogSearchTitle"),children:[e.jsx(de,{size:13}),t("models.catalogSearch")]})]}),he&&e.jsxs("div",{className:`mt-1 text-xs ${he.ok?"text-accent-green":"text-accent-red"}`,children:[he.ok?"✓ ":"✗ ",he.message]}),_e&&e.jsx("div",{className:"mt-1 text-xs text-accent-red",children:_e}),K.length===0&&Ue.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.configuredPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:Ue.length}),t("models.configuredPanelSuffix"),e.jsx("span",{className:"text-accent-green/70",children:t("models.configuredPanelHint")})]})}),e.jsx("div",{className:"max-h-48 overflow-y-auto custom-scrollbar grid grid-cols-2 sm:grid-cols-3 gap-1",children:Ue.map(s=>{const a=i.modelIds.split(",").map(te).filter(Boolean).includes(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,title:s.name&&s.name!==s.id?`${s.id} — ${s.name}`:s.name||s.id,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>Ks(s),className:`flex items-start gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-green/20 text-accent-green border border-accent-green/30":"hover:bg-dark-hover border border-transparent"}`,children:[e.jsx("span",{className:"shrink-0 mt-[3px]",children:a?e.jsx(se,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"})}),e.jsx("span",{className:"min-w-0 flex-1 break-words leading-snug",children:s.name||s.id}),s.isGlobalDefault&&e.jsx("span",{className:"text-avatar px-1 rounded bg-accent-red/20 text-accent-red shrink-0",children:t("models.globalShort")}),s.isActDefault&&!s.isGlobalDefault&&e.jsx("span",{className:"text-avatar px-1 rounded bg-accent-yellow/20 shrink-0",children:"Act"}),s.isGoalDefault&&e.jsx("span",{className:"text-avatar px-1 rounded bg-accent-purple/20 shrink-0",children:"Goal"})]},s.id)})})]}),K.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.fetchedPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:K.length}),t("models.fetchedPanelMiddle"),e.jsx("strong",{className:"text-accent-blue",children:xe.size}),t("models.fetchedPanelSuffix"),e.jsx("span",{className:"text-accent-blue/70",children:t("models.fetchedPanelHint")})]}),e.jsx("button",{onClick:()=>{Y([]),F(new Set)},className:"px-2 py-0.5 text-badge border border-dark-border rounded hover:bg-dark-hover",children:t("models.close")})]}),e.jsxs("div",{className:"relative mb-2",children:[e.jsx(de,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:pe,onChange:s=>{const a=s.target.value;re(a),a.trim()&&Ve(!1)},className:"w-full pl-7 pr-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",placeholder:t("models.modelSearchPlaceholder")})]}),pe.trim()!==""&&e.jsxs("div",{className:"mb-1 text-badge text-dark-muted",children:[t("models.searchMatchPrefix"),e.jsx("strong",{className:"text-accent-blue",children:Ye.length}),t("models.searchMatchSuffix",{total:K.length})]}),e.jsx("div",{className:"max-h-72 overflow-y-auto custom-scrollbar grid grid-cols-1 sm:grid-cols-2 gap-1",children:Ye.map(s=>{const a=xe.has(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,title:s.name&&s.name!==s.id?`${s.id} — ${s.name}`:s.id,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>Ms(s.id),className:`${ws?"reveal-on-scroll ":""}flex items-start gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-blue/20 text-accent-blue border border-accent-blue/30":"hover:bg-dark-hover border border-transparent"}`,children:[e.jsx("span",{className:"shrink-0 mt-[3px]",children:a?e.jsx(se,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"})}),e.jsx("span",{className:"min-w-0 flex-1 break-all leading-snug",children:s.id})]},s.id)})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"Base URL"}),e.jsx("input",{value:i.baseUrl,onChange:s=>{f(a=>({...a,baseUrl:s.target.value})),G(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:"https://api.example.com/v1"}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none mt-2",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":i.fullPath,onClick:()=>{f(s=>({...s,fullPath:!s.fullPath})),G(null)},className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${i.fullPath?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${i.fullPath?"translate-x-[18px]":"translate-x-0.5"}`})}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.fullPathLabel")})]}),e.jsx("div",{className:"text-meta text-dark-muted/60 mt-1",children:t("models.fullPathHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.apiTypeLabel")}),e.jsxs("select",{value:i.apiType,onChange:s=>{f(a=>({...a,apiType:s.target.value})),G(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:t("models.apiTypeAutoDetect")}),gs.map(s=>e.jsx("option",{value:s,children:we[s]},s))]}),e.jsx("div",{className:"text-meta text-dark-muted/60 mt-1",children:t("models.apiTypeHint")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:[t("models.modelApiTypeLabel"),e.jsx("span",{className:"text-dark-muted/60 text-xs",children:t("models.modelApiTypeHint")})]}),e.jsx("div",{className:"border border-dark-border rounded-lg divide-y divide-dark-border max-h-40 overflow-y-auto custom-scrollbar",children:(()=>{const s=i.modelIds.split(",").map(te).filter(Boolean);return s.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t("models.modelApiTypeEmpty")}):s.map(a=>{var l;return e.jsxs("div",{className:"flex items-start justify-between gap-2 px-3 py-1.5",children:[e.jsx("span",{className:"text-xs min-w-0 flex-1 break-all leading-snug",title:a,children:a}),e.jsxs("select",{value:((l=i.modelOverrides[a])==null?void 0:l.apiType)||"",onChange:d=>f(r=>({...r,modelOverrides:{...r.modelOverrides,[a]:{...r.modelOverrides[a]||{},apiType:d.target.value}}})),className:"w-52 px-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:"继承 Provider(默认)"}),gs.map(d=>e.jsx("option",{value:d,children:we[d]},d))]})]},a)})})()})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:i.setDefault,onChange:s=>f(a=>({...a,setDefault:s.target.checked})),className:"accent-accent-blue"}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.setDefaultProvider")})]}),He&&e.jsx("div",{className:"text-sm text-accent-red",children:He}),e.jsxs("div",{className:"flex justify-between gap-2 pt-2",children:[e.jsx("div",{children:J&&((us=(is=n==null?void 0:n.providers)==null?void 0:is[J])==null?void 0:us.hasApiKey)&&e.jsx("button",{onClick:async()=>{if(confirm(t("models.deleteProviderConfirm",{key:J})))try{await j.config.provider.delete(J),V(!1),W("select"),B(null),L(""),await Q(),await D()}catch{}},className:"px-4 py-2 rounded border border-accent-red/30 text-accent-red hover:bg-accent-red/10 transition-colors text-sm",children:t("models.deleteProvider")})}),e.jsx("button",{onClick:()=>{W("select"),B(null),L(""),V(!1)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:t("common.cancel")}),e.jsx(bs,{variant:"accent",onClick:Hs,loading:Ns,children:t("common.save")})]})]})}),e.jsx(fs,{isOpen:Ds,onClose:()=>Xe(!1),title:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(de,{size:15,className:"text-accent-green"}),t("models.catalogTitle")]}),size:"2xl",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(de,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:Ae,onChange:s=>Es(s.target.value),className:"w-full pl-9 pr-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-green",placeholder:t("models.catalogSearchPlaceholder"),autoFocus:!0})]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:je,onChange:s=>{const a=s.target.checked;As(a),oe(Ae,{reason:ye,tool:a})},className:"accent-accent-green"}),t("models.catalogOnlyToolCall")]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:ye,onChange:s=>{const a=s.target.checked;Is(a),oe(Ae,{reason:a,tool:je})},className:"accent-accent-green"}),t("models.catalogOnlyReasoning")]})]}),ts&&e.jsx("div",{className:"text-xs text-accent-red bg-accent-red/10 p-2 rounded",children:ts}),Us?e.jsxs("div",{className:"flex items-center justify-center py-10 text-dark-muted",children:[e.jsx(ne,{size:18,className:"animate-spin mr-2"})," ",t("models.searching")]}):e.jsx("div",{className:"max-h-96 overflow-y-auto custom-scrollbar border border-dark-border rounded-lg divide-y divide-dark-border",children:es.length===0?e.jsx("div",{className:"py-10 text-center text-dark-muted text-sm",children:t("models.catalogNoResults")}):es.map(s=>{var a,l,d;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 hover:bg-dark-hover",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-dark-text truncate",children:s.model.name||s.model.id}),e.jsx("code",{className:"text-badge px-1.5 py-0.5 bg-dark-bg border border-dark-border rounded text-dark-muted truncate",children:s.model.id}),s.model.reasoning&&e.jsx("span",{className:"text-badge px-1.5 py-0.5 bg-accent-yellow/10 text-accent-yellow rounded",children:t("models.badgeReasoning")}),s.model.tool_call&&e.jsx("span",{className:"text-badge px-1.5 py-0.5 bg-accent-blue/10 text-accent-blue rounded",children:t("models.badgeToolCall")}),s.model.attachment&&e.jsx("span",{className:"text-badge px-1.5 py-0.5 bg-accent-green/10 text-accent-green rounded",children:t("models.badgeMultimodal")})]}),e.jsxs("div",{className:"text-meta text-dark-muted mt-0.5",children:[s.providerName,(a=s.model.limit)!=null&&a.context?` · ${t("models.ctxLimit",{k:(s.model.limit.context/1e3).toFixed(0)})}`:"",(l=s.model.limit)!=null&&l.output?` · ${t("models.outLimit",{k:(s.model.limit.output/1e3).toFixed(0)})}`:"",((d=s.model.cost)==null?void 0:d.input)!==void 0?` · $${s.model.cost.input}/M in / $${s.model.cost.output}/M out`:""]})]}),e.jsxs("button",{onClick:()=>Fs(s),className:"shrink-0 inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-accent-green/30 text-accent-green rounded hover:bg-accent-green/10 whitespace-nowrap",title:t("models.catalogAddTitle"),children:[e.jsx(ke,{size:12})," ",t("models.add")]})]},`${s.providerId}:${s.model.id}`)})}),e.jsx("div",{className:"text-meta text-dark-muted/60",children:t("models.catalogSourceHint")})]})})]})})}function Pe({title:k,value:v,color:C}){const t={green:"bg-accent-green/10 text-accent-green",yellow:"bg-accent-yellow/10 text-accent-yellow",red:"bg-accent-red/10 text-accent-red",blue:"bg-accent-blue/10 text-accent-blue"};return e.jsxs("div",{className:`${t[C]} rounded-lg p-3`,children:[e.jsx("div",{className:"text-xs opacity-70",children:k}),e.jsx("div",{className:"text-xl font-semibold",children:v})]})}function _({label:k,value:v}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-dark-muted",children:k}),e.jsx("div",{children:v})]})}export{bt as ModelsView,bt as default};
@@ -0,0 +1,2 @@
1
+ import{j as t}from"./markdown-BWXjRrSw.js";import{D as oe,a as s,A as ie,k as G,X as H,J as fe,q as ve,d as je,S as ye,ah as Ne,H as we,w as Ce,ab as Se,C as Ie}from"./icons-Bm_ZzSAy.js";import{u as K,j as N,C as $e}from"./index-CeeLdENM.js";import{S as Me}from"./Skeleton-Dsk6B0U3.js";import"./react-vendor-C0HIWSpf.js";import"./state-Kfon1nTr.js";import"./panels-BQOvnbWH.js";function ce(r){const l=r==="bundled"?"bg-accent-blue/15 text-accent-blue border-accent-blue":r==="npm"?"bg-accent-purple/15 text-accent-purple border-accent-purple":r==="local"?"bg-accent-blue/15 text-accent-blue border-accent-blue":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-meta border ${l}`,children:r})}function Pe(r){if(!r)return null;const l=r==="builtin"?"bg-dark-hover text-dark-muted border-dark-border":r==="openclaw"?"bg-accent-yellow/15 text-accent-yellow border-accent-yellow":r==="deepseek-harness"?"bg-accent-green/15 text-accent-green border-accent-green":r==="claude-mods"?"bg-accent-purple/15 text-accent-purple border-accent-purple":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-meta border ${l}`,children:r})}function Re({plugin:r,busy:l,busyAction:p,onInstall:d}){const{t:i}=K();return t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-compact font-medium text-dark-text truncate",children:r.name||r.id}),r.version&&t.jsx("span",{className:"text-meta text-dark-muted shrink-0",children:r.version}),ce(r.source),Pe(r.market),r.category&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-meta bg-dark-hover text-dark-muted border border-dark-border shrink-0",children:r.category}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-meta text-dark-muted font-mono shrink-0",children:r.id})]}),r.description&&t.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:r.description}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[t.jsxs("button",{onClick:()=>d(r.marketId??r.id,!0),disabled:l,className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-blue/20 border border-accent-blue/40 text-accent-blue text-meta hover:bg-accent-blue/30 disabled:opacity-50 transition-colors",children:[t.jsx(oe,{size:11})," ",l?`${p??"installing"}…`:i("plugins.installActivate")]}),t.jsxs("button",{onClick:()=>d(r.marketId??r.id,!1),disabled:l,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-meta hover:text-dark-text disabled:opacity-50 transition-colors",children:[t.jsx(oe,{size:11})," ",i("plugins.installOnly")]})]})]})}const Ee={queued:"queued",resolve:"resolve",fetch:"fetch",verify:"verify",load:"load",register:"register",activate:"activate",done:"done",error:"error"},Te={queued:"Queued",resolve:"Resolving market entry",fetch:"Downloading package",verify:"Verifying manifest",load:"Loading plugin",register:"Registering",activate:"Activating",done:"Done",error:"Failed"};function ze({job:r,error:l,onClose:p,onRetry:d}){const{t:i}=K(),f=s.useRef(null),v=r.status==="running",c=!!(r.status==="error"||l),w=Math.max(0,Math.min(100,r.progress??0)),j=u=>{const o=`plugins.installStages.${Ee[u]}`,m=i(o);return m===o?Te[u]:m};s.useEffect(()=>{const u=f.current;u&&(u.scrollTop=u.scrollHeight)},[r.logs.length]);const y=c?"bg-accent-red":r.status==="done"?"bg-accent-green":"bg-accent-blue";return t.jsxs("div",{className:"shrink-0 border-t border-dark-border bg-dark-surface",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[c?t.jsx(ie,{size:13,className:"text-accent-red shrink-0"}):r.status==="done"?t.jsx(G,{size:13,className:"text-accent-green shrink-0"}):t.jsx("div",{className:"w-3 h-3 border-2 border-accent-blue border-t-transparent rounded-full animate-spin shrink-0"}),t.jsx("span",{className:"text-compact text-dark-text truncate font-mono",children:r.marketId}),t.jsx("span",{className:"text-meta text-dark-muted shrink-0",children:r.alreadyInstalled&&v?i("plugins.installAlreadyInstalled"):j(r.stage)}),t.jsx("div",{className:"flex-1"}),t.jsxs("span",{className:"text-meta text-dark-muted tabular-nums shrink-0",children:[w,"%"]}),d&&c&&t.jsx("button",{onClick:d,className:"px-2 py-0.5 rounded border border-dark-border bg-dark-hover text-dark-muted text-meta hover:text-dark-text transition-colors",children:i("plugins.installRetry")}),t.jsx("button",{onClick:p,title:i("plugins.installClose"),className:"p-1 rounded text-dark-muted hover:text-dark-text transition-colors",children:t.jsx(H,{size:13})})]}),t.jsx("div",{className:"px-3 pb-2",children:t.jsx("div",{className:"h-1 rounded-full bg-dark-hover overflow-hidden",children:t.jsx("div",{className:`h-full ${y} transition-[width] duration-300 ease-out`,style:{width:`${w}%`}})})}),(r.error||l)&&t.jsx("div",{className:"mx-3 mb-2 px-2 py-1.5 rounded bg-accent-red/15 border border-accent-red text-accent-red text-meta break-words",children:r.error||l}),t.jsxs("details",{open:!0,className:"px-3 pb-2 group",children:[t.jsxs("summary",{className:"flex items-center gap-1 text-meta text-dark-muted cursor-pointer select-none hover:text-dark-text transition-colors",children:[t.jsx(fe,{size:12}),i("plugins.installLogs",{count:r.logs.length})]}),t.jsx("pre",{ref:f,className:"mt-1 max-h-40 overflow-auto rounded bg-dark-bg border border-dark-border px-2 py-1.5 text-meta font-mono text-dark-muted whitespace-pre-wrap break-all",children:r.logs.length?r.logs.join(`
2
+ `):i("plugins.installLogsEmpty")})]})]})}const Ae=700;function Le(){const[r,l]=s.useState(null),[p,d]=s.useState(null),[i,f]=s.useState(!1),v=s.useRef(null),c=s.useCallback(()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)},[]),w=s.useCallback(y=>{c();const u=async()=>{const o=await N.get(`/api/plugins/install/${encodeURIComponent(y)}`);if(!o.success||!o.data){d(o.error??"Lost install job"),c();return}l(o.data),o.data.status==="running"?v.current=window.setTimeout(u,Ae):c()};u()},[c]),j=s.useCallback(async(y,u)=>{var m;c(),d(null),f(!1);const o=await N.post("/api/plugins/install",{id:y,activate:u});if(!o.success){const C=o.error??"Install request failed";return d(C),{job:null,error:C}}return(m=o.data)!=null&&m.jobId?(l(o.data),w(o.data.jobId),{job:o.data,error:null}):{job:null,error:null}},[w,c]);return s.useEffect(()=>c,[c]),{job:r,error:p,dismissed:i,start:j,close:()=>f(!0)}}const J=12,Fe="other",Oe=["all","builtin","openclaw","deepseek-harness","claude-mods"];function qe(r){return r==="wired"?"bg-accent-green/15 text-accent-green border-accent-green":r==="pending"||r==="pending_wiring"?"bg-accent-yellow/15 text-accent-yellow border-accent-yellow":"bg-dark-hover text-dark-muted border-dark-border"}function de(r){var l;return((l=r.category)==null?void 0:l.trim())||Fe}function Be(r,l){const p=l.trim().toLowerCase();return p?[r.id,r.name,r.description,r.category,...r.tags??[]].filter(i=>typeof i=="string").join(" ").toLowerCase().includes(p):!0}function Ke(){var le;const{t:r}=K(),[l,p]=s.useState("installed"),[d,i]=s.useState([]),[f,v]=s.useState([]),[c,w]=s.useState(null),[j,y]=s.useState(!0),[u,o]=s.useState(null),[m,C]=s.useState(null),[L,E]=s.useState(null),[T,Q]=s.useState(null),[z,F]=s.useState(null),[Y,X]=s.useState(null),[M,Z]=s.useState(""),[S,ue]=s.useState(null),[g,W]=s.useState(null),[I,O]=s.useState(1),h=s.useCallback((e,a)=>{Q({kind:e,text:a}),window.setTimeout(()=>Q(null),4e3)},[]),k=s.useCallback(async()=>{y(!0),o(null);const[e,a]=await Promise.all([N.get("/api/plugins"),N.get("/api/plugins/market")]);e.success&&e.data?(i(e.data.plugins),w(e.data.schemaVersion??null)):o(e.error??"Failed to load plugins"),a.success&&a.data&&v(a.data.plugins),y(!1)},[]);s.useEffect(()=>{k()},[k]);const q=s.useMemo(()=>d.filter(e=>e.installable!==!0),[d]),$=s.useMemo(()=>[...d.filter(e=>e.installable===!0),...f.filter(e=>!d.some(a=>a.id===e.id||a.marketId===e.id))],[d,f]),A=s.useCallback(e=>e.filter(a=>S&&de(a)!==S||g&&(a.market??null)!==g?!1:Be(a,M)),[S,M,g]),P=s.useMemo(()=>A(q),[A,q]),R=s.useMemo(()=>A($),[A,$]),ee=s.useMemo(()=>{const e=new Set;for(const a of $)e.add(de(a));return["all",...Array.from(e).sort()]},[$]),B=s.useMemo(()=>{const e=new Set;for(const a of $)a.market&&e.add(a.market);return Oe.filter(a=>a==="all"||e.has(a))},[$]),te=e=>Math.max(1,Math.ceil(e/J)),re=(e,a)=>e.slice((a-1)*J,a*J),D=te(P.length),_=te(R.length),xe=s.useMemo(()=>re(P,Math.min(I,D)),[P,I,D]),me=s.useMemo(()=>re(R,Math.min(I,_)),[R,I,_]);s.useEffect(()=>{O(1)},[l,M,S,g]),s.useEffect(()=>{g!==null&&!B.includes(g)&&W(null)},[g,B]);const be=M.trim().length>0||S!==null||g!==null,U=s.useCallback(async(e,a,x)=>{C(e),E(a);try{const n=await x();n&&n.success===!1?h("err",String(n.error??"Request failed")):(h("ok",`${a} ${e} ✓`),await k())}catch(n){h("err",n instanceof Error?n.message:String(n))}finally{C(null),E(null)}},[k,h]),b=Le(),ae=async(e,a)=>{C(e),E("installing");const{job:x,error:n}=await b.start(e,a);if(C(null),E(null),!x){if(n)return h("err",n);h("ok",`installed ${e} ✓`),await k()}},V=(le=b.job)==null?void 0:le.status;s.useEffect(()=>{V&&V!=="running"&&k()},[V,k]);const pe=e=>U(e,"activated",()=>N.post(`/api/plugins/${encodeURIComponent(e)}/activate`)),ge=e=>U(e,"deactivated",()=>N.post(`/api/plugins/${encodeURIComponent(e)}/deactivate`)),he=e=>U(e,"uninstalled",()=>N.delete(`/api/plugins/${encodeURIComponent(e)}`)),ke=async e=>{X(e);try{const a=await N.post(`/api/plugins/l2/provider/${encodeURIComponent(e)}`);a.success&&a.data?(h("ok",`Provider ${a.data.applied} applied to config ✓`),await k()):h("err",a.error??"Apply failed")}catch(a){h("err",a instanceof Error?a.message:String(a))}finally{X(null)}},se=(e,a)=>a>1?t.jsxs("div",{className:"flex items-center justify-center gap-3 pt-3 pb-1 select-none",children:[t.jsxs("button",{onClick:()=>O(x=>Math.max(1,x-1)),disabled:I<=1,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-meta hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[t.jsx(Se,{size:12})," ",r("plugins.prevPage")]}),t.jsx("span",{className:"text-meta text-dark-muted",children:r("plugins.pageInfo",{page:Math.min(I,a),pages:a,count:e})}),t.jsxs("button",{onClick:()=>O(x=>Math.min(a,x+1)),disabled:I>=a,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-meta hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[r("plugins.nextPage")," ",t.jsx(Ie,{size:12})]})]}):null,ne=e=>t.jsx("div",{className:"mt-8 text-center text-xs text-dark-muted",children:be?r("plugins.noMatch"):e});return t.jsxs("div",{className:"h-full flex flex-col min-h-0 bg-dark-bg",children:[t.jsxs("div",{className:"h-11 flex items-center gap-2 px-3 border-b border-dark-border bg-dark-bg shrink-0 select-none",children:[t.jsx(ve,{size:15,className:"text-accent-blue"}),t.jsx("span",{className:"truncate text-compact font-medium text-dark-text",children:r("nav.plugins")}),c!==null&&t.jsxs("span",{className:"px-1.5 py-0.5 rounded text-badge bg-dark-hover text-dark-muted border border-dark-border",children:["schema v",c]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:()=>void k(),className:"p-1.5 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text transition-colors",title:"Refresh",children:t.jsx(je,{size:14,className:j?"animate-spin":""})})]}),t.jsx("div",{className:"flex items-center gap-1 px-3 pt-2 shrink-0",children:["installed","available"].map(e=>t.jsx("button",{onClick:()=>p(e),className:`px-3 py-1.5 rounded-t text-xs transition-colors ${l===e?"bg-dark-surface text-accent-blue border border-b-0 border-dark-border":"text-dark-muted hover:text-dark-text"}`,children:e==="installed"?r("plugins.installedTab",{count:q.length}):r("plugins.availableTab",{count:$.length})},e))}),t.jsxs("div",{className:"shrink-0 px-3 pt-2 pb-1 space-y-2 bg-dark-bg",children:[t.jsxs("div",{className:"relative",children:[t.jsx(ye,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted pointer-events-none"}),t.jsx("input",{value:M,onChange:e=>Z(e.target.value),placeholder:r("plugins.searchPlaceholder"),className:"w-full pl-8 pr-8 py-1.5 rounded bg-dark-hover border border-dark-border text-xs text-dark-text placeholder-dark-muted outline-none focus:border-accent-blue/50 transition-colors"}),M&&t.jsx("button",{onClick:()=>Z(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-dark-muted hover:text-dark-text transition-colors",title:r("plugins.clear"),children:t.jsx(H,{size:12})})]}),l==="available"&&ee.length>2&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:ee.map(e=>t.jsx("button",{onClick:()=>ue(e==="all"?null:e),className:`px-2 py-0.5 rounded-full text-meta border transition-colors ${e==="all"&&S===null||S===e?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:e==="all"?r("plugins.allCategories"):e},e))}),l==="available"&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:B.map(e=>{const a=e==="all"?r("plugins.marketFilterAll"):e==="builtin"?r("plugins.marketFilterBuiltin"):e;return t.jsx("button",{onClick:()=>W(e==="all"?null:e),className:`px-2 py-0.5 rounded-full text-meta border transition-colors ${e==="all"&&g===null||g===e?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:a},e)})})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-3 pb-4",children:[u&&t.jsxs("div",{className:"mt-3 flex items-center gap-2 px-3 py-2 rounded bg-accent-red/15 border border-accent-red text-accent-red text-xs",children:[t.jsx(ie,{size:14})," ",u]}),j&&!u&&t.jsx("div",{className:"mt-8 px-4",role:"status",children:t.jsx(Me,{count:4})}),!j&&l==="installed"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[P.length===0&&ne(r("plugins.emptyInstalled")),xe.map(e=>{const a=e.l2??[],x=e.status==="active";return t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-compact font-medium text-dark-text truncate",children:e.name||e.id}),e.version&&t.jsx("span",{className:"text-meta text-dark-muted shrink-0",children:e.version}),ce(e.source),t.jsx("span",{className:`px-1.5 py-0.5 rounded text-meta border shrink-0 ${x?"bg-accent-green/15 text-accent-green border-accent-green":"bg-dark-hover text-dark-muted border-dark-border"}`,children:x?"active":"installed"}),e.httpMounted&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-meta bg-accent-green/15 text-accent-green border border-accent-green shrink-0",children:"http mounted"}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-meta text-dark-muted font-mono shrink-0",children:e.id})]}),e.description&&t.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:e.description}),a.length>0&&t.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[a.map(n=>t.jsxs("span",{title:n.note||n.id,className:`px-1.5 py-0.5 rounded text-meta border cursor-help ${qe(n.status)}`,children:[n.kind," · ",n.status,n.status==="wired"&&t.jsx(G,{size:10,className:"inline ml-0.5"})]},`${n.kind}-${n.id}`)),a.filter(n=>n.kind==="provider"&&n.status==="wired").map(n=>t.jsx("button",{disabled:Y===n.id,onClick:()=>void ke(n.id),className:"px-1.5 py-0.5 rounded text-meta border border-accent-blue/40 text-accent-blue hover:bg-accent-blue/10 disabled:opacity-50 transition-colors",title:r("plugins.applyProviderTitle"),children:Y===n.id?"applying…":"apply provider"},`apply-${n.id}`))]}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[x?t.jsxs("button",{onClick:()=>void ge(e.id),disabled:m===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-yellow/15 border border-accent-yellow text-accent-yellow text-meta hover:bg-accent-yellow/15 disabled:opacity-50 transition-colors",children:[t.jsx(Ne,{size:11})," ",m===e.id?`${L}…`:r("plugins.deactivate")]}):t.jsxs("button",{onClick:()=>void pe(e.id),disabled:m===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-green/15 border border-accent-green text-accent-green text-meta hover:bg-accent-green/15 disabled:opacity-50 transition-colors",children:[t.jsx(we,{size:11})," ",m===e.id?`${L}…`:r("plugins.activate")]}),t.jsxs("button",{onClick:()=>F(e.id),disabled:m===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-meta hover:text-accent-red hover:border-accent-red disabled:opacity-50 transition-colors",children:[t.jsx(Ce,{size:11})," ",r("plugins.uninstall")]})]})]},e.id)}),se(P.length,D)]}),!j&&l==="available"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[R.length===0&&ne(r("plugins.emptyMarket")),me.map(e=>t.jsx(Re,{plugin:e,busy:m===e.id,busyAction:L,onInstall:(a,x)=>void ae(a,x)},e.id)),se(R.length,_)]})]}),b.job&&!b.dismissed&&t.jsx(ze,{job:b.job,error:b.error,onClose:b.close,onRetry:b.job.status==="error"&&b.job.marketId?()=>void ae(b.job.marketId,b.job.activate):void 0}),T&&t.jsxs("div",{className:`fixed bottom-4 right-4 z-50 flex items-center gap-2 px-3 py-2 rounded-lg border text-xs shadow-lg ${T.kind==="ok"?"bg-accent-green/15 border-accent-green text-accent-green":"bg-accent-red/15 border-accent-red text-accent-red"}`,children:[T.kind==="ok"?t.jsx(G,{size:13}):t.jsx(H,{size:13})," ",T.text]}),t.jsx($e,{isOpen:z!==null,title:r("plugins.uninstallTitle"),message:r("plugins.uninstallConfirm",{id:z??""}),onConfirm:()=>{z&&he(z),F(null)},onClose:()=>F(null)})]})}export{Ke as PluginsView};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-BWXjRrSw.js";import{a as d,V as ae,am as ee,a4 as re,B as te,f as ke,C as me,aq as xe,k as ye,X as ne,x as ve,ar as Ne,s as oe,as as we,at as Se,al as Ce,au as Pe,A as ue,P as Ee,ah as Ie,d as Me,av as Te,S as Re}from"./icons-Bm_ZzSAy.js";import{m as k,n as Ae,u as O,o as he,f as T,p as ze,q as z,E as De,v as Fe,x as Oe,y as ie,z as ce,a as Le,A as se,F as _e,t as I,G as He,H as Be,J as Ke,K as je,M as $e,B as le,T as qe,L as Ve,N as Ye,O as Qe,Q as Ge,r as Ue,R as Je}from"./index-CeeLdENM.js";import{C as We,I as Xe,D as Ze}from"./InputArea-BbHslX7b.js";import{D as et}from"./Drawer-CjAgqH3B.js";import"./react-vendor-C0HIWSpf.js";import"./state-Kfon1nTr.js";import"./panels-BQOvnbWH.js";import"./sttLanguages-C7kVulzY.js";import"./Skeleton-Dsk6B0U3.js";import"./VizCardsSkeleton-C_GaEfXd.js";function tt(x={}){const t=x.enabled!==!1,l=k(s=>s.projects),a=k(s=>s.total),c=k(s=>s.hidden),r=k(s=>s.detail),o=k(s=>s.detailLoading),i=k(s=>s.detailError),p=k(s=>s.query),j=k(s=>s.sort),n=k(s=>s.stale),m=k(s=>s.loading),g=k(s=>s.lastError),y=k(s=>s.disabled),b=k(s=>s.openProjectId),f=k(s=>s.refresh);d.useEffect(()=>{t&&k.getState().refresh()},[t]),d.useEffect(()=>{!t||!n||k.getState().scheduleRefresh()},[t,n]),d.useEffect(()=>{if(!t||typeof document>"u")return;const s=()=>{document.visibilityState==="visible"&&k.getState().refresh()};return document.addEventListener("visibilitychange",s),()=>document.removeEventListener("visibilitychange",s)},[t]);const C=new Set(c),h=Ae(l,j).filter(s=>!C.has(s.projectId));return{projects:h.filter(s=>s.rootExists),hiddenCount:l.length-h.length,total:a,detail:r,detailLoading:o,detailError:i,query:p,sort:j,stale:n,loading:m,lastError:g,disabled:y,openProjectId:b,setQuery:s=>k.getState().setQuery(s),setSort:s=>k.getState().setSort(s),openProject:s=>void k.getState().openProject(s),closeDetail:()=>k.getState().closeDetail(),enterProject:(s,S)=>k.getState().enterProject(s,S),backToProjectList:()=>k.getState().backToProjectList(),createProject:(s,S)=>k.getState().createProject(s,S),hideProject:s=>k.getState().hideProject(s),unhideAll:()=>k.getState().unhideAll(),probeEntry:()=>void k.getState().probeEntry(),refresh:()=>void f()}}const st={neutral:"border-dark-border bg-dark-hover/40 text-dark-muted",ok:"border-accent-green/30 bg-accent-green/10 text-accent-green",warn:"border-accent-yellow/40 bg-accent-yellow/10 text-accent-yellow"};function at(x){return x.threads.waiting>0?{tone:"waiting",live:!1}:x.threads.review>0?{tone:"review",live:!1}:x.threads.working>0||x.sessions.running>0?{tone:"working",live:!0}:{tone:"idle",live:!1}}function Y({tone:x="neutral",testid:t,title:l,children:a}){return e.jsx("span",{"data-testid":t,title:l,className:T("inline-flex shrink-0 items-center gap-0.5 rounded-full border px-1.5 py-px text-meta leading-4",st[x]),children:a})}function X({icon:x,label:t,hint:l,disabled:a,testid:c,onClick:r}){const o=a?`${t} — ${l??""}`:t;return e.jsx("button",{type:"button","aria-label":o,title:o,"data-testid":c,"data-disabled":a?"true":"false",disabled:a,onClick:i=>{i.stopPropagation(),r()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent",children:x})}const rt=d.memo(function({project:t,onOpen:l,onOpenFolder:a,onCopyRoot:c,onHide:r,now:o}){const{t:i}=O(),p=!t.rootExists,j=Object.values(t.threads).reduce((g,y)=>g+y,0),n=at(t),m=he(t.lastActivityAt,o,i);return e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>l(t.projectId),onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&g.target===g.currentTarget&&(g.preventDefault(),l(t.projectId))},className:T("group relative flex cursor-pointer items-center gap-2.5 rounded-lg border px-3 py-2 text-left transition-colors",p?"border-dashed border-dark-border/60 opacity-70":"border-dark-border hover:border-accent-blue/40 hover:bg-dark-hover/40"),"data-testid":`project-row-${t.projectId}`,"data-root-missing":p?"true":"false","data-status":n.tone,children:[e.jsx("span",{"aria-hidden":"true",className:"status-dot shrink-0","data-tone":n.tone,"data-live":n.live?"true":"false","data-testid":`project-status-${t.projectId}`}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-compact font-semibold text-dark-text",title:t.root,children:t.name}),e.jsx("span",{className:"shrink-0 rounded border border-dark-border px-1 py-px text-badge leading-4 text-dark-muted",children:i("projects.visibility")}),p&&e.jsx("span",{className:"shrink-0 text-badge text-accent-yellow",children:i("projects.rootMissing")})]}),e.jsx("span",{className:"mt-0.5 flex items-center gap-2 text-meta leading-tight text-dark-muted/70",children:e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:t.root,children:t.root})})]}),e.jsxs("span",{className:"hidden shrink-0 items-center gap-1.5 md:flex",children:[e.jsxs(Y,{testid:`project-sessions-${t.projectId}`,children:[i("projects.sessionCount",{count:t.sessions.total}),t.sessions.running>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-dark-muted/40","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"inline-flex items-center gap-0.5 text-accent-blue","data-testid":"project-running",children:i("projects.runningCount",{count:t.sessions.running})})]})]}),e.jsx(Y,{testid:`project-threads-${t.projectId}`,children:j>0?i("projects.threadCount",{count:j}):i("projects.noThreads")}),t.agentMd.present?e.jsx(Y,{tone:t.agentMd.truncated?"warn":"ok",testid:`project-agentmd-${t.projectId}`,title:t.agentMd.truncated?i("projects.agentMdTruncated",{bytes:t.agentMd.bytes??0}):i("projects.agentMdBytes",{bytes:t.agentMd.bytes??0}),children:t.agentMd.truncated?i("projects.agentMdTruncatedShort"):i("projects.agentMdReady")}):e.jsx(Y,{testid:`project-agentmd-${t.projectId}`,children:i("projects.agentMdAbsent")}),p&&e.jsx(Y,{tone:"warn",testid:`project-missing-${t.projectId}`,children:i("projects.rootMissingChip")})]}),m&&e.jsx("span",{className:"hidden shrink-0 font-mono text-meta tabular-nums text-dark-muted lg:block","data-testid":`project-activity-${t.projectId}`,children:m}),e.jsxs("span",{className:"flex shrink-0 items-center gap-0.5",onClick:g=>g.stopPropagation(),children:[e.jsx(X,{icon:e.jsx(ae,{size:13,"aria-hidden":"true"}),label:i("projects.openFolder"),hint:p?i("projects.openFolderDisabled"):void 0,disabled:p,testid:`project-open-folder-${t.projectId}`,onClick:()=>a(t.root)}),e.jsx(X,{icon:e.jsx(ee,{size:13,"aria-hidden":"true"}),label:i("projects.copyRoot"),testid:`project-copy-root-${t.projectId}`,onClick:()=>c(t.root)}),e.jsx(X,{icon:e.jsx(re,{size:13,"aria-hidden":"true"}),label:i(p?"projects.removeView":"projects.hide"),hint:i("projects.hideHint"),testid:`project-hide-${t.projectId}`,onClick:()=>r(t.projectId)})]})]})}),nt=["answer","thread","goal","handoff","approval","session"];function Z(x){return x!==null&&typeof x=="object"&&!Array.isArray(x)?x:null}function J(x){return typeof x=="string"&&x.trim()?x:void 0}function be(x){const t=Z(x);if(!t)return null;const l=t.kind;if(typeof l!="string"||!nt.includes(l))return null;const a=typeof t.reason=="string"?t.reason:"",c={kind:l,reason:a},r=Z(t.refs);if(r){const p={},j=J(r.goalId);if(j&&(p.goalId=j),Array.isArray(r.threadIds)){const m=r.threadIds.filter(g=>typeof g=="string"&&!!g);m.length&&(p.threadIds=m)}const n=J(r.projectKey);n&&(p.projectKey=n),Object.keys(p).length&&(c.refs=p)}const o=Z(t.suggest),i=o?J(o.title):void 0;if(i){const p=o?J(o.seed):void 0;c.suggest={title:i,...p?{seed:p}:{}}}return c}function ot(x){switch(x){case"thread":return"green";case"goal":return"purple";case"handoff":return"brand";case"approval":return"yellow";case"session":return"brand";case"answer":default:return"neutral"}}const fe=d.memo(function({route:t,root:l,onOpenThread:a,onOpenSession:c}){var v,E,L,H,K;const{t:r}=O(),o=ce(M=>M.rows),i=ce(M=>M.query),[p,j]=d.useState(!1),[n,m]=d.useState(null),[g,y]=d.useState(!1);if(t.kind==="session"&&!((v=t.suggest)!=null&&v.title))return e.jsx("span",{className:"mt-0.5 block text-meta text-dark-text-secondary",children:t.reason});const b=(L=(E=t.refs)==null?void 0:E.threadIds)==null?void 0:L[0],f=(H=t.refs)==null?void 0:H.goalId,C=(K=t.refs)==null?void 0:K.projectKey,h=Object.keys(o).length>0,P=!!b&&i===""&&h&&!o[b],s=!!b&&!!a&&!P,S=async()=>{var D,_,$;const M=(D=t.suggest)==null?void 0:D.title;if(!(!M||p)){j(!0),y(!1);try{const A=await Le.sessions.create(M,l);if(A.success&&A.data){const u=($=(_=t.suggest)==null?void 0:_.seed)==null?void 0:$.trim();u&&se.getState().setSessionInput(A.data.id,u),m(A.data.title||M),c==null||c(A.data.id,l,A.data.title||M)}else y(!0)}catch{y(!0)}finally{j(!1)}}};return e.jsxs("span",{className:"mt-1 block rounded-md border border-dark-border bg-dark-bg-tertiary/50 p-1.5","data-testid":"pm-route-card","data-route-kind":t.kind,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"status-pill","data-tone":ot(t.kind),"data-testid":"pm-route-kind",children:r(`projects.pmRouteKind.${t.kind}`)}),e.jsx("span",{className:"text-badge text-dark-text-secondary",children:r("projects.pmRouteTo")})]}),t.reason?e.jsx("span",{className:"mt-0.5 block text-meta text-dark-text-secondary",children:t.reason}):null,s?e.jsxs("button",{type:"button",onClick:()=>a==null?void 0:a(b),className:"mt-1 inline-flex items-center gap-1 rounded bg-dark-hover/50 px-1.5 py-0.5 text-meta text-dark-text-primary hover:bg-dark-hover","data-testid":"pm-route-open-thread",children:[r("projects.pmRouteOpenThread"),e.jsx("span",{className:"font-mono text-dark-text-secondary",children:b})]}):P?null:f?e.jsxs("span",{className:"mt-1 block font-mono text-badge text-dark-text-secondary","data-testid":"pm-route-goal-ref",children:[r("projects.pmRouteGoalRef"),": ",f]}):C?e.jsxs("span",{className:"mt-1 block font-mono text-badge text-dark-text-secondary","data-testid":"pm-route-project-ref",children:[r("projects.pmRouteProjectRef"),": ",C]}):null,t.kind==="session"?n?e.jsx("span",{className:"mt-1 block text-meta text-accent-green","data-testid":"pm-route-session-created",children:r("projects.pmRouteSessionCreated",{title:n})}):e.jsxs("span",{className:"mt-1 block",children:[e.jsx("button",{type:"button",onClick:()=>void S(),disabled:p,className:"inline-flex items-center gap-1 rounded bg-accent-green/15 px-2 py-0.5 text-meta text-accent-green hover:bg-accent-green/25 disabled:opacity-50","data-testid":"pm-route-create-session",children:r(p?"projects.pmRouteSessionCreating":"projects.pmRouteCreateSession")}),g?e.jsx("span",{className:"ml-1.5 text-badge text-accent-red","data-testid":"pm-route-create-failed",children:r("projects.pmRouteCreateFailed")}):null]}):null]})});function it(x,t,l){const a=x.fields,c=r=>typeof a[r]=="string"?a[r]:"";switch(x.type){case"pm_started":return e.jsx("span",{children:t("projects.pmStarted")});case"pm_stopped":return e.jsx("span",{children:t("projects.pmStopped")});case"pm_wakeup":{const r=c("reason"),o=c("summary");return e.jsxs("span",{children:[t("projects.pmWakeup"),r?e.jsxs("span",{className:"text-dark-text-secondary",children:[" · ",r]}):null,o?e.jsx("span",{className:"block text-dark-text-secondary",children:o}):null]})}case"pm_report":{const r=c("title"),o=c("progressSummary"),i=c("nextAction"),p=typeof a.approvalsPending=="number"?a.approvalsPending:0,j=be(a.route);return e.jsxs("span",{children:[r?e.jsx("span",{className:"font-medium",children:r}):e.jsx("span",{children:t("projects.pmReport")}),o?e.jsx("span",{className:"block text-dark-text-secondary",children:o}):null,i?e.jsxs("span",{className:"block text-dark-text-secondary",children:[t("projects.pmNextAction"),": ",i]}):null,p>0?e.jsxs("span",{className:"mt-0.5 inline-flex items-center gap-1 text-accent-yellow",children:[e.jsx(xe,{size:12,"aria-hidden":"true"})," ",p," ",t("projects.pmApprovalsPending")]}):null,j?e.jsx(fe,{route:j,root:l.root,onOpenThread:l.onOpenThread,onOpenSession:l.onOpenSession}):null]})}case"pm_approval_requested":return e.jsx("span",{children:t("projects.pmApprovalRequested")});case"pm_approval_resolved":return e.jsxs("span",{children:[t("projects.pmApprovalResolved"),c("decision")?e.jsxs("span",{className:"text-dark-text-secondary",children:[" · ",c("decision")]}):null]});default:return e.jsx("span",{children:x.type})}}const dt=d.memo(function({root:t,onOpenThread:l,onOpenSession:a,children:c}){const{t:r}=O(),o=d.useMemo(()=>ze(t)??"",[t]),i=z(s=>s.residentByProject[o]??!1),p=z(s=>s.activityByProject[o]??De),j=z(s=>Fe(s,o)),n=z(s=>s.resolveApproval),[m,g]=d.useState(!1),[y,b]=d.useState(!1);d.useEffect(()=>{o&&Oe(o)},[o]);const f=async()=>{if(!(!o||y)){b(!0);try{await ie(o,!i)}finally{b(!1)}}},C=p.slice(-20).reverse(),h=d.useMemo(()=>{if(m)return null;const s=p.slice(-20);for(let S=s.length-1;S>=0;S--){const v=s[S];if(!v||v.type!=="pm_report")continue;const E=be(v.fields.route);if(E)return E}return null},[p,m]),P=d.useMemo(()=>({root:t,onOpenThread:l,onOpenSession:a}),[t,l,a]);return e.jsxs("section",{"aria-label":r("projects.pmPanel"),className:"flex min-h-0 min-w-0 flex-1 flex-col border-b border-dark-border",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden px-3 py-2",children:[e.jsx(te,{size:14,"aria-hidden":"true",className:i?"text-accent-green":"text-dark-text-secondary"}),e.jsx("span",{className:"min-w-0 shrink truncate text-xs font-medium",children:r("projects.pmPanel")}),e.jsxs("span",{className:T("inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-badge",i?"bg-accent-green/15 text-accent-green":"bg-dark-bg-tertiary text-dark-text-secondary"),children:[e.jsx("span",{className:T("h-1.5 w-1.5 rounded-full",i?"bg-accent-green":"bg-dark-text-secondary"),"aria-hidden":"true"}),r(i?"projects.pmResident":"projects.pmOff")]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",onClick:f,disabled:y||!o,className:T("rounded px-2 py-0.5 text-meta transition-colors",i?"text-dark-text-secondary hover:bg-dark-bg-tertiary hover:text-dark-text-primary":"bg-accent-green/15 text-accent-green hover:bg-accent-green/25"),children:r(i?"projects.pmStop":"projects.pmStart")}),e.jsx("button",{type:"button",onClick:()=>g(s=>!s),"aria-expanded":m,"aria-label":r("projects.pmToggleTimeline"),className:"rounded p-1 text-dark-text-secondary hover:bg-dark-bg-tertiary hover:text-dark-text-primary",children:m?e.jsx(ke,{size:14,"aria-hidden":"true"}):e.jsx(me,{size:14,"aria-hidden":"true"})})]})]}),j.length>0&&e.jsx("ul",{className:"space-y-1.5 px-3 pb-2",children:j.map(s=>e.jsx("li",{className:"rounded-md border border-accent-yellow bg-accent-yellow/15 p-2",children:e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(xe,{size:13,"aria-hidden":"true",className:"mt-0.5 shrink-0 text-accent-yellow"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-xs font-medium text-dark-text-primary",children:s.title||s.requestedAction||r("projects.pmApprovalCard")}),s.summary?e.jsx("p",{className:"mt-0.5 line-clamp-3 text-meta text-dark-text-secondary",children:s.summary}):null,e.jsxs("div",{className:"mt-1.5 flex gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>void n(s.escalationId,"approve"),className:"inline-flex items-center gap-1 rounded bg-accent-green/15 px-2 py-0.5 text-meta text-accent-green hover:bg-accent-green/25",children:[e.jsx(ye,{size:11,"aria-hidden":"true"})," ",r("projects.pmApprove")]}),e.jsxs("button",{type:"button",onClick:()=>void n(s.escalationId,"reject"),className:"inline-flex items-center gap-1 rounded bg-accent-red/15 px-2 py-0.5 text-meta text-accent-red hover:bg-accent-red/15",children:[e.jsx(ne,{size:11,"aria-hidden":"true"})," ",r("projects.pmReject")]})]})]})]})},s.escalationId))}),h?e.jsx("div",{className:"px-3 pb-2",children:e.jsx(fe,{route:h,root:P.root,onOpenThread:P.onOpenThread,onOpenSession:P.onOpenSession})}):null,c?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:c}):null,m&&C.length>0&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx("ul",{className:"max-h-48 space-y-1.5 overflow-y-auto",children:C.map(s=>e.jsxs("li",{className:"flex items-start gap-1.5 text-xs",children:[s.type==="pm_report"?e.jsx(ve,{size:12,"aria-hidden":"true",className:"mt-0.5 shrink-0 text-accent-green"}):e.jsx("span",{className:"mt-1 h-1.5 w-1.5 shrink-0 rounded-full bg-dark-text-secondary","aria-hidden":"true"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-dark-text-primary",children:it(s,r,P)}),e.jsx("div",{className:"text-badge text-dark-text-secondary",children:he(s.at)})]})]},s.id))})})]})}),pe=[],ct={setActiveTab:()=>{},createNewSession:()=>{},clearMessages:()=>{},setTheme:()=>{},setLogs:()=>{},setUnreadLogs:()=>{}},lt=d.memo(function({projectId:t,root:l,sessionId:a,onOpenThread:c,onOpenSession:r,onLoadSession:o,slashOptions:i,onStop:p,onPause:j,onResume:n}){const{t:m}=O(),g=z(v=>v.managers),y=z(v=>v.fetchManagers),b=z(v=>v.residentByProject[t]??!1),f=k(v=>v.setFocusedPmSession);d.useEffect(()=>{y()},[y]);const C=d.useMemo(()=>{var v;return((v=g.find(E=>E.projectKey===t))==null?void 0:v.managerSessionIds)??[]},[g,t]),h=C.includes(a)?a:g.length>0?C[0]??null:a;d.useEffect(()=>(f(h),()=>f(null)),[h,f]),d.useEffect(()=>{h&&o&&o(h)},[h,o]);const P=se(v=>h?v.messagesBySession[h]??pe:pe),s=se(v=>h?v.generatingSessions.includes(h):!1),S=d.useCallback(async v=>{const E=v.trim();!E||!h||await _e(t,E,h)||I.error(m("projects.pmSendFailed"))},[t,h,m]);return e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-testid":"coordinator-pane",children:e.jsx(dt,{root:l,onOpenThread:c,onOpenSession:r,children:h?e.jsxs(e.Fragment,{children:[e.jsx(We,{messages:P,isGenerating:s,isPaused:!1,sessionId:h}),e.jsx(Xe,{sessionId:h,onSend:S,onStop:()=>p==null?void 0:p(h),onPause:()=>j==null?void 0:j(h),onResume:()=>n==null?void 0:n(h),slashOptions:i??ct,inputDisabled:!b,inputDisabledHint:m("projects.pmInputDisabled")})]}):e.jsx("div",{className:"flex flex-1 items-center justify-center px-6 text-center text-xs text-dark-muted",children:m("projects.coordinatorHint")})})})}),pt=d.memo(function({projectName:t,projectRoot:l,missing:a,levelLabel:c,onBack:r,onBackToSessions:o,onOpenFolder:i,onNewSessionHere:p,threadsOpen:j,onToggleThreads:n,settingsOpen:m,onToggleSettings:g,onOpenMore:y,moreItemsCount:b}){const{t:f}=O(),C=h=>{const P=h.currentTarget.getBoundingClientRect();y(P.left,P.bottom+4,He(b))};return e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-dark-border px-3 py-2.5",children:[e.jsx("button",{type:"button",onClick:r,className:"ui-icon-button",title:f("projects.back"),"aria-label":f("projects.back"),"data-testid":"project-detail-back",children:e.jsx(Ne,{size:15,"aria-hidden":"true"})}),e.jsxs("nav",{className:"min-w-0 flex items-baseline gap-1.5 text-sm",children:[e.jsx("button",{type:"button",onClick:r,className:"shrink-0 text-dark-muted transition-colors hover:text-dark-text",children:f("projects.title")}),e.jsx("span",{className:"shrink-0 text-dark-muted/50","aria-hidden":"true",children:"›"}),e.jsx("button",{type:"button",onClick:o,disabled:!o,className:T("min-w-0 truncate transition-colors",o?"text-dark-muted hover:text-dark-text":"cursor-default text-dark-text"),"data-testid":"project-detail-name",children:t}),e.jsx("span",{className:"shrink-0 text-dark-muted/50","aria-hidden":"true",children:"›"}),e.jsx("button",{type:"button",onClick:o,disabled:!o,className:T("min-w-0 truncate transition-colors",o?"text-dark-muted hover:text-dark-text":"cursor-default font-medium text-dark-text"),"data-testid":"project-detail-level",children:c})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[l&&e.jsx("span",{className:"hidden min-w-0 max-w-[240px] truncate font-mono text-meta text-dark-muted lg:block",title:l,"data-testid":"project-detail-root",children:l}),e.jsxs("button",{type:"button",onClick:i,disabled:a,className:"btn shrink-0 text-meta disabled:cursor-not-allowed disabled:opacity-50",title:a?f("projects.openFolderDisabled"):l,"data-testid":"project-detail-open-folder",children:[e.jsx(ae,{size:12,"aria-hidden":"true"}),f("projects.openFolder")]}),e.jsxs("button",{type:"button",onClick:p,disabled:a,className:"btn shrink-0 text-meta disabled:cursor-not-allowed disabled:opacity-50",title:f(a?"projects.newSessionDisabled":"projects.newSessionHere"),"data-testid":"project-detail-new-session-btn",children:[e.jsx(oe,{size:12,"aria-hidden":"true"}),f("projects.newSessionHere")]}),e.jsx("button",{type:"button",onClick:n,"aria-expanded":j,className:T("ui-icon-button",j&&"bg-accent-blue/10 text-accent-blue"),title:f("threads.title"),"aria-label":f("threads.title"),"data-testid":"project-detail-threads",children:e.jsx(we,{size:14,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:g,"aria-expanded":m,className:"ui-icon-button",title:f("projects.settings"),"aria-label":f("projects.settings"),"data-testid":"project-detail-settings",children:e.jsx(Se,{size:14,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:C,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),C(h))},className:"ui-icon-button",title:f("projects.moreActions"),"aria-label":f("projects.moreActions"),"aria-haspopup":"menu","data-testid":"project-detail-more",children:e.jsx(Ce,{size:14,"aria-hidden":"true"})})]})]})}),mt=d.memo(function({projectId:t,onOpenSession:l}){const{t:a}=O(),c=z(s=>s.managers),r=z(s=>s.fetchManagers),o=z(s=>s.residentByProject[t]??!1),[i,p]=d.useState(!1),[j,n]=d.useState(!1),[m,g]=d.useState(null);d.useEffect(()=>{r()},[r]);const y=d.useMemo(()=>c.find(s=>s.projectKey===t)??null,[c,t]),b=z(s=>s.managersLoaded),f=(y==null?void 0:y.managerSessionIds)??[],C=d.useCallback(async()=>{if(i)return;p(!0);const s=await Be(t);if(await r(),p(!1),!s){I.error(a("projects.pmCreateFailed"),5e3);return}l(s)},[i,t,r,l,a]),h=d.useCallback(async()=>{if(j)return;n(!0);const s=await ie(t,!0);await r(),n(!1),s?I.success(a("projects.pmEnableDone"),3e3):I.error(a("projects.pmEnableFailed"),5e3)},[j,t,r,a]),P=d.useCallback(async s=>{if(m||typeof window<"u"&&!window.confirm(a("projects.pmCloseSessionConfirm")))return;g(s);const S=await Ke(t,s);await r(),g(null),S?I.success(a("projects.pmCloseSessionDone"),3e3):I.error(a("projects.pmCloseSessionFailed"),5e3)},[m,t,r,a]);return e.jsxs("section",{className:"flex min-h-0 flex-1 flex-col","aria-label":a("projects.pmSessionList"),"data-testid":"pm-session-list",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[e.jsx(te,{size:14,className:T("shrink-0",o?"text-accent-green":"text-dark-muted"),"aria-hidden":"true"}),e.jsx("span",{className:"text-xs font-medium text-dark-text",children:a("projects.pmSessionList")}),e.jsx("span",{className:"rounded-full border border-dark-border bg-dark-hover/40 px-1.5 py-px text-badge leading-4 text-dark-muted","data-testid":"pm-session-count-pill",children:a("projects.pmSessionCount",{count:f.length})}),!o&&e.jsx("span",{className:"inline-flex items-center gap-1 rounded-full bg-dark-hover/70 px-1.5 py-px text-badge text-dark-muted","data-testid":"pm-session-resident-pill",children:a("projects.pmOff")}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[!o&&e.jsx("button",{type:"button",onClick:()=>void h(),disabled:j,className:"btn shrink-0 text-meta disabled:opacity-50","data-testid":"pm-session-enable",children:a("projects.pmEnable")}),e.jsxs("button",{type:"button",onClick:()=>void C(),disabled:i,className:"btn btn-primary shrink-0 text-meta disabled:opacity-50",title:a("projects.pmNewSession"),"data-testid":"pm-new-session",children:[e.jsx(oe,{size:12,"aria-hidden":"true"}),a("projects.pmNewSession")]})]})]}),e.jsx("p",{className:"shrink-0 px-3 pb-2 text-meta leading-relaxed text-dark-muted",children:a("projects.pmSessionListHint")}),e.jsx("div",{className:"board-ground min-h-0 flex-1 overflow-y-auto px-3 pb-3 custom-scrollbar",children:e.jsxs("div",{className:"mx-auto flex max-w-[980px] flex-col gap-1.5",children:[b&&f.length===0?e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface px-3 py-4 text-center","data-testid":"pm-session-empty",children:[e.jsx("p",{className:"text-xs text-dark-text",children:a("projects.emptyPmSessions")}),e.jsx("p",{className:"mt-1 text-meta leading-relaxed text-dark-muted",children:a("projects.emptyPmSessionsHint")})]}):null,f.map((s,S)=>{const v=S===0,E=!v;return e.jsxs("div",{className:"group relative",children:[e.jsxs("button",{type:"button",onClick:()=>l(s),className:T("flex w-full items-center gap-2.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-left transition-colors hover:border-accent-blue/40 hover:bg-dark-hover/30",E&&"pr-10"),"data-testid":"pm-session-row","data-session-id":s,children:[e.jsx(te,{size:13,"aria-hidden":"true",className:T("shrink-0",o?"text-accent-green":"text-dark-muted")}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-xs text-dark-text",children:je(f,s,a)}),v&&(y==null?void 0:y.isDuty)&&e.jsx("span",{className:"shrink-0",title:a("projects.managerBadgeDuty"),children:e.jsx(Pe,{size:11,"aria-hidden":"true",className:"text-accent-yellow"})})]}),e.jsx("span",{className:"mt-0.5 block truncate font-mono text-meta text-dark-muted/60",title:s,children:s})]}),!E&&e.jsx(me,{size:13,"aria-hidden":"true",className:"shrink-0 text-dark-muted opacity-0 transition-opacity group-hover:opacity-70"})]}),E&&e.jsx("button",{type:"button",onClick:()=>void P(s),disabled:m===s,"aria-label":a("projects.pmCloseSession"),title:a("projects.pmCloseSession"),className:T("absolute right-2 top-1/2 -translate-y-1/2 rounded p-1 transition-opacity","text-dark-muted hover:text-accent-red disabled:opacity-50",m===s?"opacity-100":"opacity-0 focus-visible:opacity-100 group-hover:opacity-100"),"data-testid":"pm-close-session","data-session-id":s,children:e.jsx(ne,{size:13,"aria-hidden":"true"})})]},s)})]})})]})}),xt=200;function ut({isOpen:x,onClose:t,projectId:l,currentName:a}){const{t:c}=O(),r=k(m=>m.renameProject),[o,i]=d.useState(a),[p,j]=d.useState(!1);d.useEffect(()=>{x&&(i(a),j(!1))},[x,a]);const n=async()=>{const m=o.trim();if(m===a.trim()){t();return}j(!0);const g=await r(l,m===""?null:m);if(j(!1),!g.ok){I.error(g.error,6e3);return}I.success(c("projects.renamed"),3e3),t()};return e.jsxs($e,{isOpen:x,onClose:t,title:c("projects.rename"),size:"sm",children:[e.jsx("label",{className:"mb-1 block text-meta text-dark-text",htmlFor:"project-rename-input",children:c("projects.renameLabel")}),e.jsx("input",{id:"project-rename-input",autoFocus:!0,value:o,maxLength:xt,placeholder:a,onChange:m=>i(m.target.value),onKeyDown:m=>{m.key==="Enter"&&!p&&n()},className:"w-full rounded-lg border border-dark-border bg-dark-bg px-3 py-2 font-mono text-meta text-dark-text outline-none focus:border-accent-blue","data-testid":"project-rename-input"}),e.jsx("p",{className:"mt-1.5 text-meta leading-relaxed text-dark-muted",children:c("projects.renameHint")}),e.jsxs("div",{className:"mt-5 flex justify-end gap-3",children:[e.jsx(le,{onClick:t,"data-testid":"project-rename-cancel",children:c("common.cancel")}),e.jsx(le,{variant:"accent",onClick:()=>void n(),loading:p,"data-testid":"project-rename-submit",children:c("common.confirm")})]})]})}const ht=d.memo(function({projectId:t,isOpen:l,onClose:a,selectedThreadId:c,onSelectThread:r,onOpenThreadSession:o}){const{t:i}=O();return e.jsx(et,{isOpen:l,onClose:a,title:i("threads.title"),size:"lg",children:c?e.jsx(qe,{threadId:c,onBack:()=>r(null),onOpenSession:o}):e.jsx(Ve,{workspaceId:t,onOpenThread:r})})}),jt=d.memo(function({projectId:t,onBack:l,onOpenFolder:a,onCopyRoot:c,onNewSessionHere:r,onOpenThreadSession:o,onOpenSession:i,onLoadSession:p,pmSlashOptions:j,onStopSession:n,onPauseSession:m,onResumeSession:g,onHide:y}){const{t:b}=O(),[f,C]=d.useState(!1),[h,P]=d.useState(!1),[s,S]=d.useState(null),[v,E]=d.useState(!1),{state:L,openAt:H,close:K}=Ye(),M=k(N=>N.detail),D=k(N=>N.openPmSessionId),_=k(N=>N.enterPmSession),$=k(N=>N.backToPmSessions),A=z(N=>N.managers);d.useEffect(()=>{k.getState().openProject(t)},[t]),d.useEffect(()=>{S(null),C(!1),P(!1)},[t]);const u=(M==null?void 0:M.project)??null,F=u?!u.rootExists:!1,B=!u||F,Q=d.useMemo(()=>{var q;if(!D)return b("projects.pmSessionList");const N=((q=A.find(V=>V.projectKey===t))==null?void 0:q.managerSessionIds)??[];return je(N,D,b)},[D,A,t,b]),G=d.useMemo(()=>{if(!u)return[];const N=[{kind:"item",id:"copy-root",label:b("projects.copyRoot"),icon:ee,onSelect:()=>c(u.root)}];return y&&N.push({kind:"item",id:"hide-view",label:b(F?"projects.removeView":"projects.hide"),icon:re,onSelect:()=>y(u.projectId)}),N},[u,F,c,y,b]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-testid":"project-detail",children:[e.jsx(pt,{projectName:(u==null?void 0:u.name)??t,projectRoot:u==null?void 0:u.root,missing:B,levelLabel:Q,onBack:l,onBackToSessions:D?$:void 0,onOpenFolder:()=>u&&a(u.root),onNewSessionHere:()=>u&&r(u.root),threadsOpen:v,onToggleThreads:()=>E(N=>!N),settingsOpen:f,onToggleSettings:()=>C(N=>!N),onOpenMore:(N,q,V)=>H(N,q,null,{height:V}),moreItemsCount:G.length}),F&&u&&e.jsxs("div",{className:"flex shrink-0 items-start gap-1.5 border-b border-accent-yellow/30 bg-accent-yellow/10 px-3 py-2 text-meta leading-relaxed text-accent-yellow","data-testid":"project-detail-missing",children:[e.jsx(ue,{size:12,className:"mt-[1px] shrink-0","aria-hidden":"true"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:b("projects.rootMissingTitle")}),u&&e.jsx("span",{className:"mx-1 font-mono",children:u.root}),e.jsx("br",{}),b("projects.rootMissingBody")]})]}),f&&u&&e.jsxs("div",{className:"shrink-0 space-y-1 border-b border-dark-border bg-dark-hover/20 px-3 py-2","data-testid":"project-settings",children:[e.jsx(W,{icon:e.jsx(ae,{size:12,"aria-hidden":"true"}),label:b("projects.openFolder"),hint:u.root,disabled:F,disabledHint:F?b("projects.openFolderDisabled"):void 0,onClick:()=>a(u.root),testId:"project-settings-open-folder"}),e.jsx(W,{icon:e.jsx(ee,{size:12,"aria-hidden":"true"}),label:b("projects.copyRoot"),hint:u.root,onClick:()=>c(u.root),testId:"project-settings-copy-root"}),e.jsx(W,{icon:e.jsx(Ee,{size:12,"aria-hidden":"true"}),label:b("projects.rename"),hint:u.name,onClick:()=>P(!0),testId:"project-settings-rename"}),e.jsx(W,{icon:e.jsx(oe,{size:12,"aria-hidden":"true"}),label:b("projects.newSessionHere"),disabled:F,disabledHint:F?b("projects.newSessionDisabled"):void 0,onClick:()=>u&&r(u.root),testId:"project-settings-new-session"})]}),e.jsx("div",{className:"mx-auto flex min-h-0 min-w-0 w-full max-w-[1040px] flex-1 flex-col",children:D?e.jsx(lt,{projectId:t,root:(u==null?void 0:u.root)??t,sessionId:D,onOpenThread:N=>{E(!0),S(N)},onOpenSession:i,onLoadSession:p,slashOptions:j,onStop:n,onPause:m,onResume:g}):e.jsx(mt,{projectId:t,onOpenSession:_})}),e.jsx(ht,{projectId:t,isOpen:v,onClose:()=>E(!1),selectedThreadId:s,onSelectThread:S,onOpenThreadSession:o}),e.jsx(Qe,{items:G,position:L?{x:L.x,y:L.y}:null,onClose:K,ariaLabel:b("projects.moreActions")}),u&&e.jsx(ut,{isOpen:h,onClose:()=>P(!1),projectId:u.projectId,currentName:u.name})]})});function W({icon:x,label:t,hint:l,disabled:a,disabledHint:c,onClick:r,testId:o}){return e.jsxs("button",{type:"button",onClick:r,disabled:a,className:T("flex w-full items-center gap-2 rounded px-1.5 py-1 text-left text-meta transition-colors",a?"cursor-not-allowed text-dark-muted/60":"text-dark-text hover:bg-dark-hover"),"data-testid":o,"data-disabled":a?"true":"false",title:a?c:l,children:[e.jsx("span",{className:"shrink-0",children:x}),e.jsx("span",{className:"shrink-0",children:t}),e.jsx("span",{className:"ml-auto min-w-0 truncate font-mono text-badge text-dark-muted/70",children:a?c:l})]})}const bt=250,It=d.memo(function({workspaceDir:t,onNewSessionHere:l,onOpenThreadSession:a,onOpenSession:c,onLoadSession:r,pmSlashOptions:o,onStopSession:i,onPauseSession:p,onResumeSession:j}){const{t:n}=O(),{projects:m,hiddenCount:g,query:y,sort:b,loading:f,lastError:C,disabled:h,setQuery:P,setSort:s,openProjectId:S,enterProject:v,backToProjectList:E,createProject:L,hideProject:H,unhideAll:K,refresh:M}=tt(),[D,_]=d.useState(!1),[$,A]=d.useState(!1),[u,F]=d.useState(y),B=d.useRef(null);d.useEffect(()=>{F(y)},[y]),d.useEffect(()=>()=>{B.current&&clearTimeout(B.current)},[]);const Q=w=>{F(w),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>P(w),bt)},[G,N]=d.useState(()=>Date.now());d.useEffect(()=>{const w=setInterval(()=>N(Date.now()),3e4);return()=>clearInterval(w)},[]);const q=d.useMemo(()=>Ge,[]),V=w=>{Je.openFolder(w).then(R=>{R.ok||I.error(R.error||n("projects.openFolderFailed"),5e3)})},de=w=>{var U;const R=(U=navigator.clipboard)==null?void 0:U.writeText(w);R&&R.then(()=>I.success(n("projects.copied"),2e3),()=>I.error(n("projects.copyFailed"),4e3))},ge=w=>{_(!1),A(!0),L(w).then(async R=>{if(!R.ok){A(!1),I.error(R.error,6e3);return}R.projectId&&v(R.projectId);const U=R.projectId?await ie(R.projectId,!0):!1;A(!1),U?I.success(n("projects.created"),3e3):I.error(n("projects.createdNoPm"),6e3)})};return h?e.jsx("div",{className:"flex h-full items-center justify-center p-6","data-testid":"projects-disabled",children:e.jsxs("div",{className:"max-w-md rounded-xl border border-dark-border bg-dark-surface p-4 text-center",children:[e.jsx(Ie,{size:18,className:"mx-auto text-dark-muted","aria-hidden":"true"}),e.jsx("p",{className:"mt-2 text-xs leading-relaxed text-dark-muted",children:n("projects.disabled")})]})}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-testid":"projects-view",children:[S?e.jsx(jt,{projectId:S,onBack:E,onOpenFolder:V,onCopyRoot:de,onNewSessionHere:l,onOpenThreadSession:a,onOpenSession:c,onLoadSession:r,pmSlashOptions:o,onStopSession:i,onPauseSession:p,onResumeSession:j,onHide:w=>{H(w),I.info(n("projects.hiddenToast"),4e3),E()}}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-dark-border px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium text-dark-text",children:n("projects.title")}),e.jsx("span",{className:"rounded-full border border-dark-border bg-dark-hover/40 px-1.5 py-px text-badge leading-4 text-dark-muted","data-testid":"projects-count-pill",children:n("projects.projectCount",{count:m.length})}),e.jsx("div",{className:"ml-1 flex items-center rounded-md bg-dark-hover/60 p-0.5",role:"group",children:q.map(w=>e.jsx("button",{type:"button",onClick:()=>s(w),"aria-pressed":b===w,className:T("shrink-0 rounded px-1.5 py-0.5 text-meta transition-colors",b===w?"bg-dark-surface text-dark-text":"text-dark-muted hover:text-dark-text"),"data-testid":`projects-sort-${w}`,children:n(`projects.sort.${w}`)},w))}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:M,disabled:f,className:"ui-icon-button disabled:opacity-50",title:n("common.refresh"),"aria-label":n("common.refresh"),"data-testid":"projects-refresh",children:e.jsx(Me,{size:14,className:T(f&&"animate-spin"),"aria-hidden":"true"})}),e.jsxs("button",{type:"button",onClick:()=>_(!0),disabled:$,className:"btn btn-primary shrink-0 text-meta disabled:opacity-60",title:n("projects.newHint"),"data-testid":"projects-new",children:[e.jsx(Te,{size:13,"aria-hidden":"true"}),n("projects.new")]})]})]}),C&&e.jsx("div",{className:"shrink-0 px-3 pt-2","data-testid":"projects-status-banner",children:e.jsxs("div",{className:"flex items-start gap-1.5 rounded-lg border border-accent-red/40 bg-accent-red/10 px-2 py-1.5 text-meta leading-relaxed text-accent-red",children:[e.jsx(ue,{size:12,className:"mt-[1px] shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1",children:n("projects.loadFailed",{message:C})}),e.jsx("button",{type:"button",onClick:M,className:"shrink-0 underline hover:no-underline","data-testid":"projects-retry",children:n("projects.retry")})]})}),g>0&&e.jsx("div",{className:"shrink-0 px-3 pt-2","data-testid":"projects-hidden-banner",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-hover/40 px-2 py-1.5 text-meta text-dark-muted",children:[e.jsx(re,{size:11,className:"shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1",children:n("projects.hiddenCount",{count:g})}),e.jsx("button",{type:"button",onClick:K,className:"shrink-0 underline hover:no-underline","data-testid":"projects-unhide-all",children:n("projects.unhideAll")})]})}),e.jsx("div",{className:"board-ground min-h-0 flex-1 overflow-y-auto px-3 py-3 custom-scrollbar",children:e.jsxs("div",{className:"mx-auto flex max-w-[980px] flex-col",children:[e.jsx("h1",{className:"text-lg font-semibold text-dark-text",children:n("projects.title")}),e.jsx("p",{className:"mt-0.5 text-xs leading-relaxed text-dark-muted",children:n("projects.subtitle")}),e.jsxs("div",{className:"mt-4 flex items-center gap-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 transition-colors focus-within:border-accent-blue/50",children:[e.jsx(Re,{size:13,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsx("input",{type:"text",value:u,onChange:w=>Q(w.target.value),placeholder:n("projects.searchPlaceholder"),"aria-label":n("projects.searchPlaceholder"),"data-testid":"projects-search",className:"min-w-0 flex-1 bg-transparent text-xs text-dark-text placeholder:text-dark-muted focus:outline-none"}),u&&e.jsx("button",{type:"button",onClick:()=>Q(""),className:"shrink-0 rounded p-0.5 text-dark-muted transition-colors hover:text-dark-text","aria-label":n("projects.searchClear"),"data-testid":"projects-search-clear",children:e.jsx(ne,{size:12,"aria-hidden":"true"})}),e.jsx("span",{className:"shrink-0 text-badge text-dark-muted/70",children:n("projects.serverFilterHint")})]}),m.length===0?y.trim()?e.jsxs("div",{className:"mt-6 rounded-xl border border-dashed border-dark-border/60 py-8 text-center","data-testid":"projects-search-empty",children:[e.jsx("p",{className:"text-xs text-dark-text",children:n("projects.searchEmpty")}),e.jsx("p",{className:"mt-1 text-meta leading-relaxed text-dark-muted",children:n("projects.searchEmptyHint",{q:y.trim()})})]}):e.jsxs("div",{className:"mt-6 rounded-xl border border-dashed border-dark-border/60 py-8 text-center","data-testid":"projects-empty",children:[e.jsx("p",{className:"text-xs text-dark-text",children:n("projects.empty")}),e.jsx("p",{className:"mt-1 text-meta leading-relaxed text-dark-muted",children:n("projects.emptyHint")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-2 mt-5 flex items-center gap-2 text-badge font-semibold uppercase tracking-wide text-dark-muted/60",children:[e.jsx("span",{className:"shrink-0",children:n("projects.yourProjects")}),e.jsx("span",{className:"h-px flex-1 bg-dark-border/60","aria-hidden":"true"})]}),e.jsx("div",{className:"flex flex-col gap-1.5","data-testid":"projects-list",children:m.map(w=>e.jsx(rt,{project:w,onOpen:v,onOpenFolder:V,onCopyRoot:de,onHide:R=>{H(R),I.info(n("projects.hiddenToast"),4e3)},now:G},w.projectId))})]})]})})]}),D&&Ue.createPortal(e.jsx(Ze,{initial:t||"",onClose:()=>_(!1),onConfirm:ge}),document.body)]})});export{It as ProjectsView};