jishushell 0.4.24 → 0.5.15
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/INSTALL-NOTICE +11 -0
- package/apps/anythingllm-container.yaml +287 -0
- package/apps/browserless-chromium-container.yaml +90 -0
- package/apps/filebrowser-container.yaml +163 -0
- package/apps/hermes-container.yaml +36 -2
- package/apps/ollama-binary.yaml +91 -90
- package/apps/ollama-cpu-container.yaml +8 -1
- package/apps/ollama-with-hollama-binary.yaml +91 -90
- package/apps/openclaw-binary.yaml +38 -1
- package/apps/openclaw-container.yaml +45 -2
- package/apps/openclaw-with-ollama-container.yaml +11 -2
- package/apps/openclaw-with-searxng-container.yaml +26 -2
- package/apps/openwebui-container.yaml +45 -1
- package/apps/playwright-container.yaml +7 -1
- package/apps/searxng-container.yaml +58 -7
- package/apps/weknora-container.yaml +471 -0
- package/dist/cli/app.js +79 -9
- package/dist/cli/app.js.map +1 -1
- package/dist/cli/doctor.d.ts +12 -12
- package/dist/cli/doctor.js +242 -55
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/llm.d.ts +4 -3
- package/dist/cli/llm.js +4 -3
- package/dist/cli/llm.js.map +1 -1
- package/dist/cli/panel.d.ts +6 -5
- package/dist/cli/panel.js +10 -9
- package/dist/cli/panel.js.map +1 -1
- package/dist/config.d.ts +19 -0
- package/dist/config.js +99 -1
- package/dist/config.js.map +1 -1
- package/dist/control.d.ts +7 -6
- package/dist/control.js +7 -6
- package/dist/control.js.map +1 -1
- package/dist/install.js +3 -3
- package/dist/install.js.map +1 -1
- package/dist/routes/agent-apps.d.ts +1 -1
- package/dist/routes/agent-apps.js +1 -1
- package/dist/routes/apps.js +44 -11
- package/dist/routes/apps.js.map +1 -1
- package/dist/routes/auth.js +5 -2
- package/dist/routes/auth.js.map +1 -1
- package/dist/routes/backup.js +64 -11
- package/dist/routes/backup.js.map +1 -1
- package/dist/routes/external-mounts.d.ts +17 -0
- package/dist/routes/external-mounts.js +73 -0
- package/dist/routes/external-mounts.js.map +1 -0
- package/dist/routes/file-mounts.d.ts +13 -0
- package/dist/routes/file-mounts.js +90 -0
- package/dist/routes/file-mounts.js.map +1 -0
- package/dist/routes/files-organize.d.ts +28 -0
- package/dist/routes/files-organize.js +167 -0
- package/dist/routes/files-organize.js.map +1 -0
- package/dist/routes/files.d.ts +31 -0
- package/dist/routes/files.js +321 -0
- package/dist/routes/files.js.map +1 -0
- package/dist/routes/instances.js +826 -17
- package/dist/routes/instances.js.map +1 -1
- package/dist/routes/internal.d.ts +2 -0
- package/dist/routes/internal.js +59 -0
- package/dist/routes/internal.js.map +1 -0
- package/dist/routes/llm.js +24 -35
- package/dist/routes/llm.js.map +1 -1
- package/dist/routes/setup.js +10 -10
- package/dist/routes/setup.js.map +1 -1
- package/dist/routes/system.js +1 -1
- package/dist/routes/system.js.map +1 -1
- package/dist/routes/webdav.d.ts +17 -0
- package/dist/routes/webdav.js +114 -0
- package/dist/routes/webdav.js.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +751 -20
- package/dist/server.js.map +1 -1
- package/dist/services/agent-apps/catalog.js +4 -3
- package/dist/services/agent-apps/catalog.js.map +1 -1
- package/dist/services/agent-apps/index.d.ts +1 -1
- package/dist/services/agent-apps/index.js +1 -1
- package/dist/services/agent-apps/installers/adapter.d.ts +1 -1
- package/dist/services/agent-apps/installers/adapter.js +1 -1
- package/dist/services/agent-apps/installers/shell-script.d.ts +1 -1
- package/dist/services/agent-apps/installers/shell-script.js +3 -3
- package/dist/services/agent-apps/installers/shell-script.js.map +1 -1
- package/dist/services/agent-apps/types.d.ts +2 -2
- package/dist/services/agent-apps/types.js +1 -1
- package/dist/services/app/app-compiler.d.ts +1 -1
- package/dist/services/app/app-compiler.js +5 -5
- package/dist/services/app/app-compiler.js.map +1 -1
- package/dist/services/app/app-manager.d.ts +25 -1
- package/dist/services/app/app-manager.js +829 -150
- package/dist/services/app/app-manager.js.map +1 -1
- package/dist/services/app/custom-manager.js.map +1 -1
- package/dist/services/app/hermes-agent-manager.js +7 -4
- package/dist/services/app/hermes-agent-manager.js.map +1 -1
- package/dist/services/app/ollama-manager.js +1 -1
- package/dist/services/app/ollama-manager.js.map +1 -1
- package/dist/services/app/openclaw-manager.js +20 -3
- package/dist/services/app/openclaw-manager.js.map +1 -1
- package/dist/services/app/platform-transform.d.ts +32 -0
- package/dist/services/app/platform-transform.js +65 -0
- package/dist/services/app/platform-transform.js.map +1 -0
- package/dist/services/app/provide-resolver.d.ts +29 -0
- package/dist/services/app/provide-resolver.js +112 -0
- package/dist/services/app/provide-resolver.js.map +1 -0
- package/dist/services/app-passwords.d.ts +61 -0
- package/dist/services/app-passwords.js +173 -0
- package/dist/services/app-passwords.js.map +1 -0
- package/dist/services/backup-manager.d.ts +11 -0
- package/dist/services/backup-manager.js +177 -4
- package/dist/services/backup-manager.js.map +1 -1
- package/dist/services/capability-endpoint-validator.d.ts +41 -0
- package/dist/services/capability-endpoint-validator.js +104 -0
- package/dist/services/capability-endpoint-validator.js.map +1 -0
- package/dist/services/capability-health.d.ts +16 -0
- package/dist/services/capability-health.js +121 -0
- package/dist/services/capability-health.js.map +1 -0
- package/dist/services/capability-registry.d.ts +106 -0
- package/dist/services/capability-registry.js +313 -0
- package/dist/services/capability-registry.js.map +1 -0
- package/dist/services/connection-apply.d.ts +91 -0
- package/dist/services/connection-apply.js +475 -0
- package/dist/services/connection-apply.js.map +1 -0
- package/dist/services/connection-resolver.d.ts +65 -0
- package/dist/services/connection-resolver.js +281 -0
- package/dist/services/connection-resolver.js.map +1 -0
- package/dist/services/connection-transactor.d.ts +39 -0
- package/dist/services/connection-transactor.js +351 -0
- package/dist/services/connection-transactor.js.map +1 -0
- package/dist/services/external-mounts.d.ts +40 -0
- package/dist/services/external-mounts.js +187 -0
- package/dist/services/external-mounts.js.map +1 -0
- package/dist/services/files-manager.d.ts +252 -0
- package/dist/services/files-manager.js +1075 -0
- package/dist/services/files-manager.js.map +1 -0
- package/dist/services/files-mounts.d.ts +42 -0
- package/dist/services/files-mounts.js +207 -0
- package/dist/services/files-mounts.js.map +1 -0
- package/dist/services/instance-manager.d.ts +13 -0
- package/dist/services/instance-manager.js +138 -46
- package/dist/services/instance-manager.js.map +1 -1
- package/dist/services/llm-proxy/index.d.ts +16 -2
- package/dist/services/llm-proxy/index.js +48 -44
- package/dist/services/llm-proxy/index.js.map +1 -1
- package/dist/services/llm-proxy/probe.d.ts +6 -0
- package/dist/services/llm-proxy/probe.js +85 -0
- package/dist/services/llm-proxy/probe.js.map +1 -0
- package/dist/services/llm-proxy/ssrf.d.ts +1 -0
- package/dist/services/llm-proxy/ssrf.js +24 -9
- package/dist/services/llm-proxy/ssrf.js.map +1 -1
- package/dist/services/nomad-manager.d.ts +4 -0
- package/dist/services/nomad-manager.js +428 -35
- package/dist/services/nomad-manager.js.map +1 -1
- package/dist/services/organize/applier.d.ts +46 -0
- package/dist/services/organize/applier.js +218 -0
- package/dist/services/organize/applier.js.map +1 -0
- package/dist/services/organize/rules.d.ts +57 -0
- package/dist/services/organize/rules.js +286 -0
- package/dist/services/organize/rules.js.map +1 -0
- package/dist/services/organize/scanner.d.ts +50 -0
- package/dist/services/organize/scanner.js +366 -0
- package/dist/services/organize/scanner.js.map +1 -0
- package/dist/services/organize/store.d.ts +14 -0
- package/dist/services/organize/store.js +82 -0
- package/dist/services/organize/store.js.map +1 -0
- package/dist/services/panel-manager.js +20 -1
- package/dist/services/panel-manager.js.map +1 -1
- package/dist/services/process-manager.js +4 -3
- package/dist/services/process-manager.js.map +1 -1
- package/dist/services/runtime/adapters/hermes.d.ts +30 -1
- package/dist/services/runtime/adapters/hermes.js +219 -6
- package/dist/services/runtime/adapters/hermes.js.map +1 -1
- package/dist/services/runtime/adapters/openclaw-mcporter.d.ts +45 -0
- package/dist/services/runtime/adapters/openclaw-mcporter.js +108 -0
- package/dist/services/runtime/adapters/openclaw-mcporter.js.map +1 -0
- package/dist/services/runtime/adapters/openclaw-routes.d.ts +8 -2
- package/dist/services/runtime/adapters/openclaw-routes.js +68 -0
- package/dist/services/runtime/adapters/openclaw-routes.js.map +1 -1
- package/dist/services/runtime/adapters/openclaw.d.ts +177 -0
- package/dist/services/runtime/adapters/openclaw.js +1171 -11
- package/dist/services/runtime/adapters/openclaw.js.map +1 -1
- package/dist/services/runtime/instance.d.ts +1 -1
- package/dist/services/runtime/instance.js +1 -1
- package/dist/services/runtime/instance.js.map +1 -1
- package/dist/services/runtime/mcp-shims/anythingllm-shim.d.ts +46 -0
- package/dist/services/runtime/mcp-shims/anythingllm-shim.js +281 -0
- package/dist/services/runtime/mcp-shims/anythingllm-shim.js.map +1 -0
- package/dist/services/runtime/mcp-shims/drive-shim.d.ts +54 -0
- package/dist/services/runtime/mcp-shims/drive-shim.js +489 -0
- package/dist/services/runtime/mcp-shims/drive-shim.js.map +1 -0
- package/dist/services/runtime/mcp-shims/firewall.d.ts +26 -0
- package/dist/services/runtime/mcp-shims/firewall.js +129 -0
- package/dist/services/runtime/mcp-shims/firewall.js.map +1 -0
- package/dist/services/runtime/mcp-shims/searxng-shim.d.ts +27 -0
- package/dist/services/runtime/mcp-shims/searxng-shim.js +125 -0
- package/dist/services/runtime/mcp-shims/searxng-shim.js.map +1 -0
- package/dist/services/runtime/mcp-shims/write-mcp-entry.d.ts +83 -0
- package/dist/services/runtime/mcp-shims/write-mcp-entry.js +127 -0
- package/dist/services/runtime/mcp-shims/write-mcp-entry.js.map +1 -0
- package/dist/services/runtime/migrations.d.ts +8 -0
- package/dist/services/runtime/migrations.js +100 -0
- package/dist/services/runtime/migrations.js.map +1 -1
- package/dist/services/runtime/types.d.ts +46 -0
- package/dist/services/setup-manager.js +99 -24
- package/dist/services/setup-manager.js.map +1 -1
- package/dist/services/suggestions.d.ts +27 -0
- package/dist/services/suggestions.js +133 -0
- package/dist/services/suggestions.js.map +1 -0
- package/dist/services/task-registry.js +4 -2
- package/dist/services/task-registry.js.map +1 -1
- package/dist/services/telemetry/device-fingerprint.d.ts +1 -1
- package/dist/services/telemetry/device-fingerprint.js +1 -1
- package/dist/services/types-shim.d.ts +16 -0
- package/dist/services/types-shim.js +2 -0
- package/dist/services/types-shim.js.map +1 -0
- package/dist/services/webdav/server.d.ts +24 -0
- package/dist/services/webdav/server.js +420 -0
- package/dist/services/webdav/server.js.map +1 -0
- package/dist/services/webdav/xml-builder.d.ts +73 -0
- package/dist/services/webdav/xml-builder.js +156 -0
- package/dist/services/webdav/xml-builder.js.map +1 -0
- package/dist/services/workspace-builder.d.ts +29 -0
- package/dist/services/workspace-builder.js +188 -0
- package/dist/services/workspace-builder.js.map +1 -0
- package/dist/types.d.ts +231 -1
- package/dist/utils/instance-lock.d.ts +22 -0
- package/dist/utils/instance-lock.js +48 -0
- package/dist/utils/instance-lock.js.map +1 -0
- package/dist/utils/path-locks.d.ts +30 -0
- package/dist/utils/path-locks.js +63 -0
- package/dist/utils/path-locks.js.map +1 -0
- package/dist/utils/path-safety.d.ts +41 -0
- package/dist/utils/path-safety.js +119 -0
- package/dist/utils/path-safety.js.map +1 -0
- package/dist/utils/safe-json.js +55 -22
- package/dist/utils/safe-json.js.map +1 -1
- package/dist/utils/safe-write.d.ts +24 -0
- package/dist/utils/safe-write.js +82 -0
- package/dist/utils/safe-write.js.map +1 -0
- package/install/jishu-install.sh +323 -27
- package/install/jishu-uninstall.sh +353 -20
- package/package.json +18 -1
- package/public/assets/Dashboard-BdWPtroF.js +1 -0
- package/public/assets/{HermesChatPanel-mFSureyc.js → HermesChatPanel-B_2HlVBQ.js} +1 -1
- package/public/assets/HermesConfigForm-DVlhg3WV.js +4 -0
- package/public/assets/{InitPassword-CVA8wQA6.js → InitPassword-D7glTExX.js} +1 -1
- package/public/assets/InstanceDetail-CxSy2cpe.js +92 -0
- package/public/assets/{Login-BWsZH2mu.js → Login-Cfr5c2sv.js} +1 -1
- package/public/assets/NewInstance-BIYDmJis.js +1 -0
- package/public/assets/ProviderRecommendations-BuRnvRcI.js +1 -0
- package/public/assets/Settings-Cc-tYBil.js +1 -0
- package/public/assets/Setup-lGZEk5jq.js +1 -0
- package/public/assets/{WeixinLoginPanel-CnjR8xMu.js → WeixinLoginPanel-CoGqzxeV.js} +2 -2
- package/public/assets/index-87IJXG-w.css +1 -0
- package/public/assets/index-BZc5zH7u.js +19 -0
- package/public/assets/providers-DtNXh9JD.js +1 -0
- package/public/assets/registry-BWnkJgZ1.js +2 -0
- package/public/assets/{usePolling-Do5Erqm_.js → usePolling-CwwT9KrC.js} +1 -1
- package/public/assets/{vendor-i18n-ucpM0OR0.js → vendor-i18n-y9V7Sfuu.js} +1 -1
- package/public/assets/{vendor-react-Bk1hRGiY.js → vendor-react-BWrEVJVb.js} +6 -6
- package/public/index.html +4 -4
- package/scripts/check-app-spec.mjs +457 -0
- package/scripts/check-i18n.mjs +154 -0
- package/scripts/check-new-file-tests.mjs +230 -0
- package/scripts/check-quarantine-expiry.mjs +105 -0
- package/scripts/perf/README.md +49 -0
- package/scripts/perf/auth.js +99 -0
- package/scripts/perf/config.js +63 -0
- package/scripts/perf/instances.js +143 -0
- package/scripts/perf/proxy.js +96 -0
- package/scripts/run.sh +4 -4
- package/scripts/smoke/files-w1.sh +142 -0
- package/scripts/smoke-backend.mjs +122 -0
- package/scripts/smoke-post-publish.mjs +346 -0
- package/public/assets/Dashboard-B-JoOjBQ.js +0 -1
- package/public/assets/HermesConfigForm-DvR05LK1.js +0 -4
- package/public/assets/InstanceDetail-DcZW2QGO.js +0 -91
- package/public/assets/NewInstance-BCIrAd86.js +0 -1
- package/public/assets/Settings-xkDcduFz.js +0 -1
- package/public/assets/Setup-Cfuwj4gV.js +0 -1
- package/public/assets/index-CPhVFEsx.css +0 -1
- package/public/assets/index-DQsM6Joa.js +0 -19
- package/public/assets/providers-V-vwrExZ.js +0 -1
- package/public/assets/registry-B4UFJdpA.js +0 -2
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DQsM6Joa.js","assets/vendor-react-Bk1hRGiY.js","assets/vendor-i18n-ucpM0OR0.js","assets/index-CPhVFEsx.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{j as e,_ as ds,y as us,z as Rs,A as Os,B as qs,l as Cs,C as Ws,D as Us,E as Ks,F as ms,G as Bs,H as Hs,J as Js,K as zs,M as Gs,N as Qs,O as Ys,P as Xs,k as Zs,Q as Xe,R as It,S as ea,U as ta,V as xs,W as ps,X as hs,Y as fs,Z as sa,$ as aa,a0 as ra,a1 as bs,a2 as gs,a3 as la,a4 as na,a5 as oa,a6 as ia,v as ca,w as da,x as vs,a7 as ua,a8 as ma,a9 as xa,aa as pa,ab as ha,ac as fa,ad as ba}from"./index-DQsM6Joa.js";import{r as i,u as Ss,d as ga}from"./vendor-react-Bk1hRGiY.js";import{S as js,F as le,a as Ze,b as va,d as Ie,I as Ce,C as et,T as ys,c as ja,W as ya,Q as ka}from"./WeixinLoginPanel-CnjR8xMu.js";import{u as wa}from"./usePolling-Do5Erqm_.js";import{P as mt}from"./providers-V-vwrExZ.js";import{u as He,i as Na,T as Ca}from"./vendor-i18n-ucpM0OR0.js";import{R as Sa}from"./registry-B4UFJdpA.js";const Et=["feishu","openclaw-weixin"],Fa={feishu:"feishu",lark:"feishu","openclaw-weixin":"openclaw-weixin"};function Pa({config:a,onChange:f,instanceId:u,isRunning:p=!1,pluginStatuses:t={},onInstallPlugin:o}){var q,se,ne;const{t:x}=He(["instance","common"]),C=(l,h)=>f(Ie(a,l,h)),n=((q=a==null?void 0:a["x-jishushell"])==null?void 0:q.proxy)||{},j=n.upstream||{},b=j.providerId||"",V=mt.find(l=>l.id===b),M=j.models||[],I=V?V.models.map(l=>({id:l.id,name:l.name,contextWindow:l.contextWindow})):M.map(l=>({id:l.id,name:l.name||l.id,contextWindow:l.contextWindow})),R=j.selectedModelId||((se=I[0])==null?void 0:se.id)||"",H=I.find(l=>l.id===R)||I[0]||{},A=M.find(l=>l.id===R)||(H.id?H:{id:"",name:"",contextWindow:0}),Z=n.proxy||{},xe=l=>{var E;const h=mt.find(T=>T.id===l);if(!h||j.apiKey&&!window.confirm(x("configForm.switchProviderConfirm")))return;const y=JSON.parse(JSON.stringify(a));y["x-jishushell"]||(y["x-jishushell"]={}),y["x-jishushell"].proxy||(y["x-jishushell"].proxy={}),y["x-jishushell"].proxy.upstream={providerId:h.id,baseUrl:h.baseUrl,api:h.api,authHeader:h.authHeader===!0,headers:h.headers||{},models:h.models.map(T=>({id:T.id,name:T.name,contextWindow:T.contextWindow})),selectedModelId:((E=h.models[0])==null?void 0:E.id)||"",apiKey:"",hasApiKey:!1,clearApiKey:!1},f(y)},W=l=>{C("x-jishushell.proxy.upstream.selectedModelId",l)},J=(l,h)=>{C(`x-jishushell.proxy.upstream.${l}`,h)},z=(a==null?void 0:a.channels)||{},G=Object.keys(z),de=(l,h,y)=>C(`channels.${l}.${h}`,y),ee={},te=l=>{const h=et.find(T=>T.id===l),y=JSON.parse(JSON.stringify(a));y.channels||(y.channels={});const E=ee[l]||l;if(h){const T={enabled:!0,...h.defaults};h.fields.forEach(je=>{T[je.key]=""}),y.channels[E]=T}else y.channels[E]={enabled:!0};f(y)},fe=l=>{const h=JSON.parse(JSON.stringify(a));delete h.channels[l],f(h)},[ve,g]=i.useState(!1),[N,$]=i.useState(!(j.hasApiKey&&b)),U={"moonshot-coding":"configForm.hint.moonshot-coding",volcengine:"configForm.hint.volcengine",byteplus:"configForm.hint.byteplus",openrouter:"configForm.hint.openrouter",ollama:"configForm.hint.ollama",vllm:"configForm.hint.vllm",sglang:"configForm.hint.sglang"},O=U[b]?x(U[b]):void 0,_=[...new Set(mt.map(l=>l.group))];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(js,{title:x("configForm.modelConfig"),children:[e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-lg p-3 text-sm text-muted",children:[e.jsx("div",{className:"font-medium text-foreground mb-1",children:x("configForm.proxyChain")}),e.jsx("p",{children:x("configForm.proxyChainDesc")}),e.jsxs("div",{className:"mt-2 text-xs text-muted opacity-60 space-y-1",children:[e.jsxs("div",{children:[x("configForm.proxyAddress")," ",e.jsx("span",{className:"font-mono",children:Z.proxyBaseUrl||x("configForm.notConfigured")})]}),e.jsxs("div",{children:[x("configForm.proxyStatus")," ",Z.running?x("configForm.running"):x("configForm.notRunning"),x("configForm.virtualKeyLabel")," ",Z.hasVirtualKey?x("configForm.generated"):x("configForm.notGenerated")]})]})]}),!N&&e.jsx("button",{type:"button",onClick:()=>$(!0),className:"text-xs text-[#0066FF] hover:text-[#0066FF]/80 transition-colors",children:x("configForm.editModelConfig")}),N&&e.jsx(le,{label:x("configForm.upstreamProvider"),hint:x("configForm.upstreamProviderHint"),children:e.jsxs(Ze,{value:b,onChange:xe,children:[e.jsx("option",{value:"",children:x("configForm.selectProvider")}),!V&&b&&e.jsxs("option",{value:b,children:[b," ",x("configForm.custom")]}),_.map(l=>e.jsx("optgroup",{label:x(`configForm.providerGroup.${l}`,{defaultValue:l}),children:mt.filter(h=>h.group===l).map(h=>e.jsx("option",{value:h.id,children:x(`configForm.providerLabel.${h.id}`,{defaultValue:h.label})},h.id))},l))]})}),N&&O&&e.jsxs("div",{className:"flex items-start gap-2 bg-amber-500/10 border border-amber-500/20 rounded-lg px-3 py-2.5 text-xs text-amber-400",children:[e.jsx("span",{className:"shrink-0 mt-0.5",children:"⚠"}),e.jsx("span",{children:O})]}),N&&!["ollama","vllm","sglang"].includes(b)&&b&&e.jsxs(e.Fragment,{children:[e.jsxs(le,{label:x("configForm.upstreamApiKey"),hint:j.hasApiKey&&!j.clearApiKey?x("configForm.apiKeyHintSaved"):x("configForm.apiKeyHintNew"),children:[e.jsx(va,{value:j.apiKey||"",saved:j.hasApiKey&&!j.clearApiKey,onChange:l=>{let h=Ie(a,"x-jishushell.proxy.upstream.apiKey",l);l&&(h=Ie(h,"x-jishushell.proxy.upstream.clearApiKey",!1)),f(h)},placeholder:x("configForm.enterApiKey")}),j.hasApiKey&&e.jsx("button",{type:"button",onClick:()=>{let l=Ie(a,"x-jishushell.proxy.upstream.apiKey","");l=Ie(l,"x-jishushell.proxy.upstream.clearApiKey",!j.clearApiKey),f(l)},className:`mt-2 text-xs ${j.clearApiKey?"text-red-400":"text-muted hover:text-foreground"} transition-colors`,children:j.clearApiKey?x("configForm.markedForClear"):x("configForm.clearSavedApiKey")})]}),I.length>0&&e.jsx(le,{label:x("configForm.upstreamModel"),hint:x("configForm.upstreamModelHint"),children:e.jsx(Ze,{value:R,onChange:W,children:I.map(l=>e.jsxs("option",{value:l.id,children:[l.name," (",Math.round(l.contextWindow/1e3),"K)"]},l.id))})})]}),N&&["ollama","vllm","sglang"].includes(b)&&e.jsxs("div",{className:"space-y-4 border-t border-[var(--border)] pt-4",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(le,{label:"Base URL",hint:x("configForm.localServiceAddress"),children:e.jsx(Ce,{value:j.baseUrl||"",onChange:l=>J("baseUrl",l),placeholder:"http://127.0.0.1:11434",mono:!0})}),e.jsx(le,{label:x("configForm.apiProtocol"),children:e.jsxs(Ze,{value:j.api||"openai-completions",onChange:l=>J("api",l),children:[e.jsx("option",{value:"openai-completions",children:"OpenAI Compatible"}),e.jsx("option",{value:"ollama",children:"Ollama"})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsx(le,{label:x("configForm.modelId"),hint:x("configForm.modelIdHint"),children:e.jsx(Ce,{value:A.id==="default"?"":A.id,onChange:l=>{const h=[...M],y=h.findIndex(T=>T.id===R);y>=0?h[y]={...A,id:l||"default"}:h.push({id:l||"default",name:l||"default",contextWindow:A.contextWindow||0});let E=Ie(a,"x-jishushell.proxy.upstream.models",h);E=Ie(E,"x-jishushell.proxy.upstream.selectedModelId",l||"default"),f(E)},placeholder:"llama3",mono:!0})}),e.jsx(le,{label:x("configForm.modelName"),children:e.jsx(Ce,{value:A.name==="default"?"":A.name||"",onChange:l=>{const h=[...M],y=h.findIndex(E=>E.id===R);y>=0?h[y]={...A,name:l||A.id}:h.push({id:A.id||"default",name:l||"default",contextWindow:A.contextWindow||0}),J("models",h)},placeholder:x("configForm.modelNamePlaceholder")})}),e.jsx(le,{label:x("configForm.contextWindow"),children:e.jsx(Ce,{value:String(A.contextWindow||""),onChange:l=>{const h=[...M],y=h.findIndex(E=>E.id===R);y>=0?h[y]={...A,contextWindow:parseInt(l)||0}:h.push({id:A.id||"default",name:A.name||"default",contextWindow:parseInt(l)||0}),J("models",h)},placeholder:"128000",mono:!0})})]})]}),N&&!["ollama","vllm","sglang"].includes(b)&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>g(!ve),className:"text-xs text-muted hover:text-foreground transition-colors",children:x(ve?"configForm.collapseAdvanced":"configForm.advancedOptions")}),ve&&e.jsxs("div",{className:"space-y-4 border-t border-[var(--border)] pt-4",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(le,{label:x("configForm.upstreamBaseUrl"),children:e.jsx(Ce,{value:j.baseUrl||"",onChange:l=>J("baseUrl",l),placeholder:x("configForm.baseUrlPlaceholder"),mono:!0})}),e.jsx(le,{label:x("configForm.upstreamApiProtocol"),children:e.jsxs(Ze,{value:j.api||"openai-completions",onChange:l=>J("api",l),children:[e.jsx("option",{value:"openai-completions",children:"OpenAI Compatible"}),e.jsx("option",{value:"openai-responses",children:"OpenAI Responses"}),e.jsx("option",{value:"anthropic-messages",children:"Anthropic Messages"}),e.jsx("option",{value:"google-generative-ai",children:"Google Generative AI"}),e.jsx("option",{value:"ollama",children:"Ollama"})]})})]}),b&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsx(le,{label:x("configForm.modelId"),children:e.jsx(Ce,{value:A.id,onChange:l=>{const h=[...M],y=h.findIndex(T=>T.id===R);y>=0?h[y]={...A,id:l}:h.push({...A,id:l});let E=Ie(a,"x-jishushell.proxy.upstream.models",h);E=Ie(E,"x-jishushell.proxy.upstream.selectedModelId",l),f(E)},placeholder:"model-id",mono:!0})}),e.jsx(le,{label:x("configForm.modelName"),children:e.jsx(Ce,{value:A.name||"",onChange:l=>{const h=[...M],y=h.findIndex(E=>E.id===R);y>=0?h[y]={...A,name:l}:h.push({...A,name:l}),J("models",h)},placeholder:"Model Name"})}),e.jsx(le,{label:x("configForm.contextWindow"),children:e.jsx(Ce,{value:String(A.contextWindow||""),onChange:l=>{const h=[...M],y=h.findIndex(E=>E.id===R);y>=0?h[y]={...A,contextWindow:parseInt(l)||0}:h.push({...A,contextWindow:parseInt(l)||0}),J("models",h)},placeholder:"200000",mono:!0})})]}),e.jsx("div",{className:"text-xs text-muted bg-[var(--card)] border border-[var(--border)] rounded-md p-3",children:x("configForm.proxyNote")})]})]})]}),e.jsxs(js,{title:x("configForm.imChannelConfig"),id:"im-channel-section",children:[e.jsx(le,{label:x("configForm.sessionIsolation"),hint:x("configForm.sessionIsolationHint"),children:e.jsxs(Ze,{value:((ne=a==null?void 0:a.session)==null?void 0:ne.dmScope)||"main",onChange:l=>C("session.dmScope",l),children:[e.jsx("option",{value:"main",children:x("configForm.sessionMain")}),e.jsx("option",{value:"per-peer",children:x("configForm.sessionPerPeer")}),e.jsx("option",{value:"per-channel-peer",children:x("configForm.sessionPerChannelPeer")}),e.jsx("option",{value:"per-account-channel-peer",children:x("configForm.sessionPerAccountChannelPeer")})]})}),Et.map(l=>{et.find(B=>B.id===l);const h=x(`configForm.channel.${l}`,{defaultValue:l}),y=z[l]||{enabled:!0},E=y.enabled!==!1,T=Fa[l]||l,je=t[T],F=l==="openclaw-weixin"?"#07C160":"#3370FF";return e.jsxs("div",{className:"border border-[var(--border)] rounded-lg p-4 space-y-3 bg-[var(--card)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:h}),e.jsx("span",{className:"text-[11px] text-muted font-mono",children:l})]}),e.jsx(ys,{checked:E,onChange:B=>{z[l]||te(l),de(l,"enabled",B)},label:x(E?"common:label.enabled":"common:label.disabled")})]}),E&&(je==="installing"?e.jsx("div",{className:"rounded-md px-4 py-3",style:{background:`${F}10`,borderColor:`${F}30`,borderWidth:1,borderStyle:"solid"},children:e.jsxs("div",{className:"flex items-center gap-2 text-sm",style:{color:F},children:[e.jsx("div",{className:"w-4 h-4 border-2 rounded-full animate-spin",style:{borderColor:`${F}30`,borderTopColor:F}}),e.jsx("span",{children:x("configForm.pluginInstalling",{label:h})})]})}):je!=="installed"?e.jsxs("div",{className:"rounded-md px-4 py-3",style:{background:`${F}08`,borderColor:`${F}30`,borderWidth:1,borderStyle:"dashed"},children:[e.jsx("button",{onClick:()=>o==null?void 0:o(T),className:"px-4 py-2 text-white rounded-md text-xs font-medium hover:opacity-90 transition-opacity",style:{background:F},children:x("configForm.installPlugin",{label:h})}),e.jsx("p",{className:"text-xs text-muted mt-2",children:x("configForm.installPluginHint",{label:h})})]}):e.jsxs(e.Fragment,{children:[(l==="feishu"||l==="lark")&&e.jsx(ja,{instanceId:u,channelKey:l,existingAppId:y.appId,existingDomain:y.domain||l,onConfigured:()=>{u&&ds(async()=>{const{getConfig:B}=await import("./index-DQsM6Joa.js").then(Q=>Q.aB);return{getConfig:B}},__vite__mapDeps([0,1,2,3])).then(({getConfig:B})=>{B(u).then(Q=>{Q&&f(Q)})})}}),l==="openclaw-weixin"&&e.jsx(ya,{instanceId:u,onConfigured:()=>{u&&ds(async()=>{const{getConfig:B}=await import("./index-DQsM6Joa.js").then(Q=>Q.aB);return{getConfig:B}},__vite__mapDeps([0,1,2,3])).then(({getConfig:B})=>{B(u).then(Q=>{Q&&f(Q)})})}})]}))]},l)}),G.filter(l=>!Et.includes(l)).map(l=>{const h=z[l],y=et.find(F=>F.id===l),E=x(`configForm.channel.${l}`,{defaultValue:l}),T=(y==null?void 0:y.fields)||[],je=y?[]:Object.keys(h).filter(F=>F!=="enabled"&&typeof h[F]=="string");return e.jsxs("div",{className:"border border-[var(--border)] rounded-lg p-4 space-y-3 bg-[var(--card)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:E}),y&&e.jsx("span",{className:"text-[11px] text-muted font-mono",children:l})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ys,{checked:h.enabled!==!1,onChange:F=>de(l,"enabled",F),label:h.enabled!==!1?x("common:label.enabled"):x("common:label.disabled")}),e.jsx("button",{onClick:()=>fe(l),className:"text-xs text-red-400 hover:text-red-300 transition-colors",children:x("configForm.remove")})]})]}),h.enabled!==!1&&T.length>0&&e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:T.map(F=>e.jsx(le,{label:F.label,children:e.jsx(Ce,{value:h[F.key]||"",onChange:B=>de(l,F.key,B),placeholder:F.placeholder,type:F.type||"text",mono:!0})},F.key))}),h.enabled!==!1&&je.length>0&&e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:je.map(F=>e.jsx(le,{label:F,children:e.jsx(Ce,{value:h[F]||"",onChange:B=>de(l,F,B),placeholder:F,type:F.toLowerCase().includes("secret")||F.toLowerCase().includes("token")||F.toLowerCase().includes("password")?"password":"text",mono:!0})},F))}),h.enabled!==!1&&l==="whatsapp"&&T.length===0&&e.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/20 rounded-md px-3 py-2 text-xs text-amber-400",children:[e.jsx("p",{className:"font-medium mb-1",children:x("configForm.whatsappTitle")}),e.jsx("p",{children:x("configForm.whatsappHint")})]})]},l)}),e.jsxs("div",{className:"pt-2",children:[e.jsx("p",{className:"text-xs text-muted mb-2",children:x("configForm.addImChannel")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:et.filter(l=>{if(Et.includes(l.id))return!1;const h=ee[l.id]||l.id;return!G.includes(h)&&!G.includes(l.id)}).map(l=>e.jsxs("button",{onClick:()=>te(l.id),className:"px-3 py-1.5 text-xs border border-dashed rounded-md transition-colors duration-150 border-[var(--border)] text-muted hover:border-[var(--border-hover)] hover:text-foreground",children:["+ ",x(l.labelKey,{defaultValue:l.id})]},l.id))})]})]})]})}const Ia="im",Ea="即时通讯",Aa="💬",Ma=[{id:"feishu",label:"飞书 / Lark",desc:"飞书机器人(WebSocket 模式)"},{id:"openclaw-weixin",label:"微信",desc:"微信扫码接入"}],$a={id:Ia,label:Ea,emoji:Aa,items:Ma},_a="skills",Va="常用 Skill",Da="⚡",Ta=[{id:"hubs",label:"热门Hub",emoji:"🌐",skills:[{id:"clawhub",type:"hub",label:"ClawHub",desc:"OpenClaw 官方 Skill 市场",url:"https://clawhub.ai/",installMsg:""},{id:"skillhub-tencent",type:"hub",label:"腾讯 SkillHub",desc:"腾讯技能中心,官方出品",url:"https://skillhub.tencent.com/",installMsg:""},{id:"skills-sh",type:"hub",label:"Skills.sh",desc:"第三方 Skill 聚合社区",url:"https://skills.sh/",installMsg:""},{id:"lobehub-skills",type:"hub",label:"LobeHub Skills",desc:"LobeHub 社区 Skill 市场",url:"https://lobehub.com/skills",installMsg:""},{id:"findskills",type:"hub",label:"FindSkills.org",desc:"开源 Skill 搜索与聚合平台",url:"https://www.findskills.org/",installMsg:""},{id:"playbooks-skills",type:"hub",label:"Playbooks Skills",desc:"Playbooks 社区 Skill 目录",url:"https://playbooks.com/skills",installMsg:""}]},{id:"general",label:"通用基础",emoji:"🧠",skills:[{id:"skill-vetter",label:"Skill Vetter",desc:"安全审计 Skill,安装前建议先审查",installMsg:"根据以下链接安装skill:https://clawhub.ai/spclaudehome/skill-vetter",autoInstall:!0,slashCmd:"/skill-vetter",checkDirs:["skill-vetter","Skill Vetter","SkillVetter","vetter"]},{id:"self-improving-agent-cn",label:"Self-Improving CN Agent",desc:"自我优化的 Agent,持续改进任务执行",installMsg:"根据以下链接安装skill:https://clawhub.ai/zhengxinjipai/self-improving-agent-cn",autoInstall:!0,slashCmd:"/self-improving-agent-cn",checkDirs:["self-improving-agent-cn","SelfImprovingAgentCn","self_improving_agent_cn"]},{id:"proactive-agent",label:"Proactive Agent",desc:"主动式 Agent,自动感知并提前完成任务",installMsg:"根据以下链接安装skill:https://clawhub.ai/bestrocky/proactive-agent-lite",autoInstall:!0,slashCmd:"/proactive-agent",checkDirs:["proactive-agent-lite","proactive-agent","ProactiveAgent","proactive_agent"]},{id:"multi-search-engine",label:"Multi Search Engine",desc:"多搜索引擎聚合搜索",installMsg:"根据以下链接安装skill:https://clawhub.ai/gpyangyoujun/multi-search-engine",autoInstall:!0,slashCmd:"/multi-search-engine",checkDirs:["multi-search-engine","MultiSearchEngine","multi_search_engine"]},{id:"exa-web-search-free",label:"Exa Web Search Free",desc:"免费 Exa 网页语义搜索",installMsg:"根据以下链接安装skill:https://clawhub.ai/whiteknight07/exa-web-search-free",autoInstall:!0,slashCmd:"/exa-web-search-free",checkDirs:["exa-web-search-free","ExaWebSearchFree","exa_web_search_free"]},{id:"filesystem",label:"Filesystem",desc:"本地文件系统读写与管理",installMsg:"根据以下链接安装skill:https://clawhub.ai/steipete/filesystem",autoInstall:!0,slashCmd:"/filesystem",checkDirs:["filesystem","steipete-filesystem"]},{id:"summarize",label:"Summarize",desc:"内容摘要与总结提炼",installMsg:"根据以下链接安装skill:https://clawhub.ai/steipete/summarize",autoInstall:!0,slashCmd:"/summarize",checkDirs:["summarize","steipete-summarize"]},{id:"baidu-search",label:"百度搜索",desc:"百度搜索引擎集成",installMsg:"根据以下链接安装skill:https://clawhub.ai/ide-rea/baidu-search",autoInstall:!0,slashCmd:"/baidu-search",checkDirs:["baidu-search","BaiduSearch"]},{id:"agent-browser-clawdbot",label:"Agent Browser",desc:"AI 驱动的网页浏览与自动化操作",installMsg:"根据以下链接安装skill:https://clawhub.ai/matrixy/agent-browser-clawdbot",autoInstall:!0,slashCmd:"/agent-browser-clawdbot",checkDirs:["agent-browser-clawdbot","agent-browser","AgentBrowser"]},{id:"automation-workflows",label:"Automation Workflows",desc:"自动化工作流编排与执行",installMsg:"根据以下链接安装skill:https://clawhub.ai/jk-0001/automation-workflows",autoInstall:!0,slashCmd:"/automation-workflows",checkDirs:["automation-workflows","AutomationWorkflows"]},{id:"evolver",label:"Evolver",desc:"Agent 自动进化与能力迭代",installMsg:"根据以下链接安装skill:https://clawhub.ai/autogame-17/evolver",autoInstall:!0,slashCmd:"/evolver",checkDirs:["evolver","autogame-evolver"]}]},{id:"productivity",label:"工作效率",emoji:"💼",skills:[{id:"pdf-reader",label:"PDF Reader",desc:"PDF 文档读取与分析",installMsg:"根据以下链接安装skill:https://clawhub.ai/awspace/pdf",autoInstall:!0,slashCmd:"/pdf",checkDirs:["pdf","pdf-reader","awspace-pdf"]},{id:"powerpoint-pptx",label:"PowerPoint / PPTX",desc:"PPT 演示文稿生成与编辑",installMsg:"根据以下链接安装skill:https://clawhub.ai/ivangdavila/powerpoint-pptx",autoInstall:!0,slashCmd:"/powerpoint-pptx",checkDirs:["powerpoint-pptx","powerpoint","pptx"]},{id:"word-docx",label:"Word / DOCX",desc:"Word 文档生成与编辑",installMsg:"根据以下链接安装skill:https://clawhub.ai/ivangdavila/word-docx",autoInstall:!0,slashCmd:"/word-docx",checkDirs:["word-docx","word","docx"]},{id:"excel-xlsx",label:"Excel / XLSX",desc:"Excel 表格生成与数据处理",installMsg:"根据以下链接安装skill:https://clawhub.ai/ivangdavila/excel-xlsx",autoInstall:!0,slashCmd:"/excel-xlsx",checkDirs:["excel-xlsx","excel","xlsx"]},{id:"ai-ppt-generator",label:"AI PPT Generator",desc:"AI 自动生成 PPT 演示文稿",installMsg:"根据以下链接安装skill:https://clawhub.ai/ide-rea/ai-ppt-generator",autoInstall:!0,slashCmd:"/ai-ppt-generator",checkDirs:["ai-ppt-generator","AiPptGenerator"]},{id:"nano-banana-pro",label:"Nano Banana Pro",desc:"轻量高效的任务执行与流程优化",installMsg:"根据以下链接安装skill:https://clawhub.ai/steipete/nano-banana-pro",autoInstall:!0,slashCmd:"/nano-banana-pro",checkDirs:["nano-banana-pro","NanoBananaPro"]},{id:"ppt-generator",label:"PPT Generator",desc:"PPT 演示文稿智能生成",installMsg:"根据以下链接安装skill:https://clawhub.ai/wwlyzzyorg/ppt-generator",autoInstall:!0,slashCmd:"/ppt-generator",checkDirs:["ppt-generator","PptGenerator"]},{id:"marketing-mode",label:"Marketing Mode",desc:"营销文案与推广内容创作",installMsg:"根据以下链接安装skill:https://clawhub.ai/thesethrose/marketing-mode",autoInstall:!0,slashCmd:"/marketing-mode",checkDirs:["marketing-mode","MarketingMode"]},{id:"data-analysis",label:"Data Analysis",desc:"数据分析与可视化报告生成",installMsg:"根据以下链接安装skill:https://clawhub.ai/ivangdavila/data-analysis",autoInstall:!0,slashCmd:"/data-analysis",checkDirs:["data-analysis","DataAnalysis"]}]},{id:"life",label:"生活辅助",emoji:"🏠",skills:[{id:"todo-manager",label:"Todo Manager",desc:"任务与待办事项管理",installMsg:"根据以下链接安装skill:https://clawhub.ai/aeoleader/todo-manager",autoInstall:!0,slashCmd:"/todo-manager",checkDirs:["todo-manager","todo","TodoManager"]},{id:"12306",label:"12306 火车票",desc:"查询与购买 12306 火车票",installMsg:"根据以下链接安装skill:https://clawhub.ai/kirorab/12306",autoInstall:!0,slashCmd:"/12306",checkDirs:["12306","kirorab-12306"]},{id:"youtube-watcher",label:"YouTube Watcher",desc:"YouTube 视频摘要与内容分析",installMsg:"根据以下链接安装skill:https://clawhub.ai/michaelgathara/youtube-watcher",autoInstall:!0,slashCmd:"/youtube-watcher",checkDirs:["youtube-watcher","youtube","YoutubeWatcher"]},{id:"xiaohongshu-cn",label:"小红书助手",desc:"小红书内容创作与运营辅助",installMsg:"根据以下链接安装skill:https://clawhub.ai/guohongbin-git/xiaohongshu-cn",autoInstall:!0,slashCmd:"/xiaohongshu-cn",checkDirs:["xiaohongshu-cn","xiaohongshu","XiaohongshuCn"]},{id:"wechat-mp-cn",label:"微信公众号助手",desc:"微信公众号内容创作与发布辅助",installMsg:"根据以下链接安装skill:https://clawhub.ai/guohongbin-git/wechat-mp-cn",autoInstall:!0,slashCmd:"/wechat-mp-cn",checkDirs:["wechat-mp-cn","wechat-mp","WechatMpCn"]},{id:"weather",label:"Weather",desc:"实时天气查询与预报",installMsg:"根据以下链接安装skill:https://clawhub.ai/steipete/weather",autoInstall:!0,slashCmd:"/weather",checkDirs:["weather","steipete-weather"]},{id:"stock-analysis",label:"Stock Analysis",desc:"股票行情分析与投资参考",installMsg:"根据以下链接安装skill:https://clawhub.ai/udiedrichsen/stock-analysis",autoInstall:!0,slashCmd:"/stock-analysis",checkDirs:["stock-analysis","StockAnalysis"]},{id:"news-summary",label:"News Summary",desc:"新闻资讯聚合与摘要生成",installMsg:"根据以下链接安装skill:https://clawhub.ai/joargp/news-summary",autoInstall:!0,slashCmd:"/news-summary",checkDirs:["news-summary","NewsSummary"]}]},{id:"dev",label:"开发工具",emoji:"🛠️",skills:[{id:"github",label:"GitHub",desc:"GitHub 仓库管理与代码协作",installMsg:"根据以下链接安装skill:https://clawhub.ai/steipete/github",autoInstall:!0,slashCmd:"/github",checkDirs:["github","GitHub","steipete-github"]},{id:"gemini",label:"Gemini",desc:"Google Gemini 模型接入与调用",installMsg:"根据以下链接安装skill:https://clawhub.ai/steipete/gemini",autoInstall:!0,slashCmd:"/gemini",checkDirs:["gemini","Gemini","steipete-gemini"]},{id:"api-gateway",label:"API Gateway",desc:"API 接口管理与请求代理",installMsg:"根据以下链接安装skill:https://clawhub.ai/byungkyu/api-gateway",autoInstall:!0,slashCmd:"/api-gateway",checkDirs:["api-gateway","ApiGateway"]},{id:"mcporter",label:"MCPorter",desc:"MCP 服务器管理工具",installMsg:"根据以下链接安装skill:https://clawhub.ai/steipete/mcporter",autoInstall:!0,slashCmd:"/mcporter",checkDirs:["mcporter","MCPorter","steipete-mcporter"]},{id:"session-logs",label:"Session Logs",desc:"会话日志记录与回放分析",installMsg:"根据以下链接安装skill:https://clawhub.ai/guogang1024/session-logs",autoInstall:!0,slashCmd:"/session-logs",checkDirs:["session-logs","SessionLogs"]}]}],xt={id:_a,label:Va,emoji:Da,groups:Ta},La="mcp",Ra="常用 MCP",Oa="🔌",qa=[{id:"12306-mcp",label:"12306-MCP车票查询工具",desc:"12306-MCP车票查询工具",mcpJson:{"12306-mcp":{command:"npx",args:["-y","12306-mcp"]}}},{id:"bing-search",label:"Bing 搜索",desc:"必应搜索引擎 MCP 接入",mcpJson:{"bing-search":{command:"npx",args:["-y","bing-cn-mcp"]}}},{id:"fxbaogao-mcp",label:"发现报告",desc:"发现报告研究报告检索与阅读",mcpJson:{"fxbaogao-mcp":{command:"uvx",args:["fxbaogao-mcp@latest"]}}}],Wa={id:La,label:Ra,emoji:Oa,items:qa},Ua="slash",Ka="常用 /命令",Ba="/",Ha=[{label:"会话",items:[{id:"slash-new",label:"/new",desc:"开启新会话",cmd:"/new",send:!0},{id:"slash-reset",label:"/reset",desc:"重置当前会话",cmd:"/reset",send:!0},{id:"slash-compact",label:"/compact",desc:"压缩会话上下文",cmd:"/compact",send:!0},{id:"slash-stop",label:"/stop",desc:"停止当前运行",cmd:"/stop",send:!0},{id:"slash-clear",label:"/clear",desc:"清空聊天记录",cmd:"/clear",send:!0},{id:"slash-focus",label:"/focus",desc:"切换专注模式",cmd:"/focus",send:!0}]},{label:"模型",items:[{id:"slash-model",label:"/model <name>",desc:"查看或切换模型",cmd:"/model ",send:!1},{id:"slash-think",label:"/think <level>",desc:"设置思考深度",cmd:"/think ",send:!1},{id:"slash-verbose",label:"/verbose <on|off|full>",desc:"切换详细输出模式",cmd:"/verbose ",send:!1},{id:"slash-fast",label:"/fast <status|on|off>",desc:"切换快速模式",cmd:"/fast ",send:!1}]},{label:"工具",items:[{id:"slash-help",label:"/help",desc:"查看可用命令",cmd:"/help",send:!0},{id:"slash-status",label:"/status",desc:"显示会话状态(agent)",cmd:"/status",send:!0},{id:"slash-export",label:"/export",desc:"导出会话为 Markdown",cmd:"/export",send:!0},{id:"slash-usage",label:"/usage",desc:"显示 Token 用量",cmd:"/usage",send:!0}]}],Ja={id:Ua,label:Ka,emoji:Ba,groups:Ha};function za({gatewayLaunchUrl:a,gatewayReady:f,isRunning:u,isPending:p,iframeLoaded:t,actionLoading:o,onAction:x,onReload:C,onIframeLoad:n}){const{t:j}=He("instance");return e.jsx("div",{className:"overflow-hidden rounded-[22px] border border-[var(--border)] bg-[var(--card)] shadow-[0_18px_48px_rgba(15,23,42,0.06)]",children:e.jsxs("div",{className:"relative",style:{height:"calc(100vh - 160px)",minHeight:"500px"},children:[(!u||!f||!t)&&e.jsx("div",{className:`absolute inset-0 w-full h-full bg-[var(--card)] flex flex-col items-center justify-center z-10 transition-opacity duration-300 ${t?"opacity-0 pointer-events-none":"opacity-100"}`,children:u?f?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-5 h-5 border-2 border-[#0066FF]/30 border-t-[#0066FF] rounded-full animate-spin mb-3"}),e.jsx("div",{className:"text-sm text-foreground/60",children:j("chat.loadingChat")})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-5 h-5 border-2 border-[#0066FF]/30 border-t-[#0066FF] rounded-full animate-spin mb-3"}),e.jsx("div",{className:"text-sm text-foreground/60",children:j("chat.waitingGateway")})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-4xl mb-4 opacity-40",children:"💬"}),e.jsx("div",{className:"text-sm text-foreground/60 font-medium mb-1",children:j("chat.notReady")}),e.jsx("div",{className:"text-xs text-muted mb-4",children:j("chat.startHint")}),e.jsx("button",{onClick:()=>x("start"),disabled:!!o||p,className:"px-4 py-2 bg-[#0066FF] text-white rounded-md text-xs font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:j(o==="start"||p?"action.starting":"chat.startInstance")})]})}),f&&a&&e.jsx("iframe",{id:"gateway-iframe",src:a,className:"w-full h-full",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads allow-modals",allow:"microphone; camera; clipboard-write",onLoad:n})]})})}function Ga(a){return!a||typeof a!="object"?[]:Object.entries(a).map(([f,u])=>({group:f,items:Array.isArray(u)?u.map(p=>typeof p=="string"?{cmd:p,label:p}:!p||typeof p!="object"||typeof p.cmd!="string"||!p.cmd.trim()?null:{cmd:p.cmd.trim(),label:typeof p.label=="string"&&p.label.trim()?p.label.trim():p.cmd.trim(),description:typeof p.description=="string"&&p.description.trim()?p.description.trim():void 0}).filter(p=>!!p):[]})).filter(f=>f.items.length>0)}function Qa({instanceId:a,provide:f,isRunning:u}){var te,fe,ve;const[p,t]=i.useState(""),[o,x]=i.useState(((fe=(te=f.terminal)==null?void 0:te.prompt)==null?void 0:fe.trim())||"shell"),[C,n]=i.useState(null),[j,b]=i.useState(!1),[V,M]=i.useState(()=>{var $,U;const g=[],N=(U=($=f.terminal)==null?void 0:$.welcome)==null?void 0:U.trim();return N&&g.push({id:1,kind:"status",text:N}),g}),I=i.useRef(null),R=i.useRef(null),H=i.useRef(V.length+1),A=i.useRef(0),Z=i.useRef(null),xe=i.useMemo(()=>{var g;return Ga((g=f.terminal)==null?void 0:g.commands)},[(ve=f.terminal)==null?void 0:ve.commands]),W=(g,N,$=!1)=>{const U=N.trimEnd();U.trim()&&M(O=>{if($&&O.length>0){const _=O[O.length-1];if(_.kind===g){const q=[...O];return q[q.length-1]={..._,text:U},q}}return[...O,{id:H.current++,kind:g,text:U}]})},J=()=>{var g;(g=I.current)==null||g.close(),I.current=null},z=g=>{J();const N=`/api/instances/${encodeURIComponent(a)}/provides/${encodeURIComponent(f.capability)}/terminal/session/${encodeURIComponent(g)}/stream?since=${A.current}`,$=new EventSource(N);I.current=$;const U=O=>_=>{try{const q=JSON.parse(_.data);typeof(q==null?void 0:q.seq)=="number"&&(A.current=Math.max(A.current,q.seq)),typeof(q==null?void 0:q.text)=="string"&&q.text&&W(O,q.text,(q==null?void 0:q.replace)===!0)}catch{typeof _.data=="string"&&_.data&&W(O,_.data)}};$.addEventListener("stdout",U("stdout")),$.addEventListener("stderr",U("stderr")),$.addEventListener("error",O=>{const _=O instanceof MessageEvent?O.data:"";typeof _=="string"&&_&&W("stderr",_),n(null),R.current=null,J()}),$.addEventListener("exit",O=>{try{const _=JSON.parse(O.data);typeof(_==null?void 0:_.seq)=="number"&&(A.current=Math.max(A.current,_.seq)),W("status",`process exited with code ${(_==null?void 0:_.exitCode)??"unknown"}`)}catch{W("status","process exited")}n(null),R.current=null,J()}),$.addEventListener("done",()=>{n(null),R.current=null,J()})},G=async g=>{const N=g.trim();if(!(!N||j||!u)){b(!0);try{W("cmd",`${o}> ${N}`);const $=await Rs(a,f.capability,{input:N});x($.prompt||o),n($.sessionId),R.current=$.sessionId,A.current=0,z($.sessionId),t("")}catch($){W("stderr",($==null?void 0:$.message)||"failed to start terminal session")}finally{b(!1)}}},de=async()=>{const g=p.trim();if(!(j||!u)){if(!C){await G(g);return}b(!0);try{W("cmd",`${o}> ${g}`),await Os(a,f.capability,C,{input:g}),t("")}catch(N){W("stderr",(N==null?void 0:N.message)||"failed to send terminal input")}finally{b(!1)}}},ee=async()=>{if(!(!C||j)){b(!0);try{await us(a,f.capability,C),W("status","session stopped")}catch(g){W("stderr",(g==null?void 0:g.message)||"failed to stop terminal session")}finally{b(!1)}}};return i.useEffect(()=>{const g=Z.current;if(g){if(typeof g.scrollTo=="function"){g.scrollTo({top:g.scrollHeight});return}g.scrollTop=g.scrollHeight}},[V]),i.useEffect(()=>()=>{const g=R.current;J(),g&&us(a,f.capability,g).catch(()=>{})},[a,f.capability]),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[280px_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"rounded-[22px] border border-[var(--border)] bg-[var(--card)] p-4",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Ollama Commands"}),e.jsx("div",{className:"mt-1 text-xs text-muted",children:"点击左侧命令会自动写入终端并执行。"})]}),e.jsx("div",{className:"space-y-4",children:xe.map(g=>e.jsxs("section",{children:[e.jsx("div",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-foreground/55",children:g.group}),e.jsx("div",{className:"space-y-2",children:g.items.map(N=>e.jsxs("button",{type:"button",disabled:!u||!!C||j,onClick:()=>{t(N.cmd),G(N.cmd)},className:"w-full rounded-2xl border border-[var(--border)] bg-black/[0.03] px-3 py-2 text-left transition hover:border-[#0066FF]/35 hover:bg-[#0066FF]/[0.04] disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx("div",{className:"font-mono text-xs text-foreground",children:N.label}),N.description&&e.jsx("div",{className:"mt-1 text-[11px] leading-5 text-muted",children:N.description})]},`${g.group}:${N.cmd}`))})]},g.group))})]}),e.jsxs("section",{className:"rounded-[22px] border border-[var(--border)] bg-[#09111f] text-[#d7e3ff] shadow-[0_18px_60px_rgba(4,12,24,0.28)]",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-white/10 px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-white",children:f.description||"Ollama Terminal"}),e.jsx("div",{className:"mt-1 text-xs text-[#9cb3d9]",children:"支持直接输入 `ollama` 子命令;输入 `ollama list` 或 `list` 都可以。"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[#9cb3d9]",children:[e.jsx("span",{className:`inline-flex h-2.5 w-2.5 rounded-full ${u?"bg-[#39d98a]":"bg-[#ff6b6b]"}`}),e.jsx("span",{children:u?C?"session running":"ready":"service stopped"}),e.jsx("button",{type:"button",onClick:()=>void ee(),disabled:!C||j,className:"rounded-full border border-white/15 px-3 py-1 text-[11px] uppercase tracking-[0.16em] text-white transition hover:border-white/35 disabled:cursor-not-allowed disabled:opacity-45",children:"Stop"})]})]}),e.jsx("div",{ref:Z,className:"h-[520px] overflow-y-auto px-4 py-4 font-mono text-sm leading-6",children:V.length===0?e.jsxs("div",{className:"text-[#9cb3d9]",children:[o,"> 输入 `list`、`ps`、`pull gemma4:e4b` 或 `run gemma4:e2b` 开始。"]}):V.map(g=>e.jsx("div",{className:g.kind==="stderr"?"whitespace-pre-wrap text-[#ff9c9c]":g.kind==="cmd"?"whitespace-pre-wrap text-[#7fd0ff]":g.kind==="status"?"whitespace-pre-wrap text-[#9cb3d9]":"whitespace-pre-wrap text-[#d7e3ff]",children:g.text},g.id))}),e.jsxs("div",{className:"border-t border-white/10 px-4 py-4",children:[!u&&e.jsx("div",{className:"mb-3 rounded-2xl border border-[#ff6b6b]/25 bg-[#ff6b6b]/10 px-3 py-2 text-sm text-[#ffc2c2]",children:"当前实例未运行,先启动 Ollama 服务后才能执行命令。"}),e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 rounded-2xl border border-white/10 bg-black/20 px-3 py-2",children:[e.jsx("div",{className:"mb-1 text-[11px] uppercase tracking-[0.18em] text-[#7f97c2]",children:C?"stdin":"command"}),e.jsx("textarea",{value:p,onChange:g=>t(g.target.value),onKeyDown:g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),de())},rows:C?2:1,disabled:!u||j,placeholder:C?"向当前 ollama 会话发送一行输入":"例如:list / pull qwen3.6:35b / run gemma4:e2b",className:"w-full resize-none border-0 bg-transparent p-0 font-mono text-sm text-[#e8f0ff] outline-none placeholder:text-[#7188b2]"})]}),e.jsx("button",{type:"button",onClick:()=>void de(),disabled:!u||j||!p.trim(),className:"rounded-2xl bg-[#0066FF] px-4 py-3 text-sm font-semibold text-white transition hover:bg-[#0052cc] disabled:cursor-not-allowed disabled:opacity-50",children:C?"Send":"Run"})]})]})]})]})}function Ya({logs:a,logSearch:f,logType:u,logsEndRef:p,onSearchChange:t,onLogTypeChange:o,onRefresh:x,onCopy:C}){const{t:n}=He("instance"),j=f?a.filter(b=>b.toLowerCase().includes(f.toLowerCase())):a;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(qs,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted"}),e.jsx("input",{type:"text",value:f,onChange:b=>t(b.target.value),placeholder:n("logs.searchPlaceholder"),className:"w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md pl-9 pr-3 py-1.5 text-sm text-foreground placeholder-[var(--muted)] focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60 focus:border-[#0066FF]/60 transition-colors"})]}),e.jsx("div",{className:"flex items-center gap-1",children:["stderr","stdout"].map(b=>e.jsx("button",{onClick:()=>o(b),className:`px-2.5 py-1.5 text-xs rounded-md transition-colors duration-150 ${u===b?"bg-[#0066FF] text-white":"text-muted hover:bg-[var(--card-hover)]"}`,children:b},b))}),e.jsx("button",{onClick:x,className:"p-1.5 border border-[var(--border)] rounded-md text-muted hover:text-foreground hover:bg-[var(--card-hover)] transition-colors",title:n("common:action.refresh"),children:e.jsx(Cs,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:C,className:"p-1.5 border border-[var(--border)] rounded-md text-muted hover:text-foreground hover:bg-[var(--card-hover)] transition-colors",title:n("common:action.copyAll"),children:e.jsx(Ws,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"bg-black/60 border border-[var(--border)] rounded-xl font-mono text-[13px] p-4 min-h-[400px] lg:min-h-[500px] overflow-auto max-h-[70vh]",children:[j.length===0?e.jsx("p",{className:"text-muted",children:n("logs.empty")}):j.map((b,V)=>{const M=/error|ERR|panic|fatal/i.test(b),I=/warn|WARN/i.test(b);return e.jsx("div",{className:`whitespace-pre-wrap break-all leading-5 ${M?"text-red-400 bg-red-950/20":I?"text-amber-400":"text-foreground opacity-70"}`,children:b},`${V}-${b.slice(0,32)}`)}),e.jsx("div",{ref:p})]})]})}function Xa({usage:a,onRefresh:f}){const{t:u}=He("instance");if(!a)return e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[1,2,3].map(t=>e.jsx("div",{className:"h-20 bg-[var(--card)] rounded-lg"},t))}),e.jsx("div",{className:"h-60 bg-[var(--card)] rounded-lg"})]})});const p=Na.language==="zh"?"zh-CN":"en-US";return e.jsxs("div",{className:"space-y-4",children:[a.totals.totalTokens===0&&a.totals.messages>0&&e.jsx("div",{className:"bg-[var(--card)] border border-[var(--border)] text-muted text-sm rounded-lg px-4 py-3",children:u("usage.noTokenData")}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-3",children:[{label:u("usage.messages"),value:a.totals.messages.toLocaleString()},{label:u("usage.totalTokens"),value:a.totals.totalTokens.toLocaleString()},{label:u("usage.totalCost"),value:`$${a.totals.costTotal.toFixed(4)}`}].map(t=>e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl p-4 hover:border-[var(--border-hover)] transition-colors",children:[e.jsx("div",{className:"text-xs text-muted mb-1",children:t.label}),e.jsx("div",{className:"text-2xl font-semibold text-foreground",children:t.value})]},t.label))}),e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-[var(--border)] flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium text-foreground",children:[u("usage.sessions")," (",a.sessions.length,")"]}),e.jsx("button",{onClick:f,className:"text-xs text-muted hover:text-foreground transition-colors",children:u("common:action.refresh")})]}),a.sessions.length===0?e.jsx("p",{className:"text-muted text-sm p-4",children:u("usage.noSessions")}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted border-b border-[var(--border)]",children:[e.jsx("th",{className:"text-left font-medium px-4 py-2",children:u("usage.time")}),e.jsx("th",{className:"text-left font-medium px-4 py-2",children:u("usage.model")}),e.jsx("th",{className:"text-left font-medium px-4 py-2",children:u("usage.source")}),e.jsx("th",{className:"text-right font-medium px-4 py-2",children:u("usage.messagesShort")}),e.jsx("th",{className:"text-right font-medium px-4 py-2",children:u("usage.input")}),e.jsx("th",{className:"text-right font-medium px-4 py-2",children:u("usage.output")}),e.jsx("th",{className:"text-right font-medium px-4 py-2",children:u("usage.tokens")}),e.jsx("th",{className:"text-right font-medium px-4 py-2",children:u("usage.cost")})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border)]",children:a.sessions.map(t=>e.jsxs("tr",{className:"hover:bg-[var(--card-hover)] transition-colors",children:[e.jsx("td",{className:"px-4 py-2 text-muted whitespace-nowrap",children:t.lastMessage?new Date(t.lastMessage).toLocaleString(p,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"-"}),e.jsx("td",{className:"px-4 py-2 font-mono text-xs text-muted",children:t.model||"-"}),e.jsxs("td",{className:"px-4 py-2 text-muted",children:[t.channel&&e.jsx("span",{className:"inline-block bg-[var(--card-hover)] text-muted text-[11px] px-1.5 py-0.5 rounded mr-1 font-medium",children:t.channel}),e.jsx("span",{className:"text-xs text-muted opacity-60",children:t.origin?t.origin.length>20?t.origin.slice(0,20)+"...":t.origin:""})]}),e.jsx("td",{className:"px-4 py-2 text-right tabular-nums text-muted",children:t.usage.messages}),e.jsx("td",{className:"px-4 py-2 text-right font-mono text-xs tabular-nums text-muted",children:t.usage.input.toLocaleString()}),e.jsx("td",{className:"px-4 py-2 text-right font-mono text-xs tabular-nums text-muted",children:t.usage.output.toLocaleString()}),e.jsx("td",{className:"px-4 py-2 text-right font-mono text-xs tabular-nums text-muted",children:t.usage.totalTokens.toLocaleString()}),e.jsxs("td",{className:"px-4 py-2 text-right font-mono text-xs tabular-nums text-muted",children:["$",t.usage.costTotal.toFixed(4)]})]},t.key))})]})})]})]})}function Za({instanceId:a,instanceName:f,showToast:u,onRestoreComplete:p,openBackup:t,openManage:o,openExport:x,onDialogClose:C}){var Ve;const{t:n}=He("instance"),j=Ss(),[b,V]=i.useState(!1),[M,I]=i.useState(!1),[R,H]=i.useState(null),[A,Z]=i.useState(null),[xe,W]=i.useState(!1),[J,z]=i.useState(!1),[G,de]=i.useState(null),[ee,te]=i.useState(null),[fe,ve]=i.useState([]),[g,N]=i.useState(!1),[$,U]=i.useState(!1),[O,_]=i.useState("home"),[q,se]=i.useState(""),[ne,l]=i.useState(""),[h,y]=i.useState("");i.useEffect(()=>{t&&V(!0)},[t]),i.useEffect(()=>{o&&(ae(),I(!0))},[o]),i.useEffect(()=>{x&&W(!0)},[x]);const[E,T]=i.useState(null),[je,F]=i.useState(""),[B,Q]=i.useState("");i.useEffect(()=>{!b&&!M&&!xe&&!R&&!A&&!ee&&!G&&!E&&(C==null||C())},[b,M,xe,R,A,ee,G,E]);const[be,qe]=i.useState({enabled:!1}),[Je,Ee]=i.useState(!1),ae=i.useCallback(async()=>{try{const[d,D]=await Promise.all([Us(a),Ks(a).catch(()=>({enabled:!1}))]);ve(Array.isArray(d)?d:[]),qe(D)}catch{}},[a]);i.useEffect(()=>{ae()},[ae]),i.useEffect(()=>{if(!E)return;let d=!1;return(async()=>{var re,K,ue;for(;!d;)try{const Y=await Js(E);if(d)break;if(Q(Y.progress||""),Y.status==="completed"){if(T(null),F(""),N(!1),Y.operation==="manual-backup")te({type:"success",title:n("backup.created",{defaultValue:"备份完成"}),detail:(re=Y.result)!=null&&re.filename?`${Y.result.filename} (${Ae(Y.result.size||0)})`:""}),ae();else if(Y.operation==="export")de(Y.result);else if(Y.operation==="restore"){const ce=Y.result||{};ce.ok?te({type:"success",title:n("backup.restoreSuccess",{defaultValue:"恢复完成"}),detail:ce.api_key_status==="lost"?n("backup.apiKeyLost",{defaultValue:"备份来自不同平台/架构,请确认 API Key 配置是否仍然适用。"}):((K=ce.warnings)==null?void 0:K.join(`
|
|
3
|
-
`))||"",actions:ce.api_key_status==="lost"?[{label:n("backup.configApiKey",{defaultValue:"配置 API Key"}),onClick:()=>{te(null),j(`/instances/${a}/config`)}}]:void 0}):te({type:"error",title:ce.rolled_back?n("backup.restoreFailedRolledBack",{defaultValue:"恢复失败 — 已自动回滚"}):n("backup.restoreFailed",{defaultValue:"恢复失败"}),detail:((ue=ce.warnings)==null?void 0:ue.join(`
|
|
4
|
-
`))||""}),ae(),p==null||p()}break}else if(Y.status==="failed"){T(null),F(""),N(!1),u(Y.error||"Operation failed","error");break}await new Promise(ce=>setTimeout(ce,1500))}catch{break}})(),()=>{d=!0}},[E]);const ze=async()=>{N(!0),V(!1);try{const d=await zs(a,{include_sessions:$,scope:O});d.job_id?(T(d.job_id),F("manual-backup"),Q("Queued...")):(te({type:"success",title:n("backup.created",{defaultValue:"备份完成"}),detail:`${d.filename} (${Ae(d.size)})`}),N(!1),ae())}catch(d){u(d.message||n("backup.failed",{defaultValue:"备份失败"}),"error"),N(!1)}finally{U(!1),_("home")}},tt=async d=>{var D,re;N(!0),H(null),se("");try{const K=await Gs(a,d);if(K.job_id)T(K.job_id),F("restore"),Q("Queued...");else{if(K.ok){const ue=(D=K.warnings)!=null&&D.length?K.warnings.join(`
|
|
5
|
-
`):"";te({type:"success",title:n("backup.restoreSuccess",{defaultValue:"恢复完成"}),detail:K.api_key_status==="lost"?n("backup.apiKeyLost",{defaultValue:"备份来自不同平台/架构,请确认 API Key 配置是否仍然适用。"}):ue||n("backup.restoreOk",{defaultValue:"实例已恢复。"}),actions:K.api_key_status==="lost"?[{label:n("backup.configApiKey",{defaultValue:"配置 API Key"}),onClick:()=>{te(null),j(`/instances/${a}/config`)}}]:void 0}),p==null||p()}else te({type:"error",title:K.rolled_back?n("backup.restoreFailedRolledBack",{defaultValue:"恢复失败 — 已自动回滚"}):n("backup.restoreFailed",{defaultValue:"恢复失败"}),detail:((re=K.warnings)==null?void 0:re.join(`
|
|
6
|
-
`))||""});ae(),N(!1)}}catch(K){u(K.message||"Restore failed","error"),N(!1)}},We=async d=>{var D;if(!(!ne||!h)){N(!0);try{const re=await Qs({source_id:a,backup_file:d,new_id:ne,new_name:h});Z(null),re.ok?(u(n("backup.createFromBackupOk",{defaultValue:"新实例创建成功"}),"success"),(D=re.warnings)!=null&&D.length&&re.warnings.forEach(K=>u(K,"info")),j(`/instances/${re.instance_id}/config`)):u(re.detail||n("backup.createFromBackupFail",{defaultValue:"创建失败"}),"error")}catch(re){u(re.message||"Failed","error")}finally{N(!1),l(""),y("")}}},st=async d=>{try{await Ys(a,d),u(n("backup.deleted",{defaultValue:"已删除"}),"info"),ae()}catch(D){u(D.message||"Delete failed","error")}},Se=async()=>{N(!0),W(!1);try{const d=await Xs(a,{include_sessions:J});d.job_id?(T(d.job_id),F("export"),Q("Queued...")):(de(d),N(!1))}catch(d){u(d.message||"Export failed","error"),N(!1)}finally{z(!1)}};function Ae(d){return d<1024?`${d}B`:d<1024*1024?`${(d/1024).toFixed(1)}KB`:`${(d/(1024*1024)).toFixed(1)}MB`}function Ge(d){const D=new Date(d),re=D.getFullYear(),K=D.getMonth()+1,ue=D.getDate(),Y=String(D.getHours()).padStart(2,"0"),ce=String(D.getMinutes()).padStart(2,"0"),at=String(D.getSeconds()).padStart(2,"0");return`${re}/${K}/${ue} ${Y}:${ce}:${at}`}function ye(d){return d==="auto-backup"?n("backup.typeAuto",{defaultValue:"自动"}):d==="pre-restore"?n("backup.typePreRestore",{defaultValue:"恢复前"}):n("backup.typeManual",{defaultValue:"手动"})}const oe="w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground placeholder-[var(--muted)] focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60 focus:border-[#0066FF]/60 transition-colors duration-200",ie="px-4 py-2 bg-[#0066FF] text-white rounded-md text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-150",Fe="px-4 py-2 border border-[var(--border)] text-muted rounded-md text-sm font-medium hover:bg-[var(--card-hover)] hover:text-foreground transition-all duration-150";return e.jsxs(e.Fragment,{children:[E&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 max-w-sm w-full mx-4 space-y-4 shadow-2xl text-center",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("span",{className:"w-8 h-8 border-2 border-[#0066FF]/30 border-t-[#0066FF] rounded-full animate-spin"})}),e.jsx("p",{className:"text-sm text-foreground",children:B||n("backup.processing",{defaultValue:"处理中..."})}),e.jsx("p",{className:"text-xs text-muted",children:n("backup.queueNote",{defaultValue:"任务将按顺序执行"})})]})}),b&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:()=>{V(!1),U(!1),_("home")},children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 w-full max-w-sm shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("h3",{className:"text-base font-semibold text-foreground mb-2",children:n("backup.createTitle",{defaultValue:"创建备份"})}),e.jsx("p",{className:"text-sm text-muted mb-4",children:n("backup.createDesc",{defaultValue:"备份当前实例的配置、插件和数据。"})}),e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"backup-scope",value:"home",checked:O==="home",onChange:()=>_("home"),className:"mt-1"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:n("backup.scopeFull",{defaultValue:"完整备份(含运行时)"})}),e.jsx("div",{className:"text-xs text-[var(--muted)]",children:n("backup.scopeFullDesc",{defaultValue:"包含升级后的 OpenClaw 运行时——恢复后保持当前版本"})})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"backup-scope",value:"state",checked:O==="state",onChange:()=>_("state"),className:"mt-1"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:n("backup.scopeState",{defaultValue:"仅数据(更小、可移植)"})}),e.jsx("div",{className:"text-xs text-[var(--muted)]",children:n("backup.scopeStateDesc",{defaultValue:"仅 .openclaw/ 数据——体积小,兼容官方 OpenClaw 格式"})})]})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted cursor-pointer mb-5",children:[e.jsx("input",{type:"checkbox",checked:$,onChange:d=>U(d.target.checked),className:"rounded border-[var(--border)] bg-[var(--input-bg)]"}),n("backup.includeSessions",{defaultValue:"包含对话历史(体积较大)"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{className:`flex-1 ${Fe}`,onClick:()=>{V(!1),U(!1),_("home")},children:n("common:action.cancel",{defaultValue:"取消"})}),e.jsx("button",{className:`flex-1 ${ie}`,onClick:ze,disabled:g,children:g?n("backup.creating",{defaultValue:"备份中..."}):n("backup.create",{defaultValue:"备份"})})]})]})}),M&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:()=>I(!1),children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 w-full max-w-2xl shadow-2xl flex flex-col max-h-[80vh]",onClick:d=>d.stopPropagation(),children:[e.jsxs("h3",{className:"text-base font-semibold text-foreground mb-3 flex-shrink-0",children:[n("backup.manageTitle",{defaultValue:"备份管理"}),e.jsxs("span",{className:"text-muted font-normal",children:[" — ",f]})]}),e.jsx("div",{className:"bg-[var(--input-bg)] border border-[var(--border)] rounded-lg px-4 py-3 mb-3 flex-shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted",children:n("backup.autoBackup",{defaultValue:"自动备份"})}),be.enabled&&e.jsxs("span",{className:"text-muted opacity-70",children:[n("backup.interval",{defaultValue:"每{{h}}小时备份",h:be.interval_hours||24})," | ",n("backup.keep",{defaultValue:"保留{{n}}份",n:be.keep_count||7})]}),be.enabled&&be.last_backup_ok===!1&&e.jsxs("span",{className:"text-red-400 text-xs",children:["(",n("backup.failed",{defaultValue:"失败"}),")"]})]}),e.jsx("button",{disabled:Je,onClick:async d=>{d.stopPropagation(),Ee(!0);try{be.enabled?await ms(a,{enabled:!1}):(await ms(a,{enabled:!0,interval_hours:24,keep_count:7}),u(n("backup.autoEnabled",{defaultValue:"自动备份已开启"}),"success")),await ae()}catch(D){u(D.message||"Failed","error")}finally{Ee(!1)}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors duration-200 ${Je?"opacity-40":""} ${be.enabled?"bg-green-500":"bg-[var(--border)]"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform duration-200 ${be.enabled?"translate-x-4":"translate-x-0.5"}`})})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0",children:fe.length===0?e.jsx("p",{className:"text-sm text-muted py-6 text-center",children:n("backup.noBackups",{defaultValue:"暂无备份"})}):e.jsx("div",{className:"space-y-2",children:fe.map(d=>e.jsxs("div",{className:"flex items-center justify-between bg-[var(--card)] border border-[var(--border)] rounded-lg px-4 py-3 hover:border-[var(--border-hover)] transition-colors duration-150",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded bg-[var(--input-bg)] border border-[var(--border)] text-muted font-medium flex-shrink-0",children:ye(d.type)}),e.jsx("span",{className:"text-sm text-foreground truncate",children:Ge(d.created_at)}),e.jsx("span",{className:"text-xs text-muted flex-shrink-0",children:Ae(d.size)})]})}),e.jsxs("div",{className:"flex items-center gap-1 ml-3 flex-shrink-0",children:[e.jsx("button",{title:n("backup.restore",{defaultValue:"恢复"}),className:"p-2 rounded-md hover:bg-[var(--card-hover)] text-muted hover:text-foreground transition-colors duration-150 text-base",onClick:()=>{se(""),H(d.filename)},children:"↩"}),e.jsx("button",{title:n("backup.createNew",{defaultValue:"创建新实例"}),className:"p-2 rounded-md hover:bg-[var(--card-hover)] text-muted hover:text-foreground transition-colors duration-150 text-base",onClick:()=>{l(""),y(""),Z(d.filename)},children:"⊕"}),d.type!=="pre-restore"&&e.jsx("a",{href:Bs(a,d.filename),download:!0,title:n("backup.download",{defaultValue:"下载"}),className:"p-2 rounded-md hover:bg-[var(--card-hover)] text-muted hover:text-foreground transition-colors duration-150 text-base underline decoration-current underline-offset-2",children:"⬇"}),e.jsx("button",{title:n("backup.delete",{defaultValue:"删除"}),className:"p-2 rounded-md hover:bg-red-500/10 text-muted hover:text-red-400 transition-colors duration-150 text-base",onClick:()=>st(d.filename),children:"🗑"})]})]},d.filename))})}),e.jsxs("div",{className:"flex justify-between items-center pt-4 mt-4 border-t border-[var(--border)] flex-shrink-0",children:[e.jsx("button",{className:Fe,onClick:()=>I(!1),children:n("common:action.close",{defaultValue:"关闭"})}),e.jsx("button",{className:ie,onClick:()=>{I(!1),V(!0)},children:n("backup.createNew2",{defaultValue:"创建新备份"})})]})]})}),R&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:()=>{H(null),se("")},children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 w-full max-w-sm shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("h3",{className:"text-base font-semibold text-amber-400 mb-2",children:n("backup.restoreTitle",{defaultValue:"恢复将覆盖当前数据"})}),e.jsx("p",{className:"text-sm text-muted mb-4",children:n("backup.restoreDesc",{defaultValue:"已自动创建恢复前备份,如有问题可回滚。"})}),e.jsx("p",{className:"text-sm text-muted mb-2",children:n("backup.restoreConfirmLabel",{defaultValue:"输入实例名确认恢复:"})}),e.jsx("input",{type:"text",value:q,onChange:d=>se(d.target.value),placeholder:f,className:`${oe} mb-4 focus:ring-amber-500/60 focus:border-amber-500/60`,autoFocus:!0}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{className:`flex-1 ${Fe}`,onClick:()=>{H(null),se("")},children:n("common:action.cancel",{defaultValue:"取消"})}),e.jsx("button",{className:"flex-1 px-4 py-2 bg-red-600 text-white rounded-md text-sm font-medium hover:bg-red-700 disabled:opacity-40 transition-colors duration-150",onClick:()=>tt(R),disabled:g||q!==f,children:g?n("backup.restoring",{defaultValue:"恢复中..."}):n("backup.confirmRestore",{defaultValue:"确认恢复"})})]})]})}),A&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:()=>{Z(null),l(""),y("")},children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 w-full max-w-sm shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("h3",{className:"text-base font-semibold text-foreground mb-4",children:n("backup.createFromTitle",{defaultValue:"从备份创建新实例"})}),e.jsxs("div",{className:"space-y-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:n("backup.newName",{defaultValue:"新实例名称"})}),e.jsx("input",{type:"text",value:h,onChange:d=>y(d.target.value),placeholder:n("backup.newNamePlaceholder",{defaultValue:"我的 Agent 副本"}),className:oe,autoFocus:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:n("backup.newId",{defaultValue:"新实例 ID"})}),e.jsx("input",{type:"text",value:ne,onChange:d=>l(d.target.value),placeholder:n("backup.newIdPlaceholder",{defaultValue:"my-agent-copy"}),className:`${oe} font-mono text-[13px]`})]})]}),e.jsx("p",{className:"text-xs text-muted opacity-70 mb-4",children:n("backup.createFromNote",{defaultValue:"API Key 和 IM 凭证不会复制,需自行配置。"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{className:`flex-1 ${Fe}`,onClick:()=>{Z(null),l(""),y("")},children:n("common:action.cancel",{defaultValue:"取消"})}),e.jsx("button",{className:`flex-1 ${ie}`,onClick:()=>We(A),disabled:g||!ne||!h,children:g?n("backup.creatingInstance",{defaultValue:"创建中..."}):n("backup.createInstance",{defaultValue:"创建"})})]})]})}),xe&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>W(!1),children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 max-w-md w-full mx-4 space-y-4 shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:n("backup.exportTitle",{defaultValue:"导出(分享)"})}),e.jsx("p",{className:"text-sm text-muted",children:n("backup.exportDesc",{defaultValue:"生成可分享的导出包,API Key 和凭证将自动移除。"})}),e.jsxs("div",{className:"bg-[var(--input-bg)] border border-[var(--border)] rounded-lg p-3 space-y-1.5 text-sm text-muted",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-400",children:"✓"}),n("backup.exportConfig",{defaultValue:"配置 (openclaw.json, 已清洗)"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-400",children:"✓"}),n("backup.exportPlugins",{defaultValue:"插件 (extensions)"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-400",children:"✓"}),n("backup.exportWorkspace",{defaultValue:"工作区 / Skills"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-red-400",children:"✗"}),n("backup.exportNoKeys",{defaultValue:"API Key / 凭证 — 已移除"})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:J,onChange:d=>z(d.target.checked),className:"rounded border-[var(--border)] bg-[var(--input-bg)]"}),n("backup.exportIncludeSessions",{defaultValue:"包含对话历史"})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{className:Fe,onClick:()=>W(!1),children:n("common:action.cancel",{defaultValue:"取消"})}),e.jsx("button",{className:ie,onClick:Se,disabled:g,children:g?n("backup.exporting",{defaultValue:"导出中..."}):n("backup.exportBtn",{defaultValue:"导出"})})]})]})}),G&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 max-w-md w-full mx-4 space-y-4 shadow-2xl",children:[e.jsx("h3",{className:"text-lg font-semibold text-green-400",children:n("backup.exportDone",{defaultValue:"导出完成"})}),e.jsxs("p",{className:"text-sm text-muted",children:[G.filename," (",Ae(G.size),")"]}),G.warnings&&G.warnings.length>0&&e.jsx("div",{className:"space-y-1",children:G.warnings.map((d,D)=>e.jsx("p",{className:"text-xs text-amber-400",children:d},D))}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("a",{href:Hs(a,G.filename),download:!0,className:ie+" inline-block text-center no-underline",children:n("backup.downloadExport",{defaultValue:"下载"})}),e.jsx("button",{className:Fe,onClick:()=>de(null),children:n("common:action.close",{defaultValue:"关闭"})})]})]})}),ee&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 w-full max-w-sm shadow-2xl",children:[e.jsx("h3",{className:`text-base font-semibold mb-2 ${ee.type==="success"?"text-green-400":"text-red-400"}`,children:ee.title}),ee.detail&&e.jsx("p",{className:"text-sm text-muted mb-4 whitespace-pre-wrap",children:ee.detail}),e.jsxs("div",{className:"flex justify-end gap-2",children:[(Ve=ee.actions)==null?void 0:Ve.map((d,D)=>e.jsx("button",{className:ie,onClick:d.onClick,children:d.label},D)),e.jsx("button",{className:Fe,onClick:()=>te(null),children:n("common:action.close",{defaultValue:"关闭"})})]})]})})]})}function er({yaml:a,env:f,onYamlChange:u,onEnvChange:p}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl overflow-hidden",children:[e.jsx("div",{className:"border-b border-[var(--border)] px-4 py-2 flex items-center justify-between",children:e.jsx("span",{className:"text-xs font-medium text-muted",children:"config.yaml"})}),e.jsx("textarea",{value:a,onChange:t=>u(t.target.value),className:"w-full font-mono text-[13px] p-4 min-h-[320px] focus:outline-none resize-y text-foreground bg-transparent",spellCheck:!1})]}),e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl overflow-hidden",children:[e.jsx("div",{className:"border-b border-[var(--border)] px-4 py-2 flex items-center justify-between",children:e.jsx("span",{className:"text-xs font-medium text-muted",children:".env"})}),e.jsx("textarea",{value:f,onChange:t=>p(t.target.value),className:"w-full font-mono text-[13px] p-4 min-h-[220px] focus:outline-none resize-y text-foreground bg-transparent",spellCheck:!1})]})]})}const Fs={id:"openclaw",label:"tab.openclaw",icon:"🦞",description:"appDesc.openclaw",image:"ghcr.io/x-aijishu/openclaw-runtime:latest",features:{chat:!0,configEditor:!0,quickConfig:!0,logs:!0,usage:!0,cloneable:!0},configFields:[],defaultPort:18789,generateSpec:(a,f)=>`id: ${a}
|
|
7
|
-
jishushell:
|
|
8
|
-
min_version: "0.4.24"
|
|
9
|
-
tasks:
|
|
10
|
-
- name: gateway
|
|
11
|
-
runtime: container
|
|
12
|
-
image: "ghcr.io/x-aijishu/openclaw-runtime:latest"
|
|
13
|
-
args: ["gateway", "run", "--allow-unconfigured"]
|
|
14
|
-
resources: {cpu: "500m", memory: "512Mi"}
|
|
15
|
-
ports: [{name: http, port: 18789}]
|
|
16
|
-
health: {http: {path: /health, port: 18789}}
|
|
17
|
-
provides:
|
|
18
|
-
- capability: "openai-compatible-api"
|
|
19
|
-
port: 18789
|
|
20
|
-
openclaw:
|
|
21
|
-
config_defaults:
|
|
22
|
-
agents.defaults.model: "minimax/MiniMax-M2.7"
|
|
23
|
-
`},tr={id:"hermes-agent",label:"tab.hermes",icon:"🧠",description:"appDesc.hermes",image:"jishushell-hermes:latest",features:{chat:!1,configEditor:!0,quickConfig:!1,logs:!0,usage:!0,cloneable:!1,webUrl:a=>`http://localhost:${a}`},configFields:[{key:"hermes_api_key",label:"hermes.apiKey",type:"password",placeholder:"hermes.apiKeyPlaceholder",defaultValue:""}],defaultPort:8080,generateSpec:(a,f)=>{const u=f.hermes_api_key||"${HERMES_API_KEY}";return`id: ${a}
|
|
24
|
-
jishushell:
|
|
25
|
-
min_version: "0.4.24"
|
|
26
|
-
name: "Hermes Agent + Open WebUI"
|
|
27
|
-
tasks:
|
|
28
|
-
- name: hermes
|
|
29
|
-
role: service
|
|
30
|
-
runtime: container
|
|
31
|
-
image: "jishushell-hermes:latest"
|
|
32
|
-
env:
|
|
33
|
-
HERMES_API_KEY: "${u}"
|
|
34
|
-
resources: {cpu: "1500m", memory: "3072Mi"}
|
|
35
|
-
volumes:
|
|
36
|
-
- {source: hermes-data, target: /data}
|
|
37
|
-
ports:
|
|
38
|
-
- {name: webui, port: 8080, visibility: external}
|
|
39
|
-
- {name: api, port: 8642, visibility: internal}
|
|
40
|
-
health:
|
|
41
|
-
http: {path: /health, port: 8080}
|
|
42
|
-
interval: "20s"
|
|
43
|
-
timeout: "10s"
|
|
44
|
-
retries: 10
|
|
45
|
-
start_period: "180s"
|
|
46
|
-
provides:
|
|
47
|
-
- capability: "openai-compatible-api"
|
|
48
|
-
port: 8642
|
|
49
|
-
description: "Hermes Agent OpenAI-compatible API"
|
|
50
|
-
- capability: "web-ui"
|
|
51
|
-
port: 8080
|
|
52
|
-
description: "Open WebUI chat frontend"
|
|
53
|
-
`}},sr={id:"ollama",label:"tab.ollama",icon:"🦙",description:"appDesc.ollama",image:"ollama/ollama:latest",features:{chat:!1,configEditor:!1,quickConfig:!1,logs:!0,usage:!0,cloneable:!1,webUrl:a=>""},configFields:[{key:"model",label:"ollama.model",type:"text",placeholder:"ollama.modelPlaceholder",defaultValue:"llama3.2"},{key:"gpu",label:"ollama.gpu",type:"select",options:[{value:"auto",label:"Auto"},{value:"none",label:"CPU Only"},{value:"nvidia",label:"NVIDIA GPU"}],defaultValue:"auto"}],defaultPort:11434,generateSpec:(a,f)=>{const u=f.model||"llama3.2";return`id: ${a}
|
|
54
|
-
jishushell:
|
|
55
|
-
min_version: "0.4.24"
|
|
56
|
-
name: "Ollama"
|
|
57
|
-
tasks:
|
|
58
|
-
- name: ollama-server
|
|
59
|
-
role: service
|
|
60
|
-
runtime: container
|
|
61
|
-
image: "ollama/ollama:latest"
|
|
62
|
-
resources: {cpu: "2000m", memory: "4096Mi"}
|
|
63
|
-
ports:
|
|
64
|
-
- {name: api, port: 11434, visibility: external}
|
|
65
|
-
health:
|
|
66
|
-
http: {path: /, port: 11434}
|
|
67
|
-
interval: "15s"
|
|
68
|
-
timeout: "5s"
|
|
69
|
-
retries: 5
|
|
70
|
-
start_period: "120s"
|
|
71
|
-
- name: pull-model
|
|
72
|
-
role: init
|
|
73
|
-
runtime: container
|
|
74
|
-
image: "ollama/ollama:latest"
|
|
75
|
-
command: "ollama"
|
|
76
|
-
args: ["pull", "${u}"]
|
|
77
|
-
env:
|
|
78
|
-
OLLAMA_HOST: "http://localhost:11434"
|
|
79
|
-
provides:
|
|
80
|
-
- capability: "openai-compatible-api"
|
|
81
|
-
port: 11434
|
|
82
|
-
description: "Ollama OpenAI-compatible API"
|
|
83
|
-
`}},ar={id:"custom",label:"tab.custom",icon:"📝",description:"appDesc.custom",image:"",features:{chat:!1,configEditor:!1,quickConfig:!1,logs:!0,usage:!0,cloneable:!1},configFields:[],defaultPort:0,generateSpec:()=>""},rr=[Fs,tr,sr,ar];function lr(a){return rr.find(f=>f.id===a)??Fs}function nr(a){if(a!=null&&a.app_type)return a.app_type;if(a!=null&&a.app_id){if(a.app_id.startsWith("hermes"))return"hermes-agent";if(a.app_id.startsWith("ollama"))return"ollama"}return"openclaw"}function or(a,f){if(a==null)return"-";const u=Math.floor(a/86400),p=Math.floor(a%86400/3600),t=Math.floor(a%3600/60);return u>0?f("instance:uptime.days",{d:u,h:p}):p>0?f("instance:uptime.hours",{h:p,m:t}):f("instance:uptime.minutes",{m:t})}const pt=[$a,xt,Wa,Ja];function ir(a){for(const f of pt){const u=t=>(t==null?void 0:t.find(o=>o.id===a))??null;if(f.groups)for(const t of f.groups){const o=u(t.items);if(o)return o}const p=u(f.items);if(p)return p}return null}function ks(a,f){const u=JSON.parse(JSON.stringify(a??{})),p=et.find(x=>x.id===f);if(p){if(u.channels||(u.channels={}),u.plugins||(u.plugins={}),u.plugins.entries||(u.plugins.entries={}),u.channels[f])u.channels[f].enabled=!0;else{const x={enabled:!0,...p.defaults??{}};p.fields.forEach(C=>{C.key in x||(x[C.key]="")}),u.channels[f]=x}return u.plugins.entries[f]||(u.plugins.entries[f]={enabled:!0}),u}const t={"skill-vetter":{"skill-vetter":{enabled:!0}},"skill-finder":{"skill-finder":{enabled:!0}},"skill-browser":{"skill-browser":{enabled:!0}}};if(f in t)return u.skills||(u.skills={}),Object.assign(u.skills,t[f]),u;const o={};return f in o&&(u.mcp||(u.mcp={}),u.mcp.servers||(u.mcp.servers={}),Object.assign(u.mcp.servers,o[f])),u}function ws(a){return a.replace(/^(https?:\/\/)(localhost|127\.0\.0\.1)(?=[:/]|$)/i,(f,u)=>`${u}${window.location.hostname}`)}function Ns(a){var n,j,b,V,M;const f=(n=a==null?void 0:a.embeddedUi)==null?void 0:n.port;if(f)return String(f);const p=(Array.isArray(a==null?void 0:a.provides)?a.provides:[]).find(I=>I==null?void 0:I.port);if(p!=null&&p.port)return String(p.port);const t=(b=(j=a==null?void 0:a.runtime)==null?void 0:j.env)==null?void 0:b.OPENCLAW_GATEWAY_PORT;if(t)return String(t);const x=(Array.isArray((V=a==null?void 0:a.runtime)==null?void 0:V.ports)?a.runtime.ports:[]).find(I=>(I==null?void 0:I.name)==="gateway"&&(I==null?void 0:I.hostPort));if(x!=null&&x.hostPort)return String(x.hostPort);const C=((M=a==null?void 0:a.runtime)==null?void 0:M.args)||[];for(let I=0;I<C.length;I++){if(C[I]==="--port"&&I+1<C.length)return String(C[I+1]);if(typeof C[I]=="string"&&C[I].startsWith("--port="))return String(C[I].slice(7))}return"-"}function Ps(a=[]){return new Set(a.filter(f=>f.startsWith("env.")).map(f=>f.slice(4)))}function At(a,f=[]){const u=Ps(f);return u.size?a.split(`
|
|
84
|
-
`).map(p=>{const t=p.trim();if(!t||t.startsWith("#")||!t.includes("="))return p;const o=p.indexOf("="),x=p.slice(0,o).replace(/^export\s+/,"").trim();return u.has(x)?`${p.slice(0,o)}=***`:p}).join(`
|
|
85
|
-
`):a}function cr(a,f,u=[]){const p=Ps(u);if(!p.size)return a;const t=new Map;for(const o of f.split(`
|
|
86
|
-
`)){const x=o.trim();if(!x||x.startsWith("#")||!x.includes("="))continue;const C=o.indexOf("="),n=o.slice(0,C).replace(/^export\s+/,"").trim(),j=o.slice(C+1);t.set(n,j)}return a.split(`
|
|
87
|
-
`).map(o=>{const x=o.trim();if(!x||x.startsWith("#")||!x.includes("="))return o;const C=o.indexOf("="),n=o.slice(0,C).replace(/^export\s+/,"").trim(),j=o.slice(C+1).trim();if(!p.has(n)||j!=="***")return o;const b=t.get(n);return b==null?o:`${o.slice(0,C)}=${b}`}).join(`
|
|
88
|
-
`)}function br(){var Gt,Qt,Yt,Xt,Zt,es,ts,ss,as,rs,ls,ns,os,is;const{id:a,tab:f}=ga(),u=Ss(),{showToast:p}=Zs(),{t}=He(["instance","common","data"]),[o,x]=i.useState(null),C=i.useRef(0),[n,j]=i.useState(f==="overview"?"chat":f||"chat"),[b,V]=i.useState(null),[M,I]=i.useState(null),[R,H]=i.useState(!1),[A,Z]=i.useState(""),[xe,W]=i.useState(!1),[J,z]=i.useState(""),[G,de]=i.useState([]),[ee,te]=i.useState("stderr"),[fe,ve]=i.useState(""),[g,N]=i.useState(null),[$,U]=i.useState(""),[O,_]=i.useState(!1),[q,se]=i.useState(!1),[ne,l]=i.useState(""),[h,y]=i.useState(null),[E,T]=i.useState(!1),[je,F]=i.useState(!1),[B,Q]=i.useState(""),[be,qe]=i.useState(""),[Je,Ee]=i.useState(""),[ae,ze]=i.useState(!1),[tt,We]=i.useState(!1),[st,Se]=i.useState(!1),[Ae,Ge]=i.useState(null),[ye,oe]=i.useState(!1),[ie,Fe]=i.useState("im"),[Ue,Ve]=i.useState("general"),[d,D]=i.useState(null),[re,K]=i.useState({}),[ue,Y]=i.useState(""),[ce,at]=i.useState(""),[Mt,De]=i.useState(""),[Te,ke]=i.useState({servers:[],installed:!1,loading:!1}),[X,pe]=i.useState(null),we=i.useRef(!1),Ne=i.useRef(!1),[he,$t]=i.useState(!1),ht=i.useRef(null),ft=i.useRef(null),[_t,Vt]=i.useState(!1),Qe=i.useRef(null),[Dt,bt]=i.useState(null),[Tt,gt]=i.useState(null),Is=nr(o),Me=lr(Is).features,Le=Me.configEditor?"config":Me.logs?"logs":"usage";i.useEffect(()=>{const s=o==null?void 0:o.agentType;if(!s){bt(null),gt(null);return}const r=Sa[s];let c=!1;return r!=null&&r.chatComponent?r.chatComponent().then(m=>{c||bt(()=>m.default)}).catch(m=>{console.warn(`[runtime] failed to load chat component for ${s}:`,m)}):bt(null),r!=null&&r.configPanel?r.configPanel().then(m=>{c||gt(()=>m.default)}).catch(m=>{console.warn(`[runtime] failed to load config panel for ${s}:`,m)}):gt(null),()=>{c=!0}},[o==null?void 0:o.agentType]);const Lt=i.useRef(a),vt=i.useRef(he);Lt.current=a,vt.current=he,i.useEffect(()=>{ye&&a&&Xe(a).then(D).catch(()=>{})},[ye,a]),i.useEffect(()=>{ye&&ie==="mcp"&&a&&(ke(s=>({...s,loading:!0})),It(a).then(s=>ke({servers:s.servers,installed:s.installed,loading:!1})).catch(()=>ke(s=>({...s,loading:!1}))))},[ye,ie,a]),i.useEffect(()=>{f&&j(f==="overview"?"chat":f)},[f]),i.useEffect(()=>{_t&&n==="config"&&b&&(Vt(!1),W(!1),setTimeout(()=>{const s=document.getElementById("im-channel-section");s?s.scrollIntoView({behavior:"smooth",block:"start"}):window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"})},200))},[_t,n,b]);const $e=i.useCallback(()=>{const s=Lt.current;s&&!vt.current&&ea(s).then(r=>{x(r),r.llmError&&r.llmError.timestamp>C.current&&Date.now()-r.llmError.timestamp<6e4&&(p(`LLM ${t("common:error")} (${r.llmError.code}): ${r.llmError.message}`,"error"),C.current=r.llmError.timestamp)}).catch(()=>{})},[p,t]);i.useEffect(()=>{$e();const s=setInterval($e,5e3);return()=>clearInterval(s)},[a,$e]);const rt=(Qt=(Gt=o==null?void 0:o.capabilities)==null?void 0:Gt.gateway)==null?void 0:Qt.chatPanel,jt=Array.isArray(o==null?void 0:o.provides)?o.provides.find(s=>String((s==null?void 0:s.protocol)||"").toLowerCase()==="terminal"&&(s==null?void 0:s.terminal)):null,lt=typeof((Yt=o==null?void 0:o.embeddedUi)==null?void 0:Yt.url)=="string"?ws(o.embeddedUi.url.trim()):"",Re=!!lt,nt=!!jt||Re||rt==="iframe"||rt==="inline",Rt=((Xt=o==null?void 0:o.service)==null?void 0:Xt.status)==="running",Ot=Me.webUrl?ws(Me.webUrl(parseInt(Ns(o),10)||0).trim()):"";i.useEffect(()=>{if(!(!a||!o)){if(Re){U(s=>(s!==lt&&se(!1),lt));return}if(rt!=="iframe"){U(""),_(!1),se(!1);return}ta(a).then(s=>{const r=typeof(s==null?void 0:s.url)=="string"?s.url.trim():"";if(!r)throw new Error("No gateway launch URL returned");U(c=>(c!==r&&se(!1),r))}).catch(s=>{U(""),p((s==null?void 0:s.message)||t("gatewayLaunchFailed"),"error")})}},[lt,Re,a,rt,p,t]),i.useEffect(()=>{!a||!o||!nt&&n==="chat"&&(j(Le),u(`/instances/${a}/${Le}`,{replace:!0}))},[n,Le,nt,a,o,u]);const qt=i.useRef(!1);qt.current=O,i.useEffect(()=>{if(!$||!Rt){_(!1),se(!1);return}if(Re){_(!0),se(!0);return}if(qt.current)return;let s=!1,r=0;const c=60,m=()=>{s||r>=c||(r++,fetch($,{method:"HEAD",credentials:"include"}).then(v=>{!s&&v.ok&&_(!0)}).catch(()=>{}))};m();const k=setInterval(m,3e3);return()=>{s=!0,clearInterval(k)}},[$,Re,Rt]);const[ge,yt]=i.useState({}),Wt=Object.values(ge).includes("installing"),ot=i.useRef(new Set),kt=i.useRef(p);kt.current=p;const wt=i.useRef(t);wt.current=t,i.useEffect(()=>{var k;if(!a||!(((k=o==null?void 0:o.capabilities)==null?void 0:k.pluginInstall)===!0&&(n==="config"||Wt)))return;let r=!1;const c=()=>{r||xs(a).then(v=>{var P;if(r)return;const S={};for(const[w,L]of Object.entries(v.plugins))S[w]=L.status;for(const w of ot.current){const L=S[w];if(L==="installed")kt.current(wt.current(w==="feishu"?"feishu.pluginInstalled":"weixin.pluginInstalled"),"success"),ot.current.delete(w);else if(L==="failed"||L==="not_installed"){const me=(P=v.plugins[w])==null?void 0:P.error;kt.current(wt.current(w==="feishu"?"feishu.pluginFailed":"weixin.pluginFailed")+(me?": "+me:""),"error"),ot.current.delete(w)}}yt(S)}).catch(()=>{})};c();const m=setInterval(c,3e3);return()=>{r=!0,clearInterval(m)}},[a,n,Wt]),i.useEffect(()=>{var s;ye&&a&&((s=o==null?void 0:o.capabilities)==null?void 0:s.pluginInstall)===!0&&xs(a).then(r=>{const c={};for(const[m,k]of Object.entries(r.plugins))c[m]=k.status;yt(c)}).catch(()=>{})},[ye,a]);const Ut=s=>{a&&(oa(a,s).catch(()=>{}),yt(r=>({...r,[s]:"installing"})),ot.current.add(s),p(t(s==="feishu"?"feishu.installing":"weixin.installing"),"info"))};i.useEffect(()=>{if(!R)return;const s=r=>{r.preventDefault()};return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[R]),i.useEffect(()=>{n==="config"&&a&&Promise.all([ps(a),hs(a)]).then(([s,r])=>{I(s);const c=ft.current;if(ft.current=null,s.format==="yaml+env"){const k=r;Qe.current=k;const v={...k,env:At(k.env,s.secretFields)};V(v),z(""),W(!1),H(!1);return}Qe.current=null;const m=c?ks(r,c):r;V(m),z(JSON.stringify(m,null,2)),H(!!c)}).catch(()=>{}),n==="usage"&&a&&fs(a).then(N).catch(()=>{})},[n,a]);const Nt=()=>{a&&ia(a,200,ee).then(s=>{var c;de(s.lines);const r=(c=ht.current)==null?void 0:c.parentElement;r&&r.scrollHeight-r.scrollTop-r.clientHeight<80&&setTimeout(()=>{var k;return(k=ht.current)==null?void 0:k.scrollIntoView({behavior:"smooth"})},100)}).catch(()=>{})};wa(Nt,3e3,n==="logs"&&!!a),i.useEffect(()=>{n==="logs"&&Nt()},[ee]);const Kt=()=>y(Date.now()+2e4);i.useEffect(()=>{if(!h)return;const s=h-Date.now();if(s<=0){y(null);return}const r=setTimeout(()=>{y(null),$e()},s);return()=>clearTimeout(r)},[h,$e]);const it=async s=>{if(a){l(s);try{let r=null;s==="start"&&(r=await ca(a)),s==="stop"&&(r=await da(a)),s==="restart"&&(r=await vs(a),Kt()),p(t(s==="start"?"action.startHint":s==="stop"?"action.stopDone":"action.restartHint"),s==="stop"?"success":"info");const c=r==null?void 0:r.port_allocation;c&&typeof c.from=="number"&&typeof c.to=="number"&&c.from!==c.to&&p(t("common:toast.portReallocated",{defaultValue:"端口 {{from}} 被占用,已自动切换到 {{to}}",from:c.from,to:c.to}),"info"),(s==="start"||s==="restart")&&u(`/instances/${a}`),setTimeout($e,1e3)}catch(r){p(r.message||t("common:error.operationFailed"),"error")}finally{l("")}}},Bt=async s=>{if(!a)return;oe(!1),we.current=!1;const r=s==="feishu"?"feishu":"openclaw-weixin",c=ge[r];if(c==="installing"){p(t(s==="feishu"?"feishu.waitingInstall":"weixin.waitingInstall"),"info");return}if(c!=="installed"){Ut(r);return}Ne.current=!1,pe({type:s,qrUrl:"",sessionKey:"",status:"loading",message:t("qr.gettingQr")});try{let m=null;for(let P=0;P<3;P++){if(Ne.current)return;try{if(m=s==="feishu"?await ua(a):await ma(a),m!=null&&m.qrcodeUrl)break}catch{P<2&&await new Promise(w=>setTimeout(w,1500))}}if(Ne.current)return;if(!(m!=null&&m.qrcodeUrl)){pe(P=>P?{...P,status:"error",message:t("qr.getFailed")}:null);return}pe({type:s,qrUrl:m.qrcodeUrl,sessionKey:m.sessionKey,status:"waiting",message:t(s==="feishu"?"qr.scanFeishu":"qr.scanWeixin")}),we.current=!0;let k=0;const v=6,S=async P=>{if(!(!we.current||Ne.current))try{const w=s==="feishu"?await xa(a,P):await pa(a,P);if(Ne.current)return;if(k=0,w.connected){we.current=!1,pe(L=>L?{...L,qrUrl:"",status:"confirmed",message:w.message||t("qr.loginSuccess")}:null);return}if(w.status==="expired"){we.current=!1,pe(L=>L?{...L,status:"error",message:w.message||t("qr.expired")}:null);return}w.status==="refreshed"&&w.qrcodeUrl?pe(L=>L?{...L,qrUrl:w.qrcodeUrl,message:t("qr.refreshed")}:null):w.status==="scaned"&&pe(L=>L?{...L,status:"scaned",message:w.message||t("qr.scaned")}:null),setTimeout(()=>S(P),2e3)}catch{if(!we.current||Ne.current)return;if(k+=1,k>=v){we.current=!1,pe(w=>w?{...w,status:"error",message:t("qr.pollFailed",{defaultValue:"轮询失败,请刷新后重试"})}:null);return}setTimeout(()=>S(P),3e3)}};setTimeout(()=>S(m.sessionKey),2e3)}catch{Ne.current||pe(m=>m?{...m,status:"error",message:t("qr.getFailed")}:null)}},Oe=(s,r)=>{let c=0;const m=()=>{var k;try{const v=document.getElementById("gateway-iframe");if(!v){++c<50&&setTimeout(m,200);return}const S=v.contentDocument;if(!S||S.readyState==="loading"){++c<50&&setTimeout(m,200);return}const P=S.querySelector("openclaw-app");if(!P){++c<50&&setTimeout(m,200);return}if(r){if(!P.connected&&++c<50){setTimeout(m,200);return}P.handleSendChat(s)}else P.chatMessage=s}catch{const v=document.getElementById("gateway-iframe");(k=v==null?void 0:v.contentWindow)==null||k.postMessage({type:"jishu:inject-cmd",cmd:s,send:r},"*")}};n!=="chat"?(Pe("chat"),setTimeout(m,800)):setTimeout(m,100)},ct=s=>{if(oe(!1),s==="feishu"||s==="openclaw-weixin"){Bt(s==="feishu"?"feishu":"weixin");return}const r=ir(s);if(r&&r.cmd!==void 0){Oe(r.cmd,r.send!==!1);return}if(b!==null&&n==="config"){const c=ks(b,s);V(c),z(JSON.stringify(c,null,2)),H(!0),p(t("config.presetAdded"),"info")}else ft.current=s,Pe("config"),p(t("config.navigatingToConfig"),"info")},Ht=s=>{V(s),(M==null?void 0:M.format)==="json"&&z(JSON.stringify(s,null,2)),H(!0)},Es=s=>{V(r=>({...r||{format:"yaml+env",env:""},format:"yaml+env",yaml:s})),H(!0)},As=s=>{V(r=>({...r||{format:"yaml+env",yaml:""},format:"yaml+env",env:s})),H(!0)},Ms=s=>{z(s),H(!0);try{V(JSON.parse(s)),Z("")}catch{Z(t("config.jsonError"))}},$s=s=>{var k,v,S;if(!s)return"{}";const r=JSON.parse(JSON.stringify(s)),c=(k=r==null?void 0:r.models)==null?void 0:k.providers;if(c&&typeof c=="object")for(const[P,w]of Object.entries(c))P.startsWith("js-")&&(w!=null&&w.apiKey)&&(w.apiKey="(proxy token, auto-managed)");const m=(S=(v=r==null?void 0:r["x-jishushell"])==null?void 0:v.proxy)==null?void 0:S.upstream;return m&&m.apiKey===""&&m.hasApiKey&&(m.apiKey="(saved, leave empty to keep, enter new value to update)"),JSON.stringify(r,null,2)},Jt=s=>{var k,v,S;const r=JSON.parse(s),c=(v=(k=r==null?void 0:r["x-jishushell"])==null?void 0:k.proxy)==null?void 0:v.upstream;(c==null?void 0:c.apiKey)==="(saved, leave empty to keep, enter new value to update)"&&delete c.apiKey;const m=(S=r==null?void 0:r.models)==null?void 0:S.providers;if(m&&typeof m=="object")for(const[P,w]of Object.entries(m))P.startsWith("js-")&&(w==null?void 0:w.apiKey)==="(proxy token, auto-managed)"&&delete w.apiKey;return r},zt=async s=>{var r;if(!(!a||!b||!M)){Z(""),T(!0);try{const c=M.format==="yaml+env"?{format:"yaml+env",yaml:String(b.yaml||""),env:cr(String(b.env||""),((r=Qe.current)==null?void 0:r.env)||"",M.secretFields)}:Jt(xe?J:JSON.stringify(b)),m=await ha(a,c);if(m!=null&&m.config&&(M.format==="yaml+env"?(Qe.current=m.config,V({...m.config,env:At(m.config.env,M.secretFields)}),z("")):(V(m.config),z(JSON.stringify(m.config,null,2)))),H(!1),s)try{await vs(a),Kt(),p(t("config.savedAndRestarted"),"success"),j("chat"),u(`/instances/${a}`,{replace:!0})}catch(k){p(t("config.savedButRestartFailed",{error:k.message||""}),"error"),Z(t("config.restartFailed",{error:k.message||""}))}else p(t("config.saved"),"success");setTimeout($e,1e3)}catch(c){Z(c instanceof SyntaxError?t("config.jsonParseError",{error:c.message}):c.message||t("common:error.saveFailed"))}finally{T(!1)}}},_s=async()=>{var r;if(!a||B.trim()!==((r=o==null?void 0:o.name)==null?void 0:r.trim())||he||ae)return;const s=be.trim();if(Ee(""),s){ze(!0);try{await fa({sudoPassword:s})}catch(c){Ee((c==null?void 0:c.message)||t("newInstance:sudoDialog.passwordInvalid",{defaultValue:"sudo 密码错误,请重新输入。"})),qe(""),ze(!1);return}ze(!1)}vt.current=!0,$t(!0);try{await ba(a,tt,s?{sudoPassword:s}:void 0),u("/",{replace:!0})}catch(c){p(c.message||t("common:error.deleteFailed"),"error"),$t(!1)}},Pe=s=>{if(R&&n==="config"&&s!=="config"){if(!window.confirm(t("config.unsavedWarning")))return;H(!1)}j(s),u(`/instances/${a}/${s}`,{replace:!0})};if(!o)return e.jsx("div",{className:"p-6 max-w-5xl mx-auto",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-6 w-48 bg-[var(--card)] rounded"}),e.jsx("div",{className:"h-10 w-full bg-[var(--card)] rounded"}),e.jsx("div",{className:"h-40 bg-[var(--card)] rounded-lg"})]})});const Ke=((Zt=o.service)==null?void 0:Zt.status)||"stopped",Be=Ke==="running",dt=Ke==="pending",ut=Ke==="failed"||Ke==="dead",Ct=((es=o==null?void 0:o.capabilities)==null?void 0:es.backupRestore)!==!1,St=(dt||h!=null&&Date.now()<h)&&!ut,Ye=Be,Vs=t(St?"common:status.starting":Be?"common:status.running":Ke==="failed"?"common:status.failed":Ke==="dead"?"common:status.crashed":"common:status.stopped"),Ds=St?"text-amber-400":Be?"text-emerald-400":ut?"text-red-400":"text-muted",Ts=St?"bg-amber-400 animate-pulse shadow-[0_0_6px_rgba(251,191,36,0.5)]":Be?"bg-emerald-500 shadow-[0_0_6px_rgba(16,185,129,0.6)]":ut?"bg-red-500 shadow-[0_0_6px_rgba(239,68,68,0.6)]":"bg-[var(--muted)] opacity-40";return e.jsxs("div",{className:"p-6 max-w-5xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-lg font-semibold text-foreground",children:o.name}),e.jsx("span",{className:"px-2 py-0.5 rounded-full border border-[var(--border)] text-[11px] text-muted uppercase tracking-[0.08em]",children:o.agentType||"openclaw"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${Ts}`}),e.jsx("span",{className:`text-xs font-medium ${Ds}`,children:Vs}),Be&&!O&&(((ss=(ts=o==null?void 0:o.capabilities)==null?void 0:ts.gateway)==null?void 0:ss.chatPanel)==="iframe"||Re)&&e.jsx("span",{className:"text-[11px] text-amber-400/90",children:t("status.gatewayPending")})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n==="chat"&&e.jsxs(e.Fragment,{children:[e.jsx("a",{href:$||void 0,target:"_blank",rel:"noopener noreferrer","aria-disabled":!$,title:t("openInWindow"),className:`p-1.5 border border-[var(--border)] rounded-md transition-all duration-150 ${$?"text-muted hover:text-foreground hover:bg-[var(--card-hover)] cursor-pointer":"pointer-events-none text-muted opacity-30"}`,children:e.jsx(sa,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>{_(!1),se(!1)},disabled:!$,title:t("reload"),className:"p-1.5 border border-[var(--border)] rounded-md text-muted hover:text-foreground hover:bg-[var(--card-hover)] disabled:opacity-30 transition-all duration-150",children:e.jsx(Cs,{className:"w-4 h-4"})})]}),Me.configEditor&&e.jsxs("button",{onClick:()=>Pe("config"),title:t("tab.config"),className:"p-1.5 border border-[var(--border)] rounded-md text-muted hover:text-foreground hover:bg-[var(--card-hover)] transition-all duration-150 relative",children:[e.jsx(aa,{className:"w-4 h-4"}),R&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 w-1.5 h-1.5 rounded-full bg-amber-400"})]}),Me.quickConfig&&((as=o==null?void 0:o.capabilities)==null?void 0:as.pluginInstall)===!0&&e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>oe(s=>!s),title:t("quickSkill"),className:"flex items-center gap-1 px-2.5 py-1.5 border border-[#0066FF]/30 rounded-md text-xs font-medium text-[#0066FF] bg-[#0066FF]/5 hover:bg-[#0066FF]/10 transition-all duration-150",children:[e.jsx("svg",{className:"w-3.5 h-3.5",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"})}),e.jsx("span",{className:"hidden sm:inline",children:t("quickSkill")}),e.jsx(ra,{className:`w-3 h-3 transition-transform duration-150 ${ye?"rotate-180":""}`})]}),ye&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>oe(!1)}),e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-80 bg-background border border-[var(--border)] rounded-lg shadow-2xl z-20 overflow-hidden",children:[e.jsx("div",{className:"flex border-b border-[var(--border)]",children:["im","skills","mcp","slash"].map(s=>{const r={im:{emoji:"💬",label:t("quickSkill.im")},skills:{emoji:"⚡",label:t("quickSkill.skills")},mcp:{emoji:"🔌",label:t("quickSkill.mcp")},slash:{emoji:"/",label:t("quickSkill.slash")}}[s];return e.jsxs("button",{onClick:c=>{c.stopPropagation(),Fe(s)},className:`flex-1 py-2 flex flex-col items-center gap-0.5 text-[10px] font-medium transition-colors border-b-2 ${ie===s?"text-[#0066FF] border-[#0066FF] bg-[#0066FF]/5":"text-muted border-transparent hover:text-foreground hover:bg-[var(--card-hover)]"}`,children:[e.jsx("span",{className:"text-sm leading-none",children:r.emoji}),e.jsx("span",{children:r.label})]},s)})}),e.jsxs("div",{className:"max-h-[480px] overflow-y-auto",children:[ie==="im"&&e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsxs("button",{onClick:()=>ct("feishu"),className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg border border-[#3370FF]/30 bg-[#3370FF]/5 hover:bg-[#3370FF]/10 transition-all duration-150",children:[e.jsx("img",{src:"https://s1.aigei.com/src/img/png/5a/5ad236651e0c4a6b940d2e1d2bf29749.png?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:bcW1ujPdX64WlxeEm9SpuJ5H2KY=",alt:t("channel.feishu"),className:"w-8 h-8 rounded-md flex-shrink-0",onError:s=>{s.target.style.display="none"}}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"text-sm font-semibold text-[#3370FF]",children:t("channel.feishu")}),e.jsx("div",{className:"text-[11px] text-muted mt-0.5",children:ge.feishu==="installing"?t("quickSkill.pluginInstalling"):ge.feishu!=="installed"?t("quickSkill.clickToInstall"):d!=null&&d.im.feishu?`✓ ${t("quickSkill.bound")}`:t("quickSkill.scanToBind")})]}),ge.feishu==="installing"&&e.jsx("div",{className:"w-4 h-4 border-2 border-[#3370FF]/30 border-t-[#3370FF] rounded-full animate-spin flex-shrink-0"}),ge.feishu==="installed"&&(d==null?void 0:d.im.feishu)&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/15 text-emerald-400 font-medium flex-shrink-0",children:t("quickSkill.bound")})]}),e.jsxs("button",{onClick:()=>ct("openclaw-weixin"),className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg border border-[#07C160]/30 bg-[#07C160]/5 hover:bg-[#07C160]/10 transition-all duration-150",children:[e.jsx("img",{src:"https://sgnewres.wechat.com/t/ofs-wechat/newsroom-web/res/_next/static/media/wechat-with-color.7a890de8.svg",alt:t("channel.weixin"),className:"w-8 h-8 rounded-md flex-shrink-0",onError:s=>{s.target.style.display="none"}}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"text-sm font-semibold text-[#07C160]",children:t("channel.weixin")}),e.jsx("div",{className:"text-[11px] text-muted mt-0.5",children:ge["openclaw-weixin"]==="installing"?t("quickSkill.pluginInstalling"):ge["openclaw-weixin"]!=="installed"?t("quickSkill.clickToInstall"):d!=null&&d.im.weixin?`✓ ${t("quickSkill.bound")}`:t("quickSkill.scanToBind")})]}),ge["openclaw-weixin"]==="installing"&&e.jsx("div",{className:"w-4 h-4 border-2 border-[#07C160]/30 border-t-[#07C160] rounded-full animate-spin flex-shrink-0"}),ge["openclaw-weixin"]==="installed"&&(d==null?void 0:d.im.weixin)&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/15 text-emerald-400 font-medium flex-shrink-0",children:t("quickSkill.bound")})]}),e.jsxs("button",{onClick:()=>{oe(!1),Pe("config"),Vt(!0)},className:"w-full flex items-center justify-center gap-1.5 px-4 py-2 rounded-lg text-[11px] text-muted hover:text-foreground hover:bg-[var(--card-hover)] border border-dashed border-[var(--border)] transition-all duration-150",children:[e.jsx("span",{children:t("quickSkill.moreImConfig")}),e.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:e.jsx("path",{d:"M9 18l6-6-6-6"})})]})]}),ie==="skills"&&e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-[var(--border)]/60 flex gap-1.5 flex-shrink-0",children:[e.jsx("input",{type:"text",value:ue,onChange:s=>Y(s.target.value),onKeyDown:s=>{s.key==="Enter"&&ue.trim()&&(oe(!1),Oe(`安装 ${ue.trim()}`,!0),Y(""))},placeholder:t("quickSkill.customSkillPlaceholder"),className:"flex-1 min-w-0 text-[11px] bg-[var(--bg)] border border-[var(--border)] rounded px-2 py-1 text-foreground placeholder:text-muted outline-none focus:border-[#0066FF]/60"}),e.jsx("button",{disabled:!ue.trim(),onClick:()=>{ue.trim()&&(oe(!1),Oe(`安装 ${ue.trim()}`,!0),Y(""))},className:"flex-shrink-0 text-[11px] px-2 py-1 rounded bg-[#0066FF]/10 text-[#0066FF] hover:bg-[#0066FF]/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:t("quickSkill.install")})]}),e.jsxs("div",{className:"flex",style:{height:"380px"},children:[e.jsxs("div",{className:"flex flex-col border-r border-[var(--border)]/60 bg-[var(--card)] flex-shrink-0",style:{width:"72px"},children:[xt.groups.map(s=>e.jsxs("button",{onMouseEnter:r=>{r.stopPropagation(),Ve(s.id)},onClick:r=>{r.stopPropagation(),Ve(s.id)},className:`flex flex-col items-center justify-center gap-0.5 py-3 px-1 text-center transition-colors border-l-2 flex-shrink-0 ${Ue===s.id?"border-[#0066FF] bg-[#0066FF]/5 text-foreground":"border-transparent text-muted hover:text-foreground hover:bg-[var(--card-hover)]"}`,children:[e.jsx("span",{className:"text-base leading-none",children:s.emoji}),e.jsx("span",{className:"text-[9px] font-medium leading-tight mt-0.5 whitespace-pre-wrap break-all",children:t(`data:skills.group.${s.id}`,{defaultValue:s.label})})]},s.id)),e.jsxs("button",{onMouseEnter:s=>{s.stopPropagation(),Ve("installed")},onClick:s=>{s.stopPropagation(),Ve("installed")},className:`flex flex-col items-center justify-center gap-0.5 py-3 px-1 text-center transition-colors border-l-2 flex-shrink-0 ${Ue==="installed"?"border-[#0066FF] bg-[#0066FF]/5 text-foreground":"border-transparent text-muted hover:text-foreground hover:bg-[var(--card-hover)]"}`,children:[e.jsx("span",{className:"text-base leading-none",children:"📦"}),e.jsx("span",{className:"text-[9px] font-medium leading-tight mt-0.5 whitespace-pre-wrap break-all",children:t("quickSkill.allInstalled")})]})]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[Ue==="installed"&&(()=>{if(d===null)return e.jsx("div",{className:"px-3 py-6 text-center text-[11px] text-muted",children:t("quickSkill.loading")});const s=d.installedSkillDirs??[],r={};return xt.groups.forEach(c=>{c.skills.forEach(m=>{var k;(k=m.checkDirs)==null||k.forEach(v=>{r[v.toLowerCase()]=c.label})})}),s.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-[11px] text-muted",children:t("quickSkill.noInstalled")}):e.jsx(e.Fragment,{children:s.map(c=>{const m=r[c.toLowerCase()];return e.jsxs("div",{className:"w-full px-3 py-2 flex items-center gap-2 border-b border-[var(--border)]/30",children:[e.jsxs("button",{className:"flex-1 min-w-0 text-left",onClick:()=>{oe(!1),Oe(`/skill ${c} `,!1)},children:[e.jsx("div",{className:"text-xs font-semibold text-foreground font-mono truncate",children:c}),m&&e.jsx("div",{className:"text-[10px] text-muted mt-0.5",children:m})]}),e.jsx("span",{className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-emerald-500/15 text-emerald-400",children:t("quickSkill.installed")}),e.jsx("button",{onClick:async()=>{if(!(!a||!window.confirm(t("delete.skillConfirm",{name:c}))))try{await bs(a,c);const k=await Xe(a);D(k)}catch(k){p(k.message||t("common:error.deleteFailed"),"error")}},className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-red-500/10 text-red-400 hover:bg-red-500/20 transition-colors",children:t("common:action.delete")})]},c)})})})(),Ue!=="installed"&&(()=>{const s=xt.groups.find(m=>m.id===Ue),r=(s==null?void 0:s.skills)??[];if(r.length===0)return e.jsx("div",{className:"px-3 py-6 text-center text-[11px] text-muted",children:t("quickSkill.noSkills")});const c=((d==null?void 0:d.installedSkillDirs)??[]).map(m=>m.toLowerCase());return e.jsx(e.Fragment,{children:r.map(m=>{var P;if(m.type==="hub")return e.jsxs("div",{className:"w-full px-3 py-2 flex items-center gap-2 border-b border-[var(--border)]/30",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-foreground break-words",children:t(`data:skills.${m.id}.label`,{defaultValue:m.label})}),e.jsx("div",{className:"text-[10px] text-muted leading-tight mt-0.5 break-words",children:t(`data:skills.${m.id}.desc`,{defaultValue:m.desc})}),e.jsx("div",{className:"text-[9px] text-muted/60 leading-tight mt-0.5 break-all",children:m.url})]}),e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),title:"在新标签页打开",className:"flex-shrink-0 text-[11px] px-1.5 py-0.5 rounded-full font-medium bg-[var(--border)] text-muted hover:bg-[#0066FF]/15 hover:text-[#0066FF] transition-colors no-underline",children:"🔗"})]},m.id);const k=d!==null&&m.checkDirs.some(w=>c.includes(w.toLowerCase())),v=re[m.id]??!1,S=((P=d==null?void 0:d.installedSkillDirs)==null?void 0:P.find(w=>m.checkDirs.some(L=>L.toLowerCase()===w.toLowerCase())))??m.id;return e.jsxs("button",{disabled:v,onClick:()=>{if(oe(!1),k)Oe(`/skill ${S} `,!1);else{K(me=>({...me,[m.id]:!0})),Oe(m.installMsg,m.autoInstall!==!1);let w=0;const L=setInterval(async()=>{w+=5e3;try{const me=await Xe(a);D(me);const Ft=((me==null?void 0:me.installedSkillDirs)??[]).map(_e=>_e.toLowerCase());m.checkDirs.some(_e=>Ft.includes(_e.toLowerCase()))&&(clearInterval(L),K(_e=>({..._e,[m.id]:!1})))}catch{}w>=6e4&&(clearInterval(L),K(me=>({...me,[m.id]:!1})))},5e3)}},className:"w-full text-left px-3 py-2 hover:bg-[var(--card-hover)] transition-colors flex items-center gap-2 disabled:opacity-60 border-b border-[var(--border)]/30",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-foreground break-words",children:t(`data:skills.${m.id}.label`,{defaultValue:m.label})}),e.jsx("div",{className:"text-[10px] text-muted leading-tight mt-0.5 break-words",children:t(`data:skills.${m.id}.desc`,{defaultValue:m.desc})})]}),e.jsx("span",{className:`flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded-full font-medium ${v?"bg-amber-500/15 text-amber-400":d===null?"bg-[var(--border)] text-muted":k?"bg-emerald-500/15 text-emerald-400":"bg-[#0066FF]/10 text-[#0066FF]"}`,children:v?t("quickSkill.installing"):d===null?"…":t(k?"quickSkill.installed":"quickSkill.install")}),k&&!v&&e.jsx("button",{onClick:async w=>{if(w.stopPropagation(),!(!a||!window.confirm(t("delete.skillConfirm",{name:S}))))try{await bs(a,S);const L=await Xe(a);D(L)}catch(L){p(L.message||t("common:error.deleteFailed"),"error")}},className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-red-500/10 text-red-400 hover:bg-red-500/20 transition-colors",children:t("common:action.delete")})]},m.id)})})})()]})]})]}),ie==="mcp"&&e.jsxs("div",{className:"py-1",children:[(()=>{const s=!!(d!=null&&d.mcporterInstalled||Te.installed),r=d===null&&Te.loading;return e.jsxs("button",{onClick:()=>{s||(oe(!1),Oe("安装 https://clawhub.ai/steipete/mcporter",!0))},className:"w-full text-left px-3 py-2.5 hover:bg-[var(--card-hover)] transition-colors flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-foreground",children:"MCPorter"}),e.jsx("div",{className:"text-[11px] text-muted leading-tight mt-0.5",children:t("quickSkill.mcporterDesc")})]}),e.jsx("span",{className:`flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded-full font-medium ${r?"bg-[var(--border)] text-muted":s?"bg-emerald-500/15 text-emerald-400":"bg-[#0066FF]/10 text-[#0066FF]"}`,children:r?"…":t(s?"quickSkill.installed":"quickSkill.install")})]})})(),e.jsxs("div",{className:"px-3 py-2 border-t border-[var(--border)]/40",children:[e.jsx("div",{className:"text-[10px] text-muted mb-1.5",children:t("quickSkill.mcpJsonLabel")}),e.jsx("textarea",{rows:3,value:ce,onChange:s=>{at(s.target.value),De("")},placeholder:`{
|
|
89
|
-
"serverName": { "command": "npx", "args": [...] }
|
|
90
|
-
}`,className:"w-full text-[11px] font-mono bg-[var(--bg)] border border-[var(--border)] rounded px-2 py-1.5 text-foreground placeholder:text-muted/50 outline-none focus:border-[#0066FF]/60 resize-none"}),Mt&&e.jsx("div",{className:"text-[10px] text-red-400 mt-1",children:Mt}),e.jsx("button",{disabled:!ce.trim()||!a,onClick:async()=>{let s;try{const r=JSON.parse(ce.trim());if(typeof r!="object"||Array.isArray(r)||r===null)throw new Error("not-object");if(r.mcpServers&&typeof r.mcpServers=="object"&&!Array.isArray(r.mcpServers)?s=r.mcpServers:r.servers&&typeof r.servers=="object"&&!Array.isArray(r.servers)?s=r.servers:s=r,Object.keys(s).length===0)throw new Error("empty");for(const[c,m]of Object.entries(s)){if(typeof m!="object"||Array.isArray(m)||m===null)throw new Error(t("quickSkill.mcpJsonValueNotObject",{name:c}));const k=m;if(!k.command&&!k.baseUrl&&!k.url)throw new Error(t("quickSkill.mcpJsonMissingField",{name:c}))}}catch(r){const c=r==null?void 0:r.message;c==="not-object"?De(t("quickSkill.mcpJsonNotObject")):c==="empty"?De(t("quickSkill.mcpJsonEmpty")):c!=null&&c.startsWith('"')?De(c):De(t("quickSkill.mcpJsonParseFailed",{error:c||""}));return}try{const r=await gs(a,s);at(""),De(""),p(t("quickSkill.mcpWritten"),"success"),D(c=>c&&{...c,mcporterServers:r.mcpServers}),ke(c=>({...c,loading:!0})),It(a).then(c=>ke({servers:c.servers,installed:c.installed,loading:!1})).catch(()=>ke(c=>({...c,loading:!1})))}catch(r){De(r.message||t("quickSkill.mcpWriteFailed"))}},className:"mt-1.5 w-full text-[11px] px-2 py-1 rounded bg-[#0066FF]/10 text-[#0066FF] hover:bg-[#0066FF]/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:t("quickSkill.addToConfig")})]}),(((rs=pt.find(s=>s.id==="mcp"))==null?void 0:rs.items)??[]).map(s=>{const r=Object.keys((d==null?void 0:d.mcporterServers)??{}),c=Te.servers.map(v=>v.name),m=s.mcpJson?Object.keys(s.mcpJson):[],k=m.length>0&&m.some(v=>r.includes(v)||c.includes(v));return e.jsxs("button",{onClick:async()=>{if(s.mcpJson&&a)try{const v=await gs(a,s.mcpJson);p(t("quickSkill.mcpAdded",{label:s.label}),"success"),D(S=>S&&{...S,mcporterServers:v.mcpServers}),ke(S=>({...S,loading:!0})),It(a).then(S=>ke({servers:S.servers,installed:S.installed,loading:!1})).catch(()=>ke(S=>({...S,loading:!1})))}catch(v){p(v.message||t("quickSkill.mcpAddFailed"),"error")}else ct(s.id)},className:"w-full text-left px-3 py-2.5 hover:bg-[var(--card-hover)] transition-colors border-t border-[var(--border)]/40 flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-foreground",children:t(`data:mcp.${s.id}.label`,{defaultValue:s.label})}),e.jsx("div",{className:"text-[11px] text-muted leading-tight mt-0.5",children:t(`data:mcp.${s.id}.desc`,{defaultValue:s.desc})})]}),s.mcpJson&&e.jsx("span",{className:`flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded-full font-medium ${k?"bg-emerald-500/15 text-emerald-400":"bg-[#0066FF]/10 text-[#0066FF]"}`,children:t(k?"quickSkill.configured":"quickSkill.oneClickConfig")})]},s.id)}),(()=>{var k;const s=(d==null?void 0:d.mcporterServers)??{},r=new Set((((k=pt.find(v=>v.id==="mcp"))==null?void 0:k.items)??[]).flatMap(v=>v.mcpJson?Object.keys(v.mcpJson):[])),c=Object.keys(s).filter(v=>!r.has(v));if(c.length===0)return null;const m={};for(const v of Te.servers)m[v.name]=v;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 pt-2 pb-0.5 text-[9px] font-semibold text-muted/60 uppercase tracking-widest border-t border-[var(--border)]/40 mt-1",children:t("quickSkill.mcporterConfigured")}),c.map(v=>{var _e;const S=s[v],P=m[v],w=(P==null?void 0:P.transport)??(S!=null&&S.baseUrl?`HTTP ${S.baseUrl}`:S!=null&&S.command?`${S.command} ${(S.args??[]).join(" ")}`.trim():""),L=(P==null?void 0:P.status)==="ok",me=P?L?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400":(Te.loading,"bg-[var(--border)] text-muted"),Ft=Te.loading&&!P?t("quickSkill.detecting"):P?L?(_e=P.tools)!=null&&_e.length?t("quickSkill.statusNormalWithTools",{count:P.tools.length}):t("quickSkill.statusNormal"):P.status:t("quickSkill.configured");return e.jsxs("div",{className:"w-full px-3 py-2 flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-foreground font-mono",children:v}),w&&e.jsx("div",{className:"text-[11px] text-muted leading-tight mt-0.5 truncate",children:w})]}),e.jsxs("span",{className:`flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded-full font-medium ${me} flex items-center gap-1`,children:[Te.loading&&!P&&e.jsx("span",{className:"w-2 h-2 border border-muted/40 border-t-muted rounded-full animate-spin"}),Ft]}),e.jsx("button",{onClick:async()=>{if(!(!a||!window.confirm(t("delete.mcpConfirm",{name:v}))))try{await la(a,v);const Pt=await Xe(a);D(Pt),ke(cs=>({...cs,servers:cs.servers.filter(Ls=>Ls.name!==v)}))}catch(Pt){p(Pt.message||t("common:error.deleteFailed"),"error")}},className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-red-500/10 text-red-400 hover:bg-red-500/20 transition-colors",children:t("common:action.delete")})]},v)})]})})()]}),ie==="slash"&&e.jsx("div",{className:"py-1",children:(((ls=pt.find(s=>s.id==="slash"))==null?void 0:ls.groups)??[]).map((s,r)=>e.jsxs("div",{children:[r>0&&e.jsx("div",{className:"border-t border-[var(--border)]/40 mx-3 my-0.5"}),e.jsx("div",{className:"px-3 pt-1.5 pb-0.5 text-[9px] font-semibold text-muted/60 uppercase tracking-widest",children:t(`data:slash.group.${s.label}`,{defaultValue:s.label})}),s.items.map(c=>e.jsxs("button",{onClick:()=>ct(c.id),className:"w-full text-left px-3 py-1 hover:bg-[var(--card-hover)] transition-colors",children:[e.jsx("div",{className:"text-xs font-medium text-foreground font-mono",children:c.label}),e.jsx("div",{className:"text-[11px] text-muted leading-tight",children:t(`data:slash.${c.id}.desc`,{defaultValue:c.desc})})]},c.id))]},s.label))})]})]})]})]}),Be||dt?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>it("restart"),disabled:!!ne||dt,className:"px-3 py-1.5 bg-[#0066FF] text-white rounded-md text-xs font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:t(ne==="restart"?"action.restarting":"common:action.restart")}),e.jsx("button",{onClick:()=>it("stop"),disabled:!!ne,className:"px-3 py-1.5 bg-red-600 text-white rounded-md text-xs font-medium hover:bg-red-700 disabled:opacity-40 transition-all duration-200",children:t(ne==="stop"?"action.stopping":"common:action.stop")})]}):e.jsx("button",{onClick:()=>it("start"),disabled:!!ne,className:"px-3 py-1.5 bg-[#0066FF] text-white rounded-md text-xs font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:t(ne==="start"?"action.starting":"common:action.start")}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>Se(!st),className:"p-1.5 border border-[var(--border)] rounded-md text-muted hover:text-foreground hover:bg-[var(--card-hover)] transition-all duration-150",children:e.jsx(na,{className:"w-4 h-4"})}),st&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>Se(!1)}),e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-40 bg-background border border-[var(--border)] rounded-lg shadow-2xl py-1 z-20",children:[e.jsx("button",{onClick:()=>{Se(!1),Pe("logs")},className:"w-full text-left px-3 py-2 text-sm text-foreground hover:bg-[var(--card-hover)] transition-colors",children:t("tab.logs")}),e.jsx("button",{onClick:()=>{Se(!1),Pe("usage")},className:"w-full text-left px-3 py-2 text-sm text-foreground hover:bg-[var(--card-hover)] transition-colors",children:t("tab.usage")}),Ct&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-[var(--border)] my-1"}),e.jsx("button",{onClick:()=>{Se(!1),Ge("manage")},className:"w-full text-left px-3 py-2 text-sm text-foreground hover:bg-[var(--card-hover)] transition-colors",children:t("backup.manageMenu",{defaultValue:"备份管理"})}),e.jsx("button",{onClick:()=>{Se(!1),Ge("export")},className:"w-full text-left px-3 py-2 text-sm text-foreground hover:bg-[var(--card-hover)] transition-colors",children:t("backup.export",{defaultValue:"导出(分享)"})}),e.jsx("div",{className:"border-t border-[var(--border)] my-1"})]}),e.jsx("button",{onClick:()=>{Se(!1),F(!0),We(!1)},className:"w-full text-left px-3 py-2 text-sm text-red-400 hover:bg-red-500/10 transition-colors",children:t("delete.title")})]})]})]})]})]}),a&&Ct&&e.jsx(Za,{instanceId:a,instanceName:(o==null?void 0:o.name)||a,showToast:p,onRestoreComplete:$e,openBackup:Ae==="backup",openManage:Ae==="manage",openExport:Ae==="export",onDialogClose:()=>Ge(null)}),e.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted mb-3",children:[e.jsx("button",{onClick:()=>u("/"),className:"hover:text-foreground transition-colors",children:t("backToOverview")}),e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{children:["📊 ",((ns=o.service)==null?void 0:ns.memory_mb)!=null?`${o.service.memory_mb} MB`:"-"]}),e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{children:["⏱ ",or((os=o.service)==null?void 0:os.uptime,t)]}),e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{children:["🔌 ",t("port",{port:Ns(o)})]})]}),ut&&e.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 text-red-400 text-sm rounded-lg px-4 py-3 flex items-center justify-between mb-3",children:[e.jsx("span",{children:t("failedHint")}),e.jsx("button",{onClick:()=>Pe("logs"),className:"text-red-400 underline text-sm font-medium",children:t("viewLogs")})]}),n!=="chat"&&nt&&e.jsx("button",{onClick:()=>Pe("chat"),className:"flex items-center gap-1 text-xs text-[#0066FF] hover:text-[#0066FF]/80 mb-3 transition-colors",children:t("backToChat")}),n==="chat"&&(()=>{var r,c;const s=(c=(r=o==null?void 0:o.capabilities)==null?void 0:r.gateway)==null?void 0:c.chatPanel;return Dt&&a?e.jsx(Dt,{instanceId:a,instanceEpoch:(o==null?void 0:o.created_at)??null}):jt&&a?e.jsx(Qa,{instanceId:a,provide:jt,isRunning:Ye}):s==="iframe"||Re?e.jsx(za,{gatewayLaunchUrl:$,gatewayReady:O,isRunning:Ye,isPending:dt,iframeLoaded:q,actionLoading:ne,onAction:it,onReload:()=>{_(!1),se(!1)},onIframeLoad:()=>se(!0)}):s==="inline"?e.jsxs("div",{className:"rounded-[22px] border border-[var(--border)] bg-[var(--card)] p-8 text-center",children:[e.jsx("div",{className:"w-5 h-5 mx-auto border-2 border-[#0066FF]/30 border-t-[#0066FF] rounded-full animate-spin mb-3"}),e.jsx("div",{className:"text-sm text-foreground/70",children:"正在加载 Chat 组件..."})]}):e.jsxs("div",{className:"rounded-[22px] border border-[var(--border)] bg-[var(--card)] p-8 text-center",children:[e.jsx("div",{className:"text-4xl mb-3 opacity-40",children:"🔌"}),e.jsxs("div",{className:"text-sm text-foreground/70 font-medium mb-1",children:["此应用 (",o==null?void 0:o.agentType,") 没有内置应用界面"]}),e.jsx("div",{className:"text-xs text-muted mb-4",children:Le==="config"?"请切换到 Config tab 配置消息平台凭证,通过 IM 与应用交互。":"此应用没有可嵌入的应用界面,请改用日志或用量页确认运行状态。"}),e.jsx("button",{onClick:()=>Pe(Le),className:"px-4 py-2 bg-[#0066FF] text-white rounded-md text-xs font-medium hover:bg-[#0066FF]/90 transition-all duration-200",children:Le==="config"?"打开 Config":Le==="logs"?"打开 Logs":"打开 Usage"})]})})(),n==="chat"&&!Me.chat&&!nt&&Ot&&e.jsx("div",{className:"bg-card border border-[var(--border)] rounded-xl p-6 text-center space-y-3",children:Ye?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-foreground",children:t("webui.ready")}),e.jsx("a",{href:Ot,target:"_blank",rel:"noopener noreferrer",className:"inline-block px-4 py-2 bg-[#0066FF] text-white rounded-md text-sm font-medium hover:bg-[#0066FF]/90 transition-all",children:t("webui.open")})]}):e.jsx("p",{className:"text-sm text-muted",children:t("webui.notRunning")})}),n==="config"&&b&&Me.configEditor&&e.jsxs("div",{className:"space-y-4",children:[R&&e.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-lg px-4 py-2.5 flex items-center justify-between",children:[e.jsx("span",{children:t("config.modified")}),e.jsx("button",{onClick:()=>{V(null),Promise.all([ps(a),hs(a)]).then(([s,r])=>{I(s),s.format==="yaml+env"?(Qe.current=r,V({...r,env:At(r.env,s.secretFields)}),z("")):(V(r),z(JSON.stringify(r,null,2))),H(!1)})},className:"text-xs text-amber-400 hover:underline",children:t("config.discard")})]}),A&&e.jsx("div",{className:"bg-red-500/10 border border-red-500/20 text-red-400 text-sm rounded-lg px-4 py-2.5",children:A}),(M==null?void 0:M.format)==="json"&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>W(!1),className:`px-3 py-1.5 text-xs rounded-md transition-colors duration-150 ${xe?"text-muted hover:bg-[var(--card-hover)]":"bg-[#0066FF] text-white"}`,children:t("config.form")}),e.jsx("button",{onClick:()=>{z($s(b)),W(!0)},className:`px-3 py-1.5 text-xs rounded-md transition-colors duration-150 ${xe?"bg-[#0066FF] text-white":"text-muted hover:bg-[var(--card-hover)]"}`,children:t("config.json")})]}),(M==null?void 0:M.format)==="json"&&xe?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"bg-[#0066FF]/10 border border-[#0066FF]/20 rounded-lg px-3 py-2 text-xs text-[#0066FF]/80 space-y-1",children:[e.jsx("div",{className:"font-medium text-[#0066FF]/90",children:t("config.jsonHelp")}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("config.jsonHelp1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("config.jsonHelp2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("config.jsonHelp3")}})]})]}),e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl overflow-hidden",children:[e.jsx("div",{className:"border-b border-[var(--border)] px-4 py-2 flex items-center justify-between",children:e.jsx("span",{className:"text-xs font-medium text-muted",children:"openclaw.json"})}),e.jsx("textarea",{value:J,onChange:s=>Ms(s.target.value),className:"w-full font-mono text-[13px] p-4 min-h-[400px] lg:min-h-[500px] focus:outline-none resize-y text-foreground bg-transparent",spellCheck:!1})]})]}):Tt&&a?e.jsx(Tt,{config:b,onChange:Ht,instanceId:a,capabilities:o==null?void 0:o.capabilities,isRunning:Ye}):(M==null?void 0:M.format)==="yaml+env"?e.jsx(er,{yaml:String((b==null?void 0:b.yaml)||""),env:String((b==null?void 0:b.env)||""),onYamlChange:Es,onEnvChange:As}):e.jsx(Pa,{config:b,onChange:Ht,instanceId:a,isRunning:Ye,pluginStatuses:ge,onInstallPlugin:Ut}),e.jsxs("div",{className:"flex gap-2 sticky bottom-0 backdrop-blur-sm py-3 -mx-6 px-6 border-t border-[var(--border)] mt-4",style:{background:"color-mix(in srgb, var(--background) 85%, transparent)"},children:[e.jsx("button",{onClick:()=>zt(!1),disabled:!R||E,className:"px-4 py-2 border border-[var(--border)] text-muted rounded-md text-sm font-medium hover:bg-[var(--card-hover)] hover:text-foreground disabled:opacity-40 transition-all duration-200",children:t(E?"config.saving":"config.save")}),e.jsx("button",{onClick:()=>zt(!0),disabled:E,className:"px-4 py-2 bg-[#0066FF] text-white rounded-md text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:t(E?"config.processing":"config.saveAndRestart")})]})]}),n==="logs"&&e.jsx(Ya,{logs:G,logSearch:fe,logType:ee,logsEndRef:ht,onSearchChange:ve,onLogTypeChange:te,onRefresh:Nt,onCopy:()=>{const s=fe?G.filter(r=>r.toLowerCase().includes(fe.toLowerCase())):G;navigator.clipboard.writeText(s.join(`
|
|
91
|
-
`)).then(()=>p(t("logs.copied"),"success")).catch(()=>p(t("logs.copyFailed"),"error"))}}),n==="usage"&&e.jsx(Xa,{usage:g,onRefresh:()=>fs(a).then(N).catch(()=>{})}),X&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:()=>{Ne.current=!0,we.current=!1,pe(null)},children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 w-full max-w-xs shadow-2xl",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:t(X.type==="feishu"?"qr.feishuTitle":"qr.weixinTitle")}),e.jsx("button",{onClick:()=>{Ne.current=!0,we.current=!1,pe(null)},className:"text-muted hover:text-foreground transition-colors text-lg leading-none",children:"✕"})]}),e.jsx("div",{className:"flex flex-col items-center gap-3",children:X.status==="confirmed"?e.jsxs("div",{className:"bg-emerald-500/10 border border-emerald-500/20 rounded-md px-4 py-5 text-center w-full",children:[e.jsx("div",{className:"text-3xl mb-2",children:"✓"}),e.jsx("div",{className:"text-emerald-400 font-medium text-sm",children:X.message}),e.jsx("p",{className:"text-xs text-muted mt-1",children:t("qr.credSaved")})]}):X.status==="loading"?e.jsx("div",{className:"w-48 h-48 flex items-center justify-center",children:e.jsx("div",{className:`w-8 h-8 border-2 rounded-full animate-spin ${X.type==="feishu"?"border-[#3370FF]/30 border-t-[#3370FF]":"border-[#07C160]/30 border-t-[#07C160]"}`})}):X.status==="error"?e.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-md px-4 py-4 text-center w-full",children:[e.jsx("div",{className:"text-red-400 text-sm",children:X.message}),e.jsx("button",{onClick:s=>{s.stopPropagation(),Bt(X.type)},className:`mt-3 px-4 py-1.5 text-white rounded-md text-xs font-medium transition-colors ${X.type==="feishu"?"bg-[#3370FF] hover:bg-[#3370FF]/90":"bg-[#07C160] hover:bg-[#07C160]/90"}`,children:t("qr.retry")})]}):e.jsxs(e.Fragment,{children:[X.qrUrl?e.jsx(ka,{value:X.qrUrl,size:192,className:"rounded-lg"}):e.jsx("div",{className:"w-48 h-48 flex items-center justify-center",children:e.jsx("div",{className:`w-8 h-8 border-2 rounded-full animate-spin ${X.type==="feishu"?"border-[#3370FF]/30 border-t-[#3370FF]":"border-[#07C160]/30 border-t-[#07C160]"}`})}),e.jsx("div",{className:"flex items-center gap-2 text-sm",children:X.status==="scaned"?e.jsxs("span",{className:`font-medium ${X.type==="weixin"?"text-[#07C160]":"text-[#3370FF]"}`,children:["👀 ",X.message]}):e.jsx("span",{className:"text-muted",children:X.message})})]})}),X.status==="confirmed"&&e.jsx("button",{onClick:()=>{Ne.current=!0,we.current=!1,pe(null)},className:"mt-4 w-full py-2 bg-[#0066FF] text-white rounded-md text-sm font-medium hover:bg-[#0066FF]/90 transition-colors",children:t("common:action.close")})]})}),je&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:()=>{he||ae||(F(!1),Q(""),qe(""),Ee(""),We(!1))},children:e.jsxs("div",{className:"bg-background border border-[var(--border)] rounded-xl p-6 w-full max-w-sm shadow-2xl",onClick:s=>s.stopPropagation(),children:[e.jsx("h3",{className:"text-base font-semibold text-foreground mb-2",children:t("delete.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:e.jsx(Ca,{ns:"instance",i18nKey:"delete.warning",values:{name:o.name},components:{strong:e.jsx("strong",{className:"text-foreground"})}})}),e.jsx("p",{className:"text-sm text-muted mb-3",children:t("delete.confirmHint")}),e.jsx("input",{type:"text",value:B,onChange:s=>Q(s.target.value),disabled:he,className:"w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground mb-4 focus:outline-none focus:ring-1 focus:ring-red-500/60 focus:border-red-500/60 transition-colors disabled:opacity-60",placeholder:o.name}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm text-muted mb-2",children:t("delete.sudoPassword",{defaultValue:"sudo 密码(如本次删除涉及系统卸载)"})}),e.jsx("input",{type:"password",value:be,onChange:s=>{qe(s.target.value),Ee("")},disabled:he||ae,className:"w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-1 focus:ring-red-500/60 focus:border-red-500/60 transition-colors disabled:opacity-60",placeholder:t("delete.sudoPasswordPlaceholder",{defaultValue:"需要提权时请输入"}),autoComplete:"current-password"}),Je&&e.jsx("p",{className:"mt-2 text-xs text-red-400",children:Je}),e.jsx("p",{className:"mt-2 text-xs text-muted",children:t("delete.sudoPasswordHint",{defaultValue:"实例删除若会触发底层应用卸载,将使用这里提供的密码执行 sudo。"})})]}),Ct&&e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted cursor-pointer mb-4",children:[e.jsx("input",{type:"checkbox",checked:tt,onChange:s=>We(s.target.checked),disabled:he,className:"rounded border-[var(--border)] bg-[var(--input-bg)]"}),t("delete.purgeBackups",{defaultValue:"同时删除备份"})]}),he&&e.jsx("p",{className:"text-xs text-muted mb-3",children:t("delete.inProgressHint",{defaultValue:"正在删除,大实例可能需要 30 秒到 1 分钟,请勿关闭窗口。"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{F(!1),Q(""),qe(""),Ee(""),We(!1)},disabled:he||ae,className:"flex-1 py-2 border border-[var(--border)] text-muted rounded-md text-sm font-medium hover:bg-[var(--card-hover)] hover:text-foreground transition-all duration-150 disabled:opacity-40 disabled:cursor-not-allowed",children:t("common:action.cancel")}),e.jsxs("button",{onClick:_s,disabled:B.trim()!==((is=o.name)==null?void 0:is.trim())||he||ae,className:"flex-1 py-2 bg-red-600 text-white rounded-md text-sm font-medium hover:bg-red-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors inline-flex items-center justify-center gap-2",children:[(he||ae)&&e.jsx("span",{className:"w-3 h-3 border-2 border-white/40 border-t-white rounded-full animate-spin","aria-hidden":"true"}),he?t("delete.deleting",{defaultValue:"删除中..."}):ae?t("newInstance:sudoDialog.verifying",{defaultValue:"验证中..."}):t("delete.confirm")]})]})]})})]})}export{br as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as s,ae as ds,af as us,ag as cs,d as ms,k as ps,g as fs,ah as gs,o as xs,ai as bs,aj as hs,ak as ys,al as ws,v as vs,ac as Is,am as Ns}from"./index-DQsM6Joa.js";import{u as Lt,r as n,f as js}from"./vendor-react-Bk1hRGiY.js";import{u as Dt}from"./vendor-i18n-ucpM0OR0.js";import{u as Ss,F as Ft,i as Cs}from"./registry-B4UFJdpA.js";function Es({onClose:t,showToast:i}){const{t:l}=Dt("newInstance"),f=Lt(),[y,F]=n.useState("upload"),[j,o]=n.useState(!1),[R,x]=n.useState(""),[S,V]=n.useState(null),ce=n.useRef(null),[Ie,me]=n.useState(""),[G,Re]=n.useState(null),[pe,Ne]=n.useState([]),[je,Se]=n.useState(0),[M,le]=n.useState(""),[I,Ce]=n.useState(""),[T,Me]=n.useState(!1);function _(p){return p.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,63)}function $e(p){return p<1024?`${p}B`:p<1024*1024?`${(p/1024).toFixed(1)}KB`:`${(p/(1024*1024)).toFixed(1)}MB`}const fe=async()=>{var p;if(S){o(!0),x("");try{const d=await ds(S);me(d.temp_id);const b=await us(d.temp_id);Re(b.manifest),Ne(b.warnings||[]),Se(b.estimated_size||0),(p=b.manifest)!=null&&p.name&&(Ce(b.manifest.name),T||le(_(b.manifest.name))),F("preview")}catch(d){x(d.message||"Upload failed")}finally{o(!1)}}},Pe=async()=>{var p;if(!(!M||!I||!Ie)){o(!0),x(""),F("creating");try{const d=await cs({temp_id:Ie,id:M,name:I});d.ok?(i(l("import.success",{defaultValue:"导入成功"}),"success"),(p=d.warnings)!=null&&p.length&&d.warnings.forEach(b=>i(b,"info")),f(`/instances/${d.instance_id}/config`)):(x(d.detail||l("import.failed",{defaultValue:"导入失败"})),F("preview"))}catch(d){x(d.message||"Import failed"),F("preview")}finally{o(!1)}}},Ee="w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground placeholder-[var(--muted)] focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60 focus:border-[#0066FF]/60 transition-colors duration-200";return s.jsxs("div",{className:"space-y-4",children:[R&&s.jsx("div",{className:"bg-red-500/10 border border-red-500/20 text-red-400 text-sm rounded-lg px-3 py-2.5",children:R}),y==="upload"&&s.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl p-5 space-y-4",children:[s.jsx("div",{className:"text-xs text-muted bg-card border border-[var(--border)] rounded-md p-3",children:l("import.uploadDesc",{defaultValue:"上传 .tar.gz 文件(支持 JishuShell 导出包、备份包、OpenClaw 官方备份)"})}),s.jsx("input",{ref:ce,type:"file",accept:".tar.gz,.tgz",onChange:p=>{var d;return V(((d=p.target.files)==null?void 0:d[0])||null)},className:"hidden"}),s.jsx("button",{type:"button",onClick:()=>{var p;return(p=ce.current)==null?void 0:p.click()},className:"w-full flex items-center justify-center gap-2 px-4 py-3 border border-dashed border-[var(--border)] rounded-lg text-sm text-muted hover:text-foreground hover:border-[#0066FF]/40 hover:bg-[var(--input-bg)] transition-colors cursor-pointer",children:S?s.jsxs("span",{className:"text-foreground truncate",children:[S.name," (",(S.size/1024/1024).toFixed(1),"MB)"]}):l("import.selectFile",{defaultValue:"点击选择 .tar.gz 文件"})})]}),y==="preview"&&G&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl p-5 space-y-4",children:[s.jsxs("div",{className:"bg-[var(--input-bg)] border border-[var(--border)] rounded-lg p-4 space-y-2 text-sm",children:[s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted",children:l("import.name",{defaultValue:"名称"})}),s.jsx("span",{className:"text-foreground",children:G.name||"-"})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted",children:l("import.type",{defaultValue:"类型"})}),s.jsx("span",{className:"text-foreground",children:G.type||"unknown"})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted",children:l("import.size",{defaultValue:"大小"})}),s.jsx("span",{className:"text-foreground",children:$e(je)})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted",children:l("import.platform",{defaultValue:"平台"})}),s.jsxs("span",{className:"text-foreground",children:[G.platform||"-"," / ",G.arch||"-"]})]}),G.has_sessions===!1&&s.jsx("div",{className:"text-amber-400 text-xs",children:l("import.noSessions",{defaultValue:"不含对话历史"})})]}),pe.length>0&&s.jsx("div",{className:"space-y-1",children:pe.map((p,d)=>s.jsx("p",{className:"text-xs text-amber-400",children:p},d))}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:l("name.label",{defaultValue:"应用名称"})}),s.jsx("input",{type:"text",value:I,onChange:p=>{Ce(p.target.value),T||le(_(p.target.value))},className:Ee})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:l("id.label",{defaultValue:"应用 ID"})}),s.jsx("input",{type:"text",value:M,onChange:p=>{le(p.target.value),Me(!0)},className:`${Ee} font-mono text-[13px]`})]})]}),s.jsx("button",{className:"w-full bg-[#0066FF] text-white rounded-md py-2.5 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 disabled:cursor-not-allowed transition-all duration-200 shadow-[0_0_20px_rgba(0,102,255,0.3)] hover:shadow-[0_0_28px_rgba(0,102,255,0.45)]",onClick:Pe,disabled:!M||!I||j,children:l("import.create",{defaultValue:"创建应用"})})]}),y==="upload"&&s.jsx("button",{className:"w-full bg-[#0066FF] text-white rounded-md py-2.5 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 disabled:cursor-not-allowed transition-all duration-200 shadow-[0_0_20px_rgba(0,102,255,0.3)] hover:shadow-[0_0_28px_rgba(0,102,255,0.45)]",onClick:fe,disabled:!S||j,children:j?s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx("span",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"}),l("import.uploading",{defaultValue:"上传中..."})]}):l("import.upload",{defaultValue:"上传并预览"})}),y==="creating"&&s.jsxs("div",{className:"flex items-center justify-center py-8 gap-3",children:[s.jsx("span",{className:"w-4 h-4 border-2 border-[#0066FF]/30 border-t-[#0066FF] rounded-full animate-spin"}),s.jsx("span",{className:"text-sm text-muted",children:l("import.creating",{defaultValue:"正在创建应用..."})})]})]})}function Fs(t){return t.type==="done"?"success":t.type==="error"?"error":t.type==="progress"?"progress":"info"}async function Je(t,i={}){var R;const l=i.maxDurationMs??18e5,f=Math.max(200,i.pollIntervalMs??500);let y=Math.max(0,i.initialSeenCount??0),F=0,j="task completed";const o=Date.now()+l;for(;Date.now()<o;){try{const x=await ms(t);F=0;const S=x.events.slice(y);y=x.events.length;for(const V of S)(R=i.onEvent)==null||R.call(i,{message:V.message,progress:V.progress,tone:Fs(V)},{seenCount:y}),V.message&&(j=V.message);if(x.status==="done")return j;if(x.status==="error")throw new Error(j)}catch(x){const S=(x==null?void 0:x.message)||`task ${t} polling failed`;if(/task not found/i.test(S))throw new Error(S);if(F+=1,F>=5)throw new Error(S)}await new Promise(x=>setTimeout(x,f))}throw new Error(`task ${t} timeout`)}const ks="ollama-binary.yaml",kt=new Set(["ollama-binary","ollama-with-hollama-binary"]),Vs=new Set(["searxng-container.yaml","playwright-container.yaml","openwebui-container.yaml"]),ne=40,De="jishushell:new-instance:create-flow",Vt={action:null,kind:null,sourceKey:"",status:"idle",taskId:"",expectedSpecId:"",seenEventCount:0,progress:null,logs:[],lastError:""},_s={openclaw:!1,hermes:!1,ollama:!1,custom:!1};function As(){var t,i;if(typeof window>"u")return null;try{const l=window.sessionStorage.getItem(De);if(!l)return null;const f=JSON.parse(l);return!f||typeof f!="object"?null:((t=f.templateInstall)==null?void 0:t.status)==="running"&&!!((i=f.templateInstall)!=null&&i.taskId)&&!!f.pendingCreate?f:(window.sessionStorage.removeItem(De),null)}catch{return null}}function Ks(t){return/already running|已在运行/i.test(t)}function Ls(t){return/task not found|未找到.*任务/i.test(t)}function Ds(t){return/sudo 密码无效|invalid sudo password|provided sudo password invalid/i.test(t)}const Rs=[{id:"openclaw",icon:"🦞",labelKey:"tab.openclaw",descKey:"appDesc.openclaw"},{id:"hermes",icon:"🧠",iconImage:"/logos/hermes.png",labelKey:"tab.hermes",descKey:"appDesc.hermes"},{id:"ollama",icon:"🦙",iconImage:"/logos/ollama.png",labelKey:"tab.ollama",descKey:"appDesc.ollama"},{id:"custom",icon:"🧩",labelKey:"tab.custom",descKey:"appDesc.custom"}];function Ms(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,63)}function ue(t){return t.trim().toLowerCase()}function _t(t){return`${typeof t.progress=="number"&&t.progress>0?`[${t.progress}%] `:""}${t.message}`}function At(t){var i;for(let l=t.length-1;l>=0;l-=1){const f=((i=t[l])==null?void 0:i.trim())??"";if(/^(curl|sudo|su)\b/.test(f))return f}return""}function $s(t,i){return t?typeof t.seenEventCount=="number"&&t.seenEventCount>0?t.seenEventCount:t.logs.filter(l=>!!l&&l!==i).length:0}function Oe(t){var l;const i=t.match(/^\s*id:\s*["']?([^"'\s#]+)["']?\s*$/m);return((l=i==null?void 0:i[1])==null?void 0:l.trim())??""}function Ps(t){var l;const i=t.match(/^\s*name:\s*["']?([^"'\n#][^\n#]*?)["']?\s*$/m);return((l=i==null?void 0:i[1])==null?void 0:l.trim())??""}function qs(t,i){const l=t.trim().toLowerCase();if(!l)return"";if(!i.has(l))return l;for(let f=1;f<1e4;f+=1){const y=`${l}-${f}`.slice(0,63);if(!i.has(y))return y}return l}function zs(t,i){const l=t.trim();if(!l)return"";const f=ue(l);if(!i.has(f))return l;for(let y=1;y<1e4;y+=1){const F=`${l}-${y}`;if(!i.has(ue(F)))return F}return l}function Ts(t){return[...t].sort((i,l)=>new Date(l.installed_at).getTime()-new Date(i.installed_at).getTime())}function Kt(t,i){return Ts(t).find(i)??null}function Bs(t,i,l,f){return t==="builtin"?`builtin:${(i==null?void 0:i.id)??""}`:t==="url"?`url:${l.trim()}`:`yaml:${Oe(f)||"inline"}`}const de="w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground placeholder-[var(--muted)] focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60 focus:border-[#0066FF]/60 transition-colors duration-200";function Ws(){var gt,xt,bt,ht,yt,wt,vt,It,Nt,jt,St,Ct,Et;const{t}=Dt("newInstance"),[i]=js(),l=n.useRef(As()),f=i.get("showCustom")==="1",y=(gt=l.current)==null?void 0:gt.createKind,F=y==="custom"&&!f?"openclaw":y??"openclaw",{runtimes:j}=Ss(),[o,R]=n.useState(F),[x,S]=n.useState(null),[V,ce]=n.useState(null),[Ie,me]=n.useState({}),[G,Re]=n.useState([]),[pe,Ne]=n.useState(!1),[je,Se]=n.useState(""),[M,le]=n.useState(((xt=l.current)==null?void 0:xt.selectedBuiltinTemplate)??""),[I,Ce]=n.useState(((bt=l.current)==null?void 0:bt.customSourceMode)??"builtin"),[T,Me]=n.useState(((ht=l.current)==null?void 0:ht.appSpecUrl)??""),[_,$e]=n.useState(((yt=l.current)==null?void 0:yt.appSpecYaml)??""),[fe,Pe]=n.useState([]),[Ee,p]=n.useState({}),[d,b]=n.useState(((wt=l.current)==null?void 0:wt.templateInstall)??Vt),[k,X]=n.useState(((vt=l.current)==null?void 0:vt.pendingCreate)??null),[Z,ge]=n.useState(null),[Fe,ee]=n.useState(""),[We,B]=n.useState(""),[J,qe]=n.useState(!1),[A,Qe]=n.useState(((It=l.current)==null?void 0:It.name)??""),[ke,Xe]=n.useState(((Nt=l.current)==null?void 0:Nt.nameEdited)??!1),[$,ze]=n.useState(((jt=l.current)==null?void 0:jt.id)??""),[xe,Ze]=n.useState(((St=l.current)==null?void 0:St.idEdited)??!1),[re,Us]=n.useState(((Ct=l.current)==null?void 0:Ct.description)??""),[et,Rt]=n.useState(""),[Ve,Mt]=n.useState([]),[$t,Ys]=n.useState(!0),[Pt,qt]=n.useState(!1),[zt,C]=n.useState(""),[Te,Tt]=n.useState(()=>({..._s})),Bt=i.get("import")==="true",_e=Lt(),{showToast:O}=ps(),tt=n.useRef({name:"",id:""}),Be=n.useRef(""),Ue=n.useCallback(()=>{fs().then(S).catch(()=>{})},[]),W=n.useCallback(async()=>{try{const e=await gs();return Pe(e),e}catch{return[]}},[]),U=n.useCallback((e,r)=>{Tt(a=>a[e]===r?a:{...a,[e]:r})},[]),Ye=n.useCallback(async(e,r,a={})=>{const w=(await W()).filter(u=>u.install_mode==="app-dir"&&(a.allowInstalling||u.status!=="installing"));return e.kind==="ollama"?Kt(w,u=>u.id===e.appId||!!r&&u.spec_id===r||u.spec_id===e.appId):w.find(u=>u.id===e.appId)??null},[W]);n.useEffect(()=>{xs().then(Mt).catch(()=>{}),Ue(),W(),Ne(!0),bs().then(e=>{Re(e),Se("")}).catch(e=>{Se((e==null?void 0:e.message)||t("template.loadFailed"))}).finally(()=>{Ne(!1)})},[W,Ue]);const st=n.useRef(!1),be=o==="hermes"?"hermes":"openclaw",at=G.filter(e=>e.instanceCompatible),nt=Rs.filter(e=>f||e.id!=="custom"),m=at.find(e=>e.fileName===ks)??null,Ut=(m==null?void 0:m.id)??"ollama-binary",te=at.filter(e=>e.suggestedAppType==="custom"&&Vs.has(e.fileName)),h=te.find(e=>e.fileName===M)??te[0]??null,se=[...fe].filter(e=>e.install_mode==="app-dir").sort((e,r)=>new Date(r.installed_at).getTime()-new Date(e.installed_at).getTime()),P=Kt(se,e=>kt.has(e.id)||kt.has(e.spec_id)),Ae=I==="builtin"?(h==null?void 0:h.id)??"":I==="yaml"?Oe(_):"",lt=I==="builtin"?(h==null?void 0:h.name)??(h==null?void 0:h.id)??"":I==="yaml"?Ps(_)||Oe(_):"",oe=Bs(I,h,T,_),He=`ollama:${Ut}`,Y=(P==null?void 0:P.status)==="installing"?"installing":P?"installed":"missing",Q=(P==null?void 0:P.status)==="installing"?"":(P==null?void 0:P.id)??"",H=$.trim(),rt=Ee[oe]??"",Yt=rt?se.find(e=>e.id===rt)??null:null,Ht=H?se.find(e=>e.id===H&&(!Ae||e.spec_id===Ae))??null:null,q=Yt??Ht,Gt=new Set([...se.map(e=>e.id),...Ve.map(e=>typeof(e==null?void 0:e.id)=="string"?e.id:"")].filter(Boolean)),Jt=new Set([...se.map(e=>typeof(e==null?void 0:e.name)=="string"&&e.name.trim()?e.name:e.id),...Ve.map(e=>typeof(e==null?void 0:e.name)=="string"?e.name:"")].filter(Boolean).map(e=>ue(e))),he=Ae?qs(Ae,Gt):"",ye=lt?zs(lt,Jt):"",Ot=(q==null?void 0:q.status)==="installing"?"installing":q?"installed":d.kind==="custom"&&d.sourceKey===oe&&d.status==="running"?"installing":"missing",Ge=(q==null?void 0:q.status)==="installing"?"":(q==null?void 0:q.id)??"";n.useEffect(()=>{!f&&o==="custom"&&R("openclaw")},[o,f]),n.useEffect(()=>{if(d.status!=="running"&&!fe.some(r=>r.status==="installing"))return;const e=setInterval(()=>{W()},1e3);return()=>clearInterval(e)},[fe,W,d.status]),n.useEffect(()=>{if(st.current||!x||j.length===0||o==="custom"||o==="ollama")return;st.current=!0;const e=j.find(a=>a.agentType===be);if(e!=null&&e.isInstalled(x))return;const r=j.find(a=>(a.agentType==="openclaw"||a.agentType==="hermes")&&a.isInstalled(x));r&&R(r.agentType==="hermes"?"hermes":"openclaw")},[o,j,be,x]),n.useEffect(()=>{if(te.length&&!M){const e=te[0];e&&le(e.fileName)}},[te,M]),n.useEffect(()=>{if(!(typeof window>"u")){if(d.status==="running"&&d.taskId&&k){const e={createKind:o,customSourceMode:I,selectedBuiltinTemplate:M,appSpecUrl:T,appSpecYaml:_,name:A,nameEdited:ke,id:$,idEdited:xe,description:re,templateInstall:d,pendingCreate:k};window.sessionStorage.setItem(De,JSON.stringify(e));return}window.sessionStorage.removeItem(De)}},[T,_,o,I,re,$,xe,A,ke,k,M,d]),n.useEffect(()=>{if(o!=="custom"||!he||!ye)return;const e=tt.current,r=!A.trim()||!ke||A===e.name,a=!$.trim()||!xe||$===e.id;r&&A!==ye&&(Qe(ye),Xe(!1)),a&&$!==he&&(ze(he),Ze(!1)),tt.current={name:ye,id:he}},[o,$,xe,A,ke,he,ye]);const K=j.find(e=>e.agentType===be)||Ft.find(e=>e.agentType===be)||j[0]||Ft[0],Ke=ue(A),ot=Ke?Ve.find(e=>typeof(e==null?void 0:e.name)=="string"&&ue(e.name)===Ke):null,Wt=H?Ve.find(e=>(e==null?void 0:e.id)===H):null,Qt=H?se.find(e=>e.id===H):null,it=Ke?se.find(e=>ue(typeof(e==null?void 0:e.name)=="string"&&e.name.trim()?e.name:e.id)===Ke):null,Le=ot?t("name.duplicate",{name:A.trim(),id:ot.id,defaultValue:"应用名称“{{name}}”已存在(ID: {{id}})"}):it?t("name.duplicate",{name:A.trim(),id:it.id,defaultValue:"应用名称“{{name}}”已存在(ID: {{id}})"}):Wt?t("id.duplicate",{id:H,defaultValue:"应用 ID“{{id}}”已存在"}):Qt?t("id.duplicate",{id:H,defaultValue:"应用 ID“{{id}}”已存在"}):"",Xt=o==="ollama"||o==="custom",dt=o==="ollama"?Y:o==="custom"?Ot:"missing",ae=o==="ollama"?(m==null?void 0:m.name)??(m==null?void 0:m.id)??"Ollama":A.trim(),z=o==="ollama"?Q||(m==null?void 0:m.id)||"":H,Zt=(o==="ollama"||o==="custom")&&((k==null?void 0:k.kind)===o||dt==="installing"),ut=Te[o]||Zt,ie=Xt&&dt==="installing"?t("install.waitingCompletion",{defaultValue:"当前模板正在安装中,请等待安装完成"}):"",ct=Le||zt,es=async e=>{if(!V){C(""),ce(e.agentType),me(r=>({...r,[e.agentType]:{message:"准备安装...",tone:"progress"}}));try{const r=await Cs(e);r!=null&&r.taskId&&await Je(r.taskId,{onEvent:a=>{me(c=>({...c,[e.agentType]:a}))}}),Ue(),O(`${e.displayName} 安装完成`,"success"),R(e.agentType==="hermes"?"hermes":"openclaw")}catch(r){const a=(r==null?void 0:r.message)||`${e.displayName} 安装失败`;C(a),O(a,"error")}finally{ce(null),setTimeout(()=>{me(r=>({...r,[e.agentType]:null}))},3e3)}}},ts=e=>{C(""),Qe(e),o==="custom"&&Xe(!0),xe||ze(Ms(e))},ss=e=>{R(e),C(""),e!=="openclaw"&&(Rt(""),qt(!1))},as=()=>{if(o==="ollama"){if(!(m!=null&&m.yaml))throw new Error(t("template.ollamaRequired"));return{flow:{kind:"ollama",sourceKey:He,appId:m.id,name:m.name??m.id,description:m.description??""},payload:{yaml:m.yaml},existingInstalledAppId:Q}}if(o!=="custom")throw new Error(t("failed"));if(!z||!ae)throw new Error(t("install.identityRequired",{defaultValue:"请先确认应用名称和应用 ID"}));if(I==="builtin"){if(!(h!=null&&h.yaml))throw new Error(t("template.none"));return{flow:{kind:"custom",sourceKey:oe,appId:z,name:ae,description:re},payload:{yaml:h.yaml,requestedAppId:z},existingInstalledAppId:Ge}}if(I==="url"){if(!T.trim())throw new Error(t("custom.urlRequired"));return{flow:{kind:"custom",sourceKey:oe,appId:z,name:ae,description:re},payload:{url:T.trim(),requestedAppId:z},existingInstalledAppId:Ge}}if(!_.trim())throw new Error(t("custom.yamlRequired"));return{flow:{kind:"custom",sourceKey:oe,appId:z,name:ae,description:re},payload:{yaml:_.trim(),requestedAppId:z},existingInstalledAppId:Ge}},we=n.useCallback(async(e,r,a)=>{const c=t("install.waitingLogs",{defaultValue:"等待安装日志..."}),w=$s(a,c);b(N=>{var g;return{...N,action:"install",kind:e.kind,sourceKey:e.sourceKey,status:"running",taskId:(a==null?void 0:a.taskId)??N.taskId,expectedSpecId:(a==null?void 0:a.expectedSpecId)??N.expectedSpecId,seenEventCount:w,progress:(a==null?void 0:a.progress)??N.progress??null,logs:(g=a==null?void 0:a.logs)!=null&&g.length?a.logs:[c],lastError:""}});let u=(a==null?void 0:a.taskId)??"",v=(a==null?void 0:a.expectedSpecId)??"",E=null;try{if(!u){if(!r)throw new Error(t("install.missingTask",{defaultValue:"未找到可恢复的安装任务,请重新点击创建应用"}));const g=await hs(r);u=g.taskId,v=g.expectedSpecId??"",b(L=>({...L,action:"install",kind:e.kind,sourceKey:e.sourceKey,taskId:u,expectedSpecId:v,logs:g.reused?[...L.logs,t("install.reusedTask",{defaultValue:"检测到已有安装任务,继续显示该任务日志。"})].slice(-ne):L.logs}))}try{await Je(u,{pollIntervalMs:400,initialSeenCount:w,onEvent:(g,L)=>{b(D=>({...D,progress:typeof g.progress=="number"&&g.progress>0?g.progress:D.progress,seenEventCount:Math.max(D.seenEventCount,(L==null?void 0:L.seenCount)??D.seenEventCount),logs:[...D.logs,_t(g)].slice(-ne)}))}})}catch(g){const L=(g==null?void 0:g.message)||"";if(!Ls(L))throw g;if(E=await Ye(e,v,{allowInstalling:!0}),!(E!=null&&E.id))throw new Error(t("install.taskStateLost",{defaultValue:"安装任务状态已丢失(通常是服务重启后清空了内存任务),请重新点击创建应用"}));if(E.status==="installing")throw new Error(t("install.taskStateLostInstalling",{defaultValue:"安装任务状态已丢失,且应用仍显示为安装中。通常是服务在安装过程中重启,请稍后刷新;若状态不恢复,请重新点击创建应用"}));b(D=>({...D,logs:[...D.logs,t("install.taskRecovered",{defaultValue:"安装任务状态已丢失,但检测到应用已经安装完成,继续后续启动。"})].slice(-ne)}))}if(E=E??await Ye(e,v),!(E!=null&&E.id))throw new Error(t("install.notFoundAfterInstall",{defaultValue:"安装完成后未找到应用,请刷新页面后重试"}));const N=E.id;return e.kind==="custom"&&p(g=>({...g,[e.sourceKey]:N})),b(g=>({...g,action:"install",kind:e.kind,sourceKey:e.sourceKey,status:"done",progress:100})),N}catch(N){const g=(N==null?void 0:N.message)||t("install.failed",{defaultValue:"模板安装失败"});throw b(L=>{const D=[...L.logs,g].slice(-ne),is=At(D);return{...L,action:"install",kind:e.kind,sourceKey:e.sourceKey,status:"error",lastError:is?t("install.manualRequired",{defaultValue:"当前环境无法自动提权,请在终端手动执行下方命令后重新点击创建应用。"}):g,logs:D}}),new Error(g)}},[Ye,t]),mt=n.useCallback(async(e,r,a)=>{b({action:"uninstall",kind:e.kind,sourceKey:e.sourceKey,status:"running",taskId:"",expectedSpecId:"",seenEventCount:0,progress:null,logs:[t("uninstall.waitingLogs",{defaultValue:"等待卸载日志..."})],lastError:""});try{const c=await ys(r,{sudoPassword:a}),w=c.taskId;b(u=>({...u,taskId:w,logs:c.reused?[...u.logs,t("uninstall.reusedTask",{defaultValue:"检测到已有卸载任务,继续显示该任务日志。"})].slice(-ne):u.logs})),await Je(w,{pollIntervalMs:400,onEvent:u=>{b(v=>({...v,progress:typeof u.progress=="number"&&u.progress>0?u.progress:v.progress,logs:[...v.logs,_t(u)].slice(-ne)}))}}),await W(),X(null),b(u=>({...u,status:"done",progress:100})),O(t("uninstall.success",{defaultValue:"Ollama 已卸载"}),"success")}catch(c){const w=(c==null?void 0:c.message)||t("uninstall.failed",{defaultValue:"卸载失败"});throw b(u=>({...u,status:"error",lastError:w,logs:[...u.logs,w].slice(-ne)})),new Error(w)}},[W,O,t]),pt=n.useCallback(()=>{J||(ge(null),ee(""),B(""))},[J]),ve=n.useCallback(async(e,r)=>{e.kind==="custom"&&await ws(r,{name:e.name,description:e.description});try{await vs(r)}catch(c){const w=(c==null?void 0:c.message)||"";if(!Ks(w))throw c}const a=t("create.startedSuccess",{name:e.name||r,defaultValue:"应用 {{name}} 创建成功并已启动"});X(null),b(Vt),O(a,"success"),_e(`/instances/${r}/chat`)},[_e,O,t]),ns=n.useCallback(async()=>{if(!Z||J)return;if(!Fe){B(t("sudoDialog.passwordRequired",{defaultValue:"请输入 sudo 密码。"}));return}C(""),B("");const e=Z,r=Fe.trim();qe(!0);try{await Is({sudoPassword:r})}catch(a){const c=(a==null?void 0:a.message)||t("sudoDialog.passwordInvalid",{defaultValue:"sudo 密码错误,请重新输入。"});B(c),ee(""),qe(!1);return}ge(null),ee(""),B(""),U(e.flow.kind,!0),qe(!1);try{if(e.action==="uninstall"){await mt(e.flow,e.appId||e.flow.appId,r);return}X(e.flow);const a=e.existingInstalledAppId||await we(e.flow,{...e.payload,sudoPassword:r});await ve(e.flow,a)}catch(a){X(null);const c=(a==null?void 0:a.message)||t("failed");Ds(c)?(ee(""),ge(e),B(c),C("")):C(c)}finally{U(e.flow.kind,!1)}},[we,U,ve,Fe,Z,J,t,mt]);n.useEffect(()=>{k&&(Te[k.kind]||d.status!=="running"||!d.taskId||Be.current!==d.taskId&&(Be.current=d.taskId,(async()=>{C(""),U(k.kind,!0);try{const e=await we(k,void 0,d);await ve(k,e)}catch(e){X(null),C((e==null?void 0:e.message)||t("failed"))}finally{Be.current="",U(k.kind,!1)}})()))},[Te,we,k,U,ve,t,d]);const ls=async e=>{if(e.preventDefault(),o!=="ollama"&&(!z||!ae))return;if(Le){C(Le);return}if(ie){C(ie);return}C("");let r=null;try{if(o==="ollama"&&Y==="installed"&&Q){const v={kind:"ollama",sourceKey:He,appId:Q,name:(m==null?void 0:m.name)??Q,description:(m==null?void 0:m.description)??""};ee(""),B(""),ge({action:"uninstall",flow:v,appId:Q});return}if(o==="ollama"||o==="custom"){const{flow:v,payload:E,existingInstalledAppId:N}=as();if(!N&&(o==="ollama"||o==="custom")){ee(""),B(""),ge({action:"install",flow:v,payload:E,existingInstalledAppId:N});return}r=v.kind,U(v.kind,!0),X(v);const g=N||await we(v,E);await ve(v,g);return}r=o,U(o,!0);const a={id:z,name:ae,description:re};if(o==="openclaw"||o==="hermes"){if(!K.isInstalled(x))throw new Error(t("runtime.installFirst",{name:K.displayName}));a.agentType=be}o==="openclaw"&&K.supportsClone&&et&&(a.clone_from=et,a.clone_options={include_sessions:Pt,include_memory:$t});const c=await Ns(a),w=typeof(c==null?void 0:c.id)=="string"&&c.id?c.id:$,u=c==null?void 0:c.port_allocation;u&&typeof u.assigned=="number"&&typeof u.requested=="number"&&u.assigned!==u.requested&&O(t("portReallocated",{defaultValue:"默认端口 {{requested}} 被占用,已自动使用 {{assigned}}",requested:u.requested,assigned:u.assigned}),"info"),_e(c!=null&&c.autoStarted?`/instances/${w}`:`/instances/${w}/config`)}catch(a){X(null),C(a.message||t("failed"))}finally{r&&U(r,!1)}},rs=()=>{const e=K.isInstalled(x),r=V===K.agentType,a=Ie[K.agentType];return s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("runtime.label")}),s.jsxs("div",{className:"rounded-lg border border-[var(--border)] p-4 bg-[var(--input-bg)] space-y-3",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"text-sm font-medium text-foreground flex items-center gap-2",children:[K.displayName,!e&&s.jsx("span",{className:"text-[10px] text-amber-400 font-normal px-1.5 py-0.5 rounded bg-amber-500/10 border border-amber-500/20",children:t("runtime.notInstalled")})]}),s.jsx("p",{className:"text-xs text-muted mt-1",children:K.description}),K.installHint&&!e&&s.jsx("p",{className:"text-xs text-muted mt-2",children:K.installHint})]}),e&&s.jsx("span",{className:"text-xs text-emerald-400 font-medium",children:t("runtime.ready")})]}),!e&&s.jsx("button",{type:"button",onClick:()=>es(K),disabled:!!V,className:"px-3 py-1.5 bg-[#0066FF] text-white rounded-md text-xs font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:r?s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx("span",{className:"w-3 h-3 border-2 border-white/30 border-t-white rounded-full animate-spin"}),t("runtime.installing")]}):V?t("runtime.waitingOtherInstall"):t("runtime.install",{name:K.displayName})}),(a==null?void 0:a.message)&&s.jsxs("div",{className:"text-[11px] font-mono text-muted truncate",title:a.message,children:[typeof a.progress=="number"&&a.progress>0?`[${a.progress}%] `:"",a.message]})]})]})},ft=(e,r)=>{if(!(d.kind===e&&d.sourceKey===r&&(d.status!=="idle"||d.logs.length>0)))return null;const w=At(d.logs);return s.jsxs("div",{className:"rounded-lg border border-[var(--border)] bg-background/60 px-3 py-3 space-y-2",children:[s.jsx("div",{className:"text-xs",children:s.jsx("span",{className:"text-muted",children:d.action==="uninstall"?t("uninstall.logs",{defaultValue:"卸载日志"}):t("install.logs",{defaultValue:"安装日志"})})}),s.jsx("div",{className:"max-h-52 overflow-y-auto rounded-md border border-[var(--border)] bg-black/30 px-3 py-2 font-mono text-[11px] leading-5 text-muted space-y-1",children:d.logs.map((u,v)=>s.jsx("div",{children:u},`${v}-${u}`))}),d.lastError&&s.jsx("p",{className:"text-xs text-red-400",children:d.lastError}),w&&s.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 space-y-1",children:[s.jsx("p",{className:"text-[11px] text-amber-200",children:t("install.manualCommandLabel",{defaultValue:"请在终端执行以下命令后,再重新点击创建应用:"})}),s.jsx("pre",{className:"font-mono text-[11px] text-amber-50 whitespace-pre-wrap break-all",children:w})]})]})},os=()=>{if(o==="ollama"){const e=Y==="installed"?"text-emerald-400 border-emerald-500/20 bg-emerald-500/10":Y==="installing"?"text-amber-400 border-amber-500/20 bg-amber-500/10":"text-muted border-[var(--border)] bg-background/40",r=Y==="installed"?t("install.installedShort",{defaultValue:"已安装"}):Y==="installing"?t("install.installingShort",{defaultValue:"安装中"}):t("install.notInstalledShort",{defaultValue:"未安装"});return s.jsx("div",{className:"space-y-3",children:pe?s.jsx("div",{className:"rounded-lg border border-[var(--border)] p-4 bg-[var(--input-bg)] text-sm text-muted",children:t("template.loading")}):m?s.jsxs("div",{className:"rounded-lg border border-[var(--border)] p-4 bg-[var(--input-bg)] space-y-3",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:m.name}),m.description&&s.jsx("p",{className:"text-xs text-muted mt-1 leading-5",children:m.description})]}),s.jsx("span",{className:`shrink-0 rounded-full border px-2 py-0.5 text-[11px] font-medium ${e}`,children:r})]}),Y==="installed"&&Q&&s.jsx("p",{className:"text-xs text-muted",children:t("install.installedAppId",{id:Q,defaultValue:"已安装应用 ID: {{id}}"})}),Y==="installed"&&s.jsx("p",{className:"text-xs text-muted leading-5",children:t("uninstall.requiresSudo",{defaultValue:"卸载 Ollama 时会再次弹出 sudo 密码输入框。"})})]}):s.jsx("div",{className:"rounded-lg border border-[var(--border)] p-4 bg-[var(--input-bg)] text-sm text-amber-400",children:je||t("template.ollamaRequired")})})}return o!=="custom"?null:s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("source.label")}),s.jsx("div",{className:"grid grid-cols-3 gap-2",children:["builtin","url","yaml"].map(e=>{const r=I===e;return s.jsx("button",{type:"button",onClick:()=>Ce(e),className:`rounded-md border px-3 py-2 text-sm transition-all ${r?"border-[#0066FF]/70 bg-[#0066FF]/5 text-foreground":"border-[var(--border)] text-muted hover:text-foreground hover:bg-[var(--card-hover)]"}`,children:t(`source.${e}`)},e)})})]}),I==="builtin"&&s.jsxs("div",{className:"rounded-lg border border-[var(--border)] p-4 bg-[var(--input-bg)] space-y-3",children:[s.jsx("p",{className:"text-xs text-muted",children:t("template.compatibilityHint")}),pe?s.jsx("div",{className:"text-sm text-muted",children:t("template.loading")}):te.length===0?s.jsx("div",{className:"text-sm text-amber-400",children:je||t("template.none")}):s.jsxs(s.Fragment,{children:[s.jsx("select",{value:(h==null?void 0:h.fileName)??"",onChange:e=>le(e.target.value),className:`${de} appearance-none`,children:te.map(e=>s.jsx("option",{value:e.fileName,className:"bg-background text-foreground",children:e.name},e.fileName))}),(h==null?void 0:h.description)&&s.jsx("p",{className:"text-xs text-muted leading-5",children:h.description})]})]}),I==="url"&&s.jsxs("div",{className:"rounded-lg border border-[var(--border)] p-4 bg-[var(--input-bg)] space-y-2",children:[s.jsx("input",{type:"url",value:T,onChange:e=>Me(e.target.value),placeholder:t("source.urlPlaceholder"),className:de}),s.jsx("p",{className:"text-xs text-muted leading-5",children:t("source.urlHint")})]}),I==="yaml"&&s.jsxs("div",{className:"rounded-lg border border-[var(--border)] p-4 bg-[var(--input-bg)] space-y-2",children:[s.jsx("label",{className:"block text-sm font-medium text-muted",children:t("custom.yamlTitle")}),s.jsx("textarea",{value:_,onChange:e=>$e(e.target.value),placeholder:t("custom.yamlPlaceholder"),className:`${de} min-h-[220px] resize-y font-mono text-[12px] leading-5`}),s.jsx("p",{className:"text-xs text-muted leading-5",children:t("custom.yamlHint")})]})]})};return Bt?s.jsxs("div",{className:"p-6 max-w-lg mx-auto",children:[s.jsxs("div",{className:"mb-6",children:[s.jsx("h1",{className:"text-lg font-semibold text-foreground",children:t("import.title",{defaultValue:"导入实例"})}),s.jsx("p",{className:"text-sm text-muted mt-0.5",children:t("import.subtitle",{defaultValue:"从文件导入 OpenClaw 实例"})})]}),s.jsx(Es,{onClose:()=>_e("/instances/new"),showToast:O})]}):s.jsxs("div",{className:"p-6 max-w-4xl mx-auto",children:[s.jsxs("div",{className:"mb-6",children:[s.jsx("h1",{className:"text-lg font-semibold text-foreground",children:t("title")}),s.jsx("p",{className:"text-sm text-muted mt-0.5",children:t("subtitle")})]}),s.jsxs("form",{onSubmit:ls,className:"space-y-5",children:[ct&&s.jsx("div",{className:"bg-red-500/10 border border-red-500/20 text-red-400 text-sm rounded-lg px-3 py-2.5",children:ct}),s.jsxs("div",{className:"bg-card border border-[var(--border)] rounded-xl p-6 space-y-5",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("kind.label")}),s.jsx("div",{className:"overflow-x-auto pb-1",children:s.jsx("div",{className:"inline-flex min-w-full rounded-xl border border-[var(--border)] bg-[var(--input-bg)] p-1 gap-1 flex-nowrap",children:nt.map(e=>{const r=o===e.id;return s.jsxs("button",{type:"button",onClick:()=>ss(e.id),className:`flex min-w-[140px] flex-1 items-center justify-center gap-2 rounded-lg px-4 py-2.5 text-sm font-medium transition-all ${r?"bg-[#0066FF] text-white shadow-[0_8px_24px_rgba(0,102,255,0.24)]":"text-muted hover:bg-[var(--card-hover)] hover:text-foreground"}`,children:[e.iconImage?s.jsx("img",{src:e.iconImage,alt:"","aria-hidden":"true",className:"h-5 w-5 object-contain"}):s.jsx("span",{className:"text-base leading-none",children:e.icon}),s.jsx("span",{children:t(e.labelKey)})]},e.id)})})}),s.jsx("p",{className:"text-xs text-muted mt-2 leading-5",children:t(((Et=nt.find(e=>e.id===o))==null?void 0:Et.descKey)||"appDesc.openclaw")})]}),(o==="openclaw"||o==="hermes")&&rs(),(o==="ollama"||o==="custom")&&os(),o!=="ollama"&&s.jsx(s.Fragment,{children:s.jsxs("div",{className:"grid gap-4 lg:grid-cols-[1.1fr_0.9fr]",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("name.label")}),s.jsx("input",{type:"text",value:A,onChange:e=>ts(e.target.value),placeholder:t("name.placeholder"),className:de,autoFocus:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("id.label")}),s.jsx("input",{type:"text",value:$,onChange:e=>{C(""),ze(e.target.value),Ze(!0)},placeholder:t("id.placeholder"),className:`${de} font-mono text-[13px]`}),s.jsx("p",{className:"text-xs text-muted mt-1",children:A&&!$?s.jsx("span",{className:"text-amber-400",children:t("id.invalid")}):t("id.hint")})]})]})})]}),ie&&s.jsx("p",{className:"text-xs text-amber-400",children:ie}),s.jsx("div",{className:"flex flex-col gap-3",children:s.jsx("button",{type:"submit",disabled:ut||o!=="ollama"&&(!z||!ae)||!!Le||!!ie||o==="ollama"&&!m,className:"w-full bg-[#0066FF] text-white rounded-md py-2.5 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 disabled:cursor-not-allowed transition-all duration-200 shadow-[0_0_20px_rgba(0,102,255,0.3)] hover:shadow-[0_0_28px_rgba(0,102,255,0.45)]",children:ie?t("install.installing",{defaultValue:"安装中..."}):ut?s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx("span",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"}),d.action==="uninstall"?t("uninstall.loading",{defaultValue:"卸载中"}):t("loading")]}):o==="ollama"&&Y==="installed"?t("uninstall.submit",{defaultValue:"卸载 Ollama"}):t("submit")})}),o==="ollama"&&ft("ollama",He),o==="custom"&&ft("custom",oe)]}),Z&&s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:pt,children:s.jsxs("div",{className:"w-full max-w-md rounded-xl border border-[var(--border)] bg-background p-6 shadow-2xl space-y-4",onClick:e=>e.stopPropagation(),children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-base font-semibold text-foreground",children:Z.action==="uninstall"?t("sudoDialog.uninstallTitle",{defaultValue:"输入 sudo 密码以继续卸载 Ollama"}):t("sudoDialog.title",{defaultValue:"输入 sudo 密码以继续安装应用"})}),s.jsx("p",{className:"mt-1 text-xs text-muted leading-relaxed",children:Z.action==="uninstall"?t("sudoDialog.uninstallBody",{defaultValue:"当前卸载步骤需要 sudo 提权。密码只会用于这次卸载请求,不会写入应用配置或任务日志。"}):t("sudoDialog.body",{defaultValue:"当前安装步骤需要 sudo 提权。密码只会用于这次安装请求,不会写入应用配置或任务日志。"})})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("sudoDialog.passwordLabel",{defaultValue:"sudo 密码"})}),s.jsx("input",{type:"password",value:Fe,onChange:e=>{ee(e.target.value),B("")},placeholder:t("sudoDialog.passwordPlaceholder",{defaultValue:"输入当前用户的 sudo 密码"}),className:de,disabled:J,autoFocus:!0}),We&&s.jsx("p",{className:"mt-2 text-xs text-red-400",children:We})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[s.jsx("button",{type:"button",onClick:pt,disabled:J,className:"px-3 py-1.5 text-xs rounded-md border border-[var(--border)] text-muted hover:bg-[var(--card-hover)] hover:text-foreground transition-colors",children:t("sudoDialog.cancel",{defaultValue:"取消"})}),s.jsx("button",{type:"button",onClick:ns,disabled:J,className:"px-3 py-1.5 text-xs rounded-md bg-[#0066FF] text-white hover:bg-[#0066FF]/90 transition-colors",children:J?t("sudoDialog.verifying",{defaultValue:"验证中..."}):Z.action==="uninstall"?t("sudoDialog.uninstallConfirm",{defaultValue:"继续卸载"}):t("sudoDialog.confirm",{defaultValue:"继续安装"})})]})]})})]})}export{Ws as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ao as ke,ap as Ae,o as Me,E as Se,j as e,I as Z,a as T,aq as Ce,s as Ke,ar as Pe,p as ie,as as Ie,at as $e,au as Ue,av as Ee,aw as Le}from"./index-DQsM6Joa.js";import{r as d}from"./vendor-react-Bk1hRGiY.js";import{g as oe}from"./input-paste-CrNVAyOy.js";import{P as F}from"./providers-V-vwrExZ.js";import{u as ee}from"./vendor-i18n-ucpM0OR0.js";function Be({showToast:a}){var re;const{t}=ee("settings"),{t:w}=ee("instance"),[x,I]=d.useState([]),[$,U]=d.useState(!0),[c,E]=d.useState(null),[V,L]=d.useState(!1),[B,f]=d.useState(!1),[H,D]=d.useState(null),[k,j]=d.useState([]),[i,A]=d.useState(""),[r,p]=d.useState(""),[y,h]=d.useState(""),[se,J]=d.useState(!1),[te,_]=d.useState(""),[q,Y]=d.useState(""),[O,le]=d.useState(!1),[M,z]=d.useState([]),ce={name:"",baseUrl:"",api:"openai",apiKey:"",authHeader:"",selectedModelId:""},[o,g]=d.useState(ce),[ae,me]=d.useState(!1),S=d.useCallback(()=>{U(!0),Pe().then(I).catch(()=>I([])).finally(()=>U(!1))},[]);d.useEffect(()=>{S()},[S]);const v="w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground placeholder-[var(--muted)] focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60 focus:border-[#0066FF]/60 transition-colors duration-200",G="w-full bg-background border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60 focus:border-[#0066FF]/60 transition-colors duration-200 appearance-none",ue=()=>{E(null),A(""),p(""),h(""),_(""),Y(""),J(!1),z([]),j([]),L(!0)},xe=s=>{L(!1),j([]),g({name:s.name||s.id,baseUrl:s.baseUrl,api:s.api,apiKey:"",authHeader:s.authHeader||"",selectedModelId:s.selectedModelId||""}),E(s.id)},W=()=>{L(!1),E(null),j([]),A(""),p(""),h(""),_(""),Y(""),J(!1),z([])},pe=async()=>{var ne;if(!i){a(t("llm.presetRequired"),"error");return}const s=F.find(u=>u.id===i),l=s.local===!0;if(!l&&!r.trim()){a(t("llm.apiKeyRequired"),"error");return}if(l&&!y.trim()&&!s.baseUrl){a(t("llm.baseUrlRequired"),"error");return}const m=x.map(u=>u.id),b=q.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");let N=b?`${i}-${b}`:i;if(m.includes(N)){if(b){a(t("llm.aliasConflict"),"error");return}let u=2;for(;m.includes(`${i}-${u}`);)u++;N=`${i}-${u}`}const R=q.trim()?`${s.label} (${q.trim()})`:s.label,n=M.length>0?M.map(u=>({id:u.id,name:u.id,contextWindow:0})):s.models,P=te||((ne=n[0])==null?void 0:ne.id)||"";f(!0);try{await Ie({id:N,name:R,baseUrl:(l?y.trim():void 0)||s.baseUrl,api:s.api,apiKey:r||void 0,authHeader:s.authHeader?"x-api-key":void 0,models:n,selectedModelId:P}),a(t("llm.added"),"success"),W(),S()}catch(u){a(u.message||t("llm.saveFailed"),"error")}finally{f(!1)}},Q=async(s,l={})=>{if(!i)return;const m=F.find(n=>n.id===i),b=m.authHeader?"x-api-key":"Authorization",N=m.local===!0&&y.trim()?y.trim():m.baseUrl,R=s??r;le(!0);try{const{models:n}=await ie(N,R,b);z(n),n.length>0&&_(P=>P||n[0].id),l.silentSuccess||a(t("llm.modelsFetched",{count:n.length}),"success")}catch(n){a(n.message||t("llm.modelsFetchFailed"),"error")}finally{le(!1)}},he=s=>{if(!i||O)return;const l=F.find(b=>b.id===i);if(!l||l.local===!0)return;const m=oe(r,s).trim();m&&Q(m,{silentSuccess:!0})},be=async(s,l={})=>{if(!c)return;const m=o.baseUrl.trim();if(!m)return;const b=c,N=s??o.apiKey,R=o.authHeader.trim()||"Authorization";D(b);try{const{models:n}=await ie(m,N,R);j(n),n.length>0&&g(P=>({...P,selectedModelId:P.selectedModelId||n[0].id})),l.silentSuccess||a(t("llm.modelsFetched",{count:n.length}),"success")}catch(n){a(n.message||t("llm.modelsFetchFailed"),"error")}finally{D(n=>n===b?null:n)}},ge=s=>{if(!c||H===c)return;const l=oe(o.apiKey,s).trim();l&&be(l,{silentSuccess:!0})},ve=async()=>{if(c){if(!o.baseUrl.trim()){a(t("llm.baseUrlRequired"),"error");return}f(!0);try{await $e(c,{name:o.name||c,baseUrl:o.baseUrl.trim(),api:o.api,apiKey:o.apiKey||void 0,authHeader:o.authHeader||void 0,selectedModelId:o.selectedModelId||void 0}),a(t("llm.updated"),"success"),W(),S()}catch(s){a(s.message||t("llm.saveFailed"),"error")}finally{f(!1)}}},fe=async s=>{if(window.confirm(t("llm.confirmDelete",{id:s})))try{await Le(s),a(t("llm.deleted"),"success"),S()}catch(l){a(l.message||t("llm.deleteFailed"),"error")}},je=async s=>{try{await Ue(s),a(t("llm.defaultSet",{id:s}),"success"),S()}catch(l){a(l.message,"error")}},ye=async s=>{D(s);try{const{models:l}=await Ee(s);j(l),a(t("llm.modelsFetched",{count:l.length}),"success")}catch(l){a(l.message||t("llm.modelsFetchFailed"),"error")}finally{D(null)}},Ne=[...new Set(F.map(s=>s.group))],C=F.find(s=>s.id===i),de=(C==null?void 0:C.local)===!0,X=M.length>0?M.map(s=>({id:s.id,label:s.id})):((C==null?void 0:C.models)||[]).map(s=>({id:s.id,label:`${s.name} (${Math.round(s.contextWindow/1e3)}K)`})),Fe=e.jsxs("div",{className:"mt-3 border border-[var(--border)] rounded-lg p-4 space-y-3 bg-[var(--input-bg)]/40",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("llm.addTitle")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.presetLabel")}),e.jsxs("select",{value:i,onChange:s=>{const l=F.find(m=>m.id===s.target.value);A(s.target.value),h((l==null?void 0:l.baseUrl)||""),_(""),z([])},className:G,children:[e.jsx("option",{value:"",children:t("llm.presetPlaceholder")}),Ne.map(s=>e.jsx("optgroup",{label:w(`configForm.providerGroup.${s}`,{defaultValue:s}),children:F.filter(l=>l.group===s).map(l=>e.jsx("option",{value:l.id,children:w(`configForm.providerLabel.${l.id}`,{defaultValue:l.label})},l.id))},s))]})]}),i&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.alias")}),e.jsx("input",{value:q,onChange:s=>Y(s.target.value),placeholder:t("llm.aliasPlaceholder"),className:v}),e.jsx("p",{className:"text-[11px] text-muted mt-0.5",children:t("llm.aliasHint")})]}),i&&!de&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.fieldApiKey")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:se?"text":"password",value:r,onChange:s=>p(s.target.value),onPaste:he,placeholder:t("llm.apiKeyPlaceholder"),className:`${v} pr-9 font-mono`}),e.jsx("button",{type:"button",onClick:()=>J(s=>!s),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground transition-colors",children:se?e.jsx(Z,{className:"w-3.5 h-3.5"}):e.jsx(T,{className:"w-3.5 h-3.5"})})]}),e.jsx("button",{type:"button",onClick:()=>{Q()},disabled:O,className:"px-3 py-1.5 text-xs border border-[var(--border)] rounded-md hover:bg-[var(--input-bg)] disabled:opacity-40 transition-all whitespace-nowrap",children:t(O?"llm.fetchingModels":"llm.fetchModels")})]})]}),i&&de&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.fieldBaseUrl")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:y,onChange:s=>h(s.target.value),className:`${v} flex-1`}),e.jsx("button",{type:"button",onClick:()=>{Q()},disabled:O,className:"px-3 py-1.5 text-xs border border-[var(--border)] rounded-md hover:bg-[var(--input-bg)] disabled:opacity-40 transition-all whitespace-nowrap",children:t(O?"llm.fetchingModels":"llm.fetchModels")})]})]}),i&&X.length>0&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs text-muted mb-1",children:[t("llm.fieldModel"),M.length>0&&e.jsxs("span",{className:"ml-1 text-green-500 text-[10px]",children:["(",M.length," ",t("llm.liveModels"),")"]})]}),e.jsx("select",{value:te||((re=X[0])==null?void 0:re.id)||"",onChange:s=>_(s.target.value),className:G,children:X.map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx("button",{onClick:pe,disabled:B,className:"px-4 py-1.5 bg-[#0066FF] text-white rounded-md text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all",children:t(B?"llm.saving":"llm.save")}),e.jsx("button",{onClick:W,className:"px-4 py-1.5 border border-[var(--border)] rounded-md text-sm hover:bg-[var(--input-bg)] transition-all",children:t("llm.cancel")})]})]}),K=x.find(s=>s.id===c),we=e.jsxs("div",{className:"mt-3 border border-[var(--border)] rounded-lg p-4 space-y-3 bg-[var(--input-bg)]/40",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("llm.editTitle",{id:c})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.fieldName")}),e.jsx("input",{value:o.name,onChange:s=>g(l=>({...l,name:s.target.value})),placeholder:t("llm.fieldNamePlaceholder"),className:v})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsxs("label",{className:"block text-xs text-muted mb-1",children:[t("llm.fieldBaseUrl")," *"]}),e.jsx("input",{value:o.baseUrl,onChange:s=>g(l=>({...l,baseUrl:s.target.value})),placeholder:"https://api.openai.com",className:v})]}),e.jsxs("div",{className:"col-span-2 sm:col-span-1",children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.fieldApi")}),e.jsxs("select",{value:o.api,onChange:s=>g(l=>({...l,api:s.target.value})),className:G,children:[e.jsx("option",{value:"openai",children:"OpenAI"}),e.jsx("option",{value:"openai-completions",children:"OpenAI Completions"}),e.jsx("option",{value:"anthropic",children:"Anthropic"}),e.jsx("option",{value:"anthropic-messages",children:"Anthropic Messages"})]})]}),e.jsxs("div",{className:"col-span-2 sm:col-span-1",children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.fieldAuthHeader")}),e.jsx("input",{value:o.authHeader,onChange:s=>g(l=>({...l,authHeader:s.target.value})),placeholder:"Authorization",className:v})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsxs("label",{className:"block text-xs text-muted mb-1",children:[t("llm.fieldApiKey"),K!=null&&K.hasApiKey?` (${t("llm.apiKeyConfigured")})`:""]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:ae?"text":"password",value:o.apiKey,onChange:s=>g(l=>({...l,apiKey:s.target.value})),onPaste:ge,placeholder:K!=null&&K.hasApiKey?t("llm.apiKeyLeaveBlank"):t("llm.apiKeyPlaceholder"),className:`${v} pr-9 font-mono`}),e.jsx("button",{type:"button",onClick:()=>me(s=>!s),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground transition-colors",children:ae?e.jsx(Z,{className:"w-3.5 h-3.5"}):e.jsx(T,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.fieldModel")}),k.length>0?e.jsxs("select",{value:o.selectedModelId,onChange:s=>g(l=>({...l,selectedModelId:s.target.value})),className:G,children:[e.jsx("option",{value:"",children:t("llm.noModel")}),k.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}):e.jsx("input",{value:o.selectedModelId,onChange:s=>g(l=>({...l,selectedModelId:s.target.value})),placeholder:"gpt-4o",className:v})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx("button",{onClick:ve,disabled:B,className:"px-4 py-1.5 bg-[#0066FF] text-white rounded-md text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all",children:t(B?"llm.saving":"llm.save")}),e.jsx("button",{onClick:W,className:"px-4 py-1.5 border border-[var(--border)] rounded-md text-sm hover:bg-[var(--input-bg)] transition-all",children:t("llm.cancel")})]})]});return e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-medium text-foreground",children:t("llm.title")}),e.jsx("p",{className:"text-xs text-muted mt-0.5",children:t("llm.desc")})]}),!V&&!c&&e.jsxs("button",{onClick:ue,className:"px-3 py-1.5 bg-[#0066FF] text-white rounded-md text-xs font-medium hover:bg-[#0066FF]/90 transition-all",children:["+ ",t("llm.add")]})]}),V&&Fe,$?e.jsx("p",{className:"text-sm text-muted py-3",children:t("llm.loading")}):x.length===0&&!V?e.jsx("p",{className:"text-sm text-muted py-3",children:t("llm.empty")}):e.jsx("div",{className:"space-y-2 mt-2",children:x.map(s=>e.jsxs("div",{className:`border rounded-lg p-3 transition-all ${s.isDefault?"border-[#0066FF]/40 bg-[#0066FF]/5":"border-[var(--border)]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:s.name||s.id}),s.isDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-[#0066FF]/15 text-[#0066FF] rounded font-medium",children:t("llm.default")}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-[var(--input-bg)] text-muted rounded",children:s.api}),s.hasApiKey&&e.jsx("span",{className:"text-[10px] text-green-500",children:"🔑"})]}),e.jsx("p",{className:"text-xs text-muted truncate mt-0.5",children:s.baseUrl}),s.selectedModelId&&e.jsxs("p",{className:"text-xs text-muted mt-0.5",children:[t("llm.model"),": ",e.jsx("span",{className:"font-mono",children:s.selectedModelId})]})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[!s.isDefault&&e.jsx("button",{onClick:()=>je(s.id),className:"px-2 py-1 text-xs border border-[var(--border)] rounded hover:bg-[var(--input-bg)] transition-all",children:t("llm.setDefault")}),e.jsx("button",{onClick:()=>{xe(s),ye(s.id)},disabled:H===s.id,className:"px-2 py-1 text-xs border border-[var(--border)] rounded hover:bg-[var(--input-bg)] transition-all disabled:opacity-40",children:H===s.id?"...":t("llm.edit")}),e.jsx("button",{onClick:()=>fe(s.id),disabled:x.length<=1,title:x.length<=1?t("llm.deleteLastForbidden"):void 0,className:"px-2 py-1 text-xs border border-red-500/30 text-red-400 rounded hover:bg-red-500/10 transition-all disabled:opacity-30 disabled:cursor-not-allowed disabled:pointer-events-none",children:t("llm.delete")})]})]}),c===s.id&&we,H===null&&k.length>0&&c!==s.id&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-[var(--border)]",children:[e.jsxs("p",{className:"text-xs text-muted mb-1",children:[t("llm.availableModels")," (",k.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1 max-h-20 overflow-y-auto",children:k.map(l=>e.jsx("span",{className:"text-[11px] font-mono px-1.5 py-0.5 bg-[var(--input-bg)] rounded",children:l.id},l.id))})]})]},s.id))})]})}function Ve(){const{t:a}=ee("settings"),{system:t,showToast:w}=ke(),[x,I]=d.useState(""),[$,U]=d.useState(""),[c,E]=d.useState(!1),[V,L]=d.useState([]),[B,f]=d.useState(!1),[H,D]=d.useState(!1),[k,j]=d.useState(!1);d.useEffect(()=>{f(!0),Ae().then(L).catch(()=>{}).finally(()=>f(!1)),Me().then(async r=>{try{const p=await Promise.all(r.map(h=>Se(h.id).catch(()=>({enabled:!1})))),y=r.length>0&&p.every(h=>h==null?void 0:h.enabled);j(y)}catch{}}).catch(()=>{})},[]);const i=async r=>{r.preventDefault();try{const p=await Ce(x,$);p.token&&Ke(p.token),w(a("password.updated"),"success"),I(""),U("")}catch(p){w(p.message||a("password.failed"),"error")}},A="w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground placeholder-[var(--muted)] focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60 focus:border-[#0066FF]/60 transition-colors duration-200";return e.jsxs("div",{className:"p-6 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"mb-5",children:[e.jsx("h1",{className:"text-lg font-semibold text-foreground",children:a("title")}),e.jsx("p",{className:"text-sm text-muted mt-0.5",children:a("subtitle")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl p-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-medium text-foreground",children:a("proxy.title")}),e.jsx("p",{className:"text-sm text-muted mt-1",children:a("proxy.desc")})]}),e.jsx("div",{className:"mt-3 bg-red-500/10 border border-red-500/20 text-red-400 text-sm rounded-lg px-4 py-3",children:a("proxy.status")})]}),e.jsx(Be,{showToast:w}),e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl p-4",children:[e.jsx("h2",{className:"text-sm font-medium text-foreground mb-3",children:a("password.title")}),e.jsxs("form",{onSubmit:i,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted mb-1.5",children:a("password.current")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:c?"text":"password",value:x,onChange:r=>I(r.target.value),placeholder:a("password.currentPlaceholder"),className:`${A} pr-9`}),e.jsx("button",{type:"button",onClick:()=>E(!c),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground transition-colors",children:c?e.jsx(Z,{className:"w-3.5 h-3.5"}):e.jsx(T,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted mb-1.5",children:a("password.new")}),e.jsx("input",{type:c?"text":"password",value:$,onChange:r=>U(r.target.value),placeholder:a("password.newPlaceholder"),className:A})]}),e.jsx("button",{type:"submit",disabled:!x||$.length<8,className:"px-4 py-2 bg-[#0066FF] text-white rounded-md text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:a("password.submit")})]})]}),t&&e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl p-4",children:[e.jsx("h2",{className:"text-sm font-medium text-foreground mb-3",children:a("system.title")}),e.jsxs("div",{className:"space-y-3",children:[[{label:a("system.cpuUsage"),value:`${t.cpu_percent}%`,percent:t.cpu_percent,warn:t.cpu_percent>90,color:"bg-[#0066FF]"},{label:a("system.memory"),value:`${t.memory.used_mb}MB / ${t.memory.total_mb}MB (${t.memory.percent}%)`,percent:t.memory.percent,warn:!1,color:"bg-[#00D4AA]"},{label:a("system.disk"),value:`${t.disk.used_gb}GB / ${t.disk.total_gb}GB (${t.disk.percent}%)`,percent:t.disk.percent,warn:t.disk.percent>90,color:"bg-[#0066FF]"}].map(r=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1.5",children:[e.jsx("span",{className:"text-muted",children:r.label}),e.jsx("span",{className:`font-medium font-mono text-[13px] ${r.warn?"text-red-400":"text-foreground"}`,children:r.value})]}),e.jsx("div",{className:"w-full bg-[var(--input-bg)] rounded-full h-1.5",children:e.jsx("div",{className:`h-1.5 rounded-full transition-all duration-500 ${r.warn?"bg-red-500":r.color}`,style:{width:`${r.percent}%`}})})]},r.label)),t.temperature&&e.jsxs("div",{className:"flex justify-between text-sm pt-2 border-t border-[var(--border)]",children:[e.jsx("span",{className:"text-muted",children:a("system.cpuTemp")}),e.jsxs("span",{className:"font-medium font-mono text-[13px] text-foreground",children:[t.temperature,"°C"]})]})]})]}),e.jsxs("div",{className:"bg-[var(--card)] border border-[var(--border)] rounded-xl p-4",children:[e.jsx("h2",{className:"text-sm font-medium text-foreground mb-2",children:a("about.title")}),e.jsx("div",{className:"text-sm text-muted space-y-1",children:e.jsxs("p",{children:["JishuShell ","0.4.24"]})})]})]})]})}export{Ve as default};
|