pikiclaw 0.3.26 → 0.3.28
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-CeAPX53y.js → AgentTab-CtNbvg2T.js} +1 -1
- package/dashboard/dist/assets/{BrandIcon-DHNapeU6.js → BrandIcon-C-aE815y.js} +1 -1
- package/dashboard/dist/assets/{DirBrowser-rl1DwWxj.js → DirBrowser-vJss0x7d.js} +1 -1
- package/dashboard/dist/assets/ExtensionsTab-BIJUhVs_.js +1 -0
- package/dashboard/dist/assets/{IMAccessTab-vwNxr8s5.js → IMAccessTab-emw5qxk1.js} +1 -1
- package/dashboard/dist/assets/Modal-BLxBTu-V.js +1 -0
- package/dashboard/dist/assets/{Modals-xKA81lqV.js → Modals-B3HtmZgm.js} +1 -1
- package/dashboard/dist/assets/{PermissionsTab-BprW4aDB.js → PermissionsTab-BfewCKoC.js} +1 -1
- package/dashboard/dist/assets/{Select-CoN6w4C5.js → Select-CrXZymnB.js} +1 -1
- package/dashboard/dist/assets/SessionPanel-D5onHBIe.js +1 -0
- package/dashboard/dist/assets/{SystemTab-D8goIlPB.js → SystemTab-iLxOYtia.js} +1 -1
- package/dashboard/dist/assets/index-9UgAKpbU.css +1 -0
- package/dashboard/dist/assets/index-BOjiS988.js +16 -0
- package/dashboard/dist/assets/index-xNJkl-jN.js +3 -0
- package/dashboard/dist/assets/{shared-CHbIVrko.js → shared-BSx12aDa.js} +1 -1
- package/dashboard/dist/index.html +2 -2
- package/dist/agent/auto-update.js +30 -2
- package/dist/agent/cli/auth.js +239 -0
- package/dist/agent/cli/catalog.js +36 -0
- package/dist/agent/cli/detector.js +132 -0
- package/dist/agent/cli/index.js +7 -0
- package/dist/agent/cli/registry.js +33 -0
- package/dist/agent/drivers/claude.js +45 -17
- package/dist/agent/drivers/codex.js +8 -6
- package/dist/agent/drivers/gemini.js +5 -3
- package/dist/agent/index.js +6 -3
- package/dist/agent/mcp/bridge.js +126 -24
- package/dist/agent/mcp/extensions.js +223 -24
- package/dist/agent/mcp/oauth.js +331 -0
- package/dist/agent/mcp/playwright-proxy.js +156 -51
- package/dist/agent/mcp/registry.js +42 -161
- package/dist/agent/mcp/session-server.js +2 -0
- package/dist/agent/mcp/tools/ask-user.js +129 -0
- package/dist/agent/session.js +70 -0
- package/dist/agent/skill-installer.js +33 -1
- package/dist/agent/stream.js +50 -0
- package/dist/agent/utils.js +14 -1
- package/dist/bot/bot.js +83 -11
- package/dist/bot/command-ui.js +13 -7
- package/dist/bot/commands.js +1 -0
- package/dist/bot/session-status.js +19 -10
- package/dist/browser-supervisor.js +131 -0
- package/dist/catalog/cli-tools.js +318 -0
- package/dist/catalog/index.js +21 -0
- package/dist/catalog/mcp-servers.js +287 -0
- package/dist/catalog/skill-repos.js +124 -0
- package/dist/channels/feishu/bot.js +2 -1
- package/dist/channels/weixin/bot.js +15 -7
- package/dist/cli/main.js +20 -1
- package/dist/core/config/runtime-config.js +1 -1
- package/dist/core/config/user-config.js +9 -10
- package/dist/core/constants.js +7 -0
- package/dist/core/platform.js +54 -0
- package/dist/core/process-control.js +3 -2
- package/dist/core/utils.js +2 -9
- package/dist/dashboard/routes/cli.js +155 -0
- package/dist/dashboard/routes/config.js +2 -1
- package/dist/dashboard/routes/extensions.js +293 -47
- package/dist/dashboard/routes/sessions.js +1 -10
- package/dist/dashboard/server.js +2 -0
- package/package.json +4 -2
- package/dashboard/dist/assets/ExtensionsTab-BAsjoDaY.js +0 -1
- package/dashboard/dist/assets/Modal-CQ3_xUJW.js +0 -1
- package/dashboard/dist/assets/SessionPanel-BGROPMj5.js +0 -1
- package/dashboard/dist/assets/index-BFtrf-rI.js +0 -3
- package/dashboard/dist/assets/index-DC4TENJ4.css +0 -1
- package/dashboard/dist/assets/index-LJda-MTD.js +0 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,j as e}from"./react-vendor-DTcmqLiz.js";import{u as I,e as xe,a as H,g as R,B as y,E as ge,S as q,d as Y,c as pe}from"./index-BFtrf-rI.js";import{B as he}from"./BrandIcon-DHNapeU6.js";import{M as ve,a as be,L as P}from"./Modal-CQ3_xUJW.js";import{S as K}from"./Select-CoN6w4C5.js";import{S as Z}from"./shared-CHbIVrko.js";import"./router-emLofBBH.js";const je=["claude","codex","gemini"];function Ne(t){return t==="zh-CN"?{defaultsTitle:"新会话默认值",defaultsHint:"新会话会默认采用这里的智能体、模型和推理强度。",defaultsEditTitle:"编辑新会话默认值",defaultsEditHint:"在弹窗中选择默认智能体、模型和推理强度,保存后对新会话生效。",defaultsSaved:"新会话默认值已保存",editDefaults:"修改默认值",agentsTitle:"可用智能体",defaultAgent:"默认智能体",defaultModel:"默认模型",defaultEffort:"推理强度",status:"状态",model:"模型",models:"模型",version:"版本",defaultBadge:"默认",installed:"已安装",notInstalled:"未安装",noModel:"暂无可选模型",currentModelPrefix:"当前模型",availableModelsSuffix:"个可选",availableModels:"可用模型",recommendedFor:"建议场景",currentConfig:"当前配置",effort:"推理强度",readyHint:"已安装,可直接作为新会话执行智能体。",installHint:"尚未安装,需要先完成本地 CLI 安装。",noVersion:"版本未知",moreModels:s=>`+${s}`,install:"安装",installing:"安装中...",noEffort:"不支持调整",loadFailed:"无法加载智能体状态",latestVersion:"最新版本",updateAvailable:"有新版本可用",updateSkipped:"自动更新已跳过",updateFailed:"自动更新失败",update:"手动升级",updating:"升级中...",checkUpdate:"检查更新",checking:"检查中...",upToDate:"已是最新"}:{defaultsTitle:"New Session Defaults",defaultsHint:"New sessions use this agent, model, and effort by default.",defaultsEditTitle:"Edit New Session Defaults",defaultsEditHint:"Choose the default agent, model, and effort in the modal, then save them for new sessions.",defaultsSaved:"New session defaults saved",editDefaults:"Edit Defaults",agentsTitle:"Available Agents",defaultAgent:"Default Agent",defaultModel:"Default Model",defaultEffort:"Effort",status:"Status",model:"Model",models:"Models",version:"Version",defaultBadge:"Default",installed:"Installed",notInstalled:"Not installed",noModel:"No selectable models",currentModelPrefix:"Current model",availableModelsSuffix:"available",availableModels:"Available models",recommendedFor:"Recommended for",currentConfig:"Current config",effort:"Effort",readyHint:"Installed and ready for new sessions.",installHint:"Not installed locally yet.",noVersion:"Version unavailable",moreModels:s=>`+${s}`,install:"Install",installing:"Installing...",noEffort:"Not supported",loadFailed:"Failed to load agent status",latestVersion:"Latest",updateAvailable:"Update available",updateSkipped:"Auto-update skipped",updateFailed:"Auto-update failed",update:"Update",updating:"Updating...",checkUpdate:"Check update",checking:"Checking...",upToDate:"Up to date"}}function Me(t,s){const n=t.filter(u=>u.installed);return(n.length?n:t).map(u=>({value:u.agent,label:`${R(u.agent).label} · ${u.installed?u.version||s.installed:s.notInstalled}`}))}function ke(t){if(!t)return[];const s=t.models.map(n=>({value:n.id,label:n.alias?`${n.alias} · ${n.id}`:n.id}));return t.selectedModel&&!s.some(n=>n.value===t.selectedModel)&&s.unshift({value:t.selectedModel,label:t.selectedModel}),s}function Ae(t){return t?ge[t.agent].map(s=>({value:s,label:s})):[]}function Ee(t,s){if(!t.models.length)return s.noModel;const n=t.selectedModel?t.models.find(u=>u.id===t.selectedModel):t.models[0],m=n?.alias||n?.id||s.noModel;return`${s.currentModelPrefix}: ${m} · ${t.models.length} ${s.availableModelsSuffix}`}function se(t){return t?t.alias||t.id:"—"}function le(t,s){if(!t.models.length)return s.noModel;const n=t.selectedModel?t.models.find(m=>m.id===t.selectedModel):t.models[0];return se(n)}function Se(t,s=4){const n=new Set;return t.models.map(u=>({key:u.id,label:se(u)})).filter(u=>n.has(u.key)?!1:(n.add(u.key),!0)).slice(0,s)}function ee(t,s){t({defaultAgent:s.defaultAgent,agents:s.agents})}function te(t,s){return{agent:t?.agent||s,model:t?.selectedModel||"",effort:t?.selectedEffort||""}}function G({label:t,value:s,hint:n,loading:m=!1}){return e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt px-3.5 py-2.5",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-fg-5",children:t}),e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[13px] font-semibold text-fg-2",children:[m&&e.jsx(q,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:s})]}),n&&e.jsx("div",{className:"mt-0.5 text-[10px] leading-relaxed text-fg-5",children:n})]})}function we({agent:t,copy:s,t:n,installing:m,onInstall:u,updatingAgent:o,checkingAgent:d,onUpdate:A,onCheckUpdate:U,loading:c=!1}){const E=R(t.agent),V=Ee(t,s),O=le(t,s),j=E.advantageKey?n(E.advantageKey):"—",D=Se(t),F=Math.max(0,t.models.length-D.length),_=t.selectedEffort||s.noEffort,S=t.version||s.noVersion,N=c?n("status.loading"):t.installed?s.installed:s.notInstalled,i=c?"muted":t.installed?"ok":"warn",w=c?n("status.loading"):t.installed?s.readyHint:s.installHint,C=c?n("status.loading"):O,g=c?n("status.loading"):_,p=c?n("status.loading"):j,h=c?n("status.loading"):V;return e.jsx("div",{className:"glass rounded-md border border-edge px-4 py-3 shadow-[0_1px_0_rgba(255,255,255,0.02),0_4px_12px_rgba(15,23,42,0.05)]",children:e.jsxs("div",{className:"grid gap-x-5 gap-y-3 xl:grid-cols-[220px_130px_220px_minmax(0,1fr)_auto] xl:items-start",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-md border border-edge bg-panel-alt",children:e.jsx(he,{brand:t.agent,size:22})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-[15px] font-semibold text-fg",children:E.label}),t.isDefault&&e.jsx(Y,{variant:"accent",children:s.defaultBadge})]}),e.jsxs("div",{className:"mt-1 text-[12px] leading-relaxed text-fg-5",children:[s.version,": ",S,t.latestVersion&&t.updateAvailable&&e.jsxs("span",{className:"ml-1.5 text-amber-400",children:["→ ",t.latestVersion]}),t.latestVersion&&!t.updateAvailable&&t.installed&&e.jsx("span",{className:"ml-1.5 text-emerald-400",children:"✓"})]})]})]})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s.status}),e.jsx("div",{className:"mt-1.5",children:e.jsxs(Y,{variant:i,children:[c&&e.jsx(q,{className:"h-3 w-3"}),N]})}),e.jsx("div",{className:"mt-1.5 text-[12px] leading-relaxed text-fg-5",children:w})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s.currentConfig}),e.jsxs("div",{className:"mt-1.5 space-y-1.5 text-[13px] leading-relaxed text-fg-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"w-16 shrink-0 text-fg-5",children:s.model}),e.jsx("span",{className:"min-w-0 break-words text-fg-2",children:C})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"w-16 shrink-0 text-fg-5",children:s.effort}),e.jsx("span",{className:"text-fg-2",children:g})]})]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s.recommendedFor}),e.jsx("div",{className:"mt-1.5 text-[13px] leading-relaxed text-fg-3",children:p}),e.jsx("div",{className:"mt-2.5 text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s.availableModels}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[!c&&D.length>0?D.map(v=>e.jsx("span",{className:"inline-flex h-6 max-w-full items-center rounded-md border border-edge bg-panel-alt px-2 text-[11px] text-fg-3",title:v.key,children:e.jsx("span",{className:"truncate",children:v.label})},v.key)):e.jsx("span",{className:"text-[12px] text-fg-5",children:c?n("status.loading"):s.noModel}),!c&&F>0&&e.jsx("span",{className:"inline-flex h-6 items-center rounded-md border border-edge bg-panel-alt px-2 text-[11px] text-fg-5",children:s.moreModels(F)})]}),e.jsx("div",{className:"mt-1.5 text-[12px] leading-relaxed text-fg-5",children:h})]}),e.jsxs("div",{className:pe("flex flex-col items-start gap-1.5 xl:items-end",t.installed&&"xl:self-start"),children:[c&&e.jsxs("div",{className:"inline-flex h-7 items-center gap-2 rounded-md border border-edge bg-transparent px-2.5 text-[11px] text-fg-5",children:[e.jsx(q,{className:"h-3 w-3"}),n("status.loading")]}),!c&&!t.installed&&e.jsx(y,{variant:"outline",size:"sm",disabled:m,onClick:()=>u(t),children:m?s.installing:s.install}),!c&&t.installed&&t.updateAvailable&&e.jsx(y,{variant:"primary",size:"sm",disabled:o,onClick:()=>A(t),children:o?s.updating:s.update}),!c&&t.installed&&!t.updateAvailable&&e.jsx(y,{variant:"ghost",size:"sm",disabled:d,onClick:()=>U(t),children:d?s.checking:s.checkUpdate}),!c&&t.installed&&t.updateAvailable&&t.updateStatus==="skipped"&&t.updateDetail&&e.jsxs("div",{className:"text-[11px] leading-relaxed text-amber-400",children:[s.updateSkipped,": ",t.updateDetail]}),!c&&t.installed&&t.updateStatus==="failed"&&t.updateDetail&&e.jsxs("div",{className:"text-[11px] leading-relaxed text-red-400",children:[s.updateFailed,": ",t.updateDetail]})]})]})})}function Ve(){const t=I(l=>l.locale),s=I(l=>l.toast),n=I(l=>l.agentStatus),m=I(l=>l.setAgentStatus),u=I(l=>l.refreshAgentStatus),o=r.useMemo(()=>xe(t),[t]),d=Ne(t),[A,U]=r.useState(n?{defaultAgent:n.defaultAgent,agents:n.agents}:null),[c,E]=r.useState(!n),[V,O]=r.useState(null),[j,D]=r.useState(!1),[F,_]=r.useState(null),[S,N]=r.useState(!1),[i,w]=r.useState({agent:"codex",model:"",effort:""}),C=r.useRef(!!n);r.useEffect(()=>{n&&(ee(U,n),C.current||(C.current=!0,E(!1)))},[n]);const g=r.useCallback(l=>{ee(U,l),m(l)},[m]),p=r.useCallback(async()=>{C.current||E(!0);try{const l=await H.getAgentStatus();return g(l),O(null),C.current=!0,l}catch(l){const a=l instanceof Error?l.message:d.loadFailed;return O(a),C.current||s(a,!1),null}finally{E(!1)}},[g,d.loadFailed,s]);r.useEffect(()=>{n?u():p()},[]);const h=r.useMemo(()=>{const l=A?.agents||[],a=new Map(l.map(f=>[f.agent,f]));return je.map(f=>{const T=a.get(f);if(T)return T;const b=R(f);return{agent:f,label:b.label,installed:!1,version:void 0,installCommand:void 0,selectedModel:null,selectedEffort:null,isDefault:A?.defaultAgent===f,models:[],usage:null}})},[A]),v=A?.defaultAgent||"codex",M=h.find(l=>l.agent===v)||null,J=h.filter(l=>l.installed).length>0,ae=Me(h,d),x=h.find(l=>l.agent===i.agent)||null,L=ke(x),$=Ae(x),Q=r.useCallback(async l=>{D(!0);try{const a=await H.updateRuntimeAgent(l);if(!a.ok)throw new Error(a.error||o("config.applyFailed"));return g(a),a}catch(a){const f=a instanceof Error?a.message:o("config.applyFailed");return s(f,!1),p(),null}finally{D(!1)}},[g,p,o,s]);r.useEffect(()=>{S&&w(te(M,v))},[v,M,S]),r.useEffect(()=>{if(!S||!x)return;const l=x.selectedModel||"",a=!i.model||L.some(b=>b.value===i.model),f=x.selectedEffort||"",T=!i.effort||$.some(b=>b.value===i.effort);a&&T||w(b=>({...b,model:a?b.model:l,effort:T?b.effort:f}))},[S,i.effort,i.model,x,$,L]);const ne=r.useCallback(l=>{const a=h.find(f=>f.agent===l);a?.installed&&w(te(a,a.agent))},[h]),de=r.useCallback(async()=>{if(!x?.installed)return;const l={};if(i.agent!==v&&(l.defaultAgent=i.agent),i.model&&i.model!==(x.selectedModel||"")&&(l.agent=i.agent,l.model=i.model),i.effort&&i.effort!==(x.selectedEffort||"")&&(l.agent=i.agent,l.effort=i.effort),Object.keys(l).length===0){N(!1);return}await Q(l)&&(s(d.defaultsSaved),N(!1))},[d.defaultsSaved,v,i.agent,i.effort,i.model,x,s,Q]),ie=r.useCallback(async l=>{if(!F){_(l.agent);try{const a=await H.installAgent(l.agent);if(!a.ok)throw new Error(a.error||o("config.agentInstallFailed"));g(a),s(o("config.agentInstalled"))}catch(a){const f=a instanceof Error?a.message:o("config.agentInstallFailed");s(f,!1),p()}finally{_(a=>a===l.agent?null:a)}}},[g,F,p,o,s]),[B,W]=r.useState(null),[z,X]=r.useState(null),re=r.useCallback(async l=>{if(!B){W(l.agent);try{const a=await H.updateAgent(l.agent);if(!a.ok)throw new Error(a.error||o("config.agentInstallFailed"));g(a),s(d.upToDate)}catch(a){const f=a instanceof Error?a.message:d.updateFailed;s(f,!1),p()}finally{W(a=>a===l.agent?null:a)}}},[g,d.updateFailed,d.upToDate,p,o,s,B]),oe=r.useCallback(async l=>{if(!z){X(l.agent);try{const a=await H.checkAgentUpdate(l.agent);if(!a.ok)throw new Error(a.error||d.loadFailed);g(a)}catch(a){const f=a instanceof Error?a.message:d.loadFailed;s(f,!1),p()}finally{X(a=>a===l.agent?null:a)}}},[g,z,d.loadFailed,p,s]),k=c&&!A,ce=k?o("status.loading"):M?R(M.agent).label:d.notInstalled,fe=k?o("status.loading"):M?.installed?d.installed:d.notInstalled,ue=k?o("status.loading"):M?le(M,d):d.noModel,me=k?o("status.loading"):M?.selectedEffort||d.noEffort;return e.jsxs("div",{className:"animate-in space-y-4",children:[e.jsx("section",{className:"space-y-3",children:e.jsxs(Z,{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-base font-semibold tracking-tight text-fg",children:d.defaultsTitle}),e.jsx("div",{className:"mt-0.5 text-[13px] leading-relaxed text-fg-4",children:d.defaultsHint})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(y,{variant:"secondary",onClick:()=>N(!0),disabled:j||!J,children:d.editDefaults})})]}),e.jsxs("div",{className:"grid gap-2.5 lg:grid-cols-3",children:[e.jsx(G,{label:d.defaultAgent,value:ce,hint:fe,loading:k}),e.jsx(G,{label:d.defaultModel,value:ue,loading:k}),e.jsx(G,{label:d.defaultEffort,value:me,loading:k})]})]})}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-fg-5",children:d.agentsTitle}),e.jsx("div",{className:"space-y-3",children:h.map(l=>e.jsx(we,{agent:l,copy:d,t:o,installing:F===l.agent,loading:k,onInstall:ie,updatingAgent:B===l.agent,checkingAgent:z===l.agent,onUpdate:re,onCheckUpdate:oe},l.agent))})]}),V&&e.jsx(Z,{className:"border-amber-500/20 bg-amber-500/5",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[13px] text-fg-2",children:V}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{p()},children:o("sessions.retry")})]})}),e.jsxs(ve,{open:S,onClose:()=>N(!1),children:[e.jsx(be,{title:d.defaultsEditTitle,description:d.defaultsEditHint,onClose:()=>N(!1)}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(P,{children:d.defaultAgent}),e.jsx(K,{value:i.agent,options:ae,onChange:ne,disabled:j||!J,placeholder:d.notInstalled})]}),e.jsxs("div",{children:[e.jsx(P,{children:d.defaultModel}),e.jsx(K,{value:i.model,options:L,onChange:l=>w(a=>({...a,model:l})),disabled:j||!x?.installed||L.length===0,placeholder:d.noModel})]}),e.jsxs("div",{children:[e.jsx(P,{children:d.defaultEffort}),e.jsx(K,{value:i.effort,options:$,onChange:l=>w(a=>({...a,effort:l})),disabled:j||!x?.installed||$.length===0,placeholder:d.noEffort})]})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(y,{variant:"ghost",onClick:()=>N(!1),children:o("modal.cancel")}),e.jsx(y,{variant:"primary",disabled:j||!x?.installed,onClick:()=>{de()},children:o(j?"config.validating":"modal.save")})]})]})]})}export{Ve as AgentTab,Ve as default};
|
|
1
|
+
import{r,j as e}from"./react-vendor-DTcmqLiz.js";import{u as I,b as xe,a as H,g as R,B as y,E as ge,S as q,k as Y,c as pe}from"./index-xNJkl-jN.js";import{B as he}from"./BrandIcon-C-aE815y.js";import{M as ve,a as be,L as P}from"./Modal-BLxBTu-V.js";import{S as K}from"./Select-CrXZymnB.js";import{S as Z}from"./shared-BSx12aDa.js";import"./router-emLofBBH.js";const je=["claude","codex","gemini"];function Ne(t){return t==="zh-CN"?{defaultsTitle:"新会话默认值",defaultsHint:"新会话会默认采用这里的智能体、模型和推理强度。",defaultsEditTitle:"编辑新会话默认值",defaultsEditHint:"在弹窗中选择默认智能体、模型和推理强度,保存后对新会话生效。",defaultsSaved:"新会话默认值已保存",editDefaults:"修改默认值",agentsTitle:"可用智能体",defaultAgent:"默认智能体",defaultModel:"默认模型",defaultEffort:"推理强度",status:"状态",model:"模型",models:"模型",version:"版本",defaultBadge:"默认",installed:"已安装",notInstalled:"未安装",noModel:"暂无可选模型",currentModelPrefix:"当前模型",availableModelsSuffix:"个可选",availableModels:"可用模型",recommendedFor:"建议场景",currentConfig:"当前配置",effort:"推理强度",readyHint:"已安装,可直接作为新会话执行智能体。",installHint:"尚未安装,需要先完成本地 CLI 安装。",noVersion:"版本未知",moreModels:s=>`+${s}`,install:"安装",installing:"安装中...",noEffort:"不支持调整",loadFailed:"无法加载智能体状态",latestVersion:"最新版本",updateAvailable:"有新版本可用",updateSkipped:"自动更新已跳过",updateFailed:"自动更新失败",update:"手动升级",updating:"升级中...",checkUpdate:"检查更新",checking:"检查中...",upToDate:"已是最新"}:{defaultsTitle:"New Session Defaults",defaultsHint:"New sessions use this agent, model, and effort by default.",defaultsEditTitle:"Edit New Session Defaults",defaultsEditHint:"Choose the default agent, model, and effort in the modal, then save them for new sessions.",defaultsSaved:"New session defaults saved",editDefaults:"Edit Defaults",agentsTitle:"Available Agents",defaultAgent:"Default Agent",defaultModel:"Default Model",defaultEffort:"Effort",status:"Status",model:"Model",models:"Models",version:"Version",defaultBadge:"Default",installed:"Installed",notInstalled:"Not installed",noModel:"No selectable models",currentModelPrefix:"Current model",availableModelsSuffix:"available",availableModels:"Available models",recommendedFor:"Recommended for",currentConfig:"Current config",effort:"Effort",readyHint:"Installed and ready for new sessions.",installHint:"Not installed locally yet.",noVersion:"Version unavailable",moreModels:s=>`+${s}`,install:"Install",installing:"Installing...",noEffort:"Not supported",loadFailed:"Failed to load agent status",latestVersion:"Latest",updateAvailable:"Update available",updateSkipped:"Auto-update skipped",updateFailed:"Auto-update failed",update:"Update",updating:"Updating...",checkUpdate:"Check update",checking:"Checking...",upToDate:"Up to date"}}function Me(t,s){const n=t.filter(u=>u.installed);return(n.length?n:t).map(u=>({value:u.agent,label:`${R(u.agent).label} · ${u.installed?u.version||s.installed:s.notInstalled}`}))}function ke(t){if(!t)return[];const s=t.models.map(n=>({value:n.id,label:n.alias?`${n.alias} · ${n.id}`:n.id}));return t.selectedModel&&!s.some(n=>n.value===t.selectedModel)&&s.unshift({value:t.selectedModel,label:t.selectedModel}),s}function Ae(t){return t?ge[t.agent].map(s=>({value:s,label:s})):[]}function Ee(t,s){if(!t.models.length)return s.noModel;const n=t.selectedModel?t.models.find(u=>u.id===t.selectedModel):t.models[0],m=n?.alias||n?.id||s.noModel;return`${s.currentModelPrefix}: ${m} · ${t.models.length} ${s.availableModelsSuffix}`}function se(t){return t?t.alias||t.id:"—"}function le(t,s){if(!t.models.length)return s.noModel;const n=t.selectedModel?t.models.find(m=>m.id===t.selectedModel):t.models[0];return se(n)}function Se(t,s=4){const n=new Set;return t.models.map(u=>({key:u.id,label:se(u)})).filter(u=>n.has(u.key)?!1:(n.add(u.key),!0)).slice(0,s)}function ee(t,s){t({defaultAgent:s.defaultAgent,agents:s.agents})}function te(t,s){return{agent:t?.agent||s,model:t?.selectedModel||"",effort:t?.selectedEffort||""}}function G({label:t,value:s,hint:n,loading:m=!1}){return e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt px-3.5 py-2.5",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-fg-5",children:t}),e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[13px] font-semibold text-fg-2",children:[m&&e.jsx(q,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:s})]}),n&&e.jsx("div",{className:"mt-0.5 text-[10px] leading-relaxed text-fg-5",children:n})]})}function we({agent:t,copy:s,t:n,installing:m,onInstall:u,updatingAgent:o,checkingAgent:d,onUpdate:A,onCheckUpdate:U,loading:c=!1}){const E=R(t.agent),V=Ee(t,s),O=le(t,s),j=E.advantageKey?n(E.advantageKey):"—",D=Se(t),F=Math.max(0,t.models.length-D.length),_=t.selectedEffort||s.noEffort,S=t.version||s.noVersion,N=c?n("status.loading"):t.installed?s.installed:s.notInstalled,i=c?"muted":t.installed?"ok":"warn",w=c?n("status.loading"):t.installed?s.readyHint:s.installHint,C=c?n("status.loading"):O,g=c?n("status.loading"):_,p=c?n("status.loading"):j,h=c?n("status.loading"):V;return e.jsx("div",{className:"glass rounded-md border border-edge px-4 py-3 shadow-[0_1px_0_rgba(255,255,255,0.02),0_4px_12px_rgba(15,23,42,0.05)]",children:e.jsxs("div",{className:"grid gap-x-5 gap-y-3 xl:grid-cols-[220px_130px_220px_minmax(0,1fr)_auto] xl:items-start",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-md border border-edge bg-panel-alt",children:e.jsx(he,{brand:t.agent,size:22})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-[15px] font-semibold text-fg",children:E.label}),t.isDefault&&e.jsx(Y,{variant:"accent",children:s.defaultBadge})]}),e.jsxs("div",{className:"mt-1 text-[12px] leading-relaxed text-fg-5",children:[s.version,": ",S,t.latestVersion&&t.updateAvailable&&e.jsxs("span",{className:"ml-1.5 text-amber-400",children:["→ ",t.latestVersion]}),t.latestVersion&&!t.updateAvailable&&t.installed&&e.jsx("span",{className:"ml-1.5 text-emerald-400",children:"✓"})]})]})]})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s.status}),e.jsx("div",{className:"mt-1.5",children:e.jsxs(Y,{variant:i,children:[c&&e.jsx(q,{className:"h-3 w-3"}),N]})}),e.jsx("div",{className:"mt-1.5 text-[12px] leading-relaxed text-fg-5",children:w})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s.currentConfig}),e.jsxs("div",{className:"mt-1.5 space-y-1.5 text-[13px] leading-relaxed text-fg-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"w-16 shrink-0 text-fg-5",children:s.model}),e.jsx("span",{className:"min-w-0 break-words text-fg-2",children:C})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"w-16 shrink-0 text-fg-5",children:s.effort}),e.jsx("span",{className:"text-fg-2",children:g})]})]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s.recommendedFor}),e.jsx("div",{className:"mt-1.5 text-[13px] leading-relaxed text-fg-3",children:p}),e.jsx("div",{className:"mt-2.5 text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s.availableModels}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[!c&&D.length>0?D.map(v=>e.jsx("span",{className:"inline-flex h-6 max-w-full items-center rounded-md border border-edge bg-panel-alt px-2 text-[11px] text-fg-3",title:v.key,children:e.jsx("span",{className:"truncate",children:v.label})},v.key)):e.jsx("span",{className:"text-[12px] text-fg-5",children:c?n("status.loading"):s.noModel}),!c&&F>0&&e.jsx("span",{className:"inline-flex h-6 items-center rounded-md border border-edge bg-panel-alt px-2 text-[11px] text-fg-5",children:s.moreModels(F)})]}),e.jsx("div",{className:"mt-1.5 text-[12px] leading-relaxed text-fg-5",children:h})]}),e.jsxs("div",{className:pe("flex flex-col items-start gap-1.5 xl:items-end",t.installed&&"xl:self-start"),children:[c&&e.jsxs("div",{className:"inline-flex h-7 items-center gap-2 rounded-md border border-edge bg-transparent px-2.5 text-[11px] text-fg-5",children:[e.jsx(q,{className:"h-3 w-3"}),n("status.loading")]}),!c&&!t.installed&&e.jsx(y,{variant:"outline",size:"sm",disabled:m,onClick:()=>u(t),children:m?s.installing:s.install}),!c&&t.installed&&t.updateAvailable&&e.jsx(y,{variant:"primary",size:"sm",disabled:o,onClick:()=>A(t),children:o?s.updating:s.update}),!c&&t.installed&&!t.updateAvailable&&e.jsx(y,{variant:"ghost",size:"sm",disabled:d,onClick:()=>U(t),children:d?s.checking:s.checkUpdate}),!c&&t.installed&&t.updateAvailable&&t.updateStatus==="skipped"&&t.updateDetail&&e.jsxs("div",{className:"text-[11px] leading-relaxed text-amber-400",children:[s.updateSkipped,": ",t.updateDetail]}),!c&&t.installed&&t.updateStatus==="failed"&&t.updateDetail&&e.jsxs("div",{className:"text-[11px] leading-relaxed text-red-400",children:[s.updateFailed,": ",t.updateDetail]})]})]})})}function Ve(){const t=I(l=>l.locale),s=I(l=>l.toast),n=I(l=>l.agentStatus),m=I(l=>l.setAgentStatus),u=I(l=>l.refreshAgentStatus),o=r.useMemo(()=>xe(t),[t]),d=Ne(t),[A,U]=r.useState(n?{defaultAgent:n.defaultAgent,agents:n.agents}:null),[c,E]=r.useState(!n),[V,O]=r.useState(null),[j,D]=r.useState(!1),[F,_]=r.useState(null),[S,N]=r.useState(!1),[i,w]=r.useState({agent:"codex",model:"",effort:""}),C=r.useRef(!!n);r.useEffect(()=>{n&&(ee(U,n),C.current||(C.current=!0,E(!1)))},[n]);const g=r.useCallback(l=>{ee(U,l),m(l)},[m]),p=r.useCallback(async()=>{C.current||E(!0);try{const l=await H.getAgentStatus();return g(l),O(null),C.current=!0,l}catch(l){const a=l instanceof Error?l.message:d.loadFailed;return O(a),C.current||s(a,!1),null}finally{E(!1)}},[g,d.loadFailed,s]);r.useEffect(()=>{n?u():p()},[]);const h=r.useMemo(()=>{const l=A?.agents||[],a=new Map(l.map(f=>[f.agent,f]));return je.map(f=>{const T=a.get(f);if(T)return T;const b=R(f);return{agent:f,label:b.label,installed:!1,version:void 0,installCommand:void 0,selectedModel:null,selectedEffort:null,isDefault:A?.defaultAgent===f,models:[],usage:null}})},[A]),v=A?.defaultAgent||"codex",M=h.find(l=>l.agent===v)||null,J=h.filter(l=>l.installed).length>0,ae=Me(h,d),x=h.find(l=>l.agent===i.agent)||null,L=ke(x),$=Ae(x),Q=r.useCallback(async l=>{D(!0);try{const a=await H.updateRuntimeAgent(l);if(!a.ok)throw new Error(a.error||o("config.applyFailed"));return g(a),a}catch(a){const f=a instanceof Error?a.message:o("config.applyFailed");return s(f,!1),p(),null}finally{D(!1)}},[g,p,o,s]);r.useEffect(()=>{S&&w(te(M,v))},[v,M,S]),r.useEffect(()=>{if(!S||!x)return;const l=x.selectedModel||"",a=!i.model||L.some(b=>b.value===i.model),f=x.selectedEffort||"",T=!i.effort||$.some(b=>b.value===i.effort);a&&T||w(b=>({...b,model:a?b.model:l,effort:T?b.effort:f}))},[S,i.effort,i.model,x,$,L]);const ne=r.useCallback(l=>{const a=h.find(f=>f.agent===l);a?.installed&&w(te(a,a.agent))},[h]),de=r.useCallback(async()=>{if(!x?.installed)return;const l={};if(i.agent!==v&&(l.defaultAgent=i.agent),i.model&&i.model!==(x.selectedModel||"")&&(l.agent=i.agent,l.model=i.model),i.effort&&i.effort!==(x.selectedEffort||"")&&(l.agent=i.agent,l.effort=i.effort),Object.keys(l).length===0){N(!1);return}await Q(l)&&(s(d.defaultsSaved),N(!1))},[d.defaultsSaved,v,i.agent,i.effort,i.model,x,s,Q]),ie=r.useCallback(async l=>{if(!F){_(l.agent);try{const a=await H.installAgent(l.agent);if(!a.ok)throw new Error(a.error||o("config.agentInstallFailed"));g(a),s(o("config.agentInstalled"))}catch(a){const f=a instanceof Error?a.message:o("config.agentInstallFailed");s(f,!1),p()}finally{_(a=>a===l.agent?null:a)}}},[g,F,p,o,s]),[B,W]=r.useState(null),[z,X]=r.useState(null),re=r.useCallback(async l=>{if(!B){W(l.agent);try{const a=await H.updateAgent(l.agent);if(!a.ok)throw new Error(a.error||o("config.agentInstallFailed"));g(a),s(d.upToDate)}catch(a){const f=a instanceof Error?a.message:d.updateFailed;s(f,!1),p()}finally{W(a=>a===l.agent?null:a)}}},[g,d.updateFailed,d.upToDate,p,o,s,B]),oe=r.useCallback(async l=>{if(!z){X(l.agent);try{const a=await H.checkAgentUpdate(l.agent);if(!a.ok)throw new Error(a.error||d.loadFailed);g(a)}catch(a){const f=a instanceof Error?a.message:d.loadFailed;s(f,!1),p()}finally{X(a=>a===l.agent?null:a)}}},[g,z,d.loadFailed,p,s]),k=c&&!A,ce=k?o("status.loading"):M?R(M.agent).label:d.notInstalled,fe=k?o("status.loading"):M?.installed?d.installed:d.notInstalled,ue=k?o("status.loading"):M?le(M,d):d.noModel,me=k?o("status.loading"):M?.selectedEffort||d.noEffort;return e.jsxs("div",{className:"animate-in space-y-4",children:[e.jsx("section",{className:"space-y-3",children:e.jsxs(Z,{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-base font-semibold tracking-tight text-fg",children:d.defaultsTitle}),e.jsx("div",{className:"mt-0.5 text-[13px] leading-relaxed text-fg-4",children:d.defaultsHint})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(y,{variant:"secondary",onClick:()=>N(!0),disabled:j||!J,children:d.editDefaults})})]}),e.jsxs("div",{className:"grid gap-2.5 lg:grid-cols-3",children:[e.jsx(G,{label:d.defaultAgent,value:ce,hint:fe,loading:k}),e.jsx(G,{label:d.defaultModel,value:ue,loading:k}),e.jsx(G,{label:d.defaultEffort,value:me,loading:k})]})]})}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-fg-5",children:d.agentsTitle}),e.jsx("div",{className:"space-y-3",children:h.map(l=>e.jsx(we,{agent:l,copy:d,t:o,installing:F===l.agent,loading:k,onInstall:ie,updatingAgent:B===l.agent,checkingAgent:z===l.agent,onUpdate:re,onCheckUpdate:oe},l.agent))})]}),V&&e.jsx(Z,{className:"border-amber-500/20 bg-amber-500/5",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[13px] text-fg-2",children:V}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{p()},children:o("sessions.retry")})]})}),e.jsxs(ve,{open:S,onClose:()=>N(!1),children:[e.jsx(be,{title:d.defaultsEditTitle,description:d.defaultsEditHint,onClose:()=>N(!1)}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(P,{children:d.defaultAgent}),e.jsx(K,{value:i.agent,options:ae,onChange:ne,disabled:j||!J,placeholder:d.notInstalled})]}),e.jsxs("div",{children:[e.jsx(P,{children:d.defaultModel}),e.jsx(K,{value:i.model,options:L,onChange:l=>w(a=>({...a,model:l})),disabled:j||!x?.installed||L.length===0,placeholder:d.noModel})]}),e.jsxs("div",{children:[e.jsx(P,{children:d.defaultEffort}),e.jsx(K,{value:i.effort,options:$,onChange:l=>w(a=>({...a,effort:l})),disabled:j||!x?.installed||$.length===0,placeholder:d.noEffort})]})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(y,{variant:"ghost",onClick:()=>N(!1),children:o("modal.cancel")}),e.jsx(y,{variant:"primary",disabled:j||!x?.installed,onClick:()=>{de()},children:o(j?"config.validating":"modal.save")})]})]})]})}export{Ve as AgentTab,Ve as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as t}from"./react-vendor-DTcmqLiz.js";import{c as s}from"./index-
|
|
1
|
+
import{j as t}from"./react-vendor-DTcmqLiz.js";import{c as s}from"./index-xNJkl-jN.js";const o="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAF+0lEQVRYha2XbXBUZxXHf+e5u4SkCZjg0NIWnQLJLgRF5UWnL75MP9gMjqPT2eyC0qlMiYxOUAR206LOyhiSTVscp52O0xamWgu7WTp0qLUz6kht6Qed1L7M5GUTsAoDTRSIJJos2b33+GFfWMJuNqmcT/c595z/+d3nOc+9zxXKWE9Li7tm0fjyqmT6H0t/Fp8sFz9XM+UCauouH8Rx+ifmWWdP7Q0sLRbT98g3lySC/mcSQd+GGwrQt2vzx1G2ZEa6KJ3S1mJxlpOKIDyEmEM3FGCk5vw5YCw3FmFbb9hXfV2gcm/26vINBfhS+LU0qgcKXB9xT1hbr6kdDhtgcYaDxHSNwVBg92Ao0DMY8n97zgAAZnK8U2AoX1D0++rzWfkC44k6wAVghP7C3EQo8Iiijyq61oEDiV2bPjojwKk234pEsPnh/lDgzpyv/olXrwi6qyDsjsQy2ZQXmJdefPWWvp0v3uZ/CLQ9NxZINpxJj84IYDvmOUT2G/T1DD0CUB/pflnhd1eT5Mcnwl90Adi23JzPl9TbAEN7fF9AeapQW5AOicftGQFEOJ+9tEDbB9v8x99r21wLYBlnJ5AGUKhfklz8QEbY3J71nVnZceziUPAbtzvGxAB3wdPH6yPRx6cXvw4gbbm/B5zIO5SvVKjdMxAMrKvviPcpHMyLqvyoN+ybh7AUwIi+M9TaVOGI/SJwc4Fsf6rS2SqgxQBkukPDYTM40RdCZB/Z5gKmEGmzjStq2alBoDqbvF2hEWgF9oEuAvlugdx/Deaz9ZEjvcWKFwXIWaLNv14cDqmwugDvFRVOi8qOrOMdhT6BzQhvoNxzjbjItxo6o8+VqjEjAMBQa1OFXbXwh4KGuLqmDleXToHzwG1FpLs9kah/uvf98IPz08nkSuZbp+vDL4zNCJAHaQt82lH9JfCJ2cQrTFjq8hiZGrfVtQGcDQhrFNYAywELuFw15SwRgN6dvrrahcnkreGXJ0pCtDZVOFULwsCerEBJExhVGAY8FH/Z2cBvPJHY1ySx13cbaXMaqACSwCVRLqlhVNBRVTOm4lxCOSdqPkB0FdA2m5kosGGEHpC3UP2z6uRJb9fx8SwsJEL+nwBNwEKgWqBSoXaORQqtH+VNhDdErJMNnYf/ViqwbBNO3lRbVZFSS9yyIG1jucRuVuGnM6TZZL4d/wS9KEgawIH/gF5EzAWBvzecto9KPG7PqgkBTu0NLHVs7VBlcxnwS8ALgtyp6Kco3S9/OF850lQWYCD41RpMZUiUH5BZmgkRDqmyVaCqeJYeS1dqwJq4UoG56S5w7hb4PMp6YH426LJR1+qSAOrzWYPLZCvIPuAWAIHXxGGXY3geWAV6DOTrJRR+r5q8P9dskNtJ1etBVl4R19FPdh4eLQowEPR5RKxfgebOeGMqGvLMX/V0YrK/W+B+4ATCYZRnEJ5E+Q5gFM4AFwQ+I8hbLks2Ltt/ZKTUg163Rwfamrcj5q/54spvLZes9nZ2/yIx0b8jW/wCLmeLOLoCAEdeAjmYnaWPGXga9Jiia1O28+bAbt8dswJQEFF5IrO2chGVBzxdsY0r2qNnBx5uvkuELkAFedDTHj+nIl4AIzJsjL2XTAOisB+XtqryKLBcLHNyKLSpsSyAgKrKJoRtbksaPV3R5yFz7BaHOOBGOdAQib6SRV4L4KQZqe+I/wvYmZWqE1ue8nbFggjbgDoH/VOxY3vZXdDT0uKuqR37I+jdIH9JV9r3NIbjU717fLe4jPkASDVEYhW5730i2PwqIvdlZkK3eCPdv06E/GuAbmCBJxJbUnIGill13b8fyxRnRG070BiOTwG4MeuyszBSeNiw3KZFYDTzdPLzU7u3LPZEYu+qTq5Tlev+K2YESAQD94rKjqzgl72Pxd/P3VNLsgAyXJizoj161kG3Z4d1aZP6HIC36/i4tyt6dE4AasQNDIhxNnoisXevvZndJcLw9DxvpLsb5XGE9yzD2ZlqzPpVPN0SIf854FaUZz1dsW0fVqdsD5Q05Qhgg7z+oTX+Xyv2pzNX+x+eTlGviPgh3AAAAABJRU5ErkJggg==",g="/assets/codex-DYadqqp0.png",r="/assets/feishu-C4OMrjCW.ico",a="/assets/gemini-BYkEpiWr.svg",n="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='16px'%20height='16px'%20viewBox='0%200%2016%2016'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cdefs%3e%3clinearGradient%20x1='50%25'%20y1='0%25'%20x2='50%25'%20y2='100%25'%20id='linearGradient-1'%3e%3cstop%20stop-color='%2338AEEB'%20offset='0%25'%3e%3c/stop%3e%3cstop%20stop-color='%23279AD1'%20offset='100%25'%3e%3c/stop%3e%3c/linearGradient%3e%3c/defs%3e%3cg%20id='Artboard'%20stroke='none'%20stroke-width='1'%20fill='none'%20fill-rule='evenodd'%3e%3ccircle%20id='Oval'%20fill='url(%23linearGradient-1)'%20cx='8'%20cy='8'%20r='8'%3e%3c/circle%3e%3cpath%20d='M3.17026167,7.83635602%20C5.78750201,6.74265999%207.53273882,6.02162863%208.40597211,5.67326193%20C10.8992306,4.67860423%2011.2454541,4.53439191%2011.5831299,4.52864956%20C11.6573986,4.52743168%2011.8385417,4.55776042%2011.9798438,4.67645833%20C12.1211458,4.79515625%2012.1635786,4.87206678%2012.1755371,4.93908691%20C12.1874957,5.00610705%2012.1862759,5.21456762%2012.1744385,5.3338623%20C12.0393279,6.69547283%2011.5259342,9.83829771%2011.2285121,11.3633248%20C11.1026617,12.008621%2010.8548582,12.2249854%2010.6149558,12.2461596%20C10.0935924,12.2921758%209.69769267,11.9156852%209.19272668,11.5981993%20C8.40255458,11.1013965%208.13911734,10.9180161%207.3721185,10.4332283%20C6.48571864,9.87297217%206.85080034,9.6784879%207.35595703,9.17524981%20C7.48815894,9.04355001%209.67825076,7.04590073%209.71077046,6.86250183%20C9.7391276,6.70257812%209.7494847,6.68189389%209.67664063,6.60973958%20C9.60379655,6.53758527%209.51674192,6.54658941%209.46083149,6.55876051%20C9.38158015,6.57601267%208.17521836,7.33962686%205.84174612,8.84960308%20C5.48344358,9.08558775%205.15890428,9.20056741%204.86812819,9.19454205%20C4.54757089,9.18789957%203.93094724,9.02070014%203.47255094,8.87778221%20C2.91030922,8.70248755%202.46345069,8.609808%202.50236203,8.31210343%20C2.52262946,8.15704047%202.74526267,7.998458%203.17026167,7.83635602%20Z'%20id='Path-3'%20fill='%23FFFFFF'%3e%3c/path%3e%3c/g%3e%3c/svg%3e",d="data:image/svg+xml,%3csvg%20width='128'%20height='128'%20viewBox='0%200%20128%20128'%20xmlns='http://www.w3.org/2000/svg'%3e%3crect%20width='128'%20height='128'%20rx='28'%20fill='%2307C160'/%3e%3cpath%20d='M42%2033c-16.569%200-30%2011.64-30%2026%200%208.084%204.283%2015.306%2011.008%2020.073L18%2095l20.832-8.102A37.33%2037.33%200%200%200%2042%2087c16.569%200%2030-11.64%2030-26S58.569%2033%2042%2033Z'%20fill='%23fff'/%3e%3cpath%20d='M85%2048c-13.807%200-25%209.402-25%2021%200%2011.598%2011.193%2021%2025%2021%202.545%200%205-.319%207.29-.91L109%2095l-4.772-12.27C109.078%2079.05%20112%2074.232%20112%2069c0-11.598-12.193-21-27-21Z'%20fill='%23fff'%20opacity='.95'/%3e%3ccircle%20cx='33'%20cy='56'%20r='4.5'%20fill='%2307C160'/%3e%3ccircle%20cx='50'%20cy='56'%20r='4.5'%20fill='%2307C160'/%3e%3ccircle%20cx='77'%20cy='66'%20r='4'%20fill='%2307C160'/%3e%3ccircle%20cx='92'%20cy='66'%20r='4'%20fill='%2307C160'/%3e%3c/svg%3e",w="/assets/playwright-BldPFZgC.ico",h="/assets/appium-Ra-JU1qL.png",x="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M23.15%202.587L18.21.21a1.494%201.494%200%200%200-1.705.29l-9.46%208.63-4.12-3.128a.999.999%200%200%200-1.276.057L.327%207.261A1%201%200%200%200%20.326%208.74L3.899%2012%20.326%2015.26a1%201%200%200%200%20.001%201.479L1.65%2017.94a.999.999%200%200%200%201.276.057l4.12-3.128%209.46%208.63a1.492%201.492%200%200%200%201.704.29l4.942-2.377A1.5%201.5%200%200%200%2024%2020.06V3.939a1.5%201.5%200%200%200-.85-1.352zm-5.146%2014.861L10.826%2012l7.178-5.448v10.896z'%20fill='%23007ACC'/%3e%3c/svg%3e",f="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3crect%20width='24'%20height='24'%20rx='5.5'%20fill='%2319191C'/%3e%3cpath%20d='M7%205l10%207-4.5%201.5L15.5%2019l-2.2.8-3-5.5L7%2017z'%20fill='%23fff'/%3e%3c/svg%3e",A="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3crect%20width='24'%20height='24'%20rx='5.5'%20fill='%230BA48A'/%3e%3cpath%20d='M8%2018l2-12h2.5l-1.2%205h4.2L10%2018H8zm3.5-3.5l3-7.5'%20fill='%23fff'%20fill-rule='evenodd'/%3e%3c/svg%3e",v="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3crect%20width='24'%20height='24'%20rx='5.5'%20fill='%234A90D9'/%3e%3crect%20x='5'%20y='5'%20width='14'%20height='12'%20rx='1.5'%20fill='%236DB3F2'/%3e%3crect%20x='5'%20y='5'%20width='14'%20height='3.5'%20rx='1.5'%20fill='%233D7ABF'/%3e%3ccircle%20cx='8.5'%20cy='6.8'%20r='.8'%20fill='%23FF5F57'/%3e%3ccircle%20cx='11'%20cy='6.8'%20r='.8'%20fill='%23FEBC2E'/%3e%3ccircle%20cx='13.5'%20cy='6.8'%20r='.8'%20fill='%2328C840'/%3e%3crect%20x='7'%20y='10.5'%20width='10'%20height='1'%20rx='.5'%20fill='%23fff'%20opacity='.7'/%3e%3crect%20x='7'%20y='13'%20width='7'%20height='1'%20rx='.5'%20fill='%23fff'%20opacity='.5'/%3e%3c/svg%3e",L={claude:o,codex:g,gemini:a,telegram:n,feishu:r,weixin:d,playwright:w,appium:h,vscode:x,cursor:f,windsurf:A,finder:v};function C({brand:i,size:e=18,className:l}){const c=L[i];return c?t.jsx("img",{src:c,alt:"","aria-hidden":"true",draggable:!1,className:s("shrink-0 object-contain select-none",l),style:{width:e,height:e}}):null}export{C as B};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,j as e}from"./react-vendor-DTcmqLiz.js";import{a as I,
|
|
1
|
+
import{r,j as e}from"./react-vendor-DTcmqLiz.js";import{a as I,k as P,S as z}from"./index-xNJkl-jN.js";function W({initialPath:x,maxHeight:j=420,minHeight:N=200,onSelect:p,compact:l,t:o}){const[y,k]=r.useState(""),[h,m]=r.useState(""),[g,w]=r.useState([]),[i,S]=r.useState(""),[C,$]=r.useState(!1),[D,B]=r.useState([]),[E,c]=r.useState(!1),[u,d]=r.useState(""),a=r.useCallback(async t=>{c(!0),d("");try{const s=await I.lsDir(t);if(!s.ok){d(s.error||o("modal.cannotRead")),c(!1);return}k(s.path),m(s.path),w(s.dirs),S(s.parent),$(s.isGit);const G=s.path.split("/").filter(Boolean);let v="";B(G.map(b=>(v+="/"+b,{label:b,path:v}))),p?.(s.path,s.isGit)}catch{d(o("modal.loadFailed"))}finally{c(!1)}},[o,p]);r.useEffect(()=>{x!==void 0&&a(x||void 0)},[]);const n=l?"text-[11px]":"text-xs",f=l?"py-[5px]":"py-[7px]";return e.jsxs("div",{children:[e.jsxs("div",{className:`flex items-center gap-1 ${l?"text-[10px]":"text-[11px]"} font-mono text-fg-4 mb-2 flex-wrap`,children:[e.jsx("span",{className:"cursor-pointer hover:text-fg-2 transition-colors",onClick:()=>a("/"),children:"~"}),D.map((t,s)=>e.jsxs("span",{children:[e.jsx("span",{className:"text-fg-6",children:"/"}),e.jsx("span",{className:"cursor-pointer hover:text-fg-2 transition-colors",onClick:()=>a(t.path),children:t.label})]},s)),C&&e.jsx(P,{variant:"accent",className:"ml-1 !text-[9px] !py-0 !px-1.5",children:"git"})]}),e.jsxs("div",{className:"relative",children:[!l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-5 rounded-t-lg",style:{background:"linear-gradient(to bottom, var(--th-panel-alt), rgba(0, 0, 0, 0))"}}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-5 rounded-b-lg",style:{background:"linear-gradient(to top, var(--th-panel-alt), rgba(0, 0, 0, 0))"}})]}),e.jsx("div",{className:"border border-edge rounded-lg overflow-y-auto overscroll-contain scroll-smooth bg-panel-alt",style:{maxHeight:j,minHeight:N,scrollbarGutter:"stable"},children:E?e.jsx("div",{className:`${n} text-fg-5 p-4 text-center flex items-center justify-center gap-2`,children:e.jsx(z,{className:"h-3 w-3 text-fg-5"})}):u?e.jsx("div",{className:`${n} text-red-500/70 p-4`,children:u}):e.jsxs(e.Fragment,{children:[i&&i!==y&&e.jsxs("div",{className:`flex items-center gap-2 px-3 ${f} cursor-pointer hover:bg-panel transition-colors border-b border-edge`,onClick:()=>a(i),children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",className:"text-fg-5 shrink-0",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})}),e.jsx("span",{className:`${n} text-fg-4`,children:".."})]}),g.length===0&&!i&&e.jsx("div",{className:`${n} text-fg-5 p-4 text-center`,children:o("modal.emptyDir")}),g.map(t=>e.jsxs("div",{className:`flex items-center gap-2 px-3 ${f} cursor-pointer hover:bg-panel transition-colors`,onClick:()=>a(t.path),children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:t.name===".git"?"var(--th-primary)":"currentColor",strokeWidth:"1.8",className:"text-fg-5 shrink-0",children:e.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),e.jsx("span",{className:`${n} text-fg-3`,children:t.name})]},t.path))]})})]}),e.jsx("div",{className:"mt-2",children:e.jsx("input",{className:`w-full rounded-lg border border-edge bg-inset px-2.5 py-1.5 ${n} font-mono text-fg outline-none placeholder:text-fg-5 focus:border-edge-h transition-colors`,placeholder:o("modal.manualInput"),value:h,onChange:t=>m(t.target.value),onKeyDown:t=>{t.key==="Enter"&&a(h)}})})]})}export{W as D};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as o,j as e}from"./react-vendor-DTcmqLiz.js";import{u as P,a as I,m as G,T as me,o as ge,c as O,S as E,k as V,B as S}from"./index-xNJkl-jN.js";import{B as te}from"./BrandIcon-C-aE815y.js";import{M as W,a as q,I as B}from"./Modal-BLxBTu-V.js";import{a as se,b as ne,d as ae}from"./shared-BSx12aDa.js";import"./router-emLofBBH.js";function a(t,n,s){return t==="zh-CN"?n:s}function re(t,n){return n.type==="mcp-oauth"?a(t,"OAuth","OAuth"):n.type==="credentials"?a(t,"API Key","API Key"):a(t,"无需配置","No auth")}const fe={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"}},ve={hex:"#6b7280"};function K(t,n){const s=(t||"").toLowerCase(),r=fe[s]||ve,c=r.letter||(n||"").replace(/[^a-zA-Z0-9]/g,"").slice(0,2).toUpperCase()||"?";return{hex:r.hex,letter:c}}function M(t,n){const s=t.replace("#",""),r=s.length===3?s.split("").map(x=>x+x).join(""):s.padEnd(6,"0").slice(0,6),c=parseInt(r.slice(0,2),16),d=parseInt(r.slice(2,4),16),h=parseInt(r.slice(4,6),16);return`rgba(${c}, ${d}, ${h}, ${n})`}function J(t,n,s=[]){const[r,c]=o.useState(()=>{try{const g=localStorage.getItem(t);return g?JSON.parse(g):null}catch{return null}}),[d,h]=o.useState(!1),x=o.useRef(!0);o.useEffect(()=>()=>{x.current=!1},[]);const p=o.useCallback(async()=>{h(!0);try{const g=await n();if(!x.current)return;c(g);try{localStorage.setItem(t,JSON.stringify(g))}catch{}}finally{x.current&&h(!1)}},[t,...s]);return o.useEffect(()=>{p()},[p]),{data:r,loading:d,refresh:p}}const D=()=>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"})]}),ie=({size:t=14})=>e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})}),F=({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"})]}),je=({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"})]}),le=({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"})]}),be=({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","appium","vscode","cursor","windsurf","finder"]),ye={github:"logos:github",atlassian:"logos:atlassian",notion:"logos:notion",linear:"logos:linear",sentry:"logos:sentry",cloudflare:"logos:cloudflare","cloudflare-docs":"logos:cloudflare","cloudflare-bindings":"logos:cloudflare","cloudflare-observability":"logos:cloudflare",slack:"logos:slack",lark:"icon-park:lark",feishu:"icon-park:lark",stripe:"logos:stripe",perplexity:"logos:perplexity",brave:"logos:brave","brave-search":"logos:brave",huggingface:"simple-icons:huggingface",postgres:"logos:postgresql",postgresql:"logos:postgresql",sqlite:"logos:sqlite",vercel:"logos:vercel",netlify:"logos:netlify",supabase:"logos:supabase-icon",heroku:"logos:heroku",docker:"logos:docker",pnpm:"logos:pnpm",aws:"logos:aws","google-cloud":"logos:google-cloud",googlecloud:"logos:google-cloud",amazonwebservices:"logos:aws"};function ke(t,n){if(n)return n;if(!t||oe.has(t))return;const s=ye[t];if(s)return`https://api.iconify.design/${s}.svg`}function H({iconSlug:t,iconUrl:n,name:s,size:r=32,className:c}){const{hex:d,letter:h}=K(t,s),[x,p]=o.useState(!1),g=ke(t,n),v=t&&oe.has(t),i=v||!!g&&!x,m=Math.round(r*.62);return i?e.jsxs("div",{className:O("relative flex shrink-0 items-center justify-center overflow-hidden rounded-xl bg-white",c),style:{width:r,height:r,boxShadow:`0 0 0 1px ${M(d,.18)}, 0 4px 12px ${M(d,.14)}`},children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{background:`linear-gradient(135deg, ${M(d,.06)} 0%, transparent 70%)`}}),v?e.jsx(te,{brand:t,size:m}):e.jsx("img",{src:g,alt:"",width:m,height:m,loading:"lazy",decoding:"async",onError:()=>p(!0),className:"relative"})]}):e.jsxs("div",{className:O("relative flex shrink-0 items-center justify-center overflow-hidden rounded-xl font-semibold text-white",c),style:{width:r,height:r,background:`linear-gradient(135deg, ${M(d,1)} 0%, ${M(d,.82)} 100%)`,boxShadow:`0 1px 0 rgba(255,255,255,0.08) inset, 0 6px 14px ${M(d,.28)}`,fontSize:Math.max(10,Math.round(r*.36)),letterSpacing:h.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:h})]})}function Ne({state:t,locale:n}){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(F,{size:10}),a(n,"已连接","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(je,{size:10}),a(n,"已停用","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(le,{size:10}),a(n,"待授权","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(be,{size:10}),a(n,"异常","Unhealthy")]}):null}function we({open:t,onClose:n,locale:s,item:r,initial:c,onSubmit:d}){const[h,x]=o.useState({}),[p,g]=o.useState(!1);if(o.useEffect(()=>{if(t&&r&&r.auth.type==="credentials"){const i={};for(const m of r.auth.fields)i[m.key]=c?.[m.key]||"";x(i)}},[t,r,c]),!r||r.auth.type!=="credentials")return null;const v=r.auth.fields.some(i=>i.required&&!(h[i.key]||"").trim()),y=async()=>{g(!0);try{await d(h)}finally{g(!1)}};return e.jsxs(W,{open:t,onClose:n,children:[e.jsx(q,{title:a(s,`配置 ${r.name}`,`Configure ${r.name}`),description:s==="zh-CN"?r.descriptionZh:r.description,onClose:n}),e.jsxs("div",{className:"space-y-3",children:[r.auth.fields.map(i=>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:[s==="zh-CN"?i.labelZh:i.label,i.required&&e.jsx("span",{className:"ml-1 text-err",children:"*"})]}),i.helpUrl&&e.jsxs("a",{href:i.helpUrl,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-[11px] text-primary hover:text-primary/80",children:[a(s,"获取","Get one")," ",e.jsx(D,{})]})]}),e.jsx(B,{value:h[i.key]||"",onChange:m=>x({...h,[i.key]:m.target.value}),type:i.secret?"password":"text",placeholder:i.placeholder,className:"font-mono text-[12px]"})]},i.key)),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-edge pt-3",children:[e.jsx(S,{variant:"ghost",onClick:n,children:a(s,"取消","Cancel")}),e.jsx(S,{variant:"primary",disabled:p||v,onClick:y,children:p?e.jsx(E,{}):a(s,"保存并启用","Save & Enable")})]})]})]})}function Ce({open:t,onClose:n,locale:s,scope:r,workdir:c,onAdded:d}){const h=P(b=>b.toast),[x,p]=o.useState(""),[g,v]=o.useState("stdio"),[y,i]=o.useState("npx"),[m,j]=o.useState(""),[f,R]=o.useState(""),[z,u]=o.useState([]),[N,_]=o.useState(!1);o.useEffect(()=>{t&&(p(""),v("stdio"),i("npx"),j(""),R(""),u([]))},[t]);const T=async()=>{if(x.trim()){_(!0);try{const b={};for(const{k:C,v:L}of z)C.trim()&&(b[C.trim()]=L);const k=g==="http"?{type:"http",url:f.trim(),enabled:!0,...Object.keys(b).length?{headers:b}:{}}:{type:"stdio",command:y.trim(),args:m.trim()?m.trim().split(/\s+/):[],enabled:!0,...Object.keys(b).length?{env:b}:{}};await I.addCustomMcp(x.trim(),k,r,c),h(a(s,`${x} 已添加`,`${x} added`),!0),d(),n()}catch(b){h(b?.message||"Failed",!1)}finally{_(!1)}}};return e.jsxs(W,{open:t,onClose:n,wide:!0,children:[e.jsx(q,{title:a(s,"添加自定义 MCP 服务","Add Custom MCP Server"),description:a(s,"不在推荐列表中的自定义服务。","For servers not in the recommended catalog."),onClose:n}),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(s,"名称","Name")}),e.jsx(B,{value:x,onChange:b=>p(b.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(s,"传输","Transport")}),e.jsx("div",{className:"flex gap-1.5",children:["stdio","http"].map(b=>e.jsx("button",{onClick:()=>v(b),className:O("flex-1 rounded-md border px-3 py-1.5 text-[12px] font-medium transition-colors",g===b?"border-primary/40 bg-primary/10 text-primary":"border-edge bg-inset/50 text-fg-4 hover:bg-inset"),children:b},b))})]})]}),g==="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(s,"命令","Command")}),e.jsx(B,{value:y,onChange:b=>i(b.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(s,"参数","Arguments")}),e.jsx(B,{value:m,onChange:b=>j(b.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(B,{value:f,onChange:b=>R(b.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:g==="http"?a(s,"Headers","Headers"):a(s,"环境变量","Env")}),e.jsxs("button",{className:"text-[11px] font-medium text-primary hover:text-primary/80",onClick:()=>u([...z,{k:"",v:""}]),children:["+ ",a(s,"添加","Add")]})]}),z.length>0&&e.jsx("div",{className:"space-y-1 rounded-md border border-edge bg-inset/40 p-2",children:z.map((b,k)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(B,{className:"w-2/5 !h-7 !text-[12px] font-mono",value:b.k,onChange:C=>{const L=[...z];L[k]={...L[k],k:C.target.value},u(L)},placeholder:"KEY"}),e.jsx(B,{className:"flex-1 !h-7 !text-[12px] font-mono",value:b.v,onChange:C=>{const L=[...z];L[k]={...L[k],v:C.target.value},u(L)},type:/token|secret|key|bearer/i.test(b.k)?"password":"text",placeholder:"value"}),e.jsx("button",{className:"shrink-0 rounded p-1 text-fg-5 hover:text-err",onClick:()=>u(z.filter((C,L)=>L!==k)),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"})]})})]},k))})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-edge pt-3",children:[e.jsx(S,{variant:"ghost",onClick:n,children:a(s,"取消","Cancel")}),e.jsx(S,{variant:"primary",disabled:!x.trim()||N,onClick:T,children:N?e.jsx(E,{}):a(s,"添加","Add")})]})]})]})}function Se({open:t,onClose:n,locale:s,scope:r,workdir:c,onInstalled:d}){const h=P(j=>j.toast),[x,p]=o.useState(""),[g,v]=o.useState(""),[y,i]=o.useState(!1);o.useEffect(()=>{t&&(p(""),v(""))},[t]);const m=async()=>{if(x.trim()){i(!0);try{const j=await I.installSkill(x.trim(),r==="global",g.trim()||void 0,c);j.ok?(h(a(s,"技能安装成功","Skill installed"),!0),d(),n()):h(j.error||"Failed",!1)}catch(j){h(j?.message||"Failed",!1)}finally{i(!1)}}};return e.jsxs(W,{open:t,onClose:n,children:[e.jsx(q,{title:a(s,"安装自定义技能","Install Custom Skill"),description:a(s,"通过 npx skills add 从 GitHub 仓库安装。","Installs via npx skills add from a GitHub repo."),onClose:n}),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(s,"GitHub 来源","GitHub Source")}),e.jsx(B,{value:x,onChange:j=>p(j.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(s,"指定技能(可选)","Specific skill (optional)")}),e.jsx(B,{value:g,onChange:j=>v(j.target.value),placeholder:a(s,"留空安装全部","Leave empty for all")})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-edge pt-3",children:[e.jsx(S,{variant:"ghost",onClick:n,children:a(s,"取消","Cancel")}),e.jsx(S,{variant:"primary",disabled:!x.trim()||y,onClick:m,children:y?e.jsx(E,{}):a(s,"安装","Install")})]})]})]})}function Ie(t,n){return new Promise(s=>{const r=window.open(t,"pikiclaw_mcp_oauth","width=640,height=780,noopener=no");if(!r){s(!1);return}let c=!1;const d=p=>{c||(c=!0,window.removeEventListener("message",h),clearInterval(x),s(p))},h=p=>{const g=p.data;if(!(!g||g.type!=="mcp-oauth")&&!(n&&g.state!==n)){d(!!g.ok);try{r.close()}catch{}}};window.addEventListener("message",h);const x=setInterval(()=>{r.closed&&d(!1)},500)})}function Le({item:t,locale:n,busy:s,index:r,onPrimary:c,onRemove:d,onReauth:h,onReconfigure:x}){const{hex:p}=K(t.iconSlug,t.name),g=(()=>{switch(t.state){case"ready":return a(n,"停用","Pause");case"unhealthy":return a(n,"停用","Pause");case"disabled":return a(n,"启用","Enable");case"needs_auth":return t.auth.type==="mcp-oauth"?a(n,"授权","Authorize"):a(n,"配置","Configure");default:return a(n,"启用","Enable")}})(),v={background:`linear-gradient(140deg, ${M(p,.05)} 0%, ${M(p,.01)} 60%, transparent 100%)`,borderColor:M(p,.18),animationDelay:`${Math.min(r,8)*40}ms`};return e.jsxs("div",{className:O("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:v,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:M(p,.35)}}),e.jsxs("div",{className:"relative flex items-start gap-3",children:[e.jsx(H,{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(D,{})})]}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] leading-snug text-fg-4",children:n==="zh-CN"?t.descriptionZh:t.description})]}),e.jsx(Ne,{state:t.state,locale:n})]}),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:p,opacity:.8}}),re(n,t.auth)]}),e.jsxs("div",{className:"flex items-center gap-1",children:[t.installed&&t.state!=="needs_auth"&&h&&e.jsx(S,{variant:"ghost",size:"sm",onClick:h,disabled:s,children:a(n,"重新授权","Re-auth")}),t.installed&&t.state!=="needs_auth"&&x&&e.jsx(S,{variant:"ghost",size:"sm",onClick:x,disabled:s,children:a(n,"编辑","Edit")}),e.jsx(S,{variant:t.state==="disabled"||t.state==="needs_auth"?"primary":"ghost",size:"sm",onClick:c,disabled:s,children:s?e.jsx(E,{}):g}),t.installed&&e.jsx(S,{variant:"ghost",size:"sm",onClick:d,disabled:s,className:"hover:!text-err",children:a(n,"移除","Remove")})]})]})]})}function ze({item:t,locale:n,busy:s,index:r,onPrimary:c}){const d=t.auth.type==="mcp-oauth"?a(n,"授权并启用","Authorize"):t.auth.type==="credentials"?a(n,"配置并启用","Configure"):a(n,"启用","Install");return e.jsxs("div",{className:O("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(r,12)*30}ms`},children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(H,{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(D,{})})]}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] leading-snug text-fg-4",children:n==="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:re(n,t.auth)}),e.jsx(S,{variant:"outline",size:"sm",onClick:c,disabled:s,className:"group-hover:border-edge-h",children:s?e.jsx(E,{}):d})]})]})}function Me({item:t,locale:n,busy:s,index:r,onInstall:c,onRemove:d}){return e.jsxs("div",{className:O("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(r,12)*30}ms`},children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-xl text-white",style:{background:"linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%)",boxShadow:"0 6px 16px rgba(245, 158, 11, 0.25)"},children:e.jsx(ie,{size:14})}),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(D,{})})]}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] leading-snug text-fg-4",children:n==="zh-CN"?t.descriptionZh:t.description})]}),t.installed&&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(F,{size:10}),a(n,"已安装","Installed")]})]}),e.jsxs("div",{className:"mt-auto flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-[11px] text-fg-5",children:t.source}),t.installed?e.jsx(S,{variant:"ghost",size:"sm",onClick:d,disabled:s,className:"hover:!text-err",children:s?e.jsx(E,{}):a(n,"移除","Remove")}):e.jsx(S,{variant:"outline",size:"sm",onClick:c,disabled:s,children:s?e.jsx(E,{}):a(n,"安装","Install")})]})]})}const Y={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 _e(t){const n=new Map;for(const s of t){const r=n.get(s.category)||[];r.push(s),n.set(s.category,r)}return[...n.entries()].sort((s,r)=>(Y[s[0]]?.order??99)-(Y[r[0]]?.order??99)).map(([s,r])=>({key:s,items:r}))}function ce({scope:t,workdir:n,locale:s}){const r=P(l=>l.toast),c=`pikiclaw.mcp.catalog.${t}.${n||""}`,{data:d,loading:h,refresh:x}=J(c,async()=>(await I.getMcpCatalog(n,t)).items||[],[n,t]),[p,g]=o.useState(""),[v,y]=o.useState(null),[i,m]=o.useState(!1),[j,f]=o.useState(null),R=d||[],z=o.useMemo(()=>R.filter(l=>!l.installed||l.scope===t||!l.scope),[R,t]),u=o.useMemo(()=>{if(!p.trim())return z;const l=p.trim().toLowerCase();return z.filter(w=>w.name.toLowerCase().includes(l)||w.description.toLowerCase().includes(l)||w.descriptionZh.includes(l)||w.id.toLowerCase().includes(l))},[z,p]),N=o.useMemo(()=>u.filter(l=>l.installed),[u]),_=o.useMemo(()=>_e(u.filter(l=>!l.installed)),[u]),T=o.useCallback(async(l,w)=>{if(l.isRecommended){f(l.id);try{const $=await I.installMcp(l.id,t,w,n,!0);if(!$.ok)throw new Error($.error||"install failed");return await x(),$.enabled??!1}catch($){return r($?.message||"Failed",!1),!1}finally{f(null)}}},[t,n,x,r]),b=o.useCallback(async l=>{f(l.id);try{if(!l.installed){const X=await I.installMcp(l.id,t,void 0,n,!1);if(!X.ok)throw new Error(X.error||"install failed")}const w=await I.startMcpOAuth(l.id);if(!w.ok||!w.authUrl||!w.state)throw new Error(w.error||"oauth start failed");await Ie(w.authUrl,w.state)?(await I.toggleMcp(l.id,!0,t,n),r(a(s,`${l.name} 授权成功`,`${l.name} authorized`),!0)):r(a(s,"授权未完成","Authorization not completed"),!1),await x()}catch(w){r(w?.message||"OAuth failed",!1)}finally{f(null)}},[t,n,s,r,x]),k=o.useCallback(async(l,w)=>{if(l.installedKey){f(l.id);try{await I.toggleMcp(l.installedKey,w,l.scope==="workspace"?"workspace":"global",n),await x()}catch($){r($?.message||"Failed",!1)}finally{f(null)}}},[n,x,r]),C=o.useCallback(async l=>{if(l.installedKey){f(l.id);try{await I.removeMcp(l.installedKey,l.scope==="workspace"?"workspace":"global",l.isRecommended?l.id:void 0,n),await x()}catch(w){r(w?.message||"Failed",!1)}finally{f(null)}}},[n,x,r]),L=o.useCallback(async l=>{if(!v)return;await T(v,l)!==!1&&y(null)},[v,T]),A=o.useCallback(l=>{if(l.state==="ready"||l.state==="unhealthy"){k(l,!1);return}if(l.state==="disabled"){k(l,!0);return}if(l.state==="needs_auth"){if(l.auth.type==="mcp-oauth"){b(l);return}if(l.auth.type==="credentials"){y(l);return}}},[k,b]),U=o.useCallback(l=>{if(l.auth.type==="mcp-oauth"){b(l);return}if(l.auth.type==="credentials"){y(l);return}T(l)},[b,T]),pe=h&&!d;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(G,{children:"MCP Servers"}),!h&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:[N.length," ",a(s,"已连接","connected")," · ",z.length-N.length," ",a(s,"可添加","available")]}),h&&e.jsx(E,{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:l=>g(l.target.value),placeholder:a(s,"搜索...","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"})]})})]}),pe?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(E,{})}):e.jsxs("div",{className:"space-y-5",children:[N.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(s,"已连接","Connected")]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:N.map((l,w)=>e.jsx(Le,{item:l,locale:s,busy:j===l.id,index:w,onPrimary:()=>A(l),onRemove:()=>{C(l)},onReauth:l.auth.type==="mcp-oauth"?()=>{b(l)}:void 0,onReconfigure:l.auth.type==="credentials"?()=>y(l):void 0},l.id))})]}),_.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"}),N.length===0?a(s,"推荐的服务","Recommended services"):a(s,"更多可选","More options")]}),e.jsx("div",{className:"space-y-4",children:_.map(l=>e.jsx(Ae,{groupKey:l.key,locale:s,children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:l.items.map((w,$)=>e.jsx(ze,{item:w,locale:s,busy:j===w.id,index:$,onPrimary:()=>U(w)},w.id))})},l.key))})]}),N.length===0&&_.length===0&&e.jsx(Q,{title:a(s,"没有匹配的服务","No matching services"),subtitle:a(s,"试试别的关键词","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(s,"添加自定义 MCP","Add custom MCP")]})}),e.jsx(we,{open:!!v,onClose:()=>y(null),locale:s,item:v,initial:v?.config?.env||v?.config?.headers,onSubmit:L}),e.jsx(Ce,{open:i,onClose:()=>m(!1),locale:s,scope:t,workdir:n,onAdded:x})]})}function Ae({groupKey:t,locale:n,children:s}){const r=Y[t],c=r?a(n,r.zh,r.en):t;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-[11px] font-medium text-fg-5",children:c}),s]})}function Q({title:t,subtitle:n}){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}),n&&e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:n})]})}function de({scope:t,workdir:n,locale:s}){const r=P(u=>u.toast),c=`pikiclaw.skills.catalog.${t}.${n||""}`,{data:d,loading:h,refresh:x}=J(c,async()=>{const u=await I.getSkillsCatalog(n,t);return{items:u.items||[],installed:u.installed||[]}},[n,t]),[p,g]=o.useState(!1),[v,y]=o.useState(null),i=d?.items||[],m=o.useMemo(()=>{const u=d?.installed||[],N=t==="global"?"global":"project";return u.filter(_=>_.scope===N)},[d,t]),j=o.useMemo(()=>m.filter(u=>!i.some(N=>N.installedNames.includes(u.name))),[m,i]),f=o.useCallback(async u=>{y(u.id);try{const N=await I.installSkill(u.source,t==="global",void 0,n);N.ok?(r(a(s,`${u.name} 已安装`,`${u.name} installed`),!0),await x()):r(N.error||"Failed",!1)}catch(N){r(N?.message||"Failed",!1)}finally{y(null)}},[t,n,s,r,x]),R=o.useCallback(async u=>{y(u);try{const N=await I.removeExtensionSkill(u,t==="global",n);N.ok?(r(a(s,`${u} 已移除`,`${u} removed`),!0),await x()):r(N.error||"Failed",!1)}catch(N){r(N?.message||"Failed",!1)}finally{y(null)}},[t,n,s,r,x]),z=h&&!d;return e.jsxs("section",{children:[e.jsx("div",{className:"mb-3 flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(G,{children:"Skills"}),!h&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:[m.length," ",a(s,"已安装","installed")]}),h&&e.jsx(E,{className:"h-3 w-3"})]})}),z?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(E,{})}):i.length===0&&j.length===0?e.jsx(Q,{title:a(s,"暂无可用的技能包","No skill packs available"),subtitle:a(s,"从 GitHub 导入一个开始使用","Import from GitHub to get started")}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:i.map((u,N)=>e.jsx(Me,{item:u,locale:s,busy:v===u.id,index:N,onInstall:()=>{f(u)},onRemove:()=>u.installedNames.forEach(_=>{R(_)})},u.id))}),j.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-[11px] font-medium text-fg-5",children:a(s,"自定义技能","Custom skills")}),e.jsx("div",{className:"space-y-1.5",children:j.map(u=>e.jsxs(se,{children:[e.jsx(ne,{icon:e.jsx(ie,{size:14}),title:u.label||u.name,subtitle:u.description||void 0,badge:e.jsx(V,{variant:"ok",children:a(s,"已安装","Installed")})}),e.jsx("div",{className:"min-w-0 xl:col-span-2",children:u.mcpRequires?.length?e.jsxs(V,{variant:"muted",children:["MCP: ",u.mcpRequires.join(", ")]}):null}),e.jsx(ae,{children:e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{R(u.name)},disabled:v===u.name,className:"hover:!text-err",children:a(s,"移除","Remove")})})]},u.name))})]})]}),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:()=>g(!0),children:["+ ",a(s,"从 GitHub 安装自定义技能","Install custom skill from GitHub")]})}),e.jsx(Se,{open:p,onClose:()=>g(!1),locale:s,scope:t,workdir:n,onInstalled:x})]})}const Z={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 xe({state:t,locale:n}){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(F,{size:10}),a(n,"已登录","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(le,{size:10}),a(n,"待登录","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(n,"未安装","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 Ee({chunks:t,running:n,emptyHint:s}){const r=o.useRef(null);o.useEffect(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},[t.length]);const c=t.join("");return e.jsx("div",{ref:r,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:c?e.jsx("pre",{className:"whitespace-pre-wrap break-words",children:c}):e.jsx("div",{className:"flex h-full items-center justify-center text-[#6c7086]",children:n?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(E,{})," ",s||"Starting…"]}):s||"No output yet"})})}function Re({cli:t,locale:n,onSignedIn:s,onCancel:r}){const[c,d]=o.useState([]),[h,x]=o.useState(!1),[p,g]=o.useState(null),[v,y]=o.useState(null),[i,m]=o.useState(null),j=o.useRef(null),f=o.useCallback(()=>{try{j.current?.close()}catch{}j.current=null},[]);o.useEffect(()=>f,[f]);const R=o.useCallback(async()=>{d([]),m(null),y(null),x(!0);try{const k=await I.startCliAuth(t.id);if(!k.ok||!k.sessionId)throw new Error(k.error||"start failed");g(k.sessionId);const C=new EventSource(`/api/extensions/cli/auth/stream?sessionId=${encodeURIComponent(k.sessionId)}`);j.current=C,C.onmessage=L=>{try{const A=JSON.parse(L.data);A.type==="output"?d(U=>U.length>400?[...U.slice(-400),A.chunk]:[...U,A.chunk]):A.type==="status"?y(A.status.state==="ready"?a(n,"已检测到登录成功","Sign-in detected"):a(n,"等待授权完成…","Waiting for authorization…")):A.type==="error"?m(A.message||"error"):A.type==="done"&&(x(!1),f(),A.ok&&s())}catch{}},C.addEventListener("close",()=>{x(!1),f()}),C.onerror=()=>{h&&m(a(n,"连接中断","Stream disconnected"))}}catch(k){x(!1),m(k?.message||"failed to start sign-in")}},[t.id,f,n,s,h]),z=o.useCallback(async()=>{if(p)try{await I.cancelCliAuth(p)}catch{}f(),x(!1),r()},[p,f,r]),[u,N]=o.useState({}),[_,T]=o.useState(!1),b=o.useCallback(async()=>{T(!0),m(null);try{const k=await I.applyCliToken(t.id,u);k.ok?s():m(k.error||a(n,"应用凭据失败","Failed to apply credentials"))}catch(k){m(k?.message||"failed")}finally{T(!1)}},[t.id,u,n,s]);if(t.auth.type==="oauth-web"){const k=n==="zh-CN"&&t.auth.loginHintZh||t.auth.loginHint;return e.jsxs("div",{className:"space-y-3",children:[k&&e.jsx("div",{className:"text-[12px] leading-relaxed text-fg-4",children:k}),e.jsx(Ee,{chunks:c,running:h,emptyHint:a(n,"点击「开始登录」后将在此展示命令行输出",'Click "Start sign-in" to stream CLI output here')}),i&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:i}),v&&!i&&e.jsx("div",{className:"text-[12px] text-[var(--th-ok)]",children:v}),e.jsx("div",{className:"flex items-center gap-2",children:h?e.jsx(S,{variant:"outline",size:"sm",onClick:z,children:a(n,"中止","Abort")}):e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"primary",size:"sm",onClick:R,children:a(n,"开始登录","Start sign-in")}),e.jsx(S,{variant:"ghost",size:"sm",onClick:r,children:a(n,"取消","Cancel")})]})})]})}if(t.auth.type==="token"){const k=n==="zh-CN"&&t.auth.loginHintZh||t.auth.loginHint;return e.jsxs("div",{className:"space-y-3",children:[k&&e.jsx("div",{className:"text-[12px] leading-relaxed text-fg-4",children:k}),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:[n==="zh-CN"?C.labelZh:C.label,C.required&&e.jsx("span",{className:"ml-1 text-[var(--th-err)]",children:"*"})]}),e.jsx(B,{type:C.secret?"password":"text",value:u[C.key]||"",onChange:L=>N(A=>({...A,[C.key]:L.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(n,"如何获取","How to get this")," ↗"]})]},C.key))}),i&&e.jsx("div",{className:"text-[12px] text-[var(--th-err)]",children:i}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"primary",size:"sm",onClick:b,disabled:_,children:_?a(n,"验证中…","Verifying…"):a(n,"保存并验证","Save & verify")}),e.jsx(S,{variant:"ghost",size:"sm",onClick:r,children:a(n,"取消","Cancel")})]})]})}return null}function $e({commands:t,locale:n}){return e.jsx("div",{className:"space-y-2",children:t.map((s,r)=>e.jsxs("div",{className:"overflow-hidden rounded-lg border border-edge/70 bg-panel/60",children:[s.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:s.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:s.cmd}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(s.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(n,"复制到剪贴板","Copy to clipboard"),children:a(n,"复制","Copy")})]})]},r))})}function Be({cli:t,open:n,onClose:s,onChanged:r,locale:c}){const[d,h]=o.useState(!1),[x,p]=o.useState(!1),[g,v]=o.useState(null);o.useEffect(()=>{n||(h(!1),v(null))},[n]);const y=o.useMemo(()=>t?t.install[t.platform]||[]:[],[t]);if(!t)return null;const i=t.state!=="not_installed",m=t.state==="ready",j=async()=>{p(!0),v(null);try{const f=await I.logoutCli(t.id);f.ok||v(f.error||a(c,"登出失败","Logout failed")),r()}catch(f){v(f?.message||"failed")}finally{p(!1)}};return e.jsxs(W,{open:n,onClose:s,wide:!0,children:[e.jsx(q,{title:t.name,description:c==="zh-CN"?t.descriptionZh:t.description,onClose:s}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(H,{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(D,{})})]}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11.5px] text-fg-4",children:[xe({state:t.state,locale:c}),t.version&&e.jsxs("span",{className:"font-mono text-fg-5",children:["v",t.version]}),m&&t.authDetail&&e.jsxs("span",{className:"truncate text-fg-5",children:["· ",t.authDetail]})]})]})]}),!i&&e.jsxs("section",{className:"space-y-2",children:[e.jsx("div",{className:"text-[12px] font-semibold text-fg-3",children:a(c,"安装","Install")}),e.jsx("div",{className:"text-[11.5px] leading-relaxed text-fg-5",children:a(c,"复制下面的命令到终端运行。我们不自动代为安装 — 包管理器往往需要 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($e,{commands:y,locale:c}):e.jsx("div",{className:"text-[12px] text-fg-5",children:a(c,"请查看官方文档","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(c,"查看安装文档","Installation docs")," ↗"]}),e.jsx("div",{className:"pt-2",children:e.jsx(S,{variant:"outline",size:"sm",onClick:r,children:a(c,"我已安装,重新检测","I've installed, re-check")})})]}),i&&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(c,"登录","Sign in")}),m&&!d&&e.jsx(S,{variant:"ghost",size:"sm",onClick:j,disabled:x,children:x?a(c,"登出中…","Signing out…"):a(c,"登出","Sign out")})]}),g&&e.jsx("div",{className:"text-[11.5px] text-[var(--th-err)]",children:g}),m&&!d?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(F,{size:12}),e.jsx("span",{children:a(c,"你已经登录,命令行工具可直接使用。","Already signed in — the CLI is ready to use.")})]}),e.jsx("div",{className:"mt-2",children:e.jsx(S,{variant:"outline",size:"sm",onClick:()=>h(!0),children:a(c,"重新登录","Re-authenticate")})})]}):e.jsx(Re,{cli:t,locale:c,onSignedIn:()=>{h(!1),r()},onCancel:()=>h(!1)})]}),i&&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(F,{size:12}),e.jsx("span",{children:a(c,"无需授权 — 可直接使用。","No authentication required — ready to use.")})]})})]})]})}function Te({item:t,onClick:n,locale:s,animationDelay:r}){const{hex:c}=K(t.iconSlug,t.name);return e.jsxs("button",{type:"button",onClick:n,className:"animate-in-up group relative w-full 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, ${M(c,.06)} 0%, ${M(c,.02)} 100%), var(--th-panel)`,animationDelay:r},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, ${M(c,.18)}, transparent 70%)`}}),e.jsxs("div",{className:"relative flex items-start gap-3",children:[e.jsx(H,{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}),xe({state:t.state,locale:s})]}),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:s==="zh-CN"?t.descriptionZh:t.description})]})]})]})}function Pe({item:t,onClick:n,locale:s,animationDelay:r}){const{hex:c}=K(t.iconSlug,t.name),d=t.state==="not_installed"?a(s,"安装","Install"):t.state==="installed_not_auth"?a(s,"登录","Sign in"):a(s,"查看","Details");return e.jsxs("button",{type:"button",onClick:n,className:"animate-in-up group relative w-full 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:r},children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(H,{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:h=>h.stopPropagation(),className:"text-fg-5 transition-colors hover:text-primary",children:e.jsx(D,{})})]}),e.jsx("div",{className:"mt-0.5 truncate text-[11.5px] text-fg-4",children:s==="zh-CN"?t.descriptionZh:t.description})]})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] text-fg-5",children:t.auth.type==="oauth-web"?a(s,"浏览器授权","OAuth"):t.auth.type==="token"?a(s,"Token","Token"):a(s,"免配置","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:`${M(c,.08)}`,color:c},children:d})]})]})}function he({locale:t,scope:n}){const{data:s,loading:r,refresh:c}=J("pikiclaw:cli:catalog",async()=>{const i=await I.getCliCatalog();if(!i.ok)throw new Error(i.error||"failed");return i.items||[]},[]),[d,h]=o.useState(null),x=o.useMemo(()=>{const i=s||[];return i},[s,n]),p=d&&x.find(i=>i.id===d)||null,g=x.filter(i=>i.state==="ready"),v=x.filter(i=>i.state!=="ready"),y=o.useMemo(()=>{const i=new Map;for(const m of v){const j=m.category;i.has(j)||i.set(j,[]),i.get(j).push(m)}return[...i.entries()].sort(([m],[j])=>(Z[m]?.order??99)-(Z[j]?.order??99))},[v]);return e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(G,{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:[g.length," ",a(t,"已登录","signed in")," · ",v.length," ",a(t,"可用","available")]}),e.jsx("button",{type:"button",onClick:()=>{c()},className:"rounded px-2 py-0.5 text-fg-5 transition-colors hover:bg-panel-h hover:text-fg-2",children:r?a(t,"刷新中…","Refreshing…"):a(t,"刷新","Refresh")})]})]}),n==="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.")}),g.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",children:g.map((i,m)=>e.jsx(Te,{item:i,locale:t,animationDelay:`${Math.min(m,12)*30}ms`,onClick:()=>h(i.id)},i.id))})]}),v.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(([i,m])=>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"?Z[i]?.zh||i:Z[i]?.en||i}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:m.map((j,f)=>e.jsx(Pe,{item:j,locale:t,animationDelay:`${Math.min(f,12)*30}ms`,onClick:()=>h(j.id)},j.id))})]},i))]}),!r&&x.length===0&&e.jsx(Q,{title:a(t,"暂无可用 CLI","No CLI tools available"),subtitle:a(t,"稍后再试,或重启一下服务。","Try again later, or restart the service.")}),e.jsx(Be,{cli:p,open:!!p,onClose:()=>h(null),onChanged:()=>{c()},locale:t})]})}function ee({brand:t,title:n,badge:s,onClick:r,buttonLabel:c}){return e.jsxs(se,{children:[e.jsx(ne,{icon:e.jsx(te,{brand:t,size:14}),title:n,badge:e.jsx(V,{variant:s.variant,children:s.label})}),e.jsx("div",{className:"min-w-0 xl:col-span-2"}),e.jsx(ae,{children:e.jsx(S,{variant:"outline",size:"sm",onClick:r,children:c})})]})}function ue({active:t,onChange:n,locale:s,counts:r}){const c=[{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(me,{className:"w-fit bg-panel/80 backdrop-blur",children:c.map(d=>e.jsxs(ge,{active:t===d.id,onClick:()=>n(d.id),className:"gap-1.5 px-3.5",children:[e.jsx("span",{className:"shrink-0",children:d.icon}),e.jsx("span",{children:s==="zh-CN"?d.labelZh:d.labelEn}),r?.[d.id]!==void 0&&e.jsx("span",{className:O("ml-1 inline-flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[10px] font-semibold",t===d.id?"bg-primary/12 text-primary":"bg-inset/70 text-fg-5"),children:r[d.id]})]},d.id))})}function Ge({onOpenBrowserSetup:t,onOpenDesktopSetup:n}){const s=P(f=>f.locale),r=P(f=>f.state),c=r?.config?.workdir||"",[d,h]=o.useState(()=>{try{const f=localStorage.getItem("pikiclaw:extensions:tab");return f==="mcp"||f==="cli"||f==="skill"?f:"mcp"}catch{return"mcp"}}),x=o.useCallback(f=>{h(f);try{localStorage.setItem("pikiclaw:extensions:tab",f)}catch{}},[]),[p,g]=o.useState(null),v=o.useCallback(async()=>{try{g(await I.getBrowser())}catch{}},[]);o.useEffect(()=>{v()},[v,r]);const y=p?.browser,i=p?.desktop,m=y?y.enabled?y.running?{label:a(s,"运行中","Running"),variant:"ok"}:y.status==="ready"?{label:a(s,"就绪","Ready"),variant:"ok"}:{label:a(s,"需配置","Needs setup"),variant:"warn"}:{label:a(s,"已关闭","Disabled"),variant:"muted"}:{label:"...",variant:"muted"},j=i?i.installed?i.running?{label:a(s,"运行中","Running"),variant:"ok"}:{label:a(s,"已安装","Installed"),variant:"accent"}:{label:a(s,"未安装","Not installed"),variant:"muted"}:{label:"...",variant:"muted"};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(ue,{active:d,onChange:x,locale:s})]}),e.jsxs("div",{className:"animate-in-fade",children:[d==="mcp"&&e.jsxs("div",{className:"space-y-7",children:[e.jsx(ce,{scope:"global",workdir:c,locale:s}),e.jsxs("section",{children:[e.jsx("div",{className:"mb-3",children:e.jsx(G,{children:a(s,"内置自动化","Built-in Automation")})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ee,{brand:"playwright",title:a(s,"浏览器自动化","Browser Automation"),badge:m,onClick:t,buttonLabel:y?.enabled?a(s,"管理","Manage"):a(s,"配置","Setup")}),e.jsx(ee,{brand:"appium",title:a(s,"桌面自动化","Desktop Automation"),badge:j,onClick:n,buttonLabel:i?.running?a(s,"管理","Manage"):a(s,"配置","Setup")})]})]})]}),d==="cli"&&e.jsx(he,{locale:s,scope:"global"}),d==="skill"&&e.jsx(de,{scope:"global",workdir:c,locale:s})]},d)]})}function We({workdir:t}){const n=P(d=>d.locale),[s,r]=o.useState(()=>{try{const d=localStorage.getItem("pikiclaw:extensions-ws:tab");return d==="mcp"||d==="cli"||d==="skill"?d:"mcp"}catch{return"mcp"}}),c=o.useCallback(d=>{r(d);try{localStorage.setItem("pikiclaw:extensions-ws:tab",d)}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(n,"仅对当前工作区生效 — 依赖项目目录的本地服务和专属技能包。","Scoped to this workspace — local services that depend on project context and project-specific skill packs.")}),e.jsx(ue,{active:s,onChange:c,locale:n})]}),e.jsxs("div",{className:"animate-in-fade",children:[s==="mcp"&&e.jsx(ce,{scope:"workspace",workdir:t,locale:n}),s==="cli"&&e.jsx(he,{locale:n,scope:"workspace"}),s==="skill"&&e.jsx(de,{scope:"workspace",workdir:t,locale:n})]},s)]})}export{Ge as ExtensionsTab,We as WorkspaceExtensionsBody};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as S,j as i}from"./react-vendor-DTcmqLiz.js";import{u as p,
|
|
1
|
+
import{r as S,j as i}from"./react-vendor-DTcmqLiz.js";import{u as p,l as y,k as v,S as C,B as D}from"./index-xNJkl-jN.js";import{B as A}from"./BrandIcon-C-aE815y.js";import{a as j,b as V,c as w,d as N}from"./shared-BSx12aDa.js";import"./router-emLofBBH.js";function L(t){return t==="zh-CN"?{status:"状态",summary:"接入摘要",loading:"加载中",chats:"个 chat",notConnected:"未接入",configuring:"配置中",connected:"已接入",failed:"配置异常",configure:"去配置",continueSetup:"继续配置",viewSettings:"查看设置",noWeixin:"尚未登录微信账号",noTelegram:"未配置 Bot Token",noFeishu:"未配置 App ID 与应用凭证",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",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 g(t,e=4,a=4){const s=t.trim();return s?s.length<=e+a+3?s:`${s.slice(0,e)}...${s.slice(-a)}`:""}function B(t){return String(t||"").split(/[\n,;]/).map(e=>e.trim()).filter(Boolean).length}function u(t,e){return String(t?.[e]||"").trim()}function R(t,e){if(!t)return e;try{return new URL(t).host||t}catch{return t}}function h(t,e,a){if(t==="weixin"){const n=u(e,"weixinAccountId"),l=u(e,"weixinBaseUrl");return n?l?`${g(n)} · ${R(l,l)}`:`${a.accountLinked} ${g(n)}`:a.noWeixin}if(t==="telegram"){const n=u(e,"telegramBotToken"),l=B(u(e,"telegramAllowedChatIds"));return n?l>0?`${a.tokenSaved} · ${a.allowedChats} ${l} ${a.chats}`:a.tokenSaved:a.noTelegram}const s=u(e,"feishuAppId"),o=u(e,"feishuAppSecret");return!s||!o?a.noFeishu:`App ID ${g(s)} · ${a.appCredentialsSaved}`}function f(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}:y(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 $({meta:t,locale:e}){const a=L(e);return i.jsxs(j,{children:[i.jsx(V,{icon:i.jsx(A,{brand:t.key,size:22}),title:t.title,subtitle:t.subtitle}),i.jsxs(w,{label:a.status,children:[i.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:i.jsxs(v,{variant:t.statusVariant,children:[t.loading&&i.jsx(C,{className:"h-3 w-3"}),t.statusLabel]})}),i.jsx("div",{className:"mt-1 text-[13px] leading-relaxed text-fg-3 xl:truncate xl:whitespace-nowrap",title:t.statusDescription,children:t.statusDescription})]}),i.jsx(w,{label:t.summaryLabel,children:i.jsx("div",{className:"break-words text-[13px] leading-relaxed text-fg-3",children:t.summary})}),i.jsx(N,{children:i.jsxs(D,{variant:t.channel?.ready?"outline":"primary",size:"sm",onClick:t.onAction,disabled:t.actionDisabled,children:[t.loading&&i.jsx(C,{className:"h-3 w-3"}),t.actionLabel]})})]})}function M({onOpenWeixin:t,onOpenTelegram:e,onOpenFeishu:a}){const s=p(r=>r.state),o=p(r=>r.locale),n=L(o),l=!s,d=s?.setupState?.channels||[],m=s?.config||{},k=S.useMemo(()=>{const r=d.find(c=>c.channel==="weixin")||null,b=d.find(c=>c.channel==="telegram")||null,x=d.find(c=>c.channel==="feishu")||null;return l?[{key:"weixin",title:"Weixin",subtitle:o==="zh-CN"?"二维码登录与账号接入":"QR login and account routing",channel:null,loading:!0,summary:n.loading,summaryLabel:n.summary,statusLabel:n.loading,statusVariant:"muted",statusDescription:n.loading,actionLabel:n.loading,actionDisabled:!0,onAction:t},{key:"telegram",title:"Telegram",subtitle:o==="zh-CN"?"Bot Token 与 chat allowlist":"Bot token and chat allowlist",channel:null,loading:!0,summary:n.loading,summaryLabel:n.summary,statusLabel:n.loading,statusVariant:"muted",statusDescription:n.loading,actionLabel:n.loading,actionDisabled:!0,onAction:e},{key:"feishu",title:"Feishu",subtitle:o==="zh-CN"?"应用凭证与机器人身份":"App credentials and bot identity",channel:null,loading:!0,summary:n.loading,summaryLabel:n.summary,statusLabel:n.loading,statusVariant:"muted",statusDescription:n.loading,actionLabel:n.loading,actionDisabled:!0,onAction:a}]:[{key:"weixin",title:"Weixin",subtitle:o==="zh-CN"?"二维码登录与账号接入":"QR login and account routing",channel:r,summary:h("weixin",m,n),summaryLabel:n.summary,...f(r,n),actionDisabled:!1,onAction:t},{key:"telegram",title:"Telegram",subtitle:o==="zh-CN"?"Bot Token 与 chat allowlist":"Bot token and chat allowlist",channel:b,summary:h("telegram",m,n),summaryLabel:n.summary,...f(b,n),actionDisabled:!1,onAction:e},{key:"feishu",title:"Feishu",subtitle:o==="zh-CN"?"应用凭证与机器人身份":"App credentials and bot identity",channel:x,summary:h("feishu",m,n),summaryLabel:n.summary,...f(x,n),actionDisabled:!1,onAction:a}]},[d,m,n,l,o,a,e,t]);return i.jsx("div",{className:"animate-in space-y-3",children:k.map(r=>i.jsx($,{meta:r,locale:o},r.key))})}export{M as IMAccessTab};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,r as d,b as c}from"./react-vendor-DTcmqLiz.js";import{c as n,B as x}from"./index-xNJkl-jN.js";function h({className:r,...t}){return e.jsx("input",{className:n("flex h-8 w-full rounded-md border border-edge bg-inset px-2.5 py-1.5 text-[13px] text-fg shadow-sm","transition-[border-color,box-shadow,background] duration-200 outline-none","placeholder:text-fg-5","focus:border-edge-h focus:shadow-[0_0_0_4px_var(--th-glow-a)]",r),...t})}function b({children:r,className:t}){return e.jsx("label",{className:n("mb-2 block text-sm font-medium text-fg-3",t),children:r})}function f({open:r,onClose:t,wide:a,panelStyle:o,children:i}){return d.useEffect(()=>{if(!r)return;const s=l=>{l.key==="Escape"&&t()};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[r,t]),!r||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:t}),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:n("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:{...o,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:i})})]}),document.body)}function g({title:r,description:t,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:r}),t&&e.jsx("div",{className:"mt-1 text-sm leading-relaxed text-fg-4",children:t})]}),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{h as I,b 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 y,e as L,B,a as I,d as P}from"./index-BFtrf-rI.js";import{M as W,a as q,L as U,I as G}from"./Modal-CQ3_xUJW.js";import{D as V}from"./DirBrowser-rl1DwWxj.js";import"./router-emLofBBH.js";const O="https://ilinkai.weixin.qq.com";function Q(c){return c instanceof Error&&(c.name==="AbortError"||/aborted/i.test(c.message))}function H(c,h){return c instanceof Error&&/timed out/i.test(c.message)?h("modal.requestTimeout"):h("modal.networkError")}function se({open:c,onClose:h}){const N=y(x=>x.state),d=y(x=>x.toast),D=y(x=>x.reloadUntil),s=y(x=>x.locale),t=a.useMemo(()=>L(s),[s]),[u,v]=a.useState(""),[g,p]=a.useState(""),[w,S]=a.useState(!1),[b,o]=a.useState(!1),[k,l]=a.useState(null),[n,T]=a.useState(!1),j=a.useRef(null),F=a.useRef(N);F.current=N,a.useEffect(()=>{c?(v(F.current?.config.telegramBotToken||""),p(F.current?.config.telegramAllowedChatIds||""),S(!1),l(null),T(!F.current?.config.telegramBotToken)):(j.current?.abort(),j.current=null,o(!1))},[c]),a.useEffect(()=>()=>{j.current?.abort(),j.current=null},[]);const i=async()=>{if(!u.trim()){d(t("modal.inputToken"),!1);return}j.current?.abort();const x=new AbortController;j.current=x,o(!0),l(null);let r=!1;try{const f=await I.validateTelegramConfig(u.trim(),g.trim(),{signal:x.signal,timeoutMs:12e3});if(!f.ok){l({ok:!1,text:"✗ "+(f.error||t("modal.validationFailed"))});return}const C=f.normalizedAllowedChatIds??g.trim();l({ok:!0,text:"✓ @"+(f.bot?.username||"bot")+(f.bot?.displayName?" ("+f.bot.displayName+")":"")});const A=new Set((N?.setupState?.channels||[]).filter(E=>(E.ready||E.configured)&&E.channel!=="telegram").map(E=>E.channel));if(A.add("telegram"),await I.saveConfig({telegramBotToken:u.trim(),telegramAllowedChatIds:C,channels:[...A]}),!await D(E=>{const z=E.setupState?.channels?.find(K=>K.channel==="telegram");return E.config.telegramBotToken===u.trim()&&(E.config.telegramAllowedChatIds||"")===C&&!!z?.ready},{attempts:10,intervalMs:350})){l({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),d(t("modal.refreshStateFailed"),!1);return}d(t("modal.tgSaved")),r=!0}catch(f){if(Q(f))return;const C=H(f,t);l({ok:!1,text:"✗ "+C}),d(C,!1)}finally{j.current===x&&(j.current=null),o(!1),r&&h()}},m=()=>{j.current?.abort(),j.current=null,h()};return e.jsxs(W,{open:c,onClose:m,children:[e.jsx(q,{title:t("modal.configureTelegram"),onClose:m}),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:()=>T(!n),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 ${n?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),n&&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(U,{children:t("modal.botToken")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{type:w?"text":"password",className:"flex-1 font-mono text-xs",placeholder:t("modal.pasteToken"),value:u,onChange:x=>v(x.target.value)}),e.jsx(B,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>S(!w),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"})]})})]})]}),k&&e.jsx("div",{className:"text-xs",style:{color:k.ok?"var(--th-ok)":"var(--th-err)"},children:k.text}),e.jsxs("div",{children:[e.jsxs(U,{children:[t("modal.allowedIds")," ",e.jsxs("span",{className:"text-fg-5",children:["(",t("modal.optional"),")"]})]}),e.jsx(G,{className:"font-mono text-xs",placeholder:t("modal.commaSep"),value:g,onChange:x=>p(x.target.value)})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(B,{variant:"ghost",onClick:m,children:t("modal.cancel")}),e.jsx(B,{variant:"primary",disabled:b,onClick:i,children:t(b?"modal.validating":"modal.validateSave")})]})]})}function ae({open:c,onClose:h}){const N=y(i=>i.state),d=y(i=>i.toast),D=y(i=>i.reloadUntil),s=y(i=>i.locale),t=a.useMemo(()=>L(s),[s]),[u,v]=a.useState(""),[g,p]=a.useState(""),[w,S]=a.useState(!1),[b,o]=a.useState(null),[k,l]=a.useState(!1),n=a.useRef(null),T=a.useRef(N);T.current=N,a.useEffect(()=>{c?(v(T.current?.config.feishuAppId||""),p(T.current?.config.feishuAppSecret||""),o(null),l(!T.current?.config.feishuAppId)):(n.current?.abort(),n.current=null,S(!1))},[c]),a.useEffect(()=>()=>{n.current?.abort(),n.current=null},[]);const j=async()=>{if(!u.trim()){d(t("modal.inputAppId"),!1);return}n.current?.abort();const i=new AbortController;n.current=i,S(!0),o(null);let m=!1;try{const x=await I.validateFeishuConfig(u.trim(),g.trim(),{signal:i.signal,timeoutMs:2e4});if(!x.ok){o({ok:!1,text:"✗ "+(x.error||t("modal.validationFailed"))});return}o({ok:!0,text:"✓ "+(x.app?.displayName||x.app?.appId||u.trim())});const r=new Set((N?.setupState?.channels||[]).filter(C=>(C.ready||C.configured)&&C.channel!=="feishu").map(C=>C.channel));if(r.add("feishu"),await I.saveConfig({feishuAppId:u.trim(),feishuAppSecret:g.trim(),channels:[...r]}),!await D(C=>{const A=C.setupState?.channels?.find(R=>R.channel==="feishu");return C.config.feishuAppId===u.trim()&&C.config.feishuAppSecret===g.trim()&&!!A?.ready},{attempts:10,intervalMs:350})){o({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),d(t("modal.refreshStateFailed"),!1);return}d(t("modal.feishuSaved")),m=!0}catch(x){if(Q(x))return;const r=H(x,t);o({ok:!1,text:"✗ "+r}),d(r,!1)}finally{n.current===i&&(n.current=null),S(!1),m&&h()}},F=()=>{n.current?.abort(),n.current=null,h()};return e.jsxs(W,{open:c,onClose:F,children:[e.jsx(q,{title:t("modal.configureFeishu"),onClose:F}),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:()=>l(!k),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 ${k?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),k&&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(U,{children:t("modal.appId")}),e.jsx(G,{className:"font-mono text-xs",placeholder:t("modal.feishuPlaceholder"),value:u,onChange:i=>v(i.target.value)})]}),e.jsxs("div",{children:[e.jsx(U,{children:t("modal.appSecret")}),e.jsx(G,{type:"password",className:"font-mono text-xs",placeholder:t("modal.appSecret"),value:g,onChange:i=>p(i.target.value)})]}),b&&e.jsx("div",{className:"text-xs",style:{color:b.ok?"var(--th-ok)":"var(--th-err)"},children:b.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(B,{variant:"ghost",onClick:F,children:t("modal.cancel")}),e.jsx(B,{variant:"primary",disabled:w,onClick:j,children:t(w?"modal.validating":"modal.validateSave")})]})]})}function le({open:c,onClose:h}){const N=y(m=>m.state),d=y(m=>m.toast),D=y(m=>m.reloadUntil),s=y(m=>m.locale),t=a.useMemo(()=>L(s),[s]),[u,v]=a.useState(O),[g,p]=a.useState(!1),[w,S]=a.useState(""),[b,o]=a.useState(""),[k,l]=a.useState(null),n=a.useRef(null),T=a.useRef(N);T.current=N,a.useEffect(()=>{c?(v(T.current?.config.weixinBaseUrl||O),p(!1),S(""),o(""),l(null)):(n.current?.abort(),n.current=null,p(!1))},[c]),a.useEffect(()=>()=>{n.current?.abort(),n.current=null},[]);const j=()=>{n.current?.abort(),n.current=null,h()},F=a.useCallback(async(m,x,r)=>{for(;!m.signal.aborted;){const f=await I.waitWeixinLogin(x,r,{signal:m.signal,timeoutMs:45e3});if(!f.ok&&!f.connected)return l({ok:!1,text:"✗ "+(f.error||f.message||t("modal.validationFailed"))}),!1;if(f.qrcodeUrl&&S(f.qrcodeUrl),f.status==="scaned"?l({ok:!0,text:t("modal.weixinScanned")}):f.status==="expired"?l({ok:!0,text:t("modal.weixinQrRefreshed")}):f.connected||l({ok:!0,text:t("modal.weixinWaitingScan")}),!f.connected)continue;l({ok:!0,text:t("modal.weixinLoginSuccess")});const C=f.baseUrl||r,A=f.botToken||"",R=f.accountId||"",E=await I.validateWeixinConfig(C,A,R,{signal:m.signal,timeoutMs:12e3});if(!E.ok)return l({ok:!1,text:"✗ "+(E.error||t("modal.validationFailed"))}),!1;const z=E.normalizedBaseUrl||C,K=new Set((T.current?.setupState?.channels||[]).filter(M=>(M.ready||M.configured)&&M.channel!=="weixin").map(M=>M.channel));return K.add("weixin"),await I.saveConfig({weixinBaseUrl:z,weixinBotToken:A,weixinAccountId:R,channels:[...K]}),await D(M=>{const _=M.setupState?.channels?.find($=>$.channel==="weixin");return M.config.weixinBaseUrl===z&&M.config.weixinBotToken===A&&M.config.weixinAccountId===R&&!!_?.ready},{attempts:12,intervalMs:350})?(d(t("modal.weixinSaved")),!0):(l({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),d(t("modal.refreshStateFailed"),!1),!1)}return!1},[D,t,d]),i=async()=>{if(!u.trim()){d(t("modal.inputWeixinBaseUrl"),!1);return}n.current?.abort();const m=new AbortController;n.current=m,p(!0),S(""),o(""),l(null);let x=!1;try{const r=await I.startWeixinLogin(u.trim(),{signal:m.signal,timeoutMs:12e3});if(!r.ok||!r.qrcodeUrl){l({ok:!1,text:"✗ "+(r.error||r.message||t("modal.validationFailed"))});return}S(r.qrcodeUrl),o(r.sessionKey),l({ok:!0,text:t("modal.weixinWaitingScan")}),x=await F(m,r.sessionKey,u.trim())}catch(r){if(Q(r))return;const f=H(r,t);l({ok:!1,text:"✗ "+f}),d(f,!1)}finally{n.current===m&&(n.current=null),p(!1),x&&h()}};return e.jsxs(W,{open:c,onClose:j,children:[e.jsx(q,{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(U,{children:t("modal.weixinBaseUrl")}),e.jsx(G,{className:"font-mono text-xs",value:u,onChange:m=>v(m.target.value),placeholder:O}),e.jsx("div",{className:"mt-1 text-[11px] text-fg-5",children:t("modal.weixinDefaultBaseUrlHint")})]}),w&&e.jsxs("div",{className:"rounded-xl border border-edge bg-panel-alt p-4",children:[e.jsx("img",{src:w,alt:t("modal.weixinQrAlt"),className:"mx-auto h-56 w-56 rounded-lg bg-white p-3 object-contain"}),b&&e.jsx("div",{className:"mt-2 truncate text-center font-mono text-[10px] text-fg-5",children:b})]}),k&&e.jsx("div",{className:"text-xs",style:{color:k.ok?"var(--th-ok)":"var(--th-err)"},children:k.text})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(B,{variant:"ghost",onClick:j,children:t("modal.cancel")}),e.jsx(B,{variant:"primary",disabled:g,onClick:i,children:t(g?w?"modal.validating":"modal.weixinGeneratingQr":w?"modal.weixinRetry":"modal.weixinGenerateQr")})]})]})}function ne({open:c,onClose:h}){const N=y(l=>l.state),d=y(l=>l.toast),D=y(l=>l.reload),s=y(l=>l.locale),t=a.useMemo(()=>L(s),[s]),u=N?.bot?.workdir||N?.runtimeWorkdir||"",[v,g]=a.useState(""),[p,w]=a.useState(!1),[S,b]=a.useState(0);a.useEffect(()=>{c&&(g(u),b(l=>l+1))},[c,u]);const o=a.useCallback(l=>{g(l)},[]),k=async()=>{const l=v.trim();if(!l){d(t("modal.selectDirFirst"),!1);return}w(!0);try{const n=await I.switchWorkdir(l);n.ok?(await D(),d(t("modal.switchedTo")+n.workdir),h()):d(n.error||t("modal.switchFailed"),!1)}catch{d(t("modal.switchFailed"),!1)}finally{w(!1)}};return e.jsx(W,{open:c,onClose:p?void 0:h,panelStyle:{width:"min(500px, calc(100vw - 2rem))",maxWidth:"min(500px, calc(100vw - 2rem))"},children:p?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:v})]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{title:t("modal.switchWorkdir"),onClose:h}),e.jsx(V,{initialPath:u,onSelect:o,t},S),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(B,{variant:"ghost",onClick:h,children:t("modal.cancel")}),e.jsx(B,{variant:"primary",onClick:k,children:t("modal.selectDir")})]})]})})}function re({open:c,onClose:h,onSaved:N}){const d=y(r=>r.toast),D=y(r=>r.locale),s=a.useMemo(()=>L(D),[D]),[t,u]=a.useState(null),[v,g]=a.useState(!1),[p,w]=a.useState(!1),[S,b]=a.useState(null);a.useEffect(()=>{c&&(g(!1),b(null),I.getBrowser().then(r=>{u(r),w(!!r.browser.enabled)}).catch(()=>u(null)))},[c]);const o=t?.browser,k=!!o?.enabled,l=!!o&&k!==p,n=o?.profileDir||"",T=s("ext.profileDir"),j=n,F=!!o?.chromeInstalled&&!!o?.profileCreated,i=t?o?.enabled?F?s("ext.browserReady"):o?.chromeInstalled?s("ext.chromeInstalled"):s("ext.needsSetup"):s("ext.disabled"):s("status.loading"),m=t&&o?.enabled?F?"ok":o?.chromeInstalled?"warn":"err":"muted",x=async()=>{g(!0),b(null);try{await I.saveConfig({browserEnabled:p});const r=await I.getBrowser();u(r),N?.()}catch{b({ok:!1,text:"✗ "+s("ext.browserModeSaveFailed")}),d(s("ext.browserModeSaveFailed"),!1),g(!1);return}if(!p){b({ok:!0,text:"✓ "+s("ext.browserDisabledSaved")}),d(s("ext.browserDisabledSaved")),g(!1);return}try{const r=await I.setupBrowser();if(!r.ok){b({ok:!1,text:"✗ "+(r.error||s("ext.browserLaunchFailed"))}),d(r.error||s("ext.browserLaunchFailed"),!1);return}u(f=>f?{...f,browser:r.browser}:{browser:r.browser,desktop:{enabled:!1,installed:!1,running:!1,appiumUrl:""}}),b({ok:!0,text:"✓ "+s("ext.browserEnabledLaunched")}),d(s("ext.browserEnabledLaunched")),N?.()}catch{b({ok:!1,text:"✗ "+s("ext.browserLaunchFailed")}),d(s("ext.browserLaunchFailed"),!1)}finally{g(!1)}};return e.jsxs(W,{open:c,onClose:h,children:[e.jsx(q,{title:s("ext.setupBrowser"),description:s("ext.setupBrowserDesc"),onClose:h}),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(P,{variant:m,children:i}),o&&e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:k?"accent":"muted",children:s(k?"ext.enabled":"ext.disabled")}),l&&e.jsx(P,{variant:"warn",children:s("ext.pendingModeChange")}),o.running&&e.jsxs(P,{variant:"accent",children:[s("ext.browserOpen"),o.pid?` · PID ${o.pid}`:""]})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(U,{children:T}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{className:"font-mono text-xs flex-1",value:j||"—",readOnly:!0,onClick:r=>r.target.select()}),e.jsx(B,{variant:"outline",size:"sm",disabled:!j,onClick:()=>{j&&(navigator.clipboard.writeText(j),d(s("ext.step2Copied")))},children:s("ext.copyPath")})]})]}),e.jsx("div",{className:"mt-3 text-xs text-fg-5",children:s(p?"ext.profileModeDesc":"ext.browserDescDisabled")}),o?.detail&&e.jsx("div",{className:"mt-2 text-xs text-fg-5",children:o.detail}),S&&e.jsx("div",{className:"mt-3 text-xs",style:{color:S.ok?"var(--th-ok)":"var(--th-err)"},children:S.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:p,onChange:r=>w(r.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(p?"ext.step2Title":"ext.browserDisabledStepTitle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s(p?"ext.step2Desc":"ext.browserDisabledHint")})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(B,{variant:"ghost",onClick:h,children:s("modal.cancel")}),e.jsx(B,{variant:"primary",disabled:v,onClick:x,children:s(v?"ext.launching":p?"ext.enableAndLaunchBrowser":"ext.saveBrowserDisabled")})]})]})}function ie({open:c,onClose:h,onSaved:N}){const d=y(i=>i.toast),D=y(i=>i.locale),s=a.useMemo(()=>L(D),[D]),[t,u]=a.useState(!1),[v,g]=a.useState(!1),[p,w]=a.useState(!1),[S,b]=a.useState(!1),[o,k]=a.useState(!1),[l,n]=a.useState(null);a.useEffect(()=>{c&&(u(!1),b(!1),k(!1),n(null),I.getBrowser().then(i=>{g(i.desktop.installed),w(i.desktop.enabled)}).catch(()=>{}))},[c]);const T=async()=>{u(!0),n(null);try{const i=await I.desktopInstall();i.ok?(g(!0),n({ok:!0,text:"✓ "+s("ext.desktopInstalled")}),d(s("ext.desktopInstalled"))):n({ok:!1,text:"✗ "+(i.error||s("ext.desktopInstallFailed"))})}catch{n({ok:!1,text:"✗ "+s("ext.desktopInstallFailed")})}finally{u(!1)}},j=async()=>{b(!0),n(null);try{const i=await I.desktopToggle(!0);i.ok?(w(!0),n({ok:!0,text:"✓ "+s("ext.desktopStarted")}),d(s("ext.desktopStarted")),N?.()):n({ok:!1,text:"✗ "+(i.error||s("ext.desktopInstallFailed"))})}catch{n({ok:!1,text:"✗ "+s("ext.desktopInstallFailed")})}finally{b(!1)}},F=async()=>{k(!0),n(null);try{const i=await I.desktopToggle(!1);i.ok?(w(!1),n({ok:!0,text:"✓ "+s("ext.desktopStopped")}),d(s("ext.desktopStopped")),N?.()):n({ok:!1,text:"✗ "+(i.error||s("ext.desktopInstallFailed"))})}catch{n({ok:!1,text:"✗ "+s("ext.desktopInstallFailed")})}finally{k(!1)}};return e.jsxs(W,{open:c,onClose:h,children:[e.jsx(q,{title:s("ext.setupDesktop"),description:s("ext.setupDesktopDesc"),onClose:h}),e.jsxs("div",{className:"space-y-5",children:[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("ext.desktopStep1Title")}),e.jsx("div",{className:"text-xs text-fg-4 mb-3",children:s("ext.desktopStep1Desc")}),l&&!v&&e.jsx("div",{className:"mb-2 text-xs",style:{color:l.ok?"var(--th-ok)":"var(--th-err)"},children:l.text}),e.jsx(B,{variant:v?"ghost":"outline",size:"sm",disabled:t||v,onClick:T,children:s(t?"ext.desktopInstalling":v?"ext.desktopStep1Done":"ext.desktopStep1Action")})]}),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("ext.desktopStep2Title")}),e.jsx("div",{className:"text-xs text-fg-4 mb-3",children:s("ext.desktopStep2Desc")}),l&&v&&e.jsx("div",{className:"mb-2 text-xs",style:{color:l.ok?"var(--th-ok)":"var(--th-err)"},children:l.text}),e.jsx("div",{className:"flex items-center gap-2",children:p?e.jsx(B,{variant:"outline",size:"sm",disabled:o,onClick:F,children:s(o?"ext.desktopStopping":"ext.disable")}):e.jsx(B,{variant:"primary",size:"sm",disabled:!v||S,onClick:j,children:s(S?"ext.desktopStarting":"ext.desktopStep2Action")})})]})]}),e.jsx("div",{className:"flex justify-end gap-2 mt-6",children:e.jsx(B,{variant:"ghost",onClick:h,children:s("modal.cancel")})})]})}export{re as BrowserSetupModal,ie as DesktopSetupModal,ae as FeishuModal,se as TelegramModal,le as WeixinModal,ne as WorkdirModal};
|
|
1
|
+
import{r as a,j as e}from"./react-vendor-DTcmqLiz.js";import{u as y,b as L,B,a as I,k as P}from"./index-xNJkl-jN.js";import{M as W,a as q,L as U,I as G}from"./Modal-BLxBTu-V.js";import{D as V}from"./DirBrowser-vJss0x7d.js";import"./router-emLofBBH.js";const O="https://ilinkai.weixin.qq.com";function Q(c){return c instanceof Error&&(c.name==="AbortError"||/aborted/i.test(c.message))}function H(c,h){return c instanceof Error&&/timed out/i.test(c.message)?h("modal.requestTimeout"):h("modal.networkError")}function se({open:c,onClose:h}){const N=y(x=>x.state),d=y(x=>x.toast),D=y(x=>x.reloadUntil),s=y(x=>x.locale),t=a.useMemo(()=>L(s),[s]),[u,k]=a.useState(""),[g,p]=a.useState(""),[w,S]=a.useState(!1),[b,o]=a.useState(!1),[v,l]=a.useState(null),[n,T]=a.useState(!1),j=a.useRef(null),F=a.useRef(N);F.current=N,a.useEffect(()=>{c?(k(F.current?.config.telegramBotToken||""),p(F.current?.config.telegramAllowedChatIds||""),S(!1),l(null),T(!F.current?.config.telegramBotToken)):(j.current?.abort(),j.current=null,o(!1))},[c]),a.useEffect(()=>()=>{j.current?.abort(),j.current=null},[]);const i=async()=>{if(!u.trim()){d(t("modal.inputToken"),!1);return}j.current?.abort();const x=new AbortController;j.current=x,o(!0),l(null);let r=!1;try{const f=await I.validateTelegramConfig(u.trim(),g.trim(),{signal:x.signal,timeoutMs:12e3});if(!f.ok){l({ok:!1,text:"✗ "+(f.error||t("modal.validationFailed"))});return}const C=f.normalizedAllowedChatIds??g.trim();l({ok:!0,text:"✓ @"+(f.bot?.username||"bot")+(f.bot?.displayName?" ("+f.bot.displayName+")":"")});const A=new Set((N?.setupState?.channels||[]).filter(E=>(E.ready||E.configured)&&E.channel!=="telegram").map(E=>E.channel));if(A.add("telegram"),await I.saveConfig({telegramBotToken:u.trim(),telegramAllowedChatIds:C,channels:[...A]}),!await D(E=>{const z=E.setupState?.channels?.find(K=>K.channel==="telegram");return E.config.telegramBotToken===u.trim()&&(E.config.telegramAllowedChatIds||"")===C&&!!z?.ready},{attempts:10,intervalMs:350})){l({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),d(t("modal.refreshStateFailed"),!1);return}d(t("modal.tgSaved")),r=!0}catch(f){if(Q(f))return;const C=H(f,t);l({ok:!1,text:"✗ "+C}),d(C,!1)}finally{j.current===x&&(j.current=null),o(!1),r&&h()}},m=()=>{j.current?.abort(),j.current=null,h()};return e.jsxs(W,{open:c,onClose:m,children:[e.jsx(q,{title:t("modal.configureTelegram"),onClose:m}),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:()=>T(!n),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 ${n?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),n&&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(U,{children:t("modal.botToken")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{type:w?"text":"password",className:"flex-1 font-mono text-xs",placeholder:t("modal.pasteToken"),value:u,onChange:x=>k(x.target.value)}),e.jsx(B,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>S(!w),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"})]})})]})]}),v&&e.jsx("div",{className:"text-xs",style:{color:v.ok?"var(--th-ok)":"var(--th-err)"},children:v.text}),e.jsxs("div",{children:[e.jsxs(U,{children:[t("modal.allowedIds")," ",e.jsxs("span",{className:"text-fg-5",children:["(",t("modal.optional"),")"]})]}),e.jsx(G,{className:"font-mono text-xs",placeholder:t("modal.commaSep"),value:g,onChange:x=>p(x.target.value)})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(B,{variant:"ghost",onClick:m,children:t("modal.cancel")}),e.jsx(B,{variant:"primary",disabled:b,onClick:i,children:t(b?"modal.validating":"modal.validateSave")})]})]})}function ae({open:c,onClose:h}){const N=y(i=>i.state),d=y(i=>i.toast),D=y(i=>i.reloadUntil),s=y(i=>i.locale),t=a.useMemo(()=>L(s),[s]),[u,k]=a.useState(""),[g,p]=a.useState(""),[w,S]=a.useState(!1),[b,o]=a.useState(null),[v,l]=a.useState(!1),n=a.useRef(null),T=a.useRef(N);T.current=N,a.useEffect(()=>{c?(k(T.current?.config.feishuAppId||""),p(T.current?.config.feishuAppSecret||""),o(null),l(!T.current?.config.feishuAppId)):(n.current?.abort(),n.current=null,S(!1))},[c]),a.useEffect(()=>()=>{n.current?.abort(),n.current=null},[]);const j=async()=>{if(!u.trim()){d(t("modal.inputAppId"),!1);return}n.current?.abort();const i=new AbortController;n.current=i,S(!0),o(null);let m=!1;try{const x=await I.validateFeishuConfig(u.trim(),g.trim(),{signal:i.signal,timeoutMs:2e4});if(!x.ok){o({ok:!1,text:"✗ "+(x.error||t("modal.validationFailed"))});return}o({ok:!0,text:"✓ "+(x.app?.displayName||x.app?.appId||u.trim())});const r=new Set((N?.setupState?.channels||[]).filter(C=>(C.ready||C.configured)&&C.channel!=="feishu").map(C=>C.channel));if(r.add("feishu"),await I.saveConfig({feishuAppId:u.trim(),feishuAppSecret:g.trim(),channels:[...r]}),!await D(C=>{const A=C.setupState?.channels?.find(R=>R.channel==="feishu");return C.config.feishuAppId===u.trim()&&C.config.feishuAppSecret===g.trim()&&!!A?.ready},{attempts:10,intervalMs:350})){o({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),d(t("modal.refreshStateFailed"),!1);return}d(t("modal.feishuSaved")),m=!0}catch(x){if(Q(x))return;const r=H(x,t);o({ok:!1,text:"✗ "+r}),d(r,!1)}finally{n.current===i&&(n.current=null),S(!1),m&&h()}},F=()=>{n.current?.abort(),n.current=null,h()};return e.jsxs(W,{open:c,onClose:F,children:[e.jsx(q,{title:t("modal.configureFeishu"),onClose:F}),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:()=>l(!v),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 ${v?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),v&&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(U,{children:t("modal.appId")}),e.jsx(G,{className:"font-mono text-xs",placeholder:t("modal.feishuPlaceholder"),value:u,onChange:i=>k(i.target.value)})]}),e.jsxs("div",{children:[e.jsx(U,{children:t("modal.appSecret")}),e.jsx(G,{type:"password",className:"font-mono text-xs",placeholder:t("modal.appSecret"),value:g,onChange:i=>p(i.target.value)})]}),b&&e.jsx("div",{className:"text-xs",style:{color:b.ok?"var(--th-ok)":"var(--th-err)"},children:b.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(B,{variant:"ghost",onClick:F,children:t("modal.cancel")}),e.jsx(B,{variant:"primary",disabled:w,onClick:j,children:t(w?"modal.validating":"modal.validateSave")})]})]})}function le({open:c,onClose:h}){const N=y(m=>m.state),d=y(m=>m.toast),D=y(m=>m.reloadUntil),s=y(m=>m.locale),t=a.useMemo(()=>L(s),[s]),[u,k]=a.useState(O),[g,p]=a.useState(!1),[w,S]=a.useState(""),[b,o]=a.useState(""),[v,l]=a.useState(null),n=a.useRef(null),T=a.useRef(N);T.current=N,a.useEffect(()=>{c?(k(T.current?.config.weixinBaseUrl||O),p(!1),S(""),o(""),l(null)):(n.current?.abort(),n.current=null,p(!1))},[c]),a.useEffect(()=>()=>{n.current?.abort(),n.current=null},[]);const j=()=>{n.current?.abort(),n.current=null,h()},F=a.useCallback(async(m,x,r)=>{for(;!m.signal.aborted;){const f=await I.waitWeixinLogin(x,r,{signal:m.signal,timeoutMs:45e3});if(!f.ok&&!f.connected)return l({ok:!1,text:"✗ "+(f.error||f.message||t("modal.validationFailed"))}),!1;if(f.qrcodeUrl&&S(f.qrcodeUrl),f.status==="scaned"?l({ok:!0,text:t("modal.weixinScanned")}):f.status==="expired"?l({ok:!0,text:t("modal.weixinQrRefreshed")}):f.connected||l({ok:!0,text:t("modal.weixinWaitingScan")}),!f.connected)continue;l({ok:!0,text:t("modal.weixinLoginSuccess")});const C=f.baseUrl||r,A=f.botToken||"",R=f.accountId||"",E=await I.validateWeixinConfig(C,A,R,{signal:m.signal,timeoutMs:12e3});if(!E.ok)return l({ok:!1,text:"✗ "+(E.error||t("modal.validationFailed"))}),!1;const z=E.normalizedBaseUrl||C,K=new Set((T.current?.setupState?.channels||[]).filter(M=>(M.ready||M.configured)&&M.channel!=="weixin").map(M=>M.channel));return K.add("weixin"),await I.saveConfig({weixinBaseUrl:z,weixinBotToken:A,weixinAccountId:R,channels:[...K]}),await D(M=>{const _=M.setupState?.channels?.find($=>$.channel==="weixin");return M.config.weixinBaseUrl===z&&M.config.weixinBotToken===A&&M.config.weixinAccountId===R&&!!_?.ready},{attempts:12,intervalMs:350})?(d(t("modal.weixinSaved")),!0):(l({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),d(t("modal.refreshStateFailed"),!1),!1)}return!1},[D,t,d]),i=async()=>{if(!u.trim()){d(t("modal.inputWeixinBaseUrl"),!1);return}n.current?.abort();const m=new AbortController;n.current=m,p(!0),S(""),o(""),l(null);let x=!1;try{const r=await I.startWeixinLogin(u.trim(),{signal:m.signal,timeoutMs:12e3});if(!r.ok||!r.qrcodeUrl){l({ok:!1,text:"✗ "+(r.error||r.message||t("modal.validationFailed"))});return}S(r.qrcodeUrl),o(r.sessionKey),l({ok:!0,text:t("modal.weixinWaitingScan")}),x=await F(m,r.sessionKey,u.trim())}catch(r){if(Q(r))return;const f=H(r,t);l({ok:!1,text:"✗ "+f}),d(f,!1)}finally{n.current===m&&(n.current=null),p(!1),x&&h()}};return e.jsxs(W,{open:c,onClose:j,children:[e.jsx(q,{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(U,{children:t("modal.weixinBaseUrl")}),e.jsx(G,{className:"font-mono text-xs",value:u,onChange:m=>k(m.target.value),placeholder:O}),e.jsx("div",{className:"mt-1 text-[11px] text-fg-5",children:t("modal.weixinDefaultBaseUrlHint")})]}),w&&e.jsxs("div",{className:"rounded-xl border border-edge bg-panel-alt p-4",children:[e.jsx("img",{src:w,alt:t("modal.weixinQrAlt"),className:"mx-auto h-56 w-56 rounded-lg bg-white p-3 object-contain"}),b&&e.jsx("div",{className:"mt-2 truncate text-center font-mono text-[10px] text-fg-5",children:b})]}),v&&e.jsx("div",{className:"text-xs",style:{color:v.ok?"var(--th-ok)":"var(--th-err)"},children:v.text})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(B,{variant:"ghost",onClick:j,children:t("modal.cancel")}),e.jsx(B,{variant:"primary",disabled:g,onClick:i,children:t(g?w?"modal.validating":"modal.weixinGeneratingQr":w?"modal.weixinRetry":"modal.weixinGenerateQr")})]})]})}function ne({open:c,onClose:h}){const N=y(l=>l.state),d=y(l=>l.toast),D=y(l=>l.reload),s=y(l=>l.locale),t=a.useMemo(()=>L(s),[s]),u=N?.bot?.workdir||N?.runtimeWorkdir||"",[k,g]=a.useState(""),[p,w]=a.useState(!1),[S,b]=a.useState(0);a.useEffect(()=>{c&&(g(u),b(l=>l+1))},[c,u]);const o=a.useCallback(l=>{g(l)},[]),v=async()=>{const l=k.trim();if(!l){d(t("modal.selectDirFirst"),!1);return}w(!0);try{const n=await I.switchWorkdir(l);n.ok?(await D(),d(t("modal.switchedTo")+n.workdir),h()):d(n.error||t("modal.switchFailed"),!1)}catch{d(t("modal.switchFailed"),!1)}finally{w(!1)}};return e.jsx(W,{open:c,onClose:p?void 0:h,panelStyle:{width:"min(500px, calc(100vw - 2rem))",maxWidth:"min(500px, calc(100vw - 2rem))"},children:p?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:k})]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{title:t("modal.switchWorkdir"),onClose:h}),e.jsx(V,{initialPath:u,onSelect:o,t},S),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(B,{variant:"ghost",onClick:h,children:t("modal.cancel")}),e.jsx(B,{variant:"primary",onClick:v,children:t("modal.selectDir")})]})]})})}function re({open:c,onClose:h,onSaved:N}){const d=y(r=>r.toast),D=y(r=>r.locale),s=a.useMemo(()=>L(D),[D]),[t,u]=a.useState(null),[k,g]=a.useState(!1),[p,w]=a.useState(!1),[S,b]=a.useState(null);a.useEffect(()=>{c&&(g(!1),b(null),I.getBrowser().then(r=>{u(r),w(!!r.browser.enabled)}).catch(()=>u(null)))},[c]);const o=t?.browser,v=!!o?.enabled,l=!!o&&v!==p,n=o?.profileDir||"",T=s("ext.profileDir"),j=n,F=!!o?.chromeInstalled&&!!o?.profileCreated,i=t?o?.enabled?F?s("ext.browserReady"):o?.chromeInstalled?s("ext.chromeInstalled"):s("ext.needsSetup"):s("ext.disabled"):s("status.loading"),m=t&&o?.enabled?F?"ok":o?.chromeInstalled?"warn":"err":"muted",x=async()=>{g(!0),b(null);try{await I.saveConfig({browserEnabled:p});const r=await I.getBrowser();u(r),N?.()}catch{b({ok:!1,text:"✗ "+s("ext.browserModeSaveFailed")}),d(s("ext.browserModeSaveFailed"),!1),g(!1);return}if(!p){b({ok:!0,text:"✓ "+s("ext.browserDisabledSaved")}),d(s("ext.browserDisabledSaved")),g(!1);return}try{const r=await I.setupBrowser();if(!r.ok){b({ok:!1,text:"✗ "+(r.error||s("ext.browserLaunchFailed"))}),d(r.error||s("ext.browserLaunchFailed"),!1);return}u(f=>f?{...f,browser:r.browser}:{browser:r.browser,desktop:{enabled:!1,installed:!1,running:!1,appiumUrl:""}}),b({ok:!0,text:"✓ "+s("ext.browserEnabledLaunched")}),d(s("ext.browserEnabledLaunched")),N?.()}catch{b({ok:!1,text:"✗ "+s("ext.browserLaunchFailed")}),d(s("ext.browserLaunchFailed"),!1)}finally{g(!1)}};return e.jsxs(W,{open:c,onClose:h,children:[e.jsx(q,{title:s("ext.setupBrowser"),description:s("ext.setupBrowserDesc"),onClose:h}),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(P,{variant:m,children:i}),o&&e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:v?"accent":"muted",children:s(v?"ext.enabled":"ext.disabled")}),l&&e.jsx(P,{variant:"warn",children:s("ext.pendingModeChange")}),o.running&&e.jsxs(P,{variant:"accent",children:[s("ext.browserOpen"),o.pid?` · PID ${o.pid}`:""]})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(U,{children:T}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{className:"font-mono text-xs flex-1",value:j||"—",readOnly:!0,onClick:r=>r.target.select()}),e.jsx(B,{variant:"outline",size:"sm",disabled:!j,onClick:()=>{j&&(navigator.clipboard.writeText(j),d(s("ext.step2Copied")))},children:s("ext.copyPath")})]})]}),e.jsx("div",{className:"mt-3 text-xs text-fg-5",children:s(p?"ext.profileModeDesc":"ext.browserDescDisabled")}),o?.detail&&e.jsx("div",{className:"mt-2 text-xs text-fg-5",children:o.detail}),S&&e.jsx("div",{className:"mt-3 text-xs",style:{color:S.ok?"var(--th-ok)":"var(--th-err)"},children:S.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:p,onChange:r=>w(r.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(p?"ext.step2Title":"ext.browserDisabledStepTitle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s(p?"ext.step2Desc":"ext.browserDisabledHint")})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(B,{variant:"ghost",onClick:h,children:s("modal.cancel")}),e.jsx(B,{variant:"primary",disabled:k,onClick:x,children:s(k?"ext.launching":p?"ext.enableAndLaunchBrowser":"ext.saveBrowserDisabled")})]})]})}function ie({open:c,onClose:h,onSaved:N}){const d=y(i=>i.toast),D=y(i=>i.locale),s=a.useMemo(()=>L(D),[D]),[t,u]=a.useState(!1),[k,g]=a.useState(!1),[p,w]=a.useState(!1),[S,b]=a.useState(!1),[o,v]=a.useState(!1),[l,n]=a.useState(null);a.useEffect(()=>{c&&(u(!1),b(!1),v(!1),n(null),I.getBrowser().then(i=>{g(i.desktop.installed),w(i.desktop.enabled)}).catch(()=>{}))},[c]);const T=async()=>{u(!0),n(null);try{const i=await I.desktopInstall();i.ok?(g(!0),n({ok:!0,text:"✓ "+s("ext.desktopInstalled")}),d(s("ext.desktopInstalled"))):n({ok:!1,text:"✗ "+(i.error||s("ext.desktopInstallFailed"))})}catch{n({ok:!1,text:"✗ "+s("ext.desktopInstallFailed")})}finally{u(!1)}},j=async()=>{b(!0),n(null);try{const i=await I.desktopToggle(!0);i.ok?(w(!0),n({ok:!0,text:"✓ "+s("ext.desktopStarted")}),d(s("ext.desktopStarted")),N?.()):n({ok:!1,text:"✗ "+(i.error||s("ext.desktopInstallFailed"))})}catch{n({ok:!1,text:"✗ "+s("ext.desktopInstallFailed")})}finally{b(!1)}},F=async()=>{v(!0),n(null);try{const i=await I.desktopToggle(!1);i.ok?(w(!1),n({ok:!0,text:"✓ "+s("ext.desktopStopped")}),d(s("ext.desktopStopped")),N?.()):n({ok:!1,text:"✗ "+(i.error||s("ext.desktopInstallFailed"))})}catch{n({ok:!1,text:"✗ "+s("ext.desktopInstallFailed")})}finally{v(!1)}};return e.jsxs(W,{open:c,onClose:h,children:[e.jsx(q,{title:s("ext.setupDesktop"),description:s("ext.setupDesktopDesc"),onClose:h}),e.jsxs("div",{className:"space-y-5",children:[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("ext.desktopStep1Title")}),e.jsx("div",{className:"text-xs text-fg-4 mb-3",children:s("ext.desktopStep1Desc")}),l&&!k&&e.jsx("div",{className:"mb-2 text-xs",style:{color:l.ok?"var(--th-ok)":"var(--th-err)"},children:l.text}),e.jsx(B,{variant:k?"ghost":"outline",size:"sm",disabled:t||k,onClick:T,children:s(t?"ext.desktopInstalling":k?"ext.desktopStep1Done":"ext.desktopStep1Action")})]}),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("ext.desktopStep2Title")}),e.jsx("div",{className:"text-xs text-fg-4 mb-3",children:s("ext.desktopStep2Desc")}),l&&k&&e.jsx("div",{className:"mb-2 text-xs",style:{color:l.ok?"var(--th-ok)":"var(--th-err)"},children:l.text}),e.jsx("div",{className:"flex items-center gap-2",children:p?e.jsx(B,{variant:"outline",size:"sm",disabled:o,onClick:F,children:s(o?"ext.desktopStopping":"ext.disable")}):e.jsx(B,{variant:"primary",size:"sm",disabled:!k||S,onClick:j,children:s(S?"ext.desktopStarting":"ext.desktopStep2Action")})})]})]}),e.jsx("div",{className:"flex justify-end gap-2 mt-6",children:e.jsx(B,{variant:"ghost",onClick:h,children:s("modal.cancel")})})]})}export{re as BrowserSetupModal,ie as DesktopSetupModal,ae as FeishuModal,se as TelegramModal,le as WeixinModal,ne as WorkdirModal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,j as e}from"./react-vendor-DTcmqLiz.js";import{u,
|
|
1
|
+
import{r as l,j as e}from"./react-vendor-DTcmqLiz.js";import{u,b as R,a as D,B as f,k as N}from"./index-xNJkl-jN.js";import{a as L,b as O,c as j,d as z}from"./shared-BSx12aDa.js";import"./router-emLofBBH.js";const E=[{key:"accessibility",labelKey:"perm.accessibility",reasonZh:"允许控制桌面应用、点击和输入。",reasonEn:"Allows controlling desktop apps with clicks and typing.",guidePathKey:"perm.pathAccessibility",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"5",r:"1.8"}),e.jsx("path",{d:"M12 7.7v10.2"}),e.jsx("path",{d:"M8.4 10h7.2"}),e.jsx("path",{d:"M9.6 19.2 12 15.1l2.4 4.1"})]})},{key:"screenRecording",labelKey:"perm.screenRecording",reasonZh:"允许读取屏幕内容,用于截图和界面分析。",reasonEn:"Allows reading the screen for screenshots and UI inspection.",guidePathKey:"perm.pathScreenRecording",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"4",y:"5.5",width:"11.5",height:"10",rx:"2.4"}),e.jsx("path",{d:"m17.5 8.4 2.7-1.5v7.2l-2.7-1.5"}),e.jsx("circle",{cx:"9.75",cy:"10.5",r:"1.1",fill:"currentColor",stroke:"none"})]})},{key:"fullDiskAccess",labelKey:"perm.fullDiskAccess",reasonZh:"允许访问桌面、下载等受保护目录。",reasonEn:"Allows access to protected folders like Desktop and Downloads.",guidePathKey:"perm.pathFullDiskAccess",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"6.2",y:"10.1",width:"11.6",height:"8.6",rx:"2.6"}),e.jsx("path",{d:"M9 10V7.8a3 3 0 1 1 6 0V10"}),e.jsx("circle",{cx:"12",cy:"13.5",r:"0.9",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M12 14.6v1.8"})]})}];function K(o){return o==="zh-CN"?{introWithHost:"请在 macOS 中为 {hostApp} 开启以下权限。",intro:"请在 macOS 中开启以下权限。",status:"状态",summary:"系统位置",loading:"检查中",needsGrant:"需要授权",granted:"已授权",authorize:"授权",openSettings:"前往设置",refreshState:"刷新状态",checking:"检查中...",hostGranted:"{hostApp} 已可直接使用此权限。",hostGrantedFallback:"当前宿主应用已可直接使用此权限。",needsGrantDetail:"尚未授权,可通过右侧按钮发起系统授权。",needsSettingsDetail:"需要在系统设置中手动开启此权限。"}:{introWithHost:"Grant the following permissions to {hostApp} in macOS.",intro:"Grant the following permissions in macOS.",status:"Status",summary:"System path",loading:"Checking",needsGrant:"Needs access",granted:"Granted",authorize:"Authorize",openSettings:"Open settings",refreshState:"Refresh status",checking:"Checking...",hostGranted:"{hostApp} can use this permission now.",hostGrantedFallback:"The current host app can use this permission now.",needsGrantDetail:"Access has not been granted yet. Use the button on the right to trigger the macOS prompt.",needsSettingsDetail:"This permission needs to be enabled manually in System Settings."}}function B(){const o=u(t=>t.state),d=u(t=>t.locale),h=u(t=>t.reload),i=u(t=>t.toast),a=l.useMemo(()=>R(d),[d]),s=K(d),g=o?.permissions||{},p=o?.hostApp||null,c=!o,[m,x]=l.useState(null),b=l.useMemo(()=>E.map(t=>({...t,permission:g[t.key]})),[g]),S=l.useCallback(async t=>{if(!m){x(t);try{const n=await D.requestPermission(t);if(!n.ok){i(n.error||a("perm.requestFailed"),!1);return}n.action==="already_granted"?i(a("perm.alreadyGranted")):n.action==="prompted"?i(a("perm.promptOpened")):i(a("perm.settingsOpened")),await h()}catch(n){i(n instanceof Error?n.message:a("perm.requestFailed"),!1)}finally{x(n=>n===t?null:n)}}},[h,m,a,i]),k=l.useCallback(async()=>{await h()},[h]);return e.jsxs("div",{className:"animate-in space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("div",{className:"text-[13px] leading-relaxed text-fg-4",children:p?s.introWithHost.replace("{hostApp}",p):s.intro})}),e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{k()},children:s.refreshState})]}),b.map(t=>{const n=t.permission,r=!!n?.granted,y=!!n&&n.checkable,w=c?s.loading:n&&r?s.granted:s.needsGrant,v=c?"muted":r?"ok":"warn",A=c?s.loading:r?p?s.hostGranted.replace("{hostApp}",p):s.hostGrantedFallback:y?s.needsGrantDetail:s.needsSettingsDetail,G=c?s.checking:r?s.refreshState:y?s.authorize:s.openSettings,C=r?k:()=>{S(t.key)};return e.jsxs(L,{children:[e.jsx(O,{icon:t.icon,title:a(t.labelKey),subtitle:d==="zh-CN"?t.reasonZh:t.reasonEn}),e.jsxs(j,{label:s.status,children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:e.jsx(N,{variant:v,children:w})}),e.jsx("div",{className:"mt-1 text-[13px] leading-relaxed text-fg-3",children:A})]}),e.jsx(j,{label:s.summary,children:e.jsx("div",{className:"break-words text-[13px] leading-relaxed text-fg-3",children:a(t.guidePathKey)})}),e.jsx(z,{children:e.jsx(f,{variant:r?"outline":"primary",size:"sm",disabled:c||!!m,onClick:C,children:m===t.key?s.checking:G})})]},t.key)})]})}export{B as PermissionsTab};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as e,b as H}from"./react-vendor-DTcmqLiz.js";import{c}from"./index-
|
|
1
|
+
import{r as s,j as e,b as H}from"./react-vendor-DTcmqLiz.js";import{c}from"./index-xNJkl-jN.js";function _(u,h){return!!(u&&h instanceof Node&&u.contains(h))}function M({value:u,options:h,onChange:y,className:w,placeholder:a="—",disabled:x=!1,readOnly:p=!1}){const f=h.find(n=>n.value===u),m=p||h.length<=1,[i,g]=s.useState(!1),[t,l]=s.useState(null),o=s.useRef(null),j=s.useRef(null);if(s.useEffect(()=>{if(!i)return;const n=d=>{_(o.current,d.target)||_(j.current,d.target)||g(!1)},r=d=>{d.key==="Escape"&&g(!1)};return document.addEventListener("mousedown",n),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",r)}},[i]),s.useLayoutEffect(()=>{if(!i)return;const n=()=>{const r=o.current;if(!r)return;const d=r.getBoundingClientRect(),k=window.innerHeight-d.bottom-12,E=d.top-12,N=k<220&&E>k,L=Math.max(140,Math.min(260,N?E:k));l({left:d.left,top:N?Math.max(12,d.top-L-8):d.bottom+8,width:d.width,maxHeight:L})};return n(),window.addEventListener("resize",n),window.addEventListener("scroll",n,!0),()=>{window.removeEventListener("resize",n),window.removeEventListener("scroll",n,!0)}},[i]),m)return e.jsx("div",{className:c("flex h-8 w-full items-center rounded-md border border-edge bg-panel-alt px-2.5 text-[13px] text-fg-3 shadow-[inset_0_1px_0_var(--th-inset-hl),0_1px_2px_rgba(15,23,42,0.05)]",x&&"cursor-not-allowed opacity-50",w),children:e.jsx("span",{className:c("truncate",!f&&"text-fg-5"),children:f?.label||a})});const v=n=>{x||(y(n),g(!1))},b=i&&t?H.createPortal(e.jsx("div",{ref:j,role:"listbox",className:"fixed z-[220] overflow-hidden rounded-xl border border-edge-h bg-[var(--th-dropdown)] p-1.5 shadow-[0_24px_64px_rgba(2,6,23,0.22)] backdrop-blur-xl",style:{left:t.left,top:t.top,width:t.width},children:e.jsx("div",{className:"overflow-y-auto",style:{maxHeight:t.maxHeight},children:h.map(n=>{const r=n.value===u;return e.jsxs("button",{type:"button",role:"option","aria-selected":r,onClick:()=>v(n.value),className:c("flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-[13px] transition-colors duration-200",r?"bg-panel text-fg shadow-[inset_0_1px_0_rgba(255,255,255,0.03)]":"text-fg-3 hover:bg-panel-alt hover:text-fg-2"),children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:n.label}),r&&e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"shrink-0 text-fg-4",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]},n.value)})})}),document.body):null;return e.jsxs("div",{ref:o,className:c("relative",w),children:[e.jsxs("button",{type:"button",disabled:x,"aria-haspopup":"listbox","aria-expanded":i,onClick:()=>g(n=>!n),className:c("flex h-8 w-full items-center rounded-md border border-edge bg-inset px-2.5 pr-8 text-left text-[13px] text-fg shadow-[inset_0_1px_0_var(--th-inset-hl),0_1px_2px_rgba(15,23,42,0.05)]","transition-[border-color,box-shadow,background] duration-200 outline-none","hover:border-edge-h hover:bg-panel","focus-visible:border-edge-h focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]","disabled:cursor-not-allowed disabled:opacity-50",i&&"border-edge-h bg-panel shadow-[0_0_0_4px_var(--th-glow-a)]"),children:[e.jsx("span",{className:c("min-w-0 flex-1 truncate",!f&&"text-fg-5"),children:f?.label||a}),e.jsx("span",{className:c("pointer-events-none absolute inset-y-0 right-3 flex items-center text-fg-4 transition-transform duration-200",i&&"rotate-180"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),b]})}function B({value:u,options:h,onChange:y,renderIcon:w}){const[a,x]=s.useState(!1),[p,f]=s.useState(null),m=s.useRef(null),i=s.useRef(null);s.useEffect(()=>{if(!a)return;const t=o=>{_(m.current,o.target)||_(i.current,o.target)||x(!1)},l=o=>{o.key==="Escape"&&x(!1)};return document.addEventListener("mousedown",t),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",l)}},[a]),s.useLayoutEffect(()=>{if(!a)return;const t=()=>{const l=m.current;if(!l)return;const o=l.getBoundingClientRect(),v=window.innerHeight-o.bottom-12,b=o.top-12,n=v<220&&b>v,r=Math.max(140,Math.min(260,n?b:v));f({left:o.left,top:n?Math.max(12,o.top-r-8):o.bottom+8,width:Math.max(o.width,160),maxHeight:r})};return t(),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[a]);const g=a&&p?H.createPortal(e.jsx("div",{ref:i,role:"listbox",className:"fixed z-[220] overflow-hidden rounded-xl border border-edge-h bg-[var(--th-dropdown)] p-1.5 shadow-[0_24px_64px_rgba(2,6,23,0.22)] backdrop-blur-xl",style:{left:p.left,top:p.top,width:p.width},children:e.jsx("div",{className:"overflow-y-auto",style:{maxHeight:p.maxHeight},children:h.map(t=>{const l=t.value===u;return e.jsxs("button",{type:"button",role:"option","aria-selected":l,onClick:()=>{y(t.value),x(!1)},className:c("flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[13px] transition-colors duration-200",l?"bg-panel text-fg shadow-[inset_0_1px_0_rgba(255,255,255,0.03)]":"text-fg-3 hover:bg-panel-alt hover:text-fg-2"),children:[w(t.value),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.label}),l&&e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"shrink-0 text-fg-4",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]},t.value)})})}),document.body):null;return e.jsxs("div",{ref:m,className:"relative shrink-0",children:[e.jsxs("button",{type:"button","aria-haspopup":"listbox","aria-expanded":a,onClick:()=>x(t=>!t),className:c("inline-flex items-center gap-1.5 rounded-lg border border-edge bg-inset px-2 py-1.5","transition-[border-color,box-shadow,background] duration-200 outline-none","hover:border-edge-h hover:bg-panel","focus-visible:border-edge-h focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",a&&"border-edge-h bg-panel shadow-[0_0_0_4px_var(--th-glow-a)]"),children:[w(u),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:c("text-fg-5 transition-transform duration-200",a&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),g]})}export{B as I,M as S};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as t,j as s}from"./react-vendor-DTcmqLiz.js";import{u as Se,b as Me,g as we,s as Ce,a as P,S as Te,j as ee}from"./index-xNJkl-jN.js";import{l as De,n as xe,m as _e,a as $e,p as Qe,u as qe,b as Ae,T as Ue,U as Be,c as Ke,d as ke,L as Xe,I as ze}from"./index-BOjiS988.js";import"./router-emLofBBH.js";import"./Select-CrXZymnB.js";import"./Modal-BLxBTu-V.js";import"./BrandIcon-C-aE815y.js";import"./DirBrowser-vJss0x7d.js";import"./markdown-iTdiLvRJ.js";import"./ExtensionsTab-BIJUhVs_.js";import"./shared-BSx12aDa.js";const te=12,Ie=160,Fe=96,Ge=20,R=new Map;function Ve(v,r){return`${v}:${r}`}function We(v,r){for(R.delete(v),R.set(v,r);R.size>Ge;)R.delete(R.keys().next().value)}const ot=t.memo(function({session:r,workdir:d,active:re=!0,onSessionChange:q,initialPendingPrompt:ne,initialPendingImageUrls:M,onPendingPromptConsumed:se}){const le=Se(e=>e.locale),Re=Se(e=>e.agentStatus?.agents?.find(n=>n.agent===r.agent)?.selectedEffort??null),A=r.thinkingEffort||Re,m=t.useMemo(()=>Me(le),[le]),U=we(r.agent||""),ae=Ce(r),y=!!ne||!!(M&&M.length),[a,B]=t.useState(null),[K,ue]=t.useState(!y),[O,ce]=t.useState(!1),[c,b]=t.useState(null),[w,j]=t.useState(!1),[ve,X]=t.useState(null),[ye,oe]=t.useState(0),[Oe,z]=t.useState(null),[be,fe]=t.useState([]),[u,ie]=t.useState(ne||null),[L,de]=t.useState(M||[]),[je,F]=t.useState(!1),[Le,ge]=t.useState(null),G=t.useRef(M||[]),h=t.useRef(c),me=t.useRef(w);h.current=c,me.current=w;const p=t.useRef(null),C=t.useRef(null),S=t.useRef(!0),T=t.useRef(!1),V=t.useRef(!1),W=t.useRef(!1),E=t.useRef(y),H=t.useRef(!1),x=t.useRef(!1),Y=t.useRef(!1),J=t.useRef(!1);t.useEffect(()=>{Y.current||!y||(Y.current=!0,oe(e=>e+1),se?.())},[y,se]);const i=t.useCallback(()=>{ie(null),de(e=>{for(const n of e)URL.revokeObjectURL(n);return[]}),G.current=[],F(!1)},[]),he=t.useCallback((e,n)=>{for(const f of G.current)URL.revokeObjectURL(f);ie(e||null);const l=n||[];de(l),G.current=l,F(!!h.current||me.current)},[]),D=t.useCallback(async(e,n={})=>{try{const l=await De({workdir:d,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:e.turnOffset,turnLimit:e.turnLimit,lastNTurns:e.lastNTurns},{force:n.force});return l.ok?xe(l):null}catch{return null}},[d,r.agent,r.sessionId]),o=t.useCallback(async({keepOlder:e,force:n=!1,scrollToBottom:l=!1})=>{if(V.current)return!1;V.current=!0;try{const f=await D({turnOffset:0,turnLimit:te},{force:n});if(!f)return!1;if(l&&(T.current=!0),B(I=>!I||!e?f:_e(I,f)),H.current&&(H.current=!1,i()),x.current){const I=x.current;x.current=!1;const Pe=I!==!0?I.taskId:null;h.current&&(I===!0||h.current.taskId===Pe)&&b(null)}return!0}finally{V.current=!1}},[D,i]),_=t.useCallback(async()=>{if(!a?.hasOlder||W.current)return;const e=p.current;e&&(C.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}),W.current=!0,ce(!0);try{const n=await D({turnOffset:Math.max(0,a.totalTurns-a.startTurn),turnLimit:te});n?B(l=>l?$e(l,n):n):C.current=null}finally{W.current=!1,ce(!1)}},[D,a]),$=t.useRef(null),k=t.useCallback(e=>{if(e?.sessionId&&e.sessionId!==r.sessionId&&(J.current=!0,Z.current=`${r.agent}:${e.sessionId}`,q?.({agent:r.agent||"",sessionId:e.sessionId,workdir:d})),!e){const n=$.current;j(!1),n==="streaming"?(H.current=!0,x.current=!0,o({keepOlder:!0,force:!0,scrollToBottom:S.current})):b(null),n==="done"?i():n===null&&E.current&&o({keepOlder:!0,force:!0}),E.current=!1,z(null),X(null),fe([]),$.current=null;return}if(X(e.phase),z(e.taskId||null),fe(e.queuedTaskIds&&e.queuedTaskIds.length?e.queuedTaskIds:[]),e.phase==="streaming")x.current&&h.current&&h.current.taskId!==null&&h.current.taskId!==(e.taskId||null)&&!(e.text||"").trim()||b({taskId:e.taskId||null,phase:"streaming",text:e.text||"",thinking:e.thinking||"",activity:e.activity,plan:e.plan??null}),j(!0),e.queuedTaskIds?.length||F(!1),S.current&&(T.current=!0);else if(e.phase==="queued")b(null),j(!1);else if(e.phase==="done"){j(!1);const n=!!e.queuedTaskIds?.length;$.current!=="done"&&(n||(H.current=!0),x.current={taskId:e.taskId||null},o({keepOlder:!0,force:!0,scrollToBottom:S.current})),n||(E.current=!1)}$.current=e.phase},[i,o,r.sessionId,r.agent,q,d]),pe=t.useCallback(()=>{E.current=!0,oe(e=>e+1)},[]),Ee=t.useCallback(async e=>{try{await P.recallSessionMessage(e),i(),setQueuedTaskId(n=>n===e?null:n),z(n=>n===e?null:n)}catch{}},[i]),He=t.useCallback(async e=>{try{await P.steerSession(e)}catch{}},[]),Q=Ve(r.agent||"",r.sessionId);t.useEffect(()=>{if(J.current){J.current=!1,o({keepOlder:!0,force:!0});return}let e=!1;const n=Qe({workdir:d,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:0,turnLimit:te},{allowStale:!0}),l=y&&!Y.current,f=n?.ok?xe(n):R.get(Q)||null;return ue(l?!1:!f),B(f),b(null),j(!1),X(null),setQueuedTaskId(null),S.current=!0,T.current=!0,l||o({keepOlder:!1,force:!0}).finally(()=>{e||ue(!1)}),()=>{e=!0}},[o,r.agent,r.sessionId,d,Q]),t.useEffect(()=>{a&&a.turns.length>0&&We(Q,a)},[Q,a]),t.useEffect(()=>{re&&o({keepOlder:!0,force:!0})},[re,o]);const Z=t.useRef(`${r.agent}:${r.sessionId}`);Z.current=`${r.agent}:${r.sessionId}`,qe("stream-update",t.useCallback(e=>{e.key===Z.current&&k(e.snapshot??null)},[k])),t.useEffect(()=>{let e=!0;return P.getSessionStreamState(r.agent||"",r.sessionId).then(n=>{e&&k(n.state)}).catch(()=>{}),()=>{e=!1}},[k,r.agent,r.sessionId,ye]),Ae(t.useCallback(()=>{P.getSessionStreamState(r.agent||"",r.sessionId).then(e=>{k(e.state)}).catch(()=>{}),o({keepOlder:!0,force:!0})},[k,r.agent,r.sessionId,o])),t.useEffect(()=>{ae!=="running"&&!w&&!c&&(i(),E.current=!1)},[ae,w,c,i]),t.useLayoutEffect(()=>{const e=C.current,n=p.current;!e||!n||(C.current=null,n.scrollTop=e.scrollTop+(n.scrollHeight-e.scrollHeight))},[a?.turns.length]),t.useLayoutEffect(()=>{if(!T.current)return;const e=p.current;e&&(T.current=!1,e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{S.current&&(e.scrollTop=e.scrollHeight)}))},[a,c]),t.useLayoutEffect(()=>{if(!u)return;const e=p.current;e&&(e.scrollTop=e.scrollHeight)},[u]),t.useEffect(()=>{if(!a?.hasOlder||K||O)return;const e=p.current;e&&e.scrollHeight<=e.clientHeight+Ie&&_()},[a?.hasOlder,a?.turns.length,_,K,O]);const Ne=t.useCallback(()=>{const e=p.current;if(!e)return;const n=e.scrollHeight-e.scrollTop-e.clientHeight;S.current=n<=Fe,e.scrollTop<=Ie&&_()},[_]),g=a?.turns||[],N=t.useMemo(()=>{if(!c||!g.length)return g;const e=g[g.length-1];return!e.assistant||u&&e.user?.text?.trim()!==u.trim()?g:[...g.slice(0,-1),{...e,assistant:null}]},[g,c,u]);return s.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[s.jsx("div",{ref:p,onScroll:Ne,className:"flex-1 overflow-y-auto overscroll-contain",children:K?s.jsx("div",{className:"flex items-center justify-center py-20",children:s.jsx(Te,{className:"h-5 w-5 text-fg-4"})}):N.length===0&&!u&&!L.length&&!c?s.jsx("div",{className:"py-20 text-center text-[13px] text-fg-5",children:m("hub.noMessages")}):s.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[(a?.hasOlder||O)&&s.jsxs("div",{className:"mb-4 flex items-center justify-center gap-2 text-[11px] text-fg-5",children:[O?s.jsx(Te,{className:"h-3 w-3 text-fg-5"}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/35"}),s.jsx("span",{children:m(O?"hub.loadingOlderTurns":"hub.loadOlderTurnsHint")})]}),N.map((e,n)=>s.jsx(Ue,{turn:e,agent:r.agent||"",meta:U,model:r.model?ee(r.model):void 0,effort:A,t:m,onResend:l=>{T.current=!0,he(l),P.sendSessionMessage(d,r.agent||"",r.sessionId,l).then(f=>{f.ok&&pe()}).catch(()=>{i()})},onEdit:l=>ge(l)},`${a?.startTurn||0}:${n}`)),(u||L.length>0)&&!je&&!H.current&&!(u&&N.length>0&&N[N.length-1]?.user?.text?.trim()===u.trim())&&s.jsxs("div",{className:"session-turn",children:[s.jsx(Be,{text:u||"",blocks:L.map(e=>({type:"image",content:e})),t:m}),!c&&s.jsx("div",{className:"mt-3 mb-5 animate-in",children:s.jsx(Ke,{className:"text-fg-5"})})]}),c&&s.jsxs("div",{className:"mb-6",children:[!u&&!L.length&&s.jsx(ke,{agent:r.agent||"",meta:U,model:r.model?ee(r.model):void 0,effort:A}),(u||L.length>0)&&s.jsx(ke,{agent:r.agent||"",meta:U,model:r.model?ee(r.model):void 0,effort:A}),s.jsx(Xe,{stream:c,t:m})]}),s.jsx("div",{className:"h-4"})]})}),s.jsx(ze,{session:r,workdir:d,onStreamQueued:pe,onSendStart:he,onSessionChange:q,t:m,streamPhase:ve,streamTaskId:Oe,queuedTaskIds:be,pendingPrompt:u,onRecall:Ee,onSteer:He,editDraft:Le,onEditDraftConsumed:()=>ge(null)})]})});export{ot as SessionPanel};
|