pikiclaw 0.3.39 → 0.3.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dashboard/dist/assets/{AgentTab-DmKQYVz1.js → AgentTab-BFG_wBIC.js} +1 -1
- package/dashboard/dist/assets/{BrandIcon-KSnFdk62.js → BrandIcon-CmIkwB4h.js} +1 -1
- package/dashboard/dist/assets/{DirBrowser-BqA8ssEC.js → DirBrowser-BzqSOCzY.js} +1 -1
- package/dashboard/dist/assets/{ExtensionsTab-B86en9KI.js → ExtensionsTab-GyHiQaZK.js} +1 -1
- package/dashboard/dist/assets/{IMAccessTab-6L_l5Y5A.js → IMAccessTab-CO_5ztrR.js} +1 -1
- package/dashboard/dist/assets/{Modal-Dk3jQZ_G.js → Modal-Cx6r2XJQ.js} +1 -1
- package/dashboard/dist/assets/{Modals-BoS_lRW5.js → Modals-BnORfmhY.js} +1 -1
- package/dashboard/dist/assets/{Select-CCtTUA2O.js → Select-DLAvmM_i.js} +1 -1
- package/dashboard/dist/assets/{SessionPanel-DA6GsYqZ.js → SessionPanel-D2kHNUr3.js} +1 -1
- package/dashboard/dist/assets/{SystemTab-BQV-kjCS.js → SystemTab-BkgF1WI4.js} +1 -1
- package/dashboard/dist/assets/index-B_sC2ppg.js +5 -0
- package/dashboard/dist/assets/index-DZy1Xu_H.js +19 -0
- package/dashboard/dist/assets/{shared-CVa9npgA.js → shared-C-0W57w0.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dist/agent/drivers/claude.js +57 -0
- package/dist/agent/drivers/codex.js +7 -1
- package/dist/agent/handover.js +130 -0
- package/dist/agent/index.js +3 -1
- package/dist/agent/session.js +25 -11
- package/dist/bot/bot.js +146 -66
- package/dist/bot/commands.js +24 -4
- package/dist/dashboard/routes/sessions.js +8 -2
- package/dist/dashboard/session-control.js +104 -2
- package/package.json +1 -1
- package/dashboard/dist/assets/index-BS_RBT-T.js +0 -5
- package/dashboard/dist/assets/index-C-Dh421o.js +0 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as o,j as e}from"./react-vendor-DTcmqLiz.js";import{u as G,T as fe,m as ge,c as B,a as _,o as Q,S as P,B as z}from"./index-BS_RBT-T.js";import{B as ve}from"./BrandIcon-KSnFdk62.js";import{M as q,a as K,I as T}from"./Modal-Dk3jQZ_G.js";import"./router-Cav8lq-m.js";function a(t,s,n){return t==="zh-CN"?s:n}function le(t,s){return s.type==="mcp-oauth"?a(t,"OAuth","OAuth"):s.type==="credentials"?a(t,"API Key","API Key"):a(t,"无需配置","No auth")}const je={github:{hex:"#24292f",letter:"GH"},atlassian:{hex:"#0052cc",letter:"A"},notion:{hex:"#111827",letter:"N"},linear:{hex:"#5e6ad2",letter:"L"},sentry:{hex:"#362d59",letter:"S"},cloudflare:{hex:"#f6821f",letter:"CF"},gamma:{hex:"#9f2eff",letter:"G"},huggingface:{hex:"#ff9d00",letter:"HF"},slack:{hex:"#4a154b",letter:"S"},lark:{hex:"#00d6b9",letter:"L"},feishu:{hex:"#00d6b9",letter:"F"},stripe:{hex:"#635bff",letter:"S"},perplexity:{hex:"#20b8cd",letter:"P"},brave:{hex:"#fb542b",letter:"B"},filesystem:{hex:"#64748b",letter:"FS"},fetch:{hex:"#0ea5e9",letter:"F"},memory:{hex:"#a855f7",letter:"M"},time:{hex:"#10b981",letter:"T"},sqlite:{hex:"#0369a1",letter:"SQ"},postgres:{hex:"#336791",letter:"PG"}},be={hex:"#6b7280"};function W(t,s){const n=(t||"").toLowerCase(),i=je[n]||be,l=i.letter||(s||"").replace(/[^a-zA-Z0-9]/g,"").slice(0,2).toUpperCase()||"?";return{hex:i.hex,letter:l}}function E(t,s){const n=t.replace("#",""),i=n.length===3?n.split("").map(u=>u+u).join(""):n.padEnd(6,"0").slice(0,6),l=parseInt(i.slice(0,2),16),c=parseInt(i.slice(2,4),16),x=parseInt(i.slice(4,6),16);return`rgba(${l}, ${c}, ${x}, ${s})`}function X(t,s,n=[]){const[i,l]=o.useState(()=>{try{const p=localStorage.getItem(t);return p?JSON.parse(p):null}catch{return null}}),[c,x]=o.useState(!1),u=o.useRef(!0);o.useEffect(()=>()=>{u.current=!1},[]);const h=o.useCallback(async()=>{x(!0);try{const p=await s();if(!u.current)return;l(p);try{localStorage.setItem(t,JSON.stringify(p))}catch{}}finally{u.current&&x(!1)}},[t,...n]);return o.useEffect(()=>{h()},[h]),{data:i,loading:c,refresh:h}}const U=()=>e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),Z=({size:t=12})=>e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),ye=({size:t=12})=>e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18.36 6.64a9 9 0 1 1-12.73 0"}),e.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"12"})]}),ie=({size:t=12})=>e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),Ne=({size:t=12})=>e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),oe=new Set(["claude","codex","gemini","telegram","feishu","weixin","playwright","vscode","cursor","windsurf","finder"]),ke={github:"logos:github-icon",atlassian:"logos:atlassian",notion:"logos:notion-icon",linear:"logos:linear-icon",sentry:"logos:sentry-icon",cloudflare:"logos:cloudflare-icon","cloudflare-docs":"logos:cloudflare-icon","cloudflare-bindings":"logos:cloudflare-icon","cloudflare-observability":"logos:cloudflare-icon",slack:"logos:slack-icon",lark:"icon-park:lark",feishu:"icon-park:lark",stripe:"logos:stripe",perplexity:"logos:perplexity-icon",brave:"logos:brave","brave-search":"logos:brave",huggingface:"logos:hugging-face-icon",postgres:"logos:postgresql",postgresql:"logos:postgresql",sqlite:"logos:sqlite",vercel:"logos:vercel-icon",netlify:"logos:netlify-icon",supabase:"logos:supabase-icon",heroku:"logos:heroku-icon",docker:"logos:docker-icon",pnpm:"logos:pnpm",aws:"logos:aws","google-cloud":"logos:google-cloud",googlecloud:"logos:google-cloud",amazonwebservices:"logos:aws"},we=new Set(["stripe"]);function Ce(t,s){if(s)return s;if(!t||oe.has(t))return;const n=ke[t];if(n)return`https://api.iconify.design/${n}.svg`}function F({iconSlug:t,iconUrl:s,name:n,size:i=32,className:l}){const{hex:c,letter:x}=W(t,n),[u,h]=o.useState(!1),p=Ce(t,s),b=t&&oe.has(t),d=b||!!p&&!u,v=!!t&&we.has(t),m=Math.round(i*(v?.92:.76));return d?e.jsxs("div",{className:B("relative flex shrink-0 items-center justify-center overflow-hidden rounded-xl bg-white",l),style:{width:i,height:i,boxShadow:`0 0 0 1px ${E(c,.18)}, 0 4px 12px ${E(c,.14)}`},children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{background:`linear-gradient(135deg, ${E(c,.06)} 0%, transparent 70%)`}}),b?e.jsx(ve,{brand:t,size:m}):e.jsx("img",{src:p,alt:"",width:m,height:m,loading:"lazy",decoding:"async",onError:()=>h(!0),className:"relative"})]}):e.jsxs("div",{className:B("relative flex shrink-0 items-center justify-center overflow-hidden rounded-xl font-semibold text-white",l),style:{width:i,height:i,background:`linear-gradient(135deg, ${E(c,1)} 0%, ${E(c,.82)} 100%)`,boxShadow:`0 1px 0 rgba(255,255,255,0.08) inset, 0 6px 14px ${E(c,.28)}`,fontSize:Math.max(10,Math.round(i*.36)),letterSpacing:x.length>1?"-0.02em":0},children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{background:"radial-gradient(circle at 30% 20%, rgba(255,255,255,0.22), transparent 55%)"}}),e.jsx("span",{className:"relative",children:x})]})}function Se({state:t,locale:s}){return t==="ready"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-ok)]",style:{background:"color-mix(in oklab, var(--th-ok) 12%, transparent)"},children:[e.jsx(Z,{size:10}),a(s,"已连接","Connected")]}):t==="disabled"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-edge bg-inset/60 px-2 py-0.5 text-[10px] font-medium text-fg-5",children:[e.jsx(ye,{size:10}),a(s,"已停用","Paused")]}):t==="needs_auth"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-warn)]",style:{background:"color-mix(in oklab, var(--th-warn) 12%, transparent)"},children:[e.jsx(ie,{size:10}),a(s,"待授权","Needs auth")]}):t==="unhealthy"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-err)]",style:{background:"color-mix(in oklab, var(--th-err) 12%, transparent)"},children:[e.jsx(Ne,{size:10}),a(s,"异常","Unhealthy")]}):null}function Ie({open:t,onClose:s,locale:n,item:i,initial:l,onSubmit:c}){const[x,u]=o.useState({}),[h,p]=o.useState(!1);if(o.useEffect(()=>{if(t&&i&&i.auth.type==="credentials"){const d={};for(const v of i.auth.fields)d[v.key]=l?.[v.key]||"";u(d)}},[t,i,l]),!i||i.auth.type!=="credentials")return null;const b=i.auth.fields.some(d=>d.required&&!(x[d.key]||"").trim()),y=async()=>{p(!0);try{await c(x)}finally{p(!1)}};return e.jsxs(q,{open:t,onClose:s,children:[e.jsx(K,{title:a(n,`配置 ${i.name}`,`Configure ${i.name}`),description:n==="zh-CN"?i.descriptionZh:i.description,onClose:s}),e.jsxs("div",{className:"space-y-3",children:[i.auth.fields.map(d=>e.jsxs("div",{children:[e.jsxs("label",{className:"mb-1 flex items-center justify-between",children:[e.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:[n==="zh-CN"?d.labelZh:d.label,d.required&&e.jsx("span",{className:"ml-1 text-err",children:"*"})]}),d.helpUrl&&e.jsxs("a",{href:d.helpUrl,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-[11px] text-primary hover:text-primary/80",children:[a(n,"获取","Get one")," ",e.jsx(U,{})]})]}),e.jsx(T,{value:x[d.key]||"",onChange:v=>u({...x,[d.key]:v.target.value}),type:d.secret?"password":"text",placeholder:d.placeholder,className:"font-mono text-[12px]"})]},d.key)),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-edge pt-3",children:[e.jsx(z,{variant:"ghost",onClick:s,children:a(n,"取消","Cancel")}),e.jsx(z,{variant:"primary",disabled:h||b,onClick:y,children:h?e.jsx(P,{}):a(n,"保存并启用","Save & Enable")})]})]})]})}function ze({open:t,onClose:s,locale:n,scope:i,workdir:l,onAdded:c}){const x=G(f=>f.toast),[u,h]=o.useState(""),[p,b]=o.useState("stdio"),[y,d]=o.useState("npx"),[v,m]=o.useState(""),[S,$]=o.useState(""),[A,I]=o.useState([]),[L,j]=o.useState(!1);o.useEffect(()=>{t&&(h(""),b("stdio"),d("npx"),m(""),$(""),I([]))},[t]);const w=async()=>{if(u.trim()){j(!0);try{const f={};for(const{k:C,v:M}of A)C.trim()&&(f[C.trim()]=M);const N=p==="http"?{type:"http",url:S.trim(),enabled:!0,...Object.keys(f).length?{headers:f}:{}}:{type:"stdio",command:y.trim(),args:v.trim()?v.trim().split(/\s+/):[],enabled:!0,...Object.keys(f).length?{env:f}:{}};await _.addCustomMcp(u.trim(),N,i,l),x(a(n,`${u} 已添加`,`${u} added`),!0),c(),s()}catch(f){x(f?.message||"Failed",!1)}finally{j(!1)}}};return e.jsxs(q,{open:t,onClose:s,wide:!0,children:[e.jsx(K,{title:a(n,"添加自定义 MCP 服务","Add Custom MCP Server"),description:a(n,"不在推荐列表中的自定义服务。","For servers not in the recommended catalog."),onClose:s}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"名称","Name")}),e.jsx(T,{value:u,onChange:f=>h(f.target.value),placeholder:"my-server"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"传输","Transport")}),e.jsx("div",{className:"flex gap-1.5",children:["stdio","http"].map(f=>e.jsx("button",{onClick:()=>b(f),className:B("flex-1 rounded-md border px-3 py-1.5 text-[12px] font-medium transition-colors",p===f?"border-primary/40 bg-primary/10 text-primary":"border-edge bg-inset/50 text-fg-4 hover:bg-inset"),children:f},f))})]})]}),p==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"命令","Command")}),e.jsx(T,{value:y,onChange:f=>d(f.target.value),className:"font-mono",placeholder:"npx"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"参数","Arguments")}),e.jsx(T,{value:v,onChange:f=>m(f.target.value),className:"font-mono",placeholder:"-y @example/server"})]})]}):e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:"URL"}),e.jsx(T,{value:S,onChange:f=>$(f.target.value),className:"font-mono",placeholder:"https://example.com/mcp"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:p==="http"?a(n,"Headers","Headers"):a(n,"环境变量","Env")}),e.jsxs("button",{className:"text-[11px] font-medium text-primary hover:text-primary/80",onClick:()=>I([...A,{k:"",v:""}]),children:["+ ",a(n,"添加","Add")]})]}),A.length>0&&e.jsx("div",{className:"space-y-1 rounded-md border border-edge bg-inset/40 p-2",children:A.map((f,N)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(T,{className:"w-2/5 !h-7 !text-[12px] font-mono",value:f.k,onChange:C=>{const M=[...A];M[N]={...M[N],k:C.target.value},I(M)},placeholder:"KEY"}),e.jsx(T,{className:"flex-1 !h-7 !text-[12px] font-mono",value:f.v,onChange:C=>{const M=[...A];M[N]={...M[N],v:C.target.value},I(M)},type:/token|secret|key|bearer/i.test(f.k)?"password":"text",placeholder:"value"}),e.jsx("button",{className:"shrink-0 rounded p-1 text-fg-5 hover:text-err",onClick:()=>I(A.filter((C,M)=>M!==N)),children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},N))})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-edge pt-3",children:[e.jsx(z,{variant:"ghost",onClick:s,children:a(n,"取消","Cancel")}),e.jsx(z,{variant:"primary",disabled:!u.trim()||L,onClick:w,children:L?e.jsx(P,{}):a(n,"添加","Add")})]})]})]})}function Le({open:t,onClose:s,locale:n,scope:i,workdir:l,onInstalled:c}){const x=G(m=>m.toast),[u,h]=o.useState(""),[p,b]=o.useState(""),[y,d]=o.useState(!1);o.useEffect(()=>{t&&(h(""),b(""))},[t]);const v=async()=>{if(u.trim()){d(!0);try{const m=await _.installSkill(u.trim(),i==="global",p.trim()||void 0,l);m.ok?(x(a(n,"技能安装成功","Skill installed"),!0),c(),s()):x(m.error||"Failed",!1)}catch(m){x(m?.message||"Failed",!1)}finally{d(!1)}}};return e.jsxs(q,{open:t,onClose:s,children:[e.jsx(K,{title:a(n,"安装自定义技能","Install Custom Skill"),description:a(n,"通过 npx skills add 从 GitHub 仓库安装。","Installs via npx skills add from a GitHub repo."),onClose:s}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"GitHub 来源","GitHub Source")}),e.jsx(T,{value:u,onChange:m=>h(m.target.value),placeholder:"owner/repo",className:"font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"指定技能(可选)","Specific skill (optional)")}),e.jsx(T,{value:p,onChange:m=>b(m.target.value),placeholder:a(n,"留空安装全部","Leave empty for all")})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-edge pt-3",children:[e.jsx(z,{variant:"ghost",onClick:s,children:a(n,"取消","Cancel")}),e.jsx(z,{variant:"primary",disabled:!u.trim()||y,onClick:v,children:y?e.jsx(P,{}):a(n,"安装","Install")})]})]})]})}function Me(t,s){return new Promise(n=>{const i=window.open(t,"pikiclaw_mcp_oauth","width=640,height=780,noopener=no");if(!i){n(!1);return}let l=!1;const c=h=>{l||(l=!0,window.removeEventListener("message",x),clearInterval(u),n(h))},x=h=>{const p=h.data;if(!(!p||p.type!=="mcp-oauth")&&!(s&&p.state!==s)){c(!!p.ok);try{i.close()}catch{}}};window.addEventListener("message",x);const u=setInterval(()=>{i.closed&&c(!1)},500)})}function ae({item:t,locale:s,busy:n,index:i,onPrimary:l,onRemove:c,onReauth:x,onReconfigure:u}){const{hex:h}=W(t.iconSlug,t.name),p=(()=>{switch(t.state){case"ready":return a(s,"停用","Pause");case"unhealthy":return a(s,"停用","Pause");case"disabled":return a(s,"启用","Enable");case"needs_auth":return t.auth.type==="mcp-oauth"?a(s,"授权","Authorize"):a(s,"配置","Configure");default:return a(s,"启用","Enable")}})(),b={background:`linear-gradient(140deg, ${E(h,.05)} 0%, ${E(h,.01)} 60%, transparent 100%)`,borderColor:E(h,.18),animationDelay:`${Math.min(i,8)*40}ms`};return e.jsxs("div",{className:B("group relative overflow-hidden rounded-xl border p-4","transition-[transform,box-shadow,border-color] duration-200","hover:-translate-y-0.5 hover:shadow-[0_12px_28px_rgba(15,23,42,0.09)]","animate-in-up"),style:b,children:[e.jsx("div",{className:"pointer-events-none absolute -right-12 -top-12 h-32 w-32 rounded-full opacity-40 blur-2xl transition-opacity duration-300 group-hover:opacity-60",style:{background:E(h,.35)}}),e.jsxs("div",{className:"relative flex items-start gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:36}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"truncate text-[14px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",className:"text-fg-5 hover:text-fg-3 transition-colors",children:e.jsx(U,{})})]}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] leading-snug text-fg-4",children:s==="zh-CN"?t.descriptionZh:t.description})]}),e.jsx(Se,{state:t.state,locale:s})]}),e.jsxs("div",{className:"relative mt-3 flex items-center justify-between border-t border-edge/60 pt-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-fg-5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{background:h,opacity:.8}}),le(s,t.auth)]}),e.jsxs("div",{className:"flex items-center gap-1",children:[t.installed&&t.state!=="needs_auth"&&x&&e.jsx(z,{variant:"ghost",size:"sm",onClick:x,disabled:n,children:a(s,"重新授权","Re-auth")}),t.installed&&t.state!=="needs_auth"&&u&&e.jsx(z,{variant:"ghost",size:"sm",onClick:u,disabled:n,children:a(s,"编辑","Edit")}),e.jsx(z,{variant:t.state==="disabled"||t.state==="needs_auth"?"primary":"ghost",size:"sm",onClick:l,disabled:n,children:n?e.jsx(P,{}):p}),t.installed&&c&&e.jsx(z,{variant:"ghost",size:"sm",onClick:c,disabled:n,className:"hover:!text-err",children:a(s,"移除","Remove")})]})]})]})}function re({item:t,locale:s,busy:n,index:i,onPrimary:l}){const c=t.auth.type==="none"?a(s,"一键启用","One-click enable"):a(s,"授权并启用","Authorize & enable");return e.jsxs("div",{className:B("group relative flex flex-col gap-3 rounded-xl border border-edge bg-panel-alt p-4","transition-[transform,box-shadow,border-color] duration-200","hover:-translate-y-0.5 hover:border-edge-h hover:shadow-[0_12px_28px_rgba(15,23,42,0.09)]","animate-in-up"),style:{animationDelay:`${Math.min(i,12)*30}ms`},children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:32}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"truncate text-[13.5px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",className:"text-fg-5 hover:text-fg-3 transition-colors",children:e.jsx(U,{})})]}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] leading-snug text-fg-4",children:s==="zh-CN"?t.descriptionZh:t.description})]})]}),e.jsxs("div",{className:"mt-auto flex items-center justify-between",children:[e.jsx("span",{className:"inline-flex items-center gap-1 text-[11px] text-fg-5",children:le(s,t.auth)}),e.jsx(z,{variant:"outline",size:"sm",onClick:l,disabled:n,className:"group-hover:border-edge-h",children:n?e.jsx(P,{}):c})]})]})}function _e(t,s){const n=t.installedNames.length;if(typeof t.totalCount=="number"){const i=t.partial?`${t.totalCount}+`:String(t.totalCount);return s==="zh-CN"?`${n} / ${i} 已安装`:`${n} / ${i} installed`}return n>0?s==="zh-CN"?`${n} 已安装`:`${n} installed`:a(s,"未安装","Not installed")}function $e({item:t,locale:s,animationDelay:n,onClick:i}){const{hex:l}=W(void 0,t.name);return e.jsxs("button",{type:"button",onClick:i,className:"animate-in-up group relative flex min-h-[112px] w-full flex-col overflow-hidden rounded-2xl border border-edge/70 bg-panel p-4 text-left transition-all duration-200 hover:-translate-y-0.5 hover:shadow-[0_12px_28px_rgba(15,23,42,0.09)] focus-visible:outline-none focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",style:{background:`linear-gradient(135deg, ${E(l,.06)} 0%, ${E(l,.02)} 100%), var(--th-panel)`,animationDelay:n},children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute -right-10 -top-10 h-28 w-28 rounded-full opacity-60",style:{background:`radial-gradient(closest-side, ${E(l,.18)}, transparent 70%)`}}),e.jsxs("div",{className:"relative flex items-start gap-3",children:[e.jsx(F,{iconUrl:t.iconUrl,name:t.name,size:36}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"text-fg-5 transition-colors hover:text-primary",children:e.jsx(U,{})})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-ok)] shrink-0",style:{background:"color-mix(in oklab, var(--th-ok) 12%, transparent)"},children:[e.jsx(Z,{size:10}),_e(t,s)]})]}),e.jsx("div",{className:"mt-0.5 truncate text-[11.5px] text-fg-5",children:t.source}),e.jsx("div",{className:"mt-1 line-clamp-2 text-[11.5px] text-fg-4",children:s==="zh-CN"?t.descriptionZh:t.description})]})]}),e.jsxs("div",{className:"relative mt-auto pt-3 flex items-center justify-between text-[10.5px] text-fg-5",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[t.stars!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 font-medium text-fg-4",children:[e.jsx(ee,{size:10}),te(t.stars)]}),t.pushedAt&&e.jsx("span",{children:ce(t.pushedAt,s)})]}),e.jsx("span",{className:"text-fg-5 group-hover:text-primary transition-colors",children:a(s,"管理 →","Manage →")})]})]})}function Ae({item:t,locale:s,animationDelay:n,onClick:i}){const{hex:l}=W(void 0,t.name);return e.jsxs("button",{type:"button",onClick:i,className:"animate-in-up group relative flex min-h-[112px] w-full flex-col overflow-hidden rounded-2xl border border-edge/60 bg-panel p-4 text-left transition-all duration-200 hover:-translate-y-0.5 hover:border-edge hover:shadow-[0_12px_28px_rgba(15,23,42,0.07)] focus-visible:outline-none focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",style:{animationDelay:n},children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(F,{iconUrl:t.iconUrl,name:t.name,size:32}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"text-fg-5 transition-colors hover:text-primary",children:e.jsx(U,{})})]}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[11.5px] text-fg-4",children:s==="zh-CN"?t.descriptionZh:t.description})]})]}),e.jsxs("div",{className:"mt-auto pt-3 flex items-center justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2 text-[11px] text-fg-5",children:[t.stars!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 font-medium text-fg-4",children:[e.jsx(ee,{size:10}),te(t.stars)]}),typeof t.totalCount=="number"&&e.jsxs("span",{children:["· ",t.partial?`${t.totalCount}+`:t.totalCount," skills"]})]}),e.jsx("span",{className:"inline-flex items-center gap-1 rounded-md px-2.5 py-1 text-[11px] font-semibold transition-colors group-hover:text-primary",style:{background:`${E(l,.08)}`,color:l},children:a(s,"查看 →","Browse →")})]})]})}function Ee({item:t,open:s,onClose:n,onChanged:i,locale:l,scope:c,workdir:x,installedSkills:u}){const h=G(g=>g.toast),[p,b]=o.useState(null),[y,d]=o.useState(!1),[v,m]=o.useState(null),[S,$]=o.useState(!1),[A,I]=o.useState(null),[L,j]=o.useState(null),[w,f]=o.useState("");o.useEffect(()=>{if(!s||!t)return;let g=!1;return d(!0),m(null),f(""),(async()=>{try{const r=await _.listRepoSkills(t.source);if(g)return;r.ok?(b(r.skills),$(!!r.partial)):(m(r.error||"failed to list"),b([]))}catch(r){if(g)return;m(r?.message||"failed"),b([])}finally{g||d(!1)}})(),()=>{g=!0}},[s,t?.source]);const N=o.useMemo(()=>{const g=new Set,r=c==="global"?"global":"project";for(const k of u)k.scope===r&&g.add(k.name.toLowerCase());return g},[u,c]),C=o.useMemo(()=>{const g=p||[],r=w.trim().toLowerCase();return r?g.filter(k=>k.name.toLowerCase().includes(r)):g},[p,w]),M=o.useMemo(()=>p?p.filter(g=>N.has(g.name.toLowerCase())).length:0,[p,N]),R=o.useCallback(async g=>{if(t){I(g);try{const r=await _.installSkill(t.source,c==="global",g,x);r.ok?(h(a(l,`${g} 已安装`,`${g} installed`),!0),i()):h(r.error||"Failed",!1)}catch(r){h(r?.message||"Failed",!1)}finally{I(null)}}},[t,c,x,l,h,i]),D=o.useCallback(async g=>{I(g);try{const r=await _.removeExtensionSkill(g,c==="global",x);r.ok?(h(a(l,`${g} 已移除`,`${g} removed`),!0),i()):h(r.error||"Failed",!1)}catch(r){h(r?.message||"Failed",!1)}finally{I(null)}},[c,x,l,h,i]),V=o.useCallback(async()=>{if(t){j("install");try{const g=await _.installSkill(t.source,c==="global",void 0,x);g.ok?(h(a(l,"全部安装完成","All skills installed"),!0),i()):h(g.error||"Failed",!1)}catch(g){h(g?.message||"Failed",!1)}finally{j(null)}}},[t,c,x,l,h,i]),Y=o.useCallback(async()=>{if(!(!t||!p)){j("remove");try{const g=p.map(r=>r.name).filter(r=>N.has(r.toLowerCase()));for(const r of g)await _.removeExtensionSkill(r,c==="global",x);h(a(l,"已移除该集合下的全部技能","Removed all skills from this collection"),!0),i()}catch(g){h(g?.message||"Failed",!1)}finally{j(null)}}},[t,p,N,c,x,l,h,i]);return t?e.jsxs(q,{open:s,onClose:n,wide:!0,children:[e.jsx(K,{title:t.name,description:l==="zh-CN"?t.descriptionZh:t.description,onClose:n}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{iconUrl:t.iconUrl,name:t.name,size:44}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-semibold text-fg",children:[t.name,t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",className:"text-fg-5 hover:text-primary",children:e.jsx(U,{})})]}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11.5px] text-fg-4",children:[e.jsx("span",{className:"truncate text-fg-5",children:t.source}),t.stars!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-fg-5",children:[e.jsx(ee,{size:10}),te(t.stars)]}),t.pushedAt&&e.jsxs("span",{className:"text-fg-5",children:["· ",ce(t.pushedAt,l)]})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"text-[12px] font-semibold text-fg-3",children:[a(l,"该集合下的技能","Skills in this collection"),p&&e.jsxs("span",{className:"ml-2 text-[11px] font-normal text-fg-5",children:[M," / ",S?`${p.length}+`:p.length," ",a(l,"已安装","installed")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{variant:"outline",size:"sm",onClick:V,disabled:L!==null||y,children:L==="install"?e.jsx(P,{}):a(l,"全部安装","Install all")}),M>0&&e.jsx(z,{variant:"ghost",size:"sm",onClick:Y,disabled:L!==null,className:"hover:!text-err",children:L==="remove"?e.jsx(P,{}):a(l,"全部移除","Remove all")})]})]}),p&&p.length>6&&e.jsx(T,{type:"text",value:w,onChange:g=>f(g.target.value),placeholder:a(l,"搜索技能…","Search skills…"),className:"w-full"}),y?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(P,{})}):v?e.jsxs("div",{className:"rounded-lg border border-edge/70 bg-panel/60 p-3 text-[12px] text-fg-4",children:[a(l,"无法从 GitHub 拉取技能列表(可能是网络或速率限制)。你仍可以使用上方的「全部安装」按钮一次性安装该集合。",'Could not list skills from GitHub (network or rate-limit). You can still use "Install all" to grab the whole collection.'),e.jsx("div",{className:"mt-1 truncate font-mono text-[11px] text-fg-5",children:v})]}):C.length===0?e.jsx("div",{className:"rounded-lg border border-edge/70 bg-panel/60 p-3 text-center text-[12px] text-fg-5",children:w?a(l,"没有匹配的技能","No matching skills"):a(l,"该集合暂无可识别的技能","No discoverable skills in this collection")}):e.jsx("div",{className:"max-h-[60vh] overflow-y-auto rounded-lg border border-edge/70 bg-panel/40",children:C.map((g,r)=>{const k=N.has(g.name.toLowerCase()),O=A===g.name;return e.jsxs("div",{className:B("flex items-center justify-between gap-3 px-3 py-2 text-[12px]",r>0&&"border-t border-edge/40"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[k&&e.jsx(Z,{size:12}),e.jsx("span",{className:B("truncate font-medium",k?"text-[var(--th-ok)]":"text-fg-2"),children:g.name})]}),g.description&&e.jsx("div",{className:"mt-0.5 line-clamp-1 text-[11px] text-fg-5",children:g.description})]}),k?e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{D(g.name)},disabled:O||L!==null,className:"hover:!text-err",children:O?e.jsx(P,{}):a(l,"移除","Remove")}):e.jsx(z,{variant:"outline",size:"sm",onClick:()=>{R(g.name)},disabled:O||L!==null,children:O?e.jsx(P,{}):a(l,"安装","Install")})]},g.name)})}),S&&e.jsx("div",{className:"text-[11px] text-fg-5",children:a(l,"仓库内技能数量较多,仅显示前 1000 个。可使用上方搜索或直接打开仓库浏览全部。","Showing the first 1000 skills. Use search or open the repo on GitHub for the full list.")})]})]})]}):null}const ee=({size:t=12})=>e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:e.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})});function te(t){return t>=1e4?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}k`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function ce(t,s){const n=Date.parse(t);if(!Number.isFinite(n))return"";const i=Date.now()-n,l=1440*60*1e3,c=Math.max(1,Math.floor(i/l));if(c<30)return s==="zh-CN"?`${c} 天前`:`${c}d ago`;const x=Math.floor(c/30);if(x<12)return s==="zh-CN"?`${x} 个月前`:`${x}mo ago`;const u=Math.floor(x/12);return s==="zh-CN"?`${u} 年前`:`${u}y ago`}const H={dev:{zh:"开发工具",en:"Development",order:0},productivity:{zh:"生产力",en:"Productivity",order:1},communication:{zh:"协作沟通",en:"Communication",order:2},data:{zh:"数据",en:"Data",order:3},search:{zh:"搜索",en:"Search",order:4},utility:{zh:"工具",en:"Utility",order:5},custom:{zh:"自定义",en:"Custom",order:6}};function Re(t){const s=new Map;for(const n of t){const i=s.get(n.category)||[];i.push(n),s.set(n.category,i)}return[...s.entries()].sort((n,i)=>(H[n[0]]?.order??99)-(H[i[0]]?.order??99)).map(([n,i])=>({key:n,items:i}))}function de({scope:t,workdir:s,locale:n,onOpenBrowserSetup:i}){const l=G(r=>r.toast),c=`pikiclaw.mcp.catalog.${t}.${s||""}`,{data:x,loading:u,refresh:h}=X(c,async()=>(await _.getMcpCatalog(s,t)).items||[],[s,t]),[p,b]=o.useState(""),[y,d]=o.useState(null),[v,m]=o.useState(!1),[S,$]=o.useState(null),A=x||[],I=o.useMemo(()=>A.filter(r=>!r.installed||r.scope===t||!r.scope),[A,t]),L=o.useMemo(()=>{if(!p.trim())return I;const r=p.trim().toLowerCase();return I.filter(k=>k.name.toLowerCase().includes(r)||k.description.toLowerCase().includes(r)||k.descriptionZh.includes(r)||k.id.toLowerCase().includes(r))},[I,p]),j=o.useMemo(()=>L.filter(r=>r.isBuiltin),[L]),w=o.useMemo(()=>L.filter(r=>!r.isBuiltin&&(r.state==="ready"||r.state==="unhealthy")),[L]),f=o.useMemo(()=>Re(L.filter(r=>!r.isBuiltin&&r.state!=="ready"&&r.state!=="unhealthy")),[L]),N=o.useCallback(async(r,k)=>{if(r.isRecommended){$(r.id);try{const O=await _.installMcp(r.id,t,k,s,!0);if(!O.ok)throw new Error(O.error||"install failed");return await h(),O.enabled??!1}catch(O){return l(O?.message||"Failed",!1),!1}finally{$(null)}}},[t,s,h,l]),C=o.useCallback(async r=>{$(r.id);try{if(!r.installed){const ne=await _.installMcp(r.id,t,void 0,s,!1);if(!ne.ok)throw new Error(ne.error||"install failed")}const k=await _.startMcpOAuth(r.id);if(!k.ok||!k.authUrl||!k.state)throw new Error(k.error||"oauth start failed");await Me(k.authUrl,k.state)?(await _.toggleMcp(r.id,!0,t,s),l(a(n,`${r.name} 授权成功`,`${r.name} authorized`),!0)):l(a(n,"授权未完成","Authorization not completed"),!1),await h()}catch(k){l(k?.message||"OAuth failed",!1)}finally{$(null)}},[t,s,n,l,h]),M=o.useCallback(async(r,k)=>{if(r.installedKey){$(r.id);try{await _.toggleMcp(r.installedKey,k,r.scope==="workspace"?"workspace":"global",s),await h()}catch(O){l(O?.message||"Failed",!1)}finally{$(null)}}},[s,h,l]),R=o.useCallback(async r=>{if(r.installedKey){$(r.id);try{await _.removeMcp(r.installedKey,r.scope==="workspace"?"workspace":"global",r.isRecommended?r.id:void 0,s),await h()}catch(k){l(k?.message||"Failed",!1)}finally{$(null)}}},[s,h,l]),D=o.useCallback(async r=>{if(!y)return;await N(y,r)!==!1&&d(null)},[y,N]),V=o.useCallback(r=>{if(r.state==="ready"||r.state==="unhealthy"){M(r,!1);return}if(r.state==="disabled"){M(r,!0);return}if(r.state==="needs_auth"){if(r.auth.type==="mcp-oauth"){C(r);return}if(r.auth.type==="credentials"){d(r);return}}},[M,C]),Y=o.useCallback(r=>{if(r.state==="disabled"){M(r,!0);return}if(r.state==="needs_auth"){if(r.auth.type==="mcp-oauth"){C(r);return}if(r.auth.type==="credentials"){d(r);return}}if(r.auth.type==="mcp-oauth"){C(r);return}if(r.auth.type==="credentials"){d(r);return}N(r)},[C,N,M]),g=u&&!x;return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Q,{children:"MCP Servers"}),!u&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:[w.length," ",a(n,"在用","in use")," · ",I.length-w.length-j.length," ",a(n,"可添加","available")]}),u&&e.jsx(P,{className:"h-3 w-3"})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:p,onChange:r=>b(r.target.value),placeholder:a(n,"搜索...","Search..."),className:"h-7 w-52 rounded-md border border-edge bg-inset/50 pl-7 pr-2.5 text-[12px] text-fg outline-none placeholder:text-fg-5/50 focus:border-primary/30 focus:bg-inset"})]})})]}),g?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(P,{})}):e.jsxs("div",{className:"space-y-5",children:[j.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--th-accent,#7c3aed)]"}),a(n,"内置(pikiclaw 优化)","Built-in (optimized by pikiclaw)")]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:j.map((r,k)=>r.installed?e.jsx(ae,{item:r,locale:n,busy:S===r.id,index:k,onPrimary:()=>V(r),onReconfigure:i},r.id):e.jsx(re,{item:r,locale:n,busy:S===r.id,index:k,onPrimary:()=>Y(r)},r.id))})]}),w.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--th-ok)]"}),a(n,"在用","In use")]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:w.map((r,k)=>e.jsx(ae,{item:r,locale:n,busy:S===r.id,index:k,onPrimary:()=>V(r),onRemove:()=>{R(r)},onReauth:r.auth.type==="mcp-oauth"?()=>{C(r)}:void 0,onReconfigure:r.auth.type==="credentials"?()=>d(r):void 0},r.id))})]}),f.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5"}),w.length===0?a(n,"推荐的服务","Recommended services"):a(n,"更多可选","More options")]}),e.jsx("div",{className:"space-y-4",children:f.map(r=>e.jsx(Oe,{groupKey:r.key,locale:n,children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:r.items.map((k,O)=>e.jsx(re,{item:k,locale:n,busy:S===k.id,index:O,onPrimary:()=>Y(k)},k.id))})},r.key))})]}),j.length===0&&w.length===0&&f.length===0&&e.jsx(se,{title:a(n,"没有匹配的服务","No matching services"),subtitle:a(n,"试试别的关键词","Try a different search term")})]}),e.jsx("div",{className:"mt-3 flex justify-end",children:e.jsxs("button",{className:"text-[12px] text-fg-4 hover:text-fg-2 transition-colors",onClick:()=>m(!0),children:["+ ",a(n,"添加自定义 MCP","Add custom MCP")]})}),e.jsx(Ie,{open:!!y,onClose:()=>d(null),locale:n,item:y,initial:y?.config?.env||y?.config?.headers,onSubmit:D}),e.jsx(ze,{open:v,onClose:()=>m(!1),locale:n,scope:t,workdir:s,onAdded:h})]})}function Oe({groupKey:t,locale:s,children:n}){const i=H[t],l=i?a(s,i.zh,i.en):t;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-[11px] font-medium text-fg-5",children:l}),n]})}function se({title:t,subtitle:s}){return e.jsxs("div",{className:"rounded-xl border border-dashed border-edge py-10 text-center",children:[e.jsx("div",{className:"text-[13px] font-medium text-fg-3",children:t}),s&&e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:s})]})}function xe({scope:t,workdir:s,locale:n}){const i=`pikiclaw.skills.catalog.${t}.${s||""}`,{data:l,loading:c,refresh:x}=X(i,async()=>{const j=await _.getSkillsCatalog(s,t);return{items:j.items||[],installed:j.installed||[]}},[s,t]),[u,h]=o.useState(!1),[p,b]=o.useState(null),y=l?.items||[],d=l?.installed||[],v=o.useMemo(()=>{const j=t==="global"?"global":"project";return d.filter(w=>w.scope===j)},[d,t]),m=o.useMemo(()=>y.filter(j=>j.installedNames.length>0),[y]),S=o.useMemo(()=>y.filter(j=>j.installedNames.length===0),[y]),$=o.useMemo(()=>{const j=new Map;for(const w of S){const f=w.category;j.has(f)||j.set(f,[]),j.get(f).push(w)}return[...j.entries()].sort(([w],[f])=>(H[w]?.order??99)-(H[f]?.order??99))},[S]),A=p&&y.find(j=>j.id===p)||null,I=c&&!l,L=v.length;return e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Q,{children:"Skills"}),!c&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:[L," ",a(n,"已安装","installed")," · ",S.length," ",a(n,"可用","available")]}),c&&e.jsx(P,{className:"h-3 w-3"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{x()},children:c?a(n,"刷新中…","Refreshing…"):a(n,"刷新","Refresh")}),e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>h(!0),children:["+ ",a(n,"从 GitHub 安装","Install from GitHub")]})]})]}),I?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(P,{})}):y.length===0?e.jsx(se,{title:a(n,"暂无可用的技能包","No skill packs available"),subtitle:a(n,"从 GitHub 导入一个开始使用","Import from GitHub to get started")}):e.jsxs(e.Fragment,{children:[m.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-fg-3",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-[var(--th-ok)]"}),a(n,"已安装","Installed")]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:m.map((j,w)=>e.jsx($e,{item:j,locale:n,animationDelay:`${Math.min(w,12)*30}ms`,onClick:()=>b(j.id)},j.id))})]}),S.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-fg-3",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-fg-5/50"}),a(n,"推荐","Available")]}),$.map(([j,w])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[10.5px] font-medium uppercase tracking-[0.06em] text-fg-5",children:n==="zh-CN"?H[j]?.zh||j:H[j]?.en||j}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:w.map((f,N)=>e.jsx(Ae,{item:f,locale:n,animationDelay:`${Math.min(N,12)*30}ms`,onClick:()=>b(f.id)},f.id))})]},j))]})]}),e.jsx(Ee,{item:A,open:!!A,onClose:()=>b(null),onChanged:()=>{x()},locale:n,scope:t,workdir:s,installedSkills:d}),e.jsx(Le,{open:u,onClose:()=>h(!1),locale:n,scope:t,workdir:s,onInstalled:x})]})}const J={dev:{zh:"开发工具",en:"Developer",order:1},cloud:{zh:"云平台",en:"Cloud",order:2},data:{zh:"数据",en:"Data",order:3},productivity:{zh:"生产力",en:"Productivity",order:4}};function ue({state:t,locale:s}){return t==="ready"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-ok)]",style:{background:"color-mix(in oklab, var(--th-ok) 12%, transparent)"},children:[e.jsx(Z,{size:10}),a(s,"已登录","Signed in")]}):t==="installed_not_auth"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-amber-600 dark:text-amber-400",style:{background:"color-mix(in oklab, #f59e0b 14%, transparent)"},children:[e.jsx(ie,{size:10}),a(s,"待登录","Sign-in needed")]}):t==="not_installed"?e.jsx("span",{className:"inline-flex items-center gap-1 rounded-full border border-edge bg-inset/60 px-2 py-0.5 text-[10px] font-medium text-fg-5",children:a(s,"未安装","Not installed")}):e.jsx("span",{className:"inline-flex items-center gap-1 rounded-full border border-edge bg-inset/60 px-2 py-0.5 text-[10px] font-medium text-fg-5",children:"..."})}function he({chunks:t,running:s,emptyHint:n}){const i=o.useRef(null);o.useEffect(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},[t.length]);const l=t.join("");return e.jsx("div",{ref:i,className:"relative h-56 overflow-auto rounded-xl border border-edge/60 bg-[#0b0f16] p-3 font-mono text-[11.5px] leading-[1.55] text-[#cdd6f4] scrollbar-thin",style:{boxShadow:"0 1px 0 rgba(255,255,255,0.03) inset"},children:l?e.jsx("pre",{className:"whitespace-pre-wrap break-words",children:l}):e.jsx("div",{className:"flex h-full items-center justify-center text-[#6c7086]",children:s?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(P,{})," ",n||"Starting…"]}):n||"No output yet"})})}function Pe({cli:t,locale:s,onInstalled:n}){const[i,l]=o.useState([]),[c,x]=o.useState(!1),[u,h]=o.useState(null),[p,b]=o.useState(null),[y,d]=o.useState(null),v=o.useRef(null),m=o.useCallback(()=>{try{v.current?.close()}catch{}v.current=null},[]);o.useEffect(()=>m,[m]);const S=o.useCallback(async()=>{l([]),b(null),d(null),x(!0);try{const I=await _.startCliInstall(t.id);if(!I.ok||!I.sessionId)throw new Error(I.error||"start failed");h(I.sessionId);const L=new EventSource(`/api/extensions/cli/auth/stream?sessionId=${encodeURIComponent(I.sessionId)}`);v.current=L,L.onmessage=j=>{try{const w=JSON.parse(j.data);w.type==="output"?l(f=>f.length>400?[...f.slice(-400),w.chunk]:[...f,w.chunk]):w.type==="error"?b(w.message||"error"):w.type==="done"&&(x(!1),d(!!w.ok),m(),w.ok&&n())}catch{}},L.addEventListener("close",()=>{x(!1),m()}),L.onerror=()=>{c&&b(a(s,"连接中断","Stream disconnected"))}}catch(I){x(!1),b(I?.message||"failed to start install")}},[t.id,m,s,n,c]),$=o.useCallback(async()=>{if(u)try{await _.cancelCliAuth(u)}catch{}m(),x(!1)},[u,m]);if(!t.autoInstall)return null;const A=c||i.length>0||y!==null;return e.jsxs("div",{className:"space-y-3 rounded-lg border border-edge/70 bg-panel/60 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-fg-3",children:a(s,`通过 ${t.autoInstall.label} 直接在本机自动安装,无需复制命令。`,`Run the ${t.autoInstall.label} install locally — no copy-paste needed.`)}),c?e.jsx(z,{variant:"outline",size:"sm",onClick:$,children:a(s,"中止","Abort")}):e.jsx(z,{variant:"primary",size:"sm",onClick:S,disabled:y===!0,children:y===!0?a(s,"已安装","Installed"):y===!1?a(s,"重试安装","Retry install"):a(s,"一键安装","Auto-install")})]}),A&&e.jsx(he,{chunks:i,running:c,emptyHint:a(s,"安装进度将在此显示","Install output will appear here")}),p&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:p}),y===!1&&!p&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:a(s,"安装未成功,请查看上方输出排查。","Install did not complete — check the output above.")})]})}function Te({cli:t,locale:s,onSignedIn:n,onCancel:i}){const[l,c]=o.useState([]),[x,u]=o.useState(!1),[h,p]=o.useState(null),[b,y]=o.useState(null),[d,v]=o.useState(null),m=o.useRef(null),S=o.useCallback(()=>{try{m.current?.close()}catch{}m.current=null},[]);o.useEffect(()=>S,[S]);const $=o.useCallback(async()=>{c([]),v(null),y(null),u(!0);try{const N=await _.startCliAuth(t.id);if(!N.ok||!N.sessionId)throw new Error(N.error||"start failed");p(N.sessionId);const C=new EventSource(`/api/extensions/cli/auth/stream?sessionId=${encodeURIComponent(N.sessionId)}`);m.current=C,C.onmessage=M=>{try{const R=JSON.parse(M.data);R.type==="output"?c(D=>D.length>400?[...D.slice(-400),R.chunk]:[...D,R.chunk]):R.type==="status"?y(R.status.state==="ready"?a(s,"已检测到登录成功","Sign-in detected"):a(s,"等待授权完成…","Waiting for authorization…")):R.type==="error"?v(R.message||"error"):R.type==="done"&&(u(!1),S(),R.ok&&n())}catch{}},C.addEventListener("close",()=>{u(!1),S()}),C.onerror=()=>{x&&v(a(s,"连接中断","Stream disconnected"))}}catch(N){u(!1),v(N?.message||"failed to start sign-in")}},[t.id,S,s,n,x]),A=o.useCallback(async()=>{if(h)try{await _.cancelCliAuth(h)}catch{}S(),u(!1),i()},[h,S,i]),[I,L]=o.useState({}),[j,w]=o.useState(!1),f=o.useCallback(async()=>{w(!0),v(null);try{const N=await _.applyCliToken(t.id,I);N.ok?n():v(N.error||a(s,"应用凭据失败","Failed to apply credentials"))}catch(N){v(N?.message||"failed")}finally{w(!1)}},[t.id,I,s,n]);if(t.auth.type==="oauth-web"){const N=s==="zh-CN"&&t.auth.loginHintZh||t.auth.loginHint;return e.jsxs("div",{className:"space-y-3",children:[N&&e.jsx("div",{className:"text-[12px] leading-relaxed text-fg-4",children:N}),e.jsx(he,{chunks:l,running:x,emptyHint:a(s,"点击「开始登录」后将在此展示命令行输出",'Click "Start sign-in" to stream CLI output here')}),d&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:d}),b&&!d&&e.jsx("div",{className:"text-[12px] text-[var(--th-ok)]",children:b}),e.jsx("div",{className:"flex items-center gap-2",children:x?e.jsx(z,{variant:"outline",size:"sm",onClick:A,children:a(s,"中止","Abort")}):e.jsxs(e.Fragment,{children:[e.jsx(z,{variant:"primary",size:"sm",onClick:$,children:a(s,"开始登录","Start sign-in")}),e.jsx(z,{variant:"ghost",size:"sm",onClick:i,children:a(s,"取消","Cancel")})]})})]})}if(t.auth.type==="token"){const N=s==="zh-CN"&&t.auth.loginHintZh||t.auth.loginHint;return e.jsxs("div",{className:"space-y-3",children:[N&&e.jsx("div",{className:"text-[12px] leading-relaxed text-fg-4",children:N}),e.jsx("div",{className:"space-y-2",children:(t.auth.tokenFields||[]).map(C=>e.jsxs("label",{className:"block text-[12px]",children:[e.jsxs("div",{className:"mb-1 text-fg-3",children:[s==="zh-CN"?C.labelZh:C.label,C.required&&e.jsx("span",{className:"ml-1 text-[var(--th-err)]",children:"*"})]}),e.jsx(T,{type:C.secret?"password":"text",value:I[C.key]||"",onChange:M=>L(R=>({...R,[C.key]:M.target.value})),placeholder:C.placeholder||"",className:"w-full"}),C.helpUrl&&e.jsxs("a",{className:"mt-1 inline-block text-[11px] text-primary hover:underline",href:C.helpUrl,target:"_blank",rel:"noreferrer",children:[a(s,"如何获取","How to get this")," ↗"]})]},C.key))}),d&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:d}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{variant:"primary",size:"sm",onClick:f,disabled:j,children:j?a(s,"验证中…","Verifying…"):a(s,"保存并验证","Save & verify")}),e.jsx(z,{variant:"ghost",size:"sm",onClick:i,children:a(s,"取消","Cancel")})]})]})}return null}function Be({commands:t,locale:s}){return e.jsx("div",{className:"space-y-2",children:t.map((n,i)=>e.jsxs("div",{className:"overflow-hidden rounded-lg border border-edge/70 bg-panel/60",children:[n.label&&e.jsx("div",{className:"flex items-center justify-between border-b border-edge/50 bg-panel-alt/40 px-3 py-1 text-[11px] font-medium text-fg-4",children:e.jsx("span",{children:n.label})}),e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 font-mono text-[12px] text-fg-2",children:[e.jsx("span",{className:"mt-[2px] select-none text-fg-5",children:"$"}),e.jsx("code",{className:"min-w-0 flex-1 break-all",children:n.cmd}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(n.cmd)},className:"shrink-0 rounded px-2 py-0.5 text-[10.5px] text-fg-5 transition-colors hover:bg-panel-h hover:text-fg-2",title:a(s,"复制到剪贴板","Copy to clipboard"),children:a(s,"复制","Copy")})]})]},i))})}function Ue({cli:t,open:s,onClose:n,onChanged:i,locale:l}){const[c,x]=o.useState(!1),[u,h]=o.useState(!1),[p,b]=o.useState(null);o.useEffect(()=>{s||(x(!1),b(null))},[s]);const y=o.useMemo(()=>t?t.install[t.platform]||[]:[],[t]);if(!t)return null;const d=t.state!=="not_installed",v=t.state==="ready",m=async()=>{h(!0),b(null);try{const S=await _.logoutCli(t.id);S.ok||b(S.error||a(l,"登出失败","Logout failed")),i()}catch(S){b(S?.message||"failed")}finally{h(!1)}};return e.jsxs(q,{open:s,onClose:n,wide:!0,children:[e.jsx(K,{title:t.name,description:l==="zh-CN"?t.descriptionZh:t.description,onClose:n}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:44}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-semibold text-fg",children:[t.name,t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",className:"text-fg-5 hover:text-primary",children:e.jsx(U,{})})]}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11.5px] text-fg-4",children:[ue({state:t.state,locale:l}),t.version&&e.jsxs("span",{className:"font-mono text-fg-5",children:["v",t.version]}),v&&t.authDetail&&e.jsxs("span",{className:"truncate text-fg-5",children:["· ",t.authDetail]})]})]})]}),!d&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("div",{className:"text-[12px] font-semibold text-fg-3",children:a(l,"安装","Install")}),t.autoInstall&&e.jsx(Pe,{cli:t,locale:l,onInstalled:i}),e.jsx("div",{className:"text-[11.5px] leading-relaxed text-fg-5",children:t.autoInstall?a(l,"或手动复制命令到终端执行。","Or copy a command below and run it in your terminal."):a(l,"复制下面的命令到终端运行。我们不自动代为安装 — 包管理器往往需要 sudo 或交互式确认。","Copy a command below and run it in your terminal. We don't auto-install — package managers often need sudo or interactive confirmation.")}),y.length>0?e.jsx(Be,{commands:y,locale:l}):e.jsx("div",{className:"text-[12px] text-fg-5",children:a(l,"请查看官方文档","Check the official installation docs")}),t.install.docs&&e.jsxs("a",{href:t.install.docs,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[11.5px] text-primary hover:underline",children:[a(l,"查看安装文档","Installation docs")," ↗"]}),e.jsx("div",{className:"pt-2",children:e.jsx(z,{variant:"outline",size:"sm",onClick:i,children:a(l,"我已安装,重新检测","I've installed, re-check")})})]}),d&&t.auth.type!=="none"&&e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-[12px] font-semibold text-fg-3",children:a(l,"登录","Sign in")}),v&&!c&&e.jsx(z,{variant:"ghost",size:"sm",onClick:m,disabled:u,children:u?a(l,"登出中…","Signing out…"):a(l,"登出","Sign out")})]}),p&&e.jsx("div",{className:"text-[11.5px] text-[var(--th-err)]",children:p}),v&&!c?e.jsxs("div",{className:"rounded-lg border border-edge/70 bg-panel/60 p-3 text-[12px] text-fg-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{size:12}),e.jsx("span",{children:a(l,"你已经登录,命令行工具可直接使用。","Already signed in — the CLI is ready to use.")})]}),e.jsx("div",{className:"mt-2",children:e.jsx(z,{variant:"outline",size:"sm",onClick:()=>x(!0),children:a(l,"重新登录","Re-authenticate")})})]}):e.jsx(Te,{cli:t,locale:l,onSignedIn:()=>{x(!1),i()},onCancel:()=>x(!1)})]}),d&&t.auth.type==="none"&&e.jsx("section",{className:"rounded-lg border border-edge/70 bg-panel/60 p-3 text-[12px] text-fg-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{size:12}),e.jsx("span",{children:a(l,"无需授权 — 可直接使用。","No authentication required — ready to use.")})]})})]})]})}function Fe({item:t,onClick:s,locale:n,animationDelay:i}){const{hex:l}=W(t.iconSlug,t.name);return e.jsxs("button",{type:"button",onClick:s,className:"animate-in-up group relative flex min-h-[112px] w-full flex-col overflow-hidden rounded-2xl border border-edge/70 bg-panel p-4 text-left transition-all duration-200 hover:-translate-y-0.5 hover:shadow-[0_12px_28px_rgba(15,23,42,0.09)] focus-visible:outline-none focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",style:{background:`linear-gradient(135deg, ${E(l,.06)} 0%, ${E(l,.02)} 100%), var(--th-panel)`,animationDelay:i},children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute -right-10 -top-10 h-28 w-28 rounded-full opacity-60",style:{background:`radial-gradient(closest-side, ${E(l,.18)}, transparent 70%)`}}),e.jsxs("div",{className:"relative flex items-start gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:36}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"truncate text-[13px] font-semibold text-fg",children:t.name}),ue({state:t.state,locale:n})]}),e.jsxs("div",{className:"mt-0.5 truncate text-[11.5px] text-fg-5",children:[t.version?e.jsxs("span",{className:"font-mono",children:["v",t.version]}):null,t.version&&t.authDetail?" · ":null,t.authDetail]}),e.jsx("div",{className:"mt-1 truncate text-[11.5px] text-fg-4",children:n==="zh-CN"?t.descriptionZh:t.description})]})]})]})}function De({item:t,onClick:s,locale:n,animationDelay:i}){const{hex:l}=W(t.iconSlug,t.name),c=t.state==="not_installed"?a(n,"安装","Install"):t.state==="installed_not_auth"?a(n,"登录","Sign in"):a(n,"查看","Details");return e.jsxs("button",{type:"button",onClick:s,className:"animate-in-up group relative flex min-h-[112px] w-full flex-col overflow-hidden rounded-2xl border border-edge/60 bg-panel p-4 text-left transition-all duration-200 hover:-translate-y-0.5 hover:border-edge hover:shadow-[0_12px_28px_rgba(15,23,42,0.07)] focus-visible:outline-none focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",style:{animationDelay:i},children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:32}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",onClick:x=>x.stopPropagation(),className:"text-fg-5 transition-colors hover:text-primary",children:e.jsx(U,{})})]}),e.jsx("div",{className:"mt-0.5 truncate text-[11.5px] text-fg-4",children:n==="zh-CN"?t.descriptionZh:t.description})]})]}),e.jsxs("div",{className:"mt-auto pt-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] text-fg-5",children:t.auth.type==="oauth-web"?a(n,"浏览器授权","OAuth"):t.auth.type==="token"?a(n,"Token","Token"):a(n,"免配置","No auth")}),e.jsx("span",{className:"inline-flex items-center gap-1 rounded-md px-2.5 py-1 text-[11px] font-semibold transition-colors group-hover:text-primary",style:{background:`${E(l,.08)}`,color:l},children:c})]})]})}function pe({locale:t,scope:s}){const{data:n,loading:i,refresh:l}=X("pikiclaw:cli:catalog",async()=>{const d=await _.getCliCatalog();if(!d.ok)throw new Error(d.error||"failed");return d.items||[]},[]),[c,x]=o.useState(null),u=o.useMemo(()=>{const d=n||[];return d},[n,s]),h=c&&u.find(d=>d.id===c)||null,p=u.filter(d=>d.state==="ready"),b=u.filter(d=>d.state!=="ready"),y=o.useMemo(()=>{const d=new Map;for(const v of b){const m=v.category;d.has(m)||d.set(m,[]),d.get(m).push(v)}return[...d.entries()].sort(([v],[m])=>(J[v]?.order??99)-(J[m]?.order??99))},[b]);return e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Q,{children:a(t,"CLI 工具","CLI Tools")}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-fg-5",children:[e.jsxs("span",{children:[p.length," ",a(t,"已登录","signed in")," · ",b.length," ",a(t,"可用","available")]}),e.jsx("button",{type:"button",onClick:()=>{l()},className:"rounded px-2 py-0.5 text-fg-5 transition-colors hover:bg-panel-h hover:text-fg-2",children:i?a(t,"刷新中…","Refreshing…"):a(t,"刷新","Refresh")})]})]}),s==="workspace"&&e.jsx("div",{className:"rounded-lg border border-edge/60 bg-inset/40 px-3 py-2 text-[11.5px] text-fg-4",children:a(t,"CLI 工具安装于机器层面,项目视图下同样可见。","CLI tools are installed machine-wide and are shown here for convenience.")}),p.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-fg-3",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-[var(--th-ok)]"}),a(t,"已登录","Signed in")]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:p.map((d,v)=>e.jsx(Fe,{item:d,locale:t,animationDelay:`${Math.min(v,12)*30}ms`,onClick:()=>x(d.id)},d.id))})]}),b.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-fg-3",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-fg-5/50"}),a(t,"推荐工具","Available")]}),y.map(([d,v])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[10.5px] font-medium uppercase tracking-[0.06em] text-fg-5",children:t==="zh-CN"?J[d]?.zh||d:J[d]?.en||d}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:v.map((m,S)=>e.jsx(De,{item:m,locale:t,animationDelay:`${Math.min(S,12)*30}ms`,onClick:()=>x(m.id)},m.id))})]},d))]}),!i&&u.length===0&&e.jsx(se,{title:a(t,"暂无可用 CLI","No CLI tools available"),subtitle:a(t,"稍后再试,或重启一下服务。","Try again later, or restart the service.")}),e.jsx(Ue,{cli:h,open:!!h,onClose:()=>x(null),onChanged:()=>{l()},locale:t})]})}function me({active:t,onChange:s,locale:n,counts:i}){const l=[{id:"mcp",labelZh:"MCP 服务",labelEn:"MCP",icon:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("circle",{cx:"4",cy:"5",r:"1.6"}),e.jsx("circle",{cx:"20",cy:"5",r:"1.6"}),e.jsx("circle",{cx:"4",cy:"19",r:"1.6"}),e.jsx("circle",{cx:"20",cy:"19",r:"1.6"}),e.jsx("path",{d:"M6 6 l4 4 M18 6 l-4 4 M6 18 l4 -4 M18 18 l-4 -4"})]})},{id:"cli",labelZh:"命令行",labelEn:"CLI",icon:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 17 l5 -5 -5 -5"}),e.jsx("path",{d:"M12 19 h8"})]})},{id:"skill",labelZh:"技能包",labelEn:"Skills",icon:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 2 l3 7 h7 l-5.5 4.5 2 7.5 L12 17 l-6.5 4 2 -7.5 L2 9 h7 z"})})}];return e.jsx(fe,{className:"w-fit bg-panel/80 backdrop-blur",children:l.map(c=>e.jsxs(ge,{active:t===c.id,onClick:()=>s(c.id),className:"gap-1.5 px-3.5",children:[e.jsx("span",{className:"shrink-0",children:c.icon}),e.jsx("span",{children:n==="zh-CN"?c.labelZh:c.labelEn}),i?.[c.id]!==void 0&&e.jsx("span",{className:B("ml-1 inline-flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[10px] font-semibold",t===c.id?"bg-primary/12 text-primary":"bg-inset/70 text-fg-5"),children:i[c.id]})]},c.id))})}function Ke({onOpenBrowserSetup:t}){const s=G(u=>u.locale),i=G(u=>u.state)?.config?.workdir||"",[l,c]=o.useState(()=>{try{const u=localStorage.getItem("pikiclaw:extensions:tab");return u==="mcp"||u==="cli"||u==="skill"?u:"mcp"}catch{return"mcp"}}),x=o.useCallback(u=>{c(u);try{localStorage.setItem("pikiclaw:extensions:tab",u)}catch{}},[]);return e.jsxs("div",{className:"animate-in space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.jsx("div",{className:"space-y-1",children:e.jsx("div",{className:"text-[13px] leading-relaxed text-fg-4",children:a(s,"管理一次授权即可全局复用的服务与工具。项目专属的扩展请在工作台侧栏配置。","One-time authorization, use everywhere. Project-specific extensions live in the Workbench sidebar.")})}),e.jsx(me,{active:l,onChange:x,locale:s})]}),e.jsxs("div",{className:"animate-in-fade",children:[l==="mcp"&&e.jsx("div",{className:"space-y-7",children:e.jsx(de,{scope:"global",workdir:i,locale:s,onOpenBrowserSetup:t})}),l==="cli"&&e.jsx(pe,{locale:s,scope:"global"}),l==="skill"&&e.jsx(xe,{scope:"global",workdir:i,locale:s})]},l)]})}function Ve({workdir:t}){const s=G(c=>c.locale),[n,i]=o.useState(()=>{try{const c=localStorage.getItem("pikiclaw:extensions-ws:tab");return c==="mcp"||c==="cli"||c==="skill"?c:"mcp"}catch{return"mcp"}}),l=o.useCallback(c=>{i(c);try{localStorage.setItem("pikiclaw:extensions-ws:tab",c)}catch{}},[]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-3",children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-fg-4",children:a(s,"仅对当前工作区生效 — 依赖项目目录的本地服务和专属技能包。","Scoped to this workspace — local services that depend on project context and project-specific skill packs.")}),e.jsx(me,{active:n,onChange:l,locale:s})]}),e.jsxs("div",{className:"animate-in-fade",children:[n==="mcp"&&e.jsx(de,{scope:"workspace",workdir:t,locale:s}),n==="cli"&&e.jsx(pe,{locale:s,scope:"workspace"}),n==="skill"&&e.jsx(xe,{scope:"workspace",workdir:t,locale:s})]},n)]})}export{Ke as ExtensionsTab,Ve as WorkspaceExtensionsBody};
|
|
1
|
+
import{r as o,j as e}from"./react-vendor-DTcmqLiz.js";import{u as G,T as fe,m as ge,c as B,a as _,o as Q,S as P,B as z}from"./index-B_sC2ppg.js";import{B as ve}from"./BrandIcon-CmIkwB4h.js";import{M as q,a as K,I as T}from"./Modal-Cx6r2XJQ.js";import"./router-Cav8lq-m.js";function a(t,s,n){return t==="zh-CN"?s:n}function le(t,s){return s.type==="mcp-oauth"?a(t,"OAuth","OAuth"):s.type==="credentials"?a(t,"API Key","API Key"):a(t,"无需配置","No auth")}const je={github:{hex:"#24292f",letter:"GH"},atlassian:{hex:"#0052cc",letter:"A"},notion:{hex:"#111827",letter:"N"},linear:{hex:"#5e6ad2",letter:"L"},sentry:{hex:"#362d59",letter:"S"},cloudflare:{hex:"#f6821f",letter:"CF"},gamma:{hex:"#9f2eff",letter:"G"},huggingface:{hex:"#ff9d00",letter:"HF"},slack:{hex:"#4a154b",letter:"S"},lark:{hex:"#00d6b9",letter:"L"},feishu:{hex:"#00d6b9",letter:"F"},stripe:{hex:"#635bff",letter:"S"},perplexity:{hex:"#20b8cd",letter:"P"},brave:{hex:"#fb542b",letter:"B"},filesystem:{hex:"#64748b",letter:"FS"},fetch:{hex:"#0ea5e9",letter:"F"},memory:{hex:"#a855f7",letter:"M"},time:{hex:"#10b981",letter:"T"},sqlite:{hex:"#0369a1",letter:"SQ"},postgres:{hex:"#336791",letter:"PG"}},be={hex:"#6b7280"};function W(t,s){const n=(t||"").toLowerCase(),i=je[n]||be,l=i.letter||(s||"").replace(/[^a-zA-Z0-9]/g,"").slice(0,2).toUpperCase()||"?";return{hex:i.hex,letter:l}}function E(t,s){const n=t.replace("#",""),i=n.length===3?n.split("").map(u=>u+u).join(""):n.padEnd(6,"0").slice(0,6),l=parseInt(i.slice(0,2),16),c=parseInt(i.slice(2,4),16),x=parseInt(i.slice(4,6),16);return`rgba(${l}, ${c}, ${x}, ${s})`}function X(t,s,n=[]){const[i,l]=o.useState(()=>{try{const p=localStorage.getItem(t);return p?JSON.parse(p):null}catch{return null}}),[c,x]=o.useState(!1),u=o.useRef(!0);o.useEffect(()=>()=>{u.current=!1},[]);const h=o.useCallback(async()=>{x(!0);try{const p=await s();if(!u.current)return;l(p);try{localStorage.setItem(t,JSON.stringify(p))}catch{}}finally{u.current&&x(!1)}},[t,...n]);return o.useEffect(()=>{h()},[h]),{data:i,loading:c,refresh:h}}const U=()=>e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),Z=({size:t=12})=>e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),ye=({size:t=12})=>e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18.36 6.64a9 9 0 1 1-12.73 0"}),e.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"12"})]}),ie=({size:t=12})=>e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),Ne=({size:t=12})=>e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),oe=new Set(["claude","codex","gemini","telegram","feishu","weixin","playwright","vscode","cursor","windsurf","finder"]),ke={github:"logos:github-icon",atlassian:"logos:atlassian",notion:"logos:notion-icon",linear:"logos:linear-icon",sentry:"logos:sentry-icon",cloudflare:"logos:cloudflare-icon","cloudflare-docs":"logos:cloudflare-icon","cloudflare-bindings":"logos:cloudflare-icon","cloudflare-observability":"logos:cloudflare-icon",slack:"logos:slack-icon",lark:"icon-park:lark",feishu:"icon-park:lark",stripe:"logos:stripe",perplexity:"logos:perplexity-icon",brave:"logos:brave","brave-search":"logos:brave",huggingface:"logos:hugging-face-icon",postgres:"logos:postgresql",postgresql:"logos:postgresql",sqlite:"logos:sqlite",vercel:"logos:vercel-icon",netlify:"logos:netlify-icon",supabase:"logos:supabase-icon",heroku:"logos:heroku-icon",docker:"logos:docker-icon",pnpm:"logos:pnpm",aws:"logos:aws","google-cloud":"logos:google-cloud",googlecloud:"logos:google-cloud",amazonwebservices:"logos:aws"},we=new Set(["stripe"]);function Ce(t,s){if(s)return s;if(!t||oe.has(t))return;const n=ke[t];if(n)return`https://api.iconify.design/${n}.svg`}function F({iconSlug:t,iconUrl:s,name:n,size:i=32,className:l}){const{hex:c,letter:x}=W(t,n),[u,h]=o.useState(!1),p=Ce(t,s),b=t&&oe.has(t),d=b||!!p&&!u,v=!!t&&we.has(t),m=Math.round(i*(v?.92:.76));return d?e.jsxs("div",{className:B("relative flex shrink-0 items-center justify-center overflow-hidden rounded-xl bg-white",l),style:{width:i,height:i,boxShadow:`0 0 0 1px ${E(c,.18)}, 0 4px 12px ${E(c,.14)}`},children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{background:`linear-gradient(135deg, ${E(c,.06)} 0%, transparent 70%)`}}),b?e.jsx(ve,{brand:t,size:m}):e.jsx("img",{src:p,alt:"",width:m,height:m,loading:"lazy",decoding:"async",onError:()=>h(!0),className:"relative"})]}):e.jsxs("div",{className:B("relative flex shrink-0 items-center justify-center overflow-hidden rounded-xl font-semibold text-white",l),style:{width:i,height:i,background:`linear-gradient(135deg, ${E(c,1)} 0%, ${E(c,.82)} 100%)`,boxShadow:`0 1px 0 rgba(255,255,255,0.08) inset, 0 6px 14px ${E(c,.28)}`,fontSize:Math.max(10,Math.round(i*.36)),letterSpacing:x.length>1?"-0.02em":0},children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{background:"radial-gradient(circle at 30% 20%, rgba(255,255,255,0.22), transparent 55%)"}}),e.jsx("span",{className:"relative",children:x})]})}function Se({state:t,locale:s}){return t==="ready"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-ok)]",style:{background:"color-mix(in oklab, var(--th-ok) 12%, transparent)"},children:[e.jsx(Z,{size:10}),a(s,"已连接","Connected")]}):t==="disabled"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-edge bg-inset/60 px-2 py-0.5 text-[10px] font-medium text-fg-5",children:[e.jsx(ye,{size:10}),a(s,"已停用","Paused")]}):t==="needs_auth"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-warn)]",style:{background:"color-mix(in oklab, var(--th-warn) 12%, transparent)"},children:[e.jsx(ie,{size:10}),a(s,"待授权","Needs auth")]}):t==="unhealthy"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-err)]",style:{background:"color-mix(in oklab, var(--th-err) 12%, transparent)"},children:[e.jsx(Ne,{size:10}),a(s,"异常","Unhealthy")]}):null}function Ie({open:t,onClose:s,locale:n,item:i,initial:l,onSubmit:c}){const[x,u]=o.useState({}),[h,p]=o.useState(!1);if(o.useEffect(()=>{if(t&&i&&i.auth.type==="credentials"){const d={};for(const v of i.auth.fields)d[v.key]=l?.[v.key]||"";u(d)}},[t,i,l]),!i||i.auth.type!=="credentials")return null;const b=i.auth.fields.some(d=>d.required&&!(x[d.key]||"").trim()),y=async()=>{p(!0);try{await c(x)}finally{p(!1)}};return e.jsxs(q,{open:t,onClose:s,children:[e.jsx(K,{title:a(n,`配置 ${i.name}`,`Configure ${i.name}`),description:n==="zh-CN"?i.descriptionZh:i.description,onClose:s}),e.jsxs("div",{className:"space-y-3",children:[i.auth.fields.map(d=>e.jsxs("div",{children:[e.jsxs("label",{className:"mb-1 flex items-center justify-between",children:[e.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:[n==="zh-CN"?d.labelZh:d.label,d.required&&e.jsx("span",{className:"ml-1 text-err",children:"*"})]}),d.helpUrl&&e.jsxs("a",{href:d.helpUrl,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-[11px] text-primary hover:text-primary/80",children:[a(n,"获取","Get one")," ",e.jsx(U,{})]})]}),e.jsx(T,{value:x[d.key]||"",onChange:v=>u({...x,[d.key]:v.target.value}),type:d.secret?"password":"text",placeholder:d.placeholder,className:"font-mono text-[12px]"})]},d.key)),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-edge pt-3",children:[e.jsx(z,{variant:"ghost",onClick:s,children:a(n,"取消","Cancel")}),e.jsx(z,{variant:"primary",disabled:h||b,onClick:y,children:h?e.jsx(P,{}):a(n,"保存并启用","Save & Enable")})]})]})]})}function ze({open:t,onClose:s,locale:n,scope:i,workdir:l,onAdded:c}){const x=G(f=>f.toast),[u,h]=o.useState(""),[p,b]=o.useState("stdio"),[y,d]=o.useState("npx"),[v,m]=o.useState(""),[S,$]=o.useState(""),[A,I]=o.useState([]),[L,j]=o.useState(!1);o.useEffect(()=>{t&&(h(""),b("stdio"),d("npx"),m(""),$(""),I([]))},[t]);const w=async()=>{if(u.trim()){j(!0);try{const f={};for(const{k:C,v:M}of A)C.trim()&&(f[C.trim()]=M);const N=p==="http"?{type:"http",url:S.trim(),enabled:!0,...Object.keys(f).length?{headers:f}:{}}:{type:"stdio",command:y.trim(),args:v.trim()?v.trim().split(/\s+/):[],enabled:!0,...Object.keys(f).length?{env:f}:{}};await _.addCustomMcp(u.trim(),N,i,l),x(a(n,`${u} 已添加`,`${u} added`),!0),c(),s()}catch(f){x(f?.message||"Failed",!1)}finally{j(!1)}}};return e.jsxs(q,{open:t,onClose:s,wide:!0,children:[e.jsx(K,{title:a(n,"添加自定义 MCP 服务","Add Custom MCP Server"),description:a(n,"不在推荐列表中的自定义服务。","For servers not in the recommended catalog."),onClose:s}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"名称","Name")}),e.jsx(T,{value:u,onChange:f=>h(f.target.value),placeholder:"my-server"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"传输","Transport")}),e.jsx("div",{className:"flex gap-1.5",children:["stdio","http"].map(f=>e.jsx("button",{onClick:()=>b(f),className:B("flex-1 rounded-md border px-3 py-1.5 text-[12px] font-medium transition-colors",p===f?"border-primary/40 bg-primary/10 text-primary":"border-edge bg-inset/50 text-fg-4 hover:bg-inset"),children:f},f))})]})]}),p==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"命令","Command")}),e.jsx(T,{value:y,onChange:f=>d(f.target.value),className:"font-mono",placeholder:"npx"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"参数","Arguments")}),e.jsx(T,{value:v,onChange:f=>m(f.target.value),className:"font-mono",placeholder:"-y @example/server"})]})]}):e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:"URL"}),e.jsx(T,{value:S,onChange:f=>$(f.target.value),className:"font-mono",placeholder:"https://example.com/mcp"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:p==="http"?a(n,"Headers","Headers"):a(n,"环境变量","Env")}),e.jsxs("button",{className:"text-[11px] font-medium text-primary hover:text-primary/80",onClick:()=>I([...A,{k:"",v:""}]),children:["+ ",a(n,"添加","Add")]})]}),A.length>0&&e.jsx("div",{className:"space-y-1 rounded-md border border-edge bg-inset/40 p-2",children:A.map((f,N)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(T,{className:"w-2/5 !h-7 !text-[12px] font-mono",value:f.k,onChange:C=>{const M=[...A];M[N]={...M[N],k:C.target.value},I(M)},placeholder:"KEY"}),e.jsx(T,{className:"flex-1 !h-7 !text-[12px] font-mono",value:f.v,onChange:C=>{const M=[...A];M[N]={...M[N],v:C.target.value},I(M)},type:/token|secret|key|bearer/i.test(f.k)?"password":"text",placeholder:"value"}),e.jsx("button",{className:"shrink-0 rounded p-1 text-fg-5 hover:text-err",onClick:()=>I(A.filter((C,M)=>M!==N)),children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},N))})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-edge pt-3",children:[e.jsx(z,{variant:"ghost",onClick:s,children:a(n,"取消","Cancel")}),e.jsx(z,{variant:"primary",disabled:!u.trim()||L,onClick:w,children:L?e.jsx(P,{}):a(n,"添加","Add")})]})]})]})}function Le({open:t,onClose:s,locale:n,scope:i,workdir:l,onInstalled:c}){const x=G(m=>m.toast),[u,h]=o.useState(""),[p,b]=o.useState(""),[y,d]=o.useState(!1);o.useEffect(()=>{t&&(h(""),b(""))},[t]);const v=async()=>{if(u.trim()){d(!0);try{const m=await _.installSkill(u.trim(),i==="global",p.trim()||void 0,l);m.ok?(x(a(n,"技能安装成功","Skill installed"),!0),c(),s()):x(m.error||"Failed",!1)}catch(m){x(m?.message||"Failed",!1)}finally{d(!1)}}};return e.jsxs(q,{open:t,onClose:s,children:[e.jsx(K,{title:a(n,"安装自定义技能","Install Custom Skill"),description:a(n,"通过 npx skills add 从 GitHub 仓库安装。","Installs via npx skills add from a GitHub repo."),onClose:s}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"GitHub 来源","GitHub Source")}),e.jsx(T,{value:u,onChange:m=>h(m.target.value),placeholder:"owner/repo",className:"font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:a(n,"指定技能(可选)","Specific skill (optional)")}),e.jsx(T,{value:p,onChange:m=>b(m.target.value),placeholder:a(n,"留空安装全部","Leave empty for all")})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-edge pt-3",children:[e.jsx(z,{variant:"ghost",onClick:s,children:a(n,"取消","Cancel")}),e.jsx(z,{variant:"primary",disabled:!u.trim()||y,onClick:v,children:y?e.jsx(P,{}):a(n,"安装","Install")})]})]})]})}function Me(t,s){return new Promise(n=>{const i=window.open(t,"pikiclaw_mcp_oauth","width=640,height=780,noopener=no");if(!i){n(!1);return}let l=!1;const c=h=>{l||(l=!0,window.removeEventListener("message",x),clearInterval(u),n(h))},x=h=>{const p=h.data;if(!(!p||p.type!=="mcp-oauth")&&!(s&&p.state!==s)){c(!!p.ok);try{i.close()}catch{}}};window.addEventListener("message",x);const u=setInterval(()=>{i.closed&&c(!1)},500)})}function ae({item:t,locale:s,busy:n,index:i,onPrimary:l,onRemove:c,onReauth:x,onReconfigure:u}){const{hex:h}=W(t.iconSlug,t.name),p=(()=>{switch(t.state){case"ready":return a(s,"停用","Pause");case"unhealthy":return a(s,"停用","Pause");case"disabled":return a(s,"启用","Enable");case"needs_auth":return t.auth.type==="mcp-oauth"?a(s,"授权","Authorize"):a(s,"配置","Configure");default:return a(s,"启用","Enable")}})(),b={background:`linear-gradient(140deg, ${E(h,.05)} 0%, ${E(h,.01)} 60%, transparent 100%)`,borderColor:E(h,.18),animationDelay:`${Math.min(i,8)*40}ms`};return e.jsxs("div",{className:B("group relative overflow-hidden rounded-xl border p-4","transition-[transform,box-shadow,border-color] duration-200","hover:-translate-y-0.5 hover:shadow-[0_12px_28px_rgba(15,23,42,0.09)]","animate-in-up"),style:b,children:[e.jsx("div",{className:"pointer-events-none absolute -right-12 -top-12 h-32 w-32 rounded-full opacity-40 blur-2xl transition-opacity duration-300 group-hover:opacity-60",style:{background:E(h,.35)}}),e.jsxs("div",{className:"relative flex items-start gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:36}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"truncate text-[14px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",className:"text-fg-5 hover:text-fg-3 transition-colors",children:e.jsx(U,{})})]}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] leading-snug text-fg-4",children:s==="zh-CN"?t.descriptionZh:t.description})]}),e.jsx(Se,{state:t.state,locale:s})]}),e.jsxs("div",{className:"relative mt-3 flex items-center justify-between border-t border-edge/60 pt-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-fg-5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{background:h,opacity:.8}}),le(s,t.auth)]}),e.jsxs("div",{className:"flex items-center gap-1",children:[t.installed&&t.state!=="needs_auth"&&x&&e.jsx(z,{variant:"ghost",size:"sm",onClick:x,disabled:n,children:a(s,"重新授权","Re-auth")}),t.installed&&t.state!=="needs_auth"&&u&&e.jsx(z,{variant:"ghost",size:"sm",onClick:u,disabled:n,children:a(s,"编辑","Edit")}),e.jsx(z,{variant:t.state==="disabled"||t.state==="needs_auth"?"primary":"ghost",size:"sm",onClick:l,disabled:n,children:n?e.jsx(P,{}):p}),t.installed&&c&&e.jsx(z,{variant:"ghost",size:"sm",onClick:c,disabled:n,className:"hover:!text-err",children:a(s,"移除","Remove")})]})]})]})}function re({item:t,locale:s,busy:n,index:i,onPrimary:l}){const c=t.auth.type==="none"?a(s,"一键启用","One-click enable"):a(s,"授权并启用","Authorize & enable");return e.jsxs("div",{className:B("group relative flex flex-col gap-3 rounded-xl border border-edge bg-panel-alt p-4","transition-[transform,box-shadow,border-color] duration-200","hover:-translate-y-0.5 hover:border-edge-h hover:shadow-[0_12px_28px_rgba(15,23,42,0.09)]","animate-in-up"),style:{animationDelay:`${Math.min(i,12)*30}ms`},children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:32}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"truncate text-[13.5px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",className:"text-fg-5 hover:text-fg-3 transition-colors",children:e.jsx(U,{})})]}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] leading-snug text-fg-4",children:s==="zh-CN"?t.descriptionZh:t.description})]})]}),e.jsxs("div",{className:"mt-auto flex items-center justify-between",children:[e.jsx("span",{className:"inline-flex items-center gap-1 text-[11px] text-fg-5",children:le(s,t.auth)}),e.jsx(z,{variant:"outline",size:"sm",onClick:l,disabled:n,className:"group-hover:border-edge-h",children:n?e.jsx(P,{}):c})]})]})}function _e(t,s){const n=t.installedNames.length;if(typeof t.totalCount=="number"){const i=t.partial?`${t.totalCount}+`:String(t.totalCount);return s==="zh-CN"?`${n} / ${i} 已安装`:`${n} / ${i} installed`}return n>0?s==="zh-CN"?`${n} 已安装`:`${n} installed`:a(s,"未安装","Not installed")}function $e({item:t,locale:s,animationDelay:n,onClick:i}){const{hex:l}=W(void 0,t.name);return e.jsxs("button",{type:"button",onClick:i,className:"animate-in-up group relative flex min-h-[112px] w-full flex-col overflow-hidden rounded-2xl border border-edge/70 bg-panel p-4 text-left transition-all duration-200 hover:-translate-y-0.5 hover:shadow-[0_12px_28px_rgba(15,23,42,0.09)] focus-visible:outline-none focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",style:{background:`linear-gradient(135deg, ${E(l,.06)} 0%, ${E(l,.02)} 100%), var(--th-panel)`,animationDelay:n},children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute -right-10 -top-10 h-28 w-28 rounded-full opacity-60",style:{background:`radial-gradient(closest-side, ${E(l,.18)}, transparent 70%)`}}),e.jsxs("div",{className:"relative flex items-start gap-3",children:[e.jsx(F,{iconUrl:t.iconUrl,name:t.name,size:36}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"text-fg-5 transition-colors hover:text-primary",children:e.jsx(U,{})})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-ok)] shrink-0",style:{background:"color-mix(in oklab, var(--th-ok) 12%, transparent)"},children:[e.jsx(Z,{size:10}),_e(t,s)]})]}),e.jsx("div",{className:"mt-0.5 truncate text-[11.5px] text-fg-5",children:t.source}),e.jsx("div",{className:"mt-1 line-clamp-2 text-[11.5px] text-fg-4",children:s==="zh-CN"?t.descriptionZh:t.description})]})]}),e.jsxs("div",{className:"relative mt-auto pt-3 flex items-center justify-between text-[10.5px] text-fg-5",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[t.stars!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 font-medium text-fg-4",children:[e.jsx(ee,{size:10}),te(t.stars)]}),t.pushedAt&&e.jsx("span",{children:ce(t.pushedAt,s)})]}),e.jsx("span",{className:"text-fg-5 group-hover:text-primary transition-colors",children:a(s,"管理 →","Manage →")})]})]})}function Ae({item:t,locale:s,animationDelay:n,onClick:i}){const{hex:l}=W(void 0,t.name);return e.jsxs("button",{type:"button",onClick:i,className:"animate-in-up group relative flex min-h-[112px] w-full flex-col overflow-hidden rounded-2xl border border-edge/60 bg-panel p-4 text-left transition-all duration-200 hover:-translate-y-0.5 hover:border-edge hover:shadow-[0_12px_28px_rgba(15,23,42,0.07)] focus-visible:outline-none focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",style:{animationDelay:n},children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(F,{iconUrl:t.iconUrl,name:t.name,size:32}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"text-fg-5 transition-colors hover:text-primary",children:e.jsx(U,{})})]}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[11.5px] text-fg-4",children:s==="zh-CN"?t.descriptionZh:t.description})]})]}),e.jsxs("div",{className:"mt-auto pt-3 flex items-center justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2 text-[11px] text-fg-5",children:[t.stars!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 font-medium text-fg-4",children:[e.jsx(ee,{size:10}),te(t.stars)]}),typeof t.totalCount=="number"&&e.jsxs("span",{children:["· ",t.partial?`${t.totalCount}+`:t.totalCount," skills"]})]}),e.jsx("span",{className:"inline-flex items-center gap-1 rounded-md px-2.5 py-1 text-[11px] font-semibold transition-colors group-hover:text-primary",style:{background:`${E(l,.08)}`,color:l},children:a(s,"查看 →","Browse →")})]})]})}function Ee({item:t,open:s,onClose:n,onChanged:i,locale:l,scope:c,workdir:x,installedSkills:u}){const h=G(g=>g.toast),[p,b]=o.useState(null),[y,d]=o.useState(!1),[v,m]=o.useState(null),[S,$]=o.useState(!1),[A,I]=o.useState(null),[L,j]=o.useState(null),[w,f]=o.useState("");o.useEffect(()=>{if(!s||!t)return;let g=!1;return d(!0),m(null),f(""),(async()=>{try{const r=await _.listRepoSkills(t.source);if(g)return;r.ok?(b(r.skills),$(!!r.partial)):(m(r.error||"failed to list"),b([]))}catch(r){if(g)return;m(r?.message||"failed"),b([])}finally{g||d(!1)}})(),()=>{g=!0}},[s,t?.source]);const N=o.useMemo(()=>{const g=new Set,r=c==="global"?"global":"project";for(const k of u)k.scope===r&&g.add(k.name.toLowerCase());return g},[u,c]),C=o.useMemo(()=>{const g=p||[],r=w.trim().toLowerCase();return r?g.filter(k=>k.name.toLowerCase().includes(r)):g},[p,w]),M=o.useMemo(()=>p?p.filter(g=>N.has(g.name.toLowerCase())).length:0,[p,N]),R=o.useCallback(async g=>{if(t){I(g);try{const r=await _.installSkill(t.source,c==="global",g,x);r.ok?(h(a(l,`${g} 已安装`,`${g} installed`),!0),i()):h(r.error||"Failed",!1)}catch(r){h(r?.message||"Failed",!1)}finally{I(null)}}},[t,c,x,l,h,i]),D=o.useCallback(async g=>{I(g);try{const r=await _.removeExtensionSkill(g,c==="global",x);r.ok?(h(a(l,`${g} 已移除`,`${g} removed`),!0),i()):h(r.error||"Failed",!1)}catch(r){h(r?.message||"Failed",!1)}finally{I(null)}},[c,x,l,h,i]),V=o.useCallback(async()=>{if(t){j("install");try{const g=await _.installSkill(t.source,c==="global",void 0,x);g.ok?(h(a(l,"全部安装完成","All skills installed"),!0),i()):h(g.error||"Failed",!1)}catch(g){h(g?.message||"Failed",!1)}finally{j(null)}}},[t,c,x,l,h,i]),Y=o.useCallback(async()=>{if(!(!t||!p)){j("remove");try{const g=p.map(r=>r.name).filter(r=>N.has(r.toLowerCase()));for(const r of g)await _.removeExtensionSkill(r,c==="global",x);h(a(l,"已移除该集合下的全部技能","Removed all skills from this collection"),!0),i()}catch(g){h(g?.message||"Failed",!1)}finally{j(null)}}},[t,p,N,c,x,l,h,i]);return t?e.jsxs(q,{open:s,onClose:n,wide:!0,children:[e.jsx(K,{title:t.name,description:l==="zh-CN"?t.descriptionZh:t.description,onClose:n}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{iconUrl:t.iconUrl,name:t.name,size:44}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-semibold text-fg",children:[t.name,t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",className:"text-fg-5 hover:text-primary",children:e.jsx(U,{})})]}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11.5px] text-fg-4",children:[e.jsx("span",{className:"truncate text-fg-5",children:t.source}),t.stars!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-fg-5",children:[e.jsx(ee,{size:10}),te(t.stars)]}),t.pushedAt&&e.jsxs("span",{className:"text-fg-5",children:["· ",ce(t.pushedAt,l)]})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"text-[12px] font-semibold text-fg-3",children:[a(l,"该集合下的技能","Skills in this collection"),p&&e.jsxs("span",{className:"ml-2 text-[11px] font-normal text-fg-5",children:[M," / ",S?`${p.length}+`:p.length," ",a(l,"已安装","installed")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{variant:"outline",size:"sm",onClick:V,disabled:L!==null||y,children:L==="install"?e.jsx(P,{}):a(l,"全部安装","Install all")}),M>0&&e.jsx(z,{variant:"ghost",size:"sm",onClick:Y,disabled:L!==null,className:"hover:!text-err",children:L==="remove"?e.jsx(P,{}):a(l,"全部移除","Remove all")})]})]}),p&&p.length>6&&e.jsx(T,{type:"text",value:w,onChange:g=>f(g.target.value),placeholder:a(l,"搜索技能…","Search skills…"),className:"w-full"}),y?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(P,{})}):v?e.jsxs("div",{className:"rounded-lg border border-edge/70 bg-panel/60 p-3 text-[12px] text-fg-4",children:[a(l,"无法从 GitHub 拉取技能列表(可能是网络或速率限制)。你仍可以使用上方的「全部安装」按钮一次性安装该集合。",'Could not list skills from GitHub (network or rate-limit). You can still use "Install all" to grab the whole collection.'),e.jsx("div",{className:"mt-1 truncate font-mono text-[11px] text-fg-5",children:v})]}):C.length===0?e.jsx("div",{className:"rounded-lg border border-edge/70 bg-panel/60 p-3 text-center text-[12px] text-fg-5",children:w?a(l,"没有匹配的技能","No matching skills"):a(l,"该集合暂无可识别的技能","No discoverable skills in this collection")}):e.jsx("div",{className:"max-h-[60vh] overflow-y-auto rounded-lg border border-edge/70 bg-panel/40",children:C.map((g,r)=>{const k=N.has(g.name.toLowerCase()),O=A===g.name;return e.jsxs("div",{className:B("flex items-center justify-between gap-3 px-3 py-2 text-[12px]",r>0&&"border-t border-edge/40"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[k&&e.jsx(Z,{size:12}),e.jsx("span",{className:B("truncate font-medium",k?"text-[var(--th-ok)]":"text-fg-2"),children:g.name})]}),g.description&&e.jsx("div",{className:"mt-0.5 line-clamp-1 text-[11px] text-fg-5",children:g.description})]}),k?e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{D(g.name)},disabled:O||L!==null,className:"hover:!text-err",children:O?e.jsx(P,{}):a(l,"移除","Remove")}):e.jsx(z,{variant:"outline",size:"sm",onClick:()=>{R(g.name)},disabled:O||L!==null,children:O?e.jsx(P,{}):a(l,"安装","Install")})]},g.name)})}),S&&e.jsx("div",{className:"text-[11px] text-fg-5",children:a(l,"仓库内技能数量较多,仅显示前 1000 个。可使用上方搜索或直接打开仓库浏览全部。","Showing the first 1000 skills. Use search or open the repo on GitHub for the full list.")})]})]})]}):null}const ee=({size:t=12})=>e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:e.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})});function te(t){return t>=1e4?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}k`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function ce(t,s){const n=Date.parse(t);if(!Number.isFinite(n))return"";const i=Date.now()-n,l=1440*60*1e3,c=Math.max(1,Math.floor(i/l));if(c<30)return s==="zh-CN"?`${c} 天前`:`${c}d ago`;const x=Math.floor(c/30);if(x<12)return s==="zh-CN"?`${x} 个月前`:`${x}mo ago`;const u=Math.floor(x/12);return s==="zh-CN"?`${u} 年前`:`${u}y ago`}const H={dev:{zh:"开发工具",en:"Development",order:0},productivity:{zh:"生产力",en:"Productivity",order:1},communication:{zh:"协作沟通",en:"Communication",order:2},data:{zh:"数据",en:"Data",order:3},search:{zh:"搜索",en:"Search",order:4},utility:{zh:"工具",en:"Utility",order:5},custom:{zh:"自定义",en:"Custom",order:6}};function Re(t){const s=new Map;for(const n of t){const i=s.get(n.category)||[];i.push(n),s.set(n.category,i)}return[...s.entries()].sort((n,i)=>(H[n[0]]?.order??99)-(H[i[0]]?.order??99)).map(([n,i])=>({key:n,items:i}))}function de({scope:t,workdir:s,locale:n,onOpenBrowserSetup:i}){const l=G(r=>r.toast),c=`pikiclaw.mcp.catalog.${t}.${s||""}`,{data:x,loading:u,refresh:h}=X(c,async()=>(await _.getMcpCatalog(s,t)).items||[],[s,t]),[p,b]=o.useState(""),[y,d]=o.useState(null),[v,m]=o.useState(!1),[S,$]=o.useState(null),A=x||[],I=o.useMemo(()=>A.filter(r=>!r.installed||r.scope===t||!r.scope),[A,t]),L=o.useMemo(()=>{if(!p.trim())return I;const r=p.trim().toLowerCase();return I.filter(k=>k.name.toLowerCase().includes(r)||k.description.toLowerCase().includes(r)||k.descriptionZh.includes(r)||k.id.toLowerCase().includes(r))},[I,p]),j=o.useMemo(()=>L.filter(r=>r.isBuiltin),[L]),w=o.useMemo(()=>L.filter(r=>!r.isBuiltin&&(r.state==="ready"||r.state==="unhealthy")),[L]),f=o.useMemo(()=>Re(L.filter(r=>!r.isBuiltin&&r.state!=="ready"&&r.state!=="unhealthy")),[L]),N=o.useCallback(async(r,k)=>{if(r.isRecommended){$(r.id);try{const O=await _.installMcp(r.id,t,k,s,!0);if(!O.ok)throw new Error(O.error||"install failed");return await h(),O.enabled??!1}catch(O){return l(O?.message||"Failed",!1),!1}finally{$(null)}}},[t,s,h,l]),C=o.useCallback(async r=>{$(r.id);try{if(!r.installed){const ne=await _.installMcp(r.id,t,void 0,s,!1);if(!ne.ok)throw new Error(ne.error||"install failed")}const k=await _.startMcpOAuth(r.id);if(!k.ok||!k.authUrl||!k.state)throw new Error(k.error||"oauth start failed");await Me(k.authUrl,k.state)?(await _.toggleMcp(r.id,!0,t,s),l(a(n,`${r.name} 授权成功`,`${r.name} authorized`),!0)):l(a(n,"授权未完成","Authorization not completed"),!1),await h()}catch(k){l(k?.message||"OAuth failed",!1)}finally{$(null)}},[t,s,n,l,h]),M=o.useCallback(async(r,k)=>{if(r.installedKey){$(r.id);try{await _.toggleMcp(r.installedKey,k,r.scope==="workspace"?"workspace":"global",s),await h()}catch(O){l(O?.message||"Failed",!1)}finally{$(null)}}},[s,h,l]),R=o.useCallback(async r=>{if(r.installedKey){$(r.id);try{await _.removeMcp(r.installedKey,r.scope==="workspace"?"workspace":"global",r.isRecommended?r.id:void 0,s),await h()}catch(k){l(k?.message||"Failed",!1)}finally{$(null)}}},[s,h,l]),D=o.useCallback(async r=>{if(!y)return;await N(y,r)!==!1&&d(null)},[y,N]),V=o.useCallback(r=>{if(r.state==="ready"||r.state==="unhealthy"){M(r,!1);return}if(r.state==="disabled"){M(r,!0);return}if(r.state==="needs_auth"){if(r.auth.type==="mcp-oauth"){C(r);return}if(r.auth.type==="credentials"){d(r);return}}},[M,C]),Y=o.useCallback(r=>{if(r.state==="disabled"){M(r,!0);return}if(r.state==="needs_auth"){if(r.auth.type==="mcp-oauth"){C(r);return}if(r.auth.type==="credentials"){d(r);return}}if(r.auth.type==="mcp-oauth"){C(r);return}if(r.auth.type==="credentials"){d(r);return}N(r)},[C,N,M]),g=u&&!x;return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Q,{children:"MCP Servers"}),!u&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:[w.length," ",a(n,"在用","in use")," · ",I.length-w.length-j.length," ",a(n,"可添加","available")]}),u&&e.jsx(P,{className:"h-3 w-3"})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:p,onChange:r=>b(r.target.value),placeholder:a(n,"搜索...","Search..."),className:"h-7 w-52 rounded-md border border-edge bg-inset/50 pl-7 pr-2.5 text-[12px] text-fg outline-none placeholder:text-fg-5/50 focus:border-primary/30 focus:bg-inset"})]})})]}),g?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(P,{})}):e.jsxs("div",{className:"space-y-5",children:[j.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--th-accent,#7c3aed)]"}),a(n,"内置(pikiclaw 优化)","Built-in (optimized by pikiclaw)")]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:j.map((r,k)=>r.installed?e.jsx(ae,{item:r,locale:n,busy:S===r.id,index:k,onPrimary:()=>V(r),onReconfigure:i},r.id):e.jsx(re,{item:r,locale:n,busy:S===r.id,index:k,onPrimary:()=>Y(r)},r.id))})]}),w.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--th-ok)]"}),a(n,"在用","In use")]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:w.map((r,k)=>e.jsx(ae,{item:r,locale:n,busy:S===r.id,index:k,onPrimary:()=>V(r),onRemove:()=>{R(r)},onReauth:r.auth.type==="mcp-oauth"?()=>{C(r)}:void 0,onReconfigure:r.auth.type==="credentials"?()=>d(r):void 0},r.id))})]}),f.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5"}),w.length===0?a(n,"推荐的服务","Recommended services"):a(n,"更多可选","More options")]}),e.jsx("div",{className:"space-y-4",children:f.map(r=>e.jsx(Oe,{groupKey:r.key,locale:n,children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:r.items.map((k,O)=>e.jsx(re,{item:k,locale:n,busy:S===k.id,index:O,onPrimary:()=>Y(k)},k.id))})},r.key))})]}),j.length===0&&w.length===0&&f.length===0&&e.jsx(se,{title:a(n,"没有匹配的服务","No matching services"),subtitle:a(n,"试试别的关键词","Try a different search term")})]}),e.jsx("div",{className:"mt-3 flex justify-end",children:e.jsxs("button",{className:"text-[12px] text-fg-4 hover:text-fg-2 transition-colors",onClick:()=>m(!0),children:["+ ",a(n,"添加自定义 MCP","Add custom MCP")]})}),e.jsx(Ie,{open:!!y,onClose:()=>d(null),locale:n,item:y,initial:y?.config?.env||y?.config?.headers,onSubmit:D}),e.jsx(ze,{open:v,onClose:()=>m(!1),locale:n,scope:t,workdir:s,onAdded:h})]})}function Oe({groupKey:t,locale:s,children:n}){const i=H[t],l=i?a(s,i.zh,i.en):t;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-[11px] font-medium text-fg-5",children:l}),n]})}function se({title:t,subtitle:s}){return e.jsxs("div",{className:"rounded-xl border border-dashed border-edge py-10 text-center",children:[e.jsx("div",{className:"text-[13px] font-medium text-fg-3",children:t}),s&&e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:s})]})}function xe({scope:t,workdir:s,locale:n}){const i=`pikiclaw.skills.catalog.${t}.${s||""}`,{data:l,loading:c,refresh:x}=X(i,async()=>{const j=await _.getSkillsCatalog(s,t);return{items:j.items||[],installed:j.installed||[]}},[s,t]),[u,h]=o.useState(!1),[p,b]=o.useState(null),y=l?.items||[],d=l?.installed||[],v=o.useMemo(()=>{const j=t==="global"?"global":"project";return d.filter(w=>w.scope===j)},[d,t]),m=o.useMemo(()=>y.filter(j=>j.installedNames.length>0),[y]),S=o.useMemo(()=>y.filter(j=>j.installedNames.length===0),[y]),$=o.useMemo(()=>{const j=new Map;for(const w of S){const f=w.category;j.has(f)||j.set(f,[]),j.get(f).push(w)}return[...j.entries()].sort(([w],[f])=>(H[w]?.order??99)-(H[f]?.order??99))},[S]),A=p&&y.find(j=>j.id===p)||null,I=c&&!l,L=v.length;return e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Q,{children:"Skills"}),!c&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:[L," ",a(n,"已安装","installed")," · ",S.length," ",a(n,"可用","available")]}),c&&e.jsx(P,{className:"h-3 w-3"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{x()},children:c?a(n,"刷新中…","Refreshing…"):a(n,"刷新","Refresh")}),e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>h(!0),children:["+ ",a(n,"从 GitHub 安装","Install from GitHub")]})]})]}),I?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(P,{})}):y.length===0?e.jsx(se,{title:a(n,"暂无可用的技能包","No skill packs available"),subtitle:a(n,"从 GitHub 导入一个开始使用","Import from GitHub to get started")}):e.jsxs(e.Fragment,{children:[m.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-fg-3",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-[var(--th-ok)]"}),a(n,"已安装","Installed")]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:m.map((j,w)=>e.jsx($e,{item:j,locale:n,animationDelay:`${Math.min(w,12)*30}ms`,onClick:()=>b(j.id)},j.id))})]}),S.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-fg-3",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-fg-5/50"}),a(n,"推荐","Available")]}),$.map(([j,w])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[10.5px] font-medium uppercase tracking-[0.06em] text-fg-5",children:n==="zh-CN"?H[j]?.zh||j:H[j]?.en||j}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:w.map((f,N)=>e.jsx(Ae,{item:f,locale:n,animationDelay:`${Math.min(N,12)*30}ms`,onClick:()=>b(f.id)},f.id))})]},j))]})]}),e.jsx(Ee,{item:A,open:!!A,onClose:()=>b(null),onChanged:()=>{x()},locale:n,scope:t,workdir:s,installedSkills:d}),e.jsx(Le,{open:u,onClose:()=>h(!1),locale:n,scope:t,workdir:s,onInstalled:x})]})}const J={dev:{zh:"开发工具",en:"Developer",order:1},cloud:{zh:"云平台",en:"Cloud",order:2},data:{zh:"数据",en:"Data",order:3},productivity:{zh:"生产力",en:"Productivity",order:4}};function ue({state:t,locale:s}){return t==="ready"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-[var(--th-ok)]",style:{background:"color-mix(in oklab, var(--th-ok) 12%, transparent)"},children:[e.jsx(Z,{size:10}),a(s,"已登录","Signed in")]}):t==="installed_not_auth"?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold text-amber-600 dark:text-amber-400",style:{background:"color-mix(in oklab, #f59e0b 14%, transparent)"},children:[e.jsx(ie,{size:10}),a(s,"待登录","Sign-in needed")]}):t==="not_installed"?e.jsx("span",{className:"inline-flex items-center gap-1 rounded-full border border-edge bg-inset/60 px-2 py-0.5 text-[10px] font-medium text-fg-5",children:a(s,"未安装","Not installed")}):e.jsx("span",{className:"inline-flex items-center gap-1 rounded-full border border-edge bg-inset/60 px-2 py-0.5 text-[10px] font-medium text-fg-5",children:"..."})}function he({chunks:t,running:s,emptyHint:n}){const i=o.useRef(null);o.useEffect(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},[t.length]);const l=t.join("");return e.jsx("div",{ref:i,className:"relative h-56 overflow-auto rounded-xl border border-edge/60 bg-[#0b0f16] p-3 font-mono text-[11.5px] leading-[1.55] text-[#cdd6f4] scrollbar-thin",style:{boxShadow:"0 1px 0 rgba(255,255,255,0.03) inset"},children:l?e.jsx("pre",{className:"whitespace-pre-wrap break-words",children:l}):e.jsx("div",{className:"flex h-full items-center justify-center text-[#6c7086]",children:s?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(P,{})," ",n||"Starting…"]}):n||"No output yet"})})}function Pe({cli:t,locale:s,onInstalled:n}){const[i,l]=o.useState([]),[c,x]=o.useState(!1),[u,h]=o.useState(null),[p,b]=o.useState(null),[y,d]=o.useState(null),v=o.useRef(null),m=o.useCallback(()=>{try{v.current?.close()}catch{}v.current=null},[]);o.useEffect(()=>m,[m]);const S=o.useCallback(async()=>{l([]),b(null),d(null),x(!0);try{const I=await _.startCliInstall(t.id);if(!I.ok||!I.sessionId)throw new Error(I.error||"start failed");h(I.sessionId);const L=new EventSource(`/api/extensions/cli/auth/stream?sessionId=${encodeURIComponent(I.sessionId)}`);v.current=L,L.onmessage=j=>{try{const w=JSON.parse(j.data);w.type==="output"?l(f=>f.length>400?[...f.slice(-400),w.chunk]:[...f,w.chunk]):w.type==="error"?b(w.message||"error"):w.type==="done"&&(x(!1),d(!!w.ok),m(),w.ok&&n())}catch{}},L.addEventListener("close",()=>{x(!1),m()}),L.onerror=()=>{c&&b(a(s,"连接中断","Stream disconnected"))}}catch(I){x(!1),b(I?.message||"failed to start install")}},[t.id,m,s,n,c]),$=o.useCallback(async()=>{if(u)try{await _.cancelCliAuth(u)}catch{}m(),x(!1)},[u,m]);if(!t.autoInstall)return null;const A=c||i.length>0||y!==null;return e.jsxs("div",{className:"space-y-3 rounded-lg border border-edge/70 bg-panel/60 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-fg-3",children:a(s,`通过 ${t.autoInstall.label} 直接在本机自动安装,无需复制命令。`,`Run the ${t.autoInstall.label} install locally — no copy-paste needed.`)}),c?e.jsx(z,{variant:"outline",size:"sm",onClick:$,children:a(s,"中止","Abort")}):e.jsx(z,{variant:"primary",size:"sm",onClick:S,disabled:y===!0,children:y===!0?a(s,"已安装","Installed"):y===!1?a(s,"重试安装","Retry install"):a(s,"一键安装","Auto-install")})]}),A&&e.jsx(he,{chunks:i,running:c,emptyHint:a(s,"安装进度将在此显示","Install output will appear here")}),p&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:p}),y===!1&&!p&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:a(s,"安装未成功,请查看上方输出排查。","Install did not complete — check the output above.")})]})}function Te({cli:t,locale:s,onSignedIn:n,onCancel:i}){const[l,c]=o.useState([]),[x,u]=o.useState(!1),[h,p]=o.useState(null),[b,y]=o.useState(null),[d,v]=o.useState(null),m=o.useRef(null),S=o.useCallback(()=>{try{m.current?.close()}catch{}m.current=null},[]);o.useEffect(()=>S,[S]);const $=o.useCallback(async()=>{c([]),v(null),y(null),u(!0);try{const N=await _.startCliAuth(t.id);if(!N.ok||!N.sessionId)throw new Error(N.error||"start failed");p(N.sessionId);const C=new EventSource(`/api/extensions/cli/auth/stream?sessionId=${encodeURIComponent(N.sessionId)}`);m.current=C,C.onmessage=M=>{try{const R=JSON.parse(M.data);R.type==="output"?c(D=>D.length>400?[...D.slice(-400),R.chunk]:[...D,R.chunk]):R.type==="status"?y(R.status.state==="ready"?a(s,"已检测到登录成功","Sign-in detected"):a(s,"等待授权完成…","Waiting for authorization…")):R.type==="error"?v(R.message||"error"):R.type==="done"&&(u(!1),S(),R.ok&&n())}catch{}},C.addEventListener("close",()=>{u(!1),S()}),C.onerror=()=>{x&&v(a(s,"连接中断","Stream disconnected"))}}catch(N){u(!1),v(N?.message||"failed to start sign-in")}},[t.id,S,s,n,x]),A=o.useCallback(async()=>{if(h)try{await _.cancelCliAuth(h)}catch{}S(),u(!1),i()},[h,S,i]),[I,L]=o.useState({}),[j,w]=o.useState(!1),f=o.useCallback(async()=>{w(!0),v(null);try{const N=await _.applyCliToken(t.id,I);N.ok?n():v(N.error||a(s,"应用凭据失败","Failed to apply credentials"))}catch(N){v(N?.message||"failed")}finally{w(!1)}},[t.id,I,s,n]);if(t.auth.type==="oauth-web"){const N=s==="zh-CN"&&t.auth.loginHintZh||t.auth.loginHint;return e.jsxs("div",{className:"space-y-3",children:[N&&e.jsx("div",{className:"text-[12px] leading-relaxed text-fg-4",children:N}),e.jsx(he,{chunks:l,running:x,emptyHint:a(s,"点击「开始登录」后将在此展示命令行输出",'Click "Start sign-in" to stream CLI output here')}),d&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:d}),b&&!d&&e.jsx("div",{className:"text-[12px] text-[var(--th-ok)]",children:b}),e.jsx("div",{className:"flex items-center gap-2",children:x?e.jsx(z,{variant:"outline",size:"sm",onClick:A,children:a(s,"中止","Abort")}):e.jsxs(e.Fragment,{children:[e.jsx(z,{variant:"primary",size:"sm",onClick:$,children:a(s,"开始登录","Start sign-in")}),e.jsx(z,{variant:"ghost",size:"sm",onClick:i,children:a(s,"取消","Cancel")})]})})]})}if(t.auth.type==="token"){const N=s==="zh-CN"&&t.auth.loginHintZh||t.auth.loginHint;return e.jsxs("div",{className:"space-y-3",children:[N&&e.jsx("div",{className:"text-[12px] leading-relaxed text-fg-4",children:N}),e.jsx("div",{className:"space-y-2",children:(t.auth.tokenFields||[]).map(C=>e.jsxs("label",{className:"block text-[12px]",children:[e.jsxs("div",{className:"mb-1 text-fg-3",children:[s==="zh-CN"?C.labelZh:C.label,C.required&&e.jsx("span",{className:"ml-1 text-[var(--th-err)]",children:"*"})]}),e.jsx(T,{type:C.secret?"password":"text",value:I[C.key]||"",onChange:M=>L(R=>({...R,[C.key]:M.target.value})),placeholder:C.placeholder||"",className:"w-full"}),C.helpUrl&&e.jsxs("a",{className:"mt-1 inline-block text-[11px] text-primary hover:underline",href:C.helpUrl,target:"_blank",rel:"noreferrer",children:[a(s,"如何获取","How to get this")," ↗"]})]},C.key))}),d&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:d}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{variant:"primary",size:"sm",onClick:f,disabled:j,children:j?a(s,"验证中…","Verifying…"):a(s,"保存并验证","Save & verify")}),e.jsx(z,{variant:"ghost",size:"sm",onClick:i,children:a(s,"取消","Cancel")})]})]})}return null}function Be({commands:t,locale:s}){return e.jsx("div",{className:"space-y-2",children:t.map((n,i)=>e.jsxs("div",{className:"overflow-hidden rounded-lg border border-edge/70 bg-panel/60",children:[n.label&&e.jsx("div",{className:"flex items-center justify-between border-b border-edge/50 bg-panel-alt/40 px-3 py-1 text-[11px] font-medium text-fg-4",children:e.jsx("span",{children:n.label})}),e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 font-mono text-[12px] text-fg-2",children:[e.jsx("span",{className:"mt-[2px] select-none text-fg-5",children:"$"}),e.jsx("code",{className:"min-w-0 flex-1 break-all",children:n.cmd}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(n.cmd)},className:"shrink-0 rounded px-2 py-0.5 text-[10.5px] text-fg-5 transition-colors hover:bg-panel-h hover:text-fg-2",title:a(s,"复制到剪贴板","Copy to clipboard"),children:a(s,"复制","Copy")})]})]},i))})}function Ue({cli:t,open:s,onClose:n,onChanged:i,locale:l}){const[c,x]=o.useState(!1),[u,h]=o.useState(!1),[p,b]=o.useState(null);o.useEffect(()=>{s||(x(!1),b(null))},[s]);const y=o.useMemo(()=>t?t.install[t.platform]||[]:[],[t]);if(!t)return null;const d=t.state!=="not_installed",v=t.state==="ready",m=async()=>{h(!0),b(null);try{const S=await _.logoutCli(t.id);S.ok||b(S.error||a(l,"登出失败","Logout failed")),i()}catch(S){b(S?.message||"failed")}finally{h(!1)}};return e.jsxs(q,{open:s,onClose:n,wide:!0,children:[e.jsx(K,{title:t.name,description:l==="zh-CN"?t.descriptionZh:t.description,onClose:n}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:44}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-semibold text-fg",children:[t.name,t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",className:"text-fg-5 hover:text-primary",children:e.jsx(U,{})})]}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11.5px] text-fg-4",children:[ue({state:t.state,locale:l}),t.version&&e.jsxs("span",{className:"font-mono text-fg-5",children:["v",t.version]}),v&&t.authDetail&&e.jsxs("span",{className:"truncate text-fg-5",children:["· ",t.authDetail]})]})]})]}),!d&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("div",{className:"text-[12px] font-semibold text-fg-3",children:a(l,"安装","Install")}),t.autoInstall&&e.jsx(Pe,{cli:t,locale:l,onInstalled:i}),e.jsx("div",{className:"text-[11.5px] leading-relaxed text-fg-5",children:t.autoInstall?a(l,"或手动复制命令到终端执行。","Or copy a command below and run it in your terminal."):a(l,"复制下面的命令到终端运行。我们不自动代为安装 — 包管理器往往需要 sudo 或交互式确认。","Copy a command below and run it in your terminal. We don't auto-install — package managers often need sudo or interactive confirmation.")}),y.length>0?e.jsx(Be,{commands:y,locale:l}):e.jsx("div",{className:"text-[12px] text-fg-5",children:a(l,"请查看官方文档","Check the official installation docs")}),t.install.docs&&e.jsxs("a",{href:t.install.docs,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[11.5px] text-primary hover:underline",children:[a(l,"查看安装文档","Installation docs")," ↗"]}),e.jsx("div",{className:"pt-2",children:e.jsx(z,{variant:"outline",size:"sm",onClick:i,children:a(l,"我已安装,重新检测","I've installed, re-check")})})]}),d&&t.auth.type!=="none"&&e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-[12px] font-semibold text-fg-3",children:a(l,"登录","Sign in")}),v&&!c&&e.jsx(z,{variant:"ghost",size:"sm",onClick:m,disabled:u,children:u?a(l,"登出中…","Signing out…"):a(l,"登出","Sign out")})]}),p&&e.jsx("div",{className:"text-[11.5px] text-[var(--th-err)]",children:p}),v&&!c?e.jsxs("div",{className:"rounded-lg border border-edge/70 bg-panel/60 p-3 text-[12px] text-fg-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{size:12}),e.jsx("span",{children:a(l,"你已经登录,命令行工具可直接使用。","Already signed in — the CLI is ready to use.")})]}),e.jsx("div",{className:"mt-2",children:e.jsx(z,{variant:"outline",size:"sm",onClick:()=>x(!0),children:a(l,"重新登录","Re-authenticate")})})]}):e.jsx(Te,{cli:t,locale:l,onSignedIn:()=>{x(!1),i()},onCancel:()=>x(!1)})]}),d&&t.auth.type==="none"&&e.jsx("section",{className:"rounded-lg border border-edge/70 bg-panel/60 p-3 text-[12px] text-fg-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{size:12}),e.jsx("span",{children:a(l,"无需授权 — 可直接使用。","No authentication required — ready to use.")})]})})]})]})}function Fe({item:t,onClick:s,locale:n,animationDelay:i}){const{hex:l}=W(t.iconSlug,t.name);return e.jsxs("button",{type:"button",onClick:s,className:"animate-in-up group relative flex min-h-[112px] w-full flex-col overflow-hidden rounded-2xl border border-edge/70 bg-panel p-4 text-left transition-all duration-200 hover:-translate-y-0.5 hover:shadow-[0_12px_28px_rgba(15,23,42,0.09)] focus-visible:outline-none focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",style:{background:`linear-gradient(135deg, ${E(l,.06)} 0%, ${E(l,.02)} 100%), var(--th-panel)`,animationDelay:i},children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute -right-10 -top-10 h-28 w-28 rounded-full opacity-60",style:{background:`radial-gradient(closest-side, ${E(l,.18)}, transparent 70%)`}}),e.jsxs("div",{className:"relative flex items-start gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:36}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"truncate text-[13px] font-semibold text-fg",children:t.name}),ue({state:t.state,locale:n})]}),e.jsxs("div",{className:"mt-0.5 truncate text-[11.5px] text-fg-5",children:[t.version?e.jsxs("span",{className:"font-mono",children:["v",t.version]}):null,t.version&&t.authDetail?" · ":null,t.authDetail]}),e.jsx("div",{className:"mt-1 truncate text-[11.5px] text-fg-4",children:n==="zh-CN"?t.descriptionZh:t.description})]})]})]})}function De({item:t,onClick:s,locale:n,animationDelay:i}){const{hex:l}=W(t.iconSlug,t.name),c=t.state==="not_installed"?a(n,"安装","Install"):t.state==="installed_not_auth"?a(n,"登录","Sign in"):a(n,"查看","Details");return e.jsxs("button",{type:"button",onClick:s,className:"animate-in-up group relative flex min-h-[112px] w-full flex-col overflow-hidden rounded-2xl border border-edge/60 bg-panel p-4 text-left transition-all duration-200 hover:-translate-y-0.5 hover:border-edge hover:shadow-[0_12px_28px_rgba(15,23,42,0.07)] focus-visible:outline-none focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",style:{animationDelay:i},children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(F,{iconSlug:t.iconSlug,iconUrl:t.iconUrl,name:t.name,size:32}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-fg",children:t.name}),t.homepage&&e.jsx("a",{href:t.homepage,target:"_blank",rel:"noreferrer",onClick:x=>x.stopPropagation(),className:"text-fg-5 transition-colors hover:text-primary",children:e.jsx(U,{})})]}),e.jsx("div",{className:"mt-0.5 truncate text-[11.5px] text-fg-4",children:n==="zh-CN"?t.descriptionZh:t.description})]})]}),e.jsxs("div",{className:"mt-auto pt-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] text-fg-5",children:t.auth.type==="oauth-web"?a(n,"浏览器授权","OAuth"):t.auth.type==="token"?a(n,"Token","Token"):a(n,"免配置","No auth")}),e.jsx("span",{className:"inline-flex items-center gap-1 rounded-md px-2.5 py-1 text-[11px] font-semibold transition-colors group-hover:text-primary",style:{background:`${E(l,.08)}`,color:l},children:c})]})]})}function pe({locale:t,scope:s}){const{data:n,loading:i,refresh:l}=X("pikiclaw:cli:catalog",async()=>{const d=await _.getCliCatalog();if(!d.ok)throw new Error(d.error||"failed");return d.items||[]},[]),[c,x]=o.useState(null),u=o.useMemo(()=>{const d=n||[];return d},[n,s]),h=c&&u.find(d=>d.id===c)||null,p=u.filter(d=>d.state==="ready"),b=u.filter(d=>d.state!=="ready"),y=o.useMemo(()=>{const d=new Map;for(const v of b){const m=v.category;d.has(m)||d.set(m,[]),d.get(m).push(v)}return[...d.entries()].sort(([v],[m])=>(J[v]?.order??99)-(J[m]?.order??99))},[b]);return e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Q,{children:a(t,"CLI 工具","CLI Tools")}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-fg-5",children:[e.jsxs("span",{children:[p.length," ",a(t,"已登录","signed in")," · ",b.length," ",a(t,"可用","available")]}),e.jsx("button",{type:"button",onClick:()=>{l()},className:"rounded px-2 py-0.5 text-fg-5 transition-colors hover:bg-panel-h hover:text-fg-2",children:i?a(t,"刷新中…","Refreshing…"):a(t,"刷新","Refresh")})]})]}),s==="workspace"&&e.jsx("div",{className:"rounded-lg border border-edge/60 bg-inset/40 px-3 py-2 text-[11.5px] text-fg-4",children:a(t,"CLI 工具安装于机器层面,项目视图下同样可见。","CLI tools are installed machine-wide and are shown here for convenience.")}),p.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-fg-3",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-[var(--th-ok)]"}),a(t,"已登录","Signed in")]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:p.map((d,v)=>e.jsx(Fe,{item:d,locale:t,animationDelay:`${Math.min(v,12)*30}ms`,onClick:()=>x(d.id)},d.id))})]}),b.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-fg-3",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-fg-5/50"}),a(t,"推荐工具","Available")]}),y.map(([d,v])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[10.5px] font-medium uppercase tracking-[0.06em] text-fg-5",children:t==="zh-CN"?J[d]?.zh||d:J[d]?.en||d}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:v.map((m,S)=>e.jsx(De,{item:m,locale:t,animationDelay:`${Math.min(S,12)*30}ms`,onClick:()=>x(m.id)},m.id))})]},d))]}),!i&&u.length===0&&e.jsx(se,{title:a(t,"暂无可用 CLI","No CLI tools available"),subtitle:a(t,"稍后再试,或重启一下服务。","Try again later, or restart the service.")}),e.jsx(Ue,{cli:h,open:!!h,onClose:()=>x(null),onChanged:()=>{l()},locale:t})]})}function me({active:t,onChange:s,locale:n,counts:i}){const l=[{id:"mcp",labelZh:"MCP 服务",labelEn:"MCP",icon:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("circle",{cx:"4",cy:"5",r:"1.6"}),e.jsx("circle",{cx:"20",cy:"5",r:"1.6"}),e.jsx("circle",{cx:"4",cy:"19",r:"1.6"}),e.jsx("circle",{cx:"20",cy:"19",r:"1.6"}),e.jsx("path",{d:"M6 6 l4 4 M18 6 l-4 4 M6 18 l4 -4 M18 18 l-4 -4"})]})},{id:"cli",labelZh:"命令行",labelEn:"CLI",icon:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 17 l5 -5 -5 -5"}),e.jsx("path",{d:"M12 19 h8"})]})},{id:"skill",labelZh:"技能包",labelEn:"Skills",icon:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 2 l3 7 h7 l-5.5 4.5 2 7.5 L12 17 l-6.5 4 2 -7.5 L2 9 h7 z"})})}];return e.jsx(fe,{className:"w-fit bg-panel/80 backdrop-blur",children:l.map(c=>e.jsxs(ge,{active:t===c.id,onClick:()=>s(c.id),className:"gap-1.5 px-3.5",children:[e.jsx("span",{className:"shrink-0",children:c.icon}),e.jsx("span",{children:n==="zh-CN"?c.labelZh:c.labelEn}),i?.[c.id]!==void 0&&e.jsx("span",{className:B("ml-1 inline-flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[10px] font-semibold",t===c.id?"bg-primary/12 text-primary":"bg-inset/70 text-fg-5"),children:i[c.id]})]},c.id))})}function Ke({onOpenBrowserSetup:t}){const s=G(u=>u.locale),i=G(u=>u.state)?.config?.workdir||"",[l,c]=o.useState(()=>{try{const u=localStorage.getItem("pikiclaw:extensions:tab");return u==="mcp"||u==="cli"||u==="skill"?u:"mcp"}catch{return"mcp"}}),x=o.useCallback(u=>{c(u);try{localStorage.setItem("pikiclaw:extensions:tab",u)}catch{}},[]);return e.jsxs("div",{className:"animate-in space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.jsx("div",{className:"space-y-1",children:e.jsx("div",{className:"text-[13px] leading-relaxed text-fg-4",children:a(s,"管理一次授权即可全局复用的服务与工具。项目专属的扩展请在工作台侧栏配置。","One-time authorization, use everywhere. Project-specific extensions live in the Workbench sidebar.")})}),e.jsx(me,{active:l,onChange:x,locale:s})]}),e.jsxs("div",{className:"animate-in-fade",children:[l==="mcp"&&e.jsx("div",{className:"space-y-7",children:e.jsx(de,{scope:"global",workdir:i,locale:s,onOpenBrowserSetup:t})}),l==="cli"&&e.jsx(pe,{locale:s,scope:"global"}),l==="skill"&&e.jsx(xe,{scope:"global",workdir:i,locale:s})]},l)]})}function Ve({workdir:t}){const s=G(c=>c.locale),[n,i]=o.useState(()=>{try{const c=localStorage.getItem("pikiclaw:extensions-ws:tab");return c==="mcp"||c==="cli"||c==="skill"?c:"mcp"}catch{return"mcp"}}),l=o.useCallback(c=>{i(c);try{localStorage.setItem("pikiclaw:extensions-ws:tab",c)}catch{}},[]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-3",children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-fg-4",children:a(s,"仅对当前工作区生效 — 依赖项目目录的本地服务和专属技能包。","Scoped to this workspace — local services that depend on project context and project-specific skill packs.")}),e.jsx(me,{active:n,onChange:l,locale:s})]}),e.jsxs("div",{className:"animate-in-fade",children:[n==="mcp"&&e.jsx(de,{scope:"workspace",workdir:t,locale:s}),n==="cli"&&e.jsx(pe,{locale:s,scope:"workspace"}),n==="skill"&&e.jsx(xe,{scope:"workspace",workdir:t,locale:s})]},n)]})}export{Ke as ExtensionsTab,Ve as WorkspaceExtensionsBody};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as C,j as r}from"./react-vendor-DTcmqLiz.js";import{u as k,l as w,k as D,S as h,B as v}from"./index-
|
|
1
|
+
import{r as C,j as r}from"./react-vendor-DTcmqLiz.js";import{u as k,l as w,k as D,S as h,B as v}from"./index-B_sC2ppg.js";import{B as A}from"./BrandIcon-CmIkwB4h.js";import{a as B,b as L,c as S,d as T}from"./shared-C-0W57w0.js";import"./router-Cav8lq-m.js";function b(t){return t==="zh-CN"?{status:"状态",summary:"接入摘要",loading:"加载中",chats:"个 chat",notConnected:"未接入",configuring:"配置中",connected:"已接入",failed:"配置异常",configure:"去配置",continueSetup:"继续配置",viewSettings:"查看设置",noWeixin:"尚未登录微信账号",noTelegram:"未配置 Bot Token",noFeishu:"未配置 App ID 与应用凭证",noSlack:"未配置 Bot Token 与 App-Level Token",noDiscord:"未配置 Bot Token",noDingtalk:"未配置 AppKey/AppSecret",noWeCom:"未配置智能机器人 Bot ID 与 Secret",pendingValidation:"凭证已保存,等待验证。",connectedReady:"机器人已可正常接收消息。",validationFailed:"校验失败,请检查凭证或网络。",accountLinked:"已绑定账号",tokenSaved:"Token 已保存",appCredentialsSaved:"应用凭证已保存",allowedChats:"允许",notConnectedDetail:"尚未配置账号与接入凭证。"}:{status:"Status",summary:"Summary",loading:"Loading",chats:"chats",notConnected:"Not connected",configuring:"Configuring",connected:"Connected",failed:"Needs attention",configure:"Configure",continueSetup:"Continue setup",viewSettings:"View settings",noWeixin:"Weixin account not connected yet",noTelegram:"Bot token not configured",noFeishu:"App ID and credentials not configured",noSlack:"Bot Token and App-Level Token not configured",noDiscord:"Bot Token not configured",noDingtalk:"AppKey / AppSecret not configured",noWeCom:"Smart Bot ID and Secret not configured",pendingValidation:"Credentials are saved and waiting for validation.",connectedReady:"This channel can receive messages.",validationFailed:"Validation failed. Check credentials or network.",accountLinked:"Account linked",tokenSaved:"Token saved",appCredentialsSaved:"Credentials saved",allowedChats:"Allows",notConnectedDetail:"Account and access credentials have not been configured yet."}}function c(t,e=4,n=4){const a=t.trim();return a?a.length<=e+n+3?a:`${a.slice(0,e)}...${a.slice(-n)}`:""}function $(t){return String(t||"").split(/[\n,;]/).map(e=>e.trim()).filter(Boolean).length}function l(t,e){return String(t?.[e]||"").trim()}function E(t,e){if(!t)return e;try{return new URL(t).host||t}catch{return t}}function I(t,e,n){if(t==="weixin"){const i=l(e,"weixinAccountId"),o=l(e,"weixinBaseUrl");return i?o?`${c(i)} · ${E(o,o)}`:`${n.accountLinked} ${c(i)}`:n.noWeixin}if(t==="telegram"){const i=l(e,"telegramBotToken"),o=$(l(e,"telegramAllowedChatIds"));return i?o>0?`${n.tokenSaved} · ${n.allowedChats} ${o} ${n.chats}`:n.tokenSaved:n.noTelegram}if(t==="feishu"){const i=l(e,"feishuAppId"),o=l(e,"feishuAppSecret");return!i||!o?n.noFeishu:`App ID ${c(i)} · ${n.appCredentialsSaved}`}if(t==="slack"){const i=l(e,"slackBotToken"),o=l(e,"slackAppToken");return!i||!o?n.noSlack:`Bot ${c(i,6,4)} · App ${c(o,6,4)}`}if(t==="discord"){const i=l(e,"discordBotToken");return i?`${n.tokenSaved} · ${c(i,6,4)}`:n.noDiscord}if(t==="dingtalk"){const i=l(e,"dingtalkClientId"),o=l(e,"dingtalkClientSecret");return!i||!o?n.noDingtalk:`AppKey ${c(i,4,4)} · ${n.appCredentialsSaved}`}const a=l(e,"wecomBotId"),u=l(e,"wecomBotSecret");return!a||!u?n.noWeCom:`Bot ${c(a,4,4)} · ${n.appCredentialsSaved}`}function j(t,e){return!t||!t.configured?{statusLabel:e.notConnected,statusVariant:"muted",statusDescription:t?.detail||e.notConnectedDetail,actionLabel:e.configure}:t.ready?{statusLabel:e.connected,statusVariant:"ok",statusDescription:t.detail||e.connectedReady,actionLabel:e.viewSettings}:w(t)?{statusLabel:e.configuring,statusVariant:"accent",statusDescription:t.detail||e.pendingValidation,actionLabel:e.continueSetup}:{statusLabel:e.failed,statusVariant:"warn",statusDescription:t.detail||e.validationFailed,actionLabel:e.continueSetup}}function y({meta:t,locale:e}){const n=b(e);return r.jsxs(B,{children:[r.jsx(L,{icon:r.jsx(A,{brand:t.key,size:32,className:"rounded-md"}),iconWrap:!1,title:t.title,subtitle:t.subtitle}),r.jsxs(S,{label:n.status,children:[r.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:r.jsxs(D,{variant:t.statusVariant,children:[t.loading&&r.jsx(h,{className:"h-3 w-3"}),t.statusLabel]})}),r.jsx("div",{className:"mt-1 text-[13px] leading-relaxed text-fg-3 xl:truncate xl:whitespace-nowrap",title:t.statusDescription,children:t.statusDescription})]}),r.jsx(S,{label:t.summaryLabel,children:r.jsx("div",{className:"break-words text-[13px] leading-relaxed text-fg-3",children:t.summary})}),r.jsx(T,{children:r.jsxs(v,{variant:t.channel?.ready?"outline":"primary",size:"sm",onClick:t.onAction,disabled:t.actionDisabled,children:[t.loading&&r.jsx(h,{className:"h-3 w-3"}),t.actionLabel]})})]})}const Z=[{key:"weixin",titleZh:"微信",titleEn:"Weixin",subtitleZh:"二维码登录与账号接入",subtitleEn:"QR login and account routing",actionProp:"onOpenWeixin"},{key:"telegram",titleZh:"Telegram",titleEn:"Telegram",subtitleZh:"Bot Token 与 chat allowlist",subtitleEn:"Bot token and chat allowlist",actionProp:"onOpenTelegram"},{key:"feishu",titleZh:"飞书",titleEn:"Lark / Feishu",subtitleZh:"应用凭证与机器人身份",subtitleEn:"App credentials and bot identity",actionProp:"onOpenFeishu"},{key:"slack",titleZh:"Slack",titleEn:"Slack",subtitleZh:"Socket Mode (xoxb / xapp)",subtitleEn:"Socket Mode (xoxb / xapp)",actionProp:"onOpenSlack"},{key:"discord",titleZh:"Discord",titleEn:"Discord",subtitleZh:"Gateway 长连接 (需开启 Message Content Intent)",subtitleEn:"Gateway WebSocket (requires Message Content Intent)",actionProp:"onOpenDiscord"},{key:"dingtalk",titleZh:"钉钉",titleEn:"DingTalk",subtitleZh:"Stream 长连接 (AppKey / AppSecret)",subtitleEn:"Stream Mode (AppKey / AppSecret)",actionProp:"onOpenDingtalk"},{key:"wecom",titleZh:"企业微信",titleEn:"WeCom",subtitleZh:"智能机器人 WebSocket (Bot ID / Secret)",subtitleEn:"Smart Bot WebSocket (Bot ID / Secret)",actionProp:"onOpenWeCom"}];function P(t){const e=k(s=>s.state),n=k(s=>s.locale),a=b(n),u=!e,i=e?.setupState?.channels||[],o=e?.config||{},f=C.useMemo(()=>Z.map(s=>{const d=i.find(x=>x.channel===s.key)||null,p=n==="zh-CN"?s.titleZh:s.titleEn,g=n==="zh-CN"?s.subtitleZh:s.subtitleEn,m=t[s.actionProp];return u?{key:s.key,title:p,subtitle:g,channel:null,loading:!0,summary:a.loading,summaryLabel:a.summary,statusLabel:a.loading,statusVariant:"muted",statusDescription:a.loading,actionLabel:a.loading,actionDisabled:!0,onAction:m}:{key:s.key,title:p,subtitle:g,channel:d,summary:I(s.key,o,a),summaryLabel:a.summary,...j(d,a),actionDisabled:!1,onAction:m}}),[i,o,a,u,n,t]);return r.jsx("div",{className:"animate-in space-y-3",children:f.map(s=>r.jsx(y,{meta:s,locale:n},s.key))})}export{P as IMAccessTab};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,r as i,b as c}from"./react-vendor-DTcmqLiz.js";import{c as o,B as x}from"./index-
|
|
1
|
+
import{j as e,r as i,b as c}from"./react-vendor-DTcmqLiz.js";import{c as o,B as x}from"./index-B_sC2ppg.js";function u({className:t,...r}){return e.jsx("input",{className:o("flex h-9 w-full rounded-md border border-control-border bg-control px-3 py-1.5 text-[13px] text-fg shadow-sm","transition-[border-color,box-shadow,background] duration-200 outline-none","placeholder:text-fg-5","hover:border-control-border-h","focus:border-control-border-h focus:bg-control-h focus:shadow-[0_0_0_4px_var(--th-glow-a)]","disabled:cursor-not-allowed disabled:bg-panel-alt disabled:border-edge disabled:text-fg-5","disabled:shadow-none disabled:hover:border-edge disabled:placeholder:text-fg-6",t),...r})}function h({children:t,className:r}){return e.jsx("label",{className:o("mb-2 block text-sm font-medium text-fg-3",r),children:t})}function f({open:t,onClose:r,wide:a,panelStyle:s,children:l}){return i.useEffect(()=>{if(!t)return;const n=d=>{d.key==="Escape"&&r()};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[t,r]),!t||typeof document>"u"?null:c.createPortal(e.jsxs("div",{className:"fixed inset-0 z-100 flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 backdrop-blur-[10px] backdrop-saturate-125",style:{background:"linear-gradient(180deg, color-mix(in oklab, var(--th-overlay) 68%, transparent), color-mix(in oklab, var(--th-overlay) 92%, transparent))"},onClick:r}),e.jsx("div",{className:"pointer-events-none absolute inset-0",style:{background:"radial-gradient(circle at center, color-mix(in oklab, white 12%, transparent), transparent 38%)"}}),e.jsx("div",{className:o("glass-strong relative max-h-[min(88vh,860px)] w-full overflow-hidden rounded-xl border border-edge-h shadow-[0_32px_96px_rgba(2,6,23,0.28),0_8px_24px_rgba(15,23,42,0.08)] animate-scale",a?"max-w-[720px]":"max-w-[480px]"),style:{...s,background:"linear-gradient(180deg, color-mix(in oklab, var(--th-modal-bg) 90%, white 10%), color-mix(in oklab, var(--th-modal-bg) 97%, white 3%))"},children:e.jsx("div",{className:"max-h-[inherit] overflow-y-auto p-6",children:l})})]}),document.body)}function g({title:t,description:r,onClose:a}){return e.jsxs("div",{className:"mb-5 flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-base font-semibold tracking-tight text-fg",children:t}),r&&e.jsx("div",{className:"mt-1 text-sm leading-relaxed text-fg-4",children:r})]}),e.jsx(x,{variant:"ghost",size:"icon",onClick:a,className:"-mr-1 -mt-1 h-8 w-8 shrink-0",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})}export{u as I,h as L,f as M,g as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as e}from"./react-vendor-DTcmqLiz.js";import{u as C,b as O,B as D,a as R,k as $}from"./index-BS_RBT-T.js";import{M as Q,a as V,L,I as P}from"./Modal-Dk3jQZ_G.js";import{D as te}from"./DirBrowser-BqA8ssEC.js";import"./router-Cav8lq-m.js";const Y="https://ilinkai.weixin.qq.com";function _(o){return o instanceof Error&&(o.name==="AbortError"||/aborted/i.test(o.message))}function X(o,f){return o instanceof Error&&/timed out/i.test(o.message)?f("modal.requestTimeout"):f("modal.networkError")}function ie({open:o,onClose:f}){const h=C(d=>d.state),i=C(d=>d.toast),r=C(d=>d.reloadUntil),s=C(d=>d.locale),t=a.useMemo(()=>O(s),[s]),[k,I]=a.useState(""),[S,b]=a.useState(""),[T,y]=a.useState(!1),[N,c]=a.useState(!1),[u,n]=a.useState(null),[m,K]=a.useState(!1),j=a.useRef(null),A=a.useRef(h);A.current=h,a.useEffect(()=>{o?(I(A.current?.config.telegramBotToken||""),b(A.current?.config.telegramAllowedChatIds||""),y(!1),n(null),K(!A.current?.config.telegramBotToken)):(j.current?.abort(),j.current=null,c(!1))},[o]),a.useEffect(()=>()=>{j.current?.abort(),j.current=null},[]);const v=async()=>{if(!k.trim()){i(t("modal.inputToken"),!1);return}j.current?.abort();const d=new AbortController;j.current=d,c(!0),n(null);let l=!1;try{const x=await R.validateTelegramConfig(k.trim(),S.trim(),{signal:d.signal,timeoutMs:12e3});if(!x.ok){n({ok:!1,text:"✗ "+(x.error||t("modal.validationFailed"))});return}const w=x.normalizedAllowedChatIds??S.trim();n({ok:!0,text:"✓ @"+(x.bot?.username||"bot")+(x.bot?.displayName?" ("+x.bot.displayName+")":"")});const U=new Set((h?.setupState?.channels||[]).filter(F=>(F.ready||F.configured)&&F.channel!=="telegram").map(F=>F.channel));if(U.add("telegram"),await R.saveConfig({telegramBotToken:k.trim(),telegramAllowedChatIds:w,channels:[...U]}),!await r(F=>{const z=F.setupState?.channels?.find(g=>g.channel==="telegram");return F.config.telegramBotToken===k.trim()&&(F.config.telegramAllowedChatIds||"")===w&&!!z?.ready},{attempts:10,intervalMs:350})){n({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),i(t("modal.refreshStateFailed"),!1);return}i(t("modal.tgSaved")),l=!0}catch(x){if(_(x))return;const w=X(x,t);n({ok:!1,text:"✗ "+w}),i(w,!1)}finally{j.current===d&&(j.current=null),c(!1),l&&f()}},p=()=>{j.current?.abort(),j.current=null,f()};return e.jsxs(Q,{open:o,onClose:p,children:[e.jsx(V,{title:t("modal.configureTelegram"),onClose:p}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>K(!m),children:[e.jsx("span",{children:t("modal.tgGuideTitle")}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${m?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),m&&e.jsxs("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:[e.jsx("p",{children:t("modal.tgGuideStep1")}),e.jsx("p",{children:t("modal.tgGuideStep2")}),e.jsx("p",{children:t("modal.tgGuideStep3")}),e.jsx("p",{children:t("modal.tgGuideStep4")}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-5",children:t("modal.tgGuideIdTip")})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.botToken")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{type:T?"text":"password",className:"flex-1 font-mono text-xs",placeholder:t("modal.pasteToken"),value:k,onChange:d=>I(d.target.value)}),e.jsx(D,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>y(!T),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]}),u&&e.jsx("div",{className:"text-xs",style:{color:u.ok?"var(--th-ok)":"var(--th-err)"},children:u.text}),e.jsxs("div",{children:[e.jsxs(L,{children:[t("modal.allowedIds")," ",e.jsxs("span",{className:"text-fg-5",children:["(",t("modal.optional"),")"]})]}),e.jsx(P,{className:"font-mono text-xs",placeholder:t("modal.commaSep"),value:S,onChange:d=>b(d.target.value)})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:p,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:N,onClick:v,children:t(N?"modal.validating":"modal.validateSave")})]})]})}function de({open:o,onClose:f}){const h=C(v=>v.state),i=C(v=>v.toast),r=C(v=>v.reloadUntil),s=C(v=>v.locale),t=a.useMemo(()=>O(s),[s]),[k,I]=a.useState(""),[S,b]=a.useState(""),[T,y]=a.useState(!1),[N,c]=a.useState(null),[u,n]=a.useState(!1),m=a.useRef(null),K=a.useRef(h);K.current=h,a.useEffect(()=>{o?(I(K.current?.config.feishuAppId||""),b(K.current?.config.feishuAppSecret||""),c(null),n(!K.current?.config.feishuAppId)):(m.current?.abort(),m.current=null,y(!1))},[o]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const j=async()=>{if(!k.trim()){i(t("modal.inputAppId"),!1);return}m.current?.abort();const v=new AbortController;m.current=v,y(!0),c(null);let p=!1;try{const d=await R.validateFeishuConfig(k.trim(),S.trim(),{signal:v.signal,timeoutMs:2e4});if(!d.ok){c({ok:!1,text:"✗ "+(d.error||t("modal.validationFailed"))});return}c({ok:!0,text:"✓ "+(d.app?.displayName||d.app?.appId||k.trim())});const l=new Set((h?.setupState?.channels||[]).filter(w=>(w.ready||w.configured)&&w.channel!=="feishu").map(w=>w.channel));if(l.add("feishu"),await R.saveConfig({feishuAppId:k.trim(),feishuAppSecret:S.trim(),channels:[...l]}),!await r(w=>{const U=w.setupState?.channels?.find(W=>W.channel==="feishu");return w.config.feishuAppId===k.trim()&&w.config.feishuAppSecret===S.trim()&&!!U?.ready},{attempts:10,intervalMs:350})){c({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),i(t("modal.refreshStateFailed"),!1);return}i(t("modal.feishuSaved")),p=!0}catch(d){if(_(d))return;const l=X(d,t);c({ok:!1,text:"✗ "+l}),i(l,!1)}finally{m.current===v&&(m.current=null),y(!1),p&&f()}},A=()=>{m.current?.abort(),m.current=null,f()};return e.jsxs(Q,{open:o,onClose:A,children:[e.jsx(V,{title:t("modal.configureFeishu"),onClose:A}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>n(!u),children:[e.jsx("span",{children:t("modal.feishuGuideTitle")}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${u?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),u&&e.jsxs("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:[e.jsx("p",{children:t("modal.feishuGuideStep1")}),e.jsx("p",{children:t("modal.feishuGuideStep2")}),e.jsx("p",{children:t("modal.feishuGuideStep3")}),e.jsx("p",{children:t("modal.feishuGuideStep4")}),e.jsx("p",{className:"ml-3 font-mono text-[11px] text-fg-5",children:t("modal.feishuGuidePerms")}),e.jsx("p",{children:t("modal.feishuGuideStep5")}),e.jsx("p",{children:t("modal.feishuGuideStep6")}),e.jsx("p",{children:t("modal.feishuGuideStep7")}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-5",children:t("modal.feishuGuideCardKitTip")})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.appId")}),e.jsx(P,{className:"font-mono text-xs",placeholder:t("modal.feishuPlaceholder"),value:k,onChange:v=>I(v.target.value)})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.appSecret")}),e.jsx(P,{type:"password",className:"font-mono text-xs",placeholder:t("modal.appSecret"),value:S,onChange:v=>b(v.target.value)})]}),N&&e.jsx("div",{className:"text-xs",style:{color:N.ok?"var(--th-ok)":"var(--th-err)"},children:N.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:A,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:T,onClick:j,children:t(T?"modal.validating":"modal.validateSave")})]})]})}function ce({open:o,onClose:f}){const h=C(p=>p.state),i=C(p=>p.toast),r=C(p=>p.reloadUntil),s=C(p=>p.locale),t=a.useMemo(()=>O(s),[s]),[k,I]=a.useState(Y),[S,b]=a.useState(!1),[T,y]=a.useState(""),[N,c]=a.useState(""),[u,n]=a.useState(null),m=a.useRef(null),K=a.useRef(h);K.current=h,a.useEffect(()=>{o?(I(K.current?.config.weixinBaseUrl||Y),b(!1),y(""),c(""),n(null)):(m.current?.abort(),m.current=null,b(!1))},[o]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const j=()=>{m.current?.abort(),m.current=null,f()},A=a.useCallback(async(p,d,l)=>{for(;!p.signal.aborted;){const x=await R.waitWeixinLogin(d,l,{signal:p.signal,timeoutMs:45e3});if(!x.ok&&!x.connected)return n({ok:!1,text:"✗ "+(x.error||x.message||t("modal.validationFailed"))}),!1;if(x.qrcodeUrl&&y(x.qrcodeUrl),x.status==="scaned"?n({ok:!0,text:t("modal.weixinScanned")}):x.status==="expired"?n({ok:!0,text:t("modal.weixinQrRefreshed")}):x.connected||n({ok:!0,text:t("modal.weixinWaitingScan")}),!x.connected)continue;n({ok:!0,text:t("modal.weixinLoginSuccess")});const w=x.baseUrl||l,U=x.botToken||"",W=x.accountId||"",F=await R.validateWeixinConfig(w,U,W,{signal:p.signal,timeoutMs:12e3});if(!F.ok)return n({ok:!1,text:"✗ "+(F.error||t("modal.validationFailed"))}),!1;const z=F.normalizedBaseUrl||w,g=new Set((K.current?.setupState?.channels||[]).filter(G=>(G.ready||G.configured)&&G.channel!=="weixin").map(G=>G.channel));return g.add("weixin"),await R.saveConfig({weixinBaseUrl:z,weixinBotToken:U,weixinAccountId:W,channels:[...g]}),await r(G=>{const B=G.setupState?.channels?.find(M=>M.channel==="weixin");return G.config.weixinBaseUrl===z&&G.config.weixinBotToken===U&&G.config.weixinAccountId===W&&!!B?.ready},{attempts:12,intervalMs:350})?(i(t("modal.weixinSaved")),!0):(n({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),i(t("modal.refreshStateFailed"),!1),!1)}return!1},[r,t,i]),v=async()=>{if(!k.trim()){i(t("modal.inputWeixinBaseUrl"),!1);return}m.current?.abort();const p=new AbortController;m.current=p,b(!0),y(""),c(""),n(null);let d=!1;try{const l=await R.startWeixinLogin(k.trim(),{signal:p.signal,timeoutMs:12e3});if(!l.ok||!l.qrcodeUrl){n({ok:!1,text:"✗ "+(l.error||l.message||t("modal.validationFailed"))});return}y(l.qrcodeUrl),c(l.sessionKey),n({ok:!0,text:t("modal.weixinWaitingScan")}),d=await A(p,l.sessionKey,k.trim())}catch(l){if(_(l))return;const x=X(l,t);n({ok:!1,text:"✗ "+x}),i(x,!1)}finally{m.current===p&&(m.current=null),b(!1),d&&f()}};return e.jsxs(Q,{open:o,onClose:j,children:[e.jsx(V,{title:t("modal.configureWeixin"),onClose:j}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:t("modal.weixinScanHint")}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.weixinBaseUrl")}),e.jsx(P,{className:"font-mono text-xs",value:k,onChange:p=>I(p.target.value),placeholder:Y}),e.jsx("div",{className:"mt-1 text-[11px] text-fg-5",children:t("modal.weixinDefaultBaseUrlHint")})]}),T&&e.jsxs("div",{className:"rounded-xl border border-edge bg-panel-alt p-4",children:[e.jsx("img",{src:T,alt:t("modal.weixinQrAlt"),className:"mx-auto h-56 w-56 rounded-lg bg-white p-3 object-contain"}),N&&e.jsx("div",{className:"mt-2 truncate text-center font-mono text-[10px] text-fg-5",children:N})]}),u&&e.jsx("div",{className:"text-xs",style:{color:u.ok?"var(--th-ok)":"var(--th-err)"},children:u.text})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(D,{variant:"ghost",onClick:j,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:S,onClick:v,children:t(S?T?"modal.validating":"modal.weixinGeneratingQr":T?"modal.weixinRetry":"modal.weixinGenerateQr")})]})]})}function J({open:o,onClose:f,channel:h,titleKey:i,fields:r,validate:s,savedToastKey:t,guideTitleKey:k,guideStepKeys:I,guideOpenWhenEmpty:S=!0,validateTimeoutMs:b=12e3}){const T=C(g=>g.state),y=C(g=>g.toast),N=C(g=>g.reloadUntil),c=C(g=>g.locale),u=a.useMemo(()=>O(c),[c]),[n,m]=a.useState({}),[K,j]=a.useState({}),[A,v]=a.useState(!1),[p,d]=a.useState(null),[l,x]=a.useState(!1),w=a.useRef(null),U=a.useRef(T);U.current=T;const W=!!(I&&I.length);a.useEffect(()=>{if(o){const g=U.current?.config||{},E={};let G=!1;for(const B of r){const M=String(g[B.key]??"").trim();E[B.key]=M,!M&&B.required!==!1&&(G=!0)}m(E),j({}),d(null),x(W&&S&&G)}else w.current?.abort(),w.current=null,v(!1)},[o,r,W,S]),a.useEffect(()=>()=>{w.current?.abort(),w.current=null},[]);const F=()=>{w.current?.abort(),w.current=null,f()},z=async()=>{const g={};for(const B of r){const M=String(n[B.key]||"").trim();if(g[B.key]=M,B.required!==!1&&!M){y(u(B.labelKey)+": "+u("modal.fieldRequired"),!1);return}}w.current?.abort();const E=new AbortController;w.current=E,v(!0),d(null);let G=!1;try{const B=await s(g,{signal:E.signal,timeoutMs:b});if(!B.ok){d({ok:!1,text:"✗ "+(B.error||u("modal.validationFailed"))});return}d({ok:!0,text:"✓ "+(B.identity||u("modal.credentialsVerified"))});const M=new Set((T?.setupState?.channels||[]).filter(q=>(q.ready||q.configured)&&q.channel!==h).map(q=>q.channel));if(M.add(h),await R.saveConfig({...g,channels:[...M]}),!await N(q=>{const ee=q.config||{};for(const H of r)if(String(ee[H.key]||"").trim()!==g[H.key])return!1;return!!q.setupState?.channels?.find(H=>H.channel===h)?.ready},{attempts:10,intervalMs:350})){d({ok:!1,text:"✗ "+u("modal.refreshStateFailed")}),y(u("modal.refreshStateFailed"),!1);return}y(u(t)),G=!0}catch(B){if(_(B))return;const M=X(B,u);d({ok:!1,text:"✗ "+M}),y(M,!1)}finally{w.current===E&&(w.current=null),v(!1),G&&f()}};return e.jsxs(Q,{open:o,onClose:F,children:[e.jsx(V,{title:u(i),onClose:F}),e.jsxs("div",{className:"space-y-4",children:[W&&k&&e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>x(!l),children:[e.jsx("span",{children:u(k)}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${l?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),l&&e.jsx("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:I.map(g=>e.jsx("p",{children:u(g)},g))})]}),r.map(g=>{const E=g.key,G=!!K[E],B=g.password&&!G?"password":"text";return e.jsxs("div",{children:[e.jsxs(L,{children:[u(g.labelKey),g.required===!1&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"text-fg-5",children:["(",u("modal.optional"),")"]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{type:B,className:"flex-1 font-mono text-xs",placeholder:g.placeholder?u(g.placeholder):"",value:n[E]||"",onChange:M=>m(Z=>({...Z,[E]:M.target.value}))}),g.password&&e.jsx(D,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>j(M=>({...M,[E]:!M[E]})),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]},E)}),p&&e.jsx("div",{className:"text-xs",style:{color:p.ok?"var(--th-ok)":"var(--th-err)"},children:p.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:F,children:u("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:A,onClick:z,children:u(A?"modal.validating":"modal.validateSave")})]})]})}function ue({open:o,onClose:f}){return e.jsx(J,{open:o,onClose:f,channel:"slack",titleKey:"modal.configureSlack",savedToastKey:"modal.slackSaved",guideTitleKey:"modal.slackGuideTitle",guideStepKeys:["modal.slackGuideStep1","modal.slackGuideStep2","modal.slackGuideStep3","modal.slackGuideStep4","modal.slackGuideStep5"],fields:[{key:"slackBotToken",labelKey:"modal.slackBotToken",password:!0,placeholder:"modal.slackBotTokenPlaceholder"},{key:"slackAppToken",labelKey:"modal.slackAppToken",password:!0,placeholder:"modal.slackAppTokenPlaceholder"}],validate:async(h,i)=>{const r=await R.validateSlackConfig(h.slackBotToken,h.slackAppToken,i),s=r.bot?.username?"@"+r.bot.username+(r.bot.team?" ("+r.bot.team+")":""):null;return{ok:r.ok,error:r.error,identity:s}}})}function me({open:o,onClose:f}){return e.jsx(J,{open:o,onClose:f,channel:"discord",titleKey:"modal.configureDiscord",savedToastKey:"modal.discordSaved",guideTitleKey:"modal.discordGuideTitle",guideStepKeys:["modal.discordGuideStep1","modal.discordGuideStep2","modal.discordGuideStep3","modal.discordGuideStep4","modal.discordGuideStep5"],fields:[{key:"discordBotToken",labelKey:"modal.discordBotToken",password:!0,placeholder:"modal.discordBotTokenPlaceholder"}],validate:async(h,i)=>{const r=await R.validateDiscordConfig(h.discordBotToken,i),s=r.bot?.username?"@"+r.bot.username:null;return{ok:r.ok,error:r.error,identity:s}}})}function xe({open:o,onClose:f}){return e.jsx(J,{open:o,onClose:f,channel:"dingtalk",titleKey:"modal.configureDingtalk",savedToastKey:"modal.dingtalkSaved",guideTitleKey:"modal.dingtalkGuideTitle",guideStepKeys:["modal.dingtalkGuideStep1","modal.dingtalkGuideStep2","modal.dingtalkGuideStep3","modal.dingtalkGuideStep4","modal.dingtalkGuideStep5"],fields:[{key:"dingtalkClientId",labelKey:"modal.dingtalkClientId",placeholder:"modal.dingtalkClientIdPlaceholder"},{key:"dingtalkClientSecret",labelKey:"modal.dingtalkClientSecret",password:!0,placeholder:"modal.dingtalkClientSecretPlaceholder"}],validate:async(h,i)=>{const r=await R.validateDingtalkConfig(h.dingtalkClientId,h.dingtalkClientSecret,i),s=r.app?.clientId?r.app.clientId.length>12?r.app.clientId.slice(0,6)+"..."+r.app.clientId.slice(-4):r.app.clientId:null;return{ok:r.ok,error:r.error,identity:s}}})}function fe({open:o,onClose:f}){return e.jsx(J,{open:o,onClose:f,channel:"wecom",titleKey:"modal.configureWeCom",savedToastKey:"modal.wecomSaved",guideTitleKey:"modal.wecomGuideTitle",guideStepKeys:["modal.wecomGuideStep1","modal.wecomGuideStep2","modal.wecomGuideStep3","modal.wecomGuideStep4","modal.wecomGuideNote"],fields:[{key:"wecomBotId",labelKey:"modal.wecomBotId",placeholder:"modal.wecomBotIdPlaceholder"},{key:"wecomBotSecret",labelKey:"modal.wecomBotSecret",password:!0,placeholder:"modal.wecomBotSecretPlaceholder"}],validate:async(h,i)=>{const r=await R.validateWecomConfig(h.wecomBotId,h.wecomBotSecret,i),s=r.bot?.botId?r.bot.botId:null;return{ok:r.ok,error:r.error,identity:s}}})}function he({open:o,onClose:f}){const h=C(n=>n.state),i=C(n=>n.toast),r=C(n=>n.reload),s=C(n=>n.locale),t=a.useMemo(()=>O(s),[s]),k=h?.bot?.workdir||h?.runtimeWorkdir||"",[I,S]=a.useState(""),[b,T]=a.useState(!1),[y,N]=a.useState(0);a.useEffect(()=>{o&&(S(k),N(n=>n+1))},[o,k]);const c=a.useCallback(n=>{S(n)},[]),u=async()=>{const n=I.trim();if(!n){i(t("modal.selectDirFirst"),!1);return}T(!0);try{const m=await R.switchWorkdir(n);m.ok?(await r(),i(t("modal.switchedTo")+m.workdir),f()):i(m.error||t("modal.switchFailed"),!1)}catch{i(t("modal.switchFailed"),!1)}finally{T(!1)}};return e.jsx(Q,{open:o,onClose:b?void 0:f,panelStyle:{width:"min(500px, calc(100vw - 2rem))",maxWidth:"min(500px, calc(100vw - 2rem))"},children:b?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-4 animate-in",children:[e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin text-fg-3",style:{animationDuration:"1.2s"},children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]}),e.jsx("span",{className:"text-sm font-medium text-fg-3",children:t("modal.switching")}),e.jsx("span",{className:"text-xs text-fg-5 max-w-[280px] truncate",children:I})]}):e.jsxs(e.Fragment,{children:[e.jsx(V,{title:t("modal.switchWorkdir"),onClose:f}),e.jsx(te,{initialPath:k,onSelect:c,t},y),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(D,{variant:"ghost",onClick:f,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",onClick:u,children:t("modal.selectDir")})]})]})})}function pe({open:o,onClose:f,onSaved:h}){const i=C(l=>l.toast),r=C(l=>l.locale),s=a.useMemo(()=>O(r),[r]),[t,k]=a.useState(null),[I,S]=a.useState(!1),[b,T]=a.useState(!1),[y,N]=a.useState(null);a.useEffect(()=>{o&&(S(!1),N(null),R.getBrowser().then(l=>{k(l),T(!!l.browser.enabled)}).catch(()=>k(null)))},[o]);const c=t?.browser,u=!!c?.enabled,n=!!c&&u!==b,m=c?.profileDir||"",K=s("ext.profileDir"),j=m,A=!!c?.chromeInstalled&&!!c?.profileCreated,v=t?c?.enabled?A?s("ext.browserReady"):c?.chromeInstalled?s("ext.chromeInstalled"):s("ext.needsSetup"):s("ext.disabled"):s("status.loading"),p=t&&c?.enabled?A?"ok":c?.chromeInstalled?"warn":"err":"muted",d=async()=>{S(!0),N(null);try{await R.saveConfig({browserEnabled:b});const l=await R.getBrowser();k(l),h?.()}catch{N({ok:!1,text:"✗ "+s("ext.browserModeSaveFailed")}),i(s("ext.browserModeSaveFailed"),!1),S(!1);return}if(!b){N({ok:!0,text:"✓ "+s("ext.browserDisabledSaved")}),i(s("ext.browserDisabledSaved")),S(!1);return}try{const l=await R.setupBrowser();if(!l.ok){N({ok:!1,text:"✗ "+(l.error||s("ext.browserLaunchFailed"))}),i(l.error||s("ext.browserLaunchFailed"),!1);return}k(x=>x?{...x,browser:l.browser}:{browser:l.browser}),N({ok:!0,text:"✓ "+s("ext.browserEnabledLaunched")}),i(s("ext.browserEnabledLaunched")),h?.()}catch{N({ok:!1,text:"✗ "+s("ext.browserLaunchFailed")}),i(s("ext.browserLaunchFailed"),!1)}finally{S(!1)}};return e.jsxs(Q,{open:o,onClose:f,children:[e.jsx(V,{title:s("ext.setupBrowser"),description:s("ext.setupBrowserDesc"),onClose:f}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx($,{variant:p,children:v}),c&&e.jsxs(e.Fragment,{children:[e.jsx($,{variant:u?"accent":"muted",children:s(u?"ext.enabled":"ext.disabled")}),n&&e.jsx($,{variant:"warn",children:s("ext.pendingModeChange")}),c.running&&e.jsxs($,{variant:"accent",children:[s("ext.browserOpen"),c.pid?` · PID ${c.pid}`:""]})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(L,{children:K}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"font-mono text-xs flex-1",value:j||"—",readOnly:!0,onClick:l=>l.target.select()}),e.jsx(D,{variant:"outline",size:"sm",disabled:!j,onClick:()=>{j&&(navigator.clipboard.writeText(j),i(s("ext.step2Copied")))},children:s("ext.copyPath")})]})]}),e.jsx("div",{className:"mt-3 text-xs text-fg-5",children:s(b?"ext.profileModeDesc":"ext.browserDescDisabled")}),c?.detail&&e.jsx("div",{className:"mt-2 text-xs text-fg-5",children:c.detail}),y&&e.jsx("div",{className:"mt-3 text-xs",style:{color:y.ok?"var(--th-ok)":"var(--th-err)"},children:y.text})]}),e.jsx("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:b,onChange:l=>T(l.target.checked),className:"mt-0.5 h-4 w-4 rounded border border-edge bg-inset"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-2 mb-1",children:s("ext.browserEnableToggle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s("ext.browserEnableToggleDesc")})]})]})}),e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:[e.jsx("div",{className:"text-sm font-medium text-fg-2 mb-1",children:s(b?"ext.step2Title":"ext.browserDisabledStepTitle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s(b?"ext.step2Desc":"ext.browserDisabledHint")})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:f,children:s("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:I,onClick:d,children:s(I?"ext.launching":b?"ext.enableAndLaunchBrowser":"ext.saveBrowserDisabled")})]})]})}export{pe as BrowserSetupModal,xe as DingtalkModal,me as DiscordModal,de as FeishuModal,ue as SlackModal,ie as TelegramModal,fe as WeComModal,ce as WeixinModal,he as WorkdirModal};
|
|
1
|
+
import{r as a,j as e}from"./react-vendor-DTcmqLiz.js";import{u as C,b as O,B as D,a as R,k as $}from"./index-B_sC2ppg.js";import{M as Q,a as V,L,I as P}from"./Modal-Cx6r2XJQ.js";import{D as te}from"./DirBrowser-BzqSOCzY.js";import"./router-Cav8lq-m.js";const Y="https://ilinkai.weixin.qq.com";function _(o){return o instanceof Error&&(o.name==="AbortError"||/aborted/i.test(o.message))}function X(o,f){return o instanceof Error&&/timed out/i.test(o.message)?f("modal.requestTimeout"):f("modal.networkError")}function ie({open:o,onClose:f}){const h=C(d=>d.state),i=C(d=>d.toast),r=C(d=>d.reloadUntil),s=C(d=>d.locale),t=a.useMemo(()=>O(s),[s]),[k,I]=a.useState(""),[S,b]=a.useState(""),[T,y]=a.useState(!1),[N,c]=a.useState(!1),[u,n]=a.useState(null),[m,K]=a.useState(!1),j=a.useRef(null),A=a.useRef(h);A.current=h,a.useEffect(()=>{o?(I(A.current?.config.telegramBotToken||""),b(A.current?.config.telegramAllowedChatIds||""),y(!1),n(null),K(!A.current?.config.telegramBotToken)):(j.current?.abort(),j.current=null,c(!1))},[o]),a.useEffect(()=>()=>{j.current?.abort(),j.current=null},[]);const v=async()=>{if(!k.trim()){i(t("modal.inputToken"),!1);return}j.current?.abort();const d=new AbortController;j.current=d,c(!0),n(null);let l=!1;try{const x=await R.validateTelegramConfig(k.trim(),S.trim(),{signal:d.signal,timeoutMs:12e3});if(!x.ok){n({ok:!1,text:"✗ "+(x.error||t("modal.validationFailed"))});return}const w=x.normalizedAllowedChatIds??S.trim();n({ok:!0,text:"✓ @"+(x.bot?.username||"bot")+(x.bot?.displayName?" ("+x.bot.displayName+")":"")});const U=new Set((h?.setupState?.channels||[]).filter(F=>(F.ready||F.configured)&&F.channel!=="telegram").map(F=>F.channel));if(U.add("telegram"),await R.saveConfig({telegramBotToken:k.trim(),telegramAllowedChatIds:w,channels:[...U]}),!await r(F=>{const z=F.setupState?.channels?.find(g=>g.channel==="telegram");return F.config.telegramBotToken===k.trim()&&(F.config.telegramAllowedChatIds||"")===w&&!!z?.ready},{attempts:10,intervalMs:350})){n({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),i(t("modal.refreshStateFailed"),!1);return}i(t("modal.tgSaved")),l=!0}catch(x){if(_(x))return;const w=X(x,t);n({ok:!1,text:"✗ "+w}),i(w,!1)}finally{j.current===d&&(j.current=null),c(!1),l&&f()}},p=()=>{j.current?.abort(),j.current=null,f()};return e.jsxs(Q,{open:o,onClose:p,children:[e.jsx(V,{title:t("modal.configureTelegram"),onClose:p}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>K(!m),children:[e.jsx("span",{children:t("modal.tgGuideTitle")}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${m?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),m&&e.jsxs("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:[e.jsx("p",{children:t("modal.tgGuideStep1")}),e.jsx("p",{children:t("modal.tgGuideStep2")}),e.jsx("p",{children:t("modal.tgGuideStep3")}),e.jsx("p",{children:t("modal.tgGuideStep4")}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-5",children:t("modal.tgGuideIdTip")})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.botToken")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{type:T?"text":"password",className:"flex-1 font-mono text-xs",placeholder:t("modal.pasteToken"),value:k,onChange:d=>I(d.target.value)}),e.jsx(D,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>y(!T),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]}),u&&e.jsx("div",{className:"text-xs",style:{color:u.ok?"var(--th-ok)":"var(--th-err)"},children:u.text}),e.jsxs("div",{children:[e.jsxs(L,{children:[t("modal.allowedIds")," ",e.jsxs("span",{className:"text-fg-5",children:["(",t("modal.optional"),")"]})]}),e.jsx(P,{className:"font-mono text-xs",placeholder:t("modal.commaSep"),value:S,onChange:d=>b(d.target.value)})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:p,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:N,onClick:v,children:t(N?"modal.validating":"modal.validateSave")})]})]})}function de({open:o,onClose:f}){const h=C(v=>v.state),i=C(v=>v.toast),r=C(v=>v.reloadUntil),s=C(v=>v.locale),t=a.useMemo(()=>O(s),[s]),[k,I]=a.useState(""),[S,b]=a.useState(""),[T,y]=a.useState(!1),[N,c]=a.useState(null),[u,n]=a.useState(!1),m=a.useRef(null),K=a.useRef(h);K.current=h,a.useEffect(()=>{o?(I(K.current?.config.feishuAppId||""),b(K.current?.config.feishuAppSecret||""),c(null),n(!K.current?.config.feishuAppId)):(m.current?.abort(),m.current=null,y(!1))},[o]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const j=async()=>{if(!k.trim()){i(t("modal.inputAppId"),!1);return}m.current?.abort();const v=new AbortController;m.current=v,y(!0),c(null);let p=!1;try{const d=await R.validateFeishuConfig(k.trim(),S.trim(),{signal:v.signal,timeoutMs:2e4});if(!d.ok){c({ok:!1,text:"✗ "+(d.error||t("modal.validationFailed"))});return}c({ok:!0,text:"✓ "+(d.app?.displayName||d.app?.appId||k.trim())});const l=new Set((h?.setupState?.channels||[]).filter(w=>(w.ready||w.configured)&&w.channel!=="feishu").map(w=>w.channel));if(l.add("feishu"),await R.saveConfig({feishuAppId:k.trim(),feishuAppSecret:S.trim(),channels:[...l]}),!await r(w=>{const U=w.setupState?.channels?.find(W=>W.channel==="feishu");return w.config.feishuAppId===k.trim()&&w.config.feishuAppSecret===S.trim()&&!!U?.ready},{attempts:10,intervalMs:350})){c({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),i(t("modal.refreshStateFailed"),!1);return}i(t("modal.feishuSaved")),p=!0}catch(d){if(_(d))return;const l=X(d,t);c({ok:!1,text:"✗ "+l}),i(l,!1)}finally{m.current===v&&(m.current=null),y(!1),p&&f()}},A=()=>{m.current?.abort(),m.current=null,f()};return e.jsxs(Q,{open:o,onClose:A,children:[e.jsx(V,{title:t("modal.configureFeishu"),onClose:A}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>n(!u),children:[e.jsx("span",{children:t("modal.feishuGuideTitle")}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${u?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),u&&e.jsxs("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:[e.jsx("p",{children:t("modal.feishuGuideStep1")}),e.jsx("p",{children:t("modal.feishuGuideStep2")}),e.jsx("p",{children:t("modal.feishuGuideStep3")}),e.jsx("p",{children:t("modal.feishuGuideStep4")}),e.jsx("p",{className:"ml-3 font-mono text-[11px] text-fg-5",children:t("modal.feishuGuidePerms")}),e.jsx("p",{children:t("modal.feishuGuideStep5")}),e.jsx("p",{children:t("modal.feishuGuideStep6")}),e.jsx("p",{children:t("modal.feishuGuideStep7")}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-5",children:t("modal.feishuGuideCardKitTip")})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.appId")}),e.jsx(P,{className:"font-mono text-xs",placeholder:t("modal.feishuPlaceholder"),value:k,onChange:v=>I(v.target.value)})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.appSecret")}),e.jsx(P,{type:"password",className:"font-mono text-xs",placeholder:t("modal.appSecret"),value:S,onChange:v=>b(v.target.value)})]}),N&&e.jsx("div",{className:"text-xs",style:{color:N.ok?"var(--th-ok)":"var(--th-err)"},children:N.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:A,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:T,onClick:j,children:t(T?"modal.validating":"modal.validateSave")})]})]})}function ce({open:o,onClose:f}){const h=C(p=>p.state),i=C(p=>p.toast),r=C(p=>p.reloadUntil),s=C(p=>p.locale),t=a.useMemo(()=>O(s),[s]),[k,I]=a.useState(Y),[S,b]=a.useState(!1),[T,y]=a.useState(""),[N,c]=a.useState(""),[u,n]=a.useState(null),m=a.useRef(null),K=a.useRef(h);K.current=h,a.useEffect(()=>{o?(I(K.current?.config.weixinBaseUrl||Y),b(!1),y(""),c(""),n(null)):(m.current?.abort(),m.current=null,b(!1))},[o]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const j=()=>{m.current?.abort(),m.current=null,f()},A=a.useCallback(async(p,d,l)=>{for(;!p.signal.aborted;){const x=await R.waitWeixinLogin(d,l,{signal:p.signal,timeoutMs:45e3});if(!x.ok&&!x.connected)return n({ok:!1,text:"✗ "+(x.error||x.message||t("modal.validationFailed"))}),!1;if(x.qrcodeUrl&&y(x.qrcodeUrl),x.status==="scaned"?n({ok:!0,text:t("modal.weixinScanned")}):x.status==="expired"?n({ok:!0,text:t("modal.weixinQrRefreshed")}):x.connected||n({ok:!0,text:t("modal.weixinWaitingScan")}),!x.connected)continue;n({ok:!0,text:t("modal.weixinLoginSuccess")});const w=x.baseUrl||l,U=x.botToken||"",W=x.accountId||"",F=await R.validateWeixinConfig(w,U,W,{signal:p.signal,timeoutMs:12e3});if(!F.ok)return n({ok:!1,text:"✗ "+(F.error||t("modal.validationFailed"))}),!1;const z=F.normalizedBaseUrl||w,g=new Set((K.current?.setupState?.channels||[]).filter(G=>(G.ready||G.configured)&&G.channel!=="weixin").map(G=>G.channel));return g.add("weixin"),await R.saveConfig({weixinBaseUrl:z,weixinBotToken:U,weixinAccountId:W,channels:[...g]}),await r(G=>{const B=G.setupState?.channels?.find(M=>M.channel==="weixin");return G.config.weixinBaseUrl===z&&G.config.weixinBotToken===U&&G.config.weixinAccountId===W&&!!B?.ready},{attempts:12,intervalMs:350})?(i(t("modal.weixinSaved")),!0):(n({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),i(t("modal.refreshStateFailed"),!1),!1)}return!1},[r,t,i]),v=async()=>{if(!k.trim()){i(t("modal.inputWeixinBaseUrl"),!1);return}m.current?.abort();const p=new AbortController;m.current=p,b(!0),y(""),c(""),n(null);let d=!1;try{const l=await R.startWeixinLogin(k.trim(),{signal:p.signal,timeoutMs:12e3});if(!l.ok||!l.qrcodeUrl){n({ok:!1,text:"✗ "+(l.error||l.message||t("modal.validationFailed"))});return}y(l.qrcodeUrl),c(l.sessionKey),n({ok:!0,text:t("modal.weixinWaitingScan")}),d=await A(p,l.sessionKey,k.trim())}catch(l){if(_(l))return;const x=X(l,t);n({ok:!1,text:"✗ "+x}),i(x,!1)}finally{m.current===p&&(m.current=null),b(!1),d&&f()}};return e.jsxs(Q,{open:o,onClose:j,children:[e.jsx(V,{title:t("modal.configureWeixin"),onClose:j}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:t("modal.weixinScanHint")}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.weixinBaseUrl")}),e.jsx(P,{className:"font-mono text-xs",value:k,onChange:p=>I(p.target.value),placeholder:Y}),e.jsx("div",{className:"mt-1 text-[11px] text-fg-5",children:t("modal.weixinDefaultBaseUrlHint")})]}),T&&e.jsxs("div",{className:"rounded-xl border border-edge bg-panel-alt p-4",children:[e.jsx("img",{src:T,alt:t("modal.weixinQrAlt"),className:"mx-auto h-56 w-56 rounded-lg bg-white p-3 object-contain"}),N&&e.jsx("div",{className:"mt-2 truncate text-center font-mono text-[10px] text-fg-5",children:N})]}),u&&e.jsx("div",{className:"text-xs",style:{color:u.ok?"var(--th-ok)":"var(--th-err)"},children:u.text})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(D,{variant:"ghost",onClick:j,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:S,onClick:v,children:t(S?T?"modal.validating":"modal.weixinGeneratingQr":T?"modal.weixinRetry":"modal.weixinGenerateQr")})]})]})}function J({open:o,onClose:f,channel:h,titleKey:i,fields:r,validate:s,savedToastKey:t,guideTitleKey:k,guideStepKeys:I,guideOpenWhenEmpty:S=!0,validateTimeoutMs:b=12e3}){const T=C(g=>g.state),y=C(g=>g.toast),N=C(g=>g.reloadUntil),c=C(g=>g.locale),u=a.useMemo(()=>O(c),[c]),[n,m]=a.useState({}),[K,j]=a.useState({}),[A,v]=a.useState(!1),[p,d]=a.useState(null),[l,x]=a.useState(!1),w=a.useRef(null),U=a.useRef(T);U.current=T;const W=!!(I&&I.length);a.useEffect(()=>{if(o){const g=U.current?.config||{},E={};let G=!1;for(const B of r){const M=String(g[B.key]??"").trim();E[B.key]=M,!M&&B.required!==!1&&(G=!0)}m(E),j({}),d(null),x(W&&S&&G)}else w.current?.abort(),w.current=null,v(!1)},[o,r,W,S]),a.useEffect(()=>()=>{w.current?.abort(),w.current=null},[]);const F=()=>{w.current?.abort(),w.current=null,f()},z=async()=>{const g={};for(const B of r){const M=String(n[B.key]||"").trim();if(g[B.key]=M,B.required!==!1&&!M){y(u(B.labelKey)+": "+u("modal.fieldRequired"),!1);return}}w.current?.abort();const E=new AbortController;w.current=E,v(!0),d(null);let G=!1;try{const B=await s(g,{signal:E.signal,timeoutMs:b});if(!B.ok){d({ok:!1,text:"✗ "+(B.error||u("modal.validationFailed"))});return}d({ok:!0,text:"✓ "+(B.identity||u("modal.credentialsVerified"))});const M=new Set((T?.setupState?.channels||[]).filter(q=>(q.ready||q.configured)&&q.channel!==h).map(q=>q.channel));if(M.add(h),await R.saveConfig({...g,channels:[...M]}),!await N(q=>{const ee=q.config||{};for(const H of r)if(String(ee[H.key]||"").trim()!==g[H.key])return!1;return!!q.setupState?.channels?.find(H=>H.channel===h)?.ready},{attempts:10,intervalMs:350})){d({ok:!1,text:"✗ "+u("modal.refreshStateFailed")}),y(u("modal.refreshStateFailed"),!1);return}y(u(t)),G=!0}catch(B){if(_(B))return;const M=X(B,u);d({ok:!1,text:"✗ "+M}),y(M,!1)}finally{w.current===E&&(w.current=null),v(!1),G&&f()}};return e.jsxs(Q,{open:o,onClose:F,children:[e.jsx(V,{title:u(i),onClose:F}),e.jsxs("div",{className:"space-y-4",children:[W&&k&&e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>x(!l),children:[e.jsx("span",{children:u(k)}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${l?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),l&&e.jsx("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:I.map(g=>e.jsx("p",{children:u(g)},g))})]}),r.map(g=>{const E=g.key,G=!!K[E],B=g.password&&!G?"password":"text";return e.jsxs("div",{children:[e.jsxs(L,{children:[u(g.labelKey),g.required===!1&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"text-fg-5",children:["(",u("modal.optional"),")"]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{type:B,className:"flex-1 font-mono text-xs",placeholder:g.placeholder?u(g.placeholder):"",value:n[E]||"",onChange:M=>m(Z=>({...Z,[E]:M.target.value}))}),g.password&&e.jsx(D,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>j(M=>({...M,[E]:!M[E]})),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]},E)}),p&&e.jsx("div",{className:"text-xs",style:{color:p.ok?"var(--th-ok)":"var(--th-err)"},children:p.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:F,children:u("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:A,onClick:z,children:u(A?"modal.validating":"modal.validateSave")})]})]})}function ue({open:o,onClose:f}){return e.jsx(J,{open:o,onClose:f,channel:"slack",titleKey:"modal.configureSlack",savedToastKey:"modal.slackSaved",guideTitleKey:"modal.slackGuideTitle",guideStepKeys:["modal.slackGuideStep1","modal.slackGuideStep2","modal.slackGuideStep3","modal.slackGuideStep4","modal.slackGuideStep5"],fields:[{key:"slackBotToken",labelKey:"modal.slackBotToken",password:!0,placeholder:"modal.slackBotTokenPlaceholder"},{key:"slackAppToken",labelKey:"modal.slackAppToken",password:!0,placeholder:"modal.slackAppTokenPlaceholder"}],validate:async(h,i)=>{const r=await R.validateSlackConfig(h.slackBotToken,h.slackAppToken,i),s=r.bot?.username?"@"+r.bot.username+(r.bot.team?" ("+r.bot.team+")":""):null;return{ok:r.ok,error:r.error,identity:s}}})}function me({open:o,onClose:f}){return e.jsx(J,{open:o,onClose:f,channel:"discord",titleKey:"modal.configureDiscord",savedToastKey:"modal.discordSaved",guideTitleKey:"modal.discordGuideTitle",guideStepKeys:["modal.discordGuideStep1","modal.discordGuideStep2","modal.discordGuideStep3","modal.discordGuideStep4","modal.discordGuideStep5"],fields:[{key:"discordBotToken",labelKey:"modal.discordBotToken",password:!0,placeholder:"modal.discordBotTokenPlaceholder"}],validate:async(h,i)=>{const r=await R.validateDiscordConfig(h.discordBotToken,i),s=r.bot?.username?"@"+r.bot.username:null;return{ok:r.ok,error:r.error,identity:s}}})}function xe({open:o,onClose:f}){return e.jsx(J,{open:o,onClose:f,channel:"dingtalk",titleKey:"modal.configureDingtalk",savedToastKey:"modal.dingtalkSaved",guideTitleKey:"modal.dingtalkGuideTitle",guideStepKeys:["modal.dingtalkGuideStep1","modal.dingtalkGuideStep2","modal.dingtalkGuideStep3","modal.dingtalkGuideStep4","modal.dingtalkGuideStep5"],fields:[{key:"dingtalkClientId",labelKey:"modal.dingtalkClientId",placeholder:"modal.dingtalkClientIdPlaceholder"},{key:"dingtalkClientSecret",labelKey:"modal.dingtalkClientSecret",password:!0,placeholder:"modal.dingtalkClientSecretPlaceholder"}],validate:async(h,i)=>{const r=await R.validateDingtalkConfig(h.dingtalkClientId,h.dingtalkClientSecret,i),s=r.app?.clientId?r.app.clientId.length>12?r.app.clientId.slice(0,6)+"..."+r.app.clientId.slice(-4):r.app.clientId:null;return{ok:r.ok,error:r.error,identity:s}}})}function fe({open:o,onClose:f}){return e.jsx(J,{open:o,onClose:f,channel:"wecom",titleKey:"modal.configureWeCom",savedToastKey:"modal.wecomSaved",guideTitleKey:"modal.wecomGuideTitle",guideStepKeys:["modal.wecomGuideStep1","modal.wecomGuideStep2","modal.wecomGuideStep3","modal.wecomGuideStep4","modal.wecomGuideNote"],fields:[{key:"wecomBotId",labelKey:"modal.wecomBotId",placeholder:"modal.wecomBotIdPlaceholder"},{key:"wecomBotSecret",labelKey:"modal.wecomBotSecret",password:!0,placeholder:"modal.wecomBotSecretPlaceholder"}],validate:async(h,i)=>{const r=await R.validateWecomConfig(h.wecomBotId,h.wecomBotSecret,i),s=r.bot?.botId?r.bot.botId:null;return{ok:r.ok,error:r.error,identity:s}}})}function he({open:o,onClose:f}){const h=C(n=>n.state),i=C(n=>n.toast),r=C(n=>n.reload),s=C(n=>n.locale),t=a.useMemo(()=>O(s),[s]),k=h?.bot?.workdir||h?.runtimeWorkdir||"",[I,S]=a.useState(""),[b,T]=a.useState(!1),[y,N]=a.useState(0);a.useEffect(()=>{o&&(S(k),N(n=>n+1))},[o,k]);const c=a.useCallback(n=>{S(n)},[]),u=async()=>{const n=I.trim();if(!n){i(t("modal.selectDirFirst"),!1);return}T(!0);try{const m=await R.switchWorkdir(n);m.ok?(await r(),i(t("modal.switchedTo")+m.workdir),f()):i(m.error||t("modal.switchFailed"),!1)}catch{i(t("modal.switchFailed"),!1)}finally{T(!1)}};return e.jsx(Q,{open:o,onClose:b?void 0:f,panelStyle:{width:"min(500px, calc(100vw - 2rem))",maxWidth:"min(500px, calc(100vw - 2rem))"},children:b?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-4 animate-in",children:[e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin text-fg-3",style:{animationDuration:"1.2s"},children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]}),e.jsx("span",{className:"text-sm font-medium text-fg-3",children:t("modal.switching")}),e.jsx("span",{className:"text-xs text-fg-5 max-w-[280px] truncate",children:I})]}):e.jsxs(e.Fragment,{children:[e.jsx(V,{title:t("modal.switchWorkdir"),onClose:f}),e.jsx(te,{initialPath:k,onSelect:c,t},y),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(D,{variant:"ghost",onClick:f,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",onClick:u,children:t("modal.selectDir")})]})]})})}function pe({open:o,onClose:f,onSaved:h}){const i=C(l=>l.toast),r=C(l=>l.locale),s=a.useMemo(()=>O(r),[r]),[t,k]=a.useState(null),[I,S]=a.useState(!1),[b,T]=a.useState(!1),[y,N]=a.useState(null);a.useEffect(()=>{o&&(S(!1),N(null),R.getBrowser().then(l=>{k(l),T(!!l.browser.enabled)}).catch(()=>k(null)))},[o]);const c=t?.browser,u=!!c?.enabled,n=!!c&&u!==b,m=c?.profileDir||"",K=s("ext.profileDir"),j=m,A=!!c?.chromeInstalled&&!!c?.profileCreated,v=t?c?.enabled?A?s("ext.browserReady"):c?.chromeInstalled?s("ext.chromeInstalled"):s("ext.needsSetup"):s("ext.disabled"):s("status.loading"),p=t&&c?.enabled?A?"ok":c?.chromeInstalled?"warn":"err":"muted",d=async()=>{S(!0),N(null);try{await R.saveConfig({browserEnabled:b});const l=await R.getBrowser();k(l),h?.()}catch{N({ok:!1,text:"✗ "+s("ext.browserModeSaveFailed")}),i(s("ext.browserModeSaveFailed"),!1),S(!1);return}if(!b){N({ok:!0,text:"✓ "+s("ext.browserDisabledSaved")}),i(s("ext.browserDisabledSaved")),S(!1);return}try{const l=await R.setupBrowser();if(!l.ok){N({ok:!1,text:"✗ "+(l.error||s("ext.browserLaunchFailed"))}),i(l.error||s("ext.browserLaunchFailed"),!1);return}k(x=>x?{...x,browser:l.browser}:{browser:l.browser}),N({ok:!0,text:"✓ "+s("ext.browserEnabledLaunched")}),i(s("ext.browserEnabledLaunched")),h?.()}catch{N({ok:!1,text:"✗ "+s("ext.browserLaunchFailed")}),i(s("ext.browserLaunchFailed"),!1)}finally{S(!1)}};return e.jsxs(Q,{open:o,onClose:f,children:[e.jsx(V,{title:s("ext.setupBrowser"),description:s("ext.setupBrowserDesc"),onClose:f}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx($,{variant:p,children:v}),c&&e.jsxs(e.Fragment,{children:[e.jsx($,{variant:u?"accent":"muted",children:s(u?"ext.enabled":"ext.disabled")}),n&&e.jsx($,{variant:"warn",children:s("ext.pendingModeChange")}),c.running&&e.jsxs($,{variant:"accent",children:[s("ext.browserOpen"),c.pid?` · PID ${c.pid}`:""]})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(L,{children:K}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"font-mono text-xs flex-1",value:j||"—",readOnly:!0,onClick:l=>l.target.select()}),e.jsx(D,{variant:"outline",size:"sm",disabled:!j,onClick:()=>{j&&(navigator.clipboard.writeText(j),i(s("ext.step2Copied")))},children:s("ext.copyPath")})]})]}),e.jsx("div",{className:"mt-3 text-xs text-fg-5",children:s(b?"ext.profileModeDesc":"ext.browserDescDisabled")}),c?.detail&&e.jsx("div",{className:"mt-2 text-xs text-fg-5",children:c.detail}),y&&e.jsx("div",{className:"mt-3 text-xs",style:{color:y.ok?"var(--th-ok)":"var(--th-err)"},children:y.text})]}),e.jsx("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:b,onChange:l=>T(l.target.checked),className:"mt-0.5 h-4 w-4 rounded border border-edge bg-inset"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-2 mb-1",children:s("ext.browserEnableToggle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s("ext.browserEnableToggleDesc")})]})]})}),e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:[e.jsx("div",{className:"text-sm font-medium text-fg-2 mb-1",children:s(b?"ext.step2Title":"ext.browserDisabledStepTitle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s(b?"ext.step2Desc":"ext.browserDisabledHint")})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:f,children:s("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:I,onClick:d,children:s(I?"ext.launching":b?"ext.enableAndLaunchBrowser":"ext.saveBrowserDisabled")})]})]})}export{pe as BrowserSetupModal,xe as DingtalkModal,me as DiscordModal,de as FeishuModal,ue as SlackModal,ie as TelegramModal,fe as WeComModal,ce as WeixinModal,he as WorkdirModal};
|