jishushell 0.4.30 → 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/apps/anythingllm-container.yaml +287 -0
- package/apps/browserless-chromium-container.yaml +18 -6
- package/apps/filebrowser-container.yaml +163 -0
- package/apps/openclaw-binary.yaml +8 -0
- package/apps/openclaw-container.yaml +9 -1
- package/apps/openclaw-with-searxng-container.yaml +4 -0
- package/apps/searxng-container.yaml +5 -4
- package/apps/weknora-container.yaml +471 -0
- 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/install.js +3 -3
- package/dist/install.js.map +1 -1
- package/dist/routes/auth.js +2 -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 +45 -7
- 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/setup.js +9 -9
- 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.js +341 -3
- package/dist/server.js.map +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 +1 -0
- package/dist/services/app/app-manager.js +172 -41
- 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 +1 -0
- 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-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/connection-apply.d.ts +2 -0
- package/dist/services/connection-apply.js +55 -1
- package/dist/services/connection-apply.js.map +1 -1
- package/dist/services/connection-resolver.js +1 -1
- package/dist/services/connection-resolver.js.map +1 -1
- package/dist/services/connection-transactor.d.ts +2 -0
- package/dist/services/connection-transactor.js +12 -2
- package/dist/services/connection-transactor.js.map +1 -1
- 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.js +1 -23
- package/dist/services/instance-manager.js.map +1 -1
- package/dist/services/llm-proxy/index.js.map +1 -1
- package/dist/services/llm-proxy/ssrf.js +6 -2
- 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 +53 -19
- 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 +3 -2
- package/dist/services/process-manager.js.map +1 -1
- package/dist/services/runtime/adapters/hermes.js +1 -1
- package/dist/services/runtime/adapters/hermes.js.map +1 -1
- 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 +90 -0
- package/dist/services/runtime/adapters/openclaw.js +957 -45
- 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/types.d.ts +31 -0
- package/dist/services/setup-manager.js +93 -18
- package/dist/services/setup-manager.js.map +1 -1
- package/dist/services/suggestions.js.map +1 -1
- 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 +60 -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-write.d.ts +24 -0
- package/dist/utils/safe-write.js +82 -0
- package/dist/utils/safe-write.js.map +1 -0
- package/package.json +16 -1
- package/public/assets/Dashboard-BdWPtroF.js +1 -0
- package/public/assets/{HermesChatPanel-_GHoklgo.js → HermesChatPanel-B_2HlVBQ.js} +1 -1
- package/public/assets/{HermesConfigForm-anDnwUp_.js → HermesConfigForm-DVlhg3WV.js} +2 -2
- package/public/assets/{InitPassword-ZU9_-hDr.js → InitPassword-D7glTExX.js} +1 -1
- package/public/assets/InstanceDetail-CxSy2cpe.js +92 -0
- package/public/assets/{Login-BItXqYAJ.js → Login-Cfr5c2sv.js} +1 -1
- package/public/assets/NewInstance-BIYDmJis.js +1 -0
- package/public/assets/{ProviderRecommendations-DFYj7Fb6.js → ProviderRecommendations-BuRnvRcI.js} +1 -1
- package/public/assets/{Settings-Bttc6QmM.js → Settings-Cc-tYBil.js} +1 -1
- package/public/assets/{Setup-Bsxx1zgj.js → Setup-lGZEk5jq.js} +1 -1
- package/public/assets/{WeixinLoginPanel-DPZpAKgO.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/{registry-5s2UB6is.js → registry-BWnkJgZ1.js} +2 -2
- 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 +18 -4
- 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/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-rkWp-CXd.js +0 -1
- package/public/assets/InstanceDetail-CN0FH1aw.js +0 -92
- package/public/assets/NewInstance-BousE6kY.js +0 -1
- package/public/assets/index-8xZy1z5k.css +0 -1
- package/public/assets/index-Dw3HhUYE.js +0 -19
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as s,ai as xs,aj as bs,ak as hs,d as ys,k as ws,g as vs,al as Is,o as Ns,am as js,an as Ss,ao as Cs,ap as Es,v as _s,ag as Fs,aq as ks}from"./index-BZc5zH7u.js";import{u as Pt,r as l,f as As}from"./vendor-react-BWrEVJVb.js";import{u as $t}from"./vendor-i18n-y9V7Sfuu.js";import{u as Vs,F as At,i as Ks}from"./registry-BWnkJgZ1.js";function Ls({onClose:t,showToast:i}){const{t:n}=$t("newInstance"),m=Pt(),[y,j]=l.useState("upload"),[P,C]=l.useState(!1),[r,E]=l.useState(""),[f,$]=l.useState(null),_=l.useRef(null),[me,Pe]=l.useState(""),[K,$e]=l.useState(null),[Ie,Ne]=l.useState([]),[je,Se]=l.useState(0),[W,T]=l.useState(""),[Q,ie]=l.useState(""),[O,Qe]=l.useState(!1);function V(g){return g.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,63)}function Xe(g){return g<1024?`${g}B`:g<1024*1024?`${(g/1024).toFixed(1)}KB`:`${(g/(1024*1024)).toFixed(1)}MB`}const pe=async()=>{var g;if(f){C(!0),E("");try{const d=await xs(f);Pe(d.temp_id);const b=await bs(d.temp_id);$e(b.manifest),Ne(b.warnings||[]),Se(b.estimated_size||0),(g=b.manifest)!=null&&g.name&&(ie(b.manifest.name),O||T(V(b.manifest.name))),j("preview")}catch(d){E(d.message||"Upload failed")}finally{C(!1)}}},Te=async()=>{var g;if(!(!W||!Q||!me)){C(!0),E(""),j("creating");try{const d=await hs({temp_id:me,id:W,name:Q});d.ok?(i(n("import.success",{defaultValue:"导入成功"}),"success"),(g=d.warnings)!=null&&g.length&&d.warnings.forEach(b=>i(b,"info")),m(`/instances/${d.instance_id}/config`)):(E(d.detail||n("import.failed",{defaultValue:"导入失败"})),j("preview"))}catch(d){E(d.message||"Import failed"),j("preview")}finally{C(!1)}}},Ce="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:n("import.uploadDesc",{defaultValue:"上传 .tar.gz 文件(支持 JishuShell 导出包、备份包、OpenClaw 官方备份)"})}),s.jsx("input",{ref:_,type:"file",accept:".tar.gz,.tgz",onChange:g=>{var d;return $(((d=g.target.files)==null?void 0:d[0])||null)},className:"hidden"}),s.jsx("button",{type:"button",onClick:()=>{var g;return(g=_.current)==null?void 0:g.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:f?s.jsxs("span",{className:"text-foreground truncate",children:[f.name," (",(f.size/1024/1024).toFixed(1),"MB)"]}):n("import.selectFile",{defaultValue:"点击选择 .tar.gz 文件"})})]}),y==="preview"&&K&&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:n("import.name",{defaultValue:"名称"})}),s.jsx("span",{className:"text-foreground",children:K.name||"-"})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted",children:n("import.type",{defaultValue:"类型"})}),s.jsx("span",{className:"text-foreground",children:K.type||"unknown"})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted",children:n("import.size",{defaultValue:"大小"})}),s.jsx("span",{className:"text-foreground",children:Xe(je)})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted",children:n("import.platform",{defaultValue:"平台"})}),s.jsxs("span",{className:"text-foreground",children:[K.platform||"-"," / ",K.arch||"-"]})]}),K.has_sessions===!1&&s.jsx("div",{className:"text-amber-400 text-xs",children:n("import.noSessions",{defaultValue:"不含对话历史"})})]}),Ie.length>0&&s.jsx("div",{className:"space-y-1",children:Ie.map((g,d)=>s.jsx("p",{className:"text-xs text-amber-400",children:g},d))}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:n("name.label",{defaultValue:"应用名称"})}),s.jsx("input",{type:"text",value:Q,onChange:g=>{ie(g.target.value),O||T(V(g.target.value))},className:Ce})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:n("id.label",{defaultValue:"应用 ID"})}),s.jsx("input",{type:"text",value:W,onChange:g=>{T(g.target.value),Qe(!0)},className:`${Ce} 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:Te,disabled:!W||!Q||P,children:n("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:pe,disabled:!f||P,children:P?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"}),n("import.uploading",{defaultValue:"上传中..."})]}):n("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:n("import.creating",{defaultValue:"正在创建应用..."})})]})]})}function Ds(t){return t.type==="done"?"success":t.type==="error"?"error":t.type==="progress"?"progress":"info"}async function He(t,i={}){var r;const n=i.maxDurationMs??18e5,m=Math.max(200,i.pollIntervalMs??500);let y=Math.max(0,i.initialSeenCount??0),j=0,P="task completed";const C=Date.now()+n;for(;Date.now()<C;){let E=null;try{const f=await ys(t);j=0;const $=f.events.slice(y);y=f.events.length;for(const _ of $)(r=i.onEvent)==null||r.call(i,{message:_.message,progress:_.progress,tone:Ds(_)},{seenCount:y}),_.message&&(P=_.message);if(f.status==="done")return P;f.status==="error"&&(E=new Error(P))}catch(f){const $=(f==null?void 0:f.message)||`task ${t} polling failed`;if((f==null?void 0:f.code)==="TASK_NOT_FOUND"||/task not found/i.test($))throw new Error($);if(j+=1,j>=5)throw new Error($)}if(E)throw E;await new Promise(f=>setTimeout(f,m))}throw new Error(`task ${t} timeout`)}const Rs="ollama-binary.yaml",Vt=new Set(["ollama-binary","ollama-with-hollama-binary"]),Ms=["searxng-container.yaml","browserless-chromium-container.yaml","filebrowser-container.yaml","anythingllm-container.yaml","weknora-container.yaml"],Re=40,Me="jishushell:new-instance:create-flow",Kt={action:null,kind:null,sourceKey:"",status:"idle",taskId:"",expectedSpecId:"",seenEventCount:0,progress:null,logs:[],lastError:""},Ps={openclaw:!1,hermes:!1,ollama:!1,custom:!1};function $s(){var t,i;if(typeof window>"u")return null;try{const n=window.sessionStorage.getItem(Me);if(!n)return null;const m=JSON.parse(n);return!m||typeof m!="object"?null:((t=m.templateInstall)==null?void 0:t.status)==="running"&&!!((i=m.templateInstall)!=null&&i.taskId)&&!!m.pendingCreate?m:(window.sessionStorage.removeItem(Me),null)}catch{return null}}function Ts(t){return(t==null?void 0:t.code)==="INSTANCE_ALREADY_RUNNING"?!0:/already running|已在运行/i.test((t==null?void 0:t.message)||"")}function qs(t){return(t==null?void 0:t.code)==="TASK_NOT_FOUND"?!0:/task not found|未找到.*任务/i.test((t==null?void 0:t.message)||"")}function zs(t){return(t==null?void 0:t.code)==="INVALID_SUDO_PASSWORD"?!0:/sudo 密码无效|invalid sudo password|provided sudo password invalid|sudo 密码错误/i.test((t==null?void 0:t.message)||"")}const Bs=[{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 Us(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,63)}function ce(t){return t.trim().toLowerCase()}function Lt(t){return`${typeof t.progress=="number"&&t.progress>0?`[${t.progress}%] `:""}${t.message}`}function Dt(t){var i;for(let n=t.length-1;n>=0;n-=1){const m=((i=t[n])==null?void 0:i.trim())??"";if(/^(curl|sudo|su)\b/.test(m))return m}return""}function Os(t,i){return t?typeof t.seenEventCount=="number"&&t.seenEventCount>0?t.seenEventCount:t.logs.filter(n=>!!n&&n!==i).length:0}function Le(t,i,n){return[...t.length===1&&t[0]===n?[]:t,i].slice(-Re)}function We(t){var n;const i=t.match(/^\s*id:\s*["']?([^"'\s#]+)["']?\s*$/m);return((n=i==null?void 0:i[1])==null?void 0:n.trim())??""}function Ys(t){var n;const i=t.match(/^\s*name:\s*["']?([^"'\n#][^\n#]*?)["']?\s*$/m);return((n=i==null?void 0:i[1])==null?void 0:n.trim())??""}function Gs(t,i){const n=t.trim().toLowerCase();if(!n)return"";if(!i.has(n))return n;for(let m=1;m<1e4;m+=1){const y=`${n}-${m}`.slice(0,63);if(!i.has(y))return y}return n}function Hs(t,i){const n=t.trim();if(!n)return"";const m=ce(n);if(!i.has(m))return n;for(let y=1;y<1e4;y+=1){const j=`${n}-${y}`;if(!i.has(ce(j)))return j}return n}function Js(t){return[...t].sort((i,n)=>new Date(n.installed_at).getTime()-new Date(i.installed_at).getTime())}function Rt(t,i){return Js(t).find(i)??null}function Ws(t,i,n,m){return t==="builtin"?`builtin:${(i==null?void 0:i.id)??""}`:t==="url"?`url:${n.trim()}`:`yaml:${We(m)||"inline"}`}function Mt(t,i,n,m){if(i.kind===n&&i.sourceKey===m){if(i.status==="running")return"installing";if(i.status==="error")return(t==null?void 0:t.status)==="installed"?"installed":"missing"}return(t==null?void 0:t.status)==="installing"?"installing":t?"installed":"missing"}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",Je={openclaw:"openclaw","hermes-agent":"hermes",ollama:"ollama"};function aa(){var ht,yt,wt,vt,It,Nt,jt,St,Ct,Et,_t,Ft,kt;const{t}=$t("newInstance"),[i]=As(),n=l.useRef($s()),m=i.get("app")??"",y=m&&Je[m]?Je[m]:m?"custom":null,j=m&&!Je[m]?`${m}.yaml`:"",P=y??((ht=n.current)==null?void 0:ht.createKind)??"openclaw",{runtimes:C}=Vs(),[r,E]=l.useState(P),[f,$]=l.useState(null),[_,me]=l.useState(null),[Pe,K]=l.useState({}),[$e,Ie]=l.useState([]),[Ne,je]=l.useState(!1),[Se,W]=l.useState(""),[T,Q]=l.useState(j||((yt=n.current)==null?void 0:yt.selectedBuiltinTemplate)||""),[ie]=l.useState(j?"builtin":((wt=n.current)==null?void 0:wt.customSourceMode)??"builtin"),[O,Qe]=l.useState(((vt=n.current)==null?void 0:vt.appSpecUrl)??""),[V,Xe]=l.useState(((It=n.current)==null?void 0:It.appSpecYaml)??""),[pe,Te]=l.useState([]),[Ce,g]=l.useState({}),[d,b]=l.useState(((Nt=n.current)==null?void 0:Nt.templateInstall)??Kt),[L,X]=l.useState(((jt=n.current)==null?void 0:jt.pendingCreate)??null),[Z,fe]=l.useState(null),[Ee,ee]=l.useState(""),[Ze,q]=l.useState(""),[Y,qe]=l.useState(!1),[k,et]=l.useState(((St=n.current)==null?void 0:St.name)??""),[_e,tt]=l.useState(((Ct=n.current)==null?void 0:Ct.nameEdited)??!1),[D,ze]=l.useState(((Et=n.current)==null?void 0:Et.id)??""),[ge,st]=l.useState(((_t=n.current)==null?void 0:_t.idEdited)??!1),[de,Qs]=l.useState(((Ft=n.current)==null?void 0:Ft.description)??""),[at,Tt]=l.useState(""),[Fe,qt]=l.useState([]),[zt,Xs]=l.useState(!0),[Bt,Ut]=l.useState(!1),[Ot,S]=l.useState(""),[Be,Yt]=l.useState(()=>({...Ps})),Gt=i.get("import")==="true",ke=Pt(),{showToast:G}=ws(),nt=l.useRef({name:"",id:""}),Ue=l.useRef(""),Oe=l.useCallback(()=>{vs().then($).catch(()=>{})},[]),R=l.useCallback(async()=>{try{const e=await Is();return Te(e),e}catch{return[]}},[]),z=l.useCallback((e,o)=>{Yt(a=>a[e]===o?a:{...a,[e]:o})},[]),Ye=l.useCallback(async(e,o,a={})=>{const v=(await R()).filter(u=>u.install_mode==="app-dir"&&(a.allowInstalling||u.status!=="installing"));return e.kind==="ollama"?Rt(v,u=>u.id===e.appId||!!o&&u.spec_id===o||u.spec_id===e.appId):v.find(u=>u.id===e.appId)??null},[R]);l.useEffect(()=>{Ns().then(qt).catch(()=>{}),Oe(),R(),je(!0),js().then(e=>{Ie(e),W("")}).catch(e=>{W((e==null?void 0:e.message)||t("template.loadFailed"))}).finally(()=>{je(!1)})},[R,Oe]);const lt=l.useRef(!1),xe=r==="hermes"?"hermes":"openclaw",rt=$e.filter(e=>e.instanceCompatible),ot=Bs,p=rt.find(e=>e.fileName===Rs)??null,Ht=(p==null?void 0:p.id)??"ollama-binary",Jt=new Map(rt.map(e=>[e.fileName,e])),te=Ms.map(e=>Jt.get(e)).filter(e=>!!e&&e.suggestedAppType==="custom"),h=te.find(e=>e.fileName===T)??te[0]??null,se=[...pe].filter(e=>e.install_mode==="app-dir").sort((e,o)=>new Date(o.installed_at).getTime()-new Date(e.installed_at).getTime()),ae=Rt(se,e=>Vt.has(e.id)||Vt.has(e.spec_id)),ne=d.kind==="custom"&&d.status==="running"?ie:"builtin",Ae=ne==="builtin"?(h==null?void 0:h.id)??"":ne==="yaml"?We(V):"",it=ne==="builtin"?(h==null?void 0:h.name)??(h==null?void 0:h.id)??"":ne==="yaml"?Ys(V)||We(V):"",le=Ws(ne,h,O,V),be=`ollama:${Ht}`,B=Mt(ae,d,"ollama",be),H=(ae==null?void 0:ae.status)==="installing"?"":(ae==null?void 0:ae.id)??"",U=D.trim(),dt=Ce[le]??"",Wt=dt?se.find(e=>e.id===dt)??null:null,Qt=U?se.find(e=>e.id===U&&(!Ae||e.spec_id===Ae))??null:null,re=Wt??Qt,Xt=new Set([...se.map(e=>e.id),...Fe.map(e=>typeof(e==null?void 0:e.id)=="string"?e.id:"")].filter(Boolean)),Zt=new Set([...se.map(e=>typeof(e==null?void 0:e.name)=="string"&&e.name.trim()?e.name:e.id),...Fe.map(e=>typeof(e==null?void 0:e.name)=="string"?e.name:"")].filter(Boolean).map(e=>ce(e))),he=Ae?Gs(Ae,Xt):"",ye=it?Hs(it,Zt):"",es=Mt(re,d,"custom",le),Ge=(re==null?void 0:re.status)==="installing"?"":(re==null?void 0:re.id)??"";l.useEffect(()=>{if(d.status!=="running"&&!pe.some(o=>o.status==="installing"))return;const e=setInterval(()=>{R()},1e3);return()=>clearInterval(e)},[pe,R,d.status]),l.useEffect(()=>{if(lt.current||!f||C.length===0||r==="custom"||r==="ollama")return;lt.current=!0;const e=C.find(a=>a.agentType===xe);if(e!=null&&e.isInstalled(f))return;const o=C.find(a=>(a.agentType==="openclaw"||a.agentType==="hermes")&&a.isInstalled(f));o&&E(o.agentType==="hermes"?"hermes":"openclaw")},[r,C,xe,f]),l.useEffect(()=>{if(te.length&&!T){const e=te[0];e&&Q(e.fileName)}},[te,T]),l.useEffect(()=>{if(!(typeof window>"u")){if(d.status==="running"&&d.taskId&&L){const e={createKind:r,customSourceMode:ie,selectedBuiltinTemplate:T,appSpecUrl:O,appSpecYaml:V,name:k,nameEdited:_e,id:D,idEdited:ge,description:de,templateInstall:d,pendingCreate:L};window.sessionStorage.setItem(Me,JSON.stringify(e));return}window.sessionStorage.removeItem(Me)}},[O,V,r,ie,de,D,ge,k,_e,L,T,d]),l.useEffect(()=>{if(r!=="custom"||!he||!ye)return;const e=nt.current,o=!k.trim()||!_e||k===e.name,a=!D.trim()||!ge||D===e.id;o&&k!==ye&&(et(ye),tt(!1)),a&&D!==he&&(ze(he),st(!1)),nt.current={name:ye,id:he}},[r,D,ge,k,_e,he,ye]);const A=C.find(e=>e.agentType===xe)||At.find(e=>e.agentType===xe)||C[0]||At[0],Ve=ce(k),ut=Ve?Fe.find(e=>typeof(e==null?void 0:e.name)=="string"&&ce(e.name)===Ve):null,ts=U?Fe.find(e=>(e==null?void 0:e.id)===U):null,ss=U?se.find(e=>e.id===U):null,ct=Ve?se.find(e=>ce(typeof(e==null?void 0:e.name)=="string"&&e.name.trim()?e.name:e.id)===Ve):null,Ke=ut?t("name.duplicate",{name:k.trim(),id:ut.id,defaultValue:"应用名称“{{name}}”已存在(ID: {{id}})"}):ct?t("name.duplicate",{name:k.trim(),id:ct.id,defaultValue:"应用名称“{{name}}”已存在(ID: {{id}})"}):ts?t("id.duplicate",{id:U,defaultValue:"应用 ID“{{id}}”已存在"}):ss?t("id.duplicate",{id:U,defaultValue:"应用 ID“{{id}}”已存在"}):"",as=r==="ollama"||r==="custom",mt=r==="ollama"?B:r==="custom"?es:"missing",oe=r==="ollama"?(p==null?void 0:p.name)??(p==null?void 0:p.id)??"Ollama":k.trim(),M=r==="ollama"?H||(p==null?void 0:p.id)||"":U,ns=r==="ollama"?be:r==="custom"?le:"",ls=(r==="ollama"||r==="custom")&&d.status==="running"&&d.kind===r&&d.sourceKey===ns,rs=(r==="ollama"||r==="custom")&&(ls||mt==="installing"),pt=Be[r]||rs,ue=as&&mt==="installing"?t("install.waitingCompletion",{defaultValue:"当前模板正在安装中,请等待安装完成"}):"",ft=Ke||Ot,os=async e=>{if(!_){S(""),me(e.agentType),K(o=>({...o,[e.agentType]:{message:"准备安装...",tone:"progress"}}));try{const o=await Ks(e);o!=null&&o.taskId&&await He(o.taskId,{onEvent:a=>{K(c=>({...c,[e.agentType]:a}))}}),Oe(),G(`${e.displayName} 安装完成`,"success"),E(e.agentType==="hermes"?"hermes":"openclaw")}catch(o){const a=(o==null?void 0:o.message)||`${e.displayName} 安装失败`;S(a),G(a,"error")}finally{me(null),setTimeout(()=>{K(o=>({...o,[e.agentType]:null}))},3e3)}}},is=e=>{S(""),et(e),r==="custom"&&tt(!0),ge||ze(Us(e))},ds=e=>{E(e),S(""),e!=="openclaw"&&(Tt(""),Ut(!1))},us=()=>{if(r==="ollama"){if(!(p!=null&&p.yaml))throw new Error(t("template.ollamaRequired"));return{flow:{kind:"ollama",sourceKey:be,appId:p.id,name:p.name??p.id,description:p.description??""},payload:{yaml:p.yaml},existingInstalledAppId:H}}if(r!=="custom")throw new Error(t("failed"));if(!M||!oe)throw new Error(t("install.identityRequired",{defaultValue:"请先确认应用名称和应用 ID"}));if(ne==="builtin"){if(!(h!=null&&h.yaml))throw new Error(t("template.none"));return{flow:{kind:"custom",sourceKey:le,appId:M,name:oe,description:de},payload:{yaml:h.yaml,requestedAppId:M},existingInstalledAppId:Ge}}if(ne==="url"){if(!O.trim())throw new Error(t("custom.urlRequired"));return{flow:{kind:"custom",sourceKey:le,appId:M,name:oe,description:de},payload:{url:O.trim(),requestedAppId:M},existingInstalledAppId:Ge}}if(!V.trim())throw new Error(t("custom.yamlRequired"));return{flow:{kind:"custom",sourceKey:le,appId:M,name:oe,description:de},payload:{yaml:V.trim(),requestedAppId:M},existingInstalledAppId:Ge}},we=l.useCallback(async(e,o,a)=>{const c=t("install.waitingLogs"),v=Os(a,c);b(N=>{var x;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:v,progress:(a==null?void 0:a.progress)??N.progress??null,logs:(x=a==null?void 0:a.logs)!=null&&x.length?a.logs:[c],lastError:""}});let u=(a==null?void 0:a.taskId)??"",w=(a==null?void 0:a.expectedSpecId)??"",I=null;try{if(!u){if(!o)throw new Error(t("install.missingTask",{defaultValue:"未找到可恢复的安装任务,请重新点击创建应用"}));const x=await Ss(o);u=x.taskId,w=x.expectedSpecId??"",b(F=>({...F,action:"install",kind:e.kind,sourceKey:e.sourceKey,taskId:u,expectedSpecId:w,logs:x.reused?[...F.logs,t("install.reusedTask")].slice(-Re):F.logs}))}try{await He(u,{pollIntervalMs:400,initialSeenCount:v,onEvent:(x,F)=>{b(J=>({...J,progress:typeof x.progress=="number"&&x.progress>0?x.progress:J.progress,seenEventCount:Math.max(J.seenEventCount,(F==null?void 0:F.seenCount)??J.seenEventCount),logs:Le(J.logs,Lt(x),c)}))}})}catch(x){if(!qs(x))throw x;if(I=await Ye(e,w,{allowInstalling:!0}),!(I!=null&&I.id))throw new Error(t("install.taskStateLost"));if(I.status==="installing")throw new Error(t("install.taskStateLostInstalling"));b(F=>({...F,logs:[...F.logs,t("install.taskRecovered")].slice(-Re)}))}if(I=I??await Ye(e,w),!(I!=null&&I.id))throw new Error(t("install.notFoundAfterInstall"));const N=I.id;return e.kind==="custom"&&g(x=>({...x,[e.sourceKey]:N})),b(x=>({...x,action:"install",kind:e.kind,sourceKey:e.sourceKey,status:"done",progress:100})),N}catch(N){const x=(N==null?void 0:N.message)||t("install.failed",{defaultValue:"模板安装失败"});throw b(F=>{const J=Le(F.logs,x,c),gs=Dt(J);return{...F,action:"install",kind:e.kind,sourceKey:e.sourceKey,status:"error",lastError:gs?t("install.manualRequired"):x,logs:J}}),R(),new Error(x)}},[R,Ye,t]),gt=l.useCallback(async(e,o,a)=>{b({action:"uninstall",kind:e.kind,sourceKey:e.sourceKey,status:"running",taskId:"",expectedSpecId:"",seenEventCount:0,progress:null,logs:[t("uninstall.waitingLogs")],lastError:""});try{const c=await Cs(o,{sudoPassword:a}),v=c.taskId;b(u=>({...u,taskId:v,logs:c.reused?[...u.logs,t("uninstall.reusedTask")].slice(-Re):u.logs})),await He(v,{pollIntervalMs:400,onEvent:u=>{const w=t("uninstall.waitingLogs");b(I=>({...I,progress:typeof u.progress=="number"&&u.progress>0?u.progress:I.progress,logs:Le(I.logs,Lt(u),w)}))}}),await R(),X(null),b(u=>({...u,status:"done",progress:100})),G(t("uninstall.success",{defaultValue:"Ollama 已卸载"}),"success")}catch(c){const v=(c==null?void 0:c.message)||t("uninstall.failed",{defaultValue:"卸载失败"}),u=t("uninstall.waitingLogs");throw b(w=>({...w,status:"error",lastError:v,logs:Le(w.logs,v,u)})),new Error(v)}},[R,G,t]),xt=l.useCallback(()=>{Y||(fe(null),ee(""),q(""))},[Y]),ve=l.useCallback(async(e,o)=>{e.kind==="custom"&&await Es(o,{name:e.name,description:e.description});try{await _s(o)}catch(c){if(!Ts(c))throw c}const a=t("create.startedSuccess",{name:e.name||o,defaultValue:"应用 {{name}} 创建成功并已启动"});X(null),b(Kt),G(a,"success"),ke(`/instances/${o}/chat`)},[ke,G,t]),cs=l.useCallback(async()=>{if(!Z||Y)return;if(!Ee){q(t("sudoDialog.passwordRequired",{defaultValue:"请输入 sudo 密码。"}));return}S(""),q("");const e=Z,o=Ee.trim();qe(!0);try{await Fs({sudoPassword:o})}catch(a){const c=(a==null?void 0:a.message)||t("sudoDialog.passwordInvalid",{defaultValue:"sudo 密码错误,请重新输入。"});q(c),ee(""),qe(!1);return}fe(null),ee(""),q(""),z(e.flow.kind,!0),qe(!1);try{if(e.action==="uninstall"){await gt(e.flow,e.appId||e.flow.appId,o);return}X(e.flow);const a=e.existingInstalledAppId||await we(e.flow,{...e.payload,sudoPassword:o});await ve(e.flow,a)}catch(a){X(null);const c=(a==null?void 0:a.message)||t("failed");zs(a)?(ee(""),fe(e),q(c),S("")):S(c)}finally{z(e.flow.kind,!1)}},[we,z,ve,Ee,Z,Y,t,gt]);l.useEffect(()=>{L&&(Be[L.kind]||d.status!=="running"||!d.taskId||Ue.current!==d.taskId&&(Ue.current=d.taskId,(async()=>{S(""),z(L.kind,!0);try{const e=await we(L,void 0,d);await ve(L,e)}catch(e){X(null),S((e==null?void 0:e.message)||t("failed"))}finally{Ue.current="",z(L.kind,!1)}})()))},[Be,we,L,z,ve,t,d]);const ms=async e=>{if(e.preventDefault(),r!=="ollama"&&(!M||!oe))return;if(Ke){S(Ke);return}if(ue){S(ue);return}S("");let o=null;try{if(r==="ollama"&&B==="installed"&&H){const w={kind:"ollama",sourceKey:be,appId:H,name:(p==null?void 0:p.name)??H,description:(p==null?void 0:p.description)??""};ee(""),q(""),fe({action:"uninstall",flow:w,appId:H});return}if(r==="ollama"||r==="custom"){const{flow:w,payload:I,existingInstalledAppId:N}=us();if(!N&&(r==="ollama"||r==="custom")){ee(""),q(""),fe({action:"install",flow:w,payload:I,existingInstalledAppId:N});return}o=w.kind,z(w.kind,!0),X(w);const x=N||await we(w,I);await ve(w,x);return}o=r,z(r,!0);const a={id:M,name:oe,description:de};if(r==="openclaw"||r==="hermes"){if(!A.isInstalled(f))throw new Error(t("runtime.installFirst",{name:A.displayName}));a.agentType=xe}r==="openclaw"&&A.supportsClone&&at&&(a.clone_from=at,a.clone_options={include_sessions:Bt,include_memory:zt});const c=await ks(a),v=typeof(c==null?void 0:c.id)=="string"&&c.id?c.id:D,u=c==null?void 0:c.port_allocation;u&&typeof u.assigned=="number"&&typeof u.requested=="number"&&u.assigned!==u.requested&&G(t("portReallocated",{defaultValue:"默认端口 {{requested}} 被占用,已自动使用 {{assigned}}",requested:u.requested,assigned:u.assigned}),"info"),ke(c!=null&&c.autoStarted?`/instances/${v}`:`/instances/${v}/config`)}catch(a){X(null),S(a.message||t("failed"))}finally{o&&z(o,!1)}},ps=()=>{const e=A.isInstalled(f),o=_===A.agentType,a=Pe[A.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:[A.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:t(A.description)}),A.installHint&&!e&&s.jsx("p",{className:"text-xs text-muted mt-2",children:t(A.installHint)})]}),e&&s.jsx("span",{className:"text-xs text-emerald-400 font-medium",children:t("runtime.ready")})]}),!e&&s.jsx("button",{type:"button",onClick:()=>os(A),disabled:!!_,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:o?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")]}):_?t("runtime.waitingOtherInstall"):t("runtime.install",{name:A.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]})]})]})},bt=(e,o)=>{if(!(d.kind===e&&d.sourceKey===o&&(d.status!=="idle"||d.logs.length>0)))return null;const v=Dt(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,w)=>s.jsx("div",{children:u},`${w}-${u}`))}),d.lastError&&s.jsx("p",{className:"text-xs text-red-400",children:d.lastError}),v&&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:v})]})]})},fs=()=>{if(r==="ollama"){const e=B==="installed"?"text-emerald-400 border-emerald-500/20 bg-emerald-500/10":B==="installing"?"text-amber-400 border-amber-500/20 bg-amber-500/10":"text-muted border-[var(--border)] bg-background/40",o=B==="installed"?t("install.installedShort",{defaultValue:"已安装"}):B==="installing"?t("install.installingShort",{defaultValue:"安装中"}):t("install.notInstalledShort",{defaultValue:"未安装"});return s.jsx("div",{className:"space-y-3",children:Ne?s.jsx("div",{className:"rounded-lg border border-[var(--border)] p-4 bg-[var(--input-bg)] text-sm text-muted",children:t("template.loading")}):p?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:p.name}),p.description&&s.jsx("p",{className:"text-xs text-muted mt-1 leading-5",children:p.description})]}),s.jsx("span",{className:`shrink-0 rounded-full border px-2 py-0.5 text-[11px] font-medium ${e}`,children:o})]}),B==="installed"&&H&&s.jsx("p",{className:"text-xs text-muted",children:t("install.installedAppId",{id:H,defaultValue:"已安装应用 ID: {{id}}"})}),B==="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:Se||t("template.ollamaRequired")})})}return r!=="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.jsxs("div",{className:"rounded-lg border border-[var(--border)] bg-[var(--input-bg)] p-4 space-y-2",children:[s.jsx("div",{className:"inline-flex items-center rounded-full border border-[#0066FF]/25 bg-[#0066FF]/8 px-2.5 py-1 text-xs font-medium text-foreground",children:t("source.builtin")}),s.jsx("p",{className:"text-xs text-muted leading-5",children:t("source.experimentalHint")})]})]}),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")}),Ne?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:Se||t("template.none")}):s.jsxs(s.Fragment,{children:[s.jsx("select",{value:(h==null?void 0:h.fileName)??"",onChange:e=>Q(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})]})]})]})};return Gt?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(Ls,{onClose:()=>ke("/instances/new"),showToast:G})]}):s.jsxs("div",{className:"p-6 2xl:px-6 2xl:py-4 max-w-4xl xl:max-w-5xl 2xl:max-w-none 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:ms,className:"space-y-5",children:[ft&&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:ft}),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:ot.map(e=>{const o=r===e.id;return s.jsxs("button",{type:"button",onClick:()=>ds(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 ${o?"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(((kt=ot.find(e=>e.id===r))==null?void 0:kt.descKey)||"appDesc.openclaw")})]}),(r==="openclaw"||r==="hermes")&&ps(),(r==="ollama"||r==="custom")&&fs(),r!=="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:k,onChange:e=>is(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:D,onChange:e=>{S(""),ze(e.target.value),st(!0)},placeholder:t("id.placeholder"),className:`${De} font-mono text-[13px]`}),s.jsx("p",{className:"text-xs text-muted mt-1",children:k&&!D?s.jsx("span",{className:"text-amber-400",children:t("id.invalid")}):t("id.hint")})]})]})})]}),ue&&s.jsx("p",{className:"text-xs text-amber-400",children:ue}),s.jsx("div",{className:"flex flex-col gap-3",children:s.jsx("button",{type:"submit",disabled:pt||r!=="ollama"&&(!M||!oe)||!!Ke||!!ue||r==="ollama"&&!p,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:ue?t("install.installing",{defaultValue:"安装中..."}):pt?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")]}):r==="ollama"&&B==="installed"?t("uninstall.submit",{defaultValue:"卸载 Ollama"}):t("submit")})}),r==="ollama"&&bt("ollama",be),r==="custom"&&bt("custom",le)]}),Z&&s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:xt,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:Ee,onChange:e=>{ee(e.target.value),q("")},placeholder:t("sudoDialog.passwordPlaceholder",{defaultValue:"输入当前用户的 sudo 密码"}),className:De,disabled:Y,autoFocus:!0}),Ze&&s.jsx("p",{className:"mt-2 text-xs text-red-400",children:Ze})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[s.jsx("button",{type:"button",onClick:xt,disabled:Y,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:cs,disabled:Y,className:"px-3 py-1.5 text-xs rounded-md bg-[#0066FF] text-white hover:bg-[#0066FF]/90 transition-colors",children:Y?t("sudoDialog.verifying",{defaultValue:"验证中..."}):Z.action==="uninstall"?t("sudoDialog.uninstallConfirm",{defaultValue:"继续卸载"}):t("sudoDialog.confirm",{defaultValue:"继续安装"})})]})]})})]})}export{aa as default};
|
package/public/assets/{ProviderRecommendations-DFYj7Fb6.js → ProviderRecommendations-BuRnvRcI.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,a1 as m,aB as c}from"./index-
|
|
1
|
+
import{j as e,a1 as m,aB as c}from"./index-BZc5zH7u.js";import{R as x}from"./providers-DtNXh9JD.js";import{u as p}from"./vendor-i18n-y9V7Sfuu.js";function h({title:s,description:t,apiKeyHint:o,selectedProviderId:d,onSelectProvider:n}){const{t:i}=p("instance"),l=(r,a)=>{n(r),window.open(a,"_blank","noopener,noreferrer")};return e.jsxs("div",{className:"rounded-lg border border-[var(--border)] bg-[var(--input-bg)]/40 p-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-[#0066FF]",children:s}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-muted",children:t}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:x.map(r=>{const a=r.providerId===d;return e.jsxs("button",{type:"button","aria-pressed":a,onClick:()=>l(r.providerId,r.purchaseUrl),className:["inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-xs font-medium transition-all",a?"border-[#0066FF]/50 bg-[#0066FF]/12 text-[#0066FF]":"border-[var(--border)] bg-background text-foreground hover:border-[#0066FF]/40 hover:bg-[#0066FF]/5"].join(" "),children:[e.jsx("span",{children:i(`recommendedProviderLabel.${r.providerId}`,{defaultValue:r.label})}),e.jsx(m,{className:"h-3 w-3"})]},r.providerId)})}),e.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border border-amber-500/20 bg-amber-500/10 px-3 py-2.5",children:[e.jsx(c,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-400"}),e.jsx("p",{className:"text-[11px] leading-5 text-muted",children:o})]})]})}export{h as P};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{as as Ae,at as Me,o as Se,H as Ce,j as e,I as T,a as ee,au as Pe,s as Ke,av as Ie,p as oe,aw as $e,ax as Ue,ay as Ee,az as Le,aA as He}from"./index-Dw3HhUYE.js";import{r as d}from"./vendor-react-Bk1hRGiY.js";import{P as Be}from"./ProviderRecommendations-DFYj7Fb6.js";import{g as ce}from"./input-paste-CrNVAyOy.js";import{P as k}from"./providers-DtNXh9JD.js";import{u as se}from"./vendor-i18n-ucpM0OR0.js";function De({showToast:a}){var ie;const{t}=se("settings"),{t:A}=se("instance"),[p,$]=d.useState([]),[U,E]=d.useState(!0),[o,L]=d.useState(null),[z,H]=d.useState(!1),[B,j]=d.useState(!1),[D,R]=d.useState(null),[M,y]=d.useState([]),[n,S]=d.useState(""),[r,h]=d.useState(""),[N,b]=d.useState(""),[te,Y]=d.useState(!1),[le,_]=d.useState(""),[q,Q]=d.useState(""),[O,ae]=d.useState(!1),[C,G]=d.useState([]),me={name:"",baseUrl:"",api:"openai",apiKey:"",authHeader:"",selectedModelId:""},[i,f]=d.useState(me),[de,ue]=d.useState(!1),P=d.useCallback(()=>{E(!0),Ie().then($).catch(()=>$([])).finally(()=>E(!1))},[]);d.useEffect(()=>{P()},[P]);const g="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",W="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",xe=()=>{L(null),S(""),h(""),b(""),_(""),Q(""),Y(!1),G([]),y([]),H(!0)},pe=s=>{H(!1),y([]),f({name:s.name||s.id,baseUrl:s.baseUrl,api:s.api,apiKey:"",authHeader:s.authHeader||"",selectedModelId:s.selectedModelId||""}),L(s.id)},J=()=>{H(!1),L(null),y([]),S(""),h(""),b(""),_(""),Q(""),Y(!1),G([])},re=d.useCallback(s=>{const l=k.find(m=>m.id===s);S(s),b((l==null?void 0:l.baseUrl)||""),_(""),G([])},[]),he=async()=>{var w;if(!n){a(t("llm.presetRequired"),"error");return}const s=k.find(c=>c.id===n),l=s.local===!0;if(!l&&!r.trim()){a(t("llm.apiKeyRequired"),"error");return}if(l&&!N.trim()&&!s.baseUrl){a(t("llm.baseUrlRequired"),"error");return}const m=p.map(c=>c.id),x=q.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");let F=x?`${n}-${x}`:n;if(m.includes(F)){if(x){a(t("llm.aliasConflict"),"error");return}let c=2;for(;m.includes(`${n}-${c}`);)c++;F=`${n}-${c}`}const V=q.trim()?`${s.label} (${q.trim()})`:s.label,u=C.length>0?C.map(c=>({id:c.id,name:c.id,contextWindow:0})):s.models,v=le||((w=u[0])==null?void 0:w.id)||"";j(!0);try{await $e({id:F,name:V,baseUrl:(l?N.trim():void 0)||s.baseUrl,api:s.api,apiKey:r||void 0,authHeader:s.authHeader?"x-api-key":void 0,models:u,selectedModelId:v}),a(t("llm.added"),"success"),J(),P()}catch(c){a(c.message||t("llm.saveFailed"),"error")}finally{j(!1)}},X=async(s,l={})=>{if(!n)return;const m=k.find(u=>u.id===n),x=m.authHeader?"x-api-key":"Authorization",F=m.local===!0&&N.trim()?N.trim():m.baseUrl,V=s??r;ae(!0);try{const{models:u}=await oe(F,V,x,m.id,m.api);G(u),u.length>0&&_(v=>v||u[0].id),l.silentSuccess||a(t("llm.modelsFetched",{count:u.length}),"success")}catch(u){a(u.message||t("llm.modelsFetchFailed"),"error")}finally{ae(!1)}},be=s=>{if(!n||O)return;const l=k.find(x=>x.id===n);if(!l||l.local===!0)return;const m=ce(r,s).trim();m&&X(m,{silentSuccess:!0})},ve=async(s,l={})=>{var u;if(!o)return;const m=i.baseUrl.trim();if(!m)return;const x=o,F=s??i.apiKey,V=i.authHeader.trim()||"Authorization";R(x);try{const v=((u=p.find(c=>c.id===x))==null?void 0:u.api)||i.api,{models:w}=await oe(m,F,V,x,v);y(w),w.length>0&&f(c=>({...c,selectedModelId:c.selectedModelId||w[0].id})),l.silentSuccess||a(t("llm.modelsFetched",{count:w.length}),"success")}catch(v){a(v.message||t("llm.modelsFetchFailed"),"error")}finally{R(v=>v===x?null:v)}},fe=s=>{if(!o||D===o)return;const l=ce(i.apiKey,s).trim();l&&ve(l,{silentSuccess:!0})},ge=async()=>{if(o){if(!i.baseUrl.trim()){a(t("llm.baseUrlRequired"),"error");return}j(!0);try{await Ue(o,{name:i.name||o,baseUrl:i.baseUrl.trim(),api:i.api,apiKey:i.apiKey||void 0,authHeader:i.authHeader||void 0,selectedModelId:i.selectedModelId||void 0}),a(t("llm.updated"),"success"),J(),P()}catch(s){a(s.message||t("llm.saveFailed"),"error")}finally{j(!1)}}},je=async s=>{if(window.confirm(t("llm.confirmDelete",{id:s})))try{await He(s),a(t("llm.deleted"),"success"),P()}catch(l){a(l.message||t("llm.deleteFailed"),"error")}},ye=async s=>{try{await Ee(s),a(t("llm.defaultSet",{id:s}),"success"),P()}catch(l){a(l.message,"error")}},Ne=async s=>{R(s);try{const{models:l}=await Le(s);y(l),a(t("llm.modelsFetched",{count:l.length}),"success")}catch(l){a(l.message||t("llm.modelsFetchFailed"),"error")}finally{R(null)}},Fe=[...new Set(k.map(s=>s.group))],K=k.find(s=>s.id===n),ne=(K==null?void 0:K.local)===!0,Z=C.length>0?C.map(s=>({id:s.id,label:s.id})):((K==null?void 0:K.models)||[]).map(s=>({id:s.id,label:`${s.name} (${Math.round(s.contextWindow/1e3)}K)`})),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.addTitle")}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(Be,{title:t("llm.recommendedTitle"),description:t("llm.recommendedDescription"),apiKeyHint:t("llm.apiKeyHint"),selectedProviderId:n,onSelectProvider:re}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.presetLabel")}),e.jsxs("select",{value:n,onChange:s=>re(s.target.value),className:W,children:[e.jsx("option",{value:"",children:t("llm.presetPlaceholder")}),Fe.map(s=>e.jsx("optgroup",{label:A(`configForm.providerGroup.${s}`,{defaultValue:s}),children:k.filter(l=>l.group===s).map(l=>e.jsx("option",{value:l.id,children:A(`configForm.providerLabel.${l.id}`,{defaultValue:l.label})},l.id))},s))]})]}),n&&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=>Q(s.target.value),placeholder:t("llm.aliasPlaceholder"),className:g}),e.jsx("p",{className:"text-[11px] text-muted mt-0.5",children:t("llm.aliasHint")})]}),n&&!ne&&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:te?"text":"password",value:r,onChange:s=>h(s.target.value),onPaste:be,placeholder:t("llm.apiKeyPlaceholder"),className:`${g} pr-9 font-mono`}),e.jsx("button",{type:"button",onClick:()=>Y(s=>!s),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground transition-colors",children:te?e.jsx(T,{className:"w-3.5 h-3.5"}):e.jsx(ee,{className:"w-3.5 h-3.5"})})]}),e.jsx("button",{type:"button",onClick:()=>{X()},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")})]})]}),n&&ne&&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:N,onChange:s=>b(s.target.value),className:`${g} flex-1`}),e.jsx("button",{type:"button",onClick:()=>{X()},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")})]})]}),n&&Z.length>0&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs text-muted mb-1",children:[t("llm.fieldModel"),C.length>0&&e.jsxs("span",{className:"ml-1 text-green-500 text-[10px]",children:["(",C.length," ",t("llm.liveModels"),")"]})]}),e.jsx("select",{value:le||((ie=Z[0])==null?void 0:ie.id)||"",onChange:s=>_(s.target.value),className:W,children:Z.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:he,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:J,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")})]})]}),I=p.find(s=>s.id===o),ke=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:o})}),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:i.name,onChange:s=>f(l=>({...l,name:s.target.value})),placeholder:t("llm.fieldNamePlaceholder"),className:g})]}),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:i.baseUrl,onChange:s=>f(l=>({...l,baseUrl:s.target.value})),placeholder:"https://api.openai.com",className:g})]}),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:i.api,onChange:s=>f(l=>({...l,api:s.target.value})),className:W,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:i.authHeader,onChange:s=>f(l=>({...l,authHeader:s.target.value})),placeholder:"Authorization",className:g})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsxs("label",{className:"block text-xs text-muted mb-1",children:[t("llm.fieldApiKey"),I!=null&&I.hasApiKey?` (${t("llm.apiKeyConfigured")})`:""]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:de?"text":"password",value:i.apiKey,onChange:s=>f(l=>({...l,apiKey:s.target.value})),onPaste:fe,placeholder:I!=null&&I.hasApiKey?t("llm.apiKeyLeaveBlank"):t("llm.apiKeyPlaceholder"),className:`${g} pr-9 font-mono`}),e.jsx("button",{type:"button",onClick:()=>ue(s=>!s),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground transition-colors",children:de?e.jsx(T,{className:"w-3.5 h-3.5"}):e.jsx(ee,{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")}),M.length>0?e.jsxs("select",{value:i.selectedModelId,onChange:s=>f(l=>({...l,selectedModelId:s.target.value})),className:W,children:[e.jsx("option",{value:"",children:t("llm.noModel")}),M.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}):e.jsx("input",{value:i.selectedModelId,onChange:s=>f(l=>({...l,selectedModelId:s.target.value})),placeholder:"gpt-4o",className:g})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx("button",{onClick:ge,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:J,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")})]}),!z&&!o&&e.jsxs("button",{onClick:xe,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")]})]}),z&&we,U?e.jsx("p",{className:"text-sm text-muted py-3",children:t("llm.loading")}):p.length===0&&!z?e.jsx("p",{className:"text-sm text-muted py-3",children:t("llm.empty")}):e.jsx("div",{className:"space-y-2 mt-2",children:p.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:()=>ye(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:()=>{pe(s),Ne(s.id)},disabled:D===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:D===s.id?"...":t("llm.edit")}),e.jsx("button",{onClick:()=>je(s.id),disabled:p.length<=1,title:p.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")})]})]}),o===s.id&&ke,D===null&&M.length>0&&o!==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")," (",M.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1 max-h-20 overflow-y-auto",children:M.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 Ge(){const{t:a}=se("settings"),{system:t,showToast:A}=Ae(),[p,$]=d.useState(""),[U,E]=d.useState(""),[o,L]=d.useState(!1),[z,H]=d.useState([]),[B,j]=d.useState(!1),[D,R]=d.useState(!1),[M,y]=d.useState(!1);d.useEffect(()=>{j(!0),Me().then(H).catch(()=>{}).finally(()=>j(!1)),Se().then(async r=>{try{const h=await Promise.all(r.map(b=>Ce(b.id).catch(()=>({enabled:!1})))),N=r.length>0&&h.every(b=>b==null?void 0:b.enabled);y(N)}catch{}}).catch(()=>{})},[]);const n=async r=>{r.preventDefault();try{const h=await Pe(p,U);h.token&&Ke(h.token),A(a("password.updated"),"success"),$(""),E("")}catch(h){A(h.message||a("password.failed"),"error")}},S="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(De,{showToast:A}),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:n,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:o?"text":"password",value:p,onChange:r=>$(r.target.value),placeholder:a("password.currentPlaceholder"),className:`${S} pr-9`}),e.jsx("button",{type:"button",onClick:()=>L(!o),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground transition-colors",children:o?e.jsx(T,{className:"w-3.5 h-3.5"}):e.jsx(ee,{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:o?"text":"password",value:U,onChange:r=>E(r.target.value),placeholder:a("password.newPlaceholder"),className:S})]}),e.jsx("button",{type:"submit",disabled:!p||U.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.30"]})})]})]})]})}export{Ge as default};
|
|
1
|
+
import{as as Ae,at as Me,o as Se,H as Ce,j as e,I as T,a as ee,au as Pe,s as Ke,av as Ie,p as oe,aw as $e,ax as Ue,ay as Ee,az as Le,aA as He}from"./index-BZc5zH7u.js";import{r as d}from"./vendor-react-BWrEVJVb.js";import{P as Be}from"./ProviderRecommendations-BuRnvRcI.js";import{g as ce}from"./input-paste-CrNVAyOy.js";import{P as k}from"./providers-DtNXh9JD.js";import{u as se}from"./vendor-i18n-y9V7Sfuu.js";function De({showToast:a}){var ie;const{t}=se("settings"),{t:A}=se("instance"),[p,$]=d.useState([]),[U,E]=d.useState(!0),[o,L]=d.useState(null),[z,H]=d.useState(!1),[B,j]=d.useState(!1),[D,_]=d.useState(null),[M,y]=d.useState([]),[n,S]=d.useState(""),[r,h]=d.useState(""),[N,b]=d.useState(""),[te,Y]=d.useState(!1),[le,R]=d.useState(""),[q,Q]=d.useState(""),[O,ae]=d.useState(!1),[C,G]=d.useState([]),me={name:"",baseUrl:"",api:"openai",apiKey:"",authHeader:"",selectedModelId:""},[i,g]=d.useState(me),[de,ue]=d.useState(!1),P=d.useCallback(()=>{E(!0),Ie().then($).catch(()=>$([])).finally(()=>E(!1))},[]);d.useEffect(()=>{P()},[P]);const f="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",W="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",xe=()=>{L(null),S(""),h(""),b(""),R(""),Q(""),Y(!1),G([]),y([]),H(!0)},pe=s=>{H(!1),y([]),g({name:s.name||s.id,baseUrl:s.baseUrl,api:s.api,apiKey:"",authHeader:s.authHeader||"",selectedModelId:s.selectedModelId||""}),L(s.id)},J=()=>{H(!1),L(null),y([]),S(""),h(""),b(""),R(""),Q(""),Y(!1),G([])},re=d.useCallback(s=>{const l=k.find(m=>m.id===s);S(s),b((l==null?void 0:l.baseUrl)||""),R(""),G([])},[]),he=async()=>{var F;if(!n){a(t("llm.presetRequired"),"error");return}const s=k.find(c=>c.id===n),l=s.local===!0;if(!l&&!r.trim()){a(t("llm.apiKeyRequired"),"error");return}if(l&&!N.trim()&&!s.baseUrl){a(t("llm.baseUrlRequired"),"error");return}const m=p.map(c=>c.id),x=q.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");let w=x?`${n}-${x}`:n;if(m.includes(w)){if(x){a(t("llm.aliasConflict"),"error");return}let c=2;for(;m.includes(`${n}-${c}`);)c++;w=`${n}-${c}`}const V=q.trim()?`${s.label} (${q.trim()})`:s.label,u=C.length>0?C.map(c=>({id:c.id,name:c.id,contextWindow:0})):s.models,v=le||((F=u[0])==null?void 0:F.id)||"";j(!0);try{await $e({id:w,name:V,baseUrl:(l?N.trim():void 0)||s.baseUrl,api:s.api,apiKey:r||void 0,authHeader:s.authHeader?"x-api-key":void 0,models:u,selectedModelId:v}),a(t("llm.added"),"success"),J(),P()}catch(c){a(c.message||t("llm.saveFailed"),"error")}finally{j(!1)}},X=async(s,l={})=>{if(!n)return;const m=k.find(u=>u.id===n),x=m.authHeader?"x-api-key":"Authorization",w=m.local===!0&&N.trim()?N.trim():m.baseUrl,V=s??r;ae(!0);try{const{models:u}=await oe(w,V,x,m.id,m.api);G(u),u.length>0&&R(v=>v||u[0].id),l.silentSuccess||a(t("llm.modelsFetched",{count:u.length}),"success")}catch(u){a(u.message||t("llm.modelsFetchFailed"),"error")}finally{ae(!1)}},be=s=>{if(!n||O)return;const l=k.find(x=>x.id===n);if(!l||l.local===!0)return;const m=ce(r,s).trim();m&&X(m,{silentSuccess:!0})},ve=async(s,l={})=>{var u;if(!o)return;const m=i.baseUrl.trim();if(!m)return;const x=o,w=s??i.apiKey,V=i.authHeader.trim()||"Authorization";_(x);try{const v=((u=p.find(c=>c.id===x))==null?void 0:u.api)||i.api,{models:F}=await oe(m,w,V,x,v);y(F),F.length>0&&g(c=>({...c,selectedModelId:c.selectedModelId||F[0].id})),l.silentSuccess||a(t("llm.modelsFetched",{count:F.length}),"success")}catch(v){a(v.message||t("llm.modelsFetchFailed"),"error")}finally{_(v=>v===x?null:v)}},ge=s=>{if(!o||D===o)return;const l=ce(i.apiKey,s).trim();l&&ve(l,{silentSuccess:!0})},fe=async()=>{if(o){if(!i.baseUrl.trim()){a(t("llm.baseUrlRequired"),"error");return}j(!0);try{await Ue(o,{name:i.name||o,baseUrl:i.baseUrl.trim(),api:i.api,apiKey:i.apiKey||void 0,authHeader:i.authHeader||void 0,selectedModelId:i.selectedModelId||void 0}),a(t("llm.updated"),"success"),J(),P()}catch(s){a(s.message||t("llm.saveFailed"),"error")}finally{j(!1)}}},je=async s=>{if(window.confirm(t("llm.confirmDelete",{id:s})))try{await He(s),a(t("llm.deleted"),"success"),P()}catch(l){a(l.message||t("llm.deleteFailed"),"error")}},ye=async s=>{try{await Ee(s),a(t("llm.defaultSet",{id:s}),"success"),P()}catch(l){a(l.message,"error")}},Ne=async s=>{_(s);try{const{models:l}=await Le(s);y(l),a(t("llm.modelsFetched",{count:l.length}),"success")}catch(l){a(l.message||t("llm.modelsFetchFailed"),"error")}finally{_(null)}},we=[...new Set(k.map(s=>s.group))],K=k.find(s=>s.id===n),ne=(K==null?void 0:K.local)===!0,Z=C.length>0?C.map(s=>({id:s.id,label:s.id})):((K==null?void 0:K.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.jsx(Be,{title:t("llm.recommendedTitle"),description:t("llm.recommendedDescription"),apiKeyHint:t("llm.apiKeyHint"),selectedProviderId:n,onSelectProvider:re}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-muted mb-1",children:t("llm.presetLabel")}),e.jsxs("select",{value:n,onChange:s=>re(s.target.value),className:W,children:[e.jsx("option",{value:"",children:t("llm.presetPlaceholder")}),we.map(s=>e.jsx("optgroup",{label:A(`configForm.providerGroup.${s}`,{defaultValue:s}),children:k.filter(l=>l.group===s).map(l=>e.jsx("option",{value:l.id,children:A(`configForm.providerLabel.${l.id}`,{defaultValue:l.label})},l.id))},s))]})]}),n&&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=>Q(s.target.value),placeholder:t("llm.aliasPlaceholder"),className:f}),e.jsx("p",{className:"text-[11px] text-muted mt-0.5",children:t("llm.aliasHint")})]}),n&&!ne&&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:te?"text":"password",value:r,onChange:s=>h(s.target.value),onPaste:be,placeholder:t("llm.apiKeyPlaceholder"),className:`${f} pr-9 font-mono`}),e.jsx("button",{type:"button",onClick:()=>Y(s=>!s),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground transition-colors",children:te?e.jsx(T,{className:"w-3.5 h-3.5"}):e.jsx(ee,{className:"w-3.5 h-3.5"})})]}),e.jsx("button",{type:"button",onClick:()=>{X()},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")})]})]}),n&&ne&&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:N,onChange:s=>b(s.target.value),className:`${f} flex-1`}),e.jsx("button",{type:"button",onClick:()=>{X()},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")})]})]}),n&&Z.length>0&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs text-muted mb-1",children:[t("llm.fieldModel"),C.length>0&&e.jsxs("span",{className:"ml-1 text-green-500 text-[10px]",children:["(",C.length," ",t("llm.liveModels"),")"]})]}),e.jsx("select",{value:le||((ie=Z[0])==null?void 0:ie.id)||"",onChange:s=>R(s.target.value),className:W,children:Z.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:he,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:J,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")})]})]}),I=p.find(s=>s.id===o),ke=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:o})}),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:i.name,onChange:s=>g(l=>({...l,name:s.target.value})),placeholder:t("llm.fieldNamePlaceholder"),className:f})]}),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:i.baseUrl,onChange:s=>g(l=>({...l,baseUrl:s.target.value})),placeholder:"https://api.openai.com",className:f})]}),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:i.api,onChange:s=>g(l=>({...l,api:s.target.value})),className:W,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:i.authHeader,onChange:s=>g(l=>({...l,authHeader:s.target.value})),placeholder:"Authorization",className:f})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsxs("label",{className:"block text-xs text-muted mb-1",children:[t("llm.fieldApiKey"),I!=null&&I.hasApiKey?` (${t("llm.apiKeyConfigured")})`:""]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:de?"text":"password",value:i.apiKey,onChange:s=>g(l=>({...l,apiKey:s.target.value})),onPaste:ge,placeholder:I!=null&&I.hasApiKey?t("llm.apiKeyLeaveBlank"):t("llm.apiKeyPlaceholder"),className:`${f} pr-9 font-mono`}),e.jsx("button",{type:"button",onClick:()=>ue(s=>!s),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground transition-colors",children:de?e.jsx(T,{className:"w-3.5 h-3.5"}):e.jsx(ee,{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")}),M.length>0?e.jsxs("select",{value:i.selectedModelId,onChange:s=>g(l=>({...l,selectedModelId:s.target.value})),className:W,children:[e.jsx("option",{value:"",children:t("llm.noModel")}),M.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}):e.jsx("input",{value:i.selectedModelId,onChange:s=>g(l=>({...l,selectedModelId:s.target.value})),placeholder:"gpt-4o",className:f})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx("button",{onClick:fe,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:J,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")})]}),!z&&!o&&e.jsxs("button",{onClick:xe,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")]})]}),z&&Fe,U?e.jsx("p",{className:"text-sm text-muted py-3",children:t("llm.loading")}):p.length===0&&!z?e.jsx("p",{className:"text-sm text-muted py-3",children:t("llm.empty")}):e.jsx("div",{className:"space-y-2 mt-2",children:p.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:()=>ye(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:()=>{pe(s),Ne(s.id)},disabled:D===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:D===s.id?"...":t("llm.edit")}),e.jsx("button",{onClick:()=>je(s.id),disabled:p.length<=1,title:p.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")})]})]}),o===s.id&&ke,D===null&&M.length>0&&o!==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")," (",M.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1 max-h-20 overflow-y-auto",children:M.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 Ge(){const{t:a}=se("settings"),{system:t,showToast:A}=Ae(),[p,$]=d.useState(""),[U,E]=d.useState(""),[o,L]=d.useState(!1),[z,H]=d.useState([]),[B,j]=d.useState(!1),[D,_]=d.useState(!1),[M,y]=d.useState(!1);d.useEffect(()=>{j(!0),Me().then(H).catch(()=>{}).finally(()=>j(!1)),Se().then(async r=>{try{const h=await Promise.all(r.map(b=>Ce(b.id).catch(()=>({enabled:!1})))),N=r.length>0&&h.every(b=>b==null?void 0:b.enabled);y(N)}catch{}}).catch(()=>{})},[]);const n=async r=>{r.preventDefault();try{const h=await Pe(p,U);h.token&&Ke(h.token),A(a("password.updated"),"success"),$(""),E("")}catch(h){A(h.message||a("password.failed"),"error")}},S="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 2xl:px-6 2xl:py-4 max-w-4xl xl:max-w-5xl 2xl:max-w-none 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(De,{showToast:A}),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:n,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:o?"text":"password",value:p,onChange:r=>$(r.target.value),placeholder:a("password.currentPlaceholder"),className:`${S} pr-9`}),e.jsx("button",{type:"button",onClick:()=>L(!o),"aria-label":a("common:action.togglePassword"),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground transition-colors",children:o?e.jsx(T,{className:"w-3.5 h-3.5"}):e.jsx(ee,{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:o?"text":"password",value:U,onChange:r=>E(r.target.value),placeholder:a("password.newPlaceholder"),className:S})]}),e.jsx("button",{type:"submit",disabled:!p||U.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.5.15"]})})]})]})]})}export{Ge as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as ae,d as Fe,p as Se,j as e,L as _e,T as Ce,e as de,i as $,f as Ie,r as Le,h as Me,u as Te}from"./index-Dw3HhUYE.js";import{r as c}from"./vendor-react-Bk1hRGiY.js";import{g as Ae}from"./input-paste-CrNVAyOy.js";import{P as N}from"./providers-DtNXh9JD.js";import{u as Pe}from"./registry-5s2UB6is.js";import{P as Re}from"./ProviderRecommendations-DFYj7Fb6.js";import{u as le}from"./vendor-i18n-ucpM0OR0.js";function ce(i,p){var r,j;if(!i)return!1;const t=(r=i.runtimes)==null?void 0:r[p];return t?!!t.installed&&!!t.imageReady:p==="openclaw"?!!((j=i.openclaw)!=null&&j.installed)&&!!i.dockerImageReady:!1}function De(i,p){var r;const t=(r=i==null?void 0:i.runtimes)==null?void 0:r[p];return t&&typeof t.required=="boolean"?t.required:p==="openclaw"}function oe(i,p){if(!i)return!1;const t=p.filter(r=>De(i,r.agentType));return t.length===0?!0:t.every(r=>ce(i,r.agentType))}const C=[{id:"check",label:"环境检测"},{id:"node",label:"Node.js"},{id:"docker",label:"Docker"},{id:"nomad",label:"Nomad"},{id:"openclaw",label:"OpenClaw"},{id:"provider",label:"模型配置"},{id:"done",label:"完成"}];function Ee({ok:i}){return i?e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-emerald-500 shadow-[0_0_6px_rgba(16,185,129,0.7)]"}):e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-[var(--border)]"})}function D({dep:i,label:p,required:t,extra:r}){const{t:j}=le("setup"),x=i.needsUpgrade;return e.jsxs("div",{className:"flex items-center justify-between py-2.5 border-b border-[var(--border)] last:border-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[x?e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-amber-400 shadow-[0_0_6px_rgba(251,191,36,0.6)]"}):e.jsx(Ee,{ok:i.installed}),e.jsx("span",{className:"text-sm text-foreground",children:p||i.name}),x&&e.jsx("span",{className:"text-xs text-amber-400",children:j("versionTooOld")}),t&&!i.installed&&!x&&e.jsx("span",{className:"text-xs text-red-400",children:j("required")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r,e.jsx("span",{className:"text-xs text-muted font-mono",children:i.installed?i.version||"installed":"not installed"})]})]})}function I(){return e.jsx("span",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"})}function ie(i){return/失败|error|denied|forbidden|unauthorized/i.test(i)?"error":/完成|已就绪|已启动|已存在|成功|built|installed/i.test(i)?"success":/正在|等待|下载|安装|构建|启动|升级|progress|exporting|transferring/i.test(i)?"progress":"info"}function qe(i){switch(i){case"progress":return{dot:"bg-sky-400 shadow-[0_0_8px_rgba(56,189,248,0.55)]",text:"text-sky-100"};case"success":return{dot:"bg-emerald-400 shadow-[0_0_8px_rgba(52,211,153,0.55)]",text:"text-emerald-100"};case"error":return{dot:"bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.55)]",text:"text-red-200"};default:return{dot:"bg-slate-500 shadow-[0_0_8px_rgba(148,163,184,0.35)]",text:"text-slate-200/90"}}}function Oe({onDone:i}){var te,se,re,ne;const{runtimes:p}=Pe(),{t}=le(["setup","common","instance"]),[r,j]=c.useState(null),[x,E]=c.useState("check"),[f,w]=c.useState(null),[K,z]=c.useState([]),[L,v]=c.useState(""),[B,H]=c.useState(!1),[b,ue]=c.useState(""),[k,me]=c.useState(""),[q,xe]=c.useState(!1),[W,U]=c.useState(""),[O,V]=c.useState(!1),[F,M]=c.useState([]),[S,G]=c.useState(!1),[_,J]=c.useState(""),Q=c.useRef(new Set),X=c.useCallback((n,s)=>{if(Q.current.has(n))return;Q.current.add(n);const a=s==="openclaw-docker"?t("setup:dockerImageBuild"):s==="docker"?t("setup:dockerInstall"):s==="openclaw"?t("setup:openclawInstall"):s;w(s),h(t("setup:resumeTask",{label:a}),"progress"),Y(n,a).then(()=>{g(!0)}).catch(d=>{v(d.message||t("setup:taskFailed"))}).finally(()=>{w(null)})},[]),g=c.useCallback((n=!1)=>{ae().then(s=>{var a;if(j(s),(a=s.runningTasks)!=null&&a.length)for(const d of s.runningTasks)X(d.id,d.name);if(!n&&s.ready){E("provider");return}}).catch(()=>{})},[i,X]);c.useEffect(()=>{g()},[g]),c.useEffect(()=>{var s,a;if(x!=="nomad"||!((s=r==null?void 0:r.nomad)!=null&&s.installed)||(a=r==null?void 0:r.nomad)!=null&&a.running)return;const n=setInterval(()=>{g(!0)},3e3);return()=>clearInterval(n)},[x,(te=r==null?void 0:r.nomad)==null?void 0:te.installed,(se=r==null?void 0:r.nomad)==null?void 0:se.running,g]);const h=(n,s=ie(n))=>z(a=>[...a,{message:n,tone:s}].slice(-200)),pe=(n,s)=>s.type==="progress"&&typeof s.progress=="number"?`${n}: ${s.message} [${s.progress}%]`:s.type==="done"?`${n}: ${s.message}`:s.type==="error"?t("setup:taskErrorPrefix",{label:n,message:s.message}):s.message,Y=async(n,s)=>{let a=0,d=0,u=t("setup:taskCompleted",{label:s});const o=Date.now()+30*60*1e3;for(;Date.now()<o;){try{const m=await Fe(n);d=0;const ye=m.events.slice(a);a=m.events.length;for(const y of ye){const we=y.type==="done"?"success":y.type==="error"?"error":y.type==="progress"?"progress":ie(y.message);h(pe(s,y),we),y.message&&(u=y.message)}if(m.status==="done")return u;if(m.status==="error")throw new Error(u)}catch(m){if(d+=1,d>=5)throw new Error((m==null?void 0:m.message)||t("setup:taskStatusFailed",{label:s}))}const l=Math.min(1e3+a*200,3e3);await new Promise(m=>setTimeout(m,l))}throw new Error(t("setup:taskTimeout",{label:s}))},T=async(n,s,a)=>{w(n),v(""),h(t("setup:installing",{label:s}),"progress");try{const d=await a();let u=d.message||t("setup:taskStarted",{label:s});return d!=null&&d.taskId?u=await Y(d.taskId,s):h(`${s}: ${u}`,"success"),g(!0),!0}catch(d){const u=d.message||t("setup:defaultInstallFailed");return h(t("setup:installFailed",{label:s,error:u}),"error"),v(u),!1}finally{w(null)}},Z=async()=>{await T("node","Node.js",()=>Te())},be=async()=>{await T("docker","Docker",()=>$("docker"))},[he,fe]=c.useState(!1),ge=async n=>{const s=p.find(d=>d.agentType===n);if(!s)return;s.installHint&&h(t(s.installHint),"info");const a=await T(`runtime-${n}`,t(s.installLabel),()=>Me(n));n==="openclaw"&&a&&fe(!0),g(!0)},ve=async()=>{var s;if(await T("nomad","Nomad",()=>$("nomad"))){h(t("setup:configuringNomadSystemd"),"progress"),w("nomad-systemd");try{await $("nomad-systemd"),h(t("setup:nomadServiceStarted"),"success")}catch{try{await Ie("nomad"),h(t("setup:nomadStarted"),"success")}catch(a){h(t("setup:nomadStartFailed",{error:a.message}),"error"),v(a.message)}}w(null),h(t("setup:waitingNomad"),"progress");for(let a=0;a<10;a++){await new Promise(u=>setTimeout(u,2e3));const d=await ae();if((s=d.nomad)!=null&&s.running){j(d),h(t("setup:nomadReady"),"success");return}}g(!0)}},A=!!((re=r==null?void 0:r.node)!=null&&re.installed)&&!((ne=r==null?void 0:r.node)!=null&&ne.needsUpgrade),P=async()=>{var d,u,o,l;const n=C.findIndex(m=>m.id===x);if(n>=C.length-1)return;let s=n+1;for(;s<C.length-1;){const m=C[s].id;if(m==="node"&&A){s++;continue}if(m==="docker"&&((d=r==null?void 0:r.docker)!=null&&d.installed)&&((u=r==null?void 0:r.docker)!=null&&u.running)){s++;continue}if(m==="nomad"&&((o=r==null?void 0:r.nomad)!=null&&o.installed)&&((l=r==null?void 0:r.nomad)!=null&&l.running)){s++;continue}if(m==="openclaw"&&oe(r,p)){s++;continue}break}const a=C[s].id;if(v(""),z([]),a==="done"){E("done"),H(!0);try{await Le({installNomad:!1,buildDockerImage:!1})}catch(m){v(m.message||t("setup:configWriteFailed"))}finally{H(!1)}}else E(a)},je=n=>{if(!r)return!1;switch(n){case"check":return A;case"node":return A;case"docker":return r.docker.installed&&r.docker.running;case"nomad":return r.nomad.installed&&r.nomad.running;case"openclaw":return oe(r,p)||he&&r.openclaw.installed&&p.length===1;case"provider":return!0;case"done":return!0;default:return!1}},ee=c.useCallback(n=>{ue(n),U(""),M([]);const s=N.find(a=>a.id===n);J((s==null?void 0:s.baseUrl)||"")},[]),R=c.useCallback(async n=>{if(!b)return;const s=N.find(l=>l.id===b);if(!s)return;const d=s.local===!0&&_.trim()?_.trim():s.baseUrl,u=s.authHeader?"x-api-key":"Authorization",o=n??k;G(!0),v("");try{const{models:l}=await Se(d,o,u,s.id,s.api);M(l),l.length>0&&U(l[0].id)}catch(l){v(l.message||t("setup:provider.fetchModelsFailed"))}finally{G(!1)}},[k,_,b,t]),ke=c.useCallback(n=>{if(!b||S)return;const s=N.find(d=>d.id===b);if(!s||s.local===!0)return;const a=Ae(k,n).trim();a&&R(a)},[k,S,R,b]),Ne=async()=>{var o;if(!b)return!1;const n=N.find(l=>l.id===b);if(!n)return!1;const s=n.local===!0,a=s&&_.trim()?_.trim():n.baseUrl;if(s&&!a)return v(t("setup:provider.baseUrlRequired",{defaultValue:"Base URL is required"})),!1;const d=F.length>0?F.map(l=>({id:l.id,name:l.name||l.id,contextWindow:128e3})):n.models,u=W||((o=d[0])==null?void 0:o.id)||"";V(!0);try{return await de({providerId:n.id,baseUrl:a,api:n.api,authHeader:n.authHeader?"x-api-key":void 0,models:d,selectedModelId:u,apiKey:k||""}),!0}catch(l){return v(l.message||t("setup:provider.saveFailed")),!1}finally{V(!1)}};return r?e.jsxs("div",{className:"min-h-screen flex items-center justify-center p-4 bg-background relative overflow-hidden",children:[e.jsx("div",{className:"grid-bg absolute inset-0 pointer-events-none"}),e.jsx("div",{className:"absolute top-1/3 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[600px] h-[400px] rounded-full bg-[#0066FF]/[0.06] blur-[100px] pointer-events-none"}),e.jsx("div",{className:"absolute left-4 bottom-4 z-20",children:e.jsx(_e,{className:"bg-card/80 backdrop-blur-sm"})}),e.jsxs("div",{className:"w-full max-w-lg relative z-10",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx(Ce,{className:"w-48 h-48 mx-auto mb-4 object-contain"}),e.jsx("p",{className:"text-sm text-muted mt-1",children:t("setup:title")})]}),e.jsxs("div",{className:"bg-card border border-[var(--border)] rounded-xl p-6 backdrop-blur-sm",children:[x==="check"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:check.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:check.desc")}),e.jsx("p",{className:"text-xs text-muted mb-1.5 font-medium",children:t("setup:check.requiredComponents")}),e.jsxs("div",{className:"bg-card rounded-md border border-[var(--border)] px-4",children:[e.jsx(D,{dep:r.node,label:"Node.js",required:!0,extra:r.node.needsUpgrade?e.jsx("button",{onClick:Z,disabled:!!f,className:"text-xs bg-amber-500/20 text-amber-400 border border-amber-500/30 rounded px-2 py-0.5 hover:bg-amber-500/30 disabled:opacity-40 transition-colors duration-200",children:t(f==="node"?"setup:check.upgrading":"setup:check.upgrade")}):void 0}),e.jsx(D,{dep:r.docker,label:"Docker",required:!0}),e.jsx(D,{dep:r.nomad,label:"Nomad",required:!0}),e.jsx(D,{dep:r.openclaw,label:"OpenClaw",required:!0})]})]}),x==="node"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:node.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:node.desc")}),A?e.jsx("div",{className:"bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 text-sm rounded-md px-3 py-2.5",children:t("setup:node.ready",{version:r.node.version})}):r.hasSudo?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:t("setup:node.currentVersion",{version:r.node.version})}),e.jsx("button",{onClick:Z,disabled:!!f,className:"bg-[#0066FF] text-white rounded-md px-4 py-2 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:f?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(I,{}),t("setup:node.upgrading")]}):t("setup:node.upgradeBtn")}),e.jsx("p",{className:"text-xs text-muted",children:t("setup:node.sudoRequired")})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:t("setup:node.noSudo",{version:r.node.version})}),e.jsxs("div",{className:"bg-card border border-[var(--border)] rounded-md p-3",children:[e.jsx("p",{className:"text-xs text-muted mb-1.5",children:t("setup:node.contactAdmin")}),e.jsx("code",{className:"text-xs text-foreground font-mono block whitespace-pre-wrap",children:"curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && sudo apt-get install -y nodejs"})]}),e.jsx("button",{onClick:()=>g(!0),className:"text-xs text-muted hover:text-foreground underline transition-colors duration-200",children:t("setup:node.refreshAfterInstall")})]})]}),x==="docker"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:docker.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:docker.desc")}),r.docker.installed&&r.docker.running?e.jsx("div",{className:"bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 text-sm rounded-md px-3 py-2.5",children:t("setup:docker.running",{version:r.docker.version})}):r.docker.installed&&!r.docker.running?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:t("setup:docker.notRunning")}),e.jsx("div",{className:"bg-card border border-[var(--border)] rounded-md p-3",children:e.jsx("code",{className:"text-xs text-foreground font-mono block",children:"sudo systemctl start docker"})}),e.jsx("button",{onClick:()=>g(!0),className:"text-xs text-muted hover:text-foreground underline transition-colors duration-200",children:t("setup:docker.refreshAfterStart")})]}):r.hasSudo?e.jsxs("div",{className:"space-y-3",children:[e.jsx("button",{onClick:be,disabled:!!f,className:"bg-[#0066FF] text-white rounded-md px-4 py-2 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:f?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(I,{}),t("setup:docker.installing")]}):t("setup:docker.installBtn")}),e.jsx("p",{className:"text-xs text-muted",children:t("setup:docker.sudoRequired")})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:t("setup:docker.noSudo")}),e.jsxs("div",{className:"bg-card border border-[var(--border)] rounded-md p-3",children:[e.jsx("p",{className:"text-xs text-muted mb-1.5",children:t("setup:docker.contactAdmin")}),e.jsx("code",{className:"text-xs text-foreground font-mono block",children:"curl -fsSL https://get.docker.com | sh"})]}),e.jsx("button",{onClick:()=>g(!0),className:"text-xs text-muted hover:text-foreground underline transition-colors duration-200",children:t("setup:docker.refreshAfterInstall")})]})]}),x==="nomad"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:nomad.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:nomad.desc")}),r.nomad.installed&&r.nomad.running?e.jsx("div",{className:"bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 text-sm rounded-md px-3 py-2.5",children:t("setup:nomad.running",{version:r.nomad.version})}):r.nomad.installed?e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex items-center gap-2 bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:[e.jsx(I,{}),e.jsx("span",{children:t("setup:nomad.starting")})]})}):e.jsx("button",{onClick:ve,disabled:!!f,className:"bg-[#0066FF] text-white rounded-md px-4 py-2 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:f?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(I,{}),t("setup:nomad.installing")]}):t("setup:nomad.installBtn")})]}),x==="openclaw"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:"Agent 运行时"}),e.jsx("p",{className:"text-sm text-muted mb-4",children:"安装所有已注册的 Agent 运行时 (Docker 镜像 / shim)。每次添加新 Agent 时,这里会自动出现一行。"}),e.jsx("div",{className:"space-y-4",children:p.map(n=>{const s=ce(r,n.agentType),a=f===`runtime-${n.agentType}`;return e.jsxs("div",{className:"rounded-md border border-[var(--border)] bg-[var(--card)] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:n.displayName}),e.jsx("div",{className:"text-xs text-muted",children:n.description})]}),s?e.jsx("span",{className:"text-xs text-emerald-400 font-mono",children:"已就绪"}):a?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-amber-400",children:[e.jsx(I,{}),"安装中"]}):e.jsx("span",{className:"text-xs text-muted",children:"未安装"})]}),!s&&!a&&e.jsxs("div",{className:"space-y-2",children:[n.installHint&&e.jsx("p",{className:"text-xs text-muted",children:t(n.installHint)}),e.jsxs("button",{onClick:()=>ge(n.agentType),disabled:!!f,className:"bg-[#0066FF] text-white rounded-md px-4 py-2 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:["安装 ",n.displayName]})]})]},n.agentType)})})]}),x==="done"&&e.jsx("div",{className:"text-center py-4",children:B?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-3 flex items-center justify-center",children:e.jsx("div",{className:"w-8 h-8 border-2 border-white/10 border-t-[#0066FF] rounded-full animate-spin"})}),e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:done.finalizing")}),e.jsx("p",{className:"text-sm text-muted",children:t("setup:done.finalizingDesc")})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-3 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center",children:e.jsx("svg",{className:"w-6 h-6 text-emerald-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:done.complete")}),e.jsx("p",{className:"text-sm text-muted",children:t("setup:done.completeDesc")})]})}),x==="provider"&&(()=>{var u;const n=N.find(o=>o.id===b),s=[...new Set(N.map(o=>o.group))],a=(n==null?void 0:n.local)===!0,d=F.length>0?F.map(o=>({id:o.id,label:o.name||o.id})):((n==null?void 0:n.models)||[]).map(o=>({id:o.id,label:`${o.name} (${Math.round(o.contextWindow/1e3)}K)`}));return e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:provider.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:provider.desc")}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(Re,{title:t("setup:provider.recommendedTitle"),description:t("setup:provider.recommendedDescription"),apiKeyHint:t("setup:provider.apiKeyHint"),selectedProviderId:b,onSelectProvider:ee}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("setup:provider.label")}),e.jsxs("select",{value:b,onChange:o=>ee(o.target.value),className:"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",children:[e.jsx("option",{value:"",children:t("setup:provider.placeholder")}),s.map(o=>e.jsx("optgroup",{label:t(`instance:configForm.providerGroup.${o}`,{defaultValue:o}),children:N.filter(l=>l.group===o).map(l=>e.jsx("option",{value:l.id,children:t(`instance:configForm.providerLabel.${l.id}`,{defaultValue:l.label})},l.id))},o))]})]}),b&&a&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("setup:provider.baseUrl")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:_,onChange:o=>{J(o.target.value),M([])},className:"flex-1 bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60"}),e.jsx("button",{type:"button",onClick:()=>{R()},disabled:S,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(S?"setup:provider.fetchingModels":"setup:provider.fetchModels")})]})]}),b&&!a&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("setup:provider.apiKey")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:q?"text":"password",value:k,onChange:o=>{me(o.target.value),M([])},onPaste:ke,placeholder:t("setup:provider.apiKeyPlaceholder"),className:"w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 pr-9 text-sm text-foreground font-mono placeholder-[var(--muted)] focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60"}),e.jsx("button",{type:"button",onClick:()=>xe(!q),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:q?e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.878 9.878L3 3m6.878 6.878L21 21"}):e.jsxs(e.Fragment,{children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})})]}),e.jsx("button",{type:"button",onClick:()=>{R()},disabled:S||!k.trim(),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(S?"setup:provider.fetchingModels":"setup:provider.fetchModels")})]})]}),n&&d.length>0&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-muted mb-1.5",children:[t("setup:provider.defaultModel"),F.length>0&&e.jsxs("span",{className:"ml-1.5 text-emerald-400 text-xs",children:["(",F.length," ",t("setup:provider.liveModels"),")"]})]}),e.jsx("select",{value:W||((u=d[0])==null?void 0:u.id)||"",onChange:o=>U(o.target.value),className:"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",children:d.map(o=>e.jsx("option",{value:o.id,children:o.label},o.id))})]})]})]})})(),K.length>0&&x!=="done"&&e.jsxs("div",{className:"mt-4 rounded-lg border border-[var(--border)] bg-[linear-gradient(180deg,rgba(2,6,23,0.96),rgba(15,23,42,0.92))] p-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.04)] max-h-40 overflow-y-auto",children:[K.map((n,s)=>{const a=qe(n.tone);return e.jsxs("div",{className:"flex items-start gap-2 py-0.5",children:[e.jsx("span",{className:`mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full ${a.dot}`}),e.jsx("div",{className:`min-w-0 whitespace-pre-wrap break-words text-xs font-mono leading-5 ${a.text}`,children:n.message})]},s)}),e.jsx("div",{className:"pointer-events-none sticky bottom-0 h-4 bg-gradient-to-t from-slate-950/85 to-transparent"})]}),L&&e.jsx("div",{className:"mt-4 bg-red-500/10 border border-red-500/20 text-red-400 text-sm rounded-md px-3 py-2.5",children:L})]}),e.jsx("div",{className:"flex justify-between mt-6",children:x==="provider"?(()=>{var a;const n=((a=N.find(d=>d.id===b))==null?void 0:a.local)===!0,s=b&&(n||k.trim());return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:async()=>{await de({skipped:!0}).catch(()=>{}),P()},className:"bg-[var(--card)] border border-[var(--border)] text-foreground rounded-md px-6 py-2 text-sm font-medium hover:bg-[var(--card-hover)] transition-all duration-200",children:t("setup:provider.skip")}),e.jsx("button",{onClick:async()=>{await Ne()&&P()},disabled:!s||O,className:"bg-[#0066FF] text-white rounded-md px-6 py-2 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)]",children:t(O?"setup:provider.saving":"setup:provider.saveAndContinue")})]})})():x!=="done"?e.jsxs(e.Fragment,{children:[e.jsx("div",{}),e.jsx("button",{onClick:P,disabled:!je(x)||!!f,className:"bg-[#0066FF] text-white rounded-md px-6 py-2 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:t("setup:nav.next")})]}):e.jsx("button",{onClick:L?()=>P():i,disabled:B,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)]",children:t(L?"setup:nav.retry":"setup:nav.enterPanel")})})]})]}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx("div",{className:"w-5 h-5 border-2 border-[var(--border)] border-t-foreground rounded-full animate-spin"})})}export{Oe as default};
|
|
1
|
+
import{g as ae,d as Fe,p as Se,j as e,L as _e,T as Ce,e as de,i as $,f as Ie,r as Le,h as Me,u as Te}from"./index-BZc5zH7u.js";import{r as c}from"./vendor-react-BWrEVJVb.js";import{g as Pe}from"./input-paste-CrNVAyOy.js";import{P as N}from"./providers-DtNXh9JD.js";import{u as Ae}from"./registry-BWnkJgZ1.js";import{P as Re}from"./ProviderRecommendations-BuRnvRcI.js";import{u as le}from"./vendor-i18n-y9V7Sfuu.js";function ce(i,p){var r,j;if(!i)return!1;const t=(r=i.runtimes)==null?void 0:r[p];return t?!!t.installed&&!!t.imageReady:p==="openclaw"?!!((j=i.openclaw)!=null&&j.installed)&&!!i.dockerImageReady:!1}function De(i,p){var r;const t=(r=i==null?void 0:i.runtimes)==null?void 0:r[p];return t&&typeof t.required=="boolean"?t.required:p==="openclaw"}function oe(i,p){if(!i)return!1;const t=p.filter(r=>De(i,r.agentType));return t.length===0?!0:t.every(r=>ce(i,r.agentType))}const C=[{id:"check",label:"环境检测"},{id:"node",label:"Node.js"},{id:"docker",label:"Docker"},{id:"nomad",label:"Nomad"},{id:"openclaw",label:"OpenClaw"},{id:"provider",label:"模型配置"},{id:"done",label:"完成"}];function Ee({ok:i}){return i?e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-emerald-500 shadow-[0_0_6px_rgba(16,185,129,0.7)]"}):e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-[var(--border)]"})}function D({dep:i,label:p,required:t,extra:r}){const{t:j}=le("setup"),x=i.needsUpgrade;return e.jsxs("div",{className:"flex items-center justify-between py-2.5 border-b border-[var(--border)] last:border-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[x?e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-amber-400 shadow-[0_0_6px_rgba(251,191,36,0.6)]"}):e.jsx(Ee,{ok:i.installed}),e.jsx("span",{className:"text-sm text-foreground",children:p||i.name}),x&&e.jsx("span",{className:"text-xs text-amber-400",children:j("versionTooOld")}),t&&!i.installed&&!x&&e.jsx("span",{className:"text-xs text-red-400",children:j("required")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r,e.jsx("span",{className:"text-xs text-muted font-mono",children:i.installed?i.version||"installed":"not installed"})]})]})}function I(){return e.jsx("span",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"})}function ie(i){return/失败|error|denied|forbidden|unauthorized/i.test(i)?"error":/完成|已就绪|已启动|已存在|成功|built|installed/i.test(i)?"success":/正在|等待|下载|安装|构建|启动|升级|progress|exporting|transferring/i.test(i)?"progress":"info"}function qe(i){switch(i){case"progress":return{dot:"bg-sky-400 shadow-[0_0_8px_rgba(56,189,248,0.55)]",text:"text-sky-100"};case"success":return{dot:"bg-emerald-400 shadow-[0_0_8px_rgba(52,211,153,0.55)]",text:"text-emerald-100"};case"error":return{dot:"bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.55)]",text:"text-red-200"};default:return{dot:"bg-slate-500 shadow-[0_0_8px_rgba(148,163,184,0.35)]",text:"text-slate-200/90"}}}function Oe({onDone:i}){var te,se,re,ne;const{runtimes:p}=Ae(),{t}=le(["setup","common","instance"]),[r,j]=c.useState(null),[x,E]=c.useState("check"),[g,w]=c.useState(null),[K,z]=c.useState([]),[L,v]=c.useState(""),[B,H]=c.useState(!1),[b,ue]=c.useState(""),[k,me]=c.useState(""),[q,xe]=c.useState(!1),[W,U]=c.useState(""),[O,V]=c.useState(!1),[F,M]=c.useState([]),[S,G]=c.useState(!1),[_,J]=c.useState(""),Q=c.useRef(new Set),X=c.useCallback((n,s)=>{if(Q.current.has(n))return;Q.current.add(n);const a=s==="openclaw-docker"?t("setup:dockerImageBuild"):s==="docker"?t("setup:dockerInstall"):s==="openclaw"?t("setup:openclawInstall"):s;w(s),h(t("setup:resumeTask",{label:a}),"progress"),Y(n,a).then(()=>{f(!0)}).catch(d=>{v(d.message||t("setup:taskFailed"))}).finally(()=>{w(null)})},[]),f=c.useCallback((n=!1)=>{ae().then(s=>{var a;if(j(s),(a=s.runningTasks)!=null&&a.length)for(const d of s.runningTasks)X(d.id,d.name);if(!n&&s.ready){E("provider");return}}).catch(()=>{})},[i,X]);c.useEffect(()=>{f()},[f]),c.useEffect(()=>{var s,a;if(x!=="nomad"||!((s=r==null?void 0:r.nomad)!=null&&s.installed)||(a=r==null?void 0:r.nomad)!=null&&a.running)return;const n=setInterval(()=>{f(!0)},3e3);return()=>clearInterval(n)},[x,(te=r==null?void 0:r.nomad)==null?void 0:te.installed,(se=r==null?void 0:r.nomad)==null?void 0:se.running,f]);const h=(n,s=ie(n))=>z(a=>[...a,{message:n,tone:s}].slice(-200)),pe=(n,s)=>s.type==="progress"&&typeof s.progress=="number"?`${n}: ${s.message} [${s.progress}%]`:s.type==="done"?`${n}: ${s.message}`:s.type==="error"?t("setup:taskErrorPrefix",{label:n,message:s.message}):s.message,Y=async(n,s)=>{let a=0,d=0,u=t("setup:taskCompleted",{label:s});const o=Date.now()+30*60*1e3;for(;Date.now()<o;){try{const m=await Fe(n);d=0;const ye=m.events.slice(a);a=m.events.length;for(const y of ye){const we=y.type==="done"?"success":y.type==="error"?"error":y.type==="progress"?"progress":ie(y.message);h(pe(s,y),we),y.message&&(u=y.message)}if(m.status==="done")return u;if(m.status==="error")throw new Error(u)}catch(m){if(d+=1,d>=5)throw new Error((m==null?void 0:m.message)||t("setup:taskStatusFailed",{label:s}))}const l=Math.min(1e3+a*200,3e3);await new Promise(m=>setTimeout(m,l))}throw new Error(t("setup:taskTimeout",{label:s}))},T=async(n,s,a)=>{w(n),v(""),h(t("setup:installing",{label:s}),"progress");try{const d=await a();let u=d.message||t("setup:taskStarted",{label:s});return d!=null&&d.taskId?u=await Y(d.taskId,s):h(`${s}: ${u}`,"success"),f(!0),!0}catch(d){const u=d.message||t("setup:defaultInstallFailed");return h(t("setup:installFailed",{label:s,error:u}),"error"),v(u),!1}finally{w(null)}},Z=async()=>{await T("node","Node.js",()=>Te())},be=async()=>{await T("docker","Docker",()=>$("docker"))},[he,ge]=c.useState(!1),fe=async n=>{const s=p.find(d=>d.agentType===n);if(!s)return;s.installHint&&h(t(s.installHint),"info");const a=await T(`runtime-${n}`,t(s.installLabel),()=>Me(n));n==="openclaw"&&a&&ge(!0),f(!0)},ve=async()=>{var s;if(await T("nomad","Nomad",()=>$("nomad"))){h(t("setup:configuringNomadSystemd"),"progress"),w("nomad-systemd");try{await $("nomad-systemd"),h(t("setup:nomadServiceStarted"),"success")}catch{try{await Ie("nomad"),h(t("setup:nomadStarted"),"success")}catch(a){h(t("setup:nomadStartFailed",{error:a.message}),"error"),v(a.message)}}w(null),h(t("setup:waitingNomad"),"progress");for(let a=0;a<10;a++){await new Promise(u=>setTimeout(u,2e3));const d=await ae();if((s=d.nomad)!=null&&s.running){j(d),h(t("setup:nomadReady"),"success");return}}f(!0)}},P=!!((re=r==null?void 0:r.node)!=null&&re.installed)&&!((ne=r==null?void 0:r.node)!=null&&ne.needsUpgrade),A=async()=>{var d,u,o,l;const n=C.findIndex(m=>m.id===x);if(n>=C.length-1)return;let s=n+1;for(;s<C.length-1;){const m=C[s].id;if(m==="node"&&P){s++;continue}if(m==="docker"&&((d=r==null?void 0:r.docker)!=null&&d.installed)&&((u=r==null?void 0:r.docker)!=null&&u.running)){s++;continue}if(m==="nomad"&&((o=r==null?void 0:r.nomad)!=null&&o.installed)&&((l=r==null?void 0:r.nomad)!=null&&l.running)){s++;continue}if(m==="openclaw"&&oe(r,p)){s++;continue}break}const a=C[s].id;if(v(""),z([]),a==="done"){E("done"),H(!0);try{await Le({installNomad:!1,buildDockerImage:!1})}catch(m){v(m.message||t("setup:configWriteFailed"))}finally{H(!1)}}else E(a)},je=n=>{if(!r)return!1;switch(n){case"check":return P;case"node":return P;case"docker":return r.docker.installed&&r.docker.running;case"nomad":return r.nomad.installed&&r.nomad.running;case"openclaw":return oe(r,p)||he&&r.openclaw.installed&&p.length===1;case"provider":return!0;case"done":return!0;default:return!1}},ee=c.useCallback(n=>{ue(n),U(""),M([]);const s=N.find(a=>a.id===n);J((s==null?void 0:s.baseUrl)||"")},[]),R=c.useCallback(async n=>{if(!b)return;const s=N.find(l=>l.id===b);if(!s)return;const d=s.local===!0&&_.trim()?_.trim():s.baseUrl,u=s.authHeader?"x-api-key":"Authorization",o=n??k;G(!0),v("");try{const{models:l}=await Se(d,o,u,s.id,s.api);M(l),l.length>0&&U(l[0].id)}catch(l){v(l.message||t("setup:provider.fetchModelsFailed"))}finally{G(!1)}},[k,_,b,t]),ke=c.useCallback(n=>{if(!b||S)return;const s=N.find(d=>d.id===b);if(!s||s.local===!0)return;const a=Pe(k,n).trim();a&&R(a)},[k,S,R,b]),Ne=async()=>{var o;if(!b)return!1;const n=N.find(l=>l.id===b);if(!n)return!1;const s=n.local===!0,a=s&&_.trim()?_.trim():n.baseUrl;if(s&&!a)return v(t("setup:provider.baseUrlRequired",{defaultValue:"Base URL is required"})),!1;const d=F.length>0?F.map(l=>({id:l.id,name:l.name||l.id,contextWindow:128e3})):n.models,u=W||((o=d[0])==null?void 0:o.id)||"";V(!0);try{return await de({providerId:n.id,baseUrl:a,api:n.api,authHeader:n.authHeader?"x-api-key":void 0,models:d,selectedModelId:u,apiKey:k||""}),!0}catch(l){return v(l.message||t("setup:provider.saveFailed")),!1}finally{V(!1)}};return r?e.jsxs("div",{className:"min-h-screen flex items-center justify-center p-4 bg-background relative overflow-hidden",children:[e.jsx("div",{className:"grid-bg absolute inset-0 pointer-events-none"}),e.jsx("div",{className:"absolute top-1/3 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[600px] h-[400px] rounded-full bg-[#0066FF]/[0.06] blur-[100px] pointer-events-none"}),e.jsx("div",{className:"absolute left-4 bottom-4 z-20",children:e.jsx(_e,{className:"bg-card/80 backdrop-blur-sm"})}),e.jsxs("div",{className:"w-full max-w-lg relative z-10",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx(Ce,{className:"w-48 h-48 mx-auto mb-4 object-contain"}),e.jsx("p",{className:"text-sm text-muted mt-1",children:t("setup:title")})]}),e.jsxs("div",{className:"bg-card border border-[var(--border)] rounded-xl p-6 backdrop-blur-sm",children:[x==="check"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:check.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:check.desc")}),e.jsx("p",{className:"text-xs text-muted mb-1.5 font-medium",children:t("setup:check.requiredComponents")}),e.jsxs("div",{className:"bg-card rounded-md border border-[var(--border)] px-4",children:[e.jsx(D,{dep:r.node,label:"Node.js",required:!0,extra:r.node.needsUpgrade?e.jsx("button",{onClick:Z,disabled:!!g,className:"text-xs bg-amber-500/20 text-amber-400 border border-amber-500/30 rounded px-2 py-0.5 hover:bg-amber-500/30 disabled:opacity-40 transition-colors duration-200",children:t(g==="node"?"setup:check.upgrading":"setup:check.upgrade")}):void 0}),e.jsx(D,{dep:r.docker,label:"Docker",required:!0}),e.jsx(D,{dep:r.nomad,label:"Nomad",required:!0}),e.jsx(D,{dep:r.openclaw,label:"OpenClaw",required:!0})]})]}),x==="node"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:node.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:node.desc")}),P?e.jsx("div",{className:"bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 text-sm rounded-md px-3 py-2.5",children:t("setup:node.ready",{version:r.node.version})}):r.hasSudo?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:t("setup:node.currentVersion",{version:r.node.version})}),e.jsx("button",{onClick:Z,disabled:!!g,className:"bg-[#0066FF] text-white rounded-md px-4 py-2 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:g?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(I,{}),t("setup:node.upgrading")]}):t("setup:node.upgradeBtn")}),e.jsx("p",{className:"text-xs text-muted",children:t("setup:node.sudoRequired")})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:t("setup:node.noSudo",{version:r.node.version})}),e.jsxs("div",{className:"bg-card border border-[var(--border)] rounded-md p-3",children:[e.jsx("p",{className:"text-xs text-muted mb-1.5",children:t("setup:node.contactAdmin")}),e.jsx("code",{className:"text-xs text-foreground font-mono block whitespace-pre-wrap",children:"curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && sudo apt-get install -y nodejs"})]}),e.jsx("button",{onClick:()=>f(!0),className:"text-xs text-muted hover:text-foreground underline transition-colors duration-200",children:t("setup:node.refreshAfterInstall")})]})]}),x==="docker"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:docker.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:docker.desc")}),r.docker.installed&&r.docker.running?e.jsx("div",{className:"bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 text-sm rounded-md px-3 py-2.5",children:t("setup:docker.running",{version:r.docker.version})}):r.docker.installed&&!r.docker.running?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:t("setup:docker.notRunning")}),e.jsx("div",{className:"bg-card border border-[var(--border)] rounded-md p-3",children:e.jsx("code",{className:"text-xs text-foreground font-mono block",children:"sudo systemctl start docker"})}),e.jsx("button",{onClick:()=>f(!0),className:"text-xs text-muted hover:text-foreground underline transition-colors duration-200",children:t("setup:docker.refreshAfterStart")})]}):r.hasSudo?e.jsxs("div",{className:"space-y-3",children:[e.jsx("button",{onClick:be,disabled:!!g,className:"bg-[#0066FF] text-white rounded-md px-4 py-2 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:g?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(I,{}),t("setup:docker.installing")]}):t("setup:docker.installBtn")}),e.jsx("p",{className:"text-xs text-muted",children:t("setup:docker.sudoRequired")})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:t("setup:docker.noSudo")}),e.jsxs("div",{className:"bg-card border border-[var(--border)] rounded-md p-3",children:[e.jsx("p",{className:"text-xs text-muted mb-1.5",children:t("setup:docker.contactAdmin")}),e.jsx("code",{className:"text-xs text-foreground font-mono block",children:"curl -fsSL https://get.docker.com | sh"})]}),e.jsx("button",{onClick:()=>f(!0),className:"text-xs text-muted hover:text-foreground underline transition-colors duration-200",children:t("setup:docker.refreshAfterInstall")})]})]}),x==="nomad"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:nomad.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:nomad.desc")}),r.nomad.installed&&r.nomad.running?e.jsx("div",{className:"bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 text-sm rounded-md px-3 py-2.5",children:t("setup:nomad.running",{version:r.nomad.version})}):r.nomad.installed?e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex items-center gap-2 bg-amber-500/10 border border-amber-500/20 text-amber-400 text-sm rounded-md px-3 py-2.5",children:[e.jsx(I,{}),e.jsx("span",{children:t("setup:nomad.starting")})]})}):e.jsx("button",{onClick:ve,disabled:!!g,className:"bg-[#0066FF] text-white rounded-md px-4 py-2 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:g?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(I,{}),t("setup:nomad.installing")]}):t("setup:nomad.installBtn")})]}),x==="openclaw"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:"Agent 运行时"}),e.jsx("p",{className:"text-sm text-muted mb-4",children:"安装所有已注册的 Agent 运行时 (Docker 镜像 / shim)。每次添加新 Agent 时,这里会自动出现一行。"}),e.jsx("div",{className:"space-y-4",children:p.map(n=>{const s=ce(r,n.agentType),a=g===`runtime-${n.agentType}`;return e.jsxs("div",{className:"rounded-md border border-[var(--border)] bg-[var(--card)] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:n.displayName}),e.jsx("div",{className:"text-xs text-muted",children:n.description})]}),s?e.jsx("span",{className:"text-xs text-emerald-400 font-mono",children:"已就绪"}):a?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-amber-400",children:[e.jsx(I,{}),"安装中"]}):e.jsx("span",{className:"text-xs text-muted",children:"未安装"})]}),!s&&!a&&e.jsxs("div",{className:"space-y-2",children:[n.installHint&&e.jsx("p",{className:"text-xs text-muted",children:t(n.installHint)}),e.jsxs("button",{onClick:()=>fe(n.agentType),disabled:!!g,className:"bg-[#0066FF] text-white rounded-md px-4 py-2 text-sm font-medium hover:bg-[#0066FF]/90 disabled:opacity-40 transition-all duration-200",children:["安装 ",n.displayName]})]})]},n.agentType)})})]}),x==="done"&&e.jsx("div",{className:"text-center py-4",children:B?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-3 flex items-center justify-center",children:e.jsx("div",{className:"w-8 h-8 border-2 border-white/10 border-t-[#0066FF] rounded-full animate-spin"})}),e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:done.finalizing")}),e.jsx("p",{className:"text-sm text-muted",children:t("setup:done.finalizingDesc")})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-3 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center",children:e.jsx("svg",{className:"w-6 h-6 text-emerald-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:done.complete")}),e.jsx("p",{className:"text-sm text-muted",children:t("setup:done.completeDesc")})]})}),x==="provider"&&(()=>{var u;const n=N.find(o=>o.id===b),s=[...new Set(N.map(o=>o.group))],a=(n==null?void 0:n.local)===!0,d=F.length>0?F.map(o=>({id:o.id,label:o.name||o.id})):((n==null?void 0:n.models)||[]).map(o=>({id:o.id,label:`${o.name} (${Math.round(o.contextWindow/1e3)}K)`}));return e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium text-foreground mb-1",children:t("setup:provider.title")}),e.jsx("p",{className:"text-sm text-muted mb-4",children:t("setup:provider.desc")}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(Re,{title:t("setup:provider.recommendedTitle"),description:t("setup:provider.recommendedDescription"),apiKeyHint:t("setup:provider.apiKeyHint"),selectedProviderId:b,onSelectProvider:ee}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("setup:provider.label")}),e.jsxs("select",{value:b,onChange:o=>ee(o.target.value),className:"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",children:[e.jsx("option",{value:"",children:t("setup:provider.placeholder")}),s.map(o=>e.jsx("optgroup",{label:t(`instance:configForm.providerGroup.${o}`,{defaultValue:o}),children:N.filter(l=>l.group===o).map(l=>e.jsx("option",{value:l.id,children:t(`instance:configForm.providerLabel.${l.id}`,{defaultValue:l.label})},l.id))},o))]})]}),b&&a&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("setup:provider.baseUrl")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:_,onChange:o=>{J(o.target.value),M([])},className:"flex-1 bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60"}),e.jsx("button",{type:"button",onClick:()=>{R()},disabled:S,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(S?"setup:provider.fetchingModels":"setup:provider.fetchModels")})]})]}),b&&!a&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:t("setup:provider.apiKey")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:q?"text":"password",value:k,onChange:o=>{me(o.target.value),M([])},onPaste:ke,placeholder:t("setup:provider.apiKeyPlaceholder"),className:"w-full bg-[var(--input-bg)] border border-[var(--border)] rounded-md px-3 py-2 pr-9 text-sm text-foreground font-mono placeholder-[var(--muted)] focus:outline-none focus:ring-1 focus:ring-[#0066FF]/60"}),e.jsx("button",{type:"button",onClick:()=>xe(!q),"aria-label":t("common:action.togglePassword"),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground",children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:q?e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.878 9.878L3 3m6.878 6.878L21 21"}):e.jsxs(e.Fragment,{children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})})]}),e.jsx("button",{type:"button",onClick:()=>{R()},disabled:S||!k.trim(),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(S?"setup:provider.fetchingModels":"setup:provider.fetchModels")})]})]}),n&&d.length>0&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-muted mb-1.5",children:[t("setup:provider.defaultModel"),F.length>0&&e.jsxs("span",{className:"ml-1.5 text-emerald-400 text-xs",children:["(",F.length," ",t("setup:provider.liveModels"),")"]})]}),e.jsx("select",{value:W||((u=d[0])==null?void 0:u.id)||"",onChange:o=>U(o.target.value),className:"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",children:d.map(o=>e.jsx("option",{value:o.id,children:o.label},o.id))})]})]})]})})(),K.length>0&&x!=="done"&&e.jsxs("div",{className:"mt-4 rounded-lg border border-[var(--border)] bg-[linear-gradient(180deg,rgba(2,6,23,0.96),rgba(15,23,42,0.92))] p-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.04)] max-h-40 overflow-y-auto",children:[K.map((n,s)=>{const a=qe(n.tone);return e.jsxs("div",{className:"flex items-start gap-2 py-0.5",children:[e.jsx("span",{className:`mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full ${a.dot}`}),e.jsx("div",{className:`min-w-0 whitespace-pre-wrap break-words text-xs font-mono leading-5 ${a.text}`,children:n.message})]},s)}),e.jsx("div",{className:"pointer-events-none sticky bottom-0 h-4 bg-gradient-to-t from-slate-950/85 to-transparent"})]}),L&&e.jsx("div",{className:"mt-4 bg-red-500/10 border border-red-500/20 text-red-400 text-sm rounded-md px-3 py-2.5",children:L})]}),e.jsx("div",{className:"flex justify-between mt-6",children:x==="provider"?(()=>{var a;const n=((a=N.find(d=>d.id===b))==null?void 0:a.local)===!0,s=b&&(n||k.trim());return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:async()=>{await de({skipped:!0}).catch(()=>{}),A()},className:"bg-[var(--card)] border border-[var(--border)] text-foreground rounded-md px-6 py-2 text-sm font-medium hover:bg-[var(--card-hover)] transition-all duration-200",children:t("setup:provider.skip")}),e.jsx("button",{onClick:async()=>{await Ne()&&A()},disabled:!s||O,className:"bg-[#0066FF] text-white rounded-md px-6 py-2 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)]",children:t(O?"setup:provider.saving":"setup:provider.saveAndContinue")})]})})():x!=="done"?e.jsxs(e.Fragment,{children:[e.jsx("div",{}),e.jsx("button",{onClick:A,disabled:!je(x)||!!g,className:"bg-[#0066FF] text-white rounded-md px-6 py-2 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:t("setup:nav.next")})]}):e.jsx("button",{onClick:L?()=>A():i,disabled:B,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)]",children:t(L?"setup:nav.retry":"setup:nav.enterPanel")})})]})]}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx("div",{className:"w-5 h-5 border-2 border-[var(--border)] border-t-foreground rounded-full animate-spin"})})}export{Oe as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as c,a4 as fe,aE as me,I as ge,a as pe,ab as xe,ad as we,aF as Y,ac as be,ae as Ee}from"./index-
|
|
1
|
+
import{j as c,a4 as fe,aE as me,I as ge,a as pe,ab as xe,ad as we,aF as Y,ac as be,ae as Ee}from"./index-BZc5zH7u.js";import{e as A,r as y}from"./vendor-react-BWrEVJVb.js";import{u as B}from"./vendor-i18n-y9V7Sfuu.js";var ve=Object.defineProperty,D=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,V=(a,i,s)=>i in a?ve(a,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[i]=s,z=(a,i)=>{for(var s in i||(i={}))W.call(i,s)&&V(a,s,i[s]);if(D)for(var s of D(i))X.call(i,s)&&V(a,s,i[s]);return a},_=(a,i)=>{var s={};for(var d in a)W.call(a,d)&&i.indexOf(d)<0&&(s[d]=a[d]);if(a!=null&&D)for(var d of D(a))i.indexOf(d)<0&&X.call(a,d)&&(s[d]=a[d]);return s};/**
|
|
2
2
|
* @license QR Code generator library (TypeScript)
|
|
3
3
|
* Copyright (c) Project Nayuki.
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
@@ -6,4 +6,4 @@ import{j as c,a4 as fe,aE as me,I as ge,a as pe,ab as xe,ad as we,aF as Y,ac as
|
|
|
6
6
|
* @license qrcode.react
|
|
7
7
|
* Copyright (c) Paul O'Shannessy
|
|
8
8
|
* SPDX-License-Identifier: ISC
|
|
9
|
-
*/var Ne={L:O.QrCode.Ecc.LOW,M:O.QrCode.Ecc.MEDIUM,Q:O.QrCode.Ecc.QUARTILE,H:O.QrCode.Ecc.HIGH},Z=128,J="L",ee="#FFFFFF",te="#000000",re=!1,se=1,ye=4,Ce=0,Fe=.1;function ne(a,i=0){const s=[];return a.forEach(function(d,h){let l=null;d.forEach(function(E,x){if(!E&&l!==null){s.push(`M${l+i} ${h+i}h${x-l}v1H${l+i}z`),l=null;return}if(x===d.length-1){if(!E)return;l===null?s.push(`M${x+i},${h+i} h1v1H${x+i}z`):s.push(`M${l+i},${h+i} h${x+1-l}v1H${l+i}z`);return}E&&l===null&&(l=x)})}),s.join("")}function oe(a,i){return a.slice().map((s,d)=>d<i.y||d>=i.y+i.h?s:s.map((h,l)=>l<i.x||l>=i.x+i.w?h:!1))}function Re(a,i,s,d){if(d==null)return null;const h=a.length+s*2,l=Math.floor(i*Fe),E=h/i,x=(d.width||l)*E,e=(d.height||l)*E,r=d.x==null?a.length/2-x/2:d.x*E,t=d.y==null?a.length/2-e/2:d.y*E,n=d.opacity==null?1:d.opacity;let o=null;if(d.excavate){let u=Math.floor(r),m=Math.floor(t),g=Math.ceil(x+r-u),C=Math.ceil(e+t-m);o={x:u,y:m,w:g,h:C}}const f=d.crossOrigin;return{x:r,y:t,h:e,w:x,excavation:o,opacity:n,crossOrigin:f}}function Me(a,i){return i!=null?Math.max(Math.floor(i),0):a?ye:Ce}function ie({value:a,level:i,minVersion:s,includeMargin:d,marginSize:h,imageSettings:l,size:E,boostLevel:x}){let e=A.useMemo(()=>{const u=(Array.isArray(a)?a:[a]).reduce((m,g)=>(m.push(...O.QrSegment.makeSegments(g)),m),[]);return O.QrCode.encodeSegments(u,Ne[i],s,void 0,void 0,x)},[a,i,s,x]);const{cells:r,margin:t,numCells:n,calculatedImageSettings:o}=A.useMemo(()=>{let f=e.getModules();const u=Me(d,h),m=f.length+u*2,g=Re(f,E,u,l);return{cells:f,margin:u,numCells:m,calculatedImageSettings:g}},[e,E,l,d,h]);return{qrcode:e,margin:t,cells:r,numCells:n,calculatedImageSettings:o}}var Ae=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),Se=A.forwardRef(function(i,s){const d=i,{value:h,size:l=Z,level:E=J,bgColor:x=ee,fgColor:e=te,includeMargin:r=re,minVersion:t=se,boostLevel:n,marginSize:o,imageSettings:f}=d,m=z(d,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:g}=m,C=z(m,["style"]),F=f==null?void 0:f.src,p=A.useRef(null),N=A.useRef(null),S=A.useCallback(L=>{p.current=L,typeof s=="function"?s(L):s&&(s.current=L)},[s]),[w,M]=A.useState(!1),{margin:v,cells:I,numCells:B,calculatedImageSettings:P}=ie({value:h,level:E,minVersion:t,boostLevel:n,includeMargin:r,marginSize:o,imageSettings:f,size:l});A.useEffect(()=>{if(p.current!=null){const L=p.current,j=L.getContext("2d");if(!j)return;let $=I;const k=N.current,K=P!=null&&k!==null&&k.complete&&k.naturalHeight!==0&&k.naturalWidth!==0;K&&P.excavation!=null&&($=oe(I,P.excavation));const q=window.devicePixelRatio||1;L.height=L.width=l*q;const G=l/B*q;j.scale(G,G),j.fillStyle=x,j.fillRect(0,0,B,B),j.fillStyle=e,Ae?j.fill(new Path2D(ne($,v))):I.forEach(function(ce,ue){ce.forEach(function(de,he){de&&j.fillRect(he+v,ue+v,1,1)})}),P&&(j.globalAlpha=P.opacity),K&&j.drawImage(k,P.x+v,P.y+v,P.w,P.h)}}),A.useEffect(()=>{M(!1)},[F]);const le=U({height:l,width:l},g);let H=null;return F!=null&&(H=A.createElement("img",{src:F,key:F,style:{display:"none"},onLoad:()=>{M(!0)},ref:N,crossOrigin:P==null?void 0:P.crossOrigin})),A.createElement(A.Fragment,null,A.createElement("canvas",U({style:le,height:l,width:l,ref:S,role:"img"},C)),H)});Se.displayName="QRCodeCanvas";var Q=A.forwardRef(function(i,s){const d=i,{value:h,size:l=Z,level:E=J,bgColor:x=ee,fgColor:e=te,includeMargin:r=re,minVersion:t=se,boostLevel:n,title:o,marginSize:f,imageSettings:u}=d,m=z(d,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:g,cells:C,numCells:F,calculatedImageSettings:p}=ie({value:h,level:E,minVersion:t,boostLevel:n,includeMargin:r,marginSize:f,imageSettings:u,size:l});let N=C,S=null;u!=null&&p!=null&&(p.excavation!=null&&(N=oe(C,p.excavation)),S=A.createElement("image",{href:u.src,height:p.h,width:p.w,x:p.x+g,y:p.y+g,preserveAspectRatio:"none",opacity:p.opacity,crossOrigin:p.crossOrigin}));const w=ne(N,g);return A.createElement("svg",U({height:l,width:l,viewBox:`0 0 ${F} ${F}`,ref:s,role:"img"},m),!!o&&A.createElement("title",null,o),A.createElement("path",{fill:x,d:`M0,0 h${F}v${F}H0z`,shapeRendering:"crispEdges"}),A.createElement("path",{fill:e,d:w,shapeRendering:"crispEdges"}),S)});Q.displayName="QRCodeSVG";const De=[{id:"feishu",labelKey:"configForm.channel.feishu",fields:[],defaults:{connectionMode:"websocket"}},{id:"openclaw-weixin",labelKey:"configForm.channel.openclaw-weixin",fields:[],defaults:{}},{id:"telegram",labelKey:"configForm.channel.telegram",fields:[{key:"botToken",label:"Bot Token",type:"password",placeholder:"From @BotFather"}]},{id:"discord",labelKey:"configForm.channel.discord",fields:[{key:"token",label:"Bot Token",type:"password",placeholder:"From Discord Developer Portal"}]},{id:"slack",labelKey:"configForm.channel.slack",fields:[{key:"botToken",label:"Bot Token (xoxb-...)",type:"password",placeholder:"xoxb-..."},{key:"appToken",label:"App Token (xapp-...)",type:"password",placeholder:"xapp-..."}]},{id:"whatsapp",labelKey:"configForm.channel.whatsapp",fields:[],defaults:{}},{id:"msteams",labelKey:"configForm.channel.msteams",fields:[{key:"appId",label:"App ID",placeholder:"Azure App Registration ID"},{key:"appPassword",label:"App Password",type:"password",placeholder:"Azure App Secret"},{key:"tenantId",label:"Tenant ID",placeholder:"Azure AD Tenant ID"}]},{id:"signal",labelKey:"configForm.channel.signal",fields:[{key:"account",label:"Phone (E.164)",placeholder:"+8613800138000"}]},{id:"line",labelKey:"configForm.channel.line",fields:[{key:"channelAccessToken",label:"Channel Access Token",type:"password",placeholder:"From LINE Developers"},{key:"channelSecret",label:"Channel Secret",type:"password",placeholder:"LINE Channel Secret"}]},{id:"googlechat",labelKey:"configForm.channel.googlechat",fields:[{key:"serviceAccountFile",label:"Service Account JSON Path",placeholder:"/path/to/service-account.json"}]}];function Be(a,i,s){const d=structuredClone(a),h=i.split(".");let l=d;for(let E=0;E<h.length-1;E++)l[h[E]]===void 0&&(l[h[E]]={}),l=l[h[E]];return l[h[h.length-1]]=s,d}const ae="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",Pe="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-[#0066FF]/60 focus:border-[#0066FF]/60 transition-colors duration-200 appearance-none";function Ue({label:a,hint:i,children:s}){return c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:a}),s,i&&c.jsx("p",{className:"text-xs text-muted mt-1 opacity-60",children:i})]})}function ze({value:a,saved:i,onChange:s,placeholder:d,onPaste:h}){const{t:l}=_("instance"),[E,x]=y.useState(!1),e="••••••••••••••••••••••••••••••";return i&&!E&&!a?c.jsx("div",{className:"relative",children:c.jsx("input",{type:"password",value:e,readOnly:!0,onFocus:()=>x(!0),onPaste:r=>{var n;const t=((n=r.clipboardData)==null?void 0:n.getData("text"))??"";t&&(r.preventDefault(),x(!0),s(t),h==null||h(r))},className:`${ae} cursor-text`,title:l("config.clickToEdit")})}):c.jsx(je,{value:a,onChange:s,onPaste:h,placeholder:d,type:"password",mono:!0})}function je({value:a,onChange:i,placeholder:s,type:d="text",mono:h,onPaste:l}){const[E,x]=y.useState(!1),e=d==="password";return c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:e&&!E?"password":"text",value:a||"",onChange:r=>i(r.target.value),onPaste:l,placeholder:s,className:`${ae} ${h?"font-mono text-[13px]":""} ${e?"pr-9":""}`}),e&&c.jsx("button",{type:"button",onClick:()=>x(!E),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground",children:E?c.jsx(ge,{className:"w-3.5 h-3.5"}):c.jsx(pe,{className:"w-3.5 h-3.5"})})]})}function _e({value:a,onChange:i,children:s}){return c.jsx("select",{value:a||"",onChange:d=>i(d.target.value),className:Pe,children:s})}function Qe({checked:a,onChange:i,label:s}){return c.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer",children:[c.jsx("button",{type:"button",role:"switch","aria-checked":a,onClick:()=>i(!a),className:`w-9 h-5 rounded-full relative transition-colors duration-200 ${a?"bg-[#0066FF]":"bg-[var(--input-bg)]"}`,children:c.jsx("div",{className:`w-3.5 h-3.5 bg-white rounded-full absolute top-[3px] transition-transform duration-200 ${a?"left-[18px]":"left-[3px]"}`})}),c.jsx("span",{className:"text-sm text-muted",children:s})]})}function He({title:a,defaultOpen:i=!0,id:s,children:d}){const[h,l]=y.useState(i);return c.jsxs("div",{id:s,className:"bg-[var(--card)] border border-[var(--border)] rounded-xl overflow-hidden hover:border-[var(--border-hover)] transition-colors duration-200",children:[c.jsxs("button",{type:"button",onClick:()=>l(!h),className:"w-full px-4 py-3 flex items-center justify-between text-left hover:bg-[var(--card-hover)] transition-colors duration-150",children:[c.jsx("span",{className:"text-sm font-medium text-foreground",children:a}),h?c.jsx(fe,{className:"w-4 h-4 text-muted"}):c.jsx(me,{className:"w-4 h-4 text-muted"})]}),h&&c.jsx("div",{className:"px-4 pb-4 space-y-4 border-t border-[var(--border)] pt-4",children:d})]})}function $e({instanceId:a,channelKey:i,existingAppId:s,existingDomain:d,onConfigured:h}){const{t:l}=_(["instance","common"]),[E,x]=y.useState(""),[,e]=y.useState(""),[r,t]=y.useState("idle"),[n,o]=y.useState(""),[f,u]=y.useState(""),m=y.useRef(!1),g=y.useRef(!1),C=y.useRef(0),F=6,p=async()=>{if(a){g.current=!1,t("loading"),o(""),x("");try{let w=null;for(let M=0;M<3;M++){if(g.current)return;try{if(w=await xe(a,i),w!=null&&w.qrcodeUrl)break}catch{M<2&&await new Promise(v=>setTimeout(v,1500))}}if(g.current)return;w!=null&&w.qrcodeUrl?(x(w.qrcodeUrl),e(w.sessionKey),t("waiting"),o(l("configForm.feishu.scanHint")),N(w.sessionKey)):(t("error"),o(l("qr.getFailed")))}catch{g.current||(t("error"),o(l("qr.getFailed")))}}},N=w=>{if(!a||m.current)return;m.current=!0,C.current=0;const M=async()=>{if(m.current)try{const v=await we(a,w);if(C.current=0,v.connected){m.current=!1,t("confirmed"),o(v.message||l("qr.loginSuccess")),u(v.domain||"feishu"),x(""),h==null||h();return}if(v.status==="expired"){m.current=!1,t("error"),o(v.message||l("qr.expired"));return}setTimeout(M,3e3)}catch{if(!m.current)return;if(C.current+=1,C.current>=F){m.current=!1,t("error"),o(l("qr.pollFailed",{defaultValue:"轮询失败,请刷新后重试"}));return}setTimeout(M,3e3)}};M()};if(y.useEffect(()=>()=>{m.current=!1},[]),r==="confirmed")return c.jsxs("div",{className:"bg-emerald-500/10 border border-emerald-500/20 rounded-md px-4 py-3 text-sm",children:[c.jsxs("div",{className:"flex items-center gap-2 text-emerald-400",children:[c.jsx("span",{className:"text-lg",children:"✓"}),c.jsx("span",{className:"font-medium",children:n})]}),c.jsx("p",{className:"text-xs text-muted mt-1",children:l("configForm.feishu.platform",{platform:l(f==="lark"?"configForm.feishu.platformLark":"configForm.feishu.platformFeishu")})})]});if(r==="idle"||r==="error")return c.jsxs("div",{className:"bg-[var(--card-hover)] rounded-md px-4 py-3 space-y-3",children:[s&&c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-muted mb-1",children:l("configForm.feishu.added")}),c.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[c.jsx("span",{className:"text-emerald-400",children:"✓"}),c.jsx("code",{className:"font-mono text-foreground/70",children:s}),c.jsx("span",{className:"text-muted opacity-60",children:d==="lark"?"Lark":l("configForm.feishu.platformFeishu")})]})]}),c.jsxs("div",{children:[c.jsx("button",{onClick:p,className:"px-4 py-2 bg-[#3370FF] text-white rounded-md text-xs font-medium hover:bg-[#3370FF]/90 transition-colors",children:l("configForm.feishu.addBot")}),c.jsx("p",{className:"text-xs text-muted mt-2",children:l("configForm.feishu.addBotHint")})]})]});const S=()=>{g.current=!0,m.current=!1,t("idle"),o(""),x(""),e("")};return c.jsx("div",{className:"bg-[var(--card-hover)] rounded-md px-4 py-4",children:c.jsxs("div",{className:"flex flex-col items-center gap-3",children:[E?c.jsx(Q,{value:E,size:192,className:"rounded-lg"}):c.jsx("div",{className:"w-48 h-48 flex items-center justify-center",children:c.jsx("div",{className:"w-6 h-6 border-2 border-[#3370FF]/30 border-t-[#3370FF] rounded-full animate-spin"})}),c.jsx("div",{className:"text-sm text-muted",children:r==="loading"?l("configForm.feishu.gettingQr"):n}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("button",{onClick:S,className:"px-3 py-1.5 text-xs text-white bg-red-500 rounded-md hover:bg-red-500/90 transition-colors",children:l("configForm.feishu.cancel")}),c.jsx("button",{onClick:()=>{S(),setTimeout(p,100)},className:"px-3 py-1.5 text-xs text-white bg-[#0066FF] rounded-md hover:bg-[#0066FF]/90 transition-colors",children:l("configForm.feishu.refresh")})]})]})})}function Ke({instanceId:a,onConfigured:i}){const{t:s,i18n:d}=_(["instance","common"]),[h,l]=y.useState(""),[,E]=y.useState(""),[x,e]=y.useState("idle"),[r,t]=y.useState(""),[n,o]=y.useState(""),[f,u]=y.useState([]),m=y.useRef(!1),g=y.useRef(!1),C=y.useRef(0),F=6;y.useEffect(()=>{a&&Y(a).then(w=>{var M;(M=w==null?void 0:w.accounts)!=null&&M.length&&u(w.accounts)}).catch(()=>{})},[a]);const p=async()=>{if(a){g.current=!1,e("loading"),t(""),l("");try{let w=null;for(let M=0;M<3;M++){if(g.current)return;try{if(w=await be(a),w!=null&&w.qrcodeUrl)break}catch{M<2&&await new Promise(v=>setTimeout(v,1500))}}if(g.current)return;w!=null&&w.qrcodeUrl?(l(w.qrcodeUrl),E(w.sessionKey),e("waiting"),t(s("configForm.weixin.scanHint")),N(w.sessionKey)):(e("error"),t(s("qr.getFailed")))}catch{g.current||(e("error"),t(s("qr.getFailed")))}}},N=w=>{if(!a||m.current)return;m.current=!0,C.current=0;const M=async()=>{if(m.current)try{const v=await Ee(a,w);if(C.current=0,v.connected){m.current=!1,e("confirmed"),t(v.message||s("qr.loginSuccess")),o(v.accountId||""),l(""),a&&Y(a).then(I=>{I!=null&&I.accounts&&u(I.accounts)}).catch(()=>{}),i==null||i();return}if(v.status==="scaned")e("scaned"),t(v.message||s("qr.scaned"));else if(v.status==="refreshed"&&v.qrcodeUrl)l(v.qrcodeUrl),e("waiting"),t(s("qr.refreshed"));else if(v.status==="expired"){m.current=!1,e("error"),t(v.message||s("qr.expired"));return}setTimeout(M,2e3)}catch{if(!m.current)return;if(C.current+=1,C.current>=F){m.current=!1,e("error"),t(s("qr.pollFailed",{defaultValue:"轮询失败,请刷新后重试"}));return}setTimeout(M,3e3)}};M()};if(y.useEffect(()=>()=>{m.current=!1},[]),x==="confirmed")return c.jsxs("div",{className:"bg-emerald-500/10 border border-emerald-500/20 rounded-md px-4 py-3 text-sm",children:[c.jsxs("div",{className:"flex items-center gap-2 text-emerald-400",children:[c.jsx("span",{className:"text-lg",children:"✓"}),c.jsx("span",{className:"font-medium",children:r})]}),n&&c.jsxs("p",{className:"text-xs text-muted mt-1",children:[s("configForm.weixin.accountId")," ",c.jsx("code",{className:"font-mono",children:n})]}),c.jsx("p",{className:"text-xs text-muted mt-1",children:s("configForm.weixin.restartHint")}),c.jsx("button",{onClick:p,className:"mt-2 px-3 py-1 text-xs border border-emerald-500/30 rounded text-emerald-400 hover:bg-emerald-500/10 transition-colors",children:s("configForm.weixin.addAnother")})]});if(x==="idle"||x==="error")return c.jsxs("div",{className:"bg-[var(--card-hover)] rounded-md px-4 py-3 space-y-3",children:[f.length>0&&c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-muted mb-1.5",children:s("configForm.weixin.added")}),f.map(w=>c.jsxs("div",{className:"flex items-center gap-2 text-xs py-1",children:[c.jsx("span",{className:"text-emerald-400",children:"✓"}),c.jsx("code",{className:"font-mono text-foreground/70",children:w.accountId}),w.savedAt&&c.jsx("span",{className:"text-muted opacity-60",children:new Date(w.savedAt).toLocaleDateString(d.language==="zh"?"zh-CN":"en-US")})]},w.accountId))]}),c.jsxs("div",{children:[c.jsx("button",{onClick:p,className:"px-4 py-2 bg-[#07C160] text-white rounded-md text-xs font-medium hover:bg-[#07C160]/90 transition-colors",children:s("configForm.weixin.addClawBot")}),c.jsx("p",{className:"text-xs text-muted mt-2",children:s("configForm.weixin.addClawBotHint",{extra:f.length>0?s("configForm.weixin.addClawBotHintRestart"):s("configForm.weixin.addClawBotHintMulti")})})]})]});const S=()=>{g.current=!0,m.current=!1,e("idle"),t(""),l(""),E("")};return c.jsx("div",{className:"bg-[var(--card-hover)] rounded-md px-4 py-4",children:c.jsxs("div",{className:"flex flex-col items-center gap-3",children:[h?c.jsx(Q,{value:h,size:192,className:"rounded-lg"}):c.jsx("div",{className:"w-48 h-48 flex items-center justify-center",children:c.jsx("div",{className:"w-6 h-6 border-2 border-[#07C160]/30 border-t-[#07C160] rounded-full animate-spin"})}),c.jsx("div",{className:"flex items-center gap-2 text-sm",children:x==="scaned"?c.jsxs("span",{className:"text-[#07C160] font-medium",children:["👀 ",r]}):x==="loading"?c.jsx("span",{className:"text-muted",children:s("configForm.weixin.gettingQr")}):c.jsx("span",{className:"text-muted",children:r})}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("button",{onClick:S,className:"px-3 py-1.5 text-xs text-white bg-red-500 rounded-md hover:bg-red-500/90 transition-colors",children:s("configForm.weixin.cancel")}),c.jsx("button",{onClick:()=>{S(),setTimeout(p,100)},className:"px-3 py-1.5 text-xs text-white bg-[#0066FF] rounded-md hover:bg-[#0066FF]/90 transition-colors",children:s("configForm.weixin.refresh")})]})]})})}export{De as C,Ue as F,je as I,Q,He as S,Qe as T,Ke as W,_e as a,ze as b,$e as c,Be as d};
|
|
9
|
+
*/var Ne={L:O.QrCode.Ecc.LOW,M:O.QrCode.Ecc.MEDIUM,Q:O.QrCode.Ecc.QUARTILE,H:O.QrCode.Ecc.HIGH},Z=128,J="L",ee="#FFFFFF",te="#000000",re=!1,se=1,ye=4,Ce=0,Fe=.1;function ne(a,i=0){const s=[];return a.forEach(function(d,h){let l=null;d.forEach(function(E,x){if(!E&&l!==null){s.push(`M${l+i} ${h+i}h${x-l}v1H${l+i}z`),l=null;return}if(x===d.length-1){if(!E)return;l===null?s.push(`M${x+i},${h+i} h1v1H${x+i}z`):s.push(`M${l+i},${h+i} h${x+1-l}v1H${l+i}z`);return}E&&l===null&&(l=x)})}),s.join("")}function oe(a,i){return a.slice().map((s,d)=>d<i.y||d>=i.y+i.h?s:s.map((h,l)=>l<i.x||l>=i.x+i.w?h:!1))}function Re(a,i,s,d){if(d==null)return null;const h=a.length+s*2,l=Math.floor(i*Fe),E=h/i,x=(d.width||l)*E,e=(d.height||l)*E,r=d.x==null?a.length/2-x/2:d.x*E,t=d.y==null?a.length/2-e/2:d.y*E,n=d.opacity==null?1:d.opacity;let o=null;if(d.excavate){let u=Math.floor(r),m=Math.floor(t),g=Math.ceil(x+r-u),C=Math.ceil(e+t-m);o={x:u,y:m,w:g,h:C}}const f=d.crossOrigin;return{x:r,y:t,h:e,w:x,excavation:o,opacity:n,crossOrigin:f}}function Me(a,i){return i!=null?Math.max(Math.floor(i),0):a?ye:Ce}function ie({value:a,level:i,minVersion:s,includeMargin:d,marginSize:h,imageSettings:l,size:E,boostLevel:x}){let e=A.useMemo(()=>{const u=(Array.isArray(a)?a:[a]).reduce((m,g)=>(m.push(...O.QrSegment.makeSegments(g)),m),[]);return O.QrCode.encodeSegments(u,Ne[i],s,void 0,void 0,x)},[a,i,s,x]);const{cells:r,margin:t,numCells:n,calculatedImageSettings:o}=A.useMemo(()=>{let f=e.getModules();const u=Me(d,h),m=f.length+u*2,g=Re(f,E,u,l);return{cells:f,margin:u,numCells:m,calculatedImageSettings:g}},[e,E,l,d,h]);return{qrcode:e,margin:t,cells:r,numCells:n,calculatedImageSettings:o}}var Ae=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),Se=A.forwardRef(function(i,s){const d=i,{value:h,size:l=Z,level:E=J,bgColor:x=ee,fgColor:e=te,includeMargin:r=re,minVersion:t=se,boostLevel:n,marginSize:o,imageSettings:f}=d,m=_(d,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:g}=m,C=_(m,["style"]),F=f==null?void 0:f.src,p=A.useRef(null),N=A.useRef(null),S=A.useCallback(L=>{p.current=L,typeof s=="function"?s(L):s&&(s.current=L)},[s]),[w,M]=A.useState(!1),{margin:v,cells:I,numCells:U,calculatedImageSettings:P}=ie({value:h,level:E,minVersion:t,boostLevel:n,includeMargin:r,marginSize:o,imageSettings:f,size:l});A.useEffect(()=>{if(p.current!=null){const L=p.current,j=L.getContext("2d");if(!j)return;let $=I;const k=N.current,K=P!=null&&k!==null&&k.complete&&k.naturalHeight!==0&&k.naturalWidth!==0;K&&P.excavation!=null&&($=oe(I,P.excavation));const q=window.devicePixelRatio||1;L.height=L.width=l*q;const G=l/U*q;j.scale(G,G),j.fillStyle=x,j.fillRect(0,0,U,U),j.fillStyle=e,Ae?j.fill(new Path2D(ne($,v))):I.forEach(function(ce,ue){ce.forEach(function(de,he){de&&j.fillRect(he+v,ue+v,1,1)})}),P&&(j.globalAlpha=P.opacity),K&&j.drawImage(k,P.x+v,P.y+v,P.w,P.h)}}),A.useEffect(()=>{M(!1)},[F]);const le=z({height:l,width:l},g);let H=null;return F!=null&&(H=A.createElement("img",{src:F,key:F,style:{display:"none"},onLoad:()=>{M(!0)},ref:N,crossOrigin:P==null?void 0:P.crossOrigin})),A.createElement(A.Fragment,null,A.createElement("canvas",z({style:le,height:l,width:l,ref:S,role:"img"},C)),H)});Se.displayName="QRCodeCanvas";var Q=A.forwardRef(function(i,s){const d=i,{value:h,size:l=Z,level:E=J,bgColor:x=ee,fgColor:e=te,includeMargin:r=re,minVersion:t=se,boostLevel:n,title:o,marginSize:f,imageSettings:u}=d,m=_(d,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:g,cells:C,numCells:F,calculatedImageSettings:p}=ie({value:h,level:E,minVersion:t,boostLevel:n,includeMargin:r,marginSize:f,imageSettings:u,size:l});let N=C,S=null;u!=null&&p!=null&&(p.excavation!=null&&(N=oe(C,p.excavation)),S=A.createElement("image",{href:u.src,height:p.h,width:p.w,x:p.x+g,y:p.y+g,preserveAspectRatio:"none",opacity:p.opacity,crossOrigin:p.crossOrigin}));const w=ne(N,g);return A.createElement("svg",z({height:l,width:l,viewBox:`0 0 ${F} ${F}`,ref:s,role:"img"},m),!!o&&A.createElement("title",null,o),A.createElement("path",{fill:x,d:`M0,0 h${F}v${F}H0z`,shapeRendering:"crispEdges"}),A.createElement("path",{fill:e,d:w,shapeRendering:"crispEdges"}),S)});Q.displayName="QRCodeSVG";const De=[{id:"feishu",labelKey:"configForm.channel.feishu",fields:[],defaults:{connectionMode:"websocket"}},{id:"openclaw-weixin",labelKey:"configForm.channel.openclaw-weixin",fields:[],defaults:{}},{id:"telegram",labelKey:"configForm.channel.telegram",fields:[{key:"botToken",label:"Bot Token",type:"password",placeholder:"From @BotFather"}]},{id:"discord",labelKey:"configForm.channel.discord",fields:[{key:"token",label:"Bot Token",type:"password",placeholder:"From Discord Developer Portal"}]},{id:"slack",labelKey:"configForm.channel.slack",fields:[{key:"botToken",label:"Bot Token (xoxb-...)",type:"password",placeholder:"xoxb-..."},{key:"appToken",label:"App Token (xapp-...)",type:"password",placeholder:"xapp-..."}]},{id:"whatsapp",labelKey:"configForm.channel.whatsapp",fields:[],defaults:{}},{id:"msteams",labelKey:"configForm.channel.msteams",fields:[{key:"appId",label:"App ID",placeholder:"Azure App Registration ID"},{key:"appPassword",label:"App Password",type:"password",placeholder:"Azure App Secret"},{key:"tenantId",label:"Tenant ID",placeholder:"Azure AD Tenant ID"}]},{id:"signal",labelKey:"configForm.channel.signal",fields:[{key:"account",label:"Phone (E.164)",placeholder:"+8613800138000"}]},{id:"line",labelKey:"configForm.channel.line",fields:[{key:"channelAccessToken",label:"Channel Access Token",type:"password",placeholder:"From LINE Developers"},{key:"channelSecret",label:"Channel Secret",type:"password",placeholder:"LINE Channel Secret"}]},{id:"googlechat",labelKey:"configForm.channel.googlechat",fields:[{key:"serviceAccountFile",label:"Service Account JSON Path",placeholder:"/path/to/service-account.json"}]}];function Be(a,i,s){const d=structuredClone(a),h=i.split(".");let l=d;for(let E=0;E<h.length-1;E++)l[h[E]]===void 0&&(l[h[E]]={}),l=l[h[E]];return l[h[h.length-1]]=s,d}const ae="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",Pe="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-[#0066FF]/60 focus:border-[#0066FF]/60 transition-colors duration-200 appearance-none";function Ue({label:a,hint:i,children:s}){return c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-muted mb-1.5",children:a}),s,i&&c.jsx("p",{className:"text-xs text-muted mt-1 opacity-60",children:i})]})}function ze({value:a,saved:i,onChange:s,placeholder:d,onPaste:h}){const{t:l}=B("instance"),[E,x]=y.useState(!1),e="••••••••••••••••••••••••••••••";return i&&!E&&!a?c.jsx("div",{className:"relative",children:c.jsx("input",{type:"password",value:e,readOnly:!0,onFocus:()=>x(!0),onPaste:r=>{var n;const t=((n=r.clipboardData)==null?void 0:n.getData("text"))??"";t&&(r.preventDefault(),x(!0),s(t),h==null||h(r))},className:`${ae} cursor-text`,title:l("config.clickToEdit")})}):c.jsx(je,{value:a,onChange:s,onPaste:h,placeholder:d,type:"password",mono:!0})}function je({value:a,onChange:i,placeholder:s,type:d="text",mono:h,onPaste:l}){const{t:E}=B("common"),[x,e]=y.useState(!1),r=d==="password";return c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:r&&!x?"password":"text",value:a||"",onChange:t=>i(t.target.value),onPaste:l,placeholder:s,className:`${ae} ${h?"font-mono text-[13px]":""} ${r?"pr-9":""}`}),r&&c.jsx("button",{type:"button",onClick:()=>e(!x),"aria-label":E("action.togglePassword"),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-foreground",children:x?c.jsx(ge,{className:"w-3.5 h-3.5"}):c.jsx(pe,{className:"w-3.5 h-3.5"})})]})}function _e({value:a,onChange:i,children:s}){return c.jsx("select",{value:a||"",onChange:d=>i(d.target.value),className:Pe,children:s})}function Qe({checked:a,onChange:i,label:s}){return c.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer",children:[c.jsx("button",{type:"button",role:"switch","aria-checked":a,onClick:()=>i(!a),className:`w-9 h-5 rounded-full relative transition-colors duration-200 ${a?"bg-[#0066FF]":"bg-[var(--input-bg)]"}`,children:c.jsx("div",{className:`w-3.5 h-3.5 bg-white rounded-full absolute top-[3px] transition-transform duration-200 ${a?"left-[18px]":"left-[3px]"}`})}),c.jsx("span",{className:"text-sm text-muted",children:s})]})}function He({title:a,defaultOpen:i=!0,id:s,children:d}){const[h,l]=y.useState(i);return c.jsxs("div",{id:s,className:"bg-[var(--card)] border border-[var(--border)] rounded-xl overflow-hidden hover:border-[var(--border-hover)] transition-colors duration-200",children:[c.jsxs("button",{type:"button",onClick:()=>l(!h),className:"w-full px-4 py-3 flex items-center justify-between text-left hover:bg-[var(--card-hover)] transition-colors duration-150",children:[c.jsx("span",{className:"text-sm font-medium text-foreground",children:a}),h?c.jsx(fe,{className:"w-4 h-4 text-muted"}):c.jsx(me,{className:"w-4 h-4 text-muted"})]}),h&&c.jsx("div",{className:"px-4 pb-4 space-y-4 border-t border-[var(--border)] pt-4",children:d})]})}function $e({instanceId:a,channelKey:i,existingAppId:s,existingDomain:d,onConfigured:h}){const{t:l}=B(["instance","common"]),[E,x]=y.useState(""),[,e]=y.useState(""),[r,t]=y.useState("idle"),[n,o]=y.useState(""),[f,u]=y.useState(""),m=y.useRef(!1),g=y.useRef(!1),C=y.useRef(0),F=6,p=async()=>{if(a){g.current=!1,t("loading"),o(""),x("");try{let w=null;for(let M=0;M<3;M++){if(g.current)return;try{if(w=await xe(a,i),w!=null&&w.qrcodeUrl)break}catch{M<2&&await new Promise(v=>setTimeout(v,1500))}}if(g.current)return;w!=null&&w.qrcodeUrl?(x(w.qrcodeUrl),e(w.sessionKey),t("waiting"),o(l("configForm.feishu.scanHint")),N(w.sessionKey)):(t("error"),o(l("qr.getFailed")))}catch{g.current||(t("error"),o(l("qr.getFailed")))}}},N=w=>{if(!a||m.current)return;m.current=!0,C.current=0;const M=async()=>{if(m.current)try{const v=await we(a,w);if(C.current=0,v.connected){m.current=!1,t("confirmed"),o(v.message||l("qr.loginSuccess")),u(v.domain||"feishu"),x(""),h==null||h();return}if(v.status==="expired"){m.current=!1,t("error"),o(v.message||l("qr.expired"));return}setTimeout(M,3e3)}catch{if(!m.current)return;if(C.current+=1,C.current>=F){m.current=!1,t("error"),o(l("qr.pollFailed",{defaultValue:"轮询失败,请刷新后重试"}));return}setTimeout(M,3e3)}};M()};if(y.useEffect(()=>()=>{m.current=!1},[]),r==="confirmed")return c.jsxs("div",{className:"bg-emerald-500/10 border border-emerald-500/20 rounded-md px-4 py-3 text-sm",children:[c.jsxs("div",{className:"flex items-center gap-2 text-emerald-400",children:[c.jsx("span",{className:"text-lg",children:"✓"}),c.jsx("span",{className:"font-medium",children:n})]}),c.jsx("p",{className:"text-xs text-muted mt-1",children:l("configForm.feishu.platform",{platform:l(f==="lark"?"configForm.feishu.platformLark":"configForm.feishu.platformFeishu")})})]});if(r==="idle"||r==="error")return c.jsxs("div",{className:"bg-[var(--card-hover)] rounded-md px-4 py-3 space-y-3",children:[s&&c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-muted mb-1",children:l("configForm.feishu.added")}),c.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[c.jsx("span",{className:"text-emerald-400",children:"✓"}),c.jsx("code",{className:"font-mono text-foreground/70",children:s}),c.jsx("span",{className:"text-muted opacity-60",children:d==="lark"?"Lark":l("configForm.feishu.platformFeishu")})]})]}),c.jsxs("div",{children:[c.jsx("button",{onClick:p,className:"px-4 py-2 bg-[#3370FF] text-white rounded-md text-xs font-medium hover:bg-[#3370FF]/90 transition-colors",children:l("configForm.feishu.addBot")}),c.jsx("p",{className:"text-xs text-muted mt-2",children:l("configForm.feishu.addBotHint")})]})]});const S=()=>{g.current=!0,m.current=!1,t("idle"),o(""),x(""),e("")};return c.jsx("div",{className:"bg-[var(--card-hover)] rounded-md px-4 py-4",children:c.jsxs("div",{className:"flex flex-col items-center gap-3",children:[E?c.jsx(Q,{value:E,size:192,className:"rounded-lg"}):c.jsx("div",{className:"w-48 h-48 flex items-center justify-center",children:c.jsx("div",{className:"w-6 h-6 border-2 border-[#3370FF]/30 border-t-[#3370FF] rounded-full animate-spin"})}),c.jsx("div",{className:"text-sm text-muted",children:r==="loading"?l("configForm.feishu.gettingQr"):n}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("button",{onClick:S,className:"px-3 py-1.5 text-xs text-white bg-red-500 rounded-md hover:bg-red-500/90 transition-colors",children:l("configForm.feishu.cancel")}),c.jsx("button",{onClick:()=>{S(),setTimeout(p,100)},className:"px-3 py-1.5 text-xs text-white bg-[#0066FF] rounded-md hover:bg-[#0066FF]/90 transition-colors",children:l("configForm.feishu.refresh")})]})]})})}function Ke({instanceId:a,onConfigured:i}){const{t:s,i18n:d}=B(["instance","common"]),[h,l]=y.useState(""),[,E]=y.useState(""),[x,e]=y.useState("idle"),[r,t]=y.useState(""),[n,o]=y.useState(""),[f,u]=y.useState([]),m=y.useRef(!1),g=y.useRef(!1),C=y.useRef(0),F=6;y.useEffect(()=>{a&&Y(a).then(w=>{var M;(M=w==null?void 0:w.accounts)!=null&&M.length&&u(w.accounts)}).catch(()=>{})},[a]);const p=async()=>{if(a){g.current=!1,e("loading"),t(""),l("");try{let w=null;for(let M=0;M<3;M++){if(g.current)return;try{if(w=await be(a),w!=null&&w.qrcodeUrl)break}catch{M<2&&await new Promise(v=>setTimeout(v,1500))}}if(g.current)return;w!=null&&w.qrcodeUrl?(l(w.qrcodeUrl),E(w.sessionKey),e("waiting"),t(s("configForm.weixin.scanHint")),N(w.sessionKey)):(e("error"),t(s("qr.getFailed")))}catch{g.current||(e("error"),t(s("qr.getFailed")))}}},N=w=>{if(!a||m.current)return;m.current=!0,C.current=0;const M=async()=>{if(m.current)try{const v=await Ee(a,w);if(C.current=0,v.connected){m.current=!1,e("confirmed"),t(v.message||s("qr.loginSuccess")),o(v.accountId||""),l(""),a&&Y(a).then(I=>{I!=null&&I.accounts&&u(I.accounts)}).catch(()=>{}),i==null||i();return}if(v.status==="scaned")e("scaned"),t(v.message||s("qr.scaned"));else if(v.status==="refreshed"&&v.qrcodeUrl)l(v.qrcodeUrl),e("waiting"),t(s("qr.refreshed"));else if(v.status==="expired"){m.current=!1,e("error"),t(v.message||s("qr.expired"));return}setTimeout(M,2e3)}catch{if(!m.current)return;if(C.current+=1,C.current>=F){m.current=!1,e("error"),t(s("qr.pollFailed",{defaultValue:"轮询失败,请刷新后重试"}));return}setTimeout(M,3e3)}};M()};if(y.useEffect(()=>()=>{m.current=!1},[]),x==="confirmed")return c.jsxs("div",{className:"bg-emerald-500/10 border border-emerald-500/20 rounded-md px-4 py-3 text-sm",children:[c.jsxs("div",{className:"flex items-center gap-2 text-emerald-400",children:[c.jsx("span",{className:"text-lg",children:"✓"}),c.jsx("span",{className:"font-medium",children:r})]}),n&&c.jsxs("p",{className:"text-xs text-muted mt-1",children:[s("configForm.weixin.accountId")," ",c.jsx("code",{className:"font-mono",children:n})]}),c.jsx("p",{className:"text-xs text-muted mt-1",children:s("configForm.weixin.restartHint")}),c.jsx("button",{onClick:p,className:"mt-2 px-3 py-1 text-xs border border-emerald-500/30 rounded text-emerald-400 hover:bg-emerald-500/10 transition-colors",children:s("configForm.weixin.addAnother")})]});if(x==="idle"||x==="error")return c.jsxs("div",{className:"bg-[var(--card-hover)] rounded-md px-4 py-3 space-y-3",children:[f.length>0&&c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-muted mb-1.5",children:s("configForm.weixin.added")}),f.map(w=>c.jsxs("div",{className:"flex items-center gap-2 text-xs py-1",children:[c.jsx("span",{className:"text-emerald-400",children:"✓"}),c.jsx("code",{className:"font-mono text-foreground/70",children:w.accountId}),w.savedAt&&c.jsx("span",{className:"text-muted opacity-60",children:new Date(w.savedAt).toLocaleDateString(d.language==="zh"?"zh-CN":"en-US")})]},w.accountId))]}),c.jsxs("div",{children:[c.jsx("button",{onClick:p,className:"px-4 py-2 bg-[#07C160] text-white rounded-md text-xs font-medium hover:bg-[#07C160]/90 transition-colors",children:s("configForm.weixin.addClawBot")}),c.jsx("p",{className:"text-xs text-muted mt-2",children:s("configForm.weixin.addClawBotHint",{extra:f.length>0?s("configForm.weixin.addClawBotHintRestart"):s("configForm.weixin.addClawBotHintMulti")})})]})]});const S=()=>{g.current=!0,m.current=!1,e("idle"),t(""),l(""),E("")};return c.jsx("div",{className:"bg-[var(--card-hover)] rounded-md px-4 py-4",children:c.jsxs("div",{className:"flex flex-col items-center gap-3",children:[h?c.jsx(Q,{value:h,size:192,className:"rounded-lg"}):c.jsx("div",{className:"w-48 h-48 flex items-center justify-center",children:c.jsx("div",{className:"w-6 h-6 border-2 border-[#07C160]/30 border-t-[#07C160] rounded-full animate-spin"})}),c.jsx("div",{className:"flex items-center gap-2 text-sm",children:x==="scaned"?c.jsxs("span",{className:"text-[#07C160] font-medium",children:["👀 ",r]}):x==="loading"?c.jsx("span",{className:"text-muted",children:s("configForm.weixin.gettingQr")}):c.jsx("span",{className:"text-muted",children:r})}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("button",{onClick:S,className:"px-3 py-1.5 text-xs text-white bg-red-500 rounded-md hover:bg-red-500/90 transition-colors",children:s("configForm.weixin.cancel")}),c.jsx("button",{onClick:()=>{S(),setTimeout(p,100)},className:"px-3 py-1.5 text-xs text-white bg-[#0066FF] rounded-md hover:bg-[#0066FF]/90 transition-colors",children:s("configForm.weixin.refresh")})]})]})})}export{De as C,Ue as F,je as I,Q,He as S,Qe as T,Ke as W,_e as a,ze as b,$e as c,Be as d};
|